]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
libibverbs: Add ibv_open_qp
authorSean Hefty <sean.hefty@intel.com>
Wed, 19 Sep 2012 16:19:59 +0000 (09:19 -0700)
committerSean Hefty <sean.hefty@intel.com>
Thu, 27 Sep 2012 18:16:19 +0000 (11:16 -0700)
XRC receive QPs are shareable across multiple processes.  Allow
any process with access to the xrc domain to open an existing
QP.  After opening the QP, the process will receive events
related to the QP and be able to modify the QP.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
include/infiniband/driver.h
include/infiniband/kern-abi.h
include/infiniband/verbs.h
src/cmd.c
src/libibverbs.map

index 97557b5e6e95dbad3c5899838ead13b3bcd391cd..fe77ac4b94668e989762b7fe26f4e6d36ee8ba89 100644 (file)
@@ -164,6 +164,10 @@ int ibv_cmd_create_qp_ex(struct verbs_context *context,
                         struct verbs_qp *qp, struct ibv_qp_init_attr_ex *attr_ex,
                         struct ibv_create_qp *cmd, size_t cmd_size,
                         struct ibv_create_qp_resp *resp, size_t resp_size);
+int ibv_cmd_open_qp(struct verbs_context *context,
+                   struct verbs_qp *qp, struct ibv_qp_open_attr *attr,
+                   struct ibv_open_qp *cmd, size_t cmd_size,
+                   struct ibv_create_qp_resp *resp, size_t resp_size);
 int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *qp_attr,
                     int attr_mask,
                     struct ibv_qp_init_attr *qp_init_attr,
