diff mbox series

[net-next,v2] net: dsa: mt7530: fix tagged frames pass-through in VLAN-unaware mode

Message ID 20200414063408.4026-1-dqfext@gmail.com (mailing list archive)
State New, archived
Headers show
Series [net-next,v2] net: dsa: mt7530: fix tagged frames pass-through in VLAN-unaware mode | expand

Commit Message

Qingfang Deng April 14, 2020, 6:34 a.m. UTC
In VLAN-unaware mode, the Egress Tag (EG_TAG) field in Port VLAN
Control register must be set to Consistent to let tagged frames pass
through as is, otherwise their tags will be stripped.

Fixes: 83163f7dca56 ("net: dsa: mediatek: add VLAN support for MT7530")
Signed-off-by: DENG Qingfang <dqfext@gmail.com>
---
Changes since v1:
- Fix build error

---
 drivers/net/dsa/mt7530.c | 18 ++++++++++++------
 drivers/net/dsa/mt7530.h |  7 +++++++
 2 files changed, 19 insertions(+), 6 deletions(-)

Comments

Florian Fainelli April 15, 2020, 7:36 p.m. UTC | #1
On 4/13/2020 11:34 PM, DENG Qingfang wrote:
> In VLAN-unaware mode, the Egress Tag (EG_TAG) field in Port VLAN
> Control register must be set to Consistent to let tagged frames pass
> through as is, otherwise their tags will be stripped.
> 
> Fixes: 83163f7dca56 ("net: dsa: mediatek: add VLAN support for MT7530")
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
René van Dorst April 16, 2020, 6:10 a.m. UTC | #2
Hi Qingfang,


Quoting DENG Qingfang <dqfext@gmail.com>:

> In VLAN-unaware mode, the Egress Tag (EG_TAG) field in Port VLAN
> Control register must be set to Consistent to let tagged frames pass
> through as is, otherwise their tags will be stripped.

Thanks for fixing the vlan issues!

Tested-by: René van Dorst <opensource@vdorst.com>

Greats,

