net/mlx5: add metadata register copy
authorViacheslav Ovsiienko <viacheslavo@mellanox.com>
Thu, 7 Nov 2019 17:09:48 +0000 (17:09 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 11 Nov 2019 13:23:01 +0000 (14:23 +0100)
Add flow metadata register copy action which is supported through modify
header command. As it is an internal action, not exposed to users, item
type (MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG) is negative value. This can be
used when creating PMD internal subflows.

Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
drivers/net/mlx5/mlx5_flow.h
drivers/net/mlx5/mlx5_flow_dv.c

index f6f8f82..492f65e 100644 (file)
@@ -47,24 +47,30 @@ enum mlx5_rte_flow_item_type {
        MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
 };
 
-/* Private rte flow actions. */
+/* Private (internal) rte flow actions. */
 enum mlx5_rte_flow_action_type {
        MLX5_RTE_FLOW_ACTION_TYPE_END = INT_MIN,
        MLX5_RTE_FLOW_ACTION_TYPE_TAG,
+       MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
 };
 
 /* Matches on selected register. */
 struct mlx5_rte_flow_item_tag {
-       uint16_t id;
+       enum modify_reg id;
        uint32_t data;
 };
 
 /* Modify selected register. */
 struct mlx5_rte_flow_action_set_tag {
-       uint16_t id;
+       enum modify_reg id;
        uint32_t data;
 };
 
+struct mlx5_flow_action_copy_mreg {
+       enum modify_reg dst;
+       enum modify_reg src;
+};
+
 /* Matches on source queue. */
 struct mlx5_rte_flow_item_tx_queue {
        uint32_t queue;
@@ -227,7 +233,6 @@ struct mlx5_rte_flow_item_tx_queue {
 
 #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \
                                MLX5_FLOW_ACTION_OF_PUSH_VLAN)
-
 #ifndef IPPROTO_MPLS
 #define IPPROTO_MPLS 137
 #endif
index 7409bae..bbebeaf 100644 (file)
@@ -863,7 +863,7 @@ flow_dv_convert_action_set_reg
                         const struct rte_flow_action *action,
                         struct rte_flow_error *error)
 {
-       const struct mlx5_rte_flow_action_set_tag *conf = (action->conf);
+       const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
        struct mlx5_modification_cmd *actions = resource->actions;
        uint32_t i = resource->actions_num;
 
@@ -884,6 +884,47 @@ flow_dv_convert_action_set_reg
        return 0;
 }
 
+/**
+ * Convert internal COPY_REG action to DV specification.
+ *
+ * @param[in] dev
+ *   Pointer to the rte_eth_dev structure.
+ * @param[in,out] res
+ *   Pointer to the modify-header resource.
+ * @param[in] action
+ *   Pointer to action specification.
+ * @param[out] error
+ *   Pointer to the error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev  __rte_unused,
+                                struct mlx5_flow_dv_modify_hdr_resource *res,
+                                const struct rte_flow_action *action,
+                                struct rte_flow_error *error)
+{
+       const struct mlx5_flow_action_copy_mreg *conf = action->conf;
+       uint32_t mask = RTE_BE32(UINT32_MAX);
+       struct rte_flow_item item = {
+               .spec = NULL,
+               .mask = &mask,
+       };
+       struct field_modify_info reg_src[] = {
+               {4, 0, reg_to_field[conf->src]},
+               {0, 0, 0},
+       };
+       struct field_modify_info reg_dst = {
+               .offset = (uint32_t)-1, /* Same as src. */
+               .id = reg_to_field[conf->dst],
+       };
+       return flow_dv_convert_modify_action(&item,
+                                            reg_src, &reg_dst, res,
+                                            MLX5_MODIFICATION_TYPE_COPY,
+                                            error);
+}
+
 /**
  * Validate META item.
  *
@@ -3978,6 +4019,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                MLX5_FLOW_ACTION_DEC_TCP_ACK;
                        break;
                case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
+               case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
                        break;
                default:
                        return rte_flow_error_set(error, ENOTSUP,
@@ -5974,6 +6016,12 @@ cnt_err:
                                return -rte_errno;
                        action_flags |= MLX5_FLOW_ACTION_SET_TAG;
                        break;
+               case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
+                       if (flow_dv_convert_action_copy_mreg(dev, &res,
+                                                            actions, error))
+                               return -rte_errno;
+                       action_flags |= MLX5_FLOW_ACTION_SET_TAG;
+                       break;
                case RTE_FLOW_ACTION_TYPE_END:
                        actions_end = true;
                        if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS) {