1 /* $Id: arcnet.c,v 1.34 1997/11/09 11:04:55 mj Exp $
3 Written 1994-1996 by Avery Pennarun,
4 derived from skeleton.c by Donald Becker.
8 The original copyright was as follows:
10 skeleton.c Written 1993 by Donald Becker.
11 Copyright 1993 United States Government as represented by the
12 Director, National Security Agency. This software may only be used
13 and distributed according to the terms of the GNU Public License as
14 modified by SRC, incorporated herein by reference.
16 **********************
19 - Use register_netdevice() instead of register_netdev() to create
20 new devices for RFC1051 and Ethernet encapsulation in arcnet_open.
21 Likewise for unregistering them later. This avoids the deadlock
22 encountered because the original routines call rtnl_lock() when
23 it's already locked. [dw]
26 - Interrupt handler now also checks dev->[se]dev are non-NULL
27 to avoid crashes in interrupts during card init. [dw]
30 - Minor cleanup of debugging messages. [mj]
32 v2.93 ALPHA (97/11/06)
33 - irq2dev mapping removed.
34 - Interrupt handler now checks whether dev->priv is non-null in order
35 to avoid crashes in interrupts which come during card init. [mj]
37 v2.92 ALPHA (97/09/02)
38 - Code cleanup [Martin Mares <mj@atrey.karlin.mff.cuni.cz>]
39 - Better probing for the COM90xx chipset, although only as
40 a temporary solution until we implement adding of all found
43 v2.91 ALPHA (97/08/19)
44 - Add counting of octets in/out.
46 v2.90 ALPHA (97/08/08)
47 - Add support for kernel command line parsing so that chipset
48 drivers are usable when compiled in.
50 v2.80 ALPHA (97/08/01)
51 - Split source into multiple files; generic arcnet support and
52 individual chipset drivers. <Dave@imladris.demon.co.uk>
54 v2.61 ALPHA (97/07/30) by David Woodhouse (Dave@imladris.demon.co.uk)
55 for Nortel (Northern Telecom).
56 - Added support for IO-mapped modes and for SMC COM20020 chipset.
57 - Fixed (avoided) race condition in send_packet routines which was
58 discovered when the buffer copy routines got slow (?).
59 - Fixed support for device naming at load time.
60 - Added backplane, clock and timeout options for COM20020.
61 - Added support for promiscuous mode.
63 v2.60 ALPHA (96/11/23)
64 - Added patch from Vojtech Pavlik <vojtech@atrey.karlin.mff.cuni.cz>
65 and Martin Mares <mj@k332.feld.cvut.cz> to make the driver work
66 with the new Linux 2.1.x memory management. I modified their
67 patch quite a bit though; bugs are my fault. More changes should
68 be made to get eliminate any remaining phys_to_virt calls.
69 - Quietly ignore protocol id's 0, 1, 8, and 243. Thanks to Jake
70 Messinger <jake@ams.com> for reporting these codes and their
72 - Smarter shmem probe for cards with 4k mirrors. (does it work?)
73 - Initial support for RIM I type cards which use no I/O ports at
74 all. To use this option, you need to compile with RIM_I_MODE
75 enabled. Thanks to Kolja Waschk <kawk@yo.com> for explaining
76 RIM I programming to me. Now, does my RIM I code actually
80 - Turned arc0e/arc0s startup messages back on by default, as most
81 people will probably not notice the additional devices
82 otherwise. This causes undue confusion.
83 - Fixed a tiny but noticeable bug in the packet debugging routines
86 The following has been SUMMARIZED. The complete ChangeLog is
87 available in the full Linux-ARCnet package at
88 http://www.worldvisions.ca/~apenwarr/arcnet
91 - Massively improved autoprobe routines; they now work even as a
92 module. Thanks to Vojtech Pavlik <Vojtech.Pavlik@st.mff.cuni.cz>
93 for his ideas and help in this area.
94 - Changed printk's around quite a lot.
97 - Major cleanups, speedups, and better code-sharing.
98 - Eliminated/changed many useless/meaningless/scary debug messages
99 (and, in most cases, the bugs that caused them).
100 - Better IPX support.
101 - lp->stats updated properly.
102 - RECON checking now by default only prints a message if there are
103 excessive errors (ie. your cable is probably broken).
104 - New RFC1051-compliant "arc0s" virtual device by Tomasz
106 - Excess debug messages can be compiled out to reduce code size.
109 - ARCnet RECON messages are now detected and logged as "carrier"
111 - The TXACK flag is now checked, and errors are logged.
112 - Debug levels are now completely different. See the README.
113 - Massive code cleanups, with several no-longer-necessary and some
114 completely useless options removed.
115 - Multiprotocol support. You can now use the "arc0e" device to
116 send "Ethernet-Encapsulation" packets, which are compatible with
117 Windows for Workgroups and LAN Manager, and possibly other
118 software. See the README for more information.
121 - A fix to make "exception" packets sent from Linux receivable
122 on other systems. (The protocol_id byte was sometimes being set
123 incorrectly, and Linux wasn't checking it on receive so it
127 - Fixed some IPX-related bugs. (Thanks to Tomasz Motylewski
128 <motyl@tichy.ch.uj.edu.pl> for the patches to make arcnet work
132 - Initial non-alpha release.
135 TO DO: (semi-prioritized)
137 - Use cleaner "architecture-independent" shared memory access.
138 This is half-done in ARCnet 2.60, but still uses some
139 undocumented i386 stuff. (We shouldn't call phys_to_virt,
141 - Allow use of RFC1051 or Ether devices without RFC1201.
142 - Keep separate stats for each device.
143 - Support "arpless" mode like NetBSD does, and as recommended
144 by the (obsoleted) RFC1051.
145 - Smarter recovery from RECON-during-transmit conditions. (ie.
146 retransmit immediately)
147 - Add support for the new 1.3.x IP header cache, and other features.
148 - Replace setting of debug level with the "metric" flag hack by
149 something that still exists. SIOCDEVPRIVATE is a good candidate,
150 but it would require an extra user-level utility.
152 - What about cards with shared memory that can be "turned off?"
153 (or that have none at all, like the SMC PC500longboard)
154 Does this work now, with IO_MAPPED_BUFFERS?
156 - Autoconfigure PDI5xxPlus cards. (I now have a PDI508Plus to play
157 with temporarily.) Update: yes, the Pure Data config program
158 for DOS works fine, but the PDI508Plus I have doesn't! :)
159 - ATA protocol support??
160 - VINES TCP/IP encapsulation?? (info needed)
163 - Crynwr arcnet.com/arcether.com packet drivers.
164 - arcnet.c v0.00 dated 1/1/94 and apparently by
165 Donald Becker - it didn't work :)
166 - skeleton.c v0.05 dated 11/16/93 by Donald Becker
167 (from Linux Kernel 1.1.45)
168 - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
169 - The official ARCnet COM9026 data sheets (!) thanks to Ken
170 Cornetet <kcornete@nyx10.cs.du.edu>
171 - The official ARCnet COM20020 data sheets.
172 - Information on some more obscure ARCnet controller chips, thanks
173 to the nice people at SMC.
174 - net/inet/eth.c (from kernel 1.1.50) for header-building info.
175 - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
176 - Textual information and more alternate source from Joachim Koenig
180 static const char *version
=
181 "arcnet.c: v3.02 98/06/07 Avery Pennarun <apenwarr@worldvisions.ca> et al.\n";
183 #include <linux/module.h>
184 #include <linux/config.h>
185 #include <linux/version.h>
187 #include <linux/kernel.h>
188 #include <linux/sched.h>
189 #include <linux/types.h>
190 #include <linux/fcntl.h>
191 #include <linux/interrupt.h>
192 #include <linux/ptrace.h>
193 #include <linux/ioport.h>
194 #include <linux/in.h>
195 #include <linux/malloc.h>
196 #include <linux/string.h>
197 #include <linux/timer.h>
198 #include <linux/errno.h>
199 #include <linux/delay.h>
200 #include <linux/netdevice.h>
201 #include <linux/if_arp.h>
202 #include <linux/etherdevice.h>
203 #include <linux/skbuff.h>
204 #include <linux/init.h>
206 #include <linux/if_arcnet.h>
207 #include <linux/arcdevice.h>
209 #include <asm/system.h>
210 #include <asm/bitops.h>
216 /* Define this if you want to make it easier to use the "call trace" when
217 * a kernel NULL pointer assignment occurs. Hopefully unnecessary, most of
218 * the time. It will make all the function names (and other things) show
219 * up as kernel symbols. (especially handy when using arcnet as a module)
223 /**************************************************************************/
225 /* These are now provided by the chipset driver. There's a performance
226 * overhead in using them.
229 #define AINTMASK(x) ((*lp->asetmask)(dev, x))
230 #define ARCSTATUS ((*lp->astatus)(dev))
231 #define ACOMMAND(x) ((*lp->acommand)(dev, x))
233 int arcnet_debug
=ARCNET_DEBUG
;
235 /* Exported function prototypes */
238 int init_module(void);
239 void cleanup_module(void);
241 void arcnet_init(void);
242 static int init_module(void);
243 #ifdef CONFIG_ARCNET_COM90xx
244 extern char com90xx_explicit
;
245 extern int arc90xx_probe(struct net_device
*dev
);
249 void arcnet_tx_done(struct net_device
*dev
, struct arcnet_local
*lp
);
250 void arcnet_use_count (int open
);
251 void arcnet_setup(struct net_device
*dev
);
252 void arcnet_makename(char *device
);
253 void arcnetA_continue_tx(struct net_device
*dev
);
254 int arcnet_go_tx(struct net_device
*dev
,int enable_irq
);
255 void arcnet_interrupt(int irq
,void *dev_id
,struct pt_regs
*regs
);
256 void arcnet_rx(struct arcnet_local
*lp
, u_char
*arcsoft
, short length
, int saddr
, int daddr
);
258 EXPORT_SYMBOL(arcnet_debug
);
259 EXPORT_SYMBOL(arcnet_tx_done
);
260 EXPORT_SYMBOL(arcnet_use_count
);
261 EXPORT_SYMBOL(arcnet_setup
);
262 EXPORT_SYMBOL(arcnet_makename
);
263 EXPORT_SYMBOL(arcnetA_continue_tx
);
264 EXPORT_SYMBOL(arcnet_go_tx
);
265 EXPORT_SYMBOL(arcnet_interrupt
);
266 EXPORT_SYMBOL(arcnet_rx
);
268 #if ARCNET_DEBUG_MAX & D_SKB
269 void arcnet_dump_skb(struct net_device
*dev
,struct sk_buff
*skb
,
271 EXPORT_SYMBOL(arcnet_dump_skb
);
273 # define arcnet_dump_skb(dev,skb,desc) ;
276 #if (ARCNET_DEBUG_MAX & D_RX) || (ARCNET_DEBUG_MAX & D_TX)
277 void arcnet_dump_packet(struct net_device
*dev
,u_char
*buffer
,int ext
,
279 EXPORT_SYMBOL(arcnet_dump_packet
);
281 # define arcnet_dump_packet(dev,buffer,ext,desc) ;
284 /* Internal function prototypes */
286 static int arcnet_open(struct net_device
*dev
);
287 static int arcnet_close(struct net_device
*dev
);
288 static int arcnetA_header(struct sk_buff
*skb
,struct net_device
*dev
,
289 unsigned short type
,void *daddr
,void *saddr
,unsigned len
);
290 static int arcnetA_rebuild_header(struct sk_buff
*skb
);
291 static int arcnet_send_packet_bad(struct sk_buff
*skb
,struct net_device
*dev
);
292 static int arcnetA_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
293 static void arcnetA_rx(struct net_device
*dev
,u_char
*buf
,
294 int length
,u_char saddr
, u_char daddr
);
295 static struct net_device_stats
*arcnet_get_stats(struct net_device
*dev
);
296 static unsigned short arcnetA_type_trans(struct sk_buff
*skb
,
297 struct net_device
*dev
);
300 #ifdef CONFIG_ARCNET_ETH
301 /* functions specific to Ethernet-Encap */
302 static int arcnetE_init(struct net_device
*dev
);
303 static int arcnetE_open_close(struct net_device
*dev
);
304 static int arcnetE_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
305 static void arcnetE_rx(struct net_device
*dev
,u_char
*arcsoft
,
306 int length
,u_char saddr
, u_char daddr
);
310 #ifdef CONFIG_ARCNET_1051
311 /* functions specific to RFC1051 */
312 static int arcnetS_init(struct net_device
*dev
);
313 static int arcnetS_open_close(struct net_device
*dev
);
314 static int arcnetS_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
315 static void arcnetS_rx(struct net_device
*dev
,u_char
*buf
,
316 int length
,u_char saddr
, u_char daddr
);
317 static int arcnetS_header(struct sk_buff
*skb
,struct net_device
*dev
,
318 unsigned short type
,void *daddr
,void *saddr
,unsigned len
);
319 static int arcnetS_rebuild_header(struct sk_buff
*skb
);
320 static unsigned short arcnetS_type_trans(struct sk_buff
*skb
,struct net_device
*dev
);
324 /****************************************************************************
326 * Packet dumps for debugging *
328 ****************************************************************************/
330 /* Dump the contents of an sk_buff
332 #if ARCNET_DEBUG_MAX & D_SKB
333 void arcnet_dump_skb(struct net_device
*dev
,struct sk_buff
*skb
,char *desc
)
340 printk(KERN_DEBUG
"%6s: skb dump (%s) follows:",dev
->name
,desc
);
341 for(i
=0; i
<skb
->len
; i
++)
344 printk("\n" KERN_DEBUG
"[%04X] ",i
);
345 printk("%02X ",((u_char
*)skb
->data
)[i
]);
348 restore_flags(flags
);
353 /* Dump the contents of an ARCnet buffer
355 #if (ARCNET_DEBUG_MAX & D_RX) || (ARCNET_DEBUG_MAX & D_TX)
356 void arcnet_dump_packet(struct net_device
*dev
,u_char
*buffer
,int ext
,char *desc
)
363 printk(KERN_DEBUG
"%6s: packet dump (%s) follows:",dev
->name
,desc
);
364 for (i
=0; i
<256+(ext
!=0)*256; i
++)
367 printk("\n" KERN_DEBUG
"[%04X] ",i
);
368 printk("%02X ",buffer
[i
]);
371 restore_flags(flags
);
376 /* Setup a struct net_device for ARCnet. This should really be in net_init.c
377 * but since there are three different ARCnet devices ANYWAY... <gargle>
379 * Actually, the whole idea of having all this kernel-dependent stuff (ie.
380 * "new-style flags") setup per-net-device is kind of weird anyway.
382 * Intelligent defaults?! Nah.
385 void arcnet_setup(struct net_device
*dev
)
387 dev_init_buffers(dev
);
389 dev
->broadcast
[0] = 0x00; /* for us, broadcasts are address 0 */
391 dev
->type
= ARPHRD_ARCNET
;
392 dev
->tx_queue_len
= 30;
394 /* New-style flags. */
395 dev
->flags
= IFF_BROADCAST
;
397 /* Put in this stuff here, so we don't have to export the symbols
398 * to the chipset drivers.
401 dev
->open
=arcnet_open
;
402 dev
->stop
=arcnet_close
;
403 dev
->hard_start_xmit
=arcnetA_send_packet
;
404 dev
->get_stats
=arcnet_get_stats
;
405 dev
->hard_header
=arcnetA_header
;
406 dev
->rebuild_header
=arcnetA_rebuild_header
;
410 /****************************************************************************
412 * Open and close the driver *
414 ****************************************************************************/
416 /* Open/initialize the board. This is called sometime after booting when
417 * the 'ifconfig' program is run.
419 * This routine should set everything up anew at each open, even
420 * registers that "should" only need to be set once at boot, so that
421 * there is non-reboot way to recover if something goes wrong.
424 arcnet_open(struct net_device
*dev
)
426 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
428 /* if (dev->metric>=1000)
430 * arcnet_debug=dev->metric-1000;
431 * printk(KERN_INFO "%6s: debug level set to %d\n",dev->name,arcnet_debug);
435 BUGMSG(D_INIT
,"arcnet_open: resetting card.\n");
437 /* try to put the card in a defined state - if it fails the first
438 * time, actually reset it.
440 if ((*lp
->arcnet_reset
)(dev
,0) && (*lp
->arcnet_reset
)(dev
,1))
448 /* The RFC1201 driver is the default - just store */
454 #ifdef CONFIG_ARCNET_ETH
455 /* Initialize the ethernet-encap protocol driver */
456 lp
->edev
=(struct net_device
*)kmalloc(sizeof(struct net_device
),GFP_KERNEL
);
457 if (lp
->edev
== NULL
)
459 memcpy(lp
->edev
,dev
,sizeof(struct net_device
));
460 lp
->edev
->type
=ARPHRD_ETHER
;
461 lp
->edev
->name
=(char *)kmalloc(10,GFP_KERNEL
);
462 if (lp
->edev
->name
== NULL
) {
467 sprintf(lp
->edev
->name
,"%se",dev
->name
);
468 lp
->edev
->init
=arcnetE_init
;
469 register_netdevice(lp
->edev
);
472 #ifdef CONFIG_ARCNET_1051
473 /* Initialize the RFC1051-encap protocol driver */
474 lp
->sdev
=(struct net_device
*)kmalloc(sizeof(struct net_device
)+10,GFP_KERNEL
);
482 memcpy(lp
->sdev
,dev
,sizeof(struct net_device
));
483 lp
->sdev
->name
=(char *)(lp
+1);
484 sprintf(lp
->sdev
->name
,"%ss",dev
->name
);
485 lp
->sdev
->init
=arcnetS_init
;
486 register_netdevice(lp
->sdev
);
489 /* Enable TX if we need to */
490 if (lp
->en_dis_able_TX
)
491 (*lp
->en_dis_able_TX
)(dev
, 1);
493 /* make sure we're ready to receive IRQ's.
494 * arcnet_reset sets this for us, but if we receive one before
495 * START is set to 1, it could be ignored. So, we turn IRQ's
496 * off, then on again to clean out the IRQ controller.
500 udelay(1); /* give it time to set the mask before
501 * we reset it again. (may not even be
506 /* Let it increase its use count */
507 (*lp
->openclose_device
)(1);
513 /* The inverse routine to arcnet_open - shuts down the card.
516 arcnet_close(struct net_device
*dev
)
518 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
520 if (test_and_set_bit(0, (int *)&dev
->tbusy
))
521 BUGMSG(D_NORMAL
, "arcnet_close: tbusy already set!\n");
524 #ifdef CONFIG_ARCNET_1051
528 #ifdef CONFIG_ARCNET_ETH
533 /* Shut down the card */
535 /* Disable TX if we need to */
536 if (lp
->en_dis_able_TX
)
537 (*lp
->en_dis_able_TX
)(dev
, 0);
539 (*lp
->arcnet_reset
)(dev
, 3); /* reset IRQ won't run if START=0 */
542 SETMASK
; /* no IRQ's (except RESET, of course) */
543 ACOMMAND(NOTXcmd
); /* stop transmit */
544 ACOMMAND(NORXcmd
); /* disable receive */
547 /* reset more flags */
549 #ifdef CONFIG_ARCNET_ETH
550 lp
->edev
->interrupt
=0;
552 #ifdef CONFIG_ARCNET_1051
553 lp
->sdev
->interrupt
=0;
556 /* do NOT free lp->adev!! It's static! */
559 #ifdef CONFIG_ARCNET_ETH
560 /* free the ethernet-encap protocol device */
562 unregister_netdevice(lp
->edev
);
563 kfree(lp
->edev
->name
);
568 #ifdef CONFIG_ARCNET_1051
569 /* free the RFC1051-encap protocol device */
571 unregister_netdevice(lp
->sdev
);
576 /* Update the statistics here. (not necessary in ARCnet) */
578 /* Decrease the use count */
579 (*lp
->openclose_device
)(0);
585 /****************************************************************************
587 * Transmitter routines *
589 ****************************************************************************/
591 /* Generic error checking routine for arcnet??_send_packet
594 arcnet_send_packet_bad(struct sk_buff
*skb
, struct net_device
*dev
)
596 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
598 BUGMSG(D_DURING
,"transmit requested (status=%Xh, inTX=%d)\n",
601 if (lp
->in_txhandler
)
603 BUGMSG(D_NORMAL
,"send_packet called while in txhandler!\n");
604 lp
->stats
.tx_dropped
++;
610 BUGMSG(D_NORMAL
,"send_packet called while intx!\n");
611 lp
->stats
.tx_dropped
++;
615 if (test_bit(0, (int *)&dev
->tbusy
))
617 /* If we get here, some higher level has decided we are broken.
618 There should really be a "kick me" function call instead. */
619 int tickssofar
= jiffies
- dev
->trans_start
;
621 int status
=ARCSTATUS
;
623 if (tickssofar
< TX_TIMEOUT
)
625 BUGMSG(D_DURING
,"premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
626 status
,tickssofar
,lp
->outgoing
.skb
,
627 lp
->outgoing
.numsegs
,
628 lp
->outgoing
.segnum
);
632 lp
->intmask
&= ~TXFREEflag
;
635 if (status
&TXFREEflag
) /* transmit _DID_ finish */
637 BUGMSG(D_NORMAL
,"tx timeout - missed IRQ? (status=%Xh, ticks=%d, mask=%Xh, dest=%02Xh)\n",
638 status
,tickssofar
,lp
->intmask
,lp
->lasttrans_dest
);
639 lp
->stats
.tx_errors
++;
643 BUGMSG(D_EXTRA
,"tx timed out (status=%Xh, tickssofar=%d, intmask=%Xh, dest=%02Xh)\n",
644 status
,tickssofar
,lp
->intmask
,lp
->lasttrans_dest
);
645 lp
->stats
.tx_errors
++;
646 lp
->stats
.tx_aborted_errors
++;
651 if (lp
->outgoing
.skb
)
653 dev_kfree_skb(lp
->outgoing
.skb
);
654 lp
->stats
.tx_dropped
++;
656 lp
->outgoing
.skb
=NULL
;
658 #ifdef CONFIG_ARCNET_ETH
661 #ifdef CONFIG_ARCNET_1051
664 if (!test_and_clear_bit(0,(int *)&dev
->tbusy
))
665 BUGMSG(D_EXTRA
, "after timing out, tbusy was clear!\n");
673 if (lp
->txready
) /* transmit already in progress! */
675 BUGMSG(D_NORMAL
,"trying to start new packet while busy! (status=%Xh)\n",
677 lp
->intmask
&= ~TXFREEflag
;
679 ACOMMAND(NOTXcmd
); /* abort current send */
680 (*lp
->inthandler
)(dev
); /* fake an interrupt */
681 lp
->stats
.tx_errors
++;
682 lp
->stats
.tx_fifo_errors
++;
683 lp
->txready
=0; /* we definitely need this line! */
688 /* Block a timer-based transmit from overlapping. This could better be
689 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
690 if (test_and_set_bit(0, (int *)&lp
->adev
->tbusy
))
692 BUGMSG(D_NORMAL
,"transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
693 ARCSTATUS
,lp
->intx
,jiffies
-dev
->trans_start
);
694 lp
->stats
.tx_errors
++;
695 lp
->stats
.tx_fifo_errors
++;
698 #ifdef CONFIG_ARCNET_1051
701 #ifdef CONFIG_ARCNET_ETH
709 /* Called by the kernel in order to transmit a packet.
712 arcnetA_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
714 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
716 struct Outgoing
*out
=&(lp
->outgoing
);
720 oldmask
|= lp
->intmask
;
724 bad
=arcnet_send_packet_bad(skb
,dev
);
733 /* arcnet_send_packet_pad has already set tbusy - don't bother here. */
735 lp
->intmask
= oldmask
& ~TXFREEflag
;
738 out
->length
= 1 < skb
->len
? skb
->len
: 1;
739 out
->hdr
=(struct ClientData
*)skb
->data
;
742 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"tx");
744 out
->hdr
->sequence
=(lp
->sequence
++);
746 /* fits in one packet? */
747 if (out
->length
-EXTRA_CLIENTDATA
<=XMTU
)
749 BUGMSG(D_DURING
,"not splitting %d-byte packet. (split_flag=%d)\n",
750 out
->length
,out
->hdr
->split_flag
);
751 if (out
->hdr
->split_flag
)
752 BUGMSG(D_NORMAL
,"short packet has split_flag set?! (split_flag=%d)\n",
753 out
->hdr
->split_flag
);
756 (*lp
->prepare_tx
)(dev
,
757 ((char *)out
->hdr
)+EXTRA_CLIENTDATA
,
758 sizeof(struct ClientData
)-EXTRA_CLIENTDATA
,
759 ((char *)skb
->data
)+sizeof(struct ClientData
),
760 out
->length
-sizeof(struct ClientData
),
761 out
->hdr
->daddr
,1,0);
763 /* done right away */
764 lp
->stats
.tx_bytes
+= out
->skb
->len
;
765 dev_kfree_skb(out
->skb
);
768 if (arcnet_go_tx(dev
,1))
770 /* inform upper layers */
771 arcnet_tx_done(dev
, lp
);
774 else /* too big for one - split it */
776 int maxsegsize
=XMTU
-4;
778 out
->data
=(u_char
*)skb
->data
779 + sizeof(struct ClientData
);
780 out
->dataleft
=out
->length
-sizeof(struct ClientData
);
781 out
->numsegs
=(out
->dataleft
+maxsegsize
-1)/maxsegsize
;
784 BUGMSG(D_TX
,"packet (%d bytes) split into %d fragments:\n",
785 out
->length
,out
->numsegs
);
787 /* if a packet waiting, launch it */
792 /* prepare a packet, launch it and prepare
795 arcnetA_continue_tx(dev
);
796 if (arcnet_go_tx(dev
,1))
798 arcnetA_continue_tx(dev
);
803 /* if segnum==numsegs, the transmission is finished;
804 * free the skb right away.
807 if (out
->segnum
==out
->numsegs
)
809 /* transmit completed */
813 lp
->stats
.tx_bytes
+= skb
->len
;
814 dev_kfree_skb(out
->skb
);
820 dev
->trans_start
=jiffies
;
823 /* make sure we didn't ignore a TX IRQ while we were in here */
824 lp
->intmask
|= TXFREEflag
;
831 /* After an RFC1201 split packet has been set up, this function calls
832 * arcnetAS_prepare_tx to load the next segment into the card. This function
833 * does NOT automatically call arcnet_go_tx.
835 void arcnetA_continue_tx(struct net_device
*dev
)
837 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
838 int maxsegsize
=XMTU
-4;
839 struct Outgoing
*out
=&(lp
->outgoing
);
841 BUGMSG(D_DURING
,"continue_tx called (status=%Xh, intx=%d, intxh=%d, intmask=%Xh\n",
842 ARCSTATUS
,lp
->intx
,lp
->in_txhandler
,lp
->intmask
);
846 BUGMSG(D_NORMAL
,"continue_tx: called with packet in buffer!\n");
850 if (out
->segnum
>=out
->numsegs
)
852 BUGMSG(D_NORMAL
,"continue_tx: building segment %d of %d!\n",
853 out
->segnum
+1,out
->numsegs
);
856 if (!out
->segnum
) /* first packet */
857 out
->hdr
->split_flag
=((out
->numsegs
-2)<<1)+1;
859 out
->hdr
->split_flag
=out
->segnum
<<1;
861 out
->seglen
=maxsegsize
;
862 if (out
->seglen
>out
->dataleft
) out
->seglen
=out
->dataleft
;
864 BUGMSG(D_TX
,"building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
865 out
->segnum
+1,out
->seglen
,out
->numsegs
,
866 out
->length
,out
->hdr
->split_flag
);
868 (*lp
->prepare_tx
)(dev
,((char *)out
->hdr
)+EXTRA_CLIENTDATA
,
869 sizeof(struct ClientData
)-EXTRA_CLIENTDATA
,
870 out
->data
,out
->seglen
,out
->hdr
->daddr
,1,0);
872 out
->dataleft
-=out
->seglen
;
873 out
->data
+=out
->seglen
;
878 /* Actually start transmitting a packet that was placed in the card's
879 * buffer by arcnetAS_prepare_tx. Returns 1 if a Tx is really started.
881 * This should probably always be called with the INTMASK register set to 0,
882 * so go_tx is not called recursively.
884 * The enable_irq flag determines whether to actually write INTMASK value
885 * to the card; TXFREEflag is always OR'ed into the memory variable either
888 int arcnet_go_tx(struct net_device
*dev
,int enable_irq
)
890 struct arcnet_local
*lp
=(struct arcnet_local
*)dev
->priv
;
892 BUGMSG(D_DURING
,"go_tx: status=%Xh, intmask=%Xh, txready=%d, sending=%d\n",
893 ARCSTATUS
,lp
->intmask
,lp
->txready
,lp
->sending
);
895 if (lp
->sending
|| !lp
->txready
)
897 if (enable_irq
&& lp
->sending
)
899 lp
->intmask
|= TXFREEflag
;
906 ACOMMAND(TXcmd
|(lp
->txready
<<3));
908 lp
->stats
.tx_packets
++;
912 lp
->lasttrans_dest
=lp
->lastload_dest
;
915 lp
->intmask
|= TXFREEflag
;
917 if (enable_irq
) SETMASK
;
923 /****************************************************************************
925 * Interrupt handler *
927 ****************************************************************************/
930 /* The typical workload of the driver: Handle the network interface
931 * interrupts. Establish which device needs attention, and call the correct
932 * chipset interrupt handler.
935 arcnet_interrupt(int irq
,void *dev_id
,struct pt_regs
*regs
)
937 struct net_device
*dev
= dev_id
;
938 struct arcnet_local
*lp
;
942 BUGMSG(D_DURING
, "arcnet: irq %d for unknown device.\n", irq
);
946 BUGMSG(D_DURING
,"in arcnet_interrupt\n");
948 lp
=(struct arcnet_local
*)dev
->priv
;
951 BUGMSG(D_DURING
, "arcnet: irq ignored.\n");
955 /* RESET flag was enabled - if !dev->start, we must clear it right
956 * away (but nothing else) since inthandler() is never called.
961 if (ARCSTATUS
& RESETflag
)
962 ACOMMAND(CFLAGScmd
|RESETclear
);
967 if (test_and_set_bit(0, (int *)&dev
->interrupt
))
969 BUGMSG(D_NORMAL
,"DRIVER PROBLEM! Nested arcnet interrupts!\n");
970 return; /* don't even try. */
972 #ifdef CONFIG_ARCNET_1051
974 lp
->sdev
->interrupt
=1;
976 #ifdef CONFIG_ARCNET_ETH
978 lp
->edev
->interrupt
=1;
981 /* Call the "real" interrupt handler. */
982 (*lp
->inthandler
)(dev
);
984 #ifdef CONFIG_ARCNET_ETH
986 lp
->edev
->interrupt
=0;
988 #ifdef CONFIG_ARCNET_1051
990 lp
->sdev
->interrupt
=0;
992 if (!test_and_clear_bit(0, (int *)&dev
->interrupt
))
993 BUGMSG(D_NORMAL
, "Someone cleared our dev->interrupt flag!\n");
997 void arcnet_tx_done(struct net_device
*dev
, struct arcnet_local
*lp
)
1001 #ifdef CONFIG_ARCNET_ETH
1004 #ifdef CONFIG_ARCNET_1051
1007 if (!test_and_clear_bit(0, (int *)&dev
->tbusy
))
1008 BUGMSG(D_NORMAL
, "In arcnet_tx_done: Someone cleared our dev->tbusy"
1016 /****************************************************************************
1018 * Receiver routines *
1020 ****************************************************************************/
1023 * This is a generic packet receiver that calls arcnet??_rx depending on the
1024 * protocol ID found.
1027 void arcnet_rx(struct arcnet_local
*lp
, u_char
*arcsoft
, short length
, int saddr
, int daddr
)
1029 struct net_device
*dev
=lp
->adev
;
1031 BUGMSG(D_DURING
,"received packet from %02Xh to %02Xh (%d bytes)\n",
1032 saddr
,daddr
,length
);
1034 /* call the right receiver for the protocol */
1041 case ARC_P_NOVELL_EC
:
1042 arcnetA_rx(lp
->adev
,arcsoft
,length
,saddr
,daddr
);
1044 #ifdef CONFIG_ARCNET_ETH
1046 arcnetE_rx(lp
->edev
,arcsoft
,length
,saddr
,daddr
);
1049 #ifdef CONFIG_ARCNET_1051
1050 case ARC_P_IP_RFC1051
:
1051 case ARC_P_ARP_RFC1051
:
1052 arcnetS_rx(lp
->sdev
,arcsoft
,length
,saddr
,daddr
);
1055 case ARC_P_DATAPOINT_BOOT
:
1056 case ARC_P_DATAPOINT_MOUNT
:
1058 case ARC_P_POWERLAN_BEACON
:
1059 case ARC_P_POWERLAN_BEACON2
:
1061 case ARC_P_LANSOFT
: /* don't understand. fall through. */
1063 BUGMSG(D_EXTRA
,"received unknown protocol %d (%Xh) from station %d.\n",
1064 arcsoft
[0],arcsoft
[0],saddr
);
1065 lp
->stats
.rx_errors
++;
1066 lp
->stats
.rx_crc_errors
++;
1070 /* If any worth-while packets have been received, a mark_bh(NET_BH)
1071 * has been done by netif_rx and Linux will handle them after we
1080 /* Packet receiver for "standard" RFC1201-style packets
1083 arcnetA_rx(struct net_device
*dev
,u_char
*buf
,
1084 int length
, u_char saddr
, u_char daddr
)
1086 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1087 struct sk_buff
*skb
;
1088 struct ClientData
*arcsoft
,*soft
;
1090 BUGMSG(D_DURING
,"it's an RFC1201 packet (length=%d)\n",
1093 /* compensate for EXTRA_CLIENTDATA (which isn't actually in the
1096 arcsoft
=(struct ClientData
*)(buf
-EXTRA_CLIENTDATA
);
1097 length
+=EXTRA_CLIENTDATA
;
1099 if (arcsoft
->split_flag
==0xFF) /* Exception Packet */
1101 BUGMSG(D_DURING
,"compensating for exception packet\n");
1103 /* skip over 4-byte junkola */
1104 arcsoft
=(struct ClientData
*)
1105 ((u_char
*)arcsoft
+ 4);
1109 if (!arcsoft
->split_flag
) /* not split */
1111 struct Incoming
*in
=&lp
->incoming
[saddr
];
1113 BUGMSG(D_RX
,"incoming is not split (splitflag=%d)\n",
1114 arcsoft
->split_flag
);
1116 if (in
->skb
) /* already assembling one! */
1118 BUGMSG(D_EXTRA
,"aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
1119 in
->sequence
,arcsoft
->split_flag
,
1121 lp
->aborted_seq
=arcsoft
->sequence
;
1123 lp
->stats
.rx_errors
++;
1124 lp
->stats
.rx_missed_errors
++;
1128 in
->sequence
=arcsoft
->sequence
;
1130 skb
= alloc_skb(length
, GFP_ATOMIC
);
1132 BUGMSG(D_NORMAL
,"Memory squeeze, dropping packet.\n");
1133 lp
->stats
.rx_dropped
++;
1136 soft
=(struct ClientData
*)skb
->data
;
1138 skb_put(skb
,length
);
1141 memcpy((u_char
*)soft
+EXTRA_CLIENTDATA
,
1142 (u_char
*)arcsoft
+EXTRA_CLIENTDATA
,
1143 length
-EXTRA_CLIENTDATA
);
1147 /* ARP packets have problems when sent from DOS.
1148 * source address is always 0 on some systems! So we take
1149 * the hardware source addr (which is impossible to fumble)
1150 * and insert it ourselves.
1152 if (soft
->protocol_id
== ARC_P_ARP
)
1154 struct arphdr
*arp
=(struct arphdr
*)
1155 ((char *)soft
+sizeof(struct ClientData
));
1157 /* make sure addresses are the right length */
1158 if (arp
->ar_hln
==1 && arp
->ar_pln
==4)
1160 char *cptr
=(char *)(arp
)+sizeof(struct arphdr
);
1162 if (!*cptr
) /* is saddr = 00? */
1164 BUGMSG(D_EXTRA
,"ARP source address was 00h, set to %02Xh.\n",
1166 lp
->stats
.rx_crc_errors
++;
1171 BUGMSG(D_DURING
,"ARP source address (%Xh) is fine.\n",
1177 BUGMSG(D_NORMAL
,"funny-shaped ARP packet. (%Xh, %Xh)\n",
1178 arp
->ar_hln
,arp
->ar_pln
);
1179 lp
->stats
.rx_errors
++;
1180 lp
->stats
.rx_crc_errors
++;
1184 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"rx");
1186 lp
->stats
.rx_bytes
+= skb
->len
;
1187 skb
->protocol
=arcnetA_type_trans(skb
,dev
);
1190 else /* split packet */
1192 /* NOTE: MSDOS ARP packet correction should only need to
1193 * apply to unsplit packets, since ARP packets are so short.
1195 * My interpretation of the RFC1201 (ARCnet) document is that
1196 * if a packet is received out of order, the entire assembly
1197 * process should be aborted.
1199 * The RFC also mentions "it is possible for successfully
1200 * received packets to be retransmitted." As of 0.40 all
1201 * previously received packets are allowed, not just the
1204 * We allow multiple assembly processes, one for each
1205 * ARCnet card possible on the network. Seems rather like
1206 * a waste of memory. Necessary?
1209 struct Incoming
*in
=&lp
->incoming
[saddr
];
1211 BUGMSG(D_RX
,"packet is split (splitflag=%d, seq=%d)\n",
1212 arcsoft
->split_flag
,in
->sequence
);
1214 if (in
->skb
&& in
->sequence
!=arcsoft
->sequence
)
1216 BUGMSG(D_EXTRA
,"wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n",
1217 saddr
,in
->sequence
,arcsoft
->sequence
,
1218 arcsoft
->split_flag
);
1221 lp
->stats
.rx_errors
++;
1222 lp
->stats
.rx_missed_errors
++;
1223 in
->lastpacket
=in
->numpackets
=0;
1226 if (arcsoft
->split_flag
& 1) /* first packet in split */
1228 BUGMSG(D_RX
,"brand new splitpacket (splitflag=%d)\n",
1229 arcsoft
->split_flag
);
1230 if (in
->skb
) /* already assembling one! */
1232 BUGMSG(D_EXTRA
,"aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
1233 in
->sequence
,arcsoft
->split_flag
,
1235 lp
->stats
.rx_errors
++;
1236 lp
->stats
.rx_missed_errors
++;
1240 in
->sequence
=arcsoft
->sequence
;
1241 in
->numpackets
=((unsigned)arcsoft
->split_flag
>>1)+2;
1244 if (in
->numpackets
>16)
1246 BUGMSG(D_EXTRA
,"incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
1247 arcsoft
->split_flag
);
1248 lp
->stats
.rx_errors
++;
1249 lp
->stats
.rx_length_errors
++;
1253 in
->skb
=skb
=alloc_skb(508*in
->numpackets
1254 + sizeof(struct ClientData
),
1257 BUGMSG(D_NORMAL
,"(split) memory squeeze, dropping packet.\n");
1258 lp
->stats
.rx_dropped
++;
1262 soft
=(struct ClientData
*)skb
->data
;
1264 skb_put(skb
,sizeof(struct ClientData
));
1267 memcpy((u_char
*)soft
+EXTRA_CLIENTDATA
,
1268 (u_char
*)arcsoft
+EXTRA_CLIENTDATA
,
1269 sizeof(struct ClientData
)-EXTRA_CLIENTDATA
);
1270 soft
->split_flag
=0; /* final packet won't be split */
1272 else /* not first packet */
1274 int packetnum
=((unsigned)arcsoft
->split_flag
>>1) + 1;
1276 /* if we're not assembling, there's no point
1277 * trying to continue.
1281 if (lp
->aborted_seq
!= arcsoft
->sequence
)
1283 BUGMSG(D_EXTRA
,"can't continue split without starting first! (splitflag=%d, seq=%d, aborted=%d)\n",
1284 arcsoft
->split_flag
,arcsoft
->sequence
, lp
->aborted_seq
);
1285 lp
->stats
.rx_errors
++;
1286 lp
->stats
.rx_missed_errors
++;
1292 if (packetnum
!=in
->lastpacket
) /* not the right flag! */
1294 /* harmless duplicate? ignore. */
1295 if (packetnum
<=in
->lastpacket
-1)
1297 BUGMSG(D_EXTRA
,"duplicate splitpacket ignored! (splitflag=%d)\n",
1298 arcsoft
->split_flag
);
1299 lp
->stats
.rx_errors
++;
1300 lp
->stats
.rx_frame_errors
++;
1304 /* "bad" duplicate, kill reassembly */
1305 BUGMSG(D_EXTRA
,"out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
1306 in
->sequence
,arcsoft
->split_flag
,
1308 lp
->aborted_seq
=arcsoft
->sequence
;
1311 lp
->stats
.rx_errors
++;
1312 lp
->stats
.rx_missed_errors
++;
1313 in
->lastpacket
=in
->numpackets
=0;
1317 soft
=(struct ClientData
*)in
->skb
->data
;
1322 memcpy(skb
->data
+skb
->len
,
1323 (u_char
*)arcsoft
+sizeof(struct ClientData
),
1324 length
-sizeof(struct ClientData
));
1325 skb_put(skb
,length
-sizeof(struct ClientData
));
1331 if (in
->lastpacket
== in
->numpackets
)
1333 if (!skb
|| !in
->skb
)
1335 BUGMSG(D_NORMAL
,"?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
1341 in
->lastpacket
=in
->numpackets
=0;
1343 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"rx");
1345 lp
->stats
.rx_bytes
+= skb
->len
;
1346 skb
->protocol
=arcnetA_type_trans(skb
,dev
);
1354 /****************************************************************************
1356 * Miscellaneous routines *
1358 ****************************************************************************/
1360 /* Get the current statistics. This may be called with the card open or
1364 static struct net_device_stats
*arcnet_get_stats(struct net_device
*dev
)
1366 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1372 /* Create the ARCnet ClientData header for an arbitrary protocol layer
1374 * saddr=NULL means use device source address (always will anyway)
1375 * daddr=NULL means leave destination address (eg unresolved arp)
1377 static int arcnetA_header(struct sk_buff
*skb
,struct net_device
*dev
,
1378 unsigned short type
,void *daddr
,void *saddr
,unsigned len
)
1380 struct ClientData
*head
= (struct ClientData
*)
1381 skb_push(skb
,dev
->hard_header_len
);
1382 struct arcnet_local
*lp
=(struct arcnet_local
*)(dev
->priv
);
1384 BUGMSG(D_DURING
,"create header from %d to %d; protocol %d (%Xh); size %u.\n",
1385 saddr
? *(u_char
*)saddr
: -1,
1386 daddr
? *(u_char
*)daddr
: -1,
1389 /* set the protocol ID according to RFC1201 */
1393 head
->protocol_id
=ARC_P_IP
;
1396 head
->protocol_id
=ARC_P_ARP
;
1399 head
->protocol_id
=ARC_P_RARP
;
1404 head
->protocol_id
=ARC_P_IPX
;
1407 head
->protocol_id
=ARC_P_ATALK
;
1410 BUGMSG(D_NORMAL
,"I don't understand protocol %d (%Xh)\n",
1412 lp
->stats
.tx_errors
++;
1413 lp
->stats
.tx_aborted_errors
++;
1418 * Set the source hardware address.
1420 * This is pretty pointless for most purposes, but it can help
1421 * in debugging. saddr is stored in the ClientData header and
1422 * removed before sending the packet (since ARCnet does not allow
1423 * us to change the source address in the actual packet sent)
1426 head
->saddr
=((u_char
*)saddr
)[0];
1428 head
->saddr
=((u_char
*)(dev
->dev_addr
))[0];
1430 head
->split_flag
=0; /* split packets are done elsewhere */
1431 head
->sequence
=0; /* so are sequence numbers */
1433 /* supposedly if daddr is NULL, we should ignore it... */
1436 head
->daddr
=((u_char
*)daddr
)[0];
1437 return dev
->hard_header_len
;
1440 head
->daddr
=0; /* better fill one in anyway */
1442 return -dev
->hard_header_len
;
1446 /* Rebuild the ARCnet ClientData header. This is called after an ARP
1447 * (or in future other address resolution) has completed on this
1448 * sk_buff. We now let ARP fill in the other fields.
1450 static int arcnetA_rebuild_header(struct sk_buff
*skb
)
1452 struct ClientData
*head
= (struct ClientData
*)skb
->data
;
1453 struct net_device
*dev
=skb
->dev
;
1454 struct arcnet_local
*lp
=(struct arcnet_local
*)(dev
->priv
);
1460 * Only ARP and IP are currently supported
1462 * FIXME: Anyone want to spec IPv6 over ARCnet ?
1465 if(head
->protocol_id
!= ARC_P_IP
)
1467 BUGMSG(D_NORMAL
,"I don't understand protocol type %d (%Xh) addresses!\n",
1468 head
->protocol_id
,head
->protocol_id
);
1469 lp
->stats
.tx_errors
++;
1470 lp
->stats
.tx_aborted_errors
++;
1472 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
1477 * Try to get ARP to resolve the header.
1480 BUGMSG(D_DURING
,"rebuild header from %d to %d; protocol %Xh\n",
1481 head
->saddr
,head
->daddr
,head
->protocol_id
);
1482 status
=arp_find(&(head
->daddr
),skb
)? 1 : 0;
1483 BUGMSG(D_DURING
," rebuilt: from %d to %d; protocol %Xh\n",
1484 head
->saddr
,head
->daddr
,head
->protocol_id
);
1492 /* Determine a packet's protocol ID.
1494 * With ARCnet we have to convert everything to Ethernet-style stuff.
1496 static unsigned short arcnetA_type_trans(struct sk_buff
*skb
,struct net_device
*dev
)
1498 struct ClientData
*head
;
1499 struct arcnet_local
*lp
=(struct arcnet_local
*) (dev
->priv
);
1501 /* Pull off the arcnet header. */
1502 skb
->mac
.raw
=skb
->data
;
1503 skb_pull(skb
,dev
->hard_header_len
);
1504 head
=(struct ClientData
*)skb
->mac
.raw
;
1507 skb
->pkt_type
=PACKET_BROADCAST
;
1508 else if (dev
->flags
&IFF_PROMISC
)
1510 /* if we're not sending to ourselves :) */
1511 if (head
->daddr
!= dev
->dev_addr
[0])
1512 skb
->pkt_type
=PACKET_OTHERHOST
;
1515 /* now return the protocol number */
1516 switch (head
->protocol_id
)
1518 case ARC_P_IP
: return htons(ETH_P_IP
);
1519 case ARC_P_ARP
: return htons(ETH_P_ARP
);
1520 case ARC_P_RARP
: return htons(ETH_P_RARP
);
1523 case ARC_P_NOVELL_EC
:
1524 return htons(ETH_P_802_3
);
1526 lp
->stats
.rx_errors
++;
1527 lp
->stats
.rx_crc_errors
++;
1531 return htons(ETH_P_IP
);
1535 #ifdef CONFIG_ARCNET_ETH
1536 /****************************************************************************
1538 * Ethernet-Encap Support *
1540 ****************************************************************************/
1542 /* Initialize the arc0e device.
1544 static int arcnetE_init(struct net_device
*dev
)
1546 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1548 ether_setup(dev
); /* we're emulating ether here, not ARCnet */
1550 dev
->dev_addr
[5]=lp
->stationid
;
1551 dev
->mtu
=512-sizeof(struct archdr
)-dev
->hard_header_len
-1;
1552 dev
->open
=arcnetE_open_close
;
1553 dev
->stop
=arcnetE_open_close
;
1554 dev
->hard_start_xmit
=arcnetE_send_packet
;
1560 /* Bring up/down the arc0e device - we don't actually have to do anything,
1561 * since our parent arc0 handles the card I/O itself.
1563 static int arcnetE_open_close(struct net_device
*dev
)
1569 /* Called by the kernel in order to transmit an ethernet-type packet.
1572 arcnetE_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1574 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1577 short offset
,length
=skb
->len
+1;
1578 u_char proto
=ARC_P_ETHER
;
1582 oldmask
|= lp
->intmask
;
1586 bad
=arcnet_send_packet_bad(skb
,dev
);
1590 lp
->intmask
=oldmask
;
1595 /* arcnet_send_packet_pad has already set tbusy - don't bother here. */
1597 lp
->intmask
=oldmask
;
1602 BUGMSG(D_NORMAL
,"MTU must be <= 493 for ethernet encap (length=%d).\n",
1604 BUGMSG(D_NORMAL
,"transmit aborted.\n");
1611 BUGMSG(D_DURING
,"starting tx sequence...\n");
1613 /* broadcasts have address FF:FF:FF:FF:FF:FF in etherspeak */
1614 if (((struct ethhdr
*)(skb
->data
))->h_dest
[0] == 0xFF)
1617 daddr
=((struct ethhdr
*)(skb
->data
))->h_dest
[5];
1619 /* load packet into shared memory */
1621 if (length
>MTU
) /* long/exception packet */
1623 if (length
<MinTU
) offset
-=3;
1625 else /* short packet */
1630 BUGMSG(D_DURING
," length=%Xh, offset=%Xh\n",
1633 (*lp
->prepare_tx
)(dev
, &proto
, 1, skb
->data
, length
-1, daddr
, 0,
1638 if (arcnet_go_tx(dev
,1))
1640 /* inform upper layers */
1641 arcnet_tx_done(lp
->adev
, lp
);
1644 dev
->trans_start
=jiffies
;
1647 /* make sure we didn't ignore a TX IRQ while we were in here */
1648 lp
->intmask
|= TXFREEflag
;
1655 /* Packet receiver for ethernet-encap packets.
1658 arcnetE_rx(struct net_device
*dev
,u_char
*arcsoft
,
1659 int length
,u_char saddr
, u_char daddr
)
1661 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1662 struct sk_buff
*skb
;
1664 BUGMSG(D_DURING
,"it's an ethernet-encap packet (length=%d)\n",
1667 skb
= alloc_skb(length
, GFP_ATOMIC
);
1669 BUGMSG(D_NORMAL
,"Memory squeeze, dropping packet.\n");
1670 lp
->stats
.rx_dropped
++;
1674 skb_put(skb
,length
);
1678 memcpy(skb
->data
,(u_char
*)arcsoft
+1,length
-1);
1680 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"rx");
1682 lp
->stats
.rx_bytes
+= skb
->len
;
1683 skb
->protocol
=eth_type_trans(skb
,dev
);
1687 #endif /* CONFIG_ARCNET_ETH */
1689 #ifdef CONFIG_ARCNET_1051
1690 /****************************************************************************
1694 ****************************************************************************/
1696 /* Initialize the arc0s device.
1698 static int arcnetS_init(struct net_device
*dev
)
1700 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1704 /* And now fill particular fields with arcnet values */
1705 dev
->dev_addr
[0]=lp
->stationid
;
1706 dev
->hard_header_len
=sizeof(struct S_ClientData
);
1707 dev
->mtu
=512-sizeof(struct archdr
)-dev
->hard_header_len
1708 + S_EXTRA_CLIENTDATA
;
1709 dev
->open
=arcnetS_open_close
;
1710 dev
->stop
=arcnetS_open_close
;
1711 dev
->hard_start_xmit
=arcnetS_send_packet
;
1712 dev
->hard_header
=arcnetS_header
;
1713 dev
->rebuild_header
=arcnetS_rebuild_header
;
1719 /* Bring up/down the arc0s device - we don't actually have to do anything,
1720 * since our parent arc0 handles the card I/O itself.
1722 static int arcnetS_open_close(struct net_device
*dev
)
1728 /* Called by the kernel in order to transmit an RFC1051-type packet.
1731 arcnetS_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1733 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1735 struct S_ClientData
*hdr
=(struct S_ClientData
*)skb
->data
;
1739 bad
=arcnet_send_packet_bad(skb
,dev
);
1746 /* arcnet_send_packet_pad has already set tbusy - don't bother here. */
1748 length
= 1 < skb
->len
? skb
->len
: 1;
1750 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"tx");
1752 /* fits in one packet? */
1753 if (length
-S_EXTRA_CLIENTDATA
<=XMTU
)
1755 (*lp
->prepare_tx
)(dev
,
1756 skb
->data
+S_EXTRA_CLIENTDATA
,
1757 sizeof(struct S_ClientData
)-S_EXTRA_CLIENTDATA
,
1758 skb
->data
+sizeof(struct S_ClientData
),
1759 length
-sizeof(struct S_ClientData
),
1762 /* done right away */
1765 if (arcnet_go_tx(dev
,1))
1767 /* inform upper layers */
1768 arcnet_tx_done(lp
->adev
, lp
);
1771 else /* too big for one - not accepted */
1773 BUGMSG(D_NORMAL
,"packet too long (length=%d)\n",
1776 lp
->stats
.tx_dropped
++;
1777 arcnet_tx_done(lp
->adev
, lp
);
1780 dev
->trans_start
=jiffies
;
1783 /* make sure we didn't ignore a TX IRQ while we were in here */
1784 lp
->intmask
|= TXFREEflag
;
1791 /* Packet receiver for RFC1051 packets;
1794 arcnetS_rx(struct net_device
*dev
,u_char
*buf
,
1795 int length
,u_char saddr
, u_char daddr
)
1797 struct arcnet_local
*lp
= (struct arcnet_local
*)dev
->priv
;
1798 struct sk_buff
*skb
;
1799 struct S_ClientData
*arcsoft
,*soft
;
1801 arcsoft
=(struct S_ClientData
*)(buf
-S_EXTRA_CLIENTDATA
);
1802 length
+=S_EXTRA_CLIENTDATA
;
1804 BUGMSG(D_DURING
,"it's an RFC1051 packet (length=%d)\n",
1807 { /* was "if not split" in A protocol, S is never split */
1809 skb
= alloc_skb(length
, GFP_ATOMIC
);
1811 BUGMSG(D_NORMAL
,"Memory squeeze, dropping packet.\n");
1812 lp
->stats
.rx_dropped
++;
1815 soft
=(struct S_ClientData
*)skb
->data
;
1816 skb_put(skb
,length
);
1818 memcpy((u_char
*)soft
+ sizeof(struct S_ClientData
) - S_EXTRA_CLIENTDATA
,
1819 (u_char
*)arcsoft
+ sizeof(struct S_ClientData
) -S_EXTRA_CLIENTDATA
,
1820 length
- sizeof(struct S_ClientData
) + S_EXTRA_CLIENTDATA
);
1821 soft
->protocol_id
=arcsoft
->protocol_id
;
1824 skb
->dev
= dev
; /* is already lp->sdev */
1826 BUGLVL(D_SKB
) arcnet_dump_skb(dev
,skb
,"rx");
1828 lp
->stats
.rx_bytes
+= skb
->len
;
1829 skb
->protocol
=arcnetS_type_trans(skb
,dev
);
1835 /* Create the ARCnet ClientData header for an arbitrary protocol layer
1837 * saddr=NULL means use device source address (always will anyway)
1838 * daddr=NULL means leave destination address (eg unresolved arp)
1840 static int arcnetS_header(struct sk_buff
*skb
,struct net_device
*dev
,
1841 unsigned short type
,void *daddr
,void *saddr
,unsigned len
)
1843 struct S_ClientData
*head
= (struct S_ClientData
*)
1844 skb_push(skb
,dev
->hard_header_len
);
1845 struct arcnet_local
*lp
=(struct arcnet_local
*)(dev
->priv
);
1847 /* set the protocol ID according to RFC1051 */
1851 head
->protocol_id
=ARC_P_IP_RFC1051
;
1852 BUGMSG(D_DURING
,"S_header: IP_RFC1051 packet.\n");
1855 head
->protocol_id
=ARC_P_ARP_RFC1051
;
1856 BUGMSG(D_DURING
,"S_header: ARP_RFC1051 packet.\n");
1859 BUGMSG(D_NORMAL
,"I don't understand protocol %d (%Xh)\n",
1861 lp
->stats
.tx_errors
++;
1862 lp
->stats
.tx_aborted_errors
++;
1867 * Set the source hardware address.
1869 * This is pretty pointless for most purposes, but it can help
1870 * in debugging. saddr is stored in the ClientData header and
1871 * removed before sending the packet (since ARCnet does not allow
1872 * us to change the source address in the actual packet sent)
1875 head
->saddr
=((u_char
*)saddr
)[0];
1877 head
->saddr
=((u_char
*)(dev
->dev_addr
))[0];
1879 /* supposedly if daddr is NULL, we should ignore it... */
1882 head
->daddr
=((u_char
*)daddr
)[0];
1883 return dev
->hard_header_len
;
1886 head
->daddr
=0; /* better fill one in anyway */
1888 return -dev
->hard_header_len
;
1892 /* Rebuild the ARCnet ClientData header. This is called after an ARP
1893 * (or in future other address resolution) has completed on this
1894 * sk_buff. We now let ARP fill in the other fields.
1896 static int arcnetS_rebuild_header(struct sk_buff
*skb
)
1898 struct net_device
*dev
=skb
->dev
;
1899 struct S_ClientData
*head
= (struct S_ClientData
*)skb
->data
;
1900 struct arcnet_local
*lp
=(struct arcnet_local
*)(dev
->priv
);
1903 * Only ARP and IP are currently supported
1906 if(head
->protocol_id
!= ARC_P_IP_RFC1051
)
1908 BUGMSG(D_NORMAL
,"I don't understand protocol type %d (%Xh) addresses!\n",
1909 head
->protocol_id
,head
->protocol_id
);
1910 lp
->stats
.tx_errors
++;
1911 lp
->stats
.tx_aborted_errors
++;
1913 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
1918 * Try to get ARP to resolve the header.
1921 return arp_find(&(head
->daddr
),skb
)? 1 : 0;
1928 /* Determine a packet's protocol ID.
1930 * With ARCnet we have to convert everything to Ethernet-style stuff.
1932 unsigned short arcnetS_type_trans(struct sk_buff
*skb
,struct net_device
*dev
)
1934 struct S_ClientData
*head
;
1935 struct arcnet_local
*lp
=(struct arcnet_local
*) (dev
->priv
);
1937 /* Pull off the arcnet header. */
1938 skb
->mac
.raw
=skb
->data
;
1939 skb_pull(skb
,dev
->hard_header_len
);
1940 head
=(struct S_ClientData
*)skb
->mac
.raw
;
1943 skb
->pkt_type
=PACKET_BROADCAST
;
1944 else if (dev
->flags
&IFF_PROMISC
)
1946 /* if we're not sending to ourselves :) */
1947 if (head
->daddr
!= dev
->dev_addr
[0])
1948 skb
->pkt_type
=PACKET_OTHERHOST
;
1951 /* now return the protocol number */
1952 switch (head
->protocol_id
)
1954 case ARC_P_IP_RFC1051
: return htons(ETH_P_IP
);
1955 case ARC_P_ARP_RFC1051
: return htons(ETH_P_ARP
);
1956 case ARC_P_ATALK
: return htons(ETH_P_ATALK
); /* untested appletalk */
1958 lp
->stats
.rx_errors
++;
1959 lp
->stats
.rx_crc_errors
++;
1963 return htons(ETH_P_IP
);
1966 #endif /* CONFIG_ARCNET_1051 */
1969 /****************************************************************************
1971 * Kernel Loadable Module Support *
1973 ****************************************************************************/
1977 void cleanup_module(void)
1979 printk("Generic arcnet support removed.\n");
1982 void arcnet_use_count(int open
)
1992 void arcnet_use_count(int open
)
1996 struct net_device arcnet_devs
[MAX_ARCNET_DEVS
];
1997 int arcnet_num_devs
=0;
1998 char arcnet_dev_names
[MAX_ARCNET_DEVS
][10];
2000 void __init
arcnet_init(void)
2006 /* Don't register_netdev here. The chain hasn't been initialised. */
2008 #ifdef CONFIG_ARCNET_COM90xx
2009 if ((!com90xx_explicit
) && arcnet_num_devs
< MAX_ARCNET_DEVS
)
2011 arcnet_devs
[arcnet_num_devs
].init
=arc90xx_probe
;
2012 arcnet_devs
[arcnet_num_devs
].name
=
2013 (char *)&arcnet_dev_names
[arcnet_num_devs
];
2018 if (!arcnet_num_devs
)
2020 printk("Don't forget to load the chipset driver.\n");
2024 /* Link into the device chain */
2026 /* Q: Should we put ourselves at the beginning or the end of the chain? */
2027 /* Probably the end, because we're not so fast, but... */
2029 for (c
=0; c
< (arcnet_num_devs
-1); c
++)
2030 arcnet_devs
[c
].next
=&arcnet_devs
[c
+1];
2032 write_lock_bh(&dev_base_lock
);
2033 arcnet_devs
[c
].next
=dev_base
;
2034 dev_base
=&arcnet_devs
[0];
2035 write_unlock_bh(&dev_base_lock
);
2037 /* Give names to those without them */
2039 for (c
=0; c
< arcnet_num_devs
; c
++)
2040 if (!arcnet_dev_names
[c
][0])
2041 arcnet_makename((char *)&arcnet_dev_names
[c
]);
2048 int init_module(void)
2050 static int __init
init_module(void)
2053 #ifdef ALPHA_WARNING
2056 printk("arcnet: ***\n");
2057 printk("arcnet: * Read arcnet.txt for important release notes!\n");
2058 printk("arcnet: *\n");
2059 printk("arcnet: * This is an ALPHA version! (Last stable release: v2.56) E-mail me if\n");
2060 printk("arcnet: * you have any questions, comments, or bug reports.\n");
2061 printk("arcnet: ***\n");
2065 printk("%sAvailable protocols: ARCnet RFC1201"
2066 #ifdef CONFIG_ARCNET_ETH
2069 #ifdef CONFIG_ARCNET_1051
2073 ".\nDon't forget to load the chipset driver"
2080 void arcnet_makename(char *device
)
2082 struct net_device
*dev
;
2088 sprintf(device
, "arc%d", arcnum
);
2089 read_lock_bh(&dev_base_lock
);
2090 for (dev
= dev_base
; dev
; dev
=dev
->next
)
2091 if (dev
->name
!= device
&& !strcmp(dev
->name
, device
))
2093 read_unlock_bh(&dev_base_lock
);