ambassador.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422
  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 <linux/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_offset(skb));
  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
  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. fill_rx_pools (dev);
  670. PRINTD (DBG_IRQ, "work done: %u", irq_work);
  671. } else {
  672. PRINTD (DBG_IRQ|DBG_WARN, "no work done");
  673. }
  674. }
  675. PRINTD (DBG_IRQ|DBG_FLOW, "interrupt_handler done: %p", dev_id);
  676. return IRQ_HANDLED;
  677. }
  678. /********** make rate (not quite as much fun as Horizon) **********/
  679. static int make_rate (unsigned int rate, rounding r,
  680. u16 * bits, unsigned int * actual) {
  681. unsigned char exp = -1; // hush gcc
  682. unsigned int man = -1; // hush gcc
  683. PRINTD (DBG_FLOW|DBG_QOS, "make_rate %u", rate);
  684. // rates in cells per second, ITU format (nasty 16-bit floating-point)
  685. // given 5-bit e and 9-bit m:
  686. // rate = EITHER (1+m/2^9)*2^e OR 0
  687. // bits = EITHER 1<<14 | e<<9 | m OR 0
  688. // (bit 15 is "reserved", bit 14 "non-zero")
  689. // smallest rate is 0 (special representation)
  690. // largest rate is (1+511/512)*2^31 = 4290772992 (< 2^32-1)
  691. // smallest non-zero rate is (1+0/512)*2^0 = 1 (> 0)
  692. // simple algorithm:
  693. // find position of top bit, this gives e
  694. // remove top bit and shift (rounding if feeling clever) by 9-e
  695. // ucode bug: please don't set bit 14! so 0 rate not representable
  696. if (rate > 0xffc00000U) {
  697. // larger than largest representable rate
  698. if (r == round_up) {
  699. return -EINVAL;
  700. } else {
  701. exp = 31;
  702. man = 511;
  703. }
  704. } else if (rate) {
  705. // representable rate
  706. exp = 31;
  707. man = rate;
  708. // invariant: rate = man*2^(exp-31)
  709. while (!(man & (1<<31))) {
  710. exp = exp - 1;
  711. man = man<<1;
  712. }
  713. // man has top bit set
  714. // rate = (2^31+(man-2^31))*2^(exp-31)
  715. // rate = (1+(man-2^31)/2^31)*2^exp
  716. man = man<<1;
  717. man &= 0xffffffffU; // a nop on 32-bit systems
  718. // rate = (1+man/2^32)*2^exp
  719. // exp is in the range 0 to 31, man is in the range 0 to 2^32-1
  720. // time to lose significance... we want m in the range 0 to 2^9-1
  721. // rounding presents a minor problem... we first decide which way
  722. // we are rounding (based on given rounding direction and possibly
  723. // the bits of the mantissa that are to be discarded).
  724. switch (r) {
  725. case round_down: {
  726. // just truncate
  727. man = man>>(32-9);
  728. break;
  729. }
  730. case round_up: {
  731. // check all bits that we are discarding
  732. if (man & (~0U>>9)) {
  733. man = (man>>(32-9)) + 1;
  734. if (man == (1<<9)) {
  735. // no need to check for round up outside of range
  736. man = 0;
  737. exp += 1;
  738. }
  739. } else {
  740. man = (man>>(32-9));
  741. }
  742. break;
  743. }
  744. case round_nearest: {
  745. // check msb that we are discarding
  746. if (man & (1<<(32-9-1))) {
  747. man = (man>>(32-9)) + 1;
  748. if (man == (1<<9)) {
  749. // no need to check for round up outside of range
  750. man = 0;
  751. exp += 1;
  752. }
  753. } else {
  754. man = (man>>(32-9));
  755. }
  756. break;
  757. }
  758. }
  759. } else {
  760. // zero rate - not representable
  761. if (r == round_down) {
  762. return -EINVAL;
  763. } else {
  764. exp = 0;
  765. man = 0;
  766. }
  767. }
  768. PRINTD (DBG_QOS, "rate: man=%u, exp=%hu", man, exp);
  769. if (bits)
  770. *bits = /* (1<<14) | */ (exp<<9) | man;
  771. if (actual)
  772. *actual = (exp >= 9)
  773. ? (1 << exp) + (man << (exp-9))
  774. : (1 << exp) + ((man + (1<<(9-exp-1))) >> (9-exp));
  775. return 0;
  776. }
  777. /********** Linux ATM Operations **********/
  778. // some are not yet implemented while others do not make sense for
  779. // this device
  780. /********** Open a VC **********/
  781. static int amb_open (struct atm_vcc * atm_vcc)
  782. {
  783. int error;
  784. struct atm_qos * qos;
  785. struct atm_trafprm * txtp;
  786. struct atm_trafprm * rxtp;
  787. u16 tx_rate_bits = -1; // hush gcc
  788. u16 tx_vc_bits = -1; // hush gcc
  789. u16 tx_frame_bits = -1; // hush gcc
  790. amb_dev * dev = AMB_DEV(atm_vcc->dev);
  791. amb_vcc * vcc;
  792. unsigned char pool = -1; // hush gcc
  793. short vpi = atm_vcc->vpi;
  794. int vci = atm_vcc->vci;
  795. PRINTD (DBG_FLOW|DBG_VCC, "amb_open %x %x", vpi, vci);
  796. #ifdef ATM_VPI_UNSPEC
  797. // UNSPEC is deprecated, remove this code eventually
  798. if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) {
  799. PRINTK (KERN_WARNING, "rejecting open with unspecified VPI/VCI (deprecated)");
  800. return -EINVAL;
  801. }
  802. #endif
  803. if (!(0 <= vpi && vpi < (1<<NUM_VPI_BITS) &&
  804. 0 <= vci && vci < (1<<NUM_VCI_BITS))) {
  805. PRINTD (DBG_WARN|DBG_VCC, "VPI/VCI out of range: %hd/%d", vpi, vci);
  806. return -EINVAL;
  807. }
  808. qos = &atm_vcc->qos;
  809. if (qos->aal != ATM_AAL5) {
  810. PRINTD (DBG_QOS, "AAL not supported");
  811. return -EINVAL;
  812. }
  813. // traffic parameters
  814. PRINTD (DBG_QOS, "TX:");
  815. txtp = &qos->txtp;
  816. if (txtp->traffic_class != ATM_NONE) {
  817. switch (txtp->traffic_class) {
  818. case ATM_UBR: {
  819. // we take "the PCR" as a rate-cap
  820. int pcr = atm_pcr_goal (txtp);
  821. if (!pcr) {
  822. // no rate cap
  823. tx_rate_bits = 0;
  824. tx_vc_bits = TX_UBR;
  825. tx_frame_bits = TX_FRAME_NOTCAP;
  826. } else {
  827. rounding r;
  828. if (pcr < 0) {
  829. r = round_down;
  830. pcr = -pcr;
  831. } else {
  832. r = round_up;
  833. }
  834. error = make_rate (pcr, r, &tx_rate_bits, NULL);
  835. if (error)
  836. return error;
  837. tx_vc_bits = TX_UBR_CAPPED;
  838. tx_frame_bits = TX_FRAME_CAPPED;
  839. }
  840. break;
  841. }
  842. #if 0
  843. case ATM_ABR: {
  844. pcr = atm_pcr_goal (txtp);
  845. PRINTD (DBG_QOS, "pcr goal = %d", pcr);
  846. break;
  847. }
  848. #endif
  849. default: {
  850. // PRINTD (DBG_QOS, "request for non-UBR/ABR denied");
  851. PRINTD (DBG_QOS, "request for non-UBR denied");
  852. return -EINVAL;
  853. }
  854. }
  855. PRINTD (DBG_QOS, "tx_rate_bits=%hx, tx_vc_bits=%hx",
  856. tx_rate_bits, tx_vc_bits);
  857. }
  858. PRINTD (DBG_QOS, "RX:");
  859. rxtp = &qos->rxtp;
  860. if (rxtp->traffic_class == ATM_NONE) {
  861. // do nothing
  862. } else {
  863. // choose an RX pool (arranged in increasing size)
  864. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  865. if ((unsigned int) rxtp->max_sdu <= dev->rxq[pool].buffer_size) {
  866. PRINTD (DBG_VCC|DBG_QOS|DBG_POOL, "chose pool %hu (max_sdu %u <= %u)",
  867. pool, rxtp->max_sdu, dev->rxq[pool].buffer_size);
  868. break;
  869. }
  870. if (pool == NUM_RX_POOLS) {
  871. PRINTD (DBG_WARN|DBG_VCC|DBG_QOS|DBG_POOL,
  872. "no pool suitable for VC (RX max_sdu %d is too large)",
  873. rxtp->max_sdu);
  874. return -EINVAL;
  875. }
  876. switch (rxtp->traffic_class) {
  877. case ATM_UBR: {
  878. break;
  879. }
  880. #if 0
  881. case ATM_ABR: {
  882. pcr = atm_pcr_goal (rxtp);
  883. PRINTD (DBG_QOS, "pcr goal = %d", pcr);
  884. break;
  885. }
  886. #endif
  887. default: {
  888. // PRINTD (DBG_QOS, "request for non-UBR/ABR denied");
  889. PRINTD (DBG_QOS, "request for non-UBR denied");
  890. return -EINVAL;
  891. }
  892. }
  893. }
  894. // get space for our vcc stuff
  895. vcc = kmalloc (sizeof(amb_vcc), GFP_KERNEL);
  896. if (!vcc) {
  897. PRINTK (KERN_ERR, "out of memory!");
  898. return -ENOMEM;
  899. }
  900. atm_vcc->dev_data = (void *) vcc;
  901. // no failures beyond this point
  902. // we are not really "immediately before allocating the connection
  903. // identifier in hardware", but it will just have to do!
  904. set_bit(ATM_VF_ADDR,&atm_vcc->flags);
  905. if (txtp->traffic_class != ATM_NONE) {
  906. command cmd;
  907. vcc->tx_frame_bits = tx_frame_bits;
  908. mutex_lock(&dev->vcc_sf);
  909. if (dev->rxer[vci]) {
  910. // RXer on the channel already, just modify rate...
  911. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
  912. cmd.args.modify_rate.vc = cpu_to_be32 (vci); // vpi 0
  913. cmd.args.modify_rate.rate = cpu_to_be32 (tx_rate_bits << SRB_RATE_SHIFT);
  914. while (command_do (dev, &cmd))
  915. schedule();
  916. // ... and TX flags, preserving the RX pool
  917. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  918. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  919. cmd.args.modify_flags.flags = cpu_to_be32
  920. ( (AMB_VCC(dev->rxer[vci])->rx_info.pool << SRB_POOL_SHIFT)
  921. | (tx_vc_bits << SRB_FLAGS_SHIFT) );
  922. while (command_do (dev, &cmd))
  923. schedule();
  924. } else {
  925. // no RXer on the channel, just open (with pool zero)
  926. cmd.request = cpu_to_be32 (SRB_OPEN_VC);
  927. cmd.args.open.vc = cpu_to_be32 (vci); // vpi 0
  928. cmd.args.open.flags = cpu_to_be32 (tx_vc_bits << SRB_FLAGS_SHIFT);
  929. cmd.args.open.rate = cpu_to_be32 (tx_rate_bits << SRB_RATE_SHIFT);
  930. while (command_do (dev, &cmd))
  931. schedule();
  932. }
  933. dev->txer[vci].tx_present = 1;
  934. mutex_unlock(&dev->vcc_sf);
  935. }
  936. if (rxtp->traffic_class != ATM_NONE) {
  937. command cmd;
  938. vcc->rx_info.pool = pool;
  939. mutex_lock(&dev->vcc_sf);
  940. /* grow RX buffer pool */
  941. if (!dev->rxq[pool].buffers_wanted)
  942. dev->rxq[pool].buffers_wanted = rx_lats;
  943. dev->rxq[pool].buffers_wanted += 1;
  944. fill_rx_pool (dev, pool, GFP_KERNEL);
  945. if (dev->txer[vci].tx_present) {
  946. // TXer on the channel already
  947. // switch (from pool zero) to this pool, preserving the TX bits
  948. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  949. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  950. cmd.args.modify_flags.flags = cpu_to_be32
  951. ( (pool << SRB_POOL_SHIFT)
  952. | (dev->txer[vci].tx_vc_bits << SRB_FLAGS_SHIFT) );
  953. } else {
  954. // no TXer on the channel, open the VC (with no rate info)
  955. cmd.request = cpu_to_be32 (SRB_OPEN_VC);
  956. cmd.args.open.vc = cpu_to_be32 (vci); // vpi 0
  957. cmd.args.open.flags = cpu_to_be32 (pool << SRB_POOL_SHIFT);
  958. cmd.args.open.rate = cpu_to_be32 (0);
  959. }
  960. while (command_do (dev, &cmd))
  961. schedule();
  962. // this link allows RX frames through
  963. dev->rxer[vci] = atm_vcc;
  964. mutex_unlock(&dev->vcc_sf);
  965. }
  966. // indicate readiness
  967. set_bit(ATM_VF_READY,&atm_vcc->flags);
  968. return 0;
  969. }
  970. /********** Close a VC **********/
  971. static void amb_close (struct atm_vcc * atm_vcc) {
  972. amb_dev * dev = AMB_DEV (atm_vcc->dev);
  973. amb_vcc * vcc = AMB_VCC (atm_vcc);
  974. u16 vci = atm_vcc->vci;
  975. PRINTD (DBG_VCC|DBG_FLOW, "amb_close");
  976. // indicate unreadiness
  977. clear_bit(ATM_VF_READY,&atm_vcc->flags);
  978. // disable TXing
  979. if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) {
  980. command cmd;
  981. mutex_lock(&dev->vcc_sf);
  982. if (dev->rxer[vci]) {
  983. // RXer still on the channel, just modify rate... XXX not really needed
  984. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
  985. cmd.args.modify_rate.vc = cpu_to_be32 (vci); // vpi 0
  986. cmd.args.modify_rate.rate = cpu_to_be32 (0);
  987. // ... and clear TX rate flags (XXX to stop RM cell output?), preserving RX pool
  988. } else {
  989. // no RXer on the channel, close channel
  990. cmd.request = cpu_to_be32 (SRB_CLOSE_VC);
  991. cmd.args.close.vc = cpu_to_be32 (vci); // vpi 0
  992. }
  993. dev->txer[vci].tx_present = 0;
  994. while (command_do (dev, &cmd))
  995. schedule();
  996. mutex_unlock(&dev->vcc_sf);
  997. }
  998. // disable RXing
  999. if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1000. command cmd;
  1001. // this is (the?) one reason why we need the amb_vcc struct
  1002. unsigned char pool = vcc->rx_info.pool;
  1003. mutex_lock(&dev->vcc_sf);
  1004. if (dev->txer[vci].tx_present) {
  1005. // TXer still on the channel, just go to pool zero XXX not really needed
  1006. cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
  1007. cmd.args.modify_flags.vc = cpu_to_be32 (vci); // vpi 0
  1008. cmd.args.modify_flags.flags = cpu_to_be32
  1009. (dev->txer[vci].tx_vc_bits << SRB_FLAGS_SHIFT);
  1010. } else {
  1011. // no TXer on the channel, close the VC
  1012. cmd.request = cpu_to_be32 (SRB_CLOSE_VC);
  1013. cmd.args.close.vc = cpu_to_be32 (vci); // vpi 0
  1014. }
  1015. // forget the rxer - no more skbs will be pushed
  1016. if (atm_vcc != dev->rxer[vci])
  1017. PRINTK (KERN_ERR, "%s vcc=%p rxer[vci]=%p",
  1018. "arghhh! we're going to die!",
  1019. vcc, dev->rxer[vci]);
  1020. dev->rxer[vci] = NULL;
  1021. while (command_do (dev, &cmd))
  1022. schedule();
  1023. /* shrink RX buffer pool */
  1024. dev->rxq[pool].buffers_wanted -= 1;
  1025. if (dev->rxq[pool].buffers_wanted == rx_lats) {
  1026. dev->rxq[pool].buffers_wanted = 0;
  1027. drain_rx_pool (dev, pool);
  1028. }
  1029. mutex_unlock(&dev->vcc_sf);
  1030. }
  1031. // free our structure
  1032. kfree (vcc);
  1033. // say the VPI/VCI is free again
  1034. clear_bit(ATM_VF_ADDR,&atm_vcc->flags);
  1035. return;
  1036. }
  1037. /********** Send **********/
  1038. static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
  1039. amb_dev * dev = AMB_DEV(atm_vcc->dev);
  1040. amb_vcc * vcc = AMB_VCC(atm_vcc);
  1041. u16 vc = atm_vcc->vci;
  1042. unsigned int tx_len = skb->len;
  1043. unsigned char * tx_data = skb->data;
  1044. tx_simple * tx_descr;
  1045. tx_in tx;
  1046. if (test_bit (dead, &dev->flags))
  1047. return -EIO;
  1048. PRINTD (DBG_FLOW|DBG_TX, "amb_send vc %x data %p len %u",
  1049. vc, tx_data, tx_len);
  1050. dump_skb (">>>", vc, skb);
  1051. if (!dev->txer[vc].tx_present) {
  1052. PRINTK (KERN_ERR, "attempt to send on RX-only VC %x", vc);
  1053. return -EBADFD;
  1054. }
  1055. // this is a driver private field so we have to set it ourselves,
  1056. // despite the fact that we are _required_ to use it to check for a
  1057. // pop function
  1058. ATM_SKB(skb)->vcc = atm_vcc;
  1059. if (skb->len > (size_t) atm_vcc->qos.txtp.max_sdu) {
  1060. PRINTK (KERN_ERR, "sk_buff length greater than agreed max_sdu, dropping...");
  1061. return -EIO;
  1062. }
  1063. if (check_area (skb->data, skb->len)) {
  1064. atomic_inc(&atm_vcc->stats->tx_err);
  1065. return -ENOMEM; // ?
  1066. }
  1067. // allocate memory for fragments
  1068. tx_descr = kmalloc (sizeof(tx_simple), GFP_KERNEL);
  1069. if (!tx_descr) {
  1070. PRINTK (KERN_ERR, "could not allocate TX descriptor");
  1071. return -ENOMEM;
  1072. }
  1073. if (check_area (tx_descr, sizeof(tx_simple))) {
  1074. kfree (tx_descr);
  1075. return -ENOMEM;
  1076. }
  1077. PRINTD (DBG_TX, "fragment list allocated at %p", tx_descr);
  1078. tx_descr->skb = skb;
  1079. tx_descr->tx_frag.bytes = cpu_to_be32 (tx_len);
  1080. tx_descr->tx_frag.address = cpu_to_be32 (virt_to_bus (tx_data));
  1081. tx_descr->tx_frag_end.handle = virt_to_bus (tx_descr);
  1082. tx_descr->tx_frag_end.vc = 0;
  1083. tx_descr->tx_frag_end.next_descriptor_length = 0;
  1084. tx_descr->tx_frag_end.next_descriptor = 0;
  1085. #ifdef AMB_NEW_MICROCODE
  1086. tx_descr->tx_frag_end.cpcs_uu = 0;
  1087. tx_descr->tx_frag_end.cpi = 0;
  1088. tx_descr->tx_frag_end.pad = 0;
  1089. #endif
  1090. tx.vc = cpu_to_be16 (vcc->tx_frame_bits | vc);
  1091. tx.tx_descr_length = cpu_to_be16 (sizeof(tx_frag)+sizeof(tx_frag_end));
  1092. tx.tx_descr_addr = cpu_to_be32 (virt_to_bus (&tx_descr->tx_frag));
  1093. while (tx_give (dev, &tx))
  1094. schedule();
  1095. return 0;
  1096. }
  1097. /********** Change QoS on a VC **********/
  1098. // int amb_change_qos (struct atm_vcc * atm_vcc, struct atm_qos * qos, int flags);
  1099. /********** Free RX Socket Buffer **********/
  1100. #if 0
  1101. static void amb_free_rx_skb (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
  1102. amb_dev * dev = AMB_DEV (atm_vcc->dev);
  1103. amb_vcc * vcc = AMB_VCC (atm_vcc);
  1104. unsigned char pool = vcc->rx_info.pool;
  1105. rx_in rx;
  1106. // This may be unsafe for various reasons that I cannot really guess
  1107. // at. However, I note that the ATM layer calls kfree_skb rather
  1108. // than dev_kfree_skb at this point so we are least covered as far
  1109. // as buffer locking goes. There may be bugs if pcap clones RX skbs.
  1110. PRINTD (DBG_FLOW|DBG_SKB, "amb_rx_free skb %p (atm_vcc %p, vcc %p)",
  1111. skb, atm_vcc, vcc);
  1112. rx.handle = virt_to_bus (skb);
  1113. rx.host_address = cpu_to_be32 (virt_to_bus (skb->data));
  1114. skb->data = skb->head;
  1115. skb_reset_tail_pointer(skb);
  1116. skb->len = 0;
  1117. if (!rx_give (dev, &rx, pool)) {
  1118. // success
  1119. PRINTD (DBG_SKB|DBG_POOL, "recycled skb for pool %hu", pool);
  1120. return;
  1121. }
  1122. // just do what the ATM layer would have done
  1123. dev_kfree_skb_any (skb);
  1124. return;
  1125. }
  1126. #endif
  1127. /********** Proc File Output **********/
  1128. static int amb_proc_read (struct atm_dev * atm_dev, loff_t * pos, char * page) {
  1129. amb_dev * dev = AMB_DEV (atm_dev);
  1130. int left = *pos;
  1131. unsigned char pool;
  1132. PRINTD (DBG_FLOW, "amb_proc_read");
  1133. /* more diagnostics here? */
  1134. if (!left--) {
  1135. amb_stats * s = &dev->stats;
  1136. return sprintf (page,
  1137. "frames: TX OK %lu, RX OK %lu, RX bad %lu "
  1138. "(CRC %lu, long %lu, aborted %lu, unused %lu).\n",
  1139. s->tx_ok, s->rx.ok, s->rx.error,
  1140. s->rx.badcrc, s->rx.toolong,
  1141. s->rx.aborted, s->rx.unused);
  1142. }
  1143. if (!left--) {
  1144. amb_cq * c = &dev->cq;
  1145. return sprintf (page, "cmd queue [cur/hi/max]: %u/%u/%u. ",
  1146. c->pending, c->high, c->maximum);
  1147. }
  1148. if (!left--) {
  1149. amb_txq * t = &dev->txq;
  1150. return sprintf (page, "TX queue [cur/max high full]: %u/%u %u %u.\n",
  1151. t->pending, t->maximum, t->high, t->filled);
  1152. }
  1153. if (!left--) {
  1154. unsigned int count = sprintf (page, "RX queues [cur/max/req low empty]:");
  1155. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1156. amb_rxq * r = &dev->rxq[pool];
  1157. count += sprintf (page+count, " %u/%u/%u %u %u",
  1158. r->pending, r->maximum, r->buffers_wanted, r->low, r->emptied);
  1159. }
  1160. count += sprintf (page+count, ".\n");
  1161. return count;
  1162. }
  1163. if (!left--) {
  1164. unsigned int count = sprintf (page, "RX buffer sizes:");
  1165. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1166. amb_rxq * r = &dev->rxq[pool];
  1167. count += sprintf (page+count, " %u", r->buffer_size);
  1168. }
  1169. count += sprintf (page+count, ".\n");
  1170. return count;
  1171. }
  1172. #if 0
  1173. if (!left--) {
  1174. // suni block etc?
  1175. }
  1176. #endif
  1177. return 0;
  1178. }
  1179. /********** Operation Structure **********/
  1180. static const struct atmdev_ops amb_ops = {
  1181. .open = amb_open,
  1182. .close = amb_close,
  1183. .send = amb_send,
  1184. .proc_read = amb_proc_read,
  1185. .owner = THIS_MODULE,
  1186. };
  1187. /********** housekeeping **********/
  1188. static void do_housekeeping (unsigned long arg) {
  1189. amb_dev * dev = (amb_dev *) arg;
  1190. // could collect device-specific (not driver/atm-linux) stats here
  1191. // last resort refill once every ten seconds
  1192. fill_rx_pools (dev);
  1193. mod_timer(&dev->housekeeping, jiffies + 10*HZ);
  1194. return;
  1195. }
  1196. /********** creation of communication queues **********/
  1197. static int create_queues(amb_dev *dev, unsigned int cmds, unsigned int txs,
  1198. unsigned int *rxs, unsigned int *rx_buffer_sizes)
  1199. {
  1200. unsigned char pool;
  1201. size_t total = 0;
  1202. void * memory;
  1203. void * limit;
  1204. PRINTD (DBG_FLOW, "create_queues %p", dev);
  1205. total += cmds * sizeof(command);
  1206. total += txs * (sizeof(tx_in) + sizeof(tx_out));
  1207. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1208. total += rxs[pool] * (sizeof(rx_in) + sizeof(rx_out));
  1209. memory = kmalloc (total, GFP_KERNEL);
  1210. if (!memory) {
  1211. PRINTK (KERN_ERR, "could not allocate queues");
  1212. return -ENOMEM;
  1213. }
  1214. if (check_area (memory, total)) {
  1215. PRINTK (KERN_ERR, "queues allocated in nasty area");
  1216. kfree (memory);
  1217. return -ENOMEM;
  1218. }
  1219. limit = memory + total;
  1220. PRINTD (DBG_INIT, "queues from %p to %p", memory, limit);
  1221. PRINTD (DBG_CMD, "command queue at %p", memory);
  1222. {
  1223. command * cmd = memory;
  1224. amb_cq * cq = &dev->cq;
  1225. cq->pending = 0;
  1226. cq->high = 0;
  1227. cq->maximum = cmds - 1;
  1228. cq->ptrs.start = cmd;
  1229. cq->ptrs.in = cmd;
  1230. cq->ptrs.out = cmd;
  1231. cq->ptrs.limit = cmd + cmds;
  1232. memory = cq->ptrs.limit;
  1233. }
  1234. PRINTD (DBG_TX, "TX queue pair at %p", memory);
  1235. {
  1236. tx_in * in = memory;
  1237. tx_out * out;
  1238. amb_txq * txq = &dev->txq;
  1239. txq->pending = 0;
  1240. txq->high = 0;
  1241. txq->filled = 0;
  1242. txq->maximum = txs - 1;
  1243. txq->in.start = in;
  1244. txq->in.ptr = in;
  1245. txq->in.limit = in + txs;
  1246. memory = txq->in.limit;
  1247. out = memory;
  1248. txq->out.start = out;
  1249. txq->out.ptr = out;
  1250. txq->out.limit = out + txs;
  1251. memory = txq->out.limit;
  1252. }
  1253. PRINTD (DBG_RX, "RX queue pairs at %p", memory);
  1254. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1255. rx_in * in = memory;
  1256. rx_out * out;
  1257. amb_rxq * rxq = &dev->rxq[pool];
  1258. rxq->buffer_size = rx_buffer_sizes[pool];
  1259. rxq->buffers_wanted = 0;
  1260. rxq->pending = 0;
  1261. rxq->low = rxs[pool] - 1;
  1262. rxq->emptied = 0;
  1263. rxq->maximum = rxs[pool] - 1;
  1264. rxq->in.start = in;
  1265. rxq->in.ptr = in;
  1266. rxq->in.limit = in + rxs[pool];
  1267. memory = rxq->in.limit;
  1268. out = memory;
  1269. rxq->out.start = out;
  1270. rxq->out.ptr = out;
  1271. rxq->out.limit = out + rxs[pool];
  1272. memory = rxq->out.limit;
  1273. }
  1274. if (memory == limit) {
  1275. return 0;
  1276. } else {
  1277. PRINTK (KERN_ERR, "bad queue alloc %p != %p (tell maintainer)", memory, limit);
  1278. kfree (limit - total);
  1279. return -ENOMEM;
  1280. }
  1281. }
  1282. /********** destruction of communication queues **********/
  1283. static void destroy_queues (amb_dev * dev) {
  1284. // all queues assumed empty
  1285. void * memory = dev->cq.ptrs.start;
  1286. // includes txq.in, txq.out, rxq[].in and rxq[].out
  1287. PRINTD (DBG_FLOW, "destroy_queues %p", dev);
  1288. PRINTD (DBG_INIT, "freeing queues at %p", memory);
  1289. kfree (memory);
  1290. return;
  1291. }
  1292. /********** basic loader commands and error handling **********/
  1293. // centisecond timeouts - guessing away here
  1294. static unsigned int command_timeouts [] = {
  1295. [host_memory_test] = 15,
  1296. [read_adapter_memory] = 2,
  1297. [write_adapter_memory] = 2,
  1298. [adapter_start] = 50,
  1299. [get_version_number] = 10,
  1300. [interrupt_host] = 1,
  1301. [flash_erase_sector] = 1,
  1302. [adap_download_block] = 1,
  1303. [adap_erase_flash] = 1,
  1304. [adap_run_in_iram] = 1,
  1305. [adap_end_download] = 1
  1306. };
  1307. static unsigned int command_successes [] = {
  1308. [host_memory_test] = COMMAND_PASSED_TEST,
  1309. [read_adapter_memory] = COMMAND_READ_DATA_OK,
  1310. [write_adapter_memory] = COMMAND_WRITE_DATA_OK,
  1311. [adapter_start] = COMMAND_COMPLETE,
  1312. [get_version_number] = COMMAND_COMPLETE,
  1313. [interrupt_host] = COMMAND_COMPLETE,
  1314. [flash_erase_sector] = COMMAND_COMPLETE,
  1315. [adap_download_block] = COMMAND_COMPLETE,
  1316. [adap_erase_flash] = COMMAND_COMPLETE,
  1317. [adap_run_in_iram] = COMMAND_COMPLETE,
  1318. [adap_end_download] = COMMAND_COMPLETE
  1319. };
  1320. static int decode_loader_result (loader_command cmd, u32 result)
  1321. {
  1322. int res;
  1323. const char *msg;
  1324. if (result == command_successes[cmd])
  1325. return 0;
  1326. switch (result) {
  1327. case BAD_COMMAND:
  1328. res = -EINVAL;
  1329. msg = "bad command";
  1330. break;
  1331. case COMMAND_IN_PROGRESS:
  1332. res = -ETIMEDOUT;
  1333. msg = "command in progress";
  1334. break;
  1335. case COMMAND_PASSED_TEST:
  1336. res = 0;
  1337. msg = "command passed test";
  1338. break;
  1339. case COMMAND_FAILED_TEST:
  1340. res = -EIO;
  1341. msg = "command failed test";
  1342. break;
  1343. case COMMAND_READ_DATA_OK:
  1344. res = 0;
  1345. msg = "command read data ok";
  1346. break;
  1347. case COMMAND_READ_BAD_ADDRESS:
  1348. res = -EINVAL;
  1349. msg = "command read bad address";
  1350. break;
  1351. case COMMAND_WRITE_DATA_OK:
  1352. res = 0;
  1353. msg = "command write data ok";
  1354. break;
  1355. case COMMAND_WRITE_BAD_ADDRESS:
  1356. res = -EINVAL;
  1357. msg = "command write bad address";
  1358. break;
  1359. case COMMAND_WRITE_FLASH_FAILURE:
  1360. res = -EIO;
  1361. msg = "command write flash failure";
  1362. break;
  1363. case COMMAND_COMPLETE:
  1364. res = 0;
  1365. msg = "command complete";
  1366. break;
  1367. case COMMAND_FLASH_ERASE_FAILURE:
  1368. res = -EIO;
  1369. msg = "command flash erase failure";
  1370. break;
  1371. case COMMAND_WRITE_BAD_DATA:
  1372. res = -EINVAL;
  1373. msg = "command write bad data";
  1374. break;
  1375. default:
  1376. res = -EINVAL;
  1377. msg = "unknown error";
  1378. PRINTD (DBG_LOAD|DBG_ERR,
  1379. "decode_loader_result got %d=%x !",
  1380. result, result);
  1381. break;
  1382. }
  1383. PRINTK (KERN_ERR, "%s", msg);
  1384. return res;
  1385. }
  1386. static int do_loader_command(volatile loader_block *lb, const amb_dev *dev,
  1387. loader_command cmd)
  1388. {
  1389. unsigned long timeout;
  1390. PRINTD (DBG_FLOW|DBG_LOAD, "do_loader_command");
  1391. /* do a command
  1392. Set the return value to zero, set the command type and set the
  1393. valid entry to the right magic value. The payload is already
  1394. correctly byte-ordered so we leave it alone. Hit the doorbell
  1395. with the bus address of this structure.
  1396. */
  1397. lb->result = 0;
  1398. lb->command = cpu_to_be32 (cmd);
  1399. lb->valid = cpu_to_be32 (DMA_VALID);
  1400. // dump_registers (dev);
  1401. // dump_loader_block (lb);
  1402. wr_mem (dev, offsetof(amb_mem, doorbell), virt_to_bus (lb) & ~onegigmask);
  1403. timeout = command_timeouts[cmd] * 10;
  1404. while (!lb->result || lb->result == cpu_to_be32 (COMMAND_IN_PROGRESS))
  1405. if (timeout) {
  1406. timeout = msleep_interruptible(timeout);
  1407. } else {
  1408. PRINTD (DBG_LOAD|DBG_ERR, "command %d timed out", cmd);
  1409. dump_registers (dev);
  1410. dump_loader_block (lb);
  1411. return -ETIMEDOUT;
  1412. }
  1413. if (cmd == adapter_start) {
  1414. // wait for start command to acknowledge...
  1415. timeout = 100;
  1416. while (rd_plain (dev, offsetof(amb_mem, doorbell)))
  1417. if (timeout) {
  1418. timeout = msleep_interruptible(timeout);
  1419. } else {
  1420. PRINTD (DBG_LOAD|DBG_ERR, "start command did not clear doorbell, res=%08x",
  1421. be32_to_cpu (lb->result));
  1422. dump_registers (dev);
  1423. return -ETIMEDOUT;
  1424. }
  1425. return 0;
  1426. } else {
  1427. return decode_loader_result (cmd, be32_to_cpu (lb->result));
  1428. }
  1429. }
  1430. /* loader: determine loader version */
  1431. static int get_loader_version(loader_block *lb, const amb_dev *dev,
  1432. u32 *version)
  1433. {
  1434. int res;
  1435. PRINTD (DBG_FLOW|DBG_LOAD, "get_loader_version");
  1436. res = do_loader_command (lb, dev, get_version_number);
  1437. if (res)
  1438. return res;
  1439. if (version)
  1440. *version = be32_to_cpu (lb->payload.version);
  1441. return 0;
  1442. }
  1443. /* loader: write memory data blocks */
  1444. static int loader_write(loader_block *lb, const amb_dev *dev,
  1445. const struct ihex_binrec *rec)
  1446. {
  1447. transfer_block * tb = &lb->payload.transfer;
  1448. PRINTD (DBG_FLOW|DBG_LOAD, "loader_write");
  1449. tb->address = rec->addr;
  1450. tb->count = cpu_to_be32(be16_to_cpu(rec->len) / 4);
  1451. memcpy(tb->data, rec->data, be16_to_cpu(rec->len));
  1452. return do_loader_command (lb, dev, write_adapter_memory);
  1453. }
  1454. /* loader: verify memory data blocks */
  1455. static int loader_verify(loader_block *lb, const amb_dev *dev,
  1456. const struct ihex_binrec *rec)
  1457. {
  1458. transfer_block * tb = &lb->payload.transfer;
  1459. int res;
  1460. PRINTD (DBG_FLOW|DBG_LOAD, "loader_verify");
  1461. tb->address = rec->addr;
  1462. tb->count = cpu_to_be32(be16_to_cpu(rec->len) / 4);
  1463. res = do_loader_command (lb, dev, read_adapter_memory);
  1464. if (!res && memcmp(tb->data, rec->data, be16_to_cpu(rec->len)))
  1465. res = -EINVAL;
  1466. return res;
  1467. }
  1468. /* loader: start microcode */
  1469. static int loader_start(loader_block *lb, const amb_dev *dev, u32 address)
  1470. {
  1471. PRINTD (DBG_FLOW|DBG_LOAD, "loader_start");
  1472. lb->payload.start = cpu_to_be32 (address);
  1473. return do_loader_command (lb, dev, adapter_start);
  1474. }
  1475. /********** reset card **********/
  1476. static inline void sf (const char * msg)
  1477. {
  1478. PRINTK (KERN_ERR, "self-test failed: %s", msg);
  1479. }
  1480. static int amb_reset (amb_dev * dev, int diags) {
  1481. u32 word;
  1482. PRINTD (DBG_FLOW|DBG_LOAD, "amb_reset");
  1483. word = rd_plain (dev, offsetof(amb_mem, reset_control));
  1484. // put card into reset state
  1485. wr_plain (dev, offsetof(amb_mem, reset_control), word | AMB_RESET_BITS);
  1486. // wait a short while
  1487. udelay (10);
  1488. #if 1
  1489. // put card into known good state
  1490. wr_plain (dev, offsetof(amb_mem, interrupt_control), AMB_DOORBELL_BITS);
  1491. // clear all interrupts just in case
  1492. wr_plain (dev, offsetof(amb_mem, interrupt), -1);
  1493. #endif
  1494. // clear self-test done flag
  1495. wr_plain (dev, offsetof(amb_mem, mb.loader.ready), 0);
  1496. // take card out of reset state
  1497. wr_plain (dev, offsetof(amb_mem, reset_control), word &~ AMB_RESET_BITS);
  1498. if (diags) {
  1499. unsigned long timeout;
  1500. // 4.2 second wait
  1501. msleep(4200);
  1502. // half second time-out
  1503. timeout = 500;
  1504. while (!rd_plain (dev, offsetof(amb_mem, mb.loader.ready)))
  1505. if (timeout) {
  1506. timeout = msleep_interruptible(timeout);
  1507. } else {
  1508. PRINTD (DBG_LOAD|DBG_ERR, "reset timed out");
  1509. return -ETIMEDOUT;
  1510. }
  1511. // get results of self-test
  1512. // XXX double check byte-order
  1513. word = rd_mem (dev, offsetof(amb_mem, mb.loader.result));
  1514. if (word & SELF_TEST_FAILURE) {
  1515. if (word & GPINT_TST_FAILURE)
  1516. sf ("interrupt");
  1517. if (word & SUNI_DATA_PATTERN_FAILURE)
  1518. sf ("SUNI data pattern");
  1519. if (word & SUNI_DATA_BITS_FAILURE)
  1520. sf ("SUNI data bits");
  1521. if (word & SUNI_UTOPIA_FAILURE)
  1522. sf ("SUNI UTOPIA interface");
  1523. if (word & SUNI_FIFO_FAILURE)
  1524. sf ("SUNI cell buffer FIFO");
  1525. if (word & SRAM_FAILURE)
  1526. sf ("bad SRAM");
  1527. // better return value?
  1528. return -EIO;
  1529. }
  1530. }
  1531. return 0;
  1532. }
  1533. /********** transfer and start the microcode **********/
  1534. static int ucode_init(loader_block *lb, amb_dev *dev)
  1535. {
  1536. const struct firmware *fw;
  1537. unsigned long start_address;
  1538. const struct ihex_binrec *rec;
  1539. const char *errmsg = NULL;
  1540. int res;
  1541. res = request_ihex_firmware(&fw, "atmsar11.fw", &dev->pci_dev->dev);
  1542. if (res) {
  1543. PRINTK (KERN_ERR, "Cannot load microcode data");
  1544. return res;
  1545. }
  1546. /* First record contains just the start address */
  1547. rec = (const struct ihex_binrec *)fw->data;
  1548. if (be16_to_cpu(rec->len) != sizeof(__be32) || be32_to_cpu(rec->addr)) {
  1549. errmsg = "no start record";
  1550. goto fail;
  1551. }
  1552. start_address = be32_to_cpup((__be32 *)rec->data);
  1553. rec = ihex_next_binrec(rec);
  1554. PRINTD (DBG_FLOW|DBG_LOAD, "ucode_init");
  1555. while (rec) {
  1556. PRINTD (DBG_LOAD, "starting region (%x, %u)", be32_to_cpu(rec->addr),
  1557. be16_to_cpu(rec->len));
  1558. if (be16_to_cpu(rec->len) > 4 * MAX_TRANSFER_DATA) {
  1559. errmsg = "record too long";
  1560. goto fail;
  1561. }
  1562. if (be16_to_cpu(rec->len) & 3) {
  1563. errmsg = "odd number of bytes";
  1564. goto fail;
  1565. }
  1566. res = loader_write(lb, dev, rec);
  1567. if (res)
  1568. break;
  1569. res = loader_verify(lb, dev, rec);
  1570. if (res)
  1571. break;
  1572. rec = ihex_next_binrec(rec);
  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 amb_talk(amb_dev *dev)
  1588. {
  1589. adap_talk_block a;
  1590. unsigned char pool;
  1591. unsigned long timeout;
  1592. PRINTD (DBG_FLOW, "amb_talk %p", dev);
  1593. a.command_start = bus_addr (dev->cq.ptrs.start);
  1594. a.command_end = bus_addr (dev->cq.ptrs.limit);
  1595. a.tx_start = bus_addr (dev->txq.in.start);
  1596. a.tx_end = bus_addr (dev->txq.in.limit);
  1597. a.txcom_start = bus_addr (dev->txq.out.start);
  1598. a.txcom_end = bus_addr (dev->txq.out.limit);
  1599. for (pool = 0; pool < NUM_RX_POOLS; ++pool) {
  1600. // the other "a" items are set up by the adapter
  1601. a.rec_struct[pool].buffer_start = bus_addr (dev->rxq[pool].in.start);
  1602. a.rec_struct[pool].buffer_end = bus_addr (dev->rxq[pool].in.limit);
  1603. a.rec_struct[pool].rx_start = bus_addr (dev->rxq[pool].out.start);
  1604. a.rec_struct[pool].rx_end = bus_addr (dev->rxq[pool].out.limit);
  1605. a.rec_struct[pool].buffer_size = cpu_to_be32 (dev->rxq[pool].buffer_size);
  1606. }
  1607. #ifdef AMB_NEW_MICROCODE
  1608. // disable fast PLX prefetching
  1609. a.init_flags = 0;
  1610. #endif
  1611. // pass the structure
  1612. wr_mem (dev, offsetof(amb_mem, doorbell), virt_to_bus (&a));
  1613. // 2.2 second wait (must not touch doorbell during 2 second DMA test)
  1614. msleep(2200);
  1615. // give the adapter another half second?
  1616. timeout = 500;
  1617. while (rd_plain (dev, offsetof(amb_mem, doorbell)))
  1618. if (timeout) {
  1619. timeout = msleep_interruptible(timeout);
  1620. } else {
  1621. PRINTD (DBG_INIT|DBG_ERR, "adapter init timed out");
  1622. return -ETIMEDOUT;
  1623. }
  1624. return 0;
  1625. }
  1626. // get microcode version
  1627. static void amb_ucode_version(amb_dev *dev)
  1628. {
  1629. u32 major;
  1630. u32 minor;
  1631. command cmd;
  1632. cmd.request = cpu_to_be32 (SRB_GET_VERSION);
  1633. while (command_do (dev, &cmd)) {
  1634. set_current_state(TASK_UNINTERRUPTIBLE);
  1635. schedule();
  1636. }
  1637. major = be32_to_cpu (cmd.args.version.major);
  1638. minor = be32_to_cpu (cmd.args.version.minor);
  1639. PRINTK (KERN_INFO, "microcode version is %u.%u", major, minor);
  1640. }
  1641. // get end station address
  1642. static void amb_esi(amb_dev *dev, u8 *esi)
  1643. {
  1644. u32 lower4;
  1645. u16 upper2;
  1646. command cmd;
  1647. cmd.request = cpu_to_be32 (SRB_GET_BIA);
  1648. while (command_do (dev, &cmd)) {
  1649. set_current_state(TASK_UNINTERRUPTIBLE);
  1650. schedule();
  1651. }
  1652. lower4 = be32_to_cpu (cmd.args.bia.lower4);
  1653. upper2 = be32_to_cpu (cmd.args.bia.upper2);
  1654. PRINTD (DBG_LOAD, "BIA: lower4: %08x, upper2 %04x", lower4, upper2);
  1655. if (esi) {
  1656. unsigned int i;
  1657. PRINTDB (DBG_INIT, "ESI:");
  1658. for (i = 0; i < ESI_LEN; ++i) {
  1659. if (i < 4)
  1660. esi[i] = bitrev8(lower4>>(8*i));
  1661. else
  1662. esi[i] = bitrev8(upper2>>(8*(i-4)));
  1663. PRINTDM (DBG_INIT, " %02x", esi[i]);
  1664. }
  1665. PRINTDE (DBG_INIT, "");
  1666. }
  1667. return;
  1668. }
  1669. static void fixup_plx_window (amb_dev *dev, loader_block *lb)
  1670. {
  1671. // fix up the PLX-mapped window base address to match the block
  1672. unsigned long blb;
  1673. u32 mapreg;
  1674. blb = virt_to_bus(lb);
  1675. // the kernel stack had better not ever cross a 1Gb boundary!
  1676. mapreg = rd_plain (dev, offsetof(amb_mem, stuff[10]));
  1677. mapreg &= ~onegigmask;
  1678. mapreg |= blb & onegigmask;
  1679. wr_plain (dev, offsetof(amb_mem, stuff[10]), mapreg);
  1680. return;
  1681. }
  1682. static int amb_init(amb_dev *dev)
  1683. {
  1684. loader_block lb;
  1685. u32 version;
  1686. if (amb_reset (dev, 1)) {
  1687. PRINTK (KERN_ERR, "card reset failed!");
  1688. } else {
  1689. fixup_plx_window (dev, &lb);
  1690. if (get_loader_version (&lb, dev, &version)) {
  1691. PRINTK (KERN_INFO, "failed to get loader version");
  1692. } else {
  1693. PRINTK (KERN_INFO, "loader version is %08x", version);
  1694. if (ucode_init (&lb, dev)) {
  1695. PRINTK (KERN_ERR, "microcode failure");
  1696. } else if (create_queues (dev, cmds, txs, rxs, rxs_bs)) {
  1697. PRINTK (KERN_ERR, "failed to get memory for queues");
  1698. } else {
  1699. if (amb_talk (dev)) {
  1700. PRINTK (KERN_ERR, "adapter did not accept queues");
  1701. } else {
  1702. amb_ucode_version (dev);
  1703. return 0;
  1704. } /* amb_talk */
  1705. destroy_queues (dev);
  1706. } /* create_queues, ucode_init */
  1707. amb_reset (dev, 0);
  1708. } /* get_loader_version */
  1709. } /* amb_reset */
  1710. return -EINVAL;
  1711. }
  1712. static void setup_dev(amb_dev *dev, struct pci_dev *pci_dev)
  1713. {
  1714. unsigned char pool;
  1715. // set up known dev items straight away
  1716. dev->pci_dev = pci_dev;
  1717. pci_set_drvdata(pci_dev, dev);
  1718. dev->iobase = pci_resource_start (pci_dev, 1);
  1719. dev->irq = pci_dev->irq;
  1720. dev->membase = bus_to_virt(pci_resource_start(pci_dev, 0));
  1721. // flags (currently only dead)
  1722. dev->flags = 0;
  1723. // Allocate cell rates (fibre)
  1724. // ATM_OC3_PCR = 1555200000/8/270*260/53 - 29/53
  1725. // to be really pedantic, this should be ATM_OC3c_PCR
  1726. dev->tx_avail = ATM_OC3_PCR;
  1727. dev->rx_avail = ATM_OC3_PCR;
  1728. // semaphore for txer/rxer modifications - we cannot use a
  1729. // spinlock as the critical region needs to switch processes
  1730. mutex_init(&dev->vcc_sf);
  1731. // queue manipulation spinlocks; we want atomic reads and
  1732. // writes to the queue descriptors (handles IRQ and SMP)
  1733. // consider replacing "int pending" -> "atomic_t available"
  1734. // => problem related to who gets to move queue pointers
  1735. spin_lock_init (&dev->cq.lock);
  1736. spin_lock_init (&dev->txq.lock);
  1737. for (pool = 0; pool < NUM_RX_POOLS; ++pool)
  1738. spin_lock_init (&dev->rxq[pool].lock);
  1739. }
  1740. static void setup_pci_dev(struct pci_dev *pci_dev)
  1741. {
  1742. unsigned char lat;
  1743. // enable bus master accesses
  1744. pci_set_master(pci_dev);
  1745. // frobnicate latency (upwards, usually)
  1746. pci_read_config_byte (pci_dev, PCI_LATENCY_TIMER, &lat);
  1747. if (!pci_lat)
  1748. pci_lat = (lat < MIN_PCI_LATENCY) ? MIN_PCI_LATENCY : lat;
  1749. if (lat != pci_lat) {
  1750. PRINTK (KERN_INFO, "Changing PCI latency timer from %hu to %hu",
  1751. lat, pci_lat);
  1752. pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, pci_lat);
  1753. }
  1754. }
  1755. static int amb_probe(struct pci_dev *pci_dev,
  1756. 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 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 = 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);