[openib-general] ibv_cmd_create_qp() question

Roland Dreier rdreier at cisco.com
Wed Feb 15 14:43:04 PST 2006


OK, I just committed the following patch, which adds the
resp/resp_size paramters to ibv_cmd_create_qp().

I will follow up with a patch to ehca to change the kernel/userspace
create QP interface to use ib_copy_to_udata() instead of the
device-specific respbuf hack that you have now.

 - R.

Index: libibverbs/include/infiniband/driver.h
===================================================================
--- libibverbs/include/infiniband/driver.h	(revision 5421)
+++ libibverbs/include/infiniband/driver.h	(working copy)
@@ -114,7 +114,8 @@ int ibv_cmd_destroy_srq(struct ibv_srq *
 
 int ibv_cmd_create_qp(struct ibv_pd *pd,
 		      struct ibv_qp *qp, struct ibv_qp_init_attr *attr,
-		      struct ibv_create_qp *cmd, size_t cmd_size);
+		      struct ibv_create_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,
 		     enum ibv_qp_attr_mask attr_mask,
 		     struct ibv_qp_init_attr *qp_init_attr,
Index: libibverbs/ChangeLog
===================================================================
--- libibverbs/ChangeLog	(revision 5421)
+++ libibverbs/ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2006-02-15  Roland Dreier  <rdreier at cisco.com>
+
+	* src/cmd.c (ibv_cmd_create_qp): Allow userspace device-specific
+	driver to pass in a response buffer, so that the low-level driver
+	in the kernel can pass back device-specific information.  This
+	changes the userspace driver API, since the signature of
+	ibv_cmd_create_qp() is changed.
+
 2006-02-14  Roland Dreier  <rdreier at cisco.com>
 
 	* Release version 1.0-rc6.
Index: libibverbs/src/cmd.c
===================================================================
--- libibverbs/src/cmd.c	(revision 5421)
+++ libibverbs/src/cmd.c	(working copy)
@@ -543,17 +543,11 @@ int ibv_cmd_destroy_srq(struct ibv_srq *
 
 int ibv_cmd_create_qp(struct ibv_pd *pd,
 		      struct ibv_qp *qp, struct ibv_qp_init_attr *attr,
-		      struct ibv_create_qp *cmd, size_t cmd_size)
+		      struct ibv_create_qp *cmd, size_t cmd_size,
+		      struct ibv_create_qp_resp *resp, size_t resp_size)
 {
-	union {
-		struct ibv_create_qp_resp    resp;
-		struct ibv_create_qp_resp_v3 resp_v3;
-	} r;
-
-	if (abi_ver > 3)
-		IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_QP, &r.resp, sizeof r.resp);
-	else
-		IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_QP, &r.resp_v3, sizeof r.resp_v3);
+	IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_QP, resp, resp_size);
+
 	cmd->user_handle     = (uintptr_t) qp;
 	cmd->pd_handle 	     = pd->handle;
 	cmd->send_cq_handle  = attr->send_cq->handle;
