hcd_intr.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194
  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. dwc2_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 = dwc2_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 = dwc2_readl(hsotg->regs + HFIR);
  221. hfir &= ~HFIR_FRINT_MASK;
  222. hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
  223. HFIR_FRINT_MASK;
  224. dwc2_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 = dwc2_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. dwc2_writel(usbcfg, hsotg->regs + GUSBCFG);
  239. do_reset = 1;
  240. }
  241. hcfg = dwc2_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. dwc2_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. dwc2_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. dwc2_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 = dwc2_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. if (hsotg->lx_state != DWC2_L0)
  313. usb_hcd_resume_root_hub(hsotg->priv);
  314. hsotg->flags.b.port_connect_status_change = 1;
  315. hsotg->flags.b.port_connect_status = 1;
  316. hprt0_modify |= HPRT0_CONNDET;
  317. /*
  318. * The Hub driver asserts a reset when it sees port connect
  319. * status change flag
  320. */
  321. }
  322. /*
  323. * Port Enable Changed
  324. * Clear if detected - Set internal flag if disabled
  325. */
  326. if (hprt0 & HPRT0_ENACHG) {
  327. dev_vdbg(hsotg->dev,
  328. " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
  329. hprt0, !!(hprt0 & HPRT0_ENA));
  330. hprt0_modify |= HPRT0_ENACHG;
  331. if (hprt0 & HPRT0_ENA)
  332. dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
  333. else
  334. hsotg->flags.b.port_enable_change = 1;
  335. }
  336. /* Overcurrent Change Interrupt */
  337. if (hprt0 & HPRT0_OVRCURRCHG) {
  338. dev_vdbg(hsotg->dev,
  339. " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
  340. hprt0);
  341. hsotg->flags.b.port_over_current_change = 1;
  342. hprt0_modify |= HPRT0_OVRCURRCHG;
  343. }
  344. /* Clear Port Interrupts */
  345. dwc2_writel(hprt0_modify, hsotg->regs + HPRT0);
  346. }
  347. /*
  348. * Gets the actual length of a transfer after the transfer halts. halt_status
  349. * holds the reason for the halt.
  350. *
  351. * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
  352. * is set to 1 upon return if less than the requested number of bytes were
  353. * transferred. short_read may also be NULL on entry, in which case it remains
  354. * unchanged.
  355. */
  356. static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
  357. struct dwc2_host_chan *chan, int chnum,
  358. struct dwc2_qtd *qtd,
  359. enum dwc2_halt_status halt_status,
  360. int *short_read)
  361. {
  362. u32 hctsiz, count, length;
  363. hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  364. if (halt_status == DWC2_HC_XFER_COMPLETE) {
  365. if (chan->ep_is_in) {
  366. count = (hctsiz & TSIZ_XFERSIZE_MASK) >>
  367. TSIZ_XFERSIZE_SHIFT;
  368. length = chan->xfer_len - count;
  369. if (short_read != NULL)
  370. *short_read = (count != 0);
  371. } else if (chan->qh->do_split) {
  372. length = qtd->ssplit_out_xfer_count;
  373. } else {
  374. length = chan->xfer_len;
  375. }
  376. } else {
  377. /*
  378. * Must use the hctsiz.pktcnt field to determine how much data
  379. * has been transferred. This field reflects the number of
  380. * packets that have been transferred via the USB. This is
  381. * always an integral number of packets if the transfer was
  382. * halted before its normal completion. (Can't use the
  383. * hctsiz.xfersize field because that reflects the number of
  384. * bytes transferred via the AHB, not the USB).
  385. */
  386. count = (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT;
  387. length = (chan->start_pkt_count - count) * chan->max_packet;
  388. }
  389. return length;
  390. }
  391. /**
  392. * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
  393. * Complete interrupt on the host channel. Updates the actual_length field
  394. * of the URB based on the number of bytes transferred via the host channel.
  395. * Sets the URB status if the data transfer is finished.
  396. *
  397. * Return: 1 if the data transfer specified by the URB is completely finished,
  398. * 0 otherwise
  399. */
  400. static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
  401. struct dwc2_host_chan *chan, int chnum,
  402. struct dwc2_hcd_urb *urb,
  403. struct dwc2_qtd *qtd)
  404. {
  405. u32 hctsiz;
  406. int xfer_done = 0;
  407. int short_read = 0;
  408. int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  409. DWC2_HC_XFER_COMPLETE,
  410. &short_read);
  411. if (urb->actual_length + xfer_length > urb->length) {
  412. dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
  413. xfer_length = urb->length - urb->actual_length;
  414. }
  415. /* Non DWORD-aligned buffer case handling */
  416. if (chan->align_buf && xfer_length) {
  417. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  418. dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
  419. chan->qh->dw_align_buf_size,
  420. chan->ep_is_in ?
  421. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  422. if (chan->ep_is_in)
  423. memcpy(urb->buf + urb->actual_length,
  424. chan->qh->dw_align_buf, xfer_length);
  425. }
  426. dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
  427. urb->actual_length, xfer_length);
  428. urb->actual_length += xfer_length;
  429. if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
  430. (urb->flags & URB_SEND_ZERO_PACKET) &&
  431. urb->actual_length >= urb->length &&
  432. !(urb->length % chan->max_packet)) {
  433. xfer_done = 0;
  434. } else if (short_read || urb->actual_length >= urb->length) {
  435. xfer_done = 1;
  436. urb->status = 0;
  437. }
  438. hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  439. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  440. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  441. dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len);
  442. dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n",
  443. (hctsiz & TSIZ_XFERSIZE_MASK) >> TSIZ_XFERSIZE_SHIFT);
  444. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length);
  445. dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length);
  446. dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read,
  447. xfer_done);
  448. return xfer_done;
  449. }
  450. /*
  451. * Save the starting data toggle for the next transfer. The data toggle is
  452. * saved in the QH for non-control transfers and it's saved in the QTD for
  453. * control transfers.
  454. */
  455. void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
  456. struct dwc2_host_chan *chan, int chnum,
  457. struct dwc2_qtd *qtd)
  458. {
  459. u32 hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  460. u32 pid = (hctsiz & TSIZ_SC_MC_PID_MASK) >> TSIZ_SC_MC_PID_SHIFT;
  461. if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) {
  462. if (pid == TSIZ_SC_MC_PID_DATA0)
  463. chan->qh->data_toggle = DWC2_HC_PID_DATA0;
  464. else
  465. chan->qh->data_toggle = DWC2_HC_PID_DATA1;
  466. } else {
  467. if (pid == TSIZ_SC_MC_PID_DATA0)
  468. qtd->data_toggle = DWC2_HC_PID_DATA0;
  469. else
  470. qtd->data_toggle = DWC2_HC_PID_DATA1;
  471. }
  472. }
  473. /**
  474. * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
  475. * the transfer is stopped for any reason. The fields of the current entry in
  476. * the frame descriptor array are set based on the transfer state and the input
  477. * halt_status. Completes the Isochronous URB if all the URB frames have been
  478. * completed.
  479. *
  480. * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
  481. * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
  482. */
  483. static enum dwc2_halt_status dwc2_update_isoc_urb_state(
  484. struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  485. int chnum, struct dwc2_qtd *qtd,
  486. enum dwc2_halt_status halt_status)
  487. {
  488. struct dwc2_hcd_iso_packet_desc *frame_desc;
  489. struct dwc2_hcd_urb *urb = qtd->urb;
  490. if (!urb)
  491. return DWC2_HC_XFER_NO_HALT_STATUS;
  492. frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  493. switch (halt_status) {
  494. case DWC2_HC_XFER_COMPLETE:
  495. frame_desc->status = 0;
  496. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  497. chan, chnum, qtd, halt_status, NULL);
  498. /* Non DWORD-aligned buffer case handling */
  499. if (chan->align_buf && frame_desc->actual_length) {
  500. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  501. __func__);
  502. dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
  503. chan->qh->dw_align_buf_size,
  504. chan->ep_is_in ?
  505. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  506. if (chan->ep_is_in)
  507. memcpy(urb->buf + frame_desc->offset +
  508. qtd->isoc_split_offset,
  509. chan->qh->dw_align_buf,
  510. frame_desc->actual_length);
  511. }
  512. break;
  513. case DWC2_HC_XFER_FRAME_OVERRUN:
  514. urb->error_count++;
  515. if (chan->ep_is_in)
  516. frame_desc->status = -ENOSR;
  517. else
  518. frame_desc->status = -ECOMM;
  519. frame_desc->actual_length = 0;
  520. break;
  521. case DWC2_HC_XFER_BABBLE_ERR:
  522. urb->error_count++;
  523. frame_desc->status = -EOVERFLOW;
  524. /* Don't need to update actual_length in this case */
  525. break;
  526. case DWC2_HC_XFER_XACT_ERR:
  527. urb->error_count++;
  528. frame_desc->status = -EPROTO;
  529. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  530. chan, chnum, qtd, halt_status, NULL);
  531. /* Non DWORD-aligned buffer case handling */
  532. if (chan->align_buf && frame_desc->actual_length) {
  533. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  534. __func__);
  535. dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
  536. chan->qh->dw_align_buf_size,
  537. chan->ep_is_in ?
  538. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  539. if (chan->ep_is_in)
  540. memcpy(urb->buf + frame_desc->offset +
  541. qtd->isoc_split_offset,
  542. chan->qh->dw_align_buf,
  543. frame_desc->actual_length);
  544. }
  545. /* Skip whole frame */
  546. if (chan->qh->do_split &&
  547. chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
  548. hsotg->core_params->dma_enable > 0) {
  549. qtd->complete_split = 0;
  550. qtd->isoc_split_offset = 0;
  551. }
  552. break;
  553. default:
  554. dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
  555. halt_status);
  556. break;
  557. }
  558. if (++qtd->isoc_frame_index == urb->packet_count) {
  559. /*
  560. * urb->status is not used for isoc transfers. The individual
  561. * frame_desc statuses are used instead.
  562. */
  563. dwc2_host_complete(hsotg, qtd, 0);
  564. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  565. } else {
  566. halt_status = DWC2_HC_XFER_COMPLETE;
  567. }
  568. return halt_status;
  569. }
  570. /*
  571. * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  572. * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  573. * still linked to the QH, the QH is added to the end of the inactive
  574. * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  575. * schedule if no more QTDs are linked to the QH.
  576. */
  577. static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
  578. int free_qtd)
  579. {
  580. int continue_split = 0;
  581. struct dwc2_qtd *qtd;
  582. if (dbg_qh(qh))
  583. dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__,
  584. hsotg, qh, free_qtd);
  585. if (list_empty(&qh->qtd_list)) {
  586. dev_dbg(hsotg->dev, "## QTD list empty ##\n");
  587. goto no_qtd;
  588. }
  589. qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
  590. if (qtd->complete_split)
  591. continue_split = 1;
  592. else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
  593. qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
  594. continue_split = 1;
  595. if (free_qtd) {
  596. dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
  597. continue_split = 0;
  598. }
  599. no_qtd:
  600. if (qh->channel)
  601. qh->channel->align_buf = 0;
  602. qh->channel = NULL;
  603. dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
  604. }
  605. /**
  606. * dwc2_release_channel() - Releases a host channel for use by other transfers
  607. *
  608. * @hsotg: The HCD state structure
  609. * @chan: The host channel to release
  610. * @qtd: The QTD associated with the host channel. This QTD may be
  611. * freed if the transfer is complete or an error has occurred.
  612. * @halt_status: Reason the channel is being released. This status
  613. * determines the actions taken by this function.
  614. *
  615. * Also attempts to select and queue more transactions since at least one host
  616. * channel is available.
  617. */
  618. static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
  619. struct dwc2_host_chan *chan,
  620. struct dwc2_qtd *qtd,
  621. enum dwc2_halt_status halt_status)
  622. {
  623. enum dwc2_transaction_type tr_type;
  624. u32 haintmsk;
  625. int free_qtd = 0;
  626. if (dbg_hc(chan))
  627. dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n",
  628. __func__, chan->hc_num, halt_status);
  629. switch (halt_status) {
  630. case DWC2_HC_XFER_URB_COMPLETE:
  631. free_qtd = 1;
  632. break;
  633. case DWC2_HC_XFER_AHB_ERR:
  634. case DWC2_HC_XFER_STALL:
  635. case DWC2_HC_XFER_BABBLE_ERR:
  636. free_qtd = 1;
  637. break;
  638. case DWC2_HC_XFER_XACT_ERR:
  639. if (qtd && qtd->error_count >= 3) {
  640. dev_vdbg(hsotg->dev,
  641. " Complete URB with transaction error\n");
  642. free_qtd = 1;
  643. dwc2_host_complete(hsotg, qtd, -EPROTO);
  644. }
  645. break;
  646. case DWC2_HC_XFER_URB_DEQUEUE:
  647. /*
  648. * The QTD has already been removed and the QH has been
  649. * deactivated. Don't want to do anything except release the
  650. * host channel and try to queue more transfers.
  651. */
  652. goto cleanup;
  653. case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
  654. dev_vdbg(hsotg->dev, " Complete URB with I/O error\n");
  655. free_qtd = 1;
  656. dwc2_host_complete(hsotg, qtd, -EIO);
  657. break;
  658. case DWC2_HC_XFER_NO_HALT_STATUS:
  659. default:
  660. break;
  661. }
  662. dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
  663. cleanup:
  664. /*
  665. * Release the host channel for use by other transfers. The cleanup
  666. * function clears the channel interrupt enables and conditions, so
  667. * there's no need to clear the Channel Halted interrupt separately.
  668. */
  669. if (!list_empty(&chan->hc_list_entry))
  670. list_del(&chan->hc_list_entry);
  671. dwc2_hc_cleanup(hsotg, chan);
  672. list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
  673. if (hsotg->core_params->uframe_sched > 0) {
  674. hsotg->available_host_channels++;
  675. } else {
  676. switch (chan->ep_type) {
  677. case USB_ENDPOINT_XFER_CONTROL:
  678. case USB_ENDPOINT_XFER_BULK:
  679. hsotg->non_periodic_channels--;
  680. break;
  681. default:
  682. /*
  683. * Don't release reservations for periodic channels
  684. * here. That's done when a periodic transfer is
  685. * descheduled (i.e. when the QH is removed from the
  686. * periodic schedule).
  687. */
  688. break;
  689. }
  690. }
  691. haintmsk = dwc2_readl(hsotg->regs + HAINTMSK);
  692. haintmsk &= ~(1 << chan->hc_num);
  693. dwc2_writel(haintmsk, hsotg->regs + HAINTMSK);
  694. /* Try to queue more transfers now that there's a free channel */
  695. tr_type = dwc2_hcd_select_transactions(hsotg);
  696. if (tr_type != DWC2_TRANSACTION_NONE)
  697. dwc2_hcd_queue_transactions(hsotg, tr_type);
  698. }
  699. /*
  700. * Halts a host channel. If the channel cannot be halted immediately because
  701. * the request queue is full, this function ensures that the FIFO empty
  702. * interrupt for the appropriate queue is enabled so that the halt request can
  703. * be queued when there is space in the request queue.
  704. *
  705. * This function may also be called in DMA mode. In that case, the channel is
  706. * simply released since the core always halts the channel automatically in
  707. * DMA mode.
  708. */
  709. static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
  710. struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
  711. enum dwc2_halt_status halt_status)
  712. {
  713. if (dbg_hc(chan))
  714. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  715. if (hsotg->core_params->dma_enable > 0) {
  716. if (dbg_hc(chan))
  717. dev_vdbg(hsotg->dev, "DMA enabled\n");
  718. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  719. return;
  720. }
  721. /* Slave mode processing */
  722. dwc2_hc_halt(hsotg, chan, halt_status);
  723. if (chan->halt_on_queue) {
  724. u32 gintmsk;
  725. dev_vdbg(hsotg->dev, "Halt on queue\n");
  726. if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  727. chan->ep_type == USB_ENDPOINT_XFER_BULK) {
  728. dev_vdbg(hsotg->dev, "control/bulk\n");
  729. /*
  730. * Make sure the Non-periodic Tx FIFO empty interrupt
  731. * is enabled so that the non-periodic schedule will
  732. * be processed
  733. */
  734. gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
  735. gintmsk |= GINTSTS_NPTXFEMP;
  736. dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
  737. } else {
  738. dev_vdbg(hsotg->dev, "isoc/intr\n");
  739. /*
  740. * Move the QH from the periodic queued schedule to
  741. * the periodic assigned schedule. This allows the
  742. * halt to be queued when the periodic schedule is
  743. * processed.
  744. */
  745. list_move(&chan->qh->qh_list_entry,
  746. &hsotg->periodic_sched_assigned);
  747. /*
  748. * Make sure the Periodic Tx FIFO Empty interrupt is
  749. * enabled so that the periodic schedule will be
  750. * processed
  751. */
  752. gintmsk = dwc2_readl(hsotg->regs + GINTMSK);
  753. gintmsk |= GINTSTS_PTXFEMP;
  754. dwc2_writel(gintmsk, hsotg->regs + GINTMSK);
  755. }
  756. }
  757. }
  758. /*
  759. * Performs common cleanup for non-periodic transfers after a Transfer
  760. * Complete interrupt. This function should be called after any endpoint type
  761. * specific handling is finished to release the host channel.
  762. */
  763. static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
  764. struct dwc2_host_chan *chan,
  765. int chnum, struct dwc2_qtd *qtd,
  766. enum dwc2_halt_status halt_status)
  767. {
  768. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  769. qtd->error_count = 0;
  770. if (chan->hcint & HCINTMSK_NYET) {
  771. /*
  772. * Got a NYET on the last transaction of the transfer. This
  773. * means that the endpoint should be in the PING state at the
  774. * beginning of the next transfer.
  775. */
  776. dev_vdbg(hsotg->dev, "got NYET\n");
  777. chan->qh->ping_state = 1;
  778. }
  779. /*
  780. * Always halt and release the host channel to make it available for
  781. * more transfers. There may still be more phases for a control
  782. * transfer or more data packets for a bulk transfer at this point,
  783. * but the host channel is still halted. A channel will be reassigned
  784. * to the transfer when the non-periodic schedule is processed after
  785. * the channel is released. This allows transactions to be queued
  786. * properly via dwc2_hcd_queue_transactions, which also enables the
  787. * Tx FIFO Empty interrupt if necessary.
  788. */
  789. if (chan->ep_is_in) {
  790. /*
  791. * IN transfers in Slave mode require an explicit disable to
  792. * halt the channel. (In DMA mode, this call simply releases
  793. * the channel.)
  794. */
  795. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  796. } else {
  797. /*
  798. * The channel is automatically disabled by the core for OUT
  799. * transfers in Slave mode
  800. */
  801. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  802. }
  803. }
  804. /*
  805. * Performs common cleanup for periodic transfers after a Transfer Complete
  806. * interrupt. This function should be called after any endpoint type specific
  807. * handling is finished to release the host channel.
  808. */
  809. static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
  810. struct dwc2_host_chan *chan, int chnum,
  811. struct dwc2_qtd *qtd,
  812. enum dwc2_halt_status halt_status)
  813. {
  814. u32 hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  815. qtd->error_count = 0;
  816. if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
  817. /* Core halts channel in these cases */
  818. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  819. else
  820. /* Flush any outstanding requests from the Tx queue */
  821. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  822. }
  823. static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
  824. struct dwc2_host_chan *chan, int chnum,
  825. struct dwc2_qtd *qtd)
  826. {
  827. struct dwc2_hcd_iso_packet_desc *frame_desc;
  828. u32 len;
  829. if (!qtd->urb)
  830. return 0;
  831. frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  832. len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  833. DWC2_HC_XFER_COMPLETE, NULL);
  834. if (!len && !qtd->isoc_split_offset) {
  835. qtd->complete_split = 0;
  836. return 0;
  837. }
  838. frame_desc->actual_length += len;
  839. if (chan->align_buf) {
  840. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  841. dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
  842. chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
  843. memcpy(qtd->urb->buf + frame_desc->offset +
  844. qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
  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_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
  1045. chan->qh->dw_align_buf_size,
  1046. chan->ep_is_in ?
  1047. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  1048. if (chan->ep_is_in)
  1049. memcpy(urb->buf + urb->actual_length,
  1050. chan->qh->dw_align_buf,
  1051. xfer_length);
  1052. }
  1053. urb->actual_length += xfer_length;
  1054. hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  1055. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  1056. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  1057. dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n",
  1058. chan->start_pkt_count);
  1059. dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n",
  1060. (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT);
  1061. dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet);
  1062. dev_vdbg(hsotg->dev, " bytes_transferred %d\n",
  1063. xfer_length);
  1064. dev_vdbg(hsotg->dev, " urb->actual_length %d\n",
  1065. urb->actual_length);
  1066. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n",
  1067. urb->length);
  1068. }
  1069. /*
  1070. * Handles a host channel NAK interrupt. This handler may be called in either
  1071. * DMA mode or Slave mode.
  1072. */
  1073. static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
  1074. struct dwc2_host_chan *chan, int chnum,
  1075. struct dwc2_qtd *qtd)
  1076. {
  1077. if (!qtd) {
  1078. dev_dbg(hsotg->dev, "%s: qtd is NULL\n", __func__);
  1079. return;
  1080. }
  1081. if (!qtd->urb) {
  1082. dev_dbg(hsotg->dev, "%s: qtd->urb is NULL\n", __func__);
  1083. return;
  1084. }
  1085. if (dbg_hc(chan))
  1086. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
  1087. chnum);
  1088. /*
  1089. * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  1090. * interrupt. Re-start the SSPLIT transfer.
  1091. */
  1092. if (chan->do_split) {
  1093. if (chan->complete_split)
  1094. qtd->error_count = 0;
  1095. qtd->complete_split = 0;
  1096. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1097. goto handle_nak_done;
  1098. }
  1099. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1100. case USB_ENDPOINT_XFER_CONTROL:
  1101. case USB_ENDPOINT_XFER_BULK:
  1102. if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
  1103. /*
  1104. * NAK interrupts are enabled on bulk/control IN
  1105. * transfers in DMA mode for the sole purpose of
  1106. * resetting the error count after a transaction error
  1107. * occurs. The core will continue transferring data.
  1108. */
  1109. qtd->error_count = 0;
  1110. break;
  1111. }
  1112. /*
  1113. * NAK interrupts normally occur during OUT transfers in DMA
  1114. * or Slave mode. For IN transfers, more requests will be
  1115. * queued as request queue space is available.
  1116. */
  1117. qtd->error_count = 0;
  1118. if (!chan->qh->ping_state) {
  1119. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1120. qtd, DWC2_HC_XFER_NAK);
  1121. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1122. if (chan->speed == USB_SPEED_HIGH)
  1123. chan->qh->ping_state = 1;
  1124. }
  1125. /*
  1126. * Halt the channel so the transfer can be re-started from
  1127. * the appropriate point or the PING protocol will
  1128. * start/continue
  1129. */
  1130. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1131. break;
  1132. case USB_ENDPOINT_XFER_INT:
  1133. qtd->error_count = 0;
  1134. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1135. break;
  1136. case USB_ENDPOINT_XFER_ISOC:
  1137. /* Should never get called for isochronous transfers */
  1138. dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
  1139. break;
  1140. }
  1141. handle_nak_done:
  1142. disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
  1143. }
  1144. /*
  1145. * Handles a host channel ACK interrupt. This interrupt is enabled when
  1146. * performing the PING protocol in Slave mode, when errors occur during
  1147. * either Slave mode or DMA mode, and during Start Split transactions.
  1148. */
  1149. static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
  1150. struct dwc2_host_chan *chan, int chnum,
  1151. struct dwc2_qtd *qtd)
  1152. {
  1153. struct dwc2_hcd_iso_packet_desc *frame_desc;
  1154. if (dbg_hc(chan))
  1155. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
  1156. chnum);
  1157. if (chan->do_split) {
  1158. /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
  1159. if (!chan->ep_is_in &&
  1160. chan->data_pid_start != DWC2_HC_PID_SETUP)
  1161. qtd->ssplit_out_xfer_count = chan->xfer_len;
  1162. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
  1163. qtd->complete_split = 1;
  1164. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1165. } else {
  1166. /* ISOC OUT */
  1167. switch (chan->xact_pos) {
  1168. case DWC2_HCSPLT_XACTPOS_ALL:
  1169. break;
  1170. case DWC2_HCSPLT_XACTPOS_END:
  1171. qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
  1172. qtd->isoc_split_offset = 0;
  1173. break;
  1174. case DWC2_HCSPLT_XACTPOS_BEGIN:
  1175. case DWC2_HCSPLT_XACTPOS_MID:
  1176. /*
  1177. * For BEGIN or MID, calculate the length for
  1178. * the next microframe to determine the correct
  1179. * SSPLIT token, either MID or END
  1180. */
  1181. frame_desc = &qtd->urb->iso_descs[
  1182. qtd->isoc_frame_index];
  1183. qtd->isoc_split_offset += 188;
  1184. if (frame_desc->length - qtd->isoc_split_offset
  1185. <= 188)
  1186. qtd->isoc_split_pos =
  1187. DWC2_HCSPLT_XACTPOS_END;
  1188. else
  1189. qtd->isoc_split_pos =
  1190. DWC2_HCSPLT_XACTPOS_MID;
  1191. break;
  1192. }
  1193. }
  1194. } else {
  1195. qtd->error_count = 0;
  1196. if (chan->qh->ping_state) {
  1197. chan->qh->ping_state = 0;
  1198. /*
  1199. * Halt the channel so the transfer can be re-started
  1200. * from the appropriate point. This only happens in
  1201. * Slave mode. In DMA mode, the ping_state is cleared
  1202. * when the transfer is started because the core
  1203. * automatically executes the PING, then the transfer.
  1204. */
  1205. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1206. }
  1207. }
  1208. /*
  1209. * If the ACK occurred when _not_ in the PING state, let the channel
  1210. * continue transferring data after clearing the error count
  1211. */
  1212. disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
  1213. }
  1214. /*
  1215. * Handles a host channel NYET interrupt. This interrupt should only occur on
  1216. * Bulk and Control OUT endpoints and for complete split transactions. If a
  1217. * NYET occurs at the same time as a Transfer Complete interrupt, it is
  1218. * handled in the xfercomp interrupt handler, not here. This handler may be
  1219. * called in either DMA mode or Slave mode.
  1220. */
  1221. static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
  1222. struct dwc2_host_chan *chan, int chnum,
  1223. struct dwc2_qtd *qtd)
  1224. {
  1225. if (dbg_hc(chan))
  1226. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
  1227. chnum);
  1228. /*
  1229. * NYET on CSPLIT
  1230. * re-do the CSPLIT immediately on non-periodic
  1231. */
  1232. if (chan->do_split && chan->complete_split) {
  1233. if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
  1234. hsotg->core_params->dma_enable > 0) {
  1235. qtd->complete_split = 0;
  1236. qtd->isoc_split_offset = 0;
  1237. qtd->isoc_frame_index++;
  1238. if (qtd->urb &&
  1239. qtd->isoc_frame_index == qtd->urb->packet_count) {
  1240. dwc2_host_complete(hsotg, qtd, 0);
  1241. dwc2_release_channel(hsotg, chan, qtd,
  1242. DWC2_HC_XFER_URB_COMPLETE);
  1243. } else {
  1244. dwc2_release_channel(hsotg, chan, qtd,
  1245. DWC2_HC_XFER_NO_HALT_STATUS);
  1246. }
  1247. goto handle_nyet_done;
  1248. }
  1249. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1250. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1251. int frnum = dwc2_hcd_get_frame_number(hsotg);
  1252. if (dwc2_full_frame_num(frnum) !=
  1253. dwc2_full_frame_num(chan->qh->sched_frame)) {
  1254. /*
  1255. * No longer in the same full speed frame.
  1256. * Treat this as a transaction error.
  1257. */
  1258. #if 0
  1259. /*
  1260. * Todo: Fix system performance so this can
  1261. * be treated as an error. Right now complete
  1262. * splits cannot be scheduled precisely enough
  1263. * due to other system activity, so this error
  1264. * occurs regularly in Slave mode.
  1265. */
  1266. qtd->error_count++;
  1267. #endif
  1268. qtd->complete_split = 0;
  1269. dwc2_halt_channel(hsotg, chan, qtd,
  1270. DWC2_HC_XFER_XACT_ERR);
  1271. /* Todo: add support for isoc release */
  1272. goto handle_nyet_done;
  1273. }
  1274. }
  1275. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1276. goto handle_nyet_done;
  1277. }
  1278. chan->qh->ping_state = 1;
  1279. qtd->error_count = 0;
  1280. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
  1281. DWC2_HC_XFER_NYET);
  1282. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1283. /*
  1284. * Halt the channel and re-start the transfer so the PING protocol
  1285. * will start
  1286. */
  1287. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1288. handle_nyet_done:
  1289. disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
  1290. }
  1291. /*
  1292. * Handles a host channel babble interrupt. This handler may be called in
  1293. * either DMA mode or Slave mode.
  1294. */
  1295. static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
  1296. struct dwc2_host_chan *chan, int chnum,
  1297. struct dwc2_qtd *qtd)
  1298. {
  1299. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
  1300. chnum);
  1301. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1302. if (hsotg->core_params->dma_desc_enable > 0) {
  1303. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1304. DWC2_HC_XFER_BABBLE_ERR);
  1305. goto disable_int;
  1306. }
  1307. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
  1308. dwc2_host_complete(hsotg, qtd, -EOVERFLOW);
  1309. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
  1310. } else {
  1311. enum dwc2_halt_status halt_status;
  1312. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1313. qtd, DWC2_HC_XFER_BABBLE_ERR);
  1314. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1315. }
  1316. disable_int:
  1317. disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
  1318. }
  1319. /*
  1320. * Handles a host channel AHB error interrupt. This handler is only called in
  1321. * DMA mode.
  1322. */
  1323. static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
  1324. struct dwc2_host_chan *chan, int chnum,
  1325. struct dwc2_qtd *qtd)
  1326. {
  1327. struct dwc2_hcd_urb *urb = qtd->urb;
  1328. char *pipetype, *speed;
  1329. u32 hcchar;
  1330. u32 hcsplt;
  1331. u32 hctsiz;
  1332. u32 hc_dma;
  1333. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
  1334. chnum);
  1335. if (!urb)
  1336. goto handle_ahberr_halt;
  1337. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1338. hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum));
  1339. hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chnum));
  1340. hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  1341. hc_dma = dwc2_readl(hsotg->regs + HCDMA(chnum));
  1342. dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
  1343. dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
  1344. dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
  1345. dev_err(hsotg->dev, " Device address: %d\n",
  1346. dwc2_hcd_get_dev_addr(&urb->pipe_info));
  1347. dev_err(hsotg->dev, " Endpoint: %d, %s\n",
  1348. dwc2_hcd_get_ep_num(&urb->pipe_info),
  1349. dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  1350. switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
  1351. case USB_ENDPOINT_XFER_CONTROL:
  1352. pipetype = "CONTROL";
  1353. break;
  1354. case USB_ENDPOINT_XFER_BULK:
  1355. pipetype = "BULK";
  1356. break;
  1357. case USB_ENDPOINT_XFER_INT:
  1358. pipetype = "INTERRUPT";
  1359. break;
  1360. case USB_ENDPOINT_XFER_ISOC:
  1361. pipetype = "ISOCHRONOUS";
  1362. break;
  1363. default:
  1364. pipetype = "UNKNOWN";
  1365. break;
  1366. }
  1367. dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype);
  1368. switch (chan->speed) {
  1369. case USB_SPEED_HIGH:
  1370. speed = "HIGH";
  1371. break;
  1372. case USB_SPEED_FULL:
  1373. speed = "FULL";
  1374. break;
  1375. case USB_SPEED_LOW:
  1376. speed = "LOW";
  1377. break;
  1378. default:
  1379. speed = "UNKNOWN";
  1380. break;
  1381. }
  1382. dev_err(hsotg->dev, " Speed: %s\n", speed);
  1383. dev_err(hsotg->dev, " Max packet size: %d\n",
  1384. dwc2_hcd_get_mps(&urb->pipe_info));
  1385. dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length);
  1386. dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n",
  1387. urb->buf, (unsigned long)urb->dma);
  1388. dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n",
  1389. urb->setup_packet, (unsigned long)urb->setup_dma);
  1390. dev_err(hsotg->dev, " Interval: %d\n", urb->interval);
  1391. /* Core halts the channel for Descriptor DMA mode */
  1392. if (hsotg->core_params->dma_desc_enable > 0) {
  1393. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1394. DWC2_HC_XFER_AHB_ERR);
  1395. goto handle_ahberr_done;
  1396. }
  1397. dwc2_host_complete(hsotg, qtd, -EIO);
  1398. handle_ahberr_halt:
  1399. /*
  1400. * Force a channel halt. Don't call dwc2_halt_channel because that won't
  1401. * write to the HCCHARn register in DMA mode to force the halt.
  1402. */
  1403. dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
  1404. handle_ahberr_done:
  1405. disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
  1406. }
  1407. /*
  1408. * Handles a host channel transaction error interrupt. This handler may be
  1409. * called in either DMA mode or Slave mode.
  1410. */
  1411. static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
  1412. struct dwc2_host_chan *chan, int chnum,
  1413. struct dwc2_qtd *qtd)
  1414. {
  1415. dev_dbg(hsotg->dev,
  1416. "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
  1417. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1418. if (hsotg->core_params->dma_desc_enable > 0) {
  1419. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1420. DWC2_HC_XFER_XACT_ERR);
  1421. goto handle_xacterr_done;
  1422. }
  1423. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1424. case USB_ENDPOINT_XFER_CONTROL:
  1425. case USB_ENDPOINT_XFER_BULK:
  1426. qtd->error_count++;
  1427. if (!chan->qh->ping_state) {
  1428. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1429. qtd, DWC2_HC_XFER_XACT_ERR);
  1430. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1431. if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
  1432. chan->qh->ping_state = 1;
  1433. }
  1434. /*
  1435. * Halt the channel so the transfer can be re-started from
  1436. * the appropriate point or the PING protocol will start
  1437. */
  1438. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1439. break;
  1440. case USB_ENDPOINT_XFER_INT:
  1441. qtd->error_count++;
  1442. if (chan->do_split && chan->complete_split)
  1443. qtd->complete_split = 0;
  1444. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1445. break;
  1446. case USB_ENDPOINT_XFER_ISOC:
  1447. {
  1448. enum dwc2_halt_status halt_status;
  1449. halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
  1450. chnum, qtd, DWC2_HC_XFER_XACT_ERR);
  1451. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1452. }
  1453. break;
  1454. }
  1455. handle_xacterr_done:
  1456. disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
  1457. }
  1458. /*
  1459. * Handles a host channel frame overrun interrupt. This handler may be called
  1460. * in either DMA mode or Slave mode.
  1461. */
  1462. static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
  1463. struct dwc2_host_chan *chan, int chnum,
  1464. struct dwc2_qtd *qtd)
  1465. {
  1466. enum dwc2_halt_status halt_status;
  1467. if (dbg_hc(chan))
  1468. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
  1469. chnum);
  1470. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1471. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1472. case USB_ENDPOINT_XFER_CONTROL:
  1473. case USB_ENDPOINT_XFER_BULK:
  1474. break;
  1475. case USB_ENDPOINT_XFER_INT:
  1476. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1477. break;
  1478. case USB_ENDPOINT_XFER_ISOC:
  1479. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1480. qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1481. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1482. break;
  1483. }
  1484. disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
  1485. }
  1486. /*
  1487. * Handles a host channel data toggle error interrupt. This handler may be
  1488. * called in either DMA mode or Slave mode.
  1489. */
  1490. static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
  1491. struct dwc2_host_chan *chan, int chnum,
  1492. struct dwc2_qtd *qtd)
  1493. {
  1494. dev_dbg(hsotg->dev,
  1495. "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
  1496. if (chan->ep_is_in)
  1497. qtd->error_count = 0;
  1498. else
  1499. dev_err(hsotg->dev,
  1500. "Data Toggle Error on OUT transfer, channel %d\n",
  1501. chnum);
  1502. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1503. disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
  1504. }
  1505. /*
  1506. * For debug only. It checks that a valid halt status is set and that
  1507. * HCCHARn.chdis is clear. If there's a problem, corrective action is
  1508. * taken and a warning is issued.
  1509. *
  1510. * Return: true if halt status is ok, false otherwise
  1511. */
  1512. static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
  1513. struct dwc2_host_chan *chan, int chnum,
  1514. struct dwc2_qtd *qtd)
  1515. {
  1516. #ifdef DEBUG
  1517. u32 hcchar;
  1518. u32 hctsiz;
  1519. u32 hcintmsk;
  1520. u32 hcsplt;
  1521. if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
  1522. /*
  1523. * This code is here only as a check. This condition should
  1524. * never happen. Ignore the halt if it does occur.
  1525. */
  1526. hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum));
  1527. hctsiz = dwc2_readl(hsotg->regs + HCTSIZ(chnum));
  1528. hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum));
  1529. hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chnum));
  1530. dev_dbg(hsotg->dev,
  1531. "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
  1532. __func__);
  1533. dev_dbg(hsotg->dev,
  1534. "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
  1535. chnum, hcchar, hctsiz);
  1536. dev_dbg(hsotg->dev,
  1537. "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
  1538. chan->hcint, hcintmsk, hcsplt);
  1539. if (qtd)
  1540. dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
  1541. qtd->complete_split);
  1542. dev_warn(hsotg->dev,
  1543. "%s: no halt status, channel %d, ignoring interrupt\n",
  1544. __func__, chnum);
  1545. return false;
  1546. }
  1547. /*
  1548. * This code is here only as a check. hcchar.chdis should never be set
  1549. * when the halt interrupt occurs. Halt the channel again if it does
  1550. * occur.
  1551. */
  1552. hcchar = dwc2_readl(hsotg->regs + HCCHAR(chnum));
  1553. if (hcchar & HCCHAR_CHDIS) {
  1554. dev_warn(hsotg->dev,
  1555. "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
  1556. __func__, hcchar);
  1557. chan->halt_pending = 0;
  1558. dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
  1559. return false;
  1560. }
  1561. #endif
  1562. return true;
  1563. }
  1564. /*
  1565. * Handles a host Channel Halted interrupt in DMA mode. This handler
  1566. * determines the reason the channel halted and proceeds accordingly.
  1567. */
  1568. static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
  1569. struct dwc2_host_chan *chan, int chnum,
  1570. struct dwc2_qtd *qtd)
  1571. {
  1572. u32 hcintmsk;
  1573. int out_nak_enh = 0;
  1574. if (dbg_hc(chan))
  1575. dev_vdbg(hsotg->dev,
  1576. "--Host Channel %d Interrupt: DMA Channel Halted--\n",
  1577. chnum);
  1578. /*
  1579. * For core with OUT NAK enhancement, the flow for high-speed
  1580. * CONTROL/BULK OUT is handled a little differently
  1581. */
  1582. if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_71a) {
  1583. if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
  1584. (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  1585. chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
  1586. out_nak_enh = 1;
  1587. }
  1588. }
  1589. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
  1590. (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
  1591. hsotg->core_params->dma_desc_enable <= 0)) {
  1592. if (hsotg->core_params->dma_desc_enable > 0)
  1593. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1594. chan->halt_status);
  1595. else
  1596. /*
  1597. * Just release the channel. A dequeue can happen on a
  1598. * transfer timeout. In the case of an AHB Error, the
  1599. * channel was forced to halt because there's no way to
  1600. * gracefully recover.
  1601. */
  1602. dwc2_release_channel(hsotg, chan, qtd,
  1603. chan->halt_status);
  1604. return;
  1605. }
  1606. hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum));
  1607. if (chan->hcint & HCINTMSK_XFERCOMPL) {
  1608. /*
  1609. * Todo: This is here because of a possible hardware bug. Spec
  1610. * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  1611. * interrupt w/ACK bit set should occur, but I only see the
  1612. * XFERCOMP bit, even with it masked out. This is a workaround
  1613. * for that behavior. Should fix this when hardware is fixed.
  1614. */
  1615. if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
  1616. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1617. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1618. } else if (chan->hcint & HCINTMSK_STALL) {
  1619. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1620. } else if ((chan->hcint & HCINTMSK_XACTERR) &&
  1621. hsotg->core_params->dma_desc_enable <= 0) {
  1622. if (out_nak_enh) {
  1623. if (chan->hcint &
  1624. (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
  1625. dev_vdbg(hsotg->dev,
  1626. "XactErr with NYET/NAK/ACK\n");
  1627. qtd->error_count = 0;
  1628. } else {
  1629. dev_vdbg(hsotg->dev,
  1630. "XactErr without NYET/NAK/ACK\n");
  1631. }
  1632. }
  1633. /*
  1634. * Must handle xacterr before nak or ack. Could get a xacterr
  1635. * at the same time as either of these on a BULK/CONTROL OUT
  1636. * that started with a PING. The xacterr takes precedence.
  1637. */
  1638. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1639. } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
  1640. hsotg->core_params->dma_desc_enable > 0) {
  1641. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1642. } else if ((chan->hcint & HCINTMSK_AHBERR) &&
  1643. hsotg->core_params->dma_desc_enable > 0) {
  1644. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1645. } else if (chan->hcint & HCINTMSK_BBLERR) {
  1646. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1647. } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
  1648. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1649. } else if (!out_nak_enh) {
  1650. if (chan->hcint & HCINTMSK_NYET) {
  1651. /*
  1652. * Must handle nyet before nak or ack. Could get a nyet
  1653. * at the same time as either of those on a BULK/CONTROL
  1654. * OUT that started with a PING. The nyet takes
  1655. * precedence.
  1656. */
  1657. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1658. } else if ((chan->hcint & HCINTMSK_NAK) &&
  1659. !(hcintmsk & HCINTMSK_NAK)) {
  1660. /*
  1661. * If nak is not masked, it's because a non-split IN
  1662. * transfer is in an error state. In that case, the nak
  1663. * is handled by the nak interrupt handler, not here.
  1664. * Handle nak here for BULK/CONTROL OUT transfers, which
  1665. * halt on a NAK to allow rewinding the buffer pointer.
  1666. */
  1667. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1668. } else if ((chan->hcint & HCINTMSK_ACK) &&
  1669. !(hcintmsk & HCINTMSK_ACK)) {
  1670. /*
  1671. * If ack is not masked, it's because a non-split IN
  1672. * transfer is in an error state. In that case, the ack
  1673. * is handled by the ack interrupt handler, not here.
  1674. * Handle ack here for split transfers. Start splits
  1675. * halt on ACK.
  1676. */
  1677. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1678. } else {
  1679. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1680. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1681. /*
  1682. * A periodic transfer halted with no other
  1683. * channel interrupts set. Assume it was halted
  1684. * by the core because it could not be completed
  1685. * in its scheduled (micro)frame.
  1686. */
  1687. dev_dbg(hsotg->dev,
  1688. "%s: Halt channel %d (assume incomplete periodic transfer)\n",
  1689. __func__, chnum);
  1690. dwc2_halt_channel(hsotg, chan, qtd,
  1691. DWC2_HC_XFER_PERIODIC_INCOMPLETE);
  1692. } else {
  1693. dev_err(hsotg->dev,
  1694. "%s: Channel %d - ChHltd set, but reason is unknown\n",
  1695. __func__, chnum);
  1696. dev_err(hsotg->dev,
  1697. "hcint 0x%08x, intsts 0x%08x\n",
  1698. chan->hcint,
  1699. dwc2_readl(hsotg->regs + GINTSTS));
  1700. goto error;
  1701. }
  1702. }
  1703. } else {
  1704. dev_info(hsotg->dev,
  1705. "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  1706. chan->hcint);
  1707. error:
  1708. /* Failthrough: use 3-strikes rule */
  1709. qtd->error_count++;
  1710. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1711. qtd, DWC2_HC_XFER_XACT_ERR);
  1712. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1713. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1714. }
  1715. }
  1716. /*
  1717. * Handles a host channel Channel Halted interrupt
  1718. *
  1719. * In slave mode, this handler is called only when the driver specifically
  1720. * requests a halt. This occurs during handling other host channel interrupts
  1721. * (e.g. nak, xacterr, stall, nyet, etc.).
  1722. *
  1723. * In DMA mode, this is the interrupt that occurs when the core has finished
  1724. * processing a transfer on a channel. Other host channel interrupts (except
  1725. * ahberr) are disabled in DMA mode.
  1726. */
  1727. static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
  1728. struct dwc2_host_chan *chan, int chnum,
  1729. struct dwc2_qtd *qtd)
  1730. {
  1731. if (dbg_hc(chan))
  1732. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
  1733. chnum);
  1734. if (hsotg->core_params->dma_enable > 0) {
  1735. dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
  1736. } else {
  1737. if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
  1738. return;
  1739. dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
  1740. }
  1741. }
  1742. /*
  1743. * Check if the given qtd is still the top of the list (and thus valid).
  1744. *
  1745. * If dwc2_hcd_qtd_unlink_and_free() has been called since we grabbed
  1746. * the qtd from the top of the list, this will return false (otherwise true).
  1747. */
  1748. static bool dwc2_check_qtd_still_ok(struct dwc2_qtd *qtd, struct dwc2_qh *qh)
  1749. {
  1750. struct dwc2_qtd *cur_head;
  1751. if (qh == NULL)
  1752. return false;
  1753. cur_head = list_first_entry(&qh->qtd_list, struct dwc2_qtd,
  1754. qtd_list_entry);
  1755. return (cur_head == qtd);
  1756. }
  1757. /* Handles interrupt for a specific Host Channel */
  1758. static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
  1759. {
  1760. struct dwc2_qtd *qtd;
  1761. struct dwc2_host_chan *chan;
  1762. u32 hcint, hcintmsk;
  1763. chan = hsotg->hc_ptr_array[chnum];
  1764. hcint = dwc2_readl(hsotg->regs + HCINT(chnum));
  1765. hcintmsk = dwc2_readl(hsotg->regs + HCINTMSK(chnum));
  1766. if (!chan) {
  1767. dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
  1768. dwc2_writel(hcint, hsotg->regs + HCINT(chnum));
  1769. return;
  1770. }
  1771. if (dbg_hc(chan)) {
  1772. dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n",
  1773. chnum);
  1774. dev_vdbg(hsotg->dev,
  1775. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1776. hcint, hcintmsk, hcint & hcintmsk);
  1777. }
  1778. dwc2_writel(hcint, hsotg->regs + HCINT(chnum));
  1779. chan->hcint = hcint;
  1780. hcint &= hcintmsk;
  1781. /*
  1782. * If the channel was halted due to a dequeue, the qtd list might
  1783. * be empty or at least the first entry will not be the active qtd.
  1784. * In this case, take a shortcut and just release the channel.
  1785. */
  1786. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
  1787. /*
  1788. * If the channel was halted, this should be the only
  1789. * interrupt unmasked
  1790. */
  1791. WARN_ON(hcint != HCINTMSK_CHHLTD);
  1792. if (hsotg->core_params->dma_desc_enable > 0)
  1793. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1794. chan->halt_status);
  1795. else
  1796. dwc2_release_channel(hsotg, chan, NULL,
  1797. chan->halt_status);
  1798. return;
  1799. }
  1800. if (list_empty(&chan->qh->qtd_list)) {
  1801. /*
  1802. * TODO: Will this ever happen with the
  1803. * DWC2_HC_XFER_URB_DEQUEUE handling above?
  1804. */
  1805. dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
  1806. chnum);
  1807. dev_dbg(hsotg->dev,
  1808. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1809. chan->hcint, hcintmsk, hcint);
  1810. chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
  1811. disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
  1812. chan->hcint = 0;
  1813. return;
  1814. }
  1815. qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
  1816. qtd_list_entry);
  1817. if (hsotg->core_params->dma_enable <= 0) {
  1818. if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
  1819. hcint &= ~HCINTMSK_CHHLTD;
  1820. }
  1821. if (hcint & HCINTMSK_XFERCOMPL) {
  1822. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1823. /*
  1824. * If NYET occurred at same time as Xfer Complete, the NYET is
  1825. * handled by the Xfer Complete interrupt handler. Don't want
  1826. * to call the NYET interrupt handler in this case.
  1827. */
  1828. hcint &= ~HCINTMSK_NYET;
  1829. }
  1830. if (hcint & HCINTMSK_CHHLTD) {
  1831. dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
  1832. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1833. goto exit;
  1834. }
  1835. if (hcint & HCINTMSK_AHBERR) {
  1836. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1837. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1838. goto exit;
  1839. }
  1840. if (hcint & HCINTMSK_STALL) {
  1841. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1842. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1843. goto exit;
  1844. }
  1845. if (hcint & HCINTMSK_NAK) {
  1846. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1847. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1848. goto exit;
  1849. }
  1850. if (hcint & HCINTMSK_ACK) {
  1851. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1852. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1853. goto exit;
  1854. }
  1855. if (hcint & HCINTMSK_NYET) {
  1856. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1857. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1858. goto exit;
  1859. }
  1860. if (hcint & HCINTMSK_XACTERR) {
  1861. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1862. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1863. goto exit;
  1864. }
  1865. if (hcint & HCINTMSK_BBLERR) {
  1866. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1867. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1868. goto exit;
  1869. }
  1870. if (hcint & HCINTMSK_FRMOVRUN) {
  1871. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1872. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1873. goto exit;
  1874. }
  1875. if (hcint & HCINTMSK_DATATGLERR) {
  1876. dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
  1877. if (!dwc2_check_qtd_still_ok(qtd, chan->qh))
  1878. goto exit;
  1879. }
  1880. exit:
  1881. chan->hcint = 0;
  1882. }
  1883. /*
  1884. * This interrupt indicates that one or more host channels has a pending
  1885. * interrupt. There are multiple conditions that can cause each host channel
  1886. * interrupt. This function determines which conditions have occurred for each
  1887. * host channel interrupt and handles them appropriately.
  1888. */
  1889. static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
  1890. {
  1891. u32 haint;
  1892. int i;
  1893. haint = dwc2_readl(hsotg->regs + HAINT);
  1894. if (dbg_perio()) {
  1895. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  1896. dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
  1897. }
  1898. for (i = 0; i < hsotg->core_params->host_channels; i++) {
  1899. if (haint & (1 << i))
  1900. dwc2_hc_n_intr(hsotg, i);
  1901. }
  1902. }
  1903. /* This function handles interrupts for the HCD */
  1904. irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg)
  1905. {
  1906. u32 gintsts, dbg_gintsts;
  1907. irqreturn_t retval = IRQ_NONE;
  1908. if (!dwc2_is_controller_alive(hsotg)) {
  1909. dev_warn(hsotg->dev, "Controller is dead\n");
  1910. return retval;
  1911. }
  1912. spin_lock(&hsotg->lock);
  1913. /* Check if HOST Mode */
  1914. if (dwc2_is_host_mode(hsotg)) {
  1915. gintsts = dwc2_read_core_intr(hsotg);
  1916. if (!gintsts) {
  1917. spin_unlock(&hsotg->lock);
  1918. return retval;
  1919. }
  1920. retval = IRQ_HANDLED;
  1921. dbg_gintsts = gintsts;
  1922. #ifndef DEBUG_SOF
  1923. dbg_gintsts &= ~GINTSTS_SOF;
  1924. #endif
  1925. if (!dbg_perio())
  1926. dbg_gintsts &= ~(GINTSTS_HCHINT | GINTSTS_RXFLVL |
  1927. GINTSTS_PTXFEMP);
  1928. /* Only print if there are any non-suppressed interrupts left */
  1929. if (dbg_gintsts)
  1930. dev_vdbg(hsotg->dev,
  1931. "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
  1932. gintsts);
  1933. if (gintsts & GINTSTS_SOF)
  1934. dwc2_sof_intr(hsotg);
  1935. if (gintsts & GINTSTS_RXFLVL)
  1936. dwc2_rx_fifo_level_intr(hsotg);
  1937. if (gintsts & GINTSTS_NPTXFEMP)
  1938. dwc2_np_tx_fifo_empty_intr(hsotg);
  1939. if (gintsts & GINTSTS_PRTINT)
  1940. dwc2_port_intr(hsotg);
  1941. if (gintsts & GINTSTS_HCHINT)
  1942. dwc2_hc_intr(hsotg);
  1943. if (gintsts & GINTSTS_PTXFEMP)
  1944. dwc2_perio_tx_fifo_empty_intr(hsotg);
  1945. if (dbg_gintsts) {
  1946. dev_vdbg(hsotg->dev,
  1947. "DWC OTG HCD Finished Servicing Interrupts\n");
  1948. dev_vdbg(hsotg->dev,
  1949. "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
  1950. dwc2_readl(hsotg->regs + GINTSTS),
  1951. dwc2_readl(hsotg->regs + GINTMSK));
  1952. }
  1953. }
  1954. spin_unlock(&hsotg->lock);
  1955. return retval;
  1956. }