Re: [PATCH net-next v2 05/14] net: stmmac: add stmmac core serdes support
From: Vladimir Oltean <olteanv@gmail.com>
Date: 2026-01-24 00:59:57
Also in:
linux-arm-kernel, linux-arm-msm, linux-phy
Subsystem:
networking drivers, stmmac ethernet driver, the rest · Maintainers:
Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
On Fri, Jan 23, 2026 at 09:53:44AM +0000, Russell King (Oracle) wrote:
Rather than having platform glue implement SerDes PHY support, add it to the core driver, specifically to the stmmac integrated PCS driver as the SerDes is connected to the integrated PCS. Platforms using external PCS can also populate plat->serdes, and the core driver will call phy_init() and phy_exit() when the administrative state of the interface changes, but the other phy methods will not be called. Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Signed-off-by: Russell King (Oracle) <redacted> -- rfc->v1: avoid calling phy_get_mode() with NULL serdes PHY v2: add cleanup when dwmac_serdes_set_mode() fails, because AI allegedly knows better than the author and phylink maintainer, even though this will result in dwmac_serdes_power_off() being called multiple times and producing a kernel warning. But if it makes AI happy, then it must be a good thing. It'll also make Vladimir happy.
These gratuitous passive-aggressive comments about what makes me happy, based on twisted interpretations of conversations, are best kept to yourself. I remember Jakub's request was only to add a note in the commit message about the reason behind the lack of cleanup, not to add cleanup which will be executed twice: https://lore.kernel.org/netdev/20260120153248.0636f1e9@kernel.org/ (local) I only expressed dissatisfaction with the phylink_pcs calling convention as it is today, and searched for ways to make the calls balanced. I also didn't make any suggestion to make the code worse by performing the SerDes power down twice, just subscribed to Jakub's request to leave a comment why your v1 is the way that it is: https://lore.kernel.org/netdev/20260122112913.svzaie4eywk5nc32@skbuf/ (local) Getting over that dissatisfaction and working within the framework of the existing calling convention, but also inserting the comment that I was looking to see, I believe that functionally correct code would look like this (applies on top of your entire v2 patch set): -- >8 --
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_serdes.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_serdes.c
index d46a071bc383..c4465dca6b93 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_serdes.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_serdes.c@@ -59,12 +59,27 @@ int dwmac_serdes_power_on(struct stmmac_priv *priv) { int ret; + /* Because the dwmac_integrated_pcs_disable() call path is eventually + * invoked irrespective of the dwmac_integrated_pcs_enable() return + * code, we risk either underflowing the SerDes phy->power_count or + * leaving the lane powered on, depending on the cleanup choice and the + * point of failure. Keeping separate track of the lane power on state + * is a band aid until phylink offers balanced pcs_enable() and + * pcs_disable() calls. + */ + if (priv->plat->serdes_powered_on) + return 0; + ret = phy_power_on(priv->plat->serdes); - if (ret) + if (ret) { dev_err(priv->device, "failed to power on SerDes: %pe\n", ERR_PTR(ret)); + return ret; + } - return ret; + priv->plat->serdes_powered_on = true; + + return 0; } int dwmac_serdes_init_mode(struct stmmac_priv *priv, phy_interface_t interface)
@@ -95,10 +110,17 @@ void dwmac_serdes_power_off(struct stmmac_priv *priv) { int ret; + if (!priv->plat->serdes_powered_on) + return; + ret = phy_power_off(priv->plat->serdes); - if (ret) + if (ret) { dev_err(priv->device, "failed to power off SerDes: %pe\n", ERR_PTR(ret)); + return; + } + + priv->plat->serdes_powered_on = false; } void dwmac_serdes_exit(struct stmmac_priv *priv)
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 6097f4b6dd12..e62bba38ab60 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h@@ -225,6 +225,7 @@ struct plat_stmmacenet_data { */ phy_interface_t phy_interface; struct phy *serdes; + bool serdes_powered_on; struct stmmac_mdio_bus_data *mdio_bus_data; struct device_node *phy_node; struct fwnode_handle *port_node; -- >8 --