net2280.c 77 KB

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