16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
25e1ddb48SDavid Howells /*
35e1ddb48SDavid Howells * This file holds USB constants and structures that are needed for
45e1ddb48SDavid Howells * USB device APIs. These are used by the USB device model, which is
55e1ddb48SDavid Howells * defined in chapter 9 of the USB 2.0 specification and in the
61e4c5742SAlan Stern * Wireless USB 1.0 spec (now defunct). Linux has several APIs in C that
75e1ddb48SDavid Howells * need these:
85e1ddb48SDavid Howells *
95e1ddb48SDavid Howells * - the master/host side Linux-USB kernel driver API;
105e1ddb48SDavid Howells * - the "usbfs" user space API; and
115e1ddb48SDavid Howells * - the Linux "gadget" slave/device/peripheral side driver API.
125e1ddb48SDavid Howells *
135e1ddb48SDavid Howells * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
145e1ddb48SDavid Howells * act either as a USB master/host or as a USB slave/device. That means
155e1ddb48SDavid Howells * the master and slave side APIs benefit from working well together.
165e1ddb48SDavid Howells *
175e1ddb48SDavid Howells * Note all descriptors are declared '__attribute__((packed))' so that:
185e1ddb48SDavid Howells *
195e1ddb48SDavid Howells * [a] they never get padded, either internally (USB spec writers
205e1ddb48SDavid Howells * probably handled that) or externally;
215e1ddb48SDavid Howells *
225e1ddb48SDavid Howells * [b] so that accessing bigger-than-a-bytes fields will never
235e1ddb48SDavid Howells * generate bus errors on any platform, even when the location of
245e1ddb48SDavid Howells * its descriptor inside a bundle isn't "naturally aligned", and
255e1ddb48SDavid Howells *
265e1ddb48SDavid Howells * [c] for consistency, removing all doubt even when it appears to
275e1ddb48SDavid Howells * someone that the two other points are non-issues for that
285e1ddb48SDavid Howells * particular descriptor type.
295e1ddb48SDavid Howells */
305e1ddb48SDavid Howells
315e1ddb48SDavid Howells #ifndef _UAPI__LINUX_USB_CH9_H
325e1ddb48SDavid Howells #define _UAPI__LINUX_USB_CH9_H
335e1ddb48SDavid Howells
345e1ddb48SDavid Howells #include <linux/types.h> /* __u8 etc */
355e1ddb48SDavid Howells #include <asm/byteorder.h> /* le16_to_cpu */
365e1ddb48SDavid Howells
375e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
385e1ddb48SDavid Howells
395e1ddb48SDavid Howells /* CONTROL REQUEST SUPPORT */
405e1ddb48SDavid Howells
415e1ddb48SDavid Howells /*
425e1ddb48SDavid Howells * USB directions
435e1ddb48SDavid Howells *
445e1ddb48SDavid Howells * This bit flag is used in endpoint descriptors' bEndpointAddress field.
455e1ddb48SDavid Howells * It's also one of three fields in control requests bRequestType.
465e1ddb48SDavid Howells */
475e1ddb48SDavid Howells #define USB_DIR_OUT 0 /* to device */
485e1ddb48SDavid Howells #define USB_DIR_IN 0x80 /* to host */
495e1ddb48SDavid Howells
505e1ddb48SDavid Howells /*
515e1ddb48SDavid Howells * USB types, the second of three bRequestType fields
525e1ddb48SDavid Howells */
535e1ddb48SDavid Howells #define USB_TYPE_MASK (0x03 << 5)
545e1ddb48SDavid Howells #define USB_TYPE_STANDARD (0x00 << 5)
555e1ddb48SDavid Howells #define USB_TYPE_CLASS (0x01 << 5)
565e1ddb48SDavid Howells #define USB_TYPE_VENDOR (0x02 << 5)
575e1ddb48SDavid Howells #define USB_TYPE_RESERVED (0x03 << 5)
585e1ddb48SDavid Howells
595e1ddb48SDavid Howells /*
605e1ddb48SDavid Howells * USB recipients, the third of three bRequestType fields
615e1ddb48SDavid Howells */
625e1ddb48SDavid Howells #define USB_RECIP_MASK 0x1f
635e1ddb48SDavid Howells #define USB_RECIP_DEVICE 0x00
645e1ddb48SDavid Howells #define USB_RECIP_INTERFACE 0x01
655e1ddb48SDavid Howells #define USB_RECIP_ENDPOINT 0x02
665e1ddb48SDavid Howells #define USB_RECIP_OTHER 0x03
675e1ddb48SDavid Howells /* From Wireless USB 1.0 */
685e1ddb48SDavid Howells #define USB_RECIP_PORT 0x04
695e1ddb48SDavid Howells #define USB_RECIP_RPIPE 0x05
705e1ddb48SDavid Howells
715e1ddb48SDavid Howells /*
725e1ddb48SDavid Howells * Standard requests, for the bRequest field of a SETUP packet.
735e1ddb48SDavid Howells *
745e1ddb48SDavid Howells * These are qualified by the bRequestType field, so that for example
755e1ddb48SDavid Howells * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
765e1ddb48SDavid Howells * by a GET_STATUS request.
775e1ddb48SDavid Howells */
785e1ddb48SDavid Howells #define USB_REQ_GET_STATUS 0x00
795e1ddb48SDavid Howells #define USB_REQ_CLEAR_FEATURE 0x01
805e1ddb48SDavid Howells #define USB_REQ_SET_FEATURE 0x03
815e1ddb48SDavid Howells #define USB_REQ_SET_ADDRESS 0x05
825e1ddb48SDavid Howells #define USB_REQ_GET_DESCRIPTOR 0x06
835e1ddb48SDavid Howells #define USB_REQ_SET_DESCRIPTOR 0x07
845e1ddb48SDavid Howells #define USB_REQ_GET_CONFIGURATION 0x08
855e1ddb48SDavid Howells #define USB_REQ_SET_CONFIGURATION 0x09
865e1ddb48SDavid Howells #define USB_REQ_GET_INTERFACE 0x0A
875e1ddb48SDavid Howells #define USB_REQ_SET_INTERFACE 0x0B
885e1ddb48SDavid Howells #define USB_REQ_SYNCH_FRAME 0x0C
895e1ddb48SDavid Howells #define USB_REQ_SET_SEL 0x30
905e1ddb48SDavid Howells #define USB_REQ_SET_ISOCH_DELAY 0x31
915e1ddb48SDavid Howells
925e1ddb48SDavid Howells #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
935e1ddb48SDavid Howells #define USB_REQ_GET_ENCRYPTION 0x0E
945e1ddb48SDavid Howells #define USB_REQ_RPIPE_ABORT 0x0E
955e1ddb48SDavid Howells #define USB_REQ_SET_HANDSHAKE 0x0F
965e1ddb48SDavid Howells #define USB_REQ_RPIPE_RESET 0x0F
975e1ddb48SDavid Howells #define USB_REQ_GET_HANDSHAKE 0x10
985e1ddb48SDavid Howells #define USB_REQ_SET_CONNECTION 0x11
995e1ddb48SDavid Howells #define USB_REQ_SET_SECURITY_DATA 0x12
1005e1ddb48SDavid Howells #define USB_REQ_GET_SECURITY_DATA 0x13
1015e1ddb48SDavid Howells #define USB_REQ_SET_WUSB_DATA 0x14
1025e1ddb48SDavid Howells #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
1035e1ddb48SDavid Howells #define USB_REQ_LOOPBACK_DATA_READ 0x16
1045e1ddb48SDavid Howells #define USB_REQ_SET_INTERFACE_DS 0x17
1055e1ddb48SDavid Howells
106e1669f4aSOliver Neukum /* specific requests for USB Power Delivery */
107e1669f4aSOliver Neukum #define USB_REQ_GET_PARTNER_PDO 20
108e1669f4aSOliver Neukum #define USB_REQ_GET_BATTERY_STATUS 21
109e1669f4aSOliver Neukum #define USB_REQ_SET_PDO 22
110e1669f4aSOliver Neukum #define USB_REQ_GET_VDM 23
111e1669f4aSOliver Neukum #define USB_REQ_SEND_VDM 24
112e1669f4aSOliver Neukum
1135e1ddb48SDavid Howells /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command,
1145e1ddb48SDavid Howells * used by hubs to put ports into a new L1 suspend state, except that it
1155e1ddb48SDavid Howells * forgot to define its number ...
1165e1ddb48SDavid Howells */
1175e1ddb48SDavid Howells
1185e1ddb48SDavid Howells /*
1195e1ddb48SDavid Howells * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
1205e1ddb48SDavid Howells * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
1215e1ddb48SDavid Howells * are at most sixteen features of each type.) Hubs may also support a
1225e1ddb48SDavid Howells * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
1235e1ddb48SDavid Howells */
1245e1ddb48SDavid Howells #define USB_DEVICE_SELF_POWERED 0 /* (read only) */
1255e1ddb48SDavid Howells #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
1265e1ddb48SDavid Howells #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
1275e1ddb48SDavid Howells #define USB_DEVICE_BATTERY 2 /* (wireless) */
1285e1ddb48SDavid Howells #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
1295e1ddb48SDavid Howells #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
1305e1ddb48SDavid Howells #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
1315e1ddb48SDavid Howells #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
1325e1ddb48SDavid Howells #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
1335e1ddb48SDavid Howells
1345e1ddb48SDavid Howells /*
1355e1ddb48SDavid Howells * Test Mode Selectors
1365e1ddb48SDavid Howells * See USB 2.0 spec Table 9-7
1375e1ddb48SDavid Howells */
13862fb45d3SGreg Kroah-Hartman #define USB_TEST_J 1
13962fb45d3SGreg Kroah-Hartman #define USB_TEST_K 2
14062fb45d3SGreg Kroah-Hartman #define USB_TEST_SE0_NAK 3
14162fb45d3SGreg Kroah-Hartman #define USB_TEST_PACKET 4
14262fb45d3SGreg Kroah-Hartman #define USB_TEST_FORCE_ENABLE 5
1435e1ddb48SDavid Howells
1446f27f4f9SFelipe Balbi /* Status Type */
1456f27f4f9SFelipe Balbi #define USB_STATUS_TYPE_STANDARD 0
1466f27f4f9SFelipe Balbi #define USB_STATUS_TYPE_PTM 1
1476f27f4f9SFelipe Balbi
1485e1ddb48SDavid Howells /*
1495e1ddb48SDavid Howells * New Feature Selectors as added by USB 3.0
150197c58f6SHuang Rui * See USB 3.0 spec Table 9-7
1515e1ddb48SDavid Howells */
1525e1ddb48SDavid Howells #define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */
1535e1ddb48SDavid Howells #define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */
1545e1ddb48SDavid Howells #define USB_DEVICE_LTM_ENABLE 50 /* dev may send LTM */
1555e1ddb48SDavid Howells #define USB_INTRF_FUNC_SUSPEND 0 /* function suspend */
1565e1ddb48SDavid Howells
1575e1ddb48SDavid Howells #define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
1585e1ddb48SDavid Howells /*
159197c58f6SHuang Rui * Suspend Options, Table 9-8 USB 3.0 spec
1605e1ddb48SDavid Howells */
1615e1ddb48SDavid Howells #define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
1625e1ddb48SDavid Howells #define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))
1635e1ddb48SDavid Howells
16454a3ac0cSLan Tianyu /*
16554a3ac0cSLan Tianyu * Interface status, Figure 9-5 USB 3.0 spec
16654a3ac0cSLan Tianyu */
16754a3ac0cSLan Tianyu #define USB_INTRF_STAT_FUNC_RW_CAP 1
16854a3ac0cSLan Tianyu #define USB_INTRF_STAT_FUNC_RW 2
16954a3ac0cSLan Tianyu
1705e1ddb48SDavid Howells #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
1715e1ddb48SDavid Howells
1725e1ddb48SDavid Howells /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */
1735e1ddb48SDavid Howells #define USB_DEV_STAT_U1_ENABLED 2 /* transition into U1 state */
1745e1ddb48SDavid Howells #define USB_DEV_STAT_U2_ENABLED 3 /* transition into U2 state */
1755e1ddb48SDavid Howells #define USB_DEV_STAT_LTM_ENABLED 4 /* Latency tolerance messages */
1765e1ddb48SDavid Howells
177351e67abSOliver Neukum /*
178351e67abSOliver Neukum * Feature selectors from Table 9-8 USB Power Delivery spec
179351e67abSOliver Neukum */
180351e67abSOliver Neukum #define USB_DEVICE_BATTERY_WAKE_MASK 40
181351e67abSOliver Neukum #define USB_DEVICE_OS_IS_PD_AWARE 41
182351e67abSOliver Neukum #define USB_DEVICE_POLICY_MODE 42
183351e67abSOliver Neukum #define USB_PORT_PR_SWAP 43
184351e67abSOliver Neukum #define USB_PORT_GOTO_MIN 44
185351e67abSOliver Neukum #define USB_PORT_RETURN_POWER 45
186351e67abSOliver Neukum #define USB_PORT_ACCEPT_PD_REQUEST 46
187351e67abSOliver Neukum #define USB_PORT_REJECT_PD_REQUEST 47
188351e67abSOliver Neukum #define USB_PORT_PORT_PD_RESET 48
189351e67abSOliver Neukum #define USB_PORT_C_PORT_PD_CHANGE 49
190351e67abSOliver Neukum #define USB_PORT_CABLE_PD_RESET 50
191351e67abSOliver Neukum #define USB_DEVICE_CHARGING_POLICY 54
192351e67abSOliver Neukum
1935e1ddb48SDavid Howells /**
1945e1ddb48SDavid Howells * struct usb_ctrlrequest - SETUP data for a USB device control request
1955e1ddb48SDavid Howells * @bRequestType: matches the USB bmRequestType field
1965e1ddb48SDavid Howells * @bRequest: matches the USB bRequest field
1975e1ddb48SDavid Howells * @wValue: matches the USB wValue field (le16 byte order)
1985e1ddb48SDavid Howells * @wIndex: matches the USB wIndex field (le16 byte order)
1995e1ddb48SDavid Howells * @wLength: matches the USB wLength field (le16 byte order)
2005e1ddb48SDavid Howells *
2015e1ddb48SDavid Howells * This structure is used to send control requests to a USB device. It matches
2025e1ddb48SDavid Howells * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the
2035e1ddb48SDavid Howells * USB spec for a fuller description of the different fields, and what they are
2045e1ddb48SDavid Howells * used for.
2055e1ddb48SDavid Howells *
2065e1ddb48SDavid Howells * Note that the driver for any interface can issue control requests.
2075e1ddb48SDavid Howells * For most devices, interfaces don't coordinate with each other, so
2085e1ddb48SDavid Howells * such requests may be made at any time.
2095e1ddb48SDavid Howells */
2105e1ddb48SDavid Howells struct usb_ctrlrequest {
2115e1ddb48SDavid Howells __u8 bRequestType;
2125e1ddb48SDavid Howells __u8 bRequest;
2135e1ddb48SDavid Howells __le16 wValue;
2145e1ddb48SDavid Howells __le16 wIndex;
2155e1ddb48SDavid Howells __le16 wLength;
2165e1ddb48SDavid Howells } __attribute__ ((packed));
2175e1ddb48SDavid Howells
2185e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
2195e1ddb48SDavid Howells
2205e1ddb48SDavid Howells /*
2215e1ddb48SDavid Howells * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
2225e1ddb48SDavid Howells * (rarely) accepted by SET_DESCRIPTOR.
2235e1ddb48SDavid Howells *
2245e1ddb48SDavid Howells * Note that all multi-byte values here are encoded in little endian
2255e1ddb48SDavid Howells * byte order "on the wire". Within the kernel and when exposed
2265e1ddb48SDavid Howells * through the Linux-USB APIs, they are not converted to cpu byte
2275e1ddb48SDavid Howells * order; it is the responsibility of the client code to do this.
2285e1ddb48SDavid Howells * The single exception is when device and configuration descriptors (but
22921470e32SMauro Carvalho Chehab * not other descriptors) are read from character devices
23021470e32SMauro Carvalho Chehab * (i.e. /dev/bus/usb/BBB/DDD);
2315e1ddb48SDavid Howells * in this case the fields are converted to host endianness by the kernel.
2325e1ddb48SDavid Howells */
2335e1ddb48SDavid Howells
2345e1ddb48SDavid Howells /*
2355e1ddb48SDavid Howells * Descriptor types ... USB 2.0 spec table 9.5
2365e1ddb48SDavid Howells */
2375e1ddb48SDavid Howells #define USB_DT_DEVICE 0x01
2385e1ddb48SDavid Howells #define USB_DT_CONFIG 0x02
2395e1ddb48SDavid Howells #define USB_DT_STRING 0x03
2405e1ddb48SDavid Howells #define USB_DT_INTERFACE 0x04
2415e1ddb48SDavid Howells #define USB_DT_ENDPOINT 0x05
2425e1ddb48SDavid Howells #define USB_DT_DEVICE_QUALIFIER 0x06
2435e1ddb48SDavid Howells #define USB_DT_OTHER_SPEED_CONFIG 0x07
2445e1ddb48SDavid Howells #define USB_DT_INTERFACE_POWER 0x08
2455e1ddb48SDavid Howells /* these are from a minor usb 2.0 revision (ECN) */
2465e1ddb48SDavid Howells #define USB_DT_OTG 0x09
2475e1ddb48SDavid Howells #define USB_DT_DEBUG 0x0a
2485e1ddb48SDavid Howells #define USB_DT_INTERFACE_ASSOCIATION 0x0b
2495e1ddb48SDavid Howells /* these are from the Wireless USB spec */
2505e1ddb48SDavid Howells #define USB_DT_SECURITY 0x0c
2515e1ddb48SDavid Howells #define USB_DT_KEY 0x0d
2525e1ddb48SDavid Howells #define USB_DT_ENCRYPTION_TYPE 0x0e
2535e1ddb48SDavid Howells #define USB_DT_BOS 0x0f
2545e1ddb48SDavid Howells #define USB_DT_DEVICE_CAPABILITY 0x10
2555e1ddb48SDavid Howells #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
2565e1ddb48SDavid Howells /* From the eUSB2 spec */
257c26cee81SDavid Sands #define USB_DT_EUSB2_ISOC_ENDPOINT_COMP 0x12
258c26cee81SDavid Sands /* From Wireless USB spec */
259c26cee81SDavid Sands #define USB_DT_WIRE_ADAPTER 0x21
2605e1ddb48SDavid Howells /* From USB Device Firmware Upgrade Specification, Revision 1.1 */
2615e1ddb48SDavid Howells #define USB_DT_DFU_FUNCTIONAL 0x21
2625e1ddb48SDavid Howells /* these are from the Wireless USB spec */
2635e1ddb48SDavid Howells #define USB_DT_RPIPE 0x22
2645e1ddb48SDavid Howells #define USB_DT_CS_RADIO_CONTROL 0x23
2655e1ddb48SDavid Howells /* From the T10 UAS specification */
266c8b1d897SMathias Nyman #define USB_DT_PIPE_USAGE 0x24
267c8b1d897SMathias Nyman /* From the USB 3.0 spec */
2685e1ddb48SDavid Howells #define USB_DT_SS_ENDPOINT_COMP 0x30
2695e1ddb48SDavid Howells /* From the USB 3.1 spec */
2705e1ddb48SDavid Howells #define USB_DT_SSP_ISOC_ENDPOINT_COMP 0x31
2715e1ddb48SDavid Howells
2725e1ddb48SDavid Howells /* Conventional codes for class-specific descriptors. The convention is
2735e1ddb48SDavid Howells * defined in the USB "Common Class" Spec (3.11). Individual class specs
2745e1ddb48SDavid Howells * are authoritative for their usage, not the "common class" writeup.
2755e1ddb48SDavid Howells */
2765e1ddb48SDavid Howells #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE)
2775e1ddb48SDavid Howells #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG)
2785e1ddb48SDavid Howells #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING)
2795e1ddb48SDavid Howells #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE)
2805e1ddb48SDavid Howells #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT)
2815e1ddb48SDavid Howells
2825e1ddb48SDavid Howells /* All standard descriptors have these 2 fields at the beginning */
2835e1ddb48SDavid Howells struct usb_descriptor_header {
2845e1ddb48SDavid Howells __u8 bLength;
2855e1ddb48SDavid Howells __u8 bDescriptorType;
2865e1ddb48SDavid Howells } __attribute__ ((packed));
2875e1ddb48SDavid Howells
2885e1ddb48SDavid Howells
2895e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
2905e1ddb48SDavid Howells
2915e1ddb48SDavid Howells /* USB_DT_DEVICE: Device descriptor */
2925e1ddb48SDavid Howells struct usb_device_descriptor {
2935e1ddb48SDavid Howells __u8 bLength;
2945e1ddb48SDavid Howells __u8 bDescriptorType;
2955e1ddb48SDavid Howells
2965e1ddb48SDavid Howells __le16 bcdUSB;
2975e1ddb48SDavid Howells __u8 bDeviceClass;
2985e1ddb48SDavid Howells __u8 bDeviceSubClass;
2995e1ddb48SDavid Howells __u8 bDeviceProtocol;
3005e1ddb48SDavid Howells __u8 bMaxPacketSize0;
3015e1ddb48SDavid Howells __le16 idVendor;
3025e1ddb48SDavid Howells __le16 idProduct;
3035e1ddb48SDavid Howells __le16 bcdDevice;
3045e1ddb48SDavid Howells __u8 iManufacturer;
3055e1ddb48SDavid Howells __u8 iProduct;
3065e1ddb48SDavid Howells __u8 iSerialNumber;
3075e1ddb48SDavid Howells __u8 bNumConfigurations;
3085e1ddb48SDavid Howells } __attribute__ ((packed));
3095e1ddb48SDavid Howells
3105e1ddb48SDavid Howells #define USB_DT_DEVICE_SIZE 18
3115e1ddb48SDavid Howells
3125e1ddb48SDavid Howells
3135e1ddb48SDavid Howells /*
3145e1ddb48SDavid Howells * Device and/or Interface Class codes
3155e1ddb48SDavid Howells * as found in bDeviceClass or bInterfaceClass
3165e1ddb48SDavid Howells * and defined by www.usb.org documents
3175e1ddb48SDavid Howells */
3185e1ddb48SDavid Howells #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
3195e1ddb48SDavid Howells #define USB_CLASS_AUDIO 1
3205e1ddb48SDavid Howells #define USB_CLASS_COMM 2
3215e1ddb48SDavid Howells #define USB_CLASS_HID 3
3225e1ddb48SDavid Howells #define USB_CLASS_PHYSICAL 5
3235e1ddb48SDavid Howells #define USB_CLASS_STILL_IMAGE 6
3245e1ddb48SDavid Howells #define USB_CLASS_PRINTER 7
3255e1ddb48SDavid Howells #define USB_CLASS_MASS_STORAGE 8
3265e1ddb48SDavid Howells #define USB_CLASS_HUB 9
3275e1ddb48SDavid Howells #define USB_CLASS_CDC_DATA 0x0a
3285e1ddb48SDavid Howells #define USB_CLASS_CSCID 0x0b /* chip+ smart card */
32903cc8353SRob Gill #define USB_CLASS_CONTENT_SEC 0x0d /* content security */
33003cc8353SRob Gill #define USB_CLASS_VIDEO 0x0e
33103cc8353SRob Gill #define USB_CLASS_WIRELESS_CONTROLLER 0xe0
33203cc8353SRob Gill #define USB_CLASS_PERSONAL_HEALTHCARE 0x0f
333*dcc35baaSJeremy Kerr #define USB_CLASS_AUDIO_VIDEO 0x10
3345e1ddb48SDavid Howells #define USB_CLASS_BILLBOARD 0x11
3355e1ddb48SDavid Howells #define USB_CLASS_USB_TYPE_C_BRIDGE 0x12
336c26cee81SDavid Sands #define USB_CLASS_MCTP 0x14
3375e1ddb48SDavid Howells #define USB_CLASS_MISC 0xef
338c26cee81SDavid Sands #define USB_CLASS_APP_SPEC 0xfe
3395e1ddb48SDavid Howells #define USB_SUBCLASS_DFU 0x01
3405e1ddb48SDavid Howells
3415e1ddb48SDavid Howells #define USB_CLASS_VENDOR_SPEC 0xff
3425e1ddb48SDavid Howells #define USB_SUBCLASS_VENDOR_SPEC 0xff
3435e1ddb48SDavid Howells
3445e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
3455e1ddb48SDavid Howells
3465e1ddb48SDavid Howells /* USB_DT_CONFIG: Configuration descriptor information.
3475e1ddb48SDavid Howells *
3485e1ddb48SDavid Howells * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
3495e1ddb48SDavid Howells * descriptor type is different. Highspeed-capable devices can look
3505e1ddb48SDavid Howells * different depending on what speed they're currently running. Only
3515e1ddb48SDavid Howells * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
3525e1ddb48SDavid Howells * descriptors.
3535e1ddb48SDavid Howells */
3545e1ddb48SDavid Howells struct usb_config_descriptor {
3555e1ddb48SDavid Howells __u8 bLength;
3565e1ddb48SDavid Howells __u8 bDescriptorType;
3575e1ddb48SDavid Howells
3585e1ddb48SDavid Howells __le16 wTotalLength;
3595e1ddb48SDavid Howells __u8 bNumInterfaces;
3605e1ddb48SDavid Howells __u8 bConfigurationValue;
3615e1ddb48SDavid Howells __u8 iConfiguration;
3625e1ddb48SDavid Howells __u8 bmAttributes;
3635e1ddb48SDavid Howells __u8 bMaxPower;
3645e1ddb48SDavid Howells } __attribute__ ((packed));
3655e1ddb48SDavid Howells
3665e1ddb48SDavid Howells #define USB_DT_CONFIG_SIZE 9
3675e1ddb48SDavid Howells
3685e1ddb48SDavid Howells /* from config descriptor bmAttributes */
3695e1ddb48SDavid Howells #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */
3705e1ddb48SDavid Howells #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */
3715e1ddb48SDavid Howells #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */
3725e1ddb48SDavid Howells #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */
37381c74628SMacpaul Lin
37481c74628SMacpaul Lin /*-------------------------------------------------------------------------*/
37581c74628SMacpaul Lin
3765e1ddb48SDavid Howells /* USB String descriptors can contain at most 126 characters. */
3775e1ddb48SDavid Howells #define USB_MAX_STRING_LEN 126
3785e1ddb48SDavid Howells
3795e1ddb48SDavid Howells /* USB_DT_STRING: String descriptor */
3805e1ddb48SDavid Howells struct usb_string_descriptor {
38109b69dd4SKees Cook __u8 bLength;
38209b69dd4SKees Cook __u8 bDescriptorType;
38309b69dd4SKees Cook
38409b69dd4SKees Cook union {
3855e1ddb48SDavid Howells __le16 legacy_padding;
3865e1ddb48SDavid Howells __DECLARE_FLEX_ARRAY(__le16, wData); /* UTF-16LE encoded */
3875e1ddb48SDavid Howells };
3885e1ddb48SDavid Howells } __attribute__ ((packed));
3895e1ddb48SDavid Howells
3905e1ddb48SDavid Howells /* note that "string" zero is special, it holds language codes that
3915e1ddb48SDavid Howells * the device supports, not Unicode characters.
3925e1ddb48SDavid Howells */
3935e1ddb48SDavid Howells
3945e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
3955e1ddb48SDavid Howells
3965e1ddb48SDavid Howells /* USB_DT_INTERFACE: Interface descriptor */
3975e1ddb48SDavid Howells struct usb_interface_descriptor {
3985e1ddb48SDavid Howells __u8 bLength;
3995e1ddb48SDavid Howells __u8 bDescriptorType;
4005e1ddb48SDavid Howells
4015e1ddb48SDavid Howells __u8 bInterfaceNumber;
4025e1ddb48SDavid Howells __u8 bAlternateSetting;
4035e1ddb48SDavid Howells __u8 bNumEndpoints;
4045e1ddb48SDavid Howells __u8 bInterfaceClass;
4055e1ddb48SDavid Howells __u8 bInterfaceSubClass;
4065e1ddb48SDavid Howells __u8 bInterfaceProtocol;
4075e1ddb48SDavid Howells __u8 iInterface;
4085e1ddb48SDavid Howells } __attribute__ ((packed));
4095e1ddb48SDavid Howells
4105e1ddb48SDavid Howells #define USB_DT_INTERFACE_SIZE 9
4115e1ddb48SDavid Howells
4125e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
4135e1ddb48SDavid Howells
4145e1ddb48SDavid Howells /* USB_DT_ENDPOINT: Endpoint descriptor */
4155e1ddb48SDavid Howells struct usb_endpoint_descriptor {
4165e1ddb48SDavid Howells __u8 bLength;
4175e1ddb48SDavid Howells __u8 bDescriptorType;
4185e1ddb48SDavid Howells
4195e1ddb48SDavid Howells __u8 bEndpointAddress;
4205e1ddb48SDavid Howells __u8 bmAttributes;
4215e1ddb48SDavid Howells __le16 wMaxPacketSize;
4225e1ddb48SDavid Howells __u8 bInterval;
4235e1ddb48SDavid Howells
4245e1ddb48SDavid Howells /* NOTE: these two are _only_ in audio endpoints. */
4255e1ddb48SDavid Howells /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
4265e1ddb48SDavid Howells __u8 bRefresh;
4275e1ddb48SDavid Howells __u8 bSynchAddress;
4285e1ddb48SDavid Howells } __attribute__ ((packed));
4295e1ddb48SDavid Howells
4305e1ddb48SDavid Howells #define USB_DT_ENDPOINT_SIZE 7
4315e1ddb48SDavid Howells #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
4325e1ddb48SDavid Howells
4335e1ddb48SDavid Howells
4345e1ddb48SDavid Howells /*
4355e1ddb48SDavid Howells * Endpoints
4365e1ddb48SDavid Howells */
4375e1ddb48SDavid Howells #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
4385e1ddb48SDavid Howells #define USB_ENDPOINT_DIR_MASK 0x80
4395e1ddb48SDavid Howells
4405e1ddb48SDavid Howells #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
4415e1ddb48SDavid Howells #define USB_ENDPOINT_XFER_CONTROL 0
4425e1ddb48SDavid Howells #define USB_ENDPOINT_XFER_ISOC 1
4435e1ddb48SDavid Howells #define USB_ENDPOINT_XFER_BULK 2
444abb62184SFelipe Balbi #define USB_ENDPOINT_XFER_INT 3
445541b6fe6SFelipe Balbi #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
446541b6fe6SFelipe Balbi
447541b6fe6SFelipe Balbi #define USB_ENDPOINT_MAXP_MASK 0x07ff
448541b6fe6SFelipe Balbi #define USB_EP_MAXP_MULT_SHIFT 11
449541b6fe6SFelipe Balbi #define USB_EP_MAXP_MULT_MASK (3 << USB_EP_MAXP_MULT_SHIFT)
4505e1ddb48SDavid Howells #define USB_EP_MAXP_MULT(m) \
4515e1ddb48SDavid Howells (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
4525e1ddb48SDavid Howells
4535e1ddb48SDavid Howells /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
4545e1ddb48SDavid Howells #define USB_ENDPOINT_INTRTYPE 0x30
4555e1ddb48SDavid Howells #define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
4565e1ddb48SDavid Howells #define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4)
4575e1ddb48SDavid Howells
4585e1ddb48SDavid Howells #define USB_ENDPOINT_SYNCTYPE 0x0c
4595e1ddb48SDavid Howells #define USB_ENDPOINT_SYNC_NONE (0 << 2)
4605e1ddb48SDavid Howells #define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
4615e1ddb48SDavid Howells #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
4625e1ddb48SDavid Howells #define USB_ENDPOINT_SYNC_SYNC (3 << 2)
4635e1ddb48SDavid Howells
4645e1ddb48SDavid Howells #define USB_ENDPOINT_USAGE_MASK 0x30
4655e1ddb48SDavid Howells #define USB_ENDPOINT_USAGE_DATA 0x00
4665e1ddb48SDavid Howells #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
4675e1ddb48SDavid Howells #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */
4685e1ddb48SDavid Howells
4695e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
4705e1ddb48SDavid Howells
4715e1ddb48SDavid Howells /**
4725e1ddb48SDavid Howells * usb_endpoint_num - get the endpoint's number
4735e1ddb48SDavid Howells * @epd: endpoint to be checked
4745e1ddb48SDavid Howells *
4755e1ddb48SDavid Howells * Returns @epd's number: 0 to 15.
4765e1ddb48SDavid Howells */
usb_endpoint_num(const struct usb_endpoint_descriptor * epd)4775e1ddb48SDavid Howells static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
4785e1ddb48SDavid Howells {
4795e1ddb48SDavid Howells return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
4805e1ddb48SDavid Howells }
4815e1ddb48SDavid Howells
4825e1ddb48SDavid Howells /**
4835e1ddb48SDavid Howells * usb_endpoint_type - get the endpoint's transfer type
4845e1ddb48SDavid Howells * @epd: endpoint to be checked
4855e1ddb48SDavid Howells *
4865e1ddb48SDavid Howells * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
4875e1ddb48SDavid Howells * to @epd's transfer type.
4885e1ddb48SDavid Howells */
usb_endpoint_type(const struct usb_endpoint_descriptor * epd)4895e1ddb48SDavid Howells static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
4905e1ddb48SDavid Howells {
4915e1ddb48SDavid Howells return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
4925e1ddb48SDavid Howells }
4935e1ddb48SDavid Howells
4945e1ddb48SDavid Howells /**
4955e1ddb48SDavid Howells * usb_endpoint_dir_in - check if the endpoint has IN direction
4965e1ddb48SDavid Howells * @epd: endpoint to be checked
4975e1ddb48SDavid Howells *
4985e1ddb48SDavid Howells * Returns true if the endpoint is of type IN, otherwise it returns false.
4995e1ddb48SDavid Howells */
usb_endpoint_dir_in(const struct usb_endpoint_descriptor * epd)5005e1ddb48SDavid Howells static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
5015e1ddb48SDavid Howells {
5025e1ddb48SDavid Howells return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
5035e1ddb48SDavid Howells }
5045e1ddb48SDavid Howells
5055e1ddb48SDavid Howells /**
5065e1ddb48SDavid Howells * usb_endpoint_dir_out - check if the endpoint has OUT direction
5075e1ddb48SDavid Howells * @epd: endpoint to be checked
5085e1ddb48SDavid Howells *
5095e1ddb48SDavid Howells * Returns true if the endpoint is of type OUT, otherwise it returns false.
5105e1ddb48SDavid Howells */
usb_endpoint_dir_out(const struct usb_endpoint_descriptor * epd)5115e1ddb48SDavid Howells static inline int usb_endpoint_dir_out(
5125e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5135e1ddb48SDavid Howells {
5145e1ddb48SDavid Howells return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
5155e1ddb48SDavid Howells }
5165e1ddb48SDavid Howells
5175e1ddb48SDavid Howells /**
5185e1ddb48SDavid Howells * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
5195e1ddb48SDavid Howells * @epd: endpoint to be checked
5205e1ddb48SDavid Howells *
5215e1ddb48SDavid Howells * Returns true if the endpoint is of type bulk, otherwise it returns false.
5225e1ddb48SDavid Howells */
usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor * epd)5235e1ddb48SDavid Howells static inline int usb_endpoint_xfer_bulk(
5245e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5255e1ddb48SDavid Howells {
5265e1ddb48SDavid Howells return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
5275e1ddb48SDavid Howells USB_ENDPOINT_XFER_BULK);
5285e1ddb48SDavid Howells }
5295e1ddb48SDavid Howells
5305e1ddb48SDavid Howells /**
5315e1ddb48SDavid Howells * usb_endpoint_xfer_control - check if the endpoint has control transfer type
5325e1ddb48SDavid Howells * @epd: endpoint to be checked
5335e1ddb48SDavid Howells *
5345e1ddb48SDavid Howells * Returns true if the endpoint is of type control, otherwise it returns false.
5355e1ddb48SDavid Howells */
usb_endpoint_xfer_control(const struct usb_endpoint_descriptor * epd)5365e1ddb48SDavid Howells static inline int usb_endpoint_xfer_control(
5375e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5385e1ddb48SDavid Howells {
5395e1ddb48SDavid Howells return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
5405e1ddb48SDavid Howells USB_ENDPOINT_XFER_CONTROL);
5415e1ddb48SDavid Howells }
5425e1ddb48SDavid Howells
5435e1ddb48SDavid Howells /**
5445e1ddb48SDavid Howells * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
5455e1ddb48SDavid Howells * @epd: endpoint to be checked
5465e1ddb48SDavid Howells *
5475e1ddb48SDavid Howells * Returns true if the endpoint is of type interrupt, otherwise it returns
5485e1ddb48SDavid Howells * false.
5495e1ddb48SDavid Howells */
usb_endpoint_xfer_int(const struct usb_endpoint_descriptor * epd)5505e1ddb48SDavid Howells static inline int usb_endpoint_xfer_int(
5515e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5525e1ddb48SDavid Howells {
5535e1ddb48SDavid Howells return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
5545e1ddb48SDavid Howells USB_ENDPOINT_XFER_INT);
5555e1ddb48SDavid Howells }
5565e1ddb48SDavid Howells
5575e1ddb48SDavid Howells /**
5585e1ddb48SDavid Howells * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
5595e1ddb48SDavid Howells * @epd: endpoint to be checked
5605e1ddb48SDavid Howells *
5615e1ddb48SDavid Howells * Returns true if the endpoint is of type isochronous, otherwise it returns
5625e1ddb48SDavid Howells * false.
5635e1ddb48SDavid Howells */
usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor * epd)5645e1ddb48SDavid Howells static inline int usb_endpoint_xfer_isoc(
5655e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5665e1ddb48SDavid Howells {
5675e1ddb48SDavid Howells return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
5685e1ddb48SDavid Howells USB_ENDPOINT_XFER_ISOC);
5695e1ddb48SDavid Howells }
5705e1ddb48SDavid Howells
5715e1ddb48SDavid Howells /**
5725e1ddb48SDavid Howells * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
5735e1ddb48SDavid Howells * @epd: endpoint to be checked
5745e1ddb48SDavid Howells *
5755e1ddb48SDavid Howells * Returns true if the endpoint has bulk transfer type and IN direction,
5765e1ddb48SDavid Howells * otherwise it returns false.
5775e1ddb48SDavid Howells */
usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor * epd)5785e1ddb48SDavid Howells static inline int usb_endpoint_is_bulk_in(
5795e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5805e1ddb48SDavid Howells {
5815e1ddb48SDavid Howells return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
5825e1ddb48SDavid Howells }
5835e1ddb48SDavid Howells
5845e1ddb48SDavid Howells /**
5855e1ddb48SDavid Howells * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
5865e1ddb48SDavid Howells * @epd: endpoint to be checked
5875e1ddb48SDavid Howells *
5885e1ddb48SDavid Howells * Returns true if the endpoint has bulk transfer type and OUT direction,
5895e1ddb48SDavid Howells * otherwise it returns false.
5905e1ddb48SDavid Howells */
usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor * epd)5915e1ddb48SDavid Howells static inline int usb_endpoint_is_bulk_out(
5925e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
5935e1ddb48SDavid Howells {
5945e1ddb48SDavid Howells return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
5955e1ddb48SDavid Howells }
5965e1ddb48SDavid Howells
5975e1ddb48SDavid Howells /**
5985e1ddb48SDavid Howells * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
5995e1ddb48SDavid Howells * @epd: endpoint to be checked
6005e1ddb48SDavid Howells *
6015e1ddb48SDavid Howells * Returns true if the endpoint has interrupt transfer type and IN direction,
6025e1ddb48SDavid Howells * otherwise it returns false.
6035e1ddb48SDavid Howells */
usb_endpoint_is_int_in(const struct usb_endpoint_descriptor * epd)6045e1ddb48SDavid Howells static inline int usb_endpoint_is_int_in(
6055e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
6065e1ddb48SDavid Howells {
6075e1ddb48SDavid Howells return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
6085e1ddb48SDavid Howells }
6095e1ddb48SDavid Howells
6105e1ddb48SDavid Howells /**
6115e1ddb48SDavid Howells * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
6125e1ddb48SDavid Howells * @epd: endpoint to be checked
6135e1ddb48SDavid Howells *
6145e1ddb48SDavid Howells * Returns true if the endpoint has interrupt transfer type and OUT direction,
6155e1ddb48SDavid Howells * otherwise it returns false.
6165e1ddb48SDavid Howells */
usb_endpoint_is_int_out(const struct usb_endpoint_descriptor * epd)6175e1ddb48SDavid Howells static inline int usb_endpoint_is_int_out(
6185e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
6195e1ddb48SDavid Howells {
6205e1ddb48SDavid Howells return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
6215e1ddb48SDavid Howells }
6225e1ddb48SDavid Howells
6235e1ddb48SDavid Howells /**
6245e1ddb48SDavid Howells * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
6255e1ddb48SDavid Howells * @epd: endpoint to be checked
6265e1ddb48SDavid Howells *
6275e1ddb48SDavid Howells * Returns true if the endpoint has isochronous transfer type and IN direction,
6285e1ddb48SDavid Howells * otherwise it returns false.
6295e1ddb48SDavid Howells */
usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor * epd)6305e1ddb48SDavid Howells static inline int usb_endpoint_is_isoc_in(
6315e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
6325e1ddb48SDavid Howells {
6335e1ddb48SDavid Howells return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
6345e1ddb48SDavid Howells }
6355e1ddb48SDavid Howells
6365e1ddb48SDavid Howells /**
6375e1ddb48SDavid Howells * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
6385e1ddb48SDavid Howells * @epd: endpoint to be checked
6395e1ddb48SDavid Howells *
6405e1ddb48SDavid Howells * Returns true if the endpoint has isochronous transfer type and OUT direction,
6415e1ddb48SDavid Howells * otherwise it returns false.
6425e1ddb48SDavid Howells */
usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * epd)6435e1ddb48SDavid Howells static inline int usb_endpoint_is_isoc_out(
6445e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
6455e1ddb48SDavid Howells {
6465e1ddb48SDavid Howells return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
6475e1ddb48SDavid Howells }
6485e1ddb48SDavid Howells
6495e1ddb48SDavid Howells /**
650abb62184SFelipe Balbi * usb_endpoint_maxp - get endpoint's max packet size
6515e1ddb48SDavid Howells * @epd: endpoint to be checked
6525e1ddb48SDavid Howells *
6535e1ddb48SDavid Howells * Returns @epd's max packet bits [10:0]
654abb62184SFelipe Balbi */
usb_endpoint_maxp(const struct usb_endpoint_descriptor * epd)6555e1ddb48SDavid Howells static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
6565e1ddb48SDavid Howells {
657541b6fe6SFelipe Balbi return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK;
658541b6fe6SFelipe Balbi }
659541b6fe6SFelipe Balbi
660541b6fe6SFelipe Balbi /**
661541b6fe6SFelipe Balbi * usb_endpoint_maxp_mult - get endpoint's transactional opportunities
662541b6fe6SFelipe Balbi * @epd: endpoint to be checked
663541b6fe6SFelipe Balbi *
664541b6fe6SFelipe Balbi * Return @epd's wMaxPacketSize[12:11] + 1
665541b6fe6SFelipe Balbi */
666541b6fe6SFelipe Balbi static inline int
usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor * epd)667541b6fe6SFelipe Balbi usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd)
668541b6fe6SFelipe Balbi {
669541b6fe6SFelipe Balbi int maxp = __le16_to_cpu(epd->wMaxPacketSize);
670541b6fe6SFelipe Balbi
6715e1ddb48SDavid Howells return USB_EP_MAXP_MULT(maxp) + 1;
6725e1ddb48SDavid Howells }
6735e1ddb48SDavid Howells
usb_endpoint_interrupt_type(const struct usb_endpoint_descriptor * epd)6745e1ddb48SDavid Howells static inline int usb_endpoint_interrupt_type(
6755e1ddb48SDavid Howells const struct usb_endpoint_descriptor *epd)
6765e1ddb48SDavid Howells {
6775e1ddb48SDavid Howells return epd->bmAttributes & USB_ENDPOINT_INTRTYPE;
6785e1ddb48SDavid Howells }
679c8b1d897SMathias Nyman
680c8b1d897SMathias Nyman /*-------------------------------------------------------------------------*/
681c8b1d897SMathias Nyman
682c8b1d897SMathias Nyman /* USB_DT_EUSB2_ISOC_ENDPOINT_COMP: eUSB2 Isoch Endpoint Companion descriptor */
683c8b1d897SMathias Nyman struct usb_eusb2_isoc_ep_comp_descriptor {
684c8b1d897SMathias Nyman __u8 bLength;
685c8b1d897SMathias Nyman __u8 bDescriptorType;
686c8b1d897SMathias Nyman __le16 wMaxPacketSize;
687c8b1d897SMathias Nyman __le32 dwBytesPerInterval;
688c8b1d897SMathias Nyman } __attribute__ ((packed));
689c8b1d897SMathias Nyman
690c8b1d897SMathias Nyman #define USB_DT_EUSB2_ISOC_EP_COMP_SIZE 8
691c8b1d897SMathias Nyman
692c8b1d897SMathias Nyman /*-------------------------------------------------------------------------*/
6935e1ddb48SDavid Howells
6945e1ddb48SDavid Howells /* USB_DT_SSP_ISOC_ENDPOINT_COMP: SuperSpeedPlus Isochronous Endpoint Companion
6955e1ddb48SDavid Howells * descriptor
6965e1ddb48SDavid Howells */
6975e1ddb48SDavid Howells struct usb_ssp_isoc_ep_comp_descriptor {
6985e1ddb48SDavid Howells __u8 bLength;
6995e1ddb48SDavid Howells __u8 bDescriptorType;
7005e1ddb48SDavid Howells __le16 wReseved;
7015e1ddb48SDavid Howells __le32 dwBytesPerInterval;
7025e1ddb48SDavid Howells } __attribute__ ((packed));
7035e1ddb48SDavid Howells
7045e1ddb48SDavid Howells #define USB_DT_SSP_ISOC_EP_COMP_SIZE 8
7055e1ddb48SDavid Howells
7065e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
7075e1ddb48SDavid Howells
7085e1ddb48SDavid Howells /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
7095e1ddb48SDavid Howells struct usb_ss_ep_comp_descriptor {
7105e1ddb48SDavid Howells __u8 bLength;
7115e1ddb48SDavid Howells __u8 bDescriptorType;
7125e1ddb48SDavid Howells
7135e1ddb48SDavid Howells __u8 bMaxBurst;
7145e1ddb48SDavid Howells __u8 bmAttributes;
7155e1ddb48SDavid Howells __le16 wBytesPerInterval;
7165e1ddb48SDavid Howells } __attribute__ ((packed));
7175e1ddb48SDavid Howells
7185e1ddb48SDavid Howells #define USB_DT_SS_EP_COMP_SIZE 6
7195e1ddb48SDavid Howells
7205e1ddb48SDavid Howells /* Bits 4:0 of bmAttributes if this is a bulk endpoint */
7215e1ddb48SDavid Howells static inline int
usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor * comp)7225e1ddb48SDavid Howells usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp)
7235e1ddb48SDavid Howells {
7245e1ddb48SDavid Howells int max_streams;
7255e1ddb48SDavid Howells
726c8b1d897SMathias Nyman if (!comp)
727c8b1d897SMathias Nyman return 0;
7285e1ddb48SDavid Howells
7295e1ddb48SDavid Howells max_streams = comp->bmAttributes & 0x1f;
7305e1ddb48SDavid Howells
7315e1ddb48SDavid Howells if (!max_streams)
7325e1ddb48SDavid Howells return 0;
7335e1ddb48SDavid Howells
7345e1ddb48SDavid Howells max_streams = 1 << max_streams;
7355e1ddb48SDavid Howells
7365e1ddb48SDavid Howells return max_streams;
7375e1ddb48SDavid Howells }
7385e1ddb48SDavid Howells
7395e1ddb48SDavid Howells /* Bits 1:0 of bmAttributes if this is an isoc endpoint */
7405e1ddb48SDavid Howells #define USB_SS_MULT(p) (1 + ((p) & 0x3))
7415e1ddb48SDavid Howells /* Bit 7 of bmAttributes if a SSP isoc endpoint companion descriptor exists */
7425e1ddb48SDavid Howells #define USB_SS_SSP_ISOC_COMP(p) ((p) & (1 << 7))
7435e1ddb48SDavid Howells
7445e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
7455e1ddb48SDavid Howells
7465e1ddb48SDavid Howells /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
7475e1ddb48SDavid Howells struct usb_qualifier_descriptor {
7485e1ddb48SDavid Howells __u8 bLength;
7495e1ddb48SDavid Howells __u8 bDescriptorType;
7505e1ddb48SDavid Howells
7515e1ddb48SDavid Howells __le16 bcdUSB;
7525e1ddb48SDavid Howells __u8 bDeviceClass;
7535e1ddb48SDavid Howells __u8 bDeviceSubClass;
7545e1ddb48SDavid Howells __u8 bDeviceProtocol;
7555e1ddb48SDavid Howells __u8 bMaxPacketSize0;
7568486a0bbSMacpaul Lin __u8 bNumConfigurations;
7578486a0bbSMacpaul Lin __u8 bRESERVED;
7588486a0bbSMacpaul Lin } __attribute__ ((packed));
7598486a0bbSMacpaul Lin
7608486a0bbSMacpaul Lin
7618486a0bbSMacpaul Lin /*-------------------------------------------------------------------------*/
7628486a0bbSMacpaul Lin
7638486a0bbSMacpaul Lin /* USB_DT_OTG (from OTG 1.0a supplement) */
7648486a0bbSMacpaul Lin struct usb_otg_descriptor {
7658486a0bbSMacpaul Lin __u8 bLength;
7668486a0bbSMacpaul Lin __u8 bDescriptorType;
7675e1ddb48SDavid Howells
7685e1ddb48SDavid Howells __u8 bmAttributes; /* support for HNP, SRP, etc */
7695e1ddb48SDavid Howells } __attribute__ ((packed));
7705d701cefSMacpaul Lin
771b5584695SOliver Neukum /* USB_DT_OTG (from OTG 2.0 supplement) */
772b5584695SOliver Neukum struct usb_otg20_descriptor {
7735e1ddb48SDavid Howells __u8 bLength;
774346dbc69SLi Jun __u8 bDescriptorType;
7755e1ddb48SDavid Howells
7765e1ddb48SDavid Howells __u8 bmAttributes; /* support for HNP, SRP and ADP, etc */
7775e1ddb48SDavid Howells __le16 bcdOTG; /* OTG and EH supplement release number
7785e1ddb48SDavid Howells * in binary-coded decimal(i.e. 2.0 is 0200H)
7795e1ddb48SDavid Howells */
7805e1ddb48SDavid Howells } __attribute__ ((packed));
7815e1ddb48SDavid Howells
7825e1ddb48SDavid Howells /* from usb_otg_descriptor.bmAttributes */
7835e1ddb48SDavid Howells #define USB_OTG_SRP (1 << 0)
7845e1ddb48SDavid Howells #define USB_OTG_HNP (1 << 1) /* swap host/device roles */
7855e1ddb48SDavid Howells #define USB_OTG_ADP (1 << 2) /* support ADP */
7865e1ddb48SDavid Howells /* OTG 3.0 */
7875e1ddb48SDavid Howells #define USB_OTG_RSP (1 << 3) /* support RSP */
7885e1ddb48SDavid Howells
7895e1ddb48SDavid Howells #define OTG_STS_SELECTOR 0xF000 /* OTG status selector */
7905e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
7915e1ddb48SDavid Howells
7925e1ddb48SDavid Howells /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */
7935e1ddb48SDavid Howells struct usb_debug_descriptor {
7945e1ddb48SDavid Howells __u8 bLength;
7955e1ddb48SDavid Howells __u8 bDescriptorType;
7965e1ddb48SDavid Howells
7975e1ddb48SDavid Howells /* bulk endpoints with 8 byte maxpacket */
7985e1ddb48SDavid Howells __u8 bDebugInEndpoint;
7995e1ddb48SDavid Howells __u8 bDebugOutEndpoint;
8005e1ddb48SDavid Howells } __attribute__((packed));
8015e1ddb48SDavid Howells
802bd7a3fe7SGreg Kroah-Hartman /*-------------------------------------------------------------------------*/
8035e1ddb48SDavid Howells
8045e1ddb48SDavid Howells /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
8055e1ddb48SDavid Howells struct usb_interface_assoc_descriptor {
8065e1ddb48SDavid Howells __u8 bLength;
8075e1ddb48SDavid Howells __u8 bDescriptorType;
8085e1ddb48SDavid Howells
8095e1ddb48SDavid Howells __u8 bFirstInterface;
8105e1ddb48SDavid Howells __u8 bInterfaceCount;
8115e1ddb48SDavid Howells __u8 bFunctionClass;
8125e1ddb48SDavid Howells __u8 bFunctionSubClass;
8135e1ddb48SDavid Howells __u8 bFunctionProtocol;
8145e1ddb48SDavid Howells __u8 iFunction;
8155e1ddb48SDavid Howells } __attribute__ ((packed));
8165e1ddb48SDavid Howells
8175e1ddb48SDavid Howells #define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
8185e1ddb48SDavid Howells
8195e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
8205e1ddb48SDavid Howells
8215e1ddb48SDavid Howells /* USB_DT_SECURITY: group of wireless security descriptors, including
8225e1ddb48SDavid Howells * encryption types available for setting up a CC/association.
8235e1ddb48SDavid Howells */
8245e1ddb48SDavid Howells struct usb_security_descriptor {
8255e1ddb48SDavid Howells __u8 bLength;
8265e1ddb48SDavid Howells __u8 bDescriptorType;
8275e1ddb48SDavid Howells
82894dfc73eSGustavo A. R. Silva __le16 wTotalLength;
8295e1ddb48SDavid Howells __u8 bNumEncryptionTypes;
8305e1ddb48SDavid Howells } __attribute__((packed));
8315e1ddb48SDavid Howells
8325e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
8335e1ddb48SDavid Howells
8345e1ddb48SDavid Howells /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys
8355e1ddb48SDavid Howells * may be retrieved.
8365e1ddb48SDavid Howells */
8375e1ddb48SDavid Howells struct usb_key_descriptor {
8385e1ddb48SDavid Howells __u8 bLength;
8395e1ddb48SDavid Howells __u8 bDescriptorType;
8405e1ddb48SDavid Howells
8415e1ddb48SDavid Howells __u8 tTKID[3];
8425e1ddb48SDavid Howells __u8 bReserved;
8435e1ddb48SDavid Howells __u8 bKeyData[];
8445e1ddb48SDavid Howells } __attribute__((packed));
8455e1ddb48SDavid Howells
8465e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
8475e1ddb48SDavid Howells
8485e1ddb48SDavid Howells /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */
8495e1ddb48SDavid Howells struct usb_encryption_descriptor {
8505e1ddb48SDavid Howells __u8 bLength;
8515e1ddb48SDavid Howells __u8 bDescriptorType;
8525e1ddb48SDavid Howells
8535e1ddb48SDavid Howells __u8 bEncryptionType;
8545e1ddb48SDavid Howells #define USB_ENC_TYPE_UNSECURE 0
8555e1ddb48SDavid Howells #define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */
8565e1ddb48SDavid Howells #define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */
8575e1ddb48SDavid Howells #define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */
8585e1ddb48SDavid Howells __u8 bEncryptionValue; /* use in SET_ENCRYPTION */
8595e1ddb48SDavid Howells __u8 bAuthKeyIndex;
8605e1ddb48SDavid Howells } __attribute__((packed));
8615e1ddb48SDavid Howells
8625e1ddb48SDavid Howells
8635e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
8645e1ddb48SDavid Howells
8655e1ddb48SDavid Howells /* USB_DT_BOS: group of device-level capabilities */
8665e1ddb48SDavid Howells struct usb_bos_descriptor {
8675e1ddb48SDavid Howells __u8 bLength;
8685e1ddb48SDavid Howells __u8 bDescriptorType;
8695e1ddb48SDavid Howells
8705e1ddb48SDavid Howells __le16 wTotalLength;
8715e1ddb48SDavid Howells __u8 bNumDeviceCaps;
8725e1ddb48SDavid Howells } __attribute__((packed));
8735e1ddb48SDavid Howells
8745e1ddb48SDavid Howells #define USB_DT_BOS_SIZE 5
8755e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
8765e1ddb48SDavid Howells
8775e1ddb48SDavid Howells /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */
8785e1ddb48SDavid Howells struct usb_dev_cap_header {
8795e1ddb48SDavid Howells __u8 bLength;
8805e1ddb48SDavid Howells __u8 bDescriptorType;
8815e1ddb48SDavid Howells __u8 bDevCapabilityType;
8825e1ddb48SDavid Howells } __attribute__((packed));
8835e1ddb48SDavid Howells
8845e1ddb48SDavid Howells #define USB_CAP_TYPE_WIRELESS_USB 1
8855e1ddb48SDavid Howells
8865e1ddb48SDavid Howells struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
8875e1ddb48SDavid Howells __u8 bLength;
8885e1ddb48SDavid Howells __u8 bDescriptorType;
8895e1ddb48SDavid Howells __u8 bDevCapabilityType;
8905e1ddb48SDavid Howells
8915e1ddb48SDavid Howells __u8 bmAttributes;
8925e1ddb48SDavid Howells #define USB_WIRELESS_P2P_DRD (1 << 1)
8935e1ddb48SDavid Howells #define USB_WIRELESS_BEACON_MASK (3 << 2)
8945e1ddb48SDavid Howells #define USB_WIRELESS_BEACON_SELF (1 << 2)
8955e1ddb48SDavid Howells #define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
8965e1ddb48SDavid Howells #define USB_WIRELESS_BEACON_NONE (3 << 2)
89781cf4a45SMasakazu Mokuno __le16 wPHYRates; /* bit rates, Mbps */
89881cf4a45SMasakazu Mokuno #define USB_WIRELESS_PHY_53 (1 << 0) /* always set */
8995e1ddb48SDavid Howells #define USB_WIRELESS_PHY_80 (1 << 1)
9005e1ddb48SDavid Howells #define USB_WIRELESS_PHY_107 (1 << 2) /* always set */
9015e1ddb48SDavid Howells #define USB_WIRELESS_PHY_160 (1 << 3)
9025e1ddb48SDavid Howells #define USB_WIRELESS_PHY_200 (1 << 4) /* always set */
9035e1ddb48SDavid Howells #define USB_WIRELESS_PHY_320 (1 << 5)
9045e1ddb48SDavid Howells #define USB_WIRELESS_PHY_400 (1 << 6)
9055e1ddb48SDavid Howells #define USB_WIRELESS_PHY_480 (1 << 7)
9065e1ddb48SDavid Howells __u8 bmTFITXPowerInfo; /* TFI power levels */
9075e1ddb48SDavid Howells __u8 bmFFITXPowerInfo; /* FFI power levels */
9085e1ddb48SDavid Howells __le16 bmBandGroup;
9095e1ddb48SDavid Howells __u8 bReserved;
9105e1ddb48SDavid Howells } __attribute__((packed));
911cca38540SThinh Nguyen
912cca38540SThinh Nguyen #define USB_DT_USB_WIRELESS_CAP_SIZE 11
9135e1ddb48SDavid Howells
9145e1ddb48SDavid Howells /* USB 2.0 Extension descriptor */
9155e1ddb48SDavid Howells #define USB_CAP_TYPE_EXT 2
9165e1ddb48SDavid Howells
9175e1ddb48SDavid Howells struct usb_ext_cap_descriptor { /* Link Power Management */
9185e1ddb48SDavid Howells __u8 bLength;
9195e1ddb48SDavid Howells __u8 bDescriptorType;
9205e1ddb48SDavid Howells __u8 bDevCapabilityType;
9215e1ddb48SDavid Howells __le32 bmAttributes;
9225e1ddb48SDavid Howells #define USB_LPM_SUPPORT (1 << 1) /* supports LPM */
9235e1ddb48SDavid Howells #define USB_BESL_SUPPORT (1 << 2) /* supports BESL */
9245e1ddb48SDavid Howells #define USB_BESL_BASELINE_VALID (1 << 3) /* Baseline BESL valid*/
9255e1ddb48SDavid Howells #define USB_BESL_DEEP_VALID (1 << 4) /* Deep BESL valid */
9265e1ddb48SDavid Howells #define USB_SET_BESL_BASELINE(p) (((p) & 0xf) << 8)
9275e1ddb48SDavid Howells #define USB_SET_BESL_DEEP(p) (((p) & 0xf) << 12)
9285e1ddb48SDavid Howells #define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8)
9295e1ddb48SDavid Howells #define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12)
9305e1ddb48SDavid Howells } __attribute__((packed));
9315e1ddb48SDavid Howells
9325e1ddb48SDavid Howells #define USB_DT_USB_EXT_CAP_SIZE 7
9335e1ddb48SDavid Howells
9345e1ddb48SDavid Howells /*
9355e1ddb48SDavid Howells * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB
9365e1ddb48SDavid Howells * specific device level capabilities
9375e1ddb48SDavid Howells */
9385e1ddb48SDavid Howells #define USB_SS_CAP_TYPE 3
9395e1ddb48SDavid Howells struct usb_ss_cap_descriptor { /* Link Power Management */
9405e1ddb48SDavid Howells __u8 bLength;
9415e1ddb48SDavid Howells __u8 bDescriptorType;
9425e1ddb48SDavid Howells __u8 bDevCapabilityType;
9435e1ddb48SDavid Howells __u8 bmAttributes;
9445e1ddb48SDavid Howells #define USB_LTM_SUPPORT (1 << 1) /* supports LTM */
9455e1ddb48SDavid Howells __le16 wSpeedSupported;
9465e1ddb48SDavid Howells #define USB_LOW_SPEED_OPERATION (1) /* Low speed operation */
9475e1ddb48SDavid Howells #define USB_FULL_SPEED_OPERATION (1 << 1) /* Full speed operation */
9485e1ddb48SDavid Howells #define USB_HIGH_SPEED_OPERATION (1 << 2) /* High speed operation */
9495e1ddb48SDavid Howells #define USB_5GBPS_OPERATION (1 << 3) /* Operation at 5Gbps */
9505e1ddb48SDavid Howells __u8 bFunctionalitySupport;
9515e1ddb48SDavid Howells __u8 bU1devExitLat;
9525e1ddb48SDavid Howells __le16 bU2DevExitLat;
9535e1ddb48SDavid Howells } __attribute__((packed));
9545e1ddb48SDavid Howells
9555e1ddb48SDavid Howells #define USB_DT_USB_SS_CAP_SIZE 10
95690ec9247SMathias Nyman
95790ec9247SMathias Nyman /*
95893c47394SJó Ágila Bitsch * Container ID Capability descriptor: Defines the instance unique ID used to
95993c47394SJó Ágila Bitsch * identify the instance across all operating modes
96093c47394SJó Ágila Bitsch */
96193c47394SJó Ágila Bitsch #define CONTAINER_ID_TYPE 4
96293c47394SJó Ágila Bitsch struct usb_ss_container_id_descriptor {
96393c47394SJó Ágila Bitsch __u8 bLength;
96493c47394SJó Ágila Bitsch __u8 bDescriptorType;
96593c47394SJó Ágila Bitsch __u8 bDevCapabilityType;
96693c47394SJó Ágila Bitsch __u8 bReserved;
96793c47394SJó Ágila Bitsch __u8 ContainerID[16]; /* 128-bit number */
96893c47394SJó Ágila Bitsch } __attribute__((packed));
96993c47394SJó Ágila Bitsch
97093c47394SJó Ágila Bitsch #define USB_DT_USB_SS_CONTN_ID_SIZE 20
97193c47394SJó Ágila Bitsch
97293c47394SJó Ágila Bitsch /*
97393c47394SJó Ágila Bitsch * Platform Device Capability descriptor: Defines platform specific device
97490ec9247SMathias Nyman * capabilities
97590ec9247SMathias Nyman */
97690ec9247SMathias Nyman #define USB_PLAT_DEV_CAP_TYPE 5
97790ec9247SMathias Nyman struct usb_plat_dev_cap_descriptor {
97890ec9247SMathias Nyman __u8 bLength;
97990ec9247SMathias Nyman __u8 bDescriptorType;
98090ec9247SMathias Nyman __u8 bDevCapabilityType;
98190ec9247SMathias Nyman __u8 bReserved;
98290ec9247SMathias Nyman __u8 UUID[16];
98390ec9247SMathias Nyman __u8 CapabilityData[];
98490ec9247SMathias Nyman } __attribute__((packed));
98590ec9247SMathias Nyman
986743bc4b0SJohn Youn #define USB_DT_USB_PLAT_DEV_CAP_SIZE(capability_data_size) (20 + capability_data_size)
98790ec9247SMathias Nyman
98890ec9247SMathias Nyman /*
98990ec9247SMathias Nyman * SuperSpeed Plus USB Capability descriptor: Defines the set of
99090ec9247SMathias Nyman * SuperSpeed Plus USB specific device level capabilities
99101f23c5fSKees Cook */
99201f23c5fSKees Cook #define USB_SSP_CAP_TYPE 0xa
99301f23c5fSKees Cook struct usb_ssp_cap_descriptor {
99401f23c5fSKees Cook __u8 bLength;
99501f23c5fSKees Cook __u8 bDescriptorType;
99690ec9247SMathias Nyman __u8 bDevCapabilityType;
99790ec9247SMathias Nyman __u8 bReserved;
998f2fc9ff2SThinh Nguyen __le32 bmAttributes;
999f2fc9ff2SThinh Nguyen #define USB_SSP_SUBLINK_SPEED_ATTRIBS (0x1f << 0) /* sublink speed entries */
1000f2fc9ff2SThinh Nguyen #define USB_SSP_SUBLINK_SPEED_IDS (0xf << 5) /* speed ID entries */
1001f2fc9ff2SThinh Nguyen __le16 wFunctionalitySupport;
1002f2fc9ff2SThinh Nguyen #define USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID (0xf)
100390ec9247SMathias Nyman #define USB_SSP_MIN_RX_LANE_COUNT (0xf << 8)
1004f2fc9ff2SThinh Nguyen #define USB_SSP_MIN_TX_LANE_COUNT (0xf << 12)
1005f2fc9ff2SThinh Nguyen __le16 wReserved;
1006f2fc9ff2SThinh Nguyen union {
1007f2fc9ff2SThinh Nguyen __le32 legacy_padding;
1008f2fc9ff2SThinh Nguyen /* list of sublink speed attrib entries */
100990ec9247SMathias Nyman __DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr);
101090ec9247SMathias Nyman };
1011f2fc9ff2SThinh Nguyen #define USB_SSP_SUBLINK_SPEED_SSID (0xf) /* sublink speed ID */
1012f2fc9ff2SThinh Nguyen #define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4) /* Lanespeed exponent */
1013f2fc9ff2SThinh Nguyen #define USB_SSP_SUBLINK_SPEED_LSE_BPS 0
101490ec9247SMathias Nyman #define USB_SSP_SUBLINK_SPEED_LSE_KBPS 1
101590ec9247SMathias Nyman #define USB_SSP_SUBLINK_SPEED_LSE_MBPS 2
101690ec9247SMathias Nyman #define USB_SSP_SUBLINK_SPEED_LSE_GBPS 3
1017faee822cSMathias Nyman
1018e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_ST (0x3 << 6) /* Sublink type */
1019e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_ST_SYM_RX 0
1020e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX 1
1021e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_ST_SYM_TX 2
1022e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX 3
1023e10f9a42SOliver Neukum
1024e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_RSVD (0x3f << 8) /* Reserved */
1025e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_LP (0x3 << 14) /* Link protocol */
1026e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_LP_SS 0
1027e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_LP_SSP 1
1028e10f9a42SOliver Neukum
1029e10f9a42SOliver Neukum #define USB_SSP_SUBLINK_SPEED_LSM (0xff << 16) /* Lanespeed mantissa */
1030e10f9a42SOliver Neukum } __attribute__((packed));
1031e10f9a42SOliver Neukum
1032e10f9a42SOliver Neukum /*
1033e10f9a42SOliver Neukum * USB Power Delivery Capability Descriptor:
1034e10f9a42SOliver Neukum * Defines capabilities for PD
1035e10f9a42SOliver Neukum */
1036e10f9a42SOliver Neukum /* Defines the various PD Capabilities of this device */
1037e10f9a42SOliver Neukum #define USB_PD_POWER_DELIVERY_CAPABILITY 0x06
1038e10f9a42SOliver Neukum /* Provides information on each battery supported by the device */
1039e10f9a42SOliver Neukum #define USB_PD_BATTERY_INFO_CAPABILITY 0x07
1040e10f9a42SOliver Neukum /* The Consumer characteristics of a Port on the device */
1041e10f9a42SOliver Neukum #define USB_PD_PD_CONSUMER_PORT_CAPABILITY 0x08
1042e10f9a42SOliver Neukum /* The provider characteristics of a Port on the device */
1043e10f9a42SOliver Neukum #define USB_PD_PD_PROVIDER_PORT_CAPABILITY 0x09
1044e10f9a42SOliver Neukum
1045e10f9a42SOliver Neukum struct usb_pd_cap_descriptor {
1046e10f9a42SOliver Neukum __u8 bLength;
1047e10f9a42SOliver Neukum __u8 bDescriptorType;
1048e10f9a42SOliver Neukum __u8 bDevCapabilityType; /* set to USB_PD_POWER_DELIVERY_CAPABILITY */
1049e10f9a42SOliver Neukum __u8 bReserved;
1050e10f9a42SOliver Neukum __le32 bmAttributes;
1051e10f9a42SOliver Neukum #define USB_PD_CAP_BATTERY_CHARGING (1 << 1) /* supports Battery Charging specification */
1052e10f9a42SOliver Neukum #define USB_PD_CAP_USB_PD (1 << 2) /* supports USB Power Delivery specification */
1053e10f9a42SOliver Neukum #define USB_PD_CAP_PROVIDER (1 << 3) /* can provide power */
1054e10f9a42SOliver Neukum #define USB_PD_CAP_CONSUMER (1 << 4) /* can consume power */
1055e10f9a42SOliver Neukum #define USB_PD_CAP_CHARGING_POLICY (1 << 5) /* supports CHARGING_POLICY feature */
1056e10f9a42SOliver Neukum #define USB_PD_CAP_TYPE_C_CURRENT (1 << 6) /* supports power capabilities defined in the USB Type-C Specification */
1057e10f9a42SOliver Neukum
1058e10f9a42SOliver Neukum #define USB_PD_CAP_PWR_AC (1 << 8)
1059e10f9a42SOliver Neukum #define USB_PD_CAP_PWR_BAT (1 << 9)
1060e10f9a42SOliver Neukum #define USB_PD_CAP_PWR_USE_V_BUS (1 << 14)
1061e10f9a42SOliver Neukum
1062e10f9a42SOliver Neukum __le16 bmProviderPorts; /* Bit zero refers to the UFP of the device */
1063e10f9a42SOliver Neukum __le16 bmConsumerPorts;
1064e10f9a42SOliver Neukum __le16 bcdBCVersion;
1065e10f9a42SOliver Neukum __le16 bcdPDVersion;
1066e10f9a42SOliver Neukum __le16 bcdUSBTypeCVersion;
1067e10f9a42SOliver Neukum } __attribute__((packed));
1068e10f9a42SOliver Neukum
1069e10f9a42SOliver Neukum struct usb_pd_cap_battery_info_descriptor {
1070e10f9a42SOliver Neukum __u8 bLength;
1071e10f9a42SOliver Neukum __u8 bDescriptorType;
1072e10f9a42SOliver Neukum __u8 bDevCapabilityType;
1073e10f9a42SOliver Neukum /* Index of string descriptor shall contain the user friendly name for this battery */
1074e10f9a42SOliver Neukum __u8 iBattery;
1075e10f9a42SOliver Neukum /* Index of string descriptor shall contain the Serial Number String for this battery */
1076e10f9a42SOliver Neukum __u8 iSerial;
1077e10f9a42SOliver Neukum __u8 iManufacturer;
1078e10f9a42SOliver Neukum __u8 bBatteryId; /* uniquely identifies this battery in status Messages */
1079e10f9a42SOliver Neukum __u8 bReserved;
1080e10f9a42SOliver Neukum /*
1081e10f9a42SOliver Neukum * Shall contain the Battery Charge value above which this
1082e10f9a42SOliver Neukum * battery is considered to be fully charged but not necessarily
1083e10f9a42SOliver Neukum * “topped off.”
1084e10f9a42SOliver Neukum */
1085e10f9a42SOliver Neukum __le32 dwChargedThreshold; /* in mWh */
1086e10f9a42SOliver Neukum /*
1087e10f9a42SOliver Neukum * Shall contain the minimum charge level of this battery such
1088e10f9a42SOliver Neukum * that above this threshold, a device can be assured of being
1089e10f9a42SOliver Neukum * able to power up successfully (see Battery Charging 1.2).
1090e10f9a42SOliver Neukum */
1091e10f9a42SOliver Neukum __le32 dwWeakThreshold; /* in mWh */
1092e10f9a42SOliver Neukum __le32 dwBatteryDesignCapacity; /* in mWh */
1093e10f9a42SOliver Neukum __le32 dwBatteryLastFullchargeCapacity; /* in mWh */
1094e10f9a42SOliver Neukum } __attribute__((packed));
1095e10f9a42SOliver Neukum
1096e10f9a42SOliver Neukum struct usb_pd_cap_consumer_port_descriptor {
1097e10f9a42SOliver Neukum __u8 bLength;
1098e10f9a42SOliver Neukum __u8 bDescriptorType;
1099e10f9a42SOliver Neukum __u8 bDevCapabilityType;
1100e10f9a42SOliver Neukum __u8 bReserved;
1101e10f9a42SOliver Neukum __u8 bmCapabilities;
1102e10f9a42SOliver Neukum /* port will oerate under: */
1103e10f9a42SOliver Neukum #define USB_PD_CAP_CONSUMER_BC (1 << 0) /* BC */
1104e10f9a42SOliver Neukum #define USB_PD_CAP_CONSUMER_PD (1 << 1) /* PD */
1105e10f9a42SOliver Neukum #define USB_PD_CAP_CONSUMER_TYPE_C (1 << 2) /* USB Type-C Current */
1106e10f9a42SOliver Neukum __le16 wMinVoltage; /* in 50mV units */
1107e10f9a42SOliver Neukum __le16 wMaxVoltage; /* in 50mV units */
1108e10f9a42SOliver Neukum __u16 wReserved;
1109e10f9a42SOliver Neukum __le32 dwMaxOperatingPower; /* in 10 mW - operating at steady state */
1110e10f9a42SOliver Neukum __le32 dwMaxPeakPower; /* in 10mW units - operating at peak power */
1111e10f9a42SOliver Neukum __le32 dwMaxPeakPowerTime; /* in 100ms units - duration of peak */
1112e10f9a42SOliver Neukum #define USB_PD_CAP_CONSUMER_UNKNOWN_PEAK_POWER_TIME 0xffff
1113e10f9a42SOliver Neukum } __attribute__((packed));
1114e10f9a42SOliver Neukum
1115e10f9a42SOliver Neukum struct usb_pd_cap_provider_port_descriptor {
1116faee822cSMathias Nyman __u8 bLength;
1117faee822cSMathias Nyman __u8 bDescriptorType;
1118faee822cSMathias Nyman __u8 bDevCapabilityType;
1119faee822cSMathias Nyman __u8 bReserved1;
1120faee822cSMathias Nyman __u8 bmCapabilities;
1121faee822cSMathias Nyman /* port will oerate under: */
1122faee822cSMathias Nyman #define USB_PD_CAP_PROVIDER_BC (1 << 0) /* BC */
1123faee822cSMathias Nyman #define USB_PD_CAP_PROVIDER_PD (1 << 1) /* PD */
1124faee822cSMathias Nyman #define USB_PD_CAP_PROVIDER_TYPE_C (1 << 2) /* USB Type-C Current */
112590ec9247SMathias Nyman __u8 bNumOfPDObjects;
112681cf4a45SMasakazu Mokuno __u8 bReserved2;
1127446fa3a9SJohn Youn __le32 wPowerDataObject[];
1128446fa3a9SJohn Youn } __attribute__((packed));
11297c014315SMathias Nyman
1130446fa3a9SJohn Youn /*
11317c014315SMathias Nyman * Precision time measurement capability descriptor: advertised by devices and
1132446fa3a9SJohn Youn * hubs that support PTM
11335e1ddb48SDavid Howells */
11345e1ddb48SDavid Howells #define USB_PTM_CAP_TYPE 0xb
11355e1ddb48SDavid Howells struct usb_ptm_cap_descriptor {
11365e1ddb48SDavid Howells __u8 bLength;
11375e1ddb48SDavid Howells __u8 bDescriptorType;
11385e1ddb48SDavid Howells __u8 bDevCapabilityType;
11395e1ddb48SDavid Howells } __attribute__((packed));
11405e1ddb48SDavid Howells
11415e1ddb48SDavid Howells #define USB_DT_USB_PTM_ID_SIZE 3
11425e1ddb48SDavid Howells /*
11435e1ddb48SDavid Howells * The size of the descriptor for the Sublink Speed Attribute Count
11445e1ddb48SDavid Howells * (SSAC) specified in bmAttributes[4:0]. SSAC is zero-based
11455e1ddb48SDavid Howells */
11465e1ddb48SDavid Howells #define USB_DT_USB_SSP_CAP_SIZE(ssac) (12 + (ssac + 1) * 4)
11475e1ddb48SDavid Howells
11485e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
11495e1ddb48SDavid Howells
11505e1ddb48SDavid Howells /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with
11515e1ddb48SDavid Howells * each endpoint descriptor for a wireless device
11525e1ddb48SDavid Howells */
11535e1ddb48SDavid Howells struct usb_wireless_ep_comp_descriptor {
11545e1ddb48SDavid Howells __u8 bLength;
11555e1ddb48SDavid Howells __u8 bDescriptorType;
11565e1ddb48SDavid Howells
11575e1ddb48SDavid Howells __u8 bMaxBurst;
11585e1ddb48SDavid Howells __u8 bMaxSequence;
11595e1ddb48SDavid Howells __le16 wMaxStreamDelay;
11605e1ddb48SDavid Howells __le16 wOverTheAirPacketSize;
11615e1ddb48SDavid Howells __u8 bOverTheAirInterval;
11625e1ddb48SDavid Howells __u8 bmCompAttributes;
11635e1ddb48SDavid Howells #define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */
11645e1ddb48SDavid Howells #define USB_ENDPOINT_SWITCH_NO 0
11655e1ddb48SDavid Howells #define USB_ENDPOINT_SWITCH_SWITCH 1
11665e1ddb48SDavid Howells #define USB_ENDPOINT_SWITCH_SCALE 2
11675e1ddb48SDavid Howells } __attribute__((packed));
11685e1ddb48SDavid Howells
11695e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
11705e1ddb48SDavid Howells
11715e1ddb48SDavid Howells /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
11725e1ddb48SDavid Howells * host and a device for connection set up, mutual authentication, and
11735e1ddb48SDavid Howells * exchanging short lived session keys. The handshake depends on a CC.
11745e1ddb48SDavid Howells */
11755e1ddb48SDavid Howells struct usb_handshake {
11765e1ddb48SDavid Howells __u8 bMessageNumber;
11775e1ddb48SDavid Howells __u8 bStatus;
11785e1ddb48SDavid Howells __u8 tTKID[3];
11795e1ddb48SDavid Howells __u8 bReserved;
11805e1ddb48SDavid Howells __u8 CDID[16];
11815e1ddb48SDavid Howells __u8 nonce[16];
11825e1ddb48SDavid Howells __u8 MIC[8];
11835e1ddb48SDavid Howells } __attribute__((packed));
11845e1ddb48SDavid Howells
11855e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
11865e1ddb48SDavid Howells
11875e1ddb48SDavid Howells /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
11885e1ddb48SDavid Howells * A CC may also be set up using non-wireless secure channels (including
11895e1ddb48SDavid Howells * wired USB!), and some devices may support CCs with multiple hosts.
11905e1ddb48SDavid Howells */
11915e1ddb48SDavid Howells struct usb_connection_context {
11928a1b2725SMathias Nyman __u8 CHID[16]; /* persistent host id */
11935e1ddb48SDavid Howells __u8 CDID[16]; /* device id (unique w/in host context) */
11945e1ddb48SDavid Howells __u8 CK[16]; /* connection key */
11955e1ddb48SDavid Howells } __attribute__((packed));
11965e1ddb48SDavid Howells
11975e1ddb48SDavid Howells /*-------------------------------------------------------------------------*/
11985e1ddb48SDavid Howells
11995e1ddb48SDavid Howells /* USB 2.0 defines three speeds, here's how Linux identifies them */
12005e1ddb48SDavid Howells
12015e1ddb48SDavid Howells enum usb_device_speed {
12025e1ddb48SDavid Howells USB_SPEED_UNKNOWN = 0, /* enumerating */
12035e1ddb48SDavid Howells USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
12045e1ddb48SDavid Howells USB_SPEED_HIGH, /* usb 2.0 */
12055e1ddb48SDavid Howells USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
12065e1ddb48SDavid Howells USB_SPEED_SUPER, /* usb 3.0 */
12075e1ddb48SDavid Howells USB_SPEED_SUPER_PLUS, /* usb 3.1 */
12085e1ddb48SDavid Howells };
12095e1ddb48SDavid Howells
12105e1ddb48SDavid Howells
12115e1ddb48SDavid Howells enum usb_device_state {
12125e1ddb48SDavid Howells /* NOTATTACHED isn't in the USB spec, and this state acts
12135e1ddb48SDavid Howells * the same as ATTACHED ... but it's clearer this way.
12145e1ddb48SDavid Howells */
12155e1ddb48SDavid Howells USB_STATE_NOTATTACHED = 0,
12165e1ddb48SDavid Howells
12175e1ddb48SDavid Howells /* chapter 9 and authentication (wireless) device states */
12185e1ddb48SDavid Howells USB_STATE_ATTACHED,
12195e1ddb48SDavid Howells USB_STATE_POWERED, /* wired */
12205e1ddb48SDavid Howells USB_STATE_RECONNECTING, /* auth */
12215e1ddb48SDavid Howells USB_STATE_UNAUTHENTICATED, /* auth */
12225e1ddb48SDavid Howells USB_STATE_DEFAULT, /* limited function */
12235e1ddb48SDavid Howells USB_STATE_ADDRESS,
12245e1ddb48SDavid Howells USB_STATE_CONFIGURED, /* most functions */
12255e1ddb48SDavid Howells
12265e1ddb48SDavid Howells USB_STATE_SUSPENDED
12275e1ddb48SDavid Howells
12285e1ddb48SDavid Howells /* NOTE: there are actually four different SUSPENDED
12295e1ddb48SDavid Howells * states, returning to POWERED, DEFAULT, ADDRESS, or
12305e1ddb48SDavid Howells * CONFIGURED respectively when SOF tokens flow again.
12315e1ddb48SDavid Howells * At this level there's no difference between L1 and L2
12325e1ddb48SDavid Howells * suspend states. (L2 being original USB 1.1 suspend.)
12335e1ddb48SDavid Howells */
12345e1ddb48SDavid Howells };
12355e1ddb48SDavid Howells
12365e1ddb48SDavid Howells enum usb3_link_state {
12375e1ddb48SDavid Howells USB3_LPM_U0 = 0,
12385e1ddb48SDavid Howells USB3_LPM_U1,
12395e1ddb48SDavid Howells USB3_LPM_U2,
12405e1ddb48SDavid Howells USB3_LPM_U3
12415e1ddb48SDavid Howells };
12425e1ddb48SDavid Howells
12435e1ddb48SDavid Howells /*
12445e1ddb48SDavid Howells * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1.
12455e1ddb48SDavid Howells * 0xff means the parent hub will accept transitions to U1, but will not
12465e1ddb48SDavid Howells * initiate a transition.
12475e1ddb48SDavid Howells *
12485e1ddb48SDavid Howells * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to
12495e1ddb48SDavid Howells * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved
12505e1ddb48SDavid Howells * values.
12515e1ddb48SDavid Howells *
12525e1ddb48SDavid Howells * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2.
12535e1ddb48SDavid Howells * 0xff means the parent hub will accept transitions to U2, but will not
12545e1ddb48SDavid Howells * initiate a transition.
12555e1ddb48SDavid Howells *
12565e1ddb48SDavid Howells * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to
12575e1ddb48SDavid Howells * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2
12585e1ddb48SDavid Howells * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means
12595e1ddb48SDavid Howells * 65.024ms.
12605e1ddb48SDavid Howells */
12615e1ddb48SDavid Howells #define USB3_LPM_DISABLED 0x0
12625e1ddb48SDavid Howells #define USB3_LPM_U1_MAX_TIMEOUT 0x7F
12635e1ddb48SDavid Howells #define USB3_LPM_U2_MAX_TIMEOUT 0xFE
12645e1ddb48SDavid Howells #define USB3_LPM_DEVICE_INITIATED 0xFF
12655e1ddb48SDavid Howells
12665e1ddb48SDavid Howells struct usb_set_sel_req {
12675e1ddb48SDavid Howells __u8 u1_sel;
12685e1ddb48SDavid Howells __u8 u1_pel;
12695e1ddb48SDavid Howells __le16 u2_sel;
12705e1ddb48SDavid Howells __le16 u2_pel;
12715e1ddb48SDavid Howells } __attribute__ ((packed));
12727f317d34SAlexander A. Klimov
12735e1ddb48SDavid Howells /*
12745e1ddb48SDavid Howells * The Set System Exit Latency control transfer provides one byte each for
12755e1ddb48SDavid Howells * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each
12765e1ddb48SDavid Howells * are two bytes long.
1277 */
1278 #define USB3_LPM_MAX_U1_SEL_PEL 0xFF
1279 #define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF
1280
1281 /*-------------------------------------------------------------------------*/
1282
1283 /*
1284 * As per USB compliance update, a device that is actively drawing
1285 * more than 100mA from USB must report itself as bus-powered in
1286 * the GetStatus(DEVICE) call.
1287 * https://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34
1288 */
1289 #define USB_SELF_POWER_VBUS_MAX_DRAW 100
1290
1291 #endif /* _UAPI__LINUX_USB_CH9_H */
1292