* Free shared IB device context. Decrement counter and if zero free * all allocated resources and close handles. * * @param[in] sh * Pointer to mlx5_dev_ctx_shared object to free */
| 1910 | * Pointer to mlx5_dev_ctx_shared object to free |
| 1911 | */ |
| 1912 | void |
| 1913 | mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) |
| 1914 | { |
| 1915 | int ret; |
| 1916 | int i = 0; |
| 1917 | |
| 1918 | pthread_mutex_lock(&mlx5_dev_ctx_list_mutex); |
| 1919 | #ifdef RTE_LIBRTE_MLX5_DEBUG |
| 1920 | /* Check the object presence in the list. */ |
| 1921 | struct mlx5_dev_ctx_shared *lctx; |
| 1922 | |
| 1923 | LIST_FOREACH(lctx, &mlx5_dev_ctx_list, next) |
| 1924 | if (lctx == sh) |
| 1925 | break; |
| 1926 | MLX5_ASSERT(lctx); |
| 1927 | if (lctx != sh) { |
| 1928 | DRV_LOG(ERR, "Freeing non-existing shared IB context"); |
| 1929 | goto exit; |
| 1930 | } |
| 1931 | #endif |
| 1932 | MLX5_ASSERT(sh); |
| 1933 | MLX5_ASSERT(sh->refcnt); |
| 1934 | /* Secondary process should not free the shared context. */ |
| 1935 | MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); |
| 1936 | if (--sh->refcnt) |
| 1937 | goto exit; |
| 1938 | /* Stop watching for mempool events and unregister all mempools. */ |
| 1939 | if (!sh->cdev->config.mr_mempool_reg_en) { |
| 1940 | ret = rte_mempool_event_callback_unregister |
| 1941 | (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh); |
| 1942 | if (ret == 0) |
| 1943 | rte_mempool_walk |
| 1944 | (mlx5_dev_ctx_shared_rx_mempool_unregister_cb, sh); |
| 1945 | } |
| 1946 | /* Remove context from the global device list. */ |
| 1947 | LIST_REMOVE(sh, next); |
| 1948 | /* Release resources on the last device removal. */ |
| 1949 | if (LIST_EMPTY(&mlx5_dev_ctx_list)) { |
| 1950 | mlx5_os_net_cleanup(); |
| 1951 | mlx5_flow_os_release_workspace(); |
| 1952 | } |
| 1953 | pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex); |
| 1954 | if (sh->flex_parsers_dv) { |
| 1955 | mlx5_list_destroy(sh->flex_parsers_dv); |
| 1956 | sh->flex_parsers_dv = NULL; |
| 1957 | } |
| 1958 | /* |
| 1959 | * Ensure there is no async event handler installed. |
| 1960 | * Only primary process handles async device events. |
| 1961 | **/ |
| 1962 | mlx5_flow_counters_mng_close(sh); |
| 1963 | if (sh->ct_mng) |
| 1964 | mlx5_flow_aso_ct_mng_close(sh); |
| 1965 | if (sh->aso_age_mng) { |
| 1966 | mlx5_flow_aso_age_mng_close(sh); |
| 1967 | sh->aso_age_mng = NULL; |
| 1968 | } |
| 1969 | if (sh->mtrmng) |
no test coverage detected