More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / eexpress.c
blob806ad0377d734c9b742a284069b7b67ccdb03965
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>
12 * Added MCA support Adam Fritzler <mid@auk.cx>
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/config.h>
101 #include <linux/module.h>
102 #include <linux/kernel.h>
103 #include <linux/types.h>
104 #include <linux/fcntl.h>
105 #include <linux/interrupt.h>
106 #include <linux/ioport.h>
107 #include <linux/string.h>
108 #include <linux/in.h>
109 #include <linux/delay.h>
110 #include <linux/errno.h>
111 #include <linux/init.h>
112 #include <linux/netdevice.h>
113 #include <linux/etherdevice.h>
114 #include <linux/skbuff.h>
115 #include <linux/slab.h>
116 #include <linux/mca.h>
117 #include <linux/mca-legacy.h>
118 #include <linux/spinlock.h>
120 #include <asm/system.h>
121 #include <asm/bitops.h>
122 #include <asm/io.h>
123 #include <asm/irq.h>
125 #ifndef NET_DEBUG
126 #define NET_DEBUG 4
127 #endif
129 #include "eexpress.h"
131 #define EEXP_IO_EXTENT 16
134 * Private data declarations
137 struct net_local
139 struct net_device_stats stats;
140 unsigned long last_tx; /* jiffies when last transmit started */
141 unsigned long init_time; /* jiffies when eexp_hw_init586 called */
142 unsigned short rx_first; /* first rx buf, same as RX_BUF_START */
143 unsigned short rx_last; /* last rx buf */
144 unsigned short rx_ptr; /* first rx buf to look at */
145 unsigned short tx_head; /* next free tx buf */
146 unsigned short tx_reap; /* first in-use tx buf */
147 unsigned short tx_tail; /* previous tx buf to tx_head */
148 unsigned short tx_link; /* last known-executing tx buf */
149 unsigned short last_tx_restart; /* set to tx_link when we
150 restart the CU */
151 unsigned char started;
152 unsigned short rx_buf_start;
153 unsigned short rx_buf_end;
154 unsigned short num_tx_bufs;
155 unsigned short num_rx_bufs;
156 unsigned char width; /* 0 for 16bit, 1 for 8bit */
157 unsigned char was_promisc;
158 unsigned char old_mc_count;
159 spinlock_t lock;
162 /* This is the code and data that is downloaded to the EtherExpress card's
163 * memory at boot time.
166 static unsigned short start_code[] = {
167 /* 0x0000 */
168 0x0001, /* ISCP: busy - cleared after reset */
169 0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */
171 0x0000,0x0000, /* SCB: status, commands */
172 0x0000,0x0000, /* links to first command block,
173 first receive descriptor */
174 0x0000,0x0000, /* CRC error, alignment error counts */
175 0x0000,0x0000, /* out of resources, overrun error counts */
177 0x0000,0x0000, /* pad */
178 0x0000,0x0000,
180 /* 0x20 -- start of 82586 CU program */
181 #define CONF_LINK 0x20
182 0x0000,Cmd_Config,
183 0x0032, /* link to next command */
184 0x080c, /* 12 bytes follow : fifo threshold=8 */
185 0x2e40, /* don't rx bad frames
186 * SRDY/ARDY => ext. sync. : preamble len=8
187 * take addresses from data buffers
188 * 6 bytes/address
190 0x6000, /* default backoff method & priority
191 * interframe spacing = 0x60 */
192 0xf200, /* slot time=0x200
193 * max collision retry = 0xf */
194 #define CONF_PROMISC 0x2e
195 0x0000, /* no HDLC : normal CRC : enable broadcast
196 * disable promiscuous/multicast modes */
197 0x003c, /* minimum frame length = 60 octets) */
199 0x0000,Cmd_SetAddr,
200 0x003e, /* link to next command */
201 #define CONF_HWADDR 0x38
202 0x0000,0x0000,0x0000, /* hardware address placed here */
204 0x0000,Cmd_MCast,
205 0x0076, /* link to next command */
206 #define CONF_NR_MULTICAST 0x44
207 0x0000, /* number of multicast addresses */
208 #define CONF_MULTICAST 0x46
209 0x0000, 0x0000, 0x0000, /* some addresses */
210 0x0000, 0x0000, 0x0000,
211 0x0000, 0x0000, 0x0000,
212 0x0000, 0x0000, 0x0000,
213 0x0000, 0x0000, 0x0000,
214 0x0000, 0x0000, 0x0000,
215 0x0000, 0x0000, 0x0000,
216 0x0000, 0x0000, 0x0000,
218 #define CONF_DIAG_RESULT 0x76
219 0x0000, Cmd_Diag,
220 0x007c, /* link to next command */
222 0x0000,Cmd_TDR|Cmd_INT,
223 0x0084,
224 #define CONF_TDR_RESULT 0x82
225 0x0000,
227 0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
228 0x0084 /* dummy link */
231 /* maps irq number to EtherExpress magic value */
232 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
234 #ifdef CONFIG_MCA
235 /* mapping of the first four bits of the second POS register */
236 static unsigned short mca_iomap[] = {
237 0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200,
238 0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300
240 /* bits 5-7 of the second POS register */
241 static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 };
242 #endif
245 * Prototypes for Linux interface
248 extern int express_probe(struct net_device *dev);
249 static int eexp_open(struct net_device *dev);
250 static int eexp_close(struct net_device *dev);
251 static void eexp_timeout(struct net_device *dev);
252 static struct net_device_stats *eexp_stats(struct net_device *dev);
253 static int eexp_xmit(struct sk_buff *buf, struct net_device *dev);
255 static irqreturn_t eexp_irq(int irq, void *dev_addr, struct pt_regs *regs);
256 static void eexp_set_multicast(struct net_device *dev);
259 * Prototypes for hardware access functions
262 static void eexp_hw_rx_pio(struct net_device *dev);
263 static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
264 unsigned short len);
265 static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr);
266 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr,
267 unsigned char location);
269 static unsigned short eexp_hw_lasttxstat(struct net_device *dev);
270 static void eexp_hw_txrestart(struct net_device *dev);
272 static void eexp_hw_txinit (struct net_device *dev);
273 static void eexp_hw_rxinit (struct net_device *dev);
275 static void eexp_hw_init586 (struct net_device *dev);
276 static void eexp_setup_filter (struct net_device *dev);
278 static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"};
279 enum eexp_iftype {AUI=0, BNC=1, TPE=2};
281 #define STARTED_RU 2
282 #define STARTED_CU 1
285 * Primitive hardware access functions.
288 static inline unsigned short scb_status(struct net_device *dev)
290 return inw(dev->base_addr + 0xc008);
293 static inline unsigned short scb_rdcmd(struct net_device *dev)
295 return inw(dev->base_addr + 0xc00a);
298 static inline void scb_command(struct net_device *dev, unsigned short cmd)
300 outw(cmd, dev->base_addr + 0xc00a);
303 static inline void scb_wrcbl(struct net_device *dev, unsigned short val)
305 outw(val, dev->base_addr + 0xc00c);
308 static inline void scb_wrrfa(struct net_device *dev, unsigned short val)
310 outw(val, dev->base_addr + 0xc00e);
313 static inline void set_loopback(struct net_device *dev)
315 outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config);
318 static inline void clear_loopback(struct net_device *dev)
320 outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config);
323 static inline unsigned short int SHADOW(short int addr)
325 addr &= 0x1f;
326 if (addr > 0xf) addr += 0x3ff0;
327 return addr + 0x4000;
331 * Linux interface
335 * checks for presence of EtherExpress card
338 int __init express_probe(struct net_device *dev)
340 unsigned short *port;
341 static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
342 unsigned short ioaddr = dev->base_addr;
344 SET_MODULE_OWNER(dev);
346 dev->if_port = 0xff; /* not set */
348 #ifdef CONFIG_MCA
349 if (MCA_bus) {
350 int slot = 0;
353 * Only find one card at a time. Subsequent calls
354 * will find others, however, proper multicard MCA
355 * probing and setup can't be done with the
356 * old-style Space.c init routines. -- ASF
358 while (slot != MCA_NOTFOUND) {
359 int pos0, pos1;
361 slot = mca_find_unused_adapter(0x628B, slot);
362 if (slot == MCA_NOTFOUND)
363 break;
365 pos0 = mca_read_stored_pos(slot, 2);
366 pos1 = mca_read_stored_pos(slot, 3);
367 ioaddr = mca_iomap[pos1&0xf];
369 dev->irq = mca_irqmap[(pos1>>4)&0x7];
372 * XXX: Transciever selection is done
373 * differently on the MCA version.
374 * How to get it to select something
375 * other than external/AUI is currently
376 * unknown. This code is just for looks. -- ASF
378 if ((pos0 & 0x7) == 0x1)
379 dev->if_port = AUI;
380 else if ((pos0 & 0x7) == 0x5) {
381 if (pos1 & 0x80)
382 dev->if_port = BNC;
383 else
384 dev->if_port = TPE;
387 mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA");
388 mca_set_adapter_procfn(slot, NULL, dev);
389 mca_mark_as_used(slot);
391 break;
394 #endif
395 if (ioaddr&0xfe00)
396 return eexp_hw_probe(dev,ioaddr);
397 else if (ioaddr)
398 return -ENXIO;
400 for (port=&ports[0] ; *port ; port++ )
402 unsigned short sum = 0;
403 int i;
404 for ( i=0 ; i<4 ; i++ )
406 unsigned short t;
407 t = inb(*port + ID_PORT);
408 sum |= (t>>4) << ((t & 0x03)<<2);
410 if (sum==0xbaba && !eexp_hw_probe(dev,*port))
411 return 0;
413 return -ENODEV;
417 * open and initialize the adapter, ready for use
420 static int eexp_open(struct net_device *dev)
422 int ret;
423 unsigned short ioaddr = dev->base_addr;
424 struct net_local *lp = (struct net_local *)dev->priv;
426 #if NET_DEBUG > 6
427 printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
428 #endif
430 if (!dev->irq || !irqrmap[dev->irq])
431 return -ENXIO;
433 ret = request_irq(dev->irq,&eexp_irq,0,dev->name,dev);
434 if (ret) return ret;
436 if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) {
437 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
438 , ioaddr);
439 goto err_out1;
441 if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
442 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
443 , ioaddr+0x4000);
444 goto err_out2;
446 if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
447 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
448 , ioaddr+0x8000);
449 goto err_out3;
451 if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) {
452 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n"
453 , ioaddr+0xc000);
454 goto err_out4;
457 if (lp->width) {
458 printk("%s: forcing ASIC to 8-bit mode\n", dev->name);
459 outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config);
462 eexp_hw_init586(dev);
463 netif_start_queue(dev);
464 #if NET_DEBUG > 6
465 printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
466 #endif
467 return 0;
469 err_out4:
470 release_region(ioaddr+0x8000, EEXP_IO_EXTENT);
471 err_out3:
472 release_region(ioaddr+0x4000, EEXP_IO_EXTENT);
473 err_out2:
474 release_region(ioaddr, EEXP_IO_EXTENT);
475 err_out1:
476 free_irq(dev->irq, dev);
477 return -EBUSY;
481 * close and disable the interface, leaving the 586 in reset.
484 static int eexp_close(struct net_device *dev)
486 unsigned short ioaddr = dev->base_addr;
487 struct net_local *lp = dev->priv;
489 int irq = dev->irq;
491 netif_stop_queue(dev);
493 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
494 lp->started = 0;
495 scb_command(dev, SCB_CUsuspend|SCB_RUsuspend);
496 outb(0,ioaddr+SIGNAL_CA);
497 free_irq(irq,dev);
498 outb(i586_RST,ioaddr+EEPROM_Ctrl);
499 release_region(ioaddr, EEXP_IO_EXTENT);
500 release_region(ioaddr+0x4000, 16);
501 release_region(ioaddr+0x8000, 16);
502 release_region(ioaddr+0xc000, 16);
504 return 0;
508 * Return interface stats
511 static struct net_device_stats *eexp_stats(struct net_device *dev)
513 struct net_local *lp = (struct net_local *)dev->priv;
515 return &lp->stats;
519 * This gets called when a higher level thinks we are broken. Check that
520 * nothing has become jammed in the CU.
523 static void unstick_cu(struct net_device *dev)
525 struct net_local *lp = (struct net_local *)dev->priv;
526 unsigned short ioaddr = dev->base_addr;
528 if (lp->started)
530 if ((jiffies - dev->trans_start)>50)
532 if (lp->tx_link==lp->last_tx_restart)
534 unsigned short boguscount=200,rsst;
535 printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
536 dev->name, scb_status(dev));
537 eexp_hw_txinit(dev);
538 lp->last_tx_restart = 0;
539 scb_wrcbl(dev, lp->tx_link);
540 scb_command(dev, SCB_CUstart);
541 outb(0,ioaddr+SIGNAL_CA);
542 while (!SCB_complete(rsst=scb_status(dev)))
544 if (!--boguscount)
546 boguscount=200;
547 printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
548 dev->name,rsst);
549 scb_wrcbl(dev, lp->tx_link);
550 scb_command(dev, SCB_CUstart);
551 outb(0,ioaddr+SIGNAL_CA);
554 netif_wake_queue(dev);
556 else
558 unsigned short status = scb_status(dev);
559 if (SCB_CUdead(status))
561 unsigned short txstatus = eexp_hw_lasttxstat(dev);
562 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
563 dev->name, status, txstatus);
564 eexp_hw_txrestart(dev);
566 else
568 unsigned short txstatus = eexp_hw_lasttxstat(dev);
569 if (netif_queue_stopped(dev) && !txstatus)
571 printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
572 dev->name,status,txstatus);
573 eexp_hw_init586(dev);
574 netif_wake_queue(dev);
576 else
578 printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
584 else
586 if ((jiffies-lp->init_time)>10)
588 unsigned short status = scb_status(dev);
589 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
590 dev->name, status);
591 eexp_hw_init586(dev);
592 netif_wake_queue(dev);
597 static void eexp_timeout(struct net_device *dev)
599 struct net_local *lp = (struct net_local *)dev->priv;
600 #ifdef CONFIG_SMP
601 unsigned long flags;
602 #endif
603 int status;
605 disable_irq(dev->irq);
608 * Best would be to use synchronize_irq(); spin_lock() here
609 * lets make it work first..
612 #ifdef CONFIG_SMP
613 spin_lock_irqsave(&lp->lock, flags);
614 #endif
616 status = scb_status(dev);
617 unstick_cu(dev);
618 printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name,
619 (SCB_complete(status)?"lost interrupt":
620 "board on fire"));
621 lp->stats.tx_errors++;
622 lp->last_tx = jiffies;
623 if (!SCB_complete(status)) {
624 scb_command(dev, SCB_CUabort);
625 outb(0,dev->base_addr+SIGNAL_CA);
627 netif_wake_queue(dev);
628 #ifdef CONFIG_SMP
629 spin_unlock_irqrestore(&lp->lock, flags);
630 #endif
634 * Called to transmit a packet, or to allow us to right ourselves
635 * if the kernel thinks we've died.
637 static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
639 struct net_local *lp = (struct net_local *)dev->priv;
640 short length = buf->len;
641 #ifdef CONFIG_SMP
642 unsigned long flags;
643 #endif
645 #if NET_DEBUG > 6
646 printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
647 #endif
649 if (buf->len < ETH_ZLEN) {
650 buf = skb_padto(buf, ETH_ZLEN);
651 if (buf == NULL)
652 return 0;
653 length = buf->len;
656 disable_irq(dev->irq);
659 * Best would be to use synchronize_irq(); spin_lock() here
660 * lets make it work first..
663 #ifdef CONFIG_SMP
664 spin_lock_irqsave(&lp->lock, flags);
665 #endif
668 unsigned short *data = (unsigned short *)buf->data;
670 lp->stats.tx_bytes += length;
672 eexp_hw_tx_pio(dev,data,length);
674 dev_kfree_skb(buf);
675 #ifdef CONFIG_SMP
676 spin_unlock_irqrestore(&lp->lock, flags);
677 #endif
678 enable_irq(dev->irq);
679 return 0;
683 * Handle an EtherExpress interrupt
684 * If we've finished initializing, start the RU and CU up.
685 * If we've already started, reap tx buffers, handle any received packets,
686 * check to make sure we've not become wedged.
690 * Handle an EtherExpress interrupt
691 * If we've finished initializing, start the RU and CU up.
692 * If we've already started, reap tx buffers, handle any received packets,
693 * check to make sure we've not become wedged.
696 static unsigned short eexp_start_irq(struct net_device *dev,
697 unsigned short status)
699 unsigned short ack_cmd = SCB_ack(status);
700 struct net_local *lp = (struct net_local *)dev->priv;
701 unsigned short ioaddr = dev->base_addr;
702 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) {
703 short diag_status, tdr_status;
704 while (SCB_CUstat(status)==2)
705 status = scb_status(dev);
706 #if NET_DEBUG > 4
707 printk("%s: CU went non-active (status %04x)\n",
708 dev->name, status);
709 #endif
711 outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR);
712 diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
713 if (diag_status & 1<<11) {
714 printk(KERN_WARNING "%s: 82586 failed self-test\n",
715 dev->name);
716 } else if (!(diag_status & 1<<13)) {
717 printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name);
720 outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR);
721 tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT));
722 if (tdr_status & (TDR_SHORT|TDR_OPEN)) {
723 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" : "");
725 else if (tdr_status & TDR_XCVRPROBLEM) {
726 printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name);
728 else if (tdr_status & TDR_LINKOK) {
729 #if NET_DEBUG > 4
730 printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name);
731 #endif
732 } else {
733 printk("%s: TDR is ga-ga (status %04x)\n", dev->name,
734 tdr_status);
737 lp->started |= STARTED_CU;
738 scb_wrcbl(dev, lp->tx_link);
739 /* if the RU isn't running, start it now */
740 if (!(lp->started & STARTED_RU)) {
741 ack_cmd |= SCB_RUstart;
742 scb_wrrfa(dev, lp->rx_buf_start);
743 lp->rx_ptr = lp->rx_buf_start;
744 lp->started |= STARTED_RU;
746 ack_cmd |= SCB_CUstart | 0x2000;
749 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4)
750 lp->started|=STARTED_RU;
752 return ack_cmd;
755 static void eexp_cmd_clear(struct net_device *dev)
757 unsigned long int oldtime = jiffies;
758 while (scb_rdcmd(dev) && ((jiffies-oldtime)<10));
759 if (scb_rdcmd(dev)) {
760 printk("%s: command didn't clear\n", dev->name);
764 static irqreturn_t eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
766 struct net_device *dev = dev_info;
767 struct net_local *lp;
768 unsigned short ioaddr,status,ack_cmd;
769 unsigned short old_read_ptr, old_write_ptr;
771 if (dev==NULL)
773 printk(KERN_WARNING "eexpress: irq %d for unknown device\n",
774 irq);
775 return IRQ_NONE;
778 lp = (struct net_local *)dev->priv;
779 ioaddr = dev->base_addr;
781 spin_lock(&lp->lock);
783 old_read_ptr = inw(ioaddr+READ_PTR);
784 old_write_ptr = inw(ioaddr+WRITE_PTR);
786 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
789 status = scb_status(dev);
791 #if NET_DEBUG > 4
792 printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status);
793 #endif
795 if (lp->started == (STARTED_CU | STARTED_RU)) {
797 do {
798 eexp_cmd_clear(dev);
800 ack_cmd = SCB_ack(status);
801 scb_command(dev, ack_cmd);
802 outb(0,ioaddr+SIGNAL_CA);
804 eexp_cmd_clear(dev);
806 if (SCB_complete(status)) {
807 if (!eexp_hw_lasttxstat(dev)) {
808 printk("%s: tx interrupt but no status\n", dev->name);
812 if (SCB_rxdframe(status))
813 eexp_hw_rx_pio(dev);
815 status = scb_status(dev);
816 } while (status & 0xc000);
818 if (SCB_RUdead(status))
820 printk(KERN_WARNING "%s: RU stopped: status %04x\n",
821 dev->name,status);
822 #if 0
823 printk(KERN_WARNING "%s: cur_rfd=%04x, cur_rbd=%04x\n", dev->name, lp->cur_rfd, lp->cur_rbd);
824 outw(lp->cur_rfd, ioaddr+READ_PTR);
825 printk(KERN_WARNING "%s: [%04x]\n", dev->name, inw(ioaddr+DATAPORT));
826 outw(lp->cur_rfd+6, ioaddr+READ_PTR);
827 printk(KERN_WARNING "%s: rbd is %04x\n", dev->name, rbd= inw(ioaddr+DATAPORT));
828 outw(rbd, ioaddr+READ_PTR);
829 printk(KERN_WARNING "%s: [%04x %04x] ", dev->name, inw(ioaddr+DATAPORT), inw(ioaddr+DATAPORT));
830 outw(rbd+8, ioaddr+READ_PTR);
831 printk("[%04x]\n", inw(ioaddr+DATAPORT));
832 #endif
833 lp->stats.rx_errors++;
834 #if 1
835 eexp_hw_rxinit(dev);
836 #else
837 lp->cur_rfd = lp->first_rfd;
838 #endif
839 scb_wrrfa(dev, lp->rx_buf_start);
840 scb_command(dev, SCB_RUstart);
841 outb(0,ioaddr+SIGNAL_CA);
843 } else {
844 if (status & 0x8000)
845 ack_cmd = eexp_start_irq(dev, status);
846 else
847 ack_cmd = SCB_ack(status);
848 scb_command(dev, ack_cmd);
849 outb(0,ioaddr+SIGNAL_CA);
852 eexp_cmd_clear(dev);
854 outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
856 #if NET_DEBUG > 6
857 printk("%s: leaving eexp_irq()\n", dev->name);
858 #endif
859 outw(old_read_ptr, ioaddr+READ_PTR);
860 outw(old_write_ptr, ioaddr+WRITE_PTR);
862 spin_unlock(&lp->lock);
863 return IRQ_HANDLED;
867 * Hardware access functions
871 * Set the cable type to use.
874 static void eexp_hw_set_interface(struct net_device *dev)
876 unsigned char oldval = inb(dev->base_addr + 0x300e);
877 oldval &= ~0x82;
878 switch (dev->if_port) {
879 case TPE:
880 oldval |= 0x2;
881 case BNC:
882 oldval |= 0x80;
883 break;
885 outb(oldval, dev->base_addr+0x300e);
886 mdelay(20);
890 * Check all the receive buffers, and hand any received packets
891 * to the upper levels. Basic sanity check on each frame
892 * descriptor, though we don't bother trying to fix broken ones.
895 static void eexp_hw_rx_pio(struct net_device *dev)
897 struct net_local *lp = (struct net_local *)dev->priv;
898 unsigned short rx_block = lp->rx_ptr;
899 unsigned short boguscount = lp->num_rx_bufs;
900 unsigned short ioaddr = dev->base_addr;
901 unsigned short status;
903 #if NET_DEBUG > 6
904 printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
905 #endif
907 do {
908 unsigned short rfd_cmd, rx_next, pbuf, pkt_len;
910 outw(rx_block, ioaddr + READ_PTR);
911 status = inw(ioaddr + DATAPORT);
913 if (FD_Done(status))
915 rfd_cmd = inw(ioaddr + DATAPORT);
916 rx_next = inw(ioaddr + DATAPORT);
917 pbuf = inw(ioaddr + DATAPORT);
919 outw(pbuf, ioaddr + READ_PTR);
920 pkt_len = inw(ioaddr + DATAPORT);
922 if (rfd_cmd!=0x0000)
924 printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n",
925 dev->name, rfd_cmd);
926 continue;
928 else if (pbuf!=rx_block+0x16)
930 printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n",
931 dev->name, rx_block+0x16, pbuf);
932 continue;
934 else if ((pkt_len & 0xc000)!=0xc000)
936 printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n",
937 dev->name, pkt_len & 0xc000);
938 continue;
940 else if (!FD_OK(status))
942 lp->stats.rx_errors++;
943 if (FD_CRC(status))
944 lp->stats.rx_crc_errors++;
945 if (FD_Align(status))
946 lp->stats.rx_frame_errors++;
947 if (FD_Resrc(status))
948 lp->stats.rx_fifo_errors++;
949 if (FD_DMA(status))
950 lp->stats.rx_over_errors++;
951 if (FD_Short(status))
952 lp->stats.rx_length_errors++;
954 else
956 struct sk_buff *skb;
957 pkt_len &= 0x3fff;
958 skb = dev_alloc_skb(pkt_len+16);
959 if (skb == NULL)
961 printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
962 lp->stats.rx_dropped++;
963 break;
965 skb->dev = dev;
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->last_rx = jiffies;
972 lp->stats.rx_packets++;
973 lp->stats.rx_bytes += pkt_len;
975 outw(rx_block, ioaddr+WRITE_PTR);
976 outw(0, ioaddr+DATAPORT);
977 outw(0, ioaddr+DATAPORT);
978 rx_block = rx_next;
980 } while (FD_Done(status) && boguscount--);
981 lp->rx_ptr = rx_block;
985 * Hand a packet to the card for transmission
986 * If we get here, we MUST have already checked
987 * to make sure there is room in the transmit
988 * buffer region.
991 static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf,
992 unsigned short len)
994 struct net_local *lp = (struct net_local *)dev->priv;
995 unsigned short ioaddr = dev->base_addr;
997 if (LOCKUP16 || lp->width) {
998 /* Stop the CU so that there is no chance that it
999 jumps off to a bogus address while we are writing the
1000 pointer to the next transmit packet in 8-bit mode --
1001 this eliminates the "CU wedged" errors in 8-bit mode.
1002 (Zoltan Szilagyi 10-12-96) */
1003 scb_command(dev, SCB_CUsuspend);
1004 outw(0xFFFF, ioaddr+SIGNAL_CA);
1007 outw(lp->tx_head, ioaddr + WRITE_PTR);
1009 outw(0x0000, ioaddr + DATAPORT);
1010 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1011 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1012 outw(lp->tx_head+0x0e, ioaddr + DATAPORT);
1014 outw(0x0000, ioaddr + DATAPORT);
1015 outw(0x0000, ioaddr + DATAPORT);
1016 outw(lp->tx_head+0x08, ioaddr + DATAPORT);
1018 outw(0x8000|len, ioaddr + DATAPORT);
1019 outw(-1, ioaddr + DATAPORT);
1020 outw(lp->tx_head+0x16, ioaddr + DATAPORT);
1021 outw(0, ioaddr + DATAPORT);
1023 outsw(ioaddr + DATAPORT, buf, (len+1)>>1);
1025 outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR);
1026 outw(lp->tx_head, ioaddr + DATAPORT);
1028 dev->trans_start = jiffies;
1029 lp->tx_tail = lp->tx_head;
1030 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1031 lp->tx_head = TX_BUF_START;
1032 else
1033 lp->tx_head += TX_BUF_SIZE;
1034 if (lp->tx_head != lp->tx_reap)
1035 netif_wake_queue(dev);
1037 if (LOCKUP16 || lp->width) {
1038 /* Restart the CU so that the packet can actually
1039 be transmitted. (Zoltan Szilagyi 10-12-96) */
1040 scb_command(dev, SCB_CUresume);
1041 outw(0xFFFF, ioaddr+SIGNAL_CA);
1044 lp->stats.tx_packets++;
1045 lp->last_tx = jiffies;
1049 * Sanity check the suspected EtherExpress card
1050 * Read hardware address, reset card, size memory and initialize buffer
1051 * memory pointers. These are held in dev->priv, in case someone has more
1052 * than one card in a machine.
1055 static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr)
1057 unsigned short hw_addr[3];
1058 unsigned char buswidth;
1059 unsigned int memory_size;
1060 int i;
1061 unsigned short xsum = 0;
1062 struct net_local *lp;
1064 printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr);
1066 outb(ASIC_RST, ioaddr+EEPROM_Ctrl);
1067 outb(0, ioaddr+EEPROM_Ctrl);
1068 udelay(500);
1069 outb(i586_RST, ioaddr+EEPROM_Ctrl);
1071 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
1072 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
1073 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
1075 /* Standard Address or Compaq LTE Address */
1076 if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
1077 (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
1079 printk(" rejected: invalid address %04x%04x%04x\n",
1080 hw_addr[2],hw_addr[1],hw_addr[0]);
1081 return -ENODEV;
1084 /* Calculate the EEPROM checksum. Carry on anyway if it's bad,
1085 * though.
1087 for (i = 0; i < 64; i++)
1088 xsum += eexp_hw_readeeprom(ioaddr, i);
1089 if (xsum != 0xbaba)
1090 printk(" (bad EEPROM xsum 0x%02x)", xsum);
1092 dev->base_addr = ioaddr;
1093 for ( i=0 ; i<6 ; i++ )
1094 dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i];
1097 static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
1098 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
1100 /* Use the IRQ from EEPROM if none was given */
1101 if (!dev->irq)
1102 dev->irq = irqmap[setupval>>13];
1104 if (dev->if_port == 0xff) {
1105 dev->if_port = !(setupval & 0x1000) ? AUI :
1106 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC;
1109 buswidth = !((setupval & 0x400) >> 10);
1112 dev->priv = lp = kmalloc(sizeof(struct net_local), GFP_KERNEL);
1113 if (!dev->priv)
1114 return -ENOMEM;
1116 memset(dev->priv, 0, sizeof(struct net_local));
1117 spin_lock_init(&lp->lock);
1119 printk("(IRQ %d, %s connector, %d-bit bus", dev->irq,
1120 eexp_ifmap[dev->if_port], buswidth?8:16);
1122 eexp_hw_set_interface(dev);
1124 /* Find out how much RAM we have on the card */
1125 outw(0, dev->base_addr + WRITE_PTR);
1126 for (i = 0; i < 32768; i++)
1127 outw(0, dev->base_addr + DATAPORT);
1129 for (memory_size = 0; memory_size < 64; memory_size++)
1131 outw(memory_size<<10, dev->base_addr + READ_PTR);
1132 if (inw(dev->base_addr+DATAPORT))
1133 break;
1134 outw(memory_size<<10, dev->base_addr + WRITE_PTR);
1135 outw(memory_size | 0x5000, dev->base_addr+DATAPORT);
1136 outw(memory_size<<10, dev->base_addr + READ_PTR);
1137 if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000))
1138 break;
1141 /* Sort out the number of buffers. We may have 16, 32, 48 or 64k
1142 * of RAM to play with.
1144 lp->num_tx_bufs = 4;
1145 lp->rx_buf_end = 0x3ff6;
1146 switch (memory_size)
1148 case 64:
1149 lp->rx_buf_end += 0x4000;
1150 case 48:
1151 lp->num_tx_bufs += 4;
1152 lp->rx_buf_end += 0x4000;
1153 case 32:
1154 lp->rx_buf_end += 0x4000;
1155 case 16:
1156 printk(", %dk RAM)\n", memory_size);
1157 break;
1158 default:
1159 printk(") bad memory size (%dk).\n", memory_size);
1160 kfree(dev->priv);
1161 return -ENODEV;
1162 break;
1165 lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE);
1166 lp->width = buswidth;
1168 dev->open = eexp_open;
1169 dev->stop = eexp_close;
1170 dev->hard_start_xmit = eexp_xmit;
1171 dev->get_stats = eexp_stats;
1172 dev->set_multicast_list = &eexp_set_multicast;
1173 dev->tx_timeout = eexp_timeout;
1174 dev->watchdog_timeo = 2*HZ;
1175 ether_setup(dev);
1176 return 0;
1180 * Read a word from the EtherExpress on-board serial EEPROM.
1181 * The EEPROM contains 64 words of 16 bits.
1183 static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr,
1184 unsigned char location)
1186 unsigned short cmd = 0x180|(location&0x7f);
1187 unsigned short rval = 0,wval = EC_CS|i586_RST;
1188 int i;
1190 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
1191 for (i=0x100 ; i ; i>>=1 )
1193 if (cmd&i)
1194 wval |= EC_Wr;
1195 else
1196 wval &= ~EC_Wr;
1198 outb(wval,ioaddr+EEPROM_Ctrl);
1199 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1200 eeprom_delay();
1201 outb(wval,ioaddr+EEPROM_Ctrl);
1202 eeprom_delay();
1204 wval &= ~EC_Wr;
1205 outb(wval,ioaddr+EEPROM_Ctrl);
1206 for (i=0x8000 ; i ; i>>=1 )
1208 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1209 eeprom_delay();
1210 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd)
1211 rval |= i;
1212 outb(wval,ioaddr+EEPROM_Ctrl);
1213 eeprom_delay();
1215 wval &= ~EC_CS;
1216 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
1217 eeprom_delay();
1218 outb(wval,ioaddr+EEPROM_Ctrl);
1219 eeprom_delay();
1220 return rval;
1224 * Reap tx buffers and return last transmit status.
1225 * if ==0 then either:
1226 * a) we're not transmitting anything, so why are we here?
1227 * b) we've died.
1228 * otherwise, Stat_Busy(return) means we've still got some packets
1229 * to transmit, Stat_Done(return) means our buffers should be empty
1230 * again
1233 static unsigned short eexp_hw_lasttxstat(struct net_device *dev)
1235 struct net_local *lp = (struct net_local *)dev->priv;
1236 unsigned short tx_block = lp->tx_reap;
1237 unsigned short status;
1239 if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap)
1240 return 0x0000;
1244 outw(tx_block & ~31, dev->base_addr + SM_PTR);
1245 status = inw(dev->base_addr + SHADOW(tx_block));
1246 if (!Stat_Done(status))
1248 lp->tx_link = tx_block;
1249 return status;
1251 else
1253 lp->last_tx_restart = 0;
1254 lp->stats.collisions += Stat_NoColl(status);
1255 if (!Stat_OK(status))
1257 char *whatsup = NULL;
1258 lp->stats.tx_errors++;
1259 if (Stat_Abort(status))
1260 lp->stats.tx_aborted_errors++;
1261 if (Stat_TNoCar(status)) {
1262 whatsup = "aborted, no carrier";
1263 lp->stats.tx_carrier_errors++;
1265 if (Stat_TNoCTS(status)) {
1266 whatsup = "aborted, lost CTS";
1267 lp->stats.tx_carrier_errors++;
1269 if (Stat_TNoDMA(status)) {
1270 whatsup = "FIFO underran";
1271 lp->stats.tx_fifo_errors++;
1273 if (Stat_TXColl(status)) {
1274 whatsup = "aborted, too many collisions";
1275 lp->stats.tx_aborted_errors++;
1277 if (whatsup)
1278 printk(KERN_INFO "%s: transmit %s\n",
1279 dev->name, whatsup);
1281 else
1282 lp->stats.tx_packets++;
1284 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE))
1285 lp->tx_reap = tx_block = TX_BUF_START;
1286 else
1287 lp->tx_reap = tx_block += TX_BUF_SIZE;
1288 netif_wake_queue(dev);
1290 while (lp->tx_reap != lp->tx_head);
1292 lp->tx_link = lp->tx_tail + 0x08;
1294 return status;
1298 * This should never happen. It is called when some higher routine detects
1299 * that the CU has stopped, to try to restart it from the last packet we knew
1300 * we were working on, or the idle loop if we had finished for the time.
1303 static void eexp_hw_txrestart(struct net_device *dev)
1305 struct net_local *lp = (struct net_local *)dev->priv;
1306 unsigned short ioaddr = dev->base_addr;
1308 lp->last_tx_restart = lp->tx_link;
1309 scb_wrcbl(dev, lp->tx_link);
1310 scb_command(dev, SCB_CUstart);
1311 outb(0,ioaddr+SIGNAL_CA);
1314 unsigned short boguscount=50,failcount=5;
1315 while (!scb_status(dev))
1317 if (!--boguscount)
1319 if (--failcount)
1321 printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev));
1322 scb_wrcbl(dev, lp->tx_link);
1323 scb_command(dev, SCB_CUstart);
1324 outb(0,ioaddr+SIGNAL_CA);
1325 boguscount = 100;
1327 else
1329 printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
1330 eexp_hw_init586(dev);
1331 netif_wake_queue(dev);
1332 return;
1340 * Writes down the list of transmit buffers into card memory. Each
1341 * entry consists of an 82586 transmit command, followed by a jump
1342 * pointing to itself. When we want to transmit a packet, we write
1343 * the data into the appropriate transmit buffer and then modify the
1344 * preceding jump to point at the new transmit command. This means that
1345 * the 586 command unit is continuously active.
1348 static void eexp_hw_txinit(struct net_device *dev)
1350 struct net_local *lp = (struct net_local *)dev->priv;
1351 unsigned short tx_block = TX_BUF_START;
1352 unsigned short curtbuf;
1353 unsigned short ioaddr = dev->base_addr;
1355 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ )
1357 outw(tx_block, ioaddr + WRITE_PTR);
1359 outw(0x0000, ioaddr + DATAPORT);
1360 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT);
1361 outw(tx_block+0x08, ioaddr + DATAPORT);
1362 outw(tx_block+0x0e, ioaddr + DATAPORT);
1364 outw(0x0000, ioaddr + DATAPORT);
1365 outw(0x0000, ioaddr + DATAPORT);
1366 outw(tx_block+0x08, ioaddr + DATAPORT);
1368 outw(0x8000, ioaddr + DATAPORT);
1369 outw(-1, ioaddr + DATAPORT);
1370 outw(tx_block+0x16, ioaddr + DATAPORT);
1371 outw(0x0000, ioaddr + DATAPORT);
1373 tx_block += TX_BUF_SIZE;
1375 lp->tx_head = TX_BUF_START;
1376 lp->tx_reap = TX_BUF_START;
1377 lp->tx_tail = tx_block - TX_BUF_SIZE;
1378 lp->tx_link = lp->tx_tail + 0x08;
1379 lp->rx_buf_start = tx_block;
1384 * Write the circular list of receive buffer descriptors to card memory.
1385 * The end of the list isn't marked, which means that the 82586 receive
1386 * unit will loop until buffers become available (this avoids it giving us
1387 * "out of resources" messages).
1390 static void eexp_hw_rxinit(struct net_device *dev)
1392 struct net_local *lp = (struct net_local *)dev->priv;
1393 unsigned short rx_block = lp->rx_buf_start;
1394 unsigned short ioaddr = dev->base_addr;
1396 lp->num_rx_bufs = 0;
1397 lp->rx_first = lp->rx_ptr = rx_block;
1400 lp->num_rx_bufs++;
1402 outw(rx_block, ioaddr + WRITE_PTR);
1404 outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT);
1405 outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT);
1406 outw(0xffff, ioaddr+DATAPORT);
1408 outw(0x0000, ioaddr+DATAPORT);
1409 outw(0xdead, ioaddr+DATAPORT);
1410 outw(0xdead, ioaddr+DATAPORT);
1411 outw(0xdead, ioaddr+DATAPORT);
1412 outw(0xdead, ioaddr+DATAPORT);
1413 outw(0xdead, ioaddr+DATAPORT);
1414 outw(0xdead, ioaddr+DATAPORT);
1416 outw(0x0000, ioaddr+DATAPORT);
1417 outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT);
1418 outw(rx_block + 0x20, ioaddr+DATAPORT);
1419 outw(0, ioaddr+DATAPORT);
1420 outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT);
1422 lp->rx_last = rx_block;
1423 rx_block += RX_BUF_SIZE;
1424 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1427 /* Make first Rx frame descriptor point to first Rx buffer
1428 descriptor */
1429 outw(lp->rx_first + 6, ioaddr+WRITE_PTR);
1430 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1432 /* Close Rx frame descriptor ring */
1433 outw(lp->rx_last + 4, ioaddr+WRITE_PTR);
1434 outw(lp->rx_first, ioaddr+DATAPORT);
1436 /* Close Rx buffer descriptor ring */
1437 outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR);
1438 outw(lp->rx_first + 0x16, ioaddr+DATAPORT);
1443 * Un-reset the 586, and start the configuration sequence. We don't wait for
1444 * this to finish, but allow the interrupt handler to start the CU and RU for
1445 * us. We can't start the receive/transmission system up before we know that
1446 * the hardware is configured correctly.
1449 static void eexp_hw_init586(struct net_device *dev)
1451 struct net_local *lp = (struct net_local *)dev->priv;
1452 unsigned short ioaddr = dev->base_addr;
1453 int i;
1455 #if NET_DEBUG > 6
1456 printk("%s: eexp_hw_init586()\n", dev->name);
1457 #endif
1459 lp->started = 0;
1461 set_loopback(dev);
1463 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1465 /* Download the startup code */
1466 outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR);
1467 outw(lp->width?0x0001:0x0000, ioaddr + 0x8006);
1468 outw(0x0000, ioaddr + 0x8008);
1469 outw(0x0000, ioaddr + 0x800a);
1470 outw(0x0000, ioaddr + 0x800c);
1471 outw(0x0000, ioaddr + 0x800e);
1473 for (i = 0; i < (sizeof(start_code)); i+=32) {
1474 int j;
1475 outw(i, ioaddr + SM_PTR);
1476 for (j = 0; j < 16; j+=2)
1477 outw(start_code[(i+j)/2],
1478 ioaddr+0x4000+j);
1479 for (j = 0; j < 16; j+=2)
1480 outw(start_code[(i+j+16)/2],
1481 ioaddr+0x8000+j);
1484 /* Do we want promiscuous mode or multicast? */
1485 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1486 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1487 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1488 ioaddr+SHADOW(CONF_PROMISC));
1489 lp->was_promisc = dev->flags & IFF_PROMISC;
1490 #if 0
1491 eexp_setup_filter(dev);
1492 #endif
1494 /* Write our hardware address */
1495 outw(CONF_HWADDR & ~31, ioaddr+SM_PTR);
1496 outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
1497 outw(((unsigned short *)dev->dev_addr)[1],
1498 ioaddr+SHADOW(CONF_HWADDR+2));
1499 outw(((unsigned short *)dev->dev_addr)[2],
1500 ioaddr+SHADOW(CONF_HWADDR+4));
1502 eexp_hw_txinit(dev);
1503 eexp_hw_rxinit(dev);
1505 outb(0,ioaddr+EEPROM_Ctrl);
1506 mdelay(5);
1508 scb_command(dev, 0xf000);
1509 outb(0,ioaddr+SIGNAL_CA);
1511 outw(0, ioaddr+SM_PTR);
1514 unsigned short rboguscount=50,rfailcount=5;
1515 while (inw(ioaddr+0x4000))
1517 if (!--rboguscount)
1519 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1520 dev->name);
1521 scb_command(dev, 0);
1522 outb(0,ioaddr+SIGNAL_CA);
1523 rboguscount = 100;
1524 if (!--rfailcount)
1526 printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1527 dev->name);
1528 return;
1534 scb_wrcbl(dev, CONF_LINK);
1535 scb_command(dev, 0xf000|SCB_CUstart);
1536 outb(0,ioaddr+SIGNAL_CA);
1539 unsigned short iboguscount=50,ifailcount=5;
1540 while (!scb_status(dev))
1542 if (!--iboguscount)
1544 if (--ifailcount)
1546 printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1547 dev->name, scb_status(dev), scb_rdcmd(dev));
1548 scb_wrcbl(dev, CONF_LINK);
1549 scb_command(dev, 0xf000|SCB_CUstart);
1550 outb(0,ioaddr+SIGNAL_CA);
1551 iboguscount = 100;
1553 else
1555 printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1556 return;
1562 clear_loopback(dev);
1563 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1565 lp->init_time = jiffies;
1566 #if NET_DEBUG > 6
1567 printk("%s: leaving eexp_hw_init586()\n", dev->name);
1568 #endif
1569 return;
1572 static void eexp_setup_filter(struct net_device *dev)
1574 struct dev_mc_list *dmi = dev->mc_list;
1575 unsigned short ioaddr = dev->base_addr;
1576 int count = dev->mc_count;
1577 int i;
1578 if (count > 8) {
1579 printk(KERN_INFO "%s: too many multicast addresses (%d)\n",
1580 dev->name, count);
1581 count = 8;
1584 outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR);
1585 outw(count, ioaddr+SHADOW(CONF_NR_MULTICAST));
1586 for (i = 0; i < count; i++) {
1587 unsigned short *data = (unsigned short *)dmi->dmi_addr;
1588 if (!dmi) {
1589 printk(KERN_INFO "%s: too few multicast addresses\n", dev->name);
1590 break;
1592 if (dmi->dmi_addrlen != ETH_ALEN) {
1593 printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
1594 continue;
1596 outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR);
1597 outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
1598 outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR);
1599 outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
1600 outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR);
1601 outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
1606 * Set or clear the multicast filter for this adaptor.
1608 static void
1609 eexp_set_multicast(struct net_device *dev)
1611 unsigned short ioaddr = dev->base_addr;
1612 struct net_local *lp = (struct net_local *)dev->priv;
1613 int kick = 0, i;
1614 if ((dev->flags & IFF_PROMISC) != lp->was_promisc) {
1615 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR);
1616 i = inw(ioaddr+SHADOW(CONF_PROMISC));
1617 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1),
1618 ioaddr+SHADOW(CONF_PROMISC));
1619 lp->was_promisc = dev->flags & IFF_PROMISC;
1620 kick = 1;
1622 if (!(dev->flags & IFF_PROMISC)) {
1623 eexp_setup_filter(dev);
1624 if (lp->old_mc_count != dev->mc_count) {
1625 kick = 1;
1626 lp->old_mc_count = dev->mc_count;
1629 if (kick) {
1630 unsigned long oj;
1631 scb_command(dev, SCB_CUsuspend);
1632 outb(0, ioaddr+SIGNAL_CA);
1633 outb(0, ioaddr+SIGNAL_CA);
1634 #if 0
1635 printk("%s: waiting for CU to go suspended\n", dev->name);
1636 #endif
1637 oj = jiffies;
1638 while ((SCB_CUstat(scb_status(dev)) == 2) &&
1639 ((jiffies-oj) < 2000));
1640 if (SCB_CUstat(scb_status(dev)) == 2)
1641 printk("%s: warning, CU didn't stop\n", dev->name);
1642 lp->started &= ~(STARTED_CU);
1643 scb_wrcbl(dev, CONF_LINK);
1644 scb_command(dev, SCB_CUstart);
1645 outb(0, ioaddr+SIGNAL_CA);
1651 * MODULE stuff
1654 #ifdef MODULE
1656 #define EEXP_MAX_CARDS 4 /* max number of cards to support */
1658 static struct net_device dev_eexp[EEXP_MAX_CARDS];
1659 static int irq[EEXP_MAX_CARDS];
1660 static int io[EEXP_MAX_CARDS];
1662 MODULE_PARM(io, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1663 MODULE_PARM(irq, "1-" __MODULE_STRING(EEXP_MAX_CARDS) "i");
1664 MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)");
1665 MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)");
1666 MODULE_LICENSE("GPL");
1669 /* Ideally the user would give us io=, irq= for every card. If any parameters
1670 * are specified, we verify and then use them. If no parameters are given, we
1671 * autoprobe for one card only.
1673 int init_module(void)
1675 int this_dev, found = 0;
1677 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1678 struct net_device *dev = &dev_eexp[this_dev];
1679 dev->irq = irq[this_dev];
1680 dev->base_addr = io[this_dev];
1681 dev->init = express_probe;
1682 if (io[this_dev] == 0) {
1683 if (this_dev) break;
1684 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1686 if (register_netdev(dev) != 0) {
1687 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1688 if (found != 0) return 0;
1689 return -ENXIO;
1691 found++;
1693 return 0;
1696 void cleanup_module(void)
1698 int this_dev;
1700 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1701 struct net_device *dev = &dev_eexp[this_dev];
1702 if (dev->priv != NULL) {
1703 unregister_netdev(dev);
1704 kfree(dev->priv);
1705 dev->priv = NULL;
1709 #endif
1712 * Local Variables:
1713 * c-file-style: "linux"
1714 * tab-width: 8
1715 * End: