diff mbox

[4/4] PCI: Retrieve MSI cap struct for once on setup

Message ID 1364374564-19096-5-git-send-email-shangw@linux.vnet.ibm.com
State Changes Requested
Headers show

Commit Message

Gavin Shan March 27, 2013, 8:56 a.m. UTC
The patch adjusts function msi_capability_init() and pci_enable_msi_block()
so that we needn't figure out the address of MSI capability structure
for multiple time in one function call path while enabling MSI.

Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
---
 drivers/pci/msi.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index a20cb0a..f6fa697 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -542,6 +542,7 @@  out_unroll:
  * msi_capability_init - configure device's MSI capability structure
  * @dev: pointer to the pci_dev data structure of MSI device function
  * @nvec: number of interrupts to allocate
+ * @pos: address of MSI capability structure
  *
  * Setup the MSI capability structure of the device with the requested
  * number of interrupts.  A return value of zero indicates the successful
@@ -549,14 +550,13 @@  out_unroll:
  * an error, and a positive return value indicates the number of interrupts
  * which could have been allocated.
  */
-static int msi_capability_init(struct pci_dev *dev, int nvec)
+static int msi_capability_init(struct pci_dev *dev, int nvec, int pos)
 {
 	struct msi_desc *entry;
-	int pos, ret;
+	int ret;
 	u16 control;
 	unsigned mask;
 
-	pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
 	msi_set_enable(dev, pos, 0);	/* Disable MSI during set up */
 
 	pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -823,18 +823,15 @@  int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
 	int pos, status, maxvec;
 	u16 msgctl;
 
-	pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
-	if (!pos)
-		return -EINVAL;
+	status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI, &pos);
+	if (status)
+		return status;
+
 	pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
 	maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
 	if (nvec > maxvec)
 		return maxvec;
 
-	status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSI, &pos);
-	if (status)
-		return status;
-
 	WARN_ON(!!dev->msi_enabled);
 
 	/* Check whether driver already requested MSI-X irqs */
@@ -844,7 +841,7 @@  int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
 		return -EINVAL;
 	}
 
-	status = msi_capability_init(dev, nvec);
+	status = msi_capability_init(dev, nvec, pos);
 	return status;
 }
 EXPORT_SYMBOL(pci_enable_msi_block);