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 - "cap mode" packet encapsulation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * It adds sequence numbers to packets for communicating between a user space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * application and the driver. After a transmit it sends a packet with protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * byte 0 back up to the userspace containing the sequence number of the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * plus the transmit-status on the ArcNet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Written 2002-4 by Esben Nielsen, Vestas Wind Systems A/S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Derived from arc-rawmode.c by Avery Pennarun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * arc-rawmode was in turned based on skeleton.c, see below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * The original copyright of skeleton.c was as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * skeleton.c Written 1993 by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Copyright 1993 United States Government as represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Director, National Security Agency.  This software may only be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * and distributed according to the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * modified by SRC, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * For more details, see drivers/net/arcnet.c
^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)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* packet receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	       struct archdr *pkthdr, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct archdr *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	char *pktbuf, *pkthdrbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	arc_printk(D_DURING, dev, "it's a raw(cap) packet (length=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		   length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (length >= MinTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		ofs = 512 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		ofs = 256 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	skb = alloc_skb(length + ARC_HDR_SIZE + sizeof(int), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	skb_put(skb, length + ARC_HDR_SIZE + sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	pkt = (struct archdr *)skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	skb_pull(skb, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* up to sizeof(pkt->soft) has already been copied from the card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * squeeze in an int for the cap encapsulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 * use these variables to be sure we count in bytes, not in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 * sizeof(struct archdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	pktbuf = (char *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	pkthdrbuf = (char *)pkthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	memcpy(pktbuf, pkthdrbuf, ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	memcpy(pktbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto) + sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	       pkthdrbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	       sizeof(struct archdr) - ARC_HDR_SIZE - sizeof(pkt->soft.cap.proto));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (length > sizeof(pkt->soft))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				      pkt->soft.raw + sizeof(pkt->soft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				      + sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				      length - sizeof(pkt->soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		arcnet_dump_skb(dev, skb, "rx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	skb->protocol = cpu_to_be16(ETH_P_ARCNET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) /* Create the ARCnet hard/soft headers for cap mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * There aren't any soft headers in cap mode - not even the protocol id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int build_header(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			unsigned short type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			uint8_t daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int hdr_size = ARC_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct archdr *pkt = skb_push(skb, hdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	arc_printk(D_PROTO, dev, "Preparing header for cap packet %x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		   *((int *)&pkt->soft.cap.cookie[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* Set the source hardware address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	 * This is pretty pointless for most purposes, but it can help in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 * debugging.  ARCnet does not allow us to change the source address in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * the actual packet sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	pkt->hard.source = *dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* see linux/net/ethernet/eth.c to see where I got the following */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		/* FIXME: fill in the last byte of the dest ipaddr here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		 * better comply with RFC1051 in "noarp" mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		pkt->hard.dest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* otherwise, just fill it in and go! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	pkt->hard.dest = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return hdr_size;	/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		      int bufnum)
^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 arc_hardware *hard = &pkt->hard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/* hard header is not included in packet length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	length -= ARC_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* And neither is the cookie field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	length -= sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		   lp->next_tx, lp->cur_tx, bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	arc_printk(D_PROTO, dev, "Sending for cap packet %x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		   *((int *)&pkt->soft.cap.cookie[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (length > XMTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		/* should never happen! other people already check for this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		arc_printk(D_NORMAL, dev, "Bug!  prepare_tx with size %d (> %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			   length, XMTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		length = XMTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (length > MinTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		hard->offset[1] = ofs = 512 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	} else if (length > MTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		hard->offset[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		hard->offset[1] = ofs = 512 - length - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		hard->offset[0] = ofs = 256 - length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	arc_printk(D_DURING, dev, "prepare_tx: length=%d ofs=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		   length, ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* Copy the arcnet-header + the protocol byte down: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft.cap.proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			    sizeof(pkt->soft.cap.proto));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Skip the extra integer we have written into it as a cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * but write the rest of the message:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	lp->hw.copy_to_card(dev, bufnum, ofs + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			    ((unsigned char *)&pkt->soft.cap.mes), length - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	lp->lastload_dest = hard->dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return 1;	/* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int ack_tx(struct net_device *dev, int acked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct sk_buff *ackskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct archdr *ackpkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int length = sizeof(struct arc_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	arc_printk(D_DURING, dev, "capmode: ack_tx: protocol: %x: result: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		   lp->outgoing.skb->protocol, acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		arcnet_dump_skb(dev, lp->outgoing.skb, "ack_tx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/* Now alloc a skb to send back up through the layers: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	ackskb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (!ackskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		goto free_outskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	skb_put(ackskb, length + ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	ackskb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	skb_reset_mac_header(ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ackpkt = (struct archdr *)skb_mac_header(ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/* skb_pull(ackskb, ARC_HDR_SIZE); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	skb_copy_from_linear_data(lp->outgoing.skb, ackpkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				  ARC_HDR_SIZE + sizeof(struct arc_cap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	ackpkt->soft.cap.proto = 0; /* using protocol 0 for acknowledge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	ackpkt->soft.cap.mes.ack = acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	arc_printk(D_PROTO, dev, "Acknowledge for cap packet %x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		   *((int *)&ackpkt->soft.cap.cookie[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	ackskb->protocol = cpu_to_be16(ETH_P_ARCNET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		arcnet_dump_skb(dev, ackskb, "ack_tx_recv");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	netif_rx(ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) free_outskb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	dev_kfree_skb_irq(lp->outgoing.skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	lp->outgoing.proto = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			/* We are always finished when in this protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static struct ArcProto capmode_proto = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	.suffix		= 'r',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.mtu		= XMTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	.rx		= rx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	.build_header	= build_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.prepare_tx	= prepare_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.ack_tx		= ack_tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int __init capmode_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	pr_info("cap mode (`c') encapsulation support loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	for (count = 1; count <= 8; count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (arc_proto_map[count] == arc_proto_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			arc_proto_map[count] = &capmode_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* for cap mode, we only set the bcast proto if there's no better one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (arc_bcast_proto == arc_proto_default)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		arc_bcast_proto = &capmode_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	arc_proto_default = &capmode_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	arc_raw_proto = &capmode_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static void __exit capmode_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	arcnet_unregister_proto(&capmode_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) module_init(capmode_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) module_exit(capmode_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) MODULE_LICENSE("GPL");