From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>,
Vladimir Oltean <olteanv@gmail.com>,
andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
woojung.huh@microchip.com, o.rempel@pengutronix.de
Subject: [RFC net-next 1/2] net: ethtool: plumb PHY stats to PHY drivers
Date: Thu, 29 Aug 2024 10:43:41 -0700 [thread overview]
Message-ID: <20240829174342.3255168-2-kuba@kernel.org> (raw)
In-Reply-To: <20240829174342.3255168-1-kuba@kernel.org>
Feed the existing IEEE PHY counter struct (which currently
only has one entry) and link stats into the PHY driver.
The MAC driver can override the value if it somehow has a better
idea of PHY stats. Since the stats are "undefined" at input
the drivers can't += the values, so we should be safe from
double-counting.
Vladimir, I don't understand MM but doesn't MM share the PHY?
Ocelot seems to aggregate which I did not expect.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: Vladimir Oltean <olteanv@gmail.com>
CC: andrew@lunn.ch
CC: hkallweit1@gmail.com
CC: linux@armlinux.org.uk
CC: woojung.huh@microchip.com
CC: o.rempel@pengutronix.de
---
include/linux/phy.h | 10 ++++++++++
net/ethtool/linkstate.c | 25 ++++++++++++++++++++++---
net/ethtool/stats.c | 19 +++++++++++++++++++
3 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 4a9a11749c55..53942fd7760f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1090,6 +1090,16 @@ struct phy_driver {
int (*cable_test_get_status)(struct phy_device *dev, bool *finished);
/* Get statistics from the PHY using ethtool */
+ /**
+ * @get_phy_stats: Get well known statistics.
+ * @get_link_stats: Get well known link statistics.
+ * The input structure is not zero-initialized and the implementation
+ * must only set statistics which are actually collected by the device.
+ */
+ void (*get_phy_stats)(struct phy_device *dev,
+ struct ethtool_eth_phy_stats *eth_stats);
+ void (*get_link_stats)(struct phy_device *dev,
+ struct ethtool_link_ext_stats *link_stats);
/** @get_sset_count: Number of statistic counters */
int (*get_sset_count)(struct phy_device *dev);
/** @get_strings: Names of the statistic counters */
diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c
index 34d76e87847d..8d3a38cc3d48 100644
--- a/net/ethtool/linkstate.c
+++ b/net/ethtool/linkstate.c
@@ -94,6 +94,27 @@ static int linkstate_get_link_ext_state(struct net_device *dev,
return 0;
}
+static void
+ethtool_get_phydev_stats(struct net_device *dev,
+ struct linkstate_reply_data *data)
+{
+ struct phy_device *phydev = dev->phydev;
+
+ if (!phydev)
+ return;
+
+ if (dev->phydev)
+ data->link_stats.link_down_events =
+ READ_ONCE(dev->phydev->link_down_events);
+
+ if (!phydev->drv || !phydev->drv->get_link_stats)
+ return;
+
+ mutex_lock(&phydev->lock);
+ phydev->drv->get_link_stats(phydev, &data->link_stats);
+ mutex_unlock(&phydev->lock);
+}
+
static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
struct ethnl_reply_data *reply_base,
const struct genl_info *info)
@@ -127,9 +148,7 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
sizeof(data->link_stats) / 8);
if (req_base->flags & ETHTOOL_FLAG_STATS) {
- if (dev->phydev)
- data->link_stats.link_down_events =
- READ_ONCE(dev->phydev->link_down_events);
+ ethtool_get_phydev_stats(dev, data);
if (dev->ethtool_ops->get_link_ext_stats)
dev->ethtool_ops->get_link_ext_stats(dev,
diff --git a/net/ethtool/stats.c b/net/ethtool/stats.c
index 912f0c4fff2f..cf802b1cda6f 100644
--- a/net/ethtool/stats.c
+++ b/net/ethtool/stats.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/phy.h>
+
#include "netlink.h"
#include "common.h"
#include "bitset.h"
@@ -112,6 +114,19 @@ static int stats_parse_request(struct ethnl_req_info *req_base,
return 0;
}
+static void
+ethtool_get_phydev_stats(struct net_device *dev, struct stats_reply_data *data)
+{
+ struct phy_device *phydev = dev->phydev;
+
+ if (!phydev || !phydev->drv || !phydev->drv->get_phy_stats)
+ return;
+
+ mutex_lock(&phydev->lock);
+ phydev->drv->get_phy_stats(phydev, &data->phy_stats);
+ mutex_unlock(&phydev->lock);
+}
+
static int stats_prepare_data(const struct ethnl_req_info *req_base,
struct ethnl_reply_data *reply_base,
const struct genl_info *info)
@@ -145,6 +160,10 @@ static int stats_prepare_data(const struct ethnl_req_info *req_base,
data->ctrl_stats.src = src;
data->rmon_stats.src = src;
+ if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
+ src == ETHTOOL_MAC_STATS_SRC_AGGREGATE)
+ ethtool_get_phydev_stats(dev, data);
+
if (test_bit(ETHTOOL_STATS_ETH_PHY, req_info->stat_mask) &&
dev->ethtool_ops->get_eth_phy_stats)
dev->ethtool_ops->get_eth_phy_stats(dev, &data->phy_stats);
--
2.46.0
next prev parent reply other threads:[~2024-08-29 17:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 17:43 [RFC net-next 0/2] net: ethtool: add phy(dev) specific stats over netlink Jakub Kicinski
2024-08-29 17:43 ` Jakub Kicinski [this message]
2024-08-29 18:10 ` [RFC net-next 1/2] net: ethtool: plumb PHY stats to PHY drivers Oleksij Rempel
2024-08-29 19:13 ` Jakub Kicinski
2024-08-30 8:16 ` Maxime Chevallier
2024-08-30 18:30 ` Jakub Kicinski
2024-09-04 7:20 ` Maxime Chevallier
2024-09-04 8:05 ` Oleksij Rempel
2024-09-04 8:09 ` Maxime Chevallier
2024-09-02 15:08 ` Vladimir Oltean
2024-08-29 17:43 ` [RFC net-next 2/2] net: ethtool: add phy(dev) specific stats over netlink Jakub Kicinski
2024-08-29 18:47 ` Andrew Lunn
2024-08-29 19:23 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240829174342.3255168-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).