net/mlx5: support pop flow action on VLAN header
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index 1d1ff90..fd2e810 100644 (file)
@@ -143,36 +143,20 @@ struct field_modify_info modify_tcp[] = {
 };
 
 static void
-mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item, uint64_t *flags)
+mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
+                         uint8_t next_protocol, uint64_t *item_flags,
+                         int *tunnel)
 {
-       uint8_t next_protocol = 0xFF;
-
-       if (item->mask != NULL) {
-               switch (item->type) {
-               case RTE_FLOW_ITEM_TYPE_IPV4:
-                       next_protocol =
-                               ((const struct rte_flow_item_ipv4 *)
-                                (item->spec))->hdr.next_proto_id;
-                       next_protocol &=
-                               ((const struct rte_flow_item_ipv4 *)
-                                (item->mask))->hdr.next_proto_id;
-                       break;
-               case RTE_FLOW_ITEM_TYPE_IPV6:
-                       next_protocol =
-                               ((const struct rte_flow_item_ipv6 *)
-                                (item->spec))->hdr.proto;
-                       next_protocol &=
-                               ((const struct rte_flow_item_ipv6 *)
-                                (item->mask))->hdr.proto;
-                       break;
-               default:
-                       break;
-               }
+       assert(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
+              item->type == RTE_FLOW_ITEM_TYPE_IPV6);
+       if (next_protocol == IPPROTO_IPIP) {
+               *item_flags |= MLX5_FLOW_LAYER_IPIP;
+               *tunnel = 1;
+       }
+       if (next_protocol == IPPROTO_IPV6) {
+               *item_flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
+               *tunnel = 1;
        }
-       if (next_protocol == IPPROTO_IPIP)
-               *flags |= MLX5_FLOW_LAYER_IPIP;
-       if (next_protocol == IPPROTO_IPV6)
-               *flags |= MLX5_FLOW_LAYER_IPV6_ENCAP;
 }
 
 /**
@@ -830,6 +814,61 @@ flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
        return 0;
 }
 
+/**
+ * Validate the pop VLAN action.
+ *
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
+ * @param[in] action
+ *   Pointer to the pop vlan action.
+ * @param[in] item_flags
+ *   The items found in this flow rule.
+ * @param[in] attr
+ *   Pointer to flow attributes.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
+                                uint64_t action_flags,
+                                const struct rte_flow_action *action,
+                                uint64_t item_flags,
+                                const struct rte_flow_attr *attr,
+                                struct rte_flow_error *error)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+
+       (void)action;
+       (void)attr;
+       if (!priv->sh->pop_vlan_action)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL,
+                                         "pop vlan action is not supported");
+       /*
+        * Check for inconsistencies:
+        *  fail strip_vlan in a flow that matches packets without VLAN tags.
+        *  fail strip_vlan in a flow that matches packets without explicitly a
+        *  matching on VLAN tag ?
+        */
+       if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL,
+                                         "no support for multiple vlan pop "
+                                         "actions");
+       if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL,
+                                         "cannot pop vlan without a "
+                                         "match on (outer) vlan in the flow");
+       return 0;
+}
+
 /**
  * Validate count action.
  *
@@ -965,6 +1004,8 @@ flow_dv_validate_action_raw_encap(uint64_t action_flags,
                                  const struct rte_flow_attr *attr,
                                  struct rte_flow_error *error)
 {
+       const struct rte_flow_action_raw_encap *raw_encap =
+               (const struct rte_flow_action_raw_encap *)action->conf;
        if (!(action->conf))
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION, action,
@@ -986,6 +1027,10 @@ flow_dv_validate_action_raw_encap(uint64_t action_flags,
                                          NULL,
                                          "encap action not supported for "
                                          "ingress");
+       if (!raw_encap->size || !raw_encap->data)
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "raw encap data cannot be empty");
        return 0;
 }
 
@@ -1504,9 +1549,9 @@ flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
 
        /* VLAN skipping */
        while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
-               next_hdr += sizeof(struct rte_vlan_hdr);
                vlan = (struct rte_vlan_hdr *)next_hdr;
                proto = RTE_BE16(vlan->eth_proto);
