This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM6442: Network with CPSW depends on debugfs

Part Number: AM6442

Hi !

I've hit a bug in the 5.10 kernel (in ti-linux-5.10.y branch) : when the CPSW ethernet driver is initialized, it tries to create debugfs entries. If debugfs is disabled then init fails and you lose network interfaces.

This is a bit difficult to diagnose when you're cleaning kernel config, because debugfs and cpsw relationship is not obvious at all.

The culprit is

commit a986420e81a74c8c1f9502ff544932b09cb78bbe
Author: Grygorii Strashko <grygorii.strashko@ti.com>
Date: Fri Mar 26 02:03:57 2021 +0200

HACK: net: ethernet: ti: am65-cpsw-nuss: add debugfs to cfg cut-thru params

Here is a patch that fixes the issue :

From 8ee44d11fa859ec08ae55a96bf90b51f9a7544b2 Mon Sep 17 00:00:00 2001
From: Remi Peuvergne <remi.peuvergne@smile.fr>
Date: Wed, 6 Apr 2022 10:46:24 +0200
Subject: [PATCH] CPSW: Fix dependency to debugfs

If debugfs is disabled, init fails (calls to debugfs API return -ENODEV).
We should avoid calling debugfs init if it's disabled.

Also skip building am65-debugfs if debugfs is disabled.
---
 drivers/net/ethernet/ti/Makefile         | 3 ++-
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/Makefile b/drivers/net/ethernet/ti/Makefile
index 72731bdcc4c4..c554109460f3 100644
--- a/drivers/net/ethernet/ti/Makefile
+++ b/drivers/net/ethernet/ti/Makefile
@@ -25,7 +25,8 @@ obj-$(CONFIG_TI_KEYSTONE_NETCP_ETHSS) += keystone_netcp_ethss.o
 keystone_netcp_ethss-y := netcp_ethss.o netcp_sgmii.o netcp_xgbepcsr.o cpsw_ale.o
 
 obj-$(CONFIG_TI_K3_AM65_CPSW_NUSS) += ti-am65-cpsw-nuss.o
-ti-am65-cpsw-nuss-y := am65-cpsw-nuss.o cpsw_sl.o am65-cpsw-ethtool.o cpsw_ale.o k3-cppi-desc-pool.o am65-cpsw-qos.o am65-debugfs.o
+ti-am65-cpsw-nuss-y := am65-cpsw-nuss.o cpsw_sl.o am65-cpsw-ethtool.o cpsw_ale.o k3-cppi-desc-pool.o am65-cpsw-qos.o
+obj-$(CONFIG_DEBUG_FS) += am65-debugfs.o
 ti-am65-cpsw-nuss-$(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV) += am65-cpsw-switchdev.o
 obj-$(CONFIG_TI_K3_AM65_CPTS) += am65-cpts.o
 
diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 047d0e690fa4..0fbd63014f26 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -2623,9 +2623,11 @@ static int am65_cpsw_nuss_register_ndevs(struct am65_cpsw_common *common)
 	for (i = 0; i < common->port_num; i++) {
 		port = &common->ports[i];
 
+#ifdef CONFIG_DEBUG_FS
 		ret = am65_cpsw_nuss_register_port_debugfs(port);
 		if (ret)
 			goto err_cleanup_ndev;
+#endif
 
 		if (!port->ndev)
 			continue;
@@ -2857,13 +2859,17 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_of_clear;
 
+#ifdef CONFIG_DEBUG_FS
 	ret = am65_cpsw_nuss_register_debugfs(common);
 	if (ret)
 		goto err_of_clear;
+#endif
 
 	ret = am65_cpsw_nuss_register_ndevs(common);
 	if (ret) {
+#ifdef CONFIG_DEBUG_FS
 		am65_cpsw_nuss_unregister_debugfs(common);
+#endif
 		goto err_of_clear;
 	}
 
-- 
2.35.1