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