hcd_intr.c 65 KB

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