xref: /dragonfly/sys/bus/u4b/usb.h (revision 805c8e8e4093ceca2e27510ad3a66d4de8060a55)
1 /* $FreeBSD: head/sys/dev/usb/usb.h 273456 2014-10-22 07:50:19Z hselasky $ */
2 /*-
3  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * This file contains standard definitions for the following USB
31  * protocol versions:
32  *
33  * USB v1.0
34  * USB v1.1
35  * USB v2.0
36  * USB v3.0
37  */
38 
39 #ifndef _USB_STANDARD_H_
40 #define   _USB_STANDARD_H_
41 
42 #if defined(_KERNEL)
43 #include "opt_usb.h"
44 
45 /* Declare parent SYSCTL USB node. */
46 #ifdef SYSCTL_DECL
47 SYSCTL_DECL(_hw_usb);
48 #endif
49 
50 #ifdef MALLOC_DECLARE
51 MALLOC_DECLARE(M_USB);
52 MALLOC_DECLARE(M_USBDEV);
53 #endif
54 #endif /* _KERNEL */
55 
56 #include <bus/u4b/usb_endian.h>
57 #include <bus/u4b/usb_dragonfly.h>
58 
59 #define   USB_STACK_VERSION 2000                  /* 2.0 */
60 
61 /* Definition of some hardcoded USB constants. */
62 
63 #define   USB_MAX_IPACKET               8         /* initial USB packet size */
64 #define   USB_EP_MAX (2*16)             /* hardcoded */
65 #define   USB_ROOT_HUB_ADDR 1           /* index */
66 #define   USB_MIN_DEVICES 2             /* unused + root HUB */
67 #define   USB_UNCONFIG_INDEX 0xFF                 /* internal use only */
68 #define   USB_IFACE_INDEX_ANY 0xFF      /* internal use only */
69 #define   USB_START_ADDR 0              /* default USB device BUS address
70                                                    * after USB bus reset */
71 #define   USB_CONTROL_ENDPOINT 0                  /* default control endpoint */
72 
73 #define   USB_FRAMES_PER_SECOND_FS 1000 /* full speed */
74 #define   USB_FRAMES_PER_SECOND_HS 8000 /* high speed */
75 
76 #define   USB_FS_BYTES_PER_HS_UFRAME 188          /* bytes */
77 #define   USB_HS_MICRO_FRAMES_MAX 8     /* units */
78 
79 #define   USB_ISOC_TIME_MAX 128                   /* ms */
80 
81 /*
82  * Minimum time a device needs to be powered down to go through a
83  * power cycle. These values are not in the USB specification.
84  */
85 #define   USB_POWER_DOWN_TIME 200       /* ms */
86 #define   USB_PORT_POWER_DOWN_TIME      100       /* ms */
87 
88 /* Definition of software USB power modes */
89 #define   USB_POWER_MODE_OFF 0                    /* turn off device */
90 #define   USB_POWER_MODE_ON 1           /* always on */
91 #define   USB_POWER_MODE_SAVE 2                   /* automatic suspend and resume */
92 #define   USB_POWER_MODE_SUSPEND 3      /* force suspend */
93 #define   USB_POWER_MODE_RESUME 4                 /* force resume */
94 
95 /* These are the values from the USB specification. */
96 #define   USB_PORT_RESET_DELAY_SPEC     10        /* ms */
97 #define   USB_PORT_ROOT_RESET_DELAY_SPEC          50        /* ms */
98 #define   USB_PORT_RESET_RECOVERY_SPEC  10        /* ms */
99 #define   USB_PORT_POWERUP_DELAY_SPEC   100       /* ms */
100 #define   USB_PORT_RESUME_DELAY_SPEC    20        /* ms */
101 #define   USB_SET_ADDRESS_SETTLE_SPEC   2         /* ms */
102 #define   USB_RESUME_DELAY_SPEC                   (20*5)    /* ms */
103 #define   USB_RESUME_WAIT_SPEC                    10        /* ms */
104 #define   USB_RESUME_RECOVERY_SPEC      10        /* ms */
105 #define   USB_EXTRA_POWER_UP_TIME_SPEC  0         /* ms */
106 
107 /* Allow for marginal and non-conforming devices. */
108 #define   USB_PORT_RESET_DELAY                    50        /* ms */
109 #define   USB_PORT_ROOT_RESET_DELAY     250       /* ms */
110 #define   USB_PORT_RESET_RECOVERY                 250       /* ms */
111 #define   USB_PORT_POWERUP_DELAY                  300       /* ms */
112 #define   USB_PORT_RESUME_DELAY                   (20*2)    /* ms */
113 #define   USB_SET_ADDRESS_SETTLE                  10        /* ms */
114 #define   USB_RESUME_DELAY              (50*5)    /* ms */
115 #define   USB_RESUME_WAIT                         50        /* ms */
116 #define   USB_RESUME_RECOVERY           50        /* ms */
117 #define   USB_EXTRA_POWER_UP_TIME                 20        /* ms */
118 
119 #define   USB_MIN_POWER                 100       /* mA */
120 #define   USB_MAX_POWER                 500       /* mA */
121 
122 #define   USB_BUS_RESET_DELAY 100       /* ms */
123 
124 /*
125  * USB record layout in memory:
126  *
127  * - USB config 0
128  *   - USB interfaces
129  *     - USB alternative interfaces
130  *       - USB endpoints
131  *
132  * - USB config 1
133  *   - USB interfaces
134  *     - USB alternative interfaces
135  *       - USB endpoints
136  */
137 
138 /* Declaration of USB records */
139 
140 struct usb_device_request {
141           uByte     bmRequestType;
142           uByte     bRequest;
143           uWord     wValue;
144           uWord     wIndex;
145           uWord     wLength;
146 } __packed;
147 typedef struct usb_device_request usb_device_request_t;
148 
149 #define   UT_WRITE            0x00
150 #define   UT_READ                       0x80
151 #define   UT_STANDARD                   0x00
152 #define   UT_CLASS            0x20
153 #define   UT_VENDOR           0x40
154 #define   UT_DEVICE           0x00
155 #define   UT_INTERFACE                  0x01
156 #define   UT_ENDPOINT                   0x02
157 #define   UT_OTHER            0x03
158 
159 #define   UT_READ_DEVICE                (UT_READ  | UT_STANDARD | UT_DEVICE)
160 #define   UT_READ_INTERFACE   (UT_READ  | UT_STANDARD | UT_INTERFACE)
161 #define   UT_READ_ENDPOINT    (UT_READ  | UT_STANDARD | UT_ENDPOINT)
162 #define   UT_WRITE_DEVICE               (UT_WRITE | UT_STANDARD | UT_DEVICE)
163 #define   UT_WRITE_INTERFACE  (UT_WRITE | UT_STANDARD | UT_INTERFACE)
164 #define   UT_WRITE_ENDPOINT   (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
165 #define   UT_READ_CLASS_DEVICE          (UT_READ  | UT_CLASS | UT_DEVICE)
166 #define   UT_READ_CLASS_INTERFACE       (UT_READ  | UT_CLASS | UT_INTERFACE)
167 #define   UT_READ_CLASS_OTHER (UT_READ  | UT_CLASS | UT_OTHER)
168 #define   UT_READ_CLASS_ENDPOINT        (UT_READ  | UT_CLASS | UT_ENDPOINT)
169 #define   UT_WRITE_CLASS_DEVICE         (UT_WRITE | UT_CLASS | UT_DEVICE)
170 #define   UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
171 #define   UT_WRITE_CLASS_OTHER          (UT_WRITE | UT_CLASS | UT_OTHER)
172 #define   UT_WRITE_CLASS_ENDPOINT       (UT_WRITE | UT_CLASS | UT_ENDPOINT)
173 #define   UT_READ_VENDOR_DEVICE         (UT_READ  | UT_VENDOR | UT_DEVICE)
174 #define   UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
175 #define   UT_READ_VENDOR_OTHER          (UT_READ  | UT_VENDOR | UT_OTHER)
176 #define   UT_READ_VENDOR_ENDPOINT       (UT_READ  | UT_VENDOR | UT_ENDPOINT)
177 #define   UT_WRITE_VENDOR_DEVICE        (UT_WRITE | UT_VENDOR | UT_DEVICE)
178 #define   UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
179 #define   UT_WRITE_VENDOR_OTHER         (UT_WRITE | UT_VENDOR | UT_OTHER)
180 #define   UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
181 
182 /* Requests */
183 #define   UR_GET_STATUS                 0x00
184 #define   UR_CLEAR_FEATURE    0x01
185 #define   UR_SET_FEATURE                0x03
186 #define   UR_SET_ADDRESS                0x05
187 #define   UR_GET_DESCRIPTOR   0x06
188 #define   UDESC_DEVICE                  0x01
189 #define   UDESC_CONFIG                  0x02
190 #define   UDESC_STRING                  0x03
191 #define   USB_LANGUAGE_TABLE  0x00      /* language ID string index */
192 #define   UDESC_INTERFACE               0x04
193 #define   UDESC_ENDPOINT                0x05
194 #define   UDESC_DEVICE_QUALIFIER        0x06
195 #define   UDESC_OTHER_SPEED_CONFIGURATION 0x07
196 #define   UDESC_INTERFACE_POWER         0x08
197 #define   UDESC_OTG           0x09
198 #define   UDESC_DEBUG                   0x0A
199 #define   UDESC_IFACE_ASSOC   0x0B      /* interface association */
200 #define   UDESC_BOS           0x0F      /* binary object store */
201 #define   UDESC_DEVICE_CAPABILITY       0x10
202 #define   UDESC_CS_DEVICE               0x21      /* class specific */
203 #define   UDESC_CS_CONFIG               0x22
204 #define   UDESC_CS_STRING               0x23
205 #define   UDESC_CS_INTERFACE  0x24
206 #define   UDESC_CS_ENDPOINT   0x25
207 #define   UDESC_HUB           0x29
208 #define   UDESC_SS_HUB                  0x2A      /* super speed */
209 #define   UDESC_ENDPOINT_SS_COMP        0x30      /* super speed */
210 #define   UR_SET_DESCRIPTOR   0x07
211 #define   UR_GET_CONFIG                 0x08
212 #define   UR_SET_CONFIG                 0x09
213 #define   UR_GET_INTERFACE    0x0a
214 #define   UR_SET_INTERFACE    0x0b
215 #define   UR_SYNCH_FRAME                0x0c
216 #define   UR_SET_SEL                    0x30
217 #define   UR_ISOCH_DELAY                0x31
218 
219 /* HUB specific request */
220 #define   UR_GET_BUS_STATE    0x02
221 #define   UR_CLEAR_TT_BUFFER  0x08
222 #define   UR_RESET_TT                   0x09
223 #define   UR_GET_TT_STATE               0x0a
224 #define   UR_STOP_TT                    0x0b
225 #define   UR_SET_AND_TEST               0x0c      /* USB 2.0 only */
226 #define   UR_SET_HUB_DEPTH    0x0c      /* USB 3.0 only */
227 #define   USB_SS_HUB_DEPTH_MAX          5
228 #define   UR_GET_PORT_ERR_COUNT         0x0d
229 
230 /* Feature numbers */
231 #define   UF_ENDPOINT_HALT    0
232 #define   UF_DEVICE_REMOTE_WAKEUP       1
233 #define   UF_TEST_MODE                  2
234 #define   UF_U1_ENABLE                  0x30
235 #define   UF_U2_ENABLE                  0x31
236 #define   UF_LTM_ENABLE                 0x32
237 
238 /* HUB specific features */
239 #define   UHF_C_HUB_LOCAL_POWER         0
240 #define   UHF_C_HUB_OVER_CURRENT        1
241 #define   UHF_PORT_CONNECTION 0
242 #define   UHF_PORT_ENABLE               1
243 #define   UHF_PORT_SUSPEND    2
244 #define   UHF_PORT_OVER_CURRENT         3
245 #define   UHF_PORT_RESET                4
246 #define   UHF_PORT_LINK_STATE 5
247 #define   UHF_PORT_POWER                8
248 #define   UHF_PORT_LOW_SPEED  9
249 #define   UHF_PORT_L1                   10
250 #define   UHF_C_PORT_CONNECTION         16
251 #define   UHF_C_PORT_ENABLE   17
252 #define   UHF_C_PORT_SUSPEND  18
253 #define   UHF_C_PORT_OVER_CURRENT       19
254 #define   UHF_C_PORT_RESET    20
255 #define   UHF_PORT_TEST                 21
256 #define   UHF_PORT_INDICATOR  22
257 #define   UHF_C_PORT_L1                 23
258 
259 /* SuperSpeed HUB specific features */
260 #define   UHF_PORT_U1_TIMEOUT 23
261 #define   UHF_PORT_U2_TIMEOUT 24
262 #define   UHF_C_PORT_LINK_STATE         25
263 #define   UHF_C_PORT_CONFIG_ERROR       26
264 #define   UHF_PORT_REMOTE_WAKE_MASK     27
265 #define   UHF_BH_PORT_RESET   28
266 #define   UHF_C_BH_PORT_RESET 29
267 #define   UHF_FORCE_LINKPM_ACCEPT       30
268 
269 struct usb_descriptor {
270           uByte     bLength;
271           uByte     bDescriptorType;
272           uByte     bDescriptorSubtype;
273 } __packed;
274 typedef struct usb_descriptor usb_descriptor_t;
275 
276 struct usb_device_descriptor {
277           uByte     bLength;
278           uByte     bDescriptorType;
279           uWord     bcdUSB;
280 #define   UD_USB_2_0                    0x0200
281 #define   UD_USB_3_0                    0x0300
282 #define   UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
283 #define   UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
284           uByte     bDeviceClass;
285           uByte     bDeviceSubClass;
286           uByte     bDeviceProtocol;
287           uByte     bMaxPacketSize;
288           /* The fields below are not part of the initial descriptor. */
289           uWord     idVendor;
290           uWord     idProduct;
291           uWord     bcdDevice;
292           uByte     iManufacturer;
293           uByte     iProduct;
294           uByte     iSerialNumber;
295           uByte     bNumConfigurations;
296 } __packed;
297 typedef struct usb_device_descriptor usb_device_descriptor_t;
298 
299 /* Binary Device Object Store (BOS) */
300 struct usb_bos_descriptor {
301           uByte     bLength;
302           uByte     bDescriptorType;
303           uWord     wTotalLength;
304           uByte     bNumDeviceCaps;
305 } __packed;
306 typedef struct usb_bos_descriptor usb_bos_descriptor_t;
307 
308 /* Binary Device Object Store Capability */
309 struct usb_bos_cap_descriptor {
310           uByte     bLength;
311           uByte     bDescriptorType;
312           uByte     bDevCapabilityType;
313 #define   USB_DEVCAP_RESERVED 0x00
314 #define   USB_DEVCAP_WUSB               0x01
315 #define   USB_DEVCAP_USB2EXT  0x02
316 #define   USB_DEVCAP_SUPER_SPEED        0x03
317 #define   USB_DEVCAP_CONTAINER_ID       0x04
318           /* data ... */
319 } __packed;
320 typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
321 
322 struct usb_devcap_usb2ext_descriptor {
323           uByte     bLength;
324           uByte     bDescriptorType;
325           uByte     bDevCapabilityType;
326           uDWord    bmAttributes;
327 #define   USB_V2EXT_LPM (1U << 1)
328 #define   USB_V2EXT_BESL_SUPPORTED (1U << 2)
329 #define   USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
330 #define   USB_V2EXT_BESL_DEEP_VALID (1U << 4)
331 #define   USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
332 #define   USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
333 } __packed;
334 typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
335 
336 struct usb_devcap_ss_descriptor {
337           uByte     bLength;
338           uByte     bDescriptorType;
339           uByte     bDevCapabilityType;
340           uByte     bmAttributes;
341           uWord     wSpeedsSupported;
342           uByte     bFunctionalitySupport;
343           uByte     bU1DevExitLat;
344           uWord     wU2DevExitLat;
345 } __packed;
346 typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
347 
348 struct usb_devcap_container_id_descriptor {
349           uByte     bLength;
350           uByte     bDescriptorType;
351           uByte     bDevCapabilityType;
352           uByte     bReserved;
353           uByte     bContainerID;
354 } __packed;
355 typedef struct usb_devcap_container_id_descriptor
356                     usb_devcap_container_id_descriptor_t;
357 
358 /* Device class codes */
359 #define   UDCLASS_IN_INTERFACE          0x00
360 #define   UDCLASS_COMM                  0x02
361 #define   UDCLASS_HUB                   0x09
362 #define   UDSUBCLASS_HUB                0x00
363 #define   UDPROTO_FSHUB                 0x00
364 #define   UDPROTO_HSHUBSTT    0x01
365 #define   UDPROTO_HSHUBMTT    0x02
366 #define   UDPROTO_SSHUB                 0x03
367 #define   UDCLASS_DIAGNOSTIC  0xdc
368 #define   UDCLASS_WIRELESS    0xe0
369 #define   UDSUBCLASS_RF                 0x01
370 #define   UDPROTO_BLUETOOTH   0x01
371 #define   UDCLASS_VENDOR                0xff
372 
373 struct usb_config_descriptor {
374           uByte     bLength;
375           uByte     bDescriptorType;
376           uWord     wTotalLength;
377           uByte     bNumInterface;
378           uByte     bConfigurationValue;
379 #define   USB_UNCONFIG_NO 0
380           uByte     iConfiguration;
381           uByte     bmAttributes;
382 #define   UC_BUS_POWERED                0x80
383 #define   UC_SELF_POWERED               0x40
384 #define   UC_REMOTE_WAKEUP    0x20
385           uByte     bMaxPower;                    /* max current in 2 mA units */
386 #define   UC_POWER_FACTOR 2
387 } __packed;
388 typedef struct usb_config_descriptor usb_config_descriptor_t;
389 
390 struct usb_interface_descriptor {
391           uByte     bLength;
392           uByte     bDescriptorType;
393           uByte     bInterfaceNumber;
394           uByte     bAlternateSetting;
395           uByte     bNumEndpoints;
396           uByte     bInterfaceClass;
397           uByte     bInterfaceSubClass;
398           uByte     bInterfaceProtocol;
399           uByte     iInterface;
400 } __packed;
401 typedef struct usb_interface_descriptor usb_interface_descriptor_t;
402 
403 struct usb_interface_assoc_descriptor {
404           uByte     bLength;
405           uByte     bDescriptorType;
406           uByte     bFirstInterface;
407           uByte     bInterfaceCount;
408           uByte     bFunctionClass;
409           uByte     bFunctionSubClass;
410           uByte     bFunctionProtocol;
411           uByte     iFunction;
412 } __packed;
413 typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
414 
415 /* Interface class codes */
416 #define   UICLASS_UNSPEC                0x00
417 #define   UICLASS_AUDIO                 0x01      /* audio */
418 #define   UISUBCLASS_AUDIOCONTROL       1
419 #define   UISUBCLASS_AUDIOSTREAM                  2
420 #define   UISUBCLASS_MIDISTREAM                   3
421 
422 #define   UICLASS_CDC                   0x02      /* communication */
423 #define   UISUBCLASS_DIRECT_LINE_CONTROL_MODEL    1
424 #define   UISUBCLASS_ABSTRACT_CONTROL_MODEL       2
425 #define   UISUBCLASS_TELEPHONE_CONTROL_MODEL      3
426 #define   UISUBCLASS_MULTICHANNEL_CONTROL_MODEL   4
427 #define   UISUBCLASS_CAPI_CONTROLMODEL            5
428 #define   UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
429 #define   UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
430 #define   UISUBCLASS_WIRELESS_HANDSET_CM 8
431 #define   UISUBCLASS_DEVICE_MGMT 9
432 #define   UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
433 #define   UISUBCLASS_OBEX 11
434 #define   UISUBCLASS_ETHERNET_EMULATION_MODEL 12
435 #define   UISUBCLASS_NETWORK_CONTROL_MODEL 13
436 
437 #define   UIPROTO_CDC_NONE              0
438 #define   UIPROTO_CDC_AT                          1
439 
440 #define   UICLASS_HID                   0x03
441 #define   UISUBCLASS_BOOT               1
442 #define   UIPROTO_BOOT_KEYBOARD         1
443 #define   UIPROTO_MOUSE                 2
444 
445 #define   UICLASS_PHYSICAL    0x05
446 #define   UICLASS_IMAGE                 0x06
447 #define   UISUBCLASS_SIC                1         /* still image class */
448 #define   UICLASS_PRINTER               0x07
449 #define   UISUBCLASS_PRINTER  1
450 #define   UIPROTO_PRINTER_UNI 1
451 #define   UIPROTO_PRINTER_BI  2
452 #define   UIPROTO_PRINTER_1284          3
453 
454 #define   UICLASS_MASS                  0x08
455 #define   UISUBCLASS_RBC                1
456 #define   UISUBCLASS_SFF8020I 2
457 #define   UISUBCLASS_QIC157   3
458 #define   UISUBCLASS_UFI                4
459 #define   UISUBCLASS_SFF8070I 5
460 #define   UISUBCLASS_SCSI               6
461 #define   UIPROTO_MASS_CBI_I  0
462 #define   UIPROTO_MASS_CBI    1
463 #define   UIPROTO_MASS_BBB_OLD          2         /* Not in the spec anymore */
464 #define   UIPROTO_MASS_BBB    80        /* 'P' for the Iomega Zip drive */
465 
466 #define   UICLASS_HUB                   0x09
467 #define   UISUBCLASS_HUB                0
468 #define   UIPROTO_FSHUB                 0
469 #define   UIPROTO_HSHUBSTT    0         /* Yes, same as previous */
470 #define   UIPROTO_HSHUBMTT    1
471 
472 #define   UICLASS_CDC_DATA    0x0a
473 #define   UISUBCLASS_DATA               0x00
474 #define   UIPROTO_DATA_ISDNBRI                    0x30      /* Physical iface */
475 #define   UIPROTO_DATA_HDLC             0x31      /* HDLC */
476 #define   UIPROTO_DATA_TRANSPARENT      0x32      /* Transparent */
477 #define   UIPROTO_DATA_Q921M            0x50      /* Management for Q921 */
478 #define   UIPROTO_DATA_Q921             0x51      /* Data for Q921 */
479 #define   UIPROTO_DATA_Q921TM           0x52      /* TEI multiplexer for Q921 */
480 #define   UIPROTO_DATA_V42BIS           0x90      /* Data compression */
481 #define   UIPROTO_DATA_Q931             0x91      /* Euro-ISDN */
482 #define   UIPROTO_DATA_V120             0x92      /* V.24 rate adaption */
483 #define   UIPROTO_DATA_CAPI             0x93      /* CAPI 2.0 commands */
484 #define   UIPROTO_DATA_HOST_BASED                 0xfd      /* Host based driver */
485 #define   UIPROTO_DATA_PUF              0xfe      /* see Prot. Unit Func. Desc. */
486 #define   UIPROTO_DATA_VENDOR           0xff      /* Vendor specific */
487 #define   UIPROTO_DATA_NCM              0x01      /* Network Control Model */
488 
489 #define   UICLASS_SMARTCARD   0x0b
490 #define   UICLASS_FIRM_UPD    0x0c
491 #define   UICLASS_SECURITY    0x0d
492 #define   UICLASS_DIAGNOSTIC  0xdc
493 #define   UICLASS_WIRELESS    0xe0
494 #define   UISUBCLASS_RF                           0x01
495 #define   UIPROTO_BLUETOOTH             0x01
496 #define   UIPROTO_RNDIS                           0x03
497 
498 #define   UICLASS_IAD                   0xEF      /* Interface Association Descriptor */
499 #define   UISUBCLASS_SYNC                         0x01
500 #define   UIPROTO_ACTIVESYNC            0x01
501 
502 #define   UICLASS_APPL_SPEC   0xfe
503 #define   UISUBCLASS_FIRMWARE_DOWNLOAD  1
504 #define   UISUBCLASS_IRDA                         2
505 #define   UIPROTO_IRDA                            0
506 
507 #define   UICLASS_VENDOR                0xff
508 #define   UISUBCLASS_XBOX360_CONTROLLER 0x5d
509 #define   UIPROTO_XBOX360_GAMEPAD       0x01
510 
511 struct usb_endpoint_descriptor {
512           uByte     bLength;
513           uByte     bDescriptorType;
514           uByte     bEndpointAddress;
515 #define   UE_GET_DIR(a)       ((a) & 0x80)
516 #define   UE_SET_DIR(a,d)     ((a) | (((d)&1) << 7))
517 #define   UE_DIR_IN 0x80                /* IN-token endpoint, fixed */
518 #define   UE_DIR_OUT          0x00                /* OUT-token endpoint, fixed */
519 #define   UE_DIR_RX 0xfd                /* for internal use only! */
520 #define   UE_DIR_TX 0xfe                /* for internal use only! */
521 #define   UE_DIR_ANY          0xff                /* for internal use only! */
522 #define   UE_ADDR             0x0f
523 #define   UE_ADDR_ANY         0xff                /* for internal use only! */
524 #define   UE_GET_ADDR(a)      ((a) & UE_ADDR)
525           uByte     bmAttributes;
526 #define   UE_XFERTYPE         0x03
527 #define   UE_CONTROL          0x00
528 #define   UE_ISOCHRONOUS      0x01
529 #define   UE_BULK   0x02
530 #define   UE_INTERRUPT        0x03
531 #define   UE_BULK_INTR        0xfe                /* for internal use only! */
532 #define   UE_TYPE_ANY         0xff                /* for internal use only! */
533 #define   UE_GET_XFERTYPE(a)  ((a) & UE_XFERTYPE)
534 #define   UE_ISO_TYPE         0x0c
535 #define   UE_ISO_ASYNC        0x04
536 #define   UE_ISO_ADAPT        0x08
537 #define   UE_ISO_SYNC         0x0c
538 #define   UE_GET_ISO_TYPE(a)  ((a) & UE_ISO_TYPE)
539           uWord     wMaxPacketSize;
540 #define   UE_ZERO_MPS 0xFFFF            /* for internal use only */
541           uByte     bInterval;
542 } __packed;
543 typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
544 
545 struct usb_endpoint_ss_comp_descriptor {
546           uByte     bLength;
547           uByte     bDescriptorType;
548           uByte     bMaxBurst;
549           uByte     bmAttributes;
550 #define   UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
551 #define   UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
552           uWord     wBytesPerInterval;
553 } __packed;
554 typedef struct usb_endpoint_ss_comp_descriptor
555                     usb_endpoint_ss_comp_descriptor_t;
556 
557 struct usb_string_descriptor {
558           uByte     bLength;
559           uByte     bDescriptorType;
560           uWord     bString[126];
561           uByte     bUnused;
562 } __packed;
563 typedef struct usb_string_descriptor usb_string_descriptor_t;
564 
565 #define   USB_MAKE_STRING_DESC(m,name)  \
566 static const struct {                             \
567   uByte bLength;                        \
568   uByte bDescriptorType;                \
569   uByte bData[sizeof((uint8_t []){m})]; \
570 } __packed name = {                     \
571   .bLength = sizeof(name),              \
572   .bDescriptorType = UDESC_STRING,      \
573   .bData = { m },                       \
574 }
575 
576 struct usb_string_lang {
577           uByte bLength;
578           uByte bDescriptorType;
579           uByte bData[2];
580 } __packed;
581 typedef struct usb_string_lang usb_string_lang_t;
582 
583 struct usb_hub_descriptor {
584           uByte     bDescLength;
585           uByte     bDescriptorType;
586           uByte     bNbrPorts;
587           uWord     wHubCharacteristics;
588 #define   UHD_PWR                       0x0003
589 #define   UHD_PWR_GANGED                0x0000
590 #define   UHD_PWR_INDIVIDUAL  0x0001
591 #define   UHD_PWR_NO_SWITCH   0x0002
592 #define   UHD_COMPOUND                  0x0004
593 #define   UHD_OC                        0x0018
594 #define   UHD_OC_GLOBAL                 0x0000
595 #define   UHD_OC_INDIVIDUAL   0x0008
596 #define   UHD_OC_NONE                   0x0010
597 #define   UHD_TT_THINK                  0x0060
598 #define   UHD_TT_THINK_8                0x0000
599 #define   UHD_TT_THINK_16               0x0020
600 #define   UHD_TT_THINK_24               0x0040
601 #define   UHD_TT_THINK_32               0x0060
602 #define   UHD_PORT_IND                  0x0080
603           uByte     bPwrOn2PwrGood;               /* delay in 2 ms units */
604 #define   UHD_PWRON_FACTOR 2
605           uByte     bHubContrCurrent;
606           uByte     DeviceRemovable[32];          /* max 255 ports */
607 #define   UHD_NOT_REMOV(desc, i) \
608     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
609           uByte     PortPowerCtrlMask[1];         /* deprecated */
610 } __packed;
611 typedef struct usb_hub_descriptor usb_hub_descriptor_t;
612 
613 struct usb_hub_ss_descriptor {
614           uByte     bLength;
615           uByte     bDescriptorType;
616           uByte     bNbrPorts;
617           uWord     wHubCharacteristics;
618           uByte     bPwrOn2PwrGood;               /* delay in 2 ms units */
619           uByte     bHubContrCurrent;
620           uByte     bHubHdrDecLat;
621           uWord     wHubDelay;
622           uByte     DeviceRemovable[32];          /* max 255 ports */
623 } __packed;
624 typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
625 
626 /* minimum HUB descriptor (8-ports maximum) */
627 struct usb_hub_descriptor_min {
628           uByte     bDescLength;
629           uByte     bDescriptorType;
630           uByte     bNbrPorts;
631           uWord     wHubCharacteristics;
632           uByte     bPwrOn2PwrGood;
633           uByte     bHubContrCurrent;
634           uByte     DeviceRemovable[1];
635           uByte     PortPowerCtrlMask[1];
636 } __packed;
637 typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
638 
639 struct usb_device_qualifier {
640           uByte     bLength;
641           uByte     bDescriptorType;
642           uWord     bcdUSB;
643           uByte     bDeviceClass;
644           uByte     bDeviceSubClass;
645           uByte     bDeviceProtocol;
646           uByte     bMaxPacketSize0;
647           uByte     bNumConfigurations;
648           uByte     bReserved;
649 } __packed;
650 typedef struct usb_device_qualifier usb_device_qualifier_t;
651 
652 struct usb_otg_descriptor {
653           uByte     bLength;
654           uByte     bDescriptorType;
655           uByte     bmAttributes;
656 #define   UOTG_SRP  0x01
657 #define   UOTG_HNP  0x02
658 } __packed;
659 typedef struct usb_otg_descriptor usb_otg_descriptor_t;
660 
661 /* OTG feature selectors */
662 #define   UOTG_B_HNP_ENABLE   3
663 #define   UOTG_A_HNP_SUPPORT  4
664 #define   UOTG_A_ALT_HNP_SUPPORT        5
665 
666 struct usb_status {
667           uWord     wStatus;
668 /* Device status flags */
669 #define   UDS_SELF_POWERED              0x0001
670 #define   UDS_REMOTE_WAKEUP             0x0002
671 /* Endpoint status flags */
672 #define   UES_HALT                      0x0001
673 } __packed;
674 typedef struct usb_status usb_status_t;
675 
676 struct usb_hub_status {
677           uWord     wHubStatus;
678 #define   UHS_LOCAL_POWER                         0x0001
679 #define   UHS_OVER_CURRENT              0x0002
680           uWord     wHubChange;
681 } __packed;
682 typedef struct usb_hub_status usb_hub_status_t;
683 
684 struct usb_port_status {
685           uWord     wPortStatus;
686 #define   UPS_CURRENT_CONNECT_STATUS    0x0001
687 #define   UPS_PORT_ENABLED              0x0002
688 #define   UPS_SUSPEND                             0x0004
689 #define   UPS_OVERCURRENT_INDICATOR     0x0008
690 #define   UPS_RESET                     0x0010
691 #define   UPS_PORT_L1                             0x0020    /* USB 2.0 only */
692 /* The link-state bits are valid for Super-Speed USB HUBs */
693 #define   UPS_PORT_LINK_STATE_GET(x)    (((x) >> 5) & 0xF)
694 #define   UPS_PORT_LINK_STATE_SET(x)    (((x) & 0xF) << 5)
695 #define   UPS_PORT_LS_U0                0x00
696 #define   UPS_PORT_LS_U1                0x01
697 #define   UPS_PORT_LS_U2                0x02
698 #define   UPS_PORT_LS_U3                0x03
699 #define   UPS_PORT_LS_SS_DIS  0x04
700 #define   UPS_PORT_LS_RX_DET  0x05
701 #define   UPS_PORT_LS_SS_INA  0x06
702 #define   UPS_PORT_LS_POLL    0x07
703 #define   UPS_PORT_LS_RECOVER 0x08
704 #define   UPS_PORT_LS_HOT_RST 0x09
705 #define   UPS_PORT_LS_COMP_MODE         0x0A
706 #define   UPS_PORT_LS_LOOPBACK          0x0B
707 #define   UPS_PORT_LS_RESUME  0x0F
708 #define   UPS_PORT_POWER                          0x0100
709 #define   UPS_PORT_POWER_SS             0x0200    /* super-speed only */
710 #define   UPS_LOW_SPEED                           0x0200
711 #define   UPS_HIGH_SPEED                          0x0400
712 #define   UPS_OTHER_SPEED                         0x0600    /* currently FreeBSD specific */
713 #define   UPS_PORT_TEST                           0x0800
714 #define   UPS_PORT_INDICATOR            0x1000
715 #define   UPS_PORT_MODE_DEVICE                    0x8000    /* currently FreeBSD specific */
716           uWord     wPortChange;
717 #define   UPS_C_CONNECT_STATUS                    0x0001
718 #define   UPS_C_PORT_ENABLED            0x0002
719 #define   UPS_C_SUSPEND                           0x0004
720 #define   UPS_C_OVERCURRENT_INDICATOR   0x0008
721 #define   UPS_C_PORT_RESET              0x0010
722 #define   UPS_C_PORT_L1                           0x0020    /* USB 2.0 only */
723 #define   UPS_C_BH_PORT_RESET           0x0020    /* USB 3.0 only */
724 #define   UPS_C_PORT_LINK_STATE                   0x0040
725 #define   UPS_C_PORT_CONFIG_ERROR                 0x0080
726 } __packed;
727 typedef struct usb_port_status usb_port_status_t;
728 
729 /*
730  * The "USB_SPEED" macros defines all the supported USB speeds.
731  */
732 enum usb_dev_speed {
733           USB_SPEED_VARIABLE,
734           USB_SPEED_LOW,
735           USB_SPEED_FULL,
736           USB_SPEED_HIGH,
737           USB_SPEED_SUPER,
738 };
739 #define   USB_SPEED_MAX       (USB_SPEED_SUPER+1)
740 
741 /*
742  * The "USB_REV" macros defines all the supported USB revisions.
743  */
744 enum usb_revision {
745           USB_REV_UNKNOWN,
746           USB_REV_PRE_1_0,
747           USB_REV_1_0,
748           USB_REV_1_1,
749           USB_REV_2_0,
750           USB_REV_2_5,
751           USB_REV_3_0
752 };
753 #define   USB_REV_MAX         (USB_REV_3_0+1)
754 
755 /*
756  * Supported host controller modes.
757  */
758 enum usb_hc_mode {
759           USB_MODE_HOST,                /* initiates transfers */
760           USB_MODE_DEVICE,    /* bus transfer target */
761           USB_MODE_DUAL                 /* can be host or device */
762 };
763 #define   USB_MODE_MAX        (USB_MODE_DUAL+1)
764 
765 /*
766  * The "USB_STATE" enums define all the supported device states.
767  */
768 enum usb_dev_state {
769           USB_STATE_DETACHED,
770           USB_STATE_ATTACHED,
771           USB_STATE_POWERED,
772           USB_STATE_ADDRESSED,
773           USB_STATE_CONFIGURED,
774 };
775 #define   USB_STATE_MAX       (USB_STATE_CONFIGURED+1)
776 
777 /*
778  * The "USB_EP_MODE" macros define all the currently supported
779  * endpoint modes.
780  */
781 enum usb_ep_mode {
782           USB_EP_MODE_DEFAULT,
783           USB_EP_MODE_STREAMS,          /* USB3.0 specific */
784           USB_EP_MODE_HW_MASS_STORAGE,
785           USB_EP_MODE_HW_SERIAL,
786           USB_EP_MODE_HW_ETHERNET_CDC,
787           USB_EP_MODE_HW_ETHERNET_NCM,
788           USB_EP_MODE_MAX
789 };
790 #endif                                            /* _USB_STANDARD_H_ */
791