From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c

Change-Id: If0d899115e0fc2d98d4815d80026897610590a39
---
 .../net/ethernet/mellanox/mlx5/core/lag/mp.c  | 65 +++++++++++++++++--
 1 file changed, 58 insertions(+), 7 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
@@ -2,13 +2,18 @@
 /* Copyright (c) 2019 Mellanox Technologies. */
 
 #include <linux/netdevice.h>
+#ifdef HAVE_FIB_INFO_NH
 #include <net/nexthop.h>
-#include "lag/lag.h"
-#include "lag/mp.h"
+#endif
 #include "mlx5_core.h"
 #include "eswitch.h"
 #include "lib/events.h"
 
+#define MLX_LAG_SUPPORTED
+
+#ifdef MLX_LAG_SUPPORTED
+#include "lag.h"
+
 static bool __mlx5_lag_is_multipath(struct mlx5_lag *ldev)
 {
 	return ldev->mode == MLX5_LAG_MODE_MULTIPATH;
@@ -123,23 +128,43 @@ mlx5_lag_get_next_fib_dev(struct mlx5_la
 			  struct fib_info *fi,
 			  struct net_device *current_dev)
 {
-	struct net_device *fib_dev;
+	struct net_device *_fib_dev;
 	int i, ldev_idx, nhs;
 
+#ifdef HAVE_FIB_INFO_NH
 	nhs = fib_info_num_path(fi);
+#else
+	nhs = fi->fib_nhs;
+#endif
 	i = 0;
 	if (current_dev) {
 		for (; i < nhs; i++) {
-			fib_dev = fib_info_nh(fi, i)->fib_nh_dev;
-			if (fib_dev == current_dev) {
+#ifdef HAVE_FIB_INFO_NH
+			_fib_dev = fib_info_nh(fi, i)->fib_nh_dev;
+#else
+#ifdef HAVE_FIB_NH_DEV
+			_fib_dev = fi->fib_nh[i].fib_nh_dev;
+#else
+			_fib_dev = fi->fib_nh[i].nh_dev;
+#endif
+#endif
+			if (_fib_dev == current_dev) {
 				i++;
 				break;
 			}
 		}
 	}
 	for (; i < nhs; i++) {
-		fib_dev = fib_info_nh(fi, i)->fib_nh_dev;
-		ldev_idx = mlx5_lag_dev_get_netdev_idx(ldev, fib_dev);
+#ifdef HAVE_FIB_INFO_NH
+		_fib_dev = fib_info_nh(fi, i)->fib_nh_dev;
+#else
+#ifdef HAVE_FIB_NH_DEV
+		_fib_dev = fi->fib_nh[i].fib_nh_dev;
+#else
+		_fib_dev = fi->fib_nh[i].nh_dev;
+#endif
+#endif
+		ldev_idx = mlx5_lag_dev_get_netdev_idx(ldev, _fib_dev);
 		if (ldev_idx >= 0)
 			return ldev->pf[ldev_idx].netdev;
 	}
@@ -221,14 +246,22 @@ static void mlx5_lag_fib_nexthop_event(s
 
 	/* nh added/removed */
 	if (event == FIB_EVENT_NH_DEL) {
+#ifdef HAVE_FIB_NH_DEV
 		int i = mlx5_lag_dev_get_netdev_idx(ldev, fib_nh->fib_nh_dev);
+#else
+		int i = mlx5_lag_dev_get_netdev_idx(ldev, fib_nh->nh_dev);
+#endif
 
 		if (i >= 0) {
 			i = (i + 1) % 2 + 1; /* peer port */
 			mlx5_lag_set_port_affinity(ldev, i);
 		}
 	} else if (event == FIB_EVENT_NH_ADD &&
+#ifdef HAVE_FIB_INFO_NH
 		   fib_info_num_path(fi) == 2) {
+#else
+		   fi->fib_nhs == 2) {
+#endif
 		mlx5_lag_set_port_affinity(ldev, MLX5_LAG_NORMAL_AFFINITY);
 	}
 }
@@ -244,6 +277,10 @@ static void mlx5_lag_fib_update(struct w
 	rtnl_lock();
 	switch (fib_work->event) {
 	case FIB_EVENT_ENTRY_REPLACE:
+#ifdef HAVE_BASECODE_EXTRAS
+	case FIB_EVENT_ENTRY_APPEND: /* fall through */
+	case FIB_EVENT_ENTRY_ADD: /* fall through */
+#endif
 	case FIB_EVENT_ENTRY_DEL:
 		mlx5_lag_fib_route_event(ldev, fib_work->event,
 					 &fib_work->fen_info);
@@ -300,12 +337,16 @@ static int mlx5_lag_fib_event(struct not
 
 	switch (event) {
 	case FIB_EVENT_ENTRY_REPLACE:
+	case FIB_EVENT_ENTRY_APPEND: /* fall through */
+	case FIB_EVENT_ENTRY_ADD: /* fall through */
 	case FIB_EVENT_ENTRY_DEL:
 		fen_info = container_of(info, struct fib_entry_notifier_info,
 					info);
 		fi = fen_info->fi;
+#ifdef HAVE_FIB_INFO_NH
 		if (fi->nh)
 			return NOTIFY_DONE;
+#endif
 
 		fib_work = mlx5_lag_init_fib_work(ldev, event);
 		if (!fib_work)
@@ -361,8 +402,13 @@ int mlx5_lag_mp_init(struct mlx5_lag *ld
 		return -ENOMEM;
 
 	mp->fib_nb.notifier_call = mlx5_lag_fib_event;
+#ifdef HAVE_REGISTER_FIB_NOTIFIER_HAS_4_PARAMS
 	err = register_fib_notifier(&init_net, &mp->fib_nb,
 				    mlx5_lag_fib_event_flush, NULL);
+#else
+	err = register_fib_notifier(&mp->fib_nb,
+				    mlx5_lag_fib_event_flush);
+#endif
 	if (err) {
 		destroy_workqueue(mp->wq);
 		mp->fib_nb.notifier_call = NULL;
@@ -378,8 +424,13 @@ void mlx5_lag_mp_cleanup(struct mlx5_lag
 	if (!mp->fib_nb.notifier_call)
 		return;
 
+#ifdef HAVE_REGISTER_FIB_NOTIFIER_HAS_4_PARAMS
 	unregister_fib_notifier(&init_net, &mp->fib_nb);
+#else
+	unregister_fib_notifier(&mp->fib_nb);
+#endif
 	destroy_workqueue(mp->wq);
 	mp->fib_nb.notifier_call = NULL;
 	mp->fib.mfi = NULL;
 }
+#endif /* MLX_LAG_SUPPORTED */
