From: Peter Colberg <[email protected]> Add a method to return the number of Virtual Functions (VF) enabled for a Physical Function (PF).
Expose the query in the PCI core callback context and return u16, matching the type of the VF count stored by the PCI core. Signed-off-by: Peter Colberg <[email protected]> Signed-off-by: Zhi Wang <[email protected]> Signed-off-by: Simon Song <[email protected]> --- rust/kernel/pci/iov.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/kernel/pci/iov.rs b/rust/kernel/pci/iov.rs index 6f8f95ed618..1ff0ce94f16 100644 --- a/rust/kernel/pci/iov.rs +++ b/rust/kernel/pci/iov.rs @@ -11,6 +11,17 @@ prelude::*, // }; +impl Device<device::Core<'_>> { + /// Returns the number of Virtual Functions (VF) enabled for a Physical Function (PF). + #[inline] + pub fn num_vf(&self) -> u16 { + // SAFETY: `self.as_raw()` is valid and this call runs in the PCI core callback context. + unsafe { bindings::pci_num_vf(self.as_raw()) } + .try_into() + .expect("pdev->sriov->num_VFs is u16") + } +} + impl Device<device::CoreInternal<'_>> { /// Enable the Single Root I/O Virtualization (SR-IOV) capability for this device, /// where `nr_virtfn` is number of Virtual Functions (VF) to enable. -- 2.43.7
