linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/05] libata: separate out ata_sata_print_link_status
@ 2005-12-19 13:35 Tejun Heo
  2005-12-19 13:35 ` [PATCH 02/05] libata: export ata_busy_sleep Tejun Heo
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tejun Heo @ 2005-12-19 13:35 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-ide

Separate out ata_sata_print_link_status() from __sata_phy_reset().

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 9ea1025..fb1e186 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1466,6 +1466,41 @@ void ata_port_probe(struct ata_port *ap)
 }
 
 /**
+ *	ata_sata_print_link_status - Print SATA link status
+ *	@ap: SATA port to printk link status about
+ *
+ *	This function prints link speed and status of a SATA link.
+ *
+ *	LOCKING:
+ *	None.
+ */
+void ata_sata_print_link_status(struct ata_port *ap)
+{
+	u32 sstatus, tmp;
+	const char *speed;
+
+	if (!ap->ops->scr_read)
+		return;
+
+	sstatus = scr_read(ap, SCR_STATUS);
+
+	if (sata_dev_present(ap)) {
+		tmp = (sstatus >> 4) & 0xf;
+		if (tmp & (1 << 0))
+			speed = "1.5";
+		else if (tmp & (1 << 1))
+			speed = "3.0";
+		else
+			speed = "<unknown>";
+		printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n",
+		       ap->id, speed, sstatus);
+	} else {
+		printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n",
+		       ap->id, sstatus);
+	}
+}
+
+/**
  *	__sata_phy_reset - Wake/reset a low-level SATA PHY
  *	@ap: SATA port associated with target SATA PHY.
  *
@@ -1499,27 +1534,14 @@ void __sata_phy_reset(struct ata_port *a
 			break;
 	} while (time_before(jiffies, timeout));
 
-	/* TODO: phy layer with polling, timeouts, etc. */
-	sstatus = scr_read(ap, SCR_STATUS);
-	if (sata_dev_present(ap)) {
-		const char *speed;
-		u32 tmp;
+	/* print link status */
+	ata_sata_print_link_status(ap);
 
-		tmp = (sstatus >> 4) & 0xf;
-		if (tmp & (1 << 0))
-			speed = "1.5";
-		else if (tmp & (1 << 1))
-			speed = "3.0";
-		else
-			speed = "<unknown>";
-		printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n",
-		       ap->id, speed, sstatus);
+	/* TODO: phy layer with polling, timeouts, etc. */
+	if (sata_dev_present(ap))
 		ata_port_probe(ap);
-	} else {
-		printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n",
-		       ap->id, sstatus);
+	else
 		ata_port_disable(ap);
-	}
 
 	if (ap->flags & ATA_FLAG_PORT_DISABLED)
 		return;
@@ -4980,6 +5002,7 @@ EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear);
 EXPORT_SYMBOL_GPL(ata_bmdma_status);
 EXPORT_SYMBOL_GPL(ata_bmdma_stop);
 EXPORT_SYMBOL_GPL(ata_port_probe);
+EXPORT_SYMBOL_GPL(ata_sata_print_link_status);
 EXPORT_SYMBOL_GPL(sata_phy_reset);
 EXPORT_SYMBOL_GPL(__sata_phy_reset);
 EXPORT_SYMBOL_GPL(ata_bus_reset);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index e828e17..7e38705 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -427,6 +427,7 @@ struct ata_timing {
 #define FIT(v,vmin,vmax)	max_t(short,min_t(short,v,vmax),vmin)
 
 extern void ata_port_probe(struct ata_port *);
+extern void ata_sata_print_link_status(struct ata_port *ap);
 extern void __sata_phy_reset(struct ata_port *ap);
 extern void sata_phy_reset(struct ata_port *ap);
 extern void ata_bus_reset(struct ata_port *ap);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 02/05] libata: export ata_busy_sleep
  2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
@ 2005-12-19 13:35 ` Tejun Heo
  2005-12-19 13:36 ` [PATCH 03/05] ahci: separate out ahci_stop/start_engine Tejun Heo
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2005-12-19 13:35 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-ide

Export ata_busy_sleep().

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index fb1e186..b03d412 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -61,9 +61,6 @@
 
 #include "libata.h"
 
-static unsigned int ata_busy_sleep (struct ata_port *ap,
-				    unsigned long tmout_pat,
-			    	    unsigned long tmout);
 static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev);
 static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
 static void ata_set_mode(struct ata_port *ap);
@@ -1896,9 +1893,8 @@ err_out:
  *
  */
 
-static unsigned int ata_busy_sleep (struct ata_port *ap,
-				    unsigned long tmout_pat,
-			    	    unsigned long tmout)
+unsigned int ata_busy_sleep (struct ata_port *ap,
+			     unsigned long tmout_pat, unsigned long tmout)
 {
 	unsigned long timer_start, timeout;
 	u8 status;
@@ -5008,6 +5004,7 @@ EXPORT_SYMBOL_GPL(__sata_phy_reset);
 EXPORT_SYMBOL_GPL(ata_bus_reset);
 EXPORT_SYMBOL_GPL(ata_port_disable);
 EXPORT_SYMBOL_GPL(ata_ratelimit);
+EXPORT_SYMBOL_GPL(ata_busy_sleep);
 EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
 EXPORT_SYMBOL_GPL(ata_scsi_error);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 7e38705..d90909c 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -447,6 +447,9 @@ extern int ata_scsi_error(struct Scsi_Ho
 extern int ata_scsi_release(struct Scsi_Host *host);
 extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
 extern int ata_ratelimit(void);
+extern unsigned int ata_busy_sleep(struct ata_port *ap,
+				   unsigned long timeout_pat,
+				   unsigned long timeout);
 
 /*
  * Default driver ops implementations

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 03/05] ahci: separate out ahci_stop/start_engine
  2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
  2005-12-19 13:35 ` [PATCH 02/05] libata: export ata_busy_sleep Tejun Heo
