hcd_intr.c 66 KB

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