Import 2.3.10pre5
[davej-history.git] / drivers / net / depca.c
blob1be3c5dda3639fbe8136f0486e774228c63b285b
1 /* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux.
3 Written 1994, 1995 by David C. Davies.
6 Copyright 1994 David C. Davies
7 and
8 United States Government
9 (as represented by the Director, National Security Agency).
11 Copyright 1995 Digital Equipment Corporation.
14 This software may be used and distributed according to the terms of
15 the GNU Public License, incorporated herein by reference.
17 This driver is written for the Digital Equipment Corporation series
18 of DEPCA and EtherWORKS ethernet cards:
20 DEPCA (the original)
21 DE100
22 DE101
23 DE200 Turbo
24 DE201 Turbo
25 DE202 Turbo (TP BNC)
26 DE210
27 DE422 (EISA)
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.
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.
37 I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from)
38 a DECstation 5000/200.
40 The author may be reached at davies@maniac.ultranet.com
42 =========================================================================
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.
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
66 Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this
67 driver.
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).
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]).
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.
98 ************************************************************************
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.
108 I am unable to test 2 cards together for now, so this code is
109 unchecked. All reports, good or bad, are welcome.
111 ************************************************************************
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.
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).
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:
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!
142 Note that autoprobing is not allowed in loadable modules - the system is
143 already up and running and you're messing with interrupts.
145 To unload a module, turn off the associated interface
146 'ifconfig eth?? down' then 'rmmod depca'.
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.
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).
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).
162 Currently known bugs/limitations:
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.
170 ************************************************************************
171 TO DO:
172 ------
175 Revision History
176 ----------------
178 Version Date Description
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>
227 =========================================================================
230 static const char *version = "depca.c:v0.51 1999/6/27 davies@maniac.ultranet.com\n";
232 #include <linux/config.h>
233 #include <linux/module.h>
235 #include <linux/kernel.h>
236 #include <linux/sched.h>
237 #include <linux/string.h>
238 #include <linux/ptrace.h>
239 #include <linux/errno.h>
240 #include <linux/ioport.h>
241 #include <linux/malloc.h>
242 #include <linux/interrupt.h>
243 #include <linux/delay.h>
244 #include <linux/init.h>
245 #include <asm/uaccess.h>
246 #include <asm/bitops.h>
247 #include <asm/io.h>
248 #include <asm/dma.h>
250 #include <linux/netdevice.h>
251 #include <linux/etherdevice.h>
252 #include <linux/skbuff.h>
254 #include <linux/time.h>
255 #include <linux/types.h>
256 #include <linux/unistd.h>
257 #include <linux/ctype.h>
259 #ifdef CONFIG_MCA
260 #include <linux/mca.h>
261 #endif
263 #include "depca.h"
265 #ifdef DEPCA_DEBUG
266 static int depca_debug = DEPCA_DEBUG;
267 #else
268 static int depca_debug = 1;
269 #endif
271 #define DEPCA_NDA 0xffe0 /* No Device Address */
274 ** Ethernet PROM defines
276 #define PROBE_LENGTH 32
277 #define ETH_PROM_SIG 0xAA5500FFUL
280 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
281 ** here is <= to the amount of shared memory set up by the board switches.
282 ** The number of descriptors MUST BE A POWER OF 2.
284 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
286 #define NUM_RX_DESC 8 /* Number of RX descriptors */
287 #define NUM_TX_DESC 8 /* Number of TX descriptors */
288 #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
289 #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
291 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
292 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
295 ** EISA bus defines
297 #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
298 #define MAX_EISA_SLOTS 16
299 #define EISA_SLOT_INC 0x1000
302 ** ISA Bus defines
304 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
305 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
306 #define DEPCA_TOTAL_SIZE 0x10
307 static short mem_chkd = 0;
310 ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
312 #define DE212_ID 0x6def
315 ** Name <-> Adapter mapping
317 #define DEPCA_SIGNATURE {"DEPCA",\
318 "DE100","DE101",\
319 "DE200","DE201","DE202",\
320 "DE210","DE212",\
321 "DE422",\
323 static enum {
324 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
325 } adapter;
328 ** Miscellaneous info...
330 #define DEPCA_STRLEN 16
331 #define MAX_NUM_DEPCAS 2
334 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
335 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
336 ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
337 ** and hence the RX descriptor ring's first entry.
339 #define ALIGN4 ((u_long)4 - 1) /* 1 longword align */
340 #define ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
341 #define ALIGN ALIGN8 /* Keep the LANCE happy... */
344 ** The DEPCA Rx and Tx ring descriptors.
346 struct depca_rx_desc {
347 volatile s32 base;
348 s16 buf_length; /* This length is negative 2's complement! */
349 s16 msg_length; /* This length is "normal". */
352 struct depca_tx_desc {
353 volatile s32 base;
354 s16 length; /* This length is negative 2's complement! */
355 s16 misc; /* Errors and TDR info */
358 #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
359 to LANCE memory address space */
362 ** The Lance initialization block, described in databook, in common memory.
364 struct depca_init {
365 u16 mode; /* Mode register */
366 u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
367 u8 mcast_table[8]; /* Multicast Hash Table. */
368 u32 rx_ring; /* Rx ring base pointer & ring length */
369 u32 tx_ring; /* Tx ring base pointer & ring length */
372 #define DEPCA_PKT_STAT_SZ 16
373 #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
374 increase DEPCA_PKT_STAT_SZ */
375 struct depca_private {
376 char devname[DEPCA_STRLEN]; /* Device Product String */
377 char adapter_name[DEPCA_STRLEN];/* /proc/ioports string */
378 char adapter; /* Adapter type */
379 char mca_slot; /* MCA slot, if MCA else -1 */ struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
380 struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
381 struct depca_init init_block;/* Shadow Initialization block */
382 char *rx_memcpy[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
383 char *tx_memcpy[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
384 u_long bus_offset; /* (E)ISA bus address offset vs LANCE */
385 u_long sh_mem; /* Physical start addr of shared mem area */
386 u_long dma_buffs; /* LANCE Rx and Tx buffers start address. */
387 int rx_new, tx_new; /* The next free ring entry */
388 int rx_old, tx_old; /* The ring entries to be free()ed. */
389 struct net_device_stats stats;
390 struct { /* Private stats counters */
391 u32 bins[DEPCA_PKT_STAT_SZ];
392 u32 unicast;
393 u32 multicast;
394 u32 broadcast;
395 u32 excessive_collisions;
396 u32 tx_underruns;
397 u32 excessive_underruns;
398 } pktStats;
399 int txRingMask; /* TX ring mask */
400 int rxRingMask; /* RX ring mask */
401 s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
402 s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
406 ** The transmit ring full condition is described by the tx_old and tx_new
407 ** pointers by:
408 ** tx_old = tx_new Empty ring
409 ** tx_old = tx_new+1 Full ring
410 ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
412 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
413 lp->tx_old+lp->txRingMask-lp->tx_new:\
414 lp->tx_old -lp->tx_new-1)
417 ** Public Functions
419 static int depca_open(struct device *dev);
420 static int depca_start_xmit(struct sk_buff *skb, struct device *dev);
421 static void depca_interrupt(int irq, void *dev_id, struct pt_regs *regs);
422 static int depca_close(struct device *dev);
423 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd);
424 static struct net_device_stats *depca_get_stats(struct device *dev);
425 static void set_multicast_list(struct device *dev);
428 ** Private functions
430 static int depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot);
431 static void depca_init_ring(struct device *dev);
432 static int depca_rx(struct device *dev);
433 static int depca_tx(struct device *dev);
435 static void LoadCSRs(struct device *dev);
436 static int InitRestartDepca(struct device *dev);
437 static void DepcaSignature(char *name, u_long paddr);
438 static int DevicePresent(u_long ioaddr);
439 static int get_hw_addr(struct device *dev);
440 static int EISA_signature(char *name, s32 eisa_id);
441 static void SetMulticastFilter(struct device *dev);
442 static void isa_probe(struct device *dev, u_long iobase);
443 static void eisa_probe(struct device *dev, u_long iobase);
444 #ifdef CONFIG_MCA
445 static void mca_probe(struct device *dev, u_long iobase);
446 #endif
447 static struct device *alloc_device(struct device *dev, u_long iobase);
448 static int depca_dev_index(char *s);
449 static struct device *insert_device(struct device *dev, u_long iobase, int (*init)(struct device *));
450 static int load_packet(struct device *dev, struct sk_buff *skb);
451 static void depca_dbg_open(struct device *dev);
453 #ifdef MODULE
454 int init_module(void);
455 void cleanup_module(void);
456 static int autoprobed = 1, loading_module = 1;
457 # else
458 static u_char de1xx_irq[] __initdata = {2,3,4,5,7,9,0};
459 static u_char de2xx_irq[] __initdata = {5,9,10,11,15,0};
460 static u_char de422_irq[] __initdata = {5,9,10,11,0};
461 static u_char *depca_irq;
462 static int autoprobed = 0, loading_module = 0;
463 #endif /* MODULE */
465 static char name[DEPCA_STRLEN];
466 static int num_depcas = 0, num_eth = 0;
467 static int mem=0; /* For loadable module assignment
468 use insmod mem=0x????? .... */
469 static char *adapter_name = '\0'; /* If no PROM when loadable module
470 use insmod adapter_name=DE??? ...
473 ** Miscellaneous defines...
475 #define STOP_DEPCA \
476 outw(CSR0, DEPCA_ADDR);\
477 outw(STOP, DEPCA_DATA)
479 int __init
480 depca_probe(struct device *dev)
482 int tmp = num_depcas, status = -ENODEV;
483 u_long iobase = dev->base_addr;
485 if ((iobase == 0) && loading_module){
486 printk("Autoprobing is not supported when loading a module based driver.\n");
487 status = -EIO;
488 } else {
489 #ifdef CONFIG_MCA
490 mca_probe(dev, iobase);
491 #endif
492 isa_probe(dev, iobase);
493 eisa_probe(dev, iobase);
495 if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
496 printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name,
497 iobase);
501 ** Walk the device list to check that at least one device
502 ** initialised OK
504 for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
506 if (dev->priv) status = 0;
507 if (iobase == 0) autoprobed = 1;
510 return status;
513 static int __init
514 depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot)
516 struct depca_private *lp;
517 int i, j, offset, netRAM, mem_len, status=0;
518 s16 nicsr;
519 u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
521 STOP_DEPCA;
523 nicsr = inb(DEPCA_NICSR);
524 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
525 outb(nicsr, DEPCA_NICSR);
527 if (inw(DEPCA_DATA) == STOP) {
528 do {
529 strcpy(name, (adapter_name ? adapter_name : ""));
530 mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]);
531 DepcaSignature(name, mem_start);
532 } while (!mem && mem_base[mem_chkd] && (adapter == unknown));
534 if ((adapter != unknown) && mem_start) { /* found a DEPCA device */
535 dev->base_addr = ioaddr;
537 if (mca_slot != -1) {
538 printk("%s: %s at 0x%04lx (MCA slot %d)", dev->name, name,
539 ioaddr, mca_slot);
540 } else if ((ioaddr & 0x0fff) == DEPCA_EISA_IO_PORTS) { /* EISA slot address */
541 printk("%s: %s at 0x%04lx (EISA slot %d)",
542 dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f));
543 } else { /* ISA port address */
544 printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
547 printk(", h/w address ");
548 status = get_hw_addr(dev);
549 for (i=0; i<ETH_ALEN - 1; i++) { /* get the ethernet address */
550 printk("%2.2x:", dev->dev_addr[i]);
552 printk("%2.2x", dev->dev_addr[i]);
554 if (status == 0) {
555 /* Set up the maximum amount of network RAM(kB) */
556 netRAM = ((adapter != DEPCA) ? 64 : 48);
557 if ((nicsr & _128KB) && (adapter == de422)) netRAM = 128;
558 offset = 0x0000;
560 /* Shared Memory Base Address */
561 if (nicsr & BUF) {
562 offset = 0x8000; /* 32kbyte RAM offset*/
563 nicsr &= ~BS; /* DEPCA RAM in top 32k */
564 netRAM -= 32;
566 mem_start += offset; /* (E)ISA start address */
567 if ((mem_len = (NUM_RX_DESC*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ) +
568 NUM_TX_DESC*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ) +
569 sizeof(struct depca_init))) <=
570 (netRAM<<10)) {
571 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
573 /* Enable the shadow RAM. */
574 if (adapter != DEPCA) {
575 nicsr |= SHE;
576 outb(nicsr, DEPCA_NICSR);
579 /* Define the device private memory */
580 dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
581 if (dev->priv == NULL)
582 return -ENOMEM;
583 lp = (struct depca_private *)dev->priv;
584 memset((char *)dev->priv, 0, sizeof(struct depca_private));
585 lp->adapter = adapter;
586 lp->mca_slot = mca_slot;
587 sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
588 request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name);
590 /* Initialisation Block */
591 lp->sh_mem = mem_start;
592 mem_start += sizeof(struct depca_init);
594 /* Tx & Rx descriptors (aligned to a quadword boundary) */
595 mem_start = (mem_start + ALIGN) & ~ALIGN;
596 lp->rx_ring = (struct depca_rx_desc *)mem_start;
598 mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
599 lp->tx_ring = (struct depca_tx_desc *)mem_start;
601 mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
602 lp->bus_offset = mem_start & 0x00ff0000;
603 mem_start &= LA_MASK; /* LANCE re-mapped start address */
605 lp->dma_buffs = mem_start;
607 /* Finish initialising the ring information. */
608 lp->rxRingMask = NUM_RX_DESC - 1;
609 lp->txRingMask = NUM_TX_DESC - 1;
611 /* Calculate Tx/Rx RLEN size for the descriptors. */
612 for (i=0, j = lp->rxRingMask; j>0; i++) {
613 j >>= 1;
615 lp->rx_rlen = (s32)(i << 29);
616 for (i=0, j = lp->txRingMask; j>0; i++) {
617 j >>= 1;
619 lp->tx_rlen = (s32)(i << 29);
621 /* Load the initialisation block */
622 depca_init_ring(dev);
624 /* Initialise the control and status registers */
625 LoadCSRs(dev);
627 /* Enable DEPCA board interrupts for autoprobing */
628 nicsr = ((nicsr & ~IM)|IEN);
629 outb(nicsr, DEPCA_NICSR);
631 /* To auto-IRQ we enable the initialization-done and DMA err,
632 interrupts. For now we will always get a DMA error. */
633 if (dev->irq < 2) {
634 #ifndef MODULE
635 unsigned char irqnum;
636 autoirq_setup(0);
638 /* Assign the correct irq list */
639 switch (lp->adapter) {
640 case DEPCA:
641 case de100:
642 case de101:
643 depca_irq = de1xx_irq;
644 break;
645 case de200:
646 case de201:
647 case de202:
648 case de210:
649 case de212:
650 depca_irq = de2xx_irq;
651 break;
652 case de422:
653 depca_irq = de422_irq;
654 break;
657 /* Trigger an initialization just for the interrupt. */
658 outw(INEA | INIT, DEPCA_DATA);
660 irqnum = autoirq_report(1);
661 if (!irqnum) {
662 printk(" and failed to detect IRQ line.\n");
663 status = -ENXIO;
664 } else {
665 for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) {
666 if (irqnum == depca_irq[i]) {
667 dev->irq = irqnum;
668 printk(" and uses IRQ%d.\n", dev->irq);
672 if (!dev->irq) {
673 printk(" but incorrect IRQ line detected.\n");
674 status = -ENXIO;
677 #endif /* MODULE */
678 } else {
679 printk(" and assigned IRQ%d.\n", dev->irq);
681 if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE);
682 } else {
683 printk(",\n requests %dkB RAM: only %dkB is available!\n",
684 (mem_len>>10), netRAM);
685 status = -ENXIO;
687 } else {
688 printk(" which has an Ethernet PROM CRC error.\n");
689 status = -ENXIO;
691 } else {
692 status = -ENXIO;
694 if (!status) {
695 if (depca_debug > 1) {
696 printk(version);
699 /* The DEPCA-specific entries in the device structure. */
700 dev->open = &depca_open;
701 dev->hard_start_xmit = &depca_start_xmit;
702 dev->stop = &depca_close;
703 dev->get_stats = &depca_get_stats;
704 dev->set_multicast_list = &set_multicast_list;
705 dev->do_ioctl = &depca_ioctl;
707 dev->mem_start = 0;
709 /* Fill in the generic field of the device structure. */
710 ether_setup(dev);
711 } else { /* Incorrectly initialised hardware */
712 if (dev->priv) {
713 kfree_s(dev->priv, sizeof(struct depca_private));
714 dev->priv = NULL;
717 } else {
718 status = -ENXIO;
721 return status;
725 static int
726 depca_open(struct device *dev)
728 struct depca_private *lp = (struct depca_private *)dev->priv;
729 u_long ioaddr = dev->base_addr;
730 s16 nicsr;
731 int status = 0;
733 STOP_DEPCA;
734 nicsr = inb(DEPCA_NICSR);
736 /* Make sure the shadow RAM is enabled */
737 if (adapter != DEPCA) {
738 nicsr |= SHE;
739 outb(nicsr, DEPCA_NICSR);
742 /* Re-initialize the DEPCA... */
743 depca_init_ring(dev);
744 LoadCSRs(dev);
746 depca_dbg_open(dev);
748 if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) {
749 printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
750 status = -EAGAIN;
751 } else {
753 /* Enable DEPCA board interrupts and turn off LED */
754 nicsr = ((nicsr & ~IM & ~LED)|IEN);
755 outb(nicsr, DEPCA_NICSR);
756 outw(CSR0,DEPCA_ADDR);
758 dev->tbusy = 0;
759 dev->interrupt = 0;
760 dev->start = 1;
762 status = InitRestartDepca(dev);
764 if (depca_debug > 1){
765 printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
766 printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
770 MOD_INC_USE_COUNT;
772 return status;
775 /* Initialize the lance Rx and Tx descriptor rings. */
776 static void
777 depca_init_ring(struct device *dev)
779 struct depca_private *lp = (struct depca_private *)dev->priv;
780 u_int i;
781 u_long p;
783 /* Lock out other processes whilst setting up the hardware */
784 test_and_set_bit(0, (void *)&dev->tbusy);
786 lp->rx_new = lp->tx_new = 0;
787 lp->rx_old = lp->tx_old = 0;
789 /* Initialize the base addresses and length of each buffer in the ring */
790 for (i = 0; i <= lp->rxRingMask; i++) {
791 writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base);
792 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
793 lp->rx_memcpy[i]=(char *)(p+lp->bus_offset);
795 for (i = 0; i <= lp->txRingMask; i++) {
796 writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,
797 &lp->tx_ring[i].base);
798 lp->tx_memcpy[i]=(char *)(p+lp->bus_offset);
801 /* Set up the initialization block */
802 lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK) | lp->rx_rlen;
803 lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK) | lp->tx_rlen;
805 SetMulticastFilter(dev);
807 for (i = 0; i < ETH_ALEN; i++) {
808 lp->init_block.phys_addr[i] = dev->dev_addr[i];
811 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
813 return;
817 ** Writes a socket buffer to TX descriptor ring and starts transmission
819 static int
820 depca_start_xmit(struct sk_buff *skb, struct device *dev)
822 struct depca_private *lp = (struct depca_private *)dev->priv;
823 u_long ioaddr = dev->base_addr;
824 int status = 0;
826 /* Transmitter timeout, serious problems. */
827 if (dev->tbusy) {
828 int tickssofar = jiffies - dev->trans_start;
829 if (tickssofar < 1*HZ) {
830 status = -1;
831 } else {
832 printk("%s: transmit timed out, status %04x, resetting.\n",
833 dev->name, inw(DEPCA_DATA));
835 STOP_DEPCA;
836 depca_init_ring(dev);
837 LoadCSRs(dev);
838 dev->interrupt = UNMASK_INTERRUPTS;
839 dev->start = 1;
840 dev->tbusy=0;
841 dev->trans_start = jiffies;
842 InitRestartDepca(dev);
844 return status;
845 } else if (skb->len > 0) {
846 /* Enforce 1 process per h/w access */
847 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
848 printk("%s: Transmitter access conflict.\n", dev->name);
849 status = -1;
850 } else {
851 if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
852 status = load_packet(dev, skb);
854 if (!status) {
855 /* Trigger an immediate send demand. */
856 outw(CSR0, DEPCA_ADDR);
857 outw(INEA | TDMD, DEPCA_DATA);
859 dev->trans_start = jiffies;
860 dev_kfree_skb(skb);
862 if (TX_BUFFS_AVAIL) {
863 dev->tbusy=0;
865 } else {
866 status = -1;
871 return status;
875 ** The DEPCA interrupt handler.
877 static void
878 depca_interrupt(int irq, void *dev_id, struct pt_regs *regs)
880 struct device *dev = dev_id;
881 struct depca_private *lp;
882 s16 csr0, nicsr;
883 u_long ioaddr;
885 if (dev == NULL) {
886 printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
887 } else {
888 lp = (struct depca_private *)dev->priv;
889 ioaddr = dev->base_addr;
891 if (dev->interrupt)
892 printk("%s: Re-entering the interrupt handler.\n", dev->name);
894 dev->interrupt = MASK_INTERRUPTS;
896 /* mask the DEPCA board interrupts and turn on the LED */
897 nicsr = inb(DEPCA_NICSR);
898 nicsr |= (IM|LED);
899 outb(nicsr, DEPCA_NICSR);
901 outw(CSR0, DEPCA_ADDR);
902 csr0 = inw(DEPCA_DATA);
904 /* Acknowledge all of the current interrupt sources ASAP. */
905 outw(csr0 & INTE, DEPCA_DATA);
907 if (csr0 & RINT) /* Rx interrupt (packet arrived) */
908 depca_rx(dev);
910 if (csr0 & TINT) /* Tx interrupt (packet sent) */
911 depca_tx(dev);
913 if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) { /* any resources available? */
914 dev->tbusy = 0; /* clear TX busy flag */
915 mark_bh(NET_BH);
918 /* Unmask the DEPCA board interrupts and turn off the LED */
919 nicsr = (nicsr & ~IM & ~LED);
920 outb(nicsr, DEPCA_NICSR);
922 dev->interrupt = UNMASK_INTERRUPTS;
925 return;
928 static int
929 depca_rx(struct device *dev)
931 struct depca_private *lp = (struct depca_private *)dev->priv;
932 int i, entry;
933 s32 status;
935 for (entry=lp->rx_new;
936 !(readl(&lp->rx_ring[entry].base) & R_OWN);
937 entry=lp->rx_new){
938 status = readl(&lp->rx_ring[entry].base) >> 16 ;
939 if (status & R_STP) { /* Remember start of frame */
940 lp->rx_old = entry;
942 if (status & R_ENP) { /* Valid frame status */
943 if (status & R_ERR) { /* There was an error. */
944 lp->stats.rx_errors++; /* Update the error stats. */
945 if (status & R_FRAM) lp->stats.rx_frame_errors++;
946 if (status & R_OFLO) lp->stats.rx_over_errors++;
947 if (status & R_CRC) lp->stats.rx_crc_errors++;
948 if (status & R_BUFF) lp->stats.rx_fifo_errors++;
949 } else {
950 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
951 struct sk_buff *skb;
953 skb = dev_alloc_skb(pkt_len+2);
954 if (skb != NULL) {
955 unsigned char *buf;
956 skb_reserve(skb,2); /* 16 byte align the IP header */
957 buf = skb_put(skb,pkt_len);
958 skb->dev = dev;
959 if (entry < lp->rx_old) { /* Wrapped buffer */
960 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
961 memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len);
962 memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len);
963 } else { /* Linear buffer */
964 memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len);
968 ** Notify the upper protocol layers that there is another
969 ** packet to handle
971 skb->protocol=eth_type_trans(skb,dev);
972 netif_rx(skb);
975 ** Update stats
977 lp->stats.rx_packets++;
978 for (i=1; i<DEPCA_PKT_STAT_SZ-1; i++) {
979 if (pkt_len < (i*DEPCA_PKT_BIN_SZ)) {
980 lp->pktStats.bins[i]++;
981 i = DEPCA_PKT_STAT_SZ;
984 if (buf[0] & 0x01) { /* Multicast/Broadcast */
985 if ((*(s16 *)&buf[0] == -1) &&
986 (*(s16 *)&buf[2] == -1) &&
987 (*(s16 *)&buf[4] == -1)) {
988 lp->pktStats.broadcast++;
989 } else {
990 lp->pktStats.multicast++;
992 } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
993 (*(s16 *)&buf[2] == *(s16 *)&dev->dev_addr[2]) &&
994 (*(s16 *)&buf[4] == *(s16 *)&dev->dev_addr[4])) {
995 lp->pktStats.unicast++;
998 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
999 if (lp->pktStats.bins[0] == 0) { /* Reset counters */
1000 memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
1002 } else {
1003 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
1004 lp->stats.rx_dropped++; /* Really, deferred. */
1005 break;
1008 /* Change buffer ownership for this last frame, back to the adapter */
1009 for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
1010 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,
1011 &lp->rx_ring[lp->rx_old].base);
1013 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1017 ** Update entry information
1019 lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
1022 return 0;
1026 ** Buffer sent - check for buffer errors.
1028 static int
1029 depca_tx(struct device *dev)
1031 struct depca_private *lp = (struct depca_private *)dev->priv;
1032 int entry;
1033 s32 status;
1034 u_long ioaddr = dev->base_addr;
1036 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1037 status = readl(&lp->tx_ring[entry].base) >> 16 ;
1039 if (status < 0) { /* Packet not yet sent! */
1040 break;
1041 } else if (status & T_ERR) { /* An error occurred. */
1042 status = readl(&lp->tx_ring[entry].misc);
1043 lp->stats.tx_errors++;
1044 if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
1045 if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
1046 if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
1047 if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
1048 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1049 /* Trigger an immediate send demand. */
1050 outw(CSR0, DEPCA_ADDR);
1051 outw(INEA | TDMD, DEPCA_DATA);
1053 } else if (status & (T_MORE | T_ONE)) {
1054 lp->stats.collisions++;
1055 } else {
1056 lp->stats.tx_packets++;
1059 /* Update all the pointers */
1060 lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1063 return 0;
1066 static int
1067 depca_close(struct device *dev)
1069 struct depca_private *lp = (struct depca_private *)dev->priv;
1070 s16 nicsr;
1071 u_long ioaddr = dev->base_addr;
1073 dev->start = 0;
1074 dev->tbusy = 1;
1076 outw(CSR0, DEPCA_ADDR);
1078 if (depca_debug > 1) {
1079 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1080 dev->name, inw(DEPCA_DATA));
1084 ** We stop the DEPCA here -- it occasionally polls
1085 ** memory if we don't.
1087 outw(STOP, DEPCA_DATA);
1090 ** Give back the ROM in case the user wants to go to DOS
1092 if (lp->adapter != DEPCA) {
1093 nicsr = inb(DEPCA_NICSR);
1094 nicsr &= ~SHE;
1095 outb(nicsr, DEPCA_NICSR);
1099 ** Free the associated irq
1101 free_irq(dev->irq, dev);
1103 MOD_DEC_USE_COUNT;
1105 return 0;
1108 static void LoadCSRs(struct device *dev)
1110 struct depca_private *lp = (struct depca_private *)dev->priv;
1111 u_long ioaddr = dev->base_addr;
1113 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
1114 outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
1115 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
1116 outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
1117 outw(CSR3, DEPCA_ADDR); /* ALE control */
1118 outw(ACON, DEPCA_DATA);
1120 outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
1122 return;
1125 static int InitRestartDepca(struct device *dev)
1127 struct depca_private *lp = (struct depca_private *)dev->priv;
1128 u_long ioaddr = dev->base_addr;
1129 int i, status=0;
1131 /* Copy the shadow init_block to shared memory */
1132 memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1134 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
1135 outw(INIT, DEPCA_DATA); /* initialize DEPCA */
1137 /* wait for lance to complete initialisation */
1138 for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
1140 if (i!=100) {
1141 /* clear IDON by writing a "1", enable interrupts and start lance */
1142 outw(IDON | INEA | STRT, DEPCA_DATA);
1143 if (depca_debug > 2) {
1144 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1145 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1147 } else {
1148 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1149 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1150 status = -1;
1153 return status;
1156 static struct net_device_stats *
1157 depca_get_stats(struct device *dev)
1159 struct depca_private *lp = (struct depca_private *)dev->priv;
1161 /* Null body since there is no framing error counter */
1163 return &lp->stats;
1167 ** Set or clear the multicast filter for this adaptor.
1169 static void
1170 set_multicast_list(struct device *dev)
1172 struct depca_private *lp = (struct depca_private *)dev->priv;
1173 u_long ioaddr = dev->base_addr;
1175 if (dev) {
1176 while(dev->tbusy) barrier(); /* Stop ring access */
1177 set_bit(0, (void*)&dev->tbusy);
1178 while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1180 STOP_DEPCA; /* Temporarily stop the depca. */
1181 depca_init_ring(dev); /* Initialize the descriptor rings */
1183 if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
1184 lp->init_block.mode |= PROM;
1185 } else {
1186 SetMulticastFilter(dev);
1187 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
1190 LoadCSRs(dev); /* Reload CSR3 */
1191 InitRestartDepca(dev); /* Resume normal operation. */
1192 dev->tbusy = 0; /* Unlock the TX ring */
1197 ** Calculate the hash code and update the logical address filter
1198 ** from a list of ethernet multicast addresses.
1199 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1200 ** LANCE calculates its hash codes big endian.
1202 static void SetMulticastFilter(struct device *dev)
1204 struct depca_private *lp = (struct depca_private *)dev->priv;
1205 struct dev_mc_list *dmi=dev->mc_list;
1206 char *addrs;
1207 int i, j, bit, byte;
1208 u16 hashcode;
1209 s32 crc, poly = CRC_POLYNOMIAL_BE;
1211 if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
1212 for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
1213 lp->init_block.mcast_table[i] = (char)0xff;
1215 } else {
1216 for (i=0; i<(HASH_TABLE_LEN>>3); i++){ /* Clear the multicast table */
1217 lp->init_block.mcast_table[i]=0;
1219 /* Add multicast addresses */
1220 for (i=0;i<dev->mc_count;i++) { /* for each address in the list */
1221 addrs=dmi->dmi_addr;
1222 dmi=dmi->next;
1223 if ((*addrs & 0x01) == 1) { /* multicast address? */
1224 crc = 0xffffffff; /* init CRC for each address */
1225 for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
1226 /* process each address bit */
1227 for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1228 crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
1231 hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
1232 for (j=0;j<5;j++) { /* ... in reverse order. */
1233 hashcode = (hashcode << 1) | ((crc>>=1) & 1);
1237 byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
1238 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
1239 lp->init_block.mcast_table[byte] |= bit;
1244 return;
1247 #ifdef CONFIG_MCA
1249 ** Microchannel bus I/O device probe
1251 static void __init
1252 mca_probe(struct device *dev, u_long ioaddr)
1254 unsigned char pos[2];
1255 unsigned char where;
1256 unsigned long iobase;
1257 int irq;
1258 int slot = 0;
1261 ** See if we've been here before.
1263 if ((!ioaddr && autoprobed) || (ioaddr && !loading_module)) return;
1265 if (MCA_bus) {
1267 ** Search for the adapter. If an address has been given, search
1268 ** specifically for the card at that address. Otherwise find the
1269 ** first card in the system.
1271 while ((dev!=NULL) &&
1272 ((slot=mca_find_adapter(DE212_ID, slot)) != MCA_NOTFOUND)) {
1273 pos[0] = mca_read_stored_pos(slot, 2);
1274 pos[1] = mca_read_stored_pos(slot, 3);
1277 ** IO of card is handled by bits 1 and 2 of pos0.
1279 ** bit2 bit1 IO
1280 ** 0 0 0x2c00
1281 ** 0 1 0x2c10
1282 ** 1 0 0x2c20
1283 ** 1 1 0x2c30
1285 where = (pos[0] & 6) >> 1;
1286 iobase = 0x2c00 + (0x10 * where);
1288 if ((ioaddr) && (ioaddr != iobase)) {
1290 ** Card was found, but not at the right IO location. Continue
1291 ** scanning from the next MCA slot up for another card.
1293 slot++;
1294 continue;
1298 ** Found the adapter we were looking for. Now start setting it up.
1300 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1301 ** of pos1. Bits are as follows (from the ADF file):
1303 ** Bits
1304 ** 3 2 1 0 IRQ
1305 ** --------------------
1306 ** 0 0 1 0 5
1307 ** 0 0 0 1 9
1308 ** 0 1 0 0 10
1309 ** 1 0 0 0 11
1311 where = pos[1] & 0x0f;
1312 switch(where) {
1313 case 1:
1314 irq = 9;
1315 break;
1316 case 2:
1317 irq = 5;
1318 break;
1319 case 4:
1320 irq = 10;
1321 break;
1322 case 8:
1323 irq = 11;
1324 break;
1325 default:
1326 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev->name, where);
1327 return;
1331 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1332 ** They are mapped as follows:
1334 ** Bit
1335 ** 5 4 3 Memory Addresses
1336 ** 0 0 0 C0000-CFFFF (64K)
1337 ** 1 0 0 C8000-CFFFF (32K)
1338 ** 0 0 1 D0000-DFFFF (64K)
1339 ** 1 0 1 D8000-DFFFF (32K)
1340 ** 0 1 0 E0000-EFFFF (64K)
1341 ** 1 1 0 E8000-EFFFF (32K)
1343 where = (pos[0] & 0x18) >> 3;
1344 mem = 0xc0000 + (where * 0x10000);
1345 if (pos[0] & 0x20) {
1346 mem += 0x8000;
1350 ** Get everything allocated and initialized... (almost just
1351 ** like the ISA and EISA probes)
1353 if (DevicePresent(iobase) != 0) {
1355 ** If the MCA configuration says the card should be here,
1356 ** it really should be here.
1358 printk(KERN_ERR "%s: MCA reports card at 0x%lx but it is not
1359 responding.\n", dev->name, iobase);
1362 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1363 if ((dev = alloc_device(dev, iobase)) != NULL) {
1364 dev->irq = irq;
1365 if (depca_hw_init(dev, iobase, slot) == 0) {
1367 ** Adapter initialized correctly: Name it in
1368 ** /proc/mca.
1370 mca_set_adapter_name(slot, "DE210/212 Ethernet Adapter");
1371 mca_mark_as_used(slot);
1372 num_depcas++;
1374 num_eth++;
1376 } else if (autoprobed) {
1377 printk(KERN_WARNING "%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1381 ** If this is a probe by a module, return after setting up the
1382 ** given card.
1384 if (ioaddr) return;
1387 ** Set up to check the next slot and loop.
1389 slot++;
1393 return;
1395 #endif
1398 ** ISA bus I/O device probe
1400 static void __init
1401 isa_probe(struct device *dev, u_long ioaddr)
1403 int i = num_depcas, maxSlots;
1404 s32 ports[] = DEPCA_IO_PORTS;
1406 if (!ioaddr && autoprobed) return ; /* Been here before ! */
1407 if (ioaddr > 0x400) return; /* EISA Address */
1408 if (i >= MAX_NUM_DEPCAS) return; /* Too many ISA adapters */
1410 if (ioaddr == 0) { /* Autoprobing */
1411 maxSlots = MAX_NUM_DEPCAS;
1412 } else { /* Probe a specific location */
1413 ports[i] = ioaddr;
1414 maxSlots = i + 1;
1417 for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
1418 if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1419 if (DevicePresent(ports[i]) == 0) {
1420 if ((dev = alloc_device(dev, ports[i])) != NULL) {
1421 if (depca_hw_init(dev, ports[i], -1) == 0) {
1422 num_depcas++;
1424 num_eth++;
1427 } else if (autoprobed) {
1428 printk("%s: region already allocated at 0x%04x.\n", dev->name, ports[i]);
1432 return;
1436 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1437 ** the motherboard. Upto 15 EISA devices are supported.
1439 static void __init
1440 eisa_probe(struct device *dev, u_long ioaddr)
1442 int i, maxSlots;
1443 u_long iobase;
1444 char name[DEPCA_STRLEN];
1446 if (!ioaddr && autoprobed) return ; /* Been here before ! */
1447 if ((ioaddr < 0x400) && (ioaddr > 0)) return; /* ISA Address */
1449 if (ioaddr == 0) { /* Autoprobing */
1450 iobase = EISA_SLOT_INC; /* Get the first slot address */
1451 i = 1;
1452 maxSlots = MAX_EISA_SLOTS;
1453 } else { /* Probe a specific location */
1454 iobase = ioaddr;
1455 i = (ioaddr >> 12);
1456 maxSlots = i + 1;
1458 if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
1460 for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1461 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1462 if (EISA_signature(name, EISA_ID)) {
1463 if (DevicePresent(iobase) == 0) {
1464 if ((dev = alloc_device(dev, iobase)) != NULL) {
1465 if (depca_hw_init(dev, iobase, -1) == 0) {
1466 num_depcas++;
1468 num_eth++;
1472 } else if (autoprobed) {
1473 printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1477 return;
1481 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1482 ** found then check for an autoprobe or unused device location. If they
1483 ** are not available then insert a new device structure at the end of
1484 ** the current list.
1486 static struct device * __init
1487 alloc_device(struct device *dev, u_long iobase)
1489 struct device *adev = NULL;
1490 int fixed = 0, new_dev = 0;
1492 num_eth = depca_dev_index(dev->name);
1493 if (loading_module) return dev;
1495 while (1) {
1496 if (((dev->base_addr == DEPCA_NDA) || (dev->base_addr==0)) && !adev) {
1497 adev=dev;
1498 } else if ((dev->priv == NULL) && (dev->base_addr==iobase)) {
1499 fixed = 1;
1500 } else {
1501 if (dev->next == NULL) {
1502 new_dev = 1;
1503 } else if (strncmp(dev->next->name, "eth", 3) != 0) {
1504 new_dev = 1;
1507 if ((dev->next == NULL) || new_dev || fixed) break;
1508 dev = dev->next;
1509 num_eth++;
1511 if (adev && !fixed) {
1512 dev = adev;
1513 num_eth = depca_dev_index(dev->name);
1514 new_dev = 0;
1517 if (((dev->next == NULL) &&
1518 ((dev->base_addr != DEPCA_NDA) && (dev->base_addr != 0)) && !fixed) ||
1519 new_dev) {
1520 num_eth++; /* New device */
1521 dev = insert_device(dev, iobase, depca_probe);
1524 return dev;
1528 ** If at end of eth device list and can't use current entry, malloc
1529 ** one up. If memory could not be allocated, print an error message.
1531 static struct device * __init
1532 insert_device(struct device *dev, u_long iobase, int (*init)(struct device *))
1534 struct device *new;
1536 new = (struct device *)kmalloc(sizeof(struct device)+8, GFP_KERNEL);
1537 if (new == NULL) {
1538 printk("eth%d: Device not initialised, insufficient memory\n",num_eth);
1539 return NULL;
1540 } else {
1541 new->next = dev->next;
1542 dev->next = new;
1543 dev = dev->next; /* point to the new device */
1544 dev->name = (char *)(dev + 1);
1545 if (num_eth > 9999) {
1546 sprintf(dev->name,"eth????");/* New device name */
1547 } else {
1548 sprintf(dev->name,"eth%d", num_eth);/* New device name */
1550 dev->base_addr = iobase; /* assign the io address */
1551 dev->init = init; /* initialisation routine */
1554 return dev;
1557 static int __init
1558 depca_dev_index(char *s)
1560 int i=0, j=0;
1562 for (;*s; s++) {
1563 if (isdigit(*s)) {
1564 j=1;
1565 i = (i * 10) + (*s - '0');
1566 } else if (j) break;
1569 return i;
1573 ** Look for a particular board name in the on-board Remote Diagnostics
1574 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1575 ** base address.
1577 static void __init
1578 DepcaSignature(char *name, u_long paddr)
1580 u_int i,j,k;
1581 const char *signatures[] = DEPCA_SIGNATURE;
1582 char tmpstr[16];
1584 /* Copy the first 16 bytes of ROM */
1585 for (i=0;i<16;i++) {
1586 tmpstr[i] = readb(paddr+0xc000+i);
1589 /* Check if PROM contains a valid string */
1590 for (i=0;*signatures[i]!='\0';i++) {
1591 for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
1592 if (signatures[i][k] == tmpstr[j]) { /* track signature */
1593 k++;
1594 } else { /* lost signature; begin search again */
1595 k=0;
1598 if (k == strlen(signatures[i])) break;
1601 /* Check if name string is valid, provided there's no PROM */
1602 if (*name && (i == unknown)) {
1603 for (i=0;*signatures[i]!='\0';i++) {
1604 if (strcmp(name,signatures[i]) == 0) break;
1608 /* Update search results */
1609 strcpy(name,signatures[i]);
1610 adapter = i;
1612 return;
1616 ** Look for a special sequence in the Ethernet station address PROM that
1617 ** is common across all DEPCA products. Note that the original DEPCA needs
1618 ** its ROM address counter to be initialized and enabled. Only enable
1619 ** if the first address octet is a 0x08 - this minimises the chances of
1620 ** messing around with some other hardware, but it assumes that this DEPCA
1621 ** card initialized itself correctly.
1623 ** Search the Ethernet address ROM for the signature. Since the ROM address
1624 ** counter can start at an arbitrary point, the search must include the entire
1625 ** probe sequence length plus the (length_of_the_signature - 1).
1626 ** Stop the search IMMEDIATELY after the signature is found so that the
1627 ** PROM address counter is correctly positioned at the start of the
1628 ** ethernet address for later read out.
1630 static int __init
1631 DevicePresent(u_long ioaddr)
1633 union {
1634 struct {
1635 u32 a;
1636 u32 b;
1637 } llsig;
1638 char Sig[sizeof(u32) << 1];
1639 } dev;
1640 short sigLength=0;
1641 s8 data;
1642 s16 nicsr;
1643 int i, j, status = 0;
1645 data = inb(DEPCA_PROM); /* clear counter on DEPCA */
1646 data = inb(DEPCA_PROM); /* read data */
1648 if (data == 0x08) { /* Enable counter on DEPCA */
1649 nicsr = inb(DEPCA_NICSR);
1650 nicsr |= AAC;
1651 outb(nicsr, DEPCA_NICSR);
1654 dev.llsig.a = ETH_PROM_SIG;
1655 dev.llsig.b = ETH_PROM_SIG;
1656 sigLength = sizeof(u32) << 1;
1658 for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1659 data = inb(DEPCA_PROM);
1660 if (dev.Sig[j] == data) { /* track signature */
1661 j++;
1662 } else { /* lost signature; begin search again */
1663 if (data == dev.Sig[0]) { /* rare case.... */
1664 j=1;
1665 } else {
1666 j=0;
1671 if (j!=sigLength) {
1672 status = -ENODEV; /* search failed */
1675 return status;
1679 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1680 ** reason: access the upper half of the PROM with x=0; access the lower half
1681 ** with x=1.
1683 static int __init
1684 get_hw_addr(struct device *dev)
1686 u_long ioaddr = dev->base_addr;
1687 int i, k, tmp, status = 0;
1688 u_short j, x, chksum;
1690 x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1692 for (i=0,k=0,j=0;j<3;j++) {
1693 k <<= 1 ;
1694 if (k > 0xffff) k-=0xffff;
1696 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1697 dev->dev_addr[i++] = (u_char) tmp;
1698 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1699 dev->dev_addr[i++] = (u_char) tmp;
1701 if (k > 0xffff) k-=0xffff;
1703 if (k == 0xffff) k=0;
1705 chksum = (u_char) inb(DEPCA_PROM + x);
1706 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1707 if (k != chksum) status = -1;
1709 return status;
1713 ** Load a packet into the shared memory
1715 static int load_packet(struct device *dev, struct sk_buff *skb)
1717 struct depca_private *lp = (struct depca_private *)dev->priv;
1718 int i, entry, end, len, status = 0;
1720 entry = lp->tx_new; /* Ring around buffer number. */
1721 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1722 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {/* Enough room? */
1724 ** Caution: the write order is important here... don't set up the
1725 ** ownership rights until all the other information is in place.
1727 if (end < entry) { /* wrapped buffer */
1728 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1729 memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
1730 memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
1731 } else { /* linear buffer */
1732 memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
1735 /* set up the buffer descriptors */
1736 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1737 for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1738 /* clean out flags */
1739 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1740 writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */
1741 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);/* packet length in buffer */
1742 len -= TX_BUFF_SZ;
1744 /* clean out flags */
1745 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1746 writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */
1747 writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */
1749 /* start of packet */
1750 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1751 /* end of packet */
1752 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1754 for (i=end; i!=entry; --i) {
1755 /* ownership of packet */
1756 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1757 if (i == 0) i=lp->txRingMask+1;
1759 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1761 lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */
1762 } else {
1763 status = -1;
1766 return status;
1770 ** Look for a particular board name in the EISA configuration space
1772 static int __init
1773 EISA_signature(char *name, s32 eisa_id)
1775 u_int i;
1776 const char *signatures[] = DEPCA_SIGNATURE;
1777 char ManCode[DEPCA_STRLEN];
1778 union {
1779 s32 ID;
1780 char Id[4];
1781 } Eisa;
1782 int status = 0;
1784 *name = '\0';
1785 Eisa.ID = inl(eisa_id);
1787 ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1788 ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1789 ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1790 ManCode[3]=(( Eisa.Id[2]&0x0f)+0x30);
1791 ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1792 ManCode[5]='\0';
1794 for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1795 if (strstr(ManCode, signatures[i]) != NULL) {
1796 strcpy(name,ManCode);
1797 status = 1;
1801 return status;
1804 static void depca_dbg_open(struct device *dev)
1806 struct depca_private *lp = (struct depca_private *)dev->priv;
1807 u_long ioaddr = dev->base_addr;
1808 struct depca_init *p = (struct depca_init *)lp->sh_mem;
1809 int i;
1811 if (depca_debug > 1){
1812 /* Copy the shadow init_block to shared memory */
1813 memcpy_toio((char *)lp->sh_mem,&lp->init_block,sizeof(struct depca_init));
1815 printk("%s: depca open with irq %d\n",dev->name,dev->irq);
1816 printk("Descriptor head addresses:\n");
1817 printk("\t0x%lx 0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring);
1818 printk("Descriptor addresses:\nRX: ");
1819 for (i=0;i<lp->rxRingMask;i++){
1820 if (i < 3) {
1821 printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
1824 printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
1825 printk("TX: ");
1826 for (i=0;i<lp->txRingMask;i++){
1827 if (i < 3) {
1828 printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
1831 printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
1832 printk("\nDescriptor buffers:\nRX: ");
1833 for (i=0;i<lp->rxRingMask;i++){
1834 if (i < 3) {
1835 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1838 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1839 printk("TX: ");
1840 for (i=0;i<lp->txRingMask;i++){
1841 if (i < 3) {
1842 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1845 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1846 printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem);
1847 printk("\tmode: 0x%4.4x\n",readw(&p->mode));
1848 printk("\tphysical address: ");
1849 for (i=0;i<ETH_ALEN-1;i++){
1850 printk("%2.2x:",(u_char)readb(&p->phys_addr[i]));
1852 printk("%2.2x\n",(u_char)readb(&p->phys_addr[i]));
1853 printk("\tmulticast hash table: ");
1854 for (i=0;i<(HASH_TABLE_LEN >> 3)-1;i++){
1855 printk("%2.2x:",(u_char)readb(&p->mcast_table[i]));
1857 printk("%2.2x\n",(u_char)readb(&p->mcast_table[i]));
1858 printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring));
1859 printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring));
1860 printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs);
1861 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n",
1862 (int)lp->rxRingMask + 1,
1863 lp->rx_rlen);
1864 printk("TX: %d Log2(txRingMask): 0x%8.8x\n",
1865 (int)lp->txRingMask + 1,
1866 lp->tx_rlen);
1867 outw(CSR2,DEPCA_ADDR);
1868 printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
1869 outw(CSR1,DEPCA_ADDR);
1870 printk("%4.4x\n",inw(DEPCA_DATA));
1871 outw(CSR3,DEPCA_ADDR);
1872 printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
1875 return;
1879 ** Perform IOCTL call functions here. Some are privileged operations and the
1880 ** effective uid is checked in those cases.
1881 ** All multicast IOCTLs will not work here and are for testing purposes only.
1883 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
1885 struct depca_private *lp = (struct depca_private *)dev->priv;
1886 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1887 int i, status = 0;
1888 u_long ioaddr = dev->base_addr;
1889 union {
1890 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1891 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1892 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1893 } tmp;
1895 switch(ioc->cmd) {
1896 case DEPCA_GET_HWADDR: /* Get the hardware address */
1897 for (i=0; i<ETH_ALEN; i++) {
1898 tmp.addr[i] = dev->dev_addr[i];
1900 ioc->len = ETH_ALEN;
1901 if (verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len)) return -EFAULT;
1902 copy_to_user(ioc->data, tmp.addr, ioc->len);
1903 break;
1905 case DEPCA_SET_HWADDR: /* Set the hardware address */
1906 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1907 if (verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN)) return -EFAULT;
1908 copy_from_user(tmp.addr,ioc->data,ETH_ALEN);
1909 for (i=0; i<ETH_ALEN; i++) {
1910 dev->dev_addr[i] = tmp.addr[i];
1912 while(dev->tbusy) barrier(); /* Stop ring access */
1913 test_and_set_bit(0, (void*)&dev->tbusy);
1914 while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1916 STOP_DEPCA; /* Temporarily stop the depca. */
1917 depca_init_ring(dev); /* Initialize the descriptor rings */
1918 LoadCSRs(dev); /* Reload CSR3 */
1919 InitRestartDepca(dev); /* Resume normal operation. */
1920 dev->tbusy = 0; /* Unlock the TX ring */
1921 break;
1923 case DEPCA_SET_PROM: /* Set Promiscuous Mode */
1924 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1925 while(dev->tbusy) barrier(); /* Stop ring access */
1926 test_and_set_bit(0, (void*)&dev->tbusy);
1927 while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1929 STOP_DEPCA; /* Temporarily stop the depca. */
1930 depca_init_ring(dev); /* Initialize the descriptor rings */
1931 lp->init_block.mode |= PROM; /* Set promiscuous mode */
1933 LoadCSRs(dev); /* Reload CSR3 */
1934 InitRestartDepca(dev); /* Resume normal operation. */
1935 dev->tbusy = 0; /* Unlock the TX ring */
1936 break;
1938 case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */
1939 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1940 while(dev->tbusy) barrier(); /* Stop ring access */
1941 test_and_set_bit(0, (void*)&dev->tbusy);
1942 while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1944 STOP_DEPCA; /* Temporarily stop the depca. */
1945 depca_init_ring(dev); /* Initialize the descriptor rings */
1946 lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */
1948 LoadCSRs(dev); /* Reload CSR3 */
1949 InitRestartDepca(dev); /* Resume normal operation. */
1950 dev->tbusy = 0; /* Unlock the TX ring */
1951 break;
1953 case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */
1954 printk("%s: Boo!\n", dev->name);
1955 break;
1957 case DEPCA_GET_MCA: /* Get the multicast address table */
1958 ioc->len = (HASH_TABLE_LEN >> 3);
1959 if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) return -EFAULT;
1960 copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len);
1961 break;
1963 case DEPCA_SET_MCA: /* Set a multicast address */
1964 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1965 if (verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len)) return -EFAULT;
1966 copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1967 set_multicast_list(dev);
1968 break;
1970 case DEPCA_CLR_MCA: /* Clear all multicast addresses */
1971 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1972 set_multicast_list(dev);
1973 break;
1975 case DEPCA_MCA_EN: /* Enable pass all multicast addressing */
1976 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1977 set_multicast_list(dev);
1978 break;
1980 case DEPCA_GET_STATS: /* Get the driver statistics */
1981 cli();
1982 ioc->len = sizeof(lp->pktStats);
1983 if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) {
1984 status = -EFAULT;
1985 } else {
1986 copy_to_user(ioc->data, &lp->pktStats, ioc->len);
1988 sti();
1989 break;
1991 case DEPCA_CLR_STATS: /* Zero out the driver statistics */
1992 if (!capable(CAP_NET_ADMIN)) return -EPERM;
1993 cli();
1994 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1995 sti();
1996 break;
1998 case DEPCA_GET_REG: /* Get the DEPCA Registers */
1999 i=0;
2000 tmp.sval[i++] = inw(DEPCA_NICSR);
2001 outw(CSR0, DEPCA_ADDR); /* status register */
2002 tmp.sval[i++] = inw(DEPCA_DATA);
2003 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
2004 ioc->len = i+sizeof(struct depca_init);
2005 if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) return -EFAULT;
2006 copy_to_user(ioc->data, tmp.addr, ioc->len);
2007 break;
2009 default:
2010 return -EOPNOTSUPP;
2013 return status;
2016 #ifdef MODULE
2017 static char devicename[9] = {0,};
2018 static struct device thisDepca = {
2019 devicename, /* device name is inserted by /linux/drivers/net/net_init.c */
2020 0, 0, 0, 0,
2021 0x200, 7, /* I/O address, IRQ */
2022 0, 0, 0, NULL, depca_probe
2025 static int irq=7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */
2026 static int io=0x200; /* Or use the irq= io= options to insmod */
2027 MODULE_PARM(irq, "i");
2028 MODULE_PARM(io, "i");
2030 /* See depca_probe() for autoprobe messages when a module */
2032 init_module(void)
2034 thisDepca.irq=irq;
2035 thisDepca.base_addr=io;
2037 if (register_netdev(&thisDepca) != 0)
2038 return -EIO;
2040 return 0;
2043 void
2044 cleanup_module(void)
2046 struct depca_private *lp = thisDepca.priv;
2047 if (lp) {
2048 #ifdef CONFIG_MCA
2049 if(lp->mca_slot != -1)
2050 mca_mark_as_unused(lp->mca_slot);
2051 #endif
2052 kfree(lp);
2053 thisDepca.priv = NULL;
2055 thisDepca.irq=0;
2057 unregister_netdev(&thisDepca);
2058 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
2060 #endif /* MODULE */
2064 * Local variables:
2065 * 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"
2067 * 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"
2068 * End: