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                 sti();
 382                 printk("%s: timeout in middle of sending PCB\n", dev->name);
 383         }
 384 
 385         adapter_reset(dev);
 386         return FALSE;
 387 }
 388 
 389 /*****************************************************************
 390  *
 391  * receive_pcb
 392  *   Read a PCB to the adapter
 393  *
 394  *      wait for ACRF to be non-zero        ---<---+
 395  *      input a byte                               |
 396  *      if ASF1 and ASF2 were not both one         |
 397  *              before byte was read, loop      --->---+
 398  *      set HSF1 and HSF2 for ack
 399  *
 400  *****************************************************************/
 401 
 402 static int
 403 receive_pcb (struct device * dev, pcb_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 404 {
 405         int i, j;
 406         int total_length;
 407         int stat;
 408         int timeout;
 409 
 410         CHECK_NULL(pcb);
 411         CHECK_NULL(dev);
 412 
 413         set_hsf(dev->base_addr,0);
 414 
 415         /* get the command code */
 416         timeout = jiffies + 2;
 417         while (((stat = get_status(dev->base_addr))&ACRF) == 0 && jiffies < timeout)
 418                 ;
 419         if (jiffies >= timeout) {
 420                 TIMEOUT_MSG(__LINE__);
 421                 return FALSE;
 422         }
 423 
 424         pcb->command = inb_command(dev->base_addr);
 425 
 426         /* read the data length */
 427         timeout = jiffies + 3;
 428         while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout)
 429                 ;
 430         if (jiffies >= timeout) {
 431                 TIMEOUT_MSG(__LINE__);
 432                 return FALSE;
 433         }
 434         pcb->length = inb_command(dev->base_addr);
 435 
 436         if (pcb->length > MAX_PCB_DATA) {
 437                 INVALID_PCB_MSG(pcb->length);
 438                 adapter_reset(dev);
 439                 return FALSE;
 440         }
 441 
 442         /* read the data */
 443         cli();
 444         i = 0;
 445         do {
 446                 j = 0;
 447                 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && j++ < 20000)
 448                         ;
 449                 pcb->data.raw[i++] = inb_command(dev->base_addr);
 450                 if (i > MAX_PCB_DATA)
 451                         INVALID_PCB_MSG(i);
 452         } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
 453         sti();
 454         if (j >= 20000) {
 455                 TIMEOUT_MSG(__LINE__);
 456                 return FALSE;
 457         }
 458 
 459         /* woops, the last "data" byte was really the length! */
 460         total_length = pcb->data.raw[--i];
 461 
 462         /* safety check total length vs data length */
 463         if (total_length != (pcb->length + 2)) {
 464                 if (elp_debug >= 2)
 465                         printk("%s: mangled PCB received\n", dev->name);
 466                 set_hsf(dev->base_addr,HSF_PCB_NAK);
 467                 return FALSE;
 468         }
 469 
 470         set_hsf(dev->base_addr,HSF_PCB_ACK);
 471         reset_count=0;
 472         return TRUE;
 473 }
 474 
 475 static void
 476 adapter_hard_reset (struct device * dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 477 {
 478         int timeout;
 479 
 480         CHECK_NULL(dev);
 481 
 482         if (elp_debug > 0)
 483                 printk("%s: Resetting the adapter, please wait (approx 20 s)\n",
 484                         dev->name);
 485         /*
 486          * take FLSH and ATTN high
 487          */
 488         outb_control(ATTN|FLSH, dev->base_addr);
 489 
 490         /*
 491          * wait for a little bit
 492          */
 493         for (timeout = jiffies + 20; jiffies <= timeout; )
 494                 ;
 495 
 496         /*
 497          * now take them low
 498          */
 499         outb_control(0, dev->base_addr);
 500 
 501         /*
 502          * wait for a little bit
 503          */
 504         for (timeout = jiffies + 20; jiffies <= timeout; )
 505                 ;
 506 
 507         /*
 508          * now hang around until the board gets it's act together
 509          */
 510         for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
 511                 if (GET_ASF(dev->base_addr) != ASF_PCB_END)
 512                         break;
 513 }
 514 
 515 /******************************************************
 516  *
 517  *  queue a receive command on the adapter so we will get an
 518  *  interrupt when a packet is received.
 519  *
 520  ******************************************************/
 521 
 522 static int
 523 start_receive (struct device * dev, pcb_struct * tx_pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
 524 {
 525         CHECK_NULL(dev);
 526         CHECK_NULL(tx_pcb);
 527 
 528         if (elp_debug >= 3)
 529                 printk("%s: restarting receiver\n", dev->name);
 530         tx_pcb->command = CMD_RECEIVE_PACKET;
 531         tx_pcb->length = sizeof(struct Rcv_pkt);
 532         tx_pcb->data.rcv_pkt.buf_seg
 533                 = tx_pcb->data.rcv_pkt.buf_ofs = 0; /* Unused */
 534         tx_pcb->data.rcv_pkt.buf_len = 1600;
 535         tx_pcb->data.rcv_pkt.timeout = 0;       /* set timeout to zero */
 536         return send_pcb(dev, tx_pcb); 
 537 }
 538 
 539 /******************************************************
 540  *
 541  * extract a packet from the adapter
 542  * this routine is only called from within the interrupt
 543  * service routine, so no cli/sti calls are needed
 544  * note that the length is always assumed to be even
 545  *
 546  ******************************************************/
 547 
 548 static void
 549 receive_packet (struct device * dev, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 550 {
 551         register int i;
 552         unsigned short * ptr;
 553         int timeout;
 554         int rlen;
 555         struct sk_buff *skb;
 556         elp_device * adapter;
 557 
 558         CHECK_NULL(dev);
 559         adapter=dev->priv;
 560 
 561         if (len <= 0 || ((len & ~1) != len))
 562                 if (elp_debug >= 3) {
 563                         sti();
 564                         printk("*** bad packet len %d at %s(%d)\n",len,filename,__LINE__);
 565                         cli();
 566                 }
 567 
 568         rlen = (len+1) & ~1;
 569 
 570         skb = dev_alloc_skb(rlen+2);
 571 
 572         /*
 573          * make sure the data register is going the right way
 574          */
 575 
 576         outb_control(inb_control(dev->base_addr)|DIR, dev->base_addr);
 577 
 578         /*
 579          * if buffer could not be allocated, swallow it
 580          */
 581         if (skb == NULL) {
 582                 for (i = 0; i < (rlen/2); i++) {
 583                         timeout = 0;
 584                         while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
 585                                 ;
 586                         if (timeout >= 20000) {
 587                                 sti();
 588                                 TIMEOUT_MSG(__LINE__);
 589                                 break;
 590                         }
 591 
 592                         inw_data(dev->base_addr);
 593                 }
 594                 adapter->stats.rx_dropped++;
 595 
 596         } else {
 597                 skb_reserve(skb,2);     /* 16 byte alignment */
 598                 skb->dev = dev;
 599 
 600                 /*
 601                  * now read the data from the adapter
 602                  */
 603                 ptr = (unsigned short *)skb_put(skb,len);
 604                 for (i = 0; i < (rlen/2); i++) { 
 605                         timeout = 0;
 606                         while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000) 
 607                                 ;
 608                         if (timeout >= 20000) {
 609                                 sti();
 610                                 printk("*** timeout at %s(%d) reading word %d of %d ***\n",
 611                                         filename,__LINE__, i, rlen/2);  
 612                                 kfree_skb(skb, FREE_WRITE);
 613                                 return;
 614                         }
 615 
 616                         *ptr = inw_data(dev->base_addr); 
 617                         ptr++; 
 618                 }
 619 
 620                 sti();
 621                 skb->protocol=eth_type_trans(skb,dev);
 622                 netif_rx(skb);
 623         }
 624 
 625         outb_control(inb_control(dev->base_addr)&~DIR, dev->base_addr);
 626 }
 627 
 628 
 629 /******************************************************
 630  *
 631  * interrupt handler
 632  *
 633  ******************************************************/
 634 
 635 static void
 636 elp_interrupt (int irq, struct pt_regs *reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 637 {
 638         int len;
 639         int dlen;
 640         struct device *dev;
 641         elp_device * adapter;
 642         int timeout;
 643 
 644         if (irq < 0 || irq > 15) {
 645                 printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
 646                 return;
 647         }
 648 
 649         dev = irq2dev_map[irq];
 650 
 651         if (dev == NULL) {
 652                 printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
 653                 return;
 654         }
 655 
 656         adapter = (elp_device *) dev->priv;
 657 
 658         CHECK_NULL(adapter);
 659 
 660         if (dev->interrupt)
 661                 if (elp_debug >= 2)
 662                         printk("%s: Re-entering the interrupt handler.\n", dev->name);
 663         dev->interrupt = 1;
 664 
 665         /*
 666          * allow interrupts (we need timers!)
 667          */
 668         sti();
 669 
 670         /*
 671          * receive a PCB from the adapter
 672          */
 673         timeout = jiffies + 3;
 674         while ((inb_status(dev->base_addr)&ACRF) != 0 && jiffies < timeout) {
 675 
 676                 if (receive_pcb(dev, &adapter->irx_pcb)) {
 677 
 678                         switch (adapter->irx_pcb.command) {
 679 
 680                                 /*
 681                                  * received a packet - this must be handled fast
 682                                  */
 683                                 case CMD_RECEIVE_PACKET_COMPLETE:
 684                                         /* if the device isn't open, don't pass packets up the stack */
 685                                         if (dev->start == 0)
 686                                                 break;
 687                                         cli();
 688                                         /* Set direction of adapter FIFO */
 689                                         outb_control(inb_control(dev->base_addr)|DIR,
 690                                                      dev->base_addr);
 691                                         len = adapter->irx_pcb.data.rcv_resp.pkt_len;
 692                                         dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
 693                                         if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
 694                                                 printk("%s: interrupt - packet not received correctly\n", dev->name);
 695                                                 sti();
 696                                         } else {
 697                                                 if (elp_debug >= 3) {
 698                                                         sti();
 699                                                         printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
 700                                                         cli();
 701                                                 }
 702                                                 receive_packet(dev, dlen);
 703                                                 sti();
 704                                                 if (elp_debug >= 3)
 705                                                         printk("%s: packet received\n", dev->name);
 706                                         }
 707                                         if (dev->start && !start_receive(dev, &adapter->itx_pcb)) 
 708                                                 if (elp_debug >= 2)
 709                                                         printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
 710                                         if (elp_debug >= 3)
 711                                         printk("%s: receive procedure complete\n", dev->name);
 712 
 713                                         break;
 714 
 715                                 /*
 716                                  * 82586 configured correctly
 717                                  */
 718                                 case CMD_CONFIGURE_82586_RESPONSE:
 719                                         adapter->got[CMD_CONFIGURE_82586] = 1;
 720                                         if (elp_debug >= 3)
 721                                                 printk("%s: interrupt - configure response received\n", dev->name);
 722                                         break;
 723 
 724                                 /*
 725                                  * Adapter memory configuration
 726                                  */
 727                                 case CMD_CONFIGURE_ADAPTER_RESPONSE:
 728                                         adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
 729                                         if (elp_debug >= 3)
 730                                                 printk("%s: Adapter memory configuration %s.\n",dev->name,
 731                                                         adapter->irx_pcb.data.failed?"failed":"succeeded");
 732                                         break;
 733 
 734                                 /*
 735                                  * Multicast list loading
 736                                  */
 737                                 case CMD_LOAD_MULTICAST_RESPONSE:
 738                                         adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
 739                                         if (elp_debug >= 3)
 740                                                 printk("%s: Multicast address list loading %s.\n",dev->name,
 741                                                         adapter->irx_pcb.data.failed?"failed":"succeeded");
 742                                         break;
 743 
 744                                 /*
 745                                  * Station address setting
 746                                  */
 747                                 case CMD_SET_ADDRESS_RESPONSE:
 748                                         adapter->got[CMD_SET_STATION_ADDRESS] = 1;
 749                                         if (elp_debug >= 3)
 750                                                 printk("%s: Ethernet address setting %s.\n",dev->name,
 751                                                         adapter->irx_pcb.data.failed?"failed":"succeeded");
 752                                         break;
 753 
 754 
 755                                 /*
 756                                  * received board statistics
 757                                  */
 758                                 case CMD_NETWORK_STATISTICS_RESPONSE:
 759                                         adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
 760                                         adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
 761                                         adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
 762                                         adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
 763                                         adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
 764                                         adapter->got[CMD_NETWORK_STATISTICS] = 1;
 765                                         if (elp_debug >= 3)
 766                                                 printk("%s: interrupt - statistics response received\n", dev->name);
 767                                         break;
 768 
 769                                 /*
 770                                  * sent a packet
 771                                  */
 772                                 case CMD_TRANSMIT_PACKET_COMPLETE:
 773                                         if (elp_debug >= 3) 
 774                                         printk("%s: interrupt - packet sent\n", dev->name);
 775                                         if (dev->start == 0)
 776                                                 break;
 777                                         if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
 778                                                 if (elp_debug >= 2)
 779                                                         printk("%s: interrupt - error sending packet %4.4x\n",
 780                                                                 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
 781                                         dev->tbusy = 0;
 782                                         mark_bh(NET_BH);
 783                                         break;
 784 
 785                                 /*
 786                                  * some unknown PCB
 787                                  */
 788                                 default:
 789                                         printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
 790                                         break;
 791                         }
 792                 } else {
 793                         printk("%s: failed to read PCB on interrupt\n", dev->name);
 794                         adapter_reset(dev);
 795                 }
 796         }
 797 
 798         /*
 799          * indicate no longer in interrupt routine
 800          */
 801         dev->interrupt = 0;
 802 }
 803 
 804 
 805 /******************************************************
 806  *
 807  * open the board
 808  *
 809  ******************************************************/
 810 
 811 static int
 812 elp_open (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 813 {
 814         elp_device * adapter;
 815 
 816         CHECK_NULL(dev);
 817 
 818         adapter = dev->priv;
 819 
 820         if (elp_debug >= 3)  
 821                 printk("%s: request to open device\n", dev->name);
 822 
 823         /*
 824          * make sure we actually found the device
 825          */
 826         if (adapter == NULL) {
 827                 printk("%s: Opening a non-existent physical device\n", dev->name);
 828                 return -EAGAIN;
 829         }
 830 
 831         /*
 832          * disable interrupts on the board
 833          */
 834         outb_control(0x00, dev->base_addr);
 835 
 836         /*
 837          * clear any pending interrupts
 838          */
 839         inb_command(dev->base_addr);
 840         adapter_reset(dev);
 841 
 842         /*
 843          * interrupt routine not entered
 844          */
 845         dev->interrupt = 0;
 846 
 847         /*
 848          *  transmitter not busy 
 849          */
 850         dev->tbusy = 0;
 851 
 852         /*
 853          * make sure we can find the device header given the interrupt number
 854          */
 855         irq2dev_map[dev->irq] = dev;
 856 
 857         /*
 858          * install our interrupt service routine
 859          */
 860         if (request_irq(dev->irq, &elp_interrupt, 0, "3c505")) {
 861                 irq2dev_map[dev->irq] = NULL;
 862                 return -EAGAIN;
 863         }
 864 
 865         /*
 866          * enable interrupts on the board
 867          */
 868         outb_control(CMDE, dev->base_addr);
 869 
 870         /*
 871          * device is now officially open!
 872          */
 873         dev->start = 1;
 874 
 875         /*
 876          * configure adapter memory: we need 10 multicast addresses, default==0
 877          */
 878         if (elp_debug >= 3)
 879                 printk("%s: sending 3c505 memory configuration command\n", dev->name);
 880         adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
 881         adapter->tx_pcb.data.memconf.cmd_q = 10;
 882         adapter->tx_pcb.data.memconf.rcv_q = 20;
 883         adapter->tx_pcb.data.memconf.mcast = 10;
 884         adapter->tx_pcb.data.memconf.frame = 20;
 885         adapter->tx_pcb.data.memconf.rcv_b = 20;
 886         adapter->tx_pcb.data.memconf.progs = 0;
 887         adapter->tx_pcb.length = sizeof(struct Memconf);
 888         adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
 889         if (!send_pcb(dev, &adapter->tx_pcb))
 890                 printk("%s: couldn't send memory configuration command\n", dev->name);
 891         else {
 892                 int timeout = jiffies + TIMEOUT;
 893                 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
 894                         ;
 895                 if (jiffies >= timeout)
 896                         TIMEOUT_MSG(__LINE__);
 897         }
 898 
 899 
 900         /*
 901          * configure adapter to receive broadcast messages and wait for response
 902          */
 903         if (elp_debug >= 3)
 904                 printk("%s: sending 82586 configure command\n", dev->name);
 905         adapter->tx_pcb.command = CMD_CONFIGURE_82586;
 906         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
 907         adapter->tx_pcb.length  = 2;
 908         adapter->got[CMD_CONFIGURE_82586] = 0;
 909         if (!send_pcb(dev, &adapter->tx_pcb))
 910                 printk("%s: couldn't send 82586 configure command\n", dev->name);
 911         else {
 912                 int timeout = jiffies + TIMEOUT;
 913                 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
 914                         ;
 915                 if (jiffies >= timeout)
 916                         TIMEOUT_MSG(__LINE__);
 917         }
 918 
 919         /*
 920          * queue receive commands to provide buffering
 921          */
 922         if (!start_receive(dev, &adapter->tx_pcb))
 923                 printk("%s: start receive command failed \n", dev->name);
 924         if (elp_debug >= 3)
 925                 printk("%s: start receive command sent\n", dev->name);
 926 
 927 #ifdef MODULE
 928         MOD_INC_USE_COUNT;
 929 #endif
 930 
 931         return 0;                       /* Always succeed */
 932 }
 933 
 934 
 935 /******************************************************
 936  *
 937  * send a packet to the adapter
 938  *
 939  ******************************************************/
 940 
 941 static int
 942 send_packet (struct device * dev, unsigned char * ptr, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 943 {
 944         int i;
 945         int timeout = 0;
 946         elp_device * adapter;
 947 
 948         /*
 949          * make sure the length is even and no shorter than 60 bytes
 950          */
 951         unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
 952 
 953         CHECK_NULL(dev);
 954         CHECK_NULL(ptr);
 955 
 956         adapter = dev->priv;
 957 
 958         if (nlen < len)
 959                 printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
 960 
 961         /*
 962          * send the adapter a transmit packet command. Ignore segment and offset
 963          * and make sure the length is even
 964          */
 965         adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
 966         adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
 967         adapter->tx_pcb.data.xmit_pkt.buf_ofs
 968                 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0; /* Unused */
 969         adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
 970         if (!send_pcb(dev, &adapter->tx_pcb)) {
 971                 return FALSE;
 972         }
 973 
 974         /*
 975          * write data to the adapter
 976          */
 977         cli();
 978         for (i = 0; i < (nlen/2);i++) {
 979                 while (((inb_status(dev->base_addr)&HRDY) == 0)
 980                        && (timeout++ < 20000))
 981                         ;
 982                 if (timeout >= 20000) {
 983                         sti();
 984                         printk("%s: timeout at %s(%d) writing word %d of %d ***\n",
 985                                 dev->name,filename,__LINE__, i, nlen/2);
 986                         return FALSE;
 987                 }
 988 
 989                 outw_data(*(short *)ptr, dev->base_addr);
 990                 ptr +=2;
 991         }
 992         sti();
 993 
 994         return TRUE;
 995 }
 996 
 997 /******************************************************
 998  *
 999  * start the transmitter
1000  *    return 0 if sent OK, else return 1
1001  *
1002  ******************************************************/
1003 
1004 static int
1005 elp_start_xmit (struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1006 {
1007         CHECK_NULL(dev);
1008 
1009         /*
1010          * not sure what this does, but the 3c509 driver does it, so...
1011          */
1012         if (skb == NULL) {
1013                 dev_tint(dev);
1014                 return 0;
1015         }
1016 
1017         /*
1018          * if we ended up with a munged length, don't send it
1019          */
1020         if (skb->len <= 0)
1021                 return 0;
1022 
1023         if (elp_debug >= 3)
1024                 printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1025 
1026         /*
1027          * if the transmitter is still busy, we have a transmit timeout...
1028          */
1029         if (dev->tbusy) {
1030                 int tickssofar = jiffies - dev->trans_start;
1031                 int stat;
1032                 if (tickssofar < 50) /* was 500, AJT */
1033                         return 1;
1034                 printk("%s: transmit timed out, not resetting adapter\n", dev->name);
1035                 if (((stat=inb_status(dev->base_addr))&ACRF) != 0) 
1036                         printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1037                 printk("%s: status %#02x\n", dev->name, stat);
1038                 dev->trans_start = jiffies;
1039                 dev->tbusy = 0;
1040         }
1041 
1042         /*
1043          * send the packet at skb->data for skb->len
1044          */
1045         if (!send_packet(dev, skb->data, skb->len)) {
1046                 printk("%s: send packet PCB failed\n", dev->name);
1047                 return 1;
1048         }
1049 
1050         if (elp_debug >= 3)
1051                 printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1052 
1053 
1054         /*
1055          * start the transmit timeout
1056          */
1057         dev->trans_start = jiffies;
1058 
1059         /*
1060          * the transmitter is now busy
1061          */
1062         dev->tbusy = 1;
1063 
1064         /*
1065          * free the buffer
1066          */
1067         dev_kfree_skb(skb, FREE_WRITE);
1068 
1069         return 0;
1070 }
1071 
1072 /******************************************************
1073  *
1074  * return statistics on the board
1075  *
1076  ******************************************************/
1077 
1078 static struct enet_statistics *
1079 elp_get_stats (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1080 {
1081         elp_device *adapter = (elp_device *) dev->priv;
1082 
1083         if (elp_debug >= 3)
1084                 printk("%s: request for stats\n", dev->name);
1085 
1086         /* If the device is closed, just return the latest stats we have,
1087            - we cannot ask from the adapter without interrupts */
1088         if (!dev->start)
1089                 return &adapter->stats;
1090 
1091         /* send a get statistics command to the board */
1092         adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1093         adapter->tx_pcb.length  = 0;
1094         adapter->got[CMD_NETWORK_STATISTICS] = 0;
1095         if (!send_pcb(dev, &adapter->tx_pcb))
1096                 printk("%s: couldn't send get statistics command\n", dev->name);
1097         else {
1098                 int timeout = jiffies + TIMEOUT;
1099                 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1100                         ;
1101                 if (jiffies >= timeout) {
1102                         TIMEOUT_MSG(__LINE__);
1103                         return &adapter->stats;
1104                 }
1105         }
1106 
1107         /* statistics are now up to date */
1108         return &adapter->stats;
1109 }
1110 
1111 /******************************************************
1112  *
1113  * close the board
1114  *
1115  ******************************************************/
1116 
1117 static int
1118 elp_close (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1119 {
1120         elp_device * adapter;
1121 
1122         CHECK_NULL(dev);
1123         adapter = dev->priv;
1124         CHECK_NULL(adapter);
1125 
1126         if (elp_debug >= 3)
1127                 printk("%s: request to close device\n", dev->name);
1128 
1129         /* Someone may request the device statistic information even when
1130          * the interface is closed. The following will update the statistics
1131          * structure in the driver, so we'll be able to give current statistics.
1132          */
1133         (void) elp_get_stats(dev);
1134 
1135         /*
1136          * disable interrupts on the board
1137          */
1138         outb_control(0x00, dev->base_addr);
1139 
1140         /*
1141          *  flag transmitter as busy (i.e. not available)
1142          */
1143         dev->tbusy = 1;
1144 
1145         /*
1146          *  indicate device is closed
1147          */
1148         dev->start = 0;
1149 
1150         /*
1151          * release the IRQ
1152          */
1153         free_irq(dev->irq);
1154 
1155         /*
1156          * and we no longer have to map irq to dev either
1157          */
1158         irq2dev_map[dev->irq] = 0;
1159 
1160 #ifdef MODULE
1161         MOD_DEC_USE_COUNT;
1162 #endif
1163 
1164         return 0;
1165 }
1166 
1167 
1168 /************************************************************
1169  *
1170  * Set multicast list
1171  * num_addrs==0: clear mc_list
1172  * num_addrs==-1: set promiscuous mode
1173  * num_addrs>0: set mc_list
1174  *
1175  ************************************************************/
1176 
1177 static void
1178 elp_set_mc_list (struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1179 {
1180         elp_device *adapter = (elp_device *) dev->priv;
1181         int i;
1182 
1183         if (elp_debug >= 3)
1184                 printk("%s: request to set multicast list\n", dev->name);
1185 
1186         if (num_addrs != -1) {
1187                 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1188                 /* if num_addrs==0 the list will be cleared */
1189                 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1190                 adapter->tx_pcb.length  = 6*num_addrs;
1191                 for (i=0;i<num_addrs;i++)
1192                         memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1193                 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1194                 if (!send_pcb(dev, &adapter->tx_pcb))
1195                         printk("%s: couldn't send set_multicast command\n", dev->name);
1196                 else {
1197                         int timeout = jiffies + TIMEOUT;
1198                         while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1199                                 ;
1200                         if (jiffies >= timeout) {
1201                                 TIMEOUT_MSG(__LINE__);
1202                         }
1203                 }
1204                 if (num_addrs)
1205                         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1206                 else /* num_addrs == 0 */
1207                         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1208         } else /* num_addrs == -1 */
1209                 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1210         /*
1211          * configure adapter to receive messages (as specified above)
1212          * and wait for response
1213          */
1214         if (elp_debug >= 3)
1215                 printk("%s: sending 82586 configure command\n", dev->name);
1216         adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1217         adapter->tx_pcb.length  = 2;
1218         adapter->got[CMD_CONFIGURE_82586]  = 0;
1219         if (!send_pcb(dev, &adapter->tx_pcb))
1220                 printk("%s: couldn't send 82586 configure command\n", dev->name);
1221         else {
1222                 int timeout = jiffies + TIMEOUT;
1223                 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1224                         ;
1225                 if (jiffies >= timeout)
1226                         TIMEOUT_MSG(__LINE__);
1227         }
1228 }
1229 
1230 /******************************************************
1231  *
1232  * initialise Etherlink Plus board
1233  *
1234  ******************************************************/
1235 
1236 static void
1237 elp_init (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1238 {
1239         elp_device * adapter;
1240 
1241         CHECK_NULL(dev);
1242 
1243         /*
1244          * set ptrs to various functions
1245          */
1246         dev->open = elp_open;   /* local */
1247         dev->stop = elp_close;  /* local */
1248         dev->get_stats = elp_get_stats; /* local */
1249         dev->hard_start_xmit = elp_start_xmit;  /* local */
1250         dev->set_multicast_list = elp_set_mc_list;      /* local */
1251 
1252         /* Setup the generic properties */
1253         ether_setup(dev);
1254 
1255         /*
1256          * setup ptr to adapter specific information
1257          */
1258         adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1259         CHECK_NULL(adapter);
1260         if (adapter == NULL)
1261                 return -ENOMEM;
1262         memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1263 
1264         /*
1265          * memory information
1266          */
1267         dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1268 }
1269 
1270 /************************************************************
1271  *
1272  * A couple of tests to see if there's 3C505 or not
1273  * Called only by elp_autodetect
1274  ************************************************************/
1275 
1276 static int
1277 elp_sense (struct device * dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1278 {
1279         int timeout;
1280         int addr=dev->base_addr;
1281         const char *name=dev->name;
1282 
1283         byte orig_HCR=inb_control(addr),
1284                 orig_HSR=inb_status(addr);
1285 
1286         if (elp_debug > 0)
1287                 printk(search_msg, name, addr);
1288 
1289         if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1290             ((orig_HCR & DIR) != (orig_HSR & DIR))) {
1291                 if (elp_debug > 0)
1292                         printk(notfound_msg, 1);
1293                 return -1; /* It can't be 3c505 if HCR.DIR != HSR.DIR */
1294         }
1295 
1296         /* Wait for a while; the adapter may still be booting up */
1297         if (elp_debug > 0)
1298                 printk(stilllooking_msg);
1299         for (timeout = jiffies + (100 * 15); jiffies <= timeout; ) 
1300                 if (GET_ASF(addr) != ASF_PCB_END)
1301                         break;
1302 
1303         if (orig_HCR & DIR) {
1304                 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1305                 outb_control(orig_HCR & ~DIR,addr);
1306                 timeout = jiffies+30;
1307                 while (jiffies < timeout)
1308                         ;
1309                 if (inb_status(addr) & DIR) {
1310                         outb_control(orig_HCR,addr);
1311                         if (elp_debug > 0)
1312                                 printk(notfound_msg, 2);
1313                         return -1;
1314                 }
1315         } else {
1316                 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1317                 outb_control(orig_HCR | DIR,addr);
1318                 timeout = jiffies+300;
1319                 while (jiffies < timeout)
1320                         ;
1321                 if (!(inb_status(addr) & DIR)) {
1322                         outb_control(orig_HCR,addr);
1323                         if (elp_debug > 0)
1324                                 printk(notfound_msg, 3);
1325                         return -1;
1326                 }
1327         }
1328         /*
1329          * It certainly looks like a 3c505. If it has DMA enabled, it needs
1330          * a hard reset. Also, do a hard reset if selected at the compile time.
1331          */
1332         if (elp_debug > 0)
1333                         printk(found_msg);
1334 
1335         if (((orig_HCR==0x35) && (orig_HSR==0x5b)) || ELP_NEED_HARD_RESET)
1336                 adapter_hard_reset(dev);
1337         return 0;
1338 }
1339 
1340 /*************************************************************
1341  *
1342  * Search through addr_list[] and try to find a 3C505
1343  * Called only by eplus_probe
1344  *************************************************************/
1345 
1346 static int
1347 elp_autodetect (struct device * dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1348 {
1349         int idx=0;
1350 
1351         /* if base address set, then only check that address
1352         otherwise, run through the table */
1353         if (dev->base_addr != 0) { /* dev->base_addr == 0 ==> plain autodetect */
1354                 if (elp_sense(dev) == 0)
1355                         return dev->base_addr;
1356         } else while ( (dev->base_addr=addr_list[idx++]) ) {
1357                 if (elp_sense(dev) == 0)
1358                         return dev->base_addr;
1359         }
1360 
1361         /* could not find an adapter */
1362         if (elp_debug > 0)
1363                 printk(couldnot_msg, dev->name);
1364 
1365         return 0; /* Because of this, the layer above will return -ENODEV */
1366 }
1367 
1368 /******************************************************
1369  *
1370  * probe for an Etherlink Plus board at the specified address
1371  *
1372  ******************************************************/
1373 
1374 int
1375 elplus_probe (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1376 {
1377         elp_device adapter;
1378         int i;
1379 
1380         CHECK_NULL(dev);
1381 
1382         /*
1383          *  setup adapter structure
1384          */
1385 
1386         dev->base_addr = elp_autodetect(dev);
1387         if ( !(dev->base_addr) )
1388                 return -ENODEV;
1389 
1390         /*
1391          *  As we enter here from bootup, the adapter should have IRQs enabled,
1392          *  but we can as well enable them anyway.
1393          */
1394         outb_control(inb_control(dev->base_addr) | CMDE, dev->base_addr);
1395         autoirq_setup(0);
1396 
1397         /*
1398          * use ethernet address command to probe for board in polled mode
1399          * (this also makes us the IRQ that we need for automatic detection)
1400          */
1401         adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1402         adapter.tx_pcb.length  = 0;
1403         if (!send_pcb   (dev, &adapter.tx_pcb) ||
1404             !receive_pcb(dev, &adapter.rx_pcb) ||
1405             (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1406             (adapter.rx_pcb.length != 6)) {
1407                 printk("%s: not responding to first PCB\n", dev->name);
1408                 return -ENODEV;
1409         }
1410 
1411         if (dev->irq) { /* Is there a preset IRQ? */
1412                 if (dev->irq != autoirq_report(0)) {
1413                         printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1414                         return -ENODEV;
1415                 }
1416                 /* if dev->irq == autoirq_report(0), all is well */
1417         } else /* No preset IRQ; just use what we can detect */
1418                 dev->irq=autoirq_report(0);
1419         switch (dev->irq) { /* Legal, sane? */
1420                 case 0:
1421                         printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1422                         printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1423                         return -ENODEV;
1424                 case 1:
1425                 case 6:
1426                 case 8:
1427                 case 13: 
1428                         printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1429                                dev->name, dev->irq);
1430                         return -ENODEV;
1431         }
1432         /*
1433          *  Now we have the IRQ number so we can disable the interrupts from
1434          *  the board until the board is opened.
1435          */
1436         outb_control(inb_control(dev->base_addr) & ~CMDE, dev->base_addr);
1437 
1438         /*
1439          * copy ethernet address into structure
1440          */
1441         for (i = 0; i < 6; i++) 
1442                 dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1443 
1444         /*
1445          * print remainder of startup message
1446          */
1447         printk("%s: 3c505 card found at I/O %#lx using IRQ%d"
1448                " has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1449                dev->name, dev->base_addr, dev->irq,
1450                dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1451                dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1452 
1453         /*
1454          * and reserve the address region
1455          */
1456         request_region(dev->base_addr, ELP_IO_EXTENT, "3c505");
1457 
1458         /*
1459          * initialise the device
1460          */
1461         elp_init(dev);
1462         return 0;
1463 }
1464 #ifdef MODULE
1465 char kernel_version[] = UTS_RELEASE;
1466 static char devicename[9] = { 0, };
1467 static struct device dev_3c505 = {
1468         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
1469         0, 0, 0, 0,
1470         0, 0,
1471         0, 0, 0, NULL, elplus_probe };
1472 
1473 int io = 0x300;
1474 int irq = 0;
1475 
1476 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1477 {
1478         if (io == 0)
1479                 printk("3c505: You should not use auto-probing with insmod!\n");
1480         dev_3c505.base_addr = io;
1481         dev_3c505.irq       = irq;
1482         if (register_netdev(&dev_3c505) != 0) {
1483                 printk("3c505: register_netdev() returned non-zero.\n");
1484                 return -EIO;
1485         }
1486         return 0;
1487 }
1488 
1489 void
1490 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1491 {
1492         if (MOD_IN_USE)
1493                 printk("3c505: device busy, remove delayed\n");
1494         else
1495         {
1496                 unregister_netdev(&dev_3c505);
1497                 kfree(dev_3c505.priv);
1498                 dev_3c505.priv = NULL;
1499 
1500                 /* If we don't do this, we can't re-insmod it later. */
1501                 release_region(dev_3c505.base_addr, ELP_IO_EXTENT);
1502         }
1503 }
1504 #endif /* MODULE */

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