@ 2005-12-19 13:36 ` Tejun Heo
  2005-12-19 13:37 ` [PATCH 04/05] ahci: separate out ahci_dev_classify Tejun Heo
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2005-12-19 13:36 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-ide

Separate out ahci_stop/start_engine().

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 887eaa2..085d749 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -437,6 +437,43 @@ static void ahci_scr_write (struct ata_p
 	writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
 }
 
+static int ahci_stop_engine(struct ata_port *ap)
+{
+	void __iomem *mmio = ap->host_set->mmio_base;
+	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+	int work;
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_CMD);
+	tmp &= ~PORT_CMD_START;
+	writel(tmp, port_mmio + PORT_CMD);
+
+	/* wait for engine to stop.  TODO: this could be
+	 * as long as 500 msec
+	 */
+	work = 1000;
+	while (work-- > 0) {
+		tmp = readl(port_mmio + PORT_CMD);
+		if ((tmp & PORT_CMD_LIST_ON) == 0)
+			return 0;
+		udelay(10);
+	}
+
+	return -EIO;
+}
+
+static void ahci_start_engine(struct ata_port *ap)
+{
+	void __iomem *mmio = ap->host_set->mmio_base;
+	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_CMD);
+	tmp |= PORT_CMD_START;
+	writel(tmp, port_mmio + PORT_CMD);
+	readl(port_mmio + PORT_CMD); /* flush */
+}
+
 static void ahci_phy_reset(struct ata_port *ap)
 {
 	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
@@ -563,7 +600,6 @@ static void ahci_restart_port(struct ata
 	void __iomem *mmio = ap->host_set->mmio_base;
 	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
 	u32 tmp;
-	int work;
 
 	if ((ap->device[0].class != ATA_DEV_ATAPI) ||
 	    ((irq_stat & PORT_IRQ_TF_ERR) == 0))
@@ -579,20 +615,7 @@ static void ahci_restart_port(struct ata
 			readl(port_mmio + PORT_SCR_ERR));
 
 	/* stop DMA */
-	tmp = readl(port_mmio + PORT_CMD);
-	tmp &= ~PORT_CMD_START;
-	writel(tmp, port_mmio + PORT_CMD);
-
-	/* wait for engine to stop.  TODO: this could be
-	 * as long as 500 msec
-	 */
-	work = 1000;
-	while (work-- > 0) {
-		tmp = readl(port_mmio + PORT_CMD);
-		if ((tmp & PORT_CMD_LIST_ON) == 0)
-			break;
-		udelay(10);
-	}
+	ahci_stop_engine(ap);
 
 	/* clear SATA phy error, if any */
 	tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -611,10 +634,7 @@ static void ahci_restart_port(struct ata
 	}
 
 	/* re-start DMA */
-	tmp = readl(port_mmio + PORT_CMD);
-	tmp |= PORT_CMD_START;
-	writel(tmp, port_mmio + PORT_CMD);
-	readl(port_mmio + PORT_CMD); /* flush */
+	ahci_start_engine(ap);
 }
 
 static void ahci_eng_timeout(struct ata_port *ap)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 04/05] ahci: separate out ahci_dev_classify
  2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
  2005-12-19 13:35 ` [PATCH 02/05] libata: export ata_busy_sleep Tejun Heo
  2005-12-19 13:36 ` [PATCH 03/05] ahci: separate out ahci_stop/start_engine Tejun Heo
