Skip to contentSkip to conversation

libibumad: add string functions for various defines

PATCH Superseded Ira Weiny 2 participants 6 messages Feb 18, 2013 – Feb 21, 2013 4 messages not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ira Weiny

author
#0 lore raw

PATCH 1/1 libibumad: add string functions for various defines

This patch adds "enum to string" conversions of the enums in the headers files submitted by Sean Hefty on 1/28/2013

Some of this code was originally proposed by Sean in 2010 as part of user space
madeye: http://www.mail-archive.com/[email protected]/msg06185.html

---
 Makefile.am                     |   13 ++-
 include/infiniband/umad_sm.h    |   31 ++--
 include/infiniband/umad_str.h   |  333 +++++++++++++++++++++++++++++++++++++++
 include/infiniband/umad_types.h |    4 +-
 man/umad_attribute_str.3        |    3 +
 man/umad_class_str.3            |   49 ++++++
 man/umad_cm_attr_str.3          |    3 +
 man/umad_mad_status_str.3       |    3 +
 man/umad_method_str.3           |    3 +
 man/umad_sa_attr_str.3          |    3 +
 man/umad_sm_attr_str.3          |    3 +
 11 files changed, 430 insertions(+), 18 deletions(-)
 create mode 100644 include/infiniband/umad_str.h
 create mode 100644 man/umad_attribute_str.3
 create mode 100644 man/umad_class_str.3
 create mode 100644 man/umad_cm_attr_str.3
 create mode 100644 man/umad_mad_status_str.3
 create mode 100644 man/umad_method_str.3
 create mode 100644 man/umad_sa_attr_str.3
 create mode 100644 man/umad_sm_attr_str.3
Makefile.am +11 -2
index 14e2389..1855628 100644
@@ -15,7 +15,15 @@ man_MANS = man/umad_debug.3 man/umad_get_ca.3 \
 	   man/umad_get_pkey.3 \
 	   man/umad_register.3 man/umad_register_oui.3 man/umad_unregister.3 \
 	   man/umad_send.3 man/umad_recv.3 man/umad_poll.3 \
-	   man/umad_get_issm_path.3
+	   man/umad_get_issm_path.3 \
+	   man/umad_attribute_str.3 \
+	   man/umad_class_str.3 \
+	   man/umad_cm_attr_str.3 \
+	   man/umad_mad_status_str.3 \
+	   man/umad_method_str.3 \
+	   man/umad_sa_attr_str.3 \
+	   man/umad_sm_attr_str.3
+
 
 lib_LTLIBRARIES = libibumad.la
 
@@ -38,7 +46,8 @@ libibumadinclude_HEADERS = $(srcdir)/include/infiniband/umad.h \
 	$(srcdir)/include/infiniband/umad_types.h \
 	$(srcdir)/include/infiniband/umad_sa.h \
 	$(srcdir)/include/infiniband/umad_sm.h \
-	$(srcdir)/include/infiniband/umad_cm.h
+	$(srcdir)/include/infiniband/umad_cm.h \
+	$(srcdir)/include/infiniband/umad_str.h
 
 EXTRA_DIST = $(srcdir)/include/infiniband/umad.h \
 	libibumad.spec.in libibumad.spec \