+               next_hdr += sizeof(struct rte_vlan_hdr);
        }
 
        /* HW calculates IPv4 csum. no need to proceed */
@@ -1967,7 +2012,9 @@ flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
  * Validate jump action.
  *
  * @param[in] action
- *   Pointer to the modify action.
+ *   Pointer to the jump action.
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
  * @param[in] group
  *   The group of the current flow.
  * @param[out] error
@@ -1978,10 +2025,17 @@ flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
  */
 static int
 flow_dv_validate_action_jump(const struct rte_flow_action *action,
+                            uint64_t action_flags,
                             uint32_t group,
                             struct rte_flow_error *error)
 {
-       if (action->type != RTE_FLOW_ACTION_TYPE_JUMP && !action->conf)
+       if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
+                           MLX5_FLOW_FATE_ESWITCH_ACTIONS))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+                                         "can't have 2 fate actions in"
+                                         " same flow");
+       if (!action->conf)
                return rte_flow_error_set(error, EINVAL,
                                          RTE_FLOW_ERROR_TYPE_ACTION_CONF,
                                          NULL, "action configuration not set");
@@ -2319,8 +2373,6 @@ flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
 {
        struct mlx5_ibv_shared *sh = ((struct mlx5_priv *)
                                        (dev->data->dev_private))->sh;
-       struct mlx5dv_pd dv_pd;
-       struct mlx5dv_obj dv_obj;
        struct mlx5_devx_mkey_attr mkey_attr;
        struct mlx5_counter_stats_mem_mng *mem_mng;
        volatile struct flow_counter_stats *raw_data;
@@ -2344,13 +2396,10 @@ flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
                rte_free(mem);
                return NULL;
        }
-       dv_obj.pd.in = sh->pd;
-       dv_obj.pd.out = &dv_pd;
-       mlx5_glue->dv_init_obj(&dv_obj, MLX5DV_OBJ_PD);
        mkey_attr.addr = (uintptr_t)mem;
        mkey_attr.size = size;
        mkey_attr.umem_id = mem_mng->umem->umem_id;
-       mkey_attr.pd = dv_pd.pdn;
+       mkey_attr.pd = sh->pdn;
        mem_mng->dm = mlx5_devx_cmd_mkey_create(sh->ctx, &mkey_attr);
        if (!mem_mng->dm) {
                mlx5_glue->devx_umem_dereg(mem_mng->umem);
@@ -2810,7 +2859,7 @@ flow_dv_validate_attributes(struct rte_eth_dev *dev,
                if (!(priv->representor || priv->master))
                        return rte_flow_error_set
                                (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                NULL, "E-Switch configurationd can only be"
+                                NULL, "E-Switch configuration can only be"
                                 " done by a master or a representor device");
                if (attributes->egress)
                        return rte_flow_error_set
@@ -2822,7 +2871,7 @@ flow_dv_validate_attributes(struct rte_eth_dev *dev,
                                (error, EINVAL,
                                 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
                                 NULL, "group must be smaller than "
-                                RTE_STR(MLX5_MAX_FDB_TABLES));
+                                RTE_STR(MLX5_MAX_TABLES_FDB));
        }
        if (!(attributes->egress ^ attributes->ingress))
                return rte_flow_error_set(error, ENOTSUP,
@@ -2885,7 +2934,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                        (dev, items, attr, item_flags, error);
                        if (ret < 0)
                                return ret;
-                       last_item |= MLX5_FLOW_ITEM_PORT_ID;
+                       last_item = MLX5_FLOW_ITEM_PORT_ID;
                        break;
                case RTE_FLOW_ITEM_TYPE_ETH:
                        ret = mlx5_flow_validate_item_eth(items, item_flags,
@@ -2897,13 +2946,15 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        break;
                case RTE_FLOW_ITEM_TYPE_VLAN:
                        ret = mlx5_flow_validate_item_vlan(items, item_flags,
-                                                          error);
+                                                          dev, error);
                        if (ret < 0)
                                return ret;
                        last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
                                             MLX5_FLOW_LAYER_OUTER_VLAN;
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV4:
+                       mlx5_flow_tunnel_ip_check(items, next_protocol,
+                                                 &item_flags, &tunnel);
                        ret = mlx5_flow_validate_item_ipv4(items, item_flags,
                                                           NULL, error);
                        if (ret < 0)
@@ -2923,9 +2974,10 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                /* Reset for inner layer. */
                                next_protocol = 0xff;
                        }
-                       mlx5_flow_tunnel_ip_check(items, &last_item);
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV6:
+                       mlx5_flow_tunnel_ip_check(items, next_protocol,
+                                                 &item_flags, &tunnel);
                        ret = mlx5_flow_validate_item_ipv6(items, item_flags,
                                                           NULL, error);
                        if (ret < 0)
@@ -2945,7 +2997,6 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                /* Reset for inner layer. */
                                next_protocol = 0xff;
                        }
