linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling
@ 2020-07-10 12:46 nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 1/5] net: macb: fix wakeup test in runtime suspend/resume routines nicolas.ferre
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre

From: Nicolas Ferre <nicolas.ferre@microchip.com>

Hi,
Here is a split series to fix WoL magic-packet on the current macb driver. Only
fixes in this one based on current net/master.

Best regards,
  Nicolas

Changes in v5:
- Addressed the error code returned by phylink_ethtool_set_wol() as suggested
  by Russell.
  If PHY handles WoL, MAC doesn't stay in the way.
- Removed Florian's tag on 3/5 because of the above changes.
- Correct the "Fixes" tag on 1/5.

Changes in v4:
- Pure bug fix series for 'net'. GEM addition and MACB update removed: will be
  sent later.

Changes in v3:
- Revert some of the v2 changes done in macb_resume(). Now the resume function
  supports in-depth re-configuration of the controller in order to deal with
  deeper sleep states. Basically as it was before changes introduced by this
  series
- Tested for non-regression with our deeper Power Management mode which cuts
  power to the controller completely

Changes in v2:
- Add patch 4/7 ("net: macb: fix macb_suspend() by removing call to netif_carrier_off()")
  needed for keeping phy state consistent
- Add patch 5/7 ("net: macb: fix call to pm_runtime in the suspend/resume functions") that prevent
  putting the macb in runtime pm suspend mode when WoL is used
- Collect review tags on 3 first patches from Florian: Thanks!
- Review of macb_resume() function
- Addition of pm_wakeup_event() in both MACB and GEM WoL IRQ handlers


Nicolas Ferre (5):
  net: macb: fix wakeup test in runtime suspend/resume routines
  net: macb: mark device wake capable when "magic-packet" property
    present
  net: macb: fix macb_get/set_wol() when moving to phylink
  net: macb: fix macb_suspend() by removing call to netif_carrier_off()
  net: macb: fix call to pm_runtime in the suspend/resume functions

 drivers/net/ethernet/cadence/macb_main.c | 31 +++++++++++++++---------
 1 file changed, 19 insertions(+), 12 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v5 1/5] net: macb: fix wakeup test in runtime suspend/resume routines
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
@ 2020-07-10 12:46 ` nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 2/5] net: macb: mark device wake capable when "magic-packet" property present nicolas.ferre
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre

From: Nicolas Ferre <nicolas.ferre@microchip.com>

Use the proper struct device pointer to check if the wakeup flag
and wakeup source are positioned.
Use the one passed by function call which is equivalent to
&bp->dev->dev.parent.

It's preventing the trigger of a spurious interrupt in case the
Wake-on-Lan feature is used.

Fixes: d54f89af6cc4 ("net: macb: Add pm runtime support")
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Harini Katakam <harini.katakam@xilinx.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
---
 drivers/net/ethernet/cadence/macb_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 52582e8ed90e..55e680f35022 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4654,7 +4654,7 @@ static int __maybe_unused macb_runtime_suspend(struct device *dev)
 	struct net_device *netdev = dev_get_drvdata(dev);
 	struct macb *bp = netdev_priv(netdev);
 
-	if (!(device_may_wakeup(&bp->dev->dev))) {
+	if (!(device_may_wakeup(dev))) {
 		clk_disable_unprepare(bp->tx_clk);
 		clk_disable_unprepare(bp->hclk);
 		clk_disable_unprepare(bp->pclk);
@@ -4670,7 +4670,7 @@ static int __maybe_unused macb_runtime_resume(struct device *dev)
 	struct net_device *netdev = dev_get_drvdata(dev);
 	struct macb *bp = netdev_priv(netdev);
 
-	if (!(device_may_wakeup(&bp->dev->dev))) {
+	if (!(device_may_wakeup(dev))) {
 		clk_prepare_enable(bp->pclk);
 		clk_prepare_enable(bp->hclk);
 		clk_prepare_enable(bp->tx_clk);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v5 2/5] net: macb: mark device wake capable when "magic-packet" property present
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 1/5] net: macb: fix wakeup test in runtime suspend/resume routines nicolas.ferre
@ 2020-07-10 12:46 ` nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 3/5] net: macb: fix macb_get/set_wol() when moving to phylink nicolas.ferre
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre, Sergio Prado

From: Nicolas Ferre <nicolas.ferre@microchip.com>

Change the way the "magic-packet" DT property is handled in the
macb_probe() function, matching DT binding documentation.
Now we mark the device as "wakeup capable" instead of calling the
device_init_wakeup() function that would enable the wakeup source.

For Ethernet WoL, enabling the wakeup_source is done by
using ethtool and associated macb_set_wol() function that
already calls device_set_wakeup_enable() for this purpose.

