hcd_intr.c 65 KB

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