Re: [PATCH v2 1/2] rust: introduce abstractions for fwctlg

Jason Gunthorpe
2026-01-28T16:39:34Z

On Wed, Jan 28, 2026 at 05:35:04PM +0100, Danilo Krummrich wrote:
> On Wed Jan 28, 2026 at 4:56 PM CET, Jason Gunthorpe wrote:
> > On Wed, Jan 28, 2026 at 04:49:07PM +0100, Danilo Krummrich wrote:
> >
> >> // Initialize the `data` initializer within the memory pointed
> >> // to by `raw_data`.
> >> unsafe { data.__pinned_init(raw_data) }.inspect_err(|_| {
> >
> >> So, essentially the driver passes an initializer of its private data and we
> >> "write" this initializer into the extra memory allocated with
> >> _fwctl_alloc_device().
> >
> > This all seems like the right way to do it!
> >
> > My only remark it that it still doesn't give an opportunity to call a
> > function between init and register.
>
> You would, from a driver side it would look like this:
>
> #[pin_data]
> struct MyDriver {
> #[pin]
> _reg: Devres<fwctl::Registration>,
> fwctl: ARef<fwctl::Device>,
> }
>
> #[pin_data]
> struct FwctlData {
> #[pin]
> foo: Mutex<Foo>,
> ...,
> }
>
> impl pci::Driver for MyDriver {
> fn probe(
> pdev: &pci::Device<Core>,
> _info: &Self::IdInfo,
> ) -> impl PinInit<Self, Error> {
> let fwctl = fwctl::Device::new(
> pdev.as_ref(),
> try_pin_init!(FwctlData {
> foo <- mutex_new!(Foo::new()),
> ...,
> }),
> )?;
>
> // Let's do something with the `fwctl::Device` before we
> // register it.
> fwctl.do_stuff();
>
> try_pin_init!(Self {
> // We could omit this and instead provide
> // `fwctl::Registration::register()`, which does only return
> // a `Result` and keeps the `fwct::Device` registered until
> // driver unbind.
> _reg <- fwctl::Registration::new(pdev.as_ref(), fwctl);
> fwctl,
> })
> }
> }

Okay it is fine by me, Zi did you get all this?

Jason