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