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

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