Skip to content

Commit 8ef0c04

Browse files
committed
Merge branch 'mlxsw-Update-main-pool-computation-and-pool-size-limits'
Ido Schimmel says: ==================== mlxsw: Update main pool computation and pool size limits Petr says: In Spectrum ASICs, the shared buffer is an area of memory where packets are kept until they can be transmitted. There are two resources associated with shared buffer size: cap_total_buffer_size and cap_guaranteed_shared_buffer. So far, mlxsw has been using the former as a limit when validating shared buffer pool size configuration. However, the total size also includes headrooms and reserved space, which really cannot be used for shared buffer pools. Patch #1 mends this and has mlxsw use the guaranteed size. To configure default pool sizes, mlxsw has historically hard-coded one or two smallish pools, and one "main" pool that took most of the shared buffer (that would be pool 0 on ingress and pool 4 on egress). During the development of Spectrum-2, it became clear that the shared buffer size keeps shrinking as bugs are identified and worked around. In order to prevent having to tweak the size of pools 0 and 4 to catch up with updates to values reported by the FW, patch #2 changes the way these pools are set. Instead of hard-coding a fixed value, the main pool now takes whatever is left from the guaranteed size after the smaller pool(s) are taken into account. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 06cd9da + bc9f6e9 commit 8ef0c04

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum mlxsw_res_id {
2626
MLXSW_RES_ID_MAX_LAG_MEMBERS,
2727
MLXSW_RES_ID_LOCAL_PORTS_IN_1X,
2828
MLXSW_RES_ID_LOCAL_PORTS_IN_2X,
29-
MLXSW_RES_ID_MAX_BUFFER_SIZE,
29+
MLXSW_RES_ID_GUARANTEED_SHARED_BUFFER,
3030
MLXSW_RES_ID_CELL_SIZE,
3131
MLXSW_RES_ID_MAX_HEADROOM_SIZE,
3232
MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS,
@@ -82,7 +82,7 @@ static u16 mlxsw_res_ids[] = {
8282
[MLXSW_RES_ID_MAX_LAG_MEMBERS] = 0x2521,
8383
[MLXSW_RES_ID_LOCAL_PORTS_IN_1X] = 0x2610,
8484
[MLXSW_RES_ID_LOCAL_PORTS_IN_2X] = 0x2611,
85-
[MLXSW_RES_ID_MAX_BUFFER_SIZE] = 0x2802, /* Bytes */
85+
[MLXSW_RES_ID_GUARANTEED_SHARED_BUFFER] = 0x2805, /* Bytes */
8686
[MLXSW_RES_ID_CELL_SIZE] = 0x2803, /* Bytes */
8787
[MLXSW_RES_ID_MAX_HEADROOM_SIZE] = 0x2811, /* Bytes */
8888
[MLXSW_RES_ID_ACL_MAX_TCAM_REGIONS] = 0x2901,

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

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct mlxsw_sp_sb_cm {
3535
};
3636

3737
#define MLXSW_SP_SB_INFI -1U
38+
#define MLXSW_SP_SB_REST -2U
3839

3940
struct mlxsw_sp_sb_pm {
4041
u32 min_buff;
@@ -421,19 +422,16 @@ static void mlxsw_sp_sb_ports_fini(struct mlxsw_sp *mlxsw_sp)
421422
.freeze_size = _freeze_size, \
422423
}
423424

424-
#define MLXSW_SP1_SB_PR_INGRESS_SIZE 12440000
425-
#define MLXSW_SP1_SB_PR_EGRESS_SIZE 13232000
426425
#define MLXSW_SP1_SB_PR_CPU_SIZE (256 * 1000)
427426

428427
/* Order according to mlxsw_sp1_sb_pool_dess */
429428
static const struct mlxsw_sp_sb_pr mlxsw_sp1_sb_prs[] = {
430-
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC,
431-
MLXSW_SP1_SB_PR_INGRESS_SIZE),
429+
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, MLXSW_SP_SB_REST),
432430
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
433431
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
434432
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
435-
MLXSW_SP_SB_PR_EXT(MLXSW_REG_SBPR_MODE_DYNAMIC,
436-
MLXSW_SP1_SB_PR_EGRESS_SIZE, true, false),
433+
MLXSW_SP_SB_PR_EXT(MLXSW_REG_SBPR_MODE_DYNAMIC, MLXSW_SP_SB_REST,
434+
true, false),
437435
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
438436
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
439437
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
@@ -445,19 +443,16 @@ static const struct mlxsw_sp_sb_pr mlxsw_sp1_sb_prs[] = {
445443
MLXSW_SP1_SB_PR_CPU_SIZE, true, false),
446444
};
447445

448-
#define MLXSW_SP2_SB_PR_INGRESS_SIZE 35297568
449-
#define MLXSW_SP2_SB_PR_EGRESS_SIZE 35297568
450446
#define MLXSW_SP2_SB_PR_CPU_SIZE (256 * 1000)
451447

452448
/* Order according to mlxsw_sp2_sb_pool_dess */
453449
static const struct mlxsw_sp_sb_pr mlxsw_sp2_sb_prs[] = {
454-
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC,
455-
MLXSW_SP2_SB_PR_INGRESS_SIZE),
450+
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_DYNAMIC, MLXSW_SP_SB_REST),
456451
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
457452
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
458453
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
459-
MLXSW_SP_SB_PR_EXT(MLXSW_REG_SBPR_MODE_DYNAMIC,
460-
MLXSW_SP2_SB_PR_EGRESS_SIZE, true, false),
454+
MLXSW_SP_SB_PR_EXT(MLXSW_REG_SBPR_MODE_DYNAMIC, MLXSW_SP_SB_REST,
455+
true, false),
461456
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
462457
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
463458
MLXSW_SP_SB_PR(MLXSW_REG_SBPR_MODE_STATIC, 0),
@@ -471,18 +466,44 @@ static const struct mlxsw_sp_sb_pr mlxsw_sp2_sb_prs[] = {
471466

472467
static int mlxsw_sp_sb_prs_init(struct mlxsw_sp *mlxsw_sp,
473468
const struct mlxsw_sp_sb_pr *prs,
469+
const struct mlxsw_sp_sb_pool_des *pool_dess,
474470
size_t prs_len)
475471
{
472+
/* Round down, unlike mlxsw_sp_bytes_cells(). */
473+
u32 sb_cells = mlxsw_sp->sb->sb_size / mlxsw_sp->sb->cell_size;
474+
u32 rest_cells[2] = {sb_cells, sb_cells};
476475
int i;
477476
int err;
478477

478+
/* Calculate how much space to give to the "REST" pools in either
479+
* direction.
480+
*/
481+
for (i = 0; i < prs_len; i++) {
482+
enum mlxsw_reg_sbxx_dir dir = pool_dess[i].dir;
483+
u32 size = prs[i].size;
484+
u32 size_cells;
485+
486+
if (size == MLXSW_SP_SB_INFI || size == MLXSW_SP_SB_REST)
487+
continue;
488+
489+
size_cells = mlxsw_sp_bytes_cells(mlxsw_sp, size);
490+
if (WARN_ON_ONCE(size_cells > rest_cells[dir]))
491+
continue;
492+
493+
rest_cells[dir] -= size_cells;
494+
}
495+
479496
for (i = 0; i < prs_len; i++) {
480497
u32 size = prs[i].size;
481498
u32 size_cells;
482499

483500
if (size == MLXSW_SP_SB_INFI) {
484501
err = mlxsw_sp_sb_pr_write(mlxsw_sp, i, prs[i].mode,
485502
0, true);
503+
} else if (size == MLXSW_SP_SB_REST) {
504+
size_cells = rest_cells[pool_dess[i].dir];
505+
err = mlxsw_sp_sb_pr_write(mlxsw_sp, i, prs[i].mode,
506+
size_cells, false);
486507
} else {
487508
size_cells = mlxsw_sp_bytes_cells(mlxsw_sp, size);
488509
err = mlxsw_sp_sb_pr_write(mlxsw_sp, i, prs[i].mode,
@@ -904,7 +925,7 @@ int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
904925
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, CELL_SIZE))
905926
return -EIO;
906927

907-
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_BUFFER_SIZE))
928+
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, GUARANTEED_SHARED_BUFFER))
908929
return -EIO;
909930

910931
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_HEADROOM_SIZE))
@@ -915,7 +936,7 @@ int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
915936
return -ENOMEM;
916937
mlxsw_sp->sb->cell_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, CELL_SIZE);
917938
mlxsw_sp->sb->sb_size = MLXSW_CORE_RES_GET(mlxsw_sp->core,
918-
MAX_BUFFER_SIZE);
939+
GUARANTEED_SHARED_BUFFER);
919940
max_headroom_size = MLXSW_CORE_RES_GET(mlxsw_sp->core,
920941
MAX_HEADROOM_SIZE);
921942
/* Round down, because this limit must not be overstepped. */
@@ -926,6 +947,7 @@ int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
926947
if (err)
927948
goto err_sb_ports_init;
928949
err = mlxsw_sp_sb_prs_init(mlxsw_sp, mlxsw_sp->sb_vals->prs,
950+
mlxsw_sp->sb_vals->pool_dess,
929951
mlxsw_sp->sb_vals->pool_count);
930952
if (err)
931953
goto err_sb_prs_init;
@@ -1013,7 +1035,8 @@ int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
10131035
mode = (enum mlxsw_reg_sbpr_mode) threshold_type;
10141036
pr = &mlxsw_sp->sb_vals->prs[pool_index];
10151037

1016-
if (size > MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_BUFFER_SIZE)) {
1038+
if (size > MLXSW_CORE_RES_GET(mlxsw_sp->core,
1039+
GUARANTEED_SHARED_BUFFER)) {
10171040
NL_SET_ERR_MSG_MOD(extack, "Exceeded shared buffer size");
10181041
return -EINVAL;
10191042
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ mlxsw_sp_qdisc_red_check_params(struct mlxsw_sp_port *mlxsw_sp_port,
305305
p->max);
306306
return -EINVAL;
307307
}
308-
if (p->max > MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_BUFFER_SIZE)) {
308+
if (p->max > MLXSW_CORE_RES_GET(mlxsw_sp->core,
309+
GUARANTEED_SHARED_BUFFER)) {
309310
dev_err(mlxsw_sp->bus_info->dev,
310311
"spectrum: RED: max value %u is too big\n", p->max);
311312
return -EINVAL;

0 commit comments

Comments
 (0)