ambassador.c 67 KB

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