[PATCH 4/8] rust: pci: add num_vf(), to return number of VFs

Peter Colberg
2025-11-19T22:19:26Z

Add a method to return the number of Virtual Functions (VF) enabled for
a Physical Function (PF).

Signed-off-by: Peter Colberg <pcolberg@redhat.com>
---
rust/kernel/pci.rs | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 556a01ed9bc3b1300a3340a3d2383e08ceacbfe5..edb2bd41c8a14c8cfc421b26cda4dc84f75b546d 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -421,6 +421,13 @@ pub 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)]
+ pub 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) {

--
2.51.1