index b6d5ce9f776f3830c17a17c4bb05ef46636ca31d..e24fa4f912a8cad24df55104443eb745d550e919 100644 (file)
@@ -88,7 +88,8 @@ enum {
        IB_USER_VERBS_CMD_POST_SRQ_RECV,
        IB_USER_VERBS_CMD_OPEN_XRCD,
        IB_USER_VERBS_CMD_CLOSE_XRCD,
-       IB_USER_VERBS_CMD_CREATE_XSRQ
+       IB_USER_VERBS_CMD_CREATE_XSRQ,
+       IB_USER_VERBS_CMD_OPEN_QP
 };
 
 /*
@@ -476,6 +477,20 @@ struct ibv_create_qp {
        __u64 driver_data[0];
 };
 
+struct ibv_open_qp {
+       __u32 command;
+       __u16 in_words;
+       __u16 out_words;
+       __u64 response;
+       __u64 user_handle;
+       __u32 pd_handle;
+       __u32 qpn;
+       __u8  qp_type;
+       __u8  reserved[7];
+       __u64 driver_data[0];
+};
+
+/* also used for open response */
 struct ibv_create_qp_resp {
        __u32 qp_handle;
        __u32 qpn;
@@ -852,7 +867,8 @@ enum {
        IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL_V2 = -1,
        IB_USER_VERBS_CMD_OPEN_XRCD_V2 = -1,
        IB_USER_VERBS_CMD_CLOSE_XRCD_V2 = -1,
-       IB_USER_VERBS_CMD_CREATE_XSRQ_V2 = -1
+       IB_USER_VERBS_CMD_CREATE_XSRQ_V2 = -1,
+       IB_USER_VERBS_CMD_OPEN_QP_V2 = -1
 };
 
 struct ibv_destroy_cq_v1 {
index 56c5db0a814a6acd9a75d7232ab6065f0c466b6a..a91662c6f329345ff9a45ecea99aa8f0b4e01b64 100644 (file)
@@ -486,6 +486,22 @@ struct ibv_qp_init_attr_ex {
        struct ibv_xrcd        *xrcd;
 };
 
+enum ibv_qp_open_attr_mask {
+       IBV_QP_OPEN_ATTR_NUM            = 1 << 0,
+       IBV_QP_OPEN_ATTR_CONTEXT        = 1 << 1,
+       IBV_QP_OPEN_ATTR_XRCD           = 1 << 2,
+       IBV_QP_OPEN_ATTR_TYPE           = 1 << 3,
+       IBV_QP_OPEN_ATTR_RESERVED       = 1 << 4
+ };
+
+struct ibv_qp_open_attr {
+       uint32_t                comp_mask;
+       uint32_t                qp_num;
+       struct ibv_xrcd        *xrcd;
+       void                   *qp_context;
+       enum ibv_qp_type        qp_type;
+};
+
 enum ibv_qp_attr_mask {
        IBV_QP_STATE                    = 1 <<  0,
        IBV_QP_CUR_STATE                = 1 <<  1,
@@ -517,7 +533,8 @@ enum ibv_qp_state {
        IBV_QPS_RTS,
        IBV_QPS_SQD,
        IBV_QPS_SQE,
-       IBV_QPS_ERR
+       IBV_QPS_ERR,
+       IBV_QPS_UNKNOWN
 };
 
 enum ibv_mig_state {
@@ -789,6 +806,8 @@ struct verbs_context {
        int (*drv_new_func1) ();        new corresponding provider call of func1
        int (*lib_new_func1) ();        New library call func1
        */
+       struct ibv_qp *         (*open_qp)(struct ibv_context *context,
+                                          struct ibv_qp_open_attr *attr);
        struct ibv_qp *         (*create_qp_ex)(struct ibv_context *context,
                                                struct ibv_qp_init_attr_ex *qp_init_attr_ex);
        uint32_t                (*get_srq_num)(struct ibv_srq *srq);
@@ -1162,6 +1181,20 @@ ibv_create_qp_ex(struct ibv_context *context, struct ibv_qp_init_attr_ex *qp_ini
        return vctx->create_qp_ex(context, qp_init_attr_ex);
 }
 
+/**
+ * ibv_open_qp - Open a shareable queue pair.
+ */
+static inline struct ibv_qp *
+ibv_open_qp(struct ibv_xrcd *xrcd, struct ibv_qp_open_attr *qp_open_attr)
+{
+       struct verbs_context *vctx = verbs_get_ctx_op(xrcd->context, open_qp);
+       if (!vctx) {
+               errno = ENOSYS;
+               return NULL;
+       }
+       return vctx->open_qp(xrcd, qp_open_attr);
+}
+
 /**
  * ibv_modify_qp - Modify a queue pair.
  */
index 0b75df241ccde120d296313eef11b86a169ea057..7f655163bd33bee5c9eae16bd2009cc8fe67fc57 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -800,6 +800,49 @@ int ibv_cmd_create_qp(struct ibv_pd *pd,
        return 0;
 }
 
+int ibv_cmd_open_qp(struct verbs_context *context, struct verbs_qp *qp,
+                   struct ibv_qp_open_attr *attr,
+                   struct ibv_open_qp *cmd, size_t cmd_size,
+                   struct ibv_create_qp_resp *resp, size_t resp_size)
+{
+       IBV_INIT_CMD_RESP(cmd, cmd_size, OPEN_QP, resp, resp_size);
+
+       if (attr->comp_mask >= IBV_QP_OPEN_ATTR_RESERVED)
+               return ENOSYS;
+
+       if (!(attr->comp_mask & IBV_QP_OPEN_ATTR_XRCD) ||
+           !(attr->comp_mask & IBV_QP_OPEN_ATTR_NUM) ||
+           !(attr->comp_mask & IBV_QP_OPEN_ATTR_TYPE))
+               return EINAL;
+
+       cmd->user_handle = (uintptr_t) qp;
+       cmd->pd_handle   = attr->xrcd->handle;
+       cmd->qpn         = attr->qp_num;
+       cmd->qp_type     = attr->qp_type;
+
+       if (write(context->context.cmd_fd, cmd, cmd_size) != cmd_size)
+               return errno;
+
+       VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
+
+       qp->qp.handle     = resp->qp_handle;
+       qp->qp.context    = &context->context;
+       qp->qp.qp_context = attr->qp_context;
+       qp->qp.pd         = NULL;
+       qp->qp.send_cq    = qp->qp.recv_cq = NULL;
+       qp->qp.srq        = NULL;
+       qp->qp.qp_num     = attr->qp_num;
+       qp->qp.qp_type    = attr->qp_type;
+       qp->qp.state      = IBV_QPS_UNKNOWN;
+       qp->qp.events_completed = 0;
+       pthread_mutex_init(&qp->qp.mutex, NULL);
+       pthread_cond_init(&qp->qp.cond, NULL);
+       qp->comp_mask     = VERBS_QP_XRCD;
+       qp->xrcd          = attr->xrcd;
+
+       return 0;
+}
+
 int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
                     int attr_mask,
                     struct ibv_qp_init_attr *init_attr,
index 4249793a171798033b86b04bbe557acca04c5194..5ad8312d541625362a382a64bf9c3e7220094766 100644 (file)
@@ -102,5 +102,6 @@ IBVERBS_1.1 {
                ibv_cmd_close_xrcd;
                ibv_cmd_create_srq_ex;
                ibv_cmd_create_qp_ex;
+               ibv_cmd_open_qp;
                
 } IBVERBS_1.0;