diff options
author | Alexander Gordeev <agordeev@redhat.com> | 2013-12-30 02:28:13 -0500 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-01-03 19:17:55 -0500 |
commit | d1ac1d2622e8f0fd2a25127a8649d135b54db8a9 (patch) | |
tree | 9b267fa3c5d97fc9c6c65877a9d493d407258abe /drivers/pci/msi.c | |
parent | 52179dc9edc3b7a2b3bb01cbb1b6c96f6d05fc73 (diff) |
PCI/MSI: Add pci_msi_vec_count()
Device drivers can use this interface to obtain the maximum number of MSI
interrupts the device supports and use that number, e.g., in a subsequent
call to pci_enable_msi_block().
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r-- | drivers/pci/msi.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index ce0d4eb91a22..ba6d0a9bdd39 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c | |||
@@ -843,6 +843,31 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type) | |||
843 | } | 843 | } |
844 | 844 | ||
845 | /** | 845 | /** |
846 | * pci_msi_vec_count - Return the number of MSI vectors a device can send | ||
847 | * @dev: device to report about | ||
848 | * | ||
849 | * This function returns the number of MSI vectors a device requested via | ||
850 | * Multiple Message Capable register. It returns a negative errno if the | ||
851 | * device is not capable sending MSI interrupts. Otherwise, the call succeeds | ||
852 | * and returns a power of two, up to a maximum of 2^5 (32), according to the | ||
853 | * MSI specification. | ||
854 | **/ | ||
855 | int pci_msi_vec_count(struct pci_dev *dev) | ||
856 | { | ||
857 | int ret; | ||
858 | u16 msgctl; | ||
859 | |||
860 | if (!dev->msi_cap) | ||
861 | return -EINVAL; | ||
862 | |||
863 | pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl); | ||
864 | ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); | ||
865 | |||
866 | return ret; | ||
867 | } | ||
868 | EXPORT_SYMBOL(pci_msi_vec_count); | ||
869 | |||
870 | /** | ||
846 | * pci_enable_msi_block - configure device's MSI capability structure | 871 | * pci_enable_msi_block - configure device's MSI capability structure |
847 | * @dev: device to configure | 872 | * @dev: device to configure |
848 | * @nvec: number of interrupts to configure | 873 | * @nvec: number of interrupts to configure |
@@ -858,13 +883,13 @@ static int pci_msi_check_device(struct pci_dev *dev, int nvec, int type) | |||
858 | int pci_enable_msi_block(struct pci_dev *dev, int nvec) | 883 | int pci_enable_msi_block(struct pci_dev *dev, int nvec) |
859 | { | 884 | { |
860 | int status, maxvec; | 885 | int status, maxvec; |
861 | u16 msgctl; | ||
862 | 886 | ||
863 | if (!dev->msi_cap || dev->current_state != PCI_D0) | 887 | if (dev->current_state != PCI_D0) |
864 | return -EINVAL; | 888 | return -EINVAL; |
865 | 889 | ||
866 | pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl); | 890 | maxvec = pci_msi_vec_count(dev); |
867 | maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); | 891 | if (maxvec < 0) |
892 | return maxvec; | ||
868 | if (nvec > maxvec) | 893 | if (nvec > maxvec) |
869 | return maxvec; | 894 | return maxvec; |
870 | 895 | ||
@@ -889,13 +914,13 @@ EXPORT_SYMBOL(pci_enable_msi_block); | |||
889 | int pci_enable_msi_block_auto(struct pci_dev *dev, int *maxvec) | 914 | int pci_enable_msi_block_auto(struct pci_dev *dev, int *maxvec) |
890 | { | 915 | { |
891 | int ret, nvec; | 916 | int ret, nvec; |
892 | u16 msgctl; | ||
893 | 917 | ||
894 | if (!dev->msi_cap || dev->current_state != PCI_D0) | 918 | if (dev->current_state != PCI_D0) |
895 | return -EINVAL; | 919 | return -EINVAL; |
896 | 920 | ||
897 | pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl); | 921 | ret = pci_msi_vec_count(dev); |
898 | ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); | 922 | if (ret < 0) |
923 | return ret; | ||
899 | 924 | ||
900 | if (maxvec) | 925 | if (maxvec) |
901 | *maxvec = ret; | 926 | *maxvec = ret; |