hcd_intr.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  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. 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 = 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 = readl(hsotg->regs + HFIR);
  221. hfir &= ~HFIR_FRINT_MASK;
  222. hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
  223. HFIR_FRINT_MASK;
  224. 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 = 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. writel(usbcfg, hsotg->regs + GUSBCFG);
  239. do_reset = 1;
  240. }
  241. hcfg = 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. 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. 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. 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 = 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. hsotg->flags.b.port_connect_status_change = 1;
  313. hsotg->flags.b.port_connect_status = 1;
  314. hprt0_modify |= HPRT0_CONNDET;
  315. /*
  316. * The Hub driver asserts a reset when it sees port connect
  317. * status change flag
  318. */
  319. }
  320. /*
  321. * Port Enable Changed
  322. * Clear if detected - Set internal flag if disabled
  323. */
  324. if (hprt0 & HPRT0_ENACHG) {
  325. dev_vdbg(hsotg->dev,
  326. " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
  327. hprt0, !!(hprt0 & HPRT0_ENA));
  328. hprt0_modify |= HPRT0_ENACHG;
  329. if (hprt0 & HPRT0_ENA)
  330. dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
  331. else
  332. hsotg->flags.b.port_enable_change = 1;
  333. }
  334. /* Overcurrent Change Interrupt */
  335. if (hprt0 & HPRT0_OVRCURRCHG) {
  336. dev_vdbg(hsotg->dev,
  337. " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
  338. hprt0);
  339. hsotg->flags.b.port_over_current_change = 1;
  340. hprt0_modify |= HPRT0_OVRCURRCHG;
  341. }
  342. /* Clear Port Interrupts */
  343. writel(hprt0_modify, hsotg->regs + HPRT0);
  344. }
  345. /*
  346. * Gets the actual length of a transfer after the transfer halts. halt_status
  347. * holds the reason for the halt.
  348. *
  349. * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
  350. * is set to 1 upon return if less than the requested number of bytes were
  351. * transferred. short_read may also be NULL on entry, in which case it remains
  352. * unchanged.
  353. */
  354. static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
  355. struct dwc2_host_chan *chan, int chnum,
  356. struct dwc2_qtd *qtd,
  357. enum dwc2_halt_status halt_status,
  358. int *short_read)
  359. {
  360. u32 hctsiz, count, length;
  361. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  362. if (halt_status == DWC2_HC_XFER_COMPLETE) {
  363. if (chan->ep_is_in) {
  364. count = (hctsiz & TSIZ_XFERSIZE_MASK) >>
  365. TSIZ_XFERSIZE_SHIFT;
  366. length = chan->xfer_len - count;
  367. if (short_read != NULL)
  368. *short_read = (count != 0);
  369. } else if (chan->qh->do_split) {
  370. length = qtd->ssplit_out_xfer_count;
  371. } else {
  372. length = chan->xfer_len;
  373. }
  374. } else {
  375. /*
  376. * Must use the hctsiz.pktcnt field to determine how much data
  377. * has been transferred. This field reflects the number of
  378. * packets that have been transferred via the USB. This is
  379. * always an integral number of packets if the transfer was
  380. * halted before its normal completion. (Can't use the
  381. * hctsiz.xfersize field because that reflects the number of
  382. * bytes transferred via the AHB, not the USB).
  383. */
  384. count = (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT;
  385. length = (chan->start_pkt_count - count) * chan->max_packet;
  386. }
  387. return length;
  388. }
  389. /**
  390. * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
  391. * Complete interrupt on the host channel. Updates the actual_length field
  392. * of the URB based on the number of bytes transferred via the host channel.
  393. * Sets the URB status if the data transfer is finished.
  394. *
  395. * Return: 1 if the data transfer specified by the URB is completely finished,
  396. * 0 otherwise
  397. */
  398. static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
  399. struct dwc2_host_chan *chan, int chnum,
  400. struct dwc2_hcd_urb *urb,
  401. struct dwc2_qtd *qtd)
  402. {
  403. u32 hctsiz;
  404. int xfer_done = 0;
  405. int short_read = 0;
  406. int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  407. DWC2_HC_XFER_COMPLETE,
  408. &short_read);
  409. if (urb->actual_length + xfer_length > urb->length) {
  410. dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
  411. xfer_length = urb->length - urb->actual_length;
  412. }
  413. /* Non DWORD-aligned buffer case handling */
  414. if (chan->align_buf && xfer_length && chan->ep_is_in) {
  415. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  416. dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
  417. DMA_FROM_DEVICE);
  418. memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
  419. xfer_length);
  420. dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
  421. DMA_FROM_DEVICE);
  422. }
  423. dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
  424. urb->actual_length, xfer_length);
  425. urb->actual_length += xfer_length;
  426. if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
  427. (urb->flags & URB_SEND_ZERO_PACKET) &&
  428. urb->actual_length >= urb->length &&
  429. !(urb->length % chan->max_packet)) {
  430. xfer_done = 0;
  431. } else if (short_read || urb->actual_length >= urb->length) {
  432. xfer_done = 1;
  433. urb->status = 0;
  434. }
  435. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  436. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  437. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  438. dev_vdbg(hsotg->dev, " chan->xfer_len %d\n", chan->xfer_len);
  439. dev_vdbg(hsotg->dev, " hctsiz.xfersize %d\n",
  440. (hctsiz & TSIZ_XFERSIZE_MASK) >> TSIZ_XFERSIZE_SHIFT);
  441. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n", urb->length);
  442. dev_vdbg(hsotg->dev, " urb->actual_length %d\n", urb->actual_length);
  443. dev_vdbg(hsotg->dev, " short_read %d, xfer_done %d\n", short_read,
  444. xfer_done);
  445. return xfer_done;
  446. }
  447. /*
  448. * Save the starting data toggle for the next transfer. The data toggle is
  449. * saved in the QH for non-control transfers and it's saved in the QTD for
  450. * control transfers.
  451. */
  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 = 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 (pid == TSIZ_SC_MC_PID_DATA0)
  460. chan->qh->data_toggle = DWC2_HC_PID_DATA0;
  461. else
  462. chan->qh->data_toggle = DWC2_HC_PID_DATA1;
  463. } else {
  464. if (pid == TSIZ_SC_MC_PID_DATA0)
  465. qtd->data_toggle = DWC2_HC_PID_DATA0;
  466. else
  467. qtd->data_toggle = DWC2_HC_PID_DATA1;
  468. }
  469. }
  470. /**
  471. * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
  472. * the transfer is stopped for any reason. The fields of the current entry in
  473. * the frame descriptor array are set based on the transfer state and the input
  474. * halt_status. Completes the Isochronous URB if all the URB frames have been
  475. * completed.
  476. *
  477. * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
  478. * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
  479. */
  480. static enum dwc2_halt_status dwc2_update_isoc_urb_state(
  481. struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
  482. int chnum, struct dwc2_qtd *qtd,
  483. enum dwc2_halt_status halt_status)
  484. {
  485. struct dwc2_hcd_iso_packet_desc *frame_desc;
  486. struct dwc2_hcd_urb *urb = qtd->urb;
  487. if (!urb)
  488. return DWC2_HC_XFER_NO_HALT_STATUS;
  489. frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  490. switch (halt_status) {
  491. case DWC2_HC_XFER_COMPLETE:
  492. frame_desc->status = 0;
  493. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  494. chan, chnum, qtd, halt_status, NULL);
  495. /* Non DWORD-aligned buffer case handling */
  496. if (chan->align_buf && frame_desc->actual_length &&
  497. chan->ep_is_in) {
  498. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  499. __func__);
  500. dma_sync_single_for_cpu(hsotg->dev, urb->dma,
  501. urb->length, DMA_FROM_DEVICE);
  502. memcpy(urb->buf + frame_desc->offset +
  503. qtd->isoc_split_offset, chan->qh->dw_align_buf,
  504. frame_desc->actual_length);
  505. dma_sync_single_for_device(hsotg->dev, urb->dma,
  506. urb->length,
  507. DMA_FROM_DEVICE);
  508. }
  509. break;
  510. case DWC2_HC_XFER_FRAME_OVERRUN:
  511. urb->error_count++;
  512. if (chan->ep_is_in)
  513. frame_desc->status = -ENOSR;
  514. else
  515. frame_desc->status = -ECOMM;
  516. frame_desc->actual_length = 0;
  517. break;
  518. case DWC2_HC_XFER_BABBLE_ERR:
  519. urb->error_count++;
  520. frame_desc->status = -EOVERFLOW;
  521. /* Don't need to update actual_length in this case */
  522. break;
  523. case DWC2_HC_XFER_XACT_ERR:
  524. urb->error_count++;
  525. frame_desc->status = -EPROTO;
  526. frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
  527. chan, chnum, qtd, halt_status, NULL);
  528. /* Non DWORD-aligned buffer case handling */
  529. if (chan->align_buf && frame_desc->actual_length &&
  530. chan->ep_is_in) {
  531. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
  532. __func__);
  533. dma_sync_single_for_cpu(hsotg->dev, urb->dma,
  534. urb->length, DMA_FROM_DEVICE);
  535. memcpy(urb->buf + frame_desc->offset +
  536. qtd->isoc_split_offset, chan->qh->dw_align_buf,
  537. frame_desc->actual_length);
  538. dma_sync_single_for_device(hsotg->dev, urb->dma,
  539. urb->length,
  540. DMA_FROM_DEVICE);
  541. }
  542. /* Skip whole frame */
  543. if (chan->qh->do_split &&
  544. chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
  545. hsotg->core_params->dma_enable > 0) {
  546. qtd->complete_split = 0;
  547. qtd->isoc_split_offset = 0;
  548. }
  549. break;
  550. default:
  551. dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
  552. halt_status);
  553. break;
  554. }
  555. if (++qtd->isoc_frame_index == urb->packet_count) {
  556. /*
  557. * urb->status is not used for isoc transfers. The individual
  558. * frame_desc statuses are used instead.
  559. */
  560. dwc2_host_complete(hsotg, qtd, 0);
  561. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  562. } else {
  563. halt_status = DWC2_HC_XFER_COMPLETE;
  564. }
  565. return halt_status;
  566. }
  567. /*
  568. * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  569. * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  570. * still linked to the QH, the QH is added to the end of the inactive
  571. * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  572. * schedule if no more QTDs are linked to the QH.
  573. */
  574. static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
  575. int free_qtd)
  576. {
  577. int continue_split = 0;
  578. struct dwc2_qtd *qtd;
  579. if (dbg_qh(qh))
  580. dev_vdbg(hsotg->dev, " %s(%p,%p,%d)\n", __func__,
  581. hsotg, qh, free_qtd);
  582. if (list_empty(&qh->qtd_list)) {
  583. dev_dbg(hsotg->dev, "## QTD list empty ##\n");
  584. goto no_qtd;
  585. }
  586. qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
  587. if (qtd->complete_split)
  588. continue_split = 1;
  589. else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
  590. qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
  591. continue_split = 1;
  592. if (free_qtd) {
  593. dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
  594. continue_split = 0;
  595. }
  596. no_qtd:
  597. if (qh->channel)
  598. qh->channel->align_buf = 0;
  599. qh->channel = NULL;
  600. dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
  601. }
  602. /**
  603. * dwc2_release_channel() - Releases a host channel for use by other transfers
  604. *
  605. * @hsotg: The HCD state structure
  606. * @chan: The host channel to release
  607. * @qtd: The QTD associated with the host channel. This QTD may be
  608. * freed if the transfer is complete or an error has occurred.
  609. * @halt_status: Reason the channel is being released. This status
  610. * determines the actions taken by this function.
  611. *
  612. * Also attempts to select and queue more transactions since at least one host
  613. * channel is available.
  614. */
  615. static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
  616. struct dwc2_host_chan *chan,
  617. struct dwc2_qtd *qtd,
  618. enum dwc2_halt_status halt_status)
  619. {
  620. enum dwc2_transaction_type tr_type;
  621. u32 haintmsk;
  622. int free_qtd = 0;
  623. if (dbg_hc(chan))
  624. dev_vdbg(hsotg->dev, " %s: channel %d, halt_status %d\n",
  625. __func__, chan->hc_num, halt_status);
  626. switch (halt_status) {
  627. case DWC2_HC_XFER_URB_COMPLETE:
  628. free_qtd = 1;
  629. break;
  630. case DWC2_HC_XFER_AHB_ERR:
  631. case DWC2_HC_XFER_STALL:
  632. case DWC2_HC_XFER_BABBLE_ERR:
  633. free_qtd = 1;
  634. break;
  635. case DWC2_HC_XFER_XACT_ERR:
  636. if (qtd && qtd->error_count >= 3) {
  637. dev_vdbg(hsotg->dev,
  638. " Complete URB with transaction error\n");
  639. free_qtd = 1;
  640. dwc2_host_complete(hsotg, qtd, -EPROTO);
  641. }
  642. break;
  643. case DWC2_HC_XFER_URB_DEQUEUE:
  644. /*
  645. * The QTD has already been removed and the QH has been
  646. * deactivated. Don't want to do anything except release the
  647. * host channel and try to queue more transfers.
  648. */
  649. goto cleanup;
  650. case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
  651. dev_vdbg(hsotg->dev, " Complete URB with I/O error\n");
  652. free_qtd = 1;
  653. dwc2_host_complete(hsotg, qtd, -EIO);
  654. break;
  655. case DWC2_HC_XFER_NO_HALT_STATUS:
  656. default:
  657. break;
  658. }
  659. dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
  660. cleanup:
  661. /*
  662. * Release the host channel for use by other transfers. The cleanup
  663. * function clears the channel interrupt enables and conditions, so
  664. * there's no need to clear the Channel Halted interrupt separately.
  665. */
  666. if (!list_empty(&chan->hc_list_entry))
  667. list_del(&chan->hc_list_entry);
  668. dwc2_hc_cleanup(hsotg, chan);
  669. list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
  670. if (hsotg->core_params->uframe_sched > 0) {
  671. hsotg->available_host_channels++;
  672. } else {
  673. switch (chan->ep_type) {
  674. case USB_ENDPOINT_XFER_CONTROL:
  675. case USB_ENDPOINT_XFER_BULK:
  676. hsotg->non_periodic_channels--;
  677. break;
  678. default:
  679. /*
  680. * Don't release reservations for periodic channels
  681. * here. That's done when a periodic transfer is
  682. * descheduled (i.e. when the QH is removed from the
  683. * periodic schedule).
  684. */
  685. break;
  686. }
  687. }
  688. haintmsk = readl(hsotg->regs + HAINTMSK);
  689. haintmsk &= ~(1 << chan->hc_num);
  690. writel(haintmsk, hsotg->regs + HAINTMSK);
  691. /* Try to queue more transfers now that there's a free channel */
  692. tr_type = dwc2_hcd_select_transactions(hsotg);
  693. if (tr_type != DWC2_TRANSACTION_NONE)
  694. dwc2_hcd_queue_transactions(hsotg, tr_type);
  695. }
  696. /*
  697. * Halts a host channel. If the channel cannot be halted immediately because
  698. * the request queue is full, this function ensures that the FIFO empty
  699. * interrupt for the appropriate queue is enabled so that the halt request can
  700. * be queued when there is space in the request queue.
  701. *
  702. * This function may also be called in DMA mode. In that case, the channel is
  703. * simply released since the core always halts the channel automatically in
  704. * DMA mode.
  705. */
  706. static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
  707. struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
  708. enum dwc2_halt_status halt_status)
  709. {
  710. if (dbg_hc(chan))
  711. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  712. if (hsotg->core_params->dma_enable > 0) {
  713. if (dbg_hc(chan))
  714. dev_vdbg(hsotg->dev, "DMA enabled\n");
  715. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  716. return;
  717. }
  718. /* Slave mode processing */
  719. dwc2_hc_halt(hsotg, chan, halt_status);
  720. if (chan->halt_on_queue) {
  721. u32 gintmsk;
  722. dev_vdbg(hsotg->dev, "Halt on queue\n");
  723. if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  724. chan->ep_type == USB_ENDPOINT_XFER_BULK) {
  725. dev_vdbg(hsotg->dev, "control/bulk\n");
  726. /*
  727. * Make sure the Non-periodic Tx FIFO empty interrupt
  728. * is enabled so that the non-periodic schedule will
  729. * be processed
  730. */
  731. gintmsk = readl(hsotg->regs + GINTMSK);
  732. gintmsk |= GINTSTS_NPTXFEMP;
  733. writel(gintmsk, hsotg->regs + GINTMSK);
  734. } else {
  735. dev_vdbg(hsotg->dev, "isoc/intr\n");
  736. /*
  737. * Move the QH from the periodic queued schedule to
  738. * the periodic assigned schedule. This allows the
  739. * halt to be queued when the periodic schedule is
  740. * processed.
  741. */
  742. list_move(&chan->qh->qh_list_entry,
  743. &hsotg->periodic_sched_assigned);
  744. /*
  745. * Make sure the Periodic Tx FIFO Empty interrupt is
  746. * enabled so that the periodic schedule will be
  747. * processed
  748. */
  749. gintmsk = readl(hsotg->regs + GINTMSK);
  750. gintmsk |= GINTSTS_PTXFEMP;
  751. writel(gintmsk, hsotg->regs + GINTMSK);
  752. }
  753. }
  754. }
  755. /*
  756. * Performs common cleanup for non-periodic transfers after a Transfer
  757. * Complete interrupt. This function should be called after any endpoint type
  758. * specific handling is finished to release the host channel.
  759. */
  760. static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
  761. struct dwc2_host_chan *chan,
  762. int chnum, struct dwc2_qtd *qtd,
  763. enum dwc2_halt_status halt_status)
  764. {
  765. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  766. qtd->error_count = 0;
  767. if (chan->hcint & HCINTMSK_NYET) {
  768. /*
  769. * Got a NYET on the last transaction of the transfer. This
  770. * means that the endpoint should be in the PING state at the
  771. * beginning of the next transfer.
  772. */
  773. dev_vdbg(hsotg->dev, "got NYET\n");
  774. chan->qh->ping_state = 1;
  775. }
  776. /*
  777. * Always halt and release the host channel to make it available for
  778. * more transfers. There may still be more phases for a control
  779. * transfer or more data packets for a bulk transfer at this point,
  780. * but the host channel is still halted. A channel will be reassigned
  781. * to the transfer when the non-periodic schedule is processed after
  782. * the channel is released. This allows transactions to be queued
  783. * properly via dwc2_hcd_queue_transactions, which also enables the
  784. * Tx FIFO Empty interrupt if necessary.
  785. */
  786. if (chan->ep_is_in) {
  787. /*
  788. * IN transfers in Slave mode require an explicit disable to
  789. * halt the channel. (In DMA mode, this call simply releases
  790. * the channel.)
  791. */
  792. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  793. } else {
  794. /*
  795. * The channel is automatically disabled by the core for OUT
  796. * transfers in Slave mode
  797. */
  798. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  799. }
  800. }
  801. /*
  802. * Performs common cleanup for periodic transfers after a Transfer Complete
  803. * interrupt. This function should be called after any endpoint type specific
  804. * handling is finished to release the host channel.
  805. */
  806. static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
  807. struct dwc2_host_chan *chan, int chnum,
  808. struct dwc2_qtd *qtd,
  809. enum dwc2_halt_status halt_status)
  810. {
  811. u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  812. qtd->error_count = 0;
  813. if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
  814. /* Core halts channel in these cases */
  815. dwc2_release_channel(hsotg, chan, qtd, halt_status);
  816. else
  817. /* Flush any outstanding requests from the Tx queue */
  818. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  819. }
  820. static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
  821. struct dwc2_host_chan *chan, int chnum,
  822. struct dwc2_qtd *qtd)
  823. {
  824. struct dwc2_hcd_iso_packet_desc *frame_desc;
  825. u32 len;
  826. if (!qtd->urb)
  827. return 0;
  828. frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  829. len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
  830. DWC2_HC_XFER_COMPLETE, NULL);
  831. if (!len) {
  832. qtd->complete_split = 0;
  833. qtd->isoc_split_offset = 0;
  834. return 0;
  835. }
  836. frame_desc->actual_length += len;
  837. if (chan->align_buf) {
  838. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  839. dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma,
  840. qtd->urb->length, DMA_FROM_DEVICE);
  841. memcpy(qtd->urb->buf + frame_desc->offset +
  842. qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
  843. dma_sync_single_for_device(hsotg->dev, qtd->urb->dma,
  844. qtd->urb->length, DMA_FROM_DEVICE);
  845. }
  846. qtd->isoc_split_offset += len;
  847. if (frame_desc->actual_length >= frame_desc->length) {
  848. frame_desc->status = 0;
  849. qtd->isoc_frame_index++;
  850. qtd->complete_split = 0;
  851. qtd->isoc_split_offset = 0;
  852. }
  853. if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  854. dwc2_host_complete(hsotg, qtd, 0);
  855. dwc2_release_channel(hsotg, chan, qtd,
  856. DWC2_HC_XFER_URB_COMPLETE);
  857. } else {
  858. dwc2_release_channel(hsotg, chan, qtd,
  859. DWC2_HC_XFER_NO_HALT_STATUS);
  860. }
  861. return 1; /* Indicates that channel released */
  862. }
  863. /*
  864. * Handles a host channel Transfer Complete interrupt. This handler may be
  865. * called in either DMA mode or Slave mode.
  866. */
  867. static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg,
  868. struct dwc2_host_chan *chan, int chnum,
  869. struct dwc2_qtd *qtd)
  870. {
  871. struct dwc2_hcd_urb *urb = qtd->urb;
  872. enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE;
  873. int pipe_type;
  874. int urb_xfer_done;
  875. if (dbg_hc(chan))
  876. dev_vdbg(hsotg->dev,
  877. "--Host Channel %d Interrupt: Transfer Complete--\n",
  878. chnum);
  879. if (!urb)
  880. goto handle_xfercomp_done;
  881. pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
  882. if (hsotg->core_params->dma_desc_enable > 0) {
  883. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status);
  884. if (pipe_type == USB_ENDPOINT_XFER_ISOC)
  885. /* Do not disable the interrupt, just clear it */
  886. return;
  887. goto handle_xfercomp_done;
  888. }
  889. /* Handle xfer complete on CSPLIT */
  890. if (chan->qh->do_split) {
  891. if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
  892. hsotg->core_params->dma_enable > 0) {
  893. if (qtd->complete_split &&
  894. dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum,
  895. qtd))
  896. goto handle_xfercomp_done;
  897. } else {
  898. qtd->complete_split = 0;
  899. }
  900. }
  901. /* Update the QTD and URB states */
  902. switch (pipe_type) {
  903. case USB_ENDPOINT_XFER_CONTROL:
  904. switch (qtd->control_phase) {
  905. case DWC2_CONTROL_SETUP:
  906. if (urb->length > 0)
  907. qtd->control_phase = DWC2_CONTROL_DATA;
  908. else
  909. qtd->control_phase = DWC2_CONTROL_STATUS;
  910. dev_vdbg(hsotg->dev,
  911. " Control setup transaction done\n");
  912. halt_status = DWC2_HC_XFER_COMPLETE;
  913. break;
  914. case DWC2_CONTROL_DATA:
  915. urb_xfer_done = dwc2_update_urb_state(hsotg, chan,
  916. chnum, urb, qtd);
  917. if (urb_xfer_done) {
  918. qtd->control_phase = DWC2_CONTROL_STATUS;
  919. dev_vdbg(hsotg->dev,
  920. " Control data transfer done\n");
  921. } else {
  922. dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
  923. qtd);
  924. }
  925. halt_status = DWC2_HC_XFER_COMPLETE;
  926. break;
  927. case DWC2_CONTROL_STATUS:
  928. dev_vdbg(hsotg->dev, " Control transfer complete\n");
  929. if (urb->status == -EINPROGRESS)
  930. urb->status = 0;
  931. dwc2_host_complete(hsotg, qtd, urb->status);
  932. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  933. break;
  934. }
  935. dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
  936. halt_status);
  937. break;
  938. case USB_ENDPOINT_XFER_BULK:
  939. dev_vdbg(hsotg->dev, " Bulk transfer complete\n");
  940. urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
  941. qtd);
  942. if (urb_xfer_done) {
  943. dwc2_host_complete(hsotg, qtd, urb->status);
  944. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  945. } else {
  946. halt_status = DWC2_HC_XFER_COMPLETE;
  947. }
  948. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  949. dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
  950. halt_status);
  951. break;
  952. case USB_ENDPOINT_XFER_INT:
  953. dev_vdbg(hsotg->dev, " Interrupt transfer complete\n");
  954. urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
  955. qtd);
  956. /*
  957. * Interrupt URB is done on the first transfer complete
  958. * interrupt
  959. */
  960. if (urb_xfer_done) {
  961. dwc2_host_complete(hsotg, qtd, urb->status);
  962. halt_status = DWC2_HC_XFER_URB_COMPLETE;
  963. } else {
  964. halt_status = DWC2_HC_XFER_COMPLETE;
  965. }
  966. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  967. dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
  968. halt_status);
  969. break;
  970. case USB_ENDPOINT_XFER_ISOC:
  971. if (dbg_perio())
  972. dev_vdbg(hsotg->dev, " Isochronous transfer complete\n");
  973. if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL)
  974. halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
  975. chnum, qtd, DWC2_HC_XFER_COMPLETE);
  976. dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
  977. halt_status);
  978. break;
  979. }
  980. handle_xfercomp_done:
  981. disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL);
  982. }
  983. /*
  984. * Handles a host channel STALL interrupt. This handler may be called in
  985. * either DMA mode or Slave mode.
  986. */
  987. static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg,
  988. struct dwc2_host_chan *chan, int chnum,
  989. struct dwc2_qtd *qtd)
  990. {
  991. struct dwc2_hcd_urb *urb = qtd->urb;
  992. int pipe_type;
  993. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n",
  994. chnum);
  995. if (hsotg->core_params->dma_desc_enable > 0) {
  996. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  997. DWC2_HC_XFER_STALL);
  998. goto handle_stall_done;
  999. }
  1000. if (!urb)
  1001. goto handle_stall_halt;
  1002. pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
  1003. if (pipe_type == USB_ENDPOINT_XFER_CONTROL)
  1004. dwc2_host_complete(hsotg, qtd, -EPIPE);
  1005. if (pipe_type == USB_ENDPOINT_XFER_BULK ||
  1006. pipe_type == USB_ENDPOINT_XFER_INT) {
  1007. dwc2_host_complete(hsotg, qtd, -EPIPE);
  1008. /*
  1009. * USB protocol requires resetting the data toggle for bulk
  1010. * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  1011. * setup command is issued to the endpoint. Anticipate the
  1012. * CLEAR_FEATURE command since a STALL has occurred and reset
  1013. * the data toggle now.
  1014. */
  1015. chan->qh->data_toggle = 0;
  1016. }
  1017. handle_stall_halt:
  1018. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL);
  1019. handle_stall_done:
  1020. disable_hc_int(hsotg, chnum, HCINTMSK_STALL);
  1021. }
  1022. /*
  1023. * Updates the state of the URB when a transfer has been stopped due to an
  1024. * abnormal condition before the transfer completes. Modifies the
  1025. * actual_length field of the URB to reflect the number of bytes that have
  1026. * actually been transferred via the host channel.
  1027. */
  1028. static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg,
  1029. struct dwc2_host_chan *chan, int chnum,
  1030. struct dwc2_hcd_urb *urb,
  1031. struct dwc2_qtd *qtd,
  1032. enum dwc2_halt_status halt_status)
  1033. {
  1034. u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum,
  1035. qtd, halt_status, NULL);
  1036. u32 hctsiz;
  1037. if (urb->actual_length + xfer_length > urb->length) {
  1038. dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
  1039. xfer_length = urb->length - urb->actual_length;
  1040. }
  1041. /* Non DWORD-aligned buffer case handling */
  1042. if (chan->align_buf && xfer_length && chan->ep_is_in) {
  1043. dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
  1044. dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
  1045. DMA_FROM_DEVICE);
  1046. memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
  1047. xfer_length);
  1048. dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
  1049. DMA_FROM_DEVICE);
  1050. }
  1051. urb->actual_length += xfer_length;
  1052. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1053. dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
  1054. __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
  1055. dev_vdbg(hsotg->dev, " chan->start_pkt_count %d\n",
  1056. chan->start_pkt_count);
  1057. dev_vdbg(hsotg->dev, " hctsiz.pktcnt %d\n",
  1058. (hctsiz & TSIZ_PKTCNT_MASK) >> TSIZ_PKTCNT_SHIFT);
  1059. dev_vdbg(hsotg->dev, " chan->max_packet %d\n", chan->max_packet);
  1060. dev_vdbg(hsotg->dev, " bytes_transferred %d\n",
  1061. xfer_length);
  1062. dev_vdbg(hsotg->dev, " urb->actual_length %d\n",
  1063. urb->actual_length);
  1064. dev_vdbg(hsotg->dev, " urb->transfer_buffer_length %d\n",
  1065. urb->length);
  1066. }
  1067. /*
  1068. * Handles a host channel NAK interrupt. This handler may be called in either
  1069. * DMA mode or Slave mode.
  1070. */
  1071. static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
  1072. struct dwc2_host_chan *chan, int chnum,
  1073. struct dwc2_qtd *qtd)
  1074. {
  1075. if (dbg_hc(chan))
  1076. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
  1077. chnum);
  1078. /*
  1079. * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  1080. * interrupt. Re-start the SSPLIT transfer.
  1081. */
  1082. if (chan->do_split) {
  1083. if (chan->complete_split)
  1084. qtd->error_count = 0;
  1085. qtd->complete_split = 0;
  1086. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1087. goto handle_nak_done;
  1088. }
  1089. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1090. case USB_ENDPOINT_XFER_CONTROL:
  1091. case USB_ENDPOINT_XFER_BULK:
  1092. if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
  1093. /*
  1094. * NAK interrupts are enabled on bulk/control IN
  1095. * transfers in DMA mode for the sole purpose of
  1096. * resetting the error count after a transaction error
  1097. * occurs. The core will continue transferring data.
  1098. */
  1099. qtd->error_count = 0;
  1100. break;
  1101. }
  1102. /*
  1103. * NAK interrupts normally occur during OUT transfers in DMA
  1104. * or Slave mode. For IN transfers, more requests will be
  1105. * queued as request queue space is available.
  1106. */
  1107. qtd->error_count = 0;
  1108. if (!chan->qh->ping_state) {
  1109. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1110. qtd, DWC2_HC_XFER_NAK);
  1111. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1112. if (chan->speed == USB_SPEED_HIGH)
  1113. chan->qh->ping_state = 1;
  1114. }
  1115. /*
  1116. * Halt the channel so the transfer can be re-started from
  1117. * the appropriate point or the PING protocol will
  1118. * start/continue
  1119. */
  1120. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1121. break;
  1122. case USB_ENDPOINT_XFER_INT:
  1123. qtd->error_count = 0;
  1124. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
  1125. break;
  1126. case USB_ENDPOINT_XFER_ISOC:
  1127. /* Should never get called for isochronous transfers */
  1128. dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
  1129. break;
  1130. }
  1131. handle_nak_done:
  1132. disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
  1133. }
  1134. /*
  1135. * Handles a host channel ACK interrupt. This interrupt is enabled when
  1136. * performing the PING protocol in Slave mode, when errors occur during
  1137. * either Slave mode or DMA mode, and during Start Split transactions.
  1138. */
  1139. static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
  1140. struct dwc2_host_chan *chan, int chnum,
  1141. struct dwc2_qtd *qtd)
  1142. {
  1143. struct dwc2_hcd_iso_packet_desc *frame_desc;
  1144. if (dbg_hc(chan))
  1145. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
  1146. chnum);
  1147. if (chan->do_split) {
  1148. /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
  1149. if (!chan->ep_is_in &&
  1150. chan->data_pid_start != DWC2_HC_PID_SETUP)
  1151. qtd->ssplit_out_xfer_count = chan->xfer_len;
  1152. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
  1153. qtd->complete_split = 1;
  1154. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1155. } else {
  1156. /* ISOC OUT */
  1157. switch (chan->xact_pos) {
  1158. case DWC2_HCSPLT_XACTPOS_ALL:
  1159. break;
  1160. case DWC2_HCSPLT_XACTPOS_END:
  1161. qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
  1162. qtd->isoc_split_offset = 0;
  1163. break;
  1164. case DWC2_HCSPLT_XACTPOS_BEGIN:
  1165. case DWC2_HCSPLT_XACTPOS_MID:
  1166. /*
  1167. * For BEGIN or MID, calculate the length for
  1168. * the next microframe to determine the correct
  1169. * SSPLIT token, either MID or END
  1170. */
  1171. frame_desc = &qtd->urb->iso_descs[
  1172. qtd->isoc_frame_index];
  1173. qtd->isoc_split_offset += 188;
  1174. if (frame_desc->length - qtd->isoc_split_offset
  1175. <= 188)
  1176. qtd->isoc_split_pos =
  1177. DWC2_HCSPLT_XACTPOS_END;
  1178. else
  1179. qtd->isoc_split_pos =
  1180. DWC2_HCSPLT_XACTPOS_MID;
  1181. break;
  1182. }
  1183. }
  1184. } else {
  1185. qtd->error_count = 0;
  1186. if (chan->qh->ping_state) {
  1187. chan->qh->ping_state = 0;
  1188. /*
  1189. * Halt the channel so the transfer can be re-started
  1190. * from the appropriate point. This only happens in
  1191. * Slave mode. In DMA mode, the ping_state is cleared
  1192. * when the transfer is started because the core
  1193. * automatically executes the PING, then the transfer.
  1194. */
  1195. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
  1196. }
  1197. }
  1198. /*
  1199. * If the ACK occurred when _not_ in the PING state, let the channel
  1200. * continue transferring data after clearing the error count
  1201. */
  1202. disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
  1203. }
  1204. /*
  1205. * Handles a host channel NYET interrupt. This interrupt should only occur on
  1206. * Bulk and Control OUT endpoints and for complete split transactions. If a
  1207. * NYET occurs at the same time as a Transfer Complete interrupt, it is
  1208. * handled in the xfercomp interrupt handler, not here. This handler may be
  1209. * called in either DMA mode or Slave mode.
  1210. */
  1211. static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
  1212. struct dwc2_host_chan *chan, int chnum,
  1213. struct dwc2_qtd *qtd)
  1214. {
  1215. if (dbg_hc(chan))
  1216. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
  1217. chnum);
  1218. /*
  1219. * NYET on CSPLIT
  1220. * re-do the CSPLIT immediately on non-periodic
  1221. */
  1222. if (chan->do_split && chan->complete_split) {
  1223. if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
  1224. hsotg->core_params->dma_enable > 0) {
  1225. qtd->complete_split = 0;
  1226. qtd->isoc_split_offset = 0;
  1227. qtd->isoc_frame_index++;
  1228. if (qtd->urb &&
  1229. qtd->isoc_frame_index == qtd->urb->packet_count) {
  1230. dwc2_host_complete(hsotg, qtd, 0);
  1231. dwc2_release_channel(hsotg, chan, qtd,
  1232. DWC2_HC_XFER_URB_COMPLETE);
  1233. } else {
  1234. dwc2_release_channel(hsotg, chan, qtd,
  1235. DWC2_HC_XFER_NO_HALT_STATUS);
  1236. }
  1237. goto handle_nyet_done;
  1238. }
  1239. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1240. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1241. int frnum = dwc2_hcd_get_frame_number(hsotg);
  1242. if (dwc2_full_frame_num(frnum) !=
  1243. dwc2_full_frame_num(chan->qh->sched_frame)) {
  1244. /*
  1245. * No longer in the same full speed frame.
  1246. * Treat this as a transaction error.
  1247. */
  1248. #if 0
  1249. /*
  1250. * Todo: Fix system performance so this can
  1251. * be treated as an error. Right now complete
  1252. * splits cannot be scheduled precisely enough
  1253. * due to other system activity, so this error
  1254. * occurs regularly in Slave mode.
  1255. */
  1256. qtd->error_count++;
  1257. #endif
  1258. qtd->complete_split = 0;
  1259. dwc2_halt_channel(hsotg, chan, qtd,
  1260. DWC2_HC_XFER_XACT_ERR);
  1261. /* Todo: add support for isoc release */
  1262. goto handle_nyet_done;
  1263. }
  1264. }
  1265. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1266. goto handle_nyet_done;
  1267. }
  1268. chan->qh->ping_state = 1;
  1269. qtd->error_count = 0;
  1270. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
  1271. DWC2_HC_XFER_NYET);
  1272. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1273. /*
  1274. * Halt the channel and re-start the transfer so the PING protocol
  1275. * will start
  1276. */
  1277. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
  1278. handle_nyet_done:
  1279. disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
  1280. }
  1281. /*
  1282. * Handles a host channel babble interrupt. This handler may be called in
  1283. * either DMA mode or Slave mode.
  1284. */
  1285. static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
  1286. struct dwc2_host_chan *chan, int chnum,
  1287. struct dwc2_qtd *qtd)
  1288. {
  1289. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
  1290. chnum);
  1291. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1292. if (hsotg->core_params->dma_desc_enable > 0) {
  1293. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1294. DWC2_HC_XFER_BABBLE_ERR);
  1295. goto disable_int;
  1296. }
  1297. if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
  1298. dwc2_host_complete(hsotg, qtd, -EOVERFLOW);
  1299. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
  1300. } else {
  1301. enum dwc2_halt_status halt_status;
  1302. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1303. qtd, DWC2_HC_XFER_BABBLE_ERR);
  1304. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1305. }
  1306. disable_int:
  1307. disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
  1308. }
  1309. /*
  1310. * Handles a host channel AHB error interrupt. This handler is only called in
  1311. * DMA mode.
  1312. */
  1313. static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
  1314. struct dwc2_host_chan *chan, int chnum,
  1315. struct dwc2_qtd *qtd)
  1316. {
  1317. struct dwc2_hcd_urb *urb = qtd->urb;
  1318. char *pipetype, *speed;
  1319. u32 hcchar;
  1320. u32 hcsplt;
  1321. u32 hctsiz;
  1322. u32 hc_dma;
  1323. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
  1324. chnum);
  1325. if (!urb)
  1326. goto handle_ahberr_halt;
  1327. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1328. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1329. hcsplt = readl(hsotg->regs + HCSPLT(chnum));
  1330. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1331. hc_dma = readl(hsotg->regs + HCDMA(chnum));
  1332. dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
  1333. dev_err(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
  1334. dev_err(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
  1335. dev_err(hsotg->dev, " Device address: %d\n",
  1336. dwc2_hcd_get_dev_addr(&urb->pipe_info));
  1337. dev_err(hsotg->dev, " Endpoint: %d, %s\n",
  1338. dwc2_hcd_get_ep_num(&urb->pipe_info),
  1339. dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  1340. switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
  1341. case USB_ENDPOINT_XFER_CONTROL:
  1342. pipetype = "CONTROL";
  1343. break;
  1344. case USB_ENDPOINT_XFER_BULK:
  1345. pipetype = "BULK";
  1346. break;
  1347. case USB_ENDPOINT_XFER_INT:
  1348. pipetype = "INTERRUPT";
  1349. break;
  1350. case USB_ENDPOINT_XFER_ISOC:
  1351. pipetype = "ISOCHRONOUS";
  1352. break;
  1353. default:
  1354. pipetype = "UNKNOWN";
  1355. break;
  1356. }
  1357. dev_err(hsotg->dev, " Endpoint type: %s\n", pipetype);
  1358. switch (chan->speed) {
  1359. case USB_SPEED_HIGH:
  1360. speed = "HIGH";
  1361. break;
  1362. case USB_SPEED_FULL:
  1363. speed = "FULL";
  1364. break;
  1365. case USB_SPEED_LOW:
  1366. speed = "LOW";
  1367. break;
  1368. default:
  1369. speed = "UNKNOWN";
  1370. break;
  1371. }
  1372. dev_err(hsotg->dev, " Speed: %s\n", speed);
  1373. dev_err(hsotg->dev, " Max packet size: %d\n",
  1374. dwc2_hcd_get_mps(&urb->pipe_info));
  1375. dev_err(hsotg->dev, " Data buffer length: %d\n", urb->length);
  1376. dev_err(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n",
  1377. urb->buf, (unsigned long)urb->dma);
  1378. dev_err(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n",
  1379. urb->setup_packet, (unsigned long)urb->setup_dma);
  1380. dev_err(hsotg->dev, " Interval: %d\n", urb->interval);
  1381. /* Core halts the channel for Descriptor DMA mode */
  1382. if (hsotg->core_params->dma_desc_enable > 0) {
  1383. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1384. DWC2_HC_XFER_AHB_ERR);
  1385. goto handle_ahberr_done;
  1386. }
  1387. dwc2_host_complete(hsotg, qtd, -EIO);
  1388. handle_ahberr_halt:
  1389. /*
  1390. * Force a channel halt. Don't call dwc2_halt_channel because that won't
  1391. * write to the HCCHARn register in DMA mode to force the halt.
  1392. */
  1393. dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
  1394. handle_ahberr_done:
  1395. disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
  1396. }
  1397. /*
  1398. * Handles a host channel transaction error interrupt. This handler may be
  1399. * called in either DMA mode or Slave mode.
  1400. */
  1401. static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
  1402. struct dwc2_host_chan *chan, int chnum,
  1403. struct dwc2_qtd *qtd)
  1404. {
  1405. dev_dbg(hsotg->dev,
  1406. "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
  1407. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1408. if (hsotg->core_params->dma_desc_enable > 0) {
  1409. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1410. DWC2_HC_XFER_XACT_ERR);
  1411. goto handle_xacterr_done;
  1412. }
  1413. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1414. case USB_ENDPOINT_XFER_CONTROL:
  1415. case USB_ENDPOINT_XFER_BULK:
  1416. qtd->error_count++;
  1417. if (!chan->qh->ping_state) {
  1418. dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
  1419. qtd, DWC2_HC_XFER_XACT_ERR);
  1420. dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
  1421. if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
  1422. chan->qh->ping_state = 1;
  1423. }
  1424. /*
  1425. * Halt the channel so the transfer can be re-started from
  1426. * the appropriate point or the PING protocol will start
  1427. */
  1428. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1429. break;
  1430. case USB_ENDPOINT_XFER_INT:
  1431. qtd->error_count++;
  1432. if (chan->do_split && chan->complete_split)
  1433. qtd->complete_split = 0;
  1434. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
  1435. break;
  1436. case USB_ENDPOINT_XFER_ISOC:
  1437. {
  1438. enum dwc2_halt_status halt_status;
  1439. halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
  1440. chnum, qtd, DWC2_HC_XFER_XACT_ERR);
  1441. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1442. }
  1443. break;
  1444. }
  1445. handle_xacterr_done:
  1446. disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
  1447. }
  1448. /*
  1449. * Handles a host channel frame overrun interrupt. This handler may be called
  1450. * in either DMA mode or Slave mode.
  1451. */
  1452. static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
  1453. struct dwc2_host_chan *chan, int chnum,
  1454. struct dwc2_qtd *qtd)
  1455. {
  1456. enum dwc2_halt_status halt_status;
  1457. if (dbg_hc(chan))
  1458. dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
  1459. chnum);
  1460. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1461. switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  1462. case USB_ENDPOINT_XFER_CONTROL:
  1463. case USB_ENDPOINT_XFER_BULK:
  1464. break;
  1465. case USB_ENDPOINT_XFER_INT:
  1466. dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1467. break;
  1468. case USB_ENDPOINT_XFER_ISOC:
  1469. halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
  1470. qtd, DWC2_HC_XFER_FRAME_OVERRUN);
  1471. dwc2_halt_channel(hsotg, chan, qtd, halt_status);
  1472. break;
  1473. }
  1474. disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
  1475. }
  1476. /*
  1477. * Handles a host channel data toggle error interrupt. This handler may be
  1478. * called in either DMA mode or Slave mode.
  1479. */
  1480. static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
  1481. struct dwc2_host_chan *chan, int chnum,
  1482. struct dwc2_qtd *qtd)
  1483. {
  1484. dev_dbg(hsotg->dev,
  1485. "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
  1486. if (chan->ep_is_in)
  1487. qtd->error_count = 0;
  1488. else
  1489. dev_err(hsotg->dev,
  1490. "Data Toggle Error on OUT transfer, channel %d\n",
  1491. chnum);
  1492. dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
  1493. disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
  1494. }
  1495. /*
  1496. * For debug only. It checks that a valid halt status is set and that
  1497. * HCCHARn.chdis is clear. If there's a problem, corrective action is
  1498. * taken and a warning is issued.
  1499. *
  1500. * Return: true if halt status is ok, false otherwise
  1501. */
  1502. static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
  1503. struct dwc2_host_chan *chan, int chnum,
  1504. struct dwc2_qtd *qtd)
  1505. {
  1506. #ifdef DEBUG
  1507. u32 hcchar;
  1508. u32 hctsiz;
  1509. u32 hcintmsk;
  1510. u32 hcsplt;
  1511. if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
  1512. /*
  1513. * This code is here only as a check. This condition should
  1514. * never happen. Ignore the halt if it does occur.
  1515. */
  1516. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1517. hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
  1518. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1519. hcsplt = readl(hsotg->regs + HCSPLT(chnum));
  1520. dev_dbg(hsotg->dev,
  1521. "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
  1522. __func__);
  1523. dev_dbg(hsotg->dev,
  1524. "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
  1525. chnum, hcchar, hctsiz);
  1526. dev_dbg(hsotg->dev,
  1527. "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
  1528. chan->hcint, hcintmsk, hcsplt);
  1529. if (qtd)
  1530. dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
  1531. qtd->complete_split);
  1532. dev_warn(hsotg->dev,
  1533. "%s: no halt status, channel %d, ignoring interrupt\n",
  1534. __func__, chnum);
  1535. return false;
  1536. }
  1537. /*
  1538. * This code is here only as a check. hcchar.chdis should never be set
  1539. * when the halt interrupt occurs. Halt the channel again if it does
  1540. * occur.
  1541. */
  1542. hcchar = readl(hsotg->regs + HCCHAR(chnum));
  1543. if (hcchar & HCCHAR_CHDIS) {
  1544. dev_warn(hsotg->dev,
  1545. "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
  1546. __func__, hcchar);
  1547. chan->halt_pending = 0;
  1548. dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
  1549. return false;
  1550. }
  1551. #endif
  1552. return true;
  1553. }
  1554. /*
  1555. * Handles a host Channel Halted interrupt in DMA mode. This handler
  1556. * determines the reason the channel halted and proceeds accordingly.
  1557. */
  1558. static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
  1559. struct dwc2_host_chan *chan, int chnum,
  1560. struct dwc2_qtd *qtd)
  1561. {
  1562. u32 hcintmsk;
  1563. int out_nak_enh = 0;
  1564. if (dbg_hc(chan))
  1565. dev_vdbg(hsotg->dev,
  1566. "--Host Channel %d Interrupt: DMA Channel Halted--\n",
  1567. chnum);
  1568. /*
  1569. * For core with OUT NAK enhancement, the flow for high-speed
  1570. * CONTROL/BULK OUT is handled a little differently
  1571. */
  1572. if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_71a) {
  1573. if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
  1574. (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
  1575. chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
  1576. out_nak_enh = 1;
  1577. }
  1578. }
  1579. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
  1580. (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
  1581. hsotg->core_params->dma_desc_enable <= 0)) {
  1582. if (hsotg->core_params->dma_desc_enable > 0)
  1583. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1584. chan->halt_status);
  1585. else
  1586. /*
  1587. * Just release the channel. A dequeue can happen on a
  1588. * transfer timeout. In the case of an AHB Error, the
  1589. * channel was forced to halt because there's no way to
  1590. * gracefully recover.
  1591. */
  1592. dwc2_release_channel(hsotg, chan, qtd,
  1593. chan->halt_status);
  1594. return;
  1595. }
  1596. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1597. if (chan->hcint & HCINTMSK_XFERCOMPL) {
  1598. /*
  1599. * Todo: This is here because of a possible hardware bug. Spec
  1600. * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  1601. * interrupt w/ACK bit set should occur, but I only see the
  1602. * XFERCOMP bit, even with it masked out. This is a workaround
  1603. * for that behavior. Should fix this when hardware is fixed.
  1604. */
  1605. if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
  1606. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1607. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1608. } else if (chan->hcint & HCINTMSK_STALL) {
  1609. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1610. } else if ((chan->hcint & HCINTMSK_XACTERR) &&
  1611. hsotg->core_params->dma_desc_enable <= 0) {
  1612. if (out_nak_enh) {
  1613. if (chan->hcint &
  1614. (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
  1615. dev_vdbg(hsotg->dev,
  1616. "XactErr with NYET/NAK/ACK\n");
  1617. qtd->error_count = 0;
  1618. } else {
  1619. dev_vdbg(hsotg->dev,
  1620. "XactErr without NYET/NAK/ACK\n");
  1621. }
  1622. }
  1623. /*
  1624. * Must handle xacterr before nak or ack. Could get a xacterr
  1625. * at the same time as either of these on a BULK/CONTROL OUT
  1626. * that started with a PING. The xacterr takes precedence.
  1627. */
  1628. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1629. } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
  1630. hsotg->core_params->dma_desc_enable > 0) {
  1631. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1632. } else if ((chan->hcint & HCINTMSK_AHBERR) &&
  1633. hsotg->core_params->dma_desc_enable > 0) {
  1634. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1635. } else if (chan->hcint & HCINTMSK_BBLERR) {
  1636. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1637. } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
  1638. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1639. } else if (!out_nak_enh) {
  1640. if (chan->hcint & HCINTMSK_NYET) {
  1641. /*
  1642. * Must handle nyet before nak or ack. Could get a nyet
  1643. * at the same time as either of those on a BULK/CONTROL
  1644. * OUT that started with a PING. The nyet takes
  1645. * precedence.
  1646. */
  1647. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1648. } else if ((chan->hcint & HCINTMSK_NAK) &&
  1649. !(hcintmsk & HCINTMSK_NAK)) {
  1650. /*
  1651. * If nak is not masked, it's because a non-split IN
  1652. * transfer is in an error state. In that case, the nak
  1653. * is handled by the nak interrupt handler, not here.
  1654. * Handle nak here for BULK/CONTROL OUT transfers, which
  1655. * halt on a NAK to allow rewinding the buffer pointer.
  1656. */
  1657. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1658. } else if ((chan->hcint & HCINTMSK_ACK) &&
  1659. !(hcintmsk & HCINTMSK_ACK)) {
  1660. /*
  1661. * If ack is not masked, it's because a non-split IN
  1662. * transfer is in an error state. In that case, the ack
  1663. * is handled by the ack interrupt handler, not here.
  1664. * Handle ack here for split transfers. Start splits
  1665. * halt on ACK.
  1666. */
  1667. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1668. } else {
  1669. if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
  1670. chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
  1671. /*
  1672. * A periodic transfer halted with no other
  1673. * channel interrupts set. Assume it was halted
  1674. * by the core because it could not be completed
  1675. * in its scheduled (micro)frame.
  1676. */
  1677. dev_dbg(hsotg->dev,
  1678. "%s: Halt channel %d (assume incomplete periodic transfer)\n",
  1679. __func__, chnum);
  1680. dwc2_halt_channel(hsotg, chan, qtd,
  1681. DWC2_HC_XFER_PERIODIC_INCOMPLETE);
  1682. } else {
  1683. dev_err(hsotg->dev,
  1684. "%s: Channel %d - ChHltd set, but reason is unknown\n",
  1685. __func__, chnum);
  1686. dev_err(hsotg->dev,
  1687. "hcint 0x%08x, intsts 0x%08x\n",
  1688. chan->hcint,
  1689. readl(hsotg->regs + GINTSTS));
  1690. }
  1691. }
  1692. } else {
  1693. dev_info(hsotg->dev,
  1694. "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  1695. chan->hcint);
  1696. }
  1697. }
  1698. /*
  1699. * Handles a host channel Channel Halted interrupt
  1700. *
  1701. * In slave mode, this handler is called only when the driver specifically
  1702. * requests a halt. This occurs during handling other host channel interrupts
  1703. * (e.g. nak, xacterr, stall, nyet, etc.).
  1704. *
  1705. * In DMA mode, this is the interrupt that occurs when the core has finished
  1706. * processing a transfer on a channel. Other host channel interrupts (except
  1707. * ahberr) are disabled in DMA mode.
  1708. */
  1709. static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
  1710. struct dwc2_host_chan *chan, int chnum,
  1711. struct dwc2_qtd *qtd)
  1712. {
  1713. if (dbg_hc(chan))
  1714. dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
  1715. chnum);
  1716. if (hsotg->core_params->dma_enable > 0) {
  1717. dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
  1718. } else {
  1719. if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
  1720. return;
  1721. dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
  1722. }
  1723. }
  1724. /* Handles interrupt for a specific Host Channel */
  1725. static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
  1726. {
  1727. struct dwc2_qtd *qtd;
  1728. struct dwc2_host_chan *chan;
  1729. u32 hcint, hcintmsk;
  1730. chan = hsotg->hc_ptr_array[chnum];
  1731. hcint = readl(hsotg->regs + HCINT(chnum));
  1732. hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
  1733. if (!chan) {
  1734. dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
  1735. writel(hcint, hsotg->regs + HCINT(chnum));
  1736. return;
  1737. }
  1738. if (dbg_hc(chan)) {
  1739. dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n",
  1740. chnum);
  1741. dev_vdbg(hsotg->dev,
  1742. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1743. hcint, hcintmsk, hcint & hcintmsk);
  1744. }
  1745. writel(hcint, hsotg->regs + HCINT(chnum));
  1746. chan->hcint = hcint;
  1747. hcint &= hcintmsk;
  1748. /*
  1749. * If the channel was halted due to a dequeue, the qtd list might
  1750. * be empty or at least the first entry will not be the active qtd.
  1751. * In this case, take a shortcut and just release the channel.
  1752. */
  1753. if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
  1754. /*
  1755. * If the channel was halted, this should be the only
  1756. * interrupt unmasked
  1757. */
  1758. WARN_ON(hcint != HCINTMSK_CHHLTD);
  1759. if (hsotg->core_params->dma_desc_enable > 0)
  1760. dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
  1761. chan->halt_status);
  1762. else
  1763. dwc2_release_channel(hsotg, chan, NULL,
  1764. chan->halt_status);
  1765. return;
  1766. }
  1767. if (list_empty(&chan->qh->qtd_list)) {
  1768. /*
  1769. * TODO: Will this ever happen with the
  1770. * DWC2_HC_XFER_URB_DEQUEUE handling above?
  1771. */
  1772. dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
  1773. chnum);
  1774. dev_dbg(hsotg->dev,
  1775. " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  1776. chan->hcint, hcintmsk, hcint);
  1777. chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
  1778. disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
  1779. chan->hcint = 0;
  1780. return;
  1781. }
  1782. qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
  1783. qtd_list_entry);
  1784. if (hsotg->core_params->dma_enable <= 0) {
  1785. if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
  1786. hcint &= ~HCINTMSK_CHHLTD;
  1787. }
  1788. if (hcint & HCINTMSK_XFERCOMPL) {
  1789. dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
  1790. /*
  1791. * If NYET occurred at same time as Xfer Complete, the NYET is
  1792. * handled by the Xfer Complete interrupt handler. Don't want
  1793. * to call the NYET interrupt handler in this case.
  1794. */
  1795. hcint &= ~HCINTMSK_NYET;
  1796. }
  1797. if (hcint & HCINTMSK_CHHLTD)
  1798. dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
  1799. if (hcint & HCINTMSK_AHBERR)
  1800. dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
  1801. if (hcint & HCINTMSK_STALL)
  1802. dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
  1803. if (hcint & HCINTMSK_NAK)
  1804. dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
  1805. if (hcint & HCINTMSK_ACK)
  1806. dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
  1807. if (hcint & HCINTMSK_NYET)
  1808. dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
  1809. if (hcint & HCINTMSK_XACTERR)
  1810. dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
  1811. if (hcint & HCINTMSK_BBLERR)
  1812. dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
  1813. if (hcint & HCINTMSK_FRMOVRUN)
  1814. dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
  1815. if (hcint & HCINTMSK_DATATGLERR)
  1816. dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
  1817. chan->hcint = 0;
  1818. }
  1819. /*
  1820. * This interrupt indicates that one or more host channels has a pending
  1821. * interrupt. There are multiple conditions that can cause each host channel
  1822. * interrupt. This function determines which conditions have occurred for each
  1823. * host channel interrupt and handles them appropriately.
  1824. */
  1825. static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
  1826. {
  1827. u32 haint;
  1828. int i;
  1829. haint = readl(hsotg->regs + HAINT);
  1830. if (dbg_perio()) {
  1831. dev_vdbg(hsotg->dev, "%s()\n", __func__);
  1832. dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
  1833. }
  1834. for (i = 0; i < hsotg->core_params->host_channels; i++) {
  1835. if (haint & (1 << i))
  1836. dwc2_hc_n_intr(hsotg, i);
  1837. }
  1838. }
  1839. /* This function handles interrupts for the HCD */
  1840. irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg)
  1841. {
  1842. u32 gintsts, dbg_gintsts;
  1843. irqreturn_t retval = IRQ_NONE;
  1844. if (!dwc2_is_controller_alive(hsotg)) {
  1845. dev_warn(hsotg->dev, "Controller is dead\n");
  1846. return retval;
  1847. }
  1848. spin_lock(&hsotg->lock);
  1849. /* Check if HOST Mode */
  1850. if (dwc2_is_host_mode(hsotg)) {
  1851. gintsts = dwc2_read_core_intr(hsotg);
  1852. if (!gintsts) {
  1853. spin_unlock(&hsotg->lock);
  1854. return retval;
  1855. }
  1856. retval = IRQ_HANDLED;
  1857. dbg_gintsts = gintsts;
  1858. #ifndef DEBUG_SOF
  1859. dbg_gintsts &= ~GINTSTS_SOF;
  1860. #endif
  1861. if (!dbg_perio())
  1862. dbg_gintsts &= ~(GINTSTS_HCHINT | GINTSTS_RXFLVL |
  1863. GINTSTS_PTXFEMP);
  1864. /* Only print if there are any non-suppressed interrupts left */
  1865. if (dbg_gintsts)
  1866. dev_vdbg(hsotg->dev,
  1867. "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
  1868. gintsts);
  1869. if (gintsts & GINTSTS_SOF)
  1870. dwc2_sof_intr(hsotg);
  1871. if (gintsts & GINTSTS_RXFLVL)
  1872. dwc2_rx_fifo_level_intr(hsotg);
  1873. if (gintsts & GINTSTS_NPTXFEMP)
  1874. dwc2_np_tx_fifo_empty_intr(hsotg);
  1875. if (gintsts & GINTSTS_PRTINT)
  1876. dwc2_port_intr(hsotg);
  1877. if (gintsts & GINTSTS_HCHINT)
  1878. dwc2_hc_intr(hsotg);
  1879. if (gintsts & GINTSTS_PTXFEMP)
  1880. dwc2_perio_tx_fifo_empty_intr(hsotg);
  1881. if (dbg_gintsts) {
  1882. dev_vdbg(hsotg->dev,
  1883. "DWC OTG HCD Finished Servicing Interrupts\n");
  1884. dev_vdbg(hsotg->dev,
  1885. "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
  1886. readl(hsotg->regs + GINTSTS),
  1887. readl(hsotg->regs + GINTMSK));
  1888. }
  1889. }
  1890. spin_unlock(&hsotg->lock);
  1891. return retval;
  1892. }