diff mbox series

[net-next,v2,2/2] net: dsa: b53: Configure VLANs while not filtering

Message ID 20200923204514.3663635-3-f.fainelli@gmail.com
State New
Headers show
Series net: dsa: b53: Configure VLANs while not filtering | expand

Commit Message

Florian Fainelli Sept. 23, 2020, 8:45 p.m. UTC
Update the B53 driver to support VLANs while not filtering. This
requires us to enable VLAN globally within the switch upon driver
initial configuration (dev->vlan_enabled).

We also need to remove the code that dealt with PVID re-configuration in
b53_vlan_filtering() since that function worked under the assumption
that it would only be called to make a bridge VLAN filtering, or not
filtering, and we would attempt to move the port's PVID accordingly.

Now that VLANs are programmed all the time, even in the case of a
non-VLAN filtering bridge, we would be programming a default_pvid for
the bridged switch ports.

We need the DSA receive path to pop the VLAN tag if it is the bridge's
default_pvid because the CPU port is always programmed tagged in the
programmed VLANs. In order to do so we utilize the
dsa_untag_bridge_pvid() helper introduced in the commit before by
setting ds->untag_bridge_pvid to true.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 19 ++-----------------
 drivers/net/dsa/b53/b53_priv.h   |  1 -
 net/dsa/tag_brcm.c               | 16 ++++++++++++++--
 3 files changed, 16 insertions(+), 20 deletions(-)

Comments

Vladimir Oltean Sept. 23, 2020, 9:23 p.m. UTC | #1
On Wed, Sep 23, 2020 at 01:45:14PM -0700, Florian Fainelli wrote:
> Update the B53 driver to support VLANs while not filtering. This

> requires us to enable VLAN globally within the switch upon driver

> initial configuration (dev->vlan_enabled).

> 

> We also need to remove the code that dealt with PVID re-configuration in

> b53_vlan_filtering() since that function worked under the assumption

> that it would only be called to make a bridge VLAN filtering, or not

> filtering, and we would attempt to move the port's PVID accordingly.

> 

> Now that VLANs are programmed all the time, even in the case of a

> non-VLAN filtering bridge, we would be programming a default_pvid for

> the bridged switch ports.

> 

> We need the DSA receive path to pop the VLAN tag if it is the bridge's

> default_pvid because the CPU port is always programmed tagged in the

> programmed VLANs. In order to do so we utilize the

> dsa_untag_bridge_pvid() helper introduced in the commit before by

> setting ds->untag_bridge_pvid to true.

> 

> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

> ---


Acked-by: Vladimir Oltean <vladimir.oltean@nxp.com>


>  drivers/net/dsa/b53/b53_common.c | 19 ++-----------------

>  drivers/net/dsa/b53/b53_priv.h   |  1 -

>  net/dsa/tag_brcm.c               | 16 ++++++++++++++--

>  3 files changed, 16 insertions(+), 20 deletions(-)

> 

> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c

> index 6a5796c32721..73507cff3bc4 100644

> --- a/drivers/net/dsa/b53/b53_common.c

> +++ b/drivers/net/dsa/b53/b53_common.c

> @@ -1377,23 +1377,6 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);

>  int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)

>  {

>  	struct b53_device *dev = ds->priv;

> -	u16 pvid, new_pvid;

> -

> -	b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);

> -	if (!vlan_filtering) {

> -		/* Filtering is currently enabled, use the default PVID since

> -		 * the bridge does not expect tagging anymore

> -		 */

> -		dev->ports[port].pvid = pvid;

> -		new_pvid = b53_default_pvid(dev);

> -	} else {

> -		/* Filtering is currently disabled, restore the previous PVID */

> -		new_pvid = dev->ports[port].pvid;

> -	}

> -

> -	if (pvid != new_pvid)

> -		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),

> -			    new_pvid);

>  

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

>  

