This source file includes following definitions.
- express_probe
- eexp_open
- eexp_close
- eexp_stats
- eexp_xmit
- eexp_irq
- eexp_hw_rx
- eexp_hw_tx
- eexp_hw_probe
- eexp_hw_readeeprom
- eexp_hw_lasttxstat
- eexp_hw_txrestart
- eexp_hw_txinit
- eexp_hw_rxinit
- eexp_hw_init586
- eexp_hw_ASICrst
- eexp_set_multicast
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 static char version[] =
88 "eexpress.c: v0.10 04-May-95 John Sullivan <js10039@cam.ac.uk>\n"
89 " v0.13 10-Apr-96 Philip Blundell <phil@tazenda.demon.co.uk>\n";
90
91 #include <linux/module.h>
92
93 #include <linux/kernel.h>
94 #include <linux/sched.h>
95 #include <linux/types.h>
96 #include <linux/fcntl.h>
97 #include <linux/interrupt.h>
98 #include <linux/ptrace.h>
99 #include <linux/ioport.h>
100 #include <linux/string.h>
101 #include <linux/in.h>
102 #include <asm/system.h>
103 #include <asm/bitops.h>
104 #include <asm/io.h>
105 #include <asm/dma.h>
106 #include <linux/errno.h>
107
108 #include <linux/netdevice.h>
109 #include <linux/etherdevice.h>
110 #include <linux/skbuff.h>
111 #include <linux/malloc.h>
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 #ifndef NET_DEBUG
129 #define NET_DEBUG 4
130 #endif
131 static unsigned int net_debug = NET_DEBUG;
132
133 #undef F_DEB
134
135 #include "eth82586.h"
136
137 #define PRIV(x) ((struct net_local *)(x)->priv)
138 #define EEXP_IO_EXTENT 16
139
140
141
142
143
144 struct net_local
145 {
146 struct enet_statistics stats;
147 unsigned long init_time;
148 unsigned short rx_first;
149 unsigned short rx_last;
150 unsigned short tx_head;
151 unsigned short tx_reap;
152 unsigned short tx_tail;
153 unsigned short tx_link;
154 unsigned short last_tx_restart;
155 unsigned char started;
156 unsigned char promisc;
157 unsigned short rx_buf_start;
158 unsigned short rx_buf_end;
159 unsigned short num_tx_bufs;
160 unsigned short num_rx_bufs;
161 };
162
163 unsigned short start_code[] = {
164 0x0000,
165 0x0000,0x0000,
166 0x0000,0x0000,
167
168 0x0001,
169 0x0008,0x0000,0x0000,
170
171 0x0000,0x0000,
172 0x0000,0x0000,
173 0x0000,0x0000,
174 0x0000,0x0000,
175
176 0x0000,0x0000,
177 0x0000,0x0000,
178
179 0x0000,Cmd_Config,
180 0x0032,
181 0x080c,
182 0x2e40,
183
184 0x6000,
185 0xf200,
186 0x0000,
187 0x003c,
188
189 0x0000,Cmd_INT|Cmd_SetAddr,
190 0x003e,
191 0x0000,0x0000,0x0000,
192 0x0000,Cmd_END|Cmd_Nop,
193 0x003e,
194
195 0x0000
196
197 };
198
199 #define CONF_LINK 0x0020
200 #define CONF_HW_ADDR 0x0038
201
202
203 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
204
205
206
207
208
209 extern int express_probe(struct device *dev);
210 static int eexp_open (struct device *dev);
211 static int eexp_close(struct device *dev);
212 static struct enet_statistics *eexp_stats(struct device *dev);
213 static int eexp_xmit (struct sk_buff *buf, struct device *dev);
214
215 static void eexp_irq (int irq, void *dev_addr, struct pt_regs *regs);
216 static void eexp_set_multicast(struct device *dev);
217
218
219
220
221
222 static void eexp_hw_rx (struct device *dev);
223 static void eexp_hw_tx (struct device *dev, unsigned short *buf, unsigned short len);
224 static int eexp_hw_probe (struct device *dev,unsigned short ioaddr);
225 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location);
226
227 static unsigned short eexp_hw_lasttxstat(struct device *dev);
228 static void eexp_hw_txrestart (struct device *dev);
229
230 static void eexp_hw_txinit (struct device *dev);
231 static void eexp_hw_rxinit (struct device *dev);
232
233 static void eexp_hw_init586 (struct device *dev);
234 static void eexp_hw_ASICrst (struct device *dev);
235
236
237
238
239
240
241
242
243
244 int express_probe(struct device *dev)
245 {
246 unsigned short *port,ports[] = { 0x0300,0x0270,0x0320,0x0340,0 };
247 unsigned short ioaddr = dev->base_addr;
248
249 if (ioaddr&0xfe00)
250 return eexp_hw_probe(dev,ioaddr);
251 else if (ioaddr)
252 return ENXIO;
253
254 for ( port=&ports[0] ; *port ; port++ )
255 {
256 unsigned short sum = 0;
257 int i;
258 for ( i=0 ; i<4 ; i++ )
259 {
260 unsigned short t;
261 t = inb(*port + ID_PORT);
262 sum |= (t>>4) << ((t & 0x03)<<2);
263 }
264 if (sum==0xbaba && !eexp_hw_probe(dev,*port))
265 return 0;
266 }
267 return ENODEV;
268 }
269
270
271
272
273
274 static int eexp_open(struct device *dev)
275 {
276 int irq = dev->irq;
277 unsigned short ioaddr = dev->base_addr;
278
279 #if NET_DEBUG > 6
280 printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
281 #endif
282
283 if (!irq || !irqrmap[irq])
284 return -ENXIO;
285
286 if (irq2dev_map[irq] ||
287
288 ((irq2dev_map[irq]=dev),0) ||
289 request_irq(irq,&eexp_irq,0,"eexpress",NULL))
290 return -EAGAIN;
291
292 request_region(ioaddr, EEXP_IO_EXTENT, "eexpress");
293 dev->tbusy = 0;
294 dev->interrupt = 0;
295 eexp_hw_init586(dev);
296 dev->start = 1;
297 MOD_INC_USE_COUNT;
298 #if NET_DEBUG > 6
299 printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
300 #endif
301 return 0;
302 }
303
304
305
306
307
308 static int eexp_close(struct device *dev)
309 {
310 unsigned short ioaddr = dev->base_addr;
311 int irq = dev->irq;
312
313 dev->tbusy = 1;
314 dev->start = 0;
315
316 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
317 PRIV(dev)->started = 0;
318 outw(SCB_CUsuspend|SCB_RUsuspend,ioaddr+SCB_CMD);
319 outb(0,ioaddr+SIGNAL_CA);
320 free_irq(irq,NULL);
321 irq2dev_map[irq] = NULL;
322 outb(i586_RST,ioaddr+EEPROM_Ctrl);
323 release_region(ioaddr,16);
324 MOD_DEC_USE_COUNT;
325 return 0;
326 }
327
328
329
330
331
332 static struct enet_statistics *eexp_stats(struct device *dev)
333 {
334 struct net_local *lp = (struct net_local *)dev->priv;
335
336
337
338
339
340
341
342 return &lp->stats;
343 }
344
345
346
347
348
349
350 static int eexp_xmit(struct sk_buff *buf, struct device *dev)
351 {
352 struct net_local *lp = (struct net_local *)dev->priv;
353 unsigned short ioaddr = dev->base_addr;
354
355 #if NET_DEBUG > 6
356 printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
357 #endif
358
359 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
360 if (dev->tbusy)
361 {
362
363
364
365
366 if (test_bit(0,(void *)&PRIV(dev)->started))
367 {
368 if ((jiffies - dev->trans_start)>5)
369 {
370 if (lp->tx_link==lp->last_tx_restart)
371 {
372 unsigned short boguscount=200,rsst;
373 printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
374 dev->name,inw(ioaddr+SCB_STATUS));
375 eexp_hw_txinit(dev);
376 lp->last_tx_restart = 0;
377 outw(lp->tx_link,ioaddr+SCB_CBL);
378 outw(0,ioaddr+SCB_STATUS);
379 outw(SCB_CUstart,ioaddr+SCB_CMD);
380 outb(0,ioaddr+SIGNAL_CA);
381 while (!SCB_complete(rsst=inw(ioaddr+SCB_STATUS)))
382 {
383 if (!--boguscount)
384 {
385 boguscount=200;
386 printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
387 dev->name,rsst);
388 outw(lp->tx_link,ioaddr+SCB_CBL);
389 outw(0,ioaddr+SCB_STATUS);
390 outw(SCB_CUstart,ioaddr+SCB_CMD);
391 outb(0,ioaddr+SIGNAL_CA);
392 }
393 }
394 dev->tbusy = 0;
395 mark_bh(NET_BH);
396 }
397 else
398 {
399 unsigned short status = inw(ioaddr+SCB_STATUS);
400 if (SCB_CUdead(status))
401 {
402 unsigned short txstatus = eexp_hw_lasttxstat(dev);
403 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
404 dev->name, status, txstatus);
405 eexp_hw_txrestart(dev);
406 }
407 else
408 {
409 unsigned short txstatus = eexp_hw_lasttxstat(dev);
410 if (dev->tbusy && !txstatus)
411 {
412 printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
413 dev->name,status,txstatus);
414 eexp_hw_init586(dev);
415 dev->tbusy = 0;
416 mark_bh(NET_BH);
417 }
418 }
419 }
420 }
421 }
422 else
423 {
424 if ((jiffies-lp->init_time)>10)
425 {
426 unsigned short status = inw(ioaddr+SCB_STATUS);
427 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
428 dev->name, status);
429 eexp_hw_init586(dev);
430 dev->tbusy = 0;
431 mark_bh(NET_BH);
432 }
433 }
434 }
435
436 if (buf==NULL)
437 {
438 unsigned short status = inw(ioaddr+SCB_STATUS);
439 unsigned short txstatus = eexp_hw_lasttxstat(dev);
440 if (SCB_CUdead(status))
441 {
442 printk(KERN_WARNING "%s: CU has died! status %04x %04x, attempting to restart...\n",
443 dev->name, status, txstatus);
444 lp->stats.tx_errors++;
445 eexp_hw_txrestart(dev);
446 }
447 dev_tint(dev);
448 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
449 return 0;
450 }
451
452 if (set_bit(0,(void *)&dev->tbusy))
453 {
454 lp->stats.tx_dropped++;
455 }
456 else
457 {
458 unsigned short length = (ETH_ZLEN < buf->len) ? buf->len : ETH_ZLEN;
459 unsigned short *data = (unsigned short *)buf->data;
460
461 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
462 eexp_hw_tx(dev,data,length);
463 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
464 }
465 dev_kfree_skb(buf, FREE_WRITE);
466 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
467 return 0;
468 }
469
470
471
472
473
474
475
476
477 static void eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
478 {
479 struct device *dev = irq2dev_map[irq];
480 struct net_local *lp;
481 unsigned short ioaddr,status,ack_cmd;
482 unsigned short old_rp,old_wp;
483
484 if (dev==NULL)
485 {
486 printk(KERN_WARNING "net_interrupt(): irq %d for unknown device caught by EExpress\n",irq);
487 return;
488 }
489
490 #if NET_DEBUG > 6
491 printk(KERN_DEBUG "%s: interrupt\n", dev->name);
492 #endif
493
494 dev->interrupt = 1;
495
496 lp = (struct net_local *)dev->priv;
497 ioaddr = dev->base_addr;
498
499 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
500 old_rp = inw(ioaddr+READ_PTR);
501 old_wp = inw(ioaddr+WRITE_PTR);
502 status = inw(ioaddr+SCB_STATUS);
503 ack_cmd = SCB_ack(status);
504
505 if (PRIV(dev)->started==0 && SCB_complete(status))
506 {
507 #if NET_DEBUG > 4
508 printk(KERN_DEBUG "%s: SCBcomplete event received\n", dev->name);
509 #endif
510 while (SCB_CUstat(status)==2)
511 status = inw_p(ioaddr+SCB_STATUS);
512 #if NET_DEBUG > 4
513 printk(KERN_DEBUG "%s: CU went non-active (status = %08x)\n", dev->name, status);
514 #endif
515 PRIV(dev)->started=1;
516 outw_p(lp->tx_link,ioaddr+SCB_CBL);
517 outw_p(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
518 ack_cmd |= SCB_CUstart | SCB_RUstart;
519 }
520 else if (PRIV(dev)->started)
521 {
522 unsigned short txstatus;
523 txstatus = eexp_hw_lasttxstat(dev);
524 }
525
526 if (SCB_rxdframe(status))
527 {
528 eexp_hw_rx(dev);
529 }
530
531 if ((PRIV(dev)->started&2)!=0 && SCB_RUstat(status)!=4)
532 {
533 printk(KERN_WARNING "%s: RU stopped status %04x, restarting...\n",
534 dev->name,status);
535 lp->stats.rx_errors++;
536 eexp_hw_rxinit(dev);
537 outw(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
538 ack_cmd |= SCB_RUstart;
539 }
540 else if (PRIV(dev)->started==1 && SCB_RUstat(status)==4)
541 PRIV(dev)->started|=2;
542
543 outw(ack_cmd,ioaddr+SCB_CMD);
544 outb(0,ioaddr+SIGNAL_CA);
545 outw(old_rp,ioaddr+READ_PTR);
546 outw(old_wp,ioaddr+WRITE_PTR);
547 outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
548 dev->interrupt = 0;
549 #if NET_DEBUG > 6
550 printk(KERN_DEBUG "%s: leaving eexp_irq()\n", dev->name);
551 #endif
552 return;
553 }
554
555
556
557
558
559
560
561
562
563
564
565 static void eexp_hw_rx(struct device *dev)
566 {
567 struct net_local *lp = (struct net_local *)dev->priv;
568 unsigned short ioaddr = dev->base_addr;
569 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
570 unsigned short old_rp = inw(ioaddr+READ_PTR);
571 unsigned short rx_block = lp->rx_first;
572 unsigned short boguscount = lp->num_rx_bufs;
573
574 #if NET_DEBUG > 6
575 printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
576 #endif
577
578 while (outw(rx_block,ioaddr+READ_PTR),boguscount--)
579 {
580 unsigned short status = inw(ioaddr);
581 unsigned short rfd_cmd = inw(ioaddr);
582 unsigned short rx_next = inw(ioaddr);
583 unsigned short pbuf = inw(ioaddr);
584 unsigned short pkt_len;
585
586 if (FD_Done(status))
587 {
588 outw(pbuf,ioaddr+READ_PTR);
589 pkt_len = inw(ioaddr);
590
591 if (rfd_cmd!=0x0000 || pbuf!=rx_block+0x16
592 || (pkt_len & 0xc000)!=0xc000)
593 {
594 printk(KERN_WARNING "%s: Rx frame at %04x corrupted, status %04x, cmd %04x, "
595 "next %04x, pbuf %04x, len %04x\n",dev->name,rx_block,
596 status,rfd_cmd,rx_next,pbuf,pkt_len);
597 boguscount++;
598 continue;
599 }
600 else if (!FD_OK(status))
601 {
602 lp->stats.rx_errors++;
603 if (FD_CRC(status))
604 lp->stats.rx_crc_errors++;
605 if (FD_Align(status))
606 lp->stats.rx_frame_errors++;
607 if (FD_Resrc(status))
608 lp->stats.rx_fifo_errors++;
609 if (FD_DMA(status))
610 lp->stats.rx_over_errors++;
611 if (FD_Short(status))
612 lp->stats.rx_length_errors++;
613 }
614 else
615 {
616 struct sk_buff *skb;
617 pkt_len &= 0x3fff;
618 skb = dev_alloc_skb(pkt_len+16);
619 if (skb == NULL)
620 {
621 printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
622 lp->stats.rx_dropped++;
623 break;
624 }
625 skb->dev = dev;
626 skb_reserve(skb, 2);
627 outw(pbuf+10,ioaddr+READ_PTR);
628 insw(ioaddr,skb_put(skb,pkt_len),(pkt_len+1)>>1);
629 skb->protocol = eth_type_trans(skb,dev);
630 netif_rx(skb);
631 lp->stats.rx_packets++;
632 }
633 outw(rx_block,ioaddr+WRITE_PTR);
634 outw(0x0000,ioaddr);
635 outw(0x0000,ioaddr);
636 }
637 rx_block = rx_next;
638 }
639 outw(old_rp,ioaddr+READ_PTR);
640 outw(old_wp,ioaddr+WRITE_PTR);
641 }
642
643
644
645
646
647
648
649
650 static void eexp_hw_tx(struct device *dev, unsigned short *buf, unsigned short len)
651 {
652 struct net_local *lp = (struct net_local *)dev->priv;
653 unsigned short ioaddr = dev->base_addr;
654 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
655
656 outw(lp->tx_head,ioaddr+WRITE_PTR);
657 outw(0x0000,ioaddr);
658 outw(Cmd_INT|Cmd_Xmit,ioaddr);
659 outw(lp->tx_head+0x08,ioaddr);
660 outw(lp->tx_head+0x0e,ioaddr);
661 outw(0x0000,ioaddr);
662 outw(0x0000,ioaddr);
663 outw(lp->tx_head+0x08,ioaddr);
664 outw(0x8000|len,ioaddr);
665 outw(-1,ioaddr);
666 outw(lp->tx_head+0x16,ioaddr);
667 outw(0,ioaddr);
668 outsw(ioaddr,buf,(len+1)>>1);
669 outw(lp->tx_tail+0x0c,ioaddr+WRITE_PTR);
670 outw(lp->tx_head,ioaddr);
671 dev->trans_start = jiffies;
672 lp->tx_tail = lp->tx_head;
673 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
674 lp->tx_head = TX_BUF_START;
675 else
676 lp->tx_head += TX_BUF_SIZE;
677 if (lp->tx_head != lp->tx_reap)
678 dev->tbusy = 0;
679 outw(old_wp,ioaddr+WRITE_PTR);
680 }
681
682
683
684
685
686
687
688
689
690 static int eexp_hw_probe(struct device *dev, unsigned short ioaddr)
691 {
692 unsigned short hw_addr[3];
693 int i;
694 unsigned char *chw_addr = (unsigned char *)hw_addr;
695
696 printk("%s: EtherExpress at %#x, ",dev->name,ioaddr);
697
698 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
699 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
700 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
701
702 if (hw_addr[2]!=0x00aa || ((hw_addr[1] & 0xff00)!=0x0000))
703 {
704 printk("rejected: invalid address %04x%04x%04x\n",
705 hw_addr[2],hw_addr[1],hw_addr[0]);
706 return ENODEV;
707 }
708
709 dev->base_addr = ioaddr;
710 for ( i=0 ; i<6 ; i++ )
711 dev->dev_addr[i] = chw_addr[5-i];
712
713 {
714 char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
715 char *ifmap[]={"AUI", "BNC", "10baseT"};
716 enum iftype {AUI=0, BNC=1, TP=2};
717 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
718
719 dev->irq = irqmap[setupval>>13];
720 dev->if_port = !(setupval & 0x1000) ? AUI :
721 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TP : BNC;
722
723 printk("IRQ %d, Interface %s, ",dev->irq,ifmap[dev->if_port]);
724
725 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
726 outb(0,ioaddr+SET_IRQ);
727 }
728
729 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
730 if (!dev->priv)
731 return -ENOMEM;
732
733 memset(dev->priv, 0, sizeof(struct net_local));
734
735 eexp_hw_ASICrst(dev);
736
737 {
738 unsigned short i586mso = 0x023e;
739 unsigned short old_wp,old_rp,old_a0,old_a1;
740 unsigned short a0_0,a1_0,a0_1,a1_1;
741
742 old_wp = inw(ioaddr+WRITE_PTR);
743 old_rp = inw(ioaddr+READ_PTR);
744 outw(0x8000+i586mso,ioaddr+READ_PTR);
745 old_a1 = inw(ioaddr);
746 outw(i586mso,ioaddr+READ_PTR);
747 old_a0 = inw(ioaddr);
748 outw(i586mso,ioaddr+WRITE_PTR);
749 outw(0x55aa,ioaddr);
750 outw(i586mso,ioaddr+READ_PTR);
751 a0_0 = inw(ioaddr);
752 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
753 outw(0x5a5a,ioaddr);
754 outw(0x8000+i586mso,ioaddr+READ_PTR);
755 a1_0 = inw(ioaddr);
756 outw(i586mso,ioaddr+READ_PTR);
757 a0_1 = inw(ioaddr);
758 outw(i586mso,ioaddr+WRITE_PTR);
759 outw(0x1234,ioaddr);
760 outw(0x8000+i586mso,ioaddr+READ_PTR);
761 a1_1 = inw(ioaddr);
762
763 if ((a0_0 != a0_1) || (a1_0 != a1_1) ||
764 (a1_0 != 0x5a5a) || (a0_0 != 0x55aa))
765 {
766 printk("32k\n");
767 PRIV(dev)->rx_buf_end = 0x7ff6;
768 PRIV(dev)->num_tx_bufs = 4;
769 }
770 else
771 {
772 printk("64k\n");
773 PRIV(dev)->num_tx_bufs = 8;
774 PRIV(dev)->rx_buf_start = TX_BUF_START + (PRIV(dev)->num_tx_bufs*TX_BUF_SIZE);
775 PRIV(dev)->rx_buf_end = 0xfff6;
776 }
777
778 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
779 outw(old_a1,ioaddr);
780 outw(i586mso,ioaddr+WRITE_PTR);
781 outw(old_a0,ioaddr);
782 outw(old_wp,ioaddr+WRITE_PTR);
783 outw(old_rp,ioaddr+READ_PTR);
784 }
785
786 if (net_debug)
787 printk(version);
788 dev->open = eexp_open;
789 dev->stop = eexp_close;
790 dev->hard_start_xmit = eexp_xmit;
791 dev->get_stats = eexp_stats;
792 dev->set_multicast_list = &eexp_set_multicast;
793 ether_setup(dev);
794 return 0;
795 }
796
797
798
799
800 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location)
801 {
802 unsigned short cmd = 0x180|(location&0x7f);
803 unsigned short rval = 0,wval = EC_CS|i586_RST;
804 int i;
805
806 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
807 for ( i=0x100 ; i ; i>>=1 )
808 {
809 if (cmd&i)
810 wval |= EC_Wr;
811 else
812 wval &= ~EC_Wr;
813
814 outb(wval,ioaddr+EEPROM_Ctrl);
815 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
816 eeprom_delay();
817 outb(wval,ioaddr+EEPROM_Ctrl);
818 eeprom_delay();
819 }
820 wval &= ~EC_Wr;
821 outb(wval,ioaddr+EEPROM_Ctrl);
822 for ( i=0x8000 ; i ; i>>=1 )
823 {
824 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
825 eeprom_delay();
826 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
827 rval |= i;
828 outb(wval,ioaddr+EEPROM_Ctrl);
829 eeprom_delay();
830 }
831 wval &= ~EC_CS;
832 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
833 eeprom_delay();
834 outb(wval,ioaddr+EEPROM_Ctrl);
835 eeprom_delay();
836 return rval;
837 }
838
839
840
841
842
843
844
845
846
847
848
849 static unsigned short eexp_hw_lasttxstat(struct device *dev)
850 {
851 struct net_local *lp = (struct net_local *)dev->priv;
852 unsigned short ioaddr = dev->base_addr;
853 unsigned short old_rp = inw(ioaddr+READ_PTR);
854 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
855 unsigned short tx_block = lp->tx_reap;
856 unsigned short status;
857
858 if (!test_bit(0,(void *)&dev->tbusy) && lp->tx_head==lp->tx_reap)
859 return 0x0000;
860
861 do
862 {
863 outw(tx_block,ioaddr+READ_PTR);
864 status = inw(ioaddr);
865 if (!Stat_Done(status))
866 {
867 lp->tx_link = tx_block;
868 outw(old_rp,ioaddr+READ_PTR);
869 outw(old_wp,ioaddr+WRITE_PTR);
870 return status;
871 }
872 else
873 {
874 lp->last_tx_restart = 0;
875 lp->stats.collisions += Stat_NoColl(status);
876 if (!Stat_OK(status))
877 {
878 if (Stat_Abort(status))
879 lp->stats.tx_aborted_errors++;
880 if (Stat_TNoCar(status) || Stat_TNoCTS(status))
881 lp->stats.tx_carrier_errors++;
882 if (Stat_TNoDMA(status))
883 lp->stats.tx_fifo_errors++;
884 }
885 else
886 lp->stats.tx_packets++;
887 }
888 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
889 lp->tx_reap = tx_block = TX_BUF_START;
890 else
891 lp->tx_reap = tx_block += TX_BUF_SIZE;
892 dev->tbusy = 0;
893 mark_bh(NET_BH);
894 }
895 while (lp->tx_reap != lp->tx_head);
896
897 lp->tx_link = lp->tx_tail + 0x08;
898 outw(old_rp,ioaddr+READ_PTR);
899 outw(old_wp,ioaddr+WRITE_PTR);
900
901 return status;
902 }
903
904
905
906
907
908
909
910
911 static void eexp_hw_txrestart(struct device *dev)
912 {
913 struct net_local *lp = (struct net_local *)dev->priv;
914 unsigned short ioaddr = dev->base_addr;
915
916 lp->last_tx_restart = lp->tx_link;
917 outw(lp->tx_link,ioaddr+SCB_CBL);
918 outw(SCB_CUstart,ioaddr+SCB_CMD);
919 outw(0,ioaddr+SCB_STATUS);
920 outb(0,ioaddr+SIGNAL_CA);
921
922 {
923 unsigned short boguscount=50,failcount=5;
924 while (!inw(ioaddr+SCB_STATUS))
925 {
926 if (!--boguscount)
927 {
928 if (--failcount)
929 {
930 printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n",
931 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
932 outw(lp->tx_link,ioaddr+SCB_CBL);
933 outw(0,ioaddr+SCB_STATUS);
934 outw(SCB_CUstart,ioaddr+SCB_CMD);
935 outb(0,ioaddr+SIGNAL_CA);
936 boguscount = 100;
937 }
938 else
939 {
940 printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
941 eexp_hw_init586(dev);
942 dev->tbusy = 0;
943 mark_bh(NET_BH);
944 return;
945 }
946 }
947 }
948 }
949 }
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964 static void eexp_hw_txinit(struct device *dev)
965 {
966 struct net_local *lp = (struct net_local *)dev->priv;
967 unsigned short ioaddr = dev->base_addr;
968 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
969 unsigned short tx_block = TX_BUF_START;
970 unsigned short curtbuf;
971
972 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
973 {
974 outw(tx_block,ioaddr+WRITE_PTR);
975 outw(0x0000,ioaddr);
976 outw(Cmd_INT|Cmd_Xmit,ioaddr);
977 outw(tx_block+0x08,ioaddr);
978 outw(tx_block+0x0e,ioaddr);
979 outw(0x0000,ioaddr);
980 outw(0x0000,ioaddr);
981 outw(tx_block+0x08,ioaddr);
982 outw(0x8000,ioaddr);
983 outw(-1,ioaddr);
984 outw(tx_block+0x16,ioaddr);
985 outw(0x0000,ioaddr);
986 tx_block += TX_BUF_SIZE;
987 }
988 lp->tx_head = TX_BUF_START;
989 lp->tx_reap = TX_BUF_START;
990 lp->tx_tail = tx_block - TX_BUF_SIZE;
991 lp->tx_link = lp->tx_tail + 0x08;
992 lp->rx_buf_start = tx_block;
993 outw(old_wp,ioaddr+WRITE_PTR);
994 }
995
996
997
998 unsigned short rx_words[] =
999 {
1000 0xfeed,0xf00d,0xf001,0x0505,0x2424,0x6565,0xdeaf
1001 };
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 static void eexp_hw_rxinit(struct device *dev)
1013 {
1014 struct net_local *lp = (struct net_local *)dev->priv;
1015 unsigned short ioaddr = dev->base_addr;
1016 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1017 unsigned short rx_block = lp->rx_buf_start;
1018
1019 lp->num_rx_bufs = 0;
1020 lp->rx_first = rx_block;
1021 do
1022 {
1023 lp->num_rx_bufs++;
1024 outw(rx_block,ioaddr+WRITE_PTR);
1025 outw(0x0000,ioaddr);
1026 outw(0x0000,ioaddr);
1027 outw(rx_block+RX_BUF_SIZE,ioaddr);
1028 outw(rx_block+0x16,ioaddr);
1029 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1030 outw(0x8000,ioaddr);
1031 outw(-1,ioaddr);
1032 outw(rx_block+0x20,ioaddr);
1033 outw(0x0000,ioaddr);
1034 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1035 lp->rx_last = rx_block;
1036 rx_block += RX_BUF_SIZE;
1037 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1038
1039 outw(lp->rx_last+4,ioaddr+WRITE_PTR);
1040 outw(lp->rx_first,ioaddr);
1041
1042 outw(old_wp,ioaddr+WRITE_PTR);
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054 static void eexp_hw_init586(struct device *dev)
1055 {
1056 struct net_local *lp = (struct net_local *)dev->priv;
1057 unsigned short ioaddr = dev->base_addr;
1058
1059 #if NET_DEBUG > 6
1060 printk("%s: eexp_hw_init586()\n", dev->name);
1061 #endif
1062
1063 PRIV(dev)->started = 0;
1064 set_loopback;
1065
1066 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1067 outb_p(i586_RST,ioaddr+EEPROM_Ctrl);
1068
1069 outw_p(lp->rx_buf_end,ioaddr+WRITE_PTR);
1070 start_code[28] = (dev->flags & IFF_PROMISC)?(start_code[28] | 1):(start_code[28] & ~1);
1071 PRIV(dev)->promisc = dev->flags & IFF_PROMISC;
1072
1073 outsw(ioaddr, start_code, sizeof(start_code)>>1);
1074 outw(CONF_HW_ADDR,ioaddr+WRITE_PTR);
1075 outsw(ioaddr,dev->dev_addr,3);
1076 eexp_hw_txinit(dev);
1077 eexp_hw_rxinit(dev);
1078 outw(0,ioaddr+WRITE_PTR);
1079 outw(1,ioaddr);
1080 outb(0,ioaddr+EEPROM_Ctrl);
1081 outw(0,ioaddr+SCB_CMD);
1082 outb(0,ioaddr+SIGNAL_CA);
1083 {
1084 unsigned short rboguscount=50,rfailcount=5;
1085 while (outw(0,ioaddr+READ_PTR),inw(ioaddr))
1086 {
1087 if (!--rboguscount)
1088 {
1089 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1090 dev->name);
1091 outw(0,ioaddr+SCB_CMD);
1092 outb(0,ioaddr+SIGNAL_CA);
1093 rboguscount = 100;
1094 if (!--rfailcount)
1095 {
1096 printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1097 dev->name);
1098 return;
1099 }
1100 }
1101 }
1102 }
1103
1104 outw(CONF_LINK,ioaddr+SCB_CBL);
1105 outw(0,ioaddr+SCB_STATUS);
1106 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1107 outb(0,ioaddr+SIGNAL_CA);
1108 {
1109 unsigned short iboguscount=50,ifailcount=5;
1110 while (!inw(ioaddr+SCB_STATUS))
1111 {
1112 if (!--iboguscount)
1113 {
1114 if (--ifailcount)
1115 {
1116 printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1117 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
1118 outw(CONF_LINK,ioaddr+SCB_CBL);
1119 outw(0,ioaddr+SCB_STATUS);
1120 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1121 outb(0,ioaddr+SIGNAL_CA);
1122 iboguscount = 100;
1123 }
1124 else
1125 {
1126 printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1127 return;
1128 }
1129 }
1130 }
1131 }
1132
1133 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1134 clear_loopback;
1135 lp->init_time = jiffies;
1136 #if NET_DEBUG > 6
1137 printk("%s: leaving eexp_hw_init586()\n", dev->name);
1138 #endif
1139 return;
1140 }
1141
1142
1143
1144
1145
1146
1147
1148 static void eexp_hw_ASICrst(struct device *dev)
1149 {
1150 unsigned short ioaddr = dev->base_addr;
1151 unsigned short wrval = 0x0001,succount=0,boguscount=500;
1152
1153 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1154
1155 PRIV(dev)->started = 0;
1156 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1157 while (succount<20)
1158 {
1159 if (wrval == 0xffff)
1160 wrval = 0x0001;
1161 outw(0,ioaddr+WRITE_PTR);
1162 outw(wrval,ioaddr);
1163 outw(0,ioaddr+READ_PTR);
1164 if (wrval++ == inw(ioaddr))
1165 succount++;
1166 else
1167 {
1168 succount = 0;
1169 if (!boguscount--)
1170 {
1171 boguscount = 500;
1172 printk("%s: Having problems resetting EtherExpress ASIC, continuing...\n",
1173 dev->name);
1174 wrval = 0x0001;
1175 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1176 }
1177 }
1178 }
1179 outb(i586_RST,ioaddr+EEPROM_Ctrl);
1180 }
1181
1182
1183
1184
1185
1186
1187
1188 static void
1189 eexp_set_multicast(struct device *dev)
1190 {
1191 if ((dev->flags & IFF_PROMISC) != PRIV(dev)->promisc)
1192 eexp_hw_init586(dev);
1193 }
1194
1195
1196
1197
1198
1199 #ifdef MODULE
1200
1201 #define EEXP_MAX_CARDS 4
1202 #define NAMELEN 8
1203
1204 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1205
1206 static struct device dev_eexp[EEXP_MAX_CARDS] =
1207 {
1208 NULL,
1209 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe
1210 };
1211
1212 int irq[EEXP_MAX_CARDS] = {0, };
1213 int io[EEXP_MAX_CARDS] = {0, };
1214
1215
1216
1217
1218
1219 int init_module(void)
1220 {
1221 int this_dev, found = 0;
1222
1223 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1224 struct device *dev = &dev_eexp[this_dev];
1225 dev->name = namelist + (NAMELEN*this_dev);
1226 dev->irq = irq[this_dev];
1227 dev->base_addr = io[this_dev];
1228 if (io[this_dev] == 0) {
1229 if (this_dev) break;
1230 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1231 }
1232 if (register_netdev(dev) != 0) {
1233 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1234 if (found != 0) return 0;
1235 return -ENXIO;
1236 }
1237 found++;
1238 }
1239 return 0;
1240 }
1241
1242 void cleanup_module(void)
1243 {
1244 int this_dev;
1245
1246 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1247 struct device *dev = &dev_eexp[this_dev];
1248 if (dev->priv != NULL) {
1249 kfree(dev->priv);
1250 dev->priv = NULL;
1251 release_region(dev->base_addr, EEXP_IO_EXTENT);
1252 unregister_netdev(dev);
1253 }
1254 }
1255 }
1256 #endif
1257
1258
1259
1260
1261
1262
1263
1264