net: phy: realtek: Add support for WOL magic packet on RTL8211F
Subsystems (3)
PATCH v2 1/1 net: phy: realtek: Add support for WOL magic packet on RTL8211F
The RTL8211F supports multiple WOL modes. This patch adds support for magic packets.
The PHY notifies the system via the INTB/PMEB pin when a WOL event occurs.
---
Changes in v2:
- Read current WOL configuration from PHY
- Replace magic numbers with defines
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/net/phy/realtek/realtek_main.c | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
drivers/net/phy/realtek/realtek_main.c +69 -0
@@ -10,6 +10,7 @@#include <linux/bitops.h> #include <linux/of.h> #include <linux/phy.h> +#include <linux/netdevice.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/clk.h>
@@ -38,6 +39,24 @@#define RTL8211F_INSR 0x1d +/* RTL8211F WOL interrupt configuration */ +#define RTL8211F_INTBCR_PAGE 0xd40 +#define RTL8211F_INTBCR 0x16 +#define RTL8211F_INTBCR_INTB_PMEB BIT(5) + +/* RTL8211F WOL settings */ +#define RTL8211F_WOL_SETTINGS_PAGE 0xd8a +#define RTL8211F_WOL_SETTINGS_EVENTS 16 +#define RTL8211F_WOL_EVENT_MAGIC BIT(12) +#define RTL8211F_WOL_SETTINGS_STATUS 17 +#define RTL8211F_WOL_STATUS_RESET (BIT(15) | 0x1fff) + +/* RTL8211F Unique phyiscal and multicast address (WOL) */ +#define RTL8211F_PHYSICAL_ADDR_PAGE 0xd8c +#define RTL8211F_PHYSICAL_ADDR_WORD0 16 +#define RTL8211F_PHYSICAL_ADDR_WORD1 17 +#define RTL8211F_PHYSICAL_ADDR_WORD2 18 +#define RTL8211F_LEDCR 0x10#define RTL8211F_LEDCR_MODE BIT(15)#define RTL8211F_LEDCR_ACT_TXRX BIT(4)
@@ -123,6 +142,7 @@ struct rtl821x_priv {u16 phycr2;bool has_phycr2;struct clk *clk; +u32 saved_wolopts; };static int rtl821x_read_page (struct phy_device *phydev)
@@ -354,6 +374,53 @@ static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev)return IRQ_HANDLED ; } +static void rtl8211f_get_wol (struct phy_device *dev,struct ethtool_wolinfo *wol) +{ + wol->supported =WAKE_MAGIC ; +if (phy_read_paged (dev,RTL8211F_WOL_SETTINGS_PAGE ,RTL8211F_WOL_SETTINGS_EVENTS ) + &RTL8211F_WOL_EVENT_MAGIC ) + wol->wolopts =WAKE_MAGIC ; +} + +static int rtl8211f_set_wol (struct phy_device *dev,struct ethtool_wolinfo *wol) +{ +const u8 *mac_addr = dev->attached_dev->dev_addr; +int oldpage; + + oldpage =phy_save_page (dev); +if (oldpage <0 ) + goto err; + +if (wol->wolopts &WAKE_MAGIC ) { +/* Store the device address for the magic packet */ +rtl821x_write_page (dev,RTL8211F_PHYSICAL_ADDR_PAGE ); +__phy_write (dev,RTL8211F_PHYSICAL_ADDR_WORD0 , mac_addr[1 ] <<8 | (mac_addr[0 ])); +__phy_write (dev,RTL8211F_PHYSICAL_ADDR_WORD1 , mac_addr[3 ] <<8 | (mac_addr[2 ])); +__phy_write (dev,RTL8211F_PHYSICAL_ADDR_WORD2 , mac_addr[5 ] <<8 | (mac_addr[4 ])); + +/* Enable magic packet matching and reset WOL status */ +rtl821x_write_page (dev,RTL8211F_WOL_SETTINGS_PAGE ); +__phy_write (dev,RTL8211F_WOL_SETTINGS_EVENTS ,RTL8211F_WOL_EVENT_MAGIC ); +__phy_write (dev,RTL8211F_WOL_SETTINGS_STATUS ,RTL8211F_WOL_STATUS_RESET ); + +/* Enable the WOL interrupt */ +rtl821x_write_page (dev,RTL8211F_INTBCR_PAGE ); +__phy_set_bits (dev,RTL8211F_INTBCR ,RTL8211F_INTBCR_INTB_PMEB ); + }else { +/* Disable the WOL interrupt */ +rtl821x_write_page (dev,RTL8211F_INTBCR_PAGE ); +__phy_clear_bits (dev,RTL8211F_INTBCR ,RTL8211F_INTBCR_INTB_PMEB ); + +/* Disable magic packet matching and reset WOL status */ +rtl821x_write_page (dev,RTL8211F_WOL_SETTINGS_PAGE ); +__phy_write (dev,RTL8211F_WOL_SETTINGS_EVENTS ,0 ); +__phy_write (dev,RTL8211F_WOL_SETTINGS_STATUS ,RTL8211F_WOL_STATUS_RESET ); + } + +err: +return phy_restore_page (dev, oldpage,0 ); +} +static int rtl8211_config_aneg (struct phy_device *phydev) {int ret;
@@ -1400,6 +1467,8 @@ static struct phy_driver realtek_drvs[] = { .read_status = rtlgen_read_status, .config_intr = &rtl8211f_config_intr, .handle_interrupt = rtl8211f_handle_interrupt, + .set_wol = rtl8211f_set_wol, + .get_wol = rtl8211f_get_wol, .suspend = rtl821x_suspend, .resume = rtl821x_resume, .read_page = rtl821x_read_page,
---
base-commit: 4acf6d4f6afc3478753e49c495132619667549d9
change-id: 20250425-realtek_wol-6e2df8ea8cf2
Best regards,
Signature · 1 line
Daniel Braunwarth <[email protected]>
Quoted 9 lines · On Tue, Apr 29, 2025 at 01:33:37PM +0200, Daniel Braunwarth via B4 Relay wrote:
From: Daniel Braunwarth <[email protected]>
The RTL8211F supports multiple WOL modes. This patch adds support for magic packets.
The PHY notifies the system via the INTB/PMEB pin when a WOL event occurs.
Signed-off-by Daniel Braunwarth <[email protected]>
Andrew
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 29 Apr 2025 13:33:37 +0200 you wrote:
From: Daniel Braunwarth <[email protected]>
The RTL8211F supports multiple WOL modes. This patch adds support for magic packets.
The PHY notifies the system via the INTB/PMEB pin when a WOL event occurs.
[...]
Here is the summary with links:
- [net-next,v2] net: phy: realtek: Add support for WOL magic packet on RTL8211F
https://git.kernel.org/netdev/net-next/c/7840e4d6f48a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Hi Daniel,
Quoted 64 lines · On 29/04/2025 12:33, Daniel Braunwarth via B4 Relay wrote:
From: Daniel Braunwarth <[email protected]>
The RTL8211F supports multiple WOL modes. This patch adds support for magic packets.
The PHY notifies the system via the INTB/PMEB pin when a WOL event occurs.
Signed-off-by Daniel Braunwarth <[email protected]>---
Changes in v2:
- Read current WOL configuration from PHY
- Replace magic numbers with defines
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/net/phy/realtek/realtek_main.c | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)drivers/net/phy/realtek/realtek_main.c +20
-0@@ -10,6 +10,7 @@#include <linux/bitops.h> #include <linux/of.h> #include <linux/phy.h> +#include <linux/netdevice.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/clk.h> @@ -38,6 +39,24 @@#define RTL8211F_INSR 0x1d +/* RTL8211F WOL interrupt configuration */ +#define RTL8211F_INTBCR_PAGE 0xd40 +#define RTL8211F_INTBCR 0x16 +#define RTL8211F_INTBCR_INTB_PMEB BIT(5) + +/* RTL8211F WOL settings */ +#define RTL8211F_WOL_SETTINGS_PAGE 0xd8a +#define RTL8211F_WOL_SETTINGS_EVENTS 16 +#define RTL8211F_WOL_EVENT_MAGIC BIT(12) +#define RTL8211F_WOL_SETTINGS_STATUS 17 +#define RTL8211F_WOL_STATUS_RESET (BIT(15) | 0x1fff) + +/* RTL8211F Unique phyiscal and multicast address (WOL) */ +#define RTL8211F_PHYSICAL_ADDR_PAGE 0xd8c +#define RTL8211F_PHYSICAL_ADDR_WORD0 16 +#define RTL8211F_PHYSICAL_ADDR_WORD1 17 +#define RTL8211F_PHYSICAL_ADDR_WORD2 18 +#define RTL8211F_LEDCR 0x10#define RTL8211F_LEDCR_MODE BIT(15)#define RTL8211F_LEDCR_ACT_TXRX BIT(4)@@ -123,6 +142,7 @@ struct rtl821x_priv {u16 phycr2;bool has_phycr2;struct clk *clk; +u32 saved_wolopts; };static int rtl821x_read_page (struct phy_device *phydev)
drivers/net/phy/realtek/realtek_main.c static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev) · line 381
Quoted 8 lines
drivers/net/phy/realtek/realtek_main.c +5
-0@@ -354,6 +374,53 @@ static irqreturn_t rtl8211f_handle_interrupt(struct phy_device *phydev)return IRQ_HANDLED ; } +static void rtl8211f_get_wol (struct phy_device *dev,struct ethtool_wolinfo *wol) +{ + wol->supported =WAKE_MAGIC ; +if (phy_read_paged (dev,RTL8211F_WOL_SETTINGS_PAGE ,RTL8211F_WOL_SETTINGS_EVENTS ) + &RTL8211F_WOL_EVENT_MAGIC )
Given that phy_read_paged() can return an error, should we not check the value return is greater than 0 before ANDing with RTL8211F_WOL_EVENT_MAGIC?
Thanks
Jon
Signature · 1 line
nvpublic