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