2014-04-02 08:18:17

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 0/2] ahci: Tweaks to the driver's PCI function

Hello,

The changes are against the latest Linus tree.

Cc: [email protected]

Alexander Gordeev (2):
ahci: Ensure "MSI Revert to Single Message" mode is not enforced
ahci: Use pci_enable_msi_exact() instead of pci_enable_msi_range()

drivers/ata/ahci.c | 25 +++++++++++++++++++++----
drivers/ata/ahci.h | 1 +
2 files changed, 22 insertions(+), 4 deletions(-)

--
1.7.7.6


2014-04-02 08:19:23

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 1/2] ahci: Ensure "MSI Revert to Single Message" mode is not enforced

Do not rely on successful initialization of multiple MSIs mode
alone and always check if "MSI Revert to Single Message" mode
was enforced by the controller. Fall back to the single MSI
mode in case it did. Not doing so might screw up the interrupt
handling.

Signed-off-by: Alexander Gordeev <[email protected]>
Cc: [email protected]
---
drivers/ata/ahci.c | 17 +++++++++++++++++
drivers/ata/ahci.h | 1 +
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 5a0bf8e..838d97e 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1163,6 +1163,14 @@ static inline void ahci_gtf_filter_workaround(struct ata_host *host)
{}
#endif

+static int ahci_is_mrsm(struct ahci_host_priv *hpriv)
+{
+ void __iomem *mmio = hpriv->mmio;
+ u32 ctl = readl(mmio + HOST_CTL);
+
+ return ctl & HOST_MRSM;
+}
+
static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
struct ahci_host_priv *hpriv)
{
@@ -1189,6 +1197,15 @@ static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
else if (nvec < 0)
goto intx;

+ /*
+ * Fallback to single MSI mode if the controller enforced MRSM mode
+ */
+ if (ahci_is_mrsm(hpriv)) {
+ pci_disable_msi(pdev);
+ printk(KERN_INFO "ahci: MRSM is on, fallback to single MSI\n");
+ goto single_msi;
+ }
+
return nvec;

single_msi:
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 51af275..b5eb886 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -94,6 +94,7 @@ enum {
/* HOST_CTL bits */
HOST_RESET = (1 << 0), /* reset controller; self-clear */
HOST_IRQ_EN = (1 << 1), /* global IRQ enable */
+ HOST_MRSM = (1 << 2), /* MSI Revert to Single Message */
HOST_AHCI_EN = (1 << 31), /* AHCI enabled */

/* HOST_CAP bits */
--
1.7.7.6

2014-04-02 08:19:21

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 2/2] ahci: Use pci_enable_msi_exact() instead of pci_enable_msi_range()

The driver calls pci_enable_msi_range() function with the
range of [nvec..nvec] which what pci_enable_msi_exact()
function is for.

Signed-off-by: Alexander Gordeev <[email protected]>
Cc: [email protected]
---
drivers/ata/ahci.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 838d97e..01c5541 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1174,7 +1174,7 @@ static int ahci_is_mrsm(struct ahci_host_priv *hpriv)
static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
struct ahci_host_priv *hpriv)
{
- int nvec;
+ int rc, nvec;

if (hpriv->flags & AHCI_HFLAG_NO_MSI)
goto intx;
@@ -1191,10 +1191,10 @@ static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports,
if (nvec < n_ports)
goto single_msi;

- nvec = pci_enable_msi_range(pdev, nvec, nvec);
- if (nvec == -ENOSPC)
+ rc = pci_enable_msi_exact(pdev, nvec);
+ if (rc == -ENOSPC)
goto single_msi;
- else if (nvec < 0)
+ else if (rc < 0)
goto intx;

/*
--
1.7.7.6

2014-04-16 20:01:41

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 1/2] ahci: Ensure "MSI Revert to Single Message" mode is not enforced

Hello, Alexander.

On Wed, Apr 02, 2014 at 10:19:56AM +0200, Alexander Gordeev wrote:
> +static int ahci_is_mrsm(struct ahci_host_priv *hpriv)
> +{
> + void __iomem *mmio = hpriv->mmio;
> + u32 ctl = readl(mmio + HOST_CTL);
> +
> + return ctl & HOST_MRSM;
> +}

Can you please just open code this in ahci_init_interrupt()? Also, do
I need to backport this through -stable? Has this been tested
somehow? What are the impacts of missing this?

Thanks.

--
tejun

2014-04-16 20:03:00

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 2/2] ahci: Use pci_enable_msi_exact() instead of pci_enable_msi_range()

On Wed, Apr 02, 2014 at 10:19:57AM +0200, Alexander Gordeev wrote:
> The driver calls pci_enable_msi_range() function with the
> range of [nvec..nvec] which what pci_enable_msi_exact()
> function is for.
>
> Signed-off-by: Alexander Gordeev <[email protected]>
> Cc: [email protected]

Please refresh this one after updating the first patch.

Thanks.

--
tejun

2014-04-17 13:14:56

by Alexander Gordeev

[permalink] [raw]
Subject: Re: [PATCH 1/2] ahci: Ensure "MSI Revert to Single Message" mode is not enforced

On Wed, Apr 16, 2014 at 04:01:32PM -0400, Tejun Heo wrote:
> Can you please just open code this in ahci_init_interrupt()? Also, do
> I need to backport this through -stable? Has this been tested
> somehow? What are the impacts of missing this?

Hi Tejun,

Sent out an updated version.
Yes, I think it needs to go to -stable.

> Thanks.
>
> --
> tejun

--
Regards,
Alexander Gordeev
[email protected]