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