net: dsa: microchip: ksz8795: add Wake on LAN support
Subsystems (5)
v3 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 that fixes some bugs found when further testing DSA with this KSZ8794 chip.
---
v3:
- ensure each patch separately compiles & works
- additional return value checks where possible
- drop v2 patch 5/5 (net: dsa: microchip: check erratum workaround through indirect register read)
- add new patch that fixes KSZ87xx bugs wrt datasheet
v2: https://lore.kernel.org/netdev/[email protected]/
- 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: apply KSZ87xx family fixes wrt datasheet
.../bindings/net/dsa/microchip,ksz.yaml | 5 + drivers/net/dsa/microchip/ksz8.h | 3 + drivers/net/dsa/microchip/ksz8795.c | 94 +++++- drivers/net/dsa/microchip/ksz9477.c | 197 +------------ drivers/net/dsa/microchip/ksz9477.h | 5 - drivers/net/dsa/microchip/ksz9477_reg.h | 12 - drivers/net/dsa/microchip/ksz_common.c | 267 ++++++++++++++++-- drivers/net/dsa/microchip/ksz_common.h | 31 +- 8 files changed, 385 insertions(+), 229 deletions(-)
base-commit: eec9de0354105527e31394c0ed4b8c54fb1fe1dd
Signature · 1 line
2.43.0
PATCH v3 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 v3 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/ksz9477.h | 5 - drivers/net/dsa/microchip/ksz9477_reg.h | 12 -- drivers/net/dsa/microchip/ksz_common.c | 181 ++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 19 +++ 5 files changed, 200 insertions(+), 198 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/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 +181 -0
193 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.h +19 -0
@@ -391,6 +391,12 @@ 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 ksz9477_handle_wake_reason (struct ksz_device *dev,int port); +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);/* Common register access functions */ static inline struct regmap *ksz_regmap_8 (struct ksz_device *dev)
@@ -695,6 +701,19 @@ 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 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_SW_PME_CTRL 0x0006 + +#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 v3 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common
Quoted 10 lines · On Tue, 2024-08-06 at 15:25 +0200, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
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]>
PATCH v3 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 | 16 ++-- drivers/net/dsa/microchip/ksz_common.c | 113 +++++++++++++------------ drivers/net/dsa/microchip/ksz_common.h | 30 +++---- 3 files changed, 81 insertions(+), 78 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +8 -8
@@ -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,13 +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 ); - -return 0 ; +return ksz_write8 (dev, regs[REG_SW_PME_CTRL ],0 ); }u32 ksz9477_get_port_addr (int port,int offset)
drivers/net/dsa/microchip/ksz_common.c +59 -54
242 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.h +14 -16
@@ -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,12 +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 ksz9477_handle_wake_reason (struct ksz_device *dev,int port); -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 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)
@@ -635,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 ||
@@ -702,15 +705,10 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port)#define P_MII_SEL_M 0x3/* KSZ9477, KSZ8795 Wake-on-LAN (WoL) masks */ -#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_SW_PME_CTRL 0x0006 -#define PME_ENABLE BIT(1)#define PME_POLARITY BIT(0)
Signature · 1 line
2.43.0
Re: [PATCH net-next v3 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common
Hi Pieter,
Quoted 9 lines · On Tue, 2024-08-06 at 15:25 +0200, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
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.
Quoted 5 lines
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.
Signed-off-by Pieter Van Trappen <[email protected]>
PATCH v3 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 | 94 +++++++++++++++++++++++++- drivers/net/dsa/microchip/ksz_common.c | 24 +++++-- drivers/net/dsa/microchip/ksz_common.h | 4 ++ 4 files changed, 118 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 +92 -2
130 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.c +19 -5
@@ -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[] = {
@@ -3789,7 +3795,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)
@@ -3842,7 +3848,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)
@@ -3908,12 +3914,13 @@ 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)
@@ -3934,8 +3941,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) - 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,
@@ -4645,6 +4657,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 v3 4/5] net: dsa: microchip: add WoL support for KSZ87xx family
Hi Pieter,
Quoted 53 lines
static const u32 ksz8795_masks[] = {
drivers/net/dsa/microchip/ksz_common.c +1
-1@@ -3789,7 +3795,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@@ -3842,7 +3848,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 +2
-1@@ -3908,12 +3914,13 @@ 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)drivers/net/dsa/microchip/ksz_common.c +6
-2@@ -3934,8 +3941,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) - 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);
nitpick:
Do we need to rename register like KSZ87xx_REG_INT_EN since it is common to other switches as well?
Quoted 25 lines
drivers/net/dsa/microchip/ksz_common.h +4
-1@@ -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) + --2.43.0
Re: [PATCH net-next v3 4/5] net: dsa: microchip: add WoL support for KSZ87xx family
Quoted 5 lines · On Wed 7 Aug 2024 at 05:56, <[email protected]> wrote:
Hi Pieter,
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
(quoted diff) +2
-0+ if (ksz_is_ksz87xx(dev)) + ksz_write8(dev, KSZ8795_REG_INT_EN,
KSZ8795_INT_PME_MASK);nitpick:
Do we need to rename register likeKSZ87xx_REG_INT_ENsince it is common to other switches as well?
Hi Arun, well it's all a bit confusing already I have to admit. There is a filename ksz8795.c that contains code for ksz88x3 and ksz87xx devices. Also the tag protocol is named DSA_TAG_PROTO_KSZ8795.
Now it seems from function prefixes and ksz_common.h is_ksz8 that in many places ksz8795 should be replaced by ksz8 instead. I don't it's up to me to make this kind of decisions so I went along with the existing naming convention as much as I could but indeed, this specific register I will rename to KSZ87xx_REG_INT_EN.
Thanks, Pieter
PATCH v3 5/5 net: dsa: microchip: apply KSZ87xx family fixes wrt datasheet
In reply to [email protected]From: Pieter Van Trappen <[email protected]>
The KSZ87xx switches have 32 entries and not 8. This fixes -ENOSPC errors from ksz8_add_sta_mac when configured as a bridge.
Add a new ksz87xx_dev_ops structure to be able to use the ksz_r_mib_stat64 pointer for this family; this corrects a wrong mib->counters cast to ksz88xx_stats_raw. This fixes iproute2 statistics.
--- drivers/net/dsa/microchip/ksz_common.c | 47 ++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz_common.c +41 -6
@@ -312,6 +312,41 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .pme_pwrite8 = ksz8_pme_pwrite8, }; +static const struct ksz_dev_ops ksz87xx_dev_ops = { + .setup = ksz8_setup, + .get_port_addr = ksz8_get_port_addr, + .cfg_port_member = ksz8_cfg_port_member, + .flush_dyn_mac_table = ksz8_flush_dyn_mac_table, + .port_setup = ksz8_port_setup, + .r_phy = ksz8_r_phy, + .w_phy = ksz8_w_phy, + .r_mib_cnt = ksz8_r_mib_cnt, + .r_mib_pkt = ksz8_r_mib_pkt, + .r_mib_stat64 = ksz_r_mib_stats64, + .freeze_mib = ksz8_freeze_mib, + .port_init_cnt = ksz8_port_init_cnt, + .fdb_dump = ksz8_fdb_dump, + .fdb_add = ksz8_fdb_add, + .fdb_del = ksz8_fdb_del, + .mdb_add = ksz8_mdb_add, + .mdb_del = ksz8_mdb_del, + .vlan_filtering = ksz8_port_vlan_filtering, + .vlan_add = ksz8_port_vlan_add, + .vlan_del = ksz8_port_vlan_del, + .mirror_add = ksz8_port_mirror_add, + .mirror_del = ksz8_port_mirror_del, + .get_caps = ksz8_get_caps, + .config_cpu_port = ksz8_config_cpu_port, + .enable_stp_addr = ksz8_enable_stp_addr, + .reset = ksz8_reset_switch, + .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, struct phy_device *phydev, unsigned int mode,
@@ -1262,12 +1297,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8795", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names,
@@ -1303,12 +1338,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8794", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names,
@@ -1330,12 +1365,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8765", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names,
Signature · 1 line
2.43.0
Re: [PATCH net-next v3 5/5] net: dsa: microchip: apply KSZ87xx family fixes wrt datasheet
Hi Pieter,
Quoted 31 lines · On Tue, 2024-08-06 at 15:25 +0200, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
From: Pieter Van Trappen <[email protected]>
The KSZ87xx switches have 32 entries and not 8. This fixes
-ENOSPCerrors fromksz8_add_sta_macwhen configured as a bridge.Add a new
ksz87xx_dev_opsstructure to be able to use theksz_r_mib_stat64pointer for this family; this corrects a wrongmib->counterscast toksz88xx_stats_raw. This fixes iproute2 statistics.Signed-off-by Pieter Van Trappen <[email protected]>---
static void ksz9477_phylink_mac_link_up(struct
phylink_config
*config,
structphy_device*phydev, unsigned int mode,drivers/net/dsa/microchip/ksz_common.c +1
-1@@ -1262,12 +1297,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8795", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpuport */
.port_cnt = 5, /* total cpu and user ports
*/
Quoted 3 lines
.num_tx_queues = 4, .num_ipms = 4,- .ops =
&ksz8_dev_ops,
Why don't we rename ksz8_dev_ops also like KSZ88x3_dev_ops or KSZ88xx_dev_ops, since it is now used only by KSZ8863 and KSZ8873 switches.
Re: [PATCH net-next v3 5/5] net: dsa: microchip: apply KSZ87xx family fixes wrt datasheet
Quoted 34 lines · On Wed 7 Aug 2024 at 05:41, <[email protected]> wrote:
Hi Pieter,
Quoted 30 lines · On Tue, 2024-08-06 at 15:25 +0200, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
From: Pieter Van Trappen <[email protected]>
The KSZ87xx switches have 32 entries and not 8. This fixes
-ENOSPCerrors fromksz8_add_sta_macwhen configured as a bridge.Add a new
ksz87xx_dev_opsstructure to be able to use theksz_r_mib_stat64pointer for this family; this corrects a wrongmib->counterscast toksz88xx_stats_raw. This fixes iproute2 statistics.Signed-off-by Pieter Van Trappen <[email protected]>---
static void ksz9477_phylink_mac_link_up(struct
phylink_config
*config,
structphy_device*phydev, unsigned int mode,drivers/net/dsa/microchip/ksz_common.c +1
-1@@ -1262,12 +1297,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8795", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpuport */
.port_cnt = 5, /* total cpu and user ports
Quoted 8 lines
Quoted 4 lines
*/
.num_tx_queues = 4, .num_ipms = 4,- .ops =
&ksz8_dev_ops,Why don't we rename
ksz8_dev_opsalso likeKSZ88x3_dev_opsorKSZ88xx_dev_ops, since it is now used only by KSZ8863 and KSZ8873 switches.
Hi Arun, indeed that would make more sense. Will rename to ksz88x3_dev_ops, consistent with the ksz_is_* function names in ksz_common.h.
Thanks, Pieter