Skip to content

Commit 0cda1a9

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum_buffers: Convert mlxsw_sp_port_headroom_init()
Currently mlxsw_sp_port_headroom_init() configures both priomap and buffers by hand. Additionally, for port buffers, it configures buffer 0 with a size that it will never again have if PFC configuration is touched. Rewrite the init code to become a client of the new hdroom code. The only difference in invocation is that the configuration is forced, so that it is issued even if the desired configuration happens to match what is contained in (hitherto not initialized with meaningful values) mlxsw_sp_port->hdroom. Since now mlxsw_sp_port_headroom_init() initializes all the PG buffers to meaningful values, mlxsw_sp_hdroom_configure_buffers() can avoid querying the current configuration, and can fill the whole PBMC itself. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bd3e86a commit 0cda1a9

File tree

1 file changed

+23
-52
lines changed

1 file changed

+23
-52
lines changed

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

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -286,47 +286,6 @@ static int mlxsw_sp_sb_pm_occ_query(struct mlxsw_sp *mlxsw_sp, u8 local_port,
286286
(unsigned long) pm);
287287
}
288288

289-
/* 1/4 of a headroom necessary for 100Gbps port and 100m cable. */
290-
#define MLXSW_SP_PB_HEADROOM 25632
291-
#define MLXSW_SP_PB_UNUSED 8
292-
293-
static int mlxsw_sp_port_pb_init(struct mlxsw_sp_port *mlxsw_sp_port)
294-
{
295-
const u32 pbs[] = {
296-
[0] = MLXSW_SP_PB_HEADROOM * mlxsw_sp_port->mapping.width,
297-
[9] = MLXSW_PORT_MAX_MTU,
298-
};
299-
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
300-
char pbmc_pl[MLXSW_REG_PBMC_LEN];
301-
int i;
302-
303-
mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port,
304-
0xffff, 0xffff / 2);
305-
for (i = 0; i < ARRAY_SIZE(pbs); i++) {
306-
u16 size = mlxsw_sp_bytes_cells(mlxsw_sp, pbs[i]);
307-
308-
if (i == MLXSW_SP_PB_UNUSED)
309-
continue;
310-
size = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, size);
311-
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, i, size);
312-
}
313-
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl,
314-
MLXSW_REG_PBMC_PORT_SHARED_BUF_IDX, 0);
315-
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);
316-
}
317-
318-
static int mlxsw_sp_port_pb_prio_init(struct mlxsw_sp_port *mlxsw_sp_port)
319-
{
320-
char pptb_pl[MLXSW_REG_PPTB_LEN];
321-
int i;
322-
323-
mlxsw_reg_pptb_pack(pptb_pl, mlxsw_sp_port->local_port);
324-
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
325-
mlxsw_reg_pptb_prio_to_buff_pack(pptb_pl, i, 0);
326-
return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pptb),
327-
pptb_pl);
328-
}
329-
330289
void mlxsw_sp_hdroom_prios_reset_buf_idx(struct mlxsw_sp_hdroom *hdroom)
331290
{
332291
int prio;
@@ -422,6 +381,8 @@ void mlxsw_sp_hdroom_bufs_reset_sizes(struct mlxsw_sp_port *mlxsw_sp_port,
422381
}
423382
}
424383

384+
#define MLXSW_SP_PB_UNUSED 8
385+
425386
static int mlxsw_sp_hdroom_configure_buffers(struct mlxsw_sp_port *mlxsw_sp_port,
426387
const struct mlxsw_sp_hdroom *hdroom, bool force)
427388
{
@@ -435,14 +396,13 @@ static int mlxsw_sp_hdroom_configure_buffers(struct mlxsw_sp_port *mlxsw_sp_port
435396
if (!dirty && !force)
436397
return 0;
437398

438-
mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port, 0, 0);
439-
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);
440-
if (err)
441-
return err;
442-
443-
for (i = 0; i < DCBX_MAX_BUFFERS; i++) {
399+
mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port, 0xffff, 0xffff / 2);
400+
for (i = 0; i < MLXSW_SP_PB_COUNT; i++) {
444401
const struct mlxsw_sp_hdroom_buf *buf = &hdroom->bufs.buf[i];
445402

403+
if (i == MLXSW_SP_PB_UNUSED)
404+
continue;
405+
446406
mlxsw_sp_hdroom_buf_pack(pbmc_pl, i, buf->size_cells, buf->thres_cells, buf->lossy);
447407
}
448408

@@ -548,12 +508,23 @@ int mlxsw_sp_hdroom_configure(struct mlxsw_sp_port *mlxsw_sp_port,
548508

549509
static int mlxsw_sp_port_headroom_init(struct mlxsw_sp_port *mlxsw_sp_port)
550510
{
551-
int err;
511+
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
512+
struct mlxsw_sp_hdroom hdroom = {};
513+
u32 size9;
514+
int prio;
552515

553-
err = mlxsw_sp_port_pb_init(mlxsw_sp_port);
554-
if (err)
555-
return err;
556-
return mlxsw_sp_port_pb_prio_init(mlxsw_sp_port);
516+
hdroom.mtu = mlxsw_sp_port->dev->mtu;
517+
for (prio = 0; prio < IEEE_8021QAZ_MAX_TCS; prio++)
518+
hdroom.prios.prio[prio].lossy = true;
519+
520+
mlxsw_sp_hdroom_bufs_reset_lossiness(&hdroom);
521+
mlxsw_sp_hdroom_bufs_reset_sizes(mlxsw_sp_port, &hdroom);
522+
523+
/* Buffer 9 is used for control traffic. */
524+
size9 = mlxsw_sp_port_headroom_8x_adjust(mlxsw_sp_port, mlxsw_sp_port->max_mtu);
525+
hdroom.bufs.buf[9].size_cells = mlxsw_sp_bytes_cells(mlxsw_sp, size9);
526+
527+
return __mlxsw_sp_hdroom_configure(mlxsw_sp_port, &hdroom, true);
557528
}
558529

559530
static int mlxsw_sp_sb_port_init(struct mlxsw_sp *mlxsw_sp,

0 commit comments

Comments
 (0)