include/infiniband/umad_sm.h +16 -15
index 10348d4..f6ee171 100755
@@ -55,21 +55,22 @@ enum {
 
 /* Subnet management attributes */
 enum {
-	UMAD_SMP_ATTR_NODE_DESC		= 0x0010,
-	UMAD_SMP_ATTR_NODE_INFO		= 0x0011,
-	UMAD_SMP_ATTR_SWITCH_INFO	= 0x0012,
-	UMAD_SMP_ATTR_GUID_INFO		= 0x0014,
-	UMAD_SMP_ATTR_PORT_INFO		= 0x0015,
-	UMAD_SMP_ATTR_PKEY_TABLE	= 0x0016,
-	UMAD_SMP_ATTR_SLVL_TABLE	= 0x0017,
-	UMAD_SMP_ATTR_VL_ARB_TABLE	= 0x0018,
-	UMAD_SMP_ATTR_LINEAR_FT		= 0x0019,
-	UMAD_SMP_ATTR_RANDOM_FT		= 0x001A,
-	UMAD_SMP_ATTR_MCAST_FT		= 0x001B,
-	UMAD_SMP_ATTR_SM_INFO		= 0x0020,
-	UMAD_SMP_ATTR_VENDOR_DIAG	= 0x0030,
-	UMAD_SMP_ATTR_LED_INFO		= 0x0031,
-	UMAD_SMP_ATTR_VENDOR_MASK	= 0xFF00
+	UMAD_SMP_ATTR_NODE_DESC			= 0x0010,
+	UMAD_SMP_ATTR_NODE_INFO			= 0x0011,
+	UMAD_SMP_ATTR_SWITCH_INFO		= 0x0012,
+	UMAD_SMP_ATTR_GUID_INFO			= 0x0014,
+	UMAD_SMP_ATTR_PORT_INFO			= 0x0015,
+	UMAD_SMP_ATTR_PKEY_TABLE		= 0x0016,
+	UMAD_SMP_ATTR_SLVL_TABLE		= 0x0017,
+	UMAD_SMP_ATTR_VL_ARB_TABLE		= 0x0018,
+	UMAD_SMP_ATTR_LINEAR_FT			= 0x0019,
+	UMAD_SMP_ATTR_RANDOM_FT			= 0x001A,
+	UMAD_SMP_ATTR_MCAST_FT			= 0x001B,
+	UMAD_SMP_ATTR_LINK_SPD_WIDTH_TABLE	= 0x001C,
+	UMAD_SMP_ATTR_SM_INFO			= 0x0020,
+	UMAD_SMP_ATTR_VENDOR_DIAG		= 0x0030,
+	UMAD_SMP_ATTR_LED_INFO			= 0x0031,
+	UMAD_SMP_ATTR_VENDOR_MASK		= 0xFF00
 };
 
 enum {
include/infiniband/umad_str.h new file +333 -0

333 lines not on this page · raw message

include/infiniband/umad_types.h +3 -1
index bf93add..6f2f3d5 100755
@@ -64,10 +64,12 @@ enum {
 	UMAD_CLASS_SNMP			= 0x08,
 	UMAD_CLASS_VENDOR_RANGE1_START	= 0x09,
 	UMAD_CLASS_VENDOR_RANGE1_END	= 0x0F,
-	UMAD_CLASS_DEVICE_ADM		= 0x10,
+	UMAD_CLASS_APPLICATION_START	= 0x10,
+	UMAD_CLASS_DEVICE_ADM		= UMAD_CLASS_APPLICATION_START,
 	UMAD_CLASS_BOOT_MGMT		= 0x11,
 	UMAD_CLASS_BIS			= 0x12,
 	UMAD_CLASS_CONG_MGMT		= 0x21,
+	UMAD_CLASS_APPLICATION_END	= 0x2F,
 	UMAD_CLASS_VENDOR_RANGE2_START	= 0x30,
 	UMAD_CLASS_VENDOR_RANGE2_END	= 0x4F
 };
man/umad_attribute_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
man/umad_class_str.3 new file +49 -0

49 lines not on this page · raw message

man/umad_cm_attr_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
man/umad_mad_status_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
man/umad_method_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
man/umad_sa_attr_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
man/umad_sm_attr_str.3 new file +3 -0
new file mode 100644
index 0000000..f5e6b02
@@ -0,0 +1,3 @@
+.\" -*- nroff -*-
+.\"
+.so man3/umad_class_str.3
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20130218153638.2b452d138f0918b945bcdb71-i2BcT+NCU+M@public.gmane.org

#2 lore raw

include/infiniband/umad_str.h line 142

Quoted 7 lines
include/infiniband/umad_str.h new file +7 -0
+#define UMAD_GENERIC_ATTRIBUTE_STR \
+		case UMAD_ATTR_CLASS_PORT_INFO: \
+			return "Class Port Info"; \
+		case UMAD_ATTR_NOTICE: \
+			return "Notice"; \
+		case UMAD_ATTR_INFORM_INFO: \
+			return "Inform Info"

this is .. odd :P

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1828884A29C6694DAF28B7E6B8A823736F342E49-P5GAC/[email protected]

author
#4 lore raw
Quoted 9 lines · Sean

include/infiniband/umad_str.h line 142

Quoted 7 lines
include/infiniband/umad_str.h new file +7 -0
+#define UMAD_GENERIC_ATTRIBUTE_STR \
+		case UMAD_ATTR_CLASS_PORT_INFO: \
+			return "Class Port Info"; \
+		case UMAD_ATTR_NOTICE: \
+			return "Notice"; \
+		case UMAD_ATTR_INFORM_INFO: \
+			return "Inform Info"

this is .. odd :P

I got tired of typing. If you think it will be a maintenance issue I can change.

Ira

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 9 lines
Ira Weiny
Member of Technical Staff
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
In reply to a message not in the archive

include/infiniband/umad_str.h line 142

Quoted 7 lines
include/infiniband/umad_str.h new file +7 -0
+#define UMAD_GENERIC_ATTRIBUTE_STR \
+		case UMAD_ATTR_CLASS_PORT_INFO: \
+			return "Class Port Info"; \
+		case UMAD_ATTR_NOTICE: \
+			return "Notice"; \
+		case UMAD_ATTR_INFORM_INFO: \
+			return "Inform Info"

What if you convert this to something like:

static inline char *umad_attr_str(be16_t attr_id)

{
	switch(ntohs(attr_id)) {
		case UMAD_ATTR_CLASS_PORT_INFO:
			return "Class Port Info";
		case UMAD_ATTR_NOTICE:
			return "Notice";
		case UMAD_ATTR_INFORM_INFO:
			return "Inform Info";
		default:
			return "unknown";
	}
}

and then...

include/infiniband/umad_str.h line 147

Quoted 4 lines
include/infiniband/umad_str.h new file +4 -0
+static inline char * umad_sm_attr_str(be16_t attr_id)
+{
+	switch(ntohs(attr_id)) {
+

remove this line

Review

Quoted 1 line
(quoted diff) +1 -0
+		UMAD_GENERIC_ATTRIBUTE_STR;

and...

Quoted 21 lines
include/infiniband/umad_str.h new file +21 -0
+
+		case UMAD_SMP_ATTR_NODE_DESC:
+			return ("NodeDescription");
+		case UMAD_SMP_ATTR_NODE_INFO:
+			return ("NodeInfo");
+		case UMAD_SMP_ATTR_SWITCH_INFO:
+			return ("SwitchInfo");
+		case UMAD_SMP_ATTR_GUID_INFO:
+			return ("GUIDInfo");
+		case UMAD_SMP_ATTR_PORT_INFO:
+			return ("PortInfo");
+		case UMAD_SMP_ATTR_PKEY_TABLE:
+			return ("P_KeyTable");
+		case UMAD_SMP_ATTR_SLVL_TABLE:
+			return ("SLtoVLMappingTable");
+		case UMAD_SMP_ATTR_VL_ARB_TABLE:
+			return ("VLArbitrationTable");
+		case UMAD_SMP_ATTR_LINEAR_FT:
+			return ("LinearForwardingTable");
+		case UMAD_SMP_ATTR_RANDOM_FT:
+			return ("RandomForwardingTable");

include/infiniband/umad_str.h line 179

Quoted 10 lines
include/infiniband/umad_str.h new file +10 -0
+		case UMAD_SMP_ATTR_MCAST_FT:
+			return ("MulticastForwardingTable");
+		case UMAD_SMP_ATTR_SM_INFO:
+			return ("SMInfo");
+		case UMAD_SMP_ATTR_VENDOR_DIAG:
+			return ("VendorDiag");
+		case UMAD_SMP_ATTR_LED_INFO:
+			return ("LedInfo");
+		case UMAD_SMP_ATTR_LINK_SPD_WIDTH_TABLE:
+			return ("LinkSpeedWidthPairsTable");

add:

		default:
			return umad_attr_str(attr_id);

include/infiniband/umad_str.h line 95

Quoted 3 lines
include/infiniband/umad_str.h new file +3 -0
+	}
+	return ("<unknown>");
+}

- Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1828884A29C6694DAF28B7E6B8A823736F352181-P5GAC/[email protected]

author
#7 lore raw
Quoted 9 lines · Sean

include/infiniband/umad_str.h line 142

Quoted 7 lines
include/infiniband/umad_str.h new file +7 -0
+#define UMAD_GENERIC_ATTRIBUTE_STR \
+		case UMAD_ATTR_CLASS_PORT_INFO: \
+			return "Class Port Info"; \
+		case UMAD_ATTR_NOTICE: \
+			return "Notice"; \
+		case UMAD_ATTR_INFORM_INFO: \
+			return "Inform Info"

What if you convert this to something like:

This would definitely work but I was concerned that someone reading the header file would confuse such a function with:

static inline char * umad_attribute_str(uint8_t mgmt_class, be16_t attr_id)

and not get proper decoding.

Anyway, that is what I was thinking. The macro is pretty obfuscated. :-(

Perhaps:

static inline char *umad_common_attr_str(be16_t attr_id)

That follows the spec better.

Patch to follow,
Ira

Quoted 73 lines

static inline char *umad_attr_str(be16_t attr_id)

{
	switch(ntohs(attr_id)) {
		case UMAD_ATTR_CLASS_PORT_INFO:
			return "Class Port Info";
		case UMAD_ATTR_NOTICE:
			return "Notice";
		case UMAD_ATTR_INFORM_INFO:
			return "Inform Info";
		default:
			return "unknown";
	}
}

and then...

include/infiniband/umad_str.h line 147

Quoted 4 lines
include/infiniband/umad_str.h new file +4 -0
+static inline char * umad_sm_attr_str(be16_t attr_id)
+{
+	switch(ntohs(attr_id)) {
+

remove this line

Review

Quoted 1 line
(quoted diff) +1 -0
+		UMAD_GENERIC_ATTRIBUTE_STR;

and...

Quoted 21 lines
include/infiniband/umad_str.h new file +21 -0
+
+		case UMAD_SMP_ATTR_NODE_DESC:
+			return ("NodeDescription");
+		case UMAD_SMP_ATTR_NODE_INFO:
+			return ("NodeInfo");
+		case UMAD_SMP_ATTR_SWITCH_INFO:
+			return ("SwitchInfo");
+		case UMAD_SMP_ATTR_GUID_INFO:
+			return ("GUIDInfo");
+		case UMAD_SMP_ATTR_PORT_INFO:
+			return ("PortInfo");
+		case UMAD_SMP_ATTR_PKEY_TABLE:
+			return ("P_KeyTable");
+		case UMAD_SMP_ATTR_SLVL_TABLE:
+			return ("SLtoVLMappingTable");
+		case UMAD_SMP_ATTR_VL_ARB_TABLE:
+			return ("VLArbitrationTable");
+		case UMAD_SMP_ATTR_LINEAR_FT:
+			return ("LinearForwardingTable");
+		case UMAD_SMP_ATTR_RANDOM_FT:
+			return ("RandomForwardingTable");

include/infiniband/umad_str.h line 179

Quoted 10 lines
include/infiniband/umad_str.h new file +10 -0
+		case UMAD_SMP_ATTR_MCAST_FT:
+			return ("MulticastForwardingTable");
+		case UMAD_SMP_ATTR_SM_INFO:
+			return ("SMInfo");
+		case UMAD_SMP_ATTR_VENDOR_DIAG:
+			return ("VendorDiag");
+		case UMAD_SMP_ATTR_LED_INFO:
+			return ("LedInfo");
+		case UMAD_SMP_ATTR_LINK_SPD_WIDTH_TABLE:
+			return ("LinkSpeedWidthPairsTable");

add:

		default:
			return umad_attr_str(attr_id);

include/infiniband/umad_str.h line 95

Quoted 3 lines
include/infiniband/umad_str.h new file +3 -0
+	}
+	return ("<unknown>");
+}

- Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 9 lines
Ira Weiny
Member of Technical Staff
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20130221084708.b0ae44ad7b700ded7090ba0d-i2BcT+NCU+M@public.gmane.org

#9 lore raw
Quoted 7 lines

This would definitely work but I was concerned that someone reading the header file would confuse such a function with:

static inline char * umad_attribute_str(uint8_t mgmt_class, be16_t attr_id)

and not get proper decoding.

Quoted 7 lines

Anyway, that is what I was thinking. The macro is pretty obfuscated. :-(

Perhaps:

static inline char *umad_common_attr_str(be16_t attr_id)

That follows the spec better.

I'm more concerned that the #define was placed in an external header file, followed by it being a macro that's part of a switch statement.

As for the actual functions, I think they should be exported by the library, rather than declared as static inline calls (see similar libibverbs and librdmacm calls). If a caller uses these in more than one place, they're rather large functions that end up embedded in the user's code. --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html