2011-06-14 05:49:08

by Yuan-Hsin Chen

[permalink] [raw]
Subject: [PATCH] ahci: enable pmp but connected to HDD issue fixed

From: Yuan-Hsin Chen <[email protected]>

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 <[email protected]>
---
drivers/ata/ahci_platform.c | 62 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 6fef1fa..6eab716 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -27,6 +27,66 @@ static struct scsi_host_template ahci_platform_sht = {
AHCI_SHT("ahci_platform"),
};

+static int ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
+ unsigned long deadline);
+
+static struct ata_port_operations ahci_pmp_ops = {
+ .inherits = &ahci_ops,
+ .softreset = ahci_pmp_softreset,
+ .pmp_softreset = ahci_pmp_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 __init ahci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -35,7 +95,7 @@ static int __init ahci_probe(struct platform_device *pdev)
.flags = AHCI_FLAG_COMMON,
.pio_mask = ATA_PIO4,
.udma_mask = ATA_UDMA6,
- .port_ops = &ahci_ops,
+ .port_ops = &ahci_pmp_ops,
};
const struct ata_port_info *ppi[] = { &pi, NULL };
struct ahci_host_priv *hpriv;
--
1.7.3.1


2011-06-14 06:52:20

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] ahci: enable pmp but connected to HDD issue fixed

On Tue, Jun 14, 2011 at 01:48:24PM +0800, Yuan-Hsin Chen wrote:
> From: Yuan-Hsin Chen <[email protected]>
>
> 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.

This is the same one as ahci_sb600_softreset(), right? Please don't
copy & paste like that. Rename and ahci_sb600_softreset() to
libahci.c, create a separate ata_port_operations for it and use the
ops for the affected controllers.

Thanks.

--
tejun

2011-06-15 10:04:53

by Yuan-Hsin Chen

[permalink] [raw]
Subject: [PATCH v2] ahci: fix pmp softreset with HDD

From: Yuan-Hsin Chen <[email protected]>

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 <[email protected]>
---
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(-)

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)
{
--
1.7.3.1

2011-06-15 10:14:44

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v2] ahci: fix pmp softreset with HDD

Hello,

On Wed, Jun 15, 2011 at 06:04:12PM +0800, Yuan-Hsin Chen wrote:
> From: Yuan-Hsin Chen <[email protected]>
>
> 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 <[email protected]>

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.

--
tejun

2011-06-17 10:40:11

by Yuan-Hsin Chen

[permalink] [raw]
Subject: [PATCH v3] ahci: move ahci_sb600_softreset to libahci.c and rename it

From: Yuan-Hsin Chen <[email protected]>

ahci_sb600_softreset was in ahci.c. This function is used
to fix soft reset failure and renames as ahci_pmp_softreset
in libahci.c.

Signed-off-by: Yuan-Hsin Chen <[email protected]>
---
v3:
Move ahci_sb600_softreset to libahci.c and rename it.
Add ahci_pmp_ops to libahci.c
Add following stuff in your platform dependent code to use ahci_pmp_ops

#include <linux/ahci_platform.h>
#include <../../../drivers/ata/ahci.h>

static struct ata_port_info ftsata100_pi =
.flags = AHCI_FLAG_COMMON,
.pio_mask = ATA_PIO4,
.udma_mask = ATA_UDMA6,
.port_ops = &ahci_pmp_ops,
};

static struct ahci_platform_data ftsata100_pdata = {
.ata_port_info = &ftsata100_pi,
};

static struct platform_device ftsata100_device = {
...
.dev = {
...
.platform_data = &ftsata100_pdata,
},
};

drivers/ata/ahci.c | 55 +--------------------------------------------
drivers/ata/ahci.h | 1 +
drivers/ata/libahci.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 71afe03..c67f621 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -79,8 +79,6 @@ enum board_ids {
};

