net/mlx5: add drop action to Direct Verbs E-Switch
authorOri Kam <orika@mellanox.com>
Thu, 18 Apr 2019 13:16:07 +0000 (13:16 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 19 Apr 2019 12:51:55 +0000 (14:51 +0200)
This commit adds support for drop action when creating E-Switch flow
using DV.

Signed-off-by: Ori Kam <orika@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow_dv.c
drivers/net/mlx5/mlx5_glue.c
drivers/net/mlx5/mlx5_glue.h

index af21a33..46ca08a 100644 (file)
@@ -357,6 +357,7 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
                        goto error;
                }
                sh->fdb_ns = ns;
+               sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
        }
 #endif
        sh->dv_refcnt++;
@@ -377,6 +378,10 @@ error:
                mlx5_glue->dr_destroy_ns(sh->fdb_ns);
                sh->fdb_ns = NULL;
        }
+       if (sh->esw_drop_action) {
+               mlx5_glue->destroy_flow_action(sh->esw_drop_action);
+               sh->esw_drop_action = NULL;
+       }
        return err;
 #else
        (void)priv;
@@ -417,6 +422,10 @@ mlx5_free_shared_dr(struct mlx5_priv *priv)
                mlx5_glue->dr_destroy_ns(sh->fdb_ns);
                sh->fdb_ns = NULL;
        }
+       if (sh->esw_drop_action) {
+               mlx5_glue->destroy_flow_action(sh->esw_drop_action);
+               sh->esw_drop_action = NULL;
+       }
 #endif
        pthread_mutex_destroy(&sh->dv_mutex);
 #else
index 97f4c8d..0a6d7f1 100644 (file)
@@ -286,6 +286,7 @@ struct mlx5_ibv_shared {
        /* RX Direct Rules tables. */
        void *tx_ns; /* 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. */
        /* TX Direct Rules tables/ */
        LIST_HEAD(matchers, mlx5_flow_dv_matcher) matchers;
        LIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps;
index b15c852..2f777ec 100644 (file)
@@ -4052,6 +4052,7 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
 {
        struct mlx5_flow_dv *dv;
        struct mlx5_flow *dev_flow;
+       struct mlx5_priv *priv = dev->data->dev_private;
        int n;
        int err;
 
@@ -4059,15 +4060,20 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                dv = &dev_flow->dv;
                n = dv->actions_n;
                if (flow->actions & MLX5_FLOW_ACTION_DROP) {
-                       dv->hrxq = mlx5_hrxq_drop_new(dev);
-                       if (!dv->hrxq) {
-                               rte_flow_error_set
-                                       (error, errno,
-                                        RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-                                        "cannot get drop hash queue");
-                               goto error;
+                       if (flow->transfer) {
+                               dv->actions[n++] = priv->sh->esw_drop_action;
+                       } else {
+                               dv->hrxq = mlx5_hrxq_drop_new(dev);
+                               if (!dv->hrxq) {
+                                       rte_flow_error_set
+                                               (error, errno,
+                                                RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                                NULL,
+                                                "cannot get drop hash queue");
+                                       goto error;
+                               }
+                               dv->actions[n++] = dv->hrxq->action;
                        }
-                       dv->actions[n++] = dv->hrxq->action;
                } else if (flow->actions &
                           (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) {
                        struct mlx5_hrxq *hrxq;
index 117190f..b32cd09 100644 (file)
@@ -393,6 +393,16 @@ mlx5_glue_dr_create_flow_action_dest_vport(void *ns, uint32_t vport)
 #endif
 }
 
+static void *
+mlx5_glue_dr_create_flow_action_drop(void)
+{
+#ifdef HAVE_MLX5DV_DR_ESWITCH
+       return mlx5dv_dr_create_action_drop();
+#else
+       return NULL;
+#endif
+}
+
 static void *
 mlx5_glue_dr_create_flow_tbl(void *ns, uint32_t level)
 {
@@ -861,6 +871,8 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
                mlx5_glue_dr_create_flow_action_dest_flow_tbl,
        .dr_create_flow_action_dest_vport =
                mlx5_glue_dr_create_flow_action_dest_vport,
+       .dr_create_flow_action_drop =
+               mlx5_glue_dr_create_flow_action_drop,
        .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
        .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
        .dr_create_ns = mlx5_glue_dr_create_ns,
index 26f5cb3..1d06583 100644 (file)
@@ -147,6 +147,7 @@ struct mlx5_glue {
        struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
        void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
        void *(*dr_create_flow_action_dest_vport)(void *ns, uint32_t vport);
+       void *(*dr_create_flow_action_drop)();
        void *(*dr_create_flow_tbl)(void *ns, uint32_t level);
        int (*dr_destroy_flow_tbl)(void *tbl);
        void *(*dr_create_ns)(struct ibv_context *ctx,