Skip to content

Commit 64a632d

Browse files
Marek Vasutkuba-moo
authored andcommitted
net: fec: Fix phy_device lookup for phy_reset_after_clk_enable()
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: 1b0a83a ("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> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b2b8a92 commit 64a632d

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,27 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
19121912
return ret;
19131913
}
19141914

1915+
static void fec_enet_phy_reset_after_clk_enable(struct net_device *ndev)
1916+
{
1917+
struct fec_enet_private *fep = netdev_priv(ndev);
1918+
struct phy_device *phy_dev = ndev->phydev;
1919+
1920+
if (phy_dev) {
1921+
phy_reset_after_clk_enable(phy_dev);
1922+
} else if (fep->phy_node) {
1923+
/*
1924+
* If the PHY still is not bound to the MAC, but there is
1925+
* OF PHY node and a matching PHY device instance already,
1926+
* use the OF PHY node to obtain the PHY device instance,
1927+
* and then use that PHY device instance when triggering
1928+
* the PHY reset.
1929+
*/
1930+
phy_dev = of_phy_find_device(fep->phy_node);
1931+
phy_reset_after_clk_enable(phy_dev);
1932+
put_device(&phy_dev->mdio.dev);
1933+
}
1934+
}
1935+
19151936
static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
19161937
{
19171938
struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1938,7 +1959,7 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
19381959
if (ret)
19391960
goto failed_clk_ref;
19401961

1941-
phy_reset_after_clk_enable(ndev->phydev);
1962+
fec_enet_phy_reset_after_clk_enable(ndev);
19421963
} else {
19431964
clk_disable_unprepare(fep->clk_enet_out);
19441965
if (fep->clk_ptp) {
@@ -2988,7 +3009,7 @@ fec_enet_open(struct net_device *ndev)
29883009
* phy_reset_after_clk_enable() before because the PHY wasn't probed.
29893010
*/
29903011
if (reset_again)
2991-
phy_reset_after_clk_enable(ndev->phydev);
3012+
fec_enet_phy_reset_after_clk_enable(ndev);
29923013

29933014
/* Probe and connect to PHY when open the interface */
29943015
ret = fec_enet_mii_probe(ndev);

0 commit comments

Comments
 (0)