Re: [PATCH net-next v4 05/23] net: phy: add genphy_c45_ethtool_get/set_eee() support

From: Vladimir Oltean
Date: Fri Feb 03 2023 - 20:12:08 EST


On Wed, Feb 01, 2023 at 03:58:27PM +0100, Oleksij Rempel wrote:
> Add replacement for phy_ethtool_get/set_eee() functions.
>
> - it is able to support only limited amount of link modes. We have more
> EEE link modes...
>
> By refactoring this code I address most of this point except of the last
> one. Adding additional EEE link modes will need more work.

> +/**
> + * genphy_c45_ethtool_get_eee - get EEE supported and status
> + * @phydev: target phy_device struct
> + * @data: ethtool_eee data
> + *
> + * Description: it reports the Supported/Advertisement/LP Advertisement
> + * capabilities.
> + */
> +int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
> + struct ethtool_eee *data)
> +{
> + __ETHTOOL_DECLARE_LINK_MODE_MASK(adv) = {};
> + __ETHTOOL_DECLARE_LINK_MODE_MASK(lp) = {};
> + bool overflow = false, is_enabled;
> + int ret;
> +
> + ret = genphy_c45_eee_is_active(phydev, adv, lp, &is_enabled);
> + if (ret < 0)
> + return ret;
> +
> + data->eee_enabled = is_enabled;
> + data->eee_active = ret;
> +
> + if (!ethtool_convert_link_mode_to_legacy_u32(&data->supported,
> + phydev->supported_eee))
> + overflow = true;
> + if (!ethtool_convert_link_mode_to_legacy_u32(&data->advertised, adv))
> + overflow = true;
> + if (!ethtool_convert_link_mode_to_legacy_u32(&data->lp_advertised, lp))
> + overflow = true;

ah, ok, so since struct ethtool_eee stores the link modes in the old u32
format, link modes equal to ETHTOOL_LINK_MODE_25000baseKR_Full_BIT or
higher would truncate. Makes sense.

> +
> + if (overflow)
> + phydev_warn(phydev, "Not all supported or advertised EEE link modes was passed to the user space\n");

were passed

> +
> + return 0;
> +}
> +EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);