René
>
> Fixes: 83163f7dca56 ("net: dsa: mediatek: add VLAN support for MT7530")
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>
> ---
> Changes since v1:
> - Fix build error
>
> ---
>  drivers/net/dsa/mt7530.c | 18 ++++++++++++------
>  drivers/net/dsa/mt7530.h |  7 +++++++
>  2 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 2d0d91db0ddb..951a65ac7f73 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -846,8 +846,9 @@ mt7530_port_set_vlan_unaware(struct dsa_switch  
> *ds, int port)
>  	 */
>  	mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK,
>  		   MT7530_PORT_MATRIX_MODE);
> -	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK,
> -		   VLAN_ATTR(MT7530_VLAN_TRANSPARENT));
> +	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK,
> +		   VLAN_ATTR(MT7530_VLAN_TRANSPARENT) |
> +		   PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
>
>  	for (i = 0; i < MT7530_NUM_PORTS; i++) {
>  		if (dsa_is_user_port(ds, i) &&
> @@ -863,8 +864,8 @@ mt7530_port_set_vlan_unaware(struct dsa_switch  
> *ds, int port)
>  	if (all_user_ports_removed) {
>  		mt7530_write(priv, MT7530_PCR_P(MT7530_CPU_PORT),
>  			     PCR_MATRIX(dsa_user_ports(priv->ds)));
> -		mt7530_write(priv, MT7530_PVC_P(MT7530_CPU_PORT),
> -			     PORT_SPEC_TAG);
> +		mt7530_write(priv, MT7530_PVC_P(MT7530_CPU_PORT), PORT_SPEC_TAG
> +			     | PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
>  	}
>  }
>
> @@ -890,8 +891,9 @@ mt7530_port_set_vlan_aware(struct dsa_switch  
> *ds, int port)
>  	/* Set the port as a user port which is to be able to recognize VID
>  	 * from incoming packets before fetching entry within the VLAN table.
>  	 */
> -	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK,
> -		   VLAN_ATTR(MT7530_VLAN_USER));
> +	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK,
> +		   VLAN_ATTR(MT7530_VLAN_USER) |
> +		   PVC_EG_TAG(MT7530_VLAN_EG_DISABLED));
>  }
>
>  static void
> @@ -1380,6 +1382,10 @@ mt7530_setup(struct dsa_switch *ds)
>  			mt7530_cpu_port_enable(priv, i);
>  		else
>  			mt7530_port_disable(ds, i);
> +
> +		/* Enable consistent egress tag */
> +		mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK,
> +			   PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
>  	}
>
>  	/* Setup port 5 */
> diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
> index ef9b52f3152b..2528232d3325 100644
> --- a/drivers/net/dsa/mt7530.h
> +++ b/drivers/net/dsa/mt7530.h
> @@ -172,9 +172,16 @@ enum mt7530_port_mode {
>  /* Register for port vlan control */
>  #define MT7530_PVC_P(x)			(0x2010 + ((x) * 0x100))
>  #define  PORT_SPEC_TAG			BIT(5)
> +#define  PVC_EG_TAG(x)			(((x) & 0x7) << 8)
> +#define  PVC_EG_TAG_MASK		PVC_EG_TAG(7)
>  #define  VLAN_ATTR(x)			(((x) & 0x3) << 6)
>  #define  VLAN_ATTR_MASK			VLAN_ATTR(3)
>
> +enum mt7530_vlan_port_eg_tag {
> +	MT7530_VLAN_EG_DISABLED = 0,
> +	MT7530_VLAN_EG_CONSISTENT = 1,
> +};
> +
>  enum mt7530_vlan_port_attr {
>  	MT7530_VLAN_USER = 0,
>  	MT7530_VLAN_TRANSPARENT = 3,
> --
> 2.26.0
David Miller April 16, 2020, 8:32 p.m. UTC | #3
From: DENG Qingfang <dqfext@gmail.com>
Date: Tue, 14 Apr 2020 14:34:08 +0800

> In VLAN-unaware mode, the Egress Tag (EG_TAG) field in Port VLAN
> Control register must be set to Consistent to let tagged frames pass
> through as is, otherwise their tags will be stripped.
> 
> Fixes: 83163f7dca56 ("net: dsa: mediatek: add VLAN support for MT7530")
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>

Applied and queued up for -stable, thanks.
diff mbox series

Patch

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 2d0d91db0ddb..951a65ac7f73 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -846,8 +846,9 @@  mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)
 	 */
 	mt7530_rmw(priv, MT7530_PCR_P(port), PCR_PORT_VLAN_MASK,
 		   MT7530_PORT_MATRIX_MODE);
-	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK,
-		   VLAN_ATTR(MT7530_VLAN_TRANSPARENT));
+	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK,
+		   VLAN_ATTR(MT7530_VLAN_TRANSPARENT) |
+		   PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
 
 	for (i = 0; i < MT7530_NUM_PORTS; i++) {
 		if (dsa_is_user_port(ds, i) &&
@@ -863,8 +864,8 @@  mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)
 	if (all_user_ports_removed) {
 		mt7530_write(priv, MT7530_PCR_P(MT7530_CPU_PORT),
 			     PCR_MATRIX(dsa_user_ports(priv->ds)));
-		mt7530_write(priv, MT7530_PVC_P(MT7530_CPU_PORT),
-			     PORT_SPEC_TAG);
+		mt7530_write(priv, MT7530_PVC_P(MT7530_CPU_PORT), PORT_SPEC_TAG
+			     | PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
 	}
 }
 
@@ -890,8 +891,9 @@  mt7530_port_set_vlan_aware(struct dsa_switch *ds, int port)
 	/* Set the port as a user port which is to be able to recognize VID
 	 * from incoming packets before fetching entry within the VLAN table.
 	 */
-	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK,
-		   VLAN_ATTR(MT7530_VLAN_USER));
+	mt7530_rmw(priv, MT7530_PVC_P(port), VLAN_ATTR_MASK | PVC_EG_TAG_MASK,
+		   VLAN_ATTR(MT7530_VLAN_USER) |
+		   PVC_EG_TAG(MT7530_VLAN_EG_DISABLED));
 }
 
 static void
@@ -1380,6 +1382,10 @@  mt7530_setup(struct dsa_switch *ds)
 			mt7530_cpu_port_enable(priv, i);
 		else
 			mt7530_port_disable(ds, i);
+
+		/* Enable consistent egress tag */
+		mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK,
+			   PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT));
 	}
 
 	/* Setup port 5 */
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index ef9b52f3152b..2528232d3325 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -172,9 +172,16 @@  enum mt7530_port_mode {
 /* Register for port vlan control */
 #define MT7530_PVC_P(x)			(0x2010 + ((x) * 0x100))
 #define  PORT_SPEC_TAG			BIT(5)
+#define  PVC_EG_TAG(x)			(((x) & 0x7) << 8)
+#define  PVC_EG_TAG_MASK		PVC_EG_TAG(7)
 #define  VLAN_ATTR(x)			(((x) & 0x3) << 6)
 #define  VLAN_ATTR_MASK			VLAN_ATTR(3)
 
+enum mt7530_vlan_port_eg_tag {
+	MT7530_VLAN_EG_DISABLED = 0,
+	MT7530_VLAN_EG_CONSISTENT = 1,
+};
+
 enum mt7530_vlan_port_attr {
 	MT7530_VLAN_USER = 0,
 	MT7530_VLAN_TRANSPARENT = 3,