This source file includes following definitions.
- lance_init
- lance_probe1
- lance_open
- lance_purge_tx_ring
- lance_init_ring
- lance_restart
- lance_start_xmit
- lance_interrupt
- lance_rx
- lance_close
- lance_get_stats
- set_multicast_list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 static const char *version = "lance.c:v1.08 4/10/95 dplatt@3do.com\n";
19
20 #include <linux/config.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/string.h>
24 #include <linux/ptrace.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/malloc.h>
28 #include <linux/interrupt.h>
29 #include <linux/pci.h>
30 #include <linux/bios32.h>
31 #include <asm/bitops.h>
32 #include <asm/io.h>
33 #include <asm/dma.h>
34
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/skbuff.h>
38
39 static unsigned int lance_portlist[] = {0x300, 0x320, 0x340, 0x360, 0};
40 void lance_probe1(int ioaddr);
41
42 #ifdef HAVE_DEVLIST
43 struct netdev_entry lance_drv =
44 {"lance", lance_probe1, LANCE_TOTAL_SIZE, lance_portlist};
45 #endif
46
47 #ifdef LANCE_DEBUG
48 int lance_debug = LANCE_DEBUG;
49 #else
50 int lance_debug = 1;
51 #endif
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 #ifndef LANCE_LOG_TX_BUFFERS
144 #define LANCE_LOG_TX_BUFFERS 4
145 #define LANCE_LOG_RX_BUFFERS 4
146 #endif
147
148 #define TX_RING_SIZE (1 << (LANCE_LOG_TX_BUFFERS))
149 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
150 #define TX_RING_LEN_BITS ((LANCE_LOG_TX_BUFFERS) << 29)
151
152 #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
153 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
154 #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
155
156 #define PKT_BUF_SZ 1544
157
158
159 #define LANCE_DATA 0x10
160 #define LANCE_ADDR 0x12
161 #define LANCE_RESET 0x14
162 #define LANCE_BUS_IF 0x16
163 #define LANCE_TOTAL_SIZE 0x18
164
165
166 struct lance_rx_head {
167 int base;
168 short buf_length;
169 short msg_length;
170 };
171
172 struct lance_tx_head {
173 int base;
174 short length;
175 short misc;
176 };
177
178
179 struct lance_init_block {
180 unsigned short mode;
181 unsigned char phys_addr[6];
182 unsigned filter[2];
183
184 unsigned rx_ring;
185 unsigned tx_ring;
186 };
187
188 struct lance_private {
189
190
191 struct lance_rx_head rx_ring[RX_RING_SIZE];
192 struct lance_tx_head tx_ring[TX_RING_SIZE];
193 struct lance_init_block init_block;
194 const char *name;
195
196 struct sk_buff* tx_skbuff[TX_RING_SIZE];
197 long rx_buffs;
198
199 char (*tx_bounce_buffs)[PKT_BUF_SZ];
200 int cur_rx, cur_tx;
201 int dirty_rx, dirty_tx;
202 int dma;
203 struct enet_statistics stats;
204 unsigned char chip_version;
205 char tx_full;
206 char lock;
207 };
208
209 #define LANCE_MUST_PAD 0x00000001
210 #define LANCE_ENABLE_AUTOSELECT 0x00000002
211 #define LANCE_MUST_REINIT_RING 0x00000004
212 #define LANCE_MUST_UNRESET 0x00000008
213 #define LANCE_HAS_MISSED_FRAME 0x00000010
214
215
216
217
218 static struct lance_chip_type {
219 int id_number;
220 const char *name;
221 int flags;
222 } chip_table[] = {
223 {0x0000, "LANCE 7990",
224 LANCE_MUST_PAD + LANCE_MUST_UNRESET},
225 {0x0003, "PCnet/ISA 79C960",
226 LANCE_ENABLE_AUTOSELECT + LANCE_MUST_REINIT_RING +
227 LANCE_HAS_MISSED_FRAME},
228 {0x2260, "PCnet/ISA+ 79C961",
229 LANCE_ENABLE_AUTOSELECT + LANCE_MUST_REINIT_RING +
230 LANCE_HAS_MISSED_FRAME},
231 {0x2420, "PCnet/PCI 79C970",
232 LANCE_ENABLE_AUTOSELECT + LANCE_MUST_REINIT_RING +
233 LANCE_HAS_MISSED_FRAME},
234
235
236 {0x2430, "PCnet32",
237 LANCE_ENABLE_AUTOSELECT + LANCE_MUST_REINIT_RING +
238 LANCE_HAS_MISSED_FRAME},
239 {0x0, "PCnet (unknown)",
240 LANCE_ENABLE_AUTOSELECT + LANCE_MUST_REINIT_RING +
241 LANCE_HAS_MISSED_FRAME},
242 };
243
244 enum {OLD_LANCE = 0, PCNET_ISA=1, PCNET_ISAP=2, PCNET_PCI=3, PCNET_VLB=4, LANCE_UNKNOWN=5};
245
246
247 static unsigned char pci_irq_line = 0;
248
249
250
251 static unsigned char lance_need_isa_bounce_buffers = 1;
252
253 static int lance_open(struct device *dev);
254 static void lance_init_ring(struct device *dev);
255 static int lance_start_xmit(struct sk_buff *skb, struct device *dev);
256 static int lance_rx(struct device *dev);
257 static void lance_interrupt(int irq, struct pt_regs *regs);
258 static int lance_close(struct device *dev);
259 static struct enet_statistics *lance_get_stats(struct device *dev);
260 static void set_multicast_list(struct device *dev);
261
262
263
264
265
266
267
268
269
270 int lance_init(void)
271 {
272 int *port;
273
274 if (high_memory <= 16*1024*1024)
275 lance_need_isa_bounce_buffers = 0;
276
277 #if defined(CONFIG_PCI)
278 if (pcibios_present()) {
279 int pci_index;
280 printk("lance.c: PCI bios is present, checking for devices...\n");
281 for (pci_index = 0; pci_index < 8; pci_index++) {
282 unsigned char pci_bus, pci_device_fn;
283 unsigned int pci_ioaddr;
284 unsigned short pci_command;
285
286 if (pcibios_find_device (PCI_VENDOR_ID_AMD,
287 PCI_DEVICE_ID_AMD_LANCE, pci_index,
288 &pci_bus, &pci_device_fn) != 0)
289 break;
290 pcibios_read_config_byte(pci_bus, pci_device_fn,
291 PCI_INTERRUPT_LINE, &pci_irq_line);
292 pcibios_read_config_dword(pci_bus, pci_device_fn,
293 PCI_BASE_ADDRESS_0, &pci_ioaddr);
294
295 pci_ioaddr &= ~3;
296
297
298
299
300 pcibios_read_config_word(pci_bus, pci_device_fn,
301 PCI_COMMAND, &pci_command);
302 if ( ! (pci_command & PCI_COMMAND_MASTER)) {
303 printk("PCI Master Bit has not been set. Setting...\n");
304 pci_command |= PCI_COMMAND_MASTER;
305 pcibios_write_config_word(pci_bus, pci_device_fn,
306 PCI_COMMAND, pci_command);
307 }
308 printk("Found PCnet/PCI at %#x, irq %d.\n",
309 pci_ioaddr, pci_irq_line);
310 lance_probe1(pci_ioaddr);
311 pci_irq_line = 0;
312 }
313 }
314 #endif
315
316 for (port = lance_portlist; *port; port++) {
317 int ioaddr = *port;
318
319 if ( check_region(ioaddr, LANCE_TOTAL_SIZE) == 0) {
320
321
322 char offset15, offset14 = inb(ioaddr + 14);
323
324 if ((offset14 == 0x52 || offset14 == 0x57) &&
325 ((offset15 = inb(ioaddr + 15)) == 0x57 || offset15 == 0x44))
326 lance_probe1(ioaddr);
327 }
328 }
329
330 return 0;
331 }
332
333 void lance_probe1(int ioaddr)
334 {
335 struct device *dev;
336 struct lance_private *lp;
337 short dma_channels;
338 int i, reset_val, lance_version;
339 const char *chipname;
340
341 unsigned char hpJ2405A = 0;
342 int hp_builtin = 0;
343 static int did_version = 0;
344
345
346
347
348
349
350 if ( *((unsigned short *) 0x000f0102) == 0x5048) {
351 static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360};
352 int hp_port = ( *((unsigned char *) 0x000f00f1) & 1) ? 0x499 : 0x99;
353
354 if ((inb(hp_port) & 0xc0) == 0x80
355 && ioaddr_table[inb(hp_port) & 3] == ioaddr)
356 hp_builtin = hp_port;
357 }
358
359 hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00
360 && inb(ioaddr+2) == 0x09);
361
362
363 reset_val = inw(ioaddr+LANCE_RESET);
364
365
366
367 if (!hpJ2405A)
368 outw(reset_val, ioaddr+LANCE_RESET);
369
370 outw(0x0000, ioaddr+LANCE_ADDR);
371 if (inw(ioaddr+LANCE_DATA) != 0x0004)
372 return;
373
374
375 outw(88, ioaddr+LANCE_ADDR);
376 if (inw(ioaddr+LANCE_ADDR) != 88) {
377 lance_version = 0;
378 } else {
379 int chip_version = inw(ioaddr+LANCE_DATA);
380 outw(89, ioaddr+LANCE_ADDR);
381 chip_version |= inw(ioaddr+LANCE_DATA) << 16;
382 if (lance_debug > 2)
383 printk(" LANCE chip version is %#x.\n", chip_version);
384 if ((chip_version & 0xfff) != 0x003)
385 return;
386 chip_version = (chip_version >> 12) & 0xffff;
387 for (lance_version = 1; chip_table[lance_version].id_number; lance_version++) {
388 if (chip_table[lance_version].id_number == chip_version)
389 break;
390 }
391 }
392
393 dev = init_etherdev(0, 0);
394 chipname = chip_table[lance_version].name;
395 printk("%s: %s at %#3x,", dev->name, chipname, ioaddr);
396
397
398
399 for (i = 0; i < 6; i++)
400 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
401
402 dev->base_addr = ioaddr;
403 request_region(ioaddr, LANCE_TOTAL_SIZE, chip_table[lance_version].name);
404
405
406 lp = (struct lance_private *) kmalloc(sizeof(*lp), GFP_DMA | GFP_KERNEL);
407 memset(lp, 0, sizeof(*lp));
408 dev->priv = lp;
409 lp->name = chipname;
410 lp->rx_buffs = (unsigned long) kmalloc(PKT_BUF_SZ*RX_RING_SIZE, GFP_DMA | GFP_KERNEL);
411 lp->tx_bounce_buffs = NULL;
412 if (lance_need_isa_bounce_buffers)
413 lp->tx_bounce_buffs = kmalloc(PKT_BUF_SZ*TX_RING_SIZE, GFP_DMA | GFP_KERNEL);
414
415 lp->chip_version = lance_version;
416
417 lp->init_block.mode = 0x0003;
418 for (i = 0; i < 6; i++)
419 lp->init_block.phys_addr[i] = dev->dev_addr[i];
420 lp->init_block.filter[0] = 0x00000000;
421 lp->init_block.filter[1] = 0x00000000;
422 lp->init_block.rx_ring = (int)lp->rx_ring | RX_RING_LEN_BITS;
423 lp->init_block.tx_ring = (int)lp->tx_ring | TX_RING_LEN_BITS;
424
425 outw(0x0001, ioaddr+LANCE_ADDR);
426 inw(ioaddr+LANCE_ADDR);
427 outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
428 outw(0x0002, ioaddr+LANCE_ADDR);
429 inw(ioaddr+LANCE_ADDR);
430 outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
431 outw(0x0000, ioaddr+LANCE_ADDR);
432 inw(ioaddr+LANCE_ADDR);
433
434 if (pci_irq_line) {
435 dev->dma = 4;
436 dev->irq = pci_irq_line;
437 } else if (hp_builtin) {
438 static const char dma_tbl[4] = {3, 5, 6, 0};
439 static const char irq_tbl[4] = {3, 4, 5, 9};
440 unsigned char port_val = inb(hp_builtin);
441 dev->dma = dma_tbl[(port_val >> 4) & 3];
442 dev->irq = irq_tbl[(port_val >> 2) & 3];
443 printk(" HP Vectra IRQ %d DMA %d.\n", dev->irq, dev->dma);
444 } else if (hpJ2405A) {
445 static const char dma_tbl[4] = {3, 5, 6, 7};
446 static const char irq_tbl[8] = {3, 4, 5, 9, 10, 11, 12, 15};
447 short reset_val = inw(ioaddr+LANCE_RESET);
448 dev->dma = dma_tbl[(reset_val >> 2) & 3];
449 dev->irq = irq_tbl[(reset_val >> 4) & 7];
450 printk(" HP J2405A IRQ %d DMA %d.\n", dev->irq, dev->dma);
451 } else if (lance_version == PCNET_ISAP) {
452 short bus_info;
453 outw(8, ioaddr+LANCE_ADDR);
454 bus_info = inw(ioaddr+LANCE_BUS_IF);
455 dev->dma = bus_info & 0x07;
456 dev->irq = (bus_info >> 4) & 0x0F;
457 } else {
458
459 if (dev->mem_start & 0x07)
460 dev->dma = dev->mem_start & 0x07;
461 }
462
463 if (dev->dma == 0) {
464
465
466 dma_channels = ((inb(DMA1_STAT_REG) >> 4) & 0x0f) |
467 (inb(DMA2_STAT_REG) & 0xf0);
468 }
469 if (dev->irq >= 2)
470 printk(" assigned IRQ %d", dev->irq);
471 else {
472
473
474
475 autoirq_setup(0);
476
477
478 outw(0x0041, ioaddr+LANCE_DATA);
479
480 dev->irq = autoirq_report(1);
481 if (dev->irq)
482 printk(", probed IRQ %d", dev->irq);
483 else {
484 printk(", failed to detect IRQ line.\n");
485 return;
486 }
487
488
489
490 if (inw(ioaddr+LANCE_DATA) & 0x0100)
491 dev->dma = 4;
492 }
493
494 if (dev->dma == 4) {
495 printk(", no DMA needed.\n");
496 } else if (dev->dma) {
497 if (request_dma(dev->dma, chipname)) {
498 printk("DMA %d allocation failed.\n", dev->dma);
499 return;
500 } else
501 printk(", assigned DMA %d.\n", dev->dma);
502 } else {
503 for (i = 0; i < 4; i++) {
504 static const char dmas[] = { 5, 6, 7, 3 };
505 int dma = dmas[i];
506 int boguscnt;
507
508
509
510 if (test_bit(dma, &dma_channels))
511 continue;
512 outw(0x7f04, ioaddr+LANCE_DATA);
513 if (request_dma(dma, chipname))
514 continue;
515 set_dma_mode(dma, DMA_MODE_CASCADE);
516 enable_dma(dma);
517
518
519 outw(0x0001, ioaddr+LANCE_DATA);
520 for (boguscnt = 100; boguscnt > 0; --boguscnt)
521 if (inw(ioaddr+LANCE_DATA) & 0x0900)
522 break;
523 if (inw(ioaddr+LANCE_DATA) & 0x0100) {
524 dev->dma = dma;
525 printk(", DMA %d.\n", dev->dma);
526 break;
527 } else {
528 disable_dma(dma);
529 free_dma(dma);
530 }
531 }
532 if (i == 4) {
533 printk("DMA detection failed.\n");
534 return;
535 }
536 }
537
538 if (chip_table[lp->chip_version].flags & LANCE_ENABLE_AUTOSELECT) {
539
540
541 outw(0x0002, ioaddr+LANCE_ADDR);
542 outw(0x0002, ioaddr+LANCE_BUS_IF);
543 }
544
545 if (lance_debug > 0 && did_version++ == 0)
546 printk(version);
547
548
549 dev->open = &lance_open;
550 dev->hard_start_xmit = &lance_start_xmit;
551 dev->stop = &lance_close;
552 dev->get_stats = &lance_get_stats;
553 dev->set_multicast_list = &set_multicast_list;
554
555 return;
556 }
557
558
559 static int
560 lance_open(struct device *dev)
561 {
562 struct lance_private *lp = (struct lance_private *)dev->priv;
563 int ioaddr = dev->base_addr;
564 int i;
565
566 if (dev->irq == 0 ||
567 request_irq(dev->irq, &lance_interrupt, 0, lp->name)) {
568 return -EAGAIN;
569 }
570
571
572
573
574 irq2dev_map[dev->irq] = dev;
575
576
577 inw(ioaddr+LANCE_RESET);
578
579
580 if (dev->dma != 4) {
581 enable_dma(dev->dma);
582 set_dma_mode(dev->dma, DMA_MODE_CASCADE);
583 }
584
585
586 if (chip_table[lp->chip_version].flags & LANCE_MUST_UNRESET)
587 outw(0, ioaddr+LANCE_RESET);
588
589 if (chip_table[lp->chip_version].flags & LANCE_ENABLE_AUTOSELECT) {
590
591 outw(0x0002, ioaddr+LANCE_ADDR);
592 outw(0x0002, ioaddr+LANCE_BUS_IF);
593 }
594
595 if (lance_debug > 1)
596 printk("%s: lance_open() irq %d dma %d tx/rx rings %#x/%#x init %#x.\n",
597 dev->name, dev->irq, dev->dma, (int) lp->tx_ring, (int) lp->rx_ring,
598 (int) &lp->init_block);
599
600 lance_init_ring(dev);
601
602 outw(0x0001, ioaddr+LANCE_ADDR);
603 outw((short) (int) &lp->init_block, ioaddr+LANCE_DATA);
604 outw(0x0002, ioaddr+LANCE_ADDR);
605 outw(((int)&lp->init_block) >> 16, ioaddr+LANCE_DATA);
606
607 outw(0x0004, ioaddr+LANCE_ADDR);
608 outw(0x0915, ioaddr+LANCE_DATA);
609
610 outw(0x0000, ioaddr+LANCE_ADDR);
611 outw(0x0001, ioaddr+LANCE_DATA);
612
613 dev->tbusy = 0;
614 dev->interrupt = 0;
615 dev->start = 1;
616 i = 0;
617 while (i++ < 100)
618 if (inw(ioaddr+LANCE_DATA) & 0x0100)
619 break;
620
621
622
623
624 outw(0x0042, ioaddr+LANCE_DATA);
625
626 if (lance_debug > 2)
627 printk("%s: LANCE open after %d ticks, init block %#x csr0 %4.4x.\n",
628 dev->name, i, (int) &lp->init_block, inw(ioaddr+LANCE_DATA));
629
630 return 0;
631 }
632
633
634
635
636
637
638
639
640
641
642
643
644
645 static void
646 lance_purge_tx_ring(struct device *dev)
647 {
648 struct lance_private *lp = (struct lance_private *)dev->priv;
649 int i;
650
651 for (i = 0; i < TX_RING_SIZE; i++) {
652 if (lp->tx_skbuff[i]) {
653 dev_kfree_skb(lp->tx_skbuff[i],FREE_WRITE);
654 lp->tx_skbuff[i] = NULL;
655 }
656 }
657 }
658
659
660
661 static void
662 lance_init_ring(struct device *dev)
663 {
664 struct lance_private *lp = (struct lance_private *)dev->priv;
665 int i;
666
667 lp->lock = 0, lp->tx_full = 0;
668 lp->cur_rx = lp->cur_tx = 0;
669 lp->dirty_rx = lp->dirty_tx = 0;
670
671 for (i = 0; i < RX_RING_SIZE; i++) {
672 lp->rx_ring[i].base = (lp->rx_buffs + i*PKT_BUF_SZ) | 0x80000000;
673 lp->rx_ring[i].buf_length = -PKT_BUF_SZ;
674 }
675
676
677 for (i = 0; i < TX_RING_SIZE; i++) {
678 lp->tx_ring[i].base = 0;
679 }
680
681 lp->init_block.mode = 0x0000;
682 for (i = 0; i < 6; i++)
683 lp->init_block.phys_addr[i] = dev->dev_addr[i];
684 lp->init_block.filter[0] = 0x00000000;
685 lp->init_block.filter[1] = 0x00000000;
686 lp->init_block.rx_ring = (int)lp->rx_ring | RX_RING_LEN_BITS;
687 lp->init_block.tx_ring = (int)lp->tx_ring | TX_RING_LEN_BITS;
688 }
689
690 static void
691 lance_restart(struct device *dev, unsigned int csr0_bits, int must_reinit)
692 {
693 struct lance_private *lp = (struct lance_private *)dev->priv;
694
695 if (must_reinit ||
696 (chip_table[lp->chip_version].flags & LANCE_MUST_REINIT_RING)) {
697 lance_purge_tx_ring(dev);
698 lance_init_ring(dev);
699 }
700 outw(0x0000, dev->base_addr + LANCE_ADDR);
701 outw(csr0_bits, dev->base_addr + LANCE_DATA);
702 }
703
704 static int
705 lance_start_xmit(struct sk_buff *skb, struct device *dev)
706 {
707 struct lance_private *lp = (struct lance_private *)dev->priv;
708 int ioaddr = dev->base_addr;
709 int entry;
710 unsigned long flags;
711
712
713 if (dev->tbusy) {
714 int tickssofar = jiffies - dev->trans_start;
715 if (tickssofar < 20)
716 return 1;
717 outw(0, ioaddr+LANCE_ADDR);
718 printk("%s: transmit timed out, status %4.4x, resetting.\n",
719 dev->name, inw(ioaddr+LANCE_DATA));
720 outw(0x0004, ioaddr+LANCE_DATA);
721 lp->stats.tx_errors++;
722 #ifndef final_version
723 {
724 int i;
725 printk(" Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
726 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
727 lp->cur_rx);
728 for (i = 0 ; i < RX_RING_SIZE; i++)
729 printk("%s %08x %04x %04x", i & 0x3 ? "" : "\n ",
730 lp->rx_ring[i].base, -lp->rx_ring[i].buf_length,
731 lp->rx_ring[i].msg_length);
732 for (i = 0 ; i < TX_RING_SIZE; i++)
733 printk("%s %08x %04x %04x", i & 0x3 ? "" : "\n ",
734 lp->tx_ring[i].base, -lp->tx_ring[i].length,
735 lp->tx_ring[i].misc);
736 printk("\n");
737 }
738 #endif
739 lance_restart(dev, 0x0043, 1);
740
741 dev->tbusy=0;
742 dev->trans_start = jiffies;
743
744 return 0;
745 }
746
747 if (skb == NULL) {
748 dev_tint(dev);
749 return 0;
750 }
751
752 if (skb->len <= 0)
753 return 0;
754
755 if (lance_debug > 3) {
756 outw(0x0000, ioaddr+LANCE_ADDR);
757 printk("%s: lance_start_xmit() called, csr0 %4.4x.\n", dev->name,
758 inw(ioaddr+LANCE_DATA));
759 outw(0x0000, ioaddr+LANCE_DATA);
760 }
761
762
763
764 if (set_bit(0, (void*)&dev->tbusy) != 0) {
765 printk("%s: Transmitter access conflict.\n", dev->name);
766 return 1;
767 }
768
769 if (set_bit(0, (void*)&lp->lock) != 0) {
770 if (lance_debug > 0)
771 printk("%s: tx queue lock!.\n", dev->name);
772
773 return 1;
774 }
775
776
777
778
779 entry = lp->cur_tx & TX_RING_MOD_MASK;
780
781
782
783
784
785 if (chip_table[lp->chip_version].flags & LANCE_MUST_PAD) {
786 lp->tx_ring[entry].length =
787 -(ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN);
788 } else
789 lp->tx_ring[entry].length = -skb->len;
790
791 lp->tx_ring[entry].misc = 0x0000;
792
793
794
795 if ((int)(skb->data) + skb->len > 0x01000000) {
796 if (lance_debug > 5)
797 printk("%s: bouncing a high-memory packet (%#x).\n",
798 dev->name, (int)(skb->data));
799 memcpy(&lp->tx_bounce_buffs[entry], skb->data, skb->len);
800 lp->tx_ring[entry].base =
801 (int)(lp->tx_bounce_buffs + entry) | 0x83000000;
802 dev_kfree_skb (skb, FREE_WRITE);
803 } else {
804 lp->tx_skbuff[entry] = skb;
805 lp->tx_ring[entry].base = (int)(skb->data) | 0x83000000;
806 }
807 lp->cur_tx++;
808
809
810 outw(0x0000, ioaddr+LANCE_ADDR);
811 outw(0x0048, ioaddr+LANCE_DATA);
812
813 dev->trans_start = jiffies;
814
815 save_flags(flags);
816 cli();
817 lp->lock = 0;
818 if (lp->tx_ring[(entry+1) & TX_RING_MOD_MASK].base == 0)
819 dev->tbusy=0;
820 else
821 lp->tx_full = 1;
822 restore_flags(flags);
823
824 return 0;
825 }
826
827
828 static void
829 lance_interrupt(int irq, struct pt_regs * regs)
830 {
831 struct device *dev = (struct device *)(irq2dev_map[irq]);
832 struct lance_private *lp;
833 int csr0, ioaddr, boguscnt=10;
834 int must_restart;
835
836 if (dev == NULL) {
837 printk ("lance_interrupt(): irq %d for unknown device.\n", irq);
838 return;
839 }
840
841 ioaddr = dev->base_addr;
842 lp = (struct lance_private *)dev->priv;
843 if (dev->interrupt)
844 printk("%s: Re-entering the interrupt handler.\n", dev->name);
845
846 dev->interrupt = 1;
847
848 outw(0x00, dev->base_addr + LANCE_ADDR);
849 while ((csr0 = inw(dev->base_addr + LANCE_DATA)) & 0x8600
850 && --boguscnt >= 0) {
851
852 outw(csr0 & ~0x004f, dev->base_addr + LANCE_DATA);
853
854 must_restart = 0;
855
856 if (lance_debug > 5)
857 printk("%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
858 dev->name, csr0, inw(dev->base_addr + LANCE_DATA));
859
860 if (csr0 & 0x0400)
861 lance_rx(dev);
862
863 if (csr0 & 0x0200) {
864 int dirty_tx = lp->dirty_tx;
865
866 while (dirty_tx < lp->cur_tx) {
867 int entry = dirty_tx & TX_RING_MOD_MASK;
868 int status = lp->tx_ring[entry].base;
869
870 if (status < 0)
871 break;
872
873 lp->tx_ring[entry].base = 0;
874
875 if (status & 0x40000000) {
876
877 int err_status = lp->tx_ring[entry].misc;
878 lp->stats.tx_errors++;
879 if (err_status & 0x0400) lp->stats.tx_aborted_errors++;
880 if (err_status & 0x0800) lp->stats.tx_carrier_errors++;
881 if (err_status & 0x1000) lp->stats.tx_window_errors++;
882 if (err_status & 0x4000) {
883
884 lp->stats.tx_fifo_errors++;
885
886 printk("%s: Tx FIFO error! Status %4.4x.\n",
887 dev->name, csr0);
888
889 must_restart = 1;
890 }
891 } else {
892 if (status & 0x18000000)
893 lp->stats.collisions++;
894 lp->stats.tx_packets++;
895 }
896
897
898
899 if (lp->tx_skbuff[entry]) {
900 dev_kfree_skb(lp->tx_skbuff[entry],FREE_WRITE);
901 lp->tx_skbuff[entry] = 0;
902 }
903 dirty_tx++;
904 }
905
906 #ifndef final_version
907 if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
908 printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
909 dirty_tx, lp->cur_tx, lp->tx_full);
910 dirty_tx += TX_RING_SIZE;
911 }
912 #endif
913
914 if (lp->tx_full && dev->tbusy
915 && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
916
917 lp->tx_full = 0;
918 dev->tbusy = 0;
919 mark_bh(NET_BH);
920 }
921
922 lp->dirty_tx = dirty_tx;
923 }
924
925
926 if (csr0 & 0x4000) lp->stats.tx_errors++;
927 if (csr0 & 0x1000) lp->stats.rx_errors++;
928 if (csr0 & 0x0800) {
929 printk("%s: Bus master arbitration failure, status %4.4x.\n",
930 dev->name, csr0);
931
932 must_restart = 1;
933 }
934
935 if (must_restart) {
936
937 outw(0x0000, dev->base_addr + LANCE_ADDR);
938 outw(0x0004, dev->base_addr + LANCE_DATA);
939 lance_restart(dev, 0x0002, 0);
940 }
941 }
942
943
944 outw(0x0000, dev->base_addr + LANCE_ADDR);
945 outw(0x7940, dev->base_addr + LANCE_DATA);
946
947 if (lance_debug > 4)
948 printk("%s: exiting interrupt, csr%d=%#4.4x.\n",
949 dev->name, inw(ioaddr + LANCE_ADDR),
950 inw(dev->base_addr + LANCE_DATA));
951
952 dev->interrupt = 0;
953 return;
954 }
955
956 static int
957 lance_rx(struct device *dev)
958 {
959 struct lance_private *lp = (struct lance_private *)dev->priv;
960 int entry = lp->cur_rx & RX_RING_MOD_MASK;
961 int i;
962
963
964 while (lp->rx_ring[entry].base >= 0) {
965 int status = lp->rx_ring[entry].base >> 24;
966
967 if (status != 0x03) {
968
969
970
971
972 if (status & 0x01)
973 lp->stats.rx_errors++;
974 if (status & 0x20) lp->stats.rx_frame_errors++;
975 if (status & 0x10) lp->stats.rx_over_errors++;
976 if (status & 0x08) lp->stats.rx_crc_errors++;
977 if (status & 0x04) lp->stats.rx_fifo_errors++;
978 lp->rx_ring[entry].base &= 0x03ffffff;
979 }
980 else
981 {
982
983 short pkt_len = (lp->rx_ring[entry].msg_length & 0xfff)-4;
984 struct sk_buff *skb;
985
986 if(pkt_len<60)
987 {
988 printk("%s: Runt packet!\n",dev->name);
989 lp->stats.rx_errors++;
990 }
991 else
992 {
993 skb = dev_alloc_skb(pkt_len+2);
994 if (skb == NULL)
995 {
996 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
997 for (i=0; i < RX_RING_SIZE; i++)
998 if (lp->rx_ring[(entry+i) & RX_RING_MOD_MASK].base < 0)
999 break;
1000
1001 if (i > RX_RING_SIZE -2)
1002 {
1003 lp->stats.rx_dropped++;
1004 lp->rx_ring[entry].base |= 0x80000000;
1005 lp->cur_rx++;
1006 }
1007 break;
1008 }
1009 skb->dev = dev;
1010 skb_reserve(skb,2);
1011 skb_put(skb,pkt_len);
1012 eth_copy_and_sum(skb,
1013 (unsigned char *)(lp->rx_ring[entry].base & 0x00ffffff),
1014 pkt_len,0);
1015 skb->protocol=eth_type_trans(skb,dev);
1016 netif_rx(skb);
1017 lp->stats.rx_packets++;
1018 }
1019 }
1020
1021
1022 lp->rx_ring[entry].buf_length = -PKT_BUF_SZ;
1023 lp->rx_ring[entry].base |= 0x80000000;
1024 entry = (++lp->cur_rx) & RX_RING_MOD_MASK;
1025 }
1026
1027
1028
1029
1030 return 0;
1031 }
1032
1033 static int
1034 lance_close(struct device *dev)
1035 {
1036 int ioaddr = dev->base_addr;
1037 struct lance_private *lp = (struct lance_private *)dev->priv;
1038
1039 dev->start = 0;
1040 dev->tbusy = 1;
1041
1042 if (chip_table[lp->chip_version].flags & LANCE_HAS_MISSED_FRAME) {
1043 outw(112, ioaddr+LANCE_ADDR);
1044 lp->stats.rx_missed_errors = inw(ioaddr+LANCE_DATA);
1045 }
1046 outw(0, ioaddr+LANCE_ADDR);
1047
1048 if (lance_debug > 1)
1049 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1050 dev->name, inw(ioaddr+LANCE_DATA));
1051
1052
1053
1054 outw(0x0004, ioaddr+LANCE_DATA);
1055
1056 if (dev->dma != 4)
1057 disable_dma(dev->dma);
1058
1059 free_irq(dev->irq);
1060
1061 irq2dev_map[dev->irq] = 0;
1062
1063 return 0;
1064 }
1065
1066 static struct enet_statistics *
1067 lance_get_stats(struct device *dev)
1068 {
1069 struct lance_private *lp = (struct lance_private *)dev->priv;
1070 short ioaddr = dev->base_addr;
1071 short saved_addr;
1072 unsigned long flags;
1073
1074 if (chip_table[lp->chip_version].flags & LANCE_HAS_MISSED_FRAME) {
1075 save_flags(flags);
1076 cli();
1077 saved_addr = inw(ioaddr+LANCE_ADDR);
1078 outw(112, ioaddr+LANCE_ADDR);
1079 lp->stats.rx_missed_errors = inw(ioaddr+LANCE_DATA);
1080 outw(saved_addr, ioaddr+LANCE_ADDR);
1081 restore_flags(flags);
1082 }
1083
1084 return &lp->stats;
1085 }
1086
1087
1088
1089
1090 static void set_multicast_list(struct device *dev)
1091 {
1092 short ioaddr = dev->base_addr;
1093
1094 outw(0, ioaddr+LANCE_ADDR);
1095 outw(0x0004, ioaddr+LANCE_DATA);
1096
1097 if (dev->flags&IFF_PROMISC) {
1098
1099 printk("%s: Promiscuous mode enabled.\n", dev->name);
1100 outw(15, ioaddr+LANCE_ADDR);
1101 outw(0x8000, ioaddr+LANCE_DATA);
1102 } else {
1103 short multicast_table[4];
1104 int i;
1105 int num_addrs=dev->mc_count;
1106 if(dev->flags&IFF_ALLMULTI)
1107 num_addrs=1;
1108
1109 memset(multicast_table, (num_addrs == 0) ? 0 : -1, sizeof(multicast_table));
1110 for (i = 0; i < 4; i++) {
1111 outw(8 + i, ioaddr+LANCE_ADDR);
1112 outw(multicast_table[i], ioaddr+LANCE_DATA);
1113 }
1114 outw(15, ioaddr+LANCE_ADDR);
1115 outw(0x0000, ioaddr+LANCE_DATA);
1116 }
1117
1118 lance_restart(dev, 0x0142, 0);
1119
1120 }
1121
1122
1123
1124
1125
1126
1127
1128
1129