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 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>
227 =========================================================================
230 static const char *version
= "depca.c:v0.51 1999/6/27 davies@maniac.ultranet.com\n";
232 #include <linux/config.h>
233 #include <linux/module.h>
235 #include <linux/kernel.h>
236 #include <linux/sched.h>
237 #include <linux/string.h>
238 #include <linux/ptrace.h>
239 #include <linux/errno.h>
240 #include <linux/ioport.h>
241 #include <linux/malloc.h>
242 #include <linux/interrupt.h>
243 #include <linux/delay.h>
244 #include <linux/init.h>
245 #include <asm/uaccess.h>
246 #include <asm/bitops.h>
250 #include <linux/netdevice.h>
251 #include <linux/etherdevice.h>
252 #include <linux/skbuff.h>
254 #include <linux/time.h>
255 #include <linux/types.h>
256 #include <linux/unistd.h>
257 #include <linux/ctype.h>
260 #include <linux/mca.h>
266 static int depca_debug
= DEPCA_DEBUG
;
268 static int depca_debug
= 1;
271 #define DEPCA_NDA 0xffe0 /* No Device Address */
273 #define TX_TIMEOUT (1*HZ)
276 ** Ethernet PROM defines
278 #define PROBE_LENGTH 32
279 #define ETH_PROM_SIG 0xAA5500FFUL
282 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
283 ** here is <= to the amount of shared memory set up by the board switches.
284 ** The number of descriptors MUST BE A POWER OF 2.
286 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
288 #define NUM_RX_DESC 8 /* Number of RX descriptors */
289 #define NUM_TX_DESC 8 /* Number of TX descriptors */
290 #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
291 #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
293 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
294 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
299 #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
300 #define MAX_EISA_SLOTS 16
301 #define EISA_SLOT_INC 0x1000
306 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
307 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
308 #define DEPCA_TOTAL_SIZE 0x10
309 static short mem_chkd
= 0;
312 ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
314 #define DE212_ID 0x6def
317 ** Name <-> Adapter mapping
319 #define DEPCA_SIGNATURE {"DEPCA",\
321 "DE200","DE201","DE202",\
326 DEPCA
, de100
, de101
, de200
, de201
, de202
, de210
, de212
, de422
, unknown
330 ** Miscellaneous info...
332 #define DEPCA_STRLEN 16
333 #define MAX_NUM_DEPCAS 2
336 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
337 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
338 ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
339 ** and hence the RX descriptor ring's first entry.
341 #define ALIGN4 ((u_long)4 - 1) /* 1 longword align */
342 #define ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
343 #define ALIGN ALIGN8 /* Keep the LANCE happy... */
346 ** The DEPCA Rx and Tx ring descriptors.
348 struct depca_rx_desc
{
350 s16 buf_length
; /* This length is negative 2's complement! */
351 s16 msg_length
; /* This length is "normal". */
354 struct depca_tx_desc
{
356 s16 length
; /* This length is negative 2's complement! */
357 s16 misc
; /* Errors and TDR info */
360 #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
361 to LANCE memory address space */
364 ** The Lance initialization block, described in databook, in common memory.
367 u16 mode
; /* Mode register */
368 u8 phys_addr
[ETH_ALEN
]; /* Physical ethernet address */
369 u8 mcast_table
[8]; /* Multicast Hash Table. */
370 u32 rx_ring
; /* Rx ring base pointer & ring length */
371 u32 tx_ring
; /* Tx ring base pointer & ring length */
374 #define DEPCA_PKT_STAT_SZ 16
375 #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
376 increase DEPCA_PKT_STAT_SZ */
377 struct depca_private
{
378 char devname
[DEPCA_STRLEN
]; /* Device Product String */
379 char adapter_name
[DEPCA_STRLEN
];/* /proc/ioports string */
380 char adapter
; /* Adapter type */
381 char mca_slot
; /* MCA slot, if MCA else -1 */ struct depca_rx_desc
*rx_ring
; /* Pointer to start of RX descriptor ring */
382 struct depca_tx_desc
*tx_ring
; /* Pointer to start of TX descriptor ring */
383 struct depca_init init_block
;/* Shadow Initialization block */
384 char *rx_memcpy
[NUM_RX_DESC
]; /* CPU virt address of sh'd memory buffs */
385 char *tx_memcpy
[NUM_TX_DESC
]; /* CPU virt address of sh'd memory buffs */
386 u_long bus_offset
; /* (E)ISA bus address offset vs LANCE */
387 u_long sh_mem
; /* Physical start addr of shared mem area */
388 u_long dma_buffs
; /* LANCE Rx and Tx buffers start address. */
389 int rx_new
, tx_new
; /* The next free ring entry */
390 int rx_old
, tx_old
; /* The ring entries to be free()ed. */
391 struct net_device_stats stats
;
393 struct { /* Private stats counters */
394 u32 bins
[DEPCA_PKT_STAT_SZ
];
398 u32 excessive_collisions
;
400 u32 excessive_underruns
;
402 int txRingMask
; /* TX ring mask */
403 int rxRingMask
; /* RX ring mask */
404 s32 rx_rlen
; /* log2(rxRingMask+1) for the descriptors */
405 s32 tx_rlen
; /* log2(txRingMask+1) for the descriptors */
409 ** The transmit ring full condition is described by the tx_old and tx_new
411 ** tx_old = tx_new Empty ring
412 ** tx_old = tx_new+1 Full ring
413 ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
415 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
416 lp->tx_old+lp->txRingMask-lp->tx_new:\
417 lp->tx_old -lp->tx_new-1)
422 static int depca_open(struct net_device
*dev
);
423 static int depca_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
424 static void depca_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
425 static int depca_close(struct net_device
*dev
);
426 static int depca_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
427 static void depca_tx_timeout (struct net_device
*dev
);
428 static struct net_device_stats
*depca_get_stats(struct net_device
*dev
);
429 static void set_multicast_list(struct net_device
*dev
);
434 static int depca_hw_init(struct net_device
*dev
, u_long ioaddr
, int mca_slot
);
435 static void depca_init_ring(struct net_device
*dev
);
436 static int depca_rx(struct net_device
*dev
);
437 static int depca_tx(struct net_device
*dev
);
439 static void LoadCSRs(struct net_device
*dev
);
440 static int InitRestartDepca(struct net_device
*dev
);
441 static void DepcaSignature(char *name
, u_long paddr
);
442 static int DevicePresent(u_long ioaddr
);
443 static int get_hw_addr(struct net_device
*dev
);
444 static int EISA_signature(char *name
, s32 eisa_id
);
445 static void SetMulticastFilter(struct net_device
*dev
);
446 static void isa_probe(struct net_device
*dev
, u_long iobase
);
447 static void eisa_probe(struct net_device
*dev
, u_long iobase
);
449 static void mca_probe(struct net_device
*dev
, u_long iobase
);
451 static struct net_device
*alloc_device(struct net_device
*dev
, u_long iobase
);
452 static int depca_dev_index(char *s
);
453 static struct net_device
*insert_device(struct net_device
*dev
, u_long iobase
, int (*init
)(struct net_device
*));
454 static int load_packet(struct net_device
*dev
, struct sk_buff
*skb
);
455 static void depca_dbg_open(struct net_device
*dev
);
458 int init_module(void);
459 void cleanup_module(void);
460 static int autoprobed
= 1, loading_module
= 1;
462 static u_char de1xx_irq
[] __initdata
= {2,3,4,5,7,9,0};
463 static u_char de2xx_irq
[] __initdata
= {5,9,10,11,15,0};
464 static u_char de422_irq
[] __initdata
= {5,9,10,11,0};
465 static u_char
*depca_irq
;
466 static int autoprobed
= 0, loading_module
= 0;
469 static char name
[DEPCA_STRLEN
];
470 static int num_depcas
= 0, num_eth
= 0;
471 static int mem
=0; /* For loadable module assignment
472 use insmod mem=0x????? .... */
473 static char *adapter_name
= '\0'; /* If no PROM when loadable module
474 use insmod adapter_name=DE??? ...
477 ** Miscellaneous defines...
480 outw(CSR0, DEPCA_ADDR);\
481 outw(STOP, DEPCA_DATA)
484 depca_probe(struct net_device
*dev
)
486 int tmp
= num_depcas
, status
= -ENODEV
;
487 u_long iobase
= dev
->base_addr
;
489 if ((iobase
== 0) && loading_module
){
490 printk("Autoprobing is not supported when loading a module based driver.\n");
494 mca_probe(dev
, iobase
);
496 isa_probe(dev
, iobase
);
497 eisa_probe(dev
, iobase
);
499 if ((tmp
== num_depcas
) && (iobase
!= 0) && loading_module
) {
500 printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev
->name
,
505 ** Walk the device list to check that at least one device
508 for (; (dev
->priv
== NULL
) && (dev
->next
!= NULL
); dev
= dev
->next
);
510 if (dev
->priv
) status
= 0;
511 if (iobase
== 0) autoprobed
= 1;
518 depca_hw_init(struct net_device
*dev
, u_long ioaddr
, int mca_slot
)
520 struct depca_private
*lp
;
521 int i
, j
, offset
, netRAM
, mem_len
, status
=0;
523 u_long mem_start
=0, mem_base
[] = DEPCA_RAM_BASE_ADDRESSES
;
527 nicsr
= inb(DEPCA_NICSR
);
528 nicsr
= ((nicsr
& ~SHE
& ~RBE
& ~IEN
) | IM
);
529 outb(nicsr
, DEPCA_NICSR
);
531 if (inw(DEPCA_DATA
) == STOP
) {
533 strcpy(name
, (adapter_name
? adapter_name
: ""));
534 mem_start
= (mem
? mem
& 0xf0000 : mem_base
[mem_chkd
++]);
535 DepcaSignature(name
, mem_start
);
536 } while (!mem
&& mem_base
[mem_chkd
] && (adapter
== unknown
));
538 if ((adapter
!= unknown
) && mem_start
) { /* found a DEPCA device */
539 dev
->base_addr
= ioaddr
;
541 if (mca_slot
!= -1) {
542 printk("%s: %s at 0x%04lx (MCA slot %d)", dev
->name
, name
,
544 } else if ((ioaddr
& 0x0fff) == DEPCA_EISA_IO_PORTS
) { /* EISA slot address */
545 printk("%s: %s at 0x%04lx (EISA slot %d)",
546 dev
->name
, name
, ioaddr
, (int)((ioaddr
>>12)&0x0f));
547 } else { /* ISA port address */
548 printk("%s: %s at 0x%04lx", dev
->name
, name
, ioaddr
);
551 printk(", h/w address ");
552 status
= get_hw_addr(dev
);
553 for (i
=0; i
<ETH_ALEN
- 1; i
++) { /* get the ethernet address */
554 printk("%2.2x:", dev
->dev_addr
[i
]);
556 printk("%2.2x", dev
->dev_addr
[i
]);
559 /* Set up the maximum amount of network RAM(kB) */
560 netRAM
= ((adapter
!= DEPCA
) ? 64 : 48);
561 if ((nicsr
& _128KB
) && (adapter
== de422
)) netRAM
= 128;
564 /* Shared Memory Base Address */
566 offset
= 0x8000; /* 32kbyte RAM offset*/
567 nicsr
&= ~BS
; /* DEPCA RAM in top 32k */
570 mem_start
+= offset
; /* (E)ISA start address */
571 if ((mem_len
= (NUM_RX_DESC
*(sizeof(struct depca_rx_desc
)+RX_BUFF_SZ
) +
572 NUM_TX_DESC
*(sizeof(struct depca_tx_desc
)+TX_BUFF_SZ
) +
573 sizeof(struct depca_init
))) <=
575 printk(",\n has %dkB RAM at 0x%.5lx", netRAM
, mem_start
);
577 /* Enable the shadow RAM. */
578 if (adapter
!= DEPCA
) {
580 outb(nicsr
, DEPCA_NICSR
);
583 /* Define the device private memory */
584 dev
->priv
= (void *) kmalloc(sizeof(struct depca_private
), GFP_KERNEL
);
585 if (dev
->priv
== NULL
)
587 lp
= (struct depca_private
*)dev
->priv
;
588 memset((char *)dev
->priv
, 0, sizeof(struct depca_private
));
589 lp
->adapter
= adapter
;
590 lp
->mca_slot
= mca_slot
;
591 lp
->lock
= SPIN_LOCK_UNLOCKED
;
592 sprintf(lp
->adapter_name
,"%s (%s)", name
, dev
->name
);
593 request_region(ioaddr
, DEPCA_TOTAL_SIZE
, lp
->adapter_name
);
595 /* Initialisation Block */
596 lp
->sh_mem
= mem_start
;
597 mem_start
+= sizeof(struct depca_init
);
599 /* Tx & Rx descriptors (aligned to a quadword boundary) */
600 mem_start
= (mem_start
+ ALIGN
) & ~ALIGN
;
601 lp
->rx_ring
= (struct depca_rx_desc
*)mem_start
;
603 mem_start
+= (sizeof(struct depca_rx_desc
) * NUM_RX_DESC
);
604 lp
->tx_ring
= (struct depca_tx_desc
*)mem_start
;
606 mem_start
+= (sizeof(struct depca_tx_desc
) * NUM_TX_DESC
);
607 lp
->bus_offset
= mem_start
& 0x00ff0000;
608 mem_start
&= LA_MASK
; /* LANCE re-mapped start address */
610 lp
->dma_buffs
= mem_start
;
612 /* Finish initialising the ring information. */
613 lp
->rxRingMask
= NUM_RX_DESC
- 1;
614 lp
->txRingMask
= NUM_TX_DESC
- 1;
616 /* Calculate Tx/Rx RLEN size for the descriptors. */
617 for (i
=0, j
= lp
->rxRingMask
; j
>0; i
++) {
620 lp
->rx_rlen
= (s32
)(i
<< 29);
621 for (i
=0, j
= lp
->txRingMask
; j
>0; i
++) {
624 lp
->tx_rlen
= (s32
)(i
<< 29);
626 /* Load the initialisation block */
627 depca_init_ring(dev
);
629 /* Initialise the control and status registers */
632 /* Enable DEPCA board interrupts for autoprobing */
633 nicsr
= ((nicsr
& ~IM
)|IEN
);
634 outb(nicsr
, DEPCA_NICSR
);
636 /* To auto-IRQ we enable the initialization-done and DMA err,
637 interrupts. For now we will always get a DMA error. */
640 unsigned char irqnum
;
643 /* Assign the correct irq list */
644 switch (lp
->adapter
) {
648 depca_irq
= de1xx_irq
;
655 depca_irq
= de2xx_irq
;
658 depca_irq
= de422_irq
;
662 /* Trigger an initialization just for the interrupt. */
663 outw(INEA
| INIT
, DEPCA_DATA
);
665 irqnum
= autoirq_report(1);
667 printk(" and failed to detect IRQ line.\n");
670 for (dev
->irq
=0,i
=0; (depca_irq
[i
]) && (!dev
->irq
); i
++) {
671 if (irqnum
== depca_irq
[i
]) {
673 printk(" and uses IRQ%d.\n", dev
->irq
);
678 printk(" but incorrect IRQ line detected.\n");
684 printk(" and assigned IRQ%d.\n", dev
->irq
);
686 if (status
) release_region(ioaddr
, DEPCA_TOTAL_SIZE
);
688 printk(",\n requests %dkB RAM: only %dkB is available!\n",
689 (mem_len
>>10), netRAM
);
693 printk(" which has an Ethernet PROM CRC error.\n");
700 if (depca_debug
> 1) {
704 /* The DEPCA-specific entries in the device structure. */
705 dev
->open
= &depca_open
;
706 dev
->hard_start_xmit
= &depca_start_xmit
;
707 dev
->stop
= &depca_close
;
708 dev
->get_stats
= &depca_get_stats
;
709 dev
->set_multicast_list
= &set_multicast_list
;
710 dev
->do_ioctl
= &depca_ioctl
;
711 dev
->tx_timeout
= depca_tx_timeout
;
712 dev
->watchdog_timeo
= TX_TIMEOUT
;
716 /* Fill in the generic field of the device structure. */
718 } else { /* Incorrectly initialised hardware */
720 kfree_s(dev
->priv
, sizeof(struct depca_private
));
733 depca_open(struct net_device
*dev
)
735 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
736 u_long ioaddr
= dev
->base_addr
;
741 nicsr
= inb(DEPCA_NICSR
);
743 /* Make sure the shadow RAM is enabled */
744 if (adapter
!= DEPCA
) {
746 outb(nicsr
, DEPCA_NICSR
);
749 /* Re-initialize the DEPCA... */
750 depca_init_ring(dev
);
755 if (request_irq(dev
->irq
, &depca_interrupt
, 0, lp
->adapter_name
, dev
)) {
756 printk("depca_open(): Requested IRQ%d is busy\n",dev
->irq
);
760 /* Enable DEPCA board interrupts and turn off LED */
761 nicsr
= ((nicsr
& ~IM
& ~LED
)|IEN
);
762 outb(nicsr
, DEPCA_NICSR
);
763 outw(CSR0
,DEPCA_ADDR
);
765 netif_start_queue(dev
);
767 status
= InitRestartDepca(dev
);
769 if (depca_debug
> 1){
770 printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA
));
771 printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR
));
780 /* Initialize the lance Rx and Tx descriptor rings. */
782 depca_init_ring(struct net_device
*dev
)
784 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
788 /* Lock out other processes whilst setting up the hardware */
789 netif_stop_queue(dev
);
791 lp
->rx_new
= lp
->tx_new
= 0;
792 lp
->rx_old
= lp
->tx_old
= 0;
794 /* Initialize the base addresses and length of each buffer in the ring */
795 for (i
= 0; i
<= lp
->rxRingMask
; i
++) {
796 writel((p
=lp
->dma_buffs
+i
*RX_BUFF_SZ
) | R_OWN
, &lp
->rx_ring
[i
].base
);
797 writew(-RX_BUFF_SZ
, &lp
->rx_ring
[i
].buf_length
);
798 lp
->rx_memcpy
[i
]=(char *)(p
+lp
->bus_offset
);
800 for (i
= 0; i
<= lp
->txRingMask
; i
++) {
801 writel((p
=lp
->dma_buffs
+(i
+lp
->txRingMask
+1)*TX_BUFF_SZ
) & 0x00ffffff,
802 &lp
->tx_ring
[i
].base
);
803 lp
->tx_memcpy
[i
]=(char *)(p
+lp
->bus_offset
);
806 /* Set up the initialization block */
807 lp
->init_block
.rx_ring
= ((u32
)((u_long
)lp
->rx_ring
)&LA_MASK
) | lp
->rx_rlen
;
808 lp
->init_block
.tx_ring
= ((u32
)((u_long
)lp
->tx_ring
)&LA_MASK
) | lp
->tx_rlen
;
810 SetMulticastFilter(dev
);
812 for (i
= 0; i
< ETH_ALEN
; i
++) {
813 lp
->init_block
.phys_addr
[i
] = dev
->dev_addr
[i
];
816 lp
->init_block
.mode
= 0x0000; /* Enable the Tx and Rx */
820 static void depca_tx_timeout (struct net_device
*dev
)
822 u_long ioaddr
= dev
->base_addr
;
824 printk ("%s: transmit timed out, status %04x, resetting.\n",
825 dev
->name
, inw (DEPCA_DATA
));
828 depca_init_ring (dev
);
830 dev
->trans_start
= jiffies
;
831 netif_wake_queue (dev
);
832 InitRestartDepca (dev
);
837 ** Writes a socket buffer to TX descriptor ring and starts transmission
839 static int depca_start_xmit (struct sk_buff
*skb
, struct net_device
*dev
)
841 struct depca_private
*lp
= (struct depca_private
*) dev
->priv
;
842 u_long ioaddr
= dev
->base_addr
;
845 /* Transmitter timeout, serious problems. */
849 netif_stop_queue (dev
);
851 if (TX_BUFFS_AVAIL
) { /* Fill in a Tx ring entry */
852 status
= load_packet (dev
, skb
);
855 /* Trigger an immediate send demand. */
856 outw (CSR0
, DEPCA_ADDR
);
857 outw (INEA
| TDMD
, DEPCA_DATA
);
859 dev
->trans_start
= jiffies
;
863 netif_start_queue (dev
);
872 ** The DEPCA interrupt handler.
874 static void depca_interrupt (int irq
, void *dev_id
, struct pt_regs
*regs
)
876 struct net_device
*dev
= dev_id
;
877 struct depca_private
*lp
;
882 printk ("depca_interrupt(): irq %d for unknown device.\n", irq
);
886 lp
= (struct depca_private
*) dev
->priv
;
887 ioaddr
= dev
->base_addr
;
889 spin_lock (&lp
->lock
);
891 /* mask the DEPCA board interrupts and turn on the LED */
892 nicsr
= inb (DEPCA_NICSR
);
894 outb (nicsr
, DEPCA_NICSR
);
896 outw (CSR0
, DEPCA_ADDR
);
897 csr0
= inw (DEPCA_DATA
);
899 /* Acknowledge all of the current interrupt sources ASAP. */
900 outw (csr0
& INTE
, DEPCA_DATA
);
902 if (csr0
& RINT
) /* Rx interrupt (packet arrived) */
905 if (csr0
& TINT
) /* Tx interrupt (packet sent) */
908 /* Any resources available? */
909 if ((TX_BUFFS_AVAIL
>= 0) && netif_queue_stopped(dev
)) {
910 netif_wake_queue (dev
);
912 /* Unmask the DEPCA board interrupts and turn off the LED */
913 nicsr
= (nicsr
& ~IM
& ~LED
);
914 outb (nicsr
, DEPCA_NICSR
);
917 spin_unlock (&lp
->lock
);
922 depca_rx(struct net_device
*dev
)
924 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
928 for (entry
=lp
->rx_new
;
929 !(readl(&lp
->rx_ring
[entry
].base
) & R_OWN
);
931 status
= readl(&lp
->rx_ring
[entry
].base
) >> 16 ;
932 if (status
& R_STP
) { /* Remember start of frame */
935 if (status
& R_ENP
) { /* Valid frame status */
936 if (status
& R_ERR
) { /* There was an error. */
937 lp
->stats
.rx_errors
++; /* Update the error stats. */
938 if (status
& R_FRAM
) lp
->stats
.rx_frame_errors
++;
939 if (status
& R_OFLO
) lp
->stats
.rx_over_errors
++;
940 if (status
& R_CRC
) lp
->stats
.rx_crc_errors
++;
941 if (status
& R_BUFF
) lp
->stats
.rx_fifo_errors
++;
943 short len
, pkt_len
= readw(&lp
->rx_ring
[entry
].msg_length
) - 4;
946 skb
= dev_alloc_skb(pkt_len
+2);
949 skb_reserve(skb
,2); /* 16 byte align the IP header */
950 buf
= skb_put(skb
,pkt_len
);
952 if (entry
< lp
->rx_old
) { /* Wrapped buffer */
953 len
= (lp
->rxRingMask
- lp
->rx_old
+ 1) * RX_BUFF_SZ
;
954 memcpy_fromio(buf
, lp
->rx_memcpy
[lp
->rx_old
], len
);
955 memcpy_fromio(buf
+ len
, lp
->rx_memcpy
[0], pkt_len
-len
);
956 } else { /* Linear buffer */
957 memcpy_fromio(buf
, lp
->rx_memcpy
[lp
->rx_old
], pkt_len
);
961 ** Notify the upper protocol layers that there is another
964 skb
->protocol
=eth_type_trans(skb
,dev
);
970 lp
->stats
.rx_packets
++;
971 for (i
=1; i
<DEPCA_PKT_STAT_SZ
-1; i
++) {
972 if (pkt_len
< (i
*DEPCA_PKT_BIN_SZ
)) {
973 lp
->pktStats
.bins
[i
]++;
974 i
= DEPCA_PKT_STAT_SZ
;
977 if (buf
[0] & 0x01) { /* Multicast/Broadcast */
978 if ((*(s16
*)&buf
[0] == -1) &&
979 (*(s16
*)&buf
[2] == -1) &&
980 (*(s16
*)&buf
[4] == -1)) {
981 lp
->pktStats
.broadcast
++;
983 lp
->pktStats
.multicast
++;
985 } else if ((*(s16
*)&buf
[0] == *(s16
*)&dev
->dev_addr
[0]) &&
986 (*(s16
*)&buf
[2] == *(s16
*)&dev
->dev_addr
[2]) &&
987 (*(s16
*)&buf
[4] == *(s16
*)&dev
->dev_addr
[4])) {
988 lp
->pktStats
.unicast
++;
991 lp
->pktStats
.bins
[0]++; /* Duplicates stats.rx_packets */
992 if (lp
->pktStats
.bins
[0] == 0) { /* Reset counters */
993 memset((char *)&lp
->pktStats
, 0, sizeof(lp
->pktStats
));
996 printk("%s: Memory squeeze, deferring packet.\n", dev
->name
);
997 lp
->stats
.rx_dropped
++; /* Really, deferred. */
1001 /* Change buffer ownership for this last frame, back to the adapter */
1002 for (; lp
->rx_old
!=entry
; lp
->rx_old
=(++lp
->rx_old
)&lp
->rxRingMask
) {
1003 writel(readl(&lp
->rx_ring
[lp
->rx_old
].base
) | R_OWN
,
1004 &lp
->rx_ring
[lp
->rx_old
].base
);
1006 writel(readl(&lp
->rx_ring
[entry
].base
) | R_OWN
, &lp
->rx_ring
[entry
].base
);
1010 ** Update entry information
1012 lp
->rx_new
= (++lp
->rx_new
) & lp
->rxRingMask
;
1019 ** Buffer sent - check for buffer errors.
1022 depca_tx(struct net_device
*dev
)
1024 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1027 u_long ioaddr
= dev
->base_addr
;
1029 for (entry
= lp
->tx_old
; entry
!= lp
->tx_new
; entry
= lp
->tx_old
) {
1030 status
= readl(&lp
->tx_ring
[entry
].base
) >> 16 ;
1032 if (status
< 0) { /* Packet not yet sent! */
1034 } else if (status
& T_ERR
) { /* An error occurred. */
1035 status
= readl(&lp
->tx_ring
[entry
].misc
);
1036 lp
->stats
.tx_errors
++;
1037 if (status
& TMD3_RTRY
) lp
->stats
.tx_aborted_errors
++;
1038 if (status
& TMD3_LCAR
) lp
->stats
.tx_carrier_errors
++;
1039 if (status
& TMD3_LCOL
) lp
->stats
.tx_window_errors
++;
1040 if (status
& TMD3_UFLO
) lp
->stats
.tx_fifo_errors
++;
1041 if (status
& (TMD3_BUFF
| TMD3_UFLO
)) {
1042 /* Trigger an immediate send demand. */
1043 outw(CSR0
, DEPCA_ADDR
);
1044 outw(INEA
| TDMD
, DEPCA_DATA
);
1046 } else if (status
& (T_MORE
| T_ONE
)) {
1047 lp
->stats
.collisions
++;
1049 lp
->stats
.tx_packets
++;
1052 /* Update all the pointers */
1053 lp
->tx_old
= (++lp
->tx_old
) & lp
->txRingMask
;
1060 depca_close(struct net_device
*dev
)
1062 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1064 u_long ioaddr
= dev
->base_addr
;
1066 netif_stop_queue(dev
);
1068 outw(CSR0
, DEPCA_ADDR
);
1070 if (depca_debug
> 1) {
1071 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1072 dev
->name
, inw(DEPCA_DATA
));
1076 ** We stop the DEPCA here -- it occasionally polls
1077 ** memory if we don't.
1079 outw(STOP
, DEPCA_DATA
);
1082 ** Give back the ROM in case the user wants to go to DOS
1084 if (lp
->adapter
!= DEPCA
) {
1085 nicsr
= inb(DEPCA_NICSR
);
1087 outb(nicsr
, DEPCA_NICSR
);
1091 ** Free the associated irq
1093 free_irq(dev
->irq
, dev
);
1100 static void LoadCSRs(struct net_device
*dev
)
1102 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1103 u_long ioaddr
= dev
->base_addr
;
1105 outw(CSR1
, DEPCA_ADDR
); /* initialisation block address LSW */
1106 outw((u16
)(lp
->sh_mem
& LA_MASK
), DEPCA_DATA
);
1107 outw(CSR2
, DEPCA_ADDR
); /* initialisation block address MSW */
1108 outw((u16
)((lp
->sh_mem
& LA_MASK
) >> 16), DEPCA_DATA
);
1109 outw(CSR3
, DEPCA_ADDR
); /* ALE control */
1110 outw(ACON
, DEPCA_DATA
);
1112 outw(CSR0
, DEPCA_ADDR
); /* Point back to CSR0 */
1117 static int InitRestartDepca(struct net_device
*dev
)
1119 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1120 u_long ioaddr
= dev
->base_addr
;
1123 /* Copy the shadow init_block to shared memory */
1124 memcpy_toio((char *)lp
->sh_mem
, &lp
->init_block
, sizeof(struct depca_init
));
1126 outw(CSR0
, DEPCA_ADDR
); /* point back to CSR0 */
1127 outw(INIT
, DEPCA_DATA
); /* initialize DEPCA */
1129 /* wait for lance to complete initialisation */
1130 for (i
=0;(i
<100) && !(inw(DEPCA_DATA
) & IDON
); i
++);
1133 /* clear IDON by writing a "1", enable interrupts and start lance */
1134 outw(IDON
| INEA
| STRT
, DEPCA_DATA
);
1135 if (depca_debug
> 2) {
1136 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1137 dev
->name
, i
, lp
->sh_mem
, inw(DEPCA_DATA
));
1140 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1141 dev
->name
, i
, lp
->sh_mem
, inw(DEPCA_DATA
));
1148 static struct net_device_stats
*
1149 depca_get_stats(struct net_device
*dev
)
1151 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1153 /* Null body since there is no framing error counter */
1159 ** Set or clear the multicast filter for this adaptor.
1162 set_multicast_list(struct net_device
*dev
)
1164 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1165 u_long ioaddr
= dev
->base_addr
;
1168 netif_stop_queue(dev
);
1169 while(lp
->tx_old
!= lp
->tx_new
); /* Wait for the ring to empty */
1171 STOP_DEPCA
; /* Temporarily stop the depca. */
1172 depca_init_ring(dev
); /* Initialize the descriptor rings */
1174 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous mode */
1175 lp
->init_block
.mode
|= PROM
;
1177 SetMulticastFilter(dev
);
1178 lp
->init_block
.mode
&= ~PROM
; /* Unset promiscuous mode */
1181 LoadCSRs(dev
); /* Reload CSR3 */
1182 InitRestartDepca(dev
); /* Resume normal operation. */
1183 netif_start_queue(dev
); /* Unlock the TX ring */
1188 ** Calculate the hash code and update the logical address filter
1189 ** from a list of ethernet multicast addresses.
1190 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1191 ** LANCE calculates its hash codes big endian.
1193 static void SetMulticastFilter(struct net_device
*dev
)
1195 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1196 struct dev_mc_list
*dmi
=dev
->mc_list
;
1198 int i
, j
, bit
, byte
;
1200 s32 crc
, poly
= CRC_POLYNOMIAL_BE
;
1202 if (dev
->flags
& IFF_ALLMULTI
) { /* Set all multicast bits */
1203 for (i
=0; i
<(HASH_TABLE_LEN
>>3); i
++) {
1204 lp
->init_block
.mcast_table
[i
] = (char)0xff;
1207 for (i
=0; i
<(HASH_TABLE_LEN
>>3); i
++){ /* Clear the multicast table */
1208 lp
->init_block
.mcast_table
[i
]=0;
1210 /* Add multicast addresses */
1211 for (i
=0;i
<dev
->mc_count
;i
++) { /* for each address in the list */
1212 addrs
=dmi
->dmi_addr
;
1214 if ((*addrs
& 0x01) == 1) { /* multicast address? */
1215 crc
= 0xffffffff; /* init CRC for each address */
1216 for (byte
=0;byte
<ETH_ALEN
;byte
++) {/* for each address byte */
1217 /* process each address bit */
1218 for (bit
= *addrs
++,j
=0;j
<8;j
++, bit
>>=1) {
1219 crc
= (crc
<< 1) ^ ((((crc
<0?1:0) ^ bit
) & 0x01) ? poly
: 0);
1222 hashcode
= (crc
& 1); /* hashcode is 6 LSb of CRC ... */
1223 for (j
=0;j
<5;j
++) { /* ... in reverse order. */
1224 hashcode
= (hashcode
<< 1) | ((crc
>>=1) & 1);
1228 byte
= hashcode
>> 3; /* bit[3-5] -> byte in filter */
1229 bit
= 1 << (hashcode
& 0x07); /* bit[0-2] -> bit in byte */
1230 lp
->init_block
.mcast_table
[byte
] |= bit
;
1240 ** Microchannel bus I/O device probe
1243 mca_probe(struct net_device
*dev
, u_long ioaddr
)
1245 unsigned char pos
[2];
1246 unsigned char where
;
1247 unsigned long iobase
;
1252 ** See if we've been here before.
1254 if ((!ioaddr
&& autoprobed
) || (ioaddr
&& !loading_module
)) return;
1258 ** Search for the adapter. If an address has been given, search
1259 ** specifically for the card at that address. Otherwise find the
1260 ** first card in the system.
1262 while ((dev
!=NULL
) &&
1263 ((slot
=mca_find_adapter(DE212_ID
, slot
)) != MCA_NOTFOUND
)) {
1264 pos
[0] = mca_read_stored_pos(slot
, 2);
1265 pos
[1] = mca_read_stored_pos(slot
, 3);
1268 ** IO of card is handled by bits 1 and 2 of pos0.
1276 where
= (pos
[0] & 6) >> 1;
1277 iobase
= 0x2c00 + (0x10 * where
);
1279 if ((ioaddr
) && (ioaddr
!= iobase
)) {
1281 ** Card was found, but not at the right IO location. Continue
1282 ** scanning from the next MCA slot up for another card.
1289 ** Found the adapter we were looking for. Now start setting it up.
1291 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1292 ** of pos1. Bits are as follows (from the ADF file):
1296 ** --------------------
1302 where
= pos
[1] & 0x0f;
1317 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev
->name
, where
);
1322 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1323 ** They are mapped as follows:
1326 ** 5 4 3 Memory Addresses
1327 ** 0 0 0 C0000-CFFFF (64K)
1328 ** 1 0 0 C8000-CFFFF (32K)
1329 ** 0 0 1 D0000-DFFFF (64K)
1330 ** 1 0 1 D8000-DFFFF (32K)
1331 ** 0 1 0 E0000-EFFFF (64K)
1332 ** 1 1 0 E8000-EFFFF (32K)
1334 where
= (pos
[0] & 0x18) >> 3;
1335 mem
= 0xc0000 + (where
* 0x10000);
1336 if (pos
[0] & 0x20) {
1341 ** Get everything allocated and initialized... (almost just
1342 ** like the ISA and EISA probes)
1344 if (DevicePresent(iobase
) != 0) {
1346 ** If the MCA configuration says the card should be here,
1347 ** it really should be here.
1349 printk(KERN_ERR
"%s: MCA reports card at 0x%lx but it is not
1350 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
1378 ** Set up to check the next slot and loop.
1389 ** ISA bus I/O device probe
1392 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
) return ; /* Been here before ! */
1398 if (ioaddr
> 0x400) return; /* EISA Address */
1399 if (i
>= MAX_NUM_DEPCAS
) return; /* Too many ISA adapters */
1401 if (ioaddr
== 0) { /* Autoprobing */
1402 maxSlots
= MAX_NUM_DEPCAS
;
1403 } else { /* Probe a specific location */
1408 for (; (i
<maxSlots
) && (dev
!=NULL
) && ports
[i
]; i
++) {
1409 if (check_region(ports
[i
], DEPCA_TOTAL_SIZE
) == 0) {
1410 if (DevicePresent(ports
[i
]) == 0) {
1411 if ((dev
= alloc_device(dev
, ports
[i
])) != NULL
) {
1412 if (depca_hw_init(dev
, ports
[i
], -1) == 0) {
1418 } else if (autoprobed
) {
1419 printk("%s: region already allocated at 0x%04x.\n", dev
->name
, ports
[i
]);
1427 ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
1428 ** the motherboard. Upto 15 EISA devices are supported.
1431 eisa_probe(struct net_device
*dev
, u_long ioaddr
)
1435 char name
[DEPCA_STRLEN
];
1437 if (!ioaddr
&& autoprobed
) return ; /* Been here before ! */
1438 if ((ioaddr
< 0x400) && (ioaddr
> 0)) return; /* ISA Address */
1440 if (ioaddr
== 0) { /* Autoprobing */
1441 iobase
= EISA_SLOT_INC
; /* Get the first slot address */
1443 maxSlots
= MAX_EISA_SLOTS
;
1444 } else { /* Probe a specific location */
1449 if ((iobase
& 0x0fff) == 0) iobase
+= DEPCA_EISA_IO_PORTS
;
1451 for (; (i
<maxSlots
) && (dev
!=NULL
); i
++, iobase
+=EISA_SLOT_INC
) {
1452 if (check_region(iobase
, DEPCA_TOTAL_SIZE
) == 0) {
1453 if (EISA_signature(name
, EISA_ID
)) {
1454 if (DevicePresent(iobase
) == 0) {
1455 if ((dev
= alloc_device(dev
, iobase
)) != NULL
) {
1456 if (depca_hw_init(dev
, iobase
, -1) == 0) {
1463 } else if (autoprobed
) {
1464 printk("%s: region already allocated at 0x%04lx.\n", dev
->name
, iobase
);
1472 ** Search the entire 'eth' device list for a fixed probe. If a match isn't
1473 ** found then check for an autoprobe or unused device location. If they
1474 ** are not available then insert a new device structure at the end of
1475 ** the current list.
1477 static struct net_device
* __init
1478 alloc_device(struct net_device
*dev
, u_long iobase
)
1480 struct net_device
*adev
= NULL
;
1481 int fixed
= 0, new_dev
= 0;
1483 num_eth
= depca_dev_index(dev
->name
);
1484 if (loading_module
) return dev
;
1487 if (((dev
->base_addr
== DEPCA_NDA
) || (dev
->base_addr
==0)) && !adev
) {
1489 } else if ((dev
->priv
== NULL
) && (dev
->base_addr
==iobase
)) {
1492 if (dev
->next
== NULL
) {
1494 } else if (strncmp(dev
->next
->name
, "eth", 3) != 0) {
1498 if ((dev
->next
== NULL
) || new_dev
|| fixed
) break;
1502 if (adev
&& !fixed
) {
1504 num_eth
= depca_dev_index(dev
->name
);
1508 if (((dev
->next
== NULL
) &&
1509 ((dev
->base_addr
!= DEPCA_NDA
) && (dev
->base_addr
!= 0)) && !fixed
) ||
1511 num_eth
++; /* New device */
1512 dev
= insert_device(dev
, iobase
, depca_probe
);
1519 ** If at end of eth device list and can't use current entry, malloc
1520 ** one up. If memory could not be allocated, print an error message.
1522 static struct net_device
* __init
1523 insert_device(struct net_device
*dev
, u_long iobase
, int (*init
)(struct net_device
*))
1525 struct net_device
*new;
1527 new = (struct net_device
*)kmalloc(sizeof(struct net_device
), GFP_KERNEL
);
1529 printk("eth%d: Device not initialised, insufficient memory\n",num_eth
);
1532 new->next
= dev
->next
;
1534 dev
= dev
->next
; /* point to the new device */
1535 if (num_eth
> 9999) {
1536 sprintf(dev
->name
,"eth????");/* New device name */
1538 sprintf(dev
->name
,"eth%d", num_eth
);/* New device name */
1540 dev
->base_addr
= iobase
; /* assign the io address */
1541 dev
->init
= init
; /* initialisation routine */
1548 depca_dev_index(char *s
)
1555 i
= (i
* 10) + (*s
- '0');
1556 } else if (j
) break;
1563 ** Look for a particular board name in the on-board Remote Diagnostics
1564 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1568 DepcaSignature(char *name
, u_long paddr
)
1571 const char *signatures
[] = DEPCA_SIGNATURE
;
1574 /* Copy the first 16 bytes of ROM */
1575 for (i
=0;i
<16;i
++) {
1576 tmpstr
[i
] = readb(paddr
+0xc000+i
);
1579 /* Check if PROM contains a valid string */
1580 for (i
=0;*signatures
[i
]!='\0';i
++) {
1581 for (j
=0,k
=0;j
<16 && k
<strlen(signatures
[i
]);j
++) {
1582 if (signatures
[i
][k
] == tmpstr
[j
]) { /* track signature */
1584 } else { /* lost signature; begin search again */
1588 if (k
== strlen(signatures
[i
])) break;
1591 /* Check if name string is valid, provided there's no PROM */
1592 if (*name
&& (i
== unknown
)) {
1593 for (i
=0;*signatures
[i
]!='\0';i
++) {
1594 if (strcmp(name
,signatures
[i
]) == 0) break;
1598 /* Update search results */
1599 strcpy(name
,signatures
[i
]);
1606 ** Look for a special sequence in the Ethernet station address PROM that
1607 ** is common across all DEPCA products. Note that the original DEPCA needs
1608 ** its ROM address counter to be initialized and enabled. Only enable
1609 ** if the first address octet is a 0x08 - this minimises the chances of
1610 ** messing around with some other hardware, but it assumes that this DEPCA
1611 ** card initialized itself correctly.
1613 ** Search the Ethernet address ROM for the signature. Since the ROM address
1614 ** counter can start at an arbitrary point, the search must include the entire
1615 ** probe sequence length plus the (length_of_the_signature - 1).
1616 ** Stop the search IMMEDIATELY after the signature is found so that the
1617 ** PROM address counter is correctly positioned at the start of the
1618 ** ethernet address for later read out.
1621 DevicePresent(u_long ioaddr
)
1628 char Sig
[sizeof(u32
) << 1];
1633 int i
, j
, status
= 0;
1635 data
= inb(DEPCA_PROM
); /* clear counter on DEPCA */
1636 data
= inb(DEPCA_PROM
); /* read data */
1638 if (data
== 0x08) { /* Enable counter on DEPCA */
1639 nicsr
= inb(DEPCA_NICSR
);
1641 outb(nicsr
, DEPCA_NICSR
);
1644 dev
.llsig
.a
= ETH_PROM_SIG
;
1645 dev
.llsig
.b
= ETH_PROM_SIG
;
1646 sigLength
= sizeof(u32
) << 1;
1648 for (i
=0,j
=0;j
<sigLength
&& i
<PROBE_LENGTH
+sigLength
-1;i
++) {
1649 data
= inb(DEPCA_PROM
);
1650 if (dev
.Sig
[j
] == data
) { /* track signature */
1652 } else { /* lost signature; begin search again */
1653 if (data
== dev
.Sig
[0]) { /* rare case.... */
1662 status
= -ENODEV
; /* search failed */
1669 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1670 ** reason: access the upper half of the PROM with x=0; access the lower half
1674 get_hw_addr(struct net_device
*dev
)
1676 u_long ioaddr
= dev
->base_addr
;
1677 int i
, k
, tmp
, status
= 0;
1678 u_short j
, x
, chksum
;
1680 x
= (((adapter
== de100
) || (adapter
== de101
)) ? 1 : 0);
1682 for (i
=0,k
=0,j
=0;j
<3;j
++) {
1684 if (k
> 0xffff) k
-=0xffff;
1686 k
+= (u_char
) (tmp
= inb(DEPCA_PROM
+ x
));
1687 dev
->dev_addr
[i
++] = (u_char
) tmp
;
1688 k
+= (u_short
) ((tmp
= inb(DEPCA_PROM
+ x
)) << 8);
1689 dev
->dev_addr
[i
++] = (u_char
) tmp
;
1691 if (k
> 0xffff) k
-=0xffff;
1693 if (k
== 0xffff) k
=0;
1695 chksum
= (u_char
) inb(DEPCA_PROM
+ x
);
1696 chksum
|= (u_short
) (inb(DEPCA_PROM
+ x
) << 8);
1697 if (k
!= chksum
) status
= -1;
1703 ** Load a packet into the shared memory
1705 static int load_packet(struct net_device
*dev
, struct sk_buff
*skb
)
1707 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1708 int i
, entry
, end
, len
, status
= 0;
1710 entry
= lp
->tx_new
; /* Ring around buffer number. */
1711 end
= (entry
+ (skb
->len
- 1) / TX_BUFF_SZ
) & lp
->txRingMask
;
1712 if (!(readl(&lp
->tx_ring
[end
].base
) & T_OWN
)) {/* Enough room? */
1714 ** Caution: the write order is important here... don't set up the
1715 ** ownership rights until all the other information is in place.
1717 if (end
< entry
) { /* wrapped buffer */
1718 len
= (lp
->txRingMask
- entry
+ 1) * TX_BUFF_SZ
;
1719 memcpy_toio(lp
->tx_memcpy
[entry
], skb
->data
, len
);
1720 memcpy_toio(lp
->tx_memcpy
[0], skb
->data
+ len
, skb
->len
- len
);
1721 } else { /* linear buffer */
1722 memcpy_toio(lp
->tx_memcpy
[entry
], skb
->data
, skb
->len
);
1725 /* set up the buffer descriptors */
1726 len
= (skb
->len
< ETH_ZLEN
) ? ETH_ZLEN
: skb
->len
;
1727 for (i
= entry
; i
!= end
; i
= (++i
) & lp
->txRingMask
) {
1728 /* clean out flags */
1729 writel(readl(&lp
->tx_ring
[i
].base
) & ~T_FLAGS
, &lp
->tx_ring
[i
].base
);
1730 writew(0x0000, &lp
->tx_ring
[i
].misc
); /* clears other error flags */
1731 writew(-TX_BUFF_SZ
, &lp
->tx_ring
[i
].length
);/* packet length in buffer */
1734 /* clean out flags */
1735 writel(readl(&lp
->tx_ring
[end
].base
) & ~T_FLAGS
, &lp
->tx_ring
[end
].base
);
1736 writew(0x0000, &lp
->tx_ring
[end
].misc
); /* clears other error flags */
1737 writew(-len
, &lp
->tx_ring
[end
].length
); /* packet length in last buff */
1739 /* start of packet */
1740 writel(readl(&lp
->tx_ring
[entry
].base
) | T_STP
, &lp
->tx_ring
[entry
].base
);
1742 writel(readl(&lp
->tx_ring
[end
].base
) | T_ENP
, &lp
->tx_ring
[end
].base
);
1744 for (i
=end
; i
!=entry
; --i
) {
1745 /* ownership of packet */
1746 writel(readl(&lp
->tx_ring
[i
].base
) | T_OWN
, &lp
->tx_ring
[i
].base
);
1747 if (i
== 0) i
=lp
->txRingMask
+1;
1749 writel(readl(&lp
->tx_ring
[entry
].base
) | T_OWN
, &lp
->tx_ring
[entry
].base
);
1751 lp
->tx_new
= (++end
) & lp
->txRingMask
; /* update current pointers */
1760 ** Look for a particular board name in the EISA configuration space
1763 EISA_signature(char *name
, s32 eisa_id
)
1766 const char *signatures
[] = DEPCA_SIGNATURE
;
1767 char ManCode
[DEPCA_STRLEN
];
1775 Eisa
.ID
= inl(eisa_id
);
1777 ManCode
[0]=(((Eisa
.Id
[0]>>2)&0x1f)+0x40);
1778 ManCode
[1]=(((Eisa
.Id
[1]&0xe0)>>5)+((Eisa
.Id
[0]&0x03)<<3)+0x40);
1779 ManCode
[2]=(((Eisa
.Id
[2]>>4)&0x0f)+0x30);
1780 ManCode
[3]=(( Eisa
.Id
[2]&0x0f)+0x30);
1781 ManCode
[4]=(((Eisa
.Id
[3]>>4)&0x0f)+0x30);
1784 for (i
=0;(*signatures
[i
] != '\0') && (*name
== '\0');i
++) {
1785 if (strstr(ManCode
, signatures
[i
]) != NULL
) {
1786 strcpy(name
,ManCode
);
1794 static void depca_dbg_open(struct net_device
*dev
)
1796 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1797 u_long ioaddr
= dev
->base_addr
;
1798 struct depca_init
*p
= (struct depca_init
*)lp
->sh_mem
;
1801 if (depca_debug
> 1){
1802 /* Copy the shadow init_block to shared memory */
1803 memcpy_toio((char *)lp
->sh_mem
,&lp
->init_block
,sizeof(struct depca_init
));
1805 printk("%s: depca open with irq %d\n",dev
->name
,dev
->irq
);
1806 printk("Descriptor head addresses:\n");
1807 printk("\t0x%lx 0x%lx\n",(u_long
)lp
->rx_ring
, (u_long
)lp
->tx_ring
);
1808 printk("Descriptor addresses:\nRX: ");
1809 for (i
=0;i
<lp
->rxRingMask
;i
++){
1811 printk("0x%8.8lx ", (long) &lp
->rx_ring
[i
].base
);
1814 printk("...0x%8.8lx\n", (long) &lp
->rx_ring
[i
].base
);
1816 for (i
=0;i
<lp
->txRingMask
;i
++){
1818 printk("0x%8.8lx ", (long) &lp
->tx_ring
[i
].base
);
1821 printk("...0x%8.8lx\n", (long) &lp
->tx_ring
[i
].base
);
1822 printk("\nDescriptor buffers:\nRX: ");
1823 for (i
=0;i
<lp
->rxRingMask
;i
++){
1825 printk("0x%8.8x ", readl(&lp
->rx_ring
[i
].base
));
1828 printk("...0x%8.8x\n", readl(&lp
->rx_ring
[i
].base
));
1830 for (i
=0;i
<lp
->txRingMask
;i
++){
1832 printk("0x%8.8x ", readl(&lp
->tx_ring
[i
].base
));
1835 printk("...0x%8.8x\n", readl(&lp
->tx_ring
[i
].base
));
1836 printk("Initialisation block at 0x%8.8lx\n",lp
->sh_mem
);
1837 printk("\tmode: 0x%4.4x\n",readw(&p
->mode
));
1838 printk("\tphysical address: ");
1839 for (i
=0;i
<ETH_ALEN
-1;i
++){
1840 printk("%2.2x:",(u_char
)readb(&p
->phys_addr
[i
]));
1842 printk("%2.2x\n",(u_char
)readb(&p
->phys_addr
[i
]));
1843 printk("\tmulticast hash table: ");
1844 for (i
=0;i
<(HASH_TABLE_LEN
>> 3)-1;i
++){
1845 printk("%2.2x:",(u_char
)readb(&p
->mcast_table
[i
]));
1847 printk("%2.2x\n",(u_char
)readb(&p
->mcast_table
[i
]));
1848 printk("\trx_ring at: 0x%8.8x\n",readl(&p
->rx_ring
));
1849 printk("\ttx_ring at: 0x%8.8x\n",readl(&p
->tx_ring
));
1850 printk("dma_buffs: 0x%8.8lx\n",lp
->dma_buffs
);
1851 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n",
1852 (int)lp
->rxRingMask
+ 1,
1854 printk("TX: %d Log2(txRingMask): 0x%8.8x\n",
1855 (int)lp
->txRingMask
+ 1,
1857 outw(CSR2
,DEPCA_ADDR
);
1858 printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA
));
1859 outw(CSR1
,DEPCA_ADDR
);
1860 printk("%4.4x\n",inw(DEPCA_DATA
));
1861 outw(CSR3
,DEPCA_ADDR
);
1862 printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA
));
1869 ** Perform IOCTL call functions here. Some are privileged operations and the
1870 ** effective uid is checked in those cases.
1871 ** All multicast IOCTLs will not work here and are for testing purposes only.
1873 static int depca_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1875 struct depca_private
*lp
= (struct depca_private
*)dev
->priv
;
1876 struct depca_ioctl
*ioc
= (struct depca_ioctl
*) &rq
->ifr_data
;
1878 u_long ioaddr
= dev
->base_addr
;
1880 u8 addr
[(HASH_TABLE_LEN
* ETH_ALEN
)];
1881 u16 sval
[(HASH_TABLE_LEN
* ETH_ALEN
) >> 1];
1882 u32 lval
[(HASH_TABLE_LEN
* ETH_ALEN
) >> 2];
1886 case DEPCA_GET_HWADDR
: /* Get the hardware address */
1887 for (i
=0; i
<ETH_ALEN
; i
++) {
1888 tmp
.addr
[i
] = dev
->dev_addr
[i
];
1890 ioc
->len
= ETH_ALEN
;
1891 if (verify_area(VERIFY_WRITE
, (void *)ioc
->data
, ioc
->len
)) return -EFAULT
;
1892 copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
);
1895 case DEPCA_SET_HWADDR
: /* Set the hardware address */
1896 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1897 if (verify_area(VERIFY_READ
, (void *)ioc
->data
, ETH_ALEN
)) return -EFAULT
;
1898 copy_from_user(tmp
.addr
,ioc
->data
,ETH_ALEN
);
1899 for (i
=0; i
<ETH_ALEN
; i
++) {
1900 dev
->dev_addr
[i
] = tmp
.addr
[i
];
1902 netif_stop_queue(dev
);
1903 while(lp
->tx_old
!= lp
->tx_new
); /* Wait for the ring to empty */
1905 STOP_DEPCA
; /* Temporarily stop the depca. */
1906 depca_init_ring(dev
); /* Initialize the descriptor rings */
1907 LoadCSRs(dev
); /* Reload CSR3 */
1908 InitRestartDepca(dev
); /* Resume normal operation. */
1909 netif_start_queue(dev
); /* Unlock the TX ring */
1912 case DEPCA_SET_PROM
: /* Set Promiscuous Mode */
1913 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1914 netif_stop_queue(dev
);
1915 while(lp
->tx_old
!= lp
->tx_new
); /* Wait for the ring to empty */
1917 STOP_DEPCA
; /* Temporarily stop the depca. */
1918 depca_init_ring(dev
); /* Initialize the descriptor rings */
1919 lp
->init_block
.mode
|= PROM
; /* Set promiscuous mode */
1921 LoadCSRs(dev
); /* Reload CSR3 */
1922 InitRestartDepca(dev
); /* Resume normal operation. */
1923 netif_start_queue(dev
); /* Unlock the TX ring */
1926 case DEPCA_CLR_PROM
: /* Clear Promiscuous Mode */
1927 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1928 netif_stop_queue(dev
);
1929 while(lp
->tx_old
!= lp
->tx_new
); /* Wait for the ring to empty */
1931 STOP_DEPCA
; /* Temporarily stop the depca. */
1932 depca_init_ring(dev
); /* Initialize the descriptor rings */
1933 lp
->init_block
.mode
&= ~PROM
; /* Clear promiscuous mode */
1935 LoadCSRs(dev
); /* Reload CSR3 */
1936 InitRestartDepca(dev
); /* Resume normal operation. */
1937 netif_start_queue(dev
); /* Unlock the TX ring */
1940 case DEPCA_SAY_BOO
: /* Say "Boo!" to the kernel log file */
1941 printk("%s: Boo!\n", dev
->name
);
1944 case DEPCA_GET_MCA
: /* Get the multicast address table */
1945 ioc
->len
= (HASH_TABLE_LEN
>> 3);
1946 if (verify_area(VERIFY_WRITE
, ioc
->data
, ioc
->len
)) return -EFAULT
;
1947 copy_to_user(ioc
->data
, lp
->init_block
.mcast_table
, ioc
->len
);
1950 case DEPCA_SET_MCA
: /* Set a multicast address */
1951 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1952 if (verify_area(VERIFY_READ
, ioc
->data
, ETH_ALEN
*ioc
->len
)) return -EFAULT
;
1953 copy_from_user(tmp
.addr
, ioc
->data
, ETH_ALEN
* ioc
->len
);
1954 set_multicast_list(dev
);
1957 case DEPCA_CLR_MCA
: /* Clear all multicast addresses */
1958 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1959 set_multicast_list(dev
);
1962 case DEPCA_MCA_EN
: /* Enable pass all multicast addressing */
1963 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1964 set_multicast_list(dev
);
1967 case DEPCA_GET_STATS
: /* Get the driver statistics */
1969 ioc
->len
= sizeof(lp
->pktStats
);
1970 if (verify_area(VERIFY_WRITE
, ioc
->data
, ioc
->len
)) {
1973 copy_to_user(ioc
->data
, &lp
->pktStats
, ioc
->len
);
1978 case DEPCA_CLR_STATS
: /* Zero out the driver statistics */
1979 if (!capable(CAP_NET_ADMIN
)) return -EPERM
;
1981 memset(&lp
->pktStats
, 0, sizeof(lp
->pktStats
));
1985 case DEPCA_GET_REG
: /* Get the DEPCA Registers */
1987 tmp
.sval
[i
++] = inw(DEPCA_NICSR
);
1988 outw(CSR0
, DEPCA_ADDR
); /* status register */
1989 tmp
.sval
[i
++] = inw(DEPCA_DATA
);
1990 memcpy(&tmp
.sval
[i
], &lp
->init_block
, sizeof(struct depca_init
));
1991 ioc
->len
= i
+sizeof(struct depca_init
);
1992 if (verify_area(VERIFY_WRITE
, ioc
->data
, ioc
->len
)) return -EFAULT
;
1993 copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
);
2004 static struct net_device thisDepca
= {
2005 "", /* device name is inserted by /linux/drivers/net/net_init.c */
2007 0x200, 7, /* I/O address, IRQ */
2008 0, 0, 0, NULL
, depca_probe
2011 static int irq
=7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */
2012 static int io
=0x200; /* Or use the irq= io= options to insmod */
2013 MODULE_PARM(irq
, "i");
2014 MODULE_PARM(io
, "i");
2016 /* See depca_probe() for autoprobe messages when a module */
2021 thisDepca
.base_addr
=io
;
2023 if (register_netdev(&thisDepca
) != 0)
2030 cleanup_module(void)
2032 struct depca_private
*lp
= thisDepca
.priv
;
2035 if(lp
->mca_slot
!= -1)
2036 mca_mark_as_unused(lp
->mca_slot
);
2039 thisDepca
.priv
= NULL
;
2043 unregister_netdev(&thisDepca
);
2044 release_region(thisDepca
.base_addr
, DEPCA_TOTAL_SIZE
);
2051 * 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"
2053 * 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"