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

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