net: phylink managed EEE support
Subsystems (10)
Russell King (Oracle)
maintainercover net: phylink managed EEE support
Hi,
Adding managed EEE support to phylink has been on the cards ever since the idea in phylib was mooted. This overly large series attempts to do so. I've included all the patches as it's important to get the driver patches out there.
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct ethtool_keee whether the netdev driver wants it or not. This leads to weird scenarios where doing a get_eee() op followed by a set_eee() op results in e.g. tx_lpi_timer being zeroed, because the MAC driver doesn't know it needs to initialise phylib's phydev->eee_cfg.tx_lpi_timer member. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
I am ignoring that limit for this posting precisely because of this. I think we need to have a discussion about it, because if it ends up causing breakage, then we're doing something wrong.
One of the drivers that got broken was stmmac, so this series also includes a number of patches that fix it before converting stmmac to phylink managed EEE. I can point to many many more that are similarly broken.
Also inflating this series are two important patches that have been submitted for the NET tree, but which aren't yet part of the net-next tree - thus making this series larger than really necessary. If it weren't for both of these issues, then this series would be exactly 15 patches.
Anyway, these patches...
Patch 1 and 2 are patches that have been submitted and possibly applied to the net tree.
Patch 3 changes the Marvell driver to use the state we store in struct phy_device, rather than manually calling phydev->eee_cfg.eee_enabled.
Patch 4 avoids genphy_c45_ethtool_get_eee() setting ->eee_enabled, as we copy that from phydev->eee_cfg.eee_enabled later, and after patch 3 mo one uses this after calling genphy_c45_ethtool_get_eee(). In fact, the only caller of this function now is phy_ethtool_get_eee().
As all callers to genphy_c45_eee_is_active() now pass NULL as its is_enabled flag, this is no longer useful. Remove the argument in patch 5.
Patch 6 updates the phylib documentation to make it absolutely clear that phy_ethtool_get_eee() now fills in all members of struct ethtool_keee, which is why we now have so many buggy network drivers. We need to decide how to fix this mess.
Patch 7 adds a definition for the clock stop capable bit in the PCS MMD status register.
Patch 8 adds a phylib API to query whether the PHY allows the transmit xMII clock to be stopped while in LPI mode. This capability is for MAC drivers to save power when LPI is active, to allow them to stop their transmit clock.
Patch 9 adds another phylib API to configure whether the receive xMII clock may be disabled by the PHY. We do have an existing API, phy_init_eee(), but... it only allows the control bit to be set which is weird - what if a boot firmware or previous kernel has set this bit and we want it clear?
Patch 10 finally starts on the phylink parts of this, extracting from phylink_resolve() the detection of link-up. (Yes, okay, I could've dropped this patch, but with 23 patches, it's not going to make that much difference.)
Patch 11 adds phylink managed EEE support. Two new MAC APIs are added, to enable and disable LPI. The enable method is passed the LPI timer setting which it is expected to program into the hardware, and also a flag ehther the transmit clock should be stopped.
*** There are open questions here. Eagle eyed reviewers will notice
pl->config->lpi_interfaces. There are MACs out there which only support LPI signalling on a subset of their interface types. Phylib doesn't understand this. I'm handling this at the moment by simply not activating LPI at the MAC, but that leads to ethtool --show-eee suggesting that EEE is active when it isn't.
*** Should we pass the phy_interface_t to these functions? *** Should mac_enable_tx_lpi() be allowed to fail if the MAC doesn't
support the interface mode?
An example of a MAC that this is the case are the Marvell ones - both NETA and PP2 only support LPI signalling when connected via SGMII, which makes being connected to a PHY which changes its link mode problematical.
The remainder of the patches address the driver sides, which are necessary to actually test this stuff out. The exception are the stmmac patches.
The first four stmmac patches show what is necessary across many drivers to fix the current phylib EEE mess.
The 5th stmmac patch makes reporting of EEE errors dependent on whether EEE is supported by stmmac or not - I can't see why one would want anything else (maybe someone can enlighten me?)
The 6th stmmac patch converts to use phy_eee_rx_clock_stop(), thereby ensuring that, if desired, the RX clock will not be stopped by the PHY when in LPI mode (which as noted above is something that phy_init_eee() doesn't do.) Given that we know stmmac has issues if the RX clock is stopped, this could be a bug fix.
The final patch converts stmmac to phylink managed EEE.
drivers/net/ethernet/marvell/mvneta.c | 118 ++++++++++-------- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 5 + drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 88 ++++++++++++++ drivers/net/ethernet/microchip/lan743x_ethtool.c | 21 ---- drivers/net/ethernet/microchip/lan743x_main.c | 39 ++++-- drivers/net/ethernet/microchip/lan743x_main.h | 1 - drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 - .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 25 +--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 68 ++++++++--- drivers/net/phy/marvell.c | 4 +- drivers/net/phy/phy-c45.c | 15 +-- drivers/net/phy/phy.c | 106 +++++++++++----- drivers/net/phy/phylink.c | 134 +++++++++++++++++++-- include/linux/phy.h | 6 +- include/linux/phylink.h | 44 +++++++ include/uapi/linux/mdio.h | 1 + 16 files changed, 505 insertions(+), 171 deletions(-)
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!
RFC PATCH 1/23 net: phy: ensure that genphy_c45_an_config_eee_aneg() sees new value of phydev->eee_cfg.eee_enabled
From: Heiner Kallweit <[email protected]>
This is a follow-up to 41ffcd95015f ("net: phy: fix phylib's dual eee_enabled") and resolves an issue with genphy_c45_an_config_eee_aneg() (called from genphy_c45_ethtool_set_eee) not seeing the new value of phydev->eee_cfg.eee_enabled.
--- drivers/net/phy/phy.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/net/phy/phy.c +14 -10
@@ -1672,7 +1672,7 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);* phy_ethtool_set_eee_noneg - Adjusts MAC LPI configuration without PHY * renegotiation * @phydev: pointer to the target PHY device structure -* @data: pointer to the ethtool_keee structure containing the new EEE settings +* @old_cfg: pointer to the eee_config structure containing the old EEE settings * * This function updates the Energy Efficient Ethernet (EEE) configuration * for cases where only the MAC's Low Power Idle (LPI) configuration changes,
@@ -1683,11 +1683,10 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);* configuration. */ static void phy_ethtool_set_eee_noneg (struct phy_device *phydev, -struct ethtool_keee *data) +const struct eee_config *old_cfg) { -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); +if (phydev->eee_cfg.tx_lpi_enabled != old_cfg->tx_lpi_enabled || + phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) { phydev->enable_tx_lpi =eeecfg_mac_can_tx_lpi (&phydev->eee_cfg);if (phydev->link) { phydev->link = false;
@@ -1707,18 +1706,23 @@ static void phy_ethtool_set_eee_noneg(struct phy_device *phydev,*/ int phy_ethtool_set_eee (struct phy_device *phydev,struct ethtool_keee *data) { +struct eee_config old_cfg;int ret;if (!phydev->drv)return -EIO ;mutex_lock (&phydev->lock); + + old_cfg = phydev->eee_cfg; +eee_to_eeecfg (&phydev->eee_cfg, data); + ret =genphy_c45_ethtool_set_eee (phydev, data); -if (ret >=0 ) { -if (ret ==0 ) -phy_ethtool_set_eee_noneg (phydev, data); -eee_to_eeecfg (&phydev->eee_cfg, data); - } +if (ret ==0 ) +phy_ethtool_set_eee_noneg (phydev, &old_cfg); +else if (ret <0 ) + phydev->eee_cfg = old_cfg; +mutex_unlock (&phydev->lock);return ret <0 ? ret :0 ;
Signature · 1 line
2.30.2
RFC PATCH 2/23 net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
In reply to Russell King (Oracle)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 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 | 30 ++++++++++++++++++------------ include/linux/phy.h | 2 ++ 3 files changed, 21 insertions(+), 13 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 -12
@@ -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,15 +1685,21 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,const struct eee_config *old_cfg) { -if (phydev->eee_cfg.tx_lpi_enabled != old_cfg->tx_lpi_enabled || +bool enable_tx_lpi; + +if (!phydev->link) +return ; + + enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; + +if (phydev->enable_tx_lpi != enable_tx_lpi || phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) { - 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); - } + 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 +2 -0
@@ -602,6 +602,7 @@ struct macsec_ops;* @supported_eee: supported PHY EEE linkmodes * @advertising_eee: Currently advertised EEE linkmodes * @enable_tx_lpi: When True, MAC should transmit LPI to PHY +* @eee_active: phylib private state, indicating that EEE has been negotiated * @eee_cfg: User configuration of EEE * @lp_advertising: Current link partner advertised linkmodes * @host_interfaces: PHY interface modes supported by host
@@ -723,6 +724,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
Russell King (Oracle)
maintainerRe: [PATCH RFC net-next 02/23] net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
Quoted 4 lines · Russell King (Oracle)
drivers/net/phy/phy.c +0
-0@@ -1685,15 +1685,21 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,const struct eee_config *old_cfg) {
drivers/net/phy/phy.c EXPORT_SYMBOL(phy_ethtool_get_eee); · line 1696
Quoted 10 lines
drivers/net/phy/phy.c +8
-1-if (phydev->eee_cfg.tx_lpi_enabled != old_cfg->tx_lpi_enabled || +bool enable_tx_lpi; + +if (!phydev->link) +return ; + + enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; + +if (phydev->enable_tx_lpi != enable_tx_lpi || phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {
I'm wondering whether this should be:
if (phydev->enable_tx_lpi != enable_tx_lpi ||
(phydev->enable_tx_lpi &&
phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer)) {The argument for this change would be to avoid cycling the link when the LPI timer changes but we're not using LPI.
The argument against this change would be that then we don't program the hardware, and if the driver reads the initial value from hardware and is unbound/rebound, we'll lose that update whereas before the phylib changes, it would have been preserved.
The problem, however, are drivers where the LPI timer is dependent on the speed.
Any thoughts?
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!
Re: [PATCH RFC net-next 02/23] net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
Quoted 30 lines · Russell King (Oracle)
Quoted 4 lines · Russell King (Oracle)
drivers/net/phy/phy.c +0
-0@@ -1685,15 +1685,21 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,const struct eee_config *old_cfg) {drivers/net/phy/phy.c EXPORT_SYMBOL(phy_ethtool_get_eee); · line 1696
Quoted 10 lines
drivers/net/phy/phy.c +8
-1-if (phydev->eee_cfg.tx_lpi_enabled != old_cfg->tx_lpi_enabled || +bool enable_tx_lpi; + +if (!phydev->link) +return ; + + enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; + +if (phydev->enable_tx_lpi != enable_tx_lpi || phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {I'm wondering whether this should be:
if (phydev->enable_tx_lpi != enable_tx_lpi || (phydev->enable_tx_lpi && phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer)) {The argument for this change would be to avoid cycling the link when the LPI timer changes but we're not using LPI.
The argument against this change would be that then we don't program the hardware, and if the driver reads the initial value from hardware and is unbound/rebound, we'll lose that update whereas before the phylib changes, it would have been preserved.
Quoted 4 lines
The problem, however, are drivers where the LPI timer is dependent on the speed.
Any thoughts?
So far, i was not able to find any. But, like I said before, to get optimal performance and power saving balance, the lpi_timer should be link speed specific... at least, some day with appropriate user interface.
Signature · 4 lines
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 |
Andrew Lunn
maintainerRe: [PATCH RFC net-next 02/23] net: phy: fix phy_ethtool_set_eee() incorrectly enabling LPI
In reply to Russell King (Oracle)Quoted 22 lines · Russell King (Oracle)
Quoted 4 lines · Russell King (Oracle)
drivers/net/phy/phy.c +0
-0@@ -1685,15 +1685,21 @@ EXPORT_SYMBOL(phy_ethtool_get_eee);static void phy_ethtool_set_eee_noneg (struct phy_device *phydev,const struct eee_config *old_cfg) {drivers/net/phy/phy.c EXPORT_SYMBOL(phy_ethtool_get_eee); · line 1696
Quoted 10 lines
drivers/net/phy/phy.c +8
-1-if (phydev->eee_cfg.tx_lpi_enabled != old_cfg->tx_lpi_enabled || +bool enable_tx_lpi; + +if (!phydev->link) +return ; + + enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; + +if (phydev->enable_tx_lpi != enable_tx_lpi || phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) {I'm wondering whether this should be:
if (phydev->enable_tx_lpi != enable_tx_lpi || (phydev->enable_tx_lpi && phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer)) {
Quoted 7 lines
The argument for this change would be to avoid cycling the link when the LPI timer changes but we're not using LPI.
The argument against this change would be that then we don't program the hardware, and if the driver reads the initial value from hardware and is unbound/rebound, we'll lose that update whereas before the phylib changes, it would have been preserved.
unbound/rebound is a pretty unusual use case. I would not consider that a strong argument against it.
This is the case where we don't need to perform negotiation. So it is going to be a fast operation compared to when we do need negotiation. So i wounder if we really need to care? Donald Knuth, Premature optimisation is the root of all evil, etc...
Andrew
RFC PATCH 3/23 net: phy: marvell: use phydev->eee_cfg.eee_enabled
In reply to Russell King (Oracle)Rather than calling genphy_c45_ethtool_get_eee() to retrieve whether EEE is enabled, use the value stored in the phy_device eee_cfg structure.
--- drivers/net/phy/marvell.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/phy/marvell.c +1 -3
@@ -1508,7 +1508,6 @@ static int m88e1540_get_fld(struct phy_device *phydev, u8 *msecs)static int m88e1540_set_fld (struct phy_device *phydev,const u8 *msecs) { -struct ethtool_keee eee;int val, ret;if (*msecs ==ETHTOOL_PHY_FAST_LINK_DOWN_OFF )
@@ -1518,8 +1517,7 @@ static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs)/* According to the Marvell data sheet EEE must be disabled for * Fast Link Down detection to work properly */ - ret =genphy_c45_ethtool_get_eee (phydev, &eee); -if (!ret && eee.eee_enabled) { +if (phydev->eee_cfg.eee_enabled) {phydev_warn (phydev,"Fast Link Down detection requires EEE to be disabled!\n" );return -EBUSY ; }
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 03/23] net: phy: marvell: use phydev->eee_cfg.eee_enabled
Quoted 22 lines · Russell King (Oracle)
Rather than calling
genphy_c45_ethtool_get_eee()to retrieve whether EEE is enabled, use the value stored in thephy_deviceeee_cfgstructure.Signed-off-by Russell King (Oracle) <[email protected]>--- drivers/net/phy/marvell.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/net/phy/marvell.c +0
-1@@ -1508,7 +1508,6 @@ static int m88e1540_get_fld(struct phy_device *phydev, u8 *msecs)static int m88e1540_set_fld (struct phy_device *phydev,const u8 *msecs) { -struct ethtool_keee eee;int val, ret;if (*msecs ==ETHTOOL_PHY_FAST_LINK_DOWN_OFF )
drivers/net/phy/marvell.c static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs) · line 1523
Quoted 9 lines
drivers/net/phy/marvell.c +1
-2@@ -1518,8 +1517,7 @@ static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs)/* According to the Marvell data sheet EEE must be disabled for * Fast Link Down detection to work properly */ - ret =genphy_c45_ethtool_get_eee (phydev, &eee); -if (!ret && eee.eee_enabled) { +if (phydev->eee_cfg.eee_enabled) {phydev_warn (phydev,"Fast Link Down detection requires EEE to be disabled!\n" );return -EBUSY ; }
This one I had on my list too. Old and new check aren't waterproof as the user can still enable EEE later, silently disabling FLD. But the check is better than nothing.
RFC PATCH 4/23 net: phy: avoid genphy_c45_ethtool_get_eee() setting eee_enabled
In reply to Russell King (Oracle)genphy_c45_ethtool_get_eee() is only called from phy_ethtool_get_eee(), which then calls eeecfg_to_eee(). eeecfg_to_eee() will overwrite keee.eee_enabled, so there's no point setting keee.eee_enabled in genphy_c45_ethtool_get_eee(). Remove this assignment.
--- drivers/net/phy/phy-c45.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/phy/phy-c45.c +1 -3
@@ -1521,15 +1521,13 @@ EXPORT_SYMBOL(genphy_c45_eee_is_active);int genphy_c45_ethtool_get_eee (struct phy_device *phydev,struct ethtool_keee *data) { -bool is_enabled;int ret; ret =genphy_c45_eee_is_active (phydev, data->advertised, - data->lp_advertised, &is_enabled); + data->lp_advertised,NULL );if (ret <0 )return ret; - data->eee_enabled = is_enabled; data->eee_active = phydev->eee_active;linkmode_copy (data->supported, phydev->supported_eee);
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 04/23] net: phy: avoid genphy_c45_ethtool_get_eee() setting eee_enabled
Quoted 7 lines · Russell King (Oracle)
genphy_c45_ethtool_get_eee()is only called fromphy_ethtool_get_eee(), which then callseeecfg_to_eee().eeecfg_to_eee()will overwrite keee.eee_enabled, so there's no point setting keee.eee_enabled ingenphy_c45_ethtool_get_eee(). Remove this assignment.Signed-off-by Russell King (Oracle) <[email protected]>---
RFC PATCH 5/23 net: phy: remove genphy_c45_eee_is_active()'s is_enabled arg
In reply to Russell King (Oracle)All callers to genphy_c45_eee_is_active() now pass NULL as the is_enabled argument, which means we never use the value computed in this function. Remove the argument and clean up this function.
--- drivers/net/phy/phy-c45.c | 11 ++++------- drivers/net/phy/phy.c | 5 ++--- include/linux/phy.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-)
drivers/net/phy/phy-c45.c +4 -7
@@ -1475,12 +1475,12 @@ EXPORT_SYMBOL_GPL(genphy_c45_plca_get_status);* advertisements. Compare them return current EEE state. */ int genphy_c45_eee_is_active (struct phy_device *phydev,unsigned long *adv, -unsigned long *lp,bool *is_enabled) +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_enabled, eee_active; +bool eee_active;int ret; ret =genphy_c45_read_eee_adv (phydev, tmp_adv);
@@ -1491,9 +1491,8 @@ int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,if (ret)return ret; - eee_enabled = !linkmode_empty (tmp_adv);linkmode_and (common, tmp_adv, tmp_lp); -if (eee_enabled && !linkmode_empty (common)) +if (!linkmode_empty (tmp_adv) && !linkmode_empty (common)) eee_active =phy_check_valid (phydev->speed, phydev->duplex, common);else
@@ -1503,8 +1502,6 @@ int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,linkmode_copy (adv, tmp_adv);if (lp)linkmode_copy (lp, tmp_lp); -if (is_enabled) - *is_enabled = eee_enabled;return eee_active; }
@@ -1524,7 +1521,7 @@ int genphy_c45_ethtool_get_eee(struct phy_device *phydev,int ret; ret =genphy_c45_eee_is_active (phydev, data->advertised, - data->lp_advertised,NULL ); + data->lp_advertised);if (ret <0 )return ret;
drivers/net/phy/phy.c +2 -3
@@ -988,8 +988,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 ,NULL ); + err =genphy_c45_eee_is_active (phydev,NULL ,NULL ); phydev->eee_active = err >0 ; phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active;
@@ -1605,7 +1604,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 ,NULL ); + ret =genphy_c45_eee_is_active (phydev,NULL ,NULL );if (ret <0 )return ret;if (!ret)
include/linux/phy.h +1 -1
@@ -1957,7 +1957,7 @@ int genphy_c45_plca_set_cfg(struct phy_device *phydev,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,bool *is_enabled); +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,
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 05/23] net: phy: remove genphy_c45_eee_is_active()'s is_enabled arg
Quoted 6 lines · Russell King (Oracle)
All callers to
genphy_c45_eee_is_active()now pass NULL as theis_enabledargument, which means we never use the value computed in this function. Remove the argument and clean up this function.Signed-off-by Russell King (Oracle) <[email protected]>---
Eventually we should be able to get rid also of the adv argument and use phydev->advertising_eee only. Prerequisite is rework of eee_broken_modes. I have patches which I'm testing locally currently. This can be a follow-up to your series.
kernel test robot
build botRe: [PATCH RFC net-next 05/23] net: phy: remove genphy_c45_eee_is_active()'s is_enabled arg
In reply to Russell King (Oracle)kernel test robot noticed the following build warnings:
Hi Russell,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Russell-King/net-phy-ensure-that-genphy_c45_an_config_eee_aneg-sees-new-value-of-phydev-eee_cfg-eee_enabled/20241128-140608 base: net-next/main patch link: https://lore.kernel.org/r/E1tFv3U-005yhl-LJ%40rmk-PC.armlinux.org.uk patch subject: [PATCH RFC net-next 05/23] net: phy: remove genphy_c45_eee_is_active()'s is_enabled arg config: arm-spear13xx_defconfig (https://download.01.org/0day-ci/archive/20241128/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241128/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/phy/phy-c45.c:1479: warning: Excess function parameter 'is_enabled' description in 'genphy_c45_eee_is_active'
vim +1479 drivers/net/phy/phy-c45.c
493323416fed6b Piergiorgio Beruto 2023-01-09 1466
022c3f87f88e2d Oleksij Rempel 2023-02-11 1467 /**
022c3f87f88e2d Oleksij Rempel 2023-02-11 1468 * genphy_c45_eee_is_active - get EEE status
022c3f87f88e2d Oleksij Rempel 2023-02-11 1469 * @phydev: target phy_device struct
022c3f87f88e2d Oleksij Rempel 2023-02-11 1470 * @adv: variable to store advertised linkmodes
022c3f87f88e2d Oleksij Rempel 2023-02-11 1471 * @lp: variable to store LP advertised linkmodes
022c3f87f88e2d Oleksij Rempel 2023-02-11 1472 * @is_enabled: variable to store EEE enabled/disabled configuration value
022c3f87f88e2d Oleksij Rempel 2023-02-11 1473 *
022c3f87f88e2d Oleksij Rempel 2023-02-11 1474 * Description: this function will read local and link partner PHY
022c3f87f88e2d Oleksij Rempel 2023-02-11 1475 * advertisements. Compare them return current EEE state.
022c3f87f88e2d Oleksij Rempel 2023-02-11 1476 */
022c3f87f88e2d Oleksij Rempel 2023-02-11 1477 int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv,
de71eda2a2fb82 Russell King (Oracle 2024-11-26 1478) unsigned long *lp)
022c3f87f88e2d Oleksij Rempel 2023-02-11 @1479 {
022c3f87f88e2d Oleksij Rempel 2023-02-11 1480 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_adv) = {};
022c3f87f88e2d Oleksij Rempel 2023-02-11 1481 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_lp) = {};
022c3f87f88e2d Oleksij Rempel 2023-02-11 1482 __ETHTOOL_DECLARE_LINK_MODE_MASK(common);
de71eda2a2fb82 Russell King (Oracle 2024-11-26 1483) bool eee_active;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1484 int ret;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1485
022c3f87f88e2d Oleksij Rempel 2023-02-11 1486 ret = genphy_c45_read_eee_adv(phydev, tmp_adv);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1487 if (ret)
022c3f87f88e2d Oleksij Rempel 2023-02-11 1488 return ret;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1489
022c3f87f88e2d Oleksij Rempel 2023-02-11 1490 ret = genphy_c45_read_eee_lpa(phydev, tmp_lp);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1491 if (ret)
022c3f87f88e2d Oleksij Rempel 2023-02-11 1492 return ret;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1493
022c3f87f88e2d Oleksij Rempel 2023-02-11 1494 linkmode_and(common, tmp_adv, tmp_lp);
de71eda2a2fb82 Russell King (Oracle 2024-11-26 1495) if (!linkmode_empty(tmp_adv) && !linkmode_empty(common))
022c3f87f88e2d Oleksij Rempel 2023-02-11 1496 eee_active = phy_check_valid(phydev->speed, phydev->duplex,
022c3f87f88e2d Oleksij Rempel 2023-02-11 1497 common);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1498 else
022c3f87f88e2d Oleksij Rempel 2023-02-11 1499 eee_active = false;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1500
022c3f87f88e2d Oleksij Rempel 2023-02-11 1501 if (adv)
022c3f87f88e2d Oleksij Rempel 2023-02-11 1502 linkmode_copy(adv, tmp_adv);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1503 if (lp)
022c3f87f88e2d Oleksij Rempel 2023-02-11 1504 linkmode_copy(lp, tmp_lp);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1505
022c3f87f88e2d Oleksij Rempel 2023-02-11 1506 return eee_active;
022c3f87f88e2d Oleksij Rempel 2023-02-11 1507 }
022c3f87f88e2d Oleksij Rempel 2023-02-11 1508 EXPORT_SYMBOL(genphy_c45_eee_is_active);
022c3f87f88e2d Oleksij Rempel 2023-02-11 1509 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 6/23 net: phy: update phy_ethtool_get_eee() documentation
In reply to Russell King (Oracle)Update the phy_ethtool_get_eee() documentation to make it clear that all members of struct ethtool_keee are written by this function.
keee.supported, keee.advertised, keee.lp_advertised and keee.eee_active are all written by genphy_c45_ethtool_get_eee().
keee.tx_lpi_timer, keee.tx_lpi_enabled and keee.eee_enabled are all written by eeecfg_to_eee().
--- drivers/net/phy/phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +2 -2
@@ -1648,8 +1648,8 @@ EXPORT_SYMBOL(phy_get_eee_err);* @phydev: target phy_device struct * @data: ethtool_keee data * -* Description: reports the Supported/Advertisement/LP Advertisement -* capabilities, etc. +* Description: get the current EEE settings, filling in all members of +* @data. */ int phy_ethtool_get_eee (struct phy_device *phydev,struct ethtool_keee *data) {
Signature · 1 line
2.30.2
RFC PATCH 7/23 net: mdio: add definition for clock stop capable bit
In reply to Russell King (Oracle)Add a definition for the clock stop capable bit in the PCS MMD. This bit indicates whether the MAC is able to stop the transmit xMII clock while it is signalling LPI.
--- include/uapi/linux/mdio.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/mdio.h +1 -0
@@ -125,6 +125,7 @@#define MDIO_STAT1_LPOWERABLE 0x0002/* Low-power ability */ #define MDIO_STAT1_LSTATUS BMSR_LSTATUS#define MDIO_STAT1_FAULT 0x0080/* Fault */ +#define MDIO_PCS_STAT1_CLKSTOP_CAP 0x0040#define MDIO_AN_STAT1_LPABLE 0x0001/* Link partner AN ability */ #define MDIO_AN_STAT1_ABLE BMSR_ANEGCAPABLE#define MDIO_AN_STAT1_RFAULT BMSR_RFAULT
Signature · 1 line
2.30.2
RFC PATCH 8/23 net: phy: add support for querying PHY clock stop capability
In reply to Russell King (Oracle)Add support for querying whether the PHY allows the transmit xMII clock to be stopped while in LPI mode. This will be used by phylink to pass to the MAC driver so it can configure the generation of the xMII clock appropriately.
--- drivers/net/phy/phy.c | 20 ++++++++++++++++++++ include/linux/phy.h | 1 + 2 files changed, 21 insertions(+)
drivers/net/phy/phy.c +20 -0
@@ -1587,6 +1587,26 @@ void phy_mac_interrupt(struct phy_device *phydev) }EXPORT_SYMBOL (phy_mac_interrupt); +/** +* phy_eee_tx_clock_stop_capable() - indicate whether the MAC can stop tx clock +* @phydev: target phy_device struct +* +* Indicate whether the MAC can disable the transmit xMII clock while in LPI +* state. Returns 1 if the MAC may stop the transmit clock, 0 if the MAC must +* not stop the transmit clock, or negative error. +*/ +int phy_eee_tx_clock_stop_capable (struct phy_device *phydev) +{ +int stat1; + + stat1 =phy_read_mmd (phydev,MDIO_MMD_PCS ,MDIO_STAT1 ); +if (stat1 <0 ) +return stat1; + +return !!(stat1 &MDIO_PCS_STAT1_CLKSTOP_CAP ); +} +EXPORT_SYMBOL_GPL (phy_eee_tx_clock_stop_capable); +/** * phy_init_eee - init and check the EEE feature * @phydev: target phy_device struct
include/linux/phy.h +1 -0
@@ -2038,6 +2038,7 @@ int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);int phy_unregister_fixup_for_id (const char *bus_id);int phy_unregister_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask); +int phy_eee_tx_clock_stop_capable (struct phy_device *phydev);int phy_init_eee (struct phy_device *phydev,bool clk_stop_enable);int phy_get_eee_err (struct phy_device *phydev);int phy_ethtool_set_eee (struct phy_device *phydev,struct ethtool_keee *data);
Signature · 1 line
2.30.2
RFC PATCH 9/23 net: phy: add configuration of rx clock stop mode
In reply to Russell King (Oracle)Add a function to allow configuration of the PCS's clock stop enable bit, used to configure whether the xMII receive clock can be stopped during LPI mode.
--- drivers/net/phy/phy.c | 25 ++++++++++++++++++++----- include/linux/phy.h | 1 + 2 files changed, 21 insertions(+), 5 deletions(-)
drivers/net/phy/phy.c +20 -5
@@ -1607,6 +1607,25 @@ int phy_eee_tx_clock_stop_capable(struct phy_device *phydev) }EXPORT_SYMBOL_GPL (phy_eee_tx_clock_stop_capable); +/** +* phy_eee_rx_clock_stop() - configure PHY receive clock in LPI +* phydev: target phy_device struct +* +* Configure whether the PHY may disable its receive clock during LPI mode, +* See IEEE 802.3 sections 22.2.2.2, 35.2.2.10, and 45.2.3.1.4. Returns 0 or +* negative error. +*/ +int phy_eee_rx_clock_stop (struct phy_device *phydev,bool clk_stop_enable) +{ +/* Configure the PHY to stop receiving xMII +* clock while it is signaling LPI. +*/ +return phy_modify_mmd (phydev,MDIO_MMD_PCS ,MDIO_CTRL1 , +MDIO_PCS_CTRL1_CLKSTOP_EN , + clk_stop_enable ?MDIO_PCS_CTRL1_CLKSTOP_EN :0 ); +} +EXPORT_SYMBOL_GPL (phy_eee_rx_clock_stop); +/** * phy_init_eee - init and check the EEE feature * @phydev: target phy_device struct
@@ -1631,11 +1650,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)return -EPROTONOSUPPORT ;if (clk_stop_enable) -/* Configure the PHY to stop receiving xMII -* clock while it is signaling LPI. -*/ - ret =phy_set_bits_mmd (phydev,MDIO_MMD_PCS ,MDIO_CTRL1 , -MDIO_PCS_CTRL1_CLKSTOP_EN ); + ret =phy_eee_rx_clock_stop (phydev, true);return ret <0 ? ret :0 ; }
include/linux/phy.h +1 -0
@@ -2039,6 +2039,7 @@ int phy_unregister_fixup_for_id(const char *bus_id);int phy_unregister_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask);int phy_eee_tx_clock_stop_capable (struct phy_device *phydev); +int phy_eee_rx_clock_stop (struct phy_device *phydev,bool clk_stop_enable);int phy_init_eee (struct phy_device *phydev,bool clk_stop_enable);int phy_get_eee_err (struct phy_device *phydev);int phy_ethtool_set_eee (struct phy_device *phydev,struct ethtool_keee *data);
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH RFC net-next 09/23] net: phy: add configuration of rx clock stop mode
kernel test robot noticed the following build warnings:
Hi Russell,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Russell-King/net-phy-ensure-that-genphy_c45_an_config_eee_aneg-sees-new-value-of-phydev-eee_cfg-eee_enabled/20241128-140608 base: net-next/main patch link: https://lore.kernel.org/r/E1tFv3p-005yi9-3F%40rmk-PC.armlinux.org.uk patch subject: [PATCH RFC net-next 09/23] net: phy: add configuration of rx clock stop mode config: arm-spear13xx_defconfig (https://download.01.org/0day-ci/archive/20241128/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241128/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/phy/phy.c:1619: warning: Function parameter or struct member 'phydev' not described in 'phy_eee_rx_clock_stop' >> drivers/net/phy/phy.c:1619: warning: Function parameter or struct member 'clk_stop_enable' not described in 'phy_eee_rx_clock_stop'
vim +1619 drivers/net/phy/phy.c
1609
1610 /**
1611 * phy_eee_rx_clock_stop() - configure PHY receive clock in LPI
1612 * phydev: target phy_device struct
1613 *
1614 * Configure whether the PHY may disable its receive clock during LPI mode,
1615 * See IEEE 802.3 sections 22.2.2.2, 35.2.2.10, and 45.2.3.1.4. Returns 0 or
1616 * negative error.
1617 */
1618 int phy_eee_rx_clock_stop(struct phy_device *phydev, bool clk_stop_enable)
> 1619 { 1620 /* Configure the PHY to stop receiving xMII
1621 * clock while it is signaling LPI.
1622 */
1623 return phy_modify_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1,
1624 MDIO_PCS_CTRL1_CLKSTOP_EN,
1625 clk_stop_enable ? MDIO_PCS_CTRL1_CLKSTOP_EN : 0);
1626 }
1627 EXPORT_SYMBOL_GPL(phy_eee_rx_clock_stop);
1628
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 10/23 net: phylink: add phylink_link_is_up() helper
In reply to Russell King (Oracle)Add a helper to determine whether the link is up or down. Currently this is only used in one location, but becomes necessary to test when reconfiguring EEE.
--- drivers/net/phy/phylink.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/phy/phylink.c +6 -5
@@ -1442,20 +1442,21 @@ static void phylink_link_down(struct phylink *pl)phylink_info (pl,"Link is Down\n" ); } +static bool phylink_link_is_up (struct phylink *pl) +{ +return pl->netdev ?netif_carrier_ok (pl->netdev) : pl->old_link_state; +} +static void phylink_resolve (struct work_struct *w) { struct phylink *pl = container_of(w, struct phylink, resolve);struct phylink_link_state link_state; -struct net_device *ndev = pl->netdev;bool mac_config = false;bool retrigger = false;bool cur_link_state;mutex_lock (&pl->state_mutex); -if (pl->netdev) - cur_link_state =netif_carrier_ok (ndev); -else - cur_link_state = pl->old_link_state; + cur_link_state =phylink_link_is_up (pl);if (pl->phylink_disable_state) { pl->link_failed = false;
Signature · 1 line
2.30.2
RFC PATCH 11/23 net: phylink: add EEE management
In reply to Russell King (Oracle)Add EEE management to phylink, making use of the phylib implementation. This will only be used where a MAC driver populates the methods and capabilities bitfield, otherwise we keep our old behaviour.
Phylink will keep track of the EEE configuration, including the clock stop abilities at each end of the MAC to PHY link, programming the PHY appropriately and preserving the EEE configuration should the PHY go away.
It will also call into the MAC driver when LPI needs to be enabled or disabled, with the expectation that the MAC have LPI disabled during probe.
Support for phylink managed EEE is enabled by populating both tx_lpi MAC operations method pointers.
--- drivers/net/phy/phylink.c | 123 ++++++++++++++++++++++++++++++++++++-- include/linux/phylink.h | 44 ++++++++++++++ 2 files changed, 163 insertions(+), 4 deletions(-)
drivers/net/phy/phylink.c +119 -4
@@ -79,12 +79,19 @@ struct phylink {unsigned int pcs_state;bool link_failed; +bool mac_supports_eee; +bool phy_enable_tx_lpi; +bool mac_enable_tx_lpi; +bool mac_tx_clk_stop; +u32 mac_tx_lpi_timer;struct sfp_bus *sfp_bus;bool sfp_may_have_phy;DECLARE_PHY_INTERFACE_MASK (sfp_interfaces);__ETHTOOL_DECLARE_LINK_MODE_MASK (sfp_support);u8 sfp_port; + +struct eee_config eee_cfg; };#define phylink_printk (level, pl, fmt, ...) \
@@ -1375,6 +1382,47 @@ static const char *phylink_pause_to_str(int pause) } } +static void phylink_deactivate_lpi (struct phylink *pl) +{ +if (pl->mac_enable_tx_lpi) { + pl->mac_enable_tx_lpi = false; + +phylink_dbg (pl,"disabling LPI\n" ); + + pl->mac_ops->mac_disable_tx_lpi (pl->config); + } +} + +static void phylink_activate_lpi (struct phylink *pl) +{ +if (!test_bit (pl->cur_interface, pl->config->lpi_interfaces)) { +phylink_dbg (pl,"MAC does not support LPI with %s\n" , +phy_modes (pl->cur_interface)); +return ; + } + +phylink_dbg (pl,"LPI timer %uus, tx clock stop %u\n" , + pl->mac_tx_lpi_timer, pl->mac_tx_clk_stop); + + pl->mac_ops->mac_enable_tx_lpi (pl->config, pl->mac_tx_lpi_timer, + pl->mac_tx_clk_stop); + + pl->mac_enable_tx_lpi = true; +} + +static void phylink_phy_restrict_eee (struct phylink *pl,struct phy_device *phy) +{ +__ETHTOOL_DECLARE_LINK_MODE_MASK (eee_supported); + +/* Convert the MAC's LPI capabilities to linkmodes */ +linkmode_zero (eee_supported); +phylink_caps_to_linkmodes (eee_supported, pl->config->lpi_capabilities); + +/* Mask out EEE modes that are not supported */ +linkmode_and (phy->supported_eee, phy->supported_eee, eee_supported); +linkmode_and (phy->advertising_eee, phy->advertising_eee, eee_supported); +} +static void phylink_link_up (struct phylink *pl,struct phylink_link_state link_state) {
@@ -1421,6 +1469,9 @@ static void phylink_link_up(struct phylink *pl, pl->cur_interface, speed, duplex, !!(link_state.pause & MLO_PAUSE_TX), rx_pause); +if (pl->mac_supports_eee && pl->phy_enable_tx_lpi) +phylink_activate_lpi (pl); +if (ndev)netif_carrier_on (ndev);
@@ -1437,6 +1488,9 @@ static void phylink_link_down(struct phylink *pl)if (ndev)netif_carrier_off (ndev); + +phylink_deactivate_lpi (pl); + pl->mac_ops->mac_link_down (pl->config, pl->cur_link_an_mode, pl->cur_interface);phylink_info (pl,"Link is Down\n" );
@@ -1700,6 +1754,14 @@ struct phylink *phylink_create(struct phylink_config *config,return ERR_PTR (-EINVAL ); } + pl->mac_supports_eee = mac_ops->mac_disable_tx_lpi && + mac_ops->mac_enable_tx_lpi; + +/* Set the default EEE configuration */ + pl->eee_cfg.eee_enabled = pl->config->eee_enabled_default; + pl->eee_cfg.tx_lpi_enabled = pl->eee_cfg.eee_enabled; + pl->eee_cfg.tx_lpi_timer = pl->config->lpi_timer_default; + pl->phy_state.interface = iface; pl->link_interface = iface;if (iface ==PHY_INTERFACE_MODE_MOCA )
@@ -1804,16 +1866,22 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) pl->phy_state.link = up;if (!up) pl->link_failed = true; + +/* Get the LPI state from phylib */ + pl->phy_enable_tx_lpi = phydev->enable_tx_lpi; + pl->mac_tx_lpi_timer = phydev->eee_cfg.tx_lpi_timer;mutex_unlock (&pl->state_mutex);phylink_run_resolve (pl); -phylink_dbg (pl,"phy link %s %s/%s/%s/%s/%s\n" , up ?"up" :"down" , +phylink_dbg (pl,"phy link %s %s/%s/%s/%s/%s/%slpi\n" , + up ?"up" :"down" ,phy_modes (phydev->interface),phy_speed_to_str (phydev->speed),phy_duplex_to_str (phydev->duplex),phy_rate_matching_to_str (phydev->rate_matching), -phylink_pause_to_str (pl->phy_state.pause)); +phylink_pause_to_str (pl->phy_state.pause), + phydev->enable_tx_lpi ?"" :"no" ); } static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy,
@@ -1943,6 +2011,28 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,/* Restrict the phy advertisement according to the MAC support. */ linkmode_copy (phy->advertising, config.advertising); + +/* If the MAC supports phylink managed EEE, restrict the EEE +* advertisement according to the MAC's LPI capabilities. +*/ +if (pl->mac_supports_eee) { + phy->eee_cfg.eee_enabled = pl->eee_cfg.eee_enabled; + +/* If EEE is enabled, then we need to call phy_support_eee() +* to ensure that the advertising mask is appropriately set. +*/ +if (pl->eee_cfg.eee_enabled) +phy_support_eee (phy); + + phy->eee_cfg.tx_lpi_enabled = pl->eee_cfg.tx_lpi_enabled; + phy->eee_cfg.tx_lpi_timer = pl->eee_cfg.tx_lpi_timer; + +/* Restrict the PHYs EEE support/advertisement to the modes +* that the MAC supports. +*/ +phylink_phy_restrict_eee (pl, phy); + } +mutex_unlock (&pl->state_mutex);mutex_unlock (&phy->lock);
@@ -1958,7 +2048,13 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,if (pl->config->mac_managed_pm) phy->mac_managed_pm = true; -return 0 ; +/* Allow the MAC to stop its clock if the PHY has the capability */ + pl->mac_tx_clk_stop =phy_eee_tx_clock_stop_capable (phy) >0 ; + +/* Explicitly configure whether the PHY is allowed to stop it's +* receive clock. +*/ +return phy_eee_rx_clock_stop (phy, pl->config->eee_rx_clk_stop_enable); } static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,
@@ -2115,6 +2211,8 @@ void phylink_disconnect_phy(struct phylink *pl)mutex_lock (&phy->lock);mutex_lock (&pl->state_mutex); pl->phydev =NULL ; + pl->phy_enable_tx_lpi = false; + pl->mac_tx_clk_stop = false;mutex_unlock (&pl->state_mutex);mutex_unlock (&phy->lock);flush_work (&pl->resolve);
@@ -2856,12 +2954,29 @@ EXPORT_SYMBOL_GPL(phylink_ethtool_get_eee);*/ int phylink_ethtool_set_eee (struct phylink *pl,struct ethtool_keee *eee) { +bool mac_eee = pl->mac_supports_eee;int ret = -EOPNOTSUPP ;ASSERT_RTNL (); -if (pl->phydev) +phylink_dbg (pl,"mac %s phylink EEE%s, adv %*pbl, LPI%s timer %uus\n" , + mac_eee ?"supports" :"does not support" , + eee->eee_enabled ?", enabled" :"" , + __ETHTOOL_LINK_MODE_MASK_NBITS, eee->advertised, + eee->tx_lpi_enabled ?" enabled" :"" , eee->tx_lpi_timer); + +/* Clamp the LPI timer maximum value */ +if (mac_eee && eee->tx_lpi_timer > pl->config->lpi_timer_limit_us) { + eee->tx_lpi_timer = pl->config->lpi_timer_limit_us; +phylink_dbg (pl,"LPI timer limited to %uus\n" , + eee->tx_lpi_timer); + } + +if (pl->phydev) { ret =phy_ethtool_set_eee (pl->phydev, eee); +if (ret ==0 ) +eee_to_eeecfg (&pl->eee_cfg, eee); + }return ret; }
include/linux/phylink.h +44 -0
89 lines not on this page · raw message
Signature · 1 line
2.30.2
RFC PATCH 12/23 net: mvneta: convert to phylink EEE implementation
In reply to Russell King (Oracle)Convert mvneta to use phylink's EEE implementation, which means we just need to implement the two methods for LPI control, and adding the initial configuration.
Disabling LPI requires clearing a single bit. Enabling LPI needs a full configuration of several values, as the timer values are dependent on the MAC operating speed.
--- drivers/net/ethernet/marvell/mvneta.c | 116 +++++++++++++++----------- 1 file changed, 68 insertions(+), 48 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +68 -48
@@ -284,8 +284,12 @@ MVNETA_TXQ_BUCKET_REFILL_PERIOD))#define MVNETA_LPI_CTRL_0 0x2cc0 +#define MVNETA_LPI_CTRL_0_TS (0xff << 8)#define MVNETA_LPI_CTRL_1 0x2cc4 -#define MVNETA_LPI_REQUEST_ENABLE BIT(0) +#define MVNETA_LPI_CTRL_1_REQUEST_ENABLE BIT(0) +#define MVNETA_LPI_CTRL_1_REQUEST_FORCE BIT(1) +#define MVNETA_LPI_CTRL_1_MANUAL_MODE BIT(2) +#define MVNETA_LPI_CTRL_1_TW (0xfff << 4)#define MVNETA_LPI_CTRL_2 0x2cc8#define MVNETA_LPI_STATUS 0x2ccc
@@ -541,10 +545,6 @@ struct mvneta_port {struct mvneta_bm_pool *pool_short;int bm_win_id; -bool eee_enabled; -bool eee_active; -bool tx_lpi_enabled; -u64 ethtool_stats[ARRAY_SIZE (mvneta_statistics)];u32 indir[MVNETA_RSS_LU_TABLE_SIZE ];
@@ -1354,6 +1354,13 @@ static void mvneta_port_enable(struct mvneta_port *pp) val =mvreg_read (pp,MVNETA_GMAC_CTRL_0 ); val |=MVNETA_GMAC0_PORT_ENABLE ;mvreg_write (pp,MVNETA_GMAC_CTRL_0 , val); + +/* Ensure LPI is disabled */ + val =mvreg_read (pp,MVNETA_LPI_CTRL_1 ); + val &= ~(MVNETA_LPI_CTRL_1_REQUEST_ENABLE | +MVNETA_LPI_CTRL_1_REQUEST_FORCE | +MVNETA_LPI_CTRL_1_MANUAL_MODE ); +mvreg_write (pp,MVNETA_LPI_CTRL_1 , val); }/* Disable the port and wait for about 200 usec before retuning */
@@ -4206,18 +4213,6 @@ static int mvneta_mac_finish(struct phylink_config *config, unsigned int mode,return 0 ; } -static void mvneta_set_eee (struct mvneta_port *pp,bool enable) -{ -u32 lpi_ctl1; - - lpi_ctl1 =mvreg_read (pp,MVNETA_LPI_CTRL_1 ); -if (enable) - lpi_ctl1 |=MVNETA_LPI_REQUEST_ENABLE ; -else - lpi_ctl1 &= ~MVNETA_LPI_REQUEST_ENABLE ; -mvreg_write (pp,MVNETA_LPI_CTRL_1 , lpi_ctl1); -} -static void mvneta_mac_link_down (struct phylink_config *config,unsigned int mode,phy_interface_t interface) {
@@ -4233,9 +4228,6 @@ static void mvneta_mac_link_down(struct phylink_config *config, val |=MVNETA_GMAC_FORCE_LINK_DOWN ;mvreg_write (pp,MVNETA_GMAC_AUTONEG_CONFIG , val); } - - pp->eee_active = false; -mvneta_set_eee (pp, false); } static void mvneta_mac_link_up(struct phylink_config *config,
@@ -4284,11 +4276,53 @@ static void mvneta_mac_link_up(struct phylink_config *config, }mvneta_port_up (pp); +} + +static void mvneta_mac_disable_tx_lpi (struct phylink_config *config) +{ +struct mvneta_port *pp =netdev_priv (to_net_dev (config->dev)); +u32 lpi1; + + lpi1 =mvreg_read (pp,MVNETA_LPI_CTRL_1 ); + lpi1 &= ~MVNETA_LPI_CTRL_1_REQUEST_ENABLE ; +mvreg_write (pp,MVNETA_LPI_CTRL_1 , lpi1); +} + +static void mvneta_mac_enable_tx_lpi (struct phylink_config *config,u32 timer, +bool tx_clk_stop) +{ +struct mvneta_port *pp =netdev_priv (to_net_dev (config->dev)); +u32 ts, tw, lpi0, lpi1, status; -if (phy && pp->eee_enabled) { - pp->eee_active =phy_init_eee (phy, false) >=0 ; -mvneta_set_eee (pp, pp->eee_active && pp->tx_lpi_enabled); + status =mvreg_read (pp,MVNETA_GMAC_STATUS ); +if (status &MVNETA_GMAC_SPEED_1000 ) { +/* At 1G speeds, the timer resolution are 1us, and +* 802.3 says tw is 16.5us. Round up to 17us. +*/ + tw =17 ; + ts = timer; + }else { +/* At 100M speeds, the timer resolutions are 10us, and +* 802.3 says tw is 30us. +*/ + tw =3 ; + ts =DIV_ROUND_UP (timer,10 ); } + +if (ts >255 ) + ts =255 ; + + +/* Configure ts */ + lpi0 =mvreg_read (pp,MVNETA_LPI_CTRL_0 ); + lpi0 =u32_replace_bits (lpi0,MVNETA_LPI_CTRL_0_TS , ts); +mvreg_write (pp,MVNETA_LPI_CTRL_0 , lpi0); + +/* Configure tw and enable LPI generation */ + lpi1 =mvreg_read (pp,MVNETA_LPI_CTRL_1 ); + lpi1 =u32_replace_bits (lpi1,MVNETA_LPI_CTRL_1_TW , tw); + lpi1 |=MVNETA_LPI_CTRL_1_REQUEST_ENABLE ; +mvreg_write (pp,MVNETA_LPI_CTRL_1 , lpi1); }static const struct phylink_mac_ops mvneta_phylink_ops = {
@@ -4298,6 +4332,8 @@ static const struct phylink_mac_ops mvneta_phylink_ops = { .mac_finish = mvneta_mac_finish, .mac_link_down = mvneta_mac_link_down, .mac_link_up = mvneta_mac_link_up, + .mac_disable_tx_lpi = mvneta_mac_disable_tx_lpi, + .mac_enable_tx_lpi = mvneta_mac_enable_tx_lpi, };static int mvneta_mdio_probe (struct mvneta_port *pp)
@@ -5099,14 +5135,6 @@ static int mvneta_ethtool_get_eee(struct net_device *dev, struct ethtool_keee *eee) {struct mvneta_port *pp =netdev_priv (dev); -u32 lpi_ctl0; - - lpi_ctl0 =mvreg_read (pp,MVNETA_LPI_CTRL_0 ); - - eee->eee_enabled = pp->eee_enabled; - eee->eee_active = pp->eee_active; - eee->tx_lpi_enabled = pp->tx_lpi_enabled; - eee->tx_lpi_timer = (lpi_ctl0) >>8 ;// * scale; return phylink_ethtool_get_eee (pp->phylink, eee); }
@@ -5115,23 +5143,6 @@ static int mvneta_ethtool_set_eee(struct net_device *dev, struct ethtool_keee *eee) {struct mvneta_port *pp =netdev_priv (dev); -u32 lpi_ctl0; - -/* The Armada 37x documents do not give limits for this other than -* it being an 8-bit register. -*/ -if (eee->tx_lpi_enabled && eee->tx_lpi_timer >255 ) -return -EINVAL ; - - lpi_ctl0 =mvreg_read (pp,MVNETA_LPI_CTRL_0 ); - lpi_ctl0 &= ~(0xff <<8 ); - lpi_ctl0 |= eee->tx_lpi_timer <<8 ; -mvreg_write (pp,MVNETA_LPI_CTRL_0 , lpi_ctl0); - - pp->eee_enabled = eee->eee_enabled; - pp->tx_lpi_enabled = eee->tx_lpi_enabled; - -mvneta_set_eee (pp, eee->tx_lpi_enabled && eee->eee_enabled);return phylink_ethtool_set_eee (pp->phylink, eee); }
@@ -5446,6 +5457,9 @@ static int mvneta_port_power_up(struct mvneta_port *pp, int phy_mode) !phy_interface_mode_is_rgmii(phy_mode))return -EINVAL ; +/* Ensure LPI is disabled */ +mvneta_mac_disable_tx_lpi (&pp->phylink_config); +return 0 ; }
@@ -5537,6 +5551,12 @@ static int mvneta_probe(struct platform_device *pdev) pp->phylink_config.mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD |MAC_2500FD ; +/* Setup EEE. Choose 250us idle. */ + pp->phylink_config.lpi_capabilities =MAC_100FD |MAC_1000FD ; + pp->phylink_config.lpi_timer_limit_us =255 ; + pp->phylink_config.lpi_timer_default =250 ; + pp->phylink_config.eee_enabled_default = true; +phy_interface_set_rgmii (pp->phylink_config.supported_interfaces);__set_bit (PHY_INTERFACE_MODE_QSGMII , pp->phylink_config.supported_interfaces);
Signature · 1 line
2.30.2
RFC PATCH 13/23 net: mvneta: only allow EEE to be used in "SGMII" modes
In reply to Russell King (Oracle)The Armada 388 manual states that EEE is only supported in "SGMII" modes. As mvneta only supports serdes modes and RGMII, we can satisfy this by excluding it for RGMII.
--- drivers/net/ethernet/marvell/mvneta.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvneta.c +3 -1
@@ -5551,7 +5551,9 @@ static int mvneta_probe(struct platform_device *pdev) pp->phylink_config.mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD |MAC_2500FD ; -/* Setup EEE. Choose 250us idle. */ +/* Setup EEE. Choose 250us idle. Only supported in SGMII modes. */ +__set_bit (PHY_INTERFACE_MODE_QSGMII , pp->phylink_config.lpi_interfaces); +__set_bit (PHY_INTERFACE_MODE_SGMII , pp->phylink_config.lpi_interfaces); pp->phylink_config.lpi_capabilities =MAC_100FD |MAC_1000FD ; pp->phylink_config.lpi_timer_limit_us =255 ; pp->phylink_config.lpi_timer_default =250 ;
Signature · 1 line
2.30.2
RFC PATCH 14/23 net: mvpp2: add EEE implementation
In reply to Russell King (Oracle)Add EEE support for mvpp2, using phylink's EEE implementation, which means we just need to implement the two methods for LPI control, and with the initial configuration. Only SGMII mode is supported, so only 100M and 1G speeds.
Disabling LPI requires clearing a single bit. Enabling LPI needs a full configuration of several values, as the timer values are dependent on the MAC operating speed.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 5 ++ .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 88 +++++++++++++++++++ 2 files changed, 93 insertions(+)
drivers/net/ethernet/marvell/mvpp2/mvpp2.h +5 -0
@@ -481,6 +481,11 @@#define MVPP22_GMAC_INT_SUM_MASK 0xa4#define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)#define MVPP22_GMAC_INT_SUM_MASK_PTP BIT(2) +#define MVPP2_GMAC_LPI_CTRL0 0xc0 +#define MVPP2_GMAC_LPI_CTRL0_TS_MASK GENMASK(8, 8) +#define MVPP2_GMAC_LPI_CTRL1 0xc4 +#define MVPP2_GMAC_LPI_CTRL1_REQ_EN BIT(0) +#define MVPP2_GMAC_LPI_CTRL1_TW_MASK GENMASK(15, 4)/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0, * relative to port->base.
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +88 -0
124 lines not on this page · raw message
Signature · 1 line
2.30.2
RFC PATCH 15/23 net: lan743x: use netdev in lan743x_phylink_mac_link_down()
In reply to Russell King (Oracle)Use the netdev that we already have in lan743x_phylink_mac_link_down().
--- drivers/net/ethernet/microchip/lan743x_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/microchip/lan743x_main.c +1 -1
@@ -3029,7 +3029,7 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,struct net_device *netdev =to_net_dev (config->dev);struct lan743x_adapter *adapter =netdev_priv (netdev); -netif_tx_stop_all_queues (to_net_dev (config->dev)); +netif_tx_stop_all_queues (netdev);lan743x_mac_eee_enable (adapter, false); }
Signature · 1 line
2.30.2
RFC PATCH 16/23 net: lan743x: convert to phylink managed EEE
In reply to Russell King (Oracle)Convert lan743x to phylink managed EEE:
- Set the lpi_capabilties.
- Move the call to lan743x_mac_eee_enable() into the enable/disable tx_lpi functions.
- Ensure that EEEEN is clear during probe.
- Move the setting of the LPI timer into mac_enable_tx_lpi().
- Move reading of LPI timer to phylink initialisation to set the default timer value.
--- .../net/ethernet/microchip/lan743x_ethtool.c | 21 ----------- drivers/net/ethernet/microchip/lan743x_main.c | 37 ++++++++++++++++--- drivers/net/ethernet/microchip/lan743x_main.h | 1 - 3 files changed, 31 insertions(+), 28 deletions(-)
drivers/net/ethernet/microchip/lan743x_ethtool.c +0 -21
@@ -1055,9 +1055,6 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev, {struct lan743x_adapter *adapter =netdev_priv (netdev); - eee->tx_lpi_timer =lan743x_csr_read (adapter, -MAC_EEE_TX_LPI_REQ_DLY_CNT ); -return phylink_ethtool_get_eee (adapter->phylink, eee); }
@@ -1065,24 +1062,6 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, struct ethtool_keee *eee) {struct lan743x_adapter *adapter =netdev_priv (netdev); -u32 tx_lpi_timer; - - tx_lpi_timer =lan743x_csr_read (adapter,MAC_EEE_TX_LPI_REQ_DLY_CNT ); -if (tx_lpi_timer != eee->tx_lpi_timer) { -u32 mac_cr =lan743x_csr_read (adapter,MAC_CR ); - -/* Software should only change this field when Energy Efficient -* Ethernet Enable (EEEEN) is cleared. -* This function will trigger an autonegotiation restart and -* eee will be reenabled during link up if eee was negotiated. -*/ -lan743x_mac_eee_enable (adapter, false); -lan743x_csr_write (adapter,MAC_EEE_TX_LPI_REQ_DLY_CNT , - eee->tx_lpi_timer); - -if (mac_cr &MAC_CR_EEE_EN_ ) -lan743x_mac_eee_enable (adapter, true); - }return phylink_ethtool_set_eee (adapter->phylink, eee); }
drivers/net/ethernet/microchip/lan743x_main.c +31 -6
@@ -2966,7 +2966,7 @@ static int lan743x_phylink_2500basex_config(struct lan743x_adapter *adapter)return lan743x_pcs_power_reset (adapter); } -void lan743x_mac_eee_enable (struct lan743x_adapter *adapter,bool enable) +static void lan743x_mac_eee_enable (struct lan743x_adapter *adapter,bool enable) {u32 mac_cr;
@@ -3027,10 +3027,8 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config, phy_interface_t interface) {struct net_device *netdev =to_net_dev (config->dev); -struct lan743x_adapter *adapter =netdev_priv (netdev);netif_tx_stop_all_queues (netdev); -lan743x_mac_eee_enable (adapter, false); } static void lan743x_phylink_mac_link_up(struct phylink_config *config,
@@ -3072,16 +3070,32 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config, cap &FLOW_CTRL_TX , cap & FLOW_CTRL_RX); -if (phydev) -lan743x_mac_eee_enable (adapter, phydev->enable_tx_lpi); -netif_tx_wake_all_queues (netdev); } +static void mac_disable_tx_lpi (struct phylink_config *config) +{ +lan743x_mac_eee_enable (adapter, false); +} + +static void mac_enable_tx_lpi (struct phylink_config *config,u32 timer, +bool tx_clk_stop) +{ +/* Software should only change this field when Energy Efficient +* Ethernet Enable (EEEEN) is cleared. We ensure that by clearing +* EEEEN during probe, and phylink itself guarantees that +* mac_disable_tx_lpi() will have been previously called. +*/ +lan743x_csr_write (adapter,MAC_EEE_TX_LPI_REQ_DLY_CNT , timer); +lan743x_mac_eee_enable (adapter, true); +} +static const struct phylink_mac_ops lan743x_phylink_mac_ops = { .mac_config = lan743x_phylink_mac_config, .mac_link_down = lan743x_phylink_mac_link_down, .mac_link_up = lan743x_phylink_mac_link_up, + .mac_disable_tx_lpi = lan743x_mac_disable_tx_lpi, + .mac_enable_tx_lpi = lan743x_mac_enable_tx_lpi, };static int lan743x_phylink_create (struct lan743x_adapter *adapter)
@@ -3095,6 +3109,10 @@ static int lan743x_phylink_create(struct lan743x_adapter *adapter) adapter->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD ; + adapter->phylink_config.lpi_capabilities =MAC_100FD |MAC_1000FD ; + adapter->phylink_config.lpi_timer_max =U32_MAX ; + adapter->phylink_config.lpi_timer_default = +lan743x_csr_read (adapter,MAC_EEE_TX_LPI_REQ_DLY_CNT );lan743x_phy_interface_select (adapter);
@@ -3120,6 +3138,10 @@ static int lan743x_phylink_create(struct lan743x_adapter *adapter)phy_interface_set_rgmii (adapter->phylink_config.supported_interfaces); } +memcpy (adapter->phylink_config.lpi_interfaces, + adapter->phylink_config.supported_interfaces, +sizeof (adapter->phylink_config.lpi_interfaces)); + pl =phylink_create (&adapter->phylink_config,NULL , adapter->phy_interface, &lan743x_phylink_mac_ops);
@@ -3517,6 +3539,9 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,spin_lock_init (&tx->ring_lock); } +/* Ensure EEEEN is clear */ +lan743x_mac_eee_enable (adapter, false); +return 0 ; }
drivers/net/ethernet/microchip/lan743x_main.h +0 -1
@@ -1206,6 +1206,5 @@ void lan743x_hs_syslock_release(struct lan743x_adapter *adapter);void lan743x_mac_flow_ctrl_set_enables (struct lan743x_adapter *adapter,bool tx_enable,bool rx_enable);int lan743x_sgmii_read (struct lan743x_adapter *adapter,u8 mmd,u16 addr); -void lan743x_mac_eee_enable (struct lan743x_adapter *adapter,bool enable);#endif /* _LAN743X_H */
Signature · 1 line
2.30.2
RFC PATCH 17/23 net: stmmac: move tx_lpi_timer tracking to phylib
In reply to Russell King (Oracle)When stmmac_ethtool_op_get_eee() is called, stmmac sets the tx_lpi_timer and tx_lpi_enabled members, and then calls into phylink and thus phylib. phylib overwrites these members.
phylib will also cause a link down/link up transition when settings that impact the MAC have been changed.
Convert stmmac to use the tx_lpi_timer setting in struct phy_device, updating priv->tx_lpi_timer each time when the link comes up, rather than trying to maintain this user setting itself. We initialise the phylib tx_lpi_timer setting by doing a get_ee-modify-set_eee sequence with the last known priv->tx_lpi_timer value. In order for this to work correctly, we also need this member to be initialised earlier.
--- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 14 +------------- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 17 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -13
@@ -898,7 +898,6 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev,if (!priv->dma_cap.eee)return -EOPNOTSUPP ; - edata->tx_lpi_timer = priv->tx_lpi_timer; edata->tx_lpi_enabled = priv->tx_lpi_enabled;return phylink_ethtool_get_eee (priv->phylink, edata);
@@ -908,7 +907,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, struct ethtool_keee *edata) {struct stmmac_priv *priv =netdev_priv (dev); -int ret;if (!priv->dma_cap.eee)return -EOPNOTSUPP ;
@@ -920,17 +918,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,if (!edata->eee_enabled)stmmac_disable_eee_mode (priv); - ret =phylink_ethtool_set_eee (priv->phylink, edata); -if (ret) -return ret; - -if (edata->eee_enabled && - priv->tx_lpi_timer != edata->tx_lpi_timer) { - priv->tx_lpi_timer = edata->tx_lpi_timer; -stmmac_eee_init (priv); - } - -return 0 ; +return phylink_ethtool_set_eee (priv->phylink, edata); }static u32 stmmac_usec2riwt (u32 usec,struct stmmac_priv *priv)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +14 -4
@@ -1088,6 +1088,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,phy_init_eee (phy, !(priv->plat->flags &STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )) >=0 ; priv->eee_enabled =stmmac_eee_init (priv); + priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer; priv->tx_lpi_enabled = priv->eee_enabled;stmmac_set_eee_pls (priv, priv->hw, true); }
@@ -1183,6 +1184,15 @@ static int stmmac_init_phy(struct net_device *dev) ret =phylink_fwnode_phy_connect (priv->phylink, fwnode,0 ); } +if (ret ==0 ) { +struct ethtool_keee eee; + +if (phylink_ethtool_get_eee (priv->phylink, &eee)) { + eee.tx_lpi_timer = priv->tx_lpi_timer; +phylink_ethtool_set_eee (priv->phylink, &eee); + } + } +if (!priv->plat->pmt) {struct ethtool_wolinfo wol = { .cmd =ETHTOOL_GWOL };
@@ -3435,10 +3445,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) priv->eee_tw_timer =STMMAC_DEFAULT_TWT_LS ; -/* Convert the timer from msec to usec */ -if (!priv->tx_lpi_timer) - priv->tx_lpi_timer = eee_timer *1000 ; -if (priv->use_riwt) {u32 queue;
@@ -3905,6 +3911,10 @@ static int __stmmac_open(struct net_device *dev,u32 chan;int ret; +/* Initialise the tx lpi timer, converting from msec to usec */ +if (!priv->tx_lpi_timer) + priv->tx_lpi_timer = eee_timer *1000 ; + ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret;
Signature · 1 line
2.30.2
RFC PATCH 18/23 net: stmmac: make EEE depend on phy->enable_tx_lpi
In reply to Russell King (Oracle)Make stmmac EEE depend on phylib's evaluation of user settings and PHY negotiation, as indicated by phy->enable_tx_lpi. This will ensure when phylib has evaluated that the user has disabled LPI, phy_init_eee() will not be called, and priv->eee_active will be false, causing LPI/EEE to be disabled.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -1084,7 +1084,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,stmmac_mac_set (priv, priv->ioaddr, true);if (phy && priv->dma_cap.eee) { - priv->eee_active = + priv->eee_active = phy->enable_tx_lpi &&phy_init_eee (phy, !(priv->plat->flags &STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )) >=0 ; priv->eee_enabled =stmmac_eee_init (priv);
Signature · 1 line
2.30.2
RFC PATCH 19/23 net: stmmac: remove redundant code from ethtool EEE ops
In reply to Russell King (Oracle)Now that stmmac is using the result of phylib's evaluation of EEE, there is no need to handle anything in the ethtool EEE ops other than calling through to the appropriate phylink function, which will pass on to phylib the users request.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +0 -9
@@ -898,8 +898,6 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev,if (!priv->dma_cap.eee)return -EOPNOTSUPP ; - edata->tx_lpi_enabled = priv->tx_lpi_enabled; -return phylink_ethtool_get_eee (priv->phylink, edata); }
@@ -911,13 +909,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,if (!priv->dma_cap.eee)return -EOPNOTSUPP ; -if (priv->tx_lpi_enabled != edata->tx_lpi_enabled) -netdev_warn (priv->dev, -"Setting EEE tx-lpi is not supported\n" ); - -if (!edata->eee_enabled) -stmmac_disable_eee_mode (priv); -return phylink_ethtool_set_eee (priv->phylink, edata); }
Signature · 1 line
2.30.2
RFC PATCH 20/23 net: stmmac: remove priv->tx_lpi_enabled
In reply to Russell King (Oracle)Through using phylib's EEE state, priv->tx_lpi_enabled has become a write-only variable. Remove it.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 - drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 -- 2 files changed, 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -1
@@ -310,7 +310,6 @@ struct stmmac_priv {int eee_enabled;int eee_active;int tx_lpi_timer; -int tx_lpi_enabled;int eee_tw_timer;bool eee_sw_timer_en;unsigned int mode;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -2
@@ -974,7 +974,6 @@ static void stmmac_mac_link_down(struct phylink_config *config,stmmac_mac_set (priv, priv->ioaddr, false); priv->eee_active = false; - priv->tx_lpi_enabled = false; priv->eee_enabled =stmmac_eee_init (priv);stmmac_set_eee_pls (priv, priv->hw, false);
@@ -1089,7 +1088,6 @@ static void stmmac_mac_link_up(struct phylink_config *config, STMMAC_FLAG_RX_CLK_RUNS_IN_LPI)) >= 0; priv->eee_enabled =stmmac_eee_init (priv); priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer; - priv->tx_lpi_enabled = priv->eee_enabled;stmmac_set_eee_pls (priv, priv->hw, true); }
Signature · 1 line
2.30.2
RFC PATCH 21/23 net: stmmac: report EEE errors if EEE is supported
In reply to Russell King (Oracle)Report the number of EEE errors in the xstats even when EEE is not enabled in hardware, but is supported. The PHY maintains this counter even when EEE is not enabled.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -1
@@ -654,7 +654,7 @@ static void stmmac_get_ethtool_stats(struct net_device *dev, (*(u32 *)p); } } -if (priv->eee_enabled) { +if (priv->dma_cap.eee) {int val =phylink_get_eee_err (priv->phylink);if (val) priv->xstats.phy_eee_wakeup_error_n = val;
Signature · 1 line
2.30.2
RFC PATCH 22/23 net: stmmac: convert to use phy_eee_rx_clock_stop()
In reply to Russell King (Oracle)Convert stmmac to use phy_eee_rx_clock_stop() to set the PHY receive clock stop in LPI setting, rather than calling the legacy phy_init_eee() function.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
@@ -1083,9 +1083,9 @@ static void stmmac_mac_link_up(struct phylink_config *config,stmmac_mac_set (priv, priv->ioaddr, true);if (phy && priv->dma_cap.eee) { - priv->eee_active = phy->enable_tx_lpi && -phy_init_eee (phy, !(priv->plat->flags & -STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )) >=0 ; +phy_eee_rx_clock_stop (phy, !(priv->plat->flags & +STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )); + priv->eee_active = phy->enable_tx_lpi; priv->eee_enabled =stmmac_eee_init (priv); priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer;stmmac_set_eee_pls (priv, priv->hw, true);
Signature · 1 line
2.30.2
RFC PATCH 23/23 net: stmmac: convert to phylink managed EEE support
In reply to Russell King (Oracle)Convert stmmac to use phylink managed EEE support rather than delving into phylib.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +39 -11
@@ -973,9 +973,6 @@ static void stmmac_mac_link_down(struct phylink_config *config,struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev));stmmac_mac_set (priv, priv->ioaddr, false); - priv->eee_active = false; - priv->eee_enabled =stmmac_eee_init (priv); -stmmac_set_eee_pls (priv, priv->hw, false);if (stmmac_fpe_supported (priv))stmmac_fpe_link_state_handle (priv, false);
@@ -1082,14 +1079,6 @@ static void stmmac_mac_link_up(struct phylink_config *config,writel (ctrl, priv->ioaddr +MAC_CTRL_REG );stmmac_mac_set (priv, priv->ioaddr, true); -if (phy && priv->dma_cap.eee) { -phy_eee_rx_clock_stop (phy, !(priv->plat->flags & -STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )); - priv->eee_active = phy->enable_tx_lpi; - priv->eee_enabled =stmmac_eee_init (priv); - priv->tx_lpi_timer = phy->eee_cfg.tx_lpi_timer; -stmmac_set_eee_pls (priv, priv->hw, true); - }if (stmmac_fpe_supported (priv))stmmac_fpe_link_state_handle (priv, true);
@@ -1098,12 +1087,34 @@ static void stmmac_mac_link_up(struct phylink_config *config,stmmac_hwtstamp_correct_latency (priv, priv); } +static void stmmac_mac_disable_tx_lpi (struct phylink_config *config) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + + priv->eee_active = false; + priv->eee_enabled =stmmac_eee_init (priv); +stmmac_set_eee_pls (priv, priv->hw, false); +} + +static void stmmac_mac_enable_tx_lpi (struct phylink_config *config,u32 timer, +bool tx_clk_stop) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + + priv->eee_active = true; + priv->eee_enabled =stmmac_eee_init (priv); + priv->tx_lpi_timer = timer; +stmmac_set_eee_pls (priv, priv->hw, true); +} +static const struct phylink_mac_ops stmmac_phylink_mac_ops = { .mac_get_caps = stmmac_mac_get_caps, .mac_select_pcs = stmmac_mac_select_pcs, .mac_config = stmmac_mac_config, .mac_link_down = stmmac_mac_link_down, .mac_link_up = stmmac_mac_link_up, + .mac_disable_tx_lpi = stmmac_mac_disable_tx_lpi, + .mac_mac_enable_tx_lpi = stmmac_mac_enable_tx_lpi, };/**
@@ -1216,6 +1227,18 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)/* Stmmac always requires an RX clock for hardware initialization */ priv->phylink_config.mac_requires_rxc = true; +if (!(priv->plat->flags &STMMAC_FLAG_RX_CLK_RUNS_IN_LPI )) + priv->phylink_config.eee_rx_clk_stop_enable = true; + +if (priv->dma_cap.eee) { +/* All full duplex speeds above 100Mbps are supported */ + priv->phylink_config.lpi_capabilities = ~(MAC_1000FD -1 ) | +MAC_100FD ; + priv->phylink_config.lpi_timer_limit_us =U32_MAX ; + priv->phylink_config.lpi_timer_default = eee_timer *1000 ; + priv->phylink_config.eee_enabled_default = false; + } + mdio_bus_data = priv->plat->mdio_bus_data;if (mdio_bus_data) priv->phylink_config.default_an_inband =
@@ -1231,6 +1254,11 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)xpcs_get_interfaces (priv->hw->xpcs, priv->phylink_config.supported_interfaces); +/* Assume all supported interfaces also support LPI */ +memcpy (priv->phylink_config.lpi_interfaces, + priv->phylink_config.supported_interfaces, +sizeof (priv->phylink_config.lpi_interfaces)); + fwnode = priv->plat->port_node;if (!fwnode) fwnode =dev_fwnode (priv->device);
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH RFC net-next 23/23] net: stmmac: convert to phylink managed EEE support
kernel test robot noticed the following build errors:
Hi Russell,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Russell-King/net-phy-ensure-that-genphy_c45_an_config_eee_aneg-sees-new-value-of-phydev-eee_cfg-eee_enabled/20241128-140608 base: net-next/main patch link: https://lore.kernel.org/r/E1tFv4y-005yjc-MG%40rmk-PC.armlinux.org.uk patch subject: [PATCH RFC net-next 23/23] net: stmmac: convert to phylink managed EEE support config: arm-spear13xx_defconfig (https://download.01.org/0day-ci/archive/20241128/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241128/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1117:10: error: 'const struct phylink_mac_ops' has no member named 'mac_mac_enable_tx_lpi'; did you mean 'mac_enable_tx_lpi'?
1117 | .mac_mac_enable_tx_lpi = stmmac_mac_enable_tx_lpi,
| ^~~~~~~~~~~~~~~~~~~~~
| mac_enable_tx_lpivim +1117 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
1109
1110 static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
1111 .mac_get_caps = stmmac_mac_get_caps,
1112 .mac_select_pcs = stmmac_mac_select_pcs,
1113 .mac_config = stmmac_mac_config,
1114 .mac_link_down = stmmac_mac_link_down,
1115 .mac_link_up = stmmac_mac_link_up,
1116 .mac_disable_tx_lpi = stmmac_mac_disable_tx_lpi,
> 1117 .mac_mac_enable_tx_lpi = stmmac_mac_enable_tx_lpi,
1118 };
1119
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Russell King (Oracle)
maintainerQuoted 5 lines · Russell King (Oracle)
Patch 11 adds phylink managed EEE support. Two new MAC APIs are added, to enable and disable LPI. The enable method is passed the LPI timer setting which it is expected to program into the hardware, and also a flag ehther the transmit clock should be stopped.
Quoted 9 lines
*** There are open questions here. Eagle eyed reviewers will notice
pl->config->lpi_interfaces. There are MACs out there which only support LPI signalling on a subset of their interface types. Phylib doesn't understand this. I'm handling this at the moment by simply not activating LPI at the MAC, but that leads to ethtool --show-eee suggesting that EEE is active when it isn't.
*** Should we pass thephy_interface_tto these functions? *** Shouldmac_enable_tx_lpi()be allowed to fail if the MAC doesn't
support the interface mode?
There is another point to raise here - should we have a "validate_eee" method in struct phylink_mac_ops so that MAC drivers can validate settings such as the tx_lpi_timer value can be programmed into the hardware?
We do have the situation on Marvell platforms where the programmed value depends on the MAC speed, and is only 8 bit, which makes validating its value rather difficult - at 1G speeds, it's a resolution of 1us so we can support up to 255us. At 100M speeds, it's 10us, supporting up to 2.55ms. This makes it awkward to be able to validate the set_eee() settings are sane for the hardware. Should Marvell platforms instead implement a hrtimer above this? That sounds a bit problematical to manage sanely.
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!
Hi Russell,
Quoted 21 lines · Russell King (Oracle)
Quoted 5 lines · Russell King (Oracle)
Patch 11 adds phylink managed EEE support. Two new MAC APIs are added, to enable and disable LPI. The enable method is passed the LPI timer setting which it is expected to program into the hardware, and also a flag ehther the transmit clock should be stopped.
Quoted 9 lines
*** There are open questions here. Eagle eyed reviewers will notice
pl->config->lpi_interfaces. There are MACs out there which only support LPI signalling on a subset of their interface types. Phylib doesn't understand this. I'm handling this at the moment by simply not activating LPI at the MAC, but that leads to ethtool --show-eee suggesting that EEE is active when it isn't.
*** Should we pass thephy_interface_tto these functions? *** Shouldmac_enable_tx_lpi()be allowed to fail if the MAC doesn't
support the interface mode?There is another point to raise here - should we have a "
validate_eee" method in structphylink_mac_opsso that MAC drivers can validate settings such as thetx_lpi_timervalue can be programmed into the hardware?
Quoted 8 lines
We do have the situation on Marvell platforms where the programmed value depends on the MAC speed, and is only 8 bit, which makes validating its value rather difficult - at 1G speeds, it's a resolution of 1us so we can support up to 255us. At 100M speeds, it's 10us, supporting up to 2.55ms. This makes it awkward to be able to validate the
set_eee()settings are sane for the hardware. Should Marvell platforms instead implement a hrtimer above this? That sounds a bit problematical to manage sanely.
I agree that tx_lpi_timer can be a problem, and this is not just a Marvell issue. For example, I think the FEC MAC on i.MX8MP might also be affected. But I can't confirm this because I don't have an i.MX8MP board with a PHY that supports MAC-controlled EEE mode. The Realtek PHY I have uses PHY-controlled EEE (SmartEEE).
Except for this, I think there should be sane default values for tx_lpi_timer. The IEEE 802.3-2022 standard (Section 78.2) describes EEE timing, but it doesn’t give a clear recommendation for tx_lpi_timer. IMO, the best value for tx_lpi_timer should be the sum of the time needed to put the full chain (MAC -> PHY -> remote PHY) into sleep mode and the time needed to wake the chain. These times are link-speed specific, so defaults should consider PHY timings for each link speed.
Except for tx_lpi_timer, some MACs also allow configuration of the Twake timer. For example, the FEC driver uses the lpi_timer value to configure the Twake timer, and the LAN78xx driver also provides a configurable Twake timer register.
If the Twake timer is not configured properly, or if the system has quirks causing the actual Twake time to be longer than expected, it can result in frame corruption.
Regards,
Oleksij
Signature · 4 lines
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 |
Russell King (Oracle)
maintainerQuoted 39 lines · Oleksij Rempel
Hi Russell,
Quoted 21 lines · Russell King (Oracle)
Quoted 5 lines · Russell King (Oracle)
Patch 11 adds phylink managed EEE support. Two new MAC APIs are added, to enable and disable LPI. The enable method is passed the LPI timer setting which it is expected to program into the hardware, and also a flag ehther the transmit clock should be stopped.
Quoted 9 lines
*** There are open questions here. Eagle eyed reviewers will notice
pl->config->lpi_interfaces. There are MACs out there which only support LPI signalling on a subset of their interface types. Phylib doesn't understand this. I'm handling this at the moment by simply not activating LPI at the MAC, but that leads to ethtool --show-eee suggesting that EEE is active when it isn't.
*** Should we pass thephy_interface_tto these functions? *** Shouldmac_enable_tx_lpi()be allowed to fail if the MAC doesn't
support the interface mode?There is another point to raise here - should we have a "
validate_eee" method in structphylink_mac_opsso that MAC drivers can validate settings such as thetx_lpi_timervalue can be programmed into the hardware?Quoted 8 lines
We do have the situation on Marvell platforms where the programmed value depends on the MAC speed, and is only 8 bit, which makes validating its value rather difficult - at 1G speeds, it's a resolution of 1us so we can support up to 255us. At 100M speeds, it's 10us, supporting up to 2.55ms. This makes it awkward to be able to validate the
set_eee()settings are sane for the hardware. Should Marvell platforms instead implement a hrtimer above this? That sounds a bit problematical to manage sanely.I agree that
tx_lpi_timercan be a problem, and this is not just a Marvell issue. For example, I think the FEC MAC on i.MX8MP might also be affected. But I can't confirm this because I don't have an i.MX8MP board with a PHY that supports MAC-controlled EEE mode. The Realtek PHY I have uses PHY-controlled EEE (SmartEEE).
Quoted 3 lines
Except for this, I think there should be sane default values for
tx_lpi_timer. The IEEE 802.3-2022 standard (Section 78.2) describes EEE timing, but it doesn’t give a clear recommendation fortx_lpi_timer.
There are of course some parameters of EEE that should be fixed, and IEEE specifies them in that section. These are Ts, Tq and Tr, and IEEE gives a range of values for these which need to be conformed with in a compliant implementation.
Please don't get confused by the mvneta/mvpp2 implementation, there are parameters for Ts and Tw, but the Ts value is not the same as Ts in IEEE. IEEE defines it as the period of time between the PHY transmitting sleep and turning all transmitters off. Marvell define it as the minimum time from the Tx FIFO being empty to asserting LPI - quite different!
Other parameters depend on the implementation, such as the propagation delay of data through the PHY. These, we don't currently take account of. I don't recall off-hand whether there's any standards defined registers describing these parameters in the PHY (I need to delve into 802.3...) That's all needed for computing Tw.
Quoted 4 lines
IMO, the best value for
tx_lpi_timershould be the sum of the time needed to put the full chain (MAC -> PHY -> remote PHY) into sleep mode and the time needed to wake the chain. These times are link-speed specific, so defaults should consider PHY timings for each link speed.
One can only make a set of defaults that depend on the speed if we also give the user the ability to set the tx_lpi_timer values on a per-speed basis, otherwise how do we update the values when set_eee() gets called?
Also how do we know what the requirements of the remote PHY are? I think the only way that could be known is by exchanging the EEE TLV with the link partner as described in section 78.
Quoted 8 lines
Except for
tx_lpi_timer, some MACs also allow configuration of the Twake timer. For example, the FEC driver uses thelpi_timervalue to configure the Twake timer, and the LAN78xx driver also provides a configurable Twake timer register.If the Twake timer is not configured properly, or if the system has quirks causing the actual Twake time to be longer than expected, it can result in frame corruption.
I have been aware of it, and to me it sounds like another can of worms that right now I'd rather not open until we have solved the basics of EEE and got MAC drivers into better shape for the basics. I had been wondering whether we would eventually need phylink to pass Tw along with the LPI timer, and I think eventually we would need to - and we also need some infrastructure for the EEE TLV, both sending it at the appropriate time, and processing it when received. I don't think we have any of that at the moment, so it would be another chunk of development.
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!
Russell King (Oracle)
maintainerQuoted 4 lines · Russell King (Oracle)
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct
ethtool_keeewhether the netdev driver wants it or not. This leads to weird scenarios where
Quoted 8 lines
doing a
get_eee()op followed by aset_eee()op results in e.g.tx_lpi_timerbeing zeroed, because the MAC driver doesn't know it needs to initialise phylib'sphydev->eee_cfg.tx_lpi_timermember. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
Note that, I think, fec_main.c isn't broken, although a quick review only looking at fec_enet_get_eee() may suggest otherwise:
static intfec_enet_get_eee(struct net_device *ndev, struct ethtool_keee *edata)
{
struct fec_enet_private *fep = netdev_priv(ndev);
struct ethtool_keee *p = &fep->eee;
if (!(fep->quirks & FEC_QUIRK_HAS_EEE))
return -EOPNOTSUPP;
if (!netif_running(ndev))
return -ENETDOWN;
edata->tx_lpi_timer = p->tx_lpi_timer; // <===========================
return phy_ethtool_get_eee(ndev->phydev, edata);
}static intfec_enet_set_eee(struct net_device *ndev, struct ethtool_keee *edata) {
...
p->tx_lpi_timer = edata->tx_lpi_timer;
Since the driver does not touch phydev->eee_cfg.tx_lpi_timer, phy_ethtool_get_eee() above will overwrite edata->tx_lpi_timer with zero. If ethtool does a read-modify-write on the EEE settings, then fec_enet_set_eee() will be passed a value of zero for edata->tx_lpi_timer.
This will result in FEC_LPI_SLEEP and FEC_LPI_WAKE being written with zero, and from what I can see in fec_enet_eee_mode_set(), that disables EEE.
The saving grace for this driver is that p->tx_lpi_timer also starts off as zero.
A better implementation would be to get rid of p->tx_lpi_timer entirely, and instead rely on phydev->eee_cfg.tx_lpi_timer to be managed by phylib, obtaining its value from there in fec_enet_eee_mode_set(). At least the driver doesn't attempt to maintain any other EEE state!
So something like this:
drivers/net/ethernet/freescale/fec.h +0 -2
@@ -671,8 +671,6 @@ struct fec_enet_private {unsigned int tx_time_itr;unsigned int itr_clk_rate; -/* tx lpi eee mode */ -struct ethtool_keee eee;unsigned int clk_ref_rate;/* ptp clock period in ns*/
drivers/net/ethernet/freescale/fec_main.c +6 -10
@@ -2045,14 +2045,14 @@ static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us)return us * (fep->clk_ref_rate /1000 ) /1000 ; } -static int fec_enet_eee_mode_set (struct net_device *ndev,bool enable) +static int fec_enet_eee_mode_set (struct net_device *ndev,u32 lpi_timer, +bool enable) {struct fec_enet_private *fep =netdev_priv (ndev); -struct ethtool_keee *p = &fep->eee;unsigned int sleep_cycle, wake_cycle;if (enable) { - sleep_cycle =fec_enet_us_to_tx_cycle (ndev, p->tx_lpi_timer); + sleep_cycle =fec_enet_us_to_tx_cycle (lpi_timer); wake_cycle = sleep_cycle; }else { sleep_cycle =0 ;
@@ -2105,7 +2105,9 @@ static void fec_enet_adjust_link(struct net_device *ndev)napi_enable (&fep->napi); }if (fep->quirks &FEC_QUIRK_HAS_EEE ) -fec_enet_eee_mode_set (ndev, phy_dev->enable_tx_lpi); +fec_enet_eee_mode_set (ndev, + phy_dev->eee_cfg.tx_lpi_timer, + phy_dev->enable_tx_lpi); }else {if (fep->link) {netif_stop_queue (ndev);
@@ -3181,7 +3183,6 @@ static int fec_enet_get_eee(struct net_device *ndev, struct ethtool_keee *edata) { struct fec_enet_private *fep = netdev_priv(ndev); -struct ethtool_keee *p = &fep->eee;if (!(fep->quirks &FEC_QUIRK_HAS_EEE ))return -EOPNOTSUPP ;
@@ -3189,8 +3190,6 @@ fec_enet_get_eee(struct net_device *ndev, struct ethtool_keee *edata)if (!netif_running (ndev))return -ENETDOWN ; - edata->tx_lpi_timer = p->tx_lpi_timer; -return phy_ethtool_get_eee (ndev->phydev, edata); }
@@ -3198,7 +3197,6 @@ static int fec_enet_set_eee(struct net_device *ndev, struct ethtool_keee *edata) { struct fec_enet_private *fep = netdev_priv(ndev); -struct ethtool_keee *p = &fep->eee;if (!(fep->quirks &FEC_QUIRK_HAS_EEE ))return -EOPNOTSUPP ;
@@ -3206,8 +3204,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_keee *edata)if (!netif_running (ndev))return -ENETDOWN ; - p->tx_lpi_timer = edata->tx_lpi_timer; -return phy_ethtool_set_eee (ndev->phydev, edata); }
Another patch to be added to my stack...
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!
Russell King (Oracle)
maintainerRe: net: rtl8169: EEE seems to be ok (was: Re: [PATCH RFC net-next 00/23] net: phylink managed EEE support)
In reply to Russell King (Oracle)Quoted 4 lines · Russell King (Oracle)
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct
ethtool_keeewhether the netdev driver wants it or not. This leads to weird scenarios where
Quoted 8 lines
doing a
get_eee()op followed by aset_eee()op results in e.g.tx_lpi_timerbeing zeroed, because the MAC driver doesn't know it needs to initialise phylib'sphydev->eee_cfg.tx_lpi_timermember. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
Looking at the rtl8169 driver, it looks pretty similar to the Marvell situation. The value stored in tp->tx_lpi_timer is apparently, according to r8169_get_tx_lpi_timer_us(), a value in bytes, not in a unit of time. So it's dependent on the negotiated speed, and thus we can't read it to set the initial phydev->eee_cfg.tx_lpi_timer state, because in the _probe() function, the PHY may not have negotiated a speed.
However, this driver writes keee->tx_lpi_timer after phy_ethtool_get_eee() which means that it overrides phylib, so hasn't been broken.
Therefore, I think rtl8169 is fine.
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!
Heiner Kallweit
maintainerRe: net: rtl8169: EEE seems to be ok
Quoted 14 lines · Russell King (Oracle)
Quoted 4 lines · Russell King (Oracle)
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct
ethtool_keeewhether the netdev driver wants it or not. This leads to weird scenarios whereQuoted 8 lines
doing a
get_eee()op followed by aset_eee()op results in e.g.tx_lpi_timerbeing zeroed, because the MAC driver doesn't know it needs to initialise phylib'sphydev->eee_cfg.tx_lpi_timermember. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
Quoted 8 lines
Looking at the rtl8169 driver, it looks pretty similar to the Marvell situation. The value stored in
tp->tx_lpi_timeris apparently, according tor8169_get_tx_lpi_timer_us(), a value in bytes, not in a unit of time. So it's dependent on the negotiated speed, and thus we can't read it to set the initialphydev->eee_cfg.tx_lpi_timerstate, because in the_probe()function, the PHY may not have negotiated a speed.
Right, hw stores the tx_lpi_timer in bytes. Driver's default value is one frame plus a few bytes. It doesn't use phydev->eee_cfg.tx_lpi_timer. set_eee() op isn't implemented for tx_lpi_timer, because no one ever asked for it and I'm not aware of any good use case.
Quoted 6 lines
However, this driver writes
keee->tx_lpi_timerafterphy_ethtool_get_eee()which means that it overrides phylib, so hasn't been broken.Therefore, I think rtl8169 is fine.
Russell King (Oracle)
maintainerRe: net: ti: weirdness (was Re: [PATCH RFC net-next 00/23] net: phylink managed EEE support)
In reply to Russell King (Oracle)Quoted 4 lines · Russell King (Oracle)
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct
ethtool_keeewhether the netdev driver wants it or not. This leads to weird scenarios where
Quoted 8 lines
doing a
get_eee()op followed by aset_eee()op results in e.g.tx_lpi_timerbeing zeroed, because the MAC driver doesn't know it needs to initialise phylib'sphydev->eee_cfg.tx_lpi_timermember. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
Looking at the two TI offerings that call phy_ethtool_get_eee(), both of them call the phylib functions from their ethtool ops, but it looks like the driver does diddly squat with LPI state, which makes me wonder why they implemented the calls to phy_ethtool_get_eee() and phy_ethtool_set_eee(), since EEE will not be functional unless the PHY has been configured with a SmartEEE mode outside the kernel.
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!
Re: net: ti: weirdness (was Re: [PATCH RFC net-next 00/23] net: phylink managed EEE support)
Quoted 14 lines · Russell King (Oracle)
Quoted 4 lines · Russell King (Oracle)
In doing this, I came across the fact that the addition of phylib managed EEE support has actually broken a huge number of drivers - phylib will now overwrite all members of struct
ethtool_keeewhether the netdev driver wants it or not. This leads to weird scenarios whereQuoted 8 lines
doing a
get_eee()op followed by aset_eee()op results in e.g.tx_lpi_timerbeing zeroed, because the MAC driver doesn't know it needs to initialise phylib'sphydev->eee_cfg.tx_lpi_timermember. This mess really needs urgently addressing, and I believe it came about because Andrew's patches were only partly merged via another party - I guess highlighting the inherent danger of "thou shalt limit your patch series to no more than 15 patches" when one has a subsystem who's in-kernel API is changing.
Quoted 6 lines
Looking at the two TI offerings that call
phy_ethtool_get_eee(), both of them call the phylib functions from their ethtool ops, but it looks like the driver does diddly squat with LPI state, which makes me wonder why they implemented the calls tophy_ethtool_get_eee()andphy_ethtool_set_eee(), since EEE will not be functional unless the PHY has been configured with a SmartEEE mode outside the kernel.
Probably because they did not know what they were doing, and it got past reviewers.
Well, actually:
commit a090994980a15f8cc14fc188b5929bd61d2ae9c3
Author: Yegor Yefremov <[email protected]> Date: Mon Nov 28 09:41:33 2016 +0100
cpsw: ethtool: add support for getting/setting EEE registers
Add the ability to query and set Energy Efficient Ethernet parameters via ethtool for applicable devices.
This patch doesn't activate full EEE support in cpsw driver, but it enables reading and writing EEE advertising settings. This way one can disable advertising EEE for certain speeds.
Seems like somebody had an issue and did the minimum to work around the issue. This also suggests the hardware is doing EEE by default, hopefully with some sort of sensible hardware defaults.
Andrew
Re: net: sxgbe: using lpi_timer for Twake timer
In reply to Russell King (Oracle)For archive:
static void sxgbe_set_eee_timer(void __iomem *ioaddr,
const int ls, const int tw)
{
int value = ((tw & 0xffff)) | ((ls & 0x7ff) << 16);
/* Program the timers in the LPI timer control register:
* LS: minimum time (ms) for which the link
* status from PHY should be ok before transmitting
* the LPI pattern.
* TW: minimum time (us) for which the core waits
* after it has stopped transmitting the LPI pattern. */
writel(value, ioaddr + SXGBE_CORE_LPI_TIMER_CTRL);
}
bool sxgbe_eee_init(struct sxgbe_priv_data * const priv) {
....
/* MAC core supports the EEE feature. */
if (priv->hw_cap.eee) {
/* Check if the PHY supports EEE */
if (phy_init_eee(ndev->phydev, true))
return false;
timer_setup(&priv->eee_ctrl_timer, sxgbe_eee_ctrl_timer, 0);
priv->eee_ctrl_timer.expires = SXGBE_LPI_TIMER(eee_timer);
add_timer(&priv->eee_ctrl_timer);
priv->hw->mac->set_eee_timer(priv->ioaddr,
SXGBE_DEFAULT_LPI_TIMER,
priv->tx_lpi_timer);
^^^^^^^^^^^^
LPI timer is used for
Twake timer.
}In case user configures lpi_timer value to too low, it will case frame corruption instead of expected performance drop.
Signature · 4 lines
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 |