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

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