net: dsa: bcm_sf2: refactor LED regs access
PATCH 1/1 net: dsa: bcm_sf2: refactor LED regs access
From: Rafał Miłecki <[email protected]>
1. Define more regs. Some switches (e.g. BCM4908) have up to 6 regs.
2. Add helper for handling non-lineral port <-> reg mappings.
3. Add support for 12 B LED reg blocks on BCM4908 (different layout)
Complete support for LEDs setup will be implemented once Linux receives a proper design & implementation for "hardware" LEDs.
--- drivers/net/dsa/bcm_sf2.c | 60 +++++++++++++++++++++++++++---- drivers/net/dsa/bcm_sf2.h | 10 ++++++ drivers/net/dsa/bcm_sf2_regs.h | 65 +++++++++++++++++++++++++++++++--- 3 files changed, 125 insertions(+), 10 deletions(-)
drivers/net/dsa/bcm_sf2.c +54 -6
@@ -62,6 +62,44 @@ static u16 bcm_sf2_reg_rgmii_cntrl(struct bcm_sf2_priv *priv, int port)return REG_SWITCH_STATUS ; } +static u16 bcm_sf2_reg_led_base (struct bcm_sf2_priv *priv,int port) +{ +switch (priv->type) { +case BCM4908_DEVICE_ID : +switch (port) { +case 0 : +return REG_LED_0_CNTRL ; +case 1 : +return REG_LED_1_CNTRL ; +case 2 : +return REG_LED_2_CNTRL ; +case 3 : +return REG_LED_3_CNTRL ; +case 7 : +return REG_LED_4_CNTRL ; +default : +break ; + } +break ; +default : +switch (port) { +case 0 : +return REG_LED_0_CNTRL ; +case 1 : +return REG_LED_1_CNTRL ; +case 2 : +return REG_LED_2_CNTRL ; +default : +break ; + } + } + +WARN_ONCE (1 ,"Unsupported port %d\n" , port); + +/* RO fallback reg */ +return REG_SWITCH_STATUS ; +} +/* Return the number of active ports, not counting the IMP (CPU) port */ static unsigned int bcm_sf2_num_active_ports (struct dsa_switch *ds) {
@@ -187,9 +225,14 @@ static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable)/* Use PHY-driven LED signaling */ if (!enable) { - reg =reg_readl (priv,REG_LED_CNTRL (0 )); - reg |=SPDLNK_SRC_SEL ; -reg_writel (priv, reg,REG_LED_CNTRL (0 )); +u16 led_ctrl =bcm_sf2_reg_led_base (priv,0 ); + +if (priv->type ==BCM7278_DEVICE_ID || + priv->type ==BCM7445_DEVICE_ID ) { + reg =reg_led_readl (priv, led_ctrl,0 ); + reg |=LED_CNTRL_SPDLNK_SRC_SEL ; +reg_led_writel (priv, reg, led_ctrl,0 ); + } } }
@@ -1232,9 +1275,14 @@ static const u16 bcm_sf2_4908_reg_offsets[] = { [REG_SPHY_CNTRL] = 0x24, [REG_CROSSBAR] = 0xc8, [REG_RGMII_11_CNTRL] = 0x014c, - [REG_LED_0_CNTRL] = 0x40, - [REG_LED_1_CNTRL] = 0x4c, - [REG_LED_2_CNTRL] = 0x58, + [REG_LED_0_CNTRL] = 0x40, + [REG_LED_1_CNTRL] = 0x4c, + [REG_LED_2_CNTRL] = 0x58, + [REG_LED_3_CNTRL] = 0x64, + [REG_LED_4_CNTRL] = 0x88, + [REG_LED_5_CNTRL] = 0xa0, + [REG_LED_AGGREGATE_CTRL] = 0xb8, + };static const struct bcm_sf2_of_data bcm_sf2_4908_data = {
drivers/net/dsa/bcm_sf2.h +10 -0
@@ -210,6 +210,16 @@ SF2_IO_MACRO(acb);SWITCH_INTR_L2 (0 );SWITCH_INTR_L2 (1 ); +static inline u32 reg_led_readl (struct bcm_sf2_priv *priv,u16 off,u16 reg) +{ +return readl_relaxed (priv->reg + priv->reg_offsets[off] + reg); +} + +static inline void reg_led_writel (struct bcm_sf2_priv *priv,u32 val,u16 off,u16 reg) +{ +writel_relaxed (val, priv->reg + priv->reg_offsets[off] + reg); +} +/* RXNFC */ int bcm_sf2_get_rxnfc (struct dsa_switch *ds,int port,struct ethtool_rxnfc *nfc,u32 *rule_locs);
drivers/net/dsa/bcm_sf2_regs.h +61 -4
83 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 10 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
1. Define more regs. Some switches (e.g. BCM4908) have up to 6 regs.
2. Add helper for handling non-lineral port <-> reg mappings.
3. Add support for 12 B LED reg blocks on BCM4908 (different layout)Complete support for LEDs setup will be implemented once Linux receives a proper design & implementation for "hardware" LEDs.
Signed-off-by Rafał Miłecki <[email protected]>
This looks good for the most part, just one nit below:
Quoted 15 lines
--- drivers/net/dsa/bcm_sf2.c | 60 +++++++++++++++++++++++++++---- drivers/net/dsa/bcm_sf2.h | 10 ++++++ drivers/net/dsa/bcm_sf2_regs.h | 65 +++++++++++++++++++++++++++++++--- 3 files changed, 125 insertions(+), 10 deletions(-)drivers/net/dsa/bcm_sf2.c +1
-0@@ -62,6 +62,44 @@ static u16 bcm_sf2_reg_rgmii_cntrl(struct bcm_sf2_priv *priv, int port)return REG_SWITCH_STATUS ; } +static u16 bcm_sf2_reg_led_base (struct bcm_sf2_priv *priv,int port)
drivers/net/dsa/bcm_sf2.c static u16 bcm_sf2_reg_rgmii_cntrl(struct bcm_sf2_priv *priv, int port) · line 75
Quoted 10 lines
drivers/net/dsa/bcm_sf2.c +10
-0+{ +switch (priv->type) { +case BCM4908_DEVICE_ID : +switch (port) { +case 0 : +return REG_LED_0_CNTRL ; +case 1 : +return REG_LED_1_CNTRL ; +case 2 : +return REG_LED_2_CNTRL ;
Up until that port count, we have a common path, it is only after port > 2 that we stop having a common path. Only BCM7445 and BCM7278 have two external ports, 63138 (and 63148 when that gets added eventually) as well as a 4908 have more ports, so I would do something like this:
switch (port) {
case 0:
return REG_LED_0_CNTRL; case 1: return REG_LED_1_CNTRL; case 2: return REG_LED_2_CNTRL; default: break; }
if (priv->type == BCM7445_DEVICE_ID || priv->type == BCM7278_DEVICE_ID)
goto out;
Also, this LED controller is also present in the GENETv5 adapters, so we may have some value in writing a common LED framework driver for it at some point.
Thanks!
Signature · 1 line
Florian
PATCH v2 1/1 net: dsa: bcm_sf2: refactor LED regs access
In reply to Rafał MiłeckiFrom: Rafał Miłecki <[email protected]>
1. Define more regs. Some switches (e.g. BCM4908) have up to 6 regs.
2. Add helper for handling non-lineral port <-> reg mappings.
3. Add support for 12 B LED reg blocks on BCM4908 (different layout)
Complete support for LEDs setup will be implemented once Linux receives a proper design & implementation for "hardware" LEDs.
---
V2: bcm_sf2_reg_led_base(): share code for ports 0, 1 and 2
--- drivers/net/dsa/bcm_sf2.c | 54 ++++++++++++++++++++++++---- drivers/net/dsa/bcm_sf2.h | 10 ++++++ drivers/net/dsa/bcm_sf2_regs.h | 65 +++++++++++++++++++++++++++++++--- 3 files changed, 119 insertions(+), 10 deletions(-)
drivers/net/dsa/bcm_sf2.c +48 -6
@@ -62,6 +62,38 @@ static u16 bcm_sf2_reg_rgmii_cntrl(struct bcm_sf2_priv *priv, int port)return REG_SWITCH_STATUS ; } +static u16 bcm_sf2_reg_led_base (struct bcm_sf2_priv *priv,int port) +{ +switch (port) { +case 0 : +return REG_LED_0_CNTRL ; +case 1 : +return REG_LED_1_CNTRL ; +case 2 : +return REG_LED_2_CNTRL ; + } + +switch (priv->type) { +case BCM4908_DEVICE_ID : +switch (port) { +case 3 : +return REG_LED_3_CNTRL ; +case 7 : +return REG_LED_4_CNTRL ; +default : +break ; + } +break ; +default : +break ; + } + +WARN_ONCE (1 ,"Unsupported port %d\n" , port); + +/* RO fallback reg */ +return REG_SWITCH_STATUS ; +} +/* Return the number of active ports, not counting the IMP (CPU) port */ static unsigned int bcm_sf2_num_active_ports (struct dsa_switch *ds) {
@@ -187,9 +219,14 @@ static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable)/* Use PHY-driven LED signaling */ if (!enable) { - reg =reg_readl (priv,REG_LED_CNTRL (0 )); - reg |=SPDLNK_SRC_SEL ; -reg_writel (priv, reg,REG_LED_CNTRL (0 )); +u16 led_ctrl =bcm_sf2_reg_led_base (priv,0 ); + +if (priv->type ==BCM7278_DEVICE_ID || + priv->type ==BCM7445_DEVICE_ID ) { + reg =reg_led_readl (priv, led_ctrl,0 ); + reg |=LED_CNTRL_SPDLNK_SRC_SEL ; +reg_led_writel (priv, reg, led_ctrl,0 ); + } } }
@@ -1232,9 +1269,14 @@ static const u16 bcm_sf2_4908_reg_offsets[] = { [REG_SPHY_CNTRL] = 0x24, [REG_CROSSBAR] = 0xc8, [REG_RGMII_11_CNTRL] = 0x014c, - [REG_LED_0_CNTRL] = 0x40, - [REG_LED_1_CNTRL] = 0x4c, - [REG_LED_2_CNTRL] = 0x58, + [REG_LED_0_CNTRL] = 0x40, + [REG_LED_1_CNTRL] = 0x4c, + [REG_LED_2_CNTRL] = 0x58, + [REG_LED_3_CNTRL] = 0x64, + [REG_LED_4_CNTRL] = 0x88, + [REG_LED_5_CNTRL] = 0xa0, + [REG_LED_AGGREGATE_CTRL] = 0xb8, + };static const struct bcm_sf2_of_data bcm_sf2_4908_data = {
drivers/net/dsa/bcm_sf2.h +10 -0
@@ -210,6 +210,16 @@ SF2_IO_MACRO(acb);SWITCH_INTR_L2 (0 );SWITCH_INTR_L2 (1 ); +static inline u32 reg_led_readl (struct bcm_sf2_priv *priv,u16 off,u16 reg) +{ +return readl_relaxed (priv->reg + priv->reg_offsets[off] + reg); +} + +static inline void reg_led_writel (struct bcm_sf2_priv *priv,u32 val,u16 off,u16 reg) +{ +writel_relaxed (val, priv->reg + priv->reg_offsets[off] + reg); +} +/* RXNFC */ int bcm_sf2_get_rxnfc (struct dsa_switch *ds,int port,struct ethtool_rxnfc *nfc,u32 *rule_locs);
drivers/net/dsa/bcm_sf2_regs.h +61 -4
83 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 10 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
1. Define more regs. Some switches (e.g. BCM4908) have up to 6 regs.
2. Add helper for handling non-lineral port <-> reg mappings.
3. Add support for 12 B LED reg blocks on BCM4908 (different layout)Complete support for LEDs setup will be implemented once Linux receives a proper design & implementation for "hardware" LEDs.
Signed-off-by Rafał Miłecki <[email protected]>
Signature · 1 line
Florian
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 29 Dec 2021 18:16:42 +0100 you wrote:
From: Rafał Miłecki <[email protected]>
1. Define more regs. Some switches (e.g. BCM4908) have up to 6 regs.
2. Add helper for handling non-lineral port <-> reg mappings.
3. Add support for 12 B LED reg blocks on BCM4908 (different layout)Complete support for LEDs setup will be implemented once Linux receives a proper design & implementation for "hardware" LEDs.
[...]
Here is the summary with links:
- [V2] net: dsa: bcm_sf2: refactor LED regs access
https://git.kernel.org/netdev/net-next/c/af30f8eaa8fe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html