Blame SOURCES/0096-netdrv-net-mlx5-LAG-Use-port-enumerators.patch

d8f823
From 8e8051d3aa6145a96ad1457fc55cb31426fc2bdf Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Sun, 10 May 2020 15:04:14 -0400
d8f823
Subject: [PATCH 096/312] [netdrv] net/mlx5: LAG, Use port enumerators
d8f823
d8f823
Message-id: <20200510150452.10307-50-ahleihel@redhat.com>
d8f823
Patchwork-id: 306674
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1789380 v2 49/87] net/mlx5: LAG, Use port enumerators
d8f823
Bugzilla: 1789380
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
d8f823
RH-Acked-by: Jonathan Toppins <jtoppins@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1789380
d8f823
Upstream: v5.5-rc1
d8f823
Conflicts:
d8f823
 - drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
d8f823
   Various context diff due to missing commit:
d8f823
   5481d73f8154 ("ipv4: Use accessors for fib_info nexthop data")
d8f823
   And already backported commit:
d8f823
   1cdc14e9d134 ("net/mlx5: LAG, Use affinity type enumerators")
d8f823
d8f823
commit 84d2dbb0aaaf1098aa2c2ca07003bf3f973732ac
d8f823
Author: Erez Alfasi <ereza@mellanox.com>
d8f823
Date:   Mon Sep 16 13:59:58 2019 +0300
d8f823
d8f823
    net/mlx5: LAG, Use port enumerators
d8f823
d8f823
    Instead of using explicit array indexes, simply use
d8f823
    ports enumerators to make the code more readable.
d8f823
d8f823
    Fixes: 7907f23adc18 ("net/mlx5: Implement RoCE LAG feature")
d8f823
    Signed-off-by: Erez Alfasi <ereza@mellanox.com>
d8f823
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
d8f823
d8f823
Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
d8f823
---
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/lag.c    | 65 +++++++++++++-----------
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/lag.h    |  5 ++
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c | 56 ++++++++++----------
d8f823
 3 files changed, 69 insertions(+), 57 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag.c
