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