STRUCT USB_FUNCTION(9)
π NAME π
struct usb_function β bestie, this is the little struct that describes one function of a configuration. That's the whole vibe. It's the building block, the main character of a composite gadget. π
β¨ SYNOPSIS β¨
struct usb_function {
const char *name;
struct usb_gadget_strings **strings;
struct usb_descriptor_header **fs_descriptors;
struct usb_descriptor_header **hs_descriptors;
struct usb_descriptor_header **ss_descriptors;
struct usb_descriptor_header **ssp_descriptors;
struct usb_configuration *config;
struct usb_os_desc_table *os_desc_table;
unsigned os_desc_n;
int (*bind)(struct usb_configuration *, struct usb_function *);
void (*unbind)(struct usb_configuration *, struct usb_function *);
void (*free_func)(struct usb_function *f);
struct module *mod;
int (*set_alt)(struct usb_function *, unsigned interface, unsigned alt);
int (*get_alt)(struct usb_function *, unsigned interface);
void (*disable)(struct usb_function *);
int (*setup)(struct usb_function *, const struct usb_ctrlrequest *);
bool (*req_match)(struct usb_function *, const struct usb_ctrlrequest *, bool config0);
void (*suspend)(struct usb_function *);
void (*resume)(struct usb_function *);
int (*get_status)(struct usb_function *);
int (*func_suspend)(struct usb_function *, u8 suspend_opt);
bool func_suspended;
bool func_wakeup_armed;
};
π§© Members π§©
Grab a snack, we're going through every single one of these. No skipping, that's the rule. π
nameβ for diagnostics, identifies the function. It's the function's name-tag at the party. πstringsβ tables of strings, keyed by identifiers assigned duringbindand by language IDs provided in control requests.fs_descriptorsβ table of full (or low) speed descriptors, using interface and string identifiers assigned duringbind. If this pointer is null, the function will not be available at full speed (or at low speed). So null = left on read, bestie. πhs_descriptorsβ table of high speed descriptors, using interface and string identifiers assigned duringbind. If this pointer is null, the function will not be available at high speed.ss_descriptorsβ table of super speed descriptors, using interface and string identifiers assigned duringbind. If this pointer is null after initiation, the function will not be available at super speed.ssp_descriptorsβ table of super speed plus descriptors, using interface and string identifiers assigned duringbind. If this pointer is null after initiation, the function will not be available at super speed plus.configβ assigned whenusb_add_functionis called; this is the configuration with which this function is associated. It's giving "officially attached". π«Άos_desc_tableβ table of (interface id, os descriptors) pairs. The function can expose more than one interface. If an interface is a member of an IAD, only the first interface of IAD has its entry in the table.os_desc_nβ number of entries inos_desc_table.bindβ before the gadget can register, all of its functions bind to the available resources including string and interface identifiers used in interface or class descriptors; endpoints; I/O buffers; and so on. This is the "claim your stuff" step. πunbindβ reversesbind; called as a side effect of unregistering the driver which added this function.free_funcβ free thestruct usb_function.modβ (internal) points to the module that created this structure. Don't touch, it's internal, iykyk. π€«set_altβ (REQUIRED) reconfigures altsettings; function drivers may initializeusb_ep.driverdata at this time (when it is used). Note that setting an interface to its current altsetting resets interface state, and that all interfaces have a disabled state.get_altβ returns the active altsetting. If this is not provided, then only altsetting zero is supported.disableβ (REQUIRED) indicates the function should be disabled. Reasons include host resetting or reconfiguring the gadget, and disconnection. πsetupβ used for interface-specific control requests.req_matchβ tests if a given class request can be handled by this function.suspendβ notifies functions when the host stops sending USB traffic.resumeβ notifies functions when the host restarts USB traffic. Welcome back, king. πget_statusβ returns function status as a reply toGetStatusrequest when the recipient is Interface.func_suspendβ callback to be called whenSetFeature(FUNCTION_SUSPEND)is reseived (yes, that's the spelling, leave her alone π).func_suspendedβ indicates whether the function is in function suspend state.func_wakeup_armedβ indicates whether the function is armed by the host for wakeup signaling. Armed and ready, literally. βοΈ
π Description π
A single USB function uses one or more interfaces, and should in most cases support operation at both full and high speeds. Each function is associated by usb_add_function with a one configuration; that function causes bind to be called so resources can be allocated as part of setting up a gadget driver. Those resources include endpoints, which should be allocated using usb_ep_autoconfig. π οΈ
To support dual speed operation, a function driver provides descriptors for both high and full speed operation. Except in rare cases that don't involve bulk endpoints, each speed needs different endpoint descriptors. No cap, they're genuinely different. π―
Function drivers choose their own strategies for managing instance data. The simplest strategy just declares it "static', which means the function can only be activated once. If the function needs to be exposed in more than one configuration at a given speed, it needs to support multiple usb_function structures (one for each configuration).
A more complex strategy might encapsulate a usb_function structure inside a driver-specific instance structure to allows multiple activations. An example of multiple activations might be a CDC ACM function that supports two or more distinct instances within the same configuration, providing several independent logical data links to a USB host. Iconic behaviour honestly. π
π SEE ALSO π
- Kernel file
./include/linux/usb/composite.h struct usb_os_desc_ext_prop(9)struct usb_os_desc(9)struct usb_os_desc_table(9)struct usb_configuration(9)struct usb_composite_driver(9)module_usb_composite_driver(9)struct usb_composite_dev(9)
That's the whole page, bestie β go read the friends too. π¦ This little love letter lives in ./include/linux/usb in the Kernel API Manual, dated October 2026, filed under struct usb_function(9). Mwah, study hard, slay, periodt. ππ
π¦ 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