diff mbox series

[net-next,2/2] net: enetc: don't depend on system endianness in enetc_set_mac_ht_flt

Message ID 20210324154455.1899941-2-olteanv@gmail.com (mailing list archive)
State Accepted
Commit e366a39208e58ef460b9539e235413dc2b10bc75
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] net: enetc: don't depend on system endianness in enetc_set_vlan_ht_filter | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Vladimir Oltean March 24, 2021, 3:44 p.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

When enetc runs out of exact match entries for unicast address
filtering, it switches to an approach based on hash tables, where
multiple MAC addresses might end up in the same bucket.

However, the enetc_set_mac_ht_flt function currently depends on the
system endianness, because it interprets the 64-bit hash value as an
array of two u32 elements. Modify this to use lower_32_bits and
upper_32_bits.

Tested by forcing enetc to go into hash table mode by creating two
macvlan upper interfaces:

ip link add link eno0 address 00:01:02:03:00:00 eno0.0 type macvlan && ip link set eno0.0 up
ip link add link eno0 address 00:01:02:03:00:01 eno0.1 type macvlan && ip link set eno0.1 up

and verified that the same bit values are written to the registers
before and after:

enetc_sync_mac_filters: addr 00:00:80:00:40:10 exact match 0
enetc_sync_mac_filters: addr 00:00:00:00:80:00 exact match 0
enetc_set_mac_ht_flt: hash 0x80008000000000 UMHFR0 0x0 UMHFR1 0x800080

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc_pf.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Claudiu Manoil March 24, 2021, 4:21 p.m. UTC | #1
>-----Original Message-----
>From: Vladimir Oltean <olteanv@gmail.com>
>Sent: Wednesday, March 24, 2021 5:45 PM
>To: Jakub Kicinski <kuba@kernel.org>; David S. Miller
><davem@davemloft.net>
>Cc: netdev@vger.kernel.org; Claudiu Manoil <claudiu.manoil@nxp.com>;
>Vladimir Oltean <vladimir.oltean@nxp.com>
>Subject: [PATCH net-next 2/2] net: enetc: don't depend on system
>endianness in enetc_set_mac_ht_flt
>
>From: Vladimir Oltean <vladimir.oltean@nxp.com>
>
>When enetc runs out of exact match entries for unicast address
>filtering, it switches to an approach based on hash tables, where
>multiple MAC addresses might end up in the same bucket.
>
>However, the enetc_set_mac_ht_flt function currently depends on the
>system endianness, because it interprets the 64-bit hash value as an
>array of two u32 elements. Modify this to use lower_32_bits and
>upper_32_bits.
>
>Tested by forcing enetc to go into hash table mode by creating two
>macvlan upper interfaces:
>
>ip link add link eno0 address 00:01:02:03:00:00 eno0.0 type macvlan && ip link
>set eno0.0 up
>ip link add link eno0 address 00:01:02:03:00:01 eno0.1 type macvlan && ip link
>set eno0.1 up
>
>and verified that the same bit values are written to the registers
>before and after:
>
>enetc_sync_mac_filters: addr 00:00:80:00:40:10 exact match 0
>enetc_sync_mac_filters: addr 00:00:00:00:80:00 exact match 0
>enetc_set_mac_ht_flt: hash 0x80008000000000 UMHFR0 0x0 UMHFR1
>0x800080
>
>Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 9c69ca516192..5e95afd61c87 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -129,16 +129,20 @@  static void enetc_clear_mac_ht_flt(struct enetc_si *si, int si_idx, int type)
 }
 
 static void enetc_set_mac_ht_flt(struct enetc_si *si, int si_idx, int type,
-				 u32 *hash)
+				 unsigned long hash)
 {
 	bool err = si->errata & ENETC_ERR_UCMCSWP;
 
 	if (type == UC) {
-		enetc_port_wr(&si->hw, ENETC_PSIUMHFR0(si_idx, err), *hash);
-		enetc_port_wr(&si->hw, ENETC_PSIUMHFR1(si_idx), *(hash + 1));
+		enetc_port_wr(&si->hw, ENETC_PSIUMHFR0(si_idx, err),
+			      lower_32_bits(hash));
+		enetc_port_wr(&si->hw, ENETC_PSIUMHFR1(si_idx),
+			      upper_32_bits(hash));
 	} else { /* MC */
-		enetc_port_wr(&si->hw, ENETC_PSIMMHFR0(si_idx, err), *hash);
-		enetc_port_wr(&si->hw, ENETC_PSIMMHFR1(si_idx), *(hash + 1));
+		enetc_port_wr(&si->hw, ENETC_PSIMMHFR0(si_idx, err),
+			      lower_32_bits(hash));
+		enetc_port_wr(&si->hw, ENETC_PSIMMHFR1(si_idx),
+			      upper_32_bits(hash));
 	}
 }
 
@@ -182,7 +186,7 @@  static void enetc_sync_mac_filters(struct enetc_pf *pf)
 		if (i == UC)
 			enetc_clear_mac_flt_entry(si, pos);
 
-		enetc_set_mac_ht_flt(si, 0, i, (u32 *)f->mac_hash_table);
+		enetc_set_mac_ht_flt(si, 0, i, *f->mac_hash_table);
 	}
 }