Skip to contentSkip to conversation

net: mdio: mdio-bcm-unimac: Correct rate fallback logic

PATCH Applied Florian Fainelli 4 participants 4 messages Jul 30, 2025 – Aug 2, 2025

Subsystems (4)
lore
Share & tools
lore

Florian Fainelli

author maintainer
#0 lore raw

PATCH v2 1/1 net: mdio: mdio-bcm-unimac: Correct rate fallback logic

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")

---
Changes in v2:

- provide additional details as to how a parent clock can have a rate of 0 (Andrew)

- incorporate Simon's feedback that an optional clock is NULL and therefore returns a rate of 0 as well

 drivers/net/mdio/mdio-bcm-unimac.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/mdio/mdio-bcm-unimac.c +2 -3
index b6e30bdf5325..7baab230008a 100644
@@ -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) {
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Florian Fainelli

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.

Quoted 7 lines

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")

Andrew

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Florian Fainelli
Quoted 16 lines · Florian Fainelli

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")
Quoted 8 lines

---
Changes in v2:

- provide additional details as to how a parent clock can have a rate of 0 (Andrew)

- incorporate Simon's feedback that an optional clock is NULL and therefore returns a rate of 0 as well

Thanks for the update.

#3 lore raw
In reply to Florian Fainelli
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Wed, 30 Jul 2025 13:25:33 -0700 you wrote:

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.

[...]

Here is the summary with links:
- [net,v2] net: mdio: mdio-bcm-unimac: Correct rate fallback logic

    https://git.kernel.org/netdev/net/c/a81649a4efd3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html