That would reduce power consumption by cutting more clocks if
"magic-packet" property is set but WoL is not configured by ethtool.

Fixes: 3e2a5e153906 ("net: macb: add wake-on-lan support via magic packet")
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Harini Katakam <harini.katakam@xilinx.com>
Cc: Sergio Prado <sergio.prado@e-labworks.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
---
 drivers/net/ethernet/cadence/macb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 55e680f35022..4cafe343c0a2 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4422,7 +4422,7 @@ static int macb_probe(struct platform_device *pdev)
 	bp->wol = 0;
 	if (of_get_property(np, "magic-packet", NULL))
 		bp->wol |= MACB_WOL_HAS_MAGIC_PACKET;
-	device_init_wakeup(&pdev->dev, bp->wol & MACB_WOL_HAS_MAGIC_PACKET);
+	device_set_wakeup_capable(&pdev->dev, bp->wol & MACB_WOL_HAS_MAGIC_PACKET);
 
 	spin_lock_init(&bp->lock);
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v5 3/5] net: macb: fix macb_get/set_wol() when moving to phylink
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 1/5] net: macb: fix wakeup test in runtime suspend/resume routines nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 2/5] net: macb: mark device wake capable when "magic-packet" property present nicolas.ferre
@ 2020-07-10 12:46 ` nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 4/5] net: macb: fix macb_suspend() by removing call to netif_carrier_off() nicolas.ferre
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre

From: Nicolas Ferre <nicolas.ferre@microchip.com>

Keep previous function goals and integrate phylink actions to them.

phylink_ethtool_get_wol() is not enough to figure out if Ethernet driver
supports Wake-on-Lan.
Initialization of "supported" and "wolopts" members is done in phylink
function, no need to keep them in calling function.

phylink_ethtool_set_wol() return value is considered and determines
if the MAC has to handle WoL or not. The case where the PHY doesn't
implement WoL leads to the MAC configuring it to provide this feature.

Fixes: 7897b071ac3b ("net: macb: convert to phylink")
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Harini Katakam <harini.katakam@xilinx.com>
Cc: Antoine Tenart <antoine.tenart@bootlin.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
---
Changes in v5:
- Addressed the error code returned by phylink_ethtool_set_wol() as suggested
  by Russell.
  If PHY handles WoL, MAC doesn't stay in the way.
- Removed Florian's tag

 drivers/net/ethernet/cadence/macb_main.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 4cafe343c0a2..79c2fe054303 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -2821,11 +2821,13 @@ static void macb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 {
 	struct macb *bp = netdev_priv(netdev);
 
-	wol->supported = 0;
-	wol->wolopts = 0;
-
-	if (bp->wol & MACB_WOL_HAS_MAGIC_PACKET)
+	if (bp->wol & MACB_WOL_HAS_MAGIC_PACKET) {
 		phylink_ethtool_get_wol(bp->phylink, wol);
+		wol->supported |= WAKE_MAGIC;
+
+		if (bp->wol & MACB_WOL_ENABLED)
+			wol->wolopts |= WAKE_MAGIC;
+	}
 }
 
 static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
@@ -2833,9 +2835,13 @@ static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 	struct macb *bp = netdev_priv(netdev);
 	int ret;
 
+	/* Pass the order to phylink layer */
 	ret = phylink_ethtool_set_wol(bp->phylink, wol);
-	if (!ret)
-		return 0;
+	/* Don't manage WoL on MAC if handled by the PHY
+	 * or if there's a failure in talking to the PHY
+	 */
+	if (!ret || ret != -EOPNOTSUPP)
+		return ret;
 
 	if (!(bp->wol & MACB_WOL_HAS_MAGIC_PACKET) ||
 	    (wol->wolopts & ~WAKE_MAGIC))
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v5 4/5] net: macb: fix macb_suspend() by removing call to netif_carrier_off()
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
                   ` (2 preceding siblings ...)
  2020-07-10 12:46 ` [PATCH v5 3/5] net: macb: fix macb_get/set_wol() when moving to phylink nicolas.ferre
@ 2020-07-10 12:46 ` nicolas.ferre
  2020-07-10 12:46 ` [PATCH v5 5/5] net: macb: fix call to pm_runtime in the suspend/resume functions nicolas.ferre
  2020-07-10 21:29 ` [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre

From: Nicolas Ferre <nicolas.ferre@microchip.com>

As we now use the phylink call to phylink_stop() in the non-WoL path,
there is no need for this call to netif_carrier_off() anymore. It can
disturb the underlying phylink FSM.

Fixes: 7897b071ac3b ("net: macb: convert to phylink")
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Harini Katakam <harini.katakam@xilinx.com>
Cc: Antoine Tenart <antoine.tenart@bootlin.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
---
Changes in v2:
- new in v2 serries

 drivers/net/ethernet/cadence/macb_main.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 79c2fe054303..548815255e22 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4604,7 +4604,6 @@ static int __maybe_unused macb_suspend(struct device *dev)
 			bp->pm_data.scrt2 = gem_readl_n(bp, ETHT, SCRT2_ETHT);
 	}
 