static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
-static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
- unsigned long deadline);
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline);
static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
@@ -106,8 +104,8 @@ static struct ata_port_operations ahci_p5wdh_ops = {

static struct ata_port_operations ahci_sb600_ops = {
.inherits = &ahci_ops,
- .softreset = ahci_sb600_softreset,
- .pmp_softreset = ahci_sb600_softreset,
+ .softreset = ahci_pmp_softreset,
+ .pmp_softreset = ahci_pmp_softreset,
};

#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
@@ -502,55 +500,6 @@ static void ahci_pci_init_controller(struct ata_host *host)
ahci_init_controller(host);
}

-static int ahci_sb600_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;
-
- return ata_check_ready(status);
-}
-
-static int ahci_sb600_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_sb600_check_ready);
-
- /*
- * Soft reset fails on some ATI chips 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 SB600 PMP SRST workaround "
- "and retrying\n");
- rc = ahci_do_softreset(link, class, 0, deadline,
- ahci_check_ready);
- }
- }
-
- return rc;
-}
-
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline)
{
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/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)
{
--
1.7.3.1

2011-06-17 11:35:31

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v3] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello.

On 17-06-2011 14:39, Yuan-Hsin Chen wrote:

> From: Yuan-Hsin Chen<[email protected]>

> ahci_sb600_softreset was in ahci.c. This function is used
> to fix soft reset failure and renames as ahci_pmp_softreset
> in libahci.c.

> Signed-off-by: Yuan-Hsin Chen<[email protected]>
> ---
> v3:
> Move ahci_sb600_softreset to libahci.c and rename it.
> Add ahci_pmp_ops to libahci.c
> Add following stuff in your platform dependent code to use ahci_pmp_ops

> #include <linux/ahci_platform.h>
> #include<../../../drivers/ata/ahci.h>
>
> static struct ata_port_info ftsata100_pi =
> .flags = AHCI_FLAG_COMMON,
> .pio_mask = ATA_PIO4,
> .udma_mask = ATA_UDMA6,
> .port_ops = &ahci_pmp_ops,
> };
>
> static struct ahci_platform_data ftsata100_pdata = {
> .ata_port_info =&ftsata100_pi,
> };
>
> static struct platform_device ftsata100_device = {
> ...
> .dev = {
> ...
> .platform_data =&ftsata100_pdata,
> },
> };

> drivers/ata/ahci.c | 55 +--------------------------------------------
> drivers/ata/ahci.h | 1 +
> drivers/ata/libahci.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 62 insertions(+), 53 deletions(-)

> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 71afe03..c67f621 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
[...]
> @@ -106,8 +104,8 @@ static struct ata_port_operations ahci_p5wdh_ops = {
>
> static struct ata_port_operations ahci_sb600_ops = {
> .inherits =&ahci_ops,
> - .softreset = ahci_sb600_softreset,
> - .pmp_softreset = ahci_sb600_softreset,
> + .softreset = ahci_pmp_softreset,
> + .pmp_softreset = ahci_pmp_softreset,
> };
>
> #define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
[...]
> 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);

How come it's 'static' when you use it in ahci.c?

> 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);
[...]
> @@ -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);

printk() should have a logging facility. Here you should have probably
used pr_debug()...

WBR, Sergei

2011-06-17 12:07:12

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v3] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello, Yuan-Hsin.

Yeap, we're getting almost there. :)

On Fri, Jun 17, 2011 at 06:39:18PM +0800, Yuan-Hsin Chen wrote:
> 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;

But I don't like ahci_pmp_ops name. ahci_ops works just fine for pmp.
It's a workaround ops. Maybe something like ahci_pmp_retry_srst_ops?

> +static int ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
> + unsigned long deadline);

Similarly, ahci_pmp_retry_srst_softreset()

> +struct ata_port_operations ahci_pmp_ops = {
> + .inherits = &ahci_ops,
> + .softreset = ahci_pmp_softreset,
> + .pmp_softreset = ahci_pmp_softreset,
> +};

Isn't overriding .softreset enough? .pmp_softreset is used only for
downstream links.

> +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);

You probably want ata_link_printk(link, KERN_DEBUG, ...);

Thanks.

--
tejun

2011-06-20 08:07:20

by Yuan-Hsin Chen

[permalink] [raw]
Subject: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

From: Yuan-Hsin Chen <[email protected]>

ahci_sb600_softreset was in ahci.c. This function is used
to fix soft reset failure and renames as ahci_pmp_retry_srst_softreset
in libahci.c.
---
drivers/ata/ahci.c | 54 +---------------------------------------------
drivers/ata/ahci.h | 1 +
drivers/ata/libahci.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 53 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 71afe03..2de36b6 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -79,8 +79,6 @@ enum board_ids {
};

static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
-static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
- unsigned long deadline);
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline);
static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
@@ -106,8 +104,7 @@ static struct ata_port_operations ahci_p5wdh_ops = {

static struct ata_port_operations ahci_sb600_ops = {
.inherits = &ahci_ops,
- .softreset = ahci_sb600_softreset,
- .pmp_softreset = ahci_sb600_softreset,
+ .softreset = ahci_pmp_retry_srst_softreset,
};

#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
@@ -502,55 +499,6 @@ static void ahci_pci_init_controller(struct ata_host *host)
ahci_init_controller(host);
}

-static int ahci_sb600_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;
-
- return ata_check_ready(status);
-}
-
-static int ahci_sb600_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_sb600_check_ready);
-
- /*
- * Soft reset fails on some ATI chips 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 SB600 PMP SRST workaround "
- "and retrying\n");
- rc = ahci_do_softreset(link, class, 0, deadline,
- ahci_check_ready);
- }
- }
-
- return rc;
-}
-
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline)
{
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 12c5282..b175000 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_retry_srst_ops;

void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
u32 opts);
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index d38c40f..0fd5a30 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_retry_srst_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,12 @@ struct device_attribute *ahci_sdev_attrs[] = {
};
EXPORT_SYMBOL_GPL(ahci_sdev_attrs);

+struct ata_port_operations ahci_pmp_retry_srst_ops = {
+ .inherits = &ahci_ops,
+ .softreset = ahci_pmp_retry_srst_softreset,
+};
+EXPORT_SYMBOL_GPL(ahci_pmp_retry_srst_ops);
+
struct ata_port_operations ahci_ops = {
.inherits = &sata_pmp_port_ops,

@@ -1329,6 +1337,55 @@ 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;
+
+ return ata_check_ready(status);
+}
+
+static int ahci_pmp_retry_srst_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)
{
--
1.7.3.1

2011-06-20 08:16:32

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello.

On 20-06-2011 12:06, Yuan-Hsin Chen wrote:

> From: Yuan-Hsin Chen<[email protected]>

> ahci_sb600_softreset was in ahci.c. This function is used
> to fix soft reset failure and renames as ahci_pmp_retry_srst_softreset
> in libahci.c.

> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 71afe03..2de36b6 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -79,8 +79,6 @@ enum board_ids {
> };
>
> static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
> -static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
> - unsigned long deadline);
> static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
> unsigned long deadline);
> static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
> @@ -106,8 +104,7 @@ static struct ata_port_operations ahci_p5wdh_ops = {
>
> static struct ata_port_operations ahci_sb600_ops = {
> .inherits =&ahci_ops,
> - .softreset = ahci_sb600_softreset,
> - .pmp_softreset = ahci_sb600_softreset,
> + .softreset = ahci_pmp_retry_srst_softreset,

I have to ask you again: have you tried to compile this?

> diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
> index d38c40f..0fd5a30 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_retry_srst_softreset(struct ata_link *link, unsigned int *class,
> + unsigned long deadline);

How come this is static if you reference it outside this module?

WBR, Sergei

2011-06-20 08:19:45

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello, Yuan.

Yeap, almost there, just few very minor things. :)

On Mon, Jun 20, 2011 at 04:06:41PM +0800, Yuan-Hsin Chen wrote:
> static struct ata_port_operations ahci_sb600_ops = {
> .inherits = &ahci_ops,
> - .softreset = ahci_sb600_softreset,
> - .pmp_softreset = ahci_sb600_softreset,
> + .softreset = ahci_pmp_retry_srst_softreset,
> };

Why doesn't sb600 just use ahci_pmp_retry_srst_ops?

> @@ -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_retry_srst_ops;

Heh, I know I suggested that name but that is one ugly name. If
anyone has any better idea, please come forward.

> @@ -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_retry_srst_softreset(struct ata_link *link, unsigned int *class,
> + unsigned long deadline);

srst equals softreset, so ahci_pmp_retry_softreset() should do.

> +struct ata_port_operations ahci_pmp_retry_srst_ops = {
> + .inherits = &ahci_ops,
> + .softreset = ahci_pmp_retry_srst_softreset,
> +};
> +EXPORT_SYMBOL_GPL(ahci_pmp_retry_srst_ops);
> +
> struct ata_port_operations ahci_ops = {
> .inherits = &sata_pmp_port_ops,

Maybe it's better to place ahci_pmp_retry_srst_ops after ahci_ops?

> +static int ahci_pmp_check_ready(struct ata_link *link)

It would be better if the name reflects that it's not for specific
workaround.

Thank you.

--
tejun

2011-06-20 08:47:16

by Yuan-Hsin Chen

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello.
I'm really sorry for ignoring your previous e-mail.
I'll fix it in the next patch. Thanks for reviewing my patch.

Yuan-Hsin

On Mon, Jun 20, 2011 at 4:15 PM, Sergei Shtylyov <[email protected]> wrote:
> Hello.
>
> On 20-06-2011 12:06, Yuan-Hsin Chen wrote:
>
>> From: Yuan-Hsin Chen<[email protected]>
>
>> ahci_sb600_softreset was in ahci.c. This function is used
>> to fix soft reset failure and renames as ahci_pmp_retry_srst_softreset
>> in libahci.c.
>
>> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
>> index 71afe03..2de36b6 100644
>> --- a/drivers/ata/ahci.c
>> +++ b/drivers/ata/ahci.c
>> @@ -79,8 +79,6 @@ enum board_ids {
>> ?};
>>
>> ?static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id
>> *ent);
>> -static int ahci_sb600_softreset(struct ata_link *link, unsigned int
>> *class,
>> - ? ? ? ? ? ? ? ? ? ? ? ? unsigned long deadline);
>> ?static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int
>> *class,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned long deadline);
>> ?static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int
>> *class,
>> @@ -106,8 +104,7 @@ static struct ata_port_operations ahci_p5wdh_ops = {
>>
>> ?static struct ata_port_operations ahci_sb600_ops = {
>> ? ? ? ?.inherits ? ? ? ? ? ? ? =&ahci_ops,
>> - ? ? ? .softreset ? ? ? ? ? ? ?= ahci_sb600_softreset,
>> - ? ? ? .pmp_softreset ? ? ? ? ?= ahci_sb600_softreset,
>> + ? ? ? .softreset ? ? ? ? ? ? ?= ahci_pmp_retry_srst_softreset,
>
> ? I have to ask you again: have you tried to compile this?
>
>> diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
>> index d38c40f..0fd5a30 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_retry_srst_softreset(struct ata_link *link, unsigned
>> int *class,
>> + ? ? ? ? ? ? ? ? ? ? ? ? unsigned long deadline);
>
> ? How come this is static if you reference it outside this module?
>
> WBR, Sergei
>

2011-06-20 10:06:55

by Yuan-Hsin Chen

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello.

On Mon, Jun 20, 2011 at 4:19 PM, Tejun Heo <[email protected]> wrote:
> Hello, Yuan.
>
> Yeap, almost there, just few very minor things. :)
>
> On Mon, Jun 20, 2011 at 04:06:41PM +0800, Yuan-Hsin Chen wrote:
>> ?static struct ata_port_operations ahci_sb600_ops = {
>> ? ? ? .inherits ? ? ? ? ? ? ? = &ahci_ops,
>> - ? ? .softreset ? ? ? ? ? ? ?= ahci_sb600_softreset,
>> - ? ? .pmp_softreset ? ? ? ? ?= ahci_sb600_softreset,
>> + ? ? .softreset ? ? ? ? ? ? ?= ahci_pmp_retry_srst_softreset,
>> ?};
>
> Why doesn't sb600 just use ahci_pmp_retry_srst_ops?
>
>> @@ -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_retry_srst_ops;
>
> Heh, I know I suggested that name but that is one ugly name. ?If
> anyone has any better idea, please come forward.

How about ahci_pmp_workaround_softreset or ahci_pmp_ipms_set_softreset?
Also applys to ops, ahci_pmp_workaround_ops or ahci_pmp_ipms_set_ops.

>
>> @@ -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_retry_srst_softreset(struct ata_link *link, unsigned int *class,
>> + ? ? ? ? ? ? ? ? ? ? ? unsigned long deadline);
>
> srst equals softreset, so ahci_pmp_retry_softreset() should do.
>
>> +struct ata_port_operations ahci_pmp_retry_srst_ops = {
>> + ? ? .inherits ? ? ? ? ? ? ? = &ahci_ops,
>> + ? ? .softreset ? ? ? ? ? ? ?= ahci_pmp_retry_srst_softreset,
>> +};
>> +EXPORT_SYMBOL_GPL(ahci_pmp_retry_srst_ops);
>> +
>> ?struct ata_port_operations ahci_ops = {
>> ? ? ? .inherits ? ? ? ? ? ? ? = &sata_pmp_port_ops,
>
> Maybe it's better to place ahci_pmp_retry_srst_ops after ahci_ops?
>
>> +static int ahci_pmp_check_ready(struct ata_link *link)
>
> It would be better if the name reflects that it's not for specific
> workaround.
>
> Thank you.
>
> --
> tejun
>

2011-06-20 12:47:45

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello,

On Mon, Jun 20, 2011 at 06:06:52PM +0800, Yuan-Hsin Chen wrote:
> > Heh, I know I suggested that name but that is one ugly name. ?If
> > anyone has any better idea, please come forward.
>
> How about ahci_pmp_workaround_softreset or ahci_pmp_ipms_set_softreset?
> Also applys to ops, ahci_pmp_workaround_ops or ahci_pmp_ipms_set_ops.

Heh, maybe. ahci_pmp_workaround_softreset is a bit generic but at
least doesn't completely stupid. I don't know. :)

Thanks.

--
tejun

2011-06-21 03:24:16

by Yuan-Hsin Chen

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello, Tejun.

On Mon, Jun 20, 2011 at 4:19 PM, Tejun Heo <[email protected]> wrote:
>> +static int ahci_pmp_check_ready(struct ata_link *link)
>
> It would be better if the name reflects that it's not for specific
> workaround.

Do you mean it would be better to name it for specific workaround?
How about ahci_bad_pmp_check_ready? Because this function is
to avoid checking TFDATA if BAD PMP is found.

Thanks.

Yuan-Hsin

2011-06-21 07:17:30

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v4] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello,

On Tue, Jun 21, 2011 at 5:24 AM, Yuan-Hsin Chen <[email protected]> wrote:
>> It would be better if the name reflects that it's not for specific
>> workaround.
>
> Do you mean it would be better to name it for specific workaround?

Yes, I meant that. An extra 'not' there.

> How about ahci_bad_pmp_check_ready? Because this function is
> to avoid checking TFDATA if BAD PMP is found.

It's minor anyway and I don't think it matters all that much as long
as we make the actual reset and ops names not too confusing.

Thank you.

--
tejun

2011-06-21 09:19:11

by Yuan-Hsin Chen

[permalink] [raw]
Subject: [PATCH v5] ahci: move ahci_sb600_softreset to libahci.c and rename it

From: Yuan-Hsin Chen <[email protected]>

ahci_sb600_softreset was in ahci.c. This function is used
to fix soft reset failure and renames as ahci_pmp_retry_softreset
in libahci.c.

Signed-off-by: Yuan-Hsin Chen <[email protected]>
---
drivers/ata/ahci.c | 61 +-----------------------------------------------
drivers/ata/ahci.h | 1 +
drivers/ata/libahci.c | 57 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 59 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 71afe03..e1f8362 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -79,8 +79,6 @@ enum board_ids {
};

static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
-static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
- unsigned long deadline);
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline);
static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
@@ -104,12 +102,6 @@ static struct ata_port_operations ahci_p5wdh_ops = {
.hardreset = ahci_p5wdh_hardreset,
};

-static struct ata_port_operations ahci_sb600_ops = {
- .inherits = &ahci_ops,
- .softreset = ahci_sb600_softreset,
- .pmp_softreset = ahci_sb600_softreset,
-};
-
#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)

static const struct ata_port_info ahci_port_info[] = {
@@ -188,7 +180,7 @@ static const struct ata_port_info ahci_port_info[] = {
.flags = AHCI_FLAG_COMMON,
.pio_mask = ATA_PIO4,
.udma_mask = ATA_UDMA6,
- .port_ops = &ahci_sb600_ops,
+ .port_ops = &ahci_pmp_retry_srst_ops,
},
[board_ahci_sb700] = /* for SB700 and SB800 */
{
@@ -196,7 +188,7 @@ static const struct ata_port_info ahci_port_info[] = {
.flags = AHCI_FLAG_COMMON,
.pio_mask = ATA_PIO4,
.udma_mask = ATA_UDMA6,
- .port_ops = &ahci_sb600_ops,
+ .port_ops = &ahci_pmp_retry_srst_ops,
},
[board_ahci_vt8251] =
{
@@ -502,55 +494,6 @@ static void ahci_pci_init_controller(struct ata_host *host)
ahci_init_controller(host);
}

-static int ahci_sb600_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;
-
- return ata_check_ready(status);
-}
-
-static int ahci_sb600_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_sb600_check_ready);
-
- /*
- * Soft reset fails on some ATI chips 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 SB600 PMP SRST workaround "
- "and retrying\n");
- rc = ahci_do_softreset(link, class, 0, deadline,
- ahci_check_ready);
- }
- }
-
- return rc;
-}
-
static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline)
{
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 12c5282..b175000 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_retry_srst_ops;

void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
u32 opts);
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index d38c40f..239d4db 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_retry_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);
@@ -178,6 +180,12 @@ struct ata_port_operations ahci_ops = {
};
EXPORT_SYMBOL_GPL(ahci_ops);

+struct ata_port_operations ahci_pmp_retry_srst_ops = {
+ .inherits = &ahci_ops,
+ .softreset = ahci_pmp_retry_softreset,
+};
+EXPORT_SYMBOL_GPL(ahci_pmp_retry_srst_ops);
+
int ahci_em_messages = 1;
EXPORT_SYMBOL_GPL(ahci_em_messages);
module_param(ahci_em_messages, int, 0444);
@@ -1329,6 +1337,55 @@ static int ahci_softreset(struct ata_link *link, unsigned int *class,
}
EXPORT_SYMBOL_GPL(ahci_do_softreset);

+static int ahci_bad_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;
+
+ return ata_check_ready(status);
+}
+
+int ahci_pmp_retry_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_bad_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)
{
--
1.7.3.1

2011-06-21 09:54:00

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH v5] ahci: move ahci_sb600_softreset to libahci.c and rename it

Hello,

On Tue, Jun 21, 2011 at 11:17 AM, Yuan-Hsin Chen <[email protected]> wrote:
> From: Yuan-Hsin Chen <[email protected]>
>
> ahci_sb600_softreset was in ahci.c. This function is used
> to fix soft reset failure and renames as ahci_pmp_retry_softreset
> in libahci.c.
>
> Signed-off-by: Yuan-Hsin Chen <[email protected]>

Acked-by: Tejun Heo <[email protected]>

Thanks for your persistence. :)

--
tejun