linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
@ 2016-06-03 17:29 Vincent Palatin
  2016-06-06 20:45 ` Heiko Stübner
  2016-06-07  7:23 ` Giuseppe CAVALLARO
  0 siblings, 2 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-03 17:29 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Alexandre Torgue, Giuseppe Cavallaro,
	Heiko Stübner, Vincent Palatin

Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
us up.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 0cd3ecf..2e45e75 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -534,6 +534,10 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
 	struct rk_priv_data *bsp_priv = priv;
 	int ret;
 
+	/* Keep the PHY up if we use Wake-on-Lan. */
+	if (device_may_wakeup(&pdev->dev))
+		return 0;
+
 	ret = phy_power_on(bsp_priv, true);
 	if (ret)
 		return ret;
@@ -549,6 +553,10 @@ static void rk_gmac_exit(struct platform_device *pdev, void *priv)
 {
 	struct rk_priv_data *gmac = priv;
 
+	/* The PHY was up for Wake-on-Lan. */
+	if (device_may_wakeup(&pdev->dev))
+		return;
+
 	phy_power_on(gmac, false);
 	gmac_clk_enable(gmac, false);
 }
-- 
2.8.0.rc3.226.g39d4020

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-03 17:29 [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL Vincent Palatin
@ 2016-06-06 20:45 ` Heiko Stübner
  2016-06-06 21:00   ` Vincent Palatin
  2016-06-07  7:23 ` Giuseppe CAVALLARO
  1 sibling, 1 reply; 26+ messages in thread
From: Heiko Stübner @ 2016-06-06 20:45 UTC (permalink / raw)
  To: Vincent Palatin
  Cc: netdev, linux-kernel, Alexandre Torgue, Giuseppe Cavallaro

Hi,

Am Freitag, 3. Juni 2016, 10:29:20 schrieb Vincent Palatin:
> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
> us up.
> 
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 0cd3ecf..2e45e75
> 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> @@ -534,6 +534,10 @@ static int rk_gmac_init(struct platform_device *pdev,
> void *priv) struct rk_priv_data *bsp_priv = priv;
>  	int ret;
> 
> +	/* Keep the PHY up if we use Wake-on-Lan. */
> +	if (device_may_wakeup(&pdev->dev))
> +		return 0;
> +

Hmm, this looks like it would also block the initial setup of clocks and phy?
platform_device + device struct are created before probe gets called, so 
something could set the wakeup flag before the driver initially probes?


Confused,
Heiko

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-06 20:45 ` Heiko Stübner
@ 2016-06-06 21:00   ` Vincent Palatin
  0 siblings, 0 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-06 21:00 UTC (permalink / raw)
  To: Heiko Stübner
  Cc: netdev, LKML, Alexandre Torgue, Giuseppe Cavallaro, Douglas Anderson

On Mon, Jun 6, 2016 at 1:45 PM, Heiko Stübner <heiko@sntech.de> wrote:
> Hi,
>
> Am Freitag, 3. Juni 2016, 10:29:20 schrieb Vincent Palatin:
>> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
>> us up.
>>
>> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
>> ---
>>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 0cd3ecf..2e45e75
>> 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> @@ -534,6 +534,10 @@ static int rk_gmac_init(struct platform_device *pdev,
>> void *priv) struct rk_priv_data *bsp_priv = priv;
>>       int ret;
>>
>> +     /* Keep the PHY up if we use Wake-on-Lan. */
>> +     if (device_may_wakeup(&pdev->dev))
>> +             return 0;
>> +
>
> Hmm, this looks like it would also block the initial setup of clocks and phy?

Yes, that's bad. Doug told me so but I forget to CC him on the
previous submission.
I will do another version.

> platform_device + device struct are created before probe gets called, so
> something could set the wakeup flag before the driver initially probes?

The device tree 'wakeup' attribute likely does it.

-- 
Vincent

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-03 17:29 [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL Vincent Palatin
  2016-06-06 20:45 ` Heiko Stübner
@ 2016-06-07  7:23 ` Giuseppe CAVALLARO
  2016-06-08 22:25   ` Vincent Palatin
  1 sibling, 1 reply; 26+ messages in thread
From: Giuseppe CAVALLARO @ 2016-06-07  7:23 UTC (permalink / raw)
  To: Vincent Palatin, netdev
  Cc: linux-kernel, Alexandre Torgue, Heiko Stübner

Hello

On 6/3/2016 7:29 PM, Vincent Palatin wrote:
> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
> us up.
>

I do not understand why you need that.
This is done inside the PHY layer and it is tested on our platforms
he idea is: If the parent wants to Wake the system then the PHY should
not power-down.

Peppe

> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> index 0cd3ecf..2e45e75 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> @@ -534,6 +534,10 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
>  	struct rk_priv_data *bsp_priv = priv;
>  	int ret;
>
> +	/* Keep the PHY up if we use Wake-on-Lan. */
> +	if (device_may_wakeup(&pdev->dev))
> +		return 0;
> +
>  	ret = phy_power_on(bsp_priv, true);
>  	if (ret)
>  		return ret;
> @@ -549,6 +553,10 @@ static void rk_gmac_exit(struct platform_device *pdev, void *priv)
>  {
>  	struct rk_priv_data *gmac = priv;
>
> +	/* The PHY was up for Wake-on-Lan. */
> +	if (device_may_wakeup(&pdev->dev))
> +		return;
> +
>  	phy_power_on(gmac, false);
>  	gmac_clk_enable(gmac, false);
>  }
>

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-07  7:23 ` Giuseppe CAVALLARO
@ 2016-06-08 22:25   ` Vincent Palatin
  2016-06-09  0:17     ` Andrew Lunn
  0 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-08 22:25 UTC (permalink / raw)
  To: Giuseppe CAVALLARO; +Cc: netdev, LKML, Alexandre Torgue, Heiko Stübner

On Tue, Jun 7, 2016 at 12:23 AM, Giuseppe CAVALLARO
<peppe.cavallaro@st.com> wrote:
> Hello
>
> On 6/3/2016 7:29 PM, Vincent Palatin wrote:
>>
>> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
>> us up.
>>
>
> I do not understand why you need that.
> This is done inside the PHY layer and it is tested on our platforms
> he idea is: If the parent wants to Wake the system then the PHY should
> not power-down.

I'm not sure I understand :
you mean that this path is not called if WoL is enabled ?
[ currently stmmac_pltfr_suspend() is calling priv->plat->exit() which
is the rk_gmac_exit() code I'm modifying ]
or the RK driver code should not power down the phy in its exit() callback ?


>> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
>> ---
>>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> index 0cd3ecf..2e45e75 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> @@ -534,6 +534,10 @@ static int rk_gmac_init(struct platform_device *pdev,
>> void *priv)
>>         struct rk_priv_data *bsp_priv = priv;
>>         int ret;
>>
>> +       /* Keep the PHY up if we use Wake-on-Lan. */
>> +       if (device_may_wakeup(&pdev->dev))
>> +               return 0;
>> +
>>         ret = phy_power_on(bsp_priv, true);
>>         if (ret)
>>                 return ret;
>> @@ -549,6 +553,10 @@ static void rk_gmac_exit(struct platform_device
>> *pdev, void *priv)
>>  {
>>         struct rk_priv_data *gmac = priv;
>>
>> +       /* The PHY was up for Wake-on-Lan. */
>> +       if (device_may_wakeup(&pdev->dev))
>> +               return;
>> +
>>         phy_power_on(gmac, false);
>>         gmac_clk_enable(gmac, false);
>>  }
>>
>

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-08 22:25   ` Vincent Palatin
@ 2016-06-09  0:17     ` Andrew Lunn
  2016-06-09 23:00       ` Vincent Palatin
  0 siblings, 1 reply; 26+ messages in thread
From: Andrew Lunn @ 2016-06-09  0:17 UTC (permalink / raw)
  To: Vincent Palatin
  Cc: Giuseppe CAVALLARO, netdev, LKML, Alexandre Torgue, Heiko Stübner

On Wed, Jun 08, 2016 at 03:25:38PM -0700, Vincent Palatin wrote:
> On Tue, Jun 7, 2016 at 12:23 AM, Giuseppe CAVALLARO
> <peppe.cavallaro@st.com> wrote:
> > Hello
> >
> > On 6/3/2016 7:29 PM, Vincent Palatin wrote:
> >>
> >> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
> >> us up.
> >>
> >
> > I do not understand why you need that.
> > This is done inside the PHY layer and it is tested on our platforms
> > he idea is: If the parent wants to Wake the system then the PHY should
> > not power-down.
> 
> I'm not sure I understand :
> you mean that this path is not called if WoL is enabled ?
> [ currently stmmac_pltfr_suspend() is calling priv->plat->exit() which
> is the rk_gmac_exit() code I'm modifying ]
> or the RK driver code should not power down the phy in its exit() callback ?

Take a look at phy_suspend().

     Andrew

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-09  0:17     ` Andrew Lunn
@ 2016-06-09 23:00       ` Vincent Palatin
  2016-06-10 12:29         ` Giuseppe CAVALLARO
  0 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-09 23:00 UTC (permalink / raw)
  To: Andrew Lunn, Giuseppe CAVALLARO
  Cc: netdev, LKML, Alexandre Torgue, Heiko Stübner, Douglas Anderson

On Wed, Jun 8, 2016 at 5:17 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Wed, Jun 08, 2016 at 03:25:38PM -0700, Vincent Palatin wrote:
>> On Tue, Jun 7, 2016 at 12:23 AM, Giuseppe CAVALLARO
>> <peppe.cavallaro@st.com> wrote:
>> > Hello
>> >
>> > On 6/3/2016 7:29 PM, Vincent Palatin wrote:
>> >>
>> >> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
>> >> us up.
>> >>
>> >
>> > I do not understand why you need that.
>> > This is done inside the PHY layer and it is tested on our platforms
>> > he idea is: If the parent wants to Wake the system then the PHY should
>> > not power-down.
>>
>> I'm not sure I understand :
>> you mean that this path is not called if WoL is enabled ?
>> [ currently stmmac_pltfr_suspend() is calling priv->plat->exit() which
>> is the rk_gmac_exit() code I'm modifying ]
>> or the RK driver code should not power down the phy in its exit() callback ?
>
> Take a look at phy_suspend().

phy_suspend() sends (or not) the PowerDown command to the PHY through
the MDIO bus,  depending if WoL is disabled,
but most of my question still stands as far as I can tell :
I was trying to get a proper WoL support on the following setup :
  dwmac  (inside a RK3288 SoC) connected to RTL8211 PHY
The current upstream code for this case will call rk_gmac_exit() when
the MAC suspends (after the PHY has already suspended). Effectively
doing a phy_power_on(, false) which is calling regulator_disable() on
the LDO defined by the 'phy-supply' attribute.
So my reading is that the RK specific MAC code is turning off
unconditionally the PHY power regulator. Unless I'm mistaken, either
this code is incorrect for the WoL case or the naming 'phy-supply' is
misleading and should be the MAC supply.

-- 
Vincent

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

* Re: [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL
  2016-06-09 23:00       ` Vincent Palatin
@ 2016-06-10 12:29         ` Giuseppe CAVALLARO
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  0 siblings, 1 reply; 26+ messages in thread
From: Giuseppe CAVALLARO @ 2016-06-10 12:29 UTC (permalink / raw)
  To: Vincent Palatin, Andrew Lunn
  Cc: netdev, LKML, Alexandre Torgue, Heiko Stübner, Douglas Anderson

Hello Vincent

On 6/10/2016 1:00 AM, Vincent Palatin wrote:
> On Wed, Jun 8, 2016 at 5:17 PM, Andrew Lunn <andrew@lunn.ch> wrote:
>> On Wed, Jun 08, 2016 at 03:25:38PM -0700, Vincent Palatin wrote:
>>> On Tue, Jun 7, 2016 at 12:23 AM, Giuseppe CAVALLARO
>>> <peppe.cavallaro@st.com> wrote:
>>>> Hello
>>>>
>>>> On 6/3/2016 7:29 PM, Vincent Palatin wrote:
>>>>>
>>>>> Do not shutdown the PHY if Wake-on-Lan is enabled, else it cannot wake
>>>>> us up.
>>>>>
>>>>
>>>> I do not understand why you need that.
>>>> This is done inside the PHY layer and it is tested on our platforms
>>>> he idea is: If the parent wants to Wake the system then the PHY should
>>>> not power-down.
>>>
>>> I'm not sure I understand :
>>> you mean that this path is not called if WoL is enabled ?
>>> [ currently stmmac_pltfr_suspend() is calling priv->plat->exit() which
>>> is the rk_gmac_exit() code I'm modifying ]
>>> or the RK driver code should not power down the phy in its exit() callback ?
>>
>> Take a look at phy_suspend().
>
> phy_suspend() sends (or not) the PowerDown command to the PHY through
> the MDIO bus,  depending if WoL is disabled,
> but most of my question still stands as far as I can tell :
> I was trying to get a proper WoL support on the following setup :
>   dwmac  (inside a RK3288 SoC) connected to RTL8211 PHY
> The current upstream code for this case will call rk_gmac_exit() when
> the MAC suspends (after the PHY has already suspended). Effectively
> doing a phy_power_on(, false) which is calling regulator_disable() on
> the LDO defined by the 'phy-supply' attribute.
> So my reading is that the RK specific MAC code is turning off
> unconditionally the PHY power regulator. Unless I'm mistaken, either
> this code is incorrect for the WoL case or the naming 'phy-supply' is
> misleading and should be the MAC supply.

ok now clear. And you are right. I can conclude that the patch is ok
for me. I just ask you to resend it elaborating a bit the subject and
surrounding the code with a comment.

I do not know your SoC but indeed, when doing WoL, some parts of the
MAC + PHY must be powered so IMO it is legal that you do not cut
the power by invoking regulator.

Peppe

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

* net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-10 12:29         ` Giuseppe CAVALLARO
@ 2016-06-11  1:00           ` Vincent Palatin
  2016-06-11  1:00             ` [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
                               ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-11  1:00 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng

In order to support Wake-On-Lan when using the RK3288 integrated MAC
(with an external RGMII PHY), we need to avoid shutting down the regulator
of the external PHY when the MAC is suspended as it's currently done in the MAC 
platform code.
As a first step, create independant callbacks for suspend/resume rather than
re-using exit/init callbacks. So the dwmac platform driver can behave differently
on suspend where it might skip shutting the PHY and at module unloading.
Then update the dwmac-rk driver to switch off the PHY regulator only if we are
not planning to wake up from the LAN.
Finally add the PMT interrupt to the MAC device tree configuration, so we can
wake up the core from it when the PHY has received the magic packet.

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

* [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
@ 2016-06-11  1:00             ` Vincent Palatin
  2016-06-11  1:16               ` David Miller
  2016-06-11  1:00             ` [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
                               ` (3 subsequent siblings)
  4 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-11  1:00 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

Let the stmmac platform drivers provide dedicated suspend and resume
callbacks rather than always re-using the init and exits callbacks.
If the driver does not provide the suspend or resume callback, we fall
back to the old behavior trying to use exit or init.

This allows a specific platform to perform only a partial power-down on
suspend if Wake-on-Lan is enabled but always perform the full shutdown
sequence if the module is unloaded.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 8 ++++++--
 include/linux/stmmac.h                                | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 409db91..a96714d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -411,7 +411,9 @@ static int stmmac_pltfr_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 
 	ret = stmmac_suspend(dev);
-	if (priv->plat->exit)
+	if (priv->plat->suspend)
+		priv->plat->suspend(pdev, priv->plat->bsp_priv);
+	else if (priv->plat->exit)
 		priv->plat->exit(pdev, priv->plat->bsp_priv);
 
 	return ret;
@@ -430,7 +432,9 @@ static int stmmac_pltfr_resume(struct device *dev)
 	struct stmmac_priv *priv = netdev_priv(ndev);
 	struct platform_device *pdev = to_platform_device(dev);
 
-	if (priv->plat->init)
+	if (priv->plat->resume)
+		priv->plat->resume(pdev, priv->plat->bsp_priv);
+	else if (priv->plat->init)
 		priv->plat->init(pdev, priv->plat->bsp_priv);
 
 	return stmmac_resume(dev);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index ffdaca9..0507dbf 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -135,6 +135,8 @@ struct plat_stmmacenet_data {
 	void (*bus_setup)(void __iomem *ioaddr);
 	int (*init)(struct platform_device *pdev, void *priv);
 	void (*exit)(struct platform_device *pdev, void *priv);
+	void (*suspend)(struct platform_device *pdev, void *priv);
+	void (*resume)(struct platform_device *pdev, void *priv);
 	void *bsp_priv;
 	struct stmmac_axi *axi;
 	int has_gmac4;
-- 
2.8.0.rc3.226.g39d4020

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

* [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  2016-06-11  1:00             ` [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
@ 2016-06-11  1:00             ` Vincent Palatin
  2016-06-11  1:57               ` Heiko Stuebner
  2016-06-11  1:00             ` [PATCH 3/3] ARM: dts: rockchip: add interrupt " Vincent Palatin
                               ` (2 subsequent siblings)
  4 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-11  1:00 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

When suspending the machine, do not shutdown the external PHY by cutting
its regulator in the mac platform driver suspend code if Wake-on-Lan is enabled,
else it cannot wake us up.
In order to do this, split the suspend/resume callbacks from the
init/exit callbacks, so we can condition the power-down on the lack of
need to wake-up from the LAN but do it unconditionally when unloading the
module.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 49 +++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 0cd3ecf..fa05771 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -46,6 +46,7 @@ struct rk_priv_data {
 	struct platform_device *pdev;
 	int phy_iface;
 	struct regulator *regulator;
+	bool powered_down;
 	const struct rk_gmac_ops *ops;
 
 	bool clk_enabled;
@@ -529,9 +530,8 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
 	return bsp_priv;
 }
 
-static int rk_gmac_init(struct platform_device *pdev, void *priv)
+static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
 {
-	struct rk_priv_data *bsp_priv = priv;
 	int ret;
 
 	ret = phy_power_on(bsp_priv, true);
@@ -542,15 +542,52 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
 	if (ret)
 		return ret;
 
+	bsp_priv->powered_down = true;
+
 	return 0;
 }
 
-static void rk_gmac_exit(struct platform_device *pdev, void *priv)
+static void rk_gmac_powerdown(struct rk_priv_data *gmac)
 {
-	struct rk_priv_data *gmac = priv;
-
 	phy_power_on(gmac, false);
 	gmac_clk_enable(gmac, false);
+	gmac->powered_down = true;
+}
+
+static int rk_gmac_init(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	return rk_gmac_powerup(bsp_priv);
+}
+
+static void rk_gmac_exit(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	rk_gmac_powerdown(bsp_priv);
+}
+
+static void rk_gmac_suspend(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	/* Keep the PHY up if we use Wake-on-Lan. */
+	if (device_may_wakeup(&pdev->dev))
+		return;
+
+	rk_gmac_powerdown(bsp_priv);
+}
+
+static void rk_gmac_resume(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	/* The PHY was up for Wake-on-Lan. */
+	if (!bsp_priv->powered_down)
+		return;
+
+	rk_gmac_powerup(bsp_priv);
 }
 
 static void rk_fix_speed(void *priv, unsigned int speed)
@@ -591,6 +628,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	plat_dat->init = rk_gmac_init;
 	plat_dat->exit = rk_gmac_exit;
 	plat_dat->fix_mac_speed = rk_fix_speed;
+	plat_dat->suspend = rk_gmac_suspend;
+	plat_dat->resume = rk_gmac_resume;
 
 	plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
 	if (IS_ERR(plat_dat->bsp_priv))
-- 
2.8.0.rc3.226.g39d4020

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

* [PATCH 3/3] ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  2016-06-11  1:00             ` [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
  2016-06-11  1:00             ` [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
@ 2016-06-11  1:00             ` Vincent Palatin
  2016-06-11  1:16             ` net: stmmac: dwmac-rk: fixes " David Miller
  2016-06-13  6:46             ` Giuseppe CAVALLARO
  4 siblings, 0 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-11  1:00 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

In order to use Wake-on-Lan on RK3288 integrated MAC, we need to wake-up
the CPU on the PMT interrupt when the MAC and the PHY are in low power mode.
Adding the interrupt declaration.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 arch/arm/boot/dts/rk3288.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 3b44ef3..3ebee53 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -539,8 +539,9 @@
 	gmac: ethernet@ff290000 {
 		compatible = "rockchip,rk3288-gmac";
 		reg = <0xff290000 0x10000>;
-		interrupts = <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>;
-		interrupt-names = "macirq";
+		interrupts = <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>,
+				<GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "macirq", "eth_wake_irq";
 		rockchip,grf = <&grf>;
 		clocks = <&cru SCLK_MAC>,
 			<&cru SCLK_MAC_RX>, <&cru SCLK_MAC_TX>,
-- 
2.8.0.rc3.226.g39d4020

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

* Re: [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks
  2016-06-11  1:00             ` [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
@ 2016-06-11  1:16               ` David Miller
  0 siblings, 0 replies; 26+ messages in thread
From: David Miller @ 2016-06-11  1:16 UTC (permalink / raw)
  To: vpalatin
  Cc: netdev, linux-kernel, andrew, dianders, peppe.cavallaro, heiko, zhengsq


All proper patch serieses must start with an introductory postings
ala "Subject: [PATCH 0/3] ..." which explains what the patch series
is doing at a high level, why, and how.

Thanks.

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
                               ` (2 preceding siblings ...)
  2016-06-11  1:00             ` [PATCH 3/3] ARM: dts: rockchip: add interrupt " Vincent Palatin
@ 2016-06-11  1:16             ` David Miller
  2016-06-13  6:46             ` Giuseppe CAVALLARO
  4 siblings, 0 replies; 26+ messages in thread
From: David Miller @ 2016-06-11  1:16 UTC (permalink / raw)
  To: vpalatin
  Cc: netdev, linux-kernel, andrew, dianders, peppe.cavallaro, heiko, zhengsq

From: Vincent Palatin <vpalatin@chromium.org>
Date: Fri, 10 Jun 2016 18:00:36 -0700

> In order to support Wake-On-Lan when using the RK3288 integrated MAC
> (with an external RGMII PHY), we need to avoid shutting down the regulator
> of the external PHY when the MAC is suspended as it's currently done in the MAC 
> platform code.
> As a first step, create independant callbacks for suspend/resume rather than
> re-using exit/init callbacks. So the dwmac platform driver can behave differently
> on suspend where it might skip shutting the PHY and at module unloading.
> Then update the dwmac-rk driver to switch off the PHY regulator only if we are
> not planning to wake up from the LAN.
> Finally add the PMT interrupt to the MAC device tree configuration, so we can
> wake up the core from it when the PHY has received the magic packet.
> 

Ignore my previous email, but in the future please tag these postings
properly with "[PATCH 0/N] " at the beginning of the subject line.

Thanks.

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

* Re: [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL
  2016-06-11  1:00             ` [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
@ 2016-06-11  1:57               ` Heiko Stuebner
  2016-06-15 16:03                 ` Vincent Palatin
  0 siblings, 1 reply; 26+ messages in thread
From: Heiko Stuebner @ 2016-06-11  1:57 UTC (permalink / raw)
  To: Vincent Palatin
  Cc: netdev, linux-kernel, Andrew Lunn, Douglas Anderson,
	Giuseppe Cavallaro, Shunqian Zheng

Am Freitag, 10. Juni 2016, 18:00:38 schrieb Vincent Palatin:
> When suspending the machine, do not shutdown the external PHY by cutting
> its regulator in the mac platform driver suspend code if Wake-on-Lan is
> enabled, else it cannot wake us up.
> In order to do this, split the suspend/resume callbacks from the
> init/exit callbacks, so we can condition the power-down on the lack of
> need to wake-up from the LAN but do it unconditionally when unloading the
> module.
> 
> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 49
> +++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5
> deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 0cd3ecf..fa05771
> 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
> @@ -46,6 +46,7 @@ struct rk_priv_data {
>  	struct platform_device *pdev;
>  	int phy_iface;
>  	struct regulator *regulator;
> +	bool powered_down;
>  	const struct rk_gmac_ops *ops;
> 
>  	bool clk_enabled;
> @@ -529,9 +530,8 @@ static struct rk_priv_data *rk_gmac_setup(struct
> platform_device *pdev, return bsp_priv;
>  }
> 
> -static int rk_gmac_init(struct platform_device *pdev, void *priv)
> +static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
>  {
> -	struct rk_priv_data *bsp_priv = priv;
>  	int ret;
> 
>  	ret = phy_power_on(bsp_priv, true);
> @@ -542,15 +542,52 @@ static int rk_gmac_init(struct platform_device
> *pdev, void *priv) if (ret)
>  		return ret;
> 
> +	bsp_priv->powered_down = true;
> +
>  	return 0;
>  }
> 
> -static void rk_gmac_exit(struct platform_device *pdev, void *priv)
> +static void rk_gmac_powerdown(struct rk_priv_data *gmac)
>  {
> -	struct rk_priv_data *gmac = priv;
> -
>  	phy_power_on(gmac, false);
>  	gmac_clk_enable(gmac, false);
> +	gmac->powered_down = true;

naming it gmac->suspended and doing all accesses in the suspend/resume 
callback might provide a nicer way? Now the check is in resume while the 
powerdown callback is setting it.

> +}
> +
> +static int rk_gmac_init(struct platform_device *pdev, void *priv)
> +{
> +	struct rk_priv_data *bsp_priv = priv;
> +
> +	return rk_gmac_powerup(bsp_priv);
> +}
> +
> +static void rk_gmac_exit(struct platform_device *pdev, void *priv)
> +{
> +	struct rk_priv_data *bsp_priv = priv;
> +
> +	rk_gmac_powerdown(bsp_priv);
> +}
> +
> +static void rk_gmac_suspend(struct platform_device *pdev, void *priv)
> +{
> +	struct rk_priv_data *bsp_priv = priv;
> +
> +	/* Keep the PHY up if we use Wake-on-Lan. */
> +	if (device_may_wakeup(&pdev->dev))
> +		return;
> +
> +	rk_gmac_powerdown(bsp_priv);

aka do
	bsp_priv->suspended = true;
here

> +}
> +
> +static void rk_gmac_resume(struct platform_device *pdev, void *priv)
> +{
> +	struct rk_priv_data *bsp_priv = priv;
> +
> +	/* The PHY was up for Wake-on-Lan. */
> +	if (!bsp_priv->powered_down)
> +		return;
> +
> +	rk_gmac_powerup(bsp_priv);

missing something like
	bsp_priv->suspended = false;

Right now it looks like your bsp_priv->powered_down will always be true 
after the first suspend with powerdown.

>  }
> 
>  static void rk_fix_speed(void *priv, unsigned int speed)
> @@ -591,6 +628,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
> plat_dat->init = rk_gmac_init;
>  	plat_dat->exit = rk_gmac_exit;
>  	plat_dat->fix_mac_speed = rk_fix_speed;
> +	plat_dat->suspend = rk_gmac_suspend;
> +	plat_dat->resume = rk_gmac_resume;
> 
>  	plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
>  	if (IS_ERR(plat_dat->bsp_priv))
> --
> 2.8.0.rc3.226.g39d4020

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
                               ` (3 preceding siblings ...)
  2016-06-11  1:16             ` net: stmmac: dwmac-rk: fixes " David Miller
@ 2016-06-13  6:46             ` Giuseppe CAVALLARO
  2016-06-15 17:04               ` Vincent Palatin
  4 siblings, 1 reply; 26+ messages in thread
From: Giuseppe CAVALLARO @ 2016-06-13  6:46 UTC (permalink / raw)
  To: Vincent Palatin, netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Heiko Stübner,
	Shunqian Zheng, David Miller

On 6/11/2016 3:00 AM, Vincent Palatin wrote:
> In order to support Wake-On-Lan when using the RK3288 integrated MAC
> (with an external RGMII PHY), we need to avoid shutting down the regulator
> of the external PHY when the MAC is suspended as it's currently done in the MAC
> platform code.
> As a first step, create independant callbacks for suspend/resume rather than
> re-using exit/init callbacks. So the dwmac platform driver can behave differently
> on suspend where it might skip shutting the PHY and at module unloading.
> Then update the dwmac-rk driver to switch off the PHY regulator only if we are
> not planning to wake up from the LAN.
> Finally add the PMT interrupt to the MAC device tree configuration, so we can
> wake up the core from it when the PHY has received the magic packet.

IMO these could be sent for net-next and also other glue logic
files should be reworked in order to use the new API for coherence.

Peppe

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

* Re: [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL
  2016-06-11  1:57               ` Heiko Stuebner
@ 2016-06-15 16:03                 ` Vincent Palatin
  2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  0 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 16:03 UTC (permalink / raw)
  To: Heiko Stuebner
  Cc: netdev, LKML, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Shunqian Zheng

On Fri, Jun 10, 2016 at 6:57 PM, Heiko Stuebner <heiko@sntech.de> wrote:
> Am Freitag, 10. Juni 2016, 18:00:38 schrieb Vincent Palatin:
>> When suspending the machine, do not shutdown the external PHY by cutting
>> its regulator in the mac platform driver suspend code if Wake-on-Lan is
>> enabled, else it cannot wake us up.
>> In order to do this, split the suspend/resume callbacks from the
>> init/exit callbacks, so we can condition the power-down on the lack of
>> need to wake-up from the LAN but do it unconditionally when unloading the
>> module.
>>
>> Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
>> ---
>>  drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 49
>> +++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5
>> deletions(-)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 0cd3ecf..fa05771
>> 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
>> @@ -46,6 +46,7 @@ struct rk_priv_data {
>>       struct platform_device *pdev;
>>       int phy_iface;
>>       struct regulator *regulator;
>> +     bool powered_down;
>>       const struct rk_gmac_ops *ops;
>>
>>       bool clk_enabled;
>> @@ -529,9 +530,8 @@ static struct rk_priv_data *rk_gmac_setup(struct
>> platform_device *pdev, return bsp_priv;
>>  }
>>
>> -static int rk_gmac_init(struct platform_device *pdev, void *priv)
>> +static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
>>  {
>> -     struct rk_priv_data *bsp_priv = priv;
>>       int ret;
>>
>>       ret = phy_power_on(bsp_priv, true);
>> @@ -542,15 +542,52 @@ static int rk_gmac_init(struct platform_device
>> *pdev, void *priv) if (ret)
>>               return ret;
>>
>> +     bsp_priv->powered_down = true;
>> +
>>       return 0;
>>  }
>>
>> -static void rk_gmac_exit(struct platform_device *pdev, void *priv)
>> +static void rk_gmac_powerdown(struct rk_priv_data *gmac)
>>  {
>> -     struct rk_priv_data *gmac = priv;
>> -
>>       phy_power_on(gmac, false);
>>       gmac_clk_enable(gmac, false);
>> +     gmac->powered_down = true;
>
> naming it gmac->suspended and doing all accesses in the suspend/resume
> callback might provide a nicer way? Now the check is in resume while the
> powerdown callback is setting it.
>
>> +}
>> +
>> +static int rk_gmac_init(struct platform_device *pdev, void *priv)
>> +{
>> +     struct rk_priv_data *bsp_priv = priv;
>> +
>> +     return rk_gmac_powerup(bsp_priv);
>> +}
>> +
>> +static void rk_gmac_exit(struct platform_device *pdev, void *priv)
>> +{
>> +     struct rk_priv_data *bsp_priv = priv;
>> +
>> +     rk_gmac_powerdown(bsp_priv);
>> +}
>> +
>> +static void rk_gmac_suspend(struct platform_device *pdev, void *priv)
>> +{
>> +     struct rk_priv_data *bsp_priv = priv;
>> +
>> +     /* Keep the PHY up if we use Wake-on-Lan. */
>> +     if (device_may_wakeup(&pdev->dev))
>> +             return;
>> +
>> +     rk_gmac_powerdown(bsp_priv);
>
> aka do
>         bsp_priv->suspended = true;
> here
>
>> +}
>> +
>> +static void rk_gmac_resume(struct platform_device *pdev, void *priv)
>> +{
>> +     struct rk_priv_data *bsp_priv = priv;
>> +
>> +     /* The PHY was up for Wake-on-Lan. */
>> +     if (!bsp_priv->powered_down)
>> +             return;
>> +
>> +     rk_gmac_powerup(bsp_priv);
>
> missing something like
>         bsp_priv->suspended = false;
>
> Right now it looks like your bsp_priv->powered_down will always be true
> after the first suspend with powerdown.

Yes I screw up badly, that's a good reason to use a more sensible name
for the variable.

>
>>  }
>>
>>  static void rk_fix_speed(void *priv, unsigned int speed)
>> @@ -591,6 +628,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
>> plat_dat->init = rk_gmac_init;
>>       plat_dat->exit = rk_gmac_exit;
>>       plat_dat->fix_mac_speed = rk_fix_speed;
>> +     plat_dat->suspend = rk_gmac_suspend;
>> +     plat_dat->resume = rk_gmac_resume;
>>
>>       plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
>>       if (IS_ERR(plat_dat->bsp_priv))
>> --
>> 2.8.0.rc3.226.g39d4020
>

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-13  6:46             ` Giuseppe CAVALLARO
@ 2016-06-15 17:04               ` Vincent Palatin
  2016-06-16 13:37                 ` Giuseppe CAVALLARO
  0 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 17:04 UTC (permalink / raw)
  To: Giuseppe CAVALLARO
  Cc: netdev, LKML, Andrew Lunn, Douglas Anderson, Heiko Stübner,
	Shunqian Zheng, David Miller

On Sun, Jun 12, 2016 at 11:46 PM, Giuseppe CAVALLARO
<peppe.cavallaro@st.com> wrote:
> On 6/11/2016 3:00 AM, Vincent Palatin wrote:
>>
>> In order to support Wake-On-Lan when using the RK3288 integrated MAC
>> (with an external RGMII PHY), we need to avoid shutting down the regulator
>> of the external PHY when the MAC is suspended as it's currently done in
>> the MAC
>> platform code.
>> As a first step, create independant callbacks for suspend/resume rather
>> than
>> re-using exit/init callbacks. So the dwmac platform driver can behave
>> differently
>> on suspend where it might skip shutting the PHY and at module unloading.
>> Then update the dwmac-rk driver to switch off the PHY regulator only if we
>> are
>> not planning to wake up from the LAN.
>> Finally add the PMT interrupt to the MAC device tree configuration, so we
>> can
>> wake up the core from it when the PHY has received the magic packet.
>
>
> IMO these could be sent for net-next and also other glue logic
> files should be reworked in order to use the new API for coherence.

Given they will have the same set of functions for exit/init and
suspend/resume, you mean duplicating the callbacks like this :
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -359,6 +359,8 @@ static int sti_dwmac_probe(struct platform_device *pdev)
        plat_dat->bsp_priv = dwmac;
        plat_dat->init = sti_dwmac_init;
        plat_dat->exit = sti_dwmac_exit;
+       plat_dat->suspend = sti_dwmac_exit;
+       plat_dat->resume = sti_dwmac_init;
        plat_dat->fix_mac_speed = data->fix_retime_src;

        ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);

Is this anyhow useful ?

-- 
Vincent

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

* [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-15 16:03                 ` Vincent Palatin
@ 2016-06-15 18:32                   ` Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
                                       ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 18:32 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

In order to support Wake-On-Lan when using the RK3288 integrated MAC
(with an external RGMII PHY), we need to avoid shutting down the regulator
of the external PHY when the MAC is suspended as it's currently done in the MAC
platform code.
As a first step, create independant callbacks for suspend/resume rather than
re-using exit/init callbacks. So the dwmac platform driver can behave differently
on suspend where it might skip shutting the PHY and at module unloading.
Then update the dwmac-rk driver to switch off the PHY regulator only if we are
not planning to wake up from the LAN.
Finally add the PMT interrupt to the MAC device tree configuration, so we can
wake up the core from it when the PHY has received the magic packet.

Changes since v1:
  * rename 'powered_down' variable into 'suspended'.
  * fix the logic recording the PHY suspended state according to Heiko comments.

Vincent Palatin (3):
  net: stmmac: allow to split suspend/resume from init/exit callbacks
  net: stmmac: dwmac-rk: keep the PHY up for WoL
  ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288

 arch/arm/boot/dts/rk3288.dtsi                      |  5 ++-
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c     | 48 +++++++++++++++++++---
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |  8 +++-
 include/linux/stmmac.h                             |  2 +
 4 files changed, 54 insertions(+), 9 deletions(-)

-- 
2.8.0.rc3.226.g39d4020

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

* [PATCH v2 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks
  2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
@ 2016-06-15 18:32                     ` Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
                                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 18:32 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

Let the stmmac platform drivers provide dedicated suspend and resume
callbacks rather than always re-using the init and exits callbacks.
If the driver does not provide the suspend or resume callback, we fall
back to the old behavior trying to use exit or init.

This allows a specific platform to perform only a partial power-down on
suspend if Wake-on-Lan is enabled but always perform the full shutdown
sequence if the module is unloaded.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 8 ++++++--
 include/linux/stmmac.h                                | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 409db91..a96714d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -411,7 +411,9 @@ static int stmmac_pltfr_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 
 	ret = stmmac_suspend(dev);
-	if (priv->plat->exit)
+	if (priv->plat->suspend)
+		priv->plat->suspend(pdev, priv->plat->bsp_priv);
+	else if (priv->plat->exit)
 		priv->plat->exit(pdev, priv->plat->bsp_priv);
 
 	return ret;
@@ -430,7 +432,9 @@ static int stmmac_pltfr_resume(struct device *dev)
 	struct stmmac_priv *priv = netdev_priv(ndev);
 	struct platform_device *pdev = to_platform_device(dev);
 
-	if (priv->plat->init)
+	if (priv->plat->resume)
+		priv->plat->resume(pdev, priv->plat->bsp_priv);
+	else if (priv->plat->init)
 		priv->plat->init(pdev, priv->plat->bsp_priv);
 
 	return stmmac_resume(dev);
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index ffdaca9..0507dbf 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -135,6 +135,8 @@ struct plat_stmmacenet_data {
 	void (*bus_setup)(void __iomem *ioaddr);
 	int (*init)(struct platform_device *pdev, void *priv);
 	void (*exit)(struct platform_device *pdev, void *priv);
+	void (*suspend)(struct platform_device *pdev, void *priv);
+	void (*resume)(struct platform_device *pdev, void *priv);
 	void *bsp_priv;
 	struct stmmac_axi *axi;
 	int has_gmac4;
-- 
2.8.0.rc3.226.g39d4020

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

* [PATCH v2 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL
  2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
@ 2016-06-15 18:32                     ` Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 3/3] ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288 Vincent Palatin
  2016-06-16 21:15                     ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes " David Miller
  3 siblings, 0 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 18:32 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

When suspending the machine, do not shutdown the external PHY by cutting
its regulator in the mac platform driver suspend code if Wake-on-Lan is enabled,
else it cannot wake us up.
In order to do this, split the suspend/resume callbacks from the
init/exit callbacks, so we can condition the power-down on the lack of
need to wake-up from the LAN but do it unconditionally when unloading the
module.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 48 +++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 0cd3ecf..63c2e4f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -46,6 +46,7 @@ struct rk_priv_data {
 	struct platform_device *pdev;
 	int phy_iface;
 	struct regulator *regulator;
+	bool suspended;
 	const struct rk_gmac_ops *ops;
 
 	bool clk_enabled;
@@ -529,9 +530,8 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
 	return bsp_priv;
 }
 
-static int rk_gmac_init(struct platform_device *pdev, void *priv)
+static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
 {
-	struct rk_priv_data *bsp_priv = priv;
 	int ret;
 
 	ret = phy_power_on(bsp_priv, true);
@@ -545,14 +545,50 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
 	return 0;
 }
 
-static void rk_gmac_exit(struct platform_device *pdev, void *priv)
+static void rk_gmac_powerdown(struct rk_priv_data *gmac)
 {
-	struct rk_priv_data *gmac = priv;
-
 	phy_power_on(gmac, false);
 	gmac_clk_enable(gmac, false);
 }
 
+static int rk_gmac_init(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	return rk_gmac_powerup(bsp_priv);
+}
+
+static void rk_gmac_exit(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	rk_gmac_powerdown(bsp_priv);
+}
+
+static void rk_gmac_suspend(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	/* Keep the PHY up if we use Wake-on-Lan. */
+	if (device_may_wakeup(&pdev->dev))
+		return;
+
+	rk_gmac_powerdown(bsp_priv);
+	bsp_priv->suspended = true;
+}
+
+static void rk_gmac_resume(struct platform_device *pdev, void *priv)
+{
+	struct rk_priv_data *bsp_priv = priv;
+
+	/* The PHY was up for Wake-on-Lan. */
+	if (!bsp_priv->suspended)
+		return;
+
+	rk_gmac_powerup(bsp_priv);
+	bsp_priv->suspended = false;
+}
+
 static void rk_fix_speed(void *priv, unsigned int speed)
 {
 	struct rk_priv_data *bsp_priv = priv;
@@ -591,6 +627,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	plat_dat->init = rk_gmac_init;
 	plat_dat->exit = rk_gmac_exit;
 	plat_dat->fix_mac_speed = rk_fix_speed;
+	plat_dat->suspend = rk_gmac_suspend;
+	plat_dat->resume = rk_gmac_resume;
 
 	plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
 	if (IS_ERR(plat_dat->bsp_priv))
-- 
2.8.0.rc3.226.g39d4020

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

* [PATCH v2 3/3] ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288
  2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
  2016-06-15 18:32                     ` [PATCH v2 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
@ 2016-06-15 18:32                     ` Vincent Palatin
  2016-06-16 21:15                     ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes " David Miller
  3 siblings, 0 replies; 26+ messages in thread
From: Vincent Palatin @ 2016-06-15 18:32 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Andrew Lunn, Douglas Anderson, Giuseppe Cavallaro,
	Heiko Stübner, Shunqian Zheng, Vincent Palatin

In order to use Wake-on-Lan on RK3288 integrated MAC, we need to wake-up
the CPU on the PMT interrupt when the MAC and the PHY are in low power mode.
Adding the interrupt declaration.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
 arch/arm/boot/dts/rk3288.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 3b44ef3..3ebee53 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -539,8 +539,9 @@
 	gmac: ethernet@ff290000 {
 		compatible = "rockchip,rk3288-gmac";
 		reg = <0xff290000 0x10000>;
-		interrupts = <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>;
-		interrupt-names = "macirq";
+		interrupts = <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>,
+				<GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "macirq", "eth_wake_irq";
 		rockchip,grf = <&grf>;
 		clocks = <&cru SCLK_MAC>,
 			<&cru SCLK_MAC_RX>, <&cru SCLK_MAC_TX>,
-- 
2.8.0.rc3.226.g39d4020

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-15 17:04               ` Vincent Palatin
@ 2016-06-16 13:37                 ` Giuseppe CAVALLARO
  2016-06-16 14:51                   ` Vincent Palatin
  0 siblings, 1 reply; 26+ messages in thread
From: Giuseppe CAVALLARO @ 2016-06-16 13:37 UTC (permalink / raw)
  To: Vincent Palatin
  Cc: netdev, LKML, Andrew Lunn, Douglas Anderson, Heiko Stübner,
	Shunqian Zheng, David Miller

Hi Vincent

On 6/15/2016 7:04 PM, Vincent Palatin wrote:
> On Sun, Jun 12, 2016 at 11:46 PM, Giuseppe CAVALLARO
> <peppe.cavallaro@st.com> wrote:
>> On 6/11/2016 3:00 AM, Vincent Palatin wrote:
>>>
>>> In order to support Wake-On-Lan when using the RK3288 integrated MAC
>>> (with an external RGMII PHY), we need to avoid shutting down the regulator
>>> of the external PHY when the MAC is suspended as it's currently done in
>>> the MAC
>>> platform code.
>>> As a first step, create independant callbacks for suspend/resume rather
>>> than
>>> re-using exit/init callbacks. So the dwmac platform driver can behave
>>> differently
>>> on suspend where it might skip shutting the PHY and at module unloading.
>>> Then update the dwmac-rk driver to switch off the PHY regulator only if we
>>> are
>>> not planning to wake up from the LAN.
>>> Finally add the PMT interrupt to the MAC device tree configuration, so we
>>> can
>>> wake up the core from it when the PHY has received the magic packet.
>>
>>
>> IMO these could be sent for net-next and also other glue logic
>> files should be reworked in order to use the new API for coherence.
>
> Given they will have the same set of functions for exit/init and
> suspend/resume, you mean duplicating the callbacks like this :
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
> @@ -359,6 +359,8 @@ static int sti_dwmac_probe(struct platform_device *pdev)
>         plat_dat->bsp_priv = dwmac;
>         plat_dat->init = sti_dwmac_init;
>         plat_dat->exit = sti_dwmac_exit;
> +       plat_dat->suspend = sti_dwmac_exit;
> +       plat_dat->resume = sti_dwmac_init;
>         plat_dat->fix_mac_speed = data->fix_retime_src;
>
>         ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
>
> Is this anyhow useful ?

I think this is mandatory otherwise you are not guaranteeing the PM
stuff working on the rest of the glue-logics (not only sti); because
init/exit calls won't be called anymore. So I kindly ask you to
propagate the fix and send the V3.  The implementation above is ok for
me.

peppe

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-16 13:37                 ` Giuseppe CAVALLARO
@ 2016-06-16 14:51                   ` Vincent Palatin
  2016-06-17  5:38                     ` Giuseppe CAVALLARO
  0 siblings, 1 reply; 26+ messages in thread
From: Vincent Palatin @ 2016-06-16 14:51 UTC (permalink / raw)
  To: Giuseppe CAVALLARO
  Cc: netdev, LKML, Andrew Lunn, Douglas Anderson, Heiko Stübner,
	Shunqian Zheng, David Miller

Hi Giuseppe,

On Thu, Jun 16, 2016 at 6:37 AM, Giuseppe CAVALLARO
<peppe.cavallaro@st.com> wrote:
>
> Hi Vincent
>
>
> On 6/15/2016 7:04 PM, Vincent Palatin wrote:
>>
>> On Sun, Jun 12, 2016 at 11:46 PM, Giuseppe CAVALLARO
>> <peppe.cavallaro@st.com> wrote:
>>>
>>> On 6/11/2016 3:00 AM, Vincent Palatin wrote:
>>>>
>>>>
>>>> In order to support Wake-On-Lan when using the RK3288 integrated MAC
>>>> (with an external RGMII PHY), we need to avoid shutting down the regulator
>>>> of the external PHY when the MAC is suspended as it's currently done in
>>>> the MAC
>>>> platform code.
>>>> As a first step, create independant callbacks for suspend/resume rather
>>>> than
>>>> re-using exit/init callbacks. So the dwmac platform driver can behave
>>>> differently
>>>> on suspend where it might skip shutting the PHY and at module unloading.
>>>> Then update the dwmac-rk driver to switch off the PHY regulator only if we
>>>> are
>>>> not planning to wake up from the LAN.
>>>> Finally add the PMT interrupt to the MAC device tree configuration, so we
>>>> can
>>>> wake up the core from it when the PHY has received the magic packet.
>>>
>>>
>>>
>>> IMO these could be sent for net-next and also other glue logic
>>> files should be reworked in order to use the new API for coherence.
>>
>>
>> Given they will have the same set of functions for exit/init and
>> suspend/resume, you mean duplicating the callbacks like this :
>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
>> @@ -359,6 +359,8 @@ static int sti_dwmac_probe(struct platform_device *pdev)
>>         plat_dat->bsp_priv = dwmac;
>>         plat_dat->init = sti_dwmac_init;
>>         plat_dat->exit = sti_dwmac_exit;
>> +       plat_dat->suspend = sti_dwmac_exit;
>> +       plat_dat->resume = sti_dwmac_init;
>>         plat_dat->fix_mac_speed = data->fix_retime_src;
>>
>>         ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
>>
>> Is this anyhow useful ?
>
>
> I think this is mandatory otherwise you are not guaranteeing the PM
> stuff working on the rest of the glue-logics (not only sti); because
> init/exit calls won't be called anymore.


As mentioned in the PATCH 1/3 description: "If the driver does not
provide the suspend or resume callback, we fall
back to the old behavior trying to use exit or init. [...]"
ie.
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -411,7 +411,9 @@ static int stmmac_pltfr_suspend(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);

        ret = stmmac_suspend(dev);
-       if (priv->plat->exit)
+       if (priv->plat->suspend)
+               priv->plat->suspend(pdev, priv->plat->bsp_priv);
+       else if (priv->plat->exit)
                priv->plat->exit(pdev, priv->plat->bsp_priv);

        return ret;
@@ -430,7 +432,9 @@ static int stmmac_pltfr_resume(struct device *dev)
        struct stmmac_priv *priv = netdev_priv(ndev);
        struct platform_device *pdev = to_platform_device(dev);

-       if (priv->plat->init)
+       if (priv->plat->resume)
+               priv->plat->resume(pdev, priv->plat->bsp_priv);
+       else if (priv->plat->init)
                priv->plat->init(pdev, priv->plat->bsp_priv);

        return stmmac_resume(dev);

So I was under the impression that everything should continue working
as before for drivers only providing init/exit,
by falling back on calling ->exit() if there is no suspend() callback
initialized for the PM calls.
You think that won't work ?

>
> So I kindly ask you to
> propagate the fix and send the V3.  The implementation above is ok for
> me.
>
> peppe
>

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

* Re: [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
                                       ` (2 preceding siblings ...)
  2016-06-15 18:32                     ` [PATCH v2 3/3] ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288 Vincent Palatin
@ 2016-06-16 21:15                     ` David Miller
  3 siblings, 0 replies; 26+ messages in thread
From: David Miller @ 2016-06-16 21:15 UTC (permalink / raw)
  To: vpalatin
  Cc: netdev, linux-kernel, andrew, dianders, peppe.cavallaro, heiko, zhengsq

From: Vincent Palatin <vpalatin@chromium.org>
Date: Wed, 15 Jun 2016 11:32:20 -0700

> In order to support Wake-On-Lan when using the RK3288 integrated MAC
> (with an external RGMII PHY), we need to avoid shutting down the regulator
> of the external PHY when the MAC is suspended as it's currently done in the MAC
> platform code.
> As a first step, create independant callbacks for suspend/resume rather than
> re-using exit/init callbacks. So the dwmac platform driver can behave differently
> on suspend where it might skip shutting the PHY and at module unloading.
> Then update the dwmac-rk driver to switch off the PHY regulator only if we are
> not planning to wake up from the LAN.
> Finally add the PMT interrupt to the MAC device tree configuration, so we can
> wake up the core from it when the PHY has received the magic packet.
> 
> Changes since v1:
>   * rename 'powered_down' variable into 'suspended'.
>   * fix the logic recording the PHY suspended state according to Heiko comments.

Series applied to net-next, thanks.

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

* Re: net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288
  2016-06-16 14:51                   ` Vincent Palatin
@ 2016-06-17  5:38                     ` Giuseppe CAVALLARO
  0 siblings, 0 replies; 26+ messages in thread
From: Giuseppe CAVALLARO @ 2016-06-17  5:38 UTC (permalink / raw)
  To: Vincent Palatin
  Cc: netdev, LKML, Andrew Lunn, Douglas Anderson, Heiko Stübner,
	Shunqian Zheng, David Miller

On 6/16/2016 4:51 PM, Vincent Palatin wrote:
> Hi Giuseppe,
>
> On Thu, Jun 16, 2016 at 6:37 AM, Giuseppe CAVALLARO
> <peppe.cavallaro@st.com> wrote:
>>
>> Hi Vincent
>>
>>
>> On 6/15/2016 7:04 PM, Vincent Palatin wrote:
>>>
>>> On Sun, Jun 12, 2016 at 11:46 PM, Giuseppe CAVALLARO
>>> <peppe.cavallaro@st.com> wrote:
>>>>
>>>> On 6/11/2016 3:00 AM, Vincent Palatin wrote:
>>>>>
>>>>>
>>>>> In order to support Wake-On-Lan when using the RK3288 integrated MAC
>>>>> (with an external RGMII PHY), we need to avoid shutting down the regulator
>>>>> of the external PHY when the MAC is suspended as it's currently done in
>>>>> the MAC
>>>>> platform code.
>>>>> As a first step, create independant callbacks for suspend/resume rather
>>>>> than
>>>>> re-using exit/init callbacks. So the dwmac platform driver can behave
>>>>> differently
>>>>> on suspend where it might skip shutting the PHY and at module unloading.
>>>>> Then update the dwmac-rk driver to switch off the PHY regulator only if we
>>>>> are
>>>>> not planning to wake up from the LAN.
>>>>> Finally add the PMT interrupt to the MAC device tree configuration, so we
>>>>> can
>>>>> wake up the core from it when the PHY has received the magic packet.
>>>>
>>>>
>>>>
>>>> IMO these could be sent for net-next and also other glue logic
>>>> files should be reworked in order to use the new API for coherence.
>>>
>>>
>>> Given they will have the same set of functions for exit/init and
>>> suspend/resume, you mean duplicating the callbacks like this :
>>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
>>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
>>> @@ -359,6 +359,8 @@ static int sti_dwmac_probe(struct platform_device *pdev)
>>>         plat_dat->bsp_priv = dwmac;
>>>         plat_dat->init = sti_dwmac_init;
>>>         plat_dat->exit = sti_dwmac_exit;
>>> +       plat_dat->suspend = sti_dwmac_exit;
>>> +       plat_dat->resume = sti_dwmac_init;
>>>         plat_dat->fix_mac_speed = data->fix_retime_src;
>>>
>>>         ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
>>>
>>> Is this anyhow useful ?
>>
>>
>> I think this is mandatory otherwise you are not guaranteeing the PM
>> stuff working on the rest of the glue-logics (not only sti); because
>> init/exit calls won't be called anymore.
>
>
> As mentioned in the PATCH 1/3 description: "If the driver does not
> provide the suspend or resume callback, we fall
> back to the old behavior trying to use exit or init. [...]"
> ie.
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -411,7 +411,9 @@ static int stmmac_pltfr_suspend(struct device *dev)
>         struct platform_device *pdev = to_platform_device(dev);
>
>         ret = stmmac_suspend(dev);
> -       if (priv->plat->exit)
> +       if (priv->plat->suspend)
> +               priv->plat->suspend(pdev, priv->plat->bsp_priv);
> +       else if (priv->plat->exit)
>                 priv->plat->exit(pdev, priv->plat->bsp_priv);
>
>         return ret;
> @@ -430,7 +432,9 @@ static int stmmac_pltfr_resume(struct device *dev)
>         struct stmmac_priv *priv = netdev_priv(ndev);
>         struct platform_device *pdev = to_platform_device(dev);
>
> -       if (priv->plat->init)
> +       if (priv->plat->resume)
> +               priv->plat->resume(pdev, priv->plat->bsp_priv);
> +       else if (priv->plat->init)
>                 priv->plat->init(pdev, priv->plat->bsp_priv);
>
>         return stmmac_resume(dev);
>
> So I was under the impression that everything should continue working
> as before for drivers only providing init/exit,
> by falling back on calling ->exit() if there is no suspend() callback
> initialized for the PM calls.
> You think that won't work ?

it's ok for me.

Peppe

>
>>
>> So I kindly ask you to
>> propagate the fix and send the V3.  The implementation above is ok for
>> me.
>>
>> peppe
>>
>

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

end of thread, other threads:[~2016-06-17  5:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 17:29 [PATCH] net: stmmac: dwmac-rk: keep PHY up for WoL Vincent Palatin
2016-06-06 20:45 ` Heiko Stübner
2016-06-06 21:00   ` Vincent Palatin
2016-06-07  7:23 ` Giuseppe CAVALLARO
2016-06-08 22:25   ` Vincent Palatin
2016-06-09  0:17     ` Andrew Lunn
2016-06-09 23:00       ` Vincent Palatin
2016-06-10 12:29         ` Giuseppe CAVALLARO
2016-06-11  1:00           ` net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
2016-06-11  1:00             ` [PATCH 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
2016-06-11  1:16               ` David Miller
2016-06-11  1:00             ` [PATCH 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
2016-06-11  1:57               ` Heiko Stuebner
2016-06-15 16:03                 ` Vincent Palatin
2016-06-15 18:32                   ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes for Wake-on-Lan on RK3288 Vincent Palatin
2016-06-15 18:32                     ` [PATCH v2 1/3] net: stmmac: allow to split suspend/resume from init/exit callbacks Vincent Palatin
2016-06-15 18:32                     ` [PATCH v2 2/3] net: stmmac: dwmac-rk: keep the PHY up for WoL Vincent Palatin
2016-06-15 18:32                     ` [PATCH v2 3/3] ARM: dts: rockchip: add interrupt for Wake-on-Lan on RK3288 Vincent Palatin
2016-06-16 21:15                     ` [PATCH v2 0/3] net: stmmac: dwmac-rk: fixes " David Miller
2016-06-11  1:00             ` [PATCH 3/3] ARM: dts: rockchip: add interrupt " Vincent Palatin
2016-06-11  1:16             ` net: stmmac: dwmac-rk: fixes " David Miller
2016-06-13  6:46             ` Giuseppe CAVALLARO
2016-06-15 17:04               ` Vincent Palatin
2016-06-16 13:37                 ` Giuseppe CAVALLARO
2016-06-16 14:51                   ` Vincent Palatin
2016-06-17  5:38                     ` Giuseppe CAVALLARO

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).