net/mlx5: create global drop action
authorSuanming Mou <suanmingm@nvidia.com>
Wed, 28 Oct 2020 09:33:30 +0000 (17:33 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:35:04 +0000 (23:35 +0100)
This commit creates the global drop action for flows instead of
maintain it in flow insertion time. The uniqueu global drop action
makes it thread safe.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5_flow_dv.c
drivers/net/mlx5/mlx5_flow_verbs.c

index ae735a3..b12d1d5 100644 (file)
@@ -1424,6 +1424,9 @@ err_secondary:
        } else {
                priv->obj_ops = ibv_obj_ops;
        }
+       priv->drop_queue.hrxq = mlx5_drop_action_create(eth_dev);
+       if (!priv->drop_queue.hrxq)
+               goto error;
        /* Supported Verbs flow priority number detection. */
        err = mlx5_flow_discover_priorities(eth_dev);
        if (err < 0) {
@@ -1489,6 +1492,8 @@ error:
                        close(priv->nl_socket_rdma);
                if (priv->vmwa_context)
                        mlx5_vlan_vmwa_exit(priv->vmwa_context);
+               if (eth_dev && priv->drop_queue.hrxq)
+                       mlx5_drop_action_destroy(eth_dev);
                if (own_domain_id)
                        claim_zero(rte_eth_switch_domain_free(priv->domain_id));
                mlx5_free(priv);
index fa00e45..2ebc179 100644 (file)
@@ -1308,6 +1308,8 @@ mlx5_dev_close(struct rte_eth_dev *dev)
                priv->txqs = NULL;
        }
        mlx5_proc_priv_uninit(dev);
+       if (priv->drop_queue.hrxq)
+               mlx5_drop_action_destroy(dev);
        if (priv->mreg_cp_tbl)
                mlx5_hlist_destroy(priv->mreg_cp_tbl, NULL, NULL);
        mlx5_mprq_free_mp(dev);
index 34f5608..4322c59 100644 (file)
@@ -10319,24 +10319,9 @@ __flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                        if (dv->transfer) {
                                dv->actions[n++] = priv->sh->esw_drop_action;
                        } else {
-                               struct mlx5_hrxq *drop_hrxq;
-                               drop_hrxq = mlx5_drop_action_create(dev);
-                               if (!drop_hrxq) {
-                                       rte_flow_error_set
-                                               (error, errno,
-                                                RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                                NULL,
-                                                "cannot get drop hash queue");
-                                       goto error;
-                               }
-                               /*
-                                * Drop queues will be released by the specify
-                                * mlx5_drop_action_destroy() function. Assign
-                                * the special index to hrxq to mark the queue
-                                * has been allocated.
-                                */
-                               dh->rix_hrxq = UINT32_MAX;
-                               dv->actions[n++] = drop_hrxq->action;
+                               MLX5_ASSERT(priv->drop_queue.hrxq);
+                               dv->actions[n++] =
+                                               priv->drop_queue.hrxq->action;
                        }
                } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
                           !dv_h->rix_sample && !dv_h->rix_dest_array) {
@@ -10390,14 +10375,9 @@ error:
        SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
                       handle_idx, dh, next) {
                /* hrxq is union, don't clear it if the flag is not set. */
-               if (dh->rix_hrxq) {
-                       if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
-                               mlx5_drop_action_destroy(dev);
-                               dh->rix_hrxq = 0;
-                       } else if (dh->fate_action == MLX5_FLOW_FATE_QUEUE) {
-                               mlx5_hrxq_release(dev, dh->rix_hrxq);
-                               dh->rix_hrxq = 0;
-                       }
+               if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq) {
+                       mlx5_hrxq_release(dev, dh->rix_hrxq);
+                       dh->rix_hrxq = 0;
                }
                if (dh->vf_vlan.tag && dh->vf_vlan.created)
                        mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
