This source file includes following definitions.
- eepro_probe
- eepro_probe1
- eepro_grab_irq
- eepro_open
- eepro_send_packet
- eepro_interrupt
- eepro_close
- eepro_get_stats
- set_multicast_list
- read_eeprom
- hardware_send_packet
- eepro_rx
- eepro_transmit_interrupt
- init_module
- cleanup_module
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 static const char *version =
55 "eepro.c: v0.07a 6/5/95 Bao C. Ha (bao@saigon.async.com)\n";
56
57
58
59 #include <linux/config.h>
60
61 #ifdef MODULE
62 #include <linux/module.h>
63 #include <linux/version.h>
64 #endif
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 #include <linux/kernel.h>
88 #include <linux/sched.h>
89 #include <linux/types.h>
90 #include <linux/fcntl.h>
91 #include <linux/interrupt.h>
92 #include <linux/ptrace.h>
93 #include <linux/ioport.h>
94 #include <linux/in.h>
95 #include <linux/malloc.h>
96 #include <linux/string.h>
97 #include <asm/system.h>
98 #include <asm/bitops.h>
99 #include <asm/io.h>
100 #include <asm/dma.h>
101 #include <linux/errno.h>
102
103 #include <linux/netdevice.h>
104 #include <linux/etherdevice.h>
105 #include <linux/skbuff.h>
106
107
108
109
110 static unsigned int eepro_portlist[] =
111 { 0x200, 0x240, 0x280, 0x2C0, 0x300, 0x320, 0x340, 0x360, 0};
112
113
114 #ifndef NET_DEBUG
115 #define NET_DEBUG 2
116 #endif
117 static unsigned int net_debug = NET_DEBUG;
118
119
120 #define EEPRO_IO_EXTENT 16
121
122
123 struct eepro_local {
124 struct enet_statistics stats;
125 unsigned rx_start;
126 unsigned tx_start;
127 int tx_last;
128 unsigned tx_end;
129 int eepro;
130
131 };
132
133
134 #define SA_ADDR0 0x00
135 #define SA_ADDR1 0xaa
136 #define SA_ADDR2 0x00
137
138
139
140 extern int eepro_probe(struct device *dev);
141
142 static int eepro_probe1(struct device *dev, short ioaddr);
143 static int eepro_open(struct device *dev);
144 static int eepro_send_packet(struct sk_buff *skb, struct device *dev);
145 static void eepro_interrupt(int irq, struct pt_regs *regs);
146 static void eepro_rx(struct device *dev);
147 static void eepro_transmit_interrupt(struct device *dev);
148 static int eepro_close(struct device *dev);
149 static struct enet_statistics *eepro_get_stats(struct device *dev);
150 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
151
152 static int read_eeprom(int ioaddr, int location);
153 static void hardware_send_packet(struct device *dev, void *buf, short length);
154 static int eepro_grab_irq(struct device *dev);
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 #define RAM_SIZE 0x8000
179 #define RCV_HEADER 8
180 #define RCV_RAM 0x6000
181 #define RCV_LOWER_LIMIT 0x00
182 #define RCV_UPPER_LIMIT ((RCV_RAM - 2) >> 8)
183 #define XMT_RAM (RAM_SIZE - RCV_RAM)
184 #define XMT_LOWER_LIMIT (RCV_RAM >> 8)
185 #define XMT_UPPER_LIMIT ((RAM_SIZE - 2) >> 8)
186 #define XMT_HEADER 8
187
188 #define RCV_DONE 0x0008
189 #define RX_OK 0x2000
190 #define RX_ERROR 0x0d81
191
192 #define TX_DONE_BIT 0x0080
193 #define CHAIN_BIT 0x8000
194 #define XMT_STATUS 0x02
195 #define XMT_CHAIN 0x04
196 #define XMT_COUNT 0x06
197
198 #define BANK0_SELECT 0x00
199 #define BANK1_SELECT 0x40
200 #define BANK2_SELECT 0x80
201
202
203 #define COMMAND_REG 0x00
204 #define MC_SETUP 0x03
205 #define XMT_CMD 0x04
206 #define DIAGNOSE_CMD 0x07
207 #define RCV_ENABLE_CMD 0x08
208 #define RCV_DISABLE_CMD 0x0a
209 #define STOP_RCV_CMD 0x0b
210 #define RESET_CMD 0x0e
211 #define POWER_DOWN_CMD 0x18
212 #define RESUME_XMT_CMD 0x1c
213 #define SEL_RESET_CMD 0x1e
214 #define STATUS_REG 0x01
215 #define RX_INT 0x02
216 #define TX_INT 0x04
217 #define EXEC_STATUS 0x30
218 #define ID_REG 0x02
219 #define R_ROBIN_BITS 0xc0
220 #define ID_REG_MASK 0x2c
221 #define ID_REG_SIG 0x24
222 #define AUTO_ENABLE 0x10
223 #define INT_MASK_REG 0x03
224 #define RX_STOP_MASK 0x01
225 #define RX_MASK 0x02
226 #define TX_MASK 0x04
227 #define EXEC_MASK 0x08
228 #define ALL_MASK 0x0f
229 #define RCV_BAR 0x04
230 #define RCV_STOP 0x06
231 #define XMT_BAR 0x0a
232 #define HOST_ADDRESS_REG 0x0c
233 #define IO_PORT 0x0e
234
235
236 #define REG1 0x01
237 #define WORD_WIDTH 0x02
238 #define INT_ENABLE 0x80
239 #define INT_NO_REG 0x02
240 #define RCV_LOWER_LIMIT_REG 0x08
241 #define RCV_UPPER_LIMIT_REG 0x09
242 #define XMT_LOWER_LIMIT_REG 0x0a
243 #define XMT_UPPER_LIMIT_REG 0x0b
244
245
246 #define XMT_Chain_Int 0x20
247 #define XMT_Chain_ErrStop 0x40
248 #define RCV_Discard_BadFrame 0x80
249 #define REG2 0x02
250 #define PRMSC_Mode 0x01
251 #define Multi_IA 0x20
252 #define REG3 0x03
253 #define TPE_BIT 0x04
254 #define BNC_BIT 0x20
255
256 #define I_ADD_REG0 0x04
257 #define I_ADD_REG1 0x05
258 #define I_ADD_REG2 0x06
259 #define I_ADD_REG3 0x07
260 #define I_ADD_REG4 0x08
261 #define I_ADD_REG5 0x09
262
263 #define EEPROM_REG 0x0a
264 #define EESK 0x01
265 #define EECS 0x02
266 #define EEDI 0x04
267 #define EEDO 0x08
268
269
270
271
272
273
274
275
276 #ifdef HAVE_DEVLIST
277
278
279 struct netdev_entry netcard_drv =
280 {"eepro", eepro_probe1, EEPRO_IO_EXTENT, eepro_portlist};
281 #else
282 int
283 eepro_probe(struct device *dev)
284 {
285 int i;
286 int base_addr = dev ? dev->base_addr : 0;
287
288 if (base_addr > 0x1ff)
289 return eepro_probe1(dev, base_addr);
290 else if (base_addr != 0)
291 return ENXIO;
292
293 for (i = 0; eepro_portlist[i]; i++) {
294 int ioaddr = eepro_portlist[i];
295 if (check_region(ioaddr, EEPRO_IO_EXTENT))
296 continue;
297 if (eepro_probe1(dev, ioaddr) == 0)
298 return 0;
299 }
300
301 return ENODEV;
302 }
303 #endif
304
305
306
307
308
309 int eepro_probe1(struct device *dev, short ioaddr)
310 {
311 unsigned short station_addr[6], id, counter;
312 int i;
313 int eepro;
314
315 const char *ifmap[] = {"AUI", "10Base2", "10BaseT"};
316 enum iftype { AUI=0, BNC=1, TPE=2 };
317
318
319
320
321 if (((id=inb(ioaddr + ID_REG)) & ID_REG_MASK) == ID_REG_SIG) {
322
323
324
325
326
327 counter = (id & R_ROBIN_BITS);
328 if (((id=inb(ioaddr+ID_REG)) & R_ROBIN_BITS) ==
329 (counter + 0x40)) {
330
331
332
333
334
335
336 station_addr[0] = read_eeprom(ioaddr, 2);
337 station_addr[1] = read_eeprom(ioaddr, 3);
338 station_addr[2] = read_eeprom(ioaddr, 4);
339
340
341
342 if (station_addr[2] != 0x00aa || (station_addr[1] & 0xff00) != 0x0000) {
343 eepro = 0;
344 printk("%s: Intel 82595-based lan card at %#x,",
345 dev->name, ioaddr);
346 }
347 else {
348 eepro = 1;
349 printk("%s: Intel EtherExpress Pro/10 at %#x,",
350 dev->name, ioaddr);
351 }
352
353
354 dev->base_addr = ioaddr;
355
356 for (i=0; i < 6; i++) {
357 dev->dev_addr[i] = ((unsigned char *) station_addr)[5-i];
358 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
359 }
360
361 outb(BANK2_SELECT, ioaddr);
362 id = inb(ioaddr + REG3);
363 if (id & TPE_BIT)
364 dev->if_port = TPE;
365 else dev->if_port = BNC;
366
367 if (dev->irq < 2 && eepro) {
368 i = read_eeprom(ioaddr, 1);
369 switch (i & 0x07) {
370 case 0: dev->irq = 9; break;
371 case 1: dev->irq = 3; break;
372 case 2: dev->irq = 5; break;
373 case 3: dev->irq = 10; break;
374 case 4: dev->irq = 11; break;
375 default:
376 printk(" illegal interrupt vector stored in EEPROM.\n");
377 return ENODEV;
378 }
379 }
380 else if (dev->irq == 2)
381 dev->irq = 9;
382
383 if (dev->irq > 2) {
384 printk(", IRQ %d, %s.\n", dev->irq,
385 ifmap[dev->if_port]);
386 if (request_irq(dev->irq, &eepro_interrupt, 0, "eepro")) {
387 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
388 return -EAGAIN;
389 }
390 }
391 else printk(", %s.\n", ifmap[dev->if_port]);
392
393 if ((dev->mem_start & 0xf) > 0)
394 net_debug = dev->mem_start & 7;
395
396 if (net_debug > 3) {
397 i = read_eeprom(ioaddr, 5);
398 if (i & 0x2000)
399 printk("%s: Concurrent Processing is enabled but not used!\n",
400 dev->name);
401 }
402
403 if (net_debug)
404 printk(version);
405
406
407 request_region(ioaddr, EEPRO_IO_EXTENT, "eepro");
408
409
410 dev->priv = kmalloc(sizeof(struct eepro_local), GFP_KERNEL);
411 if (dev->priv == NULL)
412 return -ENOMEM;
413 memset(dev->priv, 0, sizeof(struct eepro_local));
414
415 dev->open = eepro_open;
416 dev->stop = eepro_close;
417 dev->hard_start_xmit = eepro_send_packet;
418 dev->get_stats = eepro_get_stats;
419 dev->set_multicast_list = &set_multicast_list;
420
421
422
423
424 ether_setup(dev);
425
426 outb(RESET_CMD, ioaddr);
427
428 return 0;
429 }
430 else return ENODEV;
431 }
432 else if (net_debug > 3)
433 printk ("EtherExpress Pro probed failed!\n");
434 return ENODEV;
435 }
436
437
438
439
440
441
442
443
444
445 static char irqrmap[] = {-1,-1,0,1,-1,2,-1,-1,-1,0,3,4,-1,-1,-1,-1};
446 static int eepro_grab_irq(struct device *dev)
447 {
448 int irqlist[] = { 5, 9, 10, 11, 4, 3, 0};
449 int *irqp = irqlist, temp_reg, ioaddr = dev->base_addr;
450
451 outb(BANK1_SELECT, ioaddr);
452
453
454 temp_reg = inb(ioaddr + REG1);
455 outb(temp_reg | INT_ENABLE, ioaddr + REG1);
456
457 outb(BANK0_SELECT, ioaddr);
458
459
460 outb(ALL_MASK, ioaddr + STATUS_REG);
461
462 outb(ALL_MASK & ~(EXEC_MASK), ioaddr + INT_MASK_REG);
463
464 do {
465 outb(BANK1_SELECT, ioaddr);
466
467 temp_reg = inb(ioaddr + INT_NO_REG);
468 outb((temp_reg & 0xf8) | irqrmap[*irqp], ioaddr + INT_NO_REG);
469
470 outb(BANK0_SELECT, ioaddr);
471
472 if (request_irq (*irqp, NULL, 0, "bogus") != EBUSY) {
473
474 autoirq_setup(0);
475
476 outb(DIAGNOSE_CMD, ioaddr);
477
478 if (*irqp == autoirq_report(2) &&
479 (request_irq(dev->irq = *irqp, &eepro_interrupt, 0, "eepro") == 0))
480 break;
481
482
483 outb(ALL_MASK, ioaddr + STATUS_REG);
484 }
485 } while (*++irqp);
486
487 outb(BANK1_SELECT, ioaddr);
488
489
490 temp_reg = inb(ioaddr + REG1);
491 outb(temp_reg & 0x7f, ioaddr + REG1);
492
493 outb(BANK0_SELECT, ioaddr);
494
495
496 outb(ALL_MASK, ioaddr + INT_MASK_REG);
497
498
499 outb(ALL_MASK, ioaddr + STATUS_REG);
500
501 return dev->irq;
502 }
503
504 static int
505 eepro_open(struct device *dev)
506 {
507 unsigned short temp_reg;
508 int i, ioaddr = dev->base_addr;
509 struct eepro_local *lp = (struct eepro_local *)dev->priv;
510
511 if (net_debug > 3)
512 printk("eepro: entering eepro_open routine.\n");
513
514 if (dev->dev_addr[0] == SA_ADDR0 &&
515 dev->dev_addr[1] == SA_ADDR1 &&
516 dev->dev_addr[2] == SA_ADDR2)
517 lp->eepro = 1;
518 else lp->eepro = 0;
519
520
521 if (dev->irq < 2 && eepro_grab_irq(dev) == 0) {
522 printk("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
523 return -EAGAIN;
524 }
525
526 if (irq2dev_map[dev->irq] != 0
527 || (irq2dev_map[dev->irq] = dev) == 0)
528 return -EAGAIN;
529
530
531
532 outb(BANK2_SELECT, ioaddr);
533 temp_reg = inb(ioaddr + EEPROM_REG);
534 if (temp_reg & 0x10)
535 outb(temp_reg & 0xef, ioaddr + EEPROM_REG);
536 for (i=0; i < 6; i++)
537 outb(dev->dev_addr[i] , ioaddr + I_ADD_REG0 + i);
538
539 temp_reg = inb(ioaddr + REG1);
540 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop
541 | RCV_Discard_BadFrame, ioaddr + REG1);
542
543 temp_reg = inb(ioaddr + REG2);
544 outb(temp_reg | 0x14, ioaddr + REG2);
545
546 temp_reg = inb(ioaddr + REG3);
547 outb(temp_reg & 0x3f, ioaddr + REG3);
548
549
550 outb(BANK1_SELECT, ioaddr);
551
552 temp_reg = inb(ioaddr + INT_NO_REG);
553 outb((temp_reg & 0xf8) | irqrmap[dev->irq], ioaddr + INT_NO_REG);
554
555
556 outb(RCV_LOWER_LIMIT, ioaddr + RCV_LOWER_LIMIT_REG);
557 outb(RCV_UPPER_LIMIT, ioaddr + RCV_UPPER_LIMIT_REG);
558 outb(XMT_LOWER_LIMIT, ioaddr + XMT_LOWER_LIMIT_REG);
559 outb(XMT_UPPER_LIMIT, ioaddr + XMT_UPPER_LIMIT_REG);
560
561
562 temp_reg = inb(ioaddr + REG1);
563 outb(temp_reg | INT_ENABLE, ioaddr + REG1);
564
565 outb(BANK0_SELECT, ioaddr);
566
567
568 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
569
570 outb(ALL_MASK, ioaddr + STATUS_REG);
571
572
573 outw(RCV_LOWER_LIMIT << 8, ioaddr + RCV_BAR);
574 lp->rx_start = (RCV_LOWER_LIMIT << 8) ;
575 outw((RCV_UPPER_LIMIT << 8) | 0xfe, ioaddr + RCV_STOP);
576
577
578 outw(XMT_LOWER_LIMIT << 8, ioaddr + XMT_BAR);
579
580 outb(SEL_RESET_CMD, ioaddr);
581
582 SLOW_DOWN_IO;
583 SLOW_DOWN_IO;
584
585 lp->tx_start = lp->tx_end = XMT_LOWER_LIMIT << 8;
586 lp->tx_last = 0;
587
588 dev->tbusy = 0;
589 dev->interrupt = 0;
590 dev->start = 1;
591
592 if (net_debug > 3)
593 printk("eepro: exiting eepro_open routine.\n");
594
595 outb(RCV_ENABLE_CMD, ioaddr);
596
597 #ifdef MODULE
598 MOD_INC_USE_COUNT;
599 #endif
600 return 0;
601 }
602
603 static int
604 eepro_send_packet(struct sk_buff *skb, struct device *dev)
605 {
606 struct eepro_local *lp = (struct eepro_local *)dev->priv;
607 int ioaddr = dev->base_addr;
608
609 if (net_debug > 5)
610 printk("eepro: entering eepro_send_packet routine.\n");
611
612 if (dev->tbusy) {
613
614
615 int tickssofar = jiffies - dev->trans_start;
616 if (tickssofar < 5)
617 return 1;
618 if (net_debug > 1)
619 printk("%s: transmit timed out, %s?\n", dev->name,
620 "network cable problem");
621 lp->stats.tx_errors++;
622
623 outb(SEL_RESET_CMD, ioaddr);
624
625 SLOW_DOWN_IO;
626 SLOW_DOWN_IO;
627
628
629 lp->tx_start = lp->tx_end = RCV_RAM;
630 lp->tx_last = 0;
631
632 dev->tbusy=0;
633 dev->trans_start = jiffies;
634
635 outb(RCV_ENABLE_CMD, ioaddr);
636
637 }
638
639
640
641
642 if (skb == NULL) {
643 dev_tint(dev);
644 return 0;
645 }
646
647
648 if (set_bit(0, (void*)&dev->tbusy) != 0)
649 printk("%s: Transmitter access conflict.\n", dev->name);
650 else {
651 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
652 unsigned char *buf = skb->data;
653
654 hardware_send_packet(dev, buf, length);
655 dev->trans_start = jiffies;
656 }
657
658 dev_kfree_skb (skb, FREE_WRITE);
659
660
661
662
663 if (net_debug > 5)
664 printk("eepro: exiting eepro_send_packet routine.\n");
665
666 return 0;
667 }
668
669
670
671
672 static void
673 eepro_interrupt(int irq, struct pt_regs * regs)
674 {
675 struct device *dev = (struct device *)(irq2dev_map[irq]);
676 int ioaddr, status, boguscount = 0;
677
678 if (net_debug > 5)
679 printk("eepro: entering eepro_interrupt routine.\n");
680
681 if (dev == NULL) {
682 printk ("eepro_interrupt(): irq %d for unknown device.\n", irq);
683 return;
684 }
685 dev->interrupt = 1;
686
687 ioaddr = dev->base_addr;
688
689 do {
690 status = inb(ioaddr + STATUS_REG);
691
692 if (status & RX_INT) {
693 if (net_debug > 4)
694 printk("eepro: packet received interrupt.\n");
695
696
697 outb(RX_INT, ioaddr + STATUS_REG);
698
699
700 eepro_rx(dev);
701 }
702 else if (status & TX_INT) {
703 if (net_debug > 4)
704 printk("eepro: packet transmit interrupt.\n");
705
706
707 outb(TX_INT, ioaddr + STATUS_REG);
708
709
710 eepro_transmit_interrupt(dev);
711 dev->tbusy = 0;
712 mark_bh(NET_BH);
713 }
714 } while ((++boguscount < 10) && (status & 0x06));
715
716 dev->interrupt = 0;
717 if (net_debug > 5)
718 printk("eepro: exiting eepro_interrupt routine.\n");
719
720 return;
721 }
722
723 static int
724 eepro_close(struct device *dev)
725 {
726 struct eepro_local *lp = (struct eepro_local *)dev->priv;
727 int ioaddr = dev->base_addr;
728 short temp_reg;
729
730 dev->tbusy = 1;
731 dev->start = 0;
732
733 outb(BANK1_SELECT, ioaddr);
734
735
736 temp_reg = inb(ioaddr + REG1);
737 outb(temp_reg & 0x7f, ioaddr + REG1);
738
739 outb(BANK0_SELECT, ioaddr);
740
741
742 outb(STOP_RCV_CMD, ioaddr);
743 lp->tx_start = lp->tx_end = RCV_RAM ;
744 lp->tx_last = 0;
745
746
747 outb(ALL_MASK, ioaddr + INT_MASK_REG);
748
749
750 outb(ALL_MASK, ioaddr + STATUS_REG);
751
752
753 outb(RESET_CMD, ioaddr);
754
755
756 free_irq(dev->irq);
757
758 irq2dev_map[dev->irq] = 0;
759
760
761
762
763 SLOW_DOWN_IO;
764 SLOW_DOWN_IO;
765
766 #ifdef MODULE
767 MOD_DEC_USE_COUNT;
768 #endif
769 return 0;
770 }
771
772
773
774 static struct enet_statistics *
775 eepro_get_stats(struct device *dev)
776 {
777 struct eepro_local *lp = (struct eepro_local *)dev->priv;
778
779 return &lp->stats;
780 }
781
782
783
784
785
786
787
788 static void
789 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
790 {
791 struct eepro_local *lp = (struct eepro_local *)dev->priv;
792 short ioaddr = dev->base_addr;
793 unsigned short mode;
794
795 if (num_addrs < -1 || num_addrs > 63) {
796 outb(BANK2_SELECT, ioaddr);
797 mode = inb(ioaddr + REG2);
798 outb(mode | PRMSC_Mode, ioaddr + REG2);
799 mode = inb(ioaddr + REG3);
800 outb(mode, ioaddr + REG3);
801 outb(BANK0_SELECT, ioaddr);
802 printk("%s: promiscuous mode enabled.\n", dev->name);
803 }
804 else if (num_addrs == 0) {
805 outb(BANK2_SELECT, ioaddr);
806 mode = inb(ioaddr + REG2);
807 outb(mode & 0xd6, ioaddr + REG2);
808 mode = inb(ioaddr + REG3);
809 outb(mode, ioaddr + REG3);
810 outb(BANK0_SELECT, ioaddr);
811 }
812 else {
813 unsigned short status, *eaddrs = addrs;
814 int i, boguscount = 0;
815
816
817
818
819 outb(ALL_MASK, ioaddr + INT_MASK_REG);
820
821 outb(BANK2_SELECT, ioaddr);
822 mode = inb(ioaddr + REG2);
823 outb(mode | Multi_IA, ioaddr + REG2);
824 mode = inb(ioaddr + REG3);
825 outb(mode, ioaddr + REG3);
826 outb(BANK0_SELECT, ioaddr);
827 outw(lp->tx_end, ioaddr + HOST_ADDRESS_REG);
828 outw(MC_SETUP, ioaddr + IO_PORT);
829 outw(0, ioaddr + IO_PORT);
830 outw(0, ioaddr + IO_PORT);
831 outw(6*(num_addrs + 1), ioaddr + IO_PORT);
832 for (i = 0; i < num_addrs; i++) {
833 outw(*eaddrs++, ioaddr + IO_PORT);
834 outw(*eaddrs++, ioaddr + IO_PORT);
835 outw(*eaddrs++, ioaddr + IO_PORT);
836 }
837 eaddrs = (unsigned short *) dev->dev_addr;
838 outw(eaddrs[0], ioaddr + IO_PORT);
839 outw(eaddrs[1], ioaddr + IO_PORT);
840 outw(eaddrs[2], ioaddr + IO_PORT);
841 outw(lp->tx_end, ioaddr + XMT_BAR);
842 outb(MC_SETUP, ioaddr);
843
844
845 i = lp->tx_end + XMT_HEADER + 6*(num_addrs + 1);
846 if (lp->tx_start != lp->tx_end) {
847
848
849 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
850 outw(i, ioaddr + IO_PORT);
851 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
852 status = inw(ioaddr + IO_PORT);
853 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
854 lp->tx_end = i ;
855 } else lp->tx_start = lp->tx_end = i ;
856
857
858 do {
859 SLOW_DOWN_IO;
860 SLOW_DOWN_IO;
861 if (inb(ioaddr + STATUS_REG) & 0x08) {
862 i = inb(ioaddr);
863 outb(0x08, ioaddr + STATUS_REG);
864 if (i & 0x20) {
865 printk("%s: multicast setup failed.\n",
866 dev->name);
867 break;
868 } else if ((i & 0x0f) == 0x03) {
869 printk("%s: set Rx mode to %d addresses.\n",
870 dev->name, num_addrs);
871 break;
872 }
873 }
874 } while (++boguscount < 100);
875
876
877 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
878
879 }
880 outb(RCV_ENABLE_CMD, ioaddr);
881 }
882
883
884
885
886
887 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
888 #define EE_READ_CMD (6 << 6)
889
890 int
891 read_eeprom(int ioaddr, int location)
892 {
893 int i;
894 unsigned short retval = 0;
895 short ee_addr = ioaddr + EEPROM_REG;
896 int read_cmd = location | EE_READ_CMD;
897 short ctrl_val = EECS ;
898
899 outb(BANK2_SELECT, ioaddr);
900 outb(ctrl_val, ee_addr);
901
902
903 for (i = 8; i >= 0; i--) {
904 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI
905 : ctrl_val;
906 outb(outval, ee_addr);
907 outb(outval | EESK, ee_addr);
908 eeprom_delay();
909 outb(outval, ee_addr);
910 eeprom_delay();
911 }
912 outb(ctrl_val, ee_addr);
913
914 for (i = 16; i > 0; i--) {
915 outb(ctrl_val | EESK, ee_addr); eeprom_delay();
916 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
917 outb(ctrl_val, ee_addr); eeprom_delay();
918 }
919
920
921 ctrl_val &= ~EECS;
922 outb(ctrl_val | EESK, ee_addr);
923 eeprom_delay();
924 outb(ctrl_val, ee_addr);
925 eeprom_delay();
926 outb(BANK0_SELECT, ioaddr);
927 return retval;
928 }
929
930 static void
931 hardware_send_packet(struct device *dev, void *buf, short length)
932 {
933 struct eepro_local *lp = (struct eepro_local *)dev->priv;
934 short ioaddr = dev->base_addr;
935 unsigned status, tx_available, last, end, boguscount = 10;
936
937 if (net_debug > 5)
938 printk("eepro: entering hardware_send_packet routine.\n");
939
940 while (boguscount-- > 0) {
941
942
943 if (lp->tx_end > lp->tx_start)
944 tx_available = XMT_RAM - (lp->tx_end - lp->tx_start);
945 else if (lp->tx_end < lp->tx_start)
946 tx_available = lp->tx_start - lp->tx_end;
947 else tx_available = XMT_RAM;
948
949
950
951
952 outb(ALL_MASK, ioaddr + INT_MASK_REG);
953
954 if (((((length + 1) >> 1) << 1) + 2*XMT_HEADER)
955 >= tx_available)
956 continue;
957
958 last = lp->tx_end;
959 end = last + (((length + 1) >> 1) << 1) + XMT_HEADER;
960
961 if (end >= RAM_SIZE) {
962 if ((RAM_SIZE - last) <= XMT_HEADER) {
963
964
965 last = RCV_RAM;
966 end = last + (((length + 1) >> 1) << 1) + XMT_HEADER;
967 }
968 else end = RCV_RAM + (end - RAM_SIZE);
969 }
970
971 outw(last, ioaddr + HOST_ADDRESS_REG);
972 outw(XMT_CMD, ioaddr + IO_PORT);
973 outw(0, ioaddr + IO_PORT);
974 outw(end, ioaddr + IO_PORT);
975 outw(length, ioaddr + IO_PORT);
976 outsw(ioaddr + IO_PORT, buf, (length + 1) >> 1);
977
978 if (lp->tx_start != lp->tx_end) {
979
980
981 if (lp->tx_end != last) {
982 outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);
983 outw(last, ioaddr + IO_PORT);
984 }
985 outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);
986 status = inw(ioaddr + IO_PORT);
987 outw(status | CHAIN_BIT, ioaddr + IO_PORT);
988 }
989
990
991 status = inw(ioaddr + IO_PORT);
992
993
994 outb(ALL_MASK & ~(RX_MASK | TX_MASK), ioaddr + INT_MASK_REG);
995
996 if (lp->tx_start == lp->tx_end) {
997 outw(last, ioaddr + XMT_BAR);
998 outb(XMT_CMD, ioaddr);
999 lp->tx_start = last;
1000 }
1001 else outb(RESUME_XMT_CMD, ioaddr);
1002
1003 lp->tx_last = last;
1004 lp->tx_end = end;
1005
1006 if (dev->tbusy) {
1007 dev->tbusy = 0;
1008 mark_bh(NET_BH);
1009 }
1010
1011 if (net_debug > 5)
1012 printk("eepro: exiting hardware_send_packet routine.\n");
1013 return;
1014 }
1015 dev->tbusy = 1;
1016 if (net_debug > 5)
1017 printk("eepro: exiting hardware_send_packet routine.\n");
1018 }
1019
1020 static void
1021 eepro_rx(struct device *dev)
1022 {
1023 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1024 short ioaddr = dev->base_addr;
1025 short boguscount = 20;
1026 short rcv_car = lp->rx_start;
1027 unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;
1028
1029 if (net_debug > 5)
1030 printk("eepro: entering eepro_rx routine.\n");
1031
1032
1033 outw(rcv_car, ioaddr + HOST_ADDRESS_REG);
1034 rcv_event = inw(ioaddr + IO_PORT);
1035
1036 while (rcv_event == RCV_DONE) {
1037 rcv_status = inw(ioaddr + IO_PORT);
1038 rcv_next_frame = inw(ioaddr + IO_PORT);
1039 rcv_size = inw(ioaddr + IO_PORT);
1040
1041 if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {
1042
1043 struct sk_buff *skb;
1044
1045 rcv_size &= 0x3fff;
1046 skb = dev_alloc_skb(rcv_size+2);
1047 if (skb == NULL) {
1048 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
1049 lp->stats.rx_dropped++;
1050 break;
1051 }
1052 skb->dev = dev;
1053 skb_reserve(skb,2);
1054
1055 insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 1) >> 1);
1056
1057 skb->protocol = eth_type_trans(skb,dev);
1058 netif_rx(skb);
1059 lp->stats.rx_packets++;
1060 }
1061 else {
1062
1063 lp->stats.rx_errors++;
1064 if (rcv_status & 0x0100)
1065 lp->stats.rx_over_errors++;
1066 else if (rcv_status & 0x0400)
1067 lp->stats.rx_frame_errors++;
1068 else if (rcv_status & 0x0800)
1069 lp->stats.rx_crc_errors++;
1070 printk("%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1071 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1072 }
1073 if (rcv_status & 0x1000)
1074 lp->stats.rx_length_errors++;
1075 if (--boguscount == 0)
1076 break;
1077
1078 rcv_car = lp->rx_start + RCV_HEADER + rcv_size;
1079 lp->rx_start = rcv_next_frame;
1080 outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);
1081 rcv_event = inw(ioaddr + IO_PORT);
1082
1083 }
1084 if (rcv_car == 0)
1085 rcv_car = (RCV_UPPER_LIMIT << 8) | 0xff;
1086 outw(rcv_car - 1, ioaddr + RCV_STOP);
1087
1088 if (net_debug > 5)
1089 printk("eepro: exiting eepro_rx routine.\n");
1090 }
1091
1092 static void
1093 eepro_transmit_interrupt(struct device *dev)
1094 {
1095 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1096 short ioaddr = dev->base_addr;
1097 short boguscount = 10;
1098 short xmt_status;
1099
1100 while (lp->tx_start != lp->tx_end) {
1101
1102 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1103 xmt_status = inw(ioaddr+IO_PORT);
1104 if ((xmt_status & TX_DONE_BIT) == 0) break;
1105 xmt_status = inw(ioaddr+IO_PORT);
1106 lp->tx_start = inw(ioaddr+IO_PORT);
1107
1108 if (dev->tbusy) {
1109 dev->tbusy = 0;
1110 mark_bh(NET_BH);
1111 }
1112
1113 if (xmt_status & 0x2000)
1114 lp->stats.tx_packets++;
1115 else {
1116 lp->stats.tx_errors++;
1117 if (xmt_status & 0x0400)
1118 lp->stats.tx_carrier_errors++;
1119 printk("%s: XMT status = %#x\n",
1120 dev->name, xmt_status);
1121 }
1122 if (xmt_status & 0x000f)
1123 lp->stats.collisions += (xmt_status & 0x000f);
1124 if ((xmt_status & 0x0040) == 0x0)
1125 lp->stats.tx_heartbeat_errors++;
1126
1127 if (--boguscount == 0)
1128 break;
1129 }
1130 }
1131
1132 #ifdef MODULE
1133 char kernel_version[] = UTS_RELEASE;
1134 static char devicename[9] = { 0, };
1135 static struct device dev_eepro = {
1136 devicename,
1137 0, 0, 0, 0,
1138 0, 0,
1139 0, 0, 0, NULL, eepro_probe };
1140
1141 int io = 0x200;
1142 int irq = 0;
1143
1144 int
1145 init_module(void)
1146 {
1147 if (io == 0)
1148 printk("eepro: You should not use auto-probing with insmod!\n");
1149 dev_eepro.base_addr = io;
1150 dev_eepro.irq = irq;
1151
1152 if (register_netdev(&dev_eepro) != 0)
1153 return -EIO;
1154 return 0;
1155 }
1156
1157 void
1158 cleanup_module(void)
1159 {
1160 if (MOD_IN_USE)
1161 printk("eepro: device busy, remove delayed\n");
1162 else
1163 {
1164 unregister_netdev(&dev_eepro);
1165 kfree_s(dev_eepro.priv,sizeof(struct eepro_local));
1166 dev_eepro.priv=NULL;
1167
1168
1169 release_region(dev_eepro.base_addr, EEPRO_IO_EXTENT);
1170 }
1171 }
1172 #endif