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

Change-Id: I1bf70ff04cfedc1903ffd268a43d33367458a85f
---
 .../net/ethernet/mellanox/mlx5/core/en/trap.c | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/trap.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/trap.c
@@ -1,6 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /* Copyright (c) 2020 Mellanox Technologies */
 
+#ifdef HAVE_DEVLINK_TRAP_SUPPORT
+
+#ifdef HAVE_NET_PAGE_POOL_OLD_H
+#include <net/page_pool.h>
+#endif
+#ifdef HAVE_NET_PAGE_POOL_TYPES_H
+#include <net/page_pool/types.h>
+#include <net/page_pool/helpers.h>
+#endif
 #include "en/txrx.h"
 #include "en/params.h"
 #include "en/trap.h"
@@ -52,7 +61,9 @@ static void mlx5e_init_trap_rq(struct ml
 	rq->hw_mtu       = MLX5E_SW2HW_MTU(params, params->sw_mtu);
 	rq->stats        = &priv->trap_stats.rq;
 	rq->ptp_cyc2time = mlx5_rq_ts_translator(mdev);
+#ifdef HAVE_XDP_SUPPORT
 	xdp_rxq_info_unused(&rq->xdp_rxq);
+#endif
 	mlx5e_rq_set_trap_handlers(rq, params);
 }
 
@@ -135,7 +146,11 @@ static struct mlx5e_trap *mlx5e_open_tra
 	t->mkey_be  = cpu_to_be32(priv->mdev->mlx5e_res.hw_objs.mkey);
 	t->stats    = &priv->trap_stats.ch;
 
+#ifdef HAVE_NETIF_NAPI_ADD_GET_3_PARAMS
 	netif_napi_add(netdev, &t->napi, mlx5e_trap_napi_poll);
+#else
+	netif_napi_add(netdev, &t->napi, mlx5e_trap_napi_poll, 64);
+#endif
 
 	err = mlx5e_open_trap_rq(priv, t);
 	if (unlikely(err))
@@ -222,11 +237,13 @@ static int mlx5e_handle_action_trap(stru
 		if (err)
 			goto err_out;
 		break;
+#ifdef HAVE_DEVLINK_TRAP_DMAC_FILTER
 	case DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER:
 		err = mlx5e_add_mac_trap(priv->fs, trap_id, mlx5e_trap_get_tirn(priv->en_trap));
 		if (err)
 			goto err_out;
 		break;
+#endif
 	default:
 		netdev_warn(priv->netdev, "%s: Unknown trap id %d\n", __func__, trap_id);
 		err = -EINVAL;
@@ -246,9 +263,11 @@ static int mlx5e_handle_action_drop(stru
 	case DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER:
 		mlx5e_remove_vlan_trap(priv->fs);
 		break;
+#ifdef HAVE_DEVLINK_TRAP_DMAC_FILTER
 	case DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER:
 		mlx5e_remove_mac_trap(priv->fs);
 		break;
+#endif
 	default:
 		netdev_warn(priv->netdev, "%s: Unknown trap id %d\n", __func__, trap_id);
 		return -EINVAL;
@@ -302,7 +321,9 @@ static int mlx5e_apply_trap(struct mlx5e
 
 static const int mlx5e_traps_arr[] = {
 	DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
+#ifdef HAVE_DEVLINK_TRAP_DMAC_FILTER
 	DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER,
+#endif
 };
 
 int mlx5e_apply_traps(struct mlx5e_priv *priv, bool enable)
@@ -317,3 +338,5 @@ int mlx5e_apply_traps(struct mlx5e_priv
 	}
 	return 0;
 }
+
+#endif /* HAVE_DEVLINK_TRAP_SUPPORT */
