Support for Wake-on-LAN for Broadcom PHYs
Subsystems (5)
v3 cover Support for Wake-on-LAN for Broadcom PHYs
This patch series adds support for Wake-on-LAN to the Broadcom PHY driver. Specifically the BCM54210E/B50212E are capable of supporting Wake-on-LAN using an external pin typically wired up to a system's GPIO.
These PHY operate a programmable Ethernet MAC destination address comparator which will fire up an interrupt whenever a match is received. Because of that, it was necessary to introduce patch #1 which allows the PHY driver's ->suspend() routine to be called unconditionally. This is necessary in our case because we need a hook point into the device suspend/resume flow to enable the wake-up interrupt as late as possible.
Patch #2 adds support for the Broadcom PHY library and driver for Wake-on-LAN proper with the WAKE_UCAST, WAKE_MCAST, WAKE_BCAST, WAKE_MAGIC and WAKE_MAGICSECURE. Note that WAKE_FILTER is supportable, however this will require further discussions and be submitted as a RFC series later on.
Patch #3 updates the GENET driver to defer to the PHY for Wake-on-LAN if the PHY supports it, thus allowing the MAC to be powered down to conserve power.
Changes in v3:
- collected Reviewed-by tags
- explicitly use return 0 in bcm54xx_phy_probe() (Paolo)
Changes in v2:
- introduce PHY_ALWAYS_CALL_SUSPEND and only have the Broadcom PHY driver set this flag to minimize changes to the suspend flow to only drivers that need it
- corrected possibly uninitialized variable in bcm54xx_set_wakeup_irq (Simon)
Florian Fainelli (3):
net: phy: Allow drivers to always call into ->suspend()
net: phy: broadcom: Add support for Wake-on-LAN
net: bcmgenet: Add support for PHY-based Wake-on-LAN
.../ethernet/broadcom/genet/bcmgenet_wol.c | 14 ++ drivers/net/phy/bcm-phy-lib.c | 212 ++++++++++++++++++ drivers/net/phy/bcm-phy-lib.h | 5 + drivers/net/phy/broadcom.c | 126 ++++++++++- drivers/net/phy/phy_device.c | 5 +- include/linux/brcmphy.h | 55 +++++ include/linux/phy.h | 4 + 7 files changed, 416 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/3 net: phy: Allow drivers to always call into ->suspend()
A few PHY drivers are currently attempting to not suspend the PHY when Wake-on-LAN is enabled, however that code is not currently executing at all due to an early check in phy_suspend().
This prevents PHY drivers from making an appropriate decisions and put the hardware into a low power state if desired.
In order to allow the PHY drivers to opt into getting their ->suspend routine to be called, add a PHY_ALWAYS_CALL_SUSPEND bit which can be set. A boolean that tracks whether the PHY or the attached MAC has Wake-on-LAN enabled is also provided for convenience.
If phydev::wol_enabled then the PHY shall not prevent its own Wake-on-LAN detection logic from working and shall not prevent the Ethernet MAC from receiving packets for matching.
--- drivers/net/phy/phy_device.c | 5 +++-- include/linux/phy.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +3 -2
@@ -1860,9 +1860,10 @@ int phy_suspend(struct phy_device *phydev)if (phydev->suspended)return 0 ; -/* If the device has WOL enabled, we cannot suspend the PHY */ phy_ethtool_get_wol (phydev, &wol); -if (wol.wolopts || (netdev && netdev->wol_enabled)) + phydev->wol_enabled = wol.wolopts || (netdev && netdev->wol_enabled); +/* If the device has WOL enabled, we cannot suspend the PHY */ +if (phydev->wol_enabled && !(phydrv->flags &PHY_ALWAYS_CALL_SUSPEND ))return -EBUSY ;if (!phydrv || !phydrv->suspend)
include/linux/phy.h +4 -0
@@ -86,6 +86,7 @@ extern const int phy_10gbit_features_array[1];#define PHY_IS_INTERNAL 0x00000001#define PHY_RST_AFTER_CLK_EN 0x00000002#define PHY_POLL_CABLE_TEST 0x00000004 +#define PHY_ALWAYS_CALL_SUSPEND 0x00000008#define MDIO_DEVICE_IS_PHY 0x80000000/**
@@ -548,6 +549,8 @@ struct macsec_ops;* @downshifted_rate: Set true if link speed has been downshifted. * @is_on_sfp_module: Set true if PHY is located on an SFP module. * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY +* @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN +* enabled. * @state: State of the PHY for management purposes * @dev_flags: Device-specific flags used by the PHY driver. *
@@ -644,6 +647,7 @@ struct phy_device { unsigned downshifted_rate:1; unsigned is_on_sfp_module:1; unsigned mac_managed_pm:1; + unsigned wol_enabled:1; unsigned autoneg:1;/* The most recently read link state */
Signature · 1 line
2.34.1
PATCH v3 2/3 net: phy: broadcom: Add support for Wake-on-LAN
In reply to Florian FainelliAdd support for WAKE_UCAST, WAKE_MCAST, WAKE_BCAST, WAKE_MAGIC and WAKE_MAGICSECURE. This is only supported with the BCM54210E and compatible Ethernet PHYs. Using the in-band interrupt or an out of band GPIO interrupts are supported.
Broadcom PHYs will generate a Wake-on-LAN level low interrupt on LED4 as soon as one of the supported patterns is being matched. That includes generating such an interrupt even if the PHY is operated during normal modes. If WAKE_UCAST is selected, this could lead to the LED4 interrupt firing up for every packet being received which is absolutely undesirable from a performance point of view.
Because the Wake-on-LAN configuration can be set long before the system is actually put to sleep, we cannot have an interrupt service routine to clear on read the interrupt status register and ensure that new packet matches will be detected.
It is desirable to enable the Wake-on-LAN interrupt as late as possible during the system suspend process such that we limit the number of interrupts to be handled by the system, but also conversely feed into the Linux's system suspend way of dealing with interrupts in and around the points of no return.
--- drivers/net/phy/bcm-phy-lib.c | 212 ++++++++++++++++++++++++++++++++++ drivers/net/phy/bcm-phy-lib.h | 5 + drivers/net/phy/broadcom.c | 126 +++++++++++++++++++- include/linux/brcmphy.h | 55 +++++++++ 4 files changed, 395 insertions(+), 3 deletions(-)
drivers/net/phy/bcm-phy-lib.c +212 -0
@@ -6,12 +6,14 @@#include "bcm-phy-lib.h" #include <linux/bitfield.h> #include <linux/brcmphy.h> +#include <linux/etherdevice.h> #include <linux/export.h> #include <linux/mdio.h> #include <linux/module.h> #include <linux/phy.h> #include <linux/ethtool.h> #include <linux/ethtool_netlink.h> +#include <linux/netdevice.h> #define MII_BCM_CHANNEL_WIDTH 0x2000#define BCM_CL45VEN_EEE_ADV 0x3c
@@ -816,6 +818,216 @@ int bcm_phy_cable_test_get_status_rdb(struct phy_device *phydev, }EXPORT_SYMBOL_GPL (bcm_phy_cable_test_get_status_rdb); +#define BCM54XX_WOL_SUPPORTED_MASK (WAKE_UCAST | \ + WAKE_MCAST | \ + WAKE_BCAST | \ + WAKE_MAGIC | \ + WAKE_MAGICSECURE) + +int bcm_phy_set_wol (struct phy_device *phydev,struct ethtool_wolinfo *wol) +{ +struct net_device *ndev = phydev->attached_dev; +u8 da[ETH_ALEN ], mask[ETH_ALEN ]; +unsigned int i; +u16 ctl; +int ret; + +/* Allow a MAC driver to play through its own Wake-on-LAN +* implementation +*/ +if (wol->wolopts & ~BCM54XX_WOL_SUPPORTED_MASK ) +return -EOPNOTSUPP ; + +/* The PHY supports passwords of 4, 6 and 8 bytes in size, but Linux's +* ethtool only supports 6, for now. +*/ +BUILD_BUG_ON (sizeof (wol->sopass) !=ETH_ALEN ); + +/* Clear previous interrupts */ + ret =bcm_phy_read_exp (phydev,BCM54XX_WOL_INT_STATUS ); +if (ret <0 ) +return ret; + + ret =bcm_phy_read_exp (phydev,BCM54XX_WOL_MAIN_CTL ); +if (ret <0 ) +return ret; + + ctl = ret; + +if (!wol->wolopts) { +if (phy_interrupt_is_valid (phydev)) +disable_irq_wake (phydev->irq); + +/* Leave all interrupts disabled */ + ret =bcm_phy_write_exp (phydev,BCM54XX_WOL_INT_MASK , +BCM54XX_WOL_ALL_INTRS ); +if (ret <0 ) +return ret; + +/* Disable the global Wake-on-LAN enable bit */ + ctl &= ~BCM54XX_WOL_EN ; + +return bcm_phy_write_exp (phydev,BCM54XX_WOL_MAIN_CTL , ctl); + } + +/* Clear the previously configured mode and mask mode for Wake-on-LAN */ + ctl &= ~(BCM54XX_WOL_MODE_MASK <<BCM54XX_WOL_MODE_SHIFT ); + ctl &= ~(BCM54XX_WOL_MASK_MODE_MASK <<BCM54XX_WOL_MASK_MODE_SHIFT ); + ctl &= ~BCM54XX_WOL_DIR_PKT_EN ; + ctl &= ~(BCM54XX_WOL_SECKEY_OPT_MASK <<BCM54XX_WOL_SECKEY_OPT_SHIFT ); + +/* When using WAKE_MAGIC, we program the magic pattern filter to match +* the device's MAC address and we accept any MAC DA in the Ethernet +* frame. +* +* When using WAKE_UCAST, WAKE_BCAST or WAKE_MCAST, we program the +* following: +* - WAKE_UCAST -> MAC DA is the device's MAC with a perfect match +* - WAKE_MCAST -> MAC DA is X1:XX:XX:XX:XX:XX where XX is don't care +* - WAKE_BCAST -> MAC DA is FF:FF:FF:FF:FF:FF with a perfect match +* +* Note that the Broadcast MAC DA is inherently going to match the +* multicast pattern being matched. +*/ +memset (mask,0 ,sizeof (mask)); + +if (wol->wolopts &WAKE_MCAST ) { +memset (da,0 ,sizeof (da)); +memset (mask,0xff ,sizeof (mask)); + da[0 ] =0x01 ; + mask[0 ] = ~da[0 ]; + }else { +if (wol->wolopts &WAKE_UCAST ) { +ether_addr_copy (da, ndev->dev_addr); + }else if (wol->wolopts &WAKE_BCAST ) { +eth_broadcast_addr (da); + }else if (wol->wolopts &WAKE_MAGICSECURE ) { +ether_addr_copy (da, wol->sopass); + }else if (wol->wolopts &WAKE_MAGIC ) { +memset (da,0 ,sizeof (da)); +memset (mask,0xff ,sizeof (mask)); + } + } + +for (i =0 ; i <ETH_ALEN /2 ; i++) { +if (wol->wolopts & (WAKE_MAGIC |WAKE_MAGICSECURE )) { + ret =bcm_phy_write_exp (phydev, +BCM54XX_WOL_MPD_DATA1 (2 - i), + ndev->dev_addr[i *2 ] <<8 | + ndev->dev_addr[i *2 +1 ]); +if (ret <0 ) +return ret; + } + + ret =bcm_phy_write_exp (phydev,BCM54XX_WOL_MPD_DATA2 (2 - i), + da[i *2 ] <<8 | da[i *2 +1 ]); +if (ret <0 ) +return ret; + + ret =bcm_phy_write_exp (phydev,BCM54XX_WOL_MASK (2 - i), + mask[i *2 ] <<8 | mask[i *2 +1 ]); +if (ret) +return ret; + } + +if (wol->wolopts &WAKE_MAGICSECURE ) { + ctl |=BCM54XX_WOL_SECKEY_OPT_6B << +BCM54XX_WOL_SECKEY_OPT_SHIFT ; + ctl |=BCM54XX_WOL_MODE_SINGLE_MPDSEC <<BCM54XX_WOL_MODE_SHIFT ; + ctl |=BCM54XX_WOL_MASK_MODE_DA_FF << +BCM54XX_WOL_MASK_MODE_SHIFT ; + }else { +if (wol->wolopts &WAKE_MAGIC ) + ctl |=BCM54XX_WOL_MODE_SINGLE_MPD ; +else + ctl |=BCM54XX_WOL_DIR_PKT_EN ; + ctl |=BCM54XX_WOL_MASK_MODE_DA_ONLY << +BCM54XX_WOL_MASK_MODE_SHIFT ; + } + +/* Globally enable Wake-on-LAN */ + ctl |=BCM54XX_WOL_EN |BCM54XX_WOL_CRC_CHK ; + + ret =bcm_phy_write_exp (phydev,BCM54XX_WOL_MAIN_CTL , ctl); +if (ret <0 ) +return ret; + +/* Enable WOL interrupt on LED4 */ + ret =bcm_phy_read_exp (phydev,BCM54XX_TOP_MISC_LED_CTL ); +if (ret <0 ) +return ret; + + ret |=BCM54XX_LED4_SEL_INTR ; + ret =bcm_phy_write_exp (phydev,BCM54XX_TOP_MISC_LED_CTL , ret); +if (ret <0 ) +return ret; + +/* Enable all Wake-on-LAN interrupt sources */ + ret =bcm_phy_write_exp (phydev,BCM54XX_WOL_INT_MASK ,0 ); +if (ret <0 ) +return ret; + +if (phy_interrupt_is_valid (phydev)) +enable_irq_wake (phydev->irq); + +return 0 ; +} +EXPORT_SYMBOL_GPL (bcm_phy_set_wol); + +void bcm_phy_get_wol (struct phy_device *phydev,struct ethtool_wolinfo *wol) +{ +struct net_device *ndev = phydev->attached_dev; +u8 da[ETH_ALEN ]; +unsigned int i; +int ret; +u16 ctl; + + wol->supported =BCM54XX_WOL_SUPPORTED_MASK ; + wol->wolopts =0 ; + + ret =bcm_phy_read_exp (phydev,BCM54XX_WOL_MAIN_CTL ); +if (ret <0 ) +return ; + + ctl = ret; + +if (!(ctl &BCM54XX_WOL_EN )) +return ; + +for (i =0 ; i <sizeof (da) /2 ; i++) { + ret =bcm_phy_read_exp (phydev, +BCM54XX_WOL_MPD_DATA2 (2 - i)); +if (ret <0 ) +return ; + + da[i *2 ] = ret >>8 ; + da[i *2 +1 ] = ret &0xff ; + } + +if (ctl &BCM54XX_WOL_DIR_PKT_EN ) { +if (is_broadcast_ether_addr (da)) + wol->wolopts |=WAKE_BCAST ; +else if (is_multicast_ether_addr (da)) + wol->wolopts |=WAKE_MCAST ; +else if (ether_addr_equal (da, ndev->dev_addr)) + wol->wolopts |=WAKE_UCAST ; + }else { + ctl = (ctl >>BCM54XX_WOL_MODE_SHIFT ) &BCM54XX_WOL_MODE_MASK ; +switch (ctl) { +case BCM54XX_WOL_MODE_SINGLE_MPD : + wol->wolopts |=WAKE_MAGIC ; +break ; +case BCM54XX_WOL_MODE_SINGLE_MPDSEC : + wol->wolopts |=WAKE_MAGICSECURE ; +memcpy (wol->sopass, da,sizeof (da)); +break ; +default : +break ; + } + } +} +EXPORT_SYMBOL_GPL (bcm_phy_get_wol); +MODULE_DESCRIPTION ("Broadcom PHY Library" );MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Broadcom Corporation" );
drivers/net/phy/bcm-phy-lib.h +5 -0
@@ -9,6 +9,8 @@#include <linux/brcmphy.h> #include <linux/phy.h> +struct ethtool_wolinfo ; +/* 28nm only register definitions */ #define MISC_ADDR (base, channel) base, channel
@@ -106,4 +108,7 @@ static inline void bcm_ptp_stop(struct bcm_ptp_private *priv) }#endif +int bcm_phy_set_wol (struct phy_device *phydev,struct ethtool_wolinfo *wol); +void bcm_phy_get_wol (struct phy_device *phydev,struct ethtool_wolinfo *wol); +#endif /* _LINUX_BCM_PHY_LIB_H */
drivers/net/phy/broadcom.c +123 -3
197 lines not on this page · raw message
include/linux/brcmphy.h +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 3/3 net: bcmgenet: Add support for PHY-based Wake-on-LAN
In reply to Florian FainelliIf available, interrogate the PHY to find out whether we can use it for Wake-on-LAN. This can be a more power efficient way of implementing that feature, especially when the MAC is powered off in low power states.
--- drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c +14 -0
@@ -42,6 +42,12 @@ void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)struct bcmgenet_priv *priv =netdev_priv (dev);struct device *kdev = &priv->pdev->dev; +if (dev->phydev) { +phy_ethtool_get_wol (dev->phydev, wol); +if (wol->supported) +return ; + } +if (!device_can_wakeup (kdev)) { wol->supported =0 ; wol->wolopts =0 ;
@@ -63,6 +69,14 @@ int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) {struct bcmgenet_priv *priv =netdev_priv (dev);struct device *kdev = &priv->pdev->dev; +int ret; + +/* Try Wake-on-LAN from the PHY first */ +if (dev->phydev) { + ret =phy_ethtool_set_wol (dev->phydev, wol); +if (ret != -EOPNOTSUPP ) +return ret; + }if (!device_can_wakeup (kdev))return -ENOTSUPP ;
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 4 lines · On Thu, 11 May 2023 10:21:07 -0700 you wrote:
This patch series adds support for Wake-on-LAN to the Broadcom PHY driver. Specifically the BCM54210E/B50212E are capable of supporting Wake-on-LAN using an external pin typically wired up to a system's GPIO.
Quoted 8 lines
These PHY operate a programmable Ethernet MAC destination address comparator which will fire up an interrupt whenever a match is received. Because of that, it was necessary to introduce patch #1 which allows the PHY driver's ->suspend() routine to be called unconditionally. This is necessary in our case because we need a hook point into the device suspend/resume flow to enable the wake-up interrupt as late as possible.
[...]
Here is the summary with links:
- [net-next,v3,1/3] net: phy: Allow drivers to always call into ->suspend()
https://git.kernel.org/netdev/net-next/c/a7e3448086d5 - [net-next,v3,2/3] net: phy: broadcom: Add support for Wake-on-LAN https://git.kernel.org/netdev/net-next/c/8baddaa9d4ba - [net-next,v3,3/3] net: bcmgenet: Add support for PHY-based Wake-on-LAN https://git.kernel.org/netdev/net-next/c/7e400ff35cbe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html