Skip to content

Commit 8b0587a

Browse files
armratnerkuba-moo
authored andcommitted
net/mlx5e: Preserve shared buffer capacity during headroom updates
When port buffer headroom changes, port_update_shared_buffer() recalculates the shared buffer size and splits it in a 3:1 ratio (lossy:lossless) - Currently, the calculation is: lossless = shared / 4; lossy = (shared / 4) * 3; Meaning, the calculation dropped the remainder of shared % 4 due to integer division, unintentionally reducing the total shared buffer by up to three cells on each update. Over time, this could shrink the buffer below usable size. Fix it by changing the calculation to: lossless = shared / 4; lossy = shared - lossless; This retains all buffer cells while still approximating the intended 3:1 split, preventing capacity loss over time. While at it, perform headroom calculations in units of cells rather than in bytes for more accurate calculations avoiding extra divisions. Fixes: a440030 ("net/mlx5e: Update shared buffer along with device buffer changes") Signed-off-by: Armen Ratner <[email protected]> Signed-off-by: Maher Sanalla <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Alexei Lazar <[email protected]> Signed-off-by: Mark Bloch <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 451d284 commit 8b0587a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ static int port_update_shared_buffer(struct mlx5_core_dev *mdev,
272272
/* Total shared buffer size is split in a ratio of 3:1 between
273273
* lossy and lossless pools respectively.
274274
*/
275-
lossy_epool_size = (shared_buffer_size / 4) * 3;
276275
lossless_ipool_size = shared_buffer_size / 4;
276+
lossy_epool_size = shared_buffer_size - lossless_ipool_size;
277277

278278
mlx5e_port_set_sbpr(mdev, 0, MLX5_EGRESS_DIR, MLX5_LOSSY_POOL, 0,
279279
lossy_epool_size);
@@ -288,14 +288,12 @@ static int port_set_buffer(struct mlx5e_priv *priv,
288288
u16 port_buff_cell_sz = priv->dcbx.port_buff_cell_sz;
289289
struct mlx5_core_dev *mdev = priv->mdev;
290290
int sz = MLX5_ST_SZ_BYTES(pbmc_reg);
291-
u32 new_headroom_size = 0;
292-
u32 current_headroom_size;
291+
u32 current_headroom_cells = 0;
292+
u32 new_headroom_cells = 0;
293293
void *in;
294294
int err;
295295
int i;
296296

297-
current_headroom_size = port_buffer->headroom_size;
298-
299297
in = kzalloc(sz, GFP_KERNEL);
300298
if (!in)
301299
return -ENOMEM;
@@ -306,12 +304,14 @@ static int port_set_buffer(struct mlx5e_priv *priv,
306304

307305
for (i = 0; i < MLX5E_MAX_NETWORK_BUFFER; i++) {
308306
void *buffer = MLX5_ADDR_OF(pbmc_reg, in, buffer[i]);
307+
current_headroom_cells += MLX5_GET(bufferx_reg, buffer, size);
308+
309309
u64 size = port_buffer->buffer[i].size;
310310
u64 xoff = port_buffer->buffer[i].xoff;
311311
u64 xon = port_buffer->buffer[i].xon;
312312

313-
new_headroom_size += size;
314313
do_div(size, port_buff_cell_sz);
314+
new_headroom_cells += size;
315315
do_div(xoff, port_buff_cell_sz);
316316
do_div(xon, port_buff_cell_sz);
317317
MLX5_SET(bufferx_reg, buffer, size, size);
@@ -320,10 +320,8 @@ static int port_set_buffer(struct mlx5e_priv *priv,
320320
MLX5_SET(bufferx_reg, buffer, xon_threshold, xon);
321321
}
322322

323-
new_headroom_size /= port_buff_cell_sz;
324-
current_headroom_size /= port_buff_cell_sz;
325-
err = port_update_shared_buffer(priv->mdev, current_headroom_size,
326-
new_headroom_size);
323+
err = port_update_shared_buffer(priv->mdev, current_headroom_cells,
324+
new_headroom_cells);
327325
if (err)
328326
goto out;
329327

0 commit comments

Comments
 (0)