xhci.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /*
  2. * xHCI host controller driver
  3. *
  4. * Copyright (C) 2008 Intel Corp.
  5. *
  6. * Author: Sarah Sharp
  7. * Some code borrowed from the Linux EHCI driver.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #ifndef __LINUX_XHCI_HCD_H
  23. #define __LINUX_XHCI_HCD_H
  24. #include <linux/usb.h>
  25. #include <linux/timer.h>
  26. #include "../core/hcd.h"
  27. /* Code sharing between pci-quirks and xhci hcd */
  28. #include "xhci-ext-caps.h"
  29. /* xHCI PCI Configuration Registers */
  30. #define XHCI_SBRN_OFFSET (0x60)
  31. /* Max number of USB devices for any host controller - limit in section 6.1 */
  32. #define MAX_HC_SLOTS 256
  33. /* Section 5.3.3 - MaxPorts */
  34. #define MAX_HC_PORTS 127
  35. /*
  36. * xHCI register interface.
  37. * This corresponds to the eXtensible Host Controller Interface (xHCI)
  38. * Revision 0.95 specification
  39. *
  40. * Registers should always be accessed with double word or quad word accesses.
  41. *
  42. * Some xHCI implementations may support 64-bit address pointers. Registers
  43. * with 64-bit address pointers should be written to with dword accesses by
  44. * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
  45. * xHCI implementations that do not support 64-bit address pointers will ignore
  46. * the high dword, and write order is irrelevant.
  47. */
  48. /**
  49. * struct xhci_cap_regs - xHCI Host Controller Capability Registers.
  50. * @hc_capbase: length of the capabilities register and HC version number
  51. * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
  52. * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
  53. * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
  54. * @hcc_params: HCCPARAMS - Capability Parameters
  55. * @db_off: DBOFF - Doorbell array offset
  56. * @run_regs_off: RTSOFF - Runtime register space offset
  57. */
  58. struct xhci_cap_regs {
  59. u32 hc_capbase;
  60. u32 hcs_params1;
  61. u32 hcs_params2;
  62. u32 hcs_params3;
  63. u32 hcc_params;
  64. u32 db_off;
  65. u32 run_regs_off;
  66. /* Reserved up to (CAPLENGTH - 0x1C) */
  67. } __attribute__ ((packed));
  68. /* hc_capbase bitmasks */
  69. /* bits 7:0 - how long is the Capabilities register */
  70. #define HC_LENGTH(p) XHCI_HC_LENGTH(p)
  71. /* bits 31:16 */
  72. #define HC_VERSION(p) (((p) >> 16) & 0xffff)
  73. /* HCSPARAMS1 - hcs_params1 - bitmasks */
  74. /* bits 0:7, Max Device Slots */
  75. #define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
  76. #define HCS_SLOTS_MASK 0xff
  77. /* bits 8:18, Max Interrupters */
  78. #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
  79. /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
  80. #define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
  81. /* HCSPARAMS2 - hcs_params2 - bitmasks */
  82. /* bits 0:3, frames or uframes that SW needs to queue transactions
  83. * ahead of the HW to meet periodic deadlines */
  84. #define HCS_IST(p) (((p) >> 0) & 0xf)
  85. /* bits 4:7, max number of Event Ring segments */
  86. #define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
  87. /* bit 26 Scratchpad restore - for save/restore HW state - not used yet */
  88. /* bits 27:31 number of Scratchpad buffers SW must allocate for the HW */
  89. /* HCSPARAMS3 - hcs_params3 - bitmasks */
  90. /* bits 0:7, Max U1 to U0 latency for the roothub ports */
  91. #define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
  92. /* bits 16:31, Max U2 to U0 latency for the roothub ports */
  93. #define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
  94. /* HCCPARAMS - hcc_params - bitmasks */
  95. /* true: HC can use 64-bit address pointers */
  96. #define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
  97. /* true: HC can do bandwidth negotiation */
  98. #define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
  99. /* true: HC uses 64-byte Device Context structures
  100. * FIXME 64-byte context structures aren't supported yet.
  101. */
  102. #define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
  103. /* true: HC has port power switches */
  104. #define HCC_PPC(p) ((p) & (1 << 3))
  105. /* true: HC has port indicators */
  106. #define HCS_INDICATOR(p) ((p) & (1 << 4))
  107. /* true: HC has Light HC Reset Capability */
  108. #define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
  109. /* true: HC supports latency tolerance messaging */
  110. #define HCC_LTC(p) ((p) & (1 << 6))
  111. /* true: no secondary Stream ID Support */
  112. #define HCC_NSS(p) ((p) & (1 << 7))
  113. /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
  114. #define HCC_MAX_PSA (1 << ((((p) >> 12) & 0xf) + 1))
  115. /* Extended Capabilities pointer from PCI base - section 5.3.6 */
  116. #define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
  117. /* db_off bitmask - bits 0:1 reserved */
  118. #define DBOFF_MASK (~0x3)
  119. /* run_regs_off bitmask - bits 0:4 reserved */
  120. #define RTSOFF_MASK (~0x1f)
  121. /* Number of registers per port */
  122. #define NUM_PORT_REGS 4
  123. /**
  124. * struct xhci_op_regs - xHCI Host Controller Operational Registers.
  125. * @command: USBCMD - xHC command register
  126. * @status: USBSTS - xHC status register
  127. * @page_size: This indicates the page size that the host controller
  128. * supports. If bit n is set, the HC supports a page size
  129. * of 2^(n+12), up to a 128MB page size.
  130. * 4K is the minimum page size.
  131. * @cmd_ring: CRP - 64-bit Command Ring Pointer
  132. * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer
  133. * @config_reg: CONFIG - Configure Register
  134. * @port_status_base: PORTSCn - base address for Port Status and Control
  135. * Each port has a Port Status and Control register,
  136. * followed by a Port Power Management Status and Control
  137. * register, a Port Link Info register, and a reserved
  138. * register.
  139. * @port_power_base: PORTPMSCn - base address for
  140. * Port Power Management Status and Control
  141. * @port_link_base: PORTLIn - base address for Port Link Info (current
  142. * Link PM state and control) for USB 2.1 and USB 3.0
  143. * devices.
  144. */
  145. struct xhci_op_regs {
  146. u32 command;
  147. u32 status;
  148. u32 page_size;
  149. u32 reserved1;
  150. u32 reserved2;
  151. u32 dev_notification;
  152. u32 cmd_ring[2];
  153. /* rsvd: offset 0x20-2F */
  154. u32 reserved3[4];
  155. u32 dcbaa_ptr[2];
  156. u32 config_reg;
  157. /* rsvd: offset 0x3C-3FF */
  158. u32 reserved4[241];
  159. /* port 1 registers, which serve as a base address for other ports */
  160. u32 port_status_base;
  161. u32 port_power_base;
  162. u32 port_link_base;
  163. u32 reserved5;
  164. /* registers for ports 2-255 */
  165. u32 reserved6[NUM_PORT_REGS*254];
  166. } __attribute__ ((packed));
  167. /* USBCMD - USB command - command bitmasks */
  168. /* start/stop HC execution - do not write unless HC is halted*/
  169. #define CMD_RUN XHCI_CMD_RUN
  170. /* Reset HC - resets internal HC state machine and all registers (except
  171. * PCI config regs). HC does NOT drive a USB reset on the downstream ports.
  172. * The xHCI driver must reinitialize the xHC after setting this bit.
  173. */
  174. #define CMD_RESET (1 << 1)
  175. /* Event Interrupt Enable - a '1' allows interrupts from the host controller */
  176. #define CMD_EIE XHCI_CMD_EIE
  177. /* Host System Error Interrupt Enable - get out-of-band signal for HC errors */
  178. #define CMD_HSEIE XHCI_CMD_HSEIE
  179. /* bits 4:6 are reserved (and should be preserved on writes). */
  180. /* light reset (port status stays unchanged) - reset completed when this is 0 */
  181. #define CMD_LRESET (1 << 7)
  182. /* FIXME: ignoring host controller save/restore state for now. */
  183. #define CMD_CSS (1 << 8)
  184. #define CMD_CRS (1 << 9)
  185. /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
  186. #define CMD_EWE XHCI_CMD_EWE
  187. /* MFINDEX power management - '1' means xHC can stop MFINDEX counter if all root
  188. * hubs are in U3 (selective suspend), disconnect, disabled, or powered-off.
  189. * '0' means the xHC can power it off if all ports are in the disconnect,
  190. * disabled, or powered-off state.
  191. */
  192. #define CMD_PM_INDEX (1 << 11)
  193. /* bits 12:31 are reserved (and should be preserved on writes). */
  194. /* USBSTS - USB status - status bitmasks */
  195. /* HC not running - set to 1 when run/stop bit is cleared. */
  196. #define STS_HALT XHCI_STS_HALT
  197. /* serious error, e.g. PCI parity error. The HC will clear the run/stop bit. */
  198. #define STS_FATAL (1 << 2)
  199. /* event interrupt - clear this prior to clearing any IP flags in IR set*/
  200. #define STS_EINT (1 << 3)
  201. /* port change detect */
  202. #define STS_PORT (1 << 4)
  203. /* bits 5:7 reserved and zeroed */
  204. /* save state status - '1' means xHC is saving state */
  205. #define STS_SAVE (1 << 8)
  206. /* restore state status - '1' means xHC is restoring state */
  207. #define STS_RESTORE (1 << 9)
  208. /* true: save or restore error */
  209. #define STS_SRE (1 << 10)
  210. /* true: Controller Not Ready to accept doorbell or op reg writes after reset */
  211. #define STS_CNR XHCI_STS_CNR
  212. /* true: internal Host Controller Error - SW needs to reset and reinitialize */
  213. #define STS_HCE (1 << 12)
  214. /* bits 13:31 reserved and should be preserved */
  215. /*
  216. * DNCTRL - Device Notification Control Register - dev_notification bitmasks
  217. * Generate a device notification event when the HC sees a transaction with a
  218. * notification type that matches a bit set in this bit field.
  219. */
  220. #define DEV_NOTE_MASK (0xffff)
  221. #define ENABLE_DEV_NOTE(x) (1 << x)
  222. /* Most of the device notification types should only be used for debug.
  223. * SW does need to pay attention to function wake notifications.
  224. */
  225. #define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
  226. /* CRCR - Command Ring Control Register - cmd_ring bitmasks */
  227. /* bit 0 is the command ring cycle state */
  228. /* stop ring operation after completion of the currently executing command */
  229. #define CMD_RING_PAUSE (1 << 1)
  230. /* stop ring immediately - abort the currently executing command */
  231. #define CMD_RING_ABORT (1 << 2)
  232. /* true: command ring is running */
  233. #define CMD_RING_RUNNING (1 << 3)
  234. /* bits 4:5 reserved and should be preserved */
  235. /* Command Ring pointer - bit mask for the lower 32 bits. */
  236. #define CMD_RING_ADDR_MASK (0xffffffc0)
  237. /* CONFIG - Configure Register - config_reg bitmasks */
  238. /* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */
  239. #define MAX_DEVS(p) ((p) & 0xff)
  240. /* bits 8:31 - reserved and should be preserved */
  241. /* PORTSC - Port Status and Control Register - port_status_base bitmasks */
  242. /* true: device connected */
  243. #define PORT_CONNECT (1 << 0)
  244. /* true: port enabled */
  245. #define PORT_PE (1 << 1)
  246. /* bit 2 reserved and zeroed */
  247. /* true: port has an over-current condition */
  248. #define PORT_OC (1 << 3)
  249. /* true: port reset signaling asserted */
  250. #define PORT_RESET (1 << 4)
  251. /* Port Link State - bits 5:8
  252. * A read gives the current link PM state of the port,
  253. * a write with Link State Write Strobe set sets the link state.
  254. */
  255. /* true: port has power (see HCC_PPC) */
  256. #define PORT_POWER (1 << 9)
  257. /* bits 10:13 indicate device speed:
  258. * 0 - undefined speed - port hasn't be initialized by a reset yet
  259. * 1 - full speed
  260. * 2 - low speed
  261. * 3 - high speed
  262. * 4 - super speed
  263. * 5-15 reserved
  264. */
  265. #define DEV_SPEED_MASK (0xf << 10)
  266. #define XDEV_FS (0x1 << 10)
  267. #define XDEV_LS (0x2 << 10)
  268. #define XDEV_HS (0x3 << 10)
  269. #define XDEV_SS (0x4 << 10)
  270. #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
  271. #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
  272. #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
  273. #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
  274. #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
  275. /* Bits 20:23 in the Slot Context are the speed for the device */
  276. #define SLOT_SPEED_FS (XDEV_FS << 10)
  277. #define SLOT_SPEED_LS (XDEV_LS << 10)
  278. #define SLOT_SPEED_HS (XDEV_HS << 10)
  279. #define SLOT_SPEED_SS (XDEV_SS << 10)
  280. /* Port Indicator Control */
  281. #define PORT_LED_OFF (0 << 14)
  282. #define PORT_LED_AMBER (1 << 14)
  283. #define PORT_LED_GREEN (2 << 14)
  284. #define PORT_LED_MASK (3 << 14)
  285. /* Port Link State Write Strobe - set this when changing link state */
  286. #define PORT_LINK_STROBE (1 << 16)
  287. /* true: connect status change */
  288. #define PORT_CSC (1 << 17)
  289. /* true: port enable change */
  290. #define PORT_PEC (1 << 18)
  291. /* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port
  292. * into an enabled state, and the device into the default state. A "warm" reset
  293. * also resets the link, forcing the device through the link training sequence.
  294. * SW can also look at the Port Reset register to see when warm reset is done.
  295. */
  296. #define PORT_WRC (1 << 19)
  297. /* true: over-current change */
  298. #define PORT_OCC (1 << 20)
  299. /* true: reset change - 1 to 0 transition of PORT_RESET */
  300. #define PORT_RC (1 << 21)
  301. /* port link status change - set on some port link state transitions:
  302. * Transition Reason
  303. * ------------------------------------------------------------------------------
  304. * - U3 to Resume Wakeup signaling from a device
  305. * - Resume to Recovery to U0 USB 3.0 device resume
  306. * - Resume to U0 USB 2.0 device resume
  307. * - U3 to Recovery to U0 Software resume of USB 3.0 device complete
  308. * - U3 to U0 Software resume of USB 2.0 device complete
  309. * - U2 to U0 L1 resume of USB 2.1 device complete
  310. * - U0 to U0 (???) L1 entry rejection by USB 2.1 device
  311. * - U0 to disabled L1 entry error with USB 2.1 device
  312. * - Any state to inactive Error on USB 3.0 port
  313. */
  314. #define PORT_PLC (1 << 22)
  315. /* port configure error change - port failed to configure its link partner */
  316. #define PORT_CEC (1 << 23)
  317. /* bit 24 reserved */
  318. /* wake on connect (enable) */
  319. #define PORT_WKCONN_E (1 << 25)
  320. /* wake on disconnect (enable) */
  321. #define PORT_WKDISC_E (1 << 26)
  322. /* wake on over-current (enable) */
  323. #define PORT_WKOC_E (1 << 27)
  324. /* bits 28:29 reserved */
  325. /* true: device is removable - for USB 3.0 roothub emulation */
  326. #define PORT_DEV_REMOVE (1 << 30)
  327. /* Initiate a warm port reset - complete when PORT_WRC is '1' */
  328. #define PORT_WR (1 << 31)
  329. /* Port Power Management Status and Control - port_power_base bitmasks */
  330. /* Inactivity timer value for transitions into U1, in microseconds.
  331. * Timeout can be up to 127us. 0xFF means an infinite timeout.
  332. */
  333. #define PORT_U1_TIMEOUT(p) ((p) & 0xff)
  334. /* Inactivity timer value for transitions into U2 */
  335. #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
  336. /* Bits 24:31 for port testing */
  337. /**
  338. * struct intr_reg - Interrupt Register Set
  339. * @irq_pending: IMAN - Interrupt Management Register. Used to enable
  340. * interrupts and check for pending interrupts.
  341. * @irq_control: IMOD - Interrupt Moderation Register.
  342. * Used to throttle interrupts.
  343. * @erst_size: Number of segments in the Event Ring Segment Table (ERST).
  344. * @erst_base: ERST base address.
  345. * @erst_dequeue: Event ring dequeue pointer.
  346. *
  347. * Each interrupter (defined by a MSI-X vector) has an event ring and an Event
  348. * Ring Segment Table (ERST) associated with it. The event ring is comprised of
  349. * multiple segments of the same size. The HC places events on the ring and
  350. * "updates the Cycle bit in the TRBs to indicate to software the current
  351. * position of the Enqueue Pointer." The HCD (Linux) processes those events and
  352. * updates the dequeue pointer.
  353. */
  354. struct intr_reg {
  355. u32 irq_pending;
  356. u32 irq_control;
  357. u32 erst_size;
  358. u32 rsvd;
  359. u32 erst_base[2];
  360. u32 erst_dequeue[2];
  361. } __attribute__ ((packed));
  362. /* irq_pending bitmasks */
  363. #define ER_IRQ_PENDING(p) ((p) & 0x1)
  364. /* bits 2:31 need to be preserved */
  365. /* THIS IS BUGGY - FIXME - IP IS WRITE 1 TO CLEAR */
  366. #define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
  367. #define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
  368. #define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
  369. /* irq_control bitmasks */
  370. /* Minimum interval between interrupts (in 250ns intervals). The interval
  371. * between interrupts will be longer if there are no events on the event ring.
  372. * Default is 4000 (1 ms).
  373. */
  374. #define ER_IRQ_INTERVAL_MASK (0xffff)
  375. /* Counter used to count down the time to the next interrupt - HW use only */
  376. #define ER_IRQ_COUNTER_MASK (0xffff << 16)
  377. /* erst_size bitmasks */
  378. /* Preserve bits 16:31 of erst_size */
  379. #define ERST_SIZE_MASK (0xffff << 16)
  380. /* erst_dequeue bitmasks */
  381. /* Dequeue ERST Segment Index (DESI) - Segment number (or alias)
  382. * where the current dequeue pointer lies. This is an optional HW hint.
  383. */
  384. #define ERST_DESI_MASK (0x7)
  385. /* Event Handler Busy (EHB) - is the event ring scheduled to be serviced by
  386. * a work queue (or delayed service routine)?
  387. */
  388. #define ERST_EHB (1 << 3)
  389. #define ERST_PTR_MASK (0xf)
  390. /**
  391. * struct xhci_run_regs
  392. * @microframe_index:
  393. * MFINDEX - current microframe number
  394. *
  395. * Section 5.5 Host Controller Runtime Registers:
  396. * "Software should read and write these registers using only Dword (32 bit)
  397. * or larger accesses"
  398. */
  399. struct xhci_run_regs {
  400. u32 microframe_index;
  401. u32 rsvd[7];
  402. struct intr_reg ir_set[128];
  403. } __attribute__ ((packed));
  404. /**
  405. * struct doorbell_array
  406. *
  407. * Section 5.6
  408. */
  409. struct xhci_doorbell_array {
  410. u32 doorbell[256];
  411. } __attribute__ ((packed));
  412. #define DB_TARGET_MASK 0xFFFFFF00
  413. #define DB_STREAM_ID_MASK 0x0000FFFF
  414. #define DB_TARGET_HOST 0x0
  415. #define DB_STREAM_ID_HOST 0x0
  416. #define DB_MASK (0xff << 8)
  417. /**
  418. * struct xhci_slot_ctx
  419. * @dev_info: Route string, device speed, hub info, and last valid endpoint
  420. * @dev_info2: Max exit latency for device number, root hub port number
  421. * @tt_info: tt_info is used to construct split transaction tokens
  422. * @dev_state: slot state and device address
  423. *
  424. * Slot Context - section 6.2.1.1. This assumes the HC uses 32-byte context
  425. * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
  426. * reserved at the end of the slot context for HC internal use.
  427. */
  428. struct xhci_slot_ctx {
  429. u32 dev_info;
  430. u32 dev_info2;
  431. u32 tt_info;
  432. u32 dev_state;
  433. /* offset 0x10 to 0x1f reserved for HC internal use */
  434. u32 reserved[4];
  435. } __attribute__ ((packed));
  436. /* dev_info bitmasks */
  437. /* Route String - 0:19 */
  438. #define ROUTE_STRING_MASK (0xfffff)
  439. /* Device speed - values defined by PORTSC Device Speed field - 20:23 */
  440. #define DEV_SPEED (0xf << 20)
  441. /* bit 24 reserved */
  442. /* Is this LS/FS device connected through a HS hub? - bit 25 */
  443. #define DEV_MTT (0x1 << 25)
  444. /* Set if the device is a hub - bit 26 */
  445. #define DEV_HUB (0x1 << 26)
  446. /* Index of the last valid endpoint context in this device context - 27:31 */
  447. #define LAST_CTX_MASK (0x1f << 27)
  448. #define LAST_CTX(p) ((p) << 27)
  449. #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
  450. /* Plus one for the slot context flag */
  451. #define EPI_TO_FLAG(p) (1 << ((p) + 1))
  452. #define SLOT_FLAG (1 << 0)
  453. #define EP0_FLAG (1 << 1)
  454. /* dev_info2 bitmasks */
  455. /* Max Exit Latency (ms) - worst case time to wake up all links in dev path */
  456. #define MAX_EXIT (0xffff)
  457. /* Root hub port number that is needed to access the USB device */
  458. #define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
  459. /* tt_info bitmasks */
  460. /*
  461. * TT Hub Slot ID - for low or full speed devices attached to a high-speed hub
  462. * The Slot ID of the hub that isolates the high speed signaling from
  463. * this low or full-speed device. '0' if attached to root hub port.
  464. */
  465. #define TT_SLOT (0xff)
  466. /*
  467. * The number of the downstream facing port of the high-speed hub
  468. * '0' if the device is not low or full speed.
  469. */
  470. #define TT_PORT (0xff << 8)
  471. /* dev_state bitmasks */
  472. /* USB device address - assigned by the HC */
  473. #define DEV_ADDR_MASK (0xff)
  474. /* bits 8:26 reserved */
  475. /* Slot state */
  476. #define SLOT_STATE (0x1f << 27)
  477. /**
  478. * struct xhci_ep_ctx
  479. * @ep_info: endpoint state, streams, mult, and interval information.
  480. * @ep_info2: information on endpoint type, max packet size, max burst size,
  481. * error count, and whether the HC will force an event for all
  482. * transactions.
  483. * @deq: 64-bit ring dequeue pointer address. If the endpoint only
  484. * defines one stream, this points to the endpoint transfer ring.
  485. * Otherwise, it points to a stream context array, which has a
  486. * ring pointer for each flow.
  487. * @tx_info:
  488. * Average TRB lengths for the endpoint ring and
  489. * max payload within an Endpoint Service Interval Time (ESIT).
  490. *
  491. * Endpoint Context - section 6.2.1.2. This assumes the HC uses 32-byte context
  492. * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
  493. * reserved at the end of the endpoint context for HC internal use.
  494. */
  495. struct xhci_ep_ctx {
  496. u32 ep_info;
  497. u32 ep_info2;
  498. u32 deq[2];
  499. u32 tx_info;
  500. /* offset 0x14 - 0x1f reserved for HC internal use */
  501. u32 reserved[3];
  502. } __attribute__ ((packed));
  503. /* ep_info bitmasks */
  504. /*
  505. * Endpoint State - bits 0:2
  506. * 0 - disabled
  507. * 1 - running
  508. * 2 - halted due to halt condition - ok to manipulate endpoint ring
  509. * 3 - stopped
  510. * 4 - TRB error
  511. * 5-7 - reserved
  512. */
  513. #define EP_STATE (0xf)
  514. /* Mult - Max number of burtst within an interval, in EP companion desc. */
  515. #define EP_MULT(p) ((p & 0x3) << 8)
  516. /* bits 10:14 are Max Primary Streams */
  517. /* bit 15 is Linear Stream Array */
  518. /* Interval - period between requests to an endpoint - 125u increments. */
  519. #define EP_INTERVAL (0xff << 16)
  520. /* ep_info2 bitmasks */
  521. /*
  522. * Force Event - generate transfer events for all TRBs for this endpoint
  523. * This will tell the HC to ignore the IOC and ISP flags (for debugging only).
  524. */
  525. #define FORCE_EVENT (0x1)
  526. #define ERROR_COUNT(p) (((p) & 0x3) << 1)
  527. #define EP_TYPE(p) ((p) << 3)
  528. #define ISOC_OUT_EP 1
  529. #define BULK_OUT_EP 2
  530. #define INT_OUT_EP 3
  531. #define CTRL_EP 4
  532. #define ISOC_IN_EP 5
  533. #define BULK_IN_EP 6
  534. #define INT_IN_EP 7
  535. /* bit 6 reserved */
  536. /* bit 7 is Host Initiate Disable - for disabling stream selection */
  537. #define MAX_BURST(p) (((p)&0xff) << 8)
  538. #define MAX_PACKET(p) (((p)&0xffff) << 16)
  539. /**
  540. * struct xhci_device_control
  541. * Input/Output context; see section 6.2.5.
  542. *
  543. * @drop_context: set the bit of the endpoint context you want to disable
  544. * @add_context: set the bit of the endpoint context you want to enable
  545. */
  546. struct xhci_device_control {
  547. u32 drop_flags;
  548. u32 add_flags;
  549. u32 rsvd[6];
  550. struct xhci_slot_ctx slot;
  551. struct xhci_ep_ctx ep[31];
  552. } __attribute__ ((packed));
  553. /* drop context bitmasks */
  554. #define DROP_EP(x) (0x1 << x)
  555. /* add context bitmasks */
  556. #define ADD_EP(x) (0x1 << x)
  557. struct xhci_virt_device {
  558. /*
  559. * Commands to the hardware are passed an "input context" that
  560. * tells the hardware what to change in its data structures.
  561. * The hardware will return changes in an "output context" that
  562. * software must allocate for the hardware. We need to keep
  563. * track of input and output contexts separately because
  564. * these commands might fail and we don't trust the hardware.
  565. */
  566. struct xhci_device_control *out_ctx;
  567. dma_addr_t out_ctx_dma;
  568. /* Used for addressing devices and configuration changes */
  569. struct xhci_device_control *in_ctx;
  570. dma_addr_t in_ctx_dma;
  571. /* FIXME when stream support is added */
  572. struct xhci_ring *ep_rings[31];
  573. dma_addr_t ep_dma[31];
  574. /* Status of the last command issued for this device */
  575. u32 cmd_status;
  576. };
  577. /**
  578. * struct xhci_device_context_array
  579. * @dev_context_ptr array of 64-bit DMA addresses for device contexts
  580. */
  581. struct xhci_device_context_array {
  582. /* 64-bit device addresses; we only write 32-bit addresses */
  583. u32 dev_context_ptrs[2*MAX_HC_SLOTS];
  584. /* private xHCD pointers */
  585. dma_addr_t dma;
  586. } __attribute__ ((packed));
  587. /* TODO: write function to set the 64-bit device DMA address */
  588. /*
  589. * TODO: change this to be dynamically sized at HC mem init time since the HC
  590. * might not be able to handle the maximum number of devices possible.
  591. */
  592. struct xhci_stream_ctx {
  593. /* 64-bit stream ring address, cycle state, and stream type */
  594. u32 stream_ring[2];
  595. /* offset 0x14 - 0x1f reserved for HC internal use */
  596. u32 reserved[2];
  597. } __attribute__ ((packed));
  598. struct xhci_transfer_event {
  599. /* 64-bit buffer address, or immediate data */
  600. u32 buffer[2];
  601. u32 transfer_len;
  602. /* This field is interpreted differently based on the type of TRB */
  603. u32 flags;
  604. } __attribute__ ((packed));
  605. /* Completion Code - only applicable for some types of TRBs */
  606. #define COMP_CODE_MASK (0xff << 24)
  607. #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
  608. #define COMP_SUCCESS 1
  609. /* Data Buffer Error */
  610. #define COMP_DB_ERR 2
  611. /* Babble Detected Error */
  612. #define COMP_BABBLE 3
  613. /* USB Transaction Error */
  614. #define COMP_TX_ERR 4
  615. /* TRB Error - some TRB field is invalid */
  616. #define COMP_TRB_ERR 5
  617. /* Stall Error - USB device is stalled */
  618. #define COMP_STALL 6
  619. /* Resource Error - HC doesn't have memory for that device configuration */
  620. #define COMP_ENOMEM 7
  621. /* Bandwidth Error - not enough room in schedule for this dev config */
  622. #define COMP_BW_ERR 8
  623. /* No Slots Available Error - HC ran out of device slots */
  624. #define COMP_ENOSLOTS 9
  625. /* Invalid Stream Type Error */
  626. #define COMP_STREAM_ERR 10
  627. /* Slot Not Enabled Error - doorbell rung for disabled device slot */
  628. #define COMP_EBADSLT 11
  629. /* Endpoint Not Enabled Error */
  630. #define COMP_EBADEP 12
  631. /* Short Packet */
  632. #define COMP_SHORT_TX 13
  633. /* Ring Underrun - doorbell rung for an empty isoc OUT ep ring */
  634. #define COMP_UNDERRUN 14
  635. /* Ring Overrun - isoc IN ep ring is empty when ep is scheduled to RX */
  636. #define COMP_OVERRUN 15
  637. /* Virtual Function Event Ring Full Error */
  638. #define COMP_VF_FULL 16
  639. /* Parameter Error - Context parameter is invalid */
  640. #define COMP_EINVAL 17
  641. /* Bandwidth Overrun Error - isoc ep exceeded its allocated bandwidth */
  642. #define COMP_BW_OVER 18
  643. /* Context State Error - illegal context state transition requested */
  644. #define COMP_CTX_STATE 19
  645. /* No Ping Response Error - HC didn't get PING_RESPONSE in time to TX */
  646. #define COMP_PING_ERR 20
  647. /* Event Ring is full */
  648. #define COMP_ER_FULL 21
  649. /* Missed Service Error - HC couldn't service an isoc ep within interval */
  650. #define COMP_MISSED_INT 23
  651. /* Successfully stopped command ring */
  652. #define COMP_CMD_STOP 24
  653. /* Successfully aborted current command and stopped command ring */
  654. #define COMP_CMD_ABORT 25
  655. /* Stopped - transfer was terminated by a stop endpoint command */
  656. #define COMP_STOP 26
  657. /* Same as COMP_EP_STOPPED, but the transfered length in the event is invalid */
  658. #define COMP_STOP_INVAL 27
  659. /* Control Abort Error - Debug Capability - control pipe aborted */
  660. #define COMP_DBG_ABORT 28
  661. /* TRB type 29 and 30 reserved */
  662. /* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
  663. #define COMP_BUFF_OVER 31
  664. /* Event Lost Error - xHC has an "internal event overrun condition" */
  665. #define COMP_ISSUES 32
  666. /* Undefined Error - reported when other error codes don't apply */
  667. #define COMP_UNKNOWN 33
  668. /* Invalid Stream ID Error */
  669. #define COMP_STRID_ERR 34
  670. /* Secondary Bandwidth Error - may be returned by a Configure Endpoint cmd */
  671. /* FIXME - check for this */
  672. #define COMP_2ND_BW_ERR 35
  673. /* Split Transaction Error */
  674. #define COMP_SPLIT_ERR 36
  675. struct xhci_link_trb {
  676. /* 64-bit segment pointer*/
  677. u32 segment_ptr[2];
  678. u32 intr_target;
  679. u32 control;
  680. } __attribute__ ((packed));
  681. /* control bitfields */
  682. #define LINK_TOGGLE (0x1<<1)
  683. /* Command completion event TRB */
  684. struct xhci_event_cmd {
  685. /* Pointer to command TRB, or the value passed by the event data trb */
  686. u32 cmd_trb[2];
  687. u32 status;
  688. u32 flags;
  689. } __attribute__ ((packed));
  690. /* flags bitmasks */
  691. /* bits 16:23 are the virtual function ID */
  692. /* bits 24:31 are the slot ID */
  693. #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
  694. #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
  695. /* Port Status Change Event TRB fields */
  696. /* Port ID - bits 31:24 */
  697. #define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
  698. /* Normal TRB fields */
  699. /* transfer_len bitmasks - bits 0:16 */
  700. #define TRB_LEN(p) ((p) & 0x1ffff)
  701. /* TD size - number of bytes remaining in the TD (including this TRB):
  702. * bits 17 - 21. Shift the number of bytes by 10. */
  703. #define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
  704. /* Interrupter Target - which MSI-X vector to target the completion event at */
  705. #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
  706. #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
  707. /* Cycle bit - indicates TRB ownership by HC or HCD */
  708. #define TRB_CYCLE (1<<0)
  709. /*
  710. * Force next event data TRB to be evaluated before task switch.
  711. * Used to pass OS data back after a TD completes.
  712. */
  713. #define TRB_ENT (1<<1)
  714. /* Interrupt on short packet */
  715. #define TRB_ISP (1<<2)
  716. /* Set PCIe no snoop attribute */
  717. #define TRB_NO_SNOOP (1<<3)
  718. /* Chain multiple TRBs into a TD */
  719. #define TRB_CHAIN (1<<4)
  720. /* Interrupt on completion */
  721. #define TRB_IOC (1<<5)
  722. /* The buffer pointer contains immediate data */
  723. #define TRB_IDT (1<<6)
  724. /* Control transfer TRB specific fields */
  725. #define TRB_DIR_IN (1<<16)
  726. struct xhci_generic_trb {
  727. u32 field[4];
  728. } __attribute__ ((packed));
  729. union xhci_trb {
  730. struct xhci_link_trb link;
  731. struct xhci_transfer_event trans_event;
  732. struct xhci_event_cmd event_cmd;
  733. struct xhci_generic_trb generic;
  734. };
  735. /* TRB bit mask */
  736. #define TRB_TYPE_BITMASK (0xfc00)
  737. #define TRB_TYPE(p) ((p) << 10)
  738. /* TRB type IDs */
  739. /* bulk, interrupt, isoc scatter/gather, and control data stage */
  740. #define TRB_NORMAL 1
  741. /* setup stage for control transfers */
  742. #define TRB_SETUP 2
  743. /* data stage for control transfers */
  744. #define TRB_DATA 3
  745. /* status stage for control transfers */
  746. #define TRB_STATUS 4
  747. /* isoc transfers */
  748. #define TRB_ISOC 5
  749. /* TRB for linking ring segments */
  750. #define TRB_LINK 6
  751. #define TRB_EVENT_DATA 7
  752. /* Transfer Ring No-op (not for the command ring) */
  753. #define TRB_TR_NOOP 8
  754. /* Command TRBs */
  755. /* Enable Slot Command */
  756. #define TRB_ENABLE_SLOT 9
  757. /* Disable Slot Command */
  758. #define TRB_DISABLE_SLOT 10
  759. /* Address Device Command */
  760. #define TRB_ADDR_DEV 11
  761. /* Configure Endpoint Command */
  762. #define TRB_CONFIG_EP 12
  763. /* Evaluate Context Command */
  764. #define TRB_EVAL_CONTEXT 13
  765. /* Reset Transfer Ring Command */
  766. #define TRB_RESET_RING 14
  767. /* Stop Transfer Ring Command */
  768. #define TRB_STOP_RING 15
  769. /* Set Transfer Ring Dequeue Pointer Command */
  770. #define TRB_SET_DEQ 16
  771. /* Reset Device Command */
  772. #define TRB_RESET_DEV 17
  773. /* Force Event Command (opt) */
  774. #define TRB_FORCE_EVENT 18
  775. /* Negotiate Bandwidth Command (opt) */
  776. #define TRB_NEG_BANDWIDTH 19
  777. /* Set Latency Tolerance Value Command (opt) */
  778. #define TRB_SET_LT 20
  779. /* Get port bandwidth Command */
  780. #define TRB_GET_BW 21
  781. /* Force Header Command - generate a transaction or link management packet */
  782. #define TRB_FORCE_HEADER 22
  783. /* No-op Command - not for transfer rings */
  784. #define TRB_CMD_NOOP 23
  785. /* TRB IDs 24-31 reserved */
  786. /* Event TRBS */
  787. /* Transfer Event */
  788. #define TRB_TRANSFER 32
  789. /* Command Completion Event */
  790. #define TRB_COMPLETION 33
  791. /* Port Status Change Event */
  792. #define TRB_PORT_STATUS 34
  793. /* Bandwidth Request Event (opt) */
  794. #define TRB_BANDWIDTH_EVENT 35
  795. /* Doorbell Event (opt) */
  796. #define TRB_DOORBELL 36
  797. /* Host Controller Event */
  798. #define TRB_HC_EVENT 37
  799. /* Device Notification Event - device sent function wake notification */
  800. #define TRB_DEV_NOTE 38
  801. /* MFINDEX Wrap Event - microframe counter wrapped */
  802. #define TRB_MFINDEX_WRAP 39
  803. /* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
  804. /*
  805. * TRBS_PER_SEGMENT must be a multiple of 4,
  806. * since the command ring is 64-byte aligned.
  807. * It must also be greater than 16.
  808. */
  809. #define TRBS_PER_SEGMENT 64
  810. #define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
  811. struct xhci_segment {
  812. union xhci_trb *trbs;
  813. /* private to HCD */
  814. struct xhci_segment *next;
  815. dma_addr_t dma;
  816. } __attribute__ ((packed));
  817. struct xhci_ring {
  818. struct xhci_segment *first_seg;
  819. union xhci_trb *enqueue;
  820. struct xhci_segment *enq_seg;
  821. unsigned int enq_updates;
  822. union xhci_trb *dequeue;
  823. struct xhci_segment *deq_seg;
  824. unsigned int deq_updates;
  825. /*
  826. * Write the cycle state into the TRB cycle field to give ownership of
  827. * the TRB to the host controller (if we are the producer), or to check
  828. * if we own the TRB (if we are the consumer). See section 4.9.1.
  829. */
  830. u32 cycle_state;
  831. };
  832. struct xhci_erst_entry {
  833. /* 64-bit event ring segment address */
  834. u32 seg_addr[2];
  835. u32 seg_size;
  836. /* Set to zero */
  837. u32 rsvd;
  838. } __attribute__ ((packed));
  839. struct xhci_erst {
  840. struct xhci_erst_entry *entries;
  841. unsigned int num_entries;
  842. /* xhci->event_ring keeps track of segment dma addresses */
  843. dma_addr_t erst_dma_addr;
  844. /* Num entries the ERST can contain */
  845. unsigned int erst_size;
  846. };
  847. /*
  848. * Each segment table entry is 4*32bits long. 1K seems like an ok size:
  849. * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
  850. * meaning 64 ring segments.
  851. * Initial allocated size of the ERST, in number of entries */
  852. #define ERST_NUM_SEGS 1
  853. /* Initial allocated size of the ERST, in number of entries */
  854. #define ERST_SIZE 64
  855. /* Initial number of event segment rings allocated */
  856. #define ERST_ENTRIES 1
  857. /* Poll every 60 seconds */
  858. #define POLL_TIMEOUT 60
  859. /* XXX: Make these module parameters */
  860. /* There is one ehci_hci structure per controller */
  861. struct xhci_hcd {
  862. /* glue to PCI and HCD framework */
  863. struct xhci_cap_regs __iomem *cap_regs;
  864. struct xhci_op_regs __iomem *op_regs;
  865. struct xhci_run_regs __iomem *run_regs;
  866. struct xhci_doorbell_array __iomem *dba;
  867. /* Our HCD's current interrupter register set */
  868. struct intr_reg __iomem *ir_set;
  869. /* Cached register copies of read-only HC data */
  870. __u32 hcs_params1;
  871. __u32 hcs_params2;
  872. __u32 hcs_params3;
  873. __u32 hcc_params;
  874. spinlock_t lock;
  875. /* packed release number */
  876. u8 sbrn;
  877. u16 hci_version;
  878. u8 max_slots;
  879. u8 max_interrupters;
  880. u8 max_ports;
  881. u8 isoc_threshold;
  882. int event_ring_max;
  883. int addr_64;
  884. /* 4KB min, 128MB max */
  885. int page_size;
  886. /* Valid values are 12 to 20, inclusive */
  887. int page_shift;
  888. /* only one MSI vector for now, but might need more later */
  889. int msix_count;
  890. struct msix_entry *msix_entries;
  891. /* data structures */
  892. struct xhci_device_context_array *dcbaa;
  893. struct xhci_ring *cmd_ring;
  894. struct xhci_ring *event_ring;
  895. struct xhci_erst erst;
  896. /* slot enabling and address device helpers */
  897. struct completion addr_dev;
  898. int slot_id;
  899. /* Internal mirror of the HW's dcbaa */
  900. struct xhci_virt_device *devs[MAX_HC_SLOTS];
  901. /* DMA pools */
  902. struct dma_pool *device_pool;
  903. struct dma_pool *segment_pool;
  904. #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
  905. /* Poll the rings - for debugging */
  906. struct timer_list event_ring_timer;
  907. int zombie;
  908. #endif
  909. /* Statistics */
  910. int noops_submitted;
  911. int noops_handled;
  912. int error_bitmask;
  913. };
  914. /* For testing purposes */
  915. #define NUM_TEST_NOOPS 0
  916. /* convert between an HCD pointer and the corresponding EHCI_HCD */
  917. static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
  918. {
  919. return (struct xhci_hcd *) (hcd->hcd_priv);
  920. }
  921. static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
  922. {
  923. return container_of((void *) xhci, struct usb_hcd, hcd_priv);
  924. }
  925. #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
  926. #define XHCI_DEBUG 1
  927. #else
  928. #define XHCI_DEBUG 0
  929. #endif
  930. #define xhci_dbg(xhci, fmt, args...) \
  931. do { if (XHCI_DEBUG) dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
  932. #define xhci_info(xhci, fmt, args...) \
  933. do { if (XHCI_DEBUG) dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
  934. #define xhci_err(xhci, fmt, args...) \
  935. dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
  936. #define xhci_warn(xhci, fmt, args...) \
  937. dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
  938. /* TODO: copied from ehci.h - can be refactored? */
  939. /* xHCI spec says all registers are little endian */
  940. static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
  941. __u32 __iomem *regs)
  942. {
  943. return readl(regs);
  944. }
  945. static inline void xhci_writel(const struct xhci_hcd *xhci,
  946. const unsigned int val, __u32 __iomem *regs)
  947. {
  948. if (!in_interrupt())
  949. xhci_dbg(xhci, "`MEM_WRITE_DWORD(3'b000, 32'h%0x, 32'h%0x, 4'hf);\n",
  950. (unsigned int) regs, val);
  951. writel(val, regs);
  952. }
  953. /* xHCI debugging */
  954. void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num);
  955. void xhci_print_registers(struct xhci_hcd *xhci);
  956. void xhci_dbg_regs(struct xhci_hcd *xhci);
  957. void xhci_print_run_regs(struct xhci_hcd *xhci);
  958. void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
  959. void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
  960. void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
  961. void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
  962. void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
  963. void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep);
  964. /* xHCI memory managment */
  965. void xhci_mem_cleanup(struct xhci_hcd *xhci);
  966. int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
  967. void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
  968. int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
  969. int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
  970. #ifdef CONFIG_PCI
  971. /* xHCI PCI glue */
  972. int xhci_register_pci(void);
  973. void xhci_unregister_pci(void);
  974. #endif
  975. /* xHCI host controller glue */
  976. int xhci_halt(struct xhci_hcd *xhci);
  977. int xhci_reset(struct xhci_hcd *xhci);
  978. int xhci_init(struct usb_hcd *hcd);
  979. int xhci_run(struct usb_hcd *hcd);
  980. void xhci_stop(struct usb_hcd *hcd);
  981. void xhci_shutdown(struct usb_hcd *hcd);
  982. int xhci_get_frame(struct usb_hcd *hcd);
  983. irqreturn_t xhci_irq(struct usb_hcd *hcd);
  984. int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
  985. void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
  986. int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
  987. /* xHCI ring, segment, TRB, and TD functions */
  988. dma_addr_t trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
  989. void ring_cmd_db(struct xhci_hcd *xhci);
  990. void *setup_one_noop(struct xhci_hcd *xhci);
  991. void handle_event(struct xhci_hcd *xhci);
  992. void set_hc_event_deq(struct xhci_hcd *xhci);
  993. int queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
  994. int queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, u32 slot_id);
  995. /* xHCI roothub code */
  996. int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
  997. char *buf, u16 wLength);
  998. int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
  999. #endif /* __LINUX_XHCI_HCD_H */