diff mbox series

[net] net: dsa: bcm_sf2: Do not register slave MDIO bus with OF

Message ID 20200404213517.12783-1-f.fainelli@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series [net] net: dsa: bcm_sf2: Do not register slave MDIO bus with OF | expand

Commit Message

Florian Fainelli April 4, 2020, 9:35 p.m. UTC
We were registering our slave MDIO bus with OF and doing so with
assigning the newly created slave_mii_bus of_node to the master MDIO bus
controller node. This is a bad thing to do for a number of reasons:

- we are completely lying about the slave MII bus is arranged and yet we
  still want to control which MDIO devices it probes. It was attempted
  before to play tricks with the bus_mask to perform that:
  https://www.spinics.net/lists/netdev/msg429420.html but the approach
  was rightfully rejected

- the device_node reference counting is messed up and we are effectively
  doing a double probe on the devices we already probed using the
  master, this messes up all resources reference counts (such as clocks)

The proper fix for this as indicated by David in his reply to the
thread above is to use a platform data style registration so as to
control exactly which devices we probe:
https://www.spinics.net/lists/netdev/msg430083.html

By using mdiobus_register(), our slave_mii_bus->phy_mask value is used
as intended, and all the PHY addresses that must be redirected towards
our slave MDIO bus is happening while other addresses get redirected
towards the master MDIO bus.

Fixes: 461cd1b03e32 ("net: dsa: bcm_sf2: Register our slave MDIO bus")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/bcm_sf2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vivien Didelot April 6, 2020, 3:30 p.m. UTC | #1
On Sat,  4 Apr 2020 14:35:17 -0700, Florian Fainelli <f.fainelli@gmail.com> wrote:
> We were registering our slave MDIO bus with OF and doing so with
> assigning the newly created slave_mii_bus of_node to the master MDIO bus
> controller node. This is a bad thing to do for a number of reasons:
> 
> - we are completely lying about the slave MII bus is arranged and yet we
>   still want to control which MDIO devices it probes. It was attempted
>   before to play tricks with the bus_mask to perform that:
>   https://www.spinics.net/lists/netdev/msg429420.html but the approach
>   was rightfully rejected
> 
> - the device_node reference counting is messed up and we are effectively
>   doing a double probe on the devices we already probed using the
>   master, this messes up all resources reference counts (such as clocks)
> 
> The proper fix for this as indicated by David in his reply to the
> thread above is to use a platform data style registration so as to
> control exactly which devices we probe:
> https://www.spinics.net/lists/netdev/msg430083.html
> 
> By using mdiobus_register(), our slave_mii_bus->phy_mask value is used
> as intended, and all the PHY addresses that must be redirected towards
> our slave MDIO bus is happening while other addresses get redirected
> towards the master MDIO bus.
> 
> Fixes: 461cd1b03e32 ("net: dsa: bcm_sf2: Register our slave MDIO bus")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
David Miller April 6, 2020, 5:08 p.m. UTC | #2
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Sat,  4 Apr 2020 14:35:17 -0700

> We were registering our slave MDIO bus with OF and doing so with
> assigning the newly created slave_mii_bus of_node to the master MDIO bus
> controller node. This is a bad thing to do for a number of reasons:
> 
> - we are completely lying about the slave MII bus is arranged and yet we
>   still want to control which MDIO devices it probes. It was attempted
>   before to play tricks with the bus_mask to perform that:
>   https://www.spinics.net/lists/netdev/msg429420.html but the approach
>   was rightfully rejected
> 
> - the device_node reference counting is messed up and we are effectively
>   doing a double probe on the devices we already probed using the
>   master, this messes up all resources reference counts (such as clocks)
> 
> The proper fix for this as indicated by David in his reply to the
> thread above is to use a platform data style registration so as to
> control exactly which devices we probe:
> https://www.spinics.net/lists/netdev/msg430083.html
> 
> By using mdiobus_register(), our slave_mii_bus->phy_mask value is used
> as intended, and all the PHY addresses that must be redirected towards
> our slave MDIO bus is happening while other addresses get redirected
> towards the master MDIO bus.
> 
> Fixes: 461cd1b03e32 ("net: dsa: bcm_sf2: Register our slave MDIO bus")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Applied and queued up for -stable.
diff mbox series

Patch

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index affa5c6e135c..cc95adc5ab4b 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -480,7 +480,7 @@  static int bcm_sf2_mdio_register(struct dsa_switch *ds)
 	priv->slave_mii_bus->parent = ds->dev->parent;
 	priv->slave_mii_bus->phy_mask = ~priv->indir_phy_mask;
 
-	err = of_mdiobus_register(priv->slave_mii_bus, dn);
+	err = mdiobus_register(priv->slave_mii_bus);
 	if (err && dn)
 		of_node_put(dn);