hcd_intr.c 62 KB

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