root/drivers/net/3c505.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_status
  2. set_hsf
  3. wait_hcre
  4. send_pcb
  5. receive_pcb
  6. adapter_hard_reset
  7. adapter_reset
  8. start_receive
  9. receive_packet
  10. elp_interrupt
  11. elp_open
  12. send_packet
  13. elp_start_xmit
  14. elp_get_stats
  15. elp_close
  16. elp_set_mc_list
  17. elp_init
  18. elp_sense
  19. elp_autodetect
  20. elplus_probe

   1 /*
   2  * Linux ethernet device driver for the 3Com Etherlink Plus (3C505)
   3  *      By Craig Southeren
   4  *
   5  * elplus.c     This module implements an interface to the 3Com
   6  *              Etherlink Plus (3c505) ethernet card. Linux device 
   7  *              driver interface reverse engineered from the Linux 3C509
   8  *              device drivers. Vital 3C505 information gleaned from
   9  *              the Crynwr packet driver
  10  *
  11  * Version:     @(#)elplus.c    0.5     11-Jun-94
  12  *
  13  * Authors:     Linux 3c505 device driver by:
  14  *                      Craig Southeren, <geoffw@extro.ucc.su.oz.au>
  15  *              Final debugging by:
  16  *                      Andrew Tridgell, <tridge@nimbus.anu.edu.au>
  17  *              Auto irq, auto detect, cleanup and v1.1.4+ kernel mods by:
  18  *                      Juha Laiho, <jlaiho@ichaos.nullnet.fi>
  19  *              Linux 3C509 driver by:
  20  *                      Donald Becker, <becker@super.org>
  21  *              Crynwr packet driver by
  22  *                      Krishnan Gopalan and Gregg Stefancik,
  23  *                         Clemson University Engineering Computer Operations.
  24  *                      Portions of the code have been adapted from the 3c505
  25  *                         driver for NCSA Telnet by Bruce Orchard and later
  26  *                         modified by Warren Van Houten and krus@diku.dk.
  27  *              3C505 technical information provided by
  28  *                      Terry Murphy, of 3Com Network Adapter Division
  29  *                     
  30  */
  31 
  32 
  33 /*********************************************************
  34  *
  35  *  set ELP_KERNEL_TYPE to the following values depending upon
  36  *  the kernel type:
  37  *       0   = 0.99pl14 or earlier
  38  *       1   = 0.99pl15 through 1.1.3
  39  *       2   = 1.1.4 through 1.1.11
  40  *       3   = 1.1.12 through 1.1.19
  41  *       4   = 1.1.20
  42  *
  43  *********************************************************/
  44 
  45 #define ELP_KERNEL_TYPE 4
  46 
  47 /*********************************************************
  48  *
  49  *  set ELP_NEED_HARD_RESET to 1, if having problems with
  50  *  "warm resets" from DOS. Bootup will then take some more
  51  *  time, as the adapter will perform self-test upon hard
  52  *  reset. This misbehaviour is reported to happen at least
  53  *  after use of Windows real-mode NDIS drivers.
  54  *
  55  *********************************************************/
  56 
  57 #define ELP_NEED_HARD_RESET 0
  58 
  59 #include <linux/config.h>
  60 #include <linux/kernel.h>
  61 #include <linux/sched.h>
  62 #include <linux/string.h>
  63 #include <linux/interrupt.h>
  64 #include <linux/ptrace.h>
  65 #include <linux/errno.h>
  66 #include <linux/in.h>
  67 #include <linux/malloc.h>
  68 #include <linux/ioport.h>
  69 #include <asm/bitops.h>
  70 #include <asm/io.h>
  71 
  72 #if (ELP_KERNEL_TYPE < 2)
  73 #include "dev.h"
  74 #include "eth.h"
  75 #include "skbuff.h"
  76 #include "arp.h"
  77 #else
  78 #include <linux/netdevice.h>
  79 #include <linux/etherdevice.h>
  80 #include <linux/skbuff.h>
  81 #endif
  82 
  83 #ifndef port_read
  84 #include "iow.h"
  85 #endif
  86 
  87 #include "3c505.h"
  88 
  89 #define ELPLUS_DEBUG 0
  90 
  91 /*********************************************************
  92  *
  93  *  define debug messages here as common strings to reduce space
  94  *
  95  *********************************************************/
  96 
  97 static char * filename = __FILE__;
  98 
  99 static char * null_msg = "*** NULL at %s(%d) ***\n";
 100 #define CHECK_NULL(p) if (!p) printk(null_msg, filename, __LINE__)
 101 
 102 static char * timeout_msg = "*** timeout at %s(%d) ***\n";
 103 #define TIMEOUT_MSG()     printk(timeout_msg, filename,__LINE__)
 104 
 105 static char * invalid_pcb_msg = "*** invalid pcb length %d at %s(%d) ***\n";
 106 
 107 static char * search_msg = "%s: Looking for 3c505 adapter at address 0x%x...";
 108 
 109 static char * stilllooking_msg = "still looking...";
 110 
 111 static char * found_msg = "found.\n";
 112 
 113 static char * notfound_msg = "not found (reason = %d)\n";
 114 
 115 static char * couldnot_msg = "%s: 3c505 not found\n";
 116 
 117 /*********************************************************
 118  *
 119  *  various other debug stuff
 120  *
 121  *********************************************************/
 122 
 123 #ifdef ELPLUS_DEBUG
 124 static int elp_debug = ELPLUS_DEBUG;
 125 #else
 126 static int elp_debug = 0;
 127 #endif
 128 
 129 #if (ELP_KERNEL_TYPE < 2)
 130 extern void     skb_check(struct sk_buff *skb,int, char *);
 131 #ifndef IS_SKB
 132 #define IS_SKB(skb)     skb_check((skb),__LINE__,filename)
 133 #endif
 134 #else
 135 #ifndef IS_SKB
 136 #define IS_SKB(skb)     skb_check((skb),0,__LINE__,filename)
 137 #endif
 138 #endif
 139 
 140 
 141 /*
 142  *  0 = no messages
 143  *  1 = messages when high level commands performed
 144  *  2 = messages when low level commands performed
 145  *  3 = messages when interrupts received
 146  */
 147 
 148 #define ELPLUS_VERSION  "0.4.0"
 149 
 150 /*****************************************************************
 151  *
 152  * useful macros
 153  *
 154  *****************************************************************/
 155 
 156 /*
 157  *  kernels before pl15 used an unobvious method for accessing
 158  *  the skb data area
 159  */
 160 #if (ELP_KERNEL_TYPE < 1)
 161 #define SKB_DATA        (skb+1)
 162 #else
 163 #define SKB_DATA        (skb->data) 
 164 #endif
 165 
 166 /*
 167  *  not all kernels before 1.1.4 had an alloc_skb function (apparently!!)
 168  */
 169 #if (ELP_KERNEL_TYPE < 2)
 170 #ifndef HAVE_ALLOC_SKB
 171 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
 172 #endif
 173 #endif
 174 
 175 #define INB(port)       inb((unsigned short)(port)) 
 176 #define OUTB(val,port)  outb((unsigned char)(val),(unsigned short)(port));
 177 
 178 #ifndef TRUE
 179 #define TRUE    1
 180 #endif
 181 
 182 #ifndef FALSE
 183 #define FALSE   0
 184 #endif
 185 
 186 
 187 /*****************************************************************
 188  *
 189  * List of I/O-addresses we try to auto-sense
 190  * Last element MUST BE 0!
 191  *****************************************************************/
 192 
 193 const int addr_list[]={0x300,0x280,0x310,0}; 
 194 
 195 /*****************************************************************
 196  *
 197  * PCB structure
 198  *
 199  *****************************************************************/
 200 
 201 #include "3c505dta.h"
 202 
 203 /*****************************************************************
 204  *
 205  *  structure to hold context information for adapter
 206  *
 207  *****************************************************************/
 208 
 209 typedef struct {
 210   int        io_addr;        /* base I/O address */
 211   char *     name;           /* used for debug output */
 212   short      got[NUM_TRANSMIT_CMDS];  /* flags for command completion */
 213   pcb_struct tx_pcb;         /* PCB for foreground sending */
 214   pcb_struct rx_pcb;         /* PCB for foreground receiving */
 215   pcb_struct itx_pcb;        /* PCB for background sending */
 216   pcb_struct irx_pcb;        /* PCB for background receiving */
 217   struct enet_statistics stats;
 218 } elp_device;
 219 
 220 /*****************************************************************
 221  *
 222  *  useful functions for accessing the adapter
 223  *
 224  *****************************************************************/
 225 
 226 /*
 227  * use this routine when accessing the ASF bits as they are
 228  * changed asynchronously by the adapter
 229  */
 230 
 231 /* get adapter PCB status */
 232 #define GET_ASF()       (get_status(adapter)&ASF_PCB_MASK)
 233 #define GET_STATUS()    (get_status(adapter))
 234 
 235 static int get_status (elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 236 
 237 {
 238   int timeout = jiffies + TIMEOUT;  
 239   register int stat1;
 240   do {
 241     stat1 = INB(adapter->io_addr+PORT_STATUS);
 242   } while (stat1 != INB(adapter->io_addr+PORT_STATUS) && jiffies < timeout);
 243   if (jiffies >= timeout)
 244     TIMEOUT_MSG();
 245   return stat1;
 246 }
 247 
 248 #define SET_HSF(hsf)    (set_hsf(adapter,hsf))
 249 
 250 static void set_hsf (elp_device * adapter, int hsf)
     /* [previous][next][first][last][top][bottom][index][help] */
 251 
 252 {
 253   cli();
 254   OUTB((INB(adapter->io_addr+PORT_CONTROL)&(~HSF_PCB_MASK))|hsf, adapter->io_addr+PORT_CONTROL); 
 255   sti(); 
 256 }
 257 
 258 #define WAIT_HCRE(toval)        (wait_hcre(adapter,toval))
 259 
 260 static int wait_hcre(elp_device * adapter, int toval)
     /* [previous][next][first][last][top][bottom][index][help] */
 261 
 262 {
 263   int timeout = jiffies + toval;
 264   while(((INB(adapter->io_addr+PORT_STATUS)&STATUS_HCRE)==0) &&
 265          (jiffies <= timeout))
 266     ;
 267   if (jiffies >= timeout) {
 268     TIMEOUT_MSG();
 269     return FALSE;
 270   }
 271   return TRUE;
 272 }
 273 
 274 /*****************************************************************
 275  *
 276  * send_pcb
 277  *   Send a PCB to the adapter. 
 278  *
 279  *      output byte to command reg  --<--+
 280  *      wait until HCRE is non zero      |
 281  *      loop until all bytes sent   -->--+
 282  *      set HSF1 and HSF2 to 1
 283  *      output pcb length
 284  *      wait until ASF give ACK or NAK
 285  *      set HSF1 and HSF2 to 0
 286  *
 287  *****************************************************************/
 288 
 289 static int send_pcb(elp_device * adapter, pcb_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 290 
 291 {
 292   int i;
 293   int cont;
 294   int retry = 0;
 295   int timeout;
 296 
 297   CHECK_NULL(pcb);
 298   CHECK_NULL(adapter);
 299 
 300   if (pcb->length > MAX_PCB_DATA)
 301     printk(invalid_pcb_msg, pcb->length, filename, __LINE__);
 302 
 303   while (1) {
 304 
 305     cont = 1;
 306 
 307     /*
 308      * load each byte into the command register and
 309      * wait for the HCRE bit to indicate the adapter
 310      * had read the byte
 311      */
 312     SET_HSF(0); 
 313     OUTB(pcb->command, (adapter->io_addr)+PORT_COMMAND);
 314     cont = WAIT_HCRE(5);
 315 
 316     if (cont) {
 317       OUTB(pcb->length, (adapter->io_addr)+PORT_COMMAND);
 318       cont = WAIT_HCRE(2);
 319     }
 320 
 321     for (i = 0; cont && (i < pcb->length); i++) {
 322       OUTB(pcb->data.raw[i], (adapter->io_addr)+PORT_COMMAND);
 323       cont = WAIT_HCRE(2);
 324     }
 325 
 326     /* set the host status bits to indicate end of PCB */
 327     /* send the total packet length as well */
 328     /* wait for the adapter to indicate that it has read the PCB */
 329     if (cont) {
 330       SET_HSF(HSF_PCB_END);
 331       OUTB(2+pcb->length, adapter->io_addr+PORT_COMMAND);
 332       timeout = jiffies + 6;
 333       while (jiffies < timeout) {
 334         i = GET_ASF();
 335         if ((i == ASF_PCB_ACK) ||
 336             (i == ASF_PCB_NAK))
 337           break;
 338       }
 339 
 340       if (jiffies >= timeout)
 341         TIMEOUT_MSG();
 342 
 343       if (i == ASF_PCB_ACK) {
 344         SET_HSF(0); 
 345         return TRUE;
 346       } else if (i == ASF_PCB_NAK) {
 347         SET_HSF(0);
 348         printk("%s: PCB send was NAKed\n", adapter->name);
 349         {
 350           int to = jiffies + 5;
 351           while (jiffies < to)
 352             ;
 353         }
 354       }
 355     }
 356 
 357     if (elp_debug >= 2)
 358       printk("%s: NAK/timeout on send PCB\n", adapter->name);
 359     if ((retry++ & 7) == 0) 
 360       printk("%s: retry #%i on send PCB\n", adapter->name, retry);
 361   }
 362 
 363   return FALSE;
 364 }
 365 
 366 /*****************************************************************
 367  *
 368  * receive_pcb
 369  *   Read a PCB to the adapter
 370  *
 371  *      wait for ACRF to be non-zero         ---<---+
 372  *      input a byte                                |
 373  *      if ASF1 and ASF2 were not both one          |
 374  *           before byte was read, loop      --->---+
 375  *      set HSF1 and HSF2 for ack
 376  *
 377  *****************************************************************/
 378 
 379 static int receive_pcb(elp_device * adapter, pcb_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 380 
 381 {
 382   int i;
 383   int total_length;
 384   int stat;
 385   int timeout;
 386 
 387   CHECK_NULL(pcb);
 388   CHECK_NULL(adapter);
 389 
 390   /* get the command code */
 391   timeout = jiffies + TIMEOUT;
 392   while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
 393     ;
 394   if (jiffies >= timeout)
 395     TIMEOUT_MSG();
 396 
 397   SET_HSF(0); 
 398   pcb->command = INB(adapter->io_addr+PORT_COMMAND);
 399   if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {
 400 
 401     /* read the data length */
 402     timeout = jiffies + TIMEOUT;
 403     while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
 404       ;
 405     if (jiffies >= timeout)
 406       TIMEOUT_MSG();
 407     pcb->length = INB(adapter->io_addr+PORT_COMMAND);
 408 
 409     if (pcb->length > MAX_PCB_DATA)
 410       printk(invalid_pcb_msg, pcb->length, filename,__LINE__);
 411 
 412     if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {
 413 
 414       /* read the data */
 415       i = 0;
 416       timeout = jiffies + TIMEOUT;
 417       do {
 418         while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
 419           ;
 420         pcb->data.raw[i++] = INB(adapter->io_addr+PORT_COMMAND);
 421         if (i > MAX_PCB_DATA)
 422           printk(invalid_pcb_msg, i, filename, __LINE__);
 423       } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && jiffies < timeout);
 424 
 425       if (jiffies >= timeout)
 426         TIMEOUT_MSG();
 427       
 428       /* woops, the last "data" byte was really the length! */
 429       total_length = pcb->data.raw[--i];
 430 
 431       /* safety check total length vs data length */
 432       if (total_length != (pcb->length + 2)) {
 433         if (elp_debug >= 2)
 434           printk("%s: mangled PCB received\n", adapter->name);
 435         SET_HSF(HSF_PCB_NAK);
 436         return FALSE;
 437       }
 438 
 439       SET_HSF(HSF_PCB_ACK);
 440       return TRUE;
 441     }
 442   }
 443 
 444   SET_HSF(HSF_PCB_NAK); 
 445   return FALSE;
 446 }
 447 
 448 #if ELP_NEED_HARD_RESET
 449 
 450 static void adapter_hard_reset(elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 451 
 452 {
 453   int timeout;
 454 
 455   CHECK_NULL(adapter);
 456 
 457   /*
 458    * take FLSH and ATTN high
 459    */
 460   OUTB(CONTROL_ATTN|CONTROL_FLSH, adapter->io_addr+PORT_CONTROL); 
 461 
 462   /*
 463    * wait for a little bit
 464    */
 465   for (timeout = jiffies + 20; jiffies <= timeout; )
 466     ;
 467   
 468   /*
 469    * now take them low
 470    */
 471   OUTB(0, adapter->io_addr+PORT_CONTROL); 
 472 
 473   /*
 474    * wait for a little bit
 475    */
 476   for (timeout = jiffies + 20; jiffies <= timeout; )
 477     ;
 478   
 479   /*
 480    * now hang around until the board gets it's act together
 481    */
 482   for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
 483     if (GET_ASF() != ASF_PCB_END)
 484       break;
 485 }
 486 
 487 #endif /* ELP_NEED_HARD_RESET */
 488 
 489 static void adapter_reset(elp_device * adapter)
     /* [previous][next][first][last][top][bottom][index][help] */
 490 {
 491   int timeout;
 492 
 493   CHECK_NULL(adapter);
 494 
 495   cli();
 496   OUTB(CONTROL_ATTN|INB(adapter->io_addr+PORT_CONTROL), adapter->io_addr+PORT_CONTROL);
 497   sti();
 498 
 499   /*
 500    * wait for a little bit
 501    */
 502   for (timeout = jiffies + 20; jiffies <= timeout; )
 503     ;
 504 
 505   cli();
 506   OUTB(INB(adapter->io_addr+PORT_CONTROL)&~(CONTROL_ATTN), adapter->io_addr+PORT_CONTROL);
 507   sti();
 508 
 509 }
 510 
 511 /******************************************************
 512  *
 513  *  queue a receive command on the adapter so we will get an
 514  *  interrupt when a packet is received.
 515  *
 516  ******************************************************/
 517 
 518 static int start_receive(elp_device * adapter, pcb_struct * tx_pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 519 
 520 {
 521   CHECK_NULL(adapter);
 522   CHECK_NULL(tx_pcb);
 523 
 524   if (elp_debug >= 3)
 525     printk("%s: restarting receiver\n", adapter->name);
 526   tx_pcb->command = CMD_RECEIVE_PACKET;
 527   tx_pcb->length = sizeof(struct Rcv_pkt);
 528   tx_pcb->data.rcv_pkt.buf_seg = tx_pcb->data.rcv_pkt.buf_ofs = 0; /* Unused */
 529   tx_pcb->data.rcv_pkt.buf_len = 1600;
 530   tx_pcb->data.rcv_pkt.timeout = 0;     /* set timeout to zero */
 531   return send_pcb(adapter, tx_pcb); 
 532 }
 533 
 534 /******************************************************
 535  *
 536  * extract a packet from the adapter
 537  * this routine is only called from within the interrupt
 538  * service routine, so no cli/sti calls are needed
 539  * note that the length is always assumed to be even
 540  *
 541  ******************************************************/
 542 
 543 static void receive_packet(struct device * dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 544                               elp_device * adapter,
 545                                        int len)
 546 
 547 {
 548   register int i;
 549   unsigned short * ptr;
 550   short d;
 551   int timeout;
 552   int rlen;
 553   struct sk_buff *skb;
 554 
 555   /*
 556    * allocate a buffer to put the packet into.
 557    * (for kernels prior to 1.1.4 only)
 558    */
 559 #if (ELP_KERNEL_TYPE < 2)
 560   int sksize = sizeof(struct sk_buff) + len + 4;
 561 #endif
 562 
 563   CHECK_NULL(dev);
 564   CHECK_NULL(adapter);
 565 
 566   if (len <= 0 || ((len & ~1) != len))
 567     if (elp_debug >= 3)
 568       printk("*** bad packet len %d at %s(%d)\n",len,filename,__LINE__);
 569 
 570   rlen = (len+1) & ~1;
 571 
 572 #if (ELP_KERNEL_TYPE < 2)
 573   skb = alloc_skb(sksize, GFP_ATOMIC);
 574 #else
 575   skb = alloc_skb(rlen, GFP_ATOMIC);
 576 #endif
 577 
 578   /*
 579    * make sure the data register is going the right way
 580    */
 581   OUTB(INB(adapter->io_addr+PORT_CONTROL)|CONTROL_DIR, adapter->io_addr+PORT_CONTROL); 
 582 
 583   /*
 584    * if buffer could not be allocated, swallow it
 585    */
 586   if (skb == NULL) {
 587     for (i = 0; i < (rlen/2); i++) {
 588       timeout = jiffies + TIMEOUT;
 589       while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0 && 
 590              jiffies < timeout)
 591         ;
 592       if (jiffies >= timeout)
 593         TIMEOUT_MSG();
 594 
 595       d = inw(adapter->io_addr+PORT_DATA);
 596     }
 597     adapter->stats.rx_dropped++;
 598 
 599   } else {
 600     skb->lock     = 0;
 601     skb->len = rlen;
 602     skb->dev = dev;
 603 
 604 /*
 605  * for kernels before 1.1.4, the driver allocated the buffer
 606  */
 607 #if (ELP_KERNEL_TYPE < 2)
 608     skb->mem_len = sksize;
 609     skb->mem_addr = skb;
 610 #endif
 611 
 612     /*
 613      * now read the data from the adapter
 614      */
 615     ptr = (unsigned short *)SKB_DATA;
 616     for (i = 0; i < (rlen/2); i++) { 
 617       timeout = jiffies + TIMEOUT;
 618       while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0 && 
 619              jiffies < timeout) 
 620         ;
 621       if (jiffies >= timeout)
 622         {
 623           printk("*** timeout at %s(%d) reading word %d of %d ***\n",
 624                         filename,__LINE__, i, rlen/2);  
 625 #if (ELP_KERNEL_TYPE < 2)
 626           kfree_s(skb, sksize);
 627 #else
 628           kfree_s(skb, rlen);
 629 #endif
 630           return;
 631         }
 632 
 633       *ptr = inw(adapter->io_addr+PORT_DATA); 
 634       ptr++; 
 635     }
 636 
 637     /*
 638      * the magic routine "dev_rint" passes the packet up the
 639      * protocol chain. If it returns 0, we can assume the packet was
 640      * swallowed up. If not, then we are responsible for freeing memory
 641      */
 642 
 643     IS_SKB(skb);
 644 
 645 /*
 646  * for kernels before 1.1.4, the driver allocated the buffer, so it had
 647  * to free it
 648  */
 649 #if (ELP_KERNEL_TYPE < 2)
 650     if (dev_rint((unsigned char *)skb, rlen, IN_SKBUFF, dev) != 0) {
 651       printk("%s: receive buffers full.\n", dev->name);
 652       kfree_s(skb, sksize);
 653     }
 654 #else
 655     netif_rx(skb);
 656 #endif
 657   }
 658 
 659   OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL); 
 660 }
 661 
 662 
 663 /******************************************************
 664  *
 665  * interrupt handler
 666  *
 667  ******************************************************/
 668 
 669 static void elp_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 670 
 671 {
 672   int len;
 673   int dlen;
 674   int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 675   struct device *dev;
 676   elp_device * adapter;
 677   int timeout;
 678 
 679   if (irq < 0 || irq > 15) {
 680     printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
 681     return;
 682   }
 683 
 684 /* FIXME: How do I do this kind of check without a fixed IRQ? */
 685 #if 0
 686   if (irq != ELP_IRQ) {
 687     printk ("elp_interrupt(): - interrupt routine has incorrect IRQ of %i\n", irq);
 688     return;
 689   }
 690 #endif
 691 
 692   dev = irq2dev_map[irq];
 693 
 694   if (dev == NULL) {
 695     printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
 696     return;
 697   }
 698 
 699   adapter = (elp_device *) dev->priv;
 700 
 701   CHECK_NULL(adapter);
 702 
 703   if (dev->interrupt)
 704     if (elp_debug >= 2)
 705       printk("%s: Re-entering the interrupt handler.\n", dev->name);
 706   dev->interrupt = 1;
 707 
 708   /*
 709    * allow interrupts (we need timers!)
 710    */
 711   sti();
 712 
 713   /*
 714    * receive a PCB from the adapter
 715    */
 716   timeout = jiffies + TIMEOUT;
 717   while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0 &&
 718          jiffies < timeout) {
 719     
 720     if (receive_pcb(adapter, &adapter->irx_pcb)) {
 721 
 722       switch (adapter->irx_pcb.command) {
 723 
 724         /*
 725          * 82586 configured correctly
 726          */
 727         case CMD_CONFIGURE_82586_RESPONSE:
 728           adapter->got[CMD_CONFIGURE_82586] = 1;
 729           if (elp_debug >= 3)
 730             printk("%s: interrupt - configure response received\n", dev->name);
 731           break;
 732 
 733         /*
 734          * Adapter memory configuration
 735          */
 736         case CMD_CONFIGURE_ADAPTER_RESPONSE:
 737           adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
 738           if (elp_debug >= 3)
 739             printk("%s: Adapter memory configuration %s.",dev->name,
 740                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 741           break;
 742         
 743         /*
 744          * Multicast list loading
 745          */
 746         case CMD_LOAD_MULTICAST_RESPONSE:
 747           adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
 748           if (elp_debug >= 3)
 749             printk("%s: Multicast address list loading %s.",dev->name,
 750                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 751           break;
 752 
 753         /*
 754          * Station address setting
 755          */
 756         case CMD_SET_ADDRESS_RESPONSE:
 757           adapter->got[CMD_SET_STATION_ADDRESS] = 1;
 758           if (elp_debug >= 3)
 759             printk("%s: Ethernet address setting %s.",dev->name,
 760                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 761           break;
 762 
 763 
 764         /*
 765          * received board statistics
 766          */
 767         case CMD_NETWORK_STATISTICS_RESPONSE:
 768           adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
 769           adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
 770           adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
 771           adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
 772           adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
 773           adapter->got[CMD_NETWORK_STATISTICS] = 1;
 774           if (elp_debug >= 3)
 775             printk("%s: interrupt - statistics response received\n", dev->name);
 776           break;
 777 
 778         /*
 779          * received a packet
 780          */
 781         case CMD_RECEIVE_PACKET_COMPLETE:
 782           /* if the device isn't open, don't pass packets up the stack */
 783           if (dev->start == 0)
 784             break;
 785           len = adapter->irx_pcb.data.rcv_resp.pkt_len;
 786           dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
 787           if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
 788             printk("%s: interrupt - packet not received correctly\n", dev->name);
 789           } else {
 790             if (elp_debug >= 3)
 791               printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
 792             receive_packet(dev, adapter, dlen);
 793             if (elp_debug >= 3)
 794               printk("%s: packet received\n", dev->name);
 795           }
 796           if (dev->start && !start_receive(adapter, &adapter->itx_pcb)) 
 797             if (elp_debug >= 2)
 798               printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
 799           if (elp_debug >= 3)
 800             printk("%s: receive procedure complete\n", dev->name);
 801 
 802           break;
 803 
 804         /*
 805          * sent a packet
 806          */
 807         case CMD_TRANSMIT_PACKET_COMPLETE:
 808           if (elp_debug >= 3) 
 809             printk("%s: interrupt - packet sent\n", dev->name);
 810           if (dev->start == 0)
 811             break;
 812           if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
 813             if (elp_debug >= 2)
 814               printk("%s: interrupt - error sending packet %4.4x\n",
 815                 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
 816           dev->tbusy = 0;
 817 #if (ELP_KERNEL_TYPE < 3)
 818           mark_bh(INET_BH);
 819 #else
 820           mark_bh(NET_BH);
 821 #endif
 822           break;
 823 
 824         /*
 825          * some unknown PCB
 826          */
 827         default:
 828           printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
 829           break;
 830       }
 831     } else 
 832       printk("%s: failed to read PCB on interrupt\n", dev->name);
 833   }
 834   if (jiffies >= timeout)
 835     TIMEOUT_MSG();
 836 
 837   /*
 838    * indicate no longer in interrupt routine
 839    */
 840   dev->interrupt = 0;
 841 }
 842 
 843 
 844 /******************************************************
 845  *
 846  * open the board
 847  *
 848  ******************************************************/
 849 
 850 static int elp_open (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 851 
 852 {
 853   elp_device * adapter = (elp_device *) dev->priv;
 854 
 855   CHECK_NULL(dev);
 856 
 857   if (elp_debug >= 3)  
 858     printk("%s: request to open device\n", dev->name);
 859 
 860   /*
 861    * make sure we actually found the device
 862    */
 863   if (adapter == NULL) {
 864     printk("%s: Opening a non-existent physical device\n", dev->name);
 865     return -EAGAIN;
 866   }
 867 
 868   /*
 869    * disable interrupts on the board
 870    */
 871   OUTB(0x00, adapter->io_addr+PORT_CONTROL);
 872 
 873   /*
 874    * clear any pending interrupts
 875    */
 876   INB(adapter->io_addr+PORT_COMMAND);
 877 
 878   /*
 879    * interrupt routine not entered
 880    */
 881   dev->interrupt = 0;
 882 
 883   /*
 884    *  transmitter not busy 
 885    */
 886   dev->tbusy = 0;
 887 
 888   /*
 889    * install our interrupt service routine
 890    */
 891   if (request_irq(dev->irq, &elp_interrupt, 0, "3c505"))
 892     return -EAGAIN;
 893 
 894   /*
 895    * make sure we can find the device header given the interrupt number
 896    */
 897   irq2dev_map[dev->irq] = dev;
 898 
 899   /*
 900    * enable interrupts on the board
 901    */
 902   OUTB(CONTROL_CMDE, adapter->io_addr+PORT_CONTROL);
 903 
 904   /*
 905    * device is now officially open!
 906    */
 907   dev->start = 1;
 908 
 909   /*
 910    * configure adapter memory: we need 10 multicast addresses, default==0
 911    */
 912   if (elp_debug >= 3)
 913     printk("%s: sending 3c505 memory configuration command\n", dev->name);
 914   adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
 915   adapter->tx_pcb.data.memconf.cmd_q = 10;
 916   adapter->tx_pcb.data.memconf.rcv_q = 20;
 917   adapter->tx_pcb.data.memconf.mcast = 10;
 918   adapter->tx_pcb.data.memconf.frame = 20;
 919   adapter->tx_pcb.data.memconf.rcv_b = 20;
 920   adapter->tx_pcb.data.memconf.progs = 0;
 921   adapter->tx_pcb.length = sizeof(struct Memconf);
 922   adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
 923   if (!send_pcb(adapter, &adapter->tx_pcb))
 924     printk("%s: couldn't send memory configuration command\n", dev->name);
 925   else {
 926     int timeout = jiffies + TIMEOUT;
 927     while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
 928       ;
 929     if (jiffies >= timeout)
 930       TIMEOUT_MSG();
 931   }
 932 
 933 
 934   /*
 935    * configure adapter to receive broadcast messages and wait for response
 936    */
 937   if (elp_debug >= 3)
 938     printk("%s: sending 82586 configure command\n", dev->name);
 939   adapter->tx_pcb.command = CMD_CONFIGURE_82586;
 940   adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
 941   adapter->tx_pcb.length  = 2;
 942   adapter->got[CMD_CONFIGURE_82586] = 0;
 943   if (!send_pcb(adapter, &adapter->tx_pcb))
 944     printk("%s: couldn't send 82586 configure command\n", dev->name);
 945   else {
 946     int timeout = jiffies + TIMEOUT;
 947     while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
 948       ;
 949     if (jiffies >= timeout)
 950       TIMEOUT_MSG();
 951   }
 952 
 953   /*
 954    * queue receive commands to provide buffering
 955    */
 956   if (!start_receive(adapter, &adapter->tx_pcb))
 957     printk("%s: start receive command failed \n", dev->name);
 958   if (elp_debug >= 3)
 959     printk("%s: start receive command sent\n", dev->name);
 960 
 961   return 0;                     /* Always succeed */
 962 }
 963 
 964 
 965 /******************************************************
 966  *
 967  * send a packet to the adapter
 968  *
 969  ******************************************************/
 970 
 971 static int send_packet (elp_device * adapter, unsigned char * ptr, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 972 
 973 {
 974   int i;
 975 
 976   /*
 977    * make sure the length is even and no shorter than 60 bytes
 978    */
 979   unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
 980 
 981   CHECK_NULL(adapter);
 982   CHECK_NULL(ptr);
 983 
 984   if (nlen < len)
 985     printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
 986 
 987   /*
 988    * send the adapter a transmit packet command. Ignore segment and offset
 989    * and make sure the length is even
 990    */
 991   adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
 992   adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
 993   adapter->tx_pcb.data.xmit_pkt.buf_ofs = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0; /* Unused */
 994   adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
 995   if (!send_pcb(adapter, &adapter->tx_pcb)) 
 996     return FALSE;
 997 
 998   /*
 999    * make sure the data register is going the right way
1000    */
1001   cli(); 
1002   OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL); 
1003   sti(); 
1004 
1005   /*
1006    * write data to the adapter
1007    */
1008   for (i = 0; i < (nlen/2);i++) {
1009     int timeout = jiffies + TIMEOUT;
1010     while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0 && jiffies < timeout)
1011       ;
1012     if (jiffies >= timeout) {
1013       printk("*** timeout at %s(%d) writing word %d of %d ***\n",
1014             filename,__LINE__, i, nlen/2);
1015       return FALSE;
1016     }
1017 
1018     outw(*(short *)ptr, adapter->io_addr+PORT_DATA);
1019     ptr +=2;
1020   }
1021   
1022   return TRUE;
1023 }
1024 
1025 /******************************************************
1026  *
1027  * start the transmitter
1028  *    return 0 if sent OK, else return 1
1029  *
1030  ******************************************************/
1031 
1032 static int elp_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1033 
1034 {
1035   elp_device * adapter = (elp_device *) dev->priv;
1036 
1037   CHECK_NULL(dev);
1038 
1039   /*
1040    * not sure what this does, but the 3c509 driver does it, so...
1041    */
1042   if (skb == NULL) {
1043     dev_tint(dev);
1044     return 0;
1045   }
1046 
1047   /*
1048    * Fill in the ethernet header 
1049    * (for kernels prior to 1.1.4 only)
1050    */
1051 #if (ELP_KERNEL_TYPE < 2)
1052   IS_SKB(skb);
1053   if (!skb->arp && dev->rebuild_header(SKB_DATA, dev)) {
1054     skb->dev = dev;
1055     IS_SKB(skb);
1056     arp_queue (skb);
1057     return 0;
1058   }
1059 #endif
1060 
1061   /*
1062    * if we ended up with a munged length, don't send it
1063    */
1064   if (skb->len <= 0)
1065     return 0;
1066 
1067   if (elp_debug >= 3)
1068     printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1069 
1070   /*
1071    * if the transmitter is still busy, we have a transmit timeout...
1072    */
1073   if (dev->tbusy) {
1074     int tickssofar = jiffies - dev->trans_start;
1075     if (tickssofar < 200) /* was 500, AJT */
1076       return 1;
1077     printk("%s: transmit timed out, resetting adapter\n", dev->name);
1078     if ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0) 
1079       printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1080     adapter_reset(adapter);
1081     dev->trans_start = jiffies;
1082     dev->tbusy = 0;
1083   }
1084 
1085   /*
1086    * send the packet at skb->data for skb->len
1087    */
1088   if (!send_packet(adapter, (unsigned char *)SKB_DATA, skb->len)) {
1089     printk("%s: send packet PCB failed\n", dev->name);
1090     return 1;
1091   }
1092 
1093   if (elp_debug >= 3)
1094     printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1095 
1096 
1097   /*
1098    * start the transmit timeout
1099    */
1100   dev->trans_start = jiffies;
1101 
1102   /*
1103    * the transmitter is now busy
1104    */
1105   dev->tbusy = 1;
1106 
1107   /*
1108    * if we have been asked to free the buffer, do so
1109    */
1110 #if (ELP_KERNEL_TYPE < 4)
1111   if (skb->free)
1112     {
1113       IS_SKB(skb);
1114       kfree_skb(skb, FREE_WRITE);
1115     }
1116 #else
1117   dev_kfree_skb(skb, FREE_WRITE);
1118 #endif
1119 
1120   return 0;
1121 }
1122 
1123 /******************************************************
1124  *
1125  * return statistics on the board
1126  *
1127  ******************************************************/
1128 
1129 static struct enet_statistics * elp_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1130 
1131 {
1132   elp_device *adapter = (elp_device *) dev->priv;
1133 
1134   if (elp_debug >= 3)
1135     printk("%s: request for stats\n", dev->name);
1136 
1137   /* If the device is closed, just return the latest stats we have,
1138      - we cannot ask from the adapter without interrupts */
1139   if (!dev->start)
1140     return &adapter->stats;
1141 
1142   /* send a get statistics command to the board */
1143   adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1144   adapter->tx_pcb.length  = 0;
1145   adapter->got[CMD_NETWORK_STATISTICS] = 0;
1146   if (!send_pcb(adapter, &adapter->tx_pcb))
1147     printk("%s: couldn't send get statistics command\n", dev->name);
1148   else
1149     {
1150       int timeout = jiffies + TIMEOUT;
1151       while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1152         ;
1153       if (jiffies >= timeout) {
1154         TIMEOUT_MSG();
1155         return &adapter->stats;
1156       }
1157     }
1158 
1159   /* statistics are now up to date */
1160   return &adapter->stats;
1161 }
1162 
1163 /******************************************************
1164  *
1165  * close the board
1166  *
1167  ******************************************************/
1168 
1169 static int elp_close (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1170 
1171 {
1172   elp_device * adapter = (elp_device *) dev->priv;
1173 
1174   CHECK_NULL(dev);
1175   CHECK_NULL(adapter);
1176 
1177   if (elp_debug >= 3)
1178     printk("%s: request to close device\n", dev->name);
1179 
1180   /* Someone may request the device statistic information even when
1181    * the interface is closed. The following will update the statistics
1182    * structure in the driver, so we'll be able to give current statistics.
1183    */
1184   (void) elp_get_stats(dev);
1185 
1186   /*
1187    * disable interrupts on the board
1188    */
1189   OUTB(0x00, adapter->io_addr+PORT_CONTROL);
1190 
1191   /*
1192    *  flag transmitter as busy (i.e. not available)
1193    */
1194   dev->tbusy = 1;
1195 
1196   /*
1197    *  indicate device is closed
1198    */
1199   dev->start = 0;
1200 
1201   /*
1202    * release the IRQ
1203    */
1204   free_irq(dev->irq);
1205 
1206   /*
1207    * and we no longer have to map irq to dev either
1208    */
1209   irq2dev_map[dev->irq] = 0;
1210 
1211   return 0;
1212 }
1213 
1214 
1215 /************************************************************
1216  *
1217  * Set multicast list
1218  * num_addrs==0: clear mc_list
1219  * num_addrs==-1: set promiscuous mode
1220  * num_addrs>0: set mc_list
1221  *
1222  ************************************************************/
1223 
1224 static void elp_set_mc_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1225 {
1226   elp_device *adapter = (elp_device *) dev->priv;
1227   int i;
1228 
1229   if (elp_debug >= 3)
1230     printk("%s: request to set multicast list\n", dev->name);
1231 
1232   if (num_addrs != -1) {
1233     /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1234     /* if num_addrs==0 the list will be cleared */
1235     adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1236     adapter->tx_pcb.length  = 6*num_addrs;
1237     for (i=0;i<num_addrs;i++)
1238       memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1239     adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1240     if (!send_pcb(adapter, &adapter->tx_pcb))
1241       printk("%s: couldn't send set_multicast command\n", dev->name);
1242     else {
1243       int timeout = jiffies + TIMEOUT;
1244       while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1245         ;
1246       if (jiffies >= timeout) {
1247         TIMEOUT_MSG();
1248       }
1249     }
1250     if (num_addrs)
1251       adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1252     else /* num_addrs == 0 */
1253       adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1254   } else /* num_addrs == -1 */
1255     adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_ALL;
1256   /*
1257    * configure adapter to receive messages (as specified above)
1258    * and wait for response
1259    */
1260   if (elp_debug >= 3)
1261     printk("%s: sending 82586 configure command\n", dev->name);
1262   adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1263   adapter->tx_pcb.length  = 2;
1264   adapter->got[CMD_CONFIGURE_82586]  = 0;
1265   if (!send_pcb(adapter, &adapter->tx_pcb))
1266     printk("%s: couldn't send 82586 configure command\n", dev->name);
1267   else {
1268     int timeout = jiffies + TIMEOUT;
1269     while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1270       ;
1271     if (jiffies >= timeout)
1272       TIMEOUT_MSG();
1273   }
1274 }
1275 
1276 /******************************************************
1277  *
1278  * initialise Etherlink Plus board
1279  *
1280  ******************************************************/
1281 
1282 static void elp_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1283 
1284 {
1285   elp_device * adapter;
1286 
1287   CHECK_NULL(dev);
1288 
1289   /*
1290    * NULL out buffer pointers
1291    * (kernels prior to 1.1.4 only)
1292    */
1293 #if (ELP_KERNEL_TYPE < 2)
1294   {
1295     int i;
1296     for (i = 0; i < DEV_NUMBUFFS; i++)
1297       dev->buffs[i] = NULL;
1298   }
1299 #endif
1300 
1301   /*
1302    * set ptrs to various functions
1303    */
1304   dev->open             = elp_open;             /* local */
1305   dev->stop             = elp_close;            /* local */
1306   dev->get_stats        = elp_get_stats;        /* local */
1307   dev->hard_start_xmit  = elp_start_xmit;       /* local */
1308   dev->set_multicast_list = elp_set_mc_list;    /* local */
1309 
1310 #if (ELP_KERNEL_TYPE < 2)
1311   dev->hard_header      = eth_header;           /* eth.c */
1312   dev->add_arp          = eth_add_arp;          /* eth.c */
1313   dev->rebuild_header   = eth_rebuild_header;   /* eth.c */
1314   dev->type_trans       = eth_type_trans;       /* eth.c */
1315   dev->queue_xmit       = dev_queue_xmit;       /* dev.c */
1316 #else
1317   /* Setup the generic properties */
1318   ether_setup(dev);
1319 #endif
1320 
1321   /*
1322    * setup ptr to adapter specific information
1323    */
1324   adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1325   CHECK_NULL(adapter);
1326   adapter->io_addr = dev->base_addr;
1327   adapter->name    = dev->name;
1328   memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1329 
1330 
1331   /*
1332    * Ethernet information
1333    * (for kernels prior to 1.1.4 only)
1334    */
1335 #if (ELP_KERNEL_TYPE < 2)
1336   dev->type             = ARPHRD_ETHER;
1337   dev->hard_header_len  = ETH_HLEN;
1338   dev->mtu              = 1500;         /* eth_mtu */
1339   dev->addr_len         = ETH_ALEN;
1340   {
1341     int i;
1342     for (i = 0; i < dev->addr_len; i++) 
1343       dev->broadcast[i] = 0xff;
1344   }
1345 
1346   /*
1347    * New-style flags. 
1348    */
1349   dev->flags            = IFF_BROADCAST;
1350   dev->family           = AF_INET;
1351   dev->pa_addr          = 0;
1352   dev->pa_brdaddr       = 0;
1353   dev->pa_mask          = 0;
1354   dev->pa_alen          = sizeof(unsigned long);
1355 #endif
1356 
1357   /*
1358    * memory information
1359    */
1360   dev->mem_start = dev->mem_end = dev->rmem_end = dev->mem_start = 0;
1361 
1362 #if ELP_NEED_HARD_RESET
1363   adapter_hard_reset(adapter);
1364 #else
1365   adapter_reset(adapter);
1366 #endif
1367 }
1368 
1369 /************************************************************
1370  *
1371  * A couple of tests to see if there's 3C505 or not
1372  * Called only by elp_autodetect
1373  ************************************************************/
1374 
1375 static int elp_sense(int addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1376 {
1377   int timeout;
1378   byte orig_HCR=INB(addr+PORT_CONTROL),
1379        orig_HSR=INB(addr+PORT_STATUS);
1380   
1381   if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1382        ( (orig_HCR & CONTROL_DIR) != (orig_HSR & STATUS_DIR) ) )
1383     return 1;                /* It can't be 3c505 if HCR.DIR != HSR.DIR */
1384 
1385   /* Wait for a while; the adapter may still be booting up */
1386   if (elp_debug > 0)
1387     printk(stilllooking_msg);
1388   for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
1389     if ((INB(addr+PORT_STATUS) & ASF_PCB_MASK) != ASF_PCB_END)
1390       break;
1391 
1392   if (orig_HCR & CONTROL_DIR) {
1393     /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1394     OUTB(orig_HCR & ~CONTROL_DIR,addr+PORT_CONTROL);
1395     timeout = jiffies+30;
1396     while (jiffies < timeout)
1397       ;
1398     if (INB(addr+PORT_STATUS) & STATUS_DIR) {
1399       OUTB(orig_HCR,addr+PORT_CONTROL);
1400       return 2;
1401     }
1402   } else {
1403     /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1404     OUTB(orig_HCR | CONTROL_DIR,addr+PORT_CONTROL);
1405     timeout = jiffies+300;
1406     while (jiffies < timeout)
1407       ;
1408     if (!(INB(addr+PORT_STATUS) & STATUS_DIR)) {
1409       OUTB(orig_HCR,addr+PORT_CONTROL);
1410       return 3;
1411     }
1412   }
1413   return 0;     /* It certainly looks like a 3c505. */
1414 }
1415 
1416 /*************************************************************
1417  *
1418  * Search through addr_list[] and try to find a 3C505
1419  * Called only by eplus_probe
1420  *************************************************************/
1421 
1422 static int elp_autodetect(struct device * dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1423 {
1424   int idx=0, addr;
1425 
1426   /* if base address set, then only check that address
1427      otherwise, run through the table */
1428   if ( (addr=dev->base_addr) ) { /* dev->base_addr == 0 ==> plain autodetect */
1429     if (elp_debug > 0)
1430       printk(search_msg, dev->name, addr);
1431     if (elp_sense(addr) == 0)
1432     {
1433       if (elp_debug > 0)
1434         printk(found_msg);
1435       return addr;
1436     } else if (elp_debug > 0)
1437       printk(notfound_msg);
1438   } else while ( (addr=addr_list[idx++]) ) {
1439     if (elp_debug > 0)
1440       printk(search_msg, dev->name, addr);
1441     if (elp_sense(addr) == 0) {
1442       if (elp_debug > 0)
1443         printk(found_msg);
1444       return addr;
1445     } else if (elp_debug > 0)
1446       printk(notfound_msg);
1447   }
1448 
1449   /* could not find an adapter */
1450   if (elp_debug == 0)
1451     printk(couldnot_msg, dev->name);
1452   return 0; /* Because of this, the layer above will return -ENODEV */
1453 }
1454 
1455 /******************************************************
1456  *
1457  * probe for an Etherlink Plus board at the specified address
1458  *
1459  ******************************************************/
1460 
1461 int elplus_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1462 
1463 {
1464   elp_device adapter;
1465   int            i;
1466 
1467   CHECK_NULL(dev);
1468 
1469   /*
1470    *  setup adapter structure
1471    */
1472 
1473   adapter.io_addr = dev->base_addr = elp_autodetect(dev);
1474   if ( !adapter.io_addr )
1475     return -ENODEV;
1476 
1477   /*
1478    *  As we enter here from bootup, the adapter should have IRQs enabled,
1479    *  but we can as well enable them anyway.
1480    */
1481   OUTB(INB(dev->base_addr+PORT_CONTROL) | CONTROL_CMDE,
1482        dev->base_addr+PORT_CONTROL);
1483   autoirq_setup(0);
1484 
1485   /*
1486    * use ethernet address command to probe for board in polled mode
1487    * (this also makes us the IRQ that we need for automatic detection)
1488    */
1489   adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1490   adapter.tx_pcb.length  = 0;
1491   if (!send_pcb   (&adapter, &adapter.tx_pcb) ||
1492       !receive_pcb(&adapter, &adapter.rx_pcb) ||
1493       (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1494       (adapter.rx_pcb.length != 6)) {
1495     printk("%s: not responding to first PCB\n", dev->name);
1496     return -ENODEV;
1497   }
1498   if (dev->irq) { /* Is there a preset IRQ? */
1499      if (dev->irq != autoirq_report(0)) {
1500         printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1501         return -ENODEV;
1502      }
1503      /* if dev->irq == autoirq_report(0), all is well */
1504   } else /* No preset IRQ; just use what we can detect */
1505      dev->irq=autoirq_report(0);
1506   switch (dev->irq) { /* Legal, sane? */
1507     case 0: printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1508             printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1509             return -ENODEV;
1510     case 1:
1511     case 6:
1512     case 8:
1513     case 13: 
1514             printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1515                    dev->name,
1516                    dev->irq);
1517             return -ENODEV;
1518   }
1519   /*
1520    *  Now we have the IRQ number so we can disable the interrupts from
1521    *  the board until the board is opened.
1522    */
1523   OUTB(INB(dev->base_addr+PORT_CONTROL) & ~CONTROL_CMDE,
1524        dev->base_addr+PORT_CONTROL);
1525   
1526   /*
1527    * copy ethernet address into structure
1528    */
1529   for (i = 0; i < 6; i++) 
1530     dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1531 
1532   /*
1533    * print remainder of startup message
1534    */
1535 #if (ELP_KERNEL_TYPE < 2)
1536   printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %s\n",
1537          dev->name, dev->base_addr, dev->irq, eth_print(dev->dev_addr));
1538 #else
1539   printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1540          dev->name, dev->base_addr, dev->irq,
1541          dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1542          dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1543 #endif
1544   
1545   /*
1546    * initialise the device
1547    */
1548   elp_init(dev);
1549   return 0;
1550 }

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