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

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