freebsd-nq/contrib/ofed/libibmad/portid.c
Hans Petter Selasky d6b92ffa99 OFED user-space import and update for use with Linux-4.9 compatible RDMA
kernel APIs.

List of sources used:

1) rdma-core was cloned from "https://github.com/linux-rdma/rdma-core.git"
Top commit d65138ef93af30b3ea249f3a84aa6a24ba7f8a75

2) OpenSM was cloned from git://git.openfabrics.org/~halr/opensm.git
Top commit 85f841cf209f791c89a075048a907020e924528d

3) libibmad was cloned from "git://git.openfabrics.org/~iraweiny/libibmad.git"
Tag 1.3.13 with some additional patches from Mellanox.

4) infiniband-diags was cloned from "git://git.openfabrics.org/~iraweiny/infiniband-diags.git"
Tag 1.6.7 with some additional patches from Mellanox.

Added the required Makefiles for building and installing.

Sponsored by:	Mellanox Technologies
2017-08-02 16:00:30 +00:00

128 lines
3.2 KiB
C

/*
* Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <infiniband/mad.h>
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
int portid2portnum(ib_portid_t * portid)
{
if (portid->lid > 0)
return -1;
if (portid->drpath.cnt == 0)
return 0;
return portid->drpath.p[(portid->drpath.cnt - 1)];
}
char *portid2str(ib_portid_t * portid)
{
static char buf[1024] = "local";
int n = 0;
if (portid->lid > 0) {
n += sprintf(buf + n, "Lid %d", portid->lid);
if (portid->grh_present) {
char gid[sizeof
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid)))
n += sprintf(buf + n, " Gid %s", gid);
}
if (portid->drpath.cnt)
n += sprintf(buf + n, " ");
else
return buf;
}
n += sprintf(buf + n, "DR path ");
drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n);
return buf;
}
int str2drpath(ib_dr_path_t * path, char *routepath, int drslid, int drdlid)
{
char *s, *str;
char *tmp;
path->cnt = -1;
if (!routepath || !(tmp = strdup(routepath)))
goto Exit;
DEBUG("DR str: %s", routepath);
str = tmp;
while (str && *str) {
if ((s = strchr(str, ',')))
*s = 0;
path->p[++path->cnt] = (uint8_t) atoi(str);
if (!s)
break;
str = s + 1;
}
free(tmp);
Exit:
path->drdlid = drdlid ? drdlid : 0xffff;
path->drslid = drslid ? drslid : 0xffff;
return path->cnt;
}
char *drpath2str(ib_dr_path_t * path, char *dstr, size_t dstr_size)
{
int i = 0;
int rc = snprintf(dstr, dstr_size, "slid %u; dlid %u; %d",
path->drslid, path->drdlid, path->p[0]);
if (rc >= (int)dstr_size)
return dstr;
for (i = 1; i <= path->cnt; i++) {
rc += snprintf(dstr + rc, dstr_size - rc, ",%d", path->p[i]);
if (rc >= (int)dstr_size)
break;
}
return (dstr);
}