STRUCT USB_GADGET(9)
π 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 forsysfs_notify. π οΈudcβstruct usb_udcpointer 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 thestateandteardownmembers. π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 unlessis_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 avoidskb_reserveinu_ether.cto 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 gadgetmax_speedis 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:
struct usb_request(9)struct usb_ep_caps(9)struct usb_ep(9)free_usb_request(9)usb_ep_align(9)usb_ep_align_maybe(9)gadget_is_altset_supported(9)gadget_is_stall_supported(9)gadget_is_zlp_supported(9)gadget_avoids_skb_reserve(9)gadget_is_dualspeed(9)gadget_is_superspeed(9)gadget_is_superspeed_plus(9)gadget_is_otg(9)struct usb_gadget_driver(9)usb_gadget_register_driver_owner(9)usb_gadget_unregister_driver(9)struct usb_string(9)struct usb_gadget_strings(9)usb_free_descriptors(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms