Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Linux ARCnet driver - RFC1201 (standard) packet encapsulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Written 1994-1999 by Avery Pennarun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Derived from skeleton.c by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  for sponsoring the further development of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * The original copyright of skeleton.c was as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * skeleton.c Written 1993 by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Copyright 1993 United States Government as represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Director, National Security Agency.  This software may only be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * and distributed according to the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * modified by SRC, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * For more details, see drivers/net/arcnet.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	       struct archdr *pkthdr, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			unsigned short type, uint8_t daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		      int bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int continue_tx(struct net_device *dev, int bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static struct ArcProto rfc1201_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.suffix		= 'a',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.mtu		= 1500,	/* could be more, but some receivers can't handle it... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.is_ip          = 1,    /* This is for sending IP and ARP packages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.rx		= rx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.build_header	= build_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.prepare_tx	= prepare_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.continue_tx	= continue_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.ack_tx         = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int __init arcnet_rfc1201_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	pr_info("%s\n", "RFC1201 \"standard\" (`a') encapsulation support loaded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	arc_proto_map[ARC_P_IP]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	    = arc_proto_map[ARC_P_IPV6]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	    = arc_proto_map[ARC_P_ARP]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	    = arc_proto_map[ARC_P_RARP]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	    = arc_proto_map[ARC_P_IPX]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	    = arc_proto_map[ARC_P_NOVELL_EC]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	    = &rfc1201_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* if someone else already owns the broadcast, we won't take it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (arc_bcast_proto == arc_proto_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		arc_bcast_proto = &rfc1201_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void __exit arcnet_rfc1201_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	arcnet_unregister_proto(&rfc1201_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) module_init(arcnet_rfc1201_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) module_exit(arcnet_rfc1201_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /* Determine a packet's protocol ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * With ARCnet we have to convert everything to Ethernet-style stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct archdr *pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	/* Pull off the arcnet header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	skb_pull(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (pkt->hard.dest == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		skb->pkt_type = PACKET_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	} else if (dev->flags & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		/* if we're not sending to ourselves :) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (pkt->hard.dest != dev->dev_addr[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* now return the protocol number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	switch (soft->proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case ARC_P_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case ARC_P_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case ARC_P_ARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return htons(ETH_P_ARP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case ARC_P_RARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return htons(ETH_P_RARP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case ARC_P_IPX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	case ARC_P_NOVELL_EC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return htons(ETH_P_802_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		dev->stats.rx_crc_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* packet receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	       struct archdr *pkthdr, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct archdr *pkt = pkthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct arc_rfc1201 *soft = &pkthdr->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int saddr = pkt->hard.source, ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct Incoming *in = &lp->rfc1201.incoming[saddr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	arc_printk(D_DURING, dev, "it's an RFC1201 packet (length=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		   length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (length >= MinTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		ofs = 512 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		ofs = 256 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (soft->split_flag == 0xFF) {		/* Exception Packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (length >= 4 + RFC1201_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			arc_printk(D_DURING, dev, "compensating for exception packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			arc_printk(D_EXTRA, dev, "short RFC1201 exception packet from %02Xh",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				   saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		/* skip over 4-byte junkola */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		length -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		ofs += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		lp->hw.copy_from_card(dev, bufnum, 512 - length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				      soft, sizeof(pkt->soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (!soft->split_flag) {	/* not split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		arc_printk(D_RX, dev, "incoming is not split (splitflag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			   soft->split_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (in->skb) {	/* already assembling one! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			arc_printk(D_EXTRA, dev, "aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				   in->sequence, soft->split_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				   soft->sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			lp->rfc1201.aborted_seq = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			dev_kfree_skb_irq(in->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			dev->stats.rx_missed_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			in->skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		in->sequence = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		skb_put(skb, length + ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* up to sizeof(pkt->soft) has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		 * been copied from the card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		memcpy(pkt, pkthdr, sizeof(struct archdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (length > sizeof(pkt->soft))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			lp->hw.copy_from_card(dev, bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 					      ofs + sizeof(pkt->soft),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 					      pkt->soft.raw + sizeof(pkt->soft),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 					      length - sizeof(pkt->soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* ARP packets have problems when sent from some DOS systems:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		 * the source address is always 0!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		 * So we take the hardware source addr (which is impossible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		 * to fumble) and insert it ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (soft->proto == ARC_P_ARP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			struct arphdr *arp = (struct arphdr *)soft->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			/* make sure addresses are the right length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			if (arp->ar_hln == 1 && arp->ar_pln == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				uint8_t *cptr = (uint8_t *)arp + sizeof(struct arphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				if (!*cptr) {	/* is saddr = 00? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					arc_printk(D_EXTRA, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 						   "ARP source address was 00h, set to %02Xh\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 						   saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 					dev->stats.rx_crc_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 					*cptr = saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					arc_printk(D_DURING, dev, "ARP source address (%Xh) is fine.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 						   *cptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				arc_printk(D_NORMAL, dev, "funny-shaped ARP packet. (%Xh, %Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 					   arp->ar_hln, arp->ar_pln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				dev->stats.rx_crc_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			arcnet_dump_skb(dev, skb, "rx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		skb->protocol = type_trans(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	} else {		/* split packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		/* NOTE: MSDOS ARP packet correction should only need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		 * apply to unsplit packets, since ARP packets are so short.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		 * My interpretation of the RFC1201 document is that if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		 * packet is received out of order, the entire assembly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		 * process should be aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		 * The RFC also mentions "it is possible for successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		 * received packets to be retransmitted." As of 0.40 all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		 * previously received packets are allowed, not just the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		 * most recent one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		 * We allow multiple assembly processes, one for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		 * ARCnet card possible on the network.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 * Seems rather like a waste of memory, but there's no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * other way to be reliable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		arc_printk(D_RX, dev, "packet is split (splitflag=%d, seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			   soft->split_flag, in->sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		if (in->skb && in->sequence != soft->sequence) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			arc_printk(D_EXTRA, dev, "wrong seq number (saddr=%d, expected=%d, seq=%d, splitflag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				   saddr, in->sequence, soft->sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				   soft->split_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			dev_kfree_skb_irq(in->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			in->skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			dev->stats.rx_missed_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			in->lastpacket = in->numpackets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		if (soft->split_flag & 1) {	/* first packet in split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			arc_printk(D_RX, dev, "brand new splitpacket (splitflag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				   soft->split_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			if (in->skb) {	/* already assembling one! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				arc_printk(D_EXTRA, dev, "aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 					   in->sequence, soft->split_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 					   soft->sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				dev->stats.rx_missed_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				dev_kfree_skb_irq(in->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			in->sequence = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			in->numpackets = ((unsigned)soft->split_flag >> 1) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			in->lastpacket = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			if (in->numpackets > 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				arc_printk(D_EXTRA, dev, "incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 					   soft->split_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 				lp->rfc1201.aborted_seq = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				dev->stats.rx_length_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			in->skb = skb = alloc_skb(508 * in->numpackets + ARC_HDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 						  GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				arc_printk(D_NORMAL, dev, "(split) memory squeeze, dropping packet.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				lp->rfc1201.aborted_seq = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			memcpy(pkt, pkthdr, ARC_HDR_SIZE + RFC1201_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			skb_put(skb, ARC_HDR_SIZE + RFC1201_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			soft->split_flag = 0;	/* end result won't be split */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		} else {	/* not first packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			int packetnum = ((unsigned)soft->split_flag >> 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			/* if we're not assembling, there's no point trying to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			 * continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			if (!in->skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 				if (lp->rfc1201.aborted_seq != soft->sequence) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 					arc_printk(D_EXTRA, dev, "can't continue split without starting first! (splitflag=%d, seq=%d, aborted=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 						   soft->split_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 						   soft->sequence,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 						   lp->rfc1201.aborted_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 					dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 					dev->stats.rx_missed_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			in->lastpacket++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			/* if not the right flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			if (packetnum != in->lastpacket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				/* harmless duplicate? ignore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				if (packetnum <= in->lastpacket - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 					arc_printk(D_EXTRA, dev, "duplicate splitpacket ignored! (splitflag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 						   soft->split_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 					dev->stats.rx_frame_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 					return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				/* "bad" duplicate, kill reassembly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				arc_printk(D_EXTRA, dev, "out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 					   in->sequence, soft->split_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 					   soft->sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				lp->rfc1201.aborted_seq = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				dev_kfree_skb_irq(in->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				in->skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				dev->stats.rx_missed_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				in->lastpacket = in->numpackets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			pkt = (struct archdr *)in->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		skb = in->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		lp->hw.copy_from_card(dev, bufnum, ofs + RFC1201_HDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				      skb->data + skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				      length - RFC1201_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		skb_put(skb, length - RFC1201_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		/* are we done? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		if (in->lastpacket == in->numpackets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			in->skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			in->lastpacket = in->numpackets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			arc_printk(D_SKB_SIZE, dev, "skb: received %d bytes from %02X (unsplit)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 				   skb->len, pkt->hard.source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			arc_printk(D_SKB_SIZE, dev, "skb: received %d bytes from %02X (split)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				   skb->len, pkt->hard.source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				arcnet_dump_skb(dev, skb, "rx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			skb->protocol = type_trans(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* Create the ARCnet hard/soft headers for RFC1201. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static int build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			unsigned short type, uint8_t daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	int hdr_size = ARC_HDR_SIZE + RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct archdr *pkt = skb_push(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct arc_rfc1201 *soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* set the protocol ID according to RFC1201 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	case ETH_P_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		soft->proto = ARC_P_IP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	case ETH_P_IPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		soft->proto = ARC_P_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	case ETH_P_ARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		soft->proto = ARC_P_ARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	case ETH_P_RARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		soft->proto = ARC_P_RARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	case ETH_P_IPX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	case ETH_P_802_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	case ETH_P_802_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		soft->proto = ARC_P_IPX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	case ETH_P_ATALK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		soft->proto = ARC_P_ATALK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		arc_printk(D_NORMAL, dev, "RFC1201: I don't understand protocol %d (%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			   type, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		dev->stats.tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	/* Set the source hardware address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	 * This is pretty pointless for most purposes, but it can help in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	 * debugging.  ARCnet does not allow us to change the source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	 * in the actual packet sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	pkt->hard.source = *dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	soft->sequence = htons(lp->rfc1201.sequence++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	soft->split_flag = 0;	/* split packets are done elsewhere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	/* see linux/net/ethernet/eth.c to see where I got the following */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		/* FIXME: fill in the last byte of the dest ipaddr here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		 * to better comply with RFC1051 in "noarp" mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * For now, always broadcasting will probably at least get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 * packets sent out :)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		pkt->hard.dest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	/* otherwise, drop in the dest address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	pkt->hard.dest = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	return hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static void load_pkt(struct net_device *dev, struct arc_hardware *hard,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		     struct arc_rfc1201 *soft, int softlen, int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	/* assume length <= XMTU: someone should have handled that by now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (softlen > MinTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		hard->offset[1] = ofs = 512 - softlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	} else if (softlen > MTU) {	/* exception packet - add an extra header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		struct arc_rfc1201 excsoft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		excsoft.proto = soft->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		excsoft.split_flag = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		excsoft.sequence = htons(0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		ofs = 512 - softlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		hard->offset[1] = ofs - RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		lp->hw.copy_to_card(dev, bufnum, ofs - RFC1201_HDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 				    &excsoft, RFC1201_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		hard->offset[0] = ofs = 256 - softlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	lp->hw.copy_to_card(dev, bufnum, ofs, soft, softlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	lp->lastload_dest = hard->dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		      int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	const int maxsegsize = XMTU - RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	struct Outgoing *out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		   lp->next_tx, lp->cur_tx, bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	/* hard header is not included in packet length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	length -= ARC_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	pkt->soft.rfc1201.split_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/* need to do a split packet? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (length > XMTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		out = &lp->outgoing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		out->length = length - RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		out->dataleft = lp->outgoing.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		out->numsegs = (out->dataleft + maxsegsize - 1) / maxsegsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		out->segnum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		arc_printk(D_DURING, dev, "rfc1201 prep_tx: ready for %d-segment split (%d bytes, seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			   out->numsegs, out->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			   pkt->soft.rfc1201.sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		return 0;	/* not done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	/* just load the packet into the buffers and send it off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	load_pkt(dev, &pkt->hard, &pkt->soft.rfc1201, length, bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return 1;		/* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int continue_tx(struct net_device *dev, int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct Outgoing *out = &lp->outgoing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	struct arc_hardware *hard = &out->pkt->hard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	struct arc_rfc1201 *soft = &out->pkt->soft.rfc1201, *newsoft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	int maxsegsize = XMTU - RFC1201_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	int seglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	arc_printk(D_DURING, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		   "rfc1201 continue_tx: loading segment %d(+1) of %d (seq=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		   out->segnum, out->numsegs, soft->sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	/* the "new" soft header comes right before the data chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	newsoft = (struct arc_rfc1201 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	    (out->pkt->soft.raw + out->length - out->dataleft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	if (!out->segnum)	/* first packet; newsoft == soft */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		newsoft->split_flag = ((out->numsegs - 2) << 1) | 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		newsoft->split_flag = out->segnum << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		newsoft->proto = soft->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		newsoft->sequence = soft->sequence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	seglen = maxsegsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (seglen > out->dataleft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		seglen = out->dataleft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	out->dataleft -= seglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	load_pkt(dev, hard, newsoft, seglen + RFC1201_HDR_SIZE, bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	out->segnum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (out->segnum >= out->numsegs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }