This source file includes following definitions.
- el1_probe
- el1_probe1
- el_open
- el_start_xmit
- el_interrupt
- el_receive
- el_reset
- el1_close
- el1_get_stats
- set_multicast_list
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 static char *version =
79 "3c501.c: 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov).\n";
80
81
82
83
84
85
86 #include <linux/config.h>
87 #ifdef MODULE
88 #include <linux/module.h>
89 #include <linux/version.h>
90 #else
91 #define MOD_INC_USE_COUNT
92 #define MOD_DEC_USE_COUNT
93 #endif
94
95 #include <linux/kernel.h>
96 #include <linux/sched.h>
97 #include <linux/ptrace.h>
98 #include <linux/fcntl.h>
99 #include <linux/ioport.h>
100 #include <linux/interrupt.h>
101 #include <linux/malloc.h>
102 #include <linux/string.h>
103 #include <linux/ioport.h>
104 #include <linux/errno.h>
105
106 #include <asm/bitops.h>
107 #include <asm/io.h>
108
109 #include <linux/netdevice.h>
110 #include <linux/etherdevice.h>
111 #include <linux/skbuff.h>
112
113
114
115 static unsigned int netcard_portlist[] =
116 { 0x280, 0x300, 0};
117
118
119
120 int el1_probe(struct device *dev);
121 static int el1_probe1(struct device *dev, int ioaddr);
122 static int el_open(struct device *dev);
123 static int el_start_xmit(struct sk_buff *skb, struct device *dev);
124 static void el_interrupt(int irq, struct pt_regs *regs);
125 static void el_receive(struct device *dev);
126 static void el_reset(struct device *dev);
127 static int el1_close(struct device *dev);
128 static struct enet_statistics *el1_get_stats(struct device *dev);
129 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
130
131 #define EL1_IO_EXTENT 16
132
133 #ifndef EL_DEBUG
134 #define EL_DEBUG 2
135 #endif
136 static int el_debug = EL_DEBUG;
137
138
139 struct net_local {
140 struct enet_statistics stats;
141 int tx_pkt_start;
142 int collisions;
143 int loading;
144 };
145
146
147 #define RX_STATUS (ioaddr + 0x06)
148 #define RX_CMD RX_STATUS
149 #define TX_STATUS (ioaddr + 0x07)
150 #define TX_CMD TX_STATUS
151 #define GP_LOW (ioaddr + 0x08)
152 #define GP_HIGH (ioaddr + 0x09)
153 #define RX_BUF_CLR (ioaddr + 0x0A)
154 #define RX_LOW (ioaddr + 0x0A)
155 #define RX_HIGH (ioaddr + 0x0B)
156 #define SAPROM (ioaddr + 0x0C)
157 #define AX_STATUS (ioaddr + 0x0E)
158 #define AX_CMD AX_STATUS
159 #define DATAPORT (ioaddr + 0x0F)
160 #define TX_RDY 0x08
161
162 #define EL1_DATAPTR 0x08
163 #define EL1_RXPTR 0x0A
164 #define EL1_SAPROM 0x0C
165 #define EL1_DATAPORT 0x0f
166
167
168 #define AX_OFF 0x00
169 #define AX_SYS 0x40
170 #define AX_XMIT 0x44
171 #define AX_RX 0x48
172 #define AX_LOOP 0x0C
173 #define AX_RESET 0x80
174
175
176
177 #define RX_NORM 0xA8
178 #define RX_PROM 0x68
179 #define RX_MULT 0xE8
180 #define TX_NORM 0x0A
181
182
183 #define TX_COLLISION 0x02
184 #define TX_16COLLISIONS 0x04
185 #define TX_READY 0x08
186
187 #define RX_RUNT 0x08
188 #define RX_MISSED 0x01
189 #define RX_GOOD 0x30
190
191
192
193 #ifdef HAVE_DEVLIST
194 struct netdev_entry el1_drv =
195 {"3c501", el1_probe1, EL1_IO_EXTENT, netcard_portlist};
196 #else
197 int
198 el1_probe(struct device *dev)
199 {
200 int i;
201 int base_addr = dev ? dev->base_addr : 0;
202
203 if (base_addr > 0x1ff)
204 return el1_probe1(dev, base_addr);
205 else if (base_addr != 0)
206 return ENXIO;
207
208 for (i = 0; netcard_portlist[i]; i++) {
209 int ioaddr = netcard_portlist[i];
210 if (check_region(ioaddr, EL1_IO_EXTENT))
211 continue;
212 if (el1_probe1(dev, ioaddr) == 0)
213 return 0;
214 }
215
216 return ENODEV;
217 }
218 #endif
219
220
221 static int
222 el1_probe1(struct device *dev, int ioaddr)
223 {
224 #ifndef MODULE
225
226 char *mname;
227 unsigned char station_addr[6];
228 int autoirq = 0;
229 int i;
230
231
232 for (i = 0; i < 6; i++) {
233 outw(i, ioaddr + EL1_DATAPTR);
234 station_addr[i] = inb(ioaddr + EL1_SAPROM);
235 }
236
237
238 if (station_addr[0] == 0x02 && station_addr[1] == 0x60
239 && station_addr[2] == 0x8c) {
240 mname = "3c501";
241 } else if (station_addr[0] == 0x00 && station_addr[1] == 0x80
242 && station_addr[2] == 0xC8) {
243 mname = "NP943";
244 } else
245 return ENODEV;
246
247
248 request_region(ioaddr, EL1_IO_EXTENT,"3c501");
249
250
251
252 if (dev->irq < 2) {
253
254 autoirq_setup(2);
255
256 inb(RX_STATUS);
257 inb(TX_STATUS);
258 outb(AX_LOOP + 1, AX_CMD);
259
260 outb(0x00, AX_CMD);
261
262 autoirq = autoirq_report(1);
263
264 if (autoirq == 0) {
265 printk("%s probe at %#x failed to detect IRQ line.\n",
266 mname, ioaddr);
267 return EAGAIN;
268 }
269 }
270
271 outb(AX_RESET+AX_LOOP, AX_CMD);
272
273 dev->base_addr = ioaddr;
274 memcpy(dev->dev_addr, station_addr, ETH_ALEN);
275 if (dev->mem_start & 0xf)
276 el_debug = dev->mem_start & 0x7;
277 if (autoirq)
278 dev->irq = autoirq;
279
280 printk("%s: %s EtherLink at %#lx, using %sIRQ %d.\n",
281 dev->name, mname, dev->base_addr,
282 autoirq ? "auto":"assigned ", dev->irq);
283
284 #ifdef CONFIG_IP_MULTICAST
285 printk("WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n");
286 #endif
287
288 if (el_debug)
289 printk("%s", version);
290
291
292 if (dev->priv == NULL)
293 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
294 memset(dev->priv, 0, sizeof(struct net_local));
295
296
297 dev->open = &el_open;
298 dev->hard_start_xmit = &el_start_xmit;
299 dev->stop = &el1_close;
300 dev->get_stats = &el1_get_stats;
301 dev->set_multicast_list = &set_multicast_list;
302
303 ether_setup(dev);
304
305 #endif
306 return 0;
307 }
308
309
310 static int
311 el_open(struct device *dev)
312 {
313 int ioaddr = dev->base_addr;
314
315 if (el_debug > 2)
316 printk("%s: Doing el_open()...", dev->name);
317
318 if (request_irq(dev->irq, &el_interrupt, 0, "3c501")) {
319 return -EAGAIN;
320 }
321 irq2dev_map[dev->irq] = dev;
322
323 el_reset(dev);
324
325 dev->start = 1;
326
327 outb(AX_RX, AX_CMD);
328 MOD_INC_USE_COUNT;
329 return 0;
330 }
331
332 static int
333 el_start_xmit(struct sk_buff *skb, struct device *dev)
334 {
335 struct net_local *lp = (struct net_local *)dev->priv;
336 int ioaddr = dev->base_addr;
337 unsigned long flags;
338
339 if (dev->tbusy) {
340 if (jiffies - dev->trans_start < 20) {
341 if (el_debug > 2)
342 printk(" transmitter busy, deferred.\n");
343 return 1;
344 }
345 if (el_debug)
346 printk ("%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
347 dev->name, inb(TX_STATUS), inb(AX_STATUS), inb(RX_STATUS));
348 lp->stats.tx_errors++;
349 outb(TX_NORM, TX_CMD);
350 outb(RX_NORM, RX_CMD);
351 outb(AX_OFF, AX_CMD);
352 outb(AX_RX, AX_CMD);
353 dev->tbusy = 0;
354 dev->trans_start = jiffies;
355 }
356
357 if (skb == NULL) {
358 dev_tint(dev);
359 return 0;
360 }
361
362 save_flags(flags);
363
364
365
366 cli();
367
368 if (set_bit(0, (void*)&dev->tbusy) != 0)
369 {
370 restore_flags(flags);
371 printk("%s: Transmitter access conflict.\n", dev->name);
372 }
373 else {
374 int gp_start = 0x800 - (ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN);
375 unsigned char *buf = skb->data;
376
377 load_it_again_sam:
378 lp->tx_pkt_start = gp_start;
379 lp->collisions = 0;
380
381
382
383
384
385 outb(AX_SYS, AX_CMD);
386 inb(RX_STATUS);
387 inb(TX_STATUS);
388
389 lp->loading=1;
390
391
392
393
394
395 restore_flags(flags);
396 outw(0x00, RX_BUF_CLR);
397 outw(gp_start, GP_LOW);
398 outsb(DATAPORT,buf,skb->len);
399 outw(gp_start, GP_LOW);
400 if(lp->loading==2)
401 {
402 if(el_debug>2)
403 printk("%s: burped during tx load.\n", dev->name);
404 goto load_it_again_sam;
405 }
406 outb(AX_XMIT, AX_CMD);
407 dev->trans_start = jiffies;
408 }
409
410 if (el_debug > 2)
411 printk(" queued xmit.\n");
412 dev_kfree_skb (skb, FREE_WRITE);
413 return 0;
414 }
415
416
417
418
419 static void
420 el_interrupt(int irq, struct pt_regs *regs)
421 {
422 struct device *dev = (struct device *)(irq2dev_map[irq]);
423 struct net_local *lp;
424 int ioaddr;
425 int axsr;
426
427 if (dev == NULL || dev->irq != irq) {
428 printk ("3c501 driver: irq %d for unknown device.\n", irq);
429 return;
430 }
431
432 ioaddr = dev->base_addr;
433 lp = (struct net_local *)dev->priv;
434 axsr = inb(AX_STATUS);
435
436 if (el_debug > 3)
437 printk("%s: el_interrupt() aux=%#02x", dev->name, axsr);
438 if (dev->interrupt)
439 printk("%s: Reentering the interrupt driver!\n", dev->name);
440 dev->interrupt = 1;
441
442 lp->loading=2;
443
444 if (dev->tbusy) {
445
446
447
448
449
450 int txsr = inb(TX_STATUS);
451
452 if (el_debug > 6)
453 printk(" txsr=%02x gp=%04x rp=%04x", txsr, inw(GP_LOW),
454 inw(RX_LOW));
455
456 if ((axsr & 0x80) && (txsr & TX_READY) == 0) {
457
458
459
460
461 printk("%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x"
462 " gp=%03x rp=%03x.\n", dev->name, txsr, axsr,
463 inw(ioaddr + EL1_DATAPTR), inw(ioaddr + EL1_RXPTR));
464 dev->tbusy = 0;
465 mark_bh(NET_BH);
466 } else if (txsr & TX_16COLLISIONS) {
467
468
469
470 if (el_debug)
471 printk("%s: Transmit failed 16 times, ethernet jammed?\n",
472 dev->name);
473 outb(AX_SYS, AX_CMD);
474 lp->stats.tx_aborted_errors++;
475 } else if (txsr & TX_COLLISION) {
476 if (el_debug > 6)
477 printk(" retransmitting after a collision.\n");
478
479
480
481 outb(AX_SYS, AX_CMD);
482 outw(lp->tx_pkt_start, GP_LOW);
483 outb(AX_XMIT, AX_CMD);
484 lp->stats.collisions++;
485 dev->interrupt = 0;
486 return;
487 } else {
488
489
490
491 lp->stats.tx_packets++;
492 if (el_debug > 6)
493 printk(" Tx succeeded %s\n",
494 (txsr & TX_RDY) ? "." : "but tx is busy!");
495
496
497
498 dev->tbusy = 0;
499 mark_bh(NET_BH);
500 }
501 } else {
502
503
504
505
506
507 int rxsr = inb(RX_STATUS);
508 if (el_debug > 5)
509 printk(" rxsr=%02x txsr=%02x rp=%04x", rxsr, inb(TX_STATUS),
510 inw(RX_LOW));
511
512
513
514
515 if (rxsr & RX_MISSED)
516 lp->stats.rx_missed_errors++;
517 if (rxsr & RX_RUNT) {
518 lp->stats.rx_length_errors++;
519 if (el_debug > 5) printk(" runt.\n");
520 } else if (rxsr & RX_GOOD) {
521
522
523
524 el_receive(dev);
525 } else {
526 if (el_debug > 2)
527 printk("%s: No packet seen, rxsr=%02x **resetting 3c501***\n",
528 dev->name, rxsr);
529 el_reset(dev);
530 }
531 if (el_debug > 3)
532 printk(".\n");
533 }
534
535
536
537
538 outb(AX_RX, AX_CMD);
539 outw(0x00, RX_BUF_CLR);
540 inb(RX_STATUS);
541 inb(TX_STATUS);
542 dev->interrupt = 0;
543 return;
544 }
545
546
547
548
549 static void
550 el_receive(struct device *dev)
551 {
552 struct net_local *lp = (struct net_local *)dev->priv;
553 int ioaddr = dev->base_addr;
554 int pkt_len;
555 struct sk_buff *skb;
556
557 pkt_len = inw(RX_LOW);
558
559 if (el_debug > 4)
560 printk(" el_receive %d.\n", pkt_len);
561
562 if ((pkt_len < 60) || (pkt_len > 1536)) {
563 if (el_debug)
564 printk("%s: bogus packet, length=%d\n", dev->name, pkt_len);
565 lp->stats.rx_over_errors++;
566 return;
567 }
568
569
570
571
572
573 outb(AX_SYS, AX_CMD);
574
575 skb = dev_alloc_skb(pkt_len+2);
576
577
578
579 outw(0x00, GP_LOW);
580 if (skb == NULL) {
581 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
582 lp->stats.rx_dropped++;
583 return;
584 } else {
585 skb_reserve(skb,2);
586 skb->dev = dev;
587
588
589
590
591
592
593
594 insb(DATAPORT, skb_put(skb,pkt_len), pkt_len);
595 skb->protocol=eth_type_trans(skb,dev);
596 netif_rx(skb);
597 lp->stats.rx_packets++;
598 }
599 return;
600 }
601
602 static void
603 el_reset(struct device *dev)
604 {
605 int ioaddr = dev->base_addr;
606
607 if (el_debug> 2)
608 printk("3c501 reset...");
609 outb(AX_RESET, AX_CMD);
610 outb(AX_LOOP, AX_CMD);
611 {
612 int i;
613 for (i = 0; i < 6; i++)
614 outb(dev->dev_addr[i], ioaddr + i);
615 }
616
617 outw(0, RX_BUF_CLR);
618 cli();
619 outb(TX_NORM, TX_CMD);
620 outb(RX_NORM, RX_CMD);
621 inb(RX_STATUS);
622 inb(TX_STATUS);
623 dev->interrupt = 0;
624 dev->tbusy = 0;
625 sti();
626 }
627
628 static int
629 el1_close(struct device *dev)
630 {
631 int ioaddr = dev->base_addr;
632
633 if (el_debug > 2)
634 printk("%s: Shutting down ethercard at %#x.\n", dev->name, ioaddr);
635
636 dev->tbusy = 1;
637 dev->start = 0;
638
639
640 free_irq(dev->irq);
641 outb(AX_RESET, AX_CMD);
642 irq2dev_map[dev->irq] = 0;
643
644 MOD_DEC_USE_COUNT;
645 return 0;
646 }
647
648 static struct enet_statistics *
649 el1_get_stats(struct device *dev)
650 {
651 struct net_local *lp = (struct net_local *)dev->priv;
652 return &lp->stats;
653 }
654
655
656
657
658
659
660
661 static void
662 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
663 {
664 int ioaddr = dev->base_addr;
665
666 if (num_addrs > 0) {
667 outb(RX_MULT, RX_CMD);
668 inb(RX_STATUS);
669 } else if (num_addrs < 0) {
670 outb(RX_PROM, RX_CMD);
671 inb(RX_STATUS);
672 } else {
673 outb(RX_NORM, RX_CMD);
674 inb(RX_STATUS);
675 }
676 }
677 #ifdef MODULE
678 char kernel_version[] = UTS_RELEASE;
679 static struct device dev_3c501 = {
680 " " ,
681 0, 0, 0, 0,
682 0x280, 5,
683 0, 0, 0, NULL, el1_probe };
684
685 int io=0x280;
686 int irq=5;
687
688 int
689 init_module(void)
690 {
691 dev_3c501.irq=irq;
692 dev_3c501.base_addr=io;
693 if (register_netdev(&dev_3c501) != 0)
694 return -EIO;
695 return 0;
696 }
697
698 void
699 cleanup_module(void)
700 {
701
702 unregister_netdev(&dev_3c501);
703
704
705 kfree(dev_3c501.priv);
706 dev_3c501.priv = NULL;
707
708
709 release_region(dev_3c501.base_addr, EL1_IO_EXTENT);
710 }
711 #endif
712
713
714
715
716
717
718