Skip to content

Commit 2597ba7

Browse files
ddutilebjorn-helgaas
authored andcommitted
PCI: SRIOV control and status via sysfs (documentation)
Add documentation of new sysfs files and new pci_driver SRIOV configuration interface. [bhelgaas: changelog] Signed-off: Donald Dutile <ddutile@redhat.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 1452cd7 commit 2597ba7

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

‎Documentation/ABI/testing/sysfs-bus-pci‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,37 @@ Description:
222222
satisfied too. Reading this attribute will show the current
223223
value of d3cold_allowed bit. Writing this attribute will set
224224
the value of d3cold_allowed bit.
225+
226+
What: /sys/bus/pci/devices/.../sriov_totalvfs
227+
Date: November 2012
228+
Contact: Donald Dutile <ddutile@redhat.com>
229+
Description:
230+
This file appears when a physical PCIe device supports SR-IOV.
231+
Userspace applications can read this file to determine the
232+
maximum number of Virtual Functions (VFs) a PCIe physical
233+
function (PF) can support. Typically, this is the value reported
234+
in the PF's SR-IOV extended capability structure's TotalVFs
235+
element. Drivers have the ability at probe time to reduce the
236+
value read from this file via the pci_sriov_set_totalvfs()
237+
function.
238+
239+
What: /sys/bus/pci/devices/.../sriov_numvfs
240+
Date: November 2012
241+
Contact: Donald Dutile <ddutile@redhat.com>
242+
Description:
243+
This file appears when a physical PCIe device supports SR-IOV.
244+
Userspace applications can read and write to this file to
245+
determine and control the enablement or disablement of Virtual
246+
Functions (VFs) on the physical function (PF). A read of this
247+
file will return the number of VFs that are enabled on this PF.
248+
A number written to this file will enable the specified
249+
number of VFs. A userspace application would typically read the
250+
file and check that the value is zero, and then write the number
251+
of VFs that should be enabled on the PF; the value written
252+
should be less than or equal to the value in the sriov_totalvfs
253+
file. A userspace application wanting to disable the VFs would
254+
write a zero to this file. The core ensures that valid values
255+
are written to this file, and returns errors when values are not
256+
valid. For example, writing a 2 to this file when sriov_numvfs
257+
is not 0 and not 2 already will return an error. Writing a 10
258+
when the value of sriov_totalvfs is 8 will return an error.

‎Documentation/PCI/pci-iov-howto.txt‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Copyright (C) 2009 Intel Corporation
33
Yu Zhao <yu.zhao@intel.com>
44

5+
Update: November 2012
6+
-- sysfs-based SRIOV enable-/disable-ment
7+
Donald Dutile <ddutile@redhat.com>
58

69
1. Overview
710

@@ -24,10 +27,21 @@ real existing PCI device.
2427

2528
2.1 How can I enable SR-IOV capability
2629

27-
The device driver (PF driver) will control the enabling and disabling
28-
of the capability via API provided by SR-IOV core. If the hardware
29-
has SR-IOV capability, loading its PF driver would enable it and all
30-
VFs associated with the PF.
30+
Multiple methods are available for SR-IOV enablement.
31+
In the first method, the device driver (PF driver) will control the
32+
enabling and disabling of the capability via API provided by SR-IOV core.
33+
If the hardware has SR-IOV capability, loading its PF driver would
34+
enable it and all VFs associated with the PF. Some PF drivers require
35+
a module parameter to be set to determine the number of VFs to enable.
36+
In the second method, a write to the sysfs file sriov_numvfs will
37+
enable and disable the VFs associated with a PCIe PF. This method
38+
enables per-PF, VF enable/disable values versus the first method,
39+
which applies to all PFs of the same device. Additionally, the
40+
PCI SRIOV core support ensures that enable/disable operations are
41+
valid to reduce duplication in multiple drivers for the same
42+
checks, e.g., check numvfs == 0 if enabling VFs, ensure
43+
numvfs <= totalvfs.
44+
The second method is the recommended method for new/future VF devices.
3145

3246
2.2 How can I use the Virtual Functions
3347

@@ -40,13 +54,22 @@ requires device driver that is same as a normal PCI device's.
4054
3.1 SR-IOV API
4155

4256
To enable SR-IOV capability:
57+
(a) For the first method, in the driver:
4358
int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
4459
'nr_virtfn' is number of VFs to be enabled.
60+
(b) For the second method, from sysfs:
61+
echo 'nr_virtfn' > \
62+
/sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_numvfs
4563

4664
To disable SR-IOV capability:
65+
(a) For the first method, in the driver:
4766
void pci_disable_sriov(struct pci_dev *dev);
67+
(b) For the second method, from sysfs:
68+
echo 0 > \
69+
/sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_numvfs
4870

4971
To notify SR-IOV core of Virtual Function Migration:
72+
(a) In the driver:
5073
irqreturn_t pci_sriov_migration(struct pci_dev *dev);
5174

5275
3.2 Usage example
@@ -88,6 +111,22 @@ static void dev_shutdown(struct pci_dev *dev)
88111
...
89112
}
90113

114+
static int dev_sriov_configure(struct pci_dev *dev, int numvfs)
115+
{
116+
if (numvfs > 0) {
117+
...
118+
pci_enable_sriov(dev, numvfs);
119+
...
120+
return numvfs;
121+
}
122+
if (numvfs == 0) {
123+
....
124+
pci_disable_sriov(dev);
125+
...
126+
return 0;
127+
}
128+
}
129+
91130
static struct pci_driver dev_driver = {
92131
.name = "SR-IOV Physical Function driver",
93132
.id_table = dev_id_table,
@@ -96,4 +135,5 @@ static struct pci_driver dev_driver = {
96135
.suspend = dev_suspend,
97136
.resume = dev_resume,
98137
.shutdown = dev_shutdown,
138+
.sriov_configure = dev_sriov_configure,
99139
};

0 commit comments

Comments
 (0)