Skip to content

Commit d888079

Browse files
Tariq Toukandavem330
authored andcommitted
net/mlx5e: Implement DCBNL IEEE max rate
Add support for DCBNL IEEE get/set max rate. Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ef91843 commit d888079

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
#define MLX5E_MAX_PRIORITY 8
3737

38+
#define MLX5E_100MB (100000)
39+
#define MLX5E_1GB (1000000)
40+
3841
static int mlx5e_dcbnl_ieee_getets(struct net_device *netdev,
3942
struct ieee_ets *ets)
4043
{
@@ -219,9 +222,79 @@ static u8 mlx5e_dcbnl_setdcbx(struct net_device *dev, u8 mode)
219222
return 0;
220223
}
221224

225+
static int mlx5e_dcbnl_ieee_getmaxrate(struct net_device *netdev,
226+
struct ieee_maxrate *maxrate)
227+
{
228+
struct mlx5e_priv *priv = netdev_priv(netdev);
229+
struct mlx5_core_dev *mdev = priv->mdev;
230+
u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
231+
u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
232+
int err;
233+
int i;
234+
235+
err = mlx5_query_port_ets_rate_limit(mdev, max_bw_value, max_bw_unit);
236+
if (err)
237+
return err;
238+
239+
memset(maxrate->tc_maxrate, 0, sizeof(maxrate->tc_maxrate));
240+
241+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
242+
switch (max_bw_unit[i]) {
243+
case MLX5_100_MBPS_UNIT:
244+
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_100MB;
245+
break;
246+
case MLX5_GBPS_UNIT:
247+
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_1GB;
248+
break;
249+
case MLX5_BW_NO_LIMIT:
250+
break;
251+
default:
252+
WARN(true, "non-supported BW unit");
253+
break;
254+
}
255+
}
256+
257+
return 0;
258+
}
259+
260+
static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
261+
struct ieee_maxrate *maxrate)
262+
{
263+
struct mlx5e_priv *priv = netdev_priv(netdev);
264+
struct mlx5_core_dev *mdev = priv->mdev;
265+
u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
266+
u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
267+
__u64 upper_limit_mbps = roundup(255 * MLX5E_100MB, MLX5E_1GB);
268+
int i;
269+
270+
memset(max_bw_value, 0, sizeof(max_bw_value));
271+
memset(max_bw_unit, 0, sizeof(max_bw_unit));
272+
273+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
274+
if (!maxrate->tc_maxrate[i]) {
275+
max_bw_unit[i] = MLX5_BW_NO_LIMIT;
276+
continue;
277+
}
278+
if (maxrate->tc_maxrate[i] < upper_limit_mbps) {
279+
max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
280+
MLX5E_100MB);
281+
max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
282+
max_bw_unit[i] = MLX5_100_MBPS_UNIT;
283+
} else {
284+
max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
285+
MLX5E_1GB);
286+
max_bw_unit[i] = MLX5_GBPS_UNIT;
287+
}
288+
}
289+
290+
return mlx5_modify_port_ets_rate_limit(mdev, max_bw_value, max_bw_unit);
291+
}
292+
222293
const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops = {
223294
.ieee_getets = mlx5e_dcbnl_ieee_getets,
224295
.ieee_setets = mlx5e_dcbnl_ieee_setets,
296+
.ieee_getmaxrate = mlx5e_dcbnl_ieee_getmaxrate,
297+
.ieee_setmaxrate = mlx5e_dcbnl_ieee_setmaxrate,
225298
.ieee_getpfc = mlx5e_dcbnl_ieee_getpfc,
226299
.ieee_setpfc = mlx5e_dcbnl_ieee_setpfc,
227300
.getdcbx = mlx5e_dcbnl_getdcbx,

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,19 @@ static int mlx5_set_port_qetcr_reg(struct mlx5_core_dev *mdev, u32 *in,
450450
MLX5_REG_QETCR, 0, 1);
451451
}
452452

