ibmtr.c 62 KB

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