Skip to content

Commit f417f04

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum: Refactor port buffer configuration
The sizes and thresholds of the priority group (PG) buffers are configured in cells, which represent a specific amount of bytes. The cell size can vary in different devices, so it's better to query it from the firmware than hard coding it. Refactor the code dealing with this value into different functions, so that it will be easier to make the conversion in the next patch. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d3daae1 commit f417f04

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -800,19 +800,40 @@ static int mlxsw_sp_port_set_mac_address(struct net_device *dev, void *p)
800800
return 0;
801801
}
802802

803-
static void mlxsw_sp_pg_buf_pack(char *pbmc_pl, int pg_index, int mtu,
804-
bool pause_en, bool pfc_en, u16 delay)
803+
static u16 mlxsw_sp_pg_buf_threshold_get(int mtu)
805804
{
806-
u16 pg_size = 2 * MLXSW_SP_BYTES_TO_CELLS(mtu);
805+
return 2 * MLXSW_SP_BYTES_TO_CELLS(mtu);
806+
}
807807

808-
delay = pfc_en ? mlxsw_sp_pfc_delay_get(mtu, delay) :
809-
MLXSW_SP_PAUSE_DELAY;
808+
#define MLXSW_SP_CELL_FACTOR 2 /* 2 * cell_size / (IPG + cell_size + 1) */
809+
static u16 mlxsw_sp_pfc_delay_get(int mtu, u16 delay)
810+
{
811+
delay = MLXSW_SP_BYTES_TO_CELLS(DIV_ROUND_UP(delay, BITS_PER_BYTE));
812+
return MLXSW_SP_CELL_FACTOR * delay + MLXSW_SP_BYTES_TO_CELLS(mtu);
813+
}
810814

811-
if (pause_en || pfc_en)
812-
mlxsw_reg_pbmc_lossless_buffer_pack(pbmc_pl, pg_index,
813-
pg_size + delay, pg_size);
815+
/* Maximum delay buffer needed in case of PAUSE frames, in cells.
816+
* Assumes 100m cable and maximum MTU.
817+
*/
818+
#define MLXSW_SP_PAUSE_DELAY 612
819+
static u16 mlxsw_sp_pg_buf_delay_get(int mtu, u16 delay, bool pfc, bool pause)
820+
{
821+
if (pfc)
822+
return mlxsw_sp_pfc_delay_get(mtu, delay);
823+
else if (pause)
824+
return MLXSW_SP_PAUSE_DELAY;
814825
else
815-
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, pg_index, pg_size);
826+
return 0;
827+
}
828+
829+
static void mlxsw_sp_pg_buf_pack(char *pbmc_pl, int index, u16 size, u16 thres,
830+
bool lossy)
831+
{
832+
if (lossy)
833+
mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, index, size);
834+
else
835+
mlxsw_reg_pbmc_lossless_buffer_pack(pbmc_pl, index, size,
836+
thres);
816837
}
817838

818839
int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
@@ -833,6 +854,8 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
833854
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
834855
bool configure = false;
835856
bool pfc = false;
857+
bool lossy;
858+
u16 thres;
836859

837860
for (j = 0; j < IEEE_8021QAZ_MAX_TCS; j++) {
838861
if (prio_tc[j] == i) {
@@ -844,7 +867,11 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
844867

845868
if (!configure)
846869
continue;
847-
mlxsw_sp_pg_buf_pack(pbmc_pl, i, mtu, pause_en, pfc, delay);
870+
871+
lossy = !(pfc || pause_en);
872+
thres = mlxsw_sp_pg_buf_threshold_get(mtu);
873+
delay = mlxsw_sp_pg_buf_delay_get(mtu, delay, pfc, pause_en);
874+
mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres + delay, thres, lossy);
848875
}
849876

850877
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@
7373
#define MLXSW_SP_KVD_LINEAR_SIZE 65536 /* entries */
7474
#define MLXSW_SP_KVD_GRANULARITY 128
7575

76-
/* Maximum delay buffer needed in case of PAUSE frames, in cells.
77-
* Assumes 100m cable and maximum MTU.
78-
*/
79-
#define MLXSW_SP_PAUSE_DELAY 612
80-
81-
#define MLXSW_SP_CELL_FACTOR 2 /* 2 * cell_size / (IPG + cell_size + 1) */
82-
83-
static inline u16 mlxsw_sp_pfc_delay_get(int mtu, u16 delay)
84-
{
85-
delay = MLXSW_SP_BYTES_TO_CELLS(DIV_ROUND_UP(delay, BITS_PER_BYTE));
86-
return MLXSW_SP_CELL_FACTOR * delay + MLXSW_SP_BYTES_TO_CELLS(mtu);
87-
}
88-
8976
struct mlxsw_sp_port;
9077
struct mlxsw_sp_rif;
9178

0 commit comments

Comments
 (0)