[PATCH v3 05/10] rust: pci: add num_vf(), to return number of VFs

From: Zhi Wang

Date: Wed Sep 30 2026 - 06:38:19 EST


From: Peter Colberg <peter@xxxxxxxxxxx>

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.

Signed-off-by: Peter Colberg <peter@xxxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci/iov.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/rust/kernel/pci/iov.rs b/rust/kernel/pci/iov.rs
index a4a23a9ea77a..4f611d5d0b89 100644
--- a/rust/kernel/pci/iov.rs
+++ b/rust/kernel/pci/iov.rs
@@ -28,6 +28,14 @@ pub fn is_virtfn(&self) -> bool {
}
}

+impl Device<device::Core<'_>> {
+ /// Returns the number of Virtual Functions (VF) enabled for a Physical Function (PF).
+ pub fn num_vf(&self) -> i32 {
+ // SAFETY: `self.as_raw()` is valid and this call runs in the PCI core callback context.
+ unsafe { bindings::pci_num_vf(self.as_raw()) }
+ }
+}
+
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.53.0