net: mdio: mdio-bcm-unimac: Correct rate fallback logic
authorFlorian Fainelli <florian.fainelli@broadcom.com>
Wed, 30 Jul 2025 20:25:33 +0000 (13:25 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 1 Aug 2025 21:46:50 +0000 (14:46 -0700)
When the parent clock is a gated clock which has multiple parents, the
clock provider (clk-scmi typically) might return a rate of 0 since there
is not one of those particular parent clocks that should be chosen for
returning a rate. Prior to ee975351cf0c ("net: mdio: mdio-bcm-unimac:
Manage clock around I/O accesses"), we would not always be passing a
clock reference depending upon how mdio-bcm-unimac was instantiated. In
that case, we would take the fallback path where the rate is hard coded
to 250MHz.

Make sure that we still fallback to using a fixed rate for the divider
calculation, otherwise we simply ignore the desired MDIO bus clock
frequency which can prevent us from interfacing with Ethernet PHYs
properly.

Fixes: ee975351cf0c ("net: mdio: mdio-bcm-unimac: Manage clock around I/O accesses")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250730202533.3463529-1-florian.fainelli@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/mdio/mdio-bcm-unimac.c

index b6e30bdf5325749a5b284c7b8b1b84012db0398b..7baab230008a42937e0d58d22ea6128807400ab0 100644 (file)
@@ -209,10 +209,9 @@ static int unimac_mdio_clk_set(struct unimac_mdio_priv *priv)
        if (ret)
                return ret;
 
-       if (!priv->clk)
+       rate = clk_get_rate(priv->clk);
+       if (!rate)
                rate = 250000000;
-       else
-               rate = clk_get_rate(priv->clk);
 
        div = (rate / (2 * priv->clk_freq)) - 1;
        if (div & ~MDIO_CLK_DIV_MASK) {