net/mlx5: LAG, Use affinity type enumerators
authorErez Alfasi <ereza@mellanox.com>
Mon, 16 Sep 2019 11:34:55 +0000 (14:34 +0300)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 1 Nov 2019 21:55:17 +0000 (14:55 -0700)
Instead of using explicit indexes, simply use affinity
type enumerators to make the code more readable.

Fixes: 544fe7c2e654 ("net/mlx5e: Activate HW multipath and handle port affinity based on FIB events")
Signed-off-by: Erez Alfasi <ereza@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
drivers/net/ethernet/mellanox/mlx5/core/lag_mp.h

index 5169864dd656a1625b7ba750289c4ea64de7f63f..b70afa310ad2a919272563a61aef4757c4ab9640 100644 (file)
@@ -44,7 +44,8 @@ bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev)
  *     2 - set affinity to port 2.
  *
  **/
-static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev, int port)
+static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev,
+                                      enum mlx5_lag_port_affinity port)
 {
        struct lag_tracker tracker;
 
@@ -52,19 +53,19 @@ static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev, int port)
                return;
 
        switch (port) {
-       case 0:
+       case MLX5_LAG_NORMAL_AFFINITY:
                tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
                tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
                tracker.netdev_state[MLX5_LAG_P1].link_up = true;
                tracker.netdev_state[MLX5_LAG_P2].link_up = true;
                break;
-       case 1:
+       case MLX5_LAG_P1_AFFINITY:
                tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
                tracker.netdev_state[MLX5_LAG_P1].link_up = true;
                tracker.netdev_state[MLX5_LAG_P2].tx_enabled = false;
                tracker.netdev_state[MLX5_LAG_P2].link_up = false;
                break;
-       case 2:
+       case MLX5_LAG_P2_AFFINITY:
                tracker.netdev_state[MLX5_LAG_P1].tx_enabled = false;
                tracker.netdev_state[MLX5_LAG_P1].link_up = false;
                tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
@@ -159,7 +160,7 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev,
                mlx5_activate_lag(ldev, &tracker, MLX5_LAG_FLAG_MULTIPATH);
        }
 
-       mlx5_lag_set_port_affinity(ldev, 0);
+       mlx5_lag_set_port_affinity(ldev, MLX5_LAG_NORMAL_AFFINITY);
        mp->mfi = fi;
 }
 
@@ -184,7 +185,7 @@ static void mlx5_lag_fib_nexthop_event(struct mlx5_lag *ldev,
                }
        } else if (event == FIB_EVENT_NH_ADD &&
                   fib_info_num_path(fi) == 2) {
-               mlx5_lag_set_port_affinity(ldev, 0);
+               mlx5_lag_set_port_affinity(ldev, MLX5_LAG_NORMAL_AFFINITY);
        }
 }
 
index 6d14b1100be9f347d9d02fbb67fcd0e58253d22b..79be89e9c7a433c18578f137ea48a2fdae778194 100644 (file)
@@ -7,6 +7,12 @@
 #include "lag.h"
 #include "mlx5_core.h"
 
+enum mlx5_lag_port_affinity {
+       MLX5_LAG_NORMAL_AFFINITY,
+       MLX5_LAG_P1_AFFINITY,
+       MLX5_LAG_P2_AFFINITY,
+};
+
 struct lag_mp {
        struct notifier_block     fib_nb;
        struct fib_info           *mfi; /* used in tracking fib events */