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