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