Skip to content

Commit 4f3961e

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: Introduce physical port TC/prio access functions
Add access functions to set and query a physical port TC groups and prio parameters. Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ad909eb commit 4f3961e

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

drivers/net/ethernet/mellanox/mlx5/core/port.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,79 @@ int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx, u8 *pfc_en_rx)
405405
return 0;
406406
}
407407
EXPORT_SYMBOL_GPL(mlx5_query_port_pfc);
408+
409+
int mlx5_max_tc(struct mlx5_core_dev *mdev)
410+
{
411+
u8 num_tc = MLX5_CAP_GEN(mdev, max_tc) ? : 8;
412+
413+
return num_tc - 1;
414+
}
415+
416+
int mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, u8 *prio_tc)
417+
{
418+
u32 in[MLX5_ST_SZ_DW(qtct_reg)];
419+
u32 out[MLX5_ST_SZ_DW(qtct_reg)];
420+
int err;
421+
int i;
422+
423+
memset(in, 0, sizeof(in));
424+
for (i = 0; i < 8; i++) {
425+
if (prio_tc[i] > mlx5_max_tc(mdev))
426+
return -EINVAL;
427+
428+
MLX5_SET(qtct_reg, in, prio, i);
429+
MLX5_SET(qtct_reg, in, tclass, prio_tc[i]);
430+
431+
err = mlx5_core_access_reg(mdev, in, sizeof(in), out,
432+
sizeof(out), MLX5_REG_QTCT, 0, 1);
433+
if (err)
434+
return err;
435+
}
436+
437+
return 0;
438+
}
439+
EXPORT_SYMBOL_GPL(mlx5_set_port_prio_tc);
440+
441+
static int mlx5_set_port_qetcr_reg(struct mlx5_core_dev *mdev, u32 *in,
442+
int inlen)
443+
{
444+
u32 out[MLX5_ST_SZ_DW(qtct_reg)];
445+
446+
if (!MLX5_CAP_GEN(mdev, ets))
447+
return -ENOTSUPP;
448+
449+
return mlx5_core_access_reg(mdev, in, inlen, out, sizeof(out),
450+
MLX5_REG_QETCR, 0, 1);
451+
}
452+
453+
int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group)
454+
{
455+
u32 in[MLX5_ST_SZ_DW(qetc_reg)];
456+
int i;
457+
458+
memset(in, 0, sizeof(in));
459+
460+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
461+
MLX5_SET(qetc_reg, in, tc_configuration[i].g, 1);
462+
MLX5_SET(qetc_reg, in, tc_configuration[i].group, tc_group[i]);
463+
}
464+
465+
return mlx5_set_port_qetcr_reg(mdev, in, sizeof(in));
466+
}
467+
EXPORT_SYMBOL_GPL(mlx5_set_port_tc_group);
468+
469+
int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw)
470+
{
471+
u32 in[MLX5_ST_SZ_DW(qetc_reg)];
472+
int i;
473+
474+
memset(in, 0, sizeof(in));
475+
476+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
477+
MLX5_SET(qetc_reg, in, tc_configuration[i].b, 1);
478+
MLX5_SET(qetc_reg, in, tc_configuration[i].bw_allocation, tc_bw[i]);
479+
}
480+
481+
return mlx5_set_port_qetcr_reg(mdev, in, sizeof(in));
482+
}
483+
EXPORT_SYMBOL_GPL(mlx5_set_port_tc_bw_alloc);

include/linux/mlx5/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ enum {
9999
};
100100

101101
enum {
102+
MLX5_REG_QETCR = 0x4005,
103+
MLX5_REG_QTCT = 0x400a,
102104
MLX5_REG_PCAP = 0x5001,
103105
MLX5_REG_PMTU = 0x5003,
104106
MLX5_REG_PTYS = 0x5004,

include/linux/mlx5/mlx5_ifc.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,9 @@ struct mlx5_ifc_cmd_hca_cap_bits {
729729

730730
u8 reserved_at_1bf[0x3];
731731
u8 log_max_msg[0x5];
732-
u8 reserved_at_1c7[0x18];
732+
u8 reserved_at_1c7[0x4];
733+
u8 max_tc[0x4];
734+
u8 reserved_at_1cf[0x10];
733735

734736
u8 stat_rate_support[0x10];
735737
u8 reserved_at_1ef[0xc];
@@ -7061,4 +7063,49 @@ struct mlx5_ifc_modify_flow_table_in_bits {
70617063
u8 reserved_at_100[0x100];
70627064
};
70637065

7066+
struct mlx5_ifc_ets_tcn_config_reg_bits {
7067+
u8 g[0x1];
7068+
u8 b[0x1];
7069+
u8 r[0x1];
7070+
u8 reserved_at_3[0x9];
7071+
u8 group[0x4];
7072+
u8 reserved_at_10[0x9];
7073+
u8 bw_allocation[0x7];
7074+
7075+
u8 reserved_at_20[0xc];
7076+
u8 max_bw_units[0x4];
7077+
u8 reserved_at_30[0x8];
7078+
u8 max_bw_value[0x8];
7079+
};
7080+
7081+
struct mlx5_ifc_ets_global_config_reg_bits {
7082+
u8 reserved_at_0[0x2];
7083+
u8 r[0x1];
7084+
u8 reserved_at_3[0x1d];
7085+
7086+
u8 reserved_at_20[0xc];
7087+
u8 max_bw_units[0x4];
7088+
u8 reserved_at_30[0x8];
7089+
u8 max_bw_value[0x8];
7090+
};
7091+
7092+
struct mlx5_ifc_qetc_reg_bits {
7093+
u8 reserved_at_0[0x8];
7094+
u8 port_number[0x8];
7095+
u8 reserved_at_10[0x30];
7096+
7097+
struct mlx5_ifc_ets_tcn_config_reg_bits tc_configuration[0x8];
7098+
struct mlx5_ifc_ets_global_config_reg_bits global_configuration;
7099+
};
7100+
7101+
struct mlx5_ifc_qtct_reg_bits {
7102+
u8 reserved_at_0[0x8];
7103+
u8 port_number[0x8];
7104+
u8 reserved_at_10[0xd];
7105+
u8 prio[0x3];
7106+
7107+
u8 reserved_at_20[0x1d];
7108+
u8 tclass[0x3];
7109+
};
7110+
70647111
#endif /* MLX5_IFC_H */

include/linux/mlx5/port.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ int mlx5_set_port_pfc(struct mlx5_core_dev *dev, u8 pfc_en_tx, u8 pfc_en_rx);
7070
int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx,
7171
u8 *pfc_en_rx);
7272

73+
int mlx5_max_tc(struct mlx5_core_dev *mdev);
74+
75+
int mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, u8 *prio_tc);
76+
int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group);
77+
int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw);
78+
7379
#endif /* __MLX5_PORT_H__ */

0 commit comments

Comments
 (0)