mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: "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>
Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, Simon Horman <horms@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH net-next v2 5/8] net: phy: introduce optional polling interface for PHY statistics
Date: Thu, 19 Dec 2024 14:33:51 +0100	[thread overview]
Message-ID: <Z2Qgv-AqKJONvJWu@pengutronix.de> (raw)
In-Reply-To: <20241219132534.725051-6-o.rempel@pengutronix.de>

On Thu, Dec 19, 2024 at 02:25:31PM +0100, Oleksij Rempel wrote:
> Add an optional polling interface for PHY statistics to simplify driver
> implementation. Drivers can request the PHYlib to handle the polling
> task by explicitly setting the `PHY_POLL_STATS` flag in their driver
> configuration.

The commit message is out of date. PHY_POLL_STATS should be removed.

> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> changes v2:
> - drop PHY_POLL_STATS
> - add function comments
> ---
>  drivers/net/phy/phy.c | 20 ++++++++++++++++++++
>  include/linux/phy.h   | 21 +++++++++++++++++++++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 107a35f402b3..7f6d304105f5 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1442,6 +1442,23 @@ static int phy_enable_interrupts(struct phy_device *phydev)
>  	return phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
>  }
>  
> +/**
> + * phy_update_stats - Update PHY device statistics if supported.
> + * @phydev: Pointer to the PHY device structure.
> + *
> + * If the PHY driver provides an update_stats callback, this function
> + * invokes it to update the PHY statistics. If not, it returns 0.
> + *
> + * Return: 0 on success, or a negative error code if the callback fails.
> + */
> +static int phy_update_stats(struct phy_device *phydev)
> +{
> +	if (!phydev->drv->update_stats)
> +		return 0;
> +
> +	return phydev->drv->update_stats(phydev);
> +}
> +
>  /**
>   * phy_request_interrupt - request and enable interrupt for a PHY device
>   * @phydev: target phy_device struct
> @@ -1511,6 +1528,9 @@ static enum phy_state_work _phy_state_machine(struct phy_device *phydev)
>  	case PHY_RUNNING:
>  		err = phy_check_link_status(phydev);
>  		func = &phy_check_link_status;
> +
> +		if (!err)
> +			err = phy_update_stats(phydev);
>  		break;
>  	case PHY_CABLETEST:
>  		err = phydev->drv->cable_test_get_status(phydev, &finished);
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index e1554ac16ce2..b3e4a164bfb7 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -1180,6 +1180,24 @@ struct phy_driver {
>  	 */
>  	void (*get_link_stats)(struct phy_device *dev,
>  			       struct ethtool_link_ext_stats *link_stats);
> +
> +	/**
> +	 * update_stats - Trigger periodic statistics updates.
> +	 * @dev: The PHY device for which statistics updates are triggered.
> +	 *
> +	 * Periodically gathers statistics from the PHY device to update locally
> +	 * maintained 64-bit counters. This is necessary for PHYs that implement
> +	 * reduced-width counters (e.g., 16-bit or 32-bit) which can overflow
> +	 * more frequently compared to 64-bit counters. By invoking this
> +	 * callback, drivers can fetch the current counter values, handle
> +	 * overflow detection, and accumulate the results into local 64-bit
> +	 * counters for accurate reporting through the `get_phy_stats` and
> +	 * `get_link_stats` interfaces.
> +	 *
> +	 * Return: 0 on success or a negative error code on failure.
> +	 */
> +	int (*update_stats)(struct phy_device *dev);
> +
>  	/** @get_sset_count: Number of statistic counters */
>  	int (*get_sset_count)(struct phy_device *dev);
>  	/** @get_strings: Names of the statistic counters */
> @@ -1670,6 +1688,9 @@ static inline bool phy_polling_mode(struct phy_device *phydev)
>  		if (phydev->drv->flags & PHY_POLL_CABLE_TEST)
>  			return true;
>  
> +	if (phydev->drv->update_stats)
> +		return true;
> +
>  	return phydev->irq == PHY_POLL;
>  }
>  
> -- 
> 2.39.5
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2024-12-19 13:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19 13:25 [PATCH net-next v2 0/8] Introduce unified and structured PHY Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 1/8] ethtool: linkstate: migrate linkstate functions to support multi-PHY setups Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 2/8] net: ethtool: plumb PHY stats to PHY drivers Oleksij Rempel
2024-12-20 12:36   ` kernel test robot
2024-12-20 12:47   ` kernel test robot
2024-12-19 13:25 ` [PATCH net-next v2 3/8] net: ethtool: add support for structured PHY statistics Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 4/8] Documentation: networking: update PHY error counter diagnostics in twisted pair guide Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 5/8] net: phy: introduce optional polling interface for PHY statistics Oleksij Rempel
2024-12-19 13:33   ` Oleksij Rempel [this message]
2024-12-19 13:25 ` [PATCH net-next v2 6/8] ethtool: add helper to prevent invalid statistics exposure to userspace Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 7/8] net: phy: dp83td510: add statistics support Oleksij Rempel
2024-12-19 13:25 ` [PATCH net-next v2 8/8] net: phy: dp83tg720: " Oleksij Rempel
2024-12-20  3:54 ` [PATCH net-next v2 0/8] Introduce unified and structured PHY 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=Z2Qgv-AqKJONvJWu@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --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=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®