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

Change-Id: Ife9b7993c6fec02368b2c39d7ae7118cab73b3bd
---
 .../ethernet/mellanox/mlx5/core/en/tc/sample.c   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
@@ -324,6 +324,7 @@ sample_restore_put(struct mlx5e_tc_psamp
 
 void mlx5e_tc_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj)
 {
+#if defined(HAVE_STRUCT_PSAMPLE_METADATA)
 	u32 trunc_size = mapped_obj->sample.trunc_size;
 	struct psample_group psample_group = {};
 	struct psample_metadata md = {};
@@ -335,6 +336,19 @@ void mlx5e_tc_sample_skb(struct sk_buff
 	skb_push(skb, skb->mac_len);
 
 	psample_sample_packet(&psample_group, skb, mapped_obj->sample.rate, &md);
+#else
+	u32 trunc_size = mapped_obj->sample.trunc_size;
+	struct psample_group psample_group = {};
+	int iif = skb->dev->ifindex;
+	u32 size;
+
+	size = trunc_size ? min(trunc_size, skb->len) : skb->len;
+	psample_group.group_num = mapped_obj->sample.group_id;
+	psample_group.net = &init_net;
+	skb_push(skb, skb->mac_len);
+
+	psample_sample_packet(&psample_group, skb, size, iif, 0, mapped_obj->sample.rate);
+#endif
 }
 
 static int
@@ -478,7 +492,7 @@ mlx5e_tc_sample_offload(struct mlx5e_tc_
 	struct mlx5_flow_attr *pre_attr;
 	u32 tunnel_id = attr->tunnel_id;
 	struct mlx5_eswitch *esw;
-	u32 default_tbl_id;
+	u32 default_tbl_id = 0;
 	u32 obj_id;
 	int err;
 
