root/drivers/net/depca.c

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

DEFINITIONS

This source file includes following definitions.
  1. depca_probe
  2. depca_hw_init
  3. depca_open
  4. depca_init_ring
  5. depca_start_xmit
  6. depca_interrupt
  7. depca_rx
  8. depca_tx
  9. depca_close
  10. LoadCSRs
  11. InitRestartDepca
  12. depca_get_stats
  13. set_multicast_list
  14. SetMulticastFilter
  15. isa_probe
  16. eisa_probe
  17. alloc_device
  18. DepcaSignature
  19. DevicePresent
  20. get_hw_addr
  21. load_packet
  22. EISA_signature
  23. depca_ioctl
  24. init_module
  25. cleanup_module

   1 /*  depca.c: A DIGITAL DEPCA  & EtherWORKS ethernet driver for linux.
   2 
   3     Written 1994, 1995 by David C. Davies.
   4 
   5 
   6                       Copyright 1994 David C. Davies
   7                                    and 
   8                          United States Government
   9          (as represented by the Director, National Security Agency).  
  10 
  11                Copyright 1995  Digital Equipment Corporation.
  12 
  13 
  14     This software may be used and distributed according to the terms of
  15     the GNU Public License, incorporated herein by reference.
  16 
  17     This driver is written for the Digital Equipment Corporation series
  18     of DEPCA and EtherWORKS ethernet cards:
  19 
  20         DEPCA       (the original)
  21         DE100
  22         DE101
  23         DE200 Turbo
  24         DE201 Turbo
  25         DE202 Turbo (TP BNC)
  26         DE210
  27         DE422       (EISA)
  28 
  29     The  driver has been tested on DE100, DE200 and DE202 cards  in  a
  30     relatively busy network. The DE422 has been tested a little.
  31 
  32     This  driver will NOT work   for the DE203,  DE204  and DE205 series  of
  33     cards,  since they have  a  new custom ASIC in   place of the AMD  LANCE
  34     chip.  See the 'ewrk3.c'   driver in the  Linux  source tree for running
  35     those cards.
  36 
  37     I have benchmarked the driver with a  DE100 at 595kB/s to (542kB/s from)
  38     a DECstation 5000/200.
  39 
  40     The author may be reached as davies@wanton.lkg.dec.com or
  41     Digital Equipment Corporation, 550 King Street, Littleton MA 01460.
  42 
  43     =========================================================================
  44 
  45     The  driver was originally based  on   the 'lance.c' driver from  Donald
  46     Becker   which  is included with  the  standard  driver distribution for
  47     linux.  V0.4  is  a complete  re-write  with only  the kernel  interface
  48     remaining from the original code.
  49 
  50     1) Lance.c code in /linux/drivers/net/
  51     2) "Ethernet/IEEE 802.3 Family. 1992 World Network Data Book/Handbook",
  52        AMD, 1992 [(800) 222-9323].
  53     3) "Am79C90 CMOS Local Area Network Controller for Ethernet (C-LANCE)",
  54        AMD, Pub. #17881, May 1993.
  55     4) "Am79C960 PCnet-ISA(tm), Single-Chip Ethernet Controller for ISA",
  56        AMD, Pub. #16907, May 1992
  57     5) "DEC EtherWORKS LC Ethernet Controller Owners Manual",
  58        Digital Equipment corporation, 1990, Pub. #EK-DE100-OM.003
  59     6) "DEC EtherWORKS Turbo Ethernet Controller Owners Manual",
  60        Digital Equipment corporation, 1990, Pub. #EK-DE200-OM.003
  61     7) "DEPCA Hardware Reference Manual", Pub. #EK-DEPCA-PR
  62        Digital Equipment Corporation, 1989
  63     8) "DEC EtherWORKS Turbo_(TP BNC) Ethernet Controller Owners Manual",
  64        Digital Equipment corporation, 1991, Pub. #EK-DE202-OM.001
  65     
  66 
  67     Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this
  68     driver.
  69 
  70     The original DEPCA  card requires that the  ethernet ROM address counter
  71     be enabled to count and has an 8 bit NICSR.  The ROM counter enabling is
  72     only  done when a  0x08 is read as the  first address octet (to minimise
  73     the chances  of writing over some  other hardware's  I/O register).  The
  74     NICSR accesses   have been changed  to  byte accesses  for all the cards
  75     supported by this driver, since there is only one  useful bit in the MSB
  76     (remote boot timeout) and it  is not used.  Also, there  is a maximum of
  77     only 48kB network  RAM for this  card.  My thanks  to Torbjorn Lindh for
  78     help debugging all this (and holding my feet to  the fire until I got it
  79     right).
  80 
  81     The DE200  series  boards have  on-board 64kB  RAM for  use  as a shared
  82     memory network  buffer. Only the DE100  cards make use  of a  2kB buffer
  83     mode which has not  been implemented in  this driver (only the 32kB  and
  84     64kB modes are supported [16kB/48kB for the original DEPCA]).
  85 
  86     At the most only 2 DEPCA cards can  be supported on  the ISA bus because
  87     there is only provision  for two I/O base addresses  on each card (0x300
  88     and 0x200). The I/O address is detected by searching for a byte sequence
  89     in the Ethernet station address PROM at the expected I/O address for the
  90     Ethernet  PROM.   The shared memory  base   address  is 'autoprobed'  by
  91     looking  for the self  test PROM  and detecting the  card name.   When a
  92     second  DEPCA is  detected,  information  is   placed in the   base_addr
  93     variable of the  next device structure (which  is created if necessary),
  94     thus  enabling ethif_probe  initialization  for the device.  More than 2
  95     EISA cards can  be  supported, but  care will  be  needed assigning  the
  96     shared memory to ensure that each slot has the  correct IRQ, I/O address
  97     and shared memory address assigned.
  98 
  99     ************************************************************************
 100 
 101     NOTE: If you are using two  ISA DEPCAs, it is  important that you assign
 102     the base memory addresses correctly.   The  driver autoprobes I/O  0x300
 103     then 0x200.  The  base memory address for  the first device must be less
 104     than that of the second so that the auto probe will correctly assign the
 105     I/O and memory addresses on the same card.  I can't think of a way to do
 106     this unambiguously at the moment, since there is nothing on the cards to
 107     tie I/O and memory information together.
 108 
 109     I am unable  to  test  2 cards   together for now,    so this  code   is
 110     unchecked. All reports, good or bad, are welcome.
 111 
 112     ************************************************************************
 113 
 114     The board IRQ   setting must be  at an  unused IRQ which  is auto-probed
 115     using Donald Becker's autoprobe routines. DEPCA and DE100 board IRQs are
 116     {2,3,4,5,7}, whereas the  DE200 is at {5,9,10,11,15}.  Note that IRQ2 is
 117     really IRQ9 in machines with 16 IRQ lines.
 118 
 119     No 16MB memory  limitation should exist with this  driver as DMA is  not
 120     used and the common memory area is in low memory on the network card (my
 121     current system has 20MB and I've not had problems yet).
 122 
 123     The ability to load this driver as a loadable module has been added. To
 124     utilise this ability, you have to do <8 things:
 125 
 126     0) have a copy of the loadable modules code installed on your system.
 127     1) copy depca.c from the  /linux/drivers/net directory to your favourite
 128     temporary directory.
 129     2) if you wish, edit the  source code near  line 1530 to reflect the I/O
 130     address and IRQ you're using (see also 5).
 131     3) compile  depca.c, but include -DMODULE in  the command line to ensure
 132     that the correct bits are compiled (see end of source code).
 133     4) if you are wanting to add a new  card, goto 5. Otherwise, recompile a
 134     kernel with the depca configuration turned off and reboot.
 135     5) insmod depca.o [irq=7] [io=0x200]
 136        [Alan Cox: Changed the code to allow command line irq/io assignments]
 137     6) run the net startup bits for your eth?? interface manually 
 138     (usually /etc/rc.inet[12] at boot time). 
 139     7) enjoy!
 140 
 141     Note that autoprobing is not allowed in loadable modules - the system is
 142     already up and running and you're messing with interrupts.
 143 
 144     To unload a module, turn off the associated interface 
 145     'ifconfig eth?? down' then 'rmmod depca'.
 146 
 147 
 148     TO DO:
 149     ------
 150 
 151 
 152     Revision History
 153     ----------------
 154 
 155     Version   Date        Description
 156   
 157       0.1     25-jan-94   Initial writing.
 158       0.2     27-jan-94   Added LANCE TX hardware buffer chaining.
 159       0.3      1-feb-94   Added multiple DEPCA support.
 160       0.31     4-feb-94   Added DE202 recognition.
 161       0.32    19-feb-94   Tidy up. Improve multi-DEPCA support.
 162       0.33    25-feb-94   Fix DEPCA ethernet ROM counter enable.
 163                           Add jabber packet fix from murf@perftech.com
 164                           and becker@super.org
 165       0.34     7-mar-94   Fix DEPCA max network memory RAM & NICSR access.
 166       0.35     8-mar-94   Added DE201 recognition. Tidied up.
 167       0.351   30-apr-94   Added EISA support. Added DE422 recognition.
 168       0.36    16-may-94   DE422 fix released.
 169       0.37    22-jul-94   Added MODULE support
 170       0.38    15-aug-94   Added DBR ROM switch in depca_close(). 
 171                           Multi DEPCA bug fix.
 172       0.38axp 15-sep-94   Special version for Alpha AXP Linux V1.0.
 173       0.381   12-dec-94   Added DE101 recognition, fix multicast bug.
 174       0.382    9-feb-95   Fix recognition bug reported by <bkm@star.rl.ac.uk>.
 175       0.383   22-feb-95   Fix for conflict with VESA SCSI reported by
 176                           <stromain@alf.dec.com>
 177       0.384   17-mar-95   Fix a ring full bug reported by <bkm@star.rl.ac.uk>
 178       0.385    3-apr-95   Fix a recognition bug reported by 
 179                                                 <ryan.niemi@lastfrontier.com>
 180       0.386   21-apr-95   Fix the last fix...sorry, must be galloping senility
 181       0.40    25-May-95   Rewrite for portability & updated.
 182                           ALPHA support from <jestabro@amt.tay1.dec.com>
 183       0.41    26-Jun-95   Added verify_area() calls in depca_ioctl() from
 184                           suggestion by <heiko@colossus.escape.de>
 185 
 186     =========================================================================
 187 */
 188 
 189 static char *version = "depca.c:v0.41 5/26/95 davies@wanton.lkg.dec.com\n";
 190 
 191 #include <linux/config.h>
 192 #ifdef MODULE
 193 #include <linux/module.h>
 194 #include <linux/version.h>
 195 #else
 196 #define MOD_INC_USE_COUNT
 197 #define MOD_DEC_USE_COUNT
 198 #endif /* MODULE */
 199 
 200 #include <linux/types.h>
 201 #include <linux/kernel.h>
 202 #include <linux/sched.h>
 203 #include <linux/string.h>
 204 #include <linux/ptrace.h>
 205 #include <linux/errno.h>
 206 #include <linux/ioport.h>
 207 #include <linux/malloc.h>
 208 #include <linux/interrupt.h>
 209 #include <asm/segment.h>
 210 #include <asm/bitops.h>
 211 #include <asm/io.h>
 212 #include <asm/dma.h>
 213 
 214 #include <linux/netdevice.h>
 215 #include <linux/etherdevice.h>
 216 #include <linux/skbuff.h>
 217 
 218 #include "depca.h"
 219 
 220 #ifdef DEPCA_DEBUG
 221 static int depca_debug = DEPCA_DEBUG;
 222 #else
 223 static int depca_debug = 1;
 224 #endif
 225 
 226 #define DEPCA_NDA 0xffe0            /* No Device Address */
 227 
 228 /*
 229 ** Ethernet PROM defines
 230 */
 231 #define PROBE_LENGTH    32
 232 #define ETH_PROM_SIG    0xAA5500FFUL
 233 
 234 /*
 235 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
 236 ** here is <= to the amount of shared memory set up by the board switches.
 237 ** The number of descriptors MUST BE A POWER OF 2.
 238 **
 239 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
 240 */
 241 #define NUM_RX_DESC     8               /* Number of RX descriptors */
 242 #define NUM_TX_DESC     8               /* Number of TX descriptors */
 243 #define RX_BUFF_SZ      1536            /* Buffer size for each Rx buffer */
 244 #define TX_BUFF_SZ      1536            /* Buffer size for each Tx buffer */
 245 
 246 #define CRC_POLYNOMIAL_BE 0x04c11db7UL  /* Ethernet CRC, big endian */
 247 #define CRC_POLYNOMIAL_LE 0xedb88320UL  /* Ethernet CRC, little endian */
 248 
 249 /*
 250 ** EISA bus defines
 251 */
 252 #define DEPCA_EISA_IO_PORTS 0x0c00       /* I/O port base address, slot 0 */
 253 #define MAX_EISA_SLOTS 16
 254 #define EISA_SLOT_INC 0x1000
 255 
 256 /*
 257 ** ISA Bus defines
 258 */
 259 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
 260 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
 261 #define DEPCA_TOTAL_SIZE 0x10
 262 static short mem_chkd = 0;
 263 
 264 /*
 265 ** Name <-> Adapter mapping
 266 */
 267 #define DEPCA_SIGNATURE {"DEPCA",\
 268                          "DE100","DE101",\
 269                          "DE200","DE201","DE202",\
 270                          "DE210",\
 271                          "DE422",\
 272                          ""}
 273 static enum {DEPCA, de100, de101, de200, de201, de202, de210, de422, unknown} adapter;
 274 
 275 /*
 276 ** Miscellaneous info...
 277 */
 278 #define DEPCA_STRLEN 16
 279 #define MAX_NUM_DEPCAS 2
 280 
 281 /*
 282 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
 283 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
 284 ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
 285 ** and hence the RX descriptor ring's first entry. 
 286 */
 287 #define ALIGN4      ((u_long)4 - 1)       /* 1 longword align */
 288 #define ALIGN8      ((u_long)8 - 1)       /* 2 longword (quadword) align */
 289 #define ALIGN         ALIGN8              /* Keep the LANCE happy... */
 290 
 291 /*
 292 ** The DEPCA Rx and Tx ring descriptors. 
 293 */
 294 struct depca_rx_desc {
 295     volatile s32 base;
 296     s16 buf_length;             /* This length is negative 2's complement! */
 297     s16 msg_length;             /* This length is "normal". */
 298 };
 299 
 300 struct depca_tx_desc {
 301     volatile s32 base;
 302     s16 length;                 /* This length is negative 2's complement! */
 303     s16 misc;                   /* Errors and TDR info */
 304 };
 305 
 306 #define LA_MASK 0x0000ffff      /* LANCE address mask for mapping network RAM
 307                                    to LANCE memory address space */
 308 
 309 /*
 310 ** The Lance initialization block, described in databook, in common memory.
 311 */
 312 struct depca_init {
 313     u16 mode;                   /* Mode register */
 314     u8  phys_addr[ETH_ALEN];    /* Physical ethernet address */
 315     u8  mcast_table[8];         /* Multicast Hash Table. */
 316     u32 rx_ring;                /* Rx ring base pointer & ring length */
 317     u32 tx_ring;                /* Tx ring base pointer & ring length */
 318 };
 319 
 320 #define DEPCA_PKT_STAT_SZ 16
 321 #define DEPCA_PKT_BIN_SZ  128                /* Should be >=100 unless you
 322                                                 increase DEPCA_PKT_STAT_SZ */
 323 struct depca_private {
 324     char devname[DEPCA_STRLEN];    /* Device Product String                  */
 325     char adapter_name[DEPCA_STRLEN];/* /proc/ioports string                  */
 326     char adapter;                  /* Adapter type                           */
 327     struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
 328     struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
 329     struct depca_init   init_block;/* Shadow Initialization block            */
 330     char *rx_memcpy[NUM_RX_DESC];  /* CPU virt address of sh'd memory buffs  */
 331     char *tx_memcpy[NUM_TX_DESC];  /* CPU virt address of sh'd memory buffs  */
 332     u_long bus_offset;             /* (E)ISA bus address offset vs LANCE     */
 333     u_long sh_mem;                 /* Physical start addr of shared mem area */
 334     u_long dma_buffs;              /* LANCE Rx and Tx buffers start address. */
 335     int rx_new, tx_new;            /* The next free ring entry               */
 336     int rx_old, tx_old;            /* The ring entries to be free()ed.       */
 337     struct enet_statistics stats;
 338     struct {                       /* Private stats counters                 */
 339         u32 bins[DEPCA_PKT_STAT_SZ];
 340         u32 unicast;
 341         u32 multicast;
 342         u32 broadcast;
 343         u32 excessive_collisions;
 344         u32 tx_underruns;
 345         u32 excessive_underruns;
 346     } pktStats;
 347     int txRingMask;                /* TX ring mask                           */
 348     int rxRingMask;                /* RX ring mask                           */
 349     s32 rx_rlen;                   /* log2(rxRingMask+1) for the descriptors */
 350     s32 tx_rlen;                   /* log2(txRingMask+1) for the descriptors */
 351 };
 352 
 353 /*
 354 ** The transmit ring full condition is described by the tx_old and tx_new
 355 ** pointers by:
 356 **    tx_old            = tx_new    Empty ring
 357 **    tx_old            = tx_new+1  Full ring
 358 **    tx_old+txRingMask = tx_new    Full ring  (wrapped condition)
 359 */
 360 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
 361                          lp->tx_old+lp->txRingMask-lp->tx_new:\
 362                          lp->tx_old               -lp->tx_new-1)
 363 
 364 /*
 365 ** Public Functions
 366 */
 367 static int    depca_open(struct device *dev);
 368 static int    depca_start_xmit(struct sk_buff *skb, struct device *dev);
 369 static void   depca_interrupt(int irq, struct pt_regs * regs);
 370 static int    depca_close(struct device *dev);
 371 static int    depca_ioctl(struct device *dev, struct ifreq *rq, int cmd);
 372 static struct enet_statistics *depca_get_stats(struct device *dev);
 373 static void   set_multicast_list(struct device *dev,int num_addrs,void *addrs);
 374 
 375 /*
 376 ** Private functions
 377 */
 378 static int    depca_hw_init(struct device *dev, u_long ioaddr);
 379 static void   depca_init_ring(struct device *dev);
 380 static int    depca_rx(struct device *dev);
 381 static int    depca_tx(struct device *dev);
 382 
 383 static void   LoadCSRs(struct device *dev);
 384 static int    InitRestartDepca(struct device *dev);
 385 static void   DepcaSignature(char *name, u_long paddr);
 386 static int    DevicePresent(u_long ioaddr);
 387 static int    get_hw_addr(struct device *dev);
 388 static int    EISA_signature(char *name, s32 eisa_id);
 389 static void   SetMulticastFilter(struct device *dev,int num_addrs,char *addrs);
 390 static void   isa_probe(struct device *dev, u_long iobase);
 391 static void   eisa_probe(struct device *dev, u_long iobase);
 392 static struct device *alloc_device(struct device *dev, u_long iobase);
 393 static int    load_packet(struct device *dev, struct sk_buff *skb);
 394 
 395 #ifdef MODULE
 396 int           init_module(void);
 397 void          cleanup_module(void);
 398 static int    autoprobed = 1, loading_module = 1;
 399 # else
 400 static u_char de1xx_irq[] = {2,3,4,5,7,0};
 401 static u_char de2xx_irq[] = {5,9,10,11,15,0};
 402 static u_char de422_irq[] = {5,9,10,11,0};
 403 static u_char *depca_irq;
 404 static int    autoprobed = 0, loading_module = 0;
 405 #endif /* MODULE */
 406 
 407 static char   name[DEPCA_STRLEN];
 408 static int    num_depcas = 0, num_eth = 0;
 409 
 410 /*
 411 ** Miscellaneous defines...
 412 */
 413 #define STOP_DEPCA \
 414     outw(CSR0, DEPCA_ADDR);\
 415     outw(STOP, DEPCA_DATA)
 416 
 417 
 418 
 419 int depca_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 420 {
 421   int tmp = num_depcas, status = -ENODEV;
 422   u_long iobase = dev->base_addr;
 423 
 424   if ((iobase == 0) && loading_module){
 425     printk("Autoprobing is not supported when loading a module based driver.\n");
 426     status = -EIO;
 427   } else {
 428     isa_probe(dev, iobase);
 429     eisa_probe(dev, iobase);
 430 
 431     if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
 432       printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name, 
 433                                                                        iobase);
 434     }
 435 
 436     /*
 437     ** Walk the device list to check that at least one device
 438     ** initialised OK
 439     */
 440     for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
 441 
 442     if (dev->priv) status = 0;
 443     if (iobase == 0) autoprobed = 1;
 444   }
 445 
 446   return status;
 447 }
 448 
 449 static int
 450 depca_hw_init(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 451 {
 452   struct depca_private *lp;
 453   int i, j, offset, netRAM, mem_len, status=0;
 454   s16 nicsr;
 455   u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
 456 
 457   STOP_DEPCA;
 458 
 459   nicsr = inb(DEPCA_NICSR);
 460   nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
 461   outb(nicsr, DEPCA_NICSR);
 462 
 463   if (inw(DEPCA_DATA) == STOP) {
 464     for (; mem_base[mem_chkd]; mem_chkd++) {
 465       mem_start = mem_base[mem_chkd];
 466       DepcaSignature(name, mem_start);
 467       if (*name != '\0') break;
 468     }
 469 
 470     if ((*name != '\0') && mem_start) {           /* found a DEPCA device */
 471       dev->base_addr = ioaddr;
 472 
 473       if ((ioaddr&0x0fff)==DEPCA_EISA_IO_PORTS) {/* EISA slot address */
 474         printk("%s: %s at 0x%04lx (EISA slot %d)", 
 475                             dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f));
 476       } else {                             /* ISA port address */
 477         printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
 478       }
 479 
 480       printk(", h/w address ");
 481       status = get_hw_addr(dev);
 482       for (i=0; i<ETH_ALEN - 1; i++) { /* get the ethernet address */
 483         printk("%2.2x:", dev->dev_addr[i]);
 484       }
 485       printk("%2.2x", dev->dev_addr[i]);
 486 
 487       if (status == 0) {
 488         /* Set up the maximum amount of network RAM(kB) */
 489         netRAM = ((adapter != DEPCA) ? 64 : 48);
 490         if ((nicsr & _128KB) && (adapter == de422)) netRAM = 128;
 491         offset = 0x0000;
 492 
 493         /* Shared Memory Base Address */ 
 494         if (nicsr & BUF) {
 495           offset = 0x8000;              /* 32kbyte RAM offset*/
 496           nicsr &= ~BS;                 /* DEPCA RAM in top 32k */
 497           netRAM -= 32;
 498         }
 499         mem_start += offset;            /* (E)ISA start address */
 500         if ((mem_len = (NUM_RX_DESC*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ) +
 501                         NUM_TX_DESC*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ) +
 502                         sizeof(struct depca_init))) <=
 503             (netRAM<<10)) {
 504           printk(",\n      has %dkB RAM at 0x%.5lx", netRAM, mem_start);
 505 
 506           /* Enable the shadow RAM. */
 507           if (adapter != DEPCA) {
 508             nicsr |= SHE;
 509             outb(nicsr, DEPCA_NICSR);
 510           }
 511  
 512           /* Define the device private memory */
 513           dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
 514           lp = (struct depca_private *)dev->priv;
 515           memset((char *)dev->priv, 0, sizeof(struct depca_private));
 516           lp->adapter = adapter;
 517           sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
 518           request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name);
 519 
 520           /* Initialisation Block */
 521           lp->sh_mem = mem_start;
 522           mem_start += sizeof(struct depca_init);
 523 
 524           /* Tx & Rx descriptors (aligned to a quadword boundary) */
 525           mem_start = (mem_start + ALIGN) & ~ALIGN;
 526           lp->rx_ring = (struct depca_rx_desc *)mem_start;
 527 
 528           mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
 529           lp->tx_ring = (struct depca_tx_desc *)mem_start;
 530 
 531           mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
 532           lp->bus_offset = mem_start & 0x00ff0000;
 533           mem_start &= LA_MASK;           /* LANCE re-mapped start address */
 534 
 535           lp->dma_buffs = mem_start;
 536 
 537           /* Finish initialising the ring information. */
 538           lp->rxRingMask = NUM_RX_DESC - 1;
 539           lp->txRingMask = NUM_TX_DESC - 1;
 540 
 541           /* Calculate Tx/Rx RLEN size for the descriptors. */
 542           for (i=0, j = lp->rxRingMask; j>0; i++) {
 543             j >>= 1;
 544           }
 545           lp->rx_rlen = (s32)(i << 29);
 546           for (i=0, j = lp->txRingMask; j>0; i++) {
 547             j >>= 1;
 548           }
 549           lp->tx_rlen = (s32)(i << 29);
 550 
 551           /* Load the initialisation block */
 552           depca_init_ring(dev);
 553 
 554           /* Initialise the control and status registers */
 555           LoadCSRs(dev);
 556 
 557           /* Enable DEPCA board interrupts for autoprobing */
 558           nicsr = ((nicsr & ~IM)|IEN);
 559           outb(nicsr, DEPCA_NICSR);
 560 
 561           /* To auto-IRQ we enable the initialization-done and DMA err,
 562              interrupts. For now we will always get a DMA error. */
 563           if (dev->irq < 2) {
 564 #ifndef MODULE
 565             unsigned char irqnum;
 566             autoirq_setup(0);
 567             
 568             /* Assign the correct irq list */
 569             switch (lp->adapter) {
 570             case DEPCA:
 571             case de100:
 572             case de101:
 573               depca_irq = de1xx_irq;
 574               break;
 575             case de200:
 576             case de201:
 577             case de202:
 578             case de210:
 579               depca_irq = de2xx_irq;
 580               break;
 581             case de422:
 582               depca_irq = de422_irq;
 583               break;
 584             }
 585 
 586             /* Trigger an initialization just for the interrupt. */
 587             outw(INEA | INIT, DEPCA_DATA);
 588           
 589             irqnum = autoirq_report(1);
 590             if (!irqnum) {
 591               printk("      and failed to detect IRQ line.\n");
 592               status = -ENXIO;
 593             } else {
 594               for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) {
 595                 if (irqnum == depca_irq[i]) {
 596                   dev->irq = irqnum;
 597                   printk("      and uses IRQ%d.\n", dev->irq);
 598                 }
 599               }
 600               
 601               if (!dev->irq) {
 602                 printk("      but incorrect IRQ line detected.\n");
 603                 status = -ENXIO;
 604               }
 605             }
 606 #endif /* MODULE */
 607           } else {
 608             printk(" and assigned IRQ%d.\n", dev->irq);
 609           }
 610           if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE);
 611         } else {
 612           printk(",\n      requests %dkB RAM: only %dkB is available!\n", 
 613                                                         (mem_len>>10), netRAM);
 614           status = -ENXIO;
 615         }
 616       } else {
 617         printk("      which has an Ethernet PROM CRC error.\n");
 618         status = -ENXIO;
 619       }
 620     }
 621     if (!status) {
 622       if (depca_debug > 0) {
 623         printk(version);
 624       }
 625 
 626       /* The DEPCA-specific entries in the device structure. */
 627       dev->open = &depca_open;
 628       dev->hard_start_xmit = &depca_start_xmit;
 629       dev->stop = &depca_close;
 630       dev->get_stats = &depca_get_stats;
 631       dev->set_multicast_list = &set_multicast_list;
 632       dev->do_ioctl = &depca_ioctl;
 633 
 634       dev->mem_start = 0;
 635         
 636       /* Fill in the generic field of the device structure. */
 637       ether_setup(dev);
 638     } else {                           /* Incorrectly initialised hardware */
 639       if (dev->priv) {
 640         kfree_s(dev->priv, sizeof(struct depca_private));
 641         dev->priv = NULL;
 642       }
 643     }
 644   } else {
 645     status = -ENXIO;
 646   }
 647 
 648   return status;
 649 }
 650 
 651 
 652 static int
 653 depca_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 654 {
 655     struct depca_private *lp = (struct depca_private *)dev->priv;
 656     s16 nicsr;
 657     u_long ioaddr = dev->base_addr;
 658     int i, status = 0;
 659     struct depca_init *p = (struct depca_init *)lp->sh_mem;
 660 
 661     if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name)) {
 662         printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
 663         status = -EAGAIN;
 664     }
 665 
 666     irq2dev_map[dev->irq] = dev;
 667     STOP_DEPCA;
 668     nicsr = inb(DEPCA_NICSR);
 669 
 670     /* Make sure the shadow RAM is enabled */
 671     if (adapter != DEPCA) {
 672       nicsr |= SHE;
 673       outb(nicsr, DEPCA_NICSR);
 674     }
 675 
 676     /* Re-initialize the DEPCA... */
 677     depca_init_ring(dev);
 678     LoadCSRs(dev);
 679 
 680     if (depca_debug > 1){
 681       /* Copy the shadow init_block to shared memory */
 682       memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
 683 
 684       printk("%s: depca open with irq %d\n",dev->name,dev->irq);
 685       printk("Descriptor head addresses:\n");
 686       printk("\t0x%lx  0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring);
 687       printk("Descriptor addresses:\nRX: ");
 688       for (i=0;i<lp->rxRingMask;i++){
 689         if (i < 3) {
 690           printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
 691         }
 692       }
 693       printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
 694       printk("TX: ");
 695       for (i=0;i<lp->txRingMask;i++){
 696         if (i < 3) {
 697           printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
 698         }
 699       }
 700       printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
 701       printk("\nDescriptor buffers:\nRX: ");
 702       for (i=0;i<lp->rxRingMask;i++){
 703         if (i < 3) {
 704           printk("0x%8.8x  ", readl(&lp->rx_ring[i].base));
 705         }
 706       }
 707       printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
 708       printk("TX: ");
 709       for (i=0;i<lp->txRingMask;i++){
 710         if (i < 3) {
 711           printk("0x%8.8x  ", readl(&lp->tx_ring[i].base));
 712         }
 713       }
 714       printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
 715       printk("Status:  %d\n", status);
 716       printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem);
 717       printk("\tmode: 0x%4.4x\n",readw(&p->mode));
 718       printk("\tphysical address: ");
 719       for (i=0;i<ETH_ALEN-1;i++){
 720         printk("%2.2x:",(u_char)readb(&p->phys_addr[i]));
 721       }
 722       printk("%2.2x\n",(u_char)readb(&p->phys_addr[i]));
 723       printk("\tmulticast hash table: ");
 724       for (i=0;i<(HASH_TABLE_LEN >> 3)-1;i++){
 725         printk("%2.2x:",(u_char)readb(&p->mcast_table[i]));
 726       }
 727       printk("%2.2x\n",(u_char)readb(&p->mcast_table[i]));
 728       printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring));
 729       printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring));
 730       printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs);
 731       printk("Ring size:\nRX: %d  Log2(rxRingMask): 0x%8.8x\n", 
 732                                           (int)lp->rxRingMask + 1, 
 733                                           lp->rx_rlen);
 734       printk("TX: %d  Log2(txRingMask): 0x%8.8x\n", 
 735                                           (int)lp->txRingMask + 1, 
 736                                           lp->tx_rlen);
 737       outw(CSR2,DEPCA_ADDR);
 738       printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
 739       outw(CSR1,DEPCA_ADDR);
 740       printk("%4.4x\n",inw(DEPCA_DATA));
 741       outw(CSR3,DEPCA_ADDR);
 742       printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
 743     }
 744 
 745     /* Enable DEPCA board interrupts and turn off LED */
 746     nicsr = ((nicsr & ~IM & ~LED)|IEN);
 747     outb(nicsr, DEPCA_NICSR);
 748     outw(CSR0,DEPCA_ADDR);
 749 
 750     dev->tbusy = 0;                         
 751     dev->interrupt = 0;
 752     dev->start = 1;
 753 
 754     status = InitRestartDepca(dev);
 755 
 756     if (depca_debug > 1){
 757       printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
 758       printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
 759     }
 760 
 761     MOD_INC_USE_COUNT;
 762 
 763     return status;
 764 }
 765 
 766 /* Initialize the lance Rx and Tx descriptor rings. */
 767 static void
 768 depca_init_ring(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 769 {
 770   struct depca_private *lp = (struct depca_private *)dev->priv;
 771   u_int i;
 772   u_long p;
 773 
 774   /* Lock out other processes whilst setting up the hardware */
 775   set_bit(0, (void *)&dev->tbusy);
 776 
 777   lp->rx_new = lp->tx_new = 0;
 778   lp->rx_old = lp->tx_old = 0;
 779 
 780   /* Initialize the base addresses and length of each buffer in the ring */
 781   for (i = 0; i <= lp->rxRingMask; i++) {
 782     writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base);
 783     writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
 784     lp->rx_memcpy[i]=(char *)(p+lp->bus_offset);
 785   }
 786   for (i = 0; i <= lp->txRingMask; i++) {
 787     writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,
 788                                                          &lp->tx_ring[i].base);
 789     lp->tx_memcpy[i]=(char *)(p+lp->bus_offset);
 790   }
 791 
 792   /* Set up the initialization block */
 793   lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK) | lp->rx_rlen;
 794   lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK) | lp->tx_rlen;
 795 
 796   SetMulticastFilter(dev, 0, NULL);
 797 
 798   for (i = 0; i < ETH_ALEN; i++) {
 799     lp->init_block.phys_addr[i] = dev->dev_addr[i];
 800   }
 801 
 802   lp->init_block.mode = 0x0000;            /* Enable the Tx and Rx */
 803 
 804   return;
 805 }
 806 
 807 /* 
 808 ** Writes a socket buffer to TX descriptor ring and starts transmission 
 809 */
 810 static int
 811 depca_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 812 {
 813   struct depca_private *lp = (struct depca_private *)dev->priv;
 814   u_long ioaddr = dev->base_addr;
 815   int status = 0;
 816 
 817   /* Transmitter timeout, serious problems. */
 818   if (dev->tbusy) {
 819     int tickssofar = jiffies - dev->trans_start;
 820     if (tickssofar < 100) {
 821       status = -1;
 822     } else {
 823       printk("%s: transmit timed out, status %04x, resetting.\n",
 824              dev->name, inw(DEPCA_DATA));
 825         
 826       STOP_DEPCA;
 827       depca_init_ring(dev);
 828       LoadCSRs(dev);
 829       dev->interrupt = UNMASK_INTERRUPTS;
 830       dev->start = 1;
 831       dev->tbusy=0;
 832       dev->trans_start = jiffies;
 833       InitRestartDepca(dev);
 834     }
 835     return status;
 836   } else if (skb == NULL) {
 837     dev_tint(dev);
 838   } else if (skb->len > 0) {
 839     /* Enforce 1 process per h/w access */
 840     if (set_bit(0, (void*)&dev->tbusy) != 0) {
 841       printk("%s: Transmitter access conflict.\n", dev->name);
 842       status = -1;
 843     } else {
 844       if (TX_BUFFS_AVAIL) {                    /* Fill in a Tx ring entry */
 845         status = load_packet(dev, skb);
 846 
 847         if (!status) {
 848           /* Trigger an immediate send demand. */
 849           outw(CSR0, DEPCA_ADDR);
 850           outw(INEA | TDMD, DEPCA_DATA);
 851           
 852           dev->trans_start = jiffies;
 853           dev_kfree_skb(skb, FREE_WRITE);
 854         }
 855         if (TX_BUFFS_AVAIL) {
 856           dev->tbusy=0;
 857         }  
 858       } else {
 859         status = -1;
 860       }
 861     }
 862   }
 863   
 864   return status;
 865 }
 866 
 867 /*
 868 ** The DEPCA interrupt handler. 
 869 */
 870 static void
 871 depca_interrupt(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 872 {
 873   struct device *dev = (struct device *)(irq2dev_map[irq]);
 874   struct depca_private *lp;
 875   s16 csr0, nicsr;
 876   u_long ioaddr;
 877 
 878   if (dev == NULL) {
 879     printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
 880   } else {
 881     lp = (struct depca_private *)dev->priv;
 882     ioaddr = dev->base_addr;
 883     
 884     if (dev->interrupt)
 885       printk("%s: Re-entering the interrupt handler.\n", dev->name);
 886 
 887     dev->interrupt = MASK_INTERRUPTS;
 888 
 889     /* mask the DEPCA board interrupts and turn on the LED */
 890     nicsr = inb(DEPCA_NICSR);
 891     nicsr |= (IM|LED);
 892     outb(nicsr, DEPCA_NICSR);
 893 
 894     outw(CSR0, DEPCA_ADDR);
 895     csr0 = inw(DEPCA_DATA);
 896 
 897     /* Acknowledge all of the current interrupt sources ASAP. */
 898     outw(csr0 & INTE, DEPCA_DATA);
 899 
 900     if (csr0 & RINT)                   /* Rx interrupt (packet arrived) */
 901       depca_rx(dev);
 902 
 903     if (csr0 & TINT)                   /* Tx interrupt (packet sent) */
 904       depca_tx(dev);
 905 
 906     if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) { /* any resources available? */
 907       dev->tbusy = 0;                  /* clear TX busy flag */
 908       mark_bh(NET_BH);
 909     }
 910 
 911     /* Unmask the DEPCA board interrupts and turn off the LED */
 912     nicsr = (nicsr & ~IM & ~LED);
 913     outb(nicsr, DEPCA_NICSR);
 914 
 915     dev->interrupt = UNMASK_INTERRUPTS;
 916   }
 917 
 918   return;
 919 }
 920 
 921 static int
 922 depca_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 923 {
 924   struct depca_private *lp = (struct depca_private *)dev->priv;
 925   int i, entry;
 926   s32 status;
 927 
 928   for (entry=lp->rx_new; 
 929        !(readl(&lp->rx_ring[entry].base) & R_OWN);
 930        entry=lp->rx_new){
 931     status = readl(&lp->rx_ring[entry].base) >> 16 ;
 932     if (status & R_STP) {                      /* Remember start of frame */
 933       lp->rx_old = entry;
 934     }
 935     if (status & R_ENP) {                      /* Valid frame status */
 936       if (status & R_ERR) {                    /* There was an error. */
 937         lp->stats.rx_errors++;                 /* Update the error stats. */
 938         if (status & R_FRAM) lp->stats.rx_frame_errors++;
 939         if (status & R_OFLO) lp->stats.rx_over_errors++;
 940         if (status & R_CRC)  lp->stats.rx_crc_errors++;
 941         if (status & R_BUFF) lp->stats.rx_fifo_errors++;
 942       } else {  
 943         short len, pkt_len = readw(&lp->rx_ring[entry].msg_length);
 944         struct sk_buff *skb;
 945 
 946         skb = dev_alloc_skb(pkt_len+2);
 947         if (skb != NULL) {
 948           unsigned char * buf;
 949           skb_reserve(skb,2);   /* 16 byte align the IP header */
 950           buf = skb_put(skb,pkt_len);
 951           skb->dev = dev;
 952           if (entry < lp->rx_old) {         /* Wrapped buffer */
 953             len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
 954             memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len);
 955             memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len);
 956           } else {                          /* Linear buffer */
 957             memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len);
 958           }
 959 
 960           /* 
 961           ** Notify the upper protocol layers that there is another 
 962           ** packet to handle
 963           */
 964           skb->protocol=eth_type_trans(skb,dev);
 965           netif_rx(skb);
 966  
 967           /*
 968           ** Update stats
 969           */
 970           lp->stats.rx_packets++;
 971           for (i=1; i<DEPCA_PKT_STAT_SZ-1; i++) {
 972             if (pkt_len < (i*DEPCA_PKT_BIN_SZ)) {
 973               lp->pktStats.bins[i]++;
 974               i = DEPCA_PKT_STAT_SZ;
 975             }
 976           }
 977           if (buf[0] & 0x01) {              /* Multicast/Broadcast */
 978             if ((*(s16 *)&buf[0] == -1) && (*(s32 *)&buf[2] == -1)) {
 979               lp->pktStats.broadcast++;
 980             } else {
 981               lp->pktStats.multicast++;
 982             }
 983           } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
 984                      (*(s32 *)&buf[2] == *(s32 *)&dev->dev_addr[2])) {
 985             lp->pktStats.unicast++;
 986           }
 987           
 988           lp->pktStats.bins[0]++;           /* Duplicates stats.rx_packets */
 989           if (lp->pktStats.bins[0] == 0) {  /* Reset counters */
 990             memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
 991           }
 992         } else {
 993           printk("%s: Memory squeeze, deferring packet.\n", dev->name);
 994           lp->stats.rx_dropped++;       /* Really, deferred. */
 995           break;
 996         }
 997       }
 998       /* Change buffer ownership for this last frame, back to the adapter */
 999       for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