-                       mlx5_flow_tunnel_ip_check(items, &last_item);
                        break;
                case RTE_FLOW_ITEM_TYPE_TCP:
                        ret = mlx5_flow_validate_item_tcp
@@ -2968,7 +3019,6 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                             MLX5_FLOW_LAYER_OUTER_L4_UDP;
                        break;
                case RTE_FLOW_ITEM_TYPE_GRE:
-               case RTE_FLOW_ITEM_TYPE_NVGRE:
                        ret = mlx5_flow_validate_item_gre(items, item_flags,
                                                          next_protocol, error);
                        if (ret < 0)
@@ -2976,12 +3026,20 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        gre_item = items;
                        last_item = MLX5_FLOW_LAYER_GRE;
                        break;
+               case RTE_FLOW_ITEM_TYPE_NVGRE:
+                       ret = mlx5_flow_validate_item_nvgre(items, item_flags,
+                                                           next_protocol,
+                                                           error);
+                       if (ret < 0)
+                               return ret;
+                       last_item = MLX5_FLOW_LAYER_NVGRE;
+                       break;
                case RTE_FLOW_ITEM_TYPE_GRE_KEY:
                        ret = mlx5_flow_validate_item_gre_key
                                (items, item_flags, gre_item, error);
                        if (ret < 0)
                                return ret;
-                       item_flags |= MLX5_FLOW_LAYER_GRE_KEY;
+                       last_item = MLX5_FLOW_LAYER_GRE_KEY;
                        break;
                case RTE_FLOW_ITEM_TYPE_VXLAN:
                        ret = mlx5_flow_validate_item_vxlan(items, item_flags,
@@ -3019,7 +3077,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                           error);
                        if (ret < 0)
                                return ret;
-                       item_flags |= MLX5_FLOW_LAYER_ICMP;
+                       last_item = MLX5_FLOW_LAYER_ICMP;
                        break;
                case RTE_FLOW_ITEM_TYPE_ICMP6:
                        ret = mlx5_flow_validate_item_icmp6(items, item_flags,
@@ -3027,7 +3085,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                            error);
                        if (ret < 0)
                                return ret;
-                       item_flags |= MLX5_FLOW_LAYER_ICMP6;
+                       last_item = MLX5_FLOW_LAYER_ICMP6;
                        break;
                default:
                        return rte_flow_error_set(error, ENOTSUP,
@@ -3106,6 +3164,16 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        action_flags |= MLX5_FLOW_ACTION_COUNT;
                        ++actions_n;
                        break;
+               case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
+                       if (flow_dv_validate_action_pop_vlan(dev,
+                                                            action_flags,
+                                                            actions,
+                                                            item_flags, attr,
+                                                            error))
+                               return -rte_errno;
+                       action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
+                       ++actions_n;
+                       break;
                case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
                case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
                        ret = flow_dv_validate_action_l2_encap(action_flags,
@@ -3232,6 +3300,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        break;
                case RTE_FLOW_ACTION_TYPE_JUMP:
                        ret = flow_dv_validate_action_jump(actions,
+                                                          action_flags,
                                                           attr->group, error);
                        if (ret)
                                return ret;
@@ -3279,6 +3348,13 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                                                  "action not supported");
                }
        }
