forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibmtr.c
1964 lines (1764 loc) · 61.4 KB
/
ibmtr.c
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ibmtr.c: A shared-memory IBM Token Ring 16/4 driver for linux
*
* Written 1993 by Mark Swanson and Peter De Schrijver.
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*
* This device driver should work with Any IBM Token Ring Card that does
* not use DMA.
*
* I used Donald Becker's (becker@scyld.com) device driver work
* as a base for most of my initial work.
*
* Changes by Peter De Schrijver
* (Peter.Deschrijver@linux.cc.kuleuven.ac.be) :
*
* + changed name to ibmtr.c in anticipation of other tr boards.
* + changed reset code and adapter open code.
* + added SAP open code.
* + a first attempt to write interrupt, transmit and receive routines.
*
* Changes by David W. Morris (dwm@shell.portal.com) :
* 941003 dwm: - Restructure tok_probe for multiple adapters, devices.
* + Add comments, misc reorg for clarity.
* + Flatten interrupt handler levels.
*
* Changes by Farzad Farid (farzy@zen.via.ecp.fr)
* and Pascal Andre (andre@chimay.via.ecp.fr) (March 9 1995) :
* + multi ring support clean up.
* + RFC1042 compliance enhanced.
*
* Changes by Pascal Andre (andre@chimay.via.ecp.fr) (September 7 1995) :
* + bug correction in tr_tx
* + removed redundant information display
* + some code reworking
*
* Changes by Michel Lespinasse (walken@via.ecp.fr),
* Yann Doussot (doussot@via.ecp.fr) and Pascal Andre (andre@via.ecp.fr)
* (February 18, 1996) :
* + modified shared memory and mmio access port the driver to
* alpha platform (structure access -> readb/writeb)
*
* Changes by Steve Kipisz (bungy@ibm.net or kipisz@vnet.ibm.com)
* (January 18 1996):
* + swapped WWOR and WWCR in ibmtr.h
* + moved some init code from tok_probe into trdev_init. The
* PCMCIA code can call trdev_init to complete initializing
* the driver.
* + added -DPCMCIA to support PCMCIA
* + detecting PCMCIA Card Removal in interrupt handler. If
* ISRP is FF, then a PCMCIA card has been removed
* 10/2000 Burt needed a new method to avoid crashing the OS
*
* Changes by Paul Norton (pnorton@cts.com) :
* + restructured the READ.LOG logic to prevent the transmit SRB
* from being rudely overwritten before the transmit cycle is
* complete. (August 15 1996)
* + completed multiple adapter support. (November 20 1996)
* + implemented csum_partial_copy in tr_rx and increased receive
* buffer size and count. Minor fixes. (March 15, 1997)
*
* Changes by Christopher Turcksin <wabbit@rtfc.demon.co.uk>
* + Now compiles ok as a module again.
*
* Changes by Paul Norton (pnorton@ieee.org) :
* + moved the header manipulation code in tr_tx and tr_rx to
* net/802/tr.c. (July 12 1997)
* + add retry and timeout on open if cable disconnected. (May 5 1998)
* + lifted 2000 byte mtu limit. now depends on shared-RAM size.
* May 25 1998)
* + can't allocate 2k recv buff at 8k shared-RAM. (20 October 1998)
*
* Changes by Joel Sloan (jjs@c-me.com) :
* + disable verbose debug messages by default - to enable verbose
* debugging, edit the IBMTR_DEBUG_MESSAGES define below
*
* Changes by Mike Phillips <phillim@amtrak.com> :
* + Added extra #ifdef's to work with new PCMCIA Token Ring Code.
* The PCMCIA code now just sets up the card so it can be recognized
* by ibmtr_probe. Also checks allocated memory vs. on-board memory
* for correct figure to use.
*
* Changes by Tim Hockin (thockin@isunix.it.ilstu.edu) :
* + added spinlocks for SMP sanity (10 March 1999)
*
* Changes by Jochen Friedrich to enable RFC1469 Option 2 multicasting
* i.e. using functional address C0 00 00 04 00 00 to transmit and
* receive multicast packets.
*
* Changes by Mike Sullivan (based on original sram patch by Dave Grothe
* to support windowing into on adapter shared ram.
* i.e. Use LANAID to setup a PnP configuration with 16K RAM. Paging
* will shift this 16K window over the entire available shared RAM.
*
* Changes by Peter De Schrijver (p2@mind.be) :
* + fixed a problem with PCMCIA card removal
*
* Change by Mike Sullivan et al.:
* + added turbo card support. No need to use lanaid to configure
* the adapter into isa compatibility mode.
*
* Changes by Burt Silverman to allow the computer to behave nicely when
* a cable is pulled or not in place, or a PCMCIA card is removed hot.
*/
/* change the define of IBMTR_DEBUG_MESSAGES to a nonzero value
in the event that chatty debug messages are desired - jjs 12/30/98 */
#define IBMTR_DEBUG_MESSAGES 0
#include <linux/module.h>
#include <linux/sched.h>
#ifdef PCMCIA /* required for ibmtr_cs.c to build */
#undef MODULE /* yes, really */
#undef ENABLE_PAGING
#else
#define ENABLE_PAGING 1
#endif
/* changes the output format of driver initialization */
#define TR_VERBOSE 0
/* some 95 OS send many non UI frame; this allow removing the warning */
#define TR_FILTERNONUI 1
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/trdevice.h>
#include <linux/ibmtr.h>
#include <net/checksum.h>
#include <asm/io.h>
#define DPRINTK(format, args...) printk("%s: " format, dev->name , ## args)
#define DPRINTD(format, args...) DummyCall("%s: " format, dev->name , ## args)
/* version and credits */
#ifndef PCMCIA
static char version[] __devinitdata =
"\nibmtr.c: v1.3.57 8/ 7/94 Peter De Schrijver and Mark Swanson\n"
" v2.1.125 10/20/98 Paul Norton <pnorton@ieee.org>\n"
" v2.2.0 12/30/98 Joel Sloan <jjs@c-me.com>\n"
" v2.2.1 02/08/00 Mike Sullivan <sullivam@us.ibm.com>\n"
" v2.2.2 07/27/00 Burt Silverman <burts@us.ibm.com>\n"
" v2.4.0 03/01/01 Mike Sullivan <sullivan@us.ibm.com>\n";
#endif
/* this allows displaying full adapter information */
static char *channel_def[] __devinitdata = { "ISA", "MCA", "ISA P&P" };
static char pcchannelid[] __devinitdata = {
0x05, 0x00, 0x04, 0x09,
0x04, 0x03, 0x04, 0x0f,
0x03, 0x06, 0x03, 0x01,
0x03, 0x01, 0x03, 0x00,
0x03, 0x09, 0x03, 0x09,
0x03, 0x00, 0x02, 0x00
};
static char mcchannelid[] __devinitdata = {
0x04, 0x0d, 0x04, 0x01,
0x05, 0x02, 0x05, 0x03,
0x03, 0x06, 0x03, 0x03,
0x05, 0x08, 0x03, 0x04,
0x03, 0x05, 0x03, 0x01,
0x03, 0x08, 0x02, 0x00
};
static char __devinit *adapter_def(char type)
{
switch (type) {
case 0xF: return "PC Adapter | PC Adapter II | Adapter/A";
case 0xE: return "16/4 Adapter | 16/4 Adapter/A (long)";
case 0xD: return "16/4 Adapter/A (short) | 16/4 ISA-16 Adapter";
case 0xC: return "Auto 16/4 Adapter";
default: return "adapter (unknown type)";
}
};
#define TRC_INIT 0x01 /* Trace initialization & PROBEs */
#define TRC_INITV 0x02 /* verbose init trace points */
static unsigned char ibmtr_debug_trace = 0;
static int ibmtr_probe1(struct net_device *dev, int ioaddr);
static unsigned char get_sram_size(struct tok_info *adapt_info);
static int trdev_init(struct net_device *dev);
static int tok_open(struct net_device *dev);
static int tok_init_card(struct net_device *dev);
static void tok_open_adapter(unsigned long dev_addr);
static void open_sap(unsigned char type, struct net_device *dev);
static void tok_set_multicast_list(struct net_device *dev);
static netdev_tx_t tok_send_packet(struct sk_buff *skb,
struct net_device *dev);
static int tok_close(struct net_device *dev);
static irqreturn_t tok_interrupt(int irq, void *dev_id);
static void initial_tok_int(struct net_device *dev);
static void tr_tx(struct net_device *dev);
static void tr_rx(struct net_device *dev);
static void ibmtr_reset_timer(struct timer_list*tmr,struct net_device *dev);
static void tok_rerun(unsigned long dev_addr);
static void ibmtr_readlog(struct net_device *dev);
static int ibmtr_change_mtu(struct net_device *dev, int mtu);
static void find_turbo_adapters(int *iolist);
static int ibmtr_portlist[IBMTR_MAX_ADAPTERS+1] __devinitdata = {
0xa20, 0xa24, 0, 0, 0
};
static int __devinitdata turbo_io[IBMTR_MAX_ADAPTERS] = {0};
static int __devinitdata turbo_irq[IBMTR_MAX_ADAPTERS] = {0};
static int __devinitdata turbo_searched = 0;
#ifndef PCMCIA
static __u32 ibmtr_mem_base __devinitdata = 0xd0000;
#endif
static void __devinit PrtChanID(char *pcid, short stride)
{
short i, j;
for (i = 0, j = 0; i < 24; i++, j += stride)
printk("%1x", ((int) pcid[j]) & 0x0f);
printk("\n");
}
static void __devinit HWPrtChanID(void __iomem *pcid, short stride)
{
short i, j;
for (i = 0, j = 0; i < 24; i++, j += stride)
printk("%1x", ((int) readb(pcid + j)) & 0x0f);
printk("\n");
}
/* We have to ioremap every checked address, because isa_readb is
* going away.
*/
static void __devinit find_turbo_adapters(int *iolist)
{
int ram_addr;
int index=0;
void __iomem *chanid;
int found_turbo=0;
unsigned char *tchanid, ctemp;
int i, j;
unsigned long jif;
void __iomem *ram_mapped ;
if (turbo_searched == 1) return;
turbo_searched=1;
for (ram_addr=0xC0000; ram_addr < 0xE0000; ram_addr+=0x2000) {
__u32 intf_tbl=0;
found_turbo=1;
ram_mapped = ioremap((u32)ram_addr,0x1fff) ;
if (ram_mapped==NULL)
continue ;
chanid=(CHANNEL_ID + ram_mapped);
tchanid=pcchannelid;
ctemp=readb(chanid) & 0x0f;
if (ctemp != *tchanid) continue;
for (i=2,j=1; i<=46; i=i+2,j++) {
if ((readb(chanid+i) & 0x0f) != tchanid[j]){
found_turbo=0;
break;
}
}
if (!found_turbo) continue;
writeb(0x90, ram_mapped+0x1E01);
for(i=2; i<0x0f; i++) {
writeb(0x00, ram_mapped+0x1E01+i);
}
writeb(0x00, ram_mapped+0x1E01);
for(jif=jiffies+TR_BUSY_INTERVAL; time_before_eq(jiffies,jif););
intf_tbl=ntohs(readw(ram_mapped+ACA_OFFSET+ACA_RW+WRBR_EVEN));
if (intf_tbl) {
#if IBMTR_DEBUG_MESSAGES
printk("ibmtr::find_turbo_adapters, Turbo found at "
"ram_addr %x\n",ram_addr);
printk("ibmtr::find_turbo_adapters, interface_table ");
for(i=0; i<6; i++) {
printk("%x:",readb(ram_addr+intf_tbl+i));
}
printk("\n");
#endif
turbo_io[index]=ntohs(readw(ram_mapped+intf_tbl+4));
turbo_irq[index]=readb(ram_mapped+intf_tbl+3);
outb(0, turbo_io[index] + ADAPTRESET);
for(jif=jiffies+TR_RST_TIME;time_before_eq(jiffies,jif););
outb(0, turbo_io[index] + ADAPTRESETREL);
index++;
continue;
}
#if IBMTR_DEBUG_MESSAGES
printk("ibmtr::find_turbo_adapters, ibmtr card found at"
" %x but not a Turbo model\n",ram_addr);
#endif
iounmap(ram_mapped) ;
} /* for */
for(i=0; i<IBMTR_MAX_ADAPTERS; i++) {
if(!turbo_io[i]) break;
for (j=0; j<IBMTR_MAX_ADAPTERS; j++) {
if ( iolist[j] && iolist[j] != turbo_io[i]) continue;
iolist[j]=turbo_io[i];
break;
}
}
}
static void ibmtr_cleanup_card(struct net_device *dev)
{
if (dev->base_addr) {
outb(0,dev->base_addr+ADAPTRESET);
schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
outb(0,dev->base_addr+ADAPTRESETREL);
}
#ifndef PCMCIA
free_irq(dev->irq, dev);
release_region(dev->base_addr, IBMTR_IO_EXTENT);
{
struct tok_info *ti = netdev_priv(dev);
iounmap(ti->mmio);
iounmap(ti->sram_virt);
}
#endif
}
/****************************************************************************
* ibmtr_probe(): Routine specified in the network device structure
* to probe for an IBM Token Ring Adapter. Routine outline:
* I. Interrogate hardware to determine if an adapter exists
* and what the speeds and feeds are
* II. Setup data structures to control execution based upon
* adapter characteristics.
*
* We expect ibmtr_probe to be called once for each device entry
* which references it.
****************************************************************************/
static int __devinit ibmtr_probe(struct net_device *dev)
{
int i;
int base_addr = dev->base_addr;
if (base_addr && base_addr <= 0x1ff) /* Don't probe at all. */
return -ENXIO;
if (base_addr > 0x1ff) { /* Check a single specified location. */
if (!ibmtr_probe1(dev, base_addr)) return 0;
return -ENODEV;
}
find_turbo_adapters(ibmtr_portlist);
for (i = 0; ibmtr_portlist[i]; i++) {
int ioaddr = ibmtr_portlist[i];
if (!ibmtr_probe1(dev, ioaddr)) return 0;
}
return -ENODEV;
}
int __devinit ibmtr_probe_card(struct net_device *dev)
{
int err = ibmtr_probe(dev);
if (!err) {
err = register_netdev(dev);
if (err)
ibmtr_cleanup_card(dev);
}
return err;
}
/*****************************************************************************/
static int __devinit ibmtr_probe1(struct net_device *dev, int PIOaddr)
{
unsigned char segment, intr=0, irq=0, i, j, cardpresent=NOTOK, temp=0;
void __iomem * t_mmio = NULL;
struct tok_info *ti = netdev_priv(dev);
void __iomem *cd_chanid;
unsigned char *tchanid, ctemp;
#ifndef PCMCIA
unsigned char t_irq=0;
unsigned long timeout;
static int version_printed;
#endif
/* Query the adapter PIO base port which will return
* indication of where MMIO was placed. We also have a
* coded interrupt number.
*/
segment = inb(PIOaddr);
if (segment < 0x40 || segment > 0xe0) {
/* Out of range values so we'll assume non-existent IO device
* but this is not necessarily a problem, esp if a turbo
* adapter is being used. */
#if IBMTR_DEBUG_MESSAGES
DPRINTK("ibmtr_probe1(): unhappy that inb(0x%X) == 0x%X, "
"Hardware Problem?\n",PIOaddr,segment);
#endif
return -ENODEV;
}
/*
* Compute the linear base address of the MMIO area
* as LINUX doesn't care about segments
*/
t_mmio = ioremap(((__u32) (segment & 0xfc) << 11) + 0x80000,2048);
if (!t_mmio) {
DPRINTK("Cannot remap mmiobase memory area") ;
return -ENODEV ;
}
intr = segment & 0x03; /* low bits is coded interrupt # */
if (ibmtr_debug_trace & TRC_INIT)
DPRINTK("PIOaddr: %4hx seg/intr: %2x mmio base: %p intr: %d\n"
, PIOaddr, (int) segment, t_mmio, (int) intr);
/*
* Now we will compare expected 'channelid' strings with
* what we is there to learn of ISA/MCA or not TR card
*/
#ifdef PCMCIA
iounmap(t_mmio);
t_mmio = ti->mmio; /*BMS to get virtual address */
irq = ti->irq; /*BMS to display the irq! */
#endif
cd_chanid = (CHANNEL_ID + t_mmio); /* for efficiency */
tchanid = pcchannelid;
cardpresent = TR_ISA; /* try ISA */
/* Suboptimize knowing first byte different */
ctemp = readb(cd_chanid) & 0x0f;
if (ctemp != *tchanid) { /* NOT ISA card, try MCA */
tchanid = mcchannelid;
cardpresent = TR_MCA;
if (ctemp != *tchanid) /* Neither ISA nor MCA */
cardpresent = NOTOK;
}
if (cardpresent != NOTOK) {
/* Know presumed type, try rest of ID */
for (i = 2, j = 1; i <= 46; i = i + 2, j++) {
if( (readb(cd_chanid+i)&0x0f) == tchanid[j]) continue;
/* match failed, not TR card */
cardpresent = NOTOK;
break;
}
}
/*
* If we have an ISA board check for the ISA P&P version,
* as it has different IRQ settings
*/
if (cardpresent == TR_ISA && (readb(AIPFID + t_mmio) == 0x0e))
cardpresent = TR_ISAPNP;
if (cardpresent == NOTOK) { /* "channel_id" did not match, report */
if (!(ibmtr_debug_trace & TRC_INIT)) {
#ifndef PCMCIA
iounmap(t_mmio);
#endif
return -ENODEV;
}
DPRINTK( "Channel ID string not found for PIOaddr: %4hx\n",
PIOaddr);
DPRINTK("Expected for ISA: ");
PrtChanID(pcchannelid, 1);
DPRINTK(" found: ");
/* BMS Note that this can be misleading, when hardware is flaky, because you
are reading it a second time here. So with my flaky hardware, I'll see my-
self in this block, with the HW ID matching the ISA ID exactly! */
HWPrtChanID(cd_chanid, 2);
DPRINTK("Expected for MCA: ");
PrtChanID(mcchannelid, 1);
}
/* Now, setup some of the pl0 buffers for this driver.. */
/* If called from PCMCIA, it is already set up, so no need to
waste the memory, just use the existing structure */
#ifndef PCMCIA
ti->mmio = t_mmio;
for (i = 0; i < IBMTR_MAX_ADAPTERS; i++) {
if (turbo_io[i] != PIOaddr)
continue;
#if IBMTR_DEBUG_MESSAGES
printk("ibmtr::tr_probe1, setting PIOaddr %x to Turbo\n",
PIOaddr);
#endif
ti->turbo = 1;
t_irq = turbo_irq[i];
}
#endif /* !PCMCIA */
ti->readlog_pending = 0;
init_waitqueue_head(&ti->wait_for_reset);
/* if PCMCIA, the card can be recognized as either TR_ISA or TR_ISAPNP
* depending which card is inserted. */
#ifndef PCMCIA
switch (cardpresent) {
case TR_ISA:
if (intr == 0) irq = 9; /* irq2 really is irq9 */
if (intr == 1) irq = 3;
if (intr == 2) irq = 6;
if (intr == 3) irq = 7;
ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
break;
case TR_MCA:
if (intr == 0) irq = 9;
if (intr == 1) irq = 3;
if (intr == 2) irq = 10;
if (intr == 3) irq = 11;
ti->global_int_enable = 0;
ti->adapter_int_enable = 0;
ti->sram_phys=(__u32)(inb(PIOaddr+ADAPTRESETREL) & 0xfe) << 12;
break;
case TR_ISAPNP:
if (!t_irq) {
if (intr == 0) irq = 9;
if (intr == 1) irq = 3;
if (intr == 2) irq = 10;
if (intr == 3) irq = 11;
} else
irq=t_irq;
timeout = jiffies + TR_SPIN_INTERVAL;
while (!readb(ti->mmio + ACA_OFFSET + ACA_RW + RRR_EVEN)){
if (!time_after(jiffies, timeout)) continue;
DPRINTK( "Hardware timeout during initialization.\n");
iounmap(t_mmio);
return -ENODEV;
}
ti->sram_phys =
((__u32)readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_EVEN)<<12);
ti->adapter_int_enable = PIOaddr + ADAPTINTREL;
break;
} /*end switch (cardpresent) */
#endif /*not PCMCIA */
if (ibmtr_debug_trace & TRC_INIT) { /* just report int */
DPRINTK("irq=%d", irq);
printk(", sram_phys=0x%x", ti->sram_phys);
if(ibmtr_debug_trace&TRC_INITV){ /* full chat in verbose only */
DPRINTK(", ti->mmio=%p", ti->mmio);
printk(", segment=%02X", segment);
}
printk(".\n");
}
/* Get hw address of token ring card */
j = 0;
for (i = 0; i < 0x18; i = i + 2) {
/* technical reference states to do this */
temp = readb(ti->mmio + AIP + i) & 0x0f;
ti->hw_address[j] = temp;
if (j & 1)
dev->dev_addr[(j / 2)] =
ti->hw_address[j]+ (ti->hw_address[j - 1] << 4);
++j;
}
/* get Adapter type: 'F' = Adapter/A, 'E' = 16/4 Adapter II,... */
ti->adapter_type = readb(ti->mmio + AIPADAPTYPE);
/* get Data Rate: F=4Mb, E=16Mb, D=4Mb & 16Mb ?? */
ti->data_rate = readb(ti->mmio + AIPDATARATE);
/* Get Early Token Release support?: F=no, E=4Mb, D=16Mb, C=4&16Mb */
ti->token_release = readb(ti->mmio + AIPEARLYTOKEN);
/* How much shared RAM is on adapter ? */
if (ti->turbo) {
ti->avail_shared_ram=127;
} else {
ti->avail_shared_ram = get_sram_size(ti);/*in 512 byte units */
}
/* We need to set or do a bunch of work here based on previous results*/
/* Support paging? What sizes?: F=no, E=16k, D=32k, C=16 & 32k */
ti->shared_ram_paging = readb(ti->mmio + AIPSHRAMPAGE);
/* Available DHB 4Mb size: F=2048, E=4096, D=4464 */
switch (readb(ti->mmio + AIP4MBDHB)) {
case 0xe: ti->dhb_size4mb = 4096; break;
case 0xd: ti->dhb_size4mb = 4464; break;
default: ti->dhb_size4mb = 2048; break;
}
/* Available DHB 16Mb size: F=2048, E=4096, D=8192, C=16384, B=17960 */
switch (readb(ti->mmio + AIP16MBDHB)) {
case 0xe: ti->dhb_size16mb = 4096; break;
case 0xd: ti->dhb_size16mb = 8192; break;
case 0xc: ti->dhb_size16mb = 16384; break;
case 0xb: ti->dhb_size16mb = 17960; break;
default: ti->dhb_size16mb = 2048; break;
}
/* We must figure out how much shared memory space this adapter
* will occupy so that if there are two adapters we can fit both
* in. Given a choice, we will limit this adapter to 32K. The
* maximum space will will use for two adapters is 64K so if the
* adapter we are working on demands 64K (it also doesn't support
* paging), then only one adapter can be supported.
*/
/*
* determine how much of total RAM is mapped into PC space
*/
ti->mapped_ram_size= /*sixteen to onehundredtwentyeight 512byte blocks*/
1<< ((readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03) + 4);
ti->page_mask = 0;
if (ti->turbo) ti->page_mask=0xf0;
else if (ti->shared_ram_paging == 0xf); /* No paging in adapter */
else {
#ifdef ENABLE_PAGING
unsigned char pg_size = 0;
/* BMS: page size: PCMCIA, use configuration register;
ISAPNP, use LANAIDC config tool from www.ibm.com */
switch (ti->shared_ram_paging) {
case 0xf:
break;
case 0xe:
ti->page_mask = (ti->mapped_ram_size == 32) ? 0xc0 : 0;
pg_size = 32; /* 16KB page size */
break;
case 0xd:
ti->page_mask = (ti->mapped_ram_size == 64) ? 0x80 : 0;
pg_size = 64; /* 32KB page size */
break;
case 0xc:
switch (ti->mapped_ram_size) {
case 32:
ti->page_mask = 0xc0;
pg_size = 32;
break;
case 64:
ti->page_mask = 0x80;
pg_size = 64;
break;
}
break;
default:
DPRINTK("Unknown shared ram paging info %01X\n",
ti->shared_ram_paging);
iounmap(t_mmio);
return -ENODEV;
break;
} /*end switch shared_ram_paging */
if (ibmtr_debug_trace & TRC_INIT)
DPRINTK("Shared RAM paging code: %02X, "
"mapped RAM size: %dK, shared RAM size: %dK, "
"page mask: %02X\n:",
ti->shared_ram_paging, ti->mapped_ram_size / 2,
ti->avail_shared_ram / 2, ti->page_mask);
#endif /*ENABLE_PAGING */
}
#ifndef PCMCIA
/* finish figuring the shared RAM address */
if (cardpresent == TR_ISA) {
static const __u32 ram_bndry_mask[] = {
0xffffe000, 0xffffc000, 0xffff8000, 0xffff0000
};
__u32 new_base, rrr_32, chk_base, rbm;
rrr_32=readb(ti->mmio+ACA_OFFSET+ACA_RW+RRR_ODD) >> 2 & 0x03;
rbm = ram_bndry_mask[rrr_32];
new_base = (ibmtr_mem_base + (~rbm)) & rbm;/* up to boundary */
chk_base = new_base + (ti->mapped_ram_size << 9);
if (chk_base > (ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE)) {
DPRINTK("Shared RAM for this adapter (%05x) exceeds "
"driver limit (%05x), adapter not started.\n",
chk_base, ibmtr_mem_base + IBMTR_SHARED_RAM_SIZE);
iounmap(t_mmio);
return -ENODEV;
} else { /* seems cool, record what we have figured out */
ti->sram_base = new_base >> 12;
ibmtr_mem_base = chk_base;
}
}
else ti->sram_base = ti->sram_phys >> 12;
/* The PCMCIA has already got the interrupt line and the io port,
so no chance of anybody else getting it - MLP */
if (request_irq(dev->irq = irq, tok_interrupt, 0, "ibmtr", dev) != 0) {
DPRINTK("Could not grab irq %d. Halting Token Ring driver.\n",
irq);
iounmap(t_mmio);
return -ENODEV;
}
/*?? Now, allocate some of the PIO PORTs for this driver.. */
/* record PIOaddr range as busy */
if (!request_region(PIOaddr, IBMTR_IO_EXTENT, "ibmtr")) {
DPRINTK("Could not grab PIO range. Halting driver.\n");
free_irq(dev->irq, dev);
iounmap(t_mmio);
return -EBUSY;
}
if (!version_printed++) {
printk(version);
}
#endif /* !PCMCIA */
DPRINTK("%s %s found\n",
channel_def[cardpresent - 1], adapter_def(ti->adapter_type));
DPRINTK("using irq %d, PIOaddr %hx, %dK shared RAM.\n",
irq, PIOaddr, ti->mapped_ram_size / 2);
DPRINTK("Hardware address : %pM\n", dev->dev_addr);
if (ti->page_mask)
DPRINTK("Shared RAM paging enabled. "
"Page size: %uK Shared Ram size %dK\n",
((ti->page_mask^0xff)+1) >>2, ti->avail_shared_ram / 2);
else
DPRINTK("Shared RAM paging disabled. ti->page_mask %x\n",
ti->page_mask);
/* Calculate the maximum DHB we can use */
/* two cases where avail_shared_ram doesn't equal mapped_ram_size:
1. avail_shared_ram is 127 but mapped_ram_size is 128 (typical)
2. user has configured adapter for less than avail_shared_ram
but is not using paging (she should use paging, I believe)
*/
if (!ti->page_mask) {
ti->avail_shared_ram=
min(ti->mapped_ram_size,ti->avail_shared_ram);
}
switch (ti->avail_shared_ram) {
case 16: /* 8KB shared RAM */
ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)2048);
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=2;
ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)2048);
ti->rbuf_len16 = 1032;
ti->rbuf_cnt16=2;
break;
case 32: /* 16KB shared RAM */
ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=4;
ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)4096);
ti->rbuf_len16 = 1032; /*1024 usable */
ti->rbuf_cnt16=4;
break;
case 64: /* 32KB shared RAM */
ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=6;
ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)10240);
ti->rbuf_len16 = 1032;
ti->rbuf_cnt16=6;
break;
case 127: /* 63.5KB shared RAM */
ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=6;
ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)16384);
ti->rbuf_len16 = 1032;
ti->rbuf_cnt16=16;
break;
case 128: /* 64KB shared RAM */
ti->dhb_size4mb = min(ti->dhb_size4mb, (unsigned short)4464);
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=6;
ti->dhb_size16mb = min(ti->dhb_size16mb, (unsigned short)17960);
ti->rbuf_len16 = 1032;
ti->rbuf_cnt16=16;
break;
default:
ti->dhb_size4mb = 2048;
ti->rbuf_len4 = 1032;
ti->rbuf_cnt4=2;
ti->dhb_size16mb = 2048;
ti->rbuf_len16 = 1032;
ti->rbuf_cnt16=2;
break;
}
/* this formula is not smart enough for the paging case
ti->rbuf_cnt<x> = (ti->avail_shared_ram * BLOCKSZ - ADAPT_PRIVATE -
ARBLENGTH - SSBLENGTH - DLC_MAX_SAP * SAPLENGTH -
DLC_MAX_STA * STALENGTH - ti->dhb_size<x>mb * NUM_DHB -
SRBLENGTH - ASBLENGTH) / ti->rbuf_len<x>;
*/
ti->maxmtu16 = (ti->rbuf_len16 - 8) * ti->rbuf_cnt16 - TR_HLEN;
ti->maxmtu4 = (ti->rbuf_len4 - 8) * ti->rbuf_cnt4 - TR_HLEN;
/*BMS assuming 18 bytes of Routing Information (usually works) */
DPRINTK("Maximum Receive Internet Protocol MTU 16Mbps: %d, 4Mbps: %d\n",
ti->maxmtu16, ti->maxmtu4);
dev->base_addr = PIOaddr; /* set the value for device */
dev->mem_start = ti->sram_base << 12;
dev->mem_end = dev->mem_start + (ti->mapped_ram_size << 9) - 1;
trdev_init(dev);
return 0; /* Return 0 to indicate we have found a Token Ring card. */
} /*ibmtr_probe1() */
/*****************************************************************************/
/* query the adapter for the size of shared RAM */
/* the function returns the RAM size in units of 512 bytes */
static unsigned char __devinit get_sram_size(struct tok_info *adapt_info)
{
unsigned char avail_sram_code;
static unsigned char size_code[] = { 0, 16, 32, 64, 127, 128 };
/* Adapter gives
'F' -- use RRR bits 3,2
'E' -- 8kb 'D' -- 16kb
'C' -- 32kb 'A' -- 64KB
'B' - 64KB less 512 bytes at top
(WARNING ... must zero top bytes in INIT */
avail_sram_code = 0xf - readb(adapt_info->mmio + AIPAVAILSHRAM);
if (avail_sram_code) return size_code[avail_sram_code];
else /* for code 'F', must compute size from RRR(3,2) bits */
return 1 <<
((readb(adapt_info->mmio+ACA_OFFSET+ACA_RW+RRR_ODD)>>2&3)+4);
}
/*****************************************************************************/
static const struct net_device_ops trdev_netdev_ops = {
.ndo_open = tok_open,
.ndo_stop = tok_close,
.ndo_start_xmit = tok_send_packet,
.ndo_set_multicast_list = tok_set_multicast_list,
.ndo_change_mtu = ibmtr_change_mtu,
};
static int __devinit trdev_init(struct net_device *dev)
{
struct tok_info *ti = netdev_priv(dev);
SET_PAGE(ti->srb_page);
ti->open_failure = NO ;
dev->netdev_ops = &trdev_netdev_ops;
return 0;
}
/*****************************************************************************/
static int tok_init_card(struct net_device *dev)
{
struct tok_info *ti;
short PIOaddr;
unsigned long i;
PIOaddr = dev->base_addr;
ti = netdev_priv(dev);
/* Special processing for first interrupt after reset */
ti->do_tok_int = FIRST_INT;
/* Reset adapter */
writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
outb(0, PIOaddr + ADAPTRESET);
schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
outb(0, PIOaddr + ADAPTRESETREL);
#ifdef ENABLE_PAGING
if (ti->page_mask)
writeb(SRPR_ENABLE_PAGING,ti->mmio+ACA_OFFSET+ACA_RW+SRPR_EVEN);
#endif
writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
i = sleep_on_timeout(&ti->wait_for_reset, 4 * HZ);
return i? 0 : -EAGAIN;
}
/*****************************************************************************/
static int tok_open(struct net_device *dev)
{
struct tok_info *ti = netdev_priv(dev);
int i;
/*the case we were left in a failure state during a previous open */
if (ti->open_failure == YES) {
DPRINTK("Last time you were disconnected, how about now?\n");
printk("You can't insert with an ICS connector half-cocked.\n");
}
ti->open_status = CLOSED; /* CLOSED or OPEN */
ti->sap_status = CLOSED; /* CLOSED or OPEN */
ti->open_failure = NO; /* NO or YES */
ti->open_mode = MANUAL; /* MANUAL or AUTOMATIC */
ti->sram_phys &= ~1; /* to reverse what we do in tok_close */
/* init the spinlock */
spin_lock_init(&ti->lock);
init_timer(&ti->tr_timer);
i = tok_init_card(dev);
if (i) return i;
while (1){
tok_open_adapter((unsigned long) dev);
i= interruptible_sleep_on_timeout(&ti->wait_for_reset, 25 * HZ);
/* sig catch: estimate opening adapter takes more than .5 sec*/
if (i>(245*HZ)/10) break; /* fancier than if (i==25*HZ) */
if (i==0) break;
if (ti->open_status == OPEN && ti->sap_status==OPEN) {
netif_start_queue(dev);
DPRINTK("Adapter is up and running\n");
return 0;
}
i=schedule_timeout_interruptible(TR_RETRY_INTERVAL);
/* wait 30 seconds */
if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
}
outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
DPRINTK("TERMINATED via signal\n"); /*BMS useful */
return -EAGAIN;
}
/*****************************************************************************/
#define COMMAND_OFST 0
#define OPEN_OPTIONS_OFST 8
#define NUM_RCV_BUF_OFST 24
#define RCV_BUF_LEN_OFST 26
#define DHB_LENGTH_OFST 28
#define NUM_DHB_OFST 30
#define DLC_MAX_SAP_OFST 32
#define DLC_MAX_STA_OFST 33
static void tok_open_adapter(unsigned long dev_addr)
{
struct net_device *dev = (struct net_device *) dev_addr;
struct tok_info *ti;
int i;
ti = netdev_priv(dev);
SET_PAGE(ti->init_srb_page);
writeb(~SRB_RESP_INT, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_ODD);
for (i = 0; i < sizeof(struct dir_open_adapter); i++)
writeb(0, ti->init_srb + i);
writeb(DIR_OPEN_ADAPTER, ti->init_srb + COMMAND_OFST);
writew(htons(OPEN_PASS_BCON_MAC), ti->init_srb + OPEN_OPTIONS_OFST);
if (ti->ring_speed == 16) {
writew(htons(ti->dhb_size16mb), ti->init_srb + DHB_LENGTH_OFST);
writew(htons(ti->rbuf_cnt16), ti->init_srb + NUM_RCV_BUF_OFST);
writew(htons(ti->rbuf_len16), ti->init_srb + RCV_BUF_LEN_OFST);
} else {
writew(htons(ti->dhb_size4mb), ti->init_srb + DHB_LENGTH_OFST);
writew(htons(ti->rbuf_cnt4), ti->init_srb + NUM_RCV_BUF_OFST);
writew(htons(ti->rbuf_len4), ti->init_srb + RCV_BUF_LEN_OFST);
}
writeb(NUM_DHB, /* always 2 */ ti->init_srb + NUM_DHB_OFST);
writeb(DLC_MAX_SAP, ti->init_srb + DLC_MAX_SAP_OFST);
writeb(DLC_MAX_STA, ti->init_srb + DLC_MAX_STA_OFST);
ti->srb = ti->init_srb; /* We use this one in the interrupt handler */
ti->srb_page = ti->init_srb_page;
DPRINTK("Opening adapter: Xmit bfrs: %d X %d, Rcv bfrs: %d X %d\n",
readb(ti->init_srb + NUM_DHB_OFST),
ntohs(readw(ti->init_srb + DHB_LENGTH_OFST)),
ntohs(readw(ti->init_srb + NUM_RCV_BUF_OFST)),
ntohs(readw(ti->init_srb + RCV_BUF_LEN_OFST)));
writeb(INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_SET + ISRP_EVEN);
writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
}
/*****************************************************************************/
static void open_sap(unsigned char type, struct net_device *dev)
{
int i;
struct tok_info *ti = netdev_priv(dev);
SET_PAGE(ti->srb_page);
for (i = 0; i < sizeof(struct dlc_open_sap); i++)
writeb(0, ti->srb + i);
#define MAX_I_FIELD_OFST 14
#define SAP_VALUE_OFST 16
#define SAP_OPTIONS_OFST 17
#define STATION_COUNT_OFST 18
writeb(DLC_OPEN_SAP, ti->srb + COMMAND_OFST);
writew(htons(MAX_I_FIELD), ti->srb + MAX_I_FIELD_OFST);
writeb(SAP_OPEN_IND_SAP | SAP_OPEN_PRIORITY, ti->srb+ SAP_OPTIONS_OFST);
writeb(SAP_OPEN_STATION_CNT, ti->srb + STATION_COUNT_OFST);
writeb(type, ti->srb + SAP_VALUE_OFST);
writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
}
/*****************************************************************************/
static void tok_set_multicast_list(struct net_device *dev)
{
struct tok_info *ti = netdev_priv(dev);
struct netdev_hw_addr *ha;
unsigned char address[4];
int i;
/*BMS the next line is CRUCIAL or you may be sad when you */
/*BMS ifconfig tr down or hot unplug a PCMCIA card ??hownowbrowncow*/
if (/*BMSHELPdev->start == 0 ||*/ ti->open_status != OPEN) return;
address[0] = address[1] = address[2] = address[3] = 0;
netdev_for_each_mc_addr(ha, dev) {