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
101
102
103 static char version[] =
104 "eexpress.c: v0.07 1/19/94 Donald Becker <becker@super.org>\n"
105 " v0.10 4th May 1995 John Sullivan <js10039@cam.ac.uk>\n";
106
107 #include <linux/module.h>
108
109 #include <linux/kernel.h>
110 #include <linux/sched.h>
111 #include <linux/types.h>
112 #include <linux/fcntl.h>
113 #include <linux/interrupt.h>
114 #include <linux/ptrace.h>
115 #include <linux/ioport.h>
116 #include <linux/string.h>
117 #include <linux/in.h>
118 #include <asm/system.h>
119 #include <asm/bitops.h>
120 #include <asm/io.h>
121 #include <asm/dma.h>
122 #include <linux/errno.h>
123
124 #include <linux/netdevice.h>
125 #include <linux/etherdevice.h>
126 #include <linux/skbuff.h>
127 #include <linux/malloc.h>
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 #undef NET_DEBUG
145
146 #ifndef NET_DEBUG
147 #define NET_DEBUG 4
148 #endif
149 static unsigned int net_debug = NET_DEBUG;
150
151 #undef F_DEB
152
153 #include "eth82586.h"
154
155 #define PRIV(x) ((struct net_local *)(x)->priv)
156 #define EEXP_IO_EXTENT 16
157
158
159
160
161
162 struct net_local
163 {
164 struct enet_statistics stats;
165 unsigned long init_time;
166 unsigned short rx_first;
167 unsigned short rx_last;
168 unsigned short tx_head;
169 unsigned short tx_reap;
170 unsigned short tx_tail;
171 unsigned short tx_link;
172 unsigned short last_tx_restart;
173 unsigned char started;
174 unsigned short rx_buf_start;
175 unsigned short rx_buf_end;
176 unsigned short num_tx_bufs;
177 unsigned short num_rx_bufs;
178 };
179
180 unsigned short start_code[] = {
181 0x0000,
182 0x0000,0x0000,
183 0x0000,0x0000,
184
185 0x0001,
186 0x0008,0x0000,0x0000,
187
188 0x0000,0x0000,
189 0x0000,0x0000,
190 0x0000,0x0000,
191 0x0000,0x0000,
192
193 0x0000,0x0000,
194 0x0000,0x0000,
195
196 0x0000,Cmd_Config,
197 0x0032,
198 0x080c,
199 0x2e40,
200
201 0x6000,
202 0xf200,
203 0x0000,
204 0x003c,
205
206 0x0000,Cmd_INT|Cmd_SetAddr,
207 0x003e,
208 0x0000,0x0000,0x0000,
209 0x0000,Cmd_END|Cmd_Nop,
210 0x003e,
211
212 0x0000
213
214 };
215
216 #define CONF_LINK 0x0020
217 #define CONF_HW_ADDR 0x0038
218
219
220 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
221
222
223
224
225
226 extern int express_probe(struct device *dev);
227 static int eexp_open (struct device *dev);
228 static int eexp_close(struct device *dev);
229 static struct enet_statistics *eexp_stats(struct device *dev);
230 static int eexp_xmit (struct sk_buff *buf, struct device *dev);
231
232 static void eexp_irq (int irq, void *dev_addr, struct pt_regs *regs);
233
234
235
236
237
238 static void eexp_hw_rx (struct device *dev);
239 static void eexp_hw_tx (struct device *dev, unsigned short *buf, unsigned short len);
240 static int eexp_hw_probe (struct device *dev,unsigned short ioaddr);
241 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location);
242
243 static unsigned short eexp_hw_lasttxstat(struct device *dev);
244 static void eexp_hw_txrestart (struct device *dev);
245
246 static void eexp_hw_txinit (struct device *dev);
247 static void eexp_hw_rxinit (struct device *dev);
248 static void eexp_hw_rxmap (struct device *dev,unsigned short rx_buf);
249
250 static void eexp_hw_init586 (struct device *dev);
251 static void eexp_hw_ASICrst (struct device *dev);
252
253
254
255
256
257
258
259
260
261 int express_probe(struct device *dev)
262 {
263 unsigned short *port,ports[] = { 0x0300,0x0270,0x0320,0x0340,0 };
264 unsigned short ioaddr = dev->base_addr;
265
266 if (ioaddr&0xfe00)
267 return eexp_hw_probe(dev,ioaddr);
268 else if (ioaddr)
269 return ENXIO;
270
271 for ( port=&ports[0] ; *port ; port++ )
272 {
273 unsigned short sum = 0;
274 int i;
275 for ( i=0 ; i<4 ; i++ )
276 {
277 unsigned short t;
278 t = inb(*port + ID_PORT);
279 sum |= (t>>4) << ((t & 0x03)<<2);
280 }
281 if (sum==0xbaba && !eexp_hw_probe(dev,*port))
282 return 0;
283 }
284 return ENODEV;
285 }
286
287
288
289
290
291 static int eexp_open(struct device *dev)
292 {
293 int irq = dev->irq;
294 unsigned short ioaddr = dev->base_addr;
295
296 #if NET_DEBUG > 6
297 printk("%s: eexp_open()\n", dev->name);
298 #endif
299
300 if (!irq || !irqrmap[irq])
301 return -ENXIO;
302
303 if (irq2dev_map[irq] ||
304
305 ((irq2dev_map[irq]=dev),0) ||
306 request_irq(irq,&eexp_irq,0,"eexpress",NULL))
307 return -EAGAIN;
308
309 request_region(ioaddr, EEXP_IO_EXTENT, "eexpress");
310 dev->tbusy = 0;
311 dev->interrupt = 0;
312 eexp_hw_init586(dev);
313 dev->start = 1;
314 return 0;
315 }
316
317
318
319
320
321 static int eexp_close(struct device *dev)
322 {
323 unsigned short ioaddr = dev->base_addr;
324 int irq = dev->irq;
325
326 dev->tbusy = 1;
327 dev->start = 0;
328
329 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
330 PRIV(dev)->started = 0;
331 outw(SCB_CUsuspend|SCB_RUsuspend,ioaddr+SCB_CMD);
332 outb(0,ioaddr+SIGNAL_CA);
333 free_irq(irq,NULL);
334 irq2dev_map[irq] = NULL;
335 outb(i586_RST,ioaddr+EEPROM_Ctrl);
336 release_region(ioaddr,16);
337 return 0;
338 }
339
340
341
342
343
344 static struct enet_statistics *eexp_stats(struct device *dev)
345 {
346 struct net_local *lp = (struct net_local *)dev->priv;
347
348
349
350
351
352
353
354 return &lp->stats;
355 }
356
357
358
359
360
361
362 static int eexp_xmit(struct sk_buff *buf, struct device *dev)
363 {
364 struct net_local *lp = (struct net_local *)dev->priv;
365 unsigned short ioaddr = dev->base_addr;
366
367 #if NET_DEBUG > 6
368 printk("%s: eexp_xmit()\n", dev->name);
369 #endif
370
371 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
372 if (dev->tbusy)
373 {
374
375
376
377
378 if (test_bit(0,(void *)&PRIV(dev)->started))
379 {
380 if ((jiffies - dev->trans_start)>5)
381 {
382 if (lp->tx_link==lp->last_tx_restart)
383 {
384 unsigned short boguscount=200,rsst;
385 printk("%s: Retransmit timed out, status %04x, resetting...\n",
386 dev->name,inw(ioaddr+SCB_STATUS));
387 eexp_hw_txinit(dev);
388 lp->last_tx_restart = 0;
389 outw(lp->tx_link,ioaddr+SCB_CBL);
390 outw(0,ioaddr+SCB_STATUS);
391 outw(SCB_CUstart,ioaddr+SCB_CMD);
392 outb(0,ioaddr+SIGNAL_CA);
393 while (!SCB_complete(rsst=inw(ioaddr+SCB_STATUS)))
394 {
395 if (!--boguscount)
396 {
397 boguscount=200;
398 printk("%s: Reset timed out status %04x, retrying...\n",
399 dev->name,rsst);
400 outw(lp->tx_link,ioaddr+SCB_CBL);
401 outw(0,ioaddr+SCB_STATUS);
402 outw(SCB_CUstart,ioaddr+SCB_CMD);
403 outb(0,ioaddr+SIGNAL_CA);
404 }
405 }
406 dev->tbusy = 0;
407 mark_bh(NET_BH);
408 }
409 else
410 {
411 unsigned short status = inw(ioaddr+SCB_STATUS);
412 if (SCB_CUdead(status))
413 {
414 unsigned short txstatus = eexp_hw_lasttxstat(dev);
415 printk("%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
416 dev->name, status, txstatus);
417 eexp_hw_txrestart(dev);
418 }
419 else
420 {
421 unsigned short txstatus = eexp_hw_lasttxstat(dev);
422 if (dev->tbusy && !txstatus)
423 {
424 printk("%s: CU wedged, status %04x %04x, resetting...\n",
425 dev->name,status,txstatus);
426 eexp_hw_init586(dev);
427 dev->tbusy = 0;
428 mark_bh(NET_BH);
429 }
430 }
431 }
432 }
433 }
434 else
435 {
436 if ((jiffies-lp->init_time)>10)
437 {
438 unsigned short status = inw(ioaddr+SCB_STATUS);
439 printk("%s: i82586 startup timed out, status %04x, resetting...\n",
440 dev->name, status);
441 eexp_hw_init586(dev);
442 dev->tbusy = 0;
443 mark_bh(NET_BH);
444 }
445 }
446 }
447
448 if (buf==NULL)
449 {
450 unsigned short status = inw(ioaddr+SCB_STATUS);
451 unsigned short txstatus = eexp_hw_lasttxstat(dev);
452 if (SCB_CUdead(status))
453 {
454 printk("%s: CU has died! status %04x %04x, attempting to restart...\n",
455 dev->name, status, txstatus);
456 lp->stats.tx_errors++;
457 eexp_hw_txrestart(dev);
458 }
459 dev_tint(dev);
460 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
461 return 0;
462 }
463
464 if (set_bit(0,(void *)&dev->tbusy))
465 {
466
467 lp->stats.tx_dropped++;
468 }
469 else
470 {
471 unsigned short length = (ETH_ZLEN < buf->len) ? buf->len : ETH_ZLEN;
472 unsigned short *data = (unsigned short *)buf->data;
473
474 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
475 eexp_hw_tx(dev,data,length);
476 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
477 }
478 dev_kfree_skb(buf, FREE_WRITE);
479 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
480 return 0;
481 }
482
483
484
485
486
487
488
489
490 static void eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
491 {
492 struct device *dev = irq2dev_map[irq];
493 struct net_local *lp;
494 unsigned short ioaddr,status,ack_cmd;
495 unsigned short old_rp,old_wp;
496
497 if (dev==NULL)
498 {
499 printk("net_interrupt(): irq %d for unknown device caught by EExpress\n",irq);
500 return;
501 }
502
503 #if NET_DEBUG > 6
504 printk("%s: interrupt\n", dev->name);
505 #endif
506
507 dev->interrupt = 1;
508
509 lp = (struct net_local *)dev->priv;
510 ioaddr = dev->base_addr;
511
512 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
513 old_rp = inw(ioaddr+READ_PTR);
514 old_wp = inw(ioaddr+WRITE_PTR);
515 status = inw(ioaddr+SCB_STATUS);
516 ack_cmd = SCB_ack(status);
517
518 if (PRIV(dev)->started==0 && SCB_complete(status))
519 {
520 if (SCB_CUstat(status)==2)
521 while (SCB_CUstat(inw(ioaddr+SCB_STATUS))==2);
522 PRIV(dev)->started=1;
523 outw(lp->tx_link,ioaddr+SCB_CBL);
524 outw(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
525 ack_cmd |= SCB_CUstart | SCB_RUstart;
526 }
527 else if (PRIV(dev)->started)
528 {
529 unsigned short txstatus;
530 txstatus = eexp_hw_lasttxstat(dev);
531 }
532
533 if (SCB_rxdframe(status))
534 {
535 eexp_hw_rx(dev);
536 }
537
538 if ((PRIV(dev)->started&2)!=0 && SCB_RUstat(status)!=4)
539 {
540 printk("%s: RU stopped status %04x, restarting...\n",
541 dev->name,status);
542 lp->stats.rx_errors++;
543 eexp_hw_rxinit(dev);
544 outw(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
545 ack_cmd |= SCB_RUstart;
546 }
547 else if (PRIV(dev)->started==1 && SCB_RUstat(status)==4)
548 PRIV(dev)->started|=2;
549
550 outw(ack_cmd,ioaddr+SCB_CMD);
551 outb(0,ioaddr+SIGNAL_CA);
552 outw(old_rp,ioaddr+READ_PTR);
553 outw(old_wp,ioaddr+WRITE_PTR);
554 outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
555 return;
556 }
557
558
559
560
561
562
563
564
565
566
567
568 static void eexp_hw_rx(struct device *dev)
569 {
570 struct net_local *lp = (struct net_local *)dev->priv;
571 unsigned short ioaddr = dev->base_addr;
572 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
573 unsigned short old_rp = inw(ioaddr+READ_PTR);
574 unsigned short rx_block = lp->rx_first;
575 unsigned short boguscount = lp->num_rx_bufs;
576
577 #if NET_DEBUG > 6
578 printk("%s: eexp_hw_rx()\n", dev->name);
579 #endif
580
581 while (outw(rx_block,ioaddr+READ_PTR),boguscount--)
582 {
583 unsigned short status = inw(ioaddr);
584 unsigned short rfd_cmd = inw(ioaddr);
585 unsigned short rx_next = inw(ioaddr);
586 unsigned short pbuf = inw(ioaddr);
587 unsigned short pkt_len;
588
589 if (FD_Done(status))
590 {
591 outw(pbuf,ioaddr+READ_PTR);
592 pkt_len = inw(ioaddr);
593
594 if (rfd_cmd!=0x0000 || pbuf!=rx_block+0x16
595 || (pkt_len & 0xc000)!=0xc000)
596 {
597 printk("%s: Rx frame at %04x corrupted, status %04x, cmd %04x, "
598 "next %04x, pbuf %04x, len %04x\n",dev->name,rx_block,
599 status,rfd_cmd,rx_next,pbuf,pkt_len);
600 eexp_hw_rxmap(dev,rx_block);
601 boguscount++;
602 continue;
603 }
604 else if (!FD_OK(status))
605 {
606 lp->stats.rx_errors++;
607 if (FD_CRC(status))
608 lp->stats.rx_crc_errors++;
609 if (FD_Align(status))
610 lp->stats.rx_frame_errors++;
611 if (FD_Resrc(status))
612 lp->stats.rx_fifo_errors++;
613 if (FD_DMA(status))
614 lp->stats.rx_over_errors++;
615 if (FD_Short(status))
616 lp->stats.rx_length_errors++;
617 }
618 else
619 {
620 struct sk_buff *skb;
621 pkt_len &= 0x3fff;
622 skb = dev_alloc_skb(pkt_len+16);
623 if (skb == NULL)
624 {
625 printk("%s: Memory squeeze, dropping packet\n",dev->name);
626 lp->stats.rx_dropped++;
627 break;
628 }
629 skb->dev = dev;
630 skb_reserve(skb, 2);
631 outw(pbuf+10,ioaddr+READ_PTR);
632 insw(ioaddr,skb_put(skb,pkt_len),(pkt_len+1)>>1);
633 skb->protocol = eth_type_trans(skb,dev);
634 netif_rx(skb);
635 lp->stats.rx_packets++;
636 }
637 outw(rx_block,ioaddr+WRITE_PTR);
638 outw(0x0000,ioaddr);
639 outw(0x0000,ioaddr);
640 }
641 rx_block = rx_next;
642 }
643 outw(old_rp,ioaddr+READ_PTR);
644 outw(old_wp,ioaddr+WRITE_PTR);
645 }
646
647
648
649
650
651
652
653
654 static void eexp_hw_tx(struct device *dev, unsigned short *buf, unsigned short len)
655 {
656 struct net_local *lp = (struct net_local *)dev->priv;
657 unsigned short ioaddr = dev->base_addr;
658 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
659
660 outw(lp->tx_head,ioaddr+WRITE_PTR);
661 outw(0x0000,ioaddr);
662 outw(Cmd_INT|Cmd_Xmit,ioaddr);
663 outw(lp->tx_head+0x08,ioaddr);
664 outw(lp->tx_head+0x0e,ioaddr);
665 outw(0x0000,ioaddr);
666 outw(0x0000,ioaddr);
667 outw(lp->tx_head+0x08,ioaddr);
668 outw(0x8000|len,ioaddr);
669 outw(-1,ioaddr);
670 outw(lp->tx_head+0x16,ioaddr);
671 outw(0,ioaddr);
672 outsw(ioaddr,buf,(len+1)>>1);
673 outw(lp->tx_tail+0x0c,ioaddr+WRITE_PTR);
674 outw(lp->tx_head,ioaddr);
675 dev->trans_start = jiffies;
676 lp->tx_tail = lp->tx_head;
677 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
678 lp->tx_head = TX_BUF_START;
679 else
680 lp->tx_head += TX_BUF_SIZE;
681 if (lp->tx_head != lp->tx_reap)
682 dev->tbusy = 0;
683 outw(old_wp,ioaddr+WRITE_PTR);
684 }
685
686
687
688
689
690
691
692
693
694 static int eexp_hw_probe(struct device *dev, unsigned short ioaddr)
695 {
696 unsigned short hw_addr[3];
697 int i;
698 unsigned char *chw_addr = (unsigned char *)hw_addr;
699
700 printk("%s: EtherExpress at %#x, ",dev->name,ioaddr);
701
702 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
703 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
704 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
705
706 if (hw_addr[2]!=0x00aa || ((hw_addr[1] & 0xff00)!=0x0000))
707 {
708 printk("rejected: invalid address %04x%04x%04x\n",
709 hw_addr[2],hw_addr[1],hw_addr[0]);
710 return ENODEV;
711 }
712
713 dev->base_addr = ioaddr;
714 for ( i=0 ; i<6 ; i++ )
715 dev->dev_addr[i] = chw_addr[5-i];
716
717 {
718 char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
719 char *ifmap[]={"AUI", "BNC", "10baseT"};
720 enum iftype {AUI=0, BNC=1, TP=2};
721 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
722
723 dev->irq = irqmap[setupval>>13];
724 dev->if_port = !(setupval & 0x1000) ? AUI :
725 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TP : BNC;
726
727 printk("IRQ %d, Interface %s, ",dev->irq,ifmap[dev->if_port]);
728
729 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
730 outb(0,ioaddr+SET_IRQ);
731 }
732
733 eexp_hw_ASICrst(dev);
734
735 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
736 memset(dev->priv, 0, sizeof(struct net_local));
737
738 {
739 unsigned short i586mso = 0x023e;
740 unsigned short old_wp,old_rp,old_a0,old_a1;
741 unsigned short a0_0,a1_0,a0_1,a1_1;
742
743 old_wp = inw(ioaddr+WRITE_PTR);
744 old_rp = inw(ioaddr+READ_PTR);
745 outw(0x8000+i586mso,ioaddr+READ_PTR);
746 old_a1 = inw(ioaddr);
747 outw(i586mso,ioaddr+READ_PTR);
748 old_a0 = inw(ioaddr);
749 outw(i586mso,ioaddr+WRITE_PTR);
750 outw(0x55aa,ioaddr);
751 outw(i586mso,ioaddr+READ_PTR);
752 a0_0 = inw(ioaddr);
753 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
754 outw(0x5a5a,ioaddr);
755 outw(0x8000+i586mso,ioaddr+READ_PTR);
756 a1_0 = inw(ioaddr);
757 outw(i586mso,ioaddr+READ_PTR);
758 a0_1 = inw(ioaddr);
759 outw(i586mso,ioaddr+WRITE_PTR);
760 outw(0x1234,ioaddr);
761 outw(0x8000+i586mso,ioaddr+READ_PTR);
762 a1_1 = inw(ioaddr);
763
764 if ((a0_0 != a0_1) || (a1_0 != a1_1) ||
765 (a1_0 != 0x5a5a) || (a0_0 != 0x55aa))
766 {
767 printk("32k\n");
768 PRIV(dev)->rx_buf_end = 0x7ff6;
769 PRIV(dev)->num_tx_bufs = 4;
770 }
771 else
772 {
773 printk("64k\n");
774 PRIV(dev)->num_tx_bufs = 8;
775 PRIV(dev)->rx_buf_start = TX_BUF_START + (PRIV(dev)->num_tx_bufs*TX_BUF_SIZE);
776 PRIV(dev)->rx_buf_end = 0xfff6;
777 }
778
779 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
780 outw(old_a1,ioaddr);
781 outw(i586mso,ioaddr+WRITE_PTR);
782 outw(old_a0,ioaddr);
783 outw(old_wp,ioaddr+WRITE_PTR);
784 outw(old_rp,ioaddr+READ_PTR);
785 }
786
787 if (net_debug)
788 printk(version);
789 dev->open = eexp_open;
790 dev->stop = eexp_close;
791 dev->hard_start_xmit = eexp_xmit;
792 dev->get_stats = eexp_stats;
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("%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("%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 static void eexp_hw_rxmap(struct device *dev, unsigned short rx_buf)
1052 {
1053 struct net_local *lp = (struct net_local *)dev->priv;
1054 unsigned short ioaddr = dev->base_addr;
1055 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1056
1057 outw(rx_buf,ioaddr+WRITE_PTR);
1058 outw(0x0000,ioaddr);
1059 outw(0x0000,ioaddr);
1060 outw((rx_buf==lp->rx_last)?lp->rx_first:(rx_buf+RX_BUF_SIZE),ioaddr);
1061 outw(rx_buf+0x16,ioaddr);
1062 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1063 outw(0x8000,ioaddr);
1064 outw(-1,ioaddr);
1065 outw(rx_buf+0x20,ioaddr);
1066 outw(0x0000,ioaddr);
1067 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1068 outw(old_wp,ioaddr+WRITE_PTR);
1069 }
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080 static void eexp_hw_init586(struct device *dev)
1081 {
1082 struct net_local *lp = (struct net_local *)dev->priv;
1083 unsigned short ioaddr = dev->base_addr;
1084
1085 PRIV(dev)->started = 0;
1086 set_loopback;
1087
1088 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1089 outb(i586_RST,ioaddr+EEPROM_Ctrl);
1090
1091 {
1092 unsigned short wcnt;
1093 wcnt = 0;
1094 outw(0,ioaddr+WRITE_PTR);
1095 while ((wcnt+=2) != lp->rx_buf_end+12)
1096 outw(0,ioaddr);
1097 }
1098
1099 outw(lp->rx_buf_end,ioaddr+WRITE_PTR);
1100 outsw(ioaddr, start_code, sizeof(start_code)>>1);
1101 outw(CONF_HW_ADDR,ioaddr+WRITE_PTR);
1102 outsw(ioaddr,dev->dev_addr,3);
1103 eexp_hw_txinit(dev);
1104 eexp_hw_rxinit(dev);
1105 outw(0,ioaddr+WRITE_PTR);
1106 outw(1,ioaddr);
1107 outb(0,ioaddr+EEPROM_Ctrl);
1108 outw(0,ioaddr+SCB_CMD);
1109 outb(0,ioaddr+SIGNAL_CA);
1110 {
1111 unsigned short rboguscount=50,rfailcount=5;
1112 while (outw(0,ioaddr+READ_PTR),inw(ioaddr))
1113 {
1114 if (!--rboguscount)
1115 {
1116 printk("%s: i82586 reset timed out, kicking...\n",
1117 dev->name);
1118 outw(0,ioaddr+SCB_CMD);
1119 outb(0,ioaddr+SIGNAL_CA);
1120 rboguscount = 100;
1121 if (!--rfailcount)
1122 {
1123 printk("%s: i82586 not responding, giving up.\n",
1124 dev->name);
1125 return;
1126 }
1127 }
1128 }
1129 }
1130
1131 outw(CONF_LINK,ioaddr+SCB_CBL);
1132 outw(0,ioaddr+SCB_STATUS);
1133 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1134 outb(0,ioaddr+SIGNAL_CA);
1135 {
1136 unsigned short iboguscount=50,ifailcount=5;
1137 while (!inw(ioaddr+SCB_STATUS))
1138 {
1139 if (!--iboguscount)
1140 {
1141 if (--ifailcount)
1142 {
1143 printk("%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1144 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
1145 outw(CONF_LINK,ioaddr+SCB_CBL);
1146 outw(0,ioaddr+SCB_STATUS);
1147 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1148 outb(0,ioaddr+SIGNAL_CA);
1149 iboguscount = 100;
1150 }
1151 else
1152 {
1153 printk("%s: Failed to initialize i82586, giving up.\n",dev->name);
1154 return;
1155 }
1156 }
1157 }
1158 }
1159
1160 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1161 clear_loopback;
1162 lp->init_time = jiffies;
1163 if (PRIV(dev)->started)
1164 printk("%s: Uh? We haven't started yet\n",dev->name);
1165 return;
1166 }
1167
1168
1169
1170
1171
1172
1173
1174 static void eexp_hw_ASICrst(struct device *dev)
1175 {
1176 unsigned short ioaddr = dev->base_addr;
1177 unsigned short wrval = 0x0001,succount=0,boguscount=500;
1178
1179 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1180
1181 set_loopback;
1182
1183
1184 PRIV(dev)->started = 0;
1185 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1186 while (succount<20)
1187 {
1188 if (wrval == 0xffff)
1189 wrval = 0x0001;
1190 outw(0,ioaddr+WRITE_PTR);
1191 outw(wrval,ioaddr);
1192 outw(0,ioaddr+READ_PTR);
1193 if (wrval++ == inw(ioaddr))
1194 succount++;
1195 else
1196 {
1197 succount = 0;
1198 if (!boguscount--)
1199 {
1200 boguscount = 500;
1201 printk("%s: Having problems resetting EtherExpress ASIC, continuing...\n",
1202 dev->name);
1203 wrval = 0x0001;
1204 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1205 }
1206 }
1207 }
1208 outb(i586_RST,ioaddr+EEPROM_Ctrl);
1209 }
1210
1211
1212
1213
1214 #ifdef MODULE
1215
1216 #define EEXP_MAX_CARDS 4
1217 #define NAMELEN 8
1218
1219 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1220
1221 static struct device dev_eexp[EEXP_MAX_CARDS] =
1222 {
1223 NULL,
1224 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe
1225 };
1226
1227 int irq[EEXP_MAX_CARDS] = {0, };
1228 int io[EEXP_MAX_CARDS] = {0, };
1229
1230
1231
1232
1233
1234 int init_module(void)
1235 {
1236 int this_dev, found = 0;
1237
1238 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1239 struct device *dev = &dev_eexp[this_dev];
1240 dev->name = namelist + (NAMELEN*this_dev);
1241 dev->irq = irq[this_dev];
1242 dev->base_addr = io[this_dev];
1243 if (io[this_dev] == 0) {
1244 if (this_dev) break;
1245 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1246 }
1247 if (register_netdev(dev) != 0) {
1248 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1249 if (found != 0) return 0;
1250 return -ENXIO;
1251 }
1252 found++;
1253 }
1254 return 0;
1255 }
1256
1257 void cleanup_module(void)
1258 {
1259 int this_dev;
1260
1261 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1262 struct device *dev = &dev_eexp[this_dev];
1263 if (dev->priv != NULL) {
1264 kfree(dev->priv);
1265 dev->priv = NULL;
1266 release_region(dev->base_addr, EEXP_IO_EXTENT);
1267 unregister_netdev(dev);
1268 }
1269 }
1270 }
1271 #endif