Skip to content

Commit

Permalink
net: sparx5: fix source port register when mirroring
Browse files Browse the repository at this point in the history
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: 4e50d72 ("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>
  • Loading branch information
Danielmachon authored and kuba-moo committed Oct 11, 2024
1 parent 2260059 commit 8a6be4b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ static u64 sparx5_mirror_port_get(struct sparx5 *sparx5, u32 idx)
/* Add port to mirror (only front ports) */
static void sparx5_mirror_port_add(struct sparx5 *sparx5, u32 idx, u32 portno)
{
u32 val, reg = portno;
u64 reg = portno;
u32 val;

reg = portno / BITS_PER_BYTE;
val = BIT(portno % BITS_PER_BYTE);
val = BIT(do_div(reg, 32));

if (reg == 0)
return spx5_rmw(val, val, sparx5, ANA_AC_PROBE_PORT_CFG(idx));
Expand All @@ -45,10 +45,10 @@ static void sparx5_mirror_port_add(struct sparx5 *sparx5, u32 idx, u32 portno)
/* Delete port from mirror (only front ports) */
static void sparx5_mirror_port_del(struct sparx5 *sparx5, u32 idx, u32 portno)
{
u32 val, reg = portno;
u64 reg = portno;
u32 val;

reg = portno / BITS_PER_BYTE;
val = BIT(portno % BITS_PER_BYTE);
val = BIT(do_div(reg, 32));

if (reg == 0)
return spx5_rmw(0, val, sparx5, ANA_AC_PROBE_PORT_CFG(idx));
Expand Down

0 comments on commit 8a6be4b

Please sign in to comment.