27 #include <linux/module.h>
29 #include <linux/if_arp.h>
30 #include <linux/netdevice.h>
35 #define VERSION "arcnet: RFC1201 \"standard\" (`a') encapsulation support loaded.\n"
47 static struct ArcProto rfc1201_proto =
53 .build_header = build_header,
54 .prepare_tx = prepare_tx,
55 .continue_tx = continue_tx,
60 static int __init arcnet_rfc1201_init(
void)
79 static void __exit arcnet_rfc1201_exit(
void)
99 skb_reset_mac_header(skb);
102 if (pkt->
hard.dest == 0)
110 switch (
soft->proto) {
124 dev->
stats.rx_errors++;
125 dev->
stats.rx_crc_errors++;
137 struct arcnet_local *
lp = netdev_priv(dev);
139 struct archdr *pkt = pkthdr;
142 struct Incoming *
in = &lp->rfc1201.incoming[
saddr];
144 BUGMSG(D_DURING,
"it's an RFC1201 packet (length=%d)\n", length);
153 BUGMSG(D_DURING,
"compensating for exception packet\n");
155 BUGMSG(D_EXTRA,
"short RFC1201 exception packet from %02Xh",
163 lp->hw.copy_from_card(dev, bufnum, 512 - length,
164 soft,
sizeof(pkt->
soft));
167 BUGMSG(
D_RX,
"incoming is not split (splitflag=%d)\n",
171 BUGMSG(D_EXTRA,
"aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
173 lp->rfc1201.aborted_seq = soft->
sequence;
175 dev->
stats.rx_errors++;
176 dev->
stats.rx_missed_errors++;
183 BUGMSG(D_NORMAL,
"Memory squeeze, dropping packet.\n");
184 dev->
stats.rx_dropped++;
195 if (length >
sizeof(pkt->
soft))
196 lp->hw.copy_from_card(dev, bufnum, ofs +
sizeof(pkt->
soft),
198 length -
sizeof(pkt->
soft));
214 "ARP source address was 00h, set to %02Xh.\n",
216 dev->
stats.rx_crc_errors++;
219 BUGMSG(D_DURING,
"ARP source address (%Xh) is fine.\n",
223 BUGMSG(D_NORMAL,
"funny-shaped ARP packet. (%Xh, %Xh)\n",
225 dev->
stats.rx_errors++;
226 dev->
stats.rx_crc_errors++;
229 BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "
rx");
231 skb->
protocol = type_trans(skb, dev);
251 BUGMSG(
D_RX,
"packet is split (splitflag=%d, seq=%d)\n",
254 if (in->skb && in->sequence != soft->
sequence) {
255 BUGMSG(D_EXTRA,
"wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n",
256 saddr, in->sequence, soft->
sequence,
260 dev->stats.rx_errors++;
261 dev->stats.rx_missed_errors++;
262 in->lastpacket = in->numpackets = 0;
265 BUGMSG(
D_RX,
"brand new splitpacket (splitflag=%d)\n",
268 BUGMSG(D_EXTRA,
"aborting previous (seq=%d) assembly "
269 "(splitflag=%d, seq=%d)\n",
272 dev->stats.rx_errors++;
273 dev->stats.rx_missed_errors++;
277 in->numpackets = ((unsigned) soft->
split_flag >> 1) + 2;
280 if (in->numpackets > 16) {
281 BUGMSG(D_EXTRA,
"incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
283 lp->rfc1201.aborted_seq = soft->
sequence;
284 dev->stats.rx_errors++;
285 dev->stats.rx_length_errors++;
288 in->skb = skb = alloc_skb(508 * in->numpackets +
ARC_HDR_SIZE,
291 BUGMSG(D_NORMAL,
"(split) memory squeeze, dropping packet.\n");
292 lp->rfc1201.aborted_seq = soft->
sequence;
293 dev->stats.rx_dropped++;
297 pkt = (
struct archdr *) skb->data;
305 int packetnum = ((unsigned) soft->
split_flag >> 1) + 1;
312 if (lp->rfc1201.aborted_seq != soft->
sequence) {
313 BUGMSG(D_EXTRA,
"can't continue split without starting "
314 "first! (splitflag=%d, seq=%d, aborted=%d)\n",
316 lp->rfc1201.aborted_seq);
317 dev->stats.rx_errors++;
318 dev->stats.rx_missed_errors++;
323 if (packetnum != in->lastpacket) {
325 if (packetnum <= in->lastpacket - 1) {
326 BUGMSG(D_EXTRA,
"duplicate splitpacket ignored! (splitflag=%d)\n",
328 dev->stats.rx_errors++;
329 dev->stats.rx_frame_errors++;
333 BUGMSG(D_EXTRA,
"out-of-order splitpacket, reassembly "
334 "(seq=%d) aborted (splitflag=%d, seq=%d)\n",
336 lp->rfc1201.aborted_seq = soft->
sequence;
339 dev->stats.rx_errors++;
340 dev->stats.rx_missed_errors++;
341 in->lastpacket = in->numpackets = 0;
344 pkt = (
struct archdr *) in->skb->data;
351 skb->data + skb->len,
356 if (in->lastpacket == in->numpackets) {
358 in->lastpacket = in->numpackets = 0;
360 BUGMSG(D_SKB_SIZE,
"skb: received %d bytes from %02X (unsplit)\n",
361 skb->len, pkt->
hard.source);
362 BUGMSG(D_SKB_SIZE,
"skb: received %d bytes from %02X (split)\n",
363 skb->len, pkt->
hard.source);
364 BUGLVL(D_SKB) arcnet_dump_skb(dev, skb, "rx");
366 skb->
protocol = type_trans(skb, dev);
377 struct arcnet_local *lp = netdev_priv(dev);
405 BUGMSG(D_NORMAL,
"RFC1201: I don't understand protocol %d (%Xh)\n",
407 dev->stats.tx_errors++;
408 dev->stats.tx_aborted_errors++;
419 pkt->
hard.source = *dev->dev_addr;
444 struct arcnet_local *lp = netdev_priv(dev);
449 if (softlen > MinTU) {
451 hard->
offset[1] = ofs = 512 - softlen;
452 }
else if (softlen > MTU) {
456 excsoft.split_flag = 0xff;
457 excsoft.sequence =
htons(0xffff);
462 lp->hw.copy_to_card(dev, bufnum, ofs - RFC1201_HDR_SIZE,
463 &excsoft, RFC1201_HDR_SIZE);
465 hard->
offset[0] = ofs = 256 - softlen;
467 lp->hw.copy_to_card(dev, bufnum, 0, hard,
ARC_HDR_SIZE);
468 lp->hw.copy_to_card(dev, bufnum, ofs, soft, softlen);
470 lp->lastload_dest = hard->
dest;
474 static int prepare_tx(
struct net_device *dev,
struct archdr *pkt,
int length,
477 struct arcnet_local *lp = netdev_priv(dev);
479 struct Outgoing *
out;
482 BUGMSG(D_DURING,
"prepare_tx: txbufs=%d/%d/%d\n",
483 lp->next_tx, lp->cur_tx, bufnum);
493 out->dataleft = lp->outgoing.length;
494 out->numsegs = (out->dataleft + maxsegsize - 1) / maxsegsize;
497 BUGMSG(D_DURING,
"rfc1201 prep_tx: ready for %d-segment split "
498 "(%d bytes, seq=%d)\n", out->numsegs, out->length,
510 static int continue_tx(
struct net_device *dev,
int bufnum)
512 struct arcnet_local *lp = netdev_priv(dev);
513 struct Outgoing *out = &lp->outgoing;
515 struct arc_rfc1201 *soft = &out->pkt->soft.rfc1201, *newsoft;
520 "rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n",
521 out->segnum, out->numsegs, soft->
sequence);
525 (out->pkt->soft.raw + out->length - out->dataleft);
528 newsoft->split_flag = ((out->numsegs - 2) << 1) | 1;
530 newsoft->split_flag = out->segnum << 1;
531 newsoft->proto = soft->
proto;
536 if (seglen > out->dataleft)
537 seglen = out->dataleft;
538 out->dataleft -= seglen;
540 load_pkt(dev, hard, newsoft, seglen + RFC1201_HDR_SIZE, bufnum);
543 if (out->segnum >= out->numsegs)