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,int num_addrs,void *addrs);
 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,int num_addrs,char *addrs);
 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.8x  ", readl(&lp->rx_ring[i].base));
 700         }
 701       }
 702       printk("...0x%8.8x\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.8x  ", readl(&lp->tx_ring[i].base));
 707         }
 708       }
 709       printk("...0x%8.8x\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.4x\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.8x\n",readl(&p->rx_ring));
 724       printk("\ttx_ring at: 0x%8.8x\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, 0, NULL);
 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 ** num_addrs == -1      Promiscuous mode, receive all packets
1155 ** num_addrs == 0       Normal mode, clear multicast list
1156 ** num_addrs > 0        Multicast mode, receive normal and MC packets, and do
1157 **                      best-effort filtering.
1158 */
1159 static void
1160 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1161 {
1162   struct depca_private *lp = (struct depca_private *)dev->priv;
1163   u_long ioaddr = dev->base_addr;
1164   
1165   if (irq2dev_map[dev->irq] != NULL) {
1166     while(dev->tbusy);                /* Stop ring access */
1167     set_bit(0, (void*)&dev->tbusy);
1168     while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1169 
1170     STOP_DEPCA;                       /* Temporarily stop the depca.  */
1171     depca_init_ring(dev);             /* Initialize the descriptor rings */
1172 
1173     if (num_addrs >= 0) {
1174       SetMulticastFilter(dev, num_addrs, (char *)addrs);
1175       lp->init_block.mode &= ~PROM;   /* Unset promiscuous mode */
1176     } else {
1177       lp->init_block.mode |= PROM;    /* Set promiscuous mode */
1178     }
1179 
1180     LoadCSRs(dev);                    /* Reload CSR3 */
1181     InitRestartDepca(dev);            /* Resume normal operation. */
1182     dev->tbusy = 0;                   /* Unlock the TX ring */
1183   }
1184 }
1185 
1186 /*
1187 ** Calculate the hash code and update the logical address filter
1188 ** from a list of ethernet multicast addresses.
1189 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1190 ** LANCE calculates its hash codes big endian.
1191 */
1192 static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
1193 {
1194   struct depca_private *lp = (struct depca_private *)dev->priv;
1195   int i, j, bit, byte;
1196   u16 hashcode;
1197   s32 crc, poly = CRC_POLYNOMIAL_BE;
1198 
1199   if (num_addrs == HASH_TABLE_LEN) {       /* Set all multicast bits */
1200     for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
1201       lp->init_block.mcast_table[i] = (char)0xff;
1202     }
1203   } else {
1204     /* Clear the multicast table first */
1205     for (i=0; i<(HASH_TABLE_LEN>>3); i++){
1206       lp->init_block.mcast_table[i]=0;
1207     }
1208 
1209     /* Add multicast addresses */
1210     for (i=0;i<num_addrs;i++) {            /* for each address in the list */
1211       if ((*addrs & 0x01) == 1) {          /* multicast address? */ 
1212         crc = 0xffffffff;                  /* init CRC for each address */
1213         for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
1214           /* process each address bit */ 
1215           for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1216             crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
1217           }
1218         }
1219         hashcode = (crc & 1);              /* hashcode is 6 LSb of CRC ... */
1220         for (j=0;j<5;j++) {                /* ... in reverse order. */
1221           hashcode = (hashcode << 1) | ((crc>>=1) & 1);
1222         }                                      
1223         
1224         
1225         byte = hashcode >> 3;              /* bit[3-5] -> byte in filter */
1226         bit = 1 << (hashcode & 0x07);      /* bit[0-2] -> bit in byte */
1227         lp->init_block.mcast_table[byte] |= bit;
1228       } else {                             /* skip this address */
1229         addrs += ETH_ALEN;
1230       }
1231     }
1232   }
1233 
1234   return;
1235 }
1236 
1237 /*
1238 ** ISA bus I/O device probe
1239 */
1240 static void isa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1241 {
1242   int i = num_depcas, maxSlots;
1243   s32 ports[] = DEPCA_IO_PORTS;
1244 
1245   if (!ioaddr && autoprobed) return ;          /* Been here before ! */
1246   if (ioaddr > 0x400) return;                  /* EISA Address */
1247   if (i >= MAX_NUM_DEPCAS) return;             /* Too many ISA adapters */
1248 
1249   if (ioaddr == 0) {                           /* Autoprobing */
1250     maxSlots = MAX_NUM_DEPCAS;
1251   } else {                                     /* Probe a specific location */
1252     ports[i] = ioaddr;
1253     maxSlots = i + 1;
1254   }
1255 
1256   for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
1257     if (DevicePresent(ports[i]) == 0) { 
1258       if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1259         if ((dev = alloc_device(dev, ports[i])) != NULL) {
1260           if (depca_hw_init(dev, ports[i]) == 0) {
1261             num_depcas++;
1262           }
1263           num_eth++;
1264         }
1265       } else if (autoprobed) {
1266         printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]);
1267       }
1268     }
1269   }
1270 
1271   return;
1272 }
1273 
1274 /*
1275 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1276 ** the motherboard. Upto 15 EISA devices are supported.
1277 */
1278 static void eisa_probe(struct device *dev, u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1279 {
1280   int i, maxSlots;
1281   u_long iobase;
1282   char name[DEPCA_STRLEN];
1283 
1284   if (!ioaddr && autoprobed) return ;            /* Been here before ! */
1285   if ((ioaddr < 0x400) && (ioaddr > 0)) return;  /* ISA Address */
1286 
1287   if (ioaddr == 0) {                           /* Autoprobing */
1288     iobase = EISA_SLOT_INC;                    /* Get the first slot address */
1289     i = 1;
1290     maxSlots = MAX_EISA_SLOTS;
1291   } else {                                     /* Probe a specific location */
1292     iobase = ioaddr;
1293     i = (ioaddr >> 12);
1294     maxSlots = i + 1;
1295   }
1296   if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
1297 
1298   for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1299     if (EISA_signature(name, EISA_ID)) {
1300       if (DevicePresent(iobase) == 0) { 
1301         if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1302           if ((dev = alloc_device(dev, iobase)) != NULL) {
1303             if (depca_hw_init(dev, iobase) == 0) {
1304               num_depcas++;
1305             }
1306             num_eth++;
1307           }
1308         } else if (autoprobed) {
1309           printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase);
1310         }
1311       }
1312     }
1313   }
1314 
1315   return;
1316 }
1317 
1318 /*
1319 ** Allocate the device by pointing to the next available space in the
1320 ** device structure. Should one not be available, it is created.
1321 */
1322 static struct device *alloc_device(struct device *dev, u_long iobase)
     /* [previous][next][first][last][top][bottom][index][help] */
