2 * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved.
\r
4 * This software is available to you under the OpenFabrics.org BSD license
\r
7 * Redistribution and use in source and binary forms, with or
\r
8 * without modification, are permitted provided that the following
\r
9 * conditions are met:
\r
11 * - Redistributions of source code must retain the above
\r
12 * copyright notice, this list of conditions and the following
\r
15 * - Redistributions in binary form must reproduce the above
\r
16 * copyright notice, this list of conditions and the following
\r
17 * disclaimer in the documentation and/or other materials
\r
18 * provided with the distribution.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV
\r
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
31 # include <config.h>
\r
32 #endif /* HAVE_CONFIG_H */
\r
37 #if defined(_WIN32) || defined(_WIN64)
\r
38 #include <windows.h>
\r
39 #define strtoull _strtoui64
\r
42 #include <pthread.h>
\r
44 #include <sys/time.h>
\r
47 #include <infiniband/umad.h>
\r
51 #define DEBUG if (ibdebug) IBWARN
\r
54 ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, const void *srcport)
\r
56 ib_portid_t self = {0};
\r
57 uint8_t portinfo[64];
\r
60 memset(sm_id, 0, sizeof(*sm_id));
\r
62 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO,
\r
66 mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid);
\r
68 return ib_portid_set(sm_id, lid, 0, 0);
\r
72 ib_resolve_smlid(ib_portid_t *sm_id, int timeout)
\r
74 return ib_resolve_smlid_via(sm_id, timeout, NULL);
\r
78 ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout, const void *srcport)
\r
80 ib_portid_t sm_portid;
\r
81 char buf[IB_SA_DATA_SIZE] = {0};
\r
85 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0)
\r
88 if (*(uint64_t*)&portid->gid == 0)
\r
89 mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX);
\r
91 mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid);
\r
93 if ((portid->lid = ib_path_query_via(srcport, portid->gid, portid->gid, sm_id, buf)) < 0)
\r
100 ib_resolve_guid(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout)
\r
102 return ib_resolve_guid_via(portid, guid, sm_id, timeout, NULL);
\r
106 ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport)
\r
111 ib_portid_t selfportid = {0};
\r
114 switch (dest_type) {
\r
116 lid = strtol(addr_str, 0, 0);
\r
117 if (!IB_LID_VALID(lid))
\r
119 return ib_portid_set(portid, lid, 0, 0);
\r
121 case IB_DEST_DRPATH:
\r
122 if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0)
\r
127 if (!(guid = strtoull(addr_str, 0, 0)))
\r
130 /* keep guid in portid? */
\r
131 return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport);
\r
133 case IB_DEST_DRSLID:
\r
134 lid = strtol(addr_str, &routepath, 0);
\r
136 if (!IB_LID_VALID(lid))
\r
138 ib_portid_set(portid, lid, 0, 0);
\r
140 /* handle DR parsing and set DrSLID to local lid */
\r
141 if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0)
\r
143 if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < 0)
\r
148 IBWARN("bad dest_type %d", dest_type);
\r
155 ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id)
\r
157 return ib_resolve_portid_str_via(portid, addr_str, dest_type,
\r
162 ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid,
\r
163 const void *srcport)
\r
165 ib_portid_t self = {0};
\r
166 uint8_t portinfo[64];
\r
167 uint8_t nodeinfo[64];
\r
168 uint64_t guid, prefix;
\r
170 if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport))
\r
173 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport))
\r
176 mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid);
\r
177 mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix);
\r
178 mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid);
\r
181 mad_decode_field(nodeinfo, IB_NODE_LOCAL_PORT_F, portnum);
\r
183 mad_encode_field(*gid, IB_GID_PREFIX_F, &prefix);
\r
184 mad_encode_field(*gid, IB_GID_GUID_F, &guid);
\r
190 ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid)
\r
192 return ib_resolve_self_via (portid, portnum, gid, NULL);
\r