[ofa-general] PATCH[2/6] Windows port of libibmad - dump.c

Davis, Arlin R arlin.r.davis at intel.com
Thu Dec 18 15:38:06 PST 2008


Patch 2/6 - dump.c 

Signed-off by: Arlin Davis <ardavis at ichips.intel.com>

diff -aur libibmad-1.2.2/src/dump.c libibmad/src/dump.c
--- libibmad-1.2.2/src/dump.c	2008-10-19 11:34:41.000000000 -0700
+++ libibmad/src/dump.c	2008-12-17 17:02:40.947163656 -0800
@@ -38,15 +38,51 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <winsock2.h>
+#define snprintf _snprintf
+#else
+#include <stdint.h>
+#include <unistd.h>
 #include <inttypes.h>
 #include <netinet/in.h>
+#endif
 
 #include <mad.h>
-#include <infiniband/common.h>
+#include <complib/cl_types.h>
+
+MAD_EXPORT void
+xdump(FILE *file, char *msg, void *p, int size)
+{
+#define HEX(x)  ((x) < 10 ? '0' + (x) : 'a' + ((x) -10))
+        uint8_t *cp = p;
+        int i;
+
+	if (msg)
+		fputs(msg, file);
+
+        for (i = 0; i < size;) {
+                fputc(HEX(*cp >> 4), file);
+                fputc(HEX(*cp & 0xf), file);
+                if (++i >= size)
+                        break;
+                fputc(HEX(cp[1] >> 4), file);
+                fputc(HEX(cp[1] & 0xf), file);
+                if ((++i) % 16)
+                        fputc(' ', file);
+                else
+                        fputc('\n', file);
+                cp += 2;
+        }
+        if (i % 16) {
+                fputc('\n', file);
+        }
+}
 
