[openib-general] [PATCH 2 of 2] libmthca: qp capability calculations

Michael S. Tsirkin mst at mellanox.co.il
Tue Nov 8 09:51:11 PST 2005


Move all qp capability calculations to kernel, where we can
compare the capabilities to hardware supported limits.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
Signed-off-by: Jack MorgensteinMichael <jackm at mellanox.co.il>

Index: userspace/libibverbs/include/infiniband/kern-abi.h
===================================================================
--- userspace.orig/libibverbs/include/infiniband/kern-abi.h	2005-11-02 15:30:06.000000000 +0200
+++ userspace/libibverbs/include/infiniband/kern-abi.h	2005-11-08 19:49:38.000000000 +0200
@@ -48,7 +48,7 @@
  * The minimum and maximum kernel ABI that we can handle.
  */
 #define IB_USER_VERBS_MIN_ABI_VERSION	1
-#define IB_USER_VERBS_MAX_ABI_VERSION	3
+#define IB_USER_VERBS_MAX_ABI_VERSION	4
 
 enum {
 	IB_USER_VERBS_CMD_GET_CONTEXT,
@@ -382,6 +382,11 @@ struct ibv_create_qp {
 struct ibv_create_qp_resp {
 	__u32 qp_handle;
 	__u32 qpn;
+	__u32 max_send_wr;
+	__u32 max_recv_wr;
+	__u32 max_send_sge;
+	__u32 max_recv_sge;
+	__u32 max_inline_data;
 };
 
 struct ibv_qp_dest {
Index: userspace/libibverbs/src/cmd.c
===================================================================
--- userspace.orig/libibverbs/src/cmd.c	2005-11-02 15:30:06.000000000 +0200
+++ userspace/libibverbs/src/cmd.c	2005-11-08 19:48:58.000000000 +0200
@@ -501,6 +501,13 @@ int ibv_cmd_create_qp(struct ibv_pd *pd,
 
 	qp->handle  = resp.qp_handle;
 	qp->qp_num  = resp.qpn;
+	if (abi_ver > 3) {
+		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;
+	}
 
 	return 0;
 }
Index: userspace/libmthca/src/qp.c
===================================================================
--- userspace.orig/libmthca/src/qp.c	2005-11-08 19:48:38.000000000 +0200
+++ userspace/libmthca/src/qp.c	2005-11-08 19:48:58.000000000 +0200
@@ -216,7 +216,7 @@ int mthca_tavor_post_send(struct ibv_qp 
 
 		if (wr->send_flags & IBV_SEND_INLINE) {
 			struct mthca_inline_seg *seg = wqe;
-			int max_size = (1 << qp->sq.wqe_shift) - sizeof *seg - size * 16;
+			int max_size = qp->max_inline_data;
 			int s = 0;
 
 			wqe += sizeof *seg;
@@ -515,7 +515,7 @@ int mthca_arbel_post_send(struct ibv_qp 
 
 		if (wr->send_flags & IBV_SEND_INLINE) {
 			struct mthca_inline_seg *seg = wqe;
-			int max_size = (1 << qp->sq.wqe_shift) - sizeof *seg - size * 16;
+			int max_size = qp->max_inline_data;
 			int s = 0;
 
 			wqe += sizeof *seg;
@@ -683,12 +683,14 @@ int mthca_alloc_qp_buf(struct ibv_pd *pd
 		       enum ibv_qp_type type, struct mthca_qp *qp)
 {
 	int size;
+	int max_sq_sge;
 
 	qp->rq.max_gs 	 = cap->max_recv_sge;
-	qp->sq.max_gs 	 = align(cap->max_inline_data + sizeof (struct mthca_inline_seg),
+	qp->sq.max_gs 	 = cap->max_send_sge;
+	max_sq_sge 	 = align(cap->max_inline_data + sizeof (struct mthca_inline_seg),
 				 sizeof (struct mthca_data_seg)) / sizeof (struct mthca_data_seg);
-	if (qp->sq.max_gs < cap->max_send_sge)
-		qp->sq.max_gs = cap->max_send_sge;
+	if (max_sq_sge < cap->max_send_sge)
+		max_sq_sge = cap->max_send_sge;
 
 	qp->wrid = malloc((qp->rq.max + qp->sq.max) * sizeof (uint64_t));
 	if (!qp->wrid)
@@ -702,7 +704,7 @@ int mthca_alloc_qp_buf(struct ibv_pd *pd
 		; /* nothing */
 
 	size = sizeof (struct mthca_next_seg) +
-		qp->sq.max_gs * sizeof (struct mthca_data_seg);
+		max_sq_sge * sizeof (struct mthca_data_seg);
 	switch (type) {
 	case IBV_QPT_UD:
 		if (mthca_is_memfree(pd->context))
@@ -767,36 +769,6 @@ int mthca_alloc_qp_buf(struct ibv_pd *pd
 	return 0;
 }
 
-void mthca_return_cap(struct ibv_pd *pd, struct mthca_qp *qp,
-		      enum ibv_qp_type type, struct ibv_qp_cap *cap)
-{
-	/*
-	 * Maximum inline data size is the full WQE size less the size
-	 * of the next segment, inline segment and other non-data segments.
-	 */
-	cap->max_inline_data = (1 << qp->sq.wqe_shift) -
-		sizeof (struct mthca_next_seg) -
-		sizeof (struct mthca_inline_seg);
-
-	switch (type) {
-	case IBV_QPT_UD:
-		if (mthca_is_memfree(pd->context))
-			cap->max_inline_data -= sizeof (struct mthca_arbel_ud_seg);
-		else
-			cap->max_inline_data -= sizeof (struct mthca_tavor_ud_seg);
-		break;
-
-	default:
-		cap->max_inline_data -= sizeof (struct mthca_raddr_seg);
-		break;
-	}
-
-	cap->max_send_wr     = qp->sq.max;
-	cap->max_recv_wr     = qp->rq.max;
-	cap->max_send_sge    = qp->sq.max_gs;
-	cap->max_recv_sge    = qp->rq.max_gs;
-}
-
 struct mthca_qp *mthca_find_qp(struct mthca_context *ctx, uint32_t qpn)
 {
 	int tind = (qpn & (ctx->num_qps - 1)) >> ctx->qp_table_shift;
Index: userspace/libmthca/src/verbs.c
===================================================================
--- userspace.orig/libmthca/src/verbs.c	2005-11-02 15:30:06.000000000 +0200
+++ userspace/libmthca/src/verbs.c	2005-11-08 19:50:23.000000000 +0200
@@ -471,8 +471,11 @@ struct ibv_qp *mthca_create_qp(struct ib
 	if (ret)
 		goto err_destroy;
 
-	mthca_return_cap(pd, qp, attr->qp_type, &attr->cap);
-
+	qp->sq.max = attr->cap.max_send_wr;
+	qp->rq.max = attr->cap.max_recv_wr;
+	qp->sq.max_gs = attr->cap.max_send_sge;
+	qp->rq.max_gs = attr->cap.max_recv_sge;
+	qp->max_inline_data = attr->cap.max_inline_data;
 	return &qp->ibv_qp;
 
 err_destroy:
Index: userspace/libmthca/src/mthca.h
===================================================================
--- userspace.orig/libmthca/src/mthca.h	2005-11-02 15:30:06.000000000 +0200
+++ userspace/libmthca/src/mthca.h	2005-11-08 19:48:58.000000000 +0200
@@ -177,6 +177,7 @@ struct mthca_qp {
 	void            *buf;
 	uint64_t        *wrid;
 	int              send_wqe_offset;
+	int              max_inline_data;
 	int              buf_size;
 	struct mthca_wq  sq;
 	struct mthca_wq  rq;
@@ -317,8 +318,6 @@ extern int mthca_arbel_post_recv(struct 
 				 struct ibv_recv_wr **bad_wr);
 extern int mthca_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap,
 			      enum ibv_qp_type type, struct mthca_qp *qp);
-extern void mthca_return_cap(struct ibv_pd *pd, struct mthca_qp *qp,
-			     enum ibv_qp_type type, struct ibv_qp_cap *cap);
 extern struct mthca_qp *mthca_find_qp(struct mthca_context *ctx, uint32_t qpn);
 extern int mthca_store_qp(struct mthca_context *ctx, uint32_t qpn, struct mthca_qp *qp);
 extern void mthca_clear_qp(struct mthca_context *ctx, uint32_t qpn);

-- 
MST



More information about the general mailing list