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