@@ -1011,6 +1011,8 @@ static int dsa_tree_setup_ports(struct dsa_switch_tree *dst)
list_for_each_entry(dp, &dst->ports, list) {
if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) {
err = dsa_port_setup(dp);
+ if (err == -EPROBE_DEFER)
+ goto teardown;
if (err) {
err = dsa_port_reinit_as_unused(dp);
if (err)
@@ -1628,9 +1628,11 @@ static int dsa_port_phylink_register(struct dsa_port *dp)
if (err)
return err;
- err = phylink_of_phy_connect(dp->pl, port_dn, 0);
+ err = phylink_of_phy_connect_probe(dp->pl, port_dn, 0);
if (err && err != -ENODEV) {
- pr_err("could not attach to PHY: %d\n", err);
+ dev_err_probe(ds->dev, err,
+ "DSA/CPU port %d could not attach to PHY: %pe\n",
+ dp->index, ERR_PTR(err));
goto err_phy_connect;
}
@@ -2252,18 +2252,18 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
if (ds->ops->get_phy_flags)
phy_flags = ds->ops->get_phy_flags(ds, dp->index);
- ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
+ ret = phylink_of_phy_connect_probe(dp->pl, port_dn, phy_flags);
if (ret == -ENODEV && ds->slave_mii_bus) {
/* We could not connect to a designated PHY or SFP, so try to
* use the switch internal MDIO bus instead
*/
ret = dsa_slave_phy_connect(slave_dev, dp->index, phy_flags);
}
- if (ret) {
+ if (ret && ret != -EPROBE_DEFER)
netdev_err(slave_dev, "failed to connect to PHY: %pe\n",
ERR_PTR(ret));
+ if (ret)
phylink_destroy(dp->pl);
- }
return ret;
}
@@ -2386,12 +2386,12 @@ int dsa_slave_create(struct dsa_port *port)
netif_carrier_off(slave_dev);
ret = dsa_slave_phy_setup(slave_dev);
- if (ret) {
+ if (ret && ret != -EPROBE_DEFER)
netdev_err(slave_dev,
"error %d setting up PHY for tree %d, switch %d, port %d\n",
ret, ds->dst->index, ds->index, port->index);
+ if (ret)
goto out_gcells;
- }
rtnl_lock();
DSA is among the 3 drivers which call phylink.*phy_connect() during probe time (vs 11 doing so during ndo_open). So there is no guarantee that the PHY driver will have finished probing by the time we connect to it. Use the newly introduced phylink_of_phy_connect_probe() to wait for this to happen, and propagate the error code all the way to dsa_register_switch(), which switch drivers call from their own probe function. Notably, in dsa_tree_setup_ports() we treat errors on slave interface registration as "soft" and continue probing the ports that didn't fail. This is useful on systems which have riser cards with PHYs, and some of these cards can be missing. But this logic needs to be adapted, since -EPROBE_DEFER is an error we want to propagate regardless. Fixes: 25396f680dd6 ("net: phylink: introduce phylink_fwnode_phy_connect()") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> --- net/dsa/dsa2.c | 2 ++ net/dsa/port.c | 6 ++++-- net/dsa/slave.c | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-)