hcd_intr.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131
  1. /*
  2. * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling
  3. *
  4. * Copyright (C) 2004-2013 Synopsys, Inc.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions, and the following disclaimer,
  11. * without modification.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The names of the above-listed copyright holders may not be used
  16. * to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * ALTERNATIVELY, this software may be distributed under the terms of the
  20. * GNU General Public License ("GPL") as published by the Free Software
  21. * Foundation; either version 2 of the License, or (at your option) any
  22. * later version.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  25. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /*
  37. * This file contains the interrupt handlers for Host mode
  38. */
  39. #include <linux/kernel.h>
  40. #include <linux/module.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/io.h>
  45. #include <linux/slab.h>
  46. #include <linux/usb.h>
  47. #include <linux/usb/hcd.h>
  48. #include <linux/usb/ch11.h>
  49. #include "core.h"
  50. #include "hcd.h"
  51. /* This function is for debug only */
  52. static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg)
  53. {
  54. #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
  55. u16 curr_frame_number = hsotg->frame_number;
  56. if (hsotg->frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  57. if (((hsotg->last_frame_num + 1) & HFNUM_MAX_FRNUM) !=
  58. curr_frame_number) {
  59. hsotg->frame_num_array[hsotg->frame_num_idx] =
  60. curr_frame_number;
  61. hsotg->last_frame_num_array[hsotg->frame_num_idx] =
  62. hsotg->last_frame_num;
  63. hsotg->frame_num_idx++;
  64. }
  65. } else if (!hsotg->dumped_frame_num_array) {
  66. int i;
  67. dev_info(hsotg->dev, "Frame Last Frame\n");
  68. dev_info(hsotg->dev, "----- ----------\n");
  69. for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  70. dev_info(hsotg->dev, "0x%04x 0x%04x\n",
  71. hsotg->frame_num_array[i],
  72. hsotg->last_frame_num_array[i]);
  73. }
  74. hsotg->dumped_frame_num_array = 1;
  75. }
  76. hsotg->last_frame_num = curr_frame_number;
  77. #endif
  78. }
  79. static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg,
  80. struct dwc2_host_chan *chan,
  81. struct dwc2_qtd *qtd)
  82. {
  83. struct urb *usb_urb;
  84. if (!chan->qh)
  85. return;
  86. if (chan->qh->dev_speed == USB_SPEED_HIGH)
  87. return;
  88. if (!qtd->urb)
  89. return;
  90. usb_urb = qtd->urb->priv;
  91. if (!usb_urb || !usb_urb->dev || !usb_urb->dev->tt)
  92. return;
  93. if (qtd->urb->status != -EPIPE && qtd->urb->status != -EREMOTEIO) {
  94. chan->qh->tt_buffer_dirty = 1;
  95. if (usb_hub_clear_tt_buffer(usb_urb))
  96. /* Clear failed; let's hope things work anyway */
  97. chan->qh->tt_buffer_dirty = 0;
  98. }
  99. }
  100. /*
  101. * Handles the start-of-frame interrupt in host mode. Non-periodic
  102. * transactions may be queued to the DWC_otg controller for the current
  103. * (micro)frame. Periodic transactions may be queued to the controller
  104. * for the next (micro)frame.
  105. */
  106. static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)
  107. {
  108. struct list_head *qh_entry;
  109. struct dwc2_qh *qh;
  110. enum dwc2_transaction_type tr_type;
  111. #ifdef DEBUG_SOF
  112. dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n");
  113. #endif
  114. hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
  115. dwc2_track_missed_sofs(hsotg);
  116. /* Determine whether any periodic QHs should be executed */
  117. qh_entry = hsotg->periodic_sched_inactive.next;
  118. while (qh_entry != &hsotg->periodic_sched_inactive) {
  119. qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry);
  120. qh_entry = qh_entry->next;
  121. if (dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number))
  122. /*
  123. * Move QH to the ready list to be executed next
  124. * (micro)frame
  125. */
  126. list_move(&qh->qh_list_entry,
  127. &hsotg->periodic_sched_ready);
  128. }
  129. tr_type = dwc2_hcd_select_transactions(hsotg);
  130. if (tr_type != DWC2_TRANSACTION_NONE)
  131. dwc2_hcd_queue_transactions(hsotg, tr_type);
  132. /* Clear interrupt */
  133. writel(GINTSTS_SOF, hsotg->regs + GINTSTS);
  134. }
  135. /*
  136. * Handles the Rx FIFO Level Interrupt, which indicates that there is
  137. * at least one packet in the Rx FIFO. The packets are moved from the FIFO to
  138. * memory if the DWC_otg controller is operating in Slave mode.
  139. */
  140. static void dwc2_rx_fifo_level_intr(struct dwc2_hsotg *hsotg)
  141. {
  142. u32 grxsts, chnum, bcnt, dpid, pktsts;
  143. struct dwc2_host_chan *chan;
  144. if (dbg_perio())
  145. dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n");
  146. grxsts = readl(hsotg->regs + GRXSTSP);
  147. chnum = (grxsts & GRXSTS_HCHNUM_MASK) >> GRXSTS_HCHNUM_SHIFT;
  148. chan = hsotg->hc_ptr_array[chnum];
  149. if (!chan) {
  150. dev_err(hsotg->dev, "Unable to get corresponding channel\n");
  151. return;
  152. }
  153. bcnt = (grxsts & GRXSTS_BYTECNT_MASK) >> GRXSTS_BYTECNT_SHIFT;
  154. dpid = (grxsts & GRXSTS_DPID_MASK) >> GRXSTS_DPID_SHIFT;
  155. pktsts = (grxsts & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT;
  156. /* Packet Status */
  157. if (dbg_perio()) {
  158. dev_vdbg(hsotg->dev, " Ch num = %d\n", chnum);
  159. dev_vdbg(hsotg->dev, " Count = %d\n", bcnt);
  160. dev_vdbg(hsotg->dev, " DPID = %d, chan.dpid = %d\n", dpid,
  161. chan->data_pid_start);
  162. dev_vdbg(hsotg->dev, " PStatus = %d\n", pktsts);
  163. }
  164. switch (pktsts) {
  165. case GRXSTS_PKTSTS_HCHIN:
  166. /* Read the data into the host buffer */
  167. if (bcnt > 0) {
  168. dwc2_read_packet(hsotg, chan->xfer_buf, bcnt);
  169. /* Update the HC fields for the next packet received */
  170. chan->xfer_count += bcnt;
  171. chan->xfer_buf += bcnt;
  172. }
  173. break;
  174. case GRXSTS_PKTSTS_HCHIN_XFER_COMP:
  175. case GRXSTS_PKTSTS_DATATOGGLEERR:
  176. case GRXSTS_PKTSTS_HCHHALTED:
  177. /* Handled in interrupt, just ignore data */
  178. break;
  179. default:
  180. dev_err(hsotg->dev,
  181. "RxFIFO Level Interrupt: Unknown status %d\n", pktsts);
  182. break;
  183. }
  184. }
  185. /*
  186. * This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  187. * data packets may be written to the FIFO for OUT transfers. More requests
  188. * may be written to the non-periodic request queue for IN transfers. This
  189. * interrupt is enabled only in Slave mode.
  190. */
  191. static void dwc2_np_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
  192. {
  193. dev_vdbg(hsotg->dev, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  194. dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_NON_PERIODIC);
  195. }
  196. /*
  197. * This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  198. * packets may be written to the FIFO for OUT transfers. More requests may be
  199. * written to the periodic request queue for IN transfers. This interrupt is
  200. * enabled only in Slave mode.
  201. */
  202. static void dwc2_perio_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
  203. {
  204. if (dbg_perio())
  205. dev_vdbg(hsotg->dev, "--Periodic TxFIFO Empty Interrupt--\n");
  206. dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_PERIODIC);
  207. }
  208. static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0,
  209. u32 *hprt0_modify)
  210. {
  211. struct dwc2_core_params *params = hsotg->core_params;
  212. int do_reset = 0;
  213. u32 usbcfg;
  214. u32 prtspd;
  215. u32 hcfg;
  216. u32 fslspclksel;
  217. u32 hfir;
  218. dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
  219. /* Every time when port enables calculate HFIR.FrInterval */
  220. hfir = readl(hsotg->regs + HFIR);
  221. hfir &= ~HFIR_FRINT_MASK;
  222. hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
  223. HFIR_FRINT_MASK;
  224. writel(hfir, hsotg->regs + HFIR);
  225. /* Check if we need to adjust the PHY clock speed for low power */
  226. if (!params->host_support_fs_ls_low_power) {
  227. /* Port has been enabled, set the reset change flag */
  228. hsotg->flags.b.port_reset_change = 1;
  229. return;
  230. }
  231. usbcfg = readl(hsotg->regs + GUSBCFG);
  232. prtspd = (hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT;
  233. if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) {
  234. /* Low power */
  235. if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) {
  236. /* Set PHY low power clock select for FS/LS devices */
  237. usbcfg |= GUSBCFG_PHY_LP_CLK_SEL;
  238. writel(usbcfg, hsotg->regs + GUSBCFG);
  239. do_reset = 1;
  240. }
  241. hcfg = readl(hsotg->regs + HCFG);
  242. fslspclksel = (hcfg & HCFG_FSLSPCLKSEL_MASK) >>
  243. HCFG_FSLSPCLKSEL_SHIFT;
  244. if (prtspd == HPRT0_SPD_LOW_SPEED &&
  245. params->host_ls_low_power_phy_clk ==
  246. DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
  247. /* 6 MHZ */
  248. dev_vdbg(hsotg->dev,
  249. "FS_PHY programming HCFG to 6 MHz\n");
  250. if (fslspclksel != HCFG_FSLSPCLKSEL_6_MHZ) {
  251. fslspclksel = HCFG_FSLSPCLKSEL_6_MHZ;
  252. hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
  253. hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT;
  254. writel(hcfg, hsotg->regs + HCFG);
  255. do_reset = 1;
  256. }
  257. } else {
  258. /* 48 MHZ */
  259. dev_vdbg(hsotg->dev,
  260. "FS_PHY programming HCFG to 48 MHz\n");
  261. if (fslspclksel != HCFG_FSLSPCLKSEL_48_MHZ) {
  262. fslspclksel = HCFG_FSLSPCLKSEL_48_MHZ;
  263. hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
  264. hcfg |= fslspclksel << HCFG_FSLSPCLKSEL_SHIFT;
  265. writel(hcfg, hsotg->regs + HCFG);
  266. do_reset = 1;
  267. }
  268. }
  269. } else {
  270. /* Not low power */
  271. if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) {
  272. usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL;
  273. writel(usbcfg, hsotg->regs + GUSBCFG);
  274. do_reset = 1;
  275. }
  276. }
  277. if (do_reset) {
  278. *hprt0_modify |= HPRT0_RST;
  279. queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work,
  280. msecs_to_jiffies(60));
  281. } else {
  282. /* Port has been enabled, set the reset change flag */
  283. hsotg->flags.b.port_reset_change = 1;
  284. }
  285. }
  286. /*
  287. * There are multiple conditions that can cause a port interrupt. This function
  288. * determines which interrupt conditions have occurred and handles them
  289. * appropriately.
  290. */
  291. static void dwc2_port_intr(struct dwc2_hsotg *hsotg)
  292. {
  293. u32 hprt0;
  294. u32 hprt0_modify;
  295. dev_vdbg(hsotg->dev, "--Port Interrupt--\n");
  296. hprt0 = readl(hsotg->regs + HPRT0);
  297. hprt0_modify = hprt0;
  298. /*
  299. * Clear appropriate bits in HPRT0 to clear the interrupt bit in
  300. * GINTSTS
  301. */
  302. hprt0_modify &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG |
  303. HPRT0_OVRCURRCHG);
  304. /*
  305. * Port Connect Detected
  306. * Set flag and clear if detected
  307. */
  308. if (hprt0 & HPRT0_CONNDET) {
  309. dev_vdbg(hsotg->dev,
  310. "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n",
  311. hprt0);
  312. hsotg->flags.b.port_connect_status_change = 1;
  313. hsotg->flags.b.port_connect_status = 1;
  314. hprt0_modify |= HPRT0_CONNDET;
  315. /*
  316. * The Hub driver asserts a reset when it sees port connect
  317. * status change flag
  318. */
  319. }
  320. /*
  321. * Port Enable Changed
  322. * Clear if detected - Set internal flag if disabled
  323. */
  324. if (hprt0 & HPRT0_ENACHG) {
  325. dev_vdbg(hsotg->dev,
  326. " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
  327. hprt0, !!(hprt0 & HPRT0_ENA));
  328. hprt0_modify |= HPRT0_ENACHG;
  329. if (hprt0 & HPRT0_ENA)
  330. dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
  331. else
  332. hsotg->flags.b.port_enable_change = 1;
  333. }
  334. /* Overcurrent Change Interrupt */
  335. if (hprt0 & HPRT0_OVRCURRCHG) {
  336. dev_vdbg(hsotg->dev,
  337. " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
  338. hprt0);
  339. hsotg->flags.b.port_over_current_change = 1;
  340. hprt0_modify |= HPRT0_OVRCURRCHG;
  341. }
  342. /* Clear Port Interrupts */
  343. writel(hprt0_modify, hsotg->regs + HPRT0);
  344. }
  345. /*
  346. * Gets the actual length of a transfer after the transfer halts. halt_status
  347. * holds the reason for the halt.
  348. *
  349. * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
  350. * is set to 1 upon return if less than the requested number of bytes were
  351. * transferred. short_read may also be NULL on entry, in which case it remains
  352. * unchanged.
  353. */
  354. static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
  355. struct dwc2_host_chan *chan, int chnum,
  356. struct dwc2_qtd *qtd,
  357. enum dwc2_halt_status halt_status,
  358. int *short_read)
  359. {
  360. u32 hctsiz, count, length;
  361. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  362. if (halt_status == DWC2_HC_XFER_COMPLETE) {
  363. if (chan->ep_is_in) {
  364. count = (hctsiz & TSIZ_XFERSIZE_MASK) >>
  365. TSIZ_XFERSIZE_SHIFT;
  366. length = chan->xfer_len - count;
  367. if (short_read != NULL)
  368. *short_read = (count != 0);
  369. } else if (chan->qh->do_split) {
  370. length = qtd->ssplit_out_xfer_count;
  371. } else {
  372. length = chan->xfer_len;
  373. }
  374. } else {
  375. /*
  376. * Must use the hctsiz.pktcnt field to determine how much data
  377. * has been transferred. This field reflects the number of
  378. * packets that have been transferred via the USB. This is
  379. * always an integral number of packets if the transfer was
  380. * halted before its normal completion. (Can't use the
  381. * hctsiz.xfersize field because that reflects the number of
  382. * bytes transferred via the AHB, not the USB).
  383. */
  384. count = (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT;
  385. length = (chan->start_pkt_count - count) * chan->max_packet;
  386. }
  387. return length;
  388. }
  389. /**
  390. * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
  391. * Complete interrupt on the host channel. Updates the actual_length field
  392. * of the URB based on the number of bytes transferred via the host channel.
  393. * Sets the URB status if the data transfer is finished.
  394. *
  395. * Return: 1 if the data transfer specified by the URB is completely finished,
  396. * 0 otherwise
  397. */
  398. static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
  399. struct dwc2_host_chan *chan, int chnum,
  400. struct dwc2_hcd_urb *urb,
  401. struct dwc2_qtd *qtd)
  402. {
  403. u32 hctsiz;
  404. int xfer_done = 0;
  405. int short_read = 0;
  406. int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  407. DWC2_HC_XFER_COMPLETE,
  408. &short_read);
  409. if (urb->actual_length + xfer_length > urb->length) {
  410. dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
  411. xfer_length = urb->length - urb->actual_length;
  412. }
  413. /* Non DWORD-aligned buffer case handling */
  414. if (chan->align_buf && xfer_length && chan->ep_is_in) {
  415. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  416. dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
  417. DMA_FROM_DEVICE);
  418. memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
  419. xfer_length);
  420. dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
  421. DMA_FROM_DEVICE);
  422. }
  423. dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
  424. urb->actual_length, xfer_length);
  425. urb->actual_length += xfer_length;
  426. if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
  427. (urb->flags & URB_SEND_ZERO_PACKET) &&
  428. urb->actual_length >= urb->length &&
  429. !(urb->length % chan->max_packet)) {
  430. xfer_done = 0;
  431. } else if (short_read || urb->actual_length >= urb->length) {
  432. xfer_done = 1;
  433. urb->status = 0;
  434. }
  435. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  436. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  437. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  438. dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len);
  439. dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n",
  440. (hctsiz & TSIZ_XFERSIZE_MASK) >> TSIZ_XFERSIZE_SHIFT);
  441. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length);
  442. dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length);
  443. dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read,
  444. xfer_done);
  445. return xfer_done;
  446. }
  447. /*
  448. * Save the starting data toggle for the next transfer. The data toggle is
  449. * saved in the QH for non-control transfers and it's saved in the QTD for
  450. * control transfers.
  451. */
  452. void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
  453. struct dwc2_host_chan *chan, int chnum,
  454. struct dwc2_qtd *qtd)
  455. {
  456. u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  457. u32 pid = (hctsiz & TSIZ_SC_MC_PID_MASK) >> TSIZ_SC_MC_PID_SHIFT;
  458. if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) {
  459. if (pid == TSIZ_SC_MC_PID_DATA0)
  460. chan->qh->data_toggle = DWC2_HC_PID_DATA0;
  461. else
  462. chan->qh->data_toggle = DWC2_HC_PID_DATA1;
  463. } else {
  464. if (pid == TSIZ_SC_MC_PID_DATA0)
  465. qtd->data_toggle = DWC2_HC_PID_DATA0;
  466. else
  467. qtd->data_toggle = DWC2_HC_PID_DATA1;
  468. }
  469. }
  470. /**
  471. * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
  472. * the transfer is stopped for any reason. The fields of the current entry in
  473. * the frame descriptor array are set based on the transfer state and the input
  474. * halt_status. Completes the Isochronous URB if all the URB frames have been
  475. * completed.
  476. *
  477. * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
  478. * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
  479. */
  480. static enum dwc2_halt_status dwc2_update_isoc_urb_state(
  481. struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  482. int chnum, struct dwc2_qtd *qtd,
  483. enum dwc2_halt_status halt_status)
  484. {
  485. struct dwc2_hcd_iso_packet_desc *frame_desc;
  486. struct dwc2_hcd_urb *urb = qtd->urb;
  487. if (!urb)
  488. return DWC2_HC_XFER_NO_HALT_STATUS;
  489. frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  490. switch (halt_status) {
  491. case DWC2_HC_XFER_COMPLETE:
  492. frame_desc->status = 0;
  493. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  494. chan, chnum, qtd, halt_status, NULL);
  495. /* Non DWORD-aligned buffer case handling */
  496. if (chan->align_buf && frame_desc->actual_length &&
  497. chan->ep_is_in) {
  498. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  499. __func__);
  500. dma_sync_single_for_cpu(hsotg->dev, urb->dma,
  501. urb->length, DMA_FROM_DEVICE);
  502. memcpy(urb->buf + frame_desc->offset +
  503. qtd->isoc_split_offset, chan->qh->dw_align_buf,
  504. frame_desc->actual_length);
  505. dma_sync_single_for_device(hsotg->dev, urb->dma,
  506. urb->length,
  507. DMA_FROM_DEVICE);
  508. }
  509. break;
  510. case DWC2_HC_XFER_FRAME_OVERRUN:
  511. urb->error_count++;
  512. if (chan->ep_is_in)
  513. frame_desc->status = -ENOSR;
  514. else
  515. frame_desc->status = -ECOMM;
  516. frame_desc->actual_length = 0;
  517. break;
  518. case DWC2_HC_XFER_BABBLE_ERR:
  519. urb->error_count++;
  520. frame_desc->status = -EOVERFLOW;
  521. /* Don't need to update actual_length in this case */
  522. break;
  523. case DWC2_HC_XFER_XACT_ERR:
  524. urb->error_count++;
  525. frame_desc->status = -EPROTO;
  526. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  527. chan, chnum, qtd, halt_status, NULL);
  528. /* Non DWORD-aligned buffer case handling */
  529. if (chan->align_buf && frame_desc->actual_length &&
  530. chan->ep_is_in) {
  531. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  532. __func__);
  533. dma_sync_single_for_cpu(hsotg->dev, urb->dma,
  534. urb->length, DMA_FROM_DEVICE);
  535. memcpy(urb->buf + frame_desc->offset +
  536. qtd->isoc_split_offset, chan->qh->dw_align_buf,
  537. frame_desc->actual_length);
  538. dma_sync_single_for_device(hsotg->dev, urb->dma,
  539. urb->length,
  540. DMA_FROM_DEVICE);
  541. }
  542. /* Skip whole frame */
  543. if (chan->qh->do_split &&
  544. chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
  545. hsotg->core_params->dma_enable > 0) {
  546. qtd->complete_split = 0;
  547. qtd->isoc_split_offset = 0;
  548. }
  549. break;
  550. default:
  551. dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
  552. halt_status);
  553. break;
  554. }
  555. if (++qtd->isoc_frame_index == urb->packet_count) {
  556. /*
  557. * urb->status is not used for isoc transfers. The individual
  558. * frame_desc statuses are used instead.
  559. */
  560. dwc2_host_complete(hsotg, qtd, 0);
  561. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  562. } else {
  563. halt_status = DWC2_HC_XFER_COMPLETE;
  564. }
  565. return halt_status;
  566. }
  567. /*
  568. * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  569. * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  570. * still linked to the QH, the QH is added to the end of the inactive
  571. * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  572. * schedule if no more QTDs are linked to the QH.
  573. */
  574. static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
  575. int free_qtd)
  576. {
  577. int continue_split = 0;
  578. struct dwc2_qtd *qtd;
  579. if (dbg_qh(qh))
  580. dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__,
  581. hsotg, qh, free_qtd);
  582. if (list_empty(&qh->qtd_list)) {
  583. dev_dbg(hsotg->dev, "## QTD list empty ##\n");
  584. goto no_qtd;
  585. }
  586. qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
  587. if (qtd->complete_split)
  588. continue_split = 1;
  589. else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
  590. qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
  591. continue_split = 1;
  592. if (free_qtd) {
  593. dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
  594. continue_split = 0;
  595. }
  596. no_qtd:
  597. if (qh->channel)
  598. qh->channel->align_buf = 0;
  599. qh->channel = NULL;
  600. dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
  601. }
  602. /**
  603. * dwc2_release_channel() - Releases a host channel for use by other transfers
  604. *
  605. * @hsotg: The HCD state structure
  606. * @chan: The host channel to release
  607. * @qtd: The QTD associated with the host channel. This QTD may be
  608. * freed if the transfer is complete or an error has occurred.
  609. * @halt_status: Reason the channel is being released. This status
  610. * determines the actions taken by this function.
  611. *
  612. * Also attempts to select and queue more transactions since at least one host
  613. * channel is available.
  614. */
  615. static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
  616. struct dwc2_host_chan *chan,
  617. struct dwc2_qtd *qtd,
  618. enum dwc2_halt_status halt_status)
  619. {
  620. enum dwc2_transaction_type tr_type;
  621. u32 haintmsk;
  622. int free_qtd = 0;
  623. if (dbg_hc(chan))
  624. dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n",
  625. __func__, chan->hc_num, halt_status);
  626. switch (halt_status) {
  627. case DWC2_HC_XFER_URB_COMPLETE:
  628. free_qtd = 1;
  629. break;
  630. case DWC2_HC_XFER_AHB_ERR:
  631. case DWC2_HC_XFER_STALL:
  632. case DWC2_HC_XFER_BABBLE_ERR:
  633. free_qtd = 1;
  634. break;
  635. case DWC2_HC_XFER_XACT_ERR:
  636. if (qtd && qtd->error_count >= 3) {
  637. dev_vdbg(hsotg->dev,
  638. " Complete URB with transaction error\n");
  639. free_qtd = 1;
  640. dwc2_host_complete(hsotg, qtd, -EPROTO);
  641. }
  642. break;
  643. case DWC2_HC_XFER_URB_DEQUEUE:
  644. /*
  645. * The QTD has already been removed and the QH has been
  646. * deactivated. Don't want to do anything except release the
  647. * host channel and try to queue more transfers.
  648. */
  649. goto cleanup;
  650. case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
  651. dev_vdbg(hsotg->dev, " Complete URB with I/O error\n");
  652. free_qtd = 1;
  653. dwc2_host_complete(hsotg, qtd, -EIO);
  654. break;
  655. case DWC2_HC_XFER_NO_HALT_STATUS:
  656. default:
  657. break;
  658. }
  659. dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
  660. cleanup:
  661. /*
  662. * Release the host channel for use by other transfers. The cleanup
  663. * function clears the channel interrupt enables and conditions, so
  664. * there's no need to clear the Channel Halted interrupt separately.
  665. */
  666. if (!list_empty(&chan->hc_list_entry))
  667. list_del(&chan->hc_list_entry);
  668. dwc2_hc_cleanup(hsotg, chan);
  669. list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
  670. if (hsotg->core_params->uframe_sched > 0) {
  671. hsotg->available_host_channels++;
  672. } else {
  673. switch (chan->ep_type) {
  674. case USB_ENDPOINT_XFER_CONTROL:
  675. case USB_ENDPOINT_XFER_BULK:
  676. hsotg->non_periodic_channels--;
  677. break;
  678. default:
  679. /*
  680. * Don't release reservations for periodic channels
  681. * here. That's done when a periodic transfer is
  682. * descheduled (i.e. when the QH is removed from the
  683. * periodic schedule).
  684. */
  685. break;
  686. }
  687. }
  688. haintmsk = readl(hsotg->regs + HAINTMSK);
  689. haintmsk &= ~(1 << chan->hc_num);
  690. writel(haintmsk, hsotg->regs + HAINTMSK);
  691. /* Try to queue more transfers now that there's a free channel */
  692. tr_type = dwc2_hcd_select_transactions(hsotg);
  693. if (tr_type != DWC2_TRANSACTION_NONE)
  694. dwc2_hcd_queue_transactions(hsotg, tr_type);
  695. }
  696. /*
  697. * Halts a host channel. If the channel cannot be halted immediately because
  698. * the request queue is full, this function ensures that the FIFO empty
  699. * interrupt for the appropriate queue is enabled so that the halt request can
  700. * be queued when there is space in the request queue.
  701. *
  702. * This function may also be called in DMA mode. In that case, the channel is
  703. * simply released since the core always halts the channel automatically in
  704. * DMA mode.
  705. */
  706. static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
  707. struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
  708. enum dwc2_halt_status halt_status)
  709. {
  710. if (dbg_hc(chan))
  711. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  712. if (hsotg->core_params->dma_enable > 0) {
  713. if (dbg_hc(chan))
  714. dev_vdbg(hsotg->dev, "DMA enabled\n");
  715. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  716. return;
  717. }
  718. /* Slave mode processing */
  719. dwc2_hc_halt(hsotg, chan, halt_status);
  720. if (chan->halt_on_queue) {
  721. u32 gintmsk;
  722. dev_vdbg(hsotg->dev, "Halt on queue\n");
  723. if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  724. chan->ep_type == USB_ENDPOINT_XFER_BULK) {
  725. dev_vdbg(hsotg->dev, "control/bulk\n");
  726. /*
  727. * Make sure the Non-periodic Tx FIFO empty interrupt
  728. * is enabled so that the non-periodic schedule will
  729. * be processed
  730. */
  731. gintmsk = readl(hsotg->regs + GINTMSK);
  732. gintmsk |= GINTSTS_NPTXFEMP;
  733. writel(gintmsk, hsotg->regs + GINTMSK);
  734. } else {
  735. dev_vdbg(hsotg->dev, "isoc/intr\n");
  736. /*
  737. * Move the QH from the periodic queued schedule to
  738. * the periodic assigned schedule. This allows the
  739. * halt to be queued when the periodic schedule is
  740. * processed.
  741. */
  742. list_move(&chan->qh->qh_list_entry,
  743. &hsotg->periodic_sched_assigned);
  744. /*
  745. * Make sure the Periodic Tx FIFO Empty interrupt is
  746. * enabled so that the periodic schedule will be
  747. * processed
  748. */
  749. gintmsk = readl(hsotg->regs + GINTMSK);
  750. gintmsk |= GINTSTS_PTXFEMP;
  751. writel(gintmsk, hsotg->regs + GINTMSK);
  752. }
  753. }
  754. }
  755. /*
  756. * Performs common cleanup for non-periodic transfers after a Transfer
  757. * Complete interrupt. This function should be called after any endpoint type
  758. * specific handling is finished to release the host channel.
  759. */
  760. static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
  761. struct dwc2_host_chan *chan,
  762. int chnum, struct dwc2_qtd *qtd,
  763. enum dwc2_halt_status halt_status)
  764. {
  765. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  766. qtd->error_count = 0;
  767. if (chan->hcint & HCINTMSK_NYET) {
  768. /*
  769. * Got a NYET on the last transaction of the transfer. This
  770. * means that the endpoint should be in the PING state at the
  771. * beginning of the next transfer.
  772. */
  773. dev_vdbg(hsotg->dev, "got NYET\n");
  774. chan->qh->ping_state = 1;
  775. }
  776. /*
  777. * Always halt and release the host channel to make it available for
  778. * more transfers. There may still be more phases for a control
  779. * transfer or more data packets for a bulk transfer at this point,
  780. * but the host channel is still halted. A channel will be reassigned
  781. * to the transfer when the non-periodic schedule is processed after
  782. * the channel is released. This allows transactions to be queued
  783. * properly via dwc2_hcd_queue_transactions, which also enables the
  784. * Tx FIFO Empty interrupt if necessary.
  785. */
  786. if (chan->ep_is_in) {
  787. /*
  788. * IN transfers in Slave mode require an explicit disable to
  789. * halt the channel. (In DMA mode, this call simply releases
  790. * the channel.)
  791. */
  792. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  793. } else {
  794. /*
  795. * The channel is automatically disabled by the core for OUT
  796. * transfers in Slave mode
  797. */
  798. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  799. }
  800. }
  801. /*
  802. * Performs common cleanup for periodic transfers after a Transfer Complete
  803. * interrupt. This function should be called after any endpoint type specific
  804. * handling is finished to release the host channel.
  805. */
  806. static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
  807. struct dwc2_host_chan *chan, int chnum,
  808. struct dwc2_qtd *qtd,
  809. enum dwc2_halt_status halt_status)
  810. {
  811. u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  812. qtd->error_count = 0;
  813. if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
  814. /* Core halts channel in these cases */
  815. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  816. else
  817. /* Flush any outstanding requests from the Tx queue */
  818. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  819. }
  820. static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
  821. struct dwc2_host_chan *chan, int chnum,
  822. struct dwc2_qtd *qtd)
  823. {
  824. struct dwc2_hcd_iso_packet_desc *frame_desc;
  825. u32 len;
  826. if (!qtd->urb)
  827. return 0;
  828. frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  829. len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  830. DWC2_HC_XFER_COMPLETE, NULL);
  831. if (!len) {
  832. qtd->complete_split = 0;
  833. qtd->isoc_split_offset = 0;
  834. return 0;
  835. }
  836. frame_desc->actual_length += len;
  837. if (chan->align_buf) {
  838. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  839. dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma,
  840. qtd->urb->length, DMA_FROM_DEVICE);
  841. memcpy(qtd->urb->buf + frame_desc->offset +
  842. qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
  843. dma_sync_single_for_device(hsotg->dev, qtd->urb->dma,
  844. qtd->urb->length, DMA_FROM_DEVICE);
  845. }
  846. qtd->isoc_split_offset += len;
  847. if (frame_desc->actual_length >= frame_desc->length) {
  848. frame_desc->status = 0;
  849. qtd->isoc_frame_index++;
  850. qtd->complete_split = 0;
  851. qtd->isoc_split_offset = 0;
  852. }
  853. if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  854. dwc2_host_complete(hsotg, qtd, 0);
  855. dwc2_release_channel(hsotg, chan, qtd,
  856. DWC2_HC_XFER_URB_COMPLETE);
  857. } else {
  858. dwc2_release_channel(hsotg, chan, qtd,
  859. DWC2_HC_XFER_NO_HALT_STATUS);
  860. }
  861. return 1; /* Indicates that channel released */
  862. }
  863. /*
  864. * Handles a host channel Transfer Complete interrupt. This handler may be
  865. * called in either DMA mode or Slave mode.
  866. */
  867. static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg,
  868. struct dwc2_host_chan *chan, int chnum,
  869. struct dwc2_qtd *qtd)
  870. {
  871. struct dwc2_hcd_urb *urb = qtd->urb;
  872. enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE;
  873. int pipe_type;
  874. int urb_xfer_done;
  875. if (dbg_hc(chan))
  876. dev_vdbg(hsotg->dev,
  877. "--Host Channel %d Interrupt: Transfer Complete--\n",
  878. chnum);
  879. if (!urb)
  880. goto handle_xfercomp_done;
  881. pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
  882. if (hsotg->core_params->dma_desc_enable > 0) {
  883. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status);
  884. if (pipe_type == USB_ENDPOINT_XFER_ISOC)
  885. /* Do not disable the interrupt, just clear it */
  886. return;
  887. goto handle_xfercomp_done;
  888. }
  889. /* Handle xfer complete on CSPLIT */
  890. if (chan->qh->do_split) {
  891. if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
  892. hsotg->core_params->dma_enable > 0) {
  893. if (qtd->complete_split &&
  894. dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum,
  895. qtd))
  896. goto handle_xfercomp_done;
  897. } else {
  898. qtd->complete_split = 0;
  899. }
  900. }
  901. /* Update the QTD and URB states */
  902. switch (pipe_type) {
  903. case USB_ENDPOINT_XFER_CONTROL:
  904. switch (qtd->control_phase) {
  905. case DWC2_CONTROL_SETUP:
  906. if (urb->length > 0)
  907. qtd->control_phase = DWC2_CONTROL_DATA;
  908. else
  909. qtd->control_phase = DWC2_CONTROL_STATUS;
  910. dev_vdbg(hsotg->dev,
  911. " Control setup transaction done\n");
  912. halt_status = DWC2_HC_XFER_COMPLETE;
  913. break;
  914. case DWC2_CONTROL_DATA:
  915. urb_xfer_done = dwc2_update_urb_state(hsotg, chan,
  916. chnum, urb, qtd);
  917. if (urb_xfer_done) {
  918. qtd->control_phase = DWC2_CONTROL_STATUS;
  919. dev_vdbg(hsotg->dev,
  920. " Control data transfer done\n");
  921. } else {
  922. dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
  923. qtd);
  924. }
  925. halt_status = DWC2_HC_XFER_COMPLETE;
  926. break;
  927. case DWC2_CONTROL_STATUS:
  928. dev_vdbg(hsotg->dev, " Control transfer complete\n");
  929. if (urb->status == -EINPROGRESS)
  930. urb->status = 0;
  931. dwc2_host_complete(hsotg, qtd, urb->status);
  932. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  933. break;
  934. }
  935. dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
  936. halt_status);
  937. break;
  938. case USB_ENDPOINT_XFER_BULK:
  939. dev_vdbg(hsotg->dev, " Bulk transfer complete\n");
  940. urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
  941. qtd);
  942. if (urb_xfer_done) {
  943. dwc2_host_complete(hsotg, qtd, urb->status);
  944. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  945. } else {
  946. halt_status = DWC2_HC_XFER_COMPLETE;
  947. }
  948. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  949. dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
  950. halt_status);
  951. break;
  952. case USB_ENDPOINT_XFER_INT:
  953. dev_vdbg(hsotg->dev, " Interrupt transfer complete\n");
  954. urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
  955. qtd);
  956. /*
  957. * Interrupt URB is done on the first transfer complete
  958. * interrupt
  959. */
  960. if (urb_xfer_done) {
  961. dwc2_host_complete(hsotg, qtd, urb->status);
  962. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  963. } else {
  964. halt_status = DWC2_HC_XFER_COMPLETE;
  965. }
  966. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  967. dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
  968. halt_status);
  969. break;
  970. case USB_ENDPOINT_XFER_ISOC:
  971. if (dbg_perio())
  972. dev_vdbg(hsotg->dev, " Isochronous transfer complete\n");
  973. if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL)
  974. halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
  975. chnum, qtd, DWC2_HC_XFER_COMPLETE);
  976. dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
  977. halt_status);
  978. break;
  979. }
  980. handle_xfercomp_done:
  981. disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL);
  982. }
  983. /*
  984. * Handles a host channel STALL interrupt. This handler may be called in
  985. * either DMA mode or Slave mode.
  986. */
  987. static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg,
  988. struct dwc2_host_chan *chan, int chnum,
  989. struct dwc2_qtd *qtd)
  990. {
  991. struct dwc2_hcd_urb *urb = qtd->urb;
  992. int pipe_type;
  993. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n",
  994. chnum);
  995. if (hsotg->core_params->dma_desc_enable > 0) {
  996. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  997. DWC2_HC_XFER_STALL);
  998. goto handle_stall_done;
  999. }
  1000. if (!urb)
  1001. goto handle_stall_halt;
  1002. pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
  1003. if (pipe_type == USB_ENDPOINT_XFER_CONTROL)
  1004. dwc2_host_complete(hsotg, qtd, -EPIPE);
  1005. if (pipe_type == USB_ENDPOINT_XFER_BULK ||
  1006. pipe_type == USB_ENDPOINT_XFER_INT) {
  1007. dwc2_host_complete(hsotg, qtd, -EPIPE);
  1008. /*
  1009. * USB protocol requires resetting the data toggle for bulk
  1010. * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  1011. * setup command is issued to the endpoint. Anticipate the
  1012. * CLEAR_FEATURE command since a STALL has occurred and reset
  1013. * the data toggle now.
  1014. */
  1015. chan->qh->data_toggle = 0;
  1016. }
  1017. handle_stall_halt:
  1018. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL);
  1019. handle_stall_done:
  1020. disable_hc_int(hsotg, chnum, HCINTMSK_STALL);
  1021. }
  1022. /*
  1023. * Updates the state of the URB when a transfer has been stopped due to an
  1024. * abnormal condition before the transfer completes. Modifies the
  1025. * actual_length field of the URB to reflect the number of bytes that have
  1026. * actually been transferred via the host channel.
  1027. */
  1028. static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg,
  1029. struct dwc2_host_chan *chan, int chnum,
  1030. struct dwc2_hcd_urb *urb,
  1031. struct dwc2_qtd *qtd,
  1032. enum dwc2_halt_status halt_status)
  1033. {
  1034. u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum,
  1035. qtd, halt_status, NULL);
  1036. u32 hctsiz;
  1037. if (urb->actual_length + xfer_length > urb->length) {
  1038. dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
  1039. xfer_length = urb->length - urb->actual_length;
  1040. }
  1041. /* Non DWORD-aligned buffer case handling */
  1042. if (chan->align_buf && xfer_length && chan->ep_is_in) {
  1043. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  1044. dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
  1045. DMA_FROM_DEVICE);
  1046. memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
  1047. xfer_length);
  1048. dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
  1049. DMA_FROM_DEVICE);
  1050. }
  1051. urb->actual_length += xfer_length;
  1052. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1053. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  1054. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  1055. dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n",
  1056. chan->start_pkt_count);
  1057. dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n",
  1058. (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT);
  1059. dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet);
  1060. dev_vdbg(hsotg->dev, " bytes_transferred %d\n",
  1061. xfer_length);
  1062. dev_vdbg(hsotg->dev, " urb->actual_length %d\n",
  1063. urb->actual_length);
  1064. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n",
  1065. urb->length);
  1066. }
  1067. /*
  1068. * Handles a host channel NAK interrupt. This handler may be called in either
  1069. * DMA mode or Slave mode.
  1070. */
  1071. static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
  1072. struct dwc2_host_chan *chan, int chnum,
  1073. struct dwc2_qtd *qtd)
  1074. {
  1075. if (dbg_hc(chan))
  1076. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
  1077. chnum);
  1078. /*
  1079. * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  1080. * interrupt. Re-start the SSPLIT transfer.
  1081. */
  1082. if (chan->do_split) {
  1083. if (chan->complete_split)
  1084. qtd->error_count = 0;
  1085. qtd->complete_split = 0;
  1086. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1087. goto handle_nak_done;
  1088. }
  1089. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1090. case USB_ENDPOINT_XFER_CONTROL:
  1091. case USB_ENDPOINT_XFER_BULK:
  1092. if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
  1093. /*
  1094. * NAK interrupts are enabled on bulk/control IN
  1095. * transfers in DMA mode for the sole purpose of
  1096. * resetting the error count after a transaction error
  1097. * occurs. The core will continue transferring data.
  1098. */
  1099. qtd->error_count = 0;
  1100. break;
  1101. }
  1102. /*
  1103. * NAK interrupts normally occur during OUT transfers in DMA
  1104. * or Slave mode. For IN transfers, more requests will be
  1105. * queued as request queue space is available.
  1106. */
  1107. qtd->error_count = 0;
  1108. if (!chan->qh->ping_state) {
  1109. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1110. qtd, DWC2_HC_XFER_NAK);
  1111. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1112. if (chan->speed == USB_SPEED_HIGH)
  1113. chan->qh->ping_state = 1;
  1114. }
  1115. /*
  1116. * Halt the channel so the transfer can be re-started from
  1117. * the appropriate point or the PING protocol will
  1118. * start/continue
  1119. */
  1120. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1121. break;
  1122. case USB_ENDPOINT_XFER_INT:
  1123. qtd->error_count = 0;
  1124. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1125. break;
  1126. case USB_ENDPOINT_XFER_ISOC:
  1127. /* Should never get called for isochronous transfers */
  1128. dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
  1129. break;
  1130. }
  1131. handle_nak_done:
  1132. disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
  1133. }
  1134. /*
  1135. * Handles a host channel ACK interrupt. This interrupt is enabled when
  1136. * performing the PING protocol in Slave mode, when errors occur during
  1137. * either Slave mode or DMA mode, and during Start Split transactions.
  1138. */
  1139. static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
  1140. struct dwc2_host_chan *chan, int chnum,
  1141. struct dwc2_qtd *qtd)
  1142. {
  1143. struct dwc2_hcd_iso_packet_desc *frame_desc;
  1144. if (dbg_hc(chan))
  1145. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
  1146. chnum);
  1147. if (chan->do_split) {
  1148. /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
  1149. if (!chan->ep_is_in &&
  1150. chan->data_pid_start != DWC2_HC_PID_SETUP)
  1151. qtd->ssplit_out_xfer_count = chan->xfer_len;
  1152. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
  1153. qtd->complete_split = 1;
  1154. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1155. } else {
  1156. /* ISOC OUT */
  1157. switch (chan->xact_pos) {
  1158. case DWC2_HCSPLT_XACTPOS_ALL:
  1159. break;
  1160. case DWC2_HCSPLT_XACTPOS_END:
  1161. qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
  1162. qtd->isoc_split_offset = 0;
  1163. break;
  1164. case DWC2_HCSPLT_XACTPOS_BEGIN:
  1165. case DWC2_HCSPLT_XACTPOS_MID:
  1166. /*
  1167. * For BEGIN or MID, calculate the length for
  1168. * the next microframe to determine the correct
  1169. * SSPLIT token, either MID or END
  1170. */
  1171. frame_desc = &qtd->urb->iso_descs[
  1172. qtd->isoc_frame_index];
  1173. qtd->isoc_split_offset += 188;
  1174. if (frame_desc->length - qtd->isoc_split_offset
  1175. <= 188)
  1176. qtd->isoc_split_pos =
  1177. DWC2_HCSPLT_XACTPOS_END;
  1178. else
  1179. qtd->isoc_split_pos =
  1180. DWC2_HCSPLT_XACTPOS_MID;
  1181. break;
  1182. }
  1183. }
  1184. } else {
  1185. qtd->error_count = 0;
  1186. if (chan->qh->ping_state) {
  1187. chan->qh->ping_state = 0;
  1188. /*
  1189. * Halt the channel so the transfer can be re-started
  1190. * from the appropriate point. This only happens in
  1191. * Slave mode. In DMA mode, the ping_state is cleared
  1192. * when the transfer is started because the core
  1193. * automatically executes the PING, then the transfer.
  1194. */
  1195. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1196. }
  1197. }
  1198. /*
  1199. * If the ACK occurred when _not_ in the PING state, let the channel
  1200. * continue transferring data after clearing the error count
  1201. */
  1202. disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
  1203. }
  1204. /*
  1205. * Handles a host channel NYET interrupt. This interrupt should only occur on
  1206. * Bulk and Control OUT endpoints and for complete split transactions. If a
  1207. * NYET occurs at the same time as a Transfer Complete interrupt, it is
  1208. * handled in the xfercomp interrupt handler, not here. This handler may be
  1209. * called in either DMA mode or Slave mode.
  1210. */
  1211. static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
  1212. struct dwc2_host_chan *chan, int chnum,
  1213. struct dwc2_qtd *qtd)
  1214. {
  1215. if (dbg_hc(chan))
  1216. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
  1217. chnum);
  1218. /*
  1219. * NYET on CSPLIT
  1220. * re-do the CSPLIT immediately on non-periodic
  1221. */
  1222. if (chan->do_split && chan->complete_split) {
  1223. if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
  1224. hsotg->core_params->dma_enable > 0) {
  1225. qtd->complete_split = 0;
  1226. qtd->isoc_split_offset = 0;
  1227. qtd->isoc_frame_index++;
  1228. if (qtd->urb &&
  1229. qtd->isoc_frame_index == qtd->urb->packet_count) {
  1230. dwc2_host_complete(hsotg, qtd, 0);
  1231. dwc2_release_channel(hsotg, chan, qtd,
  1232. DWC2_HC_XFER_URB_COMPLETE);
  1233. } else {
  1234. dwc2_release_channel(hsotg, chan, qtd,
  1235. DWC2_HC_XFER_NO_HALT_STATUS);
  1236. }
  1237. goto handle_nyet_done;
  1238. }
  1239. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1240. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1241. int frnum = dwc2_hcd_get_frame_number(hsotg);
  1242. if (dwc2_full_frame_num(frnum) !=
  1243. dwc2_full_frame_num(chan->qh->sched_frame)) {
  1244. /*
  1245. * No longer in the same full speed frame.
  1246. * Treat this as a transaction error.
  1247. */
  1248. #if 0
  1249. /*
  1250. * Todo: Fix system performance so this can
  1251. * be treated as an error. Right now complete
  1252. * splits cannot be scheduled precisely enough
  1253. * due to other system activity, so this error
  1254. * occurs regularly in Slave mode.
  1255. */
  1256. qtd->error_count++;
  1257. #endif
  1258. qtd->complete_split = 0;
  1259. dwc2_halt_channel(hsotg, chan, qtd,
  1260. DWC2_HC_XFER_XACT_ERR);
  1261. /* Todo: add support for isoc release */
  1262. goto handle_nyet_done;
  1263. }
  1264. }
  1265. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1266. goto handle_nyet_done;
  1267. }
  1268. chan->qh->ping_state = 1;
  1269. qtd->error_count = 0;
  1270. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
  1271. DWC2_HC_XFER_NYET);
  1272. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1273. /*
  1274. * Halt the channel and re-start the transfer so the PING protocol
  1275. * will start
  1276. */
  1277. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1278. handle_nyet_done:
  1279. disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
  1280. }
  1281. /*
  1282. * Handles a host channel babble interrupt. This handler may be called in
  1283. * either DMA mode or Slave mode.
  1284. */
  1285. static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
  1286. struct dwc2_host_chan *chan, int chnum,
  1287. struct dwc2_qtd *qtd)
  1288. {
  1289. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
  1290. chnum);
  1291. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1292. if (hsotg->core_params->dma_desc_enable > 0) {
  1293. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1294. DWC2_HC_XFER_BABBLE_ERR);
  1295. goto disable_int;
  1296. }
  1297. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
  1298. dwc2_host_complete(hsotg, qtd, -EOVERFLOW);
  1299. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
  1300. } else {
  1301. enum dwc2_halt_status halt_status;
  1302. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1303. qtd, DWC2_HC_XFER_BABBLE_ERR);
  1304. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1305. }
  1306. disable_int:
  1307. disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
  1308. }
  1309. /*
  1310. * Handles a host channel AHB error interrupt. This handler is only called in
  1311. * DMA mode.
  1312. */
  1313. static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
  1314. struct dwc2_host_chan *chan, int chnum,
  1315. struct dwc2_qtd *qtd)
  1316. {
  1317. struct dwc2_hcd_urb *urb = qtd->urb;
  1318. char *pipetype, *speed;
  1319. u32 hcchar;
  1320. u32 hcsplt;
  1321. u32 hctsiz;
  1322. u32 hc_dma;
  1323. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
  1324. chnum);
  1325. if (!urb)
  1326. goto handle_ahberr_halt;
  1327. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1328. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1329. hcsplt = readl(hsotg->regs + HCSPLT(chnum));
  1330. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1331. hc_dma = readl(hsotg->regs + HCDMA(chnum));
  1332. dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
  1333. dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
  1334. dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
  1335. dev_err(hsotg->dev, " Device address: %d\n",
  1336. dwc2_hcd_get_dev_addr(&urb->pipe_info));
  1337. dev_err(hsotg->dev, " Endpoint: %d, %s\n",
  1338. dwc2_hcd_get_ep_num(&urb->pipe_info),
  1339. dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  1340. switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
  1341. case USB_ENDPOINT_XFER_CONTROL:
  1342. pipetype = "CONTROL";
  1343. break;
  1344. case USB_ENDPOINT_XFER_BULK:
  1345. pipetype = "BULK";
  1346. break;
  1347. case USB_ENDPOINT_XFER_INT:
  1348. pipetype = "INTERRUPT";
  1349. break;
  1350. case USB_ENDPOINT_XFER_ISOC:
  1351. pipetype = "ISOCHRONOUS";
  1352. break;
  1353. default:
  1354. pipetype = "UNKNOWN";
  1355. break;
  1356. }
  1357. dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype);
  1358. switch (chan->speed) {
  1359. case USB_SPEED_HIGH:
  1360. speed = "HIGH";
  1361. break;
  1362. case USB_SPEED_FULL:
  1363. speed = "FULL";
  1364. break;
  1365. case USB_SPEED_LOW:
  1366. speed = "LOW";
  1367. break;
  1368. default:
  1369. speed = "UNKNOWN";
  1370. break;
  1371. }
  1372. dev_err(hsotg->dev, " Speed: %s\n", speed);
  1373. dev_err(hsotg->dev, " Max packet size: %d\n",
  1374. dwc2_hcd_get_mps(&urb->pipe_info));
  1375. dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length);
  1376. dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n",
  1377. urb->buf, (unsigned long)urb->dma);
  1378. dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n",
  1379. urb->setup_packet, (unsigned long)urb->setup_dma);
  1380. dev_err(hsotg->dev, " Interval: %d\n", urb->interval);
  1381. /* Core halts the channel for Descriptor DMA mode */
  1382. if (hsotg->core_params->dma_desc_enable > 0) {
  1383. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1384. DWC2_HC_XFER_AHB_ERR);
  1385. goto handle_ahberr_done;
  1386. }
  1387. dwc2_host_complete(hsotg, qtd, -EIO);
  1388. handle_ahberr_halt:
  1389. /*
  1390. * Force a channel halt. Don't call dwc2_halt_channel because that won't
  1391. * write to the HCCHARn register in DMA mode to force the halt.
  1392. */
  1393. dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
  1394. handle_ahberr_done:
  1395. disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
  1396. }
  1397. /*
  1398. * Handles a host channel transaction error interrupt. This handler may be
  1399. * called in either DMA mode or Slave mode.
  1400. */
  1401. static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
  1402. struct dwc2_host_chan *chan, int chnum,
  1403. struct dwc2_qtd *qtd)
  1404. {
  1405. dev_dbg(hsotg->dev,
  1406. "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
  1407. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1408. if (hsotg->core_params->dma_desc_enable > 0) {
  1409. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1410. DWC2_HC_XFER_XACT_ERR);
  1411. goto handle_xacterr_done;
  1412. }
  1413. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1414. case USB_ENDPOINT_XFER_CONTROL:
  1415. case USB_ENDPOINT_XFER_BULK:
  1416. qtd->error_count++;
  1417. if (!chan->qh->ping_state) {
  1418. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1419. qtd, DWC2_HC_XFER_XACT_ERR);
  1420. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1421. if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
  1422. chan->qh->ping_state = 1;
  1423. }
  1424. /*
  1425. * Halt the channel so the transfer can be re-started from
  1426. * the appropriate point or the PING protocol will start
  1427. */
  1428. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1429. break;
  1430. case USB_ENDPOINT_XFER_INT:
  1431. qtd->error_count++;
  1432. if (chan->do_split && chan->complete_split)
  1433. qtd->complete_split = 0;
  1434. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1435. break;
  1436. case USB_ENDPOINT_XFER_ISOC:
  1437. {
  1438. enum dwc2_halt_status halt_status;
  1439. halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
  1440. chnum, qtd, DWC2_HC_XFER_XACT_ERR);
  1441. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1442. }
  1443. break;
  1444. }
  1445. handle_xacterr_done:
  1446. disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
  1447. }
  1448. /*
  1449. * Handles a host channel frame overrun interrupt. This handler may be called
  1450. * in either DMA mode or Slave mode.
  1451. */
  1452. static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
  1453. struct dwc2_host_chan *chan, int chnum,
  1454. struct dwc2_qtd *qtd)
  1455. {
  1456. enum dwc2_halt_status halt_status;
  1457. if (dbg_hc(chan))
  1458. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
  1459. chnum);
  1460. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1461. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1462. case USB_ENDPOINT_XFER_CONTROL:
  1463. case USB_ENDPOINT_XFER_BULK:
  1464. break;
  1465. case USB_ENDPOINT_XFER_INT:
  1466. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1467. break;
  1468. case USB_ENDPOINT_XFER_ISOC:
  1469. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1470. qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1471. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1472. break;
  1473. }
  1474. disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
  1475. }
  1476. /*
  1477. * Handles a host channel data toggle error interrupt. This handler may be
  1478. * called in either DMA mode or Slave mode.
  1479. */
  1480. static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
  1481. struct dwc2_host_chan *chan, int chnum,
  1482. struct dwc2_qtd *qtd)
  1483. {
  1484. dev_dbg(hsotg->dev,
  1485. "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
  1486. if (chan->ep_is_in)
  1487. qtd->error_count = 0;
  1488. else
  1489. dev_err(hsotg->dev,
  1490. "Data Toggle Error on OUT transfer, channel %d\n",
  1491. chnum);
  1492. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1493. disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
  1494. }
  1495. /*
  1496. * For debug only. It checks that a valid halt status is set and that
  1497. * HCCHARn.chdis is clear. If there's a problem, corrective action is
  1498. * taken and a warning is issued.
  1499. *
  1500. * Return: true if halt status is ok, false otherwise
  1501. */
  1502. static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
  1503. struct dwc2_host_chan *chan, int chnum,
  1504. struct dwc2_qtd *qtd)
  1505. {
  1506. #ifdef DEBUG
  1507. u32 hcchar;
  1508. u32 hctsiz;
  1509. u32 hcintmsk;
  1510. u32 hcsplt;
  1511. if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
  1512. /*
  1513. * This code is here only as a check. This condition should
  1514. * never happen. Ignore the halt if it does occur.
  1515. */
  1516. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1517. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1518. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1519. hcsplt = readl(hsotg->regs + HCSPLT(chnum));
  1520. dev_dbg(hsotg->dev,
  1521. "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
  1522. __func__);
  1523. dev_dbg(hsotg->dev,
  1524. "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
  1525. chnum, hcchar, hctsiz);
  1526. dev_dbg(hsotg->dev,
  1527. "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
  1528. chan->hcint, hcintmsk, hcsplt);
  1529. if (qtd)
  1530. dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
  1531. qtd->complete_split);
  1532. dev_warn(hsotg->dev,
  1533. "%s: no halt status, channel %d, ignoring interrupt\n",
  1534. __func__, chnum);
  1535. return false;
  1536. }
  1537. /*
  1538. * This code is here only as a check. hcchar.chdis should never be set
  1539. * when the halt interrupt occurs. Halt the channel again if it does
  1540. * occur.
  1541. */
  1542. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1543. if (hcchar & HCCHAR_CHDIS) {
  1544. dev_warn(hsotg->dev,
  1545. "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
  1546. __func__, hcchar);
  1547. chan->halt_pending = 0;
  1548. dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
  1549. return false;
  1550. }
  1551. #endif
  1552. return true;
  1553. }
  1554. /*
  1555. * Handles a host Channel Halted interrupt in DMA mode. This handler
  1556. * determines the reason the channel halted and proceeds accordingly.
  1557. */
  1558. static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
  1559. struct dwc2_host_chan *chan, int chnum,
  1560. struct dwc2_qtd *qtd)
  1561. {
  1562. u32 hcintmsk;
  1563. int out_nak_enh = 0;
  1564. if (dbg_hc(chan))
  1565. dev_vdbg(hsotg->dev,
  1566. "--Host Channel %d Interrupt: DMA Channel Halted--\n",
  1567. chnum);
  1568. /*
  1569. * For core with OUT NAK enhancement, the flow for high-speed
  1570. * CONTROL/BULK OUT is handled a little differently
  1571. */
  1572. if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_71a) {
  1573. if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
  1574. (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  1575. chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
  1576. out_nak_enh = 1;
  1577. }
  1578. }
  1579. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
  1580. (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
  1581. hsotg->core_params->dma_desc_enable <= 0)) {
  1582. if (hsotg->core_params->dma_desc_enable > 0)
  1583. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1584. chan->halt_status);
  1585. else
  1586. /*
  1587. * Just release the channel. A dequeue can happen on a
  1588. * transfer timeout. In the case of an AHB Error, the
  1589. * channel was forced to halt because there's no way to
  1590. * gracefully recover.
  1591. */
  1592. dwc2_release_channel(hsotg, chan, qtd,
  1593. chan->halt_status);
  1594. return;
  1595. }
  1596. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1597. if (chan->hcint & HCINTMSK_XFERCOMPL) {
  1598. /*
  1599. * Todo: This is here because of a possible hardware bug. Spec
  1600. * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  1601. * interrupt w/ACK bit set should occur, but I only see the
  1602. * XFERCOMP bit, even with it masked out. This is a workaround
  1603. * for that behavior. Should fix this when hardware is fixed.
  1604. */
  1605. if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
  1606. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1607. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1608. } else if (chan->hcint & HCINTMSK_STALL) {
  1609. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1610. } else if ((chan->hcint & HCINTMSK_XACTERR) &&
  1611. hsotg->core_params->dma_desc_enable <= 0) {
  1612. if (out_nak_enh) {
  1613. if (chan->hcint &
  1614. (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
  1615. dev_vdbg(hsotg->dev,
  1616. "XactErr with NYET/NAK/ACK\n");
  1617. qtd->error_count = 0;
  1618. } else {
  1619. dev_vdbg(hsotg->dev,
  1620. "XactErr without NYET/NAK/ACK\n");
  1621. }
  1622. }
  1623. /*
  1624. * Must handle xacterr before nak or ack. Could get a xacterr
  1625. * at the same time as either of these on a BULK/CONTROL OUT
  1626. * that started with a PING. The xacterr takes precedence.
  1627. */
  1628. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1629. } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
  1630. hsotg->core_params->dma_desc_enable > 0) {
  1631. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1632. } else if ((chan->hcint & HCINTMSK_AHBERR) &&
  1633. hsotg->core_params->dma_desc_enable > 0) {
  1634. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1635. } else if (chan->hcint & HCINTMSK_BBLERR) {
  1636. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1637. } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
  1638. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1639. } else if (!out_nak_enh) {
  1640. if (chan->hcint & HCINTMSK_NYET) {
  1641. /*
  1642. * Must handle nyet before nak or ack. Could get a nyet
  1643. * at the same time as either of those on a BULK/CONTROL
  1644. * OUT that started with a PING. The nyet takes
  1645. * precedence.
  1646. */
  1647. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1648. } else if ((chan->hcint & HCINTMSK_NAK) &&
  1649. !(hcintmsk & HCINTMSK_NAK)) {
  1650. /*
  1651. * If nak is not masked, it's because a non-split IN
  1652. * transfer is in an error state. In that case, the nak
  1653. * is handled by the nak interrupt handler, not here.
  1654. * Handle nak here for BULK/CONTROL OUT transfers, which
  1655. * halt on a NAK to allow rewinding the buffer pointer.
  1656. */
  1657. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1658. } else if ((chan->hcint & HCINTMSK_ACK) &&
  1659. !(hcintmsk & HCINTMSK_ACK)) {
  1660. /*
  1661. * If ack is not masked, it's because a non-split IN
  1662. * transfer is in an error state. In that case, the ack
  1663. * is handled by the ack interrupt handler, not here.
  1664. * Handle ack here for split transfers. Start splits
  1665. * halt on ACK.
  1666. */
  1667. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1668. } else {
  1669. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1670. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1671. /*
  1672. * A periodic transfer halted with no other
  1673. * channel interrupts set. Assume it was halted
  1674. * by the core because it could not be completed
  1675. * in its scheduled (micro)frame.
  1676. */
  1677. dev_dbg(hsotg->dev,
  1678. "%s: Halt channel %d (assume incomplete periodic transfer)\n",
  1679. __func__, chnum);
  1680. dwc2_halt_channel(hsotg, chan, qtd,
  1681. DWC2_HC_XFER_PERIODIC_INCOMPLETE);
  1682. } else {
  1683. dev_err(hsotg->dev,
  1684. "%s: Channel %d - ChHltd set, but reason is unknown\n",
  1685. __func__, chnum);
  1686. dev_err(hsotg->dev,
  1687. "hcint 0x%08x, intsts 0x%08x\n",
  1688. chan->hcint,
  1689. readl(hsotg->regs + GINTSTS));
  1690. goto error;
  1691. }
  1692. }
  1693. } else {
  1694. dev_info(hsotg->dev,
  1695. "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  1696. chan->hcint);
  1697. error:
  1698. /* Failthrough: use 3-strikes rule */
  1699. qtd->error_count++;
  1700. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1701. qtd, DWC2_HC_XFER_XACT_ERR);
  1702. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1703. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1704. }
  1705. }
  1706. /*
  1707. * Handles a host channel Channel Halted interrupt
  1708. *
  1709. * In slave mode, this handler is called only when the driver specifically
  1710. * requests a halt. This occurs during handling other host channel interrupts
  1711. * (e.g. nak, xacterr, stall, nyet, etc.).
  1712. *
  1713. * In DMA mode, this is the interrupt that occurs when the core has finished
  1714. * processing a transfer on a channel. Other host channel interrupts (except
  1715. * ahberr) are disabled in DMA mode.
  1716. */
  1717. static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
  1718. struct dwc2_host_chan *chan, int chnum,
  1719. struct dwc2_qtd *qtd)
  1720. {
  1721. if (dbg_hc(chan))
  1722. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
  1723. chnum);
  1724. if (hsotg->core_params->dma_enable > 0) {
  1725. dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
  1726. } else {
  1727. if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
  1728. return;
  1729. dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
  1730. }
  1731. }
  1732. /* Handles interrupt for a specific Host Channel */
  1733. static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
  1734. {
  1735. struct dwc2_qtd *qtd;
  1736. struct dwc2_host_chan *chan;
  1737. u32 hcint, hcintmsk;
  1738. chan = hsotg->hc_ptr_array[chnum];
  1739. hcint = readl(hsotg->regs + HCINT(chnum));
  1740. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1741. if (!chan) {
  1742. dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
  1743. writel(hcint, hsotg->regs + HCINT(chnum));
  1744. return;
  1745. }
  1746. if (dbg_hc(chan)) {
  1747. dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n",
  1748. chnum);
  1749. dev_vdbg(hsotg->dev,
  1750. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1751. hcint, hcintmsk, hcint & hcintmsk);
  1752. }
  1753. writel(hcint, hsotg->regs + HCINT(chnum));
  1754. chan->hcint = hcint;
  1755. hcint &= hcintmsk;
  1756. /*
  1757. * If the channel was halted due to a dequeue, the qtd list might
  1758. * be empty or at least the first entry will not be the active qtd.
  1759. * In this case, take a shortcut and just release the channel.
  1760. */
  1761. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
  1762. /*
  1763. * If the channel was halted, this should be the only
  1764. * interrupt unmasked
  1765. */
  1766. WARN_ON(hcint != HCINTMSK_CHHLTD);
  1767. if (hsotg->core_params->dma_desc_enable > 0)
  1768. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1769. chan->halt_status);
  1770. else
  1771. dwc2_release_channel(hsotg, chan, NULL,
  1772. chan->halt_status);
  1773. return;
  1774. }
  1775. if (list_empty(&chan->qh->qtd_list)) {
  1776. /*
  1777. * TODO: Will this ever happen with the
  1778. * DWC2_HC_XFER_URB_DEQUEUE handling above?
  1779. */
  1780. dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
  1781. chnum);
  1782. dev_dbg(hsotg->dev,
  1783. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1784. chan->hcint, hcintmsk, hcint);
  1785. chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
  1786. disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
  1787. chan->hcint = 0;
  1788. return;
  1789. }
  1790. qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
  1791. qtd_list_entry);
  1792. if (hsotg->core_params->dma_enable <= 0) {
  1793. if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
  1794. hcint &= ~HCINTMSK_CHHLTD;
  1795. }
  1796. if (hcint & HCINTMSK_XFERCOMPL) {
  1797. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1798. /*
  1799. * If NYET occurred at same time as Xfer Complete, the NYET is
  1800. * handled by the Xfer Complete interrupt handler. Don't want
  1801. * to call the NYET interrupt handler in this case.
  1802. */
  1803. hcint &= ~HCINTMSK_NYET;
  1804. }
  1805. if (hcint & HCINTMSK_CHHLTD)
  1806. dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
  1807. if (hcint & HCINTMSK_AHBERR)
  1808. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1809. if (hcint & HCINTMSK_STALL)
  1810. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1811. if (hcint & HCINTMSK_NAK)
  1812. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1813. if (hcint & HCINTMSK_ACK)
  1814. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1815. if (hcint & HCINTMSK_NYET)
  1816. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1817. if (hcint & HCINTMSK_XACTERR)
  1818. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1819. if (hcint & HCINTMSK_BBLERR)
  1820. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1821. if (hcint & HCINTMSK_FRMOVRUN)
  1822. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1823. if (hcint & HCINTMSK_DATATGLERR)
  1824. dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
  1825. chan->hcint = 0;
  1826. }
  1827. /*
  1828. * This interrupt indicates that one or more host channels has a pending
  1829. * interrupt. There are multiple conditions that can cause each host channel
  1830. * interrupt. This function determines which conditions have occurred for each
  1831. * host channel interrupt and handles them appropriately.
  1832. */
  1833. static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
  1834. {
  1835. u32 haint;
  1836. int i;
  1837. haint = readl(hsotg->regs + HAINT);
  1838. if (dbg_perio()) {
  1839. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  1840. dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
  1841. }
  1842. for (i = 0; i < hsotg->core_params->host_channels; i++) {
  1843. if (haint & (1 << i))
  1844. dwc2_hc_n_intr(hsotg, i);
  1845. }
  1846. }
  1847. /* This function handles interrupts for the HCD */
  1848. irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg)
  1849. {
  1850. u32 gintsts, dbg_gintsts;
  1851. irqreturn_t retval = IRQ_NONE;
  1852. if (!dwc2_is_controller_alive(hsotg)) {
  1853. dev_warn(hsotg->dev, "Controller is dead\n");
  1854. return retval;
  1855. }
  1856. spin_lock(&hsotg->lock);
  1857. /* Check if HOST Mode */
  1858. if (dwc2_is_host_mode(hsotg)) {
  1859. gintsts = dwc2_read_core_intr(hsotg);
  1860. if (!gintsts) {
  1861. spin_unlock(&hsotg->lock);
  1862. return retval;
  1863. }
  1864. retval = IRQ_HANDLED;
  1865. dbg_gintsts = gintsts;
  1866. #ifndef DEBUG_SOF
  1867. dbg_gintsts &= ~GINTSTS_SOF;
  1868. #endif
  1869. if (!dbg_perio())
  1870. dbg_gintsts &= ~(GINTSTS_HCHINT | GINTSTS_RXFLVL |
  1871. GINTSTS_PTXFEMP);
  1872. /* Only print if there are any non-suppressed interrupts left */
  1873. if (dbg_gintsts)
  1874. dev_vdbg(hsotg->dev,
  1875. "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
  1876. gintsts);
  1877. if (gintsts & GINTSTS_SOF)
  1878. dwc2_sof_intr(hsotg);
  1879. if (gintsts & GINTSTS_RXFLVL)
  1880. dwc2_rx_fifo_level_intr(hsotg);
  1881. if (gintsts & GINTSTS_NPTXFEMP)
  1882. dwc2_np_tx_fifo_empty_intr(hsotg);
  1883. if (gintsts & GINTSTS_PRTINT)
  1884. dwc2_port_intr(hsotg);
  1885. if (gintsts & GINTSTS_HCHINT)
  1886. dwc2_hc_intr(hsotg);
  1887. if (gintsts & GINTSTS_PTXFEMP)
  1888. dwc2_perio_tx_fifo_empty_intr(hsotg);
  1889. if (dbg_gintsts) {
  1890. dev_vdbg(hsotg->dev,
  1891. "DWC OTG HCD Finished Servicing Interrupts\n");
  1892. dev_vdbg(hsotg->dev,
  1893. "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
  1894. readl(hsotg->regs + GINTSTS),
  1895. readl(hsotg->regs + GINTMSK));
  1896. }
  1897. }
  1898. spin_unlock(&hsotg->lock);
  1899. return retval;
  1900. }