1219820Sjeff/*
2219820Sjeff * Copyright (c) 2008 Lawrence Livermore National Laboratory
3219820Sjeff *
4219820Sjeff * This software is available to you under a choice of one of two
5219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
6219820Sjeff * General Public License (GPL) Version 2, available from the file
7219820Sjeff * COPYING in the main directory of this source tree, or the
8219820Sjeff * OpenIB.org BSD license below:
9219820Sjeff *
10219820Sjeff *     Redistribution and use in source and binary forms, with or
11219820Sjeff *     without modification, are permitted provided that the following
12219820Sjeff *     conditions are met:
13219820Sjeff *
14219820Sjeff *      - Redistributions of source code must retain the above
15219820Sjeff *        copyright notice, this list of conditions and the following
16219820Sjeff *        disclaimer.
17219820Sjeff *
18219820Sjeff *      - Redistributions in binary form must reproduce the above
19219820Sjeff *        copyright notice, this list of conditions and the following
20219820Sjeff *        disclaimer in the documentation and/or other materials
21219820Sjeff *        provided with the distribution.
22219820Sjeff *
23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30219820Sjeff * SOFTWARE.
31219820Sjeff */
32219820Sjeff
33219820Sjeff#include <infiniband/verbs.h>
34219820Sjeff
35219820Sjeffconst char *ibv_node_type_str(enum ibv_node_type node_type)
36219820Sjeff{
37219820Sjeff	static const char *const node_type_str[] = {
38219820Sjeff		[IBV_NODE_CA]		= "InfiniBand channel adapter",
39219820Sjeff		[IBV_NODE_SWITCH]	= "InfiniBand switch",
40219820Sjeff		[IBV_NODE_ROUTER]	= "InfiniBand router",
41219820Sjeff		[IBV_NODE_RNIC]		= "iWARP NIC"
42219820Sjeff	};
43219820Sjeff
44219820Sjeff	if (node_type < IBV_NODE_CA || node_type > IBV_NODE_RNIC)
45219820Sjeff		return "unknown";
46219820Sjeff
47219820Sjeff	return node_type_str[node_type];
48219820Sjeff}
49219820Sjeff
50219820Sjeffconst char *ibv_port_state_str(enum ibv_port_state port_state)
51219820Sjeff{
52219820Sjeff	static const char *const port_state_str[] = {
53219820Sjeff		[IBV_PORT_NOP]		= "no state change (NOP)",
54219820Sjeff		[IBV_PORT_DOWN]		= "down",
55219820Sjeff		[IBV_PORT_INIT]		= "init",
56219820Sjeff		[IBV_PORT_ARMED]	= "armed",
57219820Sjeff		[IBV_PORT_ACTIVE]	= "active",
58219820Sjeff		[IBV_PORT_ACTIVE_DEFER]	= "active defer"
59219820Sjeff	};
60219820Sjeff
61219820Sjeff	if (port_state < IBV_PORT_NOP || port_state > IBV_PORT_ACTIVE_DEFER)
62219820Sjeff		return "unknown";
63219820Sjeff
64219820Sjeff	return port_state_str[port_state];
65219820Sjeff}
66219820Sjeff
67219820Sjeffconst char *ibv_event_type_str(enum ibv_event_type event)
68219820Sjeff{
69219820Sjeff	static const char *const event_type_str[] = {
70219820Sjeff		[IBV_EVENT_CQ_ERR]		= "CQ error",
71219820Sjeff		[IBV_EVENT_QP_FATAL]		= "local work queue catastrophic error",
72219820Sjeff		[IBV_EVENT_QP_REQ_ERR]		= "invalid request local work queue error",
73219820Sjeff		[IBV_EVENT_QP_ACCESS_ERR]	= "local access violation work queue error",
74219820Sjeff		[IBV_EVENT_COMM_EST]		= "communication established",
75219820Sjeff		[IBV_EVENT_SQ_DRAINED]		= "send queue drained",
76219820Sjeff		[IBV_EVENT_PATH_MIG]		= "path migrated",
77219820Sjeff		[IBV_EVENT_PATH_MIG_ERR]	= "path migration request error",
78219820Sjeff		[IBV_EVENT_DEVICE_FATAL]	= "local catastrophic error",
79219820Sjeff		[IBV_EVENT_PORT_ACTIVE]		= "port active",
80219820Sjeff		[IBV_EVENT_PORT_ERR]		= "port error",
81219820Sjeff		[IBV_EVENT_LID_CHANGE]		= "LID change",
82219820Sjeff		[IBV_EVENT_PKEY_CHANGE]		= "P_Key change",
83219820Sjeff		[IBV_EVENT_SM_CHANGE]		= "SM change",
84219820Sjeff		[IBV_EVENT_SRQ_ERR]		= "SRQ catastrophic error",
85219820Sjeff		[IBV_EVENT_SRQ_LIMIT_REACHED]	= "SRQ limit reached",
86219820Sjeff		[IBV_EVENT_QP_LAST_WQE_REACHED]	= "last WQE reached",
87219820Sjeff		[IBV_EVENT_CLIENT_REREGISTER]	= "client reregistration",
88219820Sjeff	};
89219820Sjeff
90219820Sjeff	if (event < IBV_EVENT_CQ_ERR || event > IBV_EVENT_CLIENT_REREGISTER)
91219820Sjeff		return "unknown";
92219820Sjeff
93219820Sjeff	return event_type_str[event];
94219820Sjeff}
95219820Sjeff
96219820Sjeffconst char *ibv_wc_status_str(enum ibv_wc_status status)
97219820Sjeff{
98219820Sjeff	static const char *const wc_status_str[] = {
99219820Sjeff		[IBV_WC_SUCCESS]		= "success",
100219820Sjeff		[IBV_WC_LOC_LEN_ERR]		= "local length error",
101219820Sjeff		[IBV_WC_LOC_QP_OP_ERR]		= "local QP operation error",
102219820Sjeff		[IBV_WC_LOC_EEC_OP_ERR]		= "local EE context operation error",
103219820Sjeff		[IBV_WC_LOC_PROT_ERR]		= "local protection error",
104219820Sjeff		[IBV_WC_WR_FLUSH_ERR]		= "Work Request Flushed Error",
105219820Sjeff		[IBV_WC_MW_BIND_ERR]		= "memory management operation error",
106219820Sjeff		[IBV_WC_BAD_RESP_ERR]		= "bad response error",
107219820Sjeff		[IBV_WC_LOC_ACCESS_ERR]		= "local access error",
108219820Sjeff		[IBV_WC_REM_INV_REQ_ERR]	= "remote invalid request error",
109219820Sjeff		[IBV_WC_REM_ACCESS_ERR]		= "remote access error",
110219820Sjeff		[IBV_WC_REM_OP_ERR]		= "remote operation error",
111219820Sjeff		[IBV_WC_RETRY_EXC_ERR]		= "transport retry counter exceeded",
112219820Sjeff		[IBV_WC_RNR_RETRY_EXC_ERR]	= "RNR retry counter exceeded",
113219820Sjeff		[IBV_WC_LOC_RDD_VIOL_ERR]	= "local RDD violation error",
114219820Sjeff		[IBV_WC_REM_INV_RD_REQ_ERR]	= "remote invalid RD request",
115219820Sjeff		[IBV_WC_REM_ABORT_ERR]		= "aborted error",
116219820Sjeff		[IBV_WC_INV_EECN_ERR]		= "invalid EE context number",
117219820Sjeff		[IBV_WC_INV_EEC_STATE_ERR]	= "invalid EE context state",
118219820Sjeff		[IBV_WC_FATAL_ERR]		= "fatal error",
119219820Sjeff		[IBV_WC_RESP_TIMEOUT_ERR]	= "response timeout error",
120219820Sjeff		[IBV_WC_GENERAL_ERR]		= "general error"
121219820Sjeff	};
122219820Sjeff
123219820Sjeff	if (status < IBV_WC_SUCCESS || status > IBV_WC_GENERAL_ERR)
124219820Sjeff		return "unknown";
125219820Sjeff
126219820Sjeff	return wc_status_str[status];
127219820Sjeff}
128