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
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:
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
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
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
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
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
138 6) run the net startup bits for your eth?? interface manually
139 (usually /etc/rc.inet[12] at boot time).
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
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
170 ************************************************************************
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
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().
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
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
234 =========================================================================
237 #include <linux/config.h>
238 #include <linux/module.h>
240 #include <linux/kernel.h>
241 #include <linux/sched.h>
242 #include <linux/string.h>
243 #include <linux/ptrace.h>
244 #include <linux/errno.h>
245 #include <linux/ioport.h>
246 #include <linux/slab.h>
247 #include <linux/interrupt.h>
248 #include <linux/delay.h>
249 #include <linux/init.h>
250 #include <linux/crc32.h>
251 #include <asm/uaccess.h>
252 #include <asm/bitops.h>
256 #include <linux/netdevice.h>
257 #include <linux/etherdevice.h>
258 #include <linux/skbuff.h>
260 #include <linux/time.h>
261 #include <linux/types.h>
262 #include <linux/unistd.h>
263 #include <linux/ctype.h>
266 #include <linux/mca.h>
271 static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
274 static int depca_debug = DEPCA_DEBUG;
276 static int depca_debug = 1;
279 #define DEPCA_NDA 0xffe0 /* No Device Address */
281 #define TX_TIMEOUT (1*HZ)
284 ** Ethernet PROM defines
286 #define PROBE_LENGTH 32
287 #define ETH_PROM_SIG 0xAA5500FFUL
290 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
291 ** here is <= to the amount of shared memory set up by the board switches.
292 ** The number of descriptors MUST BE A POWER OF 2.
294 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
296 #define NUM_RX_DESC 8 /* Number of RX descriptors */
297 #define NUM_TX_DESC 8 /* Number of TX descriptors */
298 #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
299 #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
304 #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
305 #define MAX_EISA_SLOTS 16
306 #define EISA_SLOT_INC 0x1000
311 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
312 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
313 #define DEPCA_TOTAL_SIZE 0x10
314 static short mem_chkd;
317 ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
319 #define DE212_ID 0x6def
322 ** Name <-> Adapter mapping
324 #define DEPCA_SIGNATURE {"DEPCA",\
326 "DE200","DE201","DE202",\
331 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
335 ** Miscellaneous info...
337 #define DEPCA_STRLEN 16
338 #define MAX_NUM_DEPCAS 2
341 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
342 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
343 ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
344 ** and hence the RX descriptor ring's first entry.
346 #define ALIGN4 ((u_long)4 - 1) /* 1 longword align */
347 #define ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
348 #define ALIGN ALIGN8 /* Keep the LANCE happy... */
351 ** The DEPCA Rx and Tx ring descriptors.
353 struct depca_rx_desc {
355 s16 buf_length; /* This length is negative 2's complement! */
356 s16 msg_length; /* This length is "normal". */
359 struct depca_tx_desc {
361 s16 length; /* This length is negative 2's complement! */
362 s16 misc; /* Errors and TDR info */
365 #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
366 to LANCE memory address space */
369 ** The Lance initialization block, described in databook, in common memory.
372 u16 mode; /* Mode register */
373 u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
374 u8 mcast_table[8]; /* Multicast Hash Table. */
375 u32 rx_ring; /* Rx ring base pointer & ring length */
376 u32 tx_ring; /* Tx ring base pointer & ring length */
379 #define DEPCA_PKT_STAT_SZ 16
380 #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
381 increase DEPCA_PKT_STAT_SZ */
382 struct depca_private {
383 char devname[DEPCA_STRLEN]; /* Device Product String */
384 char adapter_name[DEPCA_STRLEN]; /* /proc/ioports string */
385 char adapter; /* Adapter type */
386 char mca_slot; /* MCA slot, if MCA else -1 */
387 struct depca_init init_block; /* Shadow Initialization block */
388 /* CPU address space fields */
389 struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
390 struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
391 void *rx_buff[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
392 void *tx_buff[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
393 void *sh_mem; /* CPU mapped virt address of device RAM */
394 /* Device address space fields */
395 u_long device_ram_start; /* Start of RAM in device addr space */
396 /* Offsets used in both address spaces */
397 u_long rx_ring_offset; /* Offset from start of RAM to rx_ring */
398 u_long tx_ring_offset; /* Offset from start of RAM to tx_ring */
399 u_long buffs_offset; /* LANCE Rx and Tx buffers start address. */
400 /* Kernel-only (not device) fields */
401 int rx_new, tx_new; /* The next free ring entry */
402 int rx_old, tx_old; /* The ring entries to be free()ed. */
403 struct net_device_stats stats;
405 struct { /* Private stats counters */
406 u32 bins[DEPCA_PKT_STAT_SZ];
410 u32 excessive_collisions;
412 u32 excessive_underruns;
414 int txRingMask; /* TX ring mask */
415 int rxRingMask; /* RX ring mask */
416 s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
417 s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
421 ** The transmit ring full condition is described by the tx_old and tx_new
423 ** tx_old = tx_new Empty ring
424 ** tx_old = tx_new+1 Full ring
425 ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
427 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
428 lp->tx_old+lp->txRingMask-lp->tx_new:\
429 lp->tx_old -lp->tx_new-1)
434 static int depca_open(struct net_device *dev);
435 static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev);
436 static void depca_interrupt(int irq, void *dev_id, struct pt_regs *regs);
437 static int depca_close(struct net_device *dev);
438 static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
439 static void depca_tx_timeout(struct net_device *dev);
440 static struct net_device_stats *depca_get_stats(struct net_device *dev);
441 static void set_multicast_list(struct net_device *dev);
446 static int depca_hw_init(struct net_device *dev, u_long ioaddr, int mca_slot);
447 static void depca_init_ring(struct net_device *dev);
448 static int depca_rx(struct net_device *dev);
449 static int depca_tx(struct net_device *dev);
451 static void LoadCSRs(struct net_device *dev);
452 static int InitRestartDepca(struct net_device *dev);
453 static void DepcaSignature(char *name, u_long paddr);
454 static int DevicePresent(u_long ioaddr);
455 static int get_hw_addr(struct net_device *dev);
456 static int EISA_signature(char *name, s32 eisa_id);
457 static void SetMulticastFilter(struct net_device *dev);
458 static void isa_probe(struct net_device *dev, u_long iobase);
459 static void eisa_probe(struct net_device *dev, u_long iobase);
461 static void mca_probe(struct net_device *dev, u_long iobase);
463 static struct net_device *alloc_device(struct net_device *dev, u_long iobase);
464 static int depca_dev_index(char *s);
465 static struct net_device *insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *));
466 static int load_packet(struct net_device *dev, struct sk_buff *skb);
467 static void depca_dbg_open(struct net_device *dev);
470 int init_module(void);
471 void cleanup_module(void);
472 static int autoprobed = 1, loading_module = 1;
474 static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 };
475 static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 };
476 static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 };
477 static u_char *depca_irq;
478 static int autoprobed, loading_module;
481 static char name[DEPCA_STRLEN];
482 static int num_depcas, num_eth;
483 static int mem; /* For loadable module assignment
484 use insmod mem=0x????? .... */
485 static char *adapter_name; /* = '\0'; If no PROM when loadable module
486 use insmod adapter_name=DE??? ...
487 bss initializes this to zero
490 ** Miscellaneous defines...
493 outw(CSR0, DEPCA_ADDR);\
494 outw(STOP, DEPCA_DATA)
496 int __init depca_probe(struct net_device *dev)
498 int tmp = num_depcas, status = -ENODEV;
499 u_long iobase = dev->base_addr;
501 SET_MODULE_OWNER(dev);
503 if ((iobase == 0) && loading_module) {
504 printk("Autoprobing is not supported when loading a module based driver.\n");
508 mca_probe(dev, iobase);
510 isa_probe(dev, iobase);
511 eisa_probe(dev, iobase);
513 if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
514 printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name, iobase);
518 ** Walk the device list to check that at least one device
521 for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
532 static int __init depca_hw_init(struct net_device *dev, u_long ioaddr, int mca_slot)
534 struct depca_private *lp;
535 int i, j, offset, netRAM, mem_len, status = 0;
537 u_long mem_start = 0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
541 nicsr = inb(DEPCA_NICSR);
542 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
543 outb(nicsr, DEPCA_NICSR);
545 if (inw(DEPCA_DATA) != STOP) {
550 strcpy(name, (adapter_name ? adapter_name : ""));
551 mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]);
552 DepcaSignature(name, mem_start);
553 } while (!mem && mem_base[mem_chkd] && (adapter == unknown));
555 if ((adapter == unknown) || !mem_start) { /* DEPCA device not found */
559 dev->base_addr = ioaddr;
561 if (mca_slot != -1) {
562 printk("%s: %s at 0x%04lx (MCA slot %d)", dev->name, name, ioaddr, mca_slot);
563 } else if ((ioaddr & 0x0fff) == DEPCA_EISA_IO_PORTS) { /* EISA slot address */
564 printk("%s: %s at 0x%04lx (EISA slot %d)", dev->name, name, ioaddr, (int) ((ioaddr >> 12) & 0x0f));
565 } else { /* ISA port address */
566 printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
569 printk(", h/w address ");
570 status = get_hw_addr(dev);
572 printk(" which has an Ethernet PROM CRC error.\n");
575 for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet address */
576 printk("%2.2x:", dev->dev_addr[i]);
578 printk("%2.2x", dev->dev_addr[i]);
580 /* Set up the maximum amount of network RAM(kB) */
581 netRAM = ((adapter != DEPCA) ? 64 : 48);
582 if ((nicsr & _128KB) && (adapter == de422))
586 /* Shared Memory Base Address */
588 offset = 0x8000; /* 32kbyte RAM offset */
589 nicsr &= ~BS; /* DEPCA RAM in top 32k */
592 mem_start += offset; /* (E)ISA start address */
593 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)))
595 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
599 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
601 /* Enable the shadow RAM. */
602 if (adapter != DEPCA) {
604 outb(nicsr, DEPCA_NICSR);
607 /* Define the device private memory */
608 dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
609 if (dev->priv == NULL)
611 lp = (struct depca_private *) dev->priv;
612 memset((char *) dev->priv, 0, sizeof(struct depca_private));
613 lp->adapter = adapter;
614 lp->mca_slot = mca_slot;
615 lp->lock = SPIN_LOCK_UNLOCKED;
616 sprintf(lp->adapter_name, "%s (%s)", name, dev->name);
618 if (!request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name)) {
619 printk(KERN_ERR "depca: I/O resource 0x%x @ 0x%lx busy\n", DEPCA_TOTAL_SIZE, ioaddr);
623 /* Initialisation Block */
624 lp->sh_mem = ioremap(mem_start, mem_len);
626 if (lp->sh_mem == NULL) {
627 printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n");
630 lp->device_ram_start = mem_start & LA_MASK;
633 offset += sizeof(struct depca_init);
635 /* Tx & Rx descriptors (aligned to a quadword boundary) */
636 offset = (offset + ALIGN) & ~ALIGN;
637 lp->rx_ring = (struct depca_rx_desc *) (lp->sh_mem + offset);
638 lp->rx_ring_offset = offset;
640 offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
641 lp->tx_ring = (struct depca_tx_desc *) (lp->sh_mem + offset);
642 lp->tx_ring_offset = offset;
644 offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
646 lp->buffs_offset = offset;
648 /* Finish initialising the ring information. */
649 lp->rxRingMask = NUM_RX_DESC - 1;
650 lp->txRingMask = NUM_TX_DESC - 1;
652 /* Calculate Tx/Rx RLEN size for the descriptors. */
653 for (i = 0, j = lp->rxRingMask; j > 0; i++) {
656 lp->rx_rlen = (s32) (i << 29);
657 for (i = 0, j = lp->txRingMask; j > 0; i++) {
660 lp->tx_rlen = (s32) (i << 29);
662 /* Load the initialisation block */
663 depca_init_ring(dev);
665 /* Initialise the control and status registers */
668 /* Enable DEPCA board interrupts for autoprobing */
669 nicsr = ((nicsr & ~IM) | IEN);
670 outb(nicsr, DEPCA_NICSR);
672 /* To auto-IRQ we enable the initialization-done and DMA err,
673 interrupts. For now we will always get a DMA error. */
676 unsigned char irqnum;
679 /* Assign the correct irq list */
680 switch (lp->adapter) {
684 depca_irq = de1xx_irq;
691 depca_irq = de2xx_irq;
694 depca_irq = de422_irq;
698 /* Trigger an initialization just for the interrupt. */
699 outw(INEA | INIT, DEPCA_DATA);
701 irqnum = autoirq_report(1);
704 printk(" and failed to detect IRQ line.\n");
707 for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
708 if (irqnum == depca_irq[i]) {
710 printk(" and uses IRQ%d.\n", dev->irq);
715 printk(" but incorrect IRQ line detected.\n");
721 printk(" and assigned IRQ%d.\n", dev->irq);
724 if (depca_debug > 1) {
728 /* The DEPCA-specific entries in the device structure. */
729 dev->open = &depca_open;
730 dev->hard_start_xmit = &depca_start_xmit;
731 dev->stop = &depca_close;
732 dev->get_stats = &depca_get_stats;
733 dev->set_multicast_list = &set_multicast_list;
734 dev->do_ioctl = &depca_ioctl;
735 dev->tx_timeout = depca_tx_timeout;
736 dev->watchdog_timeo = TX_TIMEOUT;
740 /* Fill in the generic field of the device structure. */
744 release_region(ioaddr, DEPCA_TOTAL_SIZE);
752 static int depca_open(struct net_device *dev)
754 struct depca_private *lp = (struct depca_private *) dev->priv;
755 u_long ioaddr = dev->base_addr;
760 nicsr = inb(DEPCA_NICSR);
762 /* Make sure the shadow RAM is enabled */
763 if (lp->adapter != DEPCA) {
765 outb(nicsr, DEPCA_NICSR);
768 /* Re-initialize the DEPCA... */
769 depca_init_ring(dev);
774 if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, dev)) {
775 printk("depca_open(): Requested IRQ%d is busy\n", dev->irq);
779 /* Enable DEPCA board interrupts and turn off LED */
780 nicsr = ((nicsr & ~IM & ~LED) | IEN);
781 outb(nicsr, DEPCA_NICSR);
782 outw(CSR0, DEPCA_ADDR);
784 netif_start_queue(dev);
786 status = InitRestartDepca(dev);
788 if (depca_debug > 1) {
789 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA));
790 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR));
796 /* Initialize the lance Rx and Tx descriptor rings. */
797 static void depca_init_ring(struct net_device *dev)
799 struct depca_private *lp = (struct depca_private *) dev->priv;
803 /* Lock out other processes whilst setting up the hardware */
804 netif_stop_queue(dev);
806 lp->rx_new = lp->tx_new = 0;
807 lp->rx_old = lp->tx_old = 0;
809 /* Initialize the base address and length of each buffer in the ring */
810 for (i = 0; i <= lp->rxRingMask; i++) {
811 offset = lp->buffs_offset + i * RX_BUFF_SZ;
812 writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base);
813 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
814 lp->rx_buff[i] = lp->sh_mem + offset;
817 for (i = 0; i <= lp->txRingMask; i++) {
818 offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ;
819 writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base);
820 lp->tx_buff[i] = lp->sh_mem + offset;
823 /* Set up the initialization block */
824 lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen;
825 lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen;
827 SetMulticastFilter(dev);
829 for (i = 0; i < ETH_ALEN; i++) {
830 lp->init_block.phys_addr[i] = dev->dev_addr[i];
833 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
837 static void depca_tx_timeout(struct net_device *dev)
839 u_long ioaddr = dev->base_addr;
841 printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA));
844 depca_init_ring(dev);
846 dev->trans_start = jiffies;
847 netif_wake_queue(dev);
848 InitRestartDepca(dev);
853 ** Writes a socket buffer to TX descriptor ring and starts transmission
855 static int depca_start_xmit(struct sk_buff *skb, struct net_device *dev)
857 struct depca_private *lp = (struct depca_private *) dev->priv;
858 u_long ioaddr = dev->base_addr;
861 /* Transmitter timeout, serious problems. */
865 netif_stop_queue(dev);
867 if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
868 status = load_packet(dev, skb);
871 /* Trigger an immediate send demand. */
872 outw(CSR0, DEPCA_ADDR);
873 outw(INEA | TDMD, DEPCA_DATA);
875 dev->trans_start = jiffies;
879 netif_start_queue(dev);
888 ** The DEPCA interrupt handler.
890 static void depca_interrupt(int irq, void *dev_id, struct pt_regs *regs)
892 struct net_device *dev = dev_id;
893 struct depca_private *lp;
898 printk("depca_interrupt(): irq %d for unknown device.\n", irq);
902 lp = (struct depca_private *) dev->priv;
903 ioaddr = dev->base_addr;
905 spin_lock(&lp->lock);
907 /* mask the DEPCA board interrupts and turn on the LED */
908 nicsr = inb(DEPCA_NICSR);
910 outb(nicsr, DEPCA_NICSR);
912 outw(CSR0, DEPCA_ADDR);
913 csr0 = inw(DEPCA_DATA);
915 /* Acknowledge all of the current interrupt sources ASAP. */
916 outw(csr0 & INTE, DEPCA_DATA);
918 if (csr0 & RINT) /* Rx interrupt (packet arrived) */
921 if (csr0 & TINT) /* Tx interrupt (packet sent) */
924 /* Any resources available? */
925 if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) {
926 netif_wake_queue(dev);
929 /* Unmask the DEPCA board interrupts and turn off the LED */
930 nicsr = (nicsr & ~IM & ~LED);
931 outb(nicsr, DEPCA_NICSR);
933 spin_unlock(&lp->lock);
937 static int depca_rx(struct net_device *dev)
939 struct depca_private *lp = (struct depca_private *) dev->priv;
943 for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) {
944 status = readl(&lp->rx_ring[entry].base) >> 16;
945 if (status & R_STP) { /* Remember start of frame */
948 if (status & R_ENP) { /* Valid frame status */
949 if (status & R_ERR) { /* There was an error. */
950 lp->stats.rx_errors++; /* Update the error stats. */
952 lp->stats.rx_frame_errors++;
954 lp->stats.rx_over_errors++;
956 lp->stats.rx_crc_errors++;
958 lp->stats.rx_fifo_errors++;
960 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
963 skb = dev_alloc_skb(pkt_len + 2);
966 skb_reserve(skb, 2); /* 16 byte align the IP header */
967 buf = skb_put(skb, pkt_len);
969 if (entry < lp->rx_old) { /* Wrapped buffer */
970 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
971 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len);
972 memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len);
973 } else { /* Linear buffer */
974 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len);
978 ** Notify the upper protocol layers that there is another
981 skb->protocol = eth_type_trans(skb, dev);
987 dev->last_rx = jiffies;
988 lp->stats.rx_packets++;
989 lp->stats.rx_bytes += pkt_len;
990 for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) {
991 if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) {
992 lp->pktStats.bins[i]++;
993 i = DEPCA_PKT_STAT_SZ;
996 if (buf[0] & 0x01) { /* Multicast/Broadcast */
997 if ((*(s16 *) & buf[0] == -1) && (*(s16 *) & buf[2] == -1) && (*(s16 *) & buf[4] == -1)) {
998 lp->pktStats.broadcast++;
1000 lp->pktStats.multicast++;
1002 } 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])) {
1003 lp->pktStats.unicast++;
1006 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
1007 if (lp->pktStats.bins[0] == 0) { /* Reset counters */
1008 memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats));
1011 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
1012 lp->stats.rx_dropped++; /* Really, deferred. */
1016 /* Change buffer ownership for this last frame, back to the adapter */
1017 for (; lp->rx_old != entry; lp->rx_old = (++lp->rx_old) & lp->rxRingMask) {
1018 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base);
1020 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1024 ** Update entry information
1026 lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
1033 ** Buffer sent - check for buffer errors.
1035 static int depca_tx(struct net_device *dev)
1037 struct depca_private *lp = (struct depca_private *) dev->priv;
1040 u_long ioaddr = dev->base_addr;
1042 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1043 status = readl(&lp->tx_ring[entry].base) >> 16;
1045 if (status < 0) { /* Packet not yet sent! */
1047 } else if (status & T_ERR) { /* An error occurred. */
1048 status = readl(&lp->tx_ring[entry].misc);
1049 lp->stats.tx_errors++;
1050 if (status & TMD3_RTRY)
1051 lp->stats.tx_aborted_errors++;
1052 if (status & TMD3_LCAR)
1053 lp->stats.tx_carrier_errors++;
1054 if (status & TMD3_LCOL)
1055 lp->stats.tx_window_errors++;
1056 if (status & TMD3_UFLO)
1057 lp->stats.tx_fifo_errors++;
1058 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1059 /* Trigger an immediate send demand. */
1060 outw(CSR0, DEPCA_ADDR);
1061 outw(INEA | TDMD, DEPCA_DATA);
1063 } else if (status & (T_MORE | T_ONE)) {
1064 lp->stats.collisions++;
1066 lp->stats.tx_packets++;
1069 /* Update all the pointers */
1070 lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1076 static int depca_close(struct net_device *dev)
1078 struct depca_private *lp = (struct depca_private *) dev->priv;
1080 u_long ioaddr = dev->base_addr;
1082 netif_stop_queue(dev);
1084 outw(CSR0, DEPCA_ADDR);
1086 if (depca_debug > 1) {
1087 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA));
1091 ** We stop the DEPCA here -- it occasionally polls
1092 ** memory if we don't.
1094 outw(STOP, DEPCA_DATA);
1097 ** Give back the ROM in case the user wants to go to DOS
1099 if (lp->adapter != DEPCA) {
1100 nicsr = inb(DEPCA_NICSR);
1102 outb(nicsr, DEPCA_NICSR);
1106 ** Free the associated irq
1108 free_irq(dev->irq, dev);
1112 static void LoadCSRs(struct net_device *dev)
1114 struct depca_private *lp = (struct depca_private *) dev->priv;
1115 u_long ioaddr = dev->base_addr;
1117 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
1118 outw((u16) lp->device_ram_start, DEPCA_DATA);
1119 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
1120 outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA);
1121 outw(CSR3, DEPCA_ADDR); /* ALE control */
1122 outw(ACON, DEPCA_DATA);
1124 outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
1129 static int InitRestartDepca(struct net_device *dev)
1131 struct depca_private *lp = (struct depca_private *) dev->priv;
1132 u_long ioaddr = dev->base_addr;
1135 /* Copy the shadow init_block to shared memory */
1136 memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1138 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
1139 outw(INIT, DEPCA_DATA); /* initialize DEPCA */
1141 /* wait for lance to complete initialisation */
1142 for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++);
1145 /* clear IDON by writing a "1", enable interrupts and start lance */
1146 outw(IDON | INEA | STRT, DEPCA_DATA);
1147 if (depca_debug > 2) {
1148 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));
1151 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));
1158 static struct net_device_stats *depca_get_stats(struct net_device *dev)
1160 struct depca_private *lp = (struct depca_private *) dev->priv;
1162 /* Null body since there is no framing error counter */
1168 ** Set or clear the multicast filter for this adaptor.
1170 static void set_multicast_list(struct net_device *dev)
1172 struct depca_private *lp = (struct depca_private *) dev->priv;
1173 u_long ioaddr = dev->base_addr;
1176 netif_stop_queue(dev);
1177 while (lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
1179 STOP_DEPCA; /* Temporarily stop the depca. */
1180 depca_init_ring(dev); /* Initialize the descriptor rings */
1182 if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
1183 lp->init_block.mode |= PROM;
1185 SetMulticastFilter(dev);
1186 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
1189 LoadCSRs(dev); /* Reload CSR3 */
1190 InitRestartDepca(dev); /* Resume normal operation. */
1191 netif_start_queue(dev); /* Unlock the TX ring */
1196 ** Calculate the hash code and update the logical address filter
1197 ** from a list of ethernet multicast addresses.
1198 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1199 ** LANCE calculates its hash codes big endian.
1201 static void SetMulticastFilter(struct net_device *dev)
1203 struct depca_private *lp = (struct depca_private *) dev->priv;
1204 struct dev_mc_list *dmi = dev->mc_list;
1206 int i, j, bit, byte;
1210 if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
1211 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1212 lp->init_block.mcast_table[i] = (char) 0xff;
1215 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { /* Clear the multicast table */
1216 lp->init_block.mcast_table[i] = 0;
1218 /* Add multicast addresses */
1219 for (i = 0; i < dev->mc_count; i++) { /* for each address in the list */
1220 addrs = dmi->dmi_addr;
1222 if ((*addrs & 0x01) == 1) { /* multicast address? */
1223 crc = ether_crc(ETH_ALEN, addrs);
1224 hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
1225 for (j = 0; j < 5; j++) { /* ... in reverse order. */
1226 hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
1230 byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
1231 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
1232 lp->init_block.mcast_table[byte] |= bit;
1242 ** Microchannel bus I/O device probe
1244 static void __init mca_probe(struct net_device *dev, u_long ioaddr)
1246 unsigned char pos[2];
1247 unsigned char where;
1248 unsigned long iobase;
1253 ** See if we've been here before.
1255 if ((!ioaddr && autoprobed) || (ioaddr && !loading_module))
1260 ** Search for the adapter. If an address has been given, search
1261 ** specifically for the card at that address. Otherwise find the
1262 ** first card in the system.
1264 while ((dev != NULL) && ((slot = mca_find_adapter(DE212_ID, slot)) != MCA_NOTFOUND)) {
1265 pos[0] = mca_read_stored_pos(slot, 2);
1266 pos[1] = mca_read_stored_pos(slot, 3);
1269 ** IO of card is handled by bits 1 and 2 of pos0.
1277 where = (pos[0] & 6) >> 1;
1278 iobase = 0x2c00 + (0x10 * where);
1280 if ((ioaddr) && (ioaddr != iobase)) {
1282 ** Card was found, but not at the right IO location. Continue
1283 ** scanning from the next MCA slot up for another card.
1290 ** Found the adapter we were looking for. Now start setting it up.
1292 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1293 ** of pos1. Bits are as follows (from the ADF file):
1297 ** --------------------
1303 where = pos[1] & 0x0f;
1318 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev->name, where);
1323 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1324 ** They are mapped as follows:
1327 ** 5 4 3 Memory Addresses
1328 ** 0 0 0 C0000-CFFFF (64K)
1329 ** 1 0 0 C8000-CFFFF (32K)
1330 ** 0 0 1 D0000-DFFFF (64K)
1331 ** 1 0 1 D8000-DFFFF (32K)
1332 ** 0 1 0 E0000-EFFFF (64K)
1333 ** 1 1 0 E8000-EFFFF (32K)
1335 where = (pos[0] & 0x18) >> 3;
1336 mem = 0xc0000 + (where * 0x10000);
1337 if (pos[0] & 0x20) {
1342 ** Get everything allocated and initialized... (almost just
1343 ** like the ISA and EISA probes)
1345 if (DevicePresent(iobase) != 0) {
1347 ** If the MCA configuration says the card should be here,
1348 ** it really should be here.
1350 printk(KERN_ERR "%s: MCA reports card at 0x%lx but it is not responding.\n", dev->name, iobase);
1353 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1354 if ((dev = alloc_device(dev, iobase)) != NULL) {
1356 if (depca_hw_init(dev, iobase, slot) == 0) {
1358 ** Adapter initialized correctly: Name it in
1361 mca_set_adapter_name(slot, "DE210/212 Ethernet Adapter");
1362 mca_mark_as_used(slot);
1367 } else if (autoprobed) {
1368 printk(KERN_WARNING "%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1372 ** If this is a probe by a module, return after setting up the
1379 ** Set up to check the next slot and loop.
1390 ** ISA bus I/O device probe
1392 static void __init isa_probe(struct net_device *dev, u_long ioaddr)
1394 int i = num_depcas, maxSlots;
1395 s32 ports[] = DEPCA_IO_PORTS;
1397 if (!ioaddr && autoprobed)
1398 return; /* Been here before ! */
1400 return; /* EISA Address */
1401 if (i >= MAX_NUM_DEPCAS)
1402 return; /* Too many ISA adapters */
1404 if (ioaddr == 0) { /* Autoprobing */
1405 maxSlots = MAX_NUM_DEPCAS;
1406 } else { /* Probe a specific location */
1411 for (; (i < maxSlots) && (dev != NULL) && ports[i]; i++) {
1412 if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1413 if (DevicePresent(ports[i]) == 0) {
1414 if ((dev = alloc_device(dev, ports[i])) != NULL) {
1415 if (depca_hw_init(dev, ports[i], -1) == 0) {
1421 } else if (autoprobed) {
1422 printk("%s: region already allocated at 0x%04x.\n", dev->name, ports[i]);
1430 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1431 ** the motherboard. Upto 15 EISA devices are supported.
1433 static void __init eisa_probe(struct net_device *dev, u_long ioaddr)
1437 char name[DEPCA_STRLEN];
1439 if (!ioaddr && autoprobed)
1440 return; /* Been here before ! */
1441 if ((ioaddr < 0x400) && (ioaddr > 0))
1442 return; /* ISA Address */
1444 if (ioaddr == 0) { /* Autoprobing */
1445 iobase = EISA_SLOT_INC; /* Get the first slot address */
1447 maxSlots = MAX_EISA_SLOTS;
1448 } else { /* Probe a specific location */
1453 if ((iobase & 0x0fff) == 0)
1454 iobase += DEPCA_EISA_IO_PORTS;
1456 for (; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) {
1457 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1458 if (EISA_signature(name, EISA_ID)) {
1459 if (DevicePresent(iobase) == 0) {
1460 if ((dev = alloc_device(dev, iobase)) != NULL) {
1461 if (depca_hw_init(dev, iobase, -1) == 0) {
1468 } else if (autoprobed) {
1469 printk("%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
1477 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1478 ** found then check for an autoprobe or unused device location. If they
1479 ** are not available then insert a new device structure at the end of
1480 ** the current list.
1482 static struct net_device *__init alloc_device(struct net_device *dev, u_long iobase)
1484 struct net_device *adev = NULL;
1485 int fixed = 0, new_dev = 0;
1487 num_eth = depca_dev_index(dev->name);
1492 if (((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) && !adev) {
1494 } else if ((dev->priv == NULL) && (dev->base_addr == iobase)) {
1497 if (dev->next == NULL) {
1499 } else if (strncmp(dev->next->name, "eth", 3) != 0) {
1503 if ((dev->next == NULL) || new_dev || fixed)
1508 if (adev && !fixed) {
1510 num_eth = depca_dev_index(dev->name);
1514 if (((dev->next == NULL) && ((dev->base_addr != DEPCA_NDA) && (dev->base_addr != 0)) && !fixed) || new_dev) {
1515 num_eth++; /* New device */
1516 dev = insert_device(dev, iobase, depca_probe);
1523 ** If at end of eth device list and can't use current entry, malloc
1524 ** one up. If memory could not be allocated, print an error message.
1526 static struct net_device *__init insert_device(struct net_device *dev, u_long iobase, int (*init) (struct net_device *))
1528 struct net_device *new;
1530 new = (struct net_device *) kmalloc(sizeof(struct net_device), GFP_KERNEL);
1532 printk("eth%d: Device not initialised, insufficient memory\n", num_eth);
1535 new->next = dev->next;
1537 dev = dev->next; /* point to the new device */
1538 if (num_eth > 9999) {
1539 sprintf(dev->name, "eth????"); /* New device name */
1541 sprintf(dev->name, "eth%d", num_eth); /* New device name */
1543 dev->base_addr = iobase; /* assign the io address */
1544 dev->init = init; /* initialisation routine */
1550 static int __init depca_dev_index(char *s)
1557 i = (i * 10) + (*s - '0');
1566 ** Look for a particular board name in the on-board Remote Diagnostics
1567 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1570 static void __init DepcaSignature(char *name, u_long paddr)
1573 const char *signatures[] = DEPCA_SIGNATURE;
1577 /* Copy the first 16 bytes of ROM */
1578 ptr = ioremap(paddr + 0xc000, 16);
1580 printk(KERN_ERR "depca: I/O remap failed at %lx\n", paddr + 0xc000);
1584 for (i = 0; i < 16; i++) {
1585 tmpstr[i] = readb(ptr + 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 */
1594 } else { /* lost signature; begin search again */
1598 if (k == strlen(signatures[i]))
1602 /* Check if name string is valid, provided there's no PROM */
1603 if (*name && (i == unknown)) {
1604 for (i = 0; *signatures[i] != '\0'; i++) {
1605 if (strcmp(name, signatures[i]) == 0)
1610 /* Update search results */
1611 strcpy(name, signatures[i]);
1618 ** Look for a special sequence in the Ethernet station address PROM that
1619 ** is common across all DEPCA products. Note that the original DEPCA needs
1620 ** its ROM address counter to be initialized and enabled. Only enable
1621 ** if the first address octet is a 0x08 - this minimises the chances of
1622 ** messing around with some other hardware, but it assumes that this DEPCA
1623 ** card initialized itself correctly.
1625 ** Search the Ethernet address ROM for the signature. Since the ROM address
1626 ** counter can start at an arbitrary point, the search must include the entire
1627 ** probe sequence length plus the (length_of_the_signature - 1).
1628 ** Stop the search IMMEDIATELY after the signature is found so that the
1629 ** PROM address counter is correctly positioned at the start of the
1630 ** ethernet address for later read out.
1632 static int __init DevicePresent(u_long ioaddr)
1639 char Sig[sizeof(u32) << 1];
1642 short sigLength = 0;
1645 int i, j, status = 0;
1647 data = inb(DEPCA_PROM); /* clear counter on DEPCA */
1648 data = inb(DEPCA_PROM); /* read data */
1650 if (data == 0x08) { /* Enable counter on DEPCA */
1651 nicsr = inb(DEPCA_NICSR);
1653 outb(nicsr, DEPCA_NICSR);
1656 dev.llsig.a = ETH_PROM_SIG;
1657 dev.llsig.b = ETH_PROM_SIG;
1658 sigLength = sizeof(u32) << 1;
1660 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
1661 data = inb(DEPCA_PROM);
1662 if (dev.Sig[j] == data) { /* track signature */
1664 } else { /* lost signature; begin search again */
1665 if (data == dev.Sig[0]) { /* rare case.... */
1673 if (j != sigLength) {
1674 status = -ENODEV; /* search failed */
1681 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1682 ** reason: access the upper half of the PROM with x=0; access the lower half
1685 static int __init get_hw_addr(struct net_device *dev)
1687 u_long ioaddr = dev->base_addr;
1688 int i, k, tmp, status = 0;
1689 u_short j, x, chksum;
1691 x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1693 for (i = 0, k = 0, j = 0; j < 3; j++) {
1698 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1699 dev->dev_addr[i++] = (u_char) tmp;
1700 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1701 dev->dev_addr[i++] = (u_char) tmp;
1709 chksum = (u_char) inb(DEPCA_PROM + x);
1710 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1718 ** Load a packet into the shared memory
1720 static int load_packet(struct net_device *dev, struct sk_buff *skb)
1722 struct depca_private *lp = (struct depca_private *) dev->priv;
1723 int i, entry, end, len, status = 0;
1725 entry = lp->tx_new; /* Ring around buffer number. */
1726 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1727 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) { /* Enough room? */
1729 ** Caution: the write order is important here... don't set up the
1730 ** ownership rights until all the other information is in place.
1732 if (end < entry) { /* wrapped buffer */
1733 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1734 memcpy_toio(lp->tx_buff[entry], skb->data, len);
1735 memcpy_toio(lp->tx_buff[0], skb->data + len, skb->len - len);
1736 } else { /* linear buffer */
1737 memcpy_toio(lp->tx_buff[entry], skb->data, skb->len);
1740 /* set up the buffer descriptors */
1741 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1742 for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1743 /* clean out flags */
1744 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1745 writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */
1746 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length); /* packet length in buffer */
1749 /* clean out flags */
1750 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1751 writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */
1752 writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */
1754 /* start of packet */
1755 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1757 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1759 for (i = end; i != entry; --i) {
1760 /* ownership of packet */
1761 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1763 i = lp->txRingMask + 1;
1765 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1767 lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */
1776 ** Look for a particular board name in the EISA configuration space
1778 static int __init EISA_signature(char *name, s32 eisa_id)
1781 const char *signatures[] = DEPCA_SIGNATURE;
1782 char ManCode[DEPCA_STRLEN];
1790 Eisa.ID = inl(eisa_id);
1792 ManCode[0] = (((Eisa.Id[0] >> 2) & 0x1f) + 0x40);
1793 ManCode[1] = (((Eisa.Id[1] & 0xe0) >> 5) + ((Eisa.Id[0] & 0x03) << 3) + 0x40);
1794 ManCode[2] = (((Eisa.Id[2] >> 4) & 0x0f) + 0x30);
1795 ManCode[3] = ((Eisa.Id[2] & 0x0f) + 0x30);
1796 ManCode[4] = (((Eisa.Id[3] >> 4) & 0x0f) + 0x30);
1799 for (i = 0; (*signatures[i] != '\0') && (*name == '\0'); i++) {
1800 if (strstr(ManCode, signatures[i]) != NULL) {
1801 strcpy(name, ManCode);
1809 static void depca_dbg_open(struct net_device *dev)
1811 struct depca_private *lp = (struct depca_private *) dev->priv;
1812 u_long ioaddr = dev->base_addr;
1813 struct depca_init *p = &lp->init_block;
1816 if (depca_debug > 1) {
1817 /* Do not copy the shadow init block into shared memory */
1818 /* Debugging should not affect normal operation! */
1819 /* The shadow init block will get copied across during InitRestartDepca */
1820 printk("%s: depca open with irq %d\n", dev->name, dev->irq);
1821 printk("Descriptor head addresses (CPU):\n");
1822 printk(" 0x%lx 0x%lx\n", (u_long) lp->rx_ring, (u_long) lp->tx_ring);
1823 printk("Descriptor addresses (CPU):\nRX: ");
1824 for (i = 0; i < lp->rxRingMask; i++) {
1826 printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
1829 printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
1831 for (i = 0; i < lp->txRingMask; i++) {
1833 printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
1836 printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
1837 printk("\nDescriptor buffers (Device):\nRX: ");
1838 for (i = 0; i < lp->rxRingMask; i++) {
1840 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1843 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1845 for (i = 0; i < lp->txRingMask; i++) {
1847 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1850 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1851 printk("Initialisation block at 0x%8.8lx(Phys)\n", virt_to_phys(lp->sh_mem));
1852 printk(" mode: 0x%4.4x\n", p->mode);
1853 printk(" physical address: ");
1854 for (i = 0; i < ETH_ALEN - 1; i++) {
1855 printk("%2.2x:", p->phys_addr[i]);
1857 printk("%2.2x\n", p->phys_addr[i]);
1858 printk(" multicast hash table: ");
1859 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) {
1860 printk("%2.2x:", p->mcast_table[i]);
1862 printk("%2.2x\n", p->mcast_table[i]);
1863 printk(" rx_ring at: 0x%8.8x\n", p->rx_ring);
1864 printk(" tx_ring at: 0x%8.8x\n", p->tx_ring);
1865 printk("buffers (Phys): 0x%8.8lx\n", virt_to_phys(lp->sh_mem) + lp->buffs_offset);
1866 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen);
1867 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen);
1868 outw(CSR2, DEPCA_ADDR);
1869 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA));
1870 outw(CSR1, DEPCA_ADDR);
1871 printk("%4.4x\n", inw(DEPCA_DATA));
1872 outw(CSR3, DEPCA_ADDR);
1873 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA));
1880 ** Perform IOCTL call functions here. Some are privileged operations and the
1881 ** effective uid is checked in those cases.
1882 ** All multicast IOCTLs will not work here and are for testing purposes only.
1884 static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1886 struct depca_private *lp = (struct depca_private *) dev->priv;
1887 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1889 u_long ioaddr = dev->base_addr;
1891 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1892 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1893 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1897 case DEPCA_GET_HWADDR: /* Get the hardware address */
1898 for (i = 0; i < ETH_ALEN; i++) {
1899 tmp.addr[i] = dev->dev_addr[i];
1901 ioc->len = ETH_ALEN;
1902 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
1906 case DEPCA_SET_HWADDR: /* Set the hardware address */
1907 if (!capable(CAP_NET_ADMIN))
1909 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN))
1911 for (i = 0; i < ETH_ALEN; i++) {
1912 dev->dev_addr[i] = tmp.addr[i];
1914 netif_stop_queue(dev);
1915 while (lp->tx_old != lp->tx_new)
1916 cpu_relax(); /* Wait for the ring to empty */
1918 STOP_DEPCA; /* Temporarily stop the depca. */
1919 depca_init_ring(dev); /* Initialize the descriptor rings */
1920 LoadCSRs(dev); /* Reload CSR3 */
1921 InitRestartDepca(dev); /* Resume normal operation. */
1922 netif_start_queue(dev); /* Unlock the TX ring */
1925 case DEPCA_SET_PROM: /* Set Promiscuous Mode */
1926 if (!capable(CAP_NET_ADMIN))
1928 netif_stop_queue(dev);
1929 while (lp->tx_old != lp->tx_new)
1930 cpu_relax(); /* Wait for the ring to empty */
1932 STOP_DEPCA; /* Temporarily stop the depca. */
1933 depca_init_ring(dev); /* Initialize the descriptor rings */
1934 lp->init_block.mode |= PROM; /* Set promiscuous mode */
1936 LoadCSRs(dev); /* Reload CSR3 */
1937 InitRestartDepca(dev); /* Resume normal operation. */
1938 netif_start_queue(dev); /* Unlock the TX ring */
1941 case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */
1942 if (!capable(CAP_NET_ADMIN))
1944 netif_stop_queue(dev);
1945 while (lp->tx_old != lp->tx_new)
1946 cpu_relax(); /* Wait for the ring to empty */
1948 STOP_DEPCA; /* Temporarily stop the depca. */
1949 depca_init_ring(dev); /* Initialize the descriptor rings */
1950 lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */
1952 LoadCSRs(dev); /* Reload CSR3 */
1953 InitRestartDepca(dev); /* Resume normal operation. */
1954 netif_start_queue(dev); /* Unlock the TX ring */
1957 case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */
1958 if(!capable(CAP_NET_ADMIN))
1960 printk("%s: Boo!\n", dev->name);
1963 case DEPCA_GET_MCA: /* Get the multicast address table */
1964 ioc->len = (HASH_TABLE_LEN >> 3);
1965 if (copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len))
1969 case DEPCA_SET_MCA: /* Set a multicast address */
1970 if (!capable(CAP_NET_ADMIN))
1972 if (ioc->len >= HASH_TABLE_LEN)
1974 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len))
1976 set_multicast_list(dev);
1979 case DEPCA_CLR_MCA: /* Clear all multicast addresses */
1980 if (!capable(CAP_NET_ADMIN))
1982 set_multicast_list(dev);
1985 case DEPCA_MCA_EN: /* Enable pass all multicast addressing */
1986 if (!capable(CAP_NET_ADMIN))
1988 set_multicast_list(dev);
1991 case DEPCA_GET_STATS: /* Get the driver statistics */
1993 ioc->len = sizeof(lp->pktStats);
1994 if (copy_to_user(ioc->data, &lp->pktStats, ioc->len))
1999 case DEPCA_CLR_STATS: /* Zero out the driver statistics */
2000 if (!capable(CAP_NET_ADMIN))
2003 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
2007 case DEPCA_GET_REG: /* Get the DEPCA Registers */
2009 tmp.sval[i++] = inw(DEPCA_NICSR);
2010 outw(CSR0, DEPCA_ADDR); /* status register */
2011 tmp.sval[i++] = inw(DEPCA_DATA);
2012 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
2013 ioc->len = i + sizeof(struct depca_init);
2014 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
2026 static struct net_device thisDepca;
2027 static int irq = 7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */
2028 static int io = 0x200; /* Or use the irq= io= options to insmod */
2029 MODULE_PARM(irq, "i");
2030 MODULE_PARM(io, "i");
2031 MODULE_PARM_DESC(irq, "DEPCA IRQ number");
2032 MODULE_PARM_DESC(io, "DEPCA I/O base address");
2034 /* See depca_probe() for autoprobe messages when a module */
2035 int init_module(void)
2037 thisDepca.irq = irq;
2038 thisDepca.base_addr = io;
2039 thisDepca.init = depca_probe;
2041 if (register_netdev(&thisDepca) != 0)
2047 void cleanup_module(void)
2049 struct depca_private *lp = thisDepca.priv;
2051 unregister_netdev(&thisDepca);
2053 iounmap(lp->sh_mem);
2055 if (lp->mca_slot != -1)
2056 mca_mark_as_unused(lp->mca_slot);
2059 thisDepca.priv = NULL;
2063 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
2066 MODULE_LICENSE("GPL");
2071 * 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"
2073 * 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"