net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
Subsystems (3)
PATCH v2 1/1 net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
When phy_ethtool_set_eee_noneg() detects a change in the LPI parameters, it attempts to update phylib state and trigger the link to cycle so the MAC sees the updated parameters.
However, in doing so, it sets phydev->enable_tx_lpi depending on whether the EEE configuration allows the MAC to generate LPI without taking into account the result of negotiation.
This can be demonstrated with a 1000base-T FD interface by:
# ethtool --set-eee eno0 advertise 8 # cause EEE to be not negotiated # ethtool --set-eee eno0 tx-lpi off # ethtool --set-eee eno0 tx-lpi on
This results in being true, despite EEE not having been negotiated and:
# ethtool --show-eee eno0 EEE status: enabled - inactive Tx LPI: 250 (us) Supported EEE link modes: 100baseT/Full 1000baseT/Full Advertised EEE link modes: 100baseT/Full Link partner advertised EEE link modes: 100baseT/Full 1000baseT/Full
Fix this by keeping track of whether EEE was negotiated via a new eee_active member in struct phy_device, and include this state in the decision whether phydev->enable_tx_lpi should be set.
--- drivers/net/phy/phy-c45.c | 2 +- drivers/net/phy/phy.c | 32 ++++++++++++++++++-------------- include/linux/phy.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/phy/phy-c45.c +1 -1
@@ -1530,7 +1530,7 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,return ret; data->eee_enabled = is_enabled; - data->eee_active = ret; + data->eee_active = phydev->eee_active;linkmode_copy (data->supported, phydev->supported_eee);return 0 ;
drivers/net/phy/phy.c +18 -14
@@ -990,14 +990,14 @@ static int phy_check_link_status(struct phy_device *phydev) phydev->state =PHY_RUNNING ; err =genphy_c45_eee_is_active (phydev,NULL ,NULL ,NULL ); -if (err <=0 ) - phydev->enable_tx_lpi = false; -else - phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled; + phydev->eee_active = err >0 ; + phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && + phydev->eee_active;phy_link_up (phydev); }else if (!phydev->link && phydev->state !=PHY_NOLINK ) { phydev->state =PHY_NOLINK ; + phydev->eee_active = false; phydev->enable_tx_lpi = false;phy_link_down (phydev); }
@@ -1685,16 +1685,20 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,struct ethtool_keee *data) { -if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled || - phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) { -eee_to_eeecfg (&phydev->eee_cfg, data); - phydev->enable_tx_lpi =eeecfg_mac_can_tx_lpi (&phydev->eee_cfg); -if (phydev->link) { - phydev->link = false; -phy_link_down (phydev); - phydev->link = true; -phy_link_up (phydev); - } +bool enable_tx_lpi = data->tx_lpi_enabled && + phydev->eee_active; + +eee_to_eeecfg (&phydev->eee_cfg, data); + +if ((phydev->enable_tx_lpi != enable_tx_lpi || + phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) && + phydev->link) { + phydev->enable_tx_lpi = false; + phydev->link = false; +phy_link_down (phydev); + phydev->enable_tx_lpi = enable_tx_lpi; + phydev->link = true; +phy_link_up (phydev); } }
include/linux/phy.h +1 -0
@@ -723,6 +723,7 @@ struct phy_device {/* Energy efficient ethernet modes which should be prohibited */ __ETHTOOL_DECLARE_LINK_MODE_MASK (eee_broken_modes);bool enable_tx_lpi; +bool eee_active;struct eee_config eee_cfg;/* Host supported PHY interface types. Should be ignored if empty. */
Signature · 1 line
2.30.2
Andrew Lunn
maintainerinclude/linux/phy.h struct phy_device { · line 726
Quoted 9 lines
include/linux/phy.h +1
-0@@ -723,6 +723,7 @@ struct phy_device {/* Energy efficient ethernet modes which should be prohibited */ __ETHTOOL_DECLARE_LINK_MODE_MASK (eee_broken_modes);bool enable_tx_lpi; +bool eee_active;
This is missing a kdoc entry.
With that fixed, please add my Reviewed-by:
Andrew
---
pw-bot: cr
Heiner Kallweit
maintainerQuoted 60 lines · Russell King (Oracle)
--- drivers/net/phy/phy-c45.c | 2 +- drivers/net/phy/phy.c | 32 ++++++++++++++++++-------------- include/linux/phy.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-)drivers/net/phy/phy-c45.c +1
-1@@ -1530,7 +1530,7 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,return ret; data->eee_enabled = is_enabled; - data->eee_active = ret; + data->eee_active = phydev->eee_active;linkmode_copy (data->supported, phydev->supported_eee);return 0 ;drivers/net/phy/phy.c +8
-14@@ -990,14 +990,14 @@ static int phy_check_link_status(struct phy_device *phydev) phydev->state =PHY_RUNNING ; err =genphy_c45_eee_is_active (phydev,NULL ,NULL ,NULL ); -if (err <=0 ) - phydev->enable_tx_lpi = false; -else - phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled; + phydev->eee_active = err >0 ; + phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && + phydev->eee_active;phy_link_up (phydev); }else if (!phydev->link && phydev->state !=PHY_NOLINK ) { phydev->state =PHY_NOLINK ; + phydev->eee_active = false; phydev->enable_tx_lpi = false;phy_link_down (phydev); }@@ -1685,16 +1685,20 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,struct ethtool_keee *data) { -if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled || - phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) { -eee_to_eeecfg (&phydev->eee_cfg, data); - phydev->enable_tx_lpi =eeecfg_mac_can_tx_lpi (&phydev->eee_cfg); -if (phydev->link) { - phydev->link = false; -phy_link_down (phydev); - phydev->link = true; -phy_link_up (phydev); - } +bool enable_tx_lpi = data->tx_lpi_enabled && + phydev->eee_active; + +eee_to_eeecfg (&phydev->eee_cfg, data);
drivers/net/phy/phy.c EXPORT_SYMBOL(phy_ethtool_get_eee); · line 1701
Quoted 10 lines
drivers/net/phy/phy.c +10
-0+ +if ((phydev->enable_tx_lpi != enable_tx_lpi || + phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) && + phydev->link) { + phydev->enable_tx_lpi = false; + phydev->link = false; +phy_link_down (phydev); + phydev->enable_tx_lpi = enable_tx_lpi; + phydev->link = true; +phy_link_up (phydev);
This part collides with a pending patch:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I think you have to rebase and resubmit once the pending patch has been applied.
Quoted 16 lines
drivers/net/phy/phy.c +0
-0} }include/linux/phy.h +1
-1@@ -723,6 +723,7 @@ struct phy_device {/* Energy efficient ethernet modes which should be prohibited */ __ETHTOOL_DECLARE_LINK_MODE_MASK (eee_broken_modes);bool enable_tx_lpi; +bool eee_active;struct eee_config eee_cfg;/* Host supported PHY interface types. Should be ignored if empty. */ -- 2.30.2
Heiner Kallweit
maintainerQuoted 67 lines · Heiner Kallweit
Quoted 66 lines · Russell King (Oracle)
--- drivers/net/phy/phy-c45.c | 2 +- drivers/net/phy/phy.c | 32 ++++++++++++++++++-------------- include/linux/phy.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-)drivers/net/phy/phy-c45.c +1
-1@@ -1530,7 +1530,7 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,return ret; data->eee_enabled = is_enabled; - data->eee_active = ret; + data->eee_active = phydev->eee_active;linkmode_copy (data->supported, phydev->supported_eee);return 0 ;drivers/net/phy/phy.c +14
-14@@ -990,14 +990,14 @@ static int phy_check_link_status(struct phy_device *phydev) phydev->state =PHY_RUNNING ; err =genphy_c45_eee_is_active (phydev,NULL ,NULL ,NULL ); -if (err <=0 ) - phydev->enable_tx_lpi = false; -else - phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled; + phydev->eee_active = err >0 ; + phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && + phydev->eee_active;phy_link_up (phydev); }else if (!phydev->link && phydev->state !=PHY_NOLINK ) { phydev->state =PHY_NOLINK ; + phydev->eee_active = false; phydev->enable_tx_lpi = false;phy_link_down (phydev); }@@ -1685,16 +1685,20 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,struct ethtool_keee *data) { -if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled || - phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) { -eee_to_eeecfg (&phydev->eee_cfg, data); - phydev->enable_tx_lpi =eeecfg_mac_can_tx_lpi (&phydev->eee_cfg); -if (phydev->link) { - phydev->link = false; -phy_link_down (phydev); - phydev->link = true; -phy_link_up (phydev); - } +bool enable_tx_lpi = data->tx_lpi_enabled && + phydev->eee_active; + +eee_to_eeecfg (&phydev->eee_cfg, data); + +if ((phydev->enable_tx_lpi != enable_tx_lpi || + phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) && + phydev->link) { + phydev->enable_tx_lpi = false; + phydev->link = false;
Quoted 9 lines
drivers/net/phy/phy.c EXPORT_SYMBOL(phy_ethtool_get_eee); · line 1701
Quoted 4 lines
drivers/net/phy/phy.c +4
-0+phy_link_down (phydev); + phydev->enable_tx_lpi = enable_tx_lpi; + phydev->link = true; +phy_link_up (phydev);This part collides with a pending patch:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I think you have to rebase and resubmit once the pending patch has been applied.
Merge of both changes should result in something like this:
static void phy_ethtool_set_eee_noneg(struct phy_device *phydev,
const struct eee_config *old_cfg)
{
bool enable_tx_lpi;
if (!phydev->link)
return;
enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active;
if (enable_tx_lpi != old_cfg->tx_lpi_enabled ||
phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {
phydev->enable_tx_lpi = false;
phydev->link = false;
phy_link_down(phydev);
phydev->enable_tx_lpi = enable_tx_lpi;
phydev->link = true;
phy_link_up(phydev);
}
}Russell King (Oracle)
reviewerQuoted 19 lines · Heiner Kallweit
Quoted 3 lines · Heiner Kallweit
This part collides with a pending patch:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I think you have to rebase and resubmit once the pending patch has been applied.Merge of both changes should result in something like this:
static void phy_ethtool_set_eee_noneg(struct
phy_device*phydev,
const structeee_config*old_cfg){ bool enable_tx_lpi; if (!phydev->link) return; enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; if (enable_tx_lpi != old_cfg->tx_lpi_enabled || phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {
Quoted 8 lines
phydev->enable_tx_lpi = false;
phydev->link = false;
phy_link_down(phydev);
phydev->enable_tx_lpi = enable_tx_lpi;
phydev->link = true;
phy_link_up(phydev);
}
}Thanks for pointing this out - I've now merged your patch into my tree and rebased on top. Your resolution isn't quite right - the if() statement should be:
+ if (phydev->enable_tx_lpi != enable_tx_lpi ||
phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {Since we only need to bounce the link if the LPI timer or the MAC LPI enable state has changed. I'll send a replacement patch shortly.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!