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
233 0.55 01-Mar-03 Use EISA/sysfs framework <maz@wild-wind.fr.eu.org>
235 =========================================================================
238 #include <linux/module.h>
239 #include <linux/kernel.h>
240 #include <linux/string.h>
241 #include <linux/errno.h>
242 #include <linux/ioport.h>
243 #include <linux/slab.h>
244 #include <linux/interrupt.h>
245 #include <linux/delay.h>
246 #include <linux/init.h>
247 #include <linux/crc32.h>
248 #include <linux/netdevice.h>
249 #include <linux/etherdevice.h>
250 #include <linux/skbuff.h>
251 #include <linux/time.h>
252 #include <linux/types.h>
253 #include <linux/unistd.h>
254 #include <linux/ctype.h>
255 #include <linux/moduleparam.h>
256 #include <linux/platform_device.h>
257 #include <linux/bitops.h>
259 #include <asm/uaccess.h>
264 #include <linux/mca.h>
268 #include <linux/eisa.h>
273 static char version
[] __initdata
= "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
276 static int depca_debug
= DEPCA_DEBUG
;
278 static int depca_debug
= 1;
281 #define DEPCA_NDA 0xffe0 /* No Device Address */
283 #define TX_TIMEOUT (1*HZ)
286 ** Ethernet PROM defines
288 #define PROBE_LENGTH 32
289 #define ETH_PROM_SIG 0xAA5500FFUL
292 ** Set the number of Tx and Rx buffers. Ensure that the memory requested
293 ** here is <= to the amount of shared memory set up by the board switches.
294 ** The number of descriptors MUST BE A POWER OF 2.
296 ** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
298 #define NUM_RX_DESC 8 /* Number of RX descriptors */
299 #define NUM_TX_DESC 8 /* Number of TX descriptors */
300 #define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
301 #define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
306 #define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
311 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
312 #define DEPCA_TOTAL_SIZE 0x10
316 struct platform_device
*device
;
317 } depca_io_ports
[] = {
324 ** Name <-> Adapter mapping
326 #define DEPCA_SIGNATURE {"DEPCA",\
328 "DE200","DE201","DE202",\
333 static char* __initdata depca_signature
[] = DEPCA_SIGNATURE
;
336 DEPCA
, de100
, de101
, de200
, de201
, de202
, de210
, de212
, de422
, unknown
339 static char depca_string
[] = "depca";
341 static int depca_device_remove (struct device
*device
);
344 static struct eisa_device_id depca_eisa_ids
[] = {
345 { "DEC4220", de422
},
348 MODULE_DEVICE_TABLE(eisa
, depca_eisa_ids
);
350 static int depca_eisa_probe (struct device
*device
);
352 static struct eisa_driver depca_eisa_driver
= {
353 .id_table
= depca_eisa_ids
,
355 .name
= depca_string
,
356 .probe
= depca_eisa_probe
,
357 .remove
= __devexit_p (depca_device_remove
)
364 ** Adapter ID for the MCA EtherWORKS DE210/212 adapter
366 #define DE210_ID 0x628d
367 #define DE212_ID 0x6def
369 static short depca_mca_adapter_ids
[] = {
375 static char *depca_mca_adapter_name
[] = {
376 "DEC EtherWORKS MC Adapter (DE210)",
377 "DEC EtherWORKS MC Adapter (DE212)",
381 static enum depca_type depca_mca_adapter_type
[] = {
387 static int depca_mca_probe (struct device
*);
389 static struct mca_driver depca_mca_driver
= {
390 .id_table
= depca_mca_adapter_ids
,
392 .name
= depca_string
,
393 .bus
= &mca_bus_type
,
394 .probe
= depca_mca_probe
,
395 .remove
= __devexit_p(depca_device_remove
),
400 static int depca_isa_probe (struct platform_device
*);
402 static int __devexit
depca_isa_remove(struct platform_device
*pdev
)
404 return depca_device_remove(&pdev
->dev
);
407 static struct platform_driver depca_isa_driver
= {
408 .probe
= depca_isa_probe
,
409 .remove
= __devexit_p(depca_isa_remove
),
411 .name
= depca_string
,
416 ** Miscellaneous info...
418 #define DEPCA_STRLEN 16
421 ** Memory Alignment. Each descriptor is 4 longwords long. To force a
422 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
423 ** DESC_ALIGN. DEPCA_ALIGN aligns the start address of the private memory area
424 ** and hence the RX descriptor ring's first entry.
426 #define DEPCA_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
427 #define DEPCA_ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
428 #define DEPCA_ALIGN DEPCA_ALIGN8 /* Keep the LANCE happy... */
431 ** The DEPCA Rx and Tx ring descriptors.
433 struct depca_rx_desc
{
435 s16 buf_length
; /* This length is negative 2's complement! */
436 s16 msg_length
; /* This length is "normal". */
439 struct depca_tx_desc
{
441 s16 length
; /* This length is negative 2's complement! */
442 s16 misc
; /* Errors and TDR info */
445 #define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
446 to LANCE memory address space */
449 ** The Lance initialization block, described in databook, in common memory.
452 u16 mode
; /* Mode register */
453 u8 phys_addr
[ETH_ALEN
]; /* Physical ethernet address */
454 u8 mcast_table
[8]; /* Multicast Hash Table. */
455 u32 rx_ring
; /* Rx ring base pointer & ring length */
456 u32 tx_ring
; /* Tx ring base pointer & ring length */
459 #define DEPCA_PKT_STAT_SZ 16
460 #define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
461 increase DEPCA_PKT_STAT_SZ */
462 struct depca_private
{
463 char adapter_name
[DEPCA_STRLEN
]; /* /proc/ioports string */
464 enum depca_type adapter
; /* Adapter type */
469 } depca_bus
; /* type of bus */
470 struct depca_init init_block
; /* Shadow Initialization block */
471 /* CPU address space fields */
472 struct depca_rx_desc __iomem
*rx_ring
; /* Pointer to start of RX descriptor ring */
473 struct depca_tx_desc __iomem
*tx_ring
; /* Pointer to start of TX descriptor ring */
474 void __iomem
*rx_buff
[NUM_RX_DESC
]; /* CPU virt address of sh'd memory buffs */
475 void __iomem
*tx_buff
[NUM_TX_DESC
]; /* CPU virt address of sh'd memory buffs */
476 void __iomem
*sh_mem
; /* CPU mapped virt address of device RAM */
477 u_long mem_start
; /* Bus address of device RAM (before remap) */
478 u_long mem_len
; /* device memory size */
479 /* Device address space fields */
480 u_long device_ram_start
; /* Start of RAM in device addr space */
481 /* Offsets used in both address spaces */
482 u_long rx_ring_offset
; /* Offset from start of RAM to rx_ring */
483 u_long tx_ring_offset
; /* Offset from start of RAM to tx_ring */
484 u_long buffs_offset
; /* LANCE Rx and Tx buffers start address. */
485 /* Kernel-only (not device) fields */
486 int rx_new
, tx_new
; /* The next free ring entry */
487 int rx_old
, tx_old
; /* The ring entries to be free()ed. */
489 struct { /* Private stats counters */
490 u32 bins
[DEPCA_PKT_STAT_SZ
];
494 u32 excessive_collisions
;
496 u32 excessive_underruns
;
498 int txRingMask
; /* TX ring mask */
499 int rxRingMask
; /* RX ring mask */
500 s32 rx_rlen
; /* log2(rxRingMask+1) for the descriptors */
501 s32 tx_rlen
; /* log2(txRingMask+1) for the descriptors */
505 ** The transmit ring full condition is described by the tx_old and tx_new
507 ** tx_old = tx_new Empty ring
508 ** tx_old = tx_new+1 Full ring
509 ** tx_old+txRingMask = tx_new Full ring (wrapped condition)
511 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
512 lp->tx_old+lp->txRingMask-lp->tx_new:\
513 lp->tx_old -lp->tx_new-1)
518 static int depca_open(struct net_device
*dev
);
519 static int depca_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
520 static irqreturn_t
depca_interrupt(int irq
, void *dev_id
);
521 static int depca_close(struct net_device
*dev
);
522 static int depca_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
523 static void depca_tx_timeout(struct net_device
*dev
);
524 static void set_multicast_list(struct net_device
*dev
);
529 static void depca_init_ring(struct net_device
*dev
);
530 static int depca_rx(struct net_device
*dev
);
531 static int depca_tx(struct net_device
*dev
);
533 static void LoadCSRs(struct net_device
*dev
);
534 static int InitRestartDepca(struct net_device
*dev
);
535 static int DepcaSignature(char *name
, u_long paddr
);
536 static int DevicePresent(u_long ioaddr
);
537 static int get_hw_addr(struct net_device
*dev
);
538 static void SetMulticastFilter(struct net_device
*dev
);
539 static int load_packet(struct net_device
*dev
, struct sk_buff
*skb
);
540 static void depca_dbg_open(struct net_device
*dev
);
542 static u_char de1xx_irq
[] __initdata
= { 2, 3, 4, 5, 7, 9, 0 };
543 static u_char de2xx_irq
[] __initdata
= { 5, 9, 10, 11, 15, 0 };
544 static u_char de422_irq
[] __initdata
= { 5, 9, 10, 11, 0 };
545 static u_char
*depca_irq
;
549 static char *adapter_name
;
550 static int mem
; /* For loadable module assignment
551 use insmod mem=0x????? .... */
552 module_param (irq
, int, 0);
553 module_param (io
, int, 0);
554 module_param (adapter_name
, charp
, 0);
555 module_param (mem
, int, 0);
556 MODULE_PARM_DESC(irq
, "DEPCA IRQ number");
557 MODULE_PARM_DESC(io
, "DEPCA I/O base address");
558 MODULE_PARM_DESC(adapter_name
, "DEPCA adapter name");
559 MODULE_PARM_DESC(mem
, "DEPCA shared memory address");
560 MODULE_LICENSE("GPL");
563 ** Miscellaneous defines...
566 outw(CSR0, DEPCA_ADDR);\
567 outw(STOP, DEPCA_DATA)
569 static const struct net_device_ops depca_netdev_ops
= {
570 .ndo_open
= depca_open
,
571 .ndo_start_xmit
= depca_start_xmit
,
572 .ndo_stop
= depca_close
,
573 .ndo_set_multicast_list
= set_multicast_list
,
574 .ndo_do_ioctl
= depca_ioctl
,
575 .ndo_tx_timeout
= depca_tx_timeout
,
576 .ndo_change_mtu
= eth_change_mtu
,
577 .ndo_set_mac_address
= eth_mac_addr
,
578 .ndo_validate_addr
= eth_validate_addr
,
581 static int __init
depca_hw_init (struct net_device
*dev
, struct device
*device
)
583 struct depca_private
*lp
;
584 int i
, j
, offset
, netRAM
, mem_len
, status
= 0;
590 * We are now supposed to enter this function with the
591 * following fields filled with proper values :
598 * dev->irq can be set if known from device configuration (on
599 * MCA or EISA) or module option. Otherwise, it will be auto
603 ioaddr
= dev
->base_addr
;
607 nicsr
= inb(DEPCA_NICSR
);
608 nicsr
= ((nicsr
& ~SHE
& ~RBE
& ~IEN
) | IM
);
609 outb(nicsr
, DEPCA_NICSR
);
611 if (inw(DEPCA_DATA
) != STOP
) {
615 lp
= netdev_priv(dev
);
616 mem_start
= lp
->mem_start
;
618 if (!mem_start
|| lp
->adapter
< DEPCA
|| lp
->adapter
>=unknown
)
621 printk("%s: %s at 0x%04lx",
622 dev_name(device
), depca_signature
[lp
->adapter
], ioaddr
);
624 switch (lp
->depca_bus
) {
627 printk(" (MCA slot %d)", to_mca_device(device
)->slot
+ 1);
633 printk(" (EISA slot %d)", to_eisa_device(device
)->slot
);
641 printk("Unknown DEPCA bus %d\n", lp
->depca_bus
);
645 printk(", h/w address ");
646 status
= get_hw_addr(dev
);
647 printk("%pM", dev
->dev_addr
);
649 printk(" which has an Ethernet PROM CRC error.\n");
653 /* Set up the maximum amount of network RAM(kB) */
654 netRAM
= ((lp
->adapter
!= DEPCA
) ? 64 : 48);
655 if ((nicsr
& _128KB
) && (lp
->adapter
== de422
))
658 /* Shared Memory Base Address */
660 nicsr
&= ~BS
; /* DEPCA RAM in top 32k */
663 /* Only EISA/ISA needs start address to be re-computed */
664 if (lp
->depca_bus
!= DEPCA_BUS_MCA
)
668 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
)))
670 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len
>> 10), netRAM
);
674 printk(",\n has %dkB RAM at 0x%.5lx", netRAM
, mem_start
);
676 /* Enable the shadow RAM. */
677 if (lp
->adapter
!= DEPCA
) {
679 outb(nicsr
, DEPCA_NICSR
);
682 spin_lock_init(&lp
->lock
);
683 sprintf(lp
->adapter_name
, "%s (%s)",
684 depca_signature
[lp
->adapter
], dev_name(device
));
687 /* Initialisation Block */
688 if (!request_mem_region (mem_start
, mem_len
, lp
->adapter_name
)) {
689 printk(KERN_ERR
"depca: cannot request ISA memory, aborting\n");
694 lp
->sh_mem
= ioremap(mem_start
, mem_len
);
695 if (lp
->sh_mem
== NULL
) {
696 printk(KERN_ERR
"depca: cannot remap ISA memory, aborting\n");
700 lp
->mem_start
= mem_start
;
701 lp
->mem_len
= mem_len
;
702 lp
->device_ram_start
= mem_start
& LA_MASK
;
705 offset
+= sizeof(struct depca_init
);
707 /* Tx & Rx descriptors (aligned to a quadword boundary) */
708 offset
= (offset
+ DEPCA_ALIGN
) & ~DEPCA_ALIGN
;
709 lp
->rx_ring
= (struct depca_rx_desc __iomem
*) (lp
->sh_mem
+ offset
);
710 lp
->rx_ring_offset
= offset
;
712 offset
+= (sizeof(struct depca_rx_desc
) * NUM_RX_DESC
);
713 lp
->tx_ring
= (struct depca_tx_desc __iomem
*) (lp
->sh_mem
+ offset
);
714 lp
->tx_ring_offset
= offset
;
716 offset
+= (sizeof(struct depca_tx_desc
) * NUM_TX_DESC
);
718 lp
->buffs_offset
= offset
;
720 /* Finish initialising the ring information. */
721 lp
->rxRingMask
= NUM_RX_DESC
- 1;
722 lp
->txRingMask
= NUM_TX_DESC
- 1;
724 /* Calculate Tx/Rx RLEN size for the descriptors. */
725 for (i
= 0, j
= lp
->rxRingMask
; j
> 0; i
++) {
728 lp
->rx_rlen
= (s32
) (i
<< 29);
729 for (i
= 0, j
= lp
->txRingMask
; j
> 0; i
++) {
732 lp
->tx_rlen
= (s32
) (i
<< 29);
734 /* Load the initialisation block */
735 depca_init_ring(dev
);
737 /* Initialise the control and status registers */
740 /* Enable DEPCA board interrupts for autoprobing */
741 nicsr
= ((nicsr
& ~IM
) | IEN
);
742 outb(nicsr
, DEPCA_NICSR
);
744 /* To auto-IRQ we enable the initialization-done and DMA err,
745 interrupts. For now we will always get a DMA error. */
747 unsigned char irqnum
;
748 unsigned long irq_mask
, delay
;
750 irq_mask
= probe_irq_on();
752 /* Assign the correct irq list */
753 switch (lp
->adapter
) {
757 depca_irq
= de1xx_irq
;
764 depca_irq
= de2xx_irq
;
767 depca_irq
= de422_irq
;
771 break; /* Not reached */
774 /* Trigger an initialization just for the interrupt. */
775 outw(INEA
| INIT
, DEPCA_DATA
);
777 delay
= jiffies
+ HZ
/50;
778 while (time_before(jiffies
, delay
))
781 irqnum
= probe_irq_off(irq_mask
);
785 printk(" and failed to detect IRQ line.\n");
788 for (dev
->irq
= 0, i
= 0; (depca_irq
[i
]) && (!dev
->irq
); i
++)
789 if (irqnum
== depca_irq
[i
]) {
791 printk(" and uses IRQ%d.\n", dev
->irq
);
795 printk(" but incorrect IRQ line detected.\n");
800 printk(" and assigned IRQ%d.\n", dev
->irq
);
803 if (depca_debug
> 1) {
807 /* The DEPCA-specific entries in the device structure. */
808 dev
->netdev_ops
= &depca_netdev_ops
;
809 dev
->watchdog_timeo
= TX_TIMEOUT
;
813 dev_set_drvdata(device
, dev
);
814 SET_NETDEV_DEV (dev
, device
);
816 status
= register_netdev(dev
);
822 release_mem_region (mem_start
, mem_len
);
828 static int depca_open(struct net_device
*dev
)
830 struct depca_private
*lp
= netdev_priv(dev
);
831 u_long ioaddr
= dev
->base_addr
;
836 nicsr
= inb(DEPCA_NICSR
);
838 /* Make sure the shadow RAM is enabled */
839 if (lp
->adapter
!= DEPCA
) {
841 outb(nicsr
, DEPCA_NICSR
);
844 /* Re-initialize the DEPCA... */
845 depca_init_ring(dev
);
850 if (request_irq(dev
->irq
, &depca_interrupt
, 0, lp
->adapter_name
, dev
)) {
851 printk("depca_open(): Requested IRQ%d is busy\n", dev
->irq
);
855 /* Enable DEPCA board interrupts and turn off LED */
856 nicsr
= ((nicsr
& ~IM
& ~LED
) | IEN
);
857 outb(nicsr
, DEPCA_NICSR
);
858 outw(CSR0
, DEPCA_ADDR
);
860 netif_start_queue(dev
);
862 status
= InitRestartDepca(dev
);
864 if (depca_debug
> 1) {
865 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA
));
866 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR
));
872 /* Initialize the lance Rx and Tx descriptor rings. */
873 static void depca_init_ring(struct net_device
*dev
)
875 struct depca_private
*lp
= netdev_priv(dev
);
879 /* Lock out other processes whilst setting up the hardware */
880 netif_stop_queue(dev
);
882 lp
->rx_new
= lp
->tx_new
= 0;
883 lp
->rx_old
= lp
->tx_old
= 0;
885 /* Initialize the base address and length of each buffer in the ring */
886 for (i
= 0; i
<= lp
->rxRingMask
; i
++) {
887 offset
= lp
->buffs_offset
+ i
* RX_BUFF_SZ
;
888 writel((lp
->device_ram_start
+ offset
) | R_OWN
, &lp
->rx_ring
[i
].base
);
889 writew(-RX_BUFF_SZ
, &lp
->rx_ring
[i
].buf_length
);
890 lp
->rx_buff
[i
] = lp
->sh_mem
+ offset
;
893 for (i
= 0; i
<= lp
->txRingMask
; i
++) {
894 offset
= lp
->buffs_offset
+ (i
+ lp
->rxRingMask
+ 1) * TX_BUFF_SZ
;
895 writel((lp
->device_ram_start
+ offset
) & 0x00ffffff, &lp
->tx_ring
[i
].base
);
896 lp
->tx_buff
[i
] = lp
->sh_mem
+ offset
;
899 /* Set up the initialization block */
900 lp
->init_block
.rx_ring
= (lp
->device_ram_start
+ lp
->rx_ring_offset
) | lp
->rx_rlen
;
901 lp
->init_block
.tx_ring
= (lp
->device_ram_start
+ lp
->tx_ring_offset
) | lp
->tx_rlen
;
903 SetMulticastFilter(dev
);
905 for (i
= 0; i
< ETH_ALEN
; i
++) {
906 lp
->init_block
.phys_addr
[i
] = dev
->dev_addr
[i
];
909 lp
->init_block
.mode
= 0x0000; /* Enable the Tx and Rx */
913 static void depca_tx_timeout(struct net_device
*dev
)
915 u_long ioaddr
= dev
->base_addr
;
917 printk("%s: transmit timed out, status %04x, resetting.\n", dev
->name
, inw(DEPCA_DATA
));
920 depca_init_ring(dev
);
922 dev
->trans_start
= jiffies
;
923 netif_wake_queue(dev
);
924 InitRestartDepca(dev
);
929 ** Writes a socket buffer to TX descriptor ring and starts transmission
931 static int depca_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
933 struct depca_private
*lp
= netdev_priv(dev
);
934 u_long ioaddr
= dev
->base_addr
;
937 /* Transmitter timeout, serious problems. */
941 if (skb_padto(skb
, ETH_ZLEN
))
944 netif_stop_queue(dev
);
946 if (TX_BUFFS_AVAIL
) { /* Fill in a Tx ring entry */
947 status
= load_packet(dev
, skb
);
950 /* Trigger an immediate send demand. */
951 outw(CSR0
, DEPCA_ADDR
);
952 outw(INEA
| TDMD
, DEPCA_DATA
);
954 dev
->trans_start
= jiffies
;
958 netif_start_queue(dev
);
960 status
= NETDEV_TX_LOCKED
;
967 ** The DEPCA interrupt handler.
969 static irqreturn_t
depca_interrupt(int irq
, void *dev_id
)
971 struct net_device
*dev
= dev_id
;
972 struct depca_private
*lp
;
977 printk("depca_interrupt(): irq %d for unknown device.\n", irq
);
981 lp
= netdev_priv(dev
);
982 ioaddr
= dev
->base_addr
;
984 spin_lock(&lp
->lock
);
986 /* mask the DEPCA board interrupts and turn on the LED */
987 nicsr
= inb(DEPCA_NICSR
);
989 outb(nicsr
, DEPCA_NICSR
);
991 outw(CSR0
, DEPCA_ADDR
);
992 csr0
= inw(DEPCA_DATA
);
994 /* Acknowledge all of the current interrupt sources ASAP. */
995 outw(csr0
& INTE
, DEPCA_DATA
);
997 if (csr0
& RINT
) /* Rx interrupt (packet arrived) */
1000 if (csr0
& TINT
) /* Tx interrupt (packet sent) */
1003 /* Any resources available? */
1004 if ((TX_BUFFS_AVAIL
>= 0) && netif_queue_stopped(dev
)) {
1005 netif_wake_queue(dev
);
1008 /* Unmask the DEPCA board interrupts and turn off the LED */
1009 nicsr
= (nicsr
& ~IM
& ~LED
);
1010 outb(nicsr
, DEPCA_NICSR
);
1012 spin_unlock(&lp
->lock
);
1016 /* Called with lp->lock held */
1017 static int depca_rx(struct net_device
*dev
)
1019 struct depca_private
*lp
= netdev_priv(dev
);
1023 for (entry
= lp
->rx_new
; !(readl(&lp
->rx_ring
[entry
].base
) & R_OWN
); entry
= lp
->rx_new
) {
1024 status
= readl(&lp
->rx_ring
[entry
].base
) >> 16;
1025 if (status
& R_STP
) { /* Remember start of frame */
1028 if (status
& R_ENP
) { /* Valid frame status */
1029 if (status
& R_ERR
) { /* There was an error. */
1030 dev
->stats
.rx_errors
++; /* Update the error stats. */
1031 if (status
& R_FRAM
)
1032 dev
->stats
.rx_frame_errors
++;
1033 if (status
& R_OFLO
)
1034 dev
->stats
.rx_over_errors
++;
1036 dev
->stats
.rx_crc_errors
++;
1037 if (status
& R_BUFF
)
1038 dev
->stats
.rx_fifo_errors
++;
1040 short len
, pkt_len
= readw(&lp
->rx_ring
[entry
].msg_length
) - 4;
1041 struct sk_buff
*skb
;
1043 skb
= dev_alloc_skb(pkt_len
+ 2);
1046 skb_reserve(skb
, 2); /* 16 byte align the IP header */
1047 buf
= skb_put(skb
, pkt_len
);
1048 if (entry
< lp
->rx_old
) { /* Wrapped buffer */
1049 len
= (lp
->rxRingMask
- lp
->rx_old
+ 1) * RX_BUFF_SZ
;
1050 memcpy_fromio(buf
, lp
->rx_buff
[lp
->rx_old
], len
);
1051 memcpy_fromio(buf
+ len
, lp
->rx_buff
[0], pkt_len
- len
);
1052 } else { /* Linear buffer */
1053 memcpy_fromio(buf
, lp
->rx_buff
[lp
->rx_old
], pkt_len
);
1057 ** Notify the upper protocol layers that there is another
1060 skb
->protocol
= eth_type_trans(skb
, dev
);
1066 dev
->stats
.rx_packets
++;
1067 dev
->stats
.rx_bytes
+= pkt_len
;
1068 for (i
= 1; i
< DEPCA_PKT_STAT_SZ
- 1; i
++) {
1069 if (pkt_len
< (i
* DEPCA_PKT_BIN_SZ
)) {
1070 lp
->pktStats
.bins
[i
]++;
1071 i
= DEPCA_PKT_STAT_SZ
;
1074 if (buf
[0] & 0x01) { /* Multicast/Broadcast */
1075 if ((*(s16
*) & buf
[0] == -1) && (*(s16
*) & buf
[2] == -1) && (*(s16
*) & buf
[4] == -1)) {
1076 lp
->pktStats
.broadcast
++;
1078 lp
->pktStats
.multicast
++;
1080 } 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])) {
1081 lp
->pktStats
.unicast
++;
1084 lp
->pktStats
.bins
[0]++; /* Duplicates stats.rx_packets */
1085 if (lp
->pktStats
.bins
[0] == 0) { /* Reset counters */
1086 memset((char *) &lp
->pktStats
, 0, sizeof(lp
->pktStats
));
1089 printk("%s: Memory squeeze, deferring packet.\n", dev
->name
);
1090 dev
->stats
.rx_dropped
++; /* Really, deferred. */
1094 /* Change buffer ownership for this last frame, back to the adapter */
1095 for (; lp
->rx_old
!= entry
; lp
->rx_old
= (++lp
->rx_old
) & lp
->rxRingMask
) {
1096 writel(readl(&lp
->rx_ring
[lp
->rx_old
].base
) | R_OWN
, &lp
->rx_ring
[lp
->rx_old
].base
);
1098 writel(readl(&lp
->rx_ring
[entry
].base
) | R_OWN
, &lp
->rx_ring
[entry
].base
);
1102 ** Update entry information
1104 lp
->rx_new
= (++lp
->rx_new
) & lp
->rxRingMask
;
1111 ** Buffer sent - check for buffer errors.
1112 ** Called with lp->lock held
1114 static int depca_tx(struct net_device
*dev
)
1116 struct depca_private
*lp
= netdev_priv(dev
);
1119 u_long ioaddr
= dev
->base_addr
;
1121 for (entry
= lp
->tx_old
; entry
!= lp
->tx_new
; entry
= lp
->tx_old
) {
1122 status
= readl(&lp
->tx_ring
[entry
].base
) >> 16;
1124 if (status
< 0) { /* Packet not yet sent! */
1126 } else if (status
& T_ERR
) { /* An error occurred. */
1127 status
= readl(&lp
->tx_ring
[entry
].misc
);
1128 dev
->stats
.tx_errors
++;
1129 if (status
& TMD3_RTRY
)
1130 dev
->stats
.tx_aborted_errors
++;
1131 if (status
& TMD3_LCAR
)
1132 dev
->stats
.tx_carrier_errors
++;
1133 if (status
& TMD3_LCOL
)
1134 dev
->stats
.tx_window_errors
++;
1135 if (status
& TMD3_UFLO
)
1136 dev
->stats
.tx_fifo_errors
++;
1137 if (status
& (TMD3_BUFF
| TMD3_UFLO
)) {
1138 /* Trigger an immediate send demand. */
1139 outw(CSR0
, DEPCA_ADDR
);
1140 outw(INEA
| TDMD
, DEPCA_DATA
);
1142 } else if (status
& (T_MORE
| T_ONE
)) {
1143 dev
->stats
.collisions
++;
1145 dev
->stats
.tx_packets
++;
1148 /* Update all the pointers */
1149 lp
->tx_old
= (++lp
->tx_old
) & lp
->txRingMask
;
1155 static int depca_close(struct net_device
*dev
)
1157 struct depca_private
*lp
= netdev_priv(dev
);
1159 u_long ioaddr
= dev
->base_addr
;
1161 netif_stop_queue(dev
);
1163 outw(CSR0
, DEPCA_ADDR
);
1165 if (depca_debug
> 1) {
1166 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev
->name
, inw(DEPCA_DATA
));
1170 ** We stop the DEPCA here -- it occasionally polls
1171 ** memory if we don't.
1173 outw(STOP
, DEPCA_DATA
);
1176 ** Give back the ROM in case the user wants to go to DOS
1178 if (lp
->adapter
!= DEPCA
) {
1179 nicsr
= inb(DEPCA_NICSR
);
1181 outb(nicsr
, DEPCA_NICSR
);
1185 ** Free the associated irq
1187 free_irq(dev
->irq
, dev
);
1191 static void LoadCSRs(struct net_device
*dev
)
1193 struct depca_private
*lp
= netdev_priv(dev
);
1194 u_long ioaddr
= dev
->base_addr
;
1196 outw(CSR1
, DEPCA_ADDR
); /* initialisation block address LSW */
1197 outw((u16
) lp
->device_ram_start
, DEPCA_DATA
);
1198 outw(CSR2
, DEPCA_ADDR
); /* initialisation block address MSW */
1199 outw((u16
) (lp
->device_ram_start
>> 16), DEPCA_DATA
);
1200 outw(CSR3
, DEPCA_ADDR
); /* ALE control */
1201 outw(ACON
, DEPCA_DATA
);
1203 outw(CSR0
, DEPCA_ADDR
); /* Point back to CSR0 */
1208 static int InitRestartDepca(struct net_device
*dev
)
1210 struct depca_private
*lp
= netdev_priv(dev
);
1211 u_long ioaddr
= dev
->base_addr
;
1214 /* Copy the shadow init_block to shared memory */
1215 memcpy_toio(lp
->sh_mem
, &lp
->init_block
, sizeof(struct depca_init
));
1217 outw(CSR0
, DEPCA_ADDR
); /* point back to CSR0 */
1218 outw(INIT
, DEPCA_DATA
); /* initialize DEPCA */
1220 /* wait for lance to complete initialisation */
1221 for (i
= 0; (i
< 100) && !(inw(DEPCA_DATA
) & IDON
); i
++);
1224 /* clear IDON by writing a "1", enable interrupts and start lance */
1225 outw(IDON
| INEA
| STRT
, DEPCA_DATA
);
1226 if (depca_debug
> 2) {
1227 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev
->name
, i
, lp
->mem_start
, inw(DEPCA_DATA
));
1230 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev
->name
, i
, lp
->mem_start
, inw(DEPCA_DATA
));
1238 ** Set or clear the multicast filter for this adaptor.
1240 static void set_multicast_list(struct net_device
*dev
)
1242 struct depca_private
*lp
= netdev_priv(dev
);
1243 u_long ioaddr
= dev
->base_addr
;
1245 netif_stop_queue(dev
);
1246 while (lp
->tx_old
!= lp
->tx_new
); /* Wait for the ring to empty */
1248 STOP_DEPCA
; /* Temporarily stop the depca. */
1249 depca_init_ring(dev
); /* Initialize the descriptor rings */
1251 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous mode */
1252 lp
->init_block
.mode
|= PROM
;
1254 SetMulticastFilter(dev
);
1255 lp
->init_block
.mode
&= ~PROM
; /* Unset promiscuous mode */
1258 LoadCSRs(dev
); /* Reload CSR3 */
1259 InitRestartDepca(dev
); /* Resume normal operation. */
1260 netif_start_queue(dev
); /* Unlock the TX ring */
1264 ** Calculate the hash code and update the logical address filter
1265 ** from a list of ethernet multicast addresses.
1266 ** Big endian crc one liner is mine, all mine, ha ha ha ha!
1267 ** LANCE calculates its hash codes big endian.
1269 static void SetMulticastFilter(struct net_device
*dev
)
1271 struct depca_private
*lp
= netdev_priv(dev
);
1272 struct dev_mc_list
*dmi
= dev
->mc_list
;
1274 int i
, j
, bit
, byte
;
1278 if (dev
->flags
& IFF_ALLMULTI
) { /* Set all multicast bits */
1279 for (i
= 0; i
< (HASH_TABLE_LEN
>> 3); i
++) {
1280 lp
->init_block
.mcast_table
[i
] = (char) 0xff;
1283 for (i
= 0; i
< (HASH_TABLE_LEN
>> 3); i
++) { /* Clear the multicast table */
1284 lp
->init_block
.mcast_table
[i
] = 0;
1286 /* Add multicast addresses */
1287 for (i
= 0; i
< dev
->mc_count
; i
++) { /* for each address in the list */
1288 addrs
= dmi
->dmi_addr
;
1290 if ((*addrs
& 0x01) == 1) { /* multicast address? */
1291 crc
= ether_crc(ETH_ALEN
, addrs
);
1292 hashcode
= (crc
& 1); /* hashcode is 6 LSb of CRC ... */
1293 for (j
= 0; j
< 5; j
++) { /* ... in reverse order. */
1294 hashcode
= (hashcode
<< 1) | ((crc
>>= 1) & 1);
1298 byte
= hashcode
>> 3; /* bit[3-5] -> byte in filter */
1299 bit
= 1 << (hashcode
& 0x07); /* bit[0-2] -> bit in byte */
1300 lp
->init_block
.mcast_table
[byte
] |= bit
;
1308 static int __init
depca_common_init (u_long ioaddr
, struct net_device
**devp
)
1312 if (!request_region (ioaddr
, DEPCA_TOTAL_SIZE
, depca_string
)) {
1317 if (DevicePresent(ioaddr
)) {
1322 if (!(*devp
= alloc_etherdev (sizeof (struct depca_private
)))) {
1330 release_region (ioaddr
, DEPCA_TOTAL_SIZE
);
1337 ** Microchannel bus I/O device probe
1339 static int __init
depca_mca_probe(struct device
*device
)
1341 unsigned char pos
[2];
1342 unsigned char where
;
1343 unsigned long iobase
, mem_start
;
1345 struct mca_device
*mdev
= to_mca_device (device
);
1346 struct net_device
*dev
;
1347 struct depca_private
*lp
;
1350 ** Search for the adapter. If an address has been given, search
1351 ** specifically for the card at that address. Otherwise find the
1352 ** first card in the system.
1355 pos
[0] = mca_device_read_stored_pos(mdev
, 2);
1356 pos
[1] = mca_device_read_stored_pos(mdev
, 3);
1359 ** IO of card is handled by bits 1 and 2 of pos0.
1367 where
= (pos
[0] & 6) >> 1;
1368 iobase
= 0x2c00 + (0x10 * where
);
1371 ** Found the adapter we were looking for. Now start setting it up.
1373 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1374 ** of pos1. Bits are as follows (from the ADF file):
1378 ** --------------------
1384 where
= pos
[1] & 0x0f;
1399 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", mdev
->name
, where
);
1404 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1405 ** They are mapped as follows:
1408 ** 5 4 3 Memory Addresses
1409 ** 0 0 0 C0000-CFFFF (64K)
1410 ** 1 0 0 C8000-CFFFF (32K)
1411 ** 0 0 1 D0000-DFFFF (64K)
1412 ** 1 0 1 D8000-DFFFF (32K)
1413 ** 0 1 0 E0000-EFFFF (64K)
1414 ** 1 1 0 E8000-EFFFF (32K)
1416 where
= (pos
[0] & 0x18) >> 3;
1417 mem_start
= 0xc0000 + (where
* 0x10000);
1418 if (pos
[0] & 0x20) {
1419 mem_start
+= 0x8000;
1422 /* claim the slot */
1423 strncpy(mdev
->name
, depca_mca_adapter_name
[mdev
->index
],
1424 sizeof(mdev
->name
));
1425 mca_device_set_claim(mdev
, 1);
1428 ** Get everything allocated and initialized... (almost just
1429 ** like the ISA and EISA probes)
1431 irq
= mca_device_transform_irq(mdev
, irq
);
1432 iobase
= mca_device_transform_ioport(mdev
, iobase
);
1434 if ((err
= depca_common_init (iobase
, &dev
)))
1438 dev
->base_addr
= iobase
;
1439 lp
= netdev_priv(dev
);
1440 lp
->depca_bus
= DEPCA_BUS_MCA
;
1441 lp
->adapter
= depca_mca_adapter_type
[mdev
->index
];
1442 lp
->mem_start
= mem_start
;
1444 if ((err
= depca_hw_init(dev
, device
)))
1451 release_region (iobase
, DEPCA_TOTAL_SIZE
);
1453 mca_device_set_claim(mdev
, 0);
1460 ** ISA bus I/O device probe
1463 static void __init
depca_platform_probe (void)
1466 struct platform_device
*pldev
;
1468 for (i
= 0; depca_io_ports
[i
].iobase
; i
++) {
1469 depca_io_ports
[i
].device
= NULL
;
1471 /* if an address has been specified on the command
1472 * line, use it (if valid) */
1473 if (io
&& io
!= depca_io_ports
[i
].iobase
)
1476 pldev
= platform_device_alloc(depca_string
, i
);
1480 pldev
->dev
.platform_data
= (void *) depca_io_ports
[i
].iobase
;
1481 depca_io_ports
[i
].device
= pldev
;
1483 if (platform_device_add(pldev
)) {
1484 depca_io_ports
[i
].device
= NULL
;
1485 pldev
->dev
.platform_data
= NULL
;
1486 platform_device_put(pldev
);
1490 if (!pldev
->dev
.driver
) {
1491 /* The driver was not bound to this device, there was
1492 * no hardware at this address. Unregister it, as the
1493 * release fuction will take care of freeing the
1494 * allocated structure */
1496 depca_io_ports
[i
].device
= NULL
;
1497 pldev
->dev
.platform_data
= NULL
;
1498 platform_device_unregister (pldev
);
1503 static enum depca_type __init
depca_shmem_probe (ulong
*mem_start
)
1505 u_long mem_base
[] = DEPCA_RAM_BASE_ADDRESSES
;
1506 enum depca_type adapter
= unknown
;
1509 for (i
= 0; mem_base
[i
]; i
++) {
1510 *mem_start
= mem
? mem
: mem_base
[i
];
1511 adapter
= DepcaSignature (adapter_name
, *mem_start
);
1512 if (adapter
!= unknown
)
1519 static int __init
depca_isa_probe (struct platform_device
*device
)
1521 struct net_device
*dev
;
1522 struct depca_private
*lp
;
1523 u_long ioaddr
, mem_start
= 0;
1524 enum depca_type adapter
= unknown
;
1527 ioaddr
= (u_long
) device
->dev
.platform_data
;
1529 if ((status
= depca_common_init (ioaddr
, &dev
)))
1532 adapter
= depca_shmem_probe (&mem_start
);
1534 if (adapter
== unknown
) {
1539 dev
->base_addr
= ioaddr
;
1540 dev
->irq
= irq
; /* Use whatever value the user gave
1541 * us, and 0 if he didn't. */
1542 lp
= netdev_priv(dev
);
1543 lp
->depca_bus
= DEPCA_BUS_ISA
;
1544 lp
->adapter
= adapter
;
1545 lp
->mem_start
= mem_start
;
1547 if ((status
= depca_hw_init(dev
, &device
->dev
)))
1554 release_region (ioaddr
, DEPCA_TOTAL_SIZE
);
1560 ** EISA callbacks from sysfs.
1564 static int __init
depca_eisa_probe (struct device
*device
)
1566 enum depca_type adapter
= unknown
;
1567 struct eisa_device
*edev
;
1568 struct net_device
*dev
;
1569 struct depca_private
*lp
;
1570 u_long ioaddr
, mem_start
;
1573 edev
= to_eisa_device (device
);
1574 ioaddr
= edev
->base_addr
+ DEPCA_EISA_IO_PORTS
;
1576 if ((status
= depca_common_init (ioaddr
, &dev
)))
1579 /* It would have been nice to get card configuration from the
1580 * card. Unfortunately, this register is write-only (shares
1581 * it's address with the ethernet prom)... As we don't parse
1582 * the EISA configuration structures (yet... :-), just rely on
1583 * the ISA probing to sort it out... */
1585 adapter
= depca_shmem_probe (&mem_start
);
1586 if (adapter
== unknown
) {
1591 dev
->base_addr
= ioaddr
;
1593 lp
= netdev_priv(dev
);
1594 lp
->depca_bus
= DEPCA_BUS_EISA
;
1595 lp
->adapter
= edev
->id
.driver_data
;
1596 lp
->mem_start
= mem_start
;
1598 if ((status
= depca_hw_init(dev
, device
)))
1605 release_region (ioaddr
, DEPCA_TOTAL_SIZE
);
1611 static int __devexit
depca_device_remove (struct device
*device
)
1613 struct net_device
*dev
;
1614 struct depca_private
*lp
;
1617 dev
= dev_get_drvdata(device
);
1618 lp
= netdev_priv(dev
);
1620 unregister_netdev (dev
);
1621 iounmap (lp
->sh_mem
);
1622 release_mem_region (lp
->mem_start
, lp
->mem_len
);
1623 release_region (dev
->base_addr
, DEPCA_TOTAL_SIZE
);
1624 bus
= lp
->depca_bus
;
1631 ** Look for a particular board name in the on-board Remote Diagnostics
1632 ** and Boot (readb) ROM. This will also give us a clue to the network RAM
1635 static int __init
DepcaSignature(char *name
, u_long base_addr
)
1640 u_long prom_addr
= base_addr
+ 0xc000;
1641 u_long mem_addr
= base_addr
+ 0x8000; /* 32KB */
1643 /* Can't reserve the prom region, it is already marked as
1644 * used, at least on x86. Instead, reserve a memory region a
1645 * board would certainly use. If it works, go ahead. If not,
1646 * run like hell... */
1648 if (!request_mem_region (mem_addr
, 16, depca_string
))
1651 /* Copy the first 16 bytes of ROM */
1653 ptr
= ioremap(prom_addr
, 16);
1655 printk(KERN_ERR
"depca: I/O remap failed at %lx\n", prom_addr
);
1658 for (i
= 0; i
< 16; i
++) {
1659 tmpstr
[i
] = readb(ptr
+ i
);
1663 release_mem_region (mem_addr
, 16);
1665 /* Check if PROM contains a valid string */
1666 for (i
= 0; *depca_signature
[i
] != '\0'; i
++) {
1667 for (j
= 0, k
= 0; j
< 16 && k
< strlen(depca_signature
[i
]); j
++) {
1668 if (depca_signature
[i
][k
] == tmpstr
[j
]) { /* track signature */
1670 } else { /* lost signature; begin search again */
1674 if (k
== strlen(depca_signature
[i
]))
1678 /* Check if name string is valid, provided there's no PROM */
1679 if (name
&& *name
&& (i
== unknown
)) {
1680 for (i
= 0; *depca_signature
[i
] != '\0'; i
++) {
1681 if (strcmp(name
, depca_signature
[i
]) == 0)
1690 ** Look for a special sequence in the Ethernet station address PROM that
1691 ** is common across all DEPCA products. Note that the original DEPCA needs
1692 ** its ROM address counter to be initialized and enabled. Only enable
1693 ** if the first address octet is a 0x08 - this minimises the chances of
1694 ** messing around with some other hardware, but it assumes that this DEPCA
1695 ** card initialized itself correctly.
1697 ** Search the Ethernet address ROM for the signature. Since the ROM address
1698 ** counter can start at an arbitrary point, the search must include the entire
1699 ** probe sequence length plus the (length_of_the_signature - 1).
1700 ** Stop the search IMMEDIATELY after the signature is found so that the
1701 ** PROM address counter is correctly positioned at the start of the
1702 ** ethernet address for later read out.
1704 static int __init
DevicePresent(u_long ioaddr
)
1711 char Sig
[sizeof(u32
) << 1];
1714 short sigLength
= 0;
1717 int i
, j
, status
= 0;
1719 data
= inb(DEPCA_PROM
); /* clear counter on DEPCA */
1720 data
= inb(DEPCA_PROM
); /* read data */
1722 if (data
== 0x08) { /* Enable counter on DEPCA */
1723 nicsr
= inb(DEPCA_NICSR
);
1725 outb(nicsr
, DEPCA_NICSR
);
1728 dev
.llsig
.a
= ETH_PROM_SIG
;
1729 dev
.llsig
.b
= ETH_PROM_SIG
;
1730 sigLength
= sizeof(u32
) << 1;
1732 for (i
= 0, j
= 0; j
< sigLength
&& i
< PROBE_LENGTH
+ sigLength
- 1; i
++) {
1733 data
= inb(DEPCA_PROM
);
1734 if (dev
.Sig
[j
] == data
) { /* track signature */
1736 } else { /* lost signature; begin search again */
1737 if (data
== dev
.Sig
[0]) { /* rare case.... */
1745 if (j
!= sigLength
) {
1746 status
= -ENODEV
; /* search failed */
1753 ** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1754 ** reason: access the upper half of the PROM with x=0; access the lower half
1757 static int __init
get_hw_addr(struct net_device
*dev
)
1759 u_long ioaddr
= dev
->base_addr
;
1760 struct depca_private
*lp
= netdev_priv(dev
);
1761 int i
, k
, tmp
, status
= 0;
1762 u_short j
, x
, chksum
;
1764 x
= (((lp
->adapter
== de100
) || (lp
->adapter
== de101
)) ? 1 : 0);
1766 for (i
= 0, k
= 0, j
= 0; j
< 3; j
++) {
1771 k
+= (u_char
) (tmp
= inb(DEPCA_PROM
+ x
));
1772 dev
->dev_addr
[i
++] = (u_char
) tmp
;
1773 k
+= (u_short
) ((tmp
= inb(DEPCA_PROM
+ x
)) << 8);
1774 dev
->dev_addr
[i
++] = (u_char
) tmp
;
1782 chksum
= (u_char
) inb(DEPCA_PROM
+ x
);
1783 chksum
|= (u_short
) (inb(DEPCA_PROM
+ x
) << 8);
1791 ** Load a packet into the shared memory
1793 static int load_packet(struct net_device
*dev
, struct sk_buff
*skb
)
1795 struct depca_private
*lp
= netdev_priv(dev
);
1796 int i
, entry
, end
, len
, status
= NETDEV_TX_OK
;
1798 entry
= lp
->tx_new
; /* Ring around buffer number. */
1799 end
= (entry
+ (skb
->len
- 1) / TX_BUFF_SZ
) & lp
->txRingMask
;
1800 if (!(readl(&lp
->tx_ring
[end
].base
) & T_OWN
)) { /* Enough room? */
1802 ** Caution: the write order is important here... don't set up the
1803 ** ownership rights until all the other information is in place.
1805 if (end
< entry
) { /* wrapped buffer */
1806 len
= (lp
->txRingMask
- entry
+ 1) * TX_BUFF_SZ
;
1807 memcpy_toio(lp
->tx_buff
[entry
], skb
->data
, len
);
1808 memcpy_toio(lp
->tx_buff
[0], skb
->data
+ len
, skb
->len
- len
);
1809 } else { /* linear buffer */
1810 memcpy_toio(lp
->tx_buff
[entry
], skb
->data
, skb
->len
);
1813 /* set up the buffer descriptors */
1814 len
= (skb
->len
< ETH_ZLEN
) ? ETH_ZLEN
: skb
->len
;
1815 for (i
= entry
; i
!= end
; i
= (i
+1) & lp
->txRingMask
) {
1816 /* clean out flags */
1817 writel(readl(&lp
->tx_ring
[i
].base
) & ~T_FLAGS
, &lp
->tx_ring
[i
].base
);
1818 writew(0x0000, &lp
->tx_ring
[i
].misc
); /* clears other error flags */
1819 writew(-TX_BUFF_SZ
, &lp
->tx_ring
[i
].length
); /* packet length in buffer */
1822 /* clean out flags */
1823 writel(readl(&lp
->tx_ring
[end
].base
) & ~T_FLAGS
, &lp
->tx_ring
[end
].base
);
1824 writew(0x0000, &lp
->tx_ring
[end
].misc
); /* clears other error flags */
1825 writew(-len
, &lp
->tx_ring
[end
].length
); /* packet length in last buff */
1827 /* start of packet */
1828 writel(readl(&lp
->tx_ring
[entry
].base
) | T_STP
, &lp
->tx_ring
[entry
].base
);
1830 writel(readl(&lp
->tx_ring
[end
].base
) | T_ENP
, &lp
->tx_ring
[end
].base
);
1832 for (i
= end
; i
!= entry
; --i
) {
1833 /* ownership of packet */
1834 writel(readl(&lp
->tx_ring
[i
].base
) | T_OWN
, &lp
->tx_ring
[i
].base
);
1836 i
= lp
->txRingMask
+ 1;
1838 writel(readl(&lp
->tx_ring
[entry
].base
) | T_OWN
, &lp
->tx_ring
[entry
].base
);
1840 lp
->tx_new
= (++end
) & lp
->txRingMask
; /* update current pointers */
1842 status
= NETDEV_TX_LOCKED
;
1848 static void depca_dbg_open(struct net_device
*dev
)
1850 struct depca_private
*lp
= netdev_priv(dev
);
1851 u_long ioaddr
= dev
->base_addr
;
1852 struct depca_init
*p
= &lp
->init_block
;
1855 if (depca_debug
> 1) {
1856 /* Do not copy the shadow init block into shared memory */
1857 /* Debugging should not affect normal operation! */
1858 /* The shadow init block will get copied across during InitRestartDepca */
1859 printk("%s: depca open with irq %d\n", dev
->name
, dev
->irq
);
1860 printk("Descriptor head addresses (CPU):\n");
1861 printk(" 0x%lx 0x%lx\n", (u_long
) lp
->rx_ring
, (u_long
) lp
->tx_ring
);
1862 printk("Descriptor addresses (CPU):\nRX: ");
1863 for (i
= 0; i
< lp
->rxRingMask
; i
++) {
1865 printk("%p ", &lp
->rx_ring
[i
].base
);
1868 printk("...%p\n", &lp
->rx_ring
[i
].base
);
1870 for (i
= 0; i
< lp
->txRingMask
; i
++) {
1872 printk("%p ", &lp
->tx_ring
[i
].base
);
1875 printk("...%p\n", &lp
->tx_ring
[i
].base
);
1876 printk("\nDescriptor buffers (Device):\nRX: ");
1877 for (i
= 0; i
< lp
->rxRingMask
; i
++) {
1879 printk("0x%8.8x ", readl(&lp
->rx_ring
[i
].base
));
1882 printk("...0x%8.8x\n", readl(&lp
->rx_ring
[i
].base
));
1884 for (i
= 0; i
< lp
->txRingMask
; i
++) {
1886 printk("0x%8.8x ", readl(&lp
->tx_ring
[i
].base
));
1889 printk("...0x%8.8x\n", readl(&lp
->tx_ring
[i
].base
));
1890 printk("Initialisation block at 0x%8.8lx(Phys)\n", lp
->mem_start
);
1891 printk(" mode: 0x%4.4x\n", p
->mode
);
1892 printk(" physical address: %pM\n", p
->phys_addr
);
1893 printk(" multicast hash table: ");
1894 for (i
= 0; i
< (HASH_TABLE_LEN
>> 3) - 1; i
++) {
1895 printk("%2.2x:", p
->mcast_table
[i
]);
1897 printk("%2.2x\n", p
->mcast_table
[i
]);
1898 printk(" rx_ring at: 0x%8.8x\n", p
->rx_ring
);
1899 printk(" tx_ring at: 0x%8.8x\n", p
->tx_ring
);
1900 printk("buffers (Phys): 0x%8.8lx\n", lp
->mem_start
+ lp
->buffs_offset
);
1901 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp
->rxRingMask
+ 1, lp
->rx_rlen
);
1902 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp
->txRingMask
+ 1, lp
->tx_rlen
);
1903 outw(CSR2
, DEPCA_ADDR
);
1904 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA
));
1905 outw(CSR1
, DEPCA_ADDR
);
1906 printk("%4.4x\n", inw(DEPCA_DATA
));
1907 outw(CSR3
, DEPCA_ADDR
);
1908 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA
));
1915 ** Perform IOCTL call functions here. Some are privileged operations and the
1916 ** effective uid is checked in those cases.
1917 ** All multicast IOCTLs will not work here and are for testing purposes only.
1919 static int depca_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1921 struct depca_private
*lp
= netdev_priv(dev
);
1922 struct depca_ioctl
*ioc
= (struct depca_ioctl
*) &rq
->ifr_ifru
;
1924 u_long ioaddr
= dev
->base_addr
;
1926 u8 addr
[(HASH_TABLE_LEN
* ETH_ALEN
)];
1927 u16 sval
[(HASH_TABLE_LEN
* ETH_ALEN
) >> 1];
1928 u32 lval
[(HASH_TABLE_LEN
* ETH_ALEN
) >> 2];
1930 unsigned long flags
;
1934 case DEPCA_GET_HWADDR
: /* Get the hardware address */
1935 for (i
= 0; i
< ETH_ALEN
; i
++) {
1936 tmp
.addr
[i
] = dev
->dev_addr
[i
];
1938 ioc
->len
= ETH_ALEN
;
1939 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
))
1943 case DEPCA_SET_HWADDR
: /* Set the hardware address */
1944 if (!capable(CAP_NET_ADMIN
))
1946 if (copy_from_user(tmp
.addr
, ioc
->data
, ETH_ALEN
))
1948 for (i
= 0; i
< ETH_ALEN
; i
++) {
1949 dev
->dev_addr
[i
] = tmp
.addr
[i
];
1951 netif_stop_queue(dev
);
1952 while (lp
->tx_old
!= lp
->tx_new
)
1953 cpu_relax(); /* Wait for the ring to empty */
1955 STOP_DEPCA
; /* Temporarily stop the depca. */
1956 depca_init_ring(dev
); /* Initialize the descriptor rings */
1957 LoadCSRs(dev
); /* Reload CSR3 */
1958 InitRestartDepca(dev
); /* Resume normal operation. */
1959 netif_start_queue(dev
); /* Unlock the TX ring */
1962 case DEPCA_SET_PROM
: /* Set Promiscuous Mode */
1963 if (!capable(CAP_NET_ADMIN
))
1965 netif_stop_queue(dev
);
1966 while (lp
->tx_old
!= lp
->tx_new
)
1967 cpu_relax(); /* Wait for the ring to empty */
1969 STOP_DEPCA
; /* Temporarily stop the depca. */
1970 depca_init_ring(dev
); /* Initialize the descriptor rings */
1971 lp
->init_block
.mode
|= PROM
; /* Set promiscuous mode */
1973 LoadCSRs(dev
); /* Reload CSR3 */
1974 InitRestartDepca(dev
); /* Resume normal operation. */
1975 netif_start_queue(dev
); /* Unlock the TX ring */
1978 case DEPCA_CLR_PROM
: /* Clear Promiscuous Mode */
1979 if (!capable(CAP_NET_ADMIN
))
1981 netif_stop_queue(dev
);
1982 while (lp
->tx_old
!= lp
->tx_new
)
1983 cpu_relax(); /* Wait for the ring to empty */
1985 STOP_DEPCA
; /* Temporarily stop the depca. */
1986 depca_init_ring(dev
); /* Initialize the descriptor rings */
1987 lp
->init_block
.mode
&= ~PROM
; /* Clear promiscuous mode */
1989 LoadCSRs(dev
); /* Reload CSR3 */
1990 InitRestartDepca(dev
); /* Resume normal operation. */
1991 netif_start_queue(dev
); /* Unlock the TX ring */
1994 case DEPCA_SAY_BOO
: /* Say "Boo!" to the kernel log file */
1995 if(!capable(CAP_NET_ADMIN
))
1997 printk("%s: Boo!\n", dev
->name
);
2000 case DEPCA_GET_MCA
: /* Get the multicast address table */
2001 ioc
->len
= (HASH_TABLE_LEN
>> 3);
2002 if (copy_to_user(ioc
->data
, lp
->init_block
.mcast_table
, ioc
->len
))
2006 case DEPCA_SET_MCA
: /* Set a multicast address */
2007 if (!capable(CAP_NET_ADMIN
))
2009 if (ioc
->len
>= HASH_TABLE_LEN
)
2011 if (copy_from_user(tmp
.addr
, ioc
->data
, ETH_ALEN
* ioc
->len
))
2013 set_multicast_list(dev
);
2016 case DEPCA_CLR_MCA
: /* Clear all multicast addresses */
2017 if (!capable(CAP_NET_ADMIN
))
2019 set_multicast_list(dev
);
2022 case DEPCA_MCA_EN
: /* Enable pass all multicast addressing */
2023 if (!capable(CAP_NET_ADMIN
))
2025 set_multicast_list(dev
);
2028 case DEPCA_GET_STATS
: /* Get the driver statistics */
2029 ioc
->len
= sizeof(lp
->pktStats
);
2030 buf
= kmalloc(ioc
->len
, GFP_KERNEL
);
2033 spin_lock_irqsave(&lp
->lock
, flags
);
2034 memcpy(buf
, &lp
->pktStats
, ioc
->len
);
2035 spin_unlock_irqrestore(&lp
->lock
, flags
);
2036 if (copy_to_user(ioc
->data
, buf
, ioc
->len
))
2041 case DEPCA_CLR_STATS
: /* Zero out the driver statistics */
2042 if (!capable(CAP_NET_ADMIN
))
2044 spin_lock_irqsave(&lp
->lock
, flags
);
2045 memset(&lp
->pktStats
, 0, sizeof(lp
->pktStats
));
2046 spin_unlock_irqrestore(&lp
->lock
, flags
);
2049 case DEPCA_GET_REG
: /* Get the DEPCA Registers */
2051 tmp
.sval
[i
++] = inw(DEPCA_NICSR
);
2052 outw(CSR0
, DEPCA_ADDR
); /* status register */
2053 tmp
.sval
[i
++] = inw(DEPCA_DATA
);
2054 memcpy(&tmp
.sval
[i
], &lp
->init_block
, sizeof(struct depca_init
));
2055 ioc
->len
= i
+ sizeof(struct depca_init
);
2056 if (copy_to_user(ioc
->data
, tmp
.addr
, ioc
->len
))
2067 static int __init
depca_module_init (void)
2072 err
= mca_register_driver (&depca_mca_driver
);
2075 err
|= eisa_driver_register (&depca_eisa_driver
);
2077 err
|= platform_driver_register (&depca_isa_driver
);
2078 depca_platform_probe ();
2083 static void __exit
depca_module_exit (void)
2087 mca_unregister_driver (&depca_mca_driver
);
2090 eisa_driver_unregister (&depca_eisa_driver
);
2092 platform_driver_unregister (&depca_isa_driver
);
2094 for (i
= 0; depca_io_ports
[i
].iobase
; i
++) {
2095 if (depca_io_ports
[i
].device
) {
2096 depca_io_ports
[i
].device
->dev
.platform_data
= NULL
;
2097 platform_device_unregister (depca_io_ports
[i
].device
);
2098 depca_io_ports
[i
].device
= NULL
;
2103 module_init (depca_module_init
);
2104 module_exit (depca_module_exit
);