net: phylink,xpcs,stmmac: support PCS EEE configuration
Subsystems (7)
Russell King (Oracle)
maintainercover net: phylink,xpcs,stmmac: support PCS EEE configuration
Hi,
This series adds support for phylink managed EEE at the PCS level, allowing xpcs_config_eee() to be removed. Sadly, we still end up with a XPCS specific function to configure the clock multiplier.
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 -- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 + drivers/net/pcs/pcs-xpcs.c | 89 +++++++++++++++-------- drivers/net/pcs/pcs-xpcs.h | 1 + drivers/net/phy/phylink.c | 25 ++++++- include/linux/pcs/pcs-xpcs.h | 3 +- include/linux/phylink.h | 22 ++++++ 7 files changed, 107 insertions(+), 42 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!
PATCH 1/8 net: phylink: add support for notifying PCS about EEE
There are hooks in the stmmac driver into XPCS to control the EEE settings when LPI is configured at the MAC. This bypasses the layering. To allow this to be removed from the stmmac driver, add two new methods for PCS to inform them when the LPI/EEE enablement state changes at the MAC.
--- drivers/net/phy/phylink.c | 25 ++++++++++++++++++++++--- include/linux/phylink.h | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-)
drivers/net/phy/phylink.c +22 -3
@@ -1073,6 +1073,18 @@ static void phylink_pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode, pcs->ops->pcs_link_up (pcs, neg_mode, interface, speed, duplex); } +static void phylink_pcs_disable_eee (struct phylink_pcs *pcs) +{ +if (pcs && pcs->ops->pcs_disable_eee) + pcs->ops->pcs_disable_eee (pcs); +} + +static void phylink_pcs_enable_eee (struct phylink_pcs *pcs) +{ +if (pcs && pcs->ops->pcs_enable_eee) + pcs->ops->pcs_enable_eee (pcs); +} +/* Query inband for a specific interface mode, asking the MAC for the * PCS which will be used to handle the interface mode. */
@@ -1601,6 +1613,8 @@ static void phylink_deactivate_lpi(struct phylink *pl)phylink_dbg (pl,"disabling LPI\n" ); pl->mac_ops->mac_disable_tx_lpi (pl->config); + +phylink_pcs_disable_eee (pl->pcs); } }
@@ -1617,13 +1631,18 @@ static void phylink_activate_lpi(struct phylink *pl)phylink_dbg (pl,"LPI timer %uus, tx clock stop %u\n" , pl->mac_tx_lpi_timer, pl->mac_tx_clk_stop); +phylink_pcs_enable_eee (pl->pcs); + err = pl->mac_ops->mac_enable_tx_lpi (pl->config, pl->mac_tx_lpi_timer, pl->mac_tx_clk_stop); -if (!err) - pl->mac_enable_tx_lpi = true; -else +if (err) { +phylink_pcs_disable_eee (pl->pcs);phylink_err (pl,"%ps() failed: %pe\n" , pl->mac_ops->mac_enable_tx_lpi,ERR_PTR (err)); +return ; + } + + pl->mac_enable_tx_lpi = true; } static void phylink_link_up(struct phylink *pl,
include/linux/phylink.h +22 -0
@@ -477,6 +477,10 @@ struct phylink_pcs {* @pcs_an_restart: restart 802.3z BaseX autonegotiation. * @pcs_link_up: program the PCS for the resolved link configuration * (where necessary). +* @pcs_disable_eee: optional notification to PCS that EEE has been disabled +* at the MAC. +* @pcs_enable_eee: optional notification to PCS that EEE will be enabled at +* the MAC. * @pcs_pre_init: configure PCS components necessary for MAC hardware * initialization e.g. RX clock for stmmac. */
@@ -500,6 +504,8 @@ struct phylink_pcs_ops {void (*pcs_an_restart)(struct phylink_pcs *pcs);void (*pcs_link_up)(struct phylink_pcs *pcs,unsigned int neg_mode,phy_interface_t interface,int speed,int duplex); +void (*pcs_disable_eee)(struct phylink_pcs *pcs); +void (*pcs_enable_eee)(struct phylink_pcs *pcs);int (*pcs_pre_init)(struct phylink_pcs *pcs); };
@@ -625,6 +631,22 @@ void pcs_an_restart(struct phylink_pcs *pcs);void pcs_link_up (struct phylink_pcs *pcs,unsigned int neg_mode,phy_interface_t interface,int speed,int duplex); +/** +* pcs_disable_eee() - Disable EEE at the PCS +* @pcs: a pointer to a &struct phylink_pcs +* +* Optional method informing the PCS that EEE has been disabled at the MAC. +*/ +void pcs_disable_eee (struct phylink_pcs *pcs); + +/** +* pcs_enable_eee() - Enable EEE at the PCS +* @pcs: a pointer to a &struct phylink_pcs +* +* Optional method informing the PCS that EEE is about to be enabled at the MAC. +*/ +void pcs_enable_eee (struct phylink_pcs *pcs); +/** * pcs_pre_init() - Configure PCS components necessary for MAC initialization * @pcs: a pointer to a &struct phylink_pcs.
Signature · 1 line
2.30.2
PATCH 2/8 net: xpcs: add function to configure EEE clock multiplying factor
In reply to Russell King (Oracle)Add a function to separate out the EEE clock multiplying factor. This will be called by the stmmac driver to configure this value.
It would have been better had the driver used the CLK API to retrieve this clock, get its rate and calculate the appropriate multiplier, but that door has closed.
--- drivers/net/pcs/pcs-xpcs.c | 14 ++++++++++++++ drivers/net/pcs/pcs-xpcs.h | 1 + include/linux/pcs/pcs-xpcs.h | 1 + 3 files changed, 16 insertions(+)
drivers/net/pcs/pcs-xpcs.c +14 -0
@@ -1193,6 +1193,20 @@ static void xpcs_an_restart(struct phylink_pcs *pcs) BMCR_ANRESTART); } +/** +* xpcs_config_eee_mult_fact() - set the EEE clock multiplying factor +* @xpcs: pointer to a &struct dw_xpcs instance +* @mult_fact: the multiplying factor +* +* Configure the EEE clock multiplying factor. This value should be such that +* clk_eee_time_period * (mult_fact + 1) is within the range 80 to 120ns. +*/ +void xpcs_config_eee_mult_fact (struct dw_xpcs *xpcs,u8 mult_fact) +{ + xpcs->eee_mult_fact = mult_fact; +} +EXPORT_SYMBOL_GPL (xpcs_config_eee_mult_fact); +static int xpcs_read_ids (struct dw_xpcs *xpcs) {int ret;
drivers/net/pcs/pcs-xpcs.h +1 -0
@@ -122,6 +122,7 @@ struct dw_xpcs {struct phylink_pcs pcs;phy_interface_t interface;bool need_reset; +u8 eee_mult_fact; };int xpcs_read (struct dw_xpcs *xpcs,int dev,u32 reg);
include/linux/pcs/pcs-xpcs.h +1 -0
@@ -52,6 +52,7 @@ struct phylink_pcs *xpcs_to_phylink_pcs(struct dw_xpcs *xpcs);int xpcs_get_an_mode (struct dw_xpcs *xpcs,phy_interface_t interface);int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns,int enable); +void xpcs_config_eee_mult_fact (struct dw_xpcs *xpcs,u8 mult_fact);struct dw_xpcs *xpcs_create_mdiodev (struct mii_bus *bus,int addr);struct dw_xpcs *xpcs_create_fwnode (struct fwnode_handle *fwnode);void xpcs_destroy (struct dw_xpcs *xpcs);
Signature · 1 line
2.30.2
PATCH 3/8 net: stmmac: call xpcs_config_eee_mult_fact()
In reply to Russell King (Oracle)Arrange for stmmac to call the new xpcs_config_eee_mult_fact() function to configure the EEE clock multiplying factor. This will allow the removal of the xpcs_config_eee() calls in the next patch.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +2 -0
@@ -524,6 +524,8 @@ int stmmac_pcs_setup(struct net_device *ndev)if (ret)return dev_err_probe (priv->device, ret,"No xPCS found\n" ); +xpcs_config_eee_mult_fact (xpcs, priv->plat->mult_fact_100ns); + priv->hw->xpcs = xpcs;return 0 ;
Signature · 1 line
2.30.2
PATCH 4/8 net: xpcs: convert to phylink managed EEE
In reply to Russell King (Oracle)Convert XPCS to use the new pcs_disable_eee() and pcs_enable_eee() methods. Since stmmac is the only user of xpcs_config_eee(), we can make this a no-op along with this change.
--- drivers/net/pcs/pcs-xpcs.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/net/pcs/pcs-xpcs.c +23 -1
@@ -602,7 +602,8 @@ static void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces)__set_bit (compat->interface, interfaces); } -int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns,int enable) +static int __xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns, +int enable) {u16 mask, val;int ret;
@@ -630,6 +631,11 @@ int xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns, int enable)DW_VR_MII_EEE_TRN_LPI , enable ? DW_VR_MII_EEE_TRN_LPI : 0); } + +int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns,int enable) +{ +return 0 ; +}EXPORT_SYMBOL_GPL (xpcs_config_eee);static void xpcs_pre_config (struct phylink_pcs *pcs,phy_interface_t interface)
@@ -1193,6 +1199,20 @@ static void xpcs_an_restart(struct phylink_pcs *pcs) BMCR_ANRESTART); } +static void xpcs_disable_eee (struct phylink_pcs *pcs) +{ +struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); + +__xpcs_config_eee (xpcs,0 , false); +} + +static void xpcs_enable_eee (struct phylink_pcs *pcs) +{ +struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); + +__xpcs_config_eee (xpcs, xpcs->eee_mult_fact, true); +} +/** * xpcs_config_eee_mult_fact() - set the EEE clock multiplying factor * @xpcs: pointer to a &struct dw_xpcs instance
@@ -1355,6 +1375,8 @@ static const struct phylink_pcs_ops xpcs_phylink_ops = { .pcs_get_state = xpcs_get_state, .pcs_an_restart = xpcs_an_restart, .pcs_link_up = xpcs_link_up, + .pcs_disable_eee = xpcs_disable_eee, + .pcs_enable_eee = xpcs_enable_eee, };static int xpcs_identify (struct dw_xpcs *xpcs)
Signature · 1 line
2.30.2
PATCH 5/8 net: stmmac: remove calls to xpcs_config_eee()
In reply to Russell King (Oracle)Remove the explicit calls to xpcs_config_eee() from the stmmac driver, preferring instead for phylink to manage the EEE configuration at the PCS.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -7
@@ -1046,10 +1046,6 @@ static void stmmac_mac_disable_tx_lpi(struct phylink_config *config) priv->tx_path_in_lpi_mode = false;stmmac_set_eee_timer (priv, priv->hw,0 ,STMMAC_DEFAULT_TWT_LS ); -if (priv->hw->xpcs) -xpcs_config_eee (priv->hw->xpcs, priv->plat->mult_fact_100ns, - false); -mutex_unlock (&priv->lock); }
@@ -1068,9 +1064,6 @@ static int stmmac_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,stmmac_set_eee_timer (priv, priv->hw,STMMAC_DEFAULT_LIT_LS ,STMMAC_DEFAULT_TWT_LS ); -if (priv->hw->xpcs) -xpcs_config_eee (priv->hw->xpcs, priv->plat->mult_fact_100ns, - true);/* Try to cnfigure the hardware timer. */ ret = stmmac_set_lpi_mode(priv, priv->hw, STMMAC_LPI_TIMER,
Signature · 1 line
2.30.2
PATCH 6/8 net: xpcs: remove xpcs_config_eee() from global scope
In reply to Russell King (Oracle)Make xpcs_config_eee() private to the XPCS driver, called only from the phylink pcs_disable_eee() and pcs_enable_eee() methods.
--- drivers/net/pcs/pcs-xpcs.c | 14 ++++---------- include/linux/pcs/pcs-xpcs.h | 2 -- 2 files changed, 4 insertions(+), 12 deletions(-)
drivers/net/pcs/pcs-xpcs.c +4 -10
@@ -602,8 +602,8 @@ static void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces)__set_bit (compat->interface, interfaces); } -static int __xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns, -int enable) +static int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns, +int enable) {u16 mask, val;int ret;
@@ -632,12 +632,6 @@ static int __xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns, enable ? DW_VR_MII_EEE_TRN_LPI : 0); } -int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns,int enable) -{ -return 0 ; -} -EXPORT_SYMBOL_GPL (xpcs_config_eee); -static void xpcs_pre_config (struct phylink_pcs *pcs,phy_interface_t interface) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs);
@@ -1203,14 +1197,14 @@ static void xpcs_disable_eee(struct phylink_pcs *pcs) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); -__xpcs_config_eee (xpcs,0 , false); +xpcs_config_eee (xpcs,0 , false); }static void xpcs_enable_eee (struct phylink_pcs *pcs) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); -__xpcs_config_eee (xpcs, xpcs->eee_mult_fact, true); +xpcs_config_eee (xpcs, xpcs->eee_mult_fact, true); }/**
include/linux/pcs/pcs-xpcs.h +0 -2
@@ -50,8 +50,6 @@ struct dw_xpcs;struct phylink_pcs *xpcs_to_phylink_pcs (struct dw_xpcs *xpcs);int xpcs_get_an_mode (struct dw_xpcs *xpcs,phy_interface_t interface); -int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns, -int enable);void xpcs_config_eee_mult_fact (struct dw_xpcs *xpcs,u8 mult_fact);struct dw_xpcs *xpcs_create_mdiodev (struct mii_bus *bus,int addr);struct dw_xpcs *xpcs_create_fwnode (struct fwnode_handle *fwnode);
Signature · 1 line
2.30.2
PATCH 7/8 net: xpcs: clean up xpcs_config_eee()
In reply to Russell King (Oracle)There is now no need to pass the mult_fact into xpcs_config_eee(), so let's remove that argument and use xpcs->eee_mult_fact directly. While changing the function signature, as we pass true/false for enable, use "bool" instead of "int" for this.
--- drivers/net/pcs/pcs-xpcs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/pcs/pcs-xpcs.c +4 -5
@@ -602,8 +602,7 @@ static void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces)__set_bit (compat->interface, interfaces); } -static int xpcs_config_eee (struct dw_xpcs *xpcs,int mult_fact_100ns, -int enable) +static int xpcs_config_eee (struct dw_xpcs *xpcs,bool enable) {u16 mask, val;int ret;
@@ -618,7 +617,7 @@ static int xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns,DW_VR_MII_EEE_TX_QUIET_EN |DW_VR_MII_EEE_RX_QUIET_EN |DW_VR_MII_EEE_TX_EN_CTRL |DW_VR_MII_EEE_RX_EN_CTRL |FIELD_PREP (DW_VR_MII_EEE_MULT_FACT_100NS , - mult_fact_100ns); + xpcs->eee_mult_fact); else val =0 ;
@@ -1197,14 +1196,14 @@ static void xpcs_disable_eee(struct phylink_pcs *pcs) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); -xpcs_config_eee (xpcs,0 , false); +xpcs_config_eee (xpcs, false); }static void xpcs_enable_eee (struct phylink_pcs *pcs) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs); -xpcs_config_eee (xpcs, xpcs->eee_mult_fact, true); +xpcs_config_eee (xpcs, true); }/**
Signature · 1 line
2.30.2
PATCH 8/8 net: xpcs: group EEE code together
In reply to Russell King (Oracle)Move xpcs_config_eee() with the other EEE-related functions.
--- drivers/net/pcs/pcs-xpcs.c | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/net/pcs/pcs-xpcs.c +29 -29
@@ -602,35 +602,6 @@ static void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces)__set_bit (compat->interface, interfaces); } -static int xpcs_config_eee (struct dw_xpcs *xpcs,bool enable) -{ -u16 mask, val; -int ret; - - mask =DW_VR_MII_EEE_LTX_EN |DW_VR_MII_EEE_LRX_EN | -DW_VR_MII_EEE_TX_QUIET_EN |DW_VR_MII_EEE_RX_QUIET_EN | -DW_VR_MII_EEE_TX_EN_CTRL |DW_VR_MII_EEE_RX_EN_CTRL | -DW_VR_MII_EEE_MULT_FACT_100NS ; - -if (enable) - val =DW_VR_MII_EEE_LTX_EN |DW_VR_MII_EEE_LRX_EN | -DW_VR_MII_EEE_TX_QUIET_EN |DW_VR_MII_EEE_RX_QUIET_EN | -DW_VR_MII_EEE_TX_EN_CTRL |DW_VR_MII_EEE_RX_EN_CTRL | -FIELD_PREP (DW_VR_MII_EEE_MULT_FACT_100NS , - xpcs->eee_mult_fact); -else - val =0 ; - - ret =xpcs_modify (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_EEE_MCTRL0 , mask, - val); -if (ret <0 ) -return ret; - -return xpcs_modify (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_EEE_MCTRL1 , -DW_VR_MII_EEE_TRN_LPI , - enable ?DW_VR_MII_EEE_TRN_LPI :0 ); -} -static void xpcs_pre_config (struct phylink_pcs *pcs,phy_interface_t interface) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs);
@@ -1192,6 +1163,35 @@ static void xpcs_an_restart(struct phylink_pcs *pcs) BMCR_ANRESTART); } +static int xpcs_config_eee (struct dw_xpcs *xpcs,bool enable) +{ +u16 mask, val; +int ret; + + mask =DW_VR_MII_EEE_LTX_EN |DW_VR_MII_EEE_LRX_EN | +DW_VR_MII_EEE_TX_QUIET_EN |DW_VR_MII_EEE_RX_QUIET_EN | +DW_VR_MII_EEE_TX_EN_CTRL |DW_VR_MII_EEE_RX_EN_CTRL | +DW_VR_MII_EEE_MULT_FACT_100NS ; + +if (enable) + val =DW_VR_MII_EEE_LTX_EN |DW_VR_MII_EEE_LRX_EN | +DW_VR_MII_EEE_TX_QUIET_EN |DW_VR_MII_EEE_RX_QUIET_EN | +DW_VR_MII_EEE_TX_EN_CTRL |DW_VR_MII_EEE_RX_EN_CTRL | +FIELD_PREP (DW_VR_MII_EEE_MULT_FACT_100NS , + xpcs->eee_mult_fact); +else + val =0 ; + + ret =xpcs_modify (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_EEE_MCTRL0 , mask, + val); +if (ret <0 ) +return ret; + +return xpcs_modify (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_EEE_MCTRL1 , +DW_VR_MII_EEE_TRN_LPI , + enable ?DW_VR_MII_EEE_TRN_LPI :0 ); +} +static void xpcs_disable_eee (struct phylink_pcs *pcs) {struct dw_xpcs *xpcs =phylink_pcs_to_xpcs (pcs);
Signature · 1 line
2.30.2
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Mon, 10 Feb 2025 10:52:56 +0000 you wrote:
Hi,
This series adds support for phylink managed EEE at the PCS level, allowing
xpcs_config_eee()to be removed. Sadly, we still end up with a XPCS specific function to configure the clock multiplier.
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 -- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 + drivers/net/pcs/pcs-xpcs.c | 89 +++++++++++++++-------- drivers/net/pcs/pcs-xpcs.h | 1 + drivers/net/phy/phylink.c | 25 ++++++- include/linux/pcs/pcs-xpcs.h | 3 +- include/linux/phylink.h | 22 ++++++ 7 files changed, 107 insertions(+), 42 deletions(-)
Here is the summary with links:
- [net-next,1/8] net: phylink: add support for notifying PCS about EEE
https://git.kernel.org/netdev/net-next/c/e9f03a6a879b - [net-next,2/8] net: xpcs: add function to configure EEE clock multiplying factor https://git.kernel.org/netdev/net-next/c/8c841486674a - [net-next,3/8] net: stmmac: call xpcs_config_eee_mult_fact() https://git.kernel.org/netdev/net-next/c/060fb27060e8 - [net-next,4/8] net: xpcs: convert to phylink managed EEE https://git.kernel.org/netdev/net-next/c/5a12b2cf29c1 - [net-next,5/8] net: stmmac: remove calls to xpcs_config_eee() https://git.kernel.org/netdev/net-next/c/dba7441b3916 - [net-next,6/8] net: xpcs: remove xpcs_config_eee() from global scope https://git.kernel.org/netdev/net-next/c/55faeb89968a - [net-next,7/8] net: xpcs: clean up xpcs_config_eee() https://git.kernel.org/netdev/net-next/c/760320145a5a - [net-next,8/8] net: xpcs: group EEE code together https://git.kernel.org/netdev/net-next/c/1d4c99a1ac12
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html