linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
@ 2025-07-29 21:31 Florian Fainelli
  2025-07-29 22:20 ` Andrew Lunn
  2025-07-30 14:33 ` Simon Horman
  0 siblings, 2 replies; 6+ messages in thread
From: Florian Fainelli @ 2025-07-29 21:31 UTC (permalink / raw)
  To: netdev
  Cc: Florian Fainelli, Doug Berger,
	Broadcom internal kernel review list, Andrew Lunn,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Jacob Keller, open list

In case the rate for the parent clock is zero, 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>
---
 drivers/net/mdio/mdio-bcm-unimac.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index b6e30bdf5325..9c0a11316cfd 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -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 (!priv->clk || !rate)
 		rate = 250000000;
-	else
-		rate = clk_get_rate(priv->clk);
 
 	div = (rate / (2 * priv->clk_freq)) - 1;
 	if (div & ~MDIO_CLK_DIV_MASK) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
  2025-07-29 21:31 [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic Florian Fainelli
@ 2025-07-29 22:20 ` Andrew Lunn
  2025-07-29 22:22   ` Florian Fainelli
  2025-07-30 14:33 ` Simon Horman
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2025-07-29 22:20 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, Doug Berger, Broadcom internal kernel review list,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Jacob Keller, open list

On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
> In case the rate for the parent clock is zero,

Is there a legitimate reason the parent clock would be zero?

I can understand an optional clock being missing, but it seems odd
that a clock is available, but it is ticking at 0Hz?

Maybe for this case, a warning should be issued to indicate something
odd is going on?

	Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
  2025-07-29 22:20 ` Andrew Lunn
@ 2025-07-29 22:22   ` Florian Fainelli
  2025-07-29 22:44     ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2025-07-29 22:22 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli
  Cc: netdev, Doug Berger, Broadcom internal kernel review list,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Jacob Keller, open list

On 7/29/25 15:20, Andrew Lunn wrote:
> On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
>> In case the rate for the parent clock is zero,
> 
> Is there a legitimate reason the parent clock would be zero?

Yes there is, the parent clock might be a gated clock that aggregates 
multiple sub-clocks and therefore has multiple "parents" technically. 
Because it has multiple parents, we can't really return a particular 
rate (clock provider is SCMI/firmware).

> 
> I can understand an optional clock being missing, but it seems odd
> that a clock is available, but it is ticking at 0Hz?
> 
> Maybe for this case, a warning should be issued to indicate something
> odd is going on?
> 
> 	Andrew
> 

-- 
Florian


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
  2025-07-29 22:22   ` Florian Fainelli
@ 2025-07-29 22:44     ` Andrew Lunn
  2025-07-29 22:50       ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2025-07-29 22:44 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, Doug Berger, Broadcom internal kernel review list,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Jacob Keller, open list

On Tue, Jul 29, 2025 at 03:22:57PM -0700, Florian Fainelli wrote:
> On 7/29/25 15:20, Andrew Lunn wrote:
> > On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
> > > In case the rate for the parent clock is zero,
> > 
> > Is there a legitimate reason the parent clock would be zero?
> 
> Yes there is, the parent clock might be a gated clock that aggregates
> multiple sub-clocks and therefore has multiple "parents" technically.
> Because it has multiple parents, we can't really return a particular rate
> (clock provider is SCMI/firmware).

O.K. Maybe add this to the commit message?

	Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
  2025-07-29 22:44     ` Andrew Lunn
@ 2025-07-29 22:50       ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2025-07-29 22:50 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: netdev, Doug Berger, Broadcom internal kernel review list,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Jacob Keller, open list

On 7/29/25 15:44, Andrew Lunn wrote:
> On Tue, Jul 29, 2025 at 03:22:57PM -0700, Florian Fainelli wrote:
>> On 7/29/25 15:20, Andrew Lunn wrote:
>>> On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
>>>> In case the rate for the parent clock is zero,
>>>
>>> Is there a legitimate reason the parent clock would be zero?
>>
>> Yes there is, the parent clock might be a gated clock that aggregates
>> multiple sub-clocks and therefore has multiple "parents" technically.
>> Because it has multiple parents, we can't really return a particular rate
>> (clock provider is SCMI/firmware).
> 
> O.K. Maybe add this to the commit message?

That makes sense, v2 tomorrow, thanks!
-- 
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic
  2025-07-29 21:31 [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic Florian Fainelli
  2025-07-29 22:20 ` Andrew Lunn
@ 2025-07-30 14:33 ` Simon Horman
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Horman @ 2025-07-30 14:33 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, Doug Berger, Broadcom internal kernel review list,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jacob Keller,
	open list

On Tue, Jul 29, 2025 at 02:31:48PM -0700, Florian Fainelli wrote:
> In case the rate for the parent clock is zero, 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>
> ---
>  drivers/net/mdio/mdio-bcm-unimac.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
> index b6e30bdf5325..9c0a11316cfd 100644
> --- a/drivers/net/mdio/mdio-bcm-unimac.c
> +++ b/drivers/net/mdio/mdio-bcm-unimac.c
> @@ -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 (!priv->clk || !rate)

If priv->clk is NULL then drivers/clk/clk.c:clk_get_rate()
(are there other relevant implementations?) will return 0.
So I think the condition above is tautological, and could be expressed as:

	if (!rate)

>  		rate = 250000000;
> -	else
> -		rate = clk_get_rate(priv->clk);
>  
>  	div = (rate / (2 * priv->clk_freq)) - 1;
>  	if (div & ~MDIO_CLK_DIV_MASK) {
> -- 
> 2.34.1
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-30 14:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29 21:31 [PATCH net] net: mdio: mdio-bcm-unimac: Correct rate fallback logic Florian Fainelli
2025-07-29 22:20 ` Andrew Lunn
2025-07-29 22:22   ` Florian Fainelli
2025-07-29 22:44     ` Andrew Lunn
2025-07-29 22:50       ` Florian Fainelli
2025-07-30 14:33 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).