cdnsp-gadget.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence CDNSP DRD Driver.
  4. *
  5. * Copyright (C) 2020 Cadence.
  6. *
  7. * Author: Pawel Laszczak <[email protected]>
  8. *
  9. * Code based on Linux XHCI driver.
  10. * Origin: Copyright (C) 2008 Intel Corp.
  11. */
  12. #ifndef __LINUX_CDNSP_GADGET_H
  13. #define __LINUX_CDNSP_GADGET_H
  14. #include <linux/io-64-nonatomic-lo-hi.h>
  15. #include <linux/usb/gadget.h>
  16. #include <linux/irq.h>
  17. /* Max number slots - only 1 is allowed. */
  18. #define CDNSP_DEV_MAX_SLOTS 1
  19. #define CDNSP_EP0_SETUP_SIZE 512
  20. /* One control and 15 for in and 15 for out endpoints. */
  21. #define CDNSP_ENDPOINTS_NUM 31
  22. /* Best Effort Service Latency. */
  23. #define CDNSP_DEFAULT_BESL 0
  24. /* Device Controller command default timeout value in us */
  25. #define CDNSP_CMD_TIMEOUT (15 * 1000)
  26. /* Up to 16 ms to halt an device controller */
  27. #define CDNSP_MAX_HALT_USEC (16 * 1000)
  28. #define CDNSP_CTX_SIZE 2112
  29. /*
  30. * Controller register interface.
  31. */
  32. /**
  33. * struct cdnsp_cap_regs - CDNSP Registers.
  34. * @hc_capbase: Length of the capabilities register and controller
  35. * version number
  36. * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
  37. * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
  38. * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
  39. * @hcc_params: HCCPARAMS - Capability Parameters
  40. * @db_off: DBOFF - Doorbell array offset
  41. * @run_regs_off: RTSOFF - Runtime register space offset
  42. * @hcc_params2: HCCPARAMS2 Capability Parameters 2,
  43. */
  44. struct cdnsp_cap_regs {
  45. __le32 hc_capbase;
  46. __le32 hcs_params1;
  47. __le32 hcs_params2;
  48. __le32 hcs_params3;
  49. __le32 hcc_params;
  50. __le32 db_off;
  51. __le32 run_regs_off;
  52. __le32 hcc_params2;
  53. /* Reserved up to (CAPLENGTH - 0x1C) */
  54. };
  55. /* hc_capbase bitmasks. */
  56. /* bits 7:0 - how long is the Capabilities register. */
  57. #define HC_LENGTH(p) (((p) >> 00) & GENMASK(7, 0))
  58. /* bits 31:16 */
  59. #define HC_VERSION(p) (((p) >> 16) & GENMASK(15, 1))
  60. /* HCSPARAMS1 - hcs_params1 - bitmasks */
  61. /* bits 0:7, Max Device Endpoints */
  62. #define HCS_ENDPOINTS_MASK GENMASK(7, 0)
  63. #define HCS_ENDPOINTS(p) (((p) & HCS_ENDPOINTS_MASK) >> 0)
  64. /* HCCPARAMS offset from PCI base address */
  65. #define HCC_PARAMS_OFFSET 0x10
  66. /* HCCPARAMS - hcc_params - bitmasks */
  67. /* 1: device controller can use 64-bit address pointers. */
  68. #define HCC_64BIT_ADDR(p) ((p) & BIT(0))
  69. /* 1: device controller uses 64-byte Device Context structures. */
  70. #define HCC_64BYTE_CONTEXT(p) ((p) & BIT(2))
  71. /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */
  72. #define HCC_MAX_PSA(p) ((((p) >> 12) & 0xf) + 1)
  73. /* Extended Capabilities pointer from PCI base. */
  74. #define HCC_EXT_CAPS(p) (((p) & GENMASK(31, 16)) >> 16)
  75. #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
  76. /* db_off bitmask - bits 0:1 reserved. */
  77. #define DBOFF_MASK GENMASK(31, 2)
  78. /* run_regs_off bitmask - bits 0:4 reserved. */
  79. #define RTSOFF_MASK GENMASK(31, 5)
  80. /**
  81. * struct cdnsp_op_regs - Device Controller Operational Registers.
  82. * @command: USBCMD - Controller command register.
  83. * @status: USBSTS - Controller status register.
  84. * @page_size: This indicates the page size that the device controller supports.
  85. * If bit n is set, the controller supports a page size of 2^(n+12),
  86. * up to a 128MB page size. 4K is the minimum page size.
  87. * @dnctrl: DNCTRL - Device notification control register.
  88. * @cmd_ring: CRP - 64-bit Command Ring Pointer.
  89. * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer.
  90. * @config_reg: CONFIG - Configure Register
  91. * @port_reg_base: PORTSCn - base address for Port Status and Control
  92. * Each port has a Port Status and Control register,
  93. * followed by a Port Power Management Status and Control
  94. * register, a Port Link Info register, and a reserved
  95. * register.
  96. */
  97. struct cdnsp_op_regs {
  98. __le32 command;
  99. __le32 status;
  100. __le32 page_size;
  101. __le32 reserved1;
  102. __le32 reserved2;
  103. __le32 dnctrl;
  104. __le64 cmd_ring;
  105. /* rsvd: offset 0x20-2F. */
  106. __le32 reserved3[4];
  107. __le64 dcbaa_ptr;
  108. __le32 config_reg;
  109. /* rsvd: offset 0x3C-3FF. */
  110. __le32 reserved4[241];
  111. /* port 1 registers, which serve as a base address for other ports. */
  112. __le32 port_reg_base;
  113. };
  114. /* Number of registers per port. */
  115. #define NUM_PORT_REGS 4
  116. /**
  117. * struct cdnsp_port_regs - Port Registers.
  118. * @portsc: PORTSC - Port Status and Control Register.
  119. * @portpmsc: PORTPMSC - Port Power Managements Status and Control Register.
  120. * @portli: PORTLI - Port Link Info register.
  121. */
  122. struct cdnsp_port_regs {
  123. __le32 portsc;
  124. __le32 portpmsc;
  125. __le32 portli;
  126. __le32 reserved;
  127. };
  128. /*
  129. * These bits are Read Only (RO) and should be saved and written to the
  130. * registers: 0 (connect status) and 10:13 (port speed).
  131. * These bits are also sticky - meaning they're in the AUX well and they aren't
  132. * changed by a hot and warm.
  133. */
  134. #define CDNSP_PORT_RO (PORT_CONNECT | DEV_SPEED_MASK)
  135. /*
  136. * These bits are RW; writing a 0 clears the bit, writing a 1 sets the bit:
  137. * bits 5:8 (link state), 25:26 ("wake on" enable state)
  138. */
  139. #define CDNSP_PORT_RWS (PORT_PLS_MASK | PORT_WKCONN_E | PORT_WKDISC_E)
  140. /*
  141. * These bits are RW; writing a 1 clears the bit, writing a 0 has no effect:
  142. * bits 1 (port enable/disable), 17 ( connect changed),
  143. * 21 (port reset changed) , 22 (Port Link State Change),
  144. */
  145. #define CDNSP_PORT_RW1CS (PORT_PED | PORT_CSC | PORT_RC | PORT_PLC)
  146. /* USBCMD - USB command - bitmasks. */
  147. /* Run/Stop, controller execution - do not write unless controller is halted.*/
  148. #define CMD_R_S BIT(0)
  149. /*
  150. * Reset device controller - resets internal controller state machine and all
  151. * registers (except PCI config regs).
  152. */
  153. #define CMD_RESET BIT(1)
  154. /* Event Interrupt Enable - a '1' allows interrupts from the controller. */
  155. #define CMD_INTE BIT(2)
  156. /*
  157. * Device System Error Interrupt Enable - get out-of-band signal for
  158. * controller errors.
  159. */
  160. #define CMD_DSEIE BIT(3)
  161. /* device controller save/restore state. */
  162. #define CMD_CSS BIT(8)
  163. #define CMD_CRS BIT(9)
  164. /*
  165. * Enable Wrap Event - '1' means device controller generates an event
  166. * when MFINDEX wraps.
  167. */
  168. #define CMD_EWE BIT(10)
  169. /* 1: device enabled */
  170. #define CMD_DEVEN BIT(17)
  171. /* bits 18:31 are reserved (and should be preserved on writes). */
  172. /* Command register values to disable interrupts. */
  173. #define CDNSP_IRQS (CMD_INTE | CMD_DSEIE | CMD_EWE)
  174. /* USBSTS - USB status - bitmasks */
  175. /* controller not running - set to 1 when run/stop bit is cleared. */
  176. #define STS_HALT BIT(0)
  177. /*
  178. * serious error, e.g. PCI parity error. The controller will clear
  179. * the run/stop bit.
  180. */
  181. #define STS_FATAL BIT(2)
  182. /* event interrupt - clear this prior to clearing any IP flags in IR set.*/
  183. #define STS_EINT BIT(3)
  184. /* port change detect */
  185. #define STS_PCD BIT(4)
  186. /* save state status - '1' means device controller is saving state. */
  187. #define STS_SSS BIT(8)
  188. /* restore state status - '1' means controllers is restoring state. */
  189. #define STS_RSS BIT(9)
  190. /* 1: save or restore error */
  191. #define STS_SRE BIT(10)
  192. /* 1: device Not Ready to accept doorbell or op reg writes after reset. */
  193. #define STS_CNR BIT(11)
  194. /* 1: internal Device Controller Error.*/
  195. #define STS_HCE BIT(12)
  196. /* CRCR - Command Ring Control Register - cmd_ring bitmasks. */
  197. /* bit 0 is the command ring cycle state. */
  198. #define CMD_RING_CS BIT(0)
  199. /* stop ring immediately - abort the currently executing command. */
  200. #define CMD_RING_ABORT BIT(2)
  201. /*
  202. * Command Ring Busy.
  203. * Set when Doorbell register is written with DB for command and cleared when
  204. * the controller reached end of CR.
  205. */
  206. #define CMD_RING_BUSY(p) ((p) & BIT(4))
  207. /* 1: command ring is running */
  208. #define CMD_RING_RUNNING BIT(3)
  209. /* Command Ring pointer - bit mask for the lower 32 bits. */
  210. #define CMD_RING_RSVD_BITS GENMASK(5, 0)
  211. /* CONFIG - Configure Register - config_reg bitmasks. */
  212. /* bits 0:7 - maximum number of device slots enabled. */
  213. #define MAX_DEVS GENMASK(7, 0)
  214. /* bit 8: U3 Entry Enabled, assert PLC when controller enters U3. */
  215. #define CONFIG_U3E BIT(8)
  216. /* PORTSC - Port Status and Control Register - port_reg_base bitmasks */
  217. /* 1: device connected. */
  218. #define PORT_CONNECT BIT(0)
  219. /* 1: port enabled. */
  220. #define PORT_PED BIT(1)
  221. /* 1: port reset signaling asserted. */
  222. #define PORT_RESET BIT(4)
  223. /*
  224. * Port Link State - bits 5:8
  225. * A read gives the current link PM state of the port,
  226. * a write with Link State Write Strobe sets the link state.
  227. */
  228. #define PORT_PLS_MASK GENMASK(8, 5)
  229. #define XDEV_U0 (0x0 << 5)
  230. #define XDEV_U1 (0x1 << 5)
  231. #define XDEV_U2 (0x2 << 5)
  232. #define XDEV_U3 (0x3 << 5)
  233. #define XDEV_DISABLED (0x4 << 5)
  234. #define XDEV_RXDETECT (0x5 << 5)
  235. #define XDEV_INACTIVE (0x6 << 5)
  236. #define XDEV_POLLING (0x7 << 5)
  237. #define XDEV_RECOVERY (0x8 << 5)
  238. #define XDEV_HOT_RESET (0x9 << 5)
  239. #define XDEV_COMP_MODE (0xa << 5)
  240. #define XDEV_TEST_MODE (0xb << 5)
  241. #define XDEV_RESUME (0xf << 5)
  242. /* 1: port has power. */
  243. #define PORT_POWER BIT(9)
  244. /*
  245. * bits 10:13 indicate device speed:
  246. * 0 - undefined speed - port hasn't be initialized by a reset yet
  247. * 1 - full speed
  248. * 2 - Reserved (Low Speed not supported
  249. * 3 - high speed
  250. * 4 - super speed
  251. * 5 - super speed
  252. * 6-15 reserved
  253. */
  254. #define DEV_SPEED_MASK GENMASK(13, 10)
  255. #define XDEV_FS (0x1 << 10)
  256. #define XDEV_HS (0x3 << 10)
  257. #define XDEV_SS (0x4 << 10)
  258. #define XDEV_SSP (0x5 << 10)
  259. #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0 << 10))
  260. #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
  261. #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
  262. #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
  263. #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP)
  264. #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS)
  265. #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f)
  266. /* Port Link State Write Strobe - set this when changing link state */
  267. #define PORT_LINK_STROBE BIT(16)
  268. /* 1: connect status change */
  269. #define PORT_CSC BIT(17)
  270. /* 1: warm reset for a USB 3.0 device is done. */
  271. #define PORT_WRC BIT(19)
  272. /* 1: reset change - 1 to 0 transition of PORT_RESET */
  273. #define PORT_RC BIT(21)
  274. /*
  275. * port link status change - set on some port link state transitions:
  276. * Transition Reason
  277. * ----------------------------------------------------------------------------
  278. * - U3 to Resume Wakeup signaling from a device
  279. * - Resume to Recovery to U0 USB 3.0 device resume
  280. * - Resume to U0 USB 2.0 device resume
  281. * - U3 to Recovery to U0 Software resume of USB 3.0 device complete
  282. * - U3 to U0 Software resume of USB 2.0 device complete
  283. * - U2 to U0 L1 resume of USB 2.1 device complete
  284. * - U0 to U0 L1 entry rejection by USB 2.1 device
  285. * - U0 to disabled L1 entry error with USB 2.1 device
  286. * - Any state to inactive Error on USB 3.0 port
  287. */
  288. #define PORT_PLC BIT(22)
  289. /* Port configure error change - port failed to configure its link partner. */
  290. #define PORT_CEC BIT(23)
  291. /* Wake on connect (enable). */
  292. #define PORT_WKCONN_E BIT(25)
  293. /* Wake on disconnect (enable). */
  294. #define PORT_WKDISC_E BIT(26)
  295. /* Indicates if Warm Reset is being received. */
  296. #define PORT_WR BIT(31)
  297. #define PORT_CHANGE_BITS (PORT_CSC | PORT_WRC | PORT_RC | PORT_PLC | PORT_CEC)
  298. /* PORTPMSCUSB3 - Port Power Management Status and Control - bitmasks. */
  299. /* Enables U1 entry. */
  300. #define PORT_U1_TIMEOUT_MASK GENMASK(7, 0)
  301. #define PORT_U1_TIMEOUT(p) ((p) & PORT_U1_TIMEOUT_MASK)
  302. /* Enables U2 entry .*/
  303. #define PORT_U2_TIMEOUT_MASK GENMASK(14, 8)
  304. #define PORT_U2_TIMEOUT(p) (((p) << 8) & PORT_U2_TIMEOUT_MASK)
  305. /* PORTPMSCUSB2 - Port Power Management Status and Control - bitmasks. */
  306. #define PORT_L1S_MASK GENMASK(2, 0)
  307. #define PORT_L1S(p) ((p) & PORT_L1S_MASK)
  308. #define PORT_L1S_ACK PORT_L1S(1)
  309. #define PORT_L1S_NYET PORT_L1S(2)
  310. #define PORT_L1S_STALL PORT_L1S(3)
  311. #define PORT_L1S_TIMEOUT PORT_L1S(4)
  312. /* Remote Wake Enable. */
  313. #define PORT_RWE BIT(3)
  314. /* Best Effort Service Latency (BESL). */
  315. #define PORT_BESL(p) (((p) << 4) & GENMASK(7, 4))
  316. /* Hardware LPM Enable (HLE). */
  317. #define PORT_HLE BIT(16)
  318. /* Received Best Effort Service Latency (BESL). */
  319. #define PORT_RRBESL(p) (((p) & GENMASK(20, 17)) >> 17)
  320. /* Port Test Control. */
  321. #define PORT_TEST_MODE_MASK GENMASK(31, 28)
  322. #define PORT_TEST_MODE(p) (((p) << 28) & PORT_TEST_MODE_MASK)
  323. /**
  324. * struct cdnsp_intr_reg - Interrupt Register Set.
  325. * @irq_pending: IMAN - Interrupt Management Register. Used to enable
  326. * interrupts and check for pending interrupts.
  327. * @irq_control: IMOD - Interrupt Moderation Register.
  328. * Used to throttle interrupts.
  329. * @erst_size: Number of segments in the Event Ring Segment Table (ERST).
  330. * @erst_base: ERST base address.
  331. * @erst_dequeue: Event ring dequeue pointer.
  332. *
  333. * Each interrupter (defined by a MSI-X vector) has an event ring and an Event
  334. * Ring Segment Table (ERST) associated with it. The event ring is comprised of
  335. * multiple segments of the same size. The controller places events on the ring
  336. * and "updates the Cycle bit in the TRBs to indicate to software the current
  337. * position of the Enqueue Pointer." The driver processes those events and
  338. * updates the dequeue pointer.
  339. */
  340. struct cdnsp_intr_reg {
  341. __le32 irq_pending;
  342. __le32 irq_control;
  343. __le32 erst_size;
  344. __le32 rsvd;
  345. __le64 erst_base;
  346. __le64 erst_dequeue;
  347. };
  348. /* IMAN - Interrupt Management Register - irq_pending bitmasks l. */
  349. #define IMAN_IE BIT(1)
  350. #define IMAN_IP BIT(0)
  351. /* bits 2:31 need to be preserved */
  352. #define IMAN_IE_SET(p) ((p) | IMAN_IE)
  353. #define IMAN_IE_CLEAR(p) ((p) & ~IMAN_IE)
  354. /* IMOD - Interrupter Moderation Register - irq_control bitmasks. */
  355. /*
  356. * Minimum interval between interrupts (in 250ns intervals). The interval
  357. * between interrupts will be longer if there are no events on the event ring.
  358. * Default is 4000 (1 ms).
  359. */
  360. #define IMOD_INTERVAL_MASK GENMASK(15, 0)
  361. /* Counter used to count down the time to the next interrupt - HW use only */
  362. #define IMOD_COUNTER_MASK GENMASK(31, 16)
  363. #define IMOD_DEFAULT_INTERVAL 0
  364. /* erst_size bitmasks. */
  365. /* Preserve bits 16:31 of erst_size. */
  366. #define ERST_SIZE_MASK GENMASK(31, 16)
  367. /* erst_dequeue bitmasks. */
  368. /*
  369. * Dequeue ERST Segment Index (DESI) - Segment number (or alias)
  370. * where the current dequeue pointer lies. This is an optional HW hint.
  371. */
  372. #define ERST_DESI_MASK GENMASK(2, 0)
  373. /* Event Handler Busy (EHB) - is the event ring scheduled to be serviced. */
  374. #define ERST_EHB BIT(3)
  375. #define ERST_PTR_MASK GENMASK(3, 0)
  376. /**
  377. * struct cdnsp_run_regs
  378. * @microframe_index: MFINDEX - current microframe number.
  379. * @ir_set: Array of Interrupter registers.
  380. *
  381. * Device Controller Runtime Registers:
  382. * "Software should read and write these registers using only Dword (32 bit)
  383. * or larger accesses"
  384. */
  385. struct cdnsp_run_regs {
  386. __le32 microframe_index;
  387. __le32 rsvd[7];
  388. struct cdnsp_intr_reg ir_set[128];
  389. };
  390. /**
  391. * USB2.0 Port Peripheral Configuration Registers.
  392. * @ext_cap: Header register for Extended Capability.
  393. * @port_reg1: Timer Configuration Register.
  394. * @port_reg2: Timer Configuration Register.
  395. * @port_reg3: Timer Configuration Register.
  396. * @port_reg4: Timer Configuration Register.
  397. * @port_reg5: Timer Configuration Register.
  398. * @port_reg6: Chicken bits for USB20PPP.
  399. */
  400. struct cdnsp_20port_cap {
  401. __le32 ext_cap;
  402. __le32 port_reg1;
  403. __le32 port_reg2;
  404. __le32 port_reg3;
  405. __le32 port_reg4;
  406. __le32 port_reg5;
  407. __le32 port_reg6;
  408. };
  409. /* Extended capability register fields */
  410. #define EXT_CAPS_ID(p) (((p) >> 0) & GENMASK(7, 0))
  411. #define EXT_CAPS_NEXT(p) (((p) >> 8) & GENMASK(7, 0))
  412. /* Extended capability IDs - ID 0 reserved */
  413. #define EXT_CAPS_PROTOCOL 2
  414. /* USB 2.0 Port Peripheral Configuration Extended Capability */
  415. #define EXT_CAP_CFG_DEV_20PORT_CAP_ID 0xC1
  416. /*
  417. * Setting this bit to '1' enables automatic wakeup from L1 state on transfer
  418. * TRB prepared when USBSSP operates in USB2.0 mode.
  419. */
  420. #define PORT_REG6_L1_L0_HW_EN BIT(1)
  421. /*
  422. * Setting this bit to '1' forces Full Speed when USBSSP operates in USB2.0
  423. * mode (disables High Speed).
  424. */
  425. #define PORT_REG6_FORCE_FS BIT(0)
  426. /**
  427. * USB3.x Port Peripheral Configuration Registers.
  428. * @ext_cap: Header register for Extended Capability.
  429. * @mode_addr: Miscellaneous 3xPORT operation mode configuration register.
  430. * @mode_2: 3x Port Control Register 2.
  431. */
  432. struct cdnsp_3xport_cap {
  433. __le32 ext_cap;
  434. __le32 mode_addr;
  435. __le32 reserved[52];
  436. __le32 mode_2;
  437. };
  438. /* Extended Capability Header for 3XPort Configuration Registers. */
  439. #define D_XEC_CFG_3XPORT_CAP 0xC0
  440. #define CFG_3XPORT_SSP_SUPPORT BIT(31)
  441. #define CFG_3XPORT_U1_PIPE_CLK_GATE_EN BIT(0)
  442. /* Revision Extended Capability ID */
  443. #define RTL_REV_CAP 0xC4
  444. #define RTL_REV_CAP_RX_BUFF_CMD_SIZE BITMASK(31, 24)
  445. #define RTL_REV_CAP_RX_BUFF_SIZE BITMASK(15, 0)
  446. #define RTL_REV_CAP_TX_BUFF_CMD_SIZE BITMASK(31, 24)
  447. #define RTL_REV_CAP_TX_BUFF_SIZE BITMASK(15, 0)
  448. #define CDNSP_VER_1 0x00000000
  449. #define CDNSP_VER_2 0x10000000
  450. #define CDNSP_IF_EP_EXIST(pdev, ep_num, dir) \
  451. (readl(&(pdev)->rev_cap->ep_supported) & \
  452. (BIT(ep_num) << ((dir) ? 0 : 16)))
  453. /**
  454. * struct cdnsp_rev_cap - controller capabilities.
  455. * @ext_cap: Header for RTL Revision Extended Capability.
  456. * @rtl_revision: RTL revision.
  457. * @rx_buff_size: Rx buffer sizes.
  458. * @tx_buff_size: Tx buffer sizes.
  459. * @ep_supported: Supported endpoints.
  460. * @ctrl_revision: Controller revision ID.
  461. */
  462. struct cdnsp_rev_cap {
  463. __le32 ext_cap;
  464. __le32 rtl_revision;
  465. __le32 rx_buff_size;
  466. __le32 tx_buff_size;
  467. __le32 ep_supported;
  468. __le32 ctrl_revision;
  469. };
  470. /* USB2.0 Port Peripheral Configuration Registers. */
  471. #define D_XEC_PRE_REGS_CAP 0xC8
  472. #define REG_CHICKEN_BITS_2_OFFSET 0x48
  473. #define CHICKEN_XDMA_2_TP_CACHE_DIS BIT(28)
  474. /* XBUF Extended Capability ID. */
  475. #define XBUF_CAP_ID 0xCB
  476. #define XBUF_RX_TAG_MASK_0_OFFSET 0x1C
  477. #define XBUF_RX_TAG_MASK_1_OFFSET 0x24
  478. #define XBUF_TX_CMD_OFFSET 0x2C
  479. /**
  480. * struct cdnsp_doorbell_array.
  481. * @cmd_db: Command ring doorbell register.
  482. * @ep_db: Endpoint ring doorbell register.
  483. * Bits 0 - 7: Endpoint target.
  484. * Bits 8 - 15: RsvdZ.
  485. * Bits 16 - 31: Stream ID.
  486. */
  487. struct cdnsp_doorbell_array {
  488. __le32 cmd_db;
  489. __le32 ep_db;
  490. };
  491. #define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))
  492. #define DB_VALUE_EP0_OUT(ep, stream) ((ep) & 0xff)
  493. #define DB_VALUE_CMD 0x00000000
  494. /**
  495. * struct cdnsp_container_ctx.
  496. * @type: Type of context. Used to calculated offsets to contained contexts.
  497. * @size: Size of the context data.
  498. * @ctx_size: context data structure size - 64 or 32 bits.
  499. * @dma: dma address of the bytes.
  500. * @bytes: The raw context data given to HW.
  501. *
  502. * Represents either a Device or Input context. Holds a pointer to the raw
  503. * memory used for the context (bytes) and dma address of it (dma).
  504. */
  505. struct cdnsp_container_ctx {
  506. unsigned int type;
  507. #define CDNSP_CTX_TYPE_DEVICE 0x1
  508. #define CDNSP_CTX_TYPE_INPUT 0x2
  509. int size;
  510. int ctx_size;
  511. dma_addr_t dma;
  512. u8 *bytes;
  513. };
  514. /**
  515. * struct cdnsp_slot_ctx
  516. * @dev_info: Device speed, and last valid endpoint.
  517. * @dev_port: Device port number that is needed to access the USB device.
  518. * @int_target: Interrupter target number.
  519. * @dev_state: Slot state and device address.
  520. *
  521. * Slot Context - This assumes the controller uses 32-byte context
  522. * structures. If the controller uses 64-byte contexts, there is an additional
  523. * 32 bytes reserved at the end of the slot context for controller internal use.
  524. */
  525. struct cdnsp_slot_ctx {
  526. __le32 dev_info;
  527. __le32 dev_port;
  528. __le32 int_target;
  529. __le32 dev_state;
  530. /* offset 0x10 to 0x1f reserved for controller internal use. */
  531. __le32 reserved[4];
  532. };
  533. /* Bits 20:23 in the Slot Context are the speed for the device. */
  534. #define SLOT_SPEED_FS (XDEV_FS << 10)
  535. #define SLOT_SPEED_HS (XDEV_HS << 10)
  536. #define SLOT_SPEED_SS (XDEV_SS << 10)
  537. #define SLOT_SPEED_SSP (XDEV_SSP << 10)
  538. /* dev_info bitmasks. */
  539. /* Device speed - values defined by PORTSC Device Speed field - 20:23. */
  540. #define DEV_SPEED GENMASK(23, 20)
  541. #define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20)
  542. /* Index of the last valid endpoint context in this device context - 27:31. */
  543. #define LAST_CTX_MASK ((unsigned int)GENMASK(31, 27))
  544. #define LAST_CTX(p) ((p) << 27)
  545. #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
  546. #define SLOT_FLAG BIT(0)
  547. #define EP0_FLAG BIT(1)
  548. /* dev_port bitmasks */
  549. /* Device port number that is needed to access the USB device. */
  550. #define DEV_PORT(p) (((p) & 0xff) << 16)
  551. /* dev_state bitmasks */
  552. /* USB device address - assigned by the controller. */
  553. #define DEV_ADDR_MASK GENMASK(7, 0)
  554. /* Slot state */
  555. #define SLOT_STATE GENMASK(31, 27)
  556. #define GET_SLOT_STATE(p) (((p) & SLOT_STATE) >> 27)
  557. #define SLOT_STATE_DISABLED 0
  558. #define SLOT_STATE_ENABLED SLOT_STATE_DISABLED
  559. #define SLOT_STATE_DEFAULT 1
  560. #define SLOT_STATE_ADDRESSED 2
  561. #define SLOT_STATE_CONFIGURED 3
  562. /**
  563. * struct cdnsp_ep_ctx.
  564. * @ep_info: Endpoint state, streams, mult, and interval information.
  565. * @ep_info2: Information on endpoint type, max packet size, max burst size,
  566. * error count, and whether the controller will force an event for
  567. * all transactions.
  568. * @deq: 64-bit ring dequeue pointer address. If the endpoint only
  569. * defines one stream, this points to the endpoint transfer ring.
  570. * Otherwise, it points to a stream context array, which has a
  571. * ring pointer for each flow.
  572. * @tx_info: Average TRB lengths for the endpoint ring and
  573. * max payload within an Endpoint Service Interval Time (ESIT).
  574. *
  575. * Endpoint Context - This assumes the controller uses 32-byte context
  576. * structures. If the controller uses 64-byte contexts, there is an additional
  577. * 32 bytes reserved at the end of the endpoint context for controller internal
  578. * use.
  579. */
  580. struct cdnsp_ep_ctx {
  581. __le32 ep_info;
  582. __le32 ep_info2;
  583. __le64 deq;
  584. __le32 tx_info;
  585. /* offset 0x14 - 0x1f reserved for controller internal use. */
  586. __le32 reserved[3];
  587. };
  588. /* ep_info bitmasks. */
  589. /*
  590. * Endpoint State - bits 0:2:
  591. * 0 - disabled
  592. * 1 - running
  593. * 2 - halted due to halt condition
  594. * 3 - stopped
  595. * 4 - TRB error
  596. * 5-7 - reserved
  597. */
  598. #define EP_STATE_MASK GENMASK(3, 0)
  599. #define EP_STATE_DISABLED 0
  600. #define EP_STATE_RUNNING 1
  601. #define EP_STATE_HALTED 2
  602. #define EP_STATE_STOPPED 3
  603. #define EP_STATE_ERROR 4
  604. #define GET_EP_CTX_STATE(ctx) (le32_to_cpu((ctx)->ep_info) & EP_STATE_MASK)
  605. /* Mult - Max number of burst within an interval, in EP companion desc. */
  606. #define EP_MULT(p) (((p) << 8) & GENMASK(9, 8))
  607. #define CTX_TO_EP_MULT(p) (((p) & GENMASK(9, 8)) >> 8)
  608. /* bits 10:14 are Max Primary Streams. */
  609. /* bit 15 is Linear Stream Array. */
  610. /* Interval - period between requests to an endpoint - 125u increments. */
  611. #define EP_INTERVAL(p) (((p) << 16) & GENMASK(23, 16))
  612. #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) & GENMASK(23, 16)) >> 16))
  613. #define CTX_TO_EP_INTERVAL(p) (((p) & GENMASK(23, 16)) >> 16)
  614. #define EP_MAXPSTREAMS_MASK GENMASK(14, 10)
  615. #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
  616. #define CTX_TO_EP_MAXPSTREAMS(p) (((p) & EP_MAXPSTREAMS_MASK) >> 10)
  617. /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
  618. #define EP_HAS_LSA BIT(15)
  619. /* ep_info2 bitmasks */
  620. #define ERROR_COUNT(p) (((p) & 0x3) << 1)
  621. #define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
  622. #define EP_TYPE(p) ((p) << 3)
  623. #define ISOC_OUT_EP 1
  624. #define BULK_OUT_EP 2
  625. #define INT_OUT_EP 3
  626. #define CTRL_EP 4
  627. #define ISOC_IN_EP 5
  628. #define BULK_IN_EP 6
  629. #define INT_IN_EP 7
  630. /* bit 6 reserved. */
  631. /* bit 7 is Device Initiate Disable - for disabling stream selection. */
  632. #define MAX_BURST(p) (((p) << 8) & GENMASK(15, 8))
  633. #define CTX_TO_MAX_BURST(p) (((p) & GENMASK(15, 8)) >> 8)
  634. #define MAX_PACKET(p) (((p) << 16) & GENMASK(31, 16))
  635. #define MAX_PACKET_MASK GENMASK(31, 16)
  636. #define MAX_PACKET_DECODED(p) (((p) & GENMASK(31, 16)) >> 16)
  637. /* tx_info bitmasks. */
  638. #define EP_AVG_TRB_LENGTH(p) ((p) & GENMASK(15, 0))
  639. #define EP_MAX_ESIT_PAYLOAD_LO(p) (((p) << 16) & GENMASK(31, 16))
  640. #define EP_MAX_ESIT_PAYLOAD_HI(p) ((((p) & GENMASK(23, 16)) >> 16) << 24)
  641. #define CTX_TO_MAX_ESIT_PAYLOAD_LO(p) (((p) & GENMASK(31, 16)) >> 16)
  642. #define CTX_TO_MAX_ESIT_PAYLOAD_HI(p) (((p) & GENMASK(31, 24)) >> 24)
  643. /* deq bitmasks. */
  644. #define EP_CTX_CYCLE_MASK BIT(0)
  645. #define CTX_DEQ_MASK (~0xfL)
  646. /**
  647. * struct cdnsp_input_control_context
  648. * Input control context;
  649. *
  650. * @drop_context: Set the bit of the endpoint context you want to disable.
  651. * @add_context: Set the bit of the endpoint context you want to enable.
  652. */
  653. struct cdnsp_input_control_ctx {
  654. __le32 drop_flags;
  655. __le32 add_flags;
  656. __le32 rsvd2[6];
  657. };
  658. /**
  659. * Represents everything that is needed to issue a command on the command ring.
  660. *
  661. * @in_ctx: Pointer to input context structure.
  662. * @status: Command Completion Code for last command.
  663. * @command_trb: Pointer to command TRB.
  664. */
  665. struct cdnsp_command {
  666. /* Input context for changing device state. */
  667. struct cdnsp_container_ctx *in_ctx;
  668. u32 status;
  669. union cdnsp_trb *command_trb;
  670. };
  671. /**
  672. * Stream context structure.
  673. *
  674. * @stream_ring: 64-bit stream ring address, cycle state, and stream type.
  675. * @reserved: offset 0x14 - 0x1f reserved for controller internal use.
  676. */
  677. struct cdnsp_stream_ctx {
  678. __le64 stream_ring;
  679. __le32 reserved[2];
  680. };
  681. /* Stream Context Types - bits 3:1 of stream ctx deq ptr. */
  682. #define SCT_FOR_CTX(p) (((p) << 1) & GENMASK(3, 1))
  683. /* Secondary stream array type, dequeue pointer is to a transfer ring. */
  684. #define SCT_SEC_TR 0
  685. /* Primary stream array type, dequeue pointer is to a transfer ring. */
  686. #define SCT_PRI_TR 1
  687. /**
  688. * struct cdnsp_stream_info: Representing everything that is needed to
  689. * supports stream capable endpoints.
  690. * @stream_rings: Array of pointers containing Transfer rings for all
  691. * supported streams.
  692. * @num_streams: Number of streams, including stream 0.
  693. * @stream_ctx_array: The stream context array may be bigger than the number
  694. * of streams the driver asked for.
  695. * @num_stream_ctxs: Number of streams.
  696. * @ctx_array_dma: Dma address of Context Stream Array.
  697. * @trb_address_map: For mapping physical TRB addresses to segments in
  698. * stream rings.
  699. * @td_count: Number of TDs associated with endpoint.
  700. * @first_prime_det: First PRIME packet detected.
  701. * @drbls_count: Number of allowed doorbells.
  702. */
  703. struct cdnsp_stream_info {
  704. struct cdnsp_ring **stream_rings;
  705. unsigned int num_streams;
  706. struct cdnsp_stream_ctx *stream_ctx_array;
  707. unsigned int num_stream_ctxs;
  708. dma_addr_t ctx_array_dma;
  709. struct radix_tree_root trb_address_map;
  710. int td_count;
  711. u8 first_prime_det;
  712. #define STREAM_DRBL_FIFO_DEPTH 2
  713. u8 drbls_count;
  714. };
  715. #define STREAM_LOG_STREAMS 4
  716. #define STREAM_NUM_STREAMS BIT(STREAM_LOG_STREAMS)
  717. #if STREAM_LOG_STREAMS > 16 && STREAM_LOG_STREAMS < 1
  718. #error "Not suupported stream value"
  719. #endif
  720. /**
  721. * struct cdnsp_ep - extended device side representation of USB endpoint.
  722. * @endpoint: usb endpoint
  723. * @pending_req_list: List of requests queuing on transfer ring.
  724. * @pdev: Device associated with this endpoint.
  725. * @number: Endpoint number (1 - 15).
  726. * idx: The device context index (DCI).
  727. * interval: Interval between packets used for ISOC endpoint.
  728. * @name: A human readable name e.g. ep1out.
  729. * @direction: Endpoint direction.
  730. * @buffering: Number of on-chip buffers related to endpoint.
  731. * @buffering_period; Number of on-chip buffers related to periodic endpoint.
  732. * @in_ctx: Pointer to input endpoint context structure.
  733. * @out_ctx: Pointer to output endpoint context structure.
  734. * @ring: Pointer to transfer ring.
  735. * @stream_info: Hold stream information.
  736. * @ep_state: Current state of endpoint.
  737. * @skip: Sometimes the controller can not process isochronous endpoint ring
  738. * quickly enough, and it will miss some isoc tds on the ring and
  739. * generate Missed Service Error Event.
  740. * Set skip flag when receive a Missed Service Error Event and
  741. * process the missed tds on the endpoint ring.
  742. */
  743. struct cdnsp_ep {
  744. struct usb_ep endpoint;
  745. struct list_head pending_list;
  746. struct cdnsp_device *pdev;
  747. u8 number;
  748. u8 idx;
  749. u32 interval;
  750. char name[20];
  751. u8 direction;
  752. u8 buffering;
  753. u8 buffering_period;
  754. struct cdnsp_ep_ctx *in_ctx;
  755. struct cdnsp_ep_ctx *out_ctx;
  756. struct cdnsp_ring *ring;
  757. struct cdnsp_stream_info stream_info;
  758. unsigned int ep_state;
  759. #define EP_ENABLED BIT(0)
  760. #define EP_DIS_IN_RROGRESS BIT(1)
  761. #define EP_HALTED BIT(2)
  762. #define EP_STOPPED BIT(3)
  763. #define EP_WEDGE BIT(4)
  764. #define EP0_HALTED_STATUS BIT(5)
  765. #define EP_HAS_STREAMS BIT(6)
  766. #define EP_UNCONFIGURED BIT(7)
  767. bool skip;
  768. };
  769. /**
  770. * struct cdnsp_device_context_array
  771. * @dev_context_ptr: Array of 64-bit DMA addresses for device contexts.
  772. * @dma: DMA address for device contexts structure.
  773. */
  774. struct cdnsp_device_context_array {
  775. __le64 dev_context_ptrs[CDNSP_DEV_MAX_SLOTS + 1];
  776. dma_addr_t dma;
  777. };
  778. /**
  779. * struct cdnsp_transfer_event.
  780. * @buffer: 64-bit buffer address, or immediate data.
  781. * @transfer_len: Data length transferred.
  782. * @flags: Field is interpreted differently based on the type of TRB.
  783. */
  784. struct cdnsp_transfer_event {
  785. __le64 buffer;
  786. __le32 transfer_len;
  787. __le32 flags;
  788. };
  789. /* Invalidate event after disabling endpoint. */
  790. #define TRB_EVENT_INVALIDATE 8
  791. /* Transfer event TRB length bit mask. */
  792. /* bits 0:23 */
  793. #define EVENT_TRB_LEN(p) ((p) & GENMASK(23, 0))
  794. /* Completion Code - only applicable for some types of TRBs */
  795. #define COMP_CODE_MASK (0xff << 24)
  796. #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
  797. #define COMP_INVALID 0
  798. #define COMP_SUCCESS 1
  799. #define COMP_DATA_BUFFER_ERROR 2
  800. #define COMP_BABBLE_DETECTED_ERROR 3
  801. #define COMP_TRB_ERROR 5
  802. #define COMP_RESOURCE_ERROR 7
  803. #define COMP_NO_SLOTS_AVAILABLE_ERROR 9
  804. #define COMP_INVALID_STREAM_TYPE_ERROR 10
  805. #define COMP_SLOT_NOT_ENABLED_ERROR 11
  806. #define COMP_ENDPOINT_NOT_ENABLED_ERROR 12
  807. #define COMP_SHORT_PACKET 13
  808. #define COMP_RING_UNDERRUN 14
  809. #define COMP_RING_OVERRUN 15
  810. #define COMP_VF_EVENT_RING_FULL_ERROR 16
  811. #define COMP_PARAMETER_ERROR 17
  812. #define COMP_CONTEXT_STATE_ERROR 19
  813. #define COMP_EVENT_RING_FULL_ERROR 21
  814. #define COMP_INCOMPATIBLE_DEVICE_ERROR 22
  815. #define COMP_MISSED_SERVICE_ERROR 23
  816. #define COMP_COMMAND_RING_STOPPED 24
  817. #define COMP_COMMAND_ABORTED 25
  818. #define COMP_STOPPED 26
  819. #define COMP_STOPPED_LENGTH_INVALID 27
  820. #define COMP_STOPPED_SHORT_PACKET 28
  821. #define COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR 29
  822. #define COMP_ISOCH_BUFFER_OVERRUN 31
  823. #define COMP_EVENT_LOST_ERROR 32
  824. #define COMP_UNDEFINED_ERROR 33
  825. #define COMP_INVALID_STREAM_ID_ERROR 34
  826. /*Transfer Event NRDY bit fields */
  827. #define TRB_TO_DEV_STREAM(p) ((p) & GENMASK(16, 0))
  828. #define TRB_TO_HOST_STREAM(p) ((p) & GENMASK(16, 0))
  829. #define STREAM_PRIME_ACK 0xFFFE
  830. #define STREAM_REJECTED 0xFFFF
  831. /** Transfer Event bit fields **/
  832. #define TRB_TO_EP_ID(p) (((p) & GENMASK(20, 16)) >> 16)
  833. /**
  834. * struct cdnsp_link_trb
  835. * @segment_ptr: 64-bit segment pointer.
  836. * @intr_target: Interrupter target.
  837. * @control: Flags.
  838. */
  839. struct cdnsp_link_trb {
  840. __le64 segment_ptr;
  841. __le32 intr_target;
  842. __le32 control;
  843. };
  844. /* control bitfields */
  845. #define LINK_TOGGLE BIT(1)
  846. /**
  847. * struct cdnsp_event_cmd - Command completion event TRB.
  848. * cmd_trb: Pointer to command TRB, or the value passed by the event data trb
  849. * status: Command completion parameters and error code.
  850. * flags: Flags.
  851. */
  852. struct cdnsp_event_cmd {
  853. __le64 cmd_trb;
  854. __le32 status;
  855. __le32 flags;
  856. };
  857. /* flags bitmasks */
  858. /* Address device - disable SetAddress. */
  859. #define TRB_BSR BIT(9)
  860. /* Configure Endpoint - Deconfigure. */
  861. #define TRB_DC BIT(9)
  862. /* Force Header */
  863. #define TRB_FH_TO_PACKET_TYPE(p) ((p) & GENMASK(4, 0))
  864. #define TRB_FH_TR_PACKET 0x4
  865. #define TRB_FH_TO_DEVICE_ADDRESS(p) (((p) << 25) & GENMASK(31, 25))
  866. #define TRB_FH_TR_PACKET_DEV_NOT 0x6
  867. #define TRB_FH_TO_NOT_TYPE(p) (((p) << 4) & GENMASK(7, 4))
  868. #define TRB_FH_TR_PACKET_FUNCTION_WAKE 0x1
  869. #define TRB_FH_TO_INTERFACE(p) (((p) << 8) & GENMASK(15, 8))
  870. enum cdnsp_setup_dev {
  871. SETUP_CONTEXT_ONLY,
  872. SETUP_CONTEXT_ADDRESS,
  873. };
  874. /* bits 24:31 are the slot ID. */
  875. #define TRB_TO_SLOT_ID(p) (((p) & GENMASK(31, 24)) >> 24)
  876. #define SLOT_ID_FOR_TRB(p) (((p) << 24) & GENMASK(31, 24))
  877. /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB. */
  878. #define TRB_TO_EP_INDEX(p) (((p) >> 16) & 0x1f)
  879. #define EP_ID_FOR_TRB(p) ((((p) + 1) << 16) & GENMASK(20, 16))
  880. #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
  881. #define TRB_TO_SUSPEND_PORT(p) (((p) >> 23) & 0x1)
  882. #define LAST_EP_INDEX 30
  883. /* Set TR Dequeue Pointer command TRB fields. */
  884. #define TRB_TO_STREAM_ID(p) ((((p) & GENMASK(31, 16)) >> 16))
  885. #define STREAM_ID_FOR_TRB(p) ((((p)) << 16) & GENMASK(31, 16))
  886. #define SCT_FOR_TRB(p) (((p) << 1) & 0x7)
  887. /* Link TRB specific fields. */
  888. #define TRB_TC BIT(1)
  889. /* Port Status Change Event TRB fields. */
  890. /* Port ID - bits 31:24. */
  891. #define GET_PORT_ID(p) (((p) & GENMASK(31, 24)) >> 24)
  892. #define SET_PORT_ID(p) (((p) << 24) & GENMASK(31, 24))
  893. #define EVENT_DATA BIT(2)
  894. /* Normal TRB fields. */
  895. /* transfer_len bitmasks - bits 0:16. */
  896. #define TRB_LEN(p) ((p) & GENMASK(16, 0))
  897. /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31). */
  898. #define TRB_TD_SIZE(p) (min((p), (u32)31) << 17)
  899. #define GET_TD_SIZE(p) (((p) & GENMASK(21, 17)) >> 17)
  900. /*
  901. * Controller uses the TD_SIZE field for TBC if Extended TBC
  902. * is enabled (ETE).
  903. */
  904. #define TRB_TD_SIZE_TBC(p) (min((p), (u32)31) << 17)
  905. /* Interrupter Target - which MSI-X vector to target the completion event at. */
  906. #define TRB_INTR_TARGET(p) (((p) << 22) & GENMASK(31, 22))
  907. #define GET_INTR_TARGET(p) (((p) & GENMASK(31, 22)) >> 22)
  908. /*
  909. * Total burst count field, Rsvdz on controller with Extended TBC
  910. * enabled (ETE).
  911. */
  912. #define TRB_TBC(p) (((p) & 0x3) << 7)
  913. #define TRB_TLBPC(p) (((p) & 0xf) << 16)
  914. /* Cycle bit - indicates TRB ownership by driver or driver.*/
  915. #define TRB_CYCLE BIT(0)
  916. /*
  917. * Force next event data TRB to be evaluated before task switch.
  918. * Used to pass OS data back after a TD completes.
  919. */
  920. #define TRB_ENT BIT(1)
  921. /* Interrupt on short packet. */
  922. #define TRB_ISP BIT(2)
  923. /* Set PCIe no snoop attribute. */
  924. #define TRB_NO_SNOOP BIT(3)
  925. /* Chain multiple TRBs into a TD. */
  926. #define TRB_CHAIN BIT(4)
  927. /* Interrupt on completion. */
  928. #define TRB_IOC BIT(5)
  929. /* The buffer pointer contains immediate data. */
  930. #define TRB_IDT BIT(6)
  931. /* 0 - NRDY during data stage, 1 - NRDY during status stage (only control). */
  932. #define TRB_STAT BIT(7)
  933. /* Block Event Interrupt. */
  934. #define TRB_BEI BIT(9)
  935. /* Control transfer TRB specific fields. */
  936. #define TRB_DIR_IN BIT(16)
  937. /* TRB bit mask in Data Stage TRB */
  938. #define TRB_SETUPID_BITMASK GENMASK(9, 8)
  939. #define TRB_SETUPID(p) ((p) << 8)
  940. #define TRB_SETUPID_TO_TYPE(p) (((p) & TRB_SETUPID_BITMASK) >> 8)
  941. #define TRB_SETUP_SPEEDID_USB3 0x1
  942. #define TRB_SETUP_SPEEDID_USB2 0x0
  943. #define TRB_SETUP_SPEEDID(p) ((p) & (1 << 7))
  944. #define TRB_SETUPSTAT_ACK 0x1
  945. #define TRB_SETUPSTAT_STALL 0x0
  946. #define TRB_SETUPSTAT(p) ((p) << 6)
  947. /* Isochronous TRB specific fields */
  948. #define TRB_SIA BIT(31)
  949. #define TRB_FRAME_ID(p) (((p) << 20) & GENMASK(30, 20))
  950. struct cdnsp_generic_trb {
  951. __le32 field[4];
  952. };
  953. union cdnsp_trb {
  954. struct cdnsp_link_trb link;
  955. struct cdnsp_transfer_event trans_event;
  956. struct cdnsp_event_cmd event_cmd;
  957. struct cdnsp_generic_trb generic;
  958. };
  959. /* TRB bit mask. */
  960. #define TRB_TYPE_BITMASK GENMASK(15, 10)
  961. #define TRB_TYPE(p) ((p) << 10)
  962. #define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
  963. /* TRB type IDs. */
  964. /* bulk, interrupt, isoc scatter/gather, and control data stage. */
  965. #define TRB_NORMAL 1
  966. /* Setup Stage for control transfers. */
  967. #define TRB_SETUP 2
  968. /* Data Stage for control transfers. */
  969. #define TRB_DATA 3
  970. /* Status Stage for control transfers. */
  971. #define TRB_STATUS 4
  972. /* ISOC transfers. */
  973. #define TRB_ISOC 5
  974. /* TRB for linking ring segments. */
  975. #define TRB_LINK 6
  976. #define TRB_EVENT_DATA 7
  977. /* Transfer Ring No-op (not for the command ring). */
  978. #define TRB_TR_NOOP 8
  979. /* Command TRBs */
  980. /* Enable Slot Command. */
  981. #define TRB_ENABLE_SLOT 9
  982. /* Disable Slot Command. */
  983. #define TRB_DISABLE_SLOT 10
  984. /* Address Device Command. */
  985. #define TRB_ADDR_DEV 11
  986. /* Configure Endpoint Command. */
  987. #define TRB_CONFIG_EP 12
  988. /* Evaluate Context Command. */
  989. #define TRB_EVAL_CONTEXT 13
  990. /* Reset Endpoint Command. */
  991. #define TRB_RESET_EP 14
  992. /* Stop Transfer Ring Command. */
  993. #define TRB_STOP_RING 15
  994. /* Set Transfer Ring Dequeue Pointer Command. */
  995. #define TRB_SET_DEQ 16
  996. /* Reset Device Command. */
  997. #define TRB_RESET_DEV 17
  998. /* Force Event Command (opt). */
  999. #define TRB_FORCE_EVENT 18
  1000. /* Force Header Command - generate a transaction or link management packet. */
  1001. #define TRB_FORCE_HEADER 22
  1002. /* No-op Command - not for transfer rings. */
  1003. #define TRB_CMD_NOOP 23
  1004. /* TRB IDs 24-31 reserved. */
  1005. /* Event TRBS. */
  1006. /* Transfer Event. */
  1007. #define TRB_TRANSFER 32
  1008. /* Command Completion Event. */
  1009. #define TRB_COMPLETION 33
  1010. /* Port Status Change Event. */
  1011. #define TRB_PORT_STATUS 34
  1012. /* Device Controller Event. */
  1013. #define TRB_HC_EVENT 37
  1014. /* MFINDEX Wrap Event - microframe counter wrapped. */
  1015. #define TRB_MFINDEX_WRAP 39
  1016. /* TRB IDs 40-47 reserved. */
  1017. /* Endpoint Not Ready Event. */
  1018. #define TRB_ENDPOINT_NRDY 48
  1019. /* TRB IDs 49-53 reserved. */
  1020. /* Halt Endpoint Command. */
  1021. #define TRB_HALT_ENDPOINT 54
  1022. /* Doorbell Overflow Event. */
  1023. #define TRB_DRB_OVERFLOW 57
  1024. /* Flush Endpoint Command. */
  1025. #define TRB_FLUSH_ENDPOINT 58
  1026. #define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
  1027. #define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
  1028. cpu_to_le32(TRB_TYPE(TRB_LINK)))
  1029. #define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
  1030. cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
  1031. /*
  1032. * TRBS_PER_SEGMENT must be a multiple of 4.
  1033. * The command ring is 64-byte aligned, so it must also be greater than 16.
  1034. */
  1035. #define TRBS_PER_SEGMENT 256
  1036. #define TRBS_PER_EVENT_SEGMENT 256
  1037. #define TRBS_PER_EV_DEQ_UPDATE 100
  1038. #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT * 16)
  1039. #define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE))
  1040. /* TRB buffer pointers can't cross 64KB boundaries. */
  1041. #define TRB_MAX_BUFF_SHIFT 16
  1042. #define TRB_MAX_BUFF_SIZE BIT(TRB_MAX_BUFF_SHIFT)
  1043. /* How much data is left before the 64KB boundary? */
  1044. #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \
  1045. ((addr) & (TRB_MAX_BUFF_SIZE - 1)))
  1046. /**
  1047. * struct cdnsp_segment - segment related data.
  1048. * @trbs: Array of Transfer Request Blocks.
  1049. * @next: Pointer to the next segment.
  1050. * @dma: DMA address of current segment.
  1051. * @bounce_dma: Bounce buffer DMA address .
  1052. * @bounce_buf: Bounce buffer virtual address.
  1053. * bounce_offs: Bounce buffer offset.
  1054. * bounce_len: Bounce buffer length.
  1055. */
  1056. struct cdnsp_segment {
  1057. union cdnsp_trb *trbs;
  1058. struct cdnsp_segment *next;
  1059. dma_addr_t dma;
  1060. /* Max packet sized bounce buffer for td-fragmant alignment */
  1061. dma_addr_t bounce_dma;
  1062. void *bounce_buf;
  1063. unsigned int bounce_offs;
  1064. unsigned int bounce_len;
  1065. };
  1066. /**
  1067. * struct cdnsp_td - Transfer Descriptor object.
  1068. * @td_list: Used for binding TD with ep_ring->td_list.
  1069. * @preq: Request associated with this TD
  1070. * @start_seg: Segment containing the first_trb in TD.
  1071. * @first_trb: First TRB for this TD.
  1072. * @last_trb: Last TRB related with TD.
  1073. * @bounce_seg: Bounce segment for this TD.
  1074. * @request_length_set: actual_length of the request has already been set.
  1075. * @drbl - TD has been added to HW scheduler - only for stream capable
  1076. * endpoints.
  1077. */
  1078. struct cdnsp_td {
  1079. struct list_head td_list;
  1080. struct cdnsp_request *preq;
  1081. struct cdnsp_segment *start_seg;
  1082. union cdnsp_trb *first_trb;
  1083. union cdnsp_trb *last_trb;
  1084. struct cdnsp_segment *bounce_seg;
  1085. bool request_length_set;
  1086. bool drbl;
  1087. };
  1088. /**
  1089. * struct cdnsp_dequeue_state - New dequeue pointer for Transfer Ring.
  1090. * @new_deq_seg: New dequeue segment.
  1091. * @new_deq_ptr: New dequeue pointer.
  1092. * @new_cycle_state: New cycle state.
  1093. * @stream_id: stream id for which new dequeue pointer has been selected.
  1094. */
  1095. struct cdnsp_dequeue_state {
  1096. struct cdnsp_segment *new_deq_seg;
  1097. union cdnsp_trb *new_deq_ptr;
  1098. int new_cycle_state;
  1099. unsigned int stream_id;
  1100. };
  1101. enum cdnsp_ring_type {
  1102. TYPE_CTRL = 0,
  1103. TYPE_ISOC,
  1104. TYPE_BULK,
  1105. TYPE_INTR,
  1106. TYPE_STREAM,
  1107. TYPE_COMMAND,
  1108. TYPE_EVENT,
  1109. };
  1110. /**
  1111. * struct cdnsp_ring - information describing transfer, command or event ring.
  1112. * @first_seg: First segment on transfer ring.
  1113. * @last_seg: Last segment on transfer ring.
  1114. * @enqueue: SW enqueue pointer address.
  1115. * @enq_seg: SW enqueue segment address.
  1116. * @dequeue: SW dequeue pointer address.
  1117. * @deq_seg: SW dequeue segment address.
  1118. * @td_list: transfer descriptor list associated with this ring.
  1119. * @cycle_state: Current cycle bit. Write the cycle state into the TRB cycle
  1120. * field to give ownership of the TRB to the device controller
  1121. * (if we are the producer) or to check if we own the TRB
  1122. * (if we are the consumer).
  1123. * @stream_id: Stream id
  1124. * @stream_active: Stream is active - PRIME packet has been detected.
  1125. * @stream_rejected: This ring has been rejected by host.
  1126. * @num_tds: Number of TDs associated with ring.
  1127. * @num_segs: Number of segments.
  1128. * @num_trbs_free: Number of free TRBs on the ring.
  1129. * @bounce_buf_len: Length of bounce buffer.
  1130. * @type: Ring type - event, transfer, or command ring.
  1131. * @last_td_was_short - TD is short TD.
  1132. * @trb_address_map: For mapping physical TRB addresses to segments in
  1133. * stream rings.
  1134. */
  1135. struct cdnsp_ring {
  1136. struct cdnsp_segment *first_seg;
  1137. struct cdnsp_segment *last_seg;
  1138. union cdnsp_trb *enqueue;
  1139. struct cdnsp_segment *enq_seg;
  1140. union cdnsp_trb *dequeue;
  1141. struct cdnsp_segment *deq_seg;
  1142. struct list_head td_list;
  1143. u32 cycle_state;
  1144. unsigned int stream_id;
  1145. unsigned int stream_active;
  1146. unsigned int stream_rejected;
  1147. int num_tds;
  1148. unsigned int num_segs;
  1149. unsigned int num_trbs_free;
  1150. unsigned int bounce_buf_len;
  1151. enum cdnsp_ring_type type;
  1152. bool last_td_was_short;
  1153. struct radix_tree_root *trb_address_map;
  1154. };
  1155. /**
  1156. * struct cdnsp_erst_entry - even ring segment table entry object.
  1157. * @seg_addr: 64-bit event ring segment address.
  1158. * seg_size: Number of TRBs in segment.;
  1159. */
  1160. struct cdnsp_erst_entry {
  1161. __le64 seg_addr;
  1162. __le32 seg_size;
  1163. /* Set to zero */
  1164. __le32 rsvd;
  1165. };
  1166. /**
  1167. * struct cdnsp_erst - even ring segment table for event ring.
  1168. * @entries: Array of event ring segments
  1169. * @num_entries: Number of segments in entries array.
  1170. * @erst_dma_addr: DMA address for entries array.
  1171. */
  1172. struct cdnsp_erst {
  1173. struct cdnsp_erst_entry *entries;
  1174. unsigned int num_entries;
  1175. dma_addr_t erst_dma_addr;
  1176. };
  1177. /**
  1178. * struct cdnsp_request - extended device side representation of usb_request
  1179. * object .
  1180. * @td: Transfer descriptor associated with this request.
  1181. * @request: Generic usb_request object describing single I/O request.
  1182. * @list: Used to adding request to endpoint pending_list.
  1183. * @pep: Extended representation of usb_ep object
  1184. * @epnum: Endpoint number associated with usb request.
  1185. * @direction: Endpoint direction for usb request.
  1186. */
  1187. struct cdnsp_request {
  1188. struct cdnsp_td td;
  1189. struct usb_request request;
  1190. struct list_head list;
  1191. struct cdnsp_ep *pep;
  1192. u8 epnum;
  1193. unsigned direction:1;
  1194. };
  1195. #define ERST_NUM_SEGS 1
  1196. /* Stages used during enumeration process.*/
  1197. enum cdnsp_ep0_stage {
  1198. CDNSP_SETUP_STAGE,
  1199. CDNSP_DATA_STAGE,
  1200. CDNSP_STATUS_STAGE,
  1201. };
  1202. /**
  1203. * struct cdnsp_port - holds information about detected ports.
  1204. * @port_num: Port number.
  1205. * @exist: Indicate if port exist.
  1206. * maj_rev: Major revision.
  1207. * min_rev: Minor revision.
  1208. */
  1209. struct cdnsp_port {
  1210. struct cdnsp_port_regs __iomem *regs;
  1211. u8 port_num;
  1212. u8 exist;
  1213. u8 maj_rev;
  1214. u8 min_rev;
  1215. };
  1216. #define CDNSP_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
  1217. #define CDNSP_EXT_PORT_MINOR(x) (((x) >> 16) & 0xff)
  1218. #define CDNSP_EXT_PORT_OFF(x) ((x) & 0xff)
  1219. #define CDNSP_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
  1220. /**
  1221. * struct cdnsp_device - represent USB device.
  1222. * @dev: Pointer to device structure associated whit this controller.
  1223. * @gadget: Device side representation of the peripheral controller.
  1224. * @gadget_driver: Pointer to the gadget driver.
  1225. * @irq: IRQ line number used by device side.
  1226. * @regs:IO device memory.
  1227. * @cap_regs: Capability registers.
  1228. * @op_regs: Operational registers.
  1229. * @run_regs: Runtime registers.
  1230. * @dba: Device base address register.
  1231. * @ir_set: Current interrupter register set.
  1232. * @port20_regs: Port 2.0 Peripheral Configuration Registers.
  1233. * @port3x_regs: USB3.x Port Peripheral Configuration Registers.
  1234. * @rev_cap: Controller Capabilities Registers.
  1235. * @hcs_params1: Cached register copies of read-only HCSPARAMS1
  1236. * @hcc_params: Cached register copies of read-only HCCPARAMS1
  1237. * @setup: Temporary buffer for setup packet.
  1238. * @ep0_preq: Internal allocated request used during enumeration.
  1239. * @ep0_stage: ep0 stage during enumeration process.
  1240. * @three_stage_setup: Three state or two state setup.
  1241. * @ep0_expect_in: Data IN expected for control transfer.
  1242. * @setup_id: Setup identifier.
  1243. * @setup_speed - Speed detected for current SETUP packet.
  1244. * @setup_buf: Buffer for SETUP packet.
  1245. * @device_address: Current device address.
  1246. * @may_wakeup: remote wakeup enabled/disabled.
  1247. * @lock: Lock used in interrupt thread context.
  1248. * @hci_version: device controller version.
  1249. * @dcbaa: Device context base address array.
  1250. * @cmd_ring: Command ring.
  1251. * @cmd: Represent all what is needed to issue command on Command Ring.
  1252. * @event_ring: Event ring.
  1253. * @erst: Event Ring Segment table
  1254. * @slot_id: Current Slot ID. Should be 0 or 1.
  1255. * @out_ctx: Output context.
  1256. * @in_ctx: Input context.
  1257. * @eps: array of endpoints object associated with device.
  1258. * @usb2_hw_lpm_capable: hardware lpm is enabled;
  1259. * @u1_allowed: Allow device transition to U1 state.
  1260. * @u2_allowed: Allow device transition to U2 state
  1261. * @device_pool: DMA pool for allocating input and output context.
  1262. * @segment_pool: DMA pool for allocating new segments.
  1263. * @cdnsp_state: Current state of controller.
  1264. * @link_state: Current link state.
  1265. * @usb2_port - Port USB 2.0.
  1266. * @usb3_port - Port USB 3.0.
  1267. * @active_port - Current selected Port.
  1268. * @test_mode: selected Test Mode.
  1269. */
  1270. struct cdnsp_device {
  1271. struct device *dev;
  1272. struct usb_gadget gadget;
  1273. struct usb_gadget_driver *gadget_driver;
  1274. unsigned int irq;
  1275. void __iomem *regs;
  1276. /* Registers map */
  1277. struct cdnsp_cap_regs __iomem *cap_regs;
  1278. struct cdnsp_op_regs __iomem *op_regs;
  1279. struct cdnsp_run_regs __iomem *run_regs;
  1280. struct cdnsp_doorbell_array __iomem *dba;
  1281. struct cdnsp_intr_reg __iomem *ir_set;
  1282. struct cdnsp_20port_cap __iomem *port20_regs;
  1283. struct cdnsp_3xport_cap __iomem *port3x_regs;
  1284. struct cdnsp_rev_cap __iomem *rev_cap;
  1285. /* Cached register copies of read-only CDNSP data */
  1286. __u32 hcs_params1;
  1287. __u32 hcs_params3;
  1288. __u32 hcc_params;
  1289. /* Lock used in interrupt thread context. */
  1290. spinlock_t lock;
  1291. struct usb_ctrlrequest setup;
  1292. struct cdnsp_request ep0_preq;
  1293. enum cdnsp_ep0_stage ep0_stage;
  1294. u8 three_stage_setup;
  1295. u8 ep0_expect_in;
  1296. u8 setup_id;
  1297. u8 setup_speed;
  1298. void *setup_buf;
  1299. u8 device_address;
  1300. int may_wakeup;
  1301. u16 hci_version;
  1302. /* data structures */
  1303. struct cdnsp_device_context_array *dcbaa;
  1304. struct cdnsp_ring *cmd_ring;
  1305. struct cdnsp_command cmd;
  1306. struct cdnsp_ring *event_ring;
  1307. struct cdnsp_erst erst;
  1308. int slot_id;
  1309. /*
  1310. * Commands to the hardware are passed an "input context" that
  1311. * tells the hardware what to change in its data structures.
  1312. * The hardware will return changes in an "output context" that
  1313. * software must allocate for the hardware. .
  1314. */
  1315. struct cdnsp_container_ctx out_ctx;
  1316. struct cdnsp_container_ctx in_ctx;
  1317. struct cdnsp_ep eps[CDNSP_ENDPOINTS_NUM];
  1318. u8 usb2_hw_lpm_capable:1;
  1319. u8 u1_allowed:1;
  1320. u8 u2_allowed:1;
  1321. /* DMA pools */
  1322. struct dma_pool *device_pool;
  1323. struct dma_pool *segment_pool;
  1324. #define CDNSP_STATE_HALTED BIT(1)
  1325. #define CDNSP_STATE_DYING BIT(2)
  1326. #define CDNSP_STATE_DISCONNECT_PENDING BIT(3)
  1327. #define CDNSP_WAKEUP_PENDING BIT(4)
  1328. unsigned int cdnsp_state;
  1329. unsigned int link_state;
  1330. struct cdnsp_port usb2_port;
  1331. struct cdnsp_port usb3_port;
  1332. struct cdnsp_port *active_port;
  1333. u16 test_mode;
  1334. };
  1335. /*
  1336. * Registers should always be accessed with double word or quad word accesses.
  1337. *
  1338. * Registers with 64-bit address pointers should be written to with
  1339. * dword accesses by writing the low dword first (ptr[0]), then the high dword
  1340. * (ptr[1]) second. controller implementations that do not support 64-bit
  1341. * address pointers will ignore the high dword, and write order is irrelevant.
  1342. */
  1343. static inline u64 cdnsp_read_64(__le64 __iomem *regs)
  1344. {
  1345. return lo_hi_readq(regs);
  1346. }
  1347. static inline void cdnsp_write_64(const u64 val, __le64 __iomem *regs)
  1348. {
  1349. lo_hi_writeq(val, regs);
  1350. }
  1351. /* CDNSP memory management functions. */
  1352. void cdnsp_mem_cleanup(struct cdnsp_device *pdev);
  1353. int cdnsp_mem_init(struct cdnsp_device *pdev);
  1354. int cdnsp_setup_addressable_priv_dev(struct cdnsp_device *pdev);
  1355. void cdnsp_copy_ep0_dequeue_into_input_ctx(struct cdnsp_device *pdev);
  1356. void cdnsp_endpoint_zero(struct cdnsp_device *pdev, struct cdnsp_ep *ep);
  1357. int cdnsp_endpoint_init(struct cdnsp_device *pdev,
  1358. struct cdnsp_ep *pep,
  1359. gfp_t mem_flags);
  1360. int cdnsp_ring_expansion(struct cdnsp_device *pdev,
  1361. struct cdnsp_ring *ring,
  1362. unsigned int num_trbs, gfp_t flags);
  1363. struct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *ep, u64 address);
  1364. int cdnsp_alloc_stream_info(struct cdnsp_device *pdev,
  1365. struct cdnsp_ep *pep,
  1366. unsigned int num_stream_ctxs,
  1367. unsigned int num_streams);
  1368. int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep);
  1369. void cdnsp_free_endpoint_rings(struct cdnsp_device *pdev, struct cdnsp_ep *pep);
  1370. /* Device controller glue. */
  1371. int cdnsp_find_next_ext_cap(void __iomem *base, u32 start, int id);
  1372. int cdnsp_halt(struct cdnsp_device *pdev);
  1373. void cdnsp_died(struct cdnsp_device *pdev);
  1374. int cdnsp_reset(struct cdnsp_device *pdev);
  1375. irqreturn_t cdnsp_irq_handler(int irq, void *priv);
  1376. int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup);
  1377. void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *usbsssp_data,
  1378. struct usb_request *req, int enable);
  1379. irqreturn_t cdnsp_thread_irq_handler(int irq, void *data);
  1380. /* Ring, segment, TRB, and TD functions. */
  1381. dma_addr_t cdnsp_trb_virt_to_dma(struct cdnsp_segment *seg,
  1382. union cdnsp_trb *trb);
  1383. bool cdnsp_last_trb_on_seg(struct cdnsp_segment *seg, union cdnsp_trb *trb);
  1384. bool cdnsp_last_trb_on_ring(struct cdnsp_ring *ring,
  1385. struct cdnsp_segment *seg,
  1386. union cdnsp_trb *trb);
  1387. int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev);
  1388. void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev,
  1389. union cdnsp_trb *event_ring_deq,
  1390. u8 clear_ehb);
  1391. void cdnsp_initialize_ring_info(struct cdnsp_ring *ring);
  1392. void cdnsp_ring_cmd_db(struct cdnsp_device *pdev);
  1393. void cdnsp_queue_slot_control(struct cdnsp_device *pdev, u32 trb_type);
  1394. void cdnsp_queue_address_device(struct cdnsp_device *pdev,
  1395. dma_addr_t in_ctx_ptr,
  1396. enum cdnsp_setup_dev setup);
  1397. void cdnsp_queue_stop_endpoint(struct cdnsp_device *pdev,
  1398. unsigned int ep_index);
  1399. int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq);
  1400. int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq);
  1401. int cdnsp_queue_isoc_tx_prepare(struct cdnsp_device *pdev,
  1402. struct cdnsp_request *preq);
  1403. void cdnsp_queue_configure_endpoint(struct cdnsp_device *pdev,
  1404. dma_addr_t in_ctx_ptr);
  1405. void cdnsp_queue_reset_ep(struct cdnsp_device *pdev, unsigned int ep_index);
  1406. void cdnsp_queue_halt_endpoint(struct cdnsp_device *pdev,
  1407. unsigned int ep_index);
  1408. void cdnsp_queue_flush_endpoint(struct cdnsp_device *pdev,
  1409. unsigned int ep_index);
  1410. void cdnsp_force_header_wakeup(struct cdnsp_device *pdev, int intf_num);
  1411. void cdnsp_queue_reset_device(struct cdnsp_device *pdev);
  1412. void cdnsp_queue_new_dequeue_state(struct cdnsp_device *pdev,
  1413. struct cdnsp_ep *pep,
  1414. struct cdnsp_dequeue_state *deq_state);
  1415. void cdnsp_ring_doorbell_for_active_rings(struct cdnsp_device *pdev,
  1416. struct cdnsp_ep *pep);
  1417. void cdnsp_inc_deq(struct cdnsp_device *pdev, struct cdnsp_ring *ring);
  1418. void cdnsp_set_link_state(struct cdnsp_device *pdev,
  1419. __le32 __iomem *port_regs, u32 link_state);
  1420. u32 cdnsp_port_state_to_neutral(u32 state);
  1421. /* CDNSP device controller contexts. */
  1422. int cdnsp_enable_slot(struct cdnsp_device *pdev);
  1423. int cdnsp_disable_slot(struct cdnsp_device *pdev);
  1424. struct cdnsp_input_control_ctx
  1425. *cdnsp_get_input_control_ctx(struct cdnsp_container_ctx *ctx);
  1426. struct cdnsp_slot_ctx *cdnsp_get_slot_ctx(struct cdnsp_container_ctx *ctx);
  1427. struct cdnsp_ep_ctx *cdnsp_get_ep_ctx(struct cdnsp_container_ctx *ctx,
  1428. unsigned int ep_index);
  1429. /* CDNSP gadget interface. */
  1430. void cdnsp_suspend_gadget(struct cdnsp_device *pdev);
  1431. void cdnsp_resume_gadget(struct cdnsp_device *pdev);
  1432. void cdnsp_disconnect_gadget(struct cdnsp_device *pdev);
  1433. void cdnsp_gadget_giveback(struct cdnsp_ep *pep, struct cdnsp_request *preq,
  1434. int status);
  1435. int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq);
  1436. int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq);
  1437. unsigned int cdnsp_port_speed(unsigned int port_status);
  1438. void cdnsp_irq_reset(struct cdnsp_device *pdev);
  1439. int cdnsp_halt_endpoint(struct cdnsp_device *pdev,
  1440. struct cdnsp_ep *pep, int value);
  1441. int cdnsp_cmd_stop_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep);
  1442. int cdnsp_cmd_flush_ep(struct cdnsp_device *pdev, struct cdnsp_ep *pep);
  1443. void cdnsp_setup_analyze(struct cdnsp_device *pdev);
  1444. int cdnsp_status_stage(struct cdnsp_device *pdev);
  1445. int cdnsp_reset_device(struct cdnsp_device *pdev);
  1446. /**
  1447. * next_request - gets the next request on the given list
  1448. * @list: the request list to operate on
  1449. *
  1450. * Caller should take care of locking. This function return NULL or the first
  1451. * request available on list.
  1452. */
  1453. static inline struct cdnsp_request *next_request(struct list_head *list)
  1454. {
  1455. return list_first_entry_or_null(list, struct cdnsp_request, list);
  1456. }
  1457. #define to_cdnsp_ep(ep) (container_of(ep, struct cdnsp_ep, endpoint))
  1458. #define gadget_to_cdnsp(g) (container_of(g, struct cdnsp_device, gadget))
  1459. #define request_to_cdnsp_request(r) (container_of(r, struct cdnsp_request, \
  1460. request))
  1461. #define to_cdnsp_request(r) (container_of(r, struct cdnsp_request, request))
  1462. int cdnsp_remove_request(struct cdnsp_device *pdev, struct cdnsp_request *preq,
  1463. struct cdnsp_ep *pep);
  1464. #endif /* __LINUX_CDNSP_GADGET_H */