Skip to content

Commit 8d537e3

Browse files
committed
Merge branch 'net-mlx5e-enhance-dcbnl-get-set-maxrate-code'
Tariq Toukan says: ==================== net/mlx5e: Enhance DCBNL get/set maxrate code This series by Gal introduces multiple small code quality improvements for the DCBNL operations mlx5e_dcbnl_ieee_[gs]etmaxrate(). No functional change. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 596c696 + 87a5112 commit 8d537e3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 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;
@@ -595,8 +596,8 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
595596
struct mlx5_core_dev *mdev = priv->mdev;
596597
u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
597598
u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
598-
__u64 upper_limit_mbps;
599-
__u64 upper_limit_gbps;
599+
u64 upper_limit_100mbps;
600+
u64 upper_limit_gbps;
600601
int i;
601602
struct {
602603
int scale;
@@ -614,22 +615,22 @@ 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_mbps = 255 * MLX5E_100MB;
618-
upper_limit_gbps = 255 * 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]) {
622623
max_bw_unit[i] = MLX5_BW_NO_LIMIT;
623624
continue;
624625
}
625-
if (maxrate->tc_maxrate[i] <= upper_limit_mbps) {
626+
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)