root/drivers/net/3c505.c

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

DEFINITIONS

This source file includes following definitions.
  1. inb_status
  2. inb_control
  3. inb_command
  4. outb_control
  5. outb_command
  6. inw_data
  7. outw_data
  8. get_status
  9. set_hsf
  10. wait_hcre
  11. wait_fast_hcre
  12. adapter_reset
  13. send_pcb
  14. receive_pcb
  15. adapter_hard_reset
  16. start_receive
  17. receive_packet
  18. elp_interrupt
  19. elp_open
  20. send_packet
  21. elp_start_xmit
  22. elp_get_stats
  23. elp_close
  24. elp_set_mc_list
  25. elp_init
  26. elp_sense
  27. elp_autodetect
  28. elplus_probe

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

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