Re: [PATCH v3 01/10] rust: pci: add internal SR-IOV enable and disable helpers
From: Danilo Krummrich
Date: Wed Sep 30 2026 - 07:04:06 EST
On Wed Sep 30, 2026 at 12:18 PM CEST, Zhi Wang wrote:
> +impl Device<device::CoreInternal<'_>> {
> + /// Enable the Single Root I/O Virtualization (SR-IOV) capability for this device,
> + /// where `nr_virtfn` is number of Virtual Functions (VF) to enable.
> + #[expect(dead_code)]
> + pub(crate) fn enable_sriov(&self, nr_virtfn: c_int) -> Result {
This can just be a u16; there are no implicit type conversions in Rust and the
PCIe SR-IOV spec defines this as 16bit register.
The conversion should be infallible, so you can just pass nr_virtfn.into().
> + // SAFETY:
> + // `self.as_raw` returns a valid pointer to a `struct pci_dev`.
> + //
> + // `pci_enable_sriov()` checks that the enable operation is valid:
> + // - the device is a Physical Function (PF),
> + // - SR-IOV is currently disabled, and
> + // - `nr_virtfn` does not exceed the total number of supported VFs.
> + //
> + // The CoreInternal device context inherits from the Bound device context,
> + // which guarantees that the PF device is bound to a driver.
// - `self.as_raw` returns a valid pointer to a `struct pci_dev`.
//
// - `pci_enable_sriov()` checks that the enable operation is valid:
// - the device is a Physical Function (PF),
// - SR-IOV is currently disabled, and
// - `nr_virtfn` does not exceed the total number of supported VFs.
//
// - The [`CoreInternal`] device context inherits from the [`Bound`] device context,
// which guarantees that the PF device is bound to a driver.
> + to_result(unsafe { bindings::pci_enable_sriov(self.as_raw(), nr_virtfn) })
> + }