blob: f2015a851977e6f36e936d01455b66c314d6782a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* depca.c: A DIGITAL DEPCA & EtherWORKS ethernet driver for linux.
2
3 Written 1994, 1995 by David C. Davies.
4
5
6 Copyright 1994 David C. Davies
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007 and
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 United States Government
Jeff Garzik6aa20a22006-09-13 13:24:59 -04009 (as represented by the Director, National Security Agency).
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11 Copyright 1995 Digital Equipment Corporation.
12
13
14 This software may be used and distributed according to the terms of
15 the GNU General Public License, incorporated herein by reference.
16
17 This driver is written for the Digital Equipment Corporation series
18 of DEPCA and EtherWORKS ethernet cards:
19
20 DEPCA (the original)
21 DE100
22 DE101
23 DE200 Turbo
24 DE201 Turbo
25 DE202 Turbo (TP BNC)
26 DE210
27 DE422 (EISA)
28
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.
31
32 This driver will NOT work for the DE203, DE204 and DE205 series of
33 cards, since they have a new custom ASIC in place of the AMD LANCE
34 chip. See the 'ewrk3.c' driver in the Linux source tree for running
35 those cards.
36
37 I have benchmarked the driver with a DE100 at 595kB/s to (542kB/s from)
38 a DECstation 5000/200.
39
40 The author may be reached at davies@maniac.ultranet.com
41
42 =========================================================================
43
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.
48
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
Jeff Garzik6aa20a22006-09-13 13:24:59 -040064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 Peter Bauer's depca.c (V0.5) was referred to when debugging V0.1 of this
67 driver.
68
69 The original DEPCA card requires that the ethernet ROM address counter
70 be enabled to count and has an 8 bit NICSR. The ROM counter enabling is
71 only done when a 0x08 is read as the first address octet (to minimise
72 the chances of writing over some other hardware's I/O register). The
73 NICSR accesses have been changed to byte accesses for all the cards
74 supported by this driver, since there is only one useful bit in the MSB
75 (remote boot timeout) and it is not used. Also, there is a maximum of
76 only 48kB network RAM for this card. My thanks to Torbjorn Lindh for
77 help debugging all this (and holding my feet to the fire until I got it
78 right).
79
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]).
84
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.
97
98 ************************************************************************
99
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.
107
108 I am unable to test 2 cards together for now, so this code is
109 unchecked. All reports, good or bad, are welcome.
110
111 ************************************************************************
112
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.
117
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).
121
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:
124
125 0) have a copy of the loadable modules code installed on your system.
126 1) copy depca.c from the /linux/drivers/net directory to your favourite
127 temporary directory.
128 2) if you wish, edit the source code near line 1530 to reflect the I/O
129 address and IRQ you're using (see also 5).
130 3) compile depca.c, but include -DMODULE in the command line to ensure
131 that the correct bits are compiled (see end of source code).
132 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
133 kernel with the depca configuration turned off and reboot.
134 5) insmod depca.o [irq=7] [io=0x200] [mem=0xd0000] [adapter_name=DE100]
135 [Alan Cox: Changed the code to allow command line irq/io assignments]
136 [Dave Davies: Changed the code to allow command line mem/name
137 assignments]
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400138 6) run the net startup bits for your eth?? interface manually
139 (usually /etc/rc.inet[12] at boot time).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 7) enjoy!
141
142 Note that autoprobing is not allowed in loadable modules - the system is
143 already up and running and you're messing with interrupts.
144
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400145 To unload a module, turn off the associated interface
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 'ifconfig eth?? down' then 'rmmod depca'.
147
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
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400151 option will not work with kernel built-in depca's.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 The shared memory assignment for a loadable module makes sense to avoid
154 the 'memory autoprobe' picking the wrong shared memory (for the case of
155 2 depca's in a PC).
156
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
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400160 fully stress-tested).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 Currently known bugs/limitations:
163
164 Note: with the MCA stuff as a module, it trusts the MCA configuration,
165 not the command line for IRQ and memory address. You can
166 specify them if you want, but it will throw your values out.
167 You still have to pass the IO address it was configured as
168 though.
169
170 ************************************************************************
171 TO DO:
172 ------
173
174
175 Revision History
176 ----------------
177
178 Version Date Description
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 0.1 25-jan-94 Initial writing.
181 0.2 27-jan-94 Added LANCE TX hardware buffer chaining.
182 0.3 1-feb-94 Added multiple DEPCA support.
183 0.31 4-feb-94 Added DE202 recognition.
184 0.32 19-feb-94 Tidy up. Improve multi-DEPCA support.
185 0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable.
186 Add jabber packet fix from murf@perftech.com
187 and becker@super.org
188 0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access.
189 0.35 8-mar-94 Added DE201 recognition. Tidied up.
190 0.351 30-apr-94 Added EISA support. Added DE422 recognition.
191 0.36 16-may-94 DE422 fix released.
192 0.37 22-jul-94 Added MODULE support
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400193 0.38 15-aug-94 Added DBR ROM switch in depca_close().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 Multi DEPCA bug fix.
195 0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0.
196 0.381 12-dec-94 Added DE101 recognition, fix multicast bug.
197 0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
198 0.383 22-feb-95 Fix for conflict with VESA SCSI reported by
199 <stromain@alf.dec.com>
200 0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk>
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400201 0.385 3-apr-95 Fix a recognition bug reported by
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 <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>
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400208 0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 modules.
210 Add 'adapter_name' for loadable modules when no PROM.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400211 Both above from a suggestion by
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 <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
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400221 by <tymm@computer.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 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>
234
235 =========================================================================
236*/
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#include <linux/module.h>
239#include <linux/kernel.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +0400240#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#include <linux/string.h>
242#include <linux/errno.h>
243#include <linux/ioport.h>
244#include <linux/slab.h>
245#include <linux/interrupt.h>
246#include <linux/delay.h>
247#include <linux/init.h>
248#include <linux/crc32.h>
249#include <linux/netdevice.h>
250#include <linux/etherdevice.h>
251#include <linux/skbuff.h>
252#include <linux/time.h>
253#include <linux/types.h>
254#include <linux/unistd.h>
255#include <linux/ctype.h>
256#include <linux/moduleparam.h>
Russell Kingd052d1b2005-10-29 19:07:23 +0100257#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#include <linux/bitops.h>
259
260#include <asm/uaccess.h>
261#include <asm/io.h>
262#include <asm/dma.h>
263
264#ifdef CONFIG_MCA
265#include <linux/mca.h>
266#endif
267
268#ifdef CONFIG_EISA
269#include <linux/eisa.h>
270#endif
271
272#include "depca.h"
273
274static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
275
276#ifdef DEPCA_DEBUG
277static int depca_debug = DEPCA_DEBUG;
278#else
279static int depca_debug = 1;
280#endif
281
282#define DEPCA_NDA 0xffe0 /* No Device Address */
283
284#define TX_TIMEOUT (1*HZ)
285
286/*
287** Ethernet PROM defines
288*/
289#define PROBE_LENGTH 32
290#define ETH_PROM_SIG 0xAA5500FFUL
291
292/*
293** Set the number of Tx and Rx buffers. Ensure that the memory requested
294** here is <= to the amount of shared memory set up by the board switches.
295** The number of descriptors MUST BE A POWER OF 2.
296**
297** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
298*/
299#define NUM_RX_DESC 8 /* Number of RX descriptors */
300#define NUM_TX_DESC 8 /* Number of TX descriptors */
301#define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
302#define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
303
304/*
305** EISA bus defines
306*/
307#define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
308
309/*
310** ISA Bus defines
311*/
312#define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
313#define DEPCA_TOTAL_SIZE 0x10
314
315static struct {
316 u_long iobase;
317 struct platform_device *device;
318} depca_io_ports[] = {
319 { 0x300, NULL },
320 { 0x200, NULL },
321 { 0 , NULL },
322};
323
324/*
325** Name <-> Adapter mapping
326*/
327#define DEPCA_SIGNATURE {"DEPCA",\
328 "DE100","DE101",\
329 "DE200","DE201","DE202",\
330 "DE210","DE212",\
331 "DE422",\
332 ""}
333
David S. Miller948252c2011-05-31 19:27:48 -0700334static char* __initdata depca_signature[] = DEPCA_SIGNATURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336enum depca_type {
337 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
338};
339
David S. Miller948252c2011-05-31 19:27:48 -0700340static char depca_string[] = "depca";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342static int depca_device_remove (struct device *device);
343
344#ifdef CONFIG_EISA
David S. Miller948252c2011-05-31 19:27:48 -0700345static struct eisa_device_id depca_eisa_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 { "DEC4220", de422 },
347 { "" }
348};
349MODULE_DEVICE_TABLE(eisa, depca_eisa_ids);
350
351static int depca_eisa_probe (struct device *device);
352
353static struct eisa_driver depca_eisa_driver = {
354 .id_table = depca_eisa_ids,
355 .driver = {
356 .name = depca_string,
357 .probe = depca_eisa_probe,
358 .remove = __devexit_p (depca_device_remove)
359 }
360};
361#endif
362
363#ifdef CONFIG_MCA
364/*
365** Adapter ID for the MCA EtherWORKS DE210/212 adapter
366*/
367#define DE210_ID 0x628d
368#define DE212_ID 0x6def
369
David S. Miller948252c2011-05-31 19:27:48 -0700370static short depca_mca_adapter_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 DE210_ID,
372 DE212_ID,
373 0x0000
374};
375
David S. Miller948252c2011-05-31 19:27:48 -0700376static char *depca_mca_adapter_name[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 "DEC EtherWORKS MC Adapter (DE210)",
378 "DEC EtherWORKS MC Adapter (DE212)",
379 NULL
380};
381
David S. Miller948252c2011-05-31 19:27:48 -0700382static enum depca_type depca_mca_adapter_type[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 de210,
384 de212,
385 0
386};
387
388static int depca_mca_probe (struct device *);
389
390static struct mca_driver depca_mca_driver = {
391 .id_table = depca_mca_adapter_ids,
392 .driver = {
393 .name = depca_string,
394 .bus = &mca_bus_type,
395 .probe = depca_mca_probe,
396 .remove = __devexit_p(depca_device_remove),
397 },
398};
399#endif
400
Russell King3ae5eae2005-11-09 22:32:44 +0000401static int depca_isa_probe (struct platform_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Russell King3ae5eae2005-11-09 22:32:44 +0000403static int __devexit depca_isa_remove(struct platform_device *pdev)
404{
405 return depca_device_remove(&pdev->dev);
406}
407
408static struct platform_driver depca_isa_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .probe = depca_isa_probe,
Russell King3ae5eae2005-11-09 22:32:44 +0000410 .remove = __devexit_p(depca_isa_remove),
411 .driver = {
412 .name = depca_string,
413 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416/*
417** Miscellaneous info...
418*/
419#define DEPCA_STRLEN 16
420
421/*
422** Memory Alignment. Each descriptor is 4 longwords long. To force a
423** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
424** DESC_ALIGN. DEPCA_ALIGN aligns the start address of the private memory area
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400425** and hence the RX descriptor ring's first entry.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426*/
427#define DEPCA_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
428#define DEPCA_ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
429#define DEPCA_ALIGN DEPCA_ALIGN8 /* Keep the LANCE happy... */
430
431/*
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400432** The DEPCA Rx and Tx ring descriptors.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433*/
434struct depca_rx_desc {
435 volatile s32 base;
436 s16 buf_length; /* This length is negative 2's complement! */
437 s16 msg_length; /* This length is "normal". */
438};
439
440struct depca_tx_desc {
441 volatile s32 base;
442 s16 length; /* This length is negative 2's complement! */
443 s16 misc; /* Errors and TDR info */
444};
445
446#define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
447 to LANCE memory address space */
448
449/*
450** The Lance initialization block, described in databook, in common memory.
451*/
452struct depca_init {
453 u16 mode; /* Mode register */
454 u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
455 u8 mcast_table[8]; /* Multicast Hash Table. */
456 u32 rx_ring; /* Rx ring base pointer & ring length */
457 u32 tx_ring; /* Tx ring base pointer & ring length */
458};
459
460#define DEPCA_PKT_STAT_SZ 16
461#define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
462 increase DEPCA_PKT_STAT_SZ */
463struct depca_private {
464 char adapter_name[DEPCA_STRLEN]; /* /proc/ioports string */
465 enum depca_type adapter; /* Adapter type */
466 enum {
467 DEPCA_BUS_MCA = 1,
468 DEPCA_BUS_ISA,
469 DEPCA_BUS_EISA,
470 } depca_bus; /* type of bus */
471 struct depca_init init_block; /* Shadow Initialization block */
472/* CPU address space fields */
473 struct depca_rx_desc __iomem *rx_ring; /* Pointer to start of RX descriptor ring */
474 struct depca_tx_desc __iomem *tx_ring; /* Pointer to start of TX descriptor ring */
475 void __iomem *rx_buff[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
476 void __iomem *tx_buff[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
477 void __iomem *sh_mem; /* CPU mapped virt address of device RAM */
478 u_long mem_start; /* Bus address of device RAM (before remap) */
479 u_long mem_len; /* device memory size */
480/* Device address space fields */
481 u_long device_ram_start; /* Start of RAM in device addr space */
482/* Offsets used in both address spaces */
483 u_long rx_ring_offset; /* Offset from start of RAM to rx_ring */
484 u_long tx_ring_offset; /* Offset from start of RAM to tx_ring */
485 u_long buffs_offset; /* LANCE Rx and Tx buffers start address. */
486/* Kernel-only (not device) fields */
487 int rx_new, tx_new; /* The next free ring entry */
488 int rx_old, tx_old; /* The ring entries to be free()ed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 spinlock_t lock;
490 struct { /* Private stats counters */
491 u32 bins[DEPCA_PKT_STAT_SZ];
492 u32 unicast;
493 u32 multicast;
494 u32 broadcast;
495 u32 excessive_collisions;
496 u32 tx_underruns;
497 u32 excessive_underruns;
498 } pktStats;
499 int txRingMask; /* TX ring mask */
500 int rxRingMask; /* RX ring mask */
501 s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
502 s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
503};
504
505/*
506** The transmit ring full condition is described by the tx_old and tx_new
507** pointers by:
508** tx_old = tx_new Empty ring
509** tx_old = tx_new+1 Full ring
510** tx_old+txRingMask = tx_new Full ring (wrapped condition)
511*/
512#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
513 lp->tx_old+lp->txRingMask-lp->tx_new:\
514 lp->tx_old -lp->tx_new-1)
515
516/*
517** Public Functions
518*/
519static int depca_open(struct net_device *dev);
Stephen Hemminger613573252009-08-31 19:50:58 +0000520static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
521 struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100522static irqreturn_t depca_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523static int depca_close(struct net_device *dev);
524static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
525static void depca_tx_timeout(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526static void set_multicast_list(struct net_device *dev);
527
528/*
529** Private functions
530*/
531static void depca_init_ring(struct net_device *dev);
532static int depca_rx(struct net_device *dev);
533static int depca_tx(struct net_device *dev);
534
535static void LoadCSRs(struct net_device *dev);
536static int InitRestartDepca(struct net_device *dev);
537static int DepcaSignature(char *name, u_long paddr);
538static int DevicePresent(u_long ioaddr);
539static int get_hw_addr(struct net_device *dev);
540static void SetMulticastFilter(struct net_device *dev);
541static int load_packet(struct net_device *dev, struct sk_buff *skb);
542static void depca_dbg_open(struct net_device *dev);
543
David S. Miller948252c2011-05-31 19:27:48 -0700544static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 };
545static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 };
546static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 };
547static u_char *depca_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549static int irq;
550static int io;
551static char *adapter_name;
552static int mem; /* For loadable module assignment
553 use insmod mem=0x????? .... */
554module_param (irq, int, 0);
555module_param (io, int, 0);
556module_param (adapter_name, charp, 0);
557module_param (mem, int, 0);
558MODULE_PARM_DESC(irq, "DEPCA IRQ number");
559MODULE_PARM_DESC(io, "DEPCA I/O base address");
560MODULE_PARM_DESC(adapter_name, "DEPCA adapter name");
561MODULE_PARM_DESC(mem, "DEPCA shared memory address");
562MODULE_LICENSE("GPL");
563
564/*
565** Miscellaneous defines...
566*/
567#define STOP_DEPCA \
568 outw(CSR0, DEPCA_ADDR);\
569 outw(STOP, DEPCA_DATA)
570
Stephen Hemminger361bc032009-03-26 15:11:37 +0000571static const struct net_device_ops depca_netdev_ops = {
572 .ndo_open = depca_open,
573 .ndo_start_xmit = depca_start_xmit,
574 .ndo_stop = depca_close,
575 .ndo_set_multicast_list = set_multicast_list,
576 .ndo_do_ioctl = depca_ioctl,
577 .ndo_tx_timeout = depca_tx_timeout,
578 .ndo_change_mtu = eth_change_mtu,
579 .ndo_set_mac_address = eth_mac_addr,
580 .ndo_validate_addr = eth_validate_addr,
581};
582
David S. Miller948252c2011-05-31 19:27:48 -0700583static int __init depca_hw_init (struct net_device *dev, struct device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 struct depca_private *lp;
586 int i, j, offset, netRAM, mem_len, status = 0;
587 s16 nicsr;
588 u_long ioaddr;
589 u_long mem_start;
590
591 /*
592 * We are now supposed to enter this function with the
593 * following fields filled with proper values :
594 *
595 * dev->base_addr
596 * lp->mem_start
597 * lp->depca_bus
598 * lp->adapter
599 *
600 * dev->irq can be set if known from device configuration (on
601 * MCA or EISA) or module option. Otherwise, it will be auto
602 * detected.
603 */
604
605 ioaddr = dev->base_addr;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 STOP_DEPCA;
608
609 nicsr = inb(DEPCA_NICSR);
610 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
611 outb(nicsr, DEPCA_NICSR);
612
613 if (inw(DEPCA_DATA) != STOP) {
614 return -ENXIO;
615 }
616
Wang Chen4cf16532008-11-12 23:38:14 -0800617 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 mem_start = lp->mem_start;
619
620 if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown)
621 return -ENXIO;
622
Kay Sieversc2313552009-03-24 16:38:22 -0700623 printk("%s: %s at 0x%04lx",
624 dev_name(device), depca_signature[lp->adapter], ioaddr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 switch (lp->depca_bus) {
627#ifdef CONFIG_MCA
628 case DEPCA_BUS_MCA:
629 printk(" (MCA slot %d)", to_mca_device(device)->slot + 1);
630 break;
631#endif
632
633#ifdef CONFIG_EISA
634 case DEPCA_BUS_EISA:
635 printk(" (EISA slot %d)", to_eisa_device(device)->slot);
636 break;
637#endif
638
639 case DEPCA_BUS_ISA:
640 break;
641
642 default:
643 printk("Unknown DEPCA bus %d\n", lp->depca_bus);
644 return -ENXIO;
645 }
646
647 printk(", h/w address ");
648 status = get_hw_addr(dev);
Johannes Berge1749612008-10-27 15:59:26 -0700649 printk("%pM", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 if (status != 0) {
651 printk(" which has an Ethernet PROM CRC error.\n");
652 return -ENXIO;
653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 /* Set up the maximum amount of network RAM(kB) */
656 netRAM = ((lp->adapter != DEPCA) ? 64 : 48);
657 if ((nicsr & _128KB) && (lp->adapter == de422))
658 netRAM = 128;
659
660 /* Shared Memory Base Address */
661 if (nicsr & BUF) {
662 nicsr &= ~BS; /* DEPCA RAM in top 32k */
663 netRAM -= 32;
664
665 /* Only EISA/ISA needs start address to be re-computed */
666 if (lp->depca_bus != DEPCA_BUS_MCA)
667 mem_start += 0x8000;
668 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 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)))
671 > (netRAM << 10)) {
672 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
673 return -ENXIO;
674 }
675
676 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
677
678 /* Enable the shadow RAM. */
679 if (lp->adapter != DEPCA) {
680 nicsr |= SHE;
681 outb(nicsr, DEPCA_NICSR);
682 }
683
684 spin_lock_init(&lp->lock);
685 sprintf(lp->adapter_name, "%s (%s)",
Kay Sieversc2313552009-03-24 16:38:22 -0700686 depca_signature[lp->adapter], dev_name(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 status = -EBUSY;
688
689 /* Initialisation Block */
690 if (!request_mem_region (mem_start, mem_len, lp->adapter_name)) {
691 printk(KERN_ERR "depca: cannot request ISA memory, aborting\n");
692 goto out_priv;
693 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 status = -EIO;
696 lp->sh_mem = ioremap(mem_start, mem_len);
697 if (lp->sh_mem == NULL) {
698 printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n");
699 goto out1;
700 }
701
702 lp->mem_start = mem_start;
703 lp->mem_len = mem_len;
704 lp->device_ram_start = mem_start & LA_MASK;
705
706 offset = 0;
707 offset += sizeof(struct depca_init);
708
709 /* Tx & Rx descriptors (aligned to a quadword boundary) */
710 offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
Joe Perches43d620c2011-06-16 19:08:06 +0000711 lp->rx_ring = lp->sh_mem + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 lp->rx_ring_offset = offset;
713
714 offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
Joe Perches43d620c2011-06-16 19:08:06 +0000715 lp->tx_ring = lp->sh_mem + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 lp->tx_ring_offset = offset;
717
718 offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
719
720 lp->buffs_offset = offset;
721
722 /* Finish initialising the ring information. */
723 lp->rxRingMask = NUM_RX_DESC - 1;
724 lp->txRingMask = NUM_TX_DESC - 1;
725
726 /* Calculate Tx/Rx RLEN size for the descriptors. */
727 for (i = 0, j = lp->rxRingMask; j > 0; i++) {
728 j >>= 1;
729 }
730 lp->rx_rlen = (s32) (i << 29);
731 for (i = 0, j = lp->txRingMask; j > 0; i++) {
732 j >>= 1;
733 }
734 lp->tx_rlen = (s32) (i << 29);
735
736 /* Load the initialisation block */
737 depca_init_ring(dev);
738
739 /* Initialise the control and status registers */
740 LoadCSRs(dev);
741
742 /* Enable DEPCA board interrupts for autoprobing */
743 nicsr = ((nicsr & ~IM) | IEN);
744 outb(nicsr, DEPCA_NICSR);
745
746 /* To auto-IRQ we enable the initialization-done and DMA err,
747 interrupts. For now we will always get a DMA error. */
748 if (dev->irq < 2) {
749 unsigned char irqnum;
750 unsigned long irq_mask, delay;
751
752 irq_mask = probe_irq_on();
753
754 /* Assign the correct irq list */
755 switch (lp->adapter) {
756 case DEPCA:
757 case de100:
758 case de101:
759 depca_irq = de1xx_irq;
760 break;
761 case de200:
762 case de201:
763 case de202:
764 case de210:
765 case de212:
766 depca_irq = de2xx_irq;
767 break;
768 case de422:
769 depca_irq = de422_irq;
770 break;
771
772 default:
773 break; /* Not reached */
774 }
775
776 /* Trigger an initialization just for the interrupt. */
777 outw(INEA | INIT, DEPCA_DATA);
778
779 delay = jiffies + HZ/50;
780 while (time_before(jiffies, delay))
781 yield();
782
783 irqnum = probe_irq_off(irq_mask);
784
785 status = -ENXIO;
786 if (!irqnum) {
787 printk(" and failed to detect IRQ line.\n");
788 goto out2;
789 } else {
790 for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
791 if (irqnum == depca_irq[i]) {
792 dev->irq = irqnum;
793 printk(" and uses IRQ%d.\n", dev->irq);
794 }
795
796 if (!dev->irq) {
797 printk(" but incorrect IRQ line detected.\n");
798 goto out2;
799 }
800 }
801 } else {
802 printk(" and assigned IRQ%d.\n", dev->irq);
803 }
804
805 if (depca_debug > 1) {
806 printk(version);
807 }
808
809 /* The DEPCA-specific entries in the device structure. */
Stephen Hemminger361bc032009-03-26 15:11:37 +0000810 dev->netdev_ops = &depca_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 dev->watchdog_timeo = TX_TIMEOUT;
812
813 dev->mem_start = 0;
814
Greg Kroah-Hartman1aec5bd2009-04-30 12:19:31 +0000815 dev_set_drvdata(device, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 SET_NETDEV_DEV (dev, device);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 status = register_netdev(dev);
819 if (status == 0)
820 return 0;
821out2:
822 iounmap(lp->sh_mem);
823out1:
824 release_mem_region (mem_start, mem_len);
825out_priv:
826 return status;
827}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830static int depca_open(struct net_device *dev)
831{
Wang Chen4cf16532008-11-12 23:38:14 -0800832 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 u_long ioaddr = dev->base_addr;
834 s16 nicsr;
835 int status = 0;
836
837 STOP_DEPCA;
838 nicsr = inb(DEPCA_NICSR);
839
840 /* Make sure the shadow RAM is enabled */
841 if (lp->adapter != DEPCA) {
842 nicsr |= SHE;
843 outb(nicsr, DEPCA_NICSR);
844 }
845
846 /* Re-initialize the DEPCA... */
847 depca_init_ring(dev);
848 LoadCSRs(dev);
849
850 depca_dbg_open(dev);
851
Joe Perchesa0607fd2009-11-18 23:29:17 -0800852 if (request_irq(dev->irq, depca_interrupt, 0, lp->adapter_name, dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 printk("depca_open(): Requested IRQ%d is busy\n", dev->irq);
854 status = -EAGAIN;
855 } else {
856
857 /* Enable DEPCA board interrupts and turn off LED */
858 nicsr = ((nicsr & ~IM & ~LED) | IEN);
859 outb(nicsr, DEPCA_NICSR);
860 outw(CSR0, DEPCA_ADDR);
861
862 netif_start_queue(dev);
863
864 status = InitRestartDepca(dev);
865
866 if (depca_debug > 1) {
867 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA));
868 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR));
869 }
870 }
871 return status;
872}
873
874/* Initialize the lance Rx and Tx descriptor rings. */
875static void depca_init_ring(struct net_device *dev)
876{
Wang Chen4cf16532008-11-12 23:38:14 -0800877 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 u_int i;
879 u_long offset;
880
881 /* Lock out other processes whilst setting up the hardware */
882 netif_stop_queue(dev);
883
884 lp->rx_new = lp->tx_new = 0;
885 lp->rx_old = lp->tx_old = 0;
886
887 /* Initialize the base address and length of each buffer in the ring */
888 for (i = 0; i <= lp->rxRingMask; i++) {
889 offset = lp->buffs_offset + i * RX_BUFF_SZ;
890 writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base);
891 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
892 lp->rx_buff[i] = lp->sh_mem + offset;
893 }
894
895 for (i = 0; i <= lp->txRingMask; i++) {
896 offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ;
897 writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base);
898 lp->tx_buff[i] = lp->sh_mem + offset;
899 }
900
901 /* Set up the initialization block */
902 lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen;
903 lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen;
904
905 SetMulticastFilter(dev);
906
907 for (i = 0; i < ETH_ALEN; i++) {
908 lp->init_block.phys_addr[i] = dev->dev_addr[i];
909 }
910
911 lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
912}
913
914
915static void depca_tx_timeout(struct net_device *dev)
916{
917 u_long ioaddr = dev->base_addr;
918
919 printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA));
920
921 STOP_DEPCA;
922 depca_init_ring(dev);
923 LoadCSRs(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700924 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 netif_wake_queue(dev);
926 InitRestartDepca(dev);
927}
928
929
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400930/*
931** Writes a socket buffer to TX descriptor ring and starts transmission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000933static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
934 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
Wang Chen4cf16532008-11-12 23:38:14 -0800936 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 u_long ioaddr = dev->base_addr;
938 int status = 0;
939
940 /* Transmitter timeout, serious problems. */
941 if (skb->len < 1)
942 goto out;
943
Herbert Xu5b057c62006-06-23 02:06:41 -0700944 if (skb_padto(skb, ETH_ZLEN))
945 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 netif_stop_queue(dev);
948
949 if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
950 status = load_packet(dev, skb);
951
952 if (!status) {
953 /* Trigger an immediate send demand. */
954 outw(CSR0, DEPCA_ADDR);
955 outw(INEA | TDMD, DEPCA_DATA);
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 dev_kfree_skb(skb);
958 }
959 if (TX_BUFFS_AVAIL)
960 netif_start_queue(dev);
961 } else
Patrick McHardy5b548142009-06-12 06:22:29 +0000962 status = NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 out:
965 return status;
966}
967
968/*
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400969** The DEPCA interrupt handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970*/
David Howells7d12e782006-10-05 14:55:46 +0100971static irqreturn_t depca_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
973 struct net_device *dev = dev_id;
974 struct depca_private *lp;
975 s16 csr0, nicsr;
976 u_long ioaddr;
977
978 if (dev == NULL) {
979 printk("depca_interrupt(): irq %d for unknown device.\n", irq);
980 return IRQ_NONE;
981 }
982
Wang Chen4cf16532008-11-12 23:38:14 -0800983 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 ioaddr = dev->base_addr;
985
986 spin_lock(&lp->lock);
987
988 /* mask the DEPCA board interrupts and turn on the LED */
989 nicsr = inb(DEPCA_NICSR);
990 nicsr |= (IM | LED);
991 outb(nicsr, DEPCA_NICSR);
992
993 outw(CSR0, DEPCA_ADDR);
994 csr0 = inw(DEPCA_DATA);
995
996 /* Acknowledge all of the current interrupt sources ASAP. */
997 outw(csr0 & INTE, DEPCA_DATA);
998
999 if (csr0 & RINT) /* Rx interrupt (packet arrived) */
1000 depca_rx(dev);
1001
1002 if (csr0 & TINT) /* Tx interrupt (packet sent) */
1003 depca_tx(dev);
1004
1005 /* Any resources available? */
1006 if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) {
1007 netif_wake_queue(dev);
1008 }
1009
1010 /* Unmask the DEPCA board interrupts and turn off the LED */
1011 nicsr = (nicsr & ~IM & ~LED);
1012 outb(nicsr, DEPCA_NICSR);
1013
1014 spin_unlock(&lp->lock);
1015 return IRQ_HANDLED;
1016}
1017
1018/* Called with lp->lock held */
1019static int depca_rx(struct net_device *dev)
1020{
Wang Chen4cf16532008-11-12 23:38:14 -08001021 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 int i, entry;
1023 s32 status;
1024
1025 for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) {
1026 status = readl(&lp->rx_ring[entry].base) >> 16;
1027 if (status & R_STP) { /* Remember start of frame */
1028 lp->rx_old = entry;
1029 }
1030 if (status & R_ENP) { /* Valid frame status */
1031 if (status & R_ERR) { /* There was an error. */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001032 dev->stats.rx_errors++; /* Update the error stats. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 if (status & R_FRAM)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001034 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (status & R_OFLO)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001036 dev->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (status & R_CRC)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001038 dev->stats.rx_crc_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (status & R_BUFF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001040 dev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 } else {
1042 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
1043 struct sk_buff *skb;
1044
1045 skb = dev_alloc_skb(pkt_len + 2);
1046 if (skb != NULL) {
1047 unsigned char *buf;
1048 skb_reserve(skb, 2); /* 16 byte align the IP header */
1049 buf = skb_put(skb, pkt_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (entry < lp->rx_old) { /* Wrapped buffer */
1051 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
1052 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len);
1053 memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len);
1054 } else { /* Linear buffer */
1055 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len);
1056 }
1057
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001058 /*
1059 ** Notify the upper protocol layers that there is another
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 ** packet to handle
1061 */
1062 skb->protocol = eth_type_trans(skb, dev);
1063 netif_rx(skb);
1064
1065 /*
1066 ** Update stats
1067 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001068 dev->stats.rx_packets++;
1069 dev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) {
1071 if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) {
1072 lp->pktStats.bins[i]++;
1073 i = DEPCA_PKT_STAT_SZ;
1074 }
1075 }
Tobias Klauser2effca32011-07-03 23:55:53 +00001076 if (is_multicast_ether_addr(buf)) {
1077 if (is_broadcast_ether_addr(buf)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 lp->pktStats.broadcast++;
1079 } else {
1080 lp->pktStats.multicast++;
1081 }
Tobias Klauser2effca32011-07-03 23:55:53 +00001082 } else if (compare_ether_addr(buf, dev->dev_addr) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 lp->pktStats.unicast++;
1084 }
1085
1086 lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
1087 if (lp->pktStats.bins[0] == 0) { /* Reset counters */
1088 memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats));
1089 }
1090 } else {
1091 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001092 dev->stats.rx_dropped++; /* Really, deferred. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 break;
1094 }
1095 }
1096 /* Change buffer ownership for this last frame, back to the adapter */
Alan Coxf97f3052011-02-01 13:19:07 -08001097 for (; lp->rx_old != entry; lp->rx_old = (lp->rx_old + 1) & lp->rxRingMask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base);
1099 }
1100 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1101 }
1102
1103 /*
1104 ** Update entry information
1105 */
Alan Coxf97f3052011-02-01 13:19:07 -08001106 lp->rx_new = (lp->rx_new + 1) & lp->rxRingMask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
1108
1109 return 0;
1110}
1111
1112/*
1113** Buffer sent - check for buffer errors.
1114** Called with lp->lock held
1115*/
1116static int depca_tx(struct net_device *dev)
1117{
Wang Chen4cf16532008-11-12 23:38:14 -08001118 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 int entry;
1120 s32 status;
1121 u_long ioaddr = dev->base_addr;
1122
1123 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1124 status = readl(&lp->tx_ring[entry].base) >> 16;
1125
1126 if (status < 0) { /* Packet not yet sent! */
1127 break;
1128 } else if (status & T_ERR) { /* An error occurred. */
1129 status = readl(&lp->tx_ring[entry].misc);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001130 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (status & TMD3_RTRY)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001132 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (status & TMD3_LCAR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001134 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 if (status & TMD3_LCOL)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001136 dev->stats.tx_window_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 if (status & TMD3_UFLO)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001138 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1140 /* Trigger an immediate send demand. */
1141 outw(CSR0, DEPCA_ADDR);
1142 outw(INEA | TDMD, DEPCA_DATA);
1143 }
1144 } else if (status & (T_MORE | T_ONE)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001145 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001147 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
1149
1150 /* Update all the pointers */
Alan Coxf97f3052011-02-01 13:19:07 -08001151 lp->tx_old = (lp->tx_old + 1) & lp->txRingMask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 }
1153
1154 return 0;
1155}
1156
1157static int depca_close(struct net_device *dev)
1158{
Wang Chen4cf16532008-11-12 23:38:14 -08001159 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 s16 nicsr;
1161 u_long ioaddr = dev->base_addr;
1162
1163 netif_stop_queue(dev);
1164
1165 outw(CSR0, DEPCA_ADDR);
1166
1167 if (depca_debug > 1) {
1168 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA));
1169 }
1170
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001171 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 ** We stop the DEPCA here -- it occasionally polls
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001173 ** memory if we don't.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 */
1175 outw(STOP, DEPCA_DATA);
1176
1177 /*
1178 ** Give back the ROM in case the user wants to go to DOS
1179 */
1180 if (lp->adapter != DEPCA) {
1181 nicsr = inb(DEPCA_NICSR);
1182 nicsr &= ~SHE;
1183 outb(nicsr, DEPCA_NICSR);
1184 }
1185
1186 /*
1187 ** Free the associated irq
1188 */
1189 free_irq(dev->irq, dev);
1190 return 0;
1191}
1192
1193static void LoadCSRs(struct net_device *dev)
1194{
Wang Chen4cf16532008-11-12 23:38:14 -08001195 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 u_long ioaddr = dev->base_addr;
1197
1198 outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
1199 outw((u16) lp->device_ram_start, DEPCA_DATA);
1200 outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
1201 outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA);
1202 outw(CSR3, DEPCA_ADDR); /* ALE control */
1203 outw(ACON, DEPCA_DATA);
1204
1205 outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
1208static int InitRestartDepca(struct net_device *dev)
1209{
Wang Chen4cf16532008-11-12 23:38:14 -08001210 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 u_long ioaddr = dev->base_addr;
1212 int i, status = 0;
1213
1214 /* Copy the shadow init_block to shared memory */
1215 memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1216
1217 outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
1218 outw(INIT, DEPCA_DATA); /* initialize DEPCA */
1219
1220 /* wait for lance to complete initialisation */
1221 for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++);
1222
1223 if (i != 100) {
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));
1228 }
1229 } else {
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));
1231 status = -1;
1232 }
1233
1234 return status;
1235}
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237/*
1238** Set or clear the multicast filter for this adaptor.
1239*/
1240static void set_multicast_list(struct net_device *dev)
1241{
Wang Chen4cf16532008-11-12 23:38:14 -08001242 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 u_long ioaddr = dev->base_addr;
1244
Eric Sesterhenn107ce6d2006-10-10 14:33:28 -07001245 netif_stop_queue(dev);
1246 while (lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Eric Sesterhenn107ce6d2006-10-10 14:33:28 -07001248 STOP_DEPCA; /* Temporarily stop the depca. */
1249 depca_init_ring(dev); /* Initialize the descriptor rings */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Eric Sesterhenn107ce6d2006-10-10 14:33:28 -07001251 if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
1252 lp->init_block.mode |= PROM;
1253 } else {
1254 SetMulticastFilter(dev);
1255 lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
Eric Sesterhenn107ce6d2006-10-10 14:33:28 -07001257
1258 LoadCSRs(dev); /* Reload CSR3 */
1259 InitRestartDepca(dev); /* Resume normal operation. */
1260 netif_start_queue(dev); /* Unlock the TX ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
1263/*
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.
1268*/
1269static void SetMulticastFilter(struct net_device *dev)
1270{
Wang Chen4cf16532008-11-12 23:38:14 -08001271 struct depca_private *lp = netdev_priv(dev);
Jiri Pirko22bedad2010-04-01 21:22:57 +00001272 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 int i, j, bit, byte;
1274 u16 hashcode;
1275 u32 crc;
1276
1277 if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
1278 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1279 lp->init_block.mcast_table[i] = (char) 0xff;
1280 }
1281 } else {
1282 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) { /* Clear the multicast table */
1283 lp->init_block.mcast_table[i] = 0;
1284 }
1285 /* Add multicast addresses */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001286 netdev_for_each_mc_addr(ha, dev) {
Tobias Klauser3170ff52011-06-29 02:15:15 +00001287 crc = ether_crc(ETH_ALEN, ha->addr);
1288 hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
1289 for (j = 0; j < 5; j++) { /* ... in reverse order. */
1290 hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
Tobias Klauser3170ff52011-06-29 02:15:15 +00001292
1293 byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
1294 bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
1295 lp->init_block.mcast_table[byte] |= bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 }
1297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
David S. Miller948252c2011-05-31 19:27:48 -07001300static int __init depca_common_init (u_long ioaddr, struct net_device **devp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 int status = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 if (!request_region (ioaddr, DEPCA_TOTAL_SIZE, depca_string)) {
1305 status = -EBUSY;
1306 goto out;
1307 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 if (DevicePresent(ioaddr)) {
1310 status = -ENODEV;
1311 goto out_release;
1312 }
1313
1314 if (!(*devp = alloc_etherdev (sizeof (struct depca_private)))) {
1315 status = -ENOMEM;
1316 goto out_release;
1317 }
1318
1319 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 out_release:
1322 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1323 out:
1324 return status;
1325}
1326
1327#ifdef CONFIG_MCA
1328/*
1329** Microchannel bus I/O device probe
1330*/
David S. Miller948252c2011-05-31 19:27:48 -07001331static int __init depca_mca_probe(struct device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
1333 unsigned char pos[2];
1334 unsigned char where;
1335 unsigned long iobase, mem_start;
1336 int irq, err;
1337 struct mca_device *mdev = to_mca_device (device);
1338 struct net_device *dev;
1339 struct depca_private *lp;
1340
1341 /*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001342 ** Search for the adapter. If an address has been given, search
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 ** specifically for the card at that address. Otherwise find the
1344 ** first card in the system.
1345 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 pos[0] = mca_device_read_stored_pos(mdev, 2);
1348 pos[1] = mca_device_read_stored_pos(mdev, 3);
1349
1350 /*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001351 ** IO of card is handled by bits 1 and 2 of pos0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 **
1353 ** bit2 bit1 IO
1354 ** 0 0 0x2c00
1355 ** 0 1 0x2c10
1356 ** 1 0 0x2c20
1357 ** 1 1 0x2c30
1358 */
1359 where = (pos[0] & 6) >> 1;
1360 iobase = 0x2c00 + (0x10 * where);
1361
1362 /*
1363 ** Found the adapter we were looking for. Now start setting it up.
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001364 **
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 ** First work on decoding the IRQ. It's stored in the lower 4 bits
1366 ** of pos1. Bits are as follows (from the ADF file):
1367 **
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001368 ** Bits
1369 ** 3 2 1 0 IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 ** --------------------
1371 ** 0 0 1 0 5
1372 ** 0 0 0 1 9
1373 ** 0 1 0 0 10
1374 ** 1 0 0 0 11
1375 */
1376 where = pos[1] & 0x0f;
1377 switch (where) {
1378 case 1:
1379 irq = 9;
1380 break;
1381 case 2:
1382 irq = 5;
1383 break;
1384 case 4:
1385 irq = 10;
1386 break;
1387 case 8:
1388 irq = 11;
1389 break;
1390 default:
Eric Sesterhenn6a6bbd22006-03-22 22:49:48 +01001391 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", mdev->name, where);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 return -EINVAL;
1393 }
1394
1395 /*
1396 ** Shared memory address of adapter is stored in bits 3-5 of pos0.
1397 ** They are mapped as follows:
1398 **
1399 ** Bit
1400 ** 5 4 3 Memory Addresses
1401 ** 0 0 0 C0000-CFFFF (64K)
1402 ** 1 0 0 C8000-CFFFF (32K)
1403 ** 0 0 1 D0000-DFFFF (64K)
1404 ** 1 0 1 D8000-DFFFF (32K)
1405 ** 0 1 0 E0000-EFFFF (64K)
1406 ** 1 1 0 E8000-EFFFF (32K)
1407 */
1408 where = (pos[0] & 0x18) >> 3;
1409 mem_start = 0xc0000 + (where * 0x10000);
1410 if (pos[0] & 0x20) {
1411 mem_start += 0x8000;
1412 }
1413
1414 /* claim the slot */
1415 strncpy(mdev->name, depca_mca_adapter_name[mdev->index],
1416 sizeof(mdev->name));
1417 mca_device_set_claim(mdev, 1);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 /*
1420 ** Get everything allocated and initialized... (almost just
1421 ** like the ISA and EISA probes)
1422 */
1423 irq = mca_device_transform_irq(mdev, irq);
1424 iobase = mca_device_transform_ioport(mdev, iobase);
1425
1426 if ((err = depca_common_init (iobase, &dev)))
1427 goto out_unclaim;
1428
1429 dev->irq = irq;
1430 dev->base_addr = iobase;
Wang Chen4cf16532008-11-12 23:38:14 -08001431 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 lp->depca_bus = DEPCA_BUS_MCA;
1433 lp->adapter = depca_mca_adapter_type[mdev->index];
1434 lp->mem_start = mem_start;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 if ((err = depca_hw_init(dev, device)))
1437 goto out_free;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 return 0;
1440
1441 out_free:
1442 free_netdev (dev);
1443 release_region (iobase, DEPCA_TOTAL_SIZE);
1444 out_unclaim:
1445 mca_device_set_claim(mdev, 0);
1446
1447 return err;
1448}
1449#endif
1450
1451/*
1452** ISA bus I/O device probe
1453*/
1454
David S. Miller948252c2011-05-31 19:27:48 -07001455static void __init depca_platform_probe (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
1457 int i;
1458 struct platform_device *pldev;
1459
1460 for (i = 0; depca_io_ports[i].iobase; i++) {
1461 depca_io_ports[i].device = NULL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* if an address has been specified on the command
1464 * line, use it (if valid) */
1465 if (io && io != depca_io_ports[i].iobase)
1466 continue;
Russell King5d994b72005-11-05 21:20:21 +00001467
1468 pldev = platform_device_alloc(depca_string, i);
1469 if (!pldev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 continue;
1471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 depca_io_ports[i].device = pldev;
1474
Russell King5d994b72005-11-05 21:20:21 +00001475 if (platform_device_add(pldev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 depca_io_ports[i].device = NULL;
Andrea Righid91c0882007-04-24 12:40:57 -04001477 pldev->dev.platform_data = NULL;
1478 platform_device_put(pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 continue;
1480 }
1481
1482 if (!pldev->dev.driver) {
1483 /* The driver was not bound to this device, there was
1484 * no hardware at this address. Unregister it, as the
Stefan Weileef35c22010-08-06 21:11:15 +02001485 * release function will take care of freeing the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 * allocated structure */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001487
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 depca_io_ports[i].device = NULL;
Russell King5d994b72005-11-05 21:20:21 +00001489 pldev->dev.platform_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 platform_device_unregister (pldev);
1491 }
1492 }
1493}
1494
David S. Miller948252c2011-05-31 19:27:48 -07001495static enum depca_type __init depca_shmem_probe (ulong *mem_start)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
1497 u_long mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
1498 enum depca_type adapter = unknown;
1499 int i;
1500
1501 for (i = 0; mem_base[i]; i++) {
1502 *mem_start = mem ? mem : mem_base[i];
1503 adapter = DepcaSignature (adapter_name, *mem_start);
1504 if (adapter != unknown)
1505 break;
1506 }
1507
1508 return adapter;
1509}
1510
Sedat Dilekebd80882011-01-03 11:22:15 +00001511static int __devinit depca_isa_probe (struct platform_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
1513 struct net_device *dev;
1514 struct depca_private *lp;
1515 u_long ioaddr, mem_start = 0;
1516 enum depca_type adapter = unknown;
1517 int status = 0;
1518
Russell King3ae5eae2005-11-09 22:32:44 +00001519 ioaddr = (u_long) device->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 if ((status = depca_common_init (ioaddr, &dev)))
1522 goto out;
1523
1524 adapter = depca_shmem_probe (&mem_start);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (adapter == unknown) {
1527 status = -ENODEV;
1528 goto out_free;
1529 }
1530
1531 dev->base_addr = ioaddr;
1532 dev->irq = irq; /* Use whatever value the user gave
1533 * us, and 0 if he didn't. */
Wang Chen4cf16532008-11-12 23:38:14 -08001534 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 lp->depca_bus = DEPCA_BUS_ISA;
1536 lp->adapter = adapter;
1537 lp->mem_start = mem_start;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001538
Russell King3ae5eae2005-11-09 22:32:44 +00001539 if ((status = depca_hw_init(dev, &device->dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 goto out_free;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 return 0;
1543
1544 out_free:
1545 free_netdev (dev);
1546 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1547 out:
1548 return status;
1549}
1550
1551/*
1552** EISA callbacks from sysfs.
1553*/
1554
1555#ifdef CONFIG_EISA
David S. Miller948252c2011-05-31 19:27:48 -07001556static int __init depca_eisa_probe (struct device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Ingo Molnar99da1a82008-11-25 17:00:39 -08001558 enum depca_type adapter = unknown;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 struct eisa_device *edev;
1560 struct net_device *dev;
1561 struct depca_private *lp;
1562 u_long ioaddr, mem_start;
1563 int status = 0;
1564
1565 edev = to_eisa_device (device);
1566 ioaddr = edev->base_addr + DEPCA_EISA_IO_PORTS;
1567
1568 if ((status = depca_common_init (ioaddr, &dev)))
1569 goto out;
1570
1571 /* It would have been nice to get card configuration from the
1572 * card. Unfortunately, this register is write-only (shares
1573 * it's address with the ethernet prom)... As we don't parse
1574 * the EISA configuration structures (yet... :-), just rely on
1575 * the ISA probing to sort it out... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001576
Ingo Molnar99da1a82008-11-25 17:00:39 -08001577 adapter = depca_shmem_probe (&mem_start);
1578 if (adapter == unknown) {
1579 status = -ENODEV;
1580 goto out_free;
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
1583 dev->base_addr = ioaddr;
1584 dev->irq = irq;
Wang Chen4cf16532008-11-12 23:38:14 -08001585 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 lp->depca_bus = DEPCA_BUS_EISA;
1587 lp->adapter = edev->id.driver_data;
1588 lp->mem_start = mem_start;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 if ((status = depca_hw_init(dev, device)))
1591 goto out_free;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return 0;
1594
1595 out_free:
1596 free_netdev (dev);
1597 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1598 out:
1599 return status;
1600}
1601#endif
1602
1603static int __devexit depca_device_remove (struct device *device)
1604{
1605 struct net_device *dev;
1606 struct depca_private *lp;
1607 int bus;
1608
Greg Kroah-Hartman1aec5bd2009-04-30 12:19:31 +00001609 dev = dev_get_drvdata(device);
Wang Chen4cf16532008-11-12 23:38:14 -08001610 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 unregister_netdev (dev);
1613 iounmap (lp->sh_mem);
1614 release_mem_region (lp->mem_start, lp->mem_len);
1615 release_region (dev->base_addr, DEPCA_TOTAL_SIZE);
1616 bus = lp->depca_bus;
1617 free_netdev (dev);
1618
1619 return 0;
1620}
1621
1622/*
1623** Look for a particular board name in the on-board Remote Diagnostics
1624** and Boot (readb) ROM. This will also give us a clue to the network RAM
1625** base address.
1626*/
David S. Miller948252c2011-05-31 19:27:48 -07001627static int __init DepcaSignature(char *name, u_long base_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
1629 u_int i, j, k;
1630 void __iomem *ptr;
1631 char tmpstr[16];
1632 u_long prom_addr = base_addr + 0xc000;
1633 u_long mem_addr = base_addr + 0x8000; /* 32KB */
1634
1635 /* Can't reserve the prom region, it is already marked as
1636 * used, at least on x86. Instead, reserve a memory region a
1637 * board would certainly use. If it works, go ahead. If not,
1638 * run like hell... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 if (!request_mem_region (mem_addr, 16, depca_string))
1641 return unknown;
1642
1643 /* Copy the first 16 bytes of ROM */
1644
1645 ptr = ioremap(prom_addr, 16);
1646 if (ptr == NULL) {
1647 printk(KERN_ERR "depca: I/O remap failed at %lx\n", prom_addr);
1648 return unknown;
1649 }
1650 for (i = 0; i < 16; i++) {
1651 tmpstr[i] = readb(ptr + i);
1652 }
1653 iounmap(ptr);
1654
1655 release_mem_region (mem_addr, 16);
1656
1657 /* Check if PROM contains a valid string */
1658 for (i = 0; *depca_signature[i] != '\0'; i++) {
1659 for (j = 0, k = 0; j < 16 && k < strlen(depca_signature[i]); j++) {
1660 if (depca_signature[i][k] == tmpstr[j]) { /* track signature */
1661 k++;
1662 } else { /* lost signature; begin search again */
1663 k = 0;
1664 }
1665 }
1666 if (k == strlen(depca_signature[i]))
1667 break;
1668 }
1669
1670 /* Check if name string is valid, provided there's no PROM */
1671 if (name && *name && (i == unknown)) {
1672 for (i = 0; *depca_signature[i] != '\0'; i++) {
1673 if (strcmp(name, depca_signature[i]) == 0)
1674 break;
1675 }
1676 }
1677
1678 return i;
1679}
1680
1681/*
1682** Look for a special sequence in the Ethernet station address PROM that
1683** is common across all DEPCA products. Note that the original DEPCA needs
1684** its ROM address counter to be initialized and enabled. Only enable
1685** if the first address octet is a 0x08 - this minimises the chances of
1686** messing around with some other hardware, but it assumes that this DEPCA
1687** card initialized itself correctly.
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001688**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689** Search the Ethernet address ROM for the signature. Since the ROM address
1690** counter can start at an arbitrary point, the search must include the entire
1691** probe sequence length plus the (length_of_the_signature - 1).
1692** Stop the search IMMEDIATELY after the signature is found so that the
1693** PROM address counter is correctly positioned at the start of the
1694** ethernet address for later read out.
1695*/
1696static int __init DevicePresent(u_long ioaddr)
1697{
1698 union {
1699 struct {
1700 u32 a;
1701 u32 b;
1702 } llsig;
1703 char Sig[sizeof(u32) << 1];
1704 }
1705 dev;
1706 short sigLength = 0;
1707 s8 data;
1708 s16 nicsr;
1709 int i, j, status = 0;
1710
1711 data = inb(DEPCA_PROM); /* clear counter on DEPCA */
1712 data = inb(DEPCA_PROM); /* read data */
1713
1714 if (data == 0x08) { /* Enable counter on DEPCA */
1715 nicsr = inb(DEPCA_NICSR);
1716 nicsr |= AAC;
1717 outb(nicsr, DEPCA_NICSR);
1718 }
1719
1720 dev.llsig.a = ETH_PROM_SIG;
1721 dev.llsig.b = ETH_PROM_SIG;
1722 sigLength = sizeof(u32) << 1;
1723
1724 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
1725 data = inb(DEPCA_PROM);
1726 if (dev.Sig[j] == data) { /* track signature */
1727 j++;
1728 } else { /* lost signature; begin search again */
1729 if (data == dev.Sig[0]) { /* rare case.... */
1730 j = 1;
1731 } else {
1732 j = 0;
1733 }
1734 }
1735 }
1736
1737 if (j != sigLength) {
1738 status = -ENODEV; /* search failed */
1739 }
1740
1741 return status;
1742}
1743
1744/*
1745** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
1746** reason: access the upper half of the PROM with x=0; access the lower half
1747** with x=1.
1748*/
1749static int __init get_hw_addr(struct net_device *dev)
1750{
1751 u_long ioaddr = dev->base_addr;
Wang Chen4cf16532008-11-12 23:38:14 -08001752 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 int i, k, tmp, status = 0;
1754 u_short j, x, chksum;
1755
1756 x = (((lp->adapter == de100) || (lp->adapter == de101)) ? 1 : 0);
1757
1758 for (i = 0, k = 0, j = 0; j < 3; j++) {
1759 k <<= 1;
1760 if (k > 0xffff)
1761 k -= 0xffff;
1762
1763 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1764 dev->dev_addr[i++] = (u_char) tmp;
1765 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1766 dev->dev_addr[i++] = (u_char) tmp;
1767
1768 if (k > 0xffff)
1769 k -= 0xffff;
1770 }
1771 if (k == 0xffff)
1772 k = 0;
1773
1774 chksum = (u_char) inb(DEPCA_PROM + x);
1775 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1776 if (k != chksum)
1777 status = -1;
1778
1779 return status;
1780}
1781
1782/*
1783** Load a packet into the shared memory
1784*/
1785static int load_packet(struct net_device *dev, struct sk_buff *skb)
1786{
Wang Chen4cf16532008-11-12 23:38:14 -08001787 struct depca_private *lp = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001788 int i, entry, end, len, status = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
1790 entry = lp->tx_new; /* Ring around buffer number. */
1791 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1792 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) { /* Enough room? */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001793 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 ** Caution: the write order is important here... don't set up the
1795 ** ownership rights until all the other information is in place.
1796 */
1797 if (end < entry) { /* wrapped buffer */
1798 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1799 memcpy_toio(lp->tx_buff[entry], skb->data, len);
1800 memcpy_toio(lp->tx_buff[0], skb->data + len, skb->len - len);
1801 } else { /* linear buffer */
1802 memcpy_toio(lp->tx_buff[entry], skb->data, skb->len);
1803 }
1804
1805 /* set up the buffer descriptors */
1806 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1807 for (i = entry; i != end; i = (i+1) & lp->txRingMask) {
1808 /* clean out flags */
1809 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1810 writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */
1811 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length); /* packet length in buffer */
1812 len -= TX_BUFF_SZ;
1813 }
1814 /* clean out flags */
1815 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1816 writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */
1817 writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */
1818
1819 /* start of packet */
1820 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1821 /* end of packet */
1822 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1823
1824 for (i = end; i != entry; --i) {
1825 /* ownership of packet */
1826 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1827 if (i == 0)
1828 i = lp->txRingMask + 1;
1829 }
1830 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1831
1832 lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */
1833 } else {
Patrick McHardy5b548142009-06-12 06:22:29 +00001834 status = NETDEV_TX_LOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
1836
1837 return status;
1838}
1839
1840static void depca_dbg_open(struct net_device *dev)
1841{
Wang Chen4cf16532008-11-12 23:38:14 -08001842 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 u_long ioaddr = dev->base_addr;
1844 struct depca_init *p = &lp->init_block;
1845 int i;
1846
1847 if (depca_debug > 1) {
1848 /* Do not copy the shadow init block into shared memory */
1849 /* Debugging should not affect normal operation! */
1850 /* The shadow init block will get copied across during InitRestartDepca */
1851 printk("%s: depca open with irq %d\n", dev->name, dev->irq);
1852 printk("Descriptor head addresses (CPU):\n");
1853 printk(" 0x%lx 0x%lx\n", (u_long) lp->rx_ring, (u_long) lp->tx_ring);
1854 printk("Descriptor addresses (CPU):\nRX: ");
1855 for (i = 0; i < lp->rxRingMask; i++) {
1856 if (i < 3) {
1857 printk("%p ", &lp->rx_ring[i].base);
1858 }
1859 }
1860 printk("...%p\n", &lp->rx_ring[i].base);
1861 printk("TX: ");
1862 for (i = 0; i < lp->txRingMask; i++) {
1863 if (i < 3) {
1864 printk("%p ", &lp->tx_ring[i].base);
1865 }
1866 }
1867 printk("...%p\n", &lp->tx_ring[i].base);
1868 printk("\nDescriptor buffers (Device):\nRX: ");
1869 for (i = 0; i < lp->rxRingMask; i++) {
1870 if (i < 3) {
1871 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1872 }
1873 }
1874 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1875 printk("TX: ");
1876 for (i = 0; i < lp->txRingMask; i++) {
1877 if (i < 3) {
1878 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1879 }
1880 }
1881 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1882 printk("Initialisation block at 0x%8.8lx(Phys)\n", lp->mem_start);
1883 printk(" mode: 0x%4.4x\n", p->mode);
Johannes Berge1749612008-10-27 15:59:26 -07001884 printk(" physical address: %pM\n", p->phys_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 printk(" multicast hash table: ");
1886 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) {
1887 printk("%2.2x:", p->mcast_table[i]);
1888 }
1889 printk("%2.2x\n", p->mcast_table[i]);
1890 printk(" rx_ring at: 0x%8.8x\n", p->rx_ring);
1891 printk(" tx_ring at: 0x%8.8x\n", p->tx_ring);
1892 printk("buffers (Phys): 0x%8.8lx\n", lp->mem_start + lp->buffs_offset);
1893 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen);
1894 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen);
1895 outw(CSR2, DEPCA_ADDR);
1896 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA));
1897 outw(CSR1, DEPCA_ADDR);
1898 printk("%4.4x\n", inw(DEPCA_DATA));
1899 outw(CSR3, DEPCA_ADDR);
1900 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA));
1901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902}
1903
1904/*
1905** Perform IOCTL call functions here. Some are privileged operations and the
1906** effective uid is checked in those cases.
1907** All multicast IOCTLs will not work here and are for testing purposes only.
1908*/
1909static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1910{
Wang Chen4cf16532008-11-12 23:38:14 -08001911 struct depca_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_ifru;
1913 int i, status = 0;
1914 u_long ioaddr = dev->base_addr;
1915 union {
1916 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1917 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1918 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1919 } tmp;
1920 unsigned long flags;
1921 void *buf;
1922
1923 switch (ioc->cmd) {
1924 case DEPCA_GET_HWADDR: /* Get the hardware address */
1925 for (i = 0; i < ETH_ALEN; i++) {
1926 tmp.addr[i] = dev->dev_addr[i];
1927 }
1928 ioc->len = ETH_ALEN;
1929 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
1930 return -EFAULT;
1931 break;
1932
1933 case DEPCA_SET_HWADDR: /* Set the hardware address */
1934 if (!capable(CAP_NET_ADMIN))
1935 return -EPERM;
1936 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN))
1937 return -EFAULT;
1938 for (i = 0; i < ETH_ALEN; i++) {
1939 dev->dev_addr[i] = tmp.addr[i];
1940 }
1941 netif_stop_queue(dev);
1942 while (lp->tx_old != lp->tx_new)
1943 cpu_relax(); /* Wait for the ring to empty */
1944
1945 STOP_DEPCA; /* Temporarily stop the depca. */
1946 depca_init_ring(dev); /* Initialize the descriptor rings */
1947 LoadCSRs(dev); /* Reload CSR3 */
1948 InitRestartDepca(dev); /* Resume normal operation. */
1949 netif_start_queue(dev); /* Unlock the TX ring */
1950 break;
1951
1952 case DEPCA_SET_PROM: /* Set Promiscuous Mode */
1953 if (!capable(CAP_NET_ADMIN))
1954 return -EPERM;
1955 netif_stop_queue(dev);
1956 while (lp->tx_old != lp->tx_new)
1957 cpu_relax(); /* Wait for the ring to empty */
1958
1959 STOP_DEPCA; /* Temporarily stop the depca. */
1960 depca_init_ring(dev); /* Initialize the descriptor rings */
1961 lp->init_block.mode |= PROM; /* Set promiscuous mode */
1962
1963 LoadCSRs(dev); /* Reload CSR3 */
1964 InitRestartDepca(dev); /* Resume normal operation. */
1965 netif_start_queue(dev); /* Unlock the TX ring */
1966 break;
1967
1968 case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */
1969 if (!capable(CAP_NET_ADMIN))
1970 return -EPERM;
1971 netif_stop_queue(dev);
1972 while (lp->tx_old != lp->tx_new)
1973 cpu_relax(); /* Wait for the ring to empty */
1974
1975 STOP_DEPCA; /* Temporarily stop the depca. */
1976 depca_init_ring(dev); /* Initialize the descriptor rings */
1977 lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */
1978
1979 LoadCSRs(dev); /* Reload CSR3 */
1980 InitRestartDepca(dev); /* Resume normal operation. */
1981 netif_start_queue(dev); /* Unlock the TX ring */
1982 break;
1983
1984 case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */
1985 if(!capable(CAP_NET_ADMIN))
1986 return -EPERM;
1987 printk("%s: Boo!\n", dev->name);
1988 break;
1989
1990 case DEPCA_GET_MCA: /* Get the multicast address table */
1991 ioc->len = (HASH_TABLE_LEN >> 3);
1992 if (copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len))
1993 return -EFAULT;
1994 break;
1995
1996 case DEPCA_SET_MCA: /* Set a multicast address */
1997 if (!capable(CAP_NET_ADMIN))
1998 return -EPERM;
1999 if (ioc->len >= HASH_TABLE_LEN)
2000 return -EINVAL;
2001 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len))
2002 return -EFAULT;
2003 set_multicast_list(dev);
2004 break;
2005
2006 case DEPCA_CLR_MCA: /* Clear all multicast addresses */
2007 if (!capable(CAP_NET_ADMIN))
2008 return -EPERM;
2009 set_multicast_list(dev);
2010 break;
2011
2012 case DEPCA_MCA_EN: /* Enable pass all multicast addressing */
2013 if (!capable(CAP_NET_ADMIN))
2014 return -EPERM;
2015 set_multicast_list(dev);
2016 break;
2017
2018 case DEPCA_GET_STATS: /* Get the driver statistics */
2019 ioc->len = sizeof(lp->pktStats);
2020 buf = kmalloc(ioc->len, GFP_KERNEL);
2021 if(!buf)
2022 return -ENOMEM;
2023 spin_lock_irqsave(&lp->lock, flags);
2024 memcpy(buf, &lp->pktStats, ioc->len);
2025 spin_unlock_irqrestore(&lp->lock, flags);
2026 if (copy_to_user(ioc->data, buf, ioc->len))
2027 status = -EFAULT;
2028 kfree(buf);
2029 break;
2030
2031 case DEPCA_CLR_STATS: /* Zero out the driver statistics */
2032 if (!capable(CAP_NET_ADMIN))
2033 return -EPERM;
2034 spin_lock_irqsave(&lp->lock, flags);
2035 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
2036 spin_unlock_irqrestore(&lp->lock, flags);
2037 break;
2038
2039 case DEPCA_GET_REG: /* Get the DEPCA Registers */
2040 i = 0;
2041 tmp.sval[i++] = inw(DEPCA_NICSR);
2042 outw(CSR0, DEPCA_ADDR); /* status register */
2043 tmp.sval[i++] = inw(DEPCA_DATA);
2044 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
2045 ioc->len = i + sizeof(struct depca_init);
2046 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
2047 return -EFAULT;
2048 break;
2049
2050 default:
2051 return -EOPNOTSUPP;
2052 }
2053
2054 return status;
2055}
2056
2057static int __init depca_module_init (void)
2058{
Kulikov Vasiliy84c3b972010-07-12 04:52:33 +00002059 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061#ifdef CONFIG_MCA
Kulikov Vasiliy84c3b972010-07-12 04:52:33 +00002062 err = mca_register_driver(&depca_mca_driver);
2063 if (err)
2064 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065#endif
2066#ifdef CONFIG_EISA
Kulikov Vasiliy84c3b972010-07-12 04:52:33 +00002067 err = eisa_driver_register(&depca_eisa_driver);
2068 if (err)
2069 goto err_mca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070#endif
Kulikov Vasiliy84c3b972010-07-12 04:52:33 +00002071 err = platform_driver_register(&depca_isa_driver);
2072 if (err)
2073 goto err_eisa;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002074
Kulikov Vasiliy84c3b972010-07-12 04:52:33 +00002075 depca_platform_probe();
2076 return 0;
2077
2078err_eisa:
2079#ifdef CONFIG_EISA
2080 eisa_driver_unregister(&depca_eisa_driver);
2081err_mca:
2082#endif
2083#ifdef CONFIG_MCA
2084 mca_unregister_driver(&depca_mca_driver);
2085err:
2086#endif
2087 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
2090static void __exit depca_module_exit (void)
2091{
2092 int i;
2093#ifdef CONFIG_MCA
2094 mca_unregister_driver (&depca_mca_driver);
2095#endif
2096#ifdef CONFIG_EISA
2097 eisa_driver_unregister (&depca_eisa_driver);
2098#endif
Russell King3ae5eae2005-11-09 22:32:44 +00002099 platform_driver_unregister (&depca_isa_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101 for (i = 0; depca_io_ports[i].iobase; i++) {
2102 if (depca_io_ports[i].device) {
Russell King5d994b72005-11-05 21:20:21 +00002103 depca_io_ports[i].device->dev.platform_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 platform_device_unregister (depca_io_ports[i].device);
2105 depca_io_ports[i].device = NULL;
2106 }
2107 }
2108}
2109
2110module_init (depca_module_init);
2111module_exit (depca_module_exit);