[PATCH] net: dsa: ocelot: suppress PHY device scanning on the internal MDIO bus

From: Vladimir Oltean
Date: Tue Jul 19 2022 - 13:15:52 EST


This bus contains Lynx PCS devices, and if the lynx-pcs driver ever
decided to call mdio_device_register(), it would fail due to
mdiobus_scan() having created a dummy phydev for the same address
(the PCS responds to standard clause 22 PHY ID registers and can
therefore by autodetected by phylib which thinks it's a PHY).

On the Seville driver, things are a bit more complicated, since bus
creation is handled by mscc_miim_setup() and that is shared with the
dedicated mscc-miim driver. Suppress PHY scanning only for the Seville
internal MDIO bus rather than for the whole mscc-miim driver, since we
know that on NXP T1040, this bus only contains Lynx PCS devices.

Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
---
drivers/net/dsa/ocelot/felix_vsc9959.c | 4 ++++
drivers/net/dsa/ocelot/seville_vsc9953.c | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 927225e51f05..1ff71f1df316 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1062,6 +1062,10 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
bus->read = enetc_mdio_read;
bus->write = enetc_mdio_write;
bus->parent = dev;
+ /* Suppress PHY device creation in mdiobus_scan(),
+ * we have Lynx PCSs
+ */
+ bus->phy_mask = ~0;
mdio_priv = bus->priv;
mdio_priv->hw = hw;
/* This gets added to imdio_regs, which already maps addresses
diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c
index 9006dec85ef0..9f400867fce3 100644
--- a/drivers/net/dsa/ocelot/seville_vsc9953.c
+++ b/drivers/net/dsa/ocelot/seville_vsc9953.c
@@ -1018,12 +1018,16 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot)
rc = mscc_miim_setup(dev, &bus, "VSC9953 internal MDIO bus",
ocelot->targets[GCB],
ocelot->map[GCB][GCB_MIIM_MII_STATUS & REG_MASK]);
-
if (rc) {
dev_err(dev, "failed to setup MDIO bus\n");
return rc;
}

+ /* Suppress PHY device creation in mdiobus_scan(),
+ * we have Lynx PCSs
+ */
+ bus->phy_mask = ~0;
+
/* Needed in order to initialize the bus mutex lock */
rc = devm_of_mdiobus_register(dev, bus, NULL);
if (rc < 0) {
--
2.34.1

and then things start working (including traffic).

> + if (err) {
> + mdio_device_free(mdio);
> + return ERR_PTR(err);
> + }
> +
> + pcs = pcs_get_by_provider(&mdio->dev);
> + mdio_device_free(mdio);
> + return pcs;
> +}
> +EXPORT_SYMBOL(lynx_pcs_create_on_bus);
> +
> void lynx_pcs_destroy(struct phylink_pcs *pcs)
> {
> pcs_put(pcs);
> diff --git a/include/linux/pcs-lynx.h b/include/linux/pcs-lynx.h
> index 5712cc2ce775..1c14342bb8c4 100644
> --- a/include/linux/pcs-lynx.h
> +++ b/include/linux/pcs-lynx.h
> @@ -12,6 +12,7 @@
> struct mdio_device *lynx_get_mdio_device(struct phylink_pcs *pcs);
>
> struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio);
> +struct phylink_pcs *lynx_pcs_create_on_bus(struct mii_bus *bus, int addr);
>
> void lynx_pcs_destroy(struct phylink_pcs *pcs);
>
> --
> 2.35.1.1320.gc452695387.dirty
>