From patchwork Fri Nov 9 06:51:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 197952 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5A4702C0176 for ; Fri, 9 Nov 2012 17:52:34 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781Ab2KIGwb (ORCPT ); Fri, 9 Nov 2012 01:52:31 -0500 Received: from mga11.intel.com ([192.55.52.93]:24969 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752445Ab2KIGwY (ORCPT ); Fri, 9 Nov 2012 01:52:24 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 08 Nov 2012 22:52:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.80,743,1344236400"; d="scan'208";a="246303885" Received: from aaronlu.sh.intel.com ([10.239.36.69]) by fmsmga002.fm.intel.com with ESMTP; 08 Nov 2012 22:52:21 -0800 From: Aaron Lu To: Jeff Garzik , James Bottomley , "Rafael J. Wysocki" , Alan Stern , Tejun Heo Cc: Jeff Wu , Aaron Lu , linux-ide@vger.kernel.org, linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-acpi@vger.kernel.org, Aaron Lu Subject: [PATCH v9 05/10] libata: separate ATAPI code Date: Fri, 9 Nov 2012 14:51:57 +0800 Message-Id: <1352443922-13734-6-git-send-email-aaron.lu@intel.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1352443922-13734-1-git-send-email-aaron.lu@intel.com> References: <1352443922-13734-1-git-send-email-aaron.lu@intel.com> Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org The atapi_eh_tur and atapi_eh_request_sense can be reused by ZPODD code, so separate them out to a file named libata-atapi.c, and the Makefile is modified accordingly. No functional changes should result from this commit. Signed-off-by: Aaron Lu --- drivers/ata/Makefile | 2 +- drivers/ata/libata-atapi.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-eh.c | 85 -------------------------------------------- drivers/ata/libata.h | 4 +++ 4 files changed, 93 insertions(+), 86 deletions(-) create mode 100644 drivers/ata/libata-atapi.c diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index 85e3de4..36377f9 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile @@ -103,7 +103,7 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o # Should be last libata driver obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o -libata-y := libata-core.o libata-scsi.o libata-eh.o libata-transport.o +libata-y := libata-core.o libata-scsi.o libata-eh.o libata-atapi.o libata-transport.o libata-$(CONFIG_ATA_SFF) += libata-sff.o libata-$(CONFIG_SATA_PMP) += libata-pmp.o libata-$(CONFIG_ATA_ACPI) += libata-acpi.o diff --git a/drivers/ata/libata-atapi.c b/drivers/ata/libata-atapi.c new file mode 100644 index 0000000..28684ae --- /dev/null +++ b/drivers/ata/libata-atapi.c @@ -0,0 +1,88 @@ +#include +#include +#include "libata.h" + +/** + * atapi_eh_tur - perform ATAPI TEST_UNIT_READY + * @dev: target ATAPI device + * @r_sense_key: out parameter for sense_key + * + * Perform ATAPI TEST_UNIT_READY. + * + * LOCKING: + * EH context (may sleep). + * + * RETURNS: + * 0 on success, AC_ERR_* mask on failure. + */ +unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key) +{ + u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 }; + struct ata_taskfile tf; + unsigned int err_mask; + + ata_tf_init(dev, &tf); + + tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; + tf.command = ATA_CMD_PACKET; + tf.protocol = ATAPI_PROT_NODATA; + + err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0); + if (err_mask == AC_ERR_DEV) + *r_sense_key = tf.feature >> 4; + return err_mask; +} + +/** + * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE + * @dev: device to perform REQUEST_SENSE to + * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) + * @dfl_sense_key: default sense key to use + * + * Perform ATAPI REQUEST_SENSE after the device reported CHECK + * SENSE. This function is EH helper. + * + * LOCKING: + * Kernel thread context (may sleep). + * + * RETURNS: + * 0 on success, AC_ERR_* mask on failure + */ +unsigned int atapi_eh_request_sense(struct ata_device *dev, + u8 *sense_buf, u8 dfl_sense_key) +{ + u8 cdb[ATAPI_CDB_LEN] = { + REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE, 0 }; + struct ata_port *ap = dev->link->ap; + struct ata_taskfile tf; + + DPRINTK("ATAPI request sense\n"); + + /* FIXME: is this needed? */ + memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE); + + /* initialize sense_buf with the error register, + * for the case where they are -not- overwritten + */ + sense_buf[0] = 0x70; + sense_buf[2] = dfl_sense_key; + + /* some devices time out if garbage left in tf */ + ata_tf_init(dev, &tf); + + tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; + tf.command = ATA_CMD_PACKET; + + /* is it pointless to prefer PIO for "safety reasons"? */ + if (ap->flags & ATA_FLAG_PIO_DMA) { + tf.protocol = ATAPI_PROT_DMA; + tf.feature |= ATAPI_PKT_DMA; + } else { + tf.protocol = ATAPI_PROT_PIO; + tf.lbam = SCSI_SENSE_BUFFERSIZE; + tf.lbah = 0; + } + + return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, + sense_buf, SCSI_SENSE_BUFFERSIZE, 0); +} diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index e60437c..6487b88 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1579,91 +1579,6 @@ static int ata_eh_read_log_10h(struct ata_device *dev, } /** - * atapi_eh_tur - perform ATAPI TEST_UNIT_READY - * @dev: target ATAPI device - * @r_sense_key: out parameter for sense_key - * - * Perform ATAPI TEST_UNIT_READY. - * - * LOCKING: - * EH context (may sleep). - * - * RETURNS: - * 0 on success, AC_ERR_* mask on failure. - */ -static unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key) -{ - u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 }; - struct ata_taskfile tf; - unsigned int err_mask; - - ata_tf_init(dev, &tf); - - tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; - tf.command = ATA_CMD_PACKET; - tf.protocol = ATAPI_PROT_NODATA; - - err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0); - if (err_mask == AC_ERR_DEV) - *r_sense_key = tf.feature >> 4; - return err_mask; -} - -/** - * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE - * @dev: device to perform REQUEST_SENSE to - * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) - * @dfl_sense_key: default sense key to use - * - * Perform ATAPI REQUEST_SENSE after the device reported CHECK - * SENSE. This function is EH helper. - * - * LOCKING: - * Kernel thread context (may sleep). - * - * RETURNS: - * 0 on success, AC_ERR_* mask on failure - */ -static unsigned int atapi_eh_request_sense(struct ata_device *dev, - u8 *sense_buf, u8 dfl_sense_key) -{ - u8 cdb[ATAPI_CDB_LEN] = - { REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE, 0 }; - struct ata_port *ap = dev->link->ap; - struct ata_taskfile tf; - - DPRINTK("ATAPI request sense\n"); - - /* FIXME: is this needed? */ - memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE); - - /* initialize sense_buf with the error register, - * for the case where they are -not- overwritten - */ - sense_buf[0] = 0x70; - sense_buf[2] = dfl_sense_key; - - /* some devices time out if garbage left in tf */ - ata_tf_init(dev, &tf); - - tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; - tf.command = ATA_CMD_PACKET; - - /* is it pointless to prefer PIO for "safety reasons"? */ - if (ap->flags & ATA_FLAG_PIO_DMA) { - tf.protocol = ATAPI_PROT_DMA; - tf.feature |= ATAPI_PKT_DMA; - } else { - tf.protocol = ATAPI_PROT_PIO; - tf.lbam = SCSI_SENSE_BUFFERSIZE; - tf.lbah = 0; - } - - return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, - sense_buf, SCSI_SENSE_BUFFERSIZE, 0); -} - -/** * ata_eh_analyze_serror - analyze SError for a failed port * @link: ATA link to analyze SError for * diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 55ad37e..5d68210 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -247,4 +247,8 @@ static inline void zpodd_deinit(struct ata_device *dev) {} static inline bool zpodd_dev_enabled(struct ata_device *dev) { return false; } #endif /* CONFIG_SATA_ZPODD */ +/* libata-atapi.c */ +unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key); +unsigned int atapi_eh_request_sense(struct ata_device *dev, u8 *sense_buf, u8 dfl_sense_key); + #endif /* __LIBATA_H__ */