hub.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef __LINUX_HUB_H
  2. #define __LINUX_HUB_H
  3. /*
  4. * Hub protocol and driver data structures.
  5. *
  6. * Some of these are known to the "virtual root hub" code
  7. * in host controller drivers.
  8. */
  9. #include <linux/list.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/compiler.h> /* likely()/unlikely() */
  12. /*
  13. * Hub request types
  14. */
  15. #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
  16. #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
  17. /*
  18. * Hub class requests
  19. * See USB 2.0 spec Table 11-16
  20. */
  21. #define HUB_CLEAR_TT_BUFFER 8
  22. #define HUB_RESET_TT 9
  23. #define HUB_GET_TT_STATE 10
  24. #define HUB_STOP_TT 11
  25. /*
  26. * Hub Class feature numbers
  27. * See USB 2.0 spec Table 11-17
  28. */
  29. #define C_HUB_LOCAL_POWER 0
  30. #define C_HUB_OVER_CURRENT 1
  31. /*
  32. * Port feature numbers
  33. * See USB 2.0 spec Table 11-17
  34. */
  35. #define USB_PORT_FEAT_CONNECTION 0
  36. #define USB_PORT_FEAT_ENABLE 1
  37. #define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */
  38. #define USB_PORT_FEAT_OVER_CURRENT 3
  39. #define USB_PORT_FEAT_RESET 4
  40. #define USB_PORT_FEAT_L1 5 /* L1 suspend */
  41. #define USB_PORT_FEAT_POWER 8
  42. #define USB_PORT_FEAT_LOWSPEED 9
  43. /* This value was never in Table 11-17 */
  44. #define USB_PORT_FEAT_HIGHSPEED 10
  45. /* This value is also fake */
  46. #define USB_PORT_FEAT_SUPERSPEED 11
  47. #define USB_PORT_FEAT_C_CONNECTION 16
  48. #define USB_PORT_FEAT_C_ENABLE 17
  49. #define USB_PORT_FEAT_C_SUSPEND 18
  50. #define USB_PORT_FEAT_C_OVER_CURRENT 19
  51. #define USB_PORT_FEAT_C_RESET 20
  52. #define USB_PORT_FEAT_TEST 21
  53. #define USB_PORT_FEAT_INDICATOR 22
  54. #define USB_PORT_FEAT_C_PORT_L1 23
  55. /*
  56. * Hub Status and Hub Change results
  57. * See USB 2.0 spec Table 11-19 and Table 11-20
  58. */
  59. struct usb_port_status {
  60. __le16 wPortStatus;
  61. __le16 wPortChange;
  62. } __attribute__ ((packed));
  63. /*
  64. * wPortStatus bit field
  65. * See USB 2.0 spec Table 11-21
  66. */
  67. #define USB_PORT_STAT_CONNECTION 0x0001
  68. #define USB_PORT_STAT_ENABLE 0x0002
  69. #define USB_PORT_STAT_SUSPEND 0x0004
  70. #define USB_PORT_STAT_OVERCURRENT 0x0008
  71. #define USB_PORT_STAT_RESET 0x0010
  72. #define USB_PORT_STAT_L1 0x0020
  73. /* bits 6 to 7 are reserved */
  74. #define USB_PORT_STAT_POWER 0x0100
  75. #define USB_PORT_STAT_LOW_SPEED 0x0200
  76. #define USB_PORT_STAT_HIGH_SPEED 0x0400
  77. #define USB_PORT_STAT_TEST 0x0800
  78. #define USB_PORT_STAT_INDICATOR 0x1000
  79. /* bits 13 to 15 are reserved */
  80. /*
  81. * wPortChange bit field
  82. * See USB 2.0 spec Table 11-22
  83. * Bits 0 to 4 shown, bits 5 to 15 are reserved
  84. */
  85. #define USB_PORT_STAT_C_CONNECTION 0x0001
  86. #define USB_PORT_STAT_C_ENABLE 0x0002
  87. #define USB_PORT_STAT_C_SUSPEND 0x0004
  88. #define USB_PORT_STAT_C_OVERCURRENT 0x0008
  89. #define USB_PORT_STAT_C_RESET 0x0010
  90. #define USB_PORT_STAT_C_L1 0x0020
  91. /*
  92. * wHubCharacteristics (masks)
  93. * See USB 2.0 spec Table 11-13, offset 3
  94. */
  95. #define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */
  96. #define HUB_CHAR_COMPOUND 0x0004 /* D2 */
  97. #define HUB_CHAR_OCPM 0x0018 /* D4 .. D3 */
  98. #define HUB_CHAR_TTTT 0x0060 /* D6 .. D5 */
  99. #define HUB_CHAR_PORTIND 0x0080 /* D7 */
  100. struct usb_hub_status {
  101. __le16 wHubStatus;
  102. __le16 wHubChange;
  103. } __attribute__ ((packed));
  104. /*
  105. * Hub Status & Hub Change bit masks
  106. * See USB 2.0 spec Table 11-19 and Table 11-20
  107. * Bits 0 and 1 for wHubStatus and wHubChange
  108. * Bits 2 to 15 are reserved for both
  109. */
  110. #define HUB_STATUS_LOCAL_POWER 0x0001
  111. #define HUB_STATUS_OVERCURRENT 0x0002
  112. #define HUB_CHANGE_LOCAL_POWER 0x0001
  113. #define HUB_CHANGE_OVERCURRENT 0x0002
  114. /*
  115. * Hub descriptor
  116. * See USB 2.0 spec Table 11-13
  117. */
  118. #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
  119. #define USB_DT_HUB_NONVAR_SIZE 7
  120. struct usb_hub_descriptor {
  121. __u8 bDescLength;
  122. __u8 bDescriptorType;
  123. __u8 bNbrPorts;
  124. __le16 wHubCharacteristics;
  125. __u8 bPwrOn2PwrGood;
  126. __u8 bHubContrCurrent;
  127. /* add 1 bit for hub status change; round to bytes */
  128. __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  129. __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  130. } __attribute__ ((packed));
  131. /* port indicator status selectors, tables 11-7 and 11-25 */
  132. #define HUB_LED_AUTO 0
  133. #define HUB_LED_AMBER 1
  134. #define HUB_LED_GREEN 2
  135. #define HUB_LED_OFF 3
  136. enum hub_led_mode {
  137. INDICATOR_AUTO = 0,
  138. INDICATOR_CYCLE,
  139. /* software blinks for attention: software, hardware, reserved */
  140. INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
  141. INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
  142. INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
  143. } __attribute__ ((packed));
  144. struct usb_device;
  145. /* Transaction Translator Think Times, in bits */
  146. #define HUB_TTTT_8_BITS 0x00
  147. #define HUB_TTTT_16_BITS 0x20
  148. #define HUB_TTTT_24_BITS 0x40
  149. #define HUB_TTTT_32_BITS 0x60
  150. /*
  151. * As of USB 2.0, full/low speed devices are segregated into trees.
  152. * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
  153. * The other type grows from high speed hubs when they connect to
  154. * full/low speed devices using "Transaction Translators" (TTs).
  155. *
  156. * TTs should only be known to the hub driver, and high speed bus
  157. * drivers (only EHCI for now). They affect periodic scheduling and
  158. * sometimes control/bulk error recovery.
  159. */
  160. struct usb_tt {
  161. struct usb_device *hub; /* upstream highspeed hub */
  162. int multi; /* true means one TT per port */
  163. unsigned think_time; /* think time in ns */
  164. /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
  165. spinlock_t lock;
  166. struct list_head clear_list; /* of usb_tt_clear */
  167. struct work_struct clear_work;
  168. };
  169. struct usb_tt_clear {
  170. struct list_head clear_list;
  171. unsigned tt;
  172. u16 devinfo;
  173. struct usb_hcd *hcd;
  174. struct usb_host_endpoint *ep;
  175. };
  176. extern int usb_hub_clear_tt_buffer(struct urb *urb);
  177. extern void usb_ep0_reinit(struct usb_device *);
  178. #endif /* __LINUX_HUB_H */