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

Change-Id: I5a1cd58457df40192e46425c5d42e09726e59855
---
 .../mellanox/mlx5/core/en/tc/act/police.c     | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
@@ -5,6 +5,7 @@
 #include "en/tc_priv.h"
 #include "fs_core.h"
 
+#ifdef HAVE_FLOW_ACTION_POLICE_EXCEED
 static bool police_act_validate_control(enum flow_action_id act_id,
 					struct netlink_ext_ack *extack)
 {
@@ -19,10 +20,12 @@ static bool police_act_validate_control(
 
 	return true;
 }
+#endif
 
 static int police_act_validate(const struct flow_action_entry *act,
 			       struct netlink_ext_ack *extack)
 {
+#ifdef HAVE_FLOW_ACTION_POLICE_EXCEED
 	if (!police_act_validate_control(act->police.exceed.act_id, extack) ||
 	    !police_act_validate_control(act->police.notexceed.act_id, extack))
 		return -EOPNOTSUPP;
@@ -34,6 +37,7 @@ static int police_act_validate(const str
 		return -EOPNOTSUPP;
 	}
 
+#endif
 	return 0;
 }
 
@@ -56,16 +60,23 @@ static int
 fill_meter_params_from_act(const struct flow_action_entry *act,
 			   struct mlx5e_flow_meter_params *params)
 {
+#if defined(HAVE_FLOW_ACTION_POLICE_INDEX) || defined(HAVE_FLOW_ACTION_HW_INDEX)
+#ifdef HAVE_FLOW_ACTION_HW_INDEX
 	params->index = act->hw_index;
+#else
+	params->index = act->police.index;
+#endif
 	if (act->police.rate_bytes_ps) {
 		params->mode = MLX5_RATE_LIMIT_BPS;
 		/* change rate to bits per second */
 		params->rate = act->police.rate_bytes_ps << 3;
 		params->burst = act->police.burst;
+#ifdef HAVE_FLOW_ACTION_POLICE_RATE_PKT_PS
 	} else if (act->police.rate_pkt_ps) {
 		params->mode = MLX5_RATE_LIMIT_PPS;
 		params->rate = act->police.rate_pkt_ps;
 		params->burst = act->police.burst_pkt;
+#endif
 	} else if (act->police.mtu) {
 		params->mtu = act->police.mtu;
 	} else {
@@ -73,6 +84,9 @@ fill_meter_params_from_act(const struct
 	}
 
 	return 0;
+#else
+	return -EOPNOTSUPP;
+#endif
 }
 
 static int
@@ -112,6 +126,7 @@ tc_act_is_multi_table_act_police(struct
 	return true;
 }
 
+#ifdef HAVE_FLOW_OFFLOAD_ACTION
 static int
 tc_act_police_offload(struct mlx5e_priv *priv,
 		      struct flow_offload_action *fl_act,
@@ -187,7 +202,9 @@ tc_act_police_stats(struct mlx5e_priv *p
 	mlx5e_tc_meter_put(meter);
 	return 0;
 }
+#endif /* HAVE_FLOW_OFFLOAD_ACTION */
 
+#ifdef HAVE_FLOW_ACTION_POLICE_EXCEED
 static bool
 tc_act_police_get_branch_ctrl(const struct flow_action_entry *act,
 			      struct mlx5e_tc_act_branch_ctrl *cond_true,
@@ -198,15 +215,21 @@ tc_act_police_get_branch_ctrl(const stru
 
 	cond_false->act_id = act->police.exceed.act_id;
 	cond_false->extval = act->police.exceed.extval;
+
 	return true;
 }
+#endif
 
 struct mlx5e_tc_act mlx5e_tc_act_police = {
 	.can_offload = tc_act_can_offload_police,
 	.parse_action = tc_act_parse_police,
 	.is_multi_table_act = tc_act_is_multi_table_act_police,
+#ifdef HAVE_FLOW_OFFLOAD_ACTION
 	.offload_action = tc_act_police_offload,
 	.destroy_action = tc_act_police_destroy,
 	.stats_action = tc_act_police_stats,
+#endif
+#ifdef HAVE_FLOW_ACTION_POLICE_EXCEED
 	.get_branch_ctrl = tc_act_police_get_branch_ctrl,
+#endif
 };
