Skip to content

Commit 38e1467

Browse files
committed
Merge branch 'net-stmmac-eee-and-wol-cleanups'
Russell King says: ==================== net: stmmac: EEE and WoL cleanups This series contains a series of cleanup patches for the EEE and WoL code in stmmac, prompted by issues raised during the last three weeks. ==================== Link: https://patch.msgid.link/aJ8avIp8DBAckgMc@shell.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 5883cb3 + 5e5b39a commit 38e1467

File tree

5 files changed

+25
-43
lines changed

5 files changed

+25
-43
lines changed

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ struct mac_device_info {
602602
unsigned int mcast_bits_log2;
603603
unsigned int rx_csum;
604604
unsigned int pcs;
605-
unsigned int pmt;
606605
unsigned int ps;
607606
unsigned int xlgmac;
608607
unsigned int num_vlan;

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ struct stmmac_priv {
289289
u32 msg_enable;
290290
int wolopts;
291291
int wol_irq;
292-
bool wol_irq_disabled;
293292
int clk_csr;
294293
struct timer_list eee_ctrl_timer;
295294
int lpi_irq;
@@ -376,6 +375,16 @@ enum stmmac_state {
376375

377376
extern const struct dev_pm_ops stmmac_simple_pm_ops;
378377

378+
static inline bool stmmac_wol_enabled_mac(struct stmmac_priv *priv)
379+
{
380+
return priv->plat->pmt && device_may_wakeup(priv->device);
381+
}
382+
383+
static inline bool stmmac_wol_enabled_phy(struct stmmac_priv *priv)
384+
{
385+
return !priv->plat->pmt && device_may_wakeup(priv->device);
386+
}
387+
379388
int stmmac_mdio_unregister(struct net_device *ndev);
380389
int stmmac_mdio_register(struct net_device *ndev);
381390
int stmmac_mdio_reset(struct mii_bus *mii);

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
803803
static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
804804
{
805805
struct stmmac_priv *priv = netdev_priv(dev);
806-
u32 support = WAKE_MAGIC | WAKE_UCAST;
807806

808807
if (!device_can_wakeup(priv->device))
809808
return -EOPNOTSUPP;
@@ -816,29 +815,7 @@ static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
816815
return ret;
817816
}
818817

819-
/* By default almost all GMAC devices support the WoL via
820-
* magic frame but we can disable it if the HW capability
821-
* register shows no support for pmt_magic_frame. */
822-
if ((priv->hw_cap_support) && (!priv->dma_cap.pmt_magic_frame))
823-
wol->wolopts &= ~WAKE_MAGIC;
824-
825-
if (wol->wolopts & ~support)
826-
return -EINVAL;
827-
828-
if (wol->wolopts) {
829-
pr_info("stmmac: wakeup enable\n");
830-
device_set_wakeup_enable(priv->device, 1);
831-
/* Avoid unbalanced enable_irq_wake calls */
832-
if (priv->wol_irq_disabled)
833-
enable_irq_wake(priv->wol_irq);
834-
priv->wol_irq_disabled = false;
835-
} else {
836-
device_set_wakeup_enable(priv->device, 0);
837-
/* Avoid unbalanced disable_irq_wake calls */
838-
if (!priv->wol_irq_disabled)
839-
disable_irq_wake(priv->wol_irq);
840-
priv->wol_irq_disabled = true;
841-
}
818+
device_set_wakeup_enable(priv->device, !!wol->wolopts);
842819

843820
mutex_lock(&priv->lock);
844821
priv->wolopts = wol->wolopts;
@@ -852,9 +829,6 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev,
852829
{
853830
struct stmmac_priv *priv = netdev_priv(dev);
854831

855-
if (!priv->dma_cap.eee)
856-
return -EOPNOTSUPP;
857-
858832
return phylink_ethtool_get_eee(priv->phylink, edata);
859833
}
860834

@@ -863,9 +837,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
863837
{
864838
struct stmmac_priv *priv = netdev_priv(dev);
865839

866-
if (!priv->dma_cap.eee)
867-
return -EOPNOTSUPP;
868-
869840
return phylink_ethtool_set_eee(priv->phylink, edata);
870841
}
871842

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/dma-mapping.h>
3030
#include <linux/slab.h>
3131
#include <linux/pm_runtime.h>
32+
#include <linux/pm_wakeirq.h>
3233
#include <linux/prefetch.h>
3334
#include <linux/pinctrl/consumer.h>
3435
#ifdef CONFIG_DEBUG_FS
@@ -3724,7 +3725,6 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev)
37243725
/* Request the Wake IRQ in case of another line
37253726
* is used for WoL
37263727
*/
3727-
priv->wol_irq_disabled = true;
37283728
if (priv->wol_irq > 0 && priv->wol_irq != dev->irq) {
37293729
int_name = priv->int_name_wol;
37303730
sprintf(int_name, "%s:%s", dev->name, "wol");
@@ -3885,7 +3885,6 @@ static int stmmac_request_irq_single(struct net_device *dev)
38853885
/* Request the Wake IRQ in case of another line
38863886
* is used for WoL
38873887
*/
3888-
priv->wol_irq_disabled = true;
38893888
if (priv->wol_irq > 0 && priv->wol_irq != dev->irq) {
38903889
ret = request_irq(priv->wol_irq, stmmac_interrupt,
38913890
IRQF_SHARED, dev->name, dev);
@@ -4139,8 +4138,13 @@ static int stmmac_release(struct net_device *dev)
41394138
struct stmmac_priv *priv = netdev_priv(dev);
41404139
u32 chan;
41414140

4141+
/* If the PHY or MAC has WoL enabled, then the PHY will not be
4142+
* suspended when phylink_stop() is called below. Set the PHY
4143+
* to its slowest speed to save power.
4144+
*/
41424145
if (device_may_wakeup(priv->device))
41434146
phylink_speed_down(priv->phylink, false);
4147+
41444148
/* Stop and disconnect the PHY */
41454149
phylink_stop(priv->phylink);
41464150
phylink_disconnect_phy(priv->phylink);
@@ -7240,7 +7244,6 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
72407244
priv->plat->enh_desc = priv->dma_cap.enh_desc;
72417245
priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up &&
72427246
!(priv->plat->flags & STMMAC_FLAG_USE_PHY_WOL);
7243-
priv->hw->pmt = priv->plat->pmt;
72447247
if (priv->dma_cap.hash_tb_sz) {
72457248
priv->hw->multicast_filter_bins =
72467249
(BIT(priv->dma_cap.hash_tb_sz) << 5);
@@ -7278,6 +7281,7 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
72787281
if (priv->plat->pmt) {
72797282
dev_info(priv->device, "Wake-Up On Lan supported\n");
72807283
device_set_wakeup_capable(priv->device, 1);
7284+
devm_pm_set_wake_irq(priv->device, priv->wol_irq);
72817285
}
72827286

72837287
if (priv->dma_cap.tsoen)
@@ -7858,7 +7862,7 @@ int stmmac_suspend(struct device *dev)
78587862
priv->plat->serdes_powerdown(ndev, priv->plat->bsp_priv);
78597863

78607864
/* Enable Power down mode by programming the PMT regs */
7861-
if (device_may_wakeup(priv->device) && priv->plat->pmt) {
7865+
if (stmmac_wol_enabled_mac(priv)) {
78627866
stmmac_pmt(priv, priv->hw, priv->wolopts);
78637867
priv->irq_wake = 1;
78647868
} else {
@@ -7869,11 +7873,10 @@ int stmmac_suspend(struct device *dev)
78697873
mutex_unlock(&priv->lock);
78707874

78717875
rtnl_lock();
7872-
if (device_may_wakeup(priv->device) && !priv->plat->pmt)
7876+
if (stmmac_wol_enabled_phy(priv))
78737877
phylink_speed_down(priv->phylink, false);
78747878

7875-
phylink_suspend(priv->phylink,
7876-
device_may_wakeup(priv->device) && priv->plat->pmt);
7879+
phylink_suspend(priv->phylink, stmmac_wol_enabled_mac(priv));
78777880
rtnl_unlock();
78787881

78797882
if (stmmac_fpe_supported(priv))
@@ -7949,7 +7952,7 @@ int stmmac_resume(struct device *dev)
79497952
* this bit because it can generate problems while resuming
79507953
* from another devices (e.g. serial console).
79517954
*/
7952-
if (device_may_wakeup(priv->device) && priv->plat->pmt) {
7955+
if (stmmac_wol_enabled_mac(priv)) {
79537956
mutex_lock(&priv->lock);
79547957
stmmac_pmt(priv, priv->hw, 0);
79557958
mutex_unlock(&priv->lock);
@@ -8009,7 +8012,7 @@ int stmmac_resume(struct device *dev)
80098012
* workqueue thread, which will race with initialisation.
80108013
*/
80118014
phylink_resume(priv->phylink);
8012-
if (device_may_wakeup(priv->device) && !priv->plat->pmt)
8015+
if (stmmac_wol_enabled_phy(priv))
80138016
phylink_speed_up(priv->phylink);
80148017

80158018
rtnl_unlock();

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ static int __maybe_unused stmmac_pltfr_noirq_suspend(struct device *dev)
934934
if (!netif_running(ndev))
935935
return 0;
936936

937-
if (!device_may_wakeup(priv->device) || !priv->plat->pmt) {
937+
if (!stmmac_wol_enabled_mac(priv)) {
938938
/* Disable clock in case of PWM is off */
939939
clk_disable_unprepare(priv->plat->clk_ptp_ref);
940940

@@ -955,7 +955,7 @@ static int __maybe_unused stmmac_pltfr_noirq_resume(struct device *dev)
955955
if (!netif_running(ndev))
956956
return 0;
957957

958-
if (!device_may_wakeup(priv->device) || !priv->plat->pmt) {
958+
if (!stmmac_wol_enabled_mac(priv)) {
959959
/* enable the clk previously disabled */
960960
ret = pm_runtime_force_resume(dev);
961961
if (ret)

0 commit comments

Comments
 (0)