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

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