forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheexpress.c
1750 lines (1509 loc) · 45.8 KB
/
eexpress.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
/* Intel EtherExpress 16 device driver for Linux
*
* Written by John Sullivan, 1995
* based on original code by Donald Becker, with changes by
* Alan Cox and Pauline Middelink.
*
* Support for 8-bit mode by Zoltan Szilagyi <[email protected]>
*
* Many modifications, and currently maintained, by
* Philip Blundell <[email protected]>
* Added the Compaq LTE Alan Cox <[email protected]>
* Added MCA support Adam Fritzler <[email protected]>
*
* Note - this driver is experimental still - it has problems on faster
* machines. Someone needs to sit down and go through it line by line with
* a databook...
*/
/* The EtherExpress 16 is a fairly simple card, based on a shared-memory
* design using the i82586 Ethernet coprocessor. It bears no relationship,
* as far as I know, to the similarly-named "EtherExpress Pro" range.
*
* Historically, Linux support for these cards has been very bad. However,
* things seem to be getting better slowly.
*/
/* If your card is confused about what sort of interface it has (eg it
* persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART'
* or 'SOFTSET /LISA' from DOS seems to help.
*/
/* Here's the scoop on memory mapping.
*
* There are three ways to access EtherExpress card memory: either using the
* shared-memory mapping, or using PIO through the dataport, or using PIO
* through the "shadow memory" ports.
*
* The shadow memory system works by having the card map some of its memory
* as follows:
*
* (the low five bits of the SMPTR are ignored)
*
* base+0x4000..400f memory at SMPTR+0..15
* base+0x8000..800f memory at SMPTR+16..31
* base+0xc000..c007 dubious stuff (memory at SMPTR+16..23 apparently)
* base+0xc008..c00f memory at 0x0008..0x000f
*
* This last set (the one at c008) is particularly handy because the SCB
* lives at 0x0008. So that set of ports gives us easy random access to data
* in the SCB without having to mess around setting up pointers and the like.
* We always use this method to access the SCB (via the scb_xx() functions).
*
* Dataport access works by aiming the appropriate (read or write) pointer
* at the first address you're interested in, and then reading or writing from
* the dataport. The pointers auto-increment after each transfer. We use
* this for data transfer.
*
* We don't use the shared-memory system because it allegedly doesn't work on
* all cards, and because it's a bit more prone to go wrong (it's one more
* thing to configure...).
*/
/* Known bugs:
*
* - The card seems to want to give us two interrupts every time something
* happens, where just one would be better.
*/
/*
*
* Note by Zoltan Szilagyi 10-12-96:
*
* I've succeeded in eliminating the "CU wedged" messages, and hence the
* lockups, which were only occurring with cards running in 8-bit mode ("force
* 8-bit operation" in Intel's SoftSet utility). This version of the driver
* sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the
* CU before submitting a packet for transmission, and then restarts it as soon
* as the process of handing the packet is complete. This is definitely an
* unnecessary slowdown if the card is running in 16-bit mode; therefore one
* should detect 16-bit vs 8-bit mode from the EEPROM settings and act
* accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for
* ftp's, which is significantly better than I get in DOS, so the overhead of
* stopping and restarting the CU with each transmit is not prohibitive in
* practice.
*
* Update by David Woodhouse 11/5/99:
*
* I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture.
* I assume that this is because 16-bit accesses are actually handled as two
* 8-bit accesses.
*/
#ifdef __alpha__
#define LOCKUP16 1
#endif
#ifndef LOCKUP16
#define LOCKUP16 0
#endif
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/in.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/mca-legacy.h>
#include <linux/spinlock.h>
#include <linux/bitops.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#ifndef NET_DEBUG
#define NET_DEBUG 4
#endif
#include "eexpress.h"
#define EEXP_IO_EXTENT 16
/*
* Private data declarations
*/
struct net_local
{
struct net_device_stats stats;
unsigned long last_tx; /* jiffies when last transmit started */
unsigned long init_time; /* jiffies when eexp_hw_init586 called */
unsigned short rx_first; /* first rx buf, same as RX_BUF_START */
unsigned short rx_last; /* last rx buf */
unsigned short rx_ptr; /* first rx buf to look at */
unsigned short tx_head; /* next free tx buf */
unsigned short tx_reap; /* first in-use tx buf */
unsigned short tx_tail; /* previous tx buf to tx_head */
unsigned short tx_link; /* last known-executing tx buf */
unsigned short last_tx_restart; /* set to tx_link when we
restart the CU */
unsigned char started;
unsigned short rx_buf_start;
unsigned short rx_buf_end;
unsigned short num_tx_bufs;
unsigned short num_rx_bufs;
unsigned char width; /* 0 for 16bit, 1 for 8bit */
unsigned char was_promisc;
unsigned char old_mc_count;
spinlock_t lock;
};
/* This is the code and data that is downloaded to the EtherExpress card's
* memory at boot time.
*/
static unsigned short start_code[] = {
/* 0x0000 */
0x0001, /* ISCP: busy - cleared after reset */
0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */
0x0000,0x0000, /* SCB: status, commands */
0x0000,0x0000, /* links to first command block,
first receive descriptor */
0x0000,0x0000, /* CRC error, alignment error counts */
0x0000,0x0000, /* out of resources, overrun error counts */
0x0000,0x0000, /* pad */
0x0000,0x0000,
/* 0x20 -- start of 82586 CU program */
#define CONF_LINK 0x20
0x0000,Cmd_Config,
0x0032, /* link to next command */
0x080c, /* 12 bytes follow : fifo threshold=8 */
0x2e40, /* don't rx bad frames
* SRDY/ARDY => ext. sync. : preamble len=8
* take addresses from data buffers
* 6 bytes/address
*/
0x6000, /* default backoff method & priority
* interframe spacing = 0x60 */
0xf200, /* slot time=0x200
* max collision retry = 0xf */
#define CONF_PROMISC 0x2e
0x0000, /* no HDLC : normal CRC : enable broadcast
* disable promiscuous/multicast modes */
0x003c, /* minimum frame length = 60 octets) */
0x0000,Cmd_SetAddr,
0x003e, /* link to next command */
#define CONF_HWADDR 0x38
0x0000,0x0000,0x0000, /* hardware address placed here */
0x0000,Cmd_MCast,
0x0076, /* link to next command */
#define CONF_NR_MULTICAST 0x44
0x0000, /* number of multicast addresses */
#define CONF_MULTICAST 0x46
0x0000, 0x0000, 0x0000, /* some addresses */
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000,
#define CONF_DIAG_RESULT 0x76
0x0000, Cmd_Diag,
0x007c, /* link to next command */
0x0000,Cmd_TDR|Cmd_INT,
0x0084,
#define CONF_TDR_RESULT 0x82
0x0000,
0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
0x0084 /* dummy link */
};
/* maps irq number to EtherExpress magic value */
static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
#ifdef CONFIG_MCA_LEGACY
/* mapping of the first four bits of the second POS register */
static unsigned short mca_iomap[] = {
0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200,
0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300
};
/* bits 5-7 of the second POS register */
static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 };
#endif
/*
* Prototypes for Linux interface
*/
static int eexp_open(struct net_device *dev);
static int eexp_close(struct net_device *dev);
static void eexp_timeout(struct net_device *dev);
static struct net_device_stats *eexp_stats(struct net_device *dev);
static int eexp_xmit(struct sk_buff *buf, struct net_device *dev);
static irqreturn_t eexp_irq(int irq, void *dev_addr, struct pt_regs *regs);
static void eexp_set_multicast(struct net_device *dev);
/*
* Prototypes for hardware access functions
*/
static void eexp_hw_rx_pio(struct net_device *dev);
static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
unsigned short len);
static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr);
static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
unsigned char location);
static unsigned short eexp_hw_lasttxstat(struct net_device *dev);
static void eexp_hw_txrestart(struct net_device *dev);
static void eexp_hw_txinit (struct net_device *dev);
static void eexp_hw_rxinit (struct net_device *dev);
static void eexp_hw_init586 (struct net_device *dev);
static void eexp_setup_filter (struct net_device *dev);
static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
enum eexp_iftype {AUI=0, BNC=1, TPE=2};
#define STARTED_RU 2
#define STARTED_CU 1
/*
* Primitive hardware access functions.
*/
static inline unsigned short scb_status(struct net_device *dev)
{
return inw(dev->base_addr + 0xc008);
}
static inline unsigned short scb_rdcmd(struct net_device *dev)
{
return inw(dev->base_addr + 0xc00a);
}
static inline void scb_command(struct net_device *dev, unsigned short cmd)
{
outw(cmd, dev->base_addr + 0xc00a);
}
static inline void scb_wrcbl(struct net_device *dev, unsigned short val)
{
outw(val, dev->base_addr + 0xc00c);
}
static inline void scb_wrrfa(struct net_device *dev, unsigned short val)
{
outw(val, dev->base_addr + 0xc00e);
}
static inline void set_loopback(struct net_device *dev)
{
outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
}
static inline void clear_loopback(struct net_device *dev)
{
outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
}
static inline unsigned short int SHADOW(short int addr)
{
addr &= 0x1f;
if (addr > 0xf) addr += 0x3ff0;
return addr + 0x4000;
}
/*
* Linux interface
*/
/*
* checks for presence of EtherExpress card
*/
static int __init do_express_probe(struct net_device *dev)
{
unsigned short *port;
static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
unsigned short ioaddr = dev->base_addr;
int dev_irq = dev->irq;
int err;
SET_MODULE_OWNER(dev);
dev->if_port = 0xff; /* not set */
#ifdef CONFIG_MCA_LEGACY
if (MCA_bus) {
int slot = 0;
/*
* Only find one card at a time. Subsequent calls
* will find others, however, proper multicard MCA
* probing and setup can't be done with the
* old-style Space.c init routines. -- ASF
*/
while (slot != MCA_NOTFOUND) {
int pos0, pos1;
slot = mca_find_unused_adapter(0x628B, slot);
if (slot == MCA_NOTFOUND)
break;
pos0 = mca_read_stored_pos(slot, 2);
pos1 = mca_read_stored_pos(slot, 3);
ioaddr = mca_iomap[pos1&0xf];
dev->irq = mca_irqmap[(pos1>>4)&0x7];
/*
* XXX: Transciever selection is done
* differently on the MCA version.
* How to get it to select something
* other than external/AUI is currently
* unknown. This code is just for looks. -- ASF
*/
if ((pos0 & 0x7) == 0x1)
dev->if_port = AUI;
else if ((pos0 & 0x7) == 0x5) {
if (pos1 & 0x80)
dev->if_port = BNC;
else
dev->if_port = TPE;
}
mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA");
mca_set_adapter_procfn(slot, NULL, dev);
mca_mark_as_used(slot);
break;
}
}
#endif
if (ioaddr&0xfe00) {
if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress"))
return -EBUSY;
err = eexp_hw_probe(dev,ioaddr);
release_region(ioaddr, EEXP_IO_EXTENT);
return err;
} else if (ioaddr)
return -ENXIO;
for (port=&ports[0] ; *port ; port++ )
{
unsigned short sum = 0;
int i;
if (!request_region(*port, EEXP_IO_EXTENT, "EtherExpress"))
continue;
for ( i=0 ; i<4 ; i++ )
{
unsigned short t;
t = inb(*port + ID_PORT);
sum |= (t>>4) << ((t & 0x03)<<2);
}
if (sum==0xbaba && !eexp_hw_probe(dev,*port)) {
release_region(*port, EEXP_IO_EXTENT);
return 0;
}
release_region(*port, EEXP_IO_EXTENT);
dev->irq = dev_irq;
}
return -ENODEV;
}
#ifndef MODULE
struct net_device * __init express_probe(int unit)
{
struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
int err;
if (!dev)
return ERR_PTR(-ENOMEM);
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
err = do_express_probe(dev);
if (!err)
return dev;
free_netdev(dev);
return ERR_PTR(err);
}
#endif
/*
* open and initialize the adapter, ready for use
*/
static int eexp_open(struct net_device *dev)
{
int ret;
unsigned short ioaddr = dev->base_addr;
struct net_local *lp = netdev_priv(dev);
#if NET_DEBUG > 6
printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
#endif
if (!dev->irq || !irqrmap[dev->irq])
return -ENXIO;
ret = request_irq(dev->irq,&eexp_irq,0,dev->name,dev);
if (ret) return ret;
if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
, ioaddr);
goto err_out1;
}
if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
, ioaddr+0x4000);
goto err_out2;
}
if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
, ioaddr+0x8000);
goto err_out3;
}
if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
, ioaddr+0xc000);
goto err_out4;
}
if (lp->width) {
printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
}
eexp_hw_init586(dev);
netif_start_queue(dev);
#if NET_DEBUG > 6
printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
#endif
return 0;
err_out4:
release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
err_out3:
release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
err_out2:
release_region(ioaddr, EEXP_IO_EXTENT);
err_out1:
free_irq(dev->irq, dev);
return -EBUSY;
}
/*
* close and disable the interface, leaving the 586 in reset.
*/
static int eexp_close(struct net_device *dev)
{
unsigned short ioaddr = dev->base_addr;
struct net_local *lp = netdev_priv(dev);
int irq = dev->irq;
netif_stop_queue(dev);
outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
lp->started = 0;
scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
outb(0,ioaddr+SIGNAL_CA);
free_irq(irq,dev);
outb(i586_RST,ioaddr+EEPROM_Ctrl);
release_region(ioaddr, EEXP_IO_EXTENT);
release_region(ioaddr+0x4000, 16);
release_region(ioaddr+0x8000, 16);
release_region(ioaddr+0xc000, 16);
return 0;
}
/*
* Return interface stats
*/
static struct net_device_stats *eexp_stats(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
return &lp->stats;
}
/*
* This gets called when a higher level thinks we are broken. Check that
* nothing has become jammed in the CU.
*/
static void unstick_cu(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
unsigned short ioaddr = dev->base_addr;
if (lp->started)
{
if ((jiffies - dev->trans_start)>50)
{
if (lp->tx_link==lp->last_tx_restart)
{
unsigned short boguscount=200,rsst;
printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
dev->name, scb_status(dev));
eexp_hw_txinit(dev);
lp->last_tx_restart = 0;
scb_wrcbl(dev, lp->tx_link);
scb_command(dev, SCB_CUstart);
outb(0,ioaddr+SIGNAL_CA);
while (!SCB_complete(rsst=scb_status(dev)))
{
if (!--boguscount)
{
boguscount=200;
printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
dev->name,rsst);
scb_wrcbl(dev, lp->tx_link);
scb_command(dev, SCB_CUstart);
outb(0,ioaddr+SIGNAL_CA);
}
}
netif_wake_queue(dev);
}
else
{
unsigned short status = scb_status(dev);
if (SCB_CUdead(status))
{
unsigned short txstatus = eexp_hw_lasttxstat(dev);
printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
dev->name, status, txstatus);
eexp_hw_txrestart(dev);
}
else
{
unsigned short txstatus = eexp_hw_lasttxstat(dev);
if (netif_queue_stopped(dev) && !txstatus)
{
printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
dev->name,status,txstatus);
eexp_hw_init586(dev);
netif_wake_queue(dev);
}
else
{
printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
}
}
}
}
}
else
{
if ((jiffies-lp->init_time)>10)
{
unsigned short status = scb_status(dev);
printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
dev->name, status);
eexp_hw_init586(dev);
netif_wake_queue(dev);
}
}
}
static void eexp_timeout(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
#ifdef CONFIG_SMP
unsigned long flags;
#endif
int status;
disable_irq(dev->irq);
/*
* Best would be to use synchronize_irq(); spin_lock() here
* lets make it work first..
*/
#ifdef CONFIG_SMP
spin_lock_irqsave(&lp->lock, flags);
#endif
status = scb_status(dev);
unstick_cu(dev);
printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
(SCB_complete(status)?"lost interrupt":
"board on fire"));
lp->stats.tx_errors++;
lp->last_tx = jiffies;
if (!SCB_complete(status)) {
scb_command(dev, SCB_CUabort);
outb(0,dev->base_addr+SIGNAL_CA);
}
netif_wake_queue(dev);
#ifdef CONFIG_SMP
spin_unlock_irqrestore(&lp->lock, flags);
#endif
}
/*
* Called to transmit a packet, or to allow us to right ourselves
* if the kernel thinks we've died.
*/
static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
short length = buf->len;
#ifdef CONFIG_SMP
unsigned long flags;
#endif
#if NET_DEBUG > 6
printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
#endif
if (buf->len < ETH_ZLEN) {
buf = skb_padto(buf, ETH_ZLEN);
if (buf == NULL)
return 0;
length = ETH_ZLEN;
}
disable_irq(dev->irq);
/*
* Best would be to use synchronize_irq(); spin_lock() here
* lets make it work first..
*/
#ifdef CONFIG_SMP
spin_lock_irqsave(&lp->lock, flags);
#endif
{
unsigned short *data = (unsigned short *)buf->data;
lp->stats.tx_bytes += length;
eexp_hw_tx_pio(dev,data,length);
}
dev_kfree_skb(buf);
#ifdef CONFIG_SMP
spin_unlock_irqrestore(&lp->lock, flags);
#endif
enable_irq(dev->irq);
return 0;
}
/*
* Handle an EtherExpress interrupt
* If we've finished initializing, start the RU and CU up.
* If we've already started, reap tx buffers, handle any received packets,
* check to make sure we've not become wedged.
*/
/*
* Handle an EtherExpress interrupt
* If we've finished initializing, start the RU and CU up.
* If we've already started, reap tx buffers, handle any received packets,
* check to make sure we've not become wedged.
*/
static unsigned short eexp_start_irq(struct net_device *dev,
unsigned short status)
{
unsigned short ack_cmd = SCB_ack(status);
struct net_local *lp = netdev_priv(dev);
unsigned short ioaddr = dev->base_addr;
if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
short diag_status, tdr_status;
while (SCB_CUstat(status)==2)
status = scb_status(dev);
#if NET_DEBUG > 4
printk("%s: CU went non-active (status %04x)\n",
dev->name, status);
#endif
outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
if (diag_status & 1<<11) {
printk(KERN_WARNING "%s: 82586 failed self-test\n",
dev->name);
} else if (!(diag_status & 1<<13)) {
printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
}
outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
printk(KERN_WARNING "%s: TDR reports cable %s at %d tick%s\n", dev->name, (tdr_status & TDR_SHORT)?"short":"broken", tdr_status & TDR_TIME, ((tdr_status & TDR_TIME) != 1) ? "s" : "");
}
else if (tdr_status & TDR_XCVRPROBLEM) {
printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
}
else if (tdr_status & TDR_LINKOK) {
#if NET_DEBUG > 4
printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
#endif
} else {
printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
tdr_status);
}
lp->started |= STARTED_CU;
scb_wrcbl(dev, lp->tx_link);
/* if the RU isn't running, start it now */
if (!(lp->started & STARTED_RU)) {
ack_cmd |= SCB_RUstart;
scb_wrrfa(dev, lp->rx_buf_start);
lp->rx_ptr = lp->rx_buf_start;
lp->started |= STARTED_RU;
}
ack_cmd |= SCB_CUstart | 0x2000;
}
if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
lp->started|=STARTED_RU;
return ack_cmd;
}
static void eexp_cmd_clear(struct net_device *dev)
{
unsigned long int oldtime = jiffies;
while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
if (scb_rdcmd(dev)) {
printk("%s: command didn't clear\n", dev->name);
}
}
static irqreturn_t eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
{
struct net_device *dev = dev_info;
struct net_local *lp;
unsigned short ioaddr,status,ack_cmd;
unsigned short old_read_ptr, old_write_ptr;
if (dev==NULL)
{
printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
irq);
return IRQ_NONE;
}
lp = netdev_priv(dev);
ioaddr = dev->base_addr;
spin_lock(&lp->lock);
old_read_ptr = inw(ioaddr+READ_PTR);
old_write_ptr = inw(ioaddr+WRITE_PTR);
outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
status = scb_status(dev);
#if NET_DEBUG > 4
printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
#endif
if (lp->started == (STARTED_CU | STARTED_RU)) {
do {
eexp_cmd_clear(dev);
ack_cmd = SCB_ack(status);
scb_command(dev, ack_cmd);
outb(0,ioaddr+SIGNAL_CA);
eexp_cmd_clear(dev);
if (SCB_complete(status)) {
if (!eexp_hw_lasttxstat(dev)) {
printk("%s: tx interrupt but no status\n", dev->name);
}
}
if (SCB_rxdframe(status))
eexp_hw_rx_pio(dev);
status = scb_status(dev);
} while (status & 0xc000);
if (SCB_RUdead(status))
{
printk(KERN_WARNING "%s: RU stopped: status %04x\n",
dev->name,status);
#if 0
printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
outw(lp->cur_rfd, ioaddr+READ_PTR);
printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
outw(lp->cur_rfd+6, ioaddr+READ_PTR);
printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
outw(rbd, ioaddr+READ_PTR);
printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
outw(rbd+8, ioaddr+READ_PTR);
printk("[%04x]\n", inw(ioaddr+DATAPORT));
#endif
lp->stats.rx_errors++;
#if 1
eexp_hw_rxinit(dev);
#else
lp->cur_rfd = lp->first_rfd;
#endif
scb_wrrfa(dev, lp->rx_buf_start);
scb_command(dev, SCB_RUstart);
outb(0,ioaddr+SIGNAL_CA);
}
} else {
if (status & 0x8000)
ack_cmd = eexp_start_irq(dev, status);
else
ack_cmd = SCB_ack(status);
scb_command(dev, ack_cmd);
outb(0,ioaddr+SIGNAL_CA);
}
eexp_cmd_clear(dev);
outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
#if NET_DEBUG > 6
printk("%s: leaving eexp_irq()\n", dev->name);
#endif
outw(old_read_ptr, ioaddr+READ_PTR);
outw(old_write_ptr, ioaddr+WRITE_PTR);
spin_unlock(&lp->lock);
return IRQ_HANDLED;
}
/*
* Hardware access functions
*/
/*
* Set the cable type to use.
*/
static void eexp_hw_set_interface(struct net_device *dev)
{
unsigned char oldval = inb(dev->base_addr + 0x300e);
oldval &= ~0x82;
switch (dev->if_port) {
case TPE:
oldval |= 0x2;
case BNC:
oldval |= 0x80;
break;
}
outb(oldval, dev->base_addr+0x300e);
mdelay(20);
}
/*
* Check all the receive buffers, and hand any received packets
* to the upper levels. Basic sanity check on each frame
* descriptor, though we don't bother trying to fix broken ones.
*/
static void eexp_hw_rx_pio(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
unsigned short rx_block = lp->rx_ptr;
unsigned short boguscount = lp->num_rx_bufs;
unsigned short ioaddr = dev->base_addr;
unsigned short status;
#if NET_DEBUG > 6
printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
#endif
do {
unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
outw(rx_block, ioaddr + READ_PTR);
status = inw(ioaddr + DATAPORT);
if (FD_Done(status))
{
rfd_cmd = inw(ioaddr + DATAPORT);
rx_next = inw(ioaddr + DATAPORT);
pbuf = inw(ioaddr + DATAPORT);
outw(pbuf, ioaddr + READ_PTR);
pkt_len = inw(ioaddr + DATAPORT);
if (rfd_cmd!=0x0000)
{
printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
dev->name, rfd_cmd);
continue;
}
else if (pbuf!=rx_block+0x16)
{
printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
dev->name, rx_block+0x16, pbuf);
continue;
}
else if ((pkt_len & 0xc000)!=0xc000)
{
printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
dev->name, pkt_len & 0xc000);
continue;
}
else if (!FD_OK(status))
{
lp->stats.rx_errors++;
if (FD_CRC(status))
lp->stats.rx_crc_errors++;
if (FD_Align(status))
lp->stats.rx_frame_errors++;
if (FD_Resrc(status))
lp->stats.rx_fifo_errors++;
if (FD_DMA(status))
lp->stats.rx_over_errors++;
if (FD_Short(status))
lp->stats.rx_length_errors++;
}
else
{
struct sk_buff *skb;
pkt_len &= 0x3fff;
skb = dev_alloc_skb(pkt_len+16);
if (skb == NULL)
{
printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
lp->stats.rx_dropped++;
break;
}
skb->dev = dev;
skb_reserve(skb, 2);
outw(pbuf+10, ioaddr+READ_PTR);
insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
skb->protocol = eth_type_trans(skb,dev);
netif_rx(skb);