common/mlx5: introduce common library
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index de4b765..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)
@@ -1662,14 +1664,10 @@ flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
 /**
  * Get VLAN default info from vlan match info.
  *
- * @param[in] dev
- *   Pointer to the rte_eth_dev structure.
- * @param[in] item
+ * @param[in] items
  *   the list of item specifications.
  * @param[out] vlan
  *   pointer VLAN info to fill to.
- * @param[out] error
- *   Pointer to error structure.
  *
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
@@ -1721,8 +1719,10 @@ flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
  *
  * @param[in] action_flags
  *   Holds the actions detected until now.
+ * @param[in] item_flags
+ *   The items found in this flow rule.
  * @param[in] action
- *   Pointer to the encap action.
+ *   Pointer to the action structure.
  * @param[in] attr
  *   Pointer to flow attributes
  * @param[out] error
@@ -1772,8 +1772,6 @@ flow_dv_validate_action_push_vlan(uint64_t action_flags,
  *   Holds the actions detected until now.
  * @param[in] actions
  *   Pointer to the list of actions remaining in the flow rule.
- * @param[in] attr
- *   Pointer to flow attributes
  * @param[out] error
  *   Pointer to error structure.
  *
@@ -1815,10 +1813,10 @@ flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
  *
  * @param[in] item_flags
  *   Holds the items detected in this rule.
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
  * @param[in] actions
  *   Pointer to the list of actions remaining in the flow rule.
- * @param[in] attr
- *   Pointer to flow attributes
  * @param[out] error
  *   Pointer to error structure.
  *
@@ -1838,33 +1836,17 @@ flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "VLAN VID value is too big");
-       /* there is an of_push_vlan action before us */
-       if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
-               if (mlx5_flow_find_action(actions + 1,
-                                         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID))
-                       return rte_flow_error_set(error, ENOTSUP,
-                                       RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                       "Multiple VLAN VID modifications are "
-                                       "not supported");
-               else
-                       return 0;
-       }
-
-       /*
-        * Action is on an existing VLAN header:
-        *    Need to verify this is a single modify CID action.
-        *   Rule mast include a match on outer VLAN.
-        */
+       if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
+           !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN VID action must follow push"
+                                         " VLAN action or match on VLAN item");
        if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
                return rte_flow_error_set(error, ENOTSUP,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
                                          "Multiple VLAN VID modifications are "
                                          "not supported");
-       if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
-               return rte_flow_error_set(error, EINVAL,
-                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
-                                         "match on VLAN is required in order "
-                                         "to set VLAN VID");
        if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
@@ -2004,7 +1986,7 @@ flow_dv_validate_action_mark(struct rte_eth_dev *dev,
  * @param[in] dev
  *   Pointer to the rte_eth_dev structure.
  * @param[in] action
- *   Pointer to the encap action.
+ *   Pointer to the action structure.
  * @param[in] action_flags
  *   Holds the actions detected until now.
  * @param[in] attr
@@ -2024,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,
@@ -2065,7 +2047,7 @@ flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
  * @param[in] dev
  *   Pointer to the rte_eth_dev structure.
  * @param[in] action
- *   Pointer to the encap action.
+ *   Pointer to the action structure.
  * @param[in] action_flags
  *   Holds the actions detected until now.
  * @param[in] attr
@@ -2119,7 +2101,7 @@ flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
  * Validate count action.
  *
  * @param[in] dev
- *   device otr.
+ *   Pointer to rte_eth_dev structure.
  * @param[out] error
  *   Pointer to error structure.
  *
@@ -2151,7 +2133,7 @@ notsup_err:
  * @param[in] action_flags
  *   Holds the actions detected until now.
  * @param[in] action
- *   Pointer to the encap action.
+ *   Pointer to the action structure.
  * @param[in] attr
  *   Pointer to flow attributes
  * @param[out] error
@@ -2903,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 =
@@ -2918,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,
@@ -3011,12 +2993,12 @@ flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
  *
  * @param[in] dev
  *   Pointer to rte_eth_dev structure.
- * @param[in] vlan_tag
- *   the vlan tag to push to the Ethernet header.
- * @param[in, out] dev_flow
- *   Pointer to the mlx5_flow.
  * @param[in] attr
  *   Pointer to the flow attributes.
+ * @param[in] vlan
+ *   Pointer to the vlan to push to the Ethernet header.
+ * @param[in, out] dev_flow
+ *   Pointer to the mlx5_flow.
  * @param[out] error
  *   Pointer to the error structure.
  *
@@ -4422,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 = {
@@ -4529,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;
@@ -4901,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;
@@ -6101,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;
 
@@ -7622,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))
@@ -8281,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);
@@ -8475,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)