usb.h revision 1.112 1 1.112 skrll /* $NetBSD: usb.h,v 1.112 2015/03/26 08:08:27 skrll Exp $ */
2 1.39 augustss /* $FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $ */
3 1.1 augustss
4 1.1 augustss /*
5 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 1.1 augustss * All rights reserved.
7 1.1 augustss *
8 1.4 augustss * This code is derived from software contributed to The NetBSD Foundation
9 1.48 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
10 1.4 augustss * Carlstedt Research & Technology.
11 1.1 augustss *
12 1.1 augustss * Redistribution and use in source and binary forms, with or without
13 1.1 augustss * modification, are permitted provided that the following conditions
14 1.1 augustss * are met:
15 1.1 augustss * 1. Redistributions of source code must retain the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer.
17 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 augustss * notice, this list of conditions and the following disclaimer in the
19 1.1 augustss * documentation and/or other materials provided with the distribution.
20 1.1 augustss *
21 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
32 1.1 augustss */
33 1.1 augustss
34 1.1 augustss
35 1.1 augustss #ifndef _USB_H_
36 1.1 augustss #define _USB_H_
37 1.1 augustss
38 1.1 augustss #include <sys/types.h>
39 1.37 augustss #include <sys/time.h>
40 1.36 augustss
41 1.1 augustss #include <sys/ioctl.h>
42 1.8 augustss
43 1.8 augustss #if defined(_KERNEL)
44 1.83 dyoung #include <sys/mallocvar.h>
45 1.83 dyoung
46 1.83 dyoung MALLOC_DECLARE(M_USB);
47 1.83 dyoung MALLOC_DECLARE(M_USBDEV);
48 1.83 dyoung MALLOC_DECLARE(M_USBHC);
49 1.83 dyoung
50 1.83 dyoung #include <sys/device.h>
51 1.83 dyoung
52 1.83 dyoung #endif
53 1.83 dyoung
54 1.83 dyoung #ifdef USB_DEBUG
55 1.83 dyoung #define Static
56 1.83 dyoung #else
57 1.83 dyoung #define Static static
58 1.83 dyoung #endif
59 1.83 dyoung
60 1.63 augustss #define USB_STACK_VERSION 2
61 1.1 augustss
62 1.1 augustss #define USB_MAX_DEVICES 128
63 1.101 skrll #define USB_MIN_DEVICES 2 /* unused + root HUB */
64 1.1 augustss #define USB_START_ADDR 0
65 1.1 augustss
66 1.1 augustss #define USB_CONTROL_ENDPOINT 0
67 1.1 augustss #define USB_MAX_ENDPOINTS 16
68 1.1 augustss
69 1.10 augustss #define USB_FRAMES_PER_SECOND 1000
70 1.86 jakllsch #define USB_UFRAMES_PER_FRAME 8
71 1.10 augustss
72 1.1 augustss /*
73 1.1 augustss * The USB records contain some unaligned little-endian word
74 1.1 augustss * components. The U[SG]ETW macros take care of both the alignment
75 1.50 augustss * and endian problem and should always be used to access non-byte
76 1.1 augustss * values.
77 1.1 augustss */
78 1.1 augustss typedef u_int8_t uByte;
79 1.1 augustss typedef u_int8_t uWord[2];
80 1.50 augustss typedef u_int8_t uDWord[4];
81 1.50 augustss
82 1.50 augustss #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
83 1.50 augustss
84 1.50 augustss #if 1
85 1.1 augustss #define UGETW(w) ((w)[0] | ((w)[1] << 8))
86 1.1 augustss #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
87 1.16 augustss #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
88 1.16 augustss #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
89 1.16 augustss (w)[1] = (u_int8_t)((v) >> 8), \
90 1.16 augustss (w)[2] = (u_int8_t)((v) >> 16), \
91 1.16 augustss (w)[3] = (u_int8_t)((v) >> 24))
92 1.50 augustss #else
93 1.66 augustss /*
94 1.96 msaitoh * On little-endian machines that can handle unaligned accesses
95 1.1 augustss * (e.g. i386) these macros can be replaced by the following.
96 1.1 augustss */
97 1.1 augustss #define UGETW(w) (*(u_int16_t *)(w))
98 1.1 augustss #define USETW(w,v) (*(u_int16_t *)(w) = (v))
99 1.50 augustss #define UGETDW(w) (*(u_int32_t *)(w))
100 1.50 augustss #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
101 1.1 augustss #endif
102 1.1 augustss
103 1.78 perry #define UPACKED __packed
104 1.49 augustss
105 1.1 augustss typedef struct {
106 1.1 augustss uByte bmRequestType;
107 1.1 augustss uByte bRequest;
108 1.1 augustss uWord wValue;
109 1.1 augustss uWord wIndex;
110 1.1 augustss uWord wLength;
111 1.49 augustss } UPACKED usb_device_request_t;
112 1.1 augustss
113 1.101 skrll #define UT_GET_DIR(a) ((a) & 0x80)
114 1.1 augustss #define UT_WRITE 0x00
115 1.1 augustss #define UT_READ 0x80
116 1.101 skrll
117 1.101 skrll #define UT_GET_TYPE(a) ((a) & 0x60)
118 1.1 augustss #define UT_STANDARD 0x00
119 1.1 augustss #define UT_CLASS 0x20
120 1.1 augustss #define UT_VENDOR 0x40
121 1.101 skrll
122 1.101 skrll #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
123 1.1 augustss #define UT_DEVICE 0x00
124 1.1 augustss #define UT_INTERFACE 0x01
125 1.1 augustss #define UT_ENDPOINT 0x02
126 1.1 augustss #define UT_OTHER 0x03
127 1.1 augustss
128 1.1 augustss #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
129 1.1 augustss #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
130 1.1 augustss #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
131 1.1 augustss #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
132 1.1 augustss #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
133 1.1 augustss #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
134 1.1 augustss #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
135 1.1 augustss #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
136 1.1 augustss #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
137 1.30 augustss #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
138 1.1 augustss #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
139 1.1 augustss #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
140 1.1 augustss #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
141 1.30 augustss #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
142 1.13 augustss #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
143 1.13 augustss #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
144 1.13 augustss #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
145 1.30 augustss #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
146 1.13 augustss #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
147 1.13 augustss #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
148 1.13 augustss #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
149 1.30 augustss #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
150 1.1 augustss
151 1.101 skrll /* Standard Requests Codes from the USB 2.0 spec, table 9-4 */
152 1.1 augustss #define UR_GET_STATUS 0x00
153 1.1 augustss #define UR_CLEAR_FEATURE 0x01
154 1.1 augustss #define UR_SET_FEATURE 0x03
155 1.1 augustss #define UR_SET_ADDRESS 0x05
156 1.1 augustss #define UR_GET_DESCRIPTOR 0x06
157 1.36 augustss #define UDESC_DEVICE 0x01
158 1.36 augustss #define UDESC_CONFIG 0x02
159 1.36 augustss #define UDESC_STRING 0x03
160 1.36 augustss #define UDESC_INTERFACE 0x04
161 1.36 augustss #define UDESC_ENDPOINT 0x05
162 1.53 augustss #define UDESC_DEVICE_QUALIFIER 0x06
163 1.53 augustss #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
164 1.53 augustss #define UDESC_INTERFACE_POWER 0x08
165 1.60 augustss #define UDESC_OTG 0x09
166 1.85 jakllsch #define UDESC_DEBUG 0x0a
167 1.89 jmcneill #define UDESC_INTERFACE_ASSOC 0x0b
168 1.111 skrll #define UDESC_BOS 0x0f
169 1.111 skrll #define UDESC_DEVICE_CAPABILITY 0x10
170 1.36 augustss #define UDESC_CS_DEVICE 0x21 /* class specific */
171 1.36 augustss #define UDESC_CS_CONFIG 0x22
172 1.36 augustss #define UDESC_CS_STRING 0x23
173 1.36 augustss #define UDESC_CS_INTERFACE 0x24
174 1.36 augustss #define UDESC_CS_ENDPOINT 0x25
175 1.36 augustss #define UDESC_HUB 0x29
176 1.111 skrll #define UDESC_SS_HUB 0x2a /* super speed */
177 1.111 skrll #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */
178 1.111 skrll #define UDESC_ENDPOINT_ISOCH_SSP_COMP 0x31
179 1.1 augustss #define UR_SET_DESCRIPTOR 0x07
180 1.1 augustss #define UR_GET_CONFIG 0x08
181 1.1 augustss #define UR_SET_CONFIG 0x09
182 1.1 augustss #define UR_GET_INTERFACE 0x0a
183 1.1 augustss #define UR_SET_INTERFACE 0x0b
184 1.1 augustss #define UR_SYNCH_FRAME 0x0c
185 1.111 skrll #define UR_SET_ENCRYPTION 0x0d
186 1.111 skrll #define UR_GET_ENCRYPTION 0x0e
187 1.111 skrll #define UR_SET_HANDSHAKE 0x0f
188 1.111 skrll #define UR_GET_HANDSHAKE 0x10
189 1.111 skrll #define UR_SET_CONNECTION 0x11
190 1.111 skrll #define UR_SET_SECURITY_DATA 0x12
191 1.111 skrll #define UR_GET_SECURITY_DATA 0x13
192 1.111 skrll #define UR_SET_WUSB_DATA 0x14
193 1.111 skrll #define UR_LOOPBACK_DATA_WRITE 0x15
194 1.111 skrll #define UR_LOOPBACK_DATA_READ 0x16
195 1.111 skrll #define UR_SET_INTERFACE_DS 0x17
196 1.111 skrll #define UR_SET_SEL 0x30
197 1.111 skrll #define UR_SET_ISOCH_DELAY 0x31
198 1.1 augustss
199 1.101 skrll /*
200 1.101 skrll * Feature selectors. USB 2.0 spec, table 9-6 and OTG and EH suppliment,
201 1.101 skrll * table 6-2
202 1.101 skrll */
203 1.8 augustss #define UF_ENDPOINT_HALT 0
204 1.111 skrll #define UF_INTERFACE_FUNCTION_SUSPEND 0
205 1.1 augustss #define UF_DEVICE_REMOTE_WAKEUP 1
206 1.57 augustss #define UF_TEST_MODE 2
207 1.101 skrll #define UF_DEVICE_B_HNP_ENABLE 3
208 1.101 skrll #define UF_DEVICE_A_HNP_SUPPORT 4
209 1.101 skrll #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
210 1.111 skrll #define UF_DEVICE_WUSB_DEVICE 6
211 1.111 skrll #define UF_U1_ENABLE 0x30
212 1.111 skrll #define UF_U2_ENABLE 0x31
213 1.111 skrll #define UF_LTM_ENABLE 0x32
214 1.1 augustss
215 1.1 augustss #define USB_MAX_IPACKET 8 /* maximum size of the initial packet */
216 1.1 augustss
217 1.56 augustss #define USB_2_MAX_CTRL_PACKET 64
218 1.56 augustss #define USB_2_MAX_BULK_PACKET 512
219 1.56 augustss
220 1.105 jakllsch #define USB_3_MAX_CTRL_PACKET 512
221 1.105 jakllsch
222 1.1 augustss typedef struct {
223 1.1 augustss uByte bLength;
224 1.1 augustss uByte bDescriptorType;
225 1.49 augustss } UPACKED usb_descriptor_t;
226 1.1 augustss
227 1.1 augustss typedef struct {
228 1.1 augustss uByte bLength;
229 1.1 augustss uByte bDescriptorType;
230 1.1 augustss uWord bcdUSB;
231 1.53 augustss #define UD_USB_2_0 0x0200
232 1.111 skrll #define UD_USB_3_0 0x0300
233 1.53 augustss #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
234 1.111 skrll #define UD_IS_USB3(d) (UGETW((d)->bcdUSB) >= UD_USB_3_0)
235 1.1 augustss uByte bDeviceClass;
236 1.1 augustss uByte bDeviceSubClass;
237 1.1 augustss uByte bDeviceProtocol;
238 1.1 augustss uByte bMaxPacketSize;
239 1.1 augustss /* The fields below are not part of the initial descriptor. */
240 1.1 augustss uWord idVendor;
241 1.1 augustss uWord idProduct;
242 1.1 augustss uWord bcdDevice;
243 1.1 augustss uByte iManufacturer;
244 1.1 augustss uByte iProduct;
245 1.1 augustss uByte iSerialNumber;
246 1.1 augustss uByte bNumConfigurations;
247 1.49 augustss } UPACKED usb_device_descriptor_t;
248 1.1 augustss #define USB_DEVICE_DESCRIPTOR_SIZE 18
249 1.1 augustss
250 1.1 augustss typedef struct {
251 1.1 augustss uByte bLength;
252 1.1 augustss uByte bDescriptorType;
253 1.1 augustss uWord wTotalLength;
254 1.1 augustss uByte bNumInterface;
255 1.1 augustss uByte bConfigurationValue;
256 1.1 augustss uByte iConfiguration;
257 1.1 augustss uByte bmAttributes;
258 1.76 drochner #define UC_ATTR_MBO 0x80
259 1.1 augustss #define UC_SELF_POWERED 0x40
260 1.1 augustss #define UC_REMOTE_WAKEUP 0x20
261 1.1 augustss uByte bMaxPower; /* max current in 2 mA units */
262 1.1 augustss #define UC_POWER_FACTOR 2
263 1.112 skrll #define UC_POWER_FACTOR_SS 8
264 1.49 augustss } UPACKED usb_config_descriptor_t;
265 1.1 augustss #define USB_CONFIG_DESCRIPTOR_SIZE 9
266 1.1 augustss
267 1.1 augustss typedef struct {
268 1.1 augustss uByte bLength;
269 1.1 augustss uByte bDescriptorType;
270 1.1 augustss uByte bInterfaceNumber;
271 1.1 augustss uByte bAlternateSetting;
272 1.1 augustss uByte bNumEndpoints;
273 1.1 augustss uByte bInterfaceClass;
274 1.1 augustss uByte bInterfaceSubClass;
275 1.1 augustss uByte bInterfaceProtocol;
276 1.1 augustss uByte iInterface;
277 1.49 augustss } UPACKED usb_interface_descriptor_t;
278 1.1 augustss #define USB_INTERFACE_DESCRIPTOR_SIZE 9
279 1.1 augustss
280 1.1 augustss typedef struct {
281 1.1 augustss uByte bLength;
282 1.1 augustss uByte bDescriptorType;
283 1.89 jmcneill uByte bFirstInterface;
284 1.89 jmcneill uByte bInterfaceCount;
285 1.89 jmcneill uByte bFunctionClass;
286 1.89 jmcneill uByte bFunctionSubClass;
287 1.89 jmcneill uByte bFunctionProtocol;
288 1.90 wiz uByte iFunction;
289 1.89 jmcneill } UPACKED usb_interface_assoc_descriptor_t;
290 1.89 jmcneill #define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
291 1.89 jmcneill
292 1.89 jmcneill typedef struct {
293 1.89 jmcneill uByte bLength;
294 1.89 jmcneill uByte bDescriptorType;
295 1.1 augustss uByte bEndpointAddress;
296 1.31 augustss #define UE_GET_DIR(a) ((a) & 0x80)
297 1.36 augustss #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
298 1.31 augustss #define UE_DIR_IN 0x80
299 1.31 augustss #define UE_DIR_OUT 0x00
300 1.1 augustss #define UE_ADDR 0x0f
301 1.6 augustss #define UE_GET_ADDR(a) ((a) & UE_ADDR)
302 1.1 augustss uByte bmAttributes;
303 1.1 augustss #define UE_XFERTYPE 0x03
304 1.10 augustss #define UE_CONTROL 0x00
305 1.10 augustss #define UE_ISOCHRONOUS 0x01
306 1.10 augustss #define UE_BULK 0x02
307 1.10 augustss #define UE_INTERRUPT 0x03
308 1.36 augustss #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
309 1.10 augustss #define UE_ISO_TYPE 0x0c
310 1.10 augustss #define UE_ISO_ASYNC 0x04
311 1.10 augustss #define UE_ISO_ADAPT 0x08
312 1.10 augustss #define UE_ISO_SYNC 0x0c
313 1.38 augustss #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
314 1.1 augustss uWord wMaxPacketSize;
315 1.82 jmcneill #define UE_GET_TRANS(a) (((a) >> 11) & 0x3)
316 1.82 jmcneill #define UE_GET_SIZE(a) ((a) & 0x7ff)
317 1.1 augustss uByte bInterval;
318 1.49 augustss } UPACKED usb_endpoint_descriptor_t;
319 1.1 augustss #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
320 1.1 augustss
321 1.1 augustss typedef struct {
322 1.1 augustss uByte bLength;
323 1.1 augustss uByte bDescriptorType;
324 1.111 skrll uByte bMaxBurst;
325 1.111 skrll uByte bmAttributes;
326 1.111 skrll #define UE_SSC_MAXSTREAMS(x) __SHIFTOUT(x, __BITS(4,0)) /* bulk */
327 1.111 skrll #define UE_SSC_MULT(x) __SHIFTOUT(x, __BITS(1,0)) /* isoch */
328 1.111 skrll #define UE_SSC_SSP_ISO(x) __SHIFTOUT(x, __BIT(7)) /* isoch */
329 1.111 skrll /* The fields below are only valid for periodic endpoints */
330 1.111 skrll uWord wBytesPerInterval;
331 1.111 skrll } UPACKED usb_endpoint_ss_comp_descriptor_t;
332 1.111 skrll #define USB_ENDPOINT_SS_COMP_DESCRIPTOR_SIZE 6
333 1.111 skrll
334 1.112 skrll /* USB 3.0 9.6.2, Table 9-12 */
335 1.111 skrll typedef struct {
336 1.111 skrll uByte bLength;
337 1.111 skrll uByte bDescriptorType;
338 1.111 skrll uWord wTotalLength;
339 1.111 skrll uByte bNumDeviceCaps;
340 1.111 skrll } UPACKED usb_bos_descriptor_t;
341 1.111 skrll #define USB_BOS_DESCRIPTOR_SIZE 5
342 1.111 skrll
343 1.112 skrll /* common members of device capability descriptors */
344 1.111 skrll typedef struct {
345 1.111 skrll uByte bLength;
346 1.111 skrll uByte bDescriptorType;
347 1.111 skrll uByte bDevCapabilityType;
348 1.112 skrll /* Table 9-14 */
349 1.111 skrll #define USB_DEVCAP_RESERVED 0x00
350 1.111 skrll #define USB_DEVCAP_WUSB 0x01
351 1.111 skrll #define USB_DEVCAP_USB2EXT 0x02
352 1.111 skrll #define USB_DEVCAP_SUPER_SPEED 0x03
353 1.111 skrll #define USB_DEVCAP_CONTAINER_ID 0x04
354 1.111 skrll #define USB_DEVCAP_PLATFORM 0x05
355 1.111 skrll #define USB_DEVCAP_POWER_DELIVERY_CAPABILITY 0x06
356 1.111 skrll #define USB_DEVCAP_BATTERY_INFO_CAPABILITY 0x07
357 1.111 skrll #define USB_DEVCAP_PD_CONSUMER_PORT_CAPABILITY 0x08
358 1.111 skrll #define USB_DEVCAP_PD_PROVIDER_PORT_CAPABILITY 0x09
359 1.111 skrll #define USB_DEVCAP_SUPERSPEED_PLUS 0x0a
360 1.111 skrll #define USB_DEVCAP_PRECISION_TIME_MEASUREMENT 0x0b
361 1.111 skrll #define USB_DEVCAP_WUSB_EXT 0x0c
362 1.111 skrll /* data ... */
363 1.111 skrll } UPACKED usb_device_capability_descriptor_t;
364 1.112 skrll #define USB_DEVICE_CAPABILITY_DESCRIPTOR_SIZE 3 /* at least */
365 1.111 skrll
366 1.112 skrll /* 9.6.2.1 */
367 1.111 skrll typedef struct {
368 1.111 skrll uByte bLength;
369 1.111 skrll uByte bDescriptorType;
370 1.111 skrll uByte bDevCapabilityType;
371 1.111 skrll uDWord bmAttributes;
372 1.111 skrll #define USB_DEVCAP_USB2EXT_LPM __BIT(1)
373 1.112 skrll } UPACKED usb_devcap_usb2ext_descriptor_t;
374 1.111 skrll #define USB_DEVCAP_USB2EXT_DESCRIPTOR_SIZE 7
375 1.111 skrll
376 1.112 skrll /* 9.6.2.2 */
377 1.111 skrll typedef struct {
378 1.111 skrll uByte bLength;
379 1.111 skrll uByte bDescriptorType;
380 1.111 skrll uByte bDevCapabilityType;
381 1.111 skrll uByte bmAttributes;
382 1.111 skrll #define USB_DEVCAP_SS_LTM __BIT(1)
383 1.111 skrll uWord wSpeedsSupported;
384 1.112 skrll #define USB_DEVCAP_SS_SPEED_LS __BIT(0)
385 1.111 skrll #define USB_DEVCAP_SS_SPEED_FS __BIT(1)
386 1.111 skrll #define USB_DEVCAP_SS_SPEED_HS __BIT(2)
387 1.112 skrll #define USB_DEVCAP_SS_SPEED_SS __BIT(3)
388 1.111 skrll uByte bFunctionalitySupport;
389 1.111 skrll uByte bU1DevExitLat;
390 1.111 skrll uWord wU2DevExitLat;
391 1.111 skrll } UPACKED usb_devcap_ss_descriptor_t;
392 1.111 skrll #define USB_DEVCAP_SS_DESCRIPTOR_SIZE 10
393 1.111 skrll
394 1.112 skrll /* 9.6.2.4 */
395 1.111 skrll typedef struct {
396 1.111 skrll uByte bLength;
397 1.111 skrll uByte bDescriptorType;
398 1.111 skrll uByte bDevCapabilityType;
399 1.111 skrll uByte bReserved;
400 1.111 skrll uByte ContainerID[16];
401 1.111 skrll } UPACKED usb_devcap_container_id_descriptor_t;
402 1.111 skrll #define USB_DEVCAP_CONTAINER_ID_DESCRIPTOR_SIZE 20
403 1.111 skrll
404 1.111 skrll typedef struct {
405 1.111 skrll uByte bLength;
406 1.111 skrll uByte bDescriptorType;
407 1.111 skrll uByte bDevCapabilityType;
408 1.111 skrll uByte bReserved;
409 1.111 skrll uByte PlatformCapabilityUUID[16];
410 1.111 skrll uByte CapabilityData[0];
411 1.111 skrll } UPACKED usb_devcap_platform_descriptor_t;
412 1.111 skrll #define USB_DEVCAP_PLATFORM_DESCRIPTOR_SIZE 20
413 1.111 skrll
414 1.111 skrll typedef struct {
415 1.111 skrll uByte bLength;
416 1.111 skrll uByte bDescriptorType;
417 1.111 skrll uByte bDevCapabilityType;
418 1.111 skrll uByte bReserved;
419 1.111 skrll uDWord bmAttributes;
420 1.111 skrll uWord wFunctionalitySupport;
421 1.111 skrll uWord wReserved;
422 1.111 skrll uDWord bmSublinkSpeedAttr[0];
423 1.111 skrll } UPACKED usb_devcap_ssp_descriptor_t;
424 1.111 skrll #define USB_DEVCAP_SSP_DESCRIPTOR_SIZE 12 /* variable length */
425 1.111 skrll
426 1.111 skrll typedef struct {
427 1.111 skrll uByte bLength;
428 1.111 skrll uByte bDescriptorType;
429 1.77 drochner uWord bString[126];
430 1.49 augustss } UPACKED usb_string_descriptor_t;
431 1.1 augustss #define USB_MAX_STRING_LEN 128
432 1.15 augustss #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
433 1.72 augustss #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
434 1.1 augustss
435 1.1 augustss /* Hub specific request */
436 1.1 augustss #define UR_GET_BUS_STATE 0x02
437 1.55 augustss #define UR_CLEAR_TT_BUFFER 0x08
438 1.55 augustss #define UR_RESET_TT 0x09
439 1.55 augustss #define UR_GET_TT_STATE 0x0a
440 1.55 augustss #define UR_STOP_TT 0x0b
441 1.111 skrll #define UR_SET_HUB_DEPTH 0x0c
442 1.111 skrll #define UR_GET_PORT_ERR_COUNT 0x0d
443 1.1 augustss
444 1.101 skrll /*
445 1.101 skrll * Hub features from USB 2.0 spec, table 11-17 and updated by the
446 1.101 skrll * LPM ECN table 4-7.
447 1.101 skrll */
448 1.1 augustss #define UHF_C_HUB_LOCAL_POWER 0
449 1.1 augustss #define UHF_C_HUB_OVER_CURRENT 1
450 1.1 augustss #define UHF_PORT_CONNECTION 0
451 1.1 augustss #define UHF_PORT_ENABLE 1
452 1.1 augustss #define UHF_PORT_SUSPEND 2
453 1.1 augustss #define UHF_PORT_OVER_CURRENT 3
454 1.1 augustss #define UHF_PORT_RESET 4
455 1.111 skrll #define UHF_PORT_LINK_STATE 5
456 1.1 augustss #define UHF_PORT_POWER 8
457 1.1 augustss #define UHF_PORT_LOW_SPEED 9
458 1.101 skrll #define UHF_PORT_L1 10
459 1.1 augustss #define UHF_C_PORT_CONNECTION 16
460 1.1 augustss #define UHF_C_PORT_ENABLE 17
461 1.1 augustss #define UHF_C_PORT_SUSPEND 18
462 1.1 augustss #define UHF_C_PORT_OVER_CURRENT 19
463 1.1 augustss #define UHF_C_PORT_RESET 20
464 1.55 augustss #define UHF_PORT_TEST 21
465 1.55 augustss #define UHF_PORT_INDICATOR 22
466 1.101 skrll #define UHF_C_PORT_L1 23
467 1.1 augustss
468 1.111 skrll /* SS HUB specific features */
469 1.111 skrll #define UHF_PORT_U1_TIMEOUT 23
470 1.111 skrll #define UHF_PORT_U2_TIMEOUT 24
471 1.111 skrll #define UHF_C_PORT_LINK_STATE 25
472 1.111 skrll #define UHF_C_PORT_CONFIG_ERROR 26
473 1.111 skrll #define UHF_PORT_REMOTE_WAKE_MASK 27
474 1.111 skrll #define UHF_BH_PORT_RESET 28
475 1.111 skrll #define UHF_C_BH_PORT_RESET 29
476 1.111 skrll #define UHF_FORCE_LINKPM_ACCEPT 30
477 1.111 skrll
478 1.1 augustss typedef struct {
479 1.1 augustss uByte bDescLength;
480 1.1 augustss uByte bDescriptorType;
481 1.1 augustss uByte bNbrPorts;
482 1.111 skrll #define UHD_NPORTS_MAX 255
483 1.8 augustss uWord wHubCharacteristics;
484 1.55 augustss #define UHD_PWR 0x0003
485 1.55 augustss #define UHD_PWR_GANGED 0x0000
486 1.55 augustss #define UHD_PWR_INDIVIDUAL 0x0001
487 1.55 augustss #define UHD_PWR_NO_SWITCH 0x0002
488 1.55 augustss #define UHD_COMPOUND 0x0004
489 1.55 augustss #define UHD_OC 0x0018
490 1.55 augustss #define UHD_OC_GLOBAL 0x0000
491 1.55 augustss #define UHD_OC_INDIVIDUAL 0x0008
492 1.55 augustss #define UHD_OC_NONE 0x0010
493 1.55 augustss #define UHD_TT_THINK 0x0060
494 1.55 augustss #define UHD_TT_THINK_8 0x0000
495 1.55 augustss #define UHD_TT_THINK_16 0x0020
496 1.55 augustss #define UHD_TT_THINK_24 0x0040
497 1.55 augustss #define UHD_TT_THINK_32 0x0060
498 1.55 augustss #define UHD_PORT_IND 0x0080
499 1.1 augustss uByte bPwrOn2PwrGood; /* delay in 2 ms units */
500 1.1 augustss #define UHD_PWRON_FACTOR 2
501 1.1 augustss uByte bHubContrCurrent;
502 1.8 augustss uByte DeviceRemovable[32]; /* max 255 ports */
503 1.8 augustss #define UHD_NOT_REMOV(desc, i) \
504 1.8 augustss (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
505 1.46 augustss /* deprecated */ uByte PortPowerCtrlMask[1];
506 1.49 augustss } UPACKED usb_hub_descriptor_t;
507 1.46 augustss #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
508 1.1 augustss
509 1.1 augustss typedef struct {
510 1.53 augustss uByte bLength;
511 1.53 augustss uByte bDescriptorType;
512 1.111 skrll uByte bNbrPorts;
513 1.111 skrll #define UHD_SS_NPORTS_MAX 15
514 1.111 skrll uWord wHubCharacteristics;
515 1.111 skrll uByte bPwrOn2PwrGood; /* delay in 2 ms units */
516 1.111 skrll uByte bHubContrCurrent;
517 1.111 skrll uByte bHubHdrDecLat;
518 1.111 skrll uWord wHubDelay; /* forward delay in nanosec */
519 1.111 skrll uByte DeviceRemovable[2]; /* max 15 ports */
520 1.111 skrll } UPACKED usb_hub_ss_descriptor_t;
521 1.111 skrll #define USB_HUB_SS_DESCRIPTOR_SIZE 12
522 1.111 skrll
523 1.111 skrll typedef struct {
524 1.111 skrll uByte bLength;
525 1.111 skrll uByte bDescriptorType;
526 1.53 augustss uWord bcdUSB;
527 1.53 augustss uByte bDeviceClass;
528 1.53 augustss uByte bDeviceSubClass;
529 1.53 augustss uByte bDeviceProtocol;
530 1.53 augustss uByte bMaxPacketSize0;
531 1.53 augustss uByte bNumConfigurations;
532 1.53 augustss uByte bReserved;
533 1.53 augustss } UPACKED usb_device_qualifier_t;
534 1.53 augustss #define USB_DEVICE_QUALIFIER_SIZE 10
535 1.60 augustss
536 1.60 augustss typedef struct {
537 1.60 augustss uByte bLength;
538 1.60 augustss uByte bDescriptorType;
539 1.60 augustss uByte bmAttributes;
540 1.60 augustss #define UOTG_SRP 0x01
541 1.60 augustss #define UOTG_HNP 0x02
542 1.60 augustss } UPACKED usb_otg_descriptor_t;
543 1.60 augustss
544 1.60 augustss /* OTG feature selectors */
545 1.60 augustss #define UOTG_B_HNP_ENABLE 3
546 1.60 augustss #define UOTG_A_HNP_SUPPORT 4
547 1.60 augustss #define UOTG_A_ALT_HNP_SUPPORT 5
548 1.53 augustss
549 1.53 augustss typedef struct {
550 1.85 jakllsch uByte bLength;
551 1.85 jakllsch uByte bDescriptorType;
552 1.85 jakllsch uByte bDebugInEndpoint;
553 1.85 jakllsch uByte bDebugOutEndpoint;
554 1.85 jakllsch } UPACKED usb_debug_descriptor_t;
555 1.85 jakllsch
556 1.85 jakllsch typedef struct {
557 1.1 augustss uWord wStatus;
558 1.1 augustss /* Device status flags */
559 1.1 augustss #define UDS_SELF_POWERED 0x0001
560 1.1 augustss #define UDS_REMOTE_WAKEUP 0x0002
561 1.8 augustss /* Endpoint status flags */
562 1.8 augustss #define UES_HALT 0x0001
563 1.49 augustss } UPACKED usb_status_t;
564 1.1 augustss
565 1.1 augustss typedef struct {
566 1.1 augustss uWord wHubStatus;
567 1.1 augustss #define UHS_LOCAL_POWER 0x0001
568 1.1 augustss #define UHS_OVER_CURRENT 0x0002
569 1.1 augustss uWord wHubChange;
570 1.49 augustss } UPACKED usb_hub_status_t;
571 1.1 augustss
572 1.1 augustss typedef struct {
573 1.1 augustss uWord wPortStatus;
574 1.1 augustss #define UPS_CURRENT_CONNECT_STATUS 0x0001
575 1.1 augustss #define UPS_PORT_ENABLED 0x0002
576 1.1 augustss #define UPS_SUSPEND 0x0004
577 1.1 augustss #define UPS_OVERCURRENT_INDICATOR 0x0008
578 1.1 augustss #define UPS_RESET 0x0010
579 1.102 skrll #define UPS_PORT_L1 0x0020
580 1.111 skrll #define UPS_PORT_LS_GET(x) __SHIFTOUT(x, __BITS(8,5))
581 1.111 skrll #define UPS_PORT_LS_U0 0x00
582 1.111 skrll #define UPS_PORT_LS_U1 0x01
583 1.111 skrll #define UPS_PORT_LS_U2 0x02
584 1.111 skrll #define UPS_PORT_LS_U3 0x03
585 1.111 skrll #define UPS_PORT_LS_SS_DIS 0x04
586 1.111 skrll #define UPS_PORT_LS_RX_DET 0x05
587 1.111 skrll #define UPS_PORT_LS_SS_INA 0x06
588 1.111 skrll #define UPS_PORT_LS_POLL 0x07
589 1.111 skrll #define UPS_PORT_LS_RECOVER 0x08
590 1.111 skrll #define UPS_PORT_LS_HOT_RST 0x09
591 1.111 skrll #define UPS_PORT_LS_COMP_MODE 0x0a
592 1.111 skrll #define UPS_PORT_LS_LOOPBACK 0x0b
593 1.111 skrll #define UPS_PORT_LS_RESUME 0x0f
594 1.1 augustss #define UPS_PORT_POWER 0x0100
595 1.111 skrll #define UPS_PORT_POWER_SS 0x0200
596 1.91 matt #define UPS_FULL_SPEED 0x0000 /* for completeness */
597 1.1 augustss #define UPS_LOW_SPEED 0x0200
598 1.55 augustss #define UPS_HIGH_SPEED 0x0400
599 1.111 skrll #define UPS_SUPER_SPEED 0x0800
600 1.55 augustss #define UPS_PORT_TEST 0x0800
601 1.55 augustss #define UPS_PORT_INDICATOR 0x1000
602 1.1 augustss uWord wPortChange;
603 1.1 augustss #define UPS_C_CONNECT_STATUS 0x0001
604 1.1 augustss #define UPS_C_PORT_ENABLED 0x0002
605 1.1 augustss #define UPS_C_SUSPEND 0x0004
606 1.1 augustss #define UPS_C_OVERCURRENT_INDICATOR 0x0008
607 1.1 augustss #define UPS_C_PORT_RESET 0x0010
608 1.103 skrll #define UPS_C_PORT_L1 0x0020
609 1.111 skrll #define UPS_C_BH_PORT_RESET 0x0020
610 1.111 skrll #define UPS_C_PORT_LINK_STATE 0x0040
611 1.111 skrll #define UPS_C_PORT_CONFIG_ERROR 0x0080
612 1.49 augustss } UPACKED usb_port_status_t;
613 1.1 augustss
614 1.41 augustss /* Device class codes */
615 1.68 augustss #define UDCLASS_IN_INTERFACE 0x00
616 1.41 augustss #define UDCLASS_COMM 0x02
617 1.41 augustss #define UDCLASS_HUB 0x09
618 1.67 augustss #define UDSUBCLASS_HUB 0x00
619 1.67 augustss #define UDPROTO_FSHUB 0x00
620 1.67 augustss #define UDPROTO_HSHUBSTT 0x01
621 1.67 augustss #define UDPROTO_HSHUBMTT 0x02
622 1.104 jakllsch #define UDPROTO_SSHUB 0x03
623 1.68 augustss #define UDCLASS_DIAGNOSTIC 0xdc
624 1.67 augustss #define UDCLASS_WIRELESS 0xe0
625 1.67 augustss #define UDSUBCLASS_RF 0x01
626 1.67 augustss #define UDPROTO_BLUETOOTH 0x01
627 1.68 augustss #define UDCLASS_VENDOR 0xff
628 1.41 augustss
629 1.41 augustss /* Interface class codes */
630 1.41 augustss #define UICLASS_UNSPEC 0x00
631 1.41 augustss
632 1.41 augustss #define UICLASS_AUDIO 0x01
633 1.41 augustss #define UISUBCLASS_AUDIOCONTROL 1
634 1.41 augustss #define UISUBCLASS_AUDIOSTREAM 2
635 1.41 augustss #define UISUBCLASS_MIDISTREAM 3
636 1.41 augustss
637 1.111 skrll #define UICLASS_VIDEO 0x0e
638 1.81 jmcneill #define UISUBCLASS_VIDEOCONTROL 1
639 1.81 jmcneill #define UISUBCLASS_VIDEOSTREAMING 2
640 1.81 jmcneill #define UISUBCLASS_VIDEOCOLLECTION 3
641 1.81 jmcneill
642 1.41 augustss #define UICLASS_CDC 0x02 /* communication */
643 1.41 augustss #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
644 1.41 augustss #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
645 1.41 augustss #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
646 1.41 augustss #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
647 1.41 augustss #define UISUBCLASS_CAPI_CONTROLMODEL 5
648 1.41 augustss #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
649 1.41 augustss #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
650 1.95 blymn #define UIPROTO_CDC_NOCLASS 0 /* no class specific
651 1.95 blymn protocol required */
652 1.41 augustss #define UIPROTO_CDC_AT 1
653 1.41 augustss
654 1.41 augustss #define UICLASS_HID 0x03
655 1.41 augustss #define UISUBCLASS_BOOT 1
656 1.41 augustss #define UIPROTO_BOOT_KEYBOARD 1
657 1.88 phx #define UIPROTO_MOUSE 2
658 1.41 augustss
659 1.41 augustss #define UICLASS_PHYSICAL 0x05
660 1.41 augustss
661 1.68 augustss #define UICLASS_IMAGE 0x06
662 1.68 augustss
663 1.41 augustss #define UICLASS_PRINTER 0x07
664 1.41 augustss #define UISUBCLASS_PRINTER 1
665 1.41 augustss #define UIPROTO_PRINTER_UNI 1
666 1.41 augustss #define UIPROTO_PRINTER_BI 2
667 1.52 nathanw #define UIPROTO_PRINTER_1284 3
668 1.41 augustss
669 1.41 augustss #define UICLASS_MASS 0x08
670 1.41 augustss #define UISUBCLASS_RBC 1
671 1.41 augustss #define UISUBCLASS_SFF8020I 2
672 1.41 augustss #define UISUBCLASS_QIC157 3
673 1.41 augustss #define UISUBCLASS_UFI 4
674 1.41 augustss #define UISUBCLASS_SFF8070I 5
675 1.41 augustss #define UISUBCLASS_SCSI 6
676 1.41 augustss #define UIPROTO_MASS_CBI_I 0
677 1.41 augustss #define UIPROTO_MASS_CBI 1
678 1.58 augustss #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
679 1.58 augustss #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
680 1.111 skrll #define UIPROTO_MASS_UAS 98 /* USB Attached SCSI */
681 1.41 augustss
682 1.41 augustss #define UICLASS_HUB 0x09
683 1.41 augustss #define UISUBCLASS_HUB 0
684 1.55 augustss #define UIPROTO_FSHUB 0
685 1.55 augustss #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
686 1.55 augustss #define UIPROTO_HSHUBMTT 1
687 1.41 augustss
688 1.41 augustss #define UICLASS_CDC_DATA 0x0a
689 1.41 augustss #define UISUBCLASS_DATA 0
690 1.41 augustss #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
691 1.41 augustss #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
692 1.41 augustss #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
693 1.41 augustss #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
694 1.41 augustss #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
695 1.41 augustss #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
696 1.66 augustss #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
697 1.41 augustss #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
698 1.41 augustss #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
699 1.41 augustss #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
700 1.41 augustss #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
701 1.41 augustss #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
702 1.41 augustss #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
703 1.41 augustss
704 1.68 augustss #define UICLASS_SMARTCARD 0x0b
705 1.68 augustss
706 1.68 augustss /*#define UICLASS_FIRM_UPD 0x0c*/
707 1.68 augustss
708 1.68 augustss #define UICLASS_SECURITY 0x0d
709 1.68 augustss
710 1.68 augustss #define UICLASS_DIAGNOSTIC 0xdc
711 1.67 augustss
712 1.67 augustss #define UICLASS_WIRELESS 0xe0
713 1.67 augustss #define UISUBCLASS_RF 0x01
714 1.67 augustss #define UIPROTO_BLUETOOTH 0x01
715 1.92 jakllsch #define UIPROTO_RNDIS 0x03
716 1.41 augustss
717 1.41 augustss #define UICLASS_APPL_SPEC 0xfe
718 1.61 augustss #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
719 1.59 augustss #define UISUBCLASS_IRDA 2
720 1.59 augustss #define UIPROTO_IRDA 0
721 1.59 augustss
722 1.41 augustss #define UICLASS_VENDOR 0xff
723 1.36 augustss
724 1.1 augustss
725 1.1 augustss #define USB_HUB_MAX_DEPTH 5
726 1.1 augustss
727 1.66 augustss /*
728 1.66 augustss * Minimum time a device needs to be powered down to go through
729 1.11 augustss * a power cycle. XXX Are these time in the spec?
730 1.6 augustss */
731 1.11 augustss #define USB_POWER_DOWN_TIME 200 /* ms */
732 1.9 augustss #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
733 1.6 augustss
734 1.8 augustss #if 0
735 1.9 augustss /* These are the values from the spec. */
736 1.1 augustss #define USB_PORT_RESET_DELAY 10 /* ms */
737 1.56 augustss #define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
738 1.69 augustss #define USB_PORT_RESET_RECOVERY 10 /* ms */
739 1.1 augustss #define USB_PORT_POWERUP_DELAY 100 /* ms */
740 1.8 augustss #define USB_SET_ADDRESS_SETTLE 2 /* ms */
741 1.44 augustss #define USB_RESUME_DELAY (20*5) /* ms */
742 1.22 augustss #define USB_RESUME_WAIT 10 /* ms */
743 1.22 augustss #define USB_RESUME_RECOVERY 10 /* ms */
744 1.45 augustss #define USB_EXTRA_POWER_UP_TIME 0 /* ms */
745 1.8 augustss #else
746 1.9 augustss /* Allow for marginal (i.e. non-conforming) devices. */
747 1.18 augustss #define USB_PORT_RESET_DELAY 50 /* ms */
748 1.56 augustss #define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
749 1.69 augustss #define USB_PORT_RESET_RECOVERY 250 /* ms */
750 1.56 augustss #define USB_PORT_POWERUP_DELAY 300 /* ms */
751 1.8 augustss #define USB_SET_ADDRESS_SETTLE 10 /* ms */
752 1.22 augustss #define USB_RESUME_DELAY (50*5) /* ms */
753 1.22 augustss #define USB_RESUME_WAIT 50 /* ms */
754 1.22 augustss #define USB_RESUME_RECOVERY 50 /* ms */
755 1.45 augustss #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
756 1.8 augustss #endif
757 1.1 augustss
758 1.1 augustss #define USB_MIN_POWER 100 /* mA */
759 1.112 skrll #define USB_MIN_POWER_SS 150 /* mA */
760 1.1 augustss #define USB_MAX_POWER 500 /* mA */
761 1.112 skrll #define USB_MAX_POWER_SS 900 /* mA */
762 1.1 augustss
763 1.11 augustss #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
764 1.47 augustss
765 1.47 augustss
766 1.47 augustss #define USB_UNCONFIG_NO 0
767 1.47 augustss #define USB_UNCONFIG_INDEX (-1)
768 1.1 augustss
769 1.85 jakllsch
770 1.85 jakllsch /* Packet IDs */
771 1.85 jakllsch #define UPID_RESERVED 0xf0
772 1.85 jakllsch #define UPID_OUT 0xe1
773 1.85 jakllsch #define UPID_ACK 0xd2
774 1.85 jakllsch #define UPID_DATA0 0xc3
775 1.85 jakllsch #define UPID_PING 0xb4
776 1.85 jakllsch #define UPID_SOF 0xa5
777 1.85 jakllsch #define UPID_NYET 0x96
778 1.85 jakllsch #define UPID_DATA2 0x87
779 1.85 jakllsch #define UPID_SPLIT 0x78
780 1.85 jakllsch #define UPID_IN 0x69
781 1.85 jakllsch #define UPID_NAK 0x5a
782 1.85 jakllsch #define UPID_DATA1 0x4b
783 1.85 jakllsch #define UPID_ERR 0x3c
784 1.85 jakllsch #define UPID_PREAMBLE 0x3c
785 1.85 jakllsch #define UPID_SETUP 0x2d
786 1.85 jakllsch #define UPID_STALL 0x1e
787 1.85 jakllsch #define UPID_MDATA 0x0f
788 1.85 jakllsch
789 1.85 jakllsch
790 1.1 augustss /*** ioctl() related stuff ***/
791 1.1 augustss
792 1.1 augustss struct usb_ctl_request {
793 1.62 christos int ucr_addr;
794 1.62 christos usb_device_request_t ucr_request;
795 1.62 christos void *ucr_data;
796 1.62 christos int ucr_flags;
797 1.33 augustss #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
798 1.62 christos int ucr_actlen; /* actual length transferred */
799 1.1 augustss };
800 1.1 augustss
801 1.6 augustss struct usb_alt_interface {
802 1.62 christos int uai_config_index;
803 1.62 christos int uai_interface_index;
804 1.62 christos int uai_alt_no;
805 1.6 augustss };
806 1.6 augustss
807 1.6 augustss #define USB_CURRENT_CONFIG_INDEX (-1)
808 1.6 augustss #define USB_CURRENT_ALT_INDEX (-1)
809 1.6 augustss
810 1.6 augustss struct usb_config_desc {
811 1.62 christos int ucd_config_index;
812 1.62 christos usb_config_descriptor_t ucd_desc;
813 1.6 augustss };
814 1.6 augustss
815 1.6 augustss struct usb_interface_desc {
816 1.62 christos int uid_config_index;
817 1.62 christos int uid_interface_index;
818 1.62 christos int uid_alt_index;
819 1.62 christos usb_interface_descriptor_t uid_desc;
820 1.6 augustss };
821 1.6 augustss
822 1.6 augustss struct usb_endpoint_desc {
823 1.62 christos int ued_config_index;
824 1.62 christos int ued_interface_index;
825 1.62 christos int ued_alt_index;
826 1.62 christos int ued_endpoint_index;
827 1.62 christos usb_endpoint_descriptor_t ued_desc;
828 1.6 augustss };
829 1.6 augustss
830 1.6 augustss struct usb_full_desc {
831 1.62 christos int ufd_config_index;
832 1.62 christos u_int ufd_size;
833 1.62 christos u_char *ufd_data;
834 1.1 augustss };
835 1.1 augustss
836 1.7 augustss struct usb_string_desc {
837 1.62 christos int usd_string_index;
838 1.62 christos int usd_language_id;
839 1.62 christos usb_string_descriptor_t usd_desc;
840 1.7 augustss };
841 1.7 augustss
842 1.1 augustss struct usb_ctl_report_desc {
843 1.62 christos int ucrd_size;
844 1.62 christos u_char ucrd_data[1024]; /* filled data size will vary */
845 1.1 augustss };
846 1.1 augustss
847 1.40 augustss typedef struct { u_int32_t cookie; } usb_event_cookie_t;
848 1.40 augustss
849 1.40 augustss #define USB_MAX_DEVNAMES 4
850 1.40 augustss #define USB_MAX_DEVNAMELEN 16
851 1.1 augustss struct usb_device_info {
852 1.62 christos u_int8_t udi_bus;
853 1.62 christos u_int8_t udi_addr; /* device address */
854 1.62 christos usb_event_cookie_t udi_cookie;
855 1.72 augustss char udi_product[USB_MAX_ENCODED_STRING_LEN];
856 1.72 augustss char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
857 1.62 christos char udi_release[8];
858 1.72 augustss char udi_serial[USB_MAX_ENCODED_STRING_LEN];
859 1.62 christos u_int16_t udi_productNo;
860 1.62 christos u_int16_t udi_vendorNo;
861 1.62 christos u_int16_t udi_releaseNo;
862 1.62 christos u_int8_t udi_class;
863 1.62 christos u_int8_t udi_subclass;
864 1.62 christos u_int8_t udi_protocol;
865 1.62 christos u_int8_t udi_config;
866 1.62 christos u_int8_t udi_speed;
867 1.54 augustss #define USB_SPEED_LOW 1
868 1.54 augustss #define USB_SPEED_FULL 2
869 1.54 augustss #define USB_SPEED_HIGH 3
870 1.105 jakllsch #define USB_SPEED_SUPER 4
871 1.62 christos int udi_power; /* power consumption in mA, 0 if selfpowered */
872 1.62 christos int udi_nports;
873 1.62 christos char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
874 1.62 christos u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
875 1.1 augustss #define USB_PORT_ENABLED 0xff
876 1.1 augustss #define USB_PORT_SUSPENDED 0xfe
877 1.1 augustss #define USB_PORT_POWERED 0xfd
878 1.1 augustss #define USB_PORT_DISABLED 0xfc
879 1.1 augustss };
880 1.1 augustss
881 1.75 pavel /* <=3.0 had this layout of the structure */
882 1.75 pavel struct usb_device_info_old {
883 1.75 pavel u_int8_t udi_bus;
884 1.75 pavel u_int8_t udi_addr; /* device address */
885 1.75 pavel usb_event_cookie_t udi_cookie;
886 1.75 pavel char udi_product[USB_MAX_STRING_LEN];
887 1.75 pavel char udi_vendor[USB_MAX_STRING_LEN];
888 1.75 pavel char udi_release[8];
889 1.75 pavel u_int16_t udi_productNo;
890 1.75 pavel u_int16_t udi_vendorNo;
891 1.75 pavel u_int16_t udi_releaseNo;
892 1.75 pavel u_int8_t udi_class;
893 1.75 pavel u_int8_t udi_subclass;
894 1.75 pavel u_int8_t udi_protocol;
895 1.75 pavel u_int8_t udi_config;
896 1.75 pavel u_int8_t udi_speed;
897 1.75 pavel int udi_power; /* power consumption in mA, 0 if selfpowered */
898 1.75 pavel int udi_nports;
899 1.75 pavel char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
900 1.75 pavel u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
901 1.75 pavel };
902 1.75 pavel
903 1.2 augustss struct usb_ctl_report {
904 1.62 christos int ucr_report;
905 1.62 christos u_char ucr_data[1024]; /* filled data size will vary */
906 1.2 augustss };
907 1.2 augustss
908 1.3 augustss struct usb_device_stats {
909 1.62 christos u_long uds_requests[4]; /* indexed by transfer type UE_* */
910 1.35 augustss };
911 1.35 augustss
912 1.74 gdt struct usb_bulk_ra_wb_opt {
913 1.74 gdt u_int ra_wb_buffer_size;
914 1.74 gdt u_int ra_wb_request_size;
915 1.74 gdt };
916 1.74 gdt
917 1.35 augustss /* Events that can be read from /dev/usb */
918 1.35 augustss struct usb_event {
919 1.35 augustss int ue_type;
920 1.40 augustss #define USB_EVENT_CTRLR_ATTACH 1
921 1.40 augustss #define USB_EVENT_CTRLR_DETACH 2
922 1.40 augustss #define USB_EVENT_DEVICE_ATTACH 3
923 1.40 augustss #define USB_EVENT_DEVICE_DETACH 4
924 1.40 augustss #define USB_EVENT_DRIVER_ATTACH 5
925 1.40 augustss #define USB_EVENT_DRIVER_DETACH 6
926 1.51 augustss #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
927 1.64 augustss #define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH)
928 1.35 augustss struct timespec ue_time;
929 1.40 augustss union {
930 1.40 augustss struct {
931 1.40 augustss int ue_bus;
932 1.40 augustss } ue_ctrlr;
933 1.40 augustss struct usb_device_info ue_device;
934 1.40 augustss struct {
935 1.40 augustss usb_event_cookie_t ue_cookie;
936 1.40 augustss char ue_devname[16];
937 1.66 augustss } ue_driver;
938 1.40 augustss } u;
939 1.3 augustss };
940 1.3 augustss
941 1.75 pavel /* old <=3.0 compat event */
942 1.75 pavel struct usb_event_old {
943 1.75 pavel int ue_type;
944 1.75 pavel struct timespec ue_time;
945 1.75 pavel union {
946 1.75 pavel struct {
947 1.75 pavel int ue_bus;
948 1.75 pavel } ue_ctrlr;
949 1.75 pavel struct usb_device_info_old ue_device;
950 1.75 pavel struct {
951 1.75 pavel usb_event_cookie_t ue_cookie;
952 1.75 pavel char ue_devname[16];
953 1.75 pavel } ue_driver;
954 1.75 pavel } u;
955 1.75 pavel };
956 1.75 pavel
957 1.75 pavel
958 1.1 augustss /* USB controller */
959 1.1 augustss #define USB_REQUEST _IOWR('U', 1, struct usb_ctl_request)
960 1.1 augustss #define USB_SETDEBUG _IOW ('U', 2, int)
961 1.1 augustss #define USB_DISCOVER _IO ('U', 3)
962 1.1 augustss #define USB_DEVICEINFO _IOWR('U', 4, struct usb_device_info)
963 1.75 pavel #define USB_DEVICEINFO_OLD _IOWR('U', 4, struct usb_device_info_old)
964 1.3 augustss #define USB_DEVICESTATS _IOR ('U', 5, struct usb_device_stats)
965 1.1 augustss
966 1.1 augustss /* Generic HID device */
967 1.1 augustss #define USB_GET_REPORT_DESC _IOR ('U', 21, struct usb_ctl_report_desc)
968 1.2 augustss #define USB_SET_IMMED _IOW ('U', 22, int)
969 1.2 augustss #define USB_GET_REPORT _IOWR('U', 23, struct usb_ctl_report)
970 1.42 augustss #define USB_SET_REPORT _IOW ('U', 24, struct usb_ctl_report)
971 1.53 augustss #define USB_GET_REPORT_ID _IOR ('U', 25, int)
972 1.1 augustss
973 1.1 augustss /* Generic USB device */
974 1.6 augustss #define USB_GET_CONFIG _IOR ('U', 100, int)
975 1.6 augustss #define USB_SET_CONFIG _IOW ('U', 101, int)
976 1.6 augustss #define USB_GET_ALTINTERFACE _IOWR('U', 102, struct usb_alt_interface)
977 1.7 augustss #define USB_SET_ALTINTERFACE _IOWR('U', 103, struct usb_alt_interface)
978 1.6 augustss #define USB_GET_NO_ALT _IOWR('U', 104, struct usb_alt_interface)
979 1.6 augustss #define USB_GET_DEVICE_DESC _IOR ('U', 105, usb_device_descriptor_t)
980 1.7 augustss #define USB_GET_CONFIG_DESC _IOWR('U', 106, struct usb_config_desc)
981 1.6 augustss #define USB_GET_INTERFACE_DESC _IOWR('U', 107, struct usb_interface_desc)
982 1.6 augustss #define USB_GET_ENDPOINT_DESC _IOWR('U', 108, struct usb_endpoint_desc)
983 1.7 augustss #define USB_GET_FULL_DESC _IOWR('U', 109, struct usb_full_desc)
984 1.7 augustss #define USB_GET_STRING_DESC _IOWR('U', 110, struct usb_string_desc)
985 1.7 augustss #define USB_DO_REQUEST _IOWR('U', 111, struct usb_ctl_request)
986 1.7 augustss #define USB_GET_DEVICEINFO _IOR ('U', 112, struct usb_device_info)
987 1.75 pavel #define USB_GET_DEVICEINFO_OLD _IOR ('U', 112, struct usb_device_info_old)
988 1.16 augustss #define USB_SET_SHORT_XFER _IOW ('U', 113, int)
989 1.29 augustss #define USB_SET_TIMEOUT _IOW ('U', 114, int)
990 1.74 gdt #define USB_SET_BULK_RA _IOW ('U', 115, int)
991 1.74 gdt #define USB_SET_BULK_WB _IOW ('U', 116, int)
992 1.74 gdt #define USB_SET_BULK_RA_OPT _IOW ('U', 117, struct usb_bulk_ra_wb_opt)
993 1.74 gdt #define USB_SET_BULK_WB_OPT _IOW ('U', 118, struct usb_bulk_ra_wb_opt)
994 1.24 augustss
995 1.24 augustss /* Modem device */
996 1.24 augustss #define USB_GET_CM_OVER_DATA _IOR ('U', 130, int)
997 1.24 augustss #define USB_SET_CM_OVER_DATA _IOW ('U', 131, int)
998 1.1 augustss
999 1.1 augustss #endif /* _USB_H_ */
1000