ambassador.c 67 KB

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