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

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