IB: Add ib_init_ah_from_wc()
authorSean Hefty <sean.hefty@intel.com>
Sun, 18 Jun 2006 03:37:39 +0000 (20:37 -0700)
committerRoland Dreier <rolandd@cisco.com>
Sun, 18 Jun 2006 03:37:39 +0000 (20:37 -0700)
Add a function to initialize address handle attributes from a work
completion.  This functionality is duplicated by both verbs and the CM.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/core/verbs.c
include/rdma/ib_verbs.h

index b78e7dc6933072c21f4bd943960a9b79f6e3393f..468999c388033e83f4668f4f43e187f911f7a3ec 100644 (file)
@@ -125,35 +125,47 @@ struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
 }
 EXPORT_SYMBOL(ib_create_ah);
 
-struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
-                                  struct ib_grh *grh, u8 port_num)
+int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
+                      struct ib_grh *grh, struct ib_ah_attr *ah_attr)
 {
-       struct ib_ah_attr ah_attr;
        u32 flow_class;
        u16 gid_index;
        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;
+       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 & IB_WC_GRH) {
-               ah_attr.ah_flags = IB_AH_GRH;
-               ah_attr.grh.dgid = grh->sgid;
+               ah_attr->ah_flags = IB_AH_GRH;
+               ah_attr->grh.dgid = grh->sgid;
 
-               ret = ib_find_cached_gid(pd->device, &grh->dgid, &port_num,
+               ret = ib_find_cached_gid(device, &grh->dgid, &port_num,
                                         &gid_index);
                if (ret)
-                       return ERR_PTR(ret);
+                       return ret;
 
-               ah_attr.grh.sgid_index = (u8) gid_index;
+               ah_attr->grh.sgid_index = (u8) gid_index;
                flow_class = be32_to_cpu(grh->version_tclass_flow);
-               ah_attr.grh.flow_label = flow_class & 0xFFFFF;
-               ah_attr.grh.traffic_class = (flow_class >> 20) & 0xFF;
-               ah_attr.grh.hop_limit = grh->hop_limit;
+               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;
+}
+EXPORT_SYMBOL(ib_init_ah_from_wc);
+
+struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
+                                  struct ib_grh *grh, u8 port_num)
+{
+       struct ib_ah_attr ah_attr;
+       int ret;
+
+       ret = ib_init_ah_from_wc(pd->device, port_num, wc, grh, &ah_attr);
+       if (ret)
+               return ERR_PTR(ret);
 
        return ib_create_ah(pd, &ah_attr);
 }
index 10a6268c2cc2b3ffc434de95cbfa2aee5eea5c62..7ced208edacf81131aca4541c5419195e0320171 100644 (file)
@@ -1087,6 +1087,20 @@ int ib_dealloc_pd(struct ib_pd *pd);
  */
 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
 
+/**
+ * ib_init_ah_from_wc - Initializes address handle attributes from a
+ *   work completion.
+ * @device: Device 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 ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
+                      struct ib_grh *grh, struct ib_ah_attr *ah_attr);
+
 /**
  * ib_create_ah_from_wc - Creates an address handle associated with the
  *   sender of the specified work completion.