Commit 8d85a7a4 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Bjorn Helgaas

PCI/IOV: Allow PF drivers to limit total_VFs to 0

Some SR-IOV PF drivers implement .sriov_configure(), which allows
user-space to enable VFs by writing the desired number of VFs to the sysfs
"sriov_numvfs" file (see sriov_numvfs_store()).

The PCI core limits the number of VFs to the TotalVFs advertised by the
device in its SR-IOV capability.  The PF driver can limit the number of VFs
to even fewer (it may have pre-allocated data structures or knowledge of
device limitations) by calling pci_sriov_set_totalvfs(), but previously it
could not limit the VFs to 0.

Change pci_sriov_get_totalvfs() so it always respects the VF limit imposed
by the PF driver, even if the limit is 0.

This sequence:

  pci_sriov_set_totalvfs(dev, 0);
  x = pci_sriov_get_totalvfs(dev);

previously set "x" to TotalVFs from the SR-IOV capability.  Now it will set
"x" to 0.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
[bhelgaas: split to separate patch]
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent cef74409
...@@ -469,6 +469,7 @@ static int sriov_init(struct pci_dev *dev, int pos) ...@@ -469,6 +469,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
iov->nres = nres; iov->nres = nres;
iov->ctrl = ctrl; iov->ctrl = ctrl;
iov->total_VFs = total; iov->total_VFs = total;
iov->driver_max_VFs = total;
pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_device); pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_device);
iov->pgsz = pgsz; iov->pgsz = pgsz;
iov->self = dev; iov->self = dev;
...@@ -827,10 +828,7 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev) ...@@ -827,10 +828,7 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev)
if (!dev->is_physfn) if (!dev->is_physfn)
return 0; return 0;
if (dev->sriov->driver_max_VFs) return dev->sriov->driver_max_VFs;
return dev->sriov->driver_max_VFs;
return dev->sriov->total_VFs;
} }
EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs); EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment