musb_host.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820
  1. /*
  2. * MUSB OTG driver host support
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  26. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  28. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  29. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  32. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. #include <linux/module.h>
  36. #include <linux/kernel.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/slab.h>
  40. #include <linux/errno.h>
  41. #include <linux/list.h>
  42. #include <linux/dma-mapping.h>
  43. #include "musb_core.h"
  44. #include "musb_host.h"
  45. #include "musb_trace.h"
  46. /* MUSB HOST status 22-mar-2006
  47. *
  48. * - There's still lots of partial code duplication for fault paths, so
  49. * they aren't handled as consistently as they need to be.
  50. *
  51. * - PIO mostly behaved when last tested.
  52. * + including ep0, with all usbtest cases 9, 10
  53. * + usbtest 14 (ep0out) doesn't seem to run at all
  54. * + double buffered OUT/TX endpoints saw stalls(!) with certain usbtest
  55. * configurations, but otherwise double buffering passes basic tests.
  56. * + for 2.6.N, for N > ~10, needs API changes for hcd framework.
  57. *
  58. * - DMA (CPPI) ... partially behaves, not currently recommended
  59. * + about 1/15 the speed of typical EHCI implementations (PCI)
  60. * + RX, all too often reqpkt seems to misbehave after tx
  61. * + TX, no known issues (other than evident silicon issue)
  62. *
  63. * - DMA (Mentor/OMAP) ...has at least toggle update problems
  64. *
  65. * - [23-feb-2009] minimal traffic scheduling to avoid bulk RX packet
  66. * starvation ... nothing yet for TX, interrupt, or bulk.
  67. *
  68. * - Not tested with HNP, but some SRP paths seem to behave.
  69. *
  70. * NOTE 24-August-2006:
  71. *
  72. * - Bulk traffic finally uses both sides of hardware ep1, freeing up an
  73. * extra endpoint for periodic use enabling hub + keybd + mouse. That
  74. * mostly works, except that with "usbnet" it's easy to trigger cases
  75. * with "ping" where RX loses. (a) ping to davinci, even "ping -f",
  76. * fine; but (b) ping _from_ davinci, even "ping -c 1", ICMP RX loses
  77. * although ARP RX wins. (That test was done with a full speed link.)
  78. */
  79. /*
  80. * NOTE on endpoint usage:
  81. *
  82. * CONTROL transfers all go through ep0. BULK ones go through dedicated IN
  83. * and OUT endpoints ... hardware is dedicated for those "async" queue(s).
  84. * (Yes, bulk _could_ use more of the endpoints than that, and would even
  85. * benefit from it.)
  86. *
  87. * INTERUPPT and ISOCHRONOUS transfers are scheduled to the other endpoints.
  88. * So far that scheduling is both dumb and optimistic: the endpoint will be
  89. * "claimed" until its software queue is no longer refilled. No multiplexing
  90. * of transfers between endpoints, or anything clever.
  91. */
  92. struct musb *hcd_to_musb(struct usb_hcd *hcd)
  93. {
  94. return *(struct musb **) hcd->hcd_priv;
  95. }
  96. static void musb_ep_program(struct musb *musb, u8 epnum,
  97. struct urb *urb, int is_out,
  98. u8 *buf, u32 offset, u32 len);
  99. /*
  100. * Clear TX fifo. Needed to avoid BABBLE errors.
  101. */
  102. static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep)
  103. {
  104. struct musb *musb = ep->musb;
  105. void __iomem *epio = ep->regs;
  106. u16 csr;
  107. int retries = 1000;
  108. csr = musb_readw(epio, MUSB_TXCSR);
  109. while (csr & MUSB_TXCSR_FIFONOTEMPTY) {
  110. csr |= MUSB_TXCSR_FLUSHFIFO | MUSB_TXCSR_TXPKTRDY;
  111. musb_writew(epio, MUSB_TXCSR, csr);
  112. csr = musb_readw(epio, MUSB_TXCSR);
  113. /*
  114. * FIXME: sometimes the tx fifo flush failed, it has been
  115. * observed during device disconnect on AM335x.
  116. *
  117. * To reproduce the issue, ensure tx urb(s) are queued when
  118. * unplug the usb device which is connected to AM335x usb
  119. * host port.
  120. *
  121. * I found using a usb-ethernet device and running iperf
  122. * (client on AM335x) has very high chance to trigger it.
  123. *
  124. * Better to turn on musb_dbg() in musb_cleanup_urb() with
  125. * CPPI enabled to see the issue when aborting the tx channel.
  126. */
  127. if (dev_WARN_ONCE(musb->controller, retries-- < 1,
  128. "Could not flush host TX%d fifo: csr: %04x\n",
  129. ep->epnum, csr))
  130. return;
  131. mdelay(1);
  132. }
  133. }
  134. static void musb_h_ep0_flush_fifo(struct musb_hw_ep *ep)
  135. {
  136. void __iomem *epio = ep->regs;
  137. u16 csr;
  138. int retries = 5;
  139. /* scrub any data left in the fifo */
  140. do {
  141. csr = musb_readw(epio, MUSB_TXCSR);
  142. if (!(csr & (MUSB_CSR0_TXPKTRDY | MUSB_CSR0_RXPKTRDY)))
  143. break;
  144. musb_writew(epio, MUSB_TXCSR, MUSB_CSR0_FLUSHFIFO);
  145. csr = musb_readw(epio, MUSB_TXCSR);
  146. udelay(10);
  147. } while (--retries);
  148. WARN(!retries, "Could not flush host TX%d fifo: csr: %04x\n",
  149. ep->epnum, csr);
  150. /* and reset for the next transfer */
  151. musb_writew(epio, MUSB_TXCSR, 0);
  152. }
  153. /*
  154. * Start transmit. Caller is responsible for locking shared resources.
  155. * musb must be locked.
  156. */
  157. static inline void musb_h_tx_start(struct musb_hw_ep *ep)
  158. {
  159. u16 txcsr;
  160. /* NOTE: no locks here; caller should lock and select EP */
  161. if (ep->epnum) {
  162. txcsr = musb_readw(ep->regs, MUSB_TXCSR);
  163. txcsr |= MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_H_WZC_BITS;
  164. musb_writew(ep->regs, MUSB_TXCSR, txcsr);
  165. } else {
  166. txcsr = MUSB_CSR0_H_SETUPPKT | MUSB_CSR0_TXPKTRDY;
  167. musb_writew(ep->regs, MUSB_CSR0, txcsr);
  168. }
  169. }
  170. static inline void musb_h_tx_dma_start(struct musb_hw_ep *ep)
  171. {
  172. u16 txcsr;
  173. /* NOTE: no locks here; caller should lock and select EP */
  174. txcsr = musb_readw(ep->regs, MUSB_TXCSR);
  175. txcsr |= MUSB_TXCSR_DMAENAB | MUSB_TXCSR_H_WZC_BITS;
  176. if (is_cppi_enabled(ep->musb))
  177. txcsr |= MUSB_TXCSR_DMAMODE;
  178. musb_writew(ep->regs, MUSB_TXCSR, txcsr);
  179. }
  180. static void musb_ep_set_qh(struct musb_hw_ep *ep, int is_in, struct musb_qh *qh)
  181. {
  182. if (is_in != 0 || ep->is_shared_fifo)
  183. ep->in_qh = qh;
  184. if (is_in == 0 || ep->is_shared_fifo)
  185. ep->out_qh = qh;
  186. }
  187. static struct musb_qh *musb_ep_get_qh(struct musb_hw_ep *ep, int is_in)
  188. {
  189. return is_in ? ep->in_qh : ep->out_qh;
  190. }
  191. /*
  192. * Start the URB at the front of an endpoint's queue
  193. * end must be claimed from the caller.
  194. *
  195. * Context: controller locked, irqs blocked
  196. */
  197. static void
  198. musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
  199. {
  200. u16 frame;
  201. u32 len;
  202. void __iomem *mbase = musb->mregs;
  203. struct urb *urb = next_urb(qh);
  204. void *buf = urb->transfer_buffer;
  205. u32 offset = 0;
  206. struct musb_hw_ep *hw_ep = qh->hw_ep;
  207. int epnum = hw_ep->epnum;
  208. /* initialize software qh state */
  209. qh->offset = 0;
  210. qh->segsize = 0;
  211. /* gather right source of data */
  212. switch (qh->type) {
  213. case USB_ENDPOINT_XFER_CONTROL:
  214. /* control transfers always start with SETUP */
  215. is_in = 0;
  216. musb->ep0_stage = MUSB_EP0_START;
  217. buf = urb->setup_packet;
  218. len = 8;
  219. break;
  220. case USB_ENDPOINT_XFER_ISOC:
  221. qh->iso_idx = 0;
  222. qh->frame = 0;
  223. offset = urb->iso_frame_desc[0].offset;
  224. len = urb->iso_frame_desc[0].length;
  225. break;
  226. default: /* bulk, interrupt */
  227. /* actual_length may be nonzero on retry paths */
  228. buf = urb->transfer_buffer + urb->actual_length;
  229. len = urb->transfer_buffer_length - urb->actual_length;
  230. }
  231. trace_musb_urb_start(musb, urb);
  232. /* Configure endpoint */
  233. musb_ep_set_qh(hw_ep, is_in, qh);
  234. musb_ep_program(musb, epnum, urb, !is_in, buf, offset, len);
  235. /* transmit may have more work: start it when it is time */
  236. if (is_in)
  237. return;
  238. /* determine if the time is right for a periodic transfer */
  239. switch (qh->type) {
  240. case USB_ENDPOINT_XFER_ISOC:
  241. case USB_ENDPOINT_XFER_INT:
  242. musb_dbg(musb, "check whether there's still time for periodic Tx");
  243. frame = musb_readw(mbase, MUSB_FRAME);
  244. /* FIXME this doesn't implement that scheduling policy ...
  245. * or handle framecounter wrapping
  246. */
  247. if (1) { /* Always assume URB_ISO_ASAP */
  248. /* REVISIT the SOF irq handler shouldn't duplicate
  249. * this code; and we don't init urb->start_frame...
  250. */
  251. qh->frame = 0;
  252. goto start;
  253. } else {
  254. qh->frame = urb->start_frame;
  255. /* enable SOF interrupt so we can count down */
  256. musb_dbg(musb, "SOF for %d", epnum);
  257. #if 1 /* ifndef CONFIG_ARCH_DAVINCI */
  258. musb_writeb(mbase, MUSB_INTRUSBE, 0xff);
  259. #endif
  260. }
  261. break;
  262. default:
  263. start:
  264. musb_dbg(musb, "Start TX%d %s", epnum,
  265. hw_ep->tx_channel ? "dma" : "pio");
  266. if (!hw_ep->tx_channel)
  267. musb_h_tx_start(hw_ep);
  268. else if (is_cppi_enabled(musb) || tusb_dma_omap(musb))
  269. musb_h_tx_dma_start(hw_ep);
  270. }
  271. }
  272. /* Context: caller owns controller lock, IRQs are blocked */
  273. static void musb_giveback(struct musb *musb, struct urb *urb, int status)
  274. __releases(musb->lock)
  275. __acquires(musb->lock)
  276. {
  277. trace_musb_urb_gb(musb, urb);
  278. usb_hcd_unlink_urb_from_ep(musb->hcd, urb);
  279. spin_unlock(&musb->lock);
  280. usb_hcd_giveback_urb(musb->hcd, urb, status);
  281. spin_lock(&musb->lock);
  282. }
  283. /* For bulk/interrupt endpoints only */
  284. static inline void musb_save_toggle(struct musb_qh *qh, int is_in,
  285. struct urb *urb)
  286. {
  287. void __iomem *epio = qh->hw_ep->regs;
  288. u16 csr;
  289. /*
  290. * FIXME: the current Mentor DMA code seems to have
  291. * problems getting toggle correct.
  292. */
  293. if (is_in)
  294. csr = musb_readw(epio, MUSB_RXCSR) & MUSB_RXCSR_H_DATATOGGLE;
  295. else
  296. csr = musb_readw(epio, MUSB_TXCSR) & MUSB_TXCSR_H_DATATOGGLE;
  297. usb_settoggle(urb->dev, qh->epnum, !is_in, csr ? 1 : 0);
  298. }
  299. /*
  300. * Advance this hardware endpoint's queue, completing the specified URB and
  301. * advancing to either the next URB queued to that qh, or else invalidating
  302. * that qh and advancing to the next qh scheduled after the current one.
  303. *
  304. * Context: caller owns controller lock, IRQs are blocked
  305. */
  306. static void musb_advance_schedule(struct musb *musb, struct urb *urb,
  307. struct musb_hw_ep *hw_ep, int is_in)
  308. {
  309. struct musb_qh *qh = musb_ep_get_qh(hw_ep, is_in);
  310. struct musb_hw_ep *ep = qh->hw_ep;
  311. int ready = qh->is_ready;
  312. int status;
  313. status = (urb->status == -EINPROGRESS) ? 0 : urb->status;
  314. /* save toggle eagerly, for paranoia */
  315. switch (qh->type) {
  316. case USB_ENDPOINT_XFER_BULK:
  317. case USB_ENDPOINT_XFER_INT:
  318. musb_save_toggle(qh, is_in, urb);
  319. break;
  320. case USB_ENDPOINT_XFER_ISOC:
  321. if (status == 0 && urb->error_count)
  322. status = -EXDEV;
  323. break;
  324. }
  325. qh->is_ready = 0;
  326. musb_giveback(musb, urb, status);
  327. qh->is_ready = ready;
  328. /* reclaim resources (and bandwidth) ASAP; deschedule it, and
  329. * invalidate qh as soon as list_empty(&hep->urb_list)
  330. */
  331. if (list_empty(&qh->hep->urb_list)) {
  332. struct list_head *head;
  333. struct dma_controller *dma = musb->dma_controller;
  334. if (is_in) {
  335. ep->rx_reinit = 1;
  336. if (ep->rx_channel) {
  337. dma->channel_release(ep->rx_channel);
  338. ep->rx_channel = NULL;
  339. }
  340. } else {
  341. ep->tx_reinit = 1;
  342. if (ep->tx_channel) {
  343. dma->channel_release(ep->tx_channel);
  344. ep->tx_channel = NULL;
  345. }
  346. }
  347. /* Clobber old pointers to this qh */
  348. musb_ep_set_qh(ep, is_in, NULL);
  349. qh->hep->hcpriv = NULL;
  350. switch (qh->type) {
  351. case USB_ENDPOINT_XFER_CONTROL:
  352. case USB_ENDPOINT_XFER_BULK:
  353. /* fifo policy for these lists, except that NAKing
  354. * should rotate a qh to the end (for fairness).
  355. */
  356. if (qh->mux == 1) {
  357. head = qh->ring.prev;
  358. list_del(&qh->ring);
  359. kfree(qh);
  360. qh = first_qh(head);
  361. break;
  362. }
  363. case USB_ENDPOINT_XFER_ISOC:
  364. case USB_ENDPOINT_XFER_INT:
  365. /* this is where periodic bandwidth should be
  366. * de-allocated if it's tracked and allocated;
  367. * and where we'd update the schedule tree...
  368. */
  369. kfree(qh);
  370. qh = NULL;
  371. break;
  372. }
  373. }
  374. /*
  375. * The pipe must be broken if current urb->status is set, so don't
  376. * start next urb.
  377. * TODO: to minimize the risk of regression, only check urb->status
  378. * for RX, until we have a test case to understand the behavior of TX.
  379. */
  380. if ((!status || !is_in) && qh && qh->is_ready) {
  381. musb_dbg(musb, "... next ep%d %cX urb %p",
  382. hw_ep->epnum, is_in ? 'R' : 'T', next_urb(qh));
  383. musb_start_urb(musb, is_in, qh);
  384. }
  385. }
  386. static u16 musb_h_flush_rxfifo(struct musb_hw_ep *hw_ep, u16 csr)
  387. {
  388. /* we don't want fifo to fill itself again;
  389. * ignore dma (various models),
  390. * leave toggle alone (may not have been saved yet)
  391. */
  392. csr |= MUSB_RXCSR_FLUSHFIFO | MUSB_RXCSR_RXPKTRDY;
  393. csr &= ~(MUSB_RXCSR_H_REQPKT
  394. | MUSB_RXCSR_H_AUTOREQ
  395. | MUSB_RXCSR_AUTOCLEAR);
  396. /* write 2x to allow double buffering */
  397. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  398. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  399. /* flush writebuffer */
  400. return musb_readw(hw_ep->regs, MUSB_RXCSR);
  401. }
  402. /*
  403. * PIO RX for a packet (or part of it).
  404. */
  405. static bool
  406. musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 epnum, u8 iso_err)
  407. {
  408. u16 rx_count;
  409. u8 *buf;
  410. u16 csr;
  411. bool done = false;
  412. u32 length;
  413. int do_flush = 0;
  414. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  415. void __iomem *epio = hw_ep->regs;
  416. struct musb_qh *qh = hw_ep->in_qh;
  417. int pipe = urb->pipe;
  418. void *buffer = urb->transfer_buffer;
  419. /* musb_ep_select(mbase, epnum); */
  420. rx_count = musb_readw(epio, MUSB_RXCOUNT);
  421. musb_dbg(musb, "RX%d count %d, buffer %p len %d/%d", epnum, rx_count,
  422. urb->transfer_buffer, qh->offset,
  423. urb->transfer_buffer_length);
  424. /* unload FIFO */
  425. if (usb_pipeisoc(pipe)) {
  426. int status = 0;
  427. struct usb_iso_packet_descriptor *d;
  428. if (iso_err) {
  429. status = -EILSEQ;
  430. urb->error_count++;
  431. }
  432. d = urb->iso_frame_desc + qh->iso_idx;
  433. buf = buffer + d->offset;
  434. length = d->length;
  435. if (rx_count > length) {
  436. if (status == 0) {
  437. status = -EOVERFLOW;
  438. urb->error_count++;
  439. }
  440. musb_dbg(musb, "OVERFLOW %d into %d", rx_count, length);
  441. do_flush = 1;
  442. } else
  443. length = rx_count;
  444. urb->actual_length += length;
  445. d->actual_length = length;
  446. d->status = status;
  447. /* see if we are done */
  448. done = (++qh->iso_idx >= urb->number_of_packets);
  449. } else {
  450. /* non-isoch */
  451. buf = buffer + qh->offset;
  452. length = urb->transfer_buffer_length - qh->offset;
  453. if (rx_count > length) {
  454. if (urb->status == -EINPROGRESS)
  455. urb->status = -EOVERFLOW;
  456. musb_dbg(musb, "OVERFLOW %d into %d", rx_count, length);
  457. do_flush = 1;
  458. } else
  459. length = rx_count;
  460. urb->actual_length += length;
  461. qh->offset += length;
  462. /* see if we are done */
  463. done = (urb->actual_length == urb->transfer_buffer_length)
  464. || (rx_count < qh->maxpacket)
  465. || (urb->status != -EINPROGRESS);
  466. if (done
  467. && (urb->status == -EINPROGRESS)
  468. && (urb->transfer_flags & URB_SHORT_NOT_OK)
  469. && (urb->actual_length
  470. < urb->transfer_buffer_length))
  471. urb->status = -EREMOTEIO;
  472. }
  473. musb_read_fifo(hw_ep, length, buf);
  474. csr = musb_readw(epio, MUSB_RXCSR);
  475. csr |= MUSB_RXCSR_H_WZC_BITS;
  476. if (unlikely(do_flush))
  477. musb_h_flush_rxfifo(hw_ep, csr);
  478. else {
  479. /* REVISIT this assumes AUTOCLEAR is never set */
  480. csr &= ~(MUSB_RXCSR_RXPKTRDY | MUSB_RXCSR_H_REQPKT);
  481. if (!done)
  482. csr |= MUSB_RXCSR_H_REQPKT;
  483. musb_writew(epio, MUSB_RXCSR, csr);
  484. }
  485. return done;
  486. }
  487. /* we don't always need to reinit a given side of an endpoint...
  488. * when we do, use tx/rx reinit routine and then construct a new CSR
  489. * to address data toggle, NYET, and DMA or PIO.
  490. *
  491. * it's possible that driver bugs (especially for DMA) or aborting a
  492. * transfer might have left the endpoint busier than it should be.
  493. * the busy/not-empty tests are basically paranoia.
  494. */
  495. static void
  496. musb_rx_reinit(struct musb *musb, struct musb_qh *qh, u8 epnum)
  497. {
  498. struct musb_hw_ep *ep = musb->endpoints + epnum;
  499. u16 csr;
  500. /* NOTE: we know the "rx" fifo reinit never triggers for ep0.
  501. * That always uses tx_reinit since ep0 repurposes TX register
  502. * offsets; the initial SETUP packet is also a kind of OUT.
  503. */
  504. /* if programmed for Tx, put it in RX mode */
  505. if (ep->is_shared_fifo) {
  506. csr = musb_readw(ep->regs, MUSB_TXCSR);
  507. if (csr & MUSB_TXCSR_MODE) {
  508. musb_h_tx_flush_fifo(ep);
  509. csr = musb_readw(ep->regs, MUSB_TXCSR);
  510. musb_writew(ep->regs, MUSB_TXCSR,
  511. csr | MUSB_TXCSR_FRCDATATOG);
  512. }
  513. /*
  514. * Clear the MODE bit (and everything else) to enable Rx.
  515. * NOTE: we mustn't clear the DMAMODE bit before DMAENAB.
  516. */
  517. if (csr & MUSB_TXCSR_DMAMODE)
  518. musb_writew(ep->regs, MUSB_TXCSR, MUSB_TXCSR_DMAMODE);
  519. musb_writew(ep->regs, MUSB_TXCSR, 0);
  520. /* scrub all previous state, clearing toggle */
  521. }
  522. csr = musb_readw(ep->regs, MUSB_RXCSR);
  523. if (csr & MUSB_RXCSR_RXPKTRDY)
  524. WARNING("rx%d, packet/%d ready?\n", ep->epnum,
  525. musb_readw(ep->regs, MUSB_RXCOUNT));
  526. musb_h_flush_rxfifo(ep, MUSB_RXCSR_CLRDATATOG);
  527. /* target addr and (for multipoint) hub addr/port */
  528. if (musb->is_multipoint) {
  529. musb_write_rxfunaddr(musb, epnum, qh->addr_reg);
  530. musb_write_rxhubaddr(musb, epnum, qh->h_addr_reg);
  531. musb_write_rxhubport(musb, epnum, qh->h_port_reg);
  532. } else
  533. musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg);
  534. /* protocol/endpoint, interval/NAKlimit, i/o size */
  535. musb_writeb(ep->regs, MUSB_RXTYPE, qh->type_reg);
  536. musb_writeb(ep->regs, MUSB_RXINTERVAL, qh->intv_reg);
  537. /* NOTE: bulk combining rewrites high bits of maxpacket */
  538. /* Set RXMAXP with the FIFO size of the endpoint
  539. * to disable double buffer mode.
  540. */
  541. if (musb->double_buffer_not_ok)
  542. musb_writew(ep->regs, MUSB_RXMAXP, ep->max_packet_sz_rx);
  543. else
  544. musb_writew(ep->regs, MUSB_RXMAXP,
  545. qh->maxpacket | ((qh->hb_mult - 1) << 11));
  546. ep->rx_reinit = 0;
  547. }
  548. static void musb_tx_dma_set_mode_mentor(struct dma_controller *dma,
  549. struct musb_hw_ep *hw_ep, struct musb_qh *qh,
  550. struct urb *urb, u32 offset,
  551. u32 *length, u8 *mode)
  552. {
  553. struct dma_channel *channel = hw_ep->tx_channel;
  554. void __iomem *epio = hw_ep->regs;
  555. u16 pkt_size = qh->maxpacket;
  556. u16 csr;
  557. if (*length > channel->max_len)
  558. *length = channel->max_len;
  559. csr = musb_readw(epio, MUSB_TXCSR);
  560. if (*length > pkt_size) {
  561. *mode = 1;
  562. csr |= MUSB_TXCSR_DMAMODE | MUSB_TXCSR_DMAENAB;
  563. /* autoset shouldn't be set in high bandwidth */
  564. /*
  565. * Enable Autoset according to table
  566. * below
  567. * bulk_split hb_mult Autoset_Enable
  568. * 0 1 Yes(Normal)
  569. * 0 >1 No(High BW ISO)
  570. * 1 1 Yes(HS bulk)
  571. * 1 >1 Yes(FS bulk)
  572. */
  573. if (qh->hb_mult == 1 || (qh->hb_mult > 1 &&
  574. can_bulk_split(hw_ep->musb, qh->type)))
  575. csr |= MUSB_TXCSR_AUTOSET;
  576. } else {
  577. *mode = 0;
  578. csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAMODE);
  579. csr |= MUSB_TXCSR_DMAENAB; /* against programmer's guide */
  580. }
  581. channel->desired_mode = *mode;
  582. musb_writew(epio, MUSB_TXCSR, csr);
  583. }
  584. static void musb_tx_dma_set_mode_cppi_tusb(struct dma_controller *dma,
  585. struct musb_hw_ep *hw_ep,
  586. struct musb_qh *qh,
  587. struct urb *urb,
  588. u32 offset,
  589. u32 *length,
  590. u8 *mode)
  591. {
  592. struct dma_channel *channel = hw_ep->tx_channel;
  593. channel->actual_len = 0;
  594. /*
  595. * TX uses "RNDIS" mode automatically but needs help
  596. * to identify the zero-length-final-packet case.
  597. */
  598. *mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0;
  599. }
  600. static bool musb_tx_dma_program(struct dma_controller *dma,
  601. struct musb_hw_ep *hw_ep, struct musb_qh *qh,
  602. struct urb *urb, u32 offset, u32 length)
  603. {
  604. struct dma_channel *channel = hw_ep->tx_channel;
  605. u16 pkt_size = qh->maxpacket;
  606. u8 mode;
  607. if (musb_dma_inventra(hw_ep->musb) || musb_dma_ux500(hw_ep->musb))
  608. musb_tx_dma_set_mode_mentor(dma, hw_ep, qh, urb, offset,
  609. &length, &mode);
  610. else if (is_cppi_enabled(hw_ep->musb) || tusb_dma_omap(hw_ep->musb))
  611. musb_tx_dma_set_mode_cppi_tusb(dma, hw_ep, qh, urb, offset,
  612. &length, &mode);
  613. else
  614. return false;
  615. qh->segsize = length;
  616. /*
  617. * Ensure the data reaches to main memory before starting
  618. * DMA transfer
  619. */
  620. wmb();
  621. if (!dma->channel_program(channel, pkt_size, mode,
  622. urb->transfer_dma + offset, length)) {
  623. void __iomem *epio = hw_ep->regs;
  624. u16 csr;
  625. dma->channel_release(channel);
  626. hw_ep->tx_channel = NULL;
  627. csr = musb_readw(epio, MUSB_TXCSR);
  628. csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAENAB);
  629. musb_writew(epio, MUSB_TXCSR, csr | MUSB_TXCSR_H_WZC_BITS);
  630. return false;
  631. }
  632. return true;
  633. }
  634. /*
  635. * Program an HDRC endpoint as per the given URB
  636. * Context: irqs blocked, controller lock held
  637. */
  638. static void musb_ep_program(struct musb *musb, u8 epnum,
  639. struct urb *urb, int is_out,
  640. u8 *buf, u32 offset, u32 len)
  641. {
  642. struct dma_controller *dma_controller;
  643. struct dma_channel *dma_channel;
  644. u8 dma_ok;
  645. void __iomem *mbase = musb->mregs;
  646. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  647. void __iomem *epio = hw_ep->regs;
  648. struct musb_qh *qh = musb_ep_get_qh(hw_ep, !is_out);
  649. u16 packet_sz = qh->maxpacket;
  650. u8 use_dma = 1;
  651. u16 csr;
  652. musb_dbg(musb, "%s hw%d urb %p spd%d dev%d ep%d%s "
  653. "h_addr%02x h_port%02x bytes %d",
  654. is_out ? "-->" : "<--",
  655. epnum, urb, urb->dev->speed,
  656. qh->addr_reg, qh->epnum, is_out ? "out" : "in",
  657. qh->h_addr_reg, qh->h_port_reg,
  658. len);
  659. musb_ep_select(mbase, epnum);
  660. if (is_out && !len) {
  661. use_dma = 0;
  662. csr = musb_readw(epio, MUSB_TXCSR);
  663. csr &= ~MUSB_TXCSR_DMAENAB;
  664. musb_writew(epio, MUSB_TXCSR, csr);
  665. hw_ep->tx_channel = NULL;
  666. }
  667. /* candidate for DMA? */
  668. dma_controller = musb->dma_controller;
  669. if (use_dma && is_dma_capable() && epnum && dma_controller) {
  670. dma_channel = is_out ? hw_ep->tx_channel : hw_ep->rx_channel;
  671. if (!dma_channel) {
  672. dma_channel = dma_controller->channel_alloc(
  673. dma_controller, hw_ep, is_out);
  674. if (is_out)
  675. hw_ep->tx_channel = dma_channel;
  676. else
  677. hw_ep->rx_channel = dma_channel;
  678. }
  679. } else
  680. dma_channel = NULL;
  681. /* make sure we clear DMAEnab, autoSet bits from previous run */
  682. /* OUT/transmit/EP0 or IN/receive? */
  683. if (is_out) {
  684. u16 csr;
  685. u16 int_txe;
  686. u16 load_count;
  687. csr = musb_readw(epio, MUSB_TXCSR);
  688. /* disable interrupt in case we flush */
  689. int_txe = musb->intrtxe;
  690. musb_writew(mbase, MUSB_INTRTXE, int_txe & ~(1 << epnum));
  691. /* general endpoint setup */
  692. if (epnum) {
  693. /* flush all old state, set default */
  694. /*
  695. * We could be flushing valid
  696. * packets in double buffering
  697. * case
  698. */
  699. if (!hw_ep->tx_double_buffered)
  700. musb_h_tx_flush_fifo(hw_ep);
  701. /*
  702. * We must not clear the DMAMODE bit before or in
  703. * the same cycle with the DMAENAB bit, so we clear
  704. * the latter first...
  705. */
  706. csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
  707. | MUSB_TXCSR_AUTOSET
  708. | MUSB_TXCSR_DMAENAB
  709. | MUSB_TXCSR_FRCDATATOG
  710. | MUSB_TXCSR_H_RXSTALL
  711. | MUSB_TXCSR_H_ERROR
  712. | MUSB_TXCSR_TXPKTRDY
  713. );
  714. csr |= MUSB_TXCSR_MODE;
  715. if (!hw_ep->tx_double_buffered) {
  716. if (usb_gettoggle(urb->dev, qh->epnum, 1))
  717. csr |= MUSB_TXCSR_H_WR_DATATOGGLE
  718. | MUSB_TXCSR_H_DATATOGGLE;
  719. else
  720. csr |= MUSB_TXCSR_CLRDATATOG;
  721. }
  722. musb_writew(epio, MUSB_TXCSR, csr);
  723. /* REVISIT may need to clear FLUSHFIFO ... */
  724. csr &= ~MUSB_TXCSR_DMAMODE;
  725. musb_writew(epio, MUSB_TXCSR, csr);
  726. csr = musb_readw(epio, MUSB_TXCSR);
  727. } else {
  728. /* endpoint 0: just flush */
  729. musb_h_ep0_flush_fifo(hw_ep);
  730. }
  731. /* target addr and (for multipoint) hub addr/port */
  732. if (musb->is_multipoint) {
  733. musb_write_txfunaddr(musb, epnum, qh->addr_reg);
  734. musb_write_txhubaddr(musb, epnum, qh->h_addr_reg);
  735. musb_write_txhubport(musb, epnum, qh->h_port_reg);
  736. /* FIXME if !epnum, do the same for RX ... */
  737. } else
  738. musb_writeb(mbase, MUSB_FADDR, qh->addr_reg);
  739. /* protocol/endpoint/interval/NAKlimit */
  740. if (epnum) {
  741. musb_writeb(epio, MUSB_TXTYPE, qh->type_reg);
  742. if (musb->double_buffer_not_ok) {
  743. musb_writew(epio, MUSB_TXMAXP,
  744. hw_ep->max_packet_sz_tx);
  745. } else if (can_bulk_split(musb, qh->type)) {
  746. qh->hb_mult = hw_ep->max_packet_sz_tx
  747. / packet_sz;
  748. musb_writew(epio, MUSB_TXMAXP, packet_sz
  749. | ((qh->hb_mult) - 1) << 11);
  750. } else {
  751. musb_writew(epio, MUSB_TXMAXP,
  752. qh->maxpacket |
  753. ((qh->hb_mult - 1) << 11));
  754. }
  755. musb_writeb(epio, MUSB_TXINTERVAL, qh->intv_reg);
  756. } else {
  757. musb_writeb(epio, MUSB_NAKLIMIT0, qh->intv_reg);
  758. if (musb->is_multipoint)
  759. musb_writeb(epio, MUSB_TYPE0,
  760. qh->type_reg);
  761. }
  762. if (can_bulk_split(musb, qh->type))
  763. load_count = min((u32) hw_ep->max_packet_sz_tx,
  764. len);
  765. else
  766. load_count = min((u32) packet_sz, len);
  767. if (dma_channel && musb_tx_dma_program(dma_controller,
  768. hw_ep, qh, urb, offset, len))
  769. load_count = 0;
  770. if (load_count) {
  771. /* PIO to load FIFO */
  772. qh->segsize = load_count;
  773. if (!buf) {
  774. sg_miter_start(&qh->sg_miter, urb->sg, 1,
  775. SG_MITER_ATOMIC
  776. | SG_MITER_FROM_SG);
  777. if (!sg_miter_next(&qh->sg_miter)) {
  778. dev_err(musb->controller,
  779. "error: sg"
  780. "list empty\n");
  781. sg_miter_stop(&qh->sg_miter);
  782. goto finish;
  783. }
  784. buf = qh->sg_miter.addr + urb->sg->offset +
  785. urb->actual_length;
  786. load_count = min_t(u32, load_count,
  787. qh->sg_miter.length);
  788. musb_write_fifo(hw_ep, load_count, buf);
  789. qh->sg_miter.consumed = load_count;
  790. sg_miter_stop(&qh->sg_miter);
  791. } else
  792. musb_write_fifo(hw_ep, load_count, buf);
  793. }
  794. finish:
  795. /* re-enable interrupt */
  796. musb_writew(mbase, MUSB_INTRTXE, int_txe);
  797. /* IN/receive */
  798. } else {
  799. u16 csr;
  800. if (hw_ep->rx_reinit) {
  801. musb_rx_reinit(musb, qh, epnum);
  802. /* init new state: toggle and NYET, maybe DMA later */
  803. if (usb_gettoggle(urb->dev, qh->epnum, 0))
  804. csr = MUSB_RXCSR_H_WR_DATATOGGLE
  805. | MUSB_RXCSR_H_DATATOGGLE;
  806. else
  807. csr = 0;
  808. if (qh->type == USB_ENDPOINT_XFER_INT)
  809. csr |= MUSB_RXCSR_DISNYET;
  810. } else {
  811. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  812. if (csr & (MUSB_RXCSR_RXPKTRDY
  813. | MUSB_RXCSR_DMAENAB
  814. | MUSB_RXCSR_H_REQPKT))
  815. ERR("broken !rx_reinit, ep%d csr %04x\n",
  816. hw_ep->epnum, csr);
  817. /* scrub any stale state, leaving toggle alone */
  818. csr &= MUSB_RXCSR_DISNYET;
  819. }
  820. /* kick things off */
  821. if ((is_cppi_enabled(musb) || tusb_dma_omap(musb)) && dma_channel) {
  822. /* Candidate for DMA */
  823. dma_channel->actual_len = 0L;
  824. qh->segsize = len;
  825. /* AUTOREQ is in a DMA register */
  826. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  827. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  828. /*
  829. * Unless caller treats short RX transfers as
  830. * errors, we dare not queue multiple transfers.
  831. */
  832. dma_ok = dma_controller->channel_program(dma_channel,
  833. packet_sz, !(urb->transfer_flags &
  834. URB_SHORT_NOT_OK),
  835. urb->transfer_dma + offset,
  836. qh->segsize);
  837. if (!dma_ok) {
  838. dma_controller->channel_release(dma_channel);
  839. hw_ep->rx_channel = dma_channel = NULL;
  840. } else
  841. csr |= MUSB_RXCSR_DMAENAB;
  842. }
  843. csr |= MUSB_RXCSR_H_REQPKT;
  844. musb_dbg(musb, "RXCSR%d := %04x", epnum, csr);
  845. musb_writew(hw_ep->regs, MUSB_RXCSR, csr);
  846. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  847. }
  848. }
  849. /* Schedule next QH from musb->in_bulk/out_bulk and move the current qh to
  850. * the end; avoids starvation for other endpoints.
  851. */
  852. static void musb_bulk_nak_timeout(struct musb *musb, struct musb_hw_ep *ep,
  853. int is_in)
  854. {
  855. struct dma_channel *dma;
  856. struct urb *urb;
  857. void __iomem *mbase = musb->mregs;
  858. void __iomem *epio = ep->regs;
  859. struct musb_qh *cur_qh, *next_qh;
  860. u16 rx_csr, tx_csr;
  861. musb_ep_select(mbase, ep->epnum);
  862. if (is_in) {
  863. dma = is_dma_capable() ? ep->rx_channel : NULL;
  864. /*
  865. * Need to stop the transaction by clearing REQPKT first
  866. * then the NAK Timeout bit ref MUSBMHDRC USB 2.0 HIGH-SPEED
  867. * DUAL-ROLE CONTROLLER Programmer's Guide, section 9.2.2
  868. */
  869. rx_csr = musb_readw(epio, MUSB_RXCSR);
  870. rx_csr |= MUSB_RXCSR_H_WZC_BITS;
  871. rx_csr &= ~MUSB_RXCSR_H_REQPKT;
  872. musb_writew(epio, MUSB_RXCSR, rx_csr);
  873. rx_csr &= ~MUSB_RXCSR_DATAERROR;
  874. musb_writew(epio, MUSB_RXCSR, rx_csr);
  875. cur_qh = first_qh(&musb->in_bulk);
  876. } else {
  877. dma = is_dma_capable() ? ep->tx_channel : NULL;
  878. /* clear nak timeout bit */
  879. tx_csr = musb_readw(epio, MUSB_TXCSR);
  880. tx_csr |= MUSB_TXCSR_H_WZC_BITS;
  881. tx_csr &= ~MUSB_TXCSR_H_NAKTIMEOUT;
  882. musb_writew(epio, MUSB_TXCSR, tx_csr);
  883. cur_qh = first_qh(&musb->out_bulk);
  884. }
  885. if (cur_qh) {
  886. urb = next_urb(cur_qh);
  887. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  888. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  889. musb->dma_controller->channel_abort(dma);
  890. urb->actual_length += dma->actual_len;
  891. dma->actual_len = 0L;
  892. }
  893. musb_save_toggle(cur_qh, is_in, urb);
  894. if (is_in) {
  895. /* move cur_qh to end of queue */
  896. list_move_tail(&cur_qh->ring, &musb->in_bulk);
  897. /* get the next qh from musb->in_bulk */
  898. next_qh = first_qh(&musb->in_bulk);
  899. /* set rx_reinit and schedule the next qh */
  900. ep->rx_reinit = 1;
  901. } else {
  902. /* move cur_qh to end of queue */
  903. list_move_tail(&cur_qh->ring, &musb->out_bulk);
  904. /* get the next qh from musb->out_bulk */
  905. next_qh = first_qh(&musb->out_bulk);
  906. /* set tx_reinit and schedule the next qh */
  907. ep->tx_reinit = 1;
  908. }
  909. musb_start_urb(musb, is_in, next_qh);
  910. }
  911. }
  912. /*
  913. * Service the default endpoint (ep0) as host.
  914. * Return true until it's time to start the status stage.
  915. */
  916. static bool musb_h_ep0_continue(struct musb *musb, u16 len, struct urb *urb)
  917. {
  918. bool more = false;
  919. u8 *fifo_dest = NULL;
  920. u16 fifo_count = 0;
  921. struct musb_hw_ep *hw_ep = musb->control_ep;
  922. struct musb_qh *qh = hw_ep->in_qh;
  923. struct usb_ctrlrequest *request;
  924. switch (musb->ep0_stage) {
  925. case MUSB_EP0_IN:
  926. fifo_dest = urb->transfer_buffer + urb->actual_length;
  927. fifo_count = min_t(size_t, len, urb->transfer_buffer_length -
  928. urb->actual_length);
  929. if (fifo_count < len)
  930. urb->status = -EOVERFLOW;
  931. musb_read_fifo(hw_ep, fifo_count, fifo_dest);
  932. urb->actual_length += fifo_count;
  933. if (len < qh->maxpacket) {
  934. /* always terminate on short read; it's
  935. * rarely reported as an error.
  936. */
  937. } else if (urb->actual_length <
  938. urb->transfer_buffer_length)
  939. more = true;
  940. break;
  941. case MUSB_EP0_START:
  942. request = (struct usb_ctrlrequest *) urb->setup_packet;
  943. if (!request->wLength) {
  944. musb_dbg(musb, "start no-DATA");
  945. break;
  946. } else if (request->bRequestType & USB_DIR_IN) {
  947. musb_dbg(musb, "start IN-DATA");
  948. musb->ep0_stage = MUSB_EP0_IN;
  949. more = true;
  950. break;
  951. } else {
  952. musb_dbg(musb, "start OUT-DATA");
  953. musb->ep0_stage = MUSB_EP0_OUT;
  954. more = true;
  955. }
  956. /* FALLTHROUGH */
  957. case MUSB_EP0_OUT:
  958. fifo_count = min_t(size_t, qh->maxpacket,
  959. urb->transfer_buffer_length -
  960. urb->actual_length);
  961. if (fifo_count) {
  962. fifo_dest = (u8 *) (urb->transfer_buffer
  963. + urb->actual_length);
  964. musb_dbg(musb, "Sending %d byte%s to ep0 fifo %p",
  965. fifo_count,
  966. (fifo_count == 1) ? "" : "s",
  967. fifo_dest);
  968. musb_write_fifo(hw_ep, fifo_count, fifo_dest);
  969. urb->actual_length += fifo_count;
  970. more = true;
  971. }
  972. break;
  973. default:
  974. ERR("bogus ep0 stage %d\n", musb->ep0_stage);
  975. break;
  976. }
  977. return more;
  978. }
  979. /*
  980. * Handle default endpoint interrupt as host. Only called in IRQ time
  981. * from musb_interrupt().
  982. *
  983. * called with controller irqlocked
  984. */
  985. irqreturn_t musb_h_ep0_irq(struct musb *musb)
  986. {
  987. struct urb *urb;
  988. u16 csr, len;
  989. int status = 0;
  990. void __iomem *mbase = musb->mregs;
  991. struct musb_hw_ep *hw_ep = musb->control_ep;
  992. void __iomem *epio = hw_ep->regs;
  993. struct musb_qh *qh = hw_ep->in_qh;
  994. bool complete = false;
  995. irqreturn_t retval = IRQ_NONE;
  996. /* ep0 only has one queue, "in" */
  997. urb = next_urb(qh);
  998. musb_ep_select(mbase, 0);
  999. csr = musb_readw(epio, MUSB_CSR0);
  1000. len = (csr & MUSB_CSR0_RXPKTRDY)
  1001. ? musb_readb(epio, MUSB_COUNT0)
  1002. : 0;
  1003. musb_dbg(musb, "<== csr0 %04x, qh %p, count %d, urb %p, stage %d",
  1004. csr, qh, len, urb, musb->ep0_stage);
  1005. /* if we just did status stage, we are done */
  1006. if (MUSB_EP0_STATUS == musb->ep0_stage) {
  1007. retval = IRQ_HANDLED;
  1008. complete = true;
  1009. }
  1010. /* prepare status */
  1011. if (csr & MUSB_CSR0_H_RXSTALL) {
  1012. musb_dbg(musb, "STALLING ENDPOINT");
  1013. status = -EPIPE;
  1014. } else if (csr & MUSB_CSR0_H_ERROR) {
  1015. musb_dbg(musb, "no response, csr0 %04x", csr);
  1016. status = -EPROTO;
  1017. } else if (csr & MUSB_CSR0_H_NAKTIMEOUT) {
  1018. musb_dbg(musb, "control NAK timeout");
  1019. /* NOTE: this code path would be a good place to PAUSE a
  1020. * control transfer, if another one is queued, so that
  1021. * ep0 is more likely to stay busy. That's already done
  1022. * for bulk RX transfers.
  1023. *
  1024. * if (qh->ring.next != &musb->control), then
  1025. * we have a candidate... NAKing is *NOT* an error
  1026. */
  1027. musb_writew(epio, MUSB_CSR0, 0);
  1028. retval = IRQ_HANDLED;
  1029. }
  1030. if (status) {
  1031. musb_dbg(musb, "aborting");
  1032. retval = IRQ_HANDLED;
  1033. if (urb)
  1034. urb->status = status;
  1035. complete = true;
  1036. /* use the proper sequence to abort the transfer */
  1037. if (csr & MUSB_CSR0_H_REQPKT) {
  1038. csr &= ~MUSB_CSR0_H_REQPKT;
  1039. musb_writew(epio, MUSB_CSR0, csr);
  1040. csr &= ~MUSB_CSR0_H_NAKTIMEOUT;
  1041. musb_writew(epio, MUSB_CSR0, csr);
  1042. } else {
  1043. musb_h_ep0_flush_fifo(hw_ep);
  1044. }
  1045. musb_writeb(epio, MUSB_NAKLIMIT0, 0);
  1046. /* clear it */
  1047. musb_writew(epio, MUSB_CSR0, 0);
  1048. }
  1049. if (unlikely(!urb)) {
  1050. /* stop endpoint since we have no place for its data, this
  1051. * SHOULD NEVER HAPPEN! */
  1052. ERR("no URB for end 0\n");
  1053. musb_h_ep0_flush_fifo(hw_ep);
  1054. goto done;
  1055. }
  1056. if (!complete) {
  1057. /* call common logic and prepare response */
  1058. if (musb_h_ep0_continue(musb, len, urb)) {
  1059. /* more packets required */
  1060. csr = (MUSB_EP0_IN == musb->ep0_stage)
  1061. ? MUSB_CSR0_H_REQPKT : MUSB_CSR0_TXPKTRDY;
  1062. } else {
  1063. /* data transfer complete; perform status phase */
  1064. if (usb_pipeout(urb->pipe)
  1065. || !urb->transfer_buffer_length)
  1066. csr = MUSB_CSR0_H_STATUSPKT
  1067. | MUSB_CSR0_H_REQPKT;
  1068. else
  1069. csr = MUSB_CSR0_H_STATUSPKT
  1070. | MUSB_CSR0_TXPKTRDY;
  1071. /* disable ping token in status phase */
  1072. csr |= MUSB_CSR0_H_DIS_PING;
  1073. /* flag status stage */
  1074. musb->ep0_stage = MUSB_EP0_STATUS;
  1075. musb_dbg(musb, "ep0 STATUS, csr %04x", csr);
  1076. }
  1077. musb_writew(epio, MUSB_CSR0, csr);
  1078. retval = IRQ_HANDLED;
  1079. } else
  1080. musb->ep0_stage = MUSB_EP0_IDLE;
  1081. /* call completion handler if done */
  1082. if (complete)
  1083. musb_advance_schedule(musb, urb, hw_ep, 1);
  1084. done:
  1085. return retval;
  1086. }
  1087. #ifdef CONFIG_USB_INVENTRA_DMA
  1088. /* Host side TX (OUT) using Mentor DMA works as follows:
  1089. submit_urb ->
  1090. - if queue was empty, Program Endpoint
  1091. - ... which starts DMA to fifo in mode 1 or 0
  1092. DMA Isr (transfer complete) -> TxAvail()
  1093. - Stop DMA (~DmaEnab) (<--- Alert ... currently happens
  1094. only in musb_cleanup_urb)
  1095. - TxPktRdy has to be set in mode 0 or for
  1096. short packets in mode 1.
  1097. */
  1098. #endif
  1099. /* Service a Tx-Available or dma completion irq for the endpoint */
  1100. void musb_host_tx(struct musb *musb, u8 epnum)
  1101. {
  1102. int pipe;
  1103. bool done = false;
  1104. u16 tx_csr;
  1105. size_t length = 0;
  1106. size_t offset = 0;
  1107. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  1108. void __iomem *epio = hw_ep->regs;
  1109. struct musb_qh *qh = hw_ep->out_qh;
  1110. struct urb *urb = next_urb(qh);
  1111. u32 status = 0;
  1112. void __iomem *mbase = musb->mregs;
  1113. struct dma_channel *dma;
  1114. bool transfer_pending = false;
  1115. musb_ep_select(mbase, epnum);
  1116. tx_csr = musb_readw(epio, MUSB_TXCSR);
  1117. /* with CPPI, DMA sometimes triggers "extra" irqs */
  1118. if (!urb) {
  1119. musb_dbg(musb, "extra TX%d ready, csr %04x", epnum, tx_csr);
  1120. return;
  1121. }
  1122. pipe = urb->pipe;
  1123. dma = is_dma_capable() ? hw_ep->tx_channel : NULL;
  1124. trace_musb_urb_tx(musb, urb);
  1125. musb_dbg(musb, "OUT/TX%d end, csr %04x%s", epnum, tx_csr,
  1126. dma ? ", dma" : "");
  1127. /* check for errors */
  1128. if (tx_csr & MUSB_TXCSR_H_RXSTALL) {
  1129. /* dma was disabled, fifo flushed */
  1130. musb_dbg(musb, "TX end %d stall", epnum);
  1131. /* stall; record URB status */
  1132. status = -EPIPE;
  1133. } else if (tx_csr & MUSB_TXCSR_H_ERROR) {
  1134. /* (NON-ISO) dma was disabled, fifo flushed */
  1135. musb_dbg(musb, "TX 3strikes on ep=%d", epnum);
  1136. status = -ETIMEDOUT;
  1137. } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) {
  1138. if (USB_ENDPOINT_XFER_BULK == qh->type && qh->mux == 1
  1139. && !list_is_singular(&musb->out_bulk)) {
  1140. musb_dbg(musb, "NAK timeout on TX%d ep", epnum);
  1141. musb_bulk_nak_timeout(musb, hw_ep, 0);
  1142. } else {
  1143. musb_dbg(musb, "TX ep%d device not responding", epnum);
  1144. /* NOTE: this code path would be a good place to PAUSE a
  1145. * transfer, if there's some other (nonperiodic) tx urb
  1146. * that could use this fifo. (dma complicates it...)
  1147. * That's already done for bulk RX transfers.
  1148. *
  1149. * if (bulk && qh->ring.next != &musb->out_bulk), then
  1150. * we have a candidate... NAKing is *NOT* an error
  1151. */
  1152. musb_ep_select(mbase, epnum);
  1153. musb_writew(epio, MUSB_TXCSR,
  1154. MUSB_TXCSR_H_WZC_BITS
  1155. | MUSB_TXCSR_TXPKTRDY);
  1156. }
  1157. return;
  1158. }
  1159. done:
  1160. if (status) {
  1161. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1162. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1163. musb->dma_controller->channel_abort(dma);
  1164. }
  1165. /* do the proper sequence to abort the transfer in the
  1166. * usb core; the dma engine should already be stopped.
  1167. */
  1168. musb_h_tx_flush_fifo(hw_ep);
  1169. tx_csr &= ~(MUSB_TXCSR_AUTOSET
  1170. | MUSB_TXCSR_DMAENAB
  1171. | MUSB_TXCSR_H_ERROR
  1172. | MUSB_TXCSR_H_RXSTALL
  1173. | MUSB_TXCSR_H_NAKTIMEOUT
  1174. );
  1175. musb_ep_select(mbase, epnum);
  1176. musb_writew(epio, MUSB_TXCSR, tx_csr);
  1177. /* REVISIT may need to clear FLUSHFIFO ... */
  1178. musb_writew(epio, MUSB_TXCSR, tx_csr);
  1179. musb_writeb(epio, MUSB_TXINTERVAL, 0);
  1180. done = true;
  1181. }
  1182. /* second cppi case */
  1183. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1184. musb_dbg(musb, "extra TX%d ready, csr %04x", epnum, tx_csr);
  1185. return;
  1186. }
  1187. if (is_dma_capable() && dma && !status) {
  1188. /*
  1189. * DMA has completed. But if we're using DMA mode 1 (multi
  1190. * packet DMA), we need a terminal TXPKTRDY interrupt before
  1191. * we can consider this transfer completed, lest we trash
  1192. * its last packet when writing the next URB's data. So we
  1193. * switch back to mode 0 to get that interrupt; we'll come
  1194. * back here once it happens.
  1195. */
  1196. if (tx_csr & MUSB_TXCSR_DMAMODE) {
  1197. /*
  1198. * We shouldn't clear DMAMODE with DMAENAB set; so
  1199. * clear them in a safe order. That should be OK
  1200. * once TXPKTRDY has been set (and I've never seen
  1201. * it being 0 at this moment -- DMA interrupt latency
  1202. * is significant) but if it hasn't been then we have
  1203. * no choice but to stop being polite and ignore the
  1204. * programmer's guide... :-)
  1205. *
  1206. * Note that we must write TXCSR with TXPKTRDY cleared
  1207. * in order not to re-trigger the packet send (this bit
  1208. * can't be cleared by CPU), and there's another caveat:
  1209. * TXPKTRDY may be set shortly and then cleared in the
  1210. * double-buffered FIFO mode, so we do an extra TXCSR
  1211. * read for debouncing...
  1212. */
  1213. tx_csr &= musb_readw(epio, MUSB_TXCSR);
  1214. if (tx_csr & MUSB_TXCSR_TXPKTRDY) {
  1215. tx_csr &= ~(MUSB_TXCSR_DMAENAB |
  1216. MUSB_TXCSR_TXPKTRDY);
  1217. musb_writew(epio, MUSB_TXCSR,
  1218. tx_csr | MUSB_TXCSR_H_WZC_BITS);
  1219. }
  1220. tx_csr &= ~(MUSB_TXCSR_DMAMODE |
  1221. MUSB_TXCSR_TXPKTRDY);
  1222. musb_writew(epio, MUSB_TXCSR,
  1223. tx_csr | MUSB_TXCSR_H_WZC_BITS);
  1224. /*
  1225. * There is no guarantee that we'll get an interrupt
  1226. * after clearing DMAMODE as we might have done this
  1227. * too late (after TXPKTRDY was cleared by controller).
  1228. * Re-read TXCSR as we have spoiled its previous value.
  1229. */
  1230. tx_csr = musb_readw(epio, MUSB_TXCSR);
  1231. }
  1232. /*
  1233. * We may get here from a DMA completion or TXPKTRDY interrupt.
  1234. * In any case, we must check the FIFO status here and bail out
  1235. * only if the FIFO still has data -- that should prevent the
  1236. * "missed" TXPKTRDY interrupts and deal with double-buffered
  1237. * FIFO mode too...
  1238. */
  1239. if (tx_csr & (MUSB_TXCSR_FIFONOTEMPTY | MUSB_TXCSR_TXPKTRDY)) {
  1240. musb_dbg(musb,
  1241. "DMA complete but FIFO not empty, CSR %04x",
  1242. tx_csr);
  1243. return;
  1244. }
  1245. }
  1246. if (!status || dma || usb_pipeisoc(pipe)) {
  1247. if (dma)
  1248. length = dma->actual_len;
  1249. else
  1250. length = qh->segsize;
  1251. qh->offset += length;
  1252. if (usb_pipeisoc(pipe)) {
  1253. struct usb_iso_packet_descriptor *d;
  1254. d = urb->iso_frame_desc + qh->iso_idx;
  1255. d->actual_length = length;
  1256. d->status = status;
  1257. if (++qh->iso_idx >= urb->number_of_packets) {
  1258. done = true;
  1259. } else {
  1260. d++;
  1261. offset = d->offset;
  1262. length = d->length;
  1263. }
  1264. } else if (dma && urb->transfer_buffer_length == qh->offset) {
  1265. done = true;
  1266. } else {
  1267. /* see if we need to send more data, or ZLP */
  1268. if (qh->segsize < qh->maxpacket)
  1269. done = true;
  1270. else if (qh->offset == urb->transfer_buffer_length
  1271. && !(urb->transfer_flags
  1272. & URB_ZERO_PACKET))
  1273. done = true;
  1274. if (!done) {
  1275. offset = qh->offset;
  1276. length = urb->transfer_buffer_length - offset;
  1277. transfer_pending = true;
  1278. }
  1279. }
  1280. }
  1281. /* urb->status != -EINPROGRESS means request has been faulted,
  1282. * so we must abort this transfer after cleanup
  1283. */
  1284. if (urb->status != -EINPROGRESS) {
  1285. done = true;
  1286. if (status == 0)
  1287. status = urb->status;
  1288. }
  1289. if (done) {
  1290. /* set status */
  1291. urb->status = status;
  1292. urb->actual_length = qh->offset;
  1293. musb_advance_schedule(musb, urb, hw_ep, USB_DIR_OUT);
  1294. return;
  1295. } else if ((usb_pipeisoc(pipe) || transfer_pending) && dma) {
  1296. if (musb_tx_dma_program(musb->dma_controller, hw_ep, qh, urb,
  1297. offset, length)) {
  1298. if (is_cppi_enabled(musb) || tusb_dma_omap(musb))
  1299. musb_h_tx_dma_start(hw_ep);
  1300. return;
  1301. }
  1302. } else if (tx_csr & MUSB_TXCSR_DMAENAB) {
  1303. musb_dbg(musb, "not complete, but DMA enabled?");
  1304. return;
  1305. }
  1306. /*
  1307. * PIO: start next packet in this URB.
  1308. *
  1309. * REVISIT: some docs say that when hw_ep->tx_double_buffered,
  1310. * (and presumably, FIFO is not half-full) we should write *two*
  1311. * packets before updating TXCSR; other docs disagree...
  1312. */
  1313. if (length > qh->maxpacket)
  1314. length = qh->maxpacket;
  1315. /* Unmap the buffer so that CPU can use it */
  1316. usb_hcd_unmap_urb_for_dma(musb->hcd, urb);
  1317. /*
  1318. * We need to map sg if the transfer_buffer is
  1319. * NULL.
  1320. */
  1321. if (!urb->transfer_buffer)
  1322. qh->use_sg = true;
  1323. if (qh->use_sg) {
  1324. /* sg_miter_start is already done in musb_ep_program */
  1325. if (!sg_miter_next(&qh->sg_miter)) {
  1326. dev_err(musb->controller, "error: sg list empty\n");
  1327. sg_miter_stop(&qh->sg_miter);
  1328. status = -EINVAL;
  1329. goto done;
  1330. }
  1331. urb->transfer_buffer = qh->sg_miter.addr;
  1332. length = min_t(u32, length, qh->sg_miter.length);
  1333. musb_write_fifo(hw_ep, length, urb->transfer_buffer);
  1334. qh->sg_miter.consumed = length;
  1335. sg_miter_stop(&qh->sg_miter);
  1336. } else {
  1337. musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
  1338. }
  1339. qh->segsize = length;
  1340. if (qh->use_sg) {
  1341. if (offset + length >= urb->transfer_buffer_length)
  1342. qh->use_sg = false;
  1343. }
  1344. musb_ep_select(mbase, epnum);
  1345. musb_writew(epio, MUSB_TXCSR,
  1346. MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY);
  1347. }
  1348. #ifdef CONFIG_USB_TI_CPPI41_DMA
  1349. /* Seems to set up ISO for cppi41 and not advance len. See commit c57c41d */
  1350. static int musb_rx_dma_iso_cppi41(struct dma_controller *dma,
  1351. struct musb_hw_ep *hw_ep,
  1352. struct musb_qh *qh,
  1353. struct urb *urb,
  1354. size_t len)
  1355. {
  1356. struct dma_channel *channel = hw_ep->rx_channel;
  1357. void __iomem *epio = hw_ep->regs;
  1358. dma_addr_t *buf;
  1359. u32 length;
  1360. u16 val;
  1361. buf = (void *)urb->iso_frame_desc[qh->iso_idx].offset +
  1362. (u32)urb->transfer_dma;
  1363. length = urb->iso_frame_desc[qh->iso_idx].length;
  1364. val = musb_readw(epio, MUSB_RXCSR);
  1365. val |= MUSB_RXCSR_DMAENAB;
  1366. musb_writew(hw_ep->regs, MUSB_RXCSR, val);
  1367. return dma->channel_program(channel, qh->maxpacket, 0,
  1368. (u32)buf, length);
  1369. }
  1370. #else
  1371. static inline int musb_rx_dma_iso_cppi41(struct dma_controller *dma,
  1372. struct musb_hw_ep *hw_ep,
  1373. struct musb_qh *qh,
  1374. struct urb *urb,
  1375. size_t len)
  1376. {
  1377. return false;
  1378. }
  1379. #endif
  1380. #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) || \
  1381. defined(CONFIG_USB_TI_CPPI41_DMA)
  1382. /* Host side RX (IN) using Mentor DMA works as follows:
  1383. submit_urb ->
  1384. - if queue was empty, ProgramEndpoint
  1385. - first IN token is sent out (by setting ReqPkt)
  1386. LinuxIsr -> RxReady()
  1387. /\ => first packet is received
  1388. | - Set in mode 0 (DmaEnab, ~ReqPkt)
  1389. | -> DMA Isr (transfer complete) -> RxReady()
  1390. | - Ack receive (~RxPktRdy), turn off DMA (~DmaEnab)
  1391. | - if urb not complete, send next IN token (ReqPkt)
  1392. | | else complete urb.
  1393. | |
  1394. ---------------------------
  1395. *
  1396. * Nuances of mode 1:
  1397. * For short packets, no ack (+RxPktRdy) is sent automatically
  1398. * (even if AutoClear is ON)
  1399. * For full packets, ack (~RxPktRdy) and next IN token (+ReqPkt) is sent
  1400. * automatically => major problem, as collecting the next packet becomes
  1401. * difficult. Hence mode 1 is not used.
  1402. *
  1403. * REVISIT
  1404. * All we care about at this driver level is that
  1405. * (a) all URBs terminate with REQPKT cleared and fifo(s) empty;
  1406. * (b) termination conditions are: short RX, or buffer full;
  1407. * (c) fault modes include
  1408. * - iff URB_SHORT_NOT_OK, short RX status is -EREMOTEIO.
  1409. * (and that endpoint's dma queue stops immediately)
  1410. * - overflow (full, PLUS more bytes in the terminal packet)
  1411. *
  1412. * So for example, usb-storage sets URB_SHORT_NOT_OK, and would
  1413. * thus be a great candidate for using mode 1 ... for all but the
  1414. * last packet of one URB's transfer.
  1415. */
  1416. static int musb_rx_dma_inventra_cppi41(struct dma_controller *dma,
  1417. struct musb_hw_ep *hw_ep,
  1418. struct musb_qh *qh,
  1419. struct urb *urb,
  1420. size_t len)
  1421. {
  1422. struct dma_channel *channel = hw_ep->rx_channel;
  1423. void __iomem *epio = hw_ep->regs;
  1424. u16 val;
  1425. int pipe;
  1426. bool done;
  1427. pipe = urb->pipe;
  1428. if (usb_pipeisoc(pipe)) {
  1429. struct usb_iso_packet_descriptor *d;
  1430. d = urb->iso_frame_desc + qh->iso_idx;
  1431. d->actual_length = len;
  1432. /* even if there was an error, we did the dma
  1433. * for iso_frame_desc->length
  1434. */
  1435. if (d->status != -EILSEQ && d->status != -EOVERFLOW)
  1436. d->status = 0;
  1437. if (++qh->iso_idx >= urb->number_of_packets) {
  1438. done = true;
  1439. } else {
  1440. /* REVISIT: Why ignore return value here? */
  1441. if (musb_dma_cppi41(hw_ep->musb))
  1442. done = musb_rx_dma_iso_cppi41(dma, hw_ep, qh,
  1443. urb, len);
  1444. done = false;
  1445. }
  1446. } else {
  1447. /* done if urb buffer is full or short packet is recd */
  1448. done = (urb->actual_length + len >=
  1449. urb->transfer_buffer_length
  1450. || channel->actual_len < qh->maxpacket
  1451. || channel->rx_packet_done);
  1452. }
  1453. /* send IN token for next packet, without AUTOREQ */
  1454. if (!done) {
  1455. val = musb_readw(epio, MUSB_RXCSR);
  1456. val |= MUSB_RXCSR_H_REQPKT;
  1457. musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val);
  1458. }
  1459. return done;
  1460. }
  1461. /* Disadvantage of using mode 1:
  1462. * It's basically usable only for mass storage class; essentially all
  1463. * other protocols also terminate transfers on short packets.
  1464. *
  1465. * Details:
  1466. * An extra IN token is sent at the end of the transfer (due to AUTOREQ)
  1467. * If you try to use mode 1 for (transfer_buffer_length - 512), and try
  1468. * to use the extra IN token to grab the last packet using mode 0, then
  1469. * the problem is that you cannot be sure when the device will send the
  1470. * last packet and RxPktRdy set. Sometimes the packet is recd too soon
  1471. * such that it gets lost when RxCSR is re-set at the end of the mode 1
  1472. * transfer, while sometimes it is recd just a little late so that if you
  1473. * try to configure for mode 0 soon after the mode 1 transfer is
  1474. * completed, you will find rxcount 0. Okay, so you might think why not
  1475. * wait for an interrupt when the pkt is recd. Well, you won't get any!
  1476. */
  1477. static int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma,
  1478. struct musb_hw_ep *hw_ep,
  1479. struct musb_qh *qh,
  1480. struct urb *urb,
  1481. size_t len,
  1482. u8 iso_err)
  1483. {
  1484. struct musb *musb = hw_ep->musb;
  1485. void __iomem *epio = hw_ep->regs;
  1486. struct dma_channel *channel = hw_ep->rx_channel;
  1487. u16 rx_count, val;
  1488. int length, pipe, done;
  1489. dma_addr_t buf;
  1490. rx_count = musb_readw(epio, MUSB_RXCOUNT);
  1491. pipe = urb->pipe;
  1492. if (usb_pipeisoc(pipe)) {
  1493. int d_status = 0;
  1494. struct usb_iso_packet_descriptor *d;
  1495. d = urb->iso_frame_desc + qh->iso_idx;
  1496. if (iso_err) {
  1497. d_status = -EILSEQ;
  1498. urb->error_count++;
  1499. }
  1500. if (rx_count > d->length) {
  1501. if (d_status == 0) {
  1502. d_status = -EOVERFLOW;
  1503. urb->error_count++;
  1504. }
  1505. musb_dbg(musb, "** OVERFLOW %d into %d",
  1506. rx_count, d->length);
  1507. length = d->length;
  1508. } else
  1509. length = rx_count;
  1510. d->status = d_status;
  1511. buf = urb->transfer_dma + d->offset;
  1512. } else {
  1513. length = rx_count;
  1514. buf = urb->transfer_dma + urb->actual_length;
  1515. }
  1516. channel->desired_mode = 0;
  1517. #ifdef USE_MODE1
  1518. /* because of the issue below, mode 1 will
  1519. * only rarely behave with correct semantics.
  1520. */
  1521. if ((urb->transfer_flags & URB_SHORT_NOT_OK)
  1522. && (urb->transfer_buffer_length - urb->actual_length)
  1523. > qh->maxpacket)
  1524. channel->desired_mode = 1;
  1525. if (rx_count < hw_ep->max_packet_sz_rx) {
  1526. length = rx_count;
  1527. channel->desired_mode = 0;
  1528. } else {
  1529. length = urb->transfer_buffer_length;
  1530. }
  1531. #endif
  1532. /* See comments above on disadvantages of using mode 1 */
  1533. val = musb_readw(epio, MUSB_RXCSR);
  1534. val &= ~MUSB_RXCSR_H_REQPKT;
  1535. if (channel->desired_mode == 0)
  1536. val &= ~MUSB_RXCSR_H_AUTOREQ;
  1537. else
  1538. val |= MUSB_RXCSR_H_AUTOREQ;
  1539. val |= MUSB_RXCSR_DMAENAB;
  1540. /* autoclear shouldn't be set in high bandwidth */
  1541. if (qh->hb_mult == 1)
  1542. val |= MUSB_RXCSR_AUTOCLEAR;
  1543. musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val);
  1544. /* REVISIT if when actual_length != 0,
  1545. * transfer_buffer_length needs to be
  1546. * adjusted first...
  1547. */
  1548. done = dma->channel_program(channel, qh->maxpacket,
  1549. channel->desired_mode,
  1550. buf, length);
  1551. if (!done) {
  1552. dma->channel_release(channel);
  1553. hw_ep->rx_channel = NULL;
  1554. channel = NULL;
  1555. val = musb_readw(epio, MUSB_RXCSR);
  1556. val &= ~(MUSB_RXCSR_DMAENAB
  1557. | MUSB_RXCSR_H_AUTOREQ
  1558. | MUSB_RXCSR_AUTOCLEAR);
  1559. musb_writew(epio, MUSB_RXCSR, val);
  1560. }
  1561. return done;
  1562. }
  1563. #else
  1564. static inline int musb_rx_dma_inventra_cppi41(struct dma_controller *dma,
  1565. struct musb_hw_ep *hw_ep,
  1566. struct musb_qh *qh,
  1567. struct urb *urb,
  1568. size_t len)
  1569. {
  1570. return false;
  1571. }
  1572. static inline int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma,
  1573. struct musb_hw_ep *hw_ep,
  1574. struct musb_qh *qh,
  1575. struct urb *urb,
  1576. size_t len,
  1577. u8 iso_err)
  1578. {
  1579. return false;
  1580. }
  1581. #endif
  1582. /*
  1583. * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
  1584. * and high-bandwidth IN transfer cases.
  1585. */
  1586. void musb_host_rx(struct musb *musb, u8 epnum)
  1587. {
  1588. struct urb *urb;
  1589. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  1590. struct dma_controller *c = musb->dma_controller;
  1591. void __iomem *epio = hw_ep->regs;
  1592. struct musb_qh *qh = hw_ep->in_qh;
  1593. size_t xfer_len;
  1594. void __iomem *mbase = musb->mregs;
  1595. int pipe;
  1596. u16 rx_csr, val;
  1597. bool iso_err = false;
  1598. bool done = false;
  1599. u32 status;
  1600. struct dma_channel *dma;
  1601. unsigned int sg_flags = SG_MITER_ATOMIC | SG_MITER_TO_SG;
  1602. musb_ep_select(mbase, epnum);
  1603. urb = next_urb(qh);
  1604. dma = is_dma_capable() ? hw_ep->rx_channel : NULL;
  1605. status = 0;
  1606. xfer_len = 0;
  1607. rx_csr = musb_readw(epio, MUSB_RXCSR);
  1608. val = rx_csr;
  1609. if (unlikely(!urb)) {
  1610. /* REVISIT -- THIS SHOULD NEVER HAPPEN ... but, at least
  1611. * usbtest #11 (unlinks) triggers it regularly, sometimes
  1612. * with fifo full. (Only with DMA??)
  1613. */
  1614. musb_dbg(musb, "BOGUS RX%d ready, csr %04x, count %d",
  1615. epnum, val, musb_readw(epio, MUSB_RXCOUNT));
  1616. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1617. return;
  1618. }
  1619. pipe = urb->pipe;
  1620. trace_musb_urb_rx(musb, urb);
  1621. /* check for errors, concurrent stall & unlink is not really
  1622. * handled yet! */
  1623. if (rx_csr & MUSB_RXCSR_H_RXSTALL) {
  1624. musb_dbg(musb, "RX end %d STALL", epnum);
  1625. /* stall; record URB status */
  1626. status = -EPIPE;
  1627. } else if (rx_csr & MUSB_RXCSR_H_ERROR) {
  1628. musb_dbg(musb, "end %d RX proto error", epnum);
  1629. status = -EPROTO;
  1630. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1631. rx_csr &= ~MUSB_RXCSR_H_ERROR;
  1632. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1633. } else if (rx_csr & MUSB_RXCSR_DATAERROR) {
  1634. if (USB_ENDPOINT_XFER_ISOC != qh->type) {
  1635. musb_dbg(musb, "RX end %d NAK timeout", epnum);
  1636. /* NOTE: NAKing is *NOT* an error, so we want to
  1637. * continue. Except ... if there's a request for
  1638. * another QH, use that instead of starving it.
  1639. *
  1640. * Devices like Ethernet and serial adapters keep
  1641. * reads posted at all times, which will starve
  1642. * other devices without this logic.
  1643. */
  1644. if (usb_pipebulk(urb->pipe)
  1645. && qh->mux == 1
  1646. && !list_is_singular(&musb->in_bulk)) {
  1647. musb_bulk_nak_timeout(musb, hw_ep, 1);
  1648. return;
  1649. }
  1650. musb_ep_select(mbase, epnum);
  1651. rx_csr |= MUSB_RXCSR_H_WZC_BITS;
  1652. rx_csr &= ~MUSB_RXCSR_DATAERROR;
  1653. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1654. goto finish;
  1655. } else {
  1656. musb_dbg(musb, "RX end %d ISO data error", epnum);
  1657. /* packet error reported later */
  1658. iso_err = true;
  1659. }
  1660. } else if (rx_csr & MUSB_RXCSR_INCOMPRX) {
  1661. musb_dbg(musb, "end %d high bandwidth incomplete ISO packet RX",
  1662. epnum);
  1663. status = -EPROTO;
  1664. }
  1665. /* faults abort the transfer */
  1666. if (status) {
  1667. /* clean up dma and collect transfer count */
  1668. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1669. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1670. musb->dma_controller->channel_abort(dma);
  1671. xfer_len = dma->actual_len;
  1672. }
  1673. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1674. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1675. done = true;
  1676. goto finish;
  1677. }
  1678. if (unlikely(dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY)) {
  1679. /* SHOULD NEVER HAPPEN ... but at least DaVinci has done it */
  1680. ERR("RX%d dma busy, csr %04x\n", epnum, rx_csr);
  1681. goto finish;
  1682. }
  1683. /* thorough shutdown for now ... given more precise fault handling
  1684. * and better queueing support, we might keep a DMA pipeline going
  1685. * while processing this irq for earlier completions.
  1686. */
  1687. /* FIXME this is _way_ too much in-line logic for Mentor DMA */
  1688. if (!musb_dma_inventra(musb) && !musb_dma_ux500(musb) &&
  1689. (rx_csr & MUSB_RXCSR_H_REQPKT)) {
  1690. /* REVISIT this happened for a while on some short reads...
  1691. * the cleanup still needs investigation... looks bad...
  1692. * and also duplicates dma cleanup code above ... plus,
  1693. * shouldn't this be the "half full" double buffer case?
  1694. */
  1695. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1696. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1697. musb->dma_controller->channel_abort(dma);
  1698. xfer_len = dma->actual_len;
  1699. done = true;
  1700. }
  1701. musb_dbg(musb, "RXCSR%d %04x, reqpkt, len %zu%s", epnum, rx_csr,
  1702. xfer_len, dma ? ", dma" : "");
  1703. rx_csr &= ~MUSB_RXCSR_H_REQPKT;
  1704. musb_ep_select(mbase, epnum);
  1705. musb_writew(epio, MUSB_RXCSR,
  1706. MUSB_RXCSR_H_WZC_BITS | rx_csr);
  1707. }
  1708. if (dma && (rx_csr & MUSB_RXCSR_DMAENAB)) {
  1709. xfer_len = dma->actual_len;
  1710. val &= ~(MUSB_RXCSR_DMAENAB
  1711. | MUSB_RXCSR_H_AUTOREQ
  1712. | MUSB_RXCSR_AUTOCLEAR
  1713. | MUSB_RXCSR_RXPKTRDY);
  1714. musb_writew(hw_ep->regs, MUSB_RXCSR, val);
  1715. if (musb_dma_inventra(musb) || musb_dma_ux500(musb) ||
  1716. musb_dma_cppi41(musb)) {
  1717. done = musb_rx_dma_inventra_cppi41(c, hw_ep, qh, urb, xfer_len);
  1718. musb_dbg(hw_ep->musb,
  1719. "ep %d dma %s, rxcsr %04x, rxcount %d",
  1720. epnum, done ? "off" : "reset",
  1721. musb_readw(epio, MUSB_RXCSR),
  1722. musb_readw(epio, MUSB_RXCOUNT));
  1723. } else {
  1724. done = true;
  1725. }
  1726. } else if (urb->status == -EINPROGRESS) {
  1727. /* if no errors, be sure a packet is ready for unloading */
  1728. if (unlikely(!(rx_csr & MUSB_RXCSR_RXPKTRDY))) {
  1729. status = -EPROTO;
  1730. ERR("Rx interrupt with no errors or packet!\n");
  1731. /* FIXME this is another "SHOULD NEVER HAPPEN" */
  1732. /* SCRUB (RX) */
  1733. /* do the proper sequence to abort the transfer */
  1734. musb_ep_select(mbase, epnum);
  1735. val &= ~MUSB_RXCSR_H_REQPKT;
  1736. musb_writew(epio, MUSB_RXCSR, val);
  1737. goto finish;
  1738. }
  1739. /* we are expecting IN packets */
  1740. if ((musb_dma_inventra(musb) || musb_dma_ux500(musb) ||
  1741. musb_dma_cppi41(musb)) && dma) {
  1742. musb_dbg(hw_ep->musb,
  1743. "RX%d count %d, buffer 0x%llx len %d/%d",
  1744. epnum, musb_readw(epio, MUSB_RXCOUNT),
  1745. (unsigned long long) urb->transfer_dma
  1746. + urb->actual_length,
  1747. qh->offset,
  1748. urb->transfer_buffer_length);
  1749. if (musb_rx_dma_in_inventra_cppi41(c, hw_ep, qh, urb,
  1750. xfer_len, iso_err))
  1751. goto finish;
  1752. else
  1753. dev_err(musb->controller, "error: rx_dma failed\n");
  1754. }
  1755. if (!dma) {
  1756. unsigned int received_len;
  1757. /* Unmap the buffer so that CPU can use it */
  1758. usb_hcd_unmap_urb_for_dma(musb->hcd, urb);
  1759. /*
  1760. * We need to map sg if the transfer_buffer is
  1761. * NULL.
  1762. */
  1763. if (!urb->transfer_buffer) {
  1764. qh->use_sg = true;
  1765. sg_miter_start(&qh->sg_miter, urb->sg, 1,
  1766. sg_flags);
  1767. }
  1768. if (qh->use_sg) {
  1769. if (!sg_miter_next(&qh->sg_miter)) {
  1770. dev_err(musb->controller, "error: sg list empty\n");
  1771. sg_miter_stop(&qh->sg_miter);
  1772. status = -EINVAL;
  1773. done = true;
  1774. goto finish;
  1775. }
  1776. urb->transfer_buffer = qh->sg_miter.addr;
  1777. received_len = urb->actual_length;
  1778. qh->offset = 0x0;
  1779. done = musb_host_packet_rx(musb, urb, epnum,
  1780. iso_err);
  1781. /* Calculate the number of bytes received */
  1782. received_len = urb->actual_length -
  1783. received_len;
  1784. qh->sg_miter.consumed = received_len;
  1785. sg_miter_stop(&qh->sg_miter);
  1786. } else {
  1787. done = musb_host_packet_rx(musb, urb,
  1788. epnum, iso_err);
  1789. }
  1790. musb_dbg(musb, "read %spacket", done ? "last " : "");
  1791. }
  1792. }
  1793. finish:
  1794. urb->actual_length += xfer_len;
  1795. qh->offset += xfer_len;
  1796. if (done) {
  1797. if (qh->use_sg)
  1798. qh->use_sg = false;
  1799. if (urb->status == -EINPROGRESS)
  1800. urb->status = status;
  1801. musb_advance_schedule(musb, urb, hw_ep, USB_DIR_IN);
  1802. }
  1803. }
  1804. /* schedule nodes correspond to peripheral endpoints, like an OHCI QH.
  1805. * the software schedule associates multiple such nodes with a given
  1806. * host side hardware endpoint + direction; scheduling may activate
  1807. * that hardware endpoint.
  1808. */
  1809. static int musb_schedule(
  1810. struct musb *musb,
  1811. struct musb_qh *qh,
  1812. int is_in)
  1813. {
  1814. int idle = 0;
  1815. int best_diff;
  1816. int best_end, epnum;
  1817. struct musb_hw_ep *hw_ep = NULL;
  1818. struct list_head *head = NULL;
  1819. u8 toggle;
  1820. u8 txtype;
  1821. struct urb *urb = next_urb(qh);
  1822. /* use fixed hardware for control and bulk */
  1823. if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
  1824. head = &musb->control;
  1825. hw_ep = musb->control_ep;
  1826. goto success;
  1827. }
  1828. /* else, periodic transfers get muxed to other endpoints */
  1829. /*
  1830. * We know this qh hasn't been scheduled, so all we need to do
  1831. * is choose which hardware endpoint to put it on ...
  1832. *
  1833. * REVISIT what we really want here is a regular schedule tree
  1834. * like e.g. OHCI uses.
  1835. */
  1836. best_diff = 4096;
  1837. best_end = -1;
  1838. for (epnum = 1, hw_ep = musb->endpoints + 1;
  1839. epnum < musb->nr_endpoints;
  1840. epnum++, hw_ep++) {
  1841. int diff;
  1842. if (musb_ep_get_qh(hw_ep, is_in) != NULL)
  1843. continue;
  1844. if (hw_ep == musb->bulk_ep)
  1845. continue;
  1846. if (is_in)
  1847. diff = hw_ep->max_packet_sz_rx;
  1848. else
  1849. diff = hw_ep->max_packet_sz_tx;
  1850. diff -= (qh->maxpacket * qh->hb_mult);
  1851. if (diff >= 0 && best_diff > diff) {
  1852. /*
  1853. * Mentor controller has a bug in that if we schedule
  1854. * a BULK Tx transfer on an endpoint that had earlier
  1855. * handled ISOC then the BULK transfer has to start on
  1856. * a zero toggle. If the BULK transfer starts on a 1
  1857. * toggle then this transfer will fail as the mentor
  1858. * controller starts the Bulk transfer on a 0 toggle
  1859. * irrespective of the programming of the toggle bits
  1860. * in the TXCSR register. Check for this condition
  1861. * while allocating the EP for a Tx Bulk transfer. If
  1862. * so skip this EP.
  1863. */
  1864. hw_ep = musb->endpoints + epnum;
  1865. toggle = usb_gettoggle(urb->dev, qh->epnum, !is_in);
  1866. txtype = (musb_readb(hw_ep->regs, MUSB_TXTYPE)
  1867. >> 4) & 0x3;
  1868. if (!is_in && (qh->type == USB_ENDPOINT_XFER_BULK) &&
  1869. toggle && (txtype == USB_ENDPOINT_XFER_ISOC))
  1870. continue;
  1871. best_diff = diff;
  1872. best_end = epnum;
  1873. }
  1874. }
  1875. /* use bulk reserved ep1 if no other ep is free */
  1876. if (best_end < 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
  1877. hw_ep = musb->bulk_ep;
  1878. if (is_in)
  1879. head = &musb->in_bulk;
  1880. else
  1881. head = &musb->out_bulk;
  1882. /* Enable bulk RX/TX NAK timeout scheme when bulk requests are
  1883. * multiplexed. This scheme does not work in high speed to full
  1884. * speed scenario as NAK interrupts are not coming from a
  1885. * full speed device connected to a high speed device.
  1886. * NAK timeout interval is 8 (128 uframe or 16ms) for HS and
  1887. * 4 (8 frame or 8ms) for FS device.
  1888. */
  1889. if (qh->dev)
  1890. qh->intv_reg =
  1891. (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
  1892. goto success;
  1893. } else if (best_end < 0) {
  1894. dev_err(musb->controller,
  1895. "%s hwep alloc failed for %dx%d\n",
  1896. musb_ep_xfertype_string(qh->type),
  1897. qh->hb_mult, qh->maxpacket);
  1898. return -ENOSPC;
  1899. }
  1900. idle = 1;
  1901. qh->mux = 0;
  1902. hw_ep = musb->endpoints + best_end;
  1903. musb_dbg(musb, "qh %p periodic slot %d", qh, best_end);
  1904. success:
  1905. if (head) {
  1906. idle = list_empty(head);
  1907. list_add_tail(&qh->ring, head);
  1908. qh->mux = 1;
  1909. }
  1910. qh->hw_ep = hw_ep;
  1911. qh->hep->hcpriv = qh;
  1912. if (idle)
  1913. musb_start_urb(musb, is_in, qh);
  1914. return 0;
  1915. }
  1916. static int musb_urb_enqueue(
  1917. struct usb_hcd *hcd,
  1918. struct urb *urb,
  1919. gfp_t mem_flags)
  1920. {
  1921. unsigned long flags;
  1922. struct musb *musb = hcd_to_musb(hcd);
  1923. struct usb_host_endpoint *hep = urb->ep;
  1924. struct musb_qh *qh;
  1925. struct usb_endpoint_descriptor *epd = &hep->desc;
  1926. int ret;
  1927. unsigned type_reg;
  1928. unsigned interval;
  1929. /* host role must be active */
  1930. if (!is_host_active(musb) || !musb->is_active)
  1931. return -ENODEV;
  1932. trace_musb_urb_enq(musb, urb);
  1933. spin_lock_irqsave(&musb->lock, flags);
  1934. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  1935. qh = ret ? NULL : hep->hcpriv;
  1936. if (qh)
  1937. urb->hcpriv = qh;
  1938. spin_unlock_irqrestore(&musb->lock, flags);
  1939. /* DMA mapping was already done, if needed, and this urb is on
  1940. * hep->urb_list now ... so we're done, unless hep wasn't yet
  1941. * scheduled onto a live qh.
  1942. *
  1943. * REVISIT best to keep hep->hcpriv valid until the endpoint gets
  1944. * disabled, testing for empty qh->ring and avoiding qh setup costs
  1945. * except for the first urb queued after a config change.
  1946. */
  1947. if (qh || ret)
  1948. return ret;
  1949. /* Allocate and initialize qh, minimizing the work done each time
  1950. * hw_ep gets reprogrammed, or with irqs blocked. Then schedule it.
  1951. *
  1952. * REVISIT consider a dedicated qh kmem_cache, so it's harder
  1953. * for bugs in other kernel code to break this driver...
  1954. */
  1955. qh = kzalloc(sizeof *qh, mem_flags);
  1956. if (!qh) {
  1957. spin_lock_irqsave(&musb->lock, flags);
  1958. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1959. spin_unlock_irqrestore(&musb->lock, flags);
  1960. return -ENOMEM;
  1961. }
  1962. qh->hep = hep;
  1963. qh->dev = urb->dev;
  1964. INIT_LIST_HEAD(&qh->ring);
  1965. qh->is_ready = 1;
  1966. qh->maxpacket = usb_endpoint_maxp(epd);
  1967. qh->type = usb_endpoint_type(epd);
  1968. /* Bits 11 & 12 of wMaxPacketSize encode high bandwidth multiplier.
  1969. * Some musb cores don't support high bandwidth ISO transfers; and
  1970. * we don't (yet!) support high bandwidth interrupt transfers.
  1971. */
  1972. qh->hb_mult = usb_endpoint_maxp_mult(epd);
  1973. if (qh->hb_mult > 1) {
  1974. int ok = (qh->type == USB_ENDPOINT_XFER_ISOC);
  1975. if (ok)
  1976. ok = (usb_pipein(urb->pipe) && musb->hb_iso_rx)
  1977. || (usb_pipeout(urb->pipe) && musb->hb_iso_tx);
  1978. if (!ok) {
  1979. dev_err(musb->controller,
  1980. "high bandwidth %s (%dx%d) not supported\n",
  1981. musb_ep_xfertype_string(qh->type),
  1982. qh->hb_mult, qh->maxpacket & 0x7ff);
  1983. ret = -EMSGSIZE;
  1984. goto done;
  1985. }
  1986. qh->maxpacket &= 0x7ff;
  1987. }
  1988. qh->epnum = usb_endpoint_num(epd);
  1989. /* NOTE: urb->dev->devnum is wrong during SET_ADDRESS */
  1990. qh->addr_reg = (u8) usb_pipedevice(urb->pipe);
  1991. /* precompute rxtype/txtype/type0 register */
  1992. type_reg = (qh->type << 4) | qh->epnum;
  1993. switch (urb->dev->speed) {
  1994. case USB_SPEED_LOW:
  1995. type_reg |= 0xc0;
  1996. break;
  1997. case USB_SPEED_FULL:
  1998. type_reg |= 0x80;
  1999. break;
  2000. default:
  2001. type_reg |= 0x40;
  2002. }
  2003. qh->type_reg = type_reg;
  2004. /* Precompute RXINTERVAL/TXINTERVAL register */
  2005. switch (qh->type) {
  2006. case USB_ENDPOINT_XFER_INT:
  2007. /*
  2008. * Full/low speeds use the linear encoding,
  2009. * high speed uses the logarithmic encoding.
  2010. */
  2011. if (urb->dev->speed <= USB_SPEED_FULL) {
  2012. interval = max_t(u8, epd->bInterval, 1);
  2013. break;
  2014. }
  2015. /* FALLTHROUGH */
  2016. case USB_ENDPOINT_XFER_ISOC:
  2017. /* ISO always uses logarithmic encoding */
  2018. interval = min_t(u8, epd->bInterval, 16);
  2019. break;
  2020. default:
  2021. /* REVISIT we actually want to use NAK limits, hinting to the
  2022. * transfer scheduling logic to try some other qh, e.g. try
  2023. * for 2 msec first:
  2024. *
  2025. * interval = (USB_SPEED_HIGH == urb->dev->speed) ? 16 : 2;
  2026. *
  2027. * The downside of disabling this is that transfer scheduling
  2028. * gets VERY unfair for nonperiodic transfers; a misbehaving
  2029. * peripheral could make that hurt. That's perfectly normal
  2030. * for reads from network or serial adapters ... so we have
  2031. * partial NAKlimit support for bulk RX.
  2032. *
  2033. * The upside of disabling it is simpler transfer scheduling.
  2034. */
  2035. interval = 0;
  2036. }
  2037. qh->intv_reg = interval;
  2038. /* precompute addressing for external hub/tt ports */
  2039. if (musb->is_multipoint) {
  2040. struct usb_device *parent = urb->dev->parent;
  2041. if (parent != hcd->self.root_hub) {
  2042. qh->h_addr_reg = (u8) parent->devnum;
  2043. /* set up tt info if needed */
  2044. if (urb->dev->tt) {
  2045. qh->h_port_reg = (u8) urb->dev->ttport;
  2046. if (urb->dev->tt->hub)
  2047. qh->h_addr_reg =
  2048. (u8) urb->dev->tt->hub->devnum;
  2049. if (urb->dev->tt->multi)
  2050. qh->h_addr_reg |= 0x80;
  2051. }
  2052. }
  2053. }
  2054. /* invariant: hep->hcpriv is null OR the qh that's already scheduled.
  2055. * until we get real dma queues (with an entry for each urb/buffer),
  2056. * we only have work to do in the former case.
  2057. */
  2058. spin_lock_irqsave(&musb->lock, flags);
  2059. if (hep->hcpriv || !next_urb(qh)) {
  2060. /* some concurrent activity submitted another urb to hep...
  2061. * odd, rare, error prone, but legal.
  2062. */
  2063. kfree(qh);
  2064. qh = NULL;
  2065. ret = 0;
  2066. } else
  2067. ret = musb_schedule(musb, qh,
  2068. epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK);
  2069. if (ret == 0) {
  2070. urb->hcpriv = qh;
  2071. /* FIXME set urb->start_frame for iso/intr, it's tested in
  2072. * musb_start_urb(), but otherwise only konicawc cares ...
  2073. */
  2074. }
  2075. spin_unlock_irqrestore(&musb->lock, flags);
  2076. done:
  2077. if (ret != 0) {
  2078. spin_lock_irqsave(&musb->lock, flags);
  2079. usb_hcd_unlink_urb_from_ep(hcd, urb);
  2080. spin_unlock_irqrestore(&musb->lock, flags);
  2081. kfree(qh);
  2082. }
  2083. return ret;
  2084. }
  2085. /*
  2086. * abort a transfer that's at the head of a hardware queue.
  2087. * called with controller locked, irqs blocked
  2088. * that hardware queue advances to the next transfer, unless prevented
  2089. */
  2090. static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
  2091. {
  2092. struct musb_hw_ep *ep = qh->hw_ep;
  2093. struct musb *musb = ep->musb;
  2094. void __iomem *epio = ep->regs;
  2095. unsigned hw_end = ep->epnum;
  2096. void __iomem *regs = ep->musb->mregs;
  2097. int is_in = usb_pipein(urb->pipe);
  2098. int status = 0;
  2099. u16 csr;
  2100. struct dma_channel *dma = NULL;
  2101. musb_ep_select(regs, hw_end);
  2102. if (is_dma_capable()) {
  2103. dma = is_in ? ep->rx_channel : ep->tx_channel;
  2104. if (dma) {
  2105. status = ep->musb->dma_controller->channel_abort(dma);
  2106. musb_dbg(musb, "abort %cX%d DMA for urb %p --> %d",
  2107. is_in ? 'R' : 'T', ep->epnum,
  2108. urb, status);
  2109. urb->actual_length += dma->actual_len;
  2110. }
  2111. }
  2112. /* turn off DMA requests, discard state, stop polling ... */
  2113. if (ep->epnum && is_in) {
  2114. /* giveback saves bulk toggle */
  2115. csr = musb_h_flush_rxfifo(ep, 0);
  2116. /* clear the endpoint's irq status here to avoid bogus irqs */
  2117. if (is_dma_capable() && dma)
  2118. musb_platform_clear_ep_rxintr(musb, ep->epnum);
  2119. } else if (ep->epnum) {
  2120. musb_h_tx_flush_fifo(ep);
  2121. csr = musb_readw(epio, MUSB_TXCSR);
  2122. csr &= ~(MUSB_TXCSR_AUTOSET
  2123. | MUSB_TXCSR_DMAENAB
  2124. | MUSB_TXCSR_H_RXSTALL
  2125. | MUSB_TXCSR_H_NAKTIMEOUT
  2126. | MUSB_TXCSR_H_ERROR
  2127. | MUSB_TXCSR_TXPKTRDY);
  2128. musb_writew(epio, MUSB_TXCSR, csr);
  2129. /* REVISIT may need to clear FLUSHFIFO ... */
  2130. musb_writew(epio, MUSB_TXCSR, csr);
  2131. /* flush cpu writebuffer */
  2132. csr = musb_readw(epio, MUSB_TXCSR);
  2133. } else {
  2134. musb_h_ep0_flush_fifo(ep);
  2135. }
  2136. if (status == 0)
  2137. musb_advance_schedule(ep->musb, urb, ep, is_in);
  2138. return status;
  2139. }
  2140. static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  2141. {
  2142. struct musb *musb = hcd_to_musb(hcd);
  2143. struct musb_qh *qh;
  2144. unsigned long flags;
  2145. int is_in = usb_pipein(urb->pipe);
  2146. int ret;
  2147. trace_musb_urb_deq(musb, urb);
  2148. spin_lock_irqsave(&musb->lock, flags);
  2149. ret = usb_hcd_check_unlink_urb(hcd, urb, status);
  2150. if (ret)
  2151. goto done;
  2152. qh = urb->hcpriv;
  2153. if (!qh)
  2154. goto done;
  2155. /*
  2156. * Any URB not actively programmed into endpoint hardware can be
  2157. * immediately given back; that's any URB not at the head of an
  2158. * endpoint queue, unless someday we get real DMA queues. And even
  2159. * if it's at the head, it might not be known to the hardware...
  2160. *
  2161. * Otherwise abort current transfer, pending DMA, etc.; urb->status
  2162. * has already been updated. This is a synchronous abort; it'd be
  2163. * OK to hold off until after some IRQ, though.
  2164. *
  2165. * NOTE: qh is invalid unless !list_empty(&hep->urb_list)
  2166. */
  2167. if (!qh->is_ready
  2168. || urb->urb_list.prev != &qh->hep->urb_list
  2169. || musb_ep_get_qh(qh->hw_ep, is_in) != qh) {
  2170. int ready = qh->is_ready;
  2171. qh->is_ready = 0;
  2172. musb_giveback(musb, urb, 0);
  2173. qh->is_ready = ready;
  2174. /* If nothing else (usually musb_giveback) is using it
  2175. * and its URB list has emptied, recycle this qh.
  2176. */
  2177. if (ready && list_empty(&qh->hep->urb_list)) {
  2178. qh->hep->hcpriv = NULL;
  2179. list_del(&qh->ring);
  2180. kfree(qh);
  2181. }
  2182. } else
  2183. ret = musb_cleanup_urb(urb, qh);
  2184. done:
  2185. spin_unlock_irqrestore(&musb->lock, flags);
  2186. return ret;
  2187. }
  2188. /* disable an endpoint */
  2189. static void
  2190. musb_h_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
  2191. {
  2192. u8 is_in = hep->desc.bEndpointAddress & USB_DIR_IN;
  2193. unsigned long flags;
  2194. struct musb *musb = hcd_to_musb(hcd);
  2195. struct musb_qh *qh;
  2196. struct urb *urb;
  2197. spin_lock_irqsave(&musb->lock, flags);
  2198. qh = hep->hcpriv;
  2199. if (qh == NULL)
  2200. goto exit;
  2201. /* NOTE: qh is invalid unless !list_empty(&hep->urb_list) */
  2202. /* Kick the first URB off the hardware, if needed */
  2203. qh->is_ready = 0;
  2204. if (musb_ep_get_qh(qh->hw_ep, is_in) == qh) {
  2205. urb = next_urb(qh);
  2206. /* make software (then hardware) stop ASAP */
  2207. if (!urb->unlinked)
  2208. urb->status = -ESHUTDOWN;
  2209. /* cleanup */
  2210. musb_cleanup_urb(urb, qh);
  2211. /* Then nuke all the others ... and advance the
  2212. * queue on hw_ep (e.g. bulk ring) when we're done.
  2213. */
  2214. while (!list_empty(&hep->urb_list)) {
  2215. urb = next_urb(qh);
  2216. urb->status = -ESHUTDOWN;
  2217. musb_advance_schedule(musb, urb, qh->hw_ep, is_in);
  2218. }
  2219. } else {
  2220. /* Just empty the queue; the hardware is busy with
  2221. * other transfers, and since !qh->is_ready nothing
  2222. * will activate any of these as it advances.
  2223. */
  2224. while (!list_empty(&hep->urb_list))
  2225. musb_giveback(musb, next_urb(qh), -ESHUTDOWN);
  2226. hep->hcpriv = NULL;
  2227. list_del(&qh->ring);
  2228. kfree(qh);
  2229. }
  2230. exit:
  2231. spin_unlock_irqrestore(&musb->lock, flags);
  2232. }
  2233. static int musb_h_get_frame_number(struct usb_hcd *hcd)
  2234. {
  2235. struct musb *musb = hcd_to_musb(hcd);
  2236. return musb_readw(musb->mregs, MUSB_FRAME);
  2237. }
  2238. static int musb_h_start(struct usb_hcd *hcd)
  2239. {
  2240. struct musb *musb = hcd_to_musb(hcd);
  2241. /* NOTE: musb_start() is called when the hub driver turns
  2242. * on port power, or when (OTG) peripheral starts.
  2243. */
  2244. hcd->state = HC_STATE_RUNNING;
  2245. musb->port1_status = 0;
  2246. return 0;
  2247. }
  2248. static void musb_h_stop(struct usb_hcd *hcd)
  2249. {
  2250. musb_stop(hcd_to_musb(hcd));
  2251. hcd->state = HC_STATE_HALT;
  2252. }
  2253. static int musb_bus_suspend(struct usb_hcd *hcd)
  2254. {
  2255. struct musb *musb = hcd_to_musb(hcd);
  2256. u8 devctl;
  2257. musb_port_suspend(musb, true);
  2258. if (!is_host_active(musb))
  2259. return 0;
  2260. switch (musb->xceiv->otg->state) {
  2261. case OTG_STATE_A_SUSPEND:
  2262. return 0;
  2263. case OTG_STATE_A_WAIT_VRISE:
  2264. /* ID could be grounded even if there's no device
  2265. * on the other end of the cable. NOTE that the
  2266. * A_WAIT_VRISE timers are messy with MUSB...
  2267. */
  2268. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  2269. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  2270. musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;
  2271. break;
  2272. default:
  2273. break;
  2274. }
  2275. if (musb->is_active) {
  2276. WARNING("trying to suspend as %s while active\n",
  2277. usb_otg_state_string(musb->xceiv->otg->state));
  2278. return -EBUSY;
  2279. } else
  2280. return 0;
  2281. }
  2282. static int musb_bus_resume(struct usb_hcd *hcd)
  2283. {
  2284. struct musb *musb = hcd_to_musb(hcd);
  2285. if (musb->config &&
  2286. musb->config->host_port_deassert_reset_at_resume)
  2287. musb_port_reset(musb, false);
  2288. return 0;
  2289. }
  2290. #ifndef CONFIG_MUSB_PIO_ONLY
  2291. #define MUSB_USB_DMA_ALIGN 4
  2292. struct musb_temp_buffer {
  2293. void *kmalloc_ptr;
  2294. void *old_xfer_buffer;
  2295. u8 data[0];
  2296. };
  2297. static void musb_free_temp_buffer(struct urb *urb)
  2298. {
  2299. enum dma_data_direction dir;
  2300. struct musb_temp_buffer *temp;
  2301. size_t length;
  2302. if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
  2303. return;
  2304. dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
  2305. temp = container_of(urb->transfer_buffer, struct musb_temp_buffer,
  2306. data);
  2307. if (dir == DMA_FROM_DEVICE) {
  2308. if (usb_pipeisoc(urb->pipe))
  2309. length = urb->transfer_buffer_length;
  2310. else
  2311. length = urb->actual_length;
  2312. memcpy(temp->old_xfer_buffer, temp->data, length);
  2313. }
  2314. urb->transfer_buffer = temp->old_xfer_buffer;
  2315. kfree(temp->kmalloc_ptr);
  2316. urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
  2317. }
  2318. static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
  2319. {
  2320. enum dma_data_direction dir;
  2321. struct musb_temp_buffer *temp;
  2322. void *kmalloc_ptr;
  2323. size_t kmalloc_size;
  2324. if (urb->num_sgs || urb->sg ||
  2325. urb->transfer_buffer_length == 0 ||
  2326. !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1)))
  2327. return 0;
  2328. dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
  2329. /* Allocate a buffer with enough padding for alignment */
  2330. kmalloc_size = urb->transfer_buffer_length +
  2331. sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1;
  2332. kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
  2333. if (!kmalloc_ptr)
  2334. return -ENOMEM;
  2335. /* Position our struct temp_buffer such that data is aligned */
  2336. temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN);
  2337. temp->kmalloc_ptr = kmalloc_ptr;
  2338. temp->old_xfer_buffer = urb->transfer_buffer;
  2339. if (dir == DMA_TO_DEVICE)
  2340. memcpy(temp->data, urb->transfer_buffer,
  2341. urb->transfer_buffer_length);
  2342. urb->transfer_buffer = temp->data;
  2343. urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
  2344. return 0;
  2345. }
  2346. static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
  2347. gfp_t mem_flags)
  2348. {
  2349. struct musb *musb = hcd_to_musb(hcd);
  2350. int ret;
  2351. /*
  2352. * The DMA engine in RTL1.8 and above cannot handle
  2353. * DMA addresses that are not aligned to a 4 byte boundary.
  2354. * For such engine implemented (un)map_urb_for_dma hooks.
  2355. * Do not use these hooks for RTL<1.8
  2356. */
  2357. if (musb->hwvers < MUSB_HWVERS_1800)
  2358. return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
  2359. ret = musb_alloc_temp_buffer(urb, mem_flags);
  2360. if (ret)
  2361. return ret;
  2362. ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
  2363. if (ret)
  2364. musb_free_temp_buffer(urb);
  2365. return ret;
  2366. }
  2367. static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  2368. {
  2369. struct musb *musb = hcd_to_musb(hcd);
  2370. usb_hcd_unmap_urb_for_dma(hcd, urb);
  2371. /* Do not use this hook for RTL<1.8 (see description above) */
  2372. if (musb->hwvers < MUSB_HWVERS_1800)
  2373. return;
  2374. musb_free_temp_buffer(urb);
  2375. }
  2376. #endif /* !CONFIG_MUSB_PIO_ONLY */
  2377. static const struct hc_driver musb_hc_driver = {
  2378. .description = "musb-hcd",
  2379. .product_desc = "MUSB HDRC host driver",
  2380. .hcd_priv_size = sizeof(struct musb *),
  2381. .flags = HCD_USB2 | HCD_MEMORY,
  2382. /* not using irq handler or reset hooks from usbcore, since
  2383. * those must be shared with peripheral code for OTG configs
  2384. */
  2385. .start = musb_h_start,
  2386. .stop = musb_h_stop,
  2387. .get_frame_number = musb_h_get_frame_number,
  2388. .urb_enqueue = musb_urb_enqueue,
  2389. .urb_dequeue = musb_urb_dequeue,
  2390. .endpoint_disable = musb_h_disable,
  2391. #ifndef CONFIG_MUSB_PIO_ONLY
  2392. .map_urb_for_dma = musb_map_urb_for_dma,
  2393. .unmap_urb_for_dma = musb_unmap_urb_for_dma,
  2394. #endif
  2395. .hub_status_data = musb_hub_status_data,
  2396. .hub_control = musb_hub_control,
  2397. .bus_suspend = musb_bus_suspend,
  2398. .bus_resume = musb_bus_resume,
  2399. /* .start_port_reset = NULL, */
  2400. /* .hub_irq_enable = NULL, */
  2401. };
  2402. int musb_host_alloc(struct musb *musb)
  2403. {
  2404. struct device *dev = musb->controller;
  2405. /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
  2406. musb->hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev));
  2407. if (!musb->hcd)
  2408. return -EINVAL;
  2409. *musb->hcd->hcd_priv = (unsigned long) musb;
  2410. musb->hcd->self.uses_pio_for_control = 1;
  2411. musb->hcd->uses_new_polling = 1;
  2412. musb->hcd->has_tt = 1;
  2413. return 0;
  2414. }
  2415. void musb_host_cleanup(struct musb *musb)
  2416. {
  2417. if (musb->port_mode == MUSB_PORT_MODE_GADGET)
  2418. return;
  2419. usb_remove_hcd(musb->hcd);
  2420. }
  2421. void musb_host_free(struct musb *musb)
  2422. {
  2423. usb_put_hcd(musb->hcd);
  2424. }
  2425. int musb_host_setup(struct musb *musb, int power_budget)
  2426. {
  2427. int ret;
  2428. struct usb_hcd *hcd = musb->hcd;
  2429. if (musb->port_mode == MUSB_PORT_MODE_HOST) {
  2430. MUSB_HST_MODE(musb);
  2431. musb->xceiv->otg->default_a = 1;
  2432. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  2433. }
  2434. otg_set_host(musb->xceiv->otg, &hcd->self);
  2435. hcd->self.otg_port = 1;
  2436. musb->xceiv->otg->host = &hcd->self;
  2437. hcd->power_budget = 2 * (power_budget ? : 250);
  2438. ret = usb_add_hcd(hcd, 0, 0);
  2439. if (ret < 0)
  2440. return ret;
  2441. device_wakeup_enable(hcd->self.controller);
  2442. return 0;
  2443. }
  2444. void musb_host_resume_root_hub(struct musb *musb)
  2445. {
  2446. usb_hcd_resume_root_hub(musb->hcd);
  2447. }
  2448. void musb_host_poke_root_hub(struct musb *musb)
  2449. {
  2450. MUSB_HST_MODE(musb);
  2451. if (musb->hcd->status_urb)
  2452. usb_hcd_poll_rh_status(musb->hcd);
  2453. else
  2454. usb_hcd_resume_root_hub(musb->hcd);
  2455. }