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
106static const char version[] =
107 "eepro.c: v0.13 11/08/2001 aris@cathedrallabs.org\n";
108
109#include <linux/module.h>
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133#include <linux/kernel.h>
134#include <linux/types.h>
135#include <linux/fcntl.h>
136#include <linux/interrupt.h>
137#include <linux/ioport.h>
138#include <linux/in.h>
139#include <linux/slab.h>
140#include <linux/string.h>
141#include <linux/errno.h>
142#include <linux/netdevice.h>
143#include <linux/etherdevice.h>
144#include <linux/skbuff.h>
145#include <linux/spinlock.h>
146#include <linux/init.h>
147#include <linux/delay.h>
148
149#include <asm/system.h>
150#include <asm/bitops.h>
151#include <asm/io.h>
152#include <asm/dma.h>
153
154#define compat_dev_kfree_skb( skb, mode ) dev_kfree_skb( (skb) )
155
156#define SLOW_DOWN inb(0x80)
157
158#define compat_init_data __initdata
159
160
161
162
163static unsigned int eepro_portlist[] compat_init_data =
164 { 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
165
166
167
168
169
170
171
172
173
174#ifndef NET_DEBUG
175#define NET_DEBUG 0
176#endif
177static unsigned int net_debug = NET_DEBUG;
178
179
180#define EEPRO_IO_EXTENT 16
181
182
183#define LAN595 0
184#define LAN595TX 1
185#define LAN595FX 2
186#define LAN595FX_10ISA 3
187
188
189struct eepro_local {
190 struct net_device_stats stats;
191 unsigned rx_start;
192 unsigned tx_start;
193 int tx_last;
194 unsigned tx_end;
195 int eepro;
196
197
198
199 int version;
200
201 int stepping;
202
203 spinlock_t lock;
204
205 unsigned rcv_ram;
206 unsigned xmt_ram;
207 unsigned char xmt_bar;
208 unsigned char xmt_lower_limit_reg;
209 unsigned char xmt_upper_limit_reg;
210 short xmt_lower_limit;
211 short xmt_upper_limit;
212 short rcv_lower_limit;
213 short rcv_upper_limit;
214 unsigned char eeprom_reg;
215};
216
217
218#define SA_ADDR0 0x00
219#define SA_ADDR1 0xaa
220#define SA_ADDR2 0x00
221
222#define GetBit(x,y) ((x & (1<<y))>>y)
223
224
225#define ee_PnP 0
226#define ee_Word1 1
227#define ee_BusWidth 2
228#define ee_FlashAddr 3
229#define ee_FlashMask 0x7
230#define ee_AutoIO 6
231#define ee_reserved0 7
232#define ee_Flash 8
233#define ee_AutoNeg 9
234#define ee_IO0 10
235#define ee_IO0Mask 0x
236#define ee_IO1 15
237
238
239#define ee_IntSel 0
240#define ee_IntMask 0x7
241#define ee_LI 3
242#define ee_PC 4
243#define ee_TPE_AUI 5
244#define ee_Jabber 6
245#define ee_AutoPort 7
246#define ee_SMOUT 8
247#define ee_PROM 9
248#define ee_reserved1 10
249#define ee_AltReady 13
250#define ee_reserved2 14
251#define ee_Duplex 15
252
253
254#define ee_IA5 0
255#define ee_IA4 8
256#define ee_IA3 0
257#define ee_IA2 8
258#define ee_IA1 0
259#define ee_IA0 8
260
261
262#define ee_BNC_TPE 0
263#define ee_BootType 1
264#define ee_BootTypeMask 0x3
265#define ee_NumConn 3
266#define ee_FlashSock 4
267#define ee_PortTPE 5
268#define ee_PortBNC 6
269#define ee_PortAUI 7
270#define ee_PowerMgt 10
271#define ee_CP 13
272#define ee_CPMask 0x7
273
274
275#define ee_Stepping 0
276#define ee_StepMask 0x0F
277#define ee_BoardID 4
278#define ee_BoardMask 0x0FFF
279
280
281#define ee_INT_TO_IRQ 0
282#define ee_FX_INT2IRQ 0x1EB8
283
284
285#define ee_SIZE 0x40
286#define ee_Checksum 0xBABA
287
288
289
290#define ee_addr_vendor 0x10
291#define ee_addr_id 0x11
292#define ee_addr_SN 0x12
293#define ee_addr_CRC_8 0x14
294
295
296#define ee_vendor_intel0 0x25
297#define ee_vendor_intel1 0xD4
298#define ee_id_eepro10p0 0x10
299#define ee_id_eepro10p1 0x31
300
301#define TX_TIMEOUT 40
302
303
304
305extern int eepro_probe(struct net_device *dev);
306
307static int eepro_probe1(struct net_device *dev, short ioaddr);
308static int eepro_open(struct net_device *dev);
309static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev);
310static irqreturn_t eepro_interrupt(int irq, void *dev_id, struct pt_regs *regs);
311static void eepro_rx(struct net_device *dev);
312static void eepro_transmit_interrupt(struct net_device *dev);
313static int eepro_close(struct net_device *dev);
314static struct net_device_stats *eepro_get_stats(struct net_device *dev);
315static void set_multicast_list(struct net_device *dev);
316static void eepro_tx_timeout (struct net_device *dev);
317
318static int read_eeprom(int ioaddr, int location, struct net_device *dev);
319static int hardware_send_packet(struct net_device *dev, void *buf, short length);
320static int eepro_grab_irq(struct net_device *dev);
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#define RAM_SIZE 0x8000
353
354#define RCV_HEADER 8
355#define RCV_DEFAULT_RAM 0x6000
356
357#define XMT_HEADER 8
358#define XMT_DEFAULT_RAM (RAM_SIZE - RCV_DEFAULT_RAM)
359
360#define XMT_START_PRO RCV_DEFAULT_RAM
361#define XMT_START_10 0x0000
362#define RCV_START_PRO 0x0000
363#define RCV_START_10 XMT_DEFAULT_RAM
364
365#define RCV_DONE 0x0008
366#define RX_OK 0x2000
367#define RX_ERROR 0x0d81
368
369#define TX_DONE_BIT 0x0080
370#define TX_OK 0x2000
371#define CHAIN_BIT 0x8000
372#define XMT_STATUS 0x02
373#define XMT_CHAIN 0x04
374#define XMT_COUNT 0x06
375
376#define BANK0_SELECT 0x00
377#define BANK1_SELECT 0x40
378#define BANK2_SELECT 0x80
379
380
381#define COMMAND_REG 0x00
382#define MC_SETUP 0x03
383#define XMT_CMD 0x04
384#define DIAGNOSE_CMD 0x07
385#define RCV_ENABLE_CMD 0x08
386#define RCV_DISABLE_CMD 0x0a
387#define STOP_RCV_CMD 0x0b
388#define RESET_CMD 0x0e
389#define POWER_DOWN_CMD 0x18
390#define RESUME_XMT_CMD 0x1c
391#define SEL_RESET_CMD 0x1e
392#define STATUS_REG 0x01
393#define RX_INT 0x02
394#define TX_INT 0x04
395#define EXEC_STATUS 0x30
396#define ID_REG 0x02
397#define R_ROBIN_BITS 0xc0
398#define ID_REG_MASK 0x2c
399#define ID_REG_SIG 0x24
400#define AUTO_ENABLE 0x10
401#define INT_MASK_REG 0x03
402#define RX_STOP_MASK 0x01
403#define RX_MASK 0x02
404#define TX_MASK 0x04
405#define EXEC_MASK 0x08
406#define ALL_MASK 0x0f
407#define IO_32_BIT 0x10
408#define RCV_BAR 0x04
409#define RCV_STOP 0x06
410
411#define XMT_BAR_PRO 0x0a
412#define XMT_BAR_10 0x0b
413
414#define HOST_ADDRESS_REG 0x0c
415#define IO_PORT 0x0e
416#define IO_PORT_32_BIT 0x0c
417
418
419#define REG1 0x01
420#define WORD_WIDTH 0x02
421#define INT_ENABLE 0x80
422#define INT_NO_REG 0x02
423#define RCV_LOWER_LIMIT_REG 0x08
424#define RCV_UPPER_LIMIT_REG 0x09
425
426#define XMT_LOWER_LIMIT_REG_PRO 0x0a
427#define XMT_UPPER_LIMIT_REG_PRO 0x0b
428#define XMT_LOWER_LIMIT_REG_10 0x0b
429#define XMT_UPPER_LIMIT_REG_10 0x0a
430
431
432#define XMT_Chain_Int 0x20
433#define XMT_Chain_ErrStop 0x40
434#define RCV_Discard_BadFrame 0x80
435#define REG2 0x02
436#define PRMSC_Mode 0x01
437#define Multi_IA 0x20
438#define REG3 0x03
439#define TPE_BIT 0x04
440#define BNC_BIT 0x20
441#define REG13 0x0d
442#define FDX 0x00
443#define A_N_ENABLE 0x02
444
445#define I_ADD_REG0 0x04
446#define I_ADD_REG1 0x05
447#define I_ADD_REG2 0x06
448#define I_ADD_REG3 0x07
449#define I_ADD_REG4 0x08
450#define I_ADD_REG5 0x09
451
452#define EEPROM_REG_PRO 0x0a
453#define EEPROM_REG_10 0x0b
454
455#define EESK 0x01
456#define EECS 0x02
457#define EEDI 0x04
458#define EEDO 0x08
459
460
461#define eepro_reset(ioaddr) outb(RESET_CMD, ioaddr)
462
463
464#define eepro_sel_reset(ioaddr) { \
465 outb(SEL_RESET_CMD, ioaddr); \
466 SLOW_DOWN; \
467 SLOW_DOWN; \
468 }
469
470
471#define eepro_dis_int(ioaddr) outb(ALL_MASK, ioaddr + INT_MASK_REG)
472
473
474#define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
475
476
477#define eepro_en_int(ioaddr) outb(ALL_MASK & ~(RX_MASK | TX_MASK), \
478 ioaddr + INT_MASK_REG)
479
480
481#define eepro_en_intexec(ioaddr) outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG)
482
483
484#define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
485
486
487#define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
488
489
490#define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
491#define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
492#define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
493
494
495#define eepro_en_intline(ioaddr) outb(inb(ioaddr + REG1) | INT_ENABLE,\
496 ioaddr + REG1)
497
498
499#define eepro_dis_intline(ioaddr) outb(inb(ioaddr + REG1) & 0x7f, \
500 ioaddr + REG1);
501
502
503#define eepro_diag(ioaddr) outb(DIAGNOSE_CMD, ioaddr)
504
505
506#define eepro_ack_rx(ioaddr) outb (RX_INT, ioaddr + STATUS_REG)
507
508
509#define eepro_ack_tx(ioaddr) outb (TX_INT, ioaddr + STATUS_REG)
510
511
512#define eepro_complete_selreset(ioaddr) { \
513 lp->stats.tx_errors++;\
514 eepro_sel_reset(ioaddr);\
515 lp->tx_end = \
516 lp->xmt_lower_limit;\
517 lp->tx_start = lp->tx_end;\
518 lp->tx_last = 0;\
519 dev->trans_start = jiffies;\
520 netif_wake_queue(dev);\
521 eepro_en_rx(ioaddr);\
522 }
523
524
525
526
527
528
529
530int __init eepro_probe(struct net_device *dev)
531{
532 int i;
533 int base_addr = dev->base_addr;
534
535 SET_MODULE_OWNER(dev);
536
537#ifdef PnPWakeup
538
539
540
541 #define WakeupPort 0x279
542 #define WakeupSeq {0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,\
543 0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,\
544 0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,\
545 0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x43}
546
547 {
548 unsigned short int WS[32]=WakeupSeq;
549
550 if (check_region(WakeupPort, 2)==0) {
551
552 if (net_debug>5)
553 printk(KERN_DEBUG "Waking UP\n");
554
555 outb_p(0,WakeupPort);
556 outb_p(0,WakeupPort);
557 for (i=0; i<32; i++) {
558 outb_p(WS[i],WakeupPort);
559 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
560 }
561 } else printk(KERN_WARNING "Checkregion Failed!\n");
562 }
563#endif
564
565 if (base_addr > 0x1ff)
566 return eepro_probe1(dev, base_addr);
567
568 else if (base_addr != 0)
569 return -ENXIO;
570
571
572 for (i = 0; eepro_portlist[i]; i++) {
573 int ioaddr = eepro_portlist[i];
574
575 if (check_region(ioaddr, EEPRO_IO_EXTENT))
576 continue;
577 if (eepro_probe1(dev, ioaddr) == 0)
578 return 0;
579 }
580
581 return -ENODEV;
582}
583
584static void __init printEEPROMInfo(short ioaddr, struct net_device *dev)
585{
586 unsigned short Word;
587 int i,j;
588
589 for (i=0, j=ee_Checksum; i<ee_SIZE; i++)
590 j+=read_eeprom(ioaddr,i,dev);
591 printk(KERN_DEBUG "Checksum: %#x\n",j&0xffff);
592
593 Word=read_eeprom(ioaddr, 0, dev);
594 printk(KERN_DEBUG "Word0:\n");
595 printk(KERN_DEBUG " Plug 'n Pray: %d\n",GetBit(Word,ee_PnP));
596 printk(KERN_DEBUG " Buswidth: %d\n",(GetBit(Word,ee_BusWidth)+1)*8 );
597 printk(KERN_DEBUG " AutoNegotiation: %d\n",GetBit(Word,ee_AutoNeg));
598 printk(KERN_DEBUG " IO Address: %#x\n", (Word>>ee_IO0)<<4);
599
600 if (net_debug>4) {
601 Word=read_eeprom(ioaddr, 1, dev);
602 printk(KERN_DEBUG "Word1:\n");
603 printk(KERN_DEBUG " INT: %d\n", Word & ee_IntMask);
604 printk(KERN_DEBUG " LI: %d\n", GetBit(Word,ee_LI));
605 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
606 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
607 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
608 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber));
609 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
610 }
611
612 Word=read_eeprom(ioaddr, 5, dev);
613 printk(KERN_DEBUG "Word5:\n");
614 printk(KERN_DEBUG " BNC: %d\n",GetBit(Word,ee_BNC_TPE));
615 printk(KERN_DEBUG " NumConnectors: %d\n",GetBit(Word,ee_NumConn));
616 printk(KERN_DEBUG " Has ");
617 if (GetBit(Word,ee_PortTPE)) printk(KERN_DEBUG "TPE ");
618 if (GetBit(Word,ee_PortBNC)) printk(KERN_DEBUG "BNC ");
619 if (GetBit(Word,ee_PortAUI)) printk(KERN_DEBUG "AUI ");
620 printk(KERN_DEBUG "port(s) \n");
621
622 Word=read_eeprom(ioaddr, 6, dev);
623 printk(KERN_DEBUG "Word6:\n");
624 printk(KERN_DEBUG " Stepping: %d\n",Word & ee_StepMask);
625 printk(KERN_DEBUG " BoardID: %d\n",Word>>ee_BoardID);
626
627 Word=read_eeprom(ioaddr, 7, dev);
628 printk(KERN_DEBUG "Word7:\n");
629 printk(KERN_DEBUG " INT to IRQ:\n");
630
631 for (i=0, j=0; i<15; i++)
632 if (GetBit(Word,i)) printk(KERN_DEBUG " INT%d -> IRQ %d;",j++,i);
633
634 printk(KERN_DEBUG "\n");
635}
636
637
638static void eepro_recalc (struct net_device *dev)
639{
640 struct eepro_local * lp;
641
642 lp = dev->priv;
643 lp->xmt_ram = RAM_SIZE - lp->rcv_ram;
644
645 if (lp->eepro == LAN595FX_10ISA) {
646 lp->xmt_lower_limit = XMT_START_10;
647 lp->xmt_upper_limit = (lp->xmt_ram - 2);
648 lp->rcv_lower_limit = lp->xmt_ram;
649 lp->rcv_upper_limit = (RAM_SIZE - 2);
650 }
651 else {
652 lp->rcv_lower_limit = RCV_START_PRO;
653 lp->rcv_upper_limit = (lp->rcv_ram - 2);
654 lp->xmt_lower_limit = lp->rcv_ram;
655 lp->xmt_upper_limit = (RAM_SIZE - 2);
656 }
657}
658
659
660static void eepro_print_info (struct net_device *dev)
661{
662 struct eepro_local * lp = dev->priv;
663 int i;
664 const char * ifmap[] = {"AUI", "10Base2", "10BaseT"};
665
666 i = inb(dev->base_addr + ID_REG);
667 printk(KERN_DEBUG " id: %#x ",i);
668 printk(" io: %#x ", (unsigned)dev->base_addr);
669
670 switch (lp->eepro) {
671 case LAN595FX_10ISA:
672 printk("%s: Intel EtherExpress 10 ISA\n at %#x,",
673 dev->name, (unsigned)dev->base_addr);
674 break;
675 case LAN595FX:
676 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
677 dev->name, (unsigned)dev->base_addr);
678 break;
679 case LAN595TX:
680 printk("%s: Intel EtherExpress Pro/10 ISA at %#x,",
681 dev->name, (unsigned)dev->base_addr);
682 break;
683 case LAN595:
684 printk("%s: Intel 82595-based lan card at %#x,",
685 dev->name, (unsigned)dev->base_addr);
686 }
687
688 for (i=0; i < 6; i++)
689 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
690
691 if (net_debug > 3)
692 printk(KERN_DEBUG ", %dK RCV buffer",
693 (int)(lp->rcv_ram)/1024);
694
695 if (dev->irq > 2)
696 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
697 else
698 printk(", %s.\n", ifmap[dev->if_port]);
699
700 if (net_debug > 3) {
701 i = read_eeprom(dev->base_addr, 5, dev);
702 if (i & 0x2000)
703 printk(KERN_DEBUG "%s: Concurrent Processing is "
704 "enabled but not used!\n", dev->name);
705 }
706
707
708 if (net_debug>3)
709 printEEPROMInfo(dev->base_addr, dev);
710}
711
712
713
714
715
716static int __init eepro_probe1(struct net_device *dev, short ioaddr)
717{
718 unsigned short station_addr[6], id, counter;
719 int i, j, irqMask, retval = 0;
720 struct eepro_local *lp;
721 enum iftype { AUI=0, BNC=1, TPE=2 };
722
723
724
725
726 id=inb(ioaddr + ID_REG);
727
728 if (((id) & ID_REG_MASK) != ID_REG_SIG) {
729 retval = -ENODEV;
730 goto exit;
731 }
732
733
734
735
736
737 counter = (id & R_ROBIN_BITS);
738
739 if (((id=inb(ioaddr+ID_REG)) & R_ROBIN_BITS)!=(counter + 0x40)) {
740 retval = -ENODEV;
741 goto exit;
742 }
743
744
745 dev->priv = kmalloc(sizeof(struct eepro_local), GFP_KERNEL);
746 if (!dev->priv) {
747 retval = -ENOMEM;
748 goto exit;
749 }
750
751 memset(dev->priv, 0, sizeof(struct eepro_local));
752
753 lp = (struct eepro_local *)dev->priv;
754
755
756 lp->eepro = 0;
757 lp->xmt_bar = XMT_BAR_PRO;
758 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
759 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
760 lp->eeprom_reg = EEPROM_REG_PRO;
761
762
763
764 station_addr[0] = read_eeprom(ioaddr, 2, dev);
765
766
767
768
769 if (station_addr[0] == 0x0000 ||
770 station_addr[0] == 0xffff) {
771 lp->eepro = LAN595FX_10ISA;
772 lp->eeprom_reg = EEPROM_REG_10;
773 lp->xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
774 lp->xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
775 lp->xmt_bar = XMT_BAR_10;
776 station_addr[0] = read_eeprom(ioaddr, 2, dev);
777 }
778 station_addr[1] = read_eeprom(ioaddr, 3, dev);
779 station_addr[2] = read_eeprom(ioaddr, 4, dev);
780
781 if (!lp->eepro) {
782 if (read_eeprom(ioaddr,7,dev)== ee_FX_INT2IRQ)
783 lp->eepro = 2;
784 else if (station_addr[2] == SA_ADDR1)
785 lp->eepro = 1;
786 }
787
788
789 dev->base_addr = ioaddr;
790
791 for (i=0; i < 6; i++)
792 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
793
794
795 if (dev->mem_end < 3072 || dev->mem_end > 29696)
796 lp->rcv_ram = RCV_DEFAULT_RAM;
797
798
799 eepro_recalc(dev);
800
801
802 if (GetBit( read_eeprom(ioaddr, 5, dev),ee_BNC_TPE))
803 dev->if_port = BNC;
804 else
805 dev->if_port = TPE;
806
807 if ((dev->irq < 2) && (lp->eepro!=0)) {
808 i = read_eeprom(ioaddr, 1, dev);
809 irqMask = read_eeprom(ioaddr, 7, dev);
810 i &= 0x07;
811
812 for (j=0; ((j<16) && (i>=0)); j++) {
813 if ((irqMask & (1<<j))!=0) {
814 if (i==0) {
815 dev->irq = j;
816 break;
817 }
818 i--;
819 }
820 }
821 if (dev->irq < 2) {
822 printk(KERN_ERR " Duh! invalid interrupt vector stored in EEPROM.\n");
823 retval = -ENODEV;
824 goto freeall;
825 } else
826 if (dev->irq==2) dev->irq = 9;
827 }
828
829
830 if (!request_region(ioaddr, EEPRO_IO_EXTENT, dev->name)) {
831 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n", ioaddr);
832 goto freeall;
833 }
834 ((struct eepro_local *)dev->priv)->lock = SPIN_LOCK_UNLOCKED;
835
836 dev->open = eepro_open;
837 dev->stop = eepro_close;
838 dev->hard_start_xmit = eepro_send_packet;
839 dev->get_stats = eepro_get_stats;
840 dev->set_multicast_list = &set_multicast_list;
841 dev->tx_timeout = eepro_tx_timeout;
842 dev->watchdog_timeo = TX_TIMEOUT;
843
844
845
846 ether_setup(dev);
847
848
849 eepro_print_info(dev);
850
851
852 eepro_reset(ioaddr);
853
854exit:
855 return retval;
856freeall:
857 kfree(dev->priv);
858 goto exit;
859
860}
861
862
863
864
865
866
867
868
869
870static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
871static char irqrmap2[] = {-1,-1,4,0,1,2,-1,3,-1,4,5,6,7,-1,-1,-1};
872static int eepro_grab_irq(struct net_device *dev)
873{
874 int irqlist[] = { 3, 4, 5, 7, 9, 10, 11, 12, 0 };
875 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
876
877 eepro_sw2bank1(ioaddr);
878
879
880 eepro_en_intline(ioaddr);
881
882
883 eepro_sw2bank0(ioaddr);
884
885
886 eepro_clear_int(ioaddr);
887
888
889 eepro_en_intexec(ioaddr);
890
891 do {
892 eepro_sw2bank1(ioaddr);
893
894 temp_reg = inb(ioaddr + INT_NO_REG);
895 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
896
897 eepro_sw2bank0(ioaddr);
898
899 if (request_irq (*irqp, NULL, SA_SHIRQ, "bogus", dev) != EBUSY) {
900 unsigned long irq_mask;
901
902 irq_mask = probe_irq_on();
903
904 eepro_diag(ioaddr);
905 mdelay(20);
906
907 if (*irqp == probe_irq_off(irq_mask))
908 break;
909
910
911 eepro_clear_int(ioaddr);
912 }
913 } while (*++irqp);
914
915 eepro_sw2bank1(ioaddr);
916
917
918 eepro_dis_intline(ioaddr);
919
920 eepro_sw2bank0(ioaddr);
921
922
923 eepro_dis_int(ioaddr);
924
925
926 eepro_clear_int(ioaddr);
927
928 return dev->irq;
929}
930
931static int eepro_open(struct net_device *dev)
932{
933 unsigned short temp_reg, old8, old9;
934 int irqMask;
935 int i, ioaddr = dev->base_addr;
936 struct eepro_local *lp = (struct eepro_local *)dev->priv;
937
938 if (net_debug > 3)
939 printk(KERN_DEBUG "%s: entering eepro_open routine.\n", dev->name);
940
941 irqMask = read_eeprom(ioaddr,7,dev);
942
943 if (lp->eepro == LAN595FX_10ISA) {
944 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 3;\n");
945 }
946 else if (irqMask == ee_FX_INT2IRQ)
947 {
948 lp->eepro = 2;
949 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 2;\n");
950 }
951
952 else if ((dev->dev_addr[0] == SA_ADDR0 &&
953 dev->dev_addr[1] == SA_ADDR1 &&
954 dev->dev_addr[2] == SA_ADDR2))
955 {
956 lp->eepro = 1;
957 if (net_debug > 3) printk(KERN_DEBUG "p->eepro = 1;\n");
958 }
959
960 else lp->eepro = 0;
961
962
963 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
964 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
965 return -EAGAIN;
966 }
967
968 if (request_irq(dev->irq , &eepro_interrupt, 0, dev->name, dev)) {
969 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
970 return -EAGAIN;
971 }
972
973#ifdef irq2dev_map
974 if (((irq2dev_map[dev->irq] != 0)
975 || (irq2dev_map[dev->irq] = dev) == 0) &&
976 (irq2dev_map[dev->irq]!=dev)) {
977
978 free_irq(dev->irq, dev);
979 return -EAGAIN;
980 }
981#endif
982
983
984
985 eepro_sw2bank2(ioaddr);
986 temp_reg = inb(ioaddr + lp->eeprom_reg);
987
988 lp->stepping = temp_reg >> 5;
989
990 if (net_debug > 3)
991 printk(KERN_DEBUG "The stepping of the 82595 is %d\n", lp->stepping);
992
993 if (temp_reg & 0x10)
994 outb(temp_reg & 0xef, ioaddr + lp->eeprom_reg);
995 for (i=0; i < 6; i++)
996 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
997
998 temp_reg = inb(ioaddr + REG1);
999 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop
1000 | RCV_Discard_BadFrame, ioaddr + REG1);
1001
1002 temp_reg = inb(ioaddr + REG2);
1003 outb(temp_reg | 0x14, ioaddr + REG2);
1004
1005 temp_reg = inb(ioaddr + REG3);
1006 outb(temp_reg & 0x3f, ioaddr + REG3);
1007
1008
1009 eepro_sw2bank1(ioaddr);
1010
1011
1012 temp_reg = inb(ioaddr + INT_NO_REG);
1013 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1014 outb((temp_reg & 0xf8) | irqrmap2[dev->irq], ioaddr + INT_NO_REG);
1015 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1016
1017
1018 temp_reg = inb(ioaddr + INT_NO_REG);
1019 if (lp->eepro == LAN595FX || lp->eepro == LAN595FX_10ISA)
1020 outb((temp_reg & 0xf0) | irqrmap2[dev->irq] | 0x08,ioaddr+INT_NO_REG);
1021 else outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
1022
1023 if (net_debug > 3)
1024 printk(KERN_DEBUG "eepro_open: content of INT Reg is %x\n", temp_reg);
1025
1026
1027
1028 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1029 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
1030 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1031 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1032
1033
1034 eepro_en_intline(ioaddr);
1035
1036
1037 eepro_sw2bank0(ioaddr);
1038
1039
1040 eepro_en_int(ioaddr);
1041
1042
1043 eepro_clear_int(ioaddr);
1044
1045
1046 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
1047 lp->rx_start = lp->rcv_lower_limit;
1048 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
1049
1050
1051 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
1052 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1053 lp->tx_last = 0;
1054
1055
1056 old8 = inb(ioaddr + 8);
1057 outb(~old8, ioaddr + 8);
1058
1059 if ((temp_reg = inb(ioaddr + 8)) == old8) {
1060 if (net_debug > 3)
1061 printk(KERN_DEBUG "i82595 detected!\n");
1062 lp->version = LAN595;
1063 }
1064 else {
1065 lp->version = LAN595TX;
1066 outb(old8, ioaddr + 8);
1067 old9 = inb(ioaddr + 9);
1068
1069 if (irqMask==ee_FX_INT2IRQ) {
1070 enum iftype { AUI=0, BNC=1, TPE=2 };
1071
1072 if (net_debug > 3) {
1073 printk(KERN_DEBUG "IrqMask: %#x\n",irqMask);
1074 printk(KERN_DEBUG "i82595FX detected!\n");
1075 }
1076 lp->version = LAN595FX;
1077 outb(old9, ioaddr + 9);
1078 if (dev->if_port != TPE) {
1079
1080
1081 eepro_sw2bank2(ioaddr);
1082 temp_reg = inb(ioaddr + REG13);
1083
1084
1085 outb(temp_reg & ~(FDX | A_N_ENABLE), REG13);
1086 eepro_sw2bank0(ioaddr);
1087 }
1088 }
1089 else if (net_debug > 3) {
1090 printk(KERN_DEBUG "temp_reg: %#x ~old9: %#x\n",temp_reg,((~old9)&0xff));
1091 printk(KERN_DEBUG "i82595TX detected!\n");
1092 }
1093 }
1094
1095 eepro_sel_reset(ioaddr);
1096
1097 netif_start_queue(dev);
1098
1099 if (net_debug > 3)
1100 printk(KERN_DEBUG "%s: exiting eepro_open routine.\n", dev->name);
1101
1102
1103 eepro_en_rx(ioaddr);
1104
1105 return 0;
1106}
1107
1108static void eepro_tx_timeout (struct net_device *dev)
1109{
1110 struct eepro_local *lp = (struct eepro_local *) dev->priv;
1111 int ioaddr = dev->base_addr;
1112
1113
1114 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1115 "network cable problem");
1116
1117
1118 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1119 "network cable problem");
1120 eepro_complete_selreset(ioaddr);
1121}
1122
1123
1124static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1125{
1126 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1127 unsigned long flags;
1128 int ioaddr = dev->base_addr;
1129 short length = skb->len;
1130
1131 if (net_debug > 5)
1132 printk(KERN_DEBUG "%s: entering eepro_send_packet routine.\n", dev->name);
1133
1134 if (length < ETH_ZLEN) {
1135 skb = skb_padto(skb, ETH_ZLEN);
1136 if (skb == NULL)
1137 return 0;
1138 length = ETH_ZLEN;
1139 }
1140 netif_stop_queue (dev);
1141
1142 eepro_dis_int(ioaddr);
1143 spin_lock_irqsave(&lp->lock, flags);
1144
1145 {
1146 unsigned char *buf = skb->data;
1147
1148 if (hardware_send_packet(dev, buf, length))
1149
1150 lp->stats.tx_dropped++;
1151 else {
1152 lp->stats.tx_bytes+=skb->len;
1153 dev->trans_start = jiffies;
1154 netif_wake_queue(dev);
1155 }
1156
1157 }
1158
1159 dev_kfree_skb (skb);
1160
1161
1162
1163
1164 if (net_debug > 5)
1165 printk(KERN_DEBUG "%s: exiting eepro_send_packet routine.\n", dev->name);
1166
1167 eepro_en_int(ioaddr);
1168 spin_unlock_irqrestore(&lp->lock, flags);
1169
1170 return 0;
1171}
1172
1173
1174
1175
1176
1177static irqreturn_t
1178eepro_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1179{
1180 struct net_device *dev = (struct net_device *)dev_id;
1181
1182 struct eepro_local *lp;
1183 int ioaddr, status, boguscount = 20;
1184 int handled = 0;
1185
1186 if (dev == NULL) {
1187 printk (KERN_ERR "eepro_interrupt(): irq %d for unknown device.\\n", irq);
1188 return IRQ_NONE;
1189 }
1190
1191 lp = (struct eepro_local *)dev->priv;
1192
1193 spin_lock(&lp->lock);
1194
1195 if (net_debug > 5)
1196 printk(KERN_DEBUG "%s: entering eepro_interrupt routine.\n", dev->name);
1197
1198 ioaddr = dev->base_addr;
1199
1200 while (((status = inb(ioaddr + STATUS_REG)) & (RX_INT|TX_INT)) && (boguscount--))
1201 {
1202 handled = 1;
1203 if (status & RX_INT) {
1204 if (net_debug > 4)
1205 printk(KERN_DEBUG "%s: packet received interrupt.\n", dev->name);
1206
1207 eepro_dis_int(ioaddr);
1208
1209
1210 eepro_ack_rx(ioaddr);
1211 eepro_rx(dev);
1212
1213 eepro_en_int(ioaddr);
1214 }
1215 if (status & TX_INT) {
1216 if (net_debug > 4)
1217 printk(KERN_DEBUG "%s: packet transmit interrupt.\n", dev->name);
1218
1219
1220 eepro_dis_int(ioaddr);
1221
1222
1223 eepro_ack_tx(ioaddr);
1224 eepro_transmit_interrupt(dev);
1225
1226 eepro_en_int(ioaddr);
1227 }
1228 }
1229
1230 if (net_debug > 5)
1231 printk(KERN_DEBUG "%s: exiting eepro_interrupt routine.\n", dev->name);
1232
1233 spin_unlock(&lp->lock);
1234 return IRQ_RETVAL(handled);
1235}
1236
1237static int eepro_close(struct net_device *dev)
1238{
1239 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1240 int ioaddr = dev->base_addr;
1241 short temp_reg;
1242
1243 netif_stop_queue(dev);
1244
1245 eepro_sw2bank1(ioaddr);
1246
1247
1248 temp_reg = inb(ioaddr + REG1);
1249 outb(temp_reg & 0x7f, ioaddr + REG1);
1250
1251 eepro_sw2bank0(ioaddr);
1252
1253
1254 outb(STOP_RCV_CMD, ioaddr);
1255 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1256 lp->tx_last = 0;
1257
1258
1259 eepro_dis_int(ioaddr);
1260
1261
1262 eepro_clear_int(ioaddr);
1263
1264
1265 eepro_reset(ioaddr);
1266
1267
1268 free_irq(dev->irq, dev);
1269
1270#ifdef irq2dev_map
1271 irq2dev_map[dev->irq] = 0;
1272#endif
1273
1274
1275
1276 return 0;
1277}
1278
1279
1280
1281static struct net_device_stats *
1282eepro_get_stats(struct net_device *dev)
1283{
1284 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1285
1286 return &lp->stats;
1287}
1288
1289
1290
1291static void
1292set_multicast_list(struct net_device *dev)
1293{
1294 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1295 short ioaddr = dev->base_addr;
1296 unsigned short mode;
1297 struct dev_mc_list *dmi=dev->mc_list;
1298
1299 if (dev->flags&(IFF_ALLMULTI|IFF_PROMISC) || dev->mc_count > 63)
1300 {
1301
1302
1303
1304
1305
1306
1307 dev->flags|=IFF_PROMISC;
1308
1309 eepro_sw2bank2(ioaddr);
1310 mode = inb(ioaddr + REG2);
1311 outb(mode | PRMSC_Mode, ioaddr + REG2);
1312 mode = inb(ioaddr + REG3);
1313 outb(mode, ioaddr + REG3);
1314 eepro_sw2bank0(ioaddr);
1315 printk(KERN_INFO "%s: promiscuous mode enabled.\n", dev->name);
1316 }
1317
1318 else if (dev->mc_count==0 )
1319 {
1320 eepro_sw2bank2(ioaddr);
1321 mode = inb(ioaddr + REG2);
1322 outb(mode & 0xd6, ioaddr + REG2);
1323 mode = inb(ioaddr + REG3);
1324 outb(mode, ioaddr + REG3);
1325 eepro_sw2bank0(ioaddr);
1326 }
1327
1328 else
1329 {
1330 unsigned short status, *eaddrs;
1331 int i, boguscount = 0;
1332
1333
1334
1335
1336 eepro_dis_int(ioaddr);
1337
1338 eepro_sw2bank2(ioaddr);
1339 mode = inb(ioaddr + REG2);
1340 outb(mode | Multi_IA, ioaddr + REG2);
1341 mode = inb(ioaddr + REG3);
1342 outb(mode, ioaddr + REG3);
1343 eepro_sw2bank0(ioaddr);
1344 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
1345 outw(MC_SETUP, ioaddr + IO_PORT);
1346 outw(0, ioaddr + IO_PORT);
1347 outw(0, ioaddr + IO_PORT);
1348 outw(6*(dev->mc_count + 1), ioaddr + IO_PORT);
1349
1350 for (i = 0; i < dev->mc_count; i++)
1351 {
1352 eaddrs=(unsigned short *)dmi->dmi_addr;
1353 dmi=dmi->next;
1354 outw(*eaddrs++, ioaddr + IO_PORT);
1355 outw(*eaddrs++, ioaddr + IO_PORT);
1356 outw(*eaddrs++, ioaddr + IO_PORT);
1357 }
1358
1359 eaddrs = (unsigned short *) dev->dev_addr;
1360 outw(eaddrs[0], ioaddr + IO_PORT);
1361 outw(eaddrs[1], ioaddr + IO_PORT);
1362 outw(eaddrs[2], ioaddr + IO_PORT);
1363 outw(lp->tx_end, ioaddr + lp->xmt_bar);
1364 outb(MC_SETUP, ioaddr);
1365
1366
1367 i = lp->tx_end + XMT_HEADER + 6*(dev->mc_count + 1);
1368
1369 if (lp->tx_start != lp->tx_end)
1370 {
1371
1372
1373 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1374 outw(i, ioaddr + IO_PORT);
1375 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1376 status = inw(ioaddr + IO_PORT);
1377 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1378 lp->tx_end = i ;
1379 }
1380 else {
1381 lp->tx_start = lp->tx_end = i ;
1382 }
1383
1384
1385 do {
1386 SLOW_DOWN;
1387 SLOW_DOWN;
1388 if (inb(ioaddr + STATUS_REG) & 0x08)
1389 {
1390 i = inb(ioaddr);
1391 outb(0x08, ioaddr + STATUS_REG);
1392
1393 if (i & 0x20) {
1394 printk(KERN_NOTICE "%s: multicast setup failed.\n",
1395 dev->name);
1396 break;
1397 } else if ((i & 0x0f) == 0x03) {
1398 printk(KERN_DEBUG "%s: set Rx mode to %d address%s.\n",
1399 dev->name, dev->mc_count,
1400 dev->mc_count > 1 ? "es":"");
1401 break;
1402 }
1403 }
1404 } while (++boguscount < 100);
1405
1406
1407 eepro_en_int(ioaddr);
1408 }
1409 if (lp->eepro == LAN595FX_10ISA) {
1410 eepro_complete_selreset(ioaddr);
1411 }
1412 else
1413 eepro_en_rx(ioaddr);
1414}
1415
1416
1417
1418
1419
1420#define eeprom_delay() { udelay(40); }
1421#define EE_READ_CMD (6 << 6)
1422
1423int
1424read_eeprom(int ioaddr, int location, struct net_device *dev)
1425{
1426 int i;
1427 unsigned short retval = 0;
1428 struct eepro_local *lp = dev->priv;
1429 short ee_addr = ioaddr + lp->eeprom_reg;
1430 int read_cmd = location | EE_READ_CMD;
1431 short ctrl_val = EECS ;
1432
1433
1434 eepro_sw2bank1(ioaddr);
1435 outb(0x00, ioaddr + STATUS_REG);
1436
1437
1438 eepro_sw2bank2(ioaddr);
1439 outb(ctrl_val, ee_addr);
1440
1441
1442 for (i = 8; i >= 0; i--) {
1443 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
1444 : ctrl_val;
1445 outb(outval, ee_addr);
1446 outb(outval | EESK, ee_addr);
1447 eeprom_delay();
1448 outb(outval, ee_addr);
1449 eeprom_delay();
1450 }
1451 outb(ctrl_val, ee_addr);
1452
1453 for (i = 16; i > 0; i--) {
1454 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
1455 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
1456 outb(ctrl_val, ee_addr); eeprom_delay();
1457 }
1458
1459
1460 ctrl_val &= ~EECS;
1461 outb(ctrl_val | EESK, ee_addr);
1462 eeprom_delay();
1463 outb(ctrl_val, ee_addr);
1464 eeprom_delay();
1465 eepro_sw2bank0(ioaddr);
1466 return retval;
1467}
1468
1469static int
1470hardware_send_packet(struct net_device *dev, void *buf, short length)
1471{
1472 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1473 short ioaddr = dev->base_addr;
1474 unsigned status, tx_available, last, end;
1475
1476 if (net_debug > 5)
1477 printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);
1478
1479
1480 if (lp->tx_end > lp->tx_start)
1481 tx_available = lp->xmt_ram - (lp->tx_end - lp->tx_start);
1482 else if (lp->tx_end < lp->tx_start)
1483 tx_available = lp->tx_start - lp->tx_end;
1484 else tx_available = lp->xmt_ram;
1485
1486 if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) >= tx_available) {
1487
1488 return 1;
1489 }
1490
1491 last = lp->tx_end;
1492 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1493
1494 if (end >= lp->xmt_upper_limit + 2) {
1495 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
1496
1497
1498 last = lp->xmt_lower_limit;
1499 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1500 }
1501 else end = lp->xmt_lower_limit + (end -
1502 lp->xmt_upper_limit + 2);
1503 }
1504
1505 outw(last, ioaddr + HOST_ADDRESS_REG);
1506 outw(XMT_CMD, ioaddr + IO_PORT);
1507 outw(0, ioaddr + IO_PORT);
1508 outw(end, ioaddr + IO_PORT);
1509 outw(length, ioaddr + IO_PORT);
1510
1511 if (lp->version == LAN595)
1512 outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);
1513 else {
1514 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1515 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1516 outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);
1517 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1518 }
1519
1520
1521 status = inw(ioaddr + IO_PORT);
1522
1523 if (lp->tx_start == lp->tx_end) {
1524 outw(last, ioaddr + lp->xmt_bar);
1525 outb(XMT_CMD, ioaddr);
1526 lp->tx_start = last;
1527 }
1528 else {
1529
1530
1531
1532 if (lp->tx_end != last) {
1533 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
1534 outw(last, ioaddr + IO_PORT);
1535 }
1536
1537 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
1538 status = inw(ioaddr + IO_PORT);
1539 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
1540
1541
1542 outb(RESUME_XMT_CMD, ioaddr);
1543 }
1544
1545 lp->tx_last = last;
1546 lp->tx_end = end;
1547
1548 if (net_debug > 5)
1549 printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);
1550
1551 return 0;
1552}
1553
1554static void
1555eepro_rx(struct net_device *dev)
1556{
1557 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1558 short ioaddr = dev->base_addr;
1559 short boguscount = 20;
1560 short rcv_car = lp->rx_start;
1561 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1562
1563 if (net_debug > 5)
1564 printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);
1565
1566
1567 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1568
1569 rcv_event = inw(ioaddr + IO_PORT);
1570
1571 while (rcv_event == RCV_DONE) {
1572
1573 rcv_status = inw(ioaddr + IO_PORT);
1574 rcv_next_frame = inw(ioaddr + IO_PORT);
1575 rcv_size = inw(ioaddr + IO_PORT);
1576
1577 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1578
1579
1580 struct sk_buff *skb;
1581
1582 lp->stats.rx_bytes+=rcv_size;
1583 rcv_size &= 0x3fff;
1584 skb = dev_alloc_skb(rcv_size+5);
1585 if (skb == NULL) {
1586 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1587 lp->stats.rx_dropped++;
1588 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1589 lp->rx_start = rcv_next_frame;
1590 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1591
1592 break;
1593 }
1594 skb->dev = dev;
1595 skb_reserve(skb,2);
1596
1597 if (lp->version == LAN595)
1598 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);
1599 else {
1600 unsigned short temp = inb(ioaddr + INT_MASK_REG);
1601 outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);
1602 insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size),
1603 (rcv_size + 3) >> 2);
1604 outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);
1605 }
1606
1607 skb->protocol = eth_type_trans(skb,dev);
1608 netif_rx(skb);
1609 dev->last_rx = jiffies;
1610 lp->stats.rx_packets++;
1611 }
1612
1613 else {
1614
1615 lp->stats.rx_errors++;
1616
1617 if (rcv_status & 0x0100)
1618 lp->stats.rx_over_errors++;
1619
1620 else if (rcv_status & 0x0400)
1621 lp->stats.rx_frame_errors++;
1622
1623 else if (rcv_status & 0x0800)
1624 lp->stats.rx_crc_errors++;
1625
1626 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1627 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1628 }
1629
1630 if (rcv_status & 0x1000)
1631 lp->stats.rx_length_errors++;
1632
1633 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1634 lp->rx_start = rcv_next_frame;
1635
1636 if (--boguscount == 0)
1637 break;
1638
1639 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1640 rcv_event = inw(ioaddr + IO_PORT);
1641
1642 }
1643 if (rcv_car == 0)
1644 rcv_car = lp->rcv_upper_limit | 0xff;
1645
1646 outw(rcv_car - 1, ioaddr + RCV_STOP);
1647
1648 if (net_debug > 5)
1649 printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);
1650}
1651
1652static void
1653eepro_transmit_interrupt(struct net_device *dev)
1654{
1655 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1656 short ioaddr = dev->base_addr;
1657 short boguscount = 25;
1658 short xmt_status;
1659
1660 while ((lp->tx_start != lp->tx_end) && boguscount--) {
1661
1662 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1663 xmt_status = inw(ioaddr+IO_PORT);
1664
1665 if (!(xmt_status & TX_DONE_BIT))
1666 break;
1667
1668 xmt_status = inw(ioaddr+IO_PORT);
1669 lp->tx_start = inw(ioaddr+IO_PORT);
1670
1671 netif_wake_queue (dev);
1672
1673 if (xmt_status & TX_OK)
1674 lp->stats.tx_packets++;
1675 else {
1676 lp->stats.tx_errors++;
1677 if (xmt_status & 0x0400) {
1678 lp->stats.tx_carrier_errors++;
1679 printk(KERN_DEBUG "%s: carrier error\n",
1680 dev->name);
1681 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1682 dev->name, xmt_status);
1683 }
1684 else {
1685 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1686 dev->name, xmt_status);
1687 printk(KERN_DEBUG "%s: XMT status = %#x\n",
1688 dev->name, xmt_status);
1689 }
1690 }
1691 if (xmt_status & 0x000f) {
1692 lp->stats.collisions += (xmt_status & 0x000f);
1693 }
1694
1695 if ((xmt_status & 0x0040) == 0x0) {
1696 lp->stats.tx_heartbeat_errors++;
1697 }
1698 }
1699}
1700
1701#ifdef MODULE
1702
1703#define MAX_EEPRO 8
1704static struct net_device dev_eepro[MAX_EEPRO];
1705
1706static int io[MAX_EEPRO];
1707static int irq[MAX_EEPRO];
1708static int mem[MAX_EEPRO] = {
1709 [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024
1710};
1711static int autodetect;
1712
1713static int n_eepro;
1714
1715
1716MODULE_AUTHOR("Pascal Dupuis, and aris@cathedrallabs.org");
1717MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1718MODULE_LICENSE("GPL");
1719
1720MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1721MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1722MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");
1723MODULE_PARM(autodetect, "1-" __MODULE_STRING(1) "i");
1724MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1725MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
1726MODULE_PARM_DESC(mem, "EtherExpress Pro/10 Rx buffer size(es) in kB (3-29)");
1727MODULE_PARM_DESC(autodetect, "EtherExpress Pro/10 force board(s) detection (0-1)");
1728
1729int
1730init_module(void)
1731{
1732 int i;
1733 if (io[0] == 0 && autodetect == 0) {
1734 printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
1735 printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");
1736 return 1;
1737 }
1738 else if (autodetect) {
1739
1740 io[0] = 0;
1741
1742 printk(KERN_INFO "eepro_init_module: Auto-detecting boards (May God protect us...)\n");
1743 }
1744
1745 for (i = 0; i < MAX_EEPRO; i++) {
1746 struct net_device *d = &dev_eepro[n_eepro];
1747 d->mem_end = mem[i];
1748 d->base_addr = io[i];
1749 d->irq = irq[i];
1750 d->init = eepro_probe;
1751
1752 if (register_netdev(d) == 0)
1753 n_eepro++;
1754 else
1755 break;
1756 }
1757
1758 if (n_eepro)
1759 printk(KERN_INFO "%s", version);
1760
1761 return n_eepro ? 0 : -ENODEV;
1762}
1763
1764void
1765cleanup_module(void)
1766{
1767 int i;
1768
1769 for (i=0; i<n_eepro; i++) {
1770 struct net_device *d = &dev_eepro[i];
1771 unregister_netdev(d);
1772
1773 kfree(d->priv);
1774 d->priv=NULL;
1775
1776
1777 release_region(d->base_addr, EEPRO_IO_EXTENT);
1778
1779 }
1780}
1781#endif
1782