Skip to content

Commit e4a85c5

Browse files
committed
Merge branch 'net-dsa-b53-Configure-VLANs-while-not-filtering'
Florian Fainelli says: ==================== net: dsa: b53: Configure VLANs while not filtering These two patches allow the b53 driver which always configures its CPU port as egress tagged to behave correctly with VLANs being always configured whenever a port is added to a bridge. Vladimir provides a patch that aligns the bridge with vlan_filtering=0 receive path to behave the same as vlan_filtering=1. Per discussion with Nikolay, this behavior is deemed to be too DSA specific to be done in the bridge proper. This is a preliminary series for Vladimir to make configure_vlan_while_filtering the default behavior for all DSA drivers in the future. Thanks! Changes in v3: - added Vladimir's Acked-by tag to patch #2 - removed unnecessary if_vlan.h inclusion in patch #2 - reworded commit message to be accurate with the code changes Changes in v2: - moved the call to dsa_untag_bridge_pvid() into net/dsa/tag_brcm.c since we have a single user for now ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e0da743 + ed409f3 commit e4a85c5

File tree

4 files changed

+81
-20
lines changed

4 files changed

+81
-20
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,23 +1377,6 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);
13771377
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
13781378
{
13791379
struct b53_device *dev = ds->priv;
1380-
u16 pvid, new_pvid;
1381-
1382-
b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1383-
if (!vlan_filtering) {
1384-
/* Filtering is currently enabled, use the default PVID since
1385-
* the bridge does not expect tagging anymore
1386-
*/
1387-
dev->ports[port].pvid = pvid;
1388-
new_pvid = b53_default_pvid(dev);
1389-
} else {
1390-
/* Filtering is currently disabled, restore the previous PVID */
1391-
new_pvid = dev->ports[port].pvid;
1392-
}
1393-
1394-
if (pvid != new_pvid)
1395-
b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1396-
new_pvid);
13971380

13981381
b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
13991382

@@ -2619,6 +2602,8 @@ struct b53_device *b53_switch_alloc(struct device *base,
26192602
dev->priv = priv;
26202603
dev->ops = ops;
26212604
ds->ops = &b53_switch_ops;
2605+
ds->configure_vlan_while_not_filtering = true;
2606+
dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
26222607
mutex_init(&dev->reg_mutex);
26232608
mutex_init(&dev->stats_mutex);
26242609

drivers/net/dsa/b53/b53_priv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ enum {
9191
struct b53_port {
9292
u16 vlan_ctl_mask;
9393
struct ethtool_eee eee;
94-
u16 pvid;
9594
};
9695

9796
struct b53_vlan {

net/dsa/dsa_priv.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef __DSA_PRIV_H
88
#define __DSA_PRIV_H
99

10+
#include <linux/if_bridge.h>
1011
#include <linux/phy.h>
1112
#include <linux/netdevice.h>
1213
#include <linux/netpoll.h>
@@ -194,6 +195,71 @@ dsa_slave_to_master(const struct net_device *dev)
194195
return dp->cpu_dp->master;
195196
}
196197

198+
/* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
199+
* frames as untagged, since the bridge will not untag them.
200+
*/
201+
static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
202+
{
203+
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
204+
struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
205+
struct net_device *br = dp->bridge_dev;
206+
struct net_device *dev = skb->dev;
207+
struct net_device *upper_dev;
208+
struct list_head *iter;
209+
u16 vid, pvid, proto;
210+
int err;
211+
212+
if (!br || br_vlan_enabled(br))
213+
return skb;
214+
215+
err = br_vlan_get_proto(br, &proto);
216+
if (err)
217+
return skb;
218+
219+
/* Move VLAN tag from data to hwaccel */
220+
if (!skb_vlan_tag_present(skb) && hdr->h_vlan_proto == htons(proto)) {
221+
skb = skb_vlan_untag(skb);
222+
if (!skb)
223+
return NULL;
224+
}
225+
226+
if (!skb_vlan_tag_present(skb))
227+
return skb;
228+
229+
vid = skb_vlan_tag_get_id(skb);
230+
231+
/* We already run under an RCU read-side critical section since
232+
* we are called from netif_receive_skb_list_internal().
233+
*/
234+
err = br_vlan_get_pvid_rcu(dev, &pvid);
235+
if (err)
236+
return skb;
237+
238+
if (vid != pvid)
239+
return skb;
240+
241+
/* The sad part about attempting to untag from DSA is that we
242+
* don't know, unless we check, if the skb will end up in
243+
* the bridge's data path - br_allowed_ingress() - or not.
244+
* For example, there might be an 8021q upper for the
245+
* default_pvid of the bridge, which will steal VLAN-tagged traffic
246+
* from the bridge's data path. This is a configuration that DSA
247+
* supports because vlan_filtering is 0. In that case, we should
248+
* definitely keep the tag, to make sure it keeps working.
249+
*/
250+
netdev_for_each_upper_dev_rcu(dev, upper_dev, iter) {
251+
if (!is_vlan_dev(upper_dev))
252+
continue;
253+
254+
if (vid == vlan_dev_vlan_id(upper_dev))
255+
return skb;
256+
}
257+
258+
__vlan_hwaccel_clear_tag(skb);
259+
260+
return skb;
261+
}
262+
197263
/* switch.c */
198264
int dsa_switch_register_notifier(struct dsa_switch *ds);
199265
void dsa_switch_unregister_notifier(struct dsa_switch *ds);

net/dsa/tag_brcm.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
140140
/* Remove Broadcom tag and update checksum */
141141
skb_pull_rcsum(skb, BRCM_TAG_LEN);
142142

143+
/* Set the MAC header to where it should point for
144+
* dsa_untag_bridge_pvid() to parse the correct VLAN header.
145+
*/
146+
skb_set_mac_header(skb, -ETH_HLEN);
147+
143148
skb->offload_fwd_mark = 1;
144149

145150
return skb;
@@ -191,7 +196,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
191196
nskb->data - ETH_HLEN - BRCM_TAG_LEN,
192197
2 * ETH_ALEN);
193198

194-
return nskb;
199+
return dsa_untag_bridge_pvid(nskb);
195200
}
196201

197202
static const struct dsa_device_ops brcm_netdev_ops = {
@@ -219,8 +224,14 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
219224
struct net_device *dev,
220225
struct packet_type *pt)
221226
{
227+
struct sk_buff *nskb;
228+
222229
/* tag is prepended to the packet */
223-
return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
230+
nskb = brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
231+
if (!nskb)
232+
return nskb;
233+
234+
return dsa_untag_bridge_pvid(nskb);
224235
}
225236

226237
static const struct dsa_device_ops brcm_prepend_netdev_ops = {

0 commit comments

Comments
 (0)