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         dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 734         if (!dev->priv) 
 735                 return -ENOMEM;
 736 
 737         memset(dev->priv, 0, sizeof(struct net_local));
 738 
 739         eexp_hw_ASICrst(dev);
 740 
 741         {
 742                 unsigned short i586mso = 0x023e;
 743                 unsigned short old_wp,old_rp,old_a0,old_a1;
 744                 unsigned short a0_0,a1_0,a0_1,a1_1;
 745 
 746                 old_wp = inw(ioaddr+WRITE_PTR);
 747                 old_rp = inw(ioaddr+READ_PTR);
 748                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 749                 old_a1 = inw(ioaddr);
 750                 outw(i586mso,ioaddr+READ_PTR);
 751                 old_a0 = inw(ioaddr);
 752                 outw(i586mso,ioaddr+WRITE_PTR);
 753                 outw(0x55aa,ioaddr);
 754                 outw(i586mso,ioaddr+READ_PTR);
 755                 a0_0 = inw(ioaddr);
 756                 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
 757                 outw(0x5a5a,ioaddr);
 758                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 759                 a1_0 = inw(ioaddr);
 760                 outw(i586mso,ioaddr+READ_PTR);
 761                 a0_1 = inw(ioaddr);
 762                 outw(i586mso,ioaddr+WRITE_PTR);
 763                 outw(0x1234,ioaddr);
 764                 outw(0x8000+i586mso,ioaddr+READ_PTR);
 765                 a1_1 = inw(ioaddr);
 766 
 767                 if ((a0_0 != a0_1) || (a1_0 != a1_1) ||
 768                         (a1_0 != 0x5a5a) || (a0_0 != 0x55aa)) 
 769                 {
 770                         printk("32k\n");
 771                         PRIV(dev)->rx_buf_end = 0x7ff6;
 772                         PRIV(dev)->num_tx_bufs = 4;
 773                 }
 774                 else
 775                 {
 776                         printk("64k\n");
 777                         PRIV(dev)->num_tx_bufs = 8;
 778                         PRIV(dev)->rx_buf_start = TX_BUF_START + (PRIV(dev)->num_tx_bufs*TX_BUF_SIZE);
 779                         PRIV(dev)->rx_buf_end = 0xfff6;
 780                 }
 781 
 782                 outw(0x8000+i586mso,ioaddr+WRITE_PTR);
 783                 outw(old_a1,ioaddr);
 784                 outw(i586mso,ioaddr+WRITE_PTR);
 785                 outw(old_a0,ioaddr);
 786                 outw(old_wp,ioaddr+WRITE_PTR);
 787                 outw(old_rp,ioaddr+READ_PTR);
 788         }
 789   
 790         if (net_debug) 
 791                 printk(version);
 792         dev->open = eexp_open;
 793         dev->stop = eexp_close;
 794         dev->hard_start_xmit = eexp_xmit;
 795         dev->get_stats = eexp_stats;
 796         ether_setup(dev);
 797         return 0;
 798 }
 799 
 800 /*
 801  *      Read a word from eeprom location (0-63?)
 802  */
 803 static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, unsigned char location)
     /* [previous][next][first][last][top][bottom][index][help] */
 804 {
 805         unsigned short cmd = 0x180|(location&0x7f);
 806         unsigned short rval = 0,wval = EC_CS|i586_RST;
 807         int i;
 808  
 809         outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl);
 810         for ( i=0x100 ; i ; i>>=1 ) 
 811         {
 812                 if (cmd&i) 
 813                         wval |= EC_Wr;
 814                 else 
 815                         wval &= ~EC_Wr;
 816 
 817                 outb(wval,ioaddr+EEPROM_Ctrl);
 818                 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 819                 eeprom_delay();
 820                 outb(wval,ioaddr+EEPROM_Ctrl);
 821                 eeprom_delay();
 822         }       
 823         wval &= ~EC_Wr;
 824         outb(wval,ioaddr+EEPROM_Ctrl);
 825         for ( i=0x8000 ; i ; i>>=1 ) 
 826         {
 827                 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 828                 eeprom_delay();
 829                 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd) 
 830                         rval |= i;
 831                 outb(wval,ioaddr+EEPROM_Ctrl);
 832                 eeprom_delay();
 833         }
 834         wval &= ~EC_CS;
 835         outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl);
 836         eeprom_delay();
 837         outb(wval,ioaddr+EEPROM_Ctrl);
 838         eeprom_delay();
 839         return rval;
 840 }
 841 
 842 /*
 843  * Reap tx buffers and return last transmit status.
 844  * if ==0 then either:
 845  *    a) we're not transmitting anything, so why are we here?
 846  *    b) we've died.
 847  * otherwise, Stat_Busy(return) means we've still got some packets
 848  * to transmit, Stat_Done(return) means our buffers should be empty
 849  * again
 850  */
 851 
 852 static unsigned short eexp_hw_lasttxstat(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 853 {
 854         struct net_local *lp = (struct net_local *)dev->priv;
 855         unsigned short ioaddr = dev->base_addr;
 856         unsigned short old_rp = inw(ioaddr+READ_PTR);
 857         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 858         unsigned short tx_block = lp->tx_reap;
 859         unsigned short status;
 860   
 861         if (!test_bit(0,(void *)&dev->tbusy) && lp->tx_head==lp->tx_reap) 
 862                 return 0x0000;
 863 
 864         do
 865         {
 866                 outw(tx_block,ioaddr+READ_PTR);
 867                 status = inw(ioaddr);
 868                 if (!Stat_Done(status)) 
 869                 {
 870                         lp->tx_link = tx_block;
 871                         outw(old_rp,ioaddr+READ_PTR);
 872                         outw(old_wp,ioaddr+WRITE_PTR);
 873                         return status;
 874                 }
 875                 else 
 876                 {
 877                         lp->last_tx_restart = 0;
 878                         lp->stats.collisions += Stat_NoColl(status);
 879                         if (!Stat_OK(status)) 
 880                         {
 881                                 if (Stat_Abort(status)) 
 882                                         lp->stats.tx_aborted_errors++;
 883                                 if (Stat_TNoCar(status) || Stat_TNoCTS(status)) 
 884                                         lp->stats.tx_carrier_errors++;
 885                                 if (Stat_TNoDMA(status)) 
 886                                         lp->stats.tx_fifo_errors++;
 887                         }
 888                         else
 889                                 lp->stats.tx_packets++;
 890                 }
 891                 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE)) 
 892                         lp->tx_reap = tx_block = TX_BUF_START;
 893                 else
 894                         lp->tx_reap = tx_block += TX_BUF_SIZE;
 895                 dev->tbusy = 0;
 896                 mark_bh(NET_BH);
 897         }
 898         while (lp->tx_reap != lp->tx_head);
 899 
 900         lp->tx_link = lp->tx_tail + 0x08;
 901         outw(old_rp,ioaddr+READ_PTR);
 902         outw(old_wp,ioaddr+WRITE_PTR);
 903 
 904         return status;
 905 }
 906 
 907 /* 
 908  * This should never happen. It is called when some higher
 909  * routine detects the CU has stopped, to try and restart
 910  * it from the last packet we knew we were working on,
 911  * or the idle loop if we had finished for the time.
 912  */
 913 
 914 static void eexp_hw_txrestart(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 915 {
 916         struct net_local *lp = (struct net_local *)dev->priv;
 917         unsigned short ioaddr = dev->base_addr;
 918   
 919         lp->last_tx_restart = lp->tx_link;
 920         outw(lp->tx_link,ioaddr+SCB_CBL);
 921         outw(SCB_CUstart,ioaddr+SCB_CMD);
 922         outw(0,ioaddr+SCB_STATUS);
 923         outb(0,ioaddr+SIGNAL_CA);
 924 
 925         {
 926                 unsigned short boguscount=50,failcount=5;
 927                 while (!inw(ioaddr+SCB_STATUS)) 
 928                 {
 929                         if (!--boguscount) 
 930                         {
 931                                 if (--failcount) 
 932                                 {
 933                                         printk("%s: CU start timed out, status %04x, cmd %04x\n",
 934                                                 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
 935                                         outw(lp->tx_link,ioaddr+SCB_CBL);
 936                                         outw(0,ioaddr+SCB_STATUS);
 937                                         outw(SCB_CUstart,ioaddr+SCB_CMD);
 938                                         outb(0,ioaddr+SIGNAL_CA);
 939                                         boguscount = 100;
 940                                 }
 941                                 else
 942                                 {
 943                                         printk("%s: Failed to restart CU, resetting board...\n",dev->name);
 944                                         eexp_hw_init586(dev);
 945                                         dev->tbusy = 0;
 946                                         mark_bh(NET_BH);
 947                                         return;
 948                                 }
 949                         }
 950                 }
 951         }
 952 }
 953 
 954 /*
 955  * Writes down the list of transmit buffers into card
 956  * memory. Initial seperate, repeated transmits link
 957  * them into a circular list, such that the CU can
 958  * be constantly active, and unlink them as we reap
 959  * transmitted packet buffers, so the CU doesn't loop
 960  * and endlessly transmit packets. (Try hacking the driver
 961  * to send continuous broadcast messages, say ARP requests
 962  * on a subnet with Windows boxes running on Novell and
 963  * LAN Workplace with EMM386. Amusing to watch them all die
 964  * horribly leaving the Linux boxes up!)
 965  */
 966 
 967 static void eexp_hw_txinit(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 968 {
 969         struct net_local *lp = (struct net_local *)dev->priv;
 970         unsigned short ioaddr = dev->base_addr;
 971         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
 972         unsigned short tx_block = TX_BUF_START;
 973         unsigned short curtbuf;
 974 
 975         for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ ) 
 976         {
 977                 outw(tx_block,ioaddr+WRITE_PTR);
 978                 outw(0x0000,ioaddr);
 979                 outw(Cmd_INT|Cmd_Xmit,ioaddr);
 980                 outw(tx_block+0x08,ioaddr);
 981                 outw(tx_block+0x0e,ioaddr);
 982                 outw(0x0000,ioaddr);
 983                 outw(0x0000,ioaddr);
 984                 outw(tx_block+0x08,ioaddr);
 985                 outw(0x8000,ioaddr);
 986                 outw(-1,ioaddr);
 987                 outw(tx_block+0x16,ioaddr);
 988                 outw(0x0000,ioaddr);
 989                 tx_block += TX_BUF_SIZE;
 990         }
 991         lp->tx_head = TX_BUF_START;
 992         lp->tx_reap = TX_BUF_START;
 993         lp->tx_tail = tx_block - TX_BUF_SIZE;
 994         lp->tx_link = lp->tx_tail + 0x08;
 995         lp->rx_buf_start = tx_block;
 996         outw(old_wp,ioaddr+WRITE_PTR);
 997 }
 998 
 999 /* is this a standard test pattern, or dbecker randomness? */
1000 
1001 unsigned short rx_words[] = 
1002 {
1003         0xfeed,0xf00d,0xf001,0x0505,0x2424,0x6565,0xdeaf
1004 };
1005 
1006 /*
1007  * Write the circular list of receive buffer descriptors to
1008  * card memory. Note, we no longer mark the end of the list,
1009  * so if all the buffers fill up, the 82586 will loop until
1010  * we free one. This may sound dodgy, but it works, and
1011  * it makes the error detection in the interrupt handler
1012  * a lot simpler.
1013  */
1014 
1015 static void eexp_hw_rxinit(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1016 {
1017         struct net_local *lp = (struct net_local *)dev->priv;
1018         unsigned short ioaddr = dev->base_addr;
1019         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1020         unsigned short rx_block = lp->rx_buf_start;
1021 
1022         lp->num_rx_bufs = 0;
1023         lp->rx_first = rx_block;
1024         do 
1025         {
1026                 lp->num_rx_bufs++;
1027                 outw(rx_block,ioaddr+WRITE_PTR);
1028                 outw(0x0000,ioaddr);
1029                 outw(0x0000,ioaddr);
1030                 outw(rx_block+RX_BUF_SIZE,ioaddr);
1031                 outw(rx_block+0x16,ioaddr);
1032                 outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1033                 outw(0x8000,ioaddr);
1034                 outw(-1,ioaddr);
1035                 outw(rx_block+0x20,ioaddr);
1036                 outw(0x0000,ioaddr);
1037                 outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1038                 lp->rx_last = rx_block;
1039                 rx_block += RX_BUF_SIZE;
1040         } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE);
1041 
1042         outw(lp->rx_last+4,ioaddr+WRITE_PTR);
1043         outw(lp->rx_first,ioaddr);
1044 
1045         outw(old_wp,ioaddr+WRITE_PTR);
1046 }
1047 
1048 /*
1049  * This really ought not to be necessary now. Repairs a single
1050  * damaged receive buffer. If buffer memory is getting bashed
1051  * enough to call this, we probably have bigger problems that can
1052  * be fixed here.
1053  */
1054 static void eexp_hw_rxmap(struct device *dev, unsigned short rx_buf)
     /* [previous][next][first][last][top][bottom][index][help] */
1055 {
1056         struct net_local *lp = (struct net_local *)dev->priv;
1057         unsigned short ioaddr = dev->base_addr;
1058         unsigned short old_wp = inw(ioaddr+WRITE_PTR);
1059 
1060         outw(rx_buf,ioaddr+WRITE_PTR);
1061         outw(0x0000,ioaddr);
1062         outw(0x0000,ioaddr);
1063         outw((rx_buf==lp->rx_last)?lp->rx_first:(rx_buf+RX_BUF_SIZE),ioaddr);
1064         outw(rx_buf+0x16,ioaddr);
1065         outsw(ioaddr, rx_words, sizeof(rx_words)>>1);
1066         outw(0x8000,ioaddr);
1067         outw(-1,ioaddr);
1068         outw(rx_buf+0x20,ioaddr);
1069         outw(0x0000,ioaddr);
1070         outw(0x8000|(RX_BUF_SIZE-0x20),ioaddr);
1071         outw(old_wp,ioaddr+WRITE_PTR);
1072 }
1073 
1074 /*
1075  * Reset the 586, fill memory (including calls to
1076  * eexp_hw_[(rx)(tx)]init()) unreset, and start
1077  * the configuration sequence. We don't wait for this
1078  * to finish, but allow the interrupt handler to start
1079  * the CU and RU for us. We can't start the receive/
1080  * transmission system up before we know that the
1081  * hardware is configured correctly
1082  */
1083 static void eexp_hw_init586(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1084 {
1085         struct net_local *lp = (struct net_local *)dev->priv;
1086         unsigned short ioaddr = dev->base_addr;
1087 
1088         PRIV(dev)->started = 0;
1089         set_loopback;
1090 
1091         outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1092         outb(i586_RST,ioaddr+EEPROM_Ctrl);
1093 
1094         {
1095                 unsigned short wcnt;
1096                 wcnt = 0;
1097                 outw(0,ioaddr+WRITE_PTR);
1098                 while ((wcnt+=2) != lp->rx_buf_end+12) 
1099                         outw(0,ioaddr);
1100         } 
1101   
1102         outw(lp->rx_buf_end,ioaddr+WRITE_PTR);
1103         outsw(ioaddr, start_code, sizeof(start_code)>>1);
1104         outw(CONF_HW_ADDR,ioaddr+WRITE_PTR);
1105         outsw(ioaddr,dev->dev_addr,3);
1106         eexp_hw_txinit(dev);
1107         eexp_hw_rxinit(dev);
1108         outw(0,ioaddr+WRITE_PTR);
1109         outw(1,ioaddr);
1110         outb(0,ioaddr+EEPROM_Ctrl);
1111         outw(0,ioaddr+SCB_CMD);
1112         outb(0,ioaddr+SIGNAL_CA);
1113         {
1114                 unsigned short rboguscount=50,rfailcount=5;
1115                 while (outw(0,ioaddr+READ_PTR),inw(ioaddr)) 
1116                 {
1117                         if (!--rboguscount) 
1118                         {
1119                                 printk("%s: i82586 reset timed out, kicking...\n",
1120                                         dev->name);
1121                                 outw(0,ioaddr+SCB_CMD);
1122                                 outb(0,ioaddr+SIGNAL_CA);
1123                                 rboguscount = 100;
1124                                 if (!--rfailcount) 
1125                                 {
1126                                         printk("%s: i82586 not responding, giving up.\n",
1127                                                 dev->name);
1128                                         return;
1129                                 }
1130                         }
1131                 }
1132         }
1133 
1134         outw(CONF_LINK,ioaddr+SCB_CBL);
1135         outw(0,ioaddr+SCB_STATUS);
1136         outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1137         outb(0,ioaddr+SIGNAL_CA);
1138         {
1139                 unsigned short iboguscount=50,ifailcount=5;
1140                 while (!inw(ioaddr+SCB_STATUS)) 
1141                 {
1142                         if (!--iboguscount) 
1143                         {
1144                                 if (--ifailcount) 
1145                                 {
1146                                         printk("%s: i82586 initialization timed out, status %04x, cmd %04x\n",
1147                                                 dev->name, inw(ioaddr+SCB_STATUS), inw(ioaddr+SCB_CMD));
1148                                         outw(CONF_LINK,ioaddr+SCB_CBL);
1149                                         outw(0,ioaddr+SCB_STATUS);
1150                                         outw(0xf000|SCB_CUstart,ioaddr+SCB_CMD);
1151                                         outb(0,ioaddr+SIGNAL_CA);
1152                                         iboguscount = 100;
1153                                 }
1154                                 else 
1155                                 {
1156                                         printk("%s: Failed to initialize i82586, giving up.\n",dev->name);
1157                                         return;
1158                                 }
1159                         }
1160                 }
1161         }
1162   
1163         outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ);
1164         clear_loopback;
1165         lp->init_time = jiffies;
1166         if (PRIV(dev)->started) 
1167                 printk("%s: Uh? We haven't started yet\n",dev->name);
1168         return;
1169 }
1170 
1171 /* 
1172  * completely reset the EtherExpress hardware. We will most likely get
1173  * an interrupt during this whether we want one or not. It is best,
1174  * therefore, to call this while we don't have a request_irq() on.
1175  */
1176 
1177 static void eexp_hw_ASICrst(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1178 {
1179         unsigned short ioaddr = dev->base_addr;
1180         unsigned short wrval = 0x0001,succount=0,boguscount=500;
1181 
1182         outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ);
1183 
1184         set_loopback;  /* yet more paranoia - since we're resetting the ASIC
1185                         * that controls this function, how can it possibly work?
1186                         */
1187         PRIV(dev)->started = 0;
1188         outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1189         while (succount<20) 
1190         {
1191                 if (wrval == 0xffff) 
1192                         wrval = 0x0001;
1193                 outw(0,ioaddr+WRITE_PTR);
1194                 outw(wrval,ioaddr);
1195                 outw(0,ioaddr+READ_PTR);
1196                 if (wrval++ == inw(ioaddr)) 
1197                         succount++;
1198                 else 
1199                 {
1200                         succount = 0;
1201                         if (!boguscount--) 
1202                         {
1203                                 boguscount = 500;
1204                                 printk("%s: Having problems resetting EtherExpress ASIC, continuing...\n",
1205                                         dev->name);
1206                                 wrval = 0x0001;
1207                                 outb(ASIC_RST|i586_RST,ioaddr+EEPROM_Ctrl);
1208                         }
1209                 }
1210         }
1211         outb(i586_RST,ioaddr+EEPROM_Ctrl);
1212 }
1213 
1214 /*
1215  * MODULE stuff
1216  */
1217 #ifdef MODULE
1218 
1219 #define EEXP_MAX_CARDS     4    /* max number of cards to support */
1220 #define NAMELEN            8    /* max length of dev->name (inc null) */
1221 
1222 static char namelist[NAMELEN * EEXP_MAX_CARDS] = { 0, };
1223 
1224 static struct device dev_eexp[EEXP_MAX_CARDS] = 
1225 {
1226         NULL,         /* will allocate dynamically */
1227         0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, express_probe 
1228 };
1229 
1230 int irq[EEXP_MAX_CARDS] = {0, };
1231 int io[EEXP_MAX_CARDS] = {0, };
1232 
1233 /* Ideally the user would give us io=, irq= for every card.  If any parameters
1234  * are specified, we verify and then use them.  If no parameters are given, we
1235  * autoprobe for one card only.
1236  */
1237 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1238 {
1239         int this_dev, found = 0;
1240 
1241         for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1242                 struct device *dev = &dev_eexp[this_dev];
1243                 dev->name = namelist + (NAMELEN*this_dev);
1244                 dev->irq = irq[this_dev];
1245                 dev->base_addr = io[this_dev];
1246                 if (io[this_dev] == 0) {
1247                         if (this_dev) break;
1248                         printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1249                 }
1250                 if (register_netdev(dev) != 0) {
1251                         printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]);
1252                         if (found != 0) return 0;
1253                         return -ENXIO;
1254                 }
1255                 found++;
1256         }
1257         return 0;
1258 }
1259 
1260 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1261 {
1262         int this_dev;
1263         
1264         for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1265                 struct device *dev = &dev_eexp[this_dev];
1266                 if (dev->priv != NULL) {
1267                         kfree(dev->priv);
1268                         dev->priv = NULL;
1269                         release_region(dev->base_addr, EEXP_IO_EXTENT);
1270                         unregister_netdev(dev);
1271                 }
1272         }
1273 }
1274 #endif

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