]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/dsa/tag_trailer.c
Merge tag 'linux-kselftest-fixes-5.14-rc6' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-jammy-kernel.git] / net / dsa / tag_trailer.c
CommitLineData
dfedd3b6 1// SPDX-License-Identifier: GPL-2.0+
396138f0
LB
2/*
3 * net/dsa/tag_trailer.c - Trailer tag format handling
e84665c9 4 * Copyright (c) 2008-2009 Marvell Semiconductor
396138f0
LB
5 */
6
7#include <linux/etherdevice.h>
8#include <linux/list.h>
5a0e3ad6 9#include <linux/slab.h>
ea5dd34b 10
396138f0
LB
11#include "dsa_priv.h"
12
4ed70ce9 13static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
396138f0 14{
d945097b 15 struct dsa_port *dp = dsa_slave_to_port(dev);
396138f0
LB
16 u8 *trailer;
17
ef3f72fe 18 trailer = skb_put(skb, 4);
396138f0 19 trailer[0] = 0x80;
d945097b 20 trailer[1] = 1 << dp->index;
396138f0
LB
21 trailer[2] = 0x10;
22 trailer[3] = 0x00;
23
ef3f72fe 24 return skb;
396138f0
LB
25}
26
a86d8bec 27static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
89e49506 28 struct packet_type *pt)
396138f0 29{
396138f0
LB
30 u8 *trailer;
31 int source_port;
32
396138f0 33 if (skb_linearize(skb))
54709795 34 return NULL;
396138f0
LB
35
36 trailer = skb_tail_pointer(skb) - 4;
37 if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
fbd03513 38 (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
54709795 39 return NULL;
396138f0
LB
40
41 source_port = trailer[1] & 7;
3775b1b7 42
2231c43b 43 skb->dev = dsa_master_find_slave(dev, 0, source_port);
3775b1b7 44 if (!skb->dev)
54709795 45 return NULL;
396138f0 46
349b71d6
ZJ
47 if (pskb_trim_rcsum(skb, skb->len - 4))
48 return NULL;
396138f0 49
a86d8bec 50 return skb;
396138f0
LB
51}
52
f81a43e8 53static const struct dsa_device_ops trailer_netdev_ops = {
875138f8 54 .name = "trailer",
056eed2f 55 .proto = DSA_TAG_PROTO_TRAILER,
3e8a72d1
FF
56 .xmit = trailer_xmit,
57 .rcv = trailer_rcv,
4e500251 58 .needed_tailroom = 4,
396138f0 59};
0b42f033 60
f18bba50 61MODULE_LICENSE("GPL");
0b42f033 62MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
d3b8c049
AL
63
64module_dsa_tag_driver(trailer_netdev_ops);