1323 {
1324   int addAutoProbe = 0;
1325   struct device *tmp = NULL, *ret;
1326   int (*init)(struct device *) = NULL;
1327 
1328   /*
1329   ** Check the device structures for an end of list or unused device
1330   */
1331   if (!loading_module) {
1332     while (dev->next != NULL) {
1333       if ((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) break;
1334       dev = dev->next;                     /* walk through eth device list */
1335       num_eth++;                           /* increment eth device number */
1336     }
1337 
1338     /*
1339     ** If an autoprobe is requested for another device, we must re-insert
1340     ** the request later in the list. Remember the current information.
1341     */
1342     if ((dev->base_addr == 0) && (num_depcas > 0)) {
1343       addAutoProbe++;
1344       tmp = dev->next;                     /* point to the next device */
1345       init = dev->init;                    /* remember the probe function */
1346     }
1347 
1348     /*
1349     ** If at end of list and can't use current entry, malloc one up. 
1350     ** If memory could not be allocated, print an error message.
1351     */
1352     if ((dev->next == NULL) &&  
1353         !((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0))){
1354       dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1355                                            GFP_KERNEL);
1356 
1357       dev = dev->next;                     /* point to the new device */
1358       if (dev == NULL) {
1359         printk("eth%d: Device not initialised, insufficient memory\n",
1360                num_eth);
1361       } else {
1362         /*
1363         ** If the memory was allocated, point to the new memory area
1364         ** and initialize it (name, I/O address, next device (NULL) and
1365         ** initialisation probe routine).
1366         */
1367         dev->name = (char *)(dev + sizeof(struct device));
1368         if (num_eth > 9999) {
1369           sprintf(dev->name,"eth????");    /* New device name */
1370         } else {
1371           sprintf(dev->name,"eth%d", num_eth);/* New device name */
1372         }
1373         dev->base_addr = iobase;           /* assign the io address */
1374         dev->next = NULL;                  /* mark the end of list */
1375         dev->init = &depca_probe;          /* initialisation routine */
1376         num_depcas++;
1377       }
1378     }
1379     ret = dev;                             /* return current struct, or NULL */
1380   
1381     /*
1382     ** Now figure out what to do with the autoprobe that has to be inserted.
1383     ** Firstly, search the (possibly altered) list for an empty space.
1384     */
1385     if (ret != NULL) {
1386       if (addAutoProbe) {
1387         for (;(tmp->next!=NULL) && (tmp->base_addr!=DEPCA_NDA); tmp=tmp->next);
1388 
1389         /*
1390         ** If no more device structures and can't use the current one, malloc
1391         ** one up. If memory could not be allocated, print an error message.
1392         */
1393         if ((tmp->next == NULL) && !(tmp->base_addr == DEPCA_NDA)) {
1394           tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1395                                                GFP_KERNEL);
1396           tmp = tmp->next;                     /* point to the new device */
1397           if (tmp == NULL) {
1398             printk("%s: Insufficient memory to extend the device list.\n", 
1399                    dev->name);
1400           } else {
1401             /*
1402             ** If the memory was allocated, point to the new memory area
1403             ** and initialize it (name, I/O address, next device (NULL) and
1404             ** initialisation probe routine).
1405             */
1406             tmp->name = (char *)(tmp + sizeof(struct device));
1407             if (num_eth > 9999) {
1408               sprintf(tmp->name,"eth????");       /* New device name */
1409             } else {
1410               sprintf(tmp->name,"eth%d", num_eth);/* New device name */
1411             }
1412             tmp->base_addr = 0;                /* re-insert the io address */
1413             tmp->next = NULL;                  /* mark the end of list */
1414             tmp->init = init;                  /* initialisation routine */
1415           }
1416         } else {                               /* structure already exists */
1417           tmp->base_addr = 0;                  /* re-insert the io address */
1418         }
1419       }
1420     }
1421   } else {
1422     ret = dev;
1423   }
1424 
1425   return ret;
1426 }
1427 
1428 /*
1429 ** Look for a particular board name in the on-board Remote Diagnostics
1430 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1431 ** base address.
1432 */
1433 static void DepcaSignature(char *name, u_long paddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1434 {
1435   u_int i,j,k;
1436   const char *signatures[] = DEPCA_SIGNATURE;
1437   char tmpstr[16];
1438 
1439   for (i=0;i<16;i++) {                  /* copy the first 16 bytes of ROM to */
1440     tmpstr[i] = readb(paddr+0xc000+i);  /* a temporary string */
1441   }
1442 
1443   strcpy(name,"");
1444   for (i=0;*signatures[i]!='\0' && *name=='\0';i++) {
1445     for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
1446       if (signatures[i][k] == tmpstr[j]) {              /* track signature */
1447         k++;
1448       } else {                     /* lost signature; begin search again */
1449         k=0;
1450       }
1451     }
1452     if (k == strlen(signatures[i])) {
1453       strcpy(name,signatures[i]);
1454     }
1455   }
1456 
1457   adapter = i - 1;
1458 
1459   return;
1460 }
1461 
1462 /*
1463 ** Look for a special sequence in the Ethernet station address PROM that
1464 ** is common across all DEPCA products. Note that the original DEPCA needs
1465 ** its ROM address counter to be initialized and enabled. Only enable
1466 ** if the first address octet is a 0x08 - this minimises the chances of
1467 ** messing around with some other hardware, but it assumes that this DEPCA
1468 ** card initialized itself correctly.
1469 ** 
1470 ** Search the Ethernet address ROM for the signature. Since the ROM address
1471 ** counter can start at an arbitrary point, the search must include the entire
1472 ** probe sequence length plus the (length_of_the_signature - 1).
1473 ** Stop the search IMMEDIATELY after the signature is found so that the
1474 ** PROM address counter is correctly positioned at the start of the
1475 ** ethernet address for later read out.
1476 */
1477 static int DevicePresent(u_long ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1478 {
1479   union {
1480     struct {
1481       u32 a;
1482       u32 b;
1483     } llsig;
1484     char Sig[sizeof(u32) << 1];
1485   } dev;
1486   short sigLength=0;
1487   s8 data;
1488   s16 nicsr;
1489   int i, j, status = 0;
1490 
1491   data = inb(DEPCA_PROM);                /* clear counter on DEPCA */
1492   data = inb(DEPCA_PROM);                /* read data */
1493 
1494   if (data == 0x08) {                    /* Enable counter on DEPCA */
1495     nicsr = inb(DEPCA_NICSR);
1496     nicsr |= AAC;
1497     outb(nicsr, DEPCA_NICSR);
1498   }
1499   
1500   dev.llsig.a = ETH_PROM_SIG;
1501   dev.llsig.b = ETH_PROM_SIG;
1502   sigLength = sizeof(u32) << 1;
1503 
1504   for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1505     data = inb(DEPCA_PROM);
1506     if (dev.Sig[j] == data) {    /* track signature */
1507       j++;
1508     } else {                     /* lost signature; begin search again */
1509       if (data == dev.Sig[0]) {  /* rare case.... */
1510         j=1;
1511       } else {
1512         j=0;
1513       }
1514     }
1515   }
1516 
1517   if (j!=sigLength) {
1518     status = -ENODEV;           /* search failed */
1519   }
1520 
1521   return status;
1522 }
1523 
1524 /*
1525 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1526 ** reason: access the upper half of the PROM with x=0; access the lower half
1527 ** with x=1.
1528 */
1529 static int get_hw_addr(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1530 {
1531   u_long ioaddr = dev->base_addr;
1532   int i, k, tmp, status = 0;
1533   u_short j, x, chksum;
1534 
1535   x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1536 
1537   for (i=0,k=0,j=0;j<3;j++) {
1538     k <<= 1 ;
1539     if (k > 0xffff) k-=0xffff;
1540 
1541     k += (u_char) (tmp = inb(DEPCA_PROM + x));
1542     dev->dev_addr[i++] = (u_char) tmp;
1543     k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1544     dev->dev_addr[i++] = (u_char) tmp;
1545 
1546     if (k > 0xffff) k-=0xffff;
1547   }
1548   if (k == 0xffff) k=0;
1549 
1550   chksum = (u_char) inb(DEPCA_PROM + x);
1551   chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1552   if (k != chksum) status = -1;
1553 
1554   return status;
1555 }
1556 
1557 /*
1558 ** Load a packet into the shared memory
1559 */
1560 static int load_packet(struct device *dev, struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
1561 {
1562   struct depca_private *lp = (struct depca_private *)dev->priv;
1563   int i, entry, end, len, status = 0;
1564 
1565   entry = lp->tx_new;                          /* Ring around buffer number. */
1566   end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1567   if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {/* Enough room? */
1568     /* 
1569     ** Caution: the write order is important here... don't set up the
1570     ** ownership rights until all the other information is in place.
1571     */
1572     if (end < entry) {                         /* wrapped buffer */
1573       len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1574       memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
1575       memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
1576     } else {                                   /* linear buffer */
1577       memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
1578     }
1579 
1580     /* set up the buffer descriptors */
1581     len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1582     for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1583                                                /* clean out flags */
1584       writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1585       writew(0x0000, &lp->tx_ring[i].misc);       /* clears other error flags */
1586       writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);/* packet length in buffer */
1587       len -= TX_BUFF_SZ;
1588     }
1589                                                /* clean out flags */
1590     writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1591     writew(0x0000, &lp->tx_ring[end].misc);       /* clears other error flags */
1592     writew(-len, &lp->tx_ring[end].length);       /* packet length in last buff */
1593 
1594                                                /* start of packet */
1595     writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1596                                                /* end of packet */
1597     writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1598 
1599     for (i=end; i!=entry; --i) {
1600                                                /* ownership of packet */
1601       writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1602       if (i == 0) i=lp->txRingMask+1;
1603     }   
1604     writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1605  
1606     lp->tx_new = (++end) & lp->txRingMask;     /* update current pointers */
1607   } else {
1608     status = -1;
1609   }
1610 
1611   return status;
1612 }
1613 
1614 /*
1615 ** Look for a particular board name in the EISA configuration space
1616 */
1617 static int EISA_signature(char *name, s32 eisa_id)
     /* [previous][next][first][last][top][bottom][index][help] */
