root/drivers/net/eexpress.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. express_probe
  2. eexp_open
  3. eexp_close
  4. eexp_stats
  5. eexp_xmit
  6. eexp_irq
  7. eexp_hw_rx
  8. eexp_hw_tx
  9. eexp_hw_probe
  10. eexp_hw_readeeprom
  11. eexp_hw_lasttxstat
  12. eexp_hw_txrestart
  13. eexp_hw_txinit
  14. eexp_hw_rxinit
  15. eexp_hw_init586
  16. eexp_hw_ASICrst
  17. eexp_set_multicast
  18. init_module
  19. cleanup_module

   1 /* $Id: eexpress.c,v 1.12 1996/04/15 17:27:30 phil Exp $
   2  *
   3  * Intel EtherExpress device driver for Linux
   4  *
   5  * Original version written 1993 by Donald Becker
   6  * Modularized by Pauline Middelink <middelin@polyware.iaf.nl>
   7  * Changed to support io= irq= by Alan Cox <Alan.Cox@linux.org>
   8  * Reworked 1995 by John Sullivan <js10039@cam.ac.uk>
   9  * More fixes by Philip Blundell <pjb27@cam.ac.uk>
  10  */
  11 
  12 /*
  13  * The original EtherExpress driver was just about usable, but
  14  * suffered from a long startup delay, a hard limit of 16k memory
  15  * usage on the card (EtherExpress 16s have either 32k or 64k),
  16  * and random locks under load. The last was particularly annoying
  17  * and made running eXceed/W preferable to Linux/XFree. After hacking
  18  * through the driver for a couple of days, I had fixed most of the
  19  * card handling errors, at the expense of turning the code into
  20  * a complete jungle, but still hadn't tracked down the lock-ups.
  21  * I had hoped these would be an IP bug, but failed to reproduce them
  22  * under other drivers, so decided to start from scratch and rewrite
  23  * the driver cleanly. And here it is.
  24  *
  25  * It's still not quite there, but self-corrects a lot more problems.
  26  * the 'CU wedged, resetting...' message shouldn't happen at all, but
  27  * at least we recover. It still locks occasionally, any ideas welcome.
  28  *
  29  * The original startup delay experienced by some people was due to the
  30  * first ARP request for the address of the default router getting lost.
  31  * (mostly the reply we were getting back was arriving before our
  32  * hardware address was set up, or before the configuration sequence
  33  * had told the card NOT to strip of the frame header). If you a long
  34  * startup delay, you may have lost this ARP request/reply, although
  35  * the original cause has been fixed. However, it is more likely that
  36  * you've just locked under this version.
  37  *
  38  * The main changes are in the 586 initialization procedure (which was
  39  * just broken before - the EExp is a strange beasty and needs careful
  40  * handling) the receive buffer handling (we now use a non-terminating
  41  * circular list of buffers, which stops the card giving us out-of-
  42  * resources errors), and the transmit code. The driver is also more
  43  * structured, and I have tried to keep the kernel interface separate
  44  * from the hardware interface (although some routines naturally want
  45  * to do both).
  46  *
  47  * John Sullivan
  48  *
  49  * 18/5/95:
  50  *
  51  * The lock-ups seem to happen when you access card memory after a 586
  52  * reset. This happens only 1 in 12 resets, on a random basis, and
  53  * completely locks the machine. As far as I can see there is no
  54  * workaround possible - the only thing to be done is make sure we
  55  * never reset the card *after* booting the kernel - once at probe time
  56  * must be sufficient, and we'll just have to put up with that failing
  57  * occasionally (or buy a new NIC). By the way, this looks like a 
  58  * definite card bug, since Intel's own driver for DOS does exactly the
  59  * same.
  60  *
  61  * This bug makes switching in and out of promiscuous mode a risky
  62  * business, since we must do a 586 reset each time.
  63  */
  64 
  65 /*
  66  * Sources:
  67  *
  68  * The original eexpress.c by Donald Becker
  69  *   Sources: the Crynwr EtherExpress driver source.
  70  *            the Intel Microcommunications Databook Vol.1 1990
  71  *
  72  * wavelan.c and i82586.h
  73  *   This was invaluable for the complete '586 configuration details
  74  *   and command format.
  75  *
  76  * The Crynwr sources (again)
  77  *   Not as useful as the Wavelan driver, but then I had eexpress.c to
  78  *   go off.
  79  *
  80  * The Intel EtherExpress 16 ethernet card
  81  *   Provided the only reason I want to see a working etherexpress driver.
  82  *   A lot of fixes came from just observing how the card (mis)behaves when
  83  *   you prod it.
  84  *
  85  */
  86 
  87 static char version[] = 
  88 "eexpress.c: v0.10 04-May-95 John Sullivan <js10039@cam.ac.uk>\n"
  89 "            v0.13 10-Apr-96 Philip Blundell <phil@tazenda.demon.co.uk>\n";
  90 
  91 #include <linux/module.h>
  92 
  93 #include <linux/kernel.h>
  94 #include <linux/sched.h>
  95 #include <linux/types.h>
  96 #include <linux/fcntl.h>
  97 #include <linux/interrupt.h>
  98 #include <linux/ptrace.h>
  99 #include <linux/ioport.h>
 100 #include <linux/string.h>
 101 #include <linux/in.h>
 102 #include <asm/system.h>
 103 #include <asm/bitops.h>
 104 #include <asm/io.h>
 105 #include <asm/dma.h>
 106 #include <linux/errno.h>
 107 
 108 #include <linux/netdevice.h>
 109 #include <linux/etherdevice.h>
 110 #include <linux/skbuff.h>
 111 #include <linux/malloc.h>
 112 
 113 /*
 114  * Not actually used yet - may be implemented when the driver has
 115  * been debugged!
 116  *
 117  * Debug Level          Driver Status
 118  *      0               Final release
 119  *      1               Beta test
 120  *      2
 121  *      3
 122  *      4               Report timeouts & 586 errors (normal debug level)
 123  *      5               Report all major events
 124  *      6               Dump sent/received packet contents
 125  *      7               Report function entry/exit
 126  */
 127 
 128 #ifndef NET_DEBUG
 129 #define NET_DEBUG 4
 130 #endif
 131 static unsigned int net_debug = NET_DEBUG;
 132 
 133 #undef F_DEB
 134 
 135 #include "eth82586.h"
 136 
 137 #define PRIV(x)         ((struct net_local *)(x)->priv)
 138 #define EEXP_IO_EXTENT  16
 139 
 140 /*
 141  * Private data declarations
 142  */
 143 
 144 struct net_local 
 145 {
 146         struct enet_statistics stats;
 147         unsigned long init_time;        /* jiffies when eexp_hw_init586 called */
 148         unsigned short rx_first;        /* first rx buf, same as RX_BUF_START */
 149         unsigned short rx_last;         /* last rx buf */
 150         unsigned short tx_head;         /* next free tx buf */
 151         unsigned short tx_reap;         /* first in-use tx buf */
 152         unsigned short tx_tail;         /* previous tx buf to tx_head */
 153         unsigned short tx_link;         /* last known-executing tx buf */
 154         unsigned short last_tx_restart; /* set to tx_link when we restart the CU */
 155         unsigned char started;
 156         unsigned char promisc;
 157         unsigned short rx_buf_start;
 158         unsigned short rx_buf_end;
 159         unsigned short num_tx_bufs;
 160         unsigned short num_rx_bufs;
 161 };
 162 
 163 unsigned short start_code[] = {
 164         0x0000,                 /* SCP: set bus to 16 bits */
 165         0x0000,0x0000,          /* junk */
 166         0x0000,0x0000,          /* address of ISCP (lo,hi) */
 167 
 168         0x0001,                 /* ISCP: busy - cleared after reset */
 169         0x0008,0x0000,0x0000,   /* offset,address (lo,hi) of SCB */
 170 
 171         0x0000,0x0000,          /* SCB: status, commands */
 172         0x0000,0x0000,          /* links to first command block, first receive descriptor */
 173         0x0000,0x0000,          /* CRC error, alignment error counts */
 174         0x0000,0x0000,          /* out of resources, overrun error counts */
 175 
 176         0x0000,0x0000,          /* pad */
 177         0x0000,0x0000,
 178 
 179         0x0000,Cmd_Config,      /* startup configure sequence, at 0x0020 */
 180         0x0032,                 /* link to next command */
 181         0x080c,                 /* 12 bytes follow : fifo threshold=8 */
 182         0x2e40,                 /* don't rx bad frames : SRDY/ARDY => ext. sync. : preamble len=8
 183                                  * take addresses from data buffers : 6 bytes/address */
 184         0x6000,                 /* default backoff method & priority : interframe spacing = 0x60 */
 185         0xf200,                 /* slot time=0x200 : max collision retry = 0xf */
 186         0x0000,                 /* no HDLC : normal CRC : enable broadcast : disable promiscuous/multicast modes */
 187         0x003c,                 /* minimum frame length = 60 octets) */
 188 
 189         0x0000,Cmd_INT|Cmd_SetAddr,
 190         0x003e,                 /* link to next command */
 191         0x0000,0x0000,0x0000,   /* hardware address placed here, 0x0038 */
 192         0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */
 193         0x003e,
 194 
 195         0x0000
 196 
 197 };
 198 
 199 #define CONF_LINK 0x0020
 200 #define CONF_HW_ADDR 0x0038
 201 
 202 /* maps irq number to EtherExpress magic value */
 203 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
 204 
 205 /*
 206  * Prototypes for Linux interface
 207  */
 208 
 209 extern int                  express_probe(struct device *dev);
 210 static int                     eexp_open (struct device *dev);
 211 static int                     eexp_close(struct device *dev);
 212 static struct enet_statistics *eexp_stats(struct device *dev);
 213 static int                     eexp_xmit (struct sk_buff *buf, struct device *dev);
 214 
 215 static void                    eexp_irq  (int irq, void *dev_addr, struct pt_regs *regs);
 216 static void                    eexp_set_multicast(struct device *dev);
 217 
 218 /*
 219  * Prototypes for hardware access functions
 220  */
 221 
 222 static void           eexp_hw_rx        (struct device *dev);
 223 static void           eexp_hw_tx        (struct device *dev, unsigned short *buf, unsigned short len);
 224 static int            eexp_hw_probe     (struct device *dev,unsigned short ioaddr);
 225 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location);
 226 
 227 static unsigned short eexp_hw_lasttxstat(struct device *dev);
 228 static void           eexp_hw_txrestart (struct device *dev);
 229 
 230 static void           eexp_hw_txinit    (struct device *dev);
 231 static void           eexp_hw_rxinit    (struct device *dev);
 232 
 233 static void           eexp_hw_init586   (struct device *dev);
 234 static void           eexp_hw_ASICrst   (struct device *dev);
 235 
 236 /*
 237  * Linux interface
 238  */
 239 
 240 /*
 241  * checks for presence of EtherExpress card
 242  */
 243 
 244 int express_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         unsigned short *port,ports[] = { 0x0300,0x0270,0x0320,0x0340,0 };
 247         unsigned short ioaddr = dev->base_addr;
 248 
 249         if (ioaddr&0xfe00)
 250                 return eexp_hw_probe(dev,ioaddr);
 251         else if (ioaddr)
 252                 return ENXIO;
 253 
 254         for ( port=&ports[0] ; *port ; port++ ) 
 255         {
 256                 unsigned short sum = 0;
 257                 int i;
 258                 for ( i=0 ; i<4 ; i++ ) 
 259                 {
 260                         unsigned short t;
 261                         t = inb(*port + ID_PORT);
 262                         sum |= (t>>4) << ((t & 0x03)<<2);
 263                 }
 264                 if (sum==0xbaba && !eexp_hw_probe(dev,*port)) 
 265                         return 0;
 266         }
 267         return ENODEV;
 268 }
 269 
 270 /*
 271  * open and initialize the adapter, ready for use
 272  */
 273 
 274 static int eexp_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 275 {
 276         int irq = dev->irq;
 277         unsigned short ioaddr = dev->base_addr;
 278 
 279 #if NET_DEBUG > 6
 280         printk(KERN_DEBUG "%s: eexp_open()\n", dev->name);
 281 #endif
 282 
 283         if (!irq || !irqrmap[irq]) 
 284                 return -ENXIO;
 285 
 286         if (irq2dev_map[irq] ||
 287               /* more consistent, surely? */
 288            ((irq2dev_map[irq]=dev),0) ||
 289              request_irq(irq,&eexp_irq,0,"eexpress",NULL)) 
 290                 return -EAGAIN;
 291 
 292         request_region(ioaddr, EEXP_IO_EXTENT, "eexpress");
 293         dev->tbusy = 0;
 294         dev->interrupt = 0;
 295         eexp_hw_init586(dev);
 296         dev->start = 1;
 297         MOD_INC_USE_COUNT;
 298 #if NET_DEBUG > 6
 299         printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name);
 300 #endif
 301         return 0;
 302 }
 303 
 304 /*
 305  * close and disable the interface, leaving
 306  * the 586 in reset
 307  */
 308 static int eexp_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         unsigned short ioaddr = dev->base_addr;
 311         int irq = dev->irq;
 312 
 313         dev->tbusy = 1; 
 314         dev->start = 0;
 315   
 316         outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
 317         PRIV(dev)->started = 0;
 318         outw(SCB_CUsuspend|SCB_RUsuspend,ioaddr+SCB_CMD);
 319         outb(0,ioaddr+SIGNAL_CA);
 320         free_irq(irq,NULL);
 321         irq2dev_map[irq] = NULL;
 322         outb(i586_RST,ioaddr+EEPROM_Ctrl);
 323         release_region(ioaddr,16);
 324         MOD_DEC_USE_COUNT;
 325         return 0;
 326 }
 327 
 328 /*
 329  * Return interface stats
 330  */
 331 
 332 static struct enet_statistics *eexp_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 333 {
 334         struct net_local *lp = (struct net_local *)dev->priv;
 335 
 336         /* 
 337          * Hmmm, this looks a little too easy... The card maintains
 338          * some stats in the SCB, and I'm not convinced we're
 339          * incrementing the most sensible statistics when the card
 340          * returns an error (esp. slow DMA, out-of-resources)
 341          */
 342         return &lp->stats;
 343 }
 344 
 345 /*
 346  * Called to transmit a packet, or to allow us to right ourselves
 347  * if the kernel thinks we've died.
 348  */
 349 
 350 static int eexp_xmit(struct sk_buff *buf, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 351 {
 352         struct net_local *lp = (struct net_local *)dev->priv;
 353         unsigned short ioaddr = dev->base_addr;
 354 
 355 #if NET_DEBUG > 6
 356         printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name);
 357 #endif
 358 
 359         outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
 360         if (dev->tbusy) 
 361         {
 362                 /* This will happen, but hopefully not as often as when
 363                  * tbusy==0. If it happens too much, we probably ought
 364                  * to think about unwedging ourselves...
 365                  */
 366                 if (test_bit(0,(void *)&PRIV(dev)->started)) 
 367                 {
 368                         if ((jiffies - dev->trans_start)>5) 
 369                         {
 370                                 if (lp->tx_link==lp->last_tx_restart) 
 371                                 {
 372                                         unsigned short boguscount=200,rsst;
 373                                         printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n",
 374                                                 dev->name,inw(ioaddr+SCB_STATUS));
 375                                         eexp_hw_txinit(dev);
 376                                         lp->last_tx_restart = 0;
 377                                         outw(lp->tx_link,ioaddr+SCB_CBL);
 378                                         outw(0,ioaddr+SCB_STATUS);
 379                                         outw(SCB_CUstart,ioaddr+SCB_CMD);
 380                                         outb(0,ioaddr+SIGNAL_CA);
 381                                         while (!SCB_complete(rsst=inw(ioaddr+SCB_STATUS))) 
 382                                         {
 383                                                 if (!--boguscount) 
 384                                                 {
 385                                                         boguscount=200;
 386                                                         printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n",
 387                                                                 dev->name,rsst);
 388                                                         outw(lp->tx_link,ioaddr+SCB_CBL);
 389                                                         outw(0,ioaddr+SCB_STATUS);
 390                                                         outw(SCB_CUstart,ioaddr+SCB_CMD);
 391                                                         outb(0,ioaddr+SIGNAL_CA);
 392                                                 }
 393                                         }
 394                                         dev->tbusy = 0;
 395                                         mark_bh(NET_BH);
 396                                 }
 397                                 else
 398                                 {
 399                                         unsigned short status = inw(ioaddr+SCB_STATUS);
 400                                         if (SCB_CUdead(status)) 
 401                                         {
 402                                                 unsigned short txstatus = eexp_hw_lasttxstat(dev);
 403                                                 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
 404                                                         dev->name, status, txstatus);
 405                                                 eexp_hw_txrestart(dev);
 406                                         }
 407                                         else
 408                                         {
 409                                                 unsigned short txstatus = eexp_hw_lasttxstat(dev);
 410                                                 if (dev->tbusy && !txstatus) 
 411                                                 {
 412                                                         printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n",
 413                                                                 dev->name,status,txstatus);
 414                                                         eexp_hw_init586(dev); 
 415                                                         dev->tbusy = 0;
 416                                                         mark_bh(NET_BH);
 417                                                 }
 418                                         }
 419                                 }
 420                         }
 421                 }
 422                 else
 423                 {
 424                         if ((jiffies-lp->init_time)>10)
 425                         {
 426                                 unsigned short status = inw(ioaddr+SCB_STATUS);
 427                                 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n",
 428                                         dev->name, status);
 429                                 eexp_hw_init586(dev);
 430                                 dev->tbusy = 0;
 431                                 mark_bh(NET_BH);
 432                         }
 433                 }
 434         }
 435 
 436         if (buf==NULL) 
 437         {
 438                 unsigned short status = inw(ioaddr+SCB_STATUS);
 439                 unsigned short txstatus = eexp_hw_lasttxstat(dev);
 440                 if (SCB_CUdead(status)) 
 441                 {
 442                         printk(KERN_WARNING "%s: CU has died! status %04x %04x, attempting to restart...\n",
 443                                 dev->name, status, txstatus);
 444                         lp->stats.tx_errors++;
 445                         eexp_hw_txrestart(dev);
 446                 }
 447                 dev_tint(dev);
 448                 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
 449                 return 0;
 450         }
 451 
 452         if (set_bit(0,(void *)&dev->tbusy)) 
 453         {
 454                 lp->stats.tx_dropped++;
 455         }
 456         else
 457         {
 458                 unsigned short length = (ETH_ZLEN < buf->len) ? buf->len : ETH_ZLEN;
 459                 unsigned short *data = (unsigned short *)buf->data;
 460 
 461                 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
 462                 eexp_hw_tx(dev,data,length);
 463                 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
 464         }
 465         dev_kfree_skb(buf, FREE_WRITE);
 466         outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
 467         return 0;
 468 }
 469 
 470 /*
 471  * Handle an EtherExpress interrupt
 472  * If we've finished initializing, start the RU and CU up.
 473  * If we've already started, reap tx buffers, handle any received packets,
 474  * check to make sure we've not become wedged.
 475  */
 476 
 477 static void eexp_irq(int irq, void *dev_info, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 478 {
 479         struct device *dev = irq2dev_map[irq];
 480         struct net_local *lp;
 481         unsigned short ioaddr,status,ack_cmd;
 482         unsigned short old_rp,old_wp;
 483 
 484         if (dev==NULL) 
 485         {
 486                 printk(KERN_WARNING "net_interrupt(): irq %d for unknown device caught by EExpress\n",irq);
 487                 return;
 488         }
 489 
 490 #if NET_DEBUG > 6
 491         printk(KERN_DEBUG "%s: interrupt\n", dev->name);
 492 #endif
 493 
 494         dev->interrupt = 1; /* should this be reset on exit? */
 495   
 496         lp = (struct net_local *)dev->priv;
 497         ioaddr = dev->base_addr;
 498 
 499         outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ);
 500         old_rp = inw(ioaddr+READ_PTR);
 501         old_wp = inw(ioaddr+WRITE_PTR);
 502         status = inw(ioaddr+SCB_STATUS);
 503         ack_cmd = SCB_ack(status);
 504 
 505         if (PRIV(dev)->started==0 && SCB_complete(status)) 
 506         {
 507 #if NET_DEBUG > 4
 508                 printk(KERN_DEBUG "%s: SCBcomplete event received\n", dev->name);
 509 #endif
 510                 while (SCB_CUstat(status)==2)
 511                         status = inw_p(ioaddr+SCB_STATUS);
 512 #if NET_DEBUG > 4
 513                 printk(KERN_DEBUG "%s: CU went non-active (status = %08x)\n", dev->name, status);
 514 #endif
 515                 PRIV(dev)->started=1;
 516                 outw_p(lp->tx_link,ioaddr+SCB_CBL);
 517                 outw_p(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
 518                 ack_cmd |= SCB_CUstart | SCB_RUstart;
 519         }
 520         else if (PRIV(dev)->started) 
 521         {
 522                 unsigned short txstatus;
 523                 txstatus = eexp_hw_lasttxstat(dev);
 524         }
 525   
 526         if (SCB_rxdframe(status)) 
 527         {
 528                 eexp_hw_rx(dev);
 529         }
 530 
 531         if ((PRIV(dev)->started&2)!=0 && SCB_RUstat(status)!=4) 
 532         {
 533                 printk(KERN_WARNING "%s: RU stopped status %04x, restarting...\n",
 534                         dev->name,status);
 535                 lp->stats.rx_errors++;
 536                 eexp_hw_rxinit(dev);
 537                 outw(PRIV(dev)->rx_buf_start,ioaddr+SCB_RFA);
 538                 ack_cmd |= SCB_RUstart;
 539         } 
 540         else if (PRIV(dev)->started==1 && SCB_RUstat(status)==4) 
 541                 PRIV(dev)->started|=2;
 542 
 543         outw(ack_cmd,ioaddr+SCB_CMD);
 544         outb(0,ioaddr+SIGNAL_CA);
 545         outw(old_rp,ioaddr+READ_PTR);
 546         outw(old_wp,ioaddr+WRITE_PTR);
 547         outb(SIRQ_en|irqrmap[irq],ioaddr+SET_IRQ);
 548         dev->interrupt = 0;
 549 #if NET_DEBUG > 6
 550         printk(KERN_DEBUG "%s: leaving eexp_irq()\n", dev->name);
 551 #endif
 552         return;
 553 }
 554 
 555 /*
 556  * Hardware access functions
 557  */
 558 
 559 /*
 560  * Check all the receive buffers, and hand any received packets
 561  * to the upper levels. Basic sanity check on each frame
 562  * descriptor
 563  */
 564  
 565 static void eexp_hw_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 566 {
 567         struct net_local *lp = (struct net_local *)dev->priv;
 568         unsigned short ioaddr = dev->base_addr;
 569         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 570         unsigned short old_rp = inw(ioaddr+READ_PTR);
 571         unsigned short rx_block = lp->rx_first;
 572         unsigned short boguscount = lp->num_rx_bufs;
 573 
 574 #if NET_DEBUG > 6
 575         printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name);
 576 #endif
 577 
 578         while (outw(rx_block,ioaddr+READ_PTR),boguscount--) 
 579         {
 580                 unsigned short status = inw(ioaddr);
 581                 unsigned short rfd_cmd = inw(ioaddr);
 582                 unsigned short rx_next = inw(ioaddr);
 583                 unsigned short pbuf = inw(ioaddr);
 584                 unsigned short pkt_len;
 585 
 586                 if (FD_Done(status)) 
 587                 {
 588                         outw(pbuf,ioaddr+READ_PTR);
 589                         pkt_len = inw(ioaddr);
 590 
 591                         if (rfd_cmd!=0x0000 || pbuf!=rx_block+0x16
 592                                 || (pkt_len & 0xc000)!=0xc000) 
 593                         {
 594                                 printk(KERN_WARNING "%s: Rx frame at %04x corrupted, status %04x, cmd %04x, "
 595                                         "next %04x, pbuf %04x, len %04x\n",dev->name,rx_block,
 596                                         status,rfd_cmd,rx_next,pbuf,pkt_len);
 597                                 boguscount++;
 598                                 continue;
 599                         }
 600                         else if (!FD_OK(status)) 
 601                         {
 602                                 lp->stats.rx_errors++;
 603                                 if (FD_CRC(status)) 
 604                                         lp->stats.rx_crc_errors++;
 605                                 if (FD_Align(status))
 606                                         lp->stats.rx_frame_errors++;
 607                                 if (FD_Resrc(status))
 608                                         lp->stats.rx_fifo_errors++;
 609                                 if (FD_DMA(status))
 610                                         lp->stats.rx_over_errors++;
 611                                 if (FD_Short(status))
 612                                         lp->stats.rx_length_errors++;
 613                         }
 614                         else
 615                         {
 616                                 struct sk_buff *skb;
 617                                 pkt_len &= 0x3fff;
 618                                 skb = dev_alloc_skb(pkt_len+16);
 619                                 if (skb == NULL) 
 620                                 {
 621                                         printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name);
 622                                         lp->stats.rx_dropped++;
 623                                         break;
 624                                 }
 625                                 skb->dev = dev;
 626                                 skb_reserve(skb, 2);
 627                                 outw(pbuf+10,ioaddr+READ_PTR);
 628                                 insw(ioaddr,skb_put(skb,pkt_len),(pkt_len+1)>>1);
 629                                 skb->protocol = eth_type_trans(skb,dev);
 630                                 netif_rx(skb);
 631                                 lp->stats.rx_packets++;
 632                         }
 633                         outw(rx_block,ioaddr+WRITE_PTR);
 634                         outw(0x0000,ioaddr);
 635                         outw(0x0000,ioaddr);
 636                 }
 637                 rx_block = rx_next;
 638         }
 639         outw(old_rp,ioaddr+READ_PTR);
 640         outw(old_wp,ioaddr+WRITE_PTR);
 641 }
 642 
 643 /*
 644  * Hand a packet to the card for transmission
 645  * If we get here, we MUST have already checked
 646  * to make sure there is room in the transmit
 647  * buffer region
 648  */
 649 
 650 static void eexp_hw_tx(struct device *dev, unsigned short *buf, unsigned short len)
     /* [previous][next][first][last][top][bottom][index][help] */
 651 {
 652         struct net_local *lp = (struct net_local *)dev->priv;
 653         unsigned short ioaddr = dev->base_addr;
 654         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 655 
 656         outw(lp->tx_head,ioaddr+WRITE_PTR);
 657         outw(0x0000,ioaddr);
 658         outw(Cmd_INT|Cmd_Xmit,ioaddr);
 659         outw(lp->tx_head+0x08,ioaddr);
 660         outw(lp->tx_head+0x0e,ioaddr);
 661         outw(0x0000,ioaddr);
 662         outw(0x0000,ioaddr);
 663         outw(lp->tx_head+0x08,ioaddr);
 664         outw(0x8000|len,ioaddr);
 665         outw(-1,ioaddr);
 666         outw(lp->tx_head+0x16,ioaddr);
 667         outw(0,ioaddr);
 668         outsw(ioaddr,buf,(len+1)>>1);
 669         outw(lp->tx_tail+0x0c,ioaddr+WRITE_PTR);
 670         outw(lp->tx_head,ioaddr);
 671         dev->trans_start = jiffies;
 672         lp->tx_tail = lp->tx_head;
 673         if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE)) 
 674                 lp->tx_head = TX_BUF_START;
 675         else 
 676                 lp->tx_head += TX_BUF_SIZE;
 677         if (lp->tx_head != lp->tx_reap) 
 678                 dev->tbusy = 0;
 679         outw(old_wp,ioaddr+WRITE_PTR);
 680 }
 681 
 682 /*
 683  * Sanity check the suspected EtherExpress card
 684  * Read hardware address, reset card, size memory and
 685  * initialize buffer memory pointers. These should
 686  * probably be held in dev->priv, in case someone has 2
 687  * differently configured cards in their box (Arghhh!)
 688  */
 689 
 690 static int eexp_hw_probe(struct device *dev, unsigned short ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         unsigned short hw_addr[3];
 693         int i;
 694         unsigned char *chw_addr = (unsigned char *)hw_addr;
 695 
 696         printk("%s: EtherExpress at %#x, ",dev->name,ioaddr);
 697 
 698         hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
 699         hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
 700         hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
 701 
 702         if (hw_addr[2]!=0x00aa || ((hw_addr[1] & 0xff00)!=0x0000)) 
 703         {
 704                 printk("rejected: invalid address %04x%04x%04x\n",
 705                         hw_addr[2],hw_addr[1],hw_addr[0]);
 706                 return ENODEV;
 707         }
 708 
 709         dev->base_addr = ioaddr;
 710         for ( i=0 ; i<6 ; i++ ) 
 711                 dev->dev_addr[i] = chw_addr[5-i];
 712 
 713         {
 714                 char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0};
 715                 char *ifmap[]={"AUI", "BNC", "10baseT"};
 716                 enum iftype {AUI=0, BNC=1, TP=2};
 717                 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
 718 
 719                 dev->irq = irqmap[setupval>>13];
 720                 dev->if_port = !(setupval & 0x1000) ? AUI :
 721                         eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TP : BNC;
 722 
 723                 printk("IRQ %d, Interface %s, ",dev->irq,ifmap[dev->if_port]);
 724 
 725                 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
 726                 outb(0,ioaddr+SET_IRQ);
 727         }
 728 
 729         dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 730         if (!dev->priv) 
 731                 return -ENOMEM;
 732 
 733         memset(dev->priv, 0, sizeof(struct net_local));
 734 
 735         eexp_hw_ASICrst(dev);
 736 
 737         {
 738                 unsigned short i586mso = 0x023e;
 739                 unsigned short old_wp,old_rp,old_a0,old_a1;
 740                 unsigned short a0_0,a1_0,a0_1,a1_1;
 741 
 742                 old_wp = inw(ioaddr+WRITE_PTR);
 743                 old_rp = inw(ioaddr+READ_PTR);
 744                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 745                 old_a1 = inw(ioaddr);
 746                 outw(i586mso,ioaddr+READ_PTR);
 747                 old_a0 = inw(ioaddr);
 748                 outw(i586mso,ioaddr+WRITE_PTR);
 749                 outw(0x55aa,ioaddr);
 750                 outw(i586mso,ioaddr+READ_PTR);
 751                 a0_0 = inw(ioaddr);
 752                 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
 753                 outw(0x5a5a,ioaddr);
 754                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 755                 a1_0 = inw(ioaddr);
 756                 outw(i586mso,ioaddr+READ_PTR);
 757                 a0_1 = inw(ioaddr);
 758                 outw(i586mso,ioaddr+WRITE_PTR);
 759                 outw(0x1234,ioaddr);
 760                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 761                 a1_1 = inw(ioaddr);
 762 
 763                 if ((a0_0 != a0_1) || (a1_0 != a1_1) ||
 764                         (a1_0 != 0x5a5a) || (a0_0 != 0x55aa)) 
 765                 {
 766                         printk("32k\n");
 767                         PRIV(dev)->rx_buf_end = 0x7ff6;
 768                         PRIV(dev)->num_tx_bufs = 4;
 769                 }
 770                 else
 771                 {
 772                         printk("64k\n");
 773                         PRIV(dev)->num_tx_bufs = 8;
 774                         PRIV(dev)->rx_buf_start = TX_BUF_START + (PRIV(dev)->num_tx_bufs*TX_BUF_SIZE);
 775                         PRIV(dev)->rx_buf_end = 0xfff6;
 776                 }
 777 
 778                 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
 779                 outw(old_a1,ioaddr);
 780                 outw(i586mso,ioaddr+WRITE_PTR);
 781                 outw(old_a0,ioaddr);
 782                 outw(old_wp,ioaddr+WRITE_PTR);
 783                 outw(old_rp,ioaddr+READ_PTR);
 784         }
 785   
 786         if (net_debug) 
 787                 printk(version);
 788         dev->open = eexp_open;
 789         dev->stop = eexp_close;
 790         dev->hard_start_xmit = eexp_xmit;
 791         dev->get_stats = eexp_stats;
 792         dev->set_multicast_list = &eexp_set_multicast;
 793         ether_setup(dev);
 794         return 0;
 795 }
 796 
 797 /*
 798  *      Read a word from eeprom location (0-63?)
 799  */
 800 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location)
     /* [previous][next][first][last][top][bottom][index][help] */
 801 {
 802         unsigned short cmd = 0x180|(location&0x7f);
 803         unsigned short rval = 0,wval = EC_CS|i586_RST;
 804         int i;
 805  
 806         outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
 807         for ( i=0x100 ; i ; i>>=1 ) 
 808         {
 809                 if (cmd&i) 
 810                         wval |= EC_Wr;
 811                 else 
 812                         wval &= ~EC_Wr;
 813 
 814                 outb(wval,ioaddr+EEPROM_Ctrl);
 815                 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 816                 eeprom_delay();
 817                 outb(wval,ioaddr+EEPROM_Ctrl);
 818                 eeprom_delay();
 819         }       
 820         wval &= ~EC_Wr;
 821         outb(wval,ioaddr+EEPROM_Ctrl);
 822         for ( i=0x8000 ; i ; i>>=1 ) 
 823         {
 824                 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 825                 eeprom_delay();
 826                 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd) 
 827                         rval |= i;
 828                 outb(wval,ioaddr+EEPROM_Ctrl);
 829                 eeprom_delay();
 830         }
 831         wval &= ~EC_CS;
 832         outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 833         eeprom_delay();
 834         outb(wval,ioaddr+EEPROM_Ctrl);
 835         eeprom_delay();
 836         return rval;
 837 }
 838 
 839 /*
 840  * Reap tx buffers and return last transmit status.
 841  * if ==0 then either:
 842  *    a) we're not transmitting anything, so why are we here?
 843  *    b) we've died.
 844  * otherwise, Stat_Busy(return) means we've still got some packets
 845  * to transmit, Stat_Done(return) means our buffers should be empty
 846  * again
 847  */
 848 
 849 static unsigned short eexp_hw_lasttxstat(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 850 {
 851         struct net_local *lp = (struct net_local *)dev->priv;
 852         unsigned short ioaddr = dev->base_addr;
 853         unsigned short old_rp = inw(ioaddr+READ_PTR);
 854         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 855         unsigned short tx_block = lp->tx_reap;
 856         unsigned short status;
 857   
 858         if (!test_bit(0,(void *)&dev->tbusy) && lp->tx_head==lp->tx_reap) 
 859                 return 0x0000;
 860 
 861         do
 862         {
 863                 outw(tx_block,ioaddr+READ_PTR);
 864                 status = inw(ioaddr);
 865                 if (!Stat_Done(status)) 
 866                 {
 867                         lp->tx_link = tx_block;
 868                         outw(old_rp,ioaddr+READ_PTR);
 869                         outw(old_wp,ioaddr+WRITE_PTR);
 870                         return status;
 871                 }
 872                 else 
 873                 {
 874                         lp->last_tx_restart = 0;
 875                         lp->stats.collisions += Stat_NoColl(status);
 876                         if (!Stat_OK(status)) 
 877                         {
 878                                 if (Stat_Abort(status)) 
 879                                         lp->stats.tx_aborted_errors++;
 880                                 if (Stat_TNoCar(status) || Stat_TNoCTS(status)) 
 881                                         lp->stats.tx_carrier_errors++;
 882                                 if (Stat_TNoDMA(status)) 
 883                                         lp->stats.tx_fifo_errors++;
 884                         }
 885                         else
 886                                 lp->stats.tx_packets++;
 887                 }
 888                 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE)) 
 889                         lp->tx_reap = tx_block = TX_BUF_START;
 890                 else
 891                         lp->tx_reap = tx_block += TX_BUF_SIZE;
 892                 dev->tbusy = 0;
 893                 mark_bh(NET_BH);
 894         }
 895         while (lp->tx_reap != lp->tx_head);
 896 
 897         lp->tx_link = lp->tx_tail + 0x08;
 898         outw(old_rp,ioaddr+READ_PTR);
 899         outw(old_wp,ioaddr+WRITE_PTR);
 900 
 901         return status;
 902 }
 903 
 904 /* 
 905  * This should never happen. It is called when some higher
 906  * routine detects the CU has stopped, to try and restart
 907  * it from the last packet we knew we were working on,
 908  * or the idle loop if we had finished for the time.
 909  */
 910 
 911 static void eexp_hw_txrestart(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 912 {
 913         struct net_local *lp = (struct net_local *)dev->priv;
 914         unsigned short ioaddr = dev->base_addr;
 915   
 916         lp->last_tx_restart = lp->tx_link;
 917         outw(lp->tx_link,ioaddr+SCB_CBL);
 918         outw(SCB_CUstart,ioaddr+SCB_CMD);
 919         outw(0,ioaddr+SCB_STATUS);
 920         outb(0,ioaddr+SIGNAL_CA);
 921 
 922         {
 923                 unsigned short boguscount=50,failcount=5;
 924                 while (!inw(ioaddr+SCB_STATUS)) 
 925                 {
 926                         if (!--boguscount) 
 927                         {
 928                                 if (--failcount) 
 929                                 {
 930                                         printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n",
 931                                                 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
 932                                         outw(lp->tx_link,ioaddr+SCB_CBL);
 933                                         outw(0,ioaddr+SCB_STATUS);
 934                                         outw(SCB_CUstart,ioaddr+SCB_CMD);
 935                                         outb(0,ioaddr+SIGNAL_CA);
 936                                         boguscount = 100;
 937                                 }
 938                                 else
 939                                 {
 940                                         printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name);
 941                                         eexp_hw_init586(dev);
 942                                         dev->tbusy = 0;
 943                                         mark_bh(NET_BH);
 944                                         return;
 945                                 }
 946                         }
 947                 }
 948         }
 949 }
 950 
 951 /*
 952  * Writes down the list of transmit buffers into card
 953  * memory. Initial separate, repeated transmits link
 954  * them into a circular list, such that the CU can
 955  * be constantly active, and unlink them as we reap
 956  * transmitted packet buffers, so the CU doesn't loop
 957  * and endlessly transmit packets. (Try hacking the driver
 958  * to send continuous broadcast messages, say ARP requests
 959  * on a subnet with Windows boxes running on Novell and
 960  * LAN Workplace with EMM386. Amusing to watch them all die
 961  * horribly leaving the Linux boxes up!)
 962  */
 963 
 964 static void eexp_hw_txinit(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 965 {
 966         struct net_local *lp = (struct net_local *)dev->priv;
 967         unsigned short ioaddr = dev->base_addr;
 968         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 969         unsigned short tx_block = TX_BUF_START;
 970         unsigned short curtbuf;
 971 
 972         for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ ) 
 973         {
 974                 outw(tx_block,ioaddr+WRITE_PTR);
 975                 outw(0x0000,ioaddr);
 976                 outw(Cmd_INT|Cmd_Xmit,ioaddr);
 977                 outw(tx_block+0x08,ioaddr);
 978                 outw(tx_block+0x0e,ioaddr);
 979                 outw(0x0000,ioaddr);
 980                 outw(0x0000,ioaddr);
 981                 outw(tx_block+0x08,ioaddr);
 982                 outw(0x8000,ioaddr);
 983                 outw(-1,ioaddr);
 984                 outw(tx_block+0x16,ioaddr);
 985                 outw(0x0000,ioaddr);
 986                 tx_block += TX_BUF_SIZE;
 987         }
 988         lp->tx_head = TX_BUF_START;
 989         lp->tx_reap = TX_BUF_START;
 990         lp->tx_tail = tx_block - TX_BUF_SIZE;
 991         lp->tx_link = lp->tx_tail + 0x08;
 992         lp->rx_buf_start = tx_block;
 993         outw(old_wp,ioaddr+WRITE_PTR);
 994 }
 995 
 996 /* is this a standard test pattern, or dbecker randomness? */
 997 
 998 unsigned short rx_words[] = 
 999 {
1000         0xfeed,0xf00d,0xf001,0x0505,0x2424,0x6565,0xdeaf
1001 };
1002 
1003 /*
1004  * Write the circular list of receive buffer descriptors to
1005  * card memory. Note, we no longer mark the end of the list,
1006  * so if all the buffers fill up, the 82586 will loop until
1007  * we free one. This may sound dodgy, but it works, and
1008  * it makes the error detection in the interrupt handler
1009  * a lot simpler.
1010  */
1011 
1012 static void eexp_hw_rxinit(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1013 {
1014         struct net_local *lp = (struct net_local *)dev->priv;
1015         unsigned short ioaddr = dev->base_addr;
1016         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1017         unsigned short rx_block = lp->rx_buf_start;
1018 
1019         lp->num_rx_bufs = 0;
1020         lp->rx_first = rx_block;
1021         do 
1022         {
1023                 lp->num_rx_bufs++;
1024                 outw(rx_block,ioaddr+WRITE_PTR);
1025                 outw(0x0000,ioaddr);
1026                 outw(0x0000,ioaddr);
1027                 outw(rx_block+RX_BUF_SIZE,ioaddr);
1028                 outw(rx_block+0x16,ioaddr);
1029                 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1030                 outw(0x8000,ioaddr);
1031                 outw(-1,ioaddr);
1032                 outw(rx_block+0x20,ioaddr);
1033                 outw(0x0000,ioaddr);
1034                 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1035                 lp->rx_last = rx_block;
1036                 rx_block += RX_BUF_SIZE;
1037         } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1038 
1039         outw(lp->rx_last+4,ioaddr+WRITE_PTR);
1040         outw(lp->rx_first,ioaddr);
1041 
1042         outw(old_wp,ioaddr+WRITE_PTR);
1043 }
1044 
1045 /*
1046  * Reset the 586, fill memory (including calls to
1047  * eexp_hw_[(rx)(tx)]init()) unreset, and start
1048  * the configuration sequence. We don't wait for this
1049  * to finish, but allow the interrupt handler to start
1050  * the CU and RU for us. We can't start the receive/
1051  * transmission system up before we know that the
1052  * hardware is configured correctly
1053  */
1054 static void eexp_hw_init586(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1055 {
1056         struct net_local *lp = (struct net_local *)dev->priv;
1057         unsigned short ioaddr = dev->base_addr;
1058 
1059 #if NET_DEBUG > 6
1060         printk("%s: eexp_hw_init586()\n", dev->name);
1061 #endif
1062 
1063         PRIV(dev)->started = 0;
1064         set_loopback;
1065 
1066         outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1067         outb_p(i586_RST,ioaddr+EEPROM_Ctrl);
1068 
1069         outw_p(lp->rx_buf_end,ioaddr+WRITE_PTR);
1070         start_code[28] = (dev->flags & IFF_PROMISC)?(start_code[28] | 1):(start_code[28] & ~1);
1071         PRIV(dev)->promisc = dev->flags & IFF_PROMISC;
1072         /* We may die here */
1073         outsw(ioaddr, start_code, sizeof(start_code)>>1);
1074         outw(CONF_HW_ADDR,ioaddr+WRITE_PTR);
1075         outsw(ioaddr,dev->dev_addr,3);
1076         eexp_hw_txinit(dev);
1077         eexp_hw_rxinit(dev);
1078         outw(0,ioaddr+WRITE_PTR);
1079         outw(1,ioaddr);
1080         outb(0,ioaddr+EEPROM_Ctrl);
1081         outw(0,ioaddr+SCB_CMD);
1082         outb(0,ioaddr+SIGNAL_CA);
1083         {
1084                 unsigned short rboguscount=50,rfailcount=5;
1085                 while (outw(0,ioaddr+READ_PTR),inw(ioaddr)) 
1086                 {
1087                         if (!--rboguscount) 
1088                         {
1089                                 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n",
1090                                         dev->name);
1091                                 outw(0,ioaddr+SCB_CMD);
1092                                 outb(0,ioaddr+SIGNAL_CA);
1093                                 rboguscount = 100;
1094                                 if (!--rfailcount) 
1095                                 {
1096                                         printk(KERN_WARNING "%s: i82586 not responding, giving up.\n",
1097                                                 dev->name);
1098                                         return;
1099                                 }
1100                         }
1101                 }
1102         }
1103 
1104         outw(CONF_LINK,ioaddr+SCB_CBL);
1105         outw(0,ioaddr+SCB_STATUS);
1106         outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1107         outb(0,ioaddr+SIGNAL_CA);
1108         {
1109                 unsigned short iboguscount=50,ifailcount=5;
1110                 while (!inw(ioaddr+SCB_STATUS)) 
1111                 {
1112                         if (!--iboguscount) 
1113                         {
1114                                 if (--ifailcount) 
1115                                 {
1116                                         printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1117                                                 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
1118                                         outw(CONF_LINK,ioaddr+SCB_CBL);
1119                                         outw(0,ioaddr+SCB_STATUS);
1120                                         outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1121                                         outb(0,ioaddr+SIGNAL_CA);
1122                                         iboguscount = 100;
1123                                 }
1124                                 else 
1125                                 {
1126                                         printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name);
1127                                         return;
1128                                 }
1129                         }
1130                 }
1131         }
1132   
1133         outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1134         clear_loopback;
1135         lp->init_time = jiffies;
1136 #if NET_DEBUG > 6
1137         printk("%s: leaving eexp_hw_init586()\n", dev->name);
1138 #endif
1139         return;
1140 }
1141 
1142 /* 
1143  * completely reset the EtherExpress hardware. We will most likely get
1144  * an interrupt during this whether we want one or not. It is best,
1145  * therefore, to call this while we don't have a request_irq() on.
1146  */
1147 
1148 static void eexp_hw_ASICrst(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1149 {
1150         unsigned short ioaddr = dev->base_addr;
1151         unsigned short wrval = 0x0001,succount=0,boguscount=500;
1152 
1153         outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1154 
1155         PRIV(dev)->started = 0;
1156         outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1157         while (succount<20) 
1158         {
1159                 if (wrval == 0xffff) 
1160                         wrval = 0x0001;
1161                 outw(0,ioaddr+WRITE_PTR);
1162                 outw(wrval,ioaddr);
1163                 outw(0,ioaddr+READ_PTR);
1164                 if (wrval++ == inw(ioaddr)) 
1165                         succount++;
1166                 else 
1167                 {
1168                         succount = 0;
1169                         if (!boguscount--) 
1170                         {
1171                                 boguscount = 500;
1172                                 printk("%s: Having problems resetting EtherExpress ASIC, continuing...\n",
1173                                         dev->name);
1174                                 wrval = 0x0001;
1175                                 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1176                         }
1177                 }
1178         }
1179         outb(i586_RST,ioaddr+EEPROM_Ctrl);
1180 }
1181 
1182 
1183 /*
1184  * Set or clear the multicast filter for this adaptor.
1185  * We have to do a complete 586 restart for this to take effect.
1186  * At the moment only promiscuous mode is supported.
1187  */
1188 static void
1189 eexp_set_multicast(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1190 {
1191         if ((dev->flags & IFF_PROMISC) != PRIV(dev)->promisc)
1192                 eexp_hw_init586(dev);
1193 }
1194 
1195 
1196 /*
1197  * MODULE stuff
1198  */
1199 #ifdef MODULE
1200 
1201 #define EEXP_MAX_CARDS     4    /* max number of cards to support */
1202 #define NAMELEN            8    /* max length of dev->name (inc null) */
1203 
1204 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1205 
1206 static struct device dev_eexp[EEXP_MAX_CARDS] = 
1207 {
1208         NULL,         /* will allocate dynamically */
1209         0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe 
1210 };
1211 
1212 int irq[EEXP_MAX_CARDS] = {0, };
1213 int io[EEXP_MAX_CARDS] = {0, };
1214 
1215 /* Ideally the user would give us io=, irq= for every card.  If any parameters
1216  * are specified, we verify and then use them.  If no parameters are given, we
1217  * autoprobe for one card only.
1218  */
1219 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1220 {
1221         int this_dev, found = 0;
1222 
1223         for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1224                 struct device *dev = &dev_eexp[this_dev];
1225                 dev->name = namelist + (NAMELEN*this_dev);
1226                 dev->irq = irq[this_dev];
1227                 dev->base_addr = io[this_dev];
1228                 if (io[this_dev] == 0) {
1229                         if (this_dev) break;
1230                         printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1231                 }
1232                 if (register_netdev(dev) != 0) {
1233                         printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1234                         if (found != 0) return 0;
1235                         return -ENXIO;
1236                 }
1237                 found++;
1238         }
1239         return 0;
1240 }
1241 
1242 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1243 {
1244         int this_dev;
1245         
1246         for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1247                 struct device *dev = &dev_eexp[this_dev];
1248                 if (dev->priv != NULL) {
1249                         kfree(dev->priv);
1250                         dev->priv = NULL;
1251                         release_region(dev->base_addr, EEXP_IO_EXTENT);
1252                         unregister_netdev(dev);
1253                 }
1254         }
1255 }
1256 #endif
1257 
1258 /*
1259  * Local Variables:
1260  *  c-file-style: "linux"
1261  *  tab-width: 8
1262  *  compile-command: "gcc -D__KERNEL__ -I/discs/bibble/src/linux-1.3.69/include  -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strength-reduce -pipe -m486 -DCPU=486 -DMODULE  -c 3c505.c"
1263  * End:
1264  */

/* [previous][next][first][last][top][bottom][index][help] */