Commit 8c248cd8 authored by Raju Lakkaraju's avatar Raju Lakkaraju Committed by Paolo Abeni

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: e9e13b6a ("lan743x: fix for potential NULL pointer dereference with bare card")
Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: default avatarRaju Lakkaraju <Raju.Lakkaraju@microchip.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 77253639
...@@ -1127,8 +1127,12 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev, ...@@ -1127,8 +1127,12 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev,
if (netdev->phydev) if (netdev->phydev)
phy_ethtool_get_wol(netdev->phydev, wol); phy_ethtool_get_wol(netdev->phydev, wol);
wol->supported |= WAKE_BCAST | WAKE_UCAST | WAKE_MCAST | if (wol->supported != adapter->phy_wol_supported)
WAKE_MAGIC | WAKE_PHY | WAKE_ARP; netif_warn(adapter, drv, adapter->netdev,
"PHY changed its supported WOL! old=%x, new=%x\n",
adapter->phy_wol_supported, wol->supported);
wol->supported |= MAC_SUPPORTED_WAKES;
if (adapter->is_pci11x1x) if (adapter->is_pci11x1x)
wol->supported |= WAKE_MAGICSECURE; wol->supported |= WAKE_MAGICSECURE;
...@@ -1143,7 +1147,39 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev, ...@@ -1143,7 +1147,39 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
{ {
struct lan743x_adapter *adapter = netdev_priv(netdev); struct lan743x_adapter *adapter = netdev_priv(netdev);
/* WAKE_MAGICSEGURE is a modifier of and only valid together with
* WAKE_MAGIC
*/
if ((wol->wolopts & WAKE_MAGICSECURE) && !(wol->wolopts & WAKE_MAGIC))
return -EINVAL;
if (netdev->phydev) {
struct ethtool_wolinfo phy_wol;
int ret;
phy_wol.wolopts = wol->wolopts & adapter->phy_wol_supported;
/* If WAKE_MAGICSECURE was requested, filter out WAKE_MAGIC
* for PHYs that do not support WAKE_MAGICSECURE
*/
if (wol->wolopts & WAKE_MAGICSECURE &&
!(adapter->phy_wol_supported & WAKE_MAGICSECURE))
phy_wol.wolopts &= ~WAKE_MAGIC;
ret = phy_ethtool_set_wol(netdev->phydev, &phy_wol);
if (ret && (ret != -EOPNOTSUPP))
return ret;
if (ret == -EOPNOTSUPP)
adapter->phy_wolopts = 0;
else
adapter->phy_wolopts = phy_wol.wolopts;
} else {
adapter->phy_wolopts = 0;
}
adapter->wolopts = 0; adapter->wolopts = 0;
wol->wolopts &= ~adapter->phy_wolopts;
if (wol->wolopts & WAKE_UCAST) if (wol->wolopts & WAKE_UCAST)
adapter->wolopts |= WAKE_UCAST; adapter->wolopts |= WAKE_UCAST;
if (wol->wolopts & WAKE_MCAST) if (wol->wolopts & WAKE_MCAST)
...@@ -1164,10 +1200,10 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev, ...@@ -1164,10 +1200,10 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
memset(adapter->sopass, 0, sizeof(u8) * SOPASS_MAX); memset(adapter->sopass, 0, sizeof(u8) * SOPASS_MAX);
} }
wol->wolopts = adapter->wolopts | adapter->phy_wolopts;
device_set_wakeup_enable(&adapter->pdev->dev, (bool)wol->wolopts); device_set_wakeup_enable(&adapter->pdev->dev, (bool)wol->wolopts);
return netdev->phydev ? phy_ethtool_set_wol(netdev->phydev, wol) return 0;
: -ENETDOWN;
} }
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
......
...@@ -3118,6 +3118,17 @@ static int lan743x_netdev_open(struct net_device *netdev) ...@@ -3118,6 +3118,17 @@ static int lan743x_netdev_open(struct net_device *netdev)
if (ret) if (ret)
goto close_tx; goto close_tx;
} }
#ifdef CONFIG_PM
if (adapter->netdev->phydev) {
struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
phy_ethtool_get_wol(netdev->phydev, &wol);
adapter->phy_wol_supported = wol.supported;
adapter->phy_wolopts = wol.wolopts;
}
#endif
return 0; return 0;
close_tx: close_tx:
...@@ -3587,10 +3598,9 @@ static void lan743x_pm_set_wol(struct lan743x_adapter *adapter) ...@@ -3587,10 +3598,9 @@ static void lan743x_pm_set_wol(struct lan743x_adapter *adapter)
pmtctl |= PMT_CTL_ETH_PHY_D3_COLD_OVR_ | PMT_CTL_ETH_PHY_D3_OVR_; pmtctl |= PMT_CTL_ETH_PHY_D3_COLD_OVR_ | PMT_CTL_ETH_PHY_D3_OVR_;
if (adapter->wolopts & WAKE_PHY) { if (adapter->phy_wolopts)
pmtctl |= PMT_CTL_ETH_PHY_EDPD_PLL_CTL_;
pmtctl |= PMT_CTL_ETH_PHY_WAKE_EN_; pmtctl |= PMT_CTL_ETH_PHY_WAKE_EN_;
}
if (adapter->wolopts & WAKE_MAGIC) { if (adapter->wolopts & WAKE_MAGIC) {
wucsr |= MAC_WUCSR_MPEN_; wucsr |= MAC_WUCSR_MPEN_;
macrx |= MAC_RX_RXEN_; macrx |= MAC_RX_RXEN_;
...@@ -3686,7 +3696,7 @@ static int lan743x_pm_suspend(struct device *dev) ...@@ -3686,7 +3696,7 @@ static int lan743x_pm_suspend(struct device *dev)
lan743x_csr_write(adapter, MAC_WUCSR2, 0); lan743x_csr_write(adapter, MAC_WUCSR2, 0);
lan743x_csr_write(adapter, MAC_WK_SRC, 0xFFFFFFFF); lan743x_csr_write(adapter, MAC_WK_SRC, 0xFFFFFFFF);
if (adapter->wolopts) if (adapter->wolopts || adapter->phy_wolopts)
lan743x_pm_set_wol(adapter); lan743x_pm_set_wol(adapter);
if (adapter->is_pci11x1x) { if (adapter->is_pci11x1x) {
......
...@@ -1042,6 +1042,8 @@ enum lan743x_sgmii_lsd { ...@@ -1042,6 +1042,8 @@ enum lan743x_sgmii_lsd {
LINK_2500_SLAVE LINK_2500_SLAVE
}; };
#define MAC_SUPPORTED_WAKES (WAKE_BCAST | WAKE_UCAST | WAKE_MCAST | \
WAKE_MAGIC | WAKE_ARP)
struct lan743x_adapter { struct lan743x_adapter {
struct net_device *netdev; struct net_device *netdev;
struct mii_bus *mdiobus; struct mii_bus *mdiobus;
...@@ -1049,6 +1051,8 @@ struct lan743x_adapter { ...@@ -1049,6 +1051,8 @@ struct lan743x_adapter {
#ifdef CONFIG_PM #ifdef CONFIG_PM
u32 wolopts; u32 wolopts;
u8 sopass[SOPASS_MAX]; u8 sopass[SOPASS_MAX];
u32 phy_wolopts;
u32 phy_wol_supported;
#endif #endif
struct pci_dev *pdev; struct pci_dev *pdev;
struct lan743x_csr csr; struct lan743x_csr csr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment