root/drivers/net/depca.c

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

DEFINITIONS

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

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

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