Skip to content

Commit ff1aa43

Browse files
Alexander Gordeevbjorn-helgaas
authored andcommitted
PCI/MSI: Add pci_msix_vec_count()
This creates an MSI-X counterpart for pci_msi_vec_count(). Device drivers can use this function to obtain maximum number of MSI-X interrupts the device supports and use that number in a subsequent call to pci_enable_msix(). pci_msix_vec_count() supersedes pci_msix_table_size() and returns a negative errno if device does not support MSI-X interrupts. After this update, callers must always check the returned value. The only user of pci_msix_table_size() was the PCI-Express port driver, which is also updated by this change. Signed-off-by: Alexander Gordeev <agordeev@redhat.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Tejun Heo <tj@kernel.org>
1 parent 7b92b4f commit ff1aa43

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

Documentation/PCI/MSI-HOWTO.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ MSI-X Table. This address is mapped by the PCI subsystem, and should not
243243
be accessed directly by the device driver. If the driver wishes to
244244
mask or unmask an interrupt, it should call disable_irq() / enable_irq().
245245

246+
4.3.4 pci_msix_vec_count
247+
248+
int pci_msix_vec_count(struct pci_dev *dev)
249+
250+
This function could be used to retrieve number of entries in the device
251+
MSI-X table.
252+
253+
If this function returns a negative number, it indicates the device is
254+
not capable of sending MSI-Xs.
255+
256+
If this function returns a positive number, it indicates the maximum
257+
number of MSI-X interrupt vectors that could be allocated.
258+
246259
4.4 Handling devices implementing both MSI and MSI-X capabilities
247260

248261
If a device implements both MSI and MSI-X capabilities, it can

drivers/pci/msi.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,19 +948,25 @@ void pci_disable_msi(struct pci_dev *dev)
948948
EXPORT_SYMBOL(pci_disable_msi);
949949

950950
/**
951-
* pci_msix_table_size - return the number of device's MSI-X table entries
951+
* pci_msix_vec_count - return the number of device's MSI-X table entries
952952
* @dev: pointer to the pci_dev data structure of MSI-X device function
953-
*/
954-
int pci_msix_table_size(struct pci_dev *dev)
953+
954+
* This function returns the number of device's MSI-X table entries and
955+
* therefore the number of MSI-X vectors device is capable of sending.
956+
* It returns a negative errno if the device is not capable of sending MSI-X
957+
* interrupts.
958+
**/
959+
int pci_msix_vec_count(struct pci_dev *dev)
955960
{
956961
u16 control;
957962

958963
if (!dev->msix_cap)
959-
return 0;
964+
return -EINVAL;
960965

961966
pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
962967
return msix_table_size(control);
963968
}
969+
EXPORT_SYMBOL(pci_msix_vec_count);
964970

965971
/**
966972
* pci_enable_msix - configure device's MSI-X capability structure
@@ -989,7 +995,9 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
989995
if (status)
990996
return status;
991997

992-
nr_entries = pci_msix_table_size(dev);
998+
nr_entries = pci_msix_vec_count(dev);
999+
if (nr_entries < 0)
1000+
return nr_entries;
9931001
if (nvec > nr_entries)
9941002
return nr_entries;
9951003

drivers/pci/pcie/portdrv_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)
7979
u16 reg16;
8080
u32 reg32;
8181

82-
nr_entries = pci_msix_table_size(dev);
83-
if (!nr_entries)
84-
return -EINVAL;
82+
nr_entries = pci_msix_vec_count(dev);
83+
if (nr_entries < 0)
84+
return nr_entries;
85+
BUG_ON(!nr_entries);
8586
if (nr_entries > PCIE_PORT_MAX_MSIX_ENTRIES)
8687
nr_entries = PCIE_PORT_MAX_MSIX_ENTRIES;
8788

include/linux/pci.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,9 @@ static inline void pci_msi_shutdown(struct pci_dev *dev)
11691169
static inline void pci_disable_msi(struct pci_dev *dev)
11701170
{ }
11711171

1172-
static inline int pci_msix_table_size(struct pci_dev *dev)
1172+
static inline int pci_msix_vec_count(struct pci_dev *dev)
11731173
{
1174-
return 0;
1174+
return -ENOSYS;
11751175
}
11761176
static inline int pci_enable_msix(struct pci_dev *dev,
11771177
struct msix_entry *entries, int nvec)
@@ -1198,7 +1198,7 @@ int pci_msi_vec_count(struct pci_dev *dev);
11981198
int pci_enable_msi_block(struct pci_dev *dev, int nvec);
11991199
void pci_msi_shutdown(struct pci_dev *dev);
12001200
void pci_disable_msi(struct pci_dev *dev);
1201-
int pci_msix_table_size(struct pci_dev *dev);
1201+
int pci_msix_vec_count(struct pci_dev *dev);
12021202
int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
12031203
void pci_msix_shutdown(struct pci_dev *dev);
12041204
void pci_disable_msix(struct pci_dev *dev);

0 commit comments

Comments
 (0)