STRUCT USB_DEVICE(9)
β¨ struct usb_device β¨
okay so real talk, this is from the Kernel API Manual (yes, the struct usb_device(9) page, we're doing this π
) and it's literally the kernel's whole personality wrapped around a USB device.
πΈ NAME πΈ
struct usb_device β the kernel's representation of a USB device. it's giving "everything you ever wanted to know about a plugged-in thing" π
π SYNOPSIS π
bestie. look at this. it's a lot, and every single field is important, so here's the whole thing, character for character, no cap:
struct usb_device {
int devnum;
char devpath[16];
u32 route;
enum usb_device_state state;
enum usb_device_speed speed;
unsigned int rx_lanes;
unsigned int tx_lanes;
enum usb_ssp_rate ssp_rate;
struct usb_tt *tt;
int ttport;
unsigned int toggle[2];
struct usb_device *parent;
struct usb_bus *bus;
struct usb_host_endpoint ep0;
struct device dev;
struct usb_device_descriptor descriptor;
struct usb_host_bos *bos;
struct usb_host_config *config;
struct usb_host_config *actconfig;
struct usb_host_endpoint *ep_in[16];
struct usb_host_endpoint *ep_out[16];
char **rawdescriptors;
unsigned short bus_mA;
u8 portnum;
u8 level;
u8 devaddr;
unsigned can_submit:1;
unsigned persist_enabled:1;
unsigned reset_in_progress:1;
unsigned have_langid:1;
unsigned authorized:1;
unsigned authenticated:1;
unsigned lpm_capable:1;
unsigned lpm_devinit_allow:1;
unsigned usb2_hw_lpm_capable:1;
unsigned usb2_hw_lpm_besl_capable:1;
unsigned usb2_hw_lpm_enabled:1;
unsigned usb2_hw_lpm_allowed:1;
unsigned usb3_lpm_u1_enabled:1;
unsigned usb3_lpm_u2_enabled:1;
int string_langid;
char *product;
char *manufacturer;
char *serial;
struct list_head filelist;
int maxchild;
u32 quirks;
atomic_t urbnum;
unsigned long active_duration;
unsigned long connect_time;
unsigned do_remote_wakeup:1;
unsigned reset_resume:1;
unsigned port_is_suspended:1;
unsigned offload_pm_locked:1;
int offload_usage;
spinlock_t offload_lock;
enum usb_link_tunnel_mode tunnel_mode;
struct device_link *usb4_link;
int slot_id;
struct usb2_lpm_parameters l1_params;
struct usb3_lpm_parameters u1_params;
struct usb3_lpm_parameters u2_params;
unsigned lpm_disable_count;
u16 hub_delay;
unsigned use_generic_driver:1;
};
π¦ Members π¦
okay okay, field-by-field, buckle up, this is the main character section π
devnumβ device number; address on a USB bus. their little street address on the bus fr fr πdevpathβ device ID string for use in messages (e.g.,/port/...)routeβ tree topology hex string for use with xHCIstateβ device state: configured, not attached, etc.speedβ device speed: high/full/low (or error)rx_lanesβ number of rx lanes in use, USB 3.2 adds dual-lane supporttx_lanesβ number of tx lanes in use, USB 3.2 adds dual-lane supportssp_rateβ SuperSpeed Plus phy signaling rate and lane countttβ Transaction Translator info; used with low/full speed dev, highspeed hubttportβ device port on that tt hubtoggleβ one bit for each endpoint, with ([0]= IN,[1]= OUT) endpointsparentβ our hub, unless we're the root. everybody's got a parent except the root, iconic π³busβ bus we're part ofep0β endpoint 0 data (default control pipe)devβ generic device interfacedescriptorβ USB device descriptorbosβ USB device BOS descriptor setconfigβ all of the device's configsactconfigβ the active configurationep_inβ array of IN endpointsep_outβ array of OUT endpointsrawdescriptorsβ raw descriptors for each configbus_mAβ Current available from the busportnumβ parent port number (origin 1)levelβ number of USB hub ancestorsdevaddrβ device address, XHCI: assigned by HW, others: same asdevnumcan_submitβ URBs may be submittedpersist_enabledβUSB_PERSISTenabled for this devicereset_in_progressβ the device is being resethave_langidβ whetherstring_langidis validauthorizedβ policy has said we can use it; (user space) policy determines if we authorize this device to be used or not. By default, wired USB devices are authorized. WUSB devices are not, until we authorize them from user space. FIXME -- complete doc π (the kernel literally left a FIXME here, we respect the honesty)authenticatedβ Crypto authentication passedlpm_capableβ device supports LPMlpm_devinit_allowβ Allow USB3 device initiated LPM, exit latency is in rangeusb2_hw_lpm_capableβ device can perform USB2 hardware LPMusb2_hw_lpm_besl_capableβ device can perform USB2 hardware BESL LPMusb2_hw_lpm_enabledβ USB2 hardware LPM is enabledusb2_hw_lpm_allowedβ Userspace allows USB 2.0 LPM to be enabledusb3_lpm_u1_enabledβ USB3 hardware U1 LPM enabledusb3_lpm_u2_enabledβ USB3 hardware U2 LPM enabledstring_langidβ language ID for stringsproductβ iProduct string, if present (static)manufacturerβ iManufacturer string, if present (static)serialβ iSerialNumber string, if present (static)filelistβ usbfs files that are open to this devicemaxchildβ number of ports if hubquirksβ quirks of the whole deviceurbnumβ number of URBs submitted for the whole deviceactive_durationβ total time device is not suspendedconnect_timeβ time device was first connecteddo_remote_wakeupβ remote wakeup should be enabledreset_resumeβ needs reset instead of resumeport_is_suspendedβ the upstream port is suspended (L2 or U3)offload_pm_lockedβ preventsoffload_usagechanges during PM transitions.offload_usageβ number of offload activities happening on this usb device.offload_lockβ protectsoffload_usageandoffload_pm_lockedtunnel_modeβ Connection native or tunneled over USB4usb4_linkβ device link to the USB4 host interfaceslot_idβ Slot ID assigned by xHCIl1_paramsβ best effor service latency for USB2 L1 LPM state, and L1 timeout. (yes "effor" β that's literally what the doc says, we don't fix typos in other people's homework π)u1_paramsβ exit latencies for USB3 U1 LPM state, and hub-initiated timeout.u2_paramsβ exit latencies for USB3 U2 LPM state, and hub-initiated timeout.lpm_disable_countβ Ref count used byusb_disable_lpmandusb_enable_lpmto keep track of the number of functions that require USB 3.0 Link Power Management to be disabled for thisusb_device. This count should only be manipulated by those functions, with thebandwidth_mutexis held. π (and yeah, that sentence grammar is exactly the original's, we are merely the messenger)hub_delayβ cached value consisting of:parent->hub_delay + wHubDelay + tTPTransmissionDelay (40ns)Will be used aswValuefor SetIsochDelay requests.use_generic_driverβ ask driver core to reprobe using the generic driver.
π Notes π
π¨ heads up bestie: Usbcore drivers should not setusbdev->statedirectly. Instead useusb_set_device_state. that's the whole rule, don't be messy, use the setter π
β SEE ALSO β
- Kernel file
./include/linux/usb.h struct usb_host_endpoint(9)struct usb_interface(9)usb_set_intfdata(9)struct usb_interface_cache(9)struct usb_host_config(9)usb_hub_for_each_child(9)usb_interface_claimed(9)usb_make_path(9)USB_DEVICE(9)USB_DEVICE_VER(9)USB_DEVICE_INTERFACE_CLASS(9)USB_DEVICE_INTERFACE_PROTOCOL(9)USB_DEVICE_INTERFACE_NUMBER(9)USB_DEVICE_INFO(9)USB_INTERFACE_INFO(9)USB_DEVICE_AND_INTERFACE_INFO(9)USB_VENDOR_AND_INTERFACE_INFO(9)struct usb_driver(9)struct usb_device_driver(9)struct usb_class_driver(9)module_usb_driver(9)struct urb(9)usb_fill_control_urb(9)usb_fill_bulk_urb(9)usb_fill_int_urb(9)usb_urb_dir_in(9)usb_urb_dir_out(9)struct usb_sg_request(9)
okay that's the whole page, you ate that π«Ά this little beauty lives in ./include/linux, dated October 2026, and it's part of the Kernel API Manual β go forth and read structs responsibly, 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