Patchwork [2/5] PCI: Use MSI/MSI-X cap cache in pci_msi_check_device()

login
register
mail settings
Submitter Gavin Shan
Date April 4, 2013, 11:39 a.m.
Message ID <1365075572-20763-3-git-send-email-shangw@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/233735/
State Changes Requested
Headers show

Comments

Gavin Shan - April 4, 2013, 11:39 a.m.
The function pci_msi_check_device() is called while enabling MSI
or MSI-X interrupts to make sure the PCI device can support MSI
or MSI-X capability. The patch changes the function for a bit to
use the cached MSI or MSI-X capability in pci_dev instead of polling
them from config space.

Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
---
 drivers/pci/msi.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Bjorn Helgaas - April 4, 2013, 4:33 p.m.
On Thu, Apr 4, 2013 at 5:39 AM, Gavin Shan <shangw@linux.vnet.ibm.com> wrote:
> The function pci_msi_check_device() is called while enabling MSI
> or MSI-X interrupts to make sure the PCI device can support MSI
> or MSI-X capability. The patch changes the function for a bit to
> use the cached MSI or MSI-X capability in pci_dev instead of polling
> them from config space.
>
> Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
> ---
>  drivers/pci/msi.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
> index 3459bdf..5f51e10 100644
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -772,6 +772,11 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
>         if (!pci_msi_enable || !dev || dev->no_msi)
>                 return -EINVAL;
>
> +       /* Check if the PCI device has MSI or MSI-X capability */
> +       if ((type == PCI_CAP_ID_MSI && !dev->msi_cap) ||
> +           (type == PCI_CAP_ID_MSIX && !dev->msix_cap))
> +               return -EINVAL;

The whole point of this is simplification, so just add "if
(!dev->msi_cap) return -EINVAL" (or "if (!dev->msix_cap)") to the
callers and drop the checking here in pci_msi_check_device().

> +
>         /*
>          * You can't ask to have 0 or less MSIs configured.
>          *  a) it's stupid ..
> @@ -795,9 +800,6 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
>         if (ret)
>                 return ret;
>
> -       if (!pci_find_capability(dev, type))
> -               return -EINVAL;
> -
>         return 0;
>  }
>
> --
> 1.7.5.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 3459bdf..5f51e10 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -772,6 +772,11 @@  static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
 	if (!pci_msi_enable || !dev || dev->no_msi)
 		return -EINVAL;
 
+	/* Check if the PCI device has MSI or MSI-X capability */
+	if ((type == PCI_CAP_ID_MSI && !dev->msi_cap) ||
+	    (type == PCI_CAP_ID_MSIX && !dev->msix_cap))
+		return -EINVAL;
+
 	/*
 	 * You can't ask to have 0 or less MSIs configured.
 	 *  a) it's stupid ..
@@ -795,9 +800,6 @@  static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type)
 	if (ret)
 		return ret;
 
-	if (!pci_find_capability(dev, type))
-		return -EINVAL;
-
 	return 0;
 }