@ 2005-12-19 13:37 ` Tejun Heo
  2005-12-19 13:38 ` [PATCH 05/05] ahci: rewrite ahci_phy_reset Tejun Heo
  2006-01-18  0:49 ` [PATCH 01/05] libata: separate out ata_sata_print_link_status Jeff Garzik
  4 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2005-12-19 13:37 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-ide

Separate out ahci_dev_classify().

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 085d749..463456a 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -474,10 +474,24 @@ static void ahci_start_engine(struct ata
 	readl(port_mmio + PORT_CMD); /* flush */
 }
 
-static void ahci_phy_reset(struct ata_port *ap)
+static unsigned int ahci_dev_classify(struct ata_port *ap)
 {
 	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
 	struct ata_taskfile tf;
+	u32 tmp;
+
+	tmp = readl(port_mmio + PORT_SIG);
+	tf.lbah		= (tmp >> 24)	& 0xff;
+	tf.lbam		= (tmp >> 16)	& 0xff;
+	tf.lbal		= (tmp >> 8)	& 0xff;
+	tf.nsect	= (tmp)		& 0xff;
+
+	return ata_dev_classify(&tf);
+}
+
+static void ahci_phy_reset(struct ata_port *ap)
+{
+	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
 	struct ata_device *dev = &ap->device[0];
 	u32 new_tmp, tmp;
 
@@ -486,13 +500,7 @@ static void ahci_phy_reset(struct ata_po
 	if (ap->flags & ATA_FLAG_PORT_DISABLED)
 		return;
 
-	tmp = readl(port_mmio + PORT_SIG);
-	tf.lbah		= (tmp >> 24)	& 0xff;
-	tf.lbam		= (tmp >> 16)	& 0xff;
-	tf.lbal		= (tmp >> 8)	& 0xff;
-	tf.nsect	= (tmp)		& 0xff;
-
-	dev->class = ata_dev_classify(&tf);
+	dev->class = ahci_dev_classify(ap);
 	if (!ata_dev_present(dev)) {
 		ata_port_disable(ap);
 		return;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 05/05] ahci: rewrite ahci_phy_reset
  2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
                   ` (2 preceding siblings ...)
  2005-12-19 13:37 ` [PATCH 04/05] ahci: separate out ahci_dev_classify Tejun Heo
@ 2005-12-19 13:38 ` Tejun Heo
  2006-01-18  0:49 ` [PATCH 01/05] libata: separate out ata_sata_print_link_status Jeff Garzik
  4 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2005-12-19 13:38 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-ide

Rewrite ahci_phy_reset such that engine is stopped while phy reset is
in progress as AHCI specification mandates.

Signed-off-by: Tejun Heo <htejun@gmail.com>

diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 463456a..eece762 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -489,22 +489,72 @@ static unsigned int ahci_dev_classify(st
 	return ata_dev_classify(&tf);
 }
 
+static int ahci_wait_for_bit(void __iomem *reg, u32 mask, u32 val,
+			     unsigned long interval_msec,
+			     unsigned long timeout_msec)
+{
+	unsigned long timeout;
+	u32 tmp;
+
+	timeout = jiffies + (timeout_msec * HZ) / 1000;
+	do {
+		tmp = readl(reg);
+		if ((tmp & mask) != val)
+			return 0;
+		msleep(interval_msec);
+	} while (time_before(jiffies, timeout));
+
+	return -1;
+}
+
 static void ahci_phy_reset(struct ata_port *ap)
 {
-	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
+	void __iomem *mmio = ap->host_set->mmio_base;
+	void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
 	struct ata_device *dev = &ap->device[0];
 	u32 new_tmp, tmp;
 
-	__sata_phy_reset(ap);
+	/* stop engine */
+	ahci_stop_engine(ap);
 
-	if (ap->flags & ATA_FLAG_PORT_DISABLED)
-		return;
+	/* Issue COMRESET.  On AHCI, DET bits are cleared by COMRESET
+	 * and it may take quite some millisecs before they are turned
+	 * on again.  Wait longer if device is present.
+	 */
+	tmp = readl(port_mmio + PORT_SCR_STAT);
+
+	writel(0x301, port_mmio + PORT_SCR_CTL);
+	readl(port_mmio + PORT_SCR_CTL); /* flush */
+	msleep(1);
+	writel(0x300, port_mmio + PORT_SCR_CTL);
+	readl(port_mmio + PORT_SCR_CTL); /* flush */
+
+	msleep(200);
+	if (tmp & 0xf)
+		ahci_wait_for_bit(port_mmio + PORT_SCR_STAT, 0xf, 0x0, 10, 5000);
+	ahci_wait_for_bit(port_mmio + PORT_SCR_STAT, 0xf, 0x1, 10, 5000);
+
+	/* clear SATA phy error, if any */
+	tmp = readl(port_mmio + PORT_SCR_ERR);
+	writel(tmp, port_mmio + PORT_SCR_ERR);
+
+	/* re-start engine */
+	ahci_start_engine(ap);
+
+	/* print link status & classify */
+	ata_sata_print_link_status(ap);
+
+	if (!sata_dev_present(ap))
+		goto out_disable;
+
+	if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT))
+		goto out_disable;
 
 	dev->class = ahci_dev_classify(ap);
-	if (!ata_dev_present(dev)) {
-		ata_port_disable(ap);
-		return;
-	}
+	if (!ata_dev_present(dev))
+		goto out_disable;
+
+	ata_port_probe(ap);
 
 	/* Make sure port's ATAPI bit is set appropriately */
 	new_tmp = tmp = readl(port_mmio + PORT_CMD);
@@ -516,6 +566,12 @@ static void ahci_phy_reset(struct ata_po
 		writel(new_tmp, port_mmio + PORT_CMD);
 		readl(port_mmio + PORT_CMD); /* flush */
 	}
+
+	ap->cbl = ATA_CBL_SATA;
+	return;
+
+ out_disable:
+	ata_port_disable(ap);
 }
 
 static u8 ahci_check_status(struct ata_port *ap)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 01/05] libata: separate out ata_sata_print_link_status
  2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
                   ` (3 preceding siblings ...)
  2005-12-19 13:38 ` [PATCH 05/05] ahci: rewrite ahci_phy_reset Tejun Heo
@ 2006-01-18  0:49 ` Jeff Garzik
  4 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2006-01-18  0:49 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-ide

Tejun Heo wrote:
> Separate out ata_sata_print_link_status() from __sata_phy_reset().
> 
> Signed-off-by: Tejun Heo <htejun@gmail.com>

applied patches 1, 3, 4 to 'upstream-2.6.17' branch


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-01-18  0:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-19 13:35 [PATCH 01/05] libata: separate out ata_sata_print_link_status Tejun Heo
2005-12-19 13:35 ` [PATCH 02/05] libata: export ata_busy_sleep Tejun Heo
2005-12-19 13:36 ` [PATCH 03/05] ahci: separate out ahci_stop/start_engine Tejun Heo
2005-12-19 13:37 ` [PATCH 04/05] ahci: separate out ahci_dev_classify Tejun Heo
2005-12-19 13:38 ` [PATCH 05/05] ahci: rewrite ahci_phy_reset Tejun Heo
2006-01-18  0:49 ` [PATCH 01/05] libata: separate out ata_sata_print_link_status Jeff Garzik

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).