xhci.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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. };
  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. };
  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 xhci_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 xhci_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. };
  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 xhci_intr_reg ir_set[128];
  403. };
  404. /**
  405. * struct doorbell_array
  406. *
  407. * Section 5.6
  408. */
  409. struct xhci_doorbell_array {
  410. u32 doorbell[256];
  411. };
  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. /* Endpoint Target - bits 0:7 */
  418. #define EPI_TO_DB(p) (((p) + 1) & 0xff)
  419. /**
  420. * struct xhci_slot_ctx
  421. * @dev_info: Route string, device speed, hub info, and last valid endpoint
  422. * @dev_info2: Max exit latency for device number, root hub port number
  423. * @tt_info: tt_info is used to construct split transaction tokens
  424. * @dev_state: slot state and device address
  425. *
  426. * Slot Context - section 6.2.1.1. This assumes the HC uses 32-byte context
  427. * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
  428. * reserved at the end of the slot context for HC internal use.
  429. */
  430. struct xhci_slot_ctx {
  431. u32 dev_info;
  432. u32 dev_info2;
  433. u32 tt_info;
  434. u32 dev_state;
  435. /* offset 0x10 to 0x1f reserved for HC internal use */
  436. u32 reserved[4];
  437. };
  438. /* dev_info bitmasks */
  439. /* Route String - 0:19 */
  440. #define ROUTE_STRING_MASK (0xfffff)
  441. /* Device speed - values defined by PORTSC Device Speed field - 20:23 */
  442. #define DEV_SPEED (0xf << 20)
  443. /* bit 24 reserved */
  444. /* Is this LS/FS device connected through a HS hub? - bit 25 */
  445. #define DEV_MTT (0x1 << 25)
  446. /* Set if the device is a hub - bit 26 */
  447. #define DEV_HUB (0x1 << 26)
  448. /* Index of the last valid endpoint context in this device context - 27:31 */
  449. #define LAST_CTX_MASK (0x1f << 27)
  450. #define LAST_CTX(p) ((p) << 27)
  451. #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 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. #define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
  478. /**
  479. * struct xhci_ep_ctx
  480. * @ep_info: endpoint state, streams, mult, and interval information.
  481. * @ep_info2: information on endpoint type, max packet size, max burst size,
  482. * error count, and whether the HC will force an event for all
  483. * transactions.
  484. * @deq: 64-bit ring dequeue pointer address. If the endpoint only
  485. * defines one stream, this points to the endpoint transfer ring.
  486. * Otherwise, it points to a stream context array, which has a
  487. * ring pointer for each flow.
  488. * @tx_info:
  489. * Average TRB lengths for the endpoint ring and
  490. * max payload within an Endpoint Service Interval Time (ESIT).
  491. *
  492. * Endpoint Context - section 6.2.1.2. This assumes the HC uses 32-byte context
  493. * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
  494. * reserved at the end of the endpoint context for HC internal use.
  495. */
  496. struct xhci_ep_ctx {
  497. u32 ep_info;
  498. u32 ep_info2;
  499. u32 deq[2];
  500. u32 tx_info;
  501. /* offset 0x14 - 0x1f reserved for HC internal use */
  502. u32 reserved[3];
  503. };
  504. /* ep_info bitmasks */
  505. /*
  506. * Endpoint State - bits 0:2
  507. * 0 - disabled
  508. * 1 - running
  509. * 2 - halted due to halt condition - ok to manipulate endpoint ring
  510. * 3 - stopped
  511. * 4 - TRB error
  512. * 5-7 - reserved
  513. */
  514. #define EP_STATE_MASK (0xf)
  515. #define EP_STATE_DISABLED 0
  516. #define EP_STATE_RUNNING 1
  517. #define EP_STATE_HALTED 2
  518. #define EP_STATE_STOPPED 3
  519. #define EP_STATE_ERROR 4
  520. /* Mult - Max number of burtst within an interval, in EP companion desc. */
  521. #define EP_MULT(p) ((p & 0x3) << 8)
  522. /* bits 10:14 are Max Primary Streams */
  523. /* bit 15 is Linear Stream Array */
  524. /* Interval - period between requests to an endpoint - 125u increments. */
  525. #define EP_INTERVAL(p) ((p & 0xff) << 16)
  526. /* ep_info2 bitmasks */
  527. /*
  528. * Force Event - generate transfer events for all TRBs for this endpoint
  529. * This will tell the HC to ignore the IOC and ISP flags (for debugging only).
  530. */
  531. #define FORCE_EVENT (0x1)
  532. #define ERROR_COUNT(p) (((p) & 0x3) << 1)
  533. #define EP_TYPE(p) ((p) << 3)
  534. #define ISOC_OUT_EP 1
  535. #define BULK_OUT_EP 2
  536. #define INT_OUT_EP 3
  537. #define CTRL_EP 4
  538. #define ISOC_IN_EP 5
  539. #define BULK_IN_EP 6
  540. #define INT_IN_EP 7
  541. /* bit 6 reserved */
  542. /* bit 7 is Host Initiate Disable - for disabling stream selection */
  543. #define MAX_BURST(p) (((p)&0xff) << 8)
  544. #define MAX_PACKET(p) (((p)&0xffff) << 16)
  545. /**
  546. * struct xhci_device_control
  547. * Input/Output context; see section 6.2.5.
  548. *
  549. * @drop_context: set the bit of the endpoint context you want to disable
  550. * @add_context: set the bit of the endpoint context you want to enable
  551. */
  552. struct xhci_device_control {
  553. u32 drop_flags;
  554. u32 add_flags;
  555. u32 rsvd[6];
  556. struct xhci_slot_ctx slot;
  557. struct xhci_ep_ctx ep[31];
  558. };
  559. /* drop context bitmasks */
  560. #define DROP_EP(x) (0x1 << x)
  561. /* add context bitmasks */
  562. #define ADD_EP(x) (0x1 << x)
  563. struct xhci_virt_device {
  564. /*
  565. * Commands to the hardware are passed an "input context" that
  566. * tells the hardware what to change in its data structures.
  567. * The hardware will return changes in an "output context" that
  568. * software must allocate for the hardware. We need to keep
  569. * track of input and output contexts separately because
  570. * these commands might fail and we don't trust the hardware.
  571. */
  572. struct xhci_device_control *out_ctx;
  573. dma_addr_t out_ctx_dma;
  574. /* Used for addressing devices and configuration changes */
  575. struct xhci_device_control *in_ctx;
  576. dma_addr_t in_ctx_dma;
  577. /* FIXME when stream support is added */
  578. struct xhci_ring *ep_rings[31];
  579. /* Temporary storage in case the configure endpoint command fails and we
  580. * have to restore the device state to the previous state
  581. */
  582. struct xhci_ring *new_ep_rings[31];
  583. struct completion cmd_completion;
  584. /* Status of the last command issued for this device */
  585. u32 cmd_status;
  586. };
  587. /**
  588. * struct xhci_device_context_array
  589. * @dev_context_ptr array of 64-bit DMA addresses for device contexts
  590. */
  591. struct xhci_device_context_array {
  592. /* 64-bit device addresses; we only write 32-bit addresses */
  593. u32 dev_context_ptrs[2*MAX_HC_SLOTS];
  594. /* private xHCD pointers */
  595. dma_addr_t dma;
  596. };
  597. /* TODO: write function to set the 64-bit device DMA address */
  598. /*
  599. * TODO: change this to be dynamically sized at HC mem init time since the HC
  600. * might not be able to handle the maximum number of devices possible.
  601. */
  602. struct xhci_stream_ctx {
  603. /* 64-bit stream ring address, cycle state, and stream type */
  604. u32 stream_ring[2];
  605. /* offset 0x14 - 0x1f reserved for HC internal use */
  606. u32 reserved[2];
  607. };
  608. struct xhci_transfer_event {
  609. /* 64-bit buffer address, or immediate data */
  610. u32 buffer[2];
  611. u32 transfer_len;
  612. /* This field is interpreted differently based on the type of TRB */
  613. u32 flags;
  614. };
  615. /** Transfer Event bit fields **/
  616. #define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
  617. /* Completion Code - only applicable for some types of TRBs */
  618. #define COMP_CODE_MASK (0xff << 24)
  619. #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
  620. #define COMP_SUCCESS 1
  621. /* Data Buffer Error */
  622. #define COMP_DB_ERR 2
  623. /* Babble Detected Error */
  624. #define COMP_BABBLE 3
  625. /* USB Transaction Error */
  626. #define COMP_TX_ERR 4
  627. /* TRB Error - some TRB field is invalid */
  628. #define COMP_TRB_ERR 5
  629. /* Stall Error - USB device is stalled */
  630. #define COMP_STALL 6
  631. /* Resource Error - HC doesn't have memory for that device configuration */
  632. #define COMP_ENOMEM 7
  633. /* Bandwidth Error - not enough room in schedule for this dev config */
  634. #define COMP_BW_ERR 8
  635. /* No Slots Available Error - HC ran out of device slots */
  636. #define COMP_ENOSLOTS 9
  637. /* Invalid Stream Type Error */
  638. #define COMP_STREAM_ERR 10
  639. /* Slot Not Enabled Error - doorbell rung for disabled device slot */
  640. #define COMP_EBADSLT 11
  641. /* Endpoint Not Enabled Error */
  642. #define COMP_EBADEP 12
  643. /* Short Packet */
  644. #define COMP_SHORT_TX 13
  645. /* Ring Underrun - doorbell rung for an empty isoc OUT ep ring */
  646. #define COMP_UNDERRUN 14
  647. /* Ring Overrun - isoc IN ep ring is empty when ep is scheduled to RX */
  648. #define COMP_OVERRUN 15
  649. /* Virtual Function Event Ring Full Error */
  650. #define COMP_VF_FULL 16
  651. /* Parameter Error - Context parameter is invalid */
  652. #define COMP_EINVAL 17
  653. /* Bandwidth Overrun Error - isoc ep exceeded its allocated bandwidth */
  654. #define COMP_BW_OVER 18
  655. /* Context State Error - illegal context state transition requested */
  656. #define COMP_CTX_STATE 19
  657. /* No Ping Response Error - HC didn't get PING_RESPONSE in time to TX */
  658. #define COMP_PING_ERR 20
  659. /* Event Ring is full */
  660. #define COMP_ER_FULL 21
  661. /* Missed Service Error - HC couldn't service an isoc ep within interval */
  662. #define COMP_MISSED_INT 23
  663. /* Successfully stopped command ring */
  664. #define COMP_CMD_STOP 24
  665. /* Successfully aborted current command and stopped command ring */
  666. #define COMP_CMD_ABORT 25
  667. /* Stopped - transfer was terminated by a stop endpoint command */
  668. #define COMP_STOP 26
  669. /* Same as COMP_EP_STOPPED, but the transfered length in the event is invalid */
  670. #define COMP_STOP_INVAL 27
  671. /* Control Abort Error - Debug Capability - control pipe aborted */
  672. #define COMP_DBG_ABORT 28
  673. /* TRB type 29 and 30 reserved */
  674. /* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
  675. #define COMP_BUFF_OVER 31
  676. /* Event Lost Error - xHC has an "internal event overrun condition" */
  677. #define COMP_ISSUES 32
  678. /* Undefined Error - reported when other error codes don't apply */
  679. #define COMP_UNKNOWN 33
  680. /* Invalid Stream ID Error */
  681. #define COMP_STRID_ERR 34
  682. /* Secondary Bandwidth Error - may be returned by a Configure Endpoint cmd */
  683. /* FIXME - check for this */
  684. #define COMP_2ND_BW_ERR 35
  685. /* Split Transaction Error */
  686. #define COMP_SPLIT_ERR 36
  687. struct xhci_link_trb {
  688. /* 64-bit segment pointer*/
  689. u32 segment_ptr[2];
  690. u32 intr_target;
  691. u32 control;
  692. };
  693. /* control bitfields */
  694. #define LINK_TOGGLE (0x1<<1)
  695. /* Command completion event TRB */
  696. struct xhci_event_cmd {
  697. /* Pointer to command TRB, or the value passed by the event data trb */
  698. u32 cmd_trb[2];
  699. u32 status;
  700. u32 flags;
  701. };
  702. /* flags bitmasks */
  703. /* bits 16:23 are the virtual function ID */
  704. /* bits 24:31 are the slot ID */
  705. #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
  706. #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
  707. /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
  708. #define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
  709. #define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
  710. /* Port Status Change Event TRB fields */
  711. /* Port ID - bits 31:24 */
  712. #define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
  713. /* Normal TRB fields */
  714. /* transfer_len bitmasks - bits 0:16 */
  715. #define TRB_LEN(p) ((p) & 0x1ffff)
  716. /* TD size - number of bytes remaining in the TD (including this TRB):
  717. * bits 17 - 21. Shift the number of bytes by 10. */
  718. #define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
  719. /* Interrupter Target - which MSI-X vector to target the completion event at */
  720. #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
  721. #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
  722. /* Cycle bit - indicates TRB ownership by HC or HCD */
  723. #define TRB_CYCLE (1<<0)
  724. /*
  725. * Force next event data TRB to be evaluated before task switch.
  726. * Used to pass OS data back after a TD completes.
  727. */
  728. #define TRB_ENT (1<<1)
  729. /* Interrupt on short packet */
  730. #define TRB_ISP (1<<2)
  731. /* Set PCIe no snoop attribute */
  732. #define TRB_NO_SNOOP (1<<3)
  733. /* Chain multiple TRBs into a TD */
  734. #define TRB_CHAIN (1<<4)
  735. /* Interrupt on completion */
  736. #define TRB_IOC (1<<5)
  737. /* The buffer pointer contains immediate data */
  738. #define TRB_IDT (1<<6)
  739. /* Control transfer TRB specific fields */
  740. #define TRB_DIR_IN (1<<16)
  741. struct xhci_generic_trb {
  742. u32 field[4];
  743. };
  744. union xhci_trb {
  745. struct xhci_link_trb link;
  746. struct xhci_transfer_event trans_event;
  747. struct xhci_event_cmd event_cmd;
  748. struct xhci_generic_trb generic;
  749. };
  750. /* TRB bit mask */
  751. #define TRB_TYPE_BITMASK (0xfc00)
  752. #define TRB_TYPE(p) ((p) << 10)
  753. /* TRB type IDs */
  754. /* bulk, interrupt, isoc scatter/gather, and control data stage */
  755. #define TRB_NORMAL 1
  756. /* setup stage for control transfers */
  757. #define TRB_SETUP 2
  758. /* data stage for control transfers */
  759. #define TRB_DATA 3
  760. /* status stage for control transfers */
  761. #define TRB_STATUS 4
  762. /* isoc transfers */
  763. #define TRB_ISOC 5
  764. /* TRB for linking ring segments */
  765. #define TRB_LINK 6
  766. #define TRB_EVENT_DATA 7
  767. /* Transfer Ring No-op (not for the command ring) */
  768. #define TRB_TR_NOOP 8
  769. /* Command TRBs */
  770. /* Enable Slot Command */
  771. #define TRB_ENABLE_SLOT 9
  772. /* Disable Slot Command */
  773. #define TRB_DISABLE_SLOT 10
  774. /* Address Device Command */
  775. #define TRB_ADDR_DEV 11
  776. /* Configure Endpoint Command */
  777. #define TRB_CONFIG_EP 12
  778. /* Evaluate Context Command */
  779. #define TRB_EVAL_CONTEXT 13
  780. /* Reset Transfer Ring Command */
  781. #define TRB_RESET_RING 14
  782. /* Stop Transfer Ring Command */
  783. #define TRB_STOP_RING 15
  784. /* Set Transfer Ring Dequeue Pointer Command */
  785. #define TRB_SET_DEQ 16
  786. /* Reset Device Command */
  787. #define TRB_RESET_DEV 17
  788. /* Force Event Command (opt) */
  789. #define TRB_FORCE_EVENT 18
  790. /* Negotiate Bandwidth Command (opt) */
  791. #define TRB_NEG_BANDWIDTH 19
  792. /* Set Latency Tolerance Value Command (opt) */
  793. #define TRB_SET_LT 20
  794. /* Get port bandwidth Command */
  795. #define TRB_GET_BW 21
  796. /* Force Header Command - generate a transaction or link management packet */
  797. #define TRB_FORCE_HEADER 22
  798. /* No-op Command - not for transfer rings */
  799. #define TRB_CMD_NOOP 23
  800. /* TRB IDs 24-31 reserved */
  801. /* Event TRBS */
  802. /* Transfer Event */
  803. #define TRB_TRANSFER 32
  804. /* Command Completion Event */
  805. #define TRB_COMPLETION 33
  806. /* Port Status Change Event */
  807. #define TRB_PORT_STATUS 34
  808. /* Bandwidth Request Event (opt) */
  809. #define TRB_BANDWIDTH_EVENT 35
  810. /* Doorbell Event (opt) */
  811. #define TRB_DOORBELL 36
  812. /* Host Controller Event */
  813. #define TRB_HC_EVENT 37
  814. /* Device Notification Event - device sent function wake notification */
  815. #define TRB_DEV_NOTE 38
  816. /* MFINDEX Wrap Event - microframe counter wrapped */
  817. #define TRB_MFINDEX_WRAP 39
  818. /* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
  819. /*
  820. * TRBS_PER_SEGMENT must be a multiple of 4,
  821. * since the command ring is 64-byte aligned.
  822. * It must also be greater than 16.
  823. */
  824. #define TRBS_PER_SEGMENT 64
  825. #define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
  826. /* TRB buffer pointers can't cross 64KB boundaries */
  827. #define TRB_MAX_BUFF_SHIFT 16
  828. #define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
  829. struct xhci_segment {
  830. union xhci_trb *trbs;
  831. /* private to HCD */
  832. struct xhci_segment *next;
  833. dma_addr_t dma;
  834. };
  835. struct xhci_td {
  836. struct list_head td_list;
  837. struct list_head cancelled_td_list;
  838. struct urb *urb;
  839. struct xhci_segment *start_seg;
  840. union xhci_trb *first_trb;
  841. union xhci_trb *last_trb;
  842. };
  843. struct xhci_ring {
  844. struct xhci_segment *first_seg;
  845. union xhci_trb *enqueue;
  846. struct xhci_segment *enq_seg;
  847. unsigned int enq_updates;
  848. union xhci_trb *dequeue;
  849. struct xhci_segment *deq_seg;
  850. unsigned int deq_updates;
  851. struct list_head td_list;
  852. /* ---- Related to URB cancellation ---- */
  853. struct list_head cancelled_td_list;
  854. unsigned int cancels_pending;
  855. unsigned int state;
  856. #define SET_DEQ_PENDING (1 << 0)
  857. /* The TRB that was last reported in a stopped endpoint ring */
  858. union xhci_trb *stopped_trb;
  859. struct xhci_td *stopped_td;
  860. /*
  861. * Write the cycle state into the TRB cycle field to give ownership of
  862. * the TRB to the host controller (if we are the producer), or to check
  863. * if we own the TRB (if we are the consumer). See section 4.9.1.
  864. */
  865. u32 cycle_state;
  866. };
  867. struct xhci_erst_entry {
  868. /* 64-bit event ring segment address */
  869. u32 seg_addr[2];
  870. u32 seg_size;
  871. /* Set to zero */
  872. u32 rsvd;
  873. };
  874. struct xhci_erst {
  875. struct xhci_erst_entry *entries;
  876. unsigned int num_entries;
  877. /* xhci->event_ring keeps track of segment dma addresses */
  878. dma_addr_t erst_dma_addr;
  879. /* Num entries the ERST can contain */
  880. unsigned int erst_size;
  881. };
  882. /*
  883. * Each segment table entry is 4*32bits long. 1K seems like an ok size:
  884. * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
  885. * meaning 64 ring segments.
  886. * Initial allocated size of the ERST, in number of entries */
  887. #define ERST_NUM_SEGS 1
  888. /* Initial allocated size of the ERST, in number of entries */
  889. #define ERST_SIZE 64
  890. /* Initial number of event segment rings allocated */
  891. #define ERST_ENTRIES 1
  892. /* Poll every 60 seconds */
  893. #define POLL_TIMEOUT 60
  894. /* XXX: Make these module parameters */
  895. /* There is one ehci_hci structure per controller */
  896. struct xhci_hcd {
  897. /* glue to PCI and HCD framework */
  898. struct xhci_cap_regs __iomem *cap_regs;
  899. struct xhci_op_regs __iomem *op_regs;
  900. struct xhci_run_regs __iomem *run_regs;
  901. struct xhci_doorbell_array __iomem *dba;
  902. /* Our HCD's current interrupter register set */
  903. struct xhci_intr_reg __iomem *ir_set;
  904. /* Cached register copies of read-only HC data */
  905. __u32 hcs_params1;
  906. __u32 hcs_params2;
  907. __u32 hcs_params3;
  908. __u32 hcc_params;
  909. spinlock_t lock;
  910. /* packed release number */
  911. u8 sbrn;
  912. u16 hci_version;
  913. u8 max_slots;
  914. u8 max_interrupters;
  915. u8 max_ports;
  916. u8 isoc_threshold;
  917. int event_ring_max;
  918. int addr_64;
  919. /* 4KB min, 128MB max */
  920. int page_size;
  921. /* Valid values are 12 to 20, inclusive */
  922. int page_shift;
  923. /* only one MSI vector for now, but might need more later */
  924. int msix_count;
  925. struct msix_entry *msix_entries;
  926. /* data structures */
  927. struct xhci_device_context_array *dcbaa;
  928. struct xhci_ring *cmd_ring;
  929. struct xhci_ring *event_ring;
  930. struct xhci_erst erst;
  931. /* slot enabling and address device helpers */
  932. struct completion addr_dev;
  933. int slot_id;
  934. /* Internal mirror of the HW's dcbaa */
  935. struct xhci_virt_device *devs[MAX_HC_SLOTS];
  936. /* DMA pools */
  937. struct dma_pool *device_pool;
  938. struct dma_pool *segment_pool;
  939. #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
  940. /* Poll the rings - for debugging */
  941. struct timer_list event_ring_timer;
  942. int zombie;
  943. #endif
  944. /* Statistics */
  945. int noops_submitted;
  946. int noops_handled;
  947. int error_bitmask;
  948. };
  949. /* For testing purposes */
  950. #define NUM_TEST_NOOPS 0
  951. /* convert between an HCD pointer and the corresponding EHCI_HCD */
  952. static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
  953. {
  954. return (struct xhci_hcd *) (hcd->hcd_priv);
  955. }
  956. static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
  957. {
  958. return container_of((void *) xhci, struct usb_hcd, hcd_priv);
  959. }
  960. #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
  961. #define XHCI_DEBUG 1
  962. #else
  963. #define XHCI_DEBUG 0
  964. #endif
  965. #define xhci_dbg(xhci, fmt, args...) \
  966. do { if (XHCI_DEBUG) dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
  967. #define xhci_info(xhci, fmt, args...) \
  968. do { if (XHCI_DEBUG) dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
  969. #define xhci_err(xhci, fmt, args...) \
  970. dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
  971. #define xhci_warn(xhci, fmt, args...) \
  972. dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
  973. /* TODO: copied from ehci.h - can be refactored? */
  974. /* xHCI spec says all registers are little endian */
  975. static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
  976. __u32 __iomem *regs)
  977. {
  978. return readl(regs);
  979. }
  980. static inline void xhci_writel(struct xhci_hcd *xhci,
  981. const unsigned int val, __u32 __iomem *regs)
  982. {
  983. if (!in_interrupt())
  984. xhci_dbg(xhci,
  985. "`MEM_WRITE_DWORD(3'b000, 32'h%p, 32'h%0x, 4'hf);\n",
  986. regs, val);
  987. writel(val, regs);
  988. }
  989. /* xHCI debugging */
  990. void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num);
  991. void xhci_print_registers(struct xhci_hcd *xhci);
  992. void xhci_dbg_regs(struct xhci_hcd *xhci);
  993. void xhci_print_run_regs(struct xhci_hcd *xhci);
  994. void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb);
  995. void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb);
  996. void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
  997. void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
  998. void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
  999. void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
  1000. void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
  1001. void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep);
  1002. /* xHCI memory managment */
  1003. void xhci_mem_cleanup(struct xhci_hcd *xhci);
  1004. int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
  1005. void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
  1006. int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
  1007. int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
  1008. unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
  1009. unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
  1010. void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
  1011. int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
  1012. struct usb_device *udev, struct usb_host_endpoint *ep,
  1013. gfp_t mem_flags);
  1014. void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
  1015. #ifdef CONFIG_PCI
  1016. /* xHCI PCI glue */
  1017. int xhci_register_pci(void);
  1018. void xhci_unregister_pci(void);
  1019. #endif
  1020. /* xHCI host controller glue */
  1021. int xhci_halt(struct xhci_hcd *xhci);
  1022. int xhci_reset(struct xhci_hcd *xhci);
  1023. int xhci_init(struct usb_hcd *hcd);
  1024. int xhci_run(struct usb_hcd *hcd);
  1025. void xhci_stop(struct usb_hcd *hcd);
  1026. void xhci_shutdown(struct usb_hcd *hcd);
  1027. int xhci_get_frame(struct usb_hcd *hcd);
  1028. irqreturn_t xhci_irq(struct usb_hcd *hcd);
  1029. int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
  1030. void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
  1031. int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
  1032. int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
  1033. int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
  1034. int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
  1035. int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
  1036. int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  1037. void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
  1038. /* xHCI ring, segment, TRB, and TD functions */
  1039. dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
  1040. void xhci_ring_cmd_db(struct xhci_hcd *xhci);
  1041. void *xhci_setup_one_noop(struct xhci_hcd *xhci);
  1042. void xhci_handle_event(struct xhci_hcd *xhci);
  1043. void xhci_set_hc_event_deq(struct xhci_hcd *xhci);
  1044. int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
  1045. int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
  1046. u32 slot_id);
  1047. int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
  1048. unsigned int ep_index);
  1049. int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
  1050. int slot_id, unsigned int ep_index);
  1051. int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
  1052. int slot_id, unsigned int ep_index);
  1053. int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
  1054. u32 slot_id);
  1055. /* xHCI roothub code */
  1056. int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
  1057. char *buf, u16 wLength);
  1058. int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
  1059. #endif /* __LINUX_XHCI_HCD_H */