netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, Simon Horman <horms@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH net-next v1 1/7] net: ethtool: plumb PHY stats to PHY drivers
Date: Tue, 3 Dec 2024 09:30:29 +0100	[thread overview]
Message-ID: <20241203093029.60c8b94b@fedora.home> (raw)
In-Reply-To: <20241203075622.2452169-2-o.rempel@pengutronix.de>

Hi Oleksij,

On Tue,  3 Dec 2024 08:56:15 +0100
Oleksij Rempel <o.rempel@pengutronix.de> wrote:

> From: Jakub Kicinski <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.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

[...] 

> +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);

I'm sorry to bother you with my multi-phy stuff, but I'd like to avoid
directly accessing netdev->phydev at least in the netlink code.

Could it be possible for you to pass a phydev directly to the
ethtool_get_phydev_stats() helper you're creating ? That way, you could
get the stats from other phydevs on the link if userspace passed a phy
index in the netlink header. You'd get the phydev that way :

phydev = ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_LINKSTATE_HEADER,], info->extack);

This is what's done in the pse-pd, plca and cabletest netlink code that
deals with phydevs.

Note that this helper will fallback to netdev->phydev if user didn't
pass any PHY index, which I expect to be what people do most of the
time. However should the netdev have more than 1 PHY, we would be able
to get the far-away PHY's stats :)

>  
>  		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);

Same here :)

Thanks,

Maxime

  reply	other threads:[~2024-12-03  8:30 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-03  7:56 [PATCH net-next v1 0/7] Introduce unified and structured PHY Oleksij Rempel
2024-12-03  7:56 ` [PATCH net-next v1 1/7] net: ethtool: plumb PHY stats to PHY drivers Oleksij Rempel
2024-12-03  8:30   ` Maxime Chevallier [this message]
2024-12-05  7:45   ` Mateusz Polchlopek
2024-12-05 11:57   ` Russell King (Oracle)
2024-12-06  1:19     ` Jakub Kicinski
2024-12-06  9:11       ` Russell King (Oracle)
2024-12-06 16:13         ` Jakub Kicinski
2024-12-10 12:03   ` Simon Horman
2024-12-03  7:56 ` [PATCH net-next v1 2/7] net: ethtool: add support for structured PHY statistics Oleksij Rempel
2024-12-05 12:00   ` Russell King (Oracle)
2024-12-03  7:56 ` [PATCH net-next v1 3/7] phy: replace bitwise flag definitions with BIT() macro Oleksij Rempel
2024-12-05  2:50   ` David Laight
2024-12-05 11:13     ` Oleksij Rempel
2024-12-05 12:02   ` Russell King (Oracle)
2024-12-05 12:06     ` Russell King (Oracle)
2024-12-03  7:56 ` [PATCH net-next v1 4/7] phy: introduce optional polling interface for PHY statistics Oleksij Rempel
2024-12-05  8:14   ` Mateusz Polchlopek
2024-12-05 12:09     ` Russell King (Oracle)
2024-12-06 11:14       ` Oleksij Rempel
2024-12-03  7:56 ` [PATCH net-next v1 5/7] ethtool: add helper to prevent invalid statistics exposure to userspace Oleksij Rempel
2024-12-05  8:45   ` Mateusz Polchlopek
2024-12-03  7:56 ` [PATCH net-next v1 6/7] phy: dp83td510: add statistics support Oleksij Rempel
2024-12-05  8:43   ` Mateusz Polchlopek
2024-12-05  9:01     ` Marc Kleine-Budde
2024-12-05 10:32       ` Mateusz Polchlopek
2024-12-05 10:58       ` Oleksij Rempel
2024-12-05 12:15   ` Russell King (Oracle)
2024-12-03  7:56 ` [PATCH net-next v1 7/7] phy: dp83tg720: " Oleksij Rempel
2024-12-05 11:48 ` [PATCH net-next v1 0/7] Introduce unified and structured PHY Russell King (Oracle)

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=20241203093029.60c8b94b@fedora.home \
    --to=maxime.chevallier@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.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).