This source file includes following definitions.
- dec21040_init
- tulip_probe
- tulip_probe1
- tulip_open
- tulip_init_ring
- tulip_start_xmit
- tulip_interrupt
- tulip_rx
- tulip_close
- tulip_get_stats
- set_multicast_list
- set_mac_address
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static const char *version = "tulip.c:v0.05 1/20/95 becker@cesdis.gsfc.nasa.gov\n";
18
19 #include <linux/module.h>
20
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
40
41 #define TULIP_TOTAL_SIZE 0x80
42
43 #ifdef HAVE_DEVLIST
44 struct netdev_entry tulip_drv =
45 {"Tulip", tulip_pci_probe, TULIP_TOTAL_SIZE, NULL};
46 #endif
47
48 #define TULIP_DEBUG 1
49 #ifdef TULIP_DEBUG
50 int tulip_debug = TULIP_DEBUG;
51 #else
52 int tulip_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 #define DEC_VENDOR_ID 0x1011
111 #define DEC_21040_ID 0x0002
112
113
114 #define TX_RING_SIZE 4
115 #define RX_RING_SIZE 4
116 #define PKT_BUF_SZ 1536
117
118
119
120 enum tulip_offsets {
121 CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
122 CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
123 CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78 };
124
125
126 struct tulip_rx_desc {
127 int status;
128 int length;
129 char *buffer1, *buffer2;
130 };
131
132 struct tulip_tx_desc {
133 int status;
134 int length;
135 char *buffer1, *buffer2;
136 };
137
138 struct tulip_private {
139 char devname[8];
140 struct tulip_rx_desc rx_ring[RX_RING_SIZE];
141 struct tulip_tx_desc tx_ring[TX_RING_SIZE];
142
143 struct sk_buff* tx_skbuff[TX_RING_SIZE];
144 long rx_buffs;
145 struct enet_statistics stats;
146 int setup_frame[48];
147 unsigned int cur_rx, cur_tx;
148 unsigned int dirty_rx, dirty_tx;
149 unsigned int tx_full:1;
150 int pad0, pad1;
151 };
152
153 static void tulip_probe1(int ioaddr, int irq);
154 static int tulip_open(struct device *dev);
155 static void tulip_init_ring(struct device *dev);
156 static int tulip_start_xmit(struct sk_buff *skb, struct device *dev);
157 static int tulip_rx(struct device *dev);
158 static void tulip_interrupt(int irq, struct pt_regs *regs);
159 static int tulip_close(struct device *dev);
160 static struct enet_statistics *tulip_get_stats(struct device *dev);
161 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
162 static int set_mac_address(struct device *dev, void *addr);
163
164
165
166 #ifndef MODULE
167
168
169
170
171
172 int dec21040_init(void)
173 {
174
175 if (pcibios_present()) {
176 int pci_index;
177 for (pci_index = 0; pci_index < 8; pci_index++) {
178 unsigned char pci_bus, pci_device_fn, pci_irq_line;
179 unsigned long pci_ioaddr;
180
181 if (pcibios_find_device (DEC_VENDOR_ID, DEC_21040_ID, pci_index,
182 &pci_bus, &pci_device_fn) != 0)
183 break;
184 pcibios_read_config_byte(pci_bus, pci_device_fn,
185 PCI_INTERRUPT_LINE, &pci_irq_line);
186 pcibios_read_config_dword(pci_bus, pci_device_fn,
187 PCI_BASE_ADDRESS_0, &pci_ioaddr);
188
189 pci_ioaddr &= ~3;
190 if (tulip_debug > 2)
191 printk("Found DEC PCI Tulip at I/O %#lx, IRQ %d.\n",
192 pci_ioaddr, pci_irq_line);
193 tulip_probe1(pci_ioaddr, pci_irq_line);
194 }
195 }
196
197 return 0;
198 }
199 #endif
200 #ifdef MODULE
201 static int tulip_probe(struct device *dev)
202 {
203 printk("tulip: This driver does not yet install properly from module!\n");
204 return -1;
205 }
206 #endif
207
208 static void tulip_probe1(int ioaddr, int irq)
209 {
210 static int did_version = 0;
211 struct device *dev;
212 struct tulip_private *tp;
213 int i;
214
215 if (tulip_debug > 0 && did_version++ == 0)
216 printk(version);
217
218 dev = init_etherdev(0, 0);
219
220 printk("%s: DEC 21040 Tulip at %#3x,", dev->name, ioaddr);
221
222
223 outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
224
225 inl(ioaddr + CSR8) & 0xffff;
226
227
228
229
230
231 outl(0, ioaddr + CSR9);
232 for (i = 0; i < 6; i++) {
233 int value, boguscnt = 100000;
234 do
235 value = inl(ioaddr + CSR9);
236 while (value < 0 && --boguscnt > 0);
237 printk(" %2.2x", dev->dev_addr[i] = value);
238 }
239 printk(", IRQ %d\n", irq);
240
241
242 request_region(ioaddr, TULIP_TOTAL_SIZE, "DEC Tulip Ethernet");
243
244 dev->base_addr = ioaddr;
245 dev->irq = irq;
246
247
248 tp = kmalloc(sizeof(*tp), GFP_KERNEL | GFP_DMA);
249 dev->priv = tp;
250 tp->rx_buffs = kmalloc(PKT_BUF_SZ*RX_RING_SIZE, GFP_KERNEL | GFP_DMA);
251
252
253 dev->open = &tulip_open;
254 dev->hard_start_xmit = &tulip_start_xmit;
255 dev->stop = &tulip_close;
256 dev->get_stats = &tulip_get_stats;
257 #ifdef HAVE_MULTICAST
258 dev->set_multicast_list = &set_multicast_list;
259 #endif
260 #ifdef HAVE_SET_MAC_ADDR
261 dev->set_mac_address = &set_mac_address;
262 #endif
263
264 return;
265 }
266
267
268 static int
269 tulip_open(struct device *dev)
270 {
271 struct tulip_private *tp = (struct tulip_private *)dev->priv;
272 int ioaddr = dev->base_addr;
273
274
275 outl(0xfff80001, ioaddr + CSR0);
276 SLOW_DOWN_IO;
277
278
279
280
281
282
283
284
285 outl(0xfff84800, ioaddr + CSR0);
286
287 if (irq2dev_map[dev->irq] != NULL
288 || (irq2dev_map[dev->irq] = dev) == NULL
289 || dev->irq == 0
290 || request_irq(dev->irq, &tulip_interrupt, 0, "DEC 21040 Tulip")) {
291 return -EAGAIN;
292 }
293
294 if (tulip_debug > 1)
295 printk("%s: tulip_open() irq %d.\n", dev->name, dev->irq);
296
297 tulip_init_ring(dev);
298
299
300 {
301 unsigned short *eaddrs = (unsigned short *)dev->dev_addr;
302 int *setup_frm = tp->setup_frame, i;
303
304
305 *setup_frm++ = 0xffff;
306 *setup_frm++ = 0xffff;
307 *setup_frm++ = 0xffff;
308
309 for (i = 1; i < 16; i++) {
310 *setup_frm++ = eaddrs[0];
311 *setup_frm++ = eaddrs[1];
312 *setup_frm++ = eaddrs[2];
313 }
314
315 tp->tx_ring[0].length = 0x08000000 | 192;
316 tp->tx_ring[0].buffer1 = (char *)tp->setup_frame;
317 tp->tx_ring[0].buffer2 = 0;
318 tp->tx_ring[0].status = 0x80000000;
319
320 tp->cur_tx++, tp->dirty_tx++;
321 }
322
323 outl((int)tp->rx_ring, ioaddr + CSR3);
324 outl((int)tp->tx_ring, ioaddr + CSR4);
325
326
327 outl(0x00000000, ioaddr + CSR13);
328 outl(0x00000004, ioaddr + CSR13);
329
330
331 outl(0xfffe2002, ioaddr + CSR6);
332
333
334 outl(0, ioaddr + CSR1);
335
336 dev->tbusy = 0;
337 dev->interrupt = 0;
338 dev->start = 1;
339
340
341 outl(0xFFFFFFFF, ioaddr + CSR7);
342
343 if (tulip_debug > 2) {
344 printk("%s: Done tulip_open(), CSR0 %8.8x, CSR13 %8.8x.\n",
345 dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR13));
346 }
347 MOD_INC_USE_COUNT;
348 return 0;
349 }
350
351
352 static void
353 tulip_init_ring(struct device *dev)
354 {
355 struct tulip_private *tp = (struct tulip_private *)dev->priv;
356 int i;
357
358 tp->tx_full = 0;
359 tp->cur_rx = tp->cur_tx = 0;
360 tp->dirty_rx = tp->dirty_tx = 0;
361
362 for (i = 0; i < RX_RING_SIZE; i++) {
363 tp->rx_ring[i].status = 0x80000000;
364 tp->rx_ring[i].length = PKT_BUF_SZ;
365 tp->rx_ring[i].buffer1 = (char *)(tp->rx_buffs + i*PKT_BUF_SZ);
366 tp->rx_ring[i].buffer2 = (char *)&tp->rx_ring[i+1];
367 }
368
369 tp->rx_ring[i-1].length = PKT_BUF_SZ | 0x02000000;
370 tp->rx_ring[i-1].buffer2 = (char *)&tp->rx_ring[0];
371
372
373
374 for (i = 0; i < TX_RING_SIZE; i++) {
375 tp->tx_ring[i].status = 0x00000000;
376 }
377 }
378
379 static int
380 tulip_start_xmit(struct sk_buff *skb, struct device *dev)
381 {
382 struct tulip_private *tp = (struct tulip_private *)dev->priv;
383 int ioaddr = dev->base_addr;
384 int entry;
385
386
387 if (dev->tbusy) {
388 int tickssofar = jiffies - dev->trans_start;
389 int i;
390 if (tickssofar < 20)
391 return 1;
392 printk("%s: transmit timed out, status %8.8x, SIA %8.8x %8.8x %8.8x %8.8x, resetting...\n",
393 dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR12),
394 inl(ioaddr + CSR13), inl(ioaddr + CSR14), inl(ioaddr + CSR15));
395 printk(" Rx ring %8.8x: ", (int)tp->rx_ring);
396 for (i = 0; i < RX_RING_SIZE; i++)
397 printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
398 printk("\n Tx ring %8.8x: ", (int)tp->tx_ring);
399 for (i = 0; i < TX_RING_SIZE; i++)
400 printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
401 printk("\n");
402
403 tp->stats.tx_errors++;
404
405 dev->tbusy=0;
406 dev->trans_start = jiffies;
407 return 0;
408 }
409
410 if (skb == NULL || skb->len <= 0) {
411 printk("%s: Obsolete driver layer request made: skbuff==NULL.\n",
412 dev->name);
413 dev_tint(dev);
414 return 0;
415 }
416
417
418
419
420 if (set_bit(0, (void*)&dev->tbusy) != 0) {
421 printk("%s: Transmitter access conflict.\n", dev->name);
422 return 1;
423 }
424
425
426
427
428
429 entry = tp->cur_tx % TX_RING_SIZE;
430
431 tp->tx_full = 1;
432 tp->tx_skbuff[entry] = skb;
433 tp->tx_ring[entry].length = skb->len |
434 (entry == TX_RING_SIZE-1 ? 0xe2000000 : 0xe0000000);
435 tp->tx_ring[entry].buffer1 = skb->data;
436 tp->tx_ring[entry].buffer2 = 0;
437 tp->tx_ring[entry].status = 0x80000000;
438
439 tp->cur_tx++;
440
441
442 outl(0, ioaddr + CSR1);
443
444 dev->trans_start = jiffies;
445
446 return 0;
447 }
448
449
450
451 static void tulip_interrupt(int irq, struct pt_regs *regs)
452 {
453 struct device *dev = (struct device *)(irq2dev_map[irq]);
454 struct tulip_private *lp;
455 int csr5, ioaddr, boguscnt=10;
456
457 if (dev == NULL) {
458 printk ("tulip_interrupt(): irq %d for unknown device.\n", irq);
459 return;
460 }
461
462 ioaddr = dev->base_addr;
463 lp = (struct tulip_private *)dev->priv;
464 if (dev->interrupt)
465 printk("%s: Re-entering the interrupt handler.\n", dev->name);
466
467 dev->interrupt = 1;
468
469 do {
470 csr5 = inl(ioaddr + CSR5);
471
472 outl(csr5 & 0x0001ffff, ioaddr + CSR5);
473
474 if (tulip_debug > 4)
475 printk("%s: interrupt csr5=%#8.8x new csr5=%#8.8x.\n",
476 dev->name, csr5, inl(dev->base_addr + CSR5));
477
478 if ((csr5 & 0x00018000) == 0)
479 break;
480
481 if (csr5 & 0x0040)
482 tulip_rx(dev);
483
484 if (csr5 & 0x0001) {
485 int dirty_tx = lp->dirty_tx;
486
487 while (dirty_tx < lp->cur_tx) {
488 int entry = dirty_tx % TX_RING_SIZE;
489 int status = lp->tx_ring[entry].status;
490
491 if (status < 0)
492 break;
493
494 if (status & 0x8000) {
495
496 lp->stats.tx_errors++;
497 if (status & 0x4104) lp->stats.tx_aborted_errors++;
498 if (status & 0x0C00) lp->stats.tx_carrier_errors++;
499 if (status & 0x0200) lp->stats.tx_window_errors++;
500 if (status & 0x0002) lp->stats.tx_fifo_errors++;
501 if (status & 0x0080) lp->stats.tx_heartbeat_errors++;
502 #ifdef ETHER_STATS
503 if (status & 0x0100) lp->stats.collisions16++;
504 #endif
505 } else {
506 #ifdef ETHER_STATS
507 if (status & 0x0001) lp->stats.tx_deferred++;
508 #endif
509 lp->stats.collisions += (status >> 3) & 15;
510 lp->stats.tx_packets++;
511 }
512
513
514 dev_kfree_skb(lp->tx_skbuff[entry], FREE_WRITE);
515 dirty_tx++;
516 }
517
518 #ifndef final_version
519 if (lp->cur_tx - dirty_tx >= TX_RING_SIZE) {
520 printk("out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
521 dirty_tx, lp->cur_tx, lp->tx_full);
522 dirty_tx += TX_RING_SIZE;
523 }
524 #endif
525
526 if (lp->tx_full && dev->tbusy
527 && dirty_tx > lp->cur_tx - TX_RING_SIZE + 2) {
528
529 lp->tx_full = 0;
530 dev->tbusy = 0;
531 mark_bh(NET_BH);
532 }
533
534 lp->dirty_tx = dirty_tx;
535 }
536
537
538 if (csr5 & 0x8000) {
539 if (csr5 & 0x0008) lp->stats.tx_errors++;
540 if (csr5 & 0x0100) {
541 lp->stats.rx_errors++;
542 lp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
543 }
544 if (csr5 & 0x0800) {
545 printk("%s: Something Wicked happened! %8.8x.\n",
546 dev->name, csr5);
547
548 }
549 }
550 if (--boguscnt < 0) {
551 printk("%s: Too much work at interrupt, csr5=0x%8.8x.\n",
552 dev->name, csr5);
553
554 outl(0x0001ffff, ioaddr + CSR5);
555 break;
556 }
557 } while (1);
558
559 if (tulip_debug > 3)
560 printk("%s: exiting interrupt, csr5=%#4.4x.\n",
561 dev->name, inl(ioaddr + CSR5));
562
563
564 {
565 static int stopit = 10;
566 if (dev->start == 0 && --stopit < 0) {
567 printk("%s: Emergency stop, looping startup interrupt.\n",
568 dev->name);
569 free_irq(irq);
570 }
571 }
572
573 dev->interrupt = 0;
574 return;
575 }
576
577 static int
578 tulip_rx(struct device *dev)
579 {
580 struct tulip_private *lp = (struct tulip_private *)dev->priv;
581 int entry = lp->cur_rx % RX_RING_SIZE;
582 int i;
583
584 if (tulip_debug > 4)
585 printk(" In tulip_rx().\n");
586
587 while (lp->rx_ring[entry].status >= 0) {
588 int status = lp->rx_ring[entry].status;
589
590 if (tulip_debug > 4)
591 printk(" tulip_rx() status was %8.8x.\n", status);
592 if ((status & 0x0300) != 0x0300) {
593 printk("%s: Ethernet frame spanned multiple buffers, status %8.8x!\n",
594 dev->name, status);
595 } else if (status & 0x8000) {
596
597 lp->stats.rx_errors++;
598 if (status & 0x0890) lp->stats.rx_length_errors++;
599 if (status & 0x0004) lp->stats.rx_frame_errors++;
600 if (status & 0x0002) lp->stats.rx_crc_errors++;
601 if (status & 0x0001) lp->stats.rx_fifo_errors++;
602 } else {
603
604 short pkt_len = lp->rx_ring[entry].status >> 16;
605 struct sk_buff *skb;
606
607 skb = dev_alloc_skb(pkt_len+2);
608 if (skb == NULL) {
609 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
610
611
612 for (i=0; i < RX_RING_SIZE; i++)
613 if (lp->rx_ring[(entry+i) % RX_RING_SIZE].status < 0)
614 break;
615
616 if (i > RX_RING_SIZE -2) {
617 lp->stats.rx_dropped++;
618 lp->rx_ring[entry].status = 0x80000000;
619 lp->cur_rx++;
620 }
621 break;
622 }
623 skb->dev = dev;
624 skb_reserve(skb,2);
625 memcpy(skb_put(skb,pkt_len), lp->rx_ring[entry].buffer1, pkt_len);
626 skb->protocol=eth_type_trans(skb,dev);
627 netif_rx(skb);
628 lp->stats.rx_packets++;
629 }
630
631 lp->rx_ring[entry].status = 0x80000000;
632 entry = (++lp->cur_rx) % RX_RING_SIZE;
633 }
634
635 return 0;
636 }
637
638 static int
639 tulip_close(struct device *dev)
640 {
641 int ioaddr = dev->base_addr;
642 struct tulip_private *tp = (struct tulip_private *)dev->priv;
643
644 dev->start = 0;
645 dev->tbusy = 1;
646
647 if (tulip_debug > 1)
648 printk("%s: Shutting down ethercard, status was %2.2x.\n",
649 dev->name, inl(ioaddr + CSR5));
650
651
652 outl(0x00000000, ioaddr + CSR7);
653
654 outl(inl(ioaddr + CSR6) & ~0x2002, ioaddr + CSR6);
655
656 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
657
658 free_irq(dev->irq);
659 irq2dev_map[dev->irq] = 0;
660
661 MOD_DEC_USE_COUNT;
662 return 0;
663 }
664
665 static struct enet_statistics *
666 tulip_get_stats(struct device *dev)
667 {
668 struct tulip_private *tp = (struct tulip_private *)dev->priv;
669 short ioaddr = dev->base_addr;
670
671 tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
672
673 return &tp->stats;
674 }
675
676
677
678
679
680
681
682 static void
683 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
684 {
685 short ioaddr = dev->base_addr;
686 int csr6 = inl(ioaddr + CSR6) & ~0x00D5;
687
688 if (num_addrs > 15 || num_addrs == -2) {
689
690 outl(csr6 | 0x0080, ioaddr + CSR6);
691 } else if (num_addrs < 0) {
692 outl(csr6 | 0x00C0, ioaddr + CSR6);
693
694 printk("%s: Promiscuous mode enabled.\n", dev->name);
695 } else {
696 struct tulip_private *tp = (struct tulip_private *)dev->priv;
697 int *setup_frm = tp->setup_frame;
698 unsigned short *eaddrs = addrs;
699 int i;
700
701
702
703
704 outl(csr6 | 0x0000, ioaddr + CSR6);
705 for(i = 0; i < num_addrs; i++) {
706 *setup_frm++ = *eaddrs++;
707 *setup_frm++ = *eaddrs++;
708 *setup_frm++ = *eaddrs++;
709 }
710
711 eaddrs = (unsigned short *)dev->dev_addr;
712 do {
713 *setup_frm++ = eaddrs[0];
714 *setup_frm++ = eaddrs[1];
715 *setup_frm++ = eaddrs[2];
716 } while (++i < 16);
717
718
719 }
720 }
721
722 static int
723 set_mac_address(struct device *dev, void *addr)
724 {
725 int i;
726 if (dev->start)
727 return -EBUSY;
728 printk("%s: Setting MAC address to ", dev->name);
729 for (i = 0; i < 6; i++)
730 printk(" %2.2x", dev->dev_addr[i] = ((unsigned char *)addr)[i]);
731 printk(".\n");
732 return 0;
733 }
734
735 #ifdef MODULE
736 static char devicename[9] = { 0, };
737 static struct device dev_tulip = {
738 devicename,
739 0, 0, 0, 0,
740 0, 0,
741 0, 0, 0, NULL, tulip_probe
742 };
743
744 static int io = 0;
745 static int irq = 0;
746
747 int init_module(void)
748 {
749 printk("tulip: Sorry, modularization is not completed\n");
750 return -EIO;
751 #if 0
752 if (io == 0)
753 printk("tulip: You should not use auto-probing with insmod!\n");
754 dev_tulip.base_addr = io;
755 dev_tulip.irq = irq;
756 if (register_netdev(&dev_tulip) != 0) {
757 printk("tulip: register_netdev() returned non-zero.\n");
758 return -EIO;
759 }
760 return 0;
761 #endif
762 }
763
764 void
765 cleanup_module(void)
766 {
767 unregister_netdev(&dev_tulip);
768 }
769 #endif
770
771
772
773
774
775
776
777