d8f823
index c5ef2ff26465..fc0d9583475d 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag.c
d8f823
@@ -145,34 +145,35 @@ static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker,
d8f823
 {
d8f823
 	*port1 = 1;
d8f823
 	*port2 = 2;
d8f823
-	if (!tracker->netdev_state[0].tx_enabled ||
d8f823
-	    !tracker->netdev_state[0].link_up) {
d8f823
+	if (!tracker->netdev_state[MLX5_LAG_P1].tx_enabled ||
d8f823
+	    !tracker->netdev_state[MLX5_LAG_P1].link_up) {
d8f823
 		*port1 = 2;
d8f823
 		return;
d8f823
 	}
d8f823
 
d8f823
-	if (!tracker->netdev_state[1].tx_enabled ||
d8f823
-	    !tracker->netdev_state[1].link_up)
d8f823
+	if (!tracker->netdev_state[MLX5_LAG_P2].tx_enabled ||
d8f823
+	    !tracker->netdev_state[MLX5_LAG_P2].link_up)
d8f823
 		*port2 = 1;
d8f823
 }
d8f823
 
d8f823
 void mlx5_modify_lag(struct mlx5_lag *ldev,
d8f823
 		     struct lag_tracker *tracker)
d8f823
 {
d8f823
-	struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
d8f823
+	struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
d8f823
 	u8 v2p_port1, v2p_port2;
d8f823
 	int err;
d8f823
 
d8f823
 	mlx5_infer_tx_affinity_mapping(tracker, &v2p_port1,
d8f823
 				       &v2p_port2);
d8f823
 
d8f823
-	if (v2p_port1 != ldev->v2p_map[0] ||
d8f823
-	    v2p_port2 != ldev->v2p_map[1]) {
d8f823
-		ldev->v2p_map[0] = v2p_port1;
d8f823
-		ldev->v2p_map[1] = v2p_port2;
d8f823
+	if (v2p_port1 != ldev->v2p_map[MLX5_LAG_P1] ||
d8f823
+	    v2p_port2 != ldev->v2p_map[MLX5_LAG_P2]) {
d8f823
+		ldev->v2p_map[MLX5_LAG_P1] = v2p_port1;
d8f823
+		ldev->v2p_map[MLX5_LAG_P2] = v2p_port2;
d8f823
 
d8f823
 		mlx5_core_info(dev0, "modify lag map port 1:%d port 2:%d",
d8f823
-			       ldev->v2p_map[0], ldev->v2p_map[1]);
d8f823
+			       ldev->v2p_map[MLX5_LAG_P1],
d8f823
+			       ldev->v2p_map[MLX5_LAG_P2]);
d8f823
 
d8f823
 		err = mlx5_cmd_modify_lag(dev0, v2p_port1, v2p_port2);
d8f823
 		if (err)
d8f823
@@ -185,16 +186,17 @@ void mlx5_modify_lag(struct mlx5_lag *ldev,
d8f823
 static int mlx5_create_lag(struct mlx5_lag *ldev,
d8f823
 			   struct lag_tracker *tracker)
d8f823
 {
d8f823
-	struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
d8f823
+	struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
d8f823
 	int err;
d8f823
 
d8f823
-	mlx5_infer_tx_affinity_mapping(tracker, &ldev->v2p_map[0],
d8f823
-				       &ldev->v2p_map[1]);
d8f823
+	mlx5_infer_tx_affinity_mapping(tracker, &ldev->v2p_map[MLX5_LAG_P1],
d8f823
+				       &ldev->v2p_map[MLX5_LAG_P2]);
d8f823
 
d8f823
 	mlx5_core_info(dev0, "lag map port 1:%d port 2:%d",
d8f823
-		       ldev->v2p_map[0], ldev->v2p_map[1]);
d8f823
+		       ldev->v2p_map[MLX5_LAG_P1], ldev->v2p_map[MLX5_LAG_P2]);
d8f823
 
d8f823
-	err = mlx5_cmd_create_lag(dev0, ldev->v2p_map[0], ldev->v2p_map[1]);
d8f823
+	err = mlx5_cmd_create_lag(dev0, ldev->v2p_map[MLX5_LAG_P1],
d8f823
+				  ldev->v2p_map[MLX5_LAG_P2]);
d8f823
 	if (err)
d8f823
 		mlx5_core_err(dev0,
d8f823
 			      "Failed to create LAG (%d)\n",
d8f823
@@ -207,7 +209,7 @@ int mlx5_activate_lag(struct mlx5_lag *ldev,
d8f823
 		      u8 flags)
d8f823
 {
d8f823
 	bool roce_lag = !!(flags & MLX5_LAG_FLAG_ROCE);
d8f823
-	struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
d8f823
+	struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
d8f823
 	int err;
d8f823
 
d8f823
 	err = mlx5_create_lag(ldev, tracker);
d8f823
@@ -229,7 +231,7 @@ int mlx5_activate_lag(struct mlx5_lag *ldev,
d8f823
 
d8f823
 static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
d8f823
 {
d8f823
-	struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
d8f823
+	struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
d8f823
 	bool roce_lag = __mlx5_lag_is_roce(ldev);
d8f823
 	int err;
d8f823
 
d8f823
@@ -252,14 +254,15 @@ static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
d8f823
 
d8f823
 static bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
d8f823
 {
d8f823
-	if (!ldev->pf[0].dev || !ldev->pf[1].dev)
d8f823
+	if (!ldev->pf[MLX5_LAG_P1].dev || !ldev->pf[MLX5_LAG_P2].dev)
d8f823
 		return false;
d8f823
 
d8f823
 #ifdef CONFIG_MLX5_ESWITCH
d8f823
-	return mlx5_esw_lag_prereq(ldev->pf[0].dev, ldev->pf[1].dev);
d8f823
+	return mlx5_esw_lag_prereq(ldev->pf[MLX5_LAG_P1].dev,
d8f823
+				   ldev->pf[MLX5_LAG_P2].dev);
d8f823
 #else
d8f823
-	return (!mlx5_sriov_is_enabled(ldev->pf[0].dev) &&
d8f823
-		!mlx5_sriov_is_enabled(ldev->pf[1].dev));
d8f823
+	return (!mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P1].dev) &&
d8f823
+		!mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P2].dev));
d8f823
 #endif
d8f823
 }
d8f823
 
d8f823
@@ -285,8 +288,8 @@ static void mlx5_lag_remove_ib_devices(struct mlx5_lag *ldev)
d8f823
 
d8f823
 static void mlx5_do_bond(struct mlx5_lag *ldev)
d8f823
 {
d8f823
-	struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
d8f823
-	struct mlx5_core_dev *dev1 = ldev->pf[1].dev;
d8f823
+	struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
d8f823
+	struct mlx5_core_dev *dev1 = ldev->pf[MLX5_LAG_P2].dev;
d8f823
 	struct lag_tracker tracker;
d8f823
 	bool do_bond, roce_lag;
d8f823
 	int err;
d8f823
@@ -692,10 +695,11 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
d8f823
 		goto unlock;
d8f823
 
d8f823
 	if (ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP) {
d8f823
-		ndev = ldev->tracker.netdev_state[0].tx_enabled ?
d8f823
-		       ldev->pf[0].netdev : ldev->pf[1].netdev;
d8f823
+		ndev = ldev->tracker.netdev_state[MLX5_LAG_P1].tx_enabled ?
d8f823
+		       ldev->pf[MLX5_LAG_P1].netdev :
d8f823
+		       ldev->pf[MLX5_LAG_P2].netdev;
d8f823
 	} else {
d8f823
-		ndev = ldev->pf[0].netdev;
d8f823
+		ndev = ldev->pf[MLX5_LAG_P1].netdev;
d8f823
 	}
d8f823
 	if (ndev)
d8f823
 		dev_hold(ndev);
d8f823
@@ -717,7 +721,8 @@ bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)
d8f823
 		return true;
d8f823
 
d8f823
 	ldev = mlx5_lag_dev_get(dev);
d8f823
-	if (!ldev || !__mlx5_lag_is_roce(ldev) || ldev->pf[0].dev == dev)
d8f823
+	if (!ldev || !__mlx5_lag_is_roce(ldev) ||
d8f823
+	    ldev->pf[MLX5_LAG_P1].dev == dev)
d8f823
 		return true;
d8f823
 
d8f823
 	/* If bonded, we do not add an IB device for PF1. */
d8f823
@@ -746,11 +751,11 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
d8f823
 	ldev = mlx5_lag_dev_get(dev);
d8f823
 	if (ldev && __mlx5_lag_is_roce(ldev)) {
d8f823
 		num_ports = MLX5_MAX_PORTS;
d8f823
-		mdev[0] = ldev->pf[0].dev;
d8f823
-		mdev[1] = ldev->pf[1].dev;
d8f823
+		mdev[MLX5_LAG_P1] = ldev->pf[MLX5_LAG_P1].dev;
d8f823
+		mdev[MLX5_LAG_P2] = ldev->pf[MLX5_LAG_P2].dev;
d8f823
 	} else {
d8f823
 		num_ports = 1;
d8f823
-		mdev[0] = dev;
d8f823
+		mdev[MLX5_LAG_P1] = dev;
d8f823
 	}
d8f823
 
d8f823
 	for (i = 0; i < num_ports; ++i) {
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag.h
d8f823
index 1dea0b1c9826..f1068aac6406 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag.h
d8f823
@@ -8,6 +8,11 @@
d8f823
 #include "lag_mp.h"
d8f823
 
d8f823
 enum {
d8f823
+	MLX5_LAG_P1,
d8f823
+	MLX5_LAG_P2,
d8f823
+};
d8f823
+
d8f823
+enum {
d8f823
 	MLX5_LAG_FLAG_ROCE   = 1 << 0,
d8f823
 	MLX5_LAG_FLAG_SRIOV  = 1 << 1,
d8f823
 	MLX5_LAG_FLAG_MULTIPATH = 1 << 2,
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c b/drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
d8f823
index a5addeadc732..151ba67e4d25 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
d8f823
@@ -10,10 +10,11 @@
d8f823
 
d8f823
 static bool mlx5_lag_multipath_check_prereq(struct mlx5_lag *ldev)
d8f823
 {
d8f823
-	if (!ldev->pf[0].dev || !ldev->pf[1].dev)
d8f823
+	if (!ldev->pf[MLX5_LAG_P1].dev || !ldev->pf[MLX5_LAG_P2].dev)
d8f823
 		return false;
d8f823
 
d8f823
-	return mlx5_esw_multipath_prereq(ldev->pf[0].dev, ldev->pf[1].dev);
d8f823
+	return mlx5_esw_multipath_prereq(ldev->pf[MLX5_LAG_P1].dev,
d8f823
+					 ldev->pf[MLX5_LAG_P2].dev);
d8f823
 }
d8f823
 
d8f823
 static bool __mlx5_lag_is_multipath(struct mlx5_lag *ldev)
d8f823
@@ -52,36 +53,36 @@ static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev,
d8f823
 
d8f823
 	switch (port) {
d8f823
 	case MLX5_LAG_NORMAL_AFFINITY:
d8f823
-		tracker.netdev_state[0].tx_enabled = true;
d8f823
-		tracker.netdev_state[1].tx_enabled = true;
d8f823
-		tracker.netdev_state[0].link_up = true;
d8f823
-		tracker.netdev_state[1].link_up = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].link_up = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].link_up = true;
d8f823
 		break;
d8f823
 	case MLX5_LAG_P1_AFFINITY:
d8f823
-		tracker.netdev_state[0].tx_enabled = true;
d8f823
-		tracker.netdev_state[0].link_up = true;
d8f823
-		tracker.netdev_state[1].tx_enabled = false;
d8f823
-		tracker.netdev_state[1].link_up = false;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].link_up = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].tx_enabled = false;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].link_up = false;
d8f823
 		break;
d8f823
 	case MLX5_LAG_P2_AFFINITY:
d8f823
-		tracker.netdev_state[0].tx_enabled = false;
d8f823
-		tracker.netdev_state[0].link_up = false;
d8f823
-		tracker.netdev_state[1].tx_enabled = true;
d8f823
-		tracker.netdev_state[1].link_up = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].tx_enabled = false;
d8f823
+		tracker.netdev_state[MLX5_LAG_P1].link_up = false;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
d8f823
+		tracker.netdev_state[MLX5_LAG_P2].link_up = true;
d8f823
 		break;
d8f823
 	default:
d8f823
-		mlx5_core_warn(ldev->pf[0].dev, "Invalid affinity port %d",
d8f823
-			       port);
d8f823
+		mlx5_core_warn(ldev->pf[MLX5_LAG_P1].dev,
d8f823
+			       "Invalid affinity port %d", port);
d8f823
 		return;
d8f823
 	}
d8f823
 
d8f823
-	if (tracker.netdev_state[0].tx_enabled)
d8f823
-		mlx5_notifier_call_chain(ldev->pf[0].dev->priv.events,
d8f823
+	if (tracker.netdev_state[MLX5_LAG_P1].tx_enabled)
d8f823
+		mlx5_notifier_call_chain(ldev->pf[MLX5_LAG_P1].dev->priv.events,
d8f823
 					 MLX5_DEV_EVENT_PORT_AFFINITY,
d8f823
 					 (void *)0);
d8f823
 
d8f823
-	if (tracker.netdev_state[1].tx_enabled)
d8f823
-		mlx5_notifier_call_chain(ldev->pf[1].dev->priv.events,
d8f823
+	if (tracker.netdev_state[MLX5_LAG_P2].tx_enabled)
d8f823
+		mlx5_notifier_call_chain(ldev->pf[MLX5_LAG_P2].dev->priv.events,
d8f823
 					 MLX5_DEV_EVENT_PORT_AFFINITY,
d8f823
 					 (void *)0);
d8f823
 
d8f823
@@ -135,11 +136,12 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev,
d8f823
 		return;
d8f823
 
d8f823
 	/* Verify next hops are ports of the same hca */
d8f823
-	if (!(fi->fib_nh[0].nh_dev == ldev->pf[0].netdev &&
d8f823
-	      fi->fib_nh[1].nh_dev == ldev->pf[1].netdev) &&
d8f823
-	    !(fi->fib_nh[0].nh_dev == ldev->pf[1].netdev &&
d8f823
-	      fi->fib_nh[1].nh_dev == ldev->pf[0].netdev)) {
d8f823
-		mlx5_core_warn(ldev->pf[0].dev, "Multipath offload require two ports of the same HCA\n");
d8f823
+	if (!(fi->fib_nh[0].nh_dev == ldev->pf[MLX5_LAG_P1].netdev &&
d8f823
+	      fi->fib_nh[1].nh_dev == ldev->pf[MLX5_LAG_P2].netdev) &&
d8f823
+	    !(fi->fib_nh[0].nh_dev == ldev->pf[MLX5_LAG_P2].netdev &&
d8f823
+	      fi->fib_nh[1].nh_dev == ldev->pf[MLX5_LAG_P1].netdev)) {
d8f823
+		mlx5_core_warn(ldev->pf[MLX5_LAG_P1].dev,
d8f823
+			       "Multipath offload require two ports of the same HCA\n");
d8f823
 		return;
d8f823
 	}
d8f823
 
d8f823
@@ -255,8 +257,8 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,
d8f823
 		fen_info = container_of(info, struct fib_entry_notifier_info,
d8f823
 					info);
d8f823
 		fi = fen_info->fi;
d8f823
-		if (fi->fib_dev != ldev->pf[0].netdev &&
d8f823
-		    fi->fib_dev != ldev->pf[1].netdev) {
d8f823
+		if (fi->fib_dev != ldev->pf[MLX5_LAG_P1].netdev &&
d8f823
+		    fi->fib_dev != ldev->pf[MLX5_LAG_P2].netdev) {
d8f823
 			return NOTIFY_DONE;
d8f823
 		}
d8f823
 		fib_work = mlx5_lag_init_fib_work(ldev, event);
d8f823
-- 
d8f823
2.13.6
d8f823