net/mlx5: optimize critical section in device free
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index 6dd211e..81476e2 100644 (file)
 #include <sys/mman.h>
 #include <linux/rtnetlink.h>
 
-/* Verbs header. */
-/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
-#ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-Wpedantic"
-#endif
-#include <infiniband/verbs.h>
-#ifdef PEDANTIC
-#pragma GCC diagnostic error "-Wpedantic"
-#endif
-
 #include <rte_malloc.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
@@ -40,6 +30,7 @@
 #include <mlx5_common.h>
 #include <mlx5_common_os.h>
 #include <mlx5_common_mp.h>
+#include <mlx5_common_pci.h>
 #include <mlx5_malloc.h>
 
 #include "mlx5_defs.h"
@@ -823,6 +814,12 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
                        err = ENOMEM;
                        goto error;
                }
+               sh->devx_rx_uar = mlx5_glue->devx_alloc_uar(sh->ctx, 0);
+               if (!sh->devx_rx_uar) {
+                       DRV_LOG(ERR, "Failed to allocate Rx DevX UAR.");
+                       err = ENOMEM;
+                       goto error;
+               }
        }
        sh->flow_id_pool = mlx5_flow_id_pool_alloc
                                        ((1 << HAIRPIN_FLOW_ID_BITS) - 1);
@@ -890,6 +887,8 @@ error:
                claim_zero(mlx5_devx_cmd_destroy(sh->tis));
        if (sh->td)
                claim_zero(mlx5_devx_cmd_destroy(sh->td));
+       if (sh->devx_rx_uar)
+               mlx5_glue->devx_free_uar(sh->devx_rx_uar);
        if (sh->pd)
                claim_zero(mlx5_glue->dealloc_pd(sh->pd));
        if (sh->ctx)
@@ -940,6 +939,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
        mlx5_mr_release_cache(&sh->share_cache);
        /* Remove context from the global device list. */
        LIST_REMOVE(sh, next);
+       pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
        /*
         *  Ensure there is no async event handler installed.
         *  Only primary process handles async device events.
@@ -961,12 +961,15 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
                claim_zero(mlx5_devx_cmd_destroy(sh->tis));
        if (sh->td)
                claim_zero(mlx5_devx_cmd_destroy(sh->td));
+       if (sh->devx_rx_uar)
+               mlx5_glue->devx_free_uar(sh->devx_rx_uar);
        if (sh->ctx)
                claim_zero(mlx5_glue->close_device(sh->ctx));
        if (sh->flow_id_pool)
                mlx5_flow_id_pool_release(sh->flow_id_pool);
        pthread_mutex_destroy(&sh->txpp.mutex);
        mlx5_free(sh);
+       return;
 exit:
        pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
 }
@@ -1965,16 +1968,19 @@ static const struct rte_pci_id mlx5_pci_id_map[] = {
        }
 };
 
-struct rte_pci_driver mlx5_driver = {
-       .driver = {
-               .name = MLX5_DRIVER_NAME
+static struct mlx5_pci_driver mlx5_driver = {
+       .driver_class = MLX5_CLASS_NET,
+       .pci_driver = {
+               .driver = {
+                       .name = MLX5_DRIVER_NAME,
+               },
+               .id_table = mlx5_pci_id_map,
+               .probe = mlx5_os_pci_probe,
+               .remove = mlx5_pci_remove,
+               .dma_map = mlx5_dma_map,
+               .dma_unmap = mlx5_dma_unmap,
+               .drv_flags = PCI_DRV_FLAGS,
        },
-       .id_table = mlx5_pci_id_map,
-       .probe = mlx5_os_pci_probe,
-       .remove = mlx5_pci_remove,
-       .dma_map = mlx5_dma_map,
-       .dma_unmap = mlx5_dma_unmap,
-       .drv_flags = PCI_DRV_FLAGS,
 };
 
 /* Initialize driver log type. */
@@ -1985,12 +1991,13 @@ RTE_LOG_REGISTER(mlx5_logtype, pmd.net.mlx5, NOTICE)
  */
 RTE_INIT(rte_mlx5_pmd_init)
 {
+       mlx5_common_init();
        /* Build the static tables for Verbs conversion. */
        mlx5_set_ptype_table();
        mlx5_set_cksum_table();
        mlx5_set_swp_types_table();
        if (mlx5_glue)
-               rte_pci_register(&mlx5_driver);
+               mlx5_pci_driver_register(&mlx5_driver);
 }
 
 RTE_PMD_EXPORT_NAME(net_mlx5, __COUNTER__);