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