Skip to content

Commit 9e70485

Browse files
Marek Vasutgregkh
authored andcommitted
net: fec: Fix phy_device lookup for phy_reset_after_clk_enable()
[ Upstream commit 64a632d ] 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 <[email protected]> Cc: Christoph Niedermaier <[email protected]> Cc: David S. Miller <[email protected]> Cc: NXP Linux Team <[email protected]> Cc: Richard Leitner <[email protected]> Cc: Shawn Guo <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0b41975 commit 9e70485

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
@@ -1945,6 +1945,27 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
19451945
return ret;
19461946
}
19471947

1948+
static void fec_enet_phy_reset_after_clk_enable(struct net_device *ndev)
1949+
{
1950+
struct fec_enet_private *fep = netdev_priv(ndev);
1951+
struct phy_device *phy_dev = ndev->phydev;
1952+
1953+
if (phy_dev) {
1954+
phy_reset_after_clk_enable(phy_dev);
1955+
} else if (fep->phy_node) {
1956+
/*
1957+
* If the PHY still is not bound to the MAC, but there is
1958+
* OF PHY node and a matching PHY device instance already,
1959+
* use the OF PHY node to obtain the PHY device instance,
1960+
* and then use that PHY device instance when triggering
1961+
* the PHY reset.
1962+
*/
1963+
phy_dev = of_phy_find_device(fep->phy_node);
1964+
phy_reset_after_clk_enable(phy_dev);
1965+
put_device(&phy_dev->mdio.dev);
1966+
}
1967+
}
1968+
19481969
static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
19491970
{
19501971
struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1971,7 +1992,7 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
19711992
if (ret)
19721993
goto failed_clk_ref;
19731994

1974-
phy_reset_after_clk_enable(ndev->phydev);
1995+
fec_enet_phy_reset_after_clk_enable(ndev);
19751996
} else {
19761997
clk_disable_unprepare(fep->clk_enet_out);
19771998
if (fep->clk_ptp) {
@@ -2991,7 +3012,7 @@ fec_enet_open(struct net_device *ndev)
29913012
* phy_reset_after_clk_enable() before because the PHY wasn't probed.
29923013
*/
29933014
if (reset_again)
2994-
phy_reset_after_clk_enable(ndev->phydev);
3015+
fec_enet_phy_reset_after_clk_enable(ndev);
29953016

29963017
if (fep->quirks & FEC_QUIRK_ERR006687)
29973018
imx6q_cpuidle_fec_irqs_used();

0 commit comments

Comments
 (0)