OMAP3: PM: default defconfig for PM kernel testing
[linux-ginger.git] / drivers / net / eexpress.c
blob592de8f1668a9e78bff34f9116194eb3ec6babef
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 <philb@gnu.org>
11 * Added the Compaq LTE Alan Cox <alan@lxorguk.ukuu.org.uk>
12 * Added MCA support Adam Fritzler
14 * Note - this driver is experimental still - it has problems on faster
15 * machines. Someone needs to sit down and go through it line by line with
16 * a databook...
19 /* The EtherExpress 16 is a fairly simple card, based on a shared-memory
20 * design using the i82586 Ethernet coprocessor. It bears no relationship,
21 * as far as I know, to the similarly-named "EtherExpress Pro" range.
23 * Historically, Linux support for these cards has been very bad. However,
24 * things seem to be getting better slowly.
27 /* If your card is confused about what sort of interface it has (eg it
28 * persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART'
29 * or 'SOFTSET /LISA' from DOS seems to help.
32 /* Here's the scoop on memory mapping.
34 * There are three ways to access EtherExpress card memory: either using the
35 * shared-memory mapping, or using PIO through the dataport, or using PIO
36 * through the "shadow memory" ports.
38 * The shadow memory system works by having the card map some of its memory
39 * as follows:
41 * (the low five bits of the SMPTR are ignored)
43 * base+0x4000..400f memory at SMPTR+0..15
44 * base+0x8000..800f memory at SMPTR+16..31
45 * base+0xc000..c007 dubious stuff (memory at SMPTR+16..23 apparently)
46 * base+0xc008..c00f memory at 0x0008..0x000f
48 * This last set (the one at c008) is particularly handy because the SCB
49 * lives at 0x0008. So that set of ports gives us easy random access to data
50 * in the SCB without having to mess around setting up pointers and the like.
51 * We always use this method to access the SCB (via the scb_xx() functions).
53 * Dataport access works by aiming the appropriate (read or write) pointer
54 * at the first address you're interested in, and then reading or writing from
55 * the dataport. The pointers auto-increment after each transfer. We use
56 * this for data transfer.
58 * We don't use the shared-memory system because it allegedly doesn't work on
59 * all cards, and because it's a bit more prone to go wrong (it's one more
60 * thing to configure...).
63 /* Known bugs:
65 * - The card seems to want to give us two interrupts every time something
66 * happens, where just one would be better.
71 * Note by Zoltan Szilagyi 10-12-96:
73 * I've succeeded in eliminating the "CU wedged" messages, and hence the
74 * lockups, which were only occurring with cards running in 8-bit mode ("force
75 * 8-bit operation" in Intel's SoftSet utility). This version of the driver
76 * sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the
77 * CU before submitting a packet for transmission, and then restarts it as soon
78 * as the process of handing the packet is complete. This is definitely an
79 * unnecessary slowdown if the card is running in 16-bit mode; therefore one
80 * should detect 16-bit vs 8-bit mode from the EEPROM settings and act
81 * accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for
82 * ftp's, which is significantly better than I get in DOS, so the overhead of
83 * stopping and restarting the CU with each transmit is not prohibitive in
84 * practice.
86 * Update by David Woodhouse 11/5/99:
88 * I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture.
89 * I assume that this is because 16-bit accesses are actually handled as two
90 * 8-bit accesses.
93 #ifdef __alpha__
94 #define LOCKUP16 1
95 #endif
96 #ifndef LOCKUP16
97 #define LOCKUP16 0
98 #endif
100 #include <linux/module.h>
101 #include <linux/kernel.h>
102 #include <linux/types.h>
103 #include <linux/fcntl.h>
104 #include <linux/interrupt.h>
105 #include <linux/ioport.h>
106 #include <linux/string.h>
107 #include <linux/in.h>
108 #include <linux/delay.h>
109 #include <linux/errno.h>
110 #include <linux/init.h>
111 #include <linux/netdevice.h>
112 #include <linux/etherdevice.h>
113 #include <linux/skbuff.h>
114 #include <linux/slab.h>
115 #include <linux/mca-legacy.h>
116 #include <linux/spinlock.h>
117 #include <linux/bitops.h>
118 #include <linux/jiffies.h>
120 #include <asm/system.h>
121 #include <asm/io.h>
122 #include <asm/irq.h>
124 #ifndef NET_DEBUG
125 #define NET_DEBUG 4
126 #endif
128 #include "eexpress.h"
130 #define EEXP_IO_EXTENT 16
133 * Private data declarations
136 struct net_local
138 unsigned long last_tx; /* jiffies when last transmit started */
139 unsigned long init_time; /* jiffies when eexp_hw_init586 called */
140 unsigned short rx_first; /* first rx buf, same as RX_BUF_START */
141 unsigned short rx_last; /* last rx buf */
142 unsigned short rx_ptr; /* first rx buf to look at */
143 unsigned short tx_head; /* next free tx buf */
144 unsigned short tx_reap; /* first in-use tx buf */
145 unsigned short tx_tail; /* previous tx buf to tx_head */
146 unsigned short tx_link; /* last known-executing tx buf */
147 unsigned short last_tx_restart; /* set to tx_link when we
148 restart the CU */
149 unsigned char started;
150 unsigned short rx_buf_start;
151 unsigned short rx_buf_end;
152 unsigned short num_tx_bufs;
153 unsigned short num_rx_bufs;
154 unsigned char width; /* 0 for 16bit, 1 for 8bit */
155 unsigned char was_promisc;
156 unsigned char old_mc_count;
157 spinlock_t lock;
160 /* This is the code and data that is downloaded to the EtherExpress card's
161 * memory at boot time.
164 static unsigned short start_code[] = {
165 /* 0x0000 */
166 0x0001, /* ISCP: busy - cleared after reset */
167 0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */
169 0x0000,0x0000, /* SCB: status, commands */
170 0x0000,0x0000, /* links to first command block,
171 first receive descriptor */
172 0x0000,0x0000, /* CRC error, alignment error counts */
173 0x0000,0x0000, /* out of resources, overrun error counts */
175 0x0000,0x0000, /* pad */
176 0x0000,0x0000,
178 /* 0x20 -- start of 82586 CU program */
179 #define CONF_LINK 0x20
180 0x0000,Cmd_Config,
181 0x0032, /* link to next command */
182 0x080c, /* 12 bytes follow : fifo threshold=8 */
183 0x2e40, /* don't rx bad frames
184 * SRDY/ARDY => ext. sync. : preamble len=8
185 * take addresses from data buffers
186 * 6 bytes/address
188 0x6000, /* default backoff method & priority
189 * interframe spacing = 0x60 */
190 0xf200, /* slot time=0x200
191 * max collision retry = 0xf */
192 #define CONF_PROMISC 0x2e
193 0x0000, /* no HDLC : normal CRC : enable broadcast
194 * disable promiscuous/multicast modes */
195 0x003c, /* minimum frame length = 60 octets) */
197 0x0000,Cmd_SetAddr,
198 0x003e, /* link to next command */
199 #define CONF_HWADDR 0x38
200 0x0000,0x0000,0x0000, /* hardware address placed here */
202 0x0000,Cmd_MCast,
203 0x0076, /* link to next command */
204 #define CONF_NR_MULTICAST 0x44
205 0x0000, /* number of bytes in multicast address(es) */
206 #define CONF_MULTICAST 0x46
207 0x0000, 0x0000, 0x0000, /* some addresses */
208 0x0000, 0x0000, 0x0000,
209 0x0000, 0x0000, 0x0000,
210 0x0000, 0x0000, 0x0000,
211 0x0000, 0x0000, 0x0000,
212 0x0000, 0x0000, 0x0000,
213 0x0000, 0x0000, 0x0000,
214 0x0000, 0x0000, 0x0000,
216 #define CONF_DIAG_RESULT 0x76
217 0x0000, Cmd_Diag,
218 0x007c, /* link to next command */
220 0x0000,Cmd_TDR|Cmd_INT,
221 0x0084,
222 #define CONF_TDR_RESULT 0x82
223 0x0000,
225 0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
226 0x0084 /* dummy link */
229 /* maps irq number to EtherExpress magic value */
230 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
232 #ifdef CONFIG_MCA_LEGACY
233 /* mapping of the first four bits of the second POS register */
234 static unsigned short mca_iomap[] = {
235 0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200,
236 0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300
238 /* bits 5-7 of the second POS register */
239 static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 };
240 #endif
243 * Prototypes for Linux interface
246 static int eexp_open(struct net_device *dev);
247 static int eexp_close(struct net_device *dev);
248 static void eexp_timeout(struct net_device *dev);
249 static netdev_tx_t eexp_xmit(struct sk_buff *buf,
250 struct net_device *dev);
252 static irqreturn_t eexp_irq(int irq, void *dev_addr);
253 static void eexp_set_multicast(struct net_device *dev);
256 * Prototypes for hardware access functions
259 static void eexp_hw_rx_pio(struct net_device *dev);
260 static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
261 unsigned short len);
262 static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr);
263 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
264 unsigned char location);
266 static unsigned short eexp_hw_lasttxstat(struct net_device *dev);
267 static void eexp_hw_txrestart(struct net_device *dev);
269 static void eexp_hw_txinit (struct net_device *dev);
270 static void eexp_hw_rxinit (struct net_device *dev);
272 static void eexp_hw_init586 (struct net_device *dev);
273 static void eexp_setup_filter (struct net_device *dev);
275 static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
276 enum eexp_iftype {AUI=0, BNC=1, TPE=2};
278 #define STARTED_RU 2
279 #define STARTED_CU 1
282 * Primitive hardware access functions.
285 static inline unsigned short scb_status(struct net_device *dev)
287 return inw(dev->base_addr + 0xc008);
290 static inline unsigned short scb_rdcmd(struct net_device *dev)
292 return inw(dev->base_addr + 0xc00a);
295 static inline void scb_command(struct net_device *dev, unsigned short cmd)
297 outw(cmd, dev->base_addr + 0xc00a);
300 static inline void scb_wrcbl(struct net_device *dev, unsigned short val)
302 outw(val, dev->base_addr + 0xc00c);
305 static inline void scb_wrrfa(struct net_device *dev, unsigned short val)
307 outw(val, dev->base_addr + 0xc00e);
310 static inline void set_loopback(struct net_device *dev)
312 outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
315 static inline void clear_loopback(struct net_device *dev)
317 outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
320 static inline unsigned short int SHADOW(short int addr)
322 addr &= 0x1f;
323 if (addr > 0xf) addr += 0x3ff0;
324 return addr + 0x4000;
328 * Linux interface
332 * checks for presence of EtherExpress card
335 static int __init do_express_probe(struct net_device *dev)
337 unsigned short *port;
338 static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
339 unsigned short ioaddr = dev->base_addr;
340 int dev_irq = dev->irq;
341 int err;
343 dev->if_port = 0xff; /* not set */
345 #ifdef CONFIG_MCA_LEGACY
346 if (MCA_bus) {
347 int slot = 0;
350 * Only find one card at a time. Subsequent calls
351 * will find others, however, proper multicard MCA
352 * probing and setup can't be done with the
353 * old-style Space.c init routines. -- ASF
355 while (slot != MCA_NOTFOUND) {
356 int pos0, pos1;
358 slot = mca_find_unused_adapter(0x628B, slot);
359 if (slot == MCA_NOTFOUND)
360 break;
362 pos0 = mca_read_stored_pos(slot, 2);
363 pos1 = mca_read_stored_pos(slot, 3);
364 ioaddr = mca_iomap[pos1&0xf];
366 dev->irq = mca_irqmap[(pos1>>4)&0x7];
369 * XXX: Transciever selection is done
370 * differently on the MCA version.
371 * How to get it to select something
372 * other than external/AUI is currently
373 * unknown. This code is just for looks. -- ASF
375 if ((pos0 & 0x7) == 0x1)
376 dev->if_port = AUI;
377 else if ((pos0 & 0x7) == 0x5) {
378 if (pos1 & 0x80)
379 dev->if_port = BNC;
380 else
381 dev->if_port = TPE;
384 mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA");
385 mca_set_adapter_procfn(slot, NULL, dev);
386 mca_mark_as_used(slot);
388 break;
391 #endif
392 if (ioaddr&0xfe00) {
393 if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress"))
394 return -EBUSY;
395 err = eexp_hw_probe(dev,ioaddr);
396 release_region(ioaddr, EEXP_IO_EXTENT);
397 return err;
398 } else if (ioaddr)
399 return -ENXIO;
401 for (port=&ports[0] ; *port ; port++ )
403 unsigned short sum = 0;
404 int i;
405 if (!request_region(*port, EEXP_IO_EXTENT, "EtherExpress"))
406 continue;
407 for ( i=0 ; i<4 ; i++ )
409 unsigned short t;
410 t = inb(*port + ID_PORT);
411 sum |= (t>>4) << ((t & 0x03)<<2);
413 if (sum==0xbaba && !eexp_hw_probe(dev,*port)) {
414 release_region(*port, EEXP_IO_EXTENT);
415 return 0;
417 release_region(*port, EEXP_IO_EXTENT);
418 dev->irq = dev_irq;
420 return -ENODEV;
423 #ifndef MODULE
424 struct net_device * __init express_probe(int unit)
426 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
427 int err;
429 if (!dev)
430 return ERR_PTR(-ENOMEM);
432 sprintf(dev->name, "eth%d", unit);
433 netdev_boot_setup_check(dev);
435 err = do_express_probe(dev);
436 if (!err)
437 return dev;
438 free_netdev(dev);
439 return ERR_PTR(err);
441 #endif
444 * open and initialize the adapter, ready for use
447 static int eexp_open(struct net_device *dev)
449 int ret;
450 unsigned short ioaddr = dev->base_addr;
451 struct net_local *lp = netdev_priv(dev);
453 #if NET_DEBUG > 6
454 printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
455 #endif
457 if (!dev->irq || !irqrmap[dev->irq])
458 return -ENXIO;
460 ret = request_irq(dev->irq, &eexp_irq, 0, dev->name, dev);
461 if (ret)
462 return ret;
464 if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
465 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
466 , ioaddr);
467 goto err_out1;
469 if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
470 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
471 , ioaddr+0x4000);
472 goto err_out2;
474 if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
475 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
476 , ioaddr+0x8000);
477 goto err_out3;
479 if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
480 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
481 , ioaddr+0xc000);
482 goto err_out4;
485 if (lp->width) {
486 printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
487 outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
490 eexp_hw_init586(dev);
491 netif_start_queue(dev);
492 #if NET_DEBUG > 6
493 printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
494 #endif
495 return 0;
497 err_out4:
498 release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
499 err_out3:
500 release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
501 err_out2:
502 release_region(ioaddr, EEXP_IO_EXTENT);
503 err_out1:
504 free_irq(dev->irq, dev);
505 return -EBUSY;
509 * close and disable the interface, leaving the 586 in reset.
512 static int eexp_close(struct net_device *dev)
514 unsigned short ioaddr = dev->base_addr;
515 struct net_local *lp = netdev_priv(dev);
517 int irq = dev->irq;
519 netif_stop_queue(dev);
521 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
522 lp->started = 0;
523 scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
524 outb(0,ioaddr+SIGNAL_CA);
525 free_irq(irq,dev);
526 outb(i586_RST,ioaddr+EEPROM_Ctrl);
527 release_region(ioaddr, EEXP_IO_EXTENT);
528 release_region(ioaddr+0x4000, 16);
529 release_region(ioaddr+0x8000, 16);
530 release_region(ioaddr+0xc000, 16);
532 return 0;
536 * This gets called when a higher level thinks we are broken. Check that
537 * nothing has become jammed in the CU.
540 static void unstick_cu(struct net_device *dev)
542 struct net_local *lp = netdev_priv(dev);
543 unsigned short ioaddr = dev->base_addr;
545 if (lp->started)
547 if (time_after(jiffies, dev->trans_start + 50))
549 if (lp->tx_link==lp->last_tx_restart)
551 unsigned short boguscount=200,rsst;
552 printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
553 dev->name, scb_status(dev));
554 eexp_hw_txinit(dev);
555 lp->last_tx_restart = 0;
556 scb_wrcbl(dev, lp->tx_link);
557 scb_command(dev, SCB_CUstart);
558 outb(0,ioaddr+SIGNAL_CA);
559 while (!SCB_complete(rsst=scb_status(dev)))
561 if (!--boguscount)
563 boguscount=200;
564 printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
565 dev->name,rsst);
566 scb_wrcbl(dev, lp->tx_link);
567 scb_command(dev, SCB_CUstart);
568 outb(0,ioaddr+SIGNAL_CA);
571 netif_wake_queue(dev);
573 else
575 unsigned short status = scb_status(dev);
576 if (SCB_CUdead(status))
578 unsigned short txstatus = eexp_hw_lasttxstat(dev);
579 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
580 dev->name, status, txstatus);
581 eexp_hw_txrestart(dev);
583 else
585 unsigned short txstatus = eexp_hw_lasttxstat(dev);
586 if (netif_queue_stopped(dev) && !txstatus)
588 printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
589 dev->name,status,txstatus);
590 eexp_hw_init586(dev);
591 netif_wake_queue(dev);
593 else
595 printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
601 else
603 if (time_after(jiffies, lp->init_time + 10))
605 unsigned short status = scb_status(dev);
606 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
607 dev->name, status);
608 eexp_hw_init586(dev);
609 netif_wake_queue(dev);
614 static void eexp_timeout(struct net_device *dev)
616 struct net_local *lp = netdev_priv(dev);
617 #ifdef CONFIG_SMP
618 unsigned long flags;
619 #endif
620 int status;
622 disable_irq(dev->irq);
625 * Best would be to use synchronize_irq(); spin_lock() here
626 * lets make it work first..
629 #ifdef CONFIG_SMP
630 spin_lock_irqsave(&lp->lock, flags);
631 #endif
633 status = scb_status(dev);
634 unstick_cu(dev);
635 printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
636 (SCB_complete(status)?"lost interrupt":
637 "board on fire"));
638 dev->stats.tx_errors++;
639 lp->last_tx = jiffies;
640 if (!SCB_complete(status)) {
641 scb_command(dev, SCB_CUabort);
642 outb(0,dev->base_addr+SIGNAL_CA);
644 netif_wake_queue(dev);
645 #ifdef CONFIG_SMP
646 spin_unlock_irqrestore(&lp->lock, flags);
647 #endif
651 * Called to transmit a packet, or to allow us to right ourselves
652 * if the kernel thinks we've died.
654 static netdev_tx_t eexp_xmit(struct sk_buff *buf, struct net_device *dev)
656 short length = buf->len;
657 #ifdef CONFIG_SMP
658 struct net_local *lp = netdev_priv(dev);
659 unsigned long flags;
660 #endif
662 #if NET_DEBUG > 6
663 printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
664 #endif
666 if (buf->len < ETH_ZLEN) {
667 if (skb_padto(buf, ETH_ZLEN))
668 return NETDEV_TX_OK;
669 length = ETH_ZLEN;
672 disable_irq(dev->irq);
675 * Best would be to use synchronize_irq(); spin_lock() here
676 * lets make it work first..
679 #ifdef CONFIG_SMP
680 spin_lock_irqsave(&lp->lock, flags);
681 #endif
684 unsigned short *data = (unsigned short *)buf->data;
686 dev->stats.tx_bytes += length;
688 eexp_hw_tx_pio(dev,data,length);
690 dev_kfree_skb(buf);
691 #ifdef CONFIG_SMP
692 spin_unlock_irqrestore(&lp->lock, flags);
693 #endif
694 enable_irq(dev->irq);
695 return NETDEV_TX_OK;
699 * Handle an EtherExpress interrupt
700 * If we've finished initializing, start the RU and CU up.
701 * If we've already started, reap tx buffers, handle any received packets,
702 * check to make sure we've not become wedged.
705 static unsigned short eexp_start_irq(struct net_device *dev,
706 unsigned short status)
708 unsigned short ack_cmd = SCB_ack(status);
709 struct net_local *lp = netdev_priv(dev);
710 unsigned short ioaddr = dev->base_addr;
711 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
712 short diag_status, tdr_status;
713 while (SCB_CUstat(status)==2)
714 status = scb_status(dev);
715 #if NET_DEBUG > 4
716 printk("%s: CU went non-active (status %04x)\n",
717 dev->name, status);
718 #endif
720 outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
721 diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
722 if (diag_status & 1<<11) {
723 printk(KERN_WARNING "%s: 82586 failed self-test\n",
724 dev->name);
725 } else if (!(diag_status & 1<<13)) {
726 printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
729 outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
730 tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
731 if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
732 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" : "");
734 else if (tdr_status & TDR_XCVRPROBLEM) {
735 printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
737 else if (tdr_status & TDR_LINKOK) {
738 #if NET_DEBUG > 4
739 printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
740 #endif
741 } else {
742 printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
743 tdr_status);
746 lp->started |= STARTED_CU;
747 scb_wrcbl(dev, lp->tx_link);
748 /* if the RU isn't running, start it now */
749 if (!(lp->started & STARTED_RU)) {
750 ack_cmd |= SCB_RUstart;
751 scb_wrrfa(dev, lp->rx_buf_start);
752 lp->rx_ptr = lp->rx_buf_start;
753 lp->started |= STARTED_RU;
755 ack_cmd |= SCB_CUstart | 0x2000;
758 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
759 lp->started|=STARTED_RU;
761 return ack_cmd;
764 static void eexp_cmd_clear(struct net_device *dev)
766 unsigned long int oldtime = jiffies;
767 while (scb_rdcmd(dev) && (time_before(jiffies, oldtime + 10)));
768 if (scb_rdcmd(dev)) {
769 printk("%s: command didn't clear\n", dev->name);
773 static irqreturn_t eexp_irq(int dummy, void *dev_info)
775 struct net_device *dev = dev_info;
776 struct net_local *lp;
777 unsigned short ioaddr,status,ack_cmd;
778 unsigned short old_read_ptr, old_write_ptr;
780 lp = netdev_priv(dev);
781 ioaddr = dev->base_addr;
783 spin_lock(&lp->lock);
785 old_read_ptr = inw(ioaddr+READ_PTR);
786 old_write_ptr = inw(ioaddr+WRITE_PTR);
788 outb(SIRQ_dis|irqrmap[dev->irq], ioaddr+SET_IRQ);
790 status = scb_status(dev);
792 #if NET_DEBUG > 4
793 printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
794 #endif
796 if (lp->started == (STARTED_CU | STARTED_RU)) {
798 do {
799 eexp_cmd_clear(dev);
801 ack_cmd = SCB_ack(status);
802 scb_command(dev, ack_cmd);
803 outb(0,ioaddr+SIGNAL_CA);
805 eexp_cmd_clear(dev);
807 if (SCB_complete(status)) {
808 if (!eexp_hw_lasttxstat(dev)) {
809 printk("%s: tx interrupt but no status\n", dev->name);
813 if (SCB_rxdframe(status))
814 eexp_hw_rx_pio(dev);
816 status = scb_status(dev);
817 } while (status & 0xc000);
819 if (SCB_RUdead(status))
821 printk(KERN_WARNING "%s: RU stopped: status %04x\n",
822 dev->name,status);
823 #if 0
824 printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
825 outw(lp->cur_rfd, ioaddr+READ_PTR);
826 printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
827 outw(lp->cur_rfd+6, ioaddr+READ_PTR);
828 printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
829 outw(rbd, ioaddr+READ_PTR);
830 printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
831 outw(rbd+8, ioaddr+READ_PTR);
832 printk("[%04x]\n", inw(ioaddr+DATAPORT));
833 #endif
834 dev->stats.rx_errors++;
835 #if 1
836 eexp_hw_rxinit(dev);
837 #else
838 lp->cur_rfd = lp->first_rfd;
839 #endif
840 scb_wrrfa(dev, lp->rx_buf_start);
841 scb_command(dev, SCB_RUstart);
842 outb(0,ioaddr+SIGNAL_CA);
844 } else {
845 if (status & 0x8000)
846 ack_cmd = eexp_start_irq(dev, status);
847 else
848 ack_cmd = SCB_ack(status);
849 scb_command(dev, ack_cmd);
850 outb(0,ioaddr+SIGNAL_CA);
853 eexp_cmd_clear(dev);
855 outb(SIRQ_en|irqrmap[dev->irq], ioaddr+SET_IRQ);
857 #if NET_DEBUG > 6
858 printk("%s: leaving eexp_irq()\n", dev->name);
859 #endif
860 outw(old_read_ptr, ioaddr+READ_PTR);
861 outw(old_write_ptr, ioaddr+WRITE_PTR);
863 spin_unlock(&lp->lock);
864 return IRQ_HANDLED;
868 * Hardware access functions
872 * Set the cable type to use.
875 static void eexp_hw_set_interface(struct net_device *dev)
877 unsigned char oldval = inb(dev->base_addr + 0x300e);
878 oldval &= ~0x82;
879 switch (dev->if_port) {
880 case TPE:
881 oldval |= 0x2;
882 case BNC:
883 oldval |= 0x80;
884 break;
886 outb(oldval, dev->base_addr+0x300e);
887 mdelay(20);
891 * Check all the receive buffers, and hand any received packets
892 * to the upper levels. Basic sanity check on each frame
893 * descriptor, though we don't bother trying to fix broken ones.
896 static void eexp_hw_rx_pio(struct net_device *dev)
898 struct net_local *lp = netdev_priv(dev);
899 unsigned short rx_block = lp->rx_ptr;
900 unsigned short boguscount = lp->num_rx_bufs;
901 unsigned short ioaddr = dev->base_addr;
902 unsigned short status;
904 #if NET_DEBUG > 6
905 printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
906 #endif
908 do {
909 unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
911 outw(rx_block, ioaddr + READ_PTR);
912 status = inw(ioaddr + DATAPORT);
914 if (FD_Done(status))
916 rfd_cmd = inw(ioaddr + DATAPORT);
917 rx_next = inw(ioaddr + DATAPORT);
918 pbuf = inw(ioaddr + DATAPORT);
920 outw(pbuf, ioaddr + READ_PTR);
921 pkt_len = inw(ioaddr + DATAPORT);
923 if (rfd_cmd!=0x0000)
925 printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
926 dev->name, rfd_cmd);
927 continue;
929 else if (pbuf!=rx_block+0x16)
931 printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
932 dev->name, rx_block+0x16, pbuf);
933 continue;
935 else if ((pkt_len & 0xc000)!=0xc000)
937 printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
938 dev->name, pkt_len & 0xc000);
939 continue;
941 else if (!FD_OK(status))
943 dev->stats.rx_errors++;
944 if (FD_CRC(status))
945 dev->stats.rx_crc_errors++;
946 if (FD_Align(status))
947 dev->stats.rx_frame_errors++;
948 if (FD_Resrc(status))
949 dev->stats.rx_fifo_errors++;
950 if (FD_DMA(status))
951 dev->stats.rx_over_errors++;
952 if (FD_Short(status))
953 dev->stats.rx_length_errors++;
955 else
957 struct sk_buff *skb;
958 pkt_len &= 0x3fff;
959 skb = dev_alloc_skb(pkt_len+16);
960 if (skb == NULL)
962 printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
963 dev->stats.rx_dropped++;
964 break;
966 skb_reserve(skb, 2);
967 outw(pbuf+10, ioaddr+READ_PTR);
968 insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1);
969 skb->protocol = eth_type_trans(skb,dev);
970 netif_rx(skb);
971 dev->stats.rx_packets++;
972 dev->stats.rx_bytes += pkt_len;
974 outw(rx_block, ioaddr+WRITE_PTR);
975 outw(0, ioaddr+DATAPORT);
976 outw(0, ioaddr+DATAPORT);
977 rx_block = rx_next;
979 } while (FD_Done(status) && boguscount--);
980 lp->rx_ptr = rx_block;
984 * Hand a packet to the card for transmission
985 * If we get here, we MUST have already checked
986 * to make sure there is room in the transmit
987 * buffer region.
990 static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
991 unsigned short len)
993 struct net_local *lp = netdev_priv(dev);
994 unsigned short ioaddr = dev->base_addr;
996 if (LOCKUP16 || lp->width) {
997 /* Stop the CU so that there is no chance that it
998 jumps off to a bogus address while we are writing the
999 pointer to the next transmit packet in 8-bit mode --
1000 this eliminates the "CU wedged" errors in 8-bit mode.
1001 (Zoltan Szilagyi 10-12-96) */
1002 scb_command(dev, SCB_CUsuspend);
1003 outw(0xFFFF, ioaddr+SIGNAL_CA);
1006 outw(lp->tx_head, ioaddr + WRITE_PTR);
1008 outw(0x0000, ioaddr + DATAPORT);
1009 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1010 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1011 outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
1013 outw(0x0000, ioaddr + DATAPORT);
1014 outw(0x0000, ioaddr + DATAPORT);
1015 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1017 outw(0x8000|len, ioaddr + DATAPORT);
1018 outw(-1, ioaddr + DATAPORT);
1019 outw(lp->tx_head+0x16, ioaddr + DATAPORT);
1020 outw(0, ioaddr + DATAPORT);
1022 outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
1024 outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
1025 outw(lp->tx_head, ioaddr + DATAPORT);
1027 dev->trans_start = jiffies;
1028 lp->tx_tail = lp->tx_head;
1029 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1030 lp->tx_head = TX_BUF_START;
1031 else
1032 lp->tx_head += TX_BUF_SIZE;
1033 if (lp->tx_head != lp->tx_reap)
1034 netif_wake_queue(dev);
1036 if (LOCKUP16 || lp->width) {
1037 /* Restart the CU so that the packet can actually
1038 be transmitted. (Zoltan Szilagyi 10-12-96) */
1039 scb_command(dev, SCB_CUresume);
1040 outw(0xFFFF, ioaddr+SIGNAL_CA);
1043 dev->stats.tx_packets++;
1044 lp->last_tx = jiffies;
1047 static const struct net_device_ops eexp_netdev_ops = {
1048 .ndo_open = eexp_open,
1049 .ndo_stop = eexp_close,
1050 .ndo_start_xmit = eexp_xmit,
1051 .ndo_set_multicast_list = eexp_set_multicast,
1052 .ndo_tx_timeout = eexp_timeout,
1053 .ndo_change_mtu = eth_change_mtu,
1054 .ndo_set_mac_address = eth_mac_addr,
1055 .ndo_validate_addr = eth_validate_addr,
1059 * Sanity check the suspected EtherExpress card
1060 * Read hardware address, reset card, size memory and initialize buffer
1061 * memory pointers. These are held in netdev_priv(), in case someone has more
1062 * than one card in a machine.
1065 static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
1067 unsigned short hw_addr[3];
1068 unsigned char buswidth;
1069 unsigned int memory_size;
1070 int i;
1071 unsigned short xsum = 0;
1072 struct net_local *lp = netdev_priv(dev);
1074 printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
1076 outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
1077 outb(0, ioaddr+EEPROM_Ctrl);
1078 udelay(500);
1079 outb(i586_RST, ioaddr+EEPROM_Ctrl);
1081 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
1082 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
1083 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
1085 /* Standard Address or Compaq LTE Address */
1086 if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
1087 (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
1089 printk(" rejected: invalid address %04x%04x%04x\n",
1090 hw_addr[2],hw_addr[1],hw_addr[0]);
1091 return -ENODEV;
1094 /* Calculate the EEPROM checksum. Carry on anyway if it's bad,
1095 * though.
1097 for (i = 0; i < 64; i++)
1098 xsum += eexp_hw_readeeprom(ioaddr, i);
1099 if (xsum != 0xbaba)
1100 printk(" (bad EEPROM xsum 0x%02x)", xsum);
1102 dev->base_addr = ioaddr;
1103 for ( i=0 ; i<6 ; i++ )
1104 dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
1107 static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
1108 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
1110 /* Use the IRQ from EEPROM if none was given */
1111 if (!dev->irq)
1112 dev->irq = irqmap[setupval>>13];
1114 if (dev->if_port == 0xff) {
1115 dev->if_port = !(setupval & 0x1000) ? AUI :
1116 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
1119 buswidth = !((setupval & 0x400) >> 10);
1122 memset(lp, 0, sizeof(struct net_local));
1123 spin_lock_init(&lp->lock);
1125 printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
1126 eexp_ifmap[dev->if_port], buswidth?8:16);
1128 if (!request_region(dev->base_addr + 0x300e, 1, "EtherExpress"))
1129 return -EBUSY;
1131 eexp_hw_set_interface(dev);
1133 release_region(dev->base_addr + 0x300e, 1);
1135 /* Find out how much RAM we have on the card */
1136 outw(0, dev->base_addr + WRITE_PTR);
1137 for (i = 0; i < 32768; i++)
1138 outw(0, dev->base_addr + DATAPORT);
1140 for (memory_size = 0; memory_size < 64; memory_size++)
1142 outw(memory_size<<10, dev->base_addr + READ_PTR);
1143 if (inw(dev->base_addr+DATAPORT))
1144 break;
1145 outw(memory_size<<10, dev->base_addr + WRITE_PTR);
1146 outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
1147 outw(memory_size<<10, dev->base_addr + READ_PTR);
1148 if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
1149 break;
1152 /* Sort out the number of buffers. We may have 16, 32, 48 or 64k
1153 * of RAM to play with.
1155 lp->num_tx_bufs = 4;
1156 lp->rx_buf_end = 0x3ff6;
1157 switch (memory_size)
1159 case 64:
1160 lp->rx_buf_end += 0x4000;
1161 case 48:
1162 lp->num_tx_bufs += 4;
1163 lp->rx_buf_end += 0x4000;
1164 case 32:
1165 lp->rx_buf_end += 0x4000;
1166 case 16:
1167 printk(", %dk RAM)\n", memory_size);
1168 break;
1169 default:
1170 printk(") bad memory size (%dk).\n", memory_size);
1171 return -ENODEV;
1172 break;
1175 lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
1176 lp->width = buswidth;
1178 dev->netdev_ops = &eexp_netdev_ops;
1179 dev->watchdog_timeo = 2*HZ;
1181 return register_netdev(dev);
1185 * Read a word from the EtherExpress on-board serial EEPROM.
1186 * The EEPROM contains 64 words of 16 bits.
1188 static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
1189 unsigned char location)
1191 unsigned short cmd = 0x180|(location&0x7f);
1192 unsigned short rval = 0,wval = EC_CS|i586_RST;
1193 int i;
1195 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
1196 for (i=0x100 ; i ; i>>=1 )
1198 if (cmd&i)
1199 wval |= EC_Wr;
1200 else
1201 wval &= ~EC_Wr;
1203 outb(wval,ioaddr+EEPROM_Ctrl);
1204 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1205 eeprom_delay();
1206 outb(wval,ioaddr+EEPROM_Ctrl);
1207 eeprom_delay();
1209 wval &= ~EC_Wr;
1210 outb(wval,ioaddr+EEPROM_Ctrl);
1211 for (i=0x8000 ; i ; i>>=1 )
1213 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1214 eeprom_delay();
1215 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
1216 rval |= i;
1217 outb(wval,ioaddr+EEPROM_Ctrl);
1218 eeprom_delay();
1220 wval &= ~EC_CS;
1221 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1222 eeprom_delay();
1223 outb(wval,ioaddr+EEPROM_Ctrl);
1224 eeprom_delay();
1225 return rval;
1229 * Reap tx buffers and return last transmit status.
1230 * if ==0 then either:
1231 * a) we're not transmitting anything, so why are we here?
1232 * b) we've died.
1233 * otherwise, Stat_Busy(return) means we've still got some packets
1234 * to transmit, Stat_Done(return) means our buffers should be empty
1235 * again
1238 static unsigned short eexp_hw_lasttxstat(struct net_device *dev)
1240 struct net_local *lp = netdev_priv(dev);
1241 unsigned short tx_block = lp->tx_reap;
1242 unsigned short status;
1244 if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap)
1245 return 0x0000;
1249 outw(tx_block & ~31, dev->base_addr + SM_PTR);
1250 status = inw(dev->base_addr + SHADOW(tx_block));
1251 if (!Stat_Done(status))
1253 lp->tx_link = tx_block;
1254 return status;
1256 else
1258 lp->last_tx_restart = 0;
1259 dev->stats.collisions += Stat_NoColl(status);
1260 if (!Stat_OK(status))
1262 char *whatsup = NULL;
1263 dev->stats.tx_errors++;
1264 if (Stat_Abort(status))
1265 dev->stats.tx_aborted_errors++;
1266 if (Stat_TNoCar(status)) {
1267 whatsup = "aborted, no carrier";
1268 dev->stats.tx_carrier_errors++;
1270 if (Stat_TNoCTS(status)) {
1271 whatsup = "aborted, lost CTS";
1272 dev->stats.tx_carrier_errors++;
1274 if (Stat_TNoDMA(status)) {
1275 whatsup = "FIFO underran";
1276 dev->stats.tx_fifo_errors++;
1278 if (Stat_TXColl(status)) {
1279 whatsup = "aborted, too many collisions";
1280 dev->stats.tx_aborted_errors++;
1282 if (whatsup)
1283 printk(KERN_INFO "%s: transmit %s\n",
1284 dev->name, whatsup);
1286 else
1287 dev->stats.tx_packets++;
1289 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1290 lp->tx_reap = tx_block = TX_BUF_START;
1291 else
1292 lp->tx_reap = tx_block += TX_BUF_SIZE;
1293 netif_wake_queue(dev);
1295 while (lp->tx_reap != lp->tx_head);
1297 lp->tx_link = lp->tx_tail + 0x08;
1299 return status;
1303 * This should never happen. It is called when some higher routine detects
1304 * that the CU has stopped, to try to restart it from the last packet we knew
1305 * we were working on, or the idle loop if we had finished for the time.
1308 static void eexp_hw_txrestart(struct net_device *dev)
1310 struct net_local *lp = netdev_priv(dev);
1311 unsigned short ioaddr = dev->base_addr;
1313 lp->last_tx_restart = lp->tx_link;
1314 scb_wrcbl(dev, lp->tx_link);
1315 scb_command(dev, SCB_CUstart);
1316 outb(0,ioaddr+SIGNAL_CA);
1319 unsigned short boguscount=50,failcount=5;
1320 while (!scb_status(dev))
1322 if (!--boguscount)
1324 if (--failcount)
1326 printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
1327 scb_wrcbl(dev, lp->tx_link);
1328 scb_command(dev, SCB_CUstart);
1329 outb(0,ioaddr+SIGNAL_CA);
1330 boguscount = 100;
1332 else
1334 printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
1335 eexp_hw_init586(dev);
1336 netif_wake_queue(dev);
1337 return;
1345 * Writes down the list of transmit buffers into card memory. Each
1346 * entry consists of an 82586 transmit command, followed by a jump
1347 * pointing to itself. When we want to transmit a packet, we write
1348 * the data into the appropriate transmit buffer and then modify the
1349 * preceding jump to point at the new transmit command. This means that
1350 * the 586 command unit is continuously active.
1353 static void eexp_hw_txinit(struct net_device *dev)
1355 struct net_local *lp = netdev_priv(dev);
1356 unsigned short tx_block = TX_BUF_START;
1357 unsigned short curtbuf;
1358 unsigned short ioaddr = dev->base_addr;
1360 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
1362 outw(tx_block, ioaddr + WRITE_PTR);
1364 outw(0x0000, ioaddr + DATAPORT);
1365 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1366 outw(tx_block+0x08, ioaddr + DATAPORT);
1367 outw(tx_block+0x0e, ioaddr + DATAPORT);
1369 outw(0x0000, ioaddr + DATAPORT);
1370 outw(0x0000, ioaddr + DATAPORT);
1371 outw(tx_block+0x08, ioaddr + DATAPORT);
1373 outw(0x8000, ioaddr + DATAPORT);
1374 outw(-1, ioaddr + DATAPORT);
1375 outw(tx_block+0x16, ioaddr + DATAPORT);
1376 outw(0x0000, ioaddr + DATAPORT);
1378 tx_block += TX_BUF_SIZE;
1380 lp->tx_head = TX_BUF_START;
1381 lp->tx_reap = TX_BUF_START;
1382 lp->tx_tail = tx_block - TX_BUF_SIZE;
1383 lp->tx_link = lp->tx_tail + 0x08;
1384 lp->rx_buf_start = tx_block;
1389 * Write the circular list of receive buffer descriptors to card memory.
1390 * The end of the list isn't marked, which means that the 82586 receive
1391 * unit will loop until buffers become available (this avoids it giving us
1392 * "out of resources" messages).
1395 static void eexp_hw_rxinit(struct net_device *dev)
1397 struct net_local *lp = netdev_priv(dev);
1398 unsigned short rx_block = lp->rx_buf_start;
1399 unsigned short ioaddr = dev->base_addr;
1401 lp->num_rx_bufs = 0;
1402 lp->rx_first = lp->rx_ptr = rx_block;
1405 lp->num_rx_bufs++;
1407 outw(rx_block, ioaddr + WRITE_PTR);
1409 outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT);
1410 outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
1411 outw(0xffff, ioaddr+DATAPORT);
1413 outw(0x0000, ioaddr+DATAPORT);
1414 outw(0xdead, ioaddr+DATAPORT);
1415 outw(0xdead, ioaddr+DATAPORT);
1416 outw(0xdead, ioaddr+DATAPORT);
1417 outw(0xdead, ioaddr+DATAPORT);
1418 outw(0xdead, ioaddr+DATAPORT);
1419 outw(0xdead, ioaddr+DATAPORT);
1421 outw(0x0000, ioaddr+DATAPORT);
1422 outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
1423 outw(rx_block + 0x20, ioaddr+DATAPORT);
1424 outw(0, ioaddr+DATAPORT);
1425 outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
1427 lp->rx_last = rx_block;
1428 rx_block += RX_BUF_SIZE;
1429 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1432 /* Make first Rx frame descriptor point to first Rx buffer
1433 descriptor */
1434 outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
1435 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1437 /* Close Rx frame descriptor ring */
1438 outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
1439 outw(lp->rx_first, ioaddr+DATAPORT);
1441 /* Close Rx buffer descriptor ring */
1442 outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
1443 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1448 * Un-reset the 586, and start the configuration sequence. We don't wait for
1449 * this to finish, but allow the interrupt handler to start the CU and RU for
1450 * us. We can't start the receive/transmission system up before we know that
1451 * the hardware is configured correctly.
1454 static void eexp_hw_init586(struct net_device *dev)
1456 struct net_local *lp = netdev_priv(dev);
1457 unsigned short ioaddr = dev->base_addr;
1458 int i;
1460 #if NET_DEBUG > 6
1461 printk("%s: eexp_hw_init586()\n", dev->name);
1462 #endif
1464 lp->started = 0;
1466 set_loopback(dev);
1468 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1470 /* Download the startup code */
1471 outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
1472 outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
1473 outw(0x0000, ioaddr + 0x8008);
1474 outw(0x0000, ioaddr + 0x800a);
1475 outw(0x0000, ioaddr + 0x800c);
1476 outw(0x0000, ioaddr + 0x800e);
1478 for (i = 0; i < ARRAY_SIZE(start_code) * 2; i+=32) {
1479 int j;
1480 outw(i, ioaddr + SM_PTR);
1481 for (j = 0; j < 16 && (i+j)/2 < ARRAY_SIZE(start_code); j+=2)
1482 outw(start_code[(i+j)/2],
1483 ioaddr+0x4000+j);
1484 for (j = 0; j < 16 && (i+j+16)/2 < ARRAY_SIZE(start_code); j+=2)
1485 outw(start_code[(i+j+16)/2],
1486 ioaddr+0x8000+j);
1489 /* Do we want promiscuous mode or multicast? */
1490 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1491 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1492 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1493 ioaddr+SHADOW(CONF_PROMISC));
1494 lp->was_promisc = dev->flags & IFF_PROMISC;
1495 #if 0
1496 eexp_setup_filter(dev);
1497 #endif
1499 /* Write our hardware address */
1500 outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
1501 outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
1502 outw(((unsigned short *)dev->dev_addr)[1],
1503 ioaddr+SHADOW(CONF_HWADDR+2));
1504 outw(((unsigned short *)dev->dev_addr)[2],
1505 ioaddr+SHADOW(CONF_HWADDR+4));
1507 eexp_hw_txinit(dev);
1508 eexp_hw_rxinit(dev);
1510 outb(0,ioaddr+EEPROM_Ctrl);
1511 mdelay(5);
1513 scb_command(dev, 0xf000);
1514 outb(0,ioaddr+SIGNAL_CA);
1516 outw(0, ioaddr+SM_PTR);
1519 unsigned short rboguscount=50,rfailcount=5;
1520 while (inw(ioaddr+0x4000))
1522 if (!--rboguscount)
1524 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1525 dev->name);
1526 scb_command(dev, 0);
1527 outb(0,ioaddr+SIGNAL_CA);
1528 rboguscount = 100;
1529 if (!--rfailcount)
1531 printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1532 dev->name);
1533 return;
1539 scb_wrcbl(dev, CONF_LINK);
1540 scb_command(dev, 0xf000|SCB_CUstart);
1541 outb(0,ioaddr+SIGNAL_CA);
1544 unsigned short iboguscount=50,ifailcount=5;
1545 while (!scb_status(dev))
1547 if (!--iboguscount)
1549 if (--ifailcount)
1551 printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1552 dev->name, scb_status(dev), scb_rdcmd(dev));
1553 scb_wrcbl(dev, CONF_LINK);
1554 scb_command(dev, 0xf000|SCB_CUstart);
1555 outb(0,ioaddr+SIGNAL_CA);
1556 iboguscount = 100;
1558 else
1560 printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1561 return;
1567 clear_loopback(dev);
1568 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1570 lp->init_time = jiffies;
1571 #if NET_DEBUG > 6
1572 printk("%s: leaving eexp_hw_init586()\n", dev->name);
1573 #endif
1574 return;
1577 static void eexp_setup_filter(struct net_device *dev)
1579 struct dev_mc_list *dmi;
1580 unsigned short ioaddr = dev->base_addr;
1581 int count = dev->mc_count;
1582 int i;
1583 if (count > 8) {
1584 printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
1585 dev->name, count);
1586 count = 8;
1589 outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
1590 outw(6*count, ioaddr+SHADOW(CONF_NR_MULTICAST));
1591 for (i = 0, dmi = dev->mc_list; i < count; i++, dmi = dmi->next) {
1592 unsigned short *data;
1593 if (!dmi) {
1594 printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
1595 break;
1597 if (dmi->dmi_addrlen != ETH_ALEN) {
1598 printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
1599 continue;
1601 data = (unsigned short *)dmi->dmi_addr;
1602 outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
1603 outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
1604 outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
1605 outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
1606 outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
1607 outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
1612 * Set or clear the multicast filter for this adaptor.
1614 static void
1615 eexp_set_multicast(struct net_device *dev)
1617 unsigned short ioaddr = dev->base_addr;
1618 struct net_local *lp = netdev_priv(dev);
1619 int kick = 0, i;
1620 if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
1621 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1622 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1623 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1624 ioaddr+SHADOW(CONF_PROMISC));
1625 lp->was_promisc = dev->flags & IFF_PROMISC;
1626 kick = 1;
1628 if (!(dev->flags & IFF_PROMISC)) {
1629 eexp_setup_filter(dev);
1630 if (lp->old_mc_count != dev->mc_count) {
1631 kick = 1;
1632 lp->old_mc_count = dev->mc_count;
1635 if (kick) {
1636 unsigned long oj;
1637 scb_command(dev, SCB_CUsuspend);
1638 outb(0, ioaddr+SIGNAL_CA);
1639 outb(0, ioaddr+SIGNAL_CA);
1640 #if 0
1641 printk("%s: waiting for CU to go suspended\n", dev->name);
1642 #endif
1643 oj = jiffies;
1644 while ((SCB_CUstat(scb_status(dev)) == 2) &&
1645 (time_before(jiffies, oj + 2000)));
1646 if (SCB_CUstat(scb_status(dev)) == 2)
1647 printk("%s: warning, CU didn't stop\n", dev->name);
1648 lp->started &= ~(STARTED_CU);
1649 scb_wrcbl(dev, CONF_LINK);
1650 scb_command(dev, SCB_CUstart);
1651 outb(0, ioaddr+SIGNAL_CA);
1657 * MODULE stuff
1660 #ifdef MODULE
1662 #define EEXP_MAX_CARDS 4 /* max number of cards to support */
1664 static struct net_device *dev_eexp[EEXP_MAX_CARDS];
1665 static int irq[EEXP_MAX_CARDS];
1666 static int io[EEXP_MAX_CARDS];
1668 module_param_array(io, int, NULL, 0);
1669 module_param_array(irq, int, NULL, 0);
1670 MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)");
1671 MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)");
1672 MODULE_LICENSE("GPL");
1675 /* Ideally the user would give us io=, irq= for every card. If any parameters
1676 * are specified, we verify and then use them. If no parameters are given, we
1677 * autoprobe for one card only.
1679 int __init init_module(void)
1681 struct net_device *dev;
1682 int this_dev, found = 0;
1684 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1685 dev = alloc_etherdev(sizeof(struct net_local));
1686 dev->irq = irq[this_dev];
1687 dev->base_addr = io[this_dev];
1688 if (io[this_dev] == 0) {
1689 if (this_dev)
1690 break;
1691 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1693 if (do_express_probe(dev) == 0) {
1694 dev_eexp[this_dev] = dev;
1695 found++;
1696 continue;
1698 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1699 free_netdev(dev);
1700 break;
1702 if (found)
1703 return 0;
1704 return -ENXIO;
1707 void __exit cleanup_module(void)
1709 int this_dev;
1711 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1712 struct net_device *dev = dev_eexp[this_dev];
1713 if (dev) {
1714 unregister_netdev(dev);
1715 free_netdev(dev);
1719 #endif
1722 * Local Variables:
1723 * c-file-style: "linux"
1724 * tab-width: 8
1725 * End: