usb.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #ifndef _USB_H_
  2. #define _USB_H_
  3. #include "typedef.h"
  4. #define cpu_to_le16(x) (x)
  5. #define le16_to_cpu(x) (x)
  6. #define le32_to_cpu(x) (x)
  7. #define cpu_to_le32(x) (x)
  8. #define be32_to_cpu(x) ((((x) >> 24) & 0xff) | ((((x) >> 16) & 0xff) << 8) | \
  9. ((((x) >> 8) & 0xff) << 16) | (((x) & 0xff) << 24))
  10. #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
  11. ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
  12. ((x & 0xffff0000) ? 16 : 0))
  13. /* Everything is aribtrary */
  14. #define USB_ALTSETTINGALLOC 4
  15. #define USB_MAXALTSETTING 128 /* Hard limit */
  16. #define USB_MAX_DEVICE 2
  17. #define USB_MAXINTERFACES 2
  18. #define USB_MAXENDPOINTS 4
  19. #define USB_MAXCHILDREN 4 /* This is arbitrary */
  20. #define USB_MAX_HUB 1
  21. #define USB_MAX_STOR_DEV 1
  22. #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
  23. /* Sub STORAGE Classes */
  24. #define US_SC_RBC 1 /* Typically, flash devices */
  25. #define US_SC_8020 2 /* CD-ROM */
  26. #define US_SC_QIC 3 /* QIC-157 Tapes */
  27. #define US_SC_UFI 4 /* Floppy */
  28. #define US_SC_8070 5 /* Removable media */
  29. #define US_SC_SCSI 6 /* Transparent */
  30. #define US_SC_MIN US_SC_RBC
  31. #define US_SC_MAX US_SC_SCSI
  32. /* STORAGE Protocols */
  33. #define US_PR_CB 1 /* Control/Bulk w/o interrupt */
  34. #define US_PR_CBI 0 /* Control/Bulk/Interrupt */
  35. #define US_PR_BULK 0x50 /* bulk only */
  36. /* USB types */
  37. #define USB_TYPE_STANDARD (0x00 << 5)
  38. #define USB_TYPE_CLASS (0x01 << 5)
  39. #define USB_TYPE_VENDOR (0x02 << 5)
  40. #define USB_TYPE_RESERVED (0x03 << 5)
  41. /* USB recipients */
  42. #define USB_RECIP_DEVICE 0x00
  43. #define USB_RECIP_INTERFACE 0x01
  44. #define USB_RECIP_ENDPOINT 0x02
  45. #define USB_RECIP_OTHER 0x03
  46. /* Endpoints */
  47. #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
  48. #define USB_ENDPOINT_DIR_MASK 0x80
  49. #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
  50. #define USB_ENDPOINT_XFER_CONTROL 0
  51. #define USB_ENDPOINT_XFER_ISOC 1
  52. #define USB_ENDPOINT_XFER_BULK 2
  53. #define USB_ENDPOINT_XFER_INT 3
  54. /* USB Packet IDs (PIDs) */
  55. #define USB_PID_UNDEF_0 0xf0
  56. #define USB_PID_OUT 0xe1
  57. #define USB_PID_ACK 0xd2
  58. #define USB_PID_DATA0 0xc3
  59. #define USB_PID_UNDEF_4 0xb4
  60. #define USB_PID_SOF 0xa5
  61. #define USB_PID_UNDEF_6 0x96
  62. #define USB_PID_UNDEF_7 0x87
  63. #define USB_PID_UNDEF_8 0x78
  64. #define USB_PID_IN 0x69
  65. #define USB_PID_NAK 0x5a
  66. #define USB_PID_DATA1 0x4b
  67. #define USB_PID_PREAMBLE 0x3c
  68. #define USB_PID_SETUP 0x2d
  69. #define USB_PID_STALL 0x1e
  70. #define USB_PID_UNDEF_F 0x0f
  71. /*
  72. * "pipe" definitions, use unsigned so we can compare reliably, since this
  73. * value is shifted up to bits 30/31.
  74. */
  75. #define PIPE_ISOCHRONOUS 0U
  76. #define PIPE_INTERRUPT 1U
  77. #define PIPE_CONTROL 2U
  78. #define PIPE_BULK 3U
  79. #define PIPE_DEVEP_MASK 0x0007ff00
  80. #define USB_ISOCHRONOUS 0
  81. #define USB_INTERRUPT 1
  82. #define USB_CONTROL 2
  83. #define USB_BULK 3
  84. #define USB_PIPE_TYPE_SHIFT 30
  85. #define USB_PIPE_TYPE_MASK (3 << USB_PIPE_TYPE_SHIFT)
  86. #define USB_PIPE_DEV_SHIFT 8
  87. #define USB_PIPE_DEV_MASK (0x7f << USB_PIPE_DEV_SHIFT)
  88. #define USB_PIPE_EP_SHIFT 15
  89. #define USB_PIPE_EP_MASK (0xf << USB_PIPE_EP_SHIFT)
  90. /* USB-status codes: */
  91. #define USB_ST_ACTIVE 0x1 /* TD is active */
  92. #define USB_ST_STALLED 0x2 /* TD is stalled */
  93. #define USB_ST_BUF_ERR 0x4 /* buffer error */
  94. #define USB_ST_BABBLE_DET 0x8 /* Babble detected */
  95. #define USB_ST_NAK_REC 0x10 /* NAK Received*/
  96. #define USB_ST_CRC_ERR 0x20 /* CRC/timeout Error */
  97. #define USB_ST_BIT_ERR 0x40 /* Bitstuff error */
  98. #define USB_ST_NOT_PROC 0x80000000L /* Not yet processed */
  99. /*
  100. * Hub request types
  101. */
  102. #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
  103. #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
  104. /*
  105. * Port feature numbers
  106. */
  107. #define USB_PORT_FEAT_CONNECTION 0
  108. #define USB_PORT_FEAT_ENABLE 1
  109. #define USB_PORT_FEAT_SUSPEND 2
  110. #define USB_PORT_FEAT_OVER_CURRENT 3
  111. #define USB_PORT_FEAT_RESET 4
  112. #define USB_PORT_FEAT_POWER 8
  113. #define USB_PORT_FEAT_LOWSPEED 9
  114. #define USB_PORT_FEAT_HIGHSPEED 10
  115. #define USB_PORT_FEAT_C_CONNECTION 16
  116. #define USB_PORT_FEAT_C_ENABLE 17
  117. #define USB_PORT_FEAT_C_SUSPEND 18
  118. #define USB_PORT_FEAT_C_OVER_CURRENT 19
  119. #define USB_PORT_FEAT_C_RESET 20
  120. #define USB_PORT_FEAT_TEST 21
  121. /*
  122. * Changes to Port feature numbers for Super speed,
  123. * from USB 3.0 spec Table 10-8
  124. */
  125. #define USB_SS_PORT_FEAT_U1_TIMEOUT 23
  126. #define USB_SS_PORT_FEAT_U2_TIMEOUT 24
  127. #define USB_SS_PORT_FEAT_C_LINK_STATE 25
  128. #define USB_SS_PORT_FEAT_C_CONFIG_ERROR 26
  129. #define USB_SS_PORT_FEAT_BH_RESET 28
  130. #define USB_SS_PORT_FEAT_C_BH_RESET 29
  131. /* wPortStatus bits */
  132. #define USB_PORT_STAT_CONNECTION 0x0001
  133. #define USB_PORT_STAT_ENABLE 0x0002
  134. #define USB_PORT_STAT_SUSPEND 0x0004
  135. #define USB_PORT_STAT_OVERCURRENT 0x0008
  136. #define USB_PORT_STAT_RESET 0x0010
  137. #define USB_PORT_STAT_POWER 0x0100
  138. #define USB_PORT_STAT_LOW_SPEED 0x0200
  139. #define USB_PORT_STAT_HIGH_SPEED 0x0400 /* support for EHCI */
  140. #define USB_PORT_STAT_SUPER_SPEED 0x0600 /* faking support to XHCI */
  141. #define USB_PORT_STAT_SPEED_MASK \
  142. (USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED)
  143. /* wPortChange bits */
  144. #define USB_PORT_STAT_C_CONNECTION 0x0001
  145. #define USB_PORT_STAT_C_ENABLE 0x0002
  146. #define USB_PORT_STAT_C_SUSPEND 0x0004
  147. #define USB_PORT_STAT_C_OVERCURRENT 0x0008
  148. #define USB_PORT_STAT_C_RESET 0x0010
  149. /*
  150. * Changes to wPortChange bit fields in USB 3.0
  151. * See USB 3.0 spec Table 10-12
  152. */
  153. #define USB_SS_PORT_STAT_C_BH_RESET 0x0020
  154. #define USB_SS_PORT_STAT_C_LINK_STATE 0x0040
  155. #define USB_SS_PORT_STAT_C_CONFIG_ERROR 0x0080
  156. /* wHubCharacteristics (masks) */
  157. #define HUB_CHAR_LPSM 0x0003
  158. #define HUB_CHAR_COMPOUND 0x0004
  159. #define HUB_CHAR_OCPM 0x0018
  160. #define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */
  161. #define USB_DIR_OUT 0 /* to device */
  162. #define USB_DIR_IN 0x80 /* to host */
  163. /*
  164. * Standard requests, for the bRequest field of a SETUP packet.
  165. *
  166. * These are qualified by the bRequestType field, so that for example
  167. * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
  168. * by a GET_STATUS request.
  169. */
  170. #define USB_REQ_GET_STATUS 0x00
  171. #define USB_REQ_CLEAR_FEATURE 0x01
  172. #define USB_REQ_SET_FEATURE 0x03
  173. #define USB_REQ_SET_ADDRESS 0x05
  174. #define USB_REQ_GET_DESCRIPTOR 0x06
  175. #define USB_REQ_SET_DESCRIPTOR 0x07
  176. #define USB_REQ_GET_CONFIGURATION 0x08
  177. #define USB_REQ_SET_CONFIGURATION 0x09
  178. #define USB_REQ_GET_INTERFACE 0x0A
  179. #define USB_REQ_SET_INTERFACE 0x0B
  180. #define USB_REQ_SYNCH_FRAME 0x0C
  181. #define USB_REQ_SET_SEL 0x30
  182. #define USB_REQ_SET_ISOCH_DELAY 0x31
  183. #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
  184. #define USB_REQ_GET_ENCRYPTION 0x0E
  185. #define USB_REQ_RPIPE_ABORT 0x0E
  186. #define USB_REQ_SET_HANDSHAKE 0x0F
  187. #define USB_REQ_RPIPE_RESET 0x0F
  188. #define USB_REQ_GET_HANDSHAKE 0x10
  189. #define USB_REQ_SET_CONNECTION 0x11
  190. #define USB_REQ_SET_SECURITY_DATA 0x12
  191. #define USB_REQ_GET_SECURITY_DATA 0x13
  192. #define USB_REQ_SET_WUSB_DATA 0x14
  193. #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
  194. #define USB_REQ_LOOPBACK_DATA_READ 0x16
  195. #define USB_REQ_SET_INTERFACE_DS 0x17
  196. /*
  197. * Descriptor types ... USB 2.0 spec table 9.5
  198. */
  199. #define USB_DT_DEVICE 0x01
  200. #define USB_DT_CONFIG 0x02
  201. #define USB_DT_STRING 0x03
  202. #define USB_DT_INTERFACE 0x04
  203. #define USB_DT_ENDPOINT 0x05
  204. #define USB_DT_DEVICE_QUALIFIER 0x06
  205. #define USB_DT_OTHER_SPEED_CONFIG 0x07
  206. #define USB_DT_INTERFACE_POWER 0x08
  207. #define USB_DT_HID (USB_TYPE_CLASS | 0x01)
  208. #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
  209. #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
  210. #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
  211. #define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
  212. /* these are from a minor usb 2.0 revision (ECN) */
  213. #define USB_DT_OTG 0x09
  214. #define USB_DT_DEBUG 0x0a
  215. #define USB_DT_INTERFACE_ASSOCIATION 0x0b
  216. /* these are from the Wireless USB spec */
  217. #define USB_DT_SECURITY 0x0c
  218. #define USB_DT_KEY 0x0d
  219. #define USB_DT_ENCRYPTION_TYPE 0x0e
  220. #define USB_DT_BOS 0x0f
  221. #define USB_DT_DEVICE_CAPABILITY 0x10
  222. #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
  223. #define USB_DT_WIRE_ADAPTER 0x21
  224. #define USB_DT_RPIPE 0x22
  225. #define USB_DT_CS_RADIO_CONTROL 0x23
  226. /* From the T10 UAS specification */
  227. #define USB_DT_PIPE_USAGE 0x24
  228. /* From the USB 3.0 spec */
  229. #define USB_DT_SS_ENDPOINT_COMP 0x30
  230. /* From HID 1.11 spec */
  231. #define USB_DT_HID_REPORT 0x22
  232. /*-------------------------------------------------------------------------*/
  233. /* USB 2.0 defines three speeds, here's how Linux identifies them */
  234. enum usb_device_speed {
  235. USB_SPEED_UNKNOWN = 0, /* enumerating */
  236. USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
  237. USB_SPEED_HIGH, /* usb 2.0 */
  238. USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
  239. USB_SPEED_SUPER, /* usb 3.0 */
  240. };
  241. /* Create various pipes... */
  242. #define create_pipe(dev,endpoint) \
  243. (((dev)->devnum << 8) | ((endpoint) << 15) | \
  244. (dev)->maxpacketsize)
  245. #define default_pipe(dev) ((dev)->speed << 26)
  246. #define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
  247. create_pipe(dev, endpoint))
  248. #define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
  249. create_pipe(dev, endpoint) | \
  250. USB_DIR_IN)
  251. #define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
  252. create_pipe(dev, endpoint))
  253. #define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
  254. create_pipe(dev, endpoint) | \
  255. USB_DIR_IN)
  256. #define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
  257. create_pipe(dev, endpoint))
  258. #define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
  259. create_pipe(dev, endpoint) | \
  260. USB_DIR_IN)
  261. #define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
  262. create_pipe(dev, endpoint))
  263. #define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
  264. create_pipe(dev, endpoint) | \
  265. USB_DIR_IN)
  266. #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \
  267. default_pipe(dev))
  268. #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \
  269. default_pipe(dev) | \
  270. USB_DIR_IN)
  271. /* The D0/D1 toggle bits */
  272. #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
  273. #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
  274. #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
  275. ((dev)->toggle[out] & \
  276. ~(1 << ep)) | ((bit) << ep))
  277. /* Endpoint halt control/status */
  278. #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
  279. #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
  280. #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
  281. #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
  282. #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
  283. USB_PID_OUT)
  284. #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
  285. #define usb_pipein(pipe) (((pipe) >> 7) & 1)
  286. #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
  287. #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
  288. #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
  289. #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
  290. #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
  291. #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
  292. #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
  293. #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
  294. #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
  295. #define usb_pipe_ep_index(pipe) \
  296. usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \
  297. ((usb_pipeendpoint(pipe) * 2) - \
  298. (usb_pipein(pipe) ? 0 : 1))
  299. #define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
  300. /* All standard descriptors have these 2 fields at the beginning */
  301. __packed struct usb_descriptor_header {
  302. u8 bLength;
  303. u8 bDescriptorType;
  304. };
  305. __packed struct usb_device_descriptor {
  306. u8 bLength;
  307. u8 bDescriptorType; /* 0x01 */
  308. u16 bcdUSB;
  309. u8 bDeviceClass;
  310. u8 bDeviceSubClass;
  311. u8 bDeviceProtocol;
  312. u8 bMaxPacketSize0;
  313. u16 idVendor;
  314. u16 idProduct;
  315. u16 bcdDevice;
  316. u8 iManufacturer;
  317. u8 iProduct;
  318. u8 iSerialNumber;
  319. u8 bNumConfigurations;
  320. };
  321. #define USB_DT_DEVICE_SIZE 18
  322. /*
  323. * Device and/or Interface Class codes
  324. * as found in bDeviceClass or bInterfaceClass
  325. * and defined by www.usb.org documents
  326. */
  327. #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
  328. #define USB_CLASS_AUDIO 1
  329. #define USB_CLASS_COMM 2
  330. #define USB_CLASS_HID 3
  331. #define USB_CLASS_PHYSICAL 5
  332. #define USB_CLASS_STILL_IMAGE 6
  333. #define USB_CLASS_PRINTER 7
  334. #define USB_CLASS_MASS_STORAGE 8
  335. #define USB_CLASS_HUB 9
  336. #define USB_CLASS_CDC_DATA 0x0a
  337. #define USB_CLASS_CSCID 0x0b /* chip+ smart card */
  338. #define USB_CLASS_CONTENT_SEC 0x0d /* content security */
  339. #define USB_CLASS_VIDEO 0x0e
  340. #define USB_CLASS_WIRELESS_CONTROLLER 0xe0
  341. #define USB_CLASS_MISC 0xef
  342. #define USB_CLASS_APP_SPEC 0xfe
  343. #define USB_CLASS_VENDOR_SPEC 0xff
  344. #define USB_SUBCLASS_VENDOR_SPEC 0xff
  345. __packed struct usb_config_descriptor {
  346. u8 bLength;
  347. u8 bDescriptorType;
  348. u16 wTotalLength;
  349. u8 bNumInterfaces;
  350. u8 bConfigurationValue;
  351. u8 iConfiguration;
  352. u8 bmAttributes;
  353. u8 bMaxPower;
  354. };
  355. #define USB_DT_CONFIG_SIZE 9
  356. /* USB_DT_INTERFACE: Interface descriptor */
  357. __packed struct usb_interface_descriptor {
  358. u8 bLength;
  359. u8 bDescriptorType;
  360. u8 bInterfaceNumber;
  361. u8 bAlternateSetting;
  362. u8 bNumEndpoints;
  363. u8 bInterfaceClass;
  364. u8 bInterfaceSubClass;
  365. u8 bInterfaceProtocol;
  366. u8 iInterface;
  367. };
  368. #define USB_DT_INTERFACE_SIZE 9
  369. /*-------------------------------------------------------------------------*/
  370. /* USB_DT_ENDPOINT: Endpoint descriptor */
  371. __packed struct usb_endpoint_descriptor {
  372. u8 bLength;
  373. u8 bDescriptorType;
  374. u8 bEndpointAddress;
  375. u8 bmAttributes;
  376. u16 wMaxPacketSize;
  377. u8 bInterval;
  378. /* NOTE: these two are _only_ in audio endpoints. */
  379. /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
  380. u8 bRefresh;
  381. u8 bSynchAddress;
  382. };
  383. #define USB_DT_ENDPOINT_SIZE 7
  384. #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
  385. /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
  386. __packed struct usb_ss_ep_comp_descriptor {
  387. u8 bLength;
  388. u8 bDescriptorType;
  389. u8 bMaxBurst;
  390. u8 bmAttributes;
  391. u16 wBytesPerInterval;
  392. };
  393. #define USB_DT_SS_EP_COMP_SIZE 6
  394. /*
  395. * This is the timeout to allow for submitting an urb in ms. We allow more
  396. * time for a BULK device to react - some are slow.
  397. */
  398. //#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
  399. /* device request (setup) */
  400. __packed struct devrequest {
  401. u8 requesttype;
  402. u8 request;
  403. u16 value;
  404. u16 index;
  405. u16 length;
  406. };
  407. /* Interface */
  408. __packed struct usb_interface {
  409. struct usb_interface_descriptor desc;
  410. u8 no_of_ep;
  411. u8 num_altsetting;
  412. u8 act_altsetting;
  413. struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
  414. /*
  415. * Super Speed Device will have Super Speed Endpoint
  416. * Companion Descriptor (section 9.6.7 of usb 3.0 spec)
  417. * Revision 1.0 June 6th 2011
  418. */
  419. struct usb_ss_ep_comp_descriptor ss_ep_comp_desc[USB_MAXENDPOINTS];
  420. };
  421. /* Configuration information.. */
  422. __packed struct usb_config {
  423. struct usb_config_descriptor desc;
  424. u8 no_of_if; /* number of interfaces */
  425. struct usb_interface if_desc[USB_MAXINTERFACES];
  426. };
  427. enum {
  428. /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
  429. PACKET_SIZE_8 = 0,
  430. PACKET_SIZE_16 = 1,
  431. PACKET_SIZE_32 = 2,
  432. PACKET_SIZE_64 = 3,
  433. };
  434. /**
  435. * struct usb_device - information about a USB device
  436. */
  437. struct usb_device {
  438. int devnum; /* Device number on USB bus */
  439. int speed; /* full/low/high */
  440. char mf[32]; /* manufacturer */
  441. char prod[32]; /* product */
  442. char serial[32]; /* serial number */
  443. /* Maximum packet size; one of: PACKET_SIZE_* */
  444. int maxpacketsize;
  445. /* one bit for each endpoint ([0] = IN, [1] = OUT) */
  446. unsigned int toggle[2];
  447. /* endpoint halts; one bit per endpoint # & direction;
  448. * [0] = IN, [1] = OUT
  449. */
  450. unsigned int halted[2];
  451. int epmaxpacketin[16]; /* INput endpoint specific maximums */
  452. int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
  453. int configno; /* selected config number */
  454. /* Device Descriptor */
  455. #pragma pack(ARCH_DMA_MINALIGN)
  456. struct usb_device_descriptor descriptor;
  457. struct usb_config config; /* config descriptor */
  458. int have_langid; /* whether string_langid is valid yet */
  459. int string_langid; /* language ID for strings */
  460. int (*irq_handle)(struct usb_device *dev);
  461. unsigned long irq_status;
  462. int irq_act_len; /* transferred bytes */
  463. void *privptr;
  464. /*
  465. * Child devices - if this is a hub device
  466. * Each instance needs its own set of data structures.
  467. */
  468. unsigned long status;
  469. unsigned long int_pending; /* 1 bit per ep, used by int_queue */
  470. int act_len; /* transferred bytes */
  471. int maxchild; /* Number of ports if hub */
  472. int portnr; /* Port number, 1=first */
  473. /* parent hub, or NULL if this is the root hub */
  474. struct usb_device *parent;
  475. struct usb_device *children[USB_MAXCHILDREN];
  476. void *controller; /* hardware controller private data */
  477. /* slot_id - for xHCI enabled devices */
  478. unsigned int slot_id;
  479. };
  480. enum usb_init_type {
  481. USB_INIT_HOST,
  482. USB_INIT_DEVICE
  483. };
  484. /*************************************************************************
  485. * Hub Stuff
  486. */
  487. __packed struct usb_port_status {
  488. unsigned short wPortStatus;
  489. unsigned short wPortChange;
  490. };
  491. __packed struct usb_hub_status {
  492. unsigned short wHubStatus;
  493. unsigned short wHubChange;
  494. };
  495. /*
  496. * Hub Device descriptor
  497. * USB Hub class device protocols
  498. */
  499. #define USB_HUB_PR_FS 0 /* Full speed hub */
  500. #define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */
  501. #define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */
  502. #define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */
  503. #define USB_HUB_PR_SS 3 /* Super speed hub */
  504. /* Transaction Translator Think Times, in bits */
  505. #define HUB_TTTT_8_BITS 0x00
  506. #define HUB_TTTT_16_BITS 0x20
  507. #define HUB_TTTT_24_BITS 0x40
  508. #define HUB_TTTT_32_BITS 0x60
  509. /* Hub descriptor */
  510. __packed struct usb_hub_descriptor {
  511. unsigned char bLength;
  512. unsigned char bDescriptorType;
  513. unsigned char bNbrPorts;
  514. unsigned short wHubCharacteristics;
  515. unsigned char bPwrOn2PwrGood;
  516. unsigned char bHubContrCurrent;
  517. /* 2.0 and 3.0 hubs differ here */
  518. union {
  519. __packed struct {
  520. /* add 1 bit for hub status change; round to bytes */
  521. unsigned char DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  522. unsigned char PortPowerCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  523. } hs;
  524. __packed struct {
  525. unsigned char bHubHdrDecLat;
  526. unsigned short wHubDelay;
  527. unsigned short DeviceRemovable;
  528. }ss;
  529. } u;
  530. };
  531. struct usb_tt {
  532. bool multi; /* true means one TT per port */
  533. unsigned think_time; /* think time in ns */
  534. };
  535. void usb_find_usb2_hub_address_port(struct usb_device *udev,
  536. uint8_t *hub_address, uint8_t *hub_port);
  537. /*
  538. * CBI style
  539. */
  540. #define US_CBI_ADSC 0
  541. /* Command Block Wrapper */
  542. #define CBWSIGNATURE 0x43425355
  543. #define CBWFLAGS_OUT 0x00
  544. #define CBWFLAGS_IN 0x80
  545. #define CBWFLAGS_SBZ 0x7f
  546. #define CBWCDBLENGTH 16
  547. struct umass_bbb_cbw {
  548. u32 dCBWSignature;
  549. u32 dCBWTag;
  550. u32 dCBWDataTransferLength;
  551. u8 bCBWFlags;
  552. u8 bCBWLUN;
  553. u8 bCDBLength;
  554. u8 CBWCDB[CBWCDBLENGTH];
  555. };
  556. #define UMASS_BBB_CBW_SIZE 31
  557. #define CSWSIGNATURE 0x53425355
  558. #define CSWSTATUS_GOOD 0x0
  559. #define CSWSTATUS_FAILED 0x1
  560. #define CSWSTATUS_PHASE 0x2
  561. /* Command Status Wrapper */
  562. struct umass_bbb_csw {
  563. u32 dCSWSignature;
  564. u32 dCSWTag;
  565. u32 dCSWDataResidue;
  566. u8 bCSWStatus;
  567. };
  568. #define UMASS_BBB_CSW_SIZE 13
  569. /*
  570. * BULK only
  571. */
  572. #define US_BBB_RESET 0xff
  573. #define US_BBB_GET_MAX_LUN 0xfe
  574. struct usb_hub_device {
  575. struct usb_device *pusb_dev;
  576. struct usb_hub_descriptor desc;
  577. unsigned long connect_timeout; /* Device connection timeout in ms */
  578. unsigned long query_delay; /* Device query delay in ms */
  579. int overcurrent_count[USB_MAXCHILDREN]; /* Over-current counter */
  580. int hub_depth; /* USB 3.0 hub depth */
  581. struct usb_tt tt; /* Transaction Translator */
  582. };
  583. /* Device descriptor */
  584. static unsigned char root_hub_dev_des[] = {
  585. 0x12, /* __u8 bLength; */
  586. 0x01, /* __u8 bDescriptorType; Device */
  587. 0x10, /* __u16 bcdUSB; v1.1 */
  588. 0x01,
  589. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  590. 0x00, /* __u8 bDeviceSubClass; */
  591. 0x00, /* __u8 bDeviceProtocol; */
  592. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  593. 0x00, /* __u16 idVendor; */
  594. 0x00,
  595. 0x00, /* __u16 idProduct; */
  596. 0x00,
  597. 0x00, /* __u16 bcdDevice; */
  598. 0x00,
  599. 0x00, /* __u8 iManufacturer; */
  600. 0x01, /* __u8 iProduct; */
  601. 0x00, /* __u8 iSerialNumber; */
  602. 0x01, /* __u8 bNumConfigurations; */
  603. };
  604. /* Configuration descriptor */
  605. static unsigned char root_hub_config_des[] = {
  606. 0x09, /* __u8 bLength; */
  607. 0x02, /* __u8 bDescriptorType; Configuration */
  608. 0x19, /* __u16 wTotalLength; */
  609. 0x00,
  610. 0x01, /* __u8 bNumInterfaces; */
  611. 0x01, /* __u8 bConfigurationValue; */
  612. 0x00, /* __u8 iConfiguration; */
  613. 0x40, /* __u8 bmAttributes;
  614. * Bit 7: Bus-powered
  615. * 6: Self-powered,
  616. * 5 Remote-wakwup,
  617. * 4..0: resvd
  618. */
  619. 0x00, /* __u8 MaxPower; */
  620. /* interface */
  621. 0x09, /* __u8 if_bLength; */
  622. 0x04, /* __u8 if_bDescriptorType; Interface */
  623. 0x00, /* __u8 if_bInterfaceNumber; */
  624. 0x00, /* __u8 if_bAlternateSetting; */
  625. 0x01, /* __u8 if_bNumEndpoints; */
  626. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  627. 0x00, /* __u8 if_bInterfaceSubClass; */
  628. 0x00, /* __u8 if_bInterfaceProtocol; */
  629. 0x00, /* __u8 if_iInterface; */
  630. /* endpoint */
  631. 0x07, /* __u8 ep_bLength; */
  632. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  633. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  634. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  635. 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
  636. 0x00,
  637. 0xff, /* __u8 ep_bInterval; 255 ms */
  638. };
  639. #if 0
  640. #ifdef WANT_USB_ROOT_HUB_HUB_DES
  641. static unsigned char root_hub_hub_des[] = {
  642. 0x09, /* __u8 bLength; */
  643. 0x29, /* __u8 bDescriptorType; Hub-descriptor */
  644. 0x02, /* __u8 bNbrPorts; */
  645. 0x00, /* __u16 wHubCharacteristics; */
  646. 0x00,
  647. 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
  648. 0x00, /* __u8 bHubContrCurrent; 0 mA */
  649. 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
  650. 0xff, /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
  651. };
  652. #endif
  653. #endif
  654. static unsigned char root_hub_str_index0[] = {
  655. 0x04, /* __u8 bLength; */
  656. 0x03, /* __u8 bDescriptorType; String-descriptor */
  657. 0x09, /* __u8 lang ID */
  658. 0x04, /* __u8 lang ID */
  659. };
  660. static unsigned char root_hub_str_index1[] = {
  661. 32, /* __u8 bLength; */
  662. 0x03, /* __u8 bDescriptorType; String-descriptor */
  663. 'U', /* __u8 Unicode */
  664. 0, /* __u8 Unicode */
  665. '-', /* __u8 Unicode */
  666. 0, /* __u8 Unicode */
  667. 'B', /* __u8 Unicode */
  668. 0, /* __u8 Unicode */
  669. 'o', /* __u8 Unicode */
  670. 0, /* __u8 Unicode */
  671. 'o', /* __u8 Unicode */
  672. 0, /* __u8 Unicode */
  673. 't', /* __u8 Unicode */
  674. 0, /* __u8 Unicode */
  675. ' ', /* __u8 Unicode */
  676. 0, /* __u8 Unicode */
  677. 'R', /* __u8 Unicode */
  678. 0, /* __u8 Unicode */
  679. 'o', /* __u8 Unicode */
  680. 0, /* __u8 Unicode */
  681. 'o', /* __u8 Unicode */
  682. 0, /* __u8 Unicode */
  683. 't', /* __u8 Unicode */
  684. 0, /* __u8 Unicode */
  685. ' ', /* __u8 Unicode */
  686. 0, /* __u8 Unicode */
  687. 'H', /* __u8 Unicode */
  688. 0, /* __u8 Unicode */
  689. 'u', /* __u8 Unicode */
  690. 0, /* __u8 Unicode */
  691. 'b', /* __u8 Unicode */
  692. 0, /* __u8 Unicode */
  693. };
  694. //sdp
  695. #define EP0_CON 0
  696. #define EP_MASK 0xF
  697. int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
  698. #endif