[ofw] PATCH[5/6] Windows port of libibmad - rpc.c, sa.c, serv.c, smp.c, vendor.c

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


5/6 - rpc.c, sa.c, serv.c, smp.c, vendor.c

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

diff -aur libibmad-1.2.2/src/rpc.c libibmad/src/rpc.c
--- libibmad-1.2.2/src/rpc.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/rpc.c	2008-12-17 17:02:41.077143896 -0800
@@ -37,14 +37,21 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <errno.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"
+#include <complib/cl_passivelock.h>
 
 #define MAX_CLASS 256
 
@@ -69,7 +76,7 @@
 
 #define MAD_TID(mad)	(*((uint64_t *)((char *)(mad) + 8)))
 
-void
+MAD_EXPORT void
 madrpc_show_errors(int set)
 {
 	iberrs = set;
@@ -82,7 +89,7 @@
 	save_mad_len = len;
 }
 
-int
+MAD_EXPORT int
 madrpc_set_retries(int retries)
 {
 	if (retries > 0)
@@ -90,7 +97,7 @@
 	return madrpc_retries;
 }
 
-int
+MAD_EXPORT int
 madrpc_set_timeout(int timeout)
 {
 	def_madrpc_timeout = timeout;
@@ -103,7 +110,7 @@
 	return def_madrpc_timeout;
 }
 
-int
+MAD_EXPORT int
 madrpc_portid(void)
 {
 	return mad_portid;
@@ -131,7 +138,7 @@
 		save_mad = 0;
 	}
 
-	trid = mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F);
+	trid = (uint32_t)mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F);
 
 	for (retries = 0; retries < madrpc_retries; retries++) {
 		if (retries) {
@@ -287,21 +294,21 @@
 	return mad_rpc_rmpp(&port, rpc, dport, rmpp, data);
 }
 
-static pthread_mutex_t rpclock = PTHREAD_MUTEX_INITIALIZER;
+static cl_plock_t rpclock;
 
 void
 madrpc_lock(void)
 {
-	pthread_mutex_lock(&rpclock);
+	cl_plock_acquire(&rpclock);
 }
 
 void
 madrpc_unlock(void)
 {
-	pthread_mutex_unlock(&rpclock);
+	cl_plock_release(&rpclock);
 }
 
-void
+MAD_EXPORT void
 madrpc_init(char *dev_name, int dev_port, int *mgmt_classes, int num_classes)
 {
 	if (umad_init() < 0)
@@ -314,7 +321,7 @@
 		IBPANIC("too many classes %d requested", num_classes);
 
 	while (num_classes--) {
-		int rmpp_version = 0;
+		uint8_t rmpp_version = 0;
 		int mgmt = *mgmt_classes++;
 
 		if (mgmt == IB_SA_CLASS)
@@ -322,6 +329,7 @@
 		if (mad_register_client(mgmt, rmpp_version) < 0)
 			IBPANIC("client_register for mgmt class %d failed", mgmt);
 	}
+	cl_plock_init(&rpclock);
 }
 
 void *
@@ -359,7 +367,7 @@
 	}
 
 	while (num_classes--) {
-		int rmpp_version = 0;
+		uint8_t rmpp_version = 0;
 		int mgmt = *mgmt_classes++;
 		int agent;
 
diff -aur libibmad-1.2.2/src/sa.c libibmad/src/sa.c
--- libibmad-1.2.2/src/sa.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/sa.c	2008-12-17 17:02:41.095141160 -0800
@@ -37,13 +37,17 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#else
 #include <unistd.h>
 #include <pthread.h>
 #include <string.h>
 #include <sys/time.h>
+#endif
 
 #include <mad.h>
-#include <infiniband/common.h>
 
 #undef DEBUG
 #define DEBUG 	if (ibdebug)	IBWARN
@@ -145,7 +149,8 @@
 	mad_decode_field(p, IB_SA_PR_DLID_F, &dlid);
 	return dlid;
 }
-int
+
+MAD_EXPORT int
 ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf)
 {
 	return ib_path_query_via (NULL, srcgid, destgid, sm_id, buf);
diff -aur libibmad-1.2.2/src/serv.c libibmad/src/serv.c
--- libibmad-1.2.2/src/serv.c	2008-01-15 11:21:52.000000000 -0800
+++ libibmad/src/serv.c	2008-12-17 17:02:41.113138424 -0800
@@ -37,20 +37,25 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#include <winsock2.h>
+#else
 #include <unistd.h>
 #include <pthread.h>
 #include <sys/time.h>
 #include <string.h>
 #include <netinet/in.h>
+#endif
 
-#include <infiniband/common.h>
 #include <infiniband/umad.h>
 #include <mad.h>
 
 #undef DEBUG
 #define DEBUG	if (ibdebug)	IBWARN
 
-int
+MAD_EXPORT int
 mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data)
 {
 	uint8_t pktbuf[1024];
@@ -78,7 +83,7 @@
 	return 0;
 }
 
-int
+MAD_EXPORT int
 mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus)
 {
 	uint8_t *mad = umad_get_mad(umad);
@@ -152,7 +157,7 @@
 	return 0;
 }
 
-void *
+MAD_EXPORT void *
 mad_receive(void *umad, int timeout)
 {
 	void *mad = umad ? umad : umad_alloc(1, umad_size() + IB_MAD_SIZE);
@@ -170,13 +175,13 @@
 	return mad;
 }
 
-void *
+MAD_EXPORT void *
 mad_alloc(void)
 {
 	return umad_alloc(1, umad_size() + IB_MAD_SIZE);
 }
 
-void
+MAD_EXPORT void
 mad_free(void *umad)
 {
 	umad_free(umad);
diff -aur libibmad-1.2.2/src/smp.c libibmad/src/smp.c
--- libibmad-1.2.2/src/smp.c	2008-08-31 07:15:05.000000000 -0700
+++ libibmad/src/smp.c	2008-12-17 17:02:41.140134320 -0800
@@ -37,13 +37,18 @@
 
 #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 <mad.h>
-#include <infiniband/common.h>
 
 #undef DEBUG
 #define DEBUG 	if (ibdebug)	IBWARN
@@ -78,7 +83,7 @@
 	}
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 smp_set(void *data, ib_portid_t *portid, unsigned attrid, unsigned mod, unsigned timeout)
 {
 	return smp_set_via(data, portid, attrid, mod, timeout, NULL);
@@ -115,7 +120,7 @@
 	}
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 smp_query(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod,
 	  unsigned timeout)
 {
Only in libibmad/src: Sources
diff -aur libibmad-1.2.2/src/vendor.c libibmad/src/vendor.c
--- libibmad-1.2.2/src/vendor.c	2007-07-15 14:27:05.000000000 -0700
+++ libibmad/src/vendor.c	2008-12-17 17:02:41.157131736 -0800
@@ -37,13 +37,17 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#else
 #include <unistd.h>
 #include <string.h>
 #include <pthread.h>
 #include <sys/time.h>
+#endif
 
 #include <mad.h>
-#include <infiniband/common.h>
 
 #undef DEBUG
 #define DEBUG 	if (ibdebug)	IBWARN
@@ -56,7 +60,7 @@
 		method == IB_MAD_METHOD_TRAP;
 }
 
-uint8_t *
+MAD_EXPORT uint8_t *
 ib_vendor_call(void *data, ib_portid_t *portid, ib_vendor_call_t *call)
 {
 	ib_rpc_t rpc = {0};



More information about the ofw mailing list