common/mlx5: introduce common library
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index fc156a3..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
@@ -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;
@@ -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)