diff mbox series

[net-next,12/13] net: dsa: lantiq_gswip: Add and use a GSWIP_TABLE_MAC_BRIDGE_FID macro

Message ID 20240606085234.565551-13-ms@dev.tdt.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: lantiq_gswip: code improvements | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 901 this patch: 901
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 905 this patch: 905
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 905 this patch: 905
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-07--09-00 (tests: 1041)

Commit Message

Martin Schiller June 6, 2024, 8:52 a.m. UTC
From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a
macro so this becomes obvious when reading the driver code.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/dsa/lantiq_gswip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Vladimir Oltean June 7, 2024, 11:36 a.m. UTC | #1
On Thu, Jun 06, 2024 at 10:52:33AM +0200, Martin Schiller wrote:
> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> 
> Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a
> macro so this becomes obvious when reading the driver code.
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
>  drivers/net/dsa/lantiq_gswip.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
> index f2faee112e33..4bb894e75b81 100644
> --- a/drivers/net/dsa/lantiq_gswip.c
> +++ b/drivers/net/dsa/lantiq_gswip.c
> @@ -238,6 +238,7 @@
>  #define GSWIP_TABLE_MAC_BRIDGE		0x0b
>  #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging entry */
>  #define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned entries */
> +#define  GSWIP_TABLE_MAC_BRIDGE_FID	GENMASK(5, 0)	/* Filtering identifier */
>  
>  #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
>  
> @@ -1385,7 +1386,7 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
>  	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
>  	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
>  	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
> -	mac_bridge.key[3] = fid;
> +	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
>  	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
>  	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
>  	mac_bridge.valid = add;
> -- 
> 2.39.2

On second thought, I disagree with the naming scheme of the
GSWIP_TABLE_MAC_BRIDGE_* macros. It is completely non obvious that they
are non-overlapping, because they have the same name prefix, but:
_STATIC applies to gswip_pce_table_entry :: val[1]
_PORT applies to gswip_pce_table_entry :: val[0]
_FID applies to gswip_pce_table_entry :: key[3]

I think it's all too easy to use the wrong macro on the wrong register field.
If the macros incorporated names like VAL1, KEY3 etc, it would be much
more obvious. Could you please do that?
Martin Schiller June 7, 2024, 2:27 p.m. UTC | #2
On 2024-06-07 13:36, Vladimir Oltean wrote:
> On Thu, Jun 06, 2024 at 10:52:33AM +0200, Martin Schiller wrote:
>> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>> 
>> Only bits [5:0] in mac_bridge.key[3] are reserved for the FID. Add a
>> macro so this becomes obvious when reading the driver code.
>> 
>> Signed-off-by: Martin Blumenstingl 
>> <martin.blumenstingl@googlemail.com>
>> ---
>>  drivers/net/dsa/lantiq_gswip.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/dsa/lantiq_gswip.c 
>> b/drivers/net/dsa/lantiq_gswip.c
>> index f2faee112e33..4bb894e75b81 100644
>> --- a/drivers/net/dsa/lantiq_gswip.c
>> +++ b/drivers/net/dsa/lantiq_gswip.c
>> @@ -238,6 +238,7 @@
>>  #define GSWIP_TABLE_MAC_BRIDGE		0x0b
>>  #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging 
>> entry */
>>  #define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned 
>> entries */
>> +#define  GSWIP_TABLE_MAC_BRIDGE_FID	GENMASK(5, 0)	/* Filtering 
>> identifier */
>> 
>>  #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
>> 
>> @@ -1385,7 +1386,7 @@ static int gswip_port_fdb(struct dsa_switch *ds, 
>> int port,
>>  	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
>>  	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
>>  	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
>> -	mac_bridge.key[3] = fid;
>> +	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
>>  	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
>>  	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
>>  	mac_bridge.valid = add;
>> --
>> 2.39.2
> 
> On second thought, I disagree with the naming scheme of the
> GSWIP_TABLE_MAC_BRIDGE_* macros. It is completely non obvious that they
> are non-overlapping, because they have the same name prefix, but:
> _STATIC applies to gswip_pce_table_entry :: val[1]
> _PORT applies to gswip_pce_table_entry :: val[0]
> _FID applies to gswip_pce_table_entry :: key[3]
> 
> I think it's all too easy to use the wrong macro on the wrong register 
> field.
> If the macros incorporated names like VAL1, KEY3 etc, it would be much
> more obvious. Could you please do that?

OK, so I'll change the macro names to

GSWIP_TABLE_MAC_BRIDGE_KEY3_FID
GSWIP_TABLE_MAC_BRIDGE_VAL0_PORT
GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC

Also the comment of GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC should be changed 
to
/* Static, not aging entry */

While looking again at this diff above, I noticed that val[0] is set
incorrectly. Shouldn't it be either "port << 4" or (after the previous 
patch)
"FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_PORT, port);" instead of "BIT(port)"?
Martin Schiller June 10, 2024, 6:04 a.m. UTC | #3
On 2024-06-07 16:27, Martin Schiller wrote:
> While looking again at this diff above, I noticed that val[0] is set
> incorrectly. Shouldn't it be either "port << 4" or (after the previous 
> patch)
> "FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_PORT, port);" instead of 
> "BIT(port)"?

Please ignore this comment. The format of the port specification differs
for static and dynamic (learned) entries.
diff mbox series

Patch

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index f2faee112e33..4bb894e75b81 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -238,6 +238,7 @@ 
 #define GSWIP_TABLE_MAC_BRIDGE		0x0b
 #define  GSWIP_TABLE_MAC_BRIDGE_STATIC	BIT(0)		/* Static not, aging entry */
 #define  GSWIP_TABLE_MAC_BRIDGE_PORT	GENMASK(7, 4)	/* Port on learned entries */
+#define  GSWIP_TABLE_MAC_BRIDGE_FID	GENMASK(5, 0)	/* Filtering identifier */
 
 #define XRX200_GPHY_FW_ALIGN	(16 * 1024)
 
@@ -1385,7 +1386,7 @@  static int gswip_port_fdb(struct dsa_switch *ds, int port,
 	mac_bridge.key[0] = addr[5] | (addr[4] << 8);
 	mac_bridge.key[1] = addr[3] | (addr[2] << 8);
 	mac_bridge.key[2] = addr[1] | (addr[0] << 8);
-	mac_bridge.key[3] = fid;
+	mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_FID, fid);
 	mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
 	mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
 	mac_bridge.valid = add;