root/drivers/net/ewrk3.c

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

DEFINITIONS

This source file includes following definitions.
  1. ewrk3_probe
  2. ewrk3_hw_init
  3. ewrk3_open
  4. ewrk3_init
  5. ewrk3_queue_pkt
  6. ewrk3_interrupt
  7. ewrk3_rx
  8. ewrk3_tx
  9. ewrk3_close
  10. ewrk3_get_stats
  11. set_multicast_list
  12. SetMulticastFilter
  13. isa_probe
  14. eisa_probe
  15. alloc_device
  16. Read_EEPROM
  17. Write_EEPROM
  18. EthwrkSignature
  19. DevicePresent
  20. get_hw_addr
  21. EISA_signature
  22. ewrk3_ioctl
  23. init_module
  24. cleanup_module

   1 /*  ewrk3.c: A DIGITAL EtherWORKS 3 ethernet driver for Linux.
   2 
   3     Written 1994 by David C. Davies.
   4 
   5     Copyright 1994 Digital Equipment Corporation.
   6 
   7     This software may be used and distributed according to the terms of
   8     the GNU Public License, incorporated herein by reference.
   9 
  10     This driver is written for the Digital Equipment Corporation series
  11     of EtherWORKS ethernet cards:
  12 
  13         DE203 Turbo (BNC)
  14         DE204 Turbo (TP)
  15         DE205 Turbo (TP BNC)
  16 
  17     The driver has been tested on a relatively busy  network using the DE205
  18     card and benchmarked with 'ttcp': it transferred 16M  of data at 975kB/s
  19     (7.8Mb/s) to a DECstation 5000/200.
  20 
  21     The     author  may  be    reached    at  davies@wanton.lkg.dec.com   or
  22     davies@maniac.ultranet.com or  Digital  Equipment Corporation,  550 King
  23     Street, Littleton MA 01460.
  24 
  25     =========================================================================
  26     This driver has been written  substantially  from scratch, although  its
  27     inheritance of style and stack interface from 'depca.c' and in turn from
  28     Donald Becker's 'lance.c' should be obvious.
  29 
  30     The  DE203/4/5 boards  all  use a new proprietary   chip in place of the
  31     LANCE chip used in prior cards  (DEPCA, DE100, DE200/1/2, DE210, DE422).
  32     Use the depca.c driver in the standard distribution  for the LANCE based
  33     cards from DIGITAL; this driver will not work with them.
  34 
  35     The DE203/4/5 cards have 2  main modes: shared memory  and I/O only. I/O
  36     only makes  all the card accesses through  I/O transactions and  no high
  37     (shared)  memory is used. This  mode provides a >48% performance penalty
  38     and  is deprecated in this  driver,  although allowed to provide initial
  39     setup when hardstrapped.
  40 
  41     The shared memory mode comes in 3 flavours: 2kB, 32kB and 64kB. There is
  42     no point in using any mode other than the 2kB  mode - their performances
  43     are virtually identical, although the driver has  been tested in the 2kB
  44     and 32kB modes. I would suggest you uncomment the line:
  45 
  46                              FORCE_2K_MODE;
  47 
  48     to allow the driver to configure the card as a  2kB card at your current
  49     base  address, thus leaving more  room to clutter  your  system box with
  50     other memory hungry boards.
  51 
  52     As many ISA  and EISA cards  can be supported  under this driver  as you
  53     wish, limited primarily  by the available IRQ lines,  rather than by the
  54     available I/O addresses  (24 ISA,  16 EISA).   I have  checked different
  55     configurations of  multiple  depca cards and  ewrk3 cards  and have  not
  56     found a problem yet (provided you have at least depca.c v0.38) ...
  57 
  58     The board IRQ setting   must be at  an unused  IRQ which is  auto-probed
  59     using  Donald  Becker's autoprobe  routines.   All  these cards   are at
  60     {5,10,11,15}.
  61 
  62     No 16MB memory  limitation should exist with this  driver as DMA is  not
  63     used and the common memory area is in low memory on the network card (my
  64     current system has 20MB and I've not had problems yet).
  65 
  66     The ability to load  this driver as a  loadable module has been included
  67     and used  extensively during the  driver development (to save those long
  68     reboot sequences). To utilise this ability, you have to do 8 things:
  69 
  70     0) have a copy of the loadable modules code installed on your system.
  71     1) copy ewrk3.c from the  /linux/drivers/net directory to your favourite
  72     temporary directory.
  73     2) edit the  source code near  line 1880 to reflect  the I/O address and
  74     IRQ you're using.
  75     3) compile  ewrk3.c, but include -DMODULE in  the command line to ensure
  76     that the correct bits are compiled (see end of source code).
  77     4) if you are wanting to add a new  card, goto 5. Otherwise, recompile a
  78     kernel with the ewrk3 configuration turned off and reboot.
  79     5) insmod ewrk3.o
  80           [Alan Cox: Changed this so you can insmod ewrk3.o irq=x io=y]
  81     6) run the net startup bits for your new eth?? interface manually 
  82     (usually /etc/rc.inet[12] at boot time). 
  83     7) enjoy!
  84 
  85     Note that autoprobing is not allowed in loadable modules - the system is
  86     already up and running and you're messing with interrupts.
  87 
  88     To unload a module, turn off the associated interface 
  89     'ifconfig eth?? down' then 'rmmod ewrk3'.
  90 
  91     Promiscuous   mode has been  turned  off  in this driver,   but  all the
  92     multicast  address bits  have been   turned on. This  improved the  send
  93     performance on a busy network by about 13%.
  94 
  95     Ioctl's have now been provided (primarily because  I wanted to grab some
  96     packet size statistics). They  are patterned after 'plipconfig.c' from a
  97     suggestion by Alan Cox.  Using these  ioctls, you can enable promiscuous
  98     mode, add/delete multicast  addresses, change the hardware address,  get
  99     packet size distribution statistics and muck around with the control and
 100     status register. I'll add others if and when the need arises.
 101 
 102     TO DO:
 103     ------
 104 
 105 
 106     Revision History
 107     ----------------
 108 
 109     Version   Date        Description
 110   
 111       0.1     26-aug-94   Initial writing. ALPHA code release.
 112       0.11    31-aug-94   Fixed: 2k mode memory base calc., 
 113                                  LeMAC version calc.,
 114                                  IRQ vector assignments during autoprobe.
 115       0.12    31-aug-94   Tested working on LeMAC2 (DE20[345]-AC) card.
 116                           Fixed up MCA hash table algorithm.
 117       0.20     4-sep-94   Added IOCTL functionality.
 118       0.21    14-sep-94   Added I/O mode.
 119       0.21axp 15-sep-94   Special version for ALPHA AXP Linux V1.0.
 120       0.22    16-sep-94   Added more IOCTLs & tidied up.
 121       0.23    21-sep-94   Added transmit cut through.
 122       0.24    31-oct-94   Added uid checks in some ioctls.
 123       0.30     1-nov-94   BETA code release.
 124       0.31     5-dec-94   Added check/allocate region code.
 125       0.32    16-jan-95   Broadcast packet fix.
 126       0.33    10-Feb-95   Fix recognition bug reported by <bkm@star.rl.ac.uk>.
 127       0.40    27-Dec-95   Rationalise MODULE and autoprobe code.
 128                           Rewrite for portability & updated.
 129                           ALPHA support from <jestabro@amt.tay1.dec.com>
 130                           Added verify_area() calls in depca_ioctl() from
 131                           suggestion by <heiko@colossus.escape.de>.
 132                           Add new multicasting code.
 133       0.41    20-Jan-96   Fix IRQ set up problem reported by <???>.
 134 
 135     =========================================================================
 136 */
 137 
 138 static const char *version = "ewrk3.c:v0.41 96/1/20 davies@wanton.lkg.dec.com\n";
 139 
 140 #include <linux/module.h>
 141 
 142 #include <linux/kernel.h>
 143 #include <linux/sched.h>
 144 #include <linux/string.h>
 145 #include <linux/ptrace.h>
 146 #include <linux/errno.h>
 147 #include <linux/ioport.h>
 148 #include <linux/malloc.h>
 149 #include <linux/interrupt.h>
 150 #include <linux/delay.h>
 151 #include <asm/bitops.h>
 152 #include <asm/io.h>
 153 #include <asm/dma.h>
 154 #include <asm/segment.h>
 155 
 156 #include <linux/netdevice.h>
 157 #include <linux/etherdevice.h>
 158 #include <linux/skbuff.h>
 159 
 160 #include <linux/time.h>
 161 #include <linux/types.h>
 162 #include <linux/unistd.h>
 163 
 164 #include "ewrk3.h"
 165 
 166 #ifdef EWRK3_DEBUG
 167 static int ewrk3_debug = EWRK3_DEBUG;
 168 #else
 169 static int ewrk3_debug = 1;
 170 #endif
 171 
 172 #define EWRK3_NDA 0xffe0            /* No Device Address */
 173 
 174 #define PROBE_LENGTH    32
 175 #define ETH_PROM_SIG    0xAA5500FFUL
 176 
 177 #ifndef EWRK3_SIGNATURE
 178 #define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}
 179 #define EWRK3_STRLEN 8
 180 #endif
 181 
 182 #ifndef EWRK3_RAM_BASE_ADDRESSES
 183 #define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}
 184 #endif
 185 
 186 /*
 187 ** Sets up the I/O area for the autoprobe.
 188 */
 189 #define EWRK3_IO_BASE 0x100             /* Start address for probe search */
 190 #define EWRK3_IOP_INC 0x20              /* I/O address increment */
 191 #define EWRK3_TOTAL_SIZE 0x20           /* required I/O address length */
 192 
 193 #ifndef MAX_NUM_EWRK3S
 194 #define MAX_NUM_EWRK3S 21
 195 #endif
 196 
 197 #ifndef EWRK3_EISA_IO_PORTS 
 198 #define EWRK3_EISA_IO_PORTS 0x0c00      /* I/O port base address, slot 0 */
 199 #endif
 200 
 201 #ifndef MAX_EISA_SLOTS
 202 #define MAX_EISA_SLOTS 16
 203 #define EISA_SLOT_INC 0x1000
 204 #endif
 205 
 206 #define CRC_POLYNOMIAL_BE 0x04c11db7UL   /* Ethernet CRC, big endian */
 207 #define CRC_POLYNOMIAL_LE 0xedb88320UL   /* Ethernet CRC, little endian */
 208 
 209 #define QUEUE_PKT_TIMEOUT (1*HZ)         /* Jiffies */
 210 
 211 /*
 212 ** EtherWORKS 3 shared memory window sizes
 213 */
 214 #define IO_ONLY         0x00
 215 #define SHMEM_2K        0x800
 216 #define SHMEM_32K       0x8000
 217 #define SHMEM_64K       0x10000
 218 
 219 /*
 220 ** EtherWORKS 3 IRQ ENABLE/DISABLE
 221 */
 222 #define ENABLE_IRQs { \
 223   icr |= lp->irq_mask;\
 224   outb(icr, EWRK3_ICR);                     /* Enable the IRQs */\
 225 }
 226 
 227 #define DISABLE_IRQs { \
 228   icr = inb(EWRK3_ICR);\
 229   icr &= ~lp->irq_mask;\
 230   outb(icr, EWRK3_ICR);                     /* Disable the IRQs */\
 231 }
 232 
 233 /*
 234 ** EtherWORKS 3 START/STOP
 235 */
 236 #define START_EWRK3 { \
 237   csr = inb(EWRK3_CSR);\
 238   csr &= ~(CSR_TXD|CSR_RXD);\
 239   outb(csr, EWRK3_CSR);                     /* Enable the TX and/or RX */\
 240 }
 241 
 242 #define STOP_EWRK3 { \
 243   csr = (CSR_TXD|CSR_RXD);\
 244   outb(csr, EWRK3_CSR);                     /* Disable the TX and/or RX */\
 245 }
 246 
 247 /*
 248 ** The EtherWORKS 3 private structure
 249 */
 250 #define EWRK3_PKT_STAT_SZ 16
 251 #define EWRK3_PKT_BIN_SZ  128           /* Should be >=100 unless you
 252                                            increase EWRK3_PKT_STAT_SZ */
 253 
 254 struct ewrk3_private {
 255     char adapter_name[80];              /* Name exported to /proc/ioports */
 256     u_long shmem_base;                  /* Shared memory start address */
 257     u_long shmem_length;                /* Shared memory window length */
 258     struct enet_statistics stats;       /* Public stats */
 259     struct {
 260       u32 bins[EWRK3_PKT_STAT_SZ]; /* Private stats counters */
 261       u32 unicast;
 262       u32 multicast;
 263       u32 broadcast;
 264       u32 excessive_collisions;
 265       u32 tx_underruns;
 266       u32 excessive_underruns;
 267     } pktStats;
 268     u_char irq_mask;                    /* Adapter IRQ mask bits */
 269     u_char mPage;                       /* Maximum 2kB Page number */
 270     u_char lemac;                       /* Chip rev. level */
 271     u_char hard_strapped;               /* Don't allow a full open */
 272     u_char lock;                        /* Lock the page register */
 273     u_char txc;                         /* Transmit cut through */
 274     u_char *mctbl;                      /* Pointer to the multicast table */
 275 };
 276 
 277 /*
 278 ** Force the EtherWORKS 3 card to be in 2kB MODE
 279 */
 280 #define FORCE_2K_MODE { \
 281   shmem_length = SHMEM_2K;\
 282   outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\
 283 }
 284 
 285 /*
 286 ** Public Functions
 287 */
 288 static int    ewrk3_open(struct device *dev);
 289 static int    ewrk3_queue_pkt(struct sk_buff *skb, struct device *dev);
 290 static void   ewrk3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 291 static int    ewrk3_close(struct device *dev);
 292 static struct enet_statistics *ewrk3_get_stats(struct device *dev);
 293 static void   set_multicast_list(struct device *dev);
 294 static int    ewrk3_ioctl(struct device *dev, struct ifreq *rq, int cmd);
 295 
 296 /*
 297 ** Private functions
 298 */
 299 static int    ewrk3_hw_init(struct device *dev, u_long iobase);
 300 static void   ewrk3_init(struct device *dev);
 301 static int    ewrk3_rx(struct device *dev);
 302 static int    ewrk3_tx(struct device *dev);
 303 
 304 static void   EthwrkSignature(char * name, char *eeprom_image);
 305 static int    DevicePresent(u_long iobase);
 306 static void   SetMulticastFilter(struct device *dev);
 307 static int    EISA_signature(char *name, s32 eisa_id);
 308 
 309 static int    Read_EEPROM(u_long iobase, u_char eaddr);
 310 static int    Write_EEPROM(short data, u_long iobase, u_char eaddr);
 311 static u_char get_hw_addr (struct device *dev, u_char *eeprom_image, char chipType);
 312 
 313 static void   isa_probe(struct device *dev, u_long iobase);
 314 static void   eisa_probe(struct device *dev, u_long iobase);
 315 static struct device *alloc_device(struct device *dev, u_long iobase);
 316 
 317 
 318 #ifdef MODULE
 319 int  init_module(void);
 320 void cleanup_module(void);
 321 static int autoprobed = 1, loading_module = 1;
 322 
 323 # else
 324 static u_char irq[] = {5,0,10,3,11,9,15,12};
 325 static int autoprobed = 0, loading_module = 0;
 326 
 327 #endif /* MODULE */
 328 
 329 static char name[EWRK3_STRLEN + 1];
 330 static int num_ewrk3s = 0, num_eth = 0;
 331 
 332 /*
 333 ** Miscellaneous defines...
 334 */
 335 #define INIT_EWRK3 {\
 336     outb(EEPROM_INIT, EWRK3_IOPR);\
 337     udelay(1000);\
 338 }
 339 
 340 
 341 
 342 
 343 int ewrk3_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 344 {
 345   int tmp = num_ewrk3s, status = -ENODEV;
 346   u_long iobase = dev->base_addr;
 347 
 348   if ((iobase == 0) && loading_module){
 349     printk("Autoprobing is not supported when loading a module based driver.\n");
 350     status = -EIO;
 351   } else {                              /* First probe for the Ethernet */
 352                                         /* Address PROM pattern */
 353     isa_probe(dev, iobase);
 354     eisa_probe(dev, iobase);
 355 
 356     if ((tmp == num_ewrk3s) && (iobase != 0) && loading_module) {
 357       printk("%s: ewrk3_probe() cannot find device at 0x%04lx.\n", dev->name, 
 358                                                                        iobase);
 359     }
 360 
 361     /*
 362     ** Walk the device list to check that at least one device
 363     ** initialised OK
 364     */
 365     for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
 366 
 367     if (dev->priv) status = 0;
 368     if (iobase == 0) autoprobed = 1;
 369   }
 370 
 371   return status;
 372 }
 373 
 374 static int
 375 ewrk3_hw_init(struct device *dev, u_long iobase)
     /* [previous][next][first][last][top][bottom][index][help] */
 376 {
 377   struct ewrk3_private *lp;
 378   int i, status=0;
 379   u_long mem_start, shmem_length;
 380   u_char cr, cmr, icr, nicsr, lemac, hard_strapped = 0;
 381   u_char eeprom_image[EEPROM_MAX], chksum, eisa_cr = 0;
 382 
 383   /*
 384   ** Stop the EWRK3. Enable the DBR ROM. Disable interrupts and remote boot.
 385   ** This also disables the EISA_ENABLE bit in the EISA Control Register.
 386   */
 387   if (iobase > 0x400) eisa_cr = inb(EISA_CR);
 388   INIT_EWRK3;
 389 
 390   nicsr = inb(EWRK3_CSR);
 391 
 392   icr = inb(EWRK3_ICR);
 393   icr &= 0x70;
 394   outb(icr, EWRK3_ICR);                           /* Disable all the IRQs */
 395 
 396   if (nicsr == CSR_TXD|CSR_RXD) {
 397 
 398     /* Check that the EEPROM is alive and well and not living on Pluto... */
 399     for (chksum=0, i=0; i<EEPROM_MAX; i+=2) {
 400       union {
 401         short val;
 402         char c[2];
 403       } tmp;
 404 
 405       tmp.val = (short)Read_EEPROM(iobase, (i>>1));
 406       eeprom_image[i] = tmp.c[0];
 407       eeprom_image[i+1] = tmp.c[1];
 408       chksum += eeprom_image[i] + eeprom_image[i+1];
 409     }
 410 
 411     if (chksum != 0) {                             /* Bad EEPROM Data! */
 412       printk("%s: Device has a bad on-board EEPROM.\n", dev->name);
 413       status = -ENXIO;
 414     } else {
 415       EthwrkSignature(name, eeprom_image);
 416       if (*name != '\0') {                         /* found a EWRK3 device */
 417         dev->base_addr = iobase;
 418       
 419         if (iobase > 0x400) {
 420           outb(eisa_cr, EISA_CR);                  /* Rewrite the EISA CR */
 421         }
 422 
 423         lemac = eeprom_image[EEPROM_CHIPVER];
 424         cmr = inb(EWRK3_CMR);
 425 
 426         if (((lemac == LeMAC) && ((cmr & CMR_NO_EEPROM) != CMR_NO_EEPROM)) ||
 427             ((lemac == LeMAC2) && !(cmr & CMR_HS))) {
 428           printk("%s: %s at %#4lx", dev->name, name, iobase);
 429           hard_strapped = 1;
 430         } else if ((iobase&0x0fff)==EWRK3_EISA_IO_PORTS) {
 431                                                    /* EISA slot address */
 432           printk("%s: %s at %#4lx (EISA slot %ld)", 
 433                                  dev->name, name, iobase, ((iobase>>12)&0x0f));
 434         } else {                                   /* ISA port address */
 435           printk("%s: %s at %#4lx", dev->name, name, iobase);
 436         }
 437         
 438         if (!status) {
 439           printk(", h/w address ");
 440           if (lemac!=LeMAC2) DevicePresent(iobase);/* need after EWRK3_INIT */
 441           status = get_hw_addr(dev, eeprom_image, lemac);
 442           for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet addr. */
 443             printk("%2.2x:", dev->dev_addr[i]);
 444           }
 445           printk("%2.2x,\n", dev->dev_addr[i]);
 446 
 447           if (status) {
 448             printk("      which has an EEPROM CRC error.\n");
 449             status = -ENXIO;
 450           } else {
 451             if (lemac == LeMAC2) {            /* Special LeMAC2 CMR things */
 452               cmr &= ~(CMR_RA | CMR_WB | CMR_LINK | CMR_POLARITY | CMR_0WS);
 453               if (eeprom_image[EEPROM_MISC0] & READ_AHEAD)    cmr |= CMR_RA;
 454               if (eeprom_image[EEPROM_MISC0] & WRITE_BEHIND)  cmr |= CMR_WB;
 455               if (eeprom_image[EEPROM_NETMAN0] & NETMAN_POL)  cmr |= CMR_POLARITY;
 456               if (eeprom_image[EEPROM_NETMAN0] & NETMAN_LINK) cmr |= CMR_LINK;
 457               if (eeprom_image[EEPROM_MISC0] & _0WS_ENA)      cmr |= CMR_0WS;
 458             }
 459             if (eeprom_image[EEPROM_SETUP] & SETUP_DRAM)      cmr |= CMR_DRAM;
 460             outb(cmr, EWRK3_CMR);
 461 
 462             cr = inb(EWRK3_CR);               /* Set up the Control Register */
 463             cr |= eeprom_image[EEPROM_SETUP] & SETUP_APD;
 464             if (cr & SETUP_APD) cr |= eeprom_image[EEPROM_SETUP] & SETUP_PS;
 465             cr |= eeprom_image[EEPROM_MISC0] & FAST_BUS;
 466             cr |= eeprom_image[EEPROM_MISC0] & ENA_16;
 467             outb(cr, EWRK3_CR);
 468 
 469             /* 
 470             ** Determine the base address and window length for the EWRK3
 471             ** RAM from the memory base register.
 472             */
 473             mem_start = inb(EWRK3_MBR);
 474             shmem_length = 0;
 475             if (mem_start != 0) {
 476               if ((mem_start >= 0x0a) && (mem_start <= 0x0f)) {
 477                 mem_start *= SHMEM_64K;
 478                 shmem_length = SHMEM_64K;
 479               } else if ((mem_start >= 0x14) && (mem_start <= 0x1f)) {
 480                 mem_start *= SHMEM_32K;
 481                 shmem_length = SHMEM_32K;
 482               } else if ((mem_start >= 0x40) && (mem_start <= 0xff)) {
 483                 mem_start = mem_start * SHMEM_2K + 0x80000;
 484                 shmem_length = SHMEM_2K;
 485               } else {
 486                 status = -ENXIO;
 487               }
 488             }
 489           
 490             /*
 491             ** See the top of this source code for comments about
 492             ** uncommenting this line.
 493             */
 494 /*          FORCE_2K_MODE;*/
 495 
 496             if (!status) {
 497               if (hard_strapped) {
 498                 printk("      is hard strapped.\n");
 499               } else if (mem_start) {
 500                 printk("      has a %dk RAM window", (int)(shmem_length >> 10));
 501                 printk(" at 0x%.5lx", mem_start);
 502               } else {
 503                 printk("      is in I/O only mode");
 504               }
 505             
 506               /* private area & initialise */
 507               dev->priv = (void *) kmalloc(sizeof(struct ewrk3_private), 
 508                                                                    GFP_KERNEL);
 509               if (dev->priv == NULL) {
 510                 return -ENOMEM;
 511               }
 512               lp = (struct ewrk3_private *)dev->priv;
 513               memset(dev->priv, 0, sizeof(struct ewrk3_private));
 514               lp->shmem_base = mem_start;
 515               lp->shmem_length = shmem_length;
 516               lp->lemac = lemac;
 517               lp->hard_strapped = hard_strapped;
 518 
 519               lp->mPage = 64;
 520               if (cmr & CMR_DRAM) lp->mPage <<= 1 ;/* 2 DRAMS on module */ 
 521 
 522               sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
 523               request_region(iobase, EWRK3_TOTAL_SIZE, lp->adapter_name);
 524 
 525               lp->irq_mask = ICR_TNEM|ICR_TXDM|ICR_RNEM|ICR_RXDM;
 526               
 527               if (!hard_strapped) {
 528                 /*
 529                 ** Enable EWRK3 board interrupts for autoprobing
 530                 */
 531                 icr |= ICR_IE;                     /* Enable interrupts */
 532                 outb(icr, EWRK3_ICR);
 533             
 534                 /* The DMA channel may be passed in on this parameter. */
 535                 dev->dma = 0;
 536         
 537                 /* To auto-IRQ we enable the initialization-done and DMA err,
 538                    interrupts. For now we will always get a DMA error. */
 539                 if (dev->irq < 2) {
 540 #ifndef MODULE
 541                   u_char irqnum;
 542               
 543                   autoirq_setup(0);
 544 
 545                   /* 
 546                   ** Trigger a TNE interrupt.
 547                   */
 548                   icr |=ICR_TNEM;
 549                   outb(1,EWRK3_TDQ);          /* Write to the TX done queue */
 550                   outb(icr, EWRK3_ICR);       /* Unmask the TXD interrupt */
 551               
 552                   irqnum = irq[((icr & IRQ_SEL) >> 4)];
 553               
 554                   dev->irq = autoirq_report(1);
 555                   if ((dev->irq) && (irqnum == dev->irq)) {
 556                     printk(" and uses IRQ%d.\n", dev->irq);
 557                   } else {
 558                     if (!dev->irq) {
 559                       printk(" and failed to detect IRQ line.\n");
 560                     } else if ((irqnum == 1) && (lemac == LeMAC2)) {
 561                       printk(" and an illegal IRQ line detected.\n");
 562                     } else {
 563                       printk(", but incorrect IRQ line detected.\n");
 564                     }
 565                     status = -ENXIO;
 566                   }
 567                 
 568                   DISABLE_IRQs;                 /* Mask all interrupts */
 569 
 570 #endif /* MODULE */
 571                 } else {
 572                   printk(" and requires IRQ%d.\n", dev->irq);
 573                 }
 574               }
 575               if (status) release_region(iobase, EWRK3_TOTAL_SIZE);
 576             } else {
 577               status = -ENXIO;
 578             }
 579           }
 580         }
 581       } else {
 582         status = -ENXIO;
 583       }
 584     }
 585 
 586     if (!status) {
 587       if (ewrk3_debug > 0) {
 588         printk(version);
 589       }
 590       
 591       /* The EWRK3-specific entries in the device structure. */
 592       dev->open = &ewrk3_open;
 593       dev->hard_start_xmit = &ewrk3_queue_pkt;
 594       dev->stop = &ewrk3_close;
 595       dev->get_stats = &ewrk3_get_stats;
 596       dev->set_multicast_list = &set_multicast_list;
 597       dev->do_ioctl = &ewrk3_ioctl;
 598 
 599       dev->mem_start = 0;
 600         
 601       /* Fill in the generic field of the device structure. */
 602       ether_setup(dev);
 603     }
 604   } else {
 605     status = -ENXIO;
 606   }
 607 
 608   return status;
 609 }
 610 
 611 
 612 static int
 613 ewrk3_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
 616   u_long iobase = dev->base_addr;
 617   int i, status = 0;
 618   u_char icr, csr;
 619 
 620   /*
 621   ** Stop the TX and RX...
 622   */
 623   STOP_EWRK3;
 624 
 625   if (!lp->hard_strapped) {
 626     irq2dev_map[dev->irq] = dev;                   /* For latched interrupts */
 627 
 628     if (request_irq(dev->irq, (void *)ewrk3_interrupt, 0, "ewrk3", NULL)) {
 629       printk("ewrk3_open(): Requested IRQ%d is busy\n",dev->irq);
 630       status = -EAGAIN;
 631     } else {
 632 
 633       /* 
 634       ** Re-initialize the EWRK3... 
 635       */
 636       ewrk3_init(dev);
 637 
 638       if (ewrk3_debug > 1){
 639         printk("%s: ewrk3 open with irq %d\n",dev->name,dev->irq);
 640         printk("  physical address: ");
 641         for (i=0;i<5;i++){
 642           printk("%2.2x:",(u_char)dev->dev_addr[i]);
 643         }
 644         printk("%2.2x\n",(u_char)dev->dev_addr[i]);
 645         if (lp->shmem_length == 0) {
 646           printk("  no shared memory, I/O only mode\n");
 647         } else {
 648           printk("  start of shared memory: 0x%08lx\n",lp->shmem_base);
 649           printk("  window length: 0x%04lx\n",lp->shmem_length);
 650         }
 651         printk("  # of DRAMS: %d\n",((inb(EWRK3_CMR) & 0x02) ? 2 : 1));
 652         printk("  csr:  0x%02x\n", inb(EWRK3_CSR));
 653         printk("  cr:   0x%02x\n", inb(EWRK3_CR));
 654         printk("  icr:  0x%02x\n", inb(EWRK3_ICR));
 655         printk("  cmr:  0x%02x\n", inb(EWRK3_CMR));
 656         printk("  fmqc: 0x%02x\n", inb(EWRK3_FMQC));
 657       }
 658 
 659       dev->tbusy = 0;                         
 660       dev->start = 1;
 661       dev->interrupt = UNMASK_INTERRUPTS;
 662 
 663       /*
 664       ** Unmask EWRK3 board interrupts
 665       */
 666       icr = inb(EWRK3_ICR);
 667       ENABLE_IRQs;
 668 
 669     }
 670   } else {
 671     dev->start = 0;
 672     dev->tbusy = 1;
 673     printk("%s: ewrk3 available for hard strapped set up only.\n", dev->name);
 674     printk("      Run the 'ewrk3setup' utility or remove the hard straps.\n");
 675   }
 676 
 677   MOD_INC_USE_COUNT;
 678 
 679   return status;
 680 }
 681 
 682 /*
 683 ** Initialize the EtherWORKS 3 operating conditions
 684 */
 685 static void
 686 ewrk3_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 687 {
 688   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
 689   u_char csr, page;
 690   u_long iobase = dev->base_addr;
 691   
 692   /* 
 693   ** Enable any multicasts 
 694   */
 695   set_multicast_list(dev);
 696 
 697   /*
 698   ** Clean out any remaining entries in all the queues here
 699   */
 700   while (inb(EWRK3_TQ));
 701   while (inb(EWRK3_TDQ));
 702   while (inb(EWRK3_RQ));
 703   while (inb(EWRK3_FMQ));
 704 
 705   /*
 706   ** Write a clean free memory queue
 707   */
 708   for (page=1;page<lp->mPage;page++) {      /* Write the free page numbers */
 709     outb(page, EWRK3_FMQ);                  /* to the Free Memory Queue */
 710   }
 711 
 712   lp->lock = 0;                             /* Ensure there are no locks */
 713 
 714   START_EWRK3;                              /* Enable the TX and/or RX */
 715 }
 716 
 717 /* 
 718 ** Writes a socket buffer to the free page queue
 719 */
 720 static int
 721 ewrk3_queue_pkt(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 722 {
 723   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
 724   u_long iobase = dev->base_addr;
 725   int status = 0;
 726   u_char icr, csr;
 727 
 728   /* Transmitter timeout, serious problems. */
 729   if (dev->tbusy || lp->lock) {
 730     int tickssofar = jiffies - dev->trans_start;
 731     if (tickssofar < QUEUE_PKT_TIMEOUT) {
 732       status = -1;
 733     } else if (!lp->hard_strapped) {
 734       printk("%s: transmit timed/locked out, status %04x, resetting.\n",
 735                                                    dev->name, inb(EWRK3_CSR));
 736         
 737       /*
 738       ** Mask all board interrupts
 739       */
 740       DISABLE_IRQs;
 741 
 742       /*
 743       ** Stop the TX and RX...
 744       */
 745       STOP_EWRK3;
 746 
 747       ewrk3_init(dev);
 748 
 749       /*
 750       ** Unmask EWRK3 board interrupts
 751       */
 752       ENABLE_IRQs;
 753 
 754       dev->tbusy=0;
 755       dev->trans_start = jiffies;
 756     }
 757   } else if (skb == NULL) {
 758     dev_tint(dev);
 759   } else if (skb->len > 0) {
 760 
 761     /* 
 762     ** Block a timer-based transmit from overlapping.  This could better be
 763     ** done with atomic_swap(1, dev->tbusy), but set_bit() works as well. 
 764     */
 765     if (set_bit(0, (void*)&dev->tbusy) != 0)
 766       printk("%s: Transmitter access conflict.\n", dev->name);
 767 
 768     DISABLE_IRQs;                      /* So that the page # remains correct */
 769     
 770     /* 
 771     ** Get a free page from the FMQ when resources are available
 772     */
 773     if (inb(EWRK3_FMQC) > 0) {
 774       u_long buf = 0;
 775       u_char page;
 776 
 777       if ((page = inb(EWRK3_FMQ)) < lp->mPage) {
 778         /*
 779         ** Set up shared memory window and pointer into the window
 780         */
 781         while (set_bit(0, (void *)&lp->lock) != 0); /* Wait for lock to free */
 782         if (lp->shmem_length == IO_ONLY) {
 783           outb(page, EWRK3_IOPR);
 784         } else if (lp->shmem_length == SHMEM_2K) {
 785           buf = lp->shmem_base;
 786           outb(page, EWRK3_MPR);
 787         } else if (lp->shmem_length == SHMEM_32K) {
 788           buf = ((((short)page << 11) & 0x7800) + lp->shmem_base);
 789           outb((page >> 4), EWRK3_MPR);
 790         } else if (lp->shmem_length == SHMEM_64K) {
 791           buf = ((((short)page << 11) & 0xf800) + lp->shmem_base);
 792           outb((page >> 5), EWRK3_MPR);
 793         } else {
 794           status = -1;
 795           printk("%s: Oops - your private data area is hosed!\n",dev->name);
 796         }
 797 
 798         if (!status) {
 799 
 800           /* 
 801           ** Set up the buffer control structures and copy the data from
 802           ** the socket buffer to the shared memory .
 803           */
 804 
 805           if (lp->shmem_length == IO_ONLY) {
 806             int i;
 807             u_char *p = skb->data;
 808             
 809             outb((char)(TCR_QMODE | TCR_PAD | TCR_IFC), EWRK3_DATA);
 810             outb((char)(skb->len & 0xff), EWRK3_DATA);
 811             outb((char)((skb->len >> 8) & 0xff), EWRK3_DATA);
 812             outb((char)0x04, EWRK3_DATA);
 813             for (i=0; i<skb->len; i++) {
 814               outb(*p++, EWRK3_DATA);
 815             }
 816             outb(page, EWRK3_TQ);                      /* Start sending pkt */
 817           } else {
 818             writeb((char)(TCR_QMODE|TCR_PAD|TCR_IFC), (char *)buf);/* ctrl byte*/
 819             buf+=1;
 820             writeb((char)(skb->len & 0xff), (char *)buf);/* length (16 bit xfer)*/
 821             buf+=1;
 822             if (lp->txc) {
 823               writeb((char)(((skb->len >> 8) & 0xff) | XCT), (char *)buf);
 824               buf+=1;
 825               writeb(0x04, (char *)buf);               /* index byte */
 826               buf+=1;
 827               writeb(0x00, (char *)(buf + skb->len));  /* Write the XCT flag */
 828               memcpy_toio(buf, skb->data, PRELOAD);/* Write PRELOAD bytes*/
 829               outb(page, EWRK3_TQ);                    /* Start sending pkt */
 830               memcpy_toio(buf+PRELOAD, skb->data+PRELOAD, skb->len-PRELOAD);
 831               writeb(0xff, (char *)(buf + skb->len));  /* Write the XCT flag */
 832             } else {
 833               writeb((char)((skb->len >> 8) & 0xff), (char *)buf);
 834               buf+=1;
 835               writeb(0x04, (char *)buf);               /* index byte */
 836               buf+=1;
 837               memcpy_toio((char *)buf, skb->data, skb->len);/* Write data bytes */
 838               outb(page, EWRK3_TQ);                    /* Start sending pkt */
 839             }
 840           }
 841 
 842           dev->trans_start = jiffies;
 843           dev_kfree_skb (skb, FREE_WRITE);
 844 
 845         } else {              /* return unused page to the free memory queue */
 846           outb(page, EWRK3_FMQ);
 847         }
 848         lp->lock = 0;         /* unlock the page register */
 849       } else {
 850         printk("ewrk3_queue_pkt(): Invalid free memory page (%d).\n",
 851                                                          (u_char) page);
 852       }
 853     } else {
 854       printk("ewrk3_queue_pkt(): No free resources...\n");
 855       printk("ewrk3_queue_pkt(): CSR: %02x ICR: %02x FMQC: %02x\n",inb(EWRK3_CSR),inb(EWRK3_ICR),inb(EWRK3_FMQC));
 856     }
 857     
 858     /* Check for free resources: clear 'tbusy' if there are some */
 859     if (inb(EWRK3_FMQC) > 0) {
 860       dev->tbusy = 0;
 861     }
 862 
 863     ENABLE_IRQs;
 864   }
 865 
 866   return status;
 867 }
 868 
 869 /*
 870 ** The EWRK3 interrupt handler. 
 871 */
 872 static void
 873 ewrk3_interrupt(int irq, void *dev_id, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 874 {
 875     struct device *dev = (struct device *)(irq2dev_map[irq]);
 876     struct ewrk3_private *lp;
 877     u_long iobase;
 878     u_char icr, cr, csr;
 879 
 880     if (dev == NULL) {
 881         printk ("ewrk3_interrupt(): irq %d for unknown device.\n", irq);
 882     } else {
 883       lp = (struct ewrk3_private *)dev->priv;
 884       iobase = dev->base_addr;
 885 
 886       if (dev->interrupt)
 887         printk("%s: Re-entering the interrupt handler.\n", dev->name);
 888 
 889       dev->interrupt = MASK_INTERRUPTS;
 890 
 891       /* get the interrupt information */
 892       csr = inb(EWRK3_CSR);
 893 
 894       /* 
 895       ** Mask the EWRK3 board interrupts and turn on the LED 
 896       */
 897       DISABLE_IRQs;
 898 
 899       cr = inb(EWRK3_CR);
 900       cr |= CR_LED;
 901       outb(cr, EWRK3_CR);
 902 
 903       if (csr & CSR_RNE)          /* Rx interrupt (packet[s] arrived) */
 904         ewrk3_rx(dev);
 905 
 906       if (csr & CSR_TNE)          /* Tx interrupt (packet sent) */
 907         ewrk3_tx(dev);
 908 
 909       /*
 910       ** Now deal with the TX/RX disable flags. These are set when there
 911       ** are no more resources. If resources free up then enable these
 912       ** interrupts, otherwise mask them - failure to do this will result
 913       ** in the system hanging in an interrupt loop.
 914       */
 915       if (inb(EWRK3_FMQC)) {      /* any resources available? */
 916         lp->irq_mask |= ICR_TXDM|ICR_RXDM;/* enable the interrupt source */
 917         csr &= ~(CSR_TXD|CSR_RXD);/* ensure restart of a stalled TX or RX */
 918         outb(csr, EWRK3_CSR);
 919         dev->tbusy = 0;           /* clear TX busy flag */
 920         mark_bh(NET_BH);
 921       } else {
 922         lp->irq_mask &= ~(ICR_TXDM|ICR_RXDM);/* disable the interrupt source */
 923       }
 924 
 925       /* Unmask the EWRK3 board interrupts and turn off the LED */
 926       cr &= ~CR_LED;
 927       outb(cr, EWRK3_CR);
 928 
 929       dev->interrupt = UNMASK_INTERRUPTS;
 930       ENABLE_IRQs;
 931     }
 932 
 933     return;
 934 }
 935 
 936 static int
 937 ewrk3_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 938 {
 939   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
 940   u_long iobase = dev->base_addr;
 941   int i, status = 0;
 942   u_char page, tmpPage = 0, tmpLock = 0;
 943   u_long buf = 0;
 944 
 945   while (inb(EWRK3_RQC) && !status) {        /* Whilst there's incoming data */
 946     if ((page = inb(EWRK3_RQ)) < lp->mPage) {/* Get next entry's buffer page */
 947       /*
 948       ** Preempt any process using the current page register. Check for
 949       ** an existing lock to reduce time taken in I/O transactions.
 950       */
 951       if ((tmpLock = set_bit(0, (void *)&lp->lock)) == 1) {   /* Assert lock */
 952         if (lp->shmem_length == IO_ONLY) {              /* Get existing page */
 953           tmpPage = inb(EWRK3_IOPR);
 954         } else {
 955           tmpPage = inb(EWRK3_MPR);
 956         }
 957       }
 958 
 959       /*
 960       ** Set up shared memory window and pointer into the window
 961       */
 962       if (lp->shmem_length == IO_ONLY) {
 963         outb(page, EWRK3_IOPR);
 964       } else if (lp->shmem_length == SHMEM_2K) {
 965         buf = lp->shmem_base;
 966         outb(page, EWRK3_MPR);
 967       } else if (lp->shmem_length == SHMEM_32K) {
 968         buf = ((((short)page << 11) & 0x7800) + lp->shmem_base);
 969         outb((page >> 4), EWRK3_MPR);
 970       } else if (lp->shmem_length == SHMEM_64K) {
 971         buf = ((((short)page << 11) & 0xf800) + lp->shmem_base);
 972         outb((page >> 5), EWRK3_MPR);
 973       } else {
 974         status = -1;
 975         printk("%s: Oops - your private data area is hosed!\n",dev->name);
 976       }
 977 
 978       if (!status) {
 979         char rx_status;
 980         int pkt_len;
 981 
 982         if (lp->shmem_length == IO_ONLY) {
 983           rx_status = inb(EWRK3_DATA);
 984           pkt_len = inb(EWRK3_DATA);
 985           pkt_len |= ((u_short)inb(EWRK3_DATA) << 8);
 986         } else {
 987           rx_status = readb(buf);
 988           buf+=1;
 989           pkt_len = readw(buf);
 990           buf+=3;
 991         }
 992 
 993         if (!(rx_status & R_ROK)) {         /* There was an error. */
 994           lp->stats.rx_errors++;            /* Update the error stats. */
 995           if (rx_status & R_DBE) lp->stats.rx_frame_errors++;
 996           if (rx_status & R_CRC) lp->stats.rx_crc_errors++;
 997           if (rx_status & R_PLL) lp->stats.rx_fifo_errors++;
 998         } else {
 999           struct sk_buff *skb;
1000 
1001           if ((skb = dev_alloc_skb(pkt_len+2)) != NULL) {
1002             unsigned char *p;
1003             skb->dev = dev;
1004             skb_reserve(skb,2);             /* Align to 16 bytes */
1005             p = skb_put(skb,pkt_len);
1006 
1007             if (lp->shmem_length == IO_ONLY) {
1008               *p = inb(EWRK3_DATA);         /* dummy read */
1009               for (i=0; i<pkt_len; i++) {
1010                 *p++ = inb(EWRK3_DATA);
1011               }
1012             } else {
1013               memcpy_fromio(p, buf, pkt_len);
1014             }
1015 
1016             /* 
1017             ** Notify the upper protocol layers that there is another 
1018             ** packet to handle
1019             */
1020             skb->protocol=eth_type_trans(skb,dev);
1021             netif_rx(skb);
1022 
1023             /*
1024             ** Update stats
1025             */
1026             lp->stats.rx_packets++;
1027             for (i=1; i<EWRK3_PKT_STAT_SZ-1; i++) {
1028               if (pkt_len < i*EWRK3_PKT_BIN_SZ) {
1029                 lp->pktStats.bins[i]++;
1030                 i = EWRK3_PKT_STAT_SZ;
1031               }
1032             }
1033             p = skb->data;                  /* Look at the dest addr */
1034             if (p[0] & 0x01) {              /* Multicast/Broadcast */
1035               if ((*(s32 *)&p[0] == -1) && (*(s16 *)&p[4] == -1)) {
1036                 lp->pktStats.broadcast++;
1037               } else {
1038                 lp->pktStats.multicast++;
1039               }
1040             } else if ((*(s32 *)&p[0] == *(s32 *)&dev->dev_addr[0]) &&
1041                        (*(s16 *)&p[4] == *(s16 *)&dev->dev_addr[4])) {
1042               lp->pktStats.unicast++;
1043             }
1044 
1045             lp->pktStats.bins[0]++;           /* Duplicates stats.rx_packets */
1046             if (lp->pktStats.bins[0] == 0) {  /* Reset counters */
1047               memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1048             }
1049           } else {
1050             printk("%s: Insufficient memory; nuking packet.\n", dev->name);
1051             lp->stats.rx_dropped++;           /* Really, deferred. */
1052             break;
1053           }
1054         }
1055       }
1056       /*
1057       ** Return the received buffer to the free memory queue
1058       */
1059       outb(page, EWRK3_FMQ);
1060 
1061       if (tmpLock) {                          /* If a lock was preempted */
1062         if (lp->shmem_length == IO_ONLY) {    /* Replace old page */
1063           outb(tmpPage, EWRK3_IOPR);
1064         } else {
1065           outb(tmpPage, EWRK3_MPR);
1066         }
1067       }
1068       lp->lock = 0;                           /* Unlock the page register */
1069     } else {
1070       printk("ewrk3_rx(): Illegal page number, page %d\n",page);
1071       printk("ewrk3_rx(): CSR: %02x ICR: %02x FMQC: %02x\n",inb(EWRK3_CSR),inb(EWRK3_ICR),inb(EWRK3_FMQC));
1072     }
1073   }
1074   return status;
1075 }
1076 
1077 /*
1078 ** Buffer sent - check for TX buffer errors.
1079 */
1080 static int
1081 ewrk3_tx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1082 {
1083   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1084   u_long iobase = dev->base_addr;
1085   u_char tx_status;
1086 
1087   while ((tx_status = inb(EWRK3_TDQ)) > 0) {  /* Whilst there's old buffers */
1088     if (tx_status & T_VSTS) {                 /* The status is valid */
1089       if (tx_status & T_TXE) {
1090         lp->stats.tx_errors++;
1091         if (tx_status & T_NCL)    lp->stats.tx_carrier_errors++;
1092         if (tx_status & T_LCL)    lp->stats.tx_window_errors++;
1093         if (tx_status & T_CTU) {
1094           if ((tx_status & T_COLL) ^ T_XUR) {
1095             lp->pktStats.tx_underruns++;
1096           } else {
1097             lp->pktStats.excessive_underruns++;
1098           }
1099         } else  if (tx_status & T_COLL) {
1100           if ((tx_status & T_COLL) ^ T_XCOLL) {
1101             lp->stats.collisions++;
1102           } else {
1103             lp->pktStats.excessive_collisions++;
1104           }
1105         }
1106       } else {
1107         lp->stats.tx_packets++;
1108       }
1109     }
1110   }
1111 
1112   return 0;
1113 }
1114 
1115 static int
1116 ewrk3_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1117 {
1118   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1119   u_long iobase = dev->base_addr;
1120   u_char icr, csr;
1121 
1122   dev->start = 0;
1123   dev->tbusy = 1;
1124 
1125   if (ewrk3_debug > 1) {
1126     printk("%s: Shutting down ethercard, status was %2.2x.\n",
1127            dev->name, inb(EWRK3_CSR));
1128   }
1129 
1130   /* 
1131   ** We stop the EWRK3 here... mask interrupts and stop TX & RX
1132   */
1133   DISABLE_IRQs;
1134 
1135   STOP_EWRK3;
1136 
1137   /*
1138   ** Clean out the TX and RX queues here (note that one entry
1139   ** may get added to either the TXD or RX queues if the the TX or RX
1140   ** just starts processing a packet before the STOP_EWRK3 command
1141   ** is received. This will be flushed in the ewrk3_open() call).
1142   */
1143   while (inb(EWRK3_TQ));
1144   while (inb(EWRK3_TDQ));
1145   while (inb(EWRK3_RQ));
1146 
1147   if (!lp->hard_strapped) {
1148     free_irq(dev->irq, NULL);
1149     
1150     irq2dev_map[dev->irq] = 0;
1151   }
1152 
1153   MOD_DEC_USE_COUNT;
1154 
1155   return 0;
1156 }
1157 
1158 static struct enet_statistics *
1159 ewrk3_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1160 {
1161   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1162 
1163   /* Null body since there is no framing error counter */
1164     
1165   return &lp->stats;
1166 }
1167 
1168 /*
1169 ** Set or clear the multicast filter for this adaptor.
1170 */
1171 static void
1172 set_multicast_list(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1173 {
1174   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1175   u_long iobase = dev->base_addr;
1176   u_char csr;
1177 
1178   if (irq2dev_map[dev->irq] != NULL) {
1179     csr = inb(EWRK3_CSR);
1180     
1181     if (lp->shmem_length == IO_ONLY) {
1182       lp->mctbl = (char *) PAGE0_HTE;
1183     } else {
1184       lp->mctbl = (char *)(lp->shmem_base + PAGE0_HTE);
1185     }
1186 
1187     csr &= ~(CSR_PME | CSR_MCE);
1188     if (dev->flags & IFF_PROMISC) {         /* set promiscuous mode */
1189       csr |= CSR_PME;
1190       outb(csr, EWRK3_CSR);
1191     } else {
1192       SetMulticastFilter(dev);
1193       csr |= CSR_MCE;
1194       outb(csr, EWRK3_CSR);
1195     }
1196   }
1197 }
1198 
1199 /*
1200 ** Calculate the hash code and update the logical address filter
1201 ** from a list of ethernet multicast addresses.
1202 ** Little endian crc one liner from Matt Thomas, DEC.
1203 **
1204 ** Note that when clearing the table, the broadcast bit must remain asserted
1205 ** to receive broadcast messages.
1206 */
1207 static void SetMulticastFilter(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1208 {
1209   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1210   struct dev_mc_list *dmi=dev->mc_list;
1211   u_long iobase = dev->base_addr;
1212   int i;
1213   char *addrs, j, bit, byte;
1214   short *p = (short *) lp->mctbl;
1215   u16 hashcode;
1216   s32 crc, poly = CRC_POLYNOMIAL_LE;
1217 
1218   while (set_bit(0, (void *)&lp->lock) != 0); /* Wait for lock to free */
1219 
1220   if (lp->shmem_length == IO_ONLY) {
1221     outb(0, EWRK3_IOPR);
1222     outw(EEPROM_OFFSET(lp->mctbl), EWRK3_PIR1);
1223   } else {
1224     outb(0, EWRK3_MPR);
1225   }
1226 
1227   if (dev->flags & IFF_ALLMULTI) {
1228     for (i=0; i<(HASH_TABLE_LEN >> 3); i++) {
1229       if (lp->shmem_length == IO_ONLY) {
1230         outb(0xff, EWRK3_DATA);
1231       } else {                /* memset didn't work here */
1232         writew(0xffff, p);
1233         p++; i++;
1234       }
1235     }
1236   } else {
1237     /* Clear table except for broadcast bit */
1238     if (lp->shmem_length == IO_ONLY) {
1239       for (i=0; i<(HASH_TABLE_LEN >> 4) - 1; i++) {
1240         outb(0x00, EWRK3_DATA);
1241       } 
1242       outb(0x80, EWRK3_DATA); i++;           /* insert the broadcast bit */
1243       for (; i<(HASH_TABLE_LEN >> 3); i++) {
1244         outb(0x00, EWRK3_DATA);
1245       } 
1246     } else {
1247       memset_io(lp->mctbl, 0, (HASH_TABLE_LEN >> 3));
1248       writeb(0x80, (char *)(lp->mctbl + (HASH_TABLE_LEN >> 4) - 1));
1249     }
1250 
1251     /* Update table */
1252     for (i=0;i<dev->mc_count;i++) {          /* for each address in the list */
1253       addrs=dmi->dmi_addr;
1254       dmi=dmi->next;
1255       if ((*addrs & 0x01) == 1) {            /* multicast address? */ 
1256         crc = 0xffffffff;                    /* init CRC for each address */
1257         for (byte=0;byte<ETH_ALEN;byte++) {  /* for each address byte */
1258                                              /* process each address bit */ 
1259           for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1260             crc = (crc >> 1) ^ (((crc ^ bit) & 0x01) ? poly : 0);
1261           }
1262         }
1263         hashcode = crc & ((1 << 9) - 1);     /* hashcode is 9 LSb of CRC */
1264 
1265         byte = hashcode >> 3;                /* bit[3-8] -> byte in filter */
1266         bit = 1 << (hashcode & 0x07);        /* bit[0-2] -> bit in byte */
1267 
1268         if (lp->shmem_length == IO_ONLY) {
1269           u_char tmp;
1270 
1271           outw((short)((long)lp->mctbl) + byte, EWRK3_PIR1);
1272           tmp = inb(EWRK3_DATA);
1273           tmp |= bit;
1274           outw((short)((long)lp->mctbl) + byte, EWRK3_PIR1);
1275           outb(tmp, EWRK3_DATA); 
1276         } else {
1277           writeb(readb(lp->mctbl + byte) | bit, lp->mctbl + byte);
1278         }
1279       }
1280     }
1281   }
1282 
1283   lp->lock = 0;                              /* Unlock the page register */
1284 
1285   return;
1286 }
1287 
1288 /*
1289 ** ISA bus I/O device probe
1290 */
1291 static void isa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1292 {
1293   int i = num_ewrk3s, maxSlots;
1294   u_long iobase;
1295 
1296   if (!ioaddr && autoprobed) return ;            /* Been here before ! */
1297   if (ioaddr >= 0x400) return;                   /* Not ISA */
1298 
1299   if (ioaddr == 0) {                     /* Autoprobing */
1300     iobase = EWRK3_IO_BASE;              /* Get the first slot address */
1301     maxSlots = 24;
1302   } else {                               /* Probe a specific location */
1303     iobase = ioaddr;
1304     maxSlots = i + 1;
1305   }
1306 
1307   for (; (i<maxSlots) && (dev!=NULL);iobase+=EWRK3_IOP_INC, i++) {
1308     if (!check_region(iobase, EWRK3_TOTAL_SIZE)) {    
1309       if (DevicePresent(iobase) == 0) {
1310         if ((dev = alloc_device(dev, iobase)) != NULL) {
1311           if (ewrk3_hw_init(dev, iobase) == 0) {
1312             num_ewrk3s++;
1313           }
1314           num_eth++;
1315         }
1316       }
1317     } else if (autoprobed) {
1318       printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1319     }
1320   }
1321 
1322   return;
1323 }
1324 
1325 /*
1326 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1327 ** the motherboard.
1328 */
1329 static void eisa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1330 {
1331   int i, maxSlots;
1332   u_long iobase;
1333   char name[EWRK3_STRLEN];
1334 
1335   if (!ioaddr && autoprobed) return ;            /* Been here before ! */
1336   if (ioaddr < 0x1000) return;                   /* Not EISA */
1337 
1338   if (ioaddr == 0) {                     /* Autoprobing */
1339     iobase = EISA_SLOT_INC;              /* Get the first slot address */
1340     i = 1;
1341     maxSlots = MAX_EISA_SLOTS;
1342   } else {                               /* Probe a specific location */
1343     iobase = ioaddr;
1344     i = (ioaddr >> 12);
1345     maxSlots = i + 1;
1346   }
1347 
1348   for (i=1; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1349     if (EISA_signature(name, EISA_ID) == 0) {
1350       if (!check_region(iobase, EWRK3_TOTAL_SIZE)) {
1351         if (DevicePresent(iobase) == 0) {
1352           if ((dev = alloc_device(dev, iobase)) != NULL) {
1353             if (ewrk3_hw_init(dev, iobase) == 0) {
1354               num_ewrk3s++;
1355             }
1356             num_eth++;
1357           }
1358         }
1359       } else if (autoprobed) {
1360         printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1361       }
1362     }
1363   }
1364 
1365   return;
1366 }
1367 
1368 /*
1369 ** Allocate the device by pointing to the next available space in the
1370 ** device structure. Should one not be available, it is created.
1371 */
1372 static struct device *alloc_device(struct device *dev, u_long iobase)
     /* [previous][next][first][last][top][bottom][index][help] */
1373 {
1374   int addAutoProbe = 0;
1375   struct device *tmp = NULL, *ret;
1376   int (*init)(struct device *) = NULL;
1377 
1378   /*
1379   ** Check the device structures for an end of list or unused device
1380   */
1381   if (!loading_module) {
1382     while (dev->next != NULL) {
1383       if ((dev->base_addr == EWRK3_NDA) || (dev->base_addr == 0)) break;
1384       dev = dev->next;                     /* walk through eth device list */
1385       num_eth++;                           /* increment eth device number */
1386     }
1387 
1388     /*
1389     ** If an autoprobe is requested for another device, we must re-insert
1390     ** the request later in the list. Remember the current position first.
1391     */
1392     if ((dev->base_addr == 0) && (num_ewrk3s > 0)) {
1393       addAutoProbe++;
1394       tmp = dev->next;                     /* point to the next device */
1395       init = dev->init;                    /* remember the probe function */
1396     }
1397 
1398     /*
1399     ** If at end of list and can't use current entry, malloc one up. 
1400     ** If memory could not be allocated, print an error message.
1401     */
1402     if ((dev->next == NULL) &&  
1403         !((dev->base_addr == EWRK3_NDA) || (dev->base_addr == 0))){
1404       dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1405                                            GFP_KERNEL);
1406 
1407       dev = dev->next;                     /* point to the new device */
1408       if (dev == NULL) {
1409         printk("eth%d: Device not initialised, insufficient memory\n",
1410                num_eth);
1411       } else {
1412         /*
1413         ** If the memory was allocated, point to the new memory area
1414         ** and initialize it (name, I/O address, next device (NULL) and
1415         ** initialisation probe routine).
1416         */
1417         dev->name = (char *)(dev + sizeof(struct device));
1418         if (num_eth > 9999) {
1419           sprintf(dev->name,"eth????");    /* New device name */
1420         } else {
1421           sprintf(dev->name,"eth%d", num_eth);/* New device name */
1422         }
1423         dev->base_addr = iobase;           /* assign the io address */
1424         dev->next = NULL;                  /* mark the end of list */
1425         dev->init = &ewrk3_probe;          /* initialisation routine */
1426         num_ewrk3s++;
1427       }
1428     }
1429     ret = dev;                             /* return current struct, or NULL */
1430   
1431     /*
1432     ** Now figure out what to do with the autoprobe that has to be inserted.
1433     ** Firstly, search the (possibly altered) list for an empty space.
1434     */
1435     if (ret != NULL) {
1436       if (addAutoProbe) {
1437         for (;(tmp->next!=NULL) && (tmp->base_addr!=EWRK3_NDA); tmp=tmp->next);
1438 
1439         /*
1440         ** If no more device structures and can't use the current one, malloc
1441         ** one up. If memory could not be allocated, print an error message.
1442         */
1443         if ((tmp->next == NULL) && !(tmp->base_addr == EWRK3_NDA)) {
1444           tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1445                                                GFP_KERNEL);
1446           tmp = tmp->next;                     /* point to the new device */
1447           if (tmp == NULL) {
1448             printk("%s: Insufficient memory to extend the device list.\n", 
1449                    dev->name);
1450           } else {
1451             /*
1452             ** If the memory was allocated, point to the new memory area
1453             ** and initialize it (name, I/O address, next device (NULL) and
1454             ** initialisation probe routine).
1455             */
1456             tmp->name = (char *)(tmp + sizeof(struct device));
1457             if (num_eth > 9999) {
1458               sprintf(tmp->name,"eth????");       /* New device name */
1459             } else {
1460               sprintf(tmp->name,"eth%d", num_eth);/* New device name */
1461             }
1462             tmp->base_addr = 0;                /* re-insert the io address */
1463             tmp->next = NULL;                  /* mark the end of list */
1464             tmp->init = init;                  /* initialisation routine */
1465           }
1466         } else {                               /* structure already exists */
1467           tmp->base_addr = 0;                  /* re-insert the io address */
1468         }
1469       }
1470     }
1471   } else {
1472     ret = dev;
1473   }
1474 
1475   return ret;
1476 }
1477 
1478 /*
1479 ** Read the EWRK3 EEPROM using this routine
1480 */
1481 static int Read_EEPROM(u_long iobase, u_char eaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1482 {
1483   int i;
1484 
1485   outb((eaddr & 0x3f), EWRK3_PIR1);     /* set up 6 bits of address info */
1486   outb(EEPROM_RD, EWRK3_IOPR);          /* issue read command */
1487   for (i=0;i<5000;i++) inb(EWRK3_CSR);  /* wait 1msec */
1488 
1489   return inw(EWRK3_EPROM1);             /* 16 bits data return */
1490 }
1491 
1492 /*
1493 ** Write the EWRK3 EEPROM using this routine
1494 */
1495 static int Write_EEPROM(short data, u_long iobase, u_char eaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1496 {
1497   int i;
1498 
1499   outb(EEPROM_WR_EN, EWRK3_IOPR);       /* issue write enable command */
1500   for (i=0;i<5000;i++) inb(EWRK3_CSR);  /* wait 1msec */
1501   outw(data, EWRK3_EPROM1);             /* write data to register */
1502   outb((eaddr & 0x3f), EWRK3_PIR1);     /* set up 6 bits of address info */
1503   outb(EEPROM_WR, EWRK3_IOPR);          /* issue write command */
1504   for (i=0;i<75000;i++) inb(EWRK3_CSR); /* wait 15msec */
1505   outb(EEPROM_WR_DIS, EWRK3_IOPR);      /* issue write disable command */
1506   for (i=0;i<5000;i++) inb(EWRK3_CSR);  /* wait 1msec */
1507 
1508   return 0;
1509 }
1510 
1511 /*
1512 ** Look for a particular board name in the on-board EEPROM.
1513 */
1514 static void EthwrkSignature(char *name, char *eeprom_image)
     /* [previous][next][first][last][top][bottom][index][help] */
1515 {
1516   u_long i,j,k;
1517   char *signatures[] = EWRK3_SIGNATURE;
1518 
1519   strcpy(name, "");
1520   for (i=0;*signatures[i] != '\0' && *name == '\0';i++) {
1521     for (j=EEPROM_PNAME7,k=0;j<=EEPROM_PNAME0 && k<strlen(signatures[i]);j++) {
1522       if (signatures[i][k] == eeprom_image[j]) {          /* track signature */
1523         k++;
1524       } else {                         /* lost signature; begin search again */
1525         k=0;
1526       }
1527     }
1528     if (k == strlen(signatures[i])) {
1529       for (k=0; k<EWRK3_STRLEN; k++) {
1530         name[k] = eeprom_image[EEPROM_PNAME7 + k];
1531         name[EWRK3_STRLEN] = '\0';
1532       }
1533     }
1534   }
1535 
1536   return;                                   /* return the device name string */
1537 }
1538 
1539 /*
1540 ** Look for a special sequence in the Ethernet station address PROM that
1541 ** is common across all EWRK3 products.
1542 ** 
1543 ** Search the Ethernet address ROM for the signature. Since the ROM address
1544 ** counter can start at an arbitrary point, the search must include the entire
1545 ** probe sequence length plus the (length_of_the_signature - 1).
1546 ** Stop the search IMMEDIATELY after the signature is found so that the
1547 ** PROM address counter is correctly positioned at the start of the
1548 ** ethernet address for later read out.
1549 */
1550 
1551 static int DevicePresent(u_long iobase)
     /* [previous][next][first][last][top][bottom][index][help] */
1552 {
1553   union {
1554     struct {
1555       u32 a;
1556       u32 b;
1557     } llsig;
1558     char Sig[sizeof(u32) << 1];
1559   } dev;
1560   short sigLength;
1561   char data;
1562   int i, j, status = 0;
1563 
1564   dev.llsig.a = ETH_PROM_SIG;
1565   dev.llsig.b = ETH_PROM_SIG;
1566   sigLength = sizeof(u32) << 1;
1567 
1568   for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1569     data = inb(EWRK3_APROM);
1570     if (dev.Sig[j] == data) {   /* track signature */
1571       j++;
1572     } else {                    /* lost signature; begin search again */
1573       if (data == dev.Sig[0]) {
1574         j=1;
1575       } else {
1576         j=0;
1577       }
1578     }
1579   }
1580 
1581   if (j!=sigLength) {
1582     status = -ENODEV;           /* search failed */
1583   }
1584 
1585   return status;
1586 }
1587 
1588 static u_char get_hw_addr(struct device *dev, u_char *eeprom_image, char chipType)
     /* [previous][next][first][last][top][bottom][index][help] */
1589 {
1590   int i, j, k;
1591   u_short chksum;
1592   u_char crc, lfsr, sd, status = 0;
1593   u_long iobase = dev->base_addr;
1594   u16 tmp;
1595 
1596   if (chipType == LeMAC2) {
1597     for (crc=0x6a, j=0; j<ETH_ALEN; j++) {
1598       sd = dev->dev_addr[j] = eeprom_image[EEPROM_PADDR0 + j];
1599       outb(dev->dev_addr[j], EWRK3_PAR0 + j);
1600       for (k=0; k<8; k++, sd >>= 1) {
1601         lfsr = ((((crc & 0x02) >> 1) ^ (crc & 0x01)) ^ (sd & 0x01)) << 7;
1602         crc = (crc >> 1) + lfsr;
1603       }
1604     }
1605     if (crc != eeprom_image[EEPROM_PA_CRC]) status = -1;
1606   } else {
1607     for (i=0,k=0;i<ETH_ALEN;) {
1608       k <<= 1 ;
1609       if (k > 0xffff) k-=0xffff;
1610 
1611       k += (u_char) (tmp = inb(EWRK3_APROM));
1612       dev->dev_addr[i] = (u_char) tmp;
1613       outb(dev->dev_addr[i], EWRK3_PAR0 + i);
1614       i++;
1615       k += (u_short) ((tmp = inb(EWRK3_APROM)) << 8);
1616       dev->dev_addr[i] = (u_char) tmp;
1617       outb(dev->dev_addr[i], EWRK3_PAR0 + i);
1618       i++;
1619 
1620       if (k > 0xffff) k-=0xffff;
1621     }
1622     if (k == 0xffff) k=0;
1623     chksum = inb(EWRK3_APROM);
1624     chksum |= (inb(EWRK3_APROM)<<8);
1625     if (k != chksum) status = -1;
1626   }
1627 
1628   return status;
1629 }
1630 
1631 /*
1632 ** Look for a particular board name in the EISA configuration space
1633 */
1634 static int EISA_signature(char *name, s32 eisa_id)
     /* [previous][next][first][last][top][bottom][index][help] */
1635 {
1636   u_long i;
1637   char *signatures[] = EWRK3_SIGNATURE;
1638   char ManCode[EWRK3_STRLEN];
1639   union {
1640     s32 ID;
1641     char Id[4];
1642   } Eisa;
1643   int status = 0;
1644 
1645   *name = '\0';
1646   for (i=0; i<4; i++) {
1647     Eisa.Id[i] = inb(eisa_id + i);
1648   }
1649 
1650   ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1651   ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1652   ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1653   ManCode[3]=((Eisa.Id[2]&0x0f)+0x30);
1654   ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1655   ManCode[5]='\0';
1656 
1657   for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1658     if (strstr(ManCode, signatures[i]) != NULL) {
1659       strcpy(name,ManCode);
1660       status = 1;
1661     }
1662   }
1663 
1664   return status;                           /* return the device name string */
1665 }
1666 
1667 /*
1668 ** Perform IOCTL call functions here. Some are privileged operations and the
1669 ** effective uid is checked in those cases.
1670 */
1671 static int ewrk3_ioctl(struct device *dev, struct ifreq *rq, int cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
1672 {
1673   struct ewrk3_private *lp = (struct ewrk3_private *)dev->priv;
1674   struct ewrk3_ioctl *ioc = (struct ewrk3_ioctl *) &rq->ifr_data;
1675   u_long iobase = dev->base_addr;
1676   int i, j, status = 0;
1677   u_char csr;
1678   union {
1679     u_char addr[HASH_TABLE_LEN * ETH_ALEN];
1680     u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1681   } tmp;
1682 
1683   switch(ioc->cmd) {
1684   case EWRK3_GET_HWADDR:             /* Get the hardware address */
1685     for (i=0; i<ETH_ALEN; i++) {
1686       tmp.addr[i] = dev->dev_addr[i];
1687     }
1688     ioc->len = ETH_ALEN;
1689     if (!(status = verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len))) {
1690       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1691     }
1692 
1693     break;
1694   case EWRK3_SET_HWADDR:             /* Set the hardware address */
1695     if (suser()) {
1696       if (!(status = verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN))) {
1697         csr = inb(EWRK3_CSR);
1698         csr |= (CSR_TXD|CSR_RXD);
1699         outb(csr, EWRK3_CSR);                  /* Disable the TX and RX */
1700 
1701         memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1702         for (i=0; i<ETH_ALEN; i++) {
1703           dev->dev_addr[i] = tmp.addr[i];
1704           outb(tmp.addr[i], EWRK3_PAR0 + i);
1705         }
1706 
1707         csr &= ~(CSR_TXD|CSR_RXD);             /* Enable the TX and RX */
1708         outb(csr, EWRK3_CSR);
1709       }
1710     } else {
1711       status = -EPERM;
1712     }
1713 
1714     break;
1715   case EWRK3_SET_PROM:               /* Set Promiscuous Mode */
1716     if (suser()) {
1717       csr = inb(EWRK3_CSR);
1718       csr |= CSR_PME;
1719       csr &= ~CSR_MCE;
1720       outb(csr, EWRK3_CSR);
1721     } else {
1722       status = -EPERM;
1723     }
1724 
1725     break;
1726   case EWRK3_CLR_PROM:               /* Clear Promiscuous Mode */
1727     if (suser()) {
1728       csr = inb(EWRK3_CSR);
1729       csr &= ~CSR_PME;
1730       outb(csr, EWRK3_CSR);
1731     } else {
1732       status = -EPERM;
1733     }
1734 
1735     break;
1736   case EWRK3_SAY_BOO:                /* Say "Boo!" to the kernel log file */
1737     printk("%s: Boo!\n", dev->name);
1738 
1739     break;
1740   case EWRK3_GET_MCA:                /* Get the multicast address table */
1741     if (!(status = verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1742       while (set_bit(0, (void *)&lp->lock) != 0); /* Wait for lock to free */
1743       if (lp->shmem_length == IO_ONLY) {
1744         outb(0, EWRK3_IOPR);
1745         outw(PAGE0_HTE, EWRK3_PIR1);
1746         for (i=0; i<(HASH_TABLE_LEN >> 3); i++) {
1747           tmp.addr[i] = inb(EWRK3_DATA);
1748         }
1749       } else {
1750         outb(0, EWRK3_MPR);
1751         memcpy_fromio(tmp.addr, (char *)(lp->shmem_base + PAGE0_HTE), (HASH_TABLE_LEN >> 3));
1752       }
1753       ioc->len = (HASH_TABLE_LEN >> 3);
1754       memcpy_tofs(ioc->data, tmp.addr, ioc->len); 
1755     }
1756     lp->lock = 0;                               /* Unlock the page register */
1757 
1758     break;
1759   case EWRK3_SET_MCA:                /* Set a multicast address */
1760     if (suser()) {
1761       if (!(status=verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len))) {
1762         memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1763         set_multicast_list(dev);
1764       }
1765     } else {
1766       status = -EPERM;
1767     }
1768 
1769     break;
1770   case EWRK3_CLR_MCA:                /* Clear all multicast addresses */
1771     if (suser()) {
1772       set_multicast_list(dev);
1773     } else {
1774       status = -EPERM;
1775     }
1776 
1777     break;
1778   case EWRK3_MCA_EN:                 /* Enable multicast addressing */
1779     if (suser()) {
1780       csr = inb(EWRK3_CSR);
1781       csr |= CSR_MCE;
1782       csr &= ~CSR_PME;
1783       outb(csr, EWRK3_CSR);
1784     } else {
1785       status = -EPERM;
1786     }
1787 
1788     break;
1789   case EWRK3_GET_STATS:              /* Get the driver statistics */
1790     cli();
1791     ioc->len = sizeof(lp->pktStats);
1792     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1793       memcpy_tofs(ioc->data, &lp->pktStats, ioc->len); 
1794     }
1795     sti();
1796 
1797     break;
1798   case EWRK3_CLR_STATS:              /* Zero out the driver statistics */
1799     if (suser()) {
1800       cli();
1801       memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1802       sti();
1803     } else {
1804       status = -EPERM;
1805     }
1806 
1807     break;
1808   case EWRK3_GET_CSR:                /* Get the CSR Register contents */
1809     tmp.addr[0] = inb(EWRK3_CSR);
1810     ioc->len = 1;
1811     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1812       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1813     }
1814 
1815     break;
1816   case EWRK3_SET_CSR:                /* Set the CSR Register contents */
1817     if (suser()) {
1818       if (!(status=verify_area(VERIFY_READ, ioc->data, 1))) {
1819         memcpy_fromfs(tmp.addr, ioc->data, 1);
1820         outb(tmp.addr[0], EWRK3_CSR);
1821       }
1822     } else {
1823       status = -EPERM;
1824     }
1825 
1826     break;
1827   case EWRK3_GET_EEPROM:             /* Get the EEPROM contents */
1828     if (suser()) {
1829       for (i=0; i<(EEPROM_MAX>>1); i++) {
1830         tmp.val[i] = (short)Read_EEPROM(iobase, i);
1831       }
1832       i = EEPROM_MAX;
1833       tmp.addr[i++] = inb(EWRK3_CMR);            /* Config/Management Reg. */
1834       for (j=0;j<ETH_ALEN;j++) {
1835         tmp.addr[i++] = inb(EWRK3_PAR0 + j);
1836       }
1837       ioc->len = EEPROM_MAX + 1 + ETH_ALEN;
1838       if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1839         memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1840       }
1841     } else {
1842       status = -EPERM;
1843     }
1844 
1845     break;
1846   case EWRK3_SET_EEPROM:             /* Set the EEPROM contents */
1847     if (suser()) {
1848       if (!(status=verify_area(VERIFY_READ, ioc->data, EEPROM_MAX))) {
1849         memcpy_fromfs(tmp.addr, ioc->data, EEPROM_MAX);
1850         for (i=0; i<(EEPROM_MAX>>1); i++) {
1851           Write_EEPROM(tmp.val[i], iobase, i);
1852         }
1853       }
1854     } else {
1855       status = -EPERM;
1856     }
1857 
1858     break;
1859   case EWRK3_GET_CMR:                /* Get the CMR Register contents */
1860     tmp.addr[0] = inb(EWRK3_CMR);
1861     ioc->len = 1;
1862     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1863       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1864     }
1865 
1866     break;
1867   case EWRK3_SET_TX_CUT_THRU:        /* Set TX cut through mode */
1868     if (suser()) {
1869       lp->txc = 1;
1870     } else {
1871       status = -EPERM;
1872     }
1873 
1874     break;
1875   case EWRK3_CLR_TX_CUT_THRU:        /* Clear TX cut through mode */
1876     if (suser()) {
1877       lp->txc = 0;
1878     } else {
1879       status = -EPERM;
1880     }
1881 
1882     break;
1883   default:
1884     status = -EOPNOTSUPP;
1885   }
1886 
1887   return status;
1888 }
1889 
1890 #ifdef MODULE
1891 static char devicename[9] = { 0, };
1892 static struct device thisEthwrk = {
1893   devicename, /* device name is inserted by /linux/drivers/net/net_init.c */
1894   0, 0, 0, 0,
1895   0x300, 5,   /* I/O address, IRQ */
1896   0, 0, 0, NULL, ewrk3_probe };
1897         
1898 static int io=0x300;    /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
1899 static int irq=5;       /* or use the insmod io= irq= options           */
1900 
1901 int
1902 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1903 {
1904   thisEthwrk.base_addr=io;
1905   thisEthwrk.irq=irq;
1906   if (register_netdev(&thisEthwrk) != 0)
1907     return -EIO;
1908   return 0;
1909 }
1910 
1911 void
1912 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1913 {
1914   if (thisEthwrk.priv) {
1915     kfree(thisEthwrk.priv);
1916     thisEthwrk.priv = NULL;
1917   }
1918   thisEthwrk.irq = 0;
1919 
1920   unregister_netdev(&thisEthwrk);
1921   release_region(thisEthwrk.base_addr, EWRK3_TOTAL_SIZE);
1922 }
1923 #endif /* MODULE */
1924 
1925 
1926 /*
1927  * Local variables:
1928  *  kernel-compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c ewrk3.c"
1929  *
1930  *  module-compile-command: "gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c ewrk3.c"
1931  * End:
1932  */
1933 

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