Skip to contentSkip to conversation

ethtool : added get_phy_stats,get_strings,get_sset_count

PATCH In review Thomas Scariah 4 participants 6 messages Mar 27, 2017 – Mar 28, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethtool : added get_phy_stats,get_strings,get_sset_count

From: "Scariah, Thomas" <[email protected]>

Added functions to support ethtool to print the phy statistics and error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer. This is an enahancement for ethtool to accommodate phy statistics

---
 drivers/net/ethernet/ti/cpsw.c |   16 ++++++++++++-
 drivers/net/phy/micrel.c       |   50 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c          |   23 ++++++++++++++++++
 include/linux/phy.h            |   14 +++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
drivers/net/ethernet/ti/cpsw.c +15 -1
index 3f48bb9..26d2dc5 100644
@@ -1001,9 +1001,16 @@ update_return:
 
 static int cpsw_get_sset_count(struct net_device *ndev, int sset)
 {
+	struct cpsw_priv *priv = netdev_priv(ndev);
+	int slave_no = cpsw_slave_index(priv);
+	int count;
+
 	switch (sset) {
 	case ETH_SS_STATS:
-		return CPSW_STATS_LEN;
+		count = CPSW_STATS_LEN;
+		count += phy_ethtool_get_sset_count(priv->slaves[slave_no].phy,
+						    sset);
+		return count;
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -1011,6 +1018,8 @@ static int cpsw_get_sset_count(struct net_device *ndev, int sset)
 
 static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
+	struct cpsw_priv *priv = netdev_priv(ndev);
+	int slave_no = cpsw_slave_index(priv);
 	u8 *p = data;
 	int i;
 
@@ -1021,6 +1030,8 @@ static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 			       ETH_GSTRING_LEN);
 			p += ETH_GSTRING_LEN;
 		}
+		phy_ethtool_get_strings(priv->slaves[slave_no].phy,
+					stringset, p);
 		break;
 	}
 }
@@ -1031,6 +1042,7 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev,
 	struct cpsw_priv *priv = netdev_priv(ndev);
 	struct cpdma_chan_stats rx_stats;
 	struct cpdma_chan_stats tx_stats;
+	int slave_no = cpsw_slave_index(priv);
 	u32 val;
 	u8 *p;
 	int i, ret;
@@ -1067,6 +1079,8 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev,
 		}
 	}
 
+	phy_ethtool_get_stats(priv->slaves[slave_no].phy, stats,
+			      &data[CPSW_STATS_LEN]);
 	pm_runtime_put(&priv->pdev->dev);
 }
 
drivers/net/phy/micrel.c +50 -0

62 lines not on this page · raw message

drivers/net/phy/phy.c +23 -0
index 47cd306..25b66cd 100644
@@ -1262,3 +1262,26 @@ void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol)
 		phydev->drv->get_wol(phydev, wol);
 }
 EXPORT_SYMBOL(phy_ethtool_get_wol);
+
+int phy_ethtool_get_sset_count(struct phy_device *phydev, int sset)
+{
+	if (phydev->drv->get_sset_count)
+		return phydev->drv->get_sset_count(phydev, sset);
+	return 0;
+}
+EXPORT_SYMBOL(phy_ethtool_get_sset_count);
+
+void phy_ethtool_get_strings(struct phy_device *phydev, u32 stringset, u8 *data)
+{
+	if (phydev->drv->get_strings)
+		phydev->drv->get_strings(phydev, stringset, data);
+}
+EXPORT_SYMBOL(phy_ethtool_get_strings);
+
+void phy_ethtool_get_stats(struct phy_device *phydev,
+			   struct ethtool_stats *stats, u64 *data)
+{
+	if (phydev->drv->get_phy_stats)
+		phydev->drv->get_phy_stats(phydev, stats, data);
+}
+EXPORT_SYMBOL(phy_ethtool_get_stats);
include/linux/phy.h +14 -0
index 05fde31..4f14368 100644
@@ -589,6 +589,15 @@ struct phy_driver {
 	int (*module_eeprom)(struct phy_device *dev,
 			     struct ethtool_eeprom *ee, u8 *data);
 
+	/* Request for phy statitsics information and printing statistics
+	 * information from ethtool stats. So Rx stats, Tx stats and error
+	 * information can be read from
+	 */
+	void (*get_phy_stats)(struct phy_device *, struct ethtool_stats *,
+			      u64 *);
+	void (*get_strings)(struct phy_device *, u32 stringset, u8 *);
+	int  (*get_sset_count)(struct phy_device *, int);
+
 	struct device_driver driver;
 };
 #define to_phy_driver(d) container_of(d, struct phy_driver, driver)
