2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Linux ARCnet driver - "cap mode" packet encapsulation.
|
|
|
|
* It adds sequence numbers to packets for communicating between a user space
|
|
|
|
* application and the driver. After a transmit it sends a packet with protocol
|
|
|
|
* byte 0 back up to the userspace containing the sequence number of the packet
|
|
|
|
* plus the transmit-status on the ArcNet.
|
|
|
|
*
|
|
|
|
* Written 2002-4 by Esben Nielsen, Vestas Wind Systems A/S
|
|
|
|
* Derived from arc-rawmode.c by Avery Pennarun.
|
|
|
|
* arc-rawmode was in turned based on skeleton.c, see below.
|
|
|
|
*
|
|
|
|
* **********************
|
|
|
|
*
|
|
|
|
* The original copyright of skeleton.c was as follows:
|
|
|
|
*
|
|
|
|
* skeleton.c Written 1993 by Donald Becker.
|
|
|
|
* Copyright 1993 United States Government as represented by the
|
|
|
|
* Director, National Security Agency. This software may only be used
|
|
|
|
* and distributed according to the terms of the GNU General Public License as
|
|
|
|
* modified by SRC, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
* **********************
|
|
|
|
*
|
|
|
|
* For more details, see drivers/net/arcnet.c
|
|
|
|
*
|
|
|
|
* **********************
|
|
|
|
*/
|
|
|
|
|
2015-05-06 00:05:56 +07:00
|
|
|
#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <net/arp.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
2015-05-06 00:06:03 +07:00
|
|
|
|
|
|
|
#include "arcdevice.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* packet receiver */
|
|
|
|
static void rx(struct net_device *dev, int bufnum,
|
|
|
|
struct archdr *pkthdr, int length)
|
|
|
|
{
|
2008-11-13 14:37:49 +07:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct sk_buff *skb;
|
2019-08-29 06:14:50 +07:00
|
|
|
struct archdr *pkt;
|
2005-04-17 05:20:36 +07:00
|
|
|
char *pktbuf, *pkthdrbuf;
|
|
|
|
int ofs;
|
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_DURING, dev, "it's a raw(cap) packet (length=%d)\n",
|
|
|
|
length);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (length >= MinTU)
|
|
|
|
ofs = 512 - length;
|
|
|
|
else
|
|
|
|
ofs = 256 - length;
|
|
|
|
|
|
|
|
skb = alloc_skb(length + ARC_HDR_SIZE + sizeof(int), GFP_ATOMIC);
|
2015-05-06 00:06:00 +07:00
|
|
|
if (!skb) {
|
2009-01-09 20:01:08 +07:00
|
|
|
dev->stats.rx_dropped++;
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
skb_put(skb, length + ARC_HDR_SIZE + sizeof(int));
|
|
|
|
skb->dev = dev;
|
2007-03-20 05:30:44 +07:00
|
|
|
skb_reset_mac_header(skb);
|
2007-03-20 05:33:04 +07:00
|
|
|
pkt = (struct archdr *)skb_mac_header(skb);
|
2005-04-17 05:20:36 +07:00
|
|
|
skb_pull(skb, ARC_HDR_SIZE);
|
|
|
|
|
2015-05-06 00:05:52 +07:00
|
|
|
/* up to sizeof(pkt->soft) has already been copied from the card
|
|
|
|
* squeeze in an int for the cap encapsulation
|
|
|
|
* use these variables to be sure we count in bytes, not in
|
|
|
|
* sizeof(struct archdr)
|
|
|
|
*/
|
2015-05-06 00:05:47 +07:00
|
|
|
pktbuf = (char *)pkt;
|
|
|
|
pkthdrbuf = (char *)pkthdr;
|
|
|
|
memcpy(pktbuf, pkthdrbuf, ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto));
|
|
|
|
memcpy(pktbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto) + sizeof(int),
|
|
|
|
pkthdrbuf + ARC_HDR_SIZE + sizeof(pkt->soft.cap.proto),
|
|
|
|
sizeof(struct archdr) - ARC_HDR_SIZE - sizeof(pkt->soft.cap.proto));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (length > sizeof(pkt->soft))
|
|
|
|
lp->hw.copy_from_card(dev, bufnum, ofs + sizeof(pkt->soft),
|
|
|
|
pkt->soft.raw + sizeof(pkt->soft)
|
|
|
|
+ sizeof(int),
|
|
|
|
length - sizeof(pkt->soft));
|
|
|
|
|
2015-05-06 00:05:54 +07:00
|
|
|
if (BUGLVL(D_SKB))
|
|
|
|
arcnet_dump_skb(dev, skb, "rx");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-02-01 15:45:17 +07:00
|
|
|
skb->protocol = cpu_to_be16(ETH_P_ARCNET);
|
2005-04-17 05:20:36 +07:00
|
|
|
netif_rx(skb);
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:05:52 +07:00
|
|
|
/* Create the ARCnet hard/soft headers for cap mode.
|
2005-04-17 05:20:36 +07:00
|
|
|
* There aren't any soft headers in cap mode - not even the protocol id.
|
|
|
|
*/
|
|
|
|
static int build_header(struct sk_buff *skb,
|
|
|
|
struct net_device *dev,
|
|
|
|
unsigned short type,
|
|
|
|
uint8_t daddr)
|
|
|
|
{
|
|
|
|
int hdr_size = ARC_HDR_SIZE;
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:23 +07:00
|
|
|
struct archdr *pkt = skb_push(skb, hdr_size);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_PROTO, dev, "Preparing header for cap packet %x.\n",
|
|
|
|
*((int *)&pkt->soft.cap.cookie[0]));
|
2015-05-06 00:05:52 +07:00
|
|
|
|
|
|
|
/* Set the source hardware address.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* This is pretty pointless for most purposes, but it can help in
|
|
|
|
* debugging. ARCnet does not allow us to change the source address in
|
|
|
|
* the actual packet sent)
|
|
|
|
*/
|
|
|
|
pkt->hard.source = *dev->dev_addr;
|
|
|
|
|
|
|
|
/* see linux/net/ethernet/eth.c to see where I got the following */
|
|
|
|
|
|
|
|
if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
|
2015-05-06 00:05:52 +07:00
|
|
|
/* FIXME: fill in the last byte of the dest ipaddr here to
|
|
|
|
* better comply with RFC1051 in "noarp" mode.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
pkt->hard.dest = 0;
|
|
|
|
return hdr_size;
|
|
|
|
}
|
|
|
|
/* otherwise, just fill it in and go! */
|
|
|
|
pkt->hard.dest = daddr;
|
|
|
|
|
|
|
|
return hdr_size; /* success */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
|
|
|
|
int bufnum)
|
|
|
|
{
|
2008-11-13 14:37:49 +07:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct arc_hardware *hard = &pkt->hard;
|
|
|
|
int ofs;
|
|
|
|
|
|
|
|
/* hard header is not included in packet length */
|
|
|
|
length -= ARC_HDR_SIZE;
|
|
|
|
/* And neither is the cookie field */
|
|
|
|
length -= sizeof(int);
|
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_DURING, dev, "prepare_tx: txbufs=%d/%d/%d\n",
|
|
|
|
lp->next_tx, lp->cur_tx, bufnum);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_PROTO, dev, "Sending for cap packet %x.\n",
|
|
|
|
*((int *)&pkt->soft.cap.cookie[0]));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (length > XMTU) {
|
|
|
|
/* should never happen! other people already check for this. */
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_NORMAL, dev, "Bug! prepare_tx with size %d (> %d)\n",
|
|
|
|
length, XMTU);
|
2005-04-17 05:20:36 +07:00
|
|
|
length = XMTU;
|
|
|
|
}
|
|
|
|
if (length > MinTU) {
|
|
|
|
hard->offset[0] = 0;
|
|
|
|
hard->offset[1] = ofs = 512 - length;
|
|
|
|
} else if (length > MTU) {
|
|
|
|
hard->offset[0] = 0;
|
|
|
|
hard->offset[1] = ofs = 512 - length - 3;
|
2015-05-06 00:05:49 +07:00
|
|
|
} else {
|
2005-04-17 05:20:36 +07:00
|
|
|
hard->offset[0] = ofs = 256 - length;
|
2015-05-06 00:05:49 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_DURING, dev, "prepare_tx: length=%d ofs=%d\n",
|
|
|
|
length, ofs);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
/* Copy the arcnet-header + the protocol byte down: */
|
2005-04-17 05:20:36 +07:00
|
|
|
lp->hw.copy_to_card(dev, bufnum, 0, hard, ARC_HDR_SIZE);
|
|
|
|
lp->hw.copy_to_card(dev, bufnum, ofs, &pkt->soft.cap.proto,
|
|
|
|
sizeof(pkt->soft.cap.proto));
|
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
/* Skip the extra integer we have written into it as a cookie
|
2015-05-06 00:05:52 +07:00
|
|
|
* but write the rest of the message:
|
|
|
|
*/
|
2015-05-06 00:05:47 +07:00
|
|
|
lp->hw.copy_to_card(dev, bufnum, ofs + 1,
|
|
|
|
((unsigned char *)&pkt->soft.cap.mes), length - 1);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
lp->lastload_dest = hard->dest;
|
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
return 1; /* done */
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ack_tx(struct net_device *dev, int acked)
|
|
|
|
{
|
2010-05-31 14:35:13 +07:00
|
|
|
struct arcnet_local *lp = netdev_priv(dev);
|
|
|
|
struct sk_buff *ackskb;
|
|
|
|
struct archdr *ackpkt;
|
2015-05-06 00:05:47 +07:00
|
|
|
int length = sizeof(struct arc_cap);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:55 +07:00
|
|
|
arc_printk(D_DURING, dev, "capmode: ack_tx: protocol: %x: result: %d\n",
|
|
|
|
lp->outgoing.skb->protocol, acked);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:54 +07:00
|
|
|
if (BUGLVL(D_SKB))
|
|
|
|
arcnet_dump_skb(dev, lp->outgoing.skb, "ack_tx");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
/* Now alloc a skb to send back up through the layers: */
|
2015-05-06 00:05:47 +07:00
|
|
|
ackskb = alloc_skb(length + ARC_HDR_SIZE, GFP_ATOMIC);
|
2015-05-06 00:06:00 +07:00
|
|
|
if (!ackskb)
|
2010-05-31 14:35:13 +07:00
|
|
|
goto free_outskb;
|
|
|
|
|
2015-05-06 00:05:47 +07:00
|
|
|
skb_put(ackskb, length + ARC_HDR_SIZE);
|
2010-05-31 14:35:13 +07:00
|
|
|
ackskb->dev = dev;
|
|
|
|
|
|
|
|
skb_reset_mac_header(ackskb);
|
|
|
|
ackpkt = (struct archdr *)skb_mac_header(ackskb);
|
|
|
|
/* skb_pull(ackskb, ARC_HDR_SIZE); */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
skb_copy_from_linear_data(lp->outgoing.skb, ackpkt,
|
|
|
|
ARC_HDR_SIZE + sizeof(struct arc_cap));
|
|
|
|
ackpkt->soft.cap.proto = 0; /* using protocol 0 for acknowledge */
|
2015-05-06 00:05:47 +07:00
|
|
|
ackpkt->soft.cap.mes.ack = acked;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2017-06-28 23:28:34 +07:00
|
|
|
arc_printk(D_PROTO, dev, "Acknowledge for cap packet %x.\n",
|
2015-05-06 00:05:55 +07:00
|
|
|
*((int *)&ackpkt->soft.cap.cookie[0]));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
ackskb->protocol = cpu_to_be16(ETH_P_ARCNET);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:54 +07:00
|
|
|
if (BUGLVL(D_SKB))
|
|
|
|
arcnet_dump_skb(dev, ackskb, "ack_tx_recv");
|
2010-05-31 14:35:13 +07:00
|
|
|
netif_rx(ackskb);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
free_outskb:
|
|
|
|
dev_kfree_skb_irq(lp->outgoing.skb);
|
2015-05-06 00:06:02 +07:00
|
|
|
lp->outgoing.proto = NULL;
|
|
|
|
/* We are always finished when in this protocol */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-06 00:05:49 +07:00
|
|
|
static struct ArcProto capmode_proto = {
|
2015-03-20 21:22:02 +07:00
|
|
|
.suffix = 'r',
|
|
|
|
.mtu = XMTU,
|
|
|
|
.rx = rx,
|
|
|
|
.build_header = build_header,
|
|
|
|
.prepare_tx = prepare_tx,
|
|
|
|
.ack_tx = ack_tx
|
2010-05-31 14:35:13 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-22 16:47:43 +07:00
|
|
|
static int __init capmode_module_init(void)
|
2010-05-31 14:35:13 +07:00
|
|
|
{
|
|
|
|
int count;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-22 16:47:43 +07:00
|
|
|
pr_info("cap mode (`c') encapsulation support loaded\n");
|
|
|
|
|
2010-05-31 14:35:13 +07:00
|
|
|
for (count = 1; count <= 8; count++)
|
|
|
|
if (arc_proto_map[count] == arc_proto_default)
|
|
|
|
arc_proto_map[count] = &capmode_proto;
|
|
|
|
|
|
|
|
/* for cap mode, we only set the bcast proto if there's no better one */
|
|
|
|
if (arc_bcast_proto == arc_proto_default)
|
|
|
|
arc_bcast_proto = &capmode_proto;
|
|
|
|
|
|
|
|
arc_proto_default = &capmode_proto;
|
|
|
|
arc_raw_proto = &capmode_proto;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit capmode_module_exit(void)
|
|
|
|
{
|
|
|
|
arcnet_unregister_proto(&capmode_proto);
|
|
|
|
}
|
|
|
|
module_init(capmode_module_init);
|
|
|
|
module_exit(capmode_module_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|