[7/8] net/mlx5: update the metadata register c0 support

Message ID 1593102379-400132-8-git-send-email-jiaweiw@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series support the flow-based traffic sampling |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jiawei Wang June 25, 2020, 4:26 p.m. UTC
  For Sample flow, it splits into two sub flows and using metadata
register as matcher between two flows.

Meatadata register C0 filed might be also used for source vport
index if kernel uses this field, this changes add the checking
while do tag action with reg_c0 to decide using upper or lower
16-bits of metadata register c0 filed.

Signed-off-by: Jiawei Wang <jiaweiw@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow_dv.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 62a4a3b..ed9d2d2e 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -980,13 +980,24 @@  struct field_modify_info modify_tcp[] = {
  */
 static int
 flow_dv_convert_action_set_reg
-			(struct mlx5_flow_dv_modify_hdr_resource *resource,
+			(struct rte_eth_dev *dev,
+			 struct mlx5_flow_dv_modify_hdr_resource *resource,
 			 const struct rte_flow_action *action,
 			 struct rte_flow_error *error)
 {
 	const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
-	struct mlx5_modification_cmd *actions = resource->actions;
 	uint32_t i = resource->actions_num;
+	struct mlx5_priv *priv = dev->data->dev_private;
+	rte_be32_t mask = UINT32_MAX;
+	rte_be32_t data = rte_cpu_to_be_32(conf->data) & mask;
+	struct rte_flow_item item = {
+		.spec = &data,
+		.mask = &mask,
+	};
+	struct field_modify_info reg_c_x[] = {
+		[1] = {0, 0, 0},
+	};
+	int reg = conf->id;
 
 	if (i >= MLX5_MAX_MODIFY_NUM)
 		return rte_flow_error_set(error, EINVAL,
@@ -994,15 +1005,16 @@  struct field_modify_info modify_tcp[] = {
 					  "too many items to modify");
 	MLX5_ASSERT(conf->id != REG_NONE);
 	MLX5_ASSERT(conf->id < RTE_DIM(reg_to_field));
-	actions[i] = (struct mlx5_modification_cmd) {
-		.action_type = MLX5_MODIFICATION_TYPE_SET,
-		.field = reg_to_field[conf->id],
-	};
-	actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
-	actions[i].data1 = rte_cpu_to_be_32(conf->data);
-	++i;
-	resource->actions_num = i;
-	return 0;
+	if (reg == REG_C_0) {
+		uint32_t msk_c0 = priv->sh->dv_regc0_mask;
+		uint32_t shl_c0 = rte_bsf32(msk_c0);
+		data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
+		mask = rte_cpu_to_be_32(mask) & msk_c0;
+		mask = rte_cpu_to_be_32(mask << shl_c0);
+	}
+	reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
+	return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
+			MLX5_MODIFICATION_TYPE_SET, error);
 }
 
 /**
@@ -8722,7 +8734,7 @@  struct field_modify_info modify_tcp[] = {
 			break;
 		case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
 			if (flow_dv_convert_action_set_reg
-					(mhdr_res, actions, error))
+					(dev, mhdr_res, actions, error))
 				return -rte_errno;
 			action_flags |= MLX5_FLOW_ACTION_SET_TAG;
 			break;