mv88e6xxx: Cache scratch config3 of 6352
Subsystems (4)
v2 cover mv88e6xxx: Cache scratch config3 of 6352
In mv88e6352 scratch register in Global Control 2 set of registers returns which port is attached to SERDES. This value is a pin strapping value and is set after the switch is released from reset. Thus, it can be cached during chip setup instead of reading the register everytime when SERDES check is needed.
The series consist of 4 parts:
1. Add new mv88e6352_reset function as ops->reset
2. Cache the register value in this reset function
3. Refactor mv88e6352_g2_scratch_port_has_serdes to use the cached value.
4. Remove the locks surrounding mv88e6352_g2_scratch_port_has_serdes.
---
v2 changes:
- Fix the documentation of the return value for the new function mv88e6352_g2_cache_global_scratch_config3
as addressed by Jakub Kicinski
v1 link:
https://lore.kernel.org/netdev/[email protected]/
Changes after RFC:
- Separate the patch into 4 different patches
- Move caching step into chip->info->ops->reset function
as suggested by Andrew.
RFC link:
https://lore.kernel.org/netdev/[email protected]/
---
Fidan Aliyeva (4):
mv88e6xxx: Add mv88e6352_reset for 6352 family
mv88e6xxx: Cache scratch config3 of 6352
mv88e6xxx: Use cached config3 in 6352 has_serdes
mv88e6xxx: Remove locks for 6352's has_serdes
drivers/net/dsa/mv88e6xxx/chip.c | 25 ++++++++++---- drivers/net/dsa/mv88e6xxx/chip.h | 3 ++ drivers/net/dsa/mv88e6xxx/global2.h | 1 + drivers/net/dsa/mv88e6xxx/global2_scratch.c | 38 ++++++++++++++++----- drivers/net/dsa/mv88e6xxx/pcs-6352.c | 2 -- drivers/net/dsa/mv88e6xxx/serdes.c | 2 -- 6 files changed, 51 insertions(+), 20 deletions(-)
--
2.36.0
PATCH v2 1/4 mv88e6xxx: Add mv88e6352_reset for 6352 family
1. Add mv88e6352_reset which calls the previous ops->reset function
- mv88e6352_g1_reset.
2. Make all 6352 family use this new function as ops->reset
--- drivers/net/dsa/mv88e6xxx/chip.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +13 -4
@@ -3736,6 +3736,15 @@ static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)return mv88e6xxx_software_reset (chip); } +static int mv88e6352_reset (struct mv88e6xxx_chip *chip) +{ +int err; + + err =mv88e6352_g1_reset (chip); + +return err; +} +/* prod_id for switch families which do not have a PHY model number */ static const u16 family_prod_id_table[] = { [MV88E6XXX_FAMILY_6341 ] =MV88E6XXX_PORT_SWITCH_ID_PROD_6341 ,
@@ -4654,7 +4663,7 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .hardware_reset_pre = mv88e6xxx_g2_eeprom_wait, .hardware_reset_post = mv88e6xxx_g2_eeprom_wait, - .reset = mv88e6352_g1_reset, + .reset = mv88e6352_reset, .rmu_disable = mv88e6352_g1_rmu_disable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash,
@@ -4757,7 +4766,7 @@ static const struct mv88e6xxx_ops mv88e6176_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .hardware_reset_pre = mv88e6xxx_g2_eeprom_wait, .hardware_reset_post = mv88e6xxx_g2_eeprom_wait, - .reset = mv88e6352_g1_reset, + .reset = mv88e6352_reset, .rmu_disable = mv88e6352_g1_rmu_disable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash,
@@ -5032,7 +5041,7 @@ static const struct mv88e6xxx_ops mv88e6240_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .hardware_reset_pre = mv88e6xxx_g2_eeprom_wait, .hardware_reset_post = mv88e6xxx_g2_eeprom_wait, - .reset = mv88e6352_g1_reset, + .reset = mv88e6352_reset, .rmu_disable = mv88e6352_g1_rmu_disable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash,
@@ -5463,7 +5472,7 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .pot_clear = mv88e6xxx_g2_pot_clear, .hardware_reset_pre = mv88e6xxx_g2_eeprom_wait, .hardware_reset_post = mv88e6xxx_g2_eeprom_wait, - .reset = mv88e6352_g1_reset, + .reset = mv88e6352_reset, .rmu_disable = mv88e6352_g1_rmu_disable, .atu_get_hash = mv88e6165_g1_atu_get_hash, .atu_set_hash = mv88e6165_g1_atu_set_hash,
--
2.36.0
PATCH v2 2/4 mv88e6xxx: Cache scratch config3 of 6352
In reply to Fidan AliyevaChanges:
1. Add g2_scratch_config3 member to mv88e6xxx_chip.
2. Add mv88e6352_g2_cache_global_scratch_config3 which reads the CONFIG3 value from the scratch register and caches it.
3. Call this function in mv88e6352_reset.
--- drivers/net/dsa/mv88e6xxx/chip.c | 7 +++++- drivers/net/dsa/mv88e6xxx/chip.h | 3 +++ drivers/net/dsa/mv88e6xxx/global2.h | 1 + drivers/net/dsa/mv88e6xxx/global2_scratch.c | 26 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +6 -1
@@ -3736,13 +3736,18 @@ static int mv88e6390_setup_errata(struct mv88e6xxx_chip *chip)return mv88e6xxx_software_reset (chip); } +/* For MV88E6XXX_FAMILY_6352, perform reset on G1 control. +* Also, read and cache G2 scratch register. +*/ static int mv88e6352_reset (struct mv88e6xxx_chip *chip) {int err; err =mv88e6352_g1_reset (chip); +if (err) +return err; -return err; +return mv88e6352_g2_cache_global_scratch_config3 (chip); }/* prod_id for switch families which do not have a PHY model number */
drivers/net/dsa/mv88e6xxx/chip.h +3 -0
@@ -454,6 +454,9 @@ struct mv88e6xxx_chip {/* TCAM entries */ struct mv88e6xxx_tcam tcam; + +/* Global2 scratch register config data3 */ +u8 g2_scratch_config3; };#define TCAM_MATCH_SIZE 96
drivers/net/dsa/mv88e6xxx/global2.h +1 -0
@@ -382,6 +382,7 @@ int mv88e6390_g2_scratch_gpio_set_smi(struct mv88e6xxx_chip *chip, bool external);int mv88e6393x_g2_scratch_gpio_set_smi (struct mv88e6xxx_chip *chip,bool external); +int mv88e6352_g2_cache_global_scratch_config3 (struct mv88e6xxx_chip *chip);int mv88e6352_g2_scratch_port_has_serdes (struct mv88e6xxx_chip *chip,int port);int mv88e6xxx_g2_atu_stats_set (struct mv88e6xxx_chip *chip,u16 kind,u16 bin);int mv88e6xxx_g2_atu_stats_get (struct mv88e6xxx_chip *chip,u16 *stats);
drivers/net/dsa/mv88e6xxx/global2_scratch.c +26 -0
@@ -321,6 +321,32 @@ int mv88e6393x_g2_scratch_gpio_set_smi(struct mv88e6xxx_chip *chip,return mv88e6xxx_g2_scratch_write (chip, misc_cfg, val); } +/** +* mv88e6352_g2_cache_global_scratch_config3 - caches G2 CONFIG3 value +* @chip: chip private data +* +* Reads and stores config3 value of global2 scratch registers, which +* can be used to determine if the port is attached to a serdes. The +* value does not change once the switch is released from reset and +* represents the value of the pin strapping. +* +* Return: negative error number if the register read fails; otherwise, 0 +*/ +int mv88e6352_g2_cache_global_scratch_config3 (struct mv88e6xxx_chip *chip) +{ +u8 config3; +int err; + + err =mv88e6xxx_g2_scratch_read (chip,MV88E6352_G2_SCRATCH_CONFIG_DATA3 , + &config3); +if (err) +return err; + + chip->g2_scratch_config3 = config3; + +return 0 ; +} +/** * mv88e6352_g2_scratch_port_has_serdes - indicate if a port can have a serdes * @chip: chip private data
--
2.36.0
PATCH v2 3/4 mv88e6xxx: Use cached config3 in 6352 has_serdes
In reply to Fidan Aliyeva1. Refactor mv88e6352_g2_scratch_port_has_serdes to use the cached scratch config3 value instead of reading it everytime.
2. Remove err<0 check from mv88e6352_phylink_get_caps as it is never true anymore
--- drivers/net/dsa/mv88e6xxx/chip.c | 3 --- drivers/net/dsa/mv88e6xxx/global2_scratch.c | 18 ++++++------------ 2 files changed, 6 insertions(+), 15 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +0 -3
@@ -685,9 +685,6 @@ static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,/* Port 4 supports automedia if the serdes is associated with it. */ if (port ==4 ) { err =mv88e6352_g2_scratch_port_has_serdes (chip, port); -if (err <0 ) -dev_err (chip->dev,"p%d: failed to read scratch\n" , - port);if (err <=0 )return ;
drivers/net/dsa/mv88e6xxx/global2_scratch.c +6 -12
@@ -348,26 +348,20 @@ int mv88e6352_g2_cache_global_scratch_config3(struct mv88e6xxx_chip *chip) }/** -* mv88e6352_g2_scratch_port_has_serdes - indicate if a port can have a serdes +* mv88e6352_g2_scratch_port_has_serdes - indicate if a port has serdes * @chip: chip private data * @port: port number to check for serdes * * Indicates whether the port may have a serdes attached according to the -* pin strapping. Returns negative error number, 0 if the port is not -* configured to have a serdes, and 1 if the port is configured to have a -* serdes attached. +* pin strapping, which is cached at reset (scratch config3). Returns 0 if +* the port is not configured to have a serdes, and 1 if the port is +* configured to have a serdes attached. */ int mv88e6352_g2_scratch_port_has_serdes (struct mv88e6xxx_chip *chip,int port) { -u8 config3, p; -int err; - - err =mv88e6xxx_g2_scratch_read (chip,MV88E6352_G2_SCRATCH_CONFIG_DATA3 , - &config3); -if (err) -return err; +u8 p; -if (config3 &MV88E6352_G2_SCRATCH_CONFIG_DATA3_S_SEL ) +if (chip->g2_scratch_config3 &MV88E6352_G2_SCRATCH_CONFIG_DATA3_S_SEL ) p =5 ;else p =4 ;
--
2.36.0
PATCH v2 4/4 mv88e6xxx: Remove locks for 6352's has_serdes
In reply to Fidan AliyevaThere is no register access anymore in mv88e6352_g2_scratch_port_has_serdes. So, remove the locks surrounding the function.
--- drivers/net/dsa/mv88e6xxx/pcs-6352.c | 2 -- drivers/net/dsa/mv88e6xxx/serdes.c | 2 -- 2 files changed, 4 deletions(-)
drivers/net/dsa/mv88e6xxx/pcs-6352.c +0 -2
@@ -326,9 +326,7 @@ static int mv88e6352_pcs_init(struct mv88e6xxx_chip *chip, int port)unsigned int irq;int err; -mv88e6xxx_reg_lock (chip); err =mv88e6352_g2_scratch_port_has_serdes (chip, port); -mv88e6xxx_reg_unlock (chip);if (err <=0 )return err;
drivers/net/dsa/mv88e6xxx/serdes.c +0 -2
@@ -202,9 +202,7 @@ int mv88e6352_serdes_get_regs_len(struct mv88e6xxx_chip *chip, int port) {int err; -mv88e6xxx_reg_lock (chip); err =mv88e6352_g2_scratch_port_has_serdes (chip, port); -mv88e6xxx_reg_unlock (chip);if (err <=0 )return err;
--
2.36.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Thu, 21 May 2026 22:29:20 +0200 you wrote:
In mv88e6352 scratch register in Global Control 2 set of registers returns which port is attached to SERDES. This value is a pin strapping value and is set after the switch is released from reset. Thus, it can be cached during chip setup instead of reading the register everytime when SERDES check is needed.
Quoted 8 lines
The series consist of 4 parts:
1. Add newmv88e6352_resetfunction asops->reset
2. Cache the register value in this reset function
3. Refactormv88e6352_g2_scratch_port_has_serdesto use the cached value.
4. Remove the locks surroundingmv88e6352_g2_scratch_port_has_serdes.[...]
Here is the summary with links:
- [net-next,v2,1/4] mv88e6xxx: Add mv88e6352_reset for 6352 family
https://git.kernel.org/netdev/net-next/c/f21395a783ff - [net-next,v2,2/4] mv88e6xxx: Cache scratch config3 of 6352 https://git.kernel.org/netdev/net-next/c/948330d99feb - [net-next,v2,3/4] mv88e6xxx: Use cached config3 in 6352 has_serdes https://git.kernel.org/netdev/net-next/c/da054522e881 - [net-next,v2,4/4] mv88e6xxx: Remove locks for 6352's has_serdes https://git.kernel.org/netdev/net-next/c/e4a9173e38ee
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html