@@ -572,16 +566,22 @@ int ibv_cmd_create_qp(struct ibv_pd *pd,
 		return errno;
 
 	if (abi_ver > 3) {
-		qp->handle 		  = r.resp.qp_handle;
-		qp->qp_num 		  = r.resp.qpn;
-		attr->cap.max_recv_sge    = r.resp.max_recv_sge;
-		attr->cap.max_send_sge    = r.resp.max_send_sge;
-		attr->cap.max_recv_wr     = r.resp.max_recv_wr;
-		attr->cap.max_send_wr     = r.resp.max_send_wr;
-		attr->cap.max_inline_data = r.resp.max_inline_data;
+		qp->handle 		  = resp->qp_handle;
+		qp->qp_num 		  = resp->qpn;
+		attr->cap.max_recv_sge    = resp->max_recv_sge;
+		attr->cap.max_send_sge    = resp->max_send_sge;
+		attr->cap.max_recv_wr     = resp->max_recv_wr;
+		attr->cap.max_send_wr     = resp->max_send_wr;
+		attr->cap.max_inline_data = resp->max_inline_data;
 	} else {
-		qp->handle  = r.resp_v3.qp_handle;
-		qp->qp_num  = r.resp_v3.qpn;
+		struct ibv_create_qp_resp_v3 *resp_v3 =
+			(struct ibv_create_qp_resp_v3 *) resp;
+
+		qp->handle = resp_v3->qp_handle;
+		qp->qp_num = resp_v3->qpn;
+		memmove((void *) resp + sizeof *resp,
+			(void *) resp_v3 + sizeof *resp_v3,
+			resp_size - sizeof *resp);
 	}
 
 	return 0;
Index: libmthca/src/verbs.c
===================================================================
--- libmthca/src/verbs.c	(revision 5421)
+++ libmthca/src/verbs.c	(working copy)
@@ -470,9 +470,10 @@ int mthca_destroy_srq(struct ibv_srq *sr
 
 struct ibv_qp *mthca_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr)
 {
-	struct mthca_create_qp cmd;
-	struct mthca_qp       *qp;
-	int                    ret;
+	struct mthca_create_qp    cmd;
+	struct ibv_create_qp_resp resp;
+	struct mthca_qp          *qp;
+	int                       ret;
 
 	/* Sanity check QP size before proceeding */
 	if (attr->cap.max_send_wr     > 65536 ||
@@ -525,7 +526,8 @@ struct ibv_qp *mthca_create_qp(struct ib
 
 	cmd.lkey = qp->mr->lkey;
 
-	ret = ibv_cmd_create_qp(pd, &qp->ibv_qp, attr, &cmd.ibv_cmd, sizeof cmd);
+	ret = ibv_cmd_create_qp(pd, &qp->ibv_qp, attr, &cmd.ibv_cmd, sizeof cmd,
+				&resp, sizeof resp);
 	if (ret)
 		goto err_rq_db;
 
Index: libmthca/ChangeLog
===================================================================
--- libmthca/ChangeLog	(revision 5421)
+++ libmthca/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2006-02-15  Roland Dreier  <rdreier at cisco.com>
+
+	* src/verbs.c (mthca_create_qp): Update to add new response and
+	response size parameters for libibverbs ibv_cmd_create_qp().
+
 2006-02-14  Roland Dreier  <rdreier at cisco.com>
 
 	* Release version 1.0-rc6.
Index: libipathverbs/src/verbs.c
===================================================================
--- libipathverbs/src/verbs.c	(revision 5421)
+++ libipathverbs/src/verbs.c	(working copy)
@@ -175,15 +175,16 @@ int ipath_destroy_cq(struct ibv_cq *cq)
 
 struct ibv_qp *ipath_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr)
 {
-	struct ibv_create_qp	 cmd;
-	struct ibv_qp		*qp;
-	int			 ret;
+	struct ibv_create_qp	  cmd;
+	struct ibv_create_qp_resp resp;
+	struct ibv_qp		 *qp;
+	int			  ret;
 
 	qp = malloc(sizeof *qp);
 	if (!qp)
 		return NULL;
 
-	ret = ibv_cmd_create_qp(pd, qp, attr, &cmd, sizeof cmd);
+	ret = ibv_cmd_create_qp(pd, qp, attr, &cmd, sizeof cmd, &resp, sizeof resp);
 	if (ret) {
 		free(qp);
 		return NULL;
Index: libehca/src/ehca_umain.c
===================================================================
--- libehca/src/ehca_umain.c	(revision 5421)
+++ libehca/src/ehca_umain.c	(working copy)
@@ -283,7 +283,8 @@ struct ibv_qp *ehcau_create_qp(struct ib
 	int ret = 0;
 	struct ehcau_qp *my_qp = NULL;
 	struct ehcau_create_qp cmd;
-	struct ehcau_create_qp_resp resp;
+	struct ehcau_create_qp_resp ehca_resp;
+	struct ibv_create_qp_resp resp;
 	struct ibv_context *context = NULL;
 	int ret2 = 0;
 
@@ -300,8 +301,8 @@ struct ibv_qp *ehcau_create_qp(struct ib
 
 	memset(my_qp, 0, sizeof(*my_qp));
 	memset(&cmd, 0, sizeof(cmd));
-	memset(&resp, 0, sizeof(resp));
-	cmd.respbuf = (uintptr_t) & resp;	/* TODO: better include resp in ibv_cmd_create_qp call */
+	memset(&ehca_resp, 0, sizeof(ehca_resp));
+	cmd.respbuf = (uintptr_t) &ehca_resp;	/* TODO: better include resp in ibv_cmd_create_qp call */
 
 	if (pthread_spin_init(&my_qp->spinlock_s, PTHREAD_PROCESS_PRIVATE) ||
 	    pthread_spin_init(&my_qp->spinlock_r, PTHREAD_PROCESS_PRIVATE)) {
@@ -309,7 +310,8 @@ struct ibv_qp *ehcau_create_qp(struct ib
 	}
 
 	ret = ibv_cmd_create_qp(pd, &my_qp->ib_qp, attr,
-				&cmd.ibv_cmd, sizeof(cmd));
+				&cmd.ibv_cmd, sizeof(cmd),
+				&resp, sizeof resp);
 
 	if (ret != 0) {
 		EDEB_ERR(4, "ibv_cmd_create_qp() failed ret=%x pd=%p", 
@@ -317,9 +319,9 @@ struct ibv_qp *ehcau_create_qp(struct ib
 		goto create_qp_exit0;
 	}
 	/* copy data returned from kernel */
-	my_qp->qp_num = resp.qp_num;
-	my_qp->token = resp.token;
-	my_qp->ehca_qp_core = resp.ehca_qp_core;
+	my_qp->qp_num = ehca_resp.qp_num;
+	my_qp->token = ehca_resp.token;
+	my_qp->ehca_qp_core = ehca_resp.ehca_qp_core;
 	my_qp->ehca_qp_core.ipz_rqueue.current_q_addr =
 	    my_qp->ehca_qp_core.ipz_rqueue.queue;
 	my_qp->ehca_qp_core.ipz_squeue.current_q_addr =



More information about the general mailing list