]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Add some helper functions to simplify using UD QPs
authorSean Hefty <sean.hefty@intel.com>
Fri, 16 Jun 2006 18:26:34 +0000 (18:26 +0000)
committerRoland Dreier <rolandd@cisco.com>
Thu, 9 Nov 2006 19:36:01 +0000 (11:36 -0800)
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@intel.com>
ChangeLog
include/infiniband/marshall.h
include/infiniband/verbs.h
src/libibverbs.map
src/marshall.c
src/verbs.c

index d52532a2cc224e0e37f0819b70a40add6b5b5871..409c553a85cc301648c11a2c9fc57abc8d1cb53b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-06-07  Sean Hefty     <sean.hefty@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@cisco.com>
 
        * src/device.c (ibv_get_device_list): Actually return a
index 8b85736564d48393aa17920ac04c6f9fadc0eddd..8be76c5444d25b24fa0cfebd2295562ec1760a06 100644 (file)
@@ -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 9e640fd53143307e2c3dfb5d66cadc8b4bf52655..9898f84a8350394fa86bc3355ea82bcce1b56aad 100644 (file)
@@ -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,
@@ -951,6 +960,36 @@ static inline int ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
  */
 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.
  */
index 4d7154970b61bff68d3527655607baa56fa6c198..9c7e48b13db16911b0d6c8a9ed451ca38ff15ed1 100644 (file)
@@ -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 c23a92623559813c9eb4586aec2c5fe20f421eb1..577b4b1ec2f997374a7997224ccceacf699c76d0 100644 (file)
@@ -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 5aca9bc223669f243e174c76ea3fa40ebced9606..1ab5879fc35fbe8a145267a3cc3ece8713effbb9 100644 (file)
@@ -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_pd *pd, struct ibv_ah_attr *attr)
        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);