Skip to content

Commit 8c248cd

Browse files
Raju LakkarajuPaolo Abeni
authored andcommitted
net: lan743x: Support WOL at both the PHY and MAC appropriately
Prevent options not supported by the PHY from being requested to it by the MAC Whenever a WOL option is supported by both, the PHY is given priority since that usually leads to better power savings. Fixes: e9e13b6 ("lan743x: fix for potential NULL pointer dereference with bare card") Reviewed-by: Wojciech Drewek <[email protected]> Signed-off-by: Raju Lakkaraju <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 7725363 commit 8c248cd

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

drivers/net/ethernet/microchip/lan743x_ethtool.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,12 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev,
11271127
if (netdev->phydev)
11281128
phy_ethtool_get_wol(netdev->phydev, wol);
11291129

1130-
wol->supported |= WAKE_BCAST | WAKE_UCAST | WAKE_MCAST |
1131-
WAKE_MAGIC | WAKE_PHY | WAKE_ARP;
1130+
if (wol->supported != adapter->phy_wol_supported)
1131+
netif_warn(adapter, drv, adapter->netdev,
1132+
"PHY changed its supported WOL! old=%x, new=%x\n",
1133+
adapter->phy_wol_supported, wol->supported);
1134+
1135+
wol->supported |= MAC_SUPPORTED_WAKES;
11321136

11331137
if (adapter->is_pci11x1x)
11341138
wol->supported |= WAKE_MAGICSECURE;
@@ -1143,7 +1147,39 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
11431147
{
11441148
struct lan743x_adapter *adapter = netdev_priv(netdev);
11451149

1150+
/* WAKE_MAGICSEGURE is a modifier of and only valid together with
1151+
* WAKE_MAGIC
1152+
*/
1153+
if ((wol->wolopts & WAKE_MAGICSECURE) && !(wol->wolopts & WAKE_MAGIC))
1154+
return -EINVAL;
1155+
1156+
if (netdev->phydev) {
1157+
struct ethtool_wolinfo phy_wol;
1158+
int ret;
1159+
1160+
phy_wol.wolopts = wol->wolopts & adapter->phy_wol_supported;
1161+
1162+
/* If WAKE_MAGICSECURE was requested, filter out WAKE_MAGIC
1163+
* for PHYs that do not support WAKE_MAGICSECURE
1164+
*/
1165+
if (wol->wolopts & WAKE_MAGICSECURE &&
1166+
!(adapter->phy_wol_supported & WAKE_MAGICSECURE))
1167+
phy_wol.wolopts &= ~WAKE_MAGIC;
1168+
1169+
ret = phy_ethtool_set_wol(netdev->phydev, &phy_wol);
1170+
if (ret && (ret != -EOPNOTSUPP))
1171+
return ret;
1172+
1173+
if (ret == -EOPNOTSUPP)
1174+
adapter->phy_wolopts = 0;
1175+
else
1176+
adapter->phy_wolopts = phy_wol.wolopts;
1177+
} else {
1178+
adapter->phy_wolopts = 0;
1179+
}
1180+
11461181
adapter->wolopts = 0;
1182+
wol->wolopts &= ~adapter->phy_wolopts;
11471183
if (wol->wolopts & WAKE_UCAST)
11481184
adapter->wolopts |= WAKE_UCAST;
11491185
if (wol->wolopts & WAKE_MCAST)
@@ -1164,10 +1200,10 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
11641200
memset(adapter->sopass, 0, sizeof(u8) * SOPASS_MAX);
11651201
}
11661202

1203+
wol->wolopts = adapter->wolopts | adapter->phy_wolopts;
11671204
device_set_wakeup_enable(&adapter->pdev->dev, (bool)wol->wolopts);
11681205

1169-
return netdev->phydev ? phy_ethtool_set_wol(netdev->phydev, wol)
1170-
: -ENETDOWN;
1206+
return 0;
11711207
}
11721208
#endif /* CONFIG_PM */
11731209

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,6 +3118,17 @@ static int lan743x_netdev_open(struct net_device *netdev)
31183118
if (ret)
31193119
goto close_tx;
31203120
}
3121+
3122+
#ifdef CONFIG_PM
3123+
if (adapter->netdev->phydev) {
3124+
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
3125+
3126+
phy_ethtool_get_wol(netdev->phydev, &wol);
3127+
adapter->phy_wol_supported = wol.supported;
3128+
adapter->phy_wolopts = wol.wolopts;
3129+
}
3130+
#endif
3131+
31213132
return 0;
31223133

31233134
close_tx:
@@ -3587,10 +3598,9 @@ static void lan743x_pm_set_wol(struct lan743x_adapter *adapter)
35873598

35883599
pmtctl |= PMT_CTL_ETH_PHY_D3_COLD_OVR_ | PMT_CTL_ETH_PHY_D3_OVR_;
35893600

3590-
if (adapter->wolopts & WAKE_PHY) {
3591-
pmtctl |= PMT_CTL_ETH_PHY_EDPD_PLL_CTL_;
3601+
if (adapter->phy_wolopts)
35923602
pmtctl |= PMT_CTL_ETH_PHY_WAKE_EN_;
3593-
}
3603+
35943604
if (adapter->wolopts & WAKE_MAGIC) {
35953605
wucsr |= MAC_WUCSR_MPEN_;
35963606
macrx |= MAC_RX_RXEN_;
@@ -3686,7 +3696,7 @@ static int lan743x_pm_suspend(struct device *dev)
36863696
lan743x_csr_write(adapter, MAC_WUCSR2, 0);
36873697
lan743x_csr_write(adapter, MAC_WK_SRC, 0xFFFFFFFF);
36883698

3689-
if (adapter->wolopts)
3699+
if (adapter->wolopts || adapter->phy_wolopts)
36903700
lan743x_pm_set_wol(adapter);
36913701

36923702
if (adapter->is_pci11x1x) {

drivers/net/ethernet/microchip/lan743x_main.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,17 @@ enum lan743x_sgmii_lsd {
10421042
LINK_2500_SLAVE
10431043
};
10441044

1045+
#define MAC_SUPPORTED_WAKES (WAKE_BCAST | WAKE_UCAST | WAKE_MCAST | \
1046+
WAKE_MAGIC | WAKE_ARP)
10451047
struct lan743x_adapter {
10461048
struct net_device *netdev;
10471049
struct mii_bus *mdiobus;
10481050
int msg_enable;
10491051
#ifdef CONFIG_PM
10501052
u32 wolopts;
10511053
u8 sopass[SOPASS_MAX];
1054+
u32 phy_wolopts;
1055+
u32 phy_wol_supported;
10521056
#endif
10531057
struct pci_dev *pdev;
10541058
struct lan743x_csr csr;

0 commit comments

Comments
 (0)