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

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