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