1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108#define IBMTR_DEBUG_MESSAGES 0
109
110#include <linux/module.h>
111#include <linux/sched.h>
112
113#ifdef PCMCIA
114#undef MODULE
115#undef ENABLE_PAGING
116#else
117#define ENABLE_PAGING 1
118#endif
119
120
121#define TR_VERBOSE 0
122
123
124#define TR_FILTERNONUI 1
125
126#include <linux/ioport.h>
127#include <linux/netdevice.h>
128#include <linux/ip.h>
129#include <linux/trdevice.h>
130#include <linux/ibmtr.h>
131
132#include <net/checksum.h>
133
134#include <asm/io.h>
135
136#define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
137#define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
138
139
140#ifndef PCMCIA
141static char version[] __devinitdata =
142 "\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
143 " v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
144 " v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
145 " v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n"
146 " v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n"
147 " v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n";
148#endif
149
150
151
152static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
153
154static char pcchannelid[] __devinitdata = {
155 0x05, 0x00, 0x04, 0x09,
156 0x04, 0x03, 0x04, 0x0f,
157 0x03, 0x06, 0x03, 0x01,
158 0x03, 0x01, 0x03, 0x00,
159 0x03, 0x09, 0x03, 0x09,
160 0x03, 0x00, 0x02, 0x00
161};
162
163static char mcchannelid[] __devinitdata = {
164 0x04, 0x0d, 0x04, 0x01,
165 0x05, 0x02, 0x05, 0x03,
166 0x03, 0x06, 0x03, 0x03,
167 0x05, 0x08, 0x03, 0x04,
168 0x03, 0x05, 0x03, 0x01,
169 0x03, 0x08, 0x02, 0x00
170};
171
172static char __devinit *adapter_def(char type)
173{
174 switch (type) {
175 case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
176 case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)";
177 case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
178 case 0xC: return "Auto 16/4 Adapter";
179 default: return "adapter (unknown type)";
180 };
181};
182
183#define TRC_INIT 0x01
184#define TRC_INITV 0x02
185static unsigned char ibmtr_debug_trace = 0;
186
187static int ibmtr_probe1(struct net_device *dev, int ioaddr);
188static unsigned char get_sram_size(struct tok_info *adapt_info);
189static int trdev_init(struct net_device *dev);
190static int tok_open(struct net_device *dev);
191static int tok_init_card(struct net_device *dev);
192static void tok_open_adapter(unsigned long dev_addr);
193static void open_sap(unsigned char type, struct net_device *dev);
194static void tok_set_multicast_list(struct net_device *dev);
195static netdev_tx_t tok_send_packet(struct sk_buff *skb,
196 struct net_device *dev);
197static int tok_close(struct net_device *dev);
198static irqreturn_t tok_interrupt(int irq, void *dev_id);
199static void initial_tok_int(struct net_device *dev);
200static void tr_tx(struct net_device *dev);
201static void tr_rx(struct net_device *dev);
202static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
203static void tok_rerun(unsigned long dev_addr);
204static void ibmtr_readlog(struct net_device *dev);
205static int ibmtr_change_mtu(struct net_device *dev, int mtu);
206static void find_turbo_adapters(int *iolist);
207
208static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
209 0xa20, 0xa24, 0, 0, 0
210};
211static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0};
212static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
213static int __devinitdata turbo_searched = 0;
214
215#ifndef PCMCIA
216static __u32 ibmtr_mem_base __devinitdata = 0xd0000;
217#endif
218
219static void __devinit PrtChanID(char *pcid, short stride)
220{
221 short i, j;
222 for (i = 0, j = 0; i < 24; i++, j += stride)
223 printk("%1x", ((int) pcid[j]) & 0x0f);
224 printk("\n");
225}
226
227static void __devinit HWPrtChanID(void __iomem *pcid, short stride)
228{
229 short i, j;
230 for (i = 0, j = 0; i < 24; i++, j += stride)
231 printk("%1x", ((int) readb(pcid + j)) & 0x0f);
232 printk("\n");
233}
234
235
236
237
238
239static void __devinit find_turbo_adapters(int *iolist)
240{
241 int ram_addr;
242 int index=0;
243 void __iomem *chanid;
244 int found_turbo=0;
245 unsigned char *tchanid, ctemp;
246 int i, j;
247 unsigned long jif;
248 void __iomem *ram_mapped ;
249
250 if (turbo_searched == 1) return;
251 turbo_searched=1;
252 for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) {
253
254 __u32 intf_tbl=0;
255
256 found_turbo=1;
257 ram_mapped = ioremap((u32)ram_addr,0x1fff) ;
258 if (ram_mapped==NULL)
259 continue ;
260 chanid=(CHANNEL_ID + ram_mapped);
261 tchanid=pcchannelid;
262 ctemp=readb(chanid) & 0x0f;
263 if (ctemp != *tchanid) continue;
264 for (i=2,j=1; i<=46; i=i+2,j++) {
265 if ((readb(chanid+i) & 0x0f) != tchanid[j]){
266 found_turbo=0;
267 break;
268 }
269 }
270 if (!found_turbo) continue;
271
272 writeb(0x90, ram_mapped+0x1E01);
273 for(i=2; i<0x0f; i++) {
274 writeb(0x00, ram_mapped+0x1E01+i);
275 }
276 writeb(0x00, ram_mapped+0x1E01);
277 for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif););
278 intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN));
279 if (intf_tbl) {
280#if IBMTR_DEBUG_MESSAGES
281 printk("ibmtr::find_turbo_adapters, Turbo found at "
282 "ram_addr %x\n",ram_addr);
283 printk("ibmtr::find_turbo_adapters, interface_table ");
284 for(i=0; i<6; i++) {
285 printk("%x:",readb(ram_addr+intf_tbl+i));
286 }
287 printk("\n");
288#endif
289 turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4));
290 turbo_irq[index]=readb(ram_mapped+intf_tbl+3);
291 outb(0, turbo_io[index] + ADAPTRESET);
292 for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif););
293 outb(0, turbo_io[index] + ADAPTRESETREL);
294 index++;
295 continue;
296 }
297#if IBMTR_DEBUG_MESSAGES
298 printk("ibmtr::find_turbo_adapters, ibmtr card found at"
299 " %x but not a Turbo model\n",ram_addr);
300#endif
301 iounmap(ram_mapped) ;
302 }
303 for(i=0; i<IBMTR_MAX_ADAPTERS; i++) {
304 if(!turbo_io[i]) break;
305 for (j=0; j<IBMTR_MAX_ADAPTERS; j++) {
306 if ( iolist[j] && iolist[j] != turbo_io[i]) continue;
307 iolist[j]=turbo_io[i];
308 break;
309 }
310 }
311}
312
313static void ibmtr_cleanup_card(struct net_device *dev)
314{
315 if (dev->base_addr) {
316 outb(0,dev->base_addr+ADAPTRESET);
317
318 schedule_timeout_uninterruptible(TR_RST_TIME);
319
320 outb(0,dev->base_addr+ADAPTRESETREL);
321 }
322
323#ifndef PCMCIA
324 free_irq(dev->irq, dev);
325 release_region(dev->base_addr, IBMTR_IO_EXTENT);
326
327 {
328 struct tok_info *ti = netdev_priv(dev);
329 iounmap(ti->mmio);
330 iounmap(ti->sram_virt);
331 }
332#endif
333}
334
335
336
337
338
339
340
341
342
343
344
345
346
347static int __devinit ibmtr_probe(struct net_device *dev)
348{
349 int i;
350 int base_addr = dev->base_addr;
351
352 if (base_addr && base_addr <= 0x1ff)
353 return -ENXIO;
354 if (base_addr > 0x1ff) {
355 if (!ibmtr_probe1(dev, base_addr)) return 0;
356 return -ENODEV;
357 }
358 find_turbo_adapters(ibmtr_portlist);
359 for (i = 0; ibmtr_portlist[i]; i++) {
360 int ioaddr = ibmtr_portlist[i];
361
362 if (!ibmtr_probe1(dev, ioaddr)) return 0;
363 }
364 return -ENODEV;
365}
366
367int __devinit ibmtr_probe_card(struct net_device *dev)
368{
369 int err = ibmtr_probe(dev);
370 if (!err) {
371 err = register_netdev(dev);
372 if (err)
373 ibmtr_cleanup_card(dev);
374 }
375 return err;
376}
377
378
379
380static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
381{
382
383 unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0;
384 void __iomem * t_mmio = NULL;
385 struct tok_info *ti = netdev_priv(dev);
386 void __iomem *cd_chanid;
387 unsigned char *tchanid, ctemp;
388#ifndef PCMCIA
389 unsigned char t_irq=0;
390 unsigned long timeout;
391 static int version_printed;
392#endif
393
394
395
396
397
398 segment = inb(PIOaddr);
399 if (segment < 0x40 || segment > 0xe0) {
400
401
402
403#if IBMTR_DEBUG_MESSAGES
404 DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, "
405 "Hardware Problem?\n",PIOaddr,segment);
406#endif
407 return -ENODEV;
408 }
409
410
411
412
413 t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048);
414 if (!t_mmio) {
415 DPRINTK("Cannot remap mmiobase memory area") ;
416 return -ENODEV ;
417 }
418 intr = segment & 0x03;
419 if (ibmtr_debug_trace & TRC_INIT)
420 DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n"
421 , PIOaddr, (int) segment, t_mmio, (int) intr);
422
423
424
425
426
427#ifdef PCMCIA
428 iounmap(t_mmio);
429 t_mmio = ti->mmio;
430 irq = ti->irq;
431#endif
432 cd_chanid = (CHANNEL_ID + t_mmio);
433 tchanid = pcchannelid;
434 cardpresent = TR_ISA;
435
436
437 ctemp = readb(cd_chanid) & 0x0f;
438 if (ctemp != *tchanid) {
439 tchanid = mcchannelid;
440 cardpresent = TR_MCA;
441 if (ctemp != *tchanid)
442 cardpresent = NOTOK;
443 }
444 if (cardpresent != NOTOK) {
445
446 for (i = 2, j = 1; i <= 46; i = i + 2, j++) {
447 if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue;
448
449 cardpresent = NOTOK;
450 break;
451 }
452 }
453
454
455
456
457 if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e))
458 cardpresent = TR_ISAPNP;
459 if (cardpresent == NOTOK) {
460 if (!(ibmtr_debug_trace & TRC_INIT)) {
461#ifndef PCMCIA
462 iounmap(t_mmio);
463#endif
464 return -ENODEV;
465 }
466 DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n",
467 PIOaddr);
468 DPRINTK("Expected for ISA: ");
469 PrtChanID(pcchannelid, 1);
470 DPRINTK(" found: ");
471
472
473
474 HWPrtChanID(cd_chanid, 2);
475 DPRINTK("Expected for MCA: ");
476 PrtChanID(mcchannelid, 1);
477 }
478
479
480
481#ifndef PCMCIA
482 ti->mmio = t_mmio;
483 for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) {
484 if (turbo_io[i] != PIOaddr)
485 continue;
486#if IBMTR_DEBUG_MESSAGES
487 printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n",
488 PIOaddr);
489#endif
490 ti->turbo = 1;
491 t_irq = turbo_irq[i];
492 }
493#endif
494 ti->readlog_pending = 0;
495 init_waitqueue_head(&ti->wait_for_reset);
496
497
498
499
500#ifndef PCMCIA
501 switch (cardpresent) {
502 case TR_ISA:
503 if (intr == 0) irq = 9;
504 if (intr == 1) irq = 3;
505 if (intr == 2) irq = 6;
506 if (intr == 3) irq = 7;
507 ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
508 break;
509 case TR_MCA:
510 if (intr == 0) irq = 9;
511 if (intr == 1) irq = 3;
512 if (intr == 2) irq = 10;
513 if (intr == 3) irq = 11;
514 ti->global_int_enable = 0;
515 ti->adapter_int_enable = 0;
516 ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12;
517 break;
518 case TR_ISAPNP:
519 if (!t_irq) {
520 if (intr == 0) irq = 9;
521 if (intr == 1) irq = 3;
522 if (intr == 2) irq = 10;
523 if (intr == 3) irq = 11;
524 } else
525 irq=t_irq;
526 timeout = jiffies + TR_SPIN_INTERVAL;
527 while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){
528 if (!time_after(jiffies, timeout)) continue;
529 DPRINTK( "Hardware timeout during initialization.\n");
530 iounmap(t_mmio);
531 return -ENODEV;
532 }
533 ti->sram_phys =
534 ((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12);
535 ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
536 break;
537 }
538#endif
539
540 if (ibmtr_debug_trace & TRC_INIT) {
541 DPRINTK("irq=%d", irq);
542 printk(", sram_phys=0x%x", ti->sram_phys);
543 if(ibmtr_debug_trace&TRC_INITV){
544 DPRINTK(", ti->mmio=%p", ti->mmio);
545 printk(", segment=%02X", segment);
546 }
547 printk(".\n");
548 }
549
550
551 j = 0;
552 for (i = 0; i < 0x18; i = i + 2) {
553
554 temp = readb(ti->mmio + AIP + i) & 0x0f;
555 ti->hw_address[j] = temp;
556 if (j & 1)
557 dev->dev_addr[(j / 2)] =
558 ti->hw_address[j]+ (ti->hw_address[j - 1] << 4);
559 ++j;
560 }
561
562 ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
563
564
565 ti->data_rate = readb(ti->mmio + AIPDATARATE);
566
567
568 ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
569
570
571 if (ti->turbo) {
572 ti->avail_shared_ram=127;
573 } else {
574 ti->avail_shared_ram = get_sram_size(ti);
575 }
576
577
578 ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
579
580
581 switch (readb(ti->mmio + AIP4MBDHB)) {
582 case 0xe: ti->dhb_size4mb = 4096; break;
583 case 0xd: ti->dhb_size4mb = 4464; break;
584 default: ti->dhb_size4mb = 2048; break;
585 }
586
587
588 switch (readb(ti->mmio + AIP16MBDHB)) {
589 case 0xe: ti->dhb_size16mb = 4096; break;
590 case 0xd: ti->dhb_size16mb = 8192; break;
591 case 0xc: ti->dhb_size16mb = 16384; break;
592 case 0xb: ti->dhb_size16mb = 17960; break;
593 default: ti->dhb_size16mb = 2048; break;
594 }
595
596
597
598
599
600
601
602
603
604
605
606
607 ti->mapped_ram_size=
608 1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4);
609 ti->page_mask = 0;
610 if (ti->turbo) ti->page_mask=0xf0;
611 else if (ti->shared_ram_paging == 0xf);
612 else {
613#ifdef ENABLE_PAGING
614 unsigned char pg_size = 0;
615
616
617 switch (ti->shared_ram_paging) {
618 case 0xf:
619 break;
620 case 0xe:
621 ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0;
622 pg_size = 32;
623 break;
624 case 0xd:
625 ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0;
626 pg_size = 64;
627 break;
628 case 0xc:
629 switch (ti->mapped_ram_size) {
630 case 32:
631 ti->page_mask = 0xc0;
632 pg_size = 32;
633 break;
634 case 64:
635 ti->page_mask = 0x80;
636 pg_size = 64;
637 break;
638 }
639 break;
640 default:
641 DPRINTK("Unknown shared ram paging info %01X\n",
642 ti->shared_ram_paging);
643 iounmap(t_mmio);
644 return -ENODEV;
645 break;
646 }
647
648 if (ibmtr_debug_trace & TRC_INIT)
649 DPRINTK("Shared RAM paging code: %02X, "
650 "mapped RAM size: %dK, shared RAM size: %dK, "
651 "page mask: %02X\n:",
652 ti->shared_ram_paging, ti->mapped_ram_size / 2,
653 ti->avail_shared_ram / 2, ti->page_mask);
654#endif
655 }
656
657#ifndef PCMCIA
658
659 if (cardpresent == TR_ISA) {
660 static const __u32 ram_bndry_mask[] = {
661 0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000
662 };
663 __u32 new_base, rrr_32, chk_base, rbm;
664
665 rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
666 rbm = ram_bndry_mask[rrr_32];
667 new_base = (ibmtr_mem_base + (~rbm)) & rbm;
668 chk_base = new_base + (ti->mapped_ram_size << 9);
669 if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
670 DPRINTK("Shared RAM for this adapter (%05x) exceeds "
671 "driver limit (%05x), adapter not started.\n",
672 chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
673 iounmap(t_mmio);
674 return -ENODEV;
675 } else {
676 ti->sram_base = new_base >> 12;
677 ibmtr_mem_base = chk_base;
678 }
679 }
680 else ti->sram_base = ti->sram_phys >> 12;
681
682
683
684 if (request_irq(dev->irq = irq, tok_interrupt, 0, "ibmtr", dev) != 0) {
685 DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
686 irq);
687 iounmap(t_mmio);
688 return -ENODEV;
689 }
690
691
692 if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
693 DPRINTK("Could not grab PIO range. Halting driver.\n");
694 free_irq(dev->irq, dev);
695 iounmap(t_mmio);
696 return -EBUSY;
697 }
698
699 if (!version_printed++) {
700 printk(version);
701 }
702#endif
703 DPRINTK("%s %s found\n",
704 channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
705 DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
706 irq, PIOaddr, ti->mapped_ram_size / 2);
707 DPRINTK("Hardware address : %pM\n", dev->dev_addr);
708 if (ti->page_mask)
709 DPRINTK("Shared RAM paging enabled. "
710 "Page size: %uK Shared Ram size %dK\n",
711 ((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
712 else
713 DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
714 ti->page_mask);
715
716
717
718
719
720
721
722 if (!ti->page_mask) {
723 ti->avail_shared_ram=
724 min(ti->mapped_ram_size,ti->avail_shared_ram);
725 }
726
727 switch (ti->avail_shared_ram) {
728 case 16:
729 ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
730 ti->rbuf_len4 = 1032;
731 ti->rbuf_cnt4=2;
732 ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
733 ti->rbuf_len16 = 1032;
734 ti->rbuf_cnt16=2;
735 break;
736 case 32:
737 ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
738 ti->rbuf_len4 = 1032;
739 ti->rbuf_cnt4=4;
740 ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
741 ti->rbuf_len16 = 1032;
742 ti->rbuf_cnt16=4;
743 break;
744 case 64:
745 ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
746 ti->rbuf_len4 = 1032;
747 ti->rbuf_cnt4=6;
748 ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
749 ti->rbuf_len16 = 1032;
750 ti->rbuf_cnt16=6;
751 break;
752 case 127:
753 ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
754 ti->rbuf_len4 = 1032;
755 ti->rbuf_cnt4=6;
756 ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
757 ti->rbuf_len16 = 1032;
758 ti->rbuf_cnt16=16;
759 break;
760 case 128:
761 ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
762 ti->rbuf_len4 = 1032;
763 ti->rbuf_cnt4=6;
764 ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
765 ti->rbuf_len16 = 1032;
766 ti->rbuf_cnt16=16;
767 break;
768 default:
769 ti->dhb_size4mb = 2048;
770 ti->rbuf_len4 = 1032;
771 ti->rbuf_cnt4=2;
772 ti->dhb_size16mb = 2048;
773 ti->rbuf_len16 = 1032;
774 ti->rbuf_cnt16=2;
775 break;
776 }
777
778
779
780
781
782
783 ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
784 ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
785
786 DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
787 ti->maxmtu16, ti->maxmtu4);
788
789 dev->base_addr = PIOaddr;
790 dev->mem_start = ti->sram_base << 12;
791 dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
792 trdev_init(dev);
793 return 0;
794}
795
796
797
798
799
800
801static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
802{
803 unsigned char avail_sram_code;
804 static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
805
806
807
808
809
810
811
812 avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
813 if (avail_sram_code) return size_code[avail_sram_code];
814 else
815 return 1 <<
816 ((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
817}
818
819
820
821static const struct net_device_ops trdev_netdev_ops = {
822 .ndo_open = tok_open,
823 .ndo_stop = tok_close,
824 .ndo_start_xmit = tok_send_packet,
825 .ndo_set_multicast_list = tok_set_multicast_list,
826 .ndo_change_mtu = ibmtr_change_mtu,
827};
828
829static int __devinit trdev_init(struct net_device *dev)
830{
831 struct tok_info *ti = netdev_priv(dev);
832
833 SET_PAGE(ti->srb_page);
834 ti->open_failure = NO ;
835 dev->netdev_ops = &trdev_netdev_ops;
836
837 return 0;
838}
839
840
841
842static int tok_init_card(struct net_device *dev)
843{
844 struct tok_info *ti;
845 short PIOaddr;
846 unsigned long i;
847
848 PIOaddr = dev->base_addr;
849 ti = netdev_priv(dev);
850
851 ti->do_tok_int = FIRST_INT;
852
853 writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
854 outb(0, PIOaddr + ADAPTRESET);
855
856 schedule_timeout_uninterruptible(TR_RST_TIME);
857
858 outb(0, PIOaddr + ADAPTRESETREL);
859#ifdef ENABLE_PAGING
860 if (ti->page_mask)
861 writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
862#endif
863 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
864 i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
865 return i? 0 : -EAGAIN;
866}
867
868
869static int tok_open(struct net_device *dev)
870{
871 struct tok_info *ti = netdev_priv(dev);
872 int i;
873
874
875 if (ti->open_failure == YES) {
876 DPRINTK("Last time you were disconnected, how about now?\n");
877 printk("You can't insert with an ICS connector half-cocked.\n");
878 }
879
880 ti->open_status = CLOSED;
881 ti->sap_status = CLOSED;
882 ti->open_failure = NO;
883 ti->open_mode = MANUAL;
884
885 ti->sram_phys &= ~1;
886
887 spin_lock_init(&ti->lock);
888 init_timer(&ti->tr_timer);
889
890 i = tok_init_card(dev);
891 if (i) return i;
892
893 while (1){
894 tok_open_adapter((unsigned long) dev);
895 i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
896
897 if (i>(245*HZ)/10) break;
898 if (i==0) break;
899 if (ti->open_status == OPEN && ti->sap_status==OPEN) {
900 netif_start_queue(dev);
901 DPRINTK("Adapter is up and running\n");
902 return 0;
903 }
904 i=schedule_timeout_interruptible(TR_RETRY_INTERVAL);
905
906 if(i!=0) break;
907 }
908 outb(0, dev->base_addr + ADAPTRESET);
909 DPRINTK("TERMINATED via signal\n");
910 return -EAGAIN;
911}
912
913
914
915#define COMMAND_OFST 0
916#define OPEN_OPTIONS_OFST 8
917#define NUM_RCV_BUF_OFST 24
918#define RCV_BUF_LEN_OFST 26
919#define DHB_LENGTH_OFST 28
920#define NUM_DHB_OFST 30
921#define DLC_MAX_SAP_OFST 32
922#define DLC_MAX_STA_OFST 33
923
924static void tok_open_adapter(unsigned long dev_addr)
925{
926 struct net_device *dev = (struct net_device *) dev_addr;
927 struct tok_info *ti;
928 int i;
929
930 ti = netdev_priv(dev);
931 SET_PAGE(ti->init_srb_page);
932 writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
933 for (i = 0; i < sizeof(struct dir_open_adapter); i++)
934 writeb(0, ti->init_srb + i);
935 writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
936 writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
937 if (ti->ring_speed == 16) {
938 writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
939 writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
940 writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
941 } else {
942 writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
943 writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
944 writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
945 }
946 writeb(NUM_DHB, ti->init_srb + NUM_DHB_OFST);
947 writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
948 writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
949 ti->srb = ti->init_srb;
950 ti->srb_page = ti->init_srb_page;
951 DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
952 readb(ti->init_srb + NUM_DHB_OFST),
953 ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
954 ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
955 ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
956 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
957 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
958}
959
960
961
962static void open_sap(unsigned char type, struct net_device *dev)
963{
964 int i;
965 struct tok_info *ti = netdev_priv(dev);
966
967 SET_PAGE(ti->srb_page);
968 for (i = 0; i < sizeof(struct dlc_open_sap); i++)
969 writeb(0, ti->srb + i);
970
971#define MAX_I_FIELD_OFST 14
972#define SAP_VALUE_OFST 16
973#define SAP_OPTIONS_OFST 17
974#define STATION_COUNT_OFST 18
975
976 writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
977 writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
978 writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
979 writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
980 writeb(type, ti->srb + SAP_VALUE_OFST);
981 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
982}
983
984
985
986
987static void tok_set_multicast_list(struct net_device *dev)
988{
989 struct tok_info *ti = netdev_priv(dev);
990 struct netdev_hw_addr *ha;
991 unsigned char address[4];
992
993 int i;
994
995
996
997 if ( ti->open_status != OPEN) return;
998 address[0] = address[1] = address[2] = address[3] = 0;
999 netdev_for_each_mc_addr(ha, dev) {
1000 address[0] |= ha->addr[2];
1001 address[1] |= ha->addr[3];
1002 address[2] |= ha->addr[4];
1003 address[3] |= ha->addr[5];
1004 }
1005 SET_PAGE(ti->srb_page);
1006 for (i = 0; i < sizeof(struct srb_set_funct_addr); i++)
1007 writeb(0, ti->srb + i);
1008
1009#define FUNCT_ADDRESS_OFST 6
1010
1011 writeb(DIR_SET_FUNC_ADDR, ti->srb + COMMAND_OFST);
1012 for (i = 0; i < 4; i++)
1013 writeb(address[i], ti->srb + FUNCT_ADDRESS_OFST + i);
1014 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1015#if TR_VERBOSE
1016 DPRINTK("Setting functional address: ");
1017 for (i=0;i<4;i++) printk("%02X ", address[i]);
1018 printk("\n");
1019#endif
1020}
1021
1022
1023
1024#define STATION_ID_OFST 4
1025
1026static netdev_tx_t tok_send_packet(struct sk_buff *skb,
1027 struct net_device *dev)
1028{
1029 struct tok_info *ti;
1030 unsigned long flags;
1031 ti = netdev_priv(dev);
1032
1033 netif_stop_queue(dev);
1034
1035
1036 spin_lock_irqsave(&(ti->lock), flags);
1037
1038
1039 ti->current_skb = skb;
1040 SET_PAGE(ti->srb_page);
1041 writeb(XMIT_UI_FRAME, ti->srb + COMMAND_OFST);
1042 writew(ti->exsap_station_id, ti->srb + STATION_ID_OFST);
1043 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1044 spin_unlock_irqrestore(&(ti->lock), flags);
1045 return NETDEV_TX_OK;
1046}
1047
1048
1049
1050static int tok_close(struct net_device *dev)
1051{
1052 struct tok_info *ti = netdev_priv(dev);
1053
1054
1055
1056 del_timer_sync(&ti->tr_timer);
1057 outb(0, dev->base_addr + ADAPTRESET);
1058 ti->sram_phys |= 1;
1059 ti->open_status = CLOSED;
1060
1061 netif_stop_queue(dev);
1062 DPRINTK("Adapter is closed.\n");
1063 return 0;
1064}
1065
1066
1067
1068#define RETCODE_OFST 2
1069#define OPEN_ERROR_CODE_OFST 6
1070#define ASB_ADDRESS_OFST 8
1071#define SRB_ADDRESS_OFST 10
1072#define ARB_ADDRESS_OFST 12
1073#define SSB_ADDRESS_OFST 14
1074
1075static char *printphase[]= {"Lobe media test","Physical insertion",
1076 "Address verification","Roll call poll","Request Parameters"};
1077static char *printerror[]={"Function failure","Signal loss","Reserved",
1078 "Frequency error","Timeout","Ring failure","Ring beaconing",
1079 "Duplicate node address",
1080 "Parameter request-retry count exceeded","Remove received",
1081 "IMPL force received","Duplicate modifier",
1082 "No monitor detected","Monitor contention failed for RPL"};
1083
1084static void __iomem *map_address(struct tok_info *ti, unsigned index, __u8 *page)
1085{
1086 if (ti->page_mask) {
1087 *page = (index >> 8) & ti->page_mask;
1088 index &= ~(ti->page_mask << 8);
1089 }
1090 return ti->sram_virt + index;
1091}
1092
1093static void dir_open_adapter (struct net_device *dev)
1094{
1095 struct tok_info *ti = netdev_priv(dev);
1096 unsigned char ret_code;
1097 __u16 err;
1098
1099 ti->srb = map_address(ti,
1100 ntohs(readw(ti->init_srb + SRB_ADDRESS_OFST)),
1101 &ti->srb_page);
1102 ti->ssb = map_address(ti,
1103 ntohs(readw(ti->init_srb + SSB_ADDRESS_OFST)),
1104 &ti->ssb_page);
1105 ti->arb = map_address(ti,
1106 ntohs(readw(ti->init_srb + ARB_ADDRESS_OFST)),
1107 &ti->arb_page);
1108 ti->asb = map_address(ti,
1109 ntohs(readw(ti->init_srb + ASB_ADDRESS_OFST)),
1110 &ti->asb_page);
1111 ti->current_skb = NULL;
1112 ret_code = readb(ti->init_srb + RETCODE_OFST);
1113 err = ntohs(readw(ti->init_srb + OPEN_ERROR_CODE_OFST));
1114 if (!ret_code) {
1115 ti->open_status = OPEN;
1116 if (ti->open_mode == AUTOMATIC) {
1117 DPRINTK("Adapter reopened.\n");
1118 }
1119 writeb(~SRB_RESP_INT, ti->mmio+ACA_OFFSET+ACA_RESET+ISRP_ODD);
1120 open_sap(EXTENDED_SAP, dev);
1121 return;
1122 }
1123 ti->open_failure = YES;
1124 if (ret_code == 7){
1125 if (err == 0x24) {
1126 if (!ti->auto_speedsave) {
1127 DPRINTK("Open failed: Adapter speed must match "
1128 "ring speed if Automatic Ring Speed Save is "
1129 "disabled.\n");
1130 ti->open_action = FAIL;
1131 }else
1132 DPRINTK("Retrying open to adjust to "
1133 "ring speed, ");
1134 } else if (err == 0x2d) {
1135 DPRINTK("Physical Insertion: No Monitor Detected, ");
1136 printk("retrying after %ds delay...\n",
1137 TR_RETRY_INTERVAL/HZ);
1138 } else if (err == 0x11) {
1139 DPRINTK("Lobe Media Function Failure (0x11), ");
1140 printk(" retrying after %ds delay...\n",
1141 TR_RETRY_INTERVAL/HZ);
1142 } else {
1143 char **prphase = printphase;
1144 char **prerror = printerror;
1145 int pnr = err / 16 - 1;
1146 int enr = err % 16 - 1;
1147 DPRINTK("TR Adapter misc open failure, error code = ");
1148 if (pnr < 0 || pnr >= ARRAY_SIZE(printphase) ||
1149 enr < 0 ||
1150 enr >= ARRAY_SIZE(printerror))
1151 printk("0x%x, invalid Phase/Error.", err);
1152 else
1153 printk("0x%x, Phase: %s, Error: %s\n", err,
1154 prphase[pnr], prerror[enr]);
1155 printk(" retrying after %ds delay...\n",
1156 TR_RETRY_INTERVAL/HZ);
1157 }
1158 } else DPRINTK("open failed: ret_code = %02X..., ", ret_code);
1159 if (ti->open_action != FAIL) {
1160 if (ti->open_mode==AUTOMATIC){
1161 ti->open_action = REOPEN;
1162 ibmtr_reset_timer(&(ti->tr_timer), dev);
1163 return;
1164 }
1165 wake_up(&ti->wait_for_reset);
1166 return;
1167 }
1168 DPRINTK("FAILURE, CAPUT\n");
1169}
1170
1171
1172
1173static irqreturn_t tok_interrupt(int irq, void *dev_id)
1174{
1175 unsigned char status;
1176
1177 struct tok_info *ti;
1178 struct net_device *dev;
1179#ifdef ENABLE_PAGING
1180 unsigned char save_srpr;
1181#endif
1182
1183 dev = dev_id;
1184#if TR_VERBOSE
1185 DPRINTK("Int from tok_driver, dev : %p irq%d\n", dev,irq);
1186#endif
1187 ti = netdev_priv(dev);
1188 if (ti->sram_phys & 1)
1189 return IRQ_NONE;
1190 spin_lock(&(ti->lock));
1191#ifdef ENABLE_PAGING
1192 save_srpr = readb(ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1193#endif
1194
1195
1196 writeb((~INT_ENABLE), ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
1197
1198
1199 if (ti->adapter_int_enable)
1200 outb(0, ti->adapter_int_enable);
1201 else
1202 outb(0, ti->global_int_enable);
1203 if (ti->do_tok_int == FIRST_INT){
1204 initial_tok_int(dev);
1205#ifdef ENABLE_PAGING
1206 writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1207#endif
1208 spin_unlock(&(ti->lock));
1209 return IRQ_HANDLED;
1210 }
1211
1212
1213 status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_ODD);
1214
1215
1216
1217
1218 if (status & ADAP_CHK_INT) {
1219 int i;
1220 void __iomem *check_reason;
1221 __u8 check_reason_page = 0;
1222 check_reason = map_address(ti,
1223 ntohs(readw(ti->mmio+ ACA_OFFSET+ACA_RW + WWCR_EVEN)),
1224 &check_reason_page);
1225 SET_PAGE(check_reason_page);
1226
1227 DPRINTK("Adapter check interrupt\n");
1228 DPRINTK("8 reason bytes follow: ");
1229 for (i = 0; i < 8; i++, check_reason++)
1230 printk("%02X ", (int) readb(check_reason));
1231 printk("\n");
1232 writeb(~ADAP_CHK_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
1233 status = readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRA_EVEN);
1234 DPRINTK("ISRA_EVEN == 0x02%x\n",status);
1235 ti->open_status = CLOSED;
1236 ti->sap_status = CLOSED;
1237 ti->open_mode = AUTOMATIC;
1238 netif_carrier_off(dev);
1239 netif_stop_queue(dev);
1240 ti->open_action = RESTART;
1241 outb(0, dev->base_addr + ADAPTRESET);
1242 ibmtr_reset_timer(&(ti->tr_timer), dev);
1243 spin_unlock(&(ti->lock));
1244 return IRQ_HANDLED;
1245 }
1246 if (readb(ti->mmio + ACA_OFFSET + ACA_RW + ISRP_EVEN)
1247 & (TCR_INT | ERR_INT | ACCESS_INT)) {
1248 DPRINTK("adapter error: ISRP_EVEN : %02x\n",
1249 (int)readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRP_EVEN));
1250 writeb(~(TCR_INT | ERR_INT | ACCESS_INT),
1251 ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
1252 status= readb(ti->mmio+ ACA_OFFSET + ACA_RW + ISRA_EVEN);
1253 DPRINTK("ISRA_EVEN == 0x02%x\n",status);
1254 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1255#ifdef ENABLE_PAGING
1256 writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1257#endif
1258 spin_unlock(&(ti->lock));
1259 return IRQ_HANDLED;
1260 }
1261 if (status & SRB_RESP_INT) {
1262 SET_PAGE(ti->srb_page);
1263#if TR_VERBOSE
1264 DPRINTK("SRB resp: cmd=%02X rsp=%02X\n",
1265 readb(ti->srb), readb(ti->srb + RETCODE_OFST));
1266#endif
1267 switch (readb(ti->srb)) {
1268 case XMIT_DIR_FRAME:{
1269 unsigned char xmit_ret_code;
1270 xmit_ret_code = readb(ti->srb + RETCODE_OFST);
1271 if (xmit_ret_code == 0xff) break;
1272 DPRINTK("error on xmit_dir_frame request: %02X\n",
1273 xmit_ret_code);
1274 if (ti->current_skb) {
1275 dev_kfree_skb_irq(ti->current_skb);
1276 ti->current_skb = NULL;
1277 }
1278
1279 netif_wake_queue(dev);
1280 if (ti->readlog_pending)
1281 ibmtr_readlog(dev);
1282 break;
1283 }
1284 case XMIT_UI_FRAME:{
1285 unsigned char xmit_ret_code;
1286
1287 xmit_ret_code = readb(ti->srb + RETCODE_OFST);
1288 if (xmit_ret_code == 0xff) break;
1289 DPRINTK("error on xmit_ui_frame request: %02X\n",
1290 xmit_ret_code);
1291 if (ti->current_skb) {
1292 dev_kfree_skb_irq(ti->current_skb);
1293 ti->current_skb = NULL;
1294 }
1295 netif_wake_queue(dev);
1296 if (ti->readlog_pending)
1297 ibmtr_readlog(dev);
1298 break;
1299 }
1300 case DIR_OPEN_ADAPTER:
1301 dir_open_adapter(dev);
1302 break;
1303 case DLC_OPEN_SAP:
1304 if (readb(ti->srb + RETCODE_OFST)) {
1305 DPRINTK("open_sap failed: ret_code = %02X, "
1306 "retrying\n",
1307 (int) readb(ti->srb + RETCODE_OFST));
1308 ti->open_action = REOPEN;
1309 ibmtr_reset_timer(&(ti->tr_timer), dev);
1310 break;
1311 }
1312 ti->exsap_station_id = readw(ti->srb + STATION_ID_OFST);
1313 ti->sap_status = OPEN;
1314 if (ti->open_mode==MANUAL){
1315 wake_up(&ti->wait_for_reset);
1316 break;
1317 }
1318 netif_wake_queue(dev);
1319 netif_carrier_on(dev);
1320 break;
1321 case DIR_INTERRUPT:
1322 case DIR_MOD_OPEN_PARAMS:
1323 case DIR_SET_GRP_ADDR:
1324 case DIR_SET_FUNC_ADDR:
1325 case DLC_CLOSE_SAP:
1326 if (readb(ti->srb + RETCODE_OFST))
1327 DPRINTK("error on %02X: %02X\n",
1328 (int) readb(ti->srb + COMMAND_OFST),
1329 (int) readb(ti->srb + RETCODE_OFST));
1330 break;
1331 case DIR_READ_LOG:
1332 if (readb(ti->srb + RETCODE_OFST)){
1333 DPRINTK("error on dir_read_log: %02X\n",
1334 (int) readb(ti->srb + RETCODE_OFST));
1335 netif_wake_queue(dev);
1336 break;
1337 }
1338#if IBMTR_DEBUG_MESSAGES
1339
1340#define LINE_ERRORS_OFST 0
1341#define INTERNAL_ERRORS_OFST 1
1342#define BURST_ERRORS_OFST 2
1343#define AC_ERRORS_OFST 3
1344#define ABORT_DELIMITERS_OFST 4
1345#define LOST_FRAMES_OFST 6
1346#define RECV_CONGEST_COUNT_OFST 7
1347#define FRAME_COPIED_ERRORS_OFST 8
1348#define FREQUENCY_ERRORS_OFST 9
1349#define TOKEN_ERRORS_OFST 10
1350
1351 DPRINTK("Line errors %02X, Internal errors %02X, "
1352 "Burst errors %02X\n" "A/C errors %02X, "
1353 "Abort delimiters %02X, Lost frames %02X\n"
1354 "Receive congestion count %02X, "
1355 "Frame copied errors %02X\nFrequency errors %02X, "
1356 "Token errors %02X\n",
1357 (int) readb(ti->srb + LINE_ERRORS_OFST),
1358 (int) readb(ti->srb + INTERNAL_ERRORS_OFST),
1359 (int) readb(ti->srb + BURST_ERRORS_OFST),
1360 (int) readb(ti->srb + AC_ERRORS_OFST),
1361 (int) readb(ti->srb + ABORT_DELIMITERS_OFST),
1362 (int) readb(ti->srb + LOST_FRAMES_OFST),
1363 (int) readb(ti->srb + RECV_CONGEST_COUNT_OFST),
1364 (int) readb(ti->srb + FRAME_COPIED_ERRORS_OFST),
1365 (int) readb(ti->srb + FREQUENCY_ERRORS_OFST),
1366 (int) readb(ti->srb + TOKEN_ERRORS_OFST));
1367#endif
1368 netif_wake_queue(dev);
1369 break;
1370 default:
1371 DPRINTK("Unknown command %02X encountered\n",
1372 (int) readb(ti->srb));
1373 }
1374 writeb(~SRB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
1375 }
1376 if (status & ASB_FREE_INT) {
1377 SET_PAGE(ti->asb_page);
1378#if TR_VERBOSE
1379 DPRINTK("ASB resp: cmd=%02X\n", readb(ti->asb));
1380#endif
1381
1382 switch (readb(ti->asb)) {
1383 case REC_DATA:
1384 case XMIT_UI_FRAME:
1385 case XMIT_DIR_FRAME:
1386 break;
1387 default:
1388 DPRINTK("unknown command in asb %02X\n",
1389 (int) readb(ti->asb));
1390 }
1391 if (readb(ti->asb + 2) != 0xff)
1392 DPRINTK("ASB error %02X in cmd %02X\n",
1393 (int) readb(ti->asb + 2), (int) readb(ti->asb));
1394 writeb(~ASB_FREE_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
1395 }
1396
1397#define STATUS_OFST 6
1398#define NETW_STATUS_OFST 6
1399
1400 if (status & ARB_CMD_INT) {
1401 SET_PAGE(ti->arb_page);
1402#if TR_VERBOSE
1403 DPRINTK("ARB resp: cmd=%02X\n", readb(ti->arb));
1404#endif
1405
1406 switch (readb(ti->arb)) {
1407 case DLC_STATUS:
1408 DPRINTK("DLC_STATUS new status: %02X on station %02X\n",
1409 ntohs(readw(ti->arb + STATUS_OFST)),
1410 ntohs(readw(ti->arb+ STATION_ID_OFST)));
1411 break;
1412 case REC_DATA:
1413 tr_rx(dev);
1414 break;
1415 case RING_STAT_CHANGE:{
1416 unsigned short ring_status;
1417 ring_status= ntohs(readw(ti->arb + NETW_STATUS_OFST));
1418 if (ibmtr_debug_trace & TRC_INIT)
1419 DPRINTK("Ring Status Change...(0x%x)\n",
1420 ring_status);
1421 if(ring_status& (REMOVE_RECV|AUTO_REMOVAL|LOBE_FAULT)){
1422 netif_stop_queue(dev);
1423 netif_carrier_off(dev);
1424 DPRINTK("Remove received, or Auto-removal error"
1425 ", or Lobe fault\n");
1426 DPRINTK("We'll try to reopen the closed adapter"
1427 " after a %d second delay.\n",
1428 TR_RETRY_INTERVAL/HZ);
1429
1430
1431
1432
1433 ti->open_mode = AUTOMATIC;
1434 ti->open_status = CLOSED;
1435 ti->open_action = REOPEN;
1436 ibmtr_reset_timer(&(ti->tr_timer), dev);
1437 } else if (ring_status & LOG_OVERFLOW) {
1438 if(netif_queue_stopped(dev))
1439 ti->readlog_pending = 1;
1440 else
1441 ibmtr_readlog(dev);
1442 }
1443 break;
1444 }
1445 case XMIT_DATA_REQ:
1446 tr_tx(dev);
1447 break;
1448 default:
1449 DPRINTK("Unknown command %02X in arb\n",
1450 (int) readb(ti->arb));
1451 break;
1452 }
1453 writeb(~ARB_CMD_INT, ti->mmio+ ACA_OFFSET+ACA_RESET + ISRP_ODD);
1454 writeb(ARB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1455 }
1456 if (status & SSB_RESP_INT) {
1457 unsigned char retcode;
1458 SET_PAGE(ti->ssb_page);
1459#if TR_VERBOSE
1460 DPRINTK("SSB resp: cmd=%02X rsp=%02X\n",
1461 readb(ti->ssb), readb(ti->ssb + 2));
1462#endif
1463
1464 switch (readb(ti->ssb)) {
1465 case XMIT_DIR_FRAME:
1466 case XMIT_UI_FRAME:
1467 retcode = readb(ti->ssb + 2);
1468 if (retcode && (retcode != 0x22))
1469 DPRINTK("xmit ret_code: %02X xmit error code: "
1470 "%02X\n",
1471 (int)retcode, (int)readb(ti->ssb + 6));
1472 else
1473 dev->stats.tx_packets++;
1474 break;
1475 case XMIT_XID_CMD:
1476 DPRINTK("xmit xid ret_code: %02X\n",
1477 (int) readb(ti->ssb + 2));
1478 default:
1479 DPRINTK("Unknown command %02X in ssb\n",
1480 (int) readb(ti->ssb));
1481 }
1482 writeb(~SSB_RESP_INT, ti->mmio+ ACA_OFFSET+ACA_RESET+ ISRP_ODD);
1483 writeb(SSB_FREE, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1484 }
1485#ifdef ENABLE_PAGING
1486 writeb(save_srpr, ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1487#endif
1488 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1489 spin_unlock(&(ti->lock));
1490 return IRQ_HANDLED;
1491}
1492
1493
1494
1495#define INIT_STATUS_OFST 1
1496#define INIT_STATUS_2_OFST 2
1497#define ENCODED_ADDRESS_OFST 8
1498
1499static void initial_tok_int(struct net_device *dev)
1500{
1501
1502 __u32 encoded_addr, hw_encoded_addr;
1503 struct tok_info *ti;
1504 unsigned char init_status;
1505
1506 ti = netdev_priv(dev);
1507
1508 ti->do_tok_int = NOT_FIRST;
1509
1510
1511 writeb(ti->sram_base, ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN);
1512#ifndef PCMCIA
1513 ti->sram_virt = ioremap(((__u32)ti->sram_base << 12), ti->avail_shared_ram);
1514#endif
1515 ti->init_srb = map_address(ti,
1516 ntohs(readw(ti->mmio + ACA_OFFSET + WRBR_EVEN)),
1517 &ti->init_srb_page);
1518 if (ti->page_mask && ti->avail_shared_ram == 127) {
1519 void __iomem *last_512;
1520 __u8 last_512_page=0;
1521 int i;
1522 last_512 = map_address(ti, 0xfe00, &last_512_page);
1523
1524 SET_PAGE(last_512_page);
1525 for (i = 0; i < 512; i++)
1526 writeb(0, last_512 + i);
1527 }
1528 SET_PAGE(ti->init_srb_page);
1529
1530#if TR_VERBOSE
1531 {
1532 int i;
1533
1534 DPRINTK("ti->init_srb_page=0x%x\n", ti->init_srb_page);
1535 DPRINTK("init_srb(%p):", ti->init_srb );
1536 for (i = 0; i < 20; i++)
1537 printk("%02X ", (int) readb(ti->init_srb + i));
1538 printk("\n");
1539 }
1540#endif
1541
1542 hw_encoded_addr = readw(ti->init_srb + ENCODED_ADDRESS_OFST);
1543 encoded_addr = ntohs(hw_encoded_addr);
1544 init_status=
1545 readb(ti->init_srb+offsetof(struct srb_init_response,init_status));
1546
1547 ti->ring_speed = init_status & 0x01 ? 16 : 4;
1548 DPRINTK("Initial interrupt : %d Mbps, shared RAM base %08x.\n",
1549 ti->ring_speed, (unsigned int)dev->mem_start);
1550 ti->auto_speedsave = (readb(ti->init_srb+INIT_STATUS_2_OFST) & 4) != 0;
1551
1552 if (ti->open_mode == MANUAL) wake_up(&ti->wait_for_reset);
1553 else tok_open_adapter((unsigned long)dev);
1554
1555}
1556
1557
1558
1559#define CMD_CORRELATE_OFST 1
1560#define DHB_ADDRESS_OFST 6
1561
1562#define FRAME_LENGTH_OFST 6
1563#define HEADER_LENGTH_OFST 8
1564#define RSAP_VALUE_OFST 9
1565
1566static void tr_tx(struct net_device *dev)
1567{
1568 struct tok_info *ti = netdev_priv(dev);
1569 struct trh_hdr *trhdr = (struct trh_hdr *) ti->current_skb->data;
1570 unsigned int hdr_len;
1571 __u32 dhb=0,dhb_base;
1572 void __iomem *dhbuf = NULL;
1573 unsigned char xmit_command;
1574 int i,dhb_len=0x4000,src_len,src_offset;
1575 struct trllc *llc;
1576 struct srb_xmit xsrb;
1577 __u8 dhb_page = 0;
1578 __u8 llc_ssap;
1579
1580 SET_PAGE(ti->asb_page);
1581
1582 if (readb(ti->asb+RETCODE_OFST) != 0xFF) DPRINTK("ASB not free !!!\n");
1583
1584
1585
1586
1587
1588 SET_PAGE(ti->arb_page);
1589 dhb=dhb_base=ntohs(readw(ti->arb + DHB_ADDRESS_OFST));
1590 if (ti->page_mask) {
1591 dhb_page = (dhb_base >> 8) & ti->page_mask;
1592 dhb=dhb_base & ~(ti->page_mask << 8);
1593 }
1594 dhbuf = ti->sram_virt + dhb;
1595
1596
1597 if (!(trhdr->saddr[0] & 0x80))
1598 hdr_len = sizeof(struct trh_hdr) - TR_MAXRIFLEN;
1599 else
1600 hdr_len = ((ntohs(trhdr->rcf) & TR_RCF_LEN_MASK) >> 8)
1601 + sizeof(struct trh_hdr) - TR_MAXRIFLEN;
1602
1603 llc = (struct trllc *) (ti->current_skb->data + hdr_len);
1604
1605 llc_ssap = llc->ssap;
1606 SET_PAGE(ti->srb_page);
1607 memcpy_fromio(&xsrb, ti->srb, sizeof(xsrb));
1608 SET_PAGE(ti->asb_page);
1609 xmit_command = xsrb.command;
1610
1611 writeb(xmit_command, ti->asb + COMMAND_OFST);
1612 writew(xsrb.station_id, ti->asb + STATION_ID_OFST);
1613 writeb(llc_ssap, ti->asb + RSAP_VALUE_OFST);
1614 writeb(xsrb.cmd_corr, ti->asb + CMD_CORRELATE_OFST);
1615 writeb(0, ti->asb + RETCODE_OFST);
1616 if ((xmit_command == XMIT_XID_CMD) || (xmit_command == XMIT_TEST_CMD)) {
1617 writew(htons(0x11), ti->asb + FRAME_LENGTH_OFST);
1618 writeb(0x0e, ti->asb + HEADER_LENGTH_OFST);
1619 SET_PAGE(dhb_page);
1620 writeb(AC, dhbuf);
1621 writeb(LLC_FRAME, dhbuf + 1);
1622 for (i = 0; i < TR_ALEN; i++)
1623 writeb((int) 0x0FF, dhbuf + i + 2);
1624 for (i = 0; i < TR_ALEN; i++)
1625 writeb(0, dhbuf + i + TR_ALEN + 2);
1626 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1627 return;
1628 }
1629
1630
1631
1632
1633 writeb(hdr_len, ti->asb + HEADER_LENGTH_OFST);
1634 writew(htons(ti->current_skb->len), ti->asb + FRAME_LENGTH_OFST);
1635 src_len=ti->current_skb->len;
1636 src_offset=0;
1637 dhb=dhb_base;
1638 while(1) {
1639 if (ti->page_mask) {
1640 dhb_page=(dhb >> 8) & ti->page_mask;
1641 dhb=dhb & ~(ti->page_mask << 8);
1642 dhb_len=0x4000-dhb;
1643 }
1644 dhbuf = ti->sram_virt + dhb;
1645 SET_PAGE(dhb_page);
1646 if (src_len > dhb_len) {
1647 memcpy_toio(dhbuf,&ti->current_skb->data[src_offset],
1648 dhb_len);
1649 src_len -= dhb_len;
1650 src_offset += dhb_len;
1651 dhb_base+=dhb_len;
1652 dhb=dhb_base;
1653 continue;
1654 }
1655 memcpy_toio(dhbuf, &ti->current_skb->data[src_offset], src_len);
1656 break;
1657 }
1658 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1659 dev->stats.tx_bytes += ti->current_skb->len;
1660 dev_kfree_skb_irq(ti->current_skb);
1661 ti->current_skb = NULL;
1662 netif_wake_queue(dev);
1663 if (ti->readlog_pending)
1664 ibmtr_readlog(dev);
1665}
1666
1667
1668
1669
1670#define RECEIVE_BUFFER_OFST 6
1671#define LAN_HDR_LENGTH_OFST 8
1672#define DLC_HDR_LENGTH_OFST 9
1673
1674#define DSAP_OFST 0
1675#define SSAP_OFST 1
1676#define LLC_OFST 2
1677#define PROTID_OFST 3
1678#define ETHERTYPE_OFST 6
1679
1680static void tr_rx(struct net_device *dev)
1681{
1682 struct tok_info *ti = netdev_priv(dev);
1683 __u32 rbuffer;
1684 void __iomem *rbuf, *rbufdata, *llc;
1685 __u8 rbuffer_page = 0;
1686 unsigned char *data;
1687 unsigned int rbuffer_len, lan_hdr_len, hdr_len, ip_len, length;
1688 unsigned char dlc_hdr_len;
1689 struct sk_buff *skb;
1690 unsigned int skb_size = 0;
1691 int IPv4_p = 0;
1692 unsigned int chksum = 0;
1693 struct iphdr *iph;
1694 struct arb_rec_req rarb;
1695
1696 SET_PAGE(ti->arb_page);
1697 memcpy_fromio(&rarb, ti->arb, sizeof(rarb));
1698 rbuffer = ntohs(rarb.rec_buf_addr) ;
1699 rbuf = map_address(ti, rbuffer, &rbuffer_page);
1700
1701 SET_PAGE(ti->asb_page);
1702
1703 if (readb(ti->asb + RETCODE_OFST) !=0xFF) DPRINTK("ASB not free !!!\n");
1704
1705 writeb(REC_DATA, ti->asb + COMMAND_OFST);
1706 writew(rarb.station_id, ti->asb + STATION_ID_OFST);
1707 writew(rarb.rec_buf_addr, ti->asb + RECEIVE_BUFFER_OFST);
1708
1709 lan_hdr_len = rarb.lan_hdr_len;
1710 if (lan_hdr_len > sizeof(struct trh_hdr)) {
1711 DPRINTK("Linux cannot handle greater than 18 bytes RIF\n");
1712 return;
1713 }
1714 dlc_hdr_len = readb(ti->arb + DLC_HDR_LENGTH_OFST);
1715 hdr_len = lan_hdr_len + sizeof(struct trllc) + sizeof(struct iphdr);
1716
1717 SET_PAGE(rbuffer_page);
1718 llc = rbuf + offsetof(struct rec_buf, data) + lan_hdr_len;
1719
1720#if TR_VERBOSE
1721 DPRINTK("offsetof data: %02X lan_hdr_len: %02X\n",
1722 (__u32) offsetof(struct rec_buf, data), (unsigned int) lan_hdr_len);
1723 DPRINTK("llc: %08X rec_buf_addr: %04X dev->mem_start: %lX\n",
1724 llc, ntohs(rarb.rec_buf_addr), dev->mem_start);
1725 DPRINTK("dsap: %02X, ssap: %02X, llc: %02X, protid: %02X%02X%02X, "
1726 "ethertype: %04X\n",
1727 (int) readb(llc + DSAP_OFST), (int) readb(llc + SSAP_OFST),
1728 (int) readb(llc + LLC_OFST), (int) readb(llc + PROTID_OFST),
1729 (int) readb(llc+PROTID_OFST+1),(int)readb(llc+PROTID_OFST + 2),
1730 (int) ntohs(readw(llc + ETHERTYPE_OFST)));
1731#endif
1732 if (readb(llc + offsetof(struct trllc, llc)) != UI_CMD) {
1733 SET_PAGE(ti->asb_page);
1734 writeb(DATA_LOST, ti->asb + RETCODE_OFST);
1735 dev->stats.rx_dropped++;
1736 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1737 return;
1738 }
1739 length = ntohs(rarb.frame_len);
1740 if (readb(llc + DSAP_OFST) == EXTENDED_SAP &&
1741 readb(llc + SSAP_OFST) == EXTENDED_SAP &&
1742 length >= hdr_len) IPv4_p = 1;
1743#if TR_VERBOSE
1744#define SADDR_OFST 8
1745#define DADDR_OFST 2
1746
1747 if (!IPv4_p) {
1748
1749 void __iomem *trhhdr = rbuf + offsetof(struct rec_buf, data);
1750 u8 saddr[6];
1751 u8 daddr[6];
1752 int i;
1753 for (i = 0 ; i < 6 ; i++)
1754 saddr[i] = readb(trhhdr + SADDR_OFST + i);
1755 for (i = 0 ; i < 6 ; i++)
1756 daddr[i] = readb(trhhdr + DADDR_OFST + i);
1757 DPRINTK("Probably non-IP frame received.\n");
1758 DPRINTK("ssap: %02X dsap: %02X "
1759 "saddr: %pM daddr: %pM\n",
1760 readb(llc + SSAP_OFST), readb(llc + DSAP_OFST),
1761 saddr, daddr);
1762 }
1763#endif
1764
1765
1766 skb_size=length-lan_hdr_len+sizeof(struct trh_hdr)+sizeof(struct trllc);
1767
1768 if (!(skb = dev_alloc_skb(skb_size))) {
1769 DPRINTK("out of memory. frame dropped.\n");
1770 dev->stats.rx_dropped++;
1771 SET_PAGE(ti->asb_page);
1772 writeb(DATA_LOST, ti->asb + offsetof(struct asb_rec, ret_code));
1773 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1774 return;
1775 }
1776
1777 skb_reserve(skb, sizeof(struct trh_hdr) - lan_hdr_len);
1778 skb_put(skb, length);
1779 data = skb->data;
1780 rbuffer_len = ntohs(readw(rbuf + offsetof(struct rec_buf, buf_len)));
1781 rbufdata = rbuf + offsetof(struct rec_buf, data);
1782
1783 if (IPv4_p) {
1784
1785 memcpy_fromio(data, rbufdata, hdr_len);
1786
1787
1788 iph= (struct iphdr *)(data+ lan_hdr_len + sizeof(struct trllc));
1789 ip_len = ntohs(iph->tot_len) - sizeof(struct iphdr);
1790 length -= hdr_len;
1791 if ((ip_len <= length) && (ip_len > 7))
1792 length = ip_len;
1793 data += hdr_len;
1794 rbuffer_len -= hdr_len;
1795 rbufdata += hdr_len;
1796 }
1797
1798#define BUFFER_POINTER_OFST 2
1799#define BUFFER_LENGTH_OFST 6
1800 for (;;) {
1801 if (ibmtr_debug_trace&TRC_INITV && length < rbuffer_len)
1802 DPRINTK("CURIOUS, length=%d < rbuffer_len=%d\n",
1803 length,rbuffer_len);
1804 if (IPv4_p)
1805 chksum=csum_partial_copy_nocheck((void*)rbufdata,
1806 data,length<rbuffer_len?length:rbuffer_len,chksum);
1807 else
1808 memcpy_fromio(data, rbufdata, rbuffer_len);
1809 rbuffer = ntohs(readw(rbuf+BUFFER_POINTER_OFST)) ;
1810 if (!rbuffer)
1811 break;
1812 rbuffer -= 2;
1813 length -= rbuffer_len;
1814 data += rbuffer_len;
1815 rbuf = map_address(ti, rbuffer, &rbuffer_page);
1816 SET_PAGE(rbuffer_page);
1817 rbuffer_len = ntohs(readw(rbuf + BUFFER_LENGTH_OFST));
1818 rbufdata = rbuf + offsetof(struct rec_buf, data);
1819 }
1820
1821 SET_PAGE(ti->asb_page);
1822 writeb(0, ti->asb + offsetof(struct asb_rec, ret_code));
1823
1824 writeb(RESP_IN_ASB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1825
1826 dev->stats.rx_bytes += skb->len;
1827 dev->stats.rx_packets++;
1828
1829 skb->protocol = tr_type_trans(skb, dev);
1830 if (IPv4_p) {
1831 skb->csum = chksum;
1832 skb->ip_summed = CHECKSUM_COMPLETE;
1833 }
1834 netif_rx(skb);
1835}
1836
1837
1838
1839static void ibmtr_reset_timer(struct timer_list *tmr, struct net_device *dev)
1840{
1841 tmr->expires = jiffies + TR_RETRY_INTERVAL;
1842 tmr->data = (unsigned long) dev;
1843 tmr->function = tok_rerun;
1844 init_timer(tmr);
1845 add_timer(tmr);
1846}
1847
1848
1849
1850static void tok_rerun(unsigned long dev_addr)
1851{
1852 struct net_device *dev = (struct net_device *)dev_addr;
1853 struct tok_info *ti = netdev_priv(dev);
1854
1855 if ( ti->open_action == RESTART){
1856 ti->do_tok_int = FIRST_INT;
1857 outb(0, dev->base_addr + ADAPTRESETREL);
1858#ifdef ENABLE_PAGING
1859 if (ti->page_mask)
1860 writeb(SRPR_ENABLE_PAGING,
1861 ti->mmio + ACA_OFFSET + ACA_RW + SRPR_EVEN);
1862#endif
1863
1864 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1865 } else
1866 tok_open_adapter(dev_addr);
1867}
1868
1869
1870
1871static void ibmtr_readlog(struct net_device *dev)
1872{
1873 struct tok_info *ti;
1874
1875 ti = netdev_priv(dev);
1876
1877 ti->readlog_pending = 0;
1878 SET_PAGE(ti->srb_page);
1879 writeb(DIR_READ_LOG, ti->srb);
1880 writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
1881 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1882
1883 netif_stop_queue(dev);
1884
1885}
1886
1887
1888
1889static int ibmtr_change_mtu(struct net_device *dev, int mtu)
1890{
1891 struct tok_info *ti = netdev_priv(dev);
1892
1893 if (ti->ring_speed == 16 && mtu > ti->maxmtu16)
1894 return -EINVAL;
1895 if (ti->ring_speed == 4 && mtu > ti->maxmtu4)
1896 return -EINVAL;
1897 dev->mtu = mtu;
1898 return 0;
1899}
1900
1901
1902#ifdef MODULE
1903
1904
1905static struct net_device *dev_ibmtr[IBMTR_MAX_ADAPTERS];
1906static int io[IBMTR_MAX_ADAPTERS] = { 0xa20, 0xa24 };
1907static int irq[IBMTR_MAX_ADAPTERS];
1908static int mem[IBMTR_MAX_ADAPTERS];
1909
1910MODULE_LICENSE("GPL");
1911
1912module_param_array(io, int, NULL, 0);
1913module_param_array(irq, int, NULL, 0);
1914module_param_array(mem, int, NULL, 0);
1915
1916static int __init ibmtr_init(void)
1917{
1918 int i;
1919 int count=0;
1920
1921 find_turbo_adapters(io);
1922
1923 for (i = 0; i < IBMTR_MAX_ADAPTERS && io[i]; i++) {
1924 struct net_device *dev;
1925 irq[i] = 0;
1926 mem[i] = 0;
1927 dev = alloc_trdev(sizeof(struct tok_info));
1928 if (dev == NULL) {
1929 if (i == 0)
1930 return -ENOMEM;
1931 break;
1932 }
1933 dev->base_addr = io[i];
1934 dev->irq = irq[i];
1935 dev->mem_start = mem[i];
1936
1937 if (ibmtr_probe_card(dev)) {
1938 free_netdev(dev);
1939 continue;
1940 }
1941 dev_ibmtr[i] = dev;
1942 count++;
1943 }
1944 if (count) return 0;
1945 printk("ibmtr: register_netdev() returned non-zero.\n");
1946 return -EIO;
1947}
1948module_init(ibmtr_init);
1949
1950static void __exit ibmtr_cleanup(void)
1951{
1952 int i;
1953
1954 for (i = 0; i < IBMTR_MAX_ADAPTERS; i++){
1955 if (!dev_ibmtr[i])
1956 continue;
1957 unregister_netdev(dev_ibmtr[i]);
1958 ibmtr_cleanup_card(dev_ibmtr[i]);
1959 free_netdev(dev_ibmtr[i]);
1960 }
1961}
1962module_exit(ibmtr_cleanup);
1963#endif
1964