hub.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /*
  139. * As of USB 2.0, full/low speed devices are segregated into trees.
  140. * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
  141. * The other type grows from high speed hubs when they connect to
  142. * full/low speed devices using "Transaction Translators" (TTs).
  143. *
  144. * TTs should only be known to the hub driver, and high speed bus
  145. * drivers (only EHCI for now). They affect periodic scheduling and
  146. * sometimes control/bulk error recovery.
  147. */
  148. struct usb_tt {
  149. struct usb_device *hub; /* upstream highspeed hub */
  150. int multi; /* true means one TT per port */
  151. /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
  152. spinlock_t lock;
  153. struct list_head clear_list; /* of usb_tt_clear */
  154. struct work_struct kevent;
  155. };
  156. struct usb_tt_clear {
  157. struct list_head clear_list;
  158. unsigned tt;
  159. u16 devinfo;
  160. };
  161. extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
  162. struct usb_hub {
  163. struct device *intfdev; /* the "interface" device */
  164. struct usb_device *hdev;
  165. struct urb *urb; /* for interrupt polling pipe */
  166. /* buffer for urb ... with extra space in case of babble */
  167. char (*buffer)[8];
  168. dma_addr_t buffer_dma; /* DMA address for buffer */
  169. union {
  170. struct usb_hub_status hub;
  171. struct usb_port_status port;
  172. } *status; /* buffer for status reports */
  173. int error; /* last reported error */
  174. int nerrors; /* track consecutive errors */
  175. struct list_head event_list; /* hubs w/data or errs ready */
  176. unsigned long event_bits[1]; /* status change bitmask */
  177. unsigned long change_bits[1]; /* ports with logical connect
  178. status change */
  179. unsigned long busy_bits[1]; /* ports being reset */
  180. #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
  181. #error event_bits[] is too short!
  182. #endif
  183. struct usb_hub_descriptor *descriptor; /* class descriptor */
  184. struct usb_tt tt; /* Transaction Translator */
  185. u8 power_budget; /* in 2mA units; or zero */
  186. unsigned quiescing:1;
  187. unsigned activating:1;
  188. unsigned resume_root_hub:1;
  189. unsigned has_indicators:1;
  190. enum hub_led_mode indicator[USB_MAXCHILDREN];
  191. struct work_struct leds;
  192. };
  193. #endif /* __LINUX_HUB_H */