X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=drivers%2Fpci%2Fiov.c;h=c93071d428f5d6d6cb038d5cb614e4117c5fd8aa;hb=4a4a11b98a39f479cdccef879635a72b0422049b;hp=ee599f274f057ed54b2af74cd9c72afee3cb1fbe;hpb=2cc79544bd0aabb4b3cf467ead5df526d9134c64;p=~andy%2Flinux diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ee599f274f0..c93071d428f 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -728,6 +728,47 @@ int pci_num_vf(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_num_vf); +/** + * pci_vfs_assigned - returns number of VFs are assigned to a guest + * @dev: the PCI device + * + * Returns number of VFs belonging to this device that are assigned to a guest. + * If device is not a physical function returns -ENODEV. + */ +int pci_vfs_assigned(struct pci_dev *dev) +{ + struct pci_dev *vfdev; + unsigned int vfs_assigned = 0; + unsigned short dev_id; + + /* only search if we are a PF */ + if (!dev->is_physfn) + return 0; + + /* + * determine the device ID for the VFs, the vendor ID will be the + * same as the PF so there is no need to check for that one + */ + pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id); + + /* loop through all the VFs to see if we own any that are assigned */ + vfdev = pci_get_device(dev->vendor, dev_id, NULL); + while (vfdev) { + /* + * It is considered assigned if it is a virtual function with + * our dev as the physical function and the assigned bit is set + */ + if (vfdev->is_virtfn && (vfdev->physfn == dev) && + (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)) + vfs_assigned++; + + vfdev = pci_get_device(dev->vendor, dev_id, vfdev); + } + + return vfs_assigned; +} +EXPORT_SYMBOL_GPL(pci_vfs_assigned); + /** * pci_sriov_set_totalvfs -- reduce the TotalVFs available * @dev: the PCI PF device