hcd_intr.c 65 KB

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