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