root/drivers/net/depca.c

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

DEFINITIONS

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

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

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