net: dsa: microchip: ksz8795: add Wake on LAN support
Subsystems (5)
v2 cover net: dsa: microchip: ksz8795: add Wake on LAN support
From: Pieter Van Trappen <[email protected]>
Add WoL support for KSZ8795 family of switches. This code was tested with a KSZ8794 chip.
Strongly based on existing KSZ9477 code which has now been moved to ksz_common instead of duplicating, as proposed during the review of the v1 version of this patch.
In addition to the device-tree addition and the actual code, there's an additional patch to check the erratum workaround application using the now available indirect register read.
---
v2:
- generalize instead of duplicate, much improved
- variable declaration reverse Christmas tree
- ksz8_handle_global_errata: return -EIO in case of indirect write failure
- ksz8_ind_read8/write8: document functions
- ksz8_handle_wake_reason: no need for additional write to clear
- fix wakeup_source origin comments
v1: https://lore.kernel.org/netdev/[email protected]/
Pieter Van Trappen (5):
dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag
net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common
net: dsa: microchip: add WoL support for KSZ87xx family
net: dsa: microchip: check erratum workaround through indirect
register read
.../bindings/net/dsa/microchip,ksz.yaml | 5 + drivers/net/dsa/microchip/ksz8.h | 3 + drivers/net/dsa/microchip/ksz8795.c | 99 +++++++- drivers/net/dsa/microchip/ksz8795_reg.h | 4 +- drivers/net/dsa/microchip/ksz9477.c | 195 +--------------- drivers/net/dsa/microchip/ksz9477.h | 5 - drivers/net/dsa/microchip/ksz9477_reg.h | 12 - drivers/net/dsa/microchip/ksz_common.c | 219 +++++++++++++++++- drivers/net/dsa/microchip/ksz_common.h | 31 ++- 9 files changed, 350 insertions(+), 223 deletions(-)
base-commit: 0a658d088cc63745528cf0ec8a2c2df0f37742d9
Signature · 1 line
2.43.0
PATCH v2 1/5 dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag
From: Pieter Van Trappen <[email protected]>
Add microchip,pme-active-high property to set the PME (Power Management Event) pin polarity for Wake on Lan interrupts.
Note that the polarity is active-low by default.
--- Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +5 -0
@@ -51,6 +51,11 @@ properties: Set if the output SYNCLKO clock should be disabled. Do not mix with microchip,synclko-125. + microchip,pme-active-high: + $ref: /schemas/types.yaml#/definitions/flag + description: + Indicates if the PME pin polarity is active-high. + microchip,io-drive-strength-microamp: description: IO Pad Drive Strength
Signature · 1 line
2.43.0
PATCH v2 2/5 net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
In reply to [email protected]From: Pieter Van Trappen <[email protected]>
Move KSZ9477 WoL functions to ksz_common, in preparation for adding KSZ87xx family support.
--- drivers/net/dsa/microchip/ksz9477.c | 181 ------------------------- drivers/net/dsa/microchip/ksz_common.c | 181 +++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 181 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +0 -181
@@ -56,187 +56,6 @@ int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) REG_SW_MTU_MASK, frame_size); } -/** -* ksz9477_handle_wake_reason - Handle wake reason on a specified port. -* @dev: The device structure. -* @port: The port number. -* -* This function reads the PME (Power Management Event) status register of a -* specified port to determine the wake reason. If there is no wake event, it -* returns early. Otherwise, it logs the wake reason which could be due to a -* "Magic Packet", "Link Up", or "Energy Detect" event. The PME status register -* is then cleared to acknowledge the handling of the wake event. -* -* Return: 0 on success, or an error code on failure. -*/ -static int ksz9477_handle_wake_reason (struct ksz_device *dev,int port) -{ -u8 pme_status; -int ret; - - ret =ksz_pread8 (dev, port,REG_PORT_PME_STATUS , &pme_status); -if (ret) -return ret; - -if (!pme_status) -return 0 ; - -dev_dbg (dev->dev,"Wake event on port %d due to:%s%s%s\n" , port, - pme_status &PME_WOL_MAGICPKT ?" \"Magic Packet\"" :"" , - pme_status &PME_WOL_LINKUP ?" \"Link Up\"" :"" , - pme_status &PME_WOL_ENERGY ?" \"Energy detect\"" :"" ); - -return ksz_pwrite8 (dev, port,REG_PORT_PME_STATUS , pme_status); -} - -/** -* ksz9477_get_wol - Get Wake-on-LAN settings for a specified port. -* @dev: The device structure. -* @port: The port number. -* @wol: Pointer to ethtool Wake-on-LAN settings structure. -* -* This function checks the PME Pin Control Register to see if PME Pin Output -* Enable is set, indicating PME is enabled. If enabled, it sets the supported -* and active WoL flags. -*/ -void ksz9477_get_wol (struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol) -{ -u8 pme_ctrl; -int ret; - -if (!dev->wakeup_source) -return ; - - wol->supported =WAKE_PHY ; - -/* Check if the current MAC address on this port can be set -* as global for WAKE_MAGIC support. The result may vary -* dynamically based on other ports configurations. -*/ -if (ksz_is_port_mac_global_usable (dev->ds, port)) - wol->supported |=WAKE_MAGIC ; - - ret =ksz_pread8 (dev, port,REG_PORT_PME_CTRL , &pme_ctrl); -if (ret) -return ; - -if (pme_ctrl &PME_WOL_MAGICPKT ) - wol->wolopts |=WAKE_MAGIC ; -if (pme_ctrl & (PME_WOL_LINKUP |PME_WOL_ENERGY )) - wol->wolopts |=WAKE_PHY ; -} - -/** -* ksz9477_set_wol - Set Wake-on-LAN settings for a specified port. -* @dev: The device structure. -* @port: The port number. -* @wol: Pointer to ethtool Wake-on-LAN settings structure. -* -* This function configures Wake-on-LAN (WoL) settings for a specified port. -* It validates the provided WoL options, checks if PME is enabled via the -* switch's PME Pin Control Register, clears any previous wake reasons, -* and sets the Magic Packet flag in the port's PME control register if -* specified. -* -* Return: 0 on success, or other error codes on failure. -*/ -int ksz9477_set_wol (struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol) -{ -u8 pme_ctrl =0 , pme_ctrl_old =0 ; -bool magic_switched_off; -bool magic_switched_on; -int ret; - -if (wol->wolopts & ~(WAKE_PHY |WAKE_MAGIC )) -return -EINVAL ; - -if (!dev->wakeup_source) -return -EOPNOTSUPP ; - - ret =ksz9477_handle_wake_reason (dev, port); -if (ret) -return ret; - -if (wol->wolopts &WAKE_MAGIC ) - pme_ctrl |=PME_WOL_MAGICPKT ; -if (wol->wolopts &WAKE_PHY ) - pme_ctrl |=PME_WOL_LINKUP |PME_WOL_ENERGY ; - - ret =ksz_pread8 (dev, port,REG_PORT_PME_CTRL , &pme_ctrl_old); -if (ret) -return ret; - -if (pme_ctrl_old == pme_ctrl) -return 0 ; - - magic_switched_off = (pme_ctrl_old &PME_WOL_MAGICPKT ) && - !(pme_ctrl &PME_WOL_MAGICPKT ); - magic_switched_on = !(pme_ctrl_old &PME_WOL_MAGICPKT ) && - (pme_ctrl &PME_WOL_MAGICPKT ); - -/* To keep reference count of MAC address, we should do this -* operation only on change of WOL settings. -*/ -if (magic_switched_on) { - ret =ksz_switch_macaddr_get (dev->ds, port,NULL ); -if (ret) -return ret; - }else if (magic_switched_off) { -ksz_switch_macaddr_put (dev->ds); - } - - ret =ksz_pwrite8 (dev, port,REG_PORT_PME_CTRL , pme_ctrl); -if (ret) { -if (magic_switched_on) -ksz_switch_macaddr_put (dev->ds); -return ret; - } - -return 0 ; -} - -/** -* ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while -* considering Wake-on-LAN (WoL) settings. -* @dev: The switch device structure. -* @wol_enabled: Pointer to a boolean which will be set to true if WoL is -* enabled on any port. -* -* This function prepares the switch device for a safe shutdown while taking -* into account the Wake-on-LAN (WoL) settings on the user ports. It updates -* the wol_enabled flag accordingly to reflect whether WoL is active on any -* port. -*/ -void ksz9477_wol_pre_shutdown (struct ksz_device *dev,bool *wol_enabled) -{ -struct dsa_port *dp; -int ret; - - *wol_enabled = false; - -if (!dev->wakeup_source) -return ; - -dsa_switch_for_each_user_port (dp, dev->ds) { -u8 pme_ctrl =0 ; - - ret =ksz_pread8 (dev, dp->index,REG_PORT_PME_CTRL , &pme_ctrl); -if (!ret && pme_ctrl) - *wol_enabled = true; - -/* make sure there are no pending wake events which would -* prevent the device from going to sleep/shutdown. -*/ -ksz9477_handle_wake_reason (dev, dp->index); - } - -/* Now we are save to enable PME pin. */ -if (*wol_enabled) -ksz_write8 (dev,REG_SW_PME_CTRL ,PME_ENABLE ); -} -static int ksz9477_wait_vlan_ctrl_ready (struct ksz_device *dev) {unsigned int val;
drivers/net/dsa/microchip/ksz_common.c +181 -0
193 lines not on this page · raw message
Signature · 1 line
2.43.0
Simon Horman
reviewerRe: [PATCH net-next v2 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
Quoted 6 lines · On Wed, Jul 31, 2024 at 12:34:00PM +0200, [email protected] wrote:
From: Pieter Van Trappen <[email protected]>
Move KSZ9477 WoL functions to
ksz_common, in preparation for adding KSZ87xx family support.Signed-off-by Pieter Van Trappen <[email protected]>
Hi Pieter,
This is not a full review, and I suggest waiting for feedback from others.
However, I think this patch-set needs to be re-arranged a little, perhaps by bringing forward some of the header file changes in the following patch forward, either into this patch or a new patch before it.
In any case, the driver does not compile with this patch applied, f.e. W=1 build using allmodconfig on x86_64. While it does compile just fine when the following patch is applied.
Signature · 1 line
pw-bot: changes-requested
Re: [PATCH net-next v2 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
Quoted 9 lines · Simon Horman
Quoted 6 lines · On Wed, Jul 31, 2024 at 12:34:00PM +0200, [email protected] wrote:
From: Pieter Van Trappen <[email protected]>
Move KSZ9477 WoL functions to
ksz_common, in preparation for adding KSZ87xx family support.Signed-off-by Pieter Van Trappen <[email protected]>
Quoted 8 lines
Hi Pieter,
This is not a full review, and I suggest waiting for feedback from others.
However, I think this patch-set needs to be re-arranged a little, perhaps by bringing forward some of the header file changes in the following patch forward, either into this patch or a new patch before it.
Hi Simon, thanks indeed I missed this! It seems difficult to respect both patch requirements [1] for this case:
* One significant exception is when moving code from one file to another -- in this case you should not modify the moved code at all in the same patch which moves it.
* When dividing your change into a series of patches, take special care to ensure that the kernel builds and runs properly after each patch in
the series.
I can make it compile but by moving the code, the KSZ9477 WoL part obviously won't run properly anymore. Any suggestion how to tackle this?
[1] : https://docs.kernel.org/process/submitting-patches.html
Quoted 7 lines
In any case, the driver does not compile with this patch applied, f.e. W=1 build using allmodconfig on
x86_64. While it does compile just fine when the following patch is applied.--
pw-bot: changes-requested
Re: [PATCH net-next v2 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
Hi Pieter,
Quoted 28 lines · Pieter
Quoted 9 lines · Simon Horman
Quoted 6 lines · On Wed, Jul 31, 2024 at 12:34:00PM +0200, [email protected] wrote:
From: Pieter Van Trappen <[email protected]>
Move KSZ9477 WoL functions to
ksz_common, in preparation for adding KSZ87xx family support.Signed-off-by Pieter Van Trappen <[email protected]>Quoted 8 lines
Hi Pieter,
This is not a full review, and I suggest waiting for feedback from others.
However, I think this patch-set needs to be re-arranged a little, perhaps by bringing forward some of the header file changes in the following patch forward, either into this patch or a new patch before it.
Hi Simon, thanks indeed I missed this! It seems difficult to respect both patch requirements [1] for this case:
* One significant exception is when moving code from one file to another -- in this case you should not modify the moved code at all in the same patch which moves it.
* When dividing your change into a series of patches, take special care to ensure that the kernel builds and runs properly after each patch in
the series.
Quoted 4 lines
I can make it compile but by moving the code, the KSZ9477 WoL part obviously won't run properly anymore. Any suggestion how to tackle this?
[1] : https://docs.kernel.org/process/submitting-patches.html
I see two options:
1. Add some minimal changes in the header files and describe the changes in commit message.
2. Do code refactoring which is done in patch 3, before code is moved around.
In any case, every step should compile.
Regards,
Oleksij
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 3/5 net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common
In reply to [email protected]From: Pieter Van Trappen <[email protected]>
Generalize KSZ9477 WoL functions at ksz_common. Move dedicated registers and generic masks to existing structures & defines for that purpose.
Introduction of PME (port) read/write helper functions, which happen to be the generic read/write for KSZ9477 but not for the incoming KSZ87xx patch.
--- drivers/net/dsa/microchip/ksz9477.c | 14 +-- drivers/net/dsa/microchip/ksz9477.h | 5 -- drivers/net/dsa/microchip/ksz9477_reg.h | 12 --- drivers/net/dsa/microchip/ksz_common.c | 109 ++++++++++++------------ drivers/net/dsa/microchip/ksz_common.h | 27 ++++-- 5 files changed, 86 insertions(+), 81 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +8 -6
@@ -1007,6 +1007,7 @@ void ksz9477_port_queue_split(struct ksz_device *dev, int port)void ksz9477_port_setup (struct ksz_device *dev,int port,bool cpu_port) { +const u16 *regs = dev->info->regs;struct dsa_switch *ds = dev->ds;u16 data16;u8 member;
@@ -1051,12 +1052,12 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)ksz9477_port_acl_init (dev, port);/* clear pending wake flags */ -ksz9477_handle_wake_reason (dev, port); +ksz_handle_wake_reason (dev, port);/* Disable all WoL options by default. Otherwise * ksz_switch_macaddr_get/put logic will not work properly. */ -ksz_pwrite8 (dev, port,REG_PORT_PME_CTRL ,0 ); +ksz_pwrite8 (dev, port, regs[REG_PORT_PME_CTRL ],0 ); }void ksz9477_config_cpu_port (struct dsa_switch *ds)
@@ -1153,6 +1154,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)int ksz9477_setup (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +const u16 *regs = dev->info->regs;int ret =0 ; ds->mtu_enforcement_ingress = true;
@@ -1183,11 +1185,11 @@ int ksz9477_setup(struct dsa_switch *ds)/* enable global MIB counter freeze function */ ksz_cfg (dev,REG_SW_MAC_CTRL_6 ,SW_MIB_COUNTER_FREEZE , true); -/* Make sure PME (WoL) is not enabled. If requested, it will be -* enabled by ksz9477_wol_pre_shutdown(). Otherwise, some PMICs do not -* like PME events changes before shutdown. +/* Make sure PME (WoL) is not enabled. If requested, it will +* be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs +* do not like PME events changes before shutdown. */ -ksz_write8 (dev,REG_SW_PME_CTRL ,0 ); +ksz_write8 (dev, regs[REG_SW_PME_CTRL ],0 );return 0 ; }
drivers/net/dsa/microchip/ksz9477.h +0 -5
@@ -60,11 +60,6 @@ void ksz9477_switch_exit(struct ksz_device *dev);void ksz9477_port_queue_split (struct ksz_device *dev,int port);void ksz9477_hsr_join (struct dsa_switch *ds,int port,struct net_device *hsr);void ksz9477_hsr_leave (struct dsa_switch *ds,int port,struct net_device *hsr); -void ksz9477_get_wol (struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol); -int ksz9477_set_wol (struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol); -void ksz9477_wol_pre_shutdown (struct ksz_device *dev,bool *wol_enabled);int ksz9477_port_acl_init (struct ksz_device *dev,int port);void ksz9477_port_acl_free (struct ksz_device *dev,int port);
drivers/net/dsa/microchip/ksz9477_reg.h +0 -12
@@ -38,11 +38,6 @@#define SWITCH_REVISION_S 4#define SWITCH_RESET 0x01 -#define REG_SW_PME_CTRL 0x0006 - -#define PME_ENABLE BIT(1) -#define PME_POLARITY BIT(0) -#define REG_GLOBAL_OPTIONS 0x000F#define SW_GIGABIT_ABLE BIT(6)
@@ -807,13 +802,6 @@#define REG_PORT_AVB_SR_1_TYPE 0x0008#define REG_PORT_AVB_SR_2_TYPE 0x000A -#define REG_PORT_PME_STATUS 0x0013 -#define REG_PORT_PME_CTRL 0x0017 - -#define PME_WOL_MAGICPKT BIT(2) -#define PME_WOL_LINKUP BIT(1) -#define PME_WOL_ENERGY BIT(0) -#define REG_PORT_INT_STATUS 0x001B#define REG_PORT_INT_MASK 0x001F
drivers/net/dsa/microchip/ksz_common.c +56 -53
238 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.h +22 -5
@@ -235,6 +235,9 @@ enum ksz_regs {S_MULTICAST_CTRL ,P_XMII_CTRL_0 ,P_XMII_CTRL_1 , +REG_SW_PME_CTRL , +REG_PORT_PME_STATUS , + REG_PORT_PME_CTRL, }; enum ksz_masks {
@@ -354,6 +357,11 @@ struct ksz_dev_ops {void (*get_caps)(struct ksz_device *dev,int port,struct phylink_config *config);int (*change_mtu)(struct ksz_device *dev,int port,int mtu); +int (*pme_write8)(struct ksz_device *dev,u32 reg,u8 value); +int (*pme_pread8)(struct ksz_device *dev,int port,int offset, +u8 *data); +int (*pme_pwrite8)(struct ksz_device *dev,int port,int offset, +u8 data);void (*freeze_mib)(struct ksz_device *dev,int port,bool freeze);void (*port_init_cnt)(struct ksz_device *dev,int port); void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
@@ -363,11 +371,6 @@ struct ksz_dev_ops { int duplex, bool tx_pause, bool rx_pause);void (*setup_rgmii_delay)(struct ksz_device *dev,int port);int (*tc_cbs_set_cinc)(struct ksz_device *dev,int port,u32 val); -void (*get_wol)(struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol); -int (*set_wol)(struct ksz_device *dev,int port, -struct ethtool_wolinfo *wol); -void (*wol_pre_shutdown)(struct ksz_device *dev,bool *wol_enabled);void (*config_cpu_port)(struct dsa_switch *ds);int (*enable_stp_addr)(struct ksz_device *dev);int (*reset)(struct ksz_device *dev);
@@ -391,6 +394,7 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack);void ksz_switch_macaddr_put (struct dsa_switch *ds);void ksz_switch_shutdown (struct ksz_device *dev); +int ksz_handle_wake_reason (struct ksz_device *dev,int port);/* Common register access functions */ static inline struct regmap *ksz_regmap_8 (struct ksz_device *dev)
@@ -629,6 +633,11 @@ static inline bool is_ksz8(struct ksz_device *dev)return ksz_is_ksz87xx (dev) ||ksz_is_ksz88x3 (dev); } +static inline bool is_ksz9477 (struct ksz_device *dev) +{ +return dev->chip_id ==KSZ9477_CHIP_ID ; +} +static inline int is_lan937x (struct ksz_device *dev) { return dev->chip_id == LAN9370_CHIP_ID ||
@@ -695,6 +704,14 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)#define P_MII_MAC_MODE BIT(2)#define P_MII_SEL_M 0x3 +/* KSZ9477, KSZ8795 Wake-on-LAN (WoL) masks */ +#define PME_WOL_MAGICPKT BIT(2) +#define PME_WOL_LINKUP BIT(1) +#define PME_WOL_ENERGY BIT(0) + +#define PME_ENABLE BIT(1) +#define PME_POLARITY BIT(0) +/* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B#define REG_SW_PORT_INT_MASK__1 0x001F
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common
Hi Pieter,
Quoted 11 lines
void ksz9477_port_setup(struct
ksz_device*dev, int port, boolcpu_port)
{drivers/net/dsa/microchip/ksz9477.c +1
-0+const u16 *regs = dev->info->regs;struct dsa_switch *ds = dev->ds;u16 data16;u8 member;@@ -1051,12 +1052,12 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)ksz9477_port_acl_init (dev, port);
drivers/net/dsa/microchip/ksz9477.c void ksz9477_port_setup(struct ksz_device · line 1061
Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +2
-2/* clear pending wake flags */ -ksz9477_handle_wake_reason (dev, port); +ksz_handle_wake_reason (dev, port);/* Disable all WoL options by default. Otherwise * ksz_switch_macaddr_get/put logic will not work properly. */ -ksz_pwrite8 (dev, port,REG_PORT_PME_CTRL ,0 ); +ksz_pwrite8 (dev, port, regs[REG_PORT_PME_CTRL ],0 );
check the return value.
Quoted 24 lines
(quoted diff) +0
-0}void
ksz9477_config_cpu_port(struct dsa_switch *ds)drivers/net/dsa/microchip/ksz9477.c +1
-0@@ -1153,6 +1154,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)int ksz9477_setup (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +const u16 *regs = dev->info->regs;int ret =0 ;ds->mtu_enforcement_ingress = true;drivers/net/dsa/microchip/ksz9477.c +0
-1@@ -1183,11 +1185,11 @@ int ksz9477_setup(struct dsa_switch *ds)/* enable global MIB counter freeze function */ ksz_cfg (dev,REG_SW_MAC_CTRL_6 ,SW_MIB_COUNTER_FREEZE , true); -/* Make sure PME (WoL) is not enabled. If requested, it will be
- * enabled byksz9477_wol_pre_shutdown(). Otherwise, some
PMICs do notdrivers/net/dsa/microchip/ksz9477.c +2
-1-* like PME events changes before shutdown. +/* Make sure PME (WoL) is not enabled. If requested, it will +* be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs
drivers/net/dsa/microchip/ksz9477.c int ksz9477_setup(struct dsa_switch *ds) · line 1192
Quoted 4 lines
drivers/net/dsa/microchip/ksz9477.c +2
-1+* do not like PME events changes before shutdown. */ -ksz_write8 (dev,REG_SW_PME_CTRL ,0 ); +ksz_write8 (dev, regs[REG_SW_PME_CTRL ],0 );
here also.
Quoted 5 lines
return 0;}
Re: [PATCH net-next v2 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common
Hi Arun,
Quoted 8 lines
Quoted 8 lines
drivers/net/dsa/microchip/ksz9477.c +1
-1@@ -1051,12 +1052,12 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)ksz9477_port_acl_init (dev, port);/* clear pending wake flags */ -ksz9477_handle_wake_reason (dev, port); +ksz_handle_wake_reason (dev, port);
Quoted 7 lines
drivers/net/dsa/microchip/ksz9477.c void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) · line 1060
Quoted 5 lines
drivers/net/dsa/microchip/ksz9477.c +1
-1/* Disable all WoL options by default. Otherwise * ksz_switch_macaddr_get/put logic will not work properly. */ -ksz_pwrite8 (dev, port,REG_PORT_PME_CTRL ,0 ); +ksz_pwrite8 (dev, port, regs[REG_PORT_PME_CTRL ],0 );check the return value.
Thanks but since it's a void function, I cannot pass a non-zero return value so is there a point checking it?
Quoted 17 lines
Quoted 17 lines
(quoted diff) +0
-0}void
ksz9477_config_cpu_port(struct dsa_switch *ds)drivers/net/dsa/microchip/ksz9477.c +1
-0@@ -1153,6 +1154,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)int ksz9477_setup (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +const u16 *regs = dev->info->regs;int ret =0 ;ds->mtu_enforcement_ingress = true;drivers/net/dsa/microchip/ksz9477.c +0
-0@@ -1183,11 +1185,11 @@ int ksz9477_setup(struct dsa_switch *ds)/* enable global MIB counter freeze function */ ksz_cfg (dev,REG_SW_MAC_CTRL_6 ,SW_MIB_COUNTER_FREEZE , true);
Quoted 14 lines
drivers/net/dsa/microchip/ksz9477.c int ksz9477_setup(struct dsa_switch *ds) · line 1192
Quoted 12 lines
(quoted diff) +0
-1- /* Make sure PME (WoL) is not enabled. If requested, it willbe
- * enabled byksz9477_wol_pre_shutdown(). Otherwise, some
PMICs do notdrivers/net/dsa/microchip/ksz9477.c +2
-1-* like PME events changes before shutdown. +/* Make sure PME (WoL) is not enabled. If requested, it will +* be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs
drivers/net/dsa/microchip/ksz9477.c +2
-1+* do not like PME events changes before shutdown. */ -ksz_write8 (dev,REG_SW_PME_CTRL ,0 ); +ksz_write8 (dev, regs[REG_SW_PME_CTRL ],0 );here also.
Thanks will do.
Cheers, Pieter
PATCH v2 4/5 net: dsa: microchip: add WoL support for KSZ87xx family
In reply to [email protected]From: Pieter Van Trappen <[email protected]>
Add WoL support for KSZ87xx family of switches. This code was tested with a KSZ8794 chip.
Implement ksz_common usage of the new device-tree property 'microchip,pme-active-high'.
Make use of the now generalized ksz_common WoL functions, adding an additional interrupt register write for KSZ87xx. Add helper functions to convert from PME (port) read/writes to indirect register read/writes in the dedicated ksz8795 sources. Add initial configuration during (port) setup as per KSZ9477.
--- drivers/net/dsa/microchip/ksz8.h | 3 + drivers/net/dsa/microchip/ksz8795.c | 86 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.c | 29 ++++++--- drivers/net/dsa/microchip/ksz_common.h | 4 ++ 4 files changed, 115 insertions(+), 7 deletions(-)
drivers/net/dsa/microchip/ksz8.h +3 -0
@@ -54,6 +54,9 @@ int ksz8_reset_switch(struct ksz_device *dev);int ksz8_switch_init (struct ksz_device *dev);void ksz8_switch_exit (struct ksz_device *dev);int ksz8_change_mtu (struct ksz_device *dev,int port,int mtu); +int ksz8_pme_write8 (struct ksz_device *dev,u32 reg,u8 value); +int ksz8_pme_pread8 (struct ksz_device *dev,int port,int offset,u8 *data); +int ksz8_pme_pwrite8 (struct ksz_device *dev,int port,int offset,u8 data); void ksz8_phylink_mac_link_up(struct phylink_config *config, struct phy_device *phydev, unsigned int mode, phy_interface_t interface, int speed, int duplex,
drivers/net/dsa/microchip/ksz8795.c +86 -0
122 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.c +22 -7
@@ -307,6 +307,9 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .init = ksz8_switch_init, .exit = ksz8_switch_exit, .change_mtu = ksz8_change_mtu, + .pme_write8 = ksz8_pme_write8, + .pme_pread8 = ksz8_pme_pread8, + .pme_pwrite8 = ksz8_pme_pwrite8, }; static void ksz9477_phylink_mac_link_up(struct phylink_config *config,
@@ -423,6 +426,9 @@ static const u16 ksz8795_regs[] = { [S_MULTICAST_CTRL] = 0x04, [P_XMII_CTRL_0] = 0x06, [P_XMII_CTRL_1] = 0x06, + [REG_SW_PME_CTRL] = 0x8003, + [REG_PORT_PME_STATUS] = 0x8003, + [REG_PORT_PME_CTRL] = 0x8007, };static const u32 ksz8795_masks[] = {
@@ -3752,7 +3758,7 @@ static void ksz_get_wol(struct dsa_switch *ds, int port,u8 pme_ctrl;int ret; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return ;if (!dev->wakeup_source)
@@ -3805,7 +3811,7 @@ static int ksz_set_wol(struct dsa_switch *ds, int port,if (wol->wolopts & ~(WAKE_PHY |WAKE_MAGIC ))return -EINVAL ; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return -EOPNOTSUPP ;if (!dev->wakeup_source)
@@ -3905,13 +3911,15 @@ int ksz_handle_wake_reason(struct ksz_device *dev, int port)*/ static void ksz_wol_pre_shutdown (struct ksz_device *dev,bool *wol_enabled) { +const struct ksz_dev_ops *ops = dev->dev_ops;const u16 *regs = dev->info->regs; +u8 pme_pin_en =PME_ENABLE ;struct dsa_port *dp;int ret; *wol_enabled = false; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return ;if (!dev->wakeup_source)
@@ -3920,8 +3928,8 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled)dsa_switch_for_each_user_port (dp, dev->ds) {u8 pme_ctrl =0 ; - ret = dev->dev_ops->pme_pread8 (dev, dp->index, - regs[REG_PORT_PME_CTRL ], &pme_ctrl); + ret = ops->pme_pread8 (dev, dp->index, + regs[REG_PORT_PME_CTRL ], &pme_ctrl);if (!ret && pme_ctrl) *wol_enabled = true;
@@ -3932,8 +3940,13 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) }/* Now we are save to enable PME pin. */ -if (*wol_enabled) - dev->dev_ops->pme_write8 (dev, regs[REG_SW_PME_CTRL ],PME_ENABLE ); +if (*wol_enabled) { +if (dev->pme_active_high) + pme_pin_en |=PME_POLARITY ; + ops->pme_write8 (dev, regs[REG_SW_PME_CTRL ], pme_pin_en); +if (ksz_is_ksz87xx (dev)) +ksz_write8 (dev,KSZ8795_REG_INT_EN ,KSZ8795_INT_PME_MASK ); + } } static int ksz_port_set_mac_address(struct dsa_switch *ds, int port,
@@ -4643,6 +4656,8 @@ int ksz_switch_register(struct ksz_device *dev) dev->wakeup_source =of_property_read_bool (dev->dev->of_node,"wakeup-source" ); + dev->pme_active_high =of_property_read_bool (dev->dev->of_node, +"microchip,pme-active-high" ); } ret =dsa_register_switch (dev->ds);
drivers/net/dsa/microchip/ksz_common.h +4 -0
@@ -174,6 +174,7 @@ struct ksz_device {bool synclko_125;bool synclko_disable;bool wakeup_source; +bool pme_active_high;struct vlan_table *vlan_cache;
@@ -712,6 +713,9 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)#define PME_ENABLE BIT(1)#define PME_POLARITY BIT(0) +#define KSZ8795_REG_INT_EN 0x7D +#define KSZ8795_INT_PME_MASK BIT(4) +/* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B#define REG_SW_PORT_INT_MASK__1 0x001F
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 4/5] net: dsa: microchip: add WoL support for KSZ87xx family
Hi Pieter,
Quoted 40 lines
+/**
+ *ksz8_ind_write8- EEE/ACL/PME indirect register write
+ * @dev: The device structure.
+ * @table: Function & table select, register 110.
+ * @addr: Indirect access control, register 111.
+ * @data: The data to be written.
+ *
+ * This function performs an indirect register write for EEE, ACL or
+ * PME switch functionalities. Both 8-bit registers 110 and 111 are
+ * written at once withksz_write16, using the serial multiple write
+ * functionality.
+ *
+ * Return: 0 on success, or an error code on failure.
+ */
static int ksz8_ind_write8(structksz_device*dev, u8 table, u16
addr, u8 data){ const u16 *regs;drivers/net/dsa/microchip/ksz8795.c +1
-0@@ -58,6 +72,59 @@ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data) return ret; }int ksz8_reset_switch (struct ksz_device *dev) {if (ksz_is_ksz88x3 (dev)) {@@ -1545,6 +1612,7 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port) void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) { + const u16 *regs = dev->info->regs;struct dsa_switch *ds = dev->ds;const u32 *masks; int queues;drivers/net/dsa/microchip/ksz8795.c +0
-0@@ -1575,6 +1643,13 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
drivers/net/dsa/microchip/ksz8795.c void ksz8_port_setup(struct ksz_device *dev, · line 1653
Quoted 10 lines
drivers/net/dsa/microchip/ksz8795.c +7
-0member =BIT (dsa_upstream_port (ds, port));ksz8_cfg_port_member (dev, port, member); + +/* Disable all WoL options by default. Otherwise +* ksz_switch_macaddr_get/put logic will not work properly. +* CPU port 4 has no WoL functionality. +*/ +if (ksz_is_ksz87xx (dev) && !cpu_port) + ksz8_pme_pwrite8(dev, port, regs[REG_PORT_PME_CTRL],
check the return value of register write.
Quoted 20 lines
(quoted diff) +0
-00); }static void
ksz88x3_config_rmii_clk(struct ksz_device *dev)drivers/net/dsa/microchip/ksz8795.c +1
-0@@ -1790,6 +1865,7 @@ int ksz8_enable_stp_addr(struct ksz_device *dev)int ksz8_setup (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +const u16 *regs = dev->info->regs;int i;ds->mtu_enforcement_ingress = true;drivers/net/dsa/microchip/ksz8795.c +2
-0@@ -1829,6 +1905,16 @@ int ksz8_setup(struct dsa_switch *ds)for (i =0 ; i < (dev->info->num_vlans /4 ); i++)ksz8_r_vlan_entries (dev, i); +/* Make sure PME (WoL) is not enabled. If requested, it will +* be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs
drivers/net/dsa/microchip/ksz8795.c int ksz8_setup(struct dsa_switch *ds) · line 1915
Quoted 6 lines
drivers/net/dsa/microchip/ksz8795.c +6
-0+* do not like PME events changes before shutdown. PME only +* available on KSZ87xx family. +*/ +if (ksz_is_ksz87xx (dev)) { +ksz8_pme_write8 (dev, regs[REG_SW_PME_CTRL ],0 ); +ksz_rmw8 (dev,REG_INT_ENABLE ,INT_PME ,0 );
Here also.
Quoted 29 lines
drivers/net/dsa/microchip/ksz8795.c +3
-1+ } +return ksz8_handle_global_errata (ds); }static const u32 ksz8795_masks[] = {@@ -3752,7 +3758,7 @@ static void ksz_get_wol(struct dsa_switch *ds,int port, u8 pme_ctrl;int ret; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return ;if (!dev->wakeup_source)drivers/net/dsa/microchip/ksz_common.c +1
-1@@ -3805,7 +3811,7 @@ static int ksz_set_wol(struct dsa_switch *ds, int port, if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))return -EINVAL ; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return -EOPNOTSUPP ;if (!dev->wakeup_source)
drivers/net/dsa/microchip/ksz_common.c int ksz_handle_wake_reason(struct ksz_device · line 3916
Quoted 6 lines
drivers/net/dsa/microchip/ksz_common.c +1
-0@@ -3905,13 +3911,15 @@ int ksz_handle_wake_reason(struct ksz_device*dev, int port) */ static void ksz_wol_pre_shutdown (struct ksz_device *dev,bool *wol_enabled) { +const struct ksz_dev_ops *ops = dev->dev_ops;
This change could be introduced in previous patch itself.
Quoted 41 lines
drivers/net/dsa/microchip/ksz_common.c +2
-1const u16 *regs = dev->info->regs; +u8 pme_pin_en =PME_ENABLE ;struct dsa_port *dp;int ret; *wol_enabled = false; -if (!is_ksz9477 (dev)) +if (!is_ksz9477 (dev) && !ksz_is_ksz87xx (dev))return ;if (!dev->wakeup_source)drivers/net/dsa/microchip/ksz_common.c +2
-2@@ -3920,8 +3928,8 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled)dsa_switch_for_each_user_port (dp, dev->ds) {u8 pme_ctrl =0 ; - ret = dev->dev_ops->pme_pread8 (dev, dp->index, - regs[REG_PORT_PME_CTRL ], &pme_ctrl); + ret = ops->pme_pread8 (dev, dp->index, + regs[REG_PORT_PME_CTRL ], &pme_ctrl);if (!ret && pme_ctrl) *wol_enabled = true;drivers/net/dsa/microchip/ksz_common.c +6
-2@@ -3932,8 +3940,13 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) }/* Now we are save to enable PME pin. */ -if (*wol_enabled) - dev->dev_ops->pme_write8 (dev, regs[REG_SW_PME_CTRL ], PME_ENABLE); +if (*wol_enabled) { +if (dev->pme_active_high) + pme_pin_en |=PME_POLARITY ; + ops->pme_write8 (dev, regs[REG_SW_PME_CTRL ], pme_pin_en); +if (ksz_is_ksz87xx (dev)) + ksz_write8(dev, KSZ8795_REG_INT_EN,
Quoted 1 line
KSZ8795_INT_PME_MASK);
check the return values.
Quoted 32 lines
drivers/net/dsa/microchip/ksz_common.c +1
-0+ } } ret =dsa_register_switch (dev->ds);drivers/net/dsa/microchip/ksz_common.h +4
-0@@ -174,6 +174,7 @@ struct ksz_device {bool synclko_125;bool synclko_disable;bool wakeup_source; +bool pme_active_high;struct vlan_table *vlan_cache;@@ -712,6 +713,9 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)#define PME_ENABLE BIT(1)#define PME_POLARITY BIT(0) +#define KSZ8795_REG_INT_EN 0x7D +#define KSZ8795_INT_PME_MASK BIT(4) +/* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B#define
REG_SW_PORT_INT_MASK__10x001F
--
2.43.0
PATCH v2 5/5 net: dsa: microchip: check erratum workaround through indirect register read
In reply to [email protected]From: Pieter Van Trappen <[email protected]>
Check the erratum workaround application which ensures in addition that indirect register write and read work as expected.
Commit b7fb7729c94f ("net: dsa: microchip: fix register write order in ksz8_ind_write8()") would have been found faster like this.
Also fix the register naming as in the datasheet.
--- drivers/net/dsa/microchip/ksz8795.c | 13 +++++++++++-- drivers/net/dsa/microchip/ksz8795_reg.h | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +11 -2
@@ -1834,6 +1834,7 @@ void ksz8_phylink_mac_link_up(struct phylink_config *config,static int ksz8_handle_global_errata (struct dsa_switch *ds) {struct ksz_device *dev = ds->priv; +u8 data =0xff ;int ret =0 ;/* KSZ87xx Errata DS80000687C.
@@ -1842,8 +1843,16 @@ static int ksz8_handle_global_errata(struct dsa_switch *ds)* KSZ879x/KSZ877x/KSZ876x and some EEE link partners may result in * the link dropping. */ -if (dev->info->ksz87xx_eee_link_erratum) - ret =ksz8_ind_write8 (dev,TABLE_EEE ,REG_IND_EEE_GLOB2_HI ,0 ); +if (dev->info->ksz87xx_eee_link_erratum) { + ret =ksz8_ind_write8 (dev,TABLE_EEE ,REG_IND_EEE_GLOB2_LO ,0 ); +if (!ret) + ret =ksz8_ind_read8 (dev,TABLE_EEE ,REG_IND_EEE_GLOB2_LO , &data); + } + +if (!ret && data) { +dev_err (dev->dev,"failed to disable EEE next page exchange (erratum)\n" ); +return -EIO ; + }return ret; }
drivers/net/dsa/microchip/ksz8795_reg.h +2 -2
@@ -764,8 +764,8 @@#define IND_ACC_TABLE (table) ((table) << 8)/* */ -#define REG_IND_EEE_GLOB2_LO 0x34 -#define REG_IND_EEE_GLOB2_HI 0x35 +#define REG_IND_EEE_GLOB2_HI 0x34 +#define REG_IND_EEE_GLOB2_LO 0x35/** * MIB_COUNTER_VALUE 00-00000000-3FFFFFFF
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 5/5] net: dsa: microchip: check erratum workaround through indirect register read
Hi Pieter,
Quoted 7 lines · On Wed, Jul 31, 2024 at 12:34:03PM +0200, [email protected] wrote:
From: Pieter Van Trappen <[email protected]>
Check the erratum workaround application which ensures in addition that indirect register write and read work as expected.
Commit
b7fb7729c94f("net: dsa: microchip: fix register write order inksz8_ind_write8()") would have been found faster like this.
No. It would be not found faster, because there are nearly no active users/develpers participating in the development/testing of this part of the driver. I still do not have access to any KSZ879x variant and the initial erratum fix was done on request without ability to actually test it on my side. You seems to be the first one for long time making something for this series :)
The strategy to re-read configs after writing them is also not consequent in the driver and would not really help here too. It will show you an error only if the driver is accidentally writing to a read-only register.
Quoted 3 lines
Also fix the register naming as in the datasheet.
Signed-off-by Pieter Van Trappen <[email protected]>
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |