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