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