diff mbox series

[net-next,1/1] net: phy: marvell: Add WAKE_PHY support to WOL event

Message ID 20210813084508.182333-1-yoong.siang.song@intel.com (mailing list archive)
State Accepted
Commit 6164659ff7acc16f3f37a9278f856fd1fb02a8f9
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/1] net: phy: marvell: Add WAKE_PHY support to WOL event | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 75 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Song Yoong Siang Aug. 13, 2021, 8:45 a.m. UTC
Add Wake-on-PHY feature support by enabling the Link Up Event.

Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>
---
 drivers/net/phy/marvell.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

Comments

Andrew Lunn Aug. 14, 2021, 4:07 p.m. UTC | #1
On Fri, Aug 13, 2021 at 04:45:08PM +0800, Song Yoong Siang wrote:
> Add Wake-on-PHY feature support by enabling the Link Up Event.
> 
> Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
patchwork-bot+netdevbpf@kernel.org Aug. 16, 2021, 10:10 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Fri, 13 Aug 2021 16:45:08 +0800 you wrote:
> Add Wake-on-PHY feature support by enabling the Link Up Event.
> 
> Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>
> ---
>  drivers/net/phy/marvell.c | 39 ++++++++++++++++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 3 deletions(-)

Here is the summary with links:
  - [net-next,1/1] net: phy: marvell: Add WAKE_PHY support to WOL event
    https://git.kernel.org/netdev/net-next/c/6164659ff7ac

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Russell King (Oracle) Aug. 16, 2021, 10:10 a.m. UTC | #3
On Fri, Aug 13, 2021 at 04:45:08PM +0800, Song Yoong Siang wrote:
> Add Wake-on-PHY feature support by enabling the Link Up Event.
> 
> Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>

Hi,

I think this can be greatly simplified - see below.

> ---
>  drivers/net/phy/marvell.c | 39 ++++++++++++++++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
> index 3de93c9f2744..415e2a01c151 100644
> --- a/drivers/net/phy/marvell.c
> +++ b/drivers/net/phy/marvell.c
> @@ -155,6 +155,7 @@
>  
>  #define MII_88E1318S_PHY_WOL_CTRL				0x10
>  #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS		BIT(12)
> +#define MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE		BIT(13)
>  #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE	BIT(14)
>  
>  #define MII_PHY_LED_CTRL	        16
> @@ -1746,13 +1747,19 @@ static void m88e1318_get_wol(struct phy_device *phydev,
>  {
>  	int ret;
>  
> -	wol->supported = WAKE_MAGIC;
> +	wol->supported = WAKE_MAGIC | WAKE_PHY;
>  	wol->wolopts = 0;
>  
>  	ret = phy_read_paged(phydev, MII_MARVELL_WOL_PAGE,
>  			     MII_88E1318S_PHY_WOL_CTRL);
> -	if (ret >= 0 && ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
> +	if (ret < 0)
> +		return;
> +
> +	if (ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
>  		wol->wolopts |= WAKE_MAGIC;
> +
> +	if (ret & MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE)
> +		wol->wolopts |= WAKE_PHY;
>  }
>  
>  static int m88e1318_set_wol(struct phy_device *phydev,
> @@ -1764,7 +1771,7 @@ static int m88e1318_set_wol(struct phy_device *phydev,
>  	if (oldpage < 0)
>  		goto error;
>  
> -	if (wol->wolopts & WAKE_MAGIC) {
> +	if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) {
>  		/* Explicitly switch to page 0x00, just to be sure */
>  		err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE);
>  		if (err < 0)
> @@ -1796,7 +1803,9 @@ static int m88e1318_set_wol(struct phy_device *phydev,
>  				   MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW);
>  		if (err < 0)
>  			goto error;
> +	}

Wouldn't it make more sense to always select the WOL page at this point
between these two blocks? From what I can see, the WOL page is selected
by both true and false blocks of the next if() statement, and again by
the newly added if() statement for WAKE_PHY.

Other than that, I don't see any issues.
diff mbox series

Patch

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 3de93c9f2744..415e2a01c151 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -155,6 +155,7 @@ 
 
 #define MII_88E1318S_PHY_WOL_CTRL				0x10
 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS		BIT(12)
+#define MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE		BIT(13)
 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE	BIT(14)
 
 #define MII_PHY_LED_CTRL	        16
@@ -1746,13 +1747,19 @@  static void m88e1318_get_wol(struct phy_device *phydev,
 {
 	int ret;
 
-	wol->supported = WAKE_MAGIC;
+	wol->supported = WAKE_MAGIC | WAKE_PHY;
 	wol->wolopts = 0;
 
 	ret = phy_read_paged(phydev, MII_MARVELL_WOL_PAGE,
 			     MII_88E1318S_PHY_WOL_CTRL);
-	if (ret >= 0 && ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
+	if (ret < 0)
+		return;
+
+	if (ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE)
 		wol->wolopts |= WAKE_MAGIC;
+
+	if (ret & MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE)
+		wol->wolopts |= WAKE_PHY;
 }
 
 static int m88e1318_set_wol(struct phy_device *phydev,
@@ -1764,7 +1771,7 @@  static int m88e1318_set_wol(struct phy_device *phydev,
 	if (oldpage < 0)
 		goto error;
 
-	if (wol->wolopts & WAKE_MAGIC) {
+	if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) {
 		/* Explicitly switch to page 0x00, just to be sure */
 		err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE);
 		if (err < 0)
@@ -1796,7 +1803,9 @@  static int m88e1318_set_wol(struct phy_device *phydev,
 				   MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW);
 		if (err < 0)
 			goto error;
+	}
 
+	if (wol->wolopts & WAKE_MAGIC) {
 		err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
 		if (err < 0)
 			goto error;
@@ -1837,6 +1846,30 @@  static int m88e1318_set_wol(struct phy_device *phydev,
 			goto error;
 	}
 
+	if (wol->wolopts & WAKE_PHY) {
+		err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
+		if (err < 0)
+			goto error;
+
+		/* Clear WOL status and enable link up event */
+		err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 0,
+				   MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS |
+				   MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE);
+		if (err < 0)
+			goto error;
+	} else {
+		err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE);
+		if (err < 0)
+			goto error;
+
+		/* Clear WOL status and disable link up event */
+		err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL,
+				   MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE,
+				   MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS);
+		if (err < 0)
+			goto error;
+	}
+
 error:
 	return phy_restore_page(phydev, oldpage, err);
 }