Skip to content

Commit e1f5bb1

Browse files
ffainellikuba-moo
authored andcommitted
net: bcmasp: Add support for PHY-based Wake-on-LAN
If available, interrogate the PHY to find out whether we can use it for Wake-on-LAN. This can be a more power efficient way of implementing that feature, especially when the MAC is powered off in low power states. Signed-off-by: Florian Fainelli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e5b670e commit e1f5bb1

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,30 @@ static void bcmasp_set_msglevel(struct net_device *dev, u32 level)
163163
static void bcmasp_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
164164
{
165165
struct bcmasp_intf *intf = netdev_priv(dev);
166+
struct bcmasp_priv *priv = intf->parent;
167+
struct device *kdev = &priv->pdev->dev;
168+
u32 phy_wolopts = 0;
169+
170+
if (dev->phydev) {
171+
phy_ethtool_get_wol(dev->phydev, wol);
172+
phy_wolopts = wol->wolopts;
173+
}
174+
175+
/* MAC is not wake-up capable, return what the PHY does */
176+
if (!device_can_wakeup(kdev))
177+
return;
178+
179+
/* Overlay MAC capabilities with that of the PHY queried before */
180+
wol->supported |= BCMASP_SUPPORTED_WAKE;
181+
wol->wolopts |= intf->wolopts;
182+
183+
/* Return the PHY configured magic password */
184+
if (phy_wolopts & WAKE_MAGICSECURE)
185+
return;
166186

167-
wol->supported = BCMASP_SUPPORTED_WAKE;
168-
wol->wolopts = intf->wolopts;
169187
memset(wol->sopass, 0, sizeof(wol->sopass));
170188

189+
/* Otherwise the MAC one */
171190
if (wol->wolopts & WAKE_MAGICSECURE)
172191
memcpy(wol->sopass, intf->sopass, sizeof(intf->sopass));
173192
}
@@ -177,10 +196,21 @@ static int bcmasp_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
177196
struct bcmasp_intf *intf = netdev_priv(dev);
178197
struct bcmasp_priv *priv = intf->parent;
179198
struct device *kdev = &priv->pdev->dev;
199+
int ret = 0;
200+
201+
/* Try Wake-on-LAN from the PHY first */
202+
if (dev->phydev) {
203+
ret = phy_ethtool_set_wol(dev->phydev, wol);
204+
if (ret != -EOPNOTSUPP && wol->wolopts)
205+
return ret;
206+
}
180207

181208
if (!device_can_wakeup(kdev))
182209
return -EOPNOTSUPP;
183210

211+
if (wol->wolopts & ~BCMASP_SUPPORTED_WAKE)
212+
return -EINVAL;
213+
184214
/* Interface Specific */
185215
intf->wolopts = wol->wolopts;
186216
if (intf->wolopts & WAKE_MAGICSECURE)

0 commit comments

Comments
 (0)