[PATCH 07/14] rust: pci: add num_vf(), to return number of VFs
From: Zhi Wang
Date: Tue Sep 15 2026 - 17:01:26 EST
From: Peter Colberg <pcolberg@xxxxxxxxxx>
Add a method to return the number of Virtual Functions (VF) enabled for
a Physical Function (PF).
zhiw: Keep this helper private to the PCI SR-IOV implementation instead
of extending the public `Device` API. Add a dead-code expectation
because this standalone API commit has no in-tree caller.
Signed-off-by: Peter Colberg <pcolberg@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index ed42511911d7..f2d71daef83a 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -523,6 +523,14 @@ pub(crate) fn is_virtfn(&self) -> bool {
unsafe { (*self.as_raw()).is_virtfn() != 0 }
}
+ /// Returns the number of Virtual Functions (VF) enabled for a Physical Function (PF).
+ #[cfg(CONFIG_PCI_IOV)]
+ #[expect(dead_code)]
+ pub(crate) fn num_vf(&self) -> i32 {
+ // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+ unsafe { bindings::pci_num_vf(self.as_raw()) }
+ }
+
/// Returns the size of the given PCI BAR resource.
pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
if !Bar::index_is_valid(bar) {