[ofw] PATCH[4/6] Windows port of libibmad - gs.c, mad.c, portid.c, register.c, resolve.c

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


4/6 - gs.c, mad.c, portid.c, register.c, resolve.c

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

diff -aur libibmad-1.2.2/src/gs.c libibmad/src/gs.c
--- libibmad-1.2.2/src/gs.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/gs.c	2008-12-17 17:02:40.987157576 -0800
@@ -37,10 +37,16 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <winsock2.h>
+#else
 #include <unistd.h>
 #include <string.h>
 #include <pthread.h>
 #include <sys/time.h>
+#endif
 
 #include <infiniband/umad.h>
 #include "mad.h"
@@ -98,7 +104,7 @@
 			     srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
 {
 	return pma_query(rcvbuf, dest, port, timeout, CLASS_PORT_INFO);
@@ -112,7 +118,7 @@
 			     IB_GSI_PORT_COUNTERS, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_performance_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
 {
 	return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS);
@@ -175,7 +181,7 @@
 				     IB_GSI_PORT_COUNTERS, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
 		       unsigned timeout)
 {
@@ -190,7 +196,7 @@
 			     IB_GSI_PORT_COUNTERS_EXT, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
 {
 	return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_COUNTERS_EXT);
@@ -205,7 +211,7 @@
 				     IB_GSI_PORT_COUNTERS_EXT, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port, unsigned mask,
 			   unsigned timeout)
 {
@@ -220,7 +226,7 @@
 			     IB_GSI_PORT_SAMPLES_CONTROL, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port, unsigned timeout)
 {
 	return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_CONTROL);
@@ -234,7 +240,7 @@
 			     IB_GSI_PORT_SAMPLES_RESULT, srcport);
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,  unsigned timeout)
 {
 	return pma_query(rcvbuf, dest, port, timeout, IB_GSI_PORT_SAMPLES_RESULT);
diff -aur libibmad-1.2.2/src/mad.c libibmad/src/mad.c
--- libibmad-1.2.2/src/mad.c	2008-01-15 11:21:52.000000000 -0800
+++ libibmad/src/mad.c	2008-12-17 17:02:41.004154992 -0800
@@ -37,19 +37,63 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <winsock2.h>
+#include <time.h>
+#define getpid GetCurrentProcessId
+#else
 #include <unistd.h>
 #include <string.h>
 #include <pthread.h>
 #include <sys/time.h>
+#endif
 
-#include <infiniband/common.h>
 #include <infiniband/umad.h>
 #include <mad.h>
 
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
-void
+MAD_EXPORT uint32_t
+mad_get_field(void *buf, int base_offs, int field)
+{
+	return _get_field(buf, base_offs, ib_mad_f + field);
+}
+
+MAD_EXPORT void
+mad_set_field(void *buf, int base_offs, int field, uint32_t val)
+{
+	_set_field(buf, base_offs, ib_mad_f + field, val);
+}
+
+/* field must be byte aligned */
+MAD_EXPORT uint64_t
+mad_get_field64(void *buf, int base_offs, int field)
+{
+	return _get_field64(buf, base_offs, ib_mad_f + field);
+}
+
+MAD_EXPORT void
+mad_set_field64(void *buf, int base_offs, int field, uint64_t val)
+{
+	_set_field64(buf, base_offs, ib_mad_f + field, val);
+}
+
+MAD_EXPORT void
+mad_set_array(void *buf, int base_offs, int field, void *val)
+{
+	_set_array(buf, base_offs, ib_mad_f + field, val);
+}
+
+MAD_EXPORT void
+mad_get_array(void *buf, int base_offs, int field, void *val)
+{
+	_get_array(buf, base_offs, ib_mad_f + field, val);
+}
+
+MAD_EXPORT void
 mad_decode_field(uint8_t *buf, int field, void *val)
 {
 	ib_field_t *f = ib_mad_f + field;
@@ -69,7 +113,7 @@
 	_get_array(buf, 0, f, val);
 }
 
-void
+MAD_EXPORT void
 mad_encode_field(uint8_t *buf, int field, void *val)
 {
 	ib_field_t *f = ib_mad_f + field;
@@ -89,7 +133,7 @@
 	_set_array(buf, 0, f, val);
 }
 
-uint64_t
+MAD_EXPORT uint64_t
 mad_trid(void)
 {
 	static uint64_t base;
@@ -97,15 +141,15 @@
 	uint64_t next;
 
 	if (!base) {
-		srandom(time(0)*getpid());
-		base = random();
-		trid = random();
+		srand((int)time(0)*getpid());
+		base = rand();
+		trid = rand();
 	}
 	next = ++trid | (base << 32);
 	return next;
 }
 
-void *
+MAD_EXPORT void *
 mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data)
 {
 	int is_resp = rpc->method & IB_MAD_RESPONSE;
@@ -139,8 +183,8 @@
 	mad_set_field(buf, 0, IB_MAD_ATTRMOD_F, rpc->attr.mod);
 
 	/* words 7,8 */
-	mad_set_field(buf, 0, IB_MAD_MKEY_F, rpc->mkey >> 32);
-	mad_set_field(buf, 4, IB_MAD_MKEY_F, rpc->mkey & 0xffffffff);
+	mad_set_field(buf, 0, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey >> 32));
+	mad_set_field(buf, 4, IB_MAD_MKEY_F, (uint32_t)(rpc->mkey & 0xffffffff));
 
 	if (rpc->mgtclass == IB_SMI_DIRECT_CLASS) {
 		/* word 9 */
@@ -167,7 +211,7 @@
 	return (uint8_t *)buf + IB_MAD_SIZE;
 }
 
