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