On Sat Dec 6, 2025 at 9:42 PM JST, Zhi Wang wrote:
> 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.
>
> This is useful for components that need to conditionally enable features
> based on SR-IOV capability.
>
> Signed-off-by: Zhi Wang <[email protected]>
> ---
> rust/kernel/pci.rs | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 7fcc5f6022c1..9a82e83dfd30 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -514,6 +514,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()) };
This results in a build error if CONFIG_PCI_IOV is not set:
error[E0425]: cannot find function `pci_sriov_get_totalvfs` in crate `bindings`
--> ../rust/kernel/pci.rs:521:38
|
521 | let vfs = unsafe {
bindings::pci_sriov_get_totalvfs(self.as_raw()) };
| ^^^^^^^^^^^^^^^^^^^^^^ not found in
`bindings`
error: aborting due to 1 previous error