-int
+MAD_EXPORT int
 mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport,
 	      ib_rmpp_hdr_t *rmpp, void *data)
 {
@@ -211,5 +255,5 @@
 		mad_set_field(mad, 0, IB_SA_RMPP_D2_F, rmpp->d2.u);
 	}
 
-	return p - mad;
+	return ((int)(p - mad));
 }
diff -aur libibmad-1.2.2/src/portid.c libibmad/src/portid.c
--- libibmad-1.2.2/src/portid.c	2008-10-19 11:34:41.000000000 -0700
+++ libibmad/src/portid.c	2008-12-17 17:02:41.022152256 -0800
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004-2008 Voltaire Inc.  All rights reserved.
+ * Copyright (c) 2008 Intel Corporation.  All rights reserved.
  *
  * 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
@@ -37,20 +38,72 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#define snprintf _snprintf
+#else
 #include <unistd.h>
 #include <pthread.h>
 #include <sys/time.h>
 #include <string.h>
 #include <inttypes.h>
 #include <arpa/inet.h>
+#endif
 
 #include <mad.h>
-#include <infiniband/common.h>
 
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
-int
+#if defined(_WIN32) || defined(_WIN64)  
+const char * _inet_ntop(int family, const void *addr, char *dst, size_t len)
+{
+	if (family == AF_INET)
+	{
+		struct sockaddr_in in;
+		in.sin_family = AF_INET;
+		memcpy(&in.sin_addr, addr, 4);
+		if (getnameinfo((struct sockaddr *)&in,
+				(socklen_t) (sizeof(struct sockaddr_in)),
+			        dst, len, NULL, 0, NI_NUMERICHOST))
+			return NULL;
+	}
+	else if (family == AF_INET6)
+	{
+		struct sockaddr_in6 in6;
+		memset(&in6, 0, sizeof in6);
+		in6.sin6_family = AF_INET6;
+		memcpy(&in6.sin6_addr, addr, sizeof(struct in_addr6));
+
+		/* if no ipv6 support return simple IPv6 format rule:
+		 * A series of "0's in a 16bit block can be represented by "0" 
+		 */
+		if (getnameinfo((struct sockaddr *)&in6, (socklen_t) (sizeof in6),
+				 dst, len, NULL, 0, NI_NUMERICHOST)) 
+		{
+			char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
+			int i, n=0;
+					
+			if (len < sizeof(tmp))
+				return NULL;
+
+			for (i = 0; i < 8; i++) 
+				n += sprintf(tmp+n, "%s%x", 
+					     i?":":"",
+					     ntohs(((unsigned short*)addr)[i]));
+			tmp[n]='\0';
+			strcpy(dst, tmp);
+		}
+	}
+	return dst;
+}
+#define inet_ntop _inet_ntop
+#endif
+
+MAD_EXPORT int
 portid2portnum(ib_portid_t *portid)
 {
 	if (portid->lid > 0)
@@ -62,7 +115,7 @@
 	return portid->drpath.p[(portid->drpath.cnt-1)];
 }
 
