More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / depca.c
blob623b9b54d79673c321f68ff17574a4e32a524d1f
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 General 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>
226 0.52 16-Oct-00 Fixes for 2.3 io memory accesses
227 Fix show-stopper (ints left masked) in depca_interrupt
228 by <peterd@pnd-pc.demon.co.uk>
229 0.53 12-Jan-01 Release resources on failure, bss tidbits
230 by acme@conectiva.com.br
231 0.54 08-Nov-01 use library crc32 functions
232 by Matt_Domsch@dell.com
233 0.55 01-Mar-03 Use EISA/sysfs framework <maz@wild-wind.fr.eu.org>
235 =========================================================================
238 #include <linux/config.h>
239 #include <linux/module.h>
240 #include <linux/kernel.h>
241 #include <linux/string.h>
242 #include <linux/errno.h>
243 #include <linux/ioport.h>
244 #include <linux/slab.h>
245 #include <linux/interrupt.h>
246 #include <linux/delay.h>
247 #include <linux/init.h>
248 #include <linux/crc32.h>
249 #include <linux/netdevice.h>
250 #include <linux/etherdevice.h>
251 #include <linux/skbuff.h>
252 #include <linux/time.h>
253 #include <linux/types.h>
254 #include <linux/unistd.h>
255 #include <linux/ctype.h>
256 #include <linux/mca-legacy.h>
258 #include <asm/uaccess.h>
259 #include <asm/bitops.h>
260 #include <asm/io.h>
261 #include <asm/dma.h>
263 #ifdef CONFIG_MCA
264 #include <linux/mca.h>
265 #endif
267 #ifdef CONFIG_EISA
268 #include <linux/device.h>
269 #include <linux/eisa.h>
270 #endif
272 #include "depca.h"
274 static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
276 #ifdef DEPCA_DEBUG
277 static int depca_debug = DEPCA_DEBUG;
278 #else
279 static int depca_debug = 1;
280 #endif
282 #define DEPCA_NDA 0xffe0 /* No Device Address */
284 #define TX_TIMEOUT (1*HZ)
287 ** Ethernet PROM defines
289 #define PROBE_LENGTH 32
290 #define ETH_PROM_SIG 0xAA5500FFUL
293 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
294 ** here is <= to the amount of shared memory set up by the board switches.
295 ** The number of descriptors MUST BE A POWER OF 2.
297 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
299 #define NUM_RX_DESC 8 /* Number of RX descriptors */
300 #define NUM_TX_DESC 8 /* Number of TX descriptors */
301 #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
302 #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
305 ** EISA bus defines
307 #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
308 #define MAX_EISA_SLOTS 16
309 #define EISA_SLOT_INC 0x1000
312 ** ISA Bus defines
314 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
315 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
316 #define DEPCA_TOTAL_SIZE 0x10
317 static short mem_chkd;
320 ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
322 #define DE212_ID 0x6def
325 ** Name <-> Adapter mapping
327 #define DEPCA_SIGNATURE {"DEPCA",\
328 "DE100","DE101",\
329 "DE200","DE201","DE202",\
330 "DE210","DE212",\
331 "DE422",\
333 static enum {
334 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
335 } adapter;
337 #ifdef CONFIG_EISA
338 struct eisa_device_id depca_eisa_ids[] = {
339 { "DEC4220" },
340 { "" }
343 static int depca_eisa_probe (struct device *device);
344 static int depca_eisa_remove (struct device *device);
346 struct eisa_driver depca_eisa_driver = {
347 .id_table = depca_eisa_ids,
348 .driver = {
349 .name = "depca",
350 .probe = depca_eisa_probe,
351 .remove = __devexit_p (depca_eisa_remove)
354 #endif
357 ** Miscellaneous info...
359 #define DEPCA_STRLEN 16
360 #define MAX_NUM_DEPCAS 2
363 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
364 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
365 ** DESC_ALIGN. DEPCA_ALIGN aligns the start address of the private memory area
366 ** and hence the RX descriptor ring's first entry.
368 #define DEPCA_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
369 #define DEPCA_ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
370 #define DEPCA_ALIGN DEPCA_ALIGN8 /* Keep the LANCE happy... */
373 ** The DEPCA Rx and Tx ring descriptors.
375 struct depca_rx_desc {
376 volatile s32 base;
377 s16 buf_length; /* This length is negative 2's complement! */
378 s16 msg_length; /* This length is "normal". */
381 struct depca_tx_desc {
382 volatile s32 base;
383 s16 length; /* This length is negative 2's complement! */
384 s16 misc; /* Errors and TDR info */
387 #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
388 to LANCE memory address space */
391 ** The Lance initialization block, described in databook, in common memory.
393 struct depca_init {
394 u16 mode; /* Mode register */
395 u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
396 u8 mcast_table[8]; /* Multicast Hash Table. */
397 u32 rx_ring; /* Rx ring base pointer & ring length */
398 u32 tx_ring; /* Tx ring base pointer & ring length */
401 #define DEPCA_PKT_STAT_SZ 16
402 #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
403 increase DEPCA_PKT_STAT_SZ */
404 struct depca_private {
405 char devname[DEPCA_STRLEN]; /* Device Product String */
406 char adapter_name[DEPCA_STRLEN]; /* /proc/ioports string */
407 char adapter; /* Adapter type */
408 char mca_slot; /* MCA slot, if MCA else -1 */
409 struct depca_init init_block; /* Shadow Initialization block */
410 /* CPU address space fields */
411 struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
412 struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
413 void *rx_buff[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
414 void *tx_buff[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
415 void *sh_mem; /* CPU mapped virt address of device RAM */
416 u_long mem_start; /* Bus address of device RAM (before remap) */
417 u_long mem_len; /* device memory size */
418 /* Device address space fields */
419 u_long device_ram_start; /* Start of RAM in device addr space */
420 /* Offsets used in both address spaces */
421 u_long rx_ring_offset; /* Offset from start of RAM to rx_ring */
422 u_long tx_ring_offset; /* Offset from start of RAM to tx_ring */
423 u_long buffs_offset; /* LANCE Rx and Tx buffers start address. */
424 /* Kernel-only (not device) fields */
425 int rx_new, tx_new; /* The next free ring entry */
426 int rx_old, tx_old; /* The ring entries to be free()ed. */
427 struct net_device_stats stats;
428 spinlock_t lock;
429 struct { /* Private stats counters */
430 u32 bins[DEPCA_PKT_STAT_SZ];
431 u32 unicast;
432 u32 multicast;
433 u32 broadcast;
434 u32 excessive_collisions;
435 u32 tx_underruns;
436 u32 excessive_underruns;
437 } pktStats;
438 int txRingMask; /* TX ring mask */
439 int rxRingMask; /* RX ring mask */
440 s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
441 s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
445 ** The transmit ring full condition is described by the tx_old and tx_new
446 ** pointers by:
447 ** tx_old = tx_new Empty ring
448 ** tx_old = tx_new+1 Full ring
449 ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
451 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
452 lp->tx_old+lp->txRingMask-lp->tx_new:\
453 lp->tx_old -lp->tx_new-1)
456 ** Public Functions
458 static int depca_open(struct net_device *dev);
459 static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev);
460 static irqreturn_t depca_interrupt(int irq, void *dev_id, struct pt_regs *regs);
461 static int depca_close(struct net_device *dev);
462 static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
463 static void depca_tx_timeout(struct net_device *dev);
464 static struct net_device_stats *depca_get_stats(struct net_device *dev);
465 static void set_multicast_list(struct net_device *dev);
468 ** Private functions
470 static int depca_hw_init(struct net_device *dev, u_long ioaddr, int mca_slot);
471 static void depca_init_ring(struct net_device *dev);
472 static int depca_rx(struct net_device *dev);
473 static int depca_tx(struct net_device *dev);
475 static void LoadCSRs(struct net_device *dev);
476 static int InitRestartDepca(struct net_device *dev);
477 static void DepcaSignature(char *name, u_long paddr);
478 static int DevicePresent(u_long ioaddr);
479 static int get_hw_addr(struct net_device *dev);
480 static void SetMulticastFilter(struct net_device *dev);
481 static void isa_probe(struct net_device *dev, u_long iobase);
482 #ifdef CONFIG_MCA
483 static void mca_probe(struct net_device *dev, u_long iobase);
484 #endif
485 static struct net_device *alloc_device(struct net_device *dev, u_long iobase);
486 static int depca_dev_index(char *s);
487 static struct net_device *insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *));
488 static int load_packet(struct net_device *dev, struct sk_buff *skb);
489 static void depca_dbg_open(struct net_device *dev);
491 #ifdef MODULE
492 static int autoprobed = 1, loading_module = 1;
493 # else
494 static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 };
495 static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 };
496 static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 };
497 static u_char *depca_irq;
498 static int autoprobed, loading_module;
499 #endif /* MODULE */
501 static char name[DEPCA_STRLEN];
502 static int num_depcas, num_eth;
503 static int mem; /* For loadable module assignment
504 use insmod mem=0x????? .... */
505 static char *adapter_name; /* = '\0'; If no PROM when loadable module
506 use insmod adapter_name=DE??? ...
507 bss initializes this to zero
510 ** Miscellaneous defines...
512 #define STOP_DEPCA \
513 outw(CSR0, DEPCA_ADDR);\
514 outw(STOP, DEPCA_DATA)
516 int __init depca_probe(struct net_device *dev)
518 int tmp = num_depcas, status = -ENODEV;
519 u_long iobase = dev->base_addr;
521 SET_MODULE_OWNER(dev);
523 if ((iobase == 0) && loading_module) {
524 printk("Autoprobing is not supported when loading a module based driver.\n");
525 status = -EIO;
526 } else {
527 #ifdef CONFIG_MCA
528 mca_probe(dev, iobase);
529 #endif
530 isa_probe(dev, iobase);
531 #ifdef CONFIG_EISA
532 eisa_driver_register (&depca_eisa_driver);
533 #endif
535 if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
536 printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name, iobase);
540 ** Walk the device list to check that at least one device
541 ** initialised OK
543 for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
545 if (dev->priv)
546 status = 0;
547 if (iobase == 0)
548 autoprobed = 1;
551 return status;
554 static int __init depca_hw_init(struct net_device *dev, u_long ioaddr, int mca_slot)
556 struct depca_private *lp;
557 int i, j, offset, netRAM, mem_len, status = 0;
558 s16 nicsr;
559 u_long mem_start = 0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
560 int is_eisa = ((ioaddr & 0x0fff) == DEPCA_EISA_IO_PORTS);
562 STOP_DEPCA;
564 nicsr = inb(DEPCA_NICSR);
565 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
566 outb(nicsr, DEPCA_NICSR);
568 if (inw(DEPCA_DATA) != STOP) {
569 return -ENXIO;
572 do {
573 strcpy(name, (adapter_name ? adapter_name : ""));
574 mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]);
575 DepcaSignature(name, mem_start);
576 } while (!mem && mem_base[mem_chkd] && (adapter == unknown));
578 if ((adapter == unknown) || !mem_start) { /* DEPCA device not found */
579 return -ENXIO;
582 dev->base_addr = ioaddr;
584 if (mca_slot != -1) {
585 printk("%s: %s at 0x%04lx (MCA slot %d)", dev->name, name, ioaddr, mca_slot);
586 } else if (is_eisa) { /* EISA slot address */
587 printk("%s: %s at 0x%04lx (EISA slot %d)", dev->name, name, ioaddr, (int) ((ioaddr >> 12) & 0x0f));
588 } else { /* ISA port address */
589 printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
592 printk(", h/w address ");
593 status = get_hw_addr(dev);
594 if (status != 0) {
595 printk(" which has an Ethernet PROM CRC error.\n");
596 return -ENXIO;
598 for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet address */
599 printk("%2.2x:", dev->dev_addr[i]);
601 printk("%2.2x", dev->dev_addr[i]);
603 /* Set up the maximum amount of network RAM(kB) */
604 netRAM = ((adapter != DEPCA) ? 64 : 48);
605 if ((nicsr & _128KB) && (adapter == de422))
606 netRAM = 128;
607 offset = 0x0000;
609 /* Shared Memory Base Address */
610 if (nicsr & BUF) {
611 offset = 0x8000; /* 32kbyte RAM offset */
612 nicsr &= ~BS; /* DEPCA RAM in top 32k */
613 netRAM -= 32;
615 mem_start += offset; /* (E)ISA start address */
616 if ((mem_len = (NUM_RX_DESC * (sizeof(struct depca_rx_desc) + RX_BUFF_SZ) + NUM_TX_DESC * (sizeof(struct depca_tx_desc) + TX_BUFF_SZ) + sizeof(struct depca_init)))
617 > (netRAM << 10)) {
618 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
619 return -ENXIO;
622 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
624 /* Enable the shadow RAM. */
625 if (adapter != DEPCA) {
626 nicsr |= SHE;
627 outb(nicsr, DEPCA_NICSR);
630 /* Define the device private memory */
631 if (!is_eisa) {
632 dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
633 if (dev->priv == NULL)
634 return -ENOMEM;
636 lp = (struct depca_private *) dev->priv;
637 memset((char *) dev->priv, 0, sizeof(struct depca_private));
638 lp->adapter = adapter;
639 lp->mca_slot = mca_slot;
640 lp->lock = SPIN_LOCK_UNLOCKED;
641 sprintf(lp->adapter_name, "%s (%s)", name, dev->name);
642 status = -EBUSY;
644 /* Initialisation Block */
645 if (!request_mem_region (mem_start, mem_len, lp->adapter_name)) {
646 printk(KERN_ERR "depca: cannot request ISA memory, aborting\n");
647 goto out_priv;
650 status = -EIO;
651 lp->sh_mem = ioremap(mem_start, mem_len);
652 if (lp->sh_mem == NULL) {
653 printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n");
654 release_mem_region (mem_start, mem_len);
655 goto out_priv;
658 lp->mem_start = mem_start;
659 lp->mem_len = mem_len;
660 lp->device_ram_start = mem_start & LA_MASK;
662 offset = 0;
663 offset += sizeof(struct depca_init);
665 /* Tx & Rx descriptors (aligned to a quadword boundary) */
666 offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
667 lp->rx_ring = (struct depca_rx_desc *) (lp->sh_mem + offset);
668 lp->rx_ring_offset = offset;
670 offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
671 lp->tx_ring = (struct depca_tx_desc *) (lp->sh_mem + offset);
672 lp->tx_ring_offset = offset;
674 offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
676 lp->buffs_offset = offset;
678 /* Finish initialising the ring information. */
679 lp->rxRingMask = NUM_RX_DESC - 1;
680 lp->txRingMask = NUM_TX_DESC - 1;
682 /* Calculate Tx/Rx RLEN size for the descriptors. */
683 for (i = 0, j = lp->rxRingMask; j > 0; i++) {
684 j >>= 1;
686 lp->rx_rlen = (s32) (i << 29);
687 for (i = 0, j = lp->txRingMask; j > 0; i++) {
688 j >>= 1;
690 lp->tx_rlen = (s32) (i << 29);
692 /* Load the initialisation block */
693 depca_init_ring(dev);
695 /* Initialise the control and status registers */
696 LoadCSRs(dev);
698 /* Enable DEPCA board interrupts for autoprobing */
699 nicsr = ((nicsr & ~IM) | IEN);
700 outb(nicsr, DEPCA_NICSR);
702 /* To auto-IRQ we enable the initialization-done and DMA err,
703 interrupts. For now we will always get a DMA error. */
704 if (dev->irq < 2) {
705 #ifndef MODULE
706 unsigned char irqnum;
707 unsigned long irq_mask, delay;
709 irq_mask = probe_irq_on();
711 /* Assign the correct irq list */
712 switch (lp->adapter) {
713 case DEPCA:
714 case de100:
715 case de101:
716 depca_irq = de1xx_irq;
717 break;
718 case de200:
719 case de201:
720 case de202:
721 case de210:
722 case de212:
723 depca_irq = de2xx_irq;
724 break;
725 case de422:
726 depca_irq = de422_irq;
727 break;
730 /* Trigger an initialization just for the interrupt. */
731 outw(INEA | INIT, DEPCA_DATA);
733 delay = jiffies + HZ/50;
734 while (time_before(jiffies, delay))
735 yield();
736 irqnum = probe_irq_off(irq_mask);
738 status = -ENXIO;
739 if (!irqnum) {
740 printk(" and failed to detect IRQ line.\n");
741 goto out_priv;
742 } else {
743 for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
744 if (irqnum == depca_irq[i]) {
745 dev->irq = irqnum;
746 printk(" and uses IRQ%d.\n", dev->irq);
749 status = -ENXIO;
750 if (!dev->irq) {
751 printk(" but incorrect IRQ line detected.\n");
752 goto out_priv;
755 #endif /* MODULE */
756 } else {
757 printk(" and assigned IRQ%d.\n", dev->irq);
760 if (depca_debug > 1) {
761 printk(version);
764 /* The DEPCA-specific entries in the device structure. */
765 dev->open = &depca_open;
766 dev->hard_start_xmit = &depca_start_xmit;
767 dev->stop = &depca_close;
768 dev->get_stats = &depca_get_stats;
769 dev->set_multicast_list = &set_multicast_list;
770 dev->do_ioctl = &depca_ioctl;
771 dev->tx_timeout = depca_tx_timeout;
772 dev->watchdog_timeo = TX_TIMEOUT;
774 dev->mem_start = 0;
776 /* Fill in the generic field of the device structure. */
777 if (!is_eisa)
778 ether_setup(dev);
779 return 0;
780 out_priv:
781 if (!is_eisa) {
782 kfree(dev->priv);
783 dev->priv = NULL;
784 } else {
785 unregister_netdev (dev);
787 return status;
791 static int depca_open(struct net_device *dev)
793 struct depca_private *lp = (struct depca_private *) dev->priv;
794 u_long ioaddr = dev->base_addr;
795 s16 nicsr;
796 int status = 0;
798 STOP_DEPCA;
799 nicsr = inb(DEPCA_NICSR);
801 /* Make sure the shadow RAM is enabled */
802 if (lp->adapter != DEPCA) {
803 nicsr |= SHE;
804 outb(nicsr, DEPCA_NICSR);
807 /* Re-initialize the DEPCA... */
808 depca_init_ring(dev);
809 LoadCSRs(dev);
811 depca_dbg_open(dev);
813 if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) {
814 printk("depca_open(): Requested IRQ%d is busy\n", dev->irq);
815 status = -EAGAIN;
816 } else {
818 /* Enable DEPCA board interrupts and turn off LED */
819 nicsr = ((nicsr & ~IM & ~LED) | IEN);
820 outb(nicsr, DEPCA_NICSR);
821 outw(CSR0, DEPCA_ADDR);
823 netif_start_queue(dev);
825 status = InitRestartDepca(dev);
827 if (depca_debug > 1) {
828 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA));
829 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR));
832 return status;
835 /* Initialize the lance Rx and Tx descriptor rings. */
836 static void depca_init_ring(struct net_device *dev)
838 struct depca_private *lp = (struct depca_private *) dev->priv;
839 u_int i;
840 u_long offset;
842 /* Lock out other processes whilst setting up the hardware */
843 netif_stop_queue(dev);
845 lp->rx_new = lp->tx_new = 0;
846 lp->rx_old = lp->tx_old = 0;
848 /* Initialize the base address and length of each buffer in the ring */
849 for (i = 0; i <= lp->rxRingMask; i++) {
850 offset = lp->buffs_offset + i * RX_BUFF_SZ;
851 writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base);
852 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
853 lp->rx_buff[i] = lp->sh_mem + offset;
856 for (i = 0; i <= lp->txRingMask; i++) {
857 offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ;
858 writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base);
859 lp->tx_buff[i] = lp->sh_mem + offset;
862 /* Set up the initialization block */
863 lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen;
864 lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen;
866 SetMulticastFilter(dev);
868 for (i = 0; i < ETH_ALEN; i++) {
869 lp->init_block.phys_addr[i] = dev->dev_addr[i];
872 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
876 static void depca_tx_timeout(struct net_device *dev)
878 u_long ioaddr = dev->base_addr;
880 printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA));
882 STOP_DEPCA;
883 depca_init_ring(dev);
884 LoadCSRs(dev);
885 dev->trans_start = jiffies;
886 netif_wake_queue(dev);
887 InitRestartDepca(dev);
892 ** Writes a socket buffer to TX descriptor ring and starts transmission
894 static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev)
896 struct depca_private *lp = (struct depca_private *) dev->priv;
897 u_long ioaddr = dev->base_addr;
898 int status = 0;
900 /* Transmitter timeout, serious problems. */
901 if (skb->len < 1)
902 goto out;
904 if (skb->len < ETH_ZLEN) {
905 skb = skb_padto(skb, ETH_ZLEN);
906 if (skb == NULL)
907 goto out;
910 netif_stop_queue(dev);
912 if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
913 status = load_packet(dev, skb);
915 if (!status) {
916 /* Trigger an immediate send demand. */
917 outw(CSR0, DEPCA_ADDR);
918 outw(INEA | TDMD, DEPCA_DATA);
920 dev->trans_start = jiffies;
921 dev_kfree_skb(skb);
923 if (TX_BUFFS_AVAIL)
924 netif_start_queue(dev);
925 } else
926 status = -1;
928 out:
929 return status;
933 ** The DEPCA interrupt handler.
935 static irqreturn_t depca_interrupt(int irq, void *dev_id, struct pt_regs *regs)
937 struct net_device *dev = dev_id;
938 struct depca_private *lp;
939 s16 csr0, nicsr;
940 u_long ioaddr;
942 if (dev == NULL) {
943 printk("depca_interrupt(): irq %d for unknown device.\n", irq);
944 return IRQ_NONE;
947 lp = (struct depca_private *) dev->priv;
948 ioaddr = dev->base_addr;
950 spin_lock(&lp->lock);
952 /* mask the DEPCA board interrupts and turn on the LED */
953 nicsr = inb(DEPCA_NICSR);
954 nicsr |= (IM | LED);
955 outb(nicsr, DEPCA_NICSR);
957 outw(CSR0, DEPCA_ADDR);
958 csr0 = inw(DEPCA_DATA);
960 /* Acknowledge all of the current interrupt sources ASAP. */
961 outw(csr0 & INTE, DEPCA_DATA);
963 if (csr0 & RINT) /* Rx interrupt (packet arrived) */
964 depca_rx(dev);
966 if (csr0 & TINT) /* Tx interrupt (packet sent) */
967 depca_tx(dev);
969 /* Any resources available? */
970 if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) {
971 netif_wake_queue(dev);
974 /* Unmask the DEPCA board interrupts and turn off the LED */
975 nicsr = (nicsr & ~IM & ~LED);
976 outb(nicsr, DEPCA_NICSR);
978 spin_unlock(&lp->lock);
979 return IRQ_HANDLED;
982 /* Called with lp->lock held */
983 static int depca_rx(struct net_device *dev)
985 struct depca_private *lp = (struct depca_private *) dev->priv;
986 int i, entry;
987 s32 status;
989 for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) {
990 status = readl(&lp->rx_ring[entry].base) >> 16;
991 if (status & R_STP) { /* Remember start of frame */
992 lp->rx_old = entry;
994 if (status & R_ENP) { /* Valid frame status */
995 if (status & R_ERR) { /* There was an error. */
996 lp->stats.rx_errors++; /* Update the error stats. */
997 if (status & R_FRAM)
998 lp->stats.rx_frame_errors++;
999 if (status & R_OFLO)
1000 lp->stats.rx_over_errors++;
1001 if (status & R_CRC)
1002 lp->stats.rx_crc_errors++;
1003 if (status & R_BUFF)
1004 lp->stats.rx_fifo_errors++;
1005 } else {
1006 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
1007 struct sk_buff *skb;
1009 skb = dev_alloc_skb(pkt_len + 2);
1010 if (skb != NULL) {
1011 unsigned char *buf;
1012 skb_reserve(skb, 2); /* 16 byte align the IP header */
1013 buf = skb_put(skb, pkt_len);
1014 skb->dev = dev;
1015 if (entry < lp->rx_old) { /* Wrapped buffer */
1016 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
1017 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len);
1018 memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len);
1019 } else { /* Linear buffer */
1020 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len);
1024 ** Notify the upper protocol layers that there is another
1025 ** packet to handle
1027 skb->protocol = eth_type_trans(skb, dev);
1028 netif_rx(skb);
1031 ** Update stats
1033 dev->last_rx = jiffies;
1034 lp->stats.rx_packets++;
1035 lp->stats.rx_bytes += pkt_len;
1036 for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) {
1037 if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) {
1038 lp->pktStats.bins[i]++;
1039 i = DEPCA_PKT_STAT_SZ;
1042 if (buf[0] & 0x01) { /* Multicast/Broadcast */
1043 if ((*(s16 *) & buf[0] == -1) && (*(s16 *) & buf[2] == -1) && (*(s16 *) & buf[4] == -1)) {
1044 lp->pktStats.broadcast++;
1045 } else {
1046 lp->pktStats.multicast++;
1048 } else if ((*(s16 *) & buf[0] == *(s16 *) & dev->dev_addr[0]) && (*(s16 *) & buf[2] == *(s16 *) & dev->dev_addr[2]) && (*(s16 *) & buf[4] == *(s16 *) & dev->dev_addr[4])) {
1049 lp->pktStats.unicast++;
1052 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
1053 if (lp->pktStats.bins[0] == 0) { /* Reset counters */
1054 memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats));
1056 } else {
1057 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
1058 lp->stats.rx_dropped++; /* Really, deferred. */
1059 break;
1062 /* Change buffer ownership for this last frame, back to the adapter */
1063 for (; lp->rx_old != entry; lp->rx_old = (++lp->rx_old) & lp->rxRingMask) {
1064 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base);
1066 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1070 ** Update entry information
1072 lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
1075 return 0;
1079 ** Buffer sent - check for buffer errors.
1080 ** Called with lp->lock held
1082 static int depca_tx(struct net_device *dev)
1084 struct depca_private *lp = (struct depca_private *) dev->priv;
1085 int entry;
1086 s32 status;
1087 u_long ioaddr = dev->base_addr;
1089 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1090 status = readl(&lp->tx_ring[entry].base) >> 16;
1092 if (status < 0) { /* Packet not yet sent! */
1093 break;
1094 } else if (status & T_ERR) { /* An error occurred. */
1095 status = readl(&lp->tx_ring[entry].misc);
1096 lp->stats.tx_errors++;
1097 if (status & TMD3_RTRY)
1098 lp->stats.tx_aborted_errors++;
1099 if (status & TMD3_LCAR)
1100 lp->stats.tx_carrier_errors++;
1101 if (status & TMD3_LCOL)
1102 lp->stats.tx_window_errors++;
1103 if (status & TMD3_UFLO)
1104 lp->stats.tx_fifo_errors++;
1105 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1106 /* Trigger an immediate send demand. */
1107 outw(CSR0, DEPCA_ADDR);
1108 outw(INEA | TDMD, DEPCA_DATA);
1110 } else if (status & (T_MORE | T_ONE)) {
1111 lp->stats.collisions++;
1112 } else {
1113 lp->stats.tx_packets++;
1116 /* Update all the pointers */
1117 lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1120 return 0;
1123 static int depca_close(struct net_device *dev)
1125 struct depca_private *lp = (struct depca_private *) dev->priv;
1126 s16 nicsr;
1127 u_long ioaddr = dev->base_addr;
1129 netif_stop_queue(dev);
1131 outw(CSR0, DEPCA_ADDR);
1133 if (depca_debug > 1) {
1134 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA));
1138 ** We stop the DEPCA here -- it occasionally polls
1139 ** memory if we don't.
1141 outw(STOP, DEPCA_DATA);
1144 ** Give back the ROM in case the user wants to go to DOS
1146 if (lp->adapter != DEPCA) {
1147 nicsr = inb(DEPCA_NICSR);
1148 nicsr &= ~SHE;
1149 outb(nicsr, DEPCA_NICSR);
1153 ** Free the associated irq
1155 free_irq(dev->irq, dev);
1156 return 0;
1159 static void LoadCSRs(struct net_device *dev)
1161 struct depca_private *lp = (struct depca_private *) dev->priv;
1162 u_long ioaddr = dev->base_addr;
1164 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
1165 outw((u16) lp->device_ram_start, DEPCA_DATA);
1166 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
1167 outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA);
1168 outw(CSR3, DEPCA_ADDR); /* ALE control */
1169 outw(ACON, DEPCA_DATA);
1171 outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
1173 return;
1176 static int InitRestartDepca(struct net_device *dev)
1178 struct depca_private *lp = (struct depca_private *) dev->priv;
1179 u_long ioaddr = dev->base_addr;
1180 int i, status = 0;
1182 /* Copy the shadow init_block to shared memory */
1183 memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1185 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
1186 outw(INIT, DEPCA_DATA); /* initialize DEPCA */
1188 /* wait for lance to complete initialisation */
1189 for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++);
1191 if (i != 100) {
1192 /* clear IDON by writing a "1", enable interrupts and start lance */
1193 outw(IDON | INEA | STRT, DEPCA_DATA);
1194 if (depca_debug > 2) {
1195 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, virt_to_phys(lp->sh_mem), inw(DEPCA_DATA));
1197 } else {
1198 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, virt_to_phys(lp->sh_mem), inw(DEPCA_DATA));
1199 status = -1;
1202 return status;
1205 static struct net_device_stats *depca_get_stats(struct net_device *dev)
1207 struct depca_private *lp = (struct depca_private *) dev->priv;
1209 /* Null body since there is no framing error counter */
1211 return &lp->stats;
1215 ** Set or clear the multicast filter for this adaptor.
1217 static void set_multicast_list(struct net_device *dev)
1219 struct depca_private *lp = (struct depca_private *) dev->priv;
1220 u_long ioaddr = dev->base_addr;
1222 if (dev) {
1223 netif_stop_queue(dev);
1224 while (lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1226 STOP_DEPCA; /* Temporarily stop the depca. */
1227 depca_init_ring(dev); /* Initialize the descriptor rings */
1229 if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
1230 lp->init_block.mode |= PROM;
1231 } else {
1232 SetMulticastFilter(dev);
1233 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
1236 LoadCSRs(dev); /* Reload CSR3 */
1237 InitRestartDepca(dev); /* Resume normal operation. */
1238 netif_start_queue(dev); /* Unlock the TX ring */
1243 ** Calculate the hash code and update the logical address filter
1244 ** from a list of ethernet multicast addresses.
1245 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1246 ** LANCE calculates its hash codes big endian.
1248 static void SetMulticastFilter(struct net_device *dev)
1250 struct depca_private *lp = (struct depca_private *) dev->priv;
1251 struct dev_mc_list *dmi = dev->mc_list;
1252 char *addrs;
1253 int i, j, bit, byte;
1254 u16 hashcode;
1255 u32 crc;
1257 if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
1258 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1259 lp->init_block.mcast_table[i] = (char) 0xff;
1261 } else {
1262 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { /* Clear the multicast table */
1263 lp->init_block.mcast_table[i] = 0;
1265 /* Add multicast addresses */
1266 for (i = 0; i < dev->mc_count; i++) { /* for each address in the list */
1267 addrs = dmi->dmi_addr;
1268 dmi = dmi->next;
1269 if ((*addrs & 0x01) == 1) { /* multicast address? */
1270 crc = ether_crc(ETH_ALEN, addrs);
1271 hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
1272 for (j = 0; j < 5; j++) { /* ... in reverse order. */
1273 hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
1277 byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
1278 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
1279 lp->init_block.mcast_table[byte] |= bit;
1284 return;
1287 #ifdef CONFIG_MCA
1289 ** Microchannel bus I/O device probe
1291 static void __init mca_probe(struct net_device *dev, u_long ioaddr)
1293 unsigned char pos[2];
1294 unsigned char where;
1295 unsigned long iobase;
1296 int irq;
1297 int slot = 0;
1300 ** See if we've been here before.
1302 if ((!ioaddr && autoprobed) || (ioaddr && !loading_module))
1303 return;
1305 if (MCA_bus) {
1307 ** Search for the adapter. If an address has been given, search
1308 ** specifically for the card at that address. Otherwise find the
1309 ** first card in the system.
1311 while ((dev != NULL) && ((slot = mca_find_adapter(DE212_ID, slot)) != MCA_NOTFOUND)) {
1312 pos[0] = mca_read_stored_pos(slot, 2);
1313 pos[1] = mca_read_stored_pos(slot, 3);
1316 ** IO of card is handled by bits 1 and 2 of pos0.
1318 ** bit2 bit1 IO
1319 ** 0 0 0x2c00
1320 ** 0 1 0x2c10
1321 ** 1 0 0x2c20
1322 ** 1 1 0x2c30
1324 where = (pos[0] & 6) >> 1;
1325 iobase = 0x2c00 + (0x10 * where);
1327 if ((ioaddr) && (ioaddr != iobase)) {
1329 ** Card was found, but not at the right IO location. Continue
1330 ** scanning from the next MCA slot up for another card.
1332 slot++;
1333 continue;
1337 ** Found the adapter we were looking for. Now start setting it up.
1339 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1340 ** of pos1. Bits are as follows (from the ADF file):
1342 ** Bits
1343 ** 3 2 1 0 IRQ
1344 ** --------------------
1345 ** 0 0 1 0 5
1346 ** 0 0 0 1 9
1347 ** 0 1 0 0 10
1348 ** 1 0 0 0 11
1349 * */
1350 where = pos[1] & 0x0f;
1351 switch (where) {
1352 case 1:
1353 irq = 9;
1354 break;
1355 case 2:
1356 irq = 5;
1357 break;
1358 case 4:
1359 irq = 10;
1360 break;
1361 case 8:
1362 irq = 11;
1363 break;
1364 default:
1365 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev->name, where);
1366 return;
1370 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1371 ** They are mapped as follows:
1373 ** Bit
1374 ** 5 4 3 Memory Addresses
1375 ** 0 0 0 C0000-CFFFF (64K)
1376 ** 1 0 0 C8000-CFFFF (32K)
1377 ** 0 0 1 D0000-DFFFF (64K)
1378 ** 1 0 1 D8000-DFFFF (32K)
1379 ** 0 1 0 E0000-EFFFF (64K)
1380 ** 1 1 0 E8000-EFFFF (32K)
1382 where = (pos[0] & 0x18) >> 3;
1383 mem = 0xc0000 + (where * 0x10000);
1384 if (pos[0] & 0x20) {
1385 mem += 0x8000;
1389 ** Get everything allocated and initialized... (almost just
1390 ** like the ISA and EISA probes)
1392 if (!request_region (iobase, DEPCA_TOTAL_SIZE, "depca")) {
1393 if (autoprobed)
1394 printk(KERN_WARNING "%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1395 goto next;
1397 if (DevicePresent(iobase) != 0) {
1399 ** If the MCA configuration says the card should be here,
1400 ** it really should be here.
1402 printk(KERN_ERR "%s: MCA reports card at 0x%lx but it is not responding.\n", dev->name, iobase);
1403 goto release_next;
1406 if (!(dev = alloc_device(dev, iobase)))
1407 goto release_next;
1409 num_eth++;
1410 dev->irq = irq;
1411 if (depca_hw_init(dev, iobase, slot))
1412 goto release_next;
1415 ** Adapter initialized correctly: Name it in
1416 ** /proc/mca.
1418 mca_set_adapter_name(slot, "DE210/212 Ethernet Adapter");
1419 mca_mark_as_used(slot);
1420 num_depcas++;
1423 ** If this is a probe by a module, return after setting up the
1424 ** given card.
1426 if (ioaddr)
1427 return;
1430 ** Set up to check the next slot and loop.
1432 slot++;
1433 continue;
1435 release_next:
1436 release_region (iobase, DEPCA_TOTAL_SIZE);
1437 next:
1438 slot++;
1442 return;
1444 #endif
1447 ** ISA bus I/O device probe
1449 static void __init isa_probe(struct net_device *dev, u_long ioaddr)
1451 int i = num_depcas, maxSlots;
1452 s32 ports[] = DEPCA_IO_PORTS;
1454 if (!ioaddr && autoprobed)
1455 return; /* Been here before ! */
1456 if (ioaddr > 0x400)
1457 return; /* EISA Address */
1458 if (i >= MAX_NUM_DEPCAS)
1459 return; /* Too many ISA adapters */
1461 if (ioaddr == 0) { /* Autoprobing */
1462 maxSlots = MAX_NUM_DEPCAS;
1463 } else { /* Probe a specific location */
1464 ports[i] = ioaddr;
1465 maxSlots = i + 1;
1468 for (; (i < maxSlots) && (dev != NULL) && ports[i]; i++) {
1469 if (!request_region (ports[i], DEPCA_TOTAL_SIZE, "depca")) {
1470 if (autoprobed)
1471 printk("%s: region already allocated at 0x%04x.\n", dev->name, ports[i]);
1472 continue;
1475 if (DevicePresent(ports[i])) {
1476 release_region (ports[i], DEPCA_TOTAL_SIZE);
1477 continue;
1480 if (!(dev = alloc_device(dev, ports[i]))) {
1481 release_region (ports[i], DEPCA_TOTAL_SIZE);
1482 continue;
1485 num_eth++;
1487 if (depca_hw_init(dev, ports[i], -1)) {
1488 release_region (ports[i], DEPCA_TOTAL_SIZE);
1489 continue;
1492 num_depcas++;
1495 return;
1499 ** EISA callbacks from sysfs.
1502 #ifdef CONFIG_EISA
1503 static int __init depca_eisa_probe (struct device *device)
1505 struct eisa_device *edev;
1506 struct net_device *dev;
1507 u_long iobase;
1508 int status = 0;
1510 edev = to_eisa_device (device);
1511 iobase = edev->base_addr + DEPCA_EISA_IO_PORTS;
1513 if (!request_region (iobase, DEPCA_TOTAL_SIZE, "depca")) {
1514 status = -EBUSY;
1515 goto out;
1518 if (DevicePresent(iobase)) {
1519 status = -ENODEV;
1520 goto out_release;
1523 if (!(dev = init_etherdev (NULL, sizeof (struct depca_private)))) {
1524 status = -ENOMEM;
1525 goto out_release;
1528 eisa_set_drvdata (edev, dev);
1530 if ((status = depca_hw_init(dev, iobase, -1)))
1531 goto out_free;
1533 num_depcas++;
1534 return 0;
1536 out_free:
1537 kfree (dev);
1538 out_release:
1539 release_region (iobase, DEPCA_TOTAL_SIZE);
1540 out:
1541 return status;
1544 static int __devexit depca_eisa_remove (struct device *device)
1546 struct net_device *dev;
1547 struct eisa_device *edev;
1548 struct depca_private *lp;
1550 edev = to_eisa_device (device);
1551 dev = eisa_get_drvdata (edev);
1552 lp = dev->priv;
1554 unregister_netdev (dev);
1555 iounmap (lp->sh_mem);
1556 release_mem_region (lp->mem_start, lp->mem_len);
1557 release_region (dev->base_addr, DEPCA_TOTAL_SIZE);
1558 kfree (dev);
1560 return 0;
1562 #endif
1565 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1566 ** found then check for an autoprobe or unused device location. If they
1567 ** are not available then insert a new device structure at the end of
1568 ** the current list.
1570 static struct net_device *__init alloc_device(struct net_device *dev, u_long iobase)
1572 struct net_device *adev = NULL;
1573 int fixed = 0, new_dev = 0;
1575 num_eth = depca_dev_index(dev->name);
1576 if (loading_module)
1577 return dev;
1579 while (1) {
1580 if (((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) && !adev) {
1581 adev = dev;
1582 } else if ((dev->priv == NULL) && (dev->base_addr == iobase)) {
1583 fixed = 1;
1584 } else {
1585 if (dev->next == NULL) {
1586 new_dev = 1;
1587 } else if (strncmp(dev->next->name, "eth", 3) != 0) {
1588 new_dev = 1;
1591 if ((dev->next == NULL) || new_dev || fixed)
1592 break;
1593 dev = dev->next;
1594 num_eth++;
1596 if (adev && !fixed) {
1597 dev = adev;
1598 num_eth = depca_dev_index(dev->name);
1599 new_dev = 0;
1602 if (((dev->next == NULL) && ((dev->base_addr != DEPCA_NDA) && (dev->base_addr != 0)) && !fixed) || new_dev) {
1603 num_eth++; /* New device */
1604 dev = insert_device(dev, iobase, depca_probe);
1607 return dev;
1611 ** If at end of eth device list and can't use current entry, malloc
1612 ** one up. If memory could not be allocated, print an error message.
1614 static struct net_device *__init insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *))
1616 struct net_device *new;
1618 new = (struct net_device *) kmalloc(sizeof(struct net_device), GFP_KERNEL);
1619 if (new == NULL) {
1620 printk("eth%d: Device not initialised, insufficient memory\n", num_eth);
1621 return NULL;
1622 } else {
1623 new->next = dev->next;
1624 dev->next = new;
1625 dev = dev->next; /* point to the new device */
1626 if (num_eth > 9999) {
1627 sprintf(dev->name, "eth????"); /* New device name */
1628 } else {
1629 sprintf(dev->name, "eth%d", num_eth); /* New device name */
1631 dev->base_addr = iobase; /* assign the io address */
1632 dev->init = init; /* initialisation routine */
1635 return dev;
1638 static int __init depca_dev_index(char *s)
1640 int i = 0, j = 0;
1642 for (; *s; s++) {
1643 if (isdigit(*s)) {
1644 j = 1;
1645 i = (i * 10) + (*s - '0');
1646 } else if (j)
1647 break;
1650 return i;
1654 ** Look for a particular board name in the on-board Remote Diagnostics
1655 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1656 ** base address.
1658 static void __init DepcaSignature(char *name, u_long paddr)
1660 u_int i, j, k;
1661 const char *signatures[] = DEPCA_SIGNATURE;
1662 void *ptr;
1663 char tmpstr[16];
1665 /* Copy the first 16 bytes of ROM */
1666 ptr = ioremap(paddr + 0xc000, 16);
1667 if (ptr == NULL) {
1668 printk(KERN_ERR "depca: I/O remap failed at %lx\n", paddr + 0xc000);
1669 adapter = unknown;
1670 return;
1672 for (i = 0; i < 16; i++) {
1673 tmpstr[i] = readb(ptr + i);
1675 iounmap(ptr);
1677 /* Check if PROM contains a valid string */
1678 for (i = 0; *signatures[i] != '\0'; i++) {
1679 for (j = 0, k = 0; j < 16 && k < strlen(signatures[i]); j++) {
1680 if (signatures[i][k] == tmpstr[j]) { /* track signature */
1681 k++;
1682 } else { /* lost signature; begin search again */
1683 k = 0;
1686 if (k == strlen(signatures[i]))
1687 break;
1690 /* Check if name string is valid, provided there's no PROM */
1691 if (*name && (i == unknown)) {
1692 for (i = 0; *signatures[i] != '\0'; i++) {
1693 if (strcmp(name, signatures[i]) == 0)
1694 break;
1698 /* Update search results */
1699 strcpy(name, signatures[i]);
1700 adapter = i;
1702 return;
1706 ** Look for a special sequence in the Ethernet station address PROM that
1707 ** is common across all DEPCA products. Note that the original DEPCA needs
1708 ** its ROM address counter to be initialized and enabled. Only enable
1709 ** if the first address octet is a 0x08 - this minimises the chances of
1710 ** messing around with some other hardware, but it assumes that this DEPCA
1711 ** card initialized itself correctly.
1713 ** Search the Ethernet address ROM for the signature. Since the ROM address
1714 ** counter can start at an arbitrary point, the search must include the entire
1715 ** probe sequence length plus the (length_of_the_signature - 1).
1716 ** Stop the search IMMEDIATELY after the signature is found so that the
1717 ** PROM address counter is correctly positioned at the start of the
1718 ** ethernet address for later read out.
1720 static int __init DevicePresent(u_long ioaddr)
1722 union {
1723 struct {
1724 u32 a;
1725 u32 b;
1726 } llsig;
1727 char Sig[sizeof(u32) << 1];
1729 dev;
1730 short sigLength = 0;
1731 s8 data;
1732 s16 nicsr;
1733 int i, j, status = 0;
1735 data = inb(DEPCA_PROM); /* clear counter on DEPCA */
1736 data = inb(DEPCA_PROM); /* read data */
1738 if (data == 0x08) { /* Enable counter on DEPCA */
1739 nicsr = inb(DEPCA_NICSR);
1740 nicsr |= AAC;
1741 outb(nicsr, DEPCA_NICSR);
1744 dev.llsig.a = ETH_PROM_SIG;
1745 dev.llsig.b = ETH_PROM_SIG;
1746 sigLength = sizeof(u32) << 1;
1748 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
1749 data = inb(DEPCA_PROM);
1750 if (dev.Sig[j] == data) { /* track signature */
1751 j++;
1752 } else { /* lost signature; begin search again */
1753 if (data == dev.Sig[0]) { /* rare case.... */
1754 j = 1;
1755 } else {
1756 j = 0;
1761 if (j != sigLength) {
1762 status = -ENODEV; /* search failed */
1765 return status;
1769 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1770 ** reason: access the upper half of the PROM with x=0; access the lower half
1771 ** with x=1.
1773 static int __init get_hw_addr(struct net_device *dev)
1775 u_long ioaddr = dev->base_addr;
1776 int i, k, tmp, status = 0;
1777 u_short j, x, chksum;
1779 x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1781 for (i = 0, k = 0, j = 0; j < 3; j++) {
1782 k <<= 1;
1783 if (k > 0xffff)
1784 k -= 0xffff;
1786 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1787 dev->dev_addr[i++] = (u_char) tmp;
1788 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1789 dev->dev_addr[i++] = (u_char) tmp;
1791 if (k > 0xffff)
1792 k -= 0xffff;
1794 if (k == 0xffff)
1795 k = 0;
1797 chksum = (u_char) inb(DEPCA_PROM + x);
1798 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1799 if (k != chksum)
1800 status = -1;
1802 return status;
1806 ** Load a packet into the shared memory
1808 static int load_packet(struct net_device *dev, struct sk_buff *skb)
1810 struct depca_private *lp = (struct depca_private *) dev->priv;
1811 int i, entry, end, len, status = 0;
1813 entry = lp->tx_new; /* Ring around buffer number. */
1814 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1815 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) { /* Enough room? */
1817 ** Caution: the write order is important here... don't set up the
1818 ** ownership rights until all the other information is in place.
1820 if (end < entry) { /* wrapped buffer */
1821 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1822 memcpy_toio(lp->tx_buff[entry], skb->data, len);
1823 memcpy_toio(lp->tx_buff[0], skb->data + len, skb->len - len);
1824 } else { /* linear buffer */
1825 memcpy_toio(lp->tx_buff[entry], skb->data, skb->len);
1828 /* set up the buffer descriptors */
1829 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1830 for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1831 /* clean out flags */
1832 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1833 writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */
1834 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length); /* packet length in buffer */
1835 len -= TX_BUFF_SZ;
1837 /* clean out flags */
1838 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1839 writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */
1840 writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */
1842 /* start of packet */
1843 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1844 /* end of packet */
1845 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1847 for (i = end; i != entry; --i) {
1848 /* ownership of packet */
1849 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1850 if (i == 0)
1851 i = lp->txRingMask + 1;
1853 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1855 lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */
1856 } else {
1857 status = -1;
1860 return status;
1863 static void depca_dbg_open(struct net_device *dev)
1865 struct depca_private *lp = (struct depca_private *) dev->priv;
1866 u_long ioaddr = dev->base_addr;
1867 struct depca_init *p = &lp->init_block;
1868 int i;
1870 if (depca_debug > 1) {
1871 /* Do not copy the shadow init block into shared memory */
1872 /* Debugging should not affect normal operation! */
1873 /* The shadow init block will get copied across during InitRestartDepca */
1874 printk("%s: depca open with irq %d\n", dev->name, dev->irq);
1875 printk("Descriptor head addresses (CPU):\n");
1876 printk(" 0x%lx 0x%lx\n", (u_long) lp->rx_ring, (u_long) lp->tx_ring);
1877 printk("Descriptor addresses (CPU):\nRX: ");
1878 for (i = 0; i < lp->rxRingMask; i++) {
1879 if (i < 3) {
1880 printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
1883 printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
1884 printk("TX: ");
1885 for (i = 0; i < lp->txRingMask; i++) {
1886 if (i < 3) {
1887 printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
1890 printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
1891 printk("\nDescriptor buffers (Device):\nRX: ");
1892 for (i = 0; i < lp->rxRingMask; i++) {
1893 if (i < 3) {
1894 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1897 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1898 printk("TX: ");
1899 for (i = 0; i < lp->txRingMask; i++) {
1900 if (i < 3) {
1901 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1904 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1905 printk("Initialisation block at 0x%8.8lx(Phys)\n", virt_to_phys(lp->sh_mem));
1906 printk(" mode: 0x%4.4x\n", p->mode);
1907 printk(" physical address: ");
1908 for (i = 0; i < ETH_ALEN - 1; i++) {
1909 printk("%2.2x:", p->phys_addr[i]);
1911 printk("%2.2x\n", p->phys_addr[i]);
1912 printk(" multicast hash table: ");
1913 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) {
1914 printk("%2.2x:", p->mcast_table[i]);
1916 printk("%2.2x\n", p->mcast_table[i]);
1917 printk(" rx_ring at: 0x%8.8x\n", p->rx_ring);
1918 printk(" tx_ring at: 0x%8.8x\n", p->tx_ring);
1919 printk("buffers (Phys): 0x%8.8lx\n", virt_to_phys(lp->sh_mem) + lp->buffs_offset);
1920 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen);
1921 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen);
1922 outw(CSR2, DEPCA_ADDR);
1923 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA));
1924 outw(CSR1, DEPCA_ADDR);
1925 printk("%4.4x\n", inw(DEPCA_DATA));
1926 outw(CSR3, DEPCA_ADDR);
1927 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA));
1930 return;
1934 ** Perform IOCTL call functions here. Some are privileged operations and the
1935 ** effective uid is checked in those cases.
1936 ** All multicast IOCTLs will not work here and are for testing purposes only.
1938 static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1940 struct depca_private *lp = (struct depca_private *) dev->priv;
1941 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1942 int i, status = 0;
1943 u_long ioaddr = dev->base_addr;
1944 union {
1945 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1946 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1947 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1948 } tmp;
1949 unsigned long flags;
1950 void *buf;
1952 switch (ioc->cmd) {
1953 case DEPCA_GET_HWADDR: /* Get the hardware address */
1954 for (i = 0; i < ETH_ALEN; i++) {
1955 tmp.addr[i] = dev->dev_addr[i];
1957 ioc->len = ETH_ALEN;
1958 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
1959 return -EFAULT;
1960 break;
1962 case DEPCA_SET_HWADDR: /* Set the hardware address */
1963 if (!capable(CAP_NET_ADMIN))
1964 return -EPERM;
1965 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN))
1966 return -EFAULT;
1967 for (i = 0; i < ETH_ALEN; i++) {
1968 dev->dev_addr[i] = tmp.addr[i];
1970 netif_stop_queue(dev);
1971 while (lp->tx_old != lp->tx_new)
1972 cpu_relax(); /* Wait for the ring to empty */
1974 STOP_DEPCA; /* Temporarily stop the depca. */
1975 depca_init_ring(dev); /* Initialize the descriptor rings */
1976 LoadCSRs(dev); /* Reload CSR3 */
1977 InitRestartDepca(dev); /* Resume normal operation. */
1978 netif_start_queue(dev); /* Unlock the TX ring */
1979 break;
1981 case DEPCA_SET_PROM: /* Set Promiscuous Mode */
1982 if (!capable(CAP_NET_ADMIN))
1983 return -EPERM;
1984 netif_stop_queue(dev);
1985 while (lp->tx_old != lp->tx_new)
1986 cpu_relax(); /* Wait for the ring to empty */
1988 STOP_DEPCA; /* Temporarily stop the depca. */
1989 depca_init_ring(dev); /* Initialize the descriptor rings */
1990 lp->init_block.mode |= PROM; /* Set promiscuous mode */
1992 LoadCSRs(dev); /* Reload CSR3 */
1993 InitRestartDepca(dev); /* Resume normal operation. */
1994 netif_start_queue(dev); /* Unlock the TX ring */
1995 break;
1997 case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */
1998 if (!capable(CAP_NET_ADMIN))
1999 return -EPERM;
2000 netif_stop_queue(dev);
2001 while (lp->tx_old != lp->tx_new)
2002 cpu_relax(); /* Wait for the ring to empty */
2004 STOP_DEPCA; /* Temporarily stop the depca. */
2005 depca_init_ring(dev); /* Initialize the descriptor rings */
2006 lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */
2008 LoadCSRs(dev); /* Reload CSR3 */
2009 InitRestartDepca(dev); /* Resume normal operation. */
2010 netif_start_queue(dev); /* Unlock the TX ring */
2011 break;
2013 case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */
2014 if(!capable(CAP_NET_ADMIN))
2015 return -EPERM;
2016 printk("%s: Boo!\n", dev->name);
2017 break;
2019 case DEPCA_GET_MCA: /* Get the multicast address table */
2020 ioc->len = (HASH_TABLE_LEN >> 3);
2021 if (copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len))
2022 return -EFAULT;
2023 break;
2025 case DEPCA_SET_MCA: /* Set a multicast address */
2026 if (!capable(CAP_NET_ADMIN))
2027 return -EPERM;
2028 if (ioc->len >= HASH_TABLE_LEN)
2029 return -EINVAL;
2030 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len))
2031 return -EFAULT;
2032 set_multicast_list(dev);
2033 break;
2035 case DEPCA_CLR_MCA: /* Clear all multicast addresses */
2036 if (!capable(CAP_NET_ADMIN))
2037 return -EPERM;
2038 set_multicast_list(dev);
2039 break;
2041 case DEPCA_MCA_EN: /* Enable pass all multicast addressing */
2042 if (!capable(CAP_NET_ADMIN))
2043 return -EPERM;
2044 set_multicast_list(dev);
2045 break;
2047 case DEPCA_GET_STATS: /* Get the driver statistics */
2048 ioc->len = sizeof(lp->pktStats);
2049 buf = kmalloc(ioc->len, GFP_KERNEL);
2050 if(!buf)
2051 return -ENOMEM;
2052 spin_lock_irqsave(&lp->lock, flags);
2053 memcpy(buf, &lp->pktStats, ioc->len);
2054 spin_unlock_irqrestore(&lp->lock, flags);
2055 if (copy_to_user(ioc->data, buf, ioc->len))
2056 status = -EFAULT;
2057 kfree(buf);
2058 break;
2060 case DEPCA_CLR_STATS: /* Zero out the driver statistics */
2061 if (!capable(CAP_NET_ADMIN))
2062 return -EPERM;
2063 spin_lock_irqsave(&lp->lock, flags);
2064 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
2065 spin_unlock_irqrestore(&lp->lock, flags);
2066 break;
2068 case DEPCA_GET_REG: /* Get the DEPCA Registers */
2069 i = 0;
2070 tmp.sval[i++] = inw(DEPCA_NICSR);
2071 outw(CSR0, DEPCA_ADDR); /* status register */
2072 tmp.sval[i++] = inw(DEPCA_DATA);
2073 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
2074 ioc->len = i + sizeof(struct depca_init);
2075 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
2076 return -EFAULT;
2077 break;
2079 default:
2080 return -EOPNOTSUPP;
2083 return status;
2086 #ifdef MODULE
2087 static struct net_device thisDepca;
2088 static int irq = 7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */
2089 static int io = 0x200; /* Or use the irq= io= options to insmod */
2090 MODULE_PARM(irq, "i");
2091 MODULE_PARM(io, "i");
2092 MODULE_PARM_DESC(irq, "DEPCA IRQ number");
2093 MODULE_PARM_DESC(io, "DEPCA I/O base address");
2095 /* See depca_probe() for autoprobe messages when a module */
2096 int init_module(void)
2098 thisDepca.irq = irq;
2099 thisDepca.base_addr = io;
2100 thisDepca.init = depca_probe;
2102 if (register_netdev(&thisDepca) != 0)
2103 return -EIO;
2105 return 0;
2108 void cleanup_module(void)
2110 struct depca_private *lp = thisDepca.priv;
2112 unregister_netdev(&thisDepca);
2113 if (lp) {
2114 iounmap(lp->sh_mem);
2115 release_mem_region (lp->mem_start, lp->mem_len);
2116 #ifdef CONFIG_MCA
2117 if (lp->mca_slot != -1)
2118 mca_mark_as_unused(lp->mca_slot);
2119 #endif
2120 kfree(lp);
2121 thisDepca.priv = NULL;
2123 thisDepca.irq = 0;
2125 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
2127 #endif /* MODULE */
2128 MODULE_LICENSE("GPL");
2132 * Local variables:
2133 * 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"
2135 * 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"
2136 * End: