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 */
45 #include <infiniband/common.h>
46 #include <infiniband/umad.h>
50 #define DEBUG if (ibdebug) IBWARN
53 ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout, const void *srcport)
55 ib_portid_t self = {0};
59 memset(sm_id, 0, sizeof(*sm_id));
61 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO,
65 mad_decode_field(portinfo, IB_PORT_SMLID_F, &lid);
67 return ib_portid_set(sm_id, lid, 0, 0);
71 ib_resolve_smlid(ib_portid_t *sm_id, int timeout)
73 return ib_resolve_smlid_via(sm_id, timeout, NULL);
77 ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout, const void *srcport)
79 ib_portid_t sm_portid;
80 char buf[IB_SA_DATA_SIZE] = {0};
84 if (ib_resolve_smlid_via(sm_id, timeout, srcport) < 0)
87 if (*(uint64_t*)&portid->gid == 0)
88 mad_set_field64(portid->gid, 0, IB_GID_PREFIX_F, IB_DEFAULT_SUBN_PREFIX);
90 mad_set_field64(portid->gid, 0, IB_GID_GUID_F, *guid);
92 if ((portid->lid = ib_path_query_via(srcport, portid->gid, portid->gid, sm_id, buf)) < 0)
99 ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport)
104 ib_portid_t selfportid = {0};
109 lid = strtol(addr_str, 0, 0);
110 if (!IB_LID_VALID(lid))
112 return ib_portid_set(portid, lid, 0, 0);
115 if (str2drpath(&portid->drpath, addr_str, 0, 0) < 0)
120 if (!(guid = strtoull(addr_str, 0, 0)))
123 /* keep guid in portid? */
124 return ib_resolve_guid_via(portid, &guid, sm_id, 0, srcport);
127 lid = strtol(addr_str, &routepath, 0);
129 if (!IB_LID_VALID(lid))
131 ib_portid_set(portid, lid, 0, 0);
133 /* handle DR parsing and set DrSLID to local lid */
134 if (ib_resolve_self_via(&selfportid, &selfport, 0, srcport) < 0)
136 if (str2drpath(&portid->drpath, routepath, selfportid.lid, 0) < 0)
141 IBWARN("bad dest_type %d", dest_type);
148 ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id)
150 return ib_resolve_portid_str_via(portid, addr_str, dest_type,
155 ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid,
158 ib_portid_t self = {0};
159 uint8_t portinfo[64];
160 uint8_t nodeinfo[64];
161 uint64_t guid, prefix;
163 if (!smp_query_via(nodeinfo, &self, IB_ATTR_NODE_INFO, 0, 0, srcport))
166 if (!smp_query_via(portinfo, &self, IB_ATTR_PORT_INFO, 0, 0, srcport))
169 mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid);
170 mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix);
171 mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid);
174 mad_decode_field(nodeinfo, IB_NODE_LOCAL_PORT_F, portnum);
176 mad_encode_field(*gid, IB_GID_PREFIX_F, &prefix);
177 mad_encode_field(*gid, IB_GID_GUID_F, &guid);
183 ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid)
185 return ib_resolve_self_via (portid, portnum, gid, NULL);