[ofa-general] Re: [PATCH v2] Add enum strings and *_str functions for enums
Roland Dreier
rdreier at cisco.com
Fri Apr 18 14:54:59 PDT 2008
Thanks, I added a man page and changed things a little and committed the
following:
commit 1c0b7ac0a6bbbe4d246ef4cf50ae31bde4929ba3
Author: Ira Weiny <weiny2 at llnl.gov>
Date: Tue Apr 15 13:35:48 2008 -0700
Add functions to convert enum values to strings
Add ibv_xxx_str() functions to convert node type, port state, event
type and wc status enum values to strings.
Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
Signed-off-by: Roland Dreier <rolandd at cisco.com>
diff --git a/Makefile.am b/Makefile.am
index 705b184..9b05306 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,8 @@ src_libibverbs_la_CFLAGS = $(AM_CFLAGS) -DIBV_CONFIG_DIR=\"$(sysconfdir)/libibve
libibverbs_version_script = @LIBIBVERBS_VERSION_SCRIPT@
src_libibverbs_la_SOURCES = src/cmd.c src/compat-1_0.c src/device.c src/init.c \
- src/marshall.c src/memory.c src/sysfs.c src/verbs.c
+ src/marshall.c src/memory.c src/sysfs.c src/verbs.c \
+ src/enum_strs.c
src_libibverbs_la_LDFLAGS = -version-info 1 -export-dynamic \
$(libibverbs_version_script)
src_libibverbs_la_DEPENDENCIES = $(srcdir)/src/libibverbs.map
@@ -38,20 +39,20 @@ libibverbsinclude_HEADERS = include/infiniband/arch.h include/infiniband/driver.
include/infiniband/kern-abi.h include/infiniband/opcode.h include/infiniband/verbs.h \
include/infiniband/sa-kern-abi.h include/infiniband/sa.h include/infiniband/marshall.h
-man_MANS = man/ibv_asyncwatch.1 man/ibv_devices.1 man/ibv_devinfo.1 \
- man/ibv_rc_pingpong.1 man/ibv_uc_pingpong.1 man/ibv_ud_pingpong.1 \
- man/ibv_srq_pingpong.1 \
- man/ibv_alloc_pd.3 man/ibv_attach_mcast.3 man/ibv_create_ah.3 \
- man/ibv_create_ah_from_wc.3 man/ibv_create_comp_channel.3 \
- man/ibv_create_cq.3 man/ibv_create_qp.3 man/ibv_create_srq.3 \
- man/ibv_fork_init.3 man/ibv_get_async_event.3 \
- man/ibv_get_cq_event.3 man/ibv_get_device_guid.3 \
- man/ibv_get_device_list.3 man/ibv_get_device_name.3 \
- man/ibv_modify_qp.3 man/ibv_modify_srq.3 man/ibv_open_device.3 \
- man/ibv_poll_cq.3 man/ibv_post_recv.3 man/ibv_post_send.3 \
- man/ibv_post_srq_recv.3 man/ibv_query_device.3 man/ibv_query_gid.3 \
- man/ibv_query_pkey.3 man/ibv_query_port.3 man/ibv_query_qp.3 \
- man/ibv_query_srq.3 man/ibv_rate_to_mult.3 man/ibv_reg_mr.3 \
+man_MANS = man/ibv_asyncwatch.1 man/ibv_devices.1 man/ibv_devinfo.1 \
+ man/ibv_rc_pingpong.1 man/ibv_uc_pingpong.1 man/ibv_ud_pingpong.1 \
+ man/ibv_srq_pingpong.1 man/ibv_alloc_pd.3 man/ibv_attach_mcast.3 \
+ man/ibv_create_ah.3 man/ibv_create_ah_from_wc.3 \
+ man/ibv_create_comp_channel.3 man/ibv_create_cq.3 \
+ man/ibv_create_qp.3 man/ibv_create_srq.3 man/ibv_event_type_str.3 \
+ man/ibv_fork_init.3 man/ibv_get_async_event.3 \
+ man/ibv_get_cq_event.3 man/ibv_get_device_guid.3 \
+ man/ibv_get_device_list.3 man/ibv_get_device_name.3 \
+ man/ibv_modify_qp.3 man/ibv_modify_srq.3 man/ibv_open_device.3 \
+ man/ibv_poll_cq.3 man/ibv_post_recv.3 man/ibv_post_send.3 \
+ man/ibv_post_srq_recv.3 man/ibv_query_device.3 man/ibv_query_gid.3 \
+ man/ibv_query_pkey.3 man/ibv_query_port.3 man/ibv_query_qp.3 \
+ man/ibv_query_srq.3 man/ibv_rate_to_mult.3 man/ibv_reg_mr.3 \
man/ibv_req_notify_cq.3 man/ibv_resize_cq.3
DEBIAN = debian/changelog debian/compat debian/control debian/copyright \
@@ -84,6 +85,8 @@ install-data-hook:
$(RM) ibv_free_device_list.3 && \
$(RM) ibv_init_ah_from_wc.3 && \
$(RM) mult_to_ibv_rate.3 && \
+ $(RM) ibv_node_type_str.3 && \
+ $(RM) ibv_port_state_str.3 && \
$(LN_S) ibv_get_async_event.3 ibv_ack_async_event.3 && \
$(LN_S) ibv_get_cq_event.3 ibv_ack_cq_events.3 && \
$(LN_S) ibv_open_device.3 ibv_close_device.3 && \
@@ -97,5 +100,6 @@ install-data-hook:
$(LN_S) ibv_attach_mcast.3 ibv_detach_mcast.3 && \
$(LN_S) ibv_get_device_list.3 ibv_free_device_list.3 && \
$(LN_S) ibv_create_ah_from_wc.3 ibv_init_ah_from_wc.3 && \
- $(LN_S) ibv_rate_to_mult.3 mult_to_ibv_rate.3
-
+ $(LN_S) ibv_rate_to_mult.3 mult_to_ibv_rate.3 && \
+ $(LN_S) ibv_event_type_str.3 ibv_node_type_str.3 && \
+ $(LN_S) ibv_event_type_str.3 ibv_port_state_str.3
diff --git a/examples/devinfo.c b/examples/devinfo.c
index 4e4316a..1fadc80 100644
--- a/examples/devinfo.c
+++ b/examples/devinfo.c
@@ -67,17 +67,6 @@ static const char *guid_str(uint64_t node_guid, char *str)
return str;
}
-static const char *port_state_str(enum ibv_port_state pstate)
-{
- switch (pstate) {
- case IBV_PORT_DOWN: return "PORT_DOWN";
- case IBV_PORT_INIT: return "PORT_INIT";
- case IBV_PORT_ARMED: return "PORT_ARMED";
- case IBV_PORT_ACTIVE: return "PORT_ACTIVE";
- default: return "invalid state";
- }
-}
-
static const char *port_phy_state_str(uint8_t phys_state)
{
switch (phys_state) {
@@ -266,7 +255,7 @@ static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
}
printf("\t\tport:\t%d\n", port);
printf("\t\t\tstate:\t\t\t%s (%d)\n",
- port_state_str(port_attr.state), port_attr.state);
+ ibv_port_state_str(port_attr.state), port_attr.state);
printf("\t\t\tmax_mtu:\t\t%s (%d)\n",
mtu_str(port_attr.max_mtu), port_attr.max_mtu);
printf("\t\t\tactive_mtu:\t\t%s (%d)\n",
diff --git a/examples/rc_pingpong.c b/examples/rc_pingpong.c
index 7181914..26fa45c 100644
--- a/examples/rc_pingpong.c
+++ b/examples/rc_pingpong.c
@@ -709,7 +709,8 @@ int main(int argc, char *argv[])
for (i = 0; i < ne; ++i) {
if (wc[i].status != IBV_WC_SUCCESS) {
- fprintf(stderr, "Failed status %d for wr_id %d\n",
+ fprintf(stderr, "Failed status %s (%d) for wr_id %d\n",
+ ibv_wc_status_str(wc[i].status),
wc[i].status, (int) wc[i].wr_id);
return 1;
}
diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c
index bc869c9..95bebf4 100644
--- a/examples/srq_pingpong.c
+++ b/examples/srq_pingpong.c
@@ -805,7 +805,8 @@ int main(int argc, char *argv[])
for (i = 0; i < ne; ++i) {
if (wc[i].status != IBV_WC_SUCCESS) {
- fprintf(stderr, "Failed status %d for wr_id %d\n",
+ fprintf(stderr, "Failed status %s (%d) for wr_id %d\n",
+ ibv_wc_status_str(wc[i].status),
wc[i].status, (int) wc[i].wr_id);
return 1;
}
diff --git a/examples/uc_pingpong.c b/examples/uc_pingpong.c
index 6135030..c09c8c1 100644
--- a/examples/uc_pingpong.c
+++ b/examples/uc_pingpong.c
@@ -697,7 +697,8 @@ int main(int argc, char *argv[])
for (i = 0; i < ne; ++i) {
if (wc[i].status != IBV_WC_SUCCESS) {
- fprintf(stderr, "Failed status %d for wr_id %d\n",
+ fprintf(stderr, "Failed status %s (%d) for wr_id %d\n",
+ ibv_wc_status_str(wc[i].status),
wc[i].status, (int) wc[i].wr_id);
return 1;
}
diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index aaee26c..8f3d50b 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -697,7 +697,8 @@ int main(int argc, char *argv[])
for (i = 0; i < ne; ++i) {
if (wc[i].status != IBV_WC_SUCCESS) {
- fprintf(stderr, "Failed status %d for wr_id %d\n",
+ fprintf(stderr, "Failed status %s (%d) for wr_id %d\n",
+ ibv_wc_status_str(wc[i].status),
wc[i].status, (int) wc[i].wr_id);
return 1;
}
diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h
index a51bb9d..a04cc62 100644
--- a/include/infiniband/verbs.h
+++ b/include/infiniband/verbs.h
@@ -238,6 +238,7 @@ enum ibv_wc_status {
IBV_WC_RESP_TIMEOUT_ERR,
IBV_WC_GENERAL_ERR
};
+const char *ibv_wc_status_str(enum ibv_wc_status status);
enum ibv_wc_opcode {
IBV_WC_SEND,
@@ -1077,6 +1078,21 @@ int ibv_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
*/
int ibv_fork_init(void);
+/**
+ * ibv_node_type_str - Return string describing node_type enum value
+ */
+const char *ibv_node_type_str(enum ibv_node_type node_type);
+
+/**
+ * ibv_port_state_str - Return string describing port_state enum value
+ */
+const char *ibv_port_state_str(enum ibv_port_state port_state);
+
+/**
+ * ibv_event_type_str - Return string describing event_type enum value
+ */
+const char *ibv_event_type_str(enum ibv_event_type event);
+
END_C_DECLS
# undef __attribute_const
diff --git a/man/ibv_event_type_str.3 b/man/ibv_event_type_str.3
new file mode 100644
index 0000000..0df8fcd
--- /dev/null
+++ b/man/ibv_event_type_str.3
@@ -0,0 +1,40 @@
+.\" -*- nroff -*-
+.\"
+.TH IBV_EVENT_TYPE_STR 3 2006-10-31 libibverbs "Libibverbs Programmer's Manual"
+.SH "NAME"
+.nf
+ibv_event_type_str \- Return string describing event_type enum value
+.nl
+ibv_node_type_str \- Return string describing node_type enum value
+.nl
+ibv_port_state_str \- Return string describing port_state enum value
+.SH "SYNOPSIS"
+.nf
+.B #include <infiniband/verbs.h>
+.sp
+.BI "const char *ibv_event_type_str(enum ibv_event_type " "event_type");
+.nl
+.BI "const char *ibv_node_type_str(enum ibv_node_type " "node_type");
+.nl
+.BI "const char *ibv_port_state_str(enum ibv_port_state " "port_state");
+.fi
+.SH "DESCRIPTION"
+.B ibv_node_type_str()
+returns a string describing the node type enum value
+.IR node_type .
+.PP
+.B ibv_port_state_str()
+returns a string describing the port state enum value
+.IR port_state .
+.PP
+.B ibv_event_type_str()
+returns a string describing the event type enum value
+.IR event_type .
+.SH "RETURN VALUE"
+These functions return a constant string that describes the enum value
+passed as their argument.
+.SH "AUTHOR"
+.TP
+Roland Dreier
+.RI < rolandd at cisco.com >
+
diff --git a/src/enum_strs.c b/src/enum_strs.c
new file mode 100644
index 0000000..c57feaa
--- /dev/null
+++ b/src/enum_strs.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2008 Lawrence Livermore National Laboratory
+ *
+ * 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.
+ */
+
+#include <infiniband/verbs.h>
+
+const char *ibv_node_type_str(enum ibv_node_type node_type)
+{
+ static const char *const node_type_str[] = {
+ [IBV_NODE_CA] = "InfiniBand channel adapter",
+ [IBV_NODE_SWITCH] = "InfiniBand switch",
+ [IBV_NODE_ROUTER] = "InfiniBand router",
+ [IBV_NODE_RNIC] = "iWARP NIC"
+ };
+
+ if (node_type < IBV_NODE_CA || node_type > IBV_NODE_RNIC)
+ return "unknown";
+
+ return node_type_str[node_type];
+}
+
+const char *ibv_port_state_str(enum ibv_port_state port_state)
+{
+ static const char *const port_state_str[] = {
+ [IBV_PORT_NOP] = "no state change (NOP)",
+ [IBV_PORT_DOWN] = "down",
+ [IBV_PORT_INIT] = "init",
+ [IBV_PORT_ARMED] = "armed",
+ [IBV_PORT_ACTIVE] = "active",
+ [IBV_PORT_ACTIVE_DEFER] = "active defer"
+ };
+
+ if (port_state < IBV_PORT_NOP || port_state > IBV_PORT_ACTIVE_DEFER)
+ return "unknown";
+
+ return port_state_str[port_state];
+}
+
+const char *ibv_event_type_str(enum ibv_event_type event)
+{
+ static const char *const event_type_str[] = {
+ [IBV_EVENT_CQ_ERR] = "CQ error",
+ [IBV_EVENT_QP_FATAL] = "local work queue catastrophic error",
+ [IBV_EVENT_QP_REQ_ERR] = "invalid request local work queue error",
+ [IBV_EVENT_QP_ACCESS_ERR] = "local access violation work queue error",
+ [IBV_EVENT_COMM_EST] = "communication established",
+ [IBV_EVENT_SQ_DRAINED] = "send queue drained",
+ [IBV_EVENT_PATH_MIG] = "path migrated",
+ [IBV_EVENT_PATH_MIG_ERR] = "path migration request error",
+ [IBV_EVENT_DEVICE_FATAL] = "local catastrophic error",
+ [IBV_EVENT_PORT_ACTIVE] = "port active",
+ [IBV_EVENT_PORT_ERR] = "port error",
+ [IBV_EVENT_LID_CHANGE] = "LID change",
+ [IBV_EVENT_PKEY_CHANGE] = "P_Key change",
+ [IBV_EVENT_SM_CHANGE] = "SM change",
+ [IBV_EVENT_SRQ_ERR] = "SRQ catastrophic error",
+ [IBV_EVENT_SRQ_LIMIT_REACHED] = "SRQ limit reached",
+ [IBV_EVENT_QP_LAST_WQE_REACHED] = "last WQE reached",
+ [IBV_EVENT_CLIENT_REREGISTER] = "client reregistration",
+ };
+
+ if (event < IBV_EVENT_CQ_ERR || event > IBV_EVENT_CLIENT_REREGISTER)
+ return "unknown";
+
+ return event_type_str[event];
+}
+
+const char *ibv_wc_status_str(enum ibv_wc_status status)
+{
+ static const char *const wc_status_str[] = {
+ [IBV_WC_SUCCESS] = "success",
+ [IBV_WC_LOC_LEN_ERR] = "local length error",
+ [IBV_WC_LOC_QP_OP_ERR] = "local QP operation error",
+ [IBV_WC_LOC_EEC_OP_ERR] = "local EE context operation error",
+ [IBV_WC_LOC_PROT_ERR] = "local protection error",
+ [IBV_WC_WR_FLUSH_ERR] = "Work Request Flushed Error",
+ [IBV_WC_MW_BIND_ERR] = "memory management operation error",
+ [IBV_WC_BAD_RESP_ERR] = "bad response error",
+ [IBV_WC_LOC_ACCESS_ERR] = "local access error",
+ [IBV_WC_REM_INV_REQ_ERR] = "remote invalid request error",
+ [IBV_WC_REM_ACCESS_ERR] = "remote access error",
+ [IBV_WC_REM_OP_ERR] = "remote operation error",
+ [IBV_WC_RETRY_EXC_ERR] = "transport retry counter exceeded",
+ [IBV_WC_RNR_RETRY_EXC_ERR] = "RNR retry counter exceeded",
+ [IBV_WC_LOC_RDD_VIOL_ERR] = "local RDD violation error",
+ [IBV_WC_REM_INV_RD_REQ_ERR] = "remote invalid RD request",
+ [IBV_WC_REM_ABORT_ERR] = "aborted error",
+ [IBV_WC_INV_EECN_ERR] = "invalid EE context number",
+ [IBV_WC_INV_EEC_STATE_ERR] = "invalid EE context state",
+ [IBV_WC_FATAL_ERR] = "fatal error",
+ [IBV_WC_RESP_TIMEOUT_ERR] = "response timeout error",
+ [IBV_WC_GENERAL_ERR] = "general error"
+ };
+
+ if (status < IBV_WC_SUCCESS || status > IBV_WC_GENERAL_ERR)
+ return "unknown";
+
+ return wc_status_str[status];
+}
diff --git a/src/libibverbs.map b/src/libibverbs.map
index 3a346ed..1827da0 100644
--- a/src/libibverbs.map
+++ b/src/libibverbs.map
@@ -91,4 +91,9 @@ IBVERBS_1.1 {
ibv_dontfork_range;
ibv_dofork_range;
ibv_register_driver;
+
+ ibv_node_type_str;
+ ibv_port_state_str;
+ ibv_event_type_str;
+ ibv_wc_status_str;
} IBVERBS_1.0;
More information about the general
mailing list