@@ -70,5 +70,7 @@ DECLARE_DRV_CMD(mlx4_query_device_ex, IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
empty, mlx4_uverbs_ex_query_device_resp);
DECLARE_DRV_CMD(mlx4_resize_cq, IB_USER_VERBS_CMD_RESIZE_CQ,
mlx4_ib_resize_cq, empty);
+DECLARE_DRV_CMD(mlx4_import_pd, IB_USER_VERBS_CMD_IMPORT_PD,
+ empty, mlx4_ib_alloc_pd_resp);
#endif /* MLX4_ABI_H */
@@ -86,6 +86,7 @@ static const struct verbs_context_ops mlx4_ctx_ops = {
.query_port = mlx4_query_port,
.alloc_pd = mlx4_alloc_pd,
.dealloc_pd = mlx4_free_pd,
+ .import_pd = mlx4_import_pd,
.reg_mr = mlx4_reg_mr,
.rereg_mr = mlx4_rereg_mr,
.dereg_mr = mlx4_dereg_mr,
@@ -316,6 +316,8 @@ int mlx4_query_rt_values(struct ibv_context *context,
struct ibv_values_ex *values);
struct ibv_pd *mlx4_alloc_pd(struct ibv_context *context);
int mlx4_free_pd(struct ibv_pd *pd);
+struct ibv_pd *mlx4_import_pd(struct ibv_context *context, uint32_t fd,
+ uint32_t handle);
struct ibv_xrcd *mlx4_open_xrcd(struct ibv_context *context,
struct ibv_xrcd_init_attr *attr);
int mlx4_close_xrcd(struct ibv_xrcd *xrcd);
@@ -41,6 +41,8 @@
#include <util/mmio.h>
+#include <rdma/ib_user_ioctl_cmds.h>
+
#include "mlx4.h"
#include "mlx4-abi.h"
@@ -237,6 +239,34 @@ int mlx4_free_pd(struct ibv_pd *pd)
return 0;
}
+struct ibv_pd *mlx4_import_pd(struct ibv_context *context, uint32_t fd,
+ uint32_t handle)
+{
+ struct ibv_import_pd cmd = {
+ .handle = handle,
+ .type = UVERBS_OBJECT_PD,
+ .fd = fd,
+ };
+ struct mlx4_import_pd_resp resp;
+ struct mlx4_pd *pd;
+ int ret;
+
+ pd = malloc(sizeof(*pd));
+ if (!pd)
+ return NULL;
+
+ ret = ibv_cmd_import_pd(context, &pd->ibv_pd, &cmd, sizeof(cmd),
+ &resp.ibv_resp, sizeof(resp));
+ if (ret) {
+ free(pd);
+ return NULL;
+ }
+
+ pd->pdn = resp.pdn;
+
+ return &pd->ibv_pd;
+}
+
struct ibv_xrcd *mlx4_open_xrcd(struct ibv_context *context,
struct ibv_xrcd_init_attr *attr)
{