1000         writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, 
1001                                                 &lp->rx_ring[lp->rx_old].base);
1002       }
1003       writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1004     }
1005 
1006     /*
1007     ** Update entry information
1008     */
1009     lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
1010     }
1011 
1012     return 0;
1013 }
1014 
1015 /*
1016 ** Buffer sent - check for buffer errors.
1017 */
1018 static int
1019 depca_tx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1020 {
1021   struct depca_private *lp = (struct depca_private *)dev->priv;
1022   int entry;
1023   s32 status;
1024   u_long ioaddr = dev->base_addr;
1025 
1026   for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1027     status = readl(&lp->tx_ring[entry].base) >> 16 ;
1028 
1029     if (status < 0) {                          /* Packet not yet sent! */
1030       break;
1031     } else if (status & T_ERR) {               /* An error occured. */
1032       status = readl(&lp->tx_ring[entry].misc);
1033       lp->stats.tx_errors++;
1034       if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
1035       if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
1036       if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
1037       if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
1038       if (status & (TMD3_BUFF | TMD3_UFLO)) {
1039         /* Trigger an immediate send demand. */
1040         outw(CSR0, DEPCA_ADDR);
1041         outw(INEA | TDMD, DEPCA_DATA);
1042       }
1043     } else if (status & (T_MORE | T_ONE)) {
1044       lp->stats.collisions++;
1045     } else {
1046       lp->stats.tx_packets++;
1047     }
1048 
1049     /* Update all the pointers */
1050     lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1051   }
1052 
1053   return 0;
1054 }
1055 
1056 static int
1057 depca_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1058 {
1059   struct depca_private *lp = (struct depca_private *)dev->priv;
1060   s16 nicsr;
1061   u_long ioaddr = dev->base_addr;
1062 
1063   dev->start = 0;
1064   dev->tbusy = 1;
1065 
1066   outw(CSR0, DEPCA_ADDR);
1067 
1068   if (depca_debug > 1) {
1069     printk("%s: Shutting down ethercard, status was %2.2x.\n",
1070            dev->name, inw(DEPCA_DATA));
1071   }
1072 
1073   /* 
1074   ** We stop the DEPCA here -- it occasionally polls
1075   ** memory if we don't. 
1076   */
1077   outw(STOP, DEPCA_DATA);
1078 
1079   /*
1080   ** Give back the ROM in case the user wants to go to DOS
1081   */
1082   if (lp->adapter != DEPCA) {
1083     nicsr = inb(DEPCA_NICSR);
1084     nicsr &= ~SHE;
1085     outb(nicsr, DEPCA_NICSR);
1086   }
1087 
1088   /*
1089   ** Free the associated irq
1090   */
1091   free_irq(dev->irq);
1092   irq2dev_map[dev->irq] = NULL;
1093 
1094   MOD_DEC_USE_COUNT;
1095 
1096   return 0;
1097 }
1098 
1099 static void LoadCSRs(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1100 {
1101   struct depca_private *lp = (struct depca_private *)dev->priv;
1102   u_long ioaddr = dev->base_addr;
1103 
1104   outw(CSR1, DEPCA_ADDR);                /* initialisation block address LSW */
1105   outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
1106   outw(CSR2, DEPCA_ADDR);                /* initialisation block address MSW */
1107   outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
1108   outw(CSR3, DEPCA_ADDR);                /* ALE control */
1109   outw(ACON, DEPCA_DATA);
1110 
1111   outw(CSR0, DEPCA_ADDR);                /* Point back to CSR0 */
1112 
1113   return;
1114 }
1115 
1116 static int InitRestartDepca(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1117 {
1118   struct depca_private *lp = (struct depca_private *)dev->priv;
1119   u_long ioaddr = dev->base_addr;
1120   int i, status=0;
1121 
1122   /* Copy the shadow init_block to shared memory */
1123   memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1124 
1125   outw(CSR0, DEPCA_ADDR);                /* point back to CSR0 */
1126   outw(INIT, DEPCA_DATA);                /* initialize DEPCA */
1127 
1128   /* wait for lance to complete initialisation */
1129   for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++); 
1130 
1131   if (i!=100) {
1132     /* clear IDON by writing a "1", enable interrupts and start lance */
1133     outw(IDON | INEA | STRT, DEPCA_DATA);
1134     if (depca_debug > 2) {
1135       printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1136              dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1137     }
1138   } else {
1139     printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1140              dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1141     status = -1;
1142   }
1143 
1144   return status;
1145 }
1146 
1147 static struct enet_statistics *
1148 depca_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1149 {
1150     struct depca_private *lp = (struct depca_private *)dev->priv;
1151 
1152     /* Null body since there is no framing error counter */
1153 
1154     return &lp->stats;
1155 }
1156 
1157 /*
1158 ** Set or clear the multicast filter for this adaptor.
1159 ** num_addrs == -1      Promiscuous mode, receive all packets
1160 ** num_addrs == 0       Normal mode, clear multicast list
1161 ** num_addrs > 0        Multicast mode, receive normal and MC packets, and do
1162 **                      best-effort filtering.
1163 */
1164 static void
1165 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1166 {
1167   struct depca_private *lp = (struct depca_private *)dev->priv;
1168   u_long ioaddr = dev->base_addr;
1169   
1170   if (irq2dev_map[dev->irq] != NULL) {
1171     while(dev->tbusy);                /* Stop ring access */
1172     set_bit(0, (void*)&dev->tbusy);
1173     while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1174 
1175     STOP_DEPCA;                       /* Temporarily stop the depca.  */
1176     depca_init_ring(dev);             /* Initialize the descriptor rings */
1177 
1178     if (num_addrs >= 0) {
1179       SetMulticastFilter(dev, num_addrs, (char *)addrs);
1180       lp->init_block.mode &= ~PROM;   /* Unset promiscuous mode */
1181     } else {
1182       lp->init_block.mode |= PROM;    /* Set promiscuous mode */
1183     }
1184 
1185     LoadCSRs(dev);                    /* Reload CSR3 */
1186     InitRestartDepca(dev);            /* Resume normal operation. */
1187     dev->tbusy = 0;                   /* Unlock the TX ring */
1188   }
1189 }
1190 
1191 /*
1192 ** Calculate the hash code and update the logical address filter
1193 ** from a list of ethernet multicast addresses.
1194 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1195 ** LANCE calculates its hash codes big endian.
1196 */
1197 static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1198 {
1199   struct depca_private *lp = (struct depca_private *)dev->priv;
1200   int i, j, bit, byte;
1201   u16 hashcode;
1202   s32 crc, poly = CRC_POLYNOMIAL_BE;
1203 
1204   if (num_addrs == HASH_TABLE_LEN) {       /* Set all multicast bits */
1205     for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
1206       lp->init_block.mcast_table[i] = (char)0xff;
1207     }
1208   } else {
1209     /* Clear the multicast table first */
1210     for (i=0; i<(HASH_TABLE_LEN>>3); i++){
1211       lp->init_block.mcast_table[i]=0;
1212     }
1213 
1214     /* Add multicast addresses */
1215     for (i=0;i<num_addrs;i++) {            /* for each address in the list */
1216       if ((*addrs & 0x01) == 1) {          /* multicast address? */ 
1217         crc = 0xffffffff;                  /* init CRC for each address */
1218         for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
1219           /* process each address bit */ 
1220           for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1221             crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
1222           }
1223         }
1224         hashcode = (crc & 1);              /* hashcode is 6 LSb of CRC ... */
1225         for (j=0;j<5;j++) {                /* ... in reverse order. */
1226           hashcode = (hashcode << 1) | ((crc>>=1) & 1);
1227         }                                      
1228         
1229         
1230         byte = hashcode >> 3;              /* bit[3-5] -> byte in filter */
1231         bit = 1 << (hashcode & 0x07);      /* bit[0-2] -> bit in byte */
1232         lp->init_block.mcast_table[byte] |= bit;
1233       } else {                             /* skip this address */
1234         addrs += ETH_ALEN;
1235       }
1236     }
1237   }
1238 
1239   return;
1240 }
1241 
1242 /*
1243 ** ISA bus I/O device probe
1244 */
1245 static void isa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1246 {
1247   int i = num_depcas, maxSlots;
1248   s32 ports[] = DEPCA_IO_PORTS;
1249 
1250   if (!ioaddr && autoprobed) return ;          /* Been here before ! */
1251   if (ioaddr > 0x400) return;                  /* EISA Address */
1252   if (i >= MAX_NUM_DEPCAS) return;             /* Too many ISA adapters */
1253 
1254   if (ioaddr == 0) {                           /* Autoprobing */
1255     maxSlots = MAX_NUM_DEPCAS;
1256   } else {                                     /* Probe a specific location */
1257     ports[i] = ioaddr;
1258     maxSlots = i + 1;
1259   }
1260 
1261   for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
1262     if (DevicePresent(ports[i]) == 0) { 
1263       if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1264         if ((dev = alloc_device(dev, ports[i])) != NULL) {
1265           if (depca_hw_init(dev, ports[i]) == 0) {
1266             num_depcas++;
1267           }
1268           num_eth++;
1269         }
1270       } else if (autoprobed) {
1271         printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]);
1272       }
1273     }
1274   }
1275 
1276   return;
1277 }
1278 
1279 /*
1280 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1281 ** the motherboard. Upto 15 EISA devices are supported.
1282 */
1283 static void eisa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1284 {
1285   int i, maxSlots;
1286   u_long iobase;
1287   char name[DEPCA_STRLEN];
1288 
1289   if (!ioaddr && autoprobed) return ;            /* Been here before ! */
1290   if ((ioaddr < 0x400) && (ioaddr > 0)) return;  /* ISA Address */
1291 
1292   if (ioaddr == 0) {                           /* Autoprobing */
1293     iobase = EISA_SLOT_INC;                    /* Get the first slot address */
1294     i = 1;
1295     maxSlots = MAX_EISA_SLOTS;
1296   } else {                                     /* Probe a specific location */
1297     iobase = ioaddr;
1298     i = (ioaddr >> 12);
1299     maxSlots = i + 1;
1300   }
1301   if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
1302 
1303   for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1304     if (EISA_signature(name, EISA_ID)) {
1305       if (DevicePresent(iobase) == 0) { 
1306         if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1307           if ((dev = alloc_device(dev, iobase)) != NULL) {
1308             if (depca_hw_init(dev, iobase) == 0) {
1309               num_depcas++;
1310             }
1311             num_eth++;
1312           }
1313         } else if (autoprobed) {
1314           printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase);
1315         }
1316       }
1317     }
1318   }
1319 
1320   return;
1321 }
1322 
1323 /*
1324 ** Allocate the device by pointing to the next available space in the
1325 ** device structure. Should one not be available, it is created.
1326 */
1327 static struct device *alloc_device(struct device *dev, u_long iobase)
     /* [previous][next][first][last][top][bottom][index][help] */
