common/mlx5: introduce common library
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index 059d03f..1b31602 100644 (file)
 #include <rte_vxlan.h>
 #include <rte_gtp.h>
 
-#include "mlx5.h"
+#include <mlx5_glue.h>
+#include <mlx5_devx_cmds.h>
+#include <mlx5_prm.h>
+
 #include "mlx5_defs.h"
-#include "mlx5_glue.h"
+#include "mlx5.h"
 #include "mlx5_flow.h"
-#include "mlx5_prm.h"
 #include "mlx5_rxtx.h"
 
 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
@@ -1077,7 +1079,7 @@ flow_dv_convert_action_mark(struct rte_eth_dev *dev,
                {4, 0, 0}, /* dynamic instead of MLX5_MODI_META_REG_C_1. */
                {0, 0, 0},
        };
-       enum modify_reg reg;
+       int reg;
 
        if (!mask)
                return rte_flow_error_set(error, EINVAL,
@@ -1119,7 +1121,7 @@ flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
                         const struct rte_flow_attr *attr,
                         struct rte_flow_error *error)
 {
-       enum modify_reg reg =
+       int reg =
                mlx5_flow_get_reg_id(dev, attr->transfer ?
                                          MLX5_METADATA_FDB :
                                            attr->egress ?
@@ -1167,7 +1169,7 @@ flow_dv_convert_action_set_meta
        struct field_modify_info reg_c_x[] = {
                [1] = {0, 0, 0},
        };
-       enum modify_reg reg = flow_dv_get_metadata_reg(dev, attr, error);
+       int reg = flow_dv_get_metadata_reg(dev, attr, error);
 
        if (reg < 0)
                return reg;
@@ -1370,7 +1372,7 @@ flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
        struct rte_flow_item_meta nic_mask = {
                .data = UINT32_MAX
        };
-       enum modify_reg reg;
+       int reg;
        int ret;
 
        if (!spec)
@@ -2004,7 +2006,7 @@ flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
 {
        const struct rte_flow_action_set_meta *conf;
        uint32_t nic_mask = UINT32_MAX;
-       enum modify_reg reg;
+       int reg;
 
        if (!mlx5_flow_ext_mreg_supported(dev))
                return rte_flow_error_set(error, ENOTSUP,
@@ -2883,8 +2885,6 @@ flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
                        (const struct rte_flow_action_raw_encap *)action->conf;
                res.size = raw_encap_data->size;
                memcpy(res.buf, raw_encap_data->data, res.size);
-               if (flow_dv_zero_encap_udp_csum(res.buf, error))
-                       return -rte_errno;
        } else {
                if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
                        encap_data =
@@ -2898,6 +2898,8 @@ flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
                                               &res.size, error))
                        return -rte_errno;
        }
+       if (flow_dv_zero_encap_udp_csum(res.buf, error))
+               return -rte_errno;
        if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION,
@@ -4402,6 +4404,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
        uint8_t next_protocol = 0xff;
        uint16_t ether_type = 0;
        int actions_n = 0;
+       uint8_t item_ipv6_proto = 0;
        const struct rte_flow_item *gre_item = NULL;
        struct rte_flow_item_tcp nic_tcp_mask = {
                .hdr = {
@@ -4509,6 +4512,9 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        if (items->mask != NULL &&
                            ((const struct rte_flow_item_ipv6 *)
                             items->mask)->hdr.proto) {
+                               item_ipv6_proto =
+                                       ((const struct rte_flow_item_ipv6 *)
+                                        items->spec)->hdr.proto;
                                next_protocol =
                                        ((const struct rte_flow_item_ipv6 *)
                                         items->spec)->hdr.proto;
@@ -4881,6 +4887,12 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                                  error);
                        if (ret < 0)
                                return ret;
+                       if (item_ipv6_proto == IPPROTO_ICMPV6)
+                               return rte_flow_error_set(error, ENOTSUP,
+                                       RTE_FLOW_ERROR_TYPE_ACTION,
+                                       actions,
+                                       "Can't change header "
+                                       "with ICMPv6 proto");
                        /* Count all modify-header actions as one action. */
                        if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
                                ++actions_n;
@@ -6081,7 +6093,7 @@ flow_dv_translate_item_meta(struct rte_eth_dev *dev,
                meta_m = &rte_flow_item_meta_mask;
        meta_v = (const void *)item->spec;
        if (meta_v) {
-               enum modify_reg reg;
+               int reg;
                uint32_t value = meta_v->data;
                uint32_t mask = meta_m->data;
 
@@ -7602,13 +7614,13 @@ cnt_err:
                item_flags |= last_item;
        }
        /*
-        * In case of ingress traffic when E-Switch mode is enabled,
-        * we have two cases where we need to set the source port manually.
+        * When E-Switch mode is enabled, we have two cases where we need to
+        * set the source port manually.
         * The first one, is in case of Nic steering rule, and the second is
         * E-Switch rule where no port_id item was found. In both cases
         * the source port is set according the current port in use.
         */
-       if ((attr->ingress && !(item_flags & MLX5_FLOW_ITEM_PORT_ID)) &&
+       if (!(item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
            (priv->representor || priv->master)) {
                if (flow_dv_translate_item_port_id(dev, match_mask,
                                                   match_value, NULL))
@@ -8261,7 +8273,7 @@ flow_dv_prepare_mtr_tables(struct rte_eth_dev *dev,
        dv_attr.match_criteria_enable =
                                1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
        flow_dv_match_meta_reg(mask.buf, value.buf, color_reg_c_idx,
-                              rte_col_2_mlx5_col(RTE_COLORS), UINT32_MAX);
+                              rte_col_2_mlx5_col(RTE_COLORS), UINT8_MAX);
        dtb->color_matcher = mlx5_glue->dv_create_flow_matcher(sh->ctx,
                                                               &dv_attr,
                                                               dtb->tbl->obj);
@@ -8455,7 +8467,7 @@ flow_dv_create_policer_forward_rule(struct mlx5_flow_meter *fm,
                int j = 0;
 
                flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
-                                      rte_col_2_mlx5_col(i), UINT32_MAX);
+                                      rte_col_2_mlx5_col(i), UINT8_MAX);
                if (mtb->count_actns[i])
                        actions[j++] = mtb->count_actns[i];
                if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)