1STRUCT USB_FUNCTION(9) Kernel Mode Gadget API STRUCT USB_FUNCTION(9)
2
3
4
6 struct_usb_function - describes one function of a configuration
7
9 struct usb_function {
10 const char * name;
11 struct usb_gadget_strings ** strings;
12 struct usb_descriptor_header ** fs_descriptors;
13 struct usb_descriptor_header ** hs_descriptors;
14 struct usb_descriptor_header ** ss_descriptors;
15 struct usb_configuration * config;
16 int (* bind) (struct usb_configuration *,struct usb_function *);
17 void (* unbind) (struct usb_configuration *,struct usb_function *);
18 void (* free_func) (struct usb_function *f);
19 struct module * mod;
20 int (* set_alt) (struct usb_function *,unsigned interface, unsigned alt);
21 int (* get_alt) (struct usb_function *,unsigned interface);
22 void (* disable) (struct usb_function *);
23 int (* setup) (struct usb_function *,const struct usb_ctrlrequest *);
24 void (* suspend) (struct usb_function *);
25 void (* resume) (struct usb_function *);
26 int (* get_status) (struct usb_function *);
27 int (* func_suspend) (struct usb_function *,u8 suspend_opt);
28 };
29
31 name
32 For diagnostics, identifies the function.
33
34 strings
35 tables of strings, keyed by identifiers assigned during bind and by
36 language IDs provided in control requests
37
38 fs_descriptors
39 Table of full (or low) speed descriptors, using interface and
40 string identifiers assigned during bind(). If this pointer is null,
41 the function will not be available at full speed (or at low speed).
42
43 hs_descriptors
44 Table of high speed descriptors, using interface and string
45 identifiers assigned during bind(). If this pointer is null, the
46 function will not be available at high speed.
47
48 ss_descriptors
49 Table of super speed descriptors, using interface and string
50 identifiers assigned during bind(). If this pointer is null after
51 initiation, the function will not be available at super speed.
52
53 config
54 assigned when usb_add_function() is called; this is the
55 configuration with which this function is associated.
56
57 bind
58 Before the gadget can register, all of its functions bind to the
59 available resources including string and interface identifiers used
60 in interface or class descriptors; endpoints; I/O buffers; and so
61 on.
62
63 unbind
64 Reverses bind; called as a side effect of unregistering the driver
65 which added this function.
66
67 free_func
68 free the struct usb_function.
69
70 mod
71 (internal) points to the module that created this structure.
72
73 set_alt
74 (REQUIRED) Reconfigures altsettings; function drivers may
75 initialize usb_ep.driver data at this time (when it is used). Note
76 that setting an interface to its current altsetting resets
77 interface state, and that all interfaces have a disabled state.
78
79 get_alt
80 Returns the active altsetting. If this is not provided, then only
81 altsetting zero is supported.
82
83 disable
84 (REQUIRED) Indicates the function should be disabled. Reasons
85 include host resetting or reconfiguring the gadget, and
86 disconnection.
87
88 setup
89 Used for interface-specific control requests.
90
91 suspend
92 Notifies functions when the host stops sending USB traffic.
93
94 resume
95 Notifies functions when the host restarts USB traffic.
96
97 get_status
98 Returns function status as a reply to GetStatus request when the
99 recepient is Interface.
100
101 func_suspend
102 callback to be called when SetFeature(FUNCTION_SUSPEND) is reseived
103
105 A single USB function uses one or more interfaces, and should in most
106 cases support operation at both full and high speeds. Each function is
107 associated by usb_add_function() with a one configuration; that
108 function causes bind() to be called so resources can be allocated as
109 part of setting up a gadget driver. Those resources include endpoints,
110 which should be allocated using usb_ep_autoconfig().
111
112 To support dual speed operation, a function driver provides descriptors
113 for both high and full speed operation. Except in rare cases that don't
114 involve bulk endpoints, each speed needs different endpoint
115 descriptors.
116
117 Function drivers choose their own strategies for managing instance
118 data. The simplest strategy just declares it "static', which means the
119 function can only be activated once. If the function needs to be
120 exposed in more than one configuration at a given speed, it needs to
121 support multiple usb_function structures (one for each configuration).
122
123 A more complex strategy might encapsulate a usb_function structure
124 inside a driver-specific instance structure to allows multiple
125 activations. An example of multiple activations might be a CDC ACM
126 function that supports two or more distinct instances within the same
127 configuration, providing several independent logical data links to a
128 USB host.
129
131 David Brownell <dbrownell@users.sourceforge.net>
132 Author.
133
135Kernel Hackers Manual 3.10 June 2019 STRUCT USB_FUNCTION(9)