linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Michael Schmitz <schmitzmic@gmail.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-ide@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
	linux-kernel@vger.kernel.org, b.zolnierkie@samsung.com
Subject: [PATCH v5 26/27] ata: move ata_eh_analyze_ncq_error() & co. to libata-sata.c
Date: Thu, 26 Mar 2020 16:58:21 +0100	[thread overview]
Message-ID: <20200326155822.19400-27-b.zolnierkie@samsung.com> (raw)
In-Reply-To: <20200326155822.19400-1-b.zolnierkie@samsung.com>

* move ata_eh_analyze_ncq_error() and ata_eh_read_log_10h() to
  libata-sata.c

* add static inline for ata_eh_analyze_ncq_error() for
  CONFIG_SATA_HOST=n case (link->sactive is non-zero only if
  NCQ commands are actually queued so empty function body is
  sufficient)

Code size savings on m68k arch using (modified) atari_defconfig:

   text    data     bss     dec     hex filename
before:
  16164      18       0   16182    3f36 drivers/ata/libata-eh.o
after:
  15446      18       0   15464    3c68 drivers/ata/libata-eh.o

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/ata/libata-eh.c   | 131 --------------------------------------
 drivers/ata/libata-sata.c | 131 ++++++++++++++++++++++++++++++++++++++
 include/linux/libata.h    |   3 +-
 3 files changed, 133 insertions(+), 132 deletions(-)

diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index ef4d606cd8c6..474c6c34fe02 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1351,62 +1351,6 @@ static const char *ata_err_string(unsigned int err_mask)
 	return "unknown error";
 }
 
-/**
- *	ata_eh_read_log_10h - Read log page 10h for NCQ error details
- *	@dev: Device to read log page 10h from
- *	@tag: Resulting tag of the failed command
- *	@tf: Resulting taskfile registers of the failed command
- *
- *	Read log page 10h to obtain NCQ error details and clear error
- *	condition.
- *
- *	LOCKING:
- *	Kernel thread context (may sleep).
- *
- *	RETURNS:
- *	0 on success, -errno otherwise.
- */
-static int ata_eh_read_log_10h(struct ata_device *dev,
-			       int *tag, struct ata_taskfile *tf)
-{
-	u8 *buf = dev->link->ap->sector_buf;
-	unsigned int err_mask;
-	u8 csum;
-	int i;
-
-	err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
-	if (err_mask)
-		return -EIO;
-
-	csum = 0;
-	for (i = 0; i < ATA_SECT_SIZE; i++)
-		csum += buf[i];
-	if (csum)
-		ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
-			     csum);
-
-	if (buf[0] & 0x80)
-		return -ENOENT;
-
-	*tag = buf[0] & 0x1f;
-
-	tf->command = buf[2];
-	tf->feature = buf[3];
-	tf->lbal = buf[4];
-	tf->lbam = buf[5];
-	tf->lbah = buf[6];
-	tf->device = buf[7];
-	tf->hob_lbal = buf[8];
-	tf->hob_lbam = buf[9];
-	tf->hob_lbah = buf[10];
-	tf->nsect = buf[12];
-	tf->hob_nsect = buf[13];
-	if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
-		tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
-
-	return 0;
-}
-
 /**
  *	atapi_eh_tur - perform ATAPI TEST_UNIT_READY
  *	@dev: target ATAPI device
@@ -1590,81 +1534,6 @@ static void ata_eh_analyze_serror(struct ata_link *link)
 	ehc->i.action |= action;
 }
 
-/**
- *	ata_eh_analyze_ncq_error - analyze NCQ error
- *	@link: ATA link to analyze NCQ error for
- *
- *	Read log page 10h, determine the offending qc and acquire
- *	error status TF.  For NCQ device errors, all LLDDs have to do
- *	is setting AC_ERR_DEV in ehi->err_mask.  This function takes
- *	care of the rest.
- *
- *	LOCKING:
- *	Kernel thread context (may sleep).
- */
-void ata_eh_analyze_ncq_error(struct ata_link *link)
-{
-	struct ata_port *ap = link->ap;
-	struct ata_eh_context *ehc = &link->eh_context;
-	struct ata_device *dev = link->device;
-	struct ata_queued_cmd *qc;
-	struct ata_taskfile tf;
-	int tag, rc;
-
-	/* if frozen, we can't do much */
-	if (ap->pflags & ATA_PFLAG_FROZEN)
-		return;
-
-	/* is it NCQ device error? */
-	if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
-		return;
-
-	/* has LLDD analyzed already? */
-	ata_qc_for_each_raw(ap, qc, tag) {
-		if (!(qc->flags & ATA_QCFLAG_FAILED))
-			continue;
-
-		if (qc->err_mask)
-			return;
-	}
-
-	/* okay, this error is ours */
-	memset(&tf, 0, sizeof(tf));
-	rc = ata_eh_read_log_10h(dev, &tag, &tf);
-	if (rc) {
-		ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
-			     rc);
-		return;
-	}
-
-	if (!(link->sactive & (1 << tag))) {
-		ata_link_err(link, "log page 10h reported inactive tag %d\n",
-			     tag);
-		return;
-	}
-
-	/* we've got the perpetrator, condemn it */
-	qc = __ata_qc_from_tag(ap, tag);
-	memcpy(&qc->result_tf, &tf, sizeof(tf));
-	qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
-	qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
-	if (dev->class == ATA_DEV_ZAC &&
-	    ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
-		char sense_key, asc, ascq;
-
-		sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
-		asc = (qc->result_tf.auxiliary >> 8) & 0xff;
-		ascq = qc->result_tf.auxiliary & 0xff;
-		ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
-		ata_scsi_set_sense_information(dev, qc->scsicmd,
-					       &qc->result_tf);
-		qc->flags |= ATA_QCFLAG_SENSE_VALID;
-	}
-
-	ehc->i.err_mask &= ~AC_ERR_DEV;
-}
-EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);
-
 /**
  *	ata_eh_analyze_tf - analyze taskfile of a failed qc
  *	@qc: qc to analyze
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 008468e516cd..c16423e44525 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -1350,3 +1350,134 @@ int sata_async_notification(struct ata_port *ap)
 	}
 }
 EXPORT_SYMBOL_GPL(sata_async_notification);
+
+/**
+ *	ata_eh_read_log_10h - Read log page 10h for NCQ error details
+ *	@dev: Device to read log page 10h from
+ *	@tag: Resulting tag of the failed command
+ *	@tf: Resulting taskfile registers of the failed command
+ *
+ *	Read log page 10h to obtain NCQ error details and clear error
+ *	condition.
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep).
+ *
+ *	RETURNS:
+ *	0 on success, -errno otherwise.
+ */
+static int ata_eh_read_log_10h(struct ata_device *dev,
+			       int *tag, struct ata_taskfile *tf)
+{
+	u8 *buf = dev->link->ap->sector_buf;
+	unsigned int err_mask;
+	u8 csum;
+	int i;
+
+	err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
+	if (err_mask)
+		return -EIO;
+
+	csum = 0;
+	for (i = 0; i < ATA_SECT_SIZE; i++)
+		csum += buf[i];
+	if (csum)
+		ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
+			     csum);
+
+	if (buf[0] & 0x80)
+		return -ENOENT;
+
+	*tag = buf[0] & 0x1f;
+
+	tf->command = buf[2];
+	tf->feature = buf[3];
+	tf->lbal = buf[4];
+	tf->lbam = buf[5];
+	tf->lbah = buf[6];
+	tf->device = buf[7];
+	tf->hob_lbal = buf[8];
+	tf->hob_lbam = buf[9];
+	tf->hob_lbah = buf[10];
+	tf->nsect = buf[12];
+	tf->hob_nsect = buf[13];
+	if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
+		tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
+
+	return 0;
+}
+
+/**
+ *	ata_eh_analyze_ncq_error - analyze NCQ error
+ *	@link: ATA link to analyze NCQ error for
+ *
+ *	Read log page 10h, determine the offending qc and acquire
+ *	error status TF.  For NCQ device errors, all LLDDs have to do
+ *	is setting AC_ERR_DEV in ehi->err_mask.  This function takes
+ *	care of the rest.
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep).
+ */
+void ata_eh_analyze_ncq_error(struct ata_link *link)
+{
+	struct ata_port *ap = link->ap;
+	struct ata_eh_context *ehc = &link->eh_context;
+	struct ata_device *dev = link->device;
+	struct ata_queued_cmd *qc;
+	struct ata_taskfile tf;
+	int tag, rc;
+
+	/* if frozen, we can't do much */
+	if (ap->pflags & ATA_PFLAG_FROZEN)
+		return;
+
+	/* is it NCQ device error? */
+	if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
+		return;
+
+	/* has LLDD analyzed already? */
+	ata_qc_for_each_raw(ap, qc, tag) {
+		if (!(qc->flags & ATA_QCFLAG_FAILED))
+			continue;
+
+		if (qc->err_mask)
+			return;
+	}
+
+	/* okay, this error is ours */
+	memset(&tf, 0, sizeof(tf));
+	rc = ata_eh_read_log_10h(dev, &tag, &tf);
+	if (rc) {
+		ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
+			     rc);
+		return;
+	}
+
+	if (!(link->sactive & (1 << tag))) {
+		ata_link_err(link, "log page 10h reported inactive tag %d\n",
+			     tag);
+		return;
+	}
+
+	/* we've got the perpetrator, condemn it */
+	qc = __ata_qc_from_tag(ap, tag);
+	memcpy(&qc->result_tf, &tf, sizeof(tf));
+	qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
+	qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
+	if (dev->class == ATA_DEV_ZAC &&
+	    ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
+		char sense_key, asc, ascq;
+
+		sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
+		asc = (qc->result_tf.auxiliary >> 8) & 0xff;
+		ascq = qc->result_tf.auxiliary & 0xff;
+		ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
+		ata_scsi_set_sense_information(dev, qc->scsicmd,
+					       &qc->result_tf);
+		qc->flags |= ATA_QCFLAG_SENSE_VALID;
+	}
+
+	ehc->i.err_mask &= ~AC_ERR_DEV;
+}
+EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 9c7ca659dc94..cffa4714bfa8 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1181,6 +1181,7 @@ extern int sata_link_hardreset(struct ata_link *link,
 			bool *online, int (*check_ready)(struct ata_link *));
 extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
 			    unsigned long deadline);
