Skip to content

Commit

Permalink
Merge branch 'net-phy-improve-and-simplify-eee-handling-in-phylib'
Browse files Browse the repository at this point in the history
Heiner Kallweit says:

====================
net: phy: improve and simplify EEE handling in phylib

This series improves and simplifies phylib's EEE handling.
====================

Link: https://patch.msgid.link/3caa3151-13ac-44a8-9bb6-20f82563f698@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Feb 19, 2025
2 parents fabcfd6 + 809265f commit 59ed446
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 50 deletions.
40 changes: 12 additions & 28 deletions drivers/net/phy/phy-c45.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,10 @@ EXPORT_SYMBOL_GPL(genphy_c45_read_mdix);
static int genphy_c45_write_eee_adv(struct phy_device *phydev,
unsigned long *adv)
{
__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp);
int val, changed = 0;

linkmode_andnot(tmp, adv, phydev->eee_disabled_modes);

if (linkmode_intersects(phydev->supported_eee, PHY_EEE_CAP1_FEATURES)) {
val = linkmode_to_mii_eee_cap1_t(tmp);
val = linkmode_to_mii_eee_cap1_t(adv);

/* IEEE 802.3-2018 45.2.7.13 EEE advertisement 1
* (Register 7.60)
Expand All @@ -707,7 +704,7 @@ static int genphy_c45_write_eee_adv(struct phy_device *phydev,
}

if (linkmode_intersects(phydev->supported_eee, PHY_EEE_CAP2_FEATURES)) {
val = linkmode_to_mii_eee_cap2_t(tmp);
val = linkmode_to_mii_eee_cap2_t(adv);

/* IEEE 802.3-2022 45.2.7.16 EEE advertisement 2
* (Register 7.62)
Expand Down Expand Up @@ -1467,42 +1464,29 @@ EXPORT_SYMBOL_GPL(genphy_c45_plca_get_status);
/**
* genphy_c45_eee_is_active - get EEE status
* @phydev: target phy_device struct
* @adv: variable to store advertised linkmodes
* @lp: variable to store LP advertised linkmodes
*
* Description: this function will read local and link partner PHY
* advertisements. Compare them return current EEE state.
* Description: this function will read link partner PHY advertisement
* and compare it to local advertisement to return current EEE state.
*/
int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,
unsigned long *lp)
int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *lp)
{
__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_adv) = {};
__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_lp) = {};
__ETHTOOL_DECLARE_LINK_MODE_MASK(common);
bool eee_active;
int ret;

ret = genphy_c45_read_eee_adv(phydev, tmp_adv);
if (ret)
return ret;

ret = genphy_c45_read_eee_lpa(phydev, tmp_lp);
if (ret)
return ret;

linkmode_and(common, tmp_adv, tmp_lp);
if (!linkmode_empty(tmp_adv) && !linkmode_empty(common))
eee_active = phy_check_valid(phydev->speed, phydev->duplex,
common);
else
eee_active = false;

if (adv)
linkmode_copy(adv, tmp_adv);
if (lp)
linkmode_copy(lp, tmp_lp);

return eee_active;
linkmode_and(common, phydev->advertising_eee, tmp_lp);
if (linkmode_empty(common))
return 0;

return phy_check_valid(phydev->speed, phydev->duplex, common);
}
EXPORT_SYMBOL(genphy_c45_eee_is_active);