> @@ -2619,6 +2602,8 @@ struct b53_device *b53_switch_alloc(struct device *base,

>  	dev->priv = priv;

>  	dev->ops = ops;

>  	ds->ops = &b53_switch_ops;

> +	ds->configure_vlan_while_not_filtering = true;

> +	dev->vlan_enabled = ds->configure_vlan_while_not_filtering;

>  	mutex_init(&dev->reg_mutex);

>  	mutex_init(&dev->stats_mutex);

>  

> diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h

> index c55c0a9f1b47..24893b592216 100644

> --- a/drivers/net/dsa/b53/b53_priv.h

> +++ b/drivers/net/dsa/b53/b53_priv.h

> @@ -91,7 +91,6 @@ enum {

>  struct b53_port {

>  	u16		vlan_ctl_mask;

>  	struct ethtool_eee eee;

> -	u16		pvid;

>  };

>  

>  struct b53_vlan {

> diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c

> index cc8512b5f9e2..703770161738 100644

> --- a/net/dsa/tag_brcm.c

> +++ b/net/dsa/tag_brcm.c

> @@ -7,6 +7,7 @@

>  

>  #include <linux/etherdevice.h>

>  #include <linux/list.h>

> +#include <linux/if_vlan.h>

>  #include <linux/slab.h>

>  

>  #include "dsa_priv.h"

> @@ -140,6 +141,11 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,

>  	/* Remove Broadcom tag and update checksum */

>  	skb_pull_rcsum(skb, BRCM_TAG_LEN);

>  

> +	/* Set the MAC header to where it should point for

> +	 * dsa_untag_bridge_pvid() to parse the correct VLAN header.

> +	 */

> +	skb_set_mac_header(skb, -ETH_HLEN);

> +

>  	skb->offload_fwd_mark = 1;

>  

>  	return skb;

> @@ -191,7 +197,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,

>  		nskb->data - ETH_HLEN - BRCM_TAG_LEN,

>  		2 * ETH_ALEN);

>  

> -	return nskb;

> +	return dsa_untag_bridge_pvid(nskb);

>  }

>  

>  static const struct dsa_device_ops brcm_netdev_ops = {

> @@ -219,8 +225,14 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,

>  					    struct net_device *dev,

>  					    struct packet_type *pt)

>  {

> +	struct sk_buff *nskb;

> +

>  	/* tag is prepended to the packet */

> -	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);

> +	nskb = brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);

> +	if (!nskb)

> +		return nskb;

> +

> +	return dsa_untag_bridge_pvid(nskb);

>  }

>  

>  static const struct dsa_device_ops brcm_prepend_netdev_ops = {

> -- 

> 2.25.1

>
diff mbox series

Patch

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 6a5796c32721..73507cff3bc4 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1377,23 +1377,6 @@  EXPORT_SYMBOL(b53_phylink_mac_link_up);
 int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
 {
 	struct b53_device *dev = ds->priv;
-	u16 pvid, new_pvid;
-
-	b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
-	if (!vlan_filtering) {
-		/* Filtering is currently enabled, use the default PVID since
-		 * the bridge does not expect tagging anymore
-		 */
-		dev->ports[port].pvid = pvid;
-		new_pvid = b53_default_pvid(dev);
-	} else {
-		/* Filtering is currently disabled, restore the previous PVID */
-		new_pvid = dev->ports[port].pvid;
-	}
-
-	if (pvid != new_pvid)
-		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
-			    new_pvid);
 
 	b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
 
@@ -2619,6 +2602,8 @@  struct b53_device *b53_switch_alloc(struct device *base,
 	dev->priv = priv;
 	dev->ops = ops;
 	ds->ops = &b53_switch_ops;
+	ds->configure_vlan_while_not_filtering = true;
+	dev->vlan_enabled = ds->configure_vlan_while_not_filtering;
 	mutex_init(&dev->reg_mutex);
 	mutex_init(&dev->stats_mutex);
 
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index c55c0a9f1b47..24893b592216 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -91,7 +91,6 @@  enum {
 struct b53_port {
 	u16		vlan_ctl_mask;
 	struct ethtool_eee eee;
-	u16		pvid;
 };
 
 struct b53_vlan {
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index cc8512b5f9e2..703770161738 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -7,6 +7,7 @@ 
 
 #include <linux/etherdevice.h>
 #include <linux/list.h>
+#include <linux/if_vlan.h>
 #include <linux/slab.h>
 
 #include "dsa_priv.h"
@@ -140,6 +141,11 @@  static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 	/* Remove Broadcom tag and update checksum */
 	skb_pull_rcsum(skb, BRCM_TAG_LEN);
 
+	/* Set the MAC header to where it should point for
+	 * dsa_untag_bridge_pvid() to parse the correct VLAN header.
+	 */
+	skb_set_mac_header(skb, -ETH_HLEN);
+
 	skb->offload_fwd_mark = 1;
 
 	return skb;
@@ -191,7 +197,7 @@  static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 		nskb->data - ETH_HLEN - BRCM_TAG_LEN,
 		2 * ETH_ALEN);
 
-	return nskb;
+	return dsa_untag_bridge_pvid(nskb);
 }
 
 static const struct dsa_device_ops brcm_netdev_ops = {
@@ -219,8 +225,14 @@  static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 					    struct net_device *dev,
 					    struct packet_type *pt)
 {
+	struct sk_buff *nskb;
+
 	/* tag is prepended to the packet */
-	return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
+	nskb = brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
+	if (!nskb)
+		return nskb;
+
+	return dsa_untag_bridge_pvid(nskb);
 }
 
 static const struct dsa_device_ops brcm_prepend_netdev_ops = {