+extern void ata_eh_analyze_ncq_error(struct ata_link *link);
 #else
 static inline const unsigned long *
 sata_ehc_deb_timing(struct ata_eh_context *ehc)
@@ -1217,6 +1218,7 @@ static inline int sata_link_resume(struct ata_link *link,
 {
 	return -EOPNOTSUPP;
 }
+static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
 #endif
 extern int sata_link_debounce(struct ata_link *link,
 			const unsigned long *params, unsigned long deadline);
@@ -1339,7 +1341,6 @@ extern void ata_eh_thaw_port(struct ata_port *ap);
 
 extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
 extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
-extern void ata_eh_analyze_ncq_error(struct ata_link *link);
 
 extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
 		      ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
-- 
2.24.1


  parent reply	other threads:[~2020-03-26 15:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200326155838eucas1p2a1c1f5c08832410d1e2b5a5ea8226151@eucas1p2.samsung.com>
2020-03-26 15:57 ` [PATCH v5 00/27] ata: optimize core code size on PATA only setups Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155838eucas1p1931e5db55f9efd231696c210c0690733@eucas1p1.samsung.com>
2020-03-26 15:57     ` [PATCH v5 01/27] ata: remove stale maintainership information from core code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155839eucas1p2c9e354eb1f81d47c2c00d1c6c42f28a5@eucas1p2.samsung.com>
2020-03-26 15:57     ` [PATCH v5 02/27] ata: expose ncq_enable_prio sysfs attribute only on NCQ capable hosts Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155839eucas1p226e80fe61b5df9c08ec23c7d93c843db@eucas1p2.samsung.com>
2020-03-26 15:57     ` [PATCH v5 03/27] ata: make SATA_PMP option selectable only if any SATA host driver is enabled Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155839eucas1p1d5c84c9070fd1a1282b590172be640b1@eucas1p1.samsung.com>
2020-03-26 15:57     ` [PATCH v5 04/27] sata_promise: use ata_cable_sata() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155840eucas1p1fd8d2a9a30f2f97dbf4a78258191c624@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 05/27] ata: simplify ata_scsiop_inq_89() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155840eucas1p2861601dc1c971a2baade72b03baee9f0@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 06/27] ata: use COMMAND_LINE_SIZE for ata_force_param_buf[] size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155841eucas1p1b9f0b5feb3d00618fc08d962abc709a9@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 07/27] ata: optimize struct ata_force_param size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155841eucas1p29ed1b37ca4364f205c6404ed978aa007@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 08/27] ata: optimize ata_scsi_rbuf[] size Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155842eucas1p16ec1dd1303741c202766ce6f1264df5d@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 09/27] ata: move EXPORT_SYMBOL_GPL()s close to exported code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155842eucas1p23d6b95d066eaf1a86e04935641015af6@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 10/27] ata: remove EXPORT_SYMBOL_GPL()s not used by modules Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155842eucas1p1aa92a260749305a13bebcd7999fd801b@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 11/27] ata: fix CodingStyle issues in PATA timings code Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155843eucas1p19fd3210ca004306942c7c12ca98e04c2@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 12/27] ata: separate PATA timings code from libata-core.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155843eucas1p1c3f378cfd16d7f2a29d46e1456d8cbfd@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 13/27] ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled() Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155844eucas1p2e9676a4dd5205dc66c464cf8d9f4efb7@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 14/27] ata: let compiler optimize out ata_dev_config_ncq() on non-SATA hosts Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155844eucas1p264f9d573deb8bf9019e2e2d5cb59472b@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 15/27] ata: let compiler optimize out ata_eh_set_lpm() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155845eucas1p29de94fa9d541972b78334ebfd0055320@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 16/27] ata: start separating SATA specific code from libata-core.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155845eucas1p2cd33e166f3ac6ab47f4681385491f538@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 17/27] ata: move sata_scr_*() to libata-sata.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155845eucas1p170d540c74535517def9925bf9dffc0c7@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 18/27] ata: move *sata_set_spd*() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155846eucas1p2c1a68a558be3f6df1308cd665ca60e32@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 19/27] ata: move sata_link_{debounce,resume}() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155846eucas1p26ed8a94105fa06625f4fd2c4a66f8960@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 20/27] ata: move sata_link_hardreset() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155847eucas1p1ed7286be9fa1a0616efc2d148bffe50d@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 21/27] ata: move ata_qc_complete_multiple() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155847eucas1p274137b9af50464c076fbbfb45947493d@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 22/27] ata: move sata_deb_timing_*() " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155847eucas1p2934ac7ef0c591dc15912b4d59d925d4c@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 23/27] ata: start separating SATA specific code from libata-scsi.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155848eucas1p2f3c45c3f3a26da7950118a88a1a65502@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 24/27] ata: move ata_sas_*() to libata-sata.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155848eucas1p1c9c2ca0451748cdfa4ab6a3420ab2847@eucas1p1.samsung.com>
2020-03-26 15:58     ` [PATCH v5 25/27] ata: start separating SATA specific code from libata-eh.c Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20200326155849eucas1p1b7b96c8913106b0330344af0500aca99@eucas1p1.samsung.com>
2020-03-26 15:58     ` Bartlomiej Zolnierkiewicz [this message]
     [not found]   ` <CGME20200326155849eucas1p2c1c0d059d5474597bd1eec3a6855ed8a@eucas1p2.samsung.com>
2020-03-26 15:58     ` [PATCH v5 27/27] ata: make "libata.force" kernel parameter optional Bartlomiej Zolnierkiewicz
2020-03-26 16:28   ` [PATCH v5 00/27] ata: optimize core code size on PATA only setups Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200326155822.19400-27-b.zolnierkie@samsung.com \
    --to=b.zolnierkie@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=geert@linux-m68k.org \
    --cc=hch@lst.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=schmitzmic@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).