-#ifdef HAVE_IBV_FLOW_DV_SUPPORT
- struct mlx5dv_obj obj;
- struct mlx5dv_pd pd_info;
- int ret = 0;
-
- obj.pd.in = pd;
- obj.pd.out = &pd_info;
- ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD);
- if (ret) {
- DRV_LOG(DEBUG, "Fail to get PD object info");
- return ret;
- }
- *pdn = pd_info.pdn;
- return 0;
-#else
- (void)pd;
- (void)pdn;
- return -ENOTSUP;
-#endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-}
-
-/**
- * Function API to open IB device.
- *
- * This function calls the Linux glue APIs to open a device.
- *
- * @param[in] spawn
- * Pointer to the IB device attributes (name, port, etc).
- * @param[out] config
- * Pointer to device configuration structure.
- * @param[out] sh
- * Pointer to shared context structure.
- *
- * @return
- * 0 on success, a positive error value otherwise.
- */
-int
-mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,
- const struct mlx5_dev_config *config,
- struct mlx5_dev_ctx_shared *sh)
-{
- int dbmap_env;
- int err = 0;
-
- pthread_mutex_init(&sh->txpp.mutex, NULL);
- /*
- * Configure environment variable "MLX5_BF_SHUT_UP"
- * before the device creation. The rdma_core library
- * checks the variable at device creation and
- * stores the result internally.
- */
- dbmap_env = mlx5_config_doorbell_mapping_env(config);
- /* Try to open IB device with DV first, then usual Verbs. */
- errno = 0;
- sh->ctx = mlx5_glue->dv_open_device(spawn->phys_dev);
- if (sh->ctx) {
- sh->devx = 1;
- DRV_LOG(DEBUG, "DevX is supported");
- /* The device is created, no need for environment. */
- mlx5_restore_doorbell_mapping_env(dbmap_env);
- } else {
- /* The environment variable is still configured. */
- sh->ctx = mlx5_glue->open_device(spawn->phys_dev);
- err = errno ? errno : ENODEV;
- /*
- * The environment variable is not needed anymore,
- * all device creation attempts are completed.
- */
- mlx5_restore_doorbell_mapping_env(dbmap_env);
- if (!sh->ctx)
- return err;
- DRV_LOG(DEBUG, "DevX is NOT supported");
- err = 0;
- }
- if (!err && sh->ctx) {
- /* Hint libmlx5 to use PMD allocator for data plane resources */
- mlx5_glue->dv_set_context_attr(sh->ctx,
- MLX5DV_CTX_ATTR_BUF_ALLOCATORS,
- (void *)((uintptr_t)&(struct mlx5dv_ctx_allocators){
- .alloc = &mlx5_alloc_verbs_buf,
- .free = &mlx5_free_verbs_buf,
- .data = sh,
- }));
- }
- return err;