ch11.h 8.7 KB

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