Fix missing PHY-to-MAC RX clock
Subsystems (8)
v2 cover Fix missing PHY-to-MAC RX clock
Hello everyone,
This is version two of my series that addresses the issue with some MAC/PHY combinations. Version one was sent on net, not net-next.
Notable changes in v2:
- Introduced a pcs op for initializing hardware required for MAC initialization, instead of using phylink_validate() for this purpose.
- Refactored stmmac to use a generic PCS reference in mac_device_info instead of a model-specific field.
There is an issue with some stmmac/PHY combinations that has been reported some time ago in a couple of different series:
Clark Wang's report:
https://lore.kernel.org/all/[email protected]/
Clément Léger's report:
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Stmmac controllers require an RX clock signal from the MII bus to perform their hardware initialization successfully. This causes issues with some PHY/PCS devices. If these devices do not bring the clock signal up before the MAC driver initializes its hardware, then said initialization will fail. This can happen at probe time or when the system wakes up from a suspended state.
This series introduces new flags for phy_device and phylink_pcs. These flags allow MAC drivers to signal to PHY/PCS drivers that the RX clock signal should be enabled as soon as possible, and that it should always stay enabled.
I have included specific uses of these flags that fix the RZN1 GMAC1 stmmac driver that I am currently working on and that is not yet upstream. I have also included changes to the at803x PHY driver that should fix the issue that Clark Wang was having.
Clark, could you please confirm that this series fixes your issue with the at803x PHY?
Best Regards,
Romain
Romain Gantois (2):
net: phy: add rxc_always_on flag to phylink_pcs
net: pcs: rzn1-miic: Init RX clock early if MAC requires it
Russell King (3):
net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
net: stmmac: Signal to PHY/PCS drivers to keep RX clock on
net: phy: at803x: Avoid hibernating if MAC requires RX clock
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ drivers/net/pcs/pcs-rzn1-miic.c | 18 +++++++++++++----- drivers/net/phy/at803x.c | 3 ++- drivers/net/phy/phylink.c | 13 ++++++++++++- include/linux/phy.h | 1 + include/linux/phylink.h | 9 +++++++++ 6 files changed, 42 insertions(+), 7 deletions(-)
--
2.43.0
---
Maxime Chevallier (1):
net: stmmac: don't rely on lynx_pcs presence to check for a PHY
Romain Gantois (4):
net: phy: add rxc_always_on flag to phylink_pcs
net: stmmac: Support a generic PCS field in mac_device_info
net: stmmac: Signal to PHY/PCS drivers to keep RX clock on
net: pcs: rzn1-miic: Init RX clock early if MAC requires it
Russell King (2):
net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
net: phy: at803x: Avoid hibernating if MAC requires RX clock
drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 8 ++++---- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 ++++++++------ drivers/net/pcs/pcs-rzn1-miic.c | 16 +++++++++++++++ drivers/net/phy/at803x.c | 3 ++- drivers/net/phy/phylink.c | 24 +++++++++++++++++++++- include/linux/phy.h | 1 + include/linux/phylink.h | 15 ++++++++++++++ 8 files changed, 71 insertions(+), 13 deletions(-)
---
base-commit: 795a7dfbc3d95e4c7c09569f319f026f8c7f5a9c
change-id: 20240126-rxc_bugfix-d47b3b1a374f
Best regards,
Signature · 1 line
Romain Gantois <[email protected]>
PATCH v2 1/7 net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
From: Russell King <[email protected]>
Some MAC controllers (e.g. stmmac) require their connected PHY to continuously provide a receive clock signal. This can cause issues in two cases:
1. The clock signal hasn't been started yet by the time the MAC driver initializes its hardware. This can make the initialization fail, as in the case of the rzn1 GMAC1 driver.
2. The clock signal is cut during a power saving event. By the time the MAC is brought back up, the clock signal is still not active since phylink_start hasn't been called yet. This brings us back to case 1.
If a PHY driver reads this flag, it should ensure that the receive clock signal is started as soon as possible, and that it isn't brought down when the PHY goes into suspend.
--- drivers/net/phy/phylink.c | 10 +++++++++- include/linux/phy.h | 1 + include/linux/phylink.h | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/net/phy/phylink.c +9 -1
@@ -1923,6 +1923,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,static int phylink_attach_phy (struct phylink *pl,struct phy_device *phy,phy_interface_t interface) { +u32 flags =0 ; +if (WARN_ON (pl->cfg_link_an_mode ==MLO_AN_FIXED || (pl->cfg_link_an_mode ==MLO_AN_INBAND &&phy_interface_mode_is_8023z (interface) && !pl->sfp_bus)))
@@ -1931,7 +1933,10 @@ static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,if (pl->phydev)return -EBUSY ; -return phy_attach_direct (pl->netdev, phy,0 , interface); +if (pl->config->mac_requires_rxc) + flags |=PHY_F_RXC_ALWAYS_ON ; + +return phy_attach_direct (pl->netdev, phy, flags, interface); }/**
@@ -2034,6 +2039,9 @@ int phylink_fwnode_phy_connect(struct phylink *pl, pl->link_config.interface = pl->link_interface; } +if (pl->config->mac_requires_rxc) + flags |=PHY_F_RXC_ALWAYS_ON ; + ret =phy_attach_direct (pl->netdev, phy_dev, flags, pl->link_interface);phy_device_free (phy_dev);
include/linux/phy.h +1 -0
@@ -768,6 +768,7 @@ struct phy_device {/* Generic phy_device::dev_flags */ #define PHY_F_NO_IRQ 0x80000000 +#define PHY_F_RXC_ALWAYS_ON BIT(30)static inline struct phy_device *to_phy_device (const struct device *dev) {
include/linux/phylink.h +4 -0
@@ -138,6 +138,9 @@ enum phylink_op_type {* @poll_fixed_state: if true, starts link_poll, * if MAC link is at %MLO_AN_FIXED mode. * @mac_managed_pm: if true, indicate the MAC driver is responsible for PHY PM. +* @mac_requires_rxc: if true, the MAC always requires a receive clock from PHY. +* The PHY driver should start the clock signal as soon as +* possible and avoid stopping it during suspend events. * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND * @get_fixed_state: callback to execute to determine the fixed link state, * if MAC link is at %MLO_AN_FIXED mode.
@@ -150,6 +153,7 @@ struct phylink_config {enum phylink_op_type type;bool poll_fixed_state;bool mac_managed_pm; +bool mac_requires_rxc;bool ovr_an_inband;void (*get_fixed_state)(struct phylink_config *config,struct phylink_link_state *state);
Signature · 1 line
2.43.0
Russell King (Oracle)
maintainerRe: [PATCH net-next v2 1/7] net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
Quoted 13 lines · Romain Gantois
From: Russell King <[email protected]>
Some MAC controllers (e.g. stmmac) require their connected PHY to continuously provide a receive clock signal. This can cause issues in two cases:
1. The clock signal hasn't been started yet by the time the MAC driver initializes its hardware. This can make the initialization fail, as in the case of the rzn1 GMAC1 driver.
2. The clock signal is cut during a power saving event. By the time the MAC is brought back up, the clock signal is still not active sincephylink_starthasn't been called yet. This brings us back to case 1.
Quoted 7 lines
If a PHY driver reads this flag, it should ensure that the receive clock signal is started as soon as possible, and that it isn't brought down when the PHY goes into suspend.
Signed-off-by Russell King <[email protected]>[rgantois: commit log]Signed-off-by Romain Gantois <[email protected]>
You seem to have combined two of my patches into this one, which touch two different bits of code. I'm fine with that, but please adjust the subject line to match the _majority_ of the code that is being touched, which is phylink (having the prefix net: phylink:), rather than phylib (having the prefix net: phy:).
Thanks.
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!
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
In reply to Romain Gantoisinclude/linux/phy.h struct phy_device { · line 771
Quoted 5 lines
include/linux/phy.h +1
-0@@ -768,6 +768,7 @@ struct phy_device {/* Generic phy_device::dev_flags */ #define PHY_F_NO_IRQ 0x80000000 +#define PHY_F_RXC_ALWAYS_ON BIT(30)
It is a bit odd mixing 0x numbers and BIT() macros for the same class of thing. I would use 0x40000000, or convert PHY_F_NO_IRQ to BIT(31)
Andrew
Russell King (Oracle)
maintainerRe: [PATCH net-next v2 1/7] net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
Quoted 8 lines · Andrew Lunn
include/linux/phy.h struct phy_device { · line 771
Quoted 5 lines
include/linux/phy.h +1
-0@@ -768,6 +768,7 @@ struct phy_device {/* Generic phy_device::dev_flags */ #define PHY_F_NO_IRQ 0x80000000 +#define PHY_F_RXC_ALWAYS_ON BIT(30)It is a bit odd mixing 0x numbers and
BIT()macros for the same class of thing. I would use0x40000000, or convertPHY_F_NO_IRQto BIT(31)
If I used 0x40000000, there would be review comments suggesting the use of BIT(). Can't win!
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!
Andrew Lunn
maintainerRe: [PATCH net-next v2 1/7] net: phy: add PHY_F_RXC_ALWAYS_ON to PHY dev flags
Quoted 10 lines · Russell King (Oracle)
Quoted 8 lines · Andrew Lunn
include/linux/phy.h struct phy_device { · line 771
Quoted 5 lines
include/linux/phy.h +1
-0@@ -768,6 +768,7 @@ struct phy_device {/* Generic phy_device::dev_flags */ #define PHY_F_NO_IRQ 0x80000000 +#define PHY_F_RXC_ALWAYS_ON BIT(30)It is a bit odd mixing 0x numbers and
BIT()macros for the same class of thing. I would use0x40000000, or convertPHY_F_NO_IRQto BIT(31)
Quoted 2 lines
If I used
0x40000000, there would be review comments suggesting the use ofBIT(). Can't win!
No, you cannot win, but at least it would be consistent :-)
Andrew
PATCH v2 2/7 net: phy: add rxc_always_on flag to phylink_pcs
In reply to Romain GantoisSome MAC drivers (e.g. stmmac) require a continuous receive clock signal to be generated by a PCS that is handled by a standalone PCS driver.
Such a PCS driver does not have access to a PHY device, thus cannot check the PHY_F_RXC_ALWAYS_ON flag. They cannot check max_requires_rxc in the phylink config either, since it is a private member. Therefore, a new flag is needed to signal to the PCS that it should keep the RX clock signal up at all times.
--- drivers/net/phy/phylink.c | 14 ++++++++++++++ include/linux/phylink.h | 11 +++++++++++ 2 files changed, 25 insertions(+)
drivers/net/phy/phylink.c +14 -0
@@ -1042,6 +1042,20 @@ static void phylink_pcs_poll_start(struct phylink *pl)mod_timer (&pl->link_poll, jiffies +HZ ); } +int phylink_pcs_pre_init (struct phylink *pl,struct phylink_pcs *pcs) +{ +int ret =0 ; + +/* Signal to PCS driver that MAC requires RX clock for init */ +if (pl->config->mac_requires_rxc) + pcs->rxc_always_on = true; + +if (pcs->ops->pcs_pre_init) + ret = pcs->ops->pcs_pre_init (pcs, pl->link_config.interface); + +return ret; +} +static void phylink_mac_config (struct phylink *pl,const struct phylink_link_state *state) {
include/linux/phylink.h +11 -0
@@ -396,6 +396,10 @@ struct phylink_pcs_ops;* @phylink: pointer to &struct phylink_config * @neg_mode: provide PCS neg mode via "mode" argument * @poll: poll the PCS for link changes +* @rxc_always_on: The MAC driver requires the reference clock +* to always be on. Standalone PCS drivers which +* do not have access to a PHY device can check +* this instead of PHY_F_RXC_ALWAYS_ON. * * This structure is designed to be embedded within the PCS private data, * and will be passed between phylink and the PCS.
@@ -408,6 +412,7 @@ struct phylink_pcs {struct phylink *phylink;bool neg_mode;bool poll; +bool rxc_always_on; };/**
@@ -422,6 +427,8 @@ 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_pre_init: configure PCS components necessary for MAC hardware +* initialization e.g. RX clock for stmmac. */ struct phylink_pcs_ops { int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,
@@ -441,6 +448,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); +int (*pcs_pre_init)(struct phylink_pcs *pcs, +phy_interface_t interface); };#if 0 /* For kernel-doc purposes only. */
@@ -568,6 +577,8 @@ void phylink_disconnect_phy(struct phylink *);void phylink_mac_change (struct phylink *,bool up);void phylink_pcs_change (struct phylink_pcs *,bool up); +int phylink_pcs_pre_init (struct phylink *pl,struct phylink_pcs *pcs); +void phylink_start (struct phylink *);void phylink_stop (struct phylink *);
Signature · 1 line
2.43.0
Russell King (Oracle)
maintainerRe: [PATCH net-next v2 2/7] net: phy: add rxc_always_on flag to phylink_pcs
Quoted 24 lines · Romain Gantois
Some MAC drivers (e.g. stmmac) require a continuous receive clock signal to be generated by a PCS that is handled by a standalone PCS driver.
Such a PCS driver does not have access to a PHY device, thus cannot check the
PHY_F_RXC_ALWAYS_ONflag. They cannot checkmax_requires_rxcin the phylink config either, since it is a private member. Therefore, a new flag is needed to signal to the PCS that it should keep the RX clock signal up at all times.Suggested-by Russell King <[email protected]>Signed-off-by Romain Gantois <[email protected]>--- drivers/net/phy/phylink.c | 14 ++++++++++++++ include/linux/phylink.h | 11 +++++++++++ 2 files changed, 25 insertions(+)drivers/net/phy/phylink.c +0
-0@@ -1042,6 +1042,20 @@ static void phylink_pcs_poll_start(struct phylink *pl)mod_timer (&pl->link_poll, jiffies +HZ ); }
drivers/net/phy/phylink.c static void phylink_pcs_poll_start(struct phylink *pl) · line 1054
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+int phylink_pcs_pre_init (struct phylink *pl,struct phylink_pcs *pcs) +{ +int ret =0 ; + +/* Signal to PCS driver that MAC requires RX clock for init */ +if (pl->config->mac_requires_rxc) + pcs->rxc_always_on = true; + +if (pcs->ops->pcs_pre_init) + ret = pcs->ops->pcs_pre_init (pcs, pl->link_config.interface);
Given that:
1) phylink supports switching between mutliple different interfaces,
2) from what I can see you are only calling this from stmmac's initialisation path,
3) you pass the interface mode to the PCS here
then we don't want the PCS to configure itself for the interface mode passed in, because this function won't be called when the interface mode changes - and PCS driver authors will have to bear that in mind. So...
include/linux/phylink.h struct phylink_pcs { · line 431
Quoted 10 lines
include/linux/phylink.h +2
-0@@ -422,6 +427,8 @@ 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_pre_init: configure PCS components necessary for MAC hardware +* initialization e.g. RX clock for stmmac.
This is fine as a short description.
include/linux/phylink.h struct phylink_pcs_ops { · line 452
Quoted 9 lines
include/linux/phylink.h +2
-0*/ struct phylink_pcs_ops { int (*pcs_validate)(struct phylink_pcs *pcs, unsigned long *supported,@@ -441,6 +448,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); +int (*pcs_pre_init)(struct phylink_pcs *pcs, +phy_interface_t interface);
... I would prefer this to be called initial_interface to make it clear that it's just the initial interface mode.
However, do we really need it - if the PCS is supplying the RXC to the MAC, then is the interface mode between the PCS and PHY all that relevant at this point?
Also, please note that this is poor documentation for this function (encouraged by broken kernel doc not able to properly describe "ops" structures). See further down in the #if 0..#endif block where each and every function in this ops structure is fully documented. Please do the same for any new functions added.
Thanks.
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 net-next v2 2/7] net: phy: add rxc_always_on flag to phylink_pcs
Hello Russell,
On Tue, 30 Jan 2024, Russell King (Oracle) wrote:
...
Quoted 22 lines
drivers/net/phy/phylink.c static void phylink_pcs_poll_start(struct phylink *pl) · line 1054
Quoted 10 lines
drivers/net/phy/phylink.c +10
-0+int phylink_pcs_pre_init (struct phylink *pl,struct phylink_pcs *pcs) +{ +int ret =0 ; + +/* Signal to PCS driver that MAC requires RX clock for init */ +if (pl->config->mac_requires_rxc) + pcs->rxc_always_on = true; + +if (pcs->ops->pcs_pre_init) + ret = pcs->ops->pcs_pre_init (pcs, pl->link_config.interface);Given that:
1) phylink supports switching between mutliple different interfaces,
2) from what I can see you are only calling this from stmmac's initialisation path,
3) you pass the interface mode to the PCS herethen we don't want the PCS to configure itself for the interface mode passed in, because this function won't be called when the interface mode changes - and PCS driver authors will have to bear that in mind. So...
...
Quoted 3 lines
However, do we really need it - if the PCS is supplying the RXC to the MAC, then is the interface mode between the PCS and PHY all that relevant at this point?
If a PCS can set the needed clock signal without configuring the details of a particular link mode, then passing the interface mode to pcs_pre_init() would indeed not be relevant. Generally, I agree that setting the interface mode shouldn't be the concern of the pre-initialization function. I'll dig a bit more into the PCS datasheet and run more tests to see if I can get away with enabling the RX clock selectively for this particular PCS model. If not, then maybe I can hardcode a "default" interface mode for the pre-initialization that will not interfere with the rest of the link setup process.
Best Regards,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 3/7 net: stmmac: don't rely on lynx_pcs presence to check for a PHY
In reply to Romain GantoisFrom: Maxime Chevallier <[email protected]>
When initializing attached PHYs, there are some cases where we don't expect any PHY to be connected. The logic uses conditions based on various local PCS configuration, but also calls-in phylink_expects_phy() via stmmac_init_phy(), which is enough to ensure we don't try to initialize a PHY when using a Lynx PCS, as long as we have the phy_interface set to a 802.3z mode and are using inband negociation.
Drop the lynx check, making the stmmac generic code more pcs_lynx-agnostic.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -2
@@ -3918,8 +3918,7 @@ static int __stmmac_open(struct net_device *dev,if (priv->hw->pcs !=STMMAC_PCS_TBI && priv->hw->pcs !=STMMAC_PCS_RTBI && (!priv->hw->xpcs || -xpcs_get_an_mode (priv->hw->xpcs, mode) !=DW_AN_C73 ) && - !priv->hw->lynx_pcs) { +xpcs_get_an_mode (priv->hw->xpcs, mode) !=DW_AN_C73 )) { ret =stmmac_init_phy (dev);if (ret) { netdev_err(priv->dev,
Signature · 1 line
2.43.0
PATCH v2 4/7 net: stmmac: Support a generic PCS field in mac_device_info
In reply to Romain GantoisGlobal stmmac support for early initialization of PCS devices requires a generic PCS reference that can be passed to phylink_pcs_pre_init(). Currently, the mac_device_info struct contains only one PCS field, which is specific to the Lynx model.
As PCS models are hardware-specific, it is more appropriate to have a generic PCS field in the mac_device_info struct.
Refactor the lynx_pcs field into a generic phylink_pcs field.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 8 ++++---- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +---- 3 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -1
@@ -565,7 +565,7 @@ struct mac_device_info {const struct stmmac_mmc_ops *mmc;const struct stmmac_est_ops *est;struct dw_xpcs *xpcs; -struct phylink_pcs *lynx_pcs;/* Lynx external PCS */ +struct phylink_pcs *phylink_pcs;struct mii_regs mii;/* MII register Addresses */ struct mac_link link;void __iomem *pcsr;/* vpointer to device CSRs */
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +4 -4
@@ -479,9 +479,9 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) goto err_dvr_remove; } - stpriv->hw->lynx_pcs =lynx_pcs_create_mdiodev (pcs_bus,0 ); -if (IS_ERR (stpriv->hw->lynx_pcs)) { - ret =PTR_ERR (stpriv->hw->lynx_pcs); + stpriv->hw->phylink_pcs =lynx_pcs_create_mdiodev (pcs_bus,0 ); +if (IS_ERR (stpriv->hw->phylink_pcs)) { + ret =PTR_ERR (stpriv->hw->phylink_pcs); goto err_dvr_remove; } }
@@ -498,7 +498,7 @@ static void socfpga_dwmac_remove(struct platform_device *pdev) {struct net_device *ndev =platform_get_drvdata (pdev);struct stmmac_priv *priv =netdev_priv (ndev); -struct phylink_pcs *pcs = priv->hw->lynx_pcs; +struct phylink_pcs *pcs = priv->hw->phylink_pcs;stmmac_pltfr_remove (pdev);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -4
@@ -944,10 +944,7 @@ static struct phylink_pcs *stmmac_mac_select_pcs(struct phylink_config *config,if (priv->hw->xpcs)return &priv->hw->xpcs->pcs; -if (priv->hw->lynx_pcs) -return priv->hw->lynx_pcs; - -return NULL ; +return priv->hw->phylink_pcs; } static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
Signature · 1 line
2.43.0
PATCH v2 5/7 net: stmmac: Signal to PHY/PCS drivers to keep RX clock on
In reply to Romain GantoisThere is a reocurring issue with stmmac controllers where the MAC fails to initialize its hardware if an RX clock signal isn't provided on the MAC/PHY link.
This causes issues when PHY or PCS devices either go into suspend while cutting the RX clock or do not bring the clock signal up early enough for the MAC to initialize successfully.
Set the mac_requires_rxc flag in the stmmac phylink config so that PHY/PCS drivers know to keep the RX clock up at all times.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
@@ -1218,6 +1218,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) priv->phylink_config.type =PHYLINK_NETDEV ; priv->phylink_config.mac_managed_pm = true; +/* Stmmac always requires an RX clock for hardware initialization */ + priv->phylink_config.mac_requires_rxc = true; + mdio_bus_data = priv->plat->mdio_bus_data;if (mdio_bus_data) priv->phylink_config.ovr_an_inband =
@@ -3402,6 +3405,10 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)u32 chan;int ret; +/* Make sure RX clock is enabled */ +if (priv->hw->phylink_pcs) +phylink_pcs_pre_init (priv->phylink, priv->hw->phylink_pcs); +/* DMA initialization and SW reset */ ret =stmmac_init_dma_engine (priv);if (ret <0 ) {
Signature · 1 line
2.43.0
PATCH v2 6/7 net: phy: at803x: Avoid hibernating if MAC requires RX clock
In reply to Romain GantoisFrom: Russell King <[email protected]>
Stmmac controllers connected to an at803x PHY cannot resume properly after suspend when WoL is enabled. This happens because the MAC requires an RX clock generated by the PHY to initialize its hardware properly. But the RX clock is cut when the PHY suspends and isn't brought up until the MAC driver resumes the phylink.
Prevent the at803x PHY driver from going into suspend if the attached MAC driver always requires an RX clock signal.
--- drivers/net/phy/at803x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/at803x.c +2 -1
@@ -895,7 +895,8 @@ static int at803x_hibernation_mode_config(struct phy_device *phydev)/* The default after hardware reset is hibernation mode enabled. After * software reset, the value is retained. */ -if (!(priv->flags &AT803X_DISABLE_HIBERNATION_MODE )) +if (!(priv->flags &AT803X_DISABLE_HIBERNATION_MODE ) && + !(phydev->dev_flags &PHY_F_RXC_ALWAYS_ON ))return 0 ; return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_HIB_CTRL,
Signature · 1 line
2.43.0
PATCH v2 7/7 net: pcs: rzn1-miic: Init RX clock early if MAC requires it
In reply to Romain GantoisThe GMAC1 controller in the RZN1 IP requires the RX MII clock signal to be started before it initializes its own hardware, thus before it calls phylink_start.
Check the rxc_always_on pcs flag and enable the clock signal during the link validation phase.
--- drivers/net/pcs/pcs-rzn1-miic.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/pcs/pcs-rzn1-miic.c +16 -0
@@ -279,10 +279,26 @@ static int miic_validate(struct phylink_pcs *pcs, unsigned long *supported,return -EINVAL ; } +static int miic_pre_init (struct phylink_pcs *pcs, +phy_interface_t interface) +{ +int ret =0 ; + +/* Start RX clock if required */ +if (pcs->rxc_always_on) { + ret =miic_config (pcs,0 , interface,NULL , false); +if (ret) +pr_err ("Error: Failed to init RX clock in RZN1 MIIC PCS!" ); + } + +return ret; +} +static const struct phylink_pcs_ops miic_phylink_ops = { .pcs_validate = miic_validate, .pcs_config = miic_config, .pcs_link_up = miic_link_up, + .pcs_pre_init = miic_pre_init, };struct phylink_pcs *miic_create (struct device *dev,struct device_node *np)
Signature · 1 line
2.43.0
Maxime Chevallier
maintainerHello Romain,
Quoted 10 lines · On Tue, 30 Jan 2024 10:28:35 +0100 Romain Gantois <[email protected]>…
Hello everyone,
This is version two of my series that addresses the issue with some MAC/PHY combinations. Version one was sent on net, not net-next.
Notable changes in v2:
- Introduced a pcs op for initializing hardware required for MAC initialization, instead of usingphylink_validate()for this purpose.
- Refactored stmmac to use a generic PCS reference inmac_device_infoinstead of a model-specific field.
As this impacts the dwmac-socfpga lynx integration, I'd like to give it a try, I'll be able to give some feedback on that part probably tomorrow.
Thanks,
Maxime