On Thu, Jan 09, 2025 at 10:44:52AM +0100, Oleksij Rempel wrote: > From: Jakub Kicinski <kuba@xxxxxxxxxx> > > Introduce support for standardized PHY statistics reporting in ethtool > by extending the PHYLIB framework. Add the functions > phy_ethtool_get_phy_stats() and phy_ethtool_get_link_ext_stats() to > provide a consistent interface for retrieving PHY-level and > link-specific statistics. These functions are used within the ethtool > implementation to avoid direct access to the phy_device structure > outside of the PHYLIB framework. > > A new structure, ethtool_phy_stats, is introduced to standardize PHY > statistics such as packet counts, byte counts, and error counters. > Drivers are updated to include callbacks for retrieving PHY and > link-specific statistics, ensuring values are explicitly set only for > supported fields, initialized with ETHTOOL_STAT_NOT_SET to avoid > ambiguity. > > Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> > Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx> ... > diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c > index e4b04cdaa995..e629c3b1a940 100644 > --- a/drivers/net/phy/phy.c > +++ b/drivers/net/phy/phy.c > @@ -615,6 +615,49 @@ int phy_ethtool_get_stats(struct phy_device *phydev, > } > EXPORT_SYMBOL(phy_ethtool_get_stats); > > +/** > + * phy_ethtool_get_phy_stats - Retrieve standardized PHY statistics nit: __phy_ethtool_get_phy_stats > + * @phydev: Pointer to the PHY device > + * @phy_stats: Pointer to ethtool_eth_phy_stats structure > + * @phydev_stats: Pointer to ethtool_phy_stats structure > + * > + * Fetches PHY statistics using a kernel-defined interface for consistent > + * diagnostics. Unlike phy_ethtool_get_stats(), which allows custom stats, > + * this function enforces a standardized format for better interoperability. > + */ > +void __phy_ethtool_get_phy_stats(struct phy_device *phydev, > + struct ethtool_eth_phy_stats *phy_stats, > + struct ethtool_phy_stats *phydev_stats) > +{ > + if (!phydev->drv || !phydev->drv->get_phy_stats) > + return; > + > + mutex_lock(&phydev->lock); > + phydev->drv->get_phy_stats(phydev, phy_stats, phydev_stats); > + mutex_unlock(&phydev->lock); > +} > + > +/** > + * phy_ethtool_get_link_ext_stats - Retrieve extended link statistics for a PHY nit: __phy_ethtool_get_link_ext_stats > + * @phydev: Pointer to the PHY device > + * @link_stats: Pointer to the structure to store extended link statistics > + * > + * Populates the ethtool_link_ext_stats structure with link down event counts > + * and additional driver-specific link statistics, if available. > + */ > +void __phy_ethtool_get_link_ext_stats(struct phy_device *phydev, > + struct ethtool_link_ext_stats *link_stats) > +{ > + link_stats->link_down_events = READ_ONCE(phydev->link_down_events); > + > + if (!phydev->drv || !phydev->drv->get_link_stats) > + return; > + > + mutex_lock(&phydev->lock); > + phydev->drv->get_link_stats(phydev, link_stats); > + mutex_unlock(&phydev->lock); > +} > + > /** > * phy_ethtool_get_plca_cfg - Get PLCA RS configuration > * @phydev: the phy_device struct ...