[PATCH net] net: phy: reconfigure PHY WOL in resume if WOL option still enabled

From: mohammad . athari . ismail
Date: Wed Jul 07 2021 - 20:44:03 EST


From: Mohammad Athari Bin Ismail <mohammad.athari.ismail@xxxxxxxxx>

When the PHY wakes up from suspend through WOL event, there is a need to
reconfigure the WOL if the WOL option still enabled. The main operation
is to clear the WOL event status. So that, subsequent WOL event can be
triggered properly.

This fix is needed especially for the PHY that operates in PHY_POLL mode
where there is no handler (such as interrupt handler) available to clear
the WOL event status.

Fixes: 611d779af7ca ("net: phy: fix MDIO bus PM PHY resuming")
Signed-off-by: Mohammad Athari Bin Ismail <mohammad.athari.ismail@xxxxxxxxx>
---
drivers/net/phy/phy_device.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 5d5f9a9ee768..d68703ce03b1 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -295,6 +295,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct device *dev)

static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
{
+ struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
struct phy_device *phydev = to_phy_device(dev);
int ret;

@@ -314,6 +315,13 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
if (ret < 0)
return ret;
no_resume:
+ /* If the PHY has WOL option still enabled, reconfigure the WOL mainly
+ * to clear the WOL event status.
+ */
+ phy_ethtool_get_wol(phydev, &wol);
+ if (wol.wolopts)
+ phy_ethtool_set_wol(phydev, &wol);
+
if (phydev->attached_dev && phydev->adjust_link)
phy_start_machine(phydev);

--
2.17.1