linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: Jeff Garzik <jeff@garzik.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	linux-ide@vger.kernel.org, Forrest Zhao <forrest.zhao@gmail.com>
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 12/15] ahci: separate out ahci_kick_engine()
Date: Sun, 1 Jul 2007 19:54:16 +0900	[thread overview]
Message-ID: <11832872563253-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1183287253677-git-send-email-htejun@gmail.com>

Separate out stop_engine - CLO - start_engine sequence from
ahci_softreset() and ahci_clo() into ahci_reset_engine() and use it in
ahci_softreset() and ahci_post_internal_cmd().  The function will also
be used to prepare for and clean up after PMP register access
commands.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 drivers/ata/ahci.c |   69 +++++++++++++++++++++++++++-------------------------
 1 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 9af91ac..9d24dad 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -923,25 +923,49 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
 	pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
 }
 
-static int ahci_clo(struct ata_port *ap)
+static int ahci_kick_engine(struct ata_port *ap, int force_restart)
 {
 	void __iomem *port_mmio = ap->ioaddr.cmd_addr;
 	struct ahci_host_priv *hpriv = ap->host->private_data;
 	u32 tmp;
+	int busy, rc;
 
-	if (!(hpriv->cap & HOST_CAP_CLO))
-		return -EOPNOTSUPP;
+	/* do we need to kick the port? */
+	busy = ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ);
+	if (!busy && !force_restart)
+		return 0;
+
+	/* stop engine */
+	rc = ahci_stop_engine(ap);
+	if (rc)
+		goto out_restart;
+
+	/* need to do CLO? */
+	if (!busy) {
+		rc = 0;
+		goto out_restart;
+	}
+
+	if (!(hpriv->cap & HOST_CAP_CLO)) {
+		rc = -EOPNOTSUPP;
+		goto out_restart;
+	}
 
+	/* perform CLO */
 	tmp = readl(port_mmio + PORT_CMD);
 	tmp |= PORT_CMD_CLO;
 	writel(tmp, port_mmio + PORT_CMD);
 
+	rc = 0;
 	tmp = ata_wait_register(port_mmio + PORT_CMD,
 				PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
 	if (tmp & PORT_CMD_CLO)
-		return -EIO;
+		rc = -EIO;
 
-	return 0;
+	/* restart engine */
+ out_restart:
+	ahci_start_engine(ap);
+	return rc;
 }
 
 static int ahci_softreset(struct ata_link *link, unsigned int *class,
@@ -967,27 +991,10 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
 	}
 
 	/* prepare for SRST (AHCI-1.1 10.4.1) */
-	rc = ahci_stop_engine(ap);
-	if (rc) {
-		reason = "failed to stop engine";
-		goto fail_restart;
-	}
-
-	/* check BUSY/DRQ, perform Command List Override if necessary */
-	if (ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ)) {
-		rc = ahci_clo(ap);
-
-		if (rc == -EOPNOTSUPP) {
-			reason = "port busy but CLO unavailable";
-			goto fail_restart;
-		} else if (rc) {
-			reason = "port busy but CLO failed";
-			goto fail_restart;
-		}
-	}
-
-	/* restart engine */
-	ahci_start_engine(ap);
+	rc = ahci_kick_engine(ap, 1);
+	if (rc)
+		ata_link_printk(link, KERN_WARNING,
+				"failed to reset engine (errno=%d)", rc);
 
 	ata_tf_init(link->device, &tf);
 	fis = pp->cmd_tbl;
@@ -1046,8 +1053,6 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
 	DPRINTK("EXIT, class=%u\n", *class);
 	return 0;
 
- fail_restart:
-	ahci_start_engine(ap);
  fail:
 	ata_link_printk(link, KERN_ERR, "softreset failed (%s)\n", reason);
 	return rc;
@@ -1497,11 +1502,9 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
 {
 	struct ata_port *ap = qc->ap;
 
-	if (qc->flags & ATA_QCFLAG_FAILED) {
-		/* make DMA engine forget about the failed command */
-		ahci_stop_engine(ap);
-		ahci_start_engine(ap);
-	}
+	/* make DMA engine forget about the failed command */
+	if (qc->flags & ATA_QCFLAG_FAILED)
+		ahci_kick_engine(ap, 1);
 }
 
 #ifdef CONFIG_PM
-- 
1.5.0.3



  parent reply	other threads:[~2007-07-01 10:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01 10:54 [PATCHSET 4/4] implement PMP support, take 4 Tejun Heo
2007-07-01 10:54 ` [PATCH 01/15] libata-pmp: update ata_eh_reset() for PMP Tejun Heo
2007-07-01 10:54 ` [PATCH 02/15] libata-pmp: implement Port Multiplier support Tejun Heo
2007-07-01 10:54 ` [PATCH 03/15] libata-pmp: hook PMP support and enable it Tejun Heo
2007-07-01 10:54 ` [PATCH 04/15] libata-pmp: extend ACPI support to cover PMP Tejun Heo
2007-07-12 20:24   ` Jeff Garzik
2007-07-13  3:05     ` Tejun Heo
2007-07-01 10:54 ` [PATCH 09/15] sata_sil24: implement PORT_RST Tejun Heo
2007-07-01 10:54 ` [PATCH 07/15] sata_sil24: separate out sil24_do_softreset() Tejun Heo
2007-07-12 20:26   ` Jeff Garzik
2007-07-01 10:54 ` [PATCH 06/15] sata_sil24: separate out sil24_exec_polled_cmd() Tejun Heo
2007-07-12 20:25   ` Jeff Garzik
2007-07-13  3:06     ` Tejun Heo
2007-07-01 10:54 ` [PATCH 08/15] sata_sil24: implement PMP support Tejun Heo
2007-07-01 10:54 ` [PATCH 05/15] sata_sil24: replace sil24_update_tf() with sil24_read_tf() Tejun Heo
2007-07-01 10:54 ` [PATCH 14/15] ahci: separate out ahci_do_softreset() Tejun Heo
2007-07-12 20:26   ` Jeff Garzik
2007-07-01 10:54 ` [PATCH 10/15] libata-pmp: implement qc_defer for command switching PMP support Tejun Heo
2007-07-01 10:54 ` [PATCH 11/15] ahci: use deadline instead of fixed timeout for 1st FIS for SRST Tejun Heo
2007-07-01 10:54 ` Tejun Heo [this message]
2007-07-12 20:26   ` [PATCH 12/15] ahci: separate out ahci_kick_engine() Jeff Garzik
2007-07-01 10:54 ` [PATCH 13/15] ahci: separate out ahci_exec_polled_cmd() Tejun Heo
2007-07-12 20:26   ` Jeff Garzik
2007-07-01 10:54 ` [PATCH 15/15] ahci: implement PMP support Tejun Heo
2007-07-03  7:39 ` [PATCHSET 4/4] implement PMP support, take 4 Jim Paris
2007-07-03  9:34   ` Tejun Heo
2007-07-03 19:40     ` Jim Paris
2007-07-12 20:27 ` Jeff Garzik

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=11832872563253-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=forrest.zhao@gmail.com \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    /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).