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 reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 669 
 670 {
 671   int len;
 672   int dlen;
 673   int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 674   struct device *dev;
 675   elp_device * adapter;
 676   int timeout;
 677 
 678   if (irq < 0 || irq > 15) {
 679     printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
 680     return;
 681   }
 682 
 683 /* FIXME: How do I do this kind of check without a fixed IRQ? */
 684 #if 0
 685   if (irq != ELP_IRQ) {
 686     printk ("elp_interrupt(): - interrupt routine has incorrect IRQ of %i\n", irq);
 687     return;
 688   }
 689 #endif
 690 
 691   dev = irq2dev_map[irq];
 692 
 693   if (dev == NULL) {
 694     printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
 695     return;
 696   }
 697 
 698   adapter = (elp_device *) dev->priv;
 699 
 700   CHECK_NULL(adapter);
 701 
 702   if (dev->interrupt)
 703     if (elp_debug >= 2)
 704       printk("%s: Re-entering the interrupt handler.\n", dev->name);
 705   dev->interrupt = 1;
 706 
 707   /*
 708    * allow interrupts (we need timers!)
 709    */
 710   sti();
 711 
 712   /*
 713    * receive a PCB from the adapter
 714    */
 715   timeout = jiffies + TIMEOUT;
 716   while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0 &&
 717          jiffies < timeout) {
 718     
 719     if (receive_pcb(adapter, &adapter->irx_pcb)) {
 720 
 721       switch (adapter->irx_pcb.command) {
 722 
 723         /*
 724          * 82586 configured correctly
 725          */
 726         case CMD_CONFIGURE_82586_RESPONSE:
 727           adapter->got[CMD_CONFIGURE_82586] = 1;
 728           if (elp_debug >= 3)
 729             printk("%s: interrupt - configure response received\n", dev->name);
 730           break;
 731 
 732         /*
 733          * Adapter memory configuration
 734          */
 735         case CMD_CONFIGURE_ADAPTER_RESPONSE:
 736           adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
 737           if (elp_debug >= 3)
 738             printk("%s: Adapter memory configuration %s.",dev->name,
 739                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 740           break;
 741         
 742         /*
 743          * Multicast list loading
 744          */
 745         case CMD_LOAD_MULTICAST_RESPONSE:
 746           adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
 747           if (elp_debug >= 3)
 748             printk("%s: Multicast address list loading %s.",dev->name,
 749                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 750           break;
 751 
 752         /*
 753          * Station address setting
 754          */
 755         case CMD_SET_ADDRESS_RESPONSE:
 756           adapter->got[CMD_SET_STATION_ADDRESS] = 1;
 757           if (elp_debug >= 3)
 758             printk("%s: Ethernet address setting %s.",dev->name,
 759                    adapter->irx_pcb.data.failed?"failed":"succeeded");
 760           break;
 761 
 762 
 763         /*
 764          * received board statistics
 765          */
 766         case CMD_NETWORK_STATISTICS_RESPONSE:
 767           adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
 768           adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
 769           adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
 770           adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
 771           adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
 772           adapter->got[CMD_NETWORK_STATISTICS] = 1;
 773           if (elp_debug >= 3)
 774             printk("%s: interrupt - statistics response received\n", dev->name);
 775           break;
 776 
 777         /*
 778          * received a packet
 779          */
 780         case CMD_RECEIVE_PACKET_COMPLETE:
 781           /* if the device isn't open, don't pass packets up the stack */
 782           if (dev->start == 0)
 783             break;
 784           len = adapter->irx_pcb.data.rcv_resp.pkt_len;
 785           dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
 786           if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
 787             printk("%s: interrupt - packet not received correctly\n", dev->name);
 788           } else {
 789             if (elp_debug >= 3)
 790               printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
 791             receive_packet(dev, adapter, dlen);
 792             if (elp_debug >= 3)
 793               printk("%s: packet received\n", dev->name);
 794           }
 795           if (dev->start && !start_receive(adapter, &adapter->itx_pcb)) 
 796             if (elp_debug >= 2)
 797               printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
 798           if (elp_debug >= 3)
 799             printk("%s: receive procedure complete\n", dev->name);
 800 
 801           break;
 802 
 803         /*
 804          * sent a packet
 805          */
 806         case CMD_TRANSMIT_PACKET_COMPLETE:
 807           if (elp_debug >= 3) 
 808             printk("%s: interrupt - packet sent\n", dev->name);
 809           if (dev->start == 0)
 810             break;
 811           if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
 812             if (elp_debug >= 2)
 813               printk("%s: interrupt - error sending packet %4.4x\n",
 814                 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
 815           dev->tbusy = 0;
 816 #if (ELP_KERNEL_TYPE < 3)
 817           mark_bh(INET_BH);
 818 #else
 819           mark_bh(NET_BH);
 820 #endif
 821           break;
 822 
 823         /*
 824          * some unknown PCB
 825          */
 826         default:
 827           printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
 828           break;
 829       }
 830     } else 
 831       printk("%s: failed to read PCB on interrupt\n", dev->name);
 832   }
 833   if (jiffies >= timeout)
 834     TIMEOUT_MSG();
 835 
 836   /*
 837    * indicate no longer in interrupt routine
 838    */
 839   dev->interrupt = 0;
 840 }
 841 
 842 
 843 /******************************************************
 844  *
 845  * open the board
 846  *
 847  ******************************************************/
 848 
 849 static int elp_open (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 850 
 851 {
 852   elp_device * adapter = (elp_device *) dev->priv;
 853 
 854   CHECK_NULL(dev);
 855 
 856   if (elp_debug >= 3)  
 857     printk("%s: request to open device\n", dev->name);
 858 
 859   /*
 860    * make sure we actually found the device
 861    */
 862   if (adapter == NULL) {
 863     printk("%s: Opening a non-existent physical device\n", dev->name);
 864     return -EAGAIN;
 865   }
 866 
 867   /*
 868    * disable interrupts on the board
 869    */
 870   OUTB(0x00, adapter->io_addr+PORT_CONTROL);
 871 
 872   /*
 873    * clear any pending interrupts
 874    */
 875   INB(adapter->io_addr+PORT_COMMAND);
 876 
 877   /*
 878    * interrupt routine not entered
 879    */
 880   dev->interrupt = 0;
 881 
 882   /*
 883    *  transmitter not busy 
 884    */
 885   dev->tbusy = 0;
 886 
 887   /*
 888    * install our interrupt service routine
 889    */
 890   if (request_irq(dev->irq, &elp_interrupt, 0, "3c505"))
 891     return -EAGAIN;
 892 
 893   /*
 894    * make sure we can find the device header given the interrupt number
 895    */
 896   irq2dev_map[dev->irq] = dev;
 897 
 898   /*
 899    * enable interrupts on the board
 900    */
 901   OUTB(CONTROL_CMDE, adapter->io_addr+PORT_CONTROL);
 902 
 903   /*
 904    * device is now officially open!
 905    */
 906   dev->start = 1;
 907 
 908   /*
 909    * configure adapter memory: we need 10 multicast addresses, default==0
 910    */
 911   if (elp_debug >= 3)
 912     printk("%s: sending 3c505 memory configuration command\n", dev->name);
 913   adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
 914   adapter->tx_pcb.data.memconf.cmd_q = 10;
 915   adapter->tx_pcb.data.memconf.rcv_q = 20;
 916   adapter->tx_pcb.data.memconf.mcast = 10;
 917   adapter->tx_pcb.data.memconf.frame = 20;
 918   adapter->tx_pcb.data.memconf.rcv_b = 20;
 919   adapter->tx_pcb.data.memconf.progs = 0;
 920   adapter->tx_pcb.length = sizeof(struct Memconf);
 921   adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
 922   if (!send_pcb(adapter, &adapter->tx_pcb))
 923     printk("%s: couldn't send memory configuration command\n", dev->name);
 924   else {
 925     int timeout = jiffies + TIMEOUT;
 926     while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
 927       ;
 928     if (jiffies >= timeout)
 929       TIMEOUT_MSG();
 930   }
 931 
 932 
 933   /*
 934    * configure adapter to receive broadcast messages and wait for response
 935    */
 936   if (elp_debug >= 3)
 937     printk("%s: sending 82586 configure command\n", dev->name);
 938   adapter->tx_pcb.command = CMD_CONFIGURE_82586;
 939   adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
 940   adapter->tx_pcb.length  = 2;
 941   adapter->got[CMD_CONFIGURE_82586] = 0;
 942   if (!send_pcb(adapter, &adapter->tx_pcb))
 943     printk("%s: couldn't send 82586 configure command\n", dev->name);
 944   else {
 945     int timeout = jiffies + TIMEOUT;
 946     while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
 947       ;
 948     if (jiffies >= timeout)
 949       TIMEOUT_MSG();
 950   }
 951 
 952   /*
 953    * queue receive commands to provide buffering
 954    */
 955   if (!start_receive(adapter, &adapter->tx_pcb))
 956     printk("%s: start receive command failed \n", dev->name);
 957   if (elp_debug >= 3)
 958     printk("%s: start receive command sent\n", dev->name);
 959 
 960   return 0;                     /* Always succeed */
 961 }
 962 
 963 
 964 /******************************************************
 965  *
 966  * send a packet to the adapter
 967  *
 968  ******************************************************/
 969 
 970 static int send_packet (elp_device * adapter, unsigned char * ptr, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 971 
 972 {
 973   int i;
 974 
 975   /*
 976    * make sure the length is even and no shorter than 60 bytes
 977    */
 978   unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
 979 
 980   CHECK_NULL(adapter);
 981   CHECK_NULL(ptr);
 982 
 983   if (nlen < len)
 984     printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
 985 
 986   /*
 987    * send the adapter a transmit packet command. Ignore segment and offset
 988    * and make sure the length is even
 989    */
 990   adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
 991   adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
 992   adapter->tx_pcb.data.xmit_pkt.buf_ofs = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0; /* Unused */
 993   adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
 994   if (!send_pcb(adapter, &adapter->tx_pcb)) 
 995     return FALSE;
 996 
 997   /*
 998    * make sure the data register is going the right way
 999    */
1000   cli(); 
1001   OUTB(INB(adapter->io_addr+PORT_CONTROL)&(~CONTROL_DIR), adapter->io_addr+PORT_CONTROL); 
1002   sti(); 
1003 
1004   /*
1005    * write data to the adapter
1006    */
1007   for (i = 0; i < (nlen/2);i++) {
1008     int timeout = jiffies + TIMEOUT;
1009     while ((INB(adapter->io_addr+PORT_STATUS)&STATUS_HRDY) == 0 && jiffies < timeout)
1010       ;
1011     if (jiffies >= timeout) {
1012       printk("*** timeout at %s(%d) writing word %d of %d ***\n",
1013             filename,__LINE__, i, nlen/2);
1014       return FALSE;
1015     }
1016 
1017     outw(*(short *)ptr, adapter->io_addr+PORT_DATA);
1018     ptr +=2;
1019   }
1020   
1021   return TRUE;
1022 }
1023 
1024 /******************************************************
1025  *
1026  * start the transmitter
1027  *    return 0 if sent OK, else return 1
1028  *
1029  ******************************************************/
1030 
1031 static int elp_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1032 
1033 {
1034   elp_device * adapter = (elp_device *) dev->priv;
1035 
1036   CHECK_NULL(dev);
1037 
1038   /*
1039    * not sure what this does, but the 3c509 driver does it, so...
1040    */
1041   if (skb == NULL) {
1042     dev_tint(dev);
1043     return 0;
1044   }
1045 
1046   /*
1047    * Fill in the ethernet header 
1048    * (for kernels prior to 1.1.4 only)
1049    */
1050 #if (ELP_KERNEL_TYPE < 2)
1051   IS_SKB(skb);
1052   if (!skb->arp && dev->rebuild_header(SKB_DATA, dev)) {
1053     skb->dev = dev;
1054     IS_SKB(skb);
1055     arp_queue (skb);
1056     return 0;
1057   }
1058 #endif
1059 
1060   /*
1061    * if we ended up with a munged length, don't send it
1062    */
1063   if (skb->len <= 0)
1064     return 0;
1065 
1066   if (elp_debug >= 3)
1067     printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1068 
1069   /*
1070    * if the transmitter is still busy, we have a transmit timeout...
1071    */
1072   if (dev->tbusy) {
1073     int tickssofar = jiffies - dev->trans_start;
1074     if (tickssofar < 200) /* was 500, AJT */
1075       return 1;
1076     printk("%s: transmit timed out, resetting adapter\n", dev->name);
1077     if ((INB(adapter->io_addr+PORT_STATUS)&STATUS_ACRF) != 0) 
1078       printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1079     adapter_reset(adapter);
1080     dev->trans_start = jiffies;
1081     dev->tbusy = 0;
1082   }
1083 
1084   /*
1085    * send the packet at skb->data for skb->len
1086    */
1087   if (!send_packet(adapter, (unsigned char *)SKB_DATA, skb->len)) {
1088     printk("%s: send packet PCB failed\n", dev->name);
1089     return 1;
1090   }
1091 
1092   if (elp_debug >= 3)
1093     printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1094 
1095 
1096   /*
1097    * start the transmit timeout
1098    */
1099   dev->trans_start = jiffies;
1100 
1101   /*
1102    * the transmitter is now busy
1103    */
1104   dev->tbusy = 1;
1105 
1106   /*
1107    * if we have been asked to free the buffer, do so
1108    */
1109 #if (ELP_KERNEL_TYPE < 4)
1110   if (skb->free)
1111     {
1112       IS_SKB(skb);
1113       kfree_skb(skb, FREE_WRITE);
1114     }
1115 #else
1116   dev_kfree_skb(skb, FREE_WRITE);
1117 #endif
1118 
1119   return 0;
1120 }
1121 
1122 /******************************************************
1123  *
1124  * return statistics on the board
1125  *
1126  ******************************************************/
1127 
1128 static struct enet_statistics * elp_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1129 
1130 {
1131   elp_device *adapter = (elp_device *) dev->priv;
1132 
1133   if (elp_debug >= 3)
1134     printk("%s: request for stats\n", dev->name);
1135 
1136   /* If the device is closed, just return the latest stats we have,
1137      - we cannot ask from the adapter without interrupts */
1138   if (!dev->start)
1139     return &adapter->stats;
1140 
1141   /* send a get statistics command to the board */
1142   adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1143   adapter->tx_pcb.length  = 0;
1144   adapter->got[CMD_NETWORK_STATISTICS] = 0;
1145   if (!send_pcb(adapter, &adapter->tx_pcb))
1146     printk("%s: couldn't send get statistics command\n", dev->name);
1147   else
1148     {
1149       int timeout = jiffies + TIMEOUT;
1150       while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1151         ;
1152       if (jiffies >= timeout) {
1153         TIMEOUT_MSG();
1154         return &adapter->stats;
1155       }
1156     }
1157 
1158   /* statistics are now up to date */
1159   return &adapter->stats;
1160 }
1161 
1162 /******************************************************
1163  *
1164  * close the board
1165  *
1166  ******************************************************/
1167 
1168 static int elp_close (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1169 
1170 {
1171   elp_device * adapter = (elp_device *) dev->priv;
1172 
1173   CHECK_NULL(dev);
1174   CHECK_NULL(adapter);
1175 
1176   if (elp_debug >= 3)
1177     printk("%s: request to close device\n", dev->name);
1178 
1179   /* Someone may request the device statistic information even when
1180    * the interface is closed. The following will update the statistics
1181    * structure in the driver, so we'll be able to give current statistics.
1182    */
1183   (void) elp_get_stats(dev);
1184 
1185   /*
1186    * disable interrupts on the board
1187    */
1188   OUTB(0x00, adapter->io_addr+PORT_CONTROL);
1189 
1190   /*
1191    *  flag transmitter as busy (i.e. not available)
1192    */
1193   dev->tbusy = 1;
1194 
1195   /*
1196    *  indicate device is closed
1197    */
1198   dev->start = 0;
1199 
1200   /*
1201    * release the IRQ
1202    */
1203   free_irq(dev->irq);
1204 
1205   /*
1206    * and we no longer have to map irq to dev either
1207    */
1208   irq2dev_map[dev->irq] = 0;
1209 
1210   return 0;
1211 }
1212 
1213 
1214 /************************************************************
1215  *
1216  * Set multicast list
1217  * num_addrs==0: clear mc_list
1218  * num_addrs==-1: set promiscuous mode
1219  * num_addrs>0: set mc_list
1220  *
1221  ************************************************************/
1222 
1223 static void elp_set_mc_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1224 {
1225   elp_device *adapter = (elp_device *) dev->priv;
1226   int i;
1227 
1228   if (elp_debug >= 3)
1229     printk("%s: request to set multicast list\n", dev->name);
1230 
1231   if (num_addrs != -1) {
1232     /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1233     /* if num_addrs==0 the list will be cleared */
1234     adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1235     adapter->tx_pcb.length  = 6*num_addrs;
1236     for (i=0;i<num_addrs;i++)
1237       memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1238     adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1239     if (!send_pcb(adapter, &adapter->tx_pcb))
1240       printk("%s: couldn't send set_multicast command\n", dev->name);
1241     else {
1242       int timeout = jiffies + TIMEOUT;
1243       while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1244         ;
1245       if (jiffies >= timeout) {
1246         TIMEOUT_MSG();
1247       }
1248     }
1249     if (num_addrs)
1250       adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1251     else /* num_addrs == 0 */
1252       adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1253   } else /* num_addrs == -1 */
1254     adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_ALL;
1255   /*
1256    * configure adapter to receive messages (as specified above)
1257    * and wait for response
1258    */
1259   if (elp_debug >= 3)
1260     printk("%s: sending 82586 configure command\n", dev->name);
1261   adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1262   adapter->tx_pcb.length  = 2;
1263   adapter->got[CMD_CONFIGURE_82586]  = 0;
1264   if (!send_pcb(adapter, &adapter->tx_pcb))
1265     printk("%s: couldn't send 82586 configure command\n", dev->name);
1266   else {
1267     int timeout = jiffies + TIMEOUT;
1268     while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1269       ;
1270     if (jiffies >= timeout)
1271       TIMEOUT_MSG();
1272   }
1273 }
1274 
1275 /******************************************************
1276  *
1277  * initialise Etherlink Plus board
1278  *
1279  ******************************************************/
1280 
1281 static void elp_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1282 
1283 {
1284   elp_device * adapter;
1285 
1286   CHECK_NULL(dev);
1287 
1288   /*
1289    * NULL out buffer pointers
1290    * (kernels prior to 1.1.4 only)
1291    */
1292 #if (ELP_KERNEL_TYPE < 2)
1293   {
1294     int i;
1295     for (i = 0; i < DEV_NUMBUFFS; i++)
1296       dev->buffs[i] = NULL;
1297   }
1298 #endif
1299 
1300   /*
1301    * set ptrs to various functions
1302    */
1303   dev->open             = elp_open;             /* local */
1304   dev->stop             = elp_close;            /* local */
1305   dev->get_stats        = elp_get_stats;        /* local */
1306   dev->hard_start_xmit  = elp_start_xmit;       /* local */
1307   dev->set_multicast_list = elp_set_mc_list;    /* local */
1308 
1309 #if (ELP_KERNEL_TYPE < 2)
1310   dev->hard_header      = eth_header;           /* eth.c */
1311   dev->add_arp          = eth_add_arp;          /* eth.c */
1312   dev->rebuild_header   = eth_rebuild_header;   /* eth.c */
1313   dev->type_trans       = eth_type_trans;       /* eth.c */
1314   dev->queue_xmit       = dev_queue_xmit;       /* dev.c */
1315 #else
1316   /* Setup the generic properties */
1317   ether_setup(dev);
1318 #endif
1319 
1320   /*
1321    * setup ptr to adapter specific information
1322    */
1323   adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1324   CHECK_NULL(adapter);
1325   adapter->io_addr = dev->base_addr;
1326   adapter->name    = dev->name;
1327   memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1328 
1329 
1330   /*
1331    * Ethernet information
1332    * (for kernels prior to 1.1.4 only)
1333    */
1334 #if (ELP_KERNEL_TYPE < 2)
1335   dev->type             = ARPHRD_ETHER;
1336   dev->hard_header_len  = ETH_HLEN;
1337   dev->mtu              = 1500;         /* eth_mtu */
1338   dev->addr_len         = ETH_ALEN;
1339   {
1340     int i;
1341     for (i = 0; i < dev->addr_len; i++) 
1342       dev->broadcast[i] = 0xff;
1343   }
1344 
1345   /*
1346    * New-style flags. 
1347    */
1348   dev->flags            = IFF_BROADCAST;
1349   dev->family           = AF_INET;
1350   dev->pa_addr          = 0;
1351   dev->pa_brdaddr       = 0;
1352   dev->pa_mask          = 0;
1353   dev->pa_alen          = sizeof(unsigned long);
1354 #endif
1355 
1356   /*
1357    * memory information
1358    */
1359   dev->mem_start = dev->mem_end = dev->rmem_end = dev->mem_start = 0;
1360 
1361 #if ELP_NEED_HARD_RESET
1362   adapter_hard_reset(adapter);
1363 #else
1364   adapter_reset(adapter);
1365 #endif
1366 }
1367 
1368 /************************************************************
1369  *
1370  * A couple of tests to see if there's 3C505 or not
1371  * Called only by elp_autodetect
1372  ************************************************************/
1373 
1374 static int elp_sense(int addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1375 {
1376   int timeout;
1377   byte orig_HCR=INB(addr+PORT_CONTROL),
1378        orig_HSR=INB(addr+PORT_STATUS);
1379   
1380   if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1381        ( (orig_HCR & CONTROL_DIR) != (orig_HSR & STATUS_DIR) ) )
1382     return 1;                /* It can't be 3c505 if HCR.DIR != HSR.DIR */
1383 
1384   /* Wait for a while; the adapter may still be booting up */
1385   if (elp_debug > 0)
1386     printk(stilllooking_msg);
1387   for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
1388     if ((INB(addr+PORT_STATUS) & ASF_PCB_MASK) != ASF_PCB_END)
1389       break;
1390 
1391   if (orig_HCR & CONTROL_DIR) {
1392     /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1393     OUTB(orig_HCR & ~CONTROL_DIR,addr+PORT_CONTROL);
1394     timeout = jiffies+30;
1395     while (jiffies < timeout)
1396       ;
1397     if (INB(addr+PORT_STATUS) & STATUS_DIR) {
1398       OUTB(orig_HCR,addr+PORT_CONTROL);
1399       return 2;
1400     }
1401   } else {
1402     /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1403     OUTB(orig_HCR | CONTROL_DIR,addr+PORT_CONTROL);
1404     timeout = jiffies+300;
1405     while (jiffies < timeout)
1406       ;
1407     if (!(INB(addr+PORT_STATUS) & STATUS_DIR)) {
1408       OUTB(orig_HCR,addr+PORT_CONTROL);
1409       return 3;
1410     }
1411   }
1412   return 0;     /* It certainly looks like a 3c505. */
1413 }
1414 
1415 /*************************************************************
1416  *
1417  * Search through addr_list[] and try to find a 3C505
1418  * Called only by eplus_probe
1419  *************************************************************/
1420 
1421 static int elp_autodetect(struct device * dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1422 {
1423   int idx=0, addr;
1424 
1425   /* if base address set, then only check that address
1426      otherwise, run through the table */
1427   if ( (addr=dev->base_addr) ) { /* dev->base_addr == 0 ==> plain autodetect */
1428     if (elp_debug > 0)
1429       printk(search_msg, dev->name, addr);
1430     if (elp_sense(addr) == 0)
1431     {
1432       if (elp_debug > 0)
1433         printk(found_msg);
1434       return addr;
1435     } else if (elp_debug > 0)
1436       printk(notfound_msg);
1437   } else while ( (addr=addr_list[idx++]) ) {
1438     if (elp_debug > 0)
1439       printk(search_msg, dev->name, addr);
1440     if (elp_sense(addr) == 0) {
1441       if (elp_debug > 0)
1442         printk(found_msg);
1443       return addr;
1444     } else if (elp_debug > 0)
1445       printk(notfound_msg);
1446   }
1447 
1448   /* could not find an adapter */
1449   if (elp_debug == 0)
1450     printk(couldnot_msg, dev->name);
1451   return 0; /* Because of this, the layer above will return -ENODEV */
1452 }
1453 
1454 /******************************************************
1455  *
1456  * probe for an Etherlink Plus board at the specified address
1457  *
1458  ******************************************************/
1459 
1460 int elplus_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1461 
1462 {
1463   elp_device adapter;
1464   int            i;
1465 
1466   CHECK_NULL(dev);
1467 
1468   /*
1469    *  setup adapter structure
1470    */
1471 
1472   adapter.io_addr = dev->base_addr = elp_autodetect(dev);
1473   if ( !adapter.io_addr )
1474     return -ENODEV;
1475 
1476   /*
1477    *  As we enter here from bootup, the adapter should have IRQs enabled,
1478    *  but we can as well enable them anyway.
1479    */
1480   OUTB(INB(dev->base_addr+PORT_CONTROL) | CONTROL_CMDE,
1481        dev->base_addr+PORT_CONTROL);
1482   autoirq_setup(0);
1483 
1484   /*
1485    * use ethernet address command to probe for board in polled mode
1486    * (this also makes us the IRQ that we need for automatic detection)
1487    */
1488   adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1489   adapter.tx_pcb.length  = 0;
1490   if (!send_pcb   (&adapter, &adapter.tx_pcb) ||
1491       !receive_pcb(&adapter, &adapter.rx_pcb) ||
1492       (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1493       (adapter.rx_pcb.length != 6)) {
1494     printk("%s: not responding to first PCB\n", dev->name);
1495     return -ENODEV;
1496   }
1497   if (dev->irq) { /* Is there a preset IRQ? */
1498      if (dev->irq != autoirq_report(0)) {
1499         printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1500         return -ENODEV;
1501      }
1502      /* if dev->irq == autoirq_report(0), all is well */
1503   } else /* No preset IRQ; just use what we can detect */
1504      dev->irq=autoirq_report(0);
1505   switch (dev->irq) { /* Legal, sane? */
1506     case 0: printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1507             printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1508             return -ENODEV;
1509     case 1:
1510     case 6:
1511     case 8:
1512     case 13: 
1513             printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1514                    dev->name,
1515                    dev->irq);
1516             return -ENODEV;
1517   }
1518   /*
1519    *  Now we have the IRQ number so we can disable the interrupts from
1520    *  the board until the board is opened.
1521    */
1522   OUTB(INB(dev->base_addr+PORT_CONTROL) & ~CONTROL_CMDE,
1523        dev->base_addr+PORT_CONTROL);
1524   
1525   /*
1526    * copy ethernet address into structure
1527    */
1528   for (i = 0; i < 6; i++) 
1529     dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1530 
1531   /*
1532    * print remainder of startup message
1533    */
1534 #if (ELP_KERNEL_TYPE < 2)
1535   printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %s\n",
1536          dev->name, dev->base_addr, dev->irq, eth_print(dev->dev_addr));
1537 #else
1538   printk("%s: 3c505 card found at I/O 0x%x using IRQ%d has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1539          dev->name, dev->base_addr, dev->irq,
1540          dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1541          dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1542 #endif
1543   
1544   /*
1545    * initialise the device
1546    */
1547   elp_init(dev);
1548   return 0;
1549 }

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