From: "Gary Guo" <gary@garyguo.net>
To: "Zhi Wang" <zhiw@nvidia.com>, <rust-for-linux@vger.kernel.org>,
<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <dakr@kernel.org>, <aliceryhl@google.com>, <bhelgaas@google.com>,
<kwilczynski@kernel.org>, <ojeda@kernel.org>,
<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
<lossin@kernel.org>, <a.hindborg@kernel.org>, <tmgross@umich.edu>,
<markus.probst@posteo.de>, <helgaas@kernel.org>,
<cjia@nvidia.com>, <smitra@nvidia.com>, <ankita@nvidia.com>,
<aniketa@nvidia.com>, <kwankhede@nvidia.com>,
<targupta@nvidia.com>, <acourbot@nvidia.com>,
<joelagnelf@nvidia.com>, <jhubbard@nvidia.com>,
<zhiwang@kernel.org>, <daniel.almeida@collabora.com>,
"Jason Gunthorpe" <jgg@nvidia.com>
Subject: Re: [PATCH v2 1/2] rust: introduce abstractions for fwctl
Date: Mon, 26 Jan 2026 17:48:09 +0000 [thread overview]
Message-ID: <DFYPKDARUMSH.21DBL43XL21S2@garyguo.net> (raw)
In-Reply-To: <20260122204232.15988-2-zhiw@nvidia.com>
On Thu Jan 22, 2026 at 8:42 PM GMT, Zhi Wang wrote:
> Introduce safe wrappers around `struct fwctl_device` and
> `struct fwctl_uctx`, allowing rust drivers to register fwctl devices and
> implement their control and RPC logic in safe rust.
>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Zhi Wang <zhiw@nvidia.com>
> ---
> drivers/fwctl/Kconfig | 12 +
> include/uapi/fwctl/fwctl.h | 1 +
> rust/bindings/bindings_helper.h | 1 +
> rust/helpers/fwctl.c | 17 ++
> rust/helpers/helpers.c | 3 +-
> rust/kernel/fwctl.rs | 456 ++++++++++++++++++++++++++++++++
> rust/kernel/lib.rs | 2 +
> 7 files changed, 491 insertions(+), 1 deletion(-)
> create mode 100644 rust/helpers/fwctl.c
> create mode 100644 rust/kernel/fwctl.rs
>
> diff --git a/drivers/fwctl/Kconfig b/drivers/fwctl/Kconfig
> index b5583b12a011..d8538249f3ae 100644
> --- a/drivers/fwctl/Kconfig
> +++ b/drivers/fwctl/Kconfig
> @@ -8,6 +8,18 @@ menuconfig FWCTL
> manipulating device FLASH, debugging, and other activities that don't
> fit neatly into an existing subsystem.
>
> +config RUST_FWCTL_ABSTRACTIONS
> + bool "Rust fwctl abstractions"
> + depends on RUST
> + select FWCTL
> + help
> + This enables the Rust abstractions for the fwctl device firmware
> + access framework. It provides safe wrappers around struct fwctl_device
> + and struct fwctl_uctx, allowing Rust drivers to register fwctl devices
> + and implement their control and RPC logic in safe Rust.
> +
> + If unsure, say N.
> +
> if FWCTL
> config FWCTL_MLX5
> tristate "mlx5 ConnectX control fwctl driver"
> diff --git a/include/uapi/fwctl/fwctl.h b/include/uapi/fwctl/fwctl.h
> index 716ac0eee42d..eea1020ad180 100644
> --- a/include/uapi/fwctl/fwctl.h
> +++ b/include/uapi/fwctl/fwctl.h
> @@ -45,6 +45,7 @@ enum fwctl_device_type {
> FWCTL_DEVICE_TYPE_MLX5 = 1,
> FWCTL_DEVICE_TYPE_CXL = 2,
> FWCTL_DEVICE_TYPE_PDS = 4,
> + FWCTL_DEVICE_TYPE_RUST_FWCTL_TEST = 8,
This is UAPI, adding new device type just for testing is not ideal.
> };
>
> /**
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> index 9fdf76ca630e..2c50d5bab0cf 100644
> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -56,6 +56,7 @@
> #include <linux/fdtable.h>
> #include <linux/file.h>
> #include <linux/firmware.h>
> +#include <linux/fwctl.h>
> #include <linux/interrupt.h>
> #include <linux/fs.h>
> #include <linux/i2c.h>
> diff --git a/rust/helpers/fwctl.c b/rust/helpers/fwctl.c
> new file mode 100644
> index 000000000000..bb4a028e7afb
> --- /dev/null
> +++ b/rust/helpers/fwctl.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/fwctl.h>
> +
> +#if IS_ENABLED(CONFIG_RUST_FWCTL_ABSTRACTIONS)
> +
> +struct fwctl_device *rust_helper_fwctl_get(struct fwctl_device *fwctl)
Helpers need to have __rust_helper.
> +{
> + return fwctl_get(fwctl);
> +}
> +
> +void rust_helper_fwctl_put(struct fwctl_device *fwctl)
> +{
> + fwctl_put(fwctl);
> +}
> +
> +#endif
> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
> index 79c72762ad9c..19a505473bef 100644
> --- a/rust/helpers/helpers.c
> +++ b/rust/helpers/helpers.c
> @@ -27,8 +27,9 @@
> #include "dma.c"
> #include "drm.c"
> #include "err.c"
> -#include "irq.c"
> #include "fs.c"
> +#include "fwctl.c"
> +#include "irq.c"
> #include "io.c"
> #include "jump_label.c"
> #include "kunit.c"
> diff --git a/rust/kernel/fwctl.rs b/rust/kernel/fwctl.rs
> new file mode 100644
> index 000000000000..4065c948784d
> --- /dev/null
> +++ b/rust/kernel/fwctl.rs
> @@ -0,0 +1,456 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +//! Abstractions for the fwctl.
> +//!
> +//! This module provides bindings for working with fwctl devices in kernel modules.
> +//!
> +//! C header: [`include/linux/fwctl.h`]
> +
> +use crate::{
> + bindings,
> + container_of,
> + device,
> + devres::Devres,
> + prelude::*,
> + types::{
> + ARef,
> + Opaque, //
> + }, //
> +};
> +use core::{
> + marker::PhantomData,
> + ptr::NonNull,
> + slice, //
> +};
> +
> +/// Represents a fwctl device type.
> +///
> +/// This enum corresponds to the C `enum fwctl_device_type` and is used to identify
> +/// the specific firmware control interface implemented by a device.
> +#[repr(u32)]
> +#[derive(Copy, Clone, Debug, Eq, PartialEq)]
> +pub enum DeviceType {
> + /// Error/invalid device type.
> + Error = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_ERROR,
Does this need to be present? I took a look at the C side, this isn't used at
all. It'll be a bug if `Operations` impl uses this value as their `DEVICE_TYPE`.
Best,
Gary
> + /// MLX5 device type.
> + Mlx5 = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_MLX5,
> + /// CXL device type.
> + Cxl = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_CXL,
> + /// PDS device type.
> + Pds = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_PDS,
> + /// Rust fwctl test device type.
> + RustFwctlTest = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_RUST_FWCTL_TEST,
> +}
> +
> +impl From<DeviceType> for u32 {
> + fn from(device_type: DeviceType) -> Self {
> + device_type as u32
> + }
> +}
next prev parent reply other threads:[~2026-01-26 17:48 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 20:42 [PATCH v2 0/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-22 20:42 ` [PATCH v2 1/2] " Zhi Wang
2026-01-22 21:17 ` Joel Fernandes
2026-01-23 10:25 ` Zhi Wang
2026-01-26 17:48 ` Gary Guo [this message]
2026-01-27 19:59 ` Zhi Wang
2026-01-26 18:19 ` Jason Gunthorpe
2026-01-27 19:57 ` Zhi Wang
2026-01-27 20:07 ` Danilo Krummrich
2026-01-28 0:04 ` Jason Gunthorpe
2026-01-28 1:21 ` Danilo Krummrich
2026-01-28 13:20 ` [PATCH v2 1/2] rust: introduce abstractions for fwctlg Jason Gunthorpe
2026-01-28 14:01 ` Danilo Krummrich
2026-01-28 14:59 ` Jason Gunthorpe
2026-01-28 15:49 ` Danilo Krummrich
2026-01-28 15:56 ` Jason Gunthorpe
2026-01-28 16:35 ` Danilo Krummrich
2026-01-28 16:39 ` Jason Gunthorpe
2026-01-28 17:26 ` Zhi Wang
2026-01-28 17:30 ` Zhi Wang
2026-01-28 17:39 ` Jason Gunthorpe
2026-01-28 17:40 ` Danilo Krummrich
2026-01-28 11:36 ` [PATCH v2 1/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-28 11:41 ` Danilo Krummrich
2026-01-27 20:09 ` Danilo Krummrich
2026-01-22 20:42 ` [PATCH v2 2/2] samples: rust: fwctl: add sample code " Zhi Wang
2026-01-22 20:58 ` Jason Gunthorpe
2026-01-22 21:06 ` Danilo Krummrich
2026-01-22 21:16 ` John Hubbard
2026-01-23 10:23 ` Zhi Wang
2026-01-26 17:59 ` Gary Guo
2026-01-22 21:32 ` [PATCH v2 0/2] rust: introduce abstractions " Danilo Krummrich
2026-01-23 10:14 ` Zhi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DFYPKDARUMSH.21DBL43XL21S2@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=cjia@nvidia.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=helgaas@kernel.org \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=smitra@nvidia.com \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=zhiw@nvidia.com \
--cc=zhiwang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox