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 - RFC1051 ("simple" 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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/gfp.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 <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static void rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	       struct archdr *pkthdr, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			unsigned short type, uint8_t daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		      int bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct ArcProto rfc1051_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.suffix		= 's',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.mtu		= XMTU - RFC1051_HDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.is_ip          = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.rx		= rx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.build_header	= build_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.prepare_tx	= prepare_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.continue_tx    = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.ack_tx         = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int __init arcnet_rfc1051_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	pr_info("%s\n", "RFC1051 \"simple standard\" (`s') encapsulation support loaded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	arc_proto_map[ARC_P_IP_RFC1051]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	    = arc_proto_map[ARC_P_ARP_RFC1051]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    = &rfc1051_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* if someone else already owns the broadcast, we won't take it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (arc_bcast_proto == arc_proto_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		arc_bcast_proto = &rfc1051_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void __exit arcnet_rfc1051_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	arcnet_unregister_proto(&rfc1051_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) module_init(arcnet_rfc1051_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) module_exit(arcnet_rfc1051_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /* Determine a packet's protocol ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * With ARCnet we have to convert everything to Ethernet-style stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static __be16 type_trans(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct archdr *pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct arc_rfc1051 *soft = &pkt->soft.rfc1051;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Pull off the arcnet header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	skb_pull(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (pkt->hard.dest == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		skb->pkt_type = PACKET_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	} else if (dev->flags & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		/* if we're not sending to ourselves :) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (pkt->hard.dest != dev->dev_addr[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* now return the protocol number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	switch (soft->proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	case ARC_P_IP_RFC1051:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	case ARC_P_ARP_RFC1051:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return htons(ETH_P_ARP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		dev->stats.rx_crc_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* packet receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	       struct archdr *pkthdr, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct archdr *pkt = pkthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	arc_printk(D_DURING, dev, "it's a raw packet (length=%d)\n", length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (length >= MinTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		ofs = 512 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		ofs = 256 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	skb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	skb_put(skb, length + ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* up to sizeof(pkt->soft) has already been copied from the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	memcpy(pkt, pkthdr, sizeof(struct archdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (length > sizeof(pkt->soft))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				      pkt->soft.raw + sizeof(pkt->soft),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				      length - sizeof(pkt->soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		arcnet_dump_skb(dev, skb, "rx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	skb->protocol = type_trans(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Create the ARCnet hard/soft headers for RFC1051 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			unsigned short type, uint8_t daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int hdr_size = ARC_HDR_SIZE + RFC1051_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct archdr *pkt = skb_push(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct arc_rfc1051 *soft = &pkt->soft.rfc1051;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* set the protocol ID according to RFC1051 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	case ETH_P_IP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		soft->proto = ARC_P_IP_RFC1051;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	case ETH_P_ARP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		soft->proto = ARC_P_ARP_RFC1051;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		arc_printk(D_NORMAL, dev, "RFC1051: I don't understand protocol %d (%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			   type, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		dev->stats.tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* Set the source hardware address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * This is pretty pointless for most purposes, but it can help in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * debugging.  ARCnet does not allow us to change the source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * in the actual packet sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	pkt->hard.source = *dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* see linux/net/ethernet/eth.c to see where I got the following */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		/* FIXME: fill in the last byte of the dest ipaddr here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		 * better comply with RFC1051 in "noarp" mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		pkt->hard.dest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* otherwise, just fill it in and go! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	pkt->hard.dest = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return hdr_size;	/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		      int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct arc_hardware *hard = &pkt->hard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		   lp->next_tx, lp->cur_tx, bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* hard header is not included in packet length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	length -= ARC_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (length > XMTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		/* should never happen! other people already check for this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		arc_printk(D_NORMAL, dev, "Bug!  prepare_tx with size %d (> %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			   length, XMTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		length = XMTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (length > MinTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		hard->offset[1] = ofs = 512 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	} else if (length > MTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		hard->offset[1] = ofs = 512 - length - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		hard->offset[0] = ofs = 256 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	lp->lastload_dest = hard->dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 1;		/* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }