Skip to content

Commit ff9fdfe

Browse files
jpirkodavem330
authored andcommitted
mlxsw: spectrum: Fix SPAN egress mirroring buffer size for Spectrum-2
For SPAN egress mirroring buffer size, it is needed to use a different formula for Spectrum and Spectrum-2. Move the buffer size computation to ops and implement new formula for Spectrum-2. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 31c25b9 commit ff9fdfe

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ struct mlxsw_sp_ptp_ops {
195195
u64 *data, int data_index);
196196
};
197197

198+
struct mlxsw_sp_span_ops {
199+
u32 (*buffsize_get)(int mtu, u32 speed);
200+
};
201+
198202
static int mlxsw_sp_component_query(struct mlxfw_dev *mlxfw_dev,
199203
u16 component_index, u32 *p_max_size,
200204
u8 *p_align_bits, u16 *p_max_write_size)
@@ -4914,6 +4918,33 @@ static const struct mlxsw_sp_ptp_ops mlxsw_sp2_ptp_ops = {
49144918
.get_stats = mlxsw_sp2_get_stats,
49154919
};
49164920

4921+
static u32 mlxsw_sp1_span_buffsize_get(int mtu, u32 speed)
4922+
{
4923+
return mtu * 5 / 2;
4924+
}
4925+
4926+
static const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops = {
4927+
.buffsize_get = mlxsw_sp1_span_buffsize_get,
4928+
};
4929+
4930+
#define MLXSW_SP2_SPAN_EG_MIRROR_BUFFER_FACTOR 38
4931+
4932+
static u32 mlxsw_sp2_span_buffsize_get(int mtu, u32 speed)
4933+
{
4934+
return 3 * mtu + MLXSW_SP2_SPAN_EG_MIRROR_BUFFER_FACTOR * speed / 1000;
4935+
}
4936+
4937+
static const struct mlxsw_sp_span_ops mlxsw_sp2_span_ops = {
4938+
.buffsize_get = mlxsw_sp2_span_buffsize_get,
4939+
};
4940+
4941+
u32 mlxsw_sp_span_buffsize_get(struct mlxsw_sp *mlxsw_sp, int mtu, u32 speed)
4942+
{
4943+
u32 buffsize = mlxsw_sp->span_ops->buffsize_get(speed, mtu);
4944+
4945+
return mlxsw_sp_bytes_cells(mlxsw_sp, buffsize) + 1;
4946+
}
4947+
49174948
static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
49184949
unsigned long event, void *ptr);
49194950

@@ -5135,6 +5166,7 @@ static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
51355166
mlxsw_sp->sb_vals = &mlxsw_sp1_sb_vals;
51365167
mlxsw_sp->port_type_speed_ops = &mlxsw_sp1_port_type_speed_ops;
51375168
mlxsw_sp->ptp_ops = &mlxsw_sp1_ptp_ops;
5169+
mlxsw_sp->span_ops = &mlxsw_sp1_span_ops;
51385170
mlxsw_sp->listeners = mlxsw_sp1_listener;
51395171
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
51405172

@@ -5160,6 +5192,7 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
51605192
mlxsw_sp->sb_vals = &mlxsw_sp2_sb_vals;
51615193
mlxsw_sp->port_type_speed_ops = &mlxsw_sp2_port_type_speed_ops;
51625194
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
5195+
mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
51635196

51645197
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
51655198
}
@@ -5181,6 +5214,7 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
51815214
mlxsw_sp->sb_vals = &mlxsw_sp2_sb_vals;
51825215
mlxsw_sp->port_type_speed_ops = &mlxsw_sp2_port_type_speed_ops;
51835216
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
5217+
mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
51845218

51855219
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
51865220
}

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct mlxsw_sp_sb_vals;
140140
struct mlxsw_sp_port_type_speed_ops;
141141
struct mlxsw_sp_ptp_state;
142142
struct mlxsw_sp_ptp_ops;
143+
struct mlxsw_sp_span_ops;
143144

144145
struct mlxsw_sp_port_mapping {
145146
u8 module;
@@ -185,6 +186,7 @@ struct mlxsw_sp {
185186
const struct mlxsw_sp_sb_vals *sb_vals;
186187
const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
187188
const struct mlxsw_sp_ptp_ops *ptp_ops;
189+
const struct mlxsw_sp_span_ops *span_ops;
188190
const struct mlxsw_listener *listeners;
189191
size_t listeners_count;
190192
};
@@ -502,6 +504,7 @@ int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
502504
unsigned int *p_counter_index);
503505
void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
504506
unsigned int counter_index);
507+
u32 mlxsw_sp_span_buffsize_get(struct mlxsw_sp *mlxsw_sp, int mtu, u32 speed);
505508
bool mlxsw_sp_port_dev_check(const struct net_device *dev);
506509
struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
507510
struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -748,20 +748,22 @@ static bool mlxsw_sp_span_is_egress_mirror(struct mlxsw_sp_port *port)
748748
return false;
749749
}
750750

751-
static int mlxsw_sp_span_mtu_to_buffsize(const struct mlxsw_sp *mlxsw_sp,
752-
int mtu)
753-
{
754-
return mlxsw_sp_bytes_cells(mlxsw_sp, mtu * 5 / 2) + 1;
755-
}
756-
757751
static int
758752
mlxsw_sp_span_port_buffsize_update(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
759753
{
760754
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
761755
char sbib_pl[MLXSW_REG_SBIB_LEN];
762756
u32 buffsize;
757+
u32 speed;
758+
int err;
759+
760+
err = mlxsw_sp_port_speed_get(mlxsw_sp_port, &speed);
761+
if (err)
762+
return err;
763+
if (speed == SPEED_UNKNOWN)
764+
speed = 0;
763765

764-
buffsize = mlxsw_sp_span_mtu_to_buffsize(mlxsw_sp, mtu);
766+
buffsize = mlxsw_sp_span_buffsize_get(mlxsw_sp, speed, mtu);
765767
mlxsw_reg_sbib_pack(sbib_pl, mlxsw_sp_port->local_port, buffsize);
766768
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbib), sbib_pl);
767769
}

0 commit comments

Comments
 (0)