Import 2.3.10pre5
[davej-history.git] / drivers / net / eexpress.c
blobf8088862ebc5f4fd928c9eb019a616be3b65aa0d
1 /* Intel EtherExpress 16 device driver for Linux
3 * Written by John Sullivan, 1995
4 * based on original code by Donald Becker, with changes by
5 * Alan Cox and Pauline Middelink.
7 * Support for 8-bit mode by Zoltan Szilagyi <zoltans@cs.arizona.edu>
9 * Many modifications, and currently maintained, by
10 * Philip Blundell <Philip.Blundell@pobox.com>
11 * Added the Compaq LTE Alan Cox <alan@redhat.com>
13 * Note - this driver is experimental still - it has problems on faster
14 * machines. Someone needs to sit down and go through it line by line with
15 * a databook...
18 /* The EtherExpress 16 is a fairly simple card, based on a shared-memory
19 * design using the i82586 Ethernet coprocessor. It bears no relationship,
20 * as far as I know, to the similarly-named "EtherExpress Pro" range.
22 * Historically, Linux support for these cards has been very bad. However,
23 * things seem to be getting better slowly.
26 /* If your card is confused about what sort of interface it has (eg it
27 * persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART'
28 * or 'SOFTSET /LISA' from DOS seems to help.
31 /* Here's the scoop on memory mapping.
33 * There are three ways to access EtherExpress card memory: either using the
34 * shared-memory mapping, or using PIO through the dataport, or using PIO
35 * through the "shadow memory" ports.
37 * The shadow memory system works by having the card map some of its memory
38 * as follows:
40 * (the low five bits of the SMPTR are ignored)
42 * base+0x4000..400f memory at SMPTR+0..15
43 * base+0x8000..800f memory at SMPTR+16..31
44 * base+0xc000..c007 dubious stuff (memory at SMPTR+16..23 apparently)
45 * base+0xc008..c00f memory at 0x0008..0x000f
47 * This last set (the one at c008) is particularly handy because the SCB
48 * lives at 0x0008. So that set of ports gives us easy random access to data
49 * in the SCB without having to mess around setting up pointers and the like.
50 * We always use this method to access the SCB (via the scb_xx() functions).
52 * Dataport access works by aiming the appropriate (read or write) pointer
53 * at the first address you're interested in, and then reading or writing from
54 * the dataport. The pointers auto-increment after each transfer. We use
55 * this for data transfer.
57 * We don't use the shared-memory system because it allegedly doesn't work on
58 * all cards, and because it's a bit more prone to go wrong (it's one more
59 * thing to configure...).
62 /* Known bugs:
64 * - The card seems to want to give us two interrupts every time something
65 * happens, where just one would be better.
70 * Note by Zoltan Szilagyi 10-12-96:
72 * I've succeeded in eliminating the "CU wedged" messages, and hence the
73 * lockups, which were only occurring with cards running in 8-bit mode ("force
74 * 8-bit operation" in Intel's SoftSet utility). This version of the driver
75 * sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the
76 * CU before submitting a packet for transmission, and then restarts it as soon
77 * as the process of handing the packet is complete. This is definitely an
78 * unnecessary slowdown if the card is running in 16-bit mode; therefore one
79 * should detect 16-bit vs 8-bit mode from the EEPROM settings and act
80 * accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for
81 * ftp's, which is significantly better than I get in DOS, so the overhead of
82 * stopping and restarting the CU with each transmit is not prohibitive in
83 * practice.
85 * Update by David Woodhouse 11/5/99:
87 * I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture.
88 * I assume that this is because 16-bit accesses are actually handled as two
89 * 8-bit accesses.
92 #ifdef __alpha__
93 #define LOCKUP16 1
94 #endif
95 #ifndef LOCKUP16
96 #define LOCKUP16 0
97 #endif
99 #include <linux/config.h>
100 #include <linux/module.h>
102 #include <linux/kernel.h>
103 #include <linux/sched.h>
104 #include <linux/types.h>
105 #include <linux/fcntl.h>
106 #include <linux/interrupt.h>
107 #include <linux/ptrace.h>
108 #include <linux/ioport.h>
109 #include <linux/string.h>
110 #include <linux/in.h>
111 #include <asm/system.h>
112 #include <asm/bitops.h>
113 #include <asm/io.h>
114 #include <asm/irq.h>
115 #include <linux/delay.h>
116 #include <linux/errno.h>
117 #include <linux/init.h>
119 #include <linux/netdevice.h>
120 #include <linux/etherdevice.h>
121 #include <linux/skbuff.h>
122 #include <linux/malloc.h>
124 #include <asm/spinlock.h>
126 #ifndef NET_DEBUG
127 #define NET_DEBUG 4
128 #endif
130 #include "eexpress.h"
132 #define EEXP_IO_EXTENT 16
135 * Private data declarations
138 struct net_local
140 struct net_device_stats stats;
141 unsigned long last_tx; /* jiffies when last transmit started */
142 unsigned long init_time; /* jiffies when eexp_hw_init586 called */
143 unsigned short rx_first; /* first rx buf, same as RX_BUF_START */
144 unsigned short rx_last; /* last rx buf */
145 unsigned short rx_ptr; /* first rx buf to look at */
146 unsigned short tx_head; /* next free tx buf */
147 unsigned short tx_reap; /* first in-use tx buf */
148 unsigned short tx_tail; /* previous tx buf to tx_head */
149 unsigned short tx_link; /* last known-executing tx buf */
150 unsigned short last_tx_restart; /* set to tx_link when we
151 restart the CU */
152 unsigned char started;
153 unsigned short rx_buf_start;
154 unsigned short rx_buf_end;
155 unsigned short num_tx_bufs;
156 unsigned short num_rx_bufs;
157 unsigned char width; /* 0 for 16bit, 1 for 8bit */
158 unsigned char was_promisc;
159 unsigned char old_mc_count;
160 spinlock_t lock;
163 /* This is the code and data that is downloaded to the EtherExpress card's
164 * memory at boot time.
167 static unsigned short start_code[] = {
168 /* 0x0000 */
169 0x0001, /* ISCP: busy - cleared after reset */
170 0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */
172 0x0000,0x0000, /* SCB: status, commands */
173 0x0000,0x0000, /* links to first command block,
174 first receive descriptor */
175 0x0000,0x0000, /* CRC error, alignment error counts */
176 0x0000,0x0000, /* out of resources, overrun error counts */
178 0x0000,0x0000, /* pad */
179 0x0000,0x0000,
181 /* 0x20 -- start of 82586 CU program */
182 #define CONF_LINK 0x20
183 0x0000,Cmd_Config,
184 0x0032, /* link to next command */
185 0x080c, /* 12 bytes follow : fifo threshold=8 */
186 0x2e40, /* don't rx bad frames
187 * SRDY/ARDY => ext. sync. : preamble len=8
188 * take addresses from data buffers
189 * 6 bytes/address
191 0x6000, /* default backoff method & priority
192 * interframe spacing = 0x60 */
193 0xf200, /* slot time=0x200
194 * max collision retry = 0xf */
195 #define CONF_PROMISC 0x2e
196 0x0000, /* no HDLC : normal CRC : enable broadcast
197 * disable promiscuous/multicast modes */
198 0x003c, /* minimum frame length = 60 octets) */
200 0x0000,Cmd_SetAddr,
201 0x003e, /* link to next command */
202 #define CONF_HWADDR 0x38
203 0x0000,0x0000,0x0000, /* hardware address placed here */
205 0x0000,Cmd_MCast,
206 0x0076, /* link to next command */
207 #define CONF_NR_MULTICAST 0x44
208 0x0000, /* number of multicast addresses */
209 #define CONF_MULTICAST 0x46
210 0x0000, 0x0000, 0x0000, /* some addresses */
211 0x0000, 0x0000, 0x0000,
212 0x0000, 0x0000, 0x0000,
213 0x0000, 0x0000, 0x0000,
214 0x0000, 0x0000, 0x0000,
215 0x0000, 0x0000, 0x0000,
216 0x0000, 0x0000, 0x0000,
217 0x0000, 0x0000, 0x0000,
219 #define CONF_DIAG_RESULT 0x76
220 0x0000, Cmd_Diag,
221 0x007c, /* link to next command */
223 0x0000,Cmd_TDR|Cmd_INT,
224 0x0084,
225 #define CONF_TDR_RESULT 0x82
226 0x0000,
228 0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
229 0x0084 /* dummy link */
232 /* maps irq number to EtherExpress magic value */
233 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
236 * Prototypes for Linux interface
239 extern int express_probe(struct device *dev);
240 static int eexp_open(struct device *dev);
241 static int eexp_close(struct device *dev);
242 static struct net_device_stats *eexp_stats(struct device *dev);
243 static int eexp_xmit(struct sk_buff *buf, struct device *dev);
245 static void eexp_irq(int irq, void *dev_addr, struct pt_regs *regs);
246 static void eexp_set_multicast(struct device *dev);
249 * Prototypes for hardware access functions
252 static void eexp_hw_rx_pio(struct device *dev);
253 static void eexp_hw_tx_pio(struct device *dev, unsigned short *buf,
254 unsigned short len);
255 static int eexp_hw_probe(struct device *dev,unsigned short ioaddr);
256 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
257 unsigned char location);
259 static unsigned short eexp_hw_lasttxstat(struct device *dev);
260 static void eexp_hw_txrestart(struct device *dev);
262 static void eexp_hw_txinit (struct device *dev);
263 static void eexp_hw_rxinit (struct device *dev);
265 static void eexp_hw_init586 (struct device *dev);
266 static void eexp_setup_filter (struct device *dev);
268 static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
269 enum eexp_iftype {AUI=0, BNC=1, TPE=2};
271 #define STARTED_RU 2
272 #define STARTED_CU 1
275 * Primitive hardware access functions.
278 static inline unsigned short scb_status(struct device *dev)
280 return inw(dev->base_addr + 0xc008);
283 static inline unsigned short scb_rdcmd(struct device *dev)
285 return inw(dev->base_addr + 0xc00a);
288 static inline void scb_command(struct device *dev, unsigned short cmd)
290 outw(cmd, dev->base_addr + 0xc00a);
293 static inline void scb_wrcbl(struct device *dev, unsigned short val)
295 outw(val, dev->base_addr + 0xc00c);
298 static inline void scb_wrrfa(struct device *dev, unsigned short val)
300 outw(val, dev->base_addr + 0xc00e);
303 static inline void set_loopback(struct device *dev)
305 outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
308 static inline void clear_loopback(struct device *dev)
310 outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
313 static inline unsigned short int SHADOW(short int addr)
315 addr &= 0x1f;
316 if (addr > 0xf) addr += 0x3ff0;
317 return addr + 0x4000;
321 * Linux interface
325 * checks for presence of EtherExpress card
328 int __init express_probe(struct device *dev)
330 unsigned short *port;
331 static unsigned short ports[] = { 0x300,0x310,0x270,0x320,0x340,0 };
332 unsigned short ioaddr = dev->base_addr;
334 if (ioaddr&0xfe00)
335 return eexp_hw_probe(dev,ioaddr);
336 else if (ioaddr)
337 return ENXIO;
339 for (port=&ports[0] ; *port ; port++ )
341 unsigned short sum = 0;
342 int i;
343 for ( i=0 ; i<4 ; i++ )
345 unsigned short t;
346 t = inb(*port + ID_PORT);
347 sum |= (t>>4) << ((t & 0x03)<<2);
349 if (sum==0xbaba && !eexp_hw_probe(dev,*port))
350 return 0;
352 return -ENODEV;
356 * open and initialize the adapter, ready for use
359 static int eexp_open(struct device *dev)
361 int irq = dev->irq;
362 unsigned short ioaddr = dev->base_addr;
363 struct net_local *lp = (struct net_local *)dev->priv;
365 #if NET_DEBUG > 6
366 printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
367 #endif
369 if (!irq || !irqrmap[irq])
370 return -ENXIO;
372 if (request_irq(irq,&eexp_irq,0,"EtherExpress",dev))
373 return -EAGAIN;
375 request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress");
376 request_region(ioaddr+0x4000, 16, "EtherExpress shadow");
377 request_region(ioaddr+0x8000, 16, "EtherExpress shadow");
378 request_region(ioaddr+0xc000, 16, "EtherExpress shadow");
379 dev->tbusy = 0;
380 dev->interrupt = 0;
382 if (lp->width) {
383 printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
384 outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
387 eexp_hw_init586(dev);
388 dev->start = 1;
389 MOD_INC_USE_COUNT;
390 #if NET_DEBUG > 6
391 printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
392 #endif
393 return 0;
397 * close and disable the interface, leaving the 586 in reset.
400 static int eexp_close(struct device *dev)
402 unsigned short ioaddr = dev->base_addr;
403 struct net_local *lp = dev->priv;
405 int irq = dev->irq;
407 dev->tbusy = 1;
408 dev->start = 0;
410 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
411 lp->started = 0;
412 scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
413 outb(0,ioaddr+SIGNAL_CA);
414 free_irq(irq,dev);
415 outb(i586_RST,ioaddr+EEPROM_Ctrl);
416 release_region(ioaddr, EEXP_IO_EXTENT);
417 release_region(ioaddr+0x4000, 16);
418 release_region(ioaddr+0x8000, 16);
419 release_region(ioaddr+0xc000, 16);
421 MOD_DEC_USE_COUNT;
422 return 0;
426 * Return interface stats
429 static struct net_device_stats *eexp_stats(struct device *dev)
431 struct net_local *lp = (struct net_local *)dev->priv;
433 return &lp->stats;
437 * This gets called when a higher level thinks we are broken. Check that
438 * nothing has become jammed in the CU.
441 static void unstick_cu(struct device *dev)
443 struct net_local *lp = (struct net_local *)dev->priv;
444 unsigned short ioaddr = dev->base_addr;
446 if (lp->started)
448 if ((jiffies - dev->trans_start)>50)
450 if (lp->tx_link==lp->last_tx_restart)
452 unsigned short boguscount=200,rsst;
453 printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
454 dev->name, scb_status(dev));
455 eexp_hw_txinit(dev);
456 lp->last_tx_restart = 0;
457 scb_wrcbl(dev, lp->tx_link);
458 scb_command(dev, SCB_CUstart);
459 outb(0,ioaddr+SIGNAL_CA);
460 while (!SCB_complete(rsst=scb_status(dev)))
462 if (!--boguscount)
464 boguscount=200;
465 printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
466 dev->name,rsst);
467 scb_wrcbl(dev, lp->tx_link);
468 scb_command(dev, SCB_CUstart);
469 outb(0,ioaddr+SIGNAL_CA);
472 dev->tbusy = 0;
473 mark_bh(NET_BH);
475 else
477 unsigned short status = scb_status(dev);
478 if (SCB_CUdead(status))
480 unsigned short txstatus = eexp_hw_lasttxstat(dev);
481 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
482 dev->name, status, txstatus);
483 eexp_hw_txrestart(dev);
485 else
487 unsigned short txstatus = eexp_hw_lasttxstat(dev);
488 if (dev->tbusy && !txstatus)
490 printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
491 dev->name,status,txstatus);
492 eexp_hw_init586(dev);
493 dev->tbusy = 0;
494 mark_bh(NET_BH);
496 else
498 printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
504 else
506 if ((jiffies-lp->init_time)>10)
508 unsigned short status = scb_status(dev);
509 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
510 dev->name, status);
511 eexp_hw_init586(dev);
512 dev->tbusy = 0;
513 mark_bh(NET_BH);
519 * Called to transmit a packet, or to allow us to right ourselves
520 * if the kernel thinks we've died.
522 static int eexp_xmit(struct sk_buff *buf, struct device *dev)
524 struct net_local *lp = (struct net_local *)dev->priv;
525 unsigned long flags;
527 #if NET_DEBUG > 6
528 printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
529 #endif
531 disable_irq(dev->irq);
534 * Best would be to use synchronize_irq(); spin_lock() here
535 * lets make it work first..
538 #ifdef CONFIG_SMP
539 spin_lock_irqsave(&lp->lock, flags);
540 #endif
542 /* If dev->tbusy is set, all our tx buffers are full but the kernel
543 * is calling us anyway. Check that nothing bad is happening.
545 if (dev->tbusy) {
546 int status = scb_status(dev);
547 unstick_cu(dev);
548 if ((jiffies - lp->last_tx) < HZ)
550 #ifdef CONFIG_SMP
551 spin_unlock_irqrestore(&lp->lock, flags);
552 #endif
554 return 1;
556 printk(KERN_INFO "%s: transmit timed out, %s?", dev->name,
557 (SCB_complete(status)?"lost interrupt":
558 "board on fire"));
559 lp->stats.tx_errors++;
560 dev->tbusy = 0;
561 lp->last_tx = jiffies;
562 if (!SCB_complete(status)) {
563 scb_command(dev, SCB_CUabort);
564 outb(0,dev->base_addr+SIGNAL_CA);
568 if (test_and_set_bit(0,(void *)&dev->tbusy))
570 lp->stats.tx_dropped++;
572 else
574 unsigned short length = (ETH_ZLEN < buf->len) ? buf->len :
575 ETH_ZLEN;
576 unsigned short *data = (unsigned short *)buf->data;
578 lp->stats.tx_bytes += length;
580 eexp_hw_tx_pio(dev,data,length);
582 dev_kfree_skb(buf);
583 #ifdef CONFIG_SMP
584 spin_unlock_irqrestore(&lp->lock, flags);
585 #endif
586 enable_irq(dev->irq);
587 return 0;
591 * Handle an EtherExpress interrupt
592 * If we've finished initializing, start the RU and CU up.
593 * If we've already started, reap tx buffers, handle any received packets,
594 * check to make sure we've not become wedged.
598 * Handle an EtherExpress interrupt
599 * If we've finished initializing, start the RU and CU up.
600 * If we've already started, reap tx buffers, handle any received packets,
601 * check to make sure we've not become wedged.
604 static unsigned short eexp_start_irq(struct device *dev,
605 unsigned short status)
607 unsigned short ack_cmd = SCB_ack(status);
608 struct net_local *lp = (struct net_local *)dev->priv;
609 unsigned short ioaddr = dev->base_addr;
610 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
611 short diag_status, tdr_status;
612 while (SCB_CUstat(status)==2)
613 status = scb_status(dev);
614 #if NET_DEBUG > 4
615 printk("%s: CU went non-active (status %04x)\n",
616 dev->name, status);
617 #endif
619 outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
620 diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
621 if (diag_status & 1<<11) {
622 printk(KERN_WARNING "%s: 82586 failed self-test\n",
623 dev->name);
624 } else if (!(diag_status & 1<<13)) {
625 printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
628 outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
629 tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
630 if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
631 printk(KERN_WARNING "%s: TDR reports cable %s at %d tick%s\n", dev->name, (tdr_status & TDR_SHORT)?"short":"broken", tdr_status & TDR_TIME, ((tdr_status & TDR_TIME) != 1) ? "s" : "");
633 else if (tdr_status & TDR_XCVRPROBLEM) {
634 printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
636 else if (tdr_status & TDR_LINKOK) {
637 #if NET_DEBUG > 4
638 printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
639 #endif
640 } else {
641 printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
642 tdr_status);
645 lp->started |= STARTED_CU;
646 scb_wrcbl(dev, lp->tx_link);
647 /* if the RU isn't running, start it now */
648 if (!(lp->started & STARTED_RU)) {
649 ack_cmd |= SCB_RUstart;
650 scb_wrrfa(dev, lp->rx_buf_start);
651 lp->rx_ptr = lp->rx_buf_start;
653 ack_cmd |= SCB_CUstart | 0x2000;
656 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
657 lp->started|=STARTED_RU;
659 return ack_cmd;
662 static void eexp_cmd_clear(struct device *dev)
664 unsigned long int oldtime = jiffies;
665 while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
666 if (scb_rdcmd(dev)) {
667 printk("%s: command didn't clear\n", dev->name);
671 static void eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
673 struct device *dev = dev_info;
674 struct net_local *lp;
675 unsigned short ioaddr,status,ack_cmd;
676 unsigned short old_read_ptr, old_write_ptr;
678 if (dev==NULL)
680 printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
681 irq);
682 return;
685 lp = (struct net_local *)dev->priv;
686 ioaddr = dev->base_addr;
688 spin_lock(&lp->lock);
690 old_read_ptr = inw(ioaddr+READ_PTR);
691 old_write_ptr = inw(ioaddr+WRITE_PTR);
693 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
696 dev->interrupt = 1;
698 status = scb_status(dev);
700 #if NET_DEBUG > 4
701 printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
702 #endif
704 if (lp->started == (STARTED_CU | STARTED_RU)) {
706 do {
707 eexp_cmd_clear(dev);
709 ack_cmd = SCB_ack(status);
710 scb_command(dev, ack_cmd);
711 outb(0,ioaddr+SIGNAL_CA);
713 eexp_cmd_clear(dev);
715 if (SCB_complete(status)) {
716 if (!eexp_hw_lasttxstat(dev)) {
717 printk("%s: tx interrupt but no status\n", dev->name);
721 if (SCB_rxdframe(status))
722 eexp_hw_rx_pio(dev);
724 status = scb_status(dev);
725 } while (status & 0xc000);
727 if (SCB_RUdead(status))
729 printk(KERN_WARNING "%s: RU stopped: status %04x\n",
730 dev->name,status);
731 #if 0
732 printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
733 outw(lp->cur_rfd, ioaddr+READ_PTR);
734 printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
735 outw(lp->cur_rfd+6, ioaddr+READ_PTR);
736 printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
737 outw(rbd, ioaddr+READ_PTR);
738 printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
739 outw(rbd+8, ioaddr+READ_PTR);
740 printk("[%04x]\n", inw(ioaddr+DATAPORT));
741 #endif
742 lp->stats.rx_errors++;
743 #if 1
744 eexp_hw_rxinit(dev);
745 #else
746 lp->cur_rfd = lp->first_rfd;
747 #endif
748 scb_wrrfa(dev, lp->rx_buf_start);
749 scb_command(dev, SCB_RUstart);
750 outb(0,ioaddr+SIGNAL_CA);
752 } else {
753 if (status & 0x8000)
754 ack_cmd = eexp_start_irq(dev, status);
755 else
756 ack_cmd = SCB_ack(status);
757 scb_command(dev, ack_cmd);
758 outb(0,ioaddr+SIGNAL_CA);
761 eexp_cmd_clear(dev);
763 outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
765 dev->interrupt = 0;
766 #if NET_DEBUG > 6
767 printk("%s: leaving eexp_irq()\n", dev->name);
768 #endif
769 outw(old_read_ptr, ioaddr+READ_PTR);
770 outw(old_write_ptr, ioaddr+WRITE_PTR);
772 spin_unlock(&lp->lock);
773 return;
777 * Hardware access functions
781 * Set the cable type to use.
784 static void eexp_hw_set_interface(struct device *dev)
786 unsigned char oldval = inb(dev->base_addr + 0x300e);
787 oldval &= ~0x82;
788 switch (dev->if_port) {
789 case TPE:
790 oldval |= 0x2;
791 case BNC:
792 oldval |= 0x80;
793 break;
795 outb(oldval, dev->base_addr+0x300e);
796 mdelay(20);
800 * Check all the receive buffers, and hand any received packets
801 * to the upper levels. Basic sanity check on each frame
802 * descriptor, though we don't bother trying to fix broken ones.
805 static void eexp_hw_rx_pio(struct device *dev)
807 struct net_local *lp = (struct net_local *)dev->priv;
808 unsigned short rx_block = lp->rx_ptr;
809 unsigned short boguscount = lp->num_rx_bufs;
810 unsigned short ioaddr = dev->base_addr;
811 unsigned short status;
813 #if NET_DEBUG > 6
814 printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
815 #endif
817 do {
818 unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
820 outw(rx_block, ioaddr + READ_PTR);
821 status = inw(ioaddr + DATAPORT);
823 if (FD_Done(status))
825 rfd_cmd = inw(ioaddr + DATAPORT);
826 rx_next = inw(ioaddr + DATAPORT);
827 pbuf = inw(ioaddr + DATAPORT);
829 outw(pbuf, ioaddr + READ_PTR);
830 pkt_len = inw(ioaddr + DATAPORT);
832 if (rfd_cmd!=0x0000)
834 printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
835 dev->name, rfd_cmd);
836 continue;
838 else if (pbuf!=rx_block+0x16)
840 printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
841 dev->name, rx_block+0x16, pbuf);
842 continue;
844 else if ((pkt_len & 0xc000)!=0xc000)
846 printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
847 dev->name, pkt_len & 0xc000);
848 continue;
850 else if (!FD_OK(status))
852 lp->stats.rx_errors++;
853 if (FD_CRC(status))
854 lp->stats.rx_crc_errors++;
855 if (FD_Align(status))
856 lp->stats.rx_frame_errors++;
857 if (FD_Resrc(status))
858 lp->stats.rx_fifo_errors++;
859 if (FD_DMA(status))
860 lp->stats.rx_over_errors++;
861 if (FD_Short(status))
862 lp->stats.rx_length_errors++;
864 else
866 struct sk_buff *skb;
867 pkt_len &= 0x3fff;
868 skb = dev_alloc_skb(pkt_len+16);
869 if (skb == NULL)
871 printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
872 lp->stats.rx_dropped++;
873 break;
875 skb->dev = dev;
876 skb_reserve(skb, 2);
877 outw(pbuf+10, ioaddr+READ_PTR);
878 insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
879 skb->protocol = eth_type_trans(skb,dev);
880 netif_rx(skb);
881 lp->stats.rx_packets++;
882 lp->stats.rx_bytes += pkt_len;
884 outw(rx_block, ioaddr+WRITE_PTR);
885 outw(0, ioaddr+DATAPORT);
886 outw(0, ioaddr+DATAPORT);
887 rx_block = rx_next;
889 } while (FD_Done(status) && boguscount--);
890 lp->rx_ptr = rx_block;
894 * Hand a packet to the card for transmission
895 * If we get here, we MUST have already checked
896 * to make sure there is room in the transmit
897 * buffer region.
900 static void eexp_hw_tx_pio(struct device *dev, unsigned short *buf,
901 unsigned short len)
903 struct net_local *lp = (struct net_local *)dev->priv;
904 unsigned short ioaddr = dev->base_addr;
906 if (LOCKUP16 || lp->width) {
907 /* Stop the CU so that there is no chance that it
908 jumps off to a bogus address while we are writing the
909 pointer to the next transmit packet in 8-bit mode --
910 this eliminates the "CU wedged" errors in 8-bit mode.
911 (Zoltan Szilagyi 10-12-96) */
912 scb_command(dev, SCB_CUsuspend);
913 outw(0xFFFF, ioaddr+SIGNAL_CA);
916 outw(lp->tx_head, ioaddr + WRITE_PTR);
918 outw(0x0000, ioaddr + DATAPORT);
919 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
920 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
921 outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
923 outw(0x0000, ioaddr + DATAPORT);
924 outw(0x0000, ioaddr + DATAPORT);
925 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
927 outw(0x8000|len, ioaddr + DATAPORT);
928 outw(-1, ioaddr + DATAPORT);
929 outw(lp->tx_head+0x16, ioaddr + DATAPORT);
930 outw(0, ioaddr + DATAPORT);
932 outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
934 outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
935 outw(lp->tx_head, ioaddr + DATAPORT);
937 dev->trans_start = jiffies;
938 lp->tx_tail = lp->tx_head;
939 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
940 lp->tx_head = TX_BUF_START;
941 else
942 lp->tx_head += TX_BUF_SIZE;
943 if (lp->tx_head != lp->tx_reap)
944 dev->tbusy = 0;
946 if (LOCKUP16 || lp->width) {
947 /* Restart the CU so that the packet can actually
948 be transmitted. (Zoltan Szilagyi 10-12-96) */
949 scb_command(dev, SCB_CUresume);
950 outw(0xFFFF, ioaddr+SIGNAL_CA);
953 lp->stats.tx_packets++;
954 lp->last_tx = jiffies;
958 * Sanity check the suspected EtherExpress card
959 * Read hardware address, reset card, size memory and initialize buffer
960 * memory pointers. These are held in dev->priv, in case someone has more
961 * than one card in a machine.
964 static int __init eexp_hw_probe(struct device *dev, unsigned short ioaddr)
966 unsigned short hw_addr[3];
967 unsigned char buswidth;
968 unsigned int memory_size;
969 int i;
970 unsigned short xsum = 0;
971 struct net_local *lp;
973 printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
975 outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
976 outb(0, ioaddr+EEPROM_Ctrl);
977 udelay(500);
978 outb(i586_RST, ioaddr+EEPROM_Ctrl);
980 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
981 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
982 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
984 /* Standard Address or Compaq LTE Address */
985 if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
986 (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
988 printk(" rejected: invalid address %04x%04x%04x\n",
989 hw_addr[2],hw_addr[1],hw_addr[0]);
990 return -ENODEV;
993 /* Calculate the EEPROM checksum. Carry on anyway if it's bad,
994 * though.
996 for (i = 0; i < 64; i++)
997 xsum += eexp_hw_readeeprom(ioaddr, i);
998 if (xsum != 0xbaba)
999 printk(" (bad EEPROM xsum 0x%02x)", xsum);
1001 dev->base_addr = ioaddr;
1002 for ( i=0 ; i<6 ; i++ )
1003 dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
1006 static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
1007 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
1009 /* Use the IRQ from EEPROM if none was given */
1010 if (!dev->irq)
1011 dev->irq = irqmap[setupval>>13];
1013 dev->if_port = !(setupval & 0x1000) ? AUI :
1014 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
1016 buswidth = !((setupval & 0x400) >> 10);
1019 dev->priv = lp = kmalloc(sizeof(struct net_local), GFP_KERNEL);
1020 if (!dev->priv)
1021 return ENOMEM;
1023 memset(dev->priv, 0, sizeof(struct net_local));
1025 printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
1026 eexp_ifmap[dev->if_port], buswidth?8:16);
1028 eexp_hw_set_interface(dev);
1030 /* Find out how much RAM we have on the card */
1031 outw(0, dev->base_addr + WRITE_PTR);
1032 for (i = 0; i < 32768; i++)
1033 outw(0, dev->base_addr + DATAPORT);
1035 for (memory_size = 0; memory_size < 64; memory_size++)
1037 outw(memory_size<<10, dev->base_addr + READ_PTR);
1038 if (inw(dev->base_addr+DATAPORT))
1039 break;
1040 outw(memory_size<<10, dev->base_addr + WRITE_PTR);
1041 outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
1042 outw(memory_size<<10, dev->base_addr + READ_PTR);
1043 if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
1044 break;
1047 /* Sort out the number of buffers. We may have 16, 32, 48 or 64k
1048 * of RAM to play with.
1050 lp->num_tx_bufs = 4;
1051 lp->rx_buf_end = 0x3ff6;
1052 switch (memory_size)
1054 case 64:
1055 lp->rx_buf_end += 0x4000;
1056 case 48:
1057 lp->num_tx_bufs += 4;
1058 lp->rx_buf_end += 0x4000;
1059 case 32:
1060 lp->rx_buf_end += 0x4000;
1061 case 16:
1062 printk(", %dk RAM)\n", memory_size);
1063 break;
1064 default:
1065 printk(") bad memory size (%dk).\n", memory_size);
1066 kfree(dev->priv);
1067 return ENODEV;
1068 break;
1071 lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
1072 lp->width = buswidth;
1074 dev->open = eexp_open;
1075 dev->stop = eexp_close;
1076 dev->hard_start_xmit = eexp_xmit;
1077 dev->get_stats = eexp_stats;
1078 dev->set_multicast_list = &eexp_set_multicast;
1079 ether_setup(dev);
1080 return 0;
1084 * Read a word from the EtherExpress on-board serial EEPROM.
1085 * The EEPROM contains 64 words of 16 bits.
1087 static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
1088 unsigned char location)
1090 unsigned short cmd = 0x180|(location&0x7f);
1091 unsigned short rval = 0,wval = EC_CS|i586_RST;
1092 int i;
1094 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
1095 for (i=0x100 ; i ; i>>=1 )
1097 if (cmd&i)
1098 wval |= EC_Wr;
1099 else
1100 wval &= ~EC_Wr;
1102 outb(wval,ioaddr+EEPROM_Ctrl);
1103 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1104 eeprom_delay();
1105 outb(wval,ioaddr+EEPROM_Ctrl);
1106 eeprom_delay();
1108 wval &= ~EC_Wr;
1109 outb(wval,ioaddr+EEPROM_Ctrl);
1110 for (i=0x8000 ; i ; i>>=1 )
1112 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1113 eeprom_delay();
1114 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
1115 rval |= i;
1116 outb(wval,ioaddr+EEPROM_Ctrl);
1117 eeprom_delay();
1119 wval &= ~EC_CS;
1120 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1121 eeprom_delay();
1122 outb(wval,ioaddr+EEPROM_Ctrl);
1123 eeprom_delay();
1124 return rval;
1128 * Reap tx buffers and return last transmit status.
1129 * if ==0 then either:
1130 * a) we're not transmitting anything, so why are we here?
1131 * b) we've died.
1132 * otherwise, Stat_Busy(return) means we've still got some packets
1133 * to transmit, Stat_Done(return) means our buffers should be empty
1134 * again
1137 static unsigned short eexp_hw_lasttxstat(struct device *dev)
1139 struct net_local *lp = (struct net_local *)dev->priv;
1140 unsigned short tx_block = lp->tx_reap;
1141 unsigned short status;
1143 if ((!dev->tbusy) && lp->tx_head==lp->tx_reap)
1144 return 0x0000;
1148 outw(tx_block & ~31, dev->base_addr + SM_PTR);
1149 status = inw(dev->base_addr + SHADOW(tx_block));
1150 if (!Stat_Done(status))
1152 lp->tx_link = tx_block;
1153 return status;
1155 else
1157 lp->last_tx_restart = 0;
1158 lp->stats.collisions += Stat_NoColl(status);
1159 if (!Stat_OK(status))
1161 char *whatsup = NULL;
1162 lp->stats.tx_errors++;
1163 if (Stat_Abort(status))
1164 lp->stats.tx_aborted_errors++;
1165 if (Stat_TNoCar(status)) {
1166 whatsup = "aborted, no carrier";
1167 lp->stats.tx_carrier_errors++;
1169 if (Stat_TNoCTS(status)) {
1170 whatsup = "aborted, lost CTS";
1171 lp->stats.tx_carrier_errors++;
1173 if (Stat_TNoDMA(status)) {
1174 whatsup = "FIFO underran";
1175 lp->stats.tx_fifo_errors++;
1177 if (Stat_TXColl(status)) {
1178 whatsup = "aborted, too many collisions";
1179 lp->stats.tx_aborted_errors++;
1181 if (whatsup)
1182 printk(KERN_INFO "%s: transmit %s\n",
1183 dev->name, whatsup);
1185 else
1186 lp->stats.tx_packets++;
1188 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1189 lp->tx_reap = tx_block = TX_BUF_START;
1190 else
1191 lp->tx_reap = tx_block += TX_BUF_SIZE;
1192 dev->tbusy = 0;
1193 mark_bh(NET_BH);
1195 while (lp->tx_reap != lp->tx_head);
1197 lp->tx_link = lp->tx_tail + 0x08;
1199 return status;
1203 * This should never happen. It is called when some higher routine detects
1204 * that the CU has stopped, to try to restart it from the last packet we knew
1205 * we were working on, or the idle loop if we had finished for the time.
1208 static void eexp_hw_txrestart(struct device *dev)
1210 struct net_local *lp = (struct net_local *)dev->priv;
1211 unsigned short ioaddr = dev->base_addr;
1213 lp->last_tx_restart = lp->tx_link;
1214 scb_wrcbl(dev, lp->tx_link);
1215 scb_command(dev, SCB_CUstart);
1216 outb(0,ioaddr+SIGNAL_CA);
1219 unsigned short boguscount=50,failcount=5;
1220 while (!scb_status(dev))
1222 if (!--boguscount)
1224 if (--failcount)
1226 printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
1227 scb_wrcbl(dev, lp->tx_link);
1228 scb_command(dev, SCB_CUstart);
1229 outb(0,ioaddr+SIGNAL_CA);
1230 boguscount = 100;
1232 else
1234 printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
1235 eexp_hw_init586(dev);
1236 dev->tbusy = 0;
1237 mark_bh(NET_BH);
1238 return;
1246 * Writes down the list of transmit buffers into card memory. Each
1247 * entry consists of an 82586 transmit command, followed by a jump
1248 * pointing to itself. When we want to transmit a packet, we write
1249 * the data into the appropriate transmit buffer and then modify the
1250 * preceding jump to point at the new transmit command. This means that
1251 * the 586 command unit is continuously active.
1254 static void eexp_hw_txinit(struct device *dev)
1256 struct net_local *lp = (struct net_local *)dev->priv;
1257 unsigned short tx_block = TX_BUF_START;
1258 unsigned short curtbuf;
1259 unsigned short ioaddr = dev->base_addr;
1261 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
1263 outw(tx_block, ioaddr + WRITE_PTR);
1265 outw(0x0000, ioaddr + DATAPORT);
1266 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1267 outw(tx_block+0x08, ioaddr + DATAPORT);
1268 outw(tx_block+0x0e, ioaddr + DATAPORT);
1270 outw(0x0000, ioaddr + DATAPORT);
1271 outw(0x0000, ioaddr + DATAPORT);
1272 outw(tx_block+0x08, ioaddr + DATAPORT);
1274 outw(0x8000, ioaddr + DATAPORT);
1275 outw(-1, ioaddr + DATAPORT);
1276 outw(tx_block+0x16, ioaddr + DATAPORT);
1277 outw(0x0000, ioaddr + DATAPORT);
1279 tx_block += TX_BUF_SIZE;
1281 lp->tx_head = TX_BUF_START;
1282 lp->tx_reap = TX_BUF_START;
1283 lp->tx_tail = tx_block - TX_BUF_SIZE;
1284 lp->tx_link = lp->tx_tail + 0x08;
1285 lp->rx_buf_start = tx_block;
1290 * Write the circular list of receive buffer descriptors to card memory.
1291 * The end of the list isn't marked, which means that the 82586 receive
1292 * unit will loop until buffers become available (this avoids it giving us
1293 * "out of resources" messages).
1296 static void eexp_hw_rxinit(struct device *dev)
1298 struct net_local *lp = (struct net_local *)dev->priv;
1299 unsigned short rx_block = lp->rx_buf_start;
1300 unsigned short ioaddr = dev->base_addr;
1302 lp->num_rx_bufs = 0;
1303 lp->rx_first = lp->rx_ptr = rx_block;
1306 lp->num_rx_bufs++;
1308 outw(rx_block, ioaddr + WRITE_PTR);
1310 outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT);
1311 outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
1312 outw(0xffff, ioaddr+DATAPORT);
1314 outw(0x0000, ioaddr+DATAPORT);
1315 outw(0xdead, ioaddr+DATAPORT);
1316 outw(0xdead, ioaddr+DATAPORT);
1317 outw(0xdead, ioaddr+DATAPORT);
1318 outw(0xdead, ioaddr+DATAPORT);
1319 outw(0xdead, ioaddr+DATAPORT);
1320 outw(0xdead, ioaddr+DATAPORT);
1322 outw(0x0000, ioaddr+DATAPORT);
1323 outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
1324 outw(rx_block + 0x20, ioaddr+DATAPORT);
1325 outw(0, ioaddr+DATAPORT);
1326 outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
1328 lp->rx_last = rx_block;
1329 rx_block += RX_BUF_SIZE;
1330 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1333 /* Make first Rx frame descriptor point to first Rx buffer
1334 descriptor */
1335 outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
1336 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1338 /* Close Rx frame descriptor ring */
1339 outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
1340 outw(lp->rx_first, ioaddr+DATAPORT);
1342 /* Close Rx buffer descriptor ring */
1343 outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
1344 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1349 * Un-reset the 586, and start the configuration sequence. We don't wait for
1350 * this to finish, but allow the interrupt handler to start the CU and RU for
1351 * us. We can't start the receive/transmission system up before we know that
1352 * the hardware is configured correctly.
1355 static void eexp_hw_init586(struct device *dev)
1357 struct net_local *lp = (struct net_local *)dev->priv;
1358 unsigned short ioaddr = dev->base_addr;
1359 int i;
1361 #if NET_DEBUG > 6
1362 printk("%s: eexp_hw_init586()\n", dev->name);
1363 #endif
1365 lp->started = 0;
1367 set_loopback(dev);
1369 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1371 /* Download the startup code */
1372 outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
1373 outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
1374 outw(0x0000, ioaddr + 0x8008);
1375 outw(0x0000, ioaddr + 0x800a);
1376 outw(0x0000, ioaddr + 0x800c);
1377 outw(0x0000, ioaddr + 0x800e);
1379 for (i = 0; i < (sizeof(start_code)); i+=32) {
1380 int j;
1381 outw(i, ioaddr + SM_PTR);
1382 for (j = 0; j < 16; j+=2)
1383 outw(start_code[(i+j)/2],
1384 ioaddr+0x4000+j);
1385 for (j = 0; j < 16; j+=2)
1386 outw(start_code[(i+j+16)/2],
1387 ioaddr+0x8000+j);
1390 /* Do we want promiscuous mode or multicast? */
1391 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1392 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1393 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1394 ioaddr+SHADOW(CONF_PROMISC));
1395 lp->was_promisc = dev->flags & IFF_PROMISC;
1396 #if 0
1397 eexp_setup_filter(dev);
1398 #endif
1400 /* Write our hardware address */
1401 outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
1402 outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
1403 outw(((unsigned short *)dev->dev_addr)[1],
1404 ioaddr+SHADOW(CONF_HWADDR+2));
1405 outw(((unsigned short *)dev->dev_addr)[2],
1406 ioaddr+SHADOW(CONF_HWADDR+4));
1408 eexp_hw_txinit(dev);
1409 eexp_hw_rxinit(dev);
1411 outb(0,ioaddr+EEPROM_Ctrl);
1412 mdelay(5);
1414 scb_command(dev, 0xf000);
1415 outb(0,ioaddr+SIGNAL_CA);
1417 outw(0, ioaddr+SM_PTR);
1420 unsigned short rboguscount=50,rfailcount=5;
1421 while (inw(ioaddr+0x4000))
1423 if (!--rboguscount)
1425 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1426 dev->name);
1427 scb_command(dev, 0);
1428 outb(0,ioaddr+SIGNAL_CA);
1429 rboguscount = 100;
1430 if (!--rfailcount)
1432 printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1433 dev->name);
1434 return;
1440 scb_wrcbl(dev, CONF_LINK);
1441 scb_command(dev, 0xf000|SCB_CUstart);
1442 outb(0,ioaddr+SIGNAL_CA);
1445 unsigned short iboguscount=50,ifailcount=5;
1446 while (!scb_status(dev))
1448 if (!--iboguscount)
1450 if (--ifailcount)
1452 printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1453 dev->name, scb_status(dev), scb_rdcmd(dev));
1454 scb_wrcbl(dev, CONF_LINK);
1455 scb_command(dev, 0xf000|SCB_CUstart);
1456 outb(0,ioaddr+SIGNAL_CA);
1457 iboguscount = 100;
1459 else
1461 printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1462 return;
1468 clear_loopback(dev);
1469 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1471 lp->init_time = jiffies;
1472 #if NET_DEBUG > 6
1473 printk("%s: leaving eexp_hw_init586()\n", dev->name);
1474 #endif
1475 return;
1478 static void eexp_setup_filter(struct device *dev)
1480 struct dev_mc_list *dmi = dev->mc_list;
1481 unsigned short ioaddr = dev->base_addr;
1482 int count = dev->mc_count;
1483 int i;
1484 if (count > 8) {
1485 printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
1486 dev->name, count);
1487 count = 8;
1490 outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
1491 outw(count, ioaddr+SHADOW(CONF_NR_MULTICAST));
1492 for (i = 0; i < count; i++) {
1493 unsigned short *data = (unsigned short *)dmi->dmi_addr;
1494 if (!dmi) {
1495 printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
1496 break;
1498 if (dmi->dmi_addrlen != ETH_ALEN) {
1499 printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
1500 continue;
1502 outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
1503 outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
1504 outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
1505 outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
1506 outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
1507 outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
1512 * Set or clear the multicast filter for this adaptor.
1514 static void
1515 eexp_set_multicast(struct device *dev)
1517 unsigned short ioaddr = dev->base_addr;
1518 struct net_local *lp = (struct net_local *)dev->priv;
1519 int kick = 0, i;
1520 if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
1521 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1522 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1523 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1524 ioaddr+SHADOW(CONF_PROMISC));
1525 lp->was_promisc = dev->flags & IFF_PROMISC;
1526 kick = 1;
1528 if (!(dev->flags & IFF_PROMISC)) {
1529 eexp_setup_filter(dev);
1530 if (lp->old_mc_count != dev->mc_count) {
1531 kick = 1;
1532 lp->old_mc_count = dev->mc_count;
1535 if (kick) {
1536 unsigned long oj;
1537 scb_command(dev, SCB_CUsuspend);
1538 outb(0, ioaddr+SIGNAL_CA);
1539 outb(0, ioaddr+SIGNAL_CA);
1540 #if 0
1541 printk("%s: waiting for CU to go suspended\n", dev->name);
1542 #endif
1543 oj = jiffies;
1544 while ((SCB_CUstat(scb_status(dev)) == 2) &&
1545 ((jiffies-oj) < 2000));
1546 if (SCB_CUstat(scb_status(dev)) == 2)
1547 printk("%s: warning, CU didn't stop\n", dev->name);
1548 lp->started &= ~(STARTED_CU);
1549 scb_wrcbl(dev, CONF_LINK);
1550 scb_command(dev, SCB_CUstart);
1551 outb(0, ioaddr+SIGNAL_CA);
1557 * MODULE stuff
1560 #ifdef MODULE
1562 #define EEXP_MAX_CARDS 4 /* max number of cards to support */
1563 #define NAMELEN 8 /* max length of dev->name (inc null) */
1565 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1567 static struct device dev_eexp[EEXP_MAX_CARDS] =
1569 { NULL, /* will allocate dynamically */
1570 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe },
1573 static int irq[EEXP_MAX_CARDS] = {0, };
1574 static int io[EEXP_MAX_CARDS] = {0, };
1576 MODULE_PARM(io, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1577 MODULE_PARM(irq, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1579 /* Ideally the user would give us io=, irq= for every card. If any parameters
1580 * are specified, we verify and then use them. If no parameters are given, we
1581 * autoprobe for one card only.
1583 int init_module(void)
1585 int this_dev, found = 0;
1587 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1588 struct device *dev = &dev_eexp[this_dev];
1589 dev->name = namelist + (NAMELEN*this_dev);
1590 dev->irq = irq[this_dev];
1591 dev->base_addr = io[this_dev];
1592 if (io[this_dev] == 0) {
1593 if (this_dev) break;
1594 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1596 if (register_netdev(dev) != 0) {
1597 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1598 if (found != 0) return 0;
1599 return -ENXIO;
1601 found++;
1603 return 0;
1606 void cleanup_module(void)
1608 int this_dev;
1610 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1611 struct device *dev = &dev_eexp[this_dev];
1612 if (dev->priv != NULL) {
1613 unregister_netdev(dev);
1614 kfree(dev->priv);
1615 dev->priv = NULL;
1616 release_region(dev->base_addr, EEXP_IO_EXTENT);
1620 #endif
1623 * Local Variables:
1624 * c-file-style: "linux"
1625 * tab-width: 8
1626 * End: