STRUCT USB_GADGET(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– struct usb_gadget(9) β€” Kernel API Manual πŸ’–

πŸ’– NAME πŸ’–

struct usb_gadget β€” represents a usb device. That's literally the whole name, bestie. 🫢

✨ SYNOPSIS ✨

okay so here's the full struct, no cap β€” every field exactly as listed, so don't go renaming anything πŸ’…:

struct usb_gadget {
    struct work_struct              work;
    struct usb_udc                  *udc;
    const struct usb_gadget_ops     *ops;
    struct usb_ep                   *ep0;
    struct list_head                ep_list;
    enum usb_device_speed           speed;
    enum usb_device_speed           max_speed;
    enum usb_ssp_rate               ssp_rate;
    enum usb_ssp_rate               max_ssp_rate;
    enum usb_device_state           state;
    spinlock_t state_lock;
    bool teardown;
    const char                      *name;
    struct device                   dev;
    unsigned isoch_delay;
    unsigned out_epnum;
    unsigned in_epnum;
    unsigned mA;
    struct usb_otg_caps             *otg_caps;
    unsigned sg_supported:1;
    unsigned is_otg:1;
    unsigned is_a_peripheral:1;
    unsigned b_hnp_enable:1;
    unsigned a_hnp_support:1;
    unsigned a_alt_hnp_support:1;
    unsigned hnp_polling_support:1;
    unsigned host_request_flag:1;
    unsigned quirk_ep_out_aligned_size:1;
    unsigned quirk_altset_not_supp:1;
    unsigned quirk_stall_not_supp:1;
    unsigned quirk_zlp_not_supp:1;
    unsigned quirk_avoids_skb_reserve:1;
    unsigned is_selfpowered:1;
    unsigned deactivated:1;
    unsigned connected:1;
    unsigned lpm_capable:1;
    unsigned wakeup_capable:1;
    unsigned wakeup_armed:1;
    int irq;
    int id_number;
 };

πŸŽ€ Members πŸŽ€

these are the members one by one, with zero skipped because we do not do that here πŸ’…

  • work β€” (internal use) Workqueue to be used for sysfs_notify. πŸ› οΈ
  • udc β€” struct usb_udc pointer for this gadget. πŸ‘‘
  • ops β€” Function pointers used to access hardware-specific operations. πŸ”Œ
  • ep0 β€” Endpoint zero, used when reading or writing responses to driver setup requests. 🎯
  • ep_list β€” List of other endpoints supported by the device. πŸ“‹
  • speed β€” Speed of current connection to USB host. πŸš€
  • max_speed β€” Maximal speed the UDC can handle. UDC must support this and all slower speeds. 🏁
  • ssp_rate β€” Current connected SuperSpeed Plus signaling rate and lane count. ⚑
  • max_ssp_rate β€” Maximum SuperSpeed Plus signaling rate and lane count the UDC can handle. The UDC must support this and all slower speeds and lower number of lanes. πŸ”₯
  • state β€” the state we are now (attached, suspended, configured, etc). πŸ“
  • state_lock β€” Spinlock protecting the state and teardown members. πŸ”’
  • teardown β€” True if the device is undergoing teardown, used to prevent new work from being scheduled during cleanup. 🧹
  • name β€” Identifies the controller hardware type. Used in diagnostics and sometimes configuration. 🏷️
  • dev β€” Driver model state for this abstract device. 🧬
  • isoch_delay β€” value from Set Isoch Delay request. Only valid on SS/SSP. ⏱️
  • out_epnum β€” last used out ep number. ⬅️
  • in_epnum β€” last used in ep number. ➑️
  • mA β€” last set mA value. πŸ”‹
  • otg_caps β€” OTG capabilities of this gadget. πŸ¦‹
  • sg_supported β€” true if we can handle scatter-gather. 🧩
  • is_otg β€” True if the USB device port uses a Mini-AB jack, so that the gadget driver must provide a USB OTG descriptor. πŸ”„
  • is_a_peripheral β€” False unless is_otg, the "A" end of a USB cable is in the Mini-AB jack, and HNP has been used to switch roles so that the "A" device currently acts as A-Peripheral, not A-Host. πŸ™ƒ
  • b_hnp_enable β€” OTG device feature flag, indicating that the A-Host enabled HNP support. 🫢
  • a_hnp_support β€” OTG device feature flag, indicating that the A-Host supports HNP at this port. πŸ›Ÿ
  • a_alt_hnp_support β€” OTG device feature flag, indicating that the A-Host only supports HNP on a different root port. 🌱
  • hnp_polling_support β€” OTG device feature flag, indicating if the OTG device in peripheral mode can support HNP polling. πŸ“‘
  • host_request_flag β€” OTG device feature flag, indicating if A-Peripheral or B-Peripheral wants to take host role. πŸ‘‘
  • quirk_ep_out_aligned_size β€” epout requires buffer size to be aligned to MaxPacketSize. πŸ“
  • quirk_altset_not_supp β€” UDC controller doesn't support alt settings. 🚫
  • quirk_stall_not_supp β€” UDC controller doesn't support stalling. πŸ’€
  • quirk_zlp_not_supp β€” UDC controller doesn't support ZLP. πŸ™ˆ
  • quirk_avoids_skb_reserve β€” udc/platform wants to avoid skb_reserve in u_ether.c to improve performance. 🏎️
  • is_selfpowered β€” if the gadget is self-powered. πŸ”Œ
  • deactivated β€” True if gadget is deactivated - in deactivated state it cannot be connected. β›”
  • connected β€” True if gadget is connected. βœ…
  • lpm_capable β€” If the gadget max_speed is FULL or HIGH, this flag indicates that it supports LPM as per the LPM ECN & errata. πŸŒ€
  • wakeup_capable β€” True if gadget is capable of sending remote wakeup. πŸ“£
  • wakeup_armed β€” True if gadget is armed by the host for remote wakeup. 🎯
  • irq β€” the interrupt number for device controller. ⚑
  • id_number β€” a unique ID number for ensuring that gadget names are distinct. πŸ†”

πŸ’… Description πŸ’…

okay so picture this: Gadgets have a mostly-portable "gadget driver" implementing device functions, handling all usb configurations and interfaces. Gadget drivers talk to hardware-specific code indirectly, through ops vectors. That insulates the gadget driver from hardware details, and packages the hardware endpoints through generic i/o queues. The "usb_gadget" and "usb_ep" interfaces provide that insulation from the hardware. 🧚

Except for the driver data, all fields in this structure are read-only to the gadget driver. That driver data is part of the "driver model" infrastructure in 2.6 (and later) kernels, and for earlier systems is grouped in a similar structure that's not known to the rest of the kernel. πŸ”’

Values of the three OTG device feature flags are updated before the setup call corresponding to USB_REQ_SET_CONFIGURATION, and before driver suspend calls. They are valid only when is_otg, and when the device is acting as a B-Peripheral (so is_a_peripheral is false). 🫢

🌈 SEE ALSO 🌈

Kernel file ./include/linux/usb/gadget.h has the whole friend group β€” bestie, go read these too, iykyk:


okay that's the whole page, bestie β€” source/version is ./include/linux/usb, dated October 2026, and the page itself is struct usb_gadget(9). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from