ambassador.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460
  1. /*
  2. Madge Ambassador ATM Adapter driver.
  3. Copyright (C) 1995-1999 Madge Networks Ltd.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
  16. system and in the file COPYING in the Linux kernel source.
  17. */
  18. /* * dedicated to the memory of Graham Gordon 1971-1998 * */
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/pci.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/ioport.h>
  25. #include <linux/atmdev.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/poison.h>
  29. #include <asm/atomic.h>
  30. #include <asm/io.h>
  31. #include <asm/byteorder.h>
  32. #include "ambassador.h"
  33. #define maintainer_string "Giuliano Procida at Madge Networks <gprocida@madge.com>"
  34. #define description_string "Madge ATM Ambassador driver"
  35. #define version_string "1.2.4"
  36. static inline void __init show_version (void) {
  37. printk ("%s version %s\n", description_string, version_string);
  38. }
  39. /*
  40. Theory of Operation
  41. I Hardware, detection, initialisation and shutdown.
  42. 1. Supported Hardware
  43. This driver is for the PCI ATMizer-based Ambassador card (except
  44. very early versions). It is not suitable for the similar EISA "TR7"
  45. card. Commercially, both cards are known as Collage Server ATM
  46. adapters.
  47. The loader supports image transfer to the card, image start and few
  48. other miscellaneous commands.
  49. Only AAL5 is supported with vpi = 0 and vci in the range 0 to 1023.
  50. The cards are big-endian.
  51. 2. Detection
  52. Standard PCI stuff, the early cards are detected and rejected.
  53. 3. Initialisation
  54. The cards are reset and the self-test results are checked. The
  55. microcode image is then transferred and started. This waits for a
  56. pointer to a descriptor containing details of the host-based queues
  57. and buffers and various parameters etc. Once they are processed
  58. normal operations may begin. The BIA is read using a microcode
  59. command.
  60. 4. Shutdown
  61. This may be accomplished either by a card reset or via the microcode
  62. shutdown command. Further investigation required.
  63. 5. Persistent state
  64. The card reset does not affect PCI configuration (good) or the
  65. contents of several other "shared run-time registers" (bad) which
  66. include doorbell and interrupt control as well as EEPROM and PCI
  67. control. The driver must be careful when modifying these registers
  68. not to touch bits it does not use and to undo any changes at exit.
  69. II Driver software
  70. 0. Generalities
  71. The adapter is quite intelligent (fast) and has a simple interface
  72. (few features). VPI is always zero, 1024 VCIs are supported. There
  73. is limited cell rate support. UBR channels can be capped and ABR
  74. (explicit rate, but not EFCI) is supported. There is no CBR or VBR
  75. support.
  76. 1. Driver <-> Adapter Communication
  77. Apart from the basic loader commands, the driver communicates
  78. through three entities: the command queue (CQ), the transmit queue
  79. pair (TXQ) and the receive queue pairs (RXQ). These three entities
  80. are set up by the host and passed to the microcode just after it has
  81. been started.
  82. All queues are host-based circular queues. They are contiguous and
  83. (due to hardware limitations) have some restrictions as to their
  84. locations in (bus) memory. They are of the "full means the same as
  85. empty so don't do that" variety since the adapter uses pointers
  86. internally.
  87. The queue pairs work as follows: one queue is for supply to the
  88. adapter, items in it are pending and are owned by the adapter; the
  89. other is the queue for return from the adapter, items in it have
  90. been dealt with by the adapter. The host adds items to the supply
  91. (TX descriptors and free RX buffer descriptors) and removes items
  92. from the return (TX and RX completions). The adapter deals with out
  93. of order completions.
  94. Interrupts (card to host) and the doorbell (host to card) are used
  95. for signalling.
  96. 1. CQ
  97. This is to communicate "open VC", "close VC", "get stats" etc. to
  98. the adapter. At most one command is retired every millisecond by the
  99. card. There is no out of order completion or notification. The
  100. driver needs to check the return code of the command, waiting as
  101. appropriate.
  102. 2. TXQ
  103. TX supply items are of variable length (scatter gather support) and
  104. so the queue items are (more or less) pointers to the real thing.
  105. Each TX supply item contains a unique, host-supplied handle (the skb
  106. bus address seems most sensible as this works for Alphas as well,
  107. there is no need to do any endian conversions on the handles).
  108. TX return items consist of just the handles above.
  109. 3. RXQ (up to 4 of these with different lengths and buffer sizes)
  110. RX supply items consist of a unique, host-supplied handle (the skb
  111. bus address again) and a pointer to the buffer data area.
  112. RX return items consist of the handle above, the VC, length and a
  113. status word. This just screams "oh so easy" doesn't it?
  114. Note on RX pool sizes:
  115. Each pool should have enough buffers to handle a back-to-back stream
  116. of minimum sized frames on a single VC. For example:
  117. frame spacing = 3us (about right)
  118. delay = IRQ lat + RX handling + RX buffer replenish = 20 (us) (a guess)
  119. min number of buffers for one VC = 1 + delay/spacing (buffers)
  120. delay/spacing = latency = (20+2)/3 = 7 (buffers) (rounding up)
  121. The 20us delay assumes that there is no need to sleep; if we need to
  122. sleep to get buffers we are going to drop frames anyway.
  123. In fact, each pool should have enough buffers to support the
  124. simultaneous reassembly of a separate frame on each VC and cope with
  125. the case in which frames complete in round robin cell fashion on
  126. each VC.
  127. Only one frame can complete at each cell arrival, so if "n" VCs are
  128. open, the worst case is to have them all complete frames together
  129. followed by all starting new frames together.
  130. desired number of buffers = n + delay/spacing
  131. These are the extreme requirements, however, they are "n+k" for some
  132. "k" so we have only the constant to choose. This is the argument
  133. rx_lats which current defaults to 7.
  134. Actually, "n ? n+k : 0" is better and this is what is implemented,
  135. subject to the limit given by the pool size.
  136. 4. Driver locking
  137. Simple spinlocks are used around the TX and RX queue mechanisms.
  138. Anyone with a faster, working method is welcome to implement it.
  139. The adapter command queue is protected with a spinlock. We always
  140. wait for commands to complete.
  141. A more complex form of locking is used around parts of the VC open
  142. and close functions. There are three reasons for a lock: 1. we need
  143. to do atomic rate reservation and release (not used yet), 2. Opening
  144. sometimes involves two adapter commands which must not be separated
  145. by another command on the same VC, 3. the changes to RX pool size
  146. must be atomic. The lock needs to work over context switches, so we
  147. use a semaphore.
  148. III Hardware Features and Microcode Bugs
  149. 1. Byte Ordering
  150. *%^"$&%^$*&^"$(%^$#&^%$(&#%$*(&^#%!"!"!*!
  151. 2. Memory access
  152. All structures that are not accessed using DMA must be 4-byte
  153. aligned (not a problem) and must not cross 4MB boundaries.
  154. There is a DMA memory hole at E0000000-E00000FF (groan).
  155. TX fragments (DMA read) must not cross 4MB boundaries (would be 16MB
  156. but for a hardware bug).
  157. RX buffers (DMA write) must not cross 16MB boundaries and must
  158. include spare trailing bytes up to the next 4-byte boundary; they
  159. will be written with rubbish.
  160. The PLX likes to prefetch; if reading up to 4 u32 past the end of
  161. each TX fragment is not a problem, then TX can be made to go a
  162. little faster by passing a flag at init that disables a prefetch
  163. workaround. We do not pass this flag. (new microcode only)
  164. Now we:
  165. . Note that alloc_skb rounds up size to a 16byte boundary.
  166. . Ensure all areas do not traverse 4MB boundaries.
  167. . Ensure all areas do not start at a E00000xx bus address.
  168. (I cannot be certain, but this may always hold with Linux)
  169. . Make all failures cause a loud message.
  170. . Discard non-conforming SKBs (causes TX failure or RX fill delay).
  171. . Discard non-conforming TX fragment descriptors (the TX fails).
  172. In the future we could:
  173. . Allow RX areas that traverse 4MB (but not 16MB) boundaries.
  174. . Segment TX areas into some/more fragments, when necessary.
  175. . Relax checks for non-DMA items (ignore hole).
  176. . Give scatter-gather (iovec) requirements using ???. (?)
  177. 3. VC close is broken (only for new microcode)
  178. The VC close adapter microcode command fails to do anything if any
  179. frames have been received on the VC but none have been transmitted.
  180. Frames continue to be reassembled and passed (with IRQ) to the
  181. driver.
  182. IV To Do List
  183. . Fix bugs!
  184. . Timer code may be broken.
  185. . Deal with buggy VC close (somehow) in microcode 12.
  186. . Handle interrupted and/or non-blocking writes - is this a job for
  187. the protocol layer?
  188. . Add code to break up TX fragments when they span 4MB boundaries.
  189. . Add SUNI phy layer (need to know where SUNI lives on card).
  190. . Implement a tx_alloc fn to (a) satisfy TX alignment etc. and (b)
  191. leave extra headroom space for Ambassador TX descriptors.
  192. . Understand these elements of struct atm_vcc: recvq (proto?),
  193. sleep, callback, listenq, backlog_quota, reply and user_back.
  194. . Adjust TX/RX skb allocation to favour IP with LANE/CLIP (configurable).
  195. . Impose a TX-pending limit (2?) on each VC, help avoid TX q overflow.
  196. . Decide whether RX buffer recycling is or can be made completely safe;
  197. turn it back on. It looks like Werner is going to axe this.
  198. . Implement QoS changes on open VCs (involves extracting parts of VC open
  199. and close into separate functions and using them to make changes).
  200. . Hack on command queue so that someone can issue multiple commands and wait
  201. on the last one (OR only "no-op" or "wait" commands are waited for).
  202. . Eliminate need for while-schedule around do_command.
  203. */
  204. /********** microcode **********/
  205. #ifdef AMB_NEW_MICROCODE
  206. #define UCODE(x) UCODE2(atmsar12.x)
  207. #else
  208. #define UCODE(x) UCODE2(atmsar11.x)
  209. #endif
  210. #define UCODE2(x) #x
  211. static u32 __devinitdata ucode_start =
  212. #include UCODE(start)
  213. ;
  214. static region __devinitdata ucode_regions[] = {
  215. #include UCODE(regions)
  216. { 0, 0 }
  217. };
  218. static u32 __devinitdata ucode_data[] = {
  219. #include UCODE(data)
  220. 0xdeadbeef
  221. };
  222. static void do_housekeeping (unsigned long arg);
  223. /********** globals **********/
  224. static unsigned short debug = 0;
  225. static unsigned int cmds = 8;
  226. static unsigned int txs = 32;
  227. static unsigned int rxs[NUM_RX_POOLS] = { 64, 64, 64, 64 };
  228. static unsigned int rxs_bs[NUM_RX_POOLS] = { 4080, 12240, 36720, 65535 };
  229. static unsigned int rx_lats = 7;
  230. static unsigned char pci_lat = 0;
  231. static const unsigned long onegigmask = -1 << 30;
  232. /********** access to adapter **********/
  233. static inline void wr_plain (const amb_dev * dev, size_t addr, u32 data) {
  234. PRINTD (DBG_FLOW|DBG_REGS, "wr: %08zx <- %08x", addr, data);
  235. #ifdef AMB_MMIO
  236. dev->membase[addr / sizeof(u32)] = data;
  237. #else
  238. outl (data, dev->iobase + addr);
  239. #endif
  240. }
  241. static inline u32 rd_plain (const amb_dev * dev, size_t addr) {
  242. #ifdef AMB_MMIO
  243. u32 data = dev->membase[addr / sizeof(u32)];
  244. #else
  245. u32 data = inl (dev->iobase + addr);
  246. #endif
  247. PRINTD (DBG_FLOW|DBG_REGS, "rd: %08zx -> %08x", addr, data);
  248. return data;
  249. }
  250. static inline void wr_mem (const amb_dev * dev, size_t addr, u32 data) {
  251. __be32 be = cpu_to_be32 (data);
  252. PRINTD (DBG_FLOW|DBG_REGS, "wr: %08zx <- %08x b[%08x]", addr, data, be);
  253. #ifdef AMB_MMIO
  254. dev->membase[addr / sizeof(u32)] = be;
  255. #else
  256. outl (be, dev->iobase + addr);
  257. #endif
  258. }
  259. static inline u32 rd_mem (const amb_dev * dev, size_t addr) {
  260. #ifdef AMB_MMIO
  261. __be32 be = dev->membase[addr / sizeof(u32)];
  262. #else
  263. __be32 be = inl (dev->iobase + addr);
  264. #endif
  265. u32 data = be32_to_cpu (be);
  266. PRINTD (DBG_FLOW|DBG_REGS, "rd: %08zx -> %08x b[%08x]", addr, data, be);
  267. return data;
  268. }
  269. /********** dump routines **********/
  270. static inline void dump_registers (const amb_dev * dev) {
  271. #ifdef DEBUG_AMBASSADOR
  272. if (debug & DBG_REGS) {
  273. size_t i;
  274. PRINTD (DBG_REGS, "reading PLX control: ");
  275. for (i = 0x00; i < 0x30; i += sizeof(u32))
  276. rd_mem (dev, i);
  277. PRINTD (DBG_REGS, "reading mailboxes: ");
  278. for (i = 0x40; i < 0x60; i += sizeof(u32))
  279. rd_mem (dev, i);
  280. PRINTD (DBG_REGS, "reading doorb irqev irqen reset:");
  281. for (i = 0x60; i < 0x70; i += sizeof(u32))
  282. rd_mem (dev, i);
  283. }
  284. #else
  285. (void) dev;
  286. #endif
  287. return;
  288. }
  289. static inline void dump_loader_block (volatile loader_block * lb) {
  290. #ifdef DEBUG_AMBASSADOR
  291. unsigned int i;
  292. PRINTDB (DBG_LOAD, "lb @ %p; res: %d, cmd: %d, pay:",
  293. lb, be32_to_cpu (lb->result), be32_to_cpu (lb->command));
  294. for (i = 0; i < MAX_COMMAND_DATA; ++i)
  295. PRINTDM (DBG_LOAD, " %08x", be32_to_cpu (lb->payload.data[i]));
  296. PRINTDE (DBG_LOAD, ", vld: %08x", be32_to_cpu (lb->valid));
  297. #else
  298. (void) lb;
  299. #endif
  300. return;
  301. }
  302. static inline void dump_command (command * cmd) {
  303. #ifdef DEBUG_AMBASSADOR
  304. unsigned int i;
  305. PRINTDB (DBG_CMD, "cmd @ %p, req: %08x, pars:",
  306. cmd, /*be32_to_cpu*/ (cmd->request));
  307. for (i = 0; i < 3; ++i)
  308. PRINTDM (DBG_CMD, " %08x", /*be32_to_cpu*/ (cmd->args.par[i]));
  309. PRINTDE (DBG_CMD, "");
  310. #else
  311. (void) cmd;
  312. #endif
  313. return;
  314. }
  315. static inline void dump_skb (char * prefix, unsigned int vc, struct sk_buff * skb) {
  316. #ifdef DEBUG_AMBASSADOR
  317. unsigned int i;
  318. unsigned char * data = skb->data;
  319. PRINTDB (DBG_DATA, "%s(%u) ", prefix, vc);
  320. for (i=0; i<skb->len && i < 256;i++)
  321. PRINTDM (DBG_DATA, "%02x ", data[i]);
  322. PRINTDE (DBG_DATA,"");
  323. #else
  324. (void) prefix;
  325. (void) vc;
  326. (void) skb;
  327. #endif
  328. return;
  329. }
  330. /********** check memory areas for use by Ambassador **********/
  331. /* see limitations under Hardware Features */
  332. static inline int check_area (void * start, size_t length) {
  333. // assumes length > 0
  334. const u32 fourmegmask = -1 << 22;
  335. const u32 twofivesixmask = -1 << 8;
  336. const u32 starthole = 0xE0000000;
  337. u32 startaddress = virt_to_bus (start);
  338. u32 lastaddress = startaddress+length-1;
  339. if ((startaddress ^ lastaddress) & fourmegmask ||
  340. (startaddress & twofivesixmask) == starthole) {
  341. PRINTK (KERN_ERR, "check_area failure: [%x,%x] - mail maintainer!",
  342. startaddress, lastaddress);
  343. return -1;
  344. } else {
  345. return 0;
  346. }
  347. }
  348. /********** free an skb (as per ATM device driver documentation) **********/
  349. static inline void amb_kfree_skb (struct sk_buff * skb) {
  350. if (ATM_SKB(skb)->vcc->pop) {
  351. ATM_SKB(skb)->vcc->pop (ATM_SKB(skb)->vcc, skb);
  352. } else {
  353. dev_kfree_skb_any (skb);
  354. }
  355. }
  356. /********** TX completion **********/
  357. static inline void tx_complete (amb_dev * dev, tx_out * tx) {
  358. tx_simple * tx_descr = bus_to_virt (tx->handle);
  359. struct sk_buff * skb = tx_descr->skb;
  360. PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
  361. // VC layer stats
  362. atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
  363. // free the descriptor
  364. kfree (tx_descr);
  365. // free the skb
  366. amb_kfree_skb (skb);
  367. dev->stats.tx_ok++;
  368. return;
  369. }
  370. /********** RX completion **********/
  371. static void rx_complete (amb_dev * dev, rx_out * rx) {
  372. struct sk_buff * skb = bus_to_virt (rx->handle);
  373. u16 vc = be16_to_cpu (rx->vc);
  374. // unused: u16 lec_id = be16_to_cpu (rx->lec_id);
  375. u16 status = be16_to_cpu (rx->status);
  376. u16 rx_len = be16_to_cpu (rx->length);
  377. PRINTD (DBG_FLOW|DBG_RX, "rx_complete %p %p (len=%hu)", dev, rx, rx_len);
  378. // XXX move this in and add to VC stats ???
  379. if (!status) {
  380. struct atm_vcc * atm_vcc = dev->rxer[vc];
  381. dev->stats.rx.ok++;
  382. if (atm_vcc) {
  383. if (rx_len <= atm_vcc->qos.rxtp.max_sdu) {
  384. if (atm_charge (atm_vcc, skb->truesize)) {
  385. // prepare socket buffer
  386. ATM_SKB(skb)->vcc = atm_vcc;
  387. skb_put (skb, rx_len);
  388. dump_skb ("<<<", vc, skb);
  389. // VC layer stats
  390. atomic_inc(&atm_vcc->stats->rx);
  391. __net_timestamp(skb);
  392. // end of our responsability
  393. atm_vcc->push (atm_vcc, skb);
  394. return;
  395. } else {
  396. // someone fix this (message), please!
  397. PRINTD (DBG_INFO|DBG_RX, "dropped thanks to atm_charge (vc %hu, truesize %u)", vc, skb->truesize);
  398. // drop stats incremented in atm_charge
  399. }
  400. } else {
  401. PRINTK (KERN_INFO, "dropped over-size frame");
  402. // should we count this?
  403. atomic_inc(&atm_vcc->stats->rx_drop);
  404. }
  405. } else {
  406. PRINTD (DBG_WARN|DBG_RX, "got frame but RX closed for channel %hu", vc);
  407. // this is an adapter bug, only in new version of microcode
  408. }
  409. } else {
  410. dev->stats.rx.error++;
  411. if (status & CRC_ERR)
  412. dev->stats.rx.badcrc++;
  413. if (status & LEN_ERR)
  414. dev->stats.rx.toolong++;
  415. if (status & ABORT_ERR)
  416. dev->stats.rx.aborted++;
  417. if (status & UNUSED_ERR)
  418. dev->stats.rx.unused++;
  419. }
  420. dev_kfree_skb_any (skb);
  421. return;
  422. }
  423. /*
  424. Note on queue handling.
  425. Here "give" and "take" refer to queue entries and a queue (pair)
  426. rather than frames to or from the host or adapter. Empty frame
  427. buffers are given to the RX queue pair and returned unused or
  428. containing RX frames. TX frames (well, pointers to TX fragment
  429. lists) are given to the TX queue pair, completions are returned.
  430. */
  431. /********** command queue **********/
  432. // I really don't like this, but it's the best I can do at the moment
  433. // also, the callers are responsible for byte order as the microcode
  434. // sometimes does 16-bit accesses (yuk yuk yuk)
  435. static int command_do (amb_dev * dev, command * cmd) {
  436. amb_cq * cq = &dev->cq;
  437. volatile amb_cq_ptrs * ptrs = &cq->ptrs;
  438. command * my_slot;
  439. PRINTD (DBG_FLOW|DBG_CMD, "command_do %p", dev);
  440. if (test_bit (dead, &dev->flags))
  441. return 0;
  442. spin_lock (&cq->lock);
  443. // if not full...
  444. if (cq->pending < cq->maximum) {
  445. // remember my slot for later
  446. my_slot = ptrs->in;
  447. PRINTD (DBG_CMD, "command in slot %p", my_slot);
  448. dump_command (cmd);
  449. // copy command in
  450. *ptrs->in = *cmd;
  451. cq->pending++;
  452. ptrs->in = NEXTQ (ptrs->in, ptrs->start, ptrs->limit);
  453. // mail the command
  454. wr_mem (dev, offsetof(amb_mem, mb.adapter.cmd_address), virt_to_bus (ptrs->in));
  455. if (cq->pending > cq->high)
  456. cq->high = cq->pending;
  457. spin_unlock (&cq->lock);
  458. // these comments were in a while-loop before, msleep removes the loop
  459. // go to sleep
  460. // PRINTD (DBG_CMD, "wait: sleeping %lu for command", timeout);
  461. msleep(cq->pending);
  462. // wait for my slot to be reached (all waiters are here or above, until...)
  463. while (ptrs->out != my_slot) {
  464. PRINTD (DBG_CMD, "wait: command slot (now at %p)", ptrs->out);
  465. set_current_state(TASK_UNINTERRUPTIBLE);
  466. schedule();
  467. }
  468. // wait on my slot (... one gets to its slot, and... )
  469. while (ptrs->out->request != cpu_to_be32 (SRB_COMPLETE)) {
  470. PRINTD (DBG_CMD, "wait: command slot completion");
  471. set_current_state(TASK_UNINTERRUPTIBLE);
  472. schedule();
  473. }
  474. PRINTD (DBG_CMD, "command complete");
  475. // update queue (... moves the queue along to the next slot)
  476. spin_lock (&cq->lock);
  477. cq->pending--;
  478. // copy command out
  479. *cmd = *ptrs->out;
  480. ptrs->out = NEXTQ (ptrs->out, ptrs->start, ptrs->limit);
  481. spin_unlock (&cq->lock);
  482. return 0;
  483. } else {
  484. cq->filled++;
  485. spin_unlock (&cq->lock);
  486. return -EAGAIN;
  487. }
  488. }
  489. /********** TX queue pair **********/
  490. static inline int tx_give (amb_dev * dev, tx_in * tx) {
  491. amb_txq * txq = &dev->txq;
  492. unsigned long flags;
  493. PRINTD (DBG_FLOW|DBG_TX, "tx_give %p", dev);
  494. if (test_bit (dead, &dev->flags))
  495. return 0;
  496. spin_lock_irqsave (&txq->lock, flags);
  497. if (txq->pending < txq->maximum) {
  498. PRINTD (DBG_TX, "TX in slot %p", txq->in.ptr);
  499. *txq->in.ptr = *tx;
  500. txq->pending++;
  501. txq->in.ptr = NEXTQ (txq->in.ptr, txq->in.start, txq->in.limit);
  502. // hand over the TX and ring the bell
  503. wr_mem (dev, offsetof(amb_mem, mb.adapter.tx_address), virt_to_bus (txq->in.ptr));
  504. wr_mem (dev, offsetof(amb_mem, doorbell), TX_FRAME);
  505. if (txq->pending > txq->high)
  506. txq->high = txq->pending;
  507. spin_unlock_irqrestore (&txq->lock, flags);
  508. return 0;
  509. } else {
  510. txq->filled++;
  511. spin_unlock_irqrestore (&txq->lock, flags);
  512. return -EAGAIN;
  513. }
  514. }
  515. static inline int tx_take (amb_dev * dev) {
  516. amb_txq * txq = &dev->txq;
  517. unsigned long flags;
  518. PRINTD (DBG_FLOW|DBG_TX, "tx_take %p", dev);
  519. spin_lock_irqsave (&txq->lock, flags);
  520. if (txq->pending && txq->out.ptr->handle) {
  521. // deal with TX completion
  522. tx_complete (dev, txq->out.ptr);
  523. // mark unused again
  524. txq->out.ptr->handle = 0;
  525. // remove item
  526. txq->pending--;
  527. txq->out.ptr = NEXTQ (txq->out.ptr, txq->out.start, txq->out.limit);
  528. spin_unlock_irqrestore (&txq->lock, flags);
  529. return 0;
  530. } else {
  531. spin_unlock_irqrestore (&txq->lock, flags);
  532. return -1;
  533. }
  534. }
  535. /********** RX queue pairs **********/
  536. static inline int rx_give (amb_dev * dev, rx_in * rx, unsigned char pool) {
  537. amb_rxq * rxq = &dev->rxq[pool];
  538. unsigned long flags;
  539. PRINTD (DBG_FLOW|DBG_RX, "rx_give %p[%hu]", dev, pool);
  540. spin_lock_irqsave (&rxq->lock, flags);
  541. if (rxq->pending < rxq->maximum) {
  542. PRINTD (DBG_RX, "RX in slot %p", rxq->in.ptr);
  543. *rxq->in.ptr = *rx;
  544. rxq->pending++;
  545. rxq->in.ptr = NEXTQ (rxq->in.ptr, rxq->in.start, rxq->in.limit);
  546. // hand over the RX buffer
  547. wr_mem (dev, offsetof(amb_mem, mb.adapter.rx_address[pool]), virt_to_bus (rxq->in.ptr));
  548. spin_unlock_irqrestore (&rxq->lock, flags);
  549. return 0;
  550. } else {
  551. spin_unlock_irqrestore (&rxq->lock, flags);
  552. return -1;
  553. }
  554. }
  555. static inline int rx_take (amb_dev * dev, unsigned char pool) {
  556. amb_rxq * rxq = &dev->rxq[pool];
  557. unsigned long flags;
  558. PRINTD (DBG_FLOW|DBG_RX, "rx_take %p[%hu]", dev, pool);
  559. spin_lock_irqsave (&rxq->lock, flags);
  560. if (rxq->pending && (rxq->out.ptr->status || rxq->out.ptr->length)) {
  561. // deal with RX completion
  562. rx_complete (dev, rxq->out.ptr);
  563. // mark unused again
  564. rxq->out.ptr->status = 0;
  565. rxq->out.ptr->length = 0;
  566. // remove item
  567. rxq->pending--;
  568. rxq->out.ptr = NEXTQ (rxq->out.ptr, rxq->out.start, rxq->out.limit);
  569. if (rxq->pending < rxq->low)
  570. rxq->low = rxq->pending;
  571. spin_unlock_irqrestore (&rxq->lock, flags);
  572. return 0;
  573. } else {
  574. if (!rxq->pending && rxq->buffers_wanted)
  575. rxq->emptied++;
  576. spin_unlock_irqrestore (&rxq->lock, flags);
  577. return -1;
  578. }
  579. }
  580. /********** RX Pool handling **********/
  581. /* pre: buffers_wanted = 0, post: pending = 0 */
  582. static inline void drain_rx_pool (amb_dev * dev, unsigned char pool) {
  583. amb_rxq * rxq = &dev->rxq[pool];
  584. PRINTD (DBG_FLOW|DBG_POOL, "drain_rx_pool %p %hu", dev, pool);
  585. if (test_bit (dead, &dev->flags))
  586. return;
  587. /* we are not quite like the fill pool routines as we cannot just
  588. remove one buffer, we have to remove all of them, but we might as
  589. well pretend... */
  590. if (rxq->pending > rxq->buffers_wanted) {
  591. command cmd;
  592. cmd.request = cpu_to_be32 (SRB_FLUSH_BUFFER_Q);
  593. cmd.args.flush.flags = cpu_to_be32 (pool << SRB_POOL_SHIFT);
  594. while (command_do (dev, &cmd))
  595. schedule();
  596. /* the pool may also be emptied via the interrupt handler */
  597. while (rxq->pending > rxq->buffers_wanted)
  598. if (rx_take (dev, pool))
  599. schedule();
  600. }
  601. return;
  602. }
  603. static void drain_rx_pools (amb_dev * dev) {
  604. unsigned char pool;
  605. PRINTD (DBG_FLOW|DBG_POOL, "drain_rx_pools %p", dev);
  606. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  607. drain_rx_pool (dev, pool);
  608. }
  609. static inline void fill_rx_pool (amb_dev * dev, unsigned char pool,
  610. gfp_t priority)
  611. {
  612. rx_in rx;
  613. amb_rxq * rxq;
  614. PRINTD (DBG_FLOW|DBG_POOL, "fill_rx_pool %p %hu %x", dev, pool, priority);
  615. if (test_bit (dead, &dev->flags))
  616. return;
  617. rxq = &dev->rxq[pool];
  618. while (rxq->pending < rxq->maximum && rxq->pending < rxq->buffers_wanted) {
  619. struct sk_buff * skb = alloc_skb (rxq->buffer_size, priority);
  620. if (!skb) {
  621. PRINTD (DBG_SKB|DBG_POOL, "failed to allocate skb for RX pool %hu", pool);
  622. return;
  623. }
  624. if (check_area (skb->data, skb->truesize)) {
  625. dev_kfree_skb_any (skb);
  626. return;
  627. }
  628. // cast needed as there is no %? for pointer differences
  629. PRINTD (DBG_SKB, "allocated skb at %p, head %p, area %li",
  630. skb, skb->head, (long) (skb->end - skb->head));
  631. rx.handle = virt_to_bus (skb);
  632. rx.host_address = cpu_to_be32 (virt_to_bus (skb->data));
  633. if (rx_give (dev, &rx, pool))
  634. dev_kfree_skb_any (skb);
  635. }
  636. return;
  637. }
  638. // top up all RX pools (can also be called as a bottom half)
  639. static void fill_rx_pools (amb_dev * dev) {
  640. unsigned char pool;
  641. PRINTD (DBG_FLOW|DBG_POOL, "fill_rx_pools %p", dev);
  642. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  643. fill_rx_pool (dev, pool, GFP_ATOMIC);
  644. return;
  645. }
  646. /********** enable host interrupts **********/
  647. static inline void interrupts_on (amb_dev * dev) {
  648. wr_plain (dev, offsetof(amb_mem, interrupt_control),
  649. rd_plain (dev, offsetof(amb_mem, interrupt_control))
  650. | AMB_INTERRUPT_BITS);
  651. }
  652. /********** disable host interrupts **********/
  653. static inline void interrupts_off (amb_dev * dev) {
  654. wr_plain (dev, offsetof(amb_mem, interrupt_control),
  655. rd_plain (dev, offsetof(amb_mem, interrupt_control))
  656. &~ AMB_INTERRUPT_BITS);
  657. }
  658. /********** interrupt handling **********/
  659. static irqreturn_t interrupt_handler(int irq, void *dev_id) {
  660. amb_dev * dev = dev_id;
  661. PRINTD (DBG_IRQ|DBG_FLOW, "interrupt_handler: %p", dev_id);
  662. {
  663. u32 interrupt = rd_plain (dev, offsetof(amb_mem, interrupt));
  664. // for us or someone else sharing the same interrupt
  665. if (!interrupt) {
  666. PRINTD (DBG_IRQ, "irq not for me: %d", irq);
  667. return IRQ_NONE;
  668. }
  669. // definitely for us
  670. PRINTD (DBG_IRQ, "FYI: interrupt was %08x", interrupt);
  671. wr_plain (dev, offsetof(amb_mem, interrupt), -1);
  672. }
  673. {
  674. unsigned int irq_work = 0;
  675. unsigned char pool;
  676. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  677. while (!rx_take (dev, pool))
  678. ++irq_work;
  679. while (!tx_take (dev))
  680. ++irq_work;
  681. if (irq_work) {
  682. #ifdef FILL_RX_POOLS_IN_BH
  683. schedule_work (&dev->bh);
  684. #else
  685. fill_rx_pools (dev);
  686. #endif
  687. PRINTD (DBG_IRQ, "work done: %u", irq_work);
  688. } else {
  689. PRINTD (DBG_IRQ|DBG_WARN, "no work done");
  690. }
  691. }
  692. PRINTD (DBG_IRQ|DBG_FLOW, "interrupt_handler done: %p", dev_id);
  693. return IRQ_HANDLED;
  694. }
  695. /********** make rate (not quite as much fun as Horizon) **********/
  696. static int make_rate (unsigned int rate, rounding r,
  697. u16 * bits, unsigned int * actual) {
  698. unsigned char exp = -1; // hush gcc
  699. unsigned int man = -1; // hush gcc
  700. PRINTD (DBG_FLOW|DBG_QOS, "make_rate %u", rate);
  701. // rates in cells per second, ITU format (nasty 16-bit floating-point)
  702. // given 5-bit e and 9-bit m:
  703. // rate = EITHER (1+m/2^9)*2^e OR 0
  704. // bits = EITHER 1<<14 | e<<9 | m OR 0
  705. // (bit 15 is "reserved", bit 14 "non-zero")
  706. // smallest rate is 0 (special representation)
  707. // largest rate is (1+511/512)*2^31 = 4290772992 (< 2^32-1)
  708. // smallest non-zero rate is (1+0/512)*2^0 = 1 (> 0)
  709. // simple algorithm:
  710. // find position of top bit, this gives e
  711. // remove top bit and shift (rounding if feeling clever) by 9-e
  712. // ucode bug: please don't set bit 14! so 0 rate not representable
  713. if (rate > 0xffc00000U) {
  714. // larger than largest representable rate
  715. if (r == round_up) {
  716. return -EINVAL;
  717. } else {
  718. exp = 31;
  719. man = 511;
  720. }
  721. } else if (rate) {
  722. // representable rate
  723. exp = 31;
  724. man = rate;
  725. // invariant: rate = man*2^(exp-31)
  726. while (!(man & (1<<31))) {
  727. exp = exp - 1;
  728. man = man<<1;
  729. }
  730. // man has top bit set
  731. // rate = (2^31+(man-2^31))*2^(exp-31)
  732. // rate = (1+(man-2^31)/2^31)*2^exp
  733. man = man<<1;
  734. man &= 0xffffffffU; // a nop on 32-bit systems
  735. // rate = (1+man/2^32)*2^exp
  736. // exp is in the range 0 to 31, man is in the range 0 to 2^32-1
  737. // time to lose significance... we want m in the range 0 to 2^9-1
  738. // rounding presents a minor problem... we first decide which way
  739. // we are rounding (based on given rounding direction and possibly
  740. // the bits of the mantissa that are to be discarded).
  741. switch (r) {
  742. case round_down: {
  743. // just truncate
  744. man = man>>(32-9);
  745. break;
  746. }
  747. case round_up: {
  748. // check all bits that we are discarding
  749. if (man & (-1>>9)) {
  750. man = (man>>(32-9)) + 1;
  751. if (man == (1<<9)) {
  752. // no need to check for round up outside of range
  753. man = 0;
  754. exp += 1;
  755. }
  756. } else {
  757. man = (man>>(32-9));
  758. }
  759. break;
  760. }
  761. case round_nearest: {
  762. // check msb that we are discarding
  763. if (man & (1<<(32-9-1))) {
  764. man = (man>>(32-9)) + 1;
  765. if (man == (1<<9)) {
  766. // no need to check for round up outside of range
  767. man = 0;
  768. exp += 1;
  769. }
  770. } else {
  771. man = (man>>(32-9));
  772. }
  773. break;
  774. }
  775. }
  776. } else {
  777. // zero rate - not representable
  778. if (r == round_down) {
  779. return -EINVAL;
  780. } else {
  781. exp = 0;
  782. man = 0;
  783. }
  784. }
  785. PRINTD (DBG_QOS, "rate: man=%u, exp=%hu", man, exp);
  786. if (bits)
  787. *bits = /* (1<<14) | */ (exp<<9) | man;
  788. if (actual)
  789. *actual = (exp >= 9)
  790. ? (1 << exp) + (man << (exp-9))
  791. : (1 << exp) + ((man + (1<<(9-exp-1))) >> (9-exp));
  792. return 0;
  793. }
  794. /********** Linux ATM Operations **********/
  795. // some are not yet implemented while others do not make sense for
  796. // this device
  797. /********** Open a VC **********/
  798. static int amb_open (struct atm_vcc * atm_vcc)
  799. {
  800. int error;
  801. struct atm_qos * qos;
  802. struct atm_trafprm * txtp;
  803. struct atm_trafprm * rxtp;
  804. u16 tx_rate_bits;
  805. u16 tx_vc_bits = -1; // hush gcc
  806. u16 tx_frame_bits = -1; // hush gcc
  807. amb_dev * dev = AMB_DEV(atm_vcc->dev);
  808. amb_vcc * vcc;
  809. unsigned char pool = -1; // hush gcc
  810. short vpi = atm_vcc->vpi;
  811. int vci = atm_vcc->vci;
  812. PRINTD (DBG_FLOW|DBG_VCC, "amb_open %x %x", vpi, vci);
  813. #ifdef ATM_VPI_UNSPEC
  814. // UNSPEC is deprecated, remove this code eventually
  815. if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) {
  816. PRINTK (KERN_WARNING, "rejecting open with unspecified VPI/VCI (deprecated)");
  817. return -EINVAL;
  818. }
  819. #endif
  820. if (!(0 <= vpi && vpi < (1<<NUM_VPI_BITS) &&
  821. 0 <= vci && vci < (1<<NUM_VCI_BITS))) {
  822. PRINTD (DBG_WARN|DBG_VCC, "VPI/VCI out of range: %hd/%d", vpi, vci);
  823. return -EINVAL;
  824. }
  825. qos = &atm_vcc->qos;
  826. if (qos->aal != ATM_AAL5) {
  827. PRINTD (DBG_QOS, "AAL not supported");
  828. return -EINVAL;
  829. }
  830. // traffic parameters
  831. PRINTD (DBG_QOS, "TX:");
  832. txtp = &qos->txtp;
  833. if (txtp->traffic_class != ATM_NONE) {
  834. switch (txtp->traffic_class) {
  835. case ATM_UBR: {
  836. // we take "the PCR" as a rate-cap
  837. int pcr = atm_pcr_goal (txtp);
  838. if (!pcr) {
  839. // no rate cap
  840. tx_rate_bits = 0;
  841. tx_vc_bits = TX_UBR;
  842. tx_frame_bits = TX_FRAME_NOTCAP;
  843. } else {
  844. rounding r;
  845. if (pcr < 0) {
  846. r = round_down;
  847. pcr = -pcr;
  848. } else {
  849. r = round_up;
  850. }
  851. error = make_rate (pcr, r, &tx_rate_bits, NULL);
  852. tx_vc_bits = TX_UBR_CAPPED;
  853. tx_frame_bits = TX_FRAME_CAPPED;
  854. }
  855. break;
  856. }
  857. #if 0
  858. case ATM_ABR: {
  859. pcr = atm_pcr_goal (txtp);
  860. PRINTD (DBG_QOS, "pcr goal = %d", pcr);
  861. break;
  862. }
  863. #endif
  864. default: {
  865. // PRINTD (DBG_QOS, "request for non-UBR/ABR denied");
  866. PRINTD (DBG_QOS, "request for non-UBR denied");
  867. return -EINVAL;
  868. }
  869. }
  870. PRINTD (DBG_QOS, "tx_rate_bits=%hx, tx_vc_bits=%hx",
  871. tx_rate_bits, tx_vc_bits);
  872. }
  873. PRINTD (DBG_QOS, "RX:");
  874. rxtp = &qos->rxtp;
  875. if (rxtp->traffic_class == ATM_NONE) {
  876. // do nothing
  877. } else {
  878. // choose an RX pool (arranged in increasing size)
  879. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  880. if ((unsigned int) rxtp->max_sdu <= dev->rxq[pool].buffer_size) {
  881. PRINTD (DBG_VCC|DBG_QOS|DBG_POOL, "chose pool %hu (max_sdu %u <= %u)",
  882. pool, rxtp->max_sdu, dev->rxq[pool].buffer_size);
  883. break;
  884. }
  885. if (pool == NUM_RX_POOLS) {
  886. PRINTD (DBG_WARN|DBG_VCC|DBG_QOS|DBG_POOL,
  887. "no pool suitable for VC (RX max_sdu %d is too large)",
  888. rxtp->max_sdu);
  889. return -EINVAL;
  890. }
  891. switch (rxtp->traffic_class) {
  892. case ATM_UBR: {
  893. break;
  894. }
  895. #if 0
  896. case ATM_ABR: {
  897. pcr = atm_pcr_goal (rxtp);
  898. PRINTD (DBG_QOS, "pcr goal = %d", pcr);
  899. break;
  900. }
  901. #endif
  902. default: {
  903. // PRINTD (DBG_QOS, "request for non-UBR/ABR denied");
  904. PRINTD (DBG_QOS, "request for non-UBR denied");
  905. return -EINVAL;
  906. }
  907. }
  908. }
  909. // get space for our vcc stuff
  910. vcc = kmalloc (sizeof(amb_vcc), GFP_KERNEL);
  911. if (!vcc) {
  912. PRINTK (KERN_ERR, "out of memory!");
  913. return -ENOMEM;
  914. }
  915. atm_vcc->dev_data = (void *) vcc;
  916. // no failures beyond this point
  917. // we are not really "immediately before allocating the connection
  918. // identifier in hardware", but it will just have to do!
  919. set_bit(ATM_VF_ADDR,&atm_vcc->flags);
  920. if (txtp->traffic_class != ATM_NONE) {
  921. command cmd;
  922. vcc->tx_frame_bits = tx_frame_bits;
  923. down (&dev->vcc_sf);
  924. if (dev->rxer[vci]) {
  925. // RXer on the channel already, just modify rate...
  926. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
  927. cmd.args.modify_rate.vc = cpu_to_be32 (vci); // vpi 0
  928. cmd.args.modify_rate.rate = cpu_to_be32 (tx_rate_bits << SRB_RATE_SHIFT);
  929. while (command_do (dev, &cmd))
  930. schedule();
  931. // ... and TX flags, preserving the RX pool
  932. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  933. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  934. cmd.args.modify_flags.flags = cpu_to_be32
  935. ( (AMB_VCC(dev->rxer[vci])->rx_info.pool << SRB_POOL_SHIFT)
  936. | (tx_vc_bits << SRB_FLAGS_SHIFT) );
  937. while (command_do (dev, &cmd))
  938. schedule();
  939. } else {
  940. // no RXer on the channel, just open (with pool zero)
  941. cmd.request = cpu_to_be32 (SRB_OPEN_VC);
  942. cmd.args.open.vc = cpu_to_be32 (vci); // vpi 0
  943. cmd.args.open.flags = cpu_to_be32 (tx_vc_bits << SRB_FLAGS_SHIFT);
  944. cmd.args.open.rate = cpu_to_be32 (tx_rate_bits << SRB_RATE_SHIFT);
  945. while (command_do (dev, &cmd))
  946. schedule();
  947. }
  948. dev->txer[vci].tx_present = 1;
  949. up (&dev->vcc_sf);
  950. }
  951. if (rxtp->traffic_class != ATM_NONE) {
  952. command cmd;
  953. vcc->rx_info.pool = pool;
  954. down (&dev->vcc_sf);
  955. /* grow RX buffer pool */
  956. if (!dev->rxq[pool].buffers_wanted)
  957. dev->rxq[pool].buffers_wanted = rx_lats;
  958. dev->rxq[pool].buffers_wanted += 1;
  959. fill_rx_pool (dev, pool, GFP_KERNEL);
  960. if (dev->txer[vci].tx_present) {
  961. // TXer on the channel already
  962. // switch (from pool zero) to this pool, preserving the TX bits
  963. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  964. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  965. cmd.args.modify_flags.flags = cpu_to_be32
  966. ( (pool << SRB_POOL_SHIFT)
  967. | (dev->txer[vci].tx_vc_bits << SRB_FLAGS_SHIFT) );
  968. } else {
  969. // no TXer on the channel, open the VC (with no rate info)
  970. cmd.request = cpu_to_be32 (SRB_OPEN_VC);
  971. cmd.args.open.vc = cpu_to_be32 (vci); // vpi 0
  972. cmd.args.open.flags = cpu_to_be32 (pool << SRB_POOL_SHIFT);
  973. cmd.args.open.rate = cpu_to_be32 (0);
  974. }
  975. while (command_do (dev, &cmd))
  976. schedule();
  977. // this link allows RX frames through
  978. dev->rxer[vci] = atm_vcc;
  979. up (&dev->vcc_sf);
  980. }
  981. // indicate readiness
  982. set_bit(ATM_VF_READY,&atm_vcc->flags);
  983. return 0;
  984. }
  985. /********** Close a VC **********/
  986. static void amb_close (struct atm_vcc * atm_vcc) {
  987. amb_dev * dev = AMB_DEV (atm_vcc->dev);
  988. amb_vcc * vcc = AMB_VCC (atm_vcc);
  989. u16 vci = atm_vcc->vci;
  990. PRINTD (DBG_VCC|DBG_FLOW, "amb_close");
  991. // indicate unreadiness
  992. clear_bit(ATM_VF_READY,&atm_vcc->flags);
  993. // disable TXing
  994. if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) {
  995. command cmd;
  996. down (&dev->vcc_sf);
  997. if (dev->rxer[vci]) {
  998. // RXer still on the channel, just modify rate... XXX not really needed
  999. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
  1000. cmd.args.modify_rate.vc = cpu_to_be32 (vci); // vpi 0
  1001. cmd.args.modify_rate.rate = cpu_to_be32 (0);
  1002. // ... and clear TX rate flags (XXX to stop RM cell output?), preserving RX pool
  1003. } else {
  1004. // no RXer on the channel, close channel
  1005. cmd.request = cpu_to_be32 (SRB_CLOSE_VC);
  1006. cmd.args.close.vc = cpu_to_be32 (vci); // vpi 0
  1007. }
  1008. dev->txer[vci].tx_present = 0;
  1009. while (command_do (dev, &cmd))
  1010. schedule();
  1011. up (&dev->vcc_sf);
  1012. }
  1013. // disable RXing
  1014. if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1015. command cmd;
  1016. // this is (the?) one reason why we need the amb_vcc struct
  1017. unsigned char pool = vcc->rx_info.pool;
  1018. down (&dev->vcc_sf);
  1019. if (dev->txer[vci].tx_present) {
  1020. // TXer still on the channel, just go to pool zero XXX not really needed
  1021. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  1022. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  1023. cmd.args.modify_flags.flags = cpu_to_be32
  1024. (dev->txer[vci].tx_vc_bits << SRB_FLAGS_SHIFT);
  1025. } else {
  1026. // no TXer on the channel, close the VC
  1027. cmd.request = cpu_to_be32 (SRB_CLOSE_VC);
  1028. cmd.args.close.vc = cpu_to_be32 (vci); // vpi 0
  1029. }
  1030. // forget the rxer - no more skbs will be pushed
  1031. if (atm_vcc != dev->rxer[vci])
  1032. PRINTK (KERN_ERR, "%s vcc=%p rxer[vci]=%p",
  1033. "arghhh! we're going to die!",
  1034. vcc, dev->rxer[vci]);
  1035. dev->rxer[vci] = NULL;
  1036. while (command_do (dev, &cmd))
  1037. schedule();
  1038. /* shrink RX buffer pool */
  1039. dev->rxq[pool].buffers_wanted -= 1;
  1040. if (dev->rxq[pool].buffers_wanted == rx_lats) {
  1041. dev->rxq[pool].buffers_wanted = 0;
  1042. drain_rx_pool (dev, pool);
  1043. }
  1044. up (&dev->vcc_sf);
  1045. }
  1046. // free our structure
  1047. kfree (vcc);
  1048. // say the VPI/VCI is free again
  1049. clear_bit(ATM_VF_ADDR,&atm_vcc->flags);
  1050. return;
  1051. }
  1052. /********** Set socket options for a VC **********/
  1053. // int amb_getsockopt (struct atm_vcc * atm_vcc, int level, int optname, void * optval, int optlen);
  1054. /********** Set socket options for a VC **********/
  1055. // int amb_setsockopt (struct atm_vcc * atm_vcc, int level, int optname, void * optval, int optlen);
  1056. /********** Send **********/
  1057. static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
  1058. amb_dev * dev = AMB_DEV(atm_vcc->dev);
  1059. amb_vcc * vcc = AMB_VCC(atm_vcc);
  1060. u16 vc = atm_vcc->vci;
  1061. unsigned int tx_len = skb->len;
  1062. unsigned char * tx_data = skb->data;
  1063. tx_simple * tx_descr;
  1064. tx_in tx;
  1065. if (test_bit (dead, &dev->flags))
  1066. return -EIO;
  1067. PRINTD (DBG_FLOW|DBG_TX, "amb_send vc %x data %p len %u",
  1068. vc, tx_data, tx_len);
  1069. dump_skb (">>>", vc, skb);
  1070. if (!dev->txer[vc].tx_present) {
  1071. PRINTK (KERN_ERR, "attempt to send on RX-only VC %x", vc);
  1072. return -EBADFD;
  1073. }
  1074. // this is a driver private field so we have to set it ourselves,
  1075. // despite the fact that we are _required_ to use it to check for a
  1076. // pop function
  1077. ATM_SKB(skb)->vcc = atm_vcc;
  1078. if (skb->len > (size_t) atm_vcc->qos.txtp.max_sdu) {
  1079. PRINTK (KERN_ERR, "sk_buff length greater than agreed max_sdu, dropping...");
  1080. return -EIO;
  1081. }
  1082. if (check_area (skb->data, skb->len)) {
  1083. atomic_inc(&atm_vcc->stats->tx_err);
  1084. return -ENOMEM; // ?
  1085. }
  1086. // allocate memory for fragments
  1087. tx_descr = kmalloc (sizeof(tx_simple), GFP_KERNEL);
  1088. if (!tx_descr) {
  1089. PRINTK (KERN_ERR, "could not allocate TX descriptor");
  1090. return -ENOMEM;
  1091. }
  1092. if (check_area (tx_descr, sizeof(tx_simple))) {
  1093. kfree (tx_descr);
  1094. return -ENOMEM;
  1095. }
  1096. PRINTD (DBG_TX, "fragment list allocated at %p", tx_descr);
  1097. tx_descr->skb = skb;
  1098. tx_descr->tx_frag.bytes = cpu_to_be32 (tx_len);
  1099. tx_descr->tx_frag.address = cpu_to_be32 (virt_to_bus (tx_data));
  1100. tx_descr->tx_frag_end.handle = virt_to_bus (tx_descr);
  1101. tx_descr->tx_frag_end.vc = 0;
  1102. tx_descr->tx_frag_end.next_descriptor_length = 0;
  1103. tx_descr->tx_frag_end.next_descriptor = 0;
  1104. #ifdef AMB_NEW_MICROCODE
  1105. tx_descr->tx_frag_end.cpcs_uu = 0;
  1106. tx_descr->tx_frag_end.cpi = 0;
  1107. tx_descr->tx_frag_end.pad = 0;
  1108. #endif
  1109. tx.vc = cpu_to_be16 (vcc->tx_frame_bits | vc);
  1110. tx.tx_descr_length = cpu_to_be16 (sizeof(tx_frag)+sizeof(tx_frag_end));
  1111. tx.tx_descr_addr = cpu_to_be32 (virt_to_bus (&tx_descr->tx_frag));
  1112. while (tx_give (dev, &tx))
  1113. schedule();
  1114. return 0;
  1115. }
  1116. /********** Change QoS on a VC **********/
  1117. // int amb_change_qos (struct atm_vcc * atm_vcc, struct atm_qos * qos, int flags);
  1118. /********** Free RX Socket Buffer **********/
  1119. #if 0
  1120. static void amb_free_rx_skb (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
  1121. amb_dev * dev = AMB_DEV (atm_vcc->dev);
  1122. amb_vcc * vcc = AMB_VCC (atm_vcc);
  1123. unsigned char pool = vcc->rx_info.pool;
  1124. rx_in rx;
  1125. // This may be unsafe for various reasons that I cannot really guess
  1126. // at. However, I note that the ATM layer calls kfree_skb rather
  1127. // than dev_kfree_skb at this point so we are least covered as far
  1128. // as buffer locking goes. There may be bugs if pcap clones RX skbs.
  1129. PRINTD (DBG_FLOW|DBG_SKB, "amb_rx_free skb %p (atm_vcc %p, vcc %p)",
  1130. skb, atm_vcc, vcc);
  1131. rx.handle = virt_to_bus (skb);
  1132. rx.host_address = cpu_to_be32 (virt_to_bus (skb->data));
  1133. skb->data = skb->head;
  1134. skb->tail = skb->head;
  1135. skb->len = 0;
  1136. if (!rx_give (dev, &rx, pool)) {
  1137. // success
  1138. PRINTD (DBG_SKB|DBG_POOL, "recycled skb for pool %hu", pool);
  1139. return;
  1140. }
  1141. // just do what the ATM layer would have done
  1142. dev_kfree_skb_any (skb);
  1143. return;
  1144. }
  1145. #endif
  1146. /********** Proc File Output **********/
  1147. static int amb_proc_read (struct atm_dev * atm_dev, loff_t * pos, char * page) {
  1148. amb_dev * dev = AMB_DEV (atm_dev);
  1149. int left = *pos;
  1150. unsigned char pool;
  1151. PRINTD (DBG_FLOW, "amb_proc_read");
  1152. /* more diagnostics here? */
  1153. if (!left--) {
  1154. amb_stats * s = &dev->stats;
  1155. return sprintf (page,
  1156. "frames: TX OK %lu, RX OK %lu, RX bad %lu "
  1157. "(CRC %lu, long %lu, aborted %lu, unused %lu).\n",
  1158. s->tx_ok, s->rx.ok, s->rx.error,
  1159. s->rx.badcrc, s->rx.toolong,
  1160. s->rx.aborted, s->rx.unused);
  1161. }
  1162. if (!left--) {
  1163. amb_cq * c = &dev->cq;
  1164. return sprintf (page, "cmd queue [cur/hi/max]: %u/%u/%u. ",
  1165. c->pending, c->high, c->maximum);
  1166. }
  1167. if (!left--) {
  1168. amb_txq * t = &dev->txq;
  1169. return sprintf (page, "TX queue [cur/max high full]: %u/%u %u %u.\n",
  1170. t->pending, t->maximum, t->high, t->filled);
  1171. }
  1172. if (!left--) {
  1173. unsigned int count = sprintf (page, "RX queues [cur/max/req low empty]:");
  1174. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1175. amb_rxq * r = &dev->rxq[pool];
  1176. count += sprintf (page+count, " %u/%u/%u %u %u",
  1177. r->pending, r->maximum, r->buffers_wanted, r->low, r->emptied);
  1178. }
  1179. count += sprintf (page+count, ".\n");
  1180. return count;
  1181. }
  1182. if (!left--) {
  1183. unsigned int count = sprintf (page, "RX buffer sizes:");
  1184. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1185. amb_rxq * r = &dev->rxq[pool];
  1186. count += sprintf (page+count, " %u", r->buffer_size);
  1187. }
  1188. count += sprintf (page+count, ".\n");
  1189. return count;
  1190. }
  1191. #if 0
  1192. if (!left--) {
  1193. // suni block etc?
  1194. }
  1195. #endif
  1196. return 0;
  1197. }
  1198. /********** Operation Structure **********/
  1199. static const struct atmdev_ops amb_ops = {
  1200. .open = amb_open,
  1201. .close = amb_close,
  1202. .send = amb_send,
  1203. .proc_read = amb_proc_read,
  1204. .owner = THIS_MODULE,
  1205. };
  1206. /********** housekeeping **********/
  1207. static void do_housekeeping (unsigned long arg) {
  1208. amb_dev * dev = (amb_dev *) arg;
  1209. // could collect device-specific (not driver/atm-linux) stats here
  1210. // last resort refill once every ten seconds
  1211. fill_rx_pools (dev);
  1212. mod_timer(&dev->housekeeping, jiffies + 10*HZ);
  1213. return;
  1214. }
  1215. /********** creation of communication queues **********/
  1216. static int __devinit create_queues (amb_dev * dev, unsigned int cmds,
  1217. unsigned int txs, unsigned int * rxs,
  1218. unsigned int * rx_buffer_sizes) {
  1219. unsigned char pool;
  1220. size_t total = 0;
  1221. void * memory;
  1222. void * limit;
  1223. PRINTD (DBG_FLOW, "create_queues %p", dev);
  1224. total += cmds * sizeof(command);
  1225. total += txs * (sizeof(tx_in) + sizeof(tx_out));
  1226. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1227. total += rxs[pool] * (sizeof(rx_in) + sizeof(rx_out));
  1228. memory = kmalloc (total, GFP_KERNEL);
  1229. if (!memory) {
  1230. PRINTK (KERN_ERR, "could not allocate queues");
  1231. return -ENOMEM;
  1232. }
  1233. if (check_area (memory, total)) {
  1234. PRINTK (KERN_ERR, "queues allocated in nasty area");
  1235. kfree (memory);
  1236. return -ENOMEM;
  1237. }
  1238. limit = memory + total;
  1239. PRINTD (DBG_INIT, "queues from %p to %p", memory, limit);
  1240. PRINTD (DBG_CMD, "command queue at %p", memory);
  1241. {
  1242. command * cmd = memory;
  1243. amb_cq * cq = &dev->cq;
  1244. cq->pending = 0;
  1245. cq->high = 0;
  1246. cq->maximum = cmds - 1;
  1247. cq->ptrs.start = cmd;
  1248. cq->ptrs.in = cmd;
  1249. cq->ptrs.out = cmd;
  1250. cq->ptrs.limit = cmd + cmds;
  1251. memory = cq->ptrs.limit;
  1252. }
  1253. PRINTD (DBG_TX, "TX queue pair at %p", memory);
  1254. {
  1255. tx_in * in = memory;
  1256. tx_out * out;
  1257. amb_txq * txq = &dev->txq;
  1258. txq->pending = 0;
  1259. txq->high = 0;
  1260. txq->filled = 0;
  1261. txq->maximum = txs - 1;
  1262. txq->in.start = in;
  1263. txq->in.ptr = in;
  1264. txq->in.limit = in + txs;
  1265. memory = txq->in.limit;
  1266. out = memory;
  1267. txq->out.start = out;
  1268. txq->out.ptr = out;
  1269. txq->out.limit = out + txs;
  1270. memory = txq->out.limit;
  1271. }
  1272. PRINTD (DBG_RX, "RX queue pairs at %p", memory);
  1273. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1274. rx_in * in = memory;
  1275. rx_out * out;
  1276. amb_rxq * rxq = &dev->rxq[pool];
  1277. rxq->buffer_size = rx_buffer_sizes[pool];
  1278. rxq->buffers_wanted = 0;
  1279. rxq->pending = 0;
  1280. rxq->low = rxs[pool] - 1;
  1281. rxq->emptied = 0;
  1282. rxq->maximum = rxs[pool] - 1;
  1283. rxq->in.start = in;
  1284. rxq->in.ptr = in;
  1285. rxq->in.limit = in + rxs[pool];
  1286. memory = rxq->in.limit;
  1287. out = memory;
  1288. rxq->out.start = out;
  1289. rxq->out.ptr = out;
  1290. rxq->out.limit = out + rxs[pool];
  1291. memory = rxq->out.limit;
  1292. }
  1293. if (memory == limit) {
  1294. return 0;
  1295. } else {
  1296. PRINTK (KERN_ERR, "bad queue alloc %p != %p (tell maintainer)", memory, limit);
  1297. kfree (limit - total);
  1298. return -ENOMEM;
  1299. }
  1300. }
  1301. /********** destruction of communication queues **********/
  1302. static void destroy_queues (amb_dev * dev) {
  1303. // all queues assumed empty
  1304. void * memory = dev->cq.ptrs.start;
  1305. // includes txq.in, txq.out, rxq[].in and rxq[].out
  1306. PRINTD (DBG_FLOW, "destroy_queues %p", dev);
  1307. PRINTD (DBG_INIT, "freeing queues at %p", memory);
  1308. kfree (memory);
  1309. return;
  1310. }
  1311. /********** basic loader commands and error handling **********/
  1312. // centisecond timeouts - guessing away here
  1313. static unsigned int command_timeouts [] = {
  1314. [host_memory_test] = 15,
  1315. [read_adapter_memory] = 2,
  1316. [write_adapter_memory] = 2,
  1317. [adapter_start] = 50,
  1318. [get_version_number] = 10,
  1319. [interrupt_host] = 1,
  1320. [flash_erase_sector] = 1,
  1321. [adap_download_block] = 1,
  1322. [adap_erase_flash] = 1,
  1323. [adap_run_in_iram] = 1,
  1324. [adap_end_download] = 1
  1325. };
  1326. static unsigned int command_successes [] = {
  1327. [host_memory_test] = COMMAND_PASSED_TEST,
  1328. [read_adapter_memory] = COMMAND_READ_DATA_OK,
  1329. [write_adapter_memory] = COMMAND_WRITE_DATA_OK,
  1330. [adapter_start] = COMMAND_COMPLETE,
  1331. [get_version_number] = COMMAND_COMPLETE,
  1332. [interrupt_host] = COMMAND_COMPLETE,
  1333. [flash_erase_sector] = COMMAND_COMPLETE,
  1334. [adap_download_block] = COMMAND_COMPLETE,
  1335. [adap_erase_flash] = COMMAND_COMPLETE,
  1336. [adap_run_in_iram] = COMMAND_COMPLETE,
  1337. [adap_end_download] = COMMAND_COMPLETE
  1338. };
  1339. static int decode_loader_result (loader_command cmd, u32 result)
  1340. {
  1341. int res;
  1342. const char *msg;
  1343. if (result == command_successes[cmd])
  1344. return 0;
  1345. switch (result) {
  1346. case BAD_COMMAND:
  1347. res = -EINVAL;
  1348. msg = "bad command";
  1349. break;
  1350. case COMMAND_IN_PROGRESS:
  1351. res = -ETIMEDOUT;
  1352. msg = "command in progress";
  1353. break;
  1354. case COMMAND_PASSED_TEST:
  1355. res = 0;
  1356. msg = "command passed test";
  1357. break;
  1358. case COMMAND_FAILED_TEST:
  1359. res = -EIO;
  1360. msg = "command failed test";
  1361. break;
  1362. case COMMAND_READ_DATA_OK:
  1363. res = 0;
  1364. msg = "command read data ok";
  1365. break;
  1366. case COMMAND_READ_BAD_ADDRESS:
  1367. res = -EINVAL;
  1368. msg = "command read bad address";
  1369. break;
  1370. case COMMAND_WRITE_DATA_OK:
  1371. res = 0;
  1372. msg = "command write data ok";
  1373. break;
  1374. case COMMAND_WRITE_BAD_ADDRESS:
  1375. res = -EINVAL;
  1376. msg = "command write bad address";
  1377. break;
  1378. case COMMAND_WRITE_FLASH_FAILURE:
  1379. res = -EIO;
  1380. msg = "command write flash failure";
  1381. break;
  1382. case COMMAND_COMPLETE:
  1383. res = 0;
  1384. msg = "command complete";
  1385. break;
  1386. case COMMAND_FLASH_ERASE_FAILURE:
  1387. res = -EIO;
  1388. msg = "command flash erase failure";
  1389. break;
  1390. case COMMAND_WRITE_BAD_DATA:
  1391. res = -EINVAL;
  1392. msg = "command write bad data";
  1393. break;
  1394. default:
  1395. res = -EINVAL;
  1396. msg = "unknown error";
  1397. PRINTD (DBG_LOAD|DBG_ERR,
  1398. "decode_loader_result got %d=%x !",
  1399. result, result);
  1400. break;
  1401. }
  1402. PRINTK (KERN_ERR, "%s", msg);
  1403. return res;
  1404. }
  1405. static int __devinit do_loader_command (volatile loader_block * lb,
  1406. const amb_dev * dev, loader_command cmd) {
  1407. unsigned long timeout;
  1408. PRINTD (DBG_FLOW|DBG_LOAD, "do_loader_command");
  1409. /* do a command
  1410. Set the return value to zero, set the command type and set the
  1411. valid entry to the right magic value. The payload is already
  1412. correctly byte-ordered so we leave it alone. Hit the doorbell
  1413. with the bus address of this structure.
  1414. */
  1415. lb->result = 0;
  1416. lb->command = cpu_to_be32 (cmd);
  1417. lb->valid = cpu_to_be32 (DMA_VALID);
  1418. // dump_registers (dev);
  1419. // dump_loader_block (lb);
  1420. wr_mem (dev, offsetof(amb_mem, doorbell), virt_to_bus (lb) & ~onegigmask);
  1421. timeout = command_timeouts[cmd] * 10;
  1422. while (!lb->result || lb->result == cpu_to_be32 (COMMAND_IN_PROGRESS))
  1423. if (timeout) {
  1424. timeout = msleep_interruptible(timeout);
  1425. } else {
  1426. PRINTD (DBG_LOAD|DBG_ERR, "command %d timed out", cmd);
  1427. dump_registers (dev);
  1428. dump_loader_block (lb);
  1429. return -ETIMEDOUT;
  1430. }
  1431. if (cmd == adapter_start) {
  1432. // wait for start command to acknowledge...
  1433. timeout = 100;
  1434. while (rd_plain (dev, offsetof(amb_mem, doorbell)))
  1435. if (timeout) {
  1436. timeout = msleep_interruptible(timeout);
  1437. } else {
  1438. PRINTD (DBG_LOAD|DBG_ERR, "start command did not clear doorbell, res=%08x",
  1439. be32_to_cpu (lb->result));
  1440. dump_registers (dev);
  1441. return -ETIMEDOUT;
  1442. }
  1443. return 0;
  1444. } else {
  1445. return decode_loader_result (cmd, be32_to_cpu (lb->result));
  1446. }
  1447. }
  1448. /* loader: determine loader version */
  1449. static int __devinit get_loader_version (loader_block * lb,
  1450. const amb_dev * dev, u32 * version) {
  1451. int res;
  1452. PRINTD (DBG_FLOW|DBG_LOAD, "get_loader_version");
  1453. res = do_loader_command (lb, dev, get_version_number);
  1454. if (res)
  1455. return res;
  1456. if (version)
  1457. *version = be32_to_cpu (lb->payload.version);
  1458. return 0;
  1459. }
  1460. /* loader: write memory data blocks */
  1461. static int __devinit loader_write (loader_block * lb,
  1462. const amb_dev * dev, const u32 * data,
  1463. u32 address, unsigned int count) {
  1464. unsigned int i;
  1465. transfer_block * tb = &lb->payload.transfer;
  1466. PRINTD (DBG_FLOW|DBG_LOAD, "loader_write");
  1467. if (count > MAX_TRANSFER_DATA)
  1468. return -EINVAL;
  1469. tb->address = cpu_to_be32 (address);
  1470. tb->count = cpu_to_be32 (count);
  1471. for (i = 0; i < count; ++i)
  1472. tb->data[i] = cpu_to_be32 (data[i]);
  1473. return do_loader_command (lb, dev, write_adapter_memory);
  1474. }
  1475. /* loader: verify memory data blocks */
  1476. static int __devinit loader_verify (loader_block * lb,
  1477. const amb_dev * dev, const u32 * data,
  1478. u32 address, unsigned int count) {
  1479. unsigned int i;
  1480. transfer_block * tb = &lb->payload.transfer;
  1481. int res;
  1482. PRINTD (DBG_FLOW|DBG_LOAD, "loader_verify");
  1483. if (count > MAX_TRANSFER_DATA)
  1484. return -EINVAL;
  1485. tb->address = cpu_to_be32 (address);
  1486. tb->count = cpu_to_be32 (count);
  1487. res = do_loader_command (lb, dev, read_adapter_memory);
  1488. if (!res)
  1489. for (i = 0; i < count; ++i)
  1490. if (tb->data[i] != cpu_to_be32 (data[i])) {
  1491. res = -EINVAL;
  1492. break;
  1493. }
  1494. return res;
  1495. }
  1496. /* loader: start microcode */
  1497. static int __devinit loader_start (loader_block * lb,
  1498. const amb_dev * dev, u32 address) {
  1499. PRINTD (DBG_FLOW|DBG_LOAD, "loader_start");
  1500. lb->payload.start = cpu_to_be32 (address);
  1501. return do_loader_command (lb, dev, adapter_start);
  1502. }
  1503. /********** reset card **********/
  1504. static inline void sf (const char * msg)
  1505. {
  1506. PRINTK (KERN_ERR, "self-test failed: %s", msg);
  1507. }
  1508. static int amb_reset (amb_dev * dev, int diags) {
  1509. u32 word;
  1510. PRINTD (DBG_FLOW|DBG_LOAD, "amb_reset");
  1511. word = rd_plain (dev, offsetof(amb_mem, reset_control));
  1512. // put card into reset state
  1513. wr_plain (dev, offsetof(amb_mem, reset_control), word | AMB_RESET_BITS);
  1514. // wait a short while
  1515. udelay (10);
  1516. #if 1
  1517. // put card into known good state
  1518. wr_plain (dev, offsetof(amb_mem, interrupt_control), AMB_DOORBELL_BITS);
  1519. // clear all interrupts just in case
  1520. wr_plain (dev, offsetof(amb_mem, interrupt), -1);
  1521. #endif
  1522. // clear self-test done flag
  1523. wr_plain (dev, offsetof(amb_mem, mb.loader.ready), 0);
  1524. // take card out of reset state
  1525. wr_plain (dev, offsetof(amb_mem, reset_control), word &~ AMB_RESET_BITS);
  1526. if (diags) {
  1527. unsigned long timeout;
  1528. // 4.2 second wait
  1529. msleep(4200);
  1530. // half second time-out
  1531. timeout = 500;
  1532. while (!rd_plain (dev, offsetof(amb_mem, mb.loader.ready)))
  1533. if (timeout) {
  1534. timeout = msleep_interruptible(timeout);
  1535. } else {
  1536. PRINTD (DBG_LOAD|DBG_ERR, "reset timed out");
  1537. return -ETIMEDOUT;
  1538. }
  1539. // get results of self-test
  1540. // XXX double check byte-order
  1541. word = rd_mem (dev, offsetof(amb_mem, mb.loader.result));
  1542. if (word & SELF_TEST_FAILURE) {
  1543. if (word & GPINT_TST_FAILURE)
  1544. sf ("interrupt");
  1545. if (word & SUNI_DATA_PATTERN_FAILURE)
  1546. sf ("SUNI data pattern");
  1547. if (word & SUNI_DATA_BITS_FAILURE)
  1548. sf ("SUNI data bits");
  1549. if (word & SUNI_UTOPIA_FAILURE)
  1550. sf ("SUNI UTOPIA interface");
  1551. if (word & SUNI_FIFO_FAILURE)
  1552. sf ("SUNI cell buffer FIFO");
  1553. if (word & SRAM_FAILURE)
  1554. sf ("bad SRAM");
  1555. // better return value?
  1556. return -EIO;
  1557. }
  1558. }
  1559. return 0;
  1560. }
  1561. /********** transfer and start the microcode **********/
  1562. static int __devinit ucode_init (loader_block * lb, amb_dev * dev) {
  1563. unsigned int i = 0;
  1564. unsigned int total = 0;
  1565. const u32 * pointer = ucode_data;
  1566. u32 address;
  1567. unsigned int count;
  1568. int res;
  1569. PRINTD (DBG_FLOW|DBG_LOAD, "ucode_init");
  1570. while (address = ucode_regions[i].start,
  1571. count = ucode_regions[i].count) {
  1572. PRINTD (DBG_LOAD, "starting region (%x, %u)", address, count);
  1573. while (count) {
  1574. unsigned int words;
  1575. if (count <= MAX_TRANSFER_DATA)
  1576. words = count;
  1577. else
  1578. words = MAX_TRANSFER_DATA;
  1579. total += words;
  1580. res = loader_write (lb, dev, pointer, address, words);
  1581. if (res)
  1582. return res;
  1583. res = loader_verify (lb, dev, pointer, address, words);
  1584. if (res)
  1585. return res;
  1586. count -= words;
  1587. address += sizeof(u32) * words;
  1588. pointer += words;
  1589. }
  1590. i += 1;
  1591. }
  1592. if (*pointer == ATM_POISON) {
  1593. return loader_start (lb, dev, ucode_start);
  1594. } else {
  1595. // cast needed as there is no %? for pointer differnces
  1596. PRINTD (DBG_LOAD|DBG_ERR,
  1597. "offset=%li, *pointer=%x, address=%x, total=%u",
  1598. (long) (pointer - ucode_data), *pointer, address, total);
  1599. PRINTK (KERN_ERR, "incorrect microcode data");
  1600. return -ENOMEM;
  1601. }
  1602. }
  1603. /********** give adapter parameters **********/
  1604. static inline __be32 bus_addr(void * addr) {
  1605. return cpu_to_be32 (virt_to_bus (addr));
  1606. }
  1607. static int __devinit amb_talk (amb_dev * dev) {
  1608. adap_talk_block a;
  1609. unsigned char pool;
  1610. unsigned long timeout;
  1611. PRINTD (DBG_FLOW, "amb_talk %p", dev);
  1612. a.command_start = bus_addr (dev->cq.ptrs.start);
  1613. a.command_end = bus_addr (dev->cq.ptrs.limit);
  1614. a.tx_start = bus_addr (dev->txq.in.start);
  1615. a.tx_end = bus_addr (dev->txq.in.limit);
  1616. a.txcom_start = bus_addr (dev->txq.out.start);
  1617. a.txcom_end = bus_addr (dev->txq.out.limit);
  1618. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1619. // the other "a" items are set up by the adapter
  1620. a.rec_struct[pool].buffer_start = bus_addr (dev->rxq[pool].in.start);
  1621. a.rec_struct[pool].buffer_end = bus_addr (dev->rxq[pool].in.limit);
  1622. a.rec_struct[pool].rx_start = bus_addr (dev->rxq[pool].out.start);
  1623. a.rec_struct[pool].rx_end = bus_addr (dev->rxq[pool].out.limit);
  1624. a.rec_struct[pool].buffer_size = cpu_to_be32 (dev->rxq[pool].buffer_size);
  1625. }
  1626. #ifdef AMB_NEW_MICROCODE
  1627. // disable fast PLX prefetching
  1628. a.init_flags = 0;
  1629. #endif
  1630. // pass the structure
  1631. wr_mem (dev, offsetof(amb_mem, doorbell), virt_to_bus (&a));
  1632. // 2.2 second wait (must not touch doorbell during 2 second DMA test)
  1633. msleep(2200);
  1634. // give the adapter another half second?
  1635. timeout = 500;
  1636. while (rd_plain (dev, offsetof(amb_mem, doorbell)))
  1637. if (timeout) {
  1638. timeout = msleep_interruptible(timeout);
  1639. } else {
  1640. PRINTD (DBG_INIT|DBG_ERR, "adapter init timed out");
  1641. return -ETIMEDOUT;
  1642. }
  1643. return 0;
  1644. }
  1645. // get microcode version
  1646. static void __devinit amb_ucode_version (amb_dev * dev) {
  1647. u32 major;
  1648. u32 minor;
  1649. command cmd;
  1650. cmd.request = cpu_to_be32 (SRB_GET_VERSION);
  1651. while (command_do (dev, &cmd)) {
  1652. set_current_state(TASK_UNINTERRUPTIBLE);
  1653. schedule();
  1654. }
  1655. major = be32_to_cpu (cmd.args.version.major);
  1656. minor = be32_to_cpu (cmd.args.version.minor);
  1657. PRINTK (KERN_INFO, "microcode version is %u.%u", major, minor);
  1658. }
  1659. // swap bits within byte to get Ethernet ordering
  1660. static u8 bit_swap (u8 byte)
  1661. {
  1662. const u8 swap[] = {
  1663. 0x0, 0x8, 0x4, 0xc,
  1664. 0x2, 0xa, 0x6, 0xe,
  1665. 0x1, 0x9, 0x5, 0xd,
  1666. 0x3, 0xb, 0x7, 0xf
  1667. };
  1668. return ((swap[byte & 0xf]<<4) | swap[byte>>4]);
  1669. }
  1670. // get end station address
  1671. static void __devinit amb_esi (amb_dev * dev, u8 * esi) {
  1672. u32 lower4;
  1673. u16 upper2;
  1674. command cmd;
  1675. cmd.request = cpu_to_be32 (SRB_GET_BIA);
  1676. while (command_do (dev, &cmd)) {
  1677. set_current_state(TASK_UNINTERRUPTIBLE);
  1678. schedule();
  1679. }
  1680. lower4 = be32_to_cpu (cmd.args.bia.lower4);
  1681. upper2 = be32_to_cpu (cmd.args.bia.upper2);
  1682. PRINTD (DBG_LOAD, "BIA: lower4: %08x, upper2 %04x", lower4, upper2);
  1683. if (esi) {
  1684. unsigned int i;
  1685. PRINTDB (DBG_INIT, "ESI:");
  1686. for (i = 0; i < ESI_LEN; ++i) {
  1687. if (i < 4)
  1688. esi[i] = bit_swap (lower4>>(8*i));
  1689. else
  1690. esi[i] = bit_swap (upper2>>(8*(i-4)));
  1691. PRINTDM (DBG_INIT, " %02x", esi[i]);
  1692. }
  1693. PRINTDE (DBG_INIT, "");
  1694. }
  1695. return;
  1696. }
  1697. static void fixup_plx_window (amb_dev *dev, loader_block *lb)
  1698. {
  1699. // fix up the PLX-mapped window base address to match the block
  1700. unsigned long blb;
  1701. u32 mapreg;
  1702. blb = virt_to_bus(lb);
  1703. // the kernel stack had better not ever cross a 1Gb boundary!
  1704. mapreg = rd_plain (dev, offsetof(amb_mem, stuff[10]));
  1705. mapreg &= ~onegigmask;
  1706. mapreg |= blb & onegigmask;
  1707. wr_plain (dev, offsetof(amb_mem, stuff[10]), mapreg);
  1708. return;
  1709. }
  1710. static int __devinit amb_init (amb_dev * dev)
  1711. {
  1712. loader_block lb;
  1713. u32 version;
  1714. if (amb_reset (dev, 1)) {
  1715. PRINTK (KERN_ERR, "card reset failed!");
  1716. } else {
  1717. fixup_plx_window (dev, &lb);
  1718. if (get_loader_version (&lb, dev, &version)) {
  1719. PRINTK (KERN_INFO, "failed to get loader version");
  1720. } else {
  1721. PRINTK (KERN_INFO, "loader version is %08x", version);
  1722. if (ucode_init (&lb, dev)) {
  1723. PRINTK (KERN_ERR, "microcode failure");
  1724. } else if (create_queues (dev, cmds, txs, rxs, rxs_bs)) {
  1725. PRINTK (KERN_ERR, "failed to get memory for queues");
  1726. } else {
  1727. if (amb_talk (dev)) {
  1728. PRINTK (KERN_ERR, "adapter did not accept queues");
  1729. } else {
  1730. amb_ucode_version (dev);
  1731. return 0;
  1732. } /* amb_talk */
  1733. destroy_queues (dev);
  1734. } /* create_queues, ucode_init */
  1735. amb_reset (dev, 0);
  1736. } /* get_loader_version */
  1737. } /* amb_reset */
  1738. return -EINVAL;
  1739. }
  1740. static void setup_dev(amb_dev *dev, struct pci_dev *pci_dev)
  1741. {
  1742. unsigned char pool;
  1743. memset (dev, 0, sizeof(amb_dev));
  1744. // set up known dev items straight away
  1745. dev->pci_dev = pci_dev;
  1746. pci_set_drvdata(pci_dev, dev);
  1747. dev->iobase = pci_resource_start (pci_dev, 1);
  1748. dev->irq = pci_dev->irq;
  1749. dev->membase = bus_to_virt(pci_resource_start(pci_dev, 0));
  1750. // flags (currently only dead)
  1751. dev->flags = 0;
  1752. // Allocate cell rates (fibre)
  1753. // ATM_OC3_PCR = 1555200000/8/270*260/53 - 29/53
  1754. // to be really pedantic, this should be ATM_OC3c_PCR
  1755. dev->tx_avail = ATM_OC3_PCR;
  1756. dev->rx_avail = ATM_OC3_PCR;
  1757. #ifdef FILL_RX_POOLS_IN_BH
  1758. // initialise bottom half
  1759. INIT_WORK(&dev->bh, (void (*)(void *)) fill_rx_pools, dev);
  1760. #endif
  1761. // semaphore for txer/rxer modifications - we cannot use a
  1762. // spinlock as the critical region needs to switch processes
  1763. init_MUTEX (&dev->vcc_sf);
  1764. // queue manipulation spinlocks; we want atomic reads and
  1765. // writes to the queue descriptors (handles IRQ and SMP)
  1766. // consider replacing "int pending" -> "atomic_t available"
  1767. // => problem related to who gets to move queue pointers
  1768. spin_lock_init (&dev->cq.lock);
  1769. spin_lock_init (&dev->txq.lock);
  1770. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1771. spin_lock_init (&dev->rxq[pool].lock);
  1772. }
  1773. static void setup_pci_dev(struct pci_dev *pci_dev)
  1774. {
  1775. unsigned char lat;
  1776. // enable bus master accesses
  1777. pci_set_master(pci_dev);
  1778. // frobnicate latency (upwards, usually)
  1779. pci_read_config_byte (pci_dev, PCI_LATENCY_TIMER, &lat);
  1780. if (!pci_lat)
  1781. pci_lat = (lat < MIN_PCI_LATENCY) ? MIN_PCI_LATENCY : lat;
  1782. if (lat != pci_lat) {
  1783. PRINTK (KERN_INFO, "Changing PCI latency timer from %hu to %hu",
  1784. lat, pci_lat);
  1785. pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, pci_lat);
  1786. }
  1787. }
  1788. static int __devinit amb_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
  1789. {
  1790. amb_dev * dev;
  1791. int err;
  1792. unsigned int irq;
  1793. err = pci_enable_device(pci_dev);
  1794. if (err < 0) {
  1795. PRINTK (KERN_ERR, "skipped broken (PLX rev 2) card");
  1796. goto out;
  1797. }
  1798. // read resources from PCI configuration space
  1799. irq = pci_dev->irq;
  1800. if (pci_dev->device == PCI_DEVICE_ID_MADGE_AMBASSADOR_BAD) {
  1801. PRINTK (KERN_ERR, "skipped broken (PLX rev 2) card");
  1802. err = -EINVAL;
  1803. goto out_disable;
  1804. }
  1805. PRINTD (DBG_INFO, "found Madge ATM adapter (amb) at"
  1806. " IO %llx, IRQ %u, MEM %p",
  1807. (unsigned long long)pci_resource_start(pci_dev, 1),
  1808. irq, bus_to_virt(pci_resource_start(pci_dev, 0)));
  1809. // check IO region
  1810. err = pci_request_region(pci_dev, 1, DEV_LABEL);
  1811. if (err < 0) {
  1812. PRINTK (KERN_ERR, "IO range already in use!");
  1813. goto out_disable;
  1814. }
  1815. dev = kmalloc (sizeof(amb_dev), GFP_KERNEL);
  1816. if (!dev) {
  1817. PRINTK (KERN_ERR, "out of memory!");
  1818. err = -ENOMEM;
  1819. goto out_release;
  1820. }
  1821. setup_dev(dev, pci_dev);
  1822. err = amb_init(dev);
  1823. if (err < 0) {
  1824. PRINTK (KERN_ERR, "adapter initialisation failure");
  1825. goto out_free;
  1826. }
  1827. setup_pci_dev(pci_dev);
  1828. // grab (but share) IRQ and install handler
  1829. err = request_irq(irq, interrupt_handler, IRQF_SHARED, DEV_LABEL, dev);
  1830. if (err < 0) {
  1831. PRINTK (KERN_ERR, "request IRQ failed!");
  1832. goto out_reset;
  1833. }
  1834. dev->atm_dev = atm_dev_register (DEV_LABEL, &amb_ops, -1, NULL);
  1835. if (!dev->atm_dev) {
  1836. PRINTD (DBG_ERR, "failed to register Madge ATM adapter");
  1837. err = -EINVAL;
  1838. goto out_free_irq;
  1839. }
  1840. PRINTD (DBG_INFO, "registered Madge ATM adapter (no. %d) (%p) at %p",
  1841. dev->atm_dev->number, dev, dev->atm_dev);
  1842. dev->atm_dev->dev_data = (void *) dev;
  1843. // register our address
  1844. amb_esi (dev, dev->atm_dev->esi);
  1845. // 0 bits for vpi, 10 bits for vci
  1846. dev->atm_dev->ci_range.vpi_bits = NUM_VPI_BITS;
  1847. dev->atm_dev->ci_range.vci_bits = NUM_VCI_BITS;
  1848. init_timer(&dev->housekeeping);
  1849. dev->housekeeping.function = do_housekeeping;
  1850. dev->housekeeping.data = (unsigned long) dev;
  1851. mod_timer(&dev->housekeeping, jiffies);
  1852. // enable host interrupts
  1853. interrupts_on (dev);
  1854. out:
  1855. return err;
  1856. out_free_irq:
  1857. free_irq(irq, dev);
  1858. out_reset:
  1859. amb_reset(dev, 0);
  1860. out_free:
  1861. kfree(dev);
  1862. out_release:
  1863. pci_release_region(pci_dev, 1);
  1864. out_disable:
  1865. pci_disable_device(pci_dev);
  1866. goto out;
  1867. }
  1868. static void __devexit amb_remove_one(struct pci_dev *pci_dev)
  1869. {
  1870. struct amb_dev *dev;
  1871. dev = pci_get_drvdata(pci_dev);
  1872. PRINTD(DBG_INFO|DBG_INIT, "closing %p (atm_dev = %p)", dev, dev->atm_dev);
  1873. del_timer_sync(&dev->housekeeping);
  1874. // the drain should not be necessary
  1875. drain_rx_pools(dev);
  1876. interrupts_off(dev);
  1877. amb_reset(dev, 0);
  1878. free_irq(dev->irq, dev);
  1879. pci_disable_device(pci_dev);
  1880. destroy_queues(dev);
  1881. atm_dev_deregister(dev->atm_dev);
  1882. kfree(dev);
  1883. pci_release_region(pci_dev, 1);
  1884. }
  1885. static void __init amb_check_args (void) {
  1886. unsigned char pool;
  1887. unsigned int max_rx_size;
  1888. #ifdef DEBUG_AMBASSADOR
  1889. PRINTK (KERN_NOTICE, "debug bitmap is %hx", debug &= DBG_MASK);
  1890. #else
  1891. if (debug)
  1892. PRINTK (KERN_NOTICE, "no debugging support");
  1893. #endif
  1894. if (cmds < MIN_QUEUE_SIZE)
  1895. PRINTK (KERN_NOTICE, "cmds has been raised to %u",
  1896. cmds = MIN_QUEUE_SIZE);
  1897. if (txs < MIN_QUEUE_SIZE)
  1898. PRINTK (KERN_NOTICE, "txs has been raised to %u",
  1899. txs = MIN_QUEUE_SIZE);
  1900. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1901. if (rxs[pool] < MIN_QUEUE_SIZE)
  1902. PRINTK (KERN_NOTICE, "rxs[%hu] has been raised to %u",
  1903. pool, rxs[pool] = MIN_QUEUE_SIZE);
  1904. // buffers sizes should be greater than zero and strictly increasing
  1905. max_rx_size = 0;
  1906. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1907. if (rxs_bs[pool] <= max_rx_size)
  1908. PRINTK (KERN_NOTICE, "useless pool (rxs_bs[%hu] = %u)",
  1909. pool, rxs_bs[pool]);
  1910. else
  1911. max_rx_size = rxs_bs[pool];
  1912. if (rx_lats < MIN_RX_BUFFERS)
  1913. PRINTK (KERN_NOTICE, "rx_lats has been raised to %u",
  1914. rx_lats = MIN_RX_BUFFERS);
  1915. return;
  1916. }
  1917. /********** module stuff **********/
  1918. MODULE_AUTHOR(maintainer_string);
  1919. MODULE_DESCRIPTION(description_string);
  1920. MODULE_LICENSE("GPL");
  1921. module_param(debug, ushort, 0644);
  1922. module_param(cmds, uint, 0);
  1923. module_param(txs, uint, 0);
  1924. module_param_array(rxs, uint, NULL, 0);
  1925. module_param_array(rxs_bs, uint, NULL, 0);
  1926. module_param(rx_lats, uint, 0);
  1927. module_param(pci_lat, byte, 0);
  1928. MODULE_PARM_DESC(debug, "debug bitmap, see .h file");
  1929. MODULE_PARM_DESC(cmds, "number of command queue entries");
  1930. MODULE_PARM_DESC(txs, "number of TX queue entries");
  1931. MODULE_PARM_DESC(rxs, "number of RX queue entries [" __MODULE_STRING(NUM_RX_POOLS) "]");
  1932. MODULE_PARM_DESC(rxs_bs, "size of RX buffers [" __MODULE_STRING(NUM_RX_POOLS) "]");
  1933. MODULE_PARM_DESC(rx_lats, "number of extra buffers to cope with RX latencies");
  1934. MODULE_PARM_DESC(pci_lat, "PCI latency in bus cycles");
  1935. /********** module entry **********/
  1936. static struct pci_device_id amb_pci_tbl[] = {
  1937. { PCI_VENDOR_ID_MADGE, PCI_DEVICE_ID_MADGE_AMBASSADOR, PCI_ANY_ID, PCI_ANY_ID,
  1938. 0, 0, 0 },
  1939. { PCI_VENDOR_ID_MADGE, PCI_DEVICE_ID_MADGE_AMBASSADOR_BAD, PCI_ANY_ID, PCI_ANY_ID,
  1940. 0, 0, 0 },
  1941. { 0, }
  1942. };
  1943. MODULE_DEVICE_TABLE(pci, amb_pci_tbl);
  1944. static struct pci_driver amb_driver = {
  1945. .name = "amb",
  1946. .probe = amb_probe,
  1947. .remove = __devexit_p(amb_remove_one),
  1948. .id_table = amb_pci_tbl,
  1949. };
  1950. static int __init amb_module_init (void)
  1951. {
  1952. PRINTD (DBG_FLOW|DBG_INIT, "init_module");
  1953. // sanity check - cast needed as printk does not support %Zu
  1954. if (sizeof(amb_mem) != 4*16 + 4*12) {
  1955. PRINTK (KERN_ERR, "Fix amb_mem (is %lu words).",
  1956. (unsigned long) sizeof(amb_mem));
  1957. return -ENOMEM;
  1958. }
  1959. show_version();
  1960. amb_check_args();
  1961. // get the juice
  1962. return pci_register_driver(&amb_driver);
  1963. }
  1964. /********** module exit **********/
  1965. static void __exit amb_module_exit (void)
  1966. {
  1967. PRINTD (DBG_FLOW|DBG_INIT, "cleanup_module");
  1968. pci_unregister_driver(&amb_driver);
  1969. }
  1970. module_init(amb_module_init);
  1971. module_exit(amb_module_exit);