diff mbox series

[net-next] net: ethernet: ti: am65-cpsw: VLAN-aware CPSW only if !DSA

Message ID 20250110092624.287209-1-alexander.sverdlin@siemens.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ethernet: ti: am65-cpsw: VLAN-aware CPSW only if !DSA | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: edumazet@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-01-10--12-00 (tests: 881)

Commit Message

A. Sverdlin Jan. 10, 2025, 9:26 a.m. UTC
From: Alexander Sverdlin <alexander.sverdlin@siemens.com>

Only configure VLAN-aware CPSW mode if no port is used as DSA CPU port.
VLAN-aware mode interferes with some DSA tagging schemes and makes stacking
DSA switches downstream of CPSW impossible. Previous attempts to address
the issue linked below.

Link: https://lore.kernel.org/netdev/20240227082815.2073826-1-s-vadapalli@ti.com/
Link: https://lore.kernel.org/linux-arm-kernel/4699400.vD3TdgH1nR@localhost/
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Siddharth Vadapalli Jan. 10, 2025, 10:41 a.m. UTC | #1
On Fri, Jan 10, 2025 at 10:26:21AM +0100, A. Sverdlin wrote:
> From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
> 
> Only configure VLAN-aware CPSW mode if no port is used as DSA CPU port.
> VLAN-aware mode interferes with some DSA tagging schemes and makes stacking
> DSA switches downstream of CPSW impossible. Previous attempts to address
> the issue linked below.
> 
> Link: https://lore.kernel.org/netdev/20240227082815.2073826-1-s-vadapalli@ti.com/
> Link: https://lore.kernel.org/linux-arm-kernel/4699400.vD3TdgH1nR@localhost/
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
> ---
>  drivers/net/ethernet/ti/am65-cpsw-nuss.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index dcb6662b473d..e445acb29e16 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -32,6 +32,7 @@
>  #include <linux/dma/ti-cppi5.h>
>  #include <linux/dma/k3-udma-glue.h>
>  #include <net/page_pool/helpers.h>
> +#include <net/dsa.h>
>  #include <net/switchdev.h>
>  
>  #include "cpsw_ale.h"
> @@ -724,13 +725,23 @@ static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)
>  	u32 val, port_mask;
>  	struct page *page;
>  
> +	/* Control register */
> +	val = AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE |
> +	      AM65_CPSW_CTL_P0_RX_PAD;
> +	for (port_idx = 0; port_idx < common->port_num; port_idx++) {
> +		struct am65_cpsw_port *port = &common->ports[port_idx];
> +
> +		if (netdev_uses_dsa(port->ndev))
> +			break;
> +	}
> +	/* VLAN aware CPSW mode is incompatible with some DSA tagging schemes */
> +	if (port_idx == common->port_num)
> +		val |= AM65_CPSW_CTL_VLAN_AWARE;
> +	writel(val, common->cpsw_base + AM65_CPSW_REG_CTL);
> +

Though it functionally enables VLAN_AWARE mode only when none of the ports
are a DSA port, the implementation and the comment appear inconsistent.
The comment states that VLAN aware CPSW mode is incompatible with DSA
and the lines following it are enabling VLAN_AWARE mode albeit for the
case where none of the ports are a DSA port. Since the IF condition
doesn't indicate that in an obvious manner, the implementation could be
improved to maintain consistency between what the comment states and what
the code does.

How about the following?
-------------------------------------------------------------------------
	/* Control register */
	val = AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE |
	      AM65_CPSW_CTL_VLAN_AWARE | AM65_CPSW_CTL_P0_RX_PAD;

	/* VLAN aware CPSW mode is incompatible with some DSA tagging
	 * schemes. Therefore disable VLAN_AWARE mode if any of the
	 * ports is a DSA Port.
	 */
	for (port_idx = 0; port_idx < common->port_num; port_idx++)
		if (netdev_uses_dsa(&common->ports[port_idx]->ndev)) {
			val &= ~AM65_CPSW_CTL_VLAN_AWARE;
			break;
		}

	writel(val, common->cpsw_base + AM65_CPSW_REG_CTL);
-------------------------------------------------------------------------

>  	if (common->usage_count)
>  		return 0;
>  
> -	/* Control register */
> -	writel(AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE |
> -	       AM65_CPSW_CTL_VLAN_AWARE | AM65_CPSW_CTL_P0_RX_PAD,
> -	       common->cpsw_base + AM65_CPSW_REG_CTL);
>  	/* Max length register */
>  	writel(AM65_CPSW_MAX_PACKET_SIZE,
>  	       host_p->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN);

Regards,
Siddharth.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index dcb6662b473d..e445acb29e16 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -32,6 +32,7 @@ 
 #include <linux/dma/ti-cppi5.h>
 #include <linux/dma/k3-udma-glue.h>
 #include <net/page_pool/helpers.h>
+#include <net/dsa.h>
 #include <net/switchdev.h>
 
 #include "cpsw_ale.h"
@@ -724,13 +725,23 @@  static int am65_cpsw_nuss_common_open(struct am65_cpsw_common *common)
 	u32 val, port_mask;
 	struct page *page;
 
+	/* Control register */
+	val = AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE |
+	      AM65_CPSW_CTL_P0_RX_PAD;
+	for (port_idx = 0; port_idx < common->port_num; port_idx++) {
+		struct am65_cpsw_port *port = &common->ports[port_idx];
+
+		if (netdev_uses_dsa(port->ndev))
+			break;
+	}
+	/* VLAN aware CPSW mode is incompatible with some DSA tagging schemes */
+	if (port_idx == common->port_num)
+		val |= AM65_CPSW_CTL_VLAN_AWARE;
+	writel(val, common->cpsw_base + AM65_CPSW_REG_CTL);
+
 	if (common->usage_count)
 		return 0;
 
-	/* Control register */
-	writel(AM65_CPSW_CTL_P0_ENABLE | AM65_CPSW_CTL_P0_TX_CRC_REMOVE |
-	       AM65_CPSW_CTL_VLAN_AWARE | AM65_CPSW_CTL_P0_RX_PAD,
-	       common->cpsw_base + AM65_CPSW_REG_CTL);
 	/* Max length register */
 	writel(AM65_CPSW_MAX_PACKET_SIZE,
 	       host_p->port_base + AM65_CPSW_PORT_REG_RX_MAXLEN);