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