Expand All @@ -1519,14 +1503,14 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
{
int ret;

ret = genphy_c45_eee_is_active(phydev, data->advertised,
data->lp_advertised);
ret = genphy_c45_eee_is_active(phydev, data->lp_advertised);
if (ret < 0)
return ret;

data->eee_active = phydev->eee_active;
linkmode_andnot(data->supported, phydev->supported_eee,
phydev->eee_disabled_modes);
linkmode_copy(data->advertised, phydev->advertising_eee);
return 0;
}
EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/phy/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ static int phy_check_link_status(struct phy_device *phydev)
if (phydev->link && phydev->state != PHY_RUNNING) {
phy_check_downshift(phydev);
phydev->state = PHY_RUNNING;
err = genphy_c45_eee_is_active(phydev, NULL, NULL);
err = genphy_c45_eee_is_active(phydev, NULL);
phydev->eee_active = err > 0;
phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled &&
phydev->eee_active;
Expand Down Expand Up @@ -1780,7 +1780,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
if (!phydev->drv)
return -EIO;

ret = genphy_c45_eee_is_active(phydev, NULL, NULL);
ret = genphy_c45_eee_is_active(phydev, NULL);
if (ret < 0)
return ret;
if (!ret)
Expand Down
21 changes: 10 additions & 11 deletions drivers/net/phy/phy_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -3580,22 +3580,21 @@ static int phy_probe(struct device *dev)
if (err)
goto out;

/* There is no "enabled" flag. If PHY is advertising, assume it is
* kind of enabled.
*/
phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);
/* Get the EEE modes we want to prohibit. */
of_set_phy_eee_broken(phydev);

/* Some PHYs may advertise, by default, not support EEE modes. So,
* we need to clean them.
* we need to clean them. In addition remove all disabled EEE modes.
*/
if (phydev->eee_cfg.eee_enabled)
linkmode_and(phydev->advertising_eee, phydev->supported_eee,
phydev->advertising_eee);
linkmode_and(phydev->advertising_eee, phydev->supported_eee,
phydev->advertising_eee);
linkmode_andnot(phydev->advertising_eee, phydev->advertising_eee,
phydev->eee_disabled_modes);

/* Get the EEE modes we want to prohibit. We will ask
* the PHY stop advertising these mode later on
/* There is no "enabled" flag. If PHY is advertising, assume it is
* kind of enabled.
*/
of_set_phy_eee_broken(phydev);
phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);

/* Get master/slave strap overrides */
of_set_phy_timing_role(phydev);
Expand Down
20 changes: 11 additions & 9 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1340,22 +1340,25 @@ void of_set_phy_timing_role(struct phy_device *phydev);
int phy_speed_down_core(struct phy_device *phydev);

/**
* phy_disable_eee_mode - Don't advertise an EEE mode.
* phy_is_started - Convenience function to check whether PHY is started
* @phydev: The phy_device struct
* @link_mode: The EEE mode to be disabled
*/
static inline void phy_disable_eee_mode(struct phy_device *phydev, u32 link_mode)
static inline bool phy_is_started(struct phy_device *phydev)
{
linkmode_set_bit(link_mode, phydev->eee_disabled_modes);
return phydev->state >= PHY_UP;
}

/**
* phy_is_started - Convenience function to check whether PHY is started
* phy_disable_eee_mode - Don't advertise an EEE mode.
* @phydev: The phy_device struct
* @link_mode: The EEE mode to be disabled
*/
static inline bool phy_is_started(struct phy_device *phydev)
static inline void phy_disable_eee_mode(struct phy_device *phydev, u32 link_mode)
{
return phydev->state >= PHY_UP;
WARN_ON(phy_is_started(phydev));

linkmode_set_bit(link_mode, phydev->eee_disabled_modes);
linkmode_clear_bit(link_mode, phydev->advertising_eee);
}

void phy_resolve_aneg_pause(struct phy_device *phydev);
Expand Down Expand Up @@ -2029,8 +2032,7 @@ int genphy_c45_plca_set_cfg(struct phy_device *phydev,
const struct phy_plca_cfg *plca_cfg);
int genphy_c45_plca_get_status(struct phy_device *phydev,
struct phy_plca_status *plca_st);
int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,
unsigned long *lp);
int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *lp);
int genphy_c45_ethtool_get_eee(struct phy_device *phydev,
struct ethtool_keee *data);
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
Expand Down

0 comments on commit 59ed446

Please sign in to comment.