1321936Shselasky/*
2321936Shselasky * Copyright (c) 2008 Lawrence Livermore National Laboratory
3321936Shselasky *
4321936Shselasky * This software is available to you under a choice of one of two
5321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
6321936Shselasky * General Public License (GPL) Version 2, available from the file
7321936Shselasky * COPYING in the main directory of this source tree, or the
8321936Shselasky * OpenIB.org BSD license below:
9321936Shselasky *
10321936Shselasky *     Redistribution and use in source and binary forms, with or
11321936Shselasky *     without modification, are permitted provided that the following
12321936Shselasky *     conditions are met:
13321936Shselasky *
14321936Shselasky *      - Redistributions of source code must retain the above
15321936Shselasky *        copyright notice, this list of conditions and the following
16321936Shselasky *        disclaimer.
17321936Shselasky *
18321936Shselasky *      - Redistributions in binary form must reproduce the above
19321936Shselasky *        copyright notice, this list of conditions and the following
20321936Shselasky *        disclaimer in the documentation and/or other materials
21321936Shselasky *        provided with the distribution.
22321936Shselasky *
23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30321936Shselasky * SOFTWARE.
31321936Shselasky */
32321936Shselasky
33321936Shselasky#include <infiniband/verbs.h>
34321936Shselasky
35321936Shselaskyconst char *ibv_node_type_str(enum ibv_node_type node_type)
36321936Shselasky{
37321936Shselasky	static const char *const node_type_str[] = {
38321936Shselasky		[IBV_NODE_CA]		= "InfiniBand channel adapter",
39321936Shselasky		[IBV_NODE_SWITCH]	= "InfiniBand switch",
40321936Shselasky		[IBV_NODE_ROUTER]	= "InfiniBand router",
41321936Shselasky		[IBV_NODE_RNIC]		= "iWARP NIC",
42321936Shselasky		[IBV_NODE_USNIC]	= "usNIC",
43321936Shselasky		[IBV_NODE_USNIC_UDP]	= "usNIC UDP",
44321936Shselasky	};
45321936Shselasky
46321936Shselasky	if (node_type < IBV_NODE_CA || node_type > IBV_NODE_USNIC_UDP)
47321936Shselasky		return "unknown";
48321936Shselasky
49321936Shselasky	return node_type_str[node_type];
50321936Shselasky}
51321936Shselasky
52321936Shselaskyconst char *ibv_port_state_str(enum ibv_port_state port_state)
53321936Shselasky{
54321936Shselasky	static const char *const port_state_str[] = {
55321936Shselasky		[IBV_PORT_NOP]		= "no state change (NOP)",
56321936Shselasky		[IBV_PORT_DOWN]		= "down",
57321936Shselasky		[IBV_PORT_INIT]		= "init",
58321936Shselasky		[IBV_PORT_ARMED]	= "armed",
59321936Shselasky		[IBV_PORT_ACTIVE]	= "active",
60321936Shselasky		[IBV_PORT_ACTIVE_DEFER]	= "active defer"
61321936Shselasky	};
62321936Shselasky
63321936Shselasky	if (port_state < IBV_PORT_NOP || port_state > IBV_PORT_ACTIVE_DEFER)
64321936Shselasky		return "unknown";
65321936Shselasky
66321936Shselasky	return port_state_str[port_state];
67321936Shselasky}
68321936Shselasky
69321936Shselaskyconst char *ibv_event_type_str(enum ibv_event_type event)
70321936Shselasky{
71321936Shselasky	static const char *const event_type_str[] = {
72321936Shselasky		[IBV_EVENT_CQ_ERR]		= "CQ error",
73321936Shselasky		[IBV_EVENT_QP_FATAL]		= "local work queue catastrophic error",
74321936Shselasky		[IBV_EVENT_QP_REQ_ERR]		= "invalid request local work queue error",
75321936Shselasky		[IBV_EVENT_QP_ACCESS_ERR]	= "local access violation work queue error",
76321936Shselasky		[IBV_EVENT_COMM_EST]		= "communication established",
77321936Shselasky		[IBV_EVENT_SQ_DRAINED]		= "send queue drained",
78321936Shselasky		[IBV_EVENT_PATH_MIG]		= "path migrated",
79321936Shselasky		[IBV_EVENT_PATH_MIG_ERR]	= "path migration request error",
80321936Shselasky		[IBV_EVENT_DEVICE_FATAL]	= "local catastrophic error",
81321936Shselasky		[IBV_EVENT_PORT_ACTIVE]		= "port active",
82321936Shselasky		[IBV_EVENT_PORT_ERR]		= "port error",
83321936Shselasky		[IBV_EVENT_LID_CHANGE]		= "LID change",
84321936Shselasky		[IBV_EVENT_PKEY_CHANGE]		= "P_Key change",
85321936Shselasky		[IBV_EVENT_SM_CHANGE]		= "SM change",
86321936Shselasky		[IBV_EVENT_SRQ_ERR]		= "SRQ catastrophic error",
87321936Shselasky		[IBV_EVENT_SRQ_LIMIT_REACHED]	= "SRQ limit reached",
88321936Shselasky		[IBV_EVENT_QP_LAST_WQE_REACHED]	= "last WQE reached",
89321936Shselasky		[IBV_EVENT_CLIENT_REREGISTER]	= "client reregistration",
90321936Shselasky		[IBV_EVENT_GID_CHANGE]		= "GID table change"
91321936Shselasky	};
92321936Shselasky
93321936Shselasky	if (event < IBV_EVENT_CQ_ERR || event > IBV_EVENT_GID_CHANGE)
94321936Shselasky		return "unknown";
95321936Shselasky
96321936Shselasky	return event_type_str[event];
97321936Shselasky}
98321936Shselasky
99321936Shselaskyconst char *ibv_wc_status_str(enum ibv_wc_status status)
100321936Shselasky{
101321936Shselasky	static const char *const wc_status_str[] = {
102321936Shselasky		[IBV_WC_SUCCESS]		= "success",
103321936Shselasky		[IBV_WC_LOC_LEN_ERR]		= "local length error",
104321936Shselasky		[IBV_WC_LOC_QP_OP_ERR]		= "local QP operation error",
105321936Shselasky		[IBV_WC_LOC_EEC_OP_ERR]		= "local EE context operation error",
106321936Shselasky		[IBV_WC_LOC_PROT_ERR]		= "local protection error",
107321936Shselasky		[IBV_WC_WR_FLUSH_ERR]		= "Work Request Flushed Error",
108321936Shselasky		[IBV_WC_MW_BIND_ERR]		= "memory management operation error",
109321936Shselasky		[IBV_WC_BAD_RESP_ERR]		= "bad response error",
110321936Shselasky		[IBV_WC_LOC_ACCESS_ERR]		= "local access error",
111321936Shselasky		[IBV_WC_REM_INV_REQ_ERR]	= "remote invalid request error",
112321936Shselasky		[IBV_WC_REM_ACCESS_ERR]		= "remote access error",
113321936Shselasky		[IBV_WC_REM_OP_ERR]		= "remote operation error",
114321936Shselasky		[IBV_WC_RETRY_EXC_ERR]		= "transport retry counter exceeded",
115321936Shselasky		[IBV_WC_RNR_RETRY_EXC_ERR]	= "RNR retry counter exceeded",
116321936Shselasky		[IBV_WC_LOC_RDD_VIOL_ERR]	= "local RDD violation error",
117321936Shselasky		[IBV_WC_REM_INV_RD_REQ_ERR]	= "remote invalid RD request",
118321936Shselasky		[IBV_WC_REM_ABORT_ERR]		= "aborted error",
119321936Shselasky		[IBV_WC_INV_EECN_ERR]		= "invalid EE context number",
120321936Shselasky		[IBV_WC_INV_EEC_STATE_ERR]	= "invalid EE context state",
121321936Shselasky		[IBV_WC_FATAL_ERR]		= "fatal error",
122321936Shselasky		[IBV_WC_RESP_TIMEOUT_ERR]	= "response timeout error",
123321936Shselasky		[IBV_WC_GENERAL_ERR]		= "general error"
124321936Shselasky	};
125321936Shselasky
126321936Shselasky	if (status < IBV_WC_SUCCESS || status > IBV_WC_GENERAL_ERR)
127321936Shselasky		return "unknown";
128321936Shselasky
129321936Shselasky	return wc_status_str[status];
130321936Shselasky}
131