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 "tag.h" |
12 | |
13 | #define TRAILER_NAME "trailer" |
14 | |
15 | static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) |
16 | { |
17 | struct dsa_port *dp = dsa_user_to_port(dev); |
18 | u8 *trailer; |
19 | |
20 | trailer = skb_put(skb, len: 4); |
21 | trailer[0] = 0x80; |
22 | trailer[1] = 1 << dp->index; |
23 | trailer[2] = 0x10; |
24 | trailer[3] = 0x00; |
25 | |
26 | return skb; |
27 | } |
28 | |
29 | static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev) |
30 | { |
31 | u8 *trailer; |
32 | int source_port; |
33 | |
34 | if (skb_linearize(skb)) |
35 | return NULL; |
36 | |
37 | trailer = skb_tail_pointer(skb) - 4; |
38 | if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 || |
39 | (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00) |
40 | return NULL; |
41 | |
42 | source_port = trailer[1] & 7; |
43 | |
44 | skb->dev = dsa_conduit_find_user(dev, device: 0, port: source_port); |
45 | if (!skb->dev) |
46 | return NULL; |
47 | |
48 | if (pskb_trim_rcsum(skb, len: skb->len - 4)) |
49 | return NULL; |
50 | |
51 | return skb; |
52 | } |
53 | |
54 | static const struct dsa_device_ops trailer_netdev_ops = { |
55 | .name = TRAILER_NAME, |
56 | .proto = DSA_TAG_PROTO_TRAILER, |
57 | .xmit = trailer_xmit, |
58 | .rcv = trailer_rcv, |
59 | .needed_tailroom = 4, |
60 | }; |
61 | |
62 | MODULE_LICENSE("GPL" ); |
63 | MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER, TRAILER_NAME); |
64 | |
65 | module_dsa_tag_driver(trailer_netdev_ops); |
66 | |