1328 {
1329   int addAutoProbe = 0;
1330   struct device *tmp = NULL, *ret;
1331   int (*init)(struct device *) = NULL;
1332 
1333   /*
1334   ** Check the device structures for an end of list or unused device
1335   */
1336   if (!loading_module) {
1337     while (dev->next != NULL) {
1338       if ((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) break;
1339       dev = dev->next;                     /* walk through eth device list */
1340       num_eth++;                           /* increment eth device number */
1341     }
1342 
1343     /*
1344     ** If an autoprobe is requested for another device, we must re-insert
1345     ** the request later in the list. Remember the current information.
1346     */
1347     if ((dev->base_addr == 0) && (num_depcas > 0)) {
1348       addAutoProbe++;
1349       tmp = dev->next;                     /* point to the next device */
1350       init = dev->init;                    /* remember the probe function */
1351     }
1352 
1353     /*
1354     ** If at end of list and can't use current entry, malloc one up. 
1355     ** If memory could not be allocated, print an error message.
1356     */
1357     if ((dev->next == NULL) &&  
1358         !((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0))){
1359       dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1360                                            GFP_KERNEL);
1361 
1362       dev = dev->next;                     /* point to the new device */
1363       if (dev == NULL) {
1364         printk("eth%d: Device not initialised, insufficient memory\n",
1365                num_eth);
1366       } else {
1367         /*
1368         ** If the memory was allocated, point to the new memory area
1369         ** and initialize it (name, I/O address, next device (NULL) and
1370         ** initialisation probe routine).
1371         */
1372         dev->name = (char *)(dev + sizeof(struct device));
1373         if (num_eth > 9999) {
1374           sprintf(dev->name,"eth????");    /* New device name */
1375         } else {
1376           sprintf(dev->name,"eth%d", num_eth);/* New device name */
1377         }
1378         dev->base_addr = iobase;           /* assign the io address */
1379         dev->next = NULL;                  /* mark the end of list */
1380         dev->init = &depca_probe;          /* initialisation routine */
1381         num_depcas++;
1382       }
1383     }
1384     ret = dev;                             /* return current struct, or NULL */
1385   
1386     /*
1387     ** Now figure out what to do with the autoprobe that has to be inserted.
1388     ** Firstly, search the (possibly altered) list for an empty space.
1389     */
1390     if (ret != NULL) {
1391       if (addAutoProbe) {
1392         for (;(tmp->next!=NULL) && (tmp->base_addr!=DEPCA_NDA); tmp=tmp->next);
1393 
1394         /*
1395         ** If no more device structures and can't use the current one, malloc
1396         ** one up. If memory could not be allocated, print an error message.
1397         */
1398         if ((tmp->next == NULL) && !(tmp->base_addr == DEPCA_NDA)) {
1399           tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1400                                                GFP_KERNEL);
1401           tmp = tmp->next;                     /* point to the new device */
1402           if (tmp == NULL) {
1403             printk("%s: Insufficient memory to extend the device list.\n", 
1404                    dev->name);
1405           } else {
1406             /*
1407             ** If the memory was allocated, point to the new memory area
1408             ** and initialize it (name, I/O address, next device (NULL) and
1409             ** initialisation probe routine).
1410             */
1411             tmp->name = (char *)(tmp + sizeof(struct device));
1412             if (num_eth > 9999) {
1413               sprintf(tmp->name,"eth????");       /* New device name */
1414             } else {
1415               sprintf(tmp->name,"eth%d", num_eth);/* New device name */
1416             }
1417             tmp->base_addr = 0;                /* re-insert the io address */
1418             tmp->next = NULL;                  /* mark the end of list */
1419             tmp->init = init;                  /* initialisation routine */
1420           }
1421         } else {                               /* structure already exists */
1422           tmp->base_addr = 0;                  /* re-insert the io address */
1423         }
1424       }
1425     }
1426   } else {
1427     ret = dev;
1428   }
1429 
1430   return ret;
1431 }
1432 
1433 /*
1434 ** Look for a particular board name in the on-board Remote Diagnostics
1435 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1436 ** base address.
1437 */
1438 static void DepcaSignature(char *name, u_long paddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1439 {
1440   u_int i,j,k;
1441   char *signatures[] = DEPCA_SIGNATURE;
1442   char tmpstr[16];
1443 
1444   for (i=0;i<16;i++) {                  /* copy the first 16 bytes of ROM to */
1445     tmpstr[i] = readb(paddr+0xc000+i);  /* a temporary string */
1446   }
1447 
1448   strcpy(name,"");
1449   for (i=0;*signatures[i]!='\0' && *name=='\0';i++) {
1450     for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
1451       if (signatures[i][k] == tmpstr[j]) {              /* track signature */
1452         k++;
1453       } else {                     /* lost signature; begin search again */
1454         k=0;
1455       }
1456     }
1457     if (k == strlen(signatures[i])) {
1458       strcpy(name,signatures[i]);
1459     }
1460   }
1461 
1462   adapter = i - 1;
1463 
1464   return;
1465 }
1466 
1467 /*
1468 ** Look for a special sequence in the Ethernet station address PROM that
1469 ** is common across all DEPCA products. Note that the original DEPCA needs
1470 ** its ROM address counter to be initialized and enabled. Only enable
1471 ** if the first address octet is a 0x08 - this minimises the chances of
1472 ** messing around with some other hardware, but it assumes that this DEPCA
1473 ** card initialized itself correctly.
1474 ** 
1475 ** Search the Ethernet address ROM for the signature. Since the ROM address
1476 ** counter can start at an arbitrary point, the search must include the entire
1477 ** probe sequence length plus the (length_of_the_signature - 1).
1478 ** Stop the search IMMEDIATELY after the signature is found so that the
1479 ** PROM address counter is correctly positioned at the start of the
1480 ** ethernet address for later read out.
1481 */
1482 static int DevicePresent(u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1483 {
1484   union {
1485     struct {
1486       u32 a;
1487       u32 b;
1488     } llsig;
1489     char Sig[sizeof(u32) << 1];
1490   } dev;
1491   short sigLength=0;
1492   s8 data;
1493   s16 nicsr;
1494   int i, j, status = 0;
1495 
1496   data = inb(DEPCA_PROM);                /* clear counter on DEPCA */
1497   data = inb(DEPCA_PROM);                /* read data */
1498 
1499   if (data == 0x08) {                    /* Enable counter on DEPCA */
1500     nicsr = inb(DEPCA_NICSR);
1501     nicsr |= AAC;
1502     outb(nicsr, DEPCA_NICSR);
1503   }
1504   
1505   dev.llsig.a = ETH_PROM_SIG;
1506   dev.llsig.b = ETH_PROM_SIG;
1507   sigLength = sizeof(u32) << 1;
1508 
1509   for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1510     data = inb(DEPCA_PROM);
1511     if (dev.Sig[j] == data) {    /* track signature */
1512       j++;
1513     } else {                     /* lost signature; begin search again */
1514       if (data == dev.Sig[0]) {  /* rare case.... */
1515         j=1;
1516       } else {
1517         j=0;
1518       }
1519     }
1520   }
1521 
1522   if (j!=sigLength) {
1523     status = -ENODEV;           /* search failed */
1524   }
1525 
1526   return status;
1527 }
1528 
1529 /*
1530 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1531 ** reason: access the upper half of the PROM with x=0; access the lower half
1532 ** with x=1.
1533 */
1534 static int get_hw_addr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1535 {
1536   u_long ioaddr = dev->base_addr;
1537   int i, k, tmp, status = 0;
1538   u_short j, x, chksum;
1539 
1540   x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1541 
1542   for (i=0,k=0,j=0;j<3;j++) {
1543     k <<= 1 ;
1544     if (k > 0xffff) k-=0xffff;
1545 
1546     k += (u_char) (tmp = inb(DEPCA_PROM + x));
1547     dev->dev_addr[i++] = (u_char) tmp;
1548     k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1549     dev->dev_addr[i++] = (u_char) tmp;
1550 
1551     if (k > 0xffff) k-=0xffff;
1552   }
1553   if (k == 0xffff) k=0;
1554 
1555   chksum = (u_char) inb(DEPCA_PROM + x);
1556   chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1557   if (k != chksum) status = -1;
1558 
1559   return status;
1560 }
1561 
1562 /*
1563 ** Load a packet into the shared memory
1564 */
1565 static int load_packet(struct device *dev, struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
1566 {
1567   struct depca_private *lp = (struct depca_private *)dev->priv;
1568   int i, entry, end, len, status = 0;
1569 
1570   entry = lp->tx_new;                          /* Ring around buffer number. */
1571   end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1572   if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {/* Enough room? */
1573     /* 
1574     ** Caution: the write order is important here... don't set up the
1575     ** ownership rights until all the other information is in place.
1576     */
1577     if (end < entry) {                         /* wrapped buffer */
1578       len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1579       memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
1580       memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
1581     } else {                                   /* linear buffer */
1582       memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
1583     }
1584 
1585     /* set up the buffer descriptors */
1586     len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1587     for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1588                                                /* clean out flags */
1589       writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1590       writew(0x0000, &lp->tx_ring[i].misc);       /* clears other error flags */
1591       writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);/* packet length in buffer */
1592       len -= TX_BUFF_SZ;
1593     }
1594                                                /* clean out flags */
1595     writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1596     writew(0x0000, &lp->tx_ring[end].misc);       /* clears other error flags */
1597     writew(-len, &lp->tx_ring[end].length);       /* packet length in last buff */
1598 
1599                                                /* start of packet */
1600     writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1601                                                /* end of packet */
1602     writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1603 
1604     for (i=end; i!=entry; --i) {
1605                                                /* ownership of packet */
1606       writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1607       if (i == 0) i=lp->txRingMask+1;
1608     }   
1609     writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1610  
1611     lp->tx_new = (++end) & lp->txRingMask;     /* update current pointers */
1612   } else {
1613     status = -1;
1614   }
1615 
1616   return status;
1617 }
1618 
1619 /*
1620 ** Look for a particular board name in the EISA configuration space
1621 */
1622 static int EISA_signature(char *name, s32 eisa_id)
     /* [previous][next][first][last][top][bottom][index][help] */
