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
  29. init_module
  30. cleanup_module

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

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