STRUCT USB_DRIVER(9)
π struct usb_driver(9)
okay so this is from the Kernel API Manual bestie β it's the whole entire glow-up guide to struct usb_driver, aka the thing that tells usbcore "hi yes this driver is here for a USB interface." iconic behavior only.
πΈ NAME
struct usb_driver β it literally identifies a USB interface driver to usbcore. that's the whole vibe. no notes.
β¨ SYNOPSIS
struct usb_driver {
const char *name;
int (*probe) (struct usb_interface *intf, const struct usb_device_id *id);
void (*disconnect) (struct usb_interface *intf);
int (*unlocked_ioctl) (struct usb_interface *intf, unsigned int code, void *buf);
int (*suspend) (struct usb_interface *intf, pm_message_t message);
int (*resume) (struct usb_interface *intf);
int (*reset_resume)(struct usb_interface *intf);
int (*pre_reset)(struct usb_interface *intf);
int (*post_reset)(struct usb_interface *intf);
void (*shutdown)(struct usb_interface *intf);
const struct usb_device_id *id_table;
const struct attribute_group **dev_groups;
struct usb_dynids dynids;
struct device_driver driver;
unsigned int no_dynamic_id:1;
unsigned int supports_autosuspend:1;
unsigned int disable_hub_initiated_lpm:1;
unsigned int soft_unbind:1;
};
π Members
let's go through the whole cast, one by one, main character by main character:
nameβ the driver name, and it's gotta be unique among USB drivers. lowkey the rule is: it should normally be the same as the module name. keep them matching bestie π«Άprobeβ called to see if the driver is even willing to manage a particular interface on a device. if it is:probereturns zero and usesusb_set_intfdatato associate driver-specific data with the interface. it may also useusb_set_interfaceto specify the appropriate altsetting. not willing? return-ENODEV. genuine IO errors happened?? return an appropriate negativeerrnovalue.nb: theusb_device_idparameter is only valid during probe β do NOT go keeping it around πdisconnectβ called when the interface is no longer accessible. usually that's because its device has been (or is being) disconnected, or the driver module is being unloaded. it's giving "we're so done here" πunlocked_ioctlβ for drivers that wanna talk to userspace through the"usbfs"filesystem. this lets devices provide ways to expose info to user space regardless of where they do (or don't) show up otherwise in the filesystem. slay for the messy filesystem girlies.suspendβ called when the device is gonna get suspended by the system, either from system sleep context or runtime suspend context. β οΈ the return value will be ignored in system sleep context, so do NOT try to keep using the device if suspend fails there. instead, let theresumeorreset_resumeroutine recover from the failure. like, just let them handle it bestie πresumeβ called when the device is being resumed by the system. welcome back π¦reset_resumeβ called when the suspended device has been reset instead of being resumed. different thing!! don't mix them up!!pre_resetβ called byusb_reset_devicewhen the device is about to be reset. π¨ this routine must not return until the driver has no active URBs for the device, and no more URBs may be submitted until thepost_resetmethod is called. no cap, this one's strict.post_resetβ called byusb_reset_deviceafter the device has been reset. order matters, periodt.shutdownβ called at shut-down time to quiesce the device. nap time π΄id_tableβ USB drivers use the ID table to support hotplugging. export it withMODULE_DEVICE_TABLE(usb,...). and this must be set or your driver'sprobefunction will literally never get called. never ever. πdev_groupsβ attributes attached to the device that will be created once it's bound to the driver.dynidsβ used internally to hold the list of dynamically added device ids for this driver. that's internal business, don't touch πdriverβ the driver-model core driver structure. the structural support beam of the whole fit.no_dynamic_idβ if set to1, the USB core will not allow dynamic ids to be added to this driver, and it does that by preventing the sysfs file from being created.supports_autosuspendβ if set to0, the USB core will not allow autosuspend for interfaces bound to this driver.disable_hub_initiated_lpmβ if set to1, the USB core will not allow hubs to initiate lower power link state transitions when an idle timeout occurs. but device-initiated USB 3.0 link PM will still be allowed. so it's a partial block, not a full block, iykyk.soft_unbindβ if set to1, the USB core will not kill URBs and disable endpoints before calling the driver'sdisconnectmethod. spicy πΆοΈ
π Description
okay the actual rules of the assignment:
USB interface drivers must provide a name, probe and disconnect methods, and an id_table. everything else in the driver fields is optional. those four are the non-negotiables β¨
the id_table is used in hotplugging. it holds a set of descriptors, and specialized data may be associated with each entry. that table is used by both user mode and kernel mode hotplugging support. equal opportunity table.
the probe and disconnect methods are called in a context where they can sleep β but they should avoid abusing the privilege (we all know that girl who naps through everything). most of the work to connect to a device should be done when the device is opened, and undone at the last close. the disconnect code needs to address concurrency issues with respect to open and close methods, as well as forcing all pending I/O requests to complete β by unlinking them as necessary, and blocking until the unlinks complete. so like, actually deal with it, don't just ghost the pending I/O π₯
π SEE ALSO
Kernel file ./include/linux/usb.h and honestly the whole friend group:
struct usb_host_endpoint(9)struct usb_interface(9)usb_set_intfdata(9)struct usb_interface_cache(9)struct usb_host_config(9)struct usb_device(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_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)
and that's the whole page bestie π this one lives at ./include/linux and it's dated October 2026, page struct usb_driver(9) β screenshot it, cite it, live by it. 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