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_rxmap
  16. eexp_hw_init586
  17. eexp_hw_ASICrst
  18. init_module
  19. cleanup_module

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

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