2 * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #endif /* HAVE_CONFIG_H */
42 #include <infiniband/umad.h>
46 #define DEBUG if (ibdebug) IBWARN
49 ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, const void *srcport)
51 ib_portid_t self = {0};
55 memset(sm_id, 0, sizeof(*sm_id));
57 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO,
61 mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid);
63 return ib_portid_set(sm_id, lid, 0, 0);
67 ib_resolve_smlid(ib_portid_t *sm_id, int timeout)
69 return ib_resolve_smlid_via(sm_id, timeout, NULL);
73 ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout, const void *srcport)
75 ib_portid_t sm_portid;
76 char buf[IB_SA_DATA_SIZE] = {0};
80 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0)
83 if (*(uint64_t*)&portid->gid == 0)
84 mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX);
86 mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid);
88 if ((portid->lid = ib_path_query_via(srcport, portid->gid, portid->gid, sm_id, buf)) < 0)
95 ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport)
100 ib_portid_t selfportid = {0};
105 lid = strtol(addr_str, 0, 0);
106 if (!IB_LID_VALID(lid))
108 return ib_portid_set(portid, lid, 0, 0);
111 if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0)
116 if (!(guid = strtoull(addr_str, 0, 0)))
119 /* keep guid in portid? */
120 return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport);
123 lid = strtol(addr_str, &routepath, 0);
125 if (!IB_LID_VALID(lid))
127 ib_portid_set(portid, lid, 0, 0);
129 /* handle DR parsing and set DrSLID to local lid */
130 if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0)
132 if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < 0)
137 IBWARN("bad dest_type %d", dest_type);
144 ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id)
146 return ib_resolve_portid_str_via(portid, addr_str, dest_type,
151 ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid,
154 ib_portid_t self = {0};
155 uint8_t portinfo[64];
156 uint8_t nodeinfo[64];
157 uint64_t guid, prefix;
159 if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport))
162 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport))
165 mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid);
166 mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix);
167 mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid);
170 mad_decode_field(nodeinfo, IB_NODE_LOCAL_PORT_F, portnum);
172 mad_encode_field(*gid, IB_GID_PREFIX_F, &prefix);
173 mad_encode_field(*gid, IB_GID_GUID_F, &guid);
179 ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid)
181 return ib_resolve_self_via (portid, portnum, gid, NULL);