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

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