@@ -816,6 +825,11 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data);
 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol);
 void phy_ethtool_get_wol(struct phy_device *phydev,
 			 struct ethtool_wolinfo *wol);
+int phy_ethtool_get_sset_count(struct phy_device *phydev, int sset);
+void phy_ethtool_get_strings(struct phy_device *phydev, u32 stringset,
+			     u8 *data);
+void phy_ethtool_get_stats(struct phy_device *phydev,
+			   struct ethtool_stats *stats, u64 *data);
 
 int __init mdio_bus_init(void);
 void mdio_bus_exit(void);
Signature · 1 line
1.7.9.5
#1 lore raw

Hello,

Quoted 6 lines · Thomas Scariah

From: "Scariah, Thomas" <[email protected]>

Added functions to support ethtool to print the phy statistics and error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer. This is an enahancement for ethtool to accommodate phy statistics

It sounds like your patch should actually be 3 different patches:

- add helper function to the core PHY library
- add statistics support to the Micrel PHY driver
- hook the proper ndo operations in cpsw to allow querying the PHY driver's statistics

Quoted 21 lines
---
 drivers/net/ethernet/ti/cpsw.c |   16 ++++++++++++-
 drivers/net/phy/micrel.c       |   50 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c          |   23 ++++++++++++++++++
 include/linux/phy.h            |   14 +++++++++++
 4 files changed, 102 insertions(+), 1 deletion(-)
drivers/net/ethernet/ti/cpsw.c +4 -0
index 3f48bb9..26d2dc5 100644
@@ -1001,9 +1001,16 @@ update_return:
 
 static int cpsw_get_sset_count(struct net_device *ndev, int sset)
 {
+	struct cpsw_priv *priv = netdev_priv(ndev);
+	int slave_no = cpsw_slave_index(priv);
+	int count;
+

drivers/net/ethernet/ti/cpsw.c update_return: · line 1016

Quoted 10 lines
drivers/net/ethernet/ti/cpsw.c +4 -1
 	switch (sset) {
 	case ETH_SS_STATS:
-		return CPSW_STATS_LEN;
+		count = CPSW_STATS_LEN;
+		count += phy_ethtool_get_sset_count(priv->slaves[slave_no].phy,
+						    sset);
+		return count;
 	default:
 		return -EOPNOTSUPP;
 	}

We already have a way to obtain PHY specific statistics through the ETH_SS_PHY_STATS string set, cannot we use that here too? It certainly makes it easier to overlay cpsw statistics with PHY device statistics, but when Andrew added support for that, AFAIR this was made intentionally separate.

Quoted 10 lines
drivers/net/ethernet/ti/cpsw.c +2 -0
@@ -1011,6 +1018,8 @@ static int cpsw_get_sset_count(struct net_device *ndev, int sset)
 
 static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
+	struct cpsw_priv *priv = netdev_priv(ndev);
+	int slave_no = cpsw_slave_index(priv);
 	u8 *p = data;
 	int i;
 

drivers/net/ethernet/ti/cpsw.c static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data) · line 1034

Quoted 5 lines
drivers/net/ethernet/ti/cpsw.c +2 -0
@@ -1021,6 +1030,8 @@ static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 			       ETH_GSTRING_LEN);
 			p += ETH_GSTRING_LEN;
 		}
+		phy_ethtool_get_strings(priv->slaves[slave_no].phy,
+					stringset, p);

Same here.

Quoted 12 lines
drivers/net/ethernet/ti/cpsw.c +1 -0
 		break;
 	}
 }
@@ -1031,6 +1042,7 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev,
 	struct cpsw_priv *priv = netdev_priv(ndev);
 	struct cpdma_chan_stats rx_stats;
 	struct cpdma_chan_stats tx_stats;
+	int slave_no = cpsw_slave_index(priv);
 	u32 val;
 	u8 *p;
 	int i, ret;

drivers/net/ethernet/ti/cpsw.c static void cpsw_get_ethtool_stats(struct net_device *ndev, · line 1083

Quoted 5 lines
drivers/net/ethernet/ti/cpsw.c +2 -0
@@ -1067,6 +1079,8 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev,
 		}
 	}
 
+	phy_ethtool_get_stats(priv->slaves[slave_no].phy, stats,
+			      &data[CPSW_STATS_LEN]);

And here.

Quoted 3 lines
drivers/net/ethernet/ti/cpsw.c +0 -0
 	pm_runtime_put(&priv->pdev->dev);
 }
 