+       if ((action_flags & MLX5_FLOW_LAYER_TUNNEL) &&
+           (action_flags & MLX5_FLOW_VLAN_ACTIONS))
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION,
+                                         actions,
+                                         "can't have vxlan and vlan"
+                                         " actions in the same rule");
        /* Eswitch has few restrictions on using items and actions */
        if (attr->transfer) {
                if (action_flags & MLX5_FLOW_ACTION_FLAG)
@@ -3448,6 +3524,8 @@ flow_dv_translate_item_eth(void *matcher, void *key,
 /**
  * Add VLAN item to matcher and to the value.
  *
+ * @param[in, out] dev_flow
+ *   Flow descriptor.
  * @param[in, out] matcher
  *   Flow matcher.
  * @param[in, out] key
@@ -3458,16 +3536,13 @@ flow_dv_translate_item_eth(void *matcher, void *key,
  *   Item is inner pattern.
  */
 static void
-flow_dv_translate_item_vlan(void *matcher, void *key,
+flow_dv_translate_item_vlan(struct mlx5_flow *dev_flow,
+                           void *matcher, void *key,
                            const struct rte_flow_item *item,
                            int inner)
 {
        const struct rte_flow_item_vlan *vlan_m = item->mask;
        const struct rte_flow_item_vlan *vlan_v = item->spec;
-       const struct rte_flow_item_vlan nic_mask = {
-               .tci = RTE_BE16(0x0fff),
-               .inner_type = RTE_BE16(0xffff),
-       };
        void *headers_m;
        void *headers_v;
        uint16_t tci_m;
@@ -3476,7 +3551,7 @@ flow_dv_translate_item_vlan(void *matcher, void *key,
        if (!vlan_v)
                return;
        if (!vlan_m)
-               vlan_m = &nic_mask;
+               vlan_m = &rte_flow_item_vlan_mask;
        if (inner) {
                headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
                                         inner_headers);
@@ -3485,6 +3560,12 @@ flow_dv_translate_item_vlan(void *matcher, void *key,
                headers_m = MLX5_ADDR_OF(fte_match_param, matcher,
                                         outer_headers);
                headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
+               /*
+                * This is workaround, masks are not supported,
+                * and pre-validated.
+                */
+               dev_flow->dv.vf_vlan.tag =
+                       rte_be_to_cpu_16(vlan_v->tci) & 0x0fff;
        }
        tci_m = rte_be_to_cpu_16(vlan_m->tci);
        tci_v = rte_be_to_cpu_16(vlan_m->tci & vlan_v->tci);
@@ -3496,6 +3577,10 @@ flow_dv_translate_item_vlan(void *matcher, void *key,
        MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_cfi, tci_v >> 12);
        MLX5_SET(fte_match_set_lyr_2_4, headers_m, first_prio, tci_m >> 13);
        MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, tci_v >> 13);
+       MLX5_SET(fte_match_set_lyr_2_4, headers_m, ethertype,
+                rte_be_to_cpu_16(vlan_m->inner_type));
+       MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
+                rte_be_to_cpu_16(vlan_m->inner_type & vlan_v->inner_type));
 }
 
 /**
@@ -3921,7 +4006,21 @@ flow_dv_translate_item_nvgre(void *matcher, void *key,
        int size;
        int i;
 
-       flow_dv_translate_item_gre(matcher, key, item, inner);
+       /* For NVGRE, GRE header fields must be set with defined values. */
+       const struct rte_flow_item_gre gre_spec = {
+               .c_rsvd0_ver = RTE_BE16(0x2000),
+               .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
+       };
+       const struct rte_flow_item_gre gre_mask = {
+               .c_rsvd0_ver = RTE_BE16(0xB000),
+               .protocol = RTE_BE16(UINT16_MAX),
+       };
+       const struct rte_flow_item gre_item = {
+               .spec = &gre_spec,
+               .mask = &gre_mask,
+               .last = NULL,
+       };
+       flow_dv_translate_item_gre(matcher, key, &gre_item, inner);
        if (!nvgre_v)
                return;
        if (!nvgre_m)
@@ -4299,11 +4398,9 @@ flow_dv_matcher_enable(uint32_t *match_criteria)
        match_criteria_enable |=
                (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
                MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
-#ifdef HAVE_MLX5DV_DR
        match_criteria_enable |=
                (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
                MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
-#endif
        return match_criteria_enable;
 }
 
@@ -4451,7 +4548,7 @@ flow_dv_matcher_register(struct rte_eth_dev *dev,
                return rte_flow_error_set(error, ENOMEM,
                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
                                          "cannot allocate matcher memory");
-       tbl = flow_dv_tbl_resource_get(dev, matcher->group * MLX5_GROUP_FACTOR,
+       tbl = flow_dv_tbl_resource_get(dev, matcher->group,
                                       matcher->egress, matcher->transfer,
                                       error);
        if (!tbl) {
@@ -4667,6 +4764,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
        uint32_t modify_action_position = UINT32_MAX;
        void *match_mask = matcher.mask.buf;
        void *match_value = dev_flow->dv.value.buf;
+       uint8_t next_protocol = 0xff;
 
        flow->group = attr->group;
        if (attr->transfer)
@@ -4775,6 +4873,12 @@ cnt_err:
                                                 action,
                                                 "cannot create counter"
                                                  " object.");
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
+                       dev_flow->dv.actions[actions_n++] =
+                                               priv->sh->pop_vlan_action;
+                       action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
+                       break;
                case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
                case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
                        if (flow_dv_create_action_l2_encap(dev, actions,
@@ -4840,8 +4944,7 @@ cnt_err:
                        break;
                case RTE_FLOW_ACTION_TYPE_JUMP:
                        jump_data = action->conf;
-                       tbl = flow_dv_tbl_resource_get(dev, jump_data->group *
-                                                      MLX5_GROUP_FACTOR,
+                       tbl = flow_dv_tbl_resource_get(dev, jump_data->group,
                                                       attr->egress,
                                                       attr->transfer, error);
                        if (!tbl)
@@ -4979,7 +5082,8 @@ cnt_err:
                                             MLX5_FLOW_LAYER_OUTER_L2;
                        break;
                case RTE_FLOW_ITEM_TYPE_VLAN:
-                       flow_dv_translate_item_vlan(match_mask, match_value,
+                       flow_dv_translate_item_vlan(dev_flow,
+                                                   match_mask, match_value,
                                                    items, tunnel);
                        matcher.priority = MLX5_PRIORITY_MAP_L2;
                        last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
@@ -4988,6 +5092,8 @@ cnt_err:
                                              MLX5_FLOW_LAYER_OUTER_VLAN);
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV4:
+                       mlx5_flow_tunnel_ip_check(items, next_protocol,
+                                                 &item_flags, &tunnel);
                        flow_dv_translate_item_ipv4(match_mask, match_value,
                                                    items, tunnel, attr->group);
                        matcher.priority = MLX5_PRIORITY_MAP_L3;
@@ -4998,9 +5104,23 @@ cnt_err:
                                         MLX5_IPV4_IBV_RX_HASH);
                        last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
                                             MLX5_FLOW_LAYER_OUTER_L3_IPV4;
-                       mlx5_flow_tunnel_ip_check(items, &last_item);
+                       if (items->mask != NULL &&
+                           ((const struct rte_flow_item_ipv4 *)
+                            items->mask)->hdr.next_proto_id) {
+                               next_protocol =
+                                       ((const struct rte_flow_item_ipv4 *)
+                                        (items->spec))->hdr.next_proto_id;
+                               next_protocol &=
+                                       ((const struct rte_flow_item_ipv4 *)
+                                        (items->mask))->hdr.next_proto_id;
+                       } else {
+                               /* Reset for inner layer. */
+                               next_protocol = 0xff;
+                       }
                        break;
                case RTE_FLOW_ITEM_TYPE_IPV6:
+                       mlx5_flow_tunnel_ip_check(items, next_protocol,
+                                                 &item_flags, &tunnel);
                        flow_dv_translate_item_ipv6(match_mask, match_value,
                                                    items, tunnel, attr->group);
                        matcher.priority = MLX5_PRIORITY_MAP_L3;
@@ -5011,7 +5131,19 @@ cnt_err:
                                         MLX5_IPV6_IBV_RX_HASH);
                        last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
                                             MLX5_FLOW_LAYER_OUTER_L3_IPV6;
-                       mlx5_flow_tunnel_ip_check(items, &last_item);
+                       if (items->mask != NULL &&
+                           ((const struct rte_flow_item_ipv6 *)
+                            items->mask)->hdr.proto) {
+                               next_protocol =
+                                       ((const struct rte_flow_item_ipv6 *)
+                                        items->spec)->hdr.proto;
+                               next_protocol &=
+                                       ((const struct rte_flow_item_ipv6 *)
+                                        items->mask)->hdr.proto;
+                       } else {
+                               /* Reset for inner layer. */
+                               next_protocol = 0xff;
+                       }
                        break;
                case RTE_FLOW_ITEM_TYPE_TCP:
                        flow_dv_translate_item_tcp(match_mask, match_value,
@@ -5045,7 +5177,7 @@ cnt_err:
                case RTE_FLOW_ITEM_TYPE_GRE_KEY:
                        flow_dv_translate_item_gre_key(match_mask,
                                                       match_value, items);
-                       item_flags |= MLX5_FLOW_LAYER_GRE_KEY;
+                       last_item = MLX5_FLOW_LAYER_GRE_KEY;
                        break;
                case RTE_FLOW_ITEM_TYPE_NVGRE:
                        flow_dv_translate_item_nvgre(match_mask, match_value,
@@ -5075,12 +5207,12 @@ cnt_err:
                case RTE_FLOW_ITEM_TYPE_ICMP:
                        flow_dv_translate_item_icmp(match_mask, match_value,
                                                    items, tunnel);
-                       item_flags |= MLX5_FLOW_LAYER_ICMP;
+                       last_item = MLX5_FLOW_LAYER_ICMP;
                        break;
                case RTE_FLOW_ITEM_TYPE_ICMP6:
                        flow_dv_translate_item_icmp6(match_mask, match_value,
                                                      items, tunnel);
-                       item_flags |= MLX5_FLOW_LAYER_ICMP6;
+                       last_item = MLX5_FLOW_LAYER_ICMP6;
                        break;
                default:
                        break;
@@ -5166,13 +5298,14 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                                             dv->hash_fields,
                                             (*flow->queue),
                                             flow->rss.queue_num);
-                       if (!hrxq)
+                       if (!hrxq) {
                                hrxq = mlx5_hrxq_new
                                        (dev, flow->key, MLX5_RSS_HASH_KEY_LEN,
                                         dv->hash_fields, (*flow->queue),
                                         flow->rss.queue_num,
                                         !!(dev_flow->layers &
                                            MLX5_FLOW_LAYER_TUNNEL));
+                       }
                        if (!hrxq) {
                                rte_flow_error_set
                                        (error, rte_errno,
@@ -5194,6 +5327,17 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                                           "hardware refuses to create flow");
                        goto error;
                }
+               if (priv->vmwa_context &&
+                   dev_flow->dv.vf_vlan.tag &&
+                   !dev_flow->dv.vf_vlan.created) {
+                       /*
+                        * The rule contains the VLAN pattern.
+                        * For VF we are going to create VLAN
+                        * interface to make hypervisor set correct
+                        * e-Switch vport context.
+                        */
+                       mlx5_vlan_vmwa_acquire(dev, &dev_flow->dv.vf_vlan);
+               }
        }
        return 0;
 error:
@@ -5207,6 +5351,9 @@ error:
                                mlx5_hrxq_release(dev, dv->hrxq);
                        dv->hrxq = NULL;
                }
+               if (dev_flow->dv.vf_vlan.tag &&
+                   dev_flow->dv.vf_vlan.created)
+                       mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
        }
        rte_errno = err; /* Restore rte_errno. */
        return -rte_errno;
@@ -5407,6 +5554,9 @@ flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
                                mlx5_hrxq_release(dev, dv->hrxq);
                        dv->hrxq = NULL;
                }
+               if (dev_flow->dv.vf_vlan.tag &&
+                   dev_flow->dv.vf_vlan.created)
+                       mlx5_vlan_vmwa_release(dev, &dev_flow->dv.vf_vlan);
        }
 }