Skip to content

Commit 6c87e1a

Browse files
CHKDSK88kuba-moo
authored andcommitted
net: dsa: vsc73xx: introduce tag 8021q for vsc73xx
This commit introduces a new tagger based on 802.1q tagging. It's designed for the vsc73xx driver. The VSC73xx family doesn't have any tag support for the RGMII port, but it could be based on VLANs. Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Signed-off-by: Pawel Dembicki <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d124cf5 commit 6c87e1a

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

include/net/dsa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct tc_action;
5353
#define DSA_TAG_PROTO_RTL8_4T_VALUE 25
5454
#define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26
5555
#define DSA_TAG_PROTO_LAN937X_VALUE 27
56+
#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28
5657

5758
enum dsa_tag_protocol {
5859
DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
@@ -83,6 +84,7 @@ enum dsa_tag_protocol {
8384
DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE,
8485
DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE,
8586
DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE,
87+
DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE,
8688
};
8789

8890
struct dsa_switch;

net/dsa/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ config NET_DSA_TAG_TRAILER
166166
Say Y or M if you want to enable support for tagging frames at
167167
with a trailed. e.g. Marvell 88E6060.
168168

169+
config NET_DSA_TAG_VSC73XX_8021Q
170+
tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, using VLAN"
171+
help
172+
Say Y or M if you want to enable support for tagging frames with a
173+
custom VLAN-based header.
174+
169175
config NET_DSA_TAG_XRS700X
170176
tristate "Tag driver for XRS700x switches"
171177
help

net/dsa/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) += tag_rtl8_4.o
3737
obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o
3838
obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
3939
obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
40+
obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
4041
obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
4142

4243
# for tracing framework to find trace.h

net/dsa/tag_vsc73xx_8021q.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR MIT
2+
/* Copyright (C) 2024 Pawel Dembicki <[email protected]>
3+
*/
4+
#include <linux/dsa/8021q.h>
5+
6+
#include "tag.h"
7+
#include "tag_8021q.h"
8+
9+
#define VSC73XX_8021Q_NAME "vsc73xx-8021q"
10+
11+
static struct sk_buff *
12+
vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev)
13+
{
14+
struct dsa_port *dp = dsa_user_to_port(netdev);
15+
u16 queue_mapping = skb_get_queue_mapping(skb);
16+
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
17+
u8 pcp;
18+
19+
if (skb->offload_fwd_mark) {
20+
unsigned int bridge_num = dsa_port_bridge_num_get(dp);
21+
struct net_device *br = dsa_port_bridge_dev_get(dp);
22+
23+
if (br_vlan_enabled(br))
24+
return skb;
25+
26+
tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
27+
}
28+
29+
pcp = netdev_txq_to_tc(netdev, queue_mapping);
30+
31+
return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q,
32+
((pcp << VLAN_PRIO_SHIFT) | tx_vid));
33+
}
34+
35+
static struct sk_buff *
36+
vsc73xx_rcv(struct sk_buff *skb, struct net_device *netdev)
37+
{
38+
int src_port = -1, switch_id = -1, vbid = -1, vid = -1;
39+
40+
dsa_8021q_rcv(skb, &src_port, &switch_id, &vbid, &vid);
41+
42+
skb->dev = dsa_tag_8021q_find_user(netdev, src_port, switch_id,
43+
vid, vbid);
44+
if (!skb->dev) {
45+
dev_warn_ratelimited(&netdev->dev,
46+
"Couldn't decode source port\n");
47+
return NULL;
48+
}
49+
50+
dsa_default_offload_fwd_mark(skb);
51+
52+
return skb;
53+
}
54+
55+
static const struct dsa_device_ops vsc73xx_8021q_netdev_ops = {
56+
.name = VSC73XX_8021Q_NAME,
57+
.proto = DSA_TAG_PROTO_VSC73XX_8021Q,
58+
.xmit = vsc73xx_xmit,
59+
.rcv = vsc73xx_rcv,
60+
.needed_headroom = VLAN_HLEN,
61+
.promisc_on_conduit = true,
62+
};
63+
64+
MODULE_LICENSE("GPL");
65+
MODULE_DESCRIPTION("DSA tag driver for VSC73XX family of switches, using VLAN");
66+
MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_VSC73XX_8021Q, VSC73XX_8021Q_NAME);
67+
68+
module_dsa_tag_driver(vsc73xx_8021q_netdev_ops);

0 commit comments

Comments
 (0)