Skip to content

Commit ce88b5f

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 <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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 100efd5 commit ce88b5f

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

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) {
@@ -2993,7 +3014,7 @@ fec_enet_open(struct net_device *ndev)
29933014
* phy_reset_after_clk_enable() before because the PHY wasn't probed.
29943015
*/
29953016
if (reset_again)
2996-
phy_reset_after_clk_enable(ndev->phydev);
3017+
fec_enet_phy_reset_after_clk_enable(ndev);
29973018

29983019
if (fep->quirks & FEC_QUIRK_ERR006687)
29993020
imx6q_cpuidle_fec_irqs_used();

0 commit comments

Comments
 (0)