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

ch11.h (9046B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * This file holds Hub protocol constants and data structures that are
  4. * defined in chapter 11 (Hub Specification) of the USB 2.0 specification.
  5. *
  6. * It is used/shared between the USB core, the HCDs and couple of other USB
  7. * drivers.
  8. */
  9. #ifndef __LINUX_CH11_H
  10. #define __LINUX_CH11_H
  11. #include <linux/types.h> /* __u8 etc */
  12. /* This is arbitrary.
  13. * From USB 2.0 spec Table 11-13, offset 7, a hub can
  14. * have up to 255 ports. The most yet reported is 10.
  15. * Upcoming hardware might raise that limit.
  16. * Because the arrays need to add a bit for hub status data, we
  17. * use 31, so plus one evens out to four bytes.
  18. */
  19. #define USB_MAXCHILDREN 31
  20. /* See USB 3.1 spec Table 10-5 */
  21. #define USB_SS_MAXPORTS 15
  22. /*
  23. * Hub request types
  24. */
  25. #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
  26. #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
  27. /*
  28. * Port status type for GetPortStatus requests added in USB 3.1
  29. * See USB 3.1 spec Table 10-12
  30. */
  31. #define HUB_PORT_STATUS 0
  32. #define HUB_PORT_PD_STATUS 1
  33. #define HUB_EXT_PORT_STATUS 2
  34. /*
  35. * Hub class requests
  36. * See USB 2.0 spec Table 11-16
  37. */
  38. #define HUB_CLEAR_TT_BUFFER 8
  39. #define HUB_RESET_TT 9
  40. #define HUB_GET_TT_STATE 10
  41. #define HUB_STOP_TT 11
  42. /*
  43. * Hub class additional requests defined by USB 3.0 spec
  44. * See USB 3.0 spec Table 10-6
  45. */
  46. #define HUB_SET_DEPTH 12
  47. #define HUB_GET_PORT_ERR_COUNT 13
  48. /*
  49. * Hub Class feature numbers
  50. * See USB 2.0 spec Table 11-17
  51. */
  52. #define C_HUB_LOCAL_POWER 0
  53. #define C_HUB_OVER_CURRENT 1
  54. /*
  55. * Port feature numbers
  56. * See USB 2.0 spec Table 11-17
  57. */
  58. #define USB_PORT_FEAT_CONNECTION 0
  59. #define USB_PORT_FEAT_ENABLE 1
  60. #define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */
  61. #define USB_PORT_FEAT_OVER_CURRENT 3
  62. #define USB_PORT_FEAT_RESET 4
  63. #define USB_PORT_FEAT_L1 5 /* L1 suspend */
  64. #define USB_PORT_FEAT_POWER 8
  65. #define USB_PORT_FEAT_LOWSPEED 9 /* Should never be used */
  66. #define USB_PORT_FEAT_C_CONNECTION 16
  67. #define USB_PORT_FEAT_C_ENABLE 17
  68. #define USB_PORT_FEAT_C_SUSPEND 18
  69. #define USB_PORT_FEAT_C_OVER_CURRENT 19
  70. #define USB_PORT_FEAT_C_RESET 20
  71. #define USB_PORT_FEAT_TEST 21
  72. #define USB_PORT_FEAT_INDICATOR 22
  73. #define USB_PORT_FEAT_C_PORT_L1 23
  74. /*
  75. * Port feature selectors added by USB 3.0 spec.
  76. * See USB 3.0 spec Table 10-7
  77. */
  78. #define USB_PORT_FEAT_LINK_STATE 5
  79. #define USB_PORT_FEAT_U1_TIMEOUT 23
  80. #define USB_PORT_FEAT_U2_TIMEOUT 24
  81. #define USB_PORT_FEAT_C_PORT_LINK_STATE 25
  82. #define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 26
  83. #define USB_PORT_FEAT_REMOTE_WAKE_MASK 27
  84. #define USB_PORT_FEAT_BH_PORT_RESET 28
  85. #define USB_PORT_FEAT_C_BH_PORT_RESET 29
  86. #define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30
  87. #define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8)
  88. /* USB 3.0 hub remote wake mask bits, see table 10-14 */
  89. #define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)
  90. #define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)
  91. #define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT (1 << 10)
  92. /*
  93. * Hub Status and Hub Change results
  94. * See USB 2.0 spec Table 11-19 and Table 11-20
  95. * USB 3.1 extends the port status request and may return 4 additional bytes.
  96. * See USB 3.1 spec section 10.16.2.6 Table 10-12 and 10-15
  97. */
  98. struct usb_port_status {
  99. __le16 wPortStatus;
  100. __le16 wPortChange;
  101. __le32 dwExtPortStatus;
  102. } __attribute__ ((packed));
  103. /*
  104. * wPortStatus bit field
  105. * See USB 2.0 spec Table 11-21
  106. */
  107. #define USB_PORT_STAT_CONNECTION 0x0001
  108. #define USB_PORT_STAT_ENABLE 0x0002
  109. #define USB_PORT_STAT_SUSPEND 0x0004
  110. #define USB_PORT_STAT_OVERCURRENT 0x0008
  111. #define USB_PORT_STAT_RESET 0x0010
  112. #define USB_PORT_STAT_L1 0x0020
  113. /* bits 6 to 7 are reserved */
  114. #define USB_PORT_STAT_POWER 0x0100
  115. #define USB_PORT_STAT_LOW_SPEED 0x0200
  116. #define USB_PORT_STAT_HIGH_SPEED 0x0400
  117. #define USB_PORT_STAT_TEST 0x0800
  118. #define USB_PORT_STAT_INDICATOR 0x1000
  119. /* bits 13 to 15 are reserved */
  120. /*
  121. * Additions to wPortStatus bit field from USB 3.0
  122. * See USB 3.0 spec Table 10-10
  123. */
  124. #define USB_PORT_STAT_LINK_STATE 0x01e0
  125. #define USB_SS_PORT_STAT_POWER 0x0200
  126. #define USB_SS_PORT_STAT_SPEED 0x1c00
  127. #define USB_PORT_STAT_SPEED_5GBPS 0x0000
  128. /* Valid only if port is enabled */
  129. /* Bits that are the same from USB 2.0 */
  130. #define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \
  131. USB_PORT_STAT_ENABLE | \
  132. USB_PORT_STAT_OVERCURRENT | \
  133. USB_PORT_STAT_RESET)
  134. /*
  135. * Definitions for PORT_LINK_STATE values
  136. * (bits 5-8) in wPortStatus
  137. */
  138. #define USB_SS_PORT_LS_U0 0x0000
  139. #define USB_SS_PORT_LS_U1 0x0020
  140. #define USB_SS_PORT_LS_U2 0x0040
  141. #define USB_SS_PORT_LS_U3 0x0060
  142. #define USB_SS_PORT_LS_SS_DISABLED 0x0080
  143. #define USB_SS_PORT_LS_RX_DETECT 0x00a0
  144. #define USB_SS_PORT_LS_SS_INACTIVE 0x00c0
  145. #define USB_SS_PORT_LS_POLLING 0x00e0
  146. #define USB_SS_PORT_LS_RECOVERY 0x0100
  147. #define USB_SS_PORT_LS_HOT_RESET 0x0120
  148. #define USB_SS_PORT_LS_COMP_MOD 0x0140
  149. #define USB_SS_PORT_LS_LOOPBACK 0x0160
  150. /*
  151. * wPortChange bit field
  152. * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10
  153. * Bits 0 to 5 shown, bits 6 to 15 are reserved
  154. */
  155. #define USB_PORT_STAT_C_CONNECTION 0x0001
  156. #define USB_PORT_STAT_C_ENABLE 0x0002
  157. #define USB_PORT_STAT_C_SUSPEND 0x0004
  158. #define USB_PORT_STAT_C_OVERCURRENT 0x0008
  159. #define USB_PORT_STAT_C_RESET 0x0010
  160. #define USB_PORT_STAT_C_L1 0x0020
  161. /*
  162. * USB 3.0 wPortChange bit fields
  163. * See USB 3.0 spec Table 10-11
  164. */
  165. #define USB_PORT_STAT_C_BH_RESET 0x0020
  166. #define USB_PORT_STAT_C_LINK_STATE 0x0040
  167. #define USB_PORT_STAT_C_CONFIG_ERROR 0x0080
  168. /*
  169. * USB 3.1 dwExtPortStatus field masks
  170. * See USB 3.1 spec 10.16.2.6.3 Table 10-15
  171. */
  172. #define USB_EXT_PORT_STAT_RX_SPEED_ID 0x0000000f
  173. #define USB_EXT_PORT_STAT_TX_SPEED_ID 0x000000f0
  174. #define USB_EXT_PORT_STAT_RX_LANES 0x00000f00
  175. #define USB_EXT_PORT_STAT_TX_LANES 0x0000f000
  176. #define USB_EXT_PORT_RX_LANES(p) \
  177. (((p) & USB_EXT_PORT_STAT_RX_LANES) >> 8)
  178. #define USB_EXT_PORT_TX_LANES(p) \
  179. (((p) & USB_EXT_PORT_STAT_TX_LANES) >> 12)
  180. /*
  181. * wHubCharacteristics (masks)
  182. * See USB 2.0 spec Table 11-13, offset 3
  183. */
  184. #define HUB_CHAR_LPSM 0x0003 /* Logical Power Switching Mode mask */
  185. #define HUB_CHAR_COMMON_LPSM 0x0000 /* All ports power control at once */
  186. #define HUB_CHAR_INDV_PORT_LPSM 0x0001 /* per-port power control */
  187. #define HUB_CHAR_NO_LPSM 0x0002 /* no power switching */
  188. #define HUB_CHAR_COMPOUND 0x0004 /* hub is part of a compound device */
  189. #define HUB_CHAR_OCPM 0x0018 /* Over-Current Protection Mode mask */
  190. #define HUB_CHAR_COMMON_OCPM 0x0000 /* All ports Over-Current reporting */
  191. #define HUB_CHAR_INDV_PORT_OCPM 0x0008 /* per-port Over-current reporting */
  192. #define HUB_CHAR_NO_OCPM 0x0010 /* No Over-current Protection support */
  193. #define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */
  194. #define HUB_CHAR_PORTIND 0x0080 /* per-port indicators (LEDs) */
  195. struct usb_hub_status {
  196. __le16 wHubStatus;
  197. __le16 wHubChange;
  198. } __attribute__ ((packed));
  199. /*
  200. * Hub Status & Hub Change bit masks
  201. * See USB 2.0 spec Table 11-19 and Table 11-20
  202. * Bits 0 and 1 for wHubStatus and wHubChange
  203. * Bits 2 to 15 are reserved for both
  204. */
  205. #define HUB_STATUS_LOCAL_POWER 0x0001
  206. #define HUB_STATUS_OVERCURRENT 0x0002
  207. #define HUB_CHANGE_LOCAL_POWER 0x0001
  208. #define HUB_CHANGE_OVERCURRENT 0x0002
  209. /*
  210. * Hub descriptor
  211. * See USB 2.0 spec Table 11-13
  212. */
  213. #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
  214. #define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
  215. #define USB_DT_HUB_NONVAR_SIZE 7
  216. #define USB_DT_SS_HUB_SIZE 12
  217. /*
  218. * Hub Device descriptor
  219. * USB Hub class device protocols
  220. */
  221. #define USB_HUB_PR_FS 0 /* Full speed hub */
  222. #define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */
  223. #define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */
  224. #define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */
  225. #define USB_HUB_PR_SS 3 /* Super speed hub */
  226. struct usb_hub_descriptor {
  227. __u8 bDescLength;
  228. __u8 bDescriptorType;
  229. __u8 bNbrPorts;
  230. __le16 wHubCharacteristics;
  231. __u8 bPwrOn2PwrGood;
  232. __u8 bHubContrCurrent;
  233. /* 2.0 and 3.0 hubs differ here */
  234. union {
  235. struct {
  236. /* add 1 bit for hub status change; round to bytes */
  237. __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  238. __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  239. } __attribute__ ((packed)) hs;
  240. struct {
  241. __u8 bHubHdrDecLat;
  242. __le16 wHubDelay;
  243. __le16 DeviceRemovable;
  244. } __attribute__ ((packed)) ss;
  245. } u;
  246. } __attribute__ ((packed));
  247. /* port indicator status selectors, tables 11-7 and 11-25 */
  248. #define HUB_LED_AUTO 0
  249. #define HUB_LED_AMBER 1
  250. #define HUB_LED_GREEN 2
  251. #define HUB_LED_OFF 3
  252. enum hub_led_mode {
  253. INDICATOR_AUTO = 0,
  254. INDICATOR_CYCLE,
  255. /* software blinks for attention: software, hardware, reserved */
  256. INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
  257. INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
  258. INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
  259. } __attribute__ ((packed));
  260. /* Transaction Translator Think Times, in bits */
  261. #define HUB_TTTT_8_BITS 0x00
  262. #define HUB_TTTT_16_BITS 0x20
  263. #define HUB_TTTT_24_BITS 0x40
  264. #define HUB_TTTT_32_BITS 0x60
  265. #endif /* __LINUX_CH11_H */