* [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
@ 2010-07-23 13:56 ` Ben Hutchings
0 siblings, 0 replies; 15+ messages in thread
From: Ben Hutchings @ 2010-07-23 13:56 UTC (permalink / raw)
To: Jesse Barnes; +Cc: Stephen Rothwell, ppc-dev, LKML, linux-pci
commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
return the last MSI message written instead of reading it from the
device, since it may be called while the device is in a reduced
power state.
However, the pSeries platform code really does need to read messages
from the device, since they are initially written by firmware.
Therefore:
- Restore the previous behaviour of read_msi_msg_desc()
- Add new functions get_cached_msi_msg{,_desc}() which return the
last MSI message written
- Use the new functions where appropriate
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
Compile-tested only.
Ben.
arch/ia64/kernel/msi_ia64.c | 2 +-
arch/ia64/sn/kernel/msi_sn.c | 2 +-
arch/x86/kernel/apic/io_apic.c | 2 +-
drivers/pci/msi.c | 47 +++++++++++++++++++++++++++++++++++----
include/linux/msi.h | 2 +
5 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/arch/ia64/kernel/msi_ia64.c b/arch/ia64/kernel/msi_ia64.c
index 6c89228..4a746ea 100644
--- a/arch/ia64/kernel/msi_ia64.c
+++ b/arch/ia64/kernel/msi_ia64.c
@@ -25,7 +25,7 @@ static int ia64_set_msi_irq_affinity(unsigned int irq,
if (irq_prepare_move(irq, cpu))
return -1;
- read_msi_msg(irq, &msg);
+ get_cached_msi_msg(irq, &msg);
addr = msg.address_lo;
addr &= MSI_ADDR_DEST_ID_MASK;
diff --git a/arch/ia64/sn/kernel/msi_sn.c b/arch/ia64/sn/kernel/msi_sn.c
index ebfdd6a..0c72dd4 100644
--- a/arch/ia64/sn/kernel/msi_sn.c
+++ b/arch/ia64/sn/kernel/msi_sn.c
@@ -175,7 +175,7 @@ static int sn_set_msi_irq_affinity(unsigned int irq,
* Release XIO resources for the old MSI PCI address
*/
- read_msi_msg(irq, &msg);
+ get_cached_msi_msg(irq, &msg);
sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
pdev = sn_pdev->pdi_linux_pcidev;
provider = SN_PCIDEV_BUSPROVIDER(pdev);
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index e41ed24..4dc0084 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -3397,7 +3397,7 @@ static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
cfg = desc->chip_data;
- read_msi_msg_desc(desc, &msg);
+ get_cached_msi_msg_desc(desc, &msg);
msg.data &= ~MSI_DATA_VECTOR_MASK;
msg.data |= MSI_DATA_VECTOR(cfg->vector);
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 4c14f31..69b7be3 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -197,9 +197,46 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
{
struct msi_desc *entry = get_irq_desc_msi(desc);
- /* We do not touch the hardware (which may not even be
- * accessible at the moment) but return the last message
- * written. Assert that this is valid, assuming that
+ BUG_ON(entry->dev->current_state != PCI_D0);
+
+ if (entry->msi_attrib.is_msix) {
+ void __iomem *base = entry->mask_base +
+ entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
+
+ msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR);
+ msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR);
+ msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
+ } else {
+ struct pci_dev *dev = entry->dev;
+ int pos = entry->msi_attrib.pos;
+ u16 data;
+
+ pci_read_config_dword(dev, msi_lower_address_reg(pos),
+ &msg->address_lo);
+ if (entry->msi_attrib.is_64) {
+ pci_read_config_dword(dev, msi_upper_address_reg(pos),
+ &msg->address_hi);
+ pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
+ } else {
+ msg->address_hi = 0;
+ pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
+ }
+ msg->data = data;
+ }
+}
+
+void read_msi_msg(unsigned int irq, struct msi_msg *msg)
+{
+ struct irq_desc *desc = irq_to_desc(irq);
+
+ read_msi_msg_desc(desc, msg);
+}
+
+void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
+{
+ struct msi_desc *entry = get_irq_desc_msi(desc);
+
+ /* Assert that the cache is valid, assuming that
* valid messages are not all-zeroes. */
BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo |
entry->msg.data));
@@ -207,11 +244,11 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
*msg = entry->msg;
}
-void read_msi_msg(unsigned int irq, struct msi_msg *msg)
+void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
{
struct irq_desc *desc = irq_to_desc(irq);
- read_msi_msg_desc(desc, msg);
+ get_cached_msi_msg_desc(desc, msg);
}
void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
diff --git a/include/linux/msi.h b/include/linux/msi.h
index 6991ab5..91b05c1 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -14,8 +14,10 @@ struct irq_desc;
extern void mask_msi_irq(unsigned int irq);
extern void unmask_msi_irq(unsigned int irq);
extern void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
+extern void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
extern void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
extern void read_msi_msg(unsigned int irq, struct msi_msg *msg);
+extern void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
extern void write_msi_msg(unsigned int irq, struct msi_msg *msg);
struct msi_desc {
--
1.6.2.5
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
2010-07-23 13:56 ` Ben Hutchings
@ 2010-07-26 11:20 ` Michael Ellerman
-1 siblings, 0 replies; 15+ messages in thread
From: Michael Ellerman @ 2010-07-26 11:20 UTC (permalink / raw)
To: Ben Hutchings; +Cc: Jesse Barnes, Stephen Rothwell, ppc-dev, LKML, linux-pci
[-- Attachment #1: Type: text/plain, Size: 809 bytes --]
On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
>
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Looks good to me.
cheers
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
@ 2010-07-26 11:20 ` Michael Ellerman
0 siblings, 0 replies; 15+ messages in thread
From: Michael Ellerman @ 2010-07-26 11:20 UTC (permalink / raw)
To: Ben Hutchings; +Cc: Stephen Rothwell, ppc-dev, LKML, Jesse Barnes, linux-pci
[-- Attachment #1: Type: text/plain, Size: 809 bytes --]
On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
>
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Looks good to me.
cheers
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
2010-07-23 13:56 ` Ben Hutchings
@ 2010-07-30 16:42 ` Jesse Barnes
-1 siblings, 0 replies; 15+ messages in thread
From: Jesse Barnes @ 2010-07-30 16:42 UTC (permalink / raw)
To: Ben Hutchings
Cc: Stephen Rothwell, ppc-dev, LKML, Michael Ellerman, linux-pci
On Fri, 23 Jul 2010 14:56:28 +0100
Ben Hutchings <bhutchings@solarflare.com> wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
>
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> ---
> Compile-tested only.
>
Applied to linux-next with Michael's ack, thanks. I hope it actually
works, I didn't see a tested-by!
--
Jesse Barnes, Intel Open Source Technology Center
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
@ 2010-07-30 16:42 ` Jesse Barnes
0 siblings, 0 replies; 15+ messages in thread
From: Jesse Barnes @ 2010-07-30 16:42 UTC (permalink / raw)
To: Ben Hutchings; +Cc: Stephen Rothwell, ppc-dev, LKML, linux-pci
On Fri, 23 Jul 2010 14:56:28 +0100
Ben Hutchings <bhutchings@solarflare.com> wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
>
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> ---
> Compile-tested only.
>
Applied to linux-next with Michael's ack, thanks. I hope it actually
works, I didn't see a tested-by!
--
Jesse Barnes, Intel Open Source Technology Center
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
2010-07-30 16:42 ` Jesse Barnes
(?)
@ 2010-08-01 6:23 ` Michael Ellerman
-1 siblings, 0 replies; 15+ messages in thread
From: Michael Ellerman @ 2010-08-01 6:23 UTC (permalink / raw)
To: Jesse Barnes; +Cc: Ben Hutchings, Stephen Rothwell, ppc-dev, LKML, linux-pci
[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]
On Fri, 2010-07-30 at 09:42 -0700, Jesse Barnes wrote:
> On Fri, 23 Jul 2010 14:56:28 +0100
> Ben Hutchings <bhutchings@solarflare.com> wrote:
>
> > commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> > unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> > return the last MSI message written instead of reading it from the
> > device, since it may be called while the device is in a reduced
> > power state.
> >
> > However, the pSeries platform code really does need to read messages
> > from the device, since they are initially written by firmware.
> > Therefore:
> > - Restore the previous behaviour of read_msi_msg_desc()
> > - Add new functions get_cached_msi_msg{,_desc}() which return the
> > last MSI message written
> > - Use the new functions where appropriate
> >
> > Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> > ---
> > Compile-tested only.
> >
>
> Applied to linux-next with Michael's ack, thanks. I hope it actually
> works, I didn't see a tested-by!
I assume Stephen has been using it, otherwise his linux-next boot tests
will all have been failing. Either way he'll test it when it gets into
linux-next proper.
cheers
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
2010-07-23 13:56 ` Ben Hutchings
@ 2012-11-20 7:20 ` Benjamin Herrenschmidt
-1 siblings, 0 replies; 15+ messages in thread
From: Benjamin Herrenschmidt @ 2012-11-20 7:20 UTC (permalink / raw)
To: Ben Hutchings
Cc: Jesse Barnes, Stephen Rothwell, ppc-dev, LKML, linux-pci, Bjorn Helgaas
On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
Looks reasonable... Jesse ?
Cheers,
Ben.
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> ---
> Compile-tested only.
>
> Ben.
>
> arch/ia64/kernel/msi_ia64.c | 2 +-
> arch/ia64/sn/kernel/msi_sn.c | 2 +-
> arch/x86/kernel/apic/io_apic.c | 2 +-
> drivers/pci/msi.c | 47 +++++++++++++++++++++++++++++++++++----
> include/linux/msi.h | 2 +
> 5 files changed, 47 insertions(+), 8 deletions(-)
>
> diff --git a/arch/ia64/kernel/msi_ia64.c b/arch/ia64/kernel/msi_ia64.c
> index 6c89228..4a746ea 100644
> --- a/arch/ia64/kernel/msi_ia64.c
> +++ b/arch/ia64/kernel/msi_ia64.c
> @@ -25,7 +25,7 @@ static int ia64_set_msi_irq_affinity(unsigned int irq,
> if (irq_prepare_move(irq, cpu))
> return -1;
>
> - read_msi_msg(irq, &msg);
> + get_cached_msi_msg(irq, &msg);
>
> addr = msg.address_lo;
> addr &= MSI_ADDR_DEST_ID_MASK;
> diff --git a/arch/ia64/sn/kernel/msi_sn.c b/arch/ia64/sn/kernel/msi_sn.c
> index ebfdd6a..0c72dd4 100644
> --- a/arch/ia64/sn/kernel/msi_sn.c
> +++ b/arch/ia64/sn/kernel/msi_sn.c
> @@ -175,7 +175,7 @@ static int sn_set_msi_irq_affinity(unsigned int irq,
> * Release XIO resources for the old MSI PCI address
> */
>
> - read_msi_msg(irq, &msg);
> + get_cached_msi_msg(irq, &msg);
> sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
> pdev = sn_pdev->pdi_linux_pcidev;
> provider = SN_PCIDEV_BUSPROVIDER(pdev);
> diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
> index e41ed24..4dc0084 100644
> --- a/arch/x86/kernel/apic/io_apic.c
> +++ b/arch/x86/kernel/apic/io_apic.c
> @@ -3397,7 +3397,7 @@ static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
>
> cfg = desc->chip_data;
>
> - read_msi_msg_desc(desc, &msg);
> + get_cached_msi_msg_desc(desc, &msg);
>
> msg.data &= ~MSI_DATA_VECTOR_MASK;
> msg.data |= MSI_DATA_VECTOR(cfg->vector);
> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
> index 4c14f31..69b7be3 100644
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -197,9 +197,46 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> {
> struct msi_desc *entry = get_irq_desc_msi(desc);
>
> - /* We do not touch the hardware (which may not even be
> - * accessible at the moment) but return the last message
> - * written. Assert that this is valid, assuming that
> + BUG_ON(entry->dev->current_state != PCI_D0);
> +
> + if (entry->msi_attrib.is_msix) {
> + void __iomem *base = entry->mask_base +
> + entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
> +
> + msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR);
> + msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR);
> + msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
> + } else {
> + struct pci_dev *dev = entry->dev;
> + int pos = entry->msi_attrib.pos;
> + u16 data;
> +
> + pci_read_config_dword(dev, msi_lower_address_reg(pos),
> + &msg->address_lo);
> + if (entry->msi_attrib.is_64) {
> + pci_read_config_dword(dev, msi_upper_address_reg(pos),
> + &msg->address_hi);
> + pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
> + } else {
> + msg->address_hi = 0;
> + pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
> + }
> + msg->data = data;
> + }
> +}
> +
> +void read_msi_msg(unsigned int irq, struct msi_msg *msg)
> +{
> + struct irq_desc *desc = irq_to_desc(irq);
> +
> + read_msi_msg_desc(desc, msg);
> +}
> +
> +void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> +{
> + struct msi_desc *entry = get_irq_desc_msi(desc);
> +
> + /* Assert that the cache is valid, assuming that
> * valid messages are not all-zeroes. */
> BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo |
> entry->msg.data));
> @@ -207,11 +244,11 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> *msg = entry->msg;
> }
>
> -void read_msi_msg(unsigned int irq, struct msi_msg *msg)
> +void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
> {
> struct irq_desc *desc = irq_to_desc(irq);
>
> - read_msi_msg_desc(desc, msg);
> + get_cached_msi_msg_desc(desc, msg);
> }
>
> void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> diff --git a/include/linux/msi.h b/include/linux/msi.h
> index 6991ab5..91b05c1 100644
> --- a/include/linux/msi.h
> +++ b/include/linux/msi.h
> @@ -14,8 +14,10 @@ struct irq_desc;
> extern void mask_msi_irq(unsigned int irq);
> extern void unmask_msi_irq(unsigned int irq);
> extern void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> +extern void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> extern void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> extern void read_msi_msg(unsigned int irq, struct msi_msg *msg);
> +extern void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
> extern void write_msi_msg(unsigned int irq, struct msi_msg *msg);
>
> struct msi_desc {
> --
> 1.6.2.5
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
@ 2012-11-20 7:20 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 15+ messages in thread
From: Benjamin Herrenschmidt @ 2012-11-20 7:20 UTC (permalink / raw)
To: Ben Hutchings
Cc: Stephen Rothwell, linux-pci, LKML, Jesse Barnes, Bjorn Helgaas, ppc-dev
On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> return the last MSI message written instead of reading it from the
> device, since it may be called while the device is in a reduced
> power state.
Looks reasonable... Jesse ?
Cheers,
Ben.
> However, the pSeries platform code really does need to read messages
> from the device, since they are initially written by firmware.
> Therefore:
> - Restore the previous behaviour of read_msi_msg_desc()
> - Add new functions get_cached_msi_msg{,_desc}() which return the
> last MSI message written
> - Use the new functions where appropriate
>
> Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
> ---
> Compile-tested only.
>
> Ben.
>
> arch/ia64/kernel/msi_ia64.c | 2 +-
> arch/ia64/sn/kernel/msi_sn.c | 2 +-
> arch/x86/kernel/apic/io_apic.c | 2 +-
> drivers/pci/msi.c | 47 +++++++++++++++++++++++++++++++++++----
> include/linux/msi.h | 2 +
> 5 files changed, 47 insertions(+), 8 deletions(-)
>
> diff --git a/arch/ia64/kernel/msi_ia64.c b/arch/ia64/kernel/msi_ia64.c
> index 6c89228..4a746ea 100644
> --- a/arch/ia64/kernel/msi_ia64.c
> +++ b/arch/ia64/kernel/msi_ia64.c
> @@ -25,7 +25,7 @@ static int ia64_set_msi_irq_affinity(unsigned int irq,
> if (irq_prepare_move(irq, cpu))
> return -1;
>
> - read_msi_msg(irq, &msg);
> + get_cached_msi_msg(irq, &msg);
>
> addr = msg.address_lo;
> addr &= MSI_ADDR_DEST_ID_MASK;
> diff --git a/arch/ia64/sn/kernel/msi_sn.c b/arch/ia64/sn/kernel/msi_sn.c
> index ebfdd6a..0c72dd4 100644
> --- a/arch/ia64/sn/kernel/msi_sn.c
> +++ b/arch/ia64/sn/kernel/msi_sn.c
> @@ -175,7 +175,7 @@ static int sn_set_msi_irq_affinity(unsigned int irq,
> * Release XIO resources for the old MSI PCI address
> */
>
> - read_msi_msg(irq, &msg);
> + get_cached_msi_msg(irq, &msg);
> sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
> pdev = sn_pdev->pdi_linux_pcidev;
> provider = SN_PCIDEV_BUSPROVIDER(pdev);
> diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
> index e41ed24..4dc0084 100644
> --- a/arch/x86/kernel/apic/io_apic.c
> +++ b/arch/x86/kernel/apic/io_apic.c
> @@ -3397,7 +3397,7 @@ static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
>
> cfg = desc->chip_data;
>
> - read_msi_msg_desc(desc, &msg);
> + get_cached_msi_msg_desc(desc, &msg);
>
> msg.data &= ~MSI_DATA_VECTOR_MASK;
> msg.data |= MSI_DATA_VECTOR(cfg->vector);
> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
> index 4c14f31..69b7be3 100644
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -197,9 +197,46 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> {
> struct msi_desc *entry = get_irq_desc_msi(desc);
>
> - /* We do not touch the hardware (which may not even be
> - * accessible at the moment) but return the last message
> - * written. Assert that this is valid, assuming that
> + BUG_ON(entry->dev->current_state != PCI_D0);
> +
> + if (entry->msi_attrib.is_msix) {
> + void __iomem *base = entry->mask_base +
> + entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
> +
> + msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR);
> + msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR);
> + msg->data = readl(base + PCI_MSIX_ENTRY_DATA);
> + } else {
> + struct pci_dev *dev = entry->dev;
> + int pos = entry->msi_attrib.pos;
> + u16 data;
> +
> + pci_read_config_dword(dev, msi_lower_address_reg(pos),
> + &msg->address_lo);
> + if (entry->msi_attrib.is_64) {
> + pci_read_config_dword(dev, msi_upper_address_reg(pos),
> + &msg->address_hi);
> + pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
> + } else {
> + msg->address_hi = 0;
> + pci_read_config_word(dev, msi_data_reg(pos, 0), &data);
> + }
> + msg->data = data;
> + }
> +}
> +
> +void read_msi_msg(unsigned int irq, struct msi_msg *msg)
> +{
> + struct irq_desc *desc = irq_to_desc(irq);
> +
> + read_msi_msg_desc(desc, msg);
> +}
> +
> +void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> +{
> + struct msi_desc *entry = get_irq_desc_msi(desc);
> +
> + /* Assert that the cache is valid, assuming that
> * valid messages are not all-zeroes. */
> BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo |
> entry->msg.data));
> @@ -207,11 +244,11 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> *msg = entry->msg;
> }
>
> -void read_msi_msg(unsigned int irq, struct msi_msg *msg)
> +void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
> {
> struct irq_desc *desc = irq_to_desc(irq);
>
> - read_msi_msg_desc(desc, msg);
> + get_cached_msi_msg_desc(desc, msg);
> }
>
> void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
> diff --git a/include/linux/msi.h b/include/linux/msi.h
> index 6991ab5..91b05c1 100644
> --- a/include/linux/msi.h
> +++ b/include/linux/msi.h
> @@ -14,8 +14,10 @@ struct irq_desc;
> extern void mask_msi_irq(unsigned int irq);
> extern void unmask_msi_irq(unsigned int irq);
> extern void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> +extern void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> extern void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg);
> extern void read_msi_msg(unsigned int irq, struct msi_msg *msg);
> +extern void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
> extern void write_msi_msg(unsigned int irq, struct msi_msg *msg);
>
> struct msi_desc {
> --
> 1.6.2.5
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
2012-11-20 7:20 ` Benjamin Herrenschmidt
@ 2012-11-20 12:36 ` Ben Hutchings
-1 siblings, 0 replies; 15+ messages in thread
From: Ben Hutchings @ 2012-11-20 12:36 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Jesse Barnes, Stephen Rothwell, ppc-dev, LKML, linux-pci, Bjorn Helgaas
On Tue, 2012-11-20 at 18:20 +1100, Benjamin Herrenschmidt wrote:
> On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> > commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> > unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> > return the last MSI message written instead of reading it from the
> > device, since it may be called while the device is in a reduced
> > power state.
>
> Looks reasonable... Jesse ?
[...]
So reasonable that it was committed a couple of years ago!
Where did you dredge this from?
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] PCI: MSI: Restore read_msi_msg_desc(); add get_cached_msi_msg_desc()
@ 2012-11-20 12:36 ` Ben Hutchings
0 siblings, 0 replies; 15+ messages in thread
From: Ben Hutchings @ 2012-11-20 12:36 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Stephen Rothwell, linux-pci, LKML, Jesse Barnes, Bjorn Helgaas, ppc-dev
On Tue, 2012-11-20 at 18:20 +1100, Benjamin Herrenschmidt wrote:
> On Fri, 2010-07-23 at 14:56 +0100, Ben Hutchings wrote:
> > commit 2ca1af9aa3285c6a5f103ed31ad09f7399fc65d7 "PCI: MSI: Remove
> > unsafe and unnecessary hardware access" changed read_msi_msg_desc() to
> > return the last MSI message written instead of reading it from the
> > device, since it may be called while the device is in a reduced
> > power state.
>
> Looks reasonable... Jesse ?
[...]
So reasonable that it was committed a couple of years ago!
Where did you dredge this from?
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 15+ messages in thread