Commit cd4ba3ec authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: lantiq_gswip: use devres for internal MDIO bus, not ds->user_mii_bus

This driver does not need any of the functionalities that make
ds->user_mii_bus special. Those use cases are listed here:
https://lore.kernel.org/netdev/20231221174746.hylsmr3f7g5byrsi@skbuf/

It just makes use of ds->user_mii_bus only as storage for its own MDIO
bus, which otherwise has no connection to the framework. This is because:

- the gswip driver only probes on OF: it fails if of_device_get_match_data()
  returns NULL

- when the child OF node of the MDIO bus is absent, no MDIO bus is
  registered at all, not even by the DSA framework. In order for that to
  have happened, the gswip driver would have needed to provide
  ->phy_read() and ->phy_write() in struct dsa_switch_ops, which it does
  not.

We can break the connection between the gswip driver and the DSA
framework and still preserve the same functionality.

Since commit 3b73a7b8 ("net: mdio_bus: add refcounting for fwnodes
to mdiobus"), MDIO buses take ownership of the OF node handled to them,
and release it on their own. The gswip driver no longer needs to do
this.

Combine that with devres, and we no longer need to keep track of
anything for teardown purposes.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarAlvin Šipraga <alsi@bang-olufsen.dk>
Reviewed-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: default avatarLuiz Angelo Daros de Luca <luizluca@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fc74b32b
...@@ -505,26 +505,34 @@ static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg) ...@@ -505,26 +505,34 @@ static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg)
return gswip_mdio_r(priv, GSWIP_MDIO_READ); return gswip_mdio_r(priv, GSWIP_MDIO_READ);
} }
static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np) static int gswip_mdio(struct gswip_priv *priv)
{ {
struct dsa_switch *ds = priv->ds; struct device_node *mdio_np, *switch_np = priv->dev->of_node;
struct device *dev = priv->dev;
struct mii_bus *bus;
int err; int err;
ds->user_mii_bus = mdiobus_alloc(); mdio_np = of_get_compatible_child(switch_np, "lantiq,xrx200-mdio");
if (!ds->user_mii_bus) if (!mdio_np)
return -ENOMEM; return 0;
bus = devm_mdiobus_alloc(dev);
if (!bus) {
err = -ENOMEM;
goto out_put_node;
}
ds->user_mii_bus->priv = priv; bus->priv = priv;
ds->user_mii_bus->read = gswip_mdio_rd; bus->read = gswip_mdio_rd;
ds->user_mii_bus->write = gswip_mdio_wr; bus->write = gswip_mdio_wr;
ds->user_mii_bus->name = "lantiq,xrx200-mdio"; bus->name = "lantiq,xrx200-mdio";
snprintf(ds->user_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii", snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(priv->dev));
dev_name(priv->dev)); bus->parent = priv->dev;
ds->user_mii_bus->parent = priv->dev;
err = of_mdiobus_register(ds->user_mii_bus, mdio_np); err = devm_of_mdiobus_register(dev, bus, mdio_np);
if (err)
mdiobus_free(ds->user_mii_bus); out_put_node:
of_node_put(mdio_np);
return err; return err;
} }
...@@ -2093,9 +2101,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv, ...@@ -2093,9 +2101,9 @@ static int gswip_gphy_fw_list(struct gswip_priv *priv,
static int gswip_probe(struct platform_device *pdev) static int gswip_probe(struct platform_device *pdev)
{ {
struct gswip_priv *priv; struct device_node *np, *gphy_fw_np;
struct device_node *np, *mdio_np, *gphy_fw_np;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gswip_priv *priv;
int err; int err;
int i; int i;
u32 version; u32 version;
...@@ -2162,19 +2170,16 @@ static int gswip_probe(struct platform_device *pdev) ...@@ -2162,19 +2170,16 @@ static int gswip_probe(struct platform_device *pdev)
} }
/* bring up the mdio bus */ /* bring up the mdio bus */
mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio"); err = gswip_mdio(priv);
if (mdio_np) {
err = gswip_mdio(priv, mdio_np);
if (err) { if (err) {
dev_err(dev, "mdio probe failed\n"); dev_err(dev, "mdio probe failed\n");
goto put_mdio_node; goto gphy_fw_remove;
}
} }
err = dsa_register_switch(priv->ds); err = dsa_register_switch(priv->ds);
if (err) { if (err) {
dev_err(dev, "dsa switch register failed: %i\n", err); dev_err(dev, "dsa switch register failed: %i\n", err);
goto mdio_bus; goto gphy_fw_remove;
} }
if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) { if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
dev_err(dev, "wrong CPU port defined, HW only supports port: %i", dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
...@@ -2193,13 +2198,7 @@ static int gswip_probe(struct platform_device *pdev) ...@@ -2193,13 +2198,7 @@ static int gswip_probe(struct platform_device *pdev)
disable_switch: disable_switch:
gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
dsa_unregister_switch(priv->ds); dsa_unregister_switch(priv->ds);
mdio_bus: gphy_fw_remove:
if (mdio_np) {
mdiobus_unregister(priv->ds->user_mii_bus);
mdiobus_free(priv->ds->user_mii_bus);
}
put_mdio_node:
of_node_put(mdio_np);
for (i = 0; i < priv->num_gphy_fw; i++) for (i = 0; i < priv->num_gphy_fw; i++)
gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
return err; return err;
...@@ -2218,12 +2217,6 @@ static void gswip_remove(struct platform_device *pdev) ...@@ -2218,12 +2217,6 @@ static void gswip_remove(struct platform_device *pdev)
dsa_unregister_switch(priv->ds); dsa_unregister_switch(priv->ds);
if (priv->ds->user_mii_bus) {
mdiobus_unregister(priv->ds->user_mii_bus);
of_node_put(priv->ds->user_mii_bus->dev.of_node);
mdiobus_free(priv->ds->user_mii_bus);
}
for (i = 0; i < priv->num_gphy_fw; i++) for (i = 0; i < priv->num_gphy_fw; i++)
gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment