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