lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240906093649.870883-1-danishanwar@ti.com>
Date: Fri, 6 Sep 2024 15:06:49 +0530
From: MD Danish Anwar <danishanwar@...com>
To: <saikrishnag@...vell.com>, <robh@...nel.org>, <jan.kiszka@...mens.com>,
        <dan.carpenter@...aro.org>, <diogo.ivo@...mens.com>,
        <kory.maincent@...tlin.com>, <hkallweit1@...il.com>, <andrew@...n.ch>,
        <pabeni@...hat.com>, <kuba@...nel.org>, <edumazet@...gle.com>,
        <davem@...emloft.net>
CC: <linux-kernel@...r.kernel.org>, <netdev@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>, <srk@...com>,
        Vignesh Raghavendra
	<vigneshr@...com>,
        Roger Quadros <rogerq@...nel.org>, <danishanwar@...com>
Subject: [PATCH net-next v2] net: ti: icssg-prueth: Make pa_stats optional

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@...com>
---
Cc: Jan Kiszka <jan.kiszka@...mens.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.

v1 -> v2
*) Replacing the error code returned for optional resource to NULL in probe and
simplified the if checks as suggested by Andrew Lunn <andrew@...n.ch>

v1 https://lore.kernel.org/all/20240905101739.44563-1-danishanwar@ti.com/

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

diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
index 5073ec195854..6b5cc1e6d64b 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 (emac->prueth->pa_stats)
+			return ICSSG_NUM_ETHTOOL_STATS;
+		else
+			return ICSSG_NUM_ETHTOOL_STATS - ICSSG_NUM_PA_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 (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 (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..6644203d6bb7 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -1185,7 +1185,7 @@ 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)) {
 		dev_err(dev, "couldn't get ti,pa-stats syscon regmap\n");
-		return -ENODEV;
+		prueth->pa_stats = NULL;
 	}
 
 	if (eth0_node) {
diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.c b/drivers/net/ethernet/ti/icssg/icssg_stats.c
index 06a15c0b2acc..8800bd3a8d07 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 (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 (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);

base-commit: 43b7724487109368363bb5cda034b3f600278d14
-- 
2.34.1


Powered by blists - more mailing lists