Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: sparx5: fix source port register when mirroring

When port mirroring is added to a port, the bit position of the source
port, needs to be written to the register ANA_AC_PROBE_PORT_CFG. This
register is replicated for n_ports > 32, and therefore we need to derive
the correct register from the port number.

Before this patch, we wrongly calculate the register from portno /
BITS_PER_BYTE, where the divisor ought to be 32, causing any port >=8 to
be written to the wrong register. We fix this, by using do_div(), where
the dividend is the register, the remainder is the bit position and the
divisor is now 32.

Fixes: 4e50d72b3b95 ("net: sparx5: add port mirroring implementation")
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241009-mirroring-fix-v1-1-9ec962301989@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Daniel Machon and committed by
Jakub Kicinski
8a6be4bd 22600596

+6 -6
+6 -6
drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c
··· 31 31 /* Add port to mirror (only front ports) */ 32 32 static void sparx5_mirror_port_add(struct sparx5 *sparx5, u32 idx, u32 portno) 33 33 { 34 - u32 val, reg = portno; 34 + u64 reg = portno; 35 + u32 val; 35 36 36 - reg = portno / BITS_PER_BYTE; 37 - val = BIT(portno % BITS_PER_BYTE); 37 + val = BIT(do_div(reg, 32)); 38 38 39 39 if (reg == 0) 40 40 return spx5_rmw(val, val, sparx5, ANA_AC_PROBE_PORT_CFG(idx)); ··· 45 45 /* Delete port from mirror (only front ports) */ 46 46 static void sparx5_mirror_port_del(struct sparx5 *sparx5, u32 idx, u32 portno) 47 47 { 48 - u32 val, reg = portno; 48 + u64 reg = portno; 49 + u32 val; 49 50 50 - reg = portno / BITS_PER_BYTE; 51 - val = BIT(portno % BITS_PER_BYTE); 51 + val = BIT(do_div(reg, 32)); 52 52 53 53 if (reg == 0) 54 54 return spx5_rmw(0, val, sparx5, ANA_AC_PROBE_PORT_CFG(idx));