hub.h 5.3 KB

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