net: phy: smsc: add WoL support to LAN8740/LAN8742 PHYs
Subsystems (3)
PATCH v5 1/1 net: phy: smsc: add WoL support to LAN8740/LAN8742 PHYs
From: Tristram Ha <[email protected]>
Microchip LAN8740/LAN8742 PHYs support basic unicast, broadcast, and Magic Packet WoL. They have one pattern filter matching up to 128 bytes of frame data, which can be used to implement ARP or multicast WoL.
ARP WoL matches any ARP frame with broadcast address.
Multicast WoL matches any multicast frame.
---
v5
- Resend for patch submission.
v4
- Reduce variable use for calling the function to enable WoL.
- Provide a general description of how the pattern data are prepared.
v3
- Do not try to get IPv4 and IPv6 address from the driver
- As a result only generic ARP and multicast support are provided
v2
- use in_dev_put() only when IP support is enabled
v1
- use in_dev_get() to retrieve IP address to avoid compiler warning
- use ipv6_get_lladdr() to retrieve IPv6 address
- use that function only when IPv6 support is enabled
- export that function in addrconf.c
- program the MAC address in a loop
- always set datalen in lan874x_chk_wol_pattern()
- add spaces around "<<"
- select CRC16 in Kconfig as crc16() is used in driver
drivers/net/phy/Kconfig | 1 + drivers/net/phy/smsc.c | 259 +++++++++++++++++++++++++++++++++++++++- include/linux/smscphy.h | 34 ++++++ 3 files changed, 292 insertions(+), 2 deletions(-)
drivers/net/phy/Kconfig +1 -0
@@ -350,6 +350,7 @@ config ROCKCHIP_PHY config SMSC_PHY tristate "SMSC PHYs" + select CRC16 help Currently supports the LAN83C185, LAN8187 and LAN8700 PHYs
drivers/net/phy/smsc.c +257 -2
301 lines not on this page · raw message
include/linux/smscphy.h +34 -0
@@ -38,4 +38,38 @@ int smsc_phy_set_tunable(struct phy_device *phydev, struct ethtool_tunable *tuna, const void *data);int smsc_phy_probe (struct phy_device *phydev); +#define MII_LAN874X_PHY_MMD_WOL_WUCSR 0x8010 +#define MII_LAN874X_PHY_MMD_WOL_WUF_CFGA 0x8011 +#define MII_LAN874X_PHY_MMD_WOL_WUF_CFGB 0x8012 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK0 0x8021 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK1 0x8022 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK2 0x8023 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK3 0x8024 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK4 0x8025 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK5 0x8026 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK6 0x8027 +#define MII_LAN874X_PHY_MMD_WOL_WUF_MASK7 0x8028 +#define MII_LAN874X_PHY_MMD_WOL_RX_ADDRA 0x8061 +#define MII_LAN874X_PHY_MMD_WOL_RX_ADDRB 0x8062 +#define MII_LAN874X_PHY_MMD_WOL_RX_ADDRC 0x8063 +#define MII_LAN874X_PHY_MMD_MCFGR 0x8064 + +#define MII_LAN874X_PHY_PME1_SET (2 << 13) +#define MII_LAN874X_PHY_PME2_SET (2 << 11) +#define MII_LAN874X_PHY_PME_SELF_CLEAR BIT(9) +#define MII_LAN874X_PHY_WOL_PFDA_FR BIT(7) +#define MII_LAN874X_PHY_WOL_WUFR BIT(6) +#define MII_LAN874X_PHY_WOL_MPR BIT(5) +#define MII_LAN874X_PHY_WOL_BCAST_FR BIT(4) +#define MII_LAN874X_PHY_WOL_PFDAEN BIT(3) +#define MII_LAN874X_PHY_WOL_WUEN BIT(2) +#define MII_LAN874X_PHY_WOL_MPEN BIT(1) +#define MII_LAN874X_PHY_WOL_BCSTEN BIT(0) + +#define MII_LAN874X_PHY_WOL_FILTER_EN BIT(15) +#define MII_LAN874X_PHY_WOL_FILTER_MCASTTEN BIT(9) +#define MII_LAN874X_PHY_WOL_FILTER_BCSTEN BIT(8) + +#define MII_LAN874X_PHY_PME_SELF_CLEAR_DELAY 0x1000/* 81 milliseconds */ +#endif /* __LINUX_SMSCPHY_H__ */
Signature · 1 line
2.17.1
Quoted 11 lines · On Thu, Jul 20, 2023 at 05:40:53PM -0700, [email protected] wrote:
From: Tristram Ha <[email protected]>
Microchip LAN8740/LAN8742 PHYs support basic unicast, broadcast, and Magic Packet WoL. They have one pattern filter matching up to 128 bytes of frame data, which can be used to implement ARP or multicast WoL.
ARP WoL matches any ARP frame with broadcast address.
Multicast WoL matches any multicast frame.
Signed-off-by Tristram Ha <[email protected]>
Quoted 11 lines · On 7/20/2023 5:40 PM, [email protected] wrote:
From: Tristram Ha <[email protected]>
Microchip LAN8740/LAN8742 PHYs support basic unicast, broadcast, and Magic Packet WoL. They have one pattern filter matching up to 128 bytes of frame data, which can be used to implement ARP or multicast WoL.
ARP WoL matches any ARP frame with broadcast address.
Multicast WoL matches any multicast frame.
Signed-off-by Tristram Ha <[email protected]>
This looks good to me, just one suggestion but which you can implement later, it would be nice to have a pm_wakeup_event(&phydev->mdio.dev, 0) in order to have the PHY device accounted for any wake-up event. You can do that when you do the initial acknowledgement of any wake-up interrupts in your .config_init callback.
Signature · 1 line
Florian
Jakub Kicinski
maintainerdrivers/net/phy/smsc.c line 28
Quoted 4 lines · On Thu, 20 Jul 2023 17:40:53 -0700 [email protected] wrote:
drivers/net/phy/smsc.c +4
-0+#include <linux/inetdevice.h> +#include <net/addrconf.h> +#include <net/if_inet6.h> +#include <net/ipv6.h>
You don't need these includes any more, right?
Quoted 6 lines
#include <
linux/smscphy.h>/* Vendor-specific PHY Definitions */
drivers/net/phy/smsc.c +2
-0+static int lan874x_set_wol (struct phy_device *phydev, +struct ethtool_wolinfo *wol)
drivers/net/phy/smsc.c int lan87xx_read_status(struct phy_device *phydev) · line 421
Quoted 10 lines
drivers/net/phy/smsc.c +10
-0+{ +struct net_device *ndev = phydev->attached_dev; +struct smsc_phy_priv *priv = phydev->priv; +u16 val, val_wucsr; +u8 data[128 ]; +u8 datalen; +int rc; + +if (wol->wolopts &WAKE_PHY ) +return -EOPNOTSUPP ;
You're not advertising the support for WAKE_PHY, so you don't have to check if it was requested. See recent commit 55b24334c0f2.
Please keep the review tags from Florian and Simon for v6, these are minor nit picks.
Signature · 1 line
pw-bot: cr
Quoted 12 lines · On Thu, 20 Jul 2023 17:40:53 -0700 [email protected] wrote:
drivers/net/phy/smsc.c line 28
Quoted 4 lines
drivers/net/phy/smsc.c +4
-0+#include <linux/inetdevice.h> +#include <net/addrconf.h> +#include <net/if_inet6.h> +#include <net/ipv6.h> You don't need these includes any more, right?
Quoted 3 lines
#include <
linux/smscphy.h>/* Vendor-specific PHY Definitions */
Quoted 15 lines
drivers/net/phy/smsc.c int lan87xx_read_status(struct phy_device *phydev) · line 421
Quoted 12 lines
drivers/net/phy/smsc.c +12
-0+static int lan874x_set_wol (struct phy_device *phydev, +struct ethtool_wolinfo *wol) +{ +struct net_device *ndev = phydev->attached_dev; +struct smsc_phy_priv *priv = phydev->priv; +u16 val, val_wucsr; +u8 data[128 ]; +u8 datalen; +int rc; + +if (wol->wolopts &WAKE_PHY ) +return -EOPNOTSUPP ;You're not advertising the support for
WAKE_PHY, so you don't have to check if it was requested. See recent commit55b24334c0f2.
They will be removed in next update.