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