[openib-general] [PATCH 1/2] libibverbs: add helper functions for UD QP support

Sean Hefty sean.hefty at intel.com
Tue Jun 6 20:08:57 PDT 2006


Adds some helper functions to simplify using UD QPs.

Add new routines: ibv_init_ah_from_wc() and ibv_create_ah_from_wc()
to simplify UD QP communication.

Expose ibv_copy_ah_attr_from_kern to retrieve ibv_ah_attr from kernel for
a UD QP.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: include/infiniband/verbs.h
===================================================================
--- include/infiniband/verbs.h	(revision 7636)
+++ include/infiniband/verbs.h	(working copy)
@@ -298,6 +298,15 @@ struct ibv_global_route {
 	uint8_t			traffic_class;
 };
 
+struct ibv_grh {
+	uint32_t		version_tclass_flow;
+	uint16_t		paylen;
+	uint8_t			next_hdr;
+	uint8_t			hop_limit;
+	union ibv_gid		sgid;
+	union ibv_gid		dgid;
+};
+
 enum ibv_rate {
 	IBV_RATE_MAX      = 0,
 	IBV_RATE_2_5_GBPS = 2,
@@ -952,6 +961,36 @@ static inline int ibv_post_recv(struct i
 struct ibv_ah *ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr);
 
 /**
+ * ibv_init_ah_from_wc - Initializes address handle attributes from a
+ *   work completion.
+ * @context: Device context on which the received message arrived.
+ * @port_num: Port on which the received message arrived.
+ * @wc: Work completion associated with the received message.
+ * @grh: References the received global route header.  This parameter is
+ *   ignored unless the work completion indicates that the GRH is valid.
+ * @ah_attr: Returned attributes that can be used when creating an address
+ *   handle for replying to the message.
+ */
+int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num,
+			struct ibv_wc *wc, struct ibv_grh *grh,
+			struct ibv_ah_attr *ah_attr);
+
+/**
+ * ibv_create_ah_from_wc - Creates an address handle associated with the
+ *   sender of the specified work completion.
+ * @pd: The protection domain associated with the address handle.
+ * @wc: Work completion information associated with a received message.
+ * @grh: References the received global route header.  This parameter is
+ *   ignored unless the work completion indicates that the GRH is valid.
+ * @port_num: The outbound port number to associate with the address.
+ *
+ * The address handle is used to reference a local or global destination
+ * in all UD QP post sends.
+ */
+struct ibv_ah *ibv_create_ah_from_wc(struct ibv_pd *pd, struct ibv_wc *wc,
+				     struct ibv_grh *grh, uint8_t port_num);
+
+/**
  * ibv_destroy_ah - Destroy an address handle.
  */
 int ibv_destroy_ah(struct ibv_ah *ah);
Index: include/infiniband/marshall.h
===================================================================
--- include/infiniband/marshall.h	(revision 7636)
+++ include/infiniband/marshall.h	(working copy)
@@ -51,6 +51,9 @@ BEGIN_C_DECLS
 void ibv_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
 				struct ibv_kern_qp_attr *src);
 
+void ibv_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
+				struct ibv_kern_ah_attr *src);
+
 void ibv_copy_path_rec_from_kern(struct ibv_sa_path_rec *dst,
 				 struct ibv_kern_path_rec *src);
 
