WIP FPC-III support
[linux/fpc-iii.git] / net / dsa / tag_trailer.c
blob5b97ede56a0fd89dc4276954f26414b164ed086b
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * net/dsa/tag_trailer.c - Trailer tag format handling
4 * Copyright (c) 2008-2009 Marvell Semiconductor
5 */
7 #include <linux/etherdevice.h>
8 #include <linux/list.h>
9 #include <linux/slab.h>
11 #include "dsa_priv.h"
13 static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
15 struct dsa_port *dp = dsa_slave_to_port(dev);
16 u8 *trailer;
18 trailer = skb_put(skb, 4);
19 trailer[0] = 0x80;
20 trailer[1] = 1 << dp->index;
21 trailer[2] = 0x10;
22 trailer[3] = 0x00;
24 return skb;
27 static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
28 struct packet_type *pt)
30 u8 *trailer;
31 int source_port;
33 if (skb_linearize(skb))
34 return NULL;
36 trailer = skb_tail_pointer(skb) - 4;
37 if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
38 (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
39 return NULL;
41 source_port = trailer[1] & 7;
43 skb->dev = dsa_master_find_slave(dev, 0, source_port);
44 if (!skb->dev)
45 return NULL;
47 if (pskb_trim_rcsum(skb, skb->len - 4))
48 return NULL;
50 return skb;
53 static const struct dsa_device_ops trailer_netdev_ops = {
54 .name = "trailer",
55 .proto = DSA_TAG_PROTO_TRAILER,
56 .xmit = trailer_xmit,
57 .rcv = trailer_rcv,
58 .overhead = 4,
59 .tail_tag = true,
62 MODULE_LICENSE("GPL");
63 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
65 module_dsa_tag_driver(trailer_netdev_ops);