[PATCH 1/9] rust: pci: expose sriov_get_totalvfs() helper
From: Zhi Wang
Date: Thu Jun 04 2026 - 07:49:11 EST
Add a wrapper for the `pci_sriov_get_totalvfs()` helper, allowing drivers
to query the number of total SR-IOV virtual functions a PCI device
supports.
Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Cc: linux-pci@xxxxxxxxxxxxxxx
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 5071cae6543f..d04e5f6841f2 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -450,6 +450,18 @@ pub fn pci_class(&self) -> Class {
// SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
Class::from_raw(unsafe { (*self.as_raw()).class })
}
+
+ /// Returns total number of VFs, or `Err(ENODEV)` if none available.
+ pub fn sriov_get_totalvfs(&self) -> Result<i32> {
+ // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`.
+ let vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) };
+
+ if vfs == 0 {
+ return Err(ENODEV);
+ }
+
+ Ok(vfs)
+ }
}
impl<'a> Device<device::Core<'a>> {
--
2.51.0