logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ch9.h (40171B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * This file holds USB constants and structures that are needed for
  4. * USB device APIs. These are used by the USB device model, which is
  5. * defined in chapter 9 of the USB 2.0 specification and in the
  6. * Wireless USB 1.0 spec (now defunct). Linux has several APIs in C that
  7. * need these:
  8. *
  9. * - the master/host side Linux-USB kernel driver API;
  10. * - the "usbfs" user space API; and
  11. * - the Linux "gadget" slave/device/peripheral side driver API.
  12. *
  13. * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
  14. * act either as a USB master/host or as a USB slave/device. That means
  15. * the master and slave side APIs benefit from working well together.
  16. *
  17. * Note all descriptors are declared '__attribute__((packed))' so that:
  18. *
  19. * [a] they never get padded, either internally (USB spec writers
  20. * probably handled that) or externally;
  21. *
  22. * [b] so that accessing bigger-than-a-bytes fields will never
  23. * generate bus errors on any platform, even when the location of
  24. * its descriptor inside a bundle isn't "naturally aligned", and
  25. *
  26. * [c] for consistency, removing all doubt even when it appears to
  27. * someone that the two other points are non-issues for that
  28. * particular descriptor type.
  29. */
  30. #ifndef __LINUX_USB_CH9_H
  31. #define __LINUX_USB_CH9_H
  32. #include <linux/types.h> /* __u8 etc */
  33. #include <asm/byteorder.h> /* le16_to_cpu */
  34. /*-------------------------------------------------------------------------*/
  35. /* CONTROL REQUEST SUPPORT */
  36. /*
  37. * USB directions
  38. *
  39. * This bit flag is used in endpoint descriptors' bEndpointAddress field.
  40. * It's also one of three fields in control requests bRequestType.
  41. */
  42. #define USB_DIR_OUT 0 /* to device */
  43. #define USB_DIR_IN 0x80 /* to host */
  44. /*
  45. * USB types, the second of three bRequestType fields
  46. */
  47. #define USB_TYPE_MASK (0x03 << 5)
  48. #define USB_TYPE_STANDARD (0x00 << 5)
  49. #define USB_TYPE_CLASS (0x01 << 5)
  50. #define USB_TYPE_VENDOR (0x02 << 5)
  51. #define USB_TYPE_RESERVED (0x03 << 5)
  52. /*
  53. * USB recipients, the third of three bRequestType fields
  54. */
  55. #define USB_RECIP_MASK 0x1f
  56. #define USB_RECIP_DEVICE 0x00
  57. #define USB_RECIP_INTERFACE 0x01
  58. #define USB_RECIP_ENDPOINT 0x02
  59. #define USB_RECIP_OTHER 0x03
  60. /* From Wireless USB 1.0 */
  61. #define USB_RECIP_PORT 0x04
  62. #define USB_RECIP_RPIPE 0x05
  63. /*
  64. * Standard requests, for the bRequest field of a SETUP packet.
  65. *
  66. * These are qualified by the bRequestType field, so that for example
  67. * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
  68. * by a GET_STATUS request.
  69. */
  70. #define USB_REQ_GET_STATUS 0x00
  71. #define USB_REQ_CLEAR_FEATURE 0x01
  72. #define USB_REQ_SET_FEATURE 0x03
  73. #define USB_REQ_SET_ADDRESS 0x05
  74. #define USB_REQ_GET_DESCRIPTOR 0x06
  75. #define USB_REQ_SET_DESCRIPTOR 0x07
  76. #define USB_REQ_GET_CONFIGURATION 0x08
  77. #define USB_REQ_SET_CONFIGURATION 0x09
  78. #define USB_REQ_GET_INTERFACE 0x0A
  79. #define USB_REQ_SET_INTERFACE 0x0B
  80. #define USB_REQ_SYNCH_FRAME 0x0C
  81. #define USB_REQ_SET_SEL 0x30
  82. #define USB_REQ_SET_ISOCH_DELAY 0x31
  83. #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
  84. #define USB_REQ_GET_ENCRYPTION 0x0E
  85. #define USB_REQ_RPIPE_ABORT 0x0E
  86. #define USB_REQ_SET_HANDSHAKE 0x0F
  87. #define USB_REQ_RPIPE_RESET 0x0F
  88. #define USB_REQ_GET_HANDSHAKE 0x10
  89. #define USB_REQ_SET_CONNECTION 0x11
  90. #define USB_REQ_SET_SECURITY_DATA 0x12
  91. #define USB_REQ_GET_SECURITY_DATA 0x13
  92. #define USB_REQ_SET_WUSB_DATA 0x14
  93. #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
  94. #define USB_REQ_LOOPBACK_DATA_READ 0x16
  95. #define USB_REQ_SET_INTERFACE_DS 0x17
  96. /* specific requests for USB Power Delivery */
  97. #define USB_REQ_GET_PARTNER_PDO 20
  98. #define USB_REQ_GET_BATTERY_STATUS 21
  99. #define USB_REQ_SET_PDO 22
  100. #define USB_REQ_GET_VDM 23
  101. #define USB_REQ_SEND_VDM 24
  102. /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command,
  103. * used by hubs to put ports into a new L1 suspend state, except that it
  104. * forgot to define its number ...
  105. */
  106. /*
  107. * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
  108. * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
  109. * are at most sixteen features of each type.) Hubs may also support a
  110. * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
  111. */
  112. #define USB_DEVICE_SELF_POWERED 0 /* (read only) */
  113. #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
  114. #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
  115. #define USB_DEVICE_BATTERY 2 /* (wireless) */
  116. #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
  117. #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
  118. #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
  119. #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
  120. #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
  121. /*
  122. * Test Mode Selectors
  123. * See USB 2.0 spec Table 9-7
  124. */
  125. #define USB_TEST_J 1
  126. #define USB_TEST_K 2
  127. #define USB_TEST_SE0_NAK 3
  128. #define USB_TEST_PACKET 4
  129. #define USB_TEST_FORCE_ENABLE 5
  130. /* Status Type */
  131. #define USB_STATUS_TYPE_STANDARD 0
  132. #define USB_STATUS_TYPE_PTM 1
  133. /*
  134. * New Feature Selectors as added by USB 3.0
  135. * See USB 3.0 spec Table 9-7
  136. */
  137. #define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */
  138. #define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */
  139. #define USB_DEVICE_LTM_ENABLE 50 /* dev may send LTM */
  140. #define USB_INTRF_FUNC_SUSPEND 0 /* function suspend */
  141. #define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
  142. /*
  143. * Suspend Options, Table 9-8 USB 3.0 spec
  144. */
  145. #define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
  146. #define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))
  147. /*
  148. * Interface status, Figure 9-5 USB 3.0 spec
  149. */
  150. #define USB_INTRF_STAT_FUNC_RW_CAP 1
  151. #define USB_INTRF_STAT_FUNC_RW 2
  152. #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
  153. /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */
  154. #define USB_DEV_STAT_U1_ENABLED 2 /* transition into U1 state */
  155. #define USB_DEV_STAT_U2_ENABLED 3 /* transition into U2 state */
  156. #define USB_DEV_STAT_LTM_ENABLED 4 /* Latency tolerance messages */
  157. /*
  158. * Feature selectors from Table 9-8 USB Power Delivery spec
  159. */
  160. #define USB_DEVICE_BATTERY_WAKE_MASK 40
  161. #define USB_DEVICE_OS_IS_PD_AWARE 41
  162. #define USB_DEVICE_POLICY_MODE 42
  163. #define USB_PORT_PR_SWAP 43
  164. #define USB_PORT_GOTO_MIN 44
  165. #define USB_PORT_RETURN_POWER 45
  166. #define USB_PORT_ACCEPT_PD_REQUEST 46
  167. #define USB_PORT_REJECT_PD_REQUEST 47
  168. #define USB_PORT_PORT_PD_RESET 48
  169. #define USB_PORT_C_PORT_PD_CHANGE 49
  170. #define USB_PORT_CABLE_PD_RESET 50
  171. #define USB_DEVICE_CHARGING_POLICY 54
  172. /**
  173. * struct usb_ctrlrequest - SETUP data for a USB device control request
  174. * @bRequestType: matches the USB bmRequestType field
  175. * @bRequest: matches the USB bRequest field
  176. * @wValue: matches the USB wValue field (le16 byte order)
  177. * @wIndex: matches the USB wIndex field (le16 byte order)
  178. * @wLength: matches the USB wLength field (le16 byte order)
  179. *
  180. * This structure is used to send control requests to a USB device. It matches
  181. * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the
  182. * USB spec for a fuller description of the different fields, and what they are
  183. * used for.
  184. *
  185. * Note that the driver for any interface can issue control requests.
  186. * For most devices, interfaces don't coordinate with each other, so
  187. * such requests may be made at any time.
  188. */
  189. struct usb_ctrlrequest {
  190. __u8 bRequestType;
  191. __u8 bRequest;
  192. __le16 wValue;
  193. __le16 wIndex;
  194. __le16 wLength;
  195. } __attribute__ ((packed));
  196. /*-------------------------------------------------------------------------*/
  197. /*
  198. * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
  199. * (rarely) accepted by SET_DESCRIPTOR.
  200. *
  201. * Note that all multi-byte values here are encoded in little endian
  202. * byte order "on the wire". Within the kernel and when exposed
  203. * through the Linux-USB APIs, they are not converted to cpu byte
  204. * order; it is the responsibility of the client code to do this.
  205. * The single exception is when device and configuration descriptors (but
  206. * not other descriptors) are read from character devices
  207. * (i.e. /dev/bus/usb/BBB/DDD);
  208. * in this case the fields are converted to host endianness by the kernel.
  209. */
  210. /*
  211. * Descriptor types ... USB 2.0 spec table 9.5
  212. */
  213. #define USB_DT_DEVICE 0x01
  214. #define USB_DT_CONFIG 0x02
  215. #define USB_DT_STRING 0x03
  216. #define USB_DT_INTERFACE 0x04
  217. #define USB_DT_ENDPOINT 0x05
  218. #define USB_DT_DEVICE_QUALIFIER 0x06
  219. #define USB_DT_OTHER_SPEED_CONFIG 0x07
  220. #define USB_DT_INTERFACE_POWER 0x08
  221. /* these are from a minor usb 2.0 revision (ECN) */
  222. #define USB_DT_OTG 0x09
  223. #define USB_DT_DEBUG 0x0a
  224. #define USB_DT_INTERFACE_ASSOCIATION 0x0b
  225. /* these are from the Wireless USB spec */
  226. #define USB_DT_SECURITY 0x0c
  227. #define USB_DT_KEY 0x0d
  228. #define USB_DT_ENCRYPTION_TYPE 0x0e
  229. #define USB_DT_BOS 0x0f
  230. #define USB_DT_DEVICE_CAPABILITY 0x10
  231. #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
  232. #define USB_DT_WIRE_ADAPTER 0x21
  233. /* From USB Device Firmware Upgrade Specification, Revision 1.1 */
  234. #define USB_DT_DFU_FUNCTIONAL 0x21
  235. /* these are from the Wireless USB spec */
  236. #define USB_DT_RPIPE 0x22
  237. #define USB_DT_CS_RADIO_CONTROL 0x23
  238. /* From the T10 UAS specification */
  239. #define USB_DT_PIPE_USAGE 0x24
  240. /* From the USB 3.0 spec */
  241. #define USB_DT_SS_ENDPOINT_COMP 0x30
  242. /* From the USB 3.1 spec */
  243. #define USB_DT_SSP_ISOC_ENDPOINT_COMP 0x31
  244. /* Conventional codes for class-specific descriptors. The convention is
  245. * defined in the USB "Common Class" Spec (3.11). Individual class specs
  246. * are authoritative for their usage, not the "common class" writeup.
  247. */
  248. #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE)
  249. #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG)
  250. #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING)
  251. #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE)
  252. #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT)
  253. /* All standard descriptors have these 2 fields at the beginning */
  254. struct usb_descriptor_header {
  255. __u8 bLength;
  256. __u8 bDescriptorType;
  257. } __attribute__ ((packed));
  258. /*-------------------------------------------------------------------------*/
  259. /* USB_DT_DEVICE: Device descriptor */
  260. struct usb_device_descriptor {
  261. __u8 bLength;
  262. __u8 bDescriptorType;
  263. __le16 bcdUSB;
  264. __u8 bDeviceClass;
  265. __u8 bDeviceSubClass;
  266. __u8 bDeviceProtocol;
  267. __u8 bMaxPacketSize0;
  268. __le16 idVendor;
  269. __le16 idProduct;
  270. __le16 bcdDevice;
  271. __u8 iManufacturer;
  272. __u8 iProduct;
  273. __u8 iSerialNumber;
  274. __u8 bNumConfigurations;
  275. } __attribute__ ((packed));
  276. #define USB_DT_DEVICE_SIZE 18
  277. /*
  278. * Device and/or Interface Class codes
  279. * as found in bDeviceClass or bInterfaceClass
  280. * and defined by www.usb.org documents
  281. */
  282. #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
  283. #define USB_CLASS_AUDIO 1
  284. #define USB_CLASS_COMM 2
  285. #define USB_CLASS_HID 3
  286. #define USB_CLASS_PHYSICAL 5
  287. #define USB_CLASS_STILL_IMAGE 6
  288. #define USB_CLASS_PRINTER 7
  289. #define USB_CLASS_MASS_STORAGE 8
  290. #define USB_CLASS_HUB 9
  291. #define USB_CLASS_CDC_DATA 0x0a
  292. #define USB_CLASS_CSCID 0x0b /* chip+ smart card */
  293. #define USB_CLASS_CONTENT_SEC 0x0d /* content security */
  294. #define USB_CLASS_VIDEO 0x0e
  295. #define USB_CLASS_WIRELESS_CONTROLLER 0xe0
  296. #define USB_CLASS_PERSONAL_HEALTHCARE 0x0f
  297. #define USB_CLASS_AUDIO_VIDEO 0x10
  298. #define USB_CLASS_BILLBOARD 0x11
  299. #define USB_CLASS_USB_TYPE_C_BRIDGE 0x12
  300. #define USB_CLASS_MISC 0xef
  301. #define USB_CLASS_APP_SPEC 0xfe
  302. #define USB_SUBCLASS_DFU 0x01
  303. #define USB_CLASS_VENDOR_SPEC 0xff
  304. #define USB_SUBCLASS_VENDOR_SPEC 0xff
  305. /*-------------------------------------------------------------------------*/
  306. /* USB_DT_CONFIG: Configuration descriptor information.
  307. *
  308. * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
  309. * descriptor type is different. Highspeed-capable devices can look
  310. * different depending on what speed they're currently running. Only
  311. * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
  312. * descriptors.
  313. */
  314. struct usb_config_descriptor {
  315. __u8 bLength;
  316. __u8 bDescriptorType;
  317. __le16 wTotalLength;
  318. __u8 bNumInterfaces;
  319. __u8 bConfigurationValue;
  320. __u8 iConfiguration;
  321. __u8 bmAttributes;
  322. __u8 bMaxPower;
  323. } __attribute__ ((packed));
  324. #define USB_DT_CONFIG_SIZE 9
  325. /* from config descriptor bmAttributes */
  326. #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */
  327. #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */
  328. #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */
  329. #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */
  330. /*-------------------------------------------------------------------------*/
  331. /* USB String descriptors can contain at most 126 characters. */
  332. #define USB_MAX_STRING_LEN 126
  333. /* USB_DT_STRING: String descriptor */
  334. struct usb_string_descriptor {
  335. __u8 bLength;
  336. __u8 bDescriptorType;
  337. union {
  338. __le16 legacy_padding;
  339. __DECLARE_FLEX_ARRAY(__le16, wData); /* UTF-16LE encoded */
  340. };
  341. } __attribute__ ((packed));
  342. /* note that "string" zero is special, it holds language codes that
  343. * the device supports, not Unicode characters.
  344. */
  345. /*-------------------------------------------------------------------------*/
  346. /* USB_DT_INTERFACE: Interface descriptor */
  347. struct usb_interface_descriptor {
  348. __u8 bLength;
  349. __u8 bDescriptorType;
  350. __u8 bInterfaceNumber;
  351. __u8 bAlternateSetting;
  352. __u8 bNumEndpoints;
  353. __u8 bInterfaceClass;
  354. __u8 bInterfaceSubClass;
  355. __u8 bInterfaceProtocol;
  356. __u8 iInterface;
  357. } __attribute__ ((packed));
  358. #define USB_DT_INTERFACE_SIZE 9
  359. /*-------------------------------------------------------------------------*/
  360. /* USB_DT_ENDPOINT: Endpoint descriptor */
  361. struct usb_endpoint_descriptor {
  362. __u8 bLength;
  363. __u8 bDescriptorType;
  364. __u8 bEndpointAddress;
  365. __u8 bmAttributes;
  366. __le16 wMaxPacketSize;
  367. __u8 bInterval;
  368. /* NOTE: these two are _only_ in audio endpoints. */
  369. /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
  370. __u8 bRefresh;
  371. __u8 bSynchAddress;
  372. } __attribute__ ((packed));
  373. #define USB_DT_ENDPOINT_SIZE 7
  374. #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  375. /*
  376. * Endpoints
  377. */
  378. #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
  379. #define USB_ENDPOINT_DIR_MASK 0x80
  380. #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
  381. #define USB_ENDPOINT_XFER_CONTROL 0
  382. #define USB_ENDPOINT_XFER_ISOC 1
  383. #define USB_ENDPOINT_XFER_BULK 2
  384. #define USB_ENDPOINT_XFER_INT 3
  385. #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
  386. #define USB_ENDPOINT_MAXP_MASK 0x07ff
  387. #define USB_EP_MAXP_MULT_SHIFT 11
  388. #define USB_EP_MAXP_MULT_MASK (3 << USB_EP_MAXP_MULT_SHIFT)
  389. #define USB_EP_MAXP_MULT(m) \
  390. (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
  391. /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
  392. #define USB_ENDPOINT_INTRTYPE 0x30
  393. #define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
  394. #define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4)
  395. #define USB_ENDPOINT_SYNCTYPE 0x0c
  396. #define USB_ENDPOINT_SYNC_NONE (0 << 2)
  397. #define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
  398. #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
  399. #define USB_ENDPOINT_SYNC_SYNC (3 << 2)
  400. #define USB_ENDPOINT_USAGE_MASK 0x30
  401. #define USB_ENDPOINT_USAGE_DATA 0x00
  402. #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
  403. #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */
  404. /*-------------------------------------------------------------------------*/
  405. /**
  406. * usb_endpoint_num - get the endpoint's number
  407. * @epd: endpoint to be checked
  408. *
  409. * Returns @epd's number: 0 to 15.
  410. */
  411. static __inline__ int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
  412. {
  413. return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  414. }
  415. /**
  416. * usb_endpoint_type - get the endpoint's transfer type
  417. * @epd: endpoint to be checked
  418. *
  419. * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
  420. * to @epd's transfer type.
  421. */
  422. static __inline__ int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
  423. {
  424. return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
  425. }
  426. /**
  427. * usb_endpoint_dir_in - check if the endpoint has IN direction
  428. * @epd: endpoint to be checked
  429. *
  430. * Returns true if the endpoint is of type IN, otherwise it returns false.
  431. */
  432. static __inline__ int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
  433. {
  434. return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
  435. }
  436. /**
  437. * usb_endpoint_dir_out - check if the endpoint has OUT direction
  438. * @epd: endpoint to be checked
  439. *
  440. * Returns true if the endpoint is of type OUT, otherwise it returns false.
  441. */
  442. static __inline__ int usb_endpoint_dir_out(
  443. const struct usb_endpoint_descriptor *epd)
  444. {
  445. return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
  446. }
  447. /**
  448. * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
  449. * @epd: endpoint to be checked
  450. *
  451. * Returns true if the endpoint is of type bulk, otherwise it returns false.
  452. */
  453. static __inline__ int usb_endpoint_xfer_bulk(
  454. const struct usb_endpoint_descriptor *epd)
  455. {
  456. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  457. USB_ENDPOINT_XFER_BULK);
  458. }
  459. /**
  460. * usb_endpoint_xfer_control - check if the endpoint has control transfer type
  461. * @epd: endpoint to be checked
  462. *
  463. * Returns true if the endpoint is of type control, otherwise it returns false.
  464. */
  465. static __inline__ int usb_endpoint_xfer_control(
  466. const struct usb_endpoint_descriptor *epd)
  467. {
  468. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  469. USB_ENDPOINT_XFER_CONTROL);
  470. }
  471. /**
  472. * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
  473. * @epd: endpoint to be checked
  474. *
  475. * Returns true if the endpoint is of type interrupt, otherwise it returns
  476. * false.
  477. */
  478. static __inline__ int usb_endpoint_xfer_int(
  479. const struct usb_endpoint_descriptor *epd)
  480. {
  481. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  482. USB_ENDPOINT_XFER_INT);
  483. }
  484. /**
  485. * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
  486. * @epd: endpoint to be checked
  487. *
  488. * Returns true if the endpoint is of type isochronous, otherwise it returns
  489. * false.
  490. */
  491. static __inline__ int usb_endpoint_xfer_isoc(
  492. const struct usb_endpoint_descriptor *epd)
  493. {
  494. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  495. USB_ENDPOINT_XFER_ISOC);
  496. }
  497. /**
  498. * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
  499. * @epd: endpoint to be checked
  500. *
  501. * Returns true if the endpoint has bulk transfer type and IN direction,
  502. * otherwise it returns false.
  503. */
  504. static __inline__ int usb_endpoint_is_bulk_in(
  505. const struct usb_endpoint_descriptor *epd)
  506. {
  507. return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
  508. }
  509. /**
  510. * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
  511. * @epd: endpoint to be checked
  512. *
  513. * Returns true if the endpoint has bulk transfer type and OUT direction,
  514. * otherwise it returns false.
  515. */
  516. static __inline__ int usb_endpoint_is_bulk_out(
  517. const struct usb_endpoint_descriptor *epd)
  518. {
  519. return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
  520. }
  521. /**
  522. * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
  523. * @epd: endpoint to be checked
  524. *
  525. * Returns true if the endpoint has interrupt transfer type and IN direction,
  526. * otherwise it returns false.
  527. */
  528. static __inline__ int usb_endpoint_is_int_in(
  529. const struct usb_endpoint_descriptor *epd)
  530. {
  531. return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
  532. }
  533. /**
  534. * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
  535. * @epd: endpoint to be checked
  536. *
  537. * Returns true if the endpoint has interrupt transfer type and OUT direction,
  538. * otherwise it returns false.
  539. */
  540. static __inline__ int usb_endpoint_is_int_out(
  541. const struct usb_endpoint_descriptor *epd)
  542. {
  543. return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
  544. }
  545. /**
  546. * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
  547. * @epd: endpoint to be checked
  548. *
  549. * Returns true if the endpoint has isochronous transfer type and IN direction,
  550. * otherwise it returns false.
  551. */
  552. static __inline__ int usb_endpoint_is_isoc_in(
  553. const struct usb_endpoint_descriptor *epd)
  554. {
  555. return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
  556. }
  557. /**
  558. * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
  559. * @epd: endpoint to be checked
  560. *
  561. * Returns true if the endpoint has isochronous transfer type and OUT direction,
  562. * otherwise it returns false.
  563. */
  564. static __inline__ int usb_endpoint_is_isoc_out(
  565. const struct usb_endpoint_descriptor *epd)
  566. {
  567. return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
  568. }
  569. /**
  570. * usb_endpoint_maxp - get endpoint's max packet size
  571. * @epd: endpoint to be checked
  572. *
  573. * Returns @epd's max packet bits [10:0]
  574. */
  575. static __inline__ int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
  576. {
  577. return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK;
  578. }
  579. /**
  580. * usb_endpoint_maxp_mult - get endpoint's transactional opportunities
  581. * @epd: endpoint to be checked
  582. *
  583. * Return @epd's wMaxPacketSize[12:11] + 1
  584. */
  585. static __inline__ int
  586. usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd)
  587. {
  588. int maxp = __le16_to_cpu(epd->wMaxPacketSize);
  589. return USB_EP_MAXP_MULT(maxp) + 1;
  590. }
  591. static __inline__ int usb_endpoint_interrupt_type(
  592. const struct usb_endpoint_descriptor *epd)
  593. {
  594. return epd->bmAttributes & USB_ENDPOINT_INTRTYPE;
  595. }
  596. /*-------------------------------------------------------------------------*/
  597. /* USB_DT_SSP_ISOC_ENDPOINT_COMP: SuperSpeedPlus Isochronous Endpoint Companion
  598. * descriptor
  599. */
  600. struct usb_ssp_isoc_ep_comp_descriptor {
  601. __u8 bLength;
  602. __u8 bDescriptorType;
  603. __le16 wReseved;
  604. __le32 dwBytesPerInterval;
  605. } __attribute__ ((packed));
  606. #define USB_DT_SSP_ISOC_EP_COMP_SIZE 8
  607. /*-------------------------------------------------------------------------*/
  608. /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
  609. struct usb_ss_ep_comp_descriptor {
  610. __u8 bLength;
  611. __u8 bDescriptorType;
  612. __u8 bMaxBurst;
  613. __u8 bmAttributes;
  614. __le16 wBytesPerInterval;
  615. } __attribute__ ((packed));
  616. #define USB_DT_SS_EP_COMP_SIZE 6
  617. /* Bits 4:0 of bmAttributes if this is a bulk endpoint */
  618. static __inline__ int
  619. usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp)
  620. {
  621. int max_streams;
  622. if (!comp)
  623. return 0;
  624. max_streams = comp->bmAttributes & 0x1f;
  625. if (!max_streams)
  626. return 0;
  627. max_streams = 1 << max_streams;
  628. return max_streams;
  629. }
  630. /* Bits 1:0 of bmAttributes if this is an isoc endpoint */
  631. #define USB_SS_MULT(p) (1 + ((p) & 0x3))
  632. /* Bit 7 of bmAttributes if a SSP isoc endpoint companion descriptor exists */
  633. #define USB_SS_SSP_ISOC_COMP(p) ((p) & (1 << 7))
  634. /*-------------------------------------------------------------------------*/
  635. /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
  636. struct usb_qualifier_descriptor {
  637. __u8 bLength;
  638. __u8 bDescriptorType;
  639. __le16 bcdUSB;
  640. __u8 bDeviceClass;
  641. __u8 bDeviceSubClass;
  642. __u8 bDeviceProtocol;
  643. __u8 bMaxPacketSize0;
  644. __u8 bNumConfigurations;
  645. __u8 bRESERVED;
  646. } __attribute__ ((packed));
  647. /*-------------------------------------------------------------------------*/
  648. /* USB_DT_OTG (from OTG 1.0a supplement) */
  649. struct usb_otg_descriptor {
  650. __u8 bLength;
  651. __u8 bDescriptorType;
  652. __u8 bmAttributes; /* support for HNP, SRP, etc */
  653. } __attribute__ ((packed));
  654. /* USB_DT_OTG (from OTG 2.0 supplement) */
  655. struct usb_otg20_descriptor {
  656. __u8 bLength;
  657. __u8 bDescriptorType;
  658. __u8 bmAttributes; /* support for HNP, SRP and ADP, etc */
  659. __le16 bcdOTG; /* OTG and EH supplement release number
  660. * in binary-coded decimal(i.e. 2.0 is 0200H)
  661. */
  662. } __attribute__ ((packed));
  663. /* from usb_otg_descriptor.bmAttributes */
  664. #define USB_OTG_SRP (1 << 0)
  665. #define USB_OTG_HNP (1 << 1) /* swap host/device roles */
  666. #define USB_OTG_ADP (1 << 2) /* support ADP */
  667. /* OTG 3.0 */
  668. #define USB_OTG_RSP (1 << 3) /* support RSP */
  669. #define OTG_STS_SELECTOR 0xF000 /* OTG status selector */
  670. /*-------------------------------------------------------------------------*/
  671. /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */
  672. struct usb_debug_descriptor {
  673. __u8 bLength;
  674. __u8 bDescriptorType;
  675. /* bulk endpoints with 8 byte maxpacket */
  676. __u8 bDebugInEndpoint;
  677. __u8 bDebugOutEndpoint;
  678. } __attribute__((packed));
  679. /*-------------------------------------------------------------------------*/
  680. /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
  681. struct usb_interface_assoc_descriptor {
  682. __u8 bLength;
  683. __u8 bDescriptorType;
  684. __u8 bFirstInterface;
  685. __u8 bInterfaceCount;
  686. __u8 bFunctionClass;
  687. __u8 bFunctionSubClass;
  688. __u8 bFunctionProtocol;
  689. __u8 iFunction;
  690. } __attribute__ ((packed));
  691. #define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
  692. /*-------------------------------------------------------------------------*/
  693. /* USB_DT_SECURITY: group of wireless security descriptors, including
  694. * encryption types available for setting up a CC/association.
  695. */
  696. struct usb_security_descriptor {
  697. __u8 bLength;
  698. __u8 bDescriptorType;
  699. __le16 wTotalLength;
  700. __u8 bNumEncryptionTypes;
  701. } __attribute__((packed));
  702. /*-------------------------------------------------------------------------*/
  703. /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys
  704. * may be retrieved.
  705. */
  706. struct usb_key_descriptor {
  707. __u8 bLength;
  708. __u8 bDescriptorType;
  709. __u8 tTKID[3];
  710. __u8 bReserved;
  711. __u8 bKeyData[];
  712. } __attribute__((packed));
  713. /*-------------------------------------------------------------------------*/
  714. /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */
  715. struct usb_encryption_descriptor {
  716. __u8 bLength;
  717. __u8 bDescriptorType;
  718. __u8 bEncryptionType;
  719. #define USB_ENC_TYPE_UNSECURE 0
  720. #define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */
  721. #define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */
  722. #define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */
  723. __u8 bEncryptionValue; /* use in SET_ENCRYPTION */
  724. __u8 bAuthKeyIndex;
  725. } __attribute__((packed));
  726. /*-------------------------------------------------------------------------*/
  727. /* USB_DT_BOS: group of device-level capabilities */
  728. struct usb_bos_descriptor {
  729. __u8 bLength;
  730. __u8 bDescriptorType;
  731. __le16 wTotalLength;
  732. __u8 bNumDeviceCaps;
  733. } __attribute__((packed));
  734. #define USB_DT_BOS_SIZE 5
  735. /*-------------------------------------------------------------------------*/
  736. /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */
  737. struct usb_dev_cap_header {
  738. __u8 bLength;
  739. __u8 bDescriptorType;
  740. __u8 bDevCapabilityType;
  741. } __attribute__((packed));
  742. #define USB_CAP_TYPE_WIRELESS_USB 1
  743. struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
  744. __u8 bLength;
  745. __u8 bDescriptorType;
  746. __u8 bDevCapabilityType;
  747. __u8 bmAttributes;
  748. #define USB_WIRELESS_P2P_DRD (1 << 1)
  749. #define USB_WIRELESS_BEACON_MASK (3 << 2)
  750. #define USB_WIRELESS_BEACON_SELF (1 << 2)
  751. #define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
  752. #define USB_WIRELESS_BEACON_NONE (3 << 2)
  753. __le16 wPHYRates; /* bit rates, Mbps */
  754. #define USB_WIRELESS_PHY_53 (1 << 0) /* always set */
  755. #define USB_WIRELESS_PHY_80 (1 << 1)
  756. #define USB_WIRELESS_PHY_107 (1 << 2) /* always set */
  757. #define USB_WIRELESS_PHY_160 (1 << 3)
  758. #define USB_WIRELESS_PHY_200 (1 << 4) /* always set */
  759. #define USB_WIRELESS_PHY_320 (1 << 5)
  760. #define USB_WIRELESS_PHY_400 (1 << 6)
  761. #define USB_WIRELESS_PHY_480 (1 << 7)
  762. __u8 bmTFITXPowerInfo; /* TFI power levels */
  763. __u8 bmFFITXPowerInfo; /* FFI power levels */
  764. __le16 bmBandGroup;
  765. __u8 bReserved;
  766. } __attribute__((packed));
  767. #define USB_DT_USB_WIRELESS_CAP_SIZE 11
  768. /* USB 2.0 Extension descriptor */
  769. #define USB_CAP_TYPE_EXT 2
  770. struct usb_ext_cap_descriptor { /* Link Power Management */
  771. __u8 bLength;
  772. __u8 bDescriptorType;
  773. __u8 bDevCapabilityType;
  774. __le32 bmAttributes;
  775. #define USB_LPM_SUPPORT (1 << 1) /* supports LPM */
  776. #define USB_BESL_SUPPORT (1 << 2) /* supports BESL */
  777. #define USB_BESL_BASELINE_VALID (1 << 3) /* Baseline BESL valid*/
  778. #define USB_BESL_DEEP_VALID (1 << 4) /* Deep BESL valid */
  779. #define USB_SET_BESL_BASELINE(p) (((p) & 0xf) << 8)
  780. #define USB_SET_BESL_DEEP(p) (((p) & 0xf) << 12)
  781. #define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8)
  782. #define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12)
  783. } __attribute__((packed));
  784. #define USB_DT_USB_EXT_CAP_SIZE 7
  785. /*
  786. * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB
  787. * specific device level capabilities
  788. */
  789. #define USB_SS_CAP_TYPE 3
  790. struct usb_ss_cap_descriptor { /* Link Power Management */
  791. __u8 bLength;
  792. __u8 bDescriptorType;
  793. __u8 bDevCapabilityType;
  794. __u8 bmAttributes;
  795. #define USB_LTM_SUPPORT (1 << 1) /* supports LTM */
  796. __le16 wSpeedSupported;
  797. #define USB_LOW_SPEED_OPERATION (1) /* Low speed operation */
  798. #define USB_FULL_SPEED_OPERATION (1 << 1) /* Full speed operation */
  799. #define USB_HIGH_SPEED_OPERATION (1 << 2) /* High speed operation */
  800. #define USB_5GBPS_OPERATION (1 << 3) /* Operation at 5Gbps */
  801. __u8 bFunctionalitySupport;
  802. __u8 bU1devExitLat;
  803. __le16 bU2DevExitLat;
  804. } __attribute__((packed));
  805. #define USB_DT_USB_SS_CAP_SIZE 10
  806. /*
  807. * Container ID Capability descriptor: Defines the instance unique ID used to
  808. * identify the instance across all operating modes
  809. */
  810. #define CONTAINER_ID_TYPE 4
  811. struct usb_ss_container_id_descriptor {
  812. __u8 bLength;
  813. __u8 bDescriptorType;
  814. __u8 bDevCapabilityType;
  815. __u8 bReserved;
  816. __u8 ContainerID[16]; /* 128-bit number */
  817. } __attribute__((packed));
  818. #define USB_DT_USB_SS_CONTN_ID_SIZE 20
  819. /*
  820. * Platform Device Capability descriptor: Defines platform specific device
  821. * capabilities
  822. */
  823. #define USB_PLAT_DEV_CAP_TYPE 5
  824. struct usb_plat_dev_cap_descriptor {
  825. __u8 bLength;
  826. __u8 bDescriptorType;
  827. __u8 bDevCapabilityType;
  828. __u8 bReserved;
  829. __u8 UUID[16];
  830. __u8 CapabilityData[];
  831. } __attribute__((packed));
  832. #define USB_DT_USB_PLAT_DEV_CAP_SIZE(capability_data_size) (20 + capability_data_size)
  833. /*
  834. * SuperSpeed Plus USB Capability descriptor: Defines the set of
  835. * SuperSpeed Plus USB specific device level capabilities
  836. */
  837. #define USB_SSP_CAP_TYPE 0xa
  838. struct usb_ssp_cap_descriptor {
  839. __u8 bLength;
  840. __u8 bDescriptorType;
  841. __u8 bDevCapabilityType;
  842. __u8 bReserved;
  843. __le32 bmAttributes;
  844. #define USB_SSP_SUBLINK_SPEED_ATTRIBS (0x1f << 0) /* sublink speed entries */
  845. #define USB_SSP_SUBLINK_SPEED_IDS (0xf << 5) /* speed ID entries */
  846. __le16 wFunctionalitySupport;
  847. #define USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID (0xf)
  848. #define USB_SSP_MIN_RX_LANE_COUNT (0xf << 8)
  849. #define USB_SSP_MIN_TX_LANE_COUNT (0xf << 12)
  850. __le16 wReserved;
  851. union {
  852. __le32 legacy_padding;
  853. /* list of sublink speed attrib entries */
  854. __DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr);
  855. };
  856. #define USB_SSP_SUBLINK_SPEED_SSID (0xf) /* sublink speed ID */
  857. #define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4) /* Lanespeed exponent */
  858. #define USB_SSP_SUBLINK_SPEED_LSE_BPS 0
  859. #define USB_SSP_SUBLINK_SPEED_LSE_KBPS 1
  860. #define USB_SSP_SUBLINK_SPEED_LSE_MBPS 2
  861. #define USB_SSP_SUBLINK_SPEED_LSE_GBPS 3
  862. #define USB_SSP_SUBLINK_SPEED_ST (0x3 << 6) /* Sublink type */
  863. #define USB_SSP_SUBLINK_SPEED_ST_SYM_RX 0
  864. #define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX 1
  865. #define USB_SSP_SUBLINK_SPEED_ST_SYM_TX 2
  866. #define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX 3
  867. #define USB_SSP_SUBLINK_SPEED_RSVD (0x3f << 8) /* Reserved */
  868. #define USB_SSP_SUBLINK_SPEED_LP (0x3 << 14) /* Link protocol */
  869. #define USB_SSP_SUBLINK_SPEED_LP_SS 0
  870. #define USB_SSP_SUBLINK_SPEED_LP_SSP 1
  871. #define USB_SSP_SUBLINK_SPEED_LSM (0xff << 16) /* Lanespeed mantissa */
  872. } __attribute__((packed));
  873. /*
  874. * USB Power Delivery Capability Descriptor:
  875. * Defines capabilities for PD
  876. */
  877. /* Defines the various PD Capabilities of this device */
  878. #define USB_PD_POWER_DELIVERY_CAPABILITY 0x06
  879. /* Provides information on each battery supported by the device */
  880. #define USB_PD_BATTERY_INFO_CAPABILITY 0x07
  881. /* The Consumer characteristics of a Port on the device */
  882. #define USB_PD_PD_CONSUMER_PORT_CAPABILITY 0x08
  883. /* The provider characteristics of a Port on the device */
  884. #define USB_PD_PD_PROVIDER_PORT_CAPABILITY 0x09
  885. struct usb_pd_cap_descriptor {
  886. __u8 bLength;
  887. __u8 bDescriptorType;
  888. __u8 bDevCapabilityType; /* set to USB_PD_POWER_DELIVERY_CAPABILITY */
  889. __u8 bReserved;
  890. __le32 bmAttributes;
  891. #define USB_PD_CAP_BATTERY_CHARGING (1 << 1) /* supports Battery Charging specification */
  892. #define USB_PD_CAP_USB_PD (1 << 2) /* supports USB Power Delivery specification */
  893. #define USB_PD_CAP_PROVIDER (1 << 3) /* can provide power */
  894. #define USB_PD_CAP_CONSUMER (1 << 4) /* can consume power */
  895. #define USB_PD_CAP_CHARGING_POLICY (1 << 5) /* supports CHARGING_POLICY feature */
  896. #define USB_PD_CAP_TYPE_C_CURRENT (1 << 6) /* supports power capabilities defined in the USB Type-C Specification */
  897. #define USB_PD_CAP_PWR_AC (1 << 8)
  898. #define USB_PD_CAP_PWR_BAT (1 << 9)
  899. #define USB_PD_CAP_PWR_USE_V_BUS (1 << 14)
  900. __le16 bmProviderPorts; /* Bit zero refers to the UFP of the device */
  901. __le16 bmConsumerPorts;
  902. __le16 bcdBCVersion;
  903. __le16 bcdPDVersion;
  904. __le16 bcdUSBTypeCVersion;
  905. } __attribute__((packed));
  906. struct usb_pd_cap_battery_info_descriptor {
  907. __u8 bLength;
  908. __u8 bDescriptorType;
  909. __u8 bDevCapabilityType;
  910. /* Index of string descriptor shall contain the user friendly name for this battery */
  911. __u8 iBattery;
  912. /* Index of string descriptor shall contain the Serial Number String for this battery */
  913. __u8 iSerial;
  914. __u8 iManufacturer;
  915. __u8 bBatteryId; /* uniquely identifies this battery in status Messages */
  916. __u8 bReserved;
  917. /*
  918. * Shall contain the Battery Charge value above which this
  919. * battery is considered to be fully charged but not necessarily
  920. * “topped off.”
  921. */
  922. __le32 dwChargedThreshold; /* in mWh */
  923. /*
  924. * Shall contain the minimum charge level of this battery such
  925. * that above this threshold, a device can be assured of being
  926. * able to power up successfully (see Battery Charging 1.2).
  927. */
  928. __le32 dwWeakThreshold; /* in mWh */
  929. __le32 dwBatteryDesignCapacity; /* in mWh */
  930. __le32 dwBatteryLastFullchargeCapacity; /* in mWh */
  931. } __attribute__((packed));
  932. struct usb_pd_cap_consumer_port_descriptor {
  933. __u8 bLength;
  934. __u8 bDescriptorType;
  935. __u8 bDevCapabilityType;
  936. __u8 bReserved;
  937. __u8 bmCapabilities;
  938. /* port will oerate under: */
  939. #define USB_PD_CAP_CONSUMER_BC (1 << 0) /* BC */
  940. #define USB_PD_CAP_CONSUMER_PD (1 << 1) /* PD */
  941. #define USB_PD_CAP_CONSUMER_TYPE_C (1 << 2) /* USB Type-C Current */
  942. __le16 wMinVoltage; /* in 50mV units */
  943. __le16 wMaxVoltage; /* in 50mV units */
  944. __u16 wReserved;
  945. __le32 dwMaxOperatingPower; /* in 10 mW - operating at steady state */
  946. __le32 dwMaxPeakPower; /* in 10mW units - operating at peak power */
  947. __le32 dwMaxPeakPowerTime; /* in 100ms units - duration of peak */
  948. #define USB_PD_CAP_CONSUMER_UNKNOWN_PEAK_POWER_TIME 0xffff
  949. } __attribute__((packed));
  950. struct usb_pd_cap_provider_port_descriptor {
  951. __u8 bLength;
  952. __u8 bDescriptorType;
  953. __u8 bDevCapabilityType;
  954. __u8 bReserved1;
  955. __u8 bmCapabilities;
  956. /* port will oerate under: */
  957. #define USB_PD_CAP_PROVIDER_BC (1 << 0) /* BC */
  958. #define USB_PD_CAP_PROVIDER_PD (1 << 1) /* PD */
  959. #define USB_PD_CAP_PROVIDER_TYPE_C (1 << 2) /* USB Type-C Current */
  960. __u8 bNumOfPDObjects;
  961. __u8 bReserved2;
  962. __le32 wPowerDataObject[];
  963. } __attribute__((packed));
  964. /*
  965. * Precision time measurement capability descriptor: advertised by devices and
  966. * hubs that support PTM
  967. */
  968. #define USB_PTM_CAP_TYPE 0xb
  969. struct usb_ptm_cap_descriptor {
  970. __u8 bLength;
  971. __u8 bDescriptorType;
  972. __u8 bDevCapabilityType;
  973. } __attribute__((packed));
  974. #define USB_DT_USB_PTM_ID_SIZE 3
  975. /*
  976. * The size of the descriptor for the Sublink Speed Attribute Count
  977. * (SSAC) specified in bmAttributes[4:0]. SSAC is zero-based
  978. */
  979. #define USB_DT_USB_SSP_CAP_SIZE(ssac) (12 + (ssac + 1) * 4)
  980. /*-------------------------------------------------------------------------*/
  981. /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with
  982. * each endpoint descriptor for a wireless device
  983. */
  984. struct usb_wireless_ep_comp_descriptor {
  985. __u8 bLength;
  986. __u8 bDescriptorType;
  987. __u8 bMaxBurst;
  988. __u8 bMaxSequence;
  989. __le16 wMaxStreamDelay;
  990. __le16 wOverTheAirPacketSize;
  991. __u8 bOverTheAirInterval;
  992. __u8 bmCompAttributes;
  993. #define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */
  994. #define USB_ENDPOINT_SWITCH_NO 0
  995. #define USB_ENDPOINT_SWITCH_SWITCH 1
  996. #define USB_ENDPOINT_SWITCH_SCALE 2
  997. } __attribute__((packed));
  998. /*-------------------------------------------------------------------------*/
  999. /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
  1000. * host and a device for connection set up, mutual authentication, and
  1001. * exchanging short lived session keys. The handshake depends on a CC.
  1002. */
  1003. struct usb_handshake {
  1004. __u8 bMessageNumber;
  1005. __u8 bStatus;
  1006. __u8 tTKID[3];
  1007. __u8 bReserved;
  1008. __u8 CDID[16];
  1009. __u8 nonce[16];
  1010. __u8 MIC[8];
  1011. } __attribute__((packed));
  1012. /*-------------------------------------------------------------------------*/
  1013. /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
  1014. * A CC may also be set up using non-wireless secure channels (including
  1015. * wired USB!), and some devices may support CCs with multiple hosts.
  1016. */
  1017. struct usb_connection_context {
  1018. __u8 CHID[16]; /* persistent host id */
  1019. __u8 CDID[16]; /* device id (unique w/in host context) */
  1020. __u8 CK[16]; /* connection key */
  1021. } __attribute__((packed));
  1022. /*-------------------------------------------------------------------------*/
  1023. /* USB 2.0 defines three speeds, here's how Linux identifies them */
  1024. enum usb_device_speed {
  1025. USB_SPEED_UNKNOWN = 0, /* enumerating */
  1026. USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
  1027. USB_SPEED_HIGH, /* usb 2.0 */
  1028. USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
  1029. USB_SPEED_SUPER, /* usb 3.0 */
  1030. USB_SPEED_SUPER_PLUS, /* usb 3.1 */
  1031. };
  1032. enum usb_device_state {
  1033. /* NOTATTACHED isn't in the USB spec, and this state acts
  1034. * the same as ATTACHED ... but it's clearer this way.
  1035. */
  1036. USB_STATE_NOTATTACHED = 0,
  1037. /* chapter 9 and authentication (wireless) device states */
  1038. USB_STATE_ATTACHED,
  1039. USB_STATE_POWERED, /* wired */
  1040. USB_STATE_RECONNECTING, /* auth */
  1041. USB_STATE_UNAUTHENTICATED, /* auth */
  1042. USB_STATE_DEFAULT, /* limited function */
  1043. USB_STATE_ADDRESS,
  1044. USB_STATE_CONFIGURED, /* most functions */
  1045. USB_STATE_SUSPENDED
  1046. /* NOTE: there are actually four different SUSPENDED
  1047. * states, returning to POWERED, DEFAULT, ADDRESS, or
  1048. * CONFIGURED respectively when SOF tokens flow again.
  1049. * At this level there's no difference between L1 and L2
  1050. * suspend states. (L2 being original USB 1.1 suspend.)
  1051. */
  1052. };
  1053. enum usb3_link_state {
  1054. USB3_LPM_U0 = 0,
  1055. USB3_LPM_U1,
  1056. USB3_LPM_U2,
  1057. USB3_LPM_U3
  1058. };
  1059. /*
  1060. * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1.
  1061. * 0xff means the parent hub will accept transitions to U1, but will not
  1062. * initiate a transition.
  1063. *
  1064. * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to
  1065. * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved
  1066. * values.
  1067. *
  1068. * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2.
  1069. * 0xff means the parent hub will accept transitions to U2, but will not
  1070. * initiate a transition.
  1071. *
  1072. * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to
  1073. * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2
  1074. * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means
  1075. * 65.024ms.
  1076. */
  1077. #define USB3_LPM_DISABLED 0x0
  1078. #define USB3_LPM_U1_MAX_TIMEOUT 0x7F
  1079. #define USB3_LPM_U2_MAX_TIMEOUT 0xFE
  1080. #define USB3_LPM_DEVICE_INITIATED 0xFF
  1081. struct usb_set_sel_req {
  1082. __u8 u1_sel;
  1083. __u8 u1_pel;
  1084. __le16 u2_sel;
  1085. __le16 u2_pel;
  1086. } __attribute__ ((packed));
  1087. /*
  1088. * The Set System Exit Latency control transfer provides one byte each for
  1089. * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each
  1090. * are two bytes long.
  1091. */
  1092. #define USB3_LPM_MAX_U1_SEL_PEL 0xFF
  1093. #define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF
  1094. /*-------------------------------------------------------------------------*/
  1095. /*
  1096. * As per USB compliance update, a device that is actively drawing
  1097. * more than 100mA from USB must report itself as bus-powered in
  1098. * the GetStatus(DEVICE) call.
  1099. * https://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34
  1100. */
  1101. #define USB_SELF_POWER_VBUS_MAX_DRAW 100
  1102. #endif /* __LINUX_USB_CH9_H */