Patchwork [v2] ahci: fix pmp softreset with HDD

login
register
mail settings
Submitter Yuan-Hsin Chen
Date June 15, 2011, 10:04 a.m.
Message ID <1308132252-1981-1-git-send-email-yuanlmm@gmail.com>
Download mbox | patch
Permalink /patch/100505/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Yuan-Hsin Chen - June 15, 2011, 10:04 a.m.
From: Yuan-Hsin Chen <yhchen@faraday-tech.com>

When enabling both port multiplier and platform ahci sata,
ahci times out while connecting to HDD directly. This is
because soft reset fails with IPMS set. Do soft reset
again to port 0.

The soft reset sequence is copied from ahci.c.

Signed-off-by: Yuan-Hsin Chen <yhchen@faraday-tech.com>
---
v2:
1.add ahci_pmp_softreset function and ahci_pmp_ops to libahci.c
2.add SATA_PMP_RST to Kconfig

 drivers/ata/Kconfig         |   10 +++++++
 drivers/ata/ahci.h          |    1 +
 drivers/ata/ahci_platform.c |    4 +++
 drivers/ata/libahci.c       |   59 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 0 deletions(-)
Tejun Heo - June 15, 2011, 10:14 a.m.
Hello,

On Wed, Jun 15, 2011 at 06:04:12PM +0800, Yuan-Hsin Chen wrote:
> From: Yuan-Hsin Chen <yhchen@faraday-tech.com>
> 
> When enabling both port multiplier and platform ahci sata,
> ahci times out while connecting to HDD directly. This is
> because soft reset fails with IPMS set. Do soft reset
> again to port 0.
> 
> The soft reset sequence is copied from ahci.c.
> 
> Signed-off-by: Yuan-Hsin Chen <yhchen@faraday-tech.com>

Getting closer.

> +config SATA_PMP_RST
> +	bool "SATA PMP softreset"
> +	depends on SATA_PMP
> +	default n
> +	help
> +	  When enabling both port multiplier and platform ahci sata,
> +	  ahci times out while connecting to HDD directly in some
> +	  ahci controller. This is because soft reset fails with
> +	  IPMS set. Do soft reset again to port 0.
> +

Hmmm... Is there any way to detect the specific controller from
ahci_platform.c?  This is workaround for a controller bug.  It should
be enabled automatically.  Making it a config option doesn't make
whole lot of sense.

> @@ -1329,6 +1338,56 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
>  }
>  EXPORT_SYMBOL_GPL(ahci_do_softreset);
>  
> +static int ahci_pmp_check_ready(struct ata_link *link)
> +{
> +	void __iomem *port_mmio = ahci_port_base(link->ap);
> +	u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
> +	u32 irq_status = readl(port_mmio + PORT_IRQ_STAT);
> +
> +	/*
> +	 * There is no need to check TFDATA if BAD PMP is found due to HW bug,
> +	 * which can save timeout delay.
> +	 */
> +	if (irq_status & PORT_IRQ_BAD_PMP)
> +		return -EIO;
> +
> +	printk("%s:TFT 0x%x\n", __func__, status);
> +	return ata_check_ready(status);
> +}
> +
> +static int ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
> +				unsigned long deadline)
> +{
> +	struct ata_port *ap = link->ap;
> +	void __iomem *port_mmio = ahci_port_base(ap);
> +	int pmp = sata_srst_pmp(link);
> +	int rc;
> +	u32 irq_sts;
> +
> +	DPRINTK("ENTER\n");
> +
> +	rc = ahci_do_softreset(link, class, pmp, deadline,
> +			       ahci_pmp_check_ready);
> +
> +	/*
> +	 * Soft reset fails with IPMS set when PMP is enabled but
> +	 * SATA HDD/ODD is connected to SATA port, do soft reset
> +	 * again to port 0.
> +	 */
> +	if (rc == -EIO) {
> +		irq_sts = readl(port_mmio + PORT_IRQ_STAT);
> +		if (irq_sts & PORT_IRQ_BAD_PMP) {
> +			ata_link_printk(link, KERN_WARNING,
> +					"applying PMP SRST workaround "
> +					"and retrying\n");
> +			rc = ahci_do_softreset(link, class, 0, deadline,
> +					       ahci_check_ready);
> +		}
> +	}
> +
> +	return rc;
> +}

Please make two separate patches.  One to rename & move sb600 ops to
libahci.c and another to use it for platform.  There's no reason to
have two identical sets of functions doing the same thing.

Thanks.

Patch

diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 75afa75..a6681df 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -65,6 +65,16 @@  config SATA_PMP
 	  This option adds support for SATA Port Multipliers
 	  (the SATA version of an ethernet hub, or SAS expander).
 
+config SATA_PMP_RST
+	bool "SATA PMP softreset"
+	depends on SATA_PMP
+	default n
+	help
+	  When enabling both port multiplier and platform ahci sata,
+	  ahci times out while connecting to HDD directly in some
+	  ahci controller. This is because soft reset fails with
+	  IPMS set. Do soft reset again to port 0.
+
 comment "Controllers with non-SFF native interface"
 
 config SATA_AHCI
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 12c5282..e20f8d7 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -312,6 +312,7 @@  extern struct device_attribute *ahci_sdev_attrs[];
 	.sdev_attrs		= ahci_sdev_attrs
 
 extern struct ata_port_operations ahci_ops;
+extern struct ata_port_operations ahci_pmp_ops;
 
 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
 			u32 opts);
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 6fef1fa..1c6dc16 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -35,7 +35,11 @@  static int __init ahci_probe(struct platform_device *pdev)
 		.flags		= AHCI_FLAG_COMMON,
 		.pio_mask	= ATA_PIO4,
 		.udma_mask	= ATA_UDMA6,
+#ifdef CONFIG_SATA_PMP_RST
+		.port_ops	= &ahci_pmp_ops,
+#else
 		.port_ops	= &ahci_ops,
+#endif
 	};
 	const struct ata_port_info *ppi[] = { &pi, NULL };
 	struct ahci_host_priv *hpriv;
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index d38c40f..c4cbee9 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -82,6 +82,8 @@  static void ahci_pmp_attach(struct ata_port *ap);
 static void ahci_pmp_detach(struct ata_port *ap);
 static int ahci_softreset(struct ata_link *link, unsigned int *class,
 			  unsigned long deadline);
+static int ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
+			  unsigned long deadline);
 static int ahci_hardreset(struct ata_link *link, unsigned int *class,
 			  unsigned long deadline);
 static void ahci_postreset(struct ata_link *link, unsigned int *class);
@@ -141,6 +143,13 @@  struct device_attribute *ahci_sdev_attrs[] = {
 };
 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
 
+struct ata_port_operations ahci_pmp_ops = {
+	.inherits		= &ahci_ops,
+	.softreset		= ahci_pmp_softreset,
+	.pmp_softreset		= ahci_pmp_softreset,
+};
+EXPORT_SYMBOL_GPL(ahci_pmp_ops);
+
 struct ata_port_operations ahci_ops = {
 	.inherits		= &sata_pmp_port_ops,
 
@@ -1329,6 +1338,56 @@  static int ahci_softreset(struct ata_link *link, unsigned int *class,
 }
 EXPORT_SYMBOL_GPL(ahci_do_softreset);
 
+static int ahci_pmp_check_ready(struct ata_link *link)
+{
+	void __iomem *port_mmio = ahci_port_base(link->ap);
+	u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
+	u32 irq_status = readl(port_mmio + PORT_IRQ_STAT);
+
+	/*
+	 * There is no need to check TFDATA if BAD PMP is found due to HW bug,
+	 * which can save timeout delay.
+	 */
+	if (irq_status & PORT_IRQ_BAD_PMP)
+		return -EIO;
+
+	printk("%s:TFT 0x%x\n", __func__, status);
+	return ata_check_ready(status);
+}
+
+static int ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
+				unsigned long deadline)
+{
+	struct ata_port *ap = link->ap;
+	void __iomem *port_mmio = ahci_port_base(ap);
+	int pmp = sata_srst_pmp(link);
+	int rc;
+	u32 irq_sts;
+
+	DPRINTK("ENTER\n");
+
+	rc = ahci_do_softreset(link, class, pmp, deadline,
+			       ahci_pmp_check_ready);
+
+	/*
+	 * Soft reset fails with IPMS set when PMP is enabled but
+	 * SATA HDD/ODD is connected to SATA port, do soft reset
+	 * again to port 0.
+	 */
+	if (rc == -EIO) {
+		irq_sts = readl(port_mmio + PORT_IRQ_STAT);
+		if (irq_sts & PORT_IRQ_BAD_PMP) {
+			ata_link_printk(link, KERN_WARNING,
+					"applying PMP SRST workaround "
+					"and retrying\n");
+			rc = ahci_do_softreset(link, class, 0, deadline,
+					       ahci_check_ready);
+		}
+	}
+
+	return rc;
+}
+
 static int ahci_hardreset(struct ata_link *link, unsigned int *class,
 			  unsigned long deadline)
 {