Skip to content

Commit f3fe412

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum: Do not rely on machine endianness
The second commit cited below performed a cast of 'u32 buffsize' to '(u16 *)' when calling mlxsw_sp_port_headroom_8x_adjust(): mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, (u16 *) &buffsize); Colin noted that this will behave differently on big endian architectures compared to little endian architectures. Fix this by following Colin's suggestion and have the function accept and return 'u32' instead of passing the current size by reference. Fixes: da38287 ("mlxsw: spectrum: Extend to support Spectrum-3 ASIC") Fixes: 60833d5 ("mlxsw: spectrum: Adjust headroom buffers for 8x ports") Signed-off-by: Ido Schimmel <[email protected]> Reported-by: Colin Ian King <[email protected]> Suggested-by: Colin Ian King <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6d61f48 commit f3fe412

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,10 +978,10 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
978978

979979
lossy = !(pfc || pause_en);
980980
thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
981-
mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, &thres_cells);
981+
thres_cells = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, thres_cells);
982982
delay_cells = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay,
983983
pfc, pause_en);
984-
mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, &delay_cells);
984+
delay_cells = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, delay_cells);
985985
total_cells = thres_cells + delay_cells;
986986

987987
taken_headroom_cells += total_cells;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,15 @@ mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
374374
return NULL;
375375
}
376376

377-
static inline void
377+
static inline u32
378378
mlxsw_sp_port_headroom_8x_adjust(const struct mlxsw_sp_port *mlxsw_sp_port,
379-
u16 *p_size)
379+
u32 size_cells)
380380
{
381381
/* Ports with eight lanes use two headroom buffers between which the
382382
* configured headroom size is split. Therefore, multiply the calculated
383383
* headroom size by two.
384384
*/
385-
if (mlxsw_sp_port->mapping.width != 8)
386-
return;
387-
*p_size *= 2;
385+
return mlxsw_sp_port->mapping.width == 8 ? 2 * size_cells : size_cells;
388386
}
389387

390388
enum mlxsw_sp_flood_type {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static int mlxsw_sp_port_pb_init(struct mlxsw_sp_port *mlxsw_sp_port)
312312

313313
if (i == MLXSW_SP_PB_UNUSED)
314314
continue;
315-
mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, &size);
315+
size = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, size);
316316
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, i, size);
317317
}
318318
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ mlxsw_sp_span_port_buffer_update(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
782782
speed = 0;
783783

784784
buffsize = mlxsw_sp_span_buffsize_get(mlxsw_sp, speed, mtu);
785-
mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, (u16 *) &buffsize);
785+
buffsize = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, buffsize);
786786
mlxsw_reg_sbib_pack(sbib_pl, mlxsw_sp_port->local_port, buffsize);
787787
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbib), sbib_pl);
788788
}

0 commit comments

Comments
 (0)