]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Add functions to convert enum values to strings
authorIra Weiny <weiny2@llnl.gov>
Tue, 15 Apr 2008 20:35:48 +0000 (13:35 -0700)
committerRoland Dreier <rolandd@cisco.com>
Fri, 18 Apr 2008 21:09:35 +0000 (14:09 -0700)
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@llnl.gov>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Makefile.am
examples/devinfo.c
examples/rc_pingpong.c
examples/srq_pingpong.c
examples/uc_pingpong.c
examples/ud_pingpong.c
include/infiniband/verbs.h
man/ibv_event_type_str.3 [new file with mode: 0644]
src/enum_strs.c [new file with mode: 0644]
src/libibverbs.map

index 705b1845a687894c47f572f9ab06a225c9d9451c..9b0530665ce2aafa2a643aef6ad7208568a39cfb 100644 (file)
@@ -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
index 4e4316a416c2339c12f572ba5ec3bb92f5424960..1fadc809c53e1ab9d313ac7945dec5b22541a19a 100644 (file)
@@ -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",
index 71819146bd90ab440bffce086bf69a184fb71df9..26fa45c22ef0fcb34ec30c661caadf727e63ff39 100644 (file)
@@ -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;
                                }
index bc869c96c33f67242b7efa86fa88b1a0bf0463dd..95bebf4e46e5f5d18960fc03e037f536e648bfe6 100644 (file)
@@ -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;
                                }
index 6135030097dcd97f1dd79f34962435dd428eb624..c09c8c1b0781620c9e4860525639426b5c8ddbfb 100644 (file)
@@ -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;
                                }
index aaee26cadb1849e8e5fe170406d0dae287ae8a3a..8f3d50b27ba995b31ff47eb4fc56ecd34ea1918e 100644 (file)
@@ -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;
                                }
index a51bb9d6fccca17dcf380d456bce21436d92c16f..a04cc6221e1856b59f86510420f1764937ea4137 100644 (file)
@@ -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 (file)
index 0000000..0df8fcd
--- /dev/null
@@ -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@cisco.com >
+
diff --git a/src/enum_strs.c b/src/enum_strs.c
new file mode 100644 (file)
index 0000000..c57feaa
--- /dev/null
@@ -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];
+}
index 3a346ed1124c8c55953dd572f452a89f4a1cc21c..1827da058331a7b1de10681ea8e1ef18ed53ad3b 100644 (file)
@@ -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;