musb_host.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822
  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, res;
  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. res = dma->channel_program(channel, qh->maxpacket, 0,
  1368. (u32)buf, length);
  1369. return res;
  1370. }
  1371. #else
  1372. static inline int musb_rx_dma_iso_cppi41(struct dma_controller *dma,
  1373. struct musb_hw_ep *hw_ep,
  1374. struct musb_qh *qh,
  1375. struct urb *urb,
  1376. size_t len)
  1377. {
  1378. return false;
  1379. }
  1380. #endif
  1381. #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA) || \
  1382. defined(CONFIG_USB_TI_CPPI41_DMA)
  1383. /* Host side RX (IN) using Mentor DMA works as follows:
  1384. submit_urb ->
  1385. - if queue was empty, ProgramEndpoint
  1386. - first IN token is sent out (by setting ReqPkt)
  1387. LinuxIsr -> RxReady()
  1388. /\ => first packet is received
  1389. | - Set in mode 0 (DmaEnab, ~ReqPkt)
  1390. | -> DMA Isr (transfer complete) -> RxReady()
  1391. | - Ack receive (~RxPktRdy), turn off DMA (~DmaEnab)
  1392. | - if urb not complete, send next IN token (ReqPkt)
  1393. | | else complete urb.
  1394. | |
  1395. ---------------------------
  1396. *
  1397. * Nuances of mode 1:
  1398. * For short packets, no ack (+RxPktRdy) is sent automatically
  1399. * (even if AutoClear is ON)
  1400. * For full packets, ack (~RxPktRdy) and next IN token (+ReqPkt) is sent
  1401. * automatically => major problem, as collecting the next packet becomes
  1402. * difficult. Hence mode 1 is not used.
  1403. *
  1404. * REVISIT
  1405. * All we care about at this driver level is that
  1406. * (a) all URBs terminate with REQPKT cleared and fifo(s) empty;
  1407. * (b) termination conditions are: short RX, or buffer full;
  1408. * (c) fault modes include
  1409. * - iff URB_SHORT_NOT_OK, short RX status is -EREMOTEIO.
  1410. * (and that endpoint's dma queue stops immediately)
  1411. * - overflow (full, PLUS more bytes in the terminal packet)
  1412. *
  1413. * So for example, usb-storage sets URB_SHORT_NOT_OK, and would
  1414. * thus be a great candidate for using mode 1 ... for all but the
  1415. * last packet of one URB's transfer.
  1416. */
  1417. static int musb_rx_dma_inventra_cppi41(struct dma_controller *dma,
  1418. struct musb_hw_ep *hw_ep,
  1419. struct musb_qh *qh,
  1420. struct urb *urb,
  1421. size_t len)
  1422. {
  1423. struct dma_channel *channel = hw_ep->rx_channel;
  1424. void __iomem *epio = hw_ep->regs;
  1425. u16 val;
  1426. int pipe;
  1427. bool done;
  1428. pipe = urb->pipe;
  1429. if (usb_pipeisoc(pipe)) {
  1430. struct usb_iso_packet_descriptor *d;
  1431. d = urb->iso_frame_desc + qh->iso_idx;
  1432. d->actual_length = len;
  1433. /* even if there was an error, we did the dma
  1434. * for iso_frame_desc->length
  1435. */
  1436. if (d->status != -EILSEQ && d->status != -EOVERFLOW)
  1437. d->status = 0;
  1438. if (++qh->iso_idx >= urb->number_of_packets) {
  1439. done = true;
  1440. } else {
  1441. /* REVISIT: Why ignore return value here? */
  1442. if (musb_dma_cppi41(hw_ep->musb))
  1443. done = musb_rx_dma_iso_cppi41(dma, hw_ep, qh,
  1444. urb, len);
  1445. done = false;
  1446. }
  1447. } else {
  1448. /* done if urb buffer is full or short packet is recd */
  1449. done = (urb->actual_length + len >=
  1450. urb->transfer_buffer_length
  1451. || channel->actual_len < qh->maxpacket
  1452. || channel->rx_packet_done);
  1453. }
  1454. /* send IN token for next packet, without AUTOREQ */
  1455. if (!done) {
  1456. val = musb_readw(epio, MUSB_RXCSR);
  1457. val |= MUSB_RXCSR_H_REQPKT;
  1458. musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val);
  1459. }
  1460. return done;
  1461. }
  1462. /* Disadvantage of using mode 1:
  1463. * It's basically usable only for mass storage class; essentially all
  1464. * other protocols also terminate transfers on short packets.
  1465. *
  1466. * Details:
  1467. * An extra IN token is sent at the end of the transfer (due to AUTOREQ)
  1468. * If you try to use mode 1 for (transfer_buffer_length - 512), and try
  1469. * to use the extra IN token to grab the last packet using mode 0, then
  1470. * the problem is that you cannot be sure when the device will send the
  1471. * last packet and RxPktRdy set. Sometimes the packet is recd too soon
  1472. * such that it gets lost when RxCSR is re-set at the end of the mode 1
  1473. * transfer, while sometimes it is recd just a little late so that if you
  1474. * try to configure for mode 0 soon after the mode 1 transfer is
  1475. * completed, you will find rxcount 0. Okay, so you might think why not
  1476. * wait for an interrupt when the pkt is recd. Well, you won't get any!
  1477. */
  1478. static int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma,
  1479. struct musb_hw_ep *hw_ep,
  1480. struct musb_qh *qh,
  1481. struct urb *urb,
  1482. size_t len,
  1483. u8 iso_err)
  1484. {
  1485. struct musb *musb = hw_ep->musb;
  1486. void __iomem *epio = hw_ep->regs;
  1487. struct dma_channel *channel = hw_ep->rx_channel;
  1488. u16 rx_count, val;
  1489. int length, pipe, done;
  1490. dma_addr_t buf;
  1491. rx_count = musb_readw(epio, MUSB_RXCOUNT);
  1492. pipe = urb->pipe;
  1493. if (usb_pipeisoc(pipe)) {
  1494. int d_status = 0;
  1495. struct usb_iso_packet_descriptor *d;
  1496. d = urb->iso_frame_desc + qh->iso_idx;
  1497. if (iso_err) {
  1498. d_status = -EILSEQ;
  1499. urb->error_count++;
  1500. }
  1501. if (rx_count > d->length) {
  1502. if (d_status == 0) {
  1503. d_status = -EOVERFLOW;
  1504. urb->error_count++;
  1505. }
  1506. musb_dbg(musb, "** OVERFLOW %d into %d",
  1507. rx_count, d->length);
  1508. length = d->length;
  1509. } else
  1510. length = rx_count;
  1511. d->status = d_status;
  1512. buf = urb->transfer_dma + d->offset;
  1513. } else {
  1514. length = rx_count;
  1515. buf = urb->transfer_dma + urb->actual_length;
  1516. }
  1517. channel->desired_mode = 0;
  1518. #ifdef USE_MODE1
  1519. /* because of the issue below, mode 1 will
  1520. * only rarely behave with correct semantics.
  1521. */
  1522. if ((urb->transfer_flags & URB_SHORT_NOT_OK)
  1523. && (urb->transfer_buffer_length - urb->actual_length)
  1524. > qh->maxpacket)
  1525. channel->desired_mode = 1;
  1526. if (rx_count < hw_ep->max_packet_sz_rx) {
  1527. length = rx_count;
  1528. channel->desired_mode = 0;
  1529. } else {
  1530. length = urb->transfer_buffer_length;
  1531. }
  1532. #endif
  1533. /* See comments above on disadvantages of using mode 1 */
  1534. val = musb_readw(epio, MUSB_RXCSR);
  1535. val &= ~MUSB_RXCSR_H_REQPKT;
  1536. if (channel->desired_mode == 0)
  1537. val &= ~MUSB_RXCSR_H_AUTOREQ;
  1538. else
  1539. val |= MUSB_RXCSR_H_AUTOREQ;
  1540. val |= MUSB_RXCSR_DMAENAB;
  1541. /* autoclear shouldn't be set in high bandwidth */
  1542. if (qh->hb_mult == 1)
  1543. val |= MUSB_RXCSR_AUTOCLEAR;
  1544. musb_writew(epio, MUSB_RXCSR, MUSB_RXCSR_H_WZC_BITS | val);
  1545. /* REVISIT if when actual_length != 0,
  1546. * transfer_buffer_length needs to be
  1547. * adjusted first...
  1548. */
  1549. done = dma->channel_program(channel, qh->maxpacket,
  1550. channel->desired_mode,
  1551. buf, length);
  1552. if (!done) {
  1553. dma->channel_release(channel);
  1554. hw_ep->rx_channel = NULL;
  1555. channel = NULL;
  1556. val = musb_readw(epio, MUSB_RXCSR);
  1557. val &= ~(MUSB_RXCSR_DMAENAB
  1558. | MUSB_RXCSR_H_AUTOREQ
  1559. | MUSB_RXCSR_AUTOCLEAR);
  1560. musb_writew(epio, MUSB_RXCSR, val);
  1561. }
  1562. return done;
  1563. }
  1564. #else
  1565. static inline int musb_rx_dma_inventra_cppi41(struct dma_controller *dma,
  1566. struct musb_hw_ep *hw_ep,
  1567. struct musb_qh *qh,
  1568. struct urb *urb,
  1569. size_t len)
  1570. {
  1571. return false;
  1572. }
  1573. static inline int musb_rx_dma_in_inventra_cppi41(struct dma_controller *dma,
  1574. struct musb_hw_ep *hw_ep,
  1575. struct musb_qh *qh,
  1576. struct urb *urb,
  1577. size_t len,
  1578. u8 iso_err)
  1579. {
  1580. return false;
  1581. }
  1582. #endif
  1583. /*
  1584. * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
  1585. * and high-bandwidth IN transfer cases.
  1586. */
  1587. void musb_host_rx(struct musb *musb, u8 epnum)
  1588. {
  1589. struct urb *urb;
  1590. struct musb_hw_ep *hw_ep = musb->endpoints + epnum;
  1591. struct dma_controller *c = musb->dma_controller;
  1592. void __iomem *epio = hw_ep->regs;
  1593. struct musb_qh *qh = hw_ep->in_qh;
  1594. size_t xfer_len;
  1595. void __iomem *mbase = musb->mregs;
  1596. int pipe;
  1597. u16 rx_csr, val;
  1598. bool iso_err = false;
  1599. bool done = false;
  1600. u32 status;
  1601. struct dma_channel *dma;
  1602. unsigned int sg_flags = SG_MITER_ATOMIC | SG_MITER_TO_SG;
  1603. musb_ep_select(mbase, epnum);
  1604. urb = next_urb(qh);
  1605. dma = is_dma_capable() ? hw_ep->rx_channel : NULL;
  1606. status = 0;
  1607. xfer_len = 0;
  1608. rx_csr = musb_readw(epio, MUSB_RXCSR);
  1609. val = rx_csr;
  1610. if (unlikely(!urb)) {
  1611. /* REVISIT -- THIS SHOULD NEVER HAPPEN ... but, at least
  1612. * usbtest #11 (unlinks) triggers it regularly, sometimes
  1613. * with fifo full. (Only with DMA??)
  1614. */
  1615. musb_dbg(musb, "BOGUS RX%d ready, csr %04x, count %d",
  1616. epnum, val, musb_readw(epio, MUSB_RXCOUNT));
  1617. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1618. return;
  1619. }
  1620. pipe = urb->pipe;
  1621. trace_musb_urb_rx(musb, urb);
  1622. /* check for errors, concurrent stall & unlink is not really
  1623. * handled yet! */
  1624. if (rx_csr & MUSB_RXCSR_H_RXSTALL) {
  1625. musb_dbg(musb, "RX end %d STALL", epnum);
  1626. /* stall; record URB status */
  1627. status = -EPIPE;
  1628. } else if (rx_csr & MUSB_RXCSR_H_ERROR) {
  1629. musb_dbg(musb, "end %d RX proto error", epnum);
  1630. status = -EPROTO;
  1631. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1632. rx_csr &= ~MUSB_RXCSR_H_ERROR;
  1633. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1634. } else if (rx_csr & MUSB_RXCSR_DATAERROR) {
  1635. if (USB_ENDPOINT_XFER_ISOC != qh->type) {
  1636. musb_dbg(musb, "RX end %d NAK timeout", epnum);
  1637. /* NOTE: NAKing is *NOT* an error, so we want to
  1638. * continue. Except ... if there's a request for
  1639. * another QH, use that instead of starving it.
  1640. *
  1641. * Devices like Ethernet and serial adapters keep
  1642. * reads posted at all times, which will starve
  1643. * other devices without this logic.
  1644. */
  1645. if (usb_pipebulk(urb->pipe)
  1646. && qh->mux == 1
  1647. && !list_is_singular(&musb->in_bulk)) {
  1648. musb_bulk_nak_timeout(musb, hw_ep, 1);
  1649. return;
  1650. }
  1651. musb_ep_select(mbase, epnum);
  1652. rx_csr |= MUSB_RXCSR_H_WZC_BITS;
  1653. rx_csr &= ~MUSB_RXCSR_DATAERROR;
  1654. musb_writew(epio, MUSB_RXCSR, rx_csr);
  1655. goto finish;
  1656. } else {
  1657. musb_dbg(musb, "RX end %d ISO data error", epnum);
  1658. /* packet error reported later */
  1659. iso_err = true;
  1660. }
  1661. } else if (rx_csr & MUSB_RXCSR_INCOMPRX) {
  1662. musb_dbg(musb, "end %d high bandwidth incomplete ISO packet RX",
  1663. epnum);
  1664. status = -EPROTO;
  1665. }
  1666. /* faults abort the transfer */
  1667. if (status) {
  1668. /* clean up dma and collect transfer count */
  1669. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1670. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1671. musb->dma_controller->channel_abort(dma);
  1672. xfer_len = dma->actual_len;
  1673. }
  1674. musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
  1675. musb_writeb(epio, MUSB_RXINTERVAL, 0);
  1676. done = true;
  1677. goto finish;
  1678. }
  1679. if (unlikely(dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY)) {
  1680. /* SHOULD NEVER HAPPEN ... but at least DaVinci has done it */
  1681. ERR("RX%d dma busy, csr %04x\n", epnum, rx_csr);
  1682. goto finish;
  1683. }
  1684. /* thorough shutdown for now ... given more precise fault handling
  1685. * and better queueing support, we might keep a DMA pipeline going
  1686. * while processing this irq for earlier completions.
  1687. */
  1688. /* FIXME this is _way_ too much in-line logic for Mentor DMA */
  1689. if (!musb_dma_inventra(musb) && !musb_dma_ux500(musb) &&
  1690. (rx_csr & MUSB_RXCSR_H_REQPKT)) {
  1691. /* REVISIT this happened for a while on some short reads...
  1692. * the cleanup still needs investigation... looks bad...
  1693. * and also duplicates dma cleanup code above ... plus,
  1694. * shouldn't this be the "half full" double buffer case?
  1695. */
  1696. if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
  1697. dma->status = MUSB_DMA_STATUS_CORE_ABORT;
  1698. musb->dma_controller->channel_abort(dma);
  1699. xfer_len = dma->actual_len;
  1700. done = true;
  1701. }
  1702. musb_dbg(musb, "RXCSR%d %04x, reqpkt, len %zu%s", epnum, rx_csr,
  1703. xfer_len, dma ? ", dma" : "");
  1704. rx_csr &= ~MUSB_RXCSR_H_REQPKT;
  1705. musb_ep_select(mbase, epnum);
  1706. musb_writew(epio, MUSB_RXCSR,
  1707. MUSB_RXCSR_H_WZC_BITS | rx_csr);
  1708. }
  1709. if (dma && (rx_csr & MUSB_RXCSR_DMAENAB)) {
  1710. xfer_len = dma->actual_len;
  1711. val &= ~(MUSB_RXCSR_DMAENAB
  1712. | MUSB_RXCSR_H_AUTOREQ
  1713. | MUSB_RXCSR_AUTOCLEAR
  1714. | MUSB_RXCSR_RXPKTRDY);
  1715. musb_writew(hw_ep->regs, MUSB_RXCSR, val);
  1716. if (musb_dma_inventra(musb) || musb_dma_ux500(musb) ||
  1717. musb_dma_cppi41(musb)) {
  1718. done = musb_rx_dma_inventra_cppi41(c, hw_ep, qh, urb, xfer_len);
  1719. musb_dbg(hw_ep->musb,
  1720. "ep %d dma %s, rxcsr %04x, rxcount %d",
  1721. epnum, done ? "off" : "reset",
  1722. musb_readw(epio, MUSB_RXCSR),
  1723. musb_readw(epio, MUSB_RXCOUNT));
  1724. } else {
  1725. done = true;
  1726. }
  1727. } else if (urb->status == -EINPROGRESS) {
  1728. /* if no errors, be sure a packet is ready for unloading */
  1729. if (unlikely(!(rx_csr & MUSB_RXCSR_RXPKTRDY))) {
  1730. status = -EPROTO;
  1731. ERR("Rx interrupt with no errors or packet!\n");
  1732. /* FIXME this is another "SHOULD NEVER HAPPEN" */
  1733. /* SCRUB (RX) */
  1734. /* do the proper sequence to abort the transfer */
  1735. musb_ep_select(mbase, epnum);
  1736. val &= ~MUSB_RXCSR_H_REQPKT;
  1737. musb_writew(epio, MUSB_RXCSR, val);
  1738. goto finish;
  1739. }
  1740. /* we are expecting IN packets */
  1741. if ((musb_dma_inventra(musb) || musb_dma_ux500(musb) ||
  1742. musb_dma_cppi41(musb)) && dma) {
  1743. musb_dbg(hw_ep->musb,
  1744. "RX%d count %d, buffer 0x%llx len %d/%d",
  1745. epnum, musb_readw(epio, MUSB_RXCOUNT),
  1746. (unsigned long long) urb->transfer_dma
  1747. + urb->actual_length,
  1748. qh->offset,
  1749. urb->transfer_buffer_length);
  1750. if (musb_rx_dma_in_inventra_cppi41(c, hw_ep, qh, urb,
  1751. xfer_len, iso_err))
  1752. goto finish;
  1753. else
  1754. dev_err(musb->controller, "error: rx_dma failed\n");
  1755. }
  1756. if (!dma) {
  1757. unsigned int received_len;
  1758. /* Unmap the buffer so that CPU can use it */
  1759. usb_hcd_unmap_urb_for_dma(musb->hcd, urb);
  1760. /*
  1761. * We need to map sg if the transfer_buffer is
  1762. * NULL.
  1763. */
  1764. if (!urb->transfer_buffer) {
  1765. qh->use_sg = true;
  1766. sg_miter_start(&qh->sg_miter, urb->sg, 1,
  1767. sg_flags);
  1768. }
  1769. if (qh->use_sg) {
  1770. if (!sg_miter_next(&qh->sg_miter)) {
  1771. dev_err(musb->controller, "error: sg list empty\n");
  1772. sg_miter_stop(&qh->sg_miter);
  1773. status = -EINVAL;
  1774. done = true;
  1775. goto finish;
  1776. }
  1777. urb->transfer_buffer = qh->sg_miter.addr;
  1778. received_len = urb->actual_length;
  1779. qh->offset = 0x0;
  1780. done = musb_host_packet_rx(musb, urb, epnum,
  1781. iso_err);
  1782. /* Calculate the number of bytes received */
  1783. received_len = urb->actual_length -
  1784. received_len;
  1785. qh->sg_miter.consumed = received_len;
  1786. sg_miter_stop(&qh->sg_miter);
  1787. } else {
  1788. done = musb_host_packet_rx(musb, urb,
  1789. epnum, iso_err);
  1790. }
  1791. musb_dbg(musb, "read %spacket", done ? "last " : "");
  1792. }
  1793. }
  1794. finish:
  1795. urb->actual_length += xfer_len;
  1796. qh->offset += xfer_len;
  1797. if (done) {
  1798. if (qh->use_sg)
  1799. qh->use_sg = false;
  1800. if (urb->status == -EINPROGRESS)
  1801. urb->status = status;
  1802. musb_advance_schedule(musb, urb, hw_ep, USB_DIR_IN);
  1803. }
  1804. }
  1805. /* schedule nodes correspond to peripheral endpoints, like an OHCI QH.
  1806. * the software schedule associates multiple such nodes with a given
  1807. * host side hardware endpoint + direction; scheduling may activate
  1808. * that hardware endpoint.
  1809. */
  1810. static int musb_schedule(
  1811. struct musb *musb,
  1812. struct musb_qh *qh,
  1813. int is_in)
  1814. {
  1815. int idle = 0;
  1816. int best_diff;
  1817. int best_end, epnum;
  1818. struct musb_hw_ep *hw_ep = NULL;
  1819. struct list_head *head = NULL;
  1820. u8 toggle;
  1821. u8 txtype;
  1822. struct urb *urb = next_urb(qh);
  1823. /* use fixed hardware for control and bulk */
  1824. if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
  1825. head = &musb->control;
  1826. hw_ep = musb->control_ep;
  1827. goto success;
  1828. }
  1829. /* else, periodic transfers get muxed to other endpoints */
  1830. /*
  1831. * We know this qh hasn't been scheduled, so all we need to do
  1832. * is choose which hardware endpoint to put it on ...
  1833. *
  1834. * REVISIT what we really want here is a regular schedule tree
  1835. * like e.g. OHCI uses.
  1836. */
  1837. best_diff = 4096;
  1838. best_end = -1;
  1839. for (epnum = 1, hw_ep = musb->endpoints + 1;
  1840. epnum < musb->nr_endpoints;
  1841. epnum++, hw_ep++) {
  1842. int diff;
  1843. if (musb_ep_get_qh(hw_ep, is_in) != NULL)
  1844. continue;
  1845. if (hw_ep == musb->bulk_ep)
  1846. continue;
  1847. if (is_in)
  1848. diff = hw_ep->max_packet_sz_rx;
  1849. else
  1850. diff = hw_ep->max_packet_sz_tx;
  1851. diff -= (qh->maxpacket * qh->hb_mult);
  1852. if (diff >= 0 && best_diff > diff) {
  1853. /*
  1854. * Mentor controller has a bug in that if we schedule
  1855. * a BULK Tx transfer on an endpoint that had earlier
  1856. * handled ISOC then the BULK transfer has to start on
  1857. * a zero toggle. If the BULK transfer starts on a 1
  1858. * toggle then this transfer will fail as the mentor
  1859. * controller starts the Bulk transfer on a 0 toggle
  1860. * irrespective of the programming of the toggle bits
  1861. * in the TXCSR register. Check for this condition
  1862. * while allocating the EP for a Tx Bulk transfer. If
  1863. * so skip this EP.
  1864. */
  1865. hw_ep = musb->endpoints + epnum;
  1866. toggle = usb_gettoggle(urb->dev, qh->epnum, !is_in);
  1867. txtype = (musb_readb(hw_ep->regs, MUSB_TXTYPE)
  1868. >> 4) & 0x3;
  1869. if (!is_in && (qh->type == USB_ENDPOINT_XFER_BULK) &&
  1870. toggle && (txtype == USB_ENDPOINT_XFER_ISOC))
  1871. continue;
  1872. best_diff = diff;
  1873. best_end = epnum;
  1874. }
  1875. }
  1876. /* use bulk reserved ep1 if no other ep is free */
  1877. if (best_end < 0 && qh->type == USB_ENDPOINT_XFER_BULK) {
  1878. hw_ep = musb->bulk_ep;
  1879. if (is_in)
  1880. head = &musb->in_bulk;
  1881. else
  1882. head = &musb->out_bulk;
  1883. /* Enable bulk RX/TX NAK timeout scheme when bulk requests are
  1884. * multiplexed. This scheme does not work in high speed to full
  1885. * speed scenario as NAK interrupts are not coming from a
  1886. * full speed device connected to a high speed device.
  1887. * NAK timeout interval is 8 (128 uframe or 16ms) for HS and
  1888. * 4 (8 frame or 8ms) for FS device.
  1889. */
  1890. if (qh->dev)
  1891. qh->intv_reg =
  1892. (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
  1893. goto success;
  1894. } else if (best_end < 0) {
  1895. dev_err(musb->controller,
  1896. "%s hwep alloc failed for %dx%d\n",
  1897. musb_ep_xfertype_string(qh->type),
  1898. qh->hb_mult, qh->maxpacket);
  1899. return -ENOSPC;
  1900. }
  1901. idle = 1;
  1902. qh->mux = 0;
  1903. hw_ep = musb->endpoints + best_end;
  1904. musb_dbg(musb, "qh %p periodic slot %d", qh, best_end);
  1905. success:
  1906. if (head) {
  1907. idle = list_empty(head);
  1908. list_add_tail(&qh->ring, head);
  1909. qh->mux = 1;
  1910. }
  1911. qh->hw_ep = hw_ep;
  1912. qh->hep->hcpriv = qh;
  1913. if (idle)
  1914. musb_start_urb(musb, is_in, qh);
  1915. return 0;
  1916. }
  1917. static int musb_urb_enqueue(
  1918. struct usb_hcd *hcd,
  1919. struct urb *urb,
  1920. gfp_t mem_flags)
  1921. {
  1922. unsigned long flags;
  1923. struct musb *musb = hcd_to_musb(hcd);
  1924. struct usb_host_endpoint *hep = urb->ep;
  1925. struct musb_qh *qh;
  1926. struct usb_endpoint_descriptor *epd = &hep->desc;
  1927. int ret;
  1928. unsigned type_reg;
  1929. unsigned interval;
  1930. /* host role must be active */
  1931. if (!is_host_active(musb) || !musb->is_active)
  1932. return -ENODEV;
  1933. trace_musb_urb_enq(musb, urb);
  1934. spin_lock_irqsave(&musb->lock, flags);
  1935. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  1936. qh = ret ? NULL : hep->hcpriv;
  1937. if (qh)
  1938. urb->hcpriv = qh;
  1939. spin_unlock_irqrestore(&musb->lock, flags);
  1940. /* DMA mapping was already done, if needed, and this urb is on
  1941. * hep->urb_list now ... so we're done, unless hep wasn't yet
  1942. * scheduled onto a live qh.
  1943. *
  1944. * REVISIT best to keep hep->hcpriv valid until the endpoint gets
  1945. * disabled, testing for empty qh->ring and avoiding qh setup costs
  1946. * except for the first urb queued after a config change.
  1947. */
  1948. if (qh || ret)
  1949. return ret;
  1950. /* Allocate and initialize qh, minimizing the work done each time
  1951. * hw_ep gets reprogrammed, or with irqs blocked. Then schedule it.
  1952. *
  1953. * REVISIT consider a dedicated qh kmem_cache, so it's harder
  1954. * for bugs in other kernel code to break this driver...
  1955. */
  1956. qh = kzalloc(sizeof *qh, mem_flags);
  1957. if (!qh) {
  1958. spin_lock_irqsave(&musb->lock, flags);
  1959. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1960. spin_unlock_irqrestore(&musb->lock, flags);
  1961. return -ENOMEM;
  1962. }
  1963. qh->hep = hep;
  1964. qh->dev = urb->dev;
  1965. INIT_LIST_HEAD(&qh->ring);
  1966. qh->is_ready = 1;
  1967. qh->maxpacket = usb_endpoint_maxp(epd);
  1968. qh->type = usb_endpoint_type(epd);
  1969. /* Bits 11 & 12 of wMaxPacketSize encode high bandwidth multiplier.
  1970. * Some musb cores don't support high bandwidth ISO transfers; and
  1971. * we don't (yet!) support high bandwidth interrupt transfers.
  1972. */
  1973. qh->hb_mult = 1 + ((qh->maxpacket >> 11) & 0x03);
  1974. if (qh->hb_mult > 1) {
  1975. int ok = (qh->type == USB_ENDPOINT_XFER_ISOC);
  1976. if (ok)
  1977. ok = (usb_pipein(urb->pipe) && musb->hb_iso_rx)
  1978. || (usb_pipeout(urb->pipe) && musb->hb_iso_tx);
  1979. if (!ok) {
  1980. dev_err(musb->controller,
  1981. "high bandwidth %s (%dx%d) not supported\n",
  1982. musb_ep_xfertype_string(qh->type),
  1983. qh->hb_mult, qh->maxpacket & 0x7ff);
  1984. ret = -EMSGSIZE;
  1985. goto done;
  1986. }
  1987. qh->maxpacket &= 0x7ff;
  1988. }
  1989. qh->epnum = usb_endpoint_num(epd);
  1990. /* NOTE: urb->dev->devnum is wrong during SET_ADDRESS */
  1991. qh->addr_reg = (u8) usb_pipedevice(urb->pipe);
  1992. /* precompute rxtype/txtype/type0 register */
  1993. type_reg = (qh->type << 4) | qh->epnum;
  1994. switch (urb->dev->speed) {
  1995. case USB_SPEED_LOW:
  1996. type_reg |= 0xc0;
  1997. break;
  1998. case USB_SPEED_FULL:
  1999. type_reg |= 0x80;
  2000. break;
  2001. default:
  2002. type_reg |= 0x40;
  2003. }
  2004. qh->type_reg = type_reg;
  2005. /* Precompute RXINTERVAL/TXINTERVAL register */
  2006. switch (qh->type) {
  2007. case USB_ENDPOINT_XFER_INT:
  2008. /*
  2009. * Full/low speeds use the linear encoding,
  2010. * high speed uses the logarithmic encoding.
  2011. */
  2012. if (urb->dev->speed <= USB_SPEED_FULL) {
  2013. interval = max_t(u8, epd->bInterval, 1);
  2014. break;
  2015. }
  2016. /* FALLTHROUGH */
  2017. case USB_ENDPOINT_XFER_ISOC:
  2018. /* ISO always uses logarithmic encoding */
  2019. interval = min_t(u8, epd->bInterval, 16);
  2020. break;
  2021. default:
  2022. /* REVISIT we actually want to use NAK limits, hinting to the
  2023. * transfer scheduling logic to try some other qh, e.g. try
  2024. * for 2 msec first:
  2025. *
  2026. * interval = (USB_SPEED_HIGH == urb->dev->speed) ? 16 : 2;
  2027. *
  2028. * The downside of disabling this is that transfer scheduling
  2029. * gets VERY unfair for nonperiodic transfers; a misbehaving
  2030. * peripheral could make that hurt. That's perfectly normal
  2031. * for reads from network or serial adapters ... so we have
  2032. * partial NAKlimit support for bulk RX.
  2033. *
  2034. * The upside of disabling it is simpler transfer scheduling.
  2035. */
  2036. interval = 0;
  2037. }
  2038. qh->intv_reg = interval;
  2039. /* precompute addressing for external hub/tt ports */
  2040. if (musb->is_multipoint) {
  2041. struct usb_device *parent = urb->dev->parent;
  2042. if (parent != hcd->self.root_hub) {
  2043. qh->h_addr_reg = (u8) parent->devnum;
  2044. /* set up tt info if needed */
  2045. if (urb->dev->tt) {
  2046. qh->h_port_reg = (u8) urb->dev->ttport;
  2047. if (urb->dev->tt->hub)
  2048. qh->h_addr_reg =
  2049. (u8) urb->dev->tt->hub->devnum;
  2050. if (urb->dev->tt->multi)
  2051. qh->h_addr_reg |= 0x80;
  2052. }
  2053. }
  2054. }
  2055. /* invariant: hep->hcpriv is null OR the qh that's already scheduled.
  2056. * until we get real dma queues (with an entry for each urb/buffer),
  2057. * we only have work to do in the former case.
  2058. */
  2059. spin_lock_irqsave(&musb->lock, flags);
  2060. if (hep->hcpriv || !next_urb(qh)) {
  2061. /* some concurrent activity submitted another urb to hep...
  2062. * odd, rare, error prone, but legal.
  2063. */
  2064. kfree(qh);
  2065. qh = NULL;
  2066. ret = 0;
  2067. } else
  2068. ret = musb_schedule(musb, qh,
  2069. epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK);
  2070. if (ret == 0) {
  2071. urb->hcpriv = qh;
  2072. /* FIXME set urb->start_frame for iso/intr, it's tested in
  2073. * musb_start_urb(), but otherwise only konicawc cares ...
  2074. */
  2075. }
  2076. spin_unlock_irqrestore(&musb->lock, flags);
  2077. done:
  2078. if (ret != 0) {
  2079. spin_lock_irqsave(&musb->lock, flags);
  2080. usb_hcd_unlink_urb_from_ep(hcd, urb);
  2081. spin_unlock_irqrestore(&musb->lock, flags);
  2082. kfree(qh);
  2083. }
  2084. return ret;
  2085. }
  2086. /*
  2087. * abort a transfer that's at the head of a hardware queue.
  2088. * called with controller locked, irqs blocked
  2089. * that hardware queue advances to the next transfer, unless prevented
  2090. */
  2091. static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
  2092. {
  2093. struct musb_hw_ep *ep = qh->hw_ep;
  2094. struct musb *musb = ep->musb;
  2095. void __iomem *epio = ep->regs;
  2096. unsigned hw_end = ep->epnum;
  2097. void __iomem *regs = ep->musb->mregs;
  2098. int is_in = usb_pipein(urb->pipe);
  2099. int status = 0;
  2100. u16 csr;
  2101. struct dma_channel *dma = NULL;
  2102. musb_ep_select(regs, hw_end);
  2103. if (is_dma_capable()) {
  2104. dma = is_in ? ep->rx_channel : ep->tx_channel;
  2105. if (dma) {
  2106. status = ep->musb->dma_controller->channel_abort(dma);
  2107. musb_dbg(musb, "abort %cX%d DMA for urb %p --> %d",
  2108. is_in ? 'R' : 'T', ep->epnum,
  2109. urb, status);
  2110. urb->actual_length += dma->actual_len;
  2111. }
  2112. }
  2113. /* turn off DMA requests, discard state, stop polling ... */
  2114. if (ep->epnum && is_in) {
  2115. /* giveback saves bulk toggle */
  2116. csr = musb_h_flush_rxfifo(ep, 0);
  2117. /* clear the endpoint's irq status here to avoid bogus irqs */
  2118. if (is_dma_capable() && dma)
  2119. musb_platform_clear_ep_rxintr(musb, ep->epnum);
  2120. } else if (ep->epnum) {
  2121. musb_h_tx_flush_fifo(ep);
  2122. csr = musb_readw(epio, MUSB_TXCSR);
  2123. csr &= ~(MUSB_TXCSR_AUTOSET
  2124. | MUSB_TXCSR_DMAENAB
  2125. | MUSB_TXCSR_H_RXSTALL
  2126. | MUSB_TXCSR_H_NAKTIMEOUT
  2127. | MUSB_TXCSR_H_ERROR
  2128. | MUSB_TXCSR_TXPKTRDY);
  2129. musb_writew(epio, MUSB_TXCSR, csr);
  2130. /* REVISIT may need to clear FLUSHFIFO ... */
  2131. musb_writew(epio, MUSB_TXCSR, csr);
  2132. /* flush cpu writebuffer */
  2133. csr = musb_readw(epio, MUSB_TXCSR);
  2134. } else {
  2135. musb_h_ep0_flush_fifo(ep);
  2136. }
  2137. if (status == 0)
  2138. musb_advance_schedule(ep->musb, urb, ep, is_in);
  2139. return status;
  2140. }
  2141. static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  2142. {
  2143. struct musb *musb = hcd_to_musb(hcd);
  2144. struct musb_qh *qh;
  2145. unsigned long flags;
  2146. int is_in = usb_pipein(urb->pipe);
  2147. int ret;
  2148. trace_musb_urb_deq(musb, urb);
  2149. spin_lock_irqsave(&musb->lock, flags);
  2150. ret = usb_hcd_check_unlink_urb(hcd, urb, status);
  2151. if (ret)
  2152. goto done;
  2153. qh = urb->hcpriv;
  2154. if (!qh)
  2155. goto done;
  2156. /*
  2157. * Any URB not actively programmed into endpoint hardware can be
  2158. * immediately given back; that's any URB not at the head of an
  2159. * endpoint queue, unless someday we get real DMA queues. And even
  2160. * if it's at the head, it might not be known to the hardware...
  2161. *
  2162. * Otherwise abort current transfer, pending DMA, etc.; urb->status
  2163. * has already been updated. This is a synchronous abort; it'd be
  2164. * OK to hold off until after some IRQ, though.
  2165. *
  2166. * NOTE: qh is invalid unless !list_empty(&hep->urb_list)
  2167. */
  2168. if (!qh->is_ready
  2169. || urb->urb_list.prev != &qh->hep->urb_list
  2170. || musb_ep_get_qh(qh->hw_ep, is_in) != qh) {
  2171. int ready = qh->is_ready;
  2172. qh->is_ready = 0;
  2173. musb_giveback(musb, urb, 0);
  2174. qh->is_ready = ready;
  2175. /* If nothing else (usually musb_giveback) is using it
  2176. * and its URB list has emptied, recycle this qh.
  2177. */
  2178. if (ready && list_empty(&qh->hep->urb_list)) {
  2179. qh->hep->hcpriv = NULL;
  2180. list_del(&qh->ring);
  2181. kfree(qh);
  2182. }
  2183. } else
  2184. ret = musb_cleanup_urb(urb, qh);
  2185. done:
  2186. spin_unlock_irqrestore(&musb->lock, flags);
  2187. return ret;
  2188. }
  2189. /* disable an endpoint */
  2190. static void
  2191. musb_h_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
  2192. {
  2193. u8 is_in = hep->desc.bEndpointAddress & USB_DIR_IN;
  2194. unsigned long flags;
  2195. struct musb *musb = hcd_to_musb(hcd);
  2196. struct musb_qh *qh;
  2197. struct urb *urb;
  2198. spin_lock_irqsave(&musb->lock, flags);
  2199. qh = hep->hcpriv;
  2200. if (qh == NULL)
  2201. goto exit;
  2202. /* NOTE: qh is invalid unless !list_empty(&hep->urb_list) */
  2203. /* Kick the first URB off the hardware, if needed */
  2204. qh->is_ready = 0;
  2205. if (musb_ep_get_qh(qh->hw_ep, is_in) == qh) {
  2206. urb = next_urb(qh);
  2207. /* make software (then hardware) stop ASAP */
  2208. if (!urb->unlinked)
  2209. urb->status = -ESHUTDOWN;
  2210. /* cleanup */
  2211. musb_cleanup_urb(urb, qh);
  2212. /* Then nuke all the others ... and advance the
  2213. * queue on hw_ep (e.g. bulk ring) when we're done.
  2214. */
  2215. while (!list_empty(&hep->urb_list)) {
  2216. urb = next_urb(qh);
  2217. urb->status = -ESHUTDOWN;
  2218. musb_advance_schedule(musb, urb, qh->hw_ep, is_in);
  2219. }
  2220. } else {
  2221. /* Just empty the queue; the hardware is busy with
  2222. * other transfers, and since !qh->is_ready nothing
  2223. * will activate any of these as it advances.
  2224. */
  2225. while (!list_empty(&hep->urb_list))
  2226. musb_giveback(musb, next_urb(qh), -ESHUTDOWN);
  2227. hep->hcpriv = NULL;
  2228. list_del(&qh->ring);
  2229. kfree(qh);
  2230. }
  2231. exit:
  2232. spin_unlock_irqrestore(&musb->lock, flags);
  2233. }
  2234. static int musb_h_get_frame_number(struct usb_hcd *hcd)
  2235. {
  2236. struct musb *musb = hcd_to_musb(hcd);
  2237. return musb_readw(musb->mregs, MUSB_FRAME);
  2238. }
  2239. static int musb_h_start(struct usb_hcd *hcd)
  2240. {
  2241. struct musb *musb = hcd_to_musb(hcd);
  2242. /* NOTE: musb_start() is called when the hub driver turns
  2243. * on port power, or when (OTG) peripheral starts.
  2244. */
  2245. hcd->state = HC_STATE_RUNNING;
  2246. musb->port1_status = 0;
  2247. return 0;
  2248. }
  2249. static void musb_h_stop(struct usb_hcd *hcd)
  2250. {
  2251. musb_stop(hcd_to_musb(hcd));
  2252. hcd->state = HC_STATE_HALT;
  2253. }
  2254. static int musb_bus_suspend(struct usb_hcd *hcd)
  2255. {
  2256. struct musb *musb = hcd_to_musb(hcd);
  2257. u8 devctl;
  2258. musb_port_suspend(musb, true);
  2259. if (!is_host_active(musb))
  2260. return 0;
  2261. switch (musb->xceiv->otg->state) {
  2262. case OTG_STATE_A_SUSPEND:
  2263. return 0;
  2264. case OTG_STATE_A_WAIT_VRISE:
  2265. /* ID could be grounded even if there's no device
  2266. * on the other end of the cable. NOTE that the
  2267. * A_WAIT_VRISE timers are messy with MUSB...
  2268. */
  2269. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  2270. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  2271. musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;
  2272. break;
  2273. default:
  2274. break;
  2275. }
  2276. if (musb->is_active) {
  2277. WARNING("trying to suspend as %s while active\n",
  2278. usb_otg_state_string(musb->xceiv->otg->state));
  2279. return -EBUSY;
  2280. } else
  2281. return 0;
  2282. }
  2283. static int musb_bus_resume(struct usb_hcd *hcd)
  2284. {
  2285. struct musb *musb = hcd_to_musb(hcd);
  2286. if (musb->config &&
  2287. musb->config->host_port_deassert_reset_at_resume)
  2288. musb_port_reset(musb, false);
  2289. return 0;
  2290. }
  2291. #ifndef CONFIG_MUSB_PIO_ONLY
  2292. #define MUSB_USB_DMA_ALIGN 4
  2293. struct musb_temp_buffer {
  2294. void *kmalloc_ptr;
  2295. void *old_xfer_buffer;
  2296. u8 data[0];
  2297. };
  2298. static void musb_free_temp_buffer(struct urb *urb)
  2299. {
  2300. enum dma_data_direction dir;
  2301. struct musb_temp_buffer *temp;
  2302. size_t length;
  2303. if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
  2304. return;
  2305. dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
  2306. temp = container_of(urb->transfer_buffer, struct musb_temp_buffer,
  2307. data);
  2308. if (dir == DMA_FROM_DEVICE) {
  2309. if (usb_pipeisoc(urb->pipe))
  2310. length = urb->transfer_buffer_length;
  2311. else
  2312. length = urb->actual_length;
  2313. memcpy(temp->old_xfer_buffer, temp->data, length);
  2314. }
  2315. urb->transfer_buffer = temp->old_xfer_buffer;
  2316. kfree(temp->kmalloc_ptr);
  2317. urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
  2318. }
  2319. static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
  2320. {
  2321. enum dma_data_direction dir;
  2322. struct musb_temp_buffer *temp;
  2323. void *kmalloc_ptr;
  2324. size_t kmalloc_size;
  2325. if (urb->num_sgs || urb->sg ||
  2326. urb->transfer_buffer_length == 0 ||
  2327. !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1)))
  2328. return 0;
  2329. dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
  2330. /* Allocate a buffer with enough padding for alignment */
  2331. kmalloc_size = urb->transfer_buffer_length +
  2332. sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1;
  2333. kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
  2334. if (!kmalloc_ptr)
  2335. return -ENOMEM;
  2336. /* Position our struct temp_buffer such that data is aligned */
  2337. temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN);
  2338. temp->kmalloc_ptr = kmalloc_ptr;
  2339. temp->old_xfer_buffer = urb->transfer_buffer;
  2340. if (dir == DMA_TO_DEVICE)
  2341. memcpy(temp->data, urb->transfer_buffer,
  2342. urb->transfer_buffer_length);
  2343. urb->transfer_buffer = temp->data;
  2344. urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
  2345. return 0;
  2346. }
  2347. static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
  2348. gfp_t mem_flags)
  2349. {
  2350. struct musb *musb = hcd_to_musb(hcd);
  2351. int ret;
  2352. /*
  2353. * The DMA engine in RTL1.8 and above cannot handle
  2354. * DMA addresses that are not aligned to a 4 byte boundary.
  2355. * For such engine implemented (un)map_urb_for_dma hooks.
  2356. * Do not use these hooks for RTL<1.8
  2357. */
  2358. if (musb->hwvers < MUSB_HWVERS_1800)
  2359. return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
  2360. ret = musb_alloc_temp_buffer(urb, mem_flags);
  2361. if (ret)
  2362. return ret;
  2363. ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
  2364. if (ret)
  2365. musb_free_temp_buffer(urb);
  2366. return ret;
  2367. }
  2368. static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  2369. {
  2370. struct musb *musb = hcd_to_musb(hcd);
  2371. usb_hcd_unmap_urb_for_dma(hcd, urb);
  2372. /* Do not use this hook for RTL<1.8 (see description above) */
  2373. if (musb->hwvers < MUSB_HWVERS_1800)
  2374. return;
  2375. musb_free_temp_buffer(urb);
  2376. }
  2377. #endif /* !CONFIG_MUSB_PIO_ONLY */
  2378. static const struct hc_driver musb_hc_driver = {
  2379. .description = "musb-hcd",
  2380. .product_desc = "MUSB HDRC host driver",
  2381. .hcd_priv_size = sizeof(struct musb *),
  2382. .flags = HCD_USB2 | HCD_MEMORY,
  2383. /* not using irq handler or reset hooks from usbcore, since
  2384. * those must be shared with peripheral code for OTG configs
  2385. */
  2386. .start = musb_h_start,
  2387. .stop = musb_h_stop,
  2388. .get_frame_number = musb_h_get_frame_number,
  2389. .urb_enqueue = musb_urb_enqueue,
  2390. .urb_dequeue = musb_urb_dequeue,
  2391. .endpoint_disable = musb_h_disable,
  2392. #ifndef CONFIG_MUSB_PIO_ONLY
  2393. .map_urb_for_dma = musb_map_urb_for_dma,
  2394. .unmap_urb_for_dma = musb_unmap_urb_for_dma,
  2395. #endif
  2396. .hub_status_data = musb_hub_status_data,
  2397. .hub_control = musb_hub_control,
  2398. .bus_suspend = musb_bus_suspend,
  2399. .bus_resume = musb_bus_resume,
  2400. /* .start_port_reset = NULL, */
  2401. /* .hub_irq_enable = NULL, */
  2402. };
  2403. int musb_host_alloc(struct musb *musb)
  2404. {
  2405. struct device *dev = musb->controller;
  2406. /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
  2407. musb->hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev));
  2408. if (!musb->hcd)
  2409. return -EINVAL;
  2410. *musb->hcd->hcd_priv = (unsigned long) musb;
  2411. musb->hcd->self.uses_pio_for_control = 1;
  2412. musb->hcd->uses_new_polling = 1;
  2413. musb->hcd->has_tt = 1;
  2414. return 0;
  2415. }
  2416. void musb_host_cleanup(struct musb *musb)
  2417. {
  2418. if (musb->port_mode == MUSB_PORT_MODE_GADGET)
  2419. return;
  2420. usb_remove_hcd(musb->hcd);
  2421. }
  2422. void musb_host_free(struct musb *musb)
  2423. {
  2424. usb_put_hcd(musb->hcd);
  2425. }
  2426. int musb_host_setup(struct musb *musb, int power_budget)
  2427. {
  2428. int ret;
  2429. struct usb_hcd *hcd = musb->hcd;
  2430. if (musb->port_mode == MUSB_PORT_MODE_HOST) {
  2431. MUSB_HST_MODE(musb);
  2432. musb->xceiv->otg->default_a = 1;
  2433. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  2434. }
  2435. otg_set_host(musb->xceiv->otg, &hcd->self);
  2436. hcd->self.otg_port = 1;
  2437. musb->xceiv->otg->host = &hcd->self;
  2438. hcd->power_budget = 2 * (power_budget ? : 250);
  2439. ret = usb_add_hcd(hcd, 0, 0);
  2440. if (ret < 0)
  2441. return ret;
  2442. device_wakeup_enable(hcd->self.controller);
  2443. return 0;
  2444. }
  2445. void musb_host_resume_root_hub(struct musb *musb)
  2446. {
  2447. usb_hcd_resume_root_hub(musb->hcd);
  2448. }
  2449. void musb_host_poke_root_hub(struct musb *musb)
  2450. {
  2451. MUSB_HST_MODE(musb);
  2452. if (musb->hcd->status_urb)
  2453. usb_hcd_poll_rh_status(musb->hcd);
  2454. else
  2455. usb_hcd_resume_root_hub(musb->hcd);
  2456. }