Index: src/libibverbs.map
===================================================================
--- src/libibverbs.map	(revision 7636)
+++ src/libibverbs.map	(working copy)
@@ -32,6 +32,8 @@ IBVERBS_1.0 {
 		ibv_modify_qp;
 		ibv_destroy_qp;
 		ibv_create_ah;
+		ibv_init_ah_from_wc;
+		ibv_create_ah_from_wc;
 		ibv_destroy_ah;
 		ibv_attach_mcast;
 		ibv_detach_mcast;
@@ -65,6 +67,7 @@ IBVERBS_1.0 {
 		ibv_cmd_attach_mcast;
 		ibv_cmd_detach_mcast;
 		ibv_copy_qp_attr_from_kern;
+		ibv_copy_ah_attr_from_kern;
 		ibv_copy_path_rec_from_kern;
 		ibv_copy_path_rec_to_kern;
 		ibv_rate_to_mult;
Index: src/verbs.c
===================================================================
--- src/verbs.c	(revision 7636)
+++ src/verbs.c	(working copy)
@@ -42,6 +42,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
 
 #include "ibverbs.h"
 
@@ -392,6 +393,62 @@ struct ibv_ah *ibv_create_ah(struct ibv_
 	return ah;
 }
 
+static int ibv_find_gid_index(struct ibv_context *context, uint8_t port_num,
+			      union ibv_gid *gid)
+{
+	union ibv_gid sgid;
+	int i = 0, ret;
+
+	do {
+		ret = ibv_query_gid(context, port_num, i++, &sgid);
+	} while (!ret && memcmp(&sgid, gid, sizeof *gid));
+
+	return ret ? ret : i - 1;
+}
+
+int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num,
+			struct ibv_wc *wc, struct ibv_grh *grh,
+			struct ibv_ah_attr *ah_attr)
+{
+	uint32_t flow_class;
+	int ret;
+
+	memset(ah_attr, 0, sizeof *ah_attr);
+	ah_attr->dlid = wc->slid;
+	ah_attr->sl = wc->sl;
+	ah_attr->src_path_bits = wc->dlid_path_bits;
+	ah_attr->port_num = port_num;
+
+	if (wc->wc_flags & IBV_WC_GRH) {
+		ah_attr->is_global = 1;
+		ah_attr->grh.dgid = grh->sgid;
+
+		ret = ibv_find_gid_index(context, port_num, &grh->dgid);
+		if (ret < 0)
+			return ret;
+
+		ah_attr->grh.sgid_index = (uint8_t) ret;
+		flow_class = ntohl(grh->version_tclass_flow);
+		ah_attr->grh.flow_label = flow_class & 0xFFFFF;
+		ah_attr->grh.hop_limit = grh->hop_limit;
+		ah_attr->grh.traffic_class = (flow_class >> 20) & 0xFF;
+	}
+	return 0;
+}
+
+struct ibv_ah *ibv_create_ah_from_wc(struct ibv_pd *pd, struct ibv_wc *wc,
+				     struct ibv_grh *grh, uint8_t port_num)
+{
+	struct ibv_ah_attr ah_attr;
+	int ret;
+
+	ret = ibv_init_ah_from_wc(pd->context, port_num, wc, grh, &ah_attr);
+	if (ret)
+		return NULL;
+
+	return ibv_create_ah(pd, &ah_attr);
+}
+
 int ibv_destroy_ah(struct ibv_ah *ah)
 {
 	return ah->context->ops.destroy_ah(ah);
Index: src/marshall.c
===================================================================
--- src/marshall.c	(revision 7636)
+++ src/marshall.c	(working copy)
@@ -38,8 +38,8 @@
 
 #include <infiniband/marshall.h>
 
-static void ibv_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
-				       struct ibv_kern_ah_attr *src)
+void ibv_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
+				struct ibv_kern_ah_attr *src)
 {
 	memcpy(dst->grh.dgid.raw, src->grh.dgid, sizeof dst->grh.dgid);
 	dst->grh.flow_label = src->grh.flow_label;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 7636)
+++ ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2006-06-07  Sean Hefty     <sean.hefty at intel.com>
+
+	* src/verbs.c include/infiniband/verbs.h: Add new routines:
+	ibv_init_ah_from_wc() and ibv_create_ah_from_wc() to simplify UD QP
+	communication.
+
+	* src/marshall.c include/infiniband/marshall.h: Expose
+	ibv_copy_ah_attr_from_kern to retrieve ibv_ah_attr from kernel for
+	a UD QP.
+
 2006-06-01  Roland Dreier  <rdreier at cisco.com>
 
 	* src/device.c (ibv_get_device_list): Actually return a





More information about the general mailing list