Commit c49379dc authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-dsa-vsc73xx-implement-vlan-operations'

Pawel Dembicki says:

====================
net: dsa: vsc73xx: Implement VLAN operations

This patch series is a result of splitting a larger patch series [0],
where some parts was merged before.

The first patch implements port state configuration, which is required
for bridge functionality. STP frames are not forwarded at this moment.
BPDU frames are only forwarded from/to the PI/SI interface.
For more information, see chapter 2.7.1 (CPU Forwarding) in the
datasheet.

Patches 2, 7-9 and 11 provide a basic implementation of tag_8021q
functionality with QinQ support, without VLAN filtering in
the bridge and simple VLAN awareness in VLAN filtering mode.

Patches 3-6 came from Vladimir Oltean. They prepare for making
tag8021q more common. VSC73XX uses very similar tag recognition,
and some code from tag_sja1105 could be moved to tag_8021q for
common use.

Patch 10 is preparation for use tag_8021q bridge functions as generic
implementation of the 'ds->ops->port_bridge_*()'.

Patch 12 is required to avoid problem with learning on standalone ports.

[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
====================

Link: https://patch.msgid.link/20240713211620.1125910-1-paweldembicki@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents a8ea8d53 259a7061
......@@ -127,7 +127,7 @@ config NET_DSA_SMSC_LAN9303_MDIO
config NET_DSA_VITESSE_VSC73XX
tristate
select NET_DSA_TAG_NONE
select NET_DSA_TAG_VSC73XX_8021Q
select FIXED_PHY
select VITESSE_PHY
select GPIOLIB
......
......@@ -2133,14 +2133,13 @@ static int sja1105_bridge_join(struct dsa_switch *ds, int port,
if (rc)
return rc;
rc = dsa_tag_8021q_bridge_join(ds, port, bridge);
rc = dsa_tag_8021q_bridge_join(ds, port, bridge, tx_fwd_offload,
extack);
if (rc) {
sja1105_bridge_member(ds, port, bridge, false);
return rc;
}
*tx_fwd_offload = true;
return 0;
}
......@@ -3167,8 +3166,7 @@ static int sja1105_setup(struct dsa_switch *ds)
ds->vlan_filtering_is_global = true;
ds->untag_bridge_pvid = true;
ds->fdb_isolation = true;
/* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */
ds->max_num_bridges = 7;
ds->max_num_bridges = DSA_TAG_8021Q_MAX_NUM_BRIDGES;
/* Advertise the 8 egress queues */
ds->num_tx_queues = SJA1105_NUM_TC;
......
This diff is collapsed.
......@@ -14,6 +14,22 @@
*/
#define VSC73XX_MAX_NUM_PORTS 8
/**
* struct vsc73xx_portinfo - port data structure: contains storage data
* @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode
* @pvid_tag_8021q: pvid vlan number used in tag_8021q mode
* @pvid_vlan_filtering_configured: informs if port has configured pvid in vlan
* filtering mode
* @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q
* mode
*/
struct vsc73xx_portinfo {
u16 pvid_vlan_filtering;
u16 pvid_tag_8021q;
bool pvid_vlan_filtering_configured;
bool pvid_tag_8021q_configured;
};
/**
* struct vsc73xx - VSC73xx state container: main data structure
* @dev: The device pointer
......@@ -25,6 +41,10 @@
* @addr: MAC address used in flow control frames
* @ops: Structure with hardware-dependent operations
* @priv: Pointer to the configuration interface structure
* @portinfo: Storage table portinfo structructures
* @vlans: List of configured vlans. Contains port mask and untagged status of
* every vlan configured in port vlan operation. It doesn't cover tag_8021q
* vlans.
*/
struct vsc73xx {
struct device *dev;
......@@ -35,6 +55,8 @@ struct vsc73xx {
u8 addr[ETH_ALEN];
const struct vsc73xx_ops *ops;
void *priv;
struct vsc73xx_portinfo portinfo[VSC73XX_MAX_NUM_PORTS];
struct list_head vlans;
};
/**
......@@ -49,6 +71,21 @@ struct vsc73xx_ops {
u32 val);
};
/**
* struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan
* database copy
* @vid: VLAN number
* @portmask: each bit represents one port
* @untagged: each bit represents one port configured with @vid untagged
* @list: list structure
*/
struct vsc73xx_bridge_vlan {
u16 vid;
u8 portmask;
u8 untagged;
struct list_head list;
};
int vsc73xx_is_addr_valid(u8 block, u8 subblock);
int vsc73xx_probe(struct vsc73xx *vsc);
void vsc73xx_remove(struct vsc73xx *vsc);
......
......@@ -8,12 +8,18 @@
#include <net/dsa.h>
#include <linux/types.h>
/* VBID is limited to three bits only and zero is reserved.
* Only 7 bridges can be enumerated.
*/
#define DSA_TAG_8021Q_MAX_NUM_BRIDGES 7
int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto);
void dsa_tag_8021q_unregister(struct dsa_switch *ds);
int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,
struct dsa_bridge bridge);
struct dsa_bridge bridge, bool *tx_fwd_offload,
struct netlink_ext_ack *extack);
void dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, int port,
struct dsa_bridge bridge);
......
......@@ -53,6 +53,7 @@ struct tc_action;
#define DSA_TAG_PROTO_RTL8_4T_VALUE 25
#define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26
#define DSA_TAG_PROTO_LAN937X_VALUE 27
#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28
enum dsa_tag_protocol {
DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
......@@ -83,6 +84,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_RTL8_4T = DSA_TAG_PROTO_RTL8_4T_VALUE,
DSA_TAG_PROTO_RZN1_A5PSW = DSA_TAG_PROTO_RZN1_A5PSW_VALUE,
DSA_TAG_PROTO_LAN937X = DSA_TAG_PROTO_LAN937X_VALUE,
DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE,
};
struct dsa_switch;
......
......@@ -166,6 +166,12 @@ config NET_DSA_TAG_TRAILER
Say Y or M if you want to enable support for tagging frames at
with a trailed. e.g. Marvell 88E6060.
config NET_DSA_TAG_VSC73XX_8021Q
tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, using VLAN"
help
Say Y or M if you want to enable support for tagging frames with a
custom VLAN-based header.
config NET_DSA_TAG_XRS700X
tristate "Tag driver for XRS700x switches"
help
......
......@@ -37,6 +37,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) += tag_rtl8_4.o
obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o
obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
# for tracing framework to find trace.h
......
......@@ -286,7 +286,8 @@ int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
* be used for VLAN-unaware bridging.
*/
int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,
struct dsa_bridge bridge)
struct dsa_bridge bridge, bool *tx_fwd_offload,
struct netlink_ext_ack *extack)
{
struct dsa_port *dp = dsa_to_port(ds, port);
u16 standalone_vid, bridge_vid;
......@@ -304,6 +305,8 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,
dsa_port_tag_8021q_vlan_del(dp, standalone_vid, false);
*tx_fwd_offload = true;
return 0;
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_join);
......@@ -468,8 +471,8 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
}
EXPORT_SYMBOL_GPL(dsa_8021q_xmit);
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
int vbid)
static struct net_device *
dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid)
{
struct dsa_port *cpu_dp = conduit->dsa_ptr;
struct dsa_switch_tree *dst = cpu_dp->dst;
......@@ -495,30 +498,91 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
return NULL;
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid);
struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit,
int source_port, int switch_id,
int vid, int vbid)
{
/* Always prefer precise source port information, if available */
if (source_port != -1 && switch_id != -1)
return dsa_conduit_find_user(conduit, switch_id, source_port);
else if (vbid >= 1)
return dsa_tag_8021q_find_port_by_vbid(conduit, vbid);
return dsa_find_designated_bridge_port_by_vid(conduit, vid);
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_user);
/**
* dsa_8021q_rcv - Decode source information from tag_8021q header
* @skb: RX socket buffer
* @source_port: pointer to storage for precise source port information.
* If this is known already from outside tag_8021q, the pre-initialized
* value is preserved. If not known, pass -1.
* @switch_id: similar to source_port.
* @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized
* with -1. If a positive value is returned, the source_port and switch_id
* are invalid.
* @vid: pointer to storage for original VID, in case tag_8021q decoding failed.
*
* If the packet has a tag_8021q header, decode it and set @source_port,
* @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the
* header in the hwaccel area of the packet.
*/
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
int *vbid)
int *vbid, int *vid)
{
u16 vid, tci;
int tmp_source_port, tmp_switch_id, tmp_vbid;
__be16 vlan_proto;
u16 tmp_vid, tci;
if (skb_vlan_tag_present(skb)) {
vlan_proto = skb->vlan_proto;
tci = skb_vlan_tag_get(skb);
__vlan_hwaccel_clear_tag(skb);
} else {
struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
vlan_proto = hdr->h_vlan_proto;
skb_push_rcsum(skb, ETH_HLEN);
__skb_vlan_pop(skb, &tci);
skb_pull_rcsum(skb, ETH_HLEN);
}
vid = tci & VLAN_VID_MASK;
tmp_vid = tci & VLAN_VID_MASK;
if (!vid_is_dsa_8021q(tmp_vid)) {
/* Not a tag_8021q frame, so return the VID to the
* caller for further processing, and put the tag back
*/
if (vid)
*vid = tmp_vid;
__vlan_hwaccel_put_tag(skb, vlan_proto, tci);
return;
}
*source_port = dsa_8021q_rx_source_port(vid);
*switch_id = dsa_8021q_rx_switch_id(vid);
tmp_source_port = dsa_8021q_rx_source_port(tmp_vid);
tmp_switch_id = dsa_8021q_rx_switch_id(tmp_vid);
tmp_vbid = dsa_tag_8021q_rx_vbid(tmp_vid);
/* Precise source port information is unknown when receiving from a
* VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id
* are zeroes in this case.
*
* Preserve the source information from hardware-specific mechanisms,
* if available. This allows us to not overwrite a valid source port
* and switch ID with less precise values.
*/
if (tmp_vbid == 0 && *source_port == -1)
*source_port = tmp_source_port;
if (tmp_vbid == 0 && *switch_id == -1)
*switch_id = tmp_switch_id;
if (vbid)
*vbid = dsa_tag_8021q_rx_vbid(vid);
*vbid = tmp_vbid;
skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
return;
}
EXPORT_SYMBOL_GPL(dsa_8021q_rcv);
......@@ -14,10 +14,11 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
u16 tpid, u16 tci);
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
int *vbid);
int *vbid, int *vid);
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,
int vbid);
struct net_device *dsa_tag_8021q_find_user(struct net_device *conduit,
int source_port, int switch_id,
int vid, int vbid);
int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
struct dsa_notifier_tag_8021q_vlan_info *info);
......
......@@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
{
int src_port, switch_id;
dsa_8021q_rcv(skb, &src_port, &switch_id, NULL);
dsa_8021q_rcv(skb, &src_port, &switch_id, NULL, NULL);
skb->dev = dsa_conduit_find_user(netdev, switch_id, src_port);
if (!skb->dev)
......
......@@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb)
return ntohs(eth_hdr(skb)->h_proto) == ETH_P_SJA1110;
}
/* If the VLAN in the packet is a tag_8021q one, set @source_port and
* @switch_id and strip the header. Otherwise set @vid and keep it in the
* packet.
*/
static void sja1105_vlan_rcv(struct sk_buff *skb, int *source_port,
int *switch_id, int *vbid, u16 *vid)
{
struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
u16 vlan_tci;
if (skb_vlan_tag_present(skb))
vlan_tci = skb_vlan_tag_get(skb);
else
vlan_tci = ntohs(hdr->h_vlan_TCI);
if (vid_is_dsa_8021q(vlan_tci & VLAN_VID_MASK))
return dsa_8021q_rcv(skb, source_port, switch_id, vbid);
/* Try our best with imprecise RX */
*vid = vlan_tci & VLAN_VID_MASK;
}
static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
struct net_device *netdev)
{
int source_port = -1, switch_id = -1, vbid = -1;
int source_port = -1, switch_id = -1, vbid = -1, vid = -1;
struct sja1105_meta meta = {0};
struct ethhdr *hdr;
bool is_link_local;
bool is_meta;
u16 vid;
hdr = eth_hdr(skb);
is_link_local = sja1105_is_link_local(skb);
......@@ -524,37 +501,16 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
/* Normal data plane traffic and link-local frames are tagged with
* a tag_8021q VLAN which we have to strip
*/
if (sja1105_skb_has_tag_8021q(skb)) {
int tmp_source_port = -1, tmp_switch_id = -1;
sja1105_vlan_rcv(skb, &tmp_source_port, &tmp_switch_id, &vbid,
&vid);
/* Preserve the source information from the INCL_SRCPT option,
* if available. This allows us to not overwrite a valid source
* port and switch ID with zeroes when receiving link-local
* frames from a VLAN-unaware bridged port (non-zero vbid) or a
* VLAN-aware bridged port (non-zero vid). Furthermore, the
* tag_8021q source port information is only of trust when the
* vbid is 0 (precise port). Otherwise, tmp_source_port and
* tmp_switch_id will be zeroes.
*/
if (vbid == 0 && source_port == -1)
source_port = tmp_source_port;
if (vbid == 0 && switch_id == -1)
switch_id = tmp_switch_id;
} else if (source_port == -1 && switch_id == -1) {
if (sja1105_skb_has_tag_8021q(skb))
dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid);
else if (source_port == -1 && switch_id == -1)
/* Packets with no source information have no chance of
* getting accepted, drop them straight away.
*/
return NULL;
}
if (source_port != -1 && switch_id != -1)
skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port);
else if (vbid >= 1)
skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);
else
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id,
vid, vbid);
if (!skb->dev) {
netdev_warn(netdev, "Couldn't decode source port\n");
return NULL;
......@@ -677,9 +633,8 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb,
static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
struct net_device *netdev)
{
int source_port = -1, switch_id = -1, vbid = -1;
int source_port = -1, switch_id = -1, vbid = -1, vid = -1;
bool host_only = false;
u16 vid = 0;
if (sja1110_skb_has_inband_control_extension(skb)) {
skb = sja1110_rcv_inband_control_extension(skb, &source_port,
......@@ -691,14 +646,11 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,
/* Packets with in-band control extensions might still have RX VLANs */
if (likely(sja1105_skb_has_tag_8021q(skb)))
sja1105_vlan_rcv(skb, &source_port, &switch_id, &vbid, &vid);
if (vbid >= 1)
skb->dev = dsa_tag_8021q_find_port_by_vbid(netdev, vbid);
else if (source_port == -1 || switch_id == -1)
skb->dev = dsa_find_designated_bridge_port_by_vid(netdev, vid);
else
skb->dev = dsa_conduit_find_user(netdev, switch_id, source_port);
dsa_8021q_rcv(skb, &source_port, &switch_id, &vbid, &vid);
skb->dev = dsa_tag_8021q_find_user(netdev, source_port, switch_id,
vid, vbid);
if (!skb->dev) {
netdev_warn(netdev, "Couldn't decode source port\n");
return NULL;
......
// SPDX-License-Identifier: GPL-2.0 OR MIT
/* Copyright (C) 2024 Pawel Dembicki <paweldembicki@gmail.com>
*/
#include <linux/dsa/8021q.h>
#include "tag.h"
#include "tag_8021q.h"
#define VSC73XX_8021Q_NAME "vsc73xx-8021q"
static struct sk_buff *
vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
u16 queue_mapping = skb_get_queue_mapping(skb);
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
u8 pcp;
if (skb->offload_fwd_mark) {
unsigned int bridge_num = dsa_port_bridge_num_get(dp);
struct net_device *br = dsa_port_bridge_dev_get(dp);
if (br_vlan_enabled(br))
return skb;
tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
}
pcp = netdev_txq_to_tc(netdev, queue_mapping);
return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q,
((pcp << VLAN_PRIO_SHIFT) | tx_vid));
}
static struct sk_buff *
vsc73xx_rcv(struct sk_buff *skb, struct net_device *netdev)
{
int src_port = -1, switch_id = -1, vbid = -1, vid = -1;
dsa_8021q_rcv(skb, &src_port, &switch_id, &vbid, &vid);
skb->dev = dsa_tag_8021q_find_user(netdev, src_port, switch_id,
vid, vbid);
if (!skb->dev) {
dev_warn_ratelimited(&netdev->dev,
"Couldn't decode source port\n");
return NULL;
}
dsa_default_offload_fwd_mark(skb);
return skb;
}
static const struct dsa_device_ops vsc73xx_8021q_netdev_ops = {
.name = VSC73XX_8021Q_NAME,
.proto = DSA_TAG_PROTO_VSC73XX_8021Q,
.xmit = vsc73xx_xmit,
.rcv = vsc73xx_rcv,
.needed_headroom = VLAN_HLEN,
.promisc_on_conduit = true,
};
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("DSA tag driver for VSC73XX family of switches, using VLAN");
MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_VSC73XX_8021Q, VSC73XX_8021Q_NAME);
module_dsa_tag_driver(vsc73xx_8021q_netdev_ops);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment