* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / net / tokenring / ibmtr.c
blob85cdfb77448baf7ae993874c6ed5eeb442788856
1 /* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux
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 Public License, incorporated herein by reference.
7 * This device driver should work with Any IBM Token Ring Card that does
8 * not use DMA.
10 * I used Donald Becker's (becker@cesdis.gsfc.nasa.gov) device driver work
11 * as a base for most of my initial work.
13 * Changes by Peter De Schrijver (Peter.Deschrijver@linux.cc.kuleuven.ac.be) :
15 * + changed name to ibmtr.c in anticipation of other tr boards.
16 * + changed reset code and adapter open code.
17 * + added SAP open code.
18 * + a first attempt to write interrupt, transmit and receive routines.
20 * Changes by David W. Morris (dwm@shell.portal.com) :
21 * 941003 dwm: - Restructure tok_probe for multiple adapters, devices.
22 * + Add comments, misc reorg for clarity.
23 * + Flatten interrupt handler levels.
25 * Changes by Farzad Farid (farzy@zen.via.ecp.fr)
26 * and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) :
27 * + multi ring support clean up.
28 * + RFC1042 compliance enhanced.
30 * Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) :
31 * + bug correction in tr_tx
32 * + removed redundant information display
33 * + some code reworking
35 * Changes by Michel Lespinasse (walken@via.ecp.fr),
36 * Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr)
37 * (February 18, 1996) :
38 * + modified shared memory and mmio access port the driver to
39 * alpha platform (structure access -> readb/writeb)
41 * Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com)
42 * (January 18 1996):
43 * + swapped WWOR and WWCR in ibmtr.h
44 * + moved some init code from tok_probe into trdev_init. The
45 * PCMCIA code can call trdev_init to complete initializing
46 * the driver.
47 * + added -DPCMCIA to support PCMCIA
48 * + detecting PCMCIA Card Removal in interrupt handler. If
49 * ISRP is FF, then a PCMCIA card has been removed
51 * Changes by Paul Norton (pnorton@cts.com) :
52 * + restructured the READ.LOG logic to prevent the transmit SRB
53 * from being rudely overwritten before the transmit cycle is
54 * complete. (August 15 1996)
55 * + completed multiple adapter support. (November 20 1996)
56 * + implemented csum_partial_copy in tr_rx and increased receive
57 * buffer size and count. Minor fixes. (March 15, 1997)
59 * Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk>
60 * + Now compiles ok as a module again.
62 * Changes by Paul Norton (pnorton@ieee.org) :
63 * + moved the header manipulation code in tr_tx and tr_rx to
64 * net/802/tr.c. (July 12 1997)
65 * + add retry and timeout on open if cable disconnected. (May 5 1998)
66 * + lifted 2000 byte mtu limit. now depends on shared-RAM size.
67 * May 25 1998)
68 * + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998)
70 * Changes by Joel Sloan (jjs@c-me.com) :
71 * + disable verbose debug messages by default - to enable verbose
72 * debugging, edit the IBMTR_DEBUG_MESSAGES define below
74 * Changes by Mike Phillips <phillim@amtrak.com> :
75 * + Added extra #ifdef's to work with new PCMCIA Token Ring Code.
76 * The PCMCIA code now just sets up the card so it can be recognized
77 * by ibmtr_probe. Also checks allocated memory vs. on-board memory
78 * for correct figure to use.
80 * Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) :
81 * + added spinlocks for SMP sanity (10 March 1999)
83 * Changes by Jochen Friedrich to enable RFC1469 Option 2 multicasting
84 * i.e. using functional address C0 00 00 04 00 00 to transmit and
85 * receive multicast packets.
88 /* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
89 in the event that chatty debug messages are desired - jjs 12/30/98 */
91 #define IBMTR_DEBUG_MESSAGES 0
93 #ifdef PCMCIA
94 #define MODULE
95 #endif
97 #include <linux/module.h>
99 #ifdef PCMCIA
100 #undef MODULE
101 #endif
103 #define NO_AUTODETECT 1
104 #undef NO_AUTODETECT
105 #undef ENABLE_PAGING
108 #define FALSE 0
109 #define TRUE (!FALSE)
111 /* changes the output format of driver initialisation */
112 #define TR_NEWFORMAT 1
113 #define TR_VERBOSE 0
115 /* some 95 OS send many non UI frame; this allow removing the warning */
116 #define TR_FILTERNONUI 1
118 /* version and credits */
119 static char *version =
120 "ibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
121 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
122 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n";
124 static char pcchannelid[] = {
125 0x05, 0x00, 0x04, 0x09,
126 0x04, 0x03, 0x04, 0x0f,
127 0x03, 0x06, 0x03, 0x01,
128 0x03, 0x01, 0x03, 0x00,
129 0x03, 0x09, 0x03, 0x09,
130 0x03, 0x00, 0x02, 0x00
133 static char mcchannelid[] = {
134 0x04, 0x0d, 0x04, 0x01,
135 0x05, 0x02, 0x05, 0x03,
136 0x03, 0x06, 0x03, 0x03,
137 0x05, 0x08, 0x03, 0x04,
138 0x03, 0x05, 0x03, 0x01,
139 0x03, 0x08, 0x02, 0x00
142 #include <linux/kernel.h>
143 #include <linux/sched.h>
144 #include <linux/errno.h>
145 #include <linux/timer.h>
146 #include <linux/in.h>
147 #include <linux/ioport.h>
148 #include <linux/string.h>
149 #include <linux/skbuff.h>
150 #include <linux/interrupt.h>
151 #include <linux/delay.h>
152 #include <linux/netdevice.h>
153 #include <linux/trdevice.h>
154 #include <linux/stddef.h>
155 #include <linux/init.h>
156 #include <linux/spinlock.h>
157 #include <net/checksum.h>
159 #include <asm/io.h>
160 #include <asm/system.h>
161 #include <asm/bitops.h>
163 #include "ibmtr.h"
166 #define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
167 #define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
168 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
169 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
171 #if TR_NEWFORMAT
172 /* this allows displaying full adapter information */
174 const char *channel_def[] __initdata = {
175 "ISA", "MCA", "ISA P&P"
178 char __init *adapter_def(char type)
180 switch (type)
182 case 0xF : return "PC Adapter | PC Adapter II | Adapter/A";
183 case 0xE : return "16/4 Adapter | 16/4 Adapter/A (long)";
184 case 0xD : return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
185 case 0xC : return "Auto 16/4 Adapter";
186 default : return "adapter (unknown type)";
189 #endif
191 #if !TR_NEWFORMAT
192 unsigned char ibmtr_debug_trace=1; /* Patch or otherwise alter to
193 control tokenring tracing. */
194 #else
195 unsigned char ibmtr_debug_trace=0;
196 #endif
197 #define TRC_INIT 0x01 /* Trace initialization & PROBEs */
198 #define TRC_INITV 0x02 /* verbose init trace points */
200 int ibmtr_probe(struct net_device *dev);
201 static int ibmtr_probe1(struct net_device *dev, int ioaddr);
202 static unsigned char get_sram_size(struct tok_info *adapt_info);
203 #ifdef PCMCIA
204 extern unsigned char pcmcia_reality_check(unsigned char gss);
205 #endif
206 static int tok_init_card(struct net_device *dev);
207 void tok_interrupt(int irq, void *dev_id, struct pt_regs *regs);
208 static int trdev_init(struct net_device *dev);
209 static void initial_tok_int(struct net_device *dev);
210 static void open_sap(unsigned char type,struct net_device *dev);
211 void tok_open_adapter(unsigned long dev_addr);
212 static void tr_rx(struct net_device *dev);
213 static void tr_tx(struct net_device *dev);
214 static int tok_open(struct net_device *dev);
215 static int tok_close(struct net_device *dev);
216 static int tok_send_packet(struct sk_buff *skb, struct net_device *dev);
217 static struct net_device_stats * tok_get_stats(struct net_device *dev);
218 static void tok_set_multicast_list(struct net_device *dev);
219 void ibmtr_readlog(struct net_device *dev);
220 void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev);
221 int ibmtr_change_mtu(struct net_device *dev, int mtu);
223 static unsigned int ibmtr_portlist[] __initdata = {
224 0xa20, 0xa24, 0
227 static __u32 ibmtr_mem_base = 0xd0000;
229 static void __init PrtChanID(char *pcid, short stride)
231 short i, j;
232 for (i=0, j=0; i<24; i++, j+=stride)
233 printk("%1x", ((int) pcid[j]) & 0x0f);
234 printk("\n");
237 static void __init HWPrtChanID (__u32 pcid, short stride)
239 short i, j;
240 for (i=0, j=0; i<24; i++, j+=stride)
241 printk("%1x", ((int)readb(pcid + j)) & 0x0f);
242 printk("\n");
246 * ibmtr_probe(): Routine specified in the network device structure
247 * to probe for an IBM Token Ring Adapter. Routine outline:
248 * I. Interrogate hardware to determine if an adapter exists
249 * and what the speeds and feeds are
250 * II. Setup data structures to control execution based upon
251 * adapter characteristics.
252 * III. Initialize adapter operation
254 * We expect ibmtr_probe to be called once for each device entry
255 * which references it.
258 int __init ibmtr_probe(struct net_device *dev)
260 int i;
261 int base_addr = dev ? dev->base_addr : 0;
263 if (base_addr > 0x1ff)
266 * Check a single specified location.
269 if (ibmtr_probe1(dev, base_addr))
271 #ifndef MODULE
272 #ifndef PCMCIA
273 tr_freedev(dev);
274 #endif
275 #endif
276 return -ENODEV;
277 } else
278 return 0;
280 else if (base_addr != 0) /* Don't probe at all. */
281 return -ENXIO;
283 for (i = 0; ibmtr_portlist[i]; i++)
285 int ioaddr = ibmtr_portlist[i];
286 if (check_region(ioaddr, IBMTR_IO_EXTENT))
287 continue;
288 if (ibmtr_probe1(dev, ioaddr)) {
289 #ifndef MODULE
290 #ifndef PCMCIA
291 tr_freedev(dev);
292 #endif
293 #endif
294 } else
295 return 0;
298 return -ENODEV;
301 static int __init ibmtr_probe1(struct net_device *dev, int PIOaddr)
303 unsigned char segment=0, intr=0, irq=0, i=0, j=0, cardpresent=NOTOK,temp=0;
304 __u32 t_mmio=0;
305 struct tok_info *ti=0;
306 __u32 cd_chanid;
307 unsigned char *tchanid, ctemp;
308 unsigned long timeout;
310 #ifndef MODULE
311 #ifndef PCMCIA
312 dev = init_trdev(dev,0);
313 #endif
314 #endif
316 /* Query the adapter PIO base port which will return
317 * indication of where MMIO was placed. We also have a
318 * coded interrupt number.
321 segment = inb(PIOaddr);
324 * Out of range values so we'll assume non-existent IO device
327 if (segment < 0x40 || segment > 0xe0)
328 return -ENODEV;
331 * Compute the linear base address of the MMIO area
332 * as LINUX doesn't care about segments
335 t_mmio=(((__u32)(segment & 0xfc) << 11) + 0x80000);
336 intr = segment & 0x03; /* low bits is coded interrupt # */
337 if (ibmtr_debug_trace & TRC_INIT)
338 DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %08X intr: %d\n",
339 PIOaddr, (int)segment, t_mmio, (int)intr);
342 * Now we will compare expected 'channelid' strings with
343 * what we is there to learn of ISA/MCA or not TR card
346 cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */
347 tchanid=pcchannelid;
348 cardpresent=TR_ISA; /* try ISA */
351 * Suboptimize knowing first byte different
354 ctemp = readb(cd_chanid) & 0x0f;
355 if (ctemp != *tchanid) { /* NOT ISA card, try MCA */
356 tchanid=mcchannelid;
357 cardpresent=TR_MCA;
358 if (ctemp != *tchanid) /* Neither ISA nor MCA */
359 cardpresent=NOTOK;
362 if (cardpresent != NOTOK)
365 * Know presumed type, try rest of ID
367 for (i=2,j=1; i<=46; i=i+2,j++)
369 if ((readb(cd_chanid+i) & 0x0f) != tchanid[j]) {
370 cardpresent=NOTOK; /* match failed, not TR card */
371 break;
377 * If we have an ISA board check for the ISA P&P version,
378 * as it has different IRQ settings
381 if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio)==0x0e))
382 cardpresent=TR_ISAPNP;
384 if (cardpresent == NOTOK) { /* "channel_id" did not match, report */
385 if (ibmtr_debug_trace & TRC_INIT) {
386 DPRINTK("Channel ID string not found for PIOaddr: %4hx\n", PIOaddr);
387 DPRINTK("Expected for ISA: "); PrtChanID(pcchannelid,1);
388 DPRINTK(" found: "); HWPrtChanID(cd_chanid,2);
389 DPRINTK("Expected for MCA: "); PrtChanID(mcchannelid,1);
391 return -ENODEV;
394 /* Now, allocate some of the pl0 buffers for this driver.. */
396 /* If called from PCMCIA, ti is already set up, so no need to
397 waste the memory, just use the existing structure */
399 #ifndef PCMCIA
400 ti = (struct tok_info *)kmalloc(sizeof(struct tok_info), GFP_KERNEL);
401 if (ti == NULL)
402 return -ENOMEM;
404 memset(ti, 0, sizeof(struct tok_info));
405 #else
406 ti = dev->priv ;
407 #endif
408 ti->mmio= t_mmio;
409 ti->readlog_pending = 0;
410 init_waitqueue_head(&ti->wait_for_tok_int);
411 init_waitqueue_head(&ti->wait_for_reset);
413 dev->priv = ti; /* this seems like the logical use of the
414 field ... let's try some empirical tests
415 using the token-info structure -- that
416 should fit with out future hope of multiple
417 adapter support as well /dwm */
419 /* if PCMCIA, then the card is recognized as TR_ISAPNP
420 * and there is no need to set up the interrupt, it is already done. */
422 #ifndef PCMCIA
423 switch (cardpresent)
425 case TR_ISA:
426 if (intr==0)
427 irq=9; /* irq2 really is irq9 */
428 if (intr==1)
429 irq=3;
430 if (intr==2)
431 irq=6;
432 if (intr==3)
433 irq=7;
434 ti->global_int_enable=GLOBAL_INT_ENABLE+((irq==9) ? 2 : irq);
435 ti->adapter_int_enable=PIOaddr+ADAPTINTREL;
436 ti->sram=0;
437 #if !TR_NEWFORMAT
438 DPRINTK("ti->global_int_enable: %04X\n",ti->global_int_enable);
439 #endif
440 break;
441 case TR_MCA:
442 if (intr==0)
443 irq=9;
444 if (intr==1)
445 irq=3;
446 if (intr==2)
447 irq=10;
448 if (intr==3)
449 irq=11;
450 ti->global_int_enable=0;
451 ti->adapter_int_enable=0;
452 ti->sram=((__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12);
453 break;
454 case TR_ISAPNP:
455 if (intr==0)
456 irq=9;
457 if (intr==1)
458 irq=3;
459 if (intr==2)
460 irq=10;
461 if (intr==3)
462 irq=11;
463 timeout = jiffies + TR_SPIN_INTERVAL;
464 while(!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN))
465 if (time_after(jiffies, timeout)) {
466 DPRINTK("Hardware timeout during initialization.\n");
467 kfree_s(ti, sizeof(struct tok_info));
468 return -ENODEV;
471 ti->sram=((__u32)readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)<<12);
472 ti->global_int_enable=PIOaddr+ADAPTINTREL;
473 ti->adapter_int_enable=PIOaddr+ADAPTINTREL;
474 break;
476 #endif
478 if (ibmtr_debug_trace & TRC_INIT) { /* just report int */
479 DPRINTK("irq=%d",irq);
480 if (ibmtr_debug_trace & TRC_INITV) { /* full chat in verbose only */
481 DPRINTK(", ti->mmio=%08X",ti->mmio);
482 printk(", segment=%02X",segment);
484 printk(".\n");
487 /* Get hw address of token ring card */
488 #if !TR_NEWFORMAT
489 DPRINTK("hw address: ");
490 #endif
491 j=0;
492 for (i=0; i<0x18; i=i+2)
494 /* technical reference states to do this */
495 temp = readb(ti->mmio + AIP + i) & 0x0f;
496 #if !TR_NEWFORMAT
497 printk("%1X",ti->hw_address[j]=temp);
498 #else
499 ti->hw_address[j]=temp;
500 #endif
501 if(j&1)
502 dev->dev_addr[(j/2)]=ti->hw_address[j]+(ti->hw_address[j-1]<<4);
503 ++j;
505 #ifndef TR_NEWFORMAT
506 printk("\n");
507 #endif
509 /* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,...*/
510 ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
512 /* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
513 ti->data_rate = readb(ti->mmio + AIPDATARATE);
515 /* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
516 ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
518 /* How much shared RAM is on adapter ? */
519 #ifdef PCMCIA
520 ti->avail_shared_ram = pcmcia_reality_check(get_sram_size(ti));
521 ibmtr_mem_base = ti->sram_base << 12 ;
522 #else
523 ti->avail_shared_ram = get_sram_size(ti);
524 #endif
525 /* We need to set or do a bunch of work here based on previous results.. */
526 /* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
527 ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
529 /* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
530 switch (readb(ti->mmio + AIP4MBDHB)) {
531 case 0xe :
532 ti->dhb_size4mb = 4096;
533 break;
534 case 0xd :
535 ti->dhb_size4mb = 4464;
536 break;
537 default :
538 ti->dhb_size4mb = 2048;
539 break;
542 /* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
543 switch (readb(ti->mmio + AIP16MBDHB)) {
544 case 0xe :
545 ti->dhb_size16mb = 4096;
546 break;
547 case 0xd :
548 ti->dhb_size16mb = 8192;
549 break;
550 case 0xc :
551 ti->dhb_size16mb = 16384;
552 break;
553 case 0xb :
554 ti->dhb_size16mb = 17960;
555 break;
556 default :
557 ti->dhb_size16mb = 2048;
558 break;
561 #if !TR_NEWFORMAT
562 DPRINTK("atype=%x, drate=%x, trel=%x, asram=%dK, srp=%x, "
563 "dhb(4mb=%x, 16mb=%x)\n",ti->adapter_type,
564 ti->data_rate, ti->token_release, ti->avail_shared_ram/2,
565 ti->shared_ram_paging, ti->dhb_size4mb, ti->dhb_size16mb);
566 #endif
568 /* We must figure out how much shared memory space this adapter
569 * will occupy so that if there are two adapters we can fit both
570 * in. Given a choice, we will limit this adapter to 32K. The
571 * maximum space will will use for two adapters is 64K so if the
572 * adapter we are working on demands 64K (it also doesn't support
573 * paging), then only one adapter can be supported.
577 * determine how much of total RAM is mapped into PC space
579 ti->mapped_ram_size=1<<((((readb(ti->mmio+ ACA_OFFSET + ACA_RW + RRR_ODD)) >>2) & 0x03) + 4);
580 ti->page_mask=0;
581 if (ti->shared_ram_paging == 0xf) { /* No paging in adapter */
582 ti->mapped_ram_size = ti->avail_shared_ram;
583 } else {
584 #ifdef ENABLE_PAGING
585 unsigned char pg_size;
586 #endif
588 #if !TR_NEWFORMAT
589 DPRINTK("shared ram page size: %dK\n",ti->mapped_ram_size/2);
590 #endif
591 #ifdef ENABLE_PAGING
592 switch(ti->shared_ram_paging)
594 case 0xf:
595 break;
596 case 0xe:
597 ti->page_mask=(ti->mapped_ram_size==32) ? 0xc0 : 0;
598 pg_size=32; /* 16KB page size */
599 break;
600 case 0xd:
601 ti->page_mask=(ti->mapped_ram_size==64) ? 0x80 : 0;
602 pg_size=64; /* 32KB page size */
603 break;
604 case 0xc:
605 ti->page_mask=(ti->mapped_ram_size==32) ? 0xc0 : 0;
606 ti->page_mask=(ti->mapped_ram_size==64) ? 0x80 : 0;
607 DPRINTK("Dual size shared RAM page (code=0xC), don't support it!\n");
608 /* nb/dwm: I did this because RRR (3,2) bits are documented as
609 R/O and I can't find how to select which page size
610 Also, the above conditional statement sequence is invalid
611 as page_mask will always be set by the second stmt */
612 kfree_s(ti, sizeof(struct tok_info));
613 return -ENODEV;
614 break;
615 default:
616 DPRINTK("Unknown shared ram paging info %01X\n",ti->shared_ram_paging);
617 kfree_s(ti, sizeof(struct tok_info));
618 return -ENODEV;
619 break;
621 if (ti->page_mask) {
622 if (pg_size > ti->mapped_ram_size) {
623 DPRINTK("Page size (%d) > mapped ram window (%d), can't page.\n",
624 pg_size, ti->mapped_ram_size);
625 ti->page_mask = 0; /* reset paging */
626 } else {
627 ti->mapped_ram_size=ti->avail_shared_ram;
628 DPRINTK("Shared RAM paging enabled. Page size : %uK\n",
629 ((ti->page_mask^ 0xff)+1)>>2);
631 #endif
633 /* finish figuring the shared RAM address */
634 if (cardpresent==TR_ISA) {
635 static __u32 ram_bndry_mask[]={0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000};
636 __u32 new_base, rrr_32, chk_base, rbm;
638 rrr_32 = ((readb(ti->mmio+ ACA_OFFSET + ACA_RW + RRR_ODD))>>2) & 0x00000003;
639 rbm = ram_bndry_mask[rrr_32];
640 new_base = (ibmtr_mem_base + (~rbm)) & rbm; /* up to boundary */
641 chk_base = new_base + (ti->mapped_ram_size<<9);
642 if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
643 DPRINTK("Shared RAM for this adapter (%05x) exceeds driver"
644 " limit (%05x), adapter not started.\n",
645 chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
646 kfree_s(ti, sizeof(struct tok_info));
647 return -ENODEV;
648 } else { /* seems cool, record what we have figured out */
649 ti->sram_base = new_base >> 12;
650 ibmtr_mem_base = chk_base;
654 #if !TR_NEWFORMAT
655 DPRINTK("Using %dK shared RAM\n",ti->mapped_ram_size/2);
656 #endif
658 /* The PCMCIA has already got the interrupt line and the io port,
659 so no chance of anybody else getting it - MLP */
661 #ifndef PCMCIA
662 if (request_irq (dev->irq = irq, &tok_interrupt,0,"ibmtr", dev) != 0) {
663 DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",irq);
664 kfree_s(ti, sizeof(struct tok_info));
665 return -ENODEV;
668 /*?? Now, allocate some of the PIO PORTs for this driver.. */
669 request_region(PIOaddr,IBMTR_IO_EXTENT,"ibmtr"); /* record PIOaddr range as busy */
670 #endif
672 #if !TR_NEWFORMAT
673 DPRINTK("%s",version); /* As we have passed card identification,
674 let the world know we're here! */
675 #else
677 if (version) {
678 printk("%s",version);
679 version = NULL;
681 DPRINTK("%s %s found\n",
682 channel_def[cardpresent-1], adapter_def(ti->adapter_type));
683 DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
684 irq, PIOaddr, ti->mapped_ram_size/2);
685 DPRINTK("Hardware address : %02X:%02X:%02X:%02X:%02X:%02X\n",
686 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
687 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
688 #endif
689 /* Calculate the maximum DHB we can use */
690 switch (ti->mapped_ram_size) {
691 case 16 : /* 8KB shared RAM */
692 ti->dhb_size4mb = MIN(ti->dhb_size4mb, 2048);
693 ti->rbuf_len4 = 1032;
694 ti->rbuf_cnt4 = 2;
695 ti->dhb_size16mb = MIN(ti->dhb_size16mb, 2048);
696 ti->rbuf_len16 = 1032;
697 ti->rbuf_cnt16 = 2;
698 break;
699 case 32 : /* 16KB shared RAM */
700 ti->dhb_size4mb = MIN(ti->dhb_size4mb, 4464);
701 ti->rbuf_len4 = 520;
702 ti->rbuf_cnt4 = 9;
703 ti->dhb_size16mb = MIN(ti->dhb_size16mb, 4096);
704 ti->rbuf_len16 = 1032; /* 1024 usable */
705 ti->rbuf_cnt16 = 4;
706 break;
707 case 64 : /* 32KB shared RAM */
708 ti->dhb_size4mb = MIN(ti->dhb_size4mb, 4464);
709 ti->rbuf_len4 = 1032;
710 ti->rbuf_cnt4 = 6;
711 ti->dhb_size16mb = MIN(ti->dhb_size16mb, 10240);
712 ti->rbuf_len16 = 1032;
713 ti->rbuf_cnt16 = 10;
714 break;
715 case 127 : /* 63KB shared RAM */
716 ti->dhb_size4mb = MIN(ti->dhb_size4mb, 4464);
717 ti->rbuf_len4 = 1032;
718 ti->rbuf_cnt4 = 6;
719 ti->dhb_size16mb = MIN(ti->dhb_size16mb, 16384);
720 ti->rbuf_len16 = 1032;
721 ti->rbuf_cnt16 = 16;
722 break;
723 case 128 : /* 64KB shared RAM */
724 ti->dhb_size4mb = MIN(ti->dhb_size4mb, 4464);
725 ti->rbuf_len4 = 1032;
726 ti->rbuf_cnt4 = 6;
727 ti->dhb_size16mb = MIN(ti->dhb_size16mb, 17960);
728 ti->rbuf_len16 = 1032;
729 ti->rbuf_cnt16 = 18;
730 break;
731 default :
732 ti->dhb_size4mb = 2048;
733 ti->rbuf_len4 = 1032;
734 ti->rbuf_cnt4 = 2;
735 ti->dhb_size16mb = 2048;
736 ti->rbuf_len16 = 1032;
737 ti->rbuf_cnt16 = 2;
738 break;
741 ti->maxmtu16 = (ti->rbuf_len16*ti->rbuf_cnt16)-((ti->rbuf_cnt16)<<3)-TR_HLEN;
742 ti->maxmtu4 = (ti->rbuf_len4*ti->rbuf_cnt4)-((ti->rbuf_cnt4)<<3)-TR_HLEN;
743 DPRINTK("Maximum MTU 16Mbps: %d, 4Mbps: %d\n",
744 ti->maxmtu16, ti->maxmtu4);
746 dev->base_addr=PIOaddr; /* set the value for device */
748 trdev_init(dev);
749 tok_init_card(dev);
751 return 0; /* Return 0 to indicate we have found a Token Ring card. */
754 /* query the adapter for the size of shared RAM */
756 static unsigned char __init get_sram_size(struct tok_info *adapt_info)
759 unsigned char avail_sram_code;
760 static unsigned char size_code[]={ 0,16,32,64,127,128 };
761 /* Adapter gives
762 'F' -- use RRR bits 3,2
763 'E' -- 8kb 'D' -- 16kb
764 'C' -- 32kb 'A' -- 64KB
765 'B' - 64KB less 512 bytes at top
766 (WARNING ... must zero top bytes in INIT */
768 avail_sram_code=0xf-readb(adapt_info->mmio + AIPAVAILSHRAM);
769 if (avail_sram_code)
770 return size_code[avail_sram_code];
771 else /* for code 'F', must compute size from RRR(3,2) bits */
772 return 1<<((readb(adapt_info->mmio+ ACA_OFFSET + ACA_RW + RRR_ODD)>>2)+4);
775 static int __init trdev_init(struct net_device *dev)
777 struct tok_info *ti=(struct tok_info *)dev->priv;
779 ti->open_status = CLOSED;
781 dev->init = tok_init_card;
782 dev->open = tok_open;
783 dev->stop = tok_close;
784 dev->hard_start_xmit = tok_send_packet;
785 dev->get_stats = tok_get_stats;
786 dev->set_multicast_list = tok_set_multicast_list;
787 dev->change_mtu = ibmtr_change_mtu;
789 #ifndef MODULE
790 #ifndef PCMCIA
791 tr_setup(dev);
792 #endif
793 #endif
794 return 0;
798 static void tok_set_multicast_list(struct net_device *dev)
800 struct tok_info *ti=(struct tok_info *)dev->priv;
801 struct dev_mc_list *mclist;
802 unsigned char address[4];
804 int i;
806 address[0] = address[1] = address[2] = address[3] = 0;
808 mclist = dev->mc_list;
809 for (i=0; i< dev->mc_count; i++)
811 address[0] |= mclist->dmi_addr[2];
812 address[1] |= mclist->dmi_addr[3];
813 address[2] |= mclist->dmi_addr[4];
814 address[3] |= mclist->dmi_addr[5];
815 mclist = mclist->next;
817 SET_PAGE(ti->srb);
818 for (i=0; i<sizeof(struct srb_set_funct_addr); i++)
819 writeb(0, ti->srb+i);
821 writeb(DIR_SET_FUNC_ADDR,
822 ti->srb + offsetof(struct srb_set_funct_addr, command));
824 DPRINTK("Setting functional address: ");
826 for (i=0; i<4; i++)
828 writeb(address[i],
829 ti->srb + offsetof(struct srb_set_funct_addr, funct_address)+i);
830 printk("%02X ", address[i]);
832 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
833 printk("\n");
836 static int tok_open(struct net_device *dev)
838 struct tok_info *ti=(struct tok_info *)dev->priv;
840 /* init the spinlock */
841 ti->lock = (spinlock_t) SPIN_LOCK_UNLOCKED;
843 if (ti->open_status==CLOSED) tok_init_card(dev);
845 if (ti->open_status==IN_PROGRESS) sleep_on(&ti->wait_for_reset);
847 if (ti->open_status==SUCCESS) {
848 dev->tbusy=0;
849 dev->interrupt=0;
850 dev->start=1;
851 /* NEED to see smem size *AND* reset high 512 bytes if needed */
853 MOD_INC_USE_COUNT;
855 return 0;
856 } else return -EAGAIN;
860 static int tok_close(struct net_device *dev)
863 struct tok_info *ti=(struct tok_info *) dev->priv;
865 writeb(DIR_CLOSE_ADAPTER,
866 ti->srb + offsetof(struct srb_close_adapter, command));
867 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
869 ti->open_status=CLOSED;
871 sleep_on(&ti->wait_for_tok_int);
873 if (readb(ti->srb + offsetof(struct srb_close_adapter, ret_code)))
874 DPRINTK("close adapter failed: %02X\n",
875 (int)readb(ti->srb + offsetof(struct srb_close_adapter, ret_code)));
877 dev->start = 0;
878 #ifdef PCMCIA
879 ti->sram = 0 ;
880 #endif
881 DPRINTK("Adapter closed.\n");
882 MOD_DEC_USE_COUNT;
884 return 0;
887 void tok_interrupt (int irq, void *dev_id, struct pt_regs *regs)
889 unsigned char status;
890 struct tok_info *ti;
891 struct net_device *dev;
893 dev = dev_id;
894 #if TR_VERBOSE
895 DPRINTK("Int from tok_driver, dev : %p\n",dev);
896 #endif
897 ti = (struct tok_info *) dev->priv;
898 spin_lock(&(ti->lock));
900 /* Disable interrupts till processing is finished */
901 dev->interrupt=1;
902 writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
904 /* Reset interrupt for ISA boards */
905 if (ti->adapter_int_enable)
906 outb(0,ti->adapter_int_enable);
907 else
908 outb(0,ti->global_int_enable);
911 switch (ti->do_tok_int) {
913 case NOT_FIRST:
915 /* Begin the regular interrupt handler HERE inline to avoid
916 the extra levels of logic and call depth for the
917 original solution. */
919 status=readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD);
920 #ifdef PCMCIA
921 /* Check if the PCMCIA card was pulled. */
922 if (status == 0xFF)
924 DPRINTK("PCMCIA card removed.\n");
925 spin_unlock(&(ti->lock));
926 dev->interrupt = 0;
927 return;
930 /* Check ISRP EVEN too. */
931 if ( readb (ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN) == 0xFF)
933 DPRINTK("PCMCIA card removed.\n");
934 spin_unlock(&(ti->lock));
935 dev->interrupt = 0;
936 return;
938 #endif
941 if (status & ADAP_CHK_INT) {
943 int i;
944 __u32 check_reason;
946 check_reason=ti->mmio + ntohs(readw(ti->sram + ACA_OFFSET + ACA_RW +WWCR_EVEN));
948 DPRINTK("Adapter check interrupt\n");
949 DPRINTK("8 reason bytes follow: ");
950 for(i=0; i<8; i++, check_reason++)
951 printk("%02X ", (int)readb(check_reason));
952 printk("\n");
954 writeb((~ADAP_CHK_INT), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
955 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
956 dev->interrupt=0;
958 } else if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN)
959 & (TCR_INT | ERR_INT | ACCESS_INT)) {
961 DPRINTK("adapter error: ISRP_EVEN : %02x\n",
962 (int)readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN));
963 writeb(~(TCR_INT | ERR_INT | ACCESS_INT),
964 ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
965 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
966 dev->interrupt=0;
968 } else if (status
969 & (SRB_RESP_INT | ASB_FREE_INT | ARB_CMD_INT | SSB_RESP_INT)) {
970 /* SRB, ASB, ARB or SSB response */
972 if (status & SRB_RESP_INT) { /* SRB response */
974 switch(readb(ti->srb)) { /* SRB command check */
976 case XMIT_DIR_FRAME: {
977 unsigned char xmit_ret_code;
979 xmit_ret_code=readb(ti->srb + offsetof(struct srb_xmit, ret_code));
980 if (xmit_ret_code != 0xff) {
981 DPRINTK("error on xmit_dir_frame request: %02X\n",
982 xmit_ret_code);
983 if (ti->current_skb) {
984 dev_kfree_skb(ti->current_skb);
985 ti->current_skb=NULL;
987 dev->tbusy=0;
988 if (ti->readlog_pending) ibmtr_readlog(dev);
991 break;
993 case XMIT_UI_FRAME: {
994 unsigned char xmit_ret_code;
996 xmit_ret_code=readb(ti->srb + offsetof(struct srb_xmit, ret_code));
997 if (xmit_ret_code != 0xff) {
998 DPRINTK("error on xmit_ui_frame request: %02X\n",
999 xmit_ret_code);
1000 if (ti->current_skb) {
1001 dev_kfree_skb(ti->current_skb);
1002 ti->current_skb=NULL;
1004 dev->tbusy=0;
1005 if (ti->readlog_pending) ibmtr_readlog(dev);
1008 break;
1010 case DIR_OPEN_ADAPTER: {
1011 unsigned char open_ret_code;
1012 __u16 open_error_code;
1014 ti->srb=ti->sram+ntohs(readw(ti->init_srb +offsetof(struct srb_open_response, srb_addr)));
1015 ti->ssb=ti->sram+ntohs(readw(ti->init_srb +offsetof(struct srb_open_response, ssb_addr)));
1016 ti->arb=ti->sram+ntohs(readw(ti->init_srb +offsetof(struct srb_open_response, arb_addr)));
1017 ti->asb=ti->sram+ntohs(readw(ti->init_srb +offsetof(struct srb_open_response, asb_addr)));
1018 ti->current_skb=NULL;
1020 open_ret_code = readb(ti->init_srb +offsetof(struct srb_open_response, ret_code));
1021 open_error_code = ntohs(readw(ti->init_srb +offsetof(struct srb_open_response, error_code)));
1023 if (open_ret_code==7) {
1025 if (!ti->auto_ringspeedsave && (open_error_code==0x24)) {
1026 DPRINTK("Open failed: Adapter speed must match ring "
1027 "speed if Automatic Ring Speed Save is disabled.\n");
1028 ti->open_status=FAILURE;
1029 wake_up(&ti->wait_for_reset);
1030 } else if (open_error_code==0x24)
1031 DPRINTK("Retrying open to adjust to ring speed.\n");
1032 else if ((open_error_code==0x2d) && ti->auto_ringspeedsave)
1033 DPRINTK("No signal detected for Auto Speed Detection.\n");
1034 else if (open_error_code==0x11)
1036 if (ti->retry_count--)
1037 DPRINTK("Ring broken/disconnected, retrying...\n");
1038 else {
1039 DPRINTK("Ring broken/disconnected, open failed.\n");
1040 ti->open_status = FAILURE;
1043 else DPRINTK("Unrecoverable error: error code = %04x.\n",
1044 open_error_code);
1046 } else if (!open_ret_code) {
1047 #if !TR_NEWFORMAT
1048 DPRINTK("board opened...\n");
1049 #else
1050 DPRINTK("Adapter initialized and opened.\n");
1051 #endif
1052 writeb(~(SRB_RESP_INT),
1053 ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1054 writeb(~(CMD_IN_SRB),
1055 ti->mmio + ACA_OFFSET + ACA_RESET + ISRA_ODD);
1056 open_sap(EXTENDED_SAP,dev);
1058 /* YdW probably hates me */
1059 goto skip_reset;
1060 } else
1061 DPRINTK("open failed: ret_code = %02X, retrying\n",
1062 open_ret_code);
1064 if (ti->open_status != FAILURE) {
1065 ibmtr_reset_timer(&(ti->tr_timer), dev);
1069 break;
1071 case DIR_CLOSE_ADAPTER:
1072 wake_up(&ti->wait_for_tok_int);
1073 break;
1075 case DLC_OPEN_SAP:
1076 if (readb(ti->srb+offsetof(struct dlc_open_sap, ret_code))) {
1077 DPRINTK("open_sap failed: ret_code = %02X,retrying\n",
1078 (int)readb(ti->srb+offsetof(struct dlc_open_sap, ret_code)));
1079 ibmtr_reset_timer(&(ti->tr_timer), dev);
1080 } else {
1081 ti->exsap_station_id=
1082 readw(ti->srb+offsetof(struct dlc_open_sap, station_id));
1083 ti->open_status=SUCCESS; /* TR adapter is now available */
1084 wake_up(&ti->wait_for_reset);
1086 break;
1088 case DIR_INTERRUPT:
1089 case DIR_MOD_OPEN_PARAMS:
1090 case DIR_SET_GRP_ADDR:
1091 case DIR_SET_FUNC_ADDR:
1092 case DLC_CLOSE_SAP:
1093 if (readb(ti->srb+offsetof(struct srb_interrupt, ret_code)))
1094 DPRINTK("error on %02X: %02X\n",
1095 (int)readb(ti->srb+offsetof(struct srb_interrupt, command)),
1096 (int)readb(ti->srb+offsetof(struct srb_interrupt, ret_code)));
1097 break;
1099 case DIR_READ_LOG:
1100 if (readb(ti->srb+offsetof(struct srb_read_log, ret_code)))
1101 DPRINTK("error on dir_read_log: %02X\n",
1102 (int)readb(ti->srb+offsetof(struct srb_read_log, ret_code)));
1103 else
1104 if (IBMTR_DEBUG_MESSAGES) {
1105 DPRINTK(
1106 "Line errors %02X, Internal errors %02X, Burst errors %02X\n"
1107 "A/C errors %02X, Abort delimiters %02X, Lost frames %02X\n"
1108 "Receive congestion count %02X, Frame copied errors %02X\n"
1109 "Frequency errors %02X, Token errors %02X\n",
1110 (int)readb(ti->srb+offsetof(struct srb_read_log,
1111 line_errors)),
1112 (int)readb(ti->srb+offsetof(struct srb_read_log,
1113 internal_errors)),
1114 (int)readb(ti->srb+offsetof(struct srb_read_log,
1115 burst_errors)),
1116 (int)readb(ti->srb+offsetof(struct srb_read_log, A_C_errors)),
1117 (int)readb(ti->srb+offsetof(struct srb_read_log,
1118 abort_delimiters)),
1119 (int)readb(ti->srb+offsetof(struct srb_read_log,
1120 lost_frames)),
1121 (int)readb(ti->srb+offsetof(struct srb_read_log,
1122 recv_congest_count)),
1123 (int)readb(ti->srb+offsetof(struct srb_read_log,
1124 frame_copied_errors)),
1125 (int)readb(ti->srb+offsetof(struct srb_read_log,
1126 frequency_errors)),
1127 (int)readb(ti->srb+offsetof(struct srb_read_log,
1128 token_errors)));
1130 dev->tbusy=0;
1131 break;
1133 default:
1134 DPRINTK("Unknown command %02X encountered\n",
1135 (int)readb(ti->srb));
1137 } /* SRB command check */
1139 writeb(~CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_RESET + ISRA_ODD);
1140 writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1142 skip_reset:
1143 } /* SRB response */
1145 if (status & ASB_FREE_INT) { /* ASB response */
1147 switch(readb(ti->asb)) { /* ASB command check */
1149 case REC_DATA:
1150 case XMIT_UI_FRAME:
1151 case XMIT_DIR_FRAME:
1152 break;
1154 default:
1155 DPRINTK("unknown command in asb %02X\n",
1156 (int)readb(ti->asb));
1158 } /* ASB command check */
1160 if (readb(ti->asb+2)!=0xff) /* checks ret_code */
1161 DPRINTK("ASB error %02X in cmd %02X\n",
1162 (int)readb(ti->asb+2),(int)readb(ti->asb));
1163 writeb(~ASB_FREE_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1165 } /* ASB response */
1167 if (status & ARB_CMD_INT) { /* ARB response */
1169 switch (readb(ti->arb)) { /* ARB command check */
1171 case DLC_STATUS:
1172 DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
1173 ntohs(readw(ti->arb + offsetof(struct arb_dlc_status, status))),
1174 ntohs(readw(ti->arb
1175 +offsetof(struct arb_dlc_status, station_id))));
1176 break;
1178 case REC_DATA:
1179 tr_rx(dev);
1180 break;
1182 case RING_STAT_CHANGE: {
1183 unsigned short ring_status;
1185 ring_status=ntohs(readw(ti->arb
1186 +offsetof(struct arb_ring_stat_change, ring_status)));
1188 if (ring_status & (SIGNAL_LOSS | LOBE_FAULT)) {
1190 DPRINTK("Signal loss/Lobe fault\n");
1191 DPRINTK("We try to reopen the adapter.\n");
1192 ibmtr_reset_timer(&(ti->tr_timer), dev);
1193 } else if (ring_status & (HARD_ERROR | XMIT_BEACON
1194 | AUTO_REMOVAL | REMOVE_RECV | RING_RECOVER))
1195 DPRINTK("New ring status: %02X\n", ring_status);
1197 if (ring_status & LOG_OVERFLOW) {
1198 if (dev->tbusy)
1199 ti->readlog_pending = 1;
1200 else
1201 ibmtr_readlog(dev);
1204 break;
1206 case XMIT_DATA_REQ:
1207 tr_tx(dev);
1208 break;
1210 default:
1211 DPRINTK("Unknown command %02X in arb\n",
1212 (int)readb(ti->arb));
1213 break;
1215 } /* ARB command check */
1217 writeb(~ARB_CMD_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1218 writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1220 } /* ARB response */
1222 if (status & SSB_RESP_INT) { /* SSB response */
1223 unsigned char retcode;
1224 switch (readb(ti->ssb)) { /* SSB command check */
1226 case XMIT_DIR_FRAME:
1227 case XMIT_UI_FRAME:
1228 retcode = readb(ti->ssb+2);
1229 if (retcode && (retcode != 0x22)) /* checks ret_code */
1230 DPRINTK("xmit ret_code: %02X xmit error code: %02X\n",
1231 (int)retcode, (int)readb(ti->ssb+6));
1232 else ti->tr_stats.tx_packets++;
1233 break;
1235 case XMIT_XID_CMD:
1236 DPRINTK("xmit xid ret_code: %02X\n", (int)readb(ti->ssb+2));
1238 default:
1239 DPRINTK("Unknown command %02X in ssb\n", (int)readb(ti->ssb));
1241 } /* SSB command check */
1243 writeb(~SSB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1244 writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1246 } /* SSB response */
1248 } /* SRB, ARB, ASB or SSB response */
1250 dev->interrupt=0;
1251 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1252 break;
1254 case FIRST_INT:
1255 initial_tok_int(dev);
1256 break;
1258 default:
1259 DPRINTK("Unexpected interrupt from tr adapter\n");
1262 spin_unlock(&(ti->lock));
1265 static void initial_tok_int(struct net_device *dev)
1268 __u32 encoded_addr;
1269 __u32 hw_encoded_addr;
1270 struct tok_info *ti;
1271 ti=(struct tok_info *) dev->priv;
1273 ti->do_tok_int=NOT_FIRST;
1275 #ifndef TR_NEWFORMAT
1276 DPRINTK("Initial tok int received\n");
1277 #endif
1279 /* we assign the shared-ram address for ISA devices */
1280 if(!ti->sram) {
1281 writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN);
1282 ti->sram=((__u32)ti->sram_base << 12);
1284 ti->init_srb=ti->sram
1285 +ntohs((unsigned short)readw(ti->mmio+ ACA_OFFSET + WRBR_EVEN));
1286 SET_PAGE(ntohs((unsigned short)readw(ti->mmio+ACA_OFFSET + WRBR_EVEN)));
1288 dev->mem_start = ti->sram;
1289 dev->mem_end = ti->sram + (ti->mapped_ram_size<<9) - 1;
1291 #if TR_VERBOSE
1293 int i;
1294 DPRINTK("init_srb(%p):", ti->init_srb);
1295 for (i=0;i<17;i++) printk("%02X ", (int)readb(ti->init_srb+i));
1296 printk("\n");
1298 #endif
1300 hw_encoded_addr = readw(ti->init_srb
1301 + offsetof(struct srb_init_response, encoded_address));
1303 #if !TR_NEWFORMAT
1304 DPRINTK("srb_init_response->encoded_address: %04X\n", hw_encoded_addr);
1305 DPRINTK("ntohs(srb_init_response->encoded_address): %04X\n",
1306 ntohs(hw_encoded_addr));
1307 #endif
1309 encoded_addr=(ti->sram + ntohs(hw_encoded_addr));
1310 ti->ring_speed = readb(ti->init_srb+offsetof(struct srb_init_response, init_status)) & 0x01 ? 16 : 4;
1311 #if !TR_NEWFORMAT
1312 DPRINTK("encoded addr (%04X,%04X,%08X): ", hw_encoded_addr,
1313 ntohs(hw_encoded_addr), encoded_addr);
1314 #else
1315 DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
1316 ti->ring_speed, ti->sram);
1317 #endif
1319 ti->auto_ringspeedsave=readb(ti->init_srb
1320 +offsetof(struct srb_init_response, init_status_2)) & 0x4 ? TRUE : FALSE;
1322 #if !TR_NEWFORMAT
1323 for(i=0;i<TR_ALEN;i++) {
1324 dev->dev_addr[i]=readb(encoded_addr + i);
1325 printk("%02X%s", dev->dev_addr[i], (i==TR_ALEN-1) ? "" : ":" );
1327 printk("\n");
1328 #endif
1330 tok_open_adapter((unsigned long)dev);
1333 static int tok_init_card(struct net_device *dev)
1335 struct tok_info *ti;
1336 short PIOaddr;
1337 unsigned long i;
1338 PIOaddr = dev->base_addr;
1339 ti=(struct tok_info *) dev->priv;
1341 /* Special processing for first interrupt after reset */
1342 ti->do_tok_int=FIRST_INT;
1344 /* Reset adapter */
1345 dev->tbusy=1; /* nothing can be done before reset and open completed */
1347 #ifdef ENABLE_PAGING
1348 if(ti->page_mask)
1349 writeb(SRPR_ENABLE_PAGING, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1350 #endif
1352 writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
1354 #if !TR_NEWFORMAT
1355 DPRINTK("resetting card\n");
1356 #endif
1358 outb(0, PIOaddr+ADAPTRESET);
1359 for (i=jiffies+TR_RESET_INTERVAL; time_before_eq(jiffies, i);); /* wait 50ms */
1360 outb(0,PIOaddr+ADAPTRESETREL);
1362 #if !TR_NEWFORMAT
1363 DPRINTK("card reset\n");
1364 #endif
1366 ti->open_status=IN_PROGRESS;
1367 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1368 return 0;
1371 static void open_sap(unsigned char type,struct net_device *dev)
1373 int i;
1374 struct tok_info *ti=(struct tok_info *) dev->priv;
1376 SET_PAGE(ti->srb);
1377 for (i=0; i<sizeof(struct dlc_open_sap); i++)
1378 writeb(0, ti->srb+i);
1380 writeb(DLC_OPEN_SAP, ti->srb + offsetof(struct dlc_open_sap, command));
1381 writew(htons(MAX_I_FIELD),
1382 ti->srb + offsetof(struct dlc_open_sap, max_i_field));
1383 writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY,
1384 ti->srb + offsetof(struct dlc_open_sap, sap_options));
1385 writeb(SAP_OPEN_STATION_CNT,
1386 ti->srb + offsetof(struct dlc_open_sap, station_count));
1387 writeb(type, ti->srb + offsetof(struct dlc_open_sap, sap_value));
1389 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1393 void tok_open_adapter(unsigned long dev_addr)
1396 struct net_device *dev=(struct net_device *)dev_addr;
1397 struct tok_info *ti;
1398 int i;
1400 ti=(struct tok_info *) dev->priv;
1402 #if !TR_NEWFORMAT
1403 DPRINTK("now opening the board...\n");
1404 #endif
1406 writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
1407 writeb(~CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_RESET + ISRA_ODD);
1409 for (i=0; i<sizeof(struct dir_open_adapter); i++)
1410 writeb(0, ti->init_srb+i);
1412 writeb(DIR_OPEN_ADAPTER,
1413 ti->init_srb + offsetof(struct dir_open_adapter, command));
1414 writew(htons(OPEN_PASS_BCON_MAC),
1415 ti->init_srb + offsetof(struct dir_open_adapter, open_options));
1416 if (ti->ring_speed == 16) {
1417 writew(htons(ti->dhb_size16mb),
1418 ti->init_srb + offsetof(struct dir_open_adapter, dhb_length));
1419 writew(htons(ti->rbuf_cnt16),
1420 ti->init_srb + offsetof(struct dir_open_adapter, num_rcv_buf));
1421 writew(htons(ti->rbuf_len16),
1422 ti->init_srb + offsetof(struct dir_open_adapter, rcv_buf_len));
1423 } else {
1424 writew(htons(ti->dhb_size4mb),
1425 ti->init_srb + offsetof(struct dir_open_adapter, dhb_length));
1426 writew(htons(ti->rbuf_cnt4),
1427 ti->init_srb + offsetof(struct dir_open_adapter, num_rcv_buf));
1428 writew(htons(ti->rbuf_len4),
1429 ti->init_srb + offsetof(struct dir_open_adapter, rcv_buf_len));
1431 writeb(NUM_DHB, /* always 2 */
1432 ti->init_srb + offsetof(struct dir_open_adapter, num_dhb));
1433 writeb(DLC_MAX_SAP,
1434 ti->init_srb + offsetof(struct dir_open_adapter, dlc_max_sap));
1435 writeb(DLC_MAX_STA,
1436 ti->init_srb + offsetof(struct dir_open_adapter, dlc_max_sta));
1438 ti->srb=ti->init_srb; /* We use this one in the interrupt handler */
1440 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1441 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1445 static void tr_tx(struct net_device *dev)
1447 struct tok_info *ti=(struct tok_info *) dev->priv;
1448 struct trh_hdr *trhdr=(struct trh_hdr *)ti->current_skb->data;
1449 unsigned int hdr_len;
1450 __u32 dhb;
1451 unsigned char xmit_command;
1452 int i;
1453 struct trllc *llc;
1455 if (readb(ti->asb + offsetof(struct asb_xmit_resp, ret_code))!=0xFF)
1456 DPRINTK("ASB not free !!!\n");
1458 /* in providing the transmit interrupts,
1459 is telling us it is ready for data and
1460 providing a shared memory address for us
1461 to stuff with data. Here we compute the
1462 effective address where we will place data.*/
1463 dhb=ti->sram
1464 +ntohs(readw(ti->arb + offsetof(struct arb_xmit_req, dhb_address)));
1466 /* Figure out the size of the 802.5 header */
1467 if (!(trhdr->saddr[0] & 0x80)) /* RIF present? */
1468 hdr_len=sizeof(struct trh_hdr)-TR_MAXRIFLEN;
1469 else
1470 hdr_len=((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK)>>8)
1471 +sizeof(struct trh_hdr)-TR_MAXRIFLEN;
1473 llc = (struct trllc *)(ti->current_skb->data + hdr_len);
1475 xmit_command = readb(ti->srb + offsetof(struct srb_xmit, command));
1477 writeb(xmit_command, ti->asb + offsetof(struct asb_xmit_resp, command));
1478 writew(readb(ti->srb + offsetof(struct srb_xmit, station_id)),
1479 ti->asb + offsetof(struct asb_xmit_resp, station_id));
1480 writeb(llc->ssap, ti->asb + offsetof(struct asb_xmit_resp, rsap_value));
1481 writeb(readb(ti->srb + offsetof(struct srb_xmit, cmd_corr)),
1482 ti->asb + offsetof(struct asb_xmit_resp, cmd_corr));
1483 writeb(0, ti->asb + offsetof(struct asb_xmit_resp, ret_code));
1485 if ((xmit_command==XMIT_XID_CMD) || (xmit_command==XMIT_TEST_CMD)) {
1487 writew(htons(0x11),
1488 ti->asb + offsetof(struct asb_xmit_resp, frame_length));
1489 writeb(0x0e, ti->asb + offsetof(struct asb_xmit_resp, hdr_length));
1490 writeb(AC, dhb);
1491 writeb(LLC_FRAME, dhb+1);
1493 for (i=0; i<TR_ALEN; i++) writeb((int)0x0FF, dhb+i+2);
1494 for (i=0; i<TR_ALEN; i++) writeb(0, dhb+i+TR_ALEN+2);
1496 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1497 return;
1502 * the token ring packet is copied from sk_buff to the adapter
1503 * buffer identified in the command data received with the interrupt.
1505 writeb(hdr_len, ti->asb + offsetof(struct asb_xmit_resp, hdr_length));
1506 writew(htons(ti->current_skb->len),
1507 ti->asb + offsetof(struct asb_xmit_resp, frame_length));
1509 memcpy_toio(dhb, ti->current_skb->data, ti->current_skb->len);
1511 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1512 ti->tr_stats.tx_bytes+=ti->current_skb->len;
1513 dev->tbusy=0;
1514 dev_kfree_skb(ti->current_skb);
1515 ti->current_skb=NULL;
1516 mark_bh(NET_BH);
1517 if (ti->readlog_pending) ibmtr_readlog(dev);
1520 static void tr_rx(struct net_device *dev)
1522 struct tok_info *ti=(struct tok_info *) dev->priv;
1523 __u32 rbuffer, rbufdata;
1524 __u32 llc;
1525 unsigned char *data;
1526 unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length;
1527 struct sk_buff *skb;
1528 unsigned int skb_size = 0;
1529 int IPv4_p = 0;
1530 unsigned int chksum = 0;
1531 struct iphdr *iph;
1533 rbuffer=(ti->sram
1534 +ntohs(readw(ti->arb + offsetof(struct arb_rec_req, rec_buf_addr))))+2;
1536 if(readb(ti->asb + offsetof(struct asb_rec, ret_code))!=0xFF)
1537 DPRINTK("ASB not free !!!\n");
1539 writeb(REC_DATA,
1540 ti->asb + offsetof(struct asb_rec, command));
1541 writew(readw(ti->arb + offsetof(struct arb_rec_req, station_id)),
1542 ti->asb + offsetof(struct asb_rec, station_id));
1543 writew(readw(ti->arb + offsetof(struct arb_rec_req, rec_buf_addr)),
1544 ti->asb + offsetof(struct asb_rec, rec_buf_addr));
1546 lan_hdr_len=readb(ti->arb + offsetof(struct arb_rec_req, lan_hdr_len));
1547 hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr);
1549 llc=(rbuffer + offsetof(struct rec_buf, data) + lan_hdr_len);
1551 #if TR_VERBOSE
1552 DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
1553 (unsigned int)offsetof(struct rec_buf,data), (unsigned int)lan_hdr_len);
1554 DPRINTK("llc: %08X rec_buf_addr: %04X ti->sram: %p\n", llc,
1555 ntohs(readw(ti->arb + offsetof(struct arb_rec_req, rec_buf_addr))),
1556 ti->sram);
1557 DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
1558 "ethertype: %04X\n",
1559 (int)readb(llc + offsetof(struct trllc, dsap)),
1560 (int)readb(llc + offsetof(struct trllc, ssap)),
1561 (int)readb(llc + offsetof(struct trllc, llc)),
1562 (int)readb(llc + offsetof(struct trllc, protid)),
1563 (int)readb(llc + offsetof(struct trllc, protid)+1),
1564 (int)readb(llc + offsetof(struct trllc, protid)+2),
1565 (int)readw(llc + offsetof(struct trllc, ethertype)));
1566 #endif
1567 if (readb(llc + offsetof(struct trllc, llc))!=UI_CMD) {
1568 writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
1569 ti->tr_stats.rx_dropped++;
1570 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1571 return;
1574 length = ntohs(readw(ti->arb+offsetof(struct arb_rec_req, frame_len)));
1575 if ((readb(llc + offsetof(struct trllc, dsap))==EXTENDED_SAP) &&
1576 (readb(llc + offsetof(struct trllc, ssap))==EXTENDED_SAP) &&
1577 (length>=hdr_len)) {
1578 IPv4_p = 1;
1581 #if TR_VERBOSE
1582 if (!IPv4_p){
1584 __u32 trhhdr;
1586 trhhdr=(rbuffer+offsetof(struct rec_buf,data));
1588 DPRINTK("Probably non-IP frame received.\n");
1589 DPRINTK("ssap: %02X dsap: %02X saddr: %02X:%02X:%02X:%02X:%02X:%02X "
1590 "daddr: %02X:%02X:%02X:%02X:%02X:%02X\n",
1591 (int)readb(llc + offsetof(struct trllc, ssap)),
1592 (int)readb(llc + offsetof(struct trllc, dsap)),
1593 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)),
1594 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)+1),
1595 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)+2),
1596 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)+3),
1597 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)+4),
1598 (int)readb(trhhdr + offsetof(struct trh_hdr, saddr)+5),
1599 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)),
1600 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)+1),
1601 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)+2),
1602 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)+3),
1603 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)+4),
1604 (int)readb(trhhdr + offsetof(struct trh_hdr, daddr)+5));
1606 #endif
1608 skb_size = length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
1610 if (!(skb=dev_alloc_skb(skb_size))) {
1611 DPRINTK("out of memory. frame dropped.\n");
1612 ti->tr_stats.rx_dropped++;
1613 writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
1614 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1615 return;
1618 skb_put(skb, length);
1619 skb_reserve(skb, sizeof(struct trh_hdr)-lan_hdr_len+sizeof(struct trllc));
1620 skb->dev=dev;
1621 data=skb->data;
1622 rbuffer_len=ntohs(readw(rbuffer + offsetof(struct rec_buf, buf_len)));
1623 rbufdata = rbuffer + offsetof(struct rec_buf,data);
1625 if (IPv4_p) {
1626 /* Copy the headers without checksumming */
1627 memcpy_fromio(data, rbufdata, hdr_len);
1629 /* Watch for padded packets and bogons */
1630 iph=(struct iphdr*)(data + lan_hdr_len + sizeof(struct trllc));
1631 ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr);
1632 length -= hdr_len;
1633 if ((ip_len <= length) && (ip_len > 7))
1634 length = ip_len;
1635 data += hdr_len;
1636 rbuffer_len -= hdr_len;
1637 rbufdata += hdr_len;
1640 /* Copy the payload... */
1641 for (;;) {
1642 if (IPv4_p)
1643 chksum = csum_partial_copy(bus_to_virt(rbufdata), data,
1644 length < rbuffer_len ? length : rbuffer_len,
1645 chksum);
1646 else
1647 memcpy_fromio(data, rbufdata, rbuffer_len);
1648 rbuffer = ntohs(readw(rbuffer));
1649 if (!rbuffer)
1650 break;
1651 length -= rbuffer_len;
1652 data += rbuffer_len;
1653 rbuffer += ti->sram;
1654 rbuffer_len = ntohs(readw(rbuffer + offsetof(struct rec_buf, buf_len)));
1655 rbufdata = rbuffer + offsetof(struct rec_buf, data);
1658 writeb(0, ti->asb + offsetof(struct asb_rec, ret_code));
1660 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1662 ti->tr_stats.rx_bytes += skb->len;
1663 ti->tr_stats.rx_packets++;
1665 skb->protocol = tr_type_trans(skb,dev);
1666 if (IPv4_p){
1667 skb->csum = chksum;
1668 skb->ip_summed = 1;
1670 netif_rx(skb);
1673 static int tok_send_packet(struct sk_buff *skb, struct net_device *dev)
1675 struct tok_info *ti;
1676 ti=(struct tok_info *) dev->priv;
1678 if (dev->tbusy) {
1679 int ticks_waited;
1681 ticks_waited=jiffies - dev->trans_start;
1682 if (ticks_waited<TR_BUSY_INTERVAL) return 1;
1684 DPRINTK("Arrg. Transmitter busy.\n");
1685 dev->trans_start+=5; /* we fake the transmission start time... */
1686 return 1;
1689 if (test_and_set_bit(0,(void *)&dev->tbusy)!=0)
1690 DPRINTK("Transmitter access conflict\n");
1691 else {
1692 int flags;
1694 /* lock against other CPUs */
1695 spin_lock_irqsave(&(ti->lock), flags);
1697 /* Save skb; we'll need it when the adapter asks for the data */
1698 ti->current_skb=skb;
1699 writeb(XMIT_UI_FRAME, ti->srb + offsetof(struct srb_xmit, command));
1700 writew(ti->exsap_station_id, ti->srb
1701 +offsetof(struct srb_xmit, station_id));
1702 writeb(CMD_IN_SRB, (ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD));
1703 spin_unlock_irqrestore(&(ti->lock), flags);
1705 dev->trans_start=jiffies;
1708 return 0;
1711 void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev) {
1712 tmr->expires = jiffies + TR_RETRY_INTERVAL;
1713 tmr->data = (unsigned long) dev;
1714 tmr->function = tok_open_adapter;
1715 init_timer(tmr);
1716 add_timer(tmr);
1719 void ibmtr_readlog(struct net_device *dev) {
1720 struct tok_info *ti;
1721 ti=(struct tok_info *) dev->priv;
1723 ti->readlog_pending = 0;
1724 writeb(DIR_READ_LOG, ti->srb);
1725 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1726 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1727 dev->tbusy=1; /* really srb busy... */
1730 /* tok_get_stats(): Basically a scaffold routine which will return
1731 the address of the tr_statistics structure associated with
1732 this device -- the tr.... structure is an ethnet look-alike
1733 so at least for this iteration may suffice. */
1735 static struct net_device_stats * tok_get_stats(struct net_device *dev) {
1737 struct tok_info *toki;
1738 toki=(struct tok_info *) dev->priv;
1739 return (struct net_device_stats *) &toki->tr_stats;
1742 int ibmtr_change_mtu(struct net_device *dev, int mtu) {
1743 struct tok_info *ti = (struct tok_info *) dev->priv;
1745 if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
1746 return -EINVAL;
1747 if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
1748 return -EINVAL;
1749 dev->mtu = mtu;
1750 return 0;
1753 #ifdef MODULE
1755 /* 3COM 3C619C supports 8 interrupts, 32 I/O ports */
1756 static struct net_device* dev_ibmtr[IBMTR_MAX_ADAPTERS];
1757 static int io[IBMTR_MAX_ADAPTERS] = {0xa20,0xa24};
1758 static int irq[IBMTR_MAX_ADAPTERS] = {0,0};
1759 static int mem[IBMTR_MAX_ADAPTERS] = {0,0};
1761 MODULE_PARM(io, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS) "i");
1762 MODULE_PARM(irq, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS) "i");
1763 MODULE_PARM(mem, "1-" __MODULE_STRING(IBMTR_MAX_ADAPTERS) "i");
1765 int init_module(void)
1767 int i;
1768 for (i = 0; io[i] && (i<IBMTR_MAX_ADAPTERS); i++) {
1769 irq[i] = 0;
1770 mem[i] = 0;
1771 dev_ibmtr[i] = NULL;
1772 dev_ibmtr[i] = init_trdev(dev_ibmtr[i], 0);
1773 if (dev_ibmtr[i] == NULL)
1774 return -ENOMEM;
1776 dev_ibmtr[i]->base_addr = io[i];
1777 dev_ibmtr[i]->irq = irq[i];
1778 dev_ibmtr[i]->mem_start = mem[i];
1779 dev_ibmtr[i]->init = &ibmtr_probe;
1781 if (register_trdev(dev_ibmtr[i]) != 0) {
1782 kfree_s(dev_ibmtr[i], sizeof(struct net_device));
1783 dev_ibmtr[i] = NULL;
1784 if (i == 0) {
1785 printk("ibmtr: register_trdev() returned non-zero.\n");
1786 return -EIO;
1787 } else {
1788 return 0;
1792 return 0;
1795 void cleanup_module(void)
1797 int i;
1799 for (i = 0; i < IBMTR_MAX_ADAPTERS; i++)
1800 if (dev_ibmtr[i]) {
1801 unregister_trdev(dev_ibmtr[i]);
1802 free_irq(dev_ibmtr[i]->irq, dev_ibmtr[i]);
1803 release_region(dev_ibmtr[i]->base_addr, IBMTR_IO_EXTENT);
1804 kfree_s(dev_ibmtr[i]->priv, sizeof(struct tok_info));
1805 kfree_s(dev_ibmtr[i], sizeof(struct net_device));
1806 dev_ibmtr[i] = NULL;
1809 #endif /* MODULE */