-void
+MAD_EXPORT void
 mad_dump_int(char *buf, int bufsz, void *val, int valsz)
 {
 	switch (valsz) {
@@ -72,7 +108,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_uint(char *buf, int bufsz, void *val, int valsz)
 {
 	switch (valsz) {
@@ -98,7 +134,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_hex(char *buf, int bufsz, void *val, int valsz)
 {
 	switch (valsz) {
@@ -115,13 +151,13 @@
 		snprintf(buf, bufsz, "0x%08x", *(uint32_t *)val);
 		break;
 	case 5:
-		snprintf(buf, bufsz, "0x%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffllu);
+		snprintf(buf, bufsz, "0x%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL);
 		break;
 	case 6:
-		snprintf(buf, bufsz, "0x%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffllu);
+		snprintf(buf, bufsz, "0x%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL);
 		break;
 	case 7:
-		snprintf(buf, bufsz, "0x%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffllu);
+		snprintf(buf, bufsz, "0x%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL);
 		break;
 	case 8:
 		snprintf(buf, bufsz, "0x%016" PRIx64, *(uint64_t *)val);
@@ -132,7 +168,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_rhex(char *buf, int bufsz, void *val, int valsz)
 {
 	switch (valsz) {
@@ -149,13 +185,13 @@
 		snprintf(buf, bufsz, "%08x", *(uint32_t *)val);
 		break;
 	case 5:
-		snprintf(buf, bufsz, "%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffllu);
+		snprintf(buf, bufsz, "%010" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffULL);
 		break;
 	case 6:
-		snprintf(buf, bufsz, "%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffllu);
+		snprintf(buf, bufsz, "%012" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffULL);
 		break;
 	case 7:
-		snprintf(buf, bufsz, "%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffllu);
+		snprintf(buf, bufsz, "%014" PRIx64, *(uint64_t *)val & (uint64_t) 0xffffffffffffffULL);
 		break;
 	case 8:
 		snprintf(buf, bufsz, "%016" PRIx64, *(uint64_t *)val);
@@ -166,7 +202,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkwidth(char *buf, int bufsz, void *val, int valsz)
 {
 	int width = *(int *)val;
@@ -212,7 +248,7 @@
 		buf[n-4] = '\0';
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkwidthsup(char *buf, int bufsz, void *val, int valsz)
 {
 	int width = *(int *)val;
@@ -235,7 +271,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkwidthen(char *buf, int bufsz, void *val, int valsz)
 {
 	int width = *(int *)val;
@@ -243,7 +279,7 @@
 	dump_linkwidth(buf, bufsz, width);
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkspeed(char *buf, int bufsz, void *val, int valsz)
 {
 	int speed = *(int *)val;
@@ -300,7 +336,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkspeedsup(char *buf, int bufsz, void *val, int valsz)
 {
 	int speed = *(int *)val;
@@ -308,7 +344,7 @@
 	dump_linkspeed(buf, bufsz, speed);
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkspeeden(char *buf, int bufsz, void *val, int valsz)
 {
 	int speed = *(int *)val;
@@ -316,7 +352,7 @@
 	dump_linkspeed(buf, bufsz, speed);
 }
 
-void
+MAD_EXPORT void
 mad_dump_portstate(char *buf, int bufsz, void *val, int valsz)
 {
 	int state = *(int *)val;
@@ -342,7 +378,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_linkdowndefstate(char *buf, int bufsz, void *val, int valsz)
 {
 	int state = *(int *)val;
@@ -363,7 +399,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_physportstate(char *buf, int bufsz, void *val, int valsz)
 {
 	int state = *(int *)val;
@@ -398,7 +434,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_mtu(char *buf, int bufsz, void *val, int valsz)
 {
 	int mtu = *(int *)val;
@@ -425,7 +461,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_vlcap(char *buf, int bufsz, void *val, int valsz)
 {
 	int vlcap = *(int *)val;
@@ -451,7 +487,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_opervls(char *buf, int bufsz, void *val, int valsz)
 {
 	int opervls = *(int *)val;
@@ -480,7 +516,7 @@
 	}
 }
 
-void
+MAD_EXPORT void
 mad_dump_portcapmask(char *buf, int bufsz, void *val, int valsz)
 {
 	unsigned mask = *(unsigned *)val;
@@ -534,13 +570,13 @@
 		*(--s) = 0;
 }
 
-void
+MAD_EXPORT void
 mad_dump_bitfield(char *buf, int bufsz, void *val, int valsz)
 {
 	snprintf(buf, bufsz, "0x%x", *(uint32_t *)val);
 }
 
-void
+MAD_EXPORT void
 mad_dump_array(char *buf, int bufsz, void *val, int valsz)
 {
 	uint8_t *p = val, *e;
@@ -553,7 +589,7 @@
 		sprintf(s, "%02x", *p);
 }
 
-void
+MAD_EXPORT void
 mad_dump_string(char *buf, int bufsz, void *val, int valsz)
 {
 	if (bufsz < valsz)
@@ -562,7 +598,7 @@
 	snprintf(buf, valsz, "'%s'", (char *)val);
 }
 
-void
+MAD_EXPORT void
 mad_dump_node_type(char *buf, int bufsz, void *val, int valsz)
 {
 	int nodetype = *(int*)val;
@@ -603,7 +639,7 @@
 		uint8_t res_vl;
 		uint8_t weight;
 	} vl_entry[IB_NUM_VL_ARB_ELEMENTS_IN_BLOCK];
-} __attribute__((packed)) ib_vl_arb_table_t;
+} ib_vl_arb_table_t;
 
 static inline void
 ib_vl_arb_get_vl(uint8_t res_vl, uint8_t *const vl )
@@ -611,7 +647,7 @@
 	*vl = res_vl & 0x0F;
 }
 
-void
+MAD_EXPORT void
 mad_dump_sltovl(char *buf, int bufsz, void *val, int valsz)
 {
 	ib_slvl_table_t* p_slvl_tbl = val;
@@ -627,11 +663,11 @@
 	snprintf(buf + n, bufsz - n, "\n");
 }
 
-void
+MAD_EXPORT void
 mad_dump_vlarbitration(char *buf, int bufsz, void *val, int num)
 {
 	ib_vl_arb_table_t* p_vla_tbl = val;
-	unsigned i, n;
+	int i, n;
 	uint8_t vl;
 
 	num /= sizeof(p_vla_tbl->vl_entry[0]);
@@ -678,10 +714,10 @@
 		bufsz -= n;
 	}
 
-	return s - buf;
+	return (int)(s - buf);
 }
 
-void
+MAD_EXPORT void
 mad_dump_nodedesc(char *buf, int bufsz, void *val, int valsz)
 {
 	strncpy(buf, val, bufsz);
@@ -690,37 +726,37 @@
 		buf[valsz] = 0;
 }
 
-void
+MAD_EXPORT void
 mad_dump_nodeinfo(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_NODE_FIRST_F, IB_NODE_LAST_F);
 }
 
-void
+MAD_EXPORT void
 mad_dump_portinfo(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_PORT_FIRST_F, IB_PORT_LAST_F);
 }
 
-void
+MAD_EXPORT void
 mad_dump_portstates(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_PORT_STATE_F, IB_PORT_LINK_DOWN_DEF_F);
 }
 
-void
+MAD_EXPORT void
 mad_dump_switchinfo(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_SW_FIRST_F, IB_SW_LAST_F);
 }
 
-void
+MAD_EXPORT void
 mad_dump_perfcounters(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_PC_FIRST_F, IB_PC_LAST_F);
 }
 
-void
+MAD_EXPORT void
 mad_dump_perfcounters_ext(char *buf, int bufsz, void *val, int valsz)
 {
 	_dump_fields(buf, bufsz, val, IB_PC_EXT_FIRST_F, IB_PC_EXT_LAST_F);
@@ -765,9 +801,13 @@
 int
 _mad_dump(ib_mad_dump_fn *fn, char *name, void *val, int valsz)
 {
-	ib_field_t f = { .def_dump_fn = fn, .bitlen = valsz * 8};
+	ib_field_t f;
 	char buf[512];
 
+	memset(&f, 0, sizeof(f));
+	f.def_dump_fn = fn; 
+	f.bitlen = valsz * 8;
+
 	return printf("%s\n", _mad_dump_field(&f, name, buf, sizeof buf, val));
 }
 
@@ -776,3 +816,4 @@
 {
 	return _mad_dump(f->def_dump_fn, name ? name : f->name, val, valsz ? valsz : ALIGN(f->bitlen, 8) / 8);
 }
+





More information about the general mailing list