1 // SPDX-License-Identifier: GPL-2.0
3 * PCI Express I/O Virtualization (IOV) support
5 * Address Translation Service 1.0
7 * Copyright (C) 2009 Intel Corporation, Yu Zhao <yu.zhao@intel.com>
10 #include <linux/pci.h>
11 #include <linux/slab.h>
12 #include <linux/mutex.h>
13 #include <linux/export.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/pci-ats.h>
19 #define VIRTFN_ID_LEN 16
21 int pci_iov_virtfn_bus(struct pci_dev
*dev
, int vf_id
)
25 return dev
->bus
->number
+ ((dev
->devfn
+ dev
->sriov
->offset
+
26 dev
->sriov
->stride
* vf_id
) >> 8);
29 int pci_iov_virtfn_devfn(struct pci_dev
*dev
, int vf_id
)
33 return (dev
->devfn
+ dev
->sriov
->offset
+
34 dev
->sriov
->stride
* vf_id
) & 0xff;
38 * Per SR-IOV spec sec 3.3.10 and 3.3.11, First VF Offset and VF Stride may
39 * change when NumVFs changes.
41 * Update iov->offset and iov->stride when NumVFs is written.
43 static inline void pci_iov_set_numvfs(struct pci_dev
*dev
, int nr_virtfn
)
45 struct pci_sriov
*iov
= dev
->sriov
;
47 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_NUM_VF
, nr_virtfn
);
48 pci_read_config_word(dev
, iov
->pos
+ PCI_SRIOV_VF_OFFSET
, &iov
->offset
);
49 pci_read_config_word(dev
, iov
->pos
+ PCI_SRIOV_VF_STRIDE
, &iov
->stride
);
53 * The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride
54 * determine how many additional bus numbers will be consumed by VFs.
56 * Iterate over all valid NumVFs, validate offset and stride, and calculate
57 * the maximum number of bus numbers that could ever be required.
59 static int compute_max_vf_buses(struct pci_dev
*dev
)
61 struct pci_sriov
*iov
= dev
->sriov
;
62 int nr_virtfn
, busnr
, rc
= 0;
64 for (nr_virtfn
= iov
->total_VFs
; nr_virtfn
; nr_virtfn
--) {
65 pci_iov_set_numvfs(dev
, nr_virtfn
);
66 if (!iov
->offset
|| (nr_virtfn
> 1 && !iov
->stride
)) {
71 busnr
= pci_iov_virtfn_bus(dev
, nr_virtfn
- 1);
72 if (busnr
> iov
->max_VF_buses
)
73 iov
->max_VF_buses
= busnr
;
77 pci_iov_set_numvfs(dev
, 0);
81 static struct pci_bus
*virtfn_add_bus(struct pci_bus
*bus
, int busnr
)
83 struct pci_bus
*child
;
85 if (bus
->number
== busnr
)
88 child
= pci_find_bus(pci_domain_nr(bus
), busnr
);
92 child
= pci_add_new_bus(bus
, NULL
, busnr
);
96 pci_bus_insert_busn_res(child
, busnr
, busnr
);
101 static void virtfn_remove_bus(struct pci_bus
*physbus
, struct pci_bus
*virtbus
)
103 if (physbus
!= virtbus
&& list_empty(&virtbus
->devices
))
104 pci_remove_bus(virtbus
);
107 resource_size_t
pci_iov_resource_size(struct pci_dev
*dev
, int resno
)
112 return dev
->sriov
->barsz
[resno
- PCI_IOV_RESOURCES
];
115 static void pci_read_vf_config_common(struct pci_dev
*virtfn
)
117 struct pci_dev
*physfn
= virtfn
->physfn
;
120 * Some config registers are the same across all associated VFs.
121 * Read them once from VF0 so we can skip reading them from the
124 * PCIe r4.0, sec 9.3.4.1, technically doesn't require all VFs to
125 * have the same Revision ID and Subsystem ID, but we assume they
128 pci_read_config_dword(virtfn
, PCI_CLASS_REVISION
,
129 &physfn
->sriov
->class);
130 pci_read_config_byte(virtfn
, PCI_HEADER_TYPE
,
131 &physfn
->sriov
->hdr_type
);
132 pci_read_config_word(virtfn
, PCI_SUBSYSTEM_VENDOR_ID
,
133 &physfn
->sriov
->subsystem_vendor
);
134 pci_read_config_word(virtfn
, PCI_SUBSYSTEM_ID
,
135 &physfn
->sriov
->subsystem_device
);
138 int pci_iov_add_virtfn(struct pci_dev
*dev
, int id
)
143 char buf
[VIRTFN_ID_LEN
];
144 struct pci_dev
*virtfn
;
145 struct resource
*res
;
146 struct pci_sriov
*iov
= dev
->sriov
;
149 bus
= virtfn_add_bus(dev
->bus
, pci_iov_virtfn_bus(dev
, id
));
153 virtfn
= pci_alloc_dev(bus
);
157 virtfn
->devfn
= pci_iov_virtfn_devfn(dev
, id
);
158 virtfn
->vendor
= dev
->vendor
;
159 virtfn
->device
= iov
->vf_device
;
160 virtfn
->is_virtfn
= 1;
161 virtfn
->physfn
= pci_dev_get(dev
);
164 pci_read_vf_config_common(virtfn
);
166 rc
= pci_setup_device(virtfn
);
170 virtfn
->dev
.parent
= dev
->dev
.parent
;
171 virtfn
->multifunction
= 0;
173 for (i
= 0; i
< PCI_SRIOV_NUM_BARS
; i
++) {
174 res
= &dev
->resource
[i
+ PCI_IOV_RESOURCES
];
177 virtfn
->resource
[i
].name
= pci_name(virtfn
);
178 virtfn
->resource
[i
].flags
= res
->flags
;
179 size
= pci_iov_resource_size(dev
, i
+ PCI_IOV_RESOURCES
);
180 virtfn
->resource
[i
].start
= res
->start
+ size
* id
;
181 virtfn
->resource
[i
].end
= virtfn
->resource
[i
].start
+ size
- 1;
182 rc
= request_resource(res
, &virtfn
->resource
[i
]);
186 pci_device_add(virtfn
, virtfn
->bus
);
188 sprintf(buf
, "virtfn%u", id
);
189 rc
= sysfs_create_link(&dev
->dev
.kobj
, &virtfn
->dev
.kobj
, buf
);
192 rc
= sysfs_create_link(&virtfn
->dev
.kobj
, &dev
->dev
.kobj
, "physfn");
196 kobject_uevent(&virtfn
->dev
.kobj
, KOBJ_CHANGE
);
198 pci_bus_add_device(virtfn
);
203 sysfs_remove_link(&dev
->dev
.kobj
, buf
);
205 pci_stop_and_remove_bus_device(virtfn
);
208 virtfn_remove_bus(dev
->bus
, bus
);
214 void pci_iov_remove_virtfn(struct pci_dev
*dev
, int id
)
216 char buf
[VIRTFN_ID_LEN
];
217 struct pci_dev
*virtfn
;
219 virtfn
= pci_get_domain_bus_and_slot(pci_domain_nr(dev
->bus
),
220 pci_iov_virtfn_bus(dev
, id
),
221 pci_iov_virtfn_devfn(dev
, id
));
225 sprintf(buf
, "virtfn%u", id
);
226 sysfs_remove_link(&dev
->dev
.kobj
, buf
);
228 * pci_stop_dev() could have been called for this virtfn already,
229 * so the directory for the virtfn may have been removed before.
230 * Double check to avoid spurious sysfs warnings.
232 if (virtfn
->dev
.kobj
.sd
)
233 sysfs_remove_link(&virtfn
->dev
.kobj
, "physfn");
235 pci_stop_and_remove_bus_device(virtfn
);
236 virtfn_remove_bus(dev
->bus
, virtfn
->bus
);
238 /* balance pci_get_domain_bus_and_slot() */
243 int __weak
pcibios_sriov_enable(struct pci_dev
*pdev
, u16 num_vfs
)
248 int __weak
pcibios_sriov_disable(struct pci_dev
*pdev
)
253 static int sriov_enable(struct pci_dev
*dev
, int nr_virtfn
)
259 struct resource
*res
;
260 struct pci_dev
*pdev
;
261 struct pci_sriov
*iov
= dev
->sriov
;
271 pci_read_config_word(dev
, iov
->pos
+ PCI_SRIOV_INITIAL_VF
, &initial
);
272 if (initial
> iov
->total_VFs
||
273 (!(iov
->cap
& PCI_SRIOV_CAP_VFM
) && (initial
!= iov
->total_VFs
)))
276 if (nr_virtfn
< 0 || nr_virtfn
> iov
->total_VFs
||
277 (!(iov
->cap
& PCI_SRIOV_CAP_VFM
) && (nr_virtfn
> initial
)))
281 for (i
= 0; i
< PCI_SRIOV_NUM_BARS
; i
++) {
282 bars
|= (1 << (i
+ PCI_IOV_RESOURCES
));
283 res
= &dev
->resource
[i
+ PCI_IOV_RESOURCES
];
287 if (nres
!= iov
->nres
) {
288 pci_err(dev
, "not enough MMIO resources for SR-IOV\n");
292 bus
= pci_iov_virtfn_bus(dev
, nr_virtfn
- 1);
293 if (bus
> dev
->bus
->busn_res
.end
) {
294 pci_err(dev
, "can't enable %d VFs (bus %02x out of range of %pR)\n",
295 nr_virtfn
, bus
, &dev
->bus
->busn_res
);
299 if (pci_enable_resources(dev
, bars
)) {
300 pci_err(dev
, "SR-IOV: IOV BARS not allocated\n");
304 if (iov
->link
!= dev
->devfn
) {
305 pdev
= pci_get_slot(dev
->bus
, iov
->link
);
309 if (!pdev
->is_physfn
) {
314 rc
= sysfs_create_link(&dev
->dev
.kobj
,
315 &pdev
->dev
.kobj
, "dep_link");
321 iov
->initial_VFs
= initial
;
322 if (nr_virtfn
< initial
)
325 rc
= pcibios_sriov_enable(dev
, initial
);
327 pci_err(dev
, "failure %d from pcibios_sriov_enable()\n", rc
);
331 pci_iov_set_numvfs(dev
, nr_virtfn
);
332 iov
->ctrl
|= PCI_SRIOV_CTRL_VFE
| PCI_SRIOV_CTRL_MSE
;
333 pci_cfg_access_lock(dev
);
334 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, iov
->ctrl
);
336 pci_cfg_access_unlock(dev
);
338 for (i
= 0; i
< initial
; i
++) {
339 rc
= pci_iov_add_virtfn(dev
, i
);
344 kobject_uevent(&dev
->dev
.kobj
, KOBJ_CHANGE
);
345 iov
->num_VFs
= nr_virtfn
;
351 pci_iov_remove_virtfn(dev
, i
);
354 iov
->ctrl
&= ~(PCI_SRIOV_CTRL_VFE
| PCI_SRIOV_CTRL_MSE
);
355 pci_cfg_access_lock(dev
);
356 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, iov
->ctrl
);
358 pci_cfg_access_unlock(dev
);
360 pcibios_sriov_disable(dev
);
362 if (iov
->link
!= dev
->devfn
)
363 sysfs_remove_link(&dev
->dev
.kobj
, "dep_link");
365 pci_iov_set_numvfs(dev
, 0);
369 static void sriov_disable(struct pci_dev
*dev
)
372 struct pci_sriov
*iov
= dev
->sriov
;
377 for (i
= 0; i
< iov
->num_VFs
; i
++)
378 pci_iov_remove_virtfn(dev
, i
);
380 iov
->ctrl
&= ~(PCI_SRIOV_CTRL_VFE
| PCI_SRIOV_CTRL_MSE
);
381 pci_cfg_access_lock(dev
);
382 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, iov
->ctrl
);
384 pci_cfg_access_unlock(dev
);
386 pcibios_sriov_disable(dev
);
388 if (iov
->link
!= dev
->devfn
)
389 sysfs_remove_link(&dev
->dev
.kobj
, "dep_link");
392 pci_iov_set_numvfs(dev
, 0);
395 static int sriov_init(struct pci_dev
*dev
, int pos
)
402 struct pci_sriov
*iov
;
403 struct resource
*res
;
404 struct pci_dev
*pdev
;
406 pci_read_config_word(dev
, pos
+ PCI_SRIOV_CTRL
, &ctrl
);
407 if (ctrl
& PCI_SRIOV_CTRL_VFE
) {
408 pci_write_config_word(dev
, pos
+ PCI_SRIOV_CTRL
, 0);
413 list_for_each_entry(pdev
, &dev
->bus
->devices
, bus_list
)
418 if (pci_ari_enabled(dev
->bus
))
419 ctrl
|= PCI_SRIOV_CTRL_ARI
;
422 pci_write_config_word(dev
, pos
+ PCI_SRIOV_CTRL
, ctrl
);
424 pci_read_config_word(dev
, pos
+ PCI_SRIOV_TOTAL_VF
, &total
);
428 pci_read_config_dword(dev
, pos
+ PCI_SRIOV_SUP_PGSIZE
, &pgsz
);
429 i
= PAGE_SHIFT
> 12 ? PAGE_SHIFT
- 12 : 0;
430 pgsz
&= ~((1 << i
) - 1);
435 pci_write_config_dword(dev
, pos
+ PCI_SRIOV_SYS_PGSIZE
, pgsz
);
437 iov
= kzalloc(sizeof(*iov
), GFP_KERNEL
);
442 for (i
= 0; i
< PCI_SRIOV_NUM_BARS
; i
++) {
443 res
= &dev
->resource
[i
+ PCI_IOV_RESOURCES
];
445 * If it is already FIXED, don't change it, something
446 * (perhaps EA or header fixups) wants it this way.
448 if (res
->flags
& IORESOURCE_PCI_FIXED
)
449 bar64
= (res
->flags
& IORESOURCE_MEM_64
) ? 1 : 0;
451 bar64
= __pci_read_base(dev
, pci_bar_unknown
, res
,
452 pos
+ PCI_SRIOV_BAR
+ i
* 4);
455 if (resource_size(res
) & (PAGE_SIZE
- 1)) {
459 iov
->barsz
[i
] = resource_size(res
);
460 res
->end
= res
->start
+ resource_size(res
) * total
- 1;
461 pci_info(dev
, "VF(n) BAR%d space: %pR (contains BAR%d for %d VFs)\n",
470 iov
->total_VFs
= total
;
471 iov
->driver_max_VFs
= total
;
472 pci_read_config_word(dev
, pos
+ PCI_SRIOV_VF_DID
, &iov
->vf_device
);
475 iov
->drivers_autoprobe
= true;
476 pci_read_config_dword(dev
, pos
+ PCI_SRIOV_CAP
, &iov
->cap
);
477 pci_read_config_byte(dev
, pos
+ PCI_SRIOV_FUNC_LINK
, &iov
->link
);
478 if (pci_pcie_type(dev
) == PCI_EXP_TYPE_RC_END
)
479 iov
->link
= PCI_DEVFN(PCI_SLOT(dev
->devfn
), iov
->link
);
482 iov
->dev
= pci_dev_get(pdev
);
488 rc
= compute_max_vf_buses(dev
);
498 for (i
= 0; i
< PCI_SRIOV_NUM_BARS
; i
++) {
499 res
= &dev
->resource
[i
+ PCI_IOV_RESOURCES
];
507 static void sriov_release(struct pci_dev
*dev
)
509 BUG_ON(dev
->sriov
->num_VFs
);
511 if (dev
!= dev
->sriov
->dev
)
512 pci_dev_put(dev
->sriov
->dev
);
518 static void sriov_restore_state(struct pci_dev
*dev
)
522 struct pci_sriov
*iov
= dev
->sriov
;
524 pci_read_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, &ctrl
);
525 if (ctrl
& PCI_SRIOV_CTRL_VFE
)
529 * Restore PCI_SRIOV_CTRL_ARI before pci_iov_set_numvfs() because
530 * it reads offset & stride, which depend on PCI_SRIOV_CTRL_ARI.
532 ctrl
&= ~PCI_SRIOV_CTRL_ARI
;
533 ctrl
|= iov
->ctrl
& PCI_SRIOV_CTRL_ARI
;
534 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, ctrl
);
536 for (i
= PCI_IOV_RESOURCES
; i
<= PCI_IOV_RESOURCE_END
; i
++)
537 pci_update_resource(dev
, i
);
539 pci_write_config_dword(dev
, iov
->pos
+ PCI_SRIOV_SYS_PGSIZE
, iov
->pgsz
);
540 pci_iov_set_numvfs(dev
, iov
->num_VFs
);
541 pci_write_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, iov
->ctrl
);
542 if (iov
->ctrl
& PCI_SRIOV_CTRL_VFE
)
547 * pci_iov_init - initialize the IOV capability
548 * @dev: the PCI device
550 * Returns 0 on success, or negative on failure.
552 int pci_iov_init(struct pci_dev
*dev
)
556 if (!pci_is_pcie(dev
))
559 pos
= pci_find_ext_capability(dev
, PCI_EXT_CAP_ID_SRIOV
);
561 return sriov_init(dev
, pos
);
567 * pci_iov_release - release resources used by the IOV capability
568 * @dev: the PCI device
570 void pci_iov_release(struct pci_dev
*dev
)
577 * pci_iov_remove - clean up SR-IOV state after PF driver is detached
578 * @dev: the PCI device
580 void pci_iov_remove(struct pci_dev
*dev
)
582 struct pci_sriov
*iov
= dev
->sriov
;
587 iov
->driver_max_VFs
= iov
->total_VFs
;
589 pci_warn(dev
, "driver left SR-IOV enabled after remove\n");
593 * pci_iov_update_resource - update a VF BAR
594 * @dev: the PCI device
595 * @resno: the resource number
597 * Update a VF BAR in the SR-IOV capability of a PF.
599 void pci_iov_update_resource(struct pci_dev
*dev
, int resno
)
601 struct pci_sriov
*iov
= dev
->is_physfn
? dev
->sriov
: NULL
;
602 struct resource
*res
= dev
->resource
+ resno
;
603 int vf_bar
= resno
- PCI_IOV_RESOURCES
;
604 struct pci_bus_region region
;
610 * The generic pci_restore_bars() path calls this for all devices,
611 * including VFs and non-SR-IOV devices. If this is not a PF, we
612 * have nothing to do.
617 pci_read_config_word(dev
, iov
->pos
+ PCI_SRIOV_CTRL
, &cmd
);
618 if ((cmd
& PCI_SRIOV_CTRL_VFE
) && (cmd
& PCI_SRIOV_CTRL_MSE
)) {
619 dev_WARN(&dev
->dev
, "can't update enabled VF BAR%d %pR\n",
625 * Ignore unimplemented BARs, unused resource slots for 64-bit
626 * BARs, and non-movable resources, e.g., those described via
627 * Enhanced Allocation.
632 if (res
->flags
& IORESOURCE_UNSET
)
635 if (res
->flags
& IORESOURCE_PCI_FIXED
)
638 pcibios_resource_to_bus(dev
->bus
, ®ion
, res
);
640 new |= res
->flags
& ~PCI_BASE_ADDRESS_MEM_MASK
;
642 reg
= iov
->pos
+ PCI_SRIOV_BAR
+ 4 * vf_bar
;
643 pci_write_config_dword(dev
, reg
, new);
644 if (res
->flags
& IORESOURCE_MEM_64
) {
645 new = region
.start
>> 16 >> 16;
646 pci_write_config_dword(dev
, reg
+ 4, new);
650 resource_size_t __weak
pcibios_iov_resource_alignment(struct pci_dev
*dev
,
653 return pci_iov_resource_size(dev
, resno
);
657 * pci_sriov_resource_alignment - get resource alignment for VF BAR
658 * @dev: the PCI device
659 * @resno: the resource number
661 * Returns the alignment of the VF BAR found in the SR-IOV capability.
662 * This is not the same as the resource size which is defined as
663 * the VF BAR size multiplied by the number of VFs. The alignment
664 * is just the VF BAR size.
666 resource_size_t
pci_sriov_resource_alignment(struct pci_dev
*dev
, int resno
)
668 return pcibios_iov_resource_alignment(dev
, resno
);
672 * pci_restore_iov_state - restore the state of the IOV capability
673 * @dev: the PCI device
675 void pci_restore_iov_state(struct pci_dev
*dev
)
678 sriov_restore_state(dev
);
682 * pci_vf_drivers_autoprobe - set PF property drivers_autoprobe for VFs
683 * @dev: the PCI device
684 * @auto_probe: set VF drivers auto probe flag
686 void pci_vf_drivers_autoprobe(struct pci_dev
*dev
, bool auto_probe
)
689 dev
->sriov
->drivers_autoprobe
= auto_probe
;
693 * pci_iov_bus_range - find bus range used by Virtual Function
696 * Returns max number of buses (exclude current one) used by Virtual
699 int pci_iov_bus_range(struct pci_bus
*bus
)
704 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
707 if (dev
->sriov
->max_VF_buses
> max
)
708 max
= dev
->sriov
->max_VF_buses
;
711 return max
? max
- bus
->number
: 0;
715 * pci_enable_sriov - enable the SR-IOV capability
716 * @dev: the PCI device
717 * @nr_virtfn: number of virtual functions to enable
719 * Returns 0 on success, or negative on failure.
721 int pci_enable_sriov(struct pci_dev
*dev
, int nr_virtfn
)
728 return sriov_enable(dev
, nr_virtfn
);
730 EXPORT_SYMBOL_GPL(pci_enable_sriov
);
733 * pci_disable_sriov - disable the SR-IOV capability
734 * @dev: the PCI device
736 void pci_disable_sriov(struct pci_dev
*dev
)
745 EXPORT_SYMBOL_GPL(pci_disable_sriov
);
748 * pci_num_vf - return number of VFs associated with a PF device_release_driver
749 * @dev: the PCI device
751 * Returns number of VFs, or 0 if SR-IOV is not enabled.
753 int pci_num_vf(struct pci_dev
*dev
)
758 return dev
->sriov
->num_VFs
;
760 EXPORT_SYMBOL_GPL(pci_num_vf
);
763 * pci_vfs_assigned - returns number of VFs are assigned to a guest
764 * @dev: the PCI device
766 * Returns number of VFs belonging to this device that are assigned to a guest.
767 * If device is not a physical function returns 0.
769 int pci_vfs_assigned(struct pci_dev
*dev
)
771 struct pci_dev
*vfdev
;
772 unsigned int vfs_assigned
= 0;
773 unsigned short dev_id
;
775 /* only search if we are a PF */
780 * determine the device ID for the VFs, the vendor ID will be the
781 * same as the PF so there is no need to check for that one
783 dev_id
= dev
->sriov
->vf_device
;
785 /* loop through all the VFs to see if we own any that are assigned */
786 vfdev
= pci_get_device(dev
->vendor
, dev_id
, NULL
);
789 * It is considered assigned if it is a virtual function with
790 * our dev as the physical function and the assigned bit is set
792 if (vfdev
->is_virtfn
&& (vfdev
->physfn
== dev
) &&
793 pci_is_dev_assigned(vfdev
))
796 vfdev
= pci_get_device(dev
->vendor
, dev_id
, vfdev
);
801 EXPORT_SYMBOL_GPL(pci_vfs_assigned
);
804 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
805 * @dev: the PCI PF device
806 * @numvfs: number that should be used for TotalVFs supported
808 * Should be called from PF driver's probe routine with
809 * device's mutex held.
811 * Returns 0 if PF is an SRIOV-capable device and
812 * value of numvfs valid. If not a PF return -ENOSYS;
813 * if numvfs is invalid return -EINVAL;
814 * if VFs already enabled, return -EBUSY.
816 int pci_sriov_set_totalvfs(struct pci_dev
*dev
, u16 numvfs
)
821 if (numvfs
> dev
->sriov
->total_VFs
)
824 /* Shouldn't change if VFs already enabled */
825 if (dev
->sriov
->ctrl
& PCI_SRIOV_CTRL_VFE
)
828 dev
->sriov
->driver_max_VFs
= numvfs
;
831 EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs
);
834 * pci_sriov_get_totalvfs -- get total VFs supported on this device
835 * @dev: the PCI PF device
837 * For a PCIe device with SRIOV support, return the PCIe
838 * SRIOV capability value of TotalVFs or the value of driver_max_VFs
839 * if the driver reduced it. Otherwise 0.
841 int pci_sriov_get_totalvfs(struct pci_dev
*dev
)
846 return dev
->sriov
->driver_max_VFs
;
848 EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs
);
851 * pci_sriov_configure_simple - helper to configure SR-IOV
852 * @dev: the PCI device
853 * @nr_virtfn: number of virtual functions to enable, 0 to disable
855 * Enable or disable SR-IOV for devices that don't require any PF setup
856 * before enabling SR-IOV. Return value is negative on error, or number of
857 * VFs allocated on success.
859 int pci_sriov_configure_simple(struct pci_dev
*dev
, int nr_virtfn
)
868 if (pci_vfs_assigned(dev
)) {
869 pci_warn(dev
, "Cannot modify SR-IOV while VFs are assigned\n");
873 if (nr_virtfn
== 0) {
878 rc
= sriov_enable(dev
, nr_virtfn
);
884 EXPORT_SYMBOL_GPL(pci_sriov_configure_simple
);