hcd_intr.c 66 KB

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