Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Signed-off-by: Daniel Braunwarth <daniel.braunwarth@kuka.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20250429-realtek_wol-v2-1-8f84def1ef2c@kuka.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Daniel Braunwarth and committed by
Jakub Kicinski
7840e4d6 c76bab22

+69
+69
drivers/net/phy/realtek/realtek_main.c
··· 10 10 #include <linux/bitops.h> 11 11 #include <linux/of.h> 12 12 #include <linux/phy.h> 13 + #include <linux/netdevice.h> 13 14 #include <linux/module.h> 14 15 #include <linux/delay.h> 15 16 #include <linux/clk.h> ··· 38 37 #define RTL8211F_PHYCR2_PHY_EEE_ENABLE BIT(5) 39 38 40 39 #define RTL8211F_INSR 0x1d 40 + 41 + /* RTL8211F WOL interrupt configuration */ 42 + #define RTL8211F_INTBCR_PAGE 0xd40 43 + #define RTL8211F_INTBCR 0x16 44 + #define RTL8211F_INTBCR_INTB_PMEB BIT(5) 45 + 46 + /* RTL8211F WOL settings */ 47 + #define RTL8211F_WOL_SETTINGS_PAGE 0xd8a 48 + #define RTL8211F_WOL_SETTINGS_EVENTS 16 49 + #define RTL8211F_WOL_EVENT_MAGIC BIT(12) 50 + #define RTL8211F_WOL_SETTINGS_STATUS 17 51 + #define RTL8211F_WOL_STATUS_RESET (BIT(15) | 0x1fff) 52 + 53 + /* RTL8211F Unique phyiscal and multicast address (WOL) */ 54 + #define RTL8211F_PHYSICAL_ADDR_PAGE 0xd8c 55 + #define RTL8211F_PHYSICAL_ADDR_WORD0 16 56 + #define RTL8211F_PHYSICAL_ADDR_WORD1 17 57 + #define RTL8211F_PHYSICAL_ADDR_WORD2 18 41 58 42 59 #define RTL8211F_LEDCR 0x10 43 60 #define RTL8211F_LEDCR_MODE BIT(15) ··· 142 123 u16 phycr2; 143 124 bool has_phycr2; 144 125 struct clk *clk; 126 + u32 saved_wolopts; 145 127 }; 146 128 147 129 static int rtl821x_read_page(struct phy_device *phydev) ··· 372 352 phy_trigger_machine(phydev); 373 353 374 354 return IRQ_HANDLED; 355 + } 356 + 357 + static void rtl8211f_get_wol(struct phy_device *dev, struct ethtool_wolinfo *wol) 358 + { 359 + wol->supported = WAKE_MAGIC; 360 + if (phy_read_paged(dev, RTL8211F_WOL_SETTINGS_PAGE, RTL8211F_WOL_SETTINGS_EVENTS) 361 + & RTL8211F_WOL_EVENT_MAGIC) 362 + wol->wolopts = WAKE_MAGIC; 363 + } 364 + 365 + static int rtl8211f_set_wol(struct phy_device *dev, struct ethtool_wolinfo *wol) 366 + { 367 + const u8 *mac_addr = dev->attached_dev->dev_addr; 368 + int oldpage; 369 + 370 + oldpage = phy_save_page(dev); 371 + if (oldpage < 0) 372 + goto err; 373 + 374 + if (wol->wolopts & WAKE_MAGIC) { 375 + /* Store the device address for the magic packet */ 376 + rtl821x_write_page(dev, RTL8211F_PHYSICAL_ADDR_PAGE); 377 + __phy_write(dev, RTL8211F_PHYSICAL_ADDR_WORD0, mac_addr[1] << 8 | (mac_addr[0])); 378 + __phy_write(dev, RTL8211F_PHYSICAL_ADDR_WORD1, mac_addr[3] << 8 | (mac_addr[2])); 379 + __phy_write(dev, RTL8211F_PHYSICAL_ADDR_WORD2, mac_addr[5] << 8 | (mac_addr[4])); 380 + 381 + /* Enable magic packet matching and reset WOL status */ 382 + rtl821x_write_page(dev, RTL8211F_WOL_SETTINGS_PAGE); 383 + __phy_write(dev, RTL8211F_WOL_SETTINGS_EVENTS, RTL8211F_WOL_EVENT_MAGIC); 384 + __phy_write(dev, RTL8211F_WOL_SETTINGS_STATUS, RTL8211F_WOL_STATUS_RESET); 385 + 386 + /* Enable the WOL interrupt */ 387 + rtl821x_write_page(dev, RTL8211F_INTBCR_PAGE); 388 + __phy_set_bits(dev, RTL8211F_INTBCR, RTL8211F_INTBCR_INTB_PMEB); 389 + } else { 390 + /* Disable the WOL interrupt */ 391 + rtl821x_write_page(dev, RTL8211F_INTBCR_PAGE); 392 + __phy_clear_bits(dev, RTL8211F_INTBCR, RTL8211F_INTBCR_INTB_PMEB); 393 + 394 + /* Disable magic packet matching and reset WOL status */ 395 + rtl821x_write_page(dev, RTL8211F_WOL_SETTINGS_PAGE); 396 + __phy_write(dev, RTL8211F_WOL_SETTINGS_EVENTS, 0); 397 + __phy_write(dev, RTL8211F_WOL_SETTINGS_STATUS, RTL8211F_WOL_STATUS_RESET); 398 + } 399 + 400 + err: 401 + return phy_restore_page(dev, oldpage, 0); 375 402 } 376 403 377 404 static int rtl8211_config_aneg(struct phy_device *phydev) ··· 1467 1400 .read_status = rtlgen_read_status, 1468 1401 .config_intr = &rtl8211f_config_intr, 1469 1402 .handle_interrupt = rtl8211f_handle_interrupt, 1403 + .set_wol = rtl8211f_set_wol, 1404 + .get_wol = rtl8211f_get_wol, 1470 1405 .suspend = rtl821x_suspend, 1471 1406 .resume = rtl821x_resume, 1472 1407 .read_page = rtl821x_read_page,