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