hcd_intr.c 65 KB

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