1 |
199 |
simons |
/* 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
|
7 |
|
|
and
|
8 |
|
|
United States Government
|
9 |
|
|
(as represented by the Director, National Security Agency).
|
10 |
|
|
|
11 |
|
|
Copyright 1995 Digital Equipment Corporation.
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
This software may be used and distributed according to the terms of
|
15 |
|
|
the GNU 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
|
64 |
|
|
|
65 |
|
|
|
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]
|
138 |
|
|
6) run the net startup bits for your eth?? interface manually
|
139 |
|
|
(usually /etc/rc.inet[12] at boot time).
|
140 |
|
|
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 |
|
|
|
145 |
|
|
To unload a module, turn off the associated interface
|
146 |
|
|
'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
|
151 |
|
|
option will not work with kernel built-in depca's.
|
152 |
|
|
|
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
|
160 |
|
|
fully stress-tested).
|
161 |
|
|
|
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
|
179 |
|
|
|
180 |
|
|
0.1 25-jan-94 Initial writing.
|
181 |
|
|
0.2 27-jan-94 Added LANCE TX hardware buffer chaining.
|
182 |
|
|
0.3 1-feb-94 Added multiple DEPCA support.
|
183 |
|
|
0.31 4-feb-94 Added DE202 recognition.
|
184 |
|
|
0.32 19-feb-94 Tidy up. Improve multi-DEPCA support.
|
185 |
|
|
0.33 25-feb-94 Fix DEPCA ethernet ROM counter enable.
|
186 |
|
|
Add jabber packet fix from murf@perftech.com
|
187 |
|
|
and becker@super.org
|
188 |
|
|
0.34 7-mar-94 Fix DEPCA max network memory RAM & NICSR access.
|
189 |
|
|
0.35 8-mar-94 Added DE201 recognition. Tidied up.
|
190 |
|
|
0.351 30-apr-94 Added EISA support. Added DE422 recognition.
|
191 |
|
|
0.36 16-may-94 DE422 fix released.
|
192 |
|
|
0.37 22-jul-94 Added MODULE support
|
193 |
|
|
0.38 15-aug-94 Added DBR ROM switch in depca_close().
|
194 |
|
|
Multi DEPCA bug fix.
|
195 |
|
|
0.38axp 15-sep-94 Special version for Alpha AXP Linux V1.0.
|
196 |
|
|
0.381 12-dec-94 Added DE101 recognition, fix multicast bug.
|
197 |
|
|
0.382 9-feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
|
198 |
|
|
0.383 22-feb-95 Fix for conflict with VESA SCSI reported by
|
199 |
|
|
<stromain@alf.dec.com>
|
200 |
|
|
0.384 17-mar-95 Fix a ring full bug reported by <bkm@star.rl.ac.uk>
|
201 |
|
|
0.385 3-apr-95 Fix a recognition bug reported by
|
202 |
|
|
<ryan.niemi@lastfrontier.com>
|
203 |
|
|
0.386 21-apr-95 Fix the last fix...sorry, must be galloping senility
|
204 |
|
|
0.40 25-May-95 Rewrite for portability & updated.
|
205 |
|
|
ALPHA support from <jestabro@amt.tay1.dec.com>
|
206 |
|
|
0.41 26-Jun-95 Added verify_area() calls in depca_ioctl() from
|
207 |
|
|
suggestion by <heiko@colossus.escape.de>
|
208 |
|
|
0.42 27-Dec-95 Add 'mem' shared memory assignment for loadable
|
209 |
|
|
modules.
|
210 |
|
|
Add 'adapter_name' for loadable modules when no PROM.
|
211 |
|
|
Both above from a suggestion by
|
212 |
|
|
<pchen@woodruffs121.residence.gatech.edu>.
|
213 |
|
|
Add new multicasting code.
|
214 |
|
|
0.421 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
|
215 |
|
|
0.422 29-Apr-96 Fix depca_hw_init() bug <jari@markkus2.fimr.fi>
|
216 |
|
|
0.423 7-Jun-96 Fix module load bug <kmg@barco.be>
|
217 |
|
|
0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
|
218 |
|
|
0.44 1-Sep-97 Fix *_probe() to test check_region() first - bug
|
219 |
|
|
reported by <mmogilvi@elbert.uccs.edu>
|
220 |
|
|
0.45 3-Nov-98 Added support for MCA EtherWORKS (DE210/DE212) cards
|
221 |
|
|
by <tymm@computer.org>
|
222 |
|
|
0.451 5-Nov-98 Fixed mca stuff cuz I'm a dummy. <tymm@computer.org>
|
223 |
|
|
|
224 |
|
|
=========================================================================
|
225 |
|
|
*/
|
226 |
|
|
|
227 |
|
|
static const char *version = "depca.c:v0.451 1998/11/14 davies@maniac.ultranet.com\n";
|
228 |
|
|
|
229 |
|
|
#include <linux/module.h>
|
230 |
|
|
|
231 |
|
|
#include <linux/kernel.h>
|
232 |
|
|
#include <linux/sched.h>
|
233 |
|
|
#include <linux/string.h>
|
234 |
|
|
#include <linux/ptrace.h>
|
235 |
|
|
#include <linux/errno.h>
|
236 |
|
|
#include <linux/ioport.h>
|
237 |
|
|
#include <linux/malloc.h>
|
238 |
|
|
#include <linux/interrupt.h>
|
239 |
|
|
#include <linux/delay.h>
|
240 |
|
|
#include <asm/segment.h>
|
241 |
|
|
#include <asm/bitops.h>
|
242 |
|
|
#include <asm/io.h>
|
243 |
|
|
#include <asm/dma.h>
|
244 |
|
|
|
245 |
|
|
#include <linux/netdevice.h>
|
246 |
|
|
#include <linux/etherdevice.h>
|
247 |
|
|
#include <linux/skbuff.h>
|
248 |
|
|
|
249 |
|
|
#include <linux/time.h>
|
250 |
|
|
#include <linux/types.h>
|
251 |
|
|
#include <linux/unistd.h>
|
252 |
|
|
#include <linux/ctype.h>
|
253 |
|
|
|
254 |
|
|
#ifdef CONFIG_MCA
|
255 |
|
|
#include <linux/mca.h>
|
256 |
|
|
#endif
|
257 |
|
|
|
258 |
|
|
#include "depca.h"
|
259 |
|
|
|
260 |
|
|
#ifdef DEPCA_DEBUG
|
261 |
|
|
static int depca_debug = DEPCA_DEBUG;
|
262 |
|
|
#else
|
263 |
|
|
static int depca_debug = 1;
|
264 |
|
|
#endif
|
265 |
|
|
|
266 |
|
|
#define DEPCA_NDA 0xffe0 /* No Device Address */
|
267 |
|
|
|
268 |
|
|
/*
|
269 |
|
|
** Ethernet PROM defines
|
270 |
|
|
*/
|
271 |
|
|
#define PROBE_LENGTH 32
|
272 |
|
|
#define ETH_PROM_SIG 0xAA5500FFUL
|
273 |
|
|
|
274 |
|
|
/*
|
275 |
|
|
** Set the number of Tx and Rx buffers. Ensure that the memory requested
|
276 |
|
|
** here is <= to the amount of shared memory set up by the board switches.
|
277 |
|
|
** The number of descriptors MUST BE A POWER OF 2.
|
278 |
|
|
**
|
279 |
|
|
** total_memory = NUM_RX_DESC*(8+RX_BUFF_SZ) + NUM_TX_DESC*(8+TX_BUFF_SZ)
|
280 |
|
|
*/
|
281 |
|
|
#define NUM_RX_DESC 8 /* Number of RX descriptors */
|
282 |
|
|
#define NUM_TX_DESC 8 /* Number of TX descriptors */
|
283 |
|
|
#define RX_BUFF_SZ 1536 /* Buffer size for each Rx buffer */
|
284 |
|
|
#define TX_BUFF_SZ 1536 /* Buffer size for each Tx buffer */
|
285 |
|
|
|
286 |
|
|
#define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */
|
287 |
|
|
#define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */
|
288 |
|
|
|
289 |
|
|
/*
|
290 |
|
|
** EISA bus defines
|
291 |
|
|
*/
|
292 |
|
|
#define DEPCA_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
|
293 |
|
|
#define MAX_EISA_SLOTS 16
|
294 |
|
|
#define EISA_SLOT_INC 0x1000
|
295 |
|
|
|
296 |
|
|
/*
|
297 |
|
|
** ISA Bus defines
|
298 |
|
|
*/
|
299 |
|
|
#define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
|
300 |
|
|
#define DEPCA_IO_PORTS {0x300, 0x200, 0}
|
301 |
|
|
#define DEPCA_TOTAL_SIZE 0x10
|
302 |
|
|
static short mem_chkd = 0;
|
303 |
|
|
|
304 |
|
|
/*
|
305 |
|
|
** Adapter ID for the MCA EtherWORKS DE210/212 adapter
|
306 |
|
|
*/
|
307 |
|
|
#define DE212_ID 0x6def
|
308 |
|
|
|
309 |
|
|
/*
|
310 |
|
|
** Name <-> Adapter mapping
|
311 |
|
|
*/
|
312 |
|
|
#define DEPCA_SIGNATURE {"DEPCA",\
|
313 |
|
|
"DE100","DE101",\
|
314 |
|
|
"DE200","DE201","DE202",\
|
315 |
|
|
"DE210","DE212",\
|
316 |
|
|
"DE422",\
|
317 |
|
|
""}
|
318 |
|
|
static enum {DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown} adapter;
|
319 |
|
|
|
320 |
|
|
/*
|
321 |
|
|
** Miscellaneous info...
|
322 |
|
|
*/
|
323 |
|
|
#define DEPCA_STRLEN 16
|
324 |
|
|
#define MAX_NUM_DEPCAS 2
|
325 |
|
|
|
326 |
|
|
/*
|
327 |
|
|
** Memory Alignment. Each descriptor is 4 longwords long. To force a
|
328 |
|
|
** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
|
329 |
|
|
** DESC_ALIGN. ALIGN aligns the start address of the private memory area
|
330 |
|
|
** and hence the RX descriptor ring's first entry.
|
331 |
|
|
*/
|
332 |
|
|
#define ALIGN4 ((u_long)4 - 1) /* 1 longword align */
|
333 |
|
|
#define ALIGN8 ((u_long)8 - 1) /* 2 longword (quadword) align */
|
334 |
|
|
#define ALIGN ALIGN8 /* Keep the LANCE happy... */
|
335 |
|
|
|
336 |
|
|
/*
|
337 |
|
|
** The DEPCA Rx and Tx ring descriptors.
|
338 |
|
|
*/
|
339 |
|
|
struct depca_rx_desc {
|
340 |
|
|
volatile s32 base;
|
341 |
|
|
s16 buf_length; /* This length is negative 2's complement! */
|
342 |
|
|
s16 msg_length; /* This length is "normal". */
|
343 |
|
|
};
|
344 |
|
|
|
345 |
|
|
struct depca_tx_desc {
|
346 |
|
|
volatile s32 base;
|
347 |
|
|
s16 length; /* This length is negative 2's complement! */
|
348 |
|
|
s16 misc; /* Errors and TDR info */
|
349 |
|
|
};
|
350 |
|
|
|
351 |
|
|
#define LA_MASK 0x0000ffff /* LANCE address mask for mapping network RAM
|
352 |
|
|
to LANCE memory address space */
|
353 |
|
|
|
354 |
|
|
/*
|
355 |
|
|
** The Lance initialization block, described in databook, in common memory.
|
356 |
|
|
*/
|
357 |
|
|
struct depca_init {
|
358 |
|
|
u16 mode; /* Mode register */
|
359 |
|
|
u8 phys_addr[ETH_ALEN]; /* Physical ethernet address */
|
360 |
|
|
u8 mcast_table[8]; /* Multicast Hash Table. */
|
361 |
|
|
u32 rx_ring; /* Rx ring base pointer & ring length */
|
362 |
|
|
u32 tx_ring; /* Tx ring base pointer & ring length */
|
363 |
|
|
};
|
364 |
|
|
|
365 |
|
|
#define DEPCA_PKT_STAT_SZ 16
|
366 |
|
|
#define DEPCA_PKT_BIN_SZ 128 /* Should be >=100 unless you
|
367 |
|
|
increase DEPCA_PKT_STAT_SZ */
|
368 |
|
|
struct depca_private {
|
369 |
|
|
char devname[DEPCA_STRLEN]; /* Device Product String */
|
370 |
|
|
char adapter_name[DEPCA_STRLEN];/* /proc/ioports string */
|
371 |
|
|
char adapter; /* Adapter type */
|
372 |
|
|
char mca_slot; /* MCA slot, if MCA else -1 */ struct depca_rx_desc *rx_ring; /* Pointer to start of RX descriptor ring */
|
373 |
|
|
struct depca_tx_desc *tx_ring; /* Pointer to start of TX descriptor ring */
|
374 |
|
|
struct depca_init init_block;/* Shadow Initialization block */
|
375 |
|
|
char *rx_memcpy[NUM_RX_DESC]; /* CPU virt address of sh'd memory buffs */
|
376 |
|
|
char *tx_memcpy[NUM_TX_DESC]; /* CPU virt address of sh'd memory buffs */
|
377 |
|
|
u_long bus_offset; /* (E)ISA bus address offset vs LANCE */
|
378 |
|
|
u_long sh_mem; /* Physical start addr of shared mem area */
|
379 |
|
|
u_long dma_buffs; /* LANCE Rx and Tx buffers start address. */
|
380 |
|
|
int rx_new, tx_new; /* The next free ring entry */
|
381 |
|
|
int rx_old, tx_old; /* The ring entries to be free()ed. */
|
382 |
|
|
struct enet_statistics stats;
|
383 |
|
|
struct { /* Private stats counters */
|
384 |
|
|
u32 bins[DEPCA_PKT_STAT_SZ];
|
385 |
|
|
u32 unicast;
|
386 |
|
|
u32 multicast;
|
387 |
|
|
u32 broadcast;
|
388 |
|
|
u32 excessive_collisions;
|
389 |
|
|
u32 tx_underruns;
|
390 |
|
|
u32 excessive_underruns;
|
391 |
|
|
} pktStats;
|
392 |
|
|
int txRingMask; /* TX ring mask */
|
393 |
|
|
int rxRingMask; /* RX ring mask */
|
394 |
|
|
s32 rx_rlen; /* log2(rxRingMask+1) for the descriptors */
|
395 |
|
|
s32 tx_rlen; /* log2(txRingMask+1) for the descriptors */
|
396 |
|
|
};
|
397 |
|
|
|
398 |
|
|
/*
|
399 |
|
|
** The transmit ring full condition is described by the tx_old and tx_new
|
400 |
|
|
** pointers by:
|
401 |
|
|
** tx_old = tx_new Empty ring
|
402 |
|
|
** tx_old = tx_new+1 Full ring
|
403 |
|
|
** tx_old+txRingMask = tx_new Full ring (wrapped condition)
|
404 |
|
|
*/
|
405 |
|
|
#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
|
406 |
|
|
lp->tx_old+lp->txRingMask-lp->tx_new:\
|
407 |
|
|
lp->tx_old -lp->tx_new-1)
|
408 |
|
|
|
409 |
|
|
/*
|
410 |
|
|
** Public Functions
|
411 |
|
|
*/
|
412 |
|
|
static int depca_open(struct device *dev);
|
413 |
|
|
static int depca_start_xmit(struct sk_buff *skb, struct device *dev);
|
414 |
|
|
static void depca_interrupt(int irq, void *dev_id, struct pt_regs * regs);
|
415 |
|
|
static int depca_close(struct device *dev);
|
416 |
|
|
static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd);
|
417 |
|
|
static struct enet_statistics *depca_get_stats(struct device *dev);
|
418 |
|
|
static void set_multicast_list(struct device *dev);
|
419 |
|
|
|
420 |
|
|
/*
|
421 |
|
|
** Private functions
|
422 |
|
|
*/
|
423 |
|
|
static int depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot);
|
424 |
|
|
static void depca_init_ring(struct device *dev);
|
425 |
|
|
static int depca_rx(struct device *dev);
|
426 |
|
|
static int depca_tx(struct device *dev);
|
427 |
|
|
|
428 |
|
|
static void LoadCSRs(struct device *dev);
|
429 |
|
|
static int InitRestartDepca(struct device *dev);
|
430 |
|
|
static void DepcaSignature(char *name, u_long paddr);
|
431 |
|
|
static int DevicePresent(u_long ioaddr);
|
432 |
|
|
static int get_hw_addr(struct device *dev);
|
433 |
|
|
static int EISA_signature(char *name, s32 eisa_id);
|
434 |
|
|
static void SetMulticastFilter(struct device *dev);
|
435 |
|
|
static void isa_probe(struct device *dev, u_long iobase);
|
436 |
|
|
static void eisa_probe(struct device *dev, u_long iobase);
|
437 |
|
|
#ifdef CONFIG_MCA
|
438 |
|
|
static void mca_probe(struct device *dev, u_long iobase);
|
439 |
|
|
#endif
|
440 |
|
|
static struct device *alloc_device(struct device *dev, u_long iobase);
|
441 |
|
|
static int depca_dev_index(char *s);
|
442 |
|
|
static struct device *insert_device(struct device *dev, u_long iobase, int (*init)(struct device *));
|
443 |
|
|
static int load_packet(struct device *dev, struct sk_buff *skb);
|
444 |
|
|
static void depca_dbg_open(struct device *dev);
|
445 |
|
|
|
446 |
|
|
#ifdef MODULE
|
447 |
|
|
int init_module(void);
|
448 |
|
|
void cleanup_module(void);
|
449 |
|
|
static int autoprobed = 1, loading_module = 1;
|
450 |
|
|
# else
|
451 |
|
|
static u_char de1xx_irq[] = {2,3,4,5,7,9,0};
|
452 |
|
|
static u_char de2xx_irq[] = {5,9,10,11,15,0};
|
453 |
|
|
static u_char de422_irq[] = {5,9,10,11,0};
|
454 |
|
|
static u_char *depca_irq;
|
455 |
|
|
static int autoprobed = 0, loading_module = 0;
|
456 |
|
|
#endif /* MODULE */
|
457 |
|
|
|
458 |
|
|
static char name[DEPCA_STRLEN];
|
459 |
|
|
static int num_depcas = 0, num_eth = 0;
|
460 |
|
|
static int mem=0; /* For loadable module assignment
|
461 |
|
|
use insmod mem=0x????? .... */
|
462 |
|
|
static char *adapter_name = '\0'; /* If no PROM when loadable module
|
463 |
|
|
use insmod adapter_name=DE??? ...
|
464 |
|
|
*/
|
465 |
|
|
/*
|
466 |
|
|
** Miscellaneous defines...
|
467 |
|
|
*/
|
468 |
|
|
#define STOP_DEPCA \
|
469 |
|
|
outw(CSR0, DEPCA_ADDR);\
|
470 |
|
|
outw(STOP, DEPCA_DATA)
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
int
|
475 |
|
|
depca_probe(struct device *dev)
|
476 |
|
|
{
|
477 |
|
|
int tmp = num_depcas, status = -ENODEV;
|
478 |
|
|
u_long iobase = dev->base_addr;
|
479 |
|
|
|
480 |
|
|
if ((iobase == 0) && loading_module){
|
481 |
|
|
printk("Autoprobing is not supported when loading a module based driver.\n");
|
482 |
|
|
status = -EIO;
|
483 |
|
|
} else {
|
484 |
|
|
#ifdef CONFIG_MCA
|
485 |
|
|
mca_probe(dev, iobase);
|
486 |
|
|
#endif
|
487 |
|
|
isa_probe(dev, iobase);
|
488 |
|
|
eisa_probe(dev, iobase);
|
489 |
|
|
|
490 |
|
|
if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
|
491 |
|
|
printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name,
|
492 |
|
|
iobase);
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
/*
|
496 |
|
|
** Walk the device list to check that at least one device
|
497 |
|
|
** initialised OK
|
498 |
|
|
*/
|
499 |
|
|
for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
|
500 |
|
|
|
501 |
|
|
if (dev->priv) status = 0;
|
502 |
|
|
if (iobase == 0) autoprobed = 1;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
return status;
|
506 |
|
|
}
|
507 |
|
|
|
508 |
|
|
static int
|
509 |
|
|
depca_hw_init(struct device *dev, u_long ioaddr, int mca_slot)
|
510 |
|
|
{
|
511 |
|
|
struct depca_private *lp;
|
512 |
|
|
int i, j, offset, netRAM, mem_len, status=0;
|
513 |
|
|
s16 nicsr;
|
514 |
|
|
u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
|
515 |
|
|
|
516 |
|
|
STOP_DEPCA;
|
517 |
|
|
|
518 |
|
|
nicsr = inb(DEPCA_NICSR);
|
519 |
|
|
nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
|
520 |
|
|
outb(nicsr, DEPCA_NICSR);
|
521 |
|
|
|
522 |
|
|
if (inw(DEPCA_DATA) == STOP) {
|
523 |
|
|
do {
|
524 |
|
|
strcpy(name, (adapter_name ? adapter_name : ""));
|
525 |
|
|
mem_start = (mem ? mem & 0xf0000 : mem_base[mem_chkd++]);
|
526 |
|
|
DepcaSignature(name, mem_start);
|
527 |
|
|
} while (!mem && mem_base[mem_chkd] && (adapter == unknown));
|
528 |
|
|
|
529 |
|
|
if ((adapter != unknown) && mem_start) { /* found a DEPCA device */
|
530 |
|
|
dev->base_addr = ioaddr;
|
531 |
|
|
|
532 |
|
|
if (mca_slot != -1) {
|
533 |
|
|
printk("%s: %s at 0x%04lx (MCA slot %d)", dev->name, name,
|
534 |
|
|
ioaddr, mca_slot);
|
535 |
|
|
} else if ((ioaddr & 0x0fff) == DEPCA_EISA_IO_PORTS) { /* EISA slot address */
|
536 |
|
|
printk("%s: %s at 0x%04lx (EISA slot %d)",
|
537 |
|
|
dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f));
|
538 |
|
|
} else { /* ISA port address */
|
539 |
|
|
printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
|
540 |
|
|
}
|
541 |
|
|
|
542 |
|
|
printk(", h/w address ");
|
543 |
|
|
status = get_hw_addr(dev);
|
544 |
|
|
for (i=0; i<ETH_ALEN - 1; i++) { /* get the ethernet address */
|
545 |
|
|
printk("%2.2x:", dev->dev_addr[i]);
|
546 |
|
|
}
|
547 |
|
|
printk("%2.2x", dev->dev_addr[i]);
|
548 |
|
|
|
549 |
|
|
if (status == 0) {
|
550 |
|
|
/* Set up the maximum amount of network RAM(kB) */
|
551 |
|
|
netRAM = ((adapter != DEPCA) ? 64 : 48);
|
552 |
|
|
if ((nicsr & _128KB) && (adapter == de422)) netRAM = 128;
|
553 |
|
|
offset = 0x0000;
|
554 |
|
|
|
555 |
|
|
/* Shared Memory Base Address */
|
556 |
|
|
if (nicsr & BUF) {
|
557 |
|
|
offset = 0x8000; /* 32kbyte RAM offset*/
|
558 |
|
|
nicsr &= ~BS; /* DEPCA RAM in top 32k */
|
559 |
|
|
netRAM -= 32;
|
560 |
|
|
}
|
561 |
|
|
mem_start += offset; /* (E)ISA start address */
|
562 |
|
|
if ((mem_len = (NUM_RX_DESC*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ) +
|
563 |
|
|
NUM_TX_DESC*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ) +
|
564 |
|
|
sizeof(struct depca_init))) <=
|
565 |
|
|
(netRAM<<10)) {
|
566 |
|
|
printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
|
567 |
|
|
|
568 |
|
|
/* Enable the shadow RAM. */
|
569 |
|
|
if (adapter != DEPCA) {
|
570 |
|
|
nicsr |= SHE;
|
571 |
|
|
outb(nicsr, DEPCA_NICSR);
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
/* Define the device private memory */
|
575 |
|
|
dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
|
576 |
|
|
if (dev->priv == NULL)
|
577 |
|
|
return -ENOMEM;
|
578 |
|
|
lp = (struct depca_private *)dev->priv;
|
579 |
|
|
memset((char *)dev->priv, 0, sizeof(struct depca_private));
|
580 |
|
|
lp->adapter = adapter;
|
581 |
|
|
lp->mca_slot = mca_slot;
|
582 |
|
|
sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
|
583 |
|
|
request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name);
|
584 |
|
|
|
585 |
|
|
/* Initialisation Block */
|
586 |
|
|
lp->sh_mem = mem_start;
|
587 |
|
|
mem_start += sizeof(struct depca_init);
|
588 |
|
|
|
589 |
|
|
/* Tx & Rx descriptors (aligned to a quadword boundary) */
|
590 |
|
|
mem_start = (mem_start + ALIGN) & ~ALIGN;
|
591 |
|
|
lp->rx_ring = (struct depca_rx_desc *)mem_start;
|
592 |
|
|
|
593 |
|
|
mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
|
594 |
|
|
lp->tx_ring = (struct depca_tx_desc *)mem_start;
|
595 |
|
|
|
596 |
|
|
mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
|
597 |
|
|
lp->bus_offset = mem_start & 0x00ff0000;
|
598 |
|
|
mem_start &= LA_MASK; /* LANCE re-mapped start address */
|
599 |
|
|
|
600 |
|
|
lp->dma_buffs = mem_start;
|
601 |
|
|
|
602 |
|
|
/* Finish initialising the ring information. */
|
603 |
|
|
lp->rxRingMask = NUM_RX_DESC - 1;
|
604 |
|
|
lp->txRingMask = NUM_TX_DESC - 1;
|
605 |
|
|
|
606 |
|
|
/* Calculate Tx/Rx RLEN size for the descriptors. */
|
607 |
|
|
for (i=0, j = lp->rxRingMask; j>0; i++) {
|
608 |
|
|
j >>= 1;
|
609 |
|
|
}
|
610 |
|
|
lp->rx_rlen = (s32)(i << 29);
|
611 |
|
|
for (i=0, j = lp->txRingMask; j>0; i++) {
|
612 |
|
|
j >>= 1;
|
613 |
|
|
}
|
614 |
|
|
lp->tx_rlen = (s32)(i << 29);
|
615 |
|
|
|
616 |
|
|
/* Load the initialisation block */
|
617 |
|
|
depca_init_ring(dev);
|
618 |
|
|
|
619 |
|
|
/* Initialise the control and status registers */
|
620 |
|
|
LoadCSRs(dev);
|
621 |
|
|
|
622 |
|
|
/* Enable DEPCA board interrupts for autoprobing */
|
623 |
|
|
nicsr = ((nicsr & ~IM)|IEN);
|
624 |
|
|
outb(nicsr, DEPCA_NICSR);
|
625 |
|
|
|
626 |
|
|
/* To auto-IRQ we enable the initialization-done and DMA err,
|
627 |
|
|
interrupts. For now we will always get a DMA error. */
|
628 |
|
|
if (dev->irq < 2) {
|
629 |
|
|
#ifndef MODULE
|
630 |
|
|
unsigned char irqnum;
|
631 |
|
|
autoirq_setup(0);
|
632 |
|
|
|
633 |
|
|
/* Assign the correct irq list */
|
634 |
|
|
switch (lp->adapter) {
|
635 |
|
|
case DEPCA:
|
636 |
|
|
case de100:
|
637 |
|
|
case de101:
|
638 |
|
|
depca_irq = de1xx_irq;
|
639 |
|
|
break;
|
640 |
|
|
case de200:
|
641 |
|
|
case de201:
|
642 |
|
|
case de202:
|
643 |
|
|
case de210:
|
644 |
|
|
case de212:
|
645 |
|
|
depca_irq = de2xx_irq;
|
646 |
|
|
break;
|
647 |
|
|
case de422:
|
648 |
|
|
depca_irq = de422_irq;
|
649 |
|
|
break;
|
650 |
|
|
}
|
651 |
|
|
|
652 |
|
|
/* Trigger an initialization just for the interrupt. */
|
653 |
|
|
outw(INEA | INIT, DEPCA_DATA);
|
654 |
|
|
|
655 |
|
|
irqnum = autoirq_report(1);
|
656 |
|
|
if (!irqnum) {
|
657 |
|
|
printk(" and failed to detect IRQ line.\n");
|
658 |
|
|
status = -ENXIO;
|
659 |
|
|
} else {
|
660 |
|
|
for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) {
|
661 |
|
|
if (irqnum == depca_irq[i]) {
|
662 |
|
|
dev->irq = irqnum;
|
663 |
|
|
printk(" and uses IRQ%d.\n", dev->irq);
|
664 |
|
|
}
|
665 |
|
|
}
|
666 |
|
|
|
667 |
|
|
if (!dev->irq) {
|
668 |
|
|
printk(" but incorrect IRQ line detected.\n");
|
669 |
|
|
status = -ENXIO;
|
670 |
|
|
}
|
671 |
|
|
}
|
672 |
|
|
#endif /* MODULE */
|
673 |
|
|
} else {
|
674 |
|
|
printk(" and assigned IRQ%d.\n", dev->irq);
|
675 |
|
|
}
|
676 |
|
|
if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE);
|
677 |
|
|
} else {
|
678 |
|
|
printk(",\n requests %dkB RAM: only %dkB is available!\n",
|
679 |
|
|
(mem_len>>10), netRAM);
|
680 |
|
|
status = -ENXIO;
|
681 |
|
|
}
|
682 |
|
|
} else {
|
683 |
|
|
printk(" which has an Ethernet PROM CRC error.\n");
|
684 |
|
|
status = -ENXIO;
|
685 |
|
|
}
|
686 |
|
|
} else {
|
687 |
|
|
status = -ENXIO;
|
688 |
|
|
}
|
689 |
|
|
if (!status) {
|
690 |
|
|
if (depca_debug > 1) {
|
691 |
|
|
printk(version);
|
692 |
|
|
}
|
693 |
|
|
|
694 |
|
|
/* The DEPCA-specific entries in the device structure. */
|
695 |
|
|
dev->open = &depca_open;
|
696 |
|
|
dev->hard_start_xmit = &depca_start_xmit;
|
697 |
|
|
dev->stop = &depca_close;
|
698 |
|
|
dev->get_stats = &depca_get_stats;
|
699 |
|
|
dev->set_multicast_list = &set_multicast_list;
|
700 |
|
|
dev->do_ioctl = &depca_ioctl;
|
701 |
|
|
|
702 |
|
|
dev->mem_start = 0;
|
703 |
|
|
|
704 |
|
|
/* Fill in the generic field of the device structure. */
|
705 |
|
|
ether_setup(dev);
|
706 |
|
|
} else { /* Incorrectly initialised hardware */
|
707 |
|
|
if (dev->priv) {
|
708 |
|
|
kfree_s(dev->priv, sizeof(struct depca_private));
|
709 |
|
|
dev->priv = NULL;
|
710 |
|
|
}
|
711 |
|
|
}
|
712 |
|
|
} else {
|
713 |
|
|
status = -ENXIO;
|
714 |
|
|
}
|
715 |
|
|
|
716 |
|
|
return status;
|
717 |
|
|
}
|
718 |
|
|
|
719 |
|
|
|
720 |
|
|
static int
|
721 |
|
|
depca_open(struct device *dev)
|
722 |
|
|
{
|
723 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
724 |
|
|
u_long ioaddr = dev->base_addr;
|
725 |
|
|
s16 nicsr;
|
726 |
|
|
int status = 0;
|
727 |
|
|
|
728 |
|
|
irq2dev_map[dev->irq] = dev;
|
729 |
|
|
STOP_DEPCA;
|
730 |
|
|
nicsr = inb(DEPCA_NICSR);
|
731 |
|
|
|
732 |
|
|
/* Make sure the shadow RAM is enabled */
|
733 |
|
|
if (adapter != DEPCA) {
|
734 |
|
|
nicsr |= SHE;
|
735 |
|
|
outb(nicsr, DEPCA_NICSR);
|
736 |
|
|
}
|
737 |
|
|
|
738 |
|
|
/* Re-initialize the DEPCA... */
|
739 |
|
|
depca_init_ring(dev);
|
740 |
|
|
LoadCSRs(dev);
|
741 |
|
|
|
742 |
|
|
depca_dbg_open(dev);
|
743 |
|
|
|
744 |
|
|
if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, NULL)) {
|
745 |
|
|
printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
|
746 |
|
|
status = -EAGAIN;
|
747 |
|
|
} else {
|
748 |
|
|
|
749 |
|
|
/* Enable DEPCA board interrupts and turn off LED */
|
750 |
|
|
nicsr = ((nicsr & ~IM & ~LED)|IEN);
|
751 |
|
|
outb(nicsr, DEPCA_NICSR);
|
752 |
|
|
outw(CSR0,DEPCA_ADDR);
|
753 |
|
|
|
754 |
|
|
dev->tbusy = 0;
|
755 |
|
|
dev->interrupt = 0;
|
756 |
|
|
dev->start = 1;
|
757 |
|
|
|
758 |
|
|
status = InitRestartDepca(dev);
|
759 |
|
|
|
760 |
|
|
if (depca_debug > 1){
|
761 |
|
|
printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
|
762 |
|
|
printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
|
763 |
|
|
}
|
764 |
|
|
}
|
765 |
|
|
|
766 |
|
|
MOD_INC_USE_COUNT;
|
767 |
|
|
|
768 |
|
|
return status;
|
769 |
|
|
}
|
770 |
|
|
|
771 |
|
|
/* Initialize the lance Rx and Tx descriptor rings. */
|
772 |
|
|
static void
|
773 |
|
|
depca_init_ring(struct device *dev)
|
774 |
|
|
{
|
775 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
776 |
|
|
u_int i;
|
777 |
|
|
u_long p;
|
778 |
|
|
|
779 |
|
|
/* Lock out other processes whilst setting up the hardware */
|
780 |
|
|
set_bit(0, (void *)&dev->tbusy);
|
781 |
|
|
|
782 |
|
|
lp->rx_new = lp->tx_new = 0;
|
783 |
|
|
lp->rx_old = lp->tx_old = 0;
|
784 |
|
|
|
785 |
|
|
/* Initialize the base addresses and length of each buffer in the ring */
|
786 |
|
|
for (i = 0; i <= lp->rxRingMask; i++) {
|
787 |
|
|
writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base);
|
788 |
|
|
writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
|
789 |
|
|
lp->rx_memcpy[i]=(char *)(p+lp->bus_offset);
|
790 |
|
|
}
|
791 |
|
|
for (i = 0; i <= lp->txRingMask; i++) {
|
792 |
|
|
writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,
|
793 |
|
|
&lp->tx_ring[i].base);
|
794 |
|
|
lp->tx_memcpy[i]=(char *)(p+lp->bus_offset);
|
795 |
|
|
}
|
796 |
|
|
|
797 |
|
|
/* Set up the initialization block */
|
798 |
|
|
lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK) | lp->rx_rlen;
|
799 |
|
|
lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK) | lp->tx_rlen;
|
800 |
|
|
|
801 |
|
|
SetMulticastFilter(dev);
|
802 |
|
|
|
803 |
|
|
for (i = 0; i < ETH_ALEN; i++) {
|
804 |
|
|
lp->init_block.phys_addr[i] = dev->dev_addr[i];
|
805 |
|
|
}
|
806 |
|
|
|
807 |
|
|
lp->init_block.mode = 0x0000; /* Enable the Tx and Rx */
|
808 |
|
|
|
809 |
|
|
return;
|
810 |
|
|
}
|
811 |
|
|
|
812 |
|
|
/*
|
813 |
|
|
** Writes a socket buffer to TX descriptor ring and starts transmission
|
814 |
|
|
*/
|
815 |
|
|
static int
|
816 |
|
|
depca_start_xmit(struct sk_buff *skb, struct device *dev)
|
817 |
|
|
{
|
818 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
819 |
|
|
u_long ioaddr = dev->base_addr;
|
820 |
|
|
int status = 0;
|
821 |
|
|
|
822 |
|
|
/* Transmitter timeout, serious problems. */
|
823 |
|
|
if (dev->tbusy) {
|
824 |
|
|
int tickssofar = jiffies - dev->trans_start;
|
825 |
|
|
if (tickssofar < 1*HZ) {
|
826 |
|
|
status = -1;
|
827 |
|
|
} else {
|
828 |
|
|
printk("%s: transmit timed out, status %04x, resetting.\n",
|
829 |
|
|
dev->name, inw(DEPCA_DATA));
|
830 |
|
|
|
831 |
|
|
STOP_DEPCA;
|
832 |
|
|
depca_init_ring(dev);
|
833 |
|
|
LoadCSRs(dev);
|
834 |
|
|
dev->interrupt = UNMASK_INTERRUPTS;
|
835 |
|
|
dev->start = 1;
|
836 |
|
|
dev->tbusy=0;
|
837 |
|
|
dev->trans_start = jiffies;
|
838 |
|
|
InitRestartDepca(dev);
|
839 |
|
|
dev_kfree_skb(skb, FREE_WRITE);
|
840 |
|
|
}
|
841 |
|
|
return status;
|
842 |
|
|
} else if (skb == NULL) {
|
843 |
|
|
dev_tint(dev);
|
844 |
|
|
} else if (skb->len > 0) {
|
845 |
|
|
/* Enforce 1 process per h/w access */
|
846 |
|
|
if (set_bit(0, (void*)&dev->tbusy) != 0) {
|
847 |
|
|
printk("%s: Transmitter access conflict.\n", dev->name);
|
848 |
|
|
status = -1;
|
849 |
|
|
} else {
|
850 |
|
|
if (TX_BUFFS_AVAIL) { /* Fill in a Tx ring entry */
|
851 |
|
|
status = load_packet(dev, skb);
|
852 |
|
|
|
853 |
|
|
if (!status) {
|
854 |
|
|
/* Trigger an immediate send demand. */
|
855 |
|
|
outw(CSR0, DEPCA_ADDR);
|
856 |
|
|
outw(INEA | TDMD, DEPCA_DATA);
|
857 |
|
|
|
858 |
|
|
dev->trans_start = jiffies;
|
859 |
|
|
dev_kfree_skb(skb, FREE_WRITE);
|
860 |
|
|
}
|
861 |
|
|
if (TX_BUFFS_AVAIL) {
|
862 |
|
|
dev->tbusy=0;
|
863 |
|
|
}
|
864 |
|
|
} else {
|
865 |
|
|
status = -1;
|
866 |
|
|
}
|
867 |
|
|
}
|
868 |
|
|
}
|
869 |
|
|
|
870 |
|
|
return status;
|
871 |
|
|
}
|
872 |
|
|
|
873 |
|
|
/*
|
874 |
|
|
** The DEPCA interrupt handler.
|
875 |
|
|
*/
|
876 |
|
|
static void
|
877 |
|
|
depca_interrupt(int irq, void *dev_id, struct pt_regs * regs)
|
878 |
|
|
{
|
879 |
|
|
struct device *dev = (struct device *)(irq2dev_map[irq]);
|
880 |
|
|
struct depca_private *lp;
|
881 |
|
|
s16 csr0, nicsr;
|
882 |
|
|
u_long ioaddr;
|
883 |
|
|
|
884 |
|
|
if (dev == NULL) {
|
885 |
|
|
printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
|
886 |
|
|
} else {
|
887 |
|
|
lp = (struct depca_private *)dev->priv;
|
888 |
|
|
ioaddr = dev->base_addr;
|
889 |
|
|
|
890 |
|
|
if (dev->interrupt)
|
891 |
|
|
printk("%s: Re-entering the interrupt handler.\n", dev->name);
|
892 |
|
|
|
893 |
|
|
dev->interrupt = MASK_INTERRUPTS;
|
894 |
|
|
|
895 |
|
|
/* mask the DEPCA board interrupts and turn on the LED */
|
896 |
|
|
nicsr = inb(DEPCA_NICSR);
|
897 |
|
|
nicsr |= (IM|LED);
|
898 |
|
|
outb(nicsr, DEPCA_NICSR);
|
899 |
|
|
|
900 |
|
|
outw(CSR0, DEPCA_ADDR);
|
901 |
|
|
csr0 = inw(DEPCA_DATA);
|
902 |
|
|
|
903 |
|
|
/* Acknowledge all of the current interrupt sources ASAP. */
|
904 |
|
|
outw(csr0 & INTE, DEPCA_DATA);
|
905 |
|
|
|
906 |
|
|
if (csr0 & RINT) /* Rx interrupt (packet arrived) */
|
907 |
|
|
depca_rx(dev);
|
908 |
|
|
|
909 |
|
|
if (csr0 & TINT) /* Tx interrupt (packet sent) */
|
910 |
|
|
depca_tx(dev);
|
911 |
|
|
|
912 |
|
|
if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) { /* any resources available? */
|
913 |
|
|
dev->tbusy = 0; /* clear TX busy flag */
|
914 |
|
|
mark_bh(NET_BH);
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
/* Unmask the DEPCA board interrupts and turn off the LED */
|
918 |
|
|
nicsr = (nicsr & ~IM & ~LED);
|
919 |
|
|
outb(nicsr, DEPCA_NICSR);
|
920 |
|
|
|
921 |
|
|
dev->interrupt = UNMASK_INTERRUPTS;
|
922 |
|
|
}
|
923 |
|
|
|
924 |
|
|
return;
|
925 |
|
|
}
|
926 |
|
|
|
927 |
|
|
static int
|
928 |
|
|
depca_rx(struct device *dev)
|
929 |
|
|
{
|
930 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
931 |
|
|
int i, entry;
|
932 |
|
|
s32 status;
|
933 |
|
|
|
934 |
|
|
for (entry=lp->rx_new;
|
935 |
|
|
!(readl(&lp->rx_ring[entry].base) & R_OWN);
|
936 |
|
|
entry=lp->rx_new){
|
937 |
|
|
status = readl(&lp->rx_ring[entry].base) >> 16 ;
|
938 |
|
|
if (status & R_STP) { /* Remember start of frame */
|
939 |
|
|
lp->rx_old = entry;
|
940 |
|
|
}
|
941 |
|
|
if (status & R_ENP) { /* Valid frame status */
|
942 |
|
|
if (status & R_ERR) { /* There was an error. */
|
943 |
|
|
lp->stats.rx_errors++; /* Update the error stats. */
|
944 |
|
|
if (status & R_FRAM) lp->stats.rx_frame_errors++;
|
945 |
|
|
if (status & R_OFLO) lp->stats.rx_over_errors++;
|
946 |
|
|
if (status & R_CRC) lp->stats.rx_crc_errors++;
|
947 |
|
|
if (status & R_BUFF) lp->stats.rx_fifo_errors++;
|
948 |
|
|
} else {
|
949 |
|
|
short len, pkt_len = readw(&lp->rx_ring[entry].msg_length);
|
950 |
|
|
struct sk_buff *skb;
|
951 |
|
|
|
952 |
|
|
skb = dev_alloc_skb(pkt_len+2);
|
953 |
|
|
if (skb != NULL) {
|
954 |
|
|
unsigned char *buf;
|
955 |
|
|
skb_reserve(skb,2); /* 16 byte align the IP header */
|
956 |
|
|
buf = skb_put(skb,pkt_len);
|
957 |
|
|
skb->dev = dev;
|
958 |
|
|
if (entry < lp->rx_old) { /* Wrapped buffer */
|
959 |
|
|
len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
|
960 |
|
|
memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len);
|
961 |
|
|
memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len);
|
962 |
|
|
} else { /* Linear buffer */
|
963 |
|
|
memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len);
|
964 |
|
|
}
|
965 |
|
|
|
966 |
|
|
/*
|
967 |
|
|
** Notify the upper protocol layers that there is another
|
968 |
|
|
** packet to handle
|
969 |
|
|
*/
|
970 |
|
|
skb->protocol=eth_type_trans(skb,dev);
|
971 |
|
|
netif_rx(skb);
|
972 |
|
|
|
973 |
|
|
/*
|
974 |
|
|
** Update stats
|
975 |
|
|
*/
|
976 |
|
|
lp->stats.rx_packets++;
|
977 |
|
|
for (i=1; i<DEPCA_PKT_STAT_SZ-1; i++) {
|
978 |
|
|
if (pkt_len < (i*DEPCA_PKT_BIN_SZ)) {
|
979 |
|
|
lp->pktStats.bins[i]++;
|
980 |
|
|
i = DEPCA_PKT_STAT_SZ;
|
981 |
|
|
}
|
982 |
|
|
}
|
983 |
|
|
if (buf[0] & 0x01) { /* Multicast/Broadcast */
|
984 |
|
|
if ((*(s16 *)&buf[0] == -1) &&
|
985 |
|
|
(*(s16 *)&buf[2] == -1) &&
|
986 |
|
|
(*(s16 *)&buf[4] == -1)) {
|
987 |
|
|
lp->pktStats.broadcast++;
|
988 |
|
|
} else {
|
989 |
|
|
lp->pktStats.multicast++;
|
990 |
|
|
}
|
991 |
|
|
} else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
|
992 |
|
|
(*(s16 *)&buf[2] == *(s16 *)&dev->dev_addr[2]) &&
|
993 |
|
|
(*(s16 *)&buf[4] == *(s16 *)&dev->dev_addr[4])) {
|
994 |
|
|
lp->pktStats.unicast++;
|
995 |
|
|
}
|
996 |
|
|
|
997 |
|
|
lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
|
998 |
|
|
if (lp->pktStats.bins[0] == 0) { /* Reset counters */
|
999 |
|
|
memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
|
1000 |
|
|
}
|
1001 |
|
|
} else {
|
1002 |
|
|
printk("%s: Memory squeeze, deferring packet.\n", dev->name);
|
1003 |
|
|
lp->stats.rx_dropped++; /* Really, deferred. */
|
1004 |
|
|
break;
|
1005 |
|
|
}
|
1006 |
|
|
}
|
1007 |
|
|
/* Change buffer ownership for this last frame, back to the adapter */
|
1008 |
|
|
for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
|
1009 |
|
|
writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,
|
1010 |
|
|
&lp->rx_ring[lp->rx_old].base);
|
1011 |
|
|
}
|
1012 |
|
|
writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
|
1013 |
|
|
}
|
1014 |
|
|
|
1015 |
|
|
/*
|
1016 |
|
|
** Update entry information
|
1017 |
|
|
*/
|
1018 |
|
|
lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
|
1019 |
|
|
}
|
1020 |
|
|
|
1021 |
|
|
return 0;
|
1022 |
|
|
}
|
1023 |
|
|
|
1024 |
|
|
/*
|
1025 |
|
|
** Buffer sent - check for buffer errors.
|
1026 |
|
|
*/
|
1027 |
|
|
static int
|
1028 |
|
|
depca_tx(struct device *dev)
|
1029 |
|
|
{
|
1030 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1031 |
|
|
int entry;
|
1032 |
|
|
s32 status;
|
1033 |
|
|
u_long ioaddr = dev->base_addr;
|
1034 |
|
|
|
1035 |
|
|
for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
|
1036 |
|
|
status = readl(&lp->tx_ring[entry].base) >> 16 ;
|
1037 |
|
|
|
1038 |
|
|
if (status < 0) { /* Packet not yet sent! */
|
1039 |
|
|
break;
|
1040 |
|
|
} else if (status & T_ERR) { /* An error occurred. */
|
1041 |
|
|
status = readl(&lp->tx_ring[entry].misc);
|
1042 |
|
|
lp->stats.tx_errors++;
|
1043 |
|
|
if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
|
1044 |
|
|
if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
|
1045 |
|
|
if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
|
1046 |
|
|
if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
|
1047 |
|
|
if (status & (TMD3_BUFF | TMD3_UFLO)) {
|
1048 |
|
|
/* Trigger an immediate send demand. */
|
1049 |
|
|
outw(CSR0, DEPCA_ADDR);
|
1050 |
|
|
outw(INEA | TDMD, DEPCA_DATA);
|
1051 |
|
|
}
|
1052 |
|
|
} else if (status & (T_MORE | T_ONE)) {
|
1053 |
|
|
lp->stats.collisions++;
|
1054 |
|
|
} else {
|
1055 |
|
|
lp->stats.tx_packets++;
|
1056 |
|
|
}
|
1057 |
|
|
|
1058 |
|
|
/* Update all the pointers */
|
1059 |
|
|
lp->tx_old = (++lp->tx_old) & lp->txRingMask;
|
1060 |
|
|
}
|
1061 |
|
|
|
1062 |
|
|
return 0;
|
1063 |
|
|
}
|
1064 |
|
|
|
1065 |
|
|
static int
|
1066 |
|
|
depca_close(struct device *dev)
|
1067 |
|
|
{
|
1068 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1069 |
|
|
s16 nicsr;
|
1070 |
|
|
u_long ioaddr = dev->base_addr;
|
1071 |
|
|
|
1072 |
|
|
dev->start = 0;
|
1073 |
|
|
dev->tbusy = 1;
|
1074 |
|
|
|
1075 |
|
|
outw(CSR0, DEPCA_ADDR);
|
1076 |
|
|
|
1077 |
|
|
if (depca_debug > 1) {
|
1078 |
|
|
printk("%s: Shutting down ethercard, status was %2.2x.\n",
|
1079 |
|
|
dev->name, inw(DEPCA_DATA));
|
1080 |
|
|
}
|
1081 |
|
|
|
1082 |
|
|
/*
|
1083 |
|
|
** We stop the DEPCA here -- it occasionally polls
|
1084 |
|
|
** memory if we don't.
|
1085 |
|
|
*/
|
1086 |
|
|
outw(STOP, DEPCA_DATA);
|
1087 |
|
|
|
1088 |
|
|
/*
|
1089 |
|
|
** Give back the ROM in case the user wants to go to DOS
|
1090 |
|
|
*/
|
1091 |
|
|
if (lp->adapter != DEPCA) {
|
1092 |
|
|
nicsr = inb(DEPCA_NICSR);
|
1093 |
|
|
nicsr &= ~SHE;
|
1094 |
|
|
outb(nicsr, DEPCA_NICSR);
|
1095 |
|
|
}
|
1096 |
|
|
|
1097 |
|
|
/*
|
1098 |
|
|
** Free the associated irq
|
1099 |
|
|
*/
|
1100 |
|
|
free_irq(dev->irq, NULL);
|
1101 |
|
|
irq2dev_map[dev->irq] = NULL;
|
1102 |
|
|
|
1103 |
|
|
MOD_DEC_USE_COUNT;
|
1104 |
|
|
|
1105 |
|
|
return 0;
|
1106 |
|
|
}
|
1107 |
|
|
|
1108 |
|
|
static void LoadCSRs(struct device *dev)
|
1109 |
|
|
{
|
1110 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1111 |
|
|
u_long ioaddr = dev->base_addr;
|
1112 |
|
|
|
1113 |
|
|
outw(CSR1, DEPCA_ADDR); /* initialisation block address LSW */
|
1114 |
|
|
outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
|
1115 |
|
|
outw(CSR2, DEPCA_ADDR); /* initialisation block address MSW */
|
1116 |
|
|
outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
|
1117 |
|
|
outw(CSR3, DEPCA_ADDR); /* ALE control */
|
1118 |
|
|
outw(ACON, DEPCA_DATA);
|
1119 |
|
|
|
1120 |
|
|
outw(CSR0, DEPCA_ADDR); /* Point back to CSR0 */
|
1121 |
|
|
|
1122 |
|
|
return;
|
1123 |
|
|
}
|
1124 |
|
|
|
1125 |
|
|
static int InitRestartDepca(struct device *dev)
|
1126 |
|
|
{
|
1127 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1128 |
|
|
u_long ioaddr = dev->base_addr;
|
1129 |
|
|
int i, status=0;
|
1130 |
|
|
|
1131 |
|
|
/* Copy the shadow init_block to shared memory */
|
1132 |
|
|
memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
|
1133 |
|
|
|
1134 |
|
|
outw(CSR0, DEPCA_ADDR); /* point back to CSR0 */
|
1135 |
|
|
outw(INIT, DEPCA_DATA); /* initialize DEPCA */
|
1136 |
|
|
|
1137 |
|
|
/* wait for lance to complete initialisation */
|
1138 |
|
|
for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
|
1139 |
|
|
|
1140 |
|
|
if (i!=100) {
|
1141 |
|
|
/* clear IDON by writing a "1", enable interrupts and start lance */
|
1142 |
|
|
outw(IDON | INEA | STRT, DEPCA_DATA);
|
1143 |
|
|
if (depca_debug > 2) {
|
1144 |
|
|
printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
|
1145 |
|
|
dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
|
1146 |
|
|
}
|
1147 |
|
|
} else {
|
1148 |
|
|
printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
|
1149 |
|
|
dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
|
1150 |
|
|
status = -1;
|
1151 |
|
|
}
|
1152 |
|
|
|
1153 |
|
|
return status;
|
1154 |
|
|
}
|
1155 |
|
|
|
1156 |
|
|
static struct enet_statistics *
|
1157 |
|
|
depca_get_stats(struct device *dev)
|
1158 |
|
|
{
|
1159 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1160 |
|
|
|
1161 |
|
|
/* Null body since there is no framing error counter */
|
1162 |
|
|
|
1163 |
|
|
return &lp->stats;
|
1164 |
|
|
}
|
1165 |
|
|
|
1166 |
|
|
/*
|
1167 |
|
|
** Set or clear the multicast filter for this adaptor.
|
1168 |
|
|
*/
|
1169 |
|
|
static void
|
1170 |
|
|
set_multicast_list(struct device *dev)
|
1171 |
|
|
{
|
1172 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1173 |
|
|
u_long ioaddr = dev->base_addr;
|
1174 |
|
|
|
1175 |
|
|
if (irq2dev_map[dev->irq] != NULL) {
|
1176 |
|
|
while(dev->tbusy); /* Stop ring access */
|
1177 |
|
|
set_bit(0, (void*)&dev->tbusy);
|
1178 |
|
|
while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
|
1179 |
|
|
|
1180 |
|
|
STOP_DEPCA; /* Temporarily stop the depca. */
|
1181 |
|
|
depca_init_ring(dev); /* Initialize the descriptor rings */
|
1182 |
|
|
|
1183 |
|
|
if (dev->flags & IFF_PROMISC) { /* Set promiscuous mode */
|
1184 |
|
|
lp->init_block.mode |= PROM;
|
1185 |
|
|
} else {
|
1186 |
|
|
SetMulticastFilter(dev);
|
1187 |
|
|
lp->init_block.mode &= ~PROM; /* Unset promiscuous mode */
|
1188 |
|
|
}
|
1189 |
|
|
|
1190 |
|
|
LoadCSRs(dev); /* Reload CSR3 */
|
1191 |
|
|
InitRestartDepca(dev); /* Resume normal operation. */
|
1192 |
|
|
dev->tbusy = 0; /* Unlock the TX ring */
|
1193 |
|
|
}
|
1194 |
|
|
}
|
1195 |
|
|
|
1196 |
|
|
/*
|
1197 |
|
|
** Calculate the hash code and update the logical address filter
|
1198 |
|
|
** from a list of ethernet multicast addresses.
|
1199 |
|
|
** Big endian crc one liner is mine, all mine, ha ha ha ha!
|
1200 |
|
|
** LANCE calculates its hash codes big endian.
|
1201 |
|
|
*/
|
1202 |
|
|
static void SetMulticastFilter(struct device *dev)
|
1203 |
|
|
{
|
1204 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1205 |
|
|
struct dev_mc_list *dmi=dev->mc_list;
|
1206 |
|
|
char *addrs;
|
1207 |
|
|
int i, j, bit, byte;
|
1208 |
|
|
u16 hashcode;
|
1209 |
|
|
s32 crc, poly = CRC_POLYNOMIAL_BE;
|
1210 |
|
|
|
1211 |
|
|
if (dev->flags & IFF_ALLMULTI) { /* Set all multicast bits */
|
1212 |
|
|
for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
|
1213 |
|
|
lp->init_block.mcast_table[i] = (char)0xff;
|
1214 |
|
|
}
|
1215 |
|
|
} else {
|
1216 |
|
|
for (i=0; i<(HASH_TABLE_LEN>>3); i++){ /* Clear the multicast table */
|
1217 |
|
|
lp->init_block.mcast_table[i]=0;
|
1218 |
|
|
}
|
1219 |
|
|
/* Add multicast addresses */
|
1220 |
|
|
for (i=0;i<dev->mc_count;i++) { /* for each address in the list */
|
1221 |
|
|
addrs=dmi->dmi_addr;
|
1222 |
|
|
dmi=dmi->next;
|
1223 |
|
|
if ((*addrs & 0x01) == 1) { /* multicast address? */
|
1224 |
|
|
crc = 0xffffffff; /* init CRC for each address */
|
1225 |
|
|
for (byte=0;byte<ETH_ALEN;byte++) {/* for each address byte */
|
1226 |
|
|
/* process each address bit */
|
1227 |
|
|
for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
|
1228 |
|
|
crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
|
1229 |
|
|
}
|
1230 |
|
|
}
|
1231 |
|
|
hashcode = (crc & 1); /* hashcode is 6 LSb of CRC ... */
|
1232 |
|
|
for (j=0;j<5;j++) { /* ... in reverse order. */
|
1233 |
|
|
hashcode = (hashcode << 1) | ((crc>>=1) & 1);
|
1234 |
|
|
}
|
1235 |
|
|
|
1236 |
|
|
|
1237 |
|
|
byte = hashcode >> 3; /* bit[3-5] -> byte in filter */
|
1238 |
|
|
bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
|
1239 |
|
|
lp->init_block.mcast_table[byte] |= bit;
|
1240 |
|
|
}
|
1241 |
|
|
}
|
1242 |
|
|
}
|
1243 |
|
|
|
1244 |
|
|
return;
|
1245 |
|
|
}
|
1246 |
|
|
|
1247 |
|
|
#ifdef CONFIG_MCA
|
1248 |
|
|
/*
|
1249 |
|
|
** Microchannel bus I/O device probe
|
1250 |
|
|
*/
|
1251 |
|
|
static void
|
1252 |
|
|
mca_probe(struct device *dev, u_long ioaddr)
|
1253 |
|
|
{
|
1254 |
|
|
unsigned char pos[2];
|
1255 |
|
|
unsigned char where;
|
1256 |
|
|
unsigned long iobase;
|
1257 |
|
|
int irq;
|
1258 |
|
|
int slot = 0;
|
1259 |
|
|
|
1260 |
|
|
/*
|
1261 |
|
|
** See if we've been here before.
|
1262 |
|
|
*/
|
1263 |
|
|
if ((!ioaddr && autoprobed) || (ioaddr && !loading_module)) return;
|
1264 |
|
|
|
1265 |
|
|
if (MCA_bus) {
|
1266 |
|
|
/*
|
1267 |
|
|
** Search for the adapter. If an address has been given, search
|
1268 |
|
|
** specifically for the card at that address. Otherwise find the
|
1269 |
|
|
** first card in the system.
|
1270 |
|
|
*/
|
1271 |
|
|
while ((dev!=NULL) &&
|
1272 |
|
|
((slot=mca_find_adapter(DE212_ID, slot)) != MCA_NOTFOUND)) {
|
1273 |
|
|
pos[0] = mca_read_stored_pos(slot, 2);
|
1274 |
|
|
pos[1] = mca_read_stored_pos(slot, 3);
|
1275 |
|
|
|
1276 |
|
|
/*
|
1277 |
|
|
** IO of card is handled by bits 1 and 2 of pos0.
|
1278 |
|
|
**
|
1279 |
|
|
** bit2 bit1 IO
|
1280 |
|
|
** 0 0 0x2c00
|
1281 |
|
|
** 0 1 0x2c10
|
1282 |
|
|
** 1 0 0x2c20
|
1283 |
|
|
** 1 1 0x2c30
|
1284 |
|
|
*/
|
1285 |
|
|
where = (pos[0] & 6) >> 1;
|
1286 |
|
|
iobase = 0x2c00 + (0x10 * where);
|
1287 |
|
|
|
1288 |
|
|
if ((ioaddr) && (ioaddr != iobase)) {
|
1289 |
|
|
/*
|
1290 |
|
|
** Card was found, but not at the right IO location. Continue
|
1291 |
|
|
** scanning from the next MCA slot up for another card.
|
1292 |
|
|
*/
|
1293 |
|
|
slot++;
|
1294 |
|
|
continue;
|
1295 |
|
|
}
|
1296 |
|
|
|
1297 |
|
|
/*
|
1298 |
|
|
** Found the adapter we were looking for. Now start setting it up.
|
1299 |
|
|
**
|
1300 |
|
|
** First work on decoding the IRQ. It's stored in the lower 4 bits
|
1301 |
|
|
** of pos1. Bits are as follows (from the ADF file):
|
1302 |
|
|
**
|
1303 |
|
|
** Bits
|
1304 |
|
|
** 3 2 1 0 IRQ
|
1305 |
|
|
** --------------------
|
1306 |
|
|
** 0 0 1 0 5
|
1307 |
|
|
** 0 0 0 1 9
|
1308 |
|
|
** 0 1 0 0 10
|
1309 |
|
|
** 1 0 0 0 11
|
1310 |
|
|
**/
|
1311 |
|
|
where = pos[1] & 0x0f;
|
1312 |
|
|
switch(where) {
|
1313 |
|
|
case 1:
|
1314 |
|
|
irq = 9;
|
1315 |
|
|
break;
|
1316 |
|
|
case 2:
|
1317 |
|
|
irq = 5;
|
1318 |
|
|
break;
|
1319 |
|
|
case 4:
|
1320 |
|
|
irq = 10;
|
1321 |
|
|
break;
|
1322 |
|
|
case 8:
|
1323 |
|
|
irq = 11;
|
1324 |
|
|
break;
|
1325 |
|
|
default:
|
1326 |
|
|
printk("%s: mca_probe IRQ error. You should never get here (%d).\n", dev->name, where);
|
1327 |
|
|
return;
|
1328 |
|
|
}
|
1329 |
|
|
|
1330 |
|
|
/*
|
1331 |
|
|
** Shared memory address of adapter is stored in bits 3-5 of pos0.
|
1332 |
|
|
** They are mapped as follows:
|
1333 |
|
|
**
|
1334 |
|
|
** Bit
|
1335 |
|
|
** 5 4 3 Memory Addresses
|
1336 |
|
|
** 0 0 0 C0000-CFFFF (64K)
|
1337 |
|
|
** 1 0 0 C8000-CFFFF (32K)
|
1338 |
|
|
** 0 0 1 D0000-DFFFF (64K)
|
1339 |
|
|
** 1 0 1 D8000-DFFFF (32K)
|
1340 |
|
|
** 0 1 0 E0000-EFFFF (64K)
|
1341 |
|
|
** 1 1 0 E8000-EFFFF (32K)
|
1342 |
|
|
*/
|
1343 |
|
|
where = (pos[0] & 0x18) >> 3;
|
1344 |
|
|
mem = 0xc0000 + (where * 0x10000);
|
1345 |
|
|
if (pos[0] & 0x20) {
|
1346 |
|
|
mem += 0x8000;
|
1347 |
|
|
}
|
1348 |
|
|
|
1349 |
|
|
/*
|
1350 |
|
|
** Get everything allocated and initialized... (almost just
|
1351 |
|
|
** like the ISA and EISA probes)
|
1352 |
|
|
*/
|
1353 |
|
|
if (DevicePresent(iobase) != 0) {
|
1354 |
|
|
/*
|
1355 |
|
|
** If the MCA configuration says the card should be here,
|
1356 |
|
|
** it really should be here.
|
1357 |
|
|
*/
|
1358 |
|
|
printk(KERN_ERR "%s: MCA reports card at 0x%lx but it is not
|
1359 |
|
|
responding.\n", dev->name, iobase);
|
1360 |
|
|
}
|
1361 |
|
|
|
1362 |
|
|
if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
|
1363 |
|
|
if ((dev = alloc_device(dev, iobase)) != NULL) {
|
1364 |
|
|
dev->irq = irq;
|
1365 |
|
|
if (depca_hw_init(dev, iobase, slot) == 0) {
|
1366 |
|
|
/*
|
1367 |
|
|
** Adapter initialized correctly: Name it in
|
1368 |
|
|
** /proc/mca.
|
1369 |
|
|
*/
|
1370 |
|
|
mca_set_adapter_name(slot, "DE210/212 Ethernet Adapter");
|
1371 |
|
|
mca_mark_as_used(slot);
|
1372 |
|
|
num_depcas++;
|
1373 |
|
|
}
|
1374 |
|
|
num_eth++;
|
1375 |
|
|
}
|
1376 |
|
|
} else if (autoprobed) {
|
1377 |
|
|
printk(KERN_WARNING "%s: region already allocated at 0x%04lx.\n", dev->name, iobase);
|
1378 |
|
|
}
|
1379 |
|
|
|
1380 |
|
|
/*
|
1381 |
|
|
** If this is a probe by a module, return after setting up the
|
1382 |
|
|
** given card.
|
1383 |
|
|
*/
|
1384 |
|
|
if (ioaddr) return;
|
1385 |
|
|
|
1386 |
|
|
/*
|
1387 |
|
|
** Set up to check the next slot and loop.
|
1388 |
|
|
*/
|
1389 |
|
|
slot++;
|
1390 |
|
|
}
|
1391 |
|
|
}
|
1392 |
|
|
|
1393 |
|
|
return;
|
1394 |
|
|
}
|
1395 |
|
|
#endif
|
1396 |
|
|
|
1397 |
|
|
/*
|
1398 |
|
|
** ISA bus I/O device probe
|
1399 |
|
|
*/
|
1400 |
|
|
static void
|
1401 |
|
|
isa_probe(struct device *dev, u_long ioaddr)
|
1402 |
|
|
{
|
1403 |
|
|
int i = num_depcas, maxSlots;
|
1404 |
|
|
s32 ports[] = DEPCA_IO_PORTS;
|
1405 |
|
|
|
1406 |
|
|
if (!ioaddr && autoprobed) return ; /* Been here before ! */
|
1407 |
|
|
if (ioaddr > 0x400) return; /* EISA Address */
|
1408 |
|
|
if (i >= MAX_NUM_DEPCAS) return; /* Too many ISA adapters */
|
1409 |
|
|
|
1410 |
|
|
if (ioaddr == 0) { /* Autoprobing */
|
1411 |
|
|
maxSlots = MAX_NUM_DEPCAS;
|
1412 |
|
|
} else { /* Probe a specific location */
|
1413 |
|
|
ports[i] = ioaddr;
|
1414 |
|
|
maxSlots = i + 1;
|
1415 |
|
|
}
|
1416 |
|
|
|
1417 |
|
|
for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
|
1418 |
|
|
if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
|
1419 |
|
|
if (DevicePresent(ports[i]) == 0) {
|
1420 |
|
|
if ((dev = alloc_device(dev, ports[i])) != NULL) {
|
1421 |
|
|
if (depca_hw_init(dev, ports[i], -1) == 0) {
|
1422 |
|
|
num_depcas++;
|
1423 |
|
|
}
|
1424 |
|
|
num_eth++;
|
1425 |
|
|
}
|
1426 |
|
|
}
|
1427 |
|
|
} else if (autoprobed) {
|
1428 |
|
|
printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]);
|
1429 |
|
|
}
|
1430 |
|
|
}
|
1431 |
|
|
|
1432 |
|
|
return;
|
1433 |
|
|
}
|
1434 |
|
|
|
1435 |
|
|
/*
|
1436 |
|
|
** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
|
1437 |
|
|
** the motherboard. Upto 15 EISA devices are supported.
|
1438 |
|
|
*/
|
1439 |
|
|
static void
|
1440 |
|
|
eisa_probe(struct device *dev, u_long ioaddr)
|
1441 |
|
|
{
|
1442 |
|
|
int i, maxSlots;
|
1443 |
|
|
u_long iobase;
|
1444 |
|
|
char name[DEPCA_STRLEN];
|
1445 |
|
|
|
1446 |
|
|
if (!ioaddr && autoprobed) return ; /* Been here before ! */
|
1447 |
|
|
if ((ioaddr < 0x400) && (ioaddr > 0)) return; /* ISA Address */
|
1448 |
|
|
|
1449 |
|
|
if (ioaddr == 0) { /* Autoprobing */
|
1450 |
|
|
iobase = EISA_SLOT_INC; /* Get the first slot address */
|
1451 |
|
|
i = 1;
|
1452 |
|
|
maxSlots = MAX_EISA_SLOTS;
|
1453 |
|
|
} else { /* Probe a specific location */
|
1454 |
|
|
iobase = ioaddr;
|
1455 |
|
|
i = (ioaddr >> 12);
|
1456 |
|
|
maxSlots = i + 1;
|
1457 |
|
|
}
|
1458 |
|
|
if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
|
1459 |
|
|
|
1460 |
|
|
for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
|
1461 |
|
|
if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
|
1462 |
|
|
if (EISA_signature(name, EISA_ID)) {
|
1463 |
|
|
if (DevicePresent(iobase) == 0) {
|
1464 |
|
|
if ((dev = alloc_device(dev, iobase)) != NULL) {
|
1465 |
|
|
if (depca_hw_init(dev, iobase, -1) == 0) {
|
1466 |
|
|
num_depcas++;
|
1467 |
|
|
}
|
1468 |
|
|
num_eth++;
|
1469 |
|
|
}
|
1470 |
|
|
}
|
1471 |
|
|
}
|
1472 |
|
|
} else if (autoprobed) {
|
1473 |
|
|
printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase);
|
1474 |
|
|
}
|
1475 |
|
|
}
|
1476 |
|
|
|
1477 |
|
|
return;
|
1478 |
|
|
}
|
1479 |
|
|
|
1480 |
|
|
/*
|
1481 |
|
|
** Search the entire 'eth' device list for a fixed probe. If a match isn't
|
1482 |
|
|
** found then check for an autoprobe or unused device location. If they
|
1483 |
|
|
** are not available then insert a new device structure at the end of
|
1484 |
|
|
** the current list.
|
1485 |
|
|
*/
|
1486 |
|
|
static struct device *
|
1487 |
|
|
alloc_device(struct device *dev, u_long iobase)
|
1488 |
|
|
{
|
1489 |
|
|
struct device *adev = NULL;
|
1490 |
|
|
int fixed = 0, new_dev = 0;
|
1491 |
|
|
|
1492 |
|
|
num_eth = depca_dev_index(dev->name);
|
1493 |
|
|
if (loading_module) return dev;
|
1494 |
|
|
|
1495 |
|
|
while (1) {
|
1496 |
|
|
if (((dev->base_addr == DEPCA_NDA) || (dev->base_addr==0)) && !adev) {
|
1497 |
|
|
adev=dev;
|
1498 |
|
|
} else if ((dev->priv == NULL) && (dev->base_addr==iobase)) {
|
1499 |
|
|
fixed = 1;
|
1500 |
|
|
} else {
|
1501 |
|
|
if (dev->next == NULL) {
|
1502 |
|
|
new_dev = 1;
|
1503 |
|
|
} else if (strncmp(dev->next->name, "eth", 3) != 0) {
|
1504 |
|
|
new_dev = 1;
|
1505 |
|
|
}
|
1506 |
|
|
}
|
1507 |
|
|
if ((dev->next == NULL) || new_dev || fixed) break;
|
1508 |
|
|
dev = dev->next;
|
1509 |
|
|
num_eth++;
|
1510 |
|
|
}
|
1511 |
|
|
if (adev && !fixed) {
|
1512 |
|
|
dev = adev;
|
1513 |
|
|
num_eth = depca_dev_index(dev->name);
|
1514 |
|
|
new_dev = 0;
|
1515 |
|
|
}
|
1516 |
|
|
|
1517 |
|
|
if (((dev->next == NULL) &&
|
1518 |
|
|
((dev->base_addr != DEPCA_NDA) && (dev->base_addr != 0)) && !fixed) ||
|
1519 |
|
|
new_dev) {
|
1520 |
|
|
num_eth++; /* New device */
|
1521 |
|
|
dev = insert_device(dev, iobase, depca_probe);
|
1522 |
|
|
}
|
1523 |
|
|
|
1524 |
|
|
return dev;
|
1525 |
|
|
}
|
1526 |
|
|
|
1527 |
|
|
/*
|
1528 |
|
|
** If at end of eth device list and can't use current entry, malloc
|
1529 |
|
|
** one up. If memory could not be allocated, print an error message.
|
1530 |
|
|
*/
|
1531 |
|
|
static struct device *
|
1532 |
|
|
insert_device(struct device *dev, u_long iobase, int (*init)(struct device *))
|
1533 |
|
|
{
|
1534 |
|
|
struct device *new;
|
1535 |
|
|
|
1536 |
|
|
new = (struct device *)kmalloc(sizeof(struct device)+8, GFP_KERNEL);
|
1537 |
|
|
if (new == NULL) {
|
1538 |
|
|
printk("eth%d: Device not initialised, insufficient memory\n",num_eth);
|
1539 |
|
|
return NULL;
|
1540 |
|
|
} else {
|
1541 |
|
|
new->next = dev->next;
|
1542 |
|
|
dev->next = new;
|
1543 |
|
|
dev = dev->next; /* point to the new device */
|
1544 |
|
|
dev->name = (char *)(dev + 1);
|
1545 |
|
|
if (num_eth > 9999) {
|
1546 |
|
|
sprintf(dev->name,"eth????");/* New device name */
|
1547 |
|
|
} else {
|
1548 |
|
|
sprintf(dev->name,"eth%d", num_eth);/* New device name */
|
1549 |
|
|
}
|
1550 |
|
|
dev->base_addr = iobase; /* assign the io address */
|
1551 |
|
|
dev->init = init; /* initialisation routine */
|
1552 |
|
|
}
|
1553 |
|
|
|
1554 |
|
|
return dev;
|
1555 |
|
|
}
|
1556 |
|
|
|
1557 |
|
|
static int
|
1558 |
|
|
depca_dev_index(char *s)
|
1559 |
|
|
{
|
1560 |
|
|
int i=0, j=0;
|
1561 |
|
|
|
1562 |
|
|
for (;*s; s++) {
|
1563 |
|
|
if (isdigit(*s)) {
|
1564 |
|
|
j=1;
|
1565 |
|
|
i = (i * 10) + (*s - '0');
|
1566 |
|
|
} else if (j) break;
|
1567 |
|
|
}
|
1568 |
|
|
|
1569 |
|
|
return i;
|
1570 |
|
|
}
|
1571 |
|
|
|
1572 |
|
|
/*
|
1573 |
|
|
** Look for a particular board name in the on-board Remote Diagnostics
|
1574 |
|
|
** and Boot (readb) ROM. This will also give us a clue to the network RAM
|
1575 |
|
|
** base address.
|
1576 |
|
|
*/
|
1577 |
|
|
static void DepcaSignature(char *name, u_long paddr)
|
1578 |
|
|
{
|
1579 |
|
|
u_int i,j,k;
|
1580 |
|
|
const char *signatures[] = DEPCA_SIGNATURE;
|
1581 |
|
|
char tmpstr[16];
|
1582 |
|
|
|
1583 |
|
|
/* Copy the first 16 bytes of ROM */
|
1584 |
|
|
for (i=0;i<16;i++) {
|
1585 |
|
|
tmpstr[i] = readb(paddr+0xc000+i);
|
1586 |
|
|
}
|
1587 |
|
|
|
1588 |
|
|
/* Check if PROM contains a valid string */
|
1589 |
|
|
for (i=0;*signatures[i]!='\0';i++) {
|
1590 |
|
|
for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
|
1591 |
|
|
if (signatures[i][k] == tmpstr[j]) { /* track signature */
|
1592 |
|
|
k++;
|
1593 |
|
|
} else { /* lost signature; begin search again */
|
1594 |
|
|
k=0;
|
1595 |
|
|
}
|
1596 |
|
|
}
|
1597 |
|
|
if (k == strlen(signatures[i])) break;
|
1598 |
|
|
}
|
1599 |
|
|
|
1600 |
|
|
/* Check if name string is valid, provided there's no PROM */
|
1601 |
|
|
if (*name && (i == unknown)) {
|
1602 |
|
|
for (i=0;*signatures[i]!='\0';i++) {
|
1603 |
|
|
if (strcmp(name,signatures[i]) == 0) break;
|
1604 |
|
|
}
|
1605 |
|
|
}
|
1606 |
|
|
|
1607 |
|
|
/* Update search results */
|
1608 |
|
|
strcpy(name,signatures[i]);
|
1609 |
|
|
adapter = i;
|
1610 |
|
|
|
1611 |
|
|
return;
|
1612 |
|
|
}
|
1613 |
|
|
|
1614 |
|
|
/*
|
1615 |
|
|
** Look for a special sequence in the Ethernet station address PROM that
|
1616 |
|
|
** is common across all DEPCA products. Note that the original DEPCA needs
|
1617 |
|
|
** its ROM address counter to be initialized and enabled. Only enable
|
1618 |
|
|
** if the first address octet is a 0x08 - this minimises the chances of
|
1619 |
|
|
** messing around with some other hardware, but it assumes that this DEPCA
|
1620 |
|
|
** card initialized itself correctly.
|
1621 |
|
|
**
|
1622 |
|
|
** Search the Ethernet address ROM for the signature. Since the ROM address
|
1623 |
|
|
** counter can start at an arbitrary point, the search must include the entire
|
1624 |
|
|
** probe sequence length plus the (length_of_the_signature - 1).
|
1625 |
|
|
** Stop the search IMMEDIATELY after the signature is found so that the
|
1626 |
|
|
** PROM address counter is correctly positioned at the start of the
|
1627 |
|
|
** ethernet address for later read out.
|
1628 |
|
|
*/
|
1629 |
|
|
static int DevicePresent(u_long ioaddr)
|
1630 |
|
|
{
|
1631 |
|
|
union {
|
1632 |
|
|
struct {
|
1633 |
|
|
u32 a;
|
1634 |
|
|
u32 b;
|
1635 |
|
|
} llsig;
|
1636 |
|
|
char Sig[sizeof(u32) << 1];
|
1637 |
|
|
} dev;
|
1638 |
|
|
short sigLength=0;
|
1639 |
|
|
s8 data;
|
1640 |
|
|
s16 nicsr;
|
1641 |
|
|
int i, j, status = 0;
|
1642 |
|
|
|
1643 |
|
|
data = inb(DEPCA_PROM); /* clear counter on DEPCA */
|
1644 |
|
|
data = inb(DEPCA_PROM); /* read data */
|
1645 |
|
|
|
1646 |
|
|
if (data == 0x08) { /* Enable counter on DEPCA */
|
1647 |
|
|
nicsr = inb(DEPCA_NICSR);
|
1648 |
|
|
nicsr |= AAC;
|
1649 |
|
|
outb(nicsr, DEPCA_NICSR);
|
1650 |
|
|
}
|
1651 |
|
|
|
1652 |
|
|
dev.llsig.a = ETH_PROM_SIG;
|
1653 |
|
|
dev.llsig.b = ETH_PROM_SIG;
|
1654 |
|
|
sigLength = sizeof(u32) << 1;
|
1655 |
|
|
|
1656 |
|
|
for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
|
1657 |
|
|
data = inb(DEPCA_PROM);
|
1658 |
|
|
if (dev.Sig[j] == data) { /* track signature */
|
1659 |
|
|
j++;
|
1660 |
|
|
} else { /* lost signature; begin search again */
|
1661 |
|
|
if (data == dev.Sig[0]) { /* rare case.... */
|
1662 |
|
|
j=1;
|
1663 |
|
|
} else {
|
1664 |
|
|
j=0;
|
1665 |
|
|
}
|
1666 |
|
|
}
|
1667 |
|
|
}
|
1668 |
|
|
|
1669 |
|
|
if (j!=sigLength) {
|
1670 |
|
|
status = -ENODEV; /* search failed */
|
1671 |
|
|
}
|
1672 |
|
|
|
1673 |
|
|
return status;
|
1674 |
|
|
}
|
1675 |
|
|
|
1676 |
|
|
/*
|
1677 |
|
|
** The DE100 and DE101 PROM accesses were made non-standard for some bizarre
|
1678 |
|
|
** reason: access the upper half of the PROM with x=0; access the lower half
|
1679 |
|
|
** with x=1.
|
1680 |
|
|
*/
|
1681 |
|
|
static int get_hw_addr(struct device *dev)
|
1682 |
|
|
{
|
1683 |
|
|
u_long ioaddr = dev->base_addr;
|
1684 |
|
|
int i, k, tmp, status = 0;
|
1685 |
|
|
u_short j, x, chksum;
|
1686 |
|
|
|
1687 |
|
|
x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
|
1688 |
|
|
|
1689 |
|
|
for (i=0,k=0,j=0;j<3;j++) {
|
1690 |
|
|
k <<= 1 ;
|
1691 |
|
|
if (k > 0xffff) k-=0xffff;
|
1692 |
|
|
|
1693 |
|
|
k += (u_char) (tmp = inb(DEPCA_PROM + x));
|
1694 |
|
|
dev->dev_addr[i++] = (u_char) tmp;
|
1695 |
|
|
k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
|
1696 |
|
|
dev->dev_addr[i++] = (u_char) tmp;
|
1697 |
|
|
|
1698 |
|
|
if (k > 0xffff) k-=0xffff;
|
1699 |
|
|
}
|
1700 |
|
|
if (k == 0xffff) k=0;
|
1701 |
|
|
|
1702 |
|
|
chksum = (u_char) inb(DEPCA_PROM + x);
|
1703 |
|
|
chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
|
1704 |
|
|
if (k != chksum) status = -1;
|
1705 |
|
|
|
1706 |
|
|
return status;
|
1707 |
|
|
}
|
1708 |
|
|
|
1709 |
|
|
/*
|
1710 |
|
|
** Load a packet into the shared memory
|
1711 |
|
|
*/
|
1712 |
|
|
static int load_packet(struct device *dev, struct sk_buff *skb)
|
1713 |
|
|
{
|
1714 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1715 |
|
|
int i, entry, end, len, status = 0;
|
1716 |
|
|
|
1717 |
|
|
entry = lp->tx_new; /* Ring around buffer number. */
|
1718 |
|
|
end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
|
1719 |
|
|
if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {/* Enough room? */
|
1720 |
|
|
/*
|
1721 |
|
|
** Caution: the write order is important here... don't set up the
|
1722 |
|
|
** ownership rights until all the other information is in place.
|
1723 |
|
|
*/
|
1724 |
|
|
if (end < entry) { /* wrapped buffer */
|
1725 |
|
|
len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
|
1726 |
|
|
memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
|
1727 |
|
|
memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
|
1728 |
|
|
} else { /* linear buffer */
|
1729 |
|
|
memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
|
1730 |
|
|
}
|
1731 |
|
|
|
1732 |
|
|
/* set up the buffer descriptors */
|
1733 |
|
|
len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
|
1734 |
|
|
for (i = entry; i != end; i = (++i) & lp->txRingMask) {
|
1735 |
|
|
/* clean out flags */
|
1736 |
|
|
writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
|
1737 |
|
|
writew(0x0000, &lp->tx_ring[i].misc); /* clears other error flags */
|
1738 |
|
|
writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);/* packet length in buffer */
|
1739 |
|
|
len -= TX_BUFF_SZ;
|
1740 |
|
|
}
|
1741 |
|
|
/* clean out flags */
|
1742 |
|
|
writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
|
1743 |
|
|
writew(0x0000, &lp->tx_ring[end].misc); /* clears other error flags */
|
1744 |
|
|
writew(-len, &lp->tx_ring[end].length); /* packet length in last buff */
|
1745 |
|
|
|
1746 |
|
|
/* start of packet */
|
1747 |
|
|
writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
|
1748 |
|
|
/* end of packet */
|
1749 |
|
|
writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
|
1750 |
|
|
|
1751 |
|
|
for (i=end; i!=entry; --i) {
|
1752 |
|
|
/* ownership of packet */
|
1753 |
|
|
writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
|
1754 |
|
|
if (i == 0) i=lp->txRingMask+1;
|
1755 |
|
|
}
|
1756 |
|
|
writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
|
1757 |
|
|
|
1758 |
|
|
lp->tx_new = (++end) & lp->txRingMask; /* update current pointers */
|
1759 |
|
|
} else {
|
1760 |
|
|
status = -1;
|
1761 |
|
|
}
|
1762 |
|
|
|
1763 |
|
|
return status;
|
1764 |
|
|
}
|
1765 |
|
|
|
1766 |
|
|
/*
|
1767 |
|
|
** Look for a particular board name in the EISA configuration space
|
1768 |
|
|
*/
|
1769 |
|
|
static int EISA_signature(char *name, s32 eisa_id)
|
1770 |
|
|
{
|
1771 |
|
|
u_int i;
|
1772 |
|
|
const char *signatures[] = DEPCA_SIGNATURE;
|
1773 |
|
|
char ManCode[DEPCA_STRLEN];
|
1774 |
|
|
union {
|
1775 |
|
|
s32 ID;
|
1776 |
|
|
char Id[4];
|
1777 |
|
|
} Eisa;
|
1778 |
|
|
int status = 0;
|
1779 |
|
|
|
1780 |
|
|
*name = '\0';
|
1781 |
|
|
Eisa.ID = inl(eisa_id);
|
1782 |
|
|
|
1783 |
|
|
ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
|
1784 |
|
|
ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
|
1785 |
|
|
ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
|
1786 |
|
|
ManCode[3]=(( Eisa.Id[2]&0x0f)+0x30);
|
1787 |
|
|
ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
|
1788 |
|
|
ManCode[5]='\0';
|
1789 |
|
|
|
1790 |
|
|
for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
|
1791 |
|
|
if (strstr(ManCode, signatures[i]) != NULL) {
|
1792 |
|
|
strcpy(name,ManCode);
|
1793 |
|
|
status = 1;
|
1794 |
|
|
}
|
1795 |
|
|
}
|
1796 |
|
|
|
1797 |
|
|
return status;
|
1798 |
|
|
}
|
1799 |
|
|
|
1800 |
|
|
static void depca_dbg_open(struct device *dev)
|
1801 |
|
|
{
|
1802 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1803 |
|
|
u_long ioaddr = dev->base_addr;
|
1804 |
|
|
struct depca_init *p = (struct depca_init *)lp->sh_mem;
|
1805 |
|
|
int i;
|
1806 |
|
|
|
1807 |
|
|
if (depca_debug > 1){
|
1808 |
|
|
/* Copy the shadow init_block to shared memory */
|
1809 |
|
|
memcpy_toio((char *)lp->sh_mem,&lp->init_block,sizeof(struct depca_init));
|
1810 |
|
|
|
1811 |
|
|
printk("%s: depca open with irq %d\n",dev->name,dev->irq);
|
1812 |
|
|
printk("Descriptor head addresses:\n");
|
1813 |
|
|
printk("\t0x%lx 0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring);
|
1814 |
|
|
printk("Descriptor addresses:\nRX: ");
|
1815 |
|
|
for (i=0;i<lp->rxRingMask;i++){
|
1816 |
|
|
if (i < 3) {
|
1817 |
|
|
printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
|
1818 |
|
|
}
|
1819 |
|
|
}
|
1820 |
|
|
printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
|
1821 |
|
|
printk("TX: ");
|
1822 |
|
|
for (i=0;i<lp->txRingMask;i++){
|
1823 |
|
|
if (i < 3) {
|
1824 |
|
|
printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
|
1825 |
|
|
}
|
1826 |
|
|
}
|
1827 |
|
|
printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
|
1828 |
|
|
printk("\nDescriptor buffers:\nRX: ");
|
1829 |
|
|
for (i=0;i<lp->rxRingMask;i++){
|
1830 |
|
|
if (i < 3) {
|
1831 |
|
|
printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
|
1832 |
|
|
}
|
1833 |
|
|
}
|
1834 |
|
|
printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
|
1835 |
|
|
printk("TX: ");
|
1836 |
|
|
for (i=0;i<lp->txRingMask;i++){
|
1837 |
|
|
if (i < 3) {
|
1838 |
|
|
printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
|
1839 |
|
|
}
|
1840 |
|
|
}
|
1841 |
|
|
printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
|
1842 |
|
|
printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem);
|
1843 |
|
|
printk("\tmode: 0x%4.4x\n",readw(&p->mode));
|
1844 |
|
|
printk("\tphysical address: ");
|
1845 |
|
|
for (i=0;i<ETH_ALEN-1;i++){
|
1846 |
|
|
printk("%2.2x:",(u_char)readb(&p->phys_addr[i]));
|
1847 |
|
|
}
|
1848 |
|
|
printk("%2.2x\n",(u_char)readb(&p->phys_addr[i]));
|
1849 |
|
|
printk("\tmulticast hash table: ");
|
1850 |
|
|
for (i=0;i<(HASH_TABLE_LEN >> 3)-1;i++){
|
1851 |
|
|
printk("%2.2x:",(u_char)readb(&p->mcast_table[i]));
|
1852 |
|
|
}
|
1853 |
|
|
printk("%2.2x\n",(u_char)readb(&p->mcast_table[i]));
|
1854 |
|
|
printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring));
|
1855 |
|
|
printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring));
|
1856 |
|
|
printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs);
|
1857 |
|
|
printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n",
|
1858 |
|
|
(int)lp->rxRingMask + 1,
|
1859 |
|
|
lp->rx_rlen);
|
1860 |
|
|
printk("TX: %d Log2(txRingMask): 0x%8.8x\n",
|
1861 |
|
|
(int)lp->txRingMask + 1,
|
1862 |
|
|
lp->tx_rlen);
|
1863 |
|
|
outw(CSR2,DEPCA_ADDR);
|
1864 |
|
|
printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
|
1865 |
|
|
outw(CSR1,DEPCA_ADDR);
|
1866 |
|
|
printk("%4.4x\n",inw(DEPCA_DATA));
|
1867 |
|
|
outw(CSR3,DEPCA_ADDR);
|
1868 |
|
|
printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
|
1869 |
|
|
}
|
1870 |
|
|
|
1871 |
|
|
return;
|
1872 |
|
|
}
|
1873 |
|
|
|
1874 |
|
|
/*
|
1875 |
|
|
** Perform IOCTL call functions here. Some are privileged operations and the
|
1876 |
|
|
** effective uid is checked in those cases.
|
1877 |
|
|
** All multicast IOCTLs will not work here and are for testing purposes only.
|
1878 |
|
|
*/
|
1879 |
|
|
static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
|
1880 |
|
|
{
|
1881 |
|
|
struct depca_private *lp = (struct depca_private *)dev->priv;
|
1882 |
|
|
struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
|
1883 |
|
|
int i, status = 0;
|
1884 |
|
|
u_long ioaddr = dev->base_addr;
|
1885 |
|
|
union {
|
1886 |
|
|
u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
|
1887 |
|
|
u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
|
1888 |
|
|
u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
|
1889 |
|
|
} tmp;
|
1890 |
|
|
|
1891 |
|
|
switch(ioc->cmd) {
|
1892 |
|
|
case DEPCA_GET_HWADDR: /* Get the hardware address */
|
1893 |
|
|
for (i=0; i<ETH_ALEN; i++) {
|
1894 |
|
|
tmp.addr[i] = dev->dev_addr[i];
|
1895 |
|
|
}
|
1896 |
|
|
ioc->len = ETH_ALEN;
|
1897 |
|
|
if (verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len)) return -EFAULT;
|
1898 |
|
|
memcpy_tofs(ioc->data, tmp.addr, ioc->len);
|
1899 |
|
|
break;
|
1900 |
|
|
|
1901 |
|
|
case DEPCA_SET_HWADDR: /* Set the hardware address */
|
1902 |
|
|
if (!suser()) return -EPERM;
|
1903 |
|
|
if (verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN)) return -EFAULT;
|
1904 |
|
|
memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
|
1905 |
|
|
for (i=0; i<ETH_ALEN; i++) {
|
1906 |
|
|
dev->dev_addr[i] = tmp.addr[i];
|
1907 |
|
|
}
|
1908 |
|
|
while(dev->tbusy) barrier(); /* Stop ring access */
|
1909 |
|
|
set_bit(0, (void*)&dev->tbusy);
|
1910 |
|
|
while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
|
1911 |
|
|
|
1912 |
|
|
STOP_DEPCA; /* Temporarily stop the depca. */
|
1913 |
|
|
depca_init_ring(dev); /* Initialize the descriptor rings */
|
1914 |
|
|
LoadCSRs(dev); /* Reload CSR3 */
|
1915 |
|
|
InitRestartDepca(dev); /* Resume normal operation. */
|
1916 |
|
|
dev->tbusy = 0; /* Unlock the TX ring */
|
1917 |
|
|
break;
|
1918 |
|
|
|
1919 |
|
|
case DEPCA_SET_PROM: /* Set Promiscuous Mode */
|
1920 |
|
|
if (!suser()) return -EPERM;
|
1921 |
|
|
while(dev->tbusy) barrier(); /* Stop ring access */
|
1922 |
|
|
set_bit(0, (void*)&dev->tbusy);
|
1923 |
|
|
while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
|
1924 |
|
|
|
1925 |
|
|
STOP_DEPCA; /* Temporarily stop the depca. */
|
1926 |
|
|
depca_init_ring(dev); /* Initialize the descriptor rings */
|
1927 |
|
|
lp->init_block.mode |= PROM; /* Set promiscuous mode */
|
1928 |
|
|
|
1929 |
|
|
LoadCSRs(dev); /* Reload CSR3 */
|
1930 |
|
|
InitRestartDepca(dev); /* Resume normal operation. */
|
1931 |
|
|
dev->tbusy = 0; /* Unlock the TX ring */
|
1932 |
|
|
break;
|
1933 |
|
|
|
1934 |
|
|
case DEPCA_CLR_PROM: /* Clear Promiscuous Mode */
|
1935 |
|
|
if (!suser()) return -EPERM;
|
1936 |
|
|
while(dev->tbusy) barrier(); /* Stop ring access */
|
1937 |
|
|
set_bit(0, (void*)&dev->tbusy);
|
1938 |
|
|
while(lp->tx_old != lp->tx_new); /* Wait for the ring to empty */
|
1939 |
|
|
|
1940 |
|
|
STOP_DEPCA; /* Temporarily stop the depca. */
|
1941 |
|
|
depca_init_ring(dev); /* Initialize the descriptor rings */
|
1942 |
|
|
lp->init_block.mode &= ~PROM; /* Clear promiscuous mode */
|
1943 |
|
|
|
1944 |
|
|
LoadCSRs(dev); /* Reload CSR3 */
|
1945 |
|
|
InitRestartDepca(dev); /* Resume normal operation. */
|
1946 |
|
|
dev->tbusy = 0; /* Unlock the TX ring */
|
1947 |
|
|
break;
|
1948 |
|
|
|
1949 |
|
|
case DEPCA_SAY_BOO: /* Say "Boo!" to the kernel log file */
|
1950 |
|
|
printk("%s: Boo!\n", dev->name);
|
1951 |
|
|
break;
|
1952 |
|
|
|
1953 |
|
|
case DEPCA_GET_MCA: /* Get the multicast address table */
|
1954 |
|
|
ioc->len = (HASH_TABLE_LEN >> 3);
|
1955 |
|
|
if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) return -EFAULT;
|
1956 |
|
|
memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len);
|
1957 |
|
|
break;
|
1958 |
|
|
|
1959 |
|
|
case DEPCA_SET_MCA: /* Set a multicast address */
|
1960 |
|
|
if (!suser()) return -EPERM;
|
1961 |
|
|
if (verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len)) return -EFAULT;
|
1962 |
|
|
memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
|
1963 |
|
|
set_multicast_list(dev);
|
1964 |
|
|
break;
|
1965 |
|
|
|
1966 |
|
|
case DEPCA_CLR_MCA: /* Clear all multicast addresses */
|
1967 |
|
|
if (!suser()) return -EPERM;
|
1968 |
|
|
set_multicast_list(dev);
|
1969 |
|
|
break;
|
1970 |
|
|
|
1971 |
|
|
case DEPCA_MCA_EN: /* Enable pass all multicast addressing */
|
1972 |
|
|
if (!suser()) return -EPERM;
|
1973 |
|
|
set_multicast_list(dev);
|
1974 |
|
|
break;
|
1975 |
|
|
|
1976 |
|
|
case DEPCA_GET_STATS: /* Get the driver statistics */
|
1977 |
|
|
cli();
|
1978 |
|
|
ioc->len = sizeof(lp->pktStats);
|
1979 |
|
|
if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) {
|
1980 |
|
|
status = -EFAULT;
|
1981 |
|
|
} else {
|
1982 |
|
|
memcpy_tofs(ioc->data, &lp->pktStats, ioc->len);
|
1983 |
|
|
}
|
1984 |
|
|
sti();
|
1985 |
|
|
break;
|
1986 |
|
|
|
1987 |
|
|
case DEPCA_CLR_STATS: /* Zero out the driver statistics */
|
1988 |
|
|
if (!suser()) return -EPERM;
|
1989 |
|
|
cli();
|
1990 |
|
|
memset(&lp->pktStats, 0, sizeof(lp->pktStats));
|
1991 |
|
|
sti();
|
1992 |
|
|
break;
|
1993 |
|
|
|
1994 |
|
|
case DEPCA_GET_REG: /* Get the DEPCA Registers */
|
1995 |
|
|
i=0;
|
1996 |
|
|
tmp.sval[i++] = inw(DEPCA_NICSR);
|
1997 |
|
|
outw(CSR0, DEPCA_ADDR); /* status register */
|
1998 |
|
|
tmp.sval[i++] = inw(DEPCA_DATA);
|
1999 |
|
|
memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
|
2000 |
|
|
ioc->len = i+sizeof(struct depca_init);
|
2001 |
|
|
if (verify_area(VERIFY_WRITE, ioc->data, ioc->len)) return -EFAULT;
|
2002 |
|
|
memcpy_tofs(ioc->data, tmp.addr, ioc->len);
|
2003 |
|
|
break;
|
2004 |
|
|
|
2005 |
|
|
default:
|
2006 |
|
|
return -EOPNOTSUPP;
|
2007 |
|
|
}
|
2008 |
|
|
|
2009 |
|
|
return status;
|
2010 |
|
|
}
|
2011 |
|
|
|
2012 |
|
|
#ifdef MODULE
|
2013 |
|
|
static char devicename[9] = {0,};
|
2014 |
|
|
static struct device thisDepca = {
|
2015 |
|
|
devicename, /* device name is inserted by /linux/drivers/net/net_init.c */
|
2016 |
|
|
0, 0, 0, 0,
|
2017 |
|
|
0x200, 7, /* I/O address, IRQ */
|
2018 |
|
|
0, 0, 0, NULL, depca_probe
|
2019 |
|
|
};
|
2020 |
|
|
|
2021 |
|
|
static int irq=7; /* EDIT THESE LINE FOR YOUR CONFIGURATION */
|
2022 |
|
|
static int io=0x200; /* Or use the irq= io= options to insmod */
|
2023 |
|
|
|
2024 |
|
|
/* See depca_probe() for autoprobe messages when a module */
|
2025 |
|
|
int
|
2026 |
|
|
init_module(void)
|
2027 |
|
|
{
|
2028 |
|
|
thisDepca.irq=irq;
|
2029 |
|
|
thisDepca.base_addr=io;
|
2030 |
|
|
|
2031 |
|
|
if (register_netdev(&thisDepca) != 0)
|
2032 |
|
|
return -EIO;
|
2033 |
|
|
|
2034 |
|
|
return 0;
|
2035 |
|
|
}
|
2036 |
|
|
|
2037 |
|
|
void
|
2038 |
|
|
cleanup_module(void)
|
2039 |
|
|
{
|
2040 |
|
|
struct depca_private *lp = thisDepca.priv;
|
2041 |
|
|
if (lp) {
|
2042 |
|
|
#ifdef CONFIG_MCA
|
2043 |
|
|
if(lp->mca_slot != -1)
|
2044 |
|
|
mca_mark_as_unused(lp->mca_slot);
|
2045 |
|
|
#endif
|
2046 |
|
|
kfree(lp);
|
2047 |
|
|
thisDepca.priv = NULL;
|
2048 |
|
|
}
|
2049 |
|
|
thisDepca.irq=0;
|
2050 |
|
|
|
2051 |
|
|
unregister_netdev(&thisDepca);
|
2052 |
|
|
release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
|
2053 |
|
|
}
|
2054 |
|
|
#endif /* MODULE */
|
2055 |
|
|
|
2056 |
|
|
|
2057 |
|
|
/*
|
2058 |
|
|
* Local variables:
|
2059 |
|
|
* compile-command: "gcc -D__KERNEL__ -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c depca.c"
|
2060 |
|
|
*
|
2061 |
|
|
* compile-command: "gcc -D__KERNEL__ -DMODULE -I/linux/include -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce -malign-loops=2 -malign-jumps=2 -malign-functions=2 -O2 -m486 -c depca.c"
|
2062 |
|
|
* End:
|
2063 |
|
|
*/
|