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

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