ADD_FIELD operation allows user to add the src field value to the
dest field. Dest field has the sum of src field value and original
dst field value.

Signed-off-by: Suanming Mou <suanmi...@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_dv.c | 11 +++++++----
 drivers/net/mlx5/mlx5_flow_hw.c | 10 +++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 272dbca00f..1c3d557d4a 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -389,6 +389,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
        uint32_t i = resource->actions_num;
        struct mlx5_modification_cmd *actions = resource->actions;
        uint32_t carry_b = 0;
+       bool to_dest;
 
        /*
         * The item and mask are provided in big-endian format.
@@ -397,6 +398,8 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
         */
        MLX5_ASSERT(item->mask);
        MLX5_ASSERT(field->size);
+       to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
+                 type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
        do {
                uint32_t size_b;
                uint32_t off_b;
@@ -416,7 +419,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
                        ++field;
                        continue;
                }
-               if (type == MLX5_MODIFICATION_TYPE_COPY && field->is_flex) {
+               if (to_dest && field->is_flex) {
                        off_b = 32 - field->shift + carry_b - field->size * 
CHAR_BIT;
                        size_b = field->size * CHAR_BIT - carry_b;
                } else {
@@ -433,7 +436,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
                        .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
                                0 : size_b,
                };
-               if (type == MLX5_MODIFICATION_TYPE_COPY) {
+               if (to_dest) {
                        MLX5_ASSERT(dest);
                        actions[i].dst_field = dest->id;
                        actions[i].dst_offset =
@@ -476,11 +479,11 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
                }
                /* Convert entire record to expected big-endian format. */
                actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
-               if ((type != MLX5_MODIFICATION_TYPE_COPY ||
+               if ((!to_dest ||
                     dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
                    field->id != (enum mlx5_modification_field)UINT32_MAX)
                        ++i;
-               if (next_dest && type == MLX5_MODIFICATION_TYPE_COPY)
+               if (next_dest && to_dest)
                        ++dest;
                if (next_field)
                        ++field;
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index da873ae2e2..d224979ee8 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -1102,7 +1102,8 @@ flow_hw_should_insert_nop(const struct 
mlx5_hw_modify_header_action *mhdr,
                if (last_type == MLX5_MODIFICATION_TYPE_SET ||
                    last_type == MLX5_MODIFICATION_TYPE_ADD)
                        should_insert = new_cmd.field == last_cmd.field;
-               else if (last_type == MLX5_MODIFICATION_TYPE_COPY)
+               else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
+                        last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
                        should_insert = new_cmd.field == last_cmd.dst_field;
                else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
                        should_insert = false;
@@ -1110,11 +1111,13 @@ flow_hw_should_insert_nop(const struct 
mlx5_hw_modify_header_action *mhdr,
                        MLX5_ASSERT(false); /* Other types are not supported. */
                break;
        case MLX5_MODIFICATION_TYPE_COPY:
+       case MLX5_MODIFICATION_TYPE_ADD_FIELD:
                if (last_type == MLX5_MODIFICATION_TYPE_SET ||
                    last_type == MLX5_MODIFICATION_TYPE_ADD)
                        should_insert = (new_cmd.field == last_cmd.field ||
                                         new_cmd.dst_field == last_cmd.field);
-               else if (last_type == MLX5_MODIFICATION_TYPE_COPY)
+               else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
+                        last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
                        should_insert = (new_cmd.field == last_cmd.dst_field ||
                                         new_cmd.dst_field == 
last_cmd.dst_field);
                else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
@@ -1264,7 +1267,8 @@ flow_hw_modify_field_compile(struct rte_eth_dev *dev,
                        item.spec = &value;
                }
        } else {
-               type = MLX5_MODIFICATION_TYPE_COPY;
+               type = conf->operation == RTE_FLOW_MODIFY_SET ?
+                      MLX5_MODIFICATION_TYPE_COPY : 
MLX5_MODIFICATION_TYPE_ADD_FIELD;
                /* For COPY fill the destination field (dcopy) without mask. */
                mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
                                                  conf->width, dev,
-- 
2.34.1

Reply via email to