Skip to content

Commit 31c25b9

Browse files
jpirkodavem330
authored andcommitted
mlxsw: spectrum_span: Put buffsize update code into helper function
Avoid duplication of code that is doing buffsize update and put it into a separate helper function. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ac9cc4e commit 31c25b9

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -754,26 +754,25 @@ static int mlxsw_sp_span_mtu_to_buffsize(const struct mlxsw_sp *mlxsw_sp,
754754
return mlxsw_sp_bytes_cells(mlxsw_sp, mtu * 5 / 2) + 1;
755755
}
756756

757-
int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu)
757+
static int
758+
mlxsw_sp_span_port_buffsize_update(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
758759
{
759-
struct mlxsw_sp *mlxsw_sp = port->mlxsw_sp;
760+
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
760761
char sbib_pl[MLXSW_REG_SBIB_LEN];
761-
int err;
762+
u32 buffsize;
762763

764+
buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp, mtu);
765+
mlxsw_reg_sbib_pack(sbib_pl, mlxsw_sp_port->local_port, buffsize);
766+
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbib), sbib_pl);
767+
}
768+
769+
int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu)
770+
{
763771
/* If port is egress mirrored, the shared buffer size should be
764772
* updated according to the mtu value
765773
*/
766-
if (mlxsw_sp_span_is_egress_mirror(port)) {
767-
u32 buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp, mtu);
768-
769-
mlxsw_reg_sbib_pack(sbib_pl, port->local_port, buffsize);
770-
err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbib), sbib_pl);
771-
if (err) {
772-
netdev_err(port->dev, "Could not update shared buffer for mirroring\n");
773-
return err;
774-
}
775-
}
776-
774+
if (mlxsw_sp_span_is_egress_mirror(port))
775+
return mlxsw_sp_span_port_buffsize_update(port, mtu);
777776
return 0;
778777
}
779778

@@ -836,15 +835,9 @@ mlxsw_sp_span_inspected_port_add(struct mlxsw_sp_port *port,
836835

837836
/* if it is an egress SPAN, bind a shared buffer to it */
838837
if (type == MLXSW_SP_SPAN_EGRESS) {
839-
u32 buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp,
840-
port->dev->mtu);
841-
842-
mlxsw_reg_sbib_pack(sbib_pl, port->local_port, buffsize);
843-
err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbib), sbib_pl);
844-
if (err) {
845-
netdev_err(port->dev, "Could not create shared buffer for mirroring\n");
838+
err = mlxsw_sp_span_port_buffsize_update(port, port->dev->mtu);
839+
if (err)
846840
return err;
847-
}
848841
}
849842

850843
if (bind) {

0 commit comments

Comments
 (0)