hub.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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
  38. #define USB_PORT_FEAT_OVER_CURRENT 3
  39. #define USB_PORT_FEAT_RESET 4
  40. #define USB_PORT_FEAT_POWER 8
  41. #define USB_PORT_FEAT_LOWSPEED 9
  42. #define USB_PORT_FEAT_HIGHSPEED 10
  43. #define USB_PORT_FEAT_C_CONNECTION 16
  44. #define USB_PORT_FEAT_C_ENABLE 17
  45. #define USB_PORT_FEAT_C_SUSPEND 18
  46. #define USB_PORT_FEAT_C_OVER_CURRENT 19
  47. #define USB_PORT_FEAT_C_RESET 20
  48. #define USB_PORT_FEAT_TEST 21
  49. #define USB_PORT_FEAT_INDICATOR 22
  50. /*
  51. * Hub Status and Hub Change results
  52. * See USB 2.0 spec Table 11-19 and Table 11-20
  53. */
  54. struct usb_port_status {
  55. __le16 wPortStatus;
  56. __le16 wPortChange;
  57. } __attribute__ ((packed));
  58. /*
  59. * wPortStatus bit field
  60. * See USB 2.0 spec Table 11-21
  61. */
  62. #define USB_PORT_STAT_CONNECTION 0x0001
  63. #define USB_PORT_STAT_ENABLE 0x0002
  64. #define USB_PORT_STAT_SUSPEND 0x0004
  65. #define USB_PORT_STAT_OVERCURRENT 0x0008
  66. #define USB_PORT_STAT_RESET 0x0010
  67. /* bits 5 to 7 are reserved */
  68. #define USB_PORT_STAT_POWER 0x0100
  69. #define USB_PORT_STAT_LOW_SPEED 0x0200
  70. #define USB_PORT_STAT_HIGH_SPEED 0x0400
  71. #define USB_PORT_STAT_TEST 0x0800
  72. #define USB_PORT_STAT_INDICATOR 0x1000
  73. /* bits 13 to 15 are reserved */
  74. /*
  75. * wPortChange bit field
  76. * See USB 2.0 spec Table 11-22
  77. * Bits 0 to 4 shown, bits 5 to 15 are reserved
  78. */
  79. #define USB_PORT_STAT_C_CONNECTION 0x0001
  80. #define USB_PORT_STAT_C_ENABLE 0x0002
  81. #define USB_PORT_STAT_C_SUSPEND 0x0004
  82. #define USB_PORT_STAT_C_OVERCURRENT 0x0008
  83. #define USB_PORT_STAT_C_RESET 0x0010
  84. /*
  85. * wHubCharacteristics (masks)
  86. * See USB 2.0 spec Table 11-13, offset 3
  87. */
  88. #define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */
  89. #define HUB_CHAR_COMPOUND 0x0004 /* D2 */
  90. #define HUB_CHAR_OCPM 0x0018 /* D4 .. D3 */
  91. #define HUB_CHAR_TTTT 0x0060 /* D6 .. D5 */
  92. #define HUB_CHAR_PORTIND 0x0080 /* D7 */
  93. struct usb_hub_status {
  94. __le16 wHubStatus;
  95. __le16 wHubChange;
  96. } __attribute__ ((packed));
  97. /*
  98. * Hub Status & Hub Change bit masks
  99. * See USB 2.0 spec Table 11-19 and Table 11-20
  100. * Bits 0 and 1 for wHubStatus and wHubChange
  101. * Bits 2 to 15 are reserved for both
  102. */
  103. #define HUB_STATUS_LOCAL_POWER 0x0001
  104. #define HUB_STATUS_OVERCURRENT 0x0002
  105. #define HUB_CHANGE_LOCAL_POWER 0x0001
  106. #define HUB_CHANGE_OVERCURRENT 0x0002
  107. /*
  108. * Hub descriptor
  109. * See USB 2.0 spec Table 11-13
  110. */
  111. #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
  112. #define USB_DT_HUB_NONVAR_SIZE 7
  113. struct usb_hub_descriptor {
  114. __u8 bDescLength;
  115. __u8 bDescriptorType;
  116. __u8 bNbrPorts;
  117. __u16 wHubCharacteristics;
  118. __u8 bPwrOn2PwrGood;
  119. __u8 bHubContrCurrent;
  120. /* add 1 bit for hub status change; round to bytes */
  121. __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  122. __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  123. } __attribute__ ((packed));
  124. /* port indicator status selectors, tables 11-7 and 11-25 */
  125. #define HUB_LED_AUTO 0
  126. #define HUB_LED_AMBER 1
  127. #define HUB_LED_GREEN 2
  128. #define HUB_LED_OFF 3
  129. enum hub_led_mode {
  130. INDICATOR_AUTO = 0,
  131. INDICATOR_CYCLE,
  132. /* software blinks for attention: software, hardware, reserved */
  133. INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,
  134. INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,
  135. INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
  136. } __attribute__ ((packed));
  137. struct usb_device;
  138. /* Transaction Translator Think Times, in bits */
  139. #define HUB_TTTT_8_BITS 0x00
  140. #define HUB_TTTT_16_BITS 0x20
  141. #define HUB_TTTT_24_BITS 0x40
  142. #define HUB_TTTT_32_BITS 0x60
  143. /*
  144. * As of USB 2.0, full/low speed devices are segregated into trees.
  145. * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
  146. * The other type grows from high speed hubs when they connect to
  147. * full/low speed devices using "Transaction Translators" (TTs).
  148. *
  149. * TTs should only be known to the hub driver, and high speed bus
  150. * drivers (only EHCI for now). They affect periodic scheduling and
  151. * sometimes control/bulk error recovery.
  152. */
  153. struct usb_tt {
  154. struct usb_device *hub; /* upstream highspeed hub */
  155. int multi; /* true means one TT per port */
  156. unsigned think_time; /* think time in ns */
  157. /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
  158. spinlock_t lock;
  159. struct list_head clear_list; /* of usb_tt_clear */
  160. struct work_struct kevent;
  161. };
  162. struct usb_tt_clear {
  163. struct list_head clear_list;
  164. unsigned tt;
  165. u16 devinfo;
  166. };
  167. extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
  168. struct usb_hub {
  169. struct device *intfdev; /* the "interface" device */
  170. struct usb_device *hdev;
  171. struct urb *urb; /* for interrupt polling pipe */
  172. /* buffer for urb ... with extra space in case of babble */
  173. char (*buffer)[8];
  174. dma_addr_t buffer_dma; /* DMA address for buffer */
  175. union {
  176. struct usb_hub_status hub;
  177. struct usb_port_status port;
  178. } *status; /* buffer for status reports */
  179. int error; /* last reported error */
  180. int nerrors; /* track consecutive errors */
  181. struct list_head event_list; /* hubs w/data or errs ready */
  182. unsigned long event_bits[1]; /* status change bitmask */
  183. unsigned long change_bits[1]; /* ports with logical connect
  184. status change */
  185. unsigned long busy_bits[1]; /* ports being reset */
  186. #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
  187. #error event_bits[] is too short!
  188. #endif
  189. struct usb_hub_descriptor *descriptor; /* class descriptor */
  190. struct usb_tt tt; /* Transaction Translator */
  191. u8 power_budget; /* in 2mA units; or zero */
  192. unsigned quiescing:1;
  193. unsigned activating:1;
  194. unsigned resume_root_hub:1;
  195. unsigned has_indicators:1;
  196. enum hub_led_mode indicator[USB_MAXCHILDREN];
  197. struct work_struct leds;
  198. };
  199. #endif /* __LINUX_HUB_H */