diff options
author | Alexander Duyck <alexander.h.duyck@intel.com> | 2013-04-25 00:42:29 -0400 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2013-04-24 22:31:58 -0400 |
commit | 5a8eb24292ffd68604cedeb24ad2b4bc02cfc037 (patch) | |
tree | f85a264eccef0fec9337be43d8ff5fa5bac7a250 /drivers/pci/iov.c | |
parent | d44e7a9a1f1e56918f8e937dcf750626ac5ad9b4 (diff) |
pci: Add SRIOV helper function to determine if VFs are assigned to guest
This function is meant to add a helper function that will determine if a PF
has any VFs that are currently assigned to a guest. We currently have been
implementing this function per driver, and going forward I would like to avoid
that by making this function generic and using this helper.
v2: Removed extern from declaration of pci_vfs_assigned in pci.h and return
0 if SR-IOV is disabled with is inline with other PCI SRIOV functions.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/pci/iov.c')
-rw-r--r-- | drivers/pci/iov.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ee599f274f05..c93071d428f5 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c | |||
@@ -729,6 +729,47 @@ int pci_num_vf(struct pci_dev *dev) | |||
729 | EXPORT_SYMBOL_GPL(pci_num_vf); | 729 | EXPORT_SYMBOL_GPL(pci_num_vf); |
730 | 730 | ||
731 | /** | 731 | /** |
732 | * pci_vfs_assigned - returns number of VFs are assigned to a guest | ||
733 | * @dev: the PCI device | ||
734 | * | ||
735 | * Returns number of VFs belonging to this device that are assigned to a guest. | ||
736 | * If device is not a physical function returns -ENODEV. | ||
737 | */ | ||
738 | int pci_vfs_assigned(struct pci_dev *dev) | ||
739 | { | ||
740 | struct pci_dev *vfdev; | ||
741 | unsigned int vfs_assigned = 0; | ||
742 | unsigned short dev_id; | ||
743 | |||
744 | /* only search if we are a PF */ | ||
745 | if (!dev->is_physfn) | ||
746 | return 0; | ||
747 | |||
748 | /* | ||
749 | * determine the device ID for the VFs, the vendor ID will be the | ||
750 | * same as the PF so there is no need to check for that one | ||
751 | */ | ||
752 | pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id); | ||
753 | |||
754 | /* loop through all the VFs to see if we own any that are assigned */ | ||
755 | vfdev = pci_get_device(dev->vendor, dev_id, NULL); | ||
756 | while (vfdev) { | ||
757 | /* | ||
758 | * It is considered assigned if it is a virtual function with | ||
759 | * our dev as the physical function and the assigned bit is set | ||
760 | */ | ||
761 | if (vfdev->is_virtfn && (vfdev->physfn == dev) && | ||
762 | (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)) | ||
763 | vfs_assigned++; | ||
764 | |||
765 | vfdev = pci_get_device(dev->vendor, dev_id, vfdev); | ||
766 | } | ||
767 | |||
768 | return vfs_assigned; | ||
769 | } | ||
770 | EXPORT_SYMBOL_GPL(pci_vfs_assigned); | ||
771 | |||
772 | /** | ||
732 | * pci_sriov_set_totalvfs -- reduce the TotalVFs available | 773 | * pci_sriov_set_totalvfs -- reduce the TotalVFs available |
733 | * @dev: the PCI PF device | 774 | * @dev: the PCI PF device |
734 | * @numvfs: number that should be used for TotalVFs supported | 775 | * @numvfs: number that should be used for TotalVFs supported |