netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] net: fec: Fix phy_device lookup for phy_reset_after_clk_enable()
@ 2020-10-10  9:10 Marek Vasut
  2020-10-12 21:23 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Vasut @ 2020-10-10  9:10 UTC (permalink / raw)
  To: netdev
  Cc: Marek Vasut, Christoph Niedermaier, David S . Miller,
	NXP Linux Team, Richard Leitner, Shawn Guo

The phy_reset_after_clk_enable() is always called with ndev->phydev,
however that pointer may be NULL even though the PHY device instance
already exists and is sufficient to perform the PHY reset.

This condition happens in fec_open(), where the clock must be enabled
first, then the PHY must be reset, and then the PHY IDs can be read
out of the PHY.

If the PHY still is not bound to the MAC, but there is OF PHY node
and a matching PHY device instance already, use the OF PHY node to
obtain the PHY device instance, and then use that PHY device instance
when triggering the PHY reset.

Fixes: 1b0a83ac04e3 ("net: fec: add phy_reset_after_clk_enable() support")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Richard Leitner <richard.leitner@skidata.com>
Cc: Shawn Guo <shawnguo@kernel.org>
---
V2: - put_device() the phy_dev reference from of_phy_find_device()
    - Add additional explanation into the commit message
---
 drivers/net/ethernet/freescale/fec_main.c | 25 +++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 2d5433301843..8f7eca1e7716 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1912,6 +1912,27 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	return ret;
 }
 
+static void fec_enet_phy_reset_after_clk_enable(struct net_device *ndev)
+{
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	struct phy_device *phy_dev = ndev->phydev;
+
+	if (phy_dev) {
+		phy_reset_after_clk_enable(phy_dev);
+	} else if (fep->phy_node) {
+		/*
+		 * If the PHY still is not bound to the MAC, but there is
+		 * OF PHY node and a matching PHY device instance already,
+		 * use the OF PHY node to obtain the PHY device instance,
+		 * and then use that PHY device instance when triggering
+		 * the PHY reset.
+		 */
+		phy_dev = of_phy_find_device(fep->phy_node);
+		phy_reset_after_clk_enable(phy_dev);
+		put_device(&phy_dev->mdio.dev);
+	}
+}
+
 static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
 {
 	struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1938,7 +1959,7 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
 		if (ret)
 			goto failed_clk_ref;
 
-		phy_reset_after_clk_enable(ndev->phydev);
+		fec_enet_phy_reset_after_clk_enable(ndev);
 	} else {
 		clk_disable_unprepare(fep->clk_enet_out);
 		if (fep->clk_ptp) {
@@ -2987,7 +3008,7 @@ fec_enet_open(struct net_device *ndev)
 	 * phy_reset_after_clk_enable() before because the PHY wasn't probed.
 	 */
 	if (reset_again)
-		phy_reset_after_clk_enable(ndev->phydev);
+		fec_enet_phy_reset_after_clk_enable(ndev);
 
 	/* Probe and connect to PHY when open the interface */
 	ret = fec_enet_mii_probe(ndev);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] net: fec: Fix phy_device lookup for phy_reset_after_clk_enable()
  2020-10-10  9:10 [PATCH V2] net: fec: Fix phy_device lookup for phy_reset_after_clk_enable() Marek Vasut
@ 2020-10-12 21:23 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2020-10-12 21:23 UTC (permalink / raw)
  To: Marek Vasut
  Cc: netdev, Christoph Niedermaier, David S . Miller, NXP Linux Team,
	Richard Leitner, Shawn Guo

On Sat, 10 Oct 2020 11:10:00 +0200 Marek Vasut wrote:
> The phy_reset_after_clk_enable() is always called with ndev->phydev,
> however that pointer may be NULL even though the PHY device instance
> already exists and is sufficient to perform the PHY reset.
> 
> This condition happens in fec_open(), where the clock must be enabled
> first, then the PHY must be reset, and then the PHY IDs can be read
> out of the PHY.
> 
> If the PHY still is not bound to the MAC, but there is OF PHY node
> and a matching PHY device instance already, use the OF PHY node to
> obtain the PHY device instance, and then use that PHY device instance
> when triggering the PHY reset.
> 
> Fixes: 1b0a83ac04e3 ("net: fec: add phy_reset_after_clk_enable() support")
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: NXP Linux Team <linux-imx@nxp.com>
> Cc: Richard Leitner <richard.leitner@skidata.com>
> Cc: Shawn Guo <shawnguo@kernel.org>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-12 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10  9:10 [PATCH V2] net: fec: Fix phy_device lookup for phy_reset_after_clk_enable() Marek Vasut
2020-10-12 21:23 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).