hcd_intr.c 65 KB

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