public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org
Cc: "Jakub Kicinski" <kuba@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Eric Dumazet" <edumazet@google.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Saravana Kannan" <saravanak@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"John Stultz" <jstultz@google.com>,
	"Alvin Šipraga" <alsi@bang-olufsen.dk>,
	"Russell King" <rmk+kernel@armlinux.org.uk>,
	"Heiner Kallweit" <hkallweit1@gmail.com>
Subject: [RFC PATCH net 2/2] net: dsa: wait for PHY to defer probe
Date: Sat, 14 May 2022 02:36:40 +0300	[thread overview]
Message-ID: <20220513233640.2518337-3-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20220513233640.2518337-1-vladimir.oltean@nxp.com>

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(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index cf933225df32..3a2983a1a7dd 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -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)
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 075a8db536c6..8a2fc99ca0ad 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -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;
 	}
 
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 5ee0aced9410..a5407e717c68 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -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();
 
-- 
2.25.1


  parent reply	other threads:[~2022-05-14  1:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 23:36 [RFC PATCH net 0/2] Make phylink and DSA wait for PHY driver that defers probe Vladimir Oltean
2022-05-13 23:36 ` [RFC PATCH net 1/2] net: phylink: allow PHY driver to defer probe when connecting via OF node Vladimir Oltean
2022-05-13 23:36 ` Vladimir Oltean [this message]
2022-05-14  0:23 ` [RFC PATCH net 0/2] Make phylink and DSA wait for PHY driver that defers probe Andrew Lunn
2022-05-19 14:59   ` Vladimir Oltean
2022-05-19 15:15     ` Russell King (Oracle)
2022-05-19 15:25       ` Vladimir Oltean
2022-05-19 15:32     ` Andrew Lunn
2022-05-19 15:38       ` Vladimir Oltean
2022-05-14  0:39 ` Saravana Kannan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220513233640.2518337-3-vladimir.oltean@nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkallweit1@gmail.com \
    --cc=jstultz@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=rafael@kernel.org \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=saravanak@google.com \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox