2 * Linux ARCnet driver - "cap mode" packet encapsulation.
3 * It adds sequence numbers to packets for communicating between a user space
4 * application and the driver. After a transmit it sends a packet with protocol
5 * byte 0 back up to the userspace containing the sequence number of the packet
6 * plus the transmit-status on the ArcNet.
8 * Written 2002-4 by Esben Nielsen, Vestas Wind Systems A/S
9 * Derived from arc-rawmode.c by Avery Pennarun.
10 * arc-rawmode was in turned based on skeleton.c, see below.
12 * **********************
14 * The original copyright of skeleton.c was as follows:
16 * skeleton.c Written 1993 by Donald Becker.
17 * Copyright 1993 United States Government as represented by the
18 * Director, National Security Agency. This software may only be used
19 * and distributed according to the terms of the GNU General Public License as
20 * modified by SRC, incorporated herein by reference.
22 * **********************
24 * For more details, see drivers/net/arcnet.c
26 * **********************
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/if_arp.h>
33 #include <linux/netdevice.h>
34 #include <linux/skbuff.h>
35 #include <linux/arcdevice.h>
37 #define VERSION "arcnet: cap mode (`c') encapsulation support loaded.\n"
40 static void rx(struct net_device
*dev
, int bufnum
,
41 struct archdr
*pkthdr
, int length
);
42 static int build_header(struct sk_buff
*skb
,
43 struct net_device
*dev
,
46 static int prepare_tx(struct net_device
*dev
, struct archdr
*pkt
, int length
,
48 static int ack_tx(struct net_device
*dev
, int acked
);
51 static struct ArcProto capmode_proto
=
64 void arcnet_cap_init(void)
68 for (count
= 1; count
<= 8; count
++)
69 if (arc_proto_map
[count
] == arc_proto_default
)
70 arc_proto_map
[count
] = &capmode_proto
;
72 /* for cap mode, we only set the bcast proto if there's no better one */
73 if (arc_bcast_proto
== arc_proto_default
)
74 arc_bcast_proto
= &capmode_proto
;
76 arc_proto_default
= &capmode_proto
;
77 arc_raw_proto
= &capmode_proto
;
83 <<<<<<< HEAD
:drivers
/net
/arcnet
/capmode
.c
84 int __init
init_module(void)
86 static int __init
capmode_module_init(void)
87 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/arcnet
/capmode
.c
94 <<<<<<< HEAD
:drivers
/net
/arcnet
/capmode
.c
95 void cleanup_module(void)
97 static void __exit
capmode_module_exit(void)
98 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/arcnet
/capmode
.c
100 arcnet_unregister_proto(&capmode_proto
);
102 <<<<<<< HEAD
:drivers
/net
/arcnet
/capmode
.c
104 module_init(capmode_module_init
);
105 module_exit(capmode_module_exit
);
106 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/arcnet
/capmode
.c
108 MODULE_LICENSE("GPL");
113 /* packet receiver */
114 static void rx(struct net_device
*dev
, int bufnum
,
115 struct archdr
*pkthdr
, int length
)
117 struct arcnet_local
*lp
= (struct arcnet_local
*) dev
->priv
;
119 struct archdr
*pkt
= pkthdr
;
120 char *pktbuf
, *pkthdrbuf
;
123 BUGMSG(D_DURING
, "it's a raw(cap) packet (length=%d)\n", length
);
130 skb
= alloc_skb(length
+ ARC_HDR_SIZE
+ sizeof(int), GFP_ATOMIC
);
132 BUGMSG(D_NORMAL
, "Memory squeeze, dropping packet.\n");
133 lp
->stats
.rx_dropped
++;
136 skb_put(skb
, length
+ ARC_HDR_SIZE
+ sizeof(int));
138 skb_reset_mac_header(skb
);
139 pkt
= (struct archdr
*)skb_mac_header(skb
);
140 skb_pull(skb
, ARC_HDR_SIZE
);
142 /* up to sizeof(pkt->soft) has already been copied from the card */
143 /* squeeze in an int for the cap encapsulation */
145 /* use these variables to be sure we count in bytes, not in
146 sizeof(struct archdr) */
148 pkthdrbuf
=(char*)pkthdr
;
149 memcpy(pktbuf
, pkthdrbuf
, ARC_HDR_SIZE
+sizeof(pkt
->soft
.cap
.proto
));
150 memcpy(pktbuf
+ARC_HDR_SIZE
+sizeof(pkt
->soft
.cap
.proto
)+sizeof(int),
151 pkthdrbuf
+ARC_HDR_SIZE
+sizeof(pkt
->soft
.cap
.proto
),
152 sizeof(struct archdr
)-ARC_HDR_SIZE
-sizeof(pkt
->soft
.cap
.proto
));
154 if (length
> sizeof(pkt
->soft
))
155 lp
->hw
.copy_from_card(dev
, bufnum
, ofs
+ sizeof(pkt
->soft
),
156 pkt
->soft
.raw
+ sizeof(pkt
->soft
)
158 length
- sizeof(pkt
->soft
));
160 BUGLVL(D_SKB
) arcnet_dump_skb(dev
, skb
, "rx");
162 skb
->protocol
= __constant_htons(ETH_P_ARCNET
);
165 dev
->last_rx
= jiffies
;
170 * Create the ARCnet hard/soft headers for cap mode.
171 * There aren't any soft headers in cap mode - not even the protocol id.
173 static int build_header(struct sk_buff
*skb
,
174 struct net_device
*dev
,
178 int hdr_size
= ARC_HDR_SIZE
;
179 struct archdr
*pkt
= (struct archdr
*) skb_push(skb
, hdr_size
);
181 BUGMSG(D_PROTO
, "Preparing header for cap packet %x.\n",
182 *((int*)&pkt
->soft
.cap
.cookie
[0]));
184 * Set the source hardware address.
186 * This is pretty pointless for most purposes, but it can help in
187 * debugging. ARCnet does not allow us to change the source address in
188 * the actual packet sent)
190 pkt
->hard
.source
= *dev
->dev_addr
;
192 /* see linux/net/ethernet/eth.c to see where I got the following */
194 if (dev
->flags
& (IFF_LOOPBACK
| IFF_NOARP
)) {
196 * FIXME: fill in the last byte of the dest ipaddr here to better
197 * comply with RFC1051 in "noarp" mode.
202 /* otherwise, just fill it in and go! */
203 pkt
->hard
.dest
= daddr
;
205 return hdr_size
; /* success */
209 static int prepare_tx(struct net_device
*dev
, struct archdr
*pkt
, int length
,
212 struct arcnet_local
*lp
= (struct arcnet_local
*) dev
->priv
;
213 struct arc_hardware
*hard
= &pkt
->hard
;
217 /* hard header is not included in packet length */
218 length
-= ARC_HDR_SIZE
;
219 /* And neither is the cookie field */
220 length
-= sizeof(int);
222 BUGMSG(D_DURING
, "prepare_tx: txbufs=%d/%d/%d\n",
223 lp
->next_tx
, lp
->cur_tx
, bufnum
);
225 BUGMSG(D_PROTO
, "Sending for cap packet %x.\n",
226 *((int*)&pkt
->soft
.cap
.cookie
[0]));
229 /* should never happen! other people already check for this. */
230 BUGMSG(D_NORMAL
, "Bug! prepare_tx with size %d (> %d)\n",
234 if (length
> MinTU
) {
236 hard
->offset
[1] = ofs
= 512 - length
;
237 } else if (length
> MTU
) {
239 hard
->offset
[1] = ofs
= 512 - length
- 3;
241 hard
->offset
[0] = ofs
= 256 - length
;
243 BUGMSG(D_DURING
, "prepare_tx: length=%d ofs=%d\n",
246 // Copy the arcnet-header + the protocol byte down:
247 lp
->hw
.copy_to_card(dev
, bufnum
, 0, hard
, ARC_HDR_SIZE
);
248 lp
->hw
.copy_to_card(dev
, bufnum
, ofs
, &pkt
->soft
.cap
.proto
,
249 sizeof(pkt
->soft
.cap
.proto
));
251 // Skip the extra integer we have written into it as a cookie
252 // but write the rest of the message:
253 lp
->hw
.copy_to_card(dev
, bufnum
, ofs
+1,
254 ((unsigned char*)&pkt
->soft
.cap
.mes
),length
-1);
256 lp
->lastload_dest
= hard
->dest
;
262 static int ack_tx(struct net_device
*dev
, int acked
)
264 struct arcnet_local
*lp
= (struct arcnet_local
*) dev
->priv
;
265 struct sk_buff
*ackskb
;
266 struct archdr
*ackpkt
;
267 int length
=sizeof(struct arc_cap
);
269 BUGMSG(D_DURING
, "capmode: ack_tx: protocol: %x: result: %d\n",
270 lp
->outgoing
.skb
->protocol
, acked
);
272 BUGLVL(D_SKB
) arcnet_dump_skb(dev
, lp
->outgoing
.skb
, "ack_tx");
274 /* Now alloc a skb to send back up through the layers: */
275 ackskb
= alloc_skb(length
+ ARC_HDR_SIZE
, GFP_ATOMIC
);
276 if (ackskb
== NULL
) {
277 BUGMSG(D_NORMAL
, "Memory squeeze, can't acknowledge.\n");
281 skb_put(ackskb
, length
+ ARC_HDR_SIZE
);
284 skb_reset_mac_header(ackskb
);
285 ackpkt
= (struct archdr
*)skb_mac_header(ackskb
);
286 /* skb_pull(ackskb, ARC_HDR_SIZE); */
289 skb_copy_from_linear_data(lp
->outgoing
.skb
, ackpkt
,
290 ARC_HDR_SIZE
+ sizeof(struct arc_cap
));
291 ackpkt
->soft
.cap
.proto
=0; /* using protocol 0 for acknowledge */
292 ackpkt
->soft
.cap
.mes
.ack
=acked
;
294 BUGMSG(D_PROTO
, "Ackknowledge for cap packet %x.\n",
295 *((int*)&ackpkt
->soft
.cap
.cookie
[0]));
297 ackskb
->protocol
= __constant_htons(ETH_P_ARCNET
);
299 BUGLVL(D_SKB
) arcnet_dump_skb(dev
, ackskb
, "ack_tx_recv");
303 dev_kfree_skb_irq(lp
->outgoing
.skb
);
304 lp
->outgoing
.proto
= NULL
; /* We are always finished when in this protocol */