Merge tag 'usb-serial-5.15-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / net / dsa / tag_trailer.c
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  */
6
7 #include <linux/etherdevice.h>
8 #include <linux/list.h>
9 #include <linux/slab.h>
10
11 #include "dsa_priv.h"
12
13 static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
14 {
15         struct dsa_port *dp = dsa_slave_to_port(dev);
16         u8 *trailer;
17
18         trailer = skb_put(skb, 4);
19         trailer[0] = 0x80;
20         trailer[1] = 1 << dp->index;
21         trailer[2] = 0x10;
22         trailer[3] = 0x00;
23
24         return skb;
25 }
26
27 static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev)
28 {
29         u8 *trailer;
30         int source_port;
31
32         if (skb_linearize(skb))
33                 return NULL;
34
35         trailer = skb_tail_pointer(skb) - 4;
36         if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
37             (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
38                 return NULL;
39
40         source_port = trailer[1] & 7;
41
42         skb->dev = dsa_master_find_slave(dev, 0, source_port);
43         if (!skb->dev)
44                 return NULL;
45
46         if (pskb_trim_rcsum(skb, skb->len - 4))
47                 return NULL;
48
49         return skb;
50 }
51
52 static const struct dsa_device_ops trailer_netdev_ops = {
53         .name   = "trailer",
54         .proto  = DSA_TAG_PROTO_TRAILER,
55         .xmit   = trailer_xmit,
56         .rcv    = trailer_rcv,
57         .needed_tailroom = 4,
58 };
59
60 MODULE_LICENSE("GPL");
61 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
62
63 module_dsa_tag_driver(trailer_netdev_ops);