[PATCH v6 09/11] rust: pci: add SriovEnable::enable_all(), to enable all requested VFs

From: Simon Song

Date: Wed Nov 11 2026 - 17:44:56 EST


PF drivers typically enable all VFs that userspace requests through
sriov_numvfs. With the SriovEnable token this takes two steps:
enable() consumes the token, so the requested count has to be read
from it first:

let num_vfs = token.num_vfs();
token.enable(num_vfs)

Add enable_all() for this common case. It passes the requested number
of VFs to enable(), so callers do not need to handle the count.

Suggested-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Signed-off-by: Simon Song <xinmengs@xxxxxxxxxx>
---
rust/kernel/pci/iov.rs | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/rust/kernel/pci/iov.rs b/rust/kernel/pci/iov.rs
index bda2bffffcda..a3d1c4c567f7 100644
--- a/rust/kernel/pci/iov.rs
+++ b/rust/kernel/pci/iov.rs
@@ -158,6 +158,20 @@ pub fn enable(self, num_vfs: NonZero<u16>) -> Result<SriovEnabled<'a>> {
num_vfs,
})
}
+
+ /// Enables all VFs requested for this callback.
+ ///
+ /// This is equivalent to calling [`Self::enable()`] with [`Self::num_vfs()`].
+ ///
+ /// # Errors
+ ///
+ /// - [`ENODEV`]: the PF driver has not registered a [`VfRegistration`].
+ /// - Any error returned by `pci_enable_sriov()`.
+ #[inline]
+ pub fn enable_all(self) -> Result<SriovEnabled<'a>> {
+ let num_vfs = self.num_vfs;
+ self.enable(num_vfs)
+ }
}

/// Enabled VFs awaiting successful completion of `sriov_enable()`.
--
2.43.7