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 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
734 if (!dev->priv)
735 return -ENOMEM;
736
737 memset(dev->priv, 0, sizeof(struct net_local));
738
739 eexp_hw_ASICrst(dev);
740
741 {
742 unsigned short i586mso = 0x023e;
743 unsigned short old_wp,old_rp,old_a0,old_a1;
744 unsigned short a0_0,a1_0,a0_1,a1_1;
745
746 old_wp = inw(ioaddr+WRITE_PTR);
747 old_rp = inw(ioaddr+READ_PTR);
748 outw(0x8000+i586mso,ioaddr+READ_PTR);
749 old_a1 = inw(ioaddr);
750 outw(i586mso,ioaddr+READ_PTR);
751 old_a0 = inw(ioaddr);
752 outw(i586mso,ioaddr+WRITE_PTR);
753 outw(0x55aa,ioaddr);
754 outw(i586mso,ioaddr+READ_PTR);
755 a0_0 = inw(ioaddr);
756 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
757 outw(0x5a5a,ioaddr);
758 outw(0x8000+i586mso,ioaddr+READ_PTR);
759 a1_0 = inw(ioaddr);
760 outw(i586mso,ioaddr+READ_PTR);
761 a0_1 = inw(ioaddr);
762 outw(i586mso,ioaddr+WRITE_PTR);
763 outw(0x1234,ioaddr);
764 outw(0x8000+i586mso,ioaddr+READ_PTR);
765 a1_1 = inw(ioaddr);
766
767 if ((a0_0 != a0_1) || (a1_0 != a1_1) ||
768 (a1_0 != 0x5a5a) || (a0_0 != 0x55aa))
769 {
770 printk("32k\n");
771 PRIV(dev)->rx_buf_end = 0x7ff6;
772 PRIV(dev)->num_tx_bufs = 4;
773 }
774 else
775 {
776 printk("64k\n");
777 PRIV(dev)->num_tx_bufs = 8;
778 PRIV(dev)->rx_buf_start = TX_BUF_START + (PRIV(dev)->num_tx_bufs*TX_BUF_SIZE);
779 PRIV(dev)->rx_buf_end = 0xfff6;
780 }
781
782 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
783 outw(old_a1,ioaddr);
784 outw(i586mso,ioaddr+WRITE_PTR);
785 outw(old_a0,ioaddr);
786 outw(old_wp,ioaddr+WRITE_PTR);
787 outw(old_rp,ioaddr+READ_PTR);
788 }
789
790 if (net_debug)
791 printk(version);
792 dev->open = eexp_open;
793 dev->stop = eexp_close;
794 dev->hard_start_xmit = eexp_xmit;
795 dev->get_stats = eexp_stats;
796 ether_setup(dev);
797 return 0;
798 }
799
800
801
802
803 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location)
804 {
805 unsigned short cmd = 0x180|(location&0x7f);
806 unsigned short rval = 0,wval = EC_CS|i586_RST;
807 int i;
808
809 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
810 for ( i=0x100 ; i ; i>>=1 )
811 {
812 if (cmd&i)
813 wval |= EC_Wr;
814 else
815 wval &= ~EC_Wr;
816
817 outb(wval,ioaddr+EEPROM_Ctrl);
818 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
819 eeprom_delay();
820 outb(wval,ioaddr+EEPROM_Ctrl);
821 eeprom_delay();
822 }
823 wval &= ~EC_Wr;
824 outb(wval,ioaddr+EEPROM_Ctrl);
825 for ( i=0x8000 ; i ; i>>=1 )
826 {
827 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
828 eeprom_delay();
829 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
830 rval |= i;
831 outb(wval,ioaddr+EEPROM_Ctrl);
832 eeprom_delay();
833 }
834 wval &= ~EC_CS;
835 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
836 eeprom_delay();
837 outb(wval,ioaddr+EEPROM_Ctrl);
838 eeprom_delay();
839 return rval;
840 }
841
842
843
844
845
846
847
848
849
850
851
852 static unsigned short eexp_hw_lasttxstat(struct device *dev)
853 {
854 struct net_local *lp = (struct net_local *)dev->priv;
855 unsigned short ioaddr = dev->base_addr;
856 unsigned short old_rp = inw(ioaddr+READ_PTR);
857 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
858 unsigned short tx_block = lp->tx_reap;
859 unsigned short status;
860
861 if (!test_bit(0,(void *)&dev->tbusy) && lp->tx_head==lp->tx_reap)
862 return 0x0000;
863
864 do
865 {
866 outw(tx_block,ioaddr+READ_PTR);
867 status = inw(ioaddr);
868 if (!Stat_Done(status))
869 {
870 lp->tx_link = tx_block;
871 outw(old_rp,ioaddr+READ_PTR);
872 outw(old_wp,ioaddr+WRITE_PTR);
873 return status;
874 }
875 else
876 {
877 lp->last_tx_restart = 0;
878 lp->stats.collisions += Stat_NoColl(status);
879 if (!Stat_OK(status))
880 {
881 if (Stat_Abort(status))
882 lp->stats.tx_aborted_errors++;
883 if (Stat_TNoCar(status) || Stat_TNoCTS(status))
884 lp->stats.tx_carrier_errors++;
885 if (Stat_TNoDMA(status))
886 lp->stats.tx_fifo_errors++;
887 }
888 else
889 lp->stats.tx_packets++;
890 }
891 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
892 lp->tx_reap = tx_block = TX_BUF_START;
893 else
894 lp->tx_reap = tx_block += TX_BUF_SIZE;
895 dev->tbusy = 0;
896 mark_bh(NET_BH);
897 }
898 while (lp->tx_reap != lp->tx_head);
899
900 lp->tx_link = lp->tx_tail + 0x08;
901 outw(old_rp,ioaddr+READ_PTR);
902 outw(old_wp,ioaddr+WRITE_PTR);
903
904 return status;
905 }
906
907
908
909
910
911
912
913
914 static void eexp_hw_txrestart(struct device *dev)
915 {
916 struct net_local *lp = (struct net_local *)dev->priv;
917 unsigned short ioaddr = dev->base_addr;
918
919 lp->last_tx_restart = lp->tx_link;
920 outw(lp->tx_link,ioaddr+SCB_CBL);
921 outw(SCB_CUstart,ioaddr+SCB_CMD);
922 outw(0,ioaddr+SCB_STATUS);
923 outb(0,ioaddr+SIGNAL_CA);
924
925 {
926 unsigned short boguscount=50,failcount=5;
927 while (!inw(ioaddr+SCB_STATUS))
928 {
929 if (!--boguscount)
930 {
931 if (--failcount)
932 {
933 printk("%s: CU start timed out, status %04x, cmd %04x\n",
934 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
935 outw(lp->tx_link,ioaddr+SCB_CBL);
936 outw(0,ioaddr+SCB_STATUS);
937 outw(SCB_CUstart,ioaddr+SCB_CMD);
938 outb(0,ioaddr+SIGNAL_CA);
939 boguscount = 100;
940 }
941 else
942 {
943 printk("%s: Failed to restart CU, resetting board...\n",dev->name);
944 eexp_hw_init586(dev);
945 dev->tbusy = 0;
946 mark_bh(NET_BH);
947 return;
948 }
949 }
950 }
951 }
952 }
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967 static void eexp_hw_txinit(struct device *dev)
968 {
969 struct net_local *lp = (struct net_local *)dev->priv;
970 unsigned short ioaddr = dev->base_addr;
971 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
972 unsigned short tx_block = TX_BUF_START;
973 unsigned short curtbuf;
974
975 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
976 {
977 outw(tx_block,ioaddr+WRITE_PTR);
978 outw(0x0000,ioaddr);
979 outw(Cmd_INT|Cmd_Xmit,ioaddr);
980 outw(tx_block+0x08,ioaddr);
981 outw(tx_block+0x0e,ioaddr);
982 outw(0x0000,ioaddr);
983 outw(0x0000,ioaddr);
984 outw(tx_block+0x08,ioaddr);
985 outw(0x8000,ioaddr);
986 outw(-1,ioaddr);
987 outw(tx_block+0x16,ioaddr);
988 outw(0x0000,ioaddr);
989 tx_block += TX_BUF_SIZE;
990 }
991 lp->tx_head = TX_BUF_START;
992 lp->tx_reap = TX_BUF_START;
993 lp->tx_tail = tx_block - TX_BUF_SIZE;
994 lp->tx_link = lp->tx_tail + 0x08;
995 lp->rx_buf_start = tx_block;
996 outw(old_wp,ioaddr+WRITE_PTR);
997 }
998
999
1000
1001 unsigned short rx_words[] =
1002 {
1003 0xfeed,0xf00d,0xf001,0x0505,0x2424,0x6565,0xdeaf
1004 };
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015 static void eexp_hw_rxinit(struct device *dev)
1016 {
1017 struct net_local *lp = (struct net_local *)dev->priv;
1018 unsigned short ioaddr = dev->base_addr;
1019 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1020 unsigned short rx_block = lp->rx_buf_start;
1021
1022 lp->num_rx_bufs = 0;
1023 lp->rx_first = rx_block;
1024 do
1025 {
1026 lp->num_rx_bufs++;
1027 outw(rx_block,ioaddr+WRITE_PTR);
1028 outw(0x0000,ioaddr);
1029 outw(0x0000,ioaddr);
1030 outw(rx_block+RX_BUF_SIZE,ioaddr);
1031 outw(rx_block+0x16,ioaddr);
1032 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1033 outw(0x8000,ioaddr);
1034 outw(-1,ioaddr);
1035 outw(rx_block+0x20,ioaddr);
1036 outw(0x0000,ioaddr);
1037 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1038 lp->rx_last = rx_block;
1039 rx_block += RX_BUF_SIZE;
1040 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1041
1042 outw(lp->rx_last+4,ioaddr+WRITE_PTR);
1043 outw(lp->rx_first,ioaddr);
1044
1045 outw(old_wp,ioaddr+WRITE_PTR);
1046 }
1047
1048
1049
1050
1051
1052
1053
1054 static void eexp_hw_rxmap(struct device *dev, unsigned short rx_buf)
1055 {
1056 struct net_local *lp = (struct net_local *)dev->priv;
1057 unsigned short ioaddr = dev->base_addr;
1058 unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1059
1060 outw(rx_buf,ioaddr+WRITE_PTR);
1061 outw(0x0000,ioaddr);
1062 outw(0x0000,ioaddr);
1063 outw((rx_buf==lp->rx_last)?lp->rx_first:(rx_buf+RX_BUF_SIZE),ioaddr);
1064 outw(rx_buf+0x16,ioaddr);
1065 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1066 outw(0x8000,ioaddr);
1067 outw(-1,ioaddr);
1068 outw(rx_buf+0x20,ioaddr);
1069 outw(0x0000,ioaddr);
1070 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1071 outw(old_wp,ioaddr+WRITE_PTR);
1072 }
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083 static void eexp_hw_init586(struct device *dev)
1084 {
1085 struct net_local *lp = (struct net_local *)dev->priv;
1086 unsigned short ioaddr = dev->base_addr;
1087
1088 PRIV(dev)->started = 0;
1089 set_loopback;
1090
1091 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1092 outb(i586_RST,ioaddr+EEPROM_Ctrl);
1093
1094 {
1095 unsigned short wcnt;
1096 wcnt = 0;
1097 outw(0,ioaddr+WRITE_PTR);
1098 while ((wcnt+=2) != lp->rx_buf_end+12)
1099 outw(0,ioaddr);
1100 }
1101
1102 outw(lp->rx_buf_end,ioaddr+WRITE_PTR);
1103 outsw(ioaddr, start_code, sizeof(start_code)>>1);
1104 outw(CONF_HW_ADDR,ioaddr+WRITE_PTR);
1105 outsw(ioaddr,dev->dev_addr,3);
1106 eexp_hw_txinit(dev);
1107 eexp_hw_rxinit(dev);
1108 outw(0,ioaddr+WRITE_PTR);
1109 outw(1,ioaddr);
1110 outb(0,ioaddr+EEPROM_Ctrl);
1111 outw(0,ioaddr+SCB_CMD);
1112 outb(0,ioaddr+SIGNAL_CA);
1113 {
1114 unsigned short rboguscount=50,rfailcount=5;
1115 while (outw(0,ioaddr+READ_PTR),inw(ioaddr))
1116 {
1117 if (!--rboguscount)
1118 {
1119 printk("%s: i82586 reset timed out, kicking...\n",
1120 dev->name);
1121 outw(0,ioaddr+SCB_CMD);
1122 outb(0,ioaddr+SIGNAL_CA);
1123 rboguscount = 100;
1124 if (!--rfailcount)
1125 {
1126 printk("%s: i82586 not responding, giving up.\n",
1127 dev->name);
1128 return;
1129 }
1130 }
1131 }
1132 }
1133
1134 outw(CONF_LINK,ioaddr+SCB_CBL);
1135 outw(0,ioaddr+SCB_STATUS);
1136 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1137 outb(0,ioaddr+SIGNAL_CA);
1138 {
1139 unsigned short iboguscount=50,ifailcount=5;
1140 while (!inw(ioaddr+SCB_STATUS))
1141 {
1142 if (!--iboguscount)
1143 {
1144 if (--ifailcount)
1145 {
1146 printk("%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1147 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
1148 outw(CONF_LINK,ioaddr+SCB_CBL);
1149 outw(0,ioaddr+SCB_STATUS);
1150 outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1151 outb(0,ioaddr+SIGNAL_CA);
1152 iboguscount = 100;
1153 }
1154 else
1155 {
1156 printk("%s: Failed to initialize i82586, giving up.\n",dev->name);
1157 return;
1158 }
1159 }
1160 }
1161 }
1162
1163 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1164 clear_loopback;
1165 lp->init_time = jiffies;
1166 if (PRIV(dev)->started)
1167 printk("%s: Uh? We haven't started yet\n",dev->name);
1168 return;
1169 }
1170
1171
1172
1173
1174
1175
1176
1177 static void eexp_hw_ASICrst(struct device *dev)
1178 {
1179 unsigned short ioaddr = dev->base_addr;
1180 unsigned short wrval = 0x0001,succount=0,boguscount=500;
1181
1182 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1183
1184 set_loopback;
1185
1186
1187 PRIV(dev)->started = 0;
1188 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1189 while (succount<20)
1190 {
1191 if (wrval == 0xffff)
1192 wrval = 0x0001;
1193 outw(0,ioaddr+WRITE_PTR);
1194 outw(wrval,ioaddr);
1195 outw(0,ioaddr+READ_PTR);
1196 if (wrval++ == inw(ioaddr))
1197 succount++;
1198 else
1199 {
1200 succount = 0;
1201 if (!boguscount--)
1202 {
1203 boguscount = 500;
1204 printk("%s: Having problems resetting EtherExpress ASIC, continuing...\n",
1205 dev->name);
1206 wrval = 0x0001;
1207 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1208 }
1209 }
1210 }
1211 outb(i586_RST,ioaddr+EEPROM_Ctrl);
1212 }
1213
1214
1215
1216
1217 #ifdef MODULE
1218
1219 #define EEXP_MAX_CARDS 4
1220 #define NAMELEN 8
1221
1222 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1223
1224 static struct device dev_eexp[EEXP_MAX_CARDS] =
1225 {
1226 NULL,
1227 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe
1228 };
1229
1230 int irq[EEXP_MAX_CARDS] = {0, };
1231 int io[EEXP_MAX_CARDS] = {0, };
1232
1233
1234
1235
1236
1237 int init_module(void)
1238 {
1239 int this_dev, found = 0;
1240
1241 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1242 struct device *dev = &dev_eexp[this_dev];
1243 dev->name = namelist + (NAMELEN*this_dev);
1244 dev->irq = irq[this_dev];
1245 dev->base_addr = io[this_dev];
1246 if (io[this_dev] == 0) {
1247 if (this_dev) break;
1248 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1249 }
1250 if (register_netdev(dev) != 0) {
1251 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1252 if (found != 0) return 0;
1253 return -ENXIO;
1254 }
1255 found++;
1256 }
1257 return 0;
1258 }
1259
1260 void cleanup_module(void)
1261 {
1262 int this_dev;
1263
1264 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1265 struct device *dev = &dev_eexp[this_dev];
1266 if (dev->priv != NULL) {
1267 kfree(dev->priv);
1268 dev->priv = NULL;
1269 release_region(dev->base_addr, EEXP_IO_EXTENT);
1270 unregister_netdev(dev);
1271 }
1272 }
1273 }
1274 #endif