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