This commit adds support for RTE_FLOW_ACTION_TYPE_OF_POP_VLAN via
direct verbs flow rules.

Signed-off-by: Moti Haimovsky <mo...@mellanox.com>
---
 drivers/net/mlx5/mlx5.c         |  9 +++++
 drivers/net/mlx5/mlx5.h         |  1 +
 drivers/net/mlx5/mlx5_flow.h    |  5 ++-
 drivers/net/mlx5/mlx5_flow_dv.c | 78 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index a3eacdb..4d0ff2d 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -538,6 +538,7 @@ struct mlx5_dev_spawn_data {
                sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
        }
 #endif
+       sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
        sh->dv_refcnt++;
        priv->dr_shared = 1;
        return 0;
@@ -560,6 +561,10 @@ struct mlx5_dev_spawn_data {
                mlx5_glue->destroy_flow_action(sh->esw_drop_action);
                sh->esw_drop_action = NULL;
        }
+       if (sh->pop_vlan_action) {
+               mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
+               sh->pop_vlan_action = NULL;
+       }
        return err;
 #else
        (void)priv;
@@ -605,6 +610,10 @@ struct mlx5_dev_spawn_data {
                sh->esw_drop_action = NULL;
        }
 #endif
+       if (sh->pop_vlan_action) {
+               mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
+               sh->pop_vlan_action = NULL;
+       }
        pthread_mutex_destroy(&sh->dv_mutex);
 #else
        (void)priv;
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index f559f83..4d457bf 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -570,6 +570,7 @@ struct mlx5_ibv_shared {
        void *tx_domain; /* TX Direct Rules name space handle. */
        struct mlx5_flow_tbl_resource tx_tbl[MLX5_MAX_TABLES];
        void *esw_drop_action; /* Pointer to DR E-Switch drop action. */
+       void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
        /* TX Direct Rules tables/ */
        LIST_HEAD(matchers, mlx5_flow_dv_matcher) matchers;
        LIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps;
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8d193b6..06b0470 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -154,7 +154,8 @@
 
 #define MLX5_FLOW_DECAP_ACTIONS        (MLX5_FLOW_ACTION_VXLAN_DECAP | \
                                 MLX5_FLOW_ACTION_NVGRE_DECAP | \
-                                MLX5_FLOW_ACTION_RAW_DECAP)
+                                MLX5_FLOW_ACTION_RAW_DECAP | \
+                                MLX5_FLOW_ACTION_OF_POP_VLAN)
 
 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
                                      MLX5_FLOW_ACTION_SET_IPV4_DST | \
@@ -171,6 +172,8 @@
                                      MLX5_FLOW_ACTION_INC_TCP_ACK | \
                                      MLX5_FLOW_ACTION_DEC_TCP_ACK)
 
+#define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN)
+
 #ifndef IPPROTO_MPLS
 #define IPPROTO_MPLS 137
 #endif
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index ca7252a..05e9c7b 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -831,6 +831,61 @@ struct field_modify_info modify_tcp[] = {
 }
 
 /**
+ * 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.
  *
  * @param[in] dev
@@ -3108,6 +3163,16 @@ struct field_modify_info modify_tcp[] = {
                        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,
@@ -3281,6 +3346,13 @@ struct field_modify_info modify_tcp[] = {
                                                  "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)
@@ -4798,6 +4870,12 @@ struct field_modify_info modify_tcp[] = {
                                                 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,
-- 
1.8.3.1

Reply via email to