ambassador.c 68 KB

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