hcd_intr.c 64 KB

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