net2280.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934
  1. /*
  2. * Driver for the PLX NET2280 USB device controller.
  3. * Specs and errata are available from <http://www.plxtech.com>.
  4. *
  5. * PLX Technology Inc. (formerly NetChip Technology) supported the
  6. * development of this driver.
  7. *
  8. *
  9. * CODE STATUS HIGHLIGHTS
  10. *
  11. * This driver should work well with most "gadget" drivers, including
  12. * the File Storage, Serial, and Ethernet/RNDIS gadget drivers
  13. * as well as Gadget Zero and Gadgetfs.
  14. *
  15. * DMA is enabled by default. Drivers using transfer queues might use
  16. * DMA chaining to remove IRQ latencies between transfers. (Except when
  17. * short OUT transfers happen.) Drivers can use the req->no_interrupt
  18. * hint to completely eliminate some IRQs, if a later IRQ is guaranteed
  19. * and DMA chaining is enabled.
  20. *
  21. * Note that almost all the errata workarounds here are only needed for
  22. * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
  23. */
  24. /*
  25. * Copyright (C) 2003 David Brownell
  26. * Copyright (C) 2003-2005 PLX Technology, Inc.
  27. *
  28. * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
  29. * with 2282 chip
  30. *
  31. * This program is free software; you can redistribute it and/or modify
  32. * it under the terms of the GNU General Public License as published by
  33. * the Free Software Foundation; either version 2 of the License, or
  34. * (at your option) any later version.
  35. */
  36. #undef DEBUG /* messages on error and most fault paths */
  37. #undef VERBOSE /* extra debug messages (success too) */
  38. #include <linux/module.h>
  39. #include <linux/pci.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/kernel.h>
  42. #include <linux/delay.h>
  43. #include <linux/ioport.h>
  44. #include <linux/slab.h>
  45. #include <linux/errno.h>
  46. #include <linux/init.h>
  47. #include <linux/timer.h>
  48. #include <linux/list.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/moduleparam.h>
  51. #include <linux/device.h>
  52. #include <linux/usb/ch9.h>
  53. #include <linux/usb/gadget.h>
  54. #include <linux/prefetch.h>
  55. #include <asm/byteorder.h>
  56. #include <asm/io.h>
  57. #include <asm/irq.h>
  58. #include <asm/system.h>
  59. #include <asm/unaligned.h>
  60. #define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
  61. #define DRIVER_VERSION "2005 Sept 27"
  62. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  63. #define EP_DONTUSE 13 /* nonzero */
  64. #define USE_RDK_LEDS /* GPIO pins control three LEDs */
  65. static const char driver_name [] = "net2280";
  66. static const char driver_desc [] = DRIVER_DESC;
  67. static const char ep0name [] = "ep0";
  68. static const char *const ep_name [] = {
  69. ep0name,
  70. "ep-a", "ep-b", "ep-c", "ep-d",
  71. "ep-e", "ep-f",
  72. };
  73. /* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
  74. * use_dma_chaining -- dma descriptor queueing gives even more irq reduction
  75. *
  76. * The net2280 DMA engines are not tightly integrated with their FIFOs;
  77. * not all cases are (yet) handled well in this driver or the silicon.
  78. * Some gadget drivers work better with the dma support here than others.
  79. * These two parameters let you use PIO or more aggressive DMA.
  80. */
  81. static int use_dma = 1;
  82. static int use_dma_chaining = 0;
  83. /* "modprobe net2280 use_dma=n" etc */
  84. module_param (use_dma, bool, S_IRUGO);
  85. module_param (use_dma_chaining, bool, S_IRUGO);
  86. /* mode 0 == ep-{a,b,c,d} 1K fifo each
  87. * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
  88. * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
  89. */
  90. static ushort fifo_mode = 0;
  91. /* "modprobe net2280 fifo_mode=1" etc */
  92. module_param (fifo_mode, ushort, 0644);
  93. /* enable_suspend -- When enabled, the driver will respond to
  94. * USB suspend requests by powering down the NET2280. Otherwise,
  95. * USB suspend requests will be ignored. This is acceptable for
  96. * self-powered devices
  97. */
  98. static int enable_suspend = 0;
  99. /* "modprobe net2280 enable_suspend=1" etc */
  100. module_param (enable_suspend, bool, S_IRUGO);
  101. #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
  102. #if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
  103. static char *type_string (u8 bmAttributes)
  104. {
  105. switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
  106. case USB_ENDPOINT_XFER_BULK: return "bulk";
  107. case USB_ENDPOINT_XFER_ISOC: return "iso";
  108. case USB_ENDPOINT_XFER_INT: return "intr";
  109. };
  110. return "control";
  111. }
  112. #endif
  113. #include "net2280.h"
  114. #define valid_bit cpu_to_le32 (1 << VALID_BIT)
  115. #define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
  116. /*-------------------------------------------------------------------------*/
  117. static int
  118. net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
  119. {
  120. struct net2280 *dev;
  121. struct net2280_ep *ep;
  122. u32 max, tmp;
  123. unsigned long flags;
  124. ep = container_of (_ep, struct net2280_ep, ep);
  125. if (!_ep || !desc || ep->desc || _ep->name == ep0name
  126. || desc->bDescriptorType != USB_DT_ENDPOINT)
  127. return -EINVAL;
  128. dev = ep->dev;
  129. if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
  130. return -ESHUTDOWN;
  131. /* erratum 0119 workaround ties up an endpoint number */
  132. if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE)
  133. return -EDOM;
  134. /* sanity check ep-e/ep-f since their fifos are small */
  135. max = usb_endpoint_maxp (desc) & 0x1fff;
  136. if (ep->num > 4 && max > 64)
  137. return -ERANGE;
  138. spin_lock_irqsave (&dev->lock, flags);
  139. _ep->maxpacket = max & 0x7ff;
  140. ep->desc = desc;
  141. /* ep_reset() has already been called */
  142. ep->stopped = 0;
  143. ep->wedged = 0;
  144. ep->out_overflow = 0;
  145. /* set speed-dependent max packet; may kick in high bandwidth */
  146. set_idx_reg (dev->regs, REG_EP_MAXPKT (dev, ep->num), max);
  147. /* FIFO lines can't go to different packets. PIO is ok, so
  148. * use it instead of troublesome (non-bulk) multi-packet DMA.
  149. */
  150. if (ep->dma && (max % 4) != 0 && use_dma_chaining) {
  151. DEBUG (ep->dev, "%s, no dma for maxpacket %d\n",
  152. ep->ep.name, ep->ep.maxpacket);
  153. ep->dma = NULL;
  154. }
  155. /* set type, direction, address; reset fifo counters */
  156. writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat);
  157. tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
  158. if (tmp == USB_ENDPOINT_XFER_INT) {
  159. /* erratum 0105 workaround prevents hs NYET */
  160. if (dev->chiprev == 0100
  161. && dev->gadget.speed == USB_SPEED_HIGH
  162. && !(desc->bEndpointAddress & USB_DIR_IN))
  163. writel ((1 << CLEAR_NAK_OUT_PACKETS_MODE),
  164. &ep->regs->ep_rsp);
  165. } else if (tmp == USB_ENDPOINT_XFER_BULK) {
  166. /* catch some particularly blatant driver bugs */
  167. if ((dev->gadget.speed == USB_SPEED_HIGH
  168. && max != 512)
  169. || (dev->gadget.speed == USB_SPEED_FULL
  170. && max > 64)) {
  171. spin_unlock_irqrestore (&dev->lock, flags);
  172. return -ERANGE;
  173. }
  174. }
  175. ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0;
  176. tmp <<= ENDPOINT_TYPE;
  177. tmp |= desc->bEndpointAddress;
  178. tmp |= (4 << ENDPOINT_BYTE_COUNT); /* default full fifo lines */
  179. tmp |= 1 << ENDPOINT_ENABLE;
  180. wmb ();
  181. /* for OUT transfers, block the rx fifo until a read is posted */
  182. ep->is_in = (tmp & USB_DIR_IN) != 0;
  183. if (!ep->is_in)
  184. writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  185. else if (dev->pdev->device != 0x2280) {
  186. /* Added for 2282, Don't use nak packets on an in endpoint,
  187. * this was ignored on 2280
  188. */
  189. writel ((1 << CLEAR_NAK_OUT_PACKETS)
  190. | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
  191. }
  192. writel (tmp, &ep->regs->ep_cfg);
  193. /* enable irqs */
  194. if (!ep->dma) { /* pio, per-packet */
  195. tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0);
  196. writel (tmp, &dev->regs->pciirqenb0);
  197. tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
  198. | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
  199. if (dev->pdev->device == 0x2280)
  200. tmp |= readl (&ep->regs->ep_irqenb);
  201. writel (tmp, &ep->regs->ep_irqenb);
  202. } else { /* dma, per-request */
  203. tmp = (1 << (8 + ep->num)); /* completion */
  204. tmp |= readl (&dev->regs->pciirqenb1);
  205. writel (tmp, &dev->regs->pciirqenb1);
  206. /* for short OUT transfers, dma completions can't
  207. * advance the queue; do it pio-style, by hand.
  208. * NOTE erratum 0112 workaround #2
  209. */
  210. if ((desc->bEndpointAddress & USB_DIR_IN) == 0) {
  211. tmp = (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
  212. writel (tmp, &ep->regs->ep_irqenb);
  213. tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0);
  214. writel (tmp, &dev->regs->pciirqenb0);
  215. }
  216. }
  217. tmp = desc->bEndpointAddress;
  218. DEBUG (dev, "enabled %s (ep%d%s-%s) %s max %04x\n",
  219. _ep->name, tmp & 0x0f, DIR_STRING (tmp),
  220. type_string (desc->bmAttributes),
  221. ep->dma ? "dma" : "pio", max);
  222. /* pci writes may still be posted */
  223. spin_unlock_irqrestore (&dev->lock, flags);
  224. return 0;
  225. }
  226. static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec)
  227. {
  228. u32 result;
  229. do {
  230. result = readl (ptr);
  231. if (result == ~(u32)0) /* "device unplugged" */
  232. return -ENODEV;
  233. result &= mask;
  234. if (result == done)
  235. return 0;
  236. udelay (1);
  237. usec--;
  238. } while (usec > 0);
  239. return -ETIMEDOUT;
  240. }
  241. static const struct usb_ep_ops net2280_ep_ops;
  242. static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
  243. {
  244. u32 tmp;
  245. ep->desc = NULL;
  246. INIT_LIST_HEAD (&ep->queue);
  247. ep->ep.maxpacket = ~0;
  248. ep->ep.ops = &net2280_ep_ops;
  249. /* disable the dma, irqs, endpoint... */
  250. if (ep->dma) {
  251. writel (0, &ep->dma->dmactl);
  252. writel ( (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT)
  253. | (1 << DMA_TRANSACTION_DONE_INTERRUPT)
  254. | (1 << DMA_ABORT)
  255. , &ep->dma->dmastat);
  256. tmp = readl (&regs->pciirqenb0);
  257. tmp &= ~(1 << ep->num);
  258. writel (tmp, &regs->pciirqenb0);
  259. } else {
  260. tmp = readl (&regs->pciirqenb1);
  261. tmp &= ~(1 << (8 + ep->num)); /* completion */
  262. writel (tmp, &regs->pciirqenb1);
  263. }
  264. writel (0, &ep->regs->ep_irqenb);
  265. /* init to our chosen defaults, notably so that we NAK OUT
  266. * packets until the driver queues a read (+note erratum 0112)
  267. */
  268. if (!ep->is_in || ep->dev->pdev->device == 0x2280) {
  269. tmp = (1 << SET_NAK_OUT_PACKETS_MODE)
  270. | (1 << SET_NAK_OUT_PACKETS)
  271. | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
  272. | (1 << CLEAR_INTERRUPT_MODE);
  273. } else {
  274. /* added for 2282 */
  275. tmp = (1 << CLEAR_NAK_OUT_PACKETS_MODE)
  276. | (1 << CLEAR_NAK_OUT_PACKETS)
  277. | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
  278. | (1 << CLEAR_INTERRUPT_MODE);
  279. }
  280. if (ep->num != 0) {
  281. tmp |= (1 << CLEAR_ENDPOINT_TOGGLE)
  282. | (1 << CLEAR_ENDPOINT_HALT);
  283. }
  284. writel (tmp, &ep->regs->ep_rsp);
  285. /* scrub most status bits, and flush any fifo state */
  286. if (ep->dev->pdev->device == 0x2280)
  287. tmp = (1 << FIFO_OVERFLOW)
  288. | (1 << FIFO_UNDERFLOW);
  289. else
  290. tmp = 0;
  291. writel (tmp | (1 << TIMEOUT)
  292. | (1 << USB_STALL_SENT)
  293. | (1 << USB_IN_NAK_SENT)
  294. | (1 << USB_IN_ACK_RCVD)
  295. | (1 << USB_OUT_PING_NAK_SENT)
  296. | (1 << USB_OUT_ACK_SENT)
  297. | (1 << FIFO_FLUSH)
  298. | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
  299. | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
  300. | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
  301. | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
  302. | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  303. | (1 << DATA_IN_TOKEN_INTERRUPT)
  304. , &ep->regs->ep_stat);
  305. /* fifo size is handled separately */
  306. }
  307. static void nuke (struct net2280_ep *);
  308. static int net2280_disable (struct usb_ep *_ep)
  309. {
  310. struct net2280_ep *ep;
  311. unsigned long flags;
  312. ep = container_of (_ep, struct net2280_ep, ep);
  313. if (!_ep || !ep->desc || _ep->name == ep0name)
  314. return -EINVAL;
  315. spin_lock_irqsave (&ep->dev->lock, flags);
  316. nuke (ep);
  317. ep_reset (ep->dev->regs, ep);
  318. VDEBUG (ep->dev, "disabled %s %s\n",
  319. ep->dma ? "dma" : "pio", _ep->name);
  320. /* synch memory views with the device */
  321. (void) readl (&ep->regs->ep_cfg);
  322. if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4)
  323. ep->dma = &ep->dev->dma [ep->num - 1];
  324. spin_unlock_irqrestore (&ep->dev->lock, flags);
  325. return 0;
  326. }
  327. /*-------------------------------------------------------------------------*/
  328. static struct usb_request *
  329. net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
  330. {
  331. struct net2280_ep *ep;
  332. struct net2280_request *req;
  333. if (!_ep)
  334. return NULL;
  335. ep = container_of (_ep, struct net2280_ep, ep);
  336. req = kzalloc(sizeof(*req), gfp_flags);
  337. if (!req)
  338. return NULL;
  339. req->req.dma = DMA_ADDR_INVALID;
  340. INIT_LIST_HEAD (&req->queue);
  341. /* this dma descriptor may be swapped with the previous dummy */
  342. if (ep->dma) {
  343. struct net2280_dma *td;
  344. td = pci_pool_alloc (ep->dev->requests, gfp_flags,
  345. &req->td_dma);
  346. if (!td) {
  347. kfree (req);
  348. return NULL;
  349. }
  350. td->dmacount = 0; /* not VALID */
  351. td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
  352. td->dmadesc = td->dmaaddr;
  353. req->td = td;
  354. }
  355. return &req->req;
  356. }
  357. static void
  358. net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
  359. {
  360. struct net2280_ep *ep;
  361. struct net2280_request *req;
  362. ep = container_of (_ep, struct net2280_ep, ep);
  363. if (!_ep || !_req)
  364. return;
  365. req = container_of (_req, struct net2280_request, req);
  366. WARN_ON (!list_empty (&req->queue));
  367. if (req->td)
  368. pci_pool_free (ep->dev->requests, req->td, req->td_dma);
  369. kfree (req);
  370. }
  371. /*-------------------------------------------------------------------------*/
  372. /* load a packet into the fifo we use for usb IN transfers.
  373. * works for all endpoints.
  374. *
  375. * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
  376. * at a time, but this code is simpler because it knows it only writes
  377. * one packet. ep-a..ep-d should use dma instead.
  378. */
  379. static void
  380. write_fifo (struct net2280_ep *ep, struct usb_request *req)
  381. {
  382. struct net2280_ep_regs __iomem *regs = ep->regs;
  383. u8 *buf;
  384. u32 tmp;
  385. unsigned count, total;
  386. /* INVARIANT: fifo is currently empty. (testable) */
  387. if (req) {
  388. buf = req->buf + req->actual;
  389. prefetch (buf);
  390. total = req->length - req->actual;
  391. } else {
  392. total = 0;
  393. buf = NULL;
  394. }
  395. /* write just one packet at a time */
  396. count = ep->ep.maxpacket;
  397. if (count > total) /* min() cannot be used on a bitfield */
  398. count = total;
  399. VDEBUG (ep->dev, "write %s fifo (IN) %d bytes%s req %p\n",
  400. ep->ep.name, count,
  401. (count != ep->ep.maxpacket) ? " (short)" : "",
  402. req);
  403. while (count >= 4) {
  404. /* NOTE be careful if you try to align these. fifo lines
  405. * should normally be full (4 bytes) and successive partial
  406. * lines are ok only in certain cases.
  407. */
  408. tmp = get_unaligned ((u32 *)buf);
  409. cpu_to_le32s (&tmp);
  410. writel (tmp, &regs->ep_data);
  411. buf += 4;
  412. count -= 4;
  413. }
  414. /* last fifo entry is "short" unless we wrote a full packet.
  415. * also explicitly validate last word in (periodic) transfers
  416. * when maxpacket is not a multiple of 4 bytes.
  417. */
  418. if (count || total < ep->ep.maxpacket) {
  419. tmp = count ? get_unaligned ((u32 *)buf) : count;
  420. cpu_to_le32s (&tmp);
  421. set_fifo_bytecount (ep, count & 0x03);
  422. writel (tmp, &regs->ep_data);
  423. }
  424. /* pci writes may still be posted */
  425. }
  426. /* work around erratum 0106: PCI and USB race over the OUT fifo.
  427. * caller guarantees chiprev 0100, out endpoint is NAKing, and
  428. * there's no real data in the fifo.
  429. *
  430. * NOTE: also used in cases where that erratum doesn't apply:
  431. * where the host wrote "too much" data to us.
  432. */
  433. static void out_flush (struct net2280_ep *ep)
  434. {
  435. u32 __iomem *statp;
  436. u32 tmp;
  437. ASSERT_OUT_NAKING (ep);
  438. statp = &ep->regs->ep_stat;
  439. writel ( (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  440. | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
  441. , statp);
  442. writel ((1 << FIFO_FLUSH), statp);
  443. mb ();
  444. tmp = readl (statp);
  445. if (tmp & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  446. /* high speed did bulk NYET; fifo isn't filling */
  447. && ep->dev->gadget.speed == USB_SPEED_FULL) {
  448. unsigned usec;
  449. usec = 50; /* 64 byte bulk/interrupt */
  450. handshake (statp, (1 << USB_OUT_PING_NAK_SENT),
  451. (1 << USB_OUT_PING_NAK_SENT), usec);
  452. /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
  453. }
  454. }
  455. /* unload packet(s) from the fifo we use for usb OUT transfers.
  456. * returns true iff the request completed, because of short packet
  457. * or the request buffer having filled with full packets.
  458. *
  459. * for ep-a..ep-d this will read multiple packets out when they
  460. * have been accepted.
  461. */
  462. static int
  463. read_fifo (struct net2280_ep *ep, struct net2280_request *req)
  464. {
  465. struct net2280_ep_regs __iomem *regs = ep->regs;
  466. u8 *buf = req->req.buf + req->req.actual;
  467. unsigned count, tmp, is_short;
  468. unsigned cleanup = 0, prevent = 0;
  469. /* erratum 0106 ... packets coming in during fifo reads might
  470. * be incompletely rejected. not all cases have workarounds.
  471. */
  472. if (ep->dev->chiprev == 0x0100
  473. && ep->dev->gadget.speed == USB_SPEED_FULL) {
  474. udelay (1);
  475. tmp = readl (&ep->regs->ep_stat);
  476. if ((tmp & (1 << NAK_OUT_PACKETS)))
  477. cleanup = 1;
  478. else if ((tmp & (1 << FIFO_FULL))) {
  479. start_out_naking (ep);
  480. prevent = 1;
  481. }
  482. /* else: hope we don't see the problem */
  483. }
  484. /* never overflow the rx buffer. the fifo reads packets until
  485. * it sees a short one; we might not be ready for them all.
  486. */
  487. prefetchw (buf);
  488. count = readl (&regs->ep_avail);
  489. if (unlikely (count == 0)) {
  490. udelay (1);
  491. tmp = readl (&ep->regs->ep_stat);
  492. count = readl (&regs->ep_avail);
  493. /* handled that data already? */
  494. if (count == 0 && (tmp & (1 << NAK_OUT_PACKETS)) == 0)
  495. return 0;
  496. }
  497. tmp = req->req.length - req->req.actual;
  498. if (count > tmp) {
  499. /* as with DMA, data overflow gets flushed */
  500. if ((tmp % ep->ep.maxpacket) != 0) {
  501. ERROR (ep->dev,
  502. "%s out fifo %d bytes, expected %d\n",
  503. ep->ep.name, count, tmp);
  504. req->req.status = -EOVERFLOW;
  505. cleanup = 1;
  506. /* NAK_OUT_PACKETS will be set, so flushing is safe;
  507. * the next read will start with the next packet
  508. */
  509. } /* else it's a ZLP, no worries */
  510. count = tmp;
  511. }
  512. req->req.actual += count;
  513. is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
  514. VDEBUG (ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
  515. ep->ep.name, count, is_short ? " (short)" : "",
  516. cleanup ? " flush" : "", prevent ? " nak" : "",
  517. req, req->req.actual, req->req.length);
  518. while (count >= 4) {
  519. tmp = readl (&regs->ep_data);
  520. cpu_to_le32s (&tmp);
  521. put_unaligned (tmp, (u32 *)buf);
  522. buf += 4;
  523. count -= 4;
  524. }
  525. if (count) {
  526. tmp = readl (&regs->ep_data);
  527. /* LE conversion is implicit here: */
  528. do {
  529. *buf++ = (u8) tmp;
  530. tmp >>= 8;
  531. } while (--count);
  532. }
  533. if (cleanup)
  534. out_flush (ep);
  535. if (prevent) {
  536. writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
  537. (void) readl (&ep->regs->ep_rsp);
  538. }
  539. return is_short || ((req->req.actual == req->req.length)
  540. && !req->req.zero);
  541. }
  542. /* fill out dma descriptor to match a given request */
  543. static void
  544. fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
  545. {
  546. struct net2280_dma *td = req->td;
  547. u32 dmacount = req->req.length;
  548. /* don't let DMA continue after a short OUT packet,
  549. * so overruns can't affect the next transfer.
  550. * in case of overruns on max-size packets, we can't
  551. * stop the fifo from filling but we can flush it.
  552. */
  553. if (ep->is_in)
  554. dmacount |= (1 << DMA_DIRECTION);
  555. if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0)
  556. || ep->dev->pdev->device != 0x2280)
  557. dmacount |= (1 << END_OF_CHAIN);
  558. req->valid = valid;
  559. if (valid)
  560. dmacount |= (1 << VALID_BIT);
  561. if (likely(!req->req.no_interrupt || !use_dma_chaining))
  562. dmacount |= (1 << DMA_DONE_INTERRUPT_ENABLE);
  563. /* td->dmadesc = previously set by caller */
  564. td->dmaaddr = cpu_to_le32 (req->req.dma);
  565. /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
  566. wmb ();
  567. td->dmacount = cpu_to_le32(dmacount);
  568. }
  569. static const u32 dmactl_default =
  570. (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT)
  571. | (1 << DMA_CLEAR_COUNT_ENABLE)
  572. /* erratum 0116 workaround part 1 (use POLLING) */
  573. | (POLL_100_USEC << DESCRIPTOR_POLLING_RATE)
  574. | (1 << DMA_VALID_BIT_POLLING_ENABLE)
  575. | (1 << DMA_VALID_BIT_ENABLE)
  576. | (1 << DMA_SCATTER_GATHER_ENABLE)
  577. /* erratum 0116 workaround part 2 (no AUTOSTART) */
  578. | (1 << DMA_ENABLE);
  579. static inline void spin_stop_dma (struct net2280_dma_regs __iomem *dma)
  580. {
  581. handshake (&dma->dmactl, (1 << DMA_ENABLE), 0, 50);
  582. }
  583. static inline void stop_dma (struct net2280_dma_regs __iomem *dma)
  584. {
  585. writel (readl (&dma->dmactl) & ~(1 << DMA_ENABLE), &dma->dmactl);
  586. spin_stop_dma (dma);
  587. }
  588. static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma)
  589. {
  590. struct net2280_dma_regs __iomem *dma = ep->dma;
  591. unsigned int tmp = (1 << VALID_BIT) | (ep->is_in << DMA_DIRECTION);
  592. if (ep->dev->pdev->device != 0x2280)
  593. tmp |= (1 << END_OF_CHAIN);
  594. writel (tmp, &dma->dmacount);
  595. writel (readl (&dma->dmastat), &dma->dmastat);
  596. writel (td_dma, &dma->dmadesc);
  597. writel (dmactl, &dma->dmactl);
  598. /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
  599. (void) readl (&ep->dev->pci->pcimstctl);
  600. writel ((1 << DMA_START), &dma->dmastat);
  601. if (!ep->is_in)
  602. stop_out_naking (ep);
  603. }
  604. static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
  605. {
  606. u32 tmp;
  607. struct net2280_dma_regs __iomem *dma = ep->dma;
  608. /* FIXME can't use DMA for ZLPs */
  609. /* on this path we "know" there's no dma active (yet) */
  610. WARN_ON (readl (&dma->dmactl) & (1 << DMA_ENABLE));
  611. writel (0, &ep->dma->dmactl);
  612. /* previous OUT packet might have been short */
  613. if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat))
  614. & (1 << NAK_OUT_PACKETS)) != 0) {
  615. writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT),
  616. &ep->regs->ep_stat);
  617. tmp = readl (&ep->regs->ep_avail);
  618. if (tmp) {
  619. writel (readl (&dma->dmastat), &dma->dmastat);
  620. /* transfer all/some fifo data */
  621. writel (req->req.dma, &dma->dmaaddr);
  622. tmp = min (tmp, req->req.length);
  623. /* dma irq, faking scatterlist status */
  624. req->td->dmacount = cpu_to_le32 (req->req.length - tmp);
  625. writel ((1 << DMA_DONE_INTERRUPT_ENABLE)
  626. | tmp, &dma->dmacount);
  627. req->td->dmadesc = 0;
  628. req->valid = 1;
  629. writel ((1 << DMA_ENABLE), &dma->dmactl);
  630. writel ((1 << DMA_START), &dma->dmastat);
  631. return;
  632. }
  633. }
  634. tmp = dmactl_default;
  635. /* force packet boundaries between dma requests, but prevent the
  636. * controller from automagically writing a last "short" packet
  637. * (zero length) unless the driver explicitly said to do that.
  638. */
  639. if (ep->is_in) {
  640. if (likely ((req->req.length % ep->ep.maxpacket) != 0
  641. || req->req.zero)) {
  642. tmp |= (1 << DMA_FIFO_VALIDATE);
  643. ep->in_fifo_validate = 1;
  644. } else
  645. ep->in_fifo_validate = 0;
  646. }
  647. /* init req->td, pointing to the current dummy */
  648. req->td->dmadesc = cpu_to_le32 (ep->td_dma);
  649. fill_dma_desc (ep, req, 1);
  650. if (!use_dma_chaining)
  651. req->td->dmacount |= cpu_to_le32 (1 << END_OF_CHAIN);
  652. start_queue (ep, tmp, req->td_dma);
  653. }
  654. static inline void
  655. queue_dma (struct net2280_ep *ep, struct net2280_request *req, int valid)
  656. {
  657. struct net2280_dma *end;
  658. dma_addr_t tmp;
  659. /* swap new dummy for old, link; fill and maybe activate */
  660. end = ep->dummy;
  661. ep->dummy = req->td;
  662. req->td = end;
  663. tmp = ep->td_dma;
  664. ep->td_dma = req->td_dma;
  665. req->td_dma = tmp;
  666. end->dmadesc = cpu_to_le32 (ep->td_dma);
  667. fill_dma_desc (ep, req, valid);
  668. }
  669. static void
  670. done (struct net2280_ep *ep, struct net2280_request *req, int status)
  671. {
  672. struct net2280 *dev;
  673. unsigned stopped = ep->stopped;
  674. list_del_init (&req->queue);
  675. if (req->req.status == -EINPROGRESS)
  676. req->req.status = status;
  677. else
  678. status = req->req.status;
  679. dev = ep->dev;
  680. if (req->mapped) {
  681. pci_unmap_single (dev->pdev, req->req.dma, req->req.length,
  682. ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
  683. req->req.dma = DMA_ADDR_INVALID;
  684. req->mapped = 0;
  685. }
  686. if (status && status != -ESHUTDOWN)
  687. VDEBUG (dev, "complete %s req %p stat %d len %u/%u\n",
  688. ep->ep.name, &req->req, status,
  689. req->req.actual, req->req.length);
  690. /* don't modify queue heads during completion callback */
  691. ep->stopped = 1;
  692. spin_unlock (&dev->lock);
  693. req->req.complete (&ep->ep, &req->req);
  694. spin_lock (&dev->lock);
  695. ep->stopped = stopped;
  696. }
  697. /*-------------------------------------------------------------------------*/
  698. static int
  699. net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
  700. {
  701. struct net2280_request *req;
  702. struct net2280_ep *ep;
  703. struct net2280 *dev;
  704. unsigned long flags;
  705. /* we always require a cpu-view buffer, so that we can
  706. * always use pio (as fallback or whatever).
  707. */
  708. req = container_of (_req, struct net2280_request, req);
  709. if (!_req || !_req->complete || !_req->buf
  710. || !list_empty (&req->queue))
  711. return -EINVAL;
  712. if (_req->length > (~0 & DMA_BYTE_COUNT_MASK))
  713. return -EDOM;
  714. ep = container_of (_ep, struct net2280_ep, ep);
  715. if (!_ep || (!ep->desc && ep->num != 0))
  716. return -EINVAL;
  717. dev = ep->dev;
  718. if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
  719. return -ESHUTDOWN;
  720. /* FIXME implement PIO fallback for ZLPs with DMA */
  721. if (ep->dma && _req->length == 0)
  722. return -EOPNOTSUPP;
  723. /* set up dma mapping in case the caller didn't */
  724. if (ep->dma && _req->dma == DMA_ADDR_INVALID) {
  725. _req->dma = pci_map_single (dev->pdev, _req->buf, _req->length,
  726. ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
  727. req->mapped = 1;
  728. }
  729. #if 0
  730. VDEBUG (dev, "%s queue req %p, len %d buf %p\n",
  731. _ep->name, _req, _req->length, _req->buf);
  732. #endif
  733. spin_lock_irqsave (&dev->lock, flags);
  734. _req->status = -EINPROGRESS;
  735. _req->actual = 0;
  736. /* kickstart this i/o queue? */
  737. if (list_empty (&ep->queue) && !ep->stopped) {
  738. /* use DMA if the endpoint supports it, else pio */
  739. if (ep->dma)
  740. start_dma (ep, req);
  741. else {
  742. /* maybe there's no control data, just status ack */
  743. if (ep->num == 0 && _req->length == 0) {
  744. allow_status (ep);
  745. done (ep, req, 0);
  746. VDEBUG (dev, "%s status ack\n", ep->ep.name);
  747. goto done;
  748. }
  749. /* PIO ... stuff the fifo, or unblock it. */
  750. if (ep->is_in)
  751. write_fifo (ep, _req);
  752. else if (list_empty (&ep->queue)) {
  753. u32 s;
  754. /* OUT FIFO might have packet(s) buffered */
  755. s = readl (&ep->regs->ep_stat);
  756. if ((s & (1 << FIFO_EMPTY)) == 0) {
  757. /* note: _req->short_not_ok is
  758. * ignored here since PIO _always_
  759. * stops queue advance here, and
  760. * _req->status doesn't change for
  761. * short reads (only _req->actual)
  762. */
  763. if (read_fifo (ep, req)) {
  764. done (ep, req, 0);
  765. if (ep->num == 0)
  766. allow_status (ep);
  767. /* don't queue it */
  768. req = NULL;
  769. } else
  770. s = readl (&ep->regs->ep_stat);
  771. }
  772. /* don't NAK, let the fifo fill */
  773. if (req && (s & (1 << NAK_OUT_PACKETS)))
  774. writel ((1 << CLEAR_NAK_OUT_PACKETS),
  775. &ep->regs->ep_rsp);
  776. }
  777. }
  778. } else if (ep->dma) {
  779. int valid = 1;
  780. if (ep->is_in) {
  781. int expect;
  782. /* preventing magic zlps is per-engine state, not
  783. * per-transfer; irq logic must recover hiccups.
  784. */
  785. expect = likely (req->req.zero
  786. || (req->req.length % ep->ep.maxpacket) != 0);
  787. if (expect != ep->in_fifo_validate)
  788. valid = 0;
  789. }
  790. queue_dma (ep, req, valid);
  791. } /* else the irq handler advances the queue. */
  792. ep->responded = 1;
  793. if (req)
  794. list_add_tail (&req->queue, &ep->queue);
  795. done:
  796. spin_unlock_irqrestore (&dev->lock, flags);
  797. /* pci writes may still be posted */
  798. return 0;
  799. }
  800. static inline void
  801. dma_done (
  802. struct net2280_ep *ep,
  803. struct net2280_request *req,
  804. u32 dmacount,
  805. int status
  806. )
  807. {
  808. req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
  809. done (ep, req, status);
  810. }
  811. static void restart_dma (struct net2280_ep *ep);
  812. static void scan_dma_completions (struct net2280_ep *ep)
  813. {
  814. /* only look at descriptors that were "naturally" retired,
  815. * so fifo and list head state won't matter
  816. */
  817. while (!list_empty (&ep->queue)) {
  818. struct net2280_request *req;
  819. u32 tmp;
  820. req = list_entry (ep->queue.next,
  821. struct net2280_request, queue);
  822. if (!req->valid)
  823. break;
  824. rmb ();
  825. tmp = le32_to_cpup (&req->td->dmacount);
  826. if ((tmp & (1 << VALID_BIT)) != 0)
  827. break;
  828. /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
  829. * cases where DMA must be aborted; this code handles
  830. * all non-abort DMA completions.
  831. */
  832. if (unlikely (req->td->dmadesc == 0)) {
  833. /* paranoia */
  834. tmp = readl (&ep->dma->dmacount);
  835. if (tmp & DMA_BYTE_COUNT_MASK)
  836. break;
  837. /* single transfer mode */
  838. dma_done (ep, req, tmp, 0);
  839. break;
  840. } else if (!ep->is_in
  841. && (req->req.length % ep->ep.maxpacket) != 0) {
  842. tmp = readl (&ep->regs->ep_stat);
  843. /* AVOID TROUBLE HERE by not issuing short reads from
  844. * your gadget driver. That helps avoids errata 0121,
  845. * 0122, and 0124; not all cases trigger the warning.
  846. */
  847. if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
  848. WARNING (ep->dev, "%s lost packet sync!\n",
  849. ep->ep.name);
  850. req->req.status = -EOVERFLOW;
  851. } else if ((tmp = readl (&ep->regs->ep_avail)) != 0) {
  852. /* fifo gets flushed later */
  853. ep->out_overflow = 1;
  854. DEBUG (ep->dev, "%s dma, discard %d len %d\n",
  855. ep->ep.name, tmp,
  856. req->req.length);
  857. req->req.status = -EOVERFLOW;
  858. }
  859. }
  860. dma_done (ep, req, tmp, 0);
  861. }
  862. }
  863. static void restart_dma (struct net2280_ep *ep)
  864. {
  865. struct net2280_request *req;
  866. u32 dmactl = dmactl_default;
  867. if (ep->stopped)
  868. return;
  869. req = list_entry (ep->queue.next, struct net2280_request, queue);
  870. if (!use_dma_chaining) {
  871. start_dma (ep, req);
  872. return;
  873. }
  874. /* the 2280 will be processing the queue unless queue hiccups after
  875. * the previous transfer:
  876. * IN: wanted automagic zlp, head doesn't (or vice versa)
  877. * DMA_FIFO_VALIDATE doesn't init from dma descriptors.
  878. * OUT: was "usb-short", we must restart.
  879. */
  880. if (ep->is_in && !req->valid) {
  881. struct net2280_request *entry, *prev = NULL;
  882. int reqmode, done = 0;
  883. DEBUG (ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td);
  884. ep->in_fifo_validate = likely (req->req.zero
  885. || (req->req.length % ep->ep.maxpacket) != 0);
  886. if (ep->in_fifo_validate)
  887. dmactl |= (1 << DMA_FIFO_VALIDATE);
  888. list_for_each_entry (entry, &ep->queue, queue) {
  889. __le32 dmacount;
  890. if (entry == req)
  891. continue;
  892. dmacount = entry->td->dmacount;
  893. if (!done) {
  894. reqmode = likely (entry->req.zero
  895. || (entry->req.length
  896. % ep->ep.maxpacket) != 0);
  897. if (reqmode == ep->in_fifo_validate) {
  898. entry->valid = 1;
  899. dmacount |= valid_bit;
  900. entry->td->dmacount = dmacount;
  901. prev = entry;
  902. continue;
  903. } else {
  904. /* force a hiccup */
  905. prev->td->dmacount |= dma_done_ie;
  906. done = 1;
  907. }
  908. }
  909. /* walk the rest of the queue so unlinks behave */
  910. entry->valid = 0;
  911. dmacount &= ~valid_bit;
  912. entry->td->dmacount = dmacount;
  913. prev = entry;
  914. }
  915. }
  916. writel (0, &ep->dma->dmactl);
  917. start_queue (ep, dmactl, req->td_dma);
  918. }
  919. static void abort_dma (struct net2280_ep *ep)
  920. {
  921. /* abort the current transfer */
  922. if (likely (!list_empty (&ep->queue))) {
  923. /* FIXME work around errata 0121, 0122, 0124 */
  924. writel ((1 << DMA_ABORT), &ep->dma->dmastat);
  925. spin_stop_dma (ep->dma);
  926. } else
  927. stop_dma (ep->dma);
  928. scan_dma_completions (ep);
  929. }
  930. /* dequeue ALL requests */
  931. static void nuke (struct net2280_ep *ep)
  932. {
  933. struct net2280_request *req;
  934. /* called with spinlock held */
  935. ep->stopped = 1;
  936. if (ep->dma)
  937. abort_dma (ep);
  938. while (!list_empty (&ep->queue)) {
  939. req = list_entry (ep->queue.next,
  940. struct net2280_request,
  941. queue);
  942. done (ep, req, -ESHUTDOWN);
  943. }
  944. }
  945. /* dequeue JUST ONE request */
  946. static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
  947. {
  948. struct net2280_ep *ep;
  949. struct net2280_request *req;
  950. unsigned long flags;
  951. u32 dmactl;
  952. int stopped;
  953. ep = container_of (_ep, struct net2280_ep, ep);
  954. if (!_ep || (!ep->desc && ep->num != 0) || !_req)
  955. return -EINVAL;
  956. spin_lock_irqsave (&ep->dev->lock, flags);
  957. stopped = ep->stopped;
  958. /* quiesce dma while we patch the queue */
  959. dmactl = 0;
  960. ep->stopped = 1;
  961. if (ep->dma) {
  962. dmactl = readl (&ep->dma->dmactl);
  963. /* WARNING erratum 0127 may kick in ... */
  964. stop_dma (ep->dma);
  965. scan_dma_completions (ep);
  966. }
  967. /* make sure it's still queued on this endpoint */
  968. list_for_each_entry (req, &ep->queue, queue) {
  969. if (&req->req == _req)
  970. break;
  971. }
  972. if (&req->req != _req) {
  973. spin_unlock_irqrestore (&ep->dev->lock, flags);
  974. return -EINVAL;
  975. }
  976. /* queue head may be partially complete. */
  977. if (ep->queue.next == &req->queue) {
  978. if (ep->dma) {
  979. DEBUG (ep->dev, "unlink (%s) dma\n", _ep->name);
  980. _req->status = -ECONNRESET;
  981. abort_dma (ep);
  982. if (likely (ep->queue.next == &req->queue)) {
  983. // NOTE: misreports single-transfer mode
  984. req->td->dmacount = 0; /* invalidate */
  985. dma_done (ep, req,
  986. readl (&ep->dma->dmacount),
  987. -ECONNRESET);
  988. }
  989. } else {
  990. DEBUG (ep->dev, "unlink (%s) pio\n", _ep->name);
  991. done (ep, req, -ECONNRESET);
  992. }
  993. req = NULL;
  994. /* patch up hardware chaining data */
  995. } else if (ep->dma && use_dma_chaining) {
  996. if (req->queue.prev == ep->queue.next) {
  997. writel (le32_to_cpu (req->td->dmadesc),
  998. &ep->dma->dmadesc);
  999. if (req->td->dmacount & dma_done_ie)
  1000. writel (readl (&ep->dma->dmacount)
  1001. | le32_to_cpu(dma_done_ie),
  1002. &ep->dma->dmacount);
  1003. } else {
  1004. struct net2280_request *prev;
  1005. prev = list_entry (req->queue.prev,
  1006. struct net2280_request, queue);
  1007. prev->td->dmadesc = req->td->dmadesc;
  1008. if (req->td->dmacount & dma_done_ie)
  1009. prev->td->dmacount |= dma_done_ie;
  1010. }
  1011. }
  1012. if (req)
  1013. done (ep, req, -ECONNRESET);
  1014. ep->stopped = stopped;
  1015. if (ep->dma) {
  1016. /* turn off dma on inactive queues */
  1017. if (list_empty (&ep->queue))
  1018. stop_dma (ep->dma);
  1019. else if (!ep->stopped) {
  1020. /* resume current request, or start new one */
  1021. if (req)
  1022. writel (dmactl, &ep->dma->dmactl);
  1023. else
  1024. start_dma (ep, list_entry (ep->queue.next,
  1025. struct net2280_request, queue));
  1026. }
  1027. }
  1028. spin_unlock_irqrestore (&ep->dev->lock, flags);
  1029. return 0;
  1030. }
  1031. /*-------------------------------------------------------------------------*/
  1032. static int net2280_fifo_status (struct usb_ep *_ep);
  1033. static int
  1034. net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
  1035. {
  1036. struct net2280_ep *ep;
  1037. unsigned long flags;
  1038. int retval = 0;
  1039. ep = container_of (_ep, struct net2280_ep, ep);
  1040. if (!_ep || (!ep->desc && ep->num != 0))
  1041. return -EINVAL;
  1042. if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
  1043. return -ESHUTDOWN;
  1044. if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
  1045. == USB_ENDPOINT_XFER_ISOC)
  1046. return -EINVAL;
  1047. spin_lock_irqsave (&ep->dev->lock, flags);
  1048. if (!list_empty (&ep->queue))
  1049. retval = -EAGAIN;
  1050. else if (ep->is_in && value && net2280_fifo_status (_ep) != 0)
  1051. retval = -EAGAIN;
  1052. else {
  1053. VDEBUG (ep->dev, "%s %s %s\n", _ep->name,
  1054. value ? "set" : "clear",
  1055. wedged ? "wedge" : "halt");
  1056. /* set/clear, then synch memory views with the device */
  1057. if (value) {
  1058. if (ep->num == 0)
  1059. ep->dev->protocol_stall = 1;
  1060. else
  1061. set_halt (ep);
  1062. if (wedged)
  1063. ep->wedged = 1;
  1064. } else {
  1065. clear_halt (ep);
  1066. ep->wedged = 0;
  1067. }
  1068. (void) readl (&ep->regs->ep_rsp);
  1069. }
  1070. spin_unlock_irqrestore (&ep->dev->lock, flags);
  1071. return retval;
  1072. }
  1073. static int
  1074. net2280_set_halt(struct usb_ep *_ep, int value)
  1075. {
  1076. return net2280_set_halt_and_wedge(_ep, value, 0);
  1077. }
  1078. static int
  1079. net2280_set_wedge(struct usb_ep *_ep)
  1080. {
  1081. if (!_ep || _ep->name == ep0name)
  1082. return -EINVAL;
  1083. return net2280_set_halt_and_wedge(_ep, 1, 1);
  1084. }
  1085. static int
  1086. net2280_fifo_status (struct usb_ep *_ep)
  1087. {
  1088. struct net2280_ep *ep;
  1089. u32 avail;
  1090. ep = container_of (_ep, struct net2280_ep, ep);
  1091. if (!_ep || (!ep->desc && ep->num != 0))
  1092. return -ENODEV;
  1093. if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
  1094. return -ESHUTDOWN;
  1095. avail = readl (&ep->regs->ep_avail) & ((1 << 12) - 1);
  1096. if (avail > ep->fifo_size)
  1097. return -EOVERFLOW;
  1098. if (ep->is_in)
  1099. avail = ep->fifo_size - avail;
  1100. return avail;
  1101. }
  1102. static void
  1103. net2280_fifo_flush (struct usb_ep *_ep)
  1104. {
  1105. struct net2280_ep *ep;
  1106. ep = container_of (_ep, struct net2280_ep, ep);
  1107. if (!_ep || (!ep->desc && ep->num != 0))
  1108. return;
  1109. if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
  1110. return;
  1111. writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat);
  1112. (void) readl (&ep->regs->ep_rsp);
  1113. }
  1114. static const struct usb_ep_ops net2280_ep_ops = {
  1115. .enable = net2280_enable,
  1116. .disable = net2280_disable,
  1117. .alloc_request = net2280_alloc_request,
  1118. .free_request = net2280_free_request,
  1119. .queue = net2280_queue,
  1120. .dequeue = net2280_dequeue,
  1121. .set_halt = net2280_set_halt,
  1122. .set_wedge = net2280_set_wedge,
  1123. .fifo_status = net2280_fifo_status,
  1124. .fifo_flush = net2280_fifo_flush,
  1125. };
  1126. /*-------------------------------------------------------------------------*/
  1127. static int net2280_get_frame (struct usb_gadget *_gadget)
  1128. {
  1129. struct net2280 *dev;
  1130. unsigned long flags;
  1131. u16 retval;
  1132. if (!_gadget)
  1133. return -ENODEV;
  1134. dev = container_of (_gadget, struct net2280, gadget);
  1135. spin_lock_irqsave (&dev->lock, flags);
  1136. retval = get_idx_reg (dev->regs, REG_FRAME) & 0x03ff;
  1137. spin_unlock_irqrestore (&dev->lock, flags);
  1138. return retval;
  1139. }
  1140. static int net2280_wakeup (struct usb_gadget *_gadget)
  1141. {
  1142. struct net2280 *dev;
  1143. u32 tmp;
  1144. unsigned long flags;
  1145. if (!_gadget)
  1146. return 0;
  1147. dev = container_of (_gadget, struct net2280, gadget);
  1148. spin_lock_irqsave (&dev->lock, flags);
  1149. tmp = readl (&dev->usb->usbctl);
  1150. if (tmp & (1 << DEVICE_REMOTE_WAKEUP_ENABLE))
  1151. writel (1 << GENERATE_RESUME, &dev->usb->usbstat);
  1152. spin_unlock_irqrestore (&dev->lock, flags);
  1153. /* pci writes may still be posted */
  1154. return 0;
  1155. }
  1156. static int net2280_set_selfpowered (struct usb_gadget *_gadget, int value)
  1157. {
  1158. struct net2280 *dev;
  1159. u32 tmp;
  1160. unsigned long flags;
  1161. if (!_gadget)
  1162. return 0;
  1163. dev = container_of (_gadget, struct net2280, gadget);
  1164. spin_lock_irqsave (&dev->lock, flags);
  1165. tmp = readl (&dev->usb->usbctl);
  1166. if (value)
  1167. tmp |= (1 << SELF_POWERED_STATUS);
  1168. else
  1169. tmp &= ~(1 << SELF_POWERED_STATUS);
  1170. writel (tmp, &dev->usb->usbctl);
  1171. spin_unlock_irqrestore (&dev->lock, flags);
  1172. return 0;
  1173. }
  1174. static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
  1175. {
  1176. struct net2280 *dev;
  1177. u32 tmp;
  1178. unsigned long flags;
  1179. if (!_gadget)
  1180. return -ENODEV;
  1181. dev = container_of (_gadget, struct net2280, gadget);
  1182. spin_lock_irqsave (&dev->lock, flags);
  1183. tmp = readl (&dev->usb->usbctl);
  1184. dev->softconnect = (is_on != 0);
  1185. if (is_on)
  1186. tmp |= (1 << USB_DETECT_ENABLE);
  1187. else
  1188. tmp &= ~(1 << USB_DETECT_ENABLE);
  1189. writel (tmp, &dev->usb->usbctl);
  1190. spin_unlock_irqrestore (&dev->lock, flags);
  1191. return 0;
  1192. }
  1193. static int net2280_start(struct usb_gadget_driver *driver,
  1194. int (*bind)(struct usb_gadget *));
  1195. static int net2280_stop(struct usb_gadget_driver *driver);
  1196. static const struct usb_gadget_ops net2280_ops = {
  1197. .get_frame = net2280_get_frame,
  1198. .wakeup = net2280_wakeup,
  1199. .set_selfpowered = net2280_set_selfpowered,
  1200. .pullup = net2280_pullup,
  1201. .start = net2280_start,
  1202. .stop = net2280_stop,
  1203. };
  1204. /*-------------------------------------------------------------------------*/
  1205. #ifdef CONFIG_USB_GADGET_DEBUG_FILES
  1206. /* FIXME move these into procfs, and use seq_file.
  1207. * Sysfs _still_ doesn't behave for arbitrarily sized files,
  1208. * and also doesn't help products using this with 2.4 kernels.
  1209. */
  1210. /* "function" sysfs attribute */
  1211. static ssize_t
  1212. show_function (struct device *_dev, struct device_attribute *attr, char *buf)
  1213. {
  1214. struct net2280 *dev = dev_get_drvdata (_dev);
  1215. if (!dev->driver
  1216. || !dev->driver->function
  1217. || strlen (dev->driver->function) > PAGE_SIZE)
  1218. return 0;
  1219. return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
  1220. }
  1221. static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
  1222. static ssize_t net2280_show_registers(struct device *_dev,
  1223. struct device_attribute *attr, char *buf)
  1224. {
  1225. struct net2280 *dev;
  1226. char *next;
  1227. unsigned size, t;
  1228. unsigned long flags;
  1229. int i;
  1230. u32 t1, t2;
  1231. const char *s;
  1232. dev = dev_get_drvdata (_dev);
  1233. next = buf;
  1234. size = PAGE_SIZE;
  1235. spin_lock_irqsave (&dev->lock, flags);
  1236. if (dev->driver)
  1237. s = dev->driver->driver.name;
  1238. else
  1239. s = "(none)";
  1240. /* Main Control Registers */
  1241. t = scnprintf (next, size, "%s version " DRIVER_VERSION
  1242. ", chiprev %04x, dma %s\n\n"
  1243. "devinit %03x fifoctl %08x gadget '%s'\n"
  1244. "pci irqenb0 %02x irqenb1 %08x "
  1245. "irqstat0 %04x irqstat1 %08x\n",
  1246. driver_name, dev->chiprev,
  1247. use_dma
  1248. ? (use_dma_chaining ? "chaining" : "enabled")
  1249. : "disabled",
  1250. readl (&dev->regs->devinit),
  1251. readl (&dev->regs->fifoctl),
  1252. s,
  1253. readl (&dev->regs->pciirqenb0),
  1254. readl (&dev->regs->pciirqenb1),
  1255. readl (&dev->regs->irqstat0),
  1256. readl (&dev->regs->irqstat1));
  1257. size -= t;
  1258. next += t;
  1259. /* USB Control Registers */
  1260. t1 = readl (&dev->usb->usbctl);
  1261. t2 = readl (&dev->usb->usbstat);
  1262. if (t1 & (1 << VBUS_PIN)) {
  1263. if (t2 & (1 << HIGH_SPEED))
  1264. s = "high speed";
  1265. else if (dev->gadget.speed == USB_SPEED_UNKNOWN)
  1266. s = "powered";
  1267. else
  1268. s = "full speed";
  1269. /* full speed bit (6) not working?? */
  1270. } else
  1271. s = "not attached";
  1272. t = scnprintf (next, size,
  1273. "stdrsp %08x usbctl %08x usbstat %08x "
  1274. "addr 0x%02x (%s)\n",
  1275. readl (&dev->usb->stdrsp), t1, t2,
  1276. readl (&dev->usb->ouraddr), s);
  1277. size -= t;
  1278. next += t;
  1279. /* PCI Master Control Registers */
  1280. /* DMA Control Registers */
  1281. /* Configurable EP Control Registers */
  1282. for (i = 0; i < 7; i++) {
  1283. struct net2280_ep *ep;
  1284. ep = &dev->ep [i];
  1285. if (i && !ep->desc)
  1286. continue;
  1287. t1 = readl (&ep->regs->ep_cfg);
  1288. t2 = readl (&ep->regs->ep_rsp) & 0xff;
  1289. t = scnprintf (next, size,
  1290. "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
  1291. "irqenb %02x\n",
  1292. ep->ep.name, t1, t2,
  1293. (t2 & (1 << CLEAR_NAK_OUT_PACKETS))
  1294. ? "NAK " : "",
  1295. (t2 & (1 << CLEAR_EP_HIDE_STATUS_PHASE))
  1296. ? "hide " : "",
  1297. (t2 & (1 << CLEAR_EP_FORCE_CRC_ERROR))
  1298. ? "CRC " : "",
  1299. (t2 & (1 << CLEAR_INTERRUPT_MODE))
  1300. ? "interrupt " : "",
  1301. (t2 & (1<<CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE))
  1302. ? "status " : "",
  1303. (t2 & (1 << CLEAR_NAK_OUT_PACKETS_MODE))
  1304. ? "NAKmode " : "",
  1305. (t2 & (1 << CLEAR_ENDPOINT_TOGGLE))
  1306. ? "DATA1 " : "DATA0 ",
  1307. (t2 & (1 << CLEAR_ENDPOINT_HALT))
  1308. ? "HALT " : "",
  1309. readl (&ep->regs->ep_irqenb));
  1310. size -= t;
  1311. next += t;
  1312. t = scnprintf (next, size,
  1313. "\tstat %08x avail %04x "
  1314. "(ep%d%s-%s)%s\n",
  1315. readl (&ep->regs->ep_stat),
  1316. readl (&ep->regs->ep_avail),
  1317. t1 & 0x0f, DIR_STRING (t1),
  1318. type_string (t1 >> 8),
  1319. ep->stopped ? "*" : "");
  1320. size -= t;
  1321. next += t;
  1322. if (!ep->dma)
  1323. continue;
  1324. t = scnprintf (next, size,
  1325. " dma\tctl %08x stat %08x count %08x\n"
  1326. "\taddr %08x desc %08x\n",
  1327. readl (&ep->dma->dmactl),
  1328. readl (&ep->dma->dmastat),
  1329. readl (&ep->dma->dmacount),
  1330. readl (&ep->dma->dmaaddr),
  1331. readl (&ep->dma->dmadesc));
  1332. size -= t;
  1333. next += t;
  1334. }
  1335. /* Indexed Registers */
  1336. // none yet
  1337. /* Statistics */
  1338. t = scnprintf (next, size, "\nirqs: ");
  1339. size -= t;
  1340. next += t;
  1341. for (i = 0; i < 7; i++) {
  1342. struct net2280_ep *ep;
  1343. ep = &dev->ep [i];
  1344. if (i && !ep->irqs)
  1345. continue;
  1346. t = scnprintf (next, size, " %s/%lu", ep->ep.name, ep->irqs);
  1347. size -= t;
  1348. next += t;
  1349. }
  1350. t = scnprintf (next, size, "\n");
  1351. size -= t;
  1352. next += t;
  1353. spin_unlock_irqrestore (&dev->lock, flags);
  1354. return PAGE_SIZE - size;
  1355. }
  1356. static DEVICE_ATTR(registers, S_IRUGO, net2280_show_registers, NULL);
  1357. static ssize_t
  1358. show_queues (struct device *_dev, struct device_attribute *attr, char *buf)
  1359. {
  1360. struct net2280 *dev;
  1361. char *next;
  1362. unsigned size;
  1363. unsigned long flags;
  1364. int i;
  1365. dev = dev_get_drvdata (_dev);
  1366. next = buf;
  1367. size = PAGE_SIZE;
  1368. spin_lock_irqsave (&dev->lock, flags);
  1369. for (i = 0; i < 7; i++) {
  1370. struct net2280_ep *ep = &dev->ep [i];
  1371. struct net2280_request *req;
  1372. int t;
  1373. if (i != 0) {
  1374. const struct usb_endpoint_descriptor *d;
  1375. d = ep->desc;
  1376. if (!d)
  1377. continue;
  1378. t = d->bEndpointAddress;
  1379. t = scnprintf (next, size,
  1380. "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
  1381. ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK,
  1382. (t & USB_DIR_IN) ? "in" : "out",
  1383. ({ char *val;
  1384. switch (d->bmAttributes & 0x03) {
  1385. case USB_ENDPOINT_XFER_BULK:
  1386. val = "bulk"; break;
  1387. case USB_ENDPOINT_XFER_INT:
  1388. val = "intr"; break;
  1389. default:
  1390. val = "iso"; break;
  1391. }; val; }),
  1392. usb_endpoint_maxp (d) & 0x1fff,
  1393. ep->dma ? "dma" : "pio", ep->fifo_size
  1394. );
  1395. } else /* ep0 should only have one transfer queued */
  1396. t = scnprintf (next, size, "ep0 max 64 pio %s\n",
  1397. ep->is_in ? "in" : "out");
  1398. if (t <= 0 || t > size)
  1399. goto done;
  1400. size -= t;
  1401. next += t;
  1402. if (list_empty (&ep->queue)) {
  1403. t = scnprintf (next, size, "\t(nothing queued)\n");
  1404. if (t <= 0 || t > size)
  1405. goto done;
  1406. size -= t;
  1407. next += t;
  1408. continue;
  1409. }
  1410. list_for_each_entry (req, &ep->queue, queue) {
  1411. if (ep->dma && req->td_dma == readl (&ep->dma->dmadesc))
  1412. t = scnprintf (next, size,
  1413. "\treq %p len %d/%d "
  1414. "buf %p (dmacount %08x)\n",
  1415. &req->req, req->req.actual,
  1416. req->req.length, req->req.buf,
  1417. readl (&ep->dma->dmacount));
  1418. else
  1419. t = scnprintf (next, size,
  1420. "\treq %p len %d/%d buf %p\n",
  1421. &req->req, req->req.actual,
  1422. req->req.length, req->req.buf);
  1423. if (t <= 0 || t > size)
  1424. goto done;
  1425. size -= t;
  1426. next += t;
  1427. if (ep->dma) {
  1428. struct net2280_dma *td;
  1429. td = req->td;
  1430. t = scnprintf (next, size, "\t td %08x "
  1431. " count %08x buf %08x desc %08x\n",
  1432. (u32) req->td_dma,
  1433. le32_to_cpu (td->dmacount),
  1434. le32_to_cpu (td->dmaaddr),
  1435. le32_to_cpu (td->dmadesc));
  1436. if (t <= 0 || t > size)
  1437. goto done;
  1438. size -= t;
  1439. next += t;
  1440. }
  1441. }
  1442. }
  1443. done:
  1444. spin_unlock_irqrestore (&dev->lock, flags);
  1445. return PAGE_SIZE - size;
  1446. }
  1447. static DEVICE_ATTR (queues, S_IRUGO, show_queues, NULL);
  1448. #else
  1449. #define device_create_file(a,b) (0)
  1450. #define device_remove_file(a,b) do { } while (0)
  1451. #endif
  1452. /*-------------------------------------------------------------------------*/
  1453. /* another driver-specific mode might be a request type doing dma
  1454. * to/from another device fifo instead of to/from memory.
  1455. */
  1456. static void set_fifo_mode (struct net2280 *dev, int mode)
  1457. {
  1458. /* keeping high bits preserves BAR2 */
  1459. writel ((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl);
  1460. /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
  1461. INIT_LIST_HEAD (&dev->gadget.ep_list);
  1462. list_add_tail (&dev->ep [1].ep.ep_list, &dev->gadget.ep_list);
  1463. list_add_tail (&dev->ep [2].ep.ep_list, &dev->gadget.ep_list);
  1464. switch (mode) {
  1465. case 0:
  1466. list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
  1467. list_add_tail (&dev->ep [4].ep.ep_list, &dev->gadget.ep_list);
  1468. dev->ep [1].fifo_size = dev->ep [2].fifo_size = 1024;
  1469. break;
  1470. case 1:
  1471. dev->ep [1].fifo_size = dev->ep [2].fifo_size = 2048;
  1472. break;
  1473. case 2:
  1474. list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
  1475. dev->ep [1].fifo_size = 2048;
  1476. dev->ep [2].fifo_size = 1024;
  1477. break;
  1478. }
  1479. /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
  1480. list_add_tail (&dev->ep [5].ep.ep_list, &dev->gadget.ep_list);
  1481. list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
  1482. }
  1483. /* keeping it simple:
  1484. * - one bus driver, initted first;
  1485. * - one function driver, initted second
  1486. *
  1487. * most of the work to support multiple net2280 controllers would
  1488. * be to associate this gadget driver (yes?) with all of them, or
  1489. * perhaps to bind specific drivers to specific devices.
  1490. */
  1491. static struct net2280 *the_controller;
  1492. static void usb_reset (struct net2280 *dev)
  1493. {
  1494. u32 tmp;
  1495. dev->gadget.speed = USB_SPEED_UNKNOWN;
  1496. (void) readl (&dev->usb->usbctl);
  1497. net2280_led_init (dev);
  1498. /* disable automatic responses, and irqs */
  1499. writel (0, &dev->usb->stdrsp);
  1500. writel (0, &dev->regs->pciirqenb0);
  1501. writel (0, &dev->regs->pciirqenb1);
  1502. /* clear old dma and irq state */
  1503. for (tmp = 0; tmp < 4; tmp++) {
  1504. struct net2280_ep *ep = &dev->ep [tmp + 1];
  1505. if (ep->dma)
  1506. abort_dma (ep);
  1507. }
  1508. writel (~0, &dev->regs->irqstat0),
  1509. writel (~(1 << SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1),
  1510. /* reset, and enable pci */
  1511. tmp = readl (&dev->regs->devinit)
  1512. | (1 << PCI_ENABLE)
  1513. | (1 << FIFO_SOFT_RESET)
  1514. | (1 << USB_SOFT_RESET)
  1515. | (1 << M8051_RESET);
  1516. writel (tmp, &dev->regs->devinit);
  1517. /* standard fifo and endpoint allocations */
  1518. set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0);
  1519. }
  1520. static void usb_reinit (struct net2280 *dev)
  1521. {
  1522. u32 tmp;
  1523. int init_dma;
  1524. /* use_dma changes are ignored till next device re-init */
  1525. init_dma = use_dma;
  1526. /* basic endpoint init */
  1527. for (tmp = 0; tmp < 7; tmp++) {
  1528. struct net2280_ep *ep = &dev->ep [tmp];
  1529. ep->ep.name = ep_name [tmp];
  1530. ep->dev = dev;
  1531. ep->num = tmp;
  1532. if (tmp > 0 && tmp <= 4) {
  1533. ep->fifo_size = 1024;
  1534. if (init_dma)
  1535. ep->dma = &dev->dma [tmp - 1];
  1536. } else
  1537. ep->fifo_size = 64;
  1538. ep->regs = &dev->epregs [tmp];
  1539. ep_reset (dev->regs, ep);
  1540. }
  1541. dev->ep [0].ep.maxpacket = 64;
  1542. dev->ep [5].ep.maxpacket = 64;
  1543. dev->ep [6].ep.maxpacket = 64;
  1544. dev->gadget.ep0 = &dev->ep [0].ep;
  1545. dev->ep [0].stopped = 0;
  1546. INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
  1547. /* we want to prevent lowlevel/insecure access from the USB host,
  1548. * but erratum 0119 means this enable bit is ignored
  1549. */
  1550. for (tmp = 0; tmp < 5; tmp++)
  1551. writel (EP_DONTUSE, &dev->dep [tmp].dep_cfg);
  1552. }
  1553. static void ep0_start (struct net2280 *dev)
  1554. {
  1555. writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE)
  1556. | (1 << CLEAR_NAK_OUT_PACKETS)
  1557. | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
  1558. , &dev->epregs [0].ep_rsp);
  1559. /*
  1560. * hardware optionally handles a bunch of standard requests
  1561. * that the API hides from drivers anyway. have it do so.
  1562. * endpoint status/features are handled in software, to
  1563. * help pass tests for some dubious behavior.
  1564. */
  1565. writel ( (1 << SET_TEST_MODE)
  1566. | (1 << SET_ADDRESS)
  1567. | (1 << DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP)
  1568. | (1 << GET_DEVICE_STATUS)
  1569. | (1 << GET_INTERFACE_STATUS)
  1570. , &dev->usb->stdrsp);
  1571. writel ( (1 << USB_ROOT_PORT_WAKEUP_ENABLE)
  1572. | (1 << SELF_POWERED_USB_DEVICE)
  1573. | (1 << REMOTE_WAKEUP_SUPPORT)
  1574. | (dev->softconnect << USB_DETECT_ENABLE)
  1575. | (1 << SELF_POWERED_STATUS)
  1576. , &dev->usb->usbctl);
  1577. /* enable irqs so we can see ep0 and general operation */
  1578. writel ( (1 << SETUP_PACKET_INTERRUPT_ENABLE)
  1579. | (1 << ENDPOINT_0_INTERRUPT_ENABLE)
  1580. , &dev->regs->pciirqenb0);
  1581. writel ( (1 << PCI_INTERRUPT_ENABLE)
  1582. | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE)
  1583. | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE)
  1584. | (1 << PCI_RETRY_ABORT_INTERRUPT_ENABLE)
  1585. | (1 << VBUS_INTERRUPT_ENABLE)
  1586. | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE)
  1587. | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE)
  1588. , &dev->regs->pciirqenb1);
  1589. /* don't leave any writes posted */
  1590. (void) readl (&dev->usb->usbctl);
  1591. }
  1592. /* when a driver is successfully registered, it will receive
  1593. * control requests including set_configuration(), which enables
  1594. * non-control requests. then usb traffic follows until a
  1595. * disconnect is reported. then a host may connect again, or
  1596. * the driver might get unbound.
  1597. */
  1598. static int net2280_start(struct usb_gadget_driver *driver,
  1599. int (*bind)(struct usb_gadget *))
  1600. {
  1601. struct net2280 *dev = the_controller;
  1602. int retval;
  1603. unsigned i;
  1604. /* insist on high speed support from the driver, since
  1605. * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
  1606. * "must not be used in normal operation"
  1607. */
  1608. if (!driver
  1609. || driver->speed != USB_SPEED_HIGH
  1610. || !bind || !driver->setup)
  1611. return -EINVAL;
  1612. if (!dev)
  1613. return -ENODEV;
  1614. if (dev->driver)
  1615. return -EBUSY;
  1616. for (i = 0; i < 7; i++)
  1617. dev->ep [i].irqs = 0;
  1618. /* hook up the driver ... */
  1619. dev->softconnect = 1;
  1620. driver->driver.bus = NULL;
  1621. dev->driver = driver;
  1622. dev->gadget.dev.driver = &driver->driver;
  1623. retval = bind(&dev->gadget);
  1624. if (retval) {
  1625. DEBUG (dev, "bind to driver %s --> %d\n",
  1626. driver->driver.name, retval);
  1627. dev->driver = NULL;
  1628. dev->gadget.dev.driver = NULL;
  1629. return retval;
  1630. }
  1631. retval = device_create_file (&dev->pdev->dev, &dev_attr_function);
  1632. if (retval) goto err_unbind;
  1633. retval = device_create_file (&dev->pdev->dev, &dev_attr_queues);
  1634. if (retval) goto err_func;
  1635. /* ... then enable host detection and ep0; and we're ready
  1636. * for set_configuration as well as eventual disconnect.
  1637. */
  1638. net2280_led_active (dev, 1);
  1639. ep0_start (dev);
  1640. DEBUG (dev, "%s ready, usbctl %08x stdrsp %08x\n",
  1641. driver->driver.name,
  1642. readl (&dev->usb->usbctl),
  1643. readl (&dev->usb->stdrsp));
  1644. /* pci writes may still be posted */
  1645. return 0;
  1646. err_func:
  1647. device_remove_file (&dev->pdev->dev, &dev_attr_function);
  1648. err_unbind:
  1649. driver->unbind (&dev->gadget);
  1650. dev->gadget.dev.driver = NULL;
  1651. dev->driver = NULL;
  1652. return retval;
  1653. }
  1654. static void
  1655. stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
  1656. {
  1657. int i;
  1658. /* don't disconnect if it's not connected */
  1659. if (dev->gadget.speed == USB_SPEED_UNKNOWN)
  1660. driver = NULL;
  1661. /* stop hardware; prevent new request submissions;
  1662. * and kill any outstanding requests.
  1663. */
  1664. usb_reset (dev);
  1665. for (i = 0; i < 7; i++)
  1666. nuke (&dev->ep [i]);
  1667. /* report disconnect; the driver is already quiesced */
  1668. if (driver) {
  1669. spin_unlock (&dev->lock);
  1670. driver->disconnect (&dev->gadget);
  1671. spin_lock (&dev->lock);
  1672. }
  1673. usb_reinit (dev);
  1674. }
  1675. static int net2280_stop(struct usb_gadget_driver *driver)
  1676. {
  1677. struct net2280 *dev = the_controller;
  1678. unsigned long flags;
  1679. if (!dev)
  1680. return -ENODEV;
  1681. if (!driver || driver != dev->driver || !driver->unbind)
  1682. return -EINVAL;
  1683. spin_lock_irqsave (&dev->lock, flags);
  1684. stop_activity (dev, driver);
  1685. spin_unlock_irqrestore (&dev->lock, flags);
  1686. net2280_pullup (&dev->gadget, 0);
  1687. driver->unbind (&dev->gadget);
  1688. dev->gadget.dev.driver = NULL;
  1689. dev->driver = NULL;
  1690. net2280_led_active (dev, 0);
  1691. device_remove_file (&dev->pdev->dev, &dev_attr_function);
  1692. device_remove_file (&dev->pdev->dev, &dev_attr_queues);
  1693. DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name);
  1694. return 0;
  1695. }
  1696. /*-------------------------------------------------------------------------*/
  1697. /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
  1698. * also works for dma-capable endpoints, in pio mode or just
  1699. * to manually advance the queue after short OUT transfers.
  1700. */
  1701. static void handle_ep_small (struct net2280_ep *ep)
  1702. {
  1703. struct net2280_request *req;
  1704. u32 t;
  1705. /* 0 error, 1 mid-data, 2 done */
  1706. int mode = 1;
  1707. if (!list_empty (&ep->queue))
  1708. req = list_entry (ep->queue.next,
  1709. struct net2280_request, queue);
  1710. else
  1711. req = NULL;
  1712. /* ack all, and handle what we care about */
  1713. t = readl (&ep->regs->ep_stat);
  1714. ep->irqs++;
  1715. #if 0
  1716. VDEBUG (ep->dev, "%s ack ep_stat %08x, req %p\n",
  1717. ep->ep.name, t, req ? &req->req : 0);
  1718. #endif
  1719. if (!ep->is_in || ep->dev->pdev->device == 0x2280)
  1720. writel (t & ~(1 << NAK_OUT_PACKETS), &ep->regs->ep_stat);
  1721. else
  1722. /* Added for 2282 */
  1723. writel (t, &ep->regs->ep_stat);
  1724. /* for ep0, monitor token irqs to catch data stage length errors
  1725. * and to synchronize on status.
  1726. *
  1727. * also, to defer reporting of protocol stalls ... here's where
  1728. * data or status first appears, handling stalls here should never
  1729. * cause trouble on the host side..
  1730. *
  1731. * control requests could be slightly faster without token synch for
  1732. * status, but status can jam up that way.
  1733. */
  1734. if (unlikely (ep->num == 0)) {
  1735. if (ep->is_in) {
  1736. /* status; stop NAKing */
  1737. if (t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) {
  1738. if (ep->dev->protocol_stall) {
  1739. ep->stopped = 1;
  1740. set_halt (ep);
  1741. }
  1742. if (!req)
  1743. allow_status (ep);
  1744. mode = 2;
  1745. /* reply to extra IN data tokens with a zlp */
  1746. } else if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
  1747. if (ep->dev->protocol_stall) {
  1748. ep->stopped = 1;
  1749. set_halt (ep);
  1750. mode = 2;
  1751. } else if (ep->responded &&
  1752. !req && !ep->stopped)
  1753. write_fifo (ep, NULL);
  1754. }
  1755. } else {
  1756. /* status; stop NAKing */
  1757. if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
  1758. if (ep->dev->protocol_stall) {
  1759. ep->stopped = 1;
  1760. set_halt (ep);
  1761. }
  1762. mode = 2;
  1763. /* an extra OUT token is an error */
  1764. } else if (((t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT))
  1765. && req
  1766. && req->req.actual == req->req.length)
  1767. || (ep->responded && !req)) {
  1768. ep->dev->protocol_stall = 1;
  1769. set_halt (ep);
  1770. ep->stopped = 1;
  1771. if (req)
  1772. done (ep, req, -EOVERFLOW);
  1773. req = NULL;
  1774. }
  1775. }
  1776. }
  1777. if (unlikely (!req))
  1778. return;
  1779. /* manual DMA queue advance after short OUT */
  1780. if (likely (ep->dma != 0)) {
  1781. if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
  1782. u32 count;
  1783. int stopped = ep->stopped;
  1784. /* TRANSFERRED works around OUT_DONE erratum 0112.
  1785. * we expect (N <= maxpacket) bytes; host wrote M.
  1786. * iff (M < N) we won't ever see a DMA interrupt.
  1787. */
  1788. ep->stopped = 1;
  1789. for (count = 0; ; t = readl (&ep->regs->ep_stat)) {
  1790. /* any preceding dma transfers must finish.
  1791. * dma handles (M >= N), may empty the queue
  1792. */
  1793. scan_dma_completions (ep);
  1794. if (unlikely (list_empty (&ep->queue)
  1795. || ep->out_overflow)) {
  1796. req = NULL;
  1797. break;
  1798. }
  1799. req = list_entry (ep->queue.next,
  1800. struct net2280_request, queue);
  1801. /* here either (M < N), a "real" short rx;
  1802. * or (M == N) and the queue didn't empty
  1803. */
  1804. if (likely (t & (1 << FIFO_EMPTY))) {
  1805. count = readl (&ep->dma->dmacount);
  1806. count &= DMA_BYTE_COUNT_MASK;
  1807. if (readl (&ep->dma->dmadesc)
  1808. != req->td_dma)
  1809. req = NULL;
  1810. break;
  1811. }
  1812. udelay(1);
  1813. }
  1814. /* stop DMA, leave ep NAKing */
  1815. writel ((1 << DMA_ABORT), &ep->dma->dmastat);
  1816. spin_stop_dma (ep->dma);
  1817. if (likely (req)) {
  1818. req->td->dmacount = 0;
  1819. t = readl (&ep->regs->ep_avail);
  1820. dma_done (ep, req, count,
  1821. (ep->out_overflow || t)
  1822. ? -EOVERFLOW : 0);
  1823. }
  1824. /* also flush to prevent erratum 0106 trouble */
  1825. if (unlikely (ep->out_overflow
  1826. || (ep->dev->chiprev == 0x0100
  1827. && ep->dev->gadget.speed
  1828. == USB_SPEED_FULL))) {
  1829. out_flush (ep);
  1830. ep->out_overflow = 0;
  1831. }
  1832. /* (re)start dma if needed, stop NAKing */
  1833. ep->stopped = stopped;
  1834. if (!list_empty (&ep->queue))
  1835. restart_dma (ep);
  1836. } else
  1837. DEBUG (ep->dev, "%s dma ep_stat %08x ??\n",
  1838. ep->ep.name, t);
  1839. return;
  1840. /* data packet(s) received (in the fifo, OUT) */
  1841. } else if (t & (1 << DATA_PACKET_RECEIVED_INTERRUPT)) {
  1842. if (read_fifo (ep, req) && ep->num != 0)
  1843. mode = 2;
  1844. /* data packet(s) transmitted (IN) */
  1845. } else if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)) {
  1846. unsigned len;
  1847. len = req->req.length - req->req.actual;
  1848. if (len > ep->ep.maxpacket)
  1849. len = ep->ep.maxpacket;
  1850. req->req.actual += len;
  1851. /* if we wrote it all, we're usually done */
  1852. if (req->req.actual == req->req.length) {
  1853. if (ep->num == 0) {
  1854. /* send zlps until the status stage */
  1855. } else if (!req->req.zero || len != ep->ep.maxpacket)
  1856. mode = 2;
  1857. }
  1858. /* there was nothing to do ... */
  1859. } else if (mode == 1)
  1860. return;
  1861. /* done */
  1862. if (mode == 2) {
  1863. /* stream endpoints often resubmit/unlink in completion */
  1864. done (ep, req, 0);
  1865. /* maybe advance queue to next request */
  1866. if (ep->num == 0) {
  1867. /* NOTE: net2280 could let gadget driver start the
  1868. * status stage later. since not all controllers let
  1869. * them control that, the api doesn't (yet) allow it.
  1870. */
  1871. if (!ep->stopped)
  1872. allow_status (ep);
  1873. req = NULL;
  1874. } else {
  1875. if (!list_empty (&ep->queue) && !ep->stopped)
  1876. req = list_entry (ep->queue.next,
  1877. struct net2280_request, queue);
  1878. else
  1879. req = NULL;
  1880. if (req && !ep->is_in)
  1881. stop_out_naking (ep);
  1882. }
  1883. }
  1884. /* is there a buffer for the next packet?
  1885. * for best streaming performance, make sure there is one.
  1886. */
  1887. if (req && !ep->stopped) {
  1888. /* load IN fifo with next packet (may be zlp) */
  1889. if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT))
  1890. write_fifo (ep, &req->req);
  1891. }
  1892. }
  1893. static struct net2280_ep *
  1894. get_ep_by_addr (struct net2280 *dev, u16 wIndex)
  1895. {
  1896. struct net2280_ep *ep;
  1897. if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
  1898. return &dev->ep [0];
  1899. list_for_each_entry (ep, &dev->gadget.ep_list, ep.ep_list) {
  1900. u8 bEndpointAddress;
  1901. if (!ep->desc)
  1902. continue;
  1903. bEndpointAddress = ep->desc->bEndpointAddress;
  1904. if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
  1905. continue;
  1906. if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
  1907. return ep;
  1908. }
  1909. return NULL;
  1910. }
  1911. static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
  1912. {
  1913. struct net2280_ep *ep;
  1914. u32 num, scratch;
  1915. /* most of these don't need individual acks */
  1916. stat &= ~(1 << INTA_ASSERTED);
  1917. if (!stat)
  1918. return;
  1919. // DEBUG (dev, "irqstat0 %04x\n", stat);
  1920. /* starting a control request? */
  1921. if (unlikely (stat & (1 << SETUP_PACKET_INTERRUPT))) {
  1922. union {
  1923. u32 raw [2];
  1924. struct usb_ctrlrequest r;
  1925. } u;
  1926. int tmp;
  1927. struct net2280_request *req;
  1928. if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
  1929. if (readl (&dev->usb->usbstat) & (1 << HIGH_SPEED))
  1930. dev->gadget.speed = USB_SPEED_HIGH;
  1931. else
  1932. dev->gadget.speed = USB_SPEED_FULL;
  1933. net2280_led_speed (dev, dev->gadget.speed);
  1934. DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed));
  1935. }
  1936. ep = &dev->ep [0];
  1937. ep->irqs++;
  1938. /* make sure any leftover request state is cleared */
  1939. stat &= ~(1 << ENDPOINT_0_INTERRUPT);
  1940. while (!list_empty (&ep->queue)) {
  1941. req = list_entry (ep->queue.next,
  1942. struct net2280_request, queue);
  1943. done (ep, req, (req->req.actual == req->req.length)
  1944. ? 0 : -EPROTO);
  1945. }
  1946. ep->stopped = 0;
  1947. dev->protocol_stall = 0;
  1948. if (ep->dev->pdev->device == 0x2280)
  1949. tmp = (1 << FIFO_OVERFLOW)
  1950. | (1 << FIFO_UNDERFLOW);
  1951. else
  1952. tmp = 0;
  1953. writel (tmp | (1 << TIMEOUT)
  1954. | (1 << USB_STALL_SENT)
  1955. | (1 << USB_IN_NAK_SENT)
  1956. | (1 << USB_IN_ACK_RCVD)
  1957. | (1 << USB_OUT_PING_NAK_SENT)
  1958. | (1 << USB_OUT_ACK_SENT)
  1959. | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
  1960. | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
  1961. | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
  1962. | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
  1963. | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  1964. | (1 << DATA_IN_TOKEN_INTERRUPT)
  1965. , &ep->regs->ep_stat);
  1966. u.raw [0] = readl (&dev->usb->setup0123);
  1967. u.raw [1] = readl (&dev->usb->setup4567);
  1968. cpu_to_le32s (&u.raw [0]);
  1969. cpu_to_le32s (&u.raw [1]);
  1970. tmp = 0;
  1971. #define w_value le16_to_cpu(u.r.wValue)
  1972. #define w_index le16_to_cpu(u.r.wIndex)
  1973. #define w_length le16_to_cpu(u.r.wLength)
  1974. /* ack the irq */
  1975. writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0);
  1976. stat ^= (1 << SETUP_PACKET_INTERRUPT);
  1977. /* watch control traffic at the token level, and force
  1978. * synchronization before letting the status stage happen.
  1979. * FIXME ignore tokens we'll NAK, until driver responds.
  1980. * that'll mean a lot less irqs for some drivers.
  1981. */
  1982. ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
  1983. if (ep->is_in) {
  1984. scratch = (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
  1985. | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  1986. | (1 << DATA_IN_TOKEN_INTERRUPT);
  1987. stop_out_naking (ep);
  1988. } else
  1989. scratch = (1 << DATA_PACKET_RECEIVED_INTERRUPT)
  1990. | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
  1991. | (1 << DATA_IN_TOKEN_INTERRUPT);
  1992. writel (scratch, &dev->epregs [0].ep_irqenb);
  1993. /* we made the hardware handle most lowlevel requests;
  1994. * everything else goes uplevel to the gadget code.
  1995. */
  1996. ep->responded = 1;
  1997. switch (u.r.bRequest) {
  1998. case USB_REQ_GET_STATUS: {
  1999. struct net2280_ep *e;
  2000. __le32 status;
  2001. /* hw handles device and interface status */
  2002. if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
  2003. goto delegate;
  2004. if ((e = get_ep_by_addr (dev, w_index)) == 0
  2005. || w_length > 2)
  2006. goto do_stall;
  2007. if (readl (&e->regs->ep_rsp)
  2008. & (1 << SET_ENDPOINT_HALT))
  2009. status = cpu_to_le32 (1);
  2010. else
  2011. status = cpu_to_le32 (0);
  2012. /* don't bother with a request object! */
  2013. writel (0, &dev->epregs [0].ep_irqenb);
  2014. set_fifo_bytecount (ep, w_length);
  2015. writel ((__force u32)status, &dev->epregs [0].ep_data);
  2016. allow_status (ep);
  2017. VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
  2018. goto next_endpoints;
  2019. }
  2020. break;
  2021. case USB_REQ_CLEAR_FEATURE: {
  2022. struct net2280_ep *e;
  2023. /* hw handles device features */
  2024. if (u.r.bRequestType != USB_RECIP_ENDPOINT)
  2025. goto delegate;
  2026. if (w_value != USB_ENDPOINT_HALT
  2027. || w_length != 0)
  2028. goto do_stall;
  2029. if ((e = get_ep_by_addr (dev, w_index)) == 0)
  2030. goto do_stall;
  2031. if (e->wedged) {
  2032. VDEBUG(dev, "%s wedged, halt not cleared\n",
  2033. ep->ep.name);
  2034. } else {
  2035. VDEBUG(dev, "%s clear halt\n", ep->ep.name);
  2036. clear_halt(e);
  2037. }
  2038. allow_status (ep);
  2039. goto next_endpoints;
  2040. }
  2041. break;
  2042. case USB_REQ_SET_FEATURE: {
  2043. struct net2280_ep *e;
  2044. /* hw handles device features */
  2045. if (u.r.bRequestType != USB_RECIP_ENDPOINT)
  2046. goto delegate;
  2047. if (w_value != USB_ENDPOINT_HALT
  2048. || w_length != 0)
  2049. goto do_stall;
  2050. if ((e = get_ep_by_addr (dev, w_index)) == 0)
  2051. goto do_stall;
  2052. if (e->ep.name == ep0name)
  2053. goto do_stall;
  2054. set_halt (e);
  2055. allow_status (ep);
  2056. VDEBUG (dev, "%s set halt\n", ep->ep.name);
  2057. goto next_endpoints;
  2058. }
  2059. break;
  2060. default:
  2061. delegate:
  2062. VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x "
  2063. "ep_cfg %08x\n",
  2064. u.r.bRequestType, u.r.bRequest,
  2065. w_value, w_index, w_length,
  2066. readl (&ep->regs->ep_cfg));
  2067. ep->responded = 0;
  2068. spin_unlock (&dev->lock);
  2069. tmp = dev->driver->setup (&dev->gadget, &u.r);
  2070. spin_lock (&dev->lock);
  2071. }
  2072. /* stall ep0 on error */
  2073. if (tmp < 0) {
  2074. do_stall:
  2075. VDEBUG (dev, "req %02x.%02x protocol STALL; stat %d\n",
  2076. u.r.bRequestType, u.r.bRequest, tmp);
  2077. dev->protocol_stall = 1;
  2078. }
  2079. /* some in/out token irq should follow; maybe stall then.
  2080. * driver must queue a request (even zlp) or halt ep0
  2081. * before the host times out.
  2082. */
  2083. }
  2084. #undef w_value
  2085. #undef w_index
  2086. #undef w_length
  2087. next_endpoints:
  2088. /* endpoint data irq ? */
  2089. scratch = stat & 0x7f;
  2090. stat &= ~0x7f;
  2091. for (num = 0; scratch; num++) {
  2092. u32 t;
  2093. /* do this endpoint's FIFO and queue need tending? */
  2094. t = 1 << num;
  2095. if ((scratch & t) == 0)
  2096. continue;
  2097. scratch ^= t;
  2098. ep = &dev->ep [num];
  2099. handle_ep_small (ep);
  2100. }
  2101. if (stat)
  2102. DEBUG (dev, "unhandled irqstat0 %08x\n", stat);
  2103. }
  2104. #define DMA_INTERRUPTS ( \
  2105. (1 << DMA_D_INTERRUPT) \
  2106. | (1 << DMA_C_INTERRUPT) \
  2107. | (1 << DMA_B_INTERRUPT) \
  2108. | (1 << DMA_A_INTERRUPT))
  2109. #define PCI_ERROR_INTERRUPTS ( \
  2110. (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \
  2111. | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \
  2112. | (1 << PCI_RETRY_ABORT_INTERRUPT))
  2113. static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
  2114. {
  2115. struct net2280_ep *ep;
  2116. u32 tmp, num, mask, scratch;
  2117. /* after disconnect there's nothing else to do! */
  2118. tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT);
  2119. mask = (1 << HIGH_SPEED) | (1 << FULL_SPEED);
  2120. /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
  2121. * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and
  2122. * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
  2123. * only indicates a change in the reset state).
  2124. */
  2125. if (stat & tmp) {
  2126. writel (tmp, &dev->regs->irqstat1);
  2127. if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT))
  2128. && ((readl (&dev->usb->usbstat) & mask)
  2129. == 0))
  2130. || ((readl (&dev->usb->usbctl)
  2131. & (1 << VBUS_PIN)) == 0)
  2132. ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) {
  2133. DEBUG (dev, "disconnect %s\n",
  2134. dev->driver->driver.name);
  2135. stop_activity (dev, dev->driver);
  2136. ep0_start (dev);
  2137. return;
  2138. }
  2139. stat &= ~tmp;
  2140. /* vBUS can bounce ... one of many reasons to ignore the
  2141. * notion of hotplug events on bus connect/disconnect!
  2142. */
  2143. if (!stat)
  2144. return;
  2145. }
  2146. /* NOTE: chip stays in PCI D0 state for now, but it could
  2147. * enter D1 to save more power
  2148. */
  2149. tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT);
  2150. if (stat & tmp) {
  2151. writel (tmp, &dev->regs->irqstat1);
  2152. if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) {
  2153. if (dev->driver->suspend)
  2154. dev->driver->suspend (&dev->gadget);
  2155. if (!enable_suspend)
  2156. stat &= ~(1 << SUSPEND_REQUEST_INTERRUPT);
  2157. } else {
  2158. if (dev->driver->resume)
  2159. dev->driver->resume (&dev->gadget);
  2160. /* at high speed, note erratum 0133 */
  2161. }
  2162. stat &= ~tmp;
  2163. }
  2164. /* clear any other status/irqs */
  2165. if (stat)
  2166. writel (stat, &dev->regs->irqstat1);
  2167. /* some status we can just ignore */
  2168. if (dev->pdev->device == 0x2280)
  2169. stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
  2170. | (1 << SUSPEND_REQUEST_INTERRUPT)
  2171. | (1 << RESUME_INTERRUPT)
  2172. | (1 << SOF_INTERRUPT));
  2173. else
  2174. stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
  2175. | (1 << RESUME_INTERRUPT)
  2176. | (1 << SOF_DOWN_INTERRUPT)
  2177. | (1 << SOF_INTERRUPT));
  2178. if (!stat)
  2179. return;
  2180. // DEBUG (dev, "irqstat1 %08x\n", stat);
  2181. /* DMA status, for ep-{a,b,c,d} */
  2182. scratch = stat & DMA_INTERRUPTS;
  2183. stat &= ~DMA_INTERRUPTS;
  2184. scratch >>= 9;
  2185. for (num = 0; scratch; num++) {
  2186. struct net2280_dma_regs __iomem *dma;
  2187. tmp = 1 << num;
  2188. if ((tmp & scratch) == 0)
  2189. continue;
  2190. scratch ^= tmp;
  2191. ep = &dev->ep [num + 1];
  2192. dma = ep->dma;
  2193. if (!dma)
  2194. continue;
  2195. /* clear ep's dma status */
  2196. tmp = readl (&dma->dmastat);
  2197. writel (tmp, &dma->dmastat);
  2198. /* chaining should stop on abort, short OUT from fifo,
  2199. * or (stat0 codepath) short OUT transfer.
  2200. */
  2201. if (!use_dma_chaining) {
  2202. if ((tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT))
  2203. == 0) {
  2204. DEBUG (ep->dev, "%s no xact done? %08x\n",
  2205. ep->ep.name, tmp);
  2206. continue;
  2207. }
  2208. stop_dma (ep->dma);
  2209. }
  2210. /* OUT transfers terminate when the data from the
  2211. * host is in our memory. Process whatever's done.
  2212. * On this path, we know transfer's last packet wasn't
  2213. * less than req->length. NAK_OUT_PACKETS may be set,
  2214. * or the FIFO may already be holding new packets.
  2215. *
  2216. * IN transfers can linger in the FIFO for a very
  2217. * long time ... we ignore that for now, accounting
  2218. * precisely (like PIO does) needs per-packet irqs
  2219. */
  2220. scan_dma_completions (ep);
  2221. /* disable dma on inactive queues; else maybe restart */
  2222. if (list_empty (&ep->queue)) {
  2223. if (use_dma_chaining)
  2224. stop_dma (ep->dma);
  2225. } else {
  2226. tmp = readl (&dma->dmactl);
  2227. if (!use_dma_chaining
  2228. || (tmp & (1 << DMA_ENABLE)) == 0)
  2229. restart_dma (ep);
  2230. else if (ep->is_in && use_dma_chaining) {
  2231. struct net2280_request *req;
  2232. __le32 dmacount;
  2233. /* the descriptor at the head of the chain
  2234. * may still have VALID_BIT clear; that's
  2235. * used to trigger changing DMA_FIFO_VALIDATE
  2236. * (affects automagic zlp writes).
  2237. */
  2238. req = list_entry (ep->queue.next,
  2239. struct net2280_request, queue);
  2240. dmacount = req->td->dmacount;
  2241. dmacount &= cpu_to_le32 (
  2242. (1 << VALID_BIT)
  2243. | DMA_BYTE_COUNT_MASK);
  2244. if (dmacount && (dmacount & valid_bit) == 0)
  2245. restart_dma (ep);
  2246. }
  2247. }
  2248. ep->irqs++;
  2249. }
  2250. /* NOTE: there are other PCI errors we might usefully notice.
  2251. * if they appear very often, here's where to try recovering.
  2252. */
  2253. if (stat & PCI_ERROR_INTERRUPTS) {
  2254. ERROR (dev, "pci dma error; stat %08x\n", stat);
  2255. stat &= ~PCI_ERROR_INTERRUPTS;
  2256. /* these are fatal errors, but "maybe" they won't
  2257. * happen again ...
  2258. */
  2259. stop_activity (dev, dev->driver);
  2260. ep0_start (dev);
  2261. stat = 0;
  2262. }
  2263. if (stat)
  2264. DEBUG (dev, "unhandled irqstat1 %08x\n", stat);
  2265. }
  2266. static irqreturn_t net2280_irq (int irq, void *_dev)
  2267. {
  2268. struct net2280 *dev = _dev;
  2269. /* shared interrupt, not ours */
  2270. if (!(readl(&dev->regs->irqstat0) & (1 << INTA_ASSERTED)))
  2271. return IRQ_NONE;
  2272. spin_lock (&dev->lock);
  2273. /* handle disconnect, dma, and more */
  2274. handle_stat1_irqs (dev, readl (&dev->regs->irqstat1));
  2275. /* control requests and PIO */
  2276. handle_stat0_irqs (dev, readl (&dev->regs->irqstat0));
  2277. spin_unlock (&dev->lock);
  2278. return IRQ_HANDLED;
  2279. }
  2280. /*-------------------------------------------------------------------------*/
  2281. static void gadget_release (struct device *_dev)
  2282. {
  2283. struct net2280 *dev = dev_get_drvdata (_dev);
  2284. kfree (dev);
  2285. }
  2286. /* tear down the binding between this driver and the pci device */
  2287. static void net2280_remove (struct pci_dev *pdev)
  2288. {
  2289. struct net2280 *dev = pci_get_drvdata (pdev);
  2290. usb_del_gadget_udc(&dev->gadget);
  2291. BUG_ON(dev->driver);
  2292. /* then clean up the resources we allocated during probe() */
  2293. net2280_led_shutdown (dev);
  2294. if (dev->requests) {
  2295. int i;
  2296. for (i = 1; i < 5; i++) {
  2297. if (!dev->ep [i].dummy)
  2298. continue;
  2299. pci_pool_free (dev->requests, dev->ep [i].dummy,
  2300. dev->ep [i].td_dma);
  2301. }
  2302. pci_pool_destroy (dev->requests);
  2303. }
  2304. if (dev->got_irq)
  2305. free_irq (pdev->irq, dev);
  2306. if (dev->regs)
  2307. iounmap (dev->regs);
  2308. if (dev->region)
  2309. release_mem_region (pci_resource_start (pdev, 0),
  2310. pci_resource_len (pdev, 0));
  2311. if (dev->enabled)
  2312. pci_disable_device (pdev);
  2313. device_unregister (&dev->gadget.dev);
  2314. device_remove_file (&pdev->dev, &dev_attr_registers);
  2315. pci_set_drvdata (pdev, NULL);
  2316. INFO (dev, "unbind\n");
  2317. the_controller = NULL;
  2318. }
  2319. /* wrap this driver around the specified device, but
  2320. * don't respond over USB until a gadget driver binds to us.
  2321. */
  2322. static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
  2323. {
  2324. struct net2280 *dev;
  2325. unsigned long resource, len;
  2326. void __iomem *base = NULL;
  2327. int retval, i;
  2328. /* if you want to support more than one controller in a system,
  2329. * usb_gadget_driver_{register,unregister}() must change.
  2330. */
  2331. if (the_controller) {
  2332. dev_warn (&pdev->dev, "ignoring\n");
  2333. return -EBUSY;
  2334. }
  2335. /* alloc, and start init */
  2336. dev = kzalloc (sizeof *dev, GFP_KERNEL);
  2337. if (dev == NULL){
  2338. retval = -ENOMEM;
  2339. goto done;
  2340. }
  2341. pci_set_drvdata (pdev, dev);
  2342. spin_lock_init (&dev->lock);
  2343. dev->pdev = pdev;
  2344. dev->gadget.ops = &net2280_ops;
  2345. dev->gadget.is_dualspeed = 1;
  2346. /* the "gadget" abstracts/virtualizes the controller */
  2347. dev_set_name(&dev->gadget.dev, "gadget");
  2348. dev->gadget.dev.parent = &pdev->dev;
  2349. dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
  2350. dev->gadget.dev.release = gadget_release;
  2351. dev->gadget.name = driver_name;
  2352. /* now all the pci goodies ... */
  2353. if (pci_enable_device (pdev) < 0) {
  2354. retval = -ENODEV;
  2355. goto done;
  2356. }
  2357. dev->enabled = 1;
  2358. /* BAR 0 holds all the registers
  2359. * BAR 1 is 8051 memory; unused here (note erratum 0103)
  2360. * BAR 2 is fifo memory; unused here
  2361. */
  2362. resource = pci_resource_start (pdev, 0);
  2363. len = pci_resource_len (pdev, 0);
  2364. if (!request_mem_region (resource, len, driver_name)) {
  2365. DEBUG (dev, "controller already in use\n");
  2366. retval = -EBUSY;
  2367. goto done;
  2368. }
  2369. dev->region = 1;
  2370. /* FIXME provide firmware download interface to put
  2371. * 8051 code into the chip, e.g. to turn on PCI PM.
  2372. */
  2373. base = ioremap_nocache (resource, len);
  2374. if (base == NULL) {
  2375. DEBUG (dev, "can't map memory\n");
  2376. retval = -EFAULT;
  2377. goto done;
  2378. }
  2379. dev->regs = (struct net2280_regs __iomem *) base;
  2380. dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080);
  2381. dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100);
  2382. dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180);
  2383. dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
  2384. dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
  2385. /* put into initial config, link up all endpoints */
  2386. writel (0, &dev->usb->usbctl);
  2387. usb_reset (dev);
  2388. usb_reinit (dev);
  2389. /* irq setup after old hardware is cleaned up */
  2390. if (!pdev->irq) {
  2391. ERROR (dev, "No IRQ. Check PCI setup!\n");
  2392. retval = -ENODEV;
  2393. goto done;
  2394. }
  2395. if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev)
  2396. != 0) {
  2397. ERROR (dev, "request interrupt %d failed\n", pdev->irq);
  2398. retval = -EBUSY;
  2399. goto done;
  2400. }
  2401. dev->got_irq = 1;
  2402. /* DMA setup */
  2403. /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
  2404. dev->requests = pci_pool_create ("requests", pdev,
  2405. sizeof (struct net2280_dma),
  2406. 0 /* no alignment requirements */,
  2407. 0 /* or page-crossing issues */);
  2408. if (!dev->requests) {
  2409. DEBUG (dev, "can't get request pool\n");
  2410. retval = -ENOMEM;
  2411. goto done;
  2412. }
  2413. for (i = 1; i < 5; i++) {
  2414. struct net2280_dma *td;
  2415. td = pci_pool_alloc (dev->requests, GFP_KERNEL,
  2416. &dev->ep [i].td_dma);
  2417. if (!td) {
  2418. DEBUG (dev, "can't get dummy %d\n", i);
  2419. retval = -ENOMEM;
  2420. goto done;
  2421. }
  2422. td->dmacount = 0; /* not VALID */
  2423. td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
  2424. td->dmadesc = td->dmaaddr;
  2425. dev->ep [i].dummy = td;
  2426. }
  2427. /* enable lower-overhead pci memory bursts during DMA */
  2428. writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE)
  2429. // 256 write retries may not be enough...
  2430. // | (1 << PCI_RETRY_ABORT_ENABLE)
  2431. | (1 << DMA_READ_MULTIPLE_ENABLE)
  2432. | (1 << DMA_READ_LINE_ENABLE)
  2433. , &dev->pci->pcimstctl);
  2434. /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
  2435. pci_set_master (pdev);
  2436. pci_try_set_mwi (pdev);
  2437. /* ... also flushes any posted pci writes */
  2438. dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff;
  2439. /* done */
  2440. INFO (dev, "%s\n", driver_desc);
  2441. INFO (dev, "irq %d, pci mem %p, chip rev %04x\n",
  2442. pdev->irq, base, dev->chiprev);
  2443. INFO (dev, "version: " DRIVER_VERSION "; dma %s\n",
  2444. use_dma
  2445. ? (use_dma_chaining ? "chaining" : "enabled")
  2446. : "disabled");
  2447. the_controller = dev;
  2448. retval = device_register (&dev->gadget.dev);
  2449. if (retval) goto done;
  2450. retval = device_create_file (&pdev->dev, &dev_attr_registers);
  2451. if (retval) goto done;
  2452. retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
  2453. if (retval)
  2454. goto done;
  2455. return 0;
  2456. done:
  2457. if (dev)
  2458. net2280_remove (pdev);
  2459. return retval;
  2460. }
  2461. /* make sure the board is quiescent; otherwise it will continue
  2462. * generating IRQs across the upcoming reboot.
  2463. */
  2464. static void net2280_shutdown (struct pci_dev *pdev)
  2465. {
  2466. struct net2280 *dev = pci_get_drvdata (pdev);
  2467. /* disable IRQs */
  2468. writel (0, &dev->regs->pciirqenb0);
  2469. writel (0, &dev->regs->pciirqenb1);
  2470. /* disable the pullup so the host will think we're gone */
  2471. writel (0, &dev->usb->usbctl);
  2472. }
  2473. /*-------------------------------------------------------------------------*/
  2474. static const struct pci_device_id pci_ids [] = { {
  2475. .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
  2476. .class_mask = ~0,
  2477. .vendor = 0x17cc,
  2478. .device = 0x2280,
  2479. .subvendor = PCI_ANY_ID,
  2480. .subdevice = PCI_ANY_ID,
  2481. }, {
  2482. .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
  2483. .class_mask = ~0,
  2484. .vendor = 0x17cc,
  2485. .device = 0x2282,
  2486. .subvendor = PCI_ANY_ID,
  2487. .subdevice = PCI_ANY_ID,
  2488. }, { /* end: all zeroes */ }
  2489. };
  2490. MODULE_DEVICE_TABLE (pci, pci_ids);
  2491. /* pci driver glue; this is a "new style" PCI driver module */
  2492. static struct pci_driver net2280_pci_driver = {
  2493. .name = (char *) driver_name,
  2494. .id_table = pci_ids,
  2495. .probe = net2280_probe,
  2496. .remove = net2280_remove,
  2497. .shutdown = net2280_shutdown,
  2498. /* FIXME add power management support */
  2499. };
  2500. MODULE_DESCRIPTION (DRIVER_DESC);
  2501. MODULE_AUTHOR ("David Brownell");
  2502. MODULE_LICENSE ("GPL");
  2503. static int __init init (void)
  2504. {
  2505. if (!use_dma)
  2506. use_dma_chaining = 0;
  2507. return pci_register_driver (&net2280_pci_driver);
  2508. }
  2509. module_init (init);
  2510. static void __exit cleanup (void)
  2511. {
  2512. pci_unregister_driver (&net2280_pci_driver);
  2513. }
  2514. module_exit (cleanup);