hcd_intr.c 63 KB

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