ibmtr.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  1. /* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux
  2. *
  3. * Written 1993 by Mark Swanson and Peter De Schrijver.
  4. * This software may be used and distributed according to the terms
  5. * of the GNU General Public License, incorporated herein by reference.
  6. *
  7. * This device driver should work with Any IBM Token Ring Card that does
  8. * not use DMA.
  9. *
  10. * I used Donald Becker's (becker@scyld.com) device driver work
  11. * as a base for most of my initial work.
  12. *
  13. * Changes by Peter De Schrijver
  14. * (Peter.Deschrijver@linux.cc.kuleuven.ac.be) :
  15. *
  16. * + changed name to ibmtr.c in anticipation of other tr boards.
  17. * + changed reset code and adapter open code.
  18. * + added SAP open code.
  19. * + a first attempt to write interrupt, transmit and receive routines.
  20. *
  21. * Changes by David W. Morris (dwm@shell.portal.com) :
  22. * 941003 dwm: - Restructure tok_probe for multiple adapters, devices.
  23. * + Add comments, misc reorg for clarity.
  24. * + Flatten interrupt handler levels.
  25. *
  26. * Changes by Farzad Farid (farzy@zen.via.ecp.fr)
  27. * and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) :
  28. * + multi ring support clean up.
  29. * + RFC1042 compliance enhanced.
  30. *
  31. * Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) :
  32. * + bug correction in tr_tx
  33. * + removed redundant information display
  34. * + some code reworking
  35. *
  36. * Changes by Michel Lespinasse (walken@via.ecp.fr),
  37. * Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr)
  38. * (February 18, 1996) :
  39. * + modified shared memory and mmio access port the driver to
  40. * alpha platform (structure access -> readb/writeb)
  41. *
  42. * Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com)
  43. * (January 18 1996):
  44. * + swapped WWOR and WWCR in ibmtr.h
  45. * + moved some init code from tok_probe into trdev_init. The
  46. * PCMCIA code can call trdev_init to complete initializing
  47. * the driver.
  48. * + added -DPCMCIA to support PCMCIA
  49. * + detecting PCMCIA Card Removal in interrupt handler. If
  50. * ISRP is FF, then a PCMCIA card has been removed
  51. * 10/2000 Burt needed a new method to avoid crashing the OS
  52. *
  53. * Changes by Paul Norton (pnorton@cts.com) :
  54. * + restructured the READ.LOG logic to prevent the transmit SRB
  55. * from being rudely overwritten before the transmit cycle is
  56. * complete. (August 15 1996)
  57. * + completed multiple adapter support. (November 20 1996)
  58. * + implemented csum_partial_copy in tr_rx and increased receive
  59. * buffer size and count. Minor fixes. (March 15, 1997)
  60. *
  61. * Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk>
  62. * + Now compiles ok as a module again.
  63. *
  64. * Changes by Paul Norton (pnorton@ieee.org) :
  65. * + moved the header manipulation code in tr_tx and tr_rx to
  66. * net/802/tr.c. (July 12 1997)
  67. * + add retry and timeout on open if cable disconnected. (May 5 1998)
  68. * + lifted 2000 byte mtu limit. now depends on shared-RAM size.
  69. * May 25 1998)
  70. * + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998)
  71. *
  72. * Changes by Joel Sloan (jjs@c-me.com) :
  73. * + disable verbose debug messages by default - to enable verbose
  74. * debugging, edit the IBMTR_DEBUG_MESSAGES define below
  75. *
  76. * Changes by Mike Phillips <phillim@amtrak.com> :
  77. * + Added extra #ifdef's to work with new PCMCIA Token Ring Code.
  78. * The PCMCIA code now just sets up the card so it can be recognized
  79. * by ibmtr_probe. Also checks allocated memory vs. on-board memory
  80. * for correct figure to use.
  81. *
  82. * Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) :
  83. * + added spinlocks for SMP sanity (10 March 1999)
  84. *
  85. * Changes by Jochen Friedrich to enable RFC1469 Option 2 multicasting
  86. * i.e. using functional address C0 00 00 04 00 00 to transmit and
  87. * receive multicast packets.
  88. *
  89. * Changes by Mike Sullivan (based on original sram patch by Dave Grothe
  90. * to support windowing into on adapter shared ram.
  91. * i.e. Use LANAID to setup a PnP configuration with 16K RAM. Paging
  92. * will shift this 16K window over the entire available shared RAM.
  93. *
  94. * Changes by Peter De Schrijver (p2@mind.be) :
  95. * + fixed a problem with PCMCIA card removal
  96. *
  97. * Change by Mike Sullivan et al.:
  98. * + added turbo card support. No need to use lanaid to configure
  99. * the adapter into isa compatiblity mode.
  100. *
  101. * Changes by Burt Silverman to allow the computer to behave nicely when
  102. * a cable is pulled or not in place, or a PCMCIA card is removed hot.
  103. */
  104. /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
  105. in the event that chatty debug messages are desired - jjs 12/30/98 */
  106. #define IBMTR_DEBUG_MESSAGES 0
  107. #include <linux/module.h>
  108. #ifdef PCMCIA /* required for ibmtr_cs.c to build */
  109. #undef MODULE /* yes, really */
  110. #undef ENABLE_PAGING
  111. #else
  112. #define ENABLE_PAGING 1
  113. #endif
  114. #define FALSE 0
  115. #define TRUE (!FALSE)
  116. /* changes the output format of driver initialization */
  117. #define TR_VERBOSE 0
  118. /* some 95 OS send many non UI frame; this allow removing the warning */
  119. #define TR_FILTERNONUI 1
  120. #include <linux/ioport.h>
  121. #include <linux/netdevice.h>
  122. #include <linux/ip.h>
  123. #include <linux/trdevice.h>
  124. #include <linux/ibmtr.h>
  125. #include <net/checksum.h>
  126. #include <asm/io.h>
  127. #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
  128. #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
  129. /* version and credits */
  130. #ifndef PCMCIA
  131. static char version[] __initdata =
  132. "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
  133. " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
  134. " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
  135. " v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n"
  136. " v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n"
  137. " v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n";
  138. #endif
  139. /* this allows displaying full adapter information */
  140. static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
  141. static char pcchannelid[] __devinitdata = {
  142. 0x05, 0x00, 0x04, 0x09,
  143. 0x04, 0x03, 0x04, 0x0f,
  144. 0x03, 0x06, 0x03, 0x01,
  145. 0x03, 0x01, 0x03, 0x00,
  146. 0x03, 0x09, 0x03, 0x09,
  147. 0x03, 0x00, 0x02, 0x00
  148. };
  149. static char mcchannelid[] __devinitdata = {
  150. 0x04, 0x0d, 0x04, 0x01,
  151. 0x05, 0x02, 0x05, 0x03,
  152. 0x03, 0x06, 0x03, 0x03,
  153. 0x05, 0x08, 0x03, 0x04,
  154. 0x03, 0x05, 0x03, 0x01,
  155. 0x03, 0x08, 0x02, 0x00
  156. };
  157. static char __devinit *adapter_def(char type)
  158. {
  159. switch (type) {
  160. case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
  161. case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)";
  162. case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
  163. case 0xC: return "Auto 16/4 Adapter";
  164. default: return "adapter (unknown type)";
  165. };
  166. };
  167. #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
  168. #define TRC_INITV 0x02 /* verbose init trace points */
  169. static unsigned char ibmtr_debug_trace = 0;
  170. static int ibmtr_probe(struct net_device *dev);
  171. static int ibmtr_probe1(struct net_device *dev, int ioaddr);
  172. static unsigned char get_sram_size(struct tok_info *adapt_info);
  173. static int trdev_init(struct net_device *dev);
  174. static int tok_open(struct net_device *dev);
  175. static int tok_init_card(struct net_device *dev);
  176. static void tok_open_adapter(unsigned long dev_addr);
  177. static void open_sap(unsigned char type, struct net_device *dev);
  178. static void tok_set_multicast_list(struct net_device *dev);
  179. static int tok_send_packet(struct sk_buff *skb, struct net_device *dev);
  180. static int tok_close(struct net_device *dev);
  181. static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  182. static void initial_tok_int(struct net_device *dev);
  183. static void tr_tx(struct net_device *dev);
  184. static void tr_rx(struct net_device *dev);
  185. static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
  186. static void tok_rerun(unsigned long dev_addr);
  187. static void ibmtr_readlog(struct net_device *dev);
  188. static struct net_device_stats *tok_get_stats(struct net_device *dev);
  189. static int ibmtr_change_mtu(struct net_device *dev, int mtu);
  190. static void find_turbo_adapters(int *iolist);
  191. static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
  192. 0xa20, 0xa24, 0, 0, 0
  193. };
  194. static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0};
  195. static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
  196. static int __devinitdata turbo_searched = 0;
  197. #ifndef PCMCIA
  198. static __u32 ibmtr_mem_base __initdata = 0xd0000;
  199. #endif
  200. static void __devinit PrtChanID(char *pcid, short stride)
  201. {
  202. short i, j;
  203. for (i = 0, j = 0; i < 24; i++, j += stride)
  204. printk("%1x", ((int) pcid[j]) & 0x0f);
  205. printk("\n");
  206. }
  207. static void __devinit HWPrtChanID(void __iomem *pcid, short stride)
  208. {
  209. short i, j;
  210. for (i = 0, j = 0; i < 24; i++, j += stride)
  211. printk("%1x", ((int) readb(pcid + j)) & 0x0f);
  212. printk("\n");
  213. }
  214. /* We have to ioremap every checked address, because isa_readb is
  215. * going away.
  216. */
  217. static void __devinit find_turbo_adapters(int *iolist)
  218. {
  219. int ram_addr;
  220. int index=0;
  221. void __iomem *chanid;
  222. int found_turbo=0;
  223. unsigned char *tchanid, ctemp;
  224. int i, j;
  225. unsigned long jif;
  226. void __iomem *ram_mapped ;
  227. if (turbo_searched == 1) return;
  228. turbo_searched=1;
  229. for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) {
  230. __u32 intf_tbl=0;
  231. found_turbo=1;
  232. ram_mapped = ioremap((u32)ram_addr,0x1fff) ;
  233. if (ram_mapped==NULL)
  234. continue ;
  235. chanid=(CHANNEL_ID + ram_mapped);
  236. tchanid=pcchannelid;
  237. ctemp=readb(chanid) & 0x0f;
  238. if (ctemp != *tchanid) continue;
  239. for (i=2,j=1; i<=46; i=i+2,j++) {
  240. if ((readb(chanid+i) & 0x0f) != tchanid[j]){
  241. found_turbo=0;
  242. break;
  243. }
  244. }
  245. if (!found_turbo) continue;
  246. writeb(0x90, ram_mapped+0x1E01);
  247. for(i=2; i<0x0f; i++) {
  248. writeb(0x00, ram_mapped+0x1E01+i);
  249. }
  250. writeb(0x00, ram_mapped+0x1E01);
  251. for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif););
  252. intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN));
  253. if (intf_tbl) {
  254. #if IBMTR_DEBUG_MESSAGES
  255. printk("ibmtr::find_turbo_adapters, Turbo found at "
  256. "ram_addr %x\n",ram_addr);
  257. printk("ibmtr::find_turbo_adapters, interface_table ");
  258. for(i=0; i<6; i++) {
  259. printk("%x:",readb(ram_addr+intf_tbl+i));
  260. }
  261. printk("\n");
  262. #endif
  263. turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4));
  264. turbo_irq[index]=readb(ram_mapped+intf_tbl+3);
  265. outb(0, turbo_io[index] + ADAPTRESET);
  266. for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif););
  267. outb(0, turbo_io[index] + ADAPTRESETREL);
  268. index++;
  269. continue;
  270. }
  271. #if IBMTR_DEBUG_MESSAGES
  272. printk("ibmtr::find_turbo_adapters, ibmtr card found at"
  273. " %x but not a Turbo model\n",ram_addr);
  274. #endif
  275. iounmap(ram_mapped) ;
  276. } /* for */
  277. for(i=0; i<IBMTR_MAX_ADAPTERS; i++) {
  278. if(!turbo_io[i]) break;
  279. for (j=0; j<IBMTR_MAX_ADAPTERS; j++) {
  280. if ( iolist[j] && iolist[j] != turbo_io[i]) continue;
  281. iolist[j]=turbo_io[i];
  282. break;
  283. }
  284. }
  285. }
  286. static void ibmtr_cleanup_card(struct net_device *dev)
  287. {
  288. if (dev->base_addr) {
  289. outb(0,dev->base_addr+ADAPTRESET);
  290. schedule_timeout(TR_RST_TIME); /* wait 50ms */
  291. outb(0,dev->base_addr+ADAPTRESETREL);
  292. }
  293. #ifndef PCMCIA
  294. free_irq(dev->irq, dev);
  295. release_region(dev->base_addr, IBMTR_IO_EXTENT);
  296. {
  297. struct tok_info *ti = (struct tok_info *) dev->priv;
  298. iounmap(ti->mmio);
  299. iounmap(ti->sram_virt);
  300. }
  301. #endif
  302. }
  303. int ibmtr_probe_card(struct net_device *dev)
  304. {
  305. int err = ibmtr_probe(dev);
  306. if (!err) {
  307. err = register_netdev(dev);
  308. if (err)
  309. ibmtr_cleanup_card(dev);
  310. }
  311. return err;
  312. }
  313. /****************************************************************************
  314. * ibmtr_probe(): Routine specified in the network device structure
  315. * to probe for an IBM Token Ring Adapter. Routine outline:
  316. * I. Interrogate hardware to determine if an adapter exists
  317. * and what the speeds and feeds are
  318. * II. Setup data structures to control execution based upon
  319. * adapter characteristics.
  320. *
  321. * We expect ibmtr_probe to be called once for each device entry
  322. * which references it.
  323. ****************************************************************************/
  324. static int ibmtr_probe(struct net_device *dev)
  325. {
  326. int i;
  327. int base_addr = dev->base_addr;
  328. if (base_addr && base_addr <= 0x1ff) /* Don't probe at all. */
  329. return -ENXIO;
  330. if (base_addr > 0x1ff) { /* Check a single specified location. */
  331. if (!ibmtr_probe1(dev, base_addr)) return 0;
  332. return -ENODEV;
  333. }
  334. find_turbo_adapters(ibmtr_portlist);
  335. for (i = 0; ibmtr_portlist[i]; i++) {
  336. int ioaddr = ibmtr_portlist[i];
  337. if (!ibmtr_probe1(dev, ioaddr)) return 0;
  338. }
  339. return -ENODEV;
  340. }
  341. /*****************************************************************************/
  342. static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
  343. {
  344. unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0;
  345. void __iomem * t_mmio = NULL;
  346. struct tok_info *ti = dev->priv;
  347. void __iomem *cd_chanid;
  348. unsigned char *tchanid, ctemp;
  349. #ifndef PCMCIA
  350. unsigned char t_irq=0;
  351. unsigned long timeout;
  352. static int version_printed;
  353. #endif
  354. /* Query the adapter PIO base port which will return
  355. * indication of where MMIO was placed. We also have a
  356. * coded interrupt number.
  357. */
  358. segment = inb(PIOaddr);
  359. if (segment < 0x40 || segment > 0xe0) {
  360. /* Out of range values so we'll assume non-existent IO device
  361. * but this is not necessarily a problem, esp if a turbo
  362. * adapter is being used. */
  363. #if IBMTR_DEBUG_MESSAGES
  364. DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, "
  365. "Hardware Problem?\n",PIOaddr,segment);
  366. #endif
  367. return -ENODEV;
  368. }
  369. /*
  370. * Compute the linear base address of the MMIO area
  371. * as LINUX doesn't care about segments
  372. */
  373. t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048);
  374. if (!t_mmio) {
  375. DPRINTK("Cannot remap mmiobase memory area") ;
  376. return -ENODEV ;
  377. }
  378. intr = segment & 0x03; /* low bits is coded interrupt # */
  379. if (ibmtr_debug_trace & TRC_INIT)
  380. DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n"
  381. , PIOaddr, (int) segment, t_mmio, (int) intr);
  382. /*
  383. * Now we will compare expected 'channelid' strings with
  384. * what we is there to learn of ISA/MCA or not TR card
  385. */
  386. #ifdef PCMCIA
  387. iounmap(t_mmio);
  388. t_mmio = ti->mmio; /*BMS to get virtual address */
  389. irq = ti->irq; /*BMS to display the irq! */
  390. #endif
  391. cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */
  392. tchanid = pcchannelid;
  393. cardpresent = TR_ISA; /* try ISA */
  394. /* Suboptimize knowing first byte different */
  395. ctemp = readb(cd_chanid) & 0x0f;
  396. if (ctemp != *tchanid) { /* NOT ISA card, try MCA */
  397. tchanid = mcchannelid;
  398. cardpresent = TR_MCA;
  399. if (ctemp != *tchanid) /* Neither ISA nor MCA */
  400. cardpresent = NOTOK;
  401. }
  402. if (cardpresent != NOTOK) {
  403. /* Know presumed type, try rest of ID */
  404. for (i = 2, j = 1; i <= 46; i = i + 2, j++) {
  405. if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue;
  406. /* match failed, not TR card */
  407. cardpresent = NOTOK;
  408. break;
  409. }
  410. }
  411. /*
  412. * If we have an ISA board check for the ISA P&P version,
  413. * as it has different IRQ settings
  414. */
  415. if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e))
  416. cardpresent = TR_ISAPNP;
  417. if (cardpresent == NOTOK) { /* "channel_id" did not match, report */
  418. if (!(ibmtr_debug_trace & TRC_INIT)) {
  419. #ifndef PCMCIA
  420. iounmap(t_mmio);
  421. #endif
  422. return -ENODEV;
  423. }
  424. DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n",
  425. PIOaddr);
  426. DPRINTK("Expected for ISA: ");
  427. PrtChanID(pcchannelid, 1);
  428. DPRINTK(" found: ");
  429. /* BMS Note that this can be misleading, when hardware is flaky, because you
  430. are reading it a second time here. So with my flaky hardware, I'll see my-
  431. self in this block, with the HW ID matching the ISA ID exactly! */
  432. HWPrtChanID(cd_chanid, 2);
  433. DPRINTK("Expected for MCA: ");
  434. PrtChanID(mcchannelid, 1);
  435. }
  436. /* Now, setup some of the pl0 buffers for this driver.. */
  437. /* If called from PCMCIA, it is already set up, so no need to
  438. waste the memory, just use the existing structure */
  439. #ifndef PCMCIA
  440. ti->mmio = t_mmio;
  441. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) {
  442. if (turbo_io[i] != PIOaddr)
  443. continue;
  444. #if IBMTR_DEBUG_MESSAGES
  445. printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n",
  446. PIOaddr);
  447. #endif
  448. ti->turbo = 1;
  449. t_irq = turbo_irq[i];
  450. }
  451. #endif /* !PCMCIA */
  452. ti->readlog_pending = 0;
  453. init_waitqueue_head(&ti->wait_for_reset);
  454. /* if PCMCIA, the card can be recognized as either TR_ISA or TR_ISAPNP
  455. * depending which card is inserted. */
  456. #ifndef PCMCIA
  457. switch (cardpresent) {
  458. case TR_ISA:
  459. if (intr == 0) irq = 9; /* irq2 really is irq9 */
  460. if (intr == 1) irq = 3;
  461. if (intr == 2) irq = 6;
  462. if (intr == 3) irq = 7;
  463. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  464. break;
  465. case TR_MCA:
  466. if (intr == 0) irq = 9;
  467. if (intr == 1) irq = 3;
  468. if (intr == 2) irq = 10;
  469. if (intr == 3) irq = 11;
  470. ti->global_int_enable = 0;
  471. ti->adapter_int_enable = 0;
  472. ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12;
  473. break;
  474. case TR_ISAPNP:
  475. if (!t_irq) {
  476. if (intr == 0) irq = 9;
  477. if (intr == 1) irq = 3;
  478. if (intr == 2) irq = 10;
  479. if (intr == 3) irq = 11;
  480. } else
  481. irq=t_irq;
  482. timeout = jiffies + TR_SPIN_INTERVAL;
  483. while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){
  484. if (!time_after(jiffies, timeout)) continue;
  485. DPRINTK( "Hardware timeout during initialization.\n");
  486. iounmap(t_mmio);
  487. return -ENODEV;
  488. }
  489. ti->sram_phys =
  490. ((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12);
  491. ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
  492. break;
  493. } /*end switch (cardpresent) */
  494. #endif /*not PCMCIA */
  495. if (ibmtr_debug_trace & TRC_INIT) { /* just report int */
  496. DPRINTK("irq=%d", irq);
  497. printk(", sram_phys=0x%x", ti->sram_phys);
  498. if(ibmtr_debug_trace&TRC_INITV){ /* full chat in verbose only */
  499. DPRINTK(", ti->mmio=%p", ti->mmio);
  500. printk(", segment=%02X", segment);
  501. }
  502. printk(".\n");
  503. }
  504. /* Get hw address of token ring card */
  505. j = 0;
  506. for (i = 0; i < 0x18; i = i + 2) {
  507. /* technical reference states to do this */
  508. temp = readb(ti->mmio + AIP + i) & 0x0f;
  509. ti->hw_address[j] = temp;
  510. if (j & 1)
  511. dev->dev_addr[(j / 2)] =
  512. ti->hw_address[j]+ (ti->hw_address[j - 1] << 4);
  513. ++j;
  514. }
  515. /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,... */
  516. ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
  517. /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
  518. ti->data_rate = readb(ti->mmio + AIPDATARATE);
  519. /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
  520. ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
  521. /* How much shared RAM is on adapter ? */
  522. if (ti->turbo) {
  523. ti->avail_shared_ram=127;
  524. } else {
  525. ti->avail_shared_ram = get_sram_size(ti);/*in 512 byte units */
  526. }
  527. /* We need to set or do a bunch of work here based on previous results*/
  528. /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
  529. ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
  530. /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
  531. switch (readb(ti->mmio + AIP4MBDHB)) {
  532. case 0xe: ti->dhb_size4mb = 4096; break;
  533. case 0xd: ti->dhb_size4mb = 4464; break;
  534. default: ti->dhb_size4mb = 2048; break;
  535. }
  536. /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
  537. switch (readb(ti->mmio + AIP16MBDHB)) {
  538. case 0xe: ti->dhb_size16mb = 4096; break;
  539. case 0xd: ti->dhb_size16mb = 8192; break;
  540. case 0xc: ti->dhb_size16mb = 16384; break;
  541. case 0xb: ti->dhb_size16mb = 17960; break;
  542. default: ti->dhb_size16mb = 2048; break;
  543. }
  544. /* We must figure out how much shared memory space this adapter
  545. * will occupy so that if there are two adapters we can fit both
  546. * in. Given a choice, we will limit this adapter to 32K. The
  547. * maximum space will will use for two adapters is 64K so if the
  548. * adapter we are working on demands 64K (it also doesn't support
  549. * paging), then only one adapter can be supported.
  550. */
  551. /*
  552. * determine how much of total RAM is mapped into PC space
  553. */
  554. ti->mapped_ram_size= /*sixteen to onehundredtwentyeight 512byte blocks*/
  555. 1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4);
  556. ti->page_mask = 0;
  557. if (ti->turbo) ti->page_mask=0xf0;
  558. else if (ti->shared_ram_paging == 0xf); /* No paging in adapter */
  559. else {
  560. #ifdef ENABLE_PAGING
  561. unsigned char pg_size = 0;
  562. /* BMS: page size: PCMCIA, use configuration register;
  563. ISAPNP, use LANAIDC config tool from www.ibm.com */
  564. switch (ti->shared_ram_paging) {
  565. case 0xf:
  566. break;
  567. case 0xe:
  568. ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0;
  569. pg_size = 32; /* 16KB page size */
  570. break;
  571. case 0xd:
  572. ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0;
  573. pg_size = 64; /* 32KB page size */
  574. break;
  575. case 0xc:
  576. switch (ti->mapped_ram_size) {
  577. case 32:
  578. ti->page_mask = 0xc0;
  579. pg_size = 32;
  580. break;
  581. case 64:
  582. ti->page_mask = 0x80;
  583. pg_size = 64;
  584. break;
  585. }
  586. break;
  587. default:
  588. DPRINTK("Unknown shared ram paging info %01X\n",
  589. ti->shared_ram_paging);
  590. iounmap(t_mmio);
  591. return -ENODEV;
  592. break;
  593. } /*end switch shared_ram_paging */
  594. if (ibmtr_debug_trace & TRC_INIT)
  595. DPRINTK("Shared RAM paging code: %02X, "
  596. "mapped RAM size: %dK, shared RAM size: %dK, "
  597. "page mask: %02X\n:",
  598. ti->shared_ram_paging, ti->mapped_ram_size / 2,
  599. ti->avail_shared_ram / 2, ti->page_mask);
  600. #endif /*ENABLE_PAGING */
  601. }
  602. #ifndef PCMCIA
  603. /* finish figuring the shared RAM address */
  604. if (cardpresent == TR_ISA) {
  605. static __u32 ram_bndry_mask[] =
  606. { 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000 };
  607. __u32 new_base, rrr_32, chk_base, rbm;
  608. rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
  609. rbm = ram_bndry_mask[rrr_32];
  610. new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */
  611. chk_base = new_base + (ti->mapped_ram_size << 9);
  612. if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
  613. DPRINTK("Shared RAM for this adapter (%05x) exceeds "
  614. "driver limit (%05x), adapter not started.\n",
  615. chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
  616. iounmap(t_mmio);
  617. return -ENODEV;
  618. } else { /* seems cool, record what we have figured out */
  619. ti->sram_base = new_base >> 12;
  620. ibmtr_mem_base = chk_base;
  621. }
  622. }
  623. else ti->sram_base = ti->sram_phys >> 12;
  624. /* The PCMCIA has already got the interrupt line and the io port,
  625. so no chance of anybody else getting it - MLP */
  626. if (request_irq(dev->irq = irq, &tok_interrupt, 0, "ibmtr", dev) != 0) {
  627. DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
  628. irq);
  629. iounmap(t_mmio);
  630. return -ENODEV;
  631. }
  632. /*?? Now, allocate some of the PIO PORTs for this driver.. */
  633. /* record PIOaddr range as busy */
  634. if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
  635. DPRINTK("Could not grab PIO range. Halting driver.\n");
  636. free_irq(dev->irq, dev);
  637. iounmap(t_mmio);
  638. return -EBUSY;
  639. }
  640. if (!version_printed++) {
  641. printk(version);
  642. }
  643. #endif /* !PCMCIA */
  644. DPRINTK("%s %s found\n",
  645. channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
  646. DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
  647. irq, PIOaddr, ti->mapped_ram_size / 2);
  648. DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n",
  649. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  650. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  651. if (ti->page_mask)
  652. DPRINTK("Shared RAM paging enabled. "
  653. "Page size: %uK Shared Ram size %dK\n",
  654. ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
  655. else
  656. DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
  657. ti->page_mask);
  658. /* Calculate the maximum DHB we can use */
  659. /* two cases where avail_shared_ram doesn't equal mapped_ram_size:
  660. 1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical)
  661. 2. user has configured adapter for less than avail_shared_ram
  662. but is not using paging (she should use paging, I believe)
  663. */
  664. if (!ti->page_mask) {
  665. ti->avail_shared_ram=
  666. min(ti->mapped_ram_size,ti->avail_shared_ram);
  667. }
  668. switch (ti->avail_shared_ram) {
  669. case 16: /* 8KB shared RAM */
  670. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
  671. ti->rbuf_len4 = 1032;
  672. ti->rbuf_cnt4=2;
  673. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
  674. ti->rbuf_len16 = 1032;
  675. ti->rbuf_cnt16=2;
  676. break;
  677. case 32: /* 16KB shared RAM */
  678. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  679. ti->rbuf_len4 = 1032;
  680. ti->rbuf_cnt4=4;
  681. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
  682. ti->rbuf_len16 = 1032; /*1024 usable */
  683. ti->rbuf_cnt16=4;
  684. break;
  685. case 64: /* 32KB shared RAM */
  686. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  687. ti->rbuf_len4 = 1032;
  688. ti->rbuf_cnt4=6;
  689. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
  690. ti->rbuf_len16 = 1032;
  691. ti->rbuf_cnt16=6;
  692. break;
  693. case 127: /* 63.5KB shared RAM */
  694. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  695. ti->rbuf_len4 = 1032;
  696. ti->rbuf_cnt4=6;
  697. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
  698. ti->rbuf_len16 = 1032;
  699. ti->rbuf_cnt16=16;
  700. break;
  701. case 128: /* 64KB shared RAM */
  702. ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
  703. ti->rbuf_len4 = 1032;
  704. ti->rbuf_cnt4=6;
  705. ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
  706. ti->rbuf_len16 = 1032;
  707. ti->rbuf_cnt16=16;
  708. break;
  709. default:
  710. ti->dhb_size4mb = 2048;
  711. ti->rbuf_len4 = 1032;
  712. ti->rbuf_cnt4=2;
  713. ti->dhb_size16mb = 2048;
  714. ti->rbuf_len16 = 1032;
  715. ti->rbuf_cnt16=2;
  716. break;
  717. }
  718. /* this formula is not smart enough for the paging case
  719. ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE -
  720. ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH -
  721. DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB -
  722. SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>;
  723. */
  724. ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
  725. ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
  726. /*BMS assuming 18 bytes of Routing Information (usually works) */
  727. DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
  728. ti->maxmtu16, ti->maxmtu4);
  729. dev->base_addr = PIOaddr; /* set the value for device */
  730. dev->mem_start = ti->sram_base << 12;
  731. dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
  732. trdev_init(dev);
  733. return 0; /* Return 0 to indicate we have found a Token Ring card. */
  734. } /*ibmtr_probe1() */
  735. /*****************************************************************************/
  736. /* query the adapter for the size of shared RAM */
  737. /* the function returns the RAM size in units of 512 bytes */
  738. static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
  739. {
  740. unsigned char avail_sram_code;
  741. static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
  742. /* Adapter gives
  743. 'F' -- use RRR bits 3,2
  744. 'E' -- 8kb 'D' -- 16kb
  745. 'C' -- 32kb 'A' -- 64KB
  746. 'B' - 64KB less 512 bytes at top
  747. (WARNING ... must zero top bytes in INIT */
  748. avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
  749. if (avail_sram_code) return size_code[avail_sram_code];
  750. else /* for code 'F', must compute size from RRR(3,2) bits */
  751. return 1 <<
  752. ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
  753. }
  754. /*****************************************************************************/
  755. static int __devinit trdev_init(struct net_device *dev)
  756. {
  757. struct tok_info *ti = (struct tok_info *) dev->priv;
  758. SET_PAGE(ti->srb_page);
  759. ti->open_failure = NO ;
  760. dev->open = tok_open;
  761. dev->stop = tok_close;
  762. dev->hard_start_xmit = tok_send_packet;
  763. dev->get_stats = tok_get_stats;
  764. dev->set_multicast_list = tok_set_multicast_list;
  765. dev->change_mtu = ibmtr_change_mtu;
  766. return 0;
  767. }
  768. /*****************************************************************************/
  769. static int tok_init_card(struct net_device *dev)
  770. {
  771. struct tok_info *ti;
  772. short PIOaddr;
  773. unsigned long i;
  774. PIOaddr = dev->base_addr;
  775. ti = (struct tok_info *) dev->priv;
  776. /* Special processing for first interrupt after reset */
  777. ti->do_tok_int = FIRST_INT;
  778. /* Reset adapter */
  779. writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  780. outb(0, PIOaddr + ADAPTRESET);
  781. current->state=TASK_UNINTERRUPTIBLE;
  782. schedule_timeout(TR_RST_TIME); /* wait 50ms */
  783. outb(0, PIOaddr + ADAPTRESETREL);
  784. #ifdef ENABLE_PAGING
  785. if (ti->page_mask)
  786. writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
  787. #endif
  788. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  789. i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
  790. return i? 0 : -EAGAIN;
  791. }
  792. /*****************************************************************************/
  793. static int tok_open(struct net_device *dev)
  794. {
  795. struct tok_info *ti = (struct tok_info *) dev->priv;
  796. int i;
  797. /*the case we were left in a failure state during a previous open */
  798. if (ti->open_failure == YES) {
  799. DPRINTK("Last time you were disconnected, how about now?\n");
  800. printk("You can't insert with an ICS connector half-cocked.\n");
  801. }
  802. ti->open_status = CLOSED; /* CLOSED or OPEN */
  803. ti->sap_status = CLOSED; /* CLOSED or OPEN */
  804. ti->open_failure = NO; /* NO or YES */
  805. ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */
  806. ti->sram_phys &= ~1; /* to reverse what we do in tok_close */
  807. /* init the spinlock */
  808. spin_lock_init(&ti->lock);
  809. init_timer(&ti->tr_timer);
  810. i = tok_init_card(dev);
  811. if (i) return i;
  812. while (1){
  813. tok_open_adapter((unsigned long) dev);
  814. i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
  815. /* sig catch: estimate opening adapter takes more than .5 sec*/
  816. if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */
  817. if (i==0) break;
  818. if (ti->open_status == OPEN && ti->sap_status==OPEN) {
  819. netif_start_queue(dev);
  820. DPRINTK("Adapter is up and running\n");
  821. return 0;
  822. }
  823. current->state=TASK_INTERRUPTIBLE;
  824. i=schedule_timeout(TR_RETRY_INTERVAL); /* wait 30 seconds */
  825. if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
  826. }
  827. outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
  828. DPRINTK("TERMINATED via signal\n"); /*BMS useful */
  829. return -EAGAIN;
  830. }
  831. /*****************************************************************************/
  832. #define COMMAND_OFST 0
  833. #define OPEN_OPTIONS_OFST 8
  834. #define NUM_RCV_BUF_OFST 24
  835. #define RCV_BUF_LEN_OFST 26
  836. #define DHB_LENGTH_OFST 28
  837. #define NUM_DHB_OFST 30
  838. #define DLC_MAX_SAP_OFST 32
  839. #define DLC_MAX_STA_OFST 33
  840. static void tok_open_adapter(unsigned long dev_addr)
  841. {
  842. struct net_device *dev = (struct net_device *) dev_addr;
  843. struct tok_info *ti;
  844. int i;
  845. ti = (struct tok_info *) dev->priv;
  846. SET_PAGE(ti->init_srb_page);
  847. writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
  848. for (i = 0; i < sizeof(struct dir_open_adapter); i++)
  849. writeb(0, ti->init_srb + i);
  850. writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
  851. writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
  852. if (ti->ring_speed == 16) {
  853. writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
  854. writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
  855. writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
  856. } else {
  857. writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
  858. writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
  859. writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
  860. }
  861. writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST);
  862. writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
  863. writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
  864. ti->srb = ti->init_srb; /* We use this one in the interrupt handler */
  865. ti->srb_page = ti->init_srb_page;
  866. DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
  867. readb(ti->init_srb + NUM_DHB_OFST),
  868. ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
  869. ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
  870. ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
  871. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  872. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  873. }
  874. /*****************************************************************************/
  875. static void open_sap(unsigned char type, struct net_device *dev)
  876. {
  877. int i;
  878. struct tok_info *ti = (struct tok_info *) dev->priv;
  879. SET_PAGE(ti->srb_page);
  880. for (i = 0; i < sizeof(struct dlc_open_sap); i++)
  881. writeb(0, ti->srb + i);
  882. #define MAX_I_FIELD_OFST 14
  883. #define SAP_VALUE_OFST 16
  884. #define SAP_OPTIONS_OFST 17
  885. #define STATION_COUNT_OFST 18
  886. writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
  887. writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
  888. writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
  889. writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
  890. writeb(type, ti->srb + SAP_VALUE_OFST);
  891. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  892. }
  893. /*****************************************************************************/
  894. static void tok_set_multicast_list(struct net_device *dev)
  895. {
  896. struct tok_info *ti = (struct tok_info *) dev->priv;
  897. struct dev_mc_list *mclist;
  898. unsigned char address[4];
  899. int i;
  900. /*BMS the next line is CRUCIAL or you may be sad when you */
  901. /*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/
  902. if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return;
  903. address[0] = address[1] = address[2] = address[3] = 0;
  904. mclist = dev->mc_list;
  905. for (i = 0; i < dev->mc_count; i++) {
  906. address[0] |= mclist->dmi_addr[2];
  907. address[1] |= mclist->dmi_addr[3];
  908. address[2] |= mclist->dmi_addr[4];
  909. address[3] |= mclist->dmi_addr[5];
  910. mclist = mclist->next;
  911. }
  912. SET_PAGE(ti->srb_page);
  913. for (i = 0; i < sizeof(struct srb_set_funct_addr); i++)
  914. writeb(0, ti->srb + i);
  915. #define FUNCT_ADDRESS_OFST 6
  916. writeb(DIR_SET_FUNC_ADDR, ti->srb + COMMAND_OFST);
  917. for (i = 0; i < 4; i++)
  918. writeb(address[i], ti->srb + FUNCT_ADDRESS_OFST + i);
  919. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  920. #if TR_VERBOSE
  921. DPRINTK("Setting functional address: ");
  922. for (i=0;i<4;i++) printk("%02X ", address[i]);
  923. printk("\n");
  924. #endif
  925. }
  926. /*****************************************************************************/
  927. #define STATION_ID_OFST 4
  928. static int tok_send_packet(struct sk_buff *skb, struct net_device *dev)
  929. {
  930. struct tok_info *ti;
  931. unsigned long flags;
  932. ti = (struct tok_info *) dev->priv;
  933. netif_stop_queue(dev);
  934. /* lock against other CPUs */
  935. spin_lock_irqsave(&(ti->lock), flags);
  936. /* Save skb; we'll need it when the adapter asks for the data */
  937. ti->current_skb = skb;
  938. SET_PAGE(ti->srb_page);
  939. writeb(XMIT_UI_FRAME, ti->srb + COMMAND_OFST);
  940. writew(ti->exsap_station_id, ti->srb + STATION_ID_OFST);
  941. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  942. spin_unlock_irqrestore(&(ti->lock), flags);
  943. dev->trans_start = jiffies;
  944. return 0;
  945. }
  946. /*****************************************************************************/
  947. static int tok_close(struct net_device *dev)
  948. {
  949. struct tok_info *ti = (struct tok_info *) dev->priv;
  950. /* Important for PCMCIA hot unplug, otherwise, we'll pull the card, */
  951. /* unloading the module from memory, and then if a timer pops, ouch */
  952. del_timer_sync(&ti->tr_timer);
  953. outb(0, dev->base_addr + ADAPTRESET);
  954. ti->sram_phys |= 1;
  955. ti->open_status = CLOSED;
  956. netif_stop_queue(dev);
  957. DPRINTK("Adapter is closed.\n");
  958. return 0;
  959. }
  960. /*****************************************************************************/
  961. #define RETCODE_OFST 2
  962. #define OPEN_ERROR_CODE_OFST 6
  963. #define ASB_ADDRESS_OFST 8
  964. #define SRB_ADDRESS_OFST 10
  965. #define ARB_ADDRESS_OFST 12
  966. #define SSB_ADDRESS_OFST 14
  967. static char *printphase[]= {"Lobe media test","Physical insertion",
  968. "Address verification","Roll call poll","Request Parameters"};
  969. static char *printerror[]={"Function failure","Signal loss","Reserved",
  970. "Frequency error","Timeout","Ring failure","Ring beaconing",
  971. "Duplicate node address",
  972. "Parameter request-retry count exceeded","Remove received",
  973. "IMPL force received","Duplicate modifier",
  974. "No monitor detected","Monitor contention failed for RPL"};
  975. static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page)
  976. {
  977. if (ti->page_mask) {
  978. *page = (index >> 8) & ti->page_mask;
  979. index &= ~(ti->page_mask << 8);
  980. }
  981. return ti->sram_virt + index;
  982. }
  983. static void dir_open_adapter (struct net_device *dev)
  984. {
  985. struct tok_info *ti = (struct tok_info *) dev->priv;
  986. unsigned char ret_code;
  987. __u16 err;
  988. ti->srb = map_address(ti,
  989. ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)),
  990. &ti->srb_page);
  991. ti->ssb = map_address(ti,
  992. ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)),
  993. &ti->ssb_page);
  994. ti->arb = map_address(ti,
  995. ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)),
  996. &ti->arb_page);
  997. ti->asb = map_address(ti,
  998. ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)),
  999. &ti->asb_page);
  1000. ti->current_skb = NULL;
  1001. ret_code = readb(ti->init_srb + RETCODE_OFST);
  1002. err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST));
  1003. if (!ret_code) {
  1004. ti->open_status = OPEN; /* TR adapter is now available */
  1005. if (ti->open_mode == AUTOMATIC) {
  1006. DPRINTK("Adapter reopened.\n");
  1007. }
  1008. writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD);
  1009. open_sap(EXTENDED_SAP, dev);
  1010. return;
  1011. }
  1012. ti->open_failure = YES;
  1013. if (ret_code == 7){
  1014. if (err == 0x24) {
  1015. if (!ti->auto_speedsave) {
  1016. DPRINTK("Open failed: Adapter speed must match "
  1017. "ring speed if Automatic Ring Speed Save is "
  1018. "disabled.\n");
  1019. ti->open_action = FAIL;
  1020. }else
  1021. DPRINTK("Retrying open to adjust to "
  1022. "ring speed, ");
  1023. } else if (err == 0x2d) {
  1024. DPRINTK("Physical Insertion: No Monitor Detected, ");
  1025. printk("retrying after %ds delay...\n",
  1026. TR_RETRY_INTERVAL/HZ);
  1027. } else if (err == 0x11) {
  1028. DPRINTK("Lobe Media Function Failure (0x11), ");
  1029. printk(" retrying after %ds delay...\n",
  1030. TR_RETRY_INTERVAL/HZ);
  1031. } else {
  1032. char **prphase = printphase;
  1033. char **prerror = printerror;
  1034. DPRINTK("TR Adapter misc open failure, error code = ");
  1035. printk("0x%x, Phase: %s, Error: %s\n",
  1036. err, prphase[err/16 -1], prerror[err%16 -1]);
  1037. printk(" retrying after %ds delay...\n",
  1038. TR_RETRY_INTERVAL/HZ);
  1039. }
  1040. } else DPRINTK("open failed: ret_code = %02X..., ", ret_code);
  1041. if (ti->open_action != FAIL) {
  1042. if (ti->open_mode==AUTOMATIC){
  1043. ti->open_action = REOPEN;
  1044. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1045. return;
  1046. }
  1047. wake_up(&ti->wait_for_reset);
  1048. return;
  1049. }
  1050. DPRINTK("FAILURE, CAPUT\n");
  1051. }
  1052. /******************************************************************************/
  1053. static irqreturn_t tok_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1054. {
  1055. unsigned char status;
  1056. /* unsigned char status_even ; */
  1057. struct tok_info *ti;
  1058. struct net_device *dev;
  1059. #ifdef ENABLE_PAGING
  1060. unsigned char save_srpr;
  1061. #endif
  1062. dev = dev_id;
  1063. #if TR_VERBOSE
  1064. DPRINTK("Int from tok_driver, dev : %p irq%d regs=%p\n", dev,irq,regs);
  1065. #endif
  1066. ti = (struct tok_info *) dev->priv;
  1067. if (ti->sram_phys & 1)
  1068. return IRQ_NONE; /* PCMCIA card extraction flag */
  1069. spin_lock(&(ti->lock));
  1070. #ifdef ENABLE_PAGING
  1071. save_srpr = readb(ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1072. #endif
  1073. /* Disable interrupts till processing is finished */
  1074. writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1075. /* Reset interrupt for ISA boards */
  1076. if (ti->adapter_int_enable)
  1077. outb(0, ti->adapter_int_enable);
  1078. else /* used for PCMCIA cards */
  1079. outb(0, ti->global_int_enable);
  1080. if (ti->do_tok_int == FIRST_INT){
  1081. initial_tok_int(dev);
  1082. #ifdef ENABLE_PAGING
  1083. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1084. #endif
  1085. spin_unlock(&(ti->lock));
  1086. return IRQ_HANDLED;
  1087. }
  1088. /* Begin interrupt handler HERE inline to avoid the extra
  1089. levels of logic and call depth for the original solution. */
  1090. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD);
  1091. /*BMSstatus_even = readb (ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) */
  1092. /*BMSdebugprintk("tok_interrupt: ISRP_ODD = 0x%x ISRP_EVEN = 0x%x\n", */
  1093. /*BMS status,status_even); */
  1094. if (status & ADAP_CHK_INT) {
  1095. int i;
  1096. void __iomem *check_reason;
  1097. __u8 check_reason_page = 0;
  1098. check_reason = map_address(ti,
  1099. ntohs(readw(ti->mmio+ ACA_OFFSET+ACA_RW + WWCR_EVEN)),
  1100. &check_reason_page);
  1101. SET_PAGE(check_reason_page);
  1102. DPRINTK("Adapter check interrupt\n");
  1103. DPRINTK("8 reason bytes follow: ");
  1104. for (i = 0; i < 8; i++, check_reason++)
  1105. printk("%02X ", (int) readb(check_reason));
  1106. printk("\n");
  1107. writeb(~ADAP_CHK_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1108. status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRA_EVEN);
  1109. DPRINTK("ISRA_EVEN == 0x02%x\n",status);
  1110. ti->open_status = CLOSED;
  1111. ti->sap_status = CLOSED;
  1112. ti->open_mode = AUTOMATIC;
  1113. netif_carrier_off(dev);
  1114. netif_stop_queue(dev);
  1115. ti->open_action = RESTART;
  1116. outb(0, dev->base_addr + ADAPTRESET);
  1117. ibmtr_reset_timer(&(ti->tr_timer), dev);/*BMS try to reopen*/
  1118. spin_unlock(&(ti->lock));
  1119. return IRQ_HANDLED;
  1120. }
  1121. if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN)
  1122. & (TCR_INT | ERR_INT | ACCESS_INT)) {
  1123. DPRINTK("adapter error: ISRP_EVEN : %02x\n",
  1124. (int)readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRP_EVEN));
  1125. writeb(~(TCR_INT | ERR_INT | ACCESS_INT),
  1126. ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
  1127. status= readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRA_EVEN);/*BMS*/
  1128. DPRINTK("ISRA_EVEN == 0x02%x\n",status);/*BMS*/
  1129. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1130. #ifdef ENABLE_PAGING
  1131. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1132. #endif
  1133. spin_unlock(&(ti->lock));
  1134. return IRQ_HANDLED;
  1135. }
  1136. if (status & SRB_RESP_INT) { /* SRB response */
  1137. SET_PAGE(ti->srb_page);
  1138. #if TR_VERBOSE
  1139. DPRINTK("SRB resp: cmd=%02X rsp=%02X\n",
  1140. readb(ti->srb), readb(ti->srb + RETCODE_OFST));
  1141. #endif
  1142. switch (readb(ti->srb)) { /* SRB command check */
  1143. case XMIT_DIR_FRAME:{
  1144. unsigned char xmit_ret_code;
  1145. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1146. if (xmit_ret_code == 0xff) break;
  1147. DPRINTK("error on xmit_dir_frame request: %02X\n",
  1148. xmit_ret_code);
  1149. if (ti->current_skb) {
  1150. dev_kfree_skb_irq(ti->current_skb);
  1151. ti->current_skb = NULL;
  1152. }
  1153. /*dev->tbusy = 0;*/
  1154. netif_wake_queue(dev);
  1155. if (ti->readlog_pending)
  1156. ibmtr_readlog(dev);
  1157. break;
  1158. }
  1159. case XMIT_UI_FRAME:{
  1160. unsigned char xmit_ret_code;
  1161. xmit_ret_code = readb(ti->srb + RETCODE_OFST);
  1162. if (xmit_ret_code == 0xff) break;
  1163. DPRINTK("error on xmit_ui_frame request: %02X\n",
  1164. xmit_ret_code);
  1165. if (ti->current_skb) {
  1166. dev_kfree_skb_irq(ti->current_skb);
  1167. ti->current_skb = NULL;
  1168. }
  1169. netif_wake_queue(dev);
  1170. if (ti->readlog_pending)
  1171. ibmtr_readlog(dev);
  1172. break;
  1173. }
  1174. case DIR_OPEN_ADAPTER:
  1175. dir_open_adapter(dev);
  1176. break;
  1177. case DLC_OPEN_SAP:
  1178. if (readb(ti->srb + RETCODE_OFST)) {
  1179. DPRINTK("open_sap failed: ret_code = %02X, "
  1180. "retrying\n",
  1181. (int) readb(ti->srb + RETCODE_OFST));
  1182. ti->open_action = REOPEN;
  1183. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1184. break;
  1185. }
  1186. ti->exsap_station_id = readw(ti->srb + STATION_ID_OFST);
  1187. ti->sap_status = OPEN;/* TR adapter is now available */
  1188. if (ti->open_mode==MANUAL){
  1189. wake_up(&ti->wait_for_reset);
  1190. break;
  1191. }
  1192. netif_wake_queue(dev);
  1193. netif_carrier_on(dev);
  1194. break;
  1195. case DIR_INTERRUPT:
  1196. case DIR_MOD_OPEN_PARAMS:
  1197. case DIR_SET_GRP_ADDR:
  1198. case DIR_SET_FUNC_ADDR:
  1199. case DLC_CLOSE_SAP:
  1200. if (readb(ti->srb + RETCODE_OFST))
  1201. DPRINTK("error on %02X: %02X\n",
  1202. (int) readb(ti->srb + COMMAND_OFST),
  1203. (int) readb(ti->srb + RETCODE_OFST));
  1204. break;
  1205. case DIR_READ_LOG:
  1206. if (readb(ti->srb + RETCODE_OFST)){
  1207. DPRINTK("error on dir_read_log: %02X\n",
  1208. (int) readb(ti->srb + RETCODE_OFST));
  1209. netif_wake_queue(dev);
  1210. break;
  1211. }
  1212. #if IBMTR_DEBUG_MESSAGES
  1213. #define LINE_ERRORS_OFST 0
  1214. #define INTERNAL_ERRORS_OFST 1
  1215. #define BURST_ERRORS_OFST 2
  1216. #define AC_ERRORS_OFST 3
  1217. #define ABORT_DELIMITERS_OFST 4
  1218. #define LOST_FRAMES_OFST 6
  1219. #define RECV_CONGEST_COUNT_OFST 7
  1220. #define FRAME_COPIED_ERRORS_OFST 8
  1221. #define FREQUENCY_ERRORS_OFST 9
  1222. #define TOKEN_ERRORS_OFST 10
  1223. DPRINTK("Line errors %02X, Internal errors %02X, "
  1224. "Burst errors %02X\n" "A/C errors %02X, "
  1225. "Abort delimiters %02X, Lost frames %02X\n"
  1226. "Receive congestion count %02X, "
  1227. "Frame copied errors %02X\nFrequency errors %02X, "
  1228. "Token errors %02X\n",
  1229. (int) readb(ti->srb + LINE_ERRORS_OFST),
  1230. (int) readb(ti->srb + INTERNAL_ERRORS_OFST),
  1231. (int) readb(ti->srb + BURST_ERRORS_OFST),
  1232. (int) readb(ti->srb + AC_ERRORS_OFST),
  1233. (int) readb(ti->srb + ABORT_DELIMITERS_OFST),
  1234. (int) readb(ti->srb + LOST_FRAMES_OFST),
  1235. (int) readb(ti->srb + RECV_CONGEST_COUNT_OFST),
  1236. (int) readb(ti->srb + FRAME_COPIED_ERRORS_OFST),
  1237. (int) readb(ti->srb + FREQUENCY_ERRORS_OFST),
  1238. (int) readb(ti->srb + TOKEN_ERRORS_OFST));
  1239. #endif
  1240. netif_wake_queue(dev);
  1241. break;
  1242. default:
  1243. DPRINTK("Unknown command %02X encountered\n",
  1244. (int) readb(ti->srb));
  1245. } /* end switch SRB command check */
  1246. writeb(~SRB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1247. } /* if SRB response */
  1248. if (status & ASB_FREE_INT) { /* ASB response */
  1249. SET_PAGE(ti->asb_page);
  1250. #if TR_VERBOSE
  1251. DPRINTK("ASB resp: cmd=%02X\n", readb(ti->asb));
  1252. #endif
  1253. switch (readb(ti->asb)) { /* ASB command check */
  1254. case REC_DATA:
  1255. case XMIT_UI_FRAME:
  1256. case XMIT_DIR_FRAME:
  1257. break;
  1258. default:
  1259. DPRINTK("unknown command in asb %02X\n",
  1260. (int) readb(ti->asb));
  1261. } /* switch ASB command check */
  1262. if (readb(ti->asb + 2) != 0xff) /* checks ret_code */
  1263. DPRINTK("ASB error %02X in cmd %02X\n",
  1264. (int) readb(ti->asb + 2), (int) readb(ti->asb));
  1265. writeb(~ASB_FREE_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1266. } /* if ASB response */
  1267. #define STATUS_OFST 6
  1268. #define NETW_STATUS_OFST 6
  1269. if (status & ARB_CMD_INT) { /* ARB response */
  1270. SET_PAGE(ti->arb_page);
  1271. #if TR_VERBOSE
  1272. DPRINTK("ARB resp: cmd=%02X\n", readb(ti->arb));
  1273. #endif
  1274. switch (readb(ti->arb)) { /* ARB command check */
  1275. case DLC_STATUS:
  1276. DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
  1277. ntohs(readw(ti->arb + STATUS_OFST)),
  1278. ntohs(readw(ti->arb+ STATION_ID_OFST)));
  1279. break;
  1280. case REC_DATA:
  1281. tr_rx(dev);
  1282. break;
  1283. case RING_STAT_CHANGE:{
  1284. unsigned short ring_status;
  1285. ring_status= ntohs(readw(ti->arb + NETW_STATUS_OFST));
  1286. if (ibmtr_debug_trace & TRC_INIT)
  1287. DPRINTK("Ring Status Change...(0x%x)\n",
  1288. ring_status);
  1289. if(ring_status& (REMOVE_RECV|AUTO_REMOVAL|LOBE_FAULT)){
  1290. netif_stop_queue(dev);
  1291. netif_carrier_off(dev);
  1292. DPRINTK("Remove received, or Auto-removal error"
  1293. ", or Lobe fault\n");
  1294. DPRINTK("We'll try to reopen the closed adapter"
  1295. " after a %d second delay.\n",
  1296. TR_RETRY_INTERVAL/HZ);
  1297. /*I was confused: I saw the TR reopening but */
  1298. /*forgot:with an RJ45 in an RJ45/ICS adapter */
  1299. /*but adapter not in the ring, the TR will */
  1300. /* open, and then soon close and come here. */
  1301. ti->open_mode = AUTOMATIC;
  1302. ti->open_status = CLOSED; /*12/2000 BMS*/
  1303. ti->open_action = REOPEN;
  1304. ibmtr_reset_timer(&(ti->tr_timer), dev);
  1305. } else if (ring_status & LOG_OVERFLOW) {
  1306. if(netif_queue_stopped(dev))
  1307. ti->readlog_pending = 1;
  1308. else
  1309. ibmtr_readlog(dev);
  1310. }
  1311. break;
  1312. }
  1313. case XMIT_DATA_REQ:
  1314. tr_tx(dev);
  1315. break;
  1316. default:
  1317. DPRINTK("Unknown command %02X in arb\n",
  1318. (int) readb(ti->arb));
  1319. break;
  1320. } /* switch ARB command check */
  1321. writeb(~ARB_CMD_INT, ti->mmio+ ACA_OFFSET+ACA_RESET + ISRP_ODD);
  1322. writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1323. } /* if ARB response */
  1324. if (status & SSB_RESP_INT) { /* SSB response */
  1325. unsigned char retcode;
  1326. SET_PAGE(ti->ssb_page);
  1327. #if TR_VERBOSE
  1328. DPRINTK("SSB resp: cmd=%02X rsp=%02X\n",
  1329. readb(ti->ssb), readb(ti->ssb + 2));
  1330. #endif
  1331. switch (readb(ti->ssb)) { /* SSB command check */
  1332. case XMIT_DIR_FRAME:
  1333. case XMIT_UI_FRAME:
  1334. retcode = readb(ti->ssb + 2);
  1335. if (retcode && (retcode != 0x22))/* checks ret_code */
  1336. DPRINTK("xmit ret_code: %02X xmit error code: "
  1337. "%02X\n",
  1338. (int)retcode, (int)readb(ti->ssb + 6));
  1339. else
  1340. ti->tr_stats.tx_packets++;
  1341. break;
  1342. case XMIT_XID_CMD:
  1343. DPRINTK("xmit xid ret_code: %02X\n",
  1344. (int) readb(ti->ssb + 2));
  1345. default:
  1346. DPRINTK("Unknown command %02X in ssb\n",
  1347. (int) readb(ti->ssb));
  1348. } /* SSB command check */
  1349. writeb(~SSB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
  1350. writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1351. } /* if SSB response */
  1352. #ifdef ENABLE_PAGING
  1353. writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1354. #endif
  1355. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1356. spin_unlock(&(ti->lock));
  1357. return IRQ_HANDLED;
  1358. } /*tok_interrupt */
  1359. /*****************************************************************************/
  1360. #define INIT_STATUS_OFST 1
  1361. #define INIT_STATUS_2_OFST 2
  1362. #define ENCODED_ADDRESS_OFST 8
  1363. static void initial_tok_int(struct net_device *dev)
  1364. {
  1365. __u32 encoded_addr, hw_encoded_addr;
  1366. struct tok_info *ti;
  1367. unsigned char init_status; /*BMS 12/2000*/
  1368. ti = (struct tok_info *) dev->priv;
  1369. ti->do_tok_int = NOT_FIRST;
  1370. /* we assign the shared-ram address for ISA devices */
  1371. writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN);
  1372. #ifndef PCMCIA
  1373. ti->sram_virt = ioremap(((__u32)ti->sram_base << 12), ti->avail_shared_ram);
  1374. #endif
  1375. ti->init_srb = map_address(ti,
  1376. ntohs(readw(ti->mmio + ACA_OFFSET + WRBR_EVEN)),
  1377. &ti->init_srb_page);
  1378. if (ti->page_mask && ti->avail_shared_ram == 127) {
  1379. void __iomem *last_512;
  1380. __u8 last_512_page=0;
  1381. int i;
  1382. last_512 = map_address(ti, 0xfe00, &last_512_page);
  1383. /* initialize high section of ram (if necessary) */
  1384. SET_PAGE(last_512_page);
  1385. for (i = 0; i < 512; i++)
  1386. writeb(0, last_512 + i);
  1387. }
  1388. SET_PAGE(ti->init_srb_page);
  1389. #if TR_VERBOSE
  1390. {
  1391. int i;
  1392. DPRINTK("ti->init_srb_page=0x%x\n", ti->init_srb_page);
  1393. DPRINTK("init_srb(%p):", ti->init_srb );
  1394. for (i = 0; i < 20; i++)
  1395. printk("%02X ", (int) readb(ti->init_srb + i));
  1396. printk("\n");
  1397. }
  1398. #endif
  1399. hw_encoded_addr = readw(ti->init_srb + ENCODED_ADDRESS_OFST);
  1400. encoded_addr = ntohs(hw_encoded_addr);
  1401. init_status= /*BMS 12/2000 check for shallow mode possibility (Turbo)*/
  1402. readb(ti->init_srb+offsetof(struct srb_init_response,init_status));
  1403. /*printk("Initial interrupt: init_status= 0x%02x\n",init_status);*/
  1404. ti->ring_speed = init_status & 0x01 ? 16 : 4;
  1405. DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
  1406. ti->ring_speed, (unsigned int)dev->mem_start);
  1407. ti->auto_speedsave=readb(ti->init_srb+INIT_STATUS_2_OFST)&4?TRUE:FALSE;
  1408. if (ti->open_mode == MANUAL) wake_up(&ti->wait_for_reset);
  1409. else tok_open_adapter((unsigned long)dev);
  1410. } /*initial_tok_int() */
  1411. /*****************************************************************************/
  1412. #define CMD_CORRELATE_OFST 1
  1413. #define DHB_ADDRESS_OFST 6
  1414. #define FRAME_LENGTH_OFST 6
  1415. #define HEADER_LENGTH_OFST 8
  1416. #define RSAP_VALUE_OFST 9
  1417. static void tr_tx(struct net_device *dev)
  1418. {
  1419. struct tok_info *ti = (struct tok_info *) dev->priv;
  1420. struct trh_hdr *trhdr = (struct trh_hdr *) ti->current_skb->data;
  1421. unsigned int hdr_len;
  1422. __u32 dhb=0,dhb_base;
  1423. void __iomem *dhbuf = NULL;
  1424. unsigned char xmit_command;
  1425. int i,dhb_len=0x4000,src_len,src_offset;
  1426. struct trllc *llc;
  1427. struct srb_xmit xsrb;
  1428. __u8 dhb_page = 0;
  1429. __u8 llc_ssap;
  1430. SET_PAGE(ti->asb_page);
  1431. if (readb(ti->asb+RETCODE_OFST) != 0xFF) DPRINTK("ASB not free !!!\n");
  1432. /* in providing the transmit interrupts, is telling us it is ready for
  1433. data and providing a shared memory address for us to stuff with data.
  1434. Here we compute the effective address where we will place data.
  1435. */
  1436. SET_PAGE(ti->arb_page);
  1437. dhb=dhb_base=ntohs(readw(ti->arb + DHB_ADDRESS_OFST));
  1438. if (ti->page_mask) {
  1439. dhb_page = (dhb_base >> 8) & ti->page_mask;
  1440. dhb=dhb_base & ~(ti->page_mask << 8);
  1441. }
  1442. dhbuf = ti->sram_virt + dhb;
  1443. /* Figure out the size of the 802.5 header */
  1444. if (!(trhdr->saddr[0] & 0x80)) /* RIF present? */
  1445. hdr_len = sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1446. else
  1447. hdr_len = ((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK) >> 8)
  1448. + sizeof(struct trh_hdr) - TR_MAXRIFLEN;
  1449. llc = (struct trllc *) (ti->current_skb->data + hdr_len);
  1450. llc_ssap = llc->ssap;
  1451. SET_PAGE(ti->srb_page);
  1452. memcpy_fromio(&xsrb, ti->srb, sizeof(xsrb));
  1453. SET_PAGE(ti->asb_page);
  1454. xmit_command = xsrb.command;
  1455. writeb(xmit_command, ti->asb + COMMAND_OFST);
  1456. writew(xsrb.station_id, ti->asb + STATION_ID_OFST);
  1457. writeb(llc_ssap, ti->asb + RSAP_VALUE_OFST);
  1458. writeb(xsrb.cmd_corr, ti->asb + CMD_CORRELATE_OFST);
  1459. writeb(0, ti->asb + RETCODE_OFST);
  1460. if ((xmit_command == XMIT_XID_CMD) || (xmit_command == XMIT_TEST_CMD)) {
  1461. writew(htons(0x11), ti->asb + FRAME_LENGTH_OFST);
  1462. writeb(0x0e, ti->asb + HEADER_LENGTH_OFST);
  1463. SET_PAGE(dhb_page);
  1464. writeb(AC, dhbuf);
  1465. writeb(LLC_FRAME, dhbuf + 1);
  1466. for (i = 0; i < TR_ALEN; i++)
  1467. writeb((int) 0x0FF, dhbuf + i + 2);
  1468. for (i = 0; i < TR_ALEN; i++)
  1469. writeb(0, dhbuf + i + TR_ALEN + 2);
  1470. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1471. return;
  1472. }
  1473. /*
  1474. * the token ring packet is copied from sk_buff to the adapter
  1475. * buffer identified in the command data received with the interrupt.
  1476. */
  1477. writeb(hdr_len, ti->asb + HEADER_LENGTH_OFST);
  1478. writew(htons(ti->current_skb->len), ti->asb + FRAME_LENGTH_OFST);
  1479. src_len=ti->current_skb->len;
  1480. src_offset=0;
  1481. dhb=dhb_base;
  1482. while(1) {
  1483. if (ti->page_mask) {
  1484. dhb_page=(dhb >> 8) & ti->page_mask;
  1485. dhb=dhb & ~(ti->page_mask << 8);
  1486. dhb_len=0x4000-dhb; /* remaining size of this page */
  1487. }
  1488. dhbuf = ti->sram_virt + dhb;
  1489. SET_PAGE(dhb_page);
  1490. if (src_len > dhb_len) {
  1491. memcpy_toio(dhbuf,&ti->current_skb->data[src_offset],
  1492. dhb_len);
  1493. src_len -= dhb_len;
  1494. src_offset += dhb_len;
  1495. dhb_base+=dhb_len;
  1496. dhb=dhb_base;
  1497. continue;
  1498. }
  1499. memcpy_toio(dhbuf, &ti->current_skb->data[src_offset], src_len);
  1500. break;
  1501. }
  1502. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1503. ti->tr_stats.tx_bytes += ti->current_skb->len;
  1504. dev_kfree_skb_irq(ti->current_skb);
  1505. ti->current_skb = NULL;
  1506. netif_wake_queue(dev);
  1507. if (ti->readlog_pending)
  1508. ibmtr_readlog(dev);
  1509. } /*tr_tx */
  1510. /*****************************************************************************/
  1511. #define RECEIVE_BUFFER_OFST 6
  1512. #define LAN_HDR_LENGTH_OFST 8
  1513. #define DLC_HDR_LENGTH_OFST 9
  1514. #define DSAP_OFST 0
  1515. #define SSAP_OFST 1
  1516. #define LLC_OFST 2
  1517. #define PROTID_OFST 3
  1518. #define ETHERTYPE_OFST 6
  1519. static void tr_rx(struct net_device *dev)
  1520. {
  1521. struct tok_info *ti = (struct tok_info *) dev->priv;
  1522. __u32 rbuffer;
  1523. void __iomem *rbuf, *rbufdata, *llc;
  1524. __u8 rbuffer_page = 0;
  1525. unsigned char *data;
  1526. unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length;
  1527. unsigned char dlc_hdr_len;
  1528. struct sk_buff *skb;
  1529. unsigned int skb_size = 0;
  1530. int IPv4_p = 0;
  1531. unsigned int chksum = 0;
  1532. struct iphdr *iph;
  1533. struct arb_rec_req rarb;
  1534. SET_PAGE(ti->arb_page);
  1535. memcpy_fromio(&rarb, ti->arb, sizeof(rarb));
  1536. rbuffer = ntohs(rarb.rec_buf_addr) ;
  1537. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1538. SET_PAGE(ti->asb_page);
  1539. if (readb(ti->asb + RETCODE_OFST) !=0xFF) DPRINTK("ASB not free !!!\n");
  1540. writeb(REC_DATA, ti->asb + COMMAND_OFST);
  1541. writew(rarb.station_id, ti->asb + STATION_ID_OFST);
  1542. writew(rarb.rec_buf_addr, ti->asb + RECEIVE_BUFFER_OFST);
  1543. lan_hdr_len = rarb.lan_hdr_len;
  1544. if (lan_hdr_len > sizeof(struct trh_hdr)) {
  1545. DPRINTK("Linux cannot handle greater than 18 bytes RIF\n");
  1546. return;
  1547. } /*BMS I added this above just to be very safe */
  1548. dlc_hdr_len = readb(ti->arb + DLC_HDR_LENGTH_OFST);
  1549. hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr);
  1550. SET_PAGE(rbuffer_page);
  1551. llc = rbuf + offsetof(struct rec_buf, data) + lan_hdr_len;
  1552. #if TR_VERBOSE
  1553. DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
  1554. (__u32) offsetof(struct rec_buf, data), (unsigned int) lan_hdr_len);
  1555. DPRINTK("llc: %08X rec_buf_addr: %04X dev->mem_start: %lX\n",
  1556. llc, ntohs(rarb.rec_buf_addr), dev->mem_start);
  1557. DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
  1558. "ethertype: %04X\n",
  1559. (int) readb(llc + DSAP_OFST), (int) readb(llc + SSAP_OFST),
  1560. (int) readb(llc + LLC_OFST), (int) readb(llc + PROTID_OFST),
  1561. (int) readb(llc+PROTID_OFST+1),(int)readb(llc+PROTID_OFST + 2),
  1562. (int) ntohs(readw(llc + ETHERTYPE_OFST)));
  1563. #endif
  1564. if (readb(llc + offsetof(struct trllc, llc)) != UI_CMD) {
  1565. SET_PAGE(ti->asb_page);
  1566. writeb(DATA_LOST, ti->asb + RETCODE_OFST);
  1567. ti->tr_stats.rx_dropped++;
  1568. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1569. return;
  1570. }
  1571. length = ntohs(rarb.frame_len);
  1572. if (readb(llc + DSAP_OFST) == EXTENDED_SAP &&
  1573. readb(llc + SSAP_OFST) == EXTENDED_SAP &&
  1574. length >= hdr_len) IPv4_p = 1;
  1575. #if TR_VERBOSE
  1576. #define SADDR_OFST 8
  1577. #define DADDR_OFST 2
  1578. if (!IPv4_p) {
  1579. void __iomem *trhhdr = rbuf + offsetof(struct rec_buf, data);
  1580. DPRINTK("Probably non-IP frame received.\n");
  1581. DPRINTK("ssap: %02X dsap: %02X "
  1582. "saddr: %02X:%02X:%02X:%02X:%02X:%02X "
  1583. "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n",
  1584. readb(llc + SSAP_OFST), readb(llc + DSAP_OFST),
  1585. readb(trhhdr+SADDR_OFST), readb(trhhdr+ SADDR_OFST+1),
  1586. readb(trhhdr+SADDR_OFST+2), readb(trhhdr+SADDR_OFST+3),
  1587. readb(trhhdr+SADDR_OFST+4), readb(trhhdr+SADDR_OFST+5),
  1588. readb(trhhdr+DADDR_OFST), readb(trhhdr+DADDR_OFST + 1),
  1589. readb(trhhdr+DADDR_OFST+2), readb(trhhdr+DADDR_OFST+3),
  1590. readb(trhhdr+DADDR_OFST+4), readb(trhhdr+DADDR_OFST+5));
  1591. }
  1592. #endif
  1593. /*BMS handle the case she comes in with few hops but leaves with many */
  1594. skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
  1595. if (!(skb = dev_alloc_skb(skb_size))) {
  1596. DPRINTK("out of memory. frame dropped.\n");
  1597. ti->tr_stats.rx_dropped++;
  1598. SET_PAGE(ti->asb_page);
  1599. writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
  1600. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1601. return;
  1602. }
  1603. /*BMS again, if she comes in with few but leaves with many */
  1604. skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len);
  1605. skb_put(skb, length);
  1606. skb->dev = dev;
  1607. data = skb->data;
  1608. rbuffer_len = ntohs(readw(rbuf + offsetof(struct rec_buf, buf_len)));
  1609. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1610. if (IPv4_p) {
  1611. /* Copy the headers without checksumming */
  1612. memcpy_fromio(data, rbufdata, hdr_len);
  1613. /* Watch for padded packets and bogons */
  1614. iph= (struct iphdr *)(data+ lan_hdr_len + sizeof(struct trllc));
  1615. ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr);
  1616. length -= hdr_len;
  1617. if ((ip_len <= length) && (ip_len > 7))
  1618. length = ip_len;
  1619. data += hdr_len;
  1620. rbuffer_len -= hdr_len;
  1621. rbufdata += hdr_len;
  1622. }
  1623. /* Copy the payload... */
  1624. #define BUFFER_POINTER_OFST 2
  1625. #define BUFFER_LENGTH_OFST 6
  1626. for (;;) {
  1627. if (ibmtr_debug_trace&TRC_INITV && length < rbuffer_len)
  1628. DPRINTK("CURIOUS, length=%d < rbuffer_len=%d\n",
  1629. length,rbuffer_len);
  1630. if (IPv4_p)
  1631. chksum=csum_partial_copy_nocheck((void*)rbufdata,
  1632. data,length<rbuffer_len?length:rbuffer_len,chksum);
  1633. else
  1634. memcpy_fromio(data, rbufdata, rbuffer_len);
  1635. rbuffer = ntohs(readw(rbuf+BUFFER_POINTER_OFST)) ;
  1636. if (!rbuffer)
  1637. break;
  1638. rbuffer -= 2;
  1639. length -= rbuffer_len;
  1640. data += rbuffer_len;
  1641. rbuf = map_address(ti, rbuffer, &rbuffer_page);
  1642. SET_PAGE(rbuffer_page);
  1643. rbuffer_len = ntohs(readw(rbuf + BUFFER_LENGTH_OFST));
  1644. rbufdata = rbuf + offsetof(struct rec_buf, data);
  1645. }
  1646. SET_PAGE(ti->asb_page);
  1647. writeb(0, ti->asb + offsetof(struct asb_rec, ret_code));
  1648. writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1649. ti->tr_stats.rx_bytes += skb->len;
  1650. ti->tr_stats.rx_packets++;
  1651. skb->protocol = tr_type_trans(skb, dev);
  1652. if (IPv4_p) {
  1653. skb->csum = chksum;
  1654. skb->ip_summed = 1;
  1655. }
  1656. netif_rx(skb);
  1657. dev->last_rx = jiffies;
  1658. } /*tr_rx */
  1659. /*****************************************************************************/
  1660. static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
  1661. {
  1662. tmr->expires = jiffies + TR_RETRY_INTERVAL;
  1663. tmr->data = (unsigned long) dev;
  1664. tmr->function = tok_rerun;
  1665. init_timer(tmr);
  1666. add_timer(tmr);
  1667. }
  1668. /*****************************************************************************/
  1669. void tok_rerun(unsigned long dev_addr){
  1670. struct net_device *dev = (struct net_device *)dev_addr;
  1671. struct tok_info *ti = (struct tok_info *) dev->priv;
  1672. if ( ti->open_action == RESTART){
  1673. ti->do_tok_int = FIRST_INT;
  1674. outb(0, dev->base_addr + ADAPTRESETREL);
  1675. #ifdef ENABLE_PAGING
  1676. if (ti->page_mask)
  1677. writeb(SRPR_ENABLE_PAGING,
  1678. ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
  1679. #endif
  1680. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1681. } else
  1682. tok_open_adapter(dev_addr);
  1683. }
  1684. /*****************************************************************************/
  1685. static void ibmtr_readlog(struct net_device *dev)
  1686. {
  1687. struct tok_info *ti;
  1688. ti = (struct tok_info *) dev->priv;
  1689. ti->readlog_pending = 0;
  1690. SET_PAGE(ti->srb_page);
  1691. writeb(DIR_READ_LOG, ti->srb);
  1692. writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
  1693. writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
  1694. netif_stop_queue(dev);
  1695. }
  1696. /*****************************************************************************/
  1697. /* tok_get_stats(): Basically a scaffold routine which will return
  1698. the address of the tr_statistics structure associated with
  1699. this device -- the tr.... structure is an ethnet look-alike
  1700. so at least for this iteration may suffice. */
  1701. static struct net_device_stats *tok_get_stats(struct net_device *dev)
  1702. {
  1703. struct tok_info *toki;
  1704. toki = (struct tok_info *) dev->priv;
  1705. return (struct net_device_stats *) &toki->tr_stats;
  1706. }
  1707. /*****************************************************************************/
  1708. static int ibmtr_change_mtu(struct net_device *dev, int mtu)
  1709. {
  1710. struct tok_info *ti = (struct tok_info *) dev->priv;
  1711. if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
  1712. return -EINVAL;
  1713. if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
  1714. return -EINVAL;
  1715. dev->mtu = mtu;
  1716. return 0;
  1717. }
  1718. /*****************************************************************************/
  1719. #ifdef MODULE
  1720. /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
  1721. static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS];
  1722. static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 };
  1723. static int irq[IBMTR_MAX_ADAPTERS];
  1724. static int mem[IBMTR_MAX_ADAPTERS];
  1725. MODULE_LICENSE("GPL");
  1726. module_param_array(io, int, NULL, 0);
  1727. module_param_array(irq, int, NULL, 0);
  1728. module_param_array(mem, int, NULL, 0);
  1729. static int __init ibmtr_init(void)
  1730. {
  1731. int i;
  1732. int count=0;
  1733. find_turbo_adapters(io);
  1734. for (i = 0; io[i] && (i < IBMTR_MAX_ADAPTERS); i++) {
  1735. struct net_device *dev;
  1736. irq[i] = 0;
  1737. mem[i] = 0;
  1738. dev = alloc_trdev(sizeof(struct tok_info));
  1739. if (dev == NULL) {
  1740. if (i == 0)
  1741. return -ENOMEM;
  1742. break;
  1743. }
  1744. dev->base_addr = io[i];
  1745. dev->irq = irq[i];
  1746. dev->mem_start = mem[i];
  1747. if (ibmtr_probe_card(dev)) {
  1748. free_netdev(dev);
  1749. continue;
  1750. }
  1751. dev_ibmtr[i] = dev;
  1752. count++;
  1753. }
  1754. if (count) return 0;
  1755. printk("ibmtr: register_netdev() returned non-zero.\n");
  1756. return -EIO;
  1757. }
  1758. module_init(ibmtr_init);
  1759. static void __exit ibmtr_cleanup(void)
  1760. {
  1761. int i;
  1762. for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){
  1763. if (!dev_ibmtr[i])
  1764. continue;
  1765. unregister_netdev(dev_ibmtr[i]);
  1766. ibmtr_cleanup_card(dev_ibmtr[i]);
  1767. free_netdev(dev_ibmtr[i]);
  1768. }
  1769. }
  1770. module_exit(ibmtr_cleanup);
  1771. #endif