-char *
+MAD_EXPORT char *
 portid2str(ib_portid_t *portid)
 {
 	static char buf[1024] = "local";
@@ -86,7 +139,7 @@
 	return buf;
 }
 
-int
+MAD_EXPORT int
 str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid)
 {
 	char *s, *str = routepath;
@@ -97,7 +150,7 @@
 	while (str && *str) {
 		if ((s = strchr(str, ',')))
 			*s = 0;
-		path->p[++path->cnt] = atoi(str);
+		path->p[++path->cnt] = (uint8_t)atoi(str);
 		if (!s)
 			break;
 		str = s+1;
@@ -109,17 +162,17 @@
 	return path->cnt;
 }
 
-char *
+MAD_EXPORT char *
 drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size)
 {
 	int i = 0;
 	int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d",
 		path->drslid, path->drdlid, path->p[0]);
-	if (rc >= dstr_size)
+	if (rc >= (int) dstr_size)
 		return dstr;
 	for (i = 1; i <= path->cnt; i++) {
 		rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]);
-		if (rc >= dstr_size)
+		if (rc >= (int) dstr_size)
 			break;
 	}
 	return (dstr);
diff -aur libibmad-1.2.2/src/register.c libibmad/src/register.c
--- libibmad-1.2.2/src/register.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/register.c	2008-12-17 17:02:41.040149520 -0800
@@ -37,11 +37,16 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#else
 #include <unistd.h>
 #include <pthread.h>
 #include <sys/time.h>
 #include <string.h>
 #include <errno.h>
+#endif
 
 #include <infiniband/umad.h>
 #include "mad.h"
@@ -104,7 +109,7 @@
 	return 0;
 }
 
-int
+MAD_EXPORT int
 mad_class_agent(int mgmt)
 {
 	if (mgmt < 1 || mgmt > MAX_CLASS)
@@ -112,7 +117,7 @@
 	return class_agent[mgmt];
 }
 
-int
+MAD_EXPORT int
 mad_agent_class(int agent)
 {
 	if (agent < 1 || agent > MAX_AGENTS)
@@ -120,7 +125,7 @@
 	return agent_class[agent];
 }
 
-int
+MAD_EXPORT int
 mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
 {
 	int vers, agent;
@@ -143,7 +148,7 @@
 	return agent;
 }
 
-int
+MAD_EXPORT int
 mad_register_client(int mgmt, uint8_t rmpp_version)
 {
 	int agent;
@@ -155,7 +160,7 @@
 	return register_agent(agent, mgmt);
 }
 
-int
+MAD_EXPORT int
 mad_register_server(int mgmt, uint8_t rmpp_version,
 		    long method_mask[], uint32_t class_oui)
 {
diff -aur libibmad-1.2.2/src/resolve.c libibmad/src/resolve.c
--- libibmad-1.2.2/src/resolve.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/resolve.c	2008-12-17 17:02:41.058146784 -0800
@@ -37,12 +37,17 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#define strtoull _strtoui64
+#else
 #include <unistd.h>
 #include <pthread.h>
 #include <string.h>
 #include <sys/time.h>
+#endif
 
-#include <infiniband/common.h>
 #include <infiniband/umad.h>
 #include <mad.h>
 
@@ -67,7 +72,7 @@
 	return ib_portid_set(sm_id, lid, 0, 0);
 }
 
-int
+MAD_EXPORT int
 ib_resolve_smlid(ib_portid_t *sm_id, int timeout)
 {
 	return ib_resolve_smlid_via(sm_id, timeout, NULL);
@@ -95,6 +100,12 @@
 	return 0;
 }
 
+MAD_EXPORT int
+ib_resolve_guid(ib_portid_t *portid, uint64_t *guid, ib_portid_t *sm_id, int timeout)
+{
+	return ib_resolve_guid_via(portid, guid, sm_id, timeout, NULL);
+}
+
 int
 ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id, const void *srcport)
 {
@@ -144,7 +155,7 @@
 	return -1;
 }
 
-int
+MAD_EXPORT int
 ib_resolve_portid_str(ib_portid_t *portid, char *addr_str, int dest_type, ib_portid_t *sm_id)
 {
 	return ib_resolve_portid_str_via(portid, addr_str, dest_type,
@@ -179,7 +190,7 @@
 	return 0;
 }
 
-int
+MAD_EXPORT int
 ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid)
 {
 	return ib_resolve_self_via (portid, portnum, gid, NULL);



More information about the ofw mailing list