net: dsa: microchip: Further regmap cleanups
cover net: dsa: microchip: Further regmap cleanups
This patchset cleans up KSZ9477 switch driver by replacing various ad-hoc polling implementations and register RMW with regmap functions.
Each polling function is replaced separately to make it easier to review and possibly bisect, but maybe the patches can be squashed.
Marek Vasut (5):
net: dsa: microchip: Replace ad-hoc polling with regmap
net: dsa: microchip: Replace ksz9477_wait_vlan_ctrl_ready polling with
regmap
net: dsa: microchip: Replace ksz9477_wait_alu_ready polling with
regmap
net: dsa: microchip: Replace ksz9477_wait_alu_sta_ready polling with
regmap
net: dsa: microchip: Replace bit RMW with regmap
drivers/net/dsa/microchip/ksz9477.c | 128 +++++++++---------------- drivers/net/dsa/microchip/ksz_common.h | 14 --- 2 files changed, 47 insertions(+), 95 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/5 net: dsa: microchip: Replace ad-hoc polling with regmap
Regmap provides polling function to poll for bits in a register, use in instead of reimplementing it.
--- drivers/net/dsa/microchip/ksz9477.c | 14 +++++--------- drivers/net/dsa/microchip/ksz_common.h | 14 -------------- 2 files changed, 5 insertions(+), 23 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +5 -9
@@ -263,12 +263,8 @@ static int ksz9477_reset_switch(struct ksz_device *dev)static void ksz9477_r_mib_cnt (struct ksz_device *dev,int port,u16 addr,u64 *cnt) { -struct ksz_poll_ctx ctx = { - .dev = dev, - .port = port, - .offset =REG_PORT_MIB_CTRL_STAT__4 , - };struct ksz_port *p = &dev->ports[port]; +unsigned int val;u32 data;int ret;
@@ -278,11 +274,11 @@ static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, data |= (addr <<MIB_COUNTER_INDEX_S );ksz_pwrite32 (dev, port,REG_PORT_MIB_CTRL_STAT__4 , data); - ret =readx_poll_timeout (ksz_pread32_poll, &ctx, data, - !(data &MIB_COUNTER_READ ),10 ,1000 ); - + ret =regmap_read_poll_timeout (dev->regmap[2 ], +PORT_CTRL_ADDR (port,REG_PORT_MIB_CTRL_STAT__4 ), + val, !(val &MIB_COUNTER_READ ),10 ,1000 );/* failed to read MIB. get out of loop */ -if (ret <0 ) { +if (ret) {dev_dbg (dev->dev,"Failed to get MIB\n" );return ; }
drivers/net/dsa/microchip/ksz_common.h +0 -14
@@ -119,20 +119,6 @@ static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,ksz_write32 (dev, dev->dev_ops->get_port_addr (port, offset), data); } -struct ksz_poll_ctx { -struct ksz_device *dev; -int port; -int offset; -}; - -static inline u32 ksz_pread32_poll (struct ksz_poll_ctx *ctx) -{ -u32 data; - -ksz_pread32 (ctx->dev, ctx->port, ctx->offset, &data); -return data; -} -/* Regmap tables generation */ #define KSZ_SPI_OP_RD 3#define KSZ_SPI_OP_WR 2
Signature · 1 line
2.20.1
Re: [PATCH 1/5] net: dsa: microchip: Replace ad-hoc polling with regmap
Quoted 4 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register, use in instead of reimplementing it.
Signed-off-by Marek Vasut <[email protected]>
Andrew
Re: [PATCH 1/5] net: dsa: microchip: Replace ad-hoc polling with regmap
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register, use in instead of reimplementing it.
Signed-off-by Marek Vasut <[email protected]>Cc Andrew Lunn <[email protected]>Cc Florian Fainelli <[email protected]>Cc Tristram Ha <[email protected]>Cc Woojung Huh <[email protected]>
Signature · 1 line
Florian
PATCH 2/5 net: dsa: microchip: Replace ksz9477_wait_vlan_ctrl_ready polling with regmap
In reply to Marek VasutRegmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
--- drivers/net/dsa/microchip/ksz9477.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +8 -18
@@ -89,22 +89,12 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset, bits, set ? bits : 0); } -static int ksz9477_wait_vlan_ctrl_ready (struct ksz_device *dev,u32 waiton, -int timeout) +static int ksz9477_wait_vlan_ctrl_ready (struct ksz_device *dev) { -u8 data; - -do { -ksz_read8 (dev,REG_SW_VLAN_CTRL , &data); -if (!(data & waiton)) -break ; -usleep_range (1 ,10 ); - }while (timeout-- >0 ); - -if (timeout <=0 ) -return -ETIMEDOUT ; +unsigned int val; -return 0 ; +return regmap_read_poll_timeout (dev->regmap[0 ],REG_SW_VLAN_CTRL , + val, !(val &VLAN_START ),10 ,1000 ); } static int ksz9477_get_vlan_table(struct ksz_device *dev, u16 vid,
@@ -118,8 +108,8 @@ static int ksz9477_get_vlan_table(struct ksz_device *dev, u16 vid,ksz_write8 (dev,REG_SW_VLAN_CTRL ,VLAN_READ |VLAN_START );/* wait to be cleared */ - ret =ksz9477_wait_vlan_ctrl_ready (dev,VLAN_START ,1000 ); -if (ret <0 ) { + ret =ksz9477_wait_vlan_ctrl_ready (dev); +if (ret) {dev_dbg (dev->dev,"Failed to read vlan table\n" ); goto exit; }
@@ -151,8 +141,8 @@ static int ksz9477_set_vlan_table(struct ksz_device *dev, u16 vid,ksz_write8 (dev,REG_SW_VLAN_CTRL ,VLAN_START |VLAN_WRITE );/* wait to be cleared */ - ret =ksz9477_wait_vlan_ctrl_ready (dev,VLAN_START ,1000 ); -if (ret <0 ) { + ret =ksz9477_wait_vlan_ctrl_ready (dev); +if (ret) {dev_dbg (dev->dev,"Failed to write vlan table\n" ); goto exit; }
Signature · 1 line
2.20.1
Re: [PATCH 2/5] net: dsa: microchip: Replace ksz9477_wait_vlan_ctrl_ready polling with regmap
Quoted 7 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
Signed-off-by Marek Vasut <[email protected]>
Andrew
Re: [PATCH 2/5] net: dsa: microchip: Replace ksz9477_wait_vlan_ctrl_ready polling with regmap
In reply to Marek VasutQuoted 11 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
Signed-off-by Marek Vasut <[email protected]>Cc Andrew Lunn <[email protected]>Cc Florian Fainelli <[email protected]>Cc Tristram Ha <[email protected]>Cc Woojung Huh <[email protected]>
Signature · 1 line
Florian
PATCH 3/5 net: dsa: microchip: Replace ksz9477_wait_alu_ready polling with regmap
In reply to Marek VasutRegmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
--- drivers/net/dsa/microchip/ksz9477.c | 34 ++++++++++------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +12 -22
@@ -176,22 +176,12 @@ static void ksz9477_write_table(struct ksz_device *dev, u32 *table)ksz_write32 (dev,REG_SW_ALU_VAL_D , table[3 ]); } -static int ksz9477_wait_alu_ready (struct ksz_device *dev,u32 waiton, -int timeout) +static int ksz9477_wait_alu_ready (struct ksz_device *dev) { -u32 data; - -do { -ksz_read32 (dev,REG_SW_ALU_CTRL__4 , &data); -if (!(data & waiton)) -break ; -usleep_range (1 ,10 ); - }while (timeout-- >0 ); - -if (timeout <=0 ) -return -ETIMEDOUT ; +unsigned int val; -return 0 ; +return regmap_read_poll_timeout (dev->regmap[2 ],REG_SW_ALU_CTRL__4 , + val, !(val &ALU_START ),10 ,1000 ); } static int ksz9477_wait_alu_sta_ready(struct ksz_device *dev, u32 waiton,
@@ -633,8 +623,8 @@ static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_CTRL__4 ,ALU_READ |ALU_START );/* wait to be finished */ - ret =ksz9477_wait_alu_ready (dev,ALU_START ,1000 ); -if (ret <0 ) { + ret =ksz9477_wait_alu_ready (dev); +if (ret) {dev_dbg (dev->dev,"Failed to read ALU\n" ); goto exit; }
@@ -657,8 +647,8 @@ static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_CTRL__4 ,ALU_WRITE |ALU_START );/* wait to be finished */ - ret =ksz9477_wait_alu_ready (dev,ALU_START ,1000 ); -if (ret <0 ) + ret =ksz9477_wait_alu_ready (dev); +if (ret)dev_dbg (dev->dev,"Failed to write ALU\n" ); exit:
@@ -690,8 +680,8 @@ static int ksz9477_port_fdb_del(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_CTRL__4 ,ALU_READ |ALU_START );/* wait to be finished */ - ret =ksz9477_wait_alu_ready (dev,ALU_START ,1000 ); -if (ret <0 ) { + ret =ksz9477_wait_alu_ready (dev); +if (ret) {dev_dbg (dev->dev,"Failed to read ALU\n" ); goto exit; }
@@ -724,8 +714,8 @@ static int ksz9477_port_fdb_del(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_CTRL__4 ,ALU_WRITE |ALU_START );/* wait to be finished */ - ret =ksz9477_wait_alu_ready (dev,ALU_START ,1000 ); -if (ret <0 ) + ret =ksz9477_wait_alu_ready (dev); +if (ret)dev_dbg (dev->dev,"Failed to write ALU\n" ); exit:
Signature · 1 line
2.20.1
Re: [PATCH 3/5] net: dsa: microchip: Replace ksz9477_wait_alu_ready polling with regmap
Quoted 7 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
Signed-off-by Marek Vasut <[email protected]>
Andrew
PATCH 4/5 net: dsa: microchip: Replace ksz9477_wait_alu_sta_ready polling with regmap
In reply to Marek VasutRegmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
--- drivers/net/dsa/microchip/ksz9477.c | 32 +++++++++++------------------ 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +12 -20
@@ -184,22 +184,14 @@ static int ksz9477_wait_alu_ready(struct ksz_device *dev) val, !(val & ALU_START), 10, 1000); } -static int ksz9477_wait_alu_sta_ready (struct ksz_device *dev,u32 waiton, -int timeout) +static int ksz9477_wait_alu_sta_ready (struct ksz_device *dev) { -u32 data; - -do { -ksz_read32 (dev,REG_SW_ALU_STAT_CTRL__4 , &data); -if (!(data & waiton)) -break ; -usleep_range (1 ,10 ); - }while (timeout-- >0 ); - -if (timeout <=0 ) -return -ETIMEDOUT ; +unsigned int val; -return 0 ; +return regmap_read_poll_timeout (dev->regmap[2 ], +REG_SW_ALU_STAT_CTRL__4 , + val, !(val &ALU_STAT_START ), +10 ,1000 ); }static int ksz9477_reset_switch (struct ksz_device *dev)
@@ -821,7 +813,7 @@ static void ksz9477_port_mdb_add(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data);/* wait to be finished */ -if (ksz9477_wait_alu_sta_ready (dev,ALU_STAT_START ,1000 ) <0 ) { +if (ksz9477_wait_alu_sta_ready (dev)) {dev_dbg (dev->dev,"Failed to read ALU STATIC\n" ); goto exit; }
@@ -862,7 +854,7 @@ static void ksz9477_port_mdb_add(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data);/* wait to be finished */ -if (ksz9477_wait_alu_sta_ready (dev,ALU_STAT_START ,1000 ) <0 ) +if (ksz9477_wait_alu_sta_ready (dev))dev_dbg (dev->dev,"Failed to read ALU STATIC\n" ); exit:
@@ -892,8 +884,8 @@ static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data);/* wait to be finished */ - ret =ksz9477_wait_alu_sta_ready (dev,ALU_STAT_START ,1000 ); -if (ret <0 ) { + ret =ksz9477_wait_alu_sta_ready (dev); +if (ret) {dev_dbg (dev->dev,"Failed to read ALU STATIC\n" ); goto exit; }
@@ -934,8 +926,8 @@ static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port,ksz_write32 (dev,REG_SW_ALU_STAT_CTRL__4 , data);/* wait to be finished */ - ret =ksz9477_wait_alu_sta_ready (dev,ALU_STAT_START ,1000 ); -if (ret <0 ) + ret =ksz9477_wait_alu_sta_ready (dev); +if (ret)dev_dbg (dev->dev,"Failed to read ALU STATIC\n" ); exit:
Signature · 1 line
2.20.1
Re: [PATCH 4/5] net: dsa: microchip: Replace ksz9477_wait_alu_sta_ready polling with regmap
Quoted 7 lines · Marek Vasut
Regmap provides polling function to poll for bits in a register. This function is another reimplementation of polling for bit being clear in a register. Replace this with regmap polling function. Moreover, inline the function parameters, as the function is never called with any other parameter values than this one.
Signed-off-by Marek Vasut <[email protected]>
Andrew
PATCH 5/5 net: dsa: microchip: Replace bit RMW with regmap
In reply to Marek VasutRegmap provides read-modify-write function to update bitfields in registers. Replace ad-hoc read-modify-write with regmap_update_bits() where applicable.
--- drivers/net/dsa/microchip/ksz9477.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +10 -12
@@ -197,16 +197,14 @@ static int ksz9477_wait_alu_sta_ready(struct ksz_device *dev)static int ksz9477_reset_switch (struct ksz_device *dev) {u8 data8; -u16 data16;u32 data32;/* reset switch */ ksz_cfg (dev,REG_SW_OPERATION ,SW_RESET , true);/* turn off SPI DO Edge select */ -ksz_read8 (dev,REG_SW_GLOBAL_SERIAL_CTRL_0 , &data8); - data8 &= ~SPI_AUTO_EDGE_DETECTION ; -ksz_write8 (dev,REG_SW_GLOBAL_SERIAL_CTRL_0 , data8); +regmap_update_bits (dev->regmap[0 ],REG_SW_GLOBAL_SERIAL_CTRL_0 , +SPI_AUTO_EDGE_DETECTION ,0 );/* default configuration */ ksz_read8 (dev,REG_SW_LUE_CTRL_1 , &data8);
@@ -220,10 +218,10 @@ static int ksz9477_reset_switch(struct ksz_device *dev)ksz_read32 (dev,REG_SW_PORT_INT_STATUS__4 , &data32);/* set broadcast storm protection 10% rate */ -ksz_read16 (dev,REG_SW_MAC_CTRL_2 , &data16); - data16 &= ~BROADCAST_STORM_RATE ; - data16 |= (BROADCAST_STORM_VALUE *BROADCAST_STORM_PROT_RATE ) /100 ; -ksz_write16 (dev,REG_SW_MAC_CTRL_2 , data16); +regmap_update_bits (dev->regmap[1 ],REG_SW_MAC_CTRL_2 , +BROADCAST_STORM_RATE , + (BROADCAST_STORM_VALUE * +BROADCAST_STORM_PROT_RATE ) /100 );if (dev->synclko_125) ksz_write8(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1,
@@ -485,10 +483,10 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) {u8 data; -ksz_read8 (dev,REG_SW_LUE_CTRL_2 , &data); - data &= ~(SW_FLUSH_OPTION_M <<SW_FLUSH_OPTION_S ); - data |= (SW_FLUSH_OPTION_DYN_MAC <<SW_FLUSH_OPTION_S ); -ksz_write8 (dev,REG_SW_LUE_CTRL_2 , data); +regmap_update_bits (dev->regmap[0 ],REG_SW_LUE_CTRL_2 , +SW_FLUSH_OPTION_M <<SW_FLUSH_OPTION_S , +SW_FLUSH_OPTION_DYN_MAC <<SW_FLUSH_OPTION_S ); +if (port < dev->mib_port_cnt) {/* flush individual port */ ksz_pread8 (dev, port,P_STP_CTRL , &data);
Signature · 1 line
2.20.1
Re: [PATCH 5/5] net: dsa: microchip: Replace bit RMW with regmap
Quoted 5 lines · Marek Vasut
Regmap provides read-modify-write function to update bitfields in registers. Replace ad-hoc read-modify-write with
regmap_update_bits()where applicable.Signed-off-by Marek Vasut <[email protected]>
Andrew
David Miller
maintainerFrom: Marek Vasut <[email protected]>
Date: Thu, 27 Jun 2019 23:55:51 +0200
Quoted 7 lines
This patchset cleans up KSZ9477 switch driver by replacing various ad-hoc polling implementations and register RMW with regmap functions.
Each polling function is replaced separately to make it easier to review and possibly bisect, but maybe the patches can be squashed.
Signed-off-by Marek Vasut <[email protected]>
Series applied, thanks.
Hi Marek,
Quoted 11 lines · Marek Vasut
This patchset cleans up KSZ9477 switch driver by replacing various ad-hoc polling implementations and register RMW with regmap functions.
Each polling function is replaced separately to make it easier to review and possibly bisect, but maybe the patches can be squashed.
Signed-off-by Marek Vasut <[email protected]>Cc Andrew Lunn <[email protected]>Cc Florian Fainelli <[email protected]>Cc Tristram Ha <[email protected]>Cc Woojung Huh <[email protected]>
Please copy me next time, as per the MAINTAINERS file.
Thanks,
Vivien
Quoted 9 lines · Vivien Didelot
Hi Marek,
Quoted 6 lines · Marek Vasut
This patchset cleans up KSZ9477 switch driver by replacing various ad-hoc polling implementations and register RMW with regmap functions.
Each polling function is replaced separately to make it easier to review and possibly bisect, but maybe the patches can be squashed.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Marek Vasut <[email protected]>Cc Andrew Lunn <[email protected]>Cc Florian Fainelli <[email protected]>Cc Tristram Ha <[email protected]>Cc Woojung Huh <[email protected]>Please copy me next time, as per the
MAINTAINERSfile.
Will do. I plan to submit KSZ8795 support next.
Signature · 2 lines
Best regards, Marek Vasut