diff mbox series

[net-next] net: ti: icssg-prueth: Make pa_stats optional

Message ID 20240905101739.44563-1-danishanwar@ti.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: ti: icssg-prueth: Make pa_stats optional | 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: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 98 exceeds 80 columns
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

Commit Message

MD Danish Anwar Sept. 5, 2024, 10:17 a.m. UTC
pa_stats is optional in dt bindings, make it optional in driver as well.
Currently if pa_stats syscon regmap is not found driver returns -ENODEV.
Fix this by not returning an error in case pa_stats is not found and
continue generating ethtool stats without pa_stats.

Fixes: 550ee90ac61c ("net: ti: icssg-prueth: Add support for PA Stats")
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
Cc: Jan Kiszka <jan.kiszka@siemens.com>
NOTE: This fix is targetted to net-next because the concerned commit is not
yet synced to net. So the issue isn't present in net.

 drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 17 ++++++++++-----
 drivers/net/ethernet/ti/icssg/icssg_prueth.c  |  4 +---
 drivers/net/ethernet/ti/icssg/icssg_stats.c   | 21 ++++++++++++-------
 3 files changed, 26 insertions(+), 16 deletions(-)


base-commit: 43b7724487109368363bb5cda034b3f600278d14

Comments

Andrew Lunn Sept. 5, 2024, 1:17 p.m. UTC | #1
On Thu, Sep 05, 2024 at 03:47:39PM +0530, MD Danish Anwar wrote:
> pa_stats is optional in dt bindings, make it optional in driver as well.
> Currently if pa_stats syscon regmap is not found driver returns -ENODEV.
> Fix this by not returning an error in case pa_stats is not found and
> continue generating ethtool stats without pa_stats.
> 
> Fixes: 550ee90ac61c ("net: ti: icssg-prueth: Add support for PA Stats")
> Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
> ---
> Cc: Jan Kiszka <jan.kiszka@siemens.com>
> NOTE: This fix is targetted to net-next because the concerned commit is not
> yet synced to net. So the issue isn't present in net.
> 
>  drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 17 ++++++++++-----
>  drivers/net/ethernet/ti/icssg/icssg_prueth.c  |  4 +---
>  drivers/net/ethernet/ti/icssg/icssg_stats.c   | 21 ++++++++++++-------
>  3 files changed, 26 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index 5073ec195854..b85c03172f68 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -68,9 +68,13 @@ static int emac_nway_reset(struct net_device *ndev)
>  
>  static int emac_get_sset_count(struct net_device *ndev, int stringset)
>  {
> +	struct prueth_emac *emac = netdev_priv(ndev);
>  	switch (stringset) {
>  	case ETH_SS_STATS:
> -		return ICSSG_NUM_ETHTOOL_STATS;
> +		if (IS_ERR(emac->prueth->pa_stats))

All these IS_ERR() are not so nice. What you often see is during
probe, if getting an optional resource returns an error, you replace
the error code with NULL. The code then becomes

> +		if (emac->prueth->pa_stats)
> +			return ICSSG_NUM_ETHTOOL_STATS;
> +		else
> +			return ICSSG_NUM_ETHTOOL_STATS - ICSSG_NUM_PA_STATS;

which looks nicer.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
index 5073ec195854..b85c03172f68 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
@@ -68,9 +68,13 @@  static int emac_nway_reset(struct net_device *ndev)
 
 static int emac_get_sset_count(struct net_device *ndev, int stringset)
 {
+	struct prueth_emac *emac = netdev_priv(ndev);
 	switch (stringset) {
 	case ETH_SS_STATS:
-		return ICSSG_NUM_ETHTOOL_STATS;
+		if (IS_ERR(emac->prueth->pa_stats))
+			return ICSSG_NUM_ETHTOOL_STATS - ICSSG_NUM_PA_STATS;
+		else
+			return ICSSG_NUM_ETHTOOL_STATS;
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -78,6 +82,7 @@  static int emac_get_sset_count(struct net_device *ndev, int stringset)
 
 static void emac_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
+	struct prueth_emac *emac = netdev_priv(ndev);
 	u8 *p = data;
 	int i;
 
@@ -86,8 +91,9 @@  static void emac_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 		for (i = 0; i < ARRAY_SIZE(icssg_all_miig_stats); i++)
 			if (!icssg_all_miig_stats[i].standard_stats)
 				ethtool_puts(&p, icssg_all_miig_stats[i].name);
-		for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
-			ethtool_puts(&p, icssg_all_pa_stats[i].name);
+		if (!IS_ERR(emac->prueth->pa_stats))
+			for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
+				ethtool_puts(&p, icssg_all_pa_stats[i].name);
 		break;
 	default:
 		break;
@@ -106,8 +112,9 @@  static void emac_get_ethtool_stats(struct net_device *ndev,
 		if (!icssg_all_miig_stats[i].standard_stats)
 			*(data++) = emac->stats[i];
 
-	for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
-		*(data++) = emac->pa_stats[i];
+	if (!IS_ERR(emac->prueth->pa_stats))
+		for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
+			*(data++) = emac->pa_stats[i];
 }
 
 static int emac_get_ts_info(struct net_device *ndev,
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index becdda143c19..2eba126b2a45 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -1183,10 +1183,8 @@  static int prueth_probe(struct platform_device *pdev)
 	}
 
 	prueth->pa_stats = syscon_regmap_lookup_by_phandle(np, "ti,pa-stats");
-	if (IS_ERR(prueth->pa_stats)) {
+	if (IS_ERR(prueth->pa_stats))
 		dev_err(dev, "couldn't get ti,pa-stats syscon regmap\n");
-		return -ENODEV;
-	}
 
 	if (eth0_node) {
 		ret = prueth_get_cores(prueth, ICSS_SLICE0, false);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.c b/drivers/net/ethernet/ti/icssg/icssg_stats.c
index 06a15c0b2acc..43d8b7c8c550 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_stats.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_stats.c
@@ -42,11 +42,14 @@  void emac_update_hardware_stats(struct prueth_emac *emac)
 			emac->stats[i] -= tx_pkt_cnt * 8;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++) {
-		reg = ICSSG_FW_STATS_BASE + icssg_all_pa_stats[i].offset *
-		      PRUETH_NUM_MACS + slice * sizeof(u32);
-		regmap_read(prueth->pa_stats, reg, &val);
-		emac->pa_stats[i] += val;
+	if (!IS_ERR(prueth->pa_stats)) {
+		for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++) {
+			reg = ICSSG_FW_STATS_BASE +
+			      icssg_all_pa_stats[i].offset *
+			      PRUETH_NUM_MACS + slice * sizeof(u32);
+			regmap_read(prueth->pa_stats, reg, &val);
+			emac->pa_stats[i] += val;
+		}
 	}
 }
 
@@ -70,9 +73,11 @@  int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name)
 			return emac->stats[icssg_all_miig_stats[i].offset / sizeof(u32)];
 	}
 
-	for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++) {
-		if (!strcmp(icssg_all_pa_stats[i].name, stat_name))
-			return emac->pa_stats[icssg_all_pa_stats[i].offset / sizeof(u32)];
+	if (!IS_ERR(emac->prueth->pa_stats)) {
+		for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++) {
+			if (!strcmp(icssg_all_pa_stats[i].name, stat_name))
+				return emac->pa_stats[icssg_all_pa_stats[i].offset / sizeof(u32)];
+		}
 	}
 
 	netdev_err(emac->ndev, "Invalid stats %s\n", stat_name);