1 |
1626 |
jcastillo |
/* arcnet.c:
|
2 |
|
|
Written 1994-1996 by Avery Pennarun,
|
3 |
|
|
derived from skeleton.c by Donald Becker.
|
4 |
|
|
|
5 |
|
|
Contact Avery at: apenwarr@foxnet.net or
|
6 |
|
|
RR #5 Pole Line Road, Thunder Bay, ON, Canada P7C 5M9
|
7 |
|
|
|
8 |
|
|
**********************
|
9 |
|
|
|
10 |
|
|
The original copyright was as follows:
|
11 |
|
|
|
12 |
|
|
skeleton.c Written 1993 by Donald Becker.
|
13 |
|
|
Copyright 1993 United States Government as represented by the
|
14 |
|
|
Director, National Security Agency. This software may only be used
|
15 |
|
|
and distributed according to the terms of the GNU Public License as
|
16 |
|
|
modified by SRC, incorporated herein by reference.
|
17 |
|
|
|
18 |
|
|
**********************
|
19 |
|
|
|
20 |
|
|
v2.56 (96/10/18)
|
21 |
|
|
- Turned arc0e/arc0s startup messages back on by default, as most
|
22 |
|
|
people will probably not notice the additional devices
|
23 |
|
|
otherwise, and experience more protocol confusion than
|
24 |
|
|
necessary.
|
25 |
|
|
- Fixed a tiny but noticeable bug in the packet debugging routines
|
26 |
|
|
(thanks Tomasz)
|
27 |
|
|
|
28 |
|
|
v2.55 (96/08/05)
|
29 |
|
|
- A couple more messages moved to D_EXTRA.
|
30 |
|
|
- SLOW_XMIT_COPY off by default.
|
31 |
|
|
- Some tiny changes.
|
32 |
|
|
|
33 |
|
|
v2.54 (96/07/05)
|
34 |
|
|
- Under some situations, Stage 5 autoprobe was a little bit too
|
35 |
|
|
picky about the TXACK flag.
|
36 |
|
|
- D_EXTRA removed from default debugging flags. Hey, it's stable,
|
37 |
|
|
right?
|
38 |
|
|
- Removed redundant "unknown protocol ID" messages and made remaining
|
39 |
|
|
ones D_EXTRA.
|
40 |
|
|
|
41 |
|
|
v2.53 (96/06/06)
|
42 |
|
|
- arc0e and arc0s wouldn't initialize in newer kernels, which
|
43 |
|
|
don't like dev->open==NULL or dev->stop==NULL.
|
44 |
|
|
|
45 |
|
|
v2.52 (96/04/20)
|
46 |
|
|
- Replaced more decimal node ID's with hex, for consistency.
|
47 |
|
|
- Changed a couple of printk debug levels.
|
48 |
|
|
|
49 |
|
|
v2.51 (96/02/29)
|
50 |
|
|
- Inserted a rather important missing "volatile" in autoprobe.
|
51 |
|
|
- arc0e and arc0s are now options in drivers/net/Config.in.
|
52 |
|
|
|
53 |
|
|
v2.50 (96/02/24)
|
54 |
|
|
- Increased IRQ autoprobe delay. Thanks to Andrew J. Kroll for
|
55 |
|
|
noticing the problem, which seems to only affect certain cards.
|
56 |
|
|
- Errors reserving ports and IRQ's now clean up after themselves.
|
57 |
|
|
- We now replace the TESTvalue byte from unused shmem addresses.
|
58 |
|
|
- You can now use "irq=" as well as "irqnum=" to set the IRQ
|
59 |
|
|
during module autoprobe. This doesn't seem to crash insmod
|
60 |
|
|
anymore. (?)
|
61 |
|
|
- You can now define the name of the ARCnet device more easily
|
62 |
|
|
when loading the module: insmod arcnet.o device=test1
|
63 |
|
|
A new option, CONFIG_ARCNET_ETHNAME, allows the kernel to
|
64 |
|
|
choose one of the standard eth?-style device names
|
65 |
|
|
automatically. This currently only works as a module.
|
66 |
|
|
- printk's now try to make some use of the KERN_xxx priority level
|
67 |
|
|
macros (though they may not be perfect yet).
|
68 |
|
|
- Packet and skb dump loops are now separate functions.
|
69 |
|
|
- Removed D_INIT from default debug level, because I am (finally)
|
70 |
|
|
pretty confident that autoprobe shouldn't toast anyone's
|
71 |
|
|
computer.
|
72 |
|
|
- This version is no longer ALPHA.
|
73 |
|
|
|
74 |
|
|
v2.41 ALPHA (96/02/10)
|
75 |
|
|
- Incorporated changes someone made to arcnet_setup in 1.3.60.
|
76 |
|
|
- Increased reset timeout to 3/10 of a second because some cards
|
77 |
|
|
are too slow.
|
78 |
|
|
- Removed a useless delay from autoprobe stage 4; I wonder
|
79 |
|
|
how that got there! (oops)
|
80 |
|
|
- If FAST_IFCONFIG is defined, don't reset the card during
|
81 |
|
|
arcnet_open; rather, do it in arcnet_close but don't delay.
|
82 |
|
|
This speeds up calls to ifconfig up/down. (Thanks to Vojtech
|
83 |
|
|
for the idea to speed this up.)
|
84 |
|
|
- If FAST_PROBE is defined, don't bother to reset the card in
|
85 |
|
|
autoprobe Stage 5 when there is only one io port and one shmem
|
86 |
|
|
left in the list. They "obviously" correspond to each other.
|
87 |
|
|
Another good idea from Vojtech.
|
88 |
|
|
|
89 |
|
|
v2.40 ALPHA (96/02/03)
|
90 |
|
|
- Checked the RECON flag last in the interrupt handler (when
|
91 |
|
|
enabled) so the flag will show up in "status" when reporting
|
92 |
|
|
other errors. (I had a cabling problem that was hard to notice
|
93 |
|
|
until I saw the huge RECON count in /proc/net/dev.)
|
94 |
|
|
- Moved "IRQ for unknown device" message to D_DURING.
|
95 |
|
|
- "transmit timed out" and "not acknowledged" messages are
|
96 |
|
|
now D_EXTRA, because they very commonly happen when things
|
97 |
|
|
are working fine. "transmit timed out" due to missed IRQ's
|
98 |
|
|
is still D_NORMAL, because it's probably a bug.
|
99 |
|
|
- "Transmit timed out" messages now include destination station id.
|
100 |
|
|
- The virtual arc0e and arc0s devices can now be disabled.
|
101 |
|
|
Massive (but simple) code rearrangement to support this with
|
102 |
|
|
fewer ifdef's.
|
103 |
|
|
- SLOW_XMIT_COPY option so fast computers don't hog the bus. It's
|
104 |
|
|
weird, but it works.
|
105 |
|
|
- Finally redesigned autoprobe after some discussion with Vojtech
|
106 |
|
|
Pavlik <Vojtech.Pavlik@st.mff.cuni.cz>. It should be much safer
|
107 |
|
|
and more reliable now, I think. We now probe several more io
|
108 |
|
|
ports and many more shmem addresses.
|
109 |
|
|
- Rearranged D_* debugging flags slightly. Watch out! There is
|
110 |
|
|
now a new flag, disabled by default, that will tell you the
|
111 |
|
|
reason a particular port or shmem is discarded from the list.
|
112 |
|
|
|
113 |
|
|
v2.30 ALPHA (96/01/10)
|
114 |
|
|
- Abandoned support for Linux 1.2 to simplify coding and allow me
|
115 |
|
|
to take advantage of new features in 1.3.
|
116 |
|
|
- Updated cabling/jumpers documentation with MUCH information that
|
117 |
|
|
people have recently (and in some cases, not so recently) sent
|
118 |
|
|
me. I don't mind writing documentation, but the jumpers
|
119 |
|
|
database is REALLY starting to get dull.
|
120 |
|
|
- Autoprobing works as a module now - but ONLY with my fix to
|
121 |
|
|
register_netdev and unregister_netdev. It's also much faster,
|
122 |
|
|
and uses the "new-style" IRQ autoprobe routines. Autoprobe is
|
123 |
|
|
still a horrible mess and will be cleaned up further as time
|
124 |
|
|
passes.
|
125 |
|
|
|
126 |
|
|
The following has been SUMMARIZED. The complete ChangeLog is
|
127 |
|
|
available in the full Linux-ARCnet package.
|
128 |
|
|
|
129 |
|
|
v2.22 (95/12/08)
|
130 |
|
|
- Major cleanups, speedups, and better code-sharing.
|
131 |
|
|
- Eliminated/changed many useless/meaningless/scary debug messages
|
132 |
|
|
(and, in most cases, the bugs that caused them).
|
133 |
|
|
- Better IPX support.
|
134 |
|
|
- lp->stats updated properly.
|
135 |
|
|
- RECON checking now by default only prints a message if there are
|
136 |
|
|
excessive errors (ie. your cable is probably broken).
|
137 |
|
|
- New RFC1051-compliant "arc0s" virtual device by Tomasz
|
138 |
|
|
Motylewski.
|
139 |
|
|
- Excess debug messages can be compiled out to reduce code size.
|
140 |
|
|
|
141 |
|
|
v2.00 (95/09/06)
|
142 |
|
|
- ARCnet RECON messages are now detected and logged as "carrier"
|
143 |
|
|
errors.
|
144 |
|
|
- The TXACK flag is now checked, and errors are logged.
|
145 |
|
|
- Debug levels are now completely different. See the README.
|
146 |
|
|
- Massive code cleanups, with several no-longer-necessary and some
|
147 |
|
|
completely useless options removed.
|
148 |
|
|
- Multiprotocol support. You can now use the "arc0e" device to
|
149 |
|
|
send "Ethernet-Encapsulation" packets, which are compatible with
|
150 |
|
|
Windows for Workgroups and LAN Manager, and possibly other
|
151 |
|
|
software. See the README for more information.
|
152 |
|
|
|
153 |
|
|
v1.02 (95/06/21)
|
154 |
|
|
- A fix to make "exception" packets sent from Linux receivable
|
155 |
|
|
on other systems. (The protocol_id byte was sometimes being set
|
156 |
|
|
incorrectly, and Linux wasn't checking it on receive so it
|
157 |
|
|
didn't show up)
|
158 |
|
|
|
159 |
|
|
v1.01 (95/03/24)
|
160 |
|
|
- Fixed some IPX-related bugs. (Thanks to Tomasz Motylewski
|
161 |
|
|
<motyl@tichy.ch.uj.edu.pl> for the patches to make arcnet work
|
162 |
|
|
with dosemu!)
|
163 |
|
|
|
164 |
|
|
v1.00 (95/02/15)
|
165 |
|
|
- Initial non-alpha release.
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
TO DO: (semi-prioritized)
|
169 |
|
|
|
170 |
|
|
- Support "arpless" mode like NetBSD does, and as recommended
|
171 |
|
|
by the (obsoleted) RFC1051.
|
172 |
|
|
- Smarter recovery from RECON-during-transmit conditions. (ie.
|
173 |
|
|
retransmit immediately)
|
174 |
|
|
- Make arcnetE_send_packet use arcnet_prepare_tx for loading the
|
175 |
|
|
packet into ARCnet memory.
|
176 |
|
|
- Some cards have shared memory with 4k mirrors instead of just 2k,
|
177 |
|
|
so we (uneventfully) find the "wrong" shmem when probing.
|
178 |
|
|
- Probe for multiple devices in one shot (trying to decide whether
|
179 |
|
|
to do it the "ugly" way or not).
|
180 |
|
|
- Add support for the new 1.3.x IP header cache, and other features.
|
181 |
|
|
- Debug level should be changed with a system call, not a hack to
|
182 |
|
|
the "metric" flag.
|
183 |
|
|
- What about cards with shared memory that can be "turned off?"
|
184 |
|
|
(or that have none at all, like the SMC PC500longboard)
|
185 |
|
|
- Autoconfigure PDI5xxPlus cards. (I now have a PDI508Plus to play
|
186 |
|
|
with temporarily.) Update: yes, the Pure Data config program
|
187 |
|
|
for DOS works fine, but the PDI508Plus I have doesn't! :)
|
188 |
|
|
- Try to implement promiscuous (receive-all-packets) mode available
|
189 |
|
|
on some newer cards with COM20020 and similar chips. I don't have
|
190 |
|
|
one, but SMC sent me the specs.
|
191 |
|
|
- ATA protocol support??
|
192 |
|
|
- VINES TCP/IP encapsulation?? (info needed)
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
Sources:
|
196 |
|
|
- Crynwr arcnet.com/arcether.com packet drivers.
|
197 |
|
|
- arcnet.c v0.00 dated 1/1/94 and apparently by
|
198 |
|
|
Donald Becker - it didn't work :)
|
199 |
|
|
- skeleton.c v0.05 dated 11/16/93 by Donald Becker
|
200 |
|
|
(from Linux Kernel 1.1.45)
|
201 |
|
|
- RFC's 1201 and 1051 - re: TCP/IP over ARCnet
|
202 |
|
|
- The official ARCnet COM9026 data sheets (!) thanks to Ken
|
203 |
|
|
Cornetet <kcornete@nyx10.cs.du.edu>
|
204 |
|
|
- Information on some more obscure ARCnet controller chips, thanks
|
205 |
|
|
to the nice people at SMC.
|
206 |
|
|
- net/inet/eth.c (from kernel 1.1.50) for header-building info.
|
207 |
|
|
- Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
|
208 |
|
|
- Textual information and more alternate source from Joachim Koenig
|
209 |
|
|
<jojo@repas.de>
|
210 |
|
|
*/
|
211 |
|
|
|
212 |
|
|
static const char *version =
|
213 |
|
|
"arcnet.c: v2.56 96/10/18 Avery Pennarun <apenwarr@foxnet.net>\n";
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
#include <linux/module.h>
|
218 |
|
|
#include <linux/config.h>
|
219 |
|
|
#include <linux/version.h>
|
220 |
|
|
|
221 |
|
|
#include <linux/kernel.h>
|
222 |
|
|
#include <linux/sched.h>
|
223 |
|
|
#include <linux/types.h>
|
224 |
|
|
#include <linux/fcntl.h>
|
225 |
|
|
#include <linux/interrupt.h>
|
226 |
|
|
#include <linux/ptrace.h>
|
227 |
|
|
#include <linux/ioport.h>
|
228 |
|
|
#include <linux/in.h>
|
229 |
|
|
#include <linux/malloc.h>
|
230 |
|
|
#include <linux/string.h>
|
231 |
|
|
#include <linux/timer.h>
|
232 |
|
|
#include <linux/errno.h>
|
233 |
|
|
#include <linux/delay.h>
|
234 |
|
|
#include <linux/netdevice.h>
|
235 |
|
|
#include <linux/if_arp.h>
|
236 |
|
|
#include <linux/etherdevice.h>
|
237 |
|
|
#include <linux/skbuff.h>
|
238 |
|
|
|
239 |
|
|
#include <asm/system.h>
|
240 |
|
|
#include <asm/bitops.h>
|
241 |
|
|
#include <asm/io.h>
|
242 |
|
|
#include <asm/dma.h>
|
243 |
|
|
|
244 |
|
|
#include <net/arp.h>
|
245 |
|
|
|
246 |
|
|
/**************************************************************************/
|
247 |
|
|
|
248 |
|
|
/* Normally, the ARCnet device needs to be assigned a name (default arc0).
|
249 |
|
|
* Ethernet devices have a function to automatically try eth0, eth1, etc
|
250 |
|
|
* until a free name is found. To name the ARCnet device using an "eth?"
|
251 |
|
|
* device name, define this option.
|
252 |
|
|
*/
|
253 |
|
|
#undef CONFIG_ARCNET_ETHNAME
|
254 |
|
|
|
255 |
|
|
/* On a fast computer, the buffer copy from memory to the ARCnet card during
|
256 |
|
|
* a transmit can hog the bus just a little too long. SLOW_XMIT_COPY
|
257 |
|
|
* replaces the fast memcpy() with a slower for() loop that seems to solve
|
258 |
|
|
* my problems with ftape.
|
259 |
|
|
*
|
260 |
|
|
* Probably a better solution would be to use memcpy_toio (more portable
|
261 |
|
|
* anyway) and modify that routine to support REALLY_SLOW_IO-style
|
262 |
|
|
* defines; ARCnet probably is not the only driver that can screw up an
|
263 |
|
|
* ftape DMA transfer.
|
264 |
|
|
*
|
265 |
|
|
* Turn this on if you have timing-sensitive DMA (ie. a tape drive) and
|
266 |
|
|
* would like to sacrifice a little bit of network speed to reduce tape
|
267 |
|
|
* write retries or some related problem.
|
268 |
|
|
*/
|
269 |
|
|
#undef SLOW_XMIT_COPY
|
270 |
|
|
|
271 |
|
|
/* The card sends the reconfiguration signal when it loses the connection to
|
272 |
|
|
* the rest of its network. It is a 'Hello, is anybody there?' cry. This
|
273 |
|
|
* usually happens when a new computer on the network is powered on or when
|
274 |
|
|
* the cable is broken.
|
275 |
|
|
*
|
276 |
|
|
* Define DETECT_RECONFIGS if you want to detect network reconfigurations.
|
277 |
|
|
* Recons may be a real nuisance on a larger ARCnet network; if you are a
|
278 |
|
|
* network administrator you probably would like to count them.
|
279 |
|
|
* Reconfigurations will be recorded in stats.tx_carrier_errors (the last
|
280 |
|
|
* field of the /proc/net/dev file).
|
281 |
|
|
*
|
282 |
|
|
* Define SHOW_RECONFIGS if you really want to see a log message whenever
|
283 |
|
|
* a RECON occurs.
|
284 |
|
|
*/
|
285 |
|
|
#define DETECT_RECONFIGS
|
286 |
|
|
#undef SHOW_RECONFIGS
|
287 |
|
|
|
288 |
|
|
/* RECON_THRESHOLD is the maximum number of RECON messages to receive within
|
289 |
|
|
* one minute before printing a "cabling problem" warning. You must have
|
290 |
|
|
* DETECT_RECONFIGS enabled if you want to use this. The default value
|
291 |
|
|
* should be fine.
|
292 |
|
|
*
|
293 |
|
|
* After that, a "cabling restored" message will be printed on the next IRQ
|
294 |
|
|
* if no RECON messages have been received for 10 seconds.
|
295 |
|
|
*
|
296 |
|
|
* Do not define RECON_THRESHOLD at all if you want to disable this feature.
|
297 |
|
|
*/
|
298 |
|
|
#define RECON_THRESHOLD 30
|
299 |
|
|
|
300 |
|
|
/* Define this to the minimum "timeout" value. If a transmit takes longer
|
301 |
|
|
* than TX_TIMEOUT jiffies, Linux will abort the TX and retry. On a large
|
302 |
|
|
* network, or one with heavy network traffic, this timeout may need to be
|
303 |
|
|
* increased. The larger it is, though, the longer it will be between
|
304 |
|
|
* necessary transmits - don't set this too large.
|
305 |
|
|
*/
|
306 |
|
|
#define TX_TIMEOUT 20
|
307 |
|
|
|
308 |
|
|
/* Define this to speed up the autoprobe by assuming if only one io port and
|
309 |
|
|
* shmem are left in the list at Stage 5, they must correspond to each
|
310 |
|
|
* other.
|
311 |
|
|
*
|
312 |
|
|
* This is undefined by default because it might not always be true, and the
|
313 |
|
|
* extra check makes the autoprobe even more careful. Speed demons can turn
|
314 |
|
|
* it on - I think it should be fine if you only have one ARCnet card
|
315 |
|
|
* installed.
|
316 |
|
|
*
|
317 |
|
|
* If no ARCnet cards are installed, this delay never happens anyway and thus
|
318 |
|
|
* the option has no effect.
|
319 |
|
|
*/
|
320 |
|
|
#undef FAST_PROBE
|
321 |
|
|
|
322 |
|
|
/* Define this to speed up "ifconfig up" by moving the card reset command
|
323 |
|
|
* around. This is a new option in 2.41 ALPHA. If it causes problems,
|
324 |
|
|
* undefine this to get the old behaviour; then send me email, because if
|
325 |
|
|
* there are no problems, this option will go away very soon.
|
326 |
|
|
*/
|
327 |
|
|
#define FAST_IFCONFIG
|
328 |
|
|
|
329 |
|
|
/* Define this if you want to make it easier to use the "call trace" when
|
330 |
|
|
* a kernel NULL pointer assignment occurs. Hopefully unnecessary, most of
|
331 |
|
|
* the time. It will make all the function names (and other things) show
|
332 |
|
|
* up as kernel symbols. (especially handy when using arcnet as a module)
|
333 |
|
|
*/
|
334 |
|
|
#undef static
|
335 |
|
|
|
336 |
|
|
/**************************************************************************/
|
337 |
|
|
|
338 |
|
|
/* New debugging bitflags: each option can be enabled individually.
|
339 |
|
|
*
|
340 |
|
|
* These can be set while the driver is running by typing:
|
341 |
|
|
* ifconfig arc0 down metric 1xxx HOSTNAME
|
342 |
|
|
* where 1xxx is 1000 + the debug level you want
|
343 |
|
|
* and HOSTNAME is your hostname/ip address
|
344 |
|
|
* and then resetting your routes.
|
345 |
|
|
*
|
346 |
|
|
* An ioctl() should be used for this instead, someday.
|
347 |
|
|
*
|
348 |
|
|
* Note: only debug flags included in the ARCNET_DEBUG_MAX define will
|
349 |
|
|
* actually be available. GCC will (at least, GCC 2.7.0 will) notice
|
350 |
|
|
* lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
|
351 |
|
|
* them out.
|
352 |
|
|
*/
|
353 |
|
|
#define D_NORMAL 1 /* important operational info */
|
354 |
|
|
#define D_EXTRA 2 /* useful, but non-vital information */
|
355 |
|
|
#define D_INIT 4 /* show init/probe messages */
|
356 |
|
|
#define D_INIT_REASONS 8 /* show reasons for discarding probes */
|
357 |
|
|
/* debug levels below give LOTS of output during normal operation! */
|
358 |
|
|
#define D_DURING 16 /* trace operations (including irq's) */
|
359 |
|
|
#define D_TX 32 /* show tx packets */
|
360 |
|
|
#define D_RX 64 /* show rx packets */
|
361 |
|
|
#define D_SKB 128 /* show skb's */
|
362 |
|
|
|
363 |
|
|
#ifndef ARCNET_DEBUG_MAX
|
364 |
|
|
#define ARCNET_DEBUG_MAX (~0) /* enable ALL debug messages */
|
365 |
|
|
/*#define ARCNET_DEBUG_MAX (D_NORMAL|D_EXTRA|D_INIT|D_INIT_REASONS) */
|
366 |
|
|
/*#define ARCNET_DEBUG_MAX 0 */ /* enable NO messages (bad idea) */
|
367 |
|
|
#endif
|
368 |
|
|
|
369 |
|
|
#ifndef ARCNET_DEBUG
|
370 |
|
|
#define ARCNET_DEBUG (D_NORMAL)
|
371 |
|
|
#endif
|
372 |
|
|
int arcnet_debug = ARCNET_DEBUG;
|
373 |
|
|
|
374 |
|
|
/* macros to simplify debug checking */
|
375 |
|
|
#define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x))
|
376 |
|
|
#define BUGMSG2(x,msg,args...) do{BUGLVL(x) printk(msg, ## args);}while(0)
|
377 |
|
|
#define BUGMSG(x,msg,args...) BUGMSG2(x,"%s%6s: " msg, \
|
378 |
|
|
x==D_NORMAL ? KERN_WARNING : \
|
379 |
|
|
x<=D_INIT_REASONS ? KERN_INFO : KERN_DEBUG , \
|
380 |
|
|
dev->name , ## args)
|
381 |
|
|
|
382 |
|
|
/* Some useful multiprotocol macros. The idea here is that GCC will
|
383 |
|
|
* optimize away multiple tests or assignments to lp->adev. Relying on this
|
384 |
|
|
* results in the cleanest mess possible.
|
385 |
|
|
*/
|
386 |
|
|
#define ADEV lp->adev
|
387 |
|
|
|
388 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
389 |
|
|
#define EDEV lp->edev
|
390 |
|
|
#else
|
391 |
|
|
#define EDEV lp->adev
|
392 |
|
|
#endif
|
393 |
|
|
|
394 |
|
|
#ifdef CONFIG_ARCNET_1051
|
395 |
|
|
#define SDEV lp->sdev
|
396 |
|
|
#else
|
397 |
|
|
#define SDEV lp->adev
|
398 |
|
|
#endif
|
399 |
|
|
|
400 |
|
|
#define TBUSY ADEV->tbusy=EDEV->tbusy=SDEV->tbusy
|
401 |
|
|
#define IF_TBUSY (ADEV->tbusy||EDEV->tbusy||SDEV->tbusy)
|
402 |
|
|
|
403 |
|
|
#define INTERRUPT ADEV->interrupt=EDEV->interrupt=SDEV->interrupt
|
404 |
|
|
#define IF_INTERRUPT (ADEV->interrupt||EDEV->interrupt||SDEV->interrupt)
|
405 |
|
|
|
406 |
|
|
#define START ADEV->start=EDEV->start=SDEV->start
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
/* The number of low I/O ports used by the ethercard. */
|
410 |
|
|
#define ARCNET_TOTAL_SIZE 16
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
/* Handy defines for ARCnet specific stuff */
|
414 |
|
|
/* COM 9026 controller chip --> ARCnet register addresses */
|
415 |
|
|
#define INTMASK (ioaddr+0) /* writable */
|
416 |
|
|
#define STATUS (ioaddr+0) /* readable */
|
417 |
|
|
#define COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
|
418 |
|
|
#define RESET (ioaddr+8) /* software reset writable */
|
419 |
|
|
|
420 |
|
|
#define SETMASK outb(lp->intmask,INTMASK);
|
421 |
|
|
|
422 |
|
|
/* Time needed to reset the card - in jiffies. This works on my SMC
|
423 |
|
|
* PC100. I can't find a reference that tells me just how long I
|
424 |
|
|
* should wait.
|
425 |
|
|
*/
|
426 |
|
|
#define RESETtime (HZ * 3 / 10) /* reset */
|
427 |
|
|
|
428 |
|
|
/* these are the max/min lengths of packet data. (including
|
429 |
|
|
* ClientData header)
|
430 |
|
|
* note: packet sizes 250, 251, 252 are impossible (God knows why)
|
431 |
|
|
* so exception packets become necessary.
|
432 |
|
|
*
|
433 |
|
|
* These numbers are compared with the length of the full packet,
|
434 |
|
|
* including ClientData header.
|
435 |
|
|
*/
|
436 |
|
|
#define MTU 253 /* normal packet max size */
|
437 |
|
|
#define MinTU 257 /* extended packet min size */
|
438 |
|
|
#define XMTU 508 /* extended packet max size */
|
439 |
|
|
|
440 |
|
|
/* status/interrupt mask bit fields */
|
441 |
|
|
#define TXFREEflag 0x01 /* transmitter available */
|
442 |
|
|
#define TXACKflag 0x02 /* transmitted msg. ackd */
|
443 |
|
|
#define RECONflag 0x04 /* system reconfigured */
|
444 |
|
|
#define TESTflag 0x08 /* test flag */
|
445 |
|
|
#define RESETflag 0x10 /* power-on-reset */
|
446 |
|
|
#define RES1flag 0x20 /* reserved - usually set by jumper */
|
447 |
|
|
#define RES2flag 0x40 /* reserved - usually set by jumper */
|
448 |
|
|
#define NORXflag 0x80 /* receiver inhibited */
|
449 |
|
|
|
450 |
|
|
/* in the command register, the following bits have these meanings:
|
451 |
|
|
* 0-2 command
|
452 |
|
|
* 3-4 page number (for enable rcv/xmt command)
|
453 |
|
|
* 7 receive broadcasts
|
454 |
|
|
*/
|
455 |
|
|
#define NOTXcmd 0x01 /* disable transmitter */
|
456 |
|
|
#define NORXcmd 0x02 /* disable receiver */
|
457 |
|
|
#define TXcmd 0x03 /* enable transmitter */
|
458 |
|
|
#define RXcmd 0x04 /* enable receiver */
|
459 |
|
|
#define CONFIGcmd 0x05 /* define configuration */
|
460 |
|
|
#define CFLAGScmd 0x06 /* clear flags */
|
461 |
|
|
#define TESTcmd 0x07 /* load test flags */
|
462 |
|
|
|
463 |
|
|
/* flags for "clear flags" command */
|
464 |
|
|
#define RESETclear 0x08 /* power-on-reset */
|
465 |
|
|
#define CONFIGclear 0x10 /* system reconfigured */
|
466 |
|
|
|
467 |
|
|
/* flags for "load test flags" command */
|
468 |
|
|
#define TESTload 0x08 /* test flag (diagnostic) */
|
469 |
|
|
|
470 |
|
|
/* byte deposited into first address of buffers on reset */
|
471 |
|
|
#define TESTvalue 0321 /* that's octal for 0xD1 :) */
|
472 |
|
|
|
473 |
|
|
/* for "enable receiver" command */
|
474 |
|
|
#define RXbcasts 0x80 /* receive broadcasts */
|
475 |
|
|
|
476 |
|
|
/* flags for "define configuration" command */
|
477 |
|
|
#define NORMALconf 0x00 /* 1-249 byte packets */
|
478 |
|
|
#define EXTconf 0x08 /* 250-504 byte packets */
|
479 |
|
|
|
480 |
|
|
/* Starts receiving packets into recbuf.
|
481 |
|
|
*/
|
482 |
|
|
#define EnableReceiver() outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
|
483 |
|
|
|
484 |
|
|
/* RFC1201 Protocol ID's */
|
485 |
|
|
#define ARC_P_IP 212 /* 0xD4 */
|
486 |
|
|
#define ARC_P_ARP 213 /* 0xD5 */
|
487 |
|
|
#define ARC_P_RARP 214 /* 0xD6 */
|
488 |
|
|
#define ARC_P_IPX 250 /* 0xFA */
|
489 |
|
|
#define ARC_P_NOVELL_EC 236 /* 0xEC */
|
490 |
|
|
|
491 |
|
|
/* Old RFC1051 Protocol ID's */
|
492 |
|
|
#define ARC_P_IP_RFC1051 240 /* 0xF0 */
|
493 |
|
|
#define ARC_P_ARP_RFC1051 241 /* 0xF1 */
|
494 |
|
|
|
495 |
|
|
/* MS LanMan/WfWg protocol */
|
496 |
|
|
#define ARC_P_ETHER 0xE8
|
497 |
|
|
|
498 |
|
|
/* Unsupported/indirectly supported protocols */
|
499 |
|
|
#define ARC_P_LANSOFT 251 /* 0xFB - what is this? */
|
500 |
|
|
#define ARC_P_ATALK 0xDD
|
501 |
|
|
|
502 |
|
|
/* the header required by the card itself */
|
503 |
|
|
struct HardHeader
|
504 |
|
|
{
|
505 |
|
|
u_char source, /* source ARCnet - filled in automagically */
|
506 |
|
|
destination, /* destination ARCnet - 0 for broadcast */
|
507 |
|
|
offset1, /* offset of ClientData (256-byte packets) */
|
508 |
|
|
offset2; /* offset of ClientData (512-byte packets) */
|
509 |
|
|
};
|
510 |
|
|
|
511 |
|
|
/* a complete ARCnet packet */
|
512 |
|
|
union ArcPacket
|
513 |
|
|
{
|
514 |
|
|
struct HardHeader hardheader; /* the hardware header */
|
515 |
|
|
u_char raw[512]; /* raw packet info, incl ClientData */
|
516 |
|
|
};
|
517 |
|
|
|
518 |
|
|
/* the "client data" header - RFC1201 information
|
519 |
|
|
* notice that this screws up if it's not an even number of bytes
|
520 |
|
|
* <sigh>
|
521 |
|
|
*/
|
522 |
|
|
struct ClientData
|
523 |
|
|
{
|
524 |
|
|
/* data that's NOT part of real packet - we MUST get rid of it before
|
525 |
|
|
* actually sending!!
|
526 |
|
|
*/
|
527 |
|
|
u_char saddr, /* Source address - needed for IPX */
|
528 |
|
|
daddr; /* Destination address */
|
529 |
|
|
|
530 |
|
|
/* data that IS part of real packet */
|
531 |
|
|
u_char protocol_id, /* ARC_P_IP, ARC_P_ARP, etc */
|
532 |
|
|
split_flag; /* for use with split packets */
|
533 |
|
|
u_short sequence; /* sequence number */
|
534 |
|
|
};
|
535 |
|
|
#define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
/* the "client data" header - RFC1051 information
|
539 |
|
|
* this also screws up if it's not an even number of bytes
|
540 |
|
|
* <sigh again>
|
541 |
|
|
*/
|
542 |
|
|
struct S_ClientData
|
543 |
|
|
{
|
544 |
|
|
/* data that's NOT part of real packet - we MUST get rid of it before
|
545 |
|
|
* actually sending!!
|
546 |
|
|
*/
|
547 |
|
|
u_char saddr, /* Source address - needed for IPX */
|
548 |
|
|
daddr, /* Destination address */
|
549 |
|
|
junk; /* padding to make an even length */
|
550 |
|
|
|
551 |
|
|
/* data that IS part of real packet */
|
552 |
|
|
u_char protocol_id; /* ARC_P_IP, ARC_P_ARP, etc */
|
553 |
|
|
};
|
554 |
|
|
#define S_EXTRA_CLIENTDATA (sizeof(struct S_ClientData)-1)
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
/* "Incoming" is information needed for each address that could be sending
|
558 |
|
|
* to us. Mostly for partially-received split packets.
|
559 |
|
|
*/
|
560 |
|
|
struct Incoming
|
561 |
|
|
{
|
562 |
|
|
struct sk_buff *skb; /* packet data buffer */
|
563 |
|
|
unsigned char lastpacket, /* number of last packet (from 1) */
|
564 |
|
|
numpackets; /* number of packets in split */
|
565 |
|
|
u_short sequence; /* sequence number of assembly */
|
566 |
|
|
};
|
567 |
|
|
|
568 |
|
|
struct Outgoing
|
569 |
|
|
{
|
570 |
|
|
struct sk_buff *skb; /* buffer from upper levels */
|
571 |
|
|
struct ClientData *hdr; /* clientdata of last packet */
|
572 |
|
|
u_char *data; /* pointer to data in packet */
|
573 |
|
|
short length, /* bytes total */
|
574 |
|
|
dataleft, /* bytes left */
|
575 |
|
|
segnum, /* segment being sent */
|
576 |
|
|
numsegs, /* number of segments */
|
577 |
|
|
seglen; /* length of segment */
|
578 |
|
|
};
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
/* Information that needs to be kept for each board. */
|
582 |
|
|
struct arcnet_local {
|
583 |
|
|
struct enet_statistics stats;
|
584 |
|
|
u_short sequence; /* sequence number (incs with each packet) */
|
585 |
|
|
u_char stationid, /* our 8-bit station address */
|
586 |
|
|
recbuf, /* receive buffer # (0 or 1) */
|
587 |
|
|
txbuf, /* transmit buffer # (2 or 3) */
|
588 |
|
|
txready, /* buffer where a packet is ready to send */
|
589 |
|
|
intmask; /* current value of INTMASK register */
|
590 |
|
|
short intx, /* in TX routine? */
|
591 |
|
|
in_txhandler, /* in TX_IRQ handler? */
|
592 |
|
|
sending, /* transmit in progress? */
|
593 |
|
|
lastload_dest, /* can last loaded packet be acked? */
|
594 |
|
|
lasttrans_dest; /* can last TX'd packet be acked? */
|
595 |
|
|
|
596 |
|
|
#if defined(DETECT_RECONFIGS) && defined(RECON_THRESHOLD)
|
597 |
|
|
time_t first_recon, /* time of "first" RECON message to count */
|
598 |
|
|
last_recon; /* time of most recent RECON */
|
599 |
|
|
int num_recons, /* number of RECONs between first and last. */
|
600 |
|
|
network_down; /* do we think the network is down? */
|
601 |
|
|
#endif
|
602 |
|
|
|
603 |
|
|
struct timer_list timer; /* the timer interrupt struct */
|
604 |
|
|
struct Incoming incoming[256]; /* one from each address */
|
605 |
|
|
struct Outgoing outgoing; /* packet currently being sent */
|
606 |
|
|
|
607 |
|
|
struct device *adev; /* RFC1201 protocol device */
|
608 |
|
|
|
609 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
610 |
|
|
struct device *edev; /* Ethernet-Encap device */
|
611 |
|
|
#endif
|
612 |
|
|
|
613 |
|
|
#ifdef CONFIG_ARCNET_1051
|
614 |
|
|
struct device *sdev; /* RFC1051 protocol device */
|
615 |
|
|
#endif
|
616 |
|
|
};
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
/* Index to functions, as function prototypes. */
|
620 |
|
|
|
621 |
|
|
#if ARCNET_DEBUG_MAX & D_SKB
|
622 |
|
|
static void arcnet_dump_skb(struct device *dev,struct sk_buff *skb,
|
623 |
|
|
char *desc);
|
624 |
|
|
#else
|
625 |
|
|
# define arcnet_dump_skb(dev,skb,desc) ;
|
626 |
|
|
#endif
|
627 |
|
|
|
628 |
|
|
#if (ARCNET_DEBUG_MAX & D_RX) || (ARCNET_DEBUG_MAX & D_TX)
|
629 |
|
|
static void arcnet_dump_packet(struct device *dev,u_char *buffer,int ext,
|
630 |
|
|
char *desc);
|
631 |
|
|
#else
|
632 |
|
|
# define arcnet_dump_packet(dev,buffer,ext,desc) ;
|
633 |
|
|
#endif
|
634 |
|
|
|
635 |
|
|
extern int arcnet_probe(struct device *dev);
|
636 |
|
|
static int arcnet_found(struct device *dev,int port,int airq,u_long shmem);
|
637 |
|
|
|
638 |
|
|
static void arcnet_setup(struct device *dev);
|
639 |
|
|
static int arcnet_open(struct device *dev);
|
640 |
|
|
static int arcnet_close(struct device *dev);
|
641 |
|
|
static int arcnet_reset(struct device *dev,int reset_delay);
|
642 |
|
|
|
643 |
|
|
static int arcnet_send_packet_bad(struct sk_buff *skb,struct device *dev);
|
644 |
|
|
static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
|
645 |
|
|
static void arcnetA_continue_tx(struct device *dev);
|
646 |
|
|
static void arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
|
647 |
|
|
char *data,int length,int daddr,int exceptA);
|
648 |
|
|
static int arcnet_go_tx(struct device *dev,int enable_irq);
|
649 |
|
|
|
650 |
|
|
static void arcnet_interrupt(int irq,void *dev_id,struct pt_regs *regs);
|
651 |
|
|
static void arcnet_inthandler(struct device *dev);
|
652 |
|
|
|
653 |
|
|
static void arcnet_rx(struct device *dev,int recbuf);
|
654 |
|
|
static void arcnetA_rx(struct device *dev,u_char *buf,
|
655 |
|
|
int length,u_char saddr, u_char daddr);
|
656 |
|
|
|
657 |
|
|
static struct enet_statistics *arcnet_get_stats(struct device *dev);
|
658 |
|
|
|
659 |
|
|
int arcnetA_header(struct sk_buff *skb,struct device *dev,
|
660 |
|
|
unsigned short type,void *daddr,void *saddr,unsigned len);
|
661 |
|
|
int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
|
662 |
|
|
struct sk_buff *skb);
|
663 |
|
|
unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
|
664 |
|
|
|
665 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
666 |
|
|
/* functions specific to Ethernet-Encap */
|
667 |
|
|
static int arcnetE_init(struct device *dev);
|
668 |
|
|
static int arcnetE_open_close(struct device *dev);
|
669 |
|
|
static int arcnetE_send_packet(struct sk_buff *skb, struct device *dev);
|
670 |
|
|
static void arcnetE_rx(struct device *dev,u_char *arcsoft,
|
671 |
|
|
int length,u_char saddr, u_char daddr);
|
672 |
|
|
#endif
|
673 |
|
|
|
674 |
|
|
#ifdef CONFIG_ARCNET_1051
|
675 |
|
|
/* functions specific to RFC1051 */
|
676 |
|
|
static int arcnetS_init(struct device *dev);
|
677 |
|
|
static int arcnetS_open_close(struct device *dev);
|
678 |
|
|
static int arcnetS_send_packet(struct sk_buff *skb, struct device *dev);
|
679 |
|
|
static void arcnetS_rx(struct device *dev,u_char *buf,
|
680 |
|
|
int length,u_char saddr, u_char daddr);
|
681 |
|
|
int arcnetS_header(struct sk_buff *skb,struct device *dev,
|
682 |
|
|
unsigned short type,void *daddr,void *saddr,unsigned len);
|
683 |
|
|
int arcnetS_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
|
684 |
|
|
struct sk_buff *skb);
|
685 |
|
|
unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev);
|
686 |
|
|
#endif
|
687 |
|
|
|
688 |
|
|
#ifdef MODULE
|
689 |
|
|
int init_module(void);
|
690 |
|
|
void cleanup_module(void);
|
691 |
|
|
#endif
|
692 |
|
|
|
693 |
|
|
#define tx_done(dev) 1
|
694 |
|
|
|
695 |
|
|
#define JIFFER(time) for (delayval=jiffies+time; jiffies<delayval;) ;
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
/****************************************************************************
|
699 |
|
|
* *
|
700 |
|
|
* Packet dumps for debugging *
|
701 |
|
|
* *
|
702 |
|
|
****************************************************************************/
|
703 |
|
|
|
704 |
|
|
/* Dump the contents of an sk_buff
|
705 |
|
|
*/
|
706 |
|
|
#if ARCNET_DEBUG_MAX & D_SKB
|
707 |
|
|
void arcnet_dump_skb(struct device *dev,struct sk_buff *skb,char *desc)
|
708 |
|
|
{
|
709 |
|
|
int i;
|
710 |
|
|
long flags;
|
711 |
|
|
|
712 |
|
|
save_flags(flags);
|
713 |
|
|
cli();
|
714 |
|
|
printk(KERN_DEBUG "%6s: skb dump (%s) follows:",dev->name,desc);
|
715 |
|
|
for(i=0; i<skb->len; i++)
|
716 |
|
|
{
|
717 |
|
|
if (i%16==0)
|
718 |
|
|
printk("\n" KERN_DEBUG "[%04X] ",i);
|
719 |
|
|
printk("%02X ",((u_char *)skb->data)[i]);
|
720 |
|
|
}
|
721 |
|
|
printk("\n");
|
722 |
|
|
restore_flags(flags);
|
723 |
|
|
}
|
724 |
|
|
#endif
|
725 |
|
|
|
726 |
|
|
/* Dump the contents of an ARCnet buffer
|
727 |
|
|
*/
|
728 |
|
|
#if (ARCNET_DEBUG_MAX & D_RX) || (ARCNET_DEBUG_MAX & D_TX)
|
729 |
|
|
void arcnet_dump_packet(struct device *dev,u_char *buffer,int ext,char *desc)
|
730 |
|
|
{
|
731 |
|
|
int i;
|
732 |
|
|
long flags;
|
733 |
|
|
|
734 |
|
|
save_flags(flags);
|
735 |
|
|
cli();
|
736 |
|
|
printk(KERN_DEBUG "%6s: packet dump (%s) follows:",dev->name,desc);
|
737 |
|
|
for (i=0; i<256+(ext!=0)*256; i++)
|
738 |
|
|
{
|
739 |
|
|
if (i%16==0)
|
740 |
|
|
printk("\n" KERN_DEBUG "[%04X] ",i);
|
741 |
|
|
printk("%02X ",buffer[i]);
|
742 |
|
|
}
|
743 |
|
|
printk("\n");
|
744 |
|
|
restore_flags(flags);
|
745 |
|
|
}
|
746 |
|
|
#endif
|
747 |
|
|
|
748 |
|
|
/****************************************************************************
|
749 |
|
|
* *
|
750 |
|
|
* Probe and initialization *
|
751 |
|
|
* *
|
752 |
|
|
****************************************************************************/
|
753 |
|
|
|
754 |
|
|
/* Check for an ARCnet network adaptor, and return '0' if one exists.
|
755 |
|
|
* If dev->base_addr == 0, probe all likely locations.
|
756 |
|
|
* If dev->base_addr == 1, always return failure.
|
757 |
|
|
* If dev->base_addr == 2, allocate space for the device and return success
|
758 |
|
|
* (detachable devices only).
|
759 |
|
|
*
|
760 |
|
|
* NOTE: the list of possible ports/shmems is static, so it is retained
|
761 |
|
|
* across calls to arcnet_probe. So, if more than one ARCnet probe is made,
|
762 |
|
|
* values that were discarded once will not even be tried again.
|
763 |
|
|
*
|
764 |
|
|
* FIXME: grab all devices in one shot and eliminate the big static array.
|
765 |
|
|
*/
|
766 |
|
|
int arcnet_probe(struct device *dev)
|
767 |
|
|
{
|
768 |
|
|
static int init_once = 0;
|
769 |
|
|
static int ports[(0x3f0 - 0x200) / 16 + 1];
|
770 |
|
|
static u_long shmems[(0xFF800 - 0xA0000) / 2048 + 1];
|
771 |
|
|
static int numports=sizeof(ports)/sizeof(ports[0]),
|
772 |
|
|
numshmems=sizeof(shmems)/sizeof(shmems[0]);
|
773 |
|
|
|
774 |
|
|
int count,status,delayval,ioaddr,numprint,airq,retval=-ENODEV,
|
775 |
|
|
openparen=0;
|
776 |
|
|
unsigned long airqmask;
|
777 |
|
|
int *port;
|
778 |
|
|
u_long *shmem;
|
779 |
|
|
|
780 |
|
|
if (!init_once)
|
781 |
|
|
{
|
782 |
|
|
for (count=0x200; count<=0x3f0; count+=16)
|
783 |
|
|
ports[(count-0x200)/16] = count;
|
784 |
|
|
for (count=0xA0000; count<=0xFF800; count+=2048)
|
785 |
|
|
shmems[(count-0xA0000)/2048] = count;
|
786 |
|
|
init_once=1;
|
787 |
|
|
}
|
788 |
|
|
|
789 |
|
|
BUGLVL(D_NORMAL) printk(version);
|
790 |
|
|
|
791 |
|
|
BUGMSG(D_DURING,"space used for probe buffers: %d+%d=%d bytes\n",
|
792 |
|
|
sizeof(ports),sizeof(shmems),
|
793 |
|
|
sizeof(ports)+sizeof(shmems));
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
#if 0
|
797 |
|
|
BUGLVL(D_EXTRA)
|
798 |
|
|
{
|
799 |
|
|
printk("arcnet: ***\n");
|
800 |
|
|
printk("arcnet: * Read arcnet.txt for important release notes!\n");
|
801 |
|
|
printk("arcnet: *\n");
|
802 |
|
|
printk("arcnet: * This is an ALPHA version! (Last stable release: v2.22) E-mail me if\n");
|
803 |
|
|
printk("arcnet: * you have any questions, comments, or bug reports.\n");
|
804 |
|
|
printk("arcnet: ***\n");
|
805 |
|
|
}
|
806 |
|
|
#endif
|
807 |
|
|
|
808 |
|
|
BUGMSG(D_INIT,"given: base %lXh, IRQ %d, shmem %lXh\n",
|
809 |
|
|
dev->base_addr,dev->irq,dev->mem_start);
|
810 |
|
|
|
811 |
|
|
if (dev->base_addr > 0x1ff) /* Check a single specified port */
|
812 |
|
|
{
|
813 |
|
|
ports[0]=dev->base_addr;
|
814 |
|
|
numports=1;
|
815 |
|
|
}
|
816 |
|
|
else if (dev->base_addr > 0) /* Don't probe at all. */
|
817 |
|
|
return -ENXIO;
|
818 |
|
|
|
819 |
|
|
if (dev->mem_start)
|
820 |
|
|
{
|
821 |
|
|
shmems[0]=dev->mem_start;
|
822 |
|
|
numshmems=1;
|
823 |
|
|
}
|
824 |
|
|
|
825 |
|
|
|
826 |
|
|
/* Stage 1: abandon any reserved ports, or ones with status==0xFF
|
827 |
|
|
* (empty), and reset any others by reading the reset port.
|
828 |
|
|
*/
|
829 |
|
|
BUGMSG(D_INIT,"Stage 1: ");
|
830 |
|
|
numprint=0;
|
831 |
|
|
for (port = &ports[0]; port-ports<numports; port++)
|
832 |
|
|
{
|
833 |
|
|
numprint++;
|
834 |
|
|
if (numprint>8)
|
835 |
|
|
{
|
836 |
|
|
BUGMSG2(D_INIT,"\n");
|
837 |
|
|
BUGMSG(D_INIT,"Stage 1: ");
|
838 |
|
|
numprint=1;
|
839 |
|
|
}
|
840 |
|
|
BUGMSG2(D_INIT,"%Xh ",*port);
|
841 |
|
|
|
842 |
|
|
ioaddr=*port;
|
843 |
|
|
|
844 |
|
|
if (check_region(*port, ARCNET_TOTAL_SIZE))
|
845 |
|
|
{
|
846 |
|
|
BUGMSG2(D_INIT_REASONS,"(check_region)\n");
|
847 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 1: ");
|
848 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
849 |
|
|
*port=ports[numports-1];
|
850 |
|
|
numports--;
|
851 |
|
|
port--;
|
852 |
|
|
continue;
|
853 |
|
|
}
|
854 |
|
|
|
855 |
|
|
if (inb(STATUS) == 0xFF)
|
856 |
|
|
{
|
857 |
|
|
BUGMSG2(D_INIT_REASONS,"(empty)\n");
|
858 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 1: ");
|
859 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
860 |
|
|
*port=ports[numports-1];
|
861 |
|
|
numports--;
|
862 |
|
|
port--;
|
863 |
|
|
continue;
|
864 |
|
|
}
|
865 |
|
|
|
866 |
|
|
inb(RESET); /* begin resetting card */
|
867 |
|
|
|
868 |
|
|
BUGMSG2(D_INIT_REASONS,"\n");
|
869 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 1: ");
|
870 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
871 |
|
|
}
|
872 |
|
|
BUGMSG2(D_INIT,"\n");
|
873 |
|
|
|
874 |
|
|
if (!numports)
|
875 |
|
|
{
|
876 |
|
|
BUGMSG(D_NORMAL,"Stage 1: No ARCnet cards found.\n");
|
877 |
|
|
return -ENODEV;
|
878 |
|
|
}
|
879 |
|
|
|
880 |
|
|
|
881 |
|
|
/* Stage 2: we have now reset any possible ARCnet cards, so we can't
|
882 |
|
|
* do anything until they finish. If D_INIT, print the list of
|
883 |
|
|
* cards that are left.
|
884 |
|
|
*/
|
885 |
|
|
BUGMSG(D_INIT,"Stage 2: ");
|
886 |
|
|
numprint=0;
|
887 |
|
|
for (port = &ports[0]; port-ports<numports; port++)
|
888 |
|
|
{
|
889 |
|
|
numprint++;
|
890 |
|
|
if (numprint>8)
|
891 |
|
|
{
|
892 |
|
|
BUGMSG2(D_INIT,"\n");
|
893 |
|
|
BUGMSG(D_INIT,"Stage 2: ");
|
894 |
|
|
numprint=1;
|
895 |
|
|
}
|
896 |
|
|
BUGMSG2(D_INIT,"%Xh ",*port);
|
897 |
|
|
}
|
898 |
|
|
BUGMSG2(D_INIT,"\n");
|
899 |
|
|
JIFFER(RESETtime);
|
900 |
|
|
|
901 |
|
|
|
902 |
|
|
/* Stage 3: abandon any shmem addresses that don't have the signature
|
903 |
|
|
* 0xD1 byte in the right place, or are read-only.
|
904 |
|
|
*/
|
905 |
|
|
BUGMSG(D_INIT,"Stage 3: ");
|
906 |
|
|
numprint=0;
|
907 |
|
|
for (shmem = &shmems[0]; shmem-shmems<numshmems; shmem++)
|
908 |
|
|
{
|
909 |
|
|
volatile u_char *cptr;
|
910 |
|
|
|
911 |
|
|
numprint++;
|
912 |
|
|
if (numprint>8)
|
913 |
|
|
{
|
914 |
|
|
BUGMSG2(D_INIT,"\n");
|
915 |
|
|
BUGMSG(D_INIT,"Stage 3: ");
|
916 |
|
|
numprint=1;
|
917 |
|
|
}
|
918 |
|
|
BUGMSG2(D_INIT,"%lXh ",*shmem);
|
919 |
|
|
|
920 |
|
|
cptr=(u_char *)(*shmem);
|
921 |
|
|
|
922 |
|
|
if (*cptr != TESTvalue)
|
923 |
|
|
{
|
924 |
|
|
BUGMSG2(D_INIT_REASONS,"(mem=%02Xh, not %02Xh)\n",
|
925 |
|
|
*cptr,TESTvalue);
|
926 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 3: ");
|
927 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
928 |
|
|
*shmem=shmems[numshmems-1];
|
929 |
|
|
numshmems--;
|
930 |
|
|
shmem--;
|
931 |
|
|
continue;
|
932 |
|
|
}
|
933 |
|
|
|
934 |
|
|
/* By writing 0x42 to the TESTvalue location, we also make
|
935 |
|
|
* sure no "mirror" shmem areas show up - if they occur
|
936 |
|
|
* in another pass through this loop, they will be discarded
|
937 |
|
|
* because *cptr != TESTvalue.
|
938 |
|
|
*/
|
939 |
|
|
*cptr=0x42;
|
940 |
|
|
if (*cptr != 0x42)
|
941 |
|
|
{
|
942 |
|
|
BUGMSG2(D_INIT_REASONS,"(read only)\n");
|
943 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 3: ");
|
944 |
|
|
*shmem=shmems[numshmems-1];
|
945 |
|
|
numshmems--;
|
946 |
|
|
shmem--;
|
947 |
|
|
continue;
|
948 |
|
|
}
|
949 |
|
|
|
950 |
|
|
BUGMSG2(D_INIT_REASONS,"\n");
|
951 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 3: ");
|
952 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
953 |
|
|
}
|
954 |
|
|
BUGMSG2(D_INIT,"\n");
|
955 |
|
|
|
956 |
|
|
if (!numshmems)
|
957 |
|
|
{
|
958 |
|
|
BUGMSG(D_NORMAL,"Stage 3: No ARCnet cards found.\n");
|
959 |
|
|
return -ENODEV;
|
960 |
|
|
}
|
961 |
|
|
|
962 |
|
|
/* Stage 4: something of a dummy, to report the shmems that are
|
963 |
|
|
* still possible after stage 3.
|
964 |
|
|
*/
|
965 |
|
|
BUGMSG(D_INIT,"Stage 4: ");
|
966 |
|
|
numprint=0;
|
967 |
|
|
for (shmem = &shmems[0]; shmem-shmems<numshmems; shmem++)
|
968 |
|
|
{
|
969 |
|
|
numprint++;
|
970 |
|
|
if (numprint>8)
|
971 |
|
|
{
|
972 |
|
|
BUGMSG2(D_INIT,"\n");
|
973 |
|
|
BUGMSG(D_INIT,"Stage 4: ");
|
974 |
|
|
numprint=1;
|
975 |
|
|
}
|
976 |
|
|
BUGMSG2(D_INIT,"%lXh ",*shmem);
|
977 |
|
|
}
|
978 |
|
|
BUGMSG2(D_INIT,"\n");
|
979 |
|
|
|
980 |
|
|
|
981 |
|
|
/* Stage 5: for any ports that have the correct status, can disable
|
982 |
|
|
* the RESET flag, and (if no irq is given) generate an autoirq,
|
983 |
|
|
* register an ARCnet device.
|
984 |
|
|
*
|
985 |
|
|
* Currently, we can only register one device per probe, so quit
|
986 |
|
|
* after the first one is found.
|
987 |
|
|
*/
|
988 |
|
|
BUGMSG(D_INIT,"Stage 5: ");
|
989 |
|
|
numprint=0;
|
990 |
|
|
for (port = &ports[0]; port-ports<numports; port++)
|
991 |
|
|
{
|
992 |
|
|
numprint++;
|
993 |
|
|
if (numprint>8)
|
994 |
|
|
{
|
995 |
|
|
BUGMSG2(D_INIT,"\n");
|
996 |
|
|
BUGMSG(D_INIT,"Stage 5: ");
|
997 |
|
|
numprint=1;
|
998 |
|
|
}
|
999 |
|
|
BUGMSG2(D_INIT,"%Xh ",*port);
|
1000 |
|
|
|
1001 |
|
|
ioaddr=*port;
|
1002 |
|
|
status=inb(STATUS);
|
1003 |
|
|
|
1004 |
|
|
if ((status & 0x9D)
|
1005 |
|
|
!= (NORXflag|RECONflag|TXFREEflag|RESETflag))
|
1006 |
|
|
{
|
1007 |
|
|
BUGMSG2(D_INIT_REASONS,"(status=%Xh)\n",status);
|
1008 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 5: ");
|
1009 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
1010 |
|
|
*port=ports[numports-1];
|
1011 |
|
|
numports--;
|
1012 |
|
|
port--;
|
1013 |
|
|
continue;
|
1014 |
|
|
}
|
1015 |
|
|
|
1016 |
|
|
outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
|
1017 |
|
|
status=inb(STATUS);
|
1018 |
|
|
if (status & RESETflag)
|
1019 |
|
|
{
|
1020 |
|
|
BUGMSG2(D_INIT_REASONS," (eternal reset, status=%Xh)\n",
|
1021 |
|
|
status);
|
1022 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 5: ");
|
1023 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
1024 |
|
|
*port=ports[numports-1];
|
1025 |
|
|
numports--;
|
1026 |
|
|
port--;
|
1027 |
|
|
continue;
|
1028 |
|
|
}
|
1029 |
|
|
|
1030 |
|
|
/* skip this completely if an IRQ was given, because maybe
|
1031 |
|
|
* we're on a machine that locks during autoirq!
|
1032 |
|
|
*/
|
1033 |
|
|
if (!dev->irq)
|
1034 |
|
|
{
|
1035 |
|
|
/* if we do this, we're sure to get an IRQ since the
|
1036 |
|
|
* card has just reset and the NORXflag is on until
|
1037 |
|
|
* we tell it to start receiving.
|
1038 |
|
|
*/
|
1039 |
|
|
airqmask = probe_irq_on();
|
1040 |
|
|
outb(NORXflag,INTMASK);
|
1041 |
|
|
udelay(1);
|
1042 |
|
|
outb(0,INTMASK);
|
1043 |
|
|
airq = probe_irq_off(airqmask);
|
1044 |
|
|
|
1045 |
|
|
if (airq<=0)
|
1046 |
|
|
{
|
1047 |
|
|
BUGMSG2(D_INIT_REASONS,"(airq=%d)\n",airq);
|
1048 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 5: ");
|
1049 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
1050 |
|
|
*port=ports[numports-1];
|
1051 |
|
|
numports--;
|
1052 |
|
|
port--;
|
1053 |
|
|
continue;
|
1054 |
|
|
}
|
1055 |
|
|
}
|
1056 |
|
|
else
|
1057 |
|
|
{
|
1058 |
|
|
airq=dev->irq;
|
1059 |
|
|
}
|
1060 |
|
|
|
1061 |
|
|
BUGMSG2(D_INIT,"(%d,", airq);
|
1062 |
|
|
openparen=1;
|
1063 |
|
|
|
1064 |
|
|
/* Everything seems okay. But which shmem, if any, puts
|
1065 |
|
|
* back its signature byte when the card is reset?
|
1066 |
|
|
*
|
1067 |
|
|
* If there are multiple cards installed, there might be
|
1068 |
|
|
* multiple shmems still in the list.
|
1069 |
|
|
*/
|
1070 |
|
|
#ifdef FAST_PROBE
|
1071 |
|
|
if (numports>1 || numshmems>1)
|
1072 |
|
|
{
|
1073 |
|
|
inb(RESET);
|
1074 |
|
|
JIFFER(RESETtime);
|
1075 |
|
|
}
|
1076 |
|
|
else
|
1077 |
|
|
{
|
1078 |
|
|
/* just one shmem and port, assume they match */
|
1079 |
|
|
*(u_char *)(shmems[0]) = TESTvalue;
|
1080 |
|
|
}
|
1081 |
|
|
#else
|
1082 |
|
|
inb(RESET);
|
1083 |
|
|
JIFFER(RESETtime);
|
1084 |
|
|
#endif
|
1085 |
|
|
|
1086 |
|
|
|
1087 |
|
|
for (shmem = &shmems[0]; shmem-shmems<numshmems; shmem++)
|
1088 |
|
|
{
|
1089 |
|
|
u_char *cptr;
|
1090 |
|
|
cptr=(u_char *)(*shmem);
|
1091 |
|
|
|
1092 |
|
|
if (*cptr == TESTvalue) /* found one */
|
1093 |
|
|
{
|
1094 |
|
|
BUGMSG2(D_INIT,"%lXh)\n", *shmem);
|
1095 |
|
|
openparen=0;
|
1096 |
|
|
|
1097 |
|
|
/* register the card */
|
1098 |
|
|
retval=arcnet_found(dev,*port,airq,*shmem);
|
1099 |
|
|
if (retval) openparen=0;
|
1100 |
|
|
|
1101 |
|
|
/* remove shmem from the list */
|
1102 |
|
|
*shmem=shmems[numshmems-1];
|
1103 |
|
|
numshmems--;
|
1104 |
|
|
|
1105 |
|
|
break;
|
1106 |
|
|
}
|
1107 |
|
|
else
|
1108 |
|
|
{
|
1109 |
|
|
BUGMSG2(D_INIT_REASONS,"%Xh-", *cptr);
|
1110 |
|
|
}
|
1111 |
|
|
}
|
1112 |
|
|
|
1113 |
|
|
if (openparen)
|
1114 |
|
|
{
|
1115 |
|
|
BUGMSG2(D_INIT,"no matching shmem)\n");
|
1116 |
|
|
BUGMSG(D_INIT_REASONS,"Stage 5: ");
|
1117 |
|
|
BUGLVL(D_INIT_REASONS) numprint=0;
|
1118 |
|
|
}
|
1119 |
|
|
|
1120 |
|
|
*port=ports[numports-1];
|
1121 |
|
|
numports--;
|
1122 |
|
|
port--;
|
1123 |
|
|
|
1124 |
|
|
if (!retval) break;
|
1125 |
|
|
}
|
1126 |
|
|
BUGMSG(D_INIT_REASONS,"\n");
|
1127 |
|
|
|
1128 |
|
|
/* Now put back TESTvalue on all leftover shmems.
|
1129 |
|
|
*/
|
1130 |
|
|
for (shmem = &shmems[0]; shmem-shmems<numshmems; shmem++)
|
1131 |
|
|
*(u_char *)(*shmem) = TESTvalue;
|
1132 |
|
|
|
1133 |
|
|
if (retval) BUGMSG(D_NORMAL,"Stage 5: No ARCnet cards found.\n");
|
1134 |
|
|
return retval;
|
1135 |
|
|
}
|
1136 |
|
|
|
1137 |
|
|
/* Set up the struct device associated with this card. Called after
|
1138 |
|
|
* probing succeeds.
|
1139 |
|
|
*/
|
1140 |
|
|
int arcnet_found(struct device *dev,int port,int airq, u_long shmem)
|
1141 |
|
|
{
|
1142 |
|
|
u_char *first_mirror,*last_mirror;
|
1143 |
|
|
struct arcnet_local *lp;
|
1144 |
|
|
|
1145 |
|
|
/* reserve the I/O region */
|
1146 |
|
|
request_region(port,ARCNET_TOTAL_SIZE,"arcnet");
|
1147 |
|
|
dev->base_addr=port;
|
1148 |
|
|
|
1149 |
|
|
/* reserve the irq */
|
1150 |
|
|
if (request_irq(airq,&arcnet_interrupt,0,"arcnet",NULL))
|
1151 |
|
|
{
|
1152 |
|
|
BUGMSG(D_NORMAL,"Can't get IRQ %d!\n",airq);
|
1153 |
|
|
release_region(port,ARCNET_TOTAL_SIZE);
|
1154 |
|
|
return -ENODEV;
|
1155 |
|
|
}
|
1156 |
|
|
irq2dev_map[airq]=dev;
|
1157 |
|
|
dev->irq=airq;
|
1158 |
|
|
|
1159 |
|
|
/* find the real shared memory start/end points, including mirrors */
|
1160 |
|
|
|
1161 |
|
|
#define BUFFER_SIZE (512)
|
1162 |
|
|
#define MIRROR_SIZE (BUFFER_SIZE*4)
|
1163 |
|
|
|
1164 |
|
|
first_mirror=last_mirror=(u_char *)shmem;
|
1165 |
|
|
while (*first_mirror==TESTvalue) first_mirror-=MIRROR_SIZE;
|
1166 |
|
|
first_mirror+=MIRROR_SIZE;
|
1167 |
|
|
|
1168 |
|
|
while (*last_mirror==TESTvalue) last_mirror+=MIRROR_SIZE;
|
1169 |
|
|
last_mirror-=MIRROR_SIZE;
|
1170 |
|
|
|
1171 |
|
|
dev->mem_start=(u_long)first_mirror;
|
1172 |
|
|
dev->mem_end=(u_long)last_mirror+MIRROR_SIZE-1;
|
1173 |
|
|
dev->rmem_start=dev->mem_start+BUFFER_SIZE*0;
|
1174 |
|
|
dev->rmem_end=dev->mem_start+BUFFER_SIZE*2-1;
|
1175 |
|
|
|
1176 |
|
|
/* Initialize the rest of the device structure. */
|
1177 |
|
|
|
1178 |
|
|
dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
|
1179 |
|
|
if (dev->priv == NULL)
|
1180 |
|
|
{
|
1181 |
|
|
irq2dev_map[airq] = NULL;
|
1182 |
|
|
free_irq(airq,NULL);
|
1183 |
|
|
release_region(port,ARCNET_TOTAL_SIZE);
|
1184 |
|
|
return -ENOMEM;
|
1185 |
|
|
}
|
1186 |
|
|
memset(dev->priv,0,sizeof(struct arcnet_local));
|
1187 |
|
|
lp=(struct arcnet_local *)(dev->priv);
|
1188 |
|
|
|
1189 |
|
|
dev->open=arcnet_open;
|
1190 |
|
|
dev->stop=arcnet_close;
|
1191 |
|
|
dev->hard_start_xmit=arcnetA_send_packet;
|
1192 |
|
|
dev->get_stats=arcnet_get_stats;
|
1193 |
|
|
/*dev->set_multicast_list = &set_multicast_list;*/
|
1194 |
|
|
|
1195 |
|
|
/* Fill in the fields of the device structure with generic
|
1196 |
|
|
* values.
|
1197 |
|
|
*/
|
1198 |
|
|
arcnet_setup(dev);
|
1199 |
|
|
|
1200 |
|
|
/* And now fill particular fields with arcnet values */
|
1201 |
|
|
dev->mtu=1500; /* completely arbitrary - agrees with ether, though */
|
1202 |
|
|
dev->hard_header_len=sizeof(struct ClientData);
|
1203 |
|
|
dev->hard_header=arcnetA_header;
|
1204 |
|
|
dev->rebuild_header=arcnetA_rebuild_header;
|
1205 |
|
|
lp->sequence=1;
|
1206 |
|
|
lp->recbuf=0;
|
1207 |
|
|
|
1208 |
|
|
BUGMSG(D_DURING,"ClientData header size is %d.\n",
|
1209 |
|
|
sizeof(struct ClientData));
|
1210 |
|
|
BUGMSG(D_DURING,"HardHeader size is %d.\n",
|
1211 |
|
|
sizeof(struct HardHeader));
|
1212 |
|
|
|
1213 |
|
|
/* get and check the station ID from offset 1 in shmem */
|
1214 |
|
|
lp->stationid = first_mirror[1];
|
1215 |
|
|
if (lp->stationid==0)
|
1216 |
|
|
BUGMSG(D_NORMAL,"WARNING! Station address 00 is reserved "
|
1217 |
|
|
"for broadcasts!\n");
|
1218 |
|
|
else if (lp->stationid==255)
|
1219 |
|
|
BUGMSG(D_NORMAL,"WARNING! Station address FF may confuse "
|
1220 |
|
|
"DOS networking programs!\n");
|
1221 |
|
|
dev->dev_addr[0]=lp->stationid;
|
1222 |
|
|
|
1223 |
|
|
BUGMSG(D_NORMAL,"ARCnet station %02Xh found at %03lXh, IRQ %d, "
|
1224 |
|
|
"ShMem %lXh (%ld bytes).\n",
|
1225 |
|
|
lp->stationid,
|
1226 |
|
|
dev->base_addr,dev->irq,dev->mem_start,
|
1227 |
|
|
dev->mem_end-dev->mem_start+1);
|
1228 |
|
|
|
1229 |
|
|
return 0;
|
1230 |
|
|
}
|
1231 |
|
|
|
1232 |
|
|
|
1233 |
|
|
/* Do a hardware reset on the card, and set up necessary registers.
|
1234 |
|
|
*
|
1235 |
|
|
* This should be called as little as possible, because it disrupts the
|
1236 |
|
|
* token on the network (causes a RECON) and requires a significant delay.
|
1237 |
|
|
*
|
1238 |
|
|
* However, it does make sure the card is in a defined state.
|
1239 |
|
|
*/
|
1240 |
|
|
int arcnet_reset(struct device *dev,int reset_delay)
|
1241 |
|
|
{
|
1242 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
|
1243 |
|
|
short ioaddr=dev->base_addr;
|
1244 |
|
|
int delayval,recbuf=lp->recbuf;
|
1245 |
|
|
u_char *cardmem;
|
1246 |
|
|
|
1247 |
|
|
/* no IRQ's, please! */
|
1248 |
|
|
lp->intmask=0;
|
1249 |
|
|
SETMASK;
|
1250 |
|
|
|
1251 |
|
|
BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
|
1252 |
|
|
dev->name,inb(STATUS));
|
1253 |
|
|
|
1254 |
|
|
if (reset_delay)
|
1255 |
|
|
{
|
1256 |
|
|
/* reset the card */
|
1257 |
|
|
inb(RESET);
|
1258 |
|
|
JIFFER(RESETtime);
|
1259 |
|
|
}
|
1260 |
|
|
|
1261 |
|
|
outb(CFLAGScmd|RESETclear, COMMAND); /* clear flags & end reset */
|
1262 |
|
|
outb(CFLAGScmd|CONFIGclear,COMMAND);
|
1263 |
|
|
|
1264 |
|
|
/* verify that the ARCnet signature byte is present */
|
1265 |
|
|
cardmem = (u_char *) dev->mem_start;
|
1266 |
|
|
if (cardmem[0] != TESTvalue)
|
1267 |
|
|
{
|
1268 |
|
|
BUGMSG(D_NORMAL,"reset failed: TESTvalue not present.\n");
|
1269 |
|
|
return 1;
|
1270 |
|
|
}
|
1271 |
|
|
|
1272 |
|
|
/* clear out status variables */
|
1273 |
|
|
recbuf=lp->recbuf=0;
|
1274 |
|
|
lp->txbuf=2;
|
1275 |
|
|
|
1276 |
|
|
/* enable extended (512-byte) packets */
|
1277 |
|
|
outb(CONFIGcmd|EXTconf,COMMAND);
|
1278 |
|
|
|
1279 |
|
|
#ifndef SLOW_XMIT_COPY
|
1280 |
|
|
/* clean out all the memory to make debugging make more sense :) */
|
1281 |
|
|
BUGLVL(D_DURING)
|
1282 |
|
|
memset((void *)dev->mem_start,0x42,2048);
|
1283 |
|
|
#endif
|
1284 |
|
|
|
1285 |
|
|
/* and enable receive of our first packet to the first buffer */
|
1286 |
|
|
EnableReceiver();
|
1287 |
|
|
|
1288 |
|
|
/* re-enable interrupts */
|
1289 |
|
|
lp->intmask|=NORXflag;
|
1290 |
|
|
#ifdef DETECT_RECONFIGS
|
1291 |
|
|
lp->intmask|=RECONflag;
|
1292 |
|
|
#endif
|
1293 |
|
|
SETMASK;
|
1294 |
|
|
|
1295 |
|
|
/* done! return success. */
|
1296 |
|
|
return 0;
|
1297 |
|
|
}
|
1298 |
|
|
|
1299 |
|
|
|
1300 |
|
|
/* Setup a struct device for ARCnet. This should really be in net_init.c
|
1301 |
|
|
* but since there are three different ARCnet devices ANYWAY... <gargle>
|
1302 |
|
|
*
|
1303 |
|
|
* Actually, the whole idea of having all this kernel-dependent stuff (ie.
|
1304 |
|
|
* "new-style flags") setup per-net-device is kind of weird anyway.
|
1305 |
|
|
*
|
1306 |
|
|
* Intelligent defaults?! Nah.
|
1307 |
|
|
*/
|
1308 |
|
|
void arcnet_setup(struct device *dev)
|
1309 |
|
|
{
|
1310 |
|
|
int i;
|
1311 |
|
|
for (i=0; i<DEV_NUMBUFFS; i++)
|
1312 |
|
|
skb_queue_head_init(&dev->buffs[i]);
|
1313 |
|
|
|
1314 |
|
|
dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
|
1315 |
|
|
dev->addr_len = 1;
|
1316 |
|
|
dev->type = ARPHRD_ARCNET;
|
1317 |
|
|
dev->tx_queue_len = 30; /* fairly long queue - arcnet is
|
1318 |
|
|
* quite speedy.
|
1319 |
|
|
*/
|
1320 |
|
|
|
1321 |
|
|
/* New-style flags. */
|
1322 |
|
|
dev->flags = IFF_BROADCAST;
|
1323 |
|
|
dev->family = AF_INET;
|
1324 |
|
|
dev->pa_addr = 0;
|
1325 |
|
|
dev->pa_brdaddr = 0;
|
1326 |
|
|
dev->pa_mask = 0;
|
1327 |
|
|
dev->pa_alen = 4;
|
1328 |
|
|
}
|
1329 |
|
|
|
1330 |
|
|
|
1331 |
|
|
/****************************************************************************
|
1332 |
|
|
* *
|
1333 |
|
|
* Open and close the driver *
|
1334 |
|
|
* *
|
1335 |
|
|
****************************************************************************/
|
1336 |
|
|
|
1337 |
|
|
|
1338 |
|
|
/* Open/initialize the board. This is called sometime after booting when
|
1339 |
|
|
* the 'ifconfig' program is run.
|
1340 |
|
|
*
|
1341 |
|
|
* This routine should set everything up anew at each open, even
|
1342 |
|
|
* registers that "should" only need to be set once at boot, so that
|
1343 |
|
|
* there is non-reboot way to recover if something goes wrong.
|
1344 |
|
|
*/
|
1345 |
|
|
static int
|
1346 |
|
|
arcnet_open(struct device *dev)
|
1347 |
|
|
{
|
1348 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1349 |
|
|
int ioaddr=dev->base_addr;
|
1350 |
|
|
|
1351 |
|
|
if (dev->metric>=1000)
|
1352 |
|
|
{
|
1353 |
|
|
arcnet_debug=dev->metric-1000;
|
1354 |
|
|
printk(KERN_INFO "%6s: debug level set to %d\n",dev->name,arcnet_debug);
|
1355 |
|
|
dev->metric=1;
|
1356 |
|
|
}
|
1357 |
|
|
|
1358 |
|
|
BUGMSG(D_INIT,"arcnet_open: resetting card.\n");
|
1359 |
|
|
|
1360 |
|
|
#ifdef FAST_IFCONFIG
|
1361 |
|
|
/* try to put the card in a defined state - if it fails the first
|
1362 |
|
|
* time, actually reset it.
|
1363 |
|
|
*/
|
1364 |
|
|
if (arcnet_reset(dev,0) && arcnet_reset(dev,1))
|
1365 |
|
|
return -ENODEV;
|
1366 |
|
|
#else
|
1367 |
|
|
/* reset the card twice in case something goes wrong the first time.
|
1368 |
|
|
*/
|
1369 |
|
|
if (arcnet_reset(dev,1) && arcnet_reset(dev,1))
|
1370 |
|
|
return -ENODEV;
|
1371 |
|
|
#endif
|
1372 |
|
|
|
1373 |
|
|
dev->tbusy=0;
|
1374 |
|
|
dev->interrupt=0;
|
1375 |
|
|
lp->intx=0;
|
1376 |
|
|
lp->in_txhandler=0;
|
1377 |
|
|
|
1378 |
|
|
/* The RFC1201 driver is the default - just store */
|
1379 |
|
|
lp->adev=dev;
|
1380 |
|
|
BUGMSG(D_NORMAL,"ARCnet RFC1201 protocol initialized.\n");
|
1381 |
|
|
|
1382 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
1383 |
|
|
/* Initialize the ethernet-encap protocol driver */
|
1384 |
|
|
lp->edev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
|
1385 |
|
|
if (lp->edev == NULL)
|
1386 |
|
|
return -ENOMEM;
|
1387 |
|
|
memcpy(lp->edev,dev,sizeof(struct device));
|
1388 |
|
|
lp->edev->name=(char *)kmalloc(10,GFP_KERNEL);
|
1389 |
|
|
if (lp->edev->name == NULL) {
|
1390 |
|
|
kfree(lp->edev);
|
1391 |
|
|
lp->edev = NULL;
|
1392 |
|
|
return -ENOMEM;
|
1393 |
|
|
}
|
1394 |
|
|
sprintf(lp->edev->name,"%se",dev->name);
|
1395 |
|
|
lp->edev->init=arcnetE_init;
|
1396 |
|
|
register_netdev(lp->edev);
|
1397 |
|
|
#else
|
1398 |
|
|
BUGMSG(D_NORMAL,"Ethernet-Encap protocol not available (disabled).\n");
|
1399 |
|
|
#endif
|
1400 |
|
|
|
1401 |
|
|
#ifdef CONFIG_ARCNET_1051
|
1402 |
|
|
/* Initialize the RFC1051-encap protocol driver */
|
1403 |
|
|
lp->sdev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
|
1404 |
|
|
memcpy(lp->sdev,dev,sizeof(struct device));
|
1405 |
|
|
lp->sdev->name=(char *)kmalloc(10,GFP_KERNEL);
|
1406 |
|
|
sprintf(lp->sdev->name,"%ss",dev->name);
|
1407 |
|
|
lp->sdev->init=arcnetS_init;
|
1408 |
|
|
register_netdev(lp->sdev);
|
1409 |
|
|
#else
|
1410 |
|
|
BUGMSG(D_NORMAL,"RFC1051 protocol not available (disabled).\n");
|
1411 |
|
|
#endif
|
1412 |
|
|
|
1413 |
|
|
/* we're started */
|
1414 |
|
|
START=1;
|
1415 |
|
|
|
1416 |
|
|
/* make sure we're ready to receive IRQ's.
|
1417 |
|
|
* arcnet_reset sets this for us, but if we receive one before
|
1418 |
|
|
* START is set to 1, it could be ignored. So, we turn IRQ's
|
1419 |
|
|
* off, then on again to clean out the IRQ controller.
|
1420 |
|
|
*/
|
1421 |
|
|
outb(0,INTMASK);
|
1422 |
|
|
udelay(1); /* give it time to set the mask before
|
1423 |
|
|
* we reset it again. (may not even be
|
1424 |
|
|
* necessary)
|
1425 |
|
|
*/
|
1426 |
|
|
SETMASK;
|
1427 |
|
|
|
1428 |
|
|
MOD_INC_USE_COUNT;
|
1429 |
|
|
return 0;
|
1430 |
|
|
}
|
1431 |
|
|
|
1432 |
|
|
|
1433 |
|
|
/* The inverse routine to arcnet_open - shuts down the card.
|
1434 |
|
|
*/
|
1435 |
|
|
static int
|
1436 |
|
|
arcnet_close(struct device *dev)
|
1437 |
|
|
{
|
1438 |
|
|
int ioaddr = dev->base_addr;
|
1439 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1440 |
|
|
|
1441 |
|
|
TBUSY=1;
|
1442 |
|
|
START=0;
|
1443 |
|
|
|
1444 |
|
|
/* Shut down the card */
|
1445 |
|
|
#ifdef FAST_IFCONFIG
|
1446 |
|
|
inb(RESET); /* reset IRQ won't run if START=0 */
|
1447 |
|
|
#else
|
1448 |
|
|
lp->intmask=0;
|
1449 |
|
|
SETMASK; /* no IRQ's (except RESET, of course) */
|
1450 |
|
|
outb(NOTXcmd,COMMAND); /* stop transmit */
|
1451 |
|
|
outb(NORXcmd,COMMAND); /* disable receive */
|
1452 |
|
|
#endif
|
1453 |
|
|
|
1454 |
|
|
/* reset more flags */
|
1455 |
|
|
INTERRUPT=0;
|
1456 |
|
|
|
1457 |
|
|
/* do NOT free lp->adev!! It's static! */
|
1458 |
|
|
lp->adev=NULL;
|
1459 |
|
|
|
1460 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
1461 |
|
|
/* free the ethernet-encap protocol device */
|
1462 |
|
|
lp->edev->priv=NULL;
|
1463 |
|
|
dev_close(lp->edev);
|
1464 |
|
|
unregister_netdev(lp->edev);
|
1465 |
|
|
kfree(lp->edev->name);
|
1466 |
|
|
kfree(lp->edev);
|
1467 |
|
|
lp->edev=NULL;
|
1468 |
|
|
#endif
|
1469 |
|
|
|
1470 |
|
|
#ifdef CONFIG_ARCNET_1051
|
1471 |
|
|
/* free the RFC1051-encap protocol device */
|
1472 |
|
|
lp->sdev->priv=NULL;
|
1473 |
|
|
dev_close(lp->sdev);
|
1474 |
|
|
unregister_netdev(lp->sdev);
|
1475 |
|
|
kfree(lp->sdev->name);
|
1476 |
|
|
kfree(lp->sdev);
|
1477 |
|
|
lp->sdev=NULL;
|
1478 |
|
|
#endif
|
1479 |
|
|
|
1480 |
|
|
/* Update the statistics here. (not necessary in ARCnet) */
|
1481 |
|
|
|
1482 |
|
|
MOD_DEC_USE_COUNT;
|
1483 |
|
|
return 0;
|
1484 |
|
|
}
|
1485 |
|
|
|
1486 |
|
|
|
1487 |
|
|
|
1488 |
|
|
/****************************************************************************
|
1489 |
|
|
* *
|
1490 |
|
|
* Transmitter routines *
|
1491 |
|
|
* *
|
1492 |
|
|
****************************************************************************/
|
1493 |
|
|
|
1494 |
|
|
/* Generic error checking routine for arcnet??_send_packet
|
1495 |
|
|
*/
|
1496 |
|
|
static int
|
1497 |
|
|
arcnet_send_packet_bad(struct sk_buff *skb, struct device *dev)
|
1498 |
|
|
{
|
1499 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1500 |
|
|
int ioaddr=dev->base_addr;
|
1501 |
|
|
|
1502 |
|
|
BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
|
1503 |
|
|
inb(STATUS),lp->intx);
|
1504 |
|
|
|
1505 |
|
|
if (lp->in_txhandler)
|
1506 |
|
|
{
|
1507 |
|
|
BUGMSG(D_NORMAL,"send_packet called while in txhandler!\n");
|
1508 |
|
|
lp->stats.tx_dropped++;
|
1509 |
|
|
return 1;
|
1510 |
|
|
}
|
1511 |
|
|
|
1512 |
|
|
if (lp->intx>1)
|
1513 |
|
|
{
|
1514 |
|
|
BUGMSG(D_NORMAL,"send_packet called while intx!\n");
|
1515 |
|
|
lp->stats.tx_dropped++;
|
1516 |
|
|
return 1;
|
1517 |
|
|
}
|
1518 |
|
|
|
1519 |
|
|
if (IF_TBUSY)
|
1520 |
|
|
{
|
1521 |
|
|
/* If we get here, some higher level has decided we are broken.
|
1522 |
|
|
There should really be a "kick me" function call instead. */
|
1523 |
|
|
int tickssofar = jiffies - dev->trans_start;
|
1524 |
|
|
/*int recbuf=lp->recbuf;*/
|
1525 |
|
|
int status=inb(STATUS);
|
1526 |
|
|
|
1527 |
|
|
if (tickssofar < TX_TIMEOUT)
|
1528 |
|
|
{
|
1529 |
|
|
BUGMSG(D_DURING,"premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
|
1530 |
|
|
status,tickssofar,lp->outgoing.skb,
|
1531 |
|
|
lp->outgoing.numsegs,
|
1532 |
|
|
lp->outgoing.segnum);
|
1533 |
|
|
return 1;
|
1534 |
|
|
}
|
1535 |
|
|
|
1536 |
|
|
lp->intmask &= ~TXFREEflag;
|
1537 |
|
|
SETMASK;
|
1538 |
|
|
|
1539 |
|
|
if (status&TXFREEflag) /* transmit _DID_ finish */
|
1540 |
|
|
{
|
1541 |
|
|
BUGMSG(D_NORMAL,"tx timeout - missed IRQ? (status=%Xh, ticks=%d, mask=%Xh, dest=%02Xh)\n",
|
1542 |
|
|
status,tickssofar,lp->intmask,lp->lasttrans_dest);
|
1543 |
|
|
lp->stats.tx_errors++;
|
1544 |
|
|
}
|
1545 |
|
|
else
|
1546 |
|
|
{
|
1547 |
|
|
BUGMSG(D_EXTRA,"tx timed out (status=%Xh, tickssofar=%d, intmask=%Xh, dest=%02Xh)\n",
|
1548 |
|
|
status,tickssofar,lp->intmask,lp->lasttrans_dest);
|
1549 |
|
|
lp->stats.tx_errors++;
|
1550 |
|
|
lp->stats.tx_aborted_errors++;
|
1551 |
|
|
|
1552 |
|
|
outb(NOTXcmd,COMMAND);
|
1553 |
|
|
}
|
1554 |
|
|
|
1555 |
|
|
if (lp->outgoing.skb)
|
1556 |
|
|
{
|
1557 |
|
|
dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
|
1558 |
|
|
lp->stats.tx_dropped++;
|
1559 |
|
|
}
|
1560 |
|
|
lp->outgoing.skb=NULL;
|
1561 |
|
|
|
1562 |
|
|
TBUSY=0;
|
1563 |
|
|
lp->txready=0;
|
1564 |
|
|
lp->sending=0;
|
1565 |
|
|
|
1566 |
|
|
return 1;
|
1567 |
|
|
}
|
1568 |
|
|
|
1569 |
|
|
/* If some higher layer thinks we've missed a tx-done interrupt
|
1570 |
|
|
we are passed NULL. Caution: dev_tint() handles the cli()/sti()
|
1571 |
|
|
itself. */
|
1572 |
|
|
if (skb == NULL) {
|
1573 |
|
|
BUGMSG(D_NORMAL,"tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
|
1574 |
|
|
inb(STATUS),lp->intx,jiffies-dev->trans_start);
|
1575 |
|
|
lp->stats.tx_errors++;
|
1576 |
|
|
dev_tint(dev);
|
1577 |
|
|
return 0;
|
1578 |
|
|
}
|
1579 |
|
|
|
1580 |
|
|
if (lp->txready) /* transmit already in progress! */
|
1581 |
|
|
{
|
1582 |
|
|
BUGMSG(D_NORMAL,"trying to start new packet while busy! (status=%Xh)\n",
|
1583 |
|
|
inb(STATUS));
|
1584 |
|
|
lp->intmask &= ~TXFREEflag;
|
1585 |
|
|
SETMASK;
|
1586 |
|
|
outb(NOTXcmd,COMMAND); /* abort current send */
|
1587 |
|
|
arcnet_inthandler(dev); /* fake an interrupt */
|
1588 |
|
|
lp->stats.tx_errors++;
|
1589 |
|
|
lp->stats.tx_fifo_errors++;
|
1590 |
|
|
lp->txready=0; /* we definitely need this line! */
|
1591 |
|
|
|
1592 |
|
|
return 1;
|
1593 |
|
|
}
|
1594 |
|
|
|
1595 |
|
|
/* Block a timer-based transmit from overlapping. This could better be
|
1596 |
|
|
done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
|
1597 |
|
|
if (set_bit(0, (void*)&dev->tbusy) != 0)
|
1598 |
|
|
{
|
1599 |
|
|
BUGMSG(D_NORMAL,"transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
|
1600 |
|
|
inb(STATUS),lp->intx,jiffies-dev->trans_start);
|
1601 |
|
|
lp->stats.tx_errors++;
|
1602 |
|
|
lp->stats.tx_fifo_errors++;
|
1603 |
|
|
return -EBUSY;
|
1604 |
|
|
}
|
1605 |
|
|
|
1606 |
|
|
return 0;
|
1607 |
|
|
}
|
1608 |
|
|
|
1609 |
|
|
|
1610 |
|
|
/* Called by the kernel in order to transmit a packet.
|
1611 |
|
|
*/
|
1612 |
|
|
static int
|
1613 |
|
|
arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
|
1614 |
|
|
{
|
1615 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1616 |
|
|
int ioaddr=dev->base_addr,bad;
|
1617 |
|
|
struct Outgoing *out=&(lp->outgoing);
|
1618 |
|
|
|
1619 |
|
|
lp->intx++;
|
1620 |
|
|
|
1621 |
|
|
bad=arcnet_send_packet_bad(skb,dev);
|
1622 |
|
|
if (bad)
|
1623 |
|
|
{
|
1624 |
|
|
lp->intx--;
|
1625 |
|
|
return bad;
|
1626 |
|
|
}
|
1627 |
|
|
|
1628 |
|
|
TBUSY=1;
|
1629 |
|
|
|
1630 |
|
|
out->length = 1 < skb->len ? skb->len : 1;
|
1631 |
|
|
out->hdr=(struct ClientData*)skb->data;
|
1632 |
|
|
out->skb=skb;
|
1633 |
|
|
|
1634 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"tx");
|
1635 |
|
|
|
1636 |
|
|
out->hdr->sequence=(lp->sequence++);
|
1637 |
|
|
|
1638 |
|
|
/* fits in one packet? */
|
1639 |
|
|
if (out->length-EXTRA_CLIENTDATA<=XMTU)
|
1640 |
|
|
{
|
1641 |
|
|
BUGMSG(D_DURING,"not splitting %d-byte packet. (split_flag=%d)\n",
|
1642 |
|
|
out->length,out->hdr->split_flag);
|
1643 |
|
|
if (out->hdr->split_flag)
|
1644 |
|
|
BUGMSG(D_NORMAL,"short packet has split_flag set?! (split_flag=%d)\n",
|
1645 |
|
|
out->hdr->split_flag);
|
1646 |
|
|
out->numsegs=1;
|
1647 |
|
|
out->segnum=1;
|
1648 |
|
|
arcnetAS_prepare_tx(dev,
|
1649 |
|
|
((char *)out->hdr)+EXTRA_CLIENTDATA,
|
1650 |
|
|
sizeof(struct ClientData)-EXTRA_CLIENTDATA,
|
1651 |
|
|
((char *)skb->data)+sizeof(struct ClientData),
|
1652 |
|
|
out->length-sizeof(struct ClientData),
|
1653 |
|
|
out->hdr->daddr,1);
|
1654 |
|
|
|
1655 |
|
|
/* done right away */
|
1656 |
|
|
dev_kfree_skb(out->skb,FREE_WRITE);
|
1657 |
|
|
out->skb=NULL;
|
1658 |
|
|
|
1659 |
|
|
if (arcnet_go_tx(dev,1))
|
1660 |
|
|
{
|
1661 |
|
|
/* inform upper layers */
|
1662 |
|
|
TBUSY=0;
|
1663 |
|
|
mark_bh(NET_BH);
|
1664 |
|
|
}
|
1665 |
|
|
}
|
1666 |
|
|
else /* too big for one - split it */
|
1667 |
|
|
{
|
1668 |
|
|
int maxsegsize=XMTU-4;
|
1669 |
|
|
|
1670 |
|
|
out->data=(u_char *)skb->data
|
1671 |
|
|
+ sizeof(struct ClientData);
|
1672 |
|
|
out->dataleft=out->length-sizeof(struct ClientData);
|
1673 |
|
|
out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
|
1674 |
|
|
out->segnum=0;
|
1675 |
|
|
|
1676 |
|
|
BUGMSG(D_TX,"packet (%d bytes) split into %d fragments:\n",
|
1677 |
|
|
out->length,out->numsegs);
|
1678 |
|
|
|
1679 |
|
|
/* if a packet waiting, launch it */
|
1680 |
|
|
arcnet_go_tx(dev,1);
|
1681 |
|
|
|
1682 |
|
|
if (!lp->txready)
|
1683 |
|
|
{
|
1684 |
|
|
/* prepare a packet, launch it and prepare
|
1685 |
|
|
* another.
|
1686 |
|
|
*/
|
1687 |
|
|
arcnetA_continue_tx(dev);
|
1688 |
|
|
if (arcnet_go_tx(dev,1))
|
1689 |
|
|
{
|
1690 |
|
|
arcnetA_continue_tx(dev);
|
1691 |
|
|
arcnet_go_tx(dev,1);
|
1692 |
|
|
}
|
1693 |
|
|
}
|
1694 |
|
|
|
1695 |
|
|
/* if segnum==numsegs, the transmission is finished;
|
1696 |
|
|
* free the skb right away.
|
1697 |
|
|
*/
|
1698 |
|
|
if (out->segnum==out->numsegs)
|
1699 |
|
|
{
|
1700 |
|
|
/* transmit completed */
|
1701 |
|
|
out->segnum++;
|
1702 |
|
|
if (out->skb)
|
1703 |
|
|
dev_kfree_skb(out->skb,FREE_WRITE);
|
1704 |
|
|
out->skb=NULL;
|
1705 |
|
|
}
|
1706 |
|
|
}
|
1707 |
|
|
|
1708 |
|
|
dev->trans_start=jiffies;
|
1709 |
|
|
lp->intx--;
|
1710 |
|
|
|
1711 |
|
|
/* make sure we didn't ignore a TX IRQ while we were in here */
|
1712 |
|
|
lp->intmask |= TXFREEflag;
|
1713 |
|
|
SETMASK;
|
1714 |
|
|
|
1715 |
|
|
return 0;
|
1716 |
|
|
}
|
1717 |
|
|
|
1718 |
|
|
|
1719 |
|
|
/* After an RFC1201 split packet has been set up, this function calls
|
1720 |
|
|
* arcnetAS_prepare_tx to load the next segment into the card. This function
|
1721 |
|
|
* does NOT automatically call arcnet_go_tx.
|
1722 |
|
|
*/
|
1723 |
|
|
static void arcnetA_continue_tx(struct device *dev)
|
1724 |
|
|
{
|
1725 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1726 |
|
|
int ioaddr=dev->base_addr,maxsegsize=XMTU-4;
|
1727 |
|
|
struct Outgoing *out=&(lp->outgoing);
|
1728 |
|
|
|
1729 |
|
|
BUGMSG(D_DURING,"continue_tx called (status=%Xh, intx=%d, intxh=%d, intmask=%Xh\n",
|
1730 |
|
|
inb(STATUS),lp->intx,lp->in_txhandler,lp->intmask);
|
1731 |
|
|
|
1732 |
|
|
if (lp->txready)
|
1733 |
|
|
{
|
1734 |
|
|
BUGMSG(D_NORMAL,"continue_tx: called with packet in buffer!\n");
|
1735 |
|
|
return;
|
1736 |
|
|
}
|
1737 |
|
|
|
1738 |
|
|
if (out->segnum>=out->numsegs)
|
1739 |
|
|
{
|
1740 |
|
|
BUGMSG(D_NORMAL,"continue_tx: building segment %d of %d!\n",
|
1741 |
|
|
out->segnum+1,out->numsegs);
|
1742 |
|
|
}
|
1743 |
|
|
|
1744 |
|
|
if (!out->segnum) /* first packet */
|
1745 |
|
|
out->hdr->split_flag=((out->numsegs-2)<<1)+1;
|
1746 |
|
|
else
|
1747 |
|
|
out->hdr->split_flag=out->segnum<<1;
|
1748 |
|
|
|
1749 |
|
|
out->seglen=maxsegsize;
|
1750 |
|
|
if (out->seglen>out->dataleft) out->seglen=out->dataleft;
|
1751 |
|
|
|
1752 |
|
|
BUGMSG(D_TX,"building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
|
1753 |
|
|
out->segnum+1,out->seglen,out->numsegs,
|
1754 |
|
|
out->length,out->hdr->split_flag);
|
1755 |
|
|
|
1756 |
|
|
arcnetAS_prepare_tx(dev,((char *)out->hdr)+EXTRA_CLIENTDATA,
|
1757 |
|
|
sizeof(struct ClientData)-EXTRA_CLIENTDATA,
|
1758 |
|
|
out->data,out->seglen,out->hdr->daddr,1);
|
1759 |
|
|
|
1760 |
|
|
out->dataleft-=out->seglen;
|
1761 |
|
|
out->data+=out->seglen;
|
1762 |
|
|
out->segnum++;
|
1763 |
|
|
}
|
1764 |
|
|
|
1765 |
|
|
|
1766 |
|
|
/* Given an skb, copy a packet into the ARCnet buffers for later transmission
|
1767 |
|
|
* by arcnet_go_tx.
|
1768 |
|
|
*/
|
1769 |
|
|
static void
|
1770 |
|
|
arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
|
1771 |
|
|
char *data,int length,int daddr,int exceptA)
|
1772 |
|
|
{
|
1773 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
1774 |
|
|
struct ClientData *arcsoft;
|
1775 |
|
|
union ArcPacket *arcpacket =
|
1776 |
|
|
(union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
|
1777 |
|
|
int offset;
|
1778 |
|
|
|
1779 |
|
|
#ifdef SLOW_XMIT_COPY
|
1780 |
|
|
char *iptr,*iend,*optr;
|
1781 |
|
|
#endif
|
1782 |
|
|
|
1783 |
|
|
lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate between 2 and 3 */
|
1784 |
|
|
|
1785 |
|
|
length+=hdrlen;
|
1786 |
|
|
|
1787 |
|
|
BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
|
1788 |
|
|
hdr,length,data);
|
1789 |
|
|
|
1790 |
|
|
#ifndef SLOW_XMIT_COPY
|
1791 |
|
|
/* clean out the page to make debugging make more sense :) */
|
1792 |
|
|
BUGLVL(D_DURING)
|
1793 |
|
|
memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
|
1794 |
|
|
#endif
|
1795 |
|
|
|
1796 |
|
|
arcpacket->hardheader.destination=daddr;
|
1797 |
|
|
|
1798 |
|
|
/* load packet into shared memory */
|
1799 |
|
|
if (length<=MTU) /* Normal (256-byte) Packet */
|
1800 |
|
|
{
|
1801 |
|
|
arcpacket->hardheader.offset1=offset=256-length;
|
1802 |
|
|
arcsoft=(struct ClientData *)
|
1803 |
|
|
(&arcpacket->raw[offset]);
|
1804 |
|
|
}
|
1805 |
|
|
else if (length>=MinTU) /* Extended (512-byte) Packet */
|
1806 |
|
|
{
|
1807 |
|
|
arcpacket->hardheader.offset1=0;
|
1808 |
|
|
arcpacket->hardheader.offset2=offset=512-length;
|
1809 |
|
|
|
1810 |
|
|
arcsoft=(struct ClientData *)
|
1811 |
|
|
(&arcpacket->raw[offset]);
|
1812 |
|
|
}
|
1813 |
|
|
else if (exceptA) /* RFC1201 Exception Packet */
|
1814 |
|
|
{
|
1815 |
|
|
arcpacket->hardheader.offset1=0;
|
1816 |
|
|
arcpacket->hardheader.offset2=offset=512-length-4;
|
1817 |
|
|
arcsoft=(struct ClientData *)
|
1818 |
|
|
(&arcpacket->raw[offset+4]);
|
1819 |
|
|
|
1820 |
|
|
/* exception-specific stuff - these four bytes
|
1821 |
|
|
* make the packet long enough to fit in a 512-byte
|
1822 |
|
|
* frame.
|
1823 |
|
|
*/
|
1824 |
|
|
arcpacket->raw[offset+0]=hdr[0];
|
1825 |
|
|
arcpacket->raw[offset+1]=0xFF; /* FF flag */
|
1826 |
|
|
arcpacket->raw[offset+2]=0xFF; /* FF padding */
|
1827 |
|
|
arcpacket->raw[offset+3]=0xFF; /* FF padding */
|
1828 |
|
|
}
|
1829 |
|
|
else /* "other" Exception packet */
|
1830 |
|
|
{
|
1831 |
|
|
/* RFC1051 - set 4 trailing bytes to 0 */
|
1832 |
|
|
memset(&arcpacket->raw[508],0,4);
|
1833 |
|
|
|
1834 |
|
|
/* now round up to MinTU */
|
1835 |
|
|
arcpacket->hardheader.offset1=0;
|
1836 |
|
|
arcpacket->hardheader.offset2=offset=512-MinTU;
|
1837 |
|
|
arcsoft=(struct ClientData *)(&arcpacket->raw[offset]);
|
1838 |
|
|
}
|
1839 |
|
|
|
1840 |
|
|
|
1841 |
|
|
/* copy the packet into ARCnet shmem
|
1842 |
|
|
* - the first bytes of ClientData header are skipped
|
1843 |
|
|
*/
|
1844 |
|
|
memcpy((u_char*)arcsoft,
|
1845 |
|
|
(u_char*)hdr,hdrlen);
|
1846 |
|
|
#ifdef SLOW_XMIT_COPY
|
1847 |
|
|
for (iptr=data,iend=iptr+length-hdrlen,optr=(char *)arcsoft+hdrlen;
|
1848 |
|
|
iptr<iend; iptr++,optr++)
|
1849 |
|
|
{
|
1850 |
|
|
*optr=*iptr;
|
1851 |
|
|
/*udelay(5);*/
|
1852 |
|
|
}
|
1853 |
|
|
#else
|
1854 |
|
|
memcpy((u_char*)arcsoft+hdrlen,
|
1855 |
|
|
data,length-hdrlen);
|
1856 |
|
|
#endif
|
1857 |
|
|
|
1858 |
|
|
BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
|
1859 |
|
|
daddr,length);
|
1860 |
|
|
|
1861 |
|
|
BUGLVL(D_TX) arcnet_dump_packet(dev,arcpacket->raw,length>MTU,"tx");
|
1862 |
|
|
lp->lastload_dest=daddr;
|
1863 |
|
|
lp->txready=lp->txbuf; /* packet is ready for sending */
|
1864 |
|
|
}
|
1865 |
|
|
|
1866 |
|
|
/* Actually start transmitting a packet that was placed in the card's
|
1867 |
|
|
* buffer by arcnetAS_prepare_tx. Returns 1 if a Tx is really started.
|
1868 |
|
|
*
|
1869 |
|
|
* This should probably always be called with the INTMASK register set to 0,
|
1870 |
|
|
* so go_tx is not called recursively.
|
1871 |
|
|
*
|
1872 |
|
|
* The enable_irq flag determines whether to actually write INTMASK value
|
1873 |
|
|
* to the card; TXFREEflag is always OR'ed into the memory variable either
|
1874 |
|
|
* way.
|
1875 |
|
|
*/
|
1876 |
|
|
static int
|
1877 |
|
|
arcnet_go_tx(struct device *dev,int enable_irq)
|
1878 |
|
|
{
|
1879 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
|
1880 |
|
|
int ioaddr=dev->base_addr;
|
1881 |
|
|
|
1882 |
|
|
BUGMSG(D_DURING,"go_tx: status=%Xh, intmask=%Xh, txready=%d, sending=%d\n",
|
1883 |
|
|
inb(STATUS),lp->intmask,lp->txready,lp->sending);
|
1884 |
|
|
|
1885 |
|
|
if (lp->sending || !lp->txready)
|
1886 |
|
|
{
|
1887 |
|
|
if (enable_irq && lp->sending)
|
1888 |
|
|
{
|
1889 |
|
|
lp->intmask |= TXFREEflag;
|
1890 |
|
|
SETMASK;
|
1891 |
|
|
}
|
1892 |
|
|
return 0;
|
1893 |
|
|
}
|
1894 |
|
|
|
1895 |
|
|
/* start sending */
|
1896 |
|
|
outb(TXcmd|(lp->txready<<3),COMMAND);
|
1897 |
|
|
|
1898 |
|
|
lp->stats.tx_packets++;
|
1899 |
|
|
lp->txready=0;
|
1900 |
|
|
lp->sending++;
|
1901 |
|
|
|
1902 |
|
|
lp->lasttrans_dest=lp->lastload_dest;
|
1903 |
|
|
lp->lastload_dest=0;
|
1904 |
|
|
|
1905 |
|
|
lp->intmask |= TXFREEflag;
|
1906 |
|
|
|
1907 |
|
|
if (enable_irq) SETMASK;
|
1908 |
|
|
|
1909 |
|
|
return 1;
|
1910 |
|
|
}
|
1911 |
|
|
|
1912 |
|
|
|
1913 |
|
|
/****************************************************************************
|
1914 |
|
|
* *
|
1915 |
|
|
* Interrupt handler *
|
1916 |
|
|
* *
|
1917 |
|
|
****************************************************************************/
|
1918 |
|
|
|
1919 |
|
|
|
1920 |
|
|
/* The typical workload of the driver: Handle the network interface
|
1921 |
|
|
* interrupts. This doesn't do much right now except call arcnet_inthandler,
|
1922 |
|
|
* which takes different parameters but may be called from other places
|
1923 |
|
|
* as well.
|
1924 |
|
|
*/
|
1925 |
|
|
static void
|
1926 |
|
|
arcnet_interrupt(int irq,void *dev_id,struct pt_regs *regs)
|
1927 |
|
|
{
|
1928 |
|
|
struct device *dev = (struct device *)(irq2dev_map[irq]);
|
1929 |
|
|
int ioaddr;
|
1930 |
|
|
|
1931 |
|
|
if (dev==NULL)
|
1932 |
|
|
{
|
1933 |
|
|
BUGLVL(D_DURING)
|
1934 |
|
|
printk(KERN_DEBUG "arcnet: irq %d for unknown device.\n", irq);
|
1935 |
|
|
return;
|
1936 |
|
|
}
|
1937 |
|
|
|
1938 |
|
|
BUGMSG(D_DURING,"in arcnet_interrupt\n");
|
1939 |
|
|
|
1940 |
|
|
/* RESET flag was enabled - if !dev->start, we must clear it right
|
1941 |
|
|
* away (but nothing else) since inthandler() is never called.
|
1942 |
|
|
*/
|
1943 |
|
|
ioaddr=dev->base_addr;
|
1944 |
|
|
if (!dev->start)
|
1945 |
|
|
{
|
1946 |
|
|
if (inb(STATUS) & RESETflag)
|
1947 |
|
|
outb(CFLAGScmd|RESETclear, COMMAND);
|
1948 |
|
|
return;
|
1949 |
|
|
}
|
1950 |
|
|
|
1951 |
|
|
/* Call the "real" interrupt handler. */
|
1952 |
|
|
arcnet_inthandler(dev);
|
1953 |
|
|
}
|
1954 |
|
|
|
1955 |
|
|
|
1956 |
|
|
/* The actual interrupt handler routine - handle various IRQ's generated
|
1957 |
|
|
* by the card.
|
1958 |
|
|
*/
|
1959 |
|
|
static void
|
1960 |
|
|
arcnet_inthandler(struct device *dev)
|
1961 |
|
|
{
|
1962 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
|
1963 |
|
|
int ioaddr=dev->base_addr, status, boguscount = 3, didsomething;
|
1964 |
|
|
|
1965 |
|
|
if (IF_INTERRUPT)
|
1966 |
|
|
{
|
1967 |
|
|
BUGMSG(D_NORMAL,"DRIVER PROBLEM! Nested arcnet interrupts!\n");
|
1968 |
|
|
return; /* don't even try. */
|
1969 |
|
|
}
|
1970 |
|
|
|
1971 |
|
|
outb(0,INTMASK);
|
1972 |
|
|
INTERRUPT = 1;
|
1973 |
|
|
|
1974 |
|
|
BUGMSG(D_DURING,"in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
|
1975 |
|
|
inb(STATUS),lp->intmask);
|
1976 |
|
|
|
1977 |
|
|
do
|
1978 |
|
|
{
|
1979 |
|
|
status = inb(STATUS);
|
1980 |
|
|
didsomething=0;
|
1981 |
|
|
|
1982 |
|
|
|
1983 |
|
|
/* RESET flag was enabled - card is resetting and if RX
|
1984 |
|
|
* is disabled, it's NOT because we just got a packet.
|
1985 |
|
|
*/
|
1986 |
|
|
if (status & RESETflag)
|
1987 |
|
|
{
|
1988 |
|
|
BUGMSG(D_NORMAL,"spurious reset (status=%Xh)\n",
|
1989 |
|
|
status);
|
1990 |
|
|
arcnet_reset(dev,0);
|
1991 |
|
|
|
1992 |
|
|
/* all other flag values are just garbage */
|
1993 |
|
|
break;
|
1994 |
|
|
}
|
1995 |
|
|
|
1996 |
|
|
|
1997 |
|
|
/* RX is inhibited - we must have received something. */
|
1998 |
|
|
if (status & lp->intmask & NORXflag)
|
1999 |
|
|
{
|
2000 |
|
|
int recbuf=lp->recbuf=!lp->recbuf;
|
2001 |
|
|
|
2002 |
|
|
BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
|
2003 |
|
|
status);
|
2004 |
|
|
|
2005 |
|
|
/* enable receive of our next packet */
|
2006 |
|
|
EnableReceiver();
|
2007 |
|
|
|
2008 |
|
|
/* Got a packet. */
|
2009 |
|
|
arcnet_rx(dev,!recbuf);
|
2010 |
|
|
didsomething++;
|
2011 |
|
|
}
|
2012 |
|
|
|
2013 |
|
|
/* it can only be an xmit-done irq if we're xmitting :) */
|
2014 |
|
|
/*if (status&TXFREEflag && !lp->in_txhandler && lp->sending)*/
|
2015 |
|
|
if (status & lp->intmask & TXFREEflag)
|
2016 |
|
|
{
|
2017 |
|
|
struct Outgoing *out=&(lp->outgoing);
|
2018 |
|
|
int was_sending=lp->sending;
|
2019 |
|
|
|
2020 |
|
|
lp->intmask &= ~TXFREEflag;
|
2021 |
|
|
|
2022 |
|
|
lp->in_txhandler++;
|
2023 |
|
|
if (was_sending) lp->sending--;
|
2024 |
|
|
|
2025 |
|
|
BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
|
2026 |
|
|
status,out->numsegs,out->segnum,out->skb);
|
2027 |
|
|
|
2028 |
|
|
if (was_sending && !(status&TXACKflag))
|
2029 |
|
|
{
|
2030 |
|
|
if (lp->lasttrans_dest != 0)
|
2031 |
|
|
{
|
2032 |
|
|
BUGMSG(D_EXTRA,"transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
|
2033 |
|
|
status,lp->lasttrans_dest);
|
2034 |
|
|
lp->stats.tx_errors++;
|
2035 |
|
|
lp->stats.tx_carrier_errors++;
|
2036 |
|
|
}
|
2037 |
|
|
else
|
2038 |
|
|
{
|
2039 |
|
|
BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
|
2040 |
|
|
status,
|
2041 |
|
|
lp->lasttrans_dest);
|
2042 |
|
|
}
|
2043 |
|
|
}
|
2044 |
|
|
|
2045 |
|
|
/* send packet if there is one */
|
2046 |
|
|
arcnet_go_tx(dev,0);
|
2047 |
|
|
didsomething++;
|
2048 |
|
|
|
2049 |
|
|
if (lp->intx)
|
2050 |
|
|
{
|
2051 |
|
|
BUGMSG(D_DURING,"TXDONE while intx! (status=%Xh, intx=%d)\n",
|
2052 |
|
|
inb(STATUS),lp->intx);
|
2053 |
|
|
lp->in_txhandler--;
|
2054 |
|
|
continue;
|
2055 |
|
|
}
|
2056 |
|
|
|
2057 |
|
|
if (!lp->outgoing.skb)
|
2058 |
|
|
{
|
2059 |
|
|
BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
|
2060 |
|
|
|
2061 |
|
|
/* inform upper layers */
|
2062 |
|
|
if (!lp->txready && IF_TBUSY)
|
2063 |
|
|
{
|
2064 |
|
|
TBUSY=0;
|
2065 |
|
|
mark_bh(NET_BH);
|
2066 |
|
|
}
|
2067 |
|
|
lp->in_txhandler--;
|
2068 |
|
|
continue;
|
2069 |
|
|
}
|
2070 |
|
|
|
2071 |
|
|
/* if more than one segment, and not all segments
|
2072 |
|
|
* are done, then continue xmit.
|
2073 |
|
|
*/
|
2074 |
|
|
if (out->segnum<out->numsegs)
|
2075 |
|
|
arcnetA_continue_tx(dev);
|
2076 |
|
|
arcnet_go_tx(dev,0);
|
2077 |
|
|
|
2078 |
|
|
/* if segnum==numsegs, the transmission is finished;
|
2079 |
|
|
* free the skb.
|
2080 |
|
|
*/
|
2081 |
|
|
if (out->segnum>=out->numsegs)
|
2082 |
|
|
{
|
2083 |
|
|
/* transmit completed */
|
2084 |
|
|
out->segnum++;
|
2085 |
|
|
if (out->skb)
|
2086 |
|
|
dev_kfree_skb(out->skb,FREE_WRITE);
|
2087 |
|
|
out->skb=NULL;
|
2088 |
|
|
|
2089 |
|
|
/* inform upper layers */
|
2090 |
|
|
if (!lp->txready && IF_TBUSY)
|
2091 |
|
|
{
|
2092 |
|
|
TBUSY=0;
|
2093 |
|
|
mark_bh(NET_BH);
|
2094 |
|
|
}
|
2095 |
|
|
}
|
2096 |
|
|
didsomething++;
|
2097 |
|
|
|
2098 |
|
|
lp->in_txhandler--;
|
2099 |
|
|
}
|
2100 |
|
|
else if (lp->txready && !lp->sending && !lp->intx)
|
2101 |
|
|
{
|
2102 |
|
|
BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
|
2103 |
|
|
status);
|
2104 |
|
|
arcnet_go_tx(dev,0);
|
2105 |
|
|
didsomething++;
|
2106 |
|
|
}
|
2107 |
|
|
|
2108 |
|
|
#ifdef DETECT_RECONFIGS
|
2109 |
|
|
if (status & (lp->intmask) & RECONflag)
|
2110 |
|
|
{
|
2111 |
|
|
outb(CFLAGScmd|CONFIGclear,COMMAND);
|
2112 |
|
|
lp->stats.tx_carrier_errors++;
|
2113 |
|
|
|
2114 |
|
|
#ifdef SHOW_RECONFIGS
|
2115 |
|
|
BUGMSG(D_NORMAL,"Network reconfiguration detected (status=%Xh)\n",
|
2116 |
|
|
status);
|
2117 |
|
|
#endif /* SHOW_RECONFIGS */
|
2118 |
|
|
|
2119 |
|
|
#ifdef RECON_THRESHOLD
|
2120 |
|
|
/* is the RECON info empty or old? */
|
2121 |
|
|
if (!lp->first_recon || !lp->last_recon ||
|
2122 |
|
|
jiffies-lp->last_recon > HZ*10)
|
2123 |
|
|
{
|
2124 |
|
|
if (lp->network_down)
|
2125 |
|
|
BUGMSG(D_NORMAL,"reconfiguration detected: cabling restored?\n");
|
2126 |
|
|
lp->first_recon=lp->last_recon=jiffies;
|
2127 |
|
|
lp->num_recons=lp->network_down=0;
|
2128 |
|
|
|
2129 |
|
|
BUGMSG(D_DURING,"recon: clearing counters.\n");
|
2130 |
|
|
}
|
2131 |
|
|
else /* add to current RECON counter */
|
2132 |
|
|
{
|
2133 |
|
|
lp->last_recon=jiffies;
|
2134 |
|
|
lp->num_recons++;
|
2135 |
|
|
|
2136 |
|
|
BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
|
2137 |
|
|
lp->num_recons,
|
2138 |
|
|
(lp->last_recon-lp->first_recon)/HZ,
|
2139 |
|
|
lp->network_down);
|
2140 |
|
|
|
2141 |
|
|
/* if network is marked up;
|
2142 |
|
|
* and first_recon and last_recon are 60+ sec
|
2143 |
|
|
* apart;
|
2144 |
|
|
* and the average no. of recons counted is
|
2145 |
|
|
* > RECON_THRESHOLD/min;
|
2146 |
|
|
* then print a warning message.
|
2147 |
|
|
*/
|
2148 |
|
|
if (!lp->network_down
|
2149 |
|
|
&& (lp->last_recon-lp->first_recon)<=HZ*60
|
2150 |
|
|
&& lp->num_recons >= RECON_THRESHOLD)
|
2151 |
|
|
{
|
2152 |
|
|
lp->network_down=1;
|
2153 |
|
|
BUGMSG(D_NORMAL,"many reconfigurations detected: cabling problem?\n");
|
2154 |
|
|
}
|
2155 |
|
|
else if (!lp->network_down
|
2156 |
|
|
&& lp->last_recon-lp->first_recon > HZ*60)
|
2157 |
|
|
{
|
2158 |
|
|
/* reset counters if we've gone for
|
2159 |
|
|
* over a minute.
|
2160 |
|
|
*/
|
2161 |
|
|
lp->first_recon=lp->last_recon;
|
2162 |
|
|
lp->num_recons=1;
|
2163 |
|
|
}
|
2164 |
|
|
}
|
2165 |
|
|
#endif
|
2166 |
|
|
}
|
2167 |
|
|
#ifdef RECON_THRESHOLD
|
2168 |
|
|
else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
|
2169 |
|
|
{
|
2170 |
|
|
if (lp->network_down)
|
2171 |
|
|
BUGMSG(D_NORMAL,"cabling restored?\n");
|
2172 |
|
|
lp->first_recon=lp->last_recon=0;
|
2173 |
|
|
lp->num_recons=lp->network_down=0;
|
2174 |
|
|
|
2175 |
|
|
BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
|
2176 |
|
|
}
|
2177 |
|
|
#endif
|
2178 |
|
|
#endif /* DETECT_RECONFIGS */
|
2179 |
|
|
} while (--boguscount && didsomething);
|
2180 |
|
|
|
2181 |
|
|
BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n",
|
2182 |
|
|
inb(STATUS),boguscount);
|
2183 |
|
|
BUGMSG(D_DURING,"\n");
|
2184 |
|
|
|
2185 |
|
|
SETMASK; /* put back interrupt mask */
|
2186 |
|
|
|
2187 |
|
|
INTERRUPT=0;
|
2188 |
|
|
}
|
2189 |
|
|
|
2190 |
|
|
|
2191 |
|
|
/****************************************************************************
|
2192 |
|
|
* *
|
2193 |
|
|
* Receiver routines *
|
2194 |
|
|
* *
|
2195 |
|
|
****************************************************************************/
|
2196 |
|
|
|
2197 |
|
|
|
2198 |
|
|
/* A packet has arrived; grab it from the buffers and possibly unsplit it.
|
2199 |
|
|
* This is a generic packet receiver that calls arcnet??_rx depending on the
|
2200 |
|
|
* protocol ID found.
|
2201 |
|
|
*/
|
2202 |
|
|
static void
|
2203 |
|
|
arcnet_rx(struct device *dev,int recbuf)
|
2204 |
|
|
{
|
2205 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2206 |
|
|
int ioaddr = dev->base_addr;
|
2207 |
|
|
union ArcPacket *arcpacket=
|
2208 |
|
|
(union ArcPacket *)(dev->mem_start+recbuf*512);
|
2209 |
|
|
u_char *arcsoft;
|
2210 |
|
|
short length,offset;
|
2211 |
|
|
u_char daddr,saddr;
|
2212 |
|
|
|
2213 |
|
|
lp->stats.rx_packets++;
|
2214 |
|
|
|
2215 |
|
|
saddr=arcpacket->hardheader.source;
|
2216 |
|
|
daddr=arcpacket->hardheader.destination;
|
2217 |
|
|
|
2218 |
|
|
/* if source is 0, it's a "used" packet! */
|
2219 |
|
|
if (saddr==0)
|
2220 |
|
|
{
|
2221 |
|
|
BUGMSG(D_NORMAL,"discarding old packet. (status=%Xh)\n",
|
2222 |
|
|
inb(STATUS));
|
2223 |
|
|
lp->stats.rx_errors++;
|
2224 |
|
|
return;
|
2225 |
|
|
}
|
2226 |
|
|
arcpacket->hardheader.source=0;
|
2227 |
|
|
|
2228 |
|
|
if (arcpacket->hardheader.offset1) /* Normal Packet */
|
2229 |
|
|
{
|
2230 |
|
|
offset=arcpacket->hardheader.offset1;
|
2231 |
|
|
arcsoft=&arcpacket->raw[offset];
|
2232 |
|
|
length=256-offset;
|
2233 |
|
|
}
|
2234 |
|
|
else /* ExtendedPacket or ExceptionPacket */
|
2235 |
|
|
{
|
2236 |
|
|
offset=arcpacket->hardheader.offset2;
|
2237 |
|
|
arcsoft=&arcpacket->raw[offset];
|
2238 |
|
|
|
2239 |
|
|
length=512-offset;
|
2240 |
|
|
}
|
2241 |
|
|
|
2242 |
|
|
BUGMSG(D_DURING,"received packet from %02Xh to %02Xh (%d bytes)\n",
|
2243 |
|
|
saddr,daddr,length);
|
2244 |
|
|
|
2245 |
|
|
/* call the right receiver for the protocol */
|
2246 |
|
|
switch (arcsoft[0])
|
2247 |
|
|
{
|
2248 |
|
|
case ARC_P_IP:
|
2249 |
|
|
case ARC_P_ARP:
|
2250 |
|
|
case ARC_P_RARP:
|
2251 |
|
|
case ARC_P_IPX:
|
2252 |
|
|
case ARC_P_NOVELL_EC:
|
2253 |
|
|
arcnetA_rx(lp->adev,arcsoft,length,saddr,daddr);
|
2254 |
|
|
break;
|
2255 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
2256 |
|
|
case ARC_P_ETHER:
|
2257 |
|
|
arcnetE_rx(lp->edev,arcsoft,length,saddr,daddr);
|
2258 |
|
|
break;
|
2259 |
|
|
#endif
|
2260 |
|
|
#ifdef CONFIG_ARCNET_1051
|
2261 |
|
|
case ARC_P_IP_RFC1051:
|
2262 |
|
|
case ARC_P_ARP_RFC1051:
|
2263 |
|
|
arcnetS_rx(lp->sdev,arcsoft,length,saddr,daddr);
|
2264 |
|
|
break;
|
2265 |
|
|
#endif
|
2266 |
|
|
case ARC_P_LANSOFT: /* don't understand. fall through. */
|
2267 |
|
|
default:
|
2268 |
|
|
BUGMSG(D_EXTRA,"received unknown protocol %d (%Xh) from station %d.\n",
|
2269 |
|
|
arcsoft[0],arcsoft[0],saddr);
|
2270 |
|
|
lp->stats.rx_errors++;
|
2271 |
|
|
lp->stats.rx_crc_errors++;
|
2272 |
|
|
break;
|
2273 |
|
|
}
|
2274 |
|
|
|
2275 |
|
|
BUGLVL(D_RX) arcnet_dump_packet(dev,arcpacket->raw,length>240,"rx");
|
2276 |
|
|
|
2277 |
|
|
|
2278 |
|
|
#ifndef SLOW_XMIT_COPY
|
2279 |
|
|
/* clean out the page to make debugging make more sense :) */
|
2280 |
|
|
BUGLVL(D_DURING)
|
2281 |
|
|
memset((void *)arcpacket->raw,0x42,512);
|
2282 |
|
|
#endif
|
2283 |
|
|
|
2284 |
|
|
|
2285 |
|
|
/* If any worth-while packets have been received, a mark_bh(NET_BH)
|
2286 |
|
|
* has been done by netif_rx and Linux will handle them after we
|
2287 |
|
|
* return.
|
2288 |
|
|
*/
|
2289 |
|
|
}
|
2290 |
|
|
|
2291 |
|
|
|
2292 |
|
|
/* Packet receiver for "standard" RFC1201-style packets
|
2293 |
|
|
*/
|
2294 |
|
|
static void
|
2295 |
|
|
arcnetA_rx(struct device *dev,u_char *buf,
|
2296 |
|
|
int length,u_char saddr, u_char daddr)
|
2297 |
|
|
{
|
2298 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2299 |
|
|
struct sk_buff *skb;
|
2300 |
|
|
struct ClientData *arcsoft,*soft;
|
2301 |
|
|
|
2302 |
|
|
BUGMSG(D_DURING,"it's an RFC1201 packet (length=%d)\n",
|
2303 |
|
|
length);
|
2304 |
|
|
|
2305 |
|
|
/* compensate for EXTRA_CLIENTDATA (which isn't actually in the
|
2306 |
|
|
* packet)
|
2307 |
|
|
*/
|
2308 |
|
|
arcsoft=(struct ClientData *)(buf-EXTRA_CLIENTDATA);
|
2309 |
|
|
length+=EXTRA_CLIENTDATA;
|
2310 |
|
|
|
2311 |
|
|
if (arcsoft->split_flag==0xFF) /* Exception Packet */
|
2312 |
|
|
{
|
2313 |
|
|
BUGMSG(D_DURING,"compensating for exception packet\n");
|
2314 |
|
|
|
2315 |
|
|
/* skip over 4-byte junkola */
|
2316 |
|
|
arcsoft=(struct ClientData *)
|
2317 |
|
|
((u_char *)arcsoft + 4);
|
2318 |
|
|
length-=4;
|
2319 |
|
|
}
|
2320 |
|
|
|
2321 |
|
|
if (!arcsoft->split_flag) /* not split */
|
2322 |
|
|
{
|
2323 |
|
|
struct Incoming *in=&lp->incoming[saddr];
|
2324 |
|
|
|
2325 |
|
|
BUGMSG(D_RX,"incoming is not split (splitflag=%d)\n",
|
2326 |
|
|
arcsoft->split_flag);
|
2327 |
|
|
|
2328 |
|
|
if (in->skb) /* already assembling one! */
|
2329 |
|
|
{
|
2330 |
|
|
BUGMSG(D_EXTRA,"aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
|
2331 |
|
|
in->sequence,arcsoft->split_flag,
|
2332 |
|
|
arcsoft->sequence);
|
2333 |
|
|
kfree_skb(in->skb,FREE_WRITE);
|
2334 |
|
|
lp->stats.rx_errors++;
|
2335 |
|
|
lp->stats.rx_missed_errors++;
|
2336 |
|
|
in->skb=NULL;
|
2337 |
|
|
}
|
2338 |
|
|
|
2339 |
|
|
in->sequence=arcsoft->sequence;
|
2340 |
|
|
|
2341 |
|
|
skb = alloc_skb(length, GFP_ATOMIC);
|
2342 |
|
|
if (skb == NULL) {
|
2343 |
|
|
BUGMSG(D_NORMAL,"Memory squeeze, dropping packet.\n");
|
2344 |
|
|
lp->stats.rx_dropped++;
|
2345 |
|
|
return;
|
2346 |
|
|
}
|
2347 |
|
|
soft=(struct ClientData *)skb->data;
|
2348 |
|
|
|
2349 |
|
|
skb->len = length;
|
2350 |
|
|
skb->dev = dev;
|
2351 |
|
|
|
2352 |
|
|
memcpy((u_char *)soft+EXTRA_CLIENTDATA,
|
2353 |
|
|
(u_char *)arcsoft+EXTRA_CLIENTDATA,
|
2354 |
|
|
length-EXTRA_CLIENTDATA);
|
2355 |
|
|
soft->daddr=daddr;
|
2356 |
|
|
soft->saddr=saddr;
|
2357 |
|
|
|
2358 |
|
|
/* ARP packets have problems when sent from DOS.
|
2359 |
|
|
* source address is always 0 on some systems! So we take
|
2360 |
|
|
* the hardware source addr (which is impossible to fumble)
|
2361 |
|
|
* and insert it ourselves.
|
2362 |
|
|
*/
|
2363 |
|
|
if (soft->protocol_id == ARC_P_ARP)
|
2364 |
|
|
{
|
2365 |
|
|
struct arphdr *arp=(struct arphdr *)
|
2366 |
|
|
((char *)soft+sizeof(struct ClientData));
|
2367 |
|
|
|
2368 |
|
|
/* make sure addresses are the right length */
|
2369 |
|
|
if (arp->ar_hln==1 && arp->ar_pln==4)
|
2370 |
|
|
{
|
2371 |
|
|
char *cptr=(char *)(arp)+sizeof(struct arphdr);
|
2372 |
|
|
|
2373 |
|
|
if (!*cptr) /* is saddr = 00? */
|
2374 |
|
|
{
|
2375 |
|
|
BUGMSG(D_EXTRA,"ARP source address was 00h, set to %02Xh.\n",
|
2376 |
|
|
saddr);
|
2377 |
|
|
lp->stats.rx_crc_errors++;
|
2378 |
|
|
*cptr=saddr;
|
2379 |
|
|
}
|
2380 |
|
|
else
|
2381 |
|
|
{
|
2382 |
|
|
BUGMSG(D_DURING,"ARP source address (%Xh) is fine.\n",
|
2383 |
|
|
*cptr);
|
2384 |
|
|
}
|
2385 |
|
|
}
|
2386 |
|
|
else
|
2387 |
|
|
{
|
2388 |
|
|
BUGMSG(D_NORMAL,"funny-shaped ARP packet. (%Xh, %Xh)\n",
|
2389 |
|
|
arp->ar_hln,arp->ar_pln);
|
2390 |
|
|
lp->stats.rx_errors++;
|
2391 |
|
|
lp->stats.rx_crc_errors++;
|
2392 |
|
|
}
|
2393 |
|
|
}
|
2394 |
|
|
|
2395 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"rx");
|
2396 |
|
|
|
2397 |
|
|
skb->protocol=arcnetA_type_trans(skb,dev);
|
2398 |
|
|
|
2399 |
|
|
netif_rx(skb);
|
2400 |
|
|
}
|
2401 |
|
|
else /* split packet */
|
2402 |
|
|
{
|
2403 |
|
|
/* NOTE: MSDOS ARP packet correction should only need to
|
2404 |
|
|
* apply to unsplit packets, since ARP packets are so short.
|
2405 |
|
|
*
|
2406 |
|
|
* My interpretation of the RFC1201 (ARCnet) document is that
|
2407 |
|
|
* if a packet is received out of order, the entire assembly
|
2408 |
|
|
* process should be aborted.
|
2409 |
|
|
*
|
2410 |
|
|
* The RFC also mentions "it is possible for successfully
|
2411 |
|
|
* received packets to be retransmitted." As of 0.40 all
|
2412 |
|
|
* previously received packets are allowed, not just the
|
2413 |
|
|
* most recent one.
|
2414 |
|
|
*
|
2415 |
|
|
* We allow multiple assembly processes, one for each
|
2416 |
|
|
* ARCnet card possible on the network. Seems rather like
|
2417 |
|
|
* a waste of memory. Necessary?
|
2418 |
|
|
*/
|
2419 |
|
|
|
2420 |
|
|
struct Incoming *in=&lp->incoming[saddr];
|
2421 |
|
|
|
2422 |
|
|
BUGMSG(D_RX,"packet is split (splitflag=%d, seq=%d)\n",
|
2423 |
|
|
arcsoft->split_flag,in->sequence);
|
2424 |
|
|
|
2425 |
|
|
if (in->skb && in->sequence!=arcsoft->sequence)
|
2426 |
|
|
{
|
2427 |
|
|
BUGMSG(D_EXTRA,"wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n",
|
2428 |
|
|
saddr,in->sequence,arcsoft->sequence,
|
2429 |
|
|
arcsoft->split_flag);
|
2430 |
|
|
kfree_skb(in->skb,FREE_WRITE);
|
2431 |
|
|
in->skb=NULL;
|
2432 |
|
|
lp->stats.rx_errors++;
|
2433 |
|
|
lp->stats.rx_missed_errors++;
|
2434 |
|
|
in->lastpacket=in->numpackets=0;
|
2435 |
|
|
}
|
2436 |
|
|
|
2437 |
|
|
if (arcsoft->split_flag & 1) /* first packet in split */
|
2438 |
|
|
{
|
2439 |
|
|
BUGMSG(D_RX,"brand new splitpacket (splitflag=%d)\n",
|
2440 |
|
|
arcsoft->split_flag);
|
2441 |
|
|
if (in->skb) /* already assembling one! */
|
2442 |
|
|
{
|
2443 |
|
|
BUGMSG(D_EXTRA,"aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
|
2444 |
|
|
in->sequence,arcsoft->split_flag,
|
2445 |
|
|
arcsoft->sequence);
|
2446 |
|
|
lp->stats.rx_errors++;
|
2447 |
|
|
lp->stats.rx_missed_errors++;
|
2448 |
|
|
kfree_skb(in->skb,FREE_WRITE);
|
2449 |
|
|
}
|
2450 |
|
|
|
2451 |
|
|
in->sequence=arcsoft->sequence;
|
2452 |
|
|
in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
|
2453 |
|
|
in->lastpacket=1;
|
2454 |
|
|
|
2455 |
|
|
if (in->numpackets>16)
|
2456 |
|
|
{
|
2457 |
|
|
BUGMSG(D_EXTRA,"incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
|
2458 |
|
|
arcsoft->split_flag);
|
2459 |
|
|
lp->stats.rx_errors++;
|
2460 |
|
|
lp->stats.rx_length_errors++;
|
2461 |
|
|
return;
|
2462 |
|
|
}
|
2463 |
|
|
|
2464 |
|
|
in->skb=skb=alloc_skb(508*in->numpackets
|
2465 |
|
|
+ sizeof(struct ClientData),
|
2466 |
|
|
GFP_ATOMIC);
|
2467 |
|
|
if (skb == NULL) {
|
2468 |
|
|
BUGMSG(D_NORMAL,"(split) memory squeeze, dropping packet.\n");
|
2469 |
|
|
lp->stats.rx_dropped++;
|
2470 |
|
|
return;
|
2471 |
|
|
}
|
2472 |
|
|
|
2473 |
|
|
/* I don't know what this is for, but it DOES avoid
|
2474 |
|
|
* warnings...
|
2475 |
|
|
*/
|
2476 |
|
|
skb->free=1;
|
2477 |
|
|
|
2478 |
|
|
soft=(struct ClientData *)skb->data;
|
2479 |
|
|
|
2480 |
|
|
skb->len=sizeof(struct ClientData);
|
2481 |
|
|
skb->dev=dev;
|
2482 |
|
|
|
2483 |
|
|
memcpy((u_char *)soft+EXTRA_CLIENTDATA,
|
2484 |
|
|
(u_char *)arcsoft+EXTRA_CLIENTDATA,
|
2485 |
|
|
sizeof(struct ClientData)-EXTRA_CLIENTDATA);
|
2486 |
|
|
soft->split_flag=0; /* final packet won't be split */
|
2487 |
|
|
}
|
2488 |
|
|
else /* not first packet */
|
2489 |
|
|
{
|
2490 |
|
|
int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
|
2491 |
|
|
|
2492 |
|
|
/* if we're not assembling, there's no point
|
2493 |
|
|
* trying to continue.
|
2494 |
|
|
*/
|
2495 |
|
|
if (!in->skb)
|
2496 |
|
|
{
|
2497 |
|
|
BUGMSG(D_EXTRA,"can't continue split without starting first! (splitflag=%d, seq=%d)\n",
|
2498 |
|
|
arcsoft->split_flag,arcsoft->sequence);
|
2499 |
|
|
lp->stats.rx_errors++;
|
2500 |
|
|
lp->stats.rx_missed_errors++;
|
2501 |
|
|
return;
|
2502 |
|
|
}
|
2503 |
|
|
|
2504 |
|
|
in->lastpacket++;
|
2505 |
|
|
if (packetnum!=in->lastpacket) /* not the right flag! */
|
2506 |
|
|
{
|
2507 |
|
|
/* harmless duplicate? ignore. */
|
2508 |
|
|
if (packetnum<=in->lastpacket-1)
|
2509 |
|
|
{
|
2510 |
|
|
BUGMSG(D_EXTRA,"duplicate splitpacket ignored! (splitflag=%d)\n",
|
2511 |
|
|
arcsoft->split_flag);
|
2512 |
|
|
lp->stats.rx_errors++;
|
2513 |
|
|
lp->stats.rx_frame_errors++;
|
2514 |
|
|
return;
|
2515 |
|
|
}
|
2516 |
|
|
|
2517 |
|
|
/* "bad" duplicate, kill reassembly */
|
2518 |
|
|
BUGMSG(D_EXTRA,"out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
|
2519 |
|
|
in->sequence,arcsoft->split_flag,
|
2520 |
|
|
arcsoft->sequence);
|
2521 |
|
|
kfree_skb(in->skb,FREE_WRITE);
|
2522 |
|
|
in->skb=NULL;
|
2523 |
|
|
lp->stats.rx_errors++;
|
2524 |
|
|
lp->stats.rx_missed_errors++;
|
2525 |
|
|
in->lastpacket=in->numpackets=0;
|
2526 |
|
|
return;
|
2527 |
|
|
}
|
2528 |
|
|
|
2529 |
|
|
soft=(struct ClientData *)in->skb->data;
|
2530 |
|
|
}
|
2531 |
|
|
|
2532 |
|
|
skb=in->skb;
|
2533 |
|
|
|
2534 |
|
|
memcpy(skb->data+skb->len,
|
2535 |
|
|
(u_char *)arcsoft+sizeof(struct ClientData),
|
2536 |
|
|
length-sizeof(struct ClientData));
|
2537 |
|
|
|
2538 |
|
|
skb->len+=length-sizeof(struct ClientData);
|
2539 |
|
|
|
2540 |
|
|
soft->daddr=daddr;
|
2541 |
|
|
soft->saddr=saddr;
|
2542 |
|
|
|
2543 |
|
|
/* are we done? */
|
2544 |
|
|
if (in->lastpacket == in->numpackets)
|
2545 |
|
|
{
|
2546 |
|
|
if (!skb || !in->skb)
|
2547 |
|
|
{
|
2548 |
|
|
BUGMSG(D_NORMAL,"?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
|
2549 |
|
|
skb,in->skb);
|
2550 |
|
|
}
|
2551 |
|
|
else
|
2552 |
|
|
{
|
2553 |
|
|
in->skb=NULL;
|
2554 |
|
|
in->lastpacket=in->numpackets=0;
|
2555 |
|
|
|
2556 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"rx");
|
2557 |
|
|
|
2558 |
|
|
skb->protocol=arcnetA_type_trans(skb,dev);
|
2559 |
|
|
|
2560 |
|
|
netif_rx(skb);
|
2561 |
|
|
}
|
2562 |
|
|
}
|
2563 |
|
|
}
|
2564 |
|
|
}
|
2565 |
|
|
|
2566 |
|
|
|
2567 |
|
|
|
2568 |
|
|
|
2569 |
|
|
/****************************************************************************
|
2570 |
|
|
* *
|
2571 |
|
|
* Miscellaneous routines *
|
2572 |
|
|
* *
|
2573 |
|
|
****************************************************************************/
|
2574 |
|
|
|
2575 |
|
|
|
2576 |
|
|
/* Get the current statistics. This may be called with the card open or
|
2577 |
|
|
* closed.
|
2578 |
|
|
*/
|
2579 |
|
|
|
2580 |
|
|
static struct enet_statistics *
|
2581 |
|
|
arcnet_get_stats(struct device *dev)
|
2582 |
|
|
{
|
2583 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2584 |
|
|
|
2585 |
|
|
return &lp->stats;
|
2586 |
|
|
}
|
2587 |
|
|
|
2588 |
|
|
#if 0
|
2589 |
|
|
/* Set or clear the multicast filter for this adaptor.
|
2590 |
|
|
* num_addrs == -1 Promiscuous mode, receive all packets
|
2591 |
|
|
* num_addrs == 0 Normal mode, clear multicast list
|
2592 |
|
|
* num_addrs > 0 Multicast mode, receive normal and MC packets, and do
|
2593 |
|
|
* best-effort filtering.
|
2594 |
|
|
*/
|
2595 |
|
|
static void
|
2596 |
|
|
set_multicast_list(struct device *dev)
|
2597 |
|
|
{
|
2598 |
|
|
#if 0 /* no promiscuous mode at all on most ARCnet models */
|
2599 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
|
2600 |
|
|
|
2601 |
|
|
short ioaddr = dev->base_addr;
|
2602 |
|
|
if (num_addrs) {
|
2603 |
|
|
outw(69, ioaddr); /* Enable promiscuous mode */
|
2604 |
|
|
} else
|
2605 |
|
|
outw(99, ioaddr); /* Disable promiscuous mode, use normal mode */
|
2606 |
|
|
#endif
|
2607 |
|
|
}
|
2608 |
|
|
#endif
|
2609 |
|
|
|
2610 |
|
|
/* Create the ARCnet ClientData header for an arbitrary protocol layer
|
2611 |
|
|
*
|
2612 |
|
|
* saddr=NULL means use device source address (always will anyway)
|
2613 |
|
|
* daddr=NULL means leave destination address (eg unresolved arp)
|
2614 |
|
|
*/
|
2615 |
|
|
int arcnetA_header(struct sk_buff *skb,struct device *dev,
|
2616 |
|
|
unsigned short type,void *daddr,void *saddr,unsigned len)
|
2617 |
|
|
{
|
2618 |
|
|
struct ClientData *head = (struct ClientData *)
|
2619 |
|
|
skb_push(skb,dev->hard_header_len);
|
2620 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
|
2621 |
|
|
|
2622 |
|
|
BUGMSG(D_DURING,"create header from %d to %d; protocol %d (%Xh); size %u.\n",
|
2623 |
|
|
saddr ? *(u_char*)saddr : -1,
|
2624 |
|
|
daddr ? *(u_char*)daddr : -1,
|
2625 |
|
|
type,type,len);
|
2626 |
|
|
|
2627 |
|
|
/* set the protocol ID according to RFC1201 */
|
2628 |
|
|
switch(type)
|
2629 |
|
|
{
|
2630 |
|
|
case ETH_P_IP:
|
2631 |
|
|
head->protocol_id=ARC_P_IP;
|
2632 |
|
|
break;
|
2633 |
|
|
case ETH_P_ARP:
|
2634 |
|
|
head->protocol_id=ARC_P_ARP;
|
2635 |
|
|
break;
|
2636 |
|
|
case ETH_P_RARP:
|
2637 |
|
|
head->protocol_id=ARC_P_RARP;
|
2638 |
|
|
break;
|
2639 |
|
|
case ETH_P_IPX:
|
2640 |
|
|
case ETH_P_802_3:
|
2641 |
|
|
case ETH_P_802_2:
|
2642 |
|
|
head->protocol_id=ARC_P_IPX;
|
2643 |
|
|
break;
|
2644 |
|
|
case ETH_P_ATALK:
|
2645 |
|
|
head->protocol_id=ARC_P_ATALK;
|
2646 |
|
|
break;
|
2647 |
|
|
default:
|
2648 |
|
|
BUGMSG(D_NORMAL,"I don't understand protocol %d (%Xh)\n",
|
2649 |
|
|
type,type);
|
2650 |
|
|
lp->stats.tx_errors++;
|
2651 |
|
|
lp->stats.tx_aborted_errors++;
|
2652 |
|
|
return 0;
|
2653 |
|
|
}
|
2654 |
|
|
|
2655 |
|
|
/*
|
2656 |
|
|
* Set the source hardware address.
|
2657 |
|
|
*
|
2658 |
|
|
* This is pretty pointless for most purposes, but it can help
|
2659 |
|
|
* in debugging. saddr is stored in the ClientData header and
|
2660 |
|
|
* removed before sending the packet (since ARCnet does not allow
|
2661 |
|
|
* us to change the source address in the actual packet sent)
|
2662 |
|
|
*/
|
2663 |
|
|
if(saddr)
|
2664 |
|
|
head->saddr=((u_char*)saddr)[0];
|
2665 |
|
|
else
|
2666 |
|
|
head->saddr=((u_char*)(dev->dev_addr))[0];
|
2667 |
|
|
|
2668 |
|
|
head->split_flag=0; /* split packets are done elsewhere */
|
2669 |
|
|
head->sequence=0; /* so are sequence numbers */
|
2670 |
|
|
|
2671 |
|
|
/* supposedly if daddr is NULL, we should ignore it... */
|
2672 |
|
|
if(daddr)
|
2673 |
|
|
{
|
2674 |
|
|
head->daddr=((u_char*)daddr)[0];
|
2675 |
|
|
return dev->hard_header_len;
|
2676 |
|
|
}
|
2677 |
|
|
else
|
2678 |
|
|
head->daddr=0; /* better fill one in anyway */
|
2679 |
|
|
|
2680 |
|
|
return -dev->hard_header_len;
|
2681 |
|
|
}
|
2682 |
|
|
|
2683 |
|
|
|
2684 |
|
|
|
2685 |
|
|
/* Rebuild the ARCnet ClientData header. This is called after an ARP
|
2686 |
|
|
* (or in future other address resolution) has completed on this
|
2687 |
|
|
* sk_buff. We now let ARP fill in the other fields.
|
2688 |
|
|
*/
|
2689 |
|
|
int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
|
2690 |
|
|
struct sk_buff *skb)
|
2691 |
|
|
{
|
2692 |
|
|
struct ClientData *head = (struct ClientData *)buff;
|
2693 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
|
2694 |
|
|
int status;
|
2695 |
|
|
|
2696 |
|
|
/*
|
2697 |
|
|
* Only ARP and IP are currently supported
|
2698 |
|
|
*/
|
2699 |
|
|
|
2700 |
|
|
if(head->protocol_id != ARC_P_IP)
|
2701 |
|
|
{
|
2702 |
|
|
BUGMSG(D_NORMAL,"I don't understand protocol type %d (%Xh) addresses!\n",
|
2703 |
|
|
head->protocol_id,head->protocol_id);
|
2704 |
|
|
lp->stats.tx_errors++;
|
2705 |
|
|
lp->stats.tx_aborted_errors++;
|
2706 |
|
|
head->daddr=0;
|
2707 |
|
|
/*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
|
2708 |
|
|
return 0;
|
2709 |
|
|
}
|
2710 |
|
|
|
2711 |
|
|
/*
|
2712 |
|
|
* Try to get ARP to resolve the header.
|
2713 |
|
|
*/
|
2714 |
|
|
#ifdef CONFIG_INET
|
2715 |
|
|
BUGMSG(D_DURING,"rebuild header from %d to %d; protocol %Xh\n",
|
2716 |
|
|
head->saddr,head->daddr,head->protocol_id);
|
2717 |
|
|
status=arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
|
2718 |
|
|
BUGMSG(D_DURING," rebuilt: from %d to %d; protocol %Xh\n",
|
2719 |
|
|
head->saddr,head->daddr,head->protocol_id);
|
2720 |
|
|
return status;
|
2721 |
|
|
#else
|
2722 |
|
|
return 0;
|
2723 |
|
|
#endif
|
2724 |
|
|
}
|
2725 |
|
|
|
2726 |
|
|
|
2727 |
|
|
/* Determine a packet's protocol ID.
|
2728 |
|
|
*
|
2729 |
|
|
* With ARCnet we have to convert everything to Ethernet-style stuff.
|
2730 |
|
|
*/
|
2731 |
|
|
unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
|
2732 |
|
|
{
|
2733 |
|
|
struct ClientData *head;
|
2734 |
|
|
struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
|
2735 |
|
|
|
2736 |
|
|
/* Pull off the arcnet header. */
|
2737 |
|
|
skb->mac.raw=skb->data;
|
2738 |
|
|
skb_pull(skb,dev->hard_header_len);
|
2739 |
|
|
head=(struct ClientData *)skb->mac.raw;
|
2740 |
|
|
|
2741 |
|
|
if (head->daddr==0)
|
2742 |
|
|
skb->pkt_type=PACKET_BROADCAST;
|
2743 |
|
|
else if (dev->flags&IFF_PROMISC)
|
2744 |
|
|
{
|
2745 |
|
|
/* if we're not sending to ourselves :) */
|
2746 |
|
|
if (head->daddr != dev->dev_addr[0])
|
2747 |
|
|
skb->pkt_type=PACKET_OTHERHOST;
|
2748 |
|
|
}
|
2749 |
|
|
|
2750 |
|
|
/* now return the protocol number */
|
2751 |
|
|
switch (head->protocol_id)
|
2752 |
|
|
{
|
2753 |
|
|
case ARC_P_IP: return htons(ETH_P_IP);
|
2754 |
|
|
case ARC_P_ARP: return htons(ETH_P_ARP);
|
2755 |
|
|
case ARC_P_RARP: return htons(ETH_P_RARP);
|
2756 |
|
|
|
2757 |
|
|
case ARC_P_IPX:
|
2758 |
|
|
case ARC_P_NOVELL_EC:
|
2759 |
|
|
return htons(ETH_P_802_3);
|
2760 |
|
|
default:
|
2761 |
|
|
lp->stats.rx_errors++;
|
2762 |
|
|
lp->stats.rx_crc_errors++;
|
2763 |
|
|
return 0;
|
2764 |
|
|
}
|
2765 |
|
|
|
2766 |
|
|
return htons(ETH_P_IP);
|
2767 |
|
|
}
|
2768 |
|
|
|
2769 |
|
|
|
2770 |
|
|
#ifdef CONFIG_ARCNET_ETH
|
2771 |
|
|
/****************************************************************************
|
2772 |
|
|
* *
|
2773 |
|
|
* Ethernet-Encap Support *
|
2774 |
|
|
* *
|
2775 |
|
|
****************************************************************************/
|
2776 |
|
|
|
2777 |
|
|
/* Initialize the arc0e device.
|
2778 |
|
|
*/
|
2779 |
|
|
static int arcnetE_init(struct device *dev)
|
2780 |
|
|
{
|
2781 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2782 |
|
|
|
2783 |
|
|
ether_setup(dev); /* we're emulating ether here, not ARCnet */
|
2784 |
|
|
dev->dev_addr[0]=0;
|
2785 |
|
|
dev->dev_addr[5]=lp->stationid;
|
2786 |
|
|
dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len-1;
|
2787 |
|
|
dev->open=arcnetE_open_close;
|
2788 |
|
|
dev->stop=arcnetE_open_close;
|
2789 |
|
|
dev->hard_start_xmit=arcnetE_send_packet;
|
2790 |
|
|
|
2791 |
|
|
BUGMSG(D_NORMAL,"ARCnet Ethernet-Encap protocol initialized.\n");
|
2792 |
|
|
|
2793 |
|
|
return 0;
|
2794 |
|
|
}
|
2795 |
|
|
|
2796 |
|
|
|
2797 |
|
|
/* Bring up/down the arc0e device - we don't actually have to do anything,
|
2798 |
|
|
* since our parent arc0 handles the card I/O itself.
|
2799 |
|
|
*/
|
2800 |
|
|
static int arcnetE_open_close(struct device *dev)
|
2801 |
|
|
{
|
2802 |
|
|
return 0;
|
2803 |
|
|
}
|
2804 |
|
|
|
2805 |
|
|
|
2806 |
|
|
/* Called by the kernel in order to transmit an ethernet-type packet.
|
2807 |
|
|
*/
|
2808 |
|
|
static int
|
2809 |
|
|
arcnetE_send_packet(struct sk_buff *skb, struct device *dev)
|
2810 |
|
|
{
|
2811 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2812 |
|
|
int ioaddr=dev->base_addr,bad;
|
2813 |
|
|
union ArcPacket *arcpacket =
|
2814 |
|
|
(union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
|
2815 |
|
|
u_char *arcsoft,daddr;
|
2816 |
|
|
short offset,length=skb->len+1;
|
2817 |
|
|
|
2818 |
|
|
lp->intx++;
|
2819 |
|
|
|
2820 |
|
|
bad=arcnet_send_packet_bad(skb,dev);
|
2821 |
|
|
if (bad)
|
2822 |
|
|
{
|
2823 |
|
|
lp->intx--;
|
2824 |
|
|
return bad;
|
2825 |
|
|
}
|
2826 |
|
|
|
2827 |
|
|
TBUSY=1;
|
2828 |
|
|
|
2829 |
|
|
if (length>XMTU)
|
2830 |
|
|
{
|
2831 |
|
|
BUGMSG(D_NORMAL,"MTU must be <= 493 for ethernet encap (length=%d).\n",
|
2832 |
|
|
length);
|
2833 |
|
|
BUGMSG(D_NORMAL,"transmit aborted.\n");
|
2834 |
|
|
|
2835 |
|
|
dev_kfree_skb(skb,FREE_WRITE);
|
2836 |
|
|
lp->intx--;
|
2837 |
|
|
return 0;
|
2838 |
|
|
}
|
2839 |
|
|
|
2840 |
|
|
BUGMSG(D_DURING,"starting tx sequence...\n");
|
2841 |
|
|
|
2842 |
|
|
lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate btw 2 & 3 */
|
2843 |
|
|
|
2844 |
|
|
#ifndef SLOW_XMIT_COPY
|
2845 |
|
|
/* clean out the page to make debugging make more sense :) */
|
2846 |
|
|
BUGLVL(D_DURING)
|
2847 |
|
|
memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
|
2848 |
|
|
#endif
|
2849 |
|
|
|
2850 |
|
|
/* broadcasts have address FF:FF:FF:FF:FF:FF in etherspeak */
|
2851 |
|
|
if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
|
2852 |
|
|
daddr=arcpacket->hardheader.destination=0;
|
2853 |
|
|
else
|
2854 |
|
|
daddr=arcpacket->hardheader.destination=
|
2855 |
|
|
((struct ethhdr*)(skb->data))->h_dest[5];
|
2856 |
|
|
|
2857 |
|
|
/* load packet into shared memory */
|
2858 |
|
|
offset=512-length;
|
2859 |
|
|
if (length>MTU) /* long/exception packet */
|
2860 |
|
|
{
|
2861 |
|
|
if (length<MinTU) offset-=3;
|
2862 |
|
|
arcpacket->hardheader.offset1=0;
|
2863 |
|
|
arcpacket->hardheader.offset2=offset;
|
2864 |
|
|
}
|
2865 |
|
|
else /* short packet */
|
2866 |
|
|
{
|
2867 |
|
|
arcpacket->hardheader.offset1=(offset-=256);
|
2868 |
|
|
}
|
2869 |
|
|
|
2870 |
|
|
BUGMSG(D_DURING," length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
|
2871 |
|
|
length,offset,arcpacket->hardheader.offset1,
|
2872 |
|
|
arcpacket->hardheader.offset2);
|
2873 |
|
|
|
2874 |
|
|
arcsoft=&arcpacket->raw[offset];
|
2875 |
|
|
arcsoft[0]=ARC_P_ETHER;
|
2876 |
|
|
arcsoft++;
|
2877 |
|
|
|
2878 |
|
|
/* copy the packet into ARCnet shmem
|
2879 |
|
|
* - the first bytes of ClientData header are skipped
|
2880 |
|
|
*/
|
2881 |
|
|
BUGMSG(D_DURING,"ready to memcpy\n");
|
2882 |
|
|
|
2883 |
|
|
memcpy(arcsoft,skb->data,skb->len);
|
2884 |
|
|
|
2885 |
|
|
BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
|
2886 |
|
|
daddr,length);
|
2887 |
|
|
|
2888 |
|
|
BUGLVL(D_TX) arcnet_dump_packet(dev,arcpacket->raw,length>=240,"tx");
|
2889 |
|
|
|
2890 |
|
|
lp->lastload_dest=daddr;
|
2891 |
|
|
lp->txready=lp->txbuf; /* packet is ready for sending */
|
2892 |
|
|
|
2893 |
|
|
dev_kfree_skb(skb,FREE_WRITE);
|
2894 |
|
|
|
2895 |
|
|
if (arcnet_go_tx(dev,1))
|
2896 |
|
|
{
|
2897 |
|
|
/* inform upper layers */
|
2898 |
|
|
TBUSY=0;
|
2899 |
|
|
mark_bh(NET_BH);
|
2900 |
|
|
}
|
2901 |
|
|
|
2902 |
|
|
dev->trans_start=jiffies;
|
2903 |
|
|
lp->intx--;
|
2904 |
|
|
|
2905 |
|
|
/* make sure we didn't ignore a TX IRQ while we were in here */
|
2906 |
|
|
lp->intmask |= TXFREEflag;
|
2907 |
|
|
SETMASK;
|
2908 |
|
|
|
2909 |
|
|
return 0;
|
2910 |
|
|
}
|
2911 |
|
|
|
2912 |
|
|
|
2913 |
|
|
/* Packet receiver for ethernet-encap packets.
|
2914 |
|
|
*/
|
2915 |
|
|
static void
|
2916 |
|
|
arcnetE_rx(struct device *dev,u_char *arcsoft,
|
2917 |
|
|
int length,u_char saddr, u_char daddr)
|
2918 |
|
|
{
|
2919 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2920 |
|
|
struct sk_buff *skb;
|
2921 |
|
|
|
2922 |
|
|
BUGMSG(D_DURING,"it's an ethernet-encap packet (length=%d)\n",
|
2923 |
|
|
length);
|
2924 |
|
|
|
2925 |
|
|
skb = alloc_skb(length, GFP_ATOMIC);
|
2926 |
|
|
if (skb == NULL) {
|
2927 |
|
|
BUGMSG(D_NORMAL,"Memory squeeze, dropping packet.\n");
|
2928 |
|
|
lp->stats.rx_dropped++;
|
2929 |
|
|
return;
|
2930 |
|
|
}
|
2931 |
|
|
|
2932 |
|
|
skb->len = length;
|
2933 |
|
|
skb->dev = dev;
|
2934 |
|
|
|
2935 |
|
|
memcpy(skb->data,(u_char *)arcsoft+1,length-1);
|
2936 |
|
|
|
2937 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"rx");
|
2938 |
|
|
|
2939 |
|
|
skb->protocol=eth_type_trans(skb,dev);
|
2940 |
|
|
|
2941 |
|
|
netif_rx(skb);
|
2942 |
|
|
}
|
2943 |
|
|
|
2944 |
|
|
#endif /* CONFIG_ARCNET_ETH */
|
2945 |
|
|
|
2946 |
|
|
#ifdef CONFIG_ARCNET_1051
|
2947 |
|
|
/****************************************************************************
|
2948 |
|
|
* *
|
2949 |
|
|
* RFC1051 Support *
|
2950 |
|
|
* *
|
2951 |
|
|
****************************************************************************/
|
2952 |
|
|
|
2953 |
|
|
/* Initialize the arc0s device.
|
2954 |
|
|
*/
|
2955 |
|
|
static int arcnetS_init(struct device *dev)
|
2956 |
|
|
{
|
2957 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2958 |
|
|
|
2959 |
|
|
arcnet_setup(dev);
|
2960 |
|
|
|
2961 |
|
|
/* And now fill particular fields with arcnet values */
|
2962 |
|
|
dev->dev_addr[0]=lp->stationid;
|
2963 |
|
|
dev->hard_header_len=sizeof(struct S_ClientData);
|
2964 |
|
|
dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len
|
2965 |
|
|
+ S_EXTRA_CLIENTDATA;
|
2966 |
|
|
dev->open=arcnetS_open_close;
|
2967 |
|
|
dev->stop=arcnetS_open_close;
|
2968 |
|
|
dev->hard_start_xmit=arcnetS_send_packet;
|
2969 |
|
|
dev->hard_header=arcnetS_header;
|
2970 |
|
|
dev->rebuild_header=arcnetS_rebuild_header;
|
2971 |
|
|
BUGMSG(D_NORMAL,"ARCnet RFC1051 (NetBSD, AmiTCP) protocol initialized.\n");
|
2972 |
|
|
|
2973 |
|
|
return 0;
|
2974 |
|
|
}
|
2975 |
|
|
|
2976 |
|
|
|
2977 |
|
|
/* Bring up/down the arc0s device - we don't actually have to do anything,
|
2978 |
|
|
* since our parent arc0 handles the card I/O itself.
|
2979 |
|
|
*/
|
2980 |
|
|
static int arcnetS_open_close(struct device *dev)
|
2981 |
|
|
{
|
2982 |
|
|
return 0;
|
2983 |
|
|
}
|
2984 |
|
|
|
2985 |
|
|
|
2986 |
|
|
/* Called by the kernel in order to transmit an RFC1051-type packet.
|
2987 |
|
|
*/
|
2988 |
|
|
static int
|
2989 |
|
|
arcnetS_send_packet(struct sk_buff *skb, struct device *dev)
|
2990 |
|
|
{
|
2991 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
2992 |
|
|
int ioaddr=dev->base_addr,bad,length;
|
2993 |
|
|
struct S_ClientData *hdr=(struct S_ClientData *)skb->data;
|
2994 |
|
|
|
2995 |
|
|
lp->intx++;
|
2996 |
|
|
|
2997 |
|
|
bad=arcnet_send_packet_bad(skb,dev);
|
2998 |
|
|
if (bad)
|
2999 |
|
|
{
|
3000 |
|
|
lp->intx--;
|
3001 |
|
|
return bad;
|
3002 |
|
|
}
|
3003 |
|
|
|
3004 |
|
|
TBUSY=1;
|
3005 |
|
|
|
3006 |
|
|
length = 1 < skb->len ? skb->len : 1;
|
3007 |
|
|
|
3008 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"tx");
|
3009 |
|
|
|
3010 |
|
|
/* fits in one packet? */
|
3011 |
|
|
if (length-S_EXTRA_CLIENTDATA<=XMTU)
|
3012 |
|
|
{
|
3013 |
|
|
arcnetAS_prepare_tx(dev,
|
3014 |
|
|
skb->data+S_EXTRA_CLIENTDATA,
|
3015 |
|
|
sizeof(struct S_ClientData)-S_EXTRA_CLIENTDATA,
|
3016 |
|
|
skb->data+sizeof(struct S_ClientData),
|
3017 |
|
|
length-sizeof(struct S_ClientData),
|
3018 |
|
|
hdr->daddr,0);
|
3019 |
|
|
|
3020 |
|
|
/* done right away */
|
3021 |
|
|
dev_kfree_skb(skb,FREE_WRITE);
|
3022 |
|
|
|
3023 |
|
|
if (arcnet_go_tx(dev,1))
|
3024 |
|
|
{
|
3025 |
|
|
/* inform upper layers */
|
3026 |
|
|
TBUSY=0;
|
3027 |
|
|
mark_bh(NET_BH);
|
3028 |
|
|
}
|
3029 |
|
|
}
|
3030 |
|
|
else /* too big for one - not accepted */
|
3031 |
|
|
{
|
3032 |
|
|
BUGMSG(D_NORMAL,"packet too long (length=%d)\n",
|
3033 |
|
|
length);
|
3034 |
|
|
dev_kfree_skb(skb,FREE_WRITE);
|
3035 |
|
|
lp->stats.tx_dropped++;
|
3036 |
|
|
TBUSY=0;
|
3037 |
|
|
mark_bh(NET_BH);
|
3038 |
|
|
}
|
3039 |
|
|
|
3040 |
|
|
dev->trans_start=jiffies;
|
3041 |
|
|
lp->intx--;
|
3042 |
|
|
|
3043 |
|
|
/* make sure we didn't ignore a TX IRQ while we were in here */
|
3044 |
|
|
lp->intmask |= TXFREEflag;
|
3045 |
|
|
SETMASK;
|
3046 |
|
|
|
3047 |
|
|
return 0;
|
3048 |
|
|
}
|
3049 |
|
|
|
3050 |
|
|
|
3051 |
|
|
/* Packet receiver for RFC1051 packets;
|
3052 |
|
|
*/
|
3053 |
|
|
static void
|
3054 |
|
|
arcnetS_rx(struct device *dev,u_char *buf,
|
3055 |
|
|
int length,u_char saddr, u_char daddr)
|
3056 |
|
|
{
|
3057 |
|
|
struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
|
3058 |
|
|
struct sk_buff *skb;
|
3059 |
|
|
struct S_ClientData *arcsoft,*soft;
|
3060 |
|
|
|
3061 |
|
|
arcsoft=(struct S_ClientData *)(buf-S_EXTRA_CLIENTDATA);
|
3062 |
|
|
length+=S_EXTRA_CLIENTDATA;
|
3063 |
|
|
|
3064 |
|
|
BUGMSG(D_DURING,"it's an RFC1051 packet (length=%d)\n",
|
3065 |
|
|
length);
|
3066 |
|
|
|
3067 |
|
|
|
3068 |
|
|
|
3069 |
|
|
{ /* was "if not split" in A protocol, S is never split */
|
3070 |
|
|
|
3071 |
|
|
skb = alloc_skb(length, GFP_ATOMIC);
|
3072 |
|
|
if (skb == NULL) {
|
3073 |
|
|
BUGMSG(D_NORMAL,"Memory squeeze, dropping packet.\n");
|
3074 |
|
|
lp->stats.rx_dropped++;
|
3075 |
|
|
return;
|
3076 |
|
|
}
|
3077 |
|
|
soft=(struct S_ClientData *)skb->data;
|
3078 |
|
|
skb->len = length;
|
3079 |
|
|
memcpy((u_char *)soft + sizeof(struct S_ClientData)
|
3080 |
|
|
- S_EXTRA_CLIENTDATA,
|
3081 |
|
|
(u_char *)arcsoft + sizeof(struct S_ClientData)
|
3082 |
|
|
- S_EXTRA_CLIENTDATA,
|
3083 |
|
|
length - sizeof(struct S_ClientData)
|
3084 |
|
|
+ S_EXTRA_CLIENTDATA);
|
3085 |
|
|
soft->protocol_id=arcsoft->protocol_id;
|
3086 |
|
|
soft->daddr=daddr;
|
3087 |
|
|
soft->saddr=saddr;
|
3088 |
|
|
skb->dev = dev; /* is already lp->sdev */
|
3089 |
|
|
|
3090 |
|
|
BUGLVL(D_SKB) arcnet_dump_skb(dev,skb,"rx");
|
3091 |
|
|
|
3092 |
|
|
skb->protocol=arcnetS_type_trans(skb,dev);
|
3093 |
|
|
|
3094 |
|
|
netif_rx(skb);
|
3095 |
|
|
}
|
3096 |
|
|
}
|
3097 |
|
|
|
3098 |
|
|
|
3099 |
|
|
/* Create the ARCnet ClientData header for an arbitrary protocol layer
|
3100 |
|
|
*
|
3101 |
|
|
* saddr=NULL means use device source address (always will anyway)
|
3102 |
|
|
* daddr=NULL means leave destination address (eg unresolved arp)
|
3103 |
|
|
*/
|
3104 |
|
|
int arcnetS_header(struct sk_buff *skb,struct device *dev,
|
3105 |
|
|
unsigned short type,void *daddr,void *saddr,unsigned len)
|
3106 |
|
|
{
|
3107 |
|
|
struct S_ClientData *head = (struct S_ClientData *)
|
3108 |
|
|
skb_push(skb,dev->hard_header_len);
|
3109 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
|
3110 |
|
|
|
3111 |
|
|
/* set the protocol ID according to RFC1051 */
|
3112 |
|
|
switch(type)
|
3113 |
|
|
{
|
3114 |
|
|
case ETH_P_IP:
|
3115 |
|
|
head->protocol_id=ARC_P_IP_RFC1051;
|
3116 |
|
|
BUGMSG(D_DURING,"S_header: IP_RFC1051 packet.\n");
|
3117 |
|
|
break;
|
3118 |
|
|
case ETH_P_ARP:
|
3119 |
|
|
head->protocol_id=ARC_P_ARP_RFC1051;
|
3120 |
|
|
BUGMSG(D_DURING,"S_header: ARP_RFC1051 packet.\n");
|
3121 |
|
|
break;
|
3122 |
|
|
default:
|
3123 |
|
|
BUGMSG(D_NORMAL,"I don't understand protocol %d (%Xh)\n",
|
3124 |
|
|
type,type);
|
3125 |
|
|
lp->stats.tx_errors++;
|
3126 |
|
|
lp->stats.tx_aborted_errors++;
|
3127 |
|
|
return 0;
|
3128 |
|
|
}
|
3129 |
|
|
|
3130 |
|
|
/*
|
3131 |
|
|
* Set the source hardware address.
|
3132 |
|
|
*
|
3133 |
|
|
* This is pretty pointless for most purposes, but it can help
|
3134 |
|
|
* in debugging. saddr is stored in the ClientData header and
|
3135 |
|
|
* removed before sending the packet (since ARCnet does not allow
|
3136 |
|
|
* us to change the source address in the actual packet sent)
|
3137 |
|
|
*/
|
3138 |
|
|
if(saddr)
|
3139 |
|
|
head->saddr=((u_char*)saddr)[0];
|
3140 |
|
|
else
|
3141 |
|
|
head->saddr=((u_char*)(dev->dev_addr))[0];
|
3142 |
|
|
|
3143 |
|
|
/* supposedly if daddr is NULL, we should ignore it... */
|
3144 |
|
|
if(daddr)
|
3145 |
|
|
{
|
3146 |
|
|
head->daddr=((u_char*)daddr)[0];
|
3147 |
|
|
return dev->hard_header_len;
|
3148 |
|
|
}
|
3149 |
|
|
else
|
3150 |
|
|
head->daddr=0; /* better fill one in anyway */
|
3151 |
|
|
|
3152 |
|
|
return -dev->hard_header_len;
|
3153 |
|
|
}
|
3154 |
|
|
|
3155 |
|
|
|
3156 |
|
|
/* Rebuild the ARCnet ClientData header. This is called after an ARP
|
3157 |
|
|
* (or in future other address resolution) has completed on this
|
3158 |
|
|
* sk_buff. We now let ARP fill in the other fields.
|
3159 |
|
|
*/
|
3160 |
|
|
int arcnetS_rebuild_header(void *buff,struct device *dev,unsigned long dst,
|
3161 |
|
|
struct sk_buff *skb)
|
3162 |
|
|
{
|
3163 |
|
|
struct S_ClientData *head = (struct S_ClientData *)buff;
|
3164 |
|
|
struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
|
3165 |
|
|
|
3166 |
|
|
/*
|
3167 |
|
|
* Only ARP and IP are currently supported
|
3168 |
|
|
*/
|
3169 |
|
|
|
3170 |
|
|
if(head->protocol_id != ARC_P_IP_RFC1051)
|
3171 |
|
|
{
|
3172 |
|
|
BUGMSG(D_NORMAL,"I don't understand protocol type %d (%Xh) addresses!\n",
|
3173 |
|
|
head->protocol_id,head->protocol_id);
|
3174 |
|
|
lp->stats.tx_errors++;
|
3175 |
|
|
lp->stats.tx_aborted_errors++;
|
3176 |
|
|
head->daddr=0;
|
3177 |
|
|
/*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
|
3178 |
|
|
return 0;
|
3179 |
|
|
}
|
3180 |
|
|
|
3181 |
|
|
/*
|
3182 |
|
|
* Try to get ARP to resolve the header.
|
3183 |
|
|
*/
|
3184 |
|
|
#ifdef CONFIG_INET
|
3185 |
|
|
return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
|
3186 |
|
|
#else
|
3187 |
|
|
return 0;
|
3188 |
|
|
#endif
|
3189 |
|
|
}
|
3190 |
|
|
|
3191 |
|
|
|
3192 |
|
|
/* Determine a packet's protocol ID.
|
3193 |
|
|
*
|
3194 |
|
|
* With ARCnet we have to convert everything to Ethernet-style stuff.
|
3195 |
|
|
*/
|
3196 |
|
|
unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev)
|
3197 |
|
|
{
|
3198 |
|
|
struct S_ClientData *head;
|
3199 |
|
|
struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
|
3200 |
|
|
|
3201 |
|
|
/* Pull off the arcnet header. */
|
3202 |
|
|
skb->mac.raw=skb->data;
|
3203 |
|
|
skb_pull(skb,dev->hard_header_len);
|
3204 |
|
|
head=(struct S_ClientData *)skb->mac.raw;
|
3205 |
|
|
|
3206 |
|
|
if (head->daddr==0)
|
3207 |
|
|
skb->pkt_type=PACKET_BROADCAST;
|
3208 |
|
|
else if (dev->flags&IFF_PROMISC)
|
3209 |
|
|
{
|
3210 |
|
|
/* if we're not sending to ourselves :) */
|
3211 |
|
|
if (head->daddr != dev->dev_addr[0])
|
3212 |
|
|
skb->pkt_type=PACKET_OTHERHOST;
|
3213 |
|
|
}
|
3214 |
|
|
|
3215 |
|
|
/* now return the protocol number */
|
3216 |
|
|
switch (head->protocol_id)
|
3217 |
|
|
{
|
3218 |
|
|
case ARC_P_IP_RFC1051: return htons(ETH_P_IP);
|
3219 |
|
|
case ARC_P_ARP_RFC1051: return htons(ETH_P_ARP);
|
3220 |
|
|
case ARC_P_ATALK: return htons(ETH_P_ATALK); /* untested appletalk */
|
3221 |
|
|
default:
|
3222 |
|
|
lp->stats.rx_errors++;
|
3223 |
|
|
lp->stats.rx_crc_errors++;
|
3224 |
|
|
return 0;
|
3225 |
|
|
}
|
3226 |
|
|
|
3227 |
|
|
return htons(ETH_P_IP);
|
3228 |
|
|
}
|
3229 |
|
|
|
3230 |
|
|
#endif /* CONFIG_ARCNET_1051 */
|
3231 |
|
|
|
3232 |
|
|
/****************************************************************************
|
3233 |
|
|
* *
|
3234 |
|
|
* Kernel Loadable Module Support *
|
3235 |
|
|
* *
|
3236 |
|
|
****************************************************************************/
|
3237 |
|
|
|
3238 |
|
|
|
3239 |
|
|
#ifdef MODULE
|
3240 |
|
|
|
3241 |
|
|
static char devicename[9] = "";
|
3242 |
|
|
static struct device thiscard = {
|
3243 |
|
|
devicename, /* device name is inserted by linux/drivers/net/net_init.c */
|
3244 |
|
|
0, 0, 0, 0,
|
3245 |
|
|
0, 0, /* I/O address, IRQ */
|
3246 |
|
|
0, 0, 0, NULL, arcnet_probe
|
3247 |
|
|
};
|
3248 |
|
|
|
3249 |
|
|
|
3250 |
|
|
static int io=0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
|
3251 |
|
|
static int irqnum=0; /* or use the insmod io= irq= shmem= options */
|
3252 |
|
|
static int irq=0;
|
3253 |
|
|
static int shmem=0;
|
3254 |
|
|
static char *device = NULL; /* use eg. device="arc1" to change name */
|
3255 |
|
|
|
3256 |
|
|
int
|
3257 |
|
|
init_module(void)
|
3258 |
|
|
{
|
3259 |
|
|
if (device)
|
3260 |
|
|
strcpy(thiscard.name,device);
|
3261 |
|
|
#ifndef CONFIG_ARCNET_ETHNAME
|
3262 |
|
|
else if (!thiscard.name[0]) strcpy(thiscard.name,"arc0");
|
3263 |
|
|
#endif
|
3264 |
|
|
|
3265 |
|
|
thiscard.base_addr=io;
|
3266 |
|
|
|
3267 |
|
|
if (irq) irqnum=irq;
|
3268 |
|
|
|
3269 |
|
|
thiscard.irq=irqnum;
|
3270 |
|
|
if (thiscard.irq==2) thiscard.irq=9;
|
3271 |
|
|
|
3272 |
|
|
if (shmem)
|
3273 |
|
|
{
|
3274 |
|
|
thiscard.mem_start=shmem;
|
3275 |
|
|
thiscard.mem_end=thiscard.mem_start+512*4-1;
|
3276 |
|
|
thiscard.rmem_start=thiscard.mem_start+512*0;
|
3277 |
|
|
thiscard.rmem_end=thiscard.mem_start+512*2-1;
|
3278 |
|
|
}
|
3279 |
|
|
|
3280 |
|
|
if (register_netdev(&thiscard) != 0)
|
3281 |
|
|
return -EIO;
|
3282 |
|
|
return 0;
|
3283 |
|
|
}
|
3284 |
|
|
|
3285 |
|
|
void
|
3286 |
|
|
cleanup_module(void)
|
3287 |
|
|
{
|
3288 |
|
|
int ioaddr=thiscard.base_addr;
|
3289 |
|
|
|
3290 |
|
|
if (thiscard.start) arcnet_close(&thiscard);
|
3291 |
|
|
|
3292 |
|
|
/* Flush TX and disable RX */
|
3293 |
|
|
if (ioaddr)
|
3294 |
|
|
{
|
3295 |
|
|
outb(0,INTMASK); /* disable IRQ's */
|
3296 |
|
|
outb(NOTXcmd,COMMAND); /* stop transmit */
|
3297 |
|
|
outb(NORXcmd,COMMAND); /* disable receive */
|
3298 |
|
|
}
|
3299 |
|
|
|
3300 |
|
|
if (thiscard.irq)
|
3301 |
|
|
{
|
3302 |
|
|
irq2dev_map[thiscard.irq] = NULL;
|
3303 |
|
|
free_irq(thiscard.irq,NULL);
|
3304 |
|
|
}
|
3305 |
|
|
|
3306 |
|
|
if (thiscard.base_addr) release_region(thiscard.base_addr,
|
3307 |
|
|
ARCNET_TOTAL_SIZE);
|
3308 |
|
|
unregister_netdev(&thiscard);
|
3309 |
|
|
kfree(thiscard.priv);
|
3310 |
|
|
thiscard.priv = NULL;
|
3311 |
|
|
}
|
3312 |
|
|
|
3313 |
|
|
#endif /* MODULE */
|