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