1623 {
1624   u_int i;
1625   char *signatures[] = DEPCA_SIGNATURE;
1626   char ManCode[DEPCA_STRLEN];
1627   union {
1628     s32 ID;
1629     char Id[4];
1630   } Eisa;
1631   int status = 0;
1632 
1633   *name = '\0';
1634   Eisa.ID = inl(eisa_id);
1635 
1636   ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1637   ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1638   ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1639   ManCode[3]=((Eisa.Id[2]&0x0f)+0x30);
1640   ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1641   ManCode[5]='\0';
1642 
1643   for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1644     if (strstr(ManCode, signatures[i]) != NULL) {
1645       strcpy(name,ManCode);
1646       status = 1;
1647     }
1648   }
1649 
1650   return status;
1651 }
1652 
1653 /*
1654 ** Perform IOCTL call functions here. Some are privileged operations and the
1655 ** effective uid is checked in those cases.
1656 */
1657 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
1658 {
1659   struct depca_private *lp = (struct depca_private *)dev->priv;
1660   struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1661   int i, status = 0;
1662   u_long ioaddr = dev->base_addr;
1663   union {
1664     u8  addr[(HASH_TABLE_LEN * ETH_ALEN)];
1665     u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1666     u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1667   } tmp;
1668 
1669   switch(ioc->cmd) {
1670   case DEPCA_GET_HWADDR:             /* Get the hardware address */
1671     for (i=0; i<ETH_ALEN; i++) {
1672       tmp.addr[i] = dev->dev_addr[i];
1673     }
1674     ioc->len = ETH_ALEN;
1675     if (!(status = verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len))) {
1676       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1677     }
1678 
1679     break;
1680   case DEPCA_SET_HWADDR:             /* Set the hardware address */
1681     if (suser()) {
1682       if (!(status = verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN))) {
1683         memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1684         for (i=0; i<ETH_ALEN; i++) {
1685           dev->dev_addr[i] = tmp.addr[i];
1686         }
1687         while(dev->tbusy);              /* Stop ring access */
1688         set_bit(0, (void*)&dev->tbusy);
1689         while(lp->tx_old != lp->tx_new);/* Wait for the ring to empty */
1690 
1691         STOP_DEPCA;                     /* Temporarily stop the depca.  */
1692         depca_init_ring(dev);           /* Initialize the descriptor rings */
1693         LoadCSRs(dev);                  /* Reload CSR3 */
1694         InitRestartDepca(dev);          /* Resume normal operation. */
1695         dev->tbusy = 0;                 /* Unlock the TX ring */
1696       }
1697     } else {
1698       status = -EPERM;
1699     }
1700 
1701     break;
1702   case DEPCA_SET_PROM:               /* Set Promiscuous Mode */
1703     if (suser()) {
1704       while(dev->tbusy);                /* Stop ring access */
1705       set_bit(0, (void*)&dev->tbusy);
1706       while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1707 
1708       STOP_DEPCA;                       /* Temporarily stop the depca.  */
1709       depca_init_ring(dev);             /* Initialize the descriptor rings */
1710       lp->init_block.mode |= PROM;      /* Set promiscuous mode */
1711 
1712       LoadCSRs(dev);                    /* Reload CSR3 */
1713       InitRestartDepca(dev);            /* Resume normal operation. */
1714       dev->tbusy = 0;                   /* Unlock the TX ring */
1715     } else {
1716       status = -EPERM;
1717     }
1718 
1719     break;
1720   case DEPCA_CLR_PROM:               /* Clear Promiscuous Mode */
1721     if (suser()) {
1722       while(dev->tbusy);                /* Stop ring access */
1723       set_bit(0, (void*)&dev->tbusy);
1724       while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1725 
1726       STOP_DEPCA;                       /* Temporarily stop the depca.  */
1727       depca_init_ring(dev);             /* Initialize the descriptor rings */
1728       lp->init_block.mode &= ~PROM;     /* Clear promiscuous mode */
1729 
1730       LoadCSRs(dev);                    /* Reload CSR3 */
1731       InitRestartDepca(dev);            /* Resume normal operation. */
1732       dev->tbusy = 0;                   /* Unlock the TX ring */
1733     } else {
1734       status = -EPERM;
1735     }
1736 
1737     break;
1738   case DEPCA_SAY_BOO:                /* Say "Boo!" to the kernel log file */
1739     printk("%s: Boo!\n", dev->name);
1740 
1741     break;
1742   case DEPCA_GET_MCA:                /* Get the multicast address table */
1743     ioc->len = (HASH_TABLE_LEN >> 3);
1744     if (!(status = verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1745       memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len); 
1746     }
1747 
1748     break;
1749   case DEPCA_SET_MCA:                /* Set a multicast address */
1750     if (suser()) {
1751       if (ioc->len != HASH_TABLE_LEN) {         /* MCA changes */
1752         if (!(status=verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len))) {
1753           memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1754           set_multicast_list(dev, ioc->len, tmp.addr);
1755         }
1756       } else {
1757         set_multicast_list(dev, ioc->len, NULL);
1758       }
1759     } else {
1760       status = -EPERM;
1761     }
1762 
1763     break;
1764   case DEPCA_CLR_MCA:                /* Clear all multicast addresses */
1765     if (suser()) {
1766       set_multicast_list(dev, 0, NULL);
1767     } else {
1768       status = -EPERM;
1769     }
1770 
1771     break;
1772   case DEPCA_MCA_EN:                 /* Enable pass all multicast addressing */
1773     if (suser()) {
1774       set_multicast_list(dev, HASH_TABLE_LEN, NULL);
1775     } else {
1776       status = -EPERM;
1777     }
1778 
1779     break;
1780   case DEPCA_GET_STATS:              /* Get the driver statistics */
1781     cli();
1782     ioc->len = sizeof(lp->pktStats);
1783     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1784       memcpy_tofs(ioc->data, &lp->pktStats, ioc->len); 
1785     }
1786     sti();
1787 
1788     break;
1789   case DEPCA_CLR_STATS:              /* Zero out the driver statistics */
1790     if (suser()) {
1791       cli();
1792       memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1793       sti();
1794     } else {
1795       status = -EPERM;
1796     }
1797 
1798     break;
1799   case DEPCA_GET_REG:                /* Get the DEPCA Registers */
1800     i=0;
1801     tmp.sval[i++] = inw(DEPCA_NICSR);
1802     outw(CSR0, DEPCA_ADDR);              /* status register */
1803     tmp.sval[i++] = inw(DEPCA_DATA);
1804     memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
1805     ioc->len = i+sizeof(struct depca_init);
1806     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1807       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1808     }
1809 
1810     break;
1811   default:
1812     status = -EOPNOTSUPP;
1813   }
1814 
1815   return status;
1816 }
1817 
1818 #ifdef MODULE
1819 char kernel_version[] = UTS_RELEASE;
1820 static struct device thisDepca = {
1821   "        ",  /* device name inserted by /linux/drivers/net/net_init.c */
1822   0, 0, 0, 0,
1823   0x200, 7,   /* I/O address, IRQ */
1824   0, 0, 0, NULL, depca_probe };
1825 
1826 static int irq=7;       /* EDIT THESE LINE FOR YOUR CONFIGURATION */
1827 static int io=0x200;    /* Or use the irq= io= options to insmod */
1828         
1829 int
1830 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1831 {
1832   thisDepca.irq=irq;
1833   thisDepca.base_addr=io;
1834   if (register_netdev(&thisDepca) != 0)
1835     return -EIO;
1836 
1837   return 0;
1838 }
1839 
1840 void
1841 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1842 {
1843   if (MOD_IN_USE) {
1844     printk("%s: device busy, remove delayed\n",thisDepca.name);
1845   } else {
1846     release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
1847     if (thisDepca.priv) {
1848       kfree_s(thisDepca.priv, sizeof(struct depca_private));
1849       thisDepca.priv = NULL;
1850     }
1851 
1852     unregister_netdev(&thisDepca);
1853   }
1854 }
1855 #endif /* MODULE */
1856 
1857 
1858 /*
1859  * Local variables:
1860  *  kernel-compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"
1861  *
1862  *  module-compile-command: "gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"
1863  * End:
1864  */

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