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

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