hcd_intr.c 62 KB

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