1618 {
1619   u_int i;
1620   const char *signatures[] = DEPCA_SIGNATURE;
1621   char ManCode[DEPCA_STRLEN];
1622   union {
1623     s32 ID;
1624     char Id[4];
1625   } Eisa;
1626   int status = 0;
1627 
1628   *name = '\0';
1629   Eisa.ID = inl(eisa_id);
1630 
1631   ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1632   ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1633   ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1634   ManCode[3]=((Eisa.Id[2]&0x0f)+0x30);
1635   ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1636   ManCode[5]='\0';
1637 
1638   for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1639     if (strstr(ManCode, signatures[i]) != NULL) {
1640       strcpy(name,ManCode);
1641       status = 1;
1642     }
1643   }
1644 
1645   return status;
1646 }
1647 
1648 /*
1649 ** Perform IOCTL call functions here. Some are privileged operations and the
1650 ** effective uid is checked in those cases.
1651 */
1652 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
1653 {
1654   struct depca_private *lp = (struct depca_private *)dev->priv;
1655   struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1656   int i, status = 0;
1657   u_long ioaddr = dev->base_addr;
1658   union {
1659     u8  addr[(HASH_TABLE_LEN * ETH_ALEN)];
1660     u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1661     u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1662   } tmp;
1663 
1664   switch(ioc->cmd) {
1665   case DEPCA_GET_HWADDR:             /* Get the hardware address */
1666     for (i=0; i<ETH_ALEN; i++) {
1667       tmp.addr[i] = dev->dev_addr[i];
1668     }
1669     ioc->len = ETH_ALEN;
1670     if (!(status = verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len))) {
1671       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1672     }
1673 
1674     break;
1675   case DEPCA_SET_HWADDR:             /* Set the hardware address */
1676     if (suser()) {
1677       if (!(status = verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN))) {
1678         memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1679         for (i=0; i<ETH_ALEN; i++) {
1680           dev->dev_addr[i] = tmp.addr[i];
1681         }
1682         while(dev->tbusy);              /* Stop ring access */
1683         set_bit(0, (void*)&dev->tbusy);
1684         while(lp->tx_old != lp->tx_new);/* Wait for the ring to empty */
1685 
1686         STOP_DEPCA;                     /* Temporarily stop the depca.  */
1687         depca_init_ring(dev);           /* Initialize the descriptor rings */
1688         LoadCSRs(dev);                  /* Reload CSR3 */
1689         InitRestartDepca(dev);          /* Resume normal operation. */
1690         dev->tbusy = 0;                 /* Unlock the TX ring */
1691       }
1692     } else {
1693       status = -EPERM;
1694     }
1695 
1696     break;
1697   case DEPCA_SET_PROM:               /* Set Promiscuous Mode */
1698     if (suser()) {
1699       while(dev->tbusy);                /* Stop ring access */
1700       set_bit(0, (void*)&dev->tbusy);
1701       while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1702 
1703       STOP_DEPCA;                       /* Temporarily stop the depca.  */
1704       depca_init_ring(dev);             /* Initialize the descriptor rings */
1705       lp->init_block.mode |= PROM;      /* Set promiscuous mode */
1706 
1707       LoadCSRs(dev);                    /* Reload CSR3 */
1708       InitRestartDepca(dev);            /* Resume normal operation. */
1709       dev->tbusy = 0;                   /* Unlock the TX ring */
1710     } else {
1711       status = -EPERM;
1712     }
1713 
1714     break;
1715   case DEPCA_CLR_PROM:               /* Clear Promiscuous Mode */
1716     if (suser()) {
1717       while(dev->tbusy);                /* Stop ring access */
1718       set_bit(0, (void*)&dev->tbusy);
1719       while(lp->tx_old != lp->tx_new);  /* Wait for the ring to empty */
1720 
1721       STOP_DEPCA;                       /* Temporarily stop the depca.  */
1722       depca_init_ring(dev);             /* Initialize the descriptor rings */
1723       lp->init_block.mode &= ~PROM;     /* Clear promiscuous mode */
1724 
1725       LoadCSRs(dev);                    /* Reload CSR3 */
1726       InitRestartDepca(dev);            /* Resume normal operation. */
1727       dev->tbusy = 0;                   /* Unlock the TX ring */
1728     } else {
1729       status = -EPERM;
1730     }
1731 
1732     break;
1733   case DEPCA_SAY_BOO:                /* Say "Boo!" to the kernel log file */
1734     printk("%s: Boo!\n", dev->name);
1735 
1736     break;
1737   case DEPCA_GET_MCA:                /* Get the multicast address table */
1738     ioc->len = (HASH_TABLE_LEN >> 3);
1739     if (!(status = verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1740       memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len); 
1741     }
1742 
1743     break;
1744   case DEPCA_SET_MCA:                /* Set a multicast address */
1745     if (suser()) {
1746       if (ioc->len != HASH_TABLE_LEN) {         /* MCA changes */
1747         if (!(status=verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len))) {
1748           memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1749           set_multicast_list(dev, ioc->len, tmp.addr);
1750         }
1751       } else {
1752         set_multicast_list(dev, ioc->len, NULL);
1753       }
1754     } else {
1755       status = -EPERM;
1756     }
1757 
1758     break;
1759   case DEPCA_CLR_MCA:                /* Clear all multicast addresses */
1760     if (suser()) {
1761       set_multicast_list(dev, 0, NULL);
1762     } else {
1763       status = -EPERM;
1764     }
1765 
1766     break;
1767   case DEPCA_MCA_EN:                 /* Enable pass all multicast addressing */
1768     if (suser()) {
1769       set_multicast_list(dev, HASH_TABLE_LEN, NULL);
1770     } else {
1771       status = -EPERM;
1772     }
1773 
1774     break;
1775   case DEPCA_GET_STATS:              /* Get the driver statistics */
1776     cli();
1777     ioc->len = sizeof(lp->pktStats);
1778     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1779       memcpy_tofs(ioc->data, &lp->pktStats, ioc->len); 
1780     }
1781     sti();
1782 
1783     break;
1784   case DEPCA_CLR_STATS:              /* Zero out the driver statistics */
1785     if (suser()) {
1786       cli();
1787       memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1788       sti();
1789     } else {
1790       status = -EPERM;
1791     }
1792 
1793     break;
1794   case DEPCA_GET_REG:                /* Get the DEPCA Registers */
1795     i=0;
1796     tmp.sval[i++] = inw(DEPCA_NICSR);
1797     outw(CSR0, DEPCA_ADDR);              /* status register */
1798     tmp.sval[i++] = inw(DEPCA_DATA);
1799     memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
1800     ioc->len = i+sizeof(struct depca_init);
1801     if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1802       memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1803     }
1804 
1805     break;
1806   default:
1807     status = -EOPNOTSUPP;
1808   }
1809 
1810   return status;
1811 }
1812 
1813 #ifdef MODULE
1814 static char devicename[9] = { 0, };
1815 static struct device thisDepca = {
1816   devicename, /* device name is inserted by linux/drivers/net/net_init.c */
1817   0, 0, 0, 0,
1818   0x200, 7,   /* I/O address, IRQ */
1819   0, 0, 0, NULL, depca_probe };
1820 
1821 static int irq=7;       /* EDIT THESE LINE FOR YOUR CONFIGURATION */
1822 static int io=0x200;    /* Or use the irq= io= options to insmod */
1823         
1824 int
1825 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1826 {
1827   if (io == 0)
1828     printk("depca: You should not use auto-probing with insmod!\n");
1829   thisDepca.irq=irq;
1830   thisDepca.base_addr=io;
1831   if (register_netdev(&thisDepca) != 0)
1832     return -EIO;
1833 
1834   return 0;
1835 }
1836 
1837 void
1838 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1839 {
1840     release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
1841     if (thisDepca.priv) {
1842       kfree_s(thisDepca.priv, sizeof(struct depca_private));
1843       thisDepca.priv = NULL;
1844     }
1845 
1846     unregister_netdev(&thisDepca);
1847 }
1848 #endif /* MODULE */
1849 
1850 
1851 /*
1852  * Local variables:
1853  *  kernel-compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"
1854  *
1855  *  module-compile-command: "gcc -D__KERNEL__ -DMODULE -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O2 -m486 -c depca.c"
1856  * End:
1857  */

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