453+
static int mlx5_query_port_qetcr_reg(struct mlx5_core_dev *mdev, u32 *out,
454+
int outlen)
455+
{
456+
u32 in[MLX5_ST_SZ_DW(qtct_reg)];
457+
458+
if (!MLX5_CAP_GEN(mdev, ets))
459+
return -ENOTSUPP;
460+
461+
memset(in, 0, sizeof(in));
462+
return mlx5_core_access_reg(mdev, in, sizeof(in), out, outlen,
463+
MLX5_REG_QETCR, 0, 0);
464+
}
465+
453466
int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group)
454467
{
455468
u32 in[MLX5_ST_SZ_DW(qetc_reg)];
@@ -481,3 +494,55 @@ int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw)
481494
return mlx5_set_port_qetcr_reg(mdev, in, sizeof(in));
482495
}
483496
EXPORT_SYMBOL_GPL(mlx5_set_port_tc_bw_alloc);
497+
498+
int mlx5_modify_port_ets_rate_limit(struct mlx5_core_dev *mdev,
499+
u8 *max_bw_value,
500+
u8 *max_bw_units)
501+
{
502+
u32 in[MLX5_ST_SZ_DW(qetc_reg)];
503+
void *ets_tcn_conf;
504+
int i;
505+
506+
memset(in, 0, sizeof(in));
507+
508+
MLX5_SET(qetc_reg, in, port_number, 1);
509+
510+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
511+
ets_tcn_conf = MLX5_ADDR_OF(qetc_reg, in, tc_configuration[i]);
512+
513+
MLX5_SET(ets_tcn_config_reg, ets_tcn_conf, r, 1);
514+
MLX5_SET(ets_tcn_config_reg, ets_tcn_conf, max_bw_units,
515+
max_bw_units[i]);
516+
MLX5_SET(ets_tcn_config_reg, ets_tcn_conf, max_bw_value,
517+
max_bw_value[i]);
518+
}
519+
520+
return mlx5_set_port_qetcr_reg(mdev, in, sizeof(in));
521+
}
522+
EXPORT_SYMBOL_GPL(mlx5_modify_port_ets_rate_limit);
523+
524+
int mlx5_query_port_ets_rate_limit(struct mlx5_core_dev *mdev,
525+
u8 *max_bw_value,
526+
u8 *max_bw_units)
527+
{
528+
u32 out[MLX5_ST_SZ_DW(qetc_reg)];
529+
void *ets_tcn_conf;
530+
int err;
531+
int i;
532+
533+
err = mlx5_query_port_qetcr_reg(mdev, out, sizeof(out));
534+
if (err)
535+
return err;
536+
537+
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
538+
ets_tcn_conf = MLX5_ADDR_OF(qetc_reg, out, tc_configuration[i]);
539+
540+
max_bw_value[i] = MLX5_GET(ets_tcn_config_reg, ets_tcn_conf,
541+
max_bw_value);
542+
max_bw_units[i] = MLX5_GET(ets_tcn_config_reg, ets_tcn_conf,
543+
max_bw_units);
544+
}
545+
546+
return 0;
547+
}
548+
EXPORT_SYMBOL_GPL(mlx5_query_port_ets_rate_limit);

include/linux/mlx5/device.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ enum {
350350
MLX5_SET_PORT_PKEY_TABLE = 20,
351351
};
352352

353+
enum {
354+
MLX5_BW_NO_LIMIT = 0,
355+
MLX5_100_MBPS_UNIT = 3,
356+
MLX5_GBPS_UNIT = 4,
357+
};
358+
353359
enum {
354360
MLX5_MAX_PAGE_SHIFT = 31
355361
};

include/linux/mlx5/port.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,11 @@ int mlx5_max_tc(struct mlx5_core_dev *mdev);
7575
int mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, u8 *prio_tc);
7676
int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group);
7777
int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw);
78+
int mlx5_modify_port_ets_rate_limit(struct mlx5_core_dev *mdev,
79+
u8 *max_bw_value,
80+
u8 *max_bw_unit);
81+
int mlx5_query_port_ets_rate_limit(struct mlx5_core_dev *mdev,
82+
u8 *max_bw_value,
83+
u8 *max_bw_unit);
7884

7985
#endif /* __MLX5_PORT_H__ */

0 commit comments

Comments
 (0)