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