2 * Copyright (c) 2004-2008 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 <arpa/inet.h>
48 #include <infiniband/common.h>
51 #define DEBUG if (ibdebug) IBWARN
54 portid2portnum(ib_portid_t *portid)
59 if (portid->drpath.cnt == 0)
62 return portid->drpath.p[(portid->drpath.cnt-1)];
66 portid2str(ib_portid_t *portid)
68 static char buf[1024] = "local";
71 if (portid->lid > 0) {
72 n += sprintf(buf + n, "Lid %d", portid->lid);
73 if (portid->grh_present) {
74 char gid[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
75 if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid)))
76 n += sprintf(buf + n, " Gid %s", gid);
78 if (portid->drpath.cnt)
79 n += sprintf(buf + n, " ");
83 n += sprintf(buf + n, "DR path ");
84 drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n);
90 str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid)
92 char *s, *str = routepath;
96 DEBUG("DR str: %s", routepath);
98 if ((s = strchr(str, ',')))
100 path->p[++path->cnt] = atoi(str);
106 path->drdlid = drdlid ? drdlid : 0xffff;
107 path->drslid = drslid ? drslid : 0xffff;
113 drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size)
116 int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d",
117 path->drslid, path->drdlid, path->p[0]);
120 for (i = 1; i <= path->cnt; i++) {
121 rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]);