IB/sa: Add ib_init_ah_from_path()
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 call to initialize address handle attributes given a path record.
This is used by the CM, and would be useful for users of UD QPs.

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

index 501cc054cb3b150d8af4bd3c1c6d0196560ffb65..08d9dd5e0487dfcfc76c8074442a6a6e899fa296 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <rdma/ib_pack.h>
 #include <rdma/ib_sa.h>
+#include <rdma/ib_cache.h>
 
 MODULE_AUTHOR("Roland Dreier");
 MODULE_DESCRIPTION("InfiniBand subnet administration query support");
@@ -441,6 +442,36 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query)
 }
 EXPORT_SYMBOL(ib_sa_cancel_query);
 
+int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
+                        struct ib_sa_path_rec *rec, struct ib_ah_attr *ah_attr)
+{
+       int ret;
+       u16 gid_index;
+
+       memset(ah_attr, 0, sizeof *ah_attr);
+       ah_attr->dlid = be16_to_cpu(rec->dlid);
+       ah_attr->sl = rec->sl;
+       ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f;
+       ah_attr->port_num = port_num;
+
+       if (rec->hop_limit > 1) {
+               ah_attr->ah_flags = IB_AH_GRH;
+               ah_attr->grh.dgid = rec->dgid;
+
+               ret = ib_find_cached_gid(device, &rec->sgid, &port_num,
+                                        &gid_index);
+               if (ret)
+                       return ret;
+
+               ah_attr->grh.sgid_index = gid_index;
+               ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
+               ah_attr->grh.hop_limit = rec->hop_limit;
+               ah_attr->grh.traffic_class = rec->traffic_class;
+       }
+       return 0;
+}
+EXPORT_SYMBOL(ib_init_ah_from_path);
+
 static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
 {
        unsigned long flags;
index ad63c215efe5b68be3d555fccda212ff09a3358a..c99e4420fd7ec308d9d2826c0bdd0493312bc5dd 100644 (file)
@@ -370,5 +370,12 @@ ib_sa_mcmember_rec_delete(struct ib_device *device, u8 port_num,
                                        context, query);
 }
 
+/**
+ * ib_init_ah_from_path - Initialize address handle attributes based on an SA
+ *   path record.
+ */
+int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
+                        struct ib_sa_path_rec *rec,
+                        struct ib_ah_attr *ah_attr);
 
 #endif /* IB_SA_H */