Skip to content

Commit 87a5112

Browse files
gal-pressmankuba-moo
authored andcommitted
net/mlx5e: Use standard unit definitions for bandwidth conversion
MLX5E_100MB and MLX5E_1GB defines are confusing, MLX5E_100MB is not equal to 100 * MEGA, and MLX5E_1GB is not equal to one GIGA, as they hide the Kbps rate conversion required for ieee_maxrate. Replace hardcoded bandwidth conversion values with standard unit definitions from linux/units.h. Rename MLX5E_100MB/MLX5E_1GB to MLX5E_100MB_TO_KB/MLX5E_1GB_TO_KB to clarify these are conversion factors to Kbps, not absolute bandwidth values. Signed-off-by: Gal Pressman <[email protected]> Reviewed-by: Nimrod Oren <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 53f7a77 commit 87a5112

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
*/
3232
#include <linux/device.h>
3333
#include <linux/netdevice.h>
34+
#include <linux/units.h>
3435
#include "en.h"
3536
#include "en/port.h"
3637
#include "en/port_buffer.h"
3738

3839
#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
3940

40-
#define MLX5E_100MB (100000)
41-
#define MLX5E_1GB (1000000)
41+
#define MLX5E_100MB_TO_KB (100 * MEGA / KILO)
42+
#define MLX5E_1GB_TO_KB (GIGA / KILO)
4243

4344
#define MLX5E_CEE_STATE_UP 1
4445
#define MLX5E_CEE_STATE_DOWN 0
@@ -572,10 +573,10 @@ static int mlx5e_dcbnl_ieee_getmaxrate(struct net_device *netdev,
572573
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
573574
switch (max_bw_unit[i]) {
574575
case MLX5_100_MBPS_UNIT:
575-
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_100MB;
576+
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_100MB_TO_KB;
576577
break;
577578
case MLX5_GBPS_UNIT:
578-
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_1GB;
579+
maxrate->tc_maxrate[i] = max_bw_value[i] * MLX5E_1GB_TO_KB;
579580
break;
580581
case MLX5_BW_NO_LIMIT:
581582
break;
@@ -614,8 +615,8 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
614615

615616
memset(max_bw_value, 0, sizeof(max_bw_value));
616617
memset(max_bw_unit, 0, sizeof(max_bw_unit));
617-
upper_limit_100mbps = U8_MAX * MLX5E_100MB;
618-
upper_limit_gbps = U8_MAX * MLX5E_1GB;
618+
upper_limit_100mbps = U8_MAX * MLX5E_100MB_TO_KB;
619+
upper_limit_gbps = U8_MAX * MLX5E_1GB_TO_KB;
619620

620621
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
621622
if (!maxrate->tc_maxrate[i]) {
@@ -624,12 +625,12 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
624625
}
625626
if (maxrate->tc_maxrate[i] <= upper_limit_100mbps) {
626627
max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
627-
MLX5E_100MB);
628+
MLX5E_100MB_TO_KB);
628629
max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
629630
max_bw_unit[i] = MLX5_100_MBPS_UNIT;
630631
} else if (maxrate->tc_maxrate[i] <= upper_limit_gbps) {
631632
max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
632-
MLX5E_1GB);
633+
MLX5E_1GB_TO_KB);
633634
max_bw_unit[i] = MLX5_GBPS_UNIT;
634635
} else {
635636
netdev_err(netdev,

0 commit comments

Comments
 (0)