-	netif_carrier_off(netdev);
 	if (bp->ptp_info)
 		bp->ptp_info->ptp_remove(netdev);
 	pm_runtime_force_suspend(dev);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v5 5/5] net: macb: fix call to pm_runtime in the suspend/resume functions
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
                   ` (3 preceding siblings ...)
  2020-07-10 12:46 ` [PATCH v5 4/5] net: macb: fix macb_suspend() by removing call to netif_carrier_off() nicolas.ferre
@ 2020-07-10 12:46 ` nicolas.ferre
  2020-07-10 21:29 ` [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: nicolas.ferre @ 2020-07-10 12:46 UTC (permalink / raw)
  To: linux, linux-arm-kernel, netdev, Claudiu Beznea, harini.katakam,
	f.fainelli
  Cc: linux-kernel, David S. Miller, Alexandre Belloni, antoine.tenart,
	Nicolas Ferre, Sergio Prado

From: Nicolas Ferre <nicolas.ferre@microchip.com>

The calls to pm_runtime_force_suspend/resume() functions are only
relevant if the device is not configured to act as a WoL wakeup source.
Add the device_may_wakeup() test before calling them.

Fixes: 3e2a5e153906 ("net: macb: add wake-on-lan support via magic packet")
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Harini Katakam <harini.katakam@xilinx.com>
Cc: Sergio Prado <sergio.prado@e-labworks.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
---
Changes in v3:
 - remove the parenthesis around device_may_wakeup()
Changes in v2:
- new in v2 serries
 drivers/net/ethernet/cadence/macb_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 548815255e22..f1f0976e7669 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4606,7 +4606,8 @@ static int __maybe_unused macb_suspend(struct device *dev)
 
 	if (bp->ptp_info)
 		bp->ptp_info->ptp_remove(netdev);
-	pm_runtime_force_suspend(dev);
+	if (!device_may_wakeup(dev))
+		pm_runtime_force_suspend(dev);
 
 	return 0;
 }
@@ -4621,7 +4622,8 @@ static int __maybe_unused macb_resume(struct device *dev)
 	if (!netif_running(netdev))
 		return 0;
 
-	pm_runtime_force_resume(dev);
+	if (!device_may_wakeup(dev))
+		pm_runtime_force_resume(dev);
 
 	if (bp->wol & MACB_WOL_ENABLED) {
 		macb_writel(bp, IDR, MACB_BIT(WOL));
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling
  2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
                   ` (4 preceding siblings ...)
  2020-07-10 12:46 ` [PATCH v5 5/5] net: macb: fix call to pm_runtime in the suspend/resume functions nicolas.ferre
@ 2020-07-10 21:29 ` David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2020-07-10 21:29 UTC (permalink / raw)
  To: nicolas.ferre
  Cc: linux, linux-arm-kernel, netdev, claudiu.beznea, harini.katakam,
	f.fainelli, linux-kernel, alexandre.belloni, antoine.tenart

From: <nicolas.ferre@microchip.com>
Date: Fri, 10 Jul 2020 14:46:40 +0200

> Here is a split series to fix WoL magic-packet on the current macb driver. Only
> fixes in this one based on current net/master.

Series applied, thank you.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-10 21:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 12:46 [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling nicolas.ferre
2020-07-10 12:46 ` [PATCH v5 1/5] net: macb: fix wakeup test in runtime suspend/resume routines nicolas.ferre
2020-07-10 12:46 ` [PATCH v5 2/5] net: macb: mark device wake capable when "magic-packet" property present nicolas.ferre
2020-07-10 12:46 ` [PATCH v5 3/5] net: macb: fix macb_get/set_wol() when moving to phylink nicolas.ferre
2020-07-10 12:46 ` [PATCH v5 4/5] net: macb: fix macb_suspend() by removing call to netif_carrier_off() nicolas.ferre
2020-07-10 12:46 ` [PATCH v5 5/5] net: macb: fix call to pm_runtime in the suspend/resume functions nicolas.ferre
2020-07-10 21:29 ` [PATCH v5 0/5] net: macb: Wake-on-Lan magic packet fixes and GEM handling David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).