Signature · 1 line
Florian
maintainer
#2 lore raw
Quoted 14 lines
Quoted 14 lines

static int cpsw_get_sset_count(struct net_device *ndev, int sset) {

drivers/net/ethernet/ti/cpsw.c +8 -1
+	struct cpsw_priv *priv = netdev_priv(ndev);
+	int slave_no = cpsw_slave_index(priv);
+	int count;
+
 	switch (sset) {
 	case ETH_SS_STATS:
-		return CPSW_STATS_LEN;
+		count = CPSW_STATS_LEN;
+		count += phy_ethtool_get_sset_count(priv->slaves[slave_no].phy,
+						    sset);
+		return count;
 	default:
Quoted 8 lines

drivers/net/ethernet/ti/cpsw.c update_return: · line 1016

Quoted 2 lines
drivers/net/ethernet/ti/cpsw.c +0 -0
 		return -EOPNOTSUPP;
 	}

We already have a way to obtain PHY specific statistics through the ETH_SS_PHY_STATS string set, cannot we use that here too? It certainly makes it easier to overlay cpsw statistics with PHY device statistics, but when Andrew added support for that, AFAIR this was made intentionally separate.

I don't particularly like this. It makes the cpsw driver different to all other drivers, in that it returns both MAC and PHY statistics.

If you are going to do this, please do it a higher level so that it applies to all Ethernet drivers, not just cpsw.

But personally, i don't see the point of this change. What is wrong with ethtool --phy-statistics?

Andrew

maintainer
#3 lore raw
In reply to Florian Fainelli
Quoted 9 lines · Florian Fainelli

Hello,

Quoted 6 lines · Thomas Scariah

From: "Scariah, Thomas" <[email protected]>

Added functions to support ethtool to print the phy statistics and error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer. This is an enahancement for ethtool to accommodate phy statistics

Hi Thomas

What tree is this against? net-next already has get_phy_stats, get_strings, and get_sset_count in struct phy_driver.

Andrew

#4 lore raw

RE: [EXTERNAL] Re: [PATCH 1/1] ethtool : added get_phy_stats, get_strings,get_sset_count

Hello Andrew,

Quoted 5 lines
Quoted 5 lines

Hello,

Quoted 2 lines · Thomas Scariah

From: "Scariah, Thomas" <[email protected]>

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Added functions to support ethtool to print the phy statistics and
error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer.
This is an enahancement for ethtool to accommodate phy statistics

Hi Thomas

What tree is this against? net-next already has get_phy_stats, get_strings, and get_sset_count in struct >phy_driver.

As I have mentioned I have developed against Kernel 4.4.14 and the similar functionality was not available.

Regards and Thanks
Thomas Scariah

-----Original Message-----
From: Andrew Lunn [mailto:[email protected]]
Sent: Monday, March 27, 2017 11:09 PM
To: Florian Fainelli <[email protected]>
Cc: Thomas Scariah <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Scariah, Thomas <[email protected]>; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH 1/1] ethtool : added get_phy_stats, get_strings,get_sset_count

Quoted 9 lines · Florian Fainelli

Hello,

Quoted 6 lines · Thomas Scariah

From: "Scariah, Thomas" <[email protected]>

Added functions to support ethtool to print the phy statistics and
error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer.
This is an enahancement for ethtool to accommodate phy statistics

Hi Thomas

What tree is this against? net-next already has get_phy_stats, get_strings, and get_sset_count in struct phy_driver.

Andrew

maintainer
#6 lore raw
In reply to a message not in the archive
Quoted 24 lines · Thomas Scariah

Hello Florian/Andrew,

Quoted 10 lines · Florian Fainelli

Hello,

Quoted 6 lines · Thomas Scariah

From: "Scariah, Thomas" <[email protected]>

Added functions to support ethtool to print the phy statistics and error information along with other ethtool statistics. This will help ethtool information to know the error is from physical layer or MAC layer. This is an enahancement for ethtool to accommodate phy statistics

Quoted 7 lines

It sounds like your patch should actually be 3 different patches:

- add helper function to the core PHY library
- add statistics support to the Micrel PHY driver
- hook the proper ndo operations in cpsw to allow querying the PHY driver's statistics

Quoted 4 lines

Yes agreed. This can be 3 different patches .
Anyway the latest kernel already has the same change.
I have developed this patch against Kernel 4.4.14 and the similar functionality was not available.

Hi Thomas

O.K, using v4.4 explains a lot. However, we only accept patches against:

git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

I still suggest you only do the PHY driver parts, and don't touch the MAC driver.

Andrew