@@ -10643,9 +10623,6 @@ flow_dv_fate_resource_release(struct rte_eth_dev *dev,
        if (!handle->rix_fate)
                return;
        switch (handle->fate_action) {
-       case MLX5_FLOW_FATE_DROP:
-               mlx5_drop_action_destroy(dev);
-               break;
        case MLX5_FLOW_FATE_QUEUE:
                mlx5_hrxq_release(dev, handle->rix_hrxq);
                break;
@@ -10825,8 +10802,7 @@ __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
                        claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
                        dh->drv_flow = NULL;
                }
-               if (dh->fate_action == MLX5_FLOW_FATE_DROP ||
-                   dh->fate_action == MLX5_FLOW_FATE_QUEUE)
+               if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
                        flow_dv_fate_resource_release(dev, dh);
                if (dh->vf_vlan.tag && dh->vf_vlan.created)
                        mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
index 0ec9acd..3c04727 100644 (file)
@@ -72,12 +72,12 @@ mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
                },
        };
        struct ibv_flow *flow;
-       struct mlx5_hrxq *drop = mlx5_drop_action_create(dev);
+       struct mlx5_hrxq *drop = priv->drop_queue.hrxq;
        uint16_t vprio[] = { 8, 16 };
        int i;
        int priority = 0;
 
-       if (!drop) {
+       if (!drop->qp) {
                rte_errno = ENOTSUP;
                return -rte_errno;
        }
@@ -89,7 +89,6 @@ mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
                claim_zero(mlx5_glue->destroy_flow(flow));
                priority = vprio[i];
        }
-       mlx5_drop_action_destroy(dev);
        switch (priority) {
        case 8:
                priority = RTE_DIM(priority_map_3);
@@ -1886,15 +1885,10 @@ flow_verbs_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
                        handle->drv_flow = NULL;
                }
                /* hrxq is union, don't touch it only the flag is set. */
-               if (handle->rix_hrxq) {
-                       if (handle->fate_action == MLX5_FLOW_FATE_DROP) {
-                               mlx5_drop_action_destroy(dev);
-                               handle->rix_hrxq = 0;
-                       } else if (handle->fate_action ==
-                                  MLX5_FLOW_FATE_QUEUE) {
-                               mlx5_hrxq_release(dev, handle->rix_hrxq);
-                               handle->rix_hrxq = 0;
-                       }
+               if (handle->rix_hrxq &&
+                   handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
+                       mlx5_hrxq_release(dev, handle->rix_hrxq);
+                       handle->rix_hrxq = 0;
                }
                if (handle->vf_vlan.tag && handle->vf_vlan.created)
                        mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);
@@ -1966,14 +1960,8 @@ flow_verbs_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                dev_flow = &wks->flows[idx];
                handle = dev_flow->handle;
                if (handle->fate_action == MLX5_FLOW_FATE_DROP) {
-                       hrxq = mlx5_drop_action_create(dev);
-                       if (!hrxq) {
-                               rte_flow_error_set
-                                       (error, errno,
-                                        RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-                                        "cannot get drop hash queue");
-                               goto error;
-                       }
+                       MLX5_ASSERT(priv->drop_queue.hrxq);
+                       hrxq = priv->drop_queue.hrxq;
                } else {
                        uint32_t hrxq_idx;
                        struct mlx5_flow_rss_desc *rss_desc =
@@ -2033,15 +2021,10 @@ error:
        SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
                       dev_handles, handle, next) {
                /* hrxq is union, don't touch it only the flag is set. */
-               if (handle->rix_hrxq) {
-                       if (handle->fate_action == MLX5_FLOW_FATE_DROP) {
-                               mlx5_drop_action_destroy(dev);
-                               handle->rix_hrxq = 0;
-                       } else if (handle->fate_action ==
-                                  MLX5_FLOW_FATE_QUEUE) {
-                               mlx5_hrxq_release(dev, handle->rix_hrxq);
-                               handle->rix_hrxq = 0;
-                       }
+               if (handle->rix_hrxq &&
+                   handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
+                       mlx5_hrxq_release(dev, handle->rix_hrxq);
+                       handle->rix_hrxq = 0;
                }
                if (handle->vf_vlan.tag && handle->vf_vlan.created)
                        mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);