This source file includes following definitions.
- el3_probe
- read_eeprom
- id_read_eeprom
- el3_open
- el3_start_xmit
- el3_interrupt
- el3_get_stats
- update_stats
- el3_rx
- set_multicast_list
- el3_close
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 static char *version = "3c509.c:pl13t 11/24/93 becker@super.org\n";
17
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/string.h>
22 #include <linux/interrupt.h>
23 #include <linux/ptrace.h>
24 #include <linux/errno.h>
25 #include <linux/in.h>
26 #include <linux/malloc.h>
27 #include <linux/ioport.h>
28 #include <asm/bitops.h>
29 #include <asm/io.h>
30
31 #include "dev.h"
32 #include "eth.h"
33 #include "skbuff.h"
34 #include "arp.h"
35
36 #ifndef port_read
37 #include "iow.h"
38 #endif
39
40
41 #define port_read_l(port,buf,nr) \
42 __asm__("cld;rep;insl": :"d" (port),"D" (buf),"c" (nr):"cx","di")
43 #define port_write_l(port,buf,nr) \
44 __asm__("cld;rep;outsl": :"d" (port),"S" (buf),"c" (nr):"cx","si")
45
46 #ifndef HAVE_ALLOC_SKB
47 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
48 #endif
49
50
51 #ifdef EL3_DEBUG
52 int el3_debug = EL3_DEBUG;
53 #else
54 int el3_debug = 2;
55 #endif
56
57
58
59
60
61 #define EL3_DATA 0x00
62 #define EL3_CMD 0x0e
63 #define EL3_STATUS 0x0e
64 #define ID_PORT 0x100
65 #define EEPROM_READ 0x80
66
67 #define EL3WINDOW(win_num) outw(0x0800+(win_num), ioaddr + EL3_CMD)
68
69
70 #define TX_FIFO 0x00
71 #define RX_FIFO 0x00
72 #define RX_STATUS 0x08
73 #define TX_STATUS 0x0B
74 #define TX_FREE 0x0C
75
76 #define WN4_MEDIA 0x0A
77 #define MEDIA_TP 0x00C0
78
79 struct el3_private {
80 struct enet_statistics stats;
81 };
82
83 static ushort id_read_eeprom(int index);
84 static ushort read_eeprom(short ioaddr, int index);
85 static int el3_open(struct device *dev);
86 static int el3_start_xmit(struct sk_buff *skb, struct device *dev);
87 static void el3_interrupt(int reg_ptr);
88 static void update_stats(int addr, struct device *dev);
89 static struct enet_statistics *el3_get_stats(struct device *dev);
90 static int el3_rx(struct device *dev);
91 static int el3_close(struct device *dev);
92 #ifdef HAVE_MULTICAST
93 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
94 #endif
95
96
97
98 int el3_probe(struct device *dev)
99 {
100 short lrs_state = 0xff, i;
101 ushort ioaddr, irq, if_port;
102 short *phys_addr = (short *)dev->dev_addr;
103 static int current_tag = 0;
104
105
106
107 if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0) {
108 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
109 if (inw(ioaddr) != 0x6d50)
110 continue;
111
112 irq = inw(ioaddr + 8) >> 12;
113 if_port = inw(ioaddr + 6)>>14;
114 for (i = 0; i < 3; i++)
115 phys_addr[i] = htons(read_eeprom(ioaddr, i));
116
117
118
119 read_eeprom(ioaddr, 7);
120
121
122 goto found;
123 }
124 }
125
126 #ifdef CONFIG_MCA
127 if (MCA_bus) {
128 mca_adaptor_select_mode(1);
129 for (i = 0; i < 8; i++)
130 if ((mca_adaptor_id(i) | 1) == 0x627c) {
131 ioaddr = mca_pos_base_addr(i);
132 irq = inw(ioaddr + 8) >> 12;
133 if_port = inw(ioaddr + 6)>>14;
134 for (i = 0; i < 3; i++)
135 phys_addr[i] = htons(read_eeprom(ioaddr, i));
136
137 mca_adaptor_select_mode(0);
138 goto found;
139 }
140 mca_adaptor_select_mode(0);
141
142 }
143 #endif
144
145
146 outb(0x00, ID_PORT);
147 outb(0x00, ID_PORT);
148 for(i = 0; i < 255; i++) {
149 outb(lrs_state, ID_PORT);
150 lrs_state <<= 1;
151 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
152 }
153
154
155 if (current_tag == 0)
156 outb(0xd0, ID_PORT);
157 else
158 outb(0xd8, ID_PORT);
159
160 if (id_read_eeprom(7) != 0x6d50) {
161 return -ENODEV;
162 }
163
164
165
166
167 for (i = 0; i < 3; i++) {
168 phys_addr[i] = htons(id_read_eeprom(i));
169 }
170
171 {
172 unsigned short iobase = id_read_eeprom(8);
173 if_port = iobase >> 14;
174 ioaddr = 0x200 + ((iobase & 0x1f) << 4);
175 }
176 irq = id_read_eeprom(9) >> 12;
177
178
179
180
181 if (dev->base_addr != 0
182 && dev->base_addr != (unsigned short)ioaddr) {
183 return -ENODEV;
184 }
185
186
187 outb(0xd0 + ++current_tag, ID_PORT);
188
189
190 outb(0xff, ID_PORT);
191
192 EL3WINDOW(0);
193 if (inw(ioaddr) != 0x6d50)
194 return -ENODEV;
195
196 found:
197 dev->base_addr = ioaddr;
198 dev->irq = irq;
199 dev->if_port = if_port;
200 snarf_region(dev->base_addr, 16);
201
202 {
203 char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
204 printk("%s: 3c509 at %#3.3x tag %d, %s port, address ",
205 dev->name, dev->base_addr, current_tag, if_names[dev->if_port]);
206 }
207
208
209 for (i = 0; i < 6; i++)
210 printk(" %2.2x", dev->dev_addr[i]);
211 printk(", IRQ %d.\n", dev->irq);
212
213
214 dev->priv = kmalloc(sizeof(struct el3_private), GFP_KERNEL);
215 memset(dev->priv, 0, sizeof(struct el3_private));
216
217 if (el3_debug > 0)
218 printk(version);
219
220
221 dev->open = &el3_open;
222 dev->hard_start_xmit = &el3_start_xmit;
223 dev->stop = &el3_close;
224 dev->get_stats = &el3_get_stats;
225 #ifdef HAVE_MULTICAST
226 dev->set_multicast_list = &set_multicast_list;
227 #endif
228
229
230 for (i = 0; i < DEV_NUMBUFFS; i++)
231 dev->buffs[i] = NULL;
232
233 dev->hard_header = eth_header;
234 dev->add_arp = eth_add_arp;
235 dev->queue_xmit = dev_queue_xmit;
236 dev->rebuild_header = eth_rebuild_header;
237 dev->type_trans = eth_type_trans;
238
239 dev->type = ARPHRD_ETHER;
240 dev->hard_header_len = ETH_HLEN;
241 dev->mtu = 1500;
242 dev->addr_len = ETH_ALEN;
243 for (i = 0; i < ETH_ALEN; i++) {
244 dev->broadcast[i]=0xff;
245 }
246
247
248 dev->flags = IFF_BROADCAST;
249 dev->family = AF_INET;
250 dev->pa_addr = 0;
251 dev->pa_brdaddr = 0;
252 dev->pa_mask = 0;
253 dev->pa_alen = sizeof(unsigned long);
254
255 return 0;
256 }
257
258
259
260
261 static ushort read_eeprom(short ioaddr, int index)
262 {
263 int timer;
264
265 outw(EEPROM_READ + index, ioaddr + 10);
266
267 for (timer = 0; timer < 162*4 + 400; timer++)
268 SLOW_DOWN_IO;
269 return inw(ioaddr + 12);
270 }
271
272
273 static ushort id_read_eeprom(int index)
274 {
275 int timer, bit, word = 0;
276
277
278
279 outb(EEPROM_READ + index, ID_PORT);
280
281
282 for (timer = 0; timer < 162*4 + 400; timer++)
283 SLOW_DOWN_IO;
284
285 for (bit = 15; bit >= 0; bit--)
286 word = (word << 1) + (inb(ID_PORT) & 0x01);
287
288 if (el3_debug > 3)
289 printk(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
290
291 return word;
292 }
293
294
295
296 static int
297 el3_open(struct device *dev)
298 {
299 int ioaddr = dev->base_addr;
300 int i;
301
302 if (request_irq(dev->irq, &el3_interrupt)) {
303 return -EAGAIN;
304 }
305
306 EL3WINDOW(0);
307 if (el3_debug > 3)
308 printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
309 dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
310
311
312 outw(0x0001, ioaddr + 4);
313
314 irq2dev_map[dev->irq] = dev;
315
316
317 outw((dev->irq << 12) | 0x0f00, ioaddr + 8);
318
319
320 EL3WINDOW(2);
321
322 for (i = 0; i < 6; i++)
323 outb(dev->dev_addr[i], ioaddr + i);
324
325 if (dev->if_port == 3)
326
327 outw(0x1000, ioaddr + EL3_CMD);
328 else if (dev->if_port == 0) {
329
330 EL3WINDOW(4);
331 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
332 }
333
334
335 EL3WINDOW(1);
336
337 outw(0x8005, ioaddr + EL3_CMD);
338 outw(0xA800, ioaddr + EL3_CMD);
339 outw(0x2000, ioaddr + EL3_CMD);
340 outw(0x4800, ioaddr + EL3_CMD);
341 outw(0x78ff, ioaddr + EL3_CMD);
342 dev->interrupt = 0;
343 dev->tbusy = 0;
344 dev->start = 1;
345 outw(0x7098, ioaddr + EL3_CMD);
346
347 if (el3_debug > 3)
348 printk("%s: Opened 3c509 IRQ %d status %4.4x.\n",
349 dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
350
351 return 0;
352 }
353
354 static int
355 el3_start_xmit(struct sk_buff *skb, struct device *dev)
356 {
357 struct el3_private *lp = (struct el3_private *)dev->priv;
358 int ioaddr = dev->base_addr;
359
360
361 if (dev->tbusy) {
362 int tickssofar = jiffies - dev->trans_start;
363 if (tickssofar < 10)
364 return 1;
365 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
366 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS));
367 dev->trans_start = jiffies;
368
369 outw(0x5800, ioaddr + EL3_CMD);
370 outw(0x4800, ioaddr + EL3_CMD);
371 dev->tbusy = 0;
372 }
373
374 if (skb == NULL) {
375 dev_tint(dev);
376 return 0;
377 }
378
379
380 if (!skb->arp && dev->rebuild_header(skb+1, dev)) {
381 skb->dev = dev;
382 arp_queue (skb);
383 return 0;
384 }
385 skb->arp=1;
386
387 if (skb->len <= 0)
388 return 0;
389
390 if (el3_debug > 4) {
391 printk("%s: el3_start_xmit(lenght = %d) called, status %4.4x.\n",
392 dev->name, skb->len, inw(ioaddr + EL3_STATUS));
393 }
394 #ifndef final_version
395 {
396 ushort status = inw(ioaddr + EL3_STATUS);
397 if (status & 0x0001
398 && inw(ioaddr + EL3_STATUS) & 1) {
399 printk("%s: Missed interrupt, status then %04x now %04x"
400 " Tx %2.2x Rx %4.4x.\n", dev->name, status,
401 inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
402 inw(ioaddr + RX_STATUS));
403 outw(0x7800, ioaddr + EL3_CMD);
404 outw(0x6899, ioaddr + EL3_CMD);
405 outw(0x78ff, ioaddr + EL3_CMD);
406 }
407 }
408 #endif
409
410
411 if (set_bit(0, (void*)&dev->tbusy) != 0)
412 printk("%s: Transmitter access conflict.\n", dev->name);
413 else {
414
415 outw(skb->len, ioaddr + TX_FIFO);
416 outw(0x00, ioaddr + TX_FIFO);
417
418 port_write_l(ioaddr + TX_FIFO, (void *)(skb+1), (skb->len + 3) >> 2);
419
420 dev->trans_start = jiffies;
421 if (inw(ioaddr + TX_FREE) > 1536) {
422 dev->tbusy=0;
423 } else
424
425 outw(0x9000 + 1536, ioaddr + EL3_CMD);
426 }
427
428 if (skb->free)
429 kfree_skb (skb, FREE_WRITE);
430
431
432 {
433 short tx_status;
434 int i = 4;
435
436 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
437 if (el3_debug > 5)
438 printk(" Tx status %4.4x.\n", tx_status);
439 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
440 if (tx_status & 0x30) outw(0x5800, ioaddr + EL3_CMD);
441 if (tx_status & 0x3C) outw(0x4800, ioaddr + EL3_CMD);
442 outb(0x00, ioaddr + TX_STATUS);
443 }
444 }
445 return 0;
446 }
447
448
449 static void
450 el3_interrupt(int reg_ptr)
451 {
452 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
453 struct device *dev = (struct device *)(irq2dev_map[irq]);
454 int ioaddr, status;
455 int i = 0;
456
457 if (dev == NULL) {
458 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
459 return;
460 }
461
462 if (dev->interrupt)
463 printk("%s: Re-entering the interrupt handler.\n", dev->name);
464 dev->interrupt = 1;
465
466 ioaddr = dev->base_addr;
467 status = inw(ioaddr + EL3_STATUS);
468
469 if (el3_debug > 4)
470 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
471
472 while ((status = inw(ioaddr + EL3_STATUS)) & 0x01) {
473
474 if (status & 0x10)
475 el3_rx(dev);
476
477 if (status & 0x08) {
478 if (el3_debug > 5)
479 printk(" TX room bit was handled.\n");
480
481 outw(0x6808, ioaddr + EL3_CMD);
482 dev->tbusy = 0;
483 mark_bh(INET_BH);
484 }
485 if (status & 0x80)
486 update_stats(ioaddr, dev);
487
488 if (++i > 10) {
489 printk("%s: Infinite loop in interrupt, status %4.4x.\n",
490 dev->name, status);
491 break;
492 }
493
494 outw(0x6899, ioaddr + EL3_CMD);
495 }
496
497 if (el3_debug > 4) {
498 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
499 inw(ioaddr + EL3_STATUS));
500 }
501
502 dev->interrupt = 0;
503 return;
504 }
505
506
507 static struct enet_statistics *
508 el3_get_stats(struct device *dev)
509 {
510 struct el3_private *lp = (struct el3_private *)dev->priv;
511
512 sti();
513 update_stats(dev->base_addr, dev);
514 cli();
515 return &lp->stats;
516 }
517
518
519
520
521
522
523 static void update_stats(int ioaddr, struct device *dev)
524 {
525 struct el3_private *lp = (struct el3_private *)dev->priv;
526
527 if (el3_debug > 5)
528 printk(" Updating the statistics.\n");
529
530 outw(0xB000, ioaddr + EL3_CMD);
531
532 EL3WINDOW(6);
533 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
534 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
535 inb(ioaddr + 2);
536 lp->stats.collisions += inb(ioaddr + 3);
537 lp->stats.tx_window_errors += inb(ioaddr + 4);
538 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
539 lp->stats.tx_packets += inb(ioaddr + 6);
540 lp->stats.rx_packets += inb(ioaddr + 7);
541 inb(ioaddr + 8);
542 inw(ioaddr + 10);
543 inw(ioaddr + 12);
544
545
546 EL3WINDOW(1);
547 outw(0xA800, ioaddr + EL3_CMD);
548 return;
549 }
550
551 static int
552 el3_rx(struct device *dev)
553 {
554 struct el3_private *lp = (struct el3_private *)dev->priv;
555 int ioaddr = dev->base_addr;
556 short rx_status;
557
558 if (el3_debug > 5)
559 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
560 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
561 while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
562 if (rx_status & 0x4000) {
563 short error = rx_status & 0x3C00;
564 lp->stats.rx_errors++;
565 switch (error) {
566 case 0x2000: lp->stats.rx_over_errors++; break;
567 case 0x2C00: lp->stats.rx_length_errors++; break;
568 case 0x3400: lp->stats.rx_crc_errors++; break;
569 case 0x2400: lp->stats.rx_length_errors++; break;
570 case 0x3000: lp->stats.rx_frame_errors++; break;
571 case 0x0800: lp->stats.rx_frame_errors++; break;
572 }
573 }
574 if ( (! (rx_status & 0x4000))
575 || ! (rx_status & 0x2000)) {
576 short pkt_len = rx_status & 0x7ff;
577 int sksize = sizeof(struct sk_buff) + pkt_len + 3;
578 struct sk_buff *skb;
579
580 skb = alloc_skb(sksize, GFP_ATOMIC);
581 if (el3_debug > 4)
582 printk(" Receiving packet size %d status %4.4x.\n",
583 pkt_len, rx_status);
584 if (skb != NULL) {
585 skb->mem_len = sksize;
586 skb->mem_addr = skb;
587 skb->len = pkt_len;
588 skb->dev = dev;
589
590
591 port_read_l(ioaddr+RX_FIFO, (void *)(skb+1),
592 (pkt_len + 3) >> 2);
593
594 #ifdef HAVE_NETIF_RX
595 netif_rx(skb);
596 outw(0x4000, ioaddr + EL3_CMD);
597 continue;
598 #else
599 skb->lock = 0;
600 if (dev_rint((unsigned char *)skb, pkt_len,
601 IN_SKBUFF,dev)== 0){
602 if (el3_debug > 6)
603 printk(" dev_rint() happy, status %4.4x.\n",
604 inb(ioaddr + EL3_STATUS));
605 outw(0x4000, ioaddr + EL3_CMD);
606 while (inw(ioaddr + EL3_STATUS) & 0x1000)
607 printk(" Waiting for 3c509 to discard packet, status %x.\n",
608 inw(ioaddr + EL3_STATUS) );
609 if (el3_debug > 6)
610 printk(" discarded packet, status %4.4x.\n",
611 inb(ioaddr + EL3_STATUS));
612 continue;
613 } else {
614 printk("%s: receive buffers full.\n", dev->name);
615 kfree_s(skb, sksize);
616 }
617 #endif
618 } else if (el3_debug)
619 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
620 dev->name, sksize);
621 }
622 lp->stats.rx_dropped++;
623 outw(0x4000, ioaddr + EL3_CMD);
624 while (inw(ioaddr + EL3_STATUS) & 0x1000)
625 printk(" Waiting for 3c509 to discard packet, status %x.\n",
626 inw(ioaddr + EL3_STATUS) );
627 }
628
629 if (el3_debug > 5)
630 printk(" Exiting rx_packet(), status %4.4x, rx_status %4.4x.\n",
631 inw(ioaddr+EL3_STATUS), inw(ioaddr+8));
632
633 return 0;
634 }
635
636 #ifdef HAVE_MULTICAST
637
638
639
640
641
642
643 static void
644 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
645 {
646 short ioaddr = dev->base_addr;
647 if (num_addrs > 0) {
648 outw(0x8007, ioaddr + EL3_CMD);
649 } else if (num_addrs < 0) {
650 outw(0x8008, ioaddr + EL3_CMD);
651 } else
652 outw(0x8005, ioaddr + EL3_CMD);
653 }
654 #endif
655
656 static int
657 el3_close(struct device *dev)
658 {
659 int ioaddr = dev->base_addr;
660
661 if (el3_debug > 2)
662 printk("%s: Shutting down ethercard.\n", dev->name);
663
664 dev->tbusy = 1;
665 dev->start = 0;
666
667
668 outw(0xB000, ioaddr + EL3_CMD);
669
670
671 outw(0x1800, ioaddr + EL3_CMD);
672 outw(0x5000, ioaddr + EL3_CMD);
673
674 if (dev->if_port == 3)
675
676 outw(0xb800, ioaddr + EL3_CMD);
677 else if (dev->if_port == 0) {
678
679 EL3WINDOW(4);
680 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
681 }
682
683 free_irq(dev->irq);
684
685 EL3WINDOW(0);
686
687 outw(0x0f00, ioaddr + 8);
688
689
690 irq2dev_map[dev->irq] = 0;
691
692 update_stats(ioaddr, dev);
693 return 0;
694 }
695
696
697
698
699
700
701
702
703