Re: Providing struct device for Linux USB drivers

From: Warner Losh <imp_at_bsdimp.com>
Date: Mon, 01 Jun 2026 22:21:30 UTC
On Mon, Jun 1, 2026, 3:44 PM John F Carr <jfc@mit.edu> wrote:

> I am trying to get the USB part of the rtw89 driver working.
> This driver uses the Linux 2.6.24 USB interface, which is
> newer than LinuxKPI supports.
>
> The rtw89 driver expects struct usb_interface to contain a field
>
>   struct device dev;
>
> A struct device is 256 bytes, much larger than the existing
> 80 byte struct usb_interface.  Is that too much bloat?  The
> number of these structures is not very large.
>
> Alternatively, I could add a pointer instead of a value,
>   struct device *dev;
> The struct device object would be allocated in
> usb_linux_create_usb_device and freed and nulled in
> usb_linux_detach.  With this approach the KPI is not purely
> source compatible.  The driver change is as simple as
> removing an "&".
>
> For PCI, LinuxKPI provides a struct device by interposing a
> struct pci_dev between the FreeBSD structure and the Linux
> driver.  For USB the structure name is expected to be
> "usb_interface", which is already used.
>
> Any thoughts?


I'd embed. I may be inclined to put it at the object at the end. It's small
enough. I'd be tempted to call it _lkapi_usb_interface and #define
usb_interface to that in the usb lkpi header. That will keep it out of the
way. You may need to rename the current one to _fbsd_usb_interface and
define usb_interface to that right away and undef it in th lkpi headers.

Warner