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