[ofw] [PATCH 0/?] Use DBG preprocessor constant properly

Fab Tillier ftillier at microsoft.com
Mon Jun 18 18:11:13 PDT 2012


This is the first patch in a series of patches that clean up the tree and fix minor bugs.  I don't have a clear number of patches, but am generating them as if they are applied in order.

The docs for the DBG preprocessor constant state that DBG will be set to 1 for checked builds.  It may be defined and set to 0 for free builds.  See http://msdn.microsoft.com/en-us/library/windows/hardware/ff543512(v=vs.85).aspx.

This patch updates the usage from #ifdef DBG to #if DBG.

Signed-off-by:Fab Tillier <ftillier at microsoft.com>

Index: tools/perftests/user/send_bw/send_bw.rc
===================================================================
--- tools/perftests/user/send_bw/send_bw.rc	(revision 3414)
+++ tools/perftests/user/send_bw/send_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Send/Recv Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Send/Recv Bandwidth Test "
Index: tools/perftests/user/write_bw/write_bw.rc
===================================================================
--- tools/perftests/user/write_bw/write_bw.rc	(revision 3414)
+++ tools/perftests/user/write_bw/write_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"RDMA write Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"RDMA write Bandwidth Test "
Index: tools/perftests/user/send_lat/send_lat.rc
===================================================================
--- tools/perftests/user/send_lat/send_lat.rc	(revision 3414)
+++ tools/perftests/user/send_lat/send_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Send/Recv Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Send/Recv Latency Test "
Index: tools/perftests/user/write_lat/write_lat.rc
===================================================================
--- tools/perftests/user/write_lat/write_lat.rc	(revision 3414)
+++ tools/perftests/user/write_lat/write_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"RDMA write Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"RDMA write Latency Test "
Index: tools/perftests/user/read_bw/read_bw.rc
===================================================================
--- tools/perftests/user/read_bw/read_bw.rc	(revision 3414)
+++ tools/perftests/user/read_bw/read_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"RDMA read Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"RDMA read Bandwidth Test "
Index: tools/perftests/user/read_lat/read_lat.rc
===================================================================
--- tools/perftests/user/read_lat/read_lat.rc	(revision 3414)
+++ tools/perftests/user/read_lat/read_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"RDMA read Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"RDMA read Latency Test "
Index: tools/part_man/user/part_man.rc
===================================================================
--- tools/part_man/user/part_man.rc	(revision 3414)
+++ tools/part_man/user/part_man.rc	(working copy)
@@ -3,7 +3,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Partition manager application(Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Partition manager application"
Index: tools/vstat/user/vstat.rc
===================================================================
--- tools/vstat/user/vstat.rc	(revision 3414)
+++ tools/vstat/user/vstat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"HCA Status Report Application (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"HCA Status Report Application"
Index: tools/wsdinstall/user/installsp.rc
===================================================================
--- tools/wsdinstall/user/installsp.rc	(revision 3414)
+++ tools/wsdinstall/user/installsp.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Winsock Direct for InfiniBand installer (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Winsock Direct for InfiniBand installer"
Index: tools/infiniband-diags/src/ibcacheedit/ibcacheedit.rc
===================================================================
--- tools/infiniband-diags/src/ibcacheedit/ibcacheedit.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibcacheedit/ibcacheedit.rc	(working copy)
@@ -35,7 +35,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Edit InfiniBand Diagnostic Cache Information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Edit InfiniBand Diagnostic Cache Information"
Index: tools/infiniband-diags/src/ibsysstat/ibsysstat.rc
===================================================================
--- tools/infiniband-diags/src/ibsysstat/ibsysstat.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibsysstat/ibsysstat.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SM Information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SM Information"
Index: tools/infiniband-diags/src/smpdump/smpdump.rc
===================================================================
--- tools/infiniband-diags/src/smpdump/smpdump.rc	(revision 3414)
+++ tools/infiniband-diags/src/smpdump/smpdump.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Display IB SM Attributes (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Display IB SM Attributes"
Index: tools/infiniband-diags/src/smpquery/smpquery.rc
===================================================================
--- tools/infiniband-diags/src/smpquery/smpquery.rc	(revision 3414)
+++ tools/infiniband-diags/src/smpquery/smpquery.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Query IB SM Attributes (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Query IB SM Attributes"
Index: tools/infiniband-diags/src/saquery/saquery.rc
===================================================================
--- tools/infiniband-diags/src/saquery/saquery.rc	(revision 3414)
+++ tools/infiniband-diags/src/saquery/saquery.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SA Query Utility (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SA Query Utility"
Index: tools/infiniband-diags/src/ibsendtrap/ibsendtrap.rc
===================================================================
--- tools/infiniband-diags/src/ibsendtrap/ibsendtrap.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibsendtrap/ibsendtrap.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Send InfiniBand Traps (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Send InfiniBand Traps"
Index: tools/infiniband-diags/src/sminfo/sminfo.rc
===================================================================
--- tools/infiniband-diags/src/sminfo/sminfo.rc	(revision 3414)
+++ tools/infiniband-diags/src/sminfo/sminfo.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SM Information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand SM Information"
Index: tools/infiniband-diags/src/mcm_rereg_test/mcm_rereg_test.rc
===================================================================
--- tools/infiniband-diags/src/mcm_rereg_test/mcm_rereg_test.rc	(revision 3414)
+++ tools/infiniband-diags/src/mcm_rereg_test/mcm_rereg_test.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Multicase Registration Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Multicase Registration Test"
Index: tools/infiniband-diags/src/ibportstate/ibportstate.rc
===================================================================
--- tools/infiniband-diags/src/ibportstate/ibportstate.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibportstate/ibportstate.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Port State (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Port State"
Index: tools/infiniband-diags/src/ibping/ibping.rc
===================================================================
--- tools/infiniband-diags/src/ibping/ibping.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibping/ibping.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand MAD Ping (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand MAD Ping"
Index: tools/infiniband-diags/src/ibroute/ibroute.rc
===================================================================
--- tools/infiniband-diags/src/ibroute/ibroute.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibroute/ibroute.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Query InfiniBand Switch Forwarding Tables (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Query InfiniBand Switch Forwarding Tables"
Index: tools/infiniband-diags/src/ibqueryerrors/ibqueryerrors.rc
===================================================================
--- tools/infiniband-diags/src/ibqueryerrors/ibqueryerrors.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibqueryerrors/ibqueryerrors.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Error Reporting (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Error Reporting"
Index: tools/infiniband-diags/src/ibtracert/ibtracert.rc
===================================================================
--- tools/infiniband-diags/src/ibtracert/ibtracert.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibtracert/ibtracert.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"Trace InfiniBand Path (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"Trace InfiniBand Path"
Index: tools/infiniband-diags/src/perfquery/perfquery.rc
===================================================================
--- tools/infiniband-diags/src/perfquery/perfquery.rc	(revision 3414)
+++ tools/infiniband-diags/src/perfquery/perfquery.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Performance Stats Query (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Performance Stats Query"
Index: tools/infiniband-diags/src/iblinkinfo/iblinkinfo.rc
===================================================================
--- tools/infiniband-diags/src/iblinkinfo/iblinkinfo.rc	(revision 3414)
+++ tools/infiniband-diags/src/iblinkinfo/iblinkinfo.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Network Link Information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Network Link Information"
Index: tools/infiniband-diags/src/ibaddr/ibaddr.rc
===================================================================
--- tools/infiniband-diags/src/ibaddr/ibaddr.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibaddr/ibaddr.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Address Information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Address Information"
Index: tools/infiniband-diags/src/ibstat/ibstat.rc
===================================================================
--- tools/infiniband-diags/src/ibstat/ibstat.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibstat/ibstat.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Fabric Stats (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Fabric Stats"
Index: tools/infiniband-diags/src/vendstat/vendstat.rc
===================================================================
--- tools/infiniband-diags/src/vendstat/vendstat.rc	(revision 3414)
+++ tools/infiniband-diags/src/vendstat/vendstat.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Vendor HW Stats (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Vendor HW Stats"
Index: tools/infiniband-diags/src/ibnetdiscover/ibnetdiscover.rc
===================================================================
--- tools/infiniband-diags/src/ibnetdiscover/ibnetdiscover.rc	(revision 3414)
+++ tools/infiniband-diags/src/ibnetdiscover/ibnetdiscover.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Network Topology Discovery (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR	"InfiniBand Network Topology Discovery"
Index: tools/ndinstall/user/installsp.rc
===================================================================
--- tools/ndinstall/user/installsp.rc	(revision 3414)
+++ tools/ndinstall/user/installsp.rc	(working copy)
@@ -34,7 +34,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"NetworkDirect for InfiniBand installer (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"NetworkDirect for InfiniBand installer"
Index: tools/qlgcvnic_config/qlgcvnic_config.rc
===================================================================
--- tools/qlgcvnic_config/qlgcvnic_config.rc	(revision 3414)
+++ tools/qlgcvnic_config/qlgcvnic_config.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"QLogic Vnic configuration Application (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"QLogic Vnic configuration Application"
Index: ulp/netdirect/user/SOURCES
===================================================================
--- ulp/netdirect/user/SOURCES	(revision 3414)
+++ ulp/netdirect/user/SOURCES	(working copy)
@@ -40,5 +40,5 @@
 
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
Index: ulp/netdirect/user/netdirect.rc
===================================================================
--- ulp/netdirect/user/netdirect.rc	(revision 3414)
+++ ulp/netdirect/user/netdirect.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"OpenFabrics Winverbs Network Direct Provider (Debug)"
 #define VER_INTERNALNAME_STR		"wvndprovd.dll"
 #define VER_ORIGINALFILENAME_STR	"wvndprovd.dll"
Index: ulp/libibverbs/src/ibverbs.rc
===================================================================
--- ulp/libibverbs/src/ibverbs.rc	(revision 3414)
+++ ulp/libibverbs/src/ibverbs.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"LibIbVerbs (Debug)"
 #define VER_INTERNALNAME_STR		"libibverbsd.dll"
 #define VER_ORIGINALFILENAME_STR	"libibverbsd.dll"
Index: ulp/libibverbs/examples/asyncwatch/asyncwatch.rc
===================================================================
--- ulp/libibverbs/examples/asyncwatch/asyncwatch.rc	(revision 3414)
+++ ulp/libibverbs/examples/asyncwatch/asyncwatch.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Async Event Watch (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Async Event Watch"
Index: ulp/libibverbs/examples/rc_pingpong/rc_pingpong.rc
===================================================================
--- ulp/libibverbs/examples/rc_pingpong/rc_pingpong.rc	(revision 3414)
+++ ulp/libibverbs/examples/rc_pingpong/rc_pingpong.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Reliable Connection pingpong test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Reliable Connection pingpong test"
Index: ulp/libibverbs/examples/srq_pingpong/srq_pingpong.rc
===================================================================
--- ulp/libibverbs/examples/srq_pingpong/srq_pingpong.rc	(revision 3414)
+++ ulp/libibverbs/examples/srq_pingpong/srq_pingpong.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Shared Recv Queue pingpong test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Shared Recv Queue pingpong test"
Index: ulp/libibverbs/examples/uc_pingpong/uc_pingpong.rc
===================================================================
--- ulp/libibverbs/examples/uc_pingpong/uc_pingpong.rc	(revision 3414)
+++ ulp/libibverbs/examples/uc_pingpong/uc_pingpong.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - UC pingpong test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - UC pingpong test"
Index: ulp/libibverbs/examples/ud_pingpong/ud_pingpong.rc
===================================================================
--- ulp/libibverbs/examples/ud_pingpong/ud_pingpong.rc	(revision 3414)
+++ ulp/libibverbs/examples/ud_pingpong/ud_pingpong.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Unreliable Datagram pingpong test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Unreliable Datagram pingpong test"
Index: ulp/libibverbs/examples/devinfo/devinfo.rc
===================================================================
--- ulp/libibverbs/examples/devinfo/devinfo.rc	(revision 3414)
+++ ulp/libibverbs/examples/devinfo/devinfo.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Device information (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Device information "
Index: ulp/libibumad/src/ibumad.rc
===================================================================
--- ulp/libibumad/src/ibumad.rc	(revision 3414)
+++ ulp/libibumad/src/ibumad.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"LibIbUmad (Debug)"
 #define VER_INTERNALNAME_STR		"LibIbUmadd.dll"
 #define VER_ORIGINALFILENAME_STR	"LibIbUmadd.dll"
Index: ulp/librdmacm/src/cma.rc
===================================================================
--- ulp/librdmacm/src/cma.rc	(revision 3414)
+++ ulp/librdmacm/src/cma.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"LibRdmaCm (Debug)"
 #define VER_INTERNALNAME_STR		"librdmacmd.dll"
 #define VER_ORIGINALFILENAME_STR	"librdmacmd.dll"
Index: ulp/wsd/user/ibspdll.rc
===================================================================
--- ulp/wsd/user/ibspdll.rc	(revision 3414)
+++ ulp/wsd/user/ibspdll.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Winsock Direct for InfiniBand (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Winsock Direct for InfiniBand"
Index: ulp/opensm/user/libvendor/SOURCES
===================================================================
--- ulp/opensm/user/libvendor/SOURCES	(revision 3414)
+++ ulp/opensm/user/libvendor/SOURCES	(working copy)
@@ -48,7 +48,7 @@
 C_DEFINES=$(C_DEFINES) -D__WIN__ -DHAVE_CONFIG_H -D$(VENDOR_IF)
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 # in cl_types_osd.h '_DEBUG_' is defined by virture of '_DEBUG" being defined.
 !else
 # favor fast over default small; default is /Oxs.
Index: ulp/opensm/user/osmtest/osmtest.rc
===================================================================
--- ulp/opensm/user/osmtest/osmtest.rc	(revision 3414)
+++ ulp/opensm/user/osmtest/osmtest.rc	(working copy)
@@ -33,7 +33,7 @@
 
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "OpenSM Test Application 3.3.11 (Debug)"
 #define VER_INTERNALNAME_STR        "osmtest.exe"
 #define VER_ORIGINALFILENAME_STR    "osmtest.exe"
Index: ulp/opensm/user/opensm/opensm.rc
===================================================================
--- ulp/opensm/user/opensm/opensm.rc	(revision 3414)
+++ ulp/opensm/user/opensm/opensm.rc	(working copy)
@@ -32,7 +32,7 @@
 
 #define VER_FILETYPE				VFT_APP
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "OpenSM InfiniBand Subnet Manager 3.3.13 (Debug)"
 #define VER_INTERNALNAME_STR        "opensm.exe"
 #define VER_ORIGINALFILENAME_STR    "opensm.exe"
Index: ulp/opensm/user/opensm/SOURCES
===================================================================
--- ulp/opensm/user/opensm/SOURCES	(revision 3414)
+++ ulp/opensm/user/opensm/SOURCES	(working copy)
@@ -57,7 +57,7 @@
 C_DEFINES=$(C_DEFINES) -DWINVER=$(_NT_TARGET_VERSION) 
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 # If not specified, default is no optimization: /Od /Oi per WDK docs.
 !else
 # If not specified, default is /Oxs, favor fast code here.
Index: ulp/nd/user/SOURCES
===================================================================
--- ulp/nd/user/SOURCES	(revision 3414)
+++ ulp/nd/user/SOURCES	(working copy)
@@ -45,12 +45,10 @@
 			$(SDK_LIB_PATH)\ws2_32.lib \
 			$(SDK_LIB_PATH)\iphlpapi.lib \
 			$(TARGETPATH)\*\ibat_ex.lib \
-                        $(TARGETPATH)\*\ibal.lib \
-			$(TARGETPATH)\*\complib.lib \
 			$(SDK_LIB_PATH)\uuid.lib
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 !IFDEF ENABLE_EVENT_TRACING
Index: ulp/nd/user/NdProv.rc
===================================================================
--- ulp/nd/user/NdProv.rc	(revision 3414)
+++ ulp/nd/user/NdProv.rc	(working copy)
@@ -25,8 +25,6 @@
  * 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.
- *
- * $Id$
  */
 
 
@@ -35,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"OpenFabrics NetworkDirect Infiniband Provider (Debug)"
 #define VER_INTERNALNAME_STR		"ibndprov.dll"
 #define VER_ORIGINALFILENAME_STR	"ibndprov.dll"
Index: ulp/ipoib/kernel/ipoib_port.cpp
===================================================================
--- ulp/ipoib/kernel/ipoib_port.cpp	(revision 3414)
+++ ulp/ipoib/kernel/ipoib_port.cpp	(working copy)
@@ -6289,7 +6289,7 @@
     ASSERT(MmGetMdlByteCount(pMdl) >= CurrentMdlDataOffset);
 
     ASSERT(NetBuff != NULL);
-#ifdef DBG
+#if DBG
     ASSERT(PhysBufCount <= MAX_PHYS_BUF_FRAG_ELEMENTS);
 #else
 	UNREFERENCED_PARAMETER(PhysBufCount);
@@ -6417,7 +6417,7 @@
     ASSERT(i <= PhysBufCount);
     pFragList->NumberOfElements = i;
 
-#ifdef DBG
+#if DBG
 	{
     	ULONG size = 0;
     	for (i  = 0; i <  pFragList->NumberOfElements; ++i)
Index: ulp/dapl2/test/dtest/dtest.c
===================================================================
--- ulp/dapl2/test/dtest/dtest.c	(revision 3414)
+++ ulp/dapl2/test/dtest/dtest.c	(working copy)
@@ -1,2105 +1,2105 @@
-/*
- * Copyright (c) 2005-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
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef DAPL_PROVIDER
-#undef DAPL_PROVIDER
-#endif
-
-#if defined(_WIN32) || defined(_WIN64)
-
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <io.h>
-#include <process.h>
-#include <complib/cl_types.h>
-#include "..\..\..\..\etc\user\getopt.c"
-
-#define getpid() ((int)GetCurrentProcessId())
-#define F64x "%I64x"
-
-#ifdef DBG
-#define DAPL_PROVIDER "ibnic0v2d"
-#else
-#define DAPL_PROVIDER "ibnic0v2"
-#endif
-
-#define ntohll _byteswap_uint64
-#define htonll _byteswap_uint64
-
-#else // _WIN32 || _WIN64
-
-#include <endian.h>
-#include <byteswap.h>
-#include <netdb.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <sys/mman.h>
-#include <getopt.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#define DAPL_PROVIDER "ofa-v2-ib0"
-
-#define F64x "%"PRIx64""
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define htonll(x) (x)
-#define ntohll(x) (x)
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-#define htonll(x)  bswap_64(x)
-#define ntohll(x)  bswap_64(x)
-#endif
-
-#endif // _WIN32 || _WIN64
-
-/* Debug: 1 == connect & close only, otherwise full-meal deal */
-#define CONNECT_ONLY 0
-
-#define MAX_POLLING_CNT 50000
-#define MAX_RDMA_RD    4
-#define MAX_PROCS      1000
-
-/* Header files needed for DAT/uDAPL */
-#include "dat2/udat.h"
-
-/* definitions */
-#define SERVER_CONN_QUAL  45248
-#define DTO_TIMEOUT       (1000*1000*5)
-#define CNO_TIMEOUT       (1000*1000*1)
-#define DTO_FLUSH_TIMEOUT (1000*1000*2)
-#define CONN_TIMEOUT      (1000*1000*100)
-#define SERVER_TIMEOUT    DAT_TIMEOUT_INFINITE
-#define RDMA_BUFFER_SIZE  (64)
-
-/* Global DAT vars */
-static DAT_IA_HANDLE h_ia = DAT_HANDLE_NULL;
-static DAT_PZ_HANDLE h_pz = DAT_HANDLE_NULL;
-static DAT_EP_HANDLE h_ep = DAT_HANDLE_NULL;
-static DAT_PSP_HANDLE h_psp = DAT_HANDLE_NULL;
-static DAT_CR_HANDLE h_cr = DAT_HANDLE_NULL;
-
-static DAT_EVD_HANDLE h_async_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_dto_req_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_dto_rcv_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_cr_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_conn_evd = DAT_HANDLE_NULL;
-static DAT_CNO_HANDLE h_dto_cno = DAT_HANDLE_NULL;
-
-/* RDMA buffers */
-static DAT_LMR_HANDLE h_lmr_send = DAT_HANDLE_NULL;
-static DAT_LMR_HANDLE h_lmr_recv = DAT_HANDLE_NULL;
-static DAT_LMR_CONTEXT lmr_context_send;
-static DAT_LMR_CONTEXT lmr_context_recv;
-static DAT_RMR_CONTEXT rmr_context_send;
-static DAT_RMR_CONTEXT rmr_context_recv;
-static DAT_VLEN registered_size_send;
-static DAT_VLEN registered_size_recv;
-static DAT_VADDR registered_addr_send;
-static DAT_VADDR registered_addr_recv;
-
-/* Initial msg receive buf, RMR exchange, and Rdma-write notification */
-#define MSG_BUF_COUNT     3
-#define MSG_IOV_COUNT     2
-static DAT_RMR_TRIPLET rmr_recv_msg[MSG_BUF_COUNT];
-static DAT_LMR_HANDLE h_lmr_recv_msg = DAT_HANDLE_NULL;
-static DAT_LMR_CONTEXT lmr_context_recv_msg;
-static DAT_RMR_CONTEXT rmr_context_recv_msg;
-static DAT_VLEN registered_size_recv_msg;
-static DAT_VADDR registered_addr_recv_msg;
-
-/* message send buffer */
-static DAT_RMR_TRIPLET rmr_send_msg;
-static DAT_LMR_HANDLE h_lmr_send_msg = DAT_HANDLE_NULL;
-static DAT_LMR_CONTEXT lmr_context_send_msg;
-static DAT_RMR_CONTEXT rmr_context_send_msg;
-static DAT_VLEN registered_size_send_msg;
-static DAT_VADDR registered_addr_send_msg;
-static DAT_EP_ATTR ep_attr;
-char hostname[256] = { 0 };
-char provider[64] = DAPL_PROVIDER;
-char addr_str[INET_ADDRSTRLEN];
-
-/* rdma pointers */
-char *rbuf = NULL;
-char *sbuf = NULL;
-int status;
-
-/* timers */
-double start, stop, total_us, total_sec;
-
-struct dt_time {
-	double total;
-	double open;
-	double reg;
-	double unreg;
-	double pzc;
-	double pzf;
-	double evdc;
-	double evdf;
-	double cnoc;
-	double cnof;
-	double epc;
-	double epf;
-	double rdma_wr;
-	double rdma_rd[MAX_RDMA_RD];
-	double rdma_rd_total;
-	double rtt;
-	double close;
-	double conn;
-};
-
-struct dt_time ts;
-
-/* defaults */
-static int failed = 0;
-static int performance_times = 0;
-static int connected = 0;
-static int burst = 10;
-static int server = 1;
-static int verbose = 0;
-static int polling = 0;
-static int poll_count = 0;
-static int rdma_wr_poll_count = 0;
-static int conn_poll_count = 0;
-static int rdma_rd_poll_count[MAX_RDMA_RD] = { 0 };
-static int delay = 0;
-static int buf_len = RDMA_BUFFER_SIZE;
-static int use_cno = 0;
-static int recv_msg_index = 0;
-static int burst_msg_posted = 0;
-static int burst_msg_index = 0;
-static int ucm = 0;
-static DAT_SOCK_ADDR6 remote;
-
-/* forward prototypes */
-const char *DT_RetToStr(DAT_RETURN ret_value);
-const char *DT_EventToStr(DAT_EVENT_NUMBER event_code);
-void print_usage(void);
-double get_time(void);
-void init_data(void);
-
-DAT_RETURN send_msg(void *data,
-		    DAT_COUNT size,
-		    DAT_LMR_CONTEXT context,
-		    DAT_DTO_COOKIE cookie, DAT_COMPLETION_FLAGS flags);
-
-DAT_RETURN connect_ep(char *hostname, DAT_CONN_QUAL conn_id);
-void disconnect_ep(void);
-DAT_RETURN register_rdma_memory(void);
-DAT_RETURN unregister_rdma_memory(void);
-DAT_RETURN create_events(void);
-DAT_RETURN destroy_events(void);
-DAT_RETURN do_rdma_write_with_msg(void);
-DAT_RETURN do_rdma_read_with_msg(void);
-DAT_RETURN do_ping_pong_msg(void);
-
-#define LOGPRINTF if (verbose) printf
-
-void flush_evds(void)
-{
-	DAT_EVENT event;
-
-	/* Flush async error queue */
-	printf("%d ERR: Checking ASYNC EVD...\n", getpid());
-	while (dat_evd_dequeue(h_async_evd, &event) == DAT_SUCCESS) {
-		printf(" ASYNC EVD ENTRY: handle=%p reason=%d\n",
-			event.event_data.asynch_error_event_data.dat_handle,
-			event.event_data.asynch_error_event_data.reason);
-	}
-	/* Flush receive queue */
-	printf("%d ERR: Checking RECEIVE EVD...\n", getpid());
-	while (dat_evd_dequeue(h_dto_rcv_evd, &event) == DAT_SUCCESS) {
-		printf(" RCV EVD ENTRY: op=%d stat=%d ln=%d ck="F64x"\n",
-			event.event_data.dto_completion_event_data.operation,
-			event.event_data.dto_completion_event_data.status,
-			event.event_data.dto_completion_event_data.transfered_length,
-			event.event_data.dto_completion_event_data.user_cookie.as_64);
-	}
-	/* Flush request queue */
-	printf("%d ERR: Checking REQUEST EVD...\n", getpid());
-	while (dat_evd_dequeue(h_dto_req_evd, &event) == DAT_SUCCESS) {
-		printf(" REQ EVD ENTRY: op=%d stat=%d ln=%d ck="F64x"\n",
-			event.event_data.dto_completion_event_data.operation,
-			event.event_data.dto_completion_event_data.status,
-			event.event_data.dto_completion_event_data.transfered_length,
-			event.event_data.dto_completion_event_data.user_cookie.as_64);
-	}
-}
-
-
-static inline DAT_RETURN
-collect_event(DAT_EVD_HANDLE dto_evd,
-	      DAT_EVENT *event,
-	      DAT_TIMEOUT timeout,
-	      int *counter)
-{
-	DAT_EVD_HANDLE	evd = DAT_HANDLE_NULL;
-	DAT_COUNT	nmore;
-	DAT_RETURN	ret = DAT_SUCCESS;
-
-	if (use_cno) {
-retry:
-		/* CNO wait could return EVD's in any order and
-		 * may drop some EVD notification's if already
-		 * triggered. Once woken, simply dequeue the 
-		 * Evd the caller wants to collect and return.
-		 * If notification without EVD, retry.
-		 */
-		ret = dat_cno_wait(h_dto_cno, CNO_TIMEOUT, &evd);
-		if (dat_evd_dequeue(dto_evd, event) != DAT_SUCCESS) {
-			if (ret == DAT_SUCCESS)
-				printf(" WARNING: CNO notification:"
-				       " without EVD?\n");
-			goto retry;
-		}
-		ret = DAT_SUCCESS; /* cno timed out, but EVD dequeued */
-		
-	} else if (!polling) {
-
-		/* use wait to dequeue */
-		ret = dat_evd_wait(dto_evd, timeout, 1, event, &nmore);
-		if (ret != DAT_SUCCESS)
-			fprintf(stderr,
-				"Error waiting on h_dto_evd %p: %s\n",
-				dto_evd, DT_RetToStr(ret));
-		
-	} else {
-		while (dat_evd_dequeue(dto_evd, event) == DAT_QUEUE_EMPTY)
-			if (counter)
-				(*counter)++;
-	}
-	return (ret);
-}
-
-static void print_ia_address(struct sockaddr *sa)
-{
-	char str[INET6_ADDRSTRLEN] = {" ??? "};
-
-	switch(sa->sa_family) {
-	case AF_INET:
-		inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, str, INET6_ADDRSTRLEN);
-		printf("%d Local Address AF_INET - %s port %d\n", getpid(), str, SERVER_CONN_QUAL);
-		break;
-	case AF_INET6:
-		inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, str, INET6_ADDRSTRLEN);
-		printf("%d Local Address AF_INET6 - %s flowinfo(QPN)=0x%x, port(LID)=0x%x\n",
-			getpid(), str, 
-			ntohl(((struct sockaddr_in6 *)sa)->sin6_flowinfo),
-			ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
-		break;
-	default:
-		printf("%d Local Address UNKOWN FAMILY - port %d\n", getpid(), SERVER_CONN_QUAL);
-	}
-}
-
-int main(int argc, char **argv)
-{
-	int i, c;
-	DAT_RETURN ret;
-	DAT_EP_PARAM ep_param;
-	DAT_IA_ATTR ia_attr;
-
-	/* parse arguments */
-	while ((c = getopt(argc, argv, "tscvpq:l:b:d:B:h:P:")) != -1) {
-		switch (c) {
-		case 't':
-			performance_times = 1;
-			fflush(stdout);
-			break;
-		case 's':
-			server = 1;
-			fflush(stdout);
-			break;
-		case 'c':
-			use_cno = 1;
-			printf("%d Creating CNO for DTO EVD's\n", getpid());
-			fflush(stdout);
-			break;
-		case 'v':
-			verbose = 1;
-			printf("%d Verbose\n", getpid());
-			fflush(stdout);
-			break;
-		case 'p':
-			polling = 1;
-			printf("%d Polling\n", getpid());
-			fflush(stdout);
-			break;
-		case 'q':
-			/* map UCM qpn into AF_INET6 sin6_flowinfo */
-			remote.sin6_family = AF_INET6;
-			remote.sin6_flowinfo = htonl(strtol(optarg,NULL,0));
-			ucm = 1;
-			server = 0;
-			break;
-		case 'l':
-			/* map UCM lid into AF_INET6 sin6_port */
-			remote.sin6_family = AF_INET6;
-			remote.sin6_port = htons(strtol(optarg,NULL,0));
-			ucm = 1;
-			server = 0;
-			break;
-		case 'B':
-			burst = atoi(optarg);
-			break;
-		case 'd':
-			delay = atoi(optarg);
-			break;
-		case 'b':
-			buf_len = atoi(optarg);
-			break;
-		case 'h':
-			server = 0;
-			strcpy(hostname, optarg);
-			break;
-		case 'P':
-			strcpy(provider, optarg);
-			break;
-		default:
-			print_usage();
-			exit(-12);
-		}
-	}
-
-#if defined(_WIN32) || defined(_WIN64)
-	{
-		WSADATA wsaData;
-
-		i = WSAStartup(MAKEWORD(2, 2), &wsaData);
-		if (i != 0) {
-			printf("%s WSAStartup(2.2) failed? (0x%x)\n", argv[0],
-			       i);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-#endif
-
-	if (!server) {
-		printf("%d Running as client - %s\n", getpid(), provider);
-	} else {
-		printf("%d Running as server - %s\n", getpid(), provider);
-	}
-	fflush(stdout);
-
-	/* allocate send and receive buffers */
-	if (((rbuf = malloc(buf_len * (burst+1))) == NULL) ||
-	    ((sbuf = malloc(buf_len * (burst+1))) == NULL)) {
-		perror("malloc");
-		exit(1);
-	}
-	memset(&ts, 0, sizeof(struct dt_time));
-	LOGPRINTF("%d Allocated RDMA buffers (r:%p,s:%p) len %d \n",
-		  getpid(), rbuf, sbuf, buf_len);
-
-	/* dat_ia_open, dat_pz_create */
-	h_async_evd = DAT_HANDLE_NULL;
-	start = get_time();
-	ret = dat_ia_open(provider, 8, &h_async_evd, &h_ia);
-	stop = get_time();
-	ts.open += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d: Error Adaptor open: %s\n",
-			getpid(), DT_RetToStr(ret));
-		exit(1);
-	} else
-		LOGPRINTF("%d Opened Interface Adaptor\n", getpid());
-
-	ret = dat_ia_query(h_ia, 0, DAT_IA_FIELD_ALL, &ia_attr, 0, 0);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d: Error Adaptor query: %s\n",
-			getpid(), DT_RetToStr(ret));
-		exit(1);
-	}
-	print_ia_address(ia_attr.ia_address_ptr);
-
-	/* Create Protection Zone */
-	start = get_time();
-	LOGPRINTF("%d Create Protection Zone\n", getpid());
-	ret = dat_pz_create(h_ia, &h_pz);
-	stop = get_time();
-	ts.pzc += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error creating Protection Zone: %s\n",
-			getpid(), DT_RetToStr(ret));
-		exit(1);
-	} else
-		LOGPRINTF("%d Created Protection Zone\n", getpid());
-
-	/* Register memory */
-	LOGPRINTF("%d Register RDMA memory\n", getpid());
-	ret = register_rdma_memory();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error registering RDMA memory: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d Register RDMA memory done\n", getpid());
-
-	LOGPRINTF("%d Create events\n", getpid());
-	ret = create_events();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error creating events: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else {
-		LOGPRINTF("%d Create events done\n", getpid());
-	}
-
-	/* create EP */
-	memset(&ep_attr, 0, sizeof(ep_attr));
-	ep_attr.service_type = DAT_SERVICE_TYPE_RC;
-	ep_attr.max_rdma_size = 0x10000;
-	ep_attr.qos = 0;
-	ep_attr.recv_completion_flags = 0;
-	ep_attr.max_recv_dtos = MSG_BUF_COUNT + (burst * 3);
-	ep_attr.max_request_dtos = MSG_BUF_COUNT + (burst * 3) + MAX_RDMA_RD;
-	ep_attr.max_recv_iov = MSG_IOV_COUNT;
-	ep_attr.max_request_iov = MSG_IOV_COUNT;
-	ep_attr.max_rdma_read_in = MAX_RDMA_RD;
-	ep_attr.max_rdma_read_out = MAX_RDMA_RD;
-	ep_attr.request_completion_flags = DAT_COMPLETION_DEFAULT_FLAG;
-	ep_attr.ep_transport_specific_count = 0;
-	ep_attr.ep_transport_specific = NULL;
-	ep_attr.ep_provider_specific_count = 0;
-	ep_attr.ep_provider_specific = NULL;
-
-	start = get_time();
-	ret = dat_ep_create(h_ia, h_pz, h_dto_rcv_evd,
-			    h_dto_req_evd, h_conn_evd, &ep_attr, &h_ep);
-	stop = get_time();
-	ts.epc += ((stop - start) * 1.0e6);
-	ts.total += ts.epc;
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_ep_create: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d EP created %p \n", getpid(), h_ep);
-
-	/*
-	 * register message buffers, establish connection, and
-	 * exchange DMA RMR information info via messages
-	 */
-	ret = connect_ep(hostname, SERVER_CONN_QUAL);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error connect_ep: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d connect_ep complete\n", getpid());
-
-	/* Query EP for local and remote address information, print */
-	ret = dat_ep_query(h_ep, DAT_EP_FIELD_ALL, &ep_param);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_ep_query: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d EP queried %p \n", getpid(), h_ep);
-#if defined(_WIN32)
-	printf("\n%d Query EP: LOCAL addr %s port %lld\n", getpid(),
-	       inet_ntoa(((struct sockaddr_in *)
-			  ep_param.local_ia_address_ptr)->sin_addr),
-	       (ep_param.local_port_qual));
-#else
-	inet_ntop(AF_INET,
-		  &((struct sockaddr_in *)ep_param.local_ia_address_ptr)->
-		  sin_addr, addr_str, sizeof(addr_str));
-	printf("\n%d Query EP: LOCAL addr %s port " F64x "\n", getpid(),
-	       addr_str, (ep_param.local_port_qual));
-#endif
-#if defined(_WIN32)
-	printf("%d Query EP: REMOTE addr %s port %lld\n", getpid(),
-	       inet_ntoa(((struct sockaddr_in *)
-			  ep_param.local_ia_address_ptr)->sin_addr),
-	       (ep_param.remote_port_qual));
-#else
-	inet_ntop(AF_INET,
-		  &((struct sockaddr_in *)ep_param.remote_ia_address_ptr)->
-		  sin_addr, addr_str, sizeof(addr_str));
-	printf("%d Query EP: REMOTE addr %s port " F64x "\n", getpid(),
-	       addr_str, (ep_param.remote_port_qual));
-#endif
-	fflush(stdout);
-
-#if CONNECT_ONLY
-#if defined(_WIN32) || defined(_WIN64)
-	Sleep(1 * 1000);
-#else
-	sleep(1);
-#endif
-	goto cleanup;
-#endif
-
-	/*********** RDMA write data *************/
-	ret = do_rdma_write_with_msg();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error do_rdma_write_with_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d do_rdma_write_with_msg complete\n", getpid());
-
-	/*********** RDMA read data *************/
-	ret = do_rdma_read_with_msg();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error do_rdma_read_with_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF("%d do_rdma_read_with_msg complete\n", getpid());
-
-	/*********** PING PING messages ************/
-	ret = do_ping_pong_msg();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error do_ping_pong_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		goto cleanup;
-	} else {
-		LOGPRINTF("%d do_ping_pong_msg complete\n", getpid());
-		goto complete;
-	}
-
-cleanup:
-	flush_evds();
-	failed++;
-complete:
-
-	/* disconnect and free EP resources */
-	if (h_ep != DAT_HANDLE_NULL) {
-		/* unregister message buffers and tear down connection */
-		LOGPRINTF("%d Disconnect and Free EP %p \n", getpid(), h_ep);
-		disconnect_ep();
-
-		/* free EP */
-		LOGPRINTF("%d Free EP %p \n", getpid(), h_ep);
-		start = get_time();
-		ret = dat_ep_free(h_ep);
-		stop = get_time();
-		ts.epf += ((stop - start) * 1.0e6);
-		ts.total += ts.epf;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing EP: %s\n",
-				getpid(), DT_RetToStr(ret));
-		} else {
-			LOGPRINTF("%d Freed EP\n", getpid());
-			h_ep = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free EVDs */
-	LOGPRINTF("%d destroy events\n", getpid());
-	ret = destroy_events();
-	if (ret != DAT_SUCCESS)
-		fprintf(stderr, "%d Error destroy_events: %s\n",
-			getpid(), DT_RetToStr(ret));
-	else
-		LOGPRINTF("%d destroy events done\n", getpid());
-
-	ret = unregister_rdma_memory();
-	LOGPRINTF("%d unregister_rdma_memory \n", getpid());
-	if (ret != DAT_SUCCESS)
-		fprintf(stderr, "%d Error unregister_rdma_memory: %s\n",
-			getpid(), DT_RetToStr(ret));
-	else
-		LOGPRINTF("%d unregister_rdma_memory done\n", getpid());
-
-	/* Free protection domain */
-	LOGPRINTF("%d Freeing pz\n", getpid());
-	start = get_time();
-	ret = dat_pz_free(h_pz);
-	stop = get_time();
-	ts.pzf += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error freeing PZ: %s\n",
-			getpid(), DT_RetToStr(ret));
-	} else {
-		LOGPRINTF("%d Freed pz\n", getpid());
-		h_pz = NULL;
-	}
-
-	/* close the device */
-	LOGPRINTF("%d Closing Interface Adaptor\n", getpid());
-	start = get_time();
-	ret = dat_ia_close(h_ia, DAT_CLOSE_ABRUPT_FLAG);
-	stop = get_time();
-	ts.close += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d: Error Adaptor close: %s\n",
-			getpid(), DT_RetToStr(ret));
-	} else
-		LOGPRINTF("%d Closed Interface Adaptor\n", getpid());
-
-	/* free rdma buffers */
-	free(rbuf);
-	free(sbuf);
-
-	printf("\n%d: DAPL Test Complete. %s\n\n",
-	       getpid(), failed ? "FAILED" : "PASSED");
-
-	fflush(stderr);
-	fflush(stdout);
-
-	if (!performance_times)
-		exit(0);
-
-	printf("\n%d: DAPL Test Complete.\n\n", getpid());
-	printf("%d: Message RTT: Total=%10.2lf usec, %d bursts, itime=%10.2lf"
-	       " usec, pc=%d\n",
-	       getpid(), ts.rtt, burst, ts.rtt / burst, poll_count);
-	printf("%d: RDMA write:  Total=%10.2lf usec, %d bursts, itime=%10.2lf"
-	       " usec, pc=%d\n",
-	       getpid(), ts.rdma_wr, burst,
-	       ts.rdma_wr / burst, rdma_wr_poll_count);
-	for (i = 0; i < MAX_RDMA_RD; i++) {
-		printf("%d: RDMA read:   Total=%10.2lf usec,   %d bursts, "
-		       "itime=%10.2lf usec, pc=%d\n",
-		       getpid(), ts.rdma_rd_total, MAX_RDMA_RD,
-		       ts.rdma_rd[i], rdma_rd_poll_count[i]);
-	}
-	printf("%d: open:      %10.2lf usec\n", getpid(), ts.open);
-	printf("%d: close:     %10.2lf usec\n", getpid(), ts.close);
-	printf("%d: PZ create: %10.2lf usec\n", getpid(), ts.pzc);
-	printf("%d: PZ free:   %10.2lf usec\n", getpid(), ts.pzf);
-	printf("%d: LMR create:%10.2lf usec\n", getpid(), ts.reg);
-	printf("%d: LMR free:  %10.2lf usec\n", getpid(), ts.unreg);
-	printf("%d: EVD create:%10.2lf usec\n", getpid(), ts.evdc);
-	printf("%d: EVD free:  %10.2lf usec\n", getpid(), ts.evdf);
-	if (use_cno) {
-		printf("%d: CNO create:  %10.2lf usec\n", getpid(), ts.cnoc);
-		printf("%d: CNO free:    %10.2lf usec\n", getpid(), ts.cnof);
-	}
-	printf("%d: EP create: %10.2lf usec\n", getpid(), ts.epc);
-	printf("%d: EP free:   %10.2lf usec\n", getpid(), ts.epf);
-	if (!server)
-		printf("%d: connect:   %10.2lf usec, poll_cnt=%d\n", 
-		       getpid(), ts.conn, conn_poll_count);
-	printf("%d: TOTAL:     %10.2lf usec\n", getpid(), ts.total);
-
-#if defined(_WIN32) || defined(_WIN64)
-	WSACleanup();
-#endif
-	return (0);
-}
-
-double get_time(void)
-{
-	struct timeval tp;
-
-	gettimeofday(&tp, NULL);
-	return ((double)tp.tv_sec + (double)tp.tv_usec * 1e-6);
-}
-
-void init_data(void)
-{
-	memset(rbuf, 'a', buf_len);
-	memset(sbuf, 'b', buf_len);
-}
-
-DAT_RETURN
-send_msg(void *data,
-	 DAT_COUNT size,
-	 DAT_LMR_CONTEXT context,
-	 DAT_DTO_COOKIE cookie, DAT_COMPLETION_FLAGS flags)
-{
-	DAT_LMR_TRIPLET iov;
-	DAT_EVENT event;
-	DAT_RETURN ret;
-
-	iov.lmr_context = context;
-#if defined(_WIN32)
-	iov.virtual_address = (DAT_VADDR) data;
-#else
-	iov.virtual_address = (DAT_VADDR) (unsigned long)data;
-#endif
-	iov.segment_length = size;
-
-	LOGPRINTF("%d calling post_send\n", getpid());
-	cookie.as_64 = 0xaaaa;
-	ret = dat_ep_post_send(h_ep, 1, &iov, cookie, flags);
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d: ERROR: dat_ep_post_send() %s\n",
-			getpid(), DT_RetToStr(ret));
-		return ret;
-	}
-
-	if (!(flags & DAT_COMPLETION_SUPPRESS_FLAG)) {
-		
-		if (collect_event(h_dto_req_evd, 
-				  &event, 
-				  DTO_TIMEOUT, 
-				  &poll_count) != DAT_SUCCESS)
-			return (DAT_ABORT);
-
-		/* validate event number, len, cookie, and status */
-		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-			fprintf(stderr, "%d: ERROR: DTO event number %s\n",
-				getpid(), 
-				DT_EventToStr(event.event_number));
-			return (DAT_ABORT);
-		}
-
-		if ((event.event_data.dto_completion_event_data.
-		     transfered_length != size)
-		    || (event.event_data.dto_completion_event_data.user_cookie.
-			as_64 != 0xaaaa)) {
-			fprintf(stderr,
-				"%d: ERROR: DTO len %d or cookie " F64x " \n",
-				getpid(),
-				event.event_data.dto_completion_event_data.
-				transfered_length,
-				event.event_data.dto_completion_event_data.
-				user_cookie.as_64);
-			return (DAT_ABORT);
-
-		}
-		if (event.event_data.dto_completion_event_data.status !=
-		    DAT_SUCCESS) {
-			fprintf(stderr, "%d: ERROR: DTO event status %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (DAT_ABORT);
-		}
-	}
-
-	return DAT_SUCCESS;
-}
-
-DAT_RETURN connect_ep(char *hostname, DAT_CONN_QUAL conn_id)
-{
-	DAT_IA_ADDRESS_PTR remote_addr = (DAT_IA_ADDRESS_PTR)&remote;
-	DAT_RETURN ret;
-	DAT_REGION_DESCRIPTION region;
-	DAT_EVENT event;
-	DAT_COUNT nmore;
-	DAT_LMR_TRIPLET l_iov;
-	DAT_RMR_TRIPLET r_iov;
-	DAT_DTO_COOKIE cookie;
-	int i;
-	unsigned char *buf;
-	DAT_CR_PARAM cr_param = { 0 };
-	unsigned char pdata[48] = { 0 };
-
-	/* Register send message buffer */
-	LOGPRINTF("%d Registering send Message Buffer %p, len %d\n",
-		  getpid(), &rmr_send_msg, (int)sizeof(DAT_RMR_TRIPLET));
-	region.for_va = &rmr_send_msg;
-	ret = dat_lmr_create(h_ia,
-			     DAT_MEM_TYPE_VIRTUAL,
-			     region,
-			     sizeof(DAT_RMR_TRIPLET),
-			     h_pz,
-			     DAT_MEM_PRIV_LOCAL_WRITE_FLAG,
-			     DAT_VA_TYPE_VA,
-			     &h_lmr_send_msg,
-			     &lmr_context_send_msg,
-			     &rmr_context_send_msg,
-			     &registered_size_send_msg,
-			     &registered_addr_send_msg);
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error registering send msg buffer: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else
-		LOGPRINTF("%d Registered send Message Buffer %p \n",
-			  getpid(), region.for_va);
-
-	/* Register Receive buffers */
-	LOGPRINTF("%d Registering Receive Message Buffer %p\n",
-		  getpid(), rmr_recv_msg);
-	region.for_va = rmr_recv_msg;
-	ret = dat_lmr_create(h_ia,
-			     DAT_MEM_TYPE_VIRTUAL,
-			     region,
-			     sizeof(DAT_RMR_TRIPLET) * MSG_BUF_COUNT,
-			     h_pz,
-			     DAT_MEM_PRIV_LOCAL_WRITE_FLAG,
-			     DAT_VA_TYPE_VA,
-			     &h_lmr_recv_msg,
-			     &lmr_context_recv_msg,
-			     &rmr_context_recv_msg,
-			     &registered_size_recv_msg,
-			     &registered_addr_recv_msg);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error registering recv msg buffer: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else
-		LOGPRINTF("%d Registered Receive Message Buffer %p\n",
-			  getpid(), region.for_va);
-
-	for (i = 0; i < MSG_BUF_COUNT; i++) {
-		cookie.as_64 = i;
-		l_iov.lmr_context = lmr_context_recv_msg;
-#if defined(_WIN32)
-		l_iov.virtual_address = (DAT_VADDR) & rmr_recv_msg[i];
-#else
-		l_iov.virtual_address =
-		    (DAT_VADDR) (unsigned long)&rmr_recv_msg[i];
-#endif
-		l_iov.segment_length = sizeof(DAT_RMR_TRIPLET);
-
-		LOGPRINTF("%d Posting Receive Message Buffer %p\n",
-			  getpid(), &rmr_recv_msg[i]);
-		ret = dat_ep_post_recv(h_ep,
-				       1,
-				       &l_iov,
-				       cookie, DAT_COMPLETION_DEFAULT_FLAG);
-
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d Error registering recv msg buffer: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else
-			LOGPRINTF("%d Registered Receive Message Buffer %p\n",
-				  getpid(), region.for_va);
-
-	}
-
-	/* setup receive rdma buffer to initial string to be overwritten */
-	strcpy((char *)rbuf, "blah, blah, blah\n");
-
-	/* clear event structure */
-	memset(&event, 0, sizeof(DAT_EVENT));
-
-	if (server) {		/* SERVER */
-
-		/* create the service point for server listen */
-		LOGPRINTF("%d Creating service point for listen\n", getpid());
-		ret = dat_psp_create(h_ia,
-				     conn_id,
-				     h_cr_evd, DAT_PSP_CONSUMER_FLAG, &h_psp);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_psp_create: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else
-			LOGPRINTF("%d dat_psp_created for server listen\n",
-				  getpid());
-
-		printf("%d Server waiting for connect request on port " F64x
-		       "\n", getpid(), conn_id);
-
-		ret = dat_evd_wait(h_cr_evd, SERVER_TIMEOUT, 1, &event, &nmore);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_evd_wait: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else
-			LOGPRINTF("%d dat_evd_wait for cr_evd completed\n",
-				  getpid());
-
-		if (event.event_number != DAT_CONNECTION_REQUEST_EVENT) {
-			fprintf(stderr, "%d Error unexpected cr event : %s\n",
-				getpid(), 
-				DT_EventToStr(event.event_number));
-			return (DAT_ABORT);
-		}
-		if ((event.event_data.cr_arrival_event_data.conn_qual !=
-		     SERVER_CONN_QUAL)
-		    || (event.event_data.cr_arrival_event_data.sp_handle.
-			psp_handle != h_psp)) {
-			fprintf(stderr, "%d Error wrong cr event data : %s\n",
-				getpid(), 
-				DT_EventToStr(event.event_number));
-			return (DAT_ABORT);
-		}
-
-		/* use to test rdma_cma timeout logic */
-#if defined(_WIN32) || defined(_WIN64)
-		if (delay)
-			Sleep(delay * 1000);
-#else
-		if (delay)
-			sleep(delay);
-#endif
-
-		/* accept connect request from client */
-		h_cr = event.event_data.cr_arrival_event_data.cr_handle;
-		LOGPRINTF("%d Accepting connect request from client\n",
-			  getpid());
-
-		/* private data - check and send it back */
-		dat_cr_query(h_cr, DAT_CSP_FIELD_ALL, &cr_param);
-
-		buf = (unsigned char *)cr_param.private_data;
-		LOGPRINTF("%d CONN REQUEST Private Data %p[0]=%d [47]=%d\n",
-			  getpid(), buf, buf[0], buf[47]);
-		for (i = 0; i < 48; i++) {
-			if (buf[i] != i + 1) {
-				fprintf(stderr, "%d Error with CONNECT REQUEST"
-					" private data: %p[%d]=%d s/be %d\n",
-					getpid(), buf, i, buf[i], i + 1);
-				dat_cr_reject(h_cr, 0, NULL);
-				return (DAT_ABORT);
-			}
-			buf[i]++;	/* change for trip back */
-		}
-
-#ifdef TEST_REJECT_WITH_PRIVATE_DATA
-		printf("%d REJECT request with 48 bytes of private data\n",
-		       getpid());
-		ret = dat_cr_reject(h_cr, 48, cr_param.private_data);
-		printf("\n%d: DAPL Test Complete. %s\n\n",
-		       getpid(), ret ? "FAILED" : "PASSED");
-		exit(0);
-#endif
-
-		ret = dat_cr_accept(h_cr, h_ep, 48, cr_param.private_data);
-
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_cr_accept: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else
-			LOGPRINTF("%d dat_cr_accept completed\n", getpid());
-	} else {		/* CLIENT */
-		struct addrinfo *target;
-		int rval;
-
-		if (ucm)
-			goto no_resolution;
-
-#if defined(_WIN32) || defined(_WIN64)
-		if ((rval = getaddrinfo(hostname, "ftp", NULL, &target)) != 0) {
-			printf("\n remote name resolution failed! %s\n",
-			       gai_strerror(rval));
-			exit(1);
-		}
-		rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
-#else
-		if (getaddrinfo(hostname, NULL, NULL, &target) != 0) {
-			perror("\n remote name resolution failed!");
-			exit(1);
-		}
-		rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
-#endif
-		printf("%d Server Name: %s \n", getpid(), hostname);
-		printf("%d Server Net Address: %d.%d.%d.%d port " F64x "\n",
-		       getpid(), (rval >> 0) & 0xff, (rval >> 8) & 0xff,
-		       (rval >> 16) & 0xff, (rval >> 24) & 0xff, conn_id);
-
-		remote_addr = (DAT_IA_ADDRESS_PTR)target->ai_addr; /* IP */
-no_resolution:
-		for (i = 0; i < 48; i++)	/* simple pattern in private data */
-			pdata[i] = i + 1;
-
-		LOGPRINTF("%d Connecting to server\n", getpid());
-        	start = get_time();
-		ret = dat_ep_connect(h_ep,
-				     remote_addr,
-				     conn_id,
-				     CONN_TIMEOUT,
-				     48,
-				     (DAT_PVOID) pdata,
-				     0, DAT_CONNECT_DEFAULT_FLAG);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_ep_connect: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else
-			LOGPRINTF("%d dat_ep_connect completed\n", getpid());
-
-		if (!ucm)
-			freeaddrinfo(target);
-	}
-
-	printf("%d Waiting for connect response\n", getpid());
-
-	if (polling) 
-		while (DAT_GET_TYPE(dat_evd_dequeue(h_conn_evd, &event)) == 
-		       DAT_QUEUE_EMPTY)
-			conn_poll_count++;
-	else 
-		ret = dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 
-				   1, &event, &nmore);
-
-	if (!server) {
-        	stop = get_time();
-        	ts.conn += ((stop - start) * 1.0e6);
-	}
-
-#ifdef TEST_REJECT_WITH_PRIVATE_DATA
-	if (event.event_number != DAT_CONNECTION_EVENT_PEER_REJECTED) {
-		fprintf(stderr, "%d expected conn reject event : %s\n",
-			getpid(), DT_EventToStr(event.event_number));
-		return (DAT_ABORT);
-	}
-	/* get the reject private data and validate */
-	buf = (unsigned char *)event.event_data.connect_event_data.private_data;
-	printf("%d Received REJECT with private data %p[0]=%d [47]=%d\n",
-	       getpid(), buf, buf[0], buf[47]);
-	for (i = 0; i < 48; i++) {
-		if (buf[i] != i + 2) {
-			fprintf(stderr, "%d client: Error with REJECT event"
-				" private data: %p[%d]=%d s/be %d\n",
-				getpid(), buf, i, buf[i], i + 2);
-			dat_ep_disconnect(h_ep, DAT_CLOSE_ABRUPT_FLAG);
-			return (DAT_ABORT);
-		}
-	}
-	printf("\n%d: DAPL Test Complete. PASSED\n\n", getpid());
-	exit(0);
-#endif
-
-	if (event.event_number != DAT_CONNECTION_EVENT_ESTABLISHED) {
-		fprintf(stderr, "%d Error unexpected conn event : 0x%x %s\n",
-			getpid(), event.event_number,
-			DT_EventToStr(event.event_number));
-		return (DAT_ABORT);
-	}
-
-	/* check private data back from server  */
-	if (!server) {
-		buf =
-		    (unsigned char *)event.event_data.connect_event_data.
-		    private_data;
-		LOGPRINTF("%d CONN Private Data %p[0]=%d [47]=%d\n", getpid(),
-			  buf, buf[0], buf[47]);
-		for (i = 0; i < 48; i++) {
-			if (buf[i] != i + 2) {
-				fprintf(stderr, "%d Error with CONNECT event"
-					" private data: %p[%d]=%d s/be %d\n",
-					getpid(), buf, i, buf[i], i + 2);
-				dat_ep_disconnect(h_ep, DAT_CLOSE_ABRUPT_FLAG);
-				LOGPRINTF
-				    ("%d waiting for disconnect event...\n",
-				     getpid());
-				dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE,
-					     1, &event, &nmore);
-				return (DAT_ABORT);
-			}
-		}
-	}
-
-	printf("\n%d CONNECTED!\n\n", getpid());
-	connected = 1;
-
-#if CONNECT_ONLY
-	return 0;
-#endif
-
-	/*
-	 *  Setup our remote memory and tell the other side about it
-	 */
-	rmr_send_msg.virtual_address = htonll((DAT_VADDR) (uintptr_t) rbuf);
-	rmr_send_msg.segment_length = htonl(RDMA_BUFFER_SIZE);
-	rmr_send_msg.rmr_context = htonl(rmr_context_recv);
-
-	printf("%d Send RMR msg to remote: r_key_ctx=0x%x,va=%p,len=0x%x\n",
-	       getpid(), rmr_context_recv, rbuf, RDMA_BUFFER_SIZE);
-
-	ret = send_msg(&rmr_send_msg,
-		       sizeof(DAT_RMR_TRIPLET),
-		       lmr_context_send_msg,
-		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error send_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else
-		LOGPRINTF("%d send_msg completed\n", getpid());
-
-	/*
-	 *  Wait for remote RMR information for RDMA
-	 */
-	if (collect_event(h_dto_rcv_evd, 
-			  &event, 
-			  DTO_TIMEOUT, 
-			  &poll_count) != DAT_SUCCESS)
-		return (DAT_ABORT);
-	
-	printf("%d remote RMR data arrived!\n", getpid());
-
-	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
-			getpid(), DT_EventToStr(event.event_number));
-		return (DAT_ABORT);
-	}
-	if ((event.event_data.dto_completion_event_data.transfered_length !=
-	     sizeof(DAT_RMR_TRIPLET)) ||
-	    (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
-	     recv_msg_index)) {
-		fprintf(stderr,
-			"ERR recv event: len=%d cookie=" F64x
-			" expected %d/%d\n",
-			(int)event.event_data.dto_completion_event_data.
-			transfered_length,
-			event.event_data.dto_completion_event_data.user_cookie.
-			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
-		return (DAT_ABORT);
-	}
-
-	/* swap received RMR msg: network order to host order */
-	r_iov = rmr_recv_msg[recv_msg_index];
-	rmr_recv_msg[recv_msg_index].rmr_context = ntohl(r_iov.rmr_context);
-	rmr_recv_msg[recv_msg_index].virtual_address =
-	    ntohll(r_iov.virtual_address);
-	rmr_recv_msg[recv_msg_index].segment_length =
-	    ntohl(r_iov.segment_length);
-
-	printf("%d Received RMR from remote: "
-	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
-	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
-	       rmr_recv_msg[recv_msg_index].virtual_address,
-	       rmr_recv_msg[recv_msg_index].segment_length);
-
-	recv_msg_index++;
-
-	return (DAT_SUCCESS);
-}
-
-void disconnect_ep(void)
-{
-	DAT_RETURN ret;
-	DAT_EVENT event;
-	DAT_COUNT nmore;
-
-	if (connected) {
-
-		/* 
-		 * Only the client needs to call disconnect. The server _should_ be able
-		 * to just wait on the EVD associated with connection events for a
-		 * disconnect request and then exit.
-		 */
-		if (!server) {
-			LOGPRINTF("%d dat_ep_disconnect\n", getpid());
-			ret = dat_ep_disconnect(h_ep, DAT_CLOSE_DEFAULT);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr,
-					"%d Error dat_ep_disconnect: %s\n",
-					getpid(), DT_RetToStr(ret));
-			} else {
-				LOGPRINTF("%d dat_ep_disconnect completed\n",
-					  getpid());
-			}
-		} else {
-			LOGPRINTF("%d Server waiting for disconnect...\n",
-				  getpid());
-		}
-
-		ret =
-		    dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 1, &event,
-				 &nmore);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_evd_wait: %s\n",
-				getpid(), DT_RetToStr(ret));
-		} else {
-			LOGPRINTF("%d dat_evd_wait for h_conn_evd completed\n",
-				  getpid());
-		}
-	}
-
-	/* destroy service point */
-	if ((server) && (h_psp != DAT_HANDLE_NULL)) {
-		ret = dat_psp_free(h_psp);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_psp_free: %s\n",
-				getpid(), DT_RetToStr(ret));
-		} else {
-			LOGPRINTF("%d dat_psp_free completed\n", getpid());
-		}
-	}
-
-	/* Unregister Send message Buffer */
-	if (h_lmr_send_msg != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Unregister send message h_lmr %p \n", getpid(),
-			  h_lmr_send_msg);
-		ret = dat_lmr_free(h_lmr_send_msg);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d Error deregistering send msg mr: %s\n",
-				getpid(), DT_RetToStr(ret));
-		} else {
-			LOGPRINTF("%d Unregistered send message Buffer\n",
-				  getpid());
-			h_lmr_send_msg = NULL;
-		}
-	}
-
-	/* Unregister recv message Buffer */
-	if (h_lmr_recv_msg != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Unregister recv message h_lmr %p \n", getpid(),
-			  h_lmr_recv_msg);
-		ret = dat_lmr_free(h_lmr_recv_msg);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d Error deregistering recv msg mr: %s\n",
-				getpid(), DT_RetToStr(ret));
-		} else {
-			LOGPRINTF("%d Unregistered recv message Buffer\n",
-				  getpid());
-			h_lmr_recv_msg = NULL;
-		}
-	}
-	return;
-}
-
-DAT_RETURN do_rdma_write_with_msg(void)
-{
-	DAT_EVENT event;
-	DAT_LMR_TRIPLET l_iov[MSG_IOV_COUNT];
-	DAT_RMR_TRIPLET r_iov;
-	DAT_DTO_COOKIE cookie;
-	DAT_RETURN ret;
-	int i;
-
-	printf("\n %d RDMA WRITE DATA with SEND MSG\n\n", getpid());
-
-	cookie.as_64 = 0x5555;
-
-	if (recv_msg_index >= MSG_BUF_COUNT)
-		return (DAT_ABORT);
-
-	/* get RMR information from previously received message */
-	r_iov = rmr_recv_msg[recv_msg_index - 1];
-
-	if (server)
-		strcpy((char *)sbuf, "server RDMA write data...");
-	else
-		strcpy((char *)sbuf, "client RDMA write data...");
-
-	for (i = 0; i < MSG_IOV_COUNT; i++) {
-		l_iov[i].lmr_context = lmr_context_send;
-		l_iov[i].segment_length = buf_len / MSG_IOV_COUNT;
-		l_iov[i].virtual_address = (DAT_VADDR) (uintptr_t)
-		    (&sbuf[l_iov[i].segment_length * i]);
-
-		LOGPRINTF("%d rdma_write iov[%d] buf=%p,len=%d\n",
-			  getpid(), i, &sbuf[l_iov[i].segment_length * i],
-			  l_iov[i].segment_length);
-	}
-
-	start = get_time();
-	for (i = 0; i < burst; i++) {
-		cookie.as_64 = 0x9999;
-		ret = dat_ep_post_rdma_write(h_ep,	// ep_handle
-					     MSG_IOV_COUNT,	// num_segments
-					     l_iov,	// LMR
-					     cookie,	// user_cookie
-					     &r_iov,	// RMR
-					     DAT_COMPLETION_SUPPRESS_FLAG);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d: ERROR: dat_ep_post_rdma_write() %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (DAT_ABORT);
-		}
-		LOGPRINTF("%d rdma_write # %d completed\n", getpid(), i + 1);
-	}
-
-	/*
-	 *  Send RMR information a 2nd time to indicate completion
-	 *  NOTE: already swapped to network order in connect_ep
-	 */
-	printf("%d Sending RDMA WRITE completion message\n", getpid());
-
-	ret = send_msg(&rmr_send_msg,
-		       sizeof(DAT_RMR_TRIPLET),
-		       lmr_context_send_msg,
-		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error send_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d send_msg completed\n", getpid());
-	}
-
-	/* inbound recv event, send completion's suppressed */
-	if (collect_event(h_dto_rcv_evd, 
-			  &event, 
-			  DTO_TIMEOUT, 
-			  &rdma_wr_poll_count) != DAT_SUCCESS)
-		return (DAT_ABORT);
-	
-	stop = get_time();
-	ts.rdma_wr = ((stop - start) * 1.0e6);
-
-	/* validate event number and status */
-	printf("%d inbound rdma_write; send message arrived!\n", getpid());
-	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
-			getpid(), DT_EventToStr(event.event_number));
-		return (DAT_ABORT);
-	}
-
-	if ((event.event_data.dto_completion_event_data.transfered_length !=
-	     sizeof(DAT_RMR_TRIPLET))
-	    || (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
-		recv_msg_index)) {
-		fprintf(stderr,
-			"unexpected event data for receive: len=%d cookie=" F64x
-			" exp %d/%d\n",
-			(int)event.event_data.dto_completion_event_data.
-			transfered_length,
-			event.event_data.dto_completion_event_data.user_cookie.
-			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
-
-		return (DAT_ABORT);
-	}
-
-	/* swap received RMR msg: network order to host order */
-	r_iov = rmr_recv_msg[recv_msg_index];
-	rmr_recv_msg[recv_msg_index].virtual_address =
-	    ntohll(rmr_recv_msg[recv_msg_index].virtual_address);
-	rmr_recv_msg[recv_msg_index].segment_length =
-	    ntohl(rmr_recv_msg[recv_msg_index].segment_length);
-	rmr_recv_msg[recv_msg_index].rmr_context =
-	    ntohl(rmr_recv_msg[recv_msg_index].rmr_context);
-
-	printf("%d Received RMR from remote: "
-	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
-	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
-	       rmr_recv_msg[recv_msg_index].virtual_address,
-	       rmr_recv_msg[recv_msg_index].segment_length);
-
-	LOGPRINTF("%d inbound rdma_write; send msg event SUCCESS!!\n",
-		  getpid());
-
-	printf("%d %s RDMA write buffer contains: %s\n",
-	       getpid(), server ? "SERVER:" : "CLIENT:", rbuf);
-
-	recv_msg_index++;
-
-	return (DAT_SUCCESS);
-}
-
-DAT_RETURN do_rdma_read_with_msg(void)
-{
-	DAT_EVENT event;
-	DAT_LMR_TRIPLET l_iov;
-	DAT_RMR_TRIPLET r_iov;
-	DAT_DTO_COOKIE cookie;
-	DAT_RETURN ret;
-	int i;
-
-	printf("\n %d RDMA READ DATA with SEND MSG\n\n", getpid());
-
-	if (recv_msg_index >= MSG_BUF_COUNT)
-		return (DAT_ABORT);
-
-	/* get RMR information from previously received message */
-	r_iov = rmr_recv_msg[recv_msg_index - 1];
-
-	/* setup rdma read buffer to initial string to be overwritten */
-	strcpy((char *)sbuf, "blah, blah, blah\n");
-
-	if (server)
-		strcpy((char *)rbuf, "server RDMA read data...");
-	else
-		strcpy((char *)rbuf, "client RDMA read data...");
-
-	l_iov.lmr_context = lmr_context_send;
-	l_iov.virtual_address = (DAT_VADDR) (uintptr_t) sbuf;
-	l_iov.segment_length = buf_len;
-
-	for (i = 0; i < MAX_RDMA_RD; i++) {
-		cookie.as_64 = 0x9999;
-		start = get_time();
-		ret = dat_ep_post_rdma_read(h_ep,	// ep_handle
-					    1,	// num_segments
-					    &l_iov,	// LMR
-					    cookie,	// user_cookie
-					    &r_iov,	// RMR
-					    DAT_COMPLETION_DEFAULT_FLAG);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d: ERROR: dat_ep_post_rdma_read() %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (DAT_ABORT);
-		}
-
-		/* RDMA read completion event */
-		if (collect_event(h_dto_req_evd, 
-				  &event, 
-		 		  DTO_TIMEOUT, 
-				  &rdma_rd_poll_count[i]) != DAT_SUCCESS)
-			return (DAT_ABORT);
-
-		/* validate event number, len, cookie, and status */
-		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-			fprintf(stderr, "%d: ERROR: DTO event number %s\n",
-				getpid(), DT_EventToStr(event.event_number));
-			return (DAT_ABORT);
-		}
-		if ((event.event_data.dto_completion_event_data.
-		     transfered_length != buf_len)
-		    || (event.event_data.dto_completion_event_data.user_cookie.
-			as_64 != 0x9999)) {
-			fprintf(stderr,
-				"%d: ERROR: DTO len %d or cookie " F64x "\n",
-				getpid(),
-				event.event_data.dto_completion_event_data.
-				transfered_length,
-				event.event_data.dto_completion_event_data.
-				user_cookie.as_64);
-			return (DAT_ABORT);
-		}
-		if (event.event_data.dto_completion_event_data.status !=
-		    DAT_SUCCESS) {
-			fprintf(stderr, "%d: ERROR: DTO event status %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (DAT_ABORT);
-		}
-		stop = get_time();
-		ts.rdma_rd[i] = ((stop - start) * 1.0e6);
-		ts.rdma_rd_total += ts.rdma_rd[i];
-
-		LOGPRINTF("%d rdma_read # %d completed\n", getpid(), i + 1);
-	}
-
-	/*
-	 *  Send RMR information a 3rd time to indicate completion
-	 *  NOTE: already swapped to network order in connect_ep
-	 */
-	printf("%d Sending RDMA read completion message\n", getpid());
-
-	/* give remote chance to process read completes */
-	if (use_cno) {
-#if defined(_WIN32) || defined(_WIN64)
-		Sleep(1000);
-#else
-		sleep(1);
-#endif
-	}
-
-	ret = send_msg(&rmr_send_msg,
-		       sizeof(DAT_RMR_TRIPLET),
-		       lmr_context_send_msg,
-		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error send_msg: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d send_msg completed\n", getpid());
-	}
-
-	printf("%d Waiting for inbound message....\n", getpid());
-
-	if (collect_event(h_dto_rcv_evd, 
-			  &event, 
-		 	  DTO_TIMEOUT, 
-			  &poll_count) != DAT_SUCCESS)
-		return (DAT_ABORT);
-
-	/* validate event number and status */
-	printf("%d inbound rdma_read; send message arrived!\n", getpid());
-	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
-			getpid(), DT_EventToStr(event.event_number));
-		return (DAT_ABORT);
-	}
-
-	if ((event.event_data.dto_completion_event_data.transfered_length !=
-	     sizeof(DAT_RMR_TRIPLET))
-	    || (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
-		recv_msg_index)) {
-
-		fprintf(stderr,
-			"unexpected event data for receive: len=%d cookie=" F64x
-			" exp %d/%d\n",
-			(int)event.event_data.dto_completion_event_data.
-			transfered_length,
-			event.event_data.dto_completion_event_data.user_cookie.
-			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
-
-		return (DAT_ABORT);
-	}
-
-	/* swap received RMR msg: network order to host order */
-	r_iov = rmr_recv_msg[recv_msg_index];
-	rmr_recv_msg[recv_msg_index].virtual_address =
-	    ntohll(rmr_recv_msg[recv_msg_index].virtual_address);
-	rmr_recv_msg[recv_msg_index].segment_length =
-	    ntohl(rmr_recv_msg[recv_msg_index].segment_length);
-	rmr_recv_msg[recv_msg_index].rmr_context =
-	    ntohl(rmr_recv_msg[recv_msg_index].rmr_context);
-
-	printf("%d Received RMR from remote: "
-	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
-	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
-	       rmr_recv_msg[recv_msg_index].virtual_address,
-	       rmr_recv_msg[recv_msg_index].segment_length);
-
-	LOGPRINTF("%d inbound rdma_write; send msg event SUCCESS!!\n",
-		  getpid());
-
-	printf("%d %s RCV RDMA read buffer contains: %s\n",
-	       getpid(), server ? "SERVER:" : "CLIENT:", sbuf);
-
-	recv_msg_index++;
-
-	return (DAT_SUCCESS);
-}
-
-DAT_RETURN do_ping_pong_msg()
-{
-	DAT_EVENT event;
-	DAT_DTO_COOKIE cookie;
-	DAT_LMR_TRIPLET l_iov;
-	DAT_RETURN ret;
-	int i;
-	char *snd_buf;
-	char *rcv_buf;
-
-	printf("\n %d PING DATA with SEND MSG\n\n", getpid());
-
-	snd_buf = sbuf;
-	rcv_buf = rbuf;
-
-	/* pre-post all buffers */
-	for (i = 0; i < burst; i++) {
-		burst_msg_posted++;
-		cookie.as_64 = i;
-		l_iov.lmr_context = lmr_context_recv;
-		l_iov.virtual_address = (DAT_VADDR) (uintptr_t) rcv_buf;
-		l_iov.segment_length = buf_len;
-
-		LOGPRINTF("%d Pre-posting Receive Message Buffers %p\n",
-			  getpid(), rcv_buf);
-
-		ret = dat_ep_post_recv(h_ep,
-				       1,
-				       &l_iov,
-				       cookie, DAT_COMPLETION_DEFAULT_FLAG);
-
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr,
-				"%d Error posting recv msg buffer: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Posted Receive Message Buffer %p\n",
-				  getpid(), rcv_buf);
-		}
-
-		/* next buffer */
-		rcv_buf += buf_len;
-	}
-#if defined(_WIN32) || defined(_WIN64)
-	Sleep(1000);
-#else
-	sleep(1);
-#endif
-
-	/* Initialize recv_buf and index to beginning */
-	rcv_buf = rbuf;
-	burst_msg_index = 0;
-
-	/* client ping 0x55, server pong 0xAA in first byte */
-	start = get_time();
-	for (i = 0; i < burst; i++) {
-		/* walk the send and recv buffers */
-		if (!server) {
-			*snd_buf = 0x55;
-
-			LOGPRINTF("%d %s SND buffer %p contains: 0x%x len=%d\n",
-				  getpid(), server ? "SERVER:" : "CLIENT:",
-				  snd_buf, *snd_buf, buf_len);
-
-			ret = send_msg(snd_buf,
-				       buf_len,
-				       lmr_context_send,
-				       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
-
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, "%d Error send_msg: %s\n",
-					getpid(), DT_RetToStr(ret));
-				return (ret);
-			} else {
-				LOGPRINTF("%d send_msg completed\n", getpid());
-			}
-		}
-
-		/* recv message, send completions suppressed */
-		if (collect_event(h_dto_rcv_evd, 
-				  &event, 
-				  DTO_TIMEOUT, 
-				  &poll_count) != DAT_SUCCESS)
-			return (DAT_ABORT);
-
-		
-		/* start timer after first message arrives on server */
-		if (i == 0) {
-			start = get_time();
-		}
-		/* validate event number and status */
-		LOGPRINTF("%d inbound message; message arrived!\n", getpid());
-		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
-			fprintf(stderr, "%d Error unexpected DTO event : %s\n",
-				getpid(), DT_EventToStr(event.event_number));
-			return (DAT_ABORT);
-		}
-		if ((event.event_data.dto_completion_event_data.
-		     transfered_length != buf_len)
-		    || (event.event_data.dto_completion_event_data.user_cookie.
-			as_64 != burst_msg_index)) {
-			fprintf(stderr,
-				"ERR: recv event: len=%d cookie=" F64x
-				" exp %d/%d\n",
-				(int)event.event_data.dto_completion_event_data.
-				transfered_length,
-				event.event_data.dto_completion_event_data.
-				user_cookie.as_64, (int)buf_len,
-				(int)burst_msg_index);
-
-			return (DAT_ABORT);
-		}
-
-		LOGPRINTF("%d %s RCV buffer %p contains: 0x%x len=%d\n",
-			  getpid(), server ? "SERVER:" : "CLIENT:",
-			  rcv_buf, *rcv_buf, buf_len);
-
-		burst_msg_index++;
-
-		/* If server, change data and send it back to client */
-		if (server) {
-			*snd_buf = 0xaa;
-
-			LOGPRINTF("%d %s SND buffer %p contains: 0x%x len=%d\n",
-				  getpid(), server ? "SERVER:" : "CLIENT:",
-				  snd_buf, *snd_buf, buf_len);
-
-			ret = send_msg(snd_buf,
-				       buf_len,
-				       lmr_context_send,
-				       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
-
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, "%d Error send_msg: %s\n",
-					getpid(), DT_RetToStr(ret));
-				return (ret);
-			} else {
-				LOGPRINTF("%d send_msg completed\n", getpid());
-			}
-		}
-
-		/* next buffers */
-		rcv_buf += buf_len;
-		snd_buf += buf_len;
-	}
-	stop = get_time();
-	ts.rtt = ((stop - start) * 1.0e6);
-
-	return (DAT_SUCCESS);
-}
-
-/* Register RDMA Receive buffer */
-DAT_RETURN register_rdma_memory(void)
-{
-	DAT_RETURN ret;
-	DAT_REGION_DESCRIPTION region;
-
-	region.for_va = rbuf;
-	start = get_time();
-	ret = dat_lmr_create(h_ia,
-			     DAT_MEM_TYPE_VIRTUAL,
-			     region,
-			     buf_len * (burst+1),
-			     h_pz,
-			     DAT_MEM_PRIV_ALL_FLAG,
-			     DAT_VA_TYPE_VA,
-			     &h_lmr_recv,
-			     &lmr_context_recv,
-			     &rmr_context_recv,
-			     &registered_size_recv, &registered_addr_recv);
-	stop = get_time();
-	ts.reg += ((stop - start) * 1.0e6);
-	ts.total += ts.reg;
-
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr,
-			"%d Error registering Receive RDMA buffer: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d Registered Receive RDMA Buffer %p\n",
-			  getpid(), region.for_va);
-	}
-
-	/* Register RDMA Send buffer */
-	region.for_va = sbuf;
-	ret = dat_lmr_create(h_ia,
-			     DAT_MEM_TYPE_VIRTUAL,
-			     region,
-			     buf_len * (burst + 1),
-			     h_pz,
-			     DAT_MEM_PRIV_ALL_FLAG,
-			     DAT_VA_TYPE_VA,
-			     &h_lmr_send,
-			     &lmr_context_send,
-			     &rmr_context_send,
-			     &registered_size_send, &registered_addr_send);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error registering send RDMA buffer: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d Registered Send RDMA Buffer %p\n",
-			  getpid(), region.for_va);
-	}
-
-	return DAT_SUCCESS;
-}
-
-/*
- * Unregister RDMA memory
- */
-DAT_RETURN unregister_rdma_memory(void)
-{
-	DAT_RETURN ret;
-
-	/* Unregister Recv Buffer */
-	if (h_lmr_recv != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Unregister h_lmr %p \n", getpid(), h_lmr_recv);
-		start = get_time();
-		ret = dat_lmr_free(h_lmr_recv);
-		stop = get_time();
-		ts.unreg += ((stop - start) * 1.0e6);
-		ts.total += ts.unreg;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error deregistering recv mr: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Unregistered Recv Buffer\n", getpid());
-			h_lmr_recv = NULL;
-		}
-	}
-
-	/* Unregister Send Buffer */
-	if (h_lmr_send != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Unregister h_lmr %p \n", getpid(), h_lmr_send);
-		ret = dat_lmr_free(h_lmr_send);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error deregistering send mr: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Unregistered send Buffer\n", getpid());
-			h_lmr_send = NULL;
-		}
-	}
-	return DAT_SUCCESS;
-}
-
- /*
-  * Create CNO, CR, CONN, and DTO events
-  */
-DAT_RETURN create_events(void)
-{
-	DAT_RETURN ret;
-	DAT_EVD_PARAM param;
-
-	/* create CNO */
-	if (use_cno) {
-		start = get_time();
-#if defined(_WIN32) || defined(_WIN64)
-		{
-			DAT_OS_WAIT_PROXY_AGENT pa = { NULL, NULL };
-			ret = dat_cno_create(h_ia, pa, &h_dto_cno);
-		}
-#else
-		ret =
-		    dat_cno_create(h_ia, DAT_OS_WAIT_PROXY_AGENT_NULL,
-				   &h_dto_cno);
-#endif
-		stop = get_time();
-		ts.cnoc += ((stop - start) * 1.0e6);
-		ts.total += ts.cnoc;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error dat_cno_create: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d cr_evd created, %p\n", getpid(),
-				  h_dto_cno);
-		}
-	}
-
-	/* create cr EVD */
-	start = get_time();
-	ret =
-	    dat_evd_create(h_ia, 10, DAT_HANDLE_NULL, DAT_EVD_CR_FLAG,
-			   &h_cr_evd);
-	stop = get_time();
-	ts.evdc += ((stop - start) * 1.0e6);
-	ts.total += ts.evdc;
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_evd_create: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d cr_evd created %p\n", getpid(), h_cr_evd);
-	}
-
-	/* create conn EVD */
-	ret = dat_evd_create(h_ia,
-			     10,
-			     DAT_HANDLE_NULL,
-			     DAT_EVD_CONNECTION_FLAG, &h_conn_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_evd_create: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d con_evd created %p\n", getpid(), h_conn_evd);
-	}
-
-	/* create dto SND EVD, with CNO if use_cno was set */
-	ret = dat_evd_create(h_ia,
-			     (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2,
-			     h_dto_cno, DAT_EVD_DTO_FLAG, &h_dto_req_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_evd_create REQ: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d dto_req_evd created %p\n", getpid(),
-			  h_dto_req_evd);
-	}
-
-	/* create dto RCV EVD, with CNO if use_cno was set */
-	ret = dat_evd_create(h_ia,
-			     MSG_BUF_COUNT + burst,
-			     h_dto_cno, DAT_EVD_DTO_FLAG, &h_dto_rcv_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_evd_create RCV: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else {
-		LOGPRINTF("%d dto_rcv_evd created %p\n", getpid(),
-			  h_dto_rcv_evd);
-	}
-
-	/* query DTO req EVD and check size */
-	ret = dat_evd_query(h_dto_req_evd, DAT_EVD_FIELD_EVD_QLEN, &param);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d Error dat_evd_query request evd: %s\n",
-			getpid(), DT_RetToStr(ret));
-		return (ret);
-	} else if (param.evd_qlen < (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2) {
-		fprintf(stderr, "%d Error dat_evd qsize too small: %d < %d\n",
-			getpid(), param.evd_qlen,
-			(MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2);
-		return (ret);
-	}
-
-	LOGPRINTF("%d dto_req_evd QLEN - requested %d and actual %d\n",
-		  getpid(), (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2,
-		  param.evd_qlen);
-
-	return DAT_SUCCESS;
-}
-
-/*
- * Destroy CR, CONN, CNO, and DTO events
- */
-
-DAT_RETURN destroy_events(void)
-{
-	DAT_RETURN ret;
-
-	/* free cr EVD */
-	if (h_cr_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Free cr EVD %p \n", getpid(), h_cr_evd);
-		ret = dat_evd_free(h_cr_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing cr EVD: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Freed cr EVD\n", getpid());
-			h_cr_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free conn EVD */
-	if (h_conn_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Free conn EVD %p \n", getpid(), h_conn_evd);
-		ret = dat_evd_free(h_conn_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing conn EVD: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Freed conn EVD\n", getpid());
-			h_conn_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free RCV dto EVD */
-	if (h_dto_rcv_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Free RCV dto EVD %p \n", getpid(), h_dto_rcv_evd);
-		start = get_time();
-		ret = dat_evd_free(h_dto_rcv_evd);
-		stop = get_time();
-		ts.evdf += ((stop - start) * 1.0e6);
-		ts.total += ts.evdf;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing dto EVD: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Freed dto EVD\n", getpid());
-			h_dto_rcv_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free REQ dto EVD */
-	if (h_dto_req_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Free REQ dto EVD %p \n", getpid(), h_dto_req_evd);
-		ret = dat_evd_free(h_dto_req_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing dto EVD: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Freed dto EVD\n", getpid());
-			h_dto_req_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free CNO */
-	if (h_dto_cno != DAT_HANDLE_NULL) {
-		LOGPRINTF("%d Free dto CNO %p \n", getpid(), h_dto_cno);
-		start = get_time();
-		ret = dat_cno_free(h_dto_cno);
-		stop = get_time();
-		ts.cnof += ((stop - start) * 1.0e6);
-		ts.total += ts.cnof;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, "%d Error freeing dto CNO: %s\n",
-				getpid(), DT_RetToStr(ret));
-			return (ret);
-		} else {
-			LOGPRINTF("%d Freed dto CNO\n", getpid());
-			h_dto_cno = DAT_HANDLE_NULL;
-		}
-	}
-	return DAT_SUCCESS;
-}
-
-/*
- * Map DAT_RETURN values to readable strings,
- * but don't assume the values are zero-based or contiguous.
- */
-char errmsg[512] = { 0 };
-const char *DT_RetToStr(DAT_RETURN ret_value)
-{
-	const char *major_msg, *minor_msg;
-
-	dat_strerror(ret_value, &major_msg, &minor_msg);
-
-	strcpy(errmsg, major_msg);
-	strcat(errmsg, " ");
-	strcat(errmsg, minor_msg);
-
-	return errmsg;
-}
-
-/*
- * Map DAT_EVENT_CODE values to readable strings
- */
-const char *DT_EventToStr(DAT_EVENT_NUMBER event_code)
-{
-	unsigned int i;
-	static struct {
-		const char *name;
-		DAT_RETURN value;
-	} dat_events[] = {
-#   define DATxx(x) { # x, x }
-		DATxx(DAT_DTO_COMPLETION_EVENT),
-		    DATxx(DAT_RMR_BIND_COMPLETION_EVENT),
-		    DATxx(DAT_CONNECTION_REQUEST_EVENT),
-		    DATxx(DAT_CONNECTION_EVENT_ESTABLISHED),
-		    DATxx(DAT_CONNECTION_EVENT_PEER_REJECTED),
-		    DATxx(DAT_CONNECTION_EVENT_NON_PEER_REJECTED),
-		    DATxx(DAT_CONNECTION_EVENT_ACCEPT_COMPLETION_ERROR),
-		    DATxx(DAT_CONNECTION_EVENT_DISCONNECTED),
-		    DATxx(DAT_CONNECTION_EVENT_BROKEN),
-		    DATxx(DAT_CONNECTION_EVENT_TIMED_OUT),
-		    DATxx(DAT_CONNECTION_EVENT_UNREACHABLE),
-		    DATxx(DAT_ASYNC_ERROR_EVD_OVERFLOW),
-		    DATxx(DAT_ASYNC_ERROR_IA_CATASTROPHIC),
-		    DATxx(DAT_ASYNC_ERROR_EP_BROKEN),
-		    DATxx(DAT_ASYNC_ERROR_TIMED_OUT),
-		    DATxx(DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR),
-		    DATxx(DAT_SOFTWARE_EVENT)
-#   undef DATxx
-	};
-#   define NUM_EVENTS (sizeof(dat_events)/sizeof(dat_events[0]))
-
-	for (i = 0; i < NUM_EVENTS; i++) {
-		if (dat_events[i].value == event_code) {
-			return (dat_events[i].name);
-		}
-	}
-
-	return ("Invalid_DAT_EVENT_NUMBER");
-}
-
-void print_usage(void)
-{
-	printf("\n DAPL USAGE \n\n");
-	printf("s: server\n");
-	printf("t: performance times\n");
-	printf("c: use cno\n");
-	printf("v: verbose\n");
-	printf("p: polling\n");
-	printf("d: delay before accept\n");
-	printf("b: buf length to allocate\n");
-	printf("B: burst count, rdma and msgs \n");
-	printf("h: hostname/address of server, specified on client\n");
-	printf("P: provider name (default = OpenIB-cma)\n");
-	printf("l: server lid (required ucm provider)\n");
-	printf("q: server qpn (required ucm provider)\n");
-	printf("\n");
-}
-
+/*
+ * Copyright (c) 2005-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
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef DAPL_PROVIDER
+#undef DAPL_PROVIDER
+#endif
+
+#if defined(_WIN32) || defined(_WIN64)
+
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <io.h>
+#include <process.h>
+#include <complib/cl_types.h>
+#include "..\..\..\..\etc\user\getopt.c"
+
+#define getpid() ((int)GetCurrentProcessId())
+#define F64x "%I64x"
+
+#if DBG
+#define DAPL_PROVIDER "ibnic0v2d"
+#else
+#define DAPL_PROVIDER "ibnic0v2"
+#endif
+
+#define ntohll _byteswap_uint64
+#define htonll _byteswap_uint64
+
+#else // _WIN32 || _WIN64
+
+#include <endian.h>
+#include <byteswap.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <sys/mman.h>
+#include <getopt.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define DAPL_PROVIDER "ofa-v2-ib0"
+
+#define F64x "%"PRIx64""
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define htonll(x) (x)
+#define ntohll(x) (x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define htonll(x)  bswap_64(x)
+#define ntohll(x)  bswap_64(x)
+#endif
+
+#endif // _WIN32 || _WIN64
+
+/* Debug: 1 == connect & close only, otherwise full-meal deal */
+#define CONNECT_ONLY 0
+
+#define MAX_POLLING_CNT 50000
+#define MAX_RDMA_RD    4
+#define MAX_PROCS      1000
+
+/* Header files needed for DAT/uDAPL */
+#include "dat2/udat.h"
+
+/* definitions */
+#define SERVER_CONN_QUAL  45248
+#define DTO_TIMEOUT       (1000*1000*5)
+#define CNO_TIMEOUT       (1000*1000*1)
+#define DTO_FLUSH_TIMEOUT (1000*1000*2)
+#define CONN_TIMEOUT      (1000*1000*100)
+#define SERVER_TIMEOUT    DAT_TIMEOUT_INFINITE
+#define RDMA_BUFFER_SIZE  (64)
+
+/* Global DAT vars */
+static DAT_IA_HANDLE h_ia = DAT_HANDLE_NULL;
+static DAT_PZ_HANDLE h_pz = DAT_HANDLE_NULL;
+static DAT_EP_HANDLE h_ep = DAT_HANDLE_NULL;
+static DAT_PSP_HANDLE h_psp = DAT_HANDLE_NULL;
+static DAT_CR_HANDLE h_cr = DAT_HANDLE_NULL;
+
+static DAT_EVD_HANDLE h_async_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_dto_req_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_dto_rcv_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_cr_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_conn_evd = DAT_HANDLE_NULL;
+static DAT_CNO_HANDLE h_dto_cno = DAT_HANDLE_NULL;
+
+/* RDMA buffers */
+static DAT_LMR_HANDLE h_lmr_send = DAT_HANDLE_NULL;
+static DAT_LMR_HANDLE h_lmr_recv = DAT_HANDLE_NULL;
+static DAT_LMR_CONTEXT lmr_context_send;
+static DAT_LMR_CONTEXT lmr_context_recv;
+static DAT_RMR_CONTEXT rmr_context_send;
+static DAT_RMR_CONTEXT rmr_context_recv;
+static DAT_VLEN registered_size_send;
+static DAT_VLEN registered_size_recv;
+static DAT_VADDR registered_addr_send;
+static DAT_VADDR registered_addr_recv;
+
+/* Initial msg receive buf, RMR exchange, and Rdma-write notification */
+#define MSG_BUF_COUNT     3
+#define MSG_IOV_COUNT     2
+static DAT_RMR_TRIPLET rmr_recv_msg[MSG_BUF_COUNT];
+static DAT_LMR_HANDLE h_lmr_recv_msg = DAT_HANDLE_NULL;
+static DAT_LMR_CONTEXT lmr_context_recv_msg;
+static DAT_RMR_CONTEXT rmr_context_recv_msg;
+static DAT_VLEN registered_size_recv_msg;
+static DAT_VADDR registered_addr_recv_msg;
+
+/* message send buffer */
+static DAT_RMR_TRIPLET rmr_send_msg;
+static DAT_LMR_HANDLE h_lmr_send_msg = DAT_HANDLE_NULL;
+static DAT_LMR_CONTEXT lmr_context_send_msg;
+static DAT_RMR_CONTEXT rmr_context_send_msg;
+static DAT_VLEN registered_size_send_msg;
+static DAT_VADDR registered_addr_send_msg;
+static DAT_EP_ATTR ep_attr;
+char hostname[256] = { 0 };
+char provider[64] = DAPL_PROVIDER;
+char addr_str[INET_ADDRSTRLEN];
+
+/* rdma pointers */
+char *rbuf = NULL;
+char *sbuf = NULL;
+int status;
+
+/* timers */
+double start, stop, total_us, total_sec;
+
+struct dt_time {
+	double total;
+	double open;
+	double reg;
+	double unreg;
+	double pzc;
+	double pzf;
+	double evdc;
+	double evdf;
+	double cnoc;
+	double cnof;
+	double epc;
+	double epf;
+	double rdma_wr;
+	double rdma_rd[MAX_RDMA_RD];
+	double rdma_rd_total;
+	double rtt;
+	double close;
+	double conn;
+};
+
+struct dt_time ts;
+
+/* defaults */
+static int failed = 0;
+static int performance_times = 0;
+static int connected = 0;
+static int burst = 10;
+static int server = 1;
+static int verbose = 0;
+static int polling = 0;
+static int poll_count = 0;
+static int rdma_wr_poll_count = 0;
+static int conn_poll_count = 0;
+static int rdma_rd_poll_count[MAX_RDMA_RD] = { 0 };
+static int delay = 0;
+static int buf_len = RDMA_BUFFER_SIZE;
+static int use_cno = 0;
+static int recv_msg_index = 0;
+static int burst_msg_posted = 0;
+static int burst_msg_index = 0;
+static int ucm = 0;
+static DAT_SOCK_ADDR6 remote;
+
+/* forward prototypes */
+const char *DT_RetToStr(DAT_RETURN ret_value);
+const char *DT_EventToStr(DAT_EVENT_NUMBER event_code);
+void print_usage(void);
+double get_time(void);
+void init_data(void);
+
+DAT_RETURN send_msg(void *data,
+		    DAT_COUNT size,
+		    DAT_LMR_CONTEXT context,
+		    DAT_DTO_COOKIE cookie, DAT_COMPLETION_FLAGS flags);
+
+DAT_RETURN connect_ep(char *hostname, DAT_CONN_QUAL conn_id);
+void disconnect_ep(void);
+DAT_RETURN register_rdma_memory(void);
+DAT_RETURN unregister_rdma_memory(void);
+DAT_RETURN create_events(void);
+DAT_RETURN destroy_events(void);
+DAT_RETURN do_rdma_write_with_msg(void);
+DAT_RETURN do_rdma_read_with_msg(void);
+DAT_RETURN do_ping_pong_msg(void);
+
+#define LOGPRINTF if (verbose) printf
+
+void flush_evds(void)
+{
+	DAT_EVENT event;
+
+	/* Flush async error queue */
+	printf("%d ERR: Checking ASYNC EVD...\n", getpid());
+	while (dat_evd_dequeue(h_async_evd, &event) == DAT_SUCCESS) {
+		printf(" ASYNC EVD ENTRY: handle=%p reason=%d\n",
+			event.event_data.asynch_error_event_data.dat_handle,
+			event.event_data.asynch_error_event_data.reason);
+	}
+	/* Flush receive queue */
+	printf("%d ERR: Checking RECEIVE EVD...\n", getpid());
+	while (dat_evd_dequeue(h_dto_rcv_evd, &event) == DAT_SUCCESS) {
+		printf(" RCV EVD ENTRY: op=%d stat=%d ln=%d ck="F64x"\n",
+			event.event_data.dto_completion_event_data.operation,
+			event.event_data.dto_completion_event_data.status,
+			event.event_data.dto_completion_event_data.transfered_length,
+			event.event_data.dto_completion_event_data.user_cookie.as_64);
+	}
+	/* Flush request queue */
+	printf("%d ERR: Checking REQUEST EVD...\n", getpid());
+	while (dat_evd_dequeue(h_dto_req_evd, &event) == DAT_SUCCESS) {
+		printf(" REQ EVD ENTRY: op=%d stat=%d ln=%d ck="F64x"\n",
+			event.event_data.dto_completion_event_data.operation,
+			event.event_data.dto_completion_event_data.status,
+			event.event_data.dto_completion_event_data.transfered_length,
+			event.event_data.dto_completion_event_data.user_cookie.as_64);
+	}
+}
+
+
+static inline DAT_RETURN
+collect_event(DAT_EVD_HANDLE dto_evd,
+	      DAT_EVENT *event,
+	      DAT_TIMEOUT timeout,
+	      int *counter)
+{
+	DAT_EVD_HANDLE	evd = DAT_HANDLE_NULL;
+	DAT_COUNT	nmore;
+	DAT_RETURN	ret = DAT_SUCCESS;
+
+	if (use_cno) {
+retry:
+		/* CNO wait could return EVD's in any order and
+		 * may drop some EVD notification's if already
+		 * triggered. Once woken, simply dequeue the 
+		 * Evd the caller wants to collect and return.
+		 * If notification without EVD, retry.
+		 */
+		ret = dat_cno_wait(h_dto_cno, CNO_TIMEOUT, &evd);
+		if (dat_evd_dequeue(dto_evd, event) != DAT_SUCCESS) {
+			if (ret == DAT_SUCCESS)
+				printf(" WARNING: CNO notification:"
+				       " without EVD?\n");
+			goto retry;
+		}
+		ret = DAT_SUCCESS; /* cno timed out, but EVD dequeued */
+		
+	} else if (!polling) {
+
+		/* use wait to dequeue */
+		ret = dat_evd_wait(dto_evd, timeout, 1, event, &nmore);
+		if (ret != DAT_SUCCESS)
+			fprintf(stderr,
+				"Error waiting on h_dto_evd %p: %s\n",
+				dto_evd, DT_RetToStr(ret));
+		
+	} else {
+		while (dat_evd_dequeue(dto_evd, event) == DAT_QUEUE_EMPTY)
+			if (counter)
+				(*counter)++;
+	}
+	return (ret);
+}
+
+static void print_ia_address(struct sockaddr *sa)
+{
+	char str[INET6_ADDRSTRLEN] = {" ??? "};
+
+	switch(sa->sa_family) {
+	case AF_INET:
+		inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, str, INET6_ADDRSTRLEN);
+		printf("%d Local Address AF_INET - %s port %d\n", getpid(), str, SERVER_CONN_QUAL);
+		break;
+	case AF_INET6:
+		inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, str, INET6_ADDRSTRLEN);
+		printf("%d Local Address AF_INET6 - %s flowinfo(QPN)=0x%x, port(LID)=0x%x\n",
+			getpid(), str, 
+			ntohl(((struct sockaddr_in6 *)sa)->sin6_flowinfo),
+			ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
+		break;
+	default:
+		printf("%d Local Address UNKOWN FAMILY - port %d\n", getpid(), SERVER_CONN_QUAL);
+	}
+}
+
+int main(int argc, char **argv)
+{
+	int i, c;
+	DAT_RETURN ret;
+	DAT_EP_PARAM ep_param;
+	DAT_IA_ATTR ia_attr;
+
+	/* parse arguments */
+	while ((c = getopt(argc, argv, "tscvpq:l:b:d:B:h:P:")) != -1) {
+		switch (c) {
+		case 't':
+			performance_times = 1;
+			fflush(stdout);
+			break;
+		case 's':
+			server = 1;
+			fflush(stdout);
+			break;
+		case 'c':
+			use_cno = 1;
+			printf("%d Creating CNO for DTO EVD's\n", getpid());
+			fflush(stdout);
+			break;
+		case 'v':
+			verbose = 1;
+			printf("%d Verbose\n", getpid());
+			fflush(stdout);
+			break;
+		case 'p':
+			polling = 1;
+			printf("%d Polling\n", getpid());
+			fflush(stdout);
+			break;
+		case 'q':
+			/* map UCM qpn into AF_INET6 sin6_flowinfo */
+			remote.sin6_family = AF_INET6;
+			remote.sin6_flowinfo = htonl(strtol(optarg,NULL,0));
+			ucm = 1;
+			server = 0;
+			break;
+		case 'l':
+			/* map UCM lid into AF_INET6 sin6_port */
+			remote.sin6_family = AF_INET6;
+			remote.sin6_port = htons(strtol(optarg,NULL,0));
+			ucm = 1;
+			server = 0;
+			break;
+		case 'B':
+			burst = atoi(optarg);
+			break;
+		case 'd':
+			delay = atoi(optarg);
+			break;
+		case 'b':
+			buf_len = atoi(optarg);
+			break;
+		case 'h':
+			server = 0;
+			strcpy(hostname, optarg);
+			break;
+		case 'P':
+			strcpy(provider, optarg);
+			break;
+		default:
+			print_usage();
+			exit(-12);
+		}
+	}
+
+#if defined(_WIN32) || defined(_WIN64)
+	{
+		WSADATA wsaData;
+
+		i = WSAStartup(MAKEWORD(2, 2), &wsaData);
+		if (i != 0) {
+			printf("%s WSAStartup(2.2) failed? (0x%x)\n", argv[0],
+			       i);
+			fflush(stdout);
+			exit(1);
+		}
+	}
+#endif
+
+	if (!server) {
+		printf("%d Running as client - %s\n", getpid(), provider);
+	} else {
+		printf("%d Running as server - %s\n", getpid(), provider);
+	}
+	fflush(stdout);
+
+	/* allocate send and receive buffers */
+	if (((rbuf = malloc(buf_len * (burst+1))) == NULL) ||
+	    ((sbuf = malloc(buf_len * (burst+1))) == NULL)) {
+		perror("malloc");
+		exit(1);
+	}
+	memset(&ts, 0, sizeof(struct dt_time));
+	LOGPRINTF("%d Allocated RDMA buffers (r:%p,s:%p) len %d \n",
+		  getpid(), rbuf, sbuf, buf_len);
+
+	/* dat_ia_open, dat_pz_create */
+	h_async_evd = DAT_HANDLE_NULL;
+	start = get_time();
+	ret = dat_ia_open(provider, 8, &h_async_evd, &h_ia);
+	stop = get_time();
+	ts.open += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d: Error Adaptor open: %s\n",
+			getpid(), DT_RetToStr(ret));
+		exit(1);
+	} else
+		LOGPRINTF("%d Opened Interface Adaptor\n", getpid());
+
+	ret = dat_ia_query(h_ia, 0, DAT_IA_FIELD_ALL, &ia_attr, 0, 0);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d: Error Adaptor query: %s\n",
+			getpid(), DT_RetToStr(ret));
+		exit(1);
+	}
+	print_ia_address(ia_attr.ia_address_ptr);
+
+	/* Create Protection Zone */
+	start = get_time();
+	LOGPRINTF("%d Create Protection Zone\n", getpid());
+	ret = dat_pz_create(h_ia, &h_pz);
+	stop = get_time();
+	ts.pzc += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error creating Protection Zone: %s\n",
+			getpid(), DT_RetToStr(ret));
+		exit(1);
+	} else
+		LOGPRINTF("%d Created Protection Zone\n", getpid());
+
+	/* Register memory */
+	LOGPRINTF("%d Register RDMA memory\n", getpid());
+	ret = register_rdma_memory();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error registering RDMA memory: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d Register RDMA memory done\n", getpid());
+
+	LOGPRINTF("%d Create events\n", getpid());
+	ret = create_events();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error creating events: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else {
+		LOGPRINTF("%d Create events done\n", getpid());
+	}
+
+	/* create EP */
+	memset(&ep_attr, 0, sizeof(ep_attr));
+	ep_attr.service_type = DAT_SERVICE_TYPE_RC;
+	ep_attr.max_rdma_size = 0x10000;
+	ep_attr.qos = 0;
+	ep_attr.recv_completion_flags = 0;
+	ep_attr.max_recv_dtos = MSG_BUF_COUNT + (burst * 3);
+	ep_attr.max_request_dtos = MSG_BUF_COUNT + (burst * 3) + MAX_RDMA_RD;
+	ep_attr.max_recv_iov = MSG_IOV_COUNT;
+	ep_attr.max_request_iov = MSG_IOV_COUNT;
+	ep_attr.max_rdma_read_in = MAX_RDMA_RD;
+	ep_attr.max_rdma_read_out = MAX_RDMA_RD;
+	ep_attr.request_completion_flags = DAT_COMPLETION_DEFAULT_FLAG;
+	ep_attr.ep_transport_specific_count = 0;
+	ep_attr.ep_transport_specific = NULL;
+	ep_attr.ep_provider_specific_count = 0;
+	ep_attr.ep_provider_specific = NULL;
+
+	start = get_time();
+	ret = dat_ep_create(h_ia, h_pz, h_dto_rcv_evd,
+			    h_dto_req_evd, h_conn_evd, &ep_attr, &h_ep);
+	stop = get_time();
+	ts.epc += ((stop - start) * 1.0e6);
+	ts.total += ts.epc;
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_ep_create: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d EP created %p \n", getpid(), h_ep);
+
+	/*
+	 * register message buffers, establish connection, and
+	 * exchange DMA RMR information info via messages
+	 */
+	ret = connect_ep(hostname, SERVER_CONN_QUAL);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error connect_ep: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d connect_ep complete\n", getpid());
+
+	/* Query EP for local and remote address information, print */
+	ret = dat_ep_query(h_ep, DAT_EP_FIELD_ALL, &ep_param);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_ep_query: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d EP queried %p \n", getpid(), h_ep);
+#if defined(_WIN32)
+	printf("\n%d Query EP: LOCAL addr %s port %lld\n", getpid(),
+	       inet_ntoa(((struct sockaddr_in *)
+			  ep_param.local_ia_address_ptr)->sin_addr),
+	       (ep_param.local_port_qual));
+#else
+	inet_ntop(AF_INET,
+		  &((struct sockaddr_in *)ep_param.local_ia_address_ptr)->
+		  sin_addr, addr_str, sizeof(addr_str));
+	printf("\n%d Query EP: LOCAL addr %s port " F64x "\n", getpid(),
+	       addr_str, (ep_param.local_port_qual));
+#endif
+#if defined(_WIN32)
+	printf("%d Query EP: REMOTE addr %s port %lld\n", getpid(),
+	       inet_ntoa(((struct sockaddr_in *)
+			  ep_param.local_ia_address_ptr)->sin_addr),
+	       (ep_param.remote_port_qual));
+#else
+	inet_ntop(AF_INET,
+		  &((struct sockaddr_in *)ep_param.remote_ia_address_ptr)->
+		  sin_addr, addr_str, sizeof(addr_str));
+	printf("%d Query EP: REMOTE addr %s port " F64x "\n", getpid(),
+	       addr_str, (ep_param.remote_port_qual));
+#endif
+	fflush(stdout);
+
+#if CONNECT_ONLY
+#if defined(_WIN32) || defined(_WIN64)
+	Sleep(1 * 1000);
+#else
+	sleep(1);
+#endif
+	goto cleanup;
+#endif
+
+	/*********** RDMA write data *************/
+	ret = do_rdma_write_with_msg();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error do_rdma_write_with_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d do_rdma_write_with_msg complete\n", getpid());
+
+	/*********** RDMA read data *************/
+	ret = do_rdma_read_with_msg();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error do_rdma_read_with_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF("%d do_rdma_read_with_msg complete\n", getpid());
+
+	/*********** PING PING messages ************/
+	ret = do_ping_pong_msg();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error do_ping_pong_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		goto cleanup;
+	} else {
+		LOGPRINTF("%d do_ping_pong_msg complete\n", getpid());
+		goto complete;
+	}
+
+cleanup:
+	flush_evds();
+	failed++;
+complete:
+
+	/* disconnect and free EP resources */
+	if (h_ep != DAT_HANDLE_NULL) {
+		/* unregister message buffers and tear down connection */
+		LOGPRINTF("%d Disconnect and Free EP %p \n", getpid(), h_ep);
+		disconnect_ep();
+
+		/* free EP */
+		LOGPRINTF("%d Free EP %p \n", getpid(), h_ep);
+		start = get_time();
+		ret = dat_ep_free(h_ep);
+		stop = get_time();
+		ts.epf += ((stop - start) * 1.0e6);
+		ts.total += ts.epf;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing EP: %s\n",
+				getpid(), DT_RetToStr(ret));
+		} else {
+			LOGPRINTF("%d Freed EP\n", getpid());
+			h_ep = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free EVDs */
+	LOGPRINTF("%d destroy events\n", getpid());
+	ret = destroy_events();
+	if (ret != DAT_SUCCESS)
+		fprintf(stderr, "%d Error destroy_events: %s\n",
+			getpid(), DT_RetToStr(ret));
+	else
+		LOGPRINTF("%d destroy events done\n", getpid());
+
+	ret = unregister_rdma_memory();
+	LOGPRINTF("%d unregister_rdma_memory \n", getpid());
+	if (ret != DAT_SUCCESS)
+		fprintf(stderr, "%d Error unregister_rdma_memory: %s\n",
+			getpid(), DT_RetToStr(ret));
+	else
+		LOGPRINTF("%d unregister_rdma_memory done\n", getpid());
+
+	/* Free protection domain */
+	LOGPRINTF("%d Freeing pz\n", getpid());
+	start = get_time();
+	ret = dat_pz_free(h_pz);
+	stop = get_time();
+	ts.pzf += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error freeing PZ: %s\n",
+			getpid(), DT_RetToStr(ret));
+	} else {
+		LOGPRINTF("%d Freed pz\n", getpid());
+		h_pz = NULL;
+	}
+
+	/* close the device */
+	LOGPRINTF("%d Closing Interface Adaptor\n", getpid());
+	start = get_time();
+	ret = dat_ia_close(h_ia, DAT_CLOSE_ABRUPT_FLAG);
+	stop = get_time();
+	ts.close += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d: Error Adaptor close: %s\n",
+			getpid(), DT_RetToStr(ret));
+	} else
+		LOGPRINTF("%d Closed Interface Adaptor\n", getpid());
+
+	/* free rdma buffers */
+	free(rbuf);
+	free(sbuf);
+
+	printf("\n%d: DAPL Test Complete. %s\n\n",
+	       getpid(), failed ? "FAILED" : "PASSED");
+
+	fflush(stderr);
+	fflush(stdout);
+
+	if (!performance_times)
+		exit(0);
+
+	printf("\n%d: DAPL Test Complete.\n\n", getpid());
+	printf("%d: Message RTT: Total=%10.2lf usec, %d bursts, itime=%10.2lf"
+	       " usec, pc=%d\n",
+	       getpid(), ts.rtt, burst, ts.rtt / burst, poll_count);
+	printf("%d: RDMA write:  Total=%10.2lf usec, %d bursts, itime=%10.2lf"
+	       " usec, pc=%d\n",
+	       getpid(), ts.rdma_wr, burst,
+	       ts.rdma_wr / burst, rdma_wr_poll_count);
+	for (i = 0; i < MAX_RDMA_RD; i++) {
+		printf("%d: RDMA read:   Total=%10.2lf usec,   %d bursts, "
+		       "itime=%10.2lf usec, pc=%d\n",
+		       getpid(), ts.rdma_rd_total, MAX_RDMA_RD,
+		       ts.rdma_rd[i], rdma_rd_poll_count[i]);
+	}
+	printf("%d: open:      %10.2lf usec\n", getpid(), ts.open);
+	printf("%d: close:     %10.2lf usec\n", getpid(), ts.close);
+	printf("%d: PZ create: %10.2lf usec\n", getpid(), ts.pzc);
+	printf("%d: PZ free:   %10.2lf usec\n", getpid(), ts.pzf);
+	printf("%d: LMR create:%10.2lf usec\n", getpid(), ts.reg);
+	printf("%d: LMR free:  %10.2lf usec\n", getpid(), ts.unreg);
+	printf("%d: EVD create:%10.2lf usec\n", getpid(), ts.evdc);
+	printf("%d: EVD free:  %10.2lf usec\n", getpid(), ts.evdf);
+	if (use_cno) {
+		printf("%d: CNO create:  %10.2lf usec\n", getpid(), ts.cnoc);
+		printf("%d: CNO free:    %10.2lf usec\n", getpid(), ts.cnof);
+	}
+	printf("%d: EP create: %10.2lf usec\n", getpid(), ts.epc);
+	printf("%d: EP free:   %10.2lf usec\n", getpid(), ts.epf);
+	if (!server)
+		printf("%d: connect:   %10.2lf usec, poll_cnt=%d\n", 
+		       getpid(), ts.conn, conn_poll_count);
+	printf("%d: TOTAL:     %10.2lf usec\n", getpid(), ts.total);
+
+#if defined(_WIN32) || defined(_WIN64)
+	WSACleanup();
+#endif
+	return (0);
+}
+
+double get_time(void)
+{
+	struct timeval tp;
+
+	gettimeofday(&tp, NULL);
+	return ((double)tp.tv_sec + (double)tp.tv_usec * 1e-6);
+}
+
+void init_data(void)
+{
+	memset(rbuf, 'a', buf_len);
+	memset(sbuf, 'b', buf_len);
+}
+
+DAT_RETURN
+send_msg(void *data,
+	 DAT_COUNT size,
+	 DAT_LMR_CONTEXT context,
+	 DAT_DTO_COOKIE cookie, DAT_COMPLETION_FLAGS flags)
+{
+	DAT_LMR_TRIPLET iov;
+	DAT_EVENT event;
+	DAT_RETURN ret;
+
+	iov.lmr_context = context;
+#if defined(_WIN32)
+	iov.virtual_address = (DAT_VADDR) data;
+#else
+	iov.virtual_address = (DAT_VADDR) (unsigned long)data;
+#endif
+	iov.segment_length = size;
+
+	LOGPRINTF("%d calling post_send\n", getpid());
+	cookie.as_64 = 0xaaaa;
+	ret = dat_ep_post_send(h_ep, 1, &iov, cookie, flags);
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d: ERROR: dat_ep_post_send() %s\n",
+			getpid(), DT_RetToStr(ret));
+		return ret;
+	}
+
+	if (!(flags & DAT_COMPLETION_SUPPRESS_FLAG)) {
+		
+		if (collect_event(h_dto_req_evd, 
+				  &event, 
+				  DTO_TIMEOUT, 
+				  &poll_count) != DAT_SUCCESS)
+			return (DAT_ABORT);
+
+		/* validate event number, len, cookie, and status */
+		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+			fprintf(stderr, "%d: ERROR: DTO event number %s\n",
+				getpid(), 
+				DT_EventToStr(event.event_number));
+			return (DAT_ABORT);
+		}
+
+		if ((event.event_data.dto_completion_event_data.
+		     transfered_length != size)
+		    || (event.event_data.dto_completion_event_data.user_cookie.
+			as_64 != 0xaaaa)) {
+			fprintf(stderr,
+				"%d: ERROR: DTO len %d or cookie " F64x " \n",
+				getpid(),
+				event.event_data.dto_completion_event_data.
+				transfered_length,
+				event.event_data.dto_completion_event_data.
+				user_cookie.as_64);
+			return (DAT_ABORT);
+
+		}
+		if (event.event_data.dto_completion_event_data.status !=
+		    DAT_SUCCESS) {
+			fprintf(stderr, "%d: ERROR: DTO event status %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (DAT_ABORT);
+		}
+	}
+
+	return DAT_SUCCESS;
+}
+
+DAT_RETURN connect_ep(char *hostname, DAT_CONN_QUAL conn_id)
+{
+	DAT_IA_ADDRESS_PTR remote_addr = (DAT_IA_ADDRESS_PTR)&remote;
+	DAT_RETURN ret;
+	DAT_REGION_DESCRIPTION region;
+	DAT_EVENT event;
+	DAT_COUNT nmore;
+	DAT_LMR_TRIPLET l_iov;
+	DAT_RMR_TRIPLET r_iov;
+	DAT_DTO_COOKIE cookie;
+	int i;
+	unsigned char *buf;
+	DAT_CR_PARAM cr_param = { 0 };
+	unsigned char pdata[48] = { 0 };
+
+	/* Register send message buffer */
+	LOGPRINTF("%d Registering send Message Buffer %p, len %d\n",
+		  getpid(), &rmr_send_msg, (int)sizeof(DAT_RMR_TRIPLET));
+	region.for_va = &rmr_send_msg;
+	ret = dat_lmr_create(h_ia,
+			     DAT_MEM_TYPE_VIRTUAL,
+			     region,
+			     sizeof(DAT_RMR_TRIPLET),
+			     h_pz,
+			     DAT_MEM_PRIV_LOCAL_WRITE_FLAG,
+			     DAT_VA_TYPE_VA,
+			     &h_lmr_send_msg,
+			     &lmr_context_send_msg,
+			     &rmr_context_send_msg,
+			     &registered_size_send_msg,
+			     &registered_addr_send_msg);
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error registering send msg buffer: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else
+		LOGPRINTF("%d Registered send Message Buffer %p \n",
+			  getpid(), region.for_va);
+
+	/* Register Receive buffers */
+	LOGPRINTF("%d Registering Receive Message Buffer %p\n",
+		  getpid(), rmr_recv_msg);
+	region.for_va = rmr_recv_msg;
+	ret = dat_lmr_create(h_ia,
+			     DAT_MEM_TYPE_VIRTUAL,
+			     region,
+			     sizeof(DAT_RMR_TRIPLET) * MSG_BUF_COUNT,
+			     h_pz,
+			     DAT_MEM_PRIV_LOCAL_WRITE_FLAG,
+			     DAT_VA_TYPE_VA,
+			     &h_lmr_recv_msg,
+			     &lmr_context_recv_msg,
+			     &rmr_context_recv_msg,
+			     &registered_size_recv_msg,
+			     &registered_addr_recv_msg);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error registering recv msg buffer: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else
+		LOGPRINTF("%d Registered Receive Message Buffer %p\n",
+			  getpid(), region.for_va);
+
+	for (i = 0; i < MSG_BUF_COUNT; i++) {
+		cookie.as_64 = i;
+		l_iov.lmr_context = lmr_context_recv_msg;
+#if defined(_WIN32)
+		l_iov.virtual_address = (DAT_VADDR) & rmr_recv_msg[i];
+#else
+		l_iov.virtual_address =
+		    (DAT_VADDR) (unsigned long)&rmr_recv_msg[i];
+#endif
+		l_iov.segment_length = sizeof(DAT_RMR_TRIPLET);
+
+		LOGPRINTF("%d Posting Receive Message Buffer %p\n",
+			  getpid(), &rmr_recv_msg[i]);
+		ret = dat_ep_post_recv(h_ep,
+				       1,
+				       &l_iov,
+				       cookie, DAT_COMPLETION_DEFAULT_FLAG);
+
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d Error registering recv msg buffer: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else
+			LOGPRINTF("%d Registered Receive Message Buffer %p\n",
+				  getpid(), region.for_va);
+
+	}
+
+	/* setup receive rdma buffer to initial string to be overwritten */
+	strcpy((char *)rbuf, "blah, blah, blah\n");
+
+	/* clear event structure */
+	memset(&event, 0, sizeof(DAT_EVENT));
+
+	if (server) {		/* SERVER */
+
+		/* create the service point for server listen */
+		LOGPRINTF("%d Creating service point for listen\n", getpid());
+		ret = dat_psp_create(h_ia,
+				     conn_id,
+				     h_cr_evd, DAT_PSP_CONSUMER_FLAG, &h_psp);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_psp_create: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else
+			LOGPRINTF("%d dat_psp_created for server listen\n",
+				  getpid());
+
+		printf("%d Server waiting for connect request on port " F64x
+		       "\n", getpid(), conn_id);
+
+		ret = dat_evd_wait(h_cr_evd, SERVER_TIMEOUT, 1, &event, &nmore);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_evd_wait: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else
+			LOGPRINTF("%d dat_evd_wait for cr_evd completed\n",
+				  getpid());
+
+		if (event.event_number != DAT_CONNECTION_REQUEST_EVENT) {
+			fprintf(stderr, "%d Error unexpected cr event : %s\n",
+				getpid(), 
+				DT_EventToStr(event.event_number));
+			return (DAT_ABORT);
+		}
+		if ((event.event_data.cr_arrival_event_data.conn_qual !=
+		     SERVER_CONN_QUAL)
+		    || (event.event_data.cr_arrival_event_data.sp_handle.
+			psp_handle != h_psp)) {
+			fprintf(stderr, "%d Error wrong cr event data : %s\n",
+				getpid(), 
+				DT_EventToStr(event.event_number));
+			return (DAT_ABORT);
+		}
+
+		/* use to test rdma_cma timeout logic */
+#if defined(_WIN32) || defined(_WIN64)
+		if (delay)
+			Sleep(delay * 1000);
+#else
+		if (delay)
+			sleep(delay);
+#endif
+
+		/* accept connect request from client */
+		h_cr = event.event_data.cr_arrival_event_data.cr_handle;
+		LOGPRINTF("%d Accepting connect request from client\n",
+			  getpid());
+
+		/* private data - check and send it back */
+		dat_cr_query(h_cr, DAT_CSP_FIELD_ALL, &cr_param);
+
+		buf = (unsigned char *)cr_param.private_data;
+		LOGPRINTF("%d CONN REQUEST Private Data %p[0]=%d [47]=%d\n",
+			  getpid(), buf, buf[0], buf[47]);
+		for (i = 0; i < 48; i++) {
+			if (buf[i] != i + 1) {
+				fprintf(stderr, "%d Error with CONNECT REQUEST"
+					" private data: %p[%d]=%d s/be %d\n",
+					getpid(), buf, i, buf[i], i + 1);
+				dat_cr_reject(h_cr, 0, NULL);
+				return (DAT_ABORT);
+			}
+			buf[i]++;	/* change for trip back */
+		}
+
+#ifdef TEST_REJECT_WITH_PRIVATE_DATA
+		printf("%d REJECT request with 48 bytes of private data\n",
+		       getpid());
+		ret = dat_cr_reject(h_cr, 48, cr_param.private_data);
+		printf("\n%d: DAPL Test Complete. %s\n\n",
+		       getpid(), ret ? "FAILED" : "PASSED");
+		exit(0);
+#endif
+
+		ret = dat_cr_accept(h_cr, h_ep, 48, cr_param.private_data);
+
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_cr_accept: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else
+			LOGPRINTF("%d dat_cr_accept completed\n", getpid());
+	} else {		/* CLIENT */
+		struct addrinfo *target;
+		int rval;
+
+		if (ucm)
+			goto no_resolution;
+
+#if defined(_WIN32) || defined(_WIN64)
+		if ((rval = getaddrinfo(hostname, "ftp", NULL, &target)) != 0) {
+			printf("\n remote name resolution failed! %s\n",
+			       gai_strerror(rval));
+			exit(1);
+		}
+		rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
+#else
+		if (getaddrinfo(hostname, NULL, NULL, &target) != 0) {
+			perror("\n remote name resolution failed!");
+			exit(1);
+		}
+		rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
+#endif
+		printf("%d Server Name: %s \n", getpid(), hostname);
+		printf("%d Server Net Address: %d.%d.%d.%d port " F64x "\n",
+		       getpid(), (rval >> 0) & 0xff, (rval >> 8) & 0xff,
+		       (rval >> 16) & 0xff, (rval >> 24) & 0xff, conn_id);
+
+		remote_addr = (DAT_IA_ADDRESS_PTR)target->ai_addr; /* IP */
+no_resolution:
+		for (i = 0; i < 48; i++)	/* simple pattern in private data */
+			pdata[i] = i + 1;
+
+		LOGPRINTF("%d Connecting to server\n", getpid());
+        	start = get_time();
+		ret = dat_ep_connect(h_ep,
+				     remote_addr,
+				     conn_id,
+				     CONN_TIMEOUT,
+				     48,
+				     (DAT_PVOID) pdata,
+				     0, DAT_CONNECT_DEFAULT_FLAG);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_ep_connect: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else
+			LOGPRINTF("%d dat_ep_connect completed\n", getpid());
+
+		if (!ucm)
+			freeaddrinfo(target);
+	}
+
+	printf("%d Waiting for connect response\n", getpid());
+
+	if (polling) 
+		while (DAT_GET_TYPE(dat_evd_dequeue(h_conn_evd, &event)) == 
+		       DAT_QUEUE_EMPTY)
+			conn_poll_count++;
+	else 
+		ret = dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 
+				   1, &event, &nmore);
+
+	if (!server) {
+        	stop = get_time();
+        	ts.conn += ((stop - start) * 1.0e6);
+	}
+
+#ifdef TEST_REJECT_WITH_PRIVATE_DATA
+	if (event.event_number != DAT_CONNECTION_EVENT_PEER_REJECTED) {
+		fprintf(stderr, "%d expected conn reject event : %s\n",
+			getpid(), DT_EventToStr(event.event_number));
+		return (DAT_ABORT);
+	}
+	/* get the reject private data and validate */
+	buf = (unsigned char *)event.event_data.connect_event_data.private_data;
+	printf("%d Received REJECT with private data %p[0]=%d [47]=%d\n",
+	       getpid(), buf, buf[0], buf[47]);
+	for (i = 0; i < 48; i++) {
+		if (buf[i] != i + 2) {
+			fprintf(stderr, "%d client: Error with REJECT event"
+				" private data: %p[%d]=%d s/be %d\n",
+				getpid(), buf, i, buf[i], i + 2);
+			dat_ep_disconnect(h_ep, DAT_CLOSE_ABRUPT_FLAG);
+			return (DAT_ABORT);
+		}
+	}
+	printf("\n%d: DAPL Test Complete. PASSED\n\n", getpid());
+	exit(0);
+#endif
+
+	if (event.event_number != DAT_CONNECTION_EVENT_ESTABLISHED) {
+		fprintf(stderr, "%d Error unexpected conn event : 0x%x %s\n",
+			getpid(), event.event_number,
+			DT_EventToStr(event.event_number));
+		return (DAT_ABORT);
+	}
+
+	/* check private data back from server  */
+	if (!server) {
+		buf =
+		    (unsigned char *)event.event_data.connect_event_data.
+		    private_data;
+		LOGPRINTF("%d CONN Private Data %p[0]=%d [47]=%d\n", getpid(),
+			  buf, buf[0], buf[47]);
+		for (i = 0; i < 48; i++) {
+			if (buf[i] != i + 2) {
+				fprintf(stderr, "%d Error with CONNECT event"
+					" private data: %p[%d]=%d s/be %d\n",
+					getpid(), buf, i, buf[i], i + 2);
+				dat_ep_disconnect(h_ep, DAT_CLOSE_ABRUPT_FLAG);
+				LOGPRINTF
+				    ("%d waiting for disconnect event...\n",
+				     getpid());
+				dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE,
+					     1, &event, &nmore);
+				return (DAT_ABORT);
+			}
+		}
+	}
+
+	printf("\n%d CONNECTED!\n\n", getpid());
+	connected = 1;
+
+#if CONNECT_ONLY
+	return 0;
+#endif
+
+	/*
+	 *  Setup our remote memory and tell the other side about it
+	 */
+	rmr_send_msg.virtual_address = htonll((DAT_VADDR) (uintptr_t) rbuf);
+	rmr_send_msg.segment_length = htonl(RDMA_BUFFER_SIZE);
+	rmr_send_msg.rmr_context = htonl(rmr_context_recv);
+
+	printf("%d Send RMR msg to remote: r_key_ctx=0x%x,va=%p,len=0x%x\n",
+	       getpid(), rmr_context_recv, rbuf, RDMA_BUFFER_SIZE);
+
+	ret = send_msg(&rmr_send_msg,
+		       sizeof(DAT_RMR_TRIPLET),
+		       lmr_context_send_msg,
+		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error send_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else
+		LOGPRINTF("%d send_msg completed\n", getpid());
+
+	/*
+	 *  Wait for remote RMR information for RDMA
+	 */
+	if (collect_event(h_dto_rcv_evd, 
+			  &event, 
+			  DTO_TIMEOUT, 
+			  &poll_count) != DAT_SUCCESS)
+		return (DAT_ABORT);
+	
+	printf("%d remote RMR data arrived!\n", getpid());
+
+	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
+			getpid(), DT_EventToStr(event.event_number));
+		return (DAT_ABORT);
+	}
+	if ((event.event_data.dto_completion_event_data.transfered_length !=
+	     sizeof(DAT_RMR_TRIPLET)) ||
+	    (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
+	     recv_msg_index)) {
+		fprintf(stderr,
+			"ERR recv event: len=%d cookie=" F64x
+			" expected %d/%d\n",
+			(int)event.event_data.dto_completion_event_data.
+			transfered_length,
+			event.event_data.dto_completion_event_data.user_cookie.
+			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
+		return (DAT_ABORT);
+	}
+
+	/* swap received RMR msg: network order to host order */
+	r_iov = rmr_recv_msg[recv_msg_index];
+	rmr_recv_msg[recv_msg_index].rmr_context = ntohl(r_iov.rmr_context);
+	rmr_recv_msg[recv_msg_index].virtual_address =
+	    ntohll(r_iov.virtual_address);
+	rmr_recv_msg[recv_msg_index].segment_length =
+	    ntohl(r_iov.segment_length);
+
+	printf("%d Received RMR from remote: "
+	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
+	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
+	       rmr_recv_msg[recv_msg_index].virtual_address,
+	       rmr_recv_msg[recv_msg_index].segment_length);
+
+	recv_msg_index++;
+
+	return (DAT_SUCCESS);
+}
+
+void disconnect_ep(void)
+{
+	DAT_RETURN ret;
+	DAT_EVENT event;
+	DAT_COUNT nmore;
+
+	if (connected) {
+
+		/* 
+		 * Only the client needs to call disconnect. The server _should_ be able
+		 * to just wait on the EVD associated with connection events for a
+		 * disconnect request and then exit.
+		 */
+		if (!server) {
+			LOGPRINTF("%d dat_ep_disconnect\n", getpid());
+			ret = dat_ep_disconnect(h_ep, DAT_CLOSE_DEFAULT);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr,
+					"%d Error dat_ep_disconnect: %s\n",
+					getpid(), DT_RetToStr(ret));
+			} else {
+				LOGPRINTF("%d dat_ep_disconnect completed\n",
+					  getpid());
+			}
+		} else {
+			LOGPRINTF("%d Server waiting for disconnect...\n",
+				  getpid());
+		}
+
+		ret =
+		    dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 1, &event,
+				 &nmore);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_evd_wait: %s\n",
+				getpid(), DT_RetToStr(ret));
+		} else {
+			LOGPRINTF("%d dat_evd_wait for h_conn_evd completed\n",
+				  getpid());
+		}
+	}
+
+	/* destroy service point */
+	if ((server) && (h_psp != DAT_HANDLE_NULL)) {
+		ret = dat_psp_free(h_psp);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_psp_free: %s\n",
+				getpid(), DT_RetToStr(ret));
+		} else {
+			LOGPRINTF("%d dat_psp_free completed\n", getpid());
+		}
+	}
+
+	/* Unregister Send message Buffer */
+	if (h_lmr_send_msg != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Unregister send message h_lmr %p \n", getpid(),
+			  h_lmr_send_msg);
+		ret = dat_lmr_free(h_lmr_send_msg);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d Error deregistering send msg mr: %s\n",
+				getpid(), DT_RetToStr(ret));
+		} else {
+			LOGPRINTF("%d Unregistered send message Buffer\n",
+				  getpid());
+			h_lmr_send_msg = NULL;
+		}
+	}
+
+	/* Unregister recv message Buffer */
+	if (h_lmr_recv_msg != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Unregister recv message h_lmr %p \n", getpid(),
+			  h_lmr_recv_msg);
+		ret = dat_lmr_free(h_lmr_recv_msg);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d Error deregistering recv msg mr: %s\n",
+				getpid(), DT_RetToStr(ret));
+		} else {
+			LOGPRINTF("%d Unregistered recv message Buffer\n",
+				  getpid());
+			h_lmr_recv_msg = NULL;
+		}
+	}
+	return;
+}
+
+DAT_RETURN do_rdma_write_with_msg(void)
+{
+	DAT_EVENT event;
+	DAT_LMR_TRIPLET l_iov[MSG_IOV_COUNT];
+	DAT_RMR_TRIPLET r_iov;
+	DAT_DTO_COOKIE cookie;
+	DAT_RETURN ret;
+	int i;
+
+	printf("\n %d RDMA WRITE DATA with SEND MSG\n\n", getpid());
+
+	cookie.as_64 = 0x5555;
+
+	if (recv_msg_index >= MSG_BUF_COUNT)
+		return (DAT_ABORT);
+
+	/* get RMR information from previously received message */
+	r_iov = rmr_recv_msg[recv_msg_index - 1];
+
+	if (server)
+		strcpy((char *)sbuf, "server RDMA write data...");
+	else
+		strcpy((char *)sbuf, "client RDMA write data...");
+
+	for (i = 0; i < MSG_IOV_COUNT; i++) {
+		l_iov[i].lmr_context = lmr_context_send;
+		l_iov[i].segment_length = buf_len / MSG_IOV_COUNT;
+		l_iov[i].virtual_address = (DAT_VADDR) (uintptr_t)
+		    (&sbuf[l_iov[i].segment_length * i]);
+
+		LOGPRINTF("%d rdma_write iov[%d] buf=%p,len=%d\n",
+			  getpid(), i, &sbuf[l_iov[i].segment_length * i],
+			  l_iov[i].segment_length);
+	}
+
+	start = get_time();
+	for (i = 0; i < burst; i++) {
+		cookie.as_64 = 0x9999;
+		ret = dat_ep_post_rdma_write(h_ep,	// ep_handle
+					     MSG_IOV_COUNT,	// num_segments
+					     l_iov,	// LMR
+					     cookie,	// user_cookie
+					     &r_iov,	// RMR
+					     DAT_COMPLETION_SUPPRESS_FLAG);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d: ERROR: dat_ep_post_rdma_write() %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (DAT_ABORT);
+		}
+		LOGPRINTF("%d rdma_write # %d completed\n", getpid(), i + 1);
+	}
+
+	/*
+	 *  Send RMR information a 2nd time to indicate completion
+	 *  NOTE: already swapped to network order in connect_ep
+	 */
+	printf("%d Sending RDMA WRITE completion message\n", getpid());
+
+	ret = send_msg(&rmr_send_msg,
+		       sizeof(DAT_RMR_TRIPLET),
+		       lmr_context_send_msg,
+		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error send_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d send_msg completed\n", getpid());
+	}
+
+	/* inbound recv event, send completion's suppressed */
+	if (collect_event(h_dto_rcv_evd, 
+			  &event, 
+			  DTO_TIMEOUT, 
+			  &rdma_wr_poll_count) != DAT_SUCCESS)
+		return (DAT_ABORT);
+	
+	stop = get_time();
+	ts.rdma_wr = ((stop - start) * 1.0e6);
+
+	/* validate event number and status */
+	printf("%d inbound rdma_write; send message arrived!\n", getpid());
+	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
+			getpid(), DT_EventToStr(event.event_number));
+		return (DAT_ABORT);
+	}
+
+	if ((event.event_data.dto_completion_event_data.transfered_length !=
+	     sizeof(DAT_RMR_TRIPLET))
+	    || (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
+		recv_msg_index)) {
+		fprintf(stderr,
+			"unexpected event data for receive: len=%d cookie=" F64x
+			" exp %d/%d\n",
+			(int)event.event_data.dto_completion_event_data.
+			transfered_length,
+			event.event_data.dto_completion_event_data.user_cookie.
+			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
+
+		return (DAT_ABORT);
+	}
+
+	/* swap received RMR msg: network order to host order */
+	r_iov = rmr_recv_msg[recv_msg_index];
+	rmr_recv_msg[recv_msg_index].virtual_address =
+	    ntohll(rmr_recv_msg[recv_msg_index].virtual_address);
+	rmr_recv_msg[recv_msg_index].segment_length =
+	    ntohl(rmr_recv_msg[recv_msg_index].segment_length);
+	rmr_recv_msg[recv_msg_index].rmr_context =
+	    ntohl(rmr_recv_msg[recv_msg_index].rmr_context);
+
+	printf("%d Received RMR from remote: "
+	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
+	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
+	       rmr_recv_msg[recv_msg_index].virtual_address,
+	       rmr_recv_msg[recv_msg_index].segment_length);
+
+	LOGPRINTF("%d inbound rdma_write; send msg event SUCCESS!!\n",
+		  getpid());
+
+	printf("%d %s RDMA write buffer contains: %s\n",
+	       getpid(), server ? "SERVER:" : "CLIENT:", rbuf);
+
+	recv_msg_index++;
+
+	return (DAT_SUCCESS);
+}
+
+DAT_RETURN do_rdma_read_with_msg(void)
+{
+	DAT_EVENT event;
+	DAT_LMR_TRIPLET l_iov;
+	DAT_RMR_TRIPLET r_iov;
+	DAT_DTO_COOKIE cookie;
+	DAT_RETURN ret;
+	int i;
+
+	printf("\n %d RDMA READ DATA with SEND MSG\n\n", getpid());
+
+	if (recv_msg_index >= MSG_BUF_COUNT)
+		return (DAT_ABORT);
+
+	/* get RMR information from previously received message */
+	r_iov = rmr_recv_msg[recv_msg_index - 1];
+
+	/* setup rdma read buffer to initial string to be overwritten */
+	strcpy((char *)sbuf, "blah, blah, blah\n");
+
+	if (server)
+		strcpy((char *)rbuf, "server RDMA read data...");
+	else
+		strcpy((char *)rbuf, "client RDMA read data...");
+
+	l_iov.lmr_context = lmr_context_send;
+	l_iov.virtual_address = (DAT_VADDR) (uintptr_t) sbuf;
+	l_iov.segment_length = buf_len;
+
+	for (i = 0; i < MAX_RDMA_RD; i++) {
+		cookie.as_64 = 0x9999;
+		start = get_time();
+		ret = dat_ep_post_rdma_read(h_ep,	// ep_handle
+					    1,	// num_segments
+					    &l_iov,	// LMR
+					    cookie,	// user_cookie
+					    &r_iov,	// RMR
+					    DAT_COMPLETION_DEFAULT_FLAG);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d: ERROR: dat_ep_post_rdma_read() %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (DAT_ABORT);
+		}
+
+		/* RDMA read completion event */
+		if (collect_event(h_dto_req_evd, 
+				  &event, 
+		 		  DTO_TIMEOUT, 
+				  &rdma_rd_poll_count[i]) != DAT_SUCCESS)
+			return (DAT_ABORT);
+
+		/* validate event number, len, cookie, and status */
+		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+			fprintf(stderr, "%d: ERROR: DTO event number %s\n",
+				getpid(), DT_EventToStr(event.event_number));
+			return (DAT_ABORT);
+		}
+		if ((event.event_data.dto_completion_event_data.
+		     transfered_length != buf_len)
+		    || (event.event_data.dto_completion_event_data.user_cookie.
+			as_64 != 0x9999)) {
+			fprintf(stderr,
+				"%d: ERROR: DTO len %d or cookie " F64x "\n",
+				getpid(),
+				event.event_data.dto_completion_event_data.
+				transfered_length,
+				event.event_data.dto_completion_event_data.
+				user_cookie.as_64);
+			return (DAT_ABORT);
+		}
+		if (event.event_data.dto_completion_event_data.status !=
+		    DAT_SUCCESS) {
+			fprintf(stderr, "%d: ERROR: DTO event status %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (DAT_ABORT);
+		}
+		stop = get_time();
+		ts.rdma_rd[i] = ((stop - start) * 1.0e6);
+		ts.rdma_rd_total += ts.rdma_rd[i];
+
+		LOGPRINTF("%d rdma_read # %d completed\n", getpid(), i + 1);
+	}
+
+	/*
+	 *  Send RMR information a 3rd time to indicate completion
+	 *  NOTE: already swapped to network order in connect_ep
+	 */
+	printf("%d Sending RDMA read completion message\n", getpid());
+
+	/* give remote chance to process read completes */
+	if (use_cno) {
+#if defined(_WIN32) || defined(_WIN64)
+		Sleep(1000);
+#else
+		sleep(1);
+#endif
+	}
+
+	ret = send_msg(&rmr_send_msg,
+		       sizeof(DAT_RMR_TRIPLET),
+		       lmr_context_send_msg,
+		       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error send_msg: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d send_msg completed\n", getpid());
+	}
+
+	printf("%d Waiting for inbound message....\n", getpid());
+
+	if (collect_event(h_dto_rcv_evd, 
+			  &event, 
+		 	  DTO_TIMEOUT, 
+			  &poll_count) != DAT_SUCCESS)
+		return (DAT_ABORT);
+
+	/* validate event number and status */
+	printf("%d inbound rdma_read; send message arrived!\n", getpid());
+	if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+		fprintf(stderr, "%d Error unexpected DTO event : %s\n",
+			getpid(), DT_EventToStr(event.event_number));
+		return (DAT_ABORT);
+	}
+
+	if ((event.event_data.dto_completion_event_data.transfered_length !=
+	     sizeof(DAT_RMR_TRIPLET))
+	    || (event.event_data.dto_completion_event_data.user_cookie.as_64 !=
+		recv_msg_index)) {
+
+		fprintf(stderr,
+			"unexpected event data for receive: len=%d cookie=" F64x
+			" exp %d/%d\n",
+			(int)event.event_data.dto_completion_event_data.
+			transfered_length,
+			event.event_data.dto_completion_event_data.user_cookie.
+			as_64, (int)sizeof(DAT_RMR_TRIPLET), recv_msg_index);
+
+		return (DAT_ABORT);
+	}
+
+	/* swap received RMR msg: network order to host order */
+	r_iov = rmr_recv_msg[recv_msg_index];
+	rmr_recv_msg[recv_msg_index].virtual_address =
+	    ntohll(rmr_recv_msg[recv_msg_index].virtual_address);
+	rmr_recv_msg[recv_msg_index].segment_length =
+	    ntohl(rmr_recv_msg[recv_msg_index].segment_length);
+	rmr_recv_msg[recv_msg_index].rmr_context =
+	    ntohl(rmr_recv_msg[recv_msg_index].rmr_context);
+
+	printf("%d Received RMR from remote: "
+	       "r_iov: r_key_ctx=%x,va=" F64x ",len=0x%x\n",
+	       getpid(), rmr_recv_msg[recv_msg_index].rmr_context,
+	       rmr_recv_msg[recv_msg_index].virtual_address,
+	       rmr_recv_msg[recv_msg_index].segment_length);
+
+	LOGPRINTF("%d inbound rdma_write; send msg event SUCCESS!!\n",
+		  getpid());
+
+	printf("%d %s RCV RDMA read buffer contains: %s\n",
+	       getpid(), server ? "SERVER:" : "CLIENT:", sbuf);
+
+	recv_msg_index++;
+
+	return (DAT_SUCCESS);
+}
+
+DAT_RETURN do_ping_pong_msg()
+{
+	DAT_EVENT event;
+	DAT_DTO_COOKIE cookie;
+	DAT_LMR_TRIPLET l_iov;
+	DAT_RETURN ret;
+	int i;
+	char *snd_buf;
+	char *rcv_buf;
+
+	printf("\n %d PING DATA with SEND MSG\n\n", getpid());
+
+	snd_buf = sbuf;
+	rcv_buf = rbuf;
+
+	/* pre-post all buffers */
+	for (i = 0; i < burst; i++) {
+		burst_msg_posted++;
+		cookie.as_64 = i;
+		l_iov.lmr_context = lmr_context_recv;
+		l_iov.virtual_address = (DAT_VADDR) (uintptr_t) rcv_buf;
+		l_iov.segment_length = buf_len;
+
+		LOGPRINTF("%d Pre-posting Receive Message Buffers %p\n",
+			  getpid(), rcv_buf);
+
+		ret = dat_ep_post_recv(h_ep,
+				       1,
+				       &l_iov,
+				       cookie, DAT_COMPLETION_DEFAULT_FLAG);
+
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr,
+				"%d Error posting recv msg buffer: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Posted Receive Message Buffer %p\n",
+				  getpid(), rcv_buf);
+		}
+
+		/* next buffer */
+		rcv_buf += buf_len;
+	}
+#if defined(_WIN32) || defined(_WIN64)
+	Sleep(1000);
+#else
+	sleep(1);
+#endif
+
+	/* Initialize recv_buf and index to beginning */
+	rcv_buf = rbuf;
+	burst_msg_index = 0;
+
+	/* client ping 0x55, server pong 0xAA in first byte */
+	start = get_time();
+	for (i = 0; i < burst; i++) {
+		/* walk the send and recv buffers */
+		if (!server) {
+			*snd_buf = 0x55;
+
+			LOGPRINTF("%d %s SND buffer %p contains: 0x%x len=%d\n",
+				  getpid(), server ? "SERVER:" : "CLIENT:",
+				  snd_buf, *snd_buf, buf_len);
+
+			ret = send_msg(snd_buf,
+				       buf_len,
+				       lmr_context_send,
+				       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
+
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, "%d Error send_msg: %s\n",
+					getpid(), DT_RetToStr(ret));
+				return (ret);
+			} else {
+				LOGPRINTF("%d send_msg completed\n", getpid());
+			}
+		}
+
+		/* recv message, send completions suppressed */
+		if (collect_event(h_dto_rcv_evd, 
+				  &event, 
+				  DTO_TIMEOUT, 
+				  &poll_count) != DAT_SUCCESS)
+			return (DAT_ABORT);
+
+		
+		/* start timer after first message arrives on server */
+		if (i == 0) {
+			start = get_time();
+		}
+		/* validate event number and status */
+		LOGPRINTF("%d inbound message; message arrived!\n", getpid());
+		if (event.event_number != DAT_DTO_COMPLETION_EVENT) {
+			fprintf(stderr, "%d Error unexpected DTO event : %s\n",
+				getpid(), DT_EventToStr(event.event_number));
+			return (DAT_ABORT);
+		}
+		if ((event.event_data.dto_completion_event_data.
+		     transfered_length != buf_len)
+		    || (event.event_data.dto_completion_event_data.user_cookie.
+			as_64 != burst_msg_index)) {
+			fprintf(stderr,
+				"ERR: recv event: len=%d cookie=" F64x
+				" exp %d/%d\n",
+				(int)event.event_data.dto_completion_event_data.
+				transfered_length,
+				event.event_data.dto_completion_event_data.
+				user_cookie.as_64, (int)buf_len,
+				(int)burst_msg_index);
+
+			return (DAT_ABORT);
+		}
+
+		LOGPRINTF("%d %s RCV buffer %p contains: 0x%x len=%d\n",
+			  getpid(), server ? "SERVER:" : "CLIENT:",
+			  rcv_buf, *rcv_buf, buf_len);
+
+		burst_msg_index++;
+
+		/* If server, change data and send it back to client */
+		if (server) {
+			*snd_buf = 0xaa;
+
+			LOGPRINTF("%d %s SND buffer %p contains: 0x%x len=%d\n",
+				  getpid(), server ? "SERVER:" : "CLIENT:",
+				  snd_buf, *snd_buf, buf_len);
+
+			ret = send_msg(snd_buf,
+				       buf_len,
+				       lmr_context_send,
+				       cookie, DAT_COMPLETION_SUPPRESS_FLAG);
+
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, "%d Error send_msg: %s\n",
+					getpid(), DT_RetToStr(ret));
+				return (ret);
+			} else {
+				LOGPRINTF("%d send_msg completed\n", getpid());
+			}
+		}
+
+		/* next buffers */
+		rcv_buf += buf_len;
+		snd_buf += buf_len;
+	}
+	stop = get_time();
+	ts.rtt = ((stop - start) * 1.0e6);
+
+	return (DAT_SUCCESS);
+}
+
+/* Register RDMA Receive buffer */
+DAT_RETURN register_rdma_memory(void)
+{
+	DAT_RETURN ret;
+	DAT_REGION_DESCRIPTION region;
+
+	region.for_va = rbuf;
+	start = get_time();
+	ret = dat_lmr_create(h_ia,
+			     DAT_MEM_TYPE_VIRTUAL,
+			     region,
+			     buf_len * (burst+1),
+			     h_pz,
+			     DAT_MEM_PRIV_ALL_FLAG,
+			     DAT_VA_TYPE_VA,
+			     &h_lmr_recv,
+			     &lmr_context_recv,
+			     &rmr_context_recv,
+			     &registered_size_recv, &registered_addr_recv);
+	stop = get_time();
+	ts.reg += ((stop - start) * 1.0e6);
+	ts.total += ts.reg;
+
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr,
+			"%d Error registering Receive RDMA buffer: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d Registered Receive RDMA Buffer %p\n",
+			  getpid(), region.for_va);
+	}
+
+	/* Register RDMA Send buffer */
+	region.for_va = sbuf;
+	ret = dat_lmr_create(h_ia,
+			     DAT_MEM_TYPE_VIRTUAL,
+			     region,
+			     buf_len * (burst + 1),
+			     h_pz,
+			     DAT_MEM_PRIV_ALL_FLAG,
+			     DAT_VA_TYPE_VA,
+			     &h_lmr_send,
+			     &lmr_context_send,
+			     &rmr_context_send,
+			     &registered_size_send, &registered_addr_send);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error registering send RDMA buffer: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d Registered Send RDMA Buffer %p\n",
+			  getpid(), region.for_va);
+	}
+
+	return DAT_SUCCESS;
+}
+
+/*
+ * Unregister RDMA memory
+ */
+DAT_RETURN unregister_rdma_memory(void)
+{
+	DAT_RETURN ret;
+
+	/* Unregister Recv Buffer */
+	if (h_lmr_recv != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Unregister h_lmr %p \n", getpid(), h_lmr_recv);
+		start = get_time();
+		ret = dat_lmr_free(h_lmr_recv);
+		stop = get_time();
+		ts.unreg += ((stop - start) * 1.0e6);
+		ts.total += ts.unreg;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error deregistering recv mr: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Unregistered Recv Buffer\n", getpid());
+			h_lmr_recv = NULL;
+		}
+	}
+
+	/* Unregister Send Buffer */
+	if (h_lmr_send != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Unregister h_lmr %p \n", getpid(), h_lmr_send);
+		ret = dat_lmr_free(h_lmr_send);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error deregistering send mr: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Unregistered send Buffer\n", getpid());
+			h_lmr_send = NULL;
+		}
+	}
+	return DAT_SUCCESS;
+}
+
+ /*
+  * Create CNO, CR, CONN, and DTO events
+  */
+DAT_RETURN create_events(void)
+{
+	DAT_RETURN ret;
+	DAT_EVD_PARAM param;
+
+	/* create CNO */
+	if (use_cno) {
+		start = get_time();
+#if defined(_WIN32) || defined(_WIN64)
+		{
+			DAT_OS_WAIT_PROXY_AGENT pa = { NULL, NULL };
+			ret = dat_cno_create(h_ia, pa, &h_dto_cno);
+		}
+#else
+		ret =
+		    dat_cno_create(h_ia, DAT_OS_WAIT_PROXY_AGENT_NULL,
+				   &h_dto_cno);
+#endif
+		stop = get_time();
+		ts.cnoc += ((stop - start) * 1.0e6);
+		ts.total += ts.cnoc;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error dat_cno_create: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d cr_evd created, %p\n", getpid(),
+				  h_dto_cno);
+		}
+	}
+
+	/* create cr EVD */
+	start = get_time();
+	ret =
+	    dat_evd_create(h_ia, 10, DAT_HANDLE_NULL, DAT_EVD_CR_FLAG,
+			   &h_cr_evd);
+	stop = get_time();
+	ts.evdc += ((stop - start) * 1.0e6);
+	ts.total += ts.evdc;
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_evd_create: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d cr_evd created %p\n", getpid(), h_cr_evd);
+	}
+
+	/* create conn EVD */
+	ret = dat_evd_create(h_ia,
+			     10,
+			     DAT_HANDLE_NULL,
+			     DAT_EVD_CONNECTION_FLAG, &h_conn_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_evd_create: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d con_evd created %p\n", getpid(), h_conn_evd);
+	}
+
+	/* create dto SND EVD, with CNO if use_cno was set */
+	ret = dat_evd_create(h_ia,
+			     (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2,
+			     h_dto_cno, DAT_EVD_DTO_FLAG, &h_dto_req_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_evd_create REQ: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d dto_req_evd created %p\n", getpid(),
+			  h_dto_req_evd);
+	}
+
+	/* create dto RCV EVD, with CNO if use_cno was set */
+	ret = dat_evd_create(h_ia,
+			     MSG_BUF_COUNT + burst,
+			     h_dto_cno, DAT_EVD_DTO_FLAG, &h_dto_rcv_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_evd_create RCV: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else {
+		LOGPRINTF("%d dto_rcv_evd created %p\n", getpid(),
+			  h_dto_rcv_evd);
+	}
+
+	/* query DTO req EVD and check size */
+	ret = dat_evd_query(h_dto_req_evd, DAT_EVD_FIELD_EVD_QLEN, &param);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d Error dat_evd_query request evd: %s\n",
+			getpid(), DT_RetToStr(ret));
+		return (ret);
+	} else if (param.evd_qlen < (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2) {
+		fprintf(stderr, "%d Error dat_evd qsize too small: %d < %d\n",
+			getpid(), param.evd_qlen,
+			(MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2);
+		return (ret);
+	}
+
+	LOGPRINTF("%d dto_req_evd QLEN - requested %d and actual %d\n",
+		  getpid(), (MSG_BUF_COUNT + MAX_RDMA_RD + burst) * 2,
+		  param.evd_qlen);
+
+	return DAT_SUCCESS;
+}
+
+/*
+ * Destroy CR, CONN, CNO, and DTO events
+ */
+
+DAT_RETURN destroy_events(void)
+{
+	DAT_RETURN ret;
+
+	/* free cr EVD */
+	if (h_cr_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Free cr EVD %p \n", getpid(), h_cr_evd);
+		ret = dat_evd_free(h_cr_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing cr EVD: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Freed cr EVD\n", getpid());
+			h_cr_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free conn EVD */
+	if (h_conn_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Free conn EVD %p \n", getpid(), h_conn_evd);
+		ret = dat_evd_free(h_conn_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing conn EVD: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Freed conn EVD\n", getpid());
+			h_conn_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free RCV dto EVD */
+	if (h_dto_rcv_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Free RCV dto EVD %p \n", getpid(), h_dto_rcv_evd);
+		start = get_time();
+		ret = dat_evd_free(h_dto_rcv_evd);
+		stop = get_time();
+		ts.evdf += ((stop - start) * 1.0e6);
+		ts.total += ts.evdf;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing dto EVD: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Freed dto EVD\n", getpid());
+			h_dto_rcv_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free REQ dto EVD */
+	if (h_dto_req_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Free REQ dto EVD %p \n", getpid(), h_dto_req_evd);
+		ret = dat_evd_free(h_dto_req_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing dto EVD: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Freed dto EVD\n", getpid());
+			h_dto_req_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free CNO */
+	if (h_dto_cno != DAT_HANDLE_NULL) {
+		LOGPRINTF("%d Free dto CNO %p \n", getpid(), h_dto_cno);
+		start = get_time();
+		ret = dat_cno_free(h_dto_cno);
+		stop = get_time();
+		ts.cnof += ((stop - start) * 1.0e6);
+		ts.total += ts.cnof;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, "%d Error freeing dto CNO: %s\n",
+				getpid(), DT_RetToStr(ret));
+			return (ret);
+		} else {
+			LOGPRINTF("%d Freed dto CNO\n", getpid());
+			h_dto_cno = DAT_HANDLE_NULL;
+		}
+	}
+	return DAT_SUCCESS;
+}
+
+/*
+ * Map DAT_RETURN values to readable strings,
+ * but don't assume the values are zero-based or contiguous.
+ */
+char errmsg[512] = { 0 };
+const char *DT_RetToStr(DAT_RETURN ret_value)
+{
+	const char *major_msg, *minor_msg;
+
+	dat_strerror(ret_value, &major_msg, &minor_msg);
+
+	strcpy(errmsg, major_msg);
+	strcat(errmsg, " ");
+	strcat(errmsg, minor_msg);
+
+	return errmsg;
+}
+
+/*
+ * Map DAT_EVENT_CODE values to readable strings
+ */
+const char *DT_EventToStr(DAT_EVENT_NUMBER event_code)
+{
+	unsigned int i;
+	static struct {
+		const char *name;
+		DAT_RETURN value;
+	} dat_events[] = {
+#   define DATxx(x) { # x, x }
+		DATxx(DAT_DTO_COMPLETION_EVENT),
+		    DATxx(DAT_RMR_BIND_COMPLETION_EVENT),
+		    DATxx(DAT_CONNECTION_REQUEST_EVENT),
+		    DATxx(DAT_CONNECTION_EVENT_ESTABLISHED),
+		    DATxx(DAT_CONNECTION_EVENT_PEER_REJECTED),
+		    DATxx(DAT_CONNECTION_EVENT_NON_PEER_REJECTED),
+		    DATxx(DAT_CONNECTION_EVENT_ACCEPT_COMPLETION_ERROR),
+		    DATxx(DAT_CONNECTION_EVENT_DISCONNECTED),
+		    DATxx(DAT_CONNECTION_EVENT_BROKEN),
+		    DATxx(DAT_CONNECTION_EVENT_TIMED_OUT),
+		    DATxx(DAT_CONNECTION_EVENT_UNREACHABLE),
+		    DATxx(DAT_ASYNC_ERROR_EVD_OVERFLOW),
+		    DATxx(DAT_ASYNC_ERROR_IA_CATASTROPHIC),
+		    DATxx(DAT_ASYNC_ERROR_EP_BROKEN),
+		    DATxx(DAT_ASYNC_ERROR_TIMED_OUT),
+		    DATxx(DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR),
+		    DATxx(DAT_SOFTWARE_EVENT)
+#   undef DATxx
+	};
+#   define NUM_EVENTS (sizeof(dat_events)/sizeof(dat_events[0]))
+
+	for (i = 0; i < NUM_EVENTS; i++) {
+		if (dat_events[i].value == event_code) {
+			return (dat_events[i].name);
+		}
+	}
+
+	return ("Invalid_DAT_EVENT_NUMBER");
+}
+
+void print_usage(void)
+{
+	printf("\n DAPL USAGE \n\n");
+	printf("s: server\n");
+	printf("t: performance times\n");
+	printf("c: use cno\n");
+	printf("v: verbose\n");
+	printf("p: polling\n");
+	printf("d: delay before accept\n");
+	printf("b: buf length to allocate\n");
+	printf("B: burst count, rdma and msgs \n");
+	printf("h: hostname/address of server, specified on client\n");
+	printf("P: provider name (default = OpenIB-cma)\n");
+	printf("l: server lid (required ucm provider)\n");
+	printf("q: server qpn (required ucm provider)\n");
+	printf("\n");
+}
+
Index: ulp/dapl2/test/dtest/dtestcm.c
===================================================================
--- ulp/dapl2/test/dtest/dtestcm.c	(revision 3414)
+++ ulp/dapl2/test/dtest/dtestcm.c	(working copy)
@@ -1,1166 +1,1166 @@
-/*
- * Copyright (c) 2009 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
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef DAPL_PROVIDER
-#undef DAPL_PROVIDER
-#endif
-
-#if defined(_WIN32) || defined(_WIN64)
-
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <io.h>
-#include <process.h>
-#include <complib/cl_types.h>
-#include "..\..\..\..\etc\user\getopt.c"
-
-#define getpid() ((int)GetCurrentProcessId())
-#define F64x "%I64x"
-#define F64d "%I64d"
-
-#ifdef DBG
-#define DAPL_PROVIDER "ibnic0v2d"
-#else
-#define DAPL_PROVIDER "ibnic0v2"
-#endif
-
-#define ntohll _byteswap_uint64
-#define htonll _byteswap_uint64
-
-#else // _WIN32 || _WIN64
-
-#include <endian.h>
-#include <byteswap.h>
-#include <netdb.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <sys/mman.h>
-#include <getopt.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#define DAPL_PROVIDER "ofa-v2-ib0"
-
-#define F64x "%"PRIx64""
-#define F64d "%"PRId64""
-
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define htonll(x) (x)
-#define ntohll(x) (x)
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-#define htonll(x)  bswap_64(x)
-#define ntohll(x)  bswap_64(x)
-#endif
-
-#endif // _WIN32 || _WIN64
-
-#define MAX_POLLING_CNT 50000
-
-/* Header files needed for DAT/uDAPL */
-#include "dat2/udat.h"
-#include "dat2/dat_ib_extensions.h"
-
-/* definitions */
-#define SERVER_CONN_QUAL  45248
-#define CONN_TIMEOUT      (1000*1000*100)
-#define CR_TIMEOUT	  DAT_TIMEOUT_INFINITE
-
-/* Global DAT vars */
-static DAT_IA_HANDLE h_ia = DAT_HANDLE_NULL;
-static DAT_PZ_HANDLE h_pz = DAT_HANDLE_NULL;
-static DAT_EP_HANDLE *h_ep;
-static DAT_PSP_HANDLE *h_psp;
-static DAT_CR_HANDLE h_cr = DAT_HANDLE_NULL;
-
-static DAT_EVD_HANDLE h_async_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_dto_req_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_dto_rcv_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_cr_evd = DAT_HANDLE_NULL;
-static DAT_EVD_HANDLE h_conn_evd = DAT_HANDLE_NULL;
-
-static DAT_EP_ATTR ep_attr;
-char hostname[256] = { 0 };
-char provider[64] = DAPL_PROVIDER;
-char addr_str[INET_ADDRSTRLEN];
-
-int status;
-
-/* timers */
-double start, stop, total_us, total_sec;
-
-struct dt_time {
-	double total;
-	double open;
-	double reg;
-	double unreg;
-	double pzc;
-	double pzf;
-	double evdc;
-	double evdf;
-	double cnoc;
-	double cnof;
-	double epc;
-	double epf;
-	double rtt;
-	double close;
-	double conn;
-};
-
-struct dt_time ts;
-
-/* defaults */
-static int connected = 0;
-static int multi_listens = 0;
-static int ud_test = 0;
-static int server = 1;
-static int waiting = 0;
-static int verbose = 0;
-static int cr_poll_count = 0;
-static int conn_poll_count = 0;
-static int delay = 0;
-static int connections = 1000;
-static int burst = 100;
-static int port_id = SERVER_CONN_QUAL;
-static int ucm = 0;
-static DAT_SOCK_ADDR6 remote;
-
-/* forward prototypes */
-const char *DT_RetToString(DAT_RETURN ret_value);
-const char *DT_EventToSTr(DAT_EVENT_NUMBER event_code);
-void print_usage(void);
-double get_time(void);
-DAT_RETURN conn_client(void);
-DAT_RETURN conn_server(void);
-DAT_RETURN disconnect_eps(void);
-DAT_RETURN create_events(void);
-DAT_RETURN destroy_events(void);
-
-#define LOGPRINTF if (verbose) printf
-
-void flush_evds(void)
-{
-	DAT_EVENT event;
-
-	/* Flush async error queue */
-	printf(" ERR: Checking ASYNC EVD...\n");
-	while (dat_evd_dequeue(h_async_evd, &event) == DAT_SUCCESS) {
-		printf(" ASYNC EVD ENTRY: handle=%p reason=%d\n",
-			event.event_data.asynch_error_event_data.dat_handle,
-			event.event_data.asynch_error_event_data.reason);
-	}
-}
-
-static void print_ia_address(struct sockaddr *sa)
-{
-	char str[INET6_ADDRSTRLEN] = {" ??? "};
-
-	switch(sa->sa_family) {
-	case AF_INET:
-		inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, str, INET6_ADDRSTRLEN);
-		printf("%d Local Address AF_INET - %s port %d\n", getpid(), str, SERVER_CONN_QUAL);
-		break;
-	case AF_INET6:
-		inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, str, INET6_ADDRSTRLEN);
-		printf("%d Local Address AF_INET6 - %s flowinfo(QPN)=0x%x, port(LID)=0x%x\n",
-			getpid(), str,
-			ntohl(((struct sockaddr_in6 *)sa)->sin6_flowinfo),
-			ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
-		break;
-	default:
-		printf("%d Local Address UNKOWN FAMILY - port %d\n", getpid(), SERVER_CONN_QUAL);
-	}
-}
-
-int main(int argc, char **argv)
-{
-	int i, c, len;
-	DAT_RETURN ret;
-	DAT_IA_ATTR ia_attr;
-	
-	/* parse arguments */
-	while ((c = getopt(argc, argv, "smwvub:c:d:h:P:p:q:l:")) != -1) {
-		switch (c) {
-		case 's':
-			server = 1;
-			break;
-		case 'm':
-			multi_listens = 1;
-			break;
-		case 'w':
-			waiting = 1;
-			break;
-		case 'u':
-			ud_test = 1;
-			break;
-		case 'c':
-			connections = atoi(optarg);
-			break;
-		case 'p':
-			port_id = atoi(optarg);
-			break;
-		case 'v':
-			verbose = 1;
-			fflush(stdout);
-			break;
-		case 'd':
-			delay = atoi(optarg);
-			break;
-		case 'b':
-			burst = atoi(optarg);
-			break;
-		case 'h':
-			server = 0;
-			strcpy(hostname, optarg);
-			break;
-		case 'P':
-			strcpy(provider, optarg);
-			break;
-		case 'q':
-			/* map UCM qpn into AF_INET6 sin6_flowinfo */
-			remote.sin6_family = AF_INET6;
-			remote.sin6_flowinfo = htonl(strtol(optarg,NULL,0));
-			ucm = 1;
-			server = 0;
-			break;
-		case 'l':
-			/* map UCM lid into AF_INET6 sin6_port */
-			remote.sin6_family = AF_INET6;
-			remote.sin6_port = htons(strtol(optarg,NULL,0));
-			ucm = 1;
-			server = 0;
-			break;
-		default:
-			print_usage();
-			exit(-12);
-		}
-	}
-
-#if defined(_WIN32) || defined(_WIN64)
-	{
-		WSADATA wsaData;
-
-		i = WSAStartup(MAKEWORD(2, 2), &wsaData);
-		if (i != 0) {
-			printf("%s WSAStartup(2.2) failed? (0x%x)\n", argv[0],
-			       i);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-#endif
-
-	if (!server) {
-		printf(" Running client on %s with %d %s connections\n", 
-			provider, connections, ud_test ? "UD" : "RC");
-	} else {
-		printf(" Running server on %s with %d %s connections\n", 
-			provider, connections, ud_test ? "UD" : "RC");
-	}
-	fflush(stdout);
-	
-	if (burst > connections)
-		burst = connections;
-
-	
-	/* allocate EP handles for all connections */
-	h_ep = (DAT_EP_HANDLE*)malloc(connections * sizeof(DAT_EP_HANDLE));
-	if (h_ep == NULL) {	
-		perror("malloc ep");
-		exit(1);
-	}
-	memset(h_ep, 0, (burst * sizeof(DAT_PSP_HANDLE)));
-	
-	/* allocate PSP handles, check for multi-listens */
-	if (multi_listens)
-		len = burst * sizeof(DAT_PSP_HANDLE);
-	else
-		len = sizeof(DAT_PSP_HANDLE);
-
-	h_psp = (DAT_PSP_HANDLE*)malloc(len);
-	if (h_psp == NULL) {	
-		perror("malloc psp");
-		exit(1);
-	}
-	memset(h_psp, 0, len);
-	memset(&ts, 0, sizeof(struct dt_time));
-
-	/* dat_ia_open, dat_pz_create */
-	h_async_evd = DAT_HANDLE_NULL;
-	start = get_time();
-	ret = dat_ia_open(provider, 8, &h_async_evd, &h_ia);
-	stop = get_time();
-	ts.open += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error Adaptor open: %s\n",
-			DT_RetToString(ret));
-		exit(1);
-	} else
-		LOGPRINTF(" Opened Interface Adaptor\n");
-
-	/* query for UCM addressing */
-	ret = dat_ia_query(h_ia, 0, DAT_IA_FIELD_ALL, &ia_attr, 0, 0);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, "%d: Error Adaptor query: %s\n",
-			getpid(), DT_RetToString(ret));
-		exit(1);
-	}
-	print_ia_address(ia_attr.ia_address_ptr);
-
-	/* Create Protection Zone */
-	start = get_time();
-	LOGPRINTF(" Create Protection Zone\n");
-	ret = dat_pz_create(h_ia, &h_pz);
-	stop = get_time();
-	ts.pzc += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error creating Protection Zone: %s\n",
-			DT_RetToString(ret));
-		exit(1);
-	} else
-		LOGPRINTF(" Created Protection Zone\n");
-
-	LOGPRINTF(" Create events\n");
-	ret = create_events();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error creating events: %s\n",
-			DT_RetToString(ret));
-		goto cleanup;
-	} else {
-		LOGPRINTF(" Create events done\n");
-	}
-
-	/* create EP */
-	memset(&ep_attr, 0, sizeof(ep_attr));
-	if (ud_test) {
-		ep_attr.service_type = DAT_IB_SERVICE_TYPE_UD;
-		ep_attr.max_message_size = 2048;
-	} else {
-		ep_attr.service_type = DAT_SERVICE_TYPE_RC;
-		ep_attr.max_rdma_size = 0x10000;
-		ep_attr.max_rdma_read_in = 4;
-		ep_attr.max_rdma_read_out = 4;
-	}
-	ep_attr.max_recv_dtos = 1;
-	ep_attr.max_request_dtos = 1;
-	ep_attr.max_recv_iov = 1;
-	ep_attr.max_request_iov = 1;
-	ep_attr.request_completion_flags = DAT_COMPLETION_DEFAULT_FLAG;
-	
-	start = get_time();
-	for (i = 0; i < connections; i++) {
-		ret = dat_ep_create(h_ia, h_pz, h_dto_rcv_evd,
-				    h_dto_req_evd, h_conn_evd, 
-				    &ep_attr, &h_ep[i]);
-	}
-	stop = get_time();
-	ts.epc += ((stop - start) * 1.0e6);
-	ts.total += ts.epc;
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error dat_ep_create: %s\n",
-			DT_RetToString(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF(" EP created %p \n", h_ep[i]);
-
-	/* create the service point for server listen */
-	if (server) {
-		LOGPRINTF(" Creating server service point(s)\n");
-		for (i = 0; i < burst; i++) {
-			ret = dat_psp_create(h_ia,
-					     port_id+i,
-					     h_cr_evd, 
-					     DAT_PSP_CONSUMER_FLAG, 
-					     &h_psp[i]);
-
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, " ERR psp_create: %s\n",
-					DT_RetToString(ret));
-				goto cleanup;
-			} else
-				LOGPRINTF(" psp_created for listen\n");
-
-			printf(" Server ready on port %d\n", 
-				port_id+i);
-
-			if (!multi_listens)
-				break;
-		}
-	}
-	
-	/* Connect all */
-	if (server)
-		ret = conn_server();
-	else	
-		ret = conn_client();
-	
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error %s: %s\n",
-			 server ? "server()" : "client()",
-			DT_RetToString(ret));
-		goto cleanup;
-	} else
-		LOGPRINTF(" connect_ep complete\n");
-
-	connected = 1;
-	goto complete;
-
-cleanup:
-	flush_evds();
-	goto bail;
-complete:
-
-	/* disconnect and free EP resources */
-	if (h_ep[0]) {
-		/* unregister message buffers and tear down connection */
-		LOGPRINTF(" Disconnect EPs\n");
-		ret = disconnect_eps();
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error disconnect_eps: %s\n",
-				DT_RetToString(ret));
-			goto bail;
-		} else {
-			LOGPRINTF(" disconnect_eps complete\n");
-		}
-	}
-
-	/* destroy server service point(s) */
-	if ((server) && (h_psp[0] != DAT_HANDLE_NULL)) {
-		for (i = 0; i < burst; i++) {
-			ret = dat_psp_free(h_psp[i]);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, " Error dat_psp_free: %s\n",
-					DT_RetToString(ret));
-				goto bail;
-			} else {
-				LOGPRINTF(" psp_free[%d] complete\n",i);
-			}
-			if (!multi_listens)
-				break;
-		}
-	}
-
-	/* free EVDs */
-	LOGPRINTF(" destroy events\n");
-	ret = destroy_events();
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error destroy_events: %s\n",
-			DT_RetToString(ret));
-		goto bail;
-	} else
-		LOGPRINTF(" destroy events done\n");
-
-
-	/* Free protection domain */
-	LOGPRINTF(" Freeing pz\n");
-	start = get_time();
-	ret = dat_pz_free(h_pz);
-	stop = get_time();
-	ts.pzf += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error freeing PZ: %s\n",
-			DT_RetToString(ret));
-		goto bail;
-	} else {
-		LOGPRINTF(" Freed pz\n");
-		h_pz = NULL;
-	}
-
-	/* close the device */
-	LOGPRINTF(" Closing Interface Adaptor\n");
-	start = get_time();
-	ret = dat_ia_close(h_ia, DAT_CLOSE_ABRUPT_FLAG);
-	stop = get_time();
-	ts.close += ((stop - start) * 1.0e6);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error Adaptor close: %s\n",
-			DT_RetToString(ret));
-		goto bail;
-	} else
-		LOGPRINTF(" Closed Interface Adaptor\n");
-
-	printf(" DAPL Connection Test Complete.\n");
-	printf(" open:      %10.2lf usec\n", ts.open);
-	printf(" close:     %10.2lf usec\n", ts.close);
-	printf(" PZ create: %10.2lf usec\n", ts.pzc);
-	printf(" PZ free:   %10.2lf usec\n", ts.pzf);
-	printf(" LMR create:%10.2lf usec\n", ts.reg);
-	printf(" LMR free:  %10.2lf usec\n", ts.unreg);
-	printf(" EVD create:%10.2lf usec\n", ts.evdc);
-	printf(" EVD free:  %10.2lf usec\n", ts.evdf);
-	printf(" EP create: %10.2lf usec avg\n", ts.epc/connections);
-	printf(" EP free:   %10.2lf usec avg\n", ts.epf/connections);
-	if (!server) {
-		printf(" Connections: %8.2lf usec, CPS %7.2lf "
-			"Total %4.2lf secs, poll_cnt=%u, Num=%d\n", 
-		       (double)(ts.conn/connections), 
-		       (double)(1/(ts.conn/1000000/connections)), 
-		       (double)(ts.conn/1000000), 
-		       conn_poll_count, connections);
-	}
-	printf(" TOTAL:     %4.2lf sec\n",  ts.total/1000000);
-	fflush(stderr);	fflush(stdout);
-bail:
-	free(h_ep);
-	free(h_psp);
-
-#if defined(_WIN32) || defined(_WIN64)
-	WSACleanup();
-#endif
-	return (0);
-}
-
-double get_time(void)
-{
-	struct timeval tp;
-
-	gettimeofday(&tp, NULL);
-	return ((double)tp.tv_sec + (double)tp.tv_usec * 1e-6);
-}
-
-DAT_RETURN conn_server()
-{
-	DAT_RETURN ret;
-	DAT_EVENT event;
-	DAT_COUNT nmore;
-	int i,bi;
-	unsigned char *buf;
-	DAT_CR_ARRIVAL_EVENT_DATA *cr_event =
-		&event.event_data.cr_arrival_event_data;
-	DAT_CR_PARAM cr_param = { 0 };
-	
-	printf(" Accepting...\n");
-	for (i = 0; i < connections; i++) {
-					
-		/* poll for CR's */
-		if (!waiting) {
-			cr_poll_count = 0;
-			while (DAT_GET_TYPE(dat_evd_dequeue(h_cr_evd, &event)) 
-					== DAT_QUEUE_EMPTY)
-				cr_poll_count++;
-		} else {
-			ret = dat_evd_wait(h_cr_evd, CR_TIMEOUT, 
-					   1, &event, &nmore);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr,
-					" ERR: CR dat_evd_wait() %s\n",
-					 DT_RetToString(ret));
-				return ret;
-			}
-		}
-	
-		if ((event.event_number != DAT_CONNECTION_REQUEST_EVENT) &&
-		    (ud_test && event.event_number != 
-		     DAT_IB_UD_CONNECTION_REQUEST_EVENT)) {
-				fprintf(stderr, " Error unexpected CR event : %s\n",
-					DT_EventToSTr(event.event_number));
-				return (DAT_ABORT);
-		}
-
-		
-		/* use to test rdma_cma timeout logic */
-#if defined(_WIN32) || defined(_WIN64)
-		if (delay) {
-			printf(" Accept delayed by %d seconds...\n", delay);
-			Sleep(delay * 1000);
-		}
-#else
-		if (delay) {
-			printf(" Accept delayed by %d seconds...\n", delay);
-			sleep(delay);
-		}
-#endif
-		/* accept connect request from client */
-		h_cr = cr_event->cr_handle;
-		LOGPRINTF(" Accepting connect request from client\n");
-
-		/* private data - check and send it back */
-		dat_cr_query(h_cr, DAT_CSP_FIELD_ALL, &cr_param);
-
-		buf = (unsigned char *)cr_param.private_data;
-		LOGPRINTF(" CONN REQUEST Private Data %p[0]=%d [47]=%d\n",
-			   buf, buf[0], buf[47]);
-		
-		for (bi = 0; bi < 48; bi++) {
-			if (buf[bi] != bi + 1) {
-				fprintf(stderr, " ERR on CONNECT REQUEST"
-					" private data: %p[%d]=%d s/be %d\n",
-					 buf, bi, buf[bi], bi + 1);
-				dat_cr_reject(h_cr, 0, NULL);
-				return (DAT_ABORT);
-			}
-			buf[bi]++;	/* change for trip back */
-		}
-
-#ifdef TEST_REJECT_WITH_PRIVATE_DATA
-		printf(" REJECT request with 48 bytes of private data\n");
-		ret = dat_cr_reject(h_cr, 48, cr_param.private_data);
-		printf("\n DAPL Test Complete. %s\n\n",
-		        ret ? "FAILED" : "PASSED");
-		exit(0);
-#endif
-		ret = dat_cr_accept(h_cr, h_ep[i], 48, 
-				    cr_param.private_data);
-
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " ERR dat_cr_accept: %s\n",
-				DT_RetToString(ret));
-			return (ret);
-		} else
-			LOGPRINTF(" accept[%d] complete\n", i);
-	
-		event.event_number = 0;
-	}
-
-	/* process the RTU, ESTABLISHMENT event */
-	printf(" Completing...\n");
-        for (i=0;i<connections;i++) {
-		
-		/* process completions */
-		if (!waiting) {
-			conn_poll_count = 0;
-			while (DAT_GET_TYPE(dat_evd_dequeue(h_conn_evd, 
-					    &event)) == DAT_QUEUE_EMPTY)
-				conn_poll_count++;
-		} else {
-			ret = dat_evd_wait(h_conn_evd, CONN_TIMEOUT, 
-					   1, &event, &nmore);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr,
-					" ERR: CONN evd_wait() %s\n",
-					 DT_RetToString(ret));
-				return ret;
-			}
-		}
-		if ((event.event_number != DAT_CONNECTION_EVENT_ESTABLISHED) &&
-		    (ud_test && event.event_number != 
-		     DAT_IB_UD_CONNECTION_EVENT_ESTABLISHED)) {
-
-			fprintf(stderr, " Error unexpected CR EST "
-				"event : 0x%x %s\n",
-				 event.event_number,
-				DT_EventToSTr(event.event_number));
-			return (DAT_ABORT);
-		}
-		event.event_number = 0;
-		LOGPRINTF(" CONN_EST[%d] complete\n", i);
-	}
-
-	printf("\n ALL %d CONNECTED on Server!\n\n", connections);
-	return DAT_SUCCESS;
-}
-
-	
-DAT_RETURN conn_client() 
-{
-	DAT_IA_ADDRESS_PTR raddr = (DAT_IA_ADDRESS_PTR)&remote;
-	DAT_RETURN ret;
-	DAT_EVENT event;
-	DAT_COUNT nmore;
-	DAT_CONN_QUAL conn_id;
-	DAT_CONNECTION_EVENT_DATA *conn_event =
-		&event.event_data.connect_event_data;
-	int i,ii,bi;
-	unsigned char *buf;
-	unsigned char pdata[48] = { 0 };
-	struct addrinfo *target;
-	int rval;
-
-	if (ucm)
-		goto no_resolution;
-
-#if defined(_WIN32) || defined(_WIN64)
-	if ((rval = getaddrinfo(hostname, "ftp", NULL, &target)) != 0) {
-		printf("\n remote name resolution failed! %s\n",
-			gai_strerror(rval));
-		exit(1);
-	}
-	rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
-#else
-	if (getaddrinfo(hostname, NULL, NULL, &target) != 0) {
-		perror("\n remote name resolution failed!");
-		exit(1);
-	}
-	rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
-#endif
-	printf(" Connecting to Server: %s \n",  hostname);
-	printf(" Address: %d.%d.%d.%d port %d\n",
-		(rval >> 0) & 0xff, (rval >> 8) & 0xff,
-		(rval >> 16) & 0xff, (rval >> 24) & 0xff, 
-		port_id);
-
-	raddr = (DAT_IA_ADDRESS_PTR)target->ai_addr;
-	
-no_resolution:
-
-	for (i = 0; i < 48; i++) /* simple pattern in private data */
-		pdata[i] = i + 1;
-
-       	printf(" Connecting...\n");
-	start = get_time();
-	for (i = 0; i < connections; i += burst) {
-		for (ii = 0; ii < burst; ii++) { /* conn_reqs */
-			if (multi_listens)
-				conn_id = port_id + ii;
-			else
-				conn_id = port_id;
-
-			ret = dat_ep_connect(h_ep[i+ii], raddr, 
-					     conn_id, CONN_TIMEOUT,
-					     48, (DAT_PVOID) pdata, 0, 
-					     DAT_CONNECT_DEFAULT_FLAG);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, " ERR dat_ep_connect: %s\n",
-					DT_RetToString(ret));
-				return (ret);
-			} else
-				LOGPRINTF(" dat_ep_connect[%d] complete\n", 
-					  i+ii);
-
-		} 
-		for (ii = 0; ii < burst; ii++) { /* conn_events */
-			if (!waiting) {
-				conn_poll_count = 0;
-				while (DAT_GET_TYPE(dat_evd_dequeue(
-					h_conn_evd, &event)) == 
-					DAT_QUEUE_EMPTY)
-					conn_poll_count++;
-			} else {
-				ret = dat_evd_wait(h_conn_evd, CONN_TIMEOUT, 
-						   1, &event, &nmore);
-
-				if (ret != DAT_SUCCESS) {
-					fprintf(stderr,
-						" ERR: CONN evd_wait() %s\n",
-						DT_RetToString(ret));
-					return ret;
-				}
-			}
-
-#ifdef TEST_REJECT_WITH_PRIVATE_DATA
-			if (event.event_number != 
-				DAT_CONNECTION_EVENT_PEER_REJECTED) {
-				fprintf(stderr, " expected conn reject "
-					"event : %s\n",
-					DT_EventToSTr(event.event_number));
-				return (DAT_ABORT);
-			}
-
-			/* get the reject private data and validate */
-			buf = (unsigned char *)conn_event->private_data;
-			printf(" Recv REJ with pdata %p[0]=%d [47]=%d\n",
-			 buf, buf[0], buf[47]);
-			for (bi = 0; bi < 48; bi++) {
-				if (buf[bi] != idx + 2) {
-					fprintf(stderr, " client: Error"
-						" with REJECT event private"
-						" data: %p[%d]=%d s/be %d\n",
-						 buf, bi, 
-						buf[bi], bi + 2);
-					dat_ep_disconnect(h_ep[i+ii], 0);
-					return (DAT_ABORT);
-				}
-			}
-			printf("\n Rej Test Done. PASSED\n\n");
-			exit(0);
-#endif
-			if ((event.event_number != 
-			    DAT_CONNECTION_EVENT_ESTABLISHED) &&
-			    (ud_test && event.event_number != 
-			    DAT_IB_UD_CONNECTION_EVENT_ESTABLISHED)) {
-				fprintf(stderr, " Error unexpected conn "
-					"event : 0x%x %s\n",
-					 event.event_number,
-					DT_EventToSTr(event.event_number));
-				return (DAT_ABORT);
-			}
-
-			/* check private data back from server  */
-			buf = (unsigned char *)conn_event->private_data;
-
-			LOGPRINTF(" CONN[%d] Private Data "
-				  "%p[0]=%d [47]=%d\n",
-				   i+ii, buf, buf[0], buf[47]);
-
-			for (bi = 0; bi < 48; bi++) {
-				if (buf[bi] != bi + 2) {
-					DAT_COUNT nmore;
-					fprintf(stderr, " ERR CONN event"
-						" pdata: %p[%d]=%d s/be %d\n",
-						 buf, bi, buf[bi], 
-						bi + 2);
-					dat_ep_disconnect(h_ep[i+ii], 
-						DAT_CLOSE_ABRUPT_FLAG);
-					LOGPRINTF(" waiting for disc...\n");
-					dat_evd_wait(h_conn_evd, 
-						     DAT_TIMEOUT_INFINITE,
-						     1, &event, &nmore); 
-					return (DAT_ABORT);
-				}
-			}
-			event.event_number = 0;
-		} 
-	}
-
-      	stop = get_time();
-       	ts.conn += ((stop - start) * 1.0e6);
-
-	if (!ucm)
-		freeaddrinfo(target);
-
-	printf("\n ALL %d CONNECTED on Client!\n\n",  connections);
-
-	return (DAT_SUCCESS);
-}
-
-/* validate disconnected EP's and free them */
-DAT_RETURN disconnect_eps(void)
-{
-	DAT_RETURN ret;
-	DAT_EVENT event;
-	DAT_COUNT nmore;
-	int i,ii;
-	DAT_CONNECTION_EVENT_DATA *conn_event =
-		&event.event_data.connect_event_data;
-
-	if (!connected)
-		return DAT_SUCCESS;
-
-	/* UD, no connection to disconnect, just free EP's */
-	if (ud_test) {
-		for (i = 0; i < connections; i++) {
-			ret = dat_ep_free(h_ep[i]);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr, 
-					" ERR free EP[%d] %p: %s\n",
-					i, h_ep[i], DT_RetToString(ret));
-			} else {
-				LOGPRINTF(" Freed EP[%d] %p\n", 
-					  i, h_ep[i]);
-				h_ep[i] = DAT_HANDLE_NULL;
-			}
-		}
-		stop = get_time();
-		ts.epf += ((stop - start) * 1.0e6);
-		ts.total += ts.epf;
-		return DAT_SUCCESS;
-	}
-	
-	/* 
-	 * Only the client needs to call disconnect. The server _should_ be able
-	 * to just wait on the EVD associated with connection events for a
-	 * disconnect request and then exit.
-	 */
-	if (!server) {
-		start = get_time();
-		for (i = 0; i < connections; i++) {
-			LOGPRINTF(" dat_ep_disconnect\n");
-			ret = dat_ep_disconnect(h_ep[i], 
-						DAT_CLOSE_DEFAULT);
-			if (ret != DAT_SUCCESS) {
-				fprintf(stderr,
-					" Error disconnect: %s\n",
-						DT_RetToString(ret));
-				return ret;
-			} else {
-				LOGPRINTF(" disconnect completed\n");
-			}
-		}
-	} else {
-		LOGPRINTF(" Server waiting for disconnect...\n");
-	}
-
-	LOGPRINTF(" Wait for Disc event, free EPs as completed\n");
-	start = get_time();
-	for (i = 0; i < connections; i++) {
-		event.event_number = 0;
-		conn_event->ep_handle = NULL;
-		ret = dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 
-				   1, &event, &nmore);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error dat_evd_wait: %s\n",
-				DT_RetToString(ret));
-			return ret;
-		} else {
-			LOGPRINTF(" disc event[%d] complete,"
-				  " check for valid EP...\n", i);
-		}
-
-		/* check for valid EP in creation list */
-		for (ii = 0; ii < connections; ii++) {
-			if (h_ep[ii] == conn_event->ep_handle) {
-				LOGPRINTF(" valid EP[%d] %p !\n", 
-					  ii, h_ep[ii]);
-				ret = dat_ep_free(h_ep[ii]);
-				if (ret != DAT_SUCCESS) {
-					fprintf(stderr, 
-						" ERR free EP[%d] %p: %s\n",
-						i, h_ep[ii], 
-						DT_RetToString(ret));
-				} else {
-					LOGPRINTF(" Freed EP[%d] %p\n", 
-						  i, h_ep[ii]);
-					h_ep[ii] = DAT_HANDLE_NULL;
-				}
-				break;
-			} else {
-				continue;
-			}
-		}
-		if (ii == connections) {
-			LOGPRINTF(" %s: invalid EP[%d] %p via DISC event!\n", 
-				  server ? "Server" : "Client", 
-				  i, conn_event->ep_handle);
-			return DAT_INVALID_HANDLE;
-		}
-	}
-	/* free EPs */
-	stop = get_time();
-	ts.epf += ((stop - start) * 1.0e6);
-	ts.total += ts.epf;
-	return DAT_SUCCESS;
-}
-
-
- /*
-  * Create CR, CONN, and DTO events
-  */
-DAT_RETURN create_events(void)
-{
-	DAT_RETURN ret;
-
-	/* create cr EVD */
-	start = get_time();
-	ret = dat_evd_create(h_ia, connections, DAT_HANDLE_NULL, 
-			     DAT_EVD_CR_FLAG, &h_cr_evd);
-	stop = get_time();
-	ts.evdc += ((stop - start) * 1.0e6);
-	ts.total += ts.evdc;
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error dat_evd_create: %s\n",
-			 DT_RetToString(ret));
-		return (ret);
-	} else {
-		LOGPRINTF(" cr_evd created %p\n",  h_cr_evd);
-	}
-
-	/* create conn EVD */
-	ret = dat_evd_create(h_ia,
-			     connections*2,
-			     DAT_HANDLE_NULL,
-			     DAT_EVD_CONNECTION_FLAG, &h_conn_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error dat_evd_create: %s\n",
-			 DT_RetToString(ret));
-		return (ret);
-	} else {
-		LOGPRINTF(" con_evd created %p\n",  h_conn_evd);
-	}
-
-	/* create dto SND EVD */
-	ret = dat_evd_create(h_ia, 1, NULL, 
-			     DAT_EVD_DTO_FLAG, &h_dto_req_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error dat_evd_create REQ: %s\n",
-			 DT_RetToString(ret));
-		return (ret);
-	} else {
-		LOGPRINTF(" dto_req_evd created %p\n", 
-			  h_dto_req_evd);
-	}
-
-	/* create dto RCV EVD */
-	ret = dat_evd_create(h_ia, 1, NULL,
-			     DAT_EVD_DTO_FLAG, &h_dto_rcv_evd);
-	if (ret != DAT_SUCCESS) {
-		fprintf(stderr, " Error dat_evd_create RCV: %s\n",
-			 DT_RetToString(ret));
-		return (ret);
-	} else {
-		LOGPRINTF(" dto_rcv_evd created %p\n", 
-			  h_dto_rcv_evd);
-	}
-	return DAT_SUCCESS;
-}
-
-/*
- * Destroy CR, CONN, CNO, and DTO events
- */
-
-DAT_RETURN destroy_events(void)
-{
-	DAT_RETURN ret;
-
-	/* free cr EVD */
-	if (h_cr_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF(" Free cr EVD %p \n",  h_cr_evd);
-		ret = dat_evd_free(h_cr_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error freeing cr EVD: %s\n",
-				 DT_RetToString(ret));
-			return (ret);
-		} else {
-			LOGPRINTF(" Freed cr EVD\n");
-			h_cr_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free conn EVD */
-	if (h_conn_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF(" Free conn EVD %p\n",  h_conn_evd);
-		ret = dat_evd_free(h_conn_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error freeing conn EVD: %s\n",
-				 DT_RetToString(ret));
-			return (ret);
-		} else {
-			LOGPRINTF(" Freed conn EVD\n");
-			h_conn_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free RCV dto EVD */
-	if (h_dto_rcv_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF(" Free RCV dto EVD %p\n",  h_dto_rcv_evd);
-		start = get_time();
-		ret = dat_evd_free(h_dto_rcv_evd);
-		stop = get_time();
-		ts.evdf += ((stop - start) * 1.0e6);
-		ts.total += ts.evdf;
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error freeing dto EVD: %s\n",
-				 DT_RetToString(ret));
-			return (ret);
-		} else {
-			LOGPRINTF(" Freed dto EVD\n");
-			h_dto_rcv_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	/* free REQ dto EVD */
-	if (h_dto_req_evd != DAT_HANDLE_NULL) {
-		LOGPRINTF(" Free REQ dto EVD %p\n",  h_dto_req_evd);
-		ret = dat_evd_free(h_dto_req_evd);
-		if (ret != DAT_SUCCESS) {
-			fprintf(stderr, " Error freeing dto EVD: %s\n",
-				 DT_RetToString(ret));
-			return (ret);
-		} else {
-			LOGPRINTF(" Freed dto EVD\n");
-			h_dto_req_evd = DAT_HANDLE_NULL;
-		}
-	}
-
-	return DAT_SUCCESS;
-}
-
-/*
- * Map DAT_RETURN values to readable strings,
- * but don't assume the values are zero-based or contiguous.
- */
-char errmsg[512] = { 0 };
-const char *DT_RetToString(DAT_RETURN ret_value)
-{
-	const char *major_msg, *minor_msg;
-
-	dat_strerror(ret_value, &major_msg, &minor_msg);
-
-	strcpy(errmsg, major_msg);
-	strcat(errmsg, " ");
-	strcat(errmsg, minor_msg);
-
-	return errmsg;
-}
-
-/*
- * Map DAT_EVENT_CODE values to readable strings
- */
-const char *DT_EventToSTr(DAT_EVENT_NUMBER event_code)
-{
-	unsigned int i;
-	static struct {
-		const char *name;
-		DAT_RETURN value;
-	} dat_events[] = {
-#   define DATxx(x) { # x, x }
-		DATxx(DAT_DTO_COMPLETION_EVENT),
-		    DATxx(DAT_RMR_BIND_COMPLETION_EVENT),
-		    DATxx(DAT_CONNECTION_REQUEST_EVENT),
-		    DATxx(DAT_CONNECTION_EVENT_ESTABLISHED),
-		    DATxx(DAT_CONNECTION_EVENT_PEER_REJECTED),
-		    DATxx(DAT_CONNECTION_EVENT_NON_PEER_REJECTED),
-		    DATxx(DAT_CONNECTION_EVENT_ACCEPT_COMPLETION_ERROR),
-		    DATxx(DAT_CONNECTION_EVENT_DISCONNECTED),
-		    DATxx(DAT_CONNECTION_EVENT_BROKEN),
-		    DATxx(DAT_CONNECTION_EVENT_TIMED_OUT),
-		    DATxx(DAT_CONNECTION_EVENT_UNREACHABLE),
-		    DATxx(DAT_ASYNC_ERROR_EVD_OVERFLOW),
-		    DATxx(DAT_ASYNC_ERROR_IA_CATASTROPHIC),
-		    DATxx(DAT_ASYNC_ERROR_EP_BROKEN),
-		    DATxx(DAT_ASYNC_ERROR_TIMED_OUT),
-		    DATxx(DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR),
-		    DATxx(DAT_SOFTWARE_EVENT)
-#   undef DATxx
-	};
-#   define NUM_EVENTS (sizeof(dat_events)/sizeof(dat_events[0]))
-
-	for (i = 0; i < NUM_EVENTS; i++) {
-		if (dat_events[i].value == event_code) {
-			return (dat_events[i].name);
-		}
-	}
-
-	return ("Invalid_DAT_EVENT_NUMBER");
-}
-
-void print_usage(void)
-{
-	printf("\n DAPL USAGE \n\n");
-	printf("s: server\n");
-	printf("c: connections (default = 1000)\n");
-	printf("v: verbose\n");
-	printf("w: wait on event (default, polling)\n");
-	printf("d: delay before accept\n");
-	printf("h: hostname/address of server, specified on client\n");
-	printf("P: provider name (default = OpenIB-v2-ib0)\n");
-	printf("\n");
-}
-
+/*
+ * Copyright (c) 2009 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
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef DAPL_PROVIDER
+#undef DAPL_PROVIDER
+#endif
+
+#if defined(_WIN32) || defined(_WIN64)
+
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <io.h>
+#include <process.h>
+#include <complib/cl_types.h>
+#include "..\..\..\..\etc\user\getopt.c"
+
+#define getpid() ((int)GetCurrentProcessId())
+#define F64x "%I64x"
+#define F64d "%I64d"
+
+#if DBG
+#define DAPL_PROVIDER "ibnic0v2d"
+#else
+#define DAPL_PROVIDER "ibnic0v2"
+#endif
+
+#define ntohll _byteswap_uint64
+#define htonll _byteswap_uint64
+
+#else // _WIN32 || _WIN64
+
+#include <endian.h>
+#include <byteswap.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <sys/mman.h>
+#include <getopt.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define DAPL_PROVIDER "ofa-v2-ib0"
+
+#define F64x "%"PRIx64""
+#define F64d "%"PRId64""
+
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define htonll(x) (x)
+#define ntohll(x) (x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define htonll(x)  bswap_64(x)
+#define ntohll(x)  bswap_64(x)
+#endif
+
+#endif // _WIN32 || _WIN64
+
+#define MAX_POLLING_CNT 50000
+
+/* Header files needed for DAT/uDAPL */
+#include "dat2/udat.h"
+#include "dat2/dat_ib_extensions.h"
+
+/* definitions */
+#define SERVER_CONN_QUAL  45248
+#define CONN_TIMEOUT      (1000*1000*100)
+#define CR_TIMEOUT	  DAT_TIMEOUT_INFINITE
+
+/* Global DAT vars */
+static DAT_IA_HANDLE h_ia = DAT_HANDLE_NULL;
+static DAT_PZ_HANDLE h_pz = DAT_HANDLE_NULL;
+static DAT_EP_HANDLE *h_ep;
+static DAT_PSP_HANDLE *h_psp;
+static DAT_CR_HANDLE h_cr = DAT_HANDLE_NULL;
+
+static DAT_EVD_HANDLE h_async_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_dto_req_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_dto_rcv_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_cr_evd = DAT_HANDLE_NULL;
+static DAT_EVD_HANDLE h_conn_evd = DAT_HANDLE_NULL;
+
+static DAT_EP_ATTR ep_attr;
+char hostname[256] = { 0 };
+char provider[64] = DAPL_PROVIDER;
+char addr_str[INET_ADDRSTRLEN];
+
+int status;
+
+/* timers */
+double start, stop, total_us, total_sec;
+
+struct dt_time {
+	double total;
+	double open;
+	double reg;
+	double unreg;
+	double pzc;
+	double pzf;
+	double evdc;
+	double evdf;
+	double cnoc;
+	double cnof;
+	double epc;
+	double epf;
+	double rtt;
+	double close;
+	double conn;
+};
+
+struct dt_time ts;
+
+/* defaults */
+static int connected = 0;
+static int multi_listens = 0;
+static int ud_test = 0;
+static int server = 1;
+static int waiting = 0;
+static int verbose = 0;
+static int cr_poll_count = 0;
+static int conn_poll_count = 0;
+static int delay = 0;
+static int connections = 1000;
+static int burst = 100;
+static int port_id = SERVER_CONN_QUAL;
+static int ucm = 0;
+static DAT_SOCK_ADDR6 remote;
+
+/* forward prototypes */
+const char *DT_RetToString(DAT_RETURN ret_value);
+const char *DT_EventToSTr(DAT_EVENT_NUMBER event_code);
+void print_usage(void);
+double get_time(void);
+DAT_RETURN conn_client(void);
+DAT_RETURN conn_server(void);
+DAT_RETURN disconnect_eps(void);
+DAT_RETURN create_events(void);
+DAT_RETURN destroy_events(void);
+
+#define LOGPRINTF if (verbose) printf
+
+void flush_evds(void)
+{
+	DAT_EVENT event;
+
+	/* Flush async error queue */
+	printf(" ERR: Checking ASYNC EVD...\n");
+	while (dat_evd_dequeue(h_async_evd, &event) == DAT_SUCCESS) {
+		printf(" ASYNC EVD ENTRY: handle=%p reason=%d\n",
+			event.event_data.asynch_error_event_data.dat_handle,
+			event.event_data.asynch_error_event_data.reason);
+	}
+}
+
+static void print_ia_address(struct sockaddr *sa)
+{
+	char str[INET6_ADDRSTRLEN] = {" ??? "};
+
+	switch(sa->sa_family) {
+	case AF_INET:
+		inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, str, INET6_ADDRSTRLEN);
+		printf("%d Local Address AF_INET - %s port %d\n", getpid(), str, SERVER_CONN_QUAL);
+		break;
+	case AF_INET6:
+		inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, str, INET6_ADDRSTRLEN);
+		printf("%d Local Address AF_INET6 - %s flowinfo(QPN)=0x%x, port(LID)=0x%x\n",
+			getpid(), str,
+			ntohl(((struct sockaddr_in6 *)sa)->sin6_flowinfo),
+			ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
+		break;
+	default:
+		printf("%d Local Address UNKOWN FAMILY - port %d\n", getpid(), SERVER_CONN_QUAL);
+	}
+}
+
+int main(int argc, char **argv)
+{
+	int i, c, len;
+	DAT_RETURN ret;
+	DAT_IA_ATTR ia_attr;
+	
+	/* parse arguments */
+	while ((c = getopt(argc, argv, "smwvub:c:d:h:P:p:q:l:")) != -1) {
+		switch (c) {
+		case 's':
+			server = 1;
+			break;
+		case 'm':
+			multi_listens = 1;
+			break;
+		case 'w':
+			waiting = 1;
+			break;
+		case 'u':
+			ud_test = 1;
+			break;
+		case 'c':
+			connections = atoi(optarg);
+			break;
+		case 'p':
+			port_id = atoi(optarg);
+			break;
+		case 'v':
+			verbose = 1;
+			fflush(stdout);
+			break;
+		case 'd':
+			delay = atoi(optarg);
+			break;
+		case 'b':
+			burst = atoi(optarg);
+			break;
+		case 'h':
+			server = 0;
+			strcpy(hostname, optarg);
+			break;
+		case 'P':
+			strcpy(provider, optarg);
+			break;
+		case 'q':
+			/* map UCM qpn into AF_INET6 sin6_flowinfo */
+			remote.sin6_family = AF_INET6;
+			remote.sin6_flowinfo = htonl(strtol(optarg,NULL,0));
+			ucm = 1;
+			server = 0;
+			break;
+		case 'l':
+			/* map UCM lid into AF_INET6 sin6_port */
+			remote.sin6_family = AF_INET6;
+			remote.sin6_port = htons(strtol(optarg,NULL,0));
+			ucm = 1;
+			server = 0;
+			break;
+		default:
+			print_usage();
+			exit(-12);
+		}
+	}
+
+#if defined(_WIN32) || defined(_WIN64)
+	{
+		WSADATA wsaData;
+
+		i = WSAStartup(MAKEWORD(2, 2), &wsaData);
+		if (i != 0) {
+			printf("%s WSAStartup(2.2) failed? (0x%x)\n", argv[0],
+			       i);
+			fflush(stdout);
+			exit(1);
+		}
+	}
+#endif
+
+	if (!server) {
+		printf(" Running client on %s with %d %s connections\n", 
+			provider, connections, ud_test ? "UD" : "RC");
+	} else {
+		printf(" Running server on %s with %d %s connections\n", 
+			provider, connections, ud_test ? "UD" : "RC");
+	}
+	fflush(stdout);
+	
+	if (burst > connections)
+		burst = connections;
+
+	
+	/* allocate EP handles for all connections */
+	h_ep = (DAT_EP_HANDLE*)malloc(connections * sizeof(DAT_EP_HANDLE));
+	if (h_ep == NULL) {	
+		perror("malloc ep");
+		exit(1);
+	}
+	memset(h_ep, 0, (burst * sizeof(DAT_PSP_HANDLE)));
+	
+	/* allocate PSP handles, check for multi-listens */
+	if (multi_listens)
+		len = burst * sizeof(DAT_PSP_HANDLE);
+	else
+		len = sizeof(DAT_PSP_HANDLE);
+
+	h_psp = (DAT_PSP_HANDLE*)malloc(len);
+	if (h_psp == NULL) {	
+		perror("malloc psp");
+		exit(1);
+	}
+	memset(h_psp, 0, len);
+	memset(&ts, 0, sizeof(struct dt_time));
+
+	/* dat_ia_open, dat_pz_create */
+	h_async_evd = DAT_HANDLE_NULL;
+	start = get_time();
+	ret = dat_ia_open(provider, 8, &h_async_evd, &h_ia);
+	stop = get_time();
+	ts.open += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error Adaptor open: %s\n",
+			DT_RetToString(ret));
+		exit(1);
+	} else
+		LOGPRINTF(" Opened Interface Adaptor\n");
+
+	/* query for UCM addressing */
+	ret = dat_ia_query(h_ia, 0, DAT_IA_FIELD_ALL, &ia_attr, 0, 0);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, "%d: Error Adaptor query: %s\n",
+			getpid(), DT_RetToString(ret));
+		exit(1);
+	}
+	print_ia_address(ia_attr.ia_address_ptr);
+
+	/* Create Protection Zone */
+	start = get_time();
+	LOGPRINTF(" Create Protection Zone\n");
+	ret = dat_pz_create(h_ia, &h_pz);
+	stop = get_time();
+	ts.pzc += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error creating Protection Zone: %s\n",
+			DT_RetToString(ret));
+		exit(1);
+	} else
+		LOGPRINTF(" Created Protection Zone\n");
+
+	LOGPRINTF(" Create events\n");
+	ret = create_events();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error creating events: %s\n",
+			DT_RetToString(ret));
+		goto cleanup;
+	} else {
+		LOGPRINTF(" Create events done\n");
+	}
+
+	/* create EP */
+	memset(&ep_attr, 0, sizeof(ep_attr));
+	if (ud_test) {
+		ep_attr.service_type = DAT_IB_SERVICE_TYPE_UD;
+		ep_attr.max_message_size = 2048;
+	} else {
+		ep_attr.service_type = DAT_SERVICE_TYPE_RC;
+		ep_attr.max_rdma_size = 0x10000;
+		ep_attr.max_rdma_read_in = 4;
+		ep_attr.max_rdma_read_out = 4;
+	}
+	ep_attr.max_recv_dtos = 1;
+	ep_attr.max_request_dtos = 1;
+	ep_attr.max_recv_iov = 1;
+	ep_attr.max_request_iov = 1;
+	ep_attr.request_completion_flags = DAT_COMPLETION_DEFAULT_FLAG;
+	
+	start = get_time();
+	for (i = 0; i < connections; i++) {
+		ret = dat_ep_create(h_ia, h_pz, h_dto_rcv_evd,
+				    h_dto_req_evd, h_conn_evd, 
+				    &ep_attr, &h_ep[i]);
+	}
+	stop = get_time();
+	ts.epc += ((stop - start) * 1.0e6);
+	ts.total += ts.epc;
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error dat_ep_create: %s\n",
+			DT_RetToString(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF(" EP created %p \n", h_ep[i]);
+
+	/* create the service point for server listen */
+	if (server) {
+		LOGPRINTF(" Creating server service point(s)\n");
+		for (i = 0; i < burst; i++) {
+			ret = dat_psp_create(h_ia,
+					     port_id+i,
+					     h_cr_evd, 
+					     DAT_PSP_CONSUMER_FLAG, 
+					     &h_psp[i]);
+
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, " ERR psp_create: %s\n",
+					DT_RetToString(ret));
+				goto cleanup;
+			} else
+				LOGPRINTF(" psp_created for listen\n");
+
+			printf(" Server ready on port %d\n", 
+				port_id+i);
+
+			if (!multi_listens)
+				break;
+		}
+	}
+	
+	/* Connect all */
+	if (server)
+		ret = conn_server();
+	else	
+		ret = conn_client();
+	
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error %s: %s\n",
+			 server ? "server()" : "client()",
+			DT_RetToString(ret));
+		goto cleanup;
+	} else
+		LOGPRINTF(" connect_ep complete\n");
+
+	connected = 1;
+	goto complete;
+
+cleanup:
+	flush_evds();
+	goto bail;
+complete:
+
+	/* disconnect and free EP resources */
+	if (h_ep[0]) {
+		/* unregister message buffers and tear down connection */
+		LOGPRINTF(" Disconnect EPs\n");
+		ret = disconnect_eps();
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error disconnect_eps: %s\n",
+				DT_RetToString(ret));
+			goto bail;
+		} else {
+			LOGPRINTF(" disconnect_eps complete\n");
+		}
+	}
+
+	/* destroy server service point(s) */
+	if ((server) && (h_psp[0] != DAT_HANDLE_NULL)) {
+		for (i = 0; i < burst; i++) {
+			ret = dat_psp_free(h_psp[i]);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, " Error dat_psp_free: %s\n",
+					DT_RetToString(ret));
+				goto bail;
+			} else {
+				LOGPRINTF(" psp_free[%d] complete\n",i);
+			}
+			if (!multi_listens)
+				break;
+		}
+	}
+
+	/* free EVDs */
+	LOGPRINTF(" destroy events\n");
+	ret = destroy_events();
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error destroy_events: %s\n",
+			DT_RetToString(ret));
+		goto bail;
+	} else
+		LOGPRINTF(" destroy events done\n");
+
+
+	/* Free protection domain */
+	LOGPRINTF(" Freeing pz\n");
+	start = get_time();
+	ret = dat_pz_free(h_pz);
+	stop = get_time();
+	ts.pzf += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error freeing PZ: %s\n",
+			DT_RetToString(ret));
+		goto bail;
+	} else {
+		LOGPRINTF(" Freed pz\n");
+		h_pz = NULL;
+	}
+
+	/* close the device */
+	LOGPRINTF(" Closing Interface Adaptor\n");
+	start = get_time();
+	ret = dat_ia_close(h_ia, DAT_CLOSE_ABRUPT_FLAG);
+	stop = get_time();
+	ts.close += ((stop - start) * 1.0e6);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error Adaptor close: %s\n",
+			DT_RetToString(ret));
+		goto bail;
+	} else
+		LOGPRINTF(" Closed Interface Adaptor\n");
+
+	printf(" DAPL Connection Test Complete.\n");
+	printf(" open:      %10.2lf usec\n", ts.open);
+	printf(" close:     %10.2lf usec\n", ts.close);
+	printf(" PZ create: %10.2lf usec\n", ts.pzc);
+	printf(" PZ free:   %10.2lf usec\n", ts.pzf);
+	printf(" LMR create:%10.2lf usec\n", ts.reg);
+	printf(" LMR free:  %10.2lf usec\n", ts.unreg);
+	printf(" EVD create:%10.2lf usec\n", ts.evdc);
+	printf(" EVD free:  %10.2lf usec\n", ts.evdf);
+	printf(" EP create: %10.2lf usec avg\n", ts.epc/connections);
+	printf(" EP free:   %10.2lf usec avg\n", ts.epf/connections);
+	if (!server) {
+		printf(" Connections: %8.2lf usec, CPS %7.2lf "
+			"Total %4.2lf secs, poll_cnt=%u, Num=%d\n", 
+		       (double)(ts.conn/connections), 
+		       (double)(1/(ts.conn/1000000/connections)), 
+		       (double)(ts.conn/1000000), 
+		       conn_poll_count, connections);
+	}
+	printf(" TOTAL:     %4.2lf sec\n",  ts.total/1000000);
+	fflush(stderr);	fflush(stdout);
+bail:
+	free(h_ep);
+	free(h_psp);
+
+#if defined(_WIN32) || defined(_WIN64)
+	WSACleanup();
+#endif
+	return (0);
+}
+
+double get_time(void)
+{
+	struct timeval tp;
+
+	gettimeofday(&tp, NULL);
+	return ((double)tp.tv_sec + (double)tp.tv_usec * 1e-6);
+}
+
+DAT_RETURN conn_server()
+{
+	DAT_RETURN ret;
+	DAT_EVENT event;
+	DAT_COUNT nmore;
+	int i,bi;
+	unsigned char *buf;
+	DAT_CR_ARRIVAL_EVENT_DATA *cr_event =
+		&event.event_data.cr_arrival_event_data;
+	DAT_CR_PARAM cr_param = { 0 };
+	
+	printf(" Accepting...\n");
+	for (i = 0; i < connections; i++) {
+					
+		/* poll for CR's */
+		if (!waiting) {
+			cr_poll_count = 0;
+			while (DAT_GET_TYPE(dat_evd_dequeue(h_cr_evd, &event)) 
+					== DAT_QUEUE_EMPTY)
+				cr_poll_count++;
+		} else {
+			ret = dat_evd_wait(h_cr_evd, CR_TIMEOUT, 
+					   1, &event, &nmore);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr,
+					" ERR: CR dat_evd_wait() %s\n",
+					 DT_RetToString(ret));
+				return ret;
+			}
+		}
+	
+		if ((event.event_number != DAT_CONNECTION_REQUEST_EVENT) &&
+		    (ud_test && event.event_number != 
+		     DAT_IB_UD_CONNECTION_REQUEST_EVENT)) {
+				fprintf(stderr, " Error unexpected CR event : %s\n",
+					DT_EventToSTr(event.event_number));
+				return (DAT_ABORT);
+		}
+
+		
+		/* use to test rdma_cma timeout logic */
+#if defined(_WIN32) || defined(_WIN64)
+		if (delay) {
+			printf(" Accept delayed by %d seconds...\n", delay);
+			Sleep(delay * 1000);
+		}
+#else
+		if (delay) {
+			printf(" Accept delayed by %d seconds...\n", delay);
+			sleep(delay);
+		}
+#endif
+		/* accept connect request from client */
+		h_cr = cr_event->cr_handle;
+		LOGPRINTF(" Accepting connect request from client\n");
+
+		/* private data - check and send it back */
+		dat_cr_query(h_cr, DAT_CSP_FIELD_ALL, &cr_param);
+
+		buf = (unsigned char *)cr_param.private_data;
+		LOGPRINTF(" CONN REQUEST Private Data %p[0]=%d [47]=%d\n",
+			   buf, buf[0], buf[47]);
+		
+		for (bi = 0; bi < 48; bi++) {
+			if (buf[bi] != bi + 1) {
+				fprintf(stderr, " ERR on CONNECT REQUEST"
+					" private data: %p[%d]=%d s/be %d\n",
+					 buf, bi, buf[bi], bi + 1);
+				dat_cr_reject(h_cr, 0, NULL);
+				return (DAT_ABORT);
+			}
+			buf[bi]++;	/* change for trip back */
+		}
+
+#ifdef TEST_REJECT_WITH_PRIVATE_DATA
+		printf(" REJECT request with 48 bytes of private data\n");
+		ret = dat_cr_reject(h_cr, 48, cr_param.private_data);
+		printf("\n DAPL Test Complete. %s\n\n",
+		        ret ? "FAILED" : "PASSED");
+		exit(0);
+#endif
+		ret = dat_cr_accept(h_cr, h_ep[i], 48, 
+				    cr_param.private_data);
+
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " ERR dat_cr_accept: %s\n",
+				DT_RetToString(ret));
+			return (ret);
+		} else
+			LOGPRINTF(" accept[%d] complete\n", i);
+	
+		event.event_number = 0;
+	}
+
+	/* process the RTU, ESTABLISHMENT event */
+	printf(" Completing...\n");
+        for (i=0;i<connections;i++) {
+		
+		/* process completions */
+		if (!waiting) {
+			conn_poll_count = 0;
+			while (DAT_GET_TYPE(dat_evd_dequeue(h_conn_evd, 
+					    &event)) == DAT_QUEUE_EMPTY)
+				conn_poll_count++;
+		} else {
+			ret = dat_evd_wait(h_conn_evd, CONN_TIMEOUT, 
+					   1, &event, &nmore);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr,
+					" ERR: CONN evd_wait() %s\n",
+					 DT_RetToString(ret));
+				return ret;
+			}
+		}
+		if ((event.event_number != DAT_CONNECTION_EVENT_ESTABLISHED) &&
+		    (ud_test && event.event_number != 
+		     DAT_IB_UD_CONNECTION_EVENT_ESTABLISHED)) {
+
+			fprintf(stderr, " Error unexpected CR EST "
+				"event : 0x%x %s\n",
+				 event.event_number,
+				DT_EventToSTr(event.event_number));
+			return (DAT_ABORT);
+		}
+		event.event_number = 0;
+		LOGPRINTF(" CONN_EST[%d] complete\n", i);
+	}
+
+	printf("\n ALL %d CONNECTED on Server!\n\n", connections);
+	return DAT_SUCCESS;
+}
+
+	
+DAT_RETURN conn_client() 
+{
+	DAT_IA_ADDRESS_PTR raddr = (DAT_IA_ADDRESS_PTR)&remote;
+	DAT_RETURN ret;
+	DAT_EVENT event;
+	DAT_COUNT nmore;
+	DAT_CONN_QUAL conn_id;
+	DAT_CONNECTION_EVENT_DATA *conn_event =
+		&event.event_data.connect_event_data;
+	int i,ii,bi;
+	unsigned char *buf;
+	unsigned char pdata[48] = { 0 };
+	struct addrinfo *target;
+	int rval;
+
+	if (ucm)
+		goto no_resolution;
+
+#if defined(_WIN32) || defined(_WIN64)
+	if ((rval = getaddrinfo(hostname, "ftp", NULL, &target)) != 0) {
+		printf("\n remote name resolution failed! %s\n",
+			gai_strerror(rval));
+		exit(1);
+	}
+	rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
+#else
+	if (getaddrinfo(hostname, NULL, NULL, &target) != 0) {
+		perror("\n remote name resolution failed!");
+		exit(1);
+	}
+	rval = ((struct sockaddr_in *)target->ai_addr)->sin_addr.s_addr;
+#endif
+	printf(" Connecting to Server: %s \n",  hostname);
+	printf(" Address: %d.%d.%d.%d port %d\n",
+		(rval >> 0) & 0xff, (rval >> 8) & 0xff,
+		(rval >> 16) & 0xff, (rval >> 24) & 0xff, 
+		port_id);
+
+	raddr = (DAT_IA_ADDRESS_PTR)target->ai_addr;
+	
+no_resolution:
+
+	for (i = 0; i < 48; i++) /* simple pattern in private data */
+		pdata[i] = i + 1;
+
+       	printf(" Connecting...\n");
+	start = get_time();
+	for (i = 0; i < connections; i += burst) {
+		for (ii = 0; ii < burst; ii++) { /* conn_reqs */
+			if (multi_listens)
+				conn_id = port_id + ii;
+			else
+				conn_id = port_id;
+
+			ret = dat_ep_connect(h_ep[i+ii], raddr, 
+					     conn_id, CONN_TIMEOUT,
+					     48, (DAT_PVOID) pdata, 0, 
+					     DAT_CONNECT_DEFAULT_FLAG);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, " ERR dat_ep_connect: %s\n",
+					DT_RetToString(ret));
+				return (ret);
+			} else
+				LOGPRINTF(" dat_ep_connect[%d] complete\n", 
+					  i+ii);
+
+		} 
+		for (ii = 0; ii < burst; ii++) { /* conn_events */
+			if (!waiting) {
+				conn_poll_count = 0;
+				while (DAT_GET_TYPE(dat_evd_dequeue(
+					h_conn_evd, &event)) == 
+					DAT_QUEUE_EMPTY)
+					conn_poll_count++;
+			} else {
+				ret = dat_evd_wait(h_conn_evd, CONN_TIMEOUT, 
+						   1, &event, &nmore);
+
+				if (ret != DAT_SUCCESS) {
+					fprintf(stderr,
+						" ERR: CONN evd_wait() %s\n",
+						DT_RetToString(ret));
+					return ret;
+				}
+			}
+
+#ifdef TEST_REJECT_WITH_PRIVATE_DATA
+			if (event.event_number != 
+				DAT_CONNECTION_EVENT_PEER_REJECTED) {
+				fprintf(stderr, " expected conn reject "
+					"event : %s\n",
+					DT_EventToSTr(event.event_number));
+				return (DAT_ABORT);
+			}
+
+			/* get the reject private data and validate */
+			buf = (unsigned char *)conn_event->private_data;
+			printf(" Recv REJ with pdata %p[0]=%d [47]=%d\n",
+			 buf, buf[0], buf[47]);
+			for (bi = 0; bi < 48; bi++) {
+				if (buf[bi] != idx + 2) {
+					fprintf(stderr, " client: Error"
+						" with REJECT event private"
+						" data: %p[%d]=%d s/be %d\n",
+						 buf, bi, 
+						buf[bi], bi + 2);
+					dat_ep_disconnect(h_ep[i+ii], 0);
+					return (DAT_ABORT);
+				}
+			}
+			printf("\n Rej Test Done. PASSED\n\n");
+			exit(0);
+#endif
+			if ((event.event_number != 
+			    DAT_CONNECTION_EVENT_ESTABLISHED) &&
+			    (ud_test && event.event_number != 
+			    DAT_IB_UD_CONNECTION_EVENT_ESTABLISHED)) {
+				fprintf(stderr, " Error unexpected conn "
+					"event : 0x%x %s\n",
+					 event.event_number,
+					DT_EventToSTr(event.event_number));
+				return (DAT_ABORT);
+			}
+
+			/* check private data back from server  */
+			buf = (unsigned char *)conn_event->private_data;
+
+			LOGPRINTF(" CONN[%d] Private Data "
+				  "%p[0]=%d [47]=%d\n",
+				   i+ii, buf, buf[0], buf[47]);
+
+			for (bi = 0; bi < 48; bi++) {
+				if (buf[bi] != bi + 2) {
+					DAT_COUNT nmore;
+					fprintf(stderr, " ERR CONN event"
+						" pdata: %p[%d]=%d s/be %d\n",
+						 buf, bi, buf[bi], 
+						bi + 2);
+					dat_ep_disconnect(h_ep[i+ii], 
+						DAT_CLOSE_ABRUPT_FLAG);
+					LOGPRINTF(" waiting for disc...\n");
+					dat_evd_wait(h_conn_evd, 
+						     DAT_TIMEOUT_INFINITE,
+						     1, &event, &nmore); 
+					return (DAT_ABORT);
+				}
+			}
+			event.event_number = 0;
+		} 
+	}
+
+      	stop = get_time();
+       	ts.conn += ((stop - start) * 1.0e6);
+
+	if (!ucm)
+		freeaddrinfo(target);
+
+	printf("\n ALL %d CONNECTED on Client!\n\n",  connections);
+
+	return (DAT_SUCCESS);
+}
+
+/* validate disconnected EP's and free them */
+DAT_RETURN disconnect_eps(void)
+{
+	DAT_RETURN ret;
+	DAT_EVENT event;
+	DAT_COUNT nmore;
+	int i,ii;
+	DAT_CONNECTION_EVENT_DATA *conn_event =
+		&event.event_data.connect_event_data;
+
+	if (!connected)
+		return DAT_SUCCESS;
+
+	/* UD, no connection to disconnect, just free EP's */
+	if (ud_test) {
+		for (i = 0; i < connections; i++) {
+			ret = dat_ep_free(h_ep[i]);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr, 
+					" ERR free EP[%d] %p: %s\n",
+					i, h_ep[i], DT_RetToString(ret));
+			} else {
+				LOGPRINTF(" Freed EP[%d] %p\n", 
+					  i, h_ep[i]);
+				h_ep[i] = DAT_HANDLE_NULL;
+			}
+		}
+		stop = get_time();
+		ts.epf += ((stop - start) * 1.0e6);
+		ts.total += ts.epf;
+		return DAT_SUCCESS;
+	}
+	
+	/* 
+	 * Only the client needs to call disconnect. The server _should_ be able
+	 * to just wait on the EVD associated with connection events for a
+	 * disconnect request and then exit.
+	 */
+	if (!server) {
+		start = get_time();
+		for (i = 0; i < connections; i++) {
+			LOGPRINTF(" dat_ep_disconnect\n");
+			ret = dat_ep_disconnect(h_ep[i], 
+						DAT_CLOSE_DEFAULT);
+			if (ret != DAT_SUCCESS) {
+				fprintf(stderr,
+					" Error disconnect: %s\n",
+						DT_RetToString(ret));
+				return ret;
+			} else {
+				LOGPRINTF(" disconnect completed\n");
+			}
+		}
+	} else {
+		LOGPRINTF(" Server waiting for disconnect...\n");
+	}
+
+	LOGPRINTF(" Wait for Disc event, free EPs as completed\n");
+	start = get_time();
+	for (i = 0; i < connections; i++) {
+		event.event_number = 0;
+		conn_event->ep_handle = NULL;
+		ret = dat_evd_wait(h_conn_evd, DAT_TIMEOUT_INFINITE, 
+				   1, &event, &nmore);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error dat_evd_wait: %s\n",
+				DT_RetToString(ret));
+			return ret;
+		} else {
+			LOGPRINTF(" disc event[%d] complete,"
+				  " check for valid EP...\n", i);
+		}
+
+		/* check for valid EP in creation list */
+		for (ii = 0; ii < connections; ii++) {
+			if (h_ep[ii] == conn_event->ep_handle) {
+				LOGPRINTF(" valid EP[%d] %p !\n", 
+					  ii, h_ep[ii]);
+				ret = dat_ep_free(h_ep[ii]);
+				if (ret != DAT_SUCCESS) {
+					fprintf(stderr, 
+						" ERR free EP[%d] %p: %s\n",
+						i, h_ep[ii], 
+						DT_RetToString(ret));
+				} else {
+					LOGPRINTF(" Freed EP[%d] %p\n", 
+						  i, h_ep[ii]);
+					h_ep[ii] = DAT_HANDLE_NULL;
+				}
+				break;
+			} else {
+				continue;
+			}
+		}
+		if (ii == connections) {
+			LOGPRINTF(" %s: invalid EP[%d] %p via DISC event!\n", 
+				  server ? "Server" : "Client", 
+				  i, conn_event->ep_handle);
+			return DAT_INVALID_HANDLE;
+		}
+	}
+	/* free EPs */
+	stop = get_time();
+	ts.epf += ((stop - start) * 1.0e6);
+	ts.total += ts.epf;
+	return DAT_SUCCESS;
+}
+
+
+ /*
+  * Create CR, CONN, and DTO events
+  */
+DAT_RETURN create_events(void)
+{
+	DAT_RETURN ret;
+
+	/* create cr EVD */
+	start = get_time();
+	ret = dat_evd_create(h_ia, connections, DAT_HANDLE_NULL, 
+			     DAT_EVD_CR_FLAG, &h_cr_evd);
+	stop = get_time();
+	ts.evdc += ((stop - start) * 1.0e6);
+	ts.total += ts.evdc;
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error dat_evd_create: %s\n",
+			 DT_RetToString(ret));
+		return (ret);
+	} else {
+		LOGPRINTF(" cr_evd created %p\n",  h_cr_evd);
+	}
+
+	/* create conn EVD */
+	ret = dat_evd_create(h_ia,
+			     connections*2,
+			     DAT_HANDLE_NULL,
+			     DAT_EVD_CONNECTION_FLAG, &h_conn_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error dat_evd_create: %s\n",
+			 DT_RetToString(ret));
+		return (ret);
+	} else {
+		LOGPRINTF(" con_evd created %p\n",  h_conn_evd);
+	}
+
+	/* create dto SND EVD */
+	ret = dat_evd_create(h_ia, 1, NULL, 
+			     DAT_EVD_DTO_FLAG, &h_dto_req_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error dat_evd_create REQ: %s\n",
+			 DT_RetToString(ret));
+		return (ret);
+	} else {
+		LOGPRINTF(" dto_req_evd created %p\n", 
+			  h_dto_req_evd);
+	}
+
+	/* create dto RCV EVD */
+	ret = dat_evd_create(h_ia, 1, NULL,
+			     DAT_EVD_DTO_FLAG, &h_dto_rcv_evd);
+	if (ret != DAT_SUCCESS) {
+		fprintf(stderr, " Error dat_evd_create RCV: %s\n",
+			 DT_RetToString(ret));
+		return (ret);
+	} else {
+		LOGPRINTF(" dto_rcv_evd created %p\n", 
+			  h_dto_rcv_evd);
+	}
+	return DAT_SUCCESS;
+}
+
+/*
+ * Destroy CR, CONN, CNO, and DTO events
+ */
+
+DAT_RETURN destroy_events(void)
+{
+	DAT_RETURN ret;
+
+	/* free cr EVD */
+	if (h_cr_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF(" Free cr EVD %p \n",  h_cr_evd);
+		ret = dat_evd_free(h_cr_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error freeing cr EVD: %s\n",
+				 DT_RetToString(ret));
+			return (ret);
+		} else {
+			LOGPRINTF(" Freed cr EVD\n");
+			h_cr_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free conn EVD */
+	if (h_conn_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF(" Free conn EVD %p\n",  h_conn_evd);
+		ret = dat_evd_free(h_conn_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error freeing conn EVD: %s\n",
+				 DT_RetToString(ret));
+			return (ret);
+		} else {
+			LOGPRINTF(" Freed conn EVD\n");
+			h_conn_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free RCV dto EVD */
+	if (h_dto_rcv_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF(" Free RCV dto EVD %p\n",  h_dto_rcv_evd);
+		start = get_time();
+		ret = dat_evd_free(h_dto_rcv_evd);
+		stop = get_time();
+		ts.evdf += ((stop - start) * 1.0e6);
+		ts.total += ts.evdf;
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error freeing dto EVD: %s\n",
+				 DT_RetToString(ret));
+			return (ret);
+		} else {
+			LOGPRINTF(" Freed dto EVD\n");
+			h_dto_rcv_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	/* free REQ dto EVD */
+	if (h_dto_req_evd != DAT_HANDLE_NULL) {
+		LOGPRINTF(" Free REQ dto EVD %p\n",  h_dto_req_evd);
+		ret = dat_evd_free(h_dto_req_evd);
+		if (ret != DAT_SUCCESS) {
+			fprintf(stderr, " Error freeing dto EVD: %s\n",
+				 DT_RetToString(ret));
+			return (ret);
+		} else {
+			LOGPRINTF(" Freed dto EVD\n");
+			h_dto_req_evd = DAT_HANDLE_NULL;
+		}
+	}
+
+	return DAT_SUCCESS;
+}
+
+/*
+ * Map DAT_RETURN values to readable strings,
+ * but don't assume the values are zero-based or contiguous.
+ */
+char errmsg[512] = { 0 };
+const char *DT_RetToString(DAT_RETURN ret_value)
+{
+	const char *major_msg, *minor_msg;
+
+	dat_strerror(ret_value, &major_msg, &minor_msg);
+
+	strcpy(errmsg, major_msg);
+	strcat(errmsg, " ");
+	strcat(errmsg, minor_msg);
+
+	return errmsg;
+}
+
+/*
+ * Map DAT_EVENT_CODE values to readable strings
+ */
+const char *DT_EventToSTr(DAT_EVENT_NUMBER event_code)
+{
+	unsigned int i;
+	static struct {
+		const char *name;
+		DAT_RETURN value;
+	} dat_events[] = {
+#   define DATxx(x) { # x, x }
+		DATxx(DAT_DTO_COMPLETION_EVENT),
+		    DATxx(DAT_RMR_BIND_COMPLETION_EVENT),
+		    DATxx(DAT_CONNECTION_REQUEST_EVENT),
+		    DATxx(DAT_CONNECTION_EVENT_ESTABLISHED),
+		    DATxx(DAT_CONNECTION_EVENT_PEER_REJECTED),
+		    DATxx(DAT_CONNECTION_EVENT_NON_PEER_REJECTED),
+		    DATxx(DAT_CONNECTION_EVENT_ACCEPT_COMPLETION_ERROR),
+		    DATxx(DAT_CONNECTION_EVENT_DISCONNECTED),
+		    DATxx(DAT_CONNECTION_EVENT_BROKEN),
+		    DATxx(DAT_CONNECTION_EVENT_TIMED_OUT),
+		    DATxx(DAT_CONNECTION_EVENT_UNREACHABLE),
+		    DATxx(DAT_ASYNC_ERROR_EVD_OVERFLOW),
+		    DATxx(DAT_ASYNC_ERROR_IA_CATASTROPHIC),
+		    DATxx(DAT_ASYNC_ERROR_EP_BROKEN),
+		    DATxx(DAT_ASYNC_ERROR_TIMED_OUT),
+		    DATxx(DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR),
+		    DATxx(DAT_SOFTWARE_EVENT)
+#   undef DATxx
+	};
+#   define NUM_EVENTS (sizeof(dat_events)/sizeof(dat_events[0]))
+
+	for (i = 0; i < NUM_EVENTS; i++) {
+		if (dat_events[i].value == event_code) {
+			return (dat_events[i].name);
+		}
+	}
+
+	return ("Invalid_DAT_EVENT_NUMBER");
+}
+
+void print_usage(void)
+{
+	printf("\n DAPL USAGE \n\n");
+	printf("s: server\n");
+	printf("c: connections (default = 1000)\n");
+	printf("v: verbose\n");
+	printf("w: wait on event (default, polling)\n");
+	printf("d: delay before accept\n");
+	printf("h: hostname/address of server, specified on client\n");
+	printf("P: provider name (default = OpenIB-v2-ib0)\n");
+	printf("\n");
+}
+
Index: ulp/dapl2/dapl/ibal/dapl_ibal_util.c
===================================================================
--- ulp/dapl2/dapl/ibal/dapl_ibal_util.c	(revision 3414)
+++ ulp/dapl2/dapl/ibal/dapl_ibal_util.c	(working copy)
@@ -1,2316 +1,2316 @@
-/*
- * Copyright (c) 2005-2007 Intel Corporation. All rights reserved.  
- * Copyright (c) 2002, Network Appliance, Inc. All rights reserved. 
- * 
- * This Software is licensed under the terms of the "Common Public
- * License" a copy of which is in the file LICENSE.txt in the root
- * directory. The license is also available from the Open Source
- * Initiative, see http://www.opensource.org/licenses/cpl.php.
- *
- */
-
-/**********************************************************************
- * 
- * MODULE: dapl_ibal_util.c
- *
- * PURPOSE: Utility routines for access to IBAL APIs
- *
- **********************************************************************/
-
-#include "dapl.h"
-#include "dapl_adapter_util.h"
-#include "dapl_evd_util.h"
-#include "dapl_cr_util.h"
-#include "dapl_lmr_util.h"
-#include "dapl_rmr_util.h"
-#include "dapl_cookie.h"
-#include "dapl_ring_buffer_util.h"
-
-#ifdef DAT_EXTENSIONS
-#include <dat2\dat_ib_extensions.h>
-#endif
-
-#ifndef NO_NAME_SERVICE
-#include "dapl_name_service.h"
-#endif /* NO_NAME_SERVICE */
-
-#include "dapl_ibal_name_service.h"
-
-#define DAPL_IBAL_MAX_CA 4
-#define DAT_ADAPTER_NAME "InfiniHost (Tavor)"
-#define DAT_VENDOR_NAME  "Mellanox Technolgy Inc."
-
-/*
- *  Root data structure for DAPL_IIBA.
- */
-dapl_ibal_root_t        dapl_ibal_root;
-DAPL_HCA_NAME           dapl_ibal_hca_name_array [DAPL_IBAL_MAX_CA] = 
-                            {"IbalHca0", "IbalHca1", "IbalHca2", "IbalHca3"};
-ib_net64_t              *gp_ibal_ca_guid_tbl = NULL;
-
-/*
- * DAT spec does not tie max_mtu_size with IB MTU
- *
-static ib_net32_t dapl_ibal_mtu_table[6] = {0, 256, 512, 1024, 2048, 4096};
- */
-    
-int g_loopback_connection = 0;
-
-
-static cl_status_t
-dapli_init_root_ca_list(
-    IN    dapl_ibal_root_t *root )
-{
-    cl_status_t status;
-
-    cl_qlist_init (&root->ca_head);
-    status = cl_spinlock_init (&root->ca_lock);
-
-    if (status == CL_SUCCESS)
-    {
-        /*
-         * Get the time ready to go but don't start here
-         */
-        root->shutdown = FALSE;
-        root->initialized = TRUE;
-    }
-    else
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DiIRCL: cl_spinlock_init returned %d\n", status );
-        root->initialized = FALSE;
-    }
-    
-    root->h_al = NULL;
-
-    return (status);
-}
-
-
-static cl_status_t
-dapli_destroy_root_ca_list(
-    IN    dapl_ibal_root_t *root )
-{
-
-    root->initialized = FALSE;
-
-    /* 
-     * At this point the lock should not be necessary
-     */
-    if (!cl_is_qlist_empty (&root->ca_head) )
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> Destroying nonempty ca list (%s)\n", "DiDRCL");
-    }
-    cl_spinlock_destroy (&root->ca_lock);
-
-    return CL_SUCCESS;
-}
-
-
-static void
-dapli_shutdown_port_access(
-    IN    dapl_ibal_ca_t    *ca )
-{
-    dapl_ibal_port_t    *p_port;
-
-    TAKE_LOCK( ca->port_lock );
-    {
-        while ( ! cl_is_qlist_empty( &ca->port_head ) )
-        {
-            p_port = (dapl_ibal_port_t *)cl_qlist_remove_head( &ca->port_head );
-            RELEASE_LOCK( ca->port_lock );
-            {
-                REMOVE_REFERENCE( &p_port->refs );
-                REMOVE_REFERENCE( &p_port->ca->refs );
-
-                dapl_os_free (p_port, sizeof (dapl_ibal_port_t));
-            }
-            TAKE_LOCK( ca->port_lock );
-        }
-    }
-    RELEASE_LOCK( ca->port_lock );
-}
-
-
-static void dapli_shutdown_ca_access (void)
-{
-    dapl_ibal_ca_t  *ca;
-
-    if ( dapl_ibal_root.initialized == FALSE )
-    {
-        goto destroy_root;
-    }
-
-    TAKE_LOCK (dapl_ibal_root.ca_lock);
-    {
-        while ( ! cl_is_qlist_empty (&dapl_ibal_root.ca_head) )
-        {
-            ca = (dapl_ibal_ca_t *)
-                                 cl_qlist_remove_head (&dapl_ibal_root.ca_head);
-
-            if (ca->p_ca_attr)
-            {
-                dapl_os_free (ca->p_ca_attr, sizeof (ib_ca_attr_t));
-            }
-
-
-            RELEASE_LOCK (dapl_ibal_root.ca_lock);
-            {
-                dapli_shutdown_port_access (ca);
-                REMOVE_REFERENCE (&ca->refs);
-            }
-            TAKE_LOCK (dapl_ibal_root.ca_lock);
-        }
-    }
-    RELEASE_LOCK (dapl_ibal_root.ca_lock);
-
-destroy_root:
-    /*
-     * Destroy the root CA list and list lock
-     */
-    dapli_destroy_root_ca_list (&dapl_ibal_root);
-
-    /*
-     * Signal we're all done and wake any waiter
-     */
-    dapl_ibal_root.shutdown = FALSE;
-}
-
-
-dapl_ibal_evd_cb_t *
-dapli_find_evd_cb_by_context(
-    IN    void           *context,
-    IN    dapl_ibal_ca_t *ca)
-{
-    dapl_ibal_evd_cb_t *evd_cb = NULL;
-
-    TAKE_LOCK( ca->evd_cb_lock );
-
-    evd_cb = (dapl_ibal_evd_cb_t *) cl_qlist_head( &ca->evd_cb_head );
-    while ( &evd_cb->next != cl_qlist_end( &ca->evd_cb_head ) )
-    {
-        if ( context == evd_cb->context)
-        {
-            goto found;
-        }
-
-        /*
-         *  Try again
-         */
-        evd_cb = (dapl_ibal_evd_cb_t *) cl_qlist_next( &evd_cb->next );
-    }
-    /*
-     *  No joy
-     */
-    evd_cb = NULL;
-
-found:
-
-    RELEASE_LOCK( ca->evd_cb_lock );
-
-    return ( evd_cb );
-}
-
-
-static cl_status_t
-dapli_init_ca_evd_cb_list(
-    IN    dapl_ibal_ca_t    *ca )
-{
-    cl_status_t    status;
-
-    cl_qlist_init( &ca->evd_cb_head );
-    status = cl_spinlock_init( &ca->evd_cb_lock );
-    if ( status != CL_SUCCESS )
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DiICECL: cl_spinlock_init returned %d\n", status);
-    return ( status );
-}
-
-
-static cl_status_t
-dapli_init_ca_port_list(
-    IN    dapl_ibal_ca_t    *ca )
-{
-    cl_status_t    status;
-
-    cl_qlist_init( &ca->port_head );
-    status = cl_spinlock_init( &ca->port_lock );
-    if ( status != CL_SUCCESS )
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DiICPL: cl_spinlock_init returned %d\n", status );
-    return ( status );
-}
-
-dapl_ibal_port_t  *
-dapli_ibal_get_port (
-    IN   dapl_ibal_ca_t    *p_ca,
-    IN   uint8_t           port_num)
-{
-    cl_list_item_t    *p_active_port = NULL;
-    
-    TAKE_LOCK (p_ca->port_lock);
-    for ( p_active_port = cl_qlist_head( &p_ca->port_head );
-          p_active_port != cl_qlist_end ( &p_ca->port_head);
-          p_active_port =  cl_qlist_next ( p_active_port ) )
-    {
-        if (((dapl_ibal_port_t *)p_active_port)->p_attr->port_num == port_num)
-            break;	
-    }
-    RELEASE_LOCK (p_ca->port_lock);
-
-    return (dapl_ibal_port_t *)p_active_port;
-}
-
-
-void
-dapli_ibal_ca_async_error_callback( IN ib_async_event_rec_t  *p_err_rec )
-{
-    dapl_ibal_ca_t	*p_ca = (dapl_ibal_ca_t*)((void *)p_err_rec->context);
-    dapl_ibal_evd_cb_t	*evd_cb;
-    DAPL_IA		*ia_ptr;
-			
-    dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DiCaAEC: CA error %d for context %p\n", 
-                       p_err_rec->code, p_err_rec->context);
-
-    if (p_ca == NULL)
-    {
-       	dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DiCaAEC: invalid p_ca"
-                              "(%p)in async event rec\n",p_ca);
-    	return;
-    }
-	
-    ia_ptr = (DAPL_IA*)p_ca->ia_ptr;
-    if (ia_ptr == NULL)
-    {
-       	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> DiCaAEC: invalid ia_ptr in %p ca \n", p_ca );
-	return;
-    }
-
-    if (ia_ptr->async_error_evd == NULL)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> DiCqAEC: can't find async_error_evd on %s HCA\n", 
-                      (ia_ptr->header.provider)->device_name );
-        return;
-    }
-
-    /* find QP error callback using p_ca for context */
-    evd_cb = dapli_find_evd_cb_by_context (ia_ptr->async_error_evd, p_ca);
-    if ((evd_cb == NULL) || (evd_cb->pfn_async_err_cb == NULL))
-    {
-    	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> DiCaAEC: no ERROR cb on %p found \n", p_ca);
-    	return;
-    }
-
-    /* maps to dapl_evd_un_async_error_callback(), context is async_evd */
-    evd_cb->pfn_async_err_cb( (ib_hca_handle_t)p_ca, 
-                              (ib_error_record_t*)&p_err_rec->code, 
-                              ia_ptr->async_error_evd );
-
-}
-
-
-static dapl_ibal_port_t *
-dapli_alloc_port(
-    IN    dapl_ibal_ca_t    *ca,
-    IN    ib_port_attr_t    *ib_port )
-{
-    dapl_ibal_port_t    *p_port = NULL;
-
-    if (ca->h_ca == NULL )
-    {
-    	return NULL;
-    }
-
-    /*
-     *  Allocate the port structure memory.  This will also deal with the
-     *  copying ib_port_attr_t including GID and P_Key tables
-     */
-    p_port = dapl_os_alloc ( sizeof(dapl_ibal_port_t ) );
-
-    if ( p_port )
-    {
-        dapl_os_memzero (p_port, sizeof(dapl_ibal_port_t ) );
-
-        /*
-         *  We're good to go after initializing reference.
-         */
-        INIT_REFERENCE( &p_port->refs, 1, p_port, NULL /* pfn_destructor */ );
-		
-		p_port->p_attr = ib_port;
-    }
-    return ( p_port );
-}
-
-static void
-dapli_add_active_port(
-    IN dapl_ibal_ca_t   *ca )
-{
-    dapl_ibal_port_t     *p_port;
-    ib_port_attr_t       *p_port_attr;
-    ib_ca_attr_t         *p_ca_attr;
-    int                  i;
-
-    p_ca_attr = ca->p_ca_attr;
-
-    dapl_os_assert (p_ca_attr != NULL);
-
-    for (i = 0; i < p_ca_attr->num_ports; i++)
-    {
-        p_port_attr = &p_ca_attr->p_port_attr[i];
-
-        {
-            p_port = dapli_alloc_port( ca, p_port_attr );
-            if ( p_port )
-            {
-                TAKE_REFERENCE (&ca->refs);
-
-                /*
-                 *  Record / update attribues
-                 */
-                p_port->p_attr = p_port_attr;
-
-                /*
-                 *  Remember the parant CA keeping the reference we took above
-                 */
-                p_port->ca = ca;
-
-                /*
-                 *  We're good to go - Add the new port to the list on the CA
-                 */
-                LOCK_INSERT_TAIL( ca->port_lock, ca->port_head, p_port->next );
-            }
-            else
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                               "--> %s: Could not allocate dapl_ibal_port_t\n",
-                               "DiAAP");
-            }
-        }
-	dapl_dbg_log( DAPL_DBG_TYPE_UTIL,
-                      "--> DiAAP: Port %d logical link %s lid = %#x\n",
-                      p_port_attr->port_num,
-                      ( p_port_attr->link_state != IB_LINK_ACTIVE
-                           ?  "DOWN": "UP" ),
-                      CL_HTON16(p_port_attr->lid) );
-
-    } /* for loop */
-}
-
-static dapl_ibal_ca_t *
-dapli_alloc_ca(
-    IN    ib_al_handle_t  h_al,
-    IN    ib_net64_t      ca_guid)
-{
-    dapl_ibal_ca_t         *p_ca;
-    ib_api_status_t        status;
-    uint32_t               attr_size;
-
-    /*
-     *  Allocate the CA structure
-     */
-    p_ca = dapl_os_alloc( sizeof(dapl_ibal_ca_t) );
-    dapl_os_memzero (p_ca, sizeof(dapl_ibal_ca_t) );
-
-    if ( p_ca )
-    {
-        /*
-         *  Now we pass dapli_ibal_ca_async_error_callback as the 
-         *  async error callback
-         */
-        status = ib_open_ca( h_al,
-                             ca_guid,
-                             dapli_ibal_ca_async_error_callback,
-                             p_ca,
-                             &p_ca->h_ca );
-        if ( status != IB_SUCCESS )
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> DiAC: ib_open_ca returned %s\n",
-                           ib_get_err_str(status));
-            dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
-            return (NULL);
-        }
-
-        /*
-         *  Get port list lock and list head initialized
-         */
-        if (( dapli_init_ca_port_list( p_ca ) != CL_SUCCESS ) ||
-            ( dapli_init_ca_evd_cb_list( p_ca ) != CL_SUCCESS ))
-        { 
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> %s: dapli_init_ca_port_list returned failed\n",
-                           "DiAC");
-            goto close_and_free_ca;
-        }
-
-        attr_size = 0;
-        status = ib_query_ca (p_ca->h_ca, NULL, &attr_size);
-        if (status != IB_INSUFFICIENT_MEMORY)
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                          "--> DiAC: ib_query_ca returned failed status = %d\n",
-                          status);
-            goto close_and_free_ca;
-        }
-
-        p_ca->p_ca_attr = dapl_os_alloc ((int)attr_size);
-        if (p_ca->p_ca_attr == NULL)
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> %s: dapli_alloc_ca failed to alloc memory\n",
-                           "DiAC");
-            goto close_and_free_ca;
-        }
-
-        status = ib_query_ca (
-                          p_ca->h_ca,
-                          p_ca->p_ca_attr,
-                          &attr_size);
-        if (status != IB_SUCCESS)
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> ib_query_ca returned failed status = %d\n",
-                           status);
-            dapl_os_free (p_ca->p_ca_attr, (int)attr_size);
-            goto close_and_free_ca;
-        }
-       
-        p_ca->ca_attr_size = attr_size;
-
-        INIT_REFERENCE( &p_ca->refs, 1, p_ca, NULL /* pfn_destructor */ );
-
-        dapli_add_active_port (p_ca);
-
-        /*
-         *  We're good to go
-         */
-        return ( p_ca );
-    }
-    else
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> %s: Error allocating CA structure\n","DiAC");
-        return ( NULL );
-    }
-
-close_and_free_ca:
-   /*
-    *  Close the CA.
-    */
-   (void) ib_close_ca ( p_ca->h_ca, NULL /* callback */);
-   dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
-
-    /*
-     *  If we get here, there was an initialization failure
-     */
-    return ( NULL );
-}
-
-
-static dapl_ibal_ca_t *
-dapli_add_ca (
-    IN   ib_al_handle_t    h_al,
-    IN   ib_net64_t        ca_guid )
-{
-    dapl_ibal_ca_t     *p_ca;
-
-    /*
-     *  Allocate a CA structure
-     */
-    p_ca = dapli_alloc_ca( h_al, ca_guid );
-    if ( p_ca )
-    {
-        /*
-         *  Add the new CA to the list
-         */
-        LOCK_INSERT_TAIL( dapl_ibal_root.ca_lock, 
-                          dapl_ibal_root.ca_head, p_ca->next );
-    }
-    else
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> %s: Could not allocate dapl_ibal_ca_t "
-                       " for CA guid " F64x "\n","DiAA",ca_guid);
-    }
-
-    return ( p_ca );
-}
-
-
-int32_t
-dapls_ib_init (void)
-{
-    ib_api_status_t status;
-
-    /*
-     * Initialize the root structure
-     */
-    if ( dapli_init_root_ca_list (&dapl_ibal_root) == CL_SUCCESS )
-    {
-        /*
-         * Register with the access layer
-         */
-        status = ib_open_al (&dapl_ibal_root.h_al);
-
-        if (status == IB_SUCCESS)
-        {
-            intn_t             guid_count;
-
-            status = ib_get_ca_guids ( dapl_ibal_root.h_al,
-                                       NULL,
-                                       &(size_t)guid_count );
-            if (status != IB_INSUFFICIENT_MEMORY)
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                               "--> %s: ib_get_ca_guids failed = %d\n",
-                               __FUNCTION__,status);
-                return -1;
-            }
-
-            if (guid_count == 0)
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                               "--> %s: found NO HCA in the system\n",
-                               __FUNCTION__);
-                return -1;
-            }
-
-            if (guid_count > DAPL_IBAL_MAX_CA)
-            {
-                guid_count = DAPL_IBAL_MAX_CA;
-            }
-
-            gp_ibal_ca_guid_tbl = (ib_net64_t*)
-                                  dapl_os_alloc ( (int)(guid_count * 
-                                                  sizeof (ib_net64_t)) );
-
-            if (gp_ibal_ca_guid_tbl == NULL)
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> %s() can not alloc "
-                               "gp_ibal_ca_guid_tbl\n", __FUNCTION__);
-                        
-                return -1;
-            }
-
-            status = ib_get_ca_guids ( dapl_ibal_root.h_al, 
-                                       gp_ibal_ca_guid_tbl, 
-                                       &(size_t)guid_count );
-                            
-
-            if ( status != IB_SUCCESS )
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                               "--> %s: ib_get_ca_guids failed '%s'\n", 
-                               __FUNCTION__, ib_get_err_str(status) );
-                return -1;
-            }
-
-            dapl_dbg_log ( DAPL_DBG_TYPE_UTIL, 
-                           "--> %s: Success open AL & found %d HCA avail,\n",
-                           __FUNCTION__, guid_count);
-            return 0;
-        }
-        else
-        {        
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> %s: ib_open_al() failed '%s'\n",
-                           __FUNCTION__, ib_get_err_str(status) );
-            /*
-             * Undo CA list
-             */
-            dapli_destroy_root_ca_list (&dapl_ibal_root);
-        }
-    }
-    return -1;
-}
-
-
-int32_t dapls_ib_release (void)
-{
-    dapl_ibal_root.shutdown = TRUE;
-
-    dapli_shutdown_ca_access();
-
-    /*
-     * If shutdown not complete, wait for it
-     */
-    if (dapl_ibal_root.shutdown)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                        "--> DsIR: timeout waiting for completion\n");
-    }
-
-    if ( dapl_ibal_root.h_al != NULL )
-    {
-        (void) ib_close_al (dapl_ibal_root.h_al);
-	dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIR: ib_close_al() returns\n");
-        dapl_ibal_root.h_al = NULL;
-    }
-#ifdef DBG
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> %s: Exit\n",__FUNCTION__);
-#endif
-
-    return 0;
-}
-
-
-/*
- * dapls_ib_enum_hcas
- *
- * Enumerate all HCAs on the system
- *
- * Input:
- * 	none
- *
- * Output:
- *	hca_names	Array of hca names
- *	total_hca_count	
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_enum_hcas (
-        IN   const char          *vendor,
-        OUT  DAPL_HCA_NAME       **hca_names,
-        OUT  DAT_COUNT           *total_hca_count )
-{
-    intn_t             guid_count;
-    ib_api_status_t    ib_status;
-    UNREFERENCED_PARAMETER(vendor);
-
-    ib_status = ib_get_ca_guids (dapl_ibal_root.h_al, NULL, &(size_t)guid_count);
-    if (ib_status != IB_INSUFFICIENT_MEMORY)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIEH: ib_get_ca_guids failed '%s'\n",
-                       ib_get_err_str(ib_status) );
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    if (guid_count == 0)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> %s: ib_get_ca_guids no HCA in the system\n",
-                       "DsIEH");
-        return (DAT_PROVIDER_NOT_FOUND);
-    }
-
-    if (guid_count > DAPL_IBAL_MAX_CA)
-    {
-        guid_count = DAPL_IBAL_MAX_CA;
-    }
-
-    gp_ibal_ca_guid_tbl = (ib_net64_t *)dapl_os_alloc ((int)(guid_count * sizeof (ib_net64_t)) );
-
-    if (gp_ibal_ca_guid_tbl == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> %s: can not alloc resources @line%d\n", "DsIEH",
-                       __LINE__);
-        return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    ib_status = ib_get_ca_guids ( dapl_ibal_root.h_al,
-                                  gp_ibal_ca_guid_tbl,
-                                  &(size_t)guid_count);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIEH: ib_get_ca_guids failed status = %s\n", 
-                       ib_get_err_str(ib_status) );
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    *hca_names = (DAPL_HCA_NAME*)
-                     dapl_os_alloc ((int)(guid_count * sizeof (DAPL_HCA_NAME)));
-
-    if (*hca_names == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> %s: can not alloc resources @line%d\n",
-                       "DsIEH", __LINE__);
-        return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    dapl_os_memcpy (*hca_names, 
-                    dapl_ibal_hca_name_array, 
-                    (int)(guid_count * sizeof (DAPL_HCA_NAME)) );
-
-    *total_hca_count = (DAT_COUNT)guid_count;
-
-    {
-        int i;
-
-        for (i = 0; i < guid_count; i++)
-            dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIEH: %d) hca_names = %s\n",
-                          i, dapl_ibal_hca_name_array[i]);
-    }
-
-    return (DAT_SUCCESS);
-}
-
-
-
-IB_HCA_NAME
-dapl_ib_convert_name(
-    IN  char    *name)
-{
-    int                i;
-
-    if (gp_ibal_ca_guid_tbl  == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DICN: found no HCA with name %s\n", name );
-        return 0;
-    }
-
-    for (i = 0; i < DAPL_IBAL_MAX_CA; i++)
-    {
-        if (strcmp (name, dapl_ibal_hca_name_array[i]) == 0)
-        {
-            break;
-        }
-    }
-
-    if (i >= DAPL_IBAL_MAX_CA)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DICN: can't find any HCA with name %s\n", name);
-        return 0;
-    }
-   
-    return (gp_ibal_ca_guid_tbl[i]);
-}
-
-
-/*
- * dapls_ib_open_hca
- *
- * Open HCA
- *
- * Input:
- *      *hca_name         pointer to provider device name
- *      *ib_hca_handle_p  pointer to provide HCA handle
- *
- * Output:
- *      none
- *
- * Return:
- *      DAT_SUCCESS
- *      DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN dapls_ib_open_hca ( IN  char         *hca_name,
-                               IN  DAPL_HCA     *p_hca )
-{
-    dapl_ibal_ca_t     *p_ca;
-    IB_HCA_NAME        ca_guid;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL," open_hca: %s - %p\n", hca_name, p_hca);
-
-    if (gp_ibal_ca_guid_tbl  == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIOH: found no HCA with ca_guid"
-                       F64x "\n", hca_name);
-        return (DAT_PROVIDER_NOT_FOUND);
-    }
-
-    ca_guid = dapl_ib_convert_name(hca_name);
-
-    p_ca = dapli_add_ca (dapl_ibal_root.h_al, ca_guid);
-
-    if (p_ca == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                     "--> DsIOH: can not create ca for '%s' guid " F64x "\n",
-                     hca_name, ca_guid);
-        return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    p_hca->ib_hca_handle = (ib_hca_handle_t) p_ca;
-    p_hca->ib_trans.d_hca = p_hca; // back-link
-
-    /* initialize hca wait object for uAT event */
-    dapl_os_wait_object_init(&p_hca->ib_trans.wait_object);
-
-#if SOCK_CM
-    {
-	DAT_RETURN    dat_status;
-
-	dat_status = dapli_init_sock_cm(p_hca);
-	if ( dat_status != DAT_SUCCESS )
-	{
-		dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-				" %s() failed to init sock_CM\n", __FUNCTION__);
-		return DAT_INTERNAL_ERROR;
-	}
-
-	/* initialize cr_list lock */
-	dat_status = dapl_os_lock_init(&p_hca->ib_trans.lock);
-	if (dat_status != DAT_SUCCESS)
-	{
-		dapl_dbg_log (DAPL_DBG_TYPE_ERR, " %s() failed to init lock\n",
-				__FUNCTION__);
-		return DAT_INTERNAL_ERROR;
-	}
-
-	/* initialize CM list for listens on this HCA */
-	dapl_llist_init_head((DAPL_LLIST_HEAD*)&p_hca->ib_trans.list);
-    }
-#endif
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapls_ib_close_hca
- *
- * Open HCA
- *
- * Input:
- *      ib_hca_handle   provide HCA handle
- *
- * Output:
- *      none
- *
- * Return:
- *      DAT_SUCCESS
- *      DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN dapls_ib_close_hca ( IN  DAPL_HCA  *p_hca )
-{
-    dapl_ibal_ca_t     *p_ca;
-   
-    p_ca =  (dapl_ibal_ca_t *) p_hca->ib_hca_handle;
-   
-#if SOCK_CM
-#endif
-    /*
-     * Remove it from the list
-     */
-    TAKE_LOCK (dapl_ibal_root.ca_lock);
-    {
-        cl_qlist_remove_item (&dapl_ibal_root.ca_head, &p_ca->next);
-    }
-    RELEASE_LOCK (dapl_ibal_root.ca_lock);
-
-    dapli_shutdown_port_access (p_ca);
- 
-    /*
-     * Remove the constructor reference
-     */
-    REMOVE_REFERENCE (&p_ca->refs);
-
-    (void) ib_close_ca (p_ca->h_ca, ib_sync_destroy);
-
-    cl_spinlock_destroy (&p_ca->port_lock);
-    cl_spinlock_destroy (&p_ca->evd_cb_lock);
-
-    if (p_ca->p_ca_attr)
-        dapl_os_free (p_ca->p_ca_attr, sizeof (ib_ca_attr_t));
-
-    p_hca->ib_hca_handle = IB_INVALID_HANDLE;
-    dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
-
-    return (DAT_SUCCESS);
-}
-
-
-
-/*
- * dapl_ib_pd_alloc
- *
- * Alloc a PD
- *
- * Input:
- *	ia_handle		IA handle
- *	PZ_ptr			pointer to PZEVD struct
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_pd_alloc (
-        IN  DAPL_IA                 *ia,
-        IN  DAPL_PZ                 *pz)
-{
-    ib_api_status_t         ib_status;
-    dapl_ibal_ca_t          *p_ca;
-
-    p_ca = (dapl_ibal_ca_t *) ia->hca_ptr->ib_hca_handle;
-
-    ib_status = ib_alloc_pd (
-                              p_ca->h_ca,
-                              IB_PDT_NORMAL,
-                              ia,
-                              &pz->pd_handle );
-
-    return dapl_ib_status_convert (ib_status);
-}
-
-
-/*
- * dapl_ib_pd_free
- *
- * Free a PD
- *
- * Input:
- *	PZ_ptr			pointer to PZ struct
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_pd_free (
-        IN  DAPL_PZ                 *pz)
-{
-    ib_api_status_t                 ib_status;
-
-    ib_status = ib_dealloc_pd (pz->pd_handle, /* destroy_callback */ NULL);
-
-    pz->pd_handle = IB_INVALID_HANDLE;
-
-    return dapl_ib_status_convert (ib_status);
-}
-
-
-/*
- * dapl_ib_mr_register
- *
- * Register a virtual memory region
- *
- * Input:
- *	ia_handle		IA handle
- *	lmr			pointer to dapl_lmr struct
- *	virt_addr		virtual address of beginning of mem region
- *	length			length of memory region
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mr_register (
-        IN  DAPL_IA                 *ia,
-        IN  DAPL_LMR                *lmr,
-        IN  DAT_PVOID                virt_addr,
-        IN  DAT_VLEN                length,
-        IN  DAT_MEM_PRIV_FLAGS      privileges,
-        IN  DAT_VA_TYPE             va_type)
-{
-    ib_api_status_t     ib_status;
-    ib_mr_handle_t      mr_handle;
-    ib_mr_create_t      mr_create;
-    uint32_t            l_key, r_key; 
-
-    if ( ia == NULL || ia->header.magic != DAPL_MAGIC_IA )
-    {
-        return DAT_INVALID_HANDLE;
-    }
-
-    /* IBAL does not support */
-    if (va_type == DAT_VA_TYPE_ZB) {
-        dapl_dbg_log(DAPL_DBG_TYPE_ERR,
-    	             "--> va_type == DAT_VA_TYPE_ZB: NOT SUPPORTED\n");    
-        return DAT_ERROR (DAT_NOT_IMPLEMENTED, DAT_NO_SUBTYPE);  
-    }
-
-    mr_create.vaddr         = (void *) virt_addr;
-    mr_create.length        = (size_t)length;
-    mr_create.access_ctrl   = dapl_lmr_convert_privileges (privileges);
-    mr_create.access_ctrl   |= IB_AC_MW_BIND;
-   
-    if (lmr->param.mem_type == DAT_MEM_TYPE_SHARED_VIRTUAL)
-    {
-        ib_status = ib_reg_shmid (
-                          ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
-                          (const uint8_t*)lmr->shmid,
-                          &mr_create,
-                          (uint64_t *)&virt_addr,
-                          &l_key,
-                          &r_key,
-                          &mr_handle);
-    }
-    else 
-    {
-        ib_status = ib_reg_mem ( ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
-                                 &mr_create,
-                                 &l_key,
-                                 &r_key,
-                                 &mr_handle );
-    }
-    
-    if (ib_status != IB_SUCCESS)
-    {
-        return (dapl_ib_status_convert (ib_status));
-    }
-    
-    /* DAT/DAPL expects context in host order */
-    l_key = cl_ntoh32(l_key);
-    r_key = cl_ntoh32(r_key);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMR: lmr (%p) lkey = 0x%x "
-                  "r_key= %#x mr_handle %p vaddr 0x%LX len 0x%LX\n", 
-                  lmr, l_key, r_key, mr_handle, virt_addr, length);
-
-    lmr->param.lmr_context = l_key;
-    lmr->param.rmr_context = r_key;
-    lmr->param.registered_size = length;
-    lmr->param.registered_address = (DAT_VADDR)virt_addr;
-    lmr->mr_handle         = mr_handle;
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapl_ib_mr_deregister
- *
- * Free a memory region
- *
- * Input:
- *	lmr			pointer to dapl_lmr struct
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mr_deregister (
-        IN  DAPL_LMR                *lmr)
-{
-    ib_api_status_t                ib_status;
-
-    ib_status = ib_dereg_mr (lmr->mr_handle);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    lmr->param.lmr_context = 0;
-    lmr->mr_handle         = IB_INVALID_HANDLE;
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapl_ib_mr_register_shared
- *
- * Register a virtual memory region
- *
- * Input:
- *	ia_handle		IA handle
- *	lmr			pointer to dapl_lmr struct
- *	virt_addr		virtual address of beginning of mem region
- *	length			length of memory region
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mr_register_shared (
-        IN  DAPL_IA                  *ia,
-        IN  DAPL_LMR                 *lmr,
-        IN  DAT_MEM_PRIV_FLAGS       privileges,
-        IN  DAT_VA_TYPE              va_type )
-{
-    DAT_VADDR                   virt_addr;
-    ib_mr_handle_t              mr_handle;
-    ib_api_status_t             ib_status;
-    ib_mr_handle_t              new_mr_handle;
-    ib_access_t                 access_ctrl;
-    uint32_t                    l_key, r_key; 
-    ib_mr_create_t      mr_create;
-    if ( ia == NULL || ia->header.magic != DAPL_MAGIC_IA )
-    {
-        return DAT_INVALID_HANDLE;
-    }
-
-    /* IBAL does not support?? */
-    if (va_type == DAT_VA_TYPE_ZB) {
-        dapl_dbg_log(DAPL_DBG_TYPE_ERR,
-    	    " va_type == DAT_VA_TYPE_ZB: NOT SUPPORTED\n");    
-        return DAT_ERROR (DAT_NOT_IMPLEMENTED, DAT_NO_SUBTYPE);  
-    }
-
-    virt_addr = dapl_mr_get_address (lmr->param.region_desc,
-                                     lmr->param.mem_type);
-
-    access_ctrl   = dapl_lmr_convert_privileges (privileges);
-    access_ctrl  |= IB_AC_MW_BIND;
-
-    mr_create.vaddr         = (void *) virt_addr;
-    mr_create.access_ctrl   = access_ctrl;
-    mr_handle = (ib_mr_handle_t) lmr->mr_handle;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                       "--> DsIMRS: orig mr_handle %p vaddr %p\n", 
-                       mr_handle, virt_addr);
-
-    if (lmr->param.mem_type == DAT_MEM_TYPE_SHARED_VIRTUAL)
-    {
-        ib_status = ib_reg_shmid ( ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
-                                   (const uint8_t*)lmr->shmid,
-                                   &mr_create,
-                                   &virt_addr,
-                                   &l_key,
-                                   &r_key,
-                                   &new_mr_handle );
-    }
-    else
-    { 
-
-        ib_status = ib_reg_shared ( mr_handle,
-                                   ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
-                                   access_ctrl,
-                                   /* in/out */(DAT_UINT64 *)&virt_addr,
-                                   &l_key,
-                                   &r_key,
-                                   &new_mr_handle );
-    }
-
-    if (ib_status != IB_SUCCESS)
-    {
-        return dapl_ib_status_convert (ib_status);
-    }
-    /*
-     * FIXME - Vu
-     *    What if virt_addr as an OUTPUT having the actual virtual address
-     *    assigned to the register region
-     */
-
-    /* DAT/DAPL expects context to be in host order */
-    l_key = cl_ntoh32(l_key);
-    r_key = cl_ntoh32(r_key);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMRS: lmr (%p) lkey = 0x%x "
-                  "new mr_handle %p vaddr %p\n",
-                  lmr, l_key, new_mr_handle, virt_addr);
-
-    lmr->param.lmr_context = l_key;
-    lmr->param.rmr_context = r_key;
-    lmr->param.registered_address = (DAT_VADDR) (uintptr_t) virt_addr;
-    lmr->mr_handle         = new_mr_handle;
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapls_ib_mw_alloc
- *
- * Bind a protection domain to a memory window
- *
- * Input:
- *	rmr			Initialized rmr to hold binding handles
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mw_alloc ( IN  DAPL_RMR    *rmr )
-{
-    ib_api_status_t     ib_status;
-    uint32_t            r_key;
-    ib_mw_handle_t      mw_handle;
-
-    ib_status = ib_create_mw (
-                  ((DAPL_PZ *)rmr->param.pz_handle)->pd_handle,
-                  &r_key,
-                  &mw_handle);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIMA: create MW failed = %s\n",
-                       ib_get_err_str(ib_status) );
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    rmr->mw_handle         = mw_handle;
-    rmr->param.rmr_context = (DAT_RMR_CONTEXT) cl_ntoh32(r_key);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                       "--> DsIMA: mw_handle %p r_key = 0x%x\n", 
-                        mw_handle, rmr->param.rmr_context);
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapls_ib_mw_free
- *
- * Release bindings of a protection domain to a memory window
- *
- * Input:
- *	rmr			Initialized rmr to hold binding handles
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mw_free (
-        IN  DAPL_RMR                         *rmr)
-{
-    ib_api_status_t         ib_status;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                       "--> DsIMF: mw_handle %p\n", rmr->mw_handle);
-
-    ib_status = ib_destroy_mw (rmr->mw_handle);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMF: Free MW failed = %s\n",
-                       ib_get_err_str(ib_status));
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    rmr->param.rmr_context = 0;
-    rmr->mw_handle         = IB_INVALID_HANDLE;
-
-    return (DAT_SUCCESS);
-}
-
-/*
- * dapls_ib_mw_bind
- *
- * Bind a protection domain to a memory window
- *
- * Input:
- *	rmr			Initialized rmr to hold binding handles
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mw_bind (
-        IN  DAPL_RMR                *rmr,
-        IN  DAPL_LMR                *lmr,
-        IN  DAPL_EP                 *ep,
-        IN  DAPL_COOKIE             *cookie,
-        IN  DAT_VADDR               virtual_address,
-        IN  DAT_VLEN                length,
-        IN  DAT_MEM_PRIV_FLAGS      mem_priv,
-        IN  ib_bool_t               is_signaled)
-{
-    ib_api_status_t       ib_status;
-    ib_bind_wr_t          bind_wr_prop;
-    uint32_t              new_rkey;
-    
-    bind_wr_prop.local_ds.vaddr   = virtual_address;
-    bind_wr_prop.local_ds.length  = (uint32_t)length;
-    bind_wr_prop.local_ds.lkey    = cl_hton32(lmr->param.lmr_context);
-    bind_wr_prop.current_rkey     = cl_hton32(rmr->param.rmr_context);
-    bind_wr_prop.access_ctrl      = dapl_rmr_convert_privileges (mem_priv);
-    bind_wr_prop.send_opt         = (is_signaled == TRUE) ? 
-                                    IB_SEND_OPT_SIGNALED : 0;
-    bind_wr_prop.wr_id            = (uint64_t) ((uintptr_t) cookie);
-    bind_wr_prop.h_mr             = lmr->mr_handle;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMB: mr_handle %p, mw_handle %p "
-                  "vaddr %#I64x length %#I64x\n", 
-                  lmr->mr_handle, rmr->mw_handle, virtual_address, length);
-
-    ib_status = ib_bind_mw (
-                    rmr->mw_handle,
-                    ep->qp_handle,
-                    &bind_wr_prop,
-                    &new_rkey);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMB: Bind MW failed = %s\n", 
-                       ib_get_err_str(ib_status));
-        return (dapl_ib_status_convert (ib_status));
-    }
-
-    rmr->param.rmr_context      = (DAT_RMR_CONTEXT) cl_ntoh32(new_rkey);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL,
-			"--> DsIMB: new_rkey = 0x%x\n", rmr->param.rmr_context);
-
-    return (DAT_SUCCESS);
-}
-
-/*
- * dapls_ib_mw_unbind
- *
- * Unbind a memory window
- *
- * Input:
- *	rmr			Initialized rmr to hold binding handles
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_mw_unbind (
-	IN  DAPL_RMR		*rmr,
-	IN  DAPL_EP		*ep,
-	IN  DAPL_COOKIE		*cookie,
-	IN  ib_bool_t		is_signaled)
-{
-    ib_api_status_t       ib_status;
-    ib_bind_wr_t          bind_wr_prop;
-    uint32_t              new_rkey;
-    
-    bind_wr_prop.local_ds.vaddr   = 0;
-    bind_wr_prop.local_ds.length  = 0;
-    bind_wr_prop.local_ds.lkey    = 0;
-    bind_wr_prop.access_ctrl      = 0;
-    bind_wr_prop.send_opt         = (is_signaled == TRUE) ? 
-                                    IB_SEND_OPT_SIGNALED : 0;
-    bind_wr_prop.wr_id            = (uint64_t) ((uintptr_t) cookie);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                       "--> DsIMU: mw_handle = %p\n", rmr->mw_handle);
-
-    ib_status = ib_bind_mw (
-                    rmr->mw_handle,
-                    ep->qp_handle,
-                    &bind_wr_prop,
-                    &new_rkey);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMU: Unbind MW failed = %s\n", 
-                ib_get_err_str(ib_status));
-        return (dapl_ib_status_convert (ib_status));
-    }
-
-    rmr->param.rmr_context      = (DAT_RMR_CONTEXT) cl_ntoh32(new_rkey);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
-                  "--> DsIMU: unbind new_rkey 0x%x\n", rmr->param.rmr_context);
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapls_ib_setup_async_callback
- *
- * Set up an asynchronous callbacks of various kinds
- *
- * Input:
- *	ia_handle		IA handle
- *	handler_type		type of handler to set up
- *	callback_handle		handle param for completion callbacks
- *	callback		callback routine pointer
- *	context			argument for callback routine
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INSUFFICIENT_RESOURCES
- *	DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_setup_async_callback (
-        IN  DAPL_IA                     *ia_ptr,
-        IN  DAPL_ASYNC_HANDLER_TYPE     handler_type,
-        IN  DAPL_EVD                    *evd_ptr,
-        IN  ib_async_handler_t          callback,
-        IN  void                        *context )
-{
-    dapl_ibal_ca_t     *p_ca;
-    dapl_ibal_evd_cb_t *evd_cb;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_UTIL,
-                  " setup_async_cb: ia %p type %d hdl %p cb %p ctx %p\n",
-                  ia_ptr, handler_type, evd_ptr, callback, context);
-
-    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-
-    if (p_ca == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsISAC: can't find %s HCA\n", 
-                       (ia_ptr->header.provider)->device_name);
-        return (DAT_INVALID_HANDLE);
-    }
-   
-    if (handler_type != DAPL_ASYNC_CQ_COMPLETION)
-    {
-        evd_cb = dapli_find_evd_cb_by_context (context, p_ca);
-           
-        if (evd_cb == NULL)
-        {
-            /* 
-             * No record for this evd. We allocate one
-             */
-            evd_cb = dapl_os_alloc (sizeof (dapl_ibal_evd_cb_t));
-            dapl_os_memzero (evd_cb, sizeof(dapl_ibal_evd_cb_t));
-
-            if (evd_cb == NULL)
-            {
-                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                               "--> %s: can't alloc res\n","DsISAC"); 
-                return (DAT_INSUFFICIENT_RESOURCES);
-            }
-        
-            evd_cb->context          = context;
-        
-            /*
-             *  Add the new EVD CB to the list
-             */
-            LOCK_INSERT_TAIL( p_ca->evd_cb_lock, 
-                              p_ca->evd_cb_head,
-                              evd_cb->next );
-        }
-
-        switch (handler_type)
-        {
-            case DAPL_ASYNC_UNAFILIATED:
-                evd_cb->pfn_async_err_cb = callback;
-                break;
-            case DAPL_ASYNC_CQ_ERROR:
-                evd_cb->pfn_async_cq_err_cb = callback;
-                break;
-            case DAPL_ASYNC_QP_ERROR:
-                evd_cb->pfn_async_qp_err_cb = callback;
-                break;
-            default:
-                break;
-        }
-
-    }
-
-    return DAT_SUCCESS;
-}
-
-
-/*
- * dapls_ib_query_gid
- *
- * Query the hca for the gid of the 1st active port.
- *
- * Input:
- *	hca_handl		hca handle	
- *	ep_attr			attribute of the ep
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INVALID_HANDLE
- *	DAT_INVALID_PARAMETER
- */
-
-DAT_RETURN
-dapls_ib_query_gid( IN  DAPL_HCA	*hca_ptr,
-		    IN  GID		*gid )
-{
-    dapl_ibal_ca_t    *p_ca;
-    ib_ca_attr_t      *p_hca_attr;
-    ib_api_status_t   ib_status;
-    ib_hca_port_t     port_num;
-
-    p_ca = (dapl_ibal_ca_t *) hca_ptr->ib_hca_handle;
-
-    if (p_ca == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-			"%s() invalid hca_ptr %p", __FUNCTION__, hca_ptr);
-        return DAT_INVALID_HANDLE;
-    }
-
-    ib_status = ib_query_ca (
-                          p_ca->h_ca,
-                          p_ca->p_ca_attr,
-                          &p_ca->ca_attr_size);
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "%s() ib_query_ca returned failed status = %s\n", 
-                       ib_get_err_str(ib_status));
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    p_hca_attr = p_ca->p_ca_attr;
-    port_num = hca_ptr->port_num - 1;
-
-    gid->gid_prefix = p_hca_attr->p_port_attr[port_num].p_gid_table->unicast.prefix;
-    gid->guid = p_hca_attr->p_port_attr[port_num].p_gid_table->unicast.interface_id;
-    return DAT_SUCCESS;
-}
-
-
-/*
- * dapls_ib_query_hca
- *
- * Query the hca attribute
- *
- * Input:
- *	hca_handl		hca handle	
- *	ep_attr			attribute of the ep
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INVALID_PARAMETER
- */
-
-DAT_RETURN dapls_ib_query_hca (
-	IN  DAPL_HCA                       *hca_ptr,
-        OUT DAT_IA_ATTR                    *ia_attr,
-        OUT DAT_EP_ATTR                    *ep_attr,
-	OUT DAT_SOCK_ADDR6                 *ip_addr)
-{
-    ib_ca_attr_t      *p_hca_attr;
-    dapl_ibal_ca_t    *p_ca;
-    ib_api_status_t   ib_status;
-    ib_hca_port_t     port_num;
-    GID gid;
-    DAT_SOCK_ADDR6	 *p_sock_addr;
-    DAT_RETURN dat_status = DAT_SUCCESS;
-    port_num = hca_ptr->port_num;
-
-    p_ca = (dapl_ibal_ca_t *) hca_ptr->ib_hca_handle;
-
-    if (p_ca == NULL)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,  "--> %s: invalid handle %p",
-                       "DsIQH", hca_ptr);
-        return (DAT_INVALID_HANDLE);
-    }
-
-    ib_status = ib_query_ca (
-                          p_ca->h_ca,
-                          p_ca->p_ca_attr,
-                          &p_ca->ca_attr_size);
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIQH: ib_query_ca returned failed status = %s\n", 
-                       ib_get_err_str(ib_status));
-        return (dapl_ib_status_convert (ib_status));
-    }
-
-    p_hca_attr = p_ca->p_ca_attr;
-
-    if (ip_addr != NULL)
-    {
-    	p_sock_addr = dapl_os_alloc(sizeof(DAT_SOCK_ADDR6));
-    	if ( !p_sock_addr )
-    	{
-    		dat_status = DAT_INSUFFICIENT_RESOURCES;
-    		dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                                       " Query Hca alloc Err: status %d\n",
-                                       dat_status);
-    		return dat_status;
-    	}
-    	dapl_os_memzero(p_sock_addr, sizeof(DAT_SOCK_ADDR6));
-
-    	gid.gid_prefix = p_hca_attr->p_port_attr[port_num-1].p_gid_table->unicast.prefix;
-    	gid.guid = p_hca_attr->p_port_attr[port_num-1].p_gid_table->unicast.interface_id;
-	
-    	dat_status = dapls_ns_map_ipaddr( hca_ptr,
-                                          gid,
-                                          (DAT_IA_ADDRESS_PTR)p_sock_addr);
-	
-    	if ( dat_status != DAT_SUCCESS )
-    	{
-            dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                          " SA Query for local IP failed= %d\n", dat_status );
-			/* what to do next ? */
-    	}
-    	else
-    	{
-    	    dapl_dbg_log (DAPL_DBG_TYPE_CM, "SA query GID for IP: ");
-            dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%0d:%d:%d:%d\n", 
-		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[2]&0xff,
-		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[3]&0xff,
-		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[4]&0xff,
-		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[5]&0xff);
-        }
-
-        hca_ptr->hca_address = *p_sock_addr;
-
-        /* if structure address not from our hca_ptr */
-        if ( ip_addr  != &hca_ptr->hca_address )
-        {
-            *ip_addr = *p_sock_addr;
-        }
-
-	dapl_os_free (p_sock_addr, sizeof(DAT_SOCK_ADDR6));
-
-    } /* ip_addr != NULL */
-
-    if ( ia_attr != NULL )
-    {
-        dapl_os_memzero( ia_attr->adapter_name,
-                         (int)sizeof(ia_attr->adapter_name ));
-        dapl_os_memcpy(ia_attr->adapter_name,
-                        DAT_ADAPTER_NAME, 
-                        min ( (int)dapl_os_strlen(DAT_ADAPTER_NAME),
-                              (int)(DAT_NAME_MAX_LENGTH)-1 ) );
-
-        dapl_os_memzero ( ia_attr->vendor_name,
-                          (int)sizeof(ia_attr->vendor_name) );
-        dapl_os_memcpy ( ia_attr->vendor_name, 
-                         DAT_VENDOR_NAME,
-                        min ( (int)dapl_os_strlen(DAT_VENDOR_NAME),
-                              (int)(DAT_NAME_MAX_LENGTH)-1 ) );
-        
-        /* FIXME : Vu
-         *         this value should be revisited
-         *         It can be set by DAT consumers
-         */
-        ia_attr->ia_address_ptr           = (DAT_PVOID)&hca_ptr->hca_address;
-        ia_attr->hardware_version_major   = p_hca_attr->dev_id;
-        ia_attr->hardware_version_minor   = p_hca_attr->revision;
-        ia_attr->max_eps                  = p_hca_attr->max_qps;
-        ia_attr->max_dto_per_ep           = p_hca_attr->max_wrs;
-        ia_attr->max_rdma_read_per_ep     = p_hca_attr->max_qp_resp_res;
-        ia_attr->max_evds                 = p_hca_attr->max_cqs;
-        ia_attr->max_evd_qlen             = p_hca_attr->max_cqes;
-        ia_attr->max_iov_segments_per_dto = p_hca_attr->max_sges;
-        ia_attr->max_lmrs                 = p_hca_attr->init_regions;
-        ia_attr->max_lmr_block_size       = p_hca_attr->init_region_size;
-        ia_attr->max_rmrs                 = p_hca_attr->init_windows;
-        ia_attr->max_lmr_virtual_address  = p_hca_attr->max_addr_handles;
-        ia_attr->max_rmr_target_address   = p_hca_attr->max_addr_handles;
-        ia_attr->max_pzs                  = p_hca_attr->max_pds;
-        /*
-         * DAT spec does not tie max_mtu_size with IB MTU
-         *
-        ia_attr->max_mtu_size             = 
-                        dapl_ibal_mtu_table[p_hca_attr->p_port_attr->mtu];
-        */
-        ia_attr->max_mtu_size             = 
-                        p_hca_attr->p_port_attr->max_msg_size;
-        ia_attr->max_rdma_size            = 
-                        p_hca_attr->p_port_attr->max_msg_size;
-        ia_attr->num_transport_attr       = 0;
-        ia_attr->transport_attr           = NULL;
-        ia_attr->num_vendor_attr          = 0;
-        ia_attr->vendor_attr              = NULL;
-        ia_attr->max_iov_segments_per_rdma_read = p_hca_attr->max_sges;
-
-#ifdef DAT_EXTENSIONS
-        ia_attr->extension_supported = DAT_EXTENSION_IB;
-        ia_attr->extension_version = DAT_IB_EXTENSION_VERSION;
-#endif
-	
-	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
-		" --> DsIMU_qHCA: (ver=%x) ep %d ep_q %d evd %d evd_q %d\n", 
-			ia_attr->hardware_version_major,
-			ia_attr->max_eps, ia_attr->max_dto_per_ep,
-			ia_attr->max_evds, ia_attr->max_evd_qlen );
-	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
-		" --> DsIMU_qHCA: mtu %llu rdma %llu iov %d lmr %d rmr %d"
-		" rdma_io %d\n", 
-			ia_attr->max_mtu_size, ia_attr->max_rdma_size,
-			ia_attr->max_iov_segments_per_dto, ia_attr->max_lmrs, 
-			ia_attr->max_rmrs, ia_attr->max_rdma_read_per_ep );
-    }
-
-    if ( ep_attr != NULL )
-    {
-       (void) dapl_os_memzero(ep_attr, sizeof(*ep_attr)); 
-        /*
-         * DAT spec does not tie max_mtu_size with IB MTU
-         *
-        ep_attr->max_mtu_size     = 
-                        dapl_ibal_mtu_table[p_hca_attr->p_port_attr->mtu];
-         */
-        ep_attr->max_mtu_size     = p_hca_attr->p_port_attr->max_msg_size;
-        ep_attr->max_rdma_size    = p_hca_attr->p_port_attr->max_msg_size;
-        ep_attr->max_recv_dtos    = p_hca_attr->max_wrs;
-        ep_attr->max_request_dtos = p_hca_attr->max_wrs;
-        ep_attr->max_recv_iov     = p_hca_attr->max_sges;
-        ep_attr->max_request_iov  = p_hca_attr->max_sges;
-        ep_attr->max_rdma_read_in = p_hca_attr->max_qp_resp_res;
-        ep_attr->max_rdma_read_out= p_hca_attr->max_qp_resp_res;
-	
-	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
-		" --> DsIMU_qHCA: msg %llu dto %d iov %d rdma i%d,o%d\n", 
-			ep_attr->max_mtu_size,
-			ep_attr->max_recv_dtos, ep_attr->max_recv_iov,
-			ep_attr->max_rdma_read_in, ep_attr->max_rdma_read_out);
-    }
-	return DAT_SUCCESS;
-}
-
-
-DAT_RETURN
-dapls_ib_completion_poll ( IN DAPL_HCA                *p_hca,
-                           IN DAPL_EVD                *p_evd,
-                           IN ib_work_completion_t   *cqe_ptr )
-{
-    ib_api_status_t        ib_status;
-    ib_work_completion_t   *cqe_filled;
-
-    /*
-     * FIXME - Vu
-     *     Now we only poll for one cqe. We can poll for more than
-     *     one completions later for better. However, this requires
-     *     to change the logic in dapl_evd_dto_callback function
-     *     to process more than one completion.
-     */
-    cqe_ptr->p_next = NULL;
-    cqe_filled      = NULL;
-
-    if  ( !p_hca->ib_hca_handle )
-    {
-        return DAT_INVALID_HANDLE;
-    }
-
-    ib_status = ib_poll_cq (p_evd->ib_cq_handle, &cqe_ptr, &cqe_filled);
-
-    if ( ib_status == IB_INVALID_CQ_HANDLE )
-    {
-        ib_status = IB_NOT_FOUND;
-    }
-
-    return dapl_ib_status_convert (ib_status);
-}
-
-
-DAT_RETURN
-dapls_ib_completion_notify ( IN ib_hca_handle_t         hca_handle,
-                             IN DAPL_EVD                *p_evd,
-                             IN ib_notification_type_t  type )
-{
-    ib_api_status_t        ib_status;
-    DAT_BOOLEAN            solic_notify;
-
-    if  ( !hca_handle )
-    {
-        return DAT_INVALID_HANDLE;
-    }
-    solic_notify = (type == IB_NOTIFY_ON_SOLIC_COMP) ? DAT_TRUE : DAT_FALSE; 
-    ib_status = ib_rearm_cq ( p_evd->ib_cq_handle, solic_notify );
-
-    return dapl_ib_status_convert (ib_status);
-}
-
-DAT_RETURN
-dapls_evd_dto_wakeup (
-	IN DAPL_EVD			*evd_ptr)
-{
-	return dapl_os_wait_object_wakeup(&evd_ptr->wait_object);
-}
-
-DAT_RETURN
-dapls_evd_dto_wait (
-	IN DAPL_EVD			*evd_ptr,
-	IN uint32_t 			timeout)
-{
-	return dapl_os_wait_object_wait(&evd_ptr->wait_object, timeout);
-}
-
-/*
- * dapls_ib_get_async_event
- *
- * Translate an asynchronous event type to the DAT event.
- * Note that different providers have different sets of errors.
- *
- * Input:
- *	cause_ptr		provider event cause
- *
- * Output:
- * 	async_event		DAT mapping of error
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_NOT_IMPLEMENTED	Caller is not interested this event
- */
-
-DAT_RETURN dapls_ib_get_async_event(
-	IN  ib_async_event_rec_t	*cause_ptr,
-	OUT DAT_EVENT_NUMBER		*async_event)
-{
-    ib_async_event_t		event_id;
-    DAT_RETURN			dat_status;
-
-    dat_status = DAT_SUCCESS;
-    event_id = cause_ptr->code;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_WARN, "--> DsAE: event_id = %d%d\n", event_id);
-
-    switch (event_id )
-    {
-        case IB_AE_SQ_ERROR:
-        case IB_AE_SQ_DRAINED:
-        case IB_AE_RQ_ERROR:
-	{
-	    *async_event = DAT_ASYNC_ERROR_EP_BROKEN;
-	    break;
-	}
-
-	/* INTERNAL errors */
-        case IB_AE_QP_FATAL:
-	case IB_AE_CQ_ERROR:
-	case IB_AE_LOCAL_FATAL:
-	case IB_AE_WQ_REQ_ERROR:
-	case IB_AE_WQ_ACCESS_ERROR:
-	{
-	    *async_event = DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR;
-	    break;
-	}
-
-	/* CATASTROPHIC errors */
-	case IB_AE_FLOW_CTRL_ERROR:
-	case IB_AE_BUF_OVERRUN:
-	{
-	    *async_event = DAT_ASYNC_ERROR_IA_CATASTROPHIC;
-	    break;
-	}
-
-	default:
-	{
-	    /*
-	     * Errors we are not interested in reporting:
-	     * IB_AE_QP_APM
-	     * IB_AE_PKEY_TRAP
-	     * IB_AE_QKEY_TRAP
-	     * IB_AE_MKEY_TRAP
-	     * IB_AE_PORT_TRAP
-	     * IB_AE_QP_APM_ERROR
-	     * IB_AE_PORT_ACTIVE
-	     * ...
-	     */
-	    dat_status = DAT_NOT_IMPLEMENTED;
-	}
-
-    }
-  
-    return dat_status;
-}
-
-/*
- * dapls_ib_get_dto_status
- *
- * Return the DAT status of a DTO operation
- *
- * Input:
- *	cqe_ptr			pointer to completion queue entry
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	Value from ib_status_map table above
- */
-
-DAT_DTO_COMPLETION_STATUS
-dapls_ib_get_dto_status(
-	IN ib_work_completion_t		*cqe_ptr)
-{
-    ib_uint32_t    ib_status;
-
-    ib_status = DAPL_GET_CQE_STATUS (cqe_ptr);
-
-    switch (ib_status)
-    {
-    case IB_COMP_ST_SUCCESS :
-	return	DAT_DTO_SUCCESS;
-
-    case IB_COMP_ST_LOCAL_LEN_ERR:
-	return DAT_DTO_ERR_LOCAL_LENGTH;
-
-    case IB_COMP_ST_LOCAL_OP_ERR:
-	return DAT_DTO_ERR_LOCAL_EP;
-
-    case IB_COMP_ST_LOCAL_PROTECT_ERR:
-	return DAT_DTO_ERR_LOCAL_PROTECTION;
-
-    case IB_COMP_ST_WR_FLUSHED_ERR:	
-	return DAT_DTO_ERR_FLUSHED;
-
-    case IB_COMP_ST_MW_BIND_ERR:
-	return DAT_RMR_OPERATION_FAILED;
-
-    case IB_COMP_ST_REM_ACC_ERR:
-	return DAT_DTO_ERR_REMOTE_ACCESS;
-
-    case IB_COMP_ST_REM_OP_ERR:
-	return DAT_DTO_ERR_REMOTE_RESPONDER;
-
-    case IB_COMP_ST_RNR_COUNTER:
-	return DAT_DTO_ERR_RECEIVER_NOT_READY;
-
-    case IB_COMP_ST_TRANSP_COUNTER:
-	return DAT_DTO_ERR_TRANSPORT;
-
-    case IB_COMP_ST_REM_REQ_ERR:
-	return DAT_DTO_ERR_REMOTE_RESPONDER;
-
-    case IB_COMP_ST_BAD_RESPONSE_ERR:
-	return DAT_DTO_ERR_BAD_RESPONSE;
-
-    case IB_COMP_ST_EE_STATE_ERR:
-    case IB_COMP_ST_EE_CTX_NO_ERR:
-    	return DAT_DTO_ERR_TRANSPORT;
-
-    default:
-#ifdef DAPL_DBG
-    dapl_dbg_log (DAPL_DBG_TYPE_ERR,"%s() unknown IB_COMP_ST %d(0x%x)\n",
-                  __FUNCTION__,ib_status,ib_status);
-#endif
-	return DAT_DTO_FAILURE;
-    }
-}
-
-
-/*
- * Map all IBAPI DTO completion codes to the DAT equivelent.
- *
- * dapls_ib_get_dat_event
- *
- * Return a DAT connection event given a provider CM event.
- *
- * N.B.	Some architectures combine async and CM events into a
- *	generic async event. In that case, dapls_ib_get_dat_event()
- *	and dapls_ib_get_async_event() should be entry points that
- *	call into a common routine.
- *
- * Input:
- *	ib_cm_event	event provided to the dapl callback routine
- *	active		switch indicating active or passive connection
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	DAT_EVENT_NUMBER of translated provider value
- */
-
-DAT_EVENT_NUMBER
-dapls_ib_get_dat_event (
-	IN    const ib_cm_events_t	ib_cm_event,
-	IN    DAT_BOOLEAN		active)
-{
-    DAT_EVENT_NUMBER		dat_event_num = 0;
-    UNREFERENCED_PARAMETER (active);
-
-    switch ( ib_cm_event)
-    {
-      case IB_CME_CONNECTED:
-          dat_event_num = DAT_CONNECTION_EVENT_ESTABLISHED;
-          break;
-      case IB_CME_DISCONNECTED:
-           dat_event_num = DAT_CONNECTION_EVENT_DISCONNECTED;
-           break;
-      case IB_CME_DISCONNECTED_ON_LINK_DOWN:
-           dat_event_num = DAT_CONNECTION_EVENT_DISCONNECTED;
-           break;
-      case IB_CME_CONNECTION_REQUEST_PENDING:
-           dat_event_num = DAT_CONNECTION_REQUEST_EVENT;
-           break;
-      case IB_CME_CONNECTION_REQUEST_PENDING_PRIVATE_DATA:
-           dat_event_num = DAT_CONNECTION_REQUEST_EVENT;
-           break;
-      case IB_CME_DESTINATION_REJECT:
-           dat_event_num = DAT_CONNECTION_EVENT_NON_PEER_REJECTED;
-           break;
-      case IB_CME_DESTINATION_REJECT_PRIVATE_DATA:
-           dat_event_num = DAT_CONNECTION_EVENT_PEER_REJECTED;
-           break;
-      case IB_CME_DESTINATION_UNREACHABLE:
-           dat_event_num = DAT_CONNECTION_EVENT_UNREACHABLE;
-           break;
-      case IB_CME_TOO_MANY_CONNECTION_REQUESTS:
-           dat_event_num = DAT_CONNECTION_EVENT_NON_PEER_REJECTED;
-           break;
-      case IB_CME_LOCAL_FAILURE:
-      	   dat_event_num = DAT_CONNECTION_EVENT_BROKEN;
-           break;
-      case IB_CME_REPLY_RECEIVED:
-      case IB_CME_REPLY_RECEIVED_PRIVATE_DATA:
-      default:
-           break;
-    }
-#if 0
-    dapl_dbg_log (DAPL_DBG_TYPE_CM,
-		  " dapls_ib_get_dat_event: event translation: (%s) "
-		  "ib_event 0x%x dat_event 0x%x\n",
-		  active ? "active" : "passive",
-		  ib_cm_event,
-		  dat_event_num);
-#endif
-    return dat_event_num;
-}
-
-
-/*
- * dapls_ib_get_dat_event
- *
- * Return a DAT connection event given a provider CM event.
- *
- * N.B.	Some architectures combine async and CM events into a
- *	generic async event. In that case, dapls_ib_get_cm_event()
- *	and dapls_ib_get_async_event() should be entry points that
- *	call into a common routine.
- *
- *	WARNING: In this implementation, there are multiple CM
- *	events that map to a single DAT event. Be very careful
- *	with provider routines that depend on this reverse mapping,
- *	they may have to accomodate more CM events than they
- *	'naturally' would.
- *
- * Input:
- *	dat_event_num	DAT event we need an equivelent CM event for
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	ib_cm_event of translated DAPL value
- */
-ib_cm_events_t
-dapls_ib_get_cm_event (
-	IN    DAT_EVENT_NUMBER		dat_event_num)
-{
-    ib_cm_events_t	ib_cm_event = 0;
-
-    switch (dat_event_num)
-    {
-        case DAT_CONNECTION_EVENT_ESTABLISHED:
-             ib_cm_event = IB_CME_CONNECTED;
-             break;
-        case DAT_CONNECTION_EVENT_DISCONNECTED:
-             ib_cm_event = IB_CME_DISCONNECTED;
-             break;
-        case DAT_CONNECTION_REQUEST_EVENT:
-             ib_cm_event =  IB_CME_CONNECTION_REQUEST_PENDING;
-             break;
-        case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:
-             ib_cm_event = IB_CME_DESTINATION_REJECT;
-             break;
-        case DAT_CONNECTION_EVENT_PEER_REJECTED:
-             ib_cm_event = IB_CME_DESTINATION_REJECT_PRIVATE_DATA;
-             break;
-        case DAT_CONNECTION_EVENT_UNREACHABLE:
-             ib_cm_event = IB_CME_DESTINATION_UNREACHABLE;
-             break;
-        case DAT_CONNECTION_EVENT_BROKEN:
-             ib_cm_event = IB_CME_LOCAL_FAILURE;
-             break;
-        default:
-             break;
-    }
-
-    return ib_cm_event;
-}
-
-
-
-/*
- * dapls_set_provider_specific_attr
- *
- * Input:
- *	attr_ptr	Pointer provider specific attributes
- *
- * Output:
- * 	none
- *
- * Returns:
- * 	void
- */
-
-#ifdef DAT_EXTENSIONS
-static DAT_NAMED_ATTR	ib_attrs[] = {
-    {
-    	"DAT_EXTENSION_INTERFACE", "TRUE"
-    },
-    {
-    	DAT_IB_ATTR_FETCH_AND_ADD, "TRUE"
-    },
-    {
-    	DAT_IB_ATTR_CMP_AND_SWAP, "TRUE"
-    },
-    {
-    	DAT_IB_ATTR_IMMED_DATA, "TRUE"
-    },
-};
-#define SPEC_ATTR_SIZE( x )	(sizeof( x ) / sizeof( DAT_NAMED_ATTR))
-#else
-static DAT_NAMED_ATTR	*ib_attrs = NULL;
-#define SPEC_ATTR_SIZE( x )	0
-#endif
-
-void dapls_query_provider_specific_attr(
-	IN	DAPL_IA				*ia_ptr,
-	IN	DAT_PROVIDER_ATTR	*attr_ptr )
-{
-    attr_ptr->num_provider_specific_attr = SPEC_ATTR_SIZE(ib_attrs);
-    attr_ptr->provider_specific_attr     = ib_attrs;
-}
-
-
-DAT_RETURN dapls_ns_map_gid (
-	IN  DAPL_HCA		*hca_ptr,
-	IN  DAT_IA_ADDRESS_PTR	remote_ia_address,
-	OUT GID			*gid)
-{
-    return (dapls_ib_ns_map_gid (hca_ptr, remote_ia_address, gid));
-}
-
-DAT_RETURN dapls_ns_map_ipaddr (
-	IN  DAPL_HCA		*hca_ptr,
-	IN  GID			gid,
-	OUT DAT_IA_ADDRESS_PTR	remote_ia_address)
-{
-    return (dapls_ib_ns_map_ipaddr (hca_ptr, gid, remote_ia_address));
-}
-
-
-#ifdef NOT_USED
-/*
- * dapls_ib_post_recv - defered.until QP ! in init state.
- *
- * Provider specific Post RECV function
- */
-
-DAT_RETURN 
-dapls_ib_post_recv_defered (
-	IN  DAPL_EP		   	*ep_ptr,
-	IN  DAPL_COOKIE			*cookie,
-	IN  DAT_COUNT	   		num_segments,
-	IN  DAT_LMR_TRIPLET	   	*local_iov)
-{
-    ib_api_status_t     ib_status;
-    ib_recv_wr_t	*recv_wr, *rwr;
-    ib_local_ds_t       *ds_array_p;
-    DAT_COUNT           i, total_len;
-
-    if (ep_ptr->qp_state != IB_QPS_INIT)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsPR: BAD QP state(%s), not init? "
-                      "EP %p QP %p cookie %p, num_seg %d\n", 
-                      ib_get_port_state_str(ep_ptr->qp_state), ep_ptr,
-                      ep_ptr->qp_handle, cookie, num_segments);
-	return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    recv_wr = dapl_os_alloc (sizeof(ib_recv_wr_t)
-                             + (num_segments*sizeof(ib_local_ds_t)));
-    if (NULL == recv_wr)
-    {
-	return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    dapl_os_memzero(recv_wr, sizeof(ib_recv_wr_t));
-    recv_wr->wr_id        = (DAT_UINT64) cookie;
-    recv_wr->num_ds       = num_segments;
-
-    ds_array_p = (ib_local_ds_t*)(recv_wr+1);
-
-    recv_wr->ds_array     = ds_array_p;
-
-    //total_len = 0;
-
-    for (total_len = i = 0; i < num_segments; i++, ds_array_p++)
-    {
-        ds_array_p->length = (uint32_t)local_iov[i].segment_length;
-        ds_array_p->lkey  = cl_hton32(local_iov[i].lmr_context);
-        ds_array_p->vaddr = local_iov[i].virtual_address;
-        total_len        += ds_array_p->length;
-    }
-
-    if (cookie != NULL)
-    {
-	cookie->val.dto.size = total_len;
-
-        dapl_dbg_log (DAPL_DBG_TYPE_EP,
-                      "--> DsPR: EP = %p QP = %p cookie= %p, num_seg= %d\n", 
-                      ep_ptr, ep_ptr->qp_handle, cookie, num_segments);
-    }
-
-    recv_wr->p_next = NULL;
-
-    /* find last defered recv work request, link new on the end */
-    rwr=ep_ptr->cm_post;
-    if (rwr == NULL)
-    {
-        ep_ptr->cm_post = (void*)recv_wr;
-        i = 1;
-    }
-    else
-    {
-        for(i=2; rwr->p_next; rwr=rwr->p_next) i++;
-        rwr->p_next = recv_wr;
-    }
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsPR: %s() EP %p QP %p cookie %p "
-                  "num_seg %d Tdefered %d\n", 
-                  __FUNCTION__, ep_ptr, ep_ptr->qp_handle, cookie, num_segments,
-                  i);
-
-    return DAT_SUCCESS;
-}
-#endif
-
-/*
- * Local variables:
- *  c-indent-level: 4
- *  c-basic-offset: 4
- *  tab-width: 8
- * End:
- */
-
+/*
+ * Copyright (c) 2005-2007 Intel Corporation. All rights reserved.  
+ * Copyright (c) 2002, Network Appliance, Inc. All rights reserved. 
+ * 
+ * This Software is licensed under the terms of the "Common Public
+ * License" a copy of which is in the file LICENSE.txt in the root
+ * directory. The license is also available from the Open Source
+ * Initiative, see http://www.opensource.org/licenses/cpl.php.
+ *
+ */
+
+/**********************************************************************
+ * 
+ * MODULE: dapl_ibal_util.c
+ *
+ * PURPOSE: Utility routines for access to IBAL APIs
+ *
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_adapter_util.h"
+#include "dapl_evd_util.h"
+#include "dapl_cr_util.h"
+#include "dapl_lmr_util.h"
+#include "dapl_rmr_util.h"
+#include "dapl_cookie.h"
+#include "dapl_ring_buffer_util.h"
+
+#ifdef DAT_EXTENSIONS
+#include <dat2\dat_ib_extensions.h>
+#endif
+
+#ifndef NO_NAME_SERVICE
+#include "dapl_name_service.h"
+#endif /* NO_NAME_SERVICE */
+
+#include "dapl_ibal_name_service.h"
+
+#define DAPL_IBAL_MAX_CA 4
+#define DAT_ADAPTER_NAME "InfiniHost (Tavor)"
+#define DAT_VENDOR_NAME  "Mellanox Technolgy Inc."
+
+/*
+ *  Root data structure for DAPL_IIBA.
+ */
+dapl_ibal_root_t        dapl_ibal_root;
+DAPL_HCA_NAME           dapl_ibal_hca_name_array [DAPL_IBAL_MAX_CA] = 
+                            {"IbalHca0", "IbalHca1", "IbalHca2", "IbalHca3"};
+ib_net64_t              *gp_ibal_ca_guid_tbl = NULL;
+
+/*
+ * DAT spec does not tie max_mtu_size with IB MTU
+ *
+static ib_net32_t dapl_ibal_mtu_table[6] = {0, 256, 512, 1024, 2048, 4096};
+ */
+    
+int g_loopback_connection = 0;
+
+
+static cl_status_t
+dapli_init_root_ca_list(
+    IN    dapl_ibal_root_t *root )
+{
+    cl_status_t status;
+
+    cl_qlist_init (&root->ca_head);
+    status = cl_spinlock_init (&root->ca_lock);
+
+    if (status == CL_SUCCESS)
+    {
+        /*
+         * Get the time ready to go but don't start here
+         */
+        root->shutdown = FALSE;
+        root->initialized = TRUE;
+    }
+    else
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DiIRCL: cl_spinlock_init returned %d\n", status );
+        root->initialized = FALSE;
+    }
+    
+    root->h_al = NULL;
+
+    return (status);
+}
+
+
+static cl_status_t
+dapli_destroy_root_ca_list(
+    IN    dapl_ibal_root_t *root )
+{
+
+    root->initialized = FALSE;
+
+    /* 
+     * At this point the lock should not be necessary
+     */
+    if (!cl_is_qlist_empty (&root->ca_head) )
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> Destroying nonempty ca list (%s)\n", "DiDRCL");
+    }
+    cl_spinlock_destroy (&root->ca_lock);
+
+    return CL_SUCCESS;
+}
+
+
+static void
+dapli_shutdown_port_access(
+    IN    dapl_ibal_ca_t    *ca )
+{
+    dapl_ibal_port_t    *p_port;
+
+    TAKE_LOCK( ca->port_lock );
+    {
+        while ( ! cl_is_qlist_empty( &ca->port_head ) )
+        {
+            p_port = (dapl_ibal_port_t *)cl_qlist_remove_head( &ca->port_head );
+            RELEASE_LOCK( ca->port_lock );
+            {
+                REMOVE_REFERENCE( &p_port->refs );
+                REMOVE_REFERENCE( &p_port->ca->refs );
+
+                dapl_os_free (p_port, sizeof (dapl_ibal_port_t));
+            }
+            TAKE_LOCK( ca->port_lock );
+        }
+    }
+    RELEASE_LOCK( ca->port_lock );
+}
+
+
+static void dapli_shutdown_ca_access (void)
+{
+    dapl_ibal_ca_t  *ca;
+
+    if ( dapl_ibal_root.initialized == FALSE )
+    {
+        goto destroy_root;
+    }
+
+    TAKE_LOCK (dapl_ibal_root.ca_lock);
+    {
+        while ( ! cl_is_qlist_empty (&dapl_ibal_root.ca_head) )
+        {
+            ca = (dapl_ibal_ca_t *)
+                                 cl_qlist_remove_head (&dapl_ibal_root.ca_head);
+
+            if (ca->p_ca_attr)
+            {
+                dapl_os_free (ca->p_ca_attr, sizeof (ib_ca_attr_t));
+            }
+
+
+            RELEASE_LOCK (dapl_ibal_root.ca_lock);
+            {
+                dapli_shutdown_port_access (ca);
+                REMOVE_REFERENCE (&ca->refs);
+            }
+            TAKE_LOCK (dapl_ibal_root.ca_lock);
+        }
+    }
+    RELEASE_LOCK (dapl_ibal_root.ca_lock);
+
+destroy_root:
+    /*
+     * Destroy the root CA list and list lock
+     */
+    dapli_destroy_root_ca_list (&dapl_ibal_root);
+
+    /*
+     * Signal we're all done and wake any waiter
+     */
+    dapl_ibal_root.shutdown = FALSE;
+}
+
+
+dapl_ibal_evd_cb_t *
+dapli_find_evd_cb_by_context(
+    IN    void           *context,
+    IN    dapl_ibal_ca_t *ca)
+{
+    dapl_ibal_evd_cb_t *evd_cb = NULL;
+
+    TAKE_LOCK( ca->evd_cb_lock );
+
+    evd_cb = (dapl_ibal_evd_cb_t *) cl_qlist_head( &ca->evd_cb_head );
+    while ( &evd_cb->next != cl_qlist_end( &ca->evd_cb_head ) )
+    {
+        if ( context == evd_cb->context)
+        {
+            goto found;
+        }
+
+        /*
+         *  Try again
+         */
+        evd_cb = (dapl_ibal_evd_cb_t *) cl_qlist_next( &evd_cb->next );
+    }
+    /*
+     *  No joy
+     */
+    evd_cb = NULL;
+
+found:
+
+    RELEASE_LOCK( ca->evd_cb_lock );
+
+    return ( evd_cb );
+}
+
+
+static cl_status_t
+dapli_init_ca_evd_cb_list(
+    IN    dapl_ibal_ca_t    *ca )
+{
+    cl_status_t    status;
+
+    cl_qlist_init( &ca->evd_cb_head );
+    status = cl_spinlock_init( &ca->evd_cb_lock );
+    if ( status != CL_SUCCESS )
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DiICECL: cl_spinlock_init returned %d\n", status);
+    return ( status );
+}
+
+
+static cl_status_t
+dapli_init_ca_port_list(
+    IN    dapl_ibal_ca_t    *ca )
+{
+    cl_status_t    status;
+
+    cl_qlist_init( &ca->port_head );
+    status = cl_spinlock_init( &ca->port_lock );
+    if ( status != CL_SUCCESS )
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DiICPL: cl_spinlock_init returned %d\n", status );
+    return ( status );
+}
+
+dapl_ibal_port_t  *
+dapli_ibal_get_port (
+    IN   dapl_ibal_ca_t    *p_ca,
+    IN   uint8_t           port_num)
+{
+    cl_list_item_t    *p_active_port = NULL;
+    
+    TAKE_LOCK (p_ca->port_lock);
+    for ( p_active_port = cl_qlist_head( &p_ca->port_head );
+          p_active_port != cl_qlist_end ( &p_ca->port_head);
+          p_active_port =  cl_qlist_next ( p_active_port ) )
+    {
+        if (((dapl_ibal_port_t *)p_active_port)->p_attr->port_num == port_num)
+            break;	
+    }
+    RELEASE_LOCK (p_ca->port_lock);
+
+    return (dapl_ibal_port_t *)p_active_port;
+}
+
+
+void
+dapli_ibal_ca_async_error_callback( IN ib_async_event_rec_t  *p_err_rec )
+{
+    dapl_ibal_ca_t	*p_ca = (dapl_ibal_ca_t*)((void *)p_err_rec->context);
+    dapl_ibal_evd_cb_t	*evd_cb;
+    DAPL_IA		*ia_ptr;
+			
+    dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DiCaAEC: CA error %d for context %p\n", 
+                       p_err_rec->code, p_err_rec->context);
+
+    if (p_ca == NULL)
+    {
+       	dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DiCaAEC: invalid p_ca"
+                              "(%p)in async event rec\n",p_ca);
+    	return;
+    }
+	
+    ia_ptr = (DAPL_IA*)p_ca->ia_ptr;
+    if (ia_ptr == NULL)
+    {
+       	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                              "--> DiCaAEC: invalid ia_ptr in %p ca \n", p_ca );
+	return;
+    }
+
+    if (ia_ptr->async_error_evd == NULL)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> DiCqAEC: can't find async_error_evd on %s HCA\n", 
+                      (ia_ptr->header.provider)->device_name );
+        return;
+    }
+
+    /* find QP error callback using p_ca for context */
+    evd_cb = dapli_find_evd_cb_by_context (ia_ptr->async_error_evd, p_ca);
+    if ((evd_cb == NULL) || (evd_cb->pfn_async_err_cb == NULL))
+    {
+    	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                              "--> DiCaAEC: no ERROR cb on %p found \n", p_ca);
+    	return;
+    }
+
+    /* maps to dapl_evd_un_async_error_callback(), context is async_evd */
+    evd_cb->pfn_async_err_cb( (ib_hca_handle_t)p_ca, 
+                              (ib_error_record_t*)&p_err_rec->code, 
+                              ia_ptr->async_error_evd );
+
+}
+
+
+static dapl_ibal_port_t *
+dapli_alloc_port(
+    IN    dapl_ibal_ca_t    *ca,
+    IN    ib_port_attr_t    *ib_port )
+{
+    dapl_ibal_port_t    *p_port = NULL;
+
+    if (ca->h_ca == NULL )
+    {
+    	return NULL;
+    }
+
+    /*
+     *  Allocate the port structure memory.  This will also deal with the
+     *  copying ib_port_attr_t including GID and P_Key tables
+     */
+    p_port = dapl_os_alloc ( sizeof(dapl_ibal_port_t ) );
+
+    if ( p_port )
+    {
+        dapl_os_memzero (p_port, sizeof(dapl_ibal_port_t ) );
+
+        /*
+         *  We're good to go after initializing reference.
+         */
+        INIT_REFERENCE( &p_port->refs, 1, p_port, NULL /* pfn_destructor */ );
+		
+		p_port->p_attr = ib_port;
+    }
+    return ( p_port );
+}
+
+static void
+dapli_add_active_port(
+    IN dapl_ibal_ca_t   *ca )
+{
+    dapl_ibal_port_t     *p_port;
+    ib_port_attr_t       *p_port_attr;
+    ib_ca_attr_t         *p_ca_attr;
+    int                  i;
+
+    p_ca_attr = ca->p_ca_attr;
+
+    dapl_os_assert (p_ca_attr != NULL);
+
+    for (i = 0; i < p_ca_attr->num_ports; i++)
+    {
+        p_port_attr = &p_ca_attr->p_port_attr[i];
+
+        {
+            p_port = dapli_alloc_port( ca, p_port_attr );
+            if ( p_port )
+            {
+                TAKE_REFERENCE (&ca->refs);
+
+                /*
+                 *  Record / update attribues
+                 */
+                p_port->p_attr = p_port_attr;
+
+                /*
+                 *  Remember the parant CA keeping the reference we took above
+                 */
+                p_port->ca = ca;
+
+                /*
+                 *  We're good to go - Add the new port to the list on the CA
+                 */
+                LOCK_INSERT_TAIL( ca->port_lock, ca->port_head, p_port->next );
+            }
+            else
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                               "--> %s: Could not allocate dapl_ibal_port_t\n",
+                               "DiAAP");
+            }
+        }
+	dapl_dbg_log( DAPL_DBG_TYPE_UTIL,
+                      "--> DiAAP: Port %d logical link %s lid = %#x\n",
+                      p_port_attr->port_num,
+                      ( p_port_attr->link_state != IB_LINK_ACTIVE
+                           ?  "DOWN": "UP" ),
+                      CL_HTON16(p_port_attr->lid) );
+
+    } /* for loop */
+}
+
+static dapl_ibal_ca_t *
+dapli_alloc_ca(
+    IN    ib_al_handle_t  h_al,
+    IN    ib_net64_t      ca_guid)
+{
+    dapl_ibal_ca_t         *p_ca;
+    ib_api_status_t        status;
+    uint32_t               attr_size;
+
+    /*
+     *  Allocate the CA structure
+     */
+    p_ca = dapl_os_alloc( sizeof(dapl_ibal_ca_t) );
+    dapl_os_memzero (p_ca, sizeof(dapl_ibal_ca_t) );
+
+    if ( p_ca )
+    {
+        /*
+         *  Now we pass dapli_ibal_ca_async_error_callback as the 
+         *  async error callback
+         */
+        status = ib_open_ca( h_al,
+                             ca_guid,
+                             dapli_ibal_ca_async_error_callback,
+                             p_ca,
+                             &p_ca->h_ca );
+        if ( status != IB_SUCCESS )
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> DiAC: ib_open_ca returned %s\n",
+                           ib_get_err_str(status));
+            dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
+            return (NULL);
+        }
+
+        /*
+         *  Get port list lock and list head initialized
+         */
+        if (( dapli_init_ca_port_list( p_ca ) != CL_SUCCESS ) ||
+            ( dapli_init_ca_evd_cb_list( p_ca ) != CL_SUCCESS ))
+        { 
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> %s: dapli_init_ca_port_list returned failed\n",
+                           "DiAC");
+            goto close_and_free_ca;
+        }
+
+        attr_size = 0;
+        status = ib_query_ca (p_ca->h_ca, NULL, &attr_size);
+        if (status != IB_INSUFFICIENT_MEMORY)
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                          "--> DiAC: ib_query_ca returned failed status = %d\n",
+                          status);
+            goto close_and_free_ca;
+        }
+
+        p_ca->p_ca_attr = dapl_os_alloc ((int)attr_size);
+        if (p_ca->p_ca_attr == NULL)
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> %s: dapli_alloc_ca failed to alloc memory\n",
+                           "DiAC");
+            goto close_and_free_ca;
+        }
+
+        status = ib_query_ca (
+                          p_ca->h_ca,
+                          p_ca->p_ca_attr,
+                          &attr_size);
+        if (status != IB_SUCCESS)
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> ib_query_ca returned failed status = %d\n",
+                           status);
+            dapl_os_free (p_ca->p_ca_attr, (int)attr_size);
+            goto close_and_free_ca;
+        }
+       
+        p_ca->ca_attr_size = attr_size;
+
+        INIT_REFERENCE( &p_ca->refs, 1, p_ca, NULL /* pfn_destructor */ );
+
+        dapli_add_active_port (p_ca);
+
+        /*
+         *  We're good to go
+         */
+        return ( p_ca );
+    }
+    else
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> %s: Error allocating CA structure\n","DiAC");
+        return ( NULL );
+    }
+
+close_and_free_ca:
+   /*
+    *  Close the CA.
+    */
+   (void) ib_close_ca ( p_ca->h_ca, NULL /* callback */);
+   dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
+
+    /*
+     *  If we get here, there was an initialization failure
+     */
+    return ( NULL );
+}
+
+
+static dapl_ibal_ca_t *
+dapli_add_ca (
+    IN   ib_al_handle_t    h_al,
+    IN   ib_net64_t        ca_guid )
+{
+    dapl_ibal_ca_t     *p_ca;
+
+    /*
+     *  Allocate a CA structure
+     */
+    p_ca = dapli_alloc_ca( h_al, ca_guid );
+    if ( p_ca )
+    {
+        /*
+         *  Add the new CA to the list
+         */
+        LOCK_INSERT_TAIL( dapl_ibal_root.ca_lock, 
+                          dapl_ibal_root.ca_head, p_ca->next );
+    }
+    else
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> %s: Could not allocate dapl_ibal_ca_t "
+                       " for CA guid " F64x "\n","DiAA",ca_guid);
+    }
+
+    return ( p_ca );
+}
+
+
+int32_t
+dapls_ib_init (void)
+{
+    ib_api_status_t status;
+
+    /*
+     * Initialize the root structure
+     */
+    if ( dapli_init_root_ca_list (&dapl_ibal_root) == CL_SUCCESS )
+    {
+        /*
+         * Register with the access layer
+         */
+        status = ib_open_al (&dapl_ibal_root.h_al);
+
+        if (status == IB_SUCCESS)
+        {
+            intn_t             guid_count;
+
+            status = ib_get_ca_guids ( dapl_ibal_root.h_al,
+                                       NULL,
+                                       &(size_t)guid_count );
+            if (status != IB_INSUFFICIENT_MEMORY)
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                               "--> %s: ib_get_ca_guids failed = %d\n",
+                               __FUNCTION__,status);
+                return -1;
+            }
+
+            if (guid_count == 0)
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                               "--> %s: found NO HCA in the system\n",
+                               __FUNCTION__);
+                return -1;
+            }
+
+            if (guid_count > DAPL_IBAL_MAX_CA)
+            {
+                guid_count = DAPL_IBAL_MAX_CA;
+            }
+
+            gp_ibal_ca_guid_tbl = (ib_net64_t*)
+                                  dapl_os_alloc ( (int)(guid_count * 
+                                                  sizeof (ib_net64_t)) );
+
+            if (gp_ibal_ca_guid_tbl == NULL)
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> %s() can not alloc "
+                               "gp_ibal_ca_guid_tbl\n", __FUNCTION__);
+                        
+                return -1;
+            }
+
+            status = ib_get_ca_guids ( dapl_ibal_root.h_al, 
+                                       gp_ibal_ca_guid_tbl, 
+                                       &(size_t)guid_count );
+                            
+
+            if ( status != IB_SUCCESS )
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                               "--> %s: ib_get_ca_guids failed '%s'\n", 
+                               __FUNCTION__, ib_get_err_str(status) );
+                return -1;
+            }
+
+            dapl_dbg_log ( DAPL_DBG_TYPE_UTIL, 
+                           "--> %s: Success open AL & found %d HCA avail,\n",
+                           __FUNCTION__, guid_count);
+            return 0;
+        }
+        else
+        {        
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> %s: ib_open_al() failed '%s'\n",
+                           __FUNCTION__, ib_get_err_str(status) );
+            /*
+             * Undo CA list
+             */
+            dapli_destroy_root_ca_list (&dapl_ibal_root);
+        }
+    }
+    return -1;
+}
+
+
+int32_t dapls_ib_release (void)
+{
+    dapl_ibal_root.shutdown = TRUE;
+
+    dapli_shutdown_ca_access();
+
+    /*
+     * If shutdown not complete, wait for it
+     */
+    if (dapl_ibal_root.shutdown)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                        "--> DsIR: timeout waiting for completion\n");
+    }
+
+    if ( dapl_ibal_root.h_al != NULL )
+    {
+        (void) ib_close_al (dapl_ibal_root.h_al);
+	dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIR: ib_close_al() returns\n");
+        dapl_ibal_root.h_al = NULL;
+    }
+#if DBG
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> %s: Exit\n",__FUNCTION__);
+#endif
+
+    return 0;
+}
+
+
+/*
+ * dapls_ib_enum_hcas
+ *
+ * Enumerate all HCAs on the system
+ *
+ * Input:
+ * 	none
+ *
+ * Output:
+ *	hca_names	Array of hca names
+ *	total_hca_count	
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_enum_hcas (
+        IN   const char          *vendor,
+        OUT  DAPL_HCA_NAME       **hca_names,
+        OUT  DAT_COUNT           *total_hca_count )
+{
+    intn_t             guid_count;
+    ib_api_status_t    ib_status;
+    UNREFERENCED_PARAMETER(vendor);
+
+    ib_status = ib_get_ca_guids (dapl_ibal_root.h_al, NULL, &(size_t)guid_count);
+    if (ib_status != IB_INSUFFICIENT_MEMORY)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIEH: ib_get_ca_guids failed '%s'\n",
+                       ib_get_err_str(ib_status) );
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    if (guid_count == 0)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> %s: ib_get_ca_guids no HCA in the system\n",
+                       "DsIEH");
+        return (DAT_PROVIDER_NOT_FOUND);
+    }
+
+    if (guid_count > DAPL_IBAL_MAX_CA)
+    {
+        guid_count = DAPL_IBAL_MAX_CA;
+    }
+
+    gp_ibal_ca_guid_tbl = (ib_net64_t *)dapl_os_alloc ((int)(guid_count * sizeof (ib_net64_t)) );
+
+    if (gp_ibal_ca_guid_tbl == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> %s: can not alloc resources @line%d\n", "DsIEH",
+                       __LINE__);
+        return (DAT_INSUFFICIENT_RESOURCES);
+    }
+
+    ib_status = ib_get_ca_guids ( dapl_ibal_root.h_al,
+                                  gp_ibal_ca_guid_tbl,
+                                  &(size_t)guid_count);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIEH: ib_get_ca_guids failed status = %s\n", 
+                       ib_get_err_str(ib_status) );
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    *hca_names = (DAPL_HCA_NAME*)
+                     dapl_os_alloc ((int)(guid_count * sizeof (DAPL_HCA_NAME)));
+
+    if (*hca_names == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> %s: can not alloc resources @line%d\n",
+                       "DsIEH", __LINE__);
+        return (DAT_INSUFFICIENT_RESOURCES);
+    }
+
+    dapl_os_memcpy (*hca_names, 
+                    dapl_ibal_hca_name_array, 
+                    (int)(guid_count * sizeof (DAPL_HCA_NAME)) );
+
+    *total_hca_count = (DAT_COUNT)guid_count;
+
+    {
+        int i;
+
+        for (i = 0; i < guid_count; i++)
+            dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIEH: %d) hca_names = %s\n",
+                          i, dapl_ibal_hca_name_array[i]);
+    }
+
+    return (DAT_SUCCESS);
+}
+
+
+
+IB_HCA_NAME
+dapl_ib_convert_name(
+    IN  char    *name)
+{
+    int                i;
+
+    if (gp_ibal_ca_guid_tbl  == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DICN: found no HCA with name %s\n", name );
+        return 0;
+    }
+
+    for (i = 0; i < DAPL_IBAL_MAX_CA; i++)
+    {
+        if (strcmp (name, dapl_ibal_hca_name_array[i]) == 0)
+        {
+            break;
+        }
+    }
+
+    if (i >= DAPL_IBAL_MAX_CA)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DICN: can't find any HCA with name %s\n", name);
+        return 0;
+    }
+   
+    return (gp_ibal_ca_guid_tbl[i]);
+}
+
+
+/*
+ * dapls_ib_open_hca
+ *
+ * Open HCA
+ *
+ * Input:
+ *      *hca_name         pointer to provider device name
+ *      *ib_hca_handle_p  pointer to provide HCA handle
+ *
+ * Output:
+ *      none
+ *
+ * Return:
+ *      DAT_SUCCESS
+ *      DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN dapls_ib_open_hca ( IN  char         *hca_name,
+                               IN  DAPL_HCA     *p_hca )
+{
+    dapl_ibal_ca_t     *p_ca;
+    IB_HCA_NAME        ca_guid;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL," open_hca: %s - %p\n", hca_name, p_hca);
+
+    if (gp_ibal_ca_guid_tbl  == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIOH: found no HCA with ca_guid"
+                       F64x "\n", hca_name);
+        return (DAT_PROVIDER_NOT_FOUND);
+    }
+
+    ca_guid = dapl_ib_convert_name(hca_name);
+
+    p_ca = dapli_add_ca (dapl_ibal_root.h_al, ca_guid);
+
+    if (p_ca == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                     "--> DsIOH: can not create ca for '%s' guid " F64x "\n",
+                     hca_name, ca_guid);
+        return (DAT_INSUFFICIENT_RESOURCES);
+    }
+
+    p_hca->ib_hca_handle = (ib_hca_handle_t) p_ca;
+    p_hca->ib_trans.d_hca = p_hca; // back-link
+
+    /* initialize hca wait object for uAT event */
+    dapl_os_wait_object_init(&p_hca->ib_trans.wait_object);
+
+#if SOCK_CM
+    {
+	DAT_RETURN    dat_status;
+
+	dat_status = dapli_init_sock_cm(p_hca);
+	if ( dat_status != DAT_SUCCESS )
+	{
+		dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+				" %s() failed to init sock_CM\n", __FUNCTION__);
+		return DAT_INTERNAL_ERROR;
+	}
+
+	/* initialize cr_list lock */
+	dat_status = dapl_os_lock_init(&p_hca->ib_trans.lock);
+	if (dat_status != DAT_SUCCESS)
+	{
+		dapl_dbg_log (DAPL_DBG_TYPE_ERR, " %s() failed to init lock\n",
+				__FUNCTION__);
+		return DAT_INTERNAL_ERROR;
+	}
+
+	/* initialize CM list for listens on this HCA */
+	dapl_llist_init_head((DAPL_LLIST_HEAD*)&p_hca->ib_trans.list);
+    }
+#endif
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapls_ib_close_hca
+ *
+ * Open HCA
+ *
+ * Input:
+ *      ib_hca_handle   provide HCA handle
+ *
+ * Output:
+ *      none
+ *
+ * Return:
+ *      DAT_SUCCESS
+ *      DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN dapls_ib_close_hca ( IN  DAPL_HCA  *p_hca )
+{
+    dapl_ibal_ca_t     *p_ca;
+   
+    p_ca =  (dapl_ibal_ca_t *) p_hca->ib_hca_handle;
+   
+#if SOCK_CM
+#endif
+    /*
+     * Remove it from the list
+     */
+    TAKE_LOCK (dapl_ibal_root.ca_lock);
+    {
+        cl_qlist_remove_item (&dapl_ibal_root.ca_head, &p_ca->next);
+    }
+    RELEASE_LOCK (dapl_ibal_root.ca_lock);
+
+    dapli_shutdown_port_access (p_ca);
+ 
+    /*
+     * Remove the constructor reference
+     */
+    REMOVE_REFERENCE (&p_ca->refs);
+
+    (void) ib_close_ca (p_ca->h_ca, ib_sync_destroy);
+
+    cl_spinlock_destroy (&p_ca->port_lock);
+    cl_spinlock_destroy (&p_ca->evd_cb_lock);
+
+    if (p_ca->p_ca_attr)
+        dapl_os_free (p_ca->p_ca_attr, sizeof (ib_ca_attr_t));
+
+    p_hca->ib_hca_handle = IB_INVALID_HANDLE;
+    dapl_os_free (p_ca, sizeof (dapl_ibal_ca_t));
+
+    return (DAT_SUCCESS);
+}
+
+
+
+/*
+ * dapl_ib_pd_alloc
+ *
+ * Alloc a PD
+ *
+ * Input:
+ *	ia_handle		IA handle
+ *	PZ_ptr			pointer to PZEVD struct
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_pd_alloc (
+        IN  DAPL_IA                 *ia,
+        IN  DAPL_PZ                 *pz)
+{
+    ib_api_status_t         ib_status;
+    dapl_ibal_ca_t          *p_ca;
+
+    p_ca = (dapl_ibal_ca_t *) ia->hca_ptr->ib_hca_handle;
+
+    ib_status = ib_alloc_pd (
+                              p_ca->h_ca,
+                              IB_PDT_NORMAL,
+                              ia,
+                              &pz->pd_handle );
+
+    return dapl_ib_status_convert (ib_status);
+}
+
+
+/*
+ * dapl_ib_pd_free
+ *
+ * Free a PD
+ *
+ * Input:
+ *	PZ_ptr			pointer to PZ struct
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_pd_free (
+        IN  DAPL_PZ                 *pz)
+{
+    ib_api_status_t                 ib_status;
+
+    ib_status = ib_dealloc_pd (pz->pd_handle, /* destroy_callback */ NULL);
+
+    pz->pd_handle = IB_INVALID_HANDLE;
+
+    return dapl_ib_status_convert (ib_status);
+}
+
+
+/*
+ * dapl_ib_mr_register
+ *
+ * Register a virtual memory region
+ *
+ * Input:
+ *	ia_handle		IA handle
+ *	lmr			pointer to dapl_lmr struct
+ *	virt_addr		virtual address of beginning of mem region
+ *	length			length of memory region
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mr_register (
+        IN  DAPL_IA                 *ia,
+        IN  DAPL_LMR                *lmr,
+        IN  DAT_PVOID                virt_addr,
+        IN  DAT_VLEN                length,
+        IN  DAT_MEM_PRIV_FLAGS      privileges,
+        IN  DAT_VA_TYPE             va_type)
+{
+    ib_api_status_t     ib_status;
+    ib_mr_handle_t      mr_handle;
+    ib_mr_create_t      mr_create;
+    uint32_t            l_key, r_key; 
+
+    if ( ia == NULL || ia->header.magic != DAPL_MAGIC_IA )
+    {
+        return DAT_INVALID_HANDLE;
+    }
+
+    /* IBAL does not support */
+    if (va_type == DAT_VA_TYPE_ZB) {
+        dapl_dbg_log(DAPL_DBG_TYPE_ERR,
+    	             "--> va_type == DAT_VA_TYPE_ZB: NOT SUPPORTED\n");    
+        return DAT_ERROR (DAT_NOT_IMPLEMENTED, DAT_NO_SUBTYPE);  
+    }
+
+    mr_create.vaddr         = (void *) virt_addr;
+    mr_create.length        = (size_t)length;
+    mr_create.access_ctrl   = dapl_lmr_convert_privileges (privileges);
+    mr_create.access_ctrl   |= IB_AC_MW_BIND;
+   
+    if (lmr->param.mem_type == DAT_MEM_TYPE_SHARED_VIRTUAL)
+    {
+        ib_status = ib_reg_shmid (
+                          ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
+                          (const uint8_t*)lmr->shmid,
+                          &mr_create,
+                          (uint64_t *)&virt_addr,
+                          &l_key,
+                          &r_key,
+                          &mr_handle);
+    }
+    else 
+    {
+        ib_status = ib_reg_mem ( ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
+                                 &mr_create,
+                                 &l_key,
+                                 &r_key,
+                                 &mr_handle );
+    }
+    
+    if (ib_status != IB_SUCCESS)
+    {
+        return (dapl_ib_status_convert (ib_status));
+    }
+    
+    /* DAT/DAPL expects context in host order */
+    l_key = cl_ntoh32(l_key);
+    r_key = cl_ntoh32(r_key);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMR: lmr (%p) lkey = 0x%x "
+                  "r_key= %#x mr_handle %p vaddr 0x%LX len 0x%LX\n", 
+                  lmr, l_key, r_key, mr_handle, virt_addr, length);
+
+    lmr->param.lmr_context = l_key;
+    lmr->param.rmr_context = r_key;
+    lmr->param.registered_size = length;
+    lmr->param.registered_address = (DAT_VADDR)virt_addr;
+    lmr->mr_handle         = mr_handle;
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapl_ib_mr_deregister
+ *
+ * Free a memory region
+ *
+ * Input:
+ *	lmr			pointer to dapl_lmr struct
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mr_deregister (
+        IN  DAPL_LMR                *lmr)
+{
+    ib_api_status_t                ib_status;
+
+    ib_status = ib_dereg_mr (lmr->mr_handle);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    lmr->param.lmr_context = 0;
+    lmr->mr_handle         = IB_INVALID_HANDLE;
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapl_ib_mr_register_shared
+ *
+ * Register a virtual memory region
+ *
+ * Input:
+ *	ia_handle		IA handle
+ *	lmr			pointer to dapl_lmr struct
+ *	virt_addr		virtual address of beginning of mem region
+ *	length			length of memory region
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mr_register_shared (
+        IN  DAPL_IA                  *ia,
+        IN  DAPL_LMR                 *lmr,
+        IN  DAT_MEM_PRIV_FLAGS       privileges,
+        IN  DAT_VA_TYPE              va_type )
+{
+    DAT_VADDR                   virt_addr;
+    ib_mr_handle_t              mr_handle;
+    ib_api_status_t             ib_status;
+    ib_mr_handle_t              new_mr_handle;
+    ib_access_t                 access_ctrl;
+    uint32_t                    l_key, r_key; 
+    ib_mr_create_t      mr_create;
+    if ( ia == NULL || ia->header.magic != DAPL_MAGIC_IA )
+    {
+        return DAT_INVALID_HANDLE;
+    }
+
+    /* IBAL does not support?? */
+    if (va_type == DAT_VA_TYPE_ZB) {
+        dapl_dbg_log(DAPL_DBG_TYPE_ERR,
+    	    " va_type == DAT_VA_TYPE_ZB: NOT SUPPORTED\n");    
+        return DAT_ERROR (DAT_NOT_IMPLEMENTED, DAT_NO_SUBTYPE);  
+    }
+
+    virt_addr = dapl_mr_get_address (lmr->param.region_desc,
+                                     lmr->param.mem_type);
+
+    access_ctrl   = dapl_lmr_convert_privileges (privileges);
+    access_ctrl  |= IB_AC_MW_BIND;
+
+    mr_create.vaddr         = (void *) virt_addr;
+    mr_create.access_ctrl   = access_ctrl;
+    mr_handle = (ib_mr_handle_t) lmr->mr_handle;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                       "--> DsIMRS: orig mr_handle %p vaddr %p\n", 
+                       mr_handle, virt_addr);
+
+    if (lmr->param.mem_type == DAT_MEM_TYPE_SHARED_VIRTUAL)
+    {
+        ib_status = ib_reg_shmid ( ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
+                                   (const uint8_t*)lmr->shmid,
+                                   &mr_create,
+                                   &virt_addr,
+                                   &l_key,
+                                   &r_key,
+                                   &new_mr_handle );
+    }
+    else
+    { 
+
+        ib_status = ib_reg_shared ( mr_handle,
+                                   ((DAPL_PZ *)lmr->param.pz_handle)->pd_handle,
+                                   access_ctrl,
+                                   /* in/out */(DAT_UINT64 *)&virt_addr,
+                                   &l_key,
+                                   &r_key,
+                                   &new_mr_handle );
+    }
+
+    if (ib_status != IB_SUCCESS)
+    {
+        return dapl_ib_status_convert (ib_status);
+    }
+    /*
+     * FIXME - Vu
+     *    What if virt_addr as an OUTPUT having the actual virtual address
+     *    assigned to the register region
+     */
+
+    /* DAT/DAPL expects context to be in host order */
+    l_key = cl_ntoh32(l_key);
+    r_key = cl_ntoh32(r_key);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMRS: lmr (%p) lkey = 0x%x "
+                  "new mr_handle %p vaddr %p\n",
+                  lmr, l_key, new_mr_handle, virt_addr);
+
+    lmr->param.lmr_context = l_key;
+    lmr->param.rmr_context = r_key;
+    lmr->param.registered_address = (DAT_VADDR) (uintptr_t) virt_addr;
+    lmr->mr_handle         = new_mr_handle;
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapls_ib_mw_alloc
+ *
+ * Bind a protection domain to a memory window
+ *
+ * Input:
+ *	rmr			Initialized rmr to hold binding handles
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mw_alloc ( IN  DAPL_RMR    *rmr )
+{
+    ib_api_status_t     ib_status;
+    uint32_t            r_key;
+    ib_mw_handle_t      mw_handle;
+
+    ib_status = ib_create_mw (
+                  ((DAPL_PZ *)rmr->param.pz_handle)->pd_handle,
+                  &r_key,
+                  &mw_handle);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIMA: create MW failed = %s\n",
+                       ib_get_err_str(ib_status) );
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    rmr->mw_handle         = mw_handle;
+    rmr->param.rmr_context = (DAT_RMR_CONTEXT) cl_ntoh32(r_key);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                       "--> DsIMA: mw_handle %p r_key = 0x%x\n", 
+                        mw_handle, rmr->param.rmr_context);
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapls_ib_mw_free
+ *
+ * Release bindings of a protection domain to a memory window
+ *
+ * Input:
+ *	rmr			Initialized rmr to hold binding handles
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mw_free (
+        IN  DAPL_RMR                         *rmr)
+{
+    ib_api_status_t         ib_status;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                       "--> DsIMF: mw_handle %p\n", rmr->mw_handle);
+
+    ib_status = ib_destroy_mw (rmr->mw_handle);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMF: Free MW failed = %s\n",
+                       ib_get_err_str(ib_status));
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    rmr->param.rmr_context = 0;
+    rmr->mw_handle         = IB_INVALID_HANDLE;
+
+    return (DAT_SUCCESS);
+}
+
+/*
+ * dapls_ib_mw_bind
+ *
+ * Bind a protection domain to a memory window
+ *
+ * Input:
+ *	rmr			Initialized rmr to hold binding handles
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mw_bind (
+        IN  DAPL_RMR                *rmr,
+        IN  DAPL_LMR                *lmr,
+        IN  DAPL_EP                 *ep,
+        IN  DAPL_COOKIE             *cookie,
+        IN  DAT_VADDR               virtual_address,
+        IN  DAT_VLEN                length,
+        IN  DAT_MEM_PRIV_FLAGS      mem_priv,
+        IN  ib_bool_t               is_signaled)
+{
+    ib_api_status_t       ib_status;
+    ib_bind_wr_t          bind_wr_prop;
+    uint32_t              new_rkey;
+    
+    bind_wr_prop.local_ds.vaddr   = virtual_address;
+    bind_wr_prop.local_ds.length  = (uint32_t)length;
+    bind_wr_prop.local_ds.lkey    = cl_hton32(lmr->param.lmr_context);
+    bind_wr_prop.current_rkey     = cl_hton32(rmr->param.rmr_context);
+    bind_wr_prop.access_ctrl      = dapl_rmr_convert_privileges (mem_priv);
+    bind_wr_prop.send_opt         = (is_signaled == TRUE) ? 
+                                    IB_SEND_OPT_SIGNALED : 0;
+    bind_wr_prop.wr_id            = (uint64_t) ((uintptr_t) cookie);
+    bind_wr_prop.h_mr             = lmr->mr_handle;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, "--> DsIMB: mr_handle %p, mw_handle %p "
+                  "vaddr %#I64x length %#I64x\n", 
+                  lmr->mr_handle, rmr->mw_handle, virtual_address, length);
+
+    ib_status = ib_bind_mw (
+                    rmr->mw_handle,
+                    ep->qp_handle,
+                    &bind_wr_prop,
+                    &new_rkey);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMB: Bind MW failed = %s\n", 
+                       ib_get_err_str(ib_status));
+        return (dapl_ib_status_convert (ib_status));
+    }
+
+    rmr->param.rmr_context      = (DAT_RMR_CONTEXT) cl_ntoh32(new_rkey);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL,
+			"--> DsIMB: new_rkey = 0x%x\n", rmr->param.rmr_context);
+
+    return (DAT_SUCCESS);
+}
+
+/*
+ * dapls_ib_mw_unbind
+ *
+ * Unbind a memory window
+ *
+ * Input:
+ *	rmr			Initialized rmr to hold binding handles
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *
+ */
+DAT_RETURN
+dapls_ib_mw_unbind (
+	IN  DAPL_RMR		*rmr,
+	IN  DAPL_EP		*ep,
+	IN  DAPL_COOKIE		*cookie,
+	IN  ib_bool_t		is_signaled)
+{
+    ib_api_status_t       ib_status;
+    ib_bind_wr_t          bind_wr_prop;
+    uint32_t              new_rkey;
+    
+    bind_wr_prop.local_ds.vaddr   = 0;
+    bind_wr_prop.local_ds.length  = 0;
+    bind_wr_prop.local_ds.lkey    = 0;
+    bind_wr_prop.access_ctrl      = 0;
+    bind_wr_prop.send_opt         = (is_signaled == TRUE) ? 
+                                    IB_SEND_OPT_SIGNALED : 0;
+    bind_wr_prop.wr_id            = (uint64_t) ((uintptr_t) cookie);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                       "--> DsIMU: mw_handle = %p\n", rmr->mw_handle);
+
+    ib_status = ib_bind_mw (
+                    rmr->mw_handle,
+                    ep->qp_handle,
+                    &bind_wr_prop,
+                    &new_rkey);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsIMU: Unbind MW failed = %s\n", 
+                ib_get_err_str(ib_status));
+        return (dapl_ib_status_convert (ib_status));
+    }
+
+    rmr->param.rmr_context      = (DAT_RMR_CONTEXT) cl_ntoh32(new_rkey);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL, 
+                  "--> DsIMU: unbind new_rkey 0x%x\n", rmr->param.rmr_context);
+
+    return (DAT_SUCCESS);
+}
+
+
+/*
+ * dapls_ib_setup_async_callback
+ *
+ * Set up an asynchronous callbacks of various kinds
+ *
+ * Input:
+ *	ia_handle		IA handle
+ *	handler_type		type of handler to set up
+ *	callback_handle		handle param for completion callbacks
+ *	callback		callback routine pointer
+ *	context			argument for callback routine
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INSUFFICIENT_RESOURCES
+ *	DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_setup_async_callback (
+        IN  DAPL_IA                     *ia_ptr,
+        IN  DAPL_ASYNC_HANDLER_TYPE     handler_type,
+        IN  DAPL_EVD                    *evd_ptr,
+        IN  ib_async_handler_t          callback,
+        IN  void                        *context )
+{
+    dapl_ibal_ca_t     *p_ca;
+    dapl_ibal_evd_cb_t *evd_cb;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_UTIL,
+                  " setup_async_cb: ia %p type %d hdl %p cb %p ctx %p\n",
+                  ia_ptr, handler_type, evd_ptr, callback, context);
+
+    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
+
+    if (p_ca == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsISAC: can't find %s HCA\n", 
+                       (ia_ptr->header.provider)->device_name);
+        return (DAT_INVALID_HANDLE);
+    }
+   
+    if (handler_type != DAPL_ASYNC_CQ_COMPLETION)
+    {
+        evd_cb = dapli_find_evd_cb_by_context (context, p_ca);
+           
+        if (evd_cb == NULL)
+        {
+            /* 
+             * No record for this evd. We allocate one
+             */
+            evd_cb = dapl_os_alloc (sizeof (dapl_ibal_evd_cb_t));
+            dapl_os_memzero (evd_cb, sizeof(dapl_ibal_evd_cb_t));
+
+            if (evd_cb == NULL)
+            {
+                dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                               "--> %s: can't alloc res\n","DsISAC"); 
+                return (DAT_INSUFFICIENT_RESOURCES);
+            }
+        
+            evd_cb->context          = context;
+        
+            /*
+             *  Add the new EVD CB to the list
+             */
+            LOCK_INSERT_TAIL( p_ca->evd_cb_lock, 
+                              p_ca->evd_cb_head,
+                              evd_cb->next );
+        }
+
+        switch (handler_type)
+        {
+            case DAPL_ASYNC_UNAFILIATED:
+                evd_cb->pfn_async_err_cb = callback;
+                break;
+            case DAPL_ASYNC_CQ_ERROR:
+                evd_cb->pfn_async_cq_err_cb = callback;
+                break;
+            case DAPL_ASYNC_QP_ERROR:
+                evd_cb->pfn_async_qp_err_cb = callback;
+                break;
+            default:
+                break;
+        }
+
+    }
+
+    return DAT_SUCCESS;
+}
+
+
+/*
+ * dapls_ib_query_gid
+ *
+ * Query the hca for the gid of the 1st active port.
+ *
+ * Input:
+ *	hca_handl		hca handle	
+ *	ep_attr			attribute of the ep
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INVALID_HANDLE
+ *	DAT_INVALID_PARAMETER
+ */
+
+DAT_RETURN
+dapls_ib_query_gid( IN  DAPL_HCA	*hca_ptr,
+		    IN  GID		*gid )
+{
+    dapl_ibal_ca_t    *p_ca;
+    ib_ca_attr_t      *p_hca_attr;
+    ib_api_status_t   ib_status;
+    ib_hca_port_t     port_num;
+
+    p_ca = (dapl_ibal_ca_t *) hca_ptr->ib_hca_handle;
+
+    if (p_ca == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+			"%s() invalid hca_ptr %p", __FUNCTION__, hca_ptr);
+        return DAT_INVALID_HANDLE;
+    }
+
+    ib_status = ib_query_ca (
+                          p_ca->h_ca,
+                          p_ca->p_ca_attr,
+                          &p_ca->ca_attr_size);
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "%s() ib_query_ca returned failed status = %s\n", 
+                       ib_get_err_str(ib_status));
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    p_hca_attr = p_ca->p_ca_attr;
+    port_num = hca_ptr->port_num - 1;
+
+    gid->gid_prefix = p_hca_attr->p_port_attr[port_num].p_gid_table->unicast.prefix;
+    gid->guid = p_hca_attr->p_port_attr[port_num].p_gid_table->unicast.interface_id;
+    return DAT_SUCCESS;
+}
+
+
+/*
+ * dapls_ib_query_hca
+ *
+ * Query the hca attribute
+ *
+ * Input:
+ *	hca_handl		hca handle	
+ *	ep_attr			attribute of the ep
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INVALID_PARAMETER
+ */
+
+DAT_RETURN dapls_ib_query_hca (
+	IN  DAPL_HCA                       *hca_ptr,
+        OUT DAT_IA_ATTR                    *ia_attr,
+        OUT DAT_EP_ATTR                    *ep_attr,
+	OUT DAT_SOCK_ADDR6                 *ip_addr)
+{
+    ib_ca_attr_t      *p_hca_attr;
+    dapl_ibal_ca_t    *p_ca;
+    ib_api_status_t   ib_status;
+    ib_hca_port_t     port_num;
+    GID gid;
+    DAT_SOCK_ADDR6	 *p_sock_addr;
+    DAT_RETURN dat_status = DAT_SUCCESS;
+    port_num = hca_ptr->port_num;
+
+    p_ca = (dapl_ibal_ca_t *) hca_ptr->ib_hca_handle;
+
+    if (p_ca == NULL)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,  "--> %s: invalid handle %p",
+                       "DsIQH", hca_ptr);
+        return (DAT_INVALID_HANDLE);
+    }
+
+    ib_status = ib_query_ca (
+                          p_ca->h_ca,
+                          p_ca->p_ca_attr,
+                          &p_ca->ca_attr_size);
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIQH: ib_query_ca returned failed status = %s\n", 
+                       ib_get_err_str(ib_status));
+        return (dapl_ib_status_convert (ib_status));
+    }
+
+    p_hca_attr = p_ca->p_ca_attr;
+
+    if (ip_addr != NULL)
+    {
+    	p_sock_addr = dapl_os_alloc(sizeof(DAT_SOCK_ADDR6));
+    	if ( !p_sock_addr )
+    	{
+    		dat_status = DAT_INSUFFICIENT_RESOURCES;
+    		dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                                       " Query Hca alloc Err: status %d\n",
+                                       dat_status);
+    		return dat_status;
+    	}
+    	dapl_os_memzero(p_sock_addr, sizeof(DAT_SOCK_ADDR6));
+
+    	gid.gid_prefix = p_hca_attr->p_port_attr[port_num-1].p_gid_table->unicast.prefix;
+    	gid.guid = p_hca_attr->p_port_attr[port_num-1].p_gid_table->unicast.interface_id;
+	
+    	dat_status = dapls_ns_map_ipaddr( hca_ptr,
+                                          gid,
+                                          (DAT_IA_ADDRESS_PTR)p_sock_addr);
+	
+    	if ( dat_status != DAT_SUCCESS )
+    	{
+            dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                          " SA Query for local IP failed= %d\n", dat_status );
+			/* what to do next ? */
+    	}
+    	else
+    	{
+    	    dapl_dbg_log (DAPL_DBG_TYPE_CM, "SA query GID for IP: ");
+            dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%0d:%d:%d:%d\n", 
+		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[2]&0xff,
+		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[3]&0xff,
+		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[4]&0xff,
+		(uint8_t)((DAT_IA_ADDRESS_PTR )p_sock_addr)->sa_data[5]&0xff);
+        }
+
+        hca_ptr->hca_address = *p_sock_addr;
+
+        /* if structure address not from our hca_ptr */
+        if ( ip_addr  != &hca_ptr->hca_address )
+        {
+            *ip_addr = *p_sock_addr;
+        }
+
+	dapl_os_free (p_sock_addr, sizeof(DAT_SOCK_ADDR6));
+
+    } /* ip_addr != NULL */
+
+    if ( ia_attr != NULL )
+    {
+        dapl_os_memzero( ia_attr->adapter_name,
+                         (int)sizeof(ia_attr->adapter_name ));
+        dapl_os_memcpy(ia_attr->adapter_name,
+                        DAT_ADAPTER_NAME, 
+                        min ( (int)dapl_os_strlen(DAT_ADAPTER_NAME),
+                              (int)(DAT_NAME_MAX_LENGTH)-1 ) );
+
+        dapl_os_memzero ( ia_attr->vendor_name,
+                          (int)sizeof(ia_attr->vendor_name) );
+        dapl_os_memcpy ( ia_attr->vendor_name, 
+                         DAT_VENDOR_NAME,
+                        min ( (int)dapl_os_strlen(DAT_VENDOR_NAME),
+                              (int)(DAT_NAME_MAX_LENGTH)-1 ) );
+        
+        /* FIXME : Vu
+         *         this value should be revisited
+         *         It can be set by DAT consumers
+         */
+        ia_attr->ia_address_ptr           = (DAT_PVOID)&hca_ptr->hca_address;
+        ia_attr->hardware_version_major   = p_hca_attr->dev_id;
+        ia_attr->hardware_version_minor   = p_hca_attr->revision;
+        ia_attr->max_eps                  = p_hca_attr->max_qps;
+        ia_attr->max_dto_per_ep           = p_hca_attr->max_wrs;
+        ia_attr->max_rdma_read_per_ep     = p_hca_attr->max_qp_resp_res;
+        ia_attr->max_evds                 = p_hca_attr->max_cqs;
+        ia_attr->max_evd_qlen             = p_hca_attr->max_cqes;
+        ia_attr->max_iov_segments_per_dto = p_hca_attr->max_sges;
+        ia_attr->max_lmrs                 = p_hca_attr->init_regions;
+        ia_attr->max_lmr_block_size       = p_hca_attr->init_region_size;
+        ia_attr->max_rmrs                 = p_hca_attr->init_windows;
+        ia_attr->max_lmr_virtual_address  = p_hca_attr->max_addr_handles;
+        ia_attr->max_rmr_target_address   = p_hca_attr->max_addr_handles;
+        ia_attr->max_pzs                  = p_hca_attr->max_pds;
+        /*
+         * DAT spec does not tie max_mtu_size with IB MTU
+         *
+        ia_attr->max_mtu_size             = 
+                        dapl_ibal_mtu_table[p_hca_attr->p_port_attr->mtu];
+        */
+        ia_attr->max_mtu_size             = 
+                        p_hca_attr->p_port_attr->max_msg_size;
+        ia_attr->max_rdma_size            = 
+                        p_hca_attr->p_port_attr->max_msg_size;
+        ia_attr->num_transport_attr       = 0;
+        ia_attr->transport_attr           = NULL;
+        ia_attr->num_vendor_attr          = 0;
+        ia_attr->vendor_attr              = NULL;
+        ia_attr->max_iov_segments_per_rdma_read = p_hca_attr->max_sges;
+
+#ifdef DAT_EXTENSIONS
+        ia_attr->extension_supported = DAT_EXTENSION_IB;
+        ia_attr->extension_version = DAT_IB_EXTENSION_VERSION;
+#endif
+	
+	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
+		" --> DsIMU_qHCA: (ver=%x) ep %d ep_q %d evd %d evd_q %d\n", 
+			ia_attr->hardware_version_major,
+			ia_attr->max_eps, ia_attr->max_dto_per_ep,
+			ia_attr->max_evds, ia_attr->max_evd_qlen );
+	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
+		" --> DsIMU_qHCA: mtu %llu rdma %llu iov %d lmr %d rmr %d"
+		" rdma_io %d\n", 
+			ia_attr->max_mtu_size, ia_attr->max_rdma_size,
+			ia_attr->max_iov_segments_per_dto, ia_attr->max_lmrs, 
+			ia_attr->max_rmrs, ia_attr->max_rdma_read_per_ep );
+    }
+
+    if ( ep_attr != NULL )
+    {
+       (void) dapl_os_memzero(ep_attr, sizeof(*ep_attr)); 
+        /*
+         * DAT spec does not tie max_mtu_size with IB MTU
+         *
+        ep_attr->max_mtu_size     = 
+                        dapl_ibal_mtu_table[p_hca_attr->p_port_attr->mtu];
+         */
+        ep_attr->max_mtu_size     = p_hca_attr->p_port_attr->max_msg_size;
+        ep_attr->max_rdma_size    = p_hca_attr->p_port_attr->max_msg_size;
+        ep_attr->max_recv_dtos    = p_hca_attr->max_wrs;
+        ep_attr->max_request_dtos = p_hca_attr->max_wrs;
+        ep_attr->max_recv_iov     = p_hca_attr->max_sges;
+        ep_attr->max_request_iov  = p_hca_attr->max_sges;
+        ep_attr->max_rdma_read_in = p_hca_attr->max_qp_resp_res;
+        ep_attr->max_rdma_read_out= p_hca_attr->max_qp_resp_res;
+	
+	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, 
+		" --> DsIMU_qHCA: msg %llu dto %d iov %d rdma i%d,o%d\n", 
+			ep_attr->max_mtu_size,
+			ep_attr->max_recv_dtos, ep_attr->max_recv_iov,
+			ep_attr->max_rdma_read_in, ep_attr->max_rdma_read_out);
+    }
+	return DAT_SUCCESS;
+}
+
+
+DAT_RETURN
+dapls_ib_completion_poll ( IN DAPL_HCA                *p_hca,
+                           IN DAPL_EVD                *p_evd,
+                           IN ib_work_completion_t   *cqe_ptr )
+{
+    ib_api_status_t        ib_status;
+    ib_work_completion_t   *cqe_filled;
+
+    /*
+     * FIXME - Vu
+     *     Now we only poll for one cqe. We can poll for more than
+     *     one completions later for better. However, this requires
+     *     to change the logic in dapl_evd_dto_callback function
+     *     to process more than one completion.
+     */
+    cqe_ptr->p_next = NULL;
+    cqe_filled      = NULL;
+
+    if  ( !p_hca->ib_hca_handle )
+    {
+        return DAT_INVALID_HANDLE;
+    }
+
+    ib_status = ib_poll_cq (p_evd->ib_cq_handle, &cqe_ptr, &cqe_filled);
+
+    if ( ib_status == IB_INVALID_CQ_HANDLE )
+    {
+        ib_status = IB_NOT_FOUND;
+    }
+
+    return dapl_ib_status_convert (ib_status);
+}
+
+
+DAT_RETURN
+dapls_ib_completion_notify ( IN ib_hca_handle_t         hca_handle,
+                             IN DAPL_EVD                *p_evd,
+                             IN ib_notification_type_t  type )
+{
+    ib_api_status_t        ib_status;
+    DAT_BOOLEAN            solic_notify;
+
+    if  ( !hca_handle )
+    {
+        return DAT_INVALID_HANDLE;
+    }
+    solic_notify = (type == IB_NOTIFY_ON_SOLIC_COMP) ? DAT_TRUE : DAT_FALSE; 
+    ib_status = ib_rearm_cq ( p_evd->ib_cq_handle, solic_notify );
+
+    return dapl_ib_status_convert (ib_status);
+}
+
+DAT_RETURN
+dapls_evd_dto_wakeup (
+	IN DAPL_EVD			*evd_ptr)
+{
+	return dapl_os_wait_object_wakeup(&evd_ptr->wait_object);
+}
+
+DAT_RETURN
+dapls_evd_dto_wait (
+	IN DAPL_EVD			*evd_ptr,
+	IN uint32_t 			timeout)
+{
+	return dapl_os_wait_object_wait(&evd_ptr->wait_object, timeout);
+}
+
+/*
+ * dapls_ib_get_async_event
+ *
+ * Translate an asynchronous event type to the DAT event.
+ * Note that different providers have different sets of errors.
+ *
+ * Input:
+ *	cause_ptr		provider event cause
+ *
+ * Output:
+ * 	async_event		DAT mapping of error
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_NOT_IMPLEMENTED	Caller is not interested this event
+ */
+
+DAT_RETURN dapls_ib_get_async_event(
+	IN  ib_async_event_rec_t	*cause_ptr,
+	OUT DAT_EVENT_NUMBER		*async_event)
+{
+    ib_async_event_t		event_id;
+    DAT_RETURN			dat_status;
+
+    dat_status = DAT_SUCCESS;
+    event_id = cause_ptr->code;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_WARN, "--> DsAE: event_id = %d%d\n", event_id);
+
+    switch (event_id )
+    {
+        case IB_AE_SQ_ERROR:
+        case IB_AE_SQ_DRAINED:
+        case IB_AE_RQ_ERROR:
+	{
+	    *async_event = DAT_ASYNC_ERROR_EP_BROKEN;
+	    break;
+	}
+
+	/* INTERNAL errors */
+        case IB_AE_QP_FATAL:
+	case IB_AE_CQ_ERROR:
+	case IB_AE_LOCAL_FATAL:
+	case IB_AE_WQ_REQ_ERROR:
+	case IB_AE_WQ_ACCESS_ERROR:
+	{
+	    *async_event = DAT_ASYNC_ERROR_PROVIDER_INTERNAL_ERROR;
+	    break;
+	}
+
+	/* CATASTROPHIC errors */
+	case IB_AE_FLOW_CTRL_ERROR:
+	case IB_AE_BUF_OVERRUN:
+	{
+	    *async_event = DAT_ASYNC_ERROR_IA_CATASTROPHIC;
+	    break;
+	}
+
+	default:
+	{
+	    /*
+	     * Errors we are not interested in reporting:
+	     * IB_AE_QP_APM
+	     * IB_AE_PKEY_TRAP
+	     * IB_AE_QKEY_TRAP
+	     * IB_AE_MKEY_TRAP
+	     * IB_AE_PORT_TRAP
+	     * IB_AE_QP_APM_ERROR
+	     * IB_AE_PORT_ACTIVE
+	     * ...
+	     */
+	    dat_status = DAT_NOT_IMPLEMENTED;
+	}
+
+    }
+  
+    return dat_status;
+}
+
+/*
+ * dapls_ib_get_dto_status
+ *
+ * Return the DAT status of a DTO operation
+ *
+ * Input:
+ *	cqe_ptr			pointer to completion queue entry
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	Value from ib_status_map table above
+ */
+
+DAT_DTO_COMPLETION_STATUS
+dapls_ib_get_dto_status(
+	IN ib_work_completion_t		*cqe_ptr)
+{
+    ib_uint32_t    ib_status;
+
+    ib_status = DAPL_GET_CQE_STATUS (cqe_ptr);
+
+    switch (ib_status)
+    {
+    case IB_COMP_ST_SUCCESS :
+	return	DAT_DTO_SUCCESS;
+
+    case IB_COMP_ST_LOCAL_LEN_ERR:
+	return DAT_DTO_ERR_LOCAL_LENGTH;
+
+    case IB_COMP_ST_LOCAL_OP_ERR:
+	return DAT_DTO_ERR_LOCAL_EP;
+
+    case IB_COMP_ST_LOCAL_PROTECT_ERR:
+	return DAT_DTO_ERR_LOCAL_PROTECTION;
+
+    case IB_COMP_ST_WR_FLUSHED_ERR:	
+	return DAT_DTO_ERR_FLUSHED;
+
+    case IB_COMP_ST_MW_BIND_ERR:
+	return DAT_RMR_OPERATION_FAILED;
+
+    case IB_COMP_ST_REM_ACC_ERR:
+	return DAT_DTO_ERR_REMOTE_ACCESS;
+
+    case IB_COMP_ST_REM_OP_ERR:
+	return DAT_DTO_ERR_REMOTE_RESPONDER;
+
+    case IB_COMP_ST_RNR_COUNTER:
+	return DAT_DTO_ERR_RECEIVER_NOT_READY;
+
+    case IB_COMP_ST_TRANSP_COUNTER:
+	return DAT_DTO_ERR_TRANSPORT;
+
+    case IB_COMP_ST_REM_REQ_ERR:
+	return DAT_DTO_ERR_REMOTE_RESPONDER;
+
+    case IB_COMP_ST_BAD_RESPONSE_ERR:
+	return DAT_DTO_ERR_BAD_RESPONSE;
+
+    case IB_COMP_ST_EE_STATE_ERR:
+    case IB_COMP_ST_EE_CTX_NO_ERR:
+    	return DAT_DTO_ERR_TRANSPORT;
+
+    default:
+#ifdef DAPL_DBG
+    dapl_dbg_log (DAPL_DBG_TYPE_ERR,"%s() unknown IB_COMP_ST %d(0x%x)\n",
+                  __FUNCTION__,ib_status,ib_status);
+#endif
+	return DAT_DTO_FAILURE;
+    }
+}
+
+
+/*
+ * Map all IBAPI DTO completion codes to the DAT equivelent.
+ *
+ * dapls_ib_get_dat_event
+ *
+ * Return a DAT connection event given a provider CM event.
+ *
+ * N.B.	Some architectures combine async and CM events into a
+ *	generic async event. In that case, dapls_ib_get_dat_event()
+ *	and dapls_ib_get_async_event() should be entry points that
+ *	call into a common routine.
+ *
+ * Input:
+ *	ib_cm_event	event provided to the dapl callback routine
+ *	active		switch indicating active or passive connection
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	DAT_EVENT_NUMBER of translated provider value
+ */
+
+DAT_EVENT_NUMBER
+dapls_ib_get_dat_event (
+	IN    const ib_cm_events_t	ib_cm_event,
+	IN    DAT_BOOLEAN		active)
+{
+    DAT_EVENT_NUMBER		dat_event_num = 0;
+    UNREFERENCED_PARAMETER (active);
+
+    switch ( ib_cm_event)
+    {
+      case IB_CME_CONNECTED:
+          dat_event_num = DAT_CONNECTION_EVENT_ESTABLISHED;
+          break;
+      case IB_CME_DISCONNECTED:
+           dat_event_num = DAT_CONNECTION_EVENT_DISCONNECTED;
+           break;
+      case IB_CME_DISCONNECTED_ON_LINK_DOWN:
+           dat_event_num = DAT_CONNECTION_EVENT_DISCONNECTED;
+           break;
+      case IB_CME_CONNECTION_REQUEST_PENDING:
+           dat_event_num = DAT_CONNECTION_REQUEST_EVENT;
+           break;
+      case IB_CME_CONNECTION_REQUEST_PENDING_PRIVATE_DATA:
+           dat_event_num = DAT_CONNECTION_REQUEST_EVENT;
+           break;
+      case IB_CME_DESTINATION_REJECT:
+           dat_event_num = DAT_CONNECTION_EVENT_NON_PEER_REJECTED;
+           break;
+      case IB_CME_DESTINATION_REJECT_PRIVATE_DATA:
+           dat_event_num = DAT_CONNECTION_EVENT_PEER_REJECTED;
+           break;
+      case IB_CME_DESTINATION_UNREACHABLE:
+           dat_event_num = DAT_CONNECTION_EVENT_UNREACHABLE;
+           break;
+      case IB_CME_TOO_MANY_CONNECTION_REQUESTS:
+           dat_event_num = DAT_CONNECTION_EVENT_NON_PEER_REJECTED;
+           break;
+      case IB_CME_LOCAL_FAILURE:
+      	   dat_event_num = DAT_CONNECTION_EVENT_BROKEN;
+           break;
+      case IB_CME_REPLY_RECEIVED:
+      case IB_CME_REPLY_RECEIVED_PRIVATE_DATA:
+      default:
+           break;
+    }
+#if 0
+    dapl_dbg_log (DAPL_DBG_TYPE_CM,
+		  " dapls_ib_get_dat_event: event translation: (%s) "
+		  "ib_event 0x%x dat_event 0x%x\n",
+		  active ? "active" : "passive",
+		  ib_cm_event,
+		  dat_event_num);
+#endif
+    return dat_event_num;
+}
+
+
+/*
+ * dapls_ib_get_dat_event
+ *
+ * Return a DAT connection event given a provider CM event.
+ *
+ * N.B.	Some architectures combine async and CM events into a
+ *	generic async event. In that case, dapls_ib_get_cm_event()
+ *	and dapls_ib_get_async_event() should be entry points that
+ *	call into a common routine.
+ *
+ *	WARNING: In this implementation, there are multiple CM
+ *	events that map to a single DAT event. Be very careful
+ *	with provider routines that depend on this reverse mapping,
+ *	they may have to accomodate more CM events than they
+ *	'naturally' would.
+ *
+ * Input:
+ *	dat_event_num	DAT event we need an equivelent CM event for
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	ib_cm_event of translated DAPL value
+ */
+ib_cm_events_t
+dapls_ib_get_cm_event (
+	IN    DAT_EVENT_NUMBER		dat_event_num)
+{
+    ib_cm_events_t	ib_cm_event = 0;
+
+    switch (dat_event_num)
+    {
+        case DAT_CONNECTION_EVENT_ESTABLISHED:
+             ib_cm_event = IB_CME_CONNECTED;
+             break;
+        case DAT_CONNECTION_EVENT_DISCONNECTED:
+             ib_cm_event = IB_CME_DISCONNECTED;
+             break;
+        case DAT_CONNECTION_REQUEST_EVENT:
+             ib_cm_event =  IB_CME_CONNECTION_REQUEST_PENDING;
+             break;
+        case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:
+             ib_cm_event = IB_CME_DESTINATION_REJECT;
+             break;
+        case DAT_CONNECTION_EVENT_PEER_REJECTED:
+             ib_cm_event = IB_CME_DESTINATION_REJECT_PRIVATE_DATA;
+             break;
+        case DAT_CONNECTION_EVENT_UNREACHABLE:
+             ib_cm_event = IB_CME_DESTINATION_UNREACHABLE;
+             break;
+        case DAT_CONNECTION_EVENT_BROKEN:
+             ib_cm_event = IB_CME_LOCAL_FAILURE;
+             break;
+        default:
+             break;
+    }
+
+    return ib_cm_event;
+}
+
+
+
+/*
+ * dapls_set_provider_specific_attr
+ *
+ * Input:
+ *	attr_ptr	Pointer provider specific attributes
+ *
+ * Output:
+ * 	none
+ *
+ * Returns:
+ * 	void
+ */
+
+#ifdef DAT_EXTENSIONS
+static DAT_NAMED_ATTR	ib_attrs[] = {
+    {
+    	"DAT_EXTENSION_INTERFACE", "TRUE"
+    },
+    {
+    	DAT_IB_ATTR_FETCH_AND_ADD, "TRUE"
+    },
+    {
+    	DAT_IB_ATTR_CMP_AND_SWAP, "TRUE"
+    },
+    {
+    	DAT_IB_ATTR_IMMED_DATA, "TRUE"
+    },
+};
+#define SPEC_ATTR_SIZE( x )	(sizeof( x ) / sizeof( DAT_NAMED_ATTR))
+#else
+static DAT_NAMED_ATTR	*ib_attrs = NULL;
+#define SPEC_ATTR_SIZE( x )	0
+#endif
+
+void dapls_query_provider_specific_attr(
+	IN	DAPL_IA				*ia_ptr,
+	IN	DAT_PROVIDER_ATTR	*attr_ptr )
+{
+    attr_ptr->num_provider_specific_attr = SPEC_ATTR_SIZE(ib_attrs);
+    attr_ptr->provider_specific_attr     = ib_attrs;
+}
+
+
+DAT_RETURN dapls_ns_map_gid (
+	IN  DAPL_HCA		*hca_ptr,
+	IN  DAT_IA_ADDRESS_PTR	remote_ia_address,
+	OUT GID			*gid)
+{
+    return (dapls_ib_ns_map_gid (hca_ptr, remote_ia_address, gid));
+}
+
+DAT_RETURN dapls_ns_map_ipaddr (
+	IN  DAPL_HCA		*hca_ptr,
+	IN  GID			gid,
+	OUT DAT_IA_ADDRESS_PTR	remote_ia_address)
+{
+    return (dapls_ib_ns_map_ipaddr (hca_ptr, gid, remote_ia_address));
+}
+
+
+#ifdef NOT_USED
+/*
+ * dapls_ib_post_recv - defered.until QP ! in init state.
+ *
+ * Provider specific Post RECV function
+ */
+
+DAT_RETURN 
+dapls_ib_post_recv_defered (
+	IN  DAPL_EP		   	*ep_ptr,
+	IN  DAPL_COOKIE			*cookie,
+	IN  DAT_COUNT	   		num_segments,
+	IN  DAT_LMR_TRIPLET	   	*local_iov)
+{
+    ib_api_status_t     ib_status;
+    ib_recv_wr_t	*recv_wr, *rwr;
+    ib_local_ds_t       *ds_array_p;
+    DAT_COUNT           i, total_len;
+
+    if (ep_ptr->qp_state != IB_QPS_INIT)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsPR: BAD QP state(%s), not init? "
+                      "EP %p QP %p cookie %p, num_seg %d\n", 
+                      ib_get_port_state_str(ep_ptr->qp_state), ep_ptr,
+                      ep_ptr->qp_handle, cookie, num_segments);
+	return (DAT_INSUFFICIENT_RESOURCES);
+    }
+
+    recv_wr = dapl_os_alloc (sizeof(ib_recv_wr_t)
+                             + (num_segments*sizeof(ib_local_ds_t)));
+    if (NULL == recv_wr)
+    {
+	return (DAT_INSUFFICIENT_RESOURCES);
+    }
+
+    dapl_os_memzero(recv_wr, sizeof(ib_recv_wr_t));
+    recv_wr->wr_id        = (DAT_UINT64) cookie;
+    recv_wr->num_ds       = num_segments;
+
+    ds_array_p = (ib_local_ds_t*)(recv_wr+1);
+
+    recv_wr->ds_array     = ds_array_p;
+
+    //total_len = 0;
+
+    for (total_len = i = 0; i < num_segments; i++, ds_array_p++)
+    {
+        ds_array_p->length = (uint32_t)local_iov[i].segment_length;
+        ds_array_p->lkey  = cl_hton32(local_iov[i].lmr_context);
+        ds_array_p->vaddr = local_iov[i].virtual_address;
+        total_len        += ds_array_p->length;
+    }
+
+    if (cookie != NULL)
+    {
+	cookie->val.dto.size = total_len;
+
+        dapl_dbg_log (DAPL_DBG_TYPE_EP,
+                      "--> DsPR: EP = %p QP = %p cookie= %p, num_seg= %d\n", 
+                      ep_ptr, ep_ptr->qp_handle, cookie, num_segments);
+    }
+
+    recv_wr->p_next = NULL;
+
+    /* find last defered recv work request, link new on the end */
+    rwr=ep_ptr->cm_post;
+    if (rwr == NULL)
+    {
+        ep_ptr->cm_post = (void*)recv_wr;
+        i = 1;
+    }
+    else
+    {
+        for(i=2; rwr->p_next; rwr=rwr->p_next) i++;
+        rwr->p_next = recv_wr;
+    }
+
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsPR: %s() EP %p QP %p cookie %p "
+                  "num_seg %d Tdefered %d\n", 
+                  __FUNCTION__, ep_ptr, ep_ptr->qp_handle, cookie, num_segments,
+                  i);
+
+    return DAT_SUCCESS;
+}
+#endif
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 8
+ * End:
+ */
+
Index: ulp/dapl2/dapl/ibal/dapl_ibal_cm.c
===================================================================
--- ulp/dapl2/dapl/ibal/dapl_ibal_cm.c	(revision 3414)
+++ ulp/dapl2/dapl/ibal/dapl_ibal_cm.c	(working copy)
@@ -1,1821 +1,1821 @@
-
-/*
- * Copyright (c) 2005-2007 Intel Corporation. All rights reserved.
- * Copyright (c) 2002, Network Appliance, Inc. All rights reserved. 
- * 
- * This Software is licensed under the terms of the "Common Public
- * License" a copy of which is in the file LICENSE.txt in the root
- * directory. The license is also available from the Open Source
- * Initiative, see http://www.opensource.org/licenses/cpl.php.
- *
- */
-
-/**********************************************************************
- * 
- * MODULE: dapl_ibal_cm.c
- *
- * PURPOSE: IB Connection routines for access to IBAL APIs
- *
- **********************************************************************/
-
-#include "dapl.h"
-#include "dapl_adapter_util.h"
-#include "dapl_evd_util.h"
-#include "dapl_cr_util.h"
-#include "dapl_sp_util.h"
-#include "dapl_ep_util.h"
-#include "dapl_ia_util.h"
-#include "dapl_ibal_util.h"
-#include "dapl_name_service.h"
-#include "dapl_ibal_name_service.h"
-#include "dapl_cookie.h"
-
-#define IB_INFINITE_SERVICE_LEASE   0xFFFFFFFF
-#define  DAPL_ATS_SERVICE_ID        ATS_SERVICE_ID //0x10000CE100415453
-#define  DAPL_ATS_NAME              ATS_NAME
-#define  HCA_IPV6_ADDRESS_LENGTH    16
-
-/* until dapl_ibal_util.h define of IB_INVALID_HANDLE which overlaps the
- * Windows ib_types.h typedef enu ib_api_status_t IB_INVALID_HANDLE is fixed.
- */
-#undef IB_INVALID_HANDLE
-#define DAPL_IB_INVALID_HANDLE NULL
-
-int g_dapl_loopback_connection = 0;
-extern dapl_ibal_root_t        dapl_ibal_root;
-
-static void dapli_ib_cm_drep_cb (
-	IN    ib_cm_drep_rec_t          *p_cm_drep_rec );
-
-/*
- * Prototypes
- */
-
-char *
-dapli_ib_cm_event_str(ib_cm_events_t e)
-{
-#ifdef DBG
-    char        *cp;
-    static char *event_str[13] = {
-        "IB_CME_CONNECTED",
-        "IB_CME_DISCONNECTED",
-        "IB_CME_DISCONNECTED_ON_LINK_DOWN",
-        "IB_CME_CONNECTION_REQUEST_PENDING",
-        "IB_CME_CONNECTION_REQUEST_PENDING_PRIVATE_DATA",
-        "IB_CME_DESTINATION_REJECT",
-        "IB_CME_DESTINATION_REJECT_PRIVATE_DATA",
-        "IB_CME_DESTINATION_UNREACHABLE",
-        "IB_CME_TOO_MANY_CONNECTION_REQUESTS",
-        "IB_CME_LOCAL_FAILURE",
-        "IB_CME_REPLY_RECEIVED",
-        "IB_CME_REPLY_RECEIVED_PRIVATE_DATA",
-        "IB_CM_LOCAL_FAILURE"
-    };
-
-    if (e > IB_CM_LOCAL_FAILURE || e < IB_CME_CONNECTED)
-	cp =  "BAD EVENT";
-    else
-        cp = event_str[e];
-
-    return cp;
-#else
-    static char num[8];
-    sprintf(num,"%d",e);
-    return num;
-#endif
-}
-
-
-#if defined(DAPL_DBG)
-
-void dapli_print_private_data( char *prefix, const uint8_t *pd, int len )
-{
-    int i;
-            
-    if ( !pd || len <= 0 )
-	return;
-
-    dapl_log ( DAPL_DBG_TYPE_CM, "--> %s: private_data(len %d)\n    ",prefix,len);
-
-    if (len > IB_MAX_REP_PDATA_SIZE)
-    {
-    	dapl_log ( DAPL_DBG_TYPE_ERR,
-		"    Private data size(%d) > Max(%d), ignored.\n    ",
-					len,DAPL_MAX_PRIVATE_DATA_SIZE);
-	len = IB_MAX_REP_PDATA_SIZE;
-    }
-
-    for ( i = 0 ; i < len; i++ )
-    {
-	dapl_log ( DAPL_DBG_TYPE_CM, "%2x ", pd[i]);
-	if ( ((i+1) % 5) == 0 ) 
-	    dapl_log ( DAPL_DBG_TYPE_CM, "\n    ");
-    }
-   dapl_log ( DAPL_DBG_TYPE_CM, "\n");
-}
-#endif
-
-/* EP-CM linking support */
-dp_ib_cm_handle_t ibal_cm_alloc(void)
-{
-	dp_ib_cm_handle_t cm_ptr;
-
-	/* Allocate CM, init lock, and initialize */
-	if ((cm_ptr = dapl_os_alloc(sizeof(*cm_ptr))) == NULL)
-		return NULL;
-
-	(void)dapl_os_memzero(cm_ptr, sizeof(*cm_ptr));
-	cm_ptr->ref_count = 1;
-
-	if (dapl_os_lock_init(&cm_ptr->lock)) {
-		dapl_os_free(cm_ptr, sizeof(*cm_ptr));
-		return NULL;
-	}
-
-	dapl_llist_init_entry((DAPL_LLIST_ENTRY *)&cm_ptr->list_entry);
-	
-	return cm_ptr;
-}
-
-/* free CM object resources */
-static void ibal_cm_dealloc(dp_ib_cm_handle_t cm_ptr) 
-{
-	dapl_os_assert(!cm_ptr->ref_count);
-	dapl_os_lock_destroy(&cm_ptr->lock);
-	dapl_os_free(cm_ptr, sizeof(*cm_ptr));
-}
-
-void dapls_cm_acquire(dp_ib_cm_handle_t cm_ptr)
-{
-	dapl_os_lock(&cm_ptr->lock);
-	cm_ptr->ref_count++;
-	dapl_os_unlock(&cm_ptr->lock);
-}
-
-void dapls_cm_release(dp_ib_cm_handle_t cm_ptr)
-{
-	dapl_os_lock(&cm_ptr->lock);
-	cm_ptr->ref_count--;
-	if (cm_ptr->ref_count) {
-                dapl_os_unlock(&cm_ptr->lock);
-		return;
-	}
-	dapl_os_unlock(&cm_ptr->lock);
-	ibal_cm_dealloc(cm_ptr);
-}
-
-/* blocking: called from user thread dapl_ep_free() only */
-void dapls_cm_free(dp_ib_cm_handle_t cm_ptr)
-{
-	dapl_ep_unlink_cm(cm_ptr->ep, cm_ptr);
-
-	/* final reference, alloc */
-	dapls_cm_release(cm_ptr);
-}
-
-static void 
-dapli_ib_cm_apr_cb (
-        IN    ib_cm_apr_rec_t          *p_cm_apr_rec )
-{
-    UNUSED_PARAM( p_cm_apr_rec );
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> DiCAcb: CM callback APR (Alternate Path Request)\n");
-}
-
-static void 
-dapli_ib_cm_lap_cb (
-        IN    ib_cm_lap_rec_t          *p_cm_lap_rec )
-{
-    UNUSED_PARAM( p_cm_lap_rec );
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> DiCLcb: CM callback LAP (Load Alternate Path)\n");
-}
-
-static DAT_RETURN dapli_send_ib_cm_dreq(ib_cm_handle_t h_cm)
-{
-	ib_cm_dreq_t cm_dreq;
-
-	dapl_os_memzero(&cm_dreq, sizeof(ib_cm_dreq_t));
-
-	cm_dreq.flags = IB_FLAGS_SYNC;
-	cm_dreq.qp_type = IB_QPT_RELIABLE_CONN;
-	cm_dreq.h_qp = h_cm.h_qp;
-	cm_dreq.pfn_cm_drep_cb = dapli_ib_cm_drep_cb;
-
-	return dapl_ib_status_convert(ib_cm_dreq(&cm_dreq));
-}
-
-static DAT_RETURN dapli_send_ib_cm_drep(ib_cm_handle_t h_cm)
-{
-    ib_cm_drep_t cm_drep;
-
-    dapl_os_memzero(&cm_drep, sizeof(ib_cm_drep_t));
-	return dapl_ib_status_convert(ib_cm_drep(h_cm, &cm_drep));
-}
-
-/*
- * Connection Disconnect Request callback
- * We received a DREQ, return a DREP (disconnect reply).
- */
-
-static void 
-dapli_ib_cm_dreq_cb (
-        IN    ib_cm_dreq_rec_t          *p_cm_dreq_rec )
-{
-    DAPL_EP             *ep_ptr;
-    dp_ib_cm_handle_t	cm_ptr;
-    
-    dapl_os_assert (p_cm_dreq_rec);
-
-    ep_ptr  = (DAPL_EP * __ptr64) p_cm_dreq_rec->qp_context;
-    if ( DAPL_BAD_PTR(ep_ptr) )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
-                      "--> %s: BAD_PTR EP %lx\n", __FUNCTION__, ep_ptr);
-        goto send_drep;
-    }
-    if ( ep_ptr->header.magic != DAPL_MAGIC_EP  )
-    {
-        if ( ep_ptr->header.magic == DAPL_MAGIC_INVALID )
-            goto send_drep;
-
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> %s: EP %p BAD_EP_MAGIC %x != wanted %x\n",
-		       __FUNCTION__, ep_ptr, ep_ptr->header.magic,
-		       DAPL_MAGIC_EP );
-        goto send_drep;
-    }
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-        goto send_drep;
-    }
-    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_dreq_rec->h_cm_dreq.h_qp);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> %s() EP %p, %s\n",
-                  __FUNCTION__,ep_ptr,
-                  dapl_get_ep_state_str(ep_ptr->param.ep_state));
-
-    dapl_os_lock (&ep_ptr->header.lock);
-    if ( ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                      "--> DiCDcb: EP %lx QP %lx already Disconnected\n",
-                      ep_ptr, ep_ptr->qp_handle);
-        goto unlock;
-    }
-
-    ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;
-
-    if (cm_ptr->state == IBAL_CM_CONNECT)
-    {
-	    cm_ptr->state = IBAL_CM_DREQ;
-	    cm_ptr->ib_cm = p_cm_dreq_rec->h_cm_dreq;
-    }
-    else
-    {
-	    dapli_send_ib_cm_drep(p_cm_dreq_rec->h_cm_dreq);
-    }
-    dapl_os_unlock (&ep_ptr->header.lock);
-
-    if (ep_ptr->cr_ptr)
-    {
-        /* passive side */
-        dapls_cr_callback ( cm_ptr,
-                            IB_CME_DISCONNECTED,
-                            (void * __ptr64) p_cm_dreq_rec->p_dreq_pdata,
-							IB_DREQ_PDATA_SIZE,
-                            (void *) (((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr) );
-    }
-    else
-    {
-        /* active side */
-        dapl_evd_connection_callback (
-                                  cm_ptr,
-                                  IB_CME_DISCONNECTED,
-                                  (void * __ptr64)
-                                  p_cm_dreq_rec->p_dreq_pdata,
-								  IB_DREQ_PDATA_SIZE,
-                                  p_cm_dreq_rec->qp_context );
-    }
-    return;
-
-unlock:
-	dapl_os_unlock (&ep_ptr->header.lock);
-send_drep:
-    dapli_send_ib_cm_drep(p_cm_dreq_rec->h_cm_dreq);
-}
-
-/*
- * Connection Disconnect Reply callback
- * We sent a DREQ and received a DREP.
- */
-
-static void 
-dapli_ib_cm_drep_cb (
-        IN    ib_cm_drep_rec_t          *p_cm_drep_rec )
-{
-    DAPL_EP            *ep_ptr;
-    dp_ib_cm_handle_t	cm_ptr;
-    
-    dapl_os_assert (p_cm_drep_rec != NULL);
-
-    ep_ptr  = (DAPL_EP * __ptr64) p_cm_drep_rec->qp_context;
-
-    if (p_cm_drep_rec->cm_status)
-    {
-         dapl_dbg_log (DAPL_DBG_TYPE_CM,
-                  "--> %s: DREP cm_status(%s) EP=%p\n", __FUNCTION__,
-                  ib_get_err_str(p_cm_drep_rec->cm_status), ep_ptr); 
-    }
-
-    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
-    {
-         dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                  "--> %s: BAD EP Handle EP=%lx\n", __FUNCTION__,ep_ptr); 
-        return;
-    }
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-        return;
-    }
-    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_drep_rec->h_qp);
-    
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-		"--> DiCDpcb: EP %p state %s cm_hdl %p\n",ep_ptr,
-		dapl_get_ep_state_str(ep_ptr->param.ep_state), cm_ptr);
-
-    if ( ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
-                      "--> DiCDpcb: EP %lx QP %lx already Disconnected\n",
-                      ep_ptr, ep_ptr->qp_handle);
-        return;
-    }
-
-    if (ep_ptr->cr_ptr)
-    {
-        /* passive connection side */
-        dapls_cr_callback ( cm_ptr,
-                            IB_CME_DISCONNECTED,
-                           (void * __ptr64) p_cm_drep_rec->p_drep_pdata,
-						   IB_DREP_PDATA_SIZE,
-                           (void *) (((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr) );
-    }
-    else
-    {
-        /* active connection side */
-        dapl_evd_connection_callback (
-                                   cm_ptr,
-                                   IB_CME_DISCONNECTED,
-                                   (void * __ptr64) p_cm_drep_rec->p_drep_pdata,
-								   IB_DREP_PDATA_SIZE,
-                                   p_cm_drep_rec->qp_context );
-    }
-}
-
-/*
- * CM reply callback
- */
-
-static void 
-dapli_ib_cm_rep_cb (
-        IN    ib_cm_rep_rec_t          *p_cm_rep_rec )
-{
-    ib_api_status_t     ib_status; 
-    ib_cm_rtu_t         cm_rtu;
-    uint8_t             cm_cb_op;
-    DAPL_PRIVATE        *prd_ptr;
-    DAPL_EP             *ep_ptr;
-    dapl_ibal_ca_t      *p_ca;
-    dp_ib_cm_handle_t	cm_ptr;
-        
-    dapl_os_assert (p_cm_rep_rec != NULL);
-
-    ep_ptr  = (DAPL_EP * __ptr64) p_cm_rep_rec->qp_context;
-
-    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
-                      __FUNCTION__, ep_ptr);
-        return;
-    }
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-        return;
-    }
-    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rep_rec->h_cm_rep.h_qp);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> DiCRpcb: EP %lx local_max_rdma_read_in %d\n", 
-                  ep_ptr, p_cm_rep_rec->resp_res);
-
-    p_ca   = (dapl_ibal_ca_t *) 
-             ep_ptr->header.owner_ia->hca_ptr->ib_hca_handle;
-
-    dapl_os_memzero (&cm_rtu, sizeof ( ib_cm_rtu_t ));
-    cm_rtu.pfn_cm_apr_cb  = dapli_ib_cm_apr_cb;
-    cm_rtu.pfn_cm_dreq_cb = dapli_ib_cm_dreq_cb;
-    cm_rtu.p_rtu_pdata    = NULL;
-    cm_rtu.access_ctrl = 
-		IB_AC_LOCAL_WRITE|IB_AC_RDMA_WRITE|IB_AC_MW_BIND|IB_AC_ATOMIC;
-    if ((ep_ptr->param.ep_attr.max_rdma_read_in > 0) || 
-		(ep_ptr->param.ep_attr.max_rdma_read_out > 0))
-    {
-    	cm_rtu.access_ctrl |= IB_AC_RDMA_READ;
-    }
-	    
-    cm_rtu.rq_depth       = 0;
-    cm_rtu.sq_depth       = 0;
-       
-    ib_status = ib_cm_rtu (p_cm_rep_rec->h_cm_rep, &cm_rtu);
-
-    if (ib_status == IB_SUCCESS)
-    {
-        cm_cb_op = IB_CME_CONNECTED;
-        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> DiCRpcb: EP %lx Connected req_count %d\n", 
-                  ep_ptr, dapls_cb_pending(&ep_ptr->req_buffer));
-    }
-    else
-    {
-        cm_cb_op = IB_CME_LOCAL_FAILURE;
-    }
-
-    prd_ptr = (DAPL_PRIVATE * __ptr64) p_cm_rep_rec->p_rep_pdata;
-
-#if defined(DAPL_DBG) && 0
-    dapli_print_private_data( "DiCRpcb",
-			      prd_ptr->private_data,
-			      IB_MAX_REP_PDATA_SIZE);
-#endif
-
-    dapl_evd_connection_callback ( 
-                            cm_ptr,
-                            cm_cb_op,
-                            (void *) prd_ptr,
-			    IB_REP_PDATA_SIZE,
-                            (void * __ptr64) p_cm_rep_rec->qp_context);
-}
-
-
-static void 
-dapli_ib_cm_rej_cb (
-        IN    ib_cm_rej_rec_t          *p_cm_rej_rec )
-{
-    DAPL_EP         *ep_ptr;
-    ib_cm_events_t  cm_event;
-    dp_ib_cm_handle_t	cm_ptr;
-
-    dapl_os_assert (p_cm_rej_rec);
-
-    ep_ptr = (DAPL_EP * __ptr64) p_cm_rej_rec->qp_context;
-
-    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
-                      __FUNCTION__, ep_ptr);
-        return;
-    }
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
-                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-        return;
-    }
-    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rej_rec->h_qp);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "--> DiCRjcb: EP = %lx QP = %lx rej reason = 0x%x\n", 
-                  ep_ptr,ep_ptr->qp_handle,CL_NTOH16(p_cm_rej_rec->rej_status));
-
-    switch (p_cm_rej_rec->rej_status)
-    {
-        case IB_REJ_INSUF_RESOURCES:
-        case IB_REJ_INSUF_QP:
-        case IB_REJ_INVALID_COMM_ID:
-        case IB_REJ_INVALID_COMM_INSTANCE:
-        case IB_REJ_INVALID_PKT_RATE:
-        case IB_REJ_INVALID_ALT_GID:
-        case IB_REJ_INVALID_ALT_LID:
-        case IB_REJ_INVALID_ALT_SL:
-        case IB_REJ_INVALID_ALT_TRAFFIC_CLASS:
-        case IB_REJ_INVALID_ALT_PKT_RATE:
-        case IB_REJ_INVALID_ALT_HOP_LIMIT:
-        case IB_REJ_INVALID_ALT_FLOW_LBL:
-        case IB_REJ_INVALID_GID:
-        case IB_REJ_INVALID_LID:
-        case IB_REJ_INVALID_SID:
-        case IB_REJ_INVALID_SL:
-        case IB_REJ_INVALID_TRAFFIC_CLASS:
-        case IB_REJ_PORT_REDIRECT:
-        case IB_REJ_INVALID_MTU:
-        case IB_REJ_INSUFFICIENT_RESP_RES:
-        case IB_REJ_INVALID_CLASS_VER:
-        case IB_REJ_INVALID_FLOW_LBL:
-            cm_event = IB_CME_DESTINATION_REJECT;
-            break;
-
-        case IB_REJ_TIMEOUT:
-            cm_event = IB_CME_DESTINATION_UNREACHABLE;
-            dapl_dbg_log (DAPL_DBG_TYPE_CM, "--> DiCRjcb: CR TIMEOUT\n");
-            break;
-
-        case IB_REJ_USER_DEFINED:
-            cm_event = IB_CME_DESTINATION_REJECT;
-            dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                               "--> DiCRjcb: user defined rej reason %s\n",
-                               p_cm_rej_rec->p_ari);
-            break;
-
-        default:
-            cm_event = IB_CME_LOCAL_FAILURE;
-            dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                               "--> DiCRjcb: with unknown status %x\n", 
-                               p_cm_rej_rec->rej_status);
-            break;
-     }
-
-    /* FIXME - Vu
-     * We do not take care off the user defined rej reason with additional 
-     * rejection information (p_ari)
-     */
-
-    if (ep_ptr->cr_ptr)
-    {
-        dapls_cr_callback ( cm_ptr,
-                            cm_event,
-                            (void * __ptr64) p_cm_rej_rec->p_rej_pdata,
-			    IB_REJ_PDATA_SIZE,
-                            (void *) ((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr);
-    }
-    else
-    {
-        dapl_evd_connection_callback (
-                                   cm_ptr,
-                                   cm_event,
-                                   (void * __ptr64) p_cm_rej_rec->p_rej_pdata,
-				   IB_REJ_PDATA_SIZE,
-                                   (void * __ptr64) p_cm_rej_rec->qp_context );
-    }
-
-}
-
-
-
-static void 
-dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
-{
-    DAPL_SP              *sp_ptr;
-    DAT_SOCK_ADDR6       dest_ia_addr;
-    dp_ib_cm_handle_t    cm_ptr;
-
-    dapl_os_assert (p_cm_req_rec);
-
-    sp_ptr = (DAPL_SP * __ptr64) p_cm_req_rec->context;
-
-    dapl_os_assert (sp_ptr);
-
-    /*
-     * The context pointer could have been cleaned up in a racing
-     * CM callback, check to see if we should just exit here
-     */
-    if (sp_ptr->header.magic == DAPL_MAGIC_INVALID)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_CM,
-                     "%s: BAD-Magic in SP %lx, racing CM callback?\n",
-                      __FUNCTION__, sp_ptr );
-	return;
-    }
-
-    dapl_os_assert ( sp_ptr->header.magic == DAPL_MAGIC_PSP || 
-                     sp_ptr->header.magic == DAPL_MAGIC_RSP );
-
-    /* preserve ibal's connection handle storage so we have a consistent
-     * pointer value. The reasons this is done dynamically instead of a static
-     * allocation in an end_point is the pointer value is set in the SP list
-     * of CR's here and searched for from disconnect callbacks. If the pointer
-     * value changes, you never find the CR on the sp list...
-     * EP struct deallocation is where this memory is released or prior in the
-     * error case.
-     */
-    cm_ptr = ibal_cm_alloc();
-    if (!cm_ptr)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "%s: FAILED to alloc IB CM handle storage?\n",
-                       __FUNCTION__);
-        return;
-    }
-
-    /*
-     * Save the cm_srvc_handle to avoid the race condition between
-     * the return of the ib_cm_listen and the notification of a conn req
-     */
-    if (sp_ptr->cm_srvc_handle != p_cm_req_rec->h_cm_listen)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
-                           "--> DiCRqcb: cm_service_handle is changed\n"); 
-        sp_ptr->cm_srvc_handle = p_cm_req_rec->h_cm_listen;
-    }
-
-    dapl_os_memzero (&dest_ia_addr, sizeof (dest_ia_addr));
-
-#ifdef NO_NAME_SERVICE
-
-    {
-        DAPL_PRIVATE *prd_ptr;
-        
-        prd_ptr = (DAPL_PRIVATE *)p_cm_req_rec->p_req_pdata;
-
-        dapl_os_memcpy ((void *)&dest_ia_addr,
-                        (void *)&prd_ptr->hca_address,
-                        sizeof (DAT_SOCK_ADDR6));        
-    }
-    
-#else
-
-    {
-        GID            dest_gid;
-
-        dapl_os_memzero (&dest_gid, sizeof (dest_gid));
-
-        dest_gid.guid = p_cm_req_rec->primary_path.dgid.unicast.interface_id;
-        dest_gid.gid_prefix = p_cm_req_rec->primary_path.dgid.unicast.prefix;
-
-        if (DAT_SUCCESS != dapls_ns_map_ipaddr (
-                                 sp_ptr->header.owner_ia->hca_ptr,
-                                 dest_gid,
-                                 (DAT_IA_ADDRESS_PTR)&dest_ia_addr))
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "cm_req_cb: SP = %lx failed mapping GID-IPaddr\n",
-                           sp_ptr);
-        }
-    }
-
-#endif /* NO_NAME_SERVICE */
-
-    /* preserve CR cm handle data */
-    dapl_os_memcpy( (void*)&cm_ptr->ib_cm,
-                    (void*)&p_cm_req_rec->h_cm_req,
-                    sizeof(ib_cm_handle_t));
-
-    /* preserve remote IP address */
-    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,
-                    (void*)&dest_ia_addr,
-                    sizeof(dest_ia_addr));
-
-#if defined(DAPL_DBG)
-    {
-        char ipa[20];
-  
-        //rval = ((struct sockaddr_in *) (&dest_ia_addr))->sin_addr.s_addr;
-
-        dapl_dbg_log (DAPL_DBG_TYPE_CM|DAPL_DBG_TYPE_CALLBACK, 
-                      "%s: query SA (CM %lx)->dst_ip_addr: %s\n",
-                      __FUNCTION__,cm_ptr,
-                      dapli_get_ip_addr_str(
-				(DAT_SOCK_ADDR6*) &cm_ptr->dst_ip_addr, ipa) );
-    }
-#endif
-
-    /* FIXME - Vu
-     * We have NOT used/saved the primary and alternative path record
-     * ie. p_cm_req_rec->p_primary_path and p_cm_req_rec->p_alt_path
-     * We should cache some fields in path record in the Name Service DB
-     * such as: dgid, dlid
-     * Also we do not save resp_res (ie. max_oustanding_rdma_read/atomic)
-     * rnr_retry_cnt and flow_ctrl fields
-     */
-    dapl_dbg_log (DAPL_DBG_TYPE_CM,
-                  "%s: SP %lx max_rdma_read %d PrivateData %lx\n",
-                  __FUNCTION__, sp_ptr, p_cm_req_rec->resp_res,
-                  p_cm_req_rec->p_req_pdata);
-
-    dapls_cr_callback ( cm_ptr,
-                        IB_CME_CONNECTION_REQUEST_PENDING,
-                        (void * __ptr64) p_cm_req_rec->p_req_pdata,
-						IB_REQ_PDATA_SIZE,
-                        (void * __ptr64) sp_ptr );
-}
-
-
-static void 
-dapli_ib_cm_mra_cb (
-        IN    ib_cm_mra_rec_t          *p_cm_mra_rec )
-{
-	UNUSED_PARAM( p_cm_mra_rec );
-	dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
-                       "--> DiCMcb: CM callback MRA\n");
-}
-
-static void 
-dapli_ib_cm_rtu_cb (
-        IN    ib_cm_rtu_rec_t          *p_cm_rtu_rec )
-{
-    DAPL_EP         	*ep_ptr;
-    dp_ib_cm_handle_t	cm_ptr;
-
-    dapl_os_assert (p_cm_rtu_rec != NULL);
-   
-    ep_ptr = (DAPL_EP * __ptr64) p_cm_rtu_rec->qp_context;
-
-    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
-                      __FUNCTION__, ep_ptr);
-        return;
-    }
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr)
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-        return;
-    }
-    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rtu_rec->h_qp);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
-                  "--> DiCRucb: EP %lx QP %lx CR %lx\n",
-                  ep_ptr, ep_ptr->qp_handle, ep_ptr->cr_ptr); 
-
-    if (ep_ptr->cr_ptr)
-    {
-        DAPL_SP  *sp_ptr;
-
-        sp_ptr = ((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr;
-
-        /* passive connection side */
-        dapls_cr_callback ( cm_ptr,
-                            IB_CME_CONNECTED,
-                            (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,
-                            IB_RTU_PDATA_SIZE,
-                            (void *) sp_ptr);
-                            
-    }
-    else
-    {
-        dapl_evd_connection_callback ( 
-                            cm_ptr,
-                            IB_CME_CONNECTED,
-                            (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,
-			    IB_RTU_PDATA_SIZE,
-                            (void *) ep_ptr);
-    }
-}
-
-/*
- * dapls_ib_cm_remote_addr
- *
- * Obtain the remote IP address given a connection
- *
- * Input:
- *	cr_handle
- *
- * Output:
- *	remote_ia_address: where to place the remote address
- *
- * Returns:
- * 	DAT_SUCCESS
- *	DAT_INVALID_HANDLE
- *
- */
-DAT_RETURN
-dapls_ib_cm_remote_addr (
-    IN      DAT_HANDLE          dat_handle,
-    OUT     DAT_SOCK_ADDR6      *remote_address )
-{
-
-    DAPL_HEADER        *header;
-    dp_ib_cm_handle_t  cm;
-    char               ipa[20];
-    char               *rtype;
-
-    header = (DAPL_HEADER *)dat_handle;
-
-    if (header->magic == DAPL_MAGIC_EP) 
-    {
-    	cm = dapl_get_cm_from_ep((DAPL_EP *)dat_handle);
-	rtype = "EP";
-    }
-    else if (header->magic == DAPL_MAGIC_CR) 
-    {
-    	cm = ((DAPL_CR *) dat_handle)->ib_cm_handle;
-	rtype = "CR";
-    }
-    else 
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_CM,
-                       "%s: hdr->magic %x, dat_handle(%lx)\n",
-                       __FUNCTION__, header->magic, dat_handle );
-    	return DAT_INVALID_HANDLE;
-    }
-
-    dapl_os_memcpy( remote_address, &cm->dst_ip_addr, sizeof(DAT_SOCK_ADDR6) );
-
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s: returns %s remote Addrs %s\n",
-                   __FUNCTION__, rtype,
-                   dapli_get_ip_addr_str((DAT_SOCK_ADDR6*)remote_address,ipa) );
-
-    return DAT_SUCCESS;
-}
-
-
-/*
- * dapls_ib_connect
- *
- * Initiate a connection with the passive listener on another node
- *
- * Input:
- *        ep_handle,
- *        remote_ia_address,
- *        remote_conn_qual,
- *          prd_size                size of private data and structure
- *          prd_prt                pointer to private data structure
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_connect (
-        IN        DAT_EP_HANDLE                ep_handle,
-        IN        DAT_IA_ADDRESS_PTR           remote_ia_address,
-        IN        DAT_CONN_QUAL                remote_conn_qual,
-        IN        DAT_COUNT                    private_data_size,
-        IN        DAT_PVOID                    private_data )
-{
-    DAPL_EP                      *ep_ptr;
-    DAPL_IA                      *ia_ptr;
-    ib_api_status_t              ib_status;
-    dapl_ibal_port_t             *p_active_port;
-    dapl_ibal_ca_t               *p_ca;
-    ib_cm_req_t                  cm_req;
-    ib_path_rec_t                path_rec;
-    GID                          dest_GID;
-    ib_query_req_t               query_req;
-    ib_gid_pair_t                gid_pair;
-    ib_service_record_t          service_rec;
-    int                          retry_cnt;
-    DAT_RETURN                   dat_status;
-
-    ep_ptr         = (DAPL_EP *) ep_handle;
-    ia_ptr         = ep_ptr->header.owner_ia;
-    ep_ptr->cr_ptr = NULL;
-    retry_cnt      = 0;
-    dat_status     = DAT_SUCCESS;
-
-    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-
-    /*
-     * We are using the first active port in the list for
-     * communication. We have to get back here when we decide to support
-     * fail-over and high-availability.
-     */
-    p_active_port = dapli_ibal_get_port ( p_ca,
-                                          (uint8_t)ia_ptr->hca_ptr->port_num );
-
-    if (NULL == p_active_port)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: Port %d not available %d\n",
-                       ia_ptr->hca_ptr->port_num, __LINE__ );
-        return (DAT_INVALID_STATE);
-    }
-
-    dapl_os_memzero (&dest_GID, sizeof (GID));
-    dapl_os_memzero (&cm_req, sizeof (ib_cm_req_t));
-    dapl_os_memzero (&path_rec, sizeof (ib_path_rec_t));
-    dapl_os_memzero (&service_rec, sizeof (ib_service_record_t));
-    dapl_os_memzero (&query_req, sizeof (ib_query_req_t));
-    dapl_os_memzero (&gid_pair, sizeof (ib_gid_pair_t));
-    dapl_os_memzero (&ep_ptr->remote_ia_address, sizeof (DAT_SOCK_ADDR6));
-
-    dapl_os_memcpy (&ep_ptr->remote_ia_address, 
-                    remote_ia_address, 
-                    sizeof (ep_ptr->remote_ia_address));
-
-
-#ifdef NO_NAME_SERVICE
-
-    if (DAT_SUCCESS !=
-        (dat_status = dapls_ns_lookup_address (
-                                         ia_ptr,
-                                         remote_ia_address,
-                                         &dest_GID         )))
-    {
-        /*
-         * Remote address not in the table, this is a
-         * strange return code!
-         */
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: exits status = %x\n", dat_status);
-        return dat_status;
-    }
-
-    dest_GID.guid = CL_HTON64 (dest_GID.guid);
-    dest_GID.gid_prefix = CL_HTON64 (dest_GID.gid_prefix);
-
-#else
-
-    /*
-     * We query the SA to get the dest_gid with the 
-     * {uDAPL_svc_id, IP-address} as the key to get GID.
-     */
-    if (DAT_SUCCESS !=
-        (dat_status = dapls_ns_map_gid (ia_ptr->hca_ptr, 
-                                        remote_ia_address,
-                                        &dest_GID)))
-        
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsC: fail to map remote_ia_addr "
-                       "(sa_family %d) to gid\n",
-                       remote_ia_address->sa_family); 
-        return dat_status;
-    }
-#endif /* NO_NAME_SERVICE */
-
-    gid_pair.dest_gid.unicast.interface_id = dest_GID.guid;
-    gid_pair.dest_gid.unicast.prefix       = dest_GID.gid_prefix;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                  "dapls_ib_connect: EP %lx QP %lx SERVER GID{0x" F64x
-                  ", 0x" F64x "}\n", 
-                  ep_ptr, ep_ptr->qp_handle,
-                  cl_hton64 (gid_pair.dest_gid.unicast.prefix),
-                  cl_hton64 (gid_pair.dest_gid.unicast.interface_id));
-
-    gid_pair.src_gid = p_active_port->p_attr->p_gid_table[0];
-/*
-    if ((gid_pair.src_gid.unicast.interface_id == 
-         gid_pair.dest_gid.unicast.interface_id   ) &&
-        (gid_pair.src_gid.unicast.prefix == 
-         gid_pair.dest_gid.unicast.prefix   ))
-    {
-        path_rec.dgid     = gid_pair.dest_gid;
-        path_rec.sgid     = gid_pair.src_gid;
-        path_rec.slid     = path_rec.dlid = p_active_port->p_attr->lid;
-        path_rec.pkey     = p_active_port->p_attr->p_pkey_table[0];
-        path_rec.mtu      = p_active_port->p_attr->mtu;
-		path_rec.pkt_life = 18;  // 1 sec
-		path_rec.rate     = IB_PATH_RECORD_RATE_10_GBS;
-	
-	}
-    else
-    {
-  */
-        /*
-         * Query SA to get the path record from pair of GIDs
-         */
-        dapl_os_memzero (&query_req, sizeof (ib_query_req_t));
-        query_req.query_type      = IB_QUERY_PATH_REC_BY_GIDS;
-        query_req.p_query_input   = (void *) &gid_pair;
-        query_req.flags           = IB_FLAGS_SYNC;  
-        query_req.timeout_ms      = 1 * 1000;       /* 1 second */
-        query_req.retry_cnt       = 3;
-        /* query SA using this port */
-        query_req.port_guid       = p_active_port->p_attr->port_guid;
-        query_req.query_context   = (void *) &path_rec;
-        query_req.pfn_query_cb    = dapli_ib_sa_query_cb;
- 
-        ib_status = ib_query (dapl_ibal_root.h_al, &query_req, NULL);
-
-        if ((ib_status != IB_SUCCESS) || (!path_rec.dlid))
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: EP %lx QP %lx query "
-                           "pair_gids status = %s\n", 
-                           ep_ptr, ep_ptr->qp_handle,ib_get_err_str(ib_status));
-            return DAT_INVALID_PARAMETER;
-        }
-
-    //}
-
-	/*
-	 * Tavor has a HW bug that causes bandwidth with 2K MTU to be less than
-	 * with 1K MTU.  Cap the MTU based on device ID to compensate for this.
-	 */
-	if( (p_ca->p_ca_attr->dev_id == 0x5A44) &&
-		(ib_path_rec_mtu( &path_rec ) > IB_MTU_LEN_1024) )
-	{
-            /* Local endpoint is Tavor - cap MTU to 1K for extra bandwidth. */
-            path_rec.mtu &= IB_PATH_REC_SELECTOR_MASK;
-            path_rec.mtu |= IB_MTU_LEN_1024;
-	}
-
-	/* 
-     * prepare the Service ID from conn_qual 
-     */
-    cm_req.svc_id           = remote_conn_qual;
-    cm_req.p_primary_path   = &path_rec;
-    cm_req.p_alt_path       = NULL;
-    cm_req.h_qp             = ep_ptr->qp_handle;
-    cm_req.qp_type          = IB_QPT_RELIABLE_CONN;
-    cm_req.p_req_pdata      = (uint8_t *) private_data;
-    cm_req.req_length       = (uint8_t)
-				min(private_data_size,IB_MAX_REQ_PDATA_SIZE);
-    /* cm retry to send this request messages, IB max of 4 bits */
-    cm_req.max_cm_retries   = 15; /* timer outside of call, s/be infinite */
-    /* qp retry to send any wr */
-    cm_req.retry_cnt        = 5;
-    /* max num of oustanding RDMA read/atomic support */
-    cm_req.resp_res         = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_in;
-    /* max num of oustanding RDMA read/atomic will use */
-    cm_req.init_depth       = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_out;
-
-    /* time wait before retrying a pkt after receiving a RNR NAK */
-    cm_req.rnr_nak_timeout  = IB_RNR_NAK_TIMEOUT;
-    
-	/* 
-     * number of time local QP should retry after receiving RNR NACK before
-     * reporting an error
-     */
-    cm_req.rnr_retry_cnt       = IB_RNR_RETRY_CNT;
-
-    cm_req.remote_resp_timeout = 16;	/* 250ms */
-    cm_req.local_resp_timeout  = 16;	/* 250ms */
-    
-    cm_req.flow_ctrl           = TRUE;
-    cm_req.flags               = 0;
-    /*
-     * We do not use specific data buffer to check for specific connection
-     */
-    cm_req.p_compare_buffer    = NULL;
-    cm_req.compare_offset      = 0;
-    cm_req.compare_length      = 0;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM, "--> DsConn: EP=%lx QP=%lx rio=%d,%d pl=%d "
-                  "mtu=%d slid=%#x dlid=%#x\n", 
-                  ep_ptr, ep_ptr->qp_handle,  cm_req.resp_res, 
-                  cm_req.init_depth, ib_path_rec_pkt_life(&path_rec),
-                  ib_path_rec_mtu(&path_rec),
-                  cm_req.p_primary_path->slid,
-                  cm_req.p_primary_path->dlid);
-
-    /*
-     * We do not support peer_to_peer; therefore, we set pfn_cm_req_cb = NULL
-     */
-    cm_req.pfn_cm_req_cb       = NULL;
-    cm_req.pfn_cm_rep_cb       = dapli_ib_cm_rep_cb;
-    cm_req.pfn_cm_rej_cb       = dapli_ib_cm_rej_cb;
-    /* callback when a message received acknowledgement is received */
-    cm_req.pfn_cm_mra_cb       = dapli_ib_cm_mra_cb;
-
-    ib_status = ib_cm_req (&cm_req);
-    
-    if ( ib_status != IB_SUCCESS )
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsC: EP %lx QP %lx conn_request failed = %s\n", 
-                       ep_ptr, ep_ptr->qp_handle, ib_get_err_str(ib_status));
-
-        return  (dapl_ib_status_convert (ib_status));
-    }
-
-    return DAT_SUCCESS;
-}
-
-
-/*
- * dapls_ib_disconnect
- *
- * Disconnect an EP
- *
- * Input:
- *        ep_handle,
- *        disconnect_flags
- *           DAT_CLOSE_ABRUPT_FLAG - no callback
- *           DAT_CLOSE_GRACEFUL_FLAG - callback desired.
- *
- * Output:
- *         none
- *
- * Returns:
- *        DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_disconnect ( IN   DAPL_EP           *ep_ptr,
-                      IN   DAT_CLOSE_FLAGS   disconnect_flags )
-{
-	DAT_RETURN dat_status = DAT_SUCCESS;
-	ib_cm_dreq_t	cm_dreq;
-	dp_ib_cm_handle_t	cm_ptr;
-	ib_cm_handle_t h_cm;
-	enum dapl_ibal_cm_state state;
-
-	dapl_os_assert(ep_ptr);
-
-	if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
-	{
-		dapl_dbg_log (DAPL_DBG_TYPE_CM,
-			"--> %s: BAD EP Magic EP=%lx\n", __FUNCTION__,ep_ptr); 
-		return DAT_SUCCESS;
-	}
-
-	cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-	if (!cm_ptr)
-	{
-		dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
-			"--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
-		return DAT_SUCCESS;
-	}
- 
-	dapl_dbg_log (DAPL_DBG_TYPE_CM,
-		"--> %s() EP %p %s Close %s\n", __FUNCTION__,
-		ep_ptr, dapl_get_ep_state_str(ep_ptr->param.ep_state),
-		(disconnect_flags == DAT_CLOSE_ABRUPT_FLAG ? "Abrupt":"Graceful"));
-
-	//if ( disconnect_flags == DAT_CLOSE_ABRUPT_FLAG )
-	//{
-	//    dapl_dbg_log(DAPL_DBG_TYPE_CM,
-	//		"%s() calling legacy_post_disconnect()\n",__FUNCTION__);
-	//	dapl_ep_legacy_post_disconnect(ep_ptr, disconnect_flags);
-	//}
-
-	dapl_os_lock(&ep_ptr->header.lock);
-	if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED)
-	{
-		dapl_os_unlock(&ep_ptr->header.lock);
-		return dat_status;
-	}
-
-	h_cm = cm_ptr->ib_cm;
-	state = cm_ptr->state;
-	cm_ptr->state = IBAL_CM_DISCONNECT;
-	dapl_os_unlock(&ep_ptr->header.lock);
-
-	if (state == IBAL_CM_DREQ)
-		dapli_send_ib_cm_drep(h_cm);
-	else
-		dapli_send_ib_cm_dreq(cm_ptr->ib_cm);
-
-	return DAT_SUCCESS;
-}
-
-
-/*
- * dapl_ib_setup_conn_listener
- *
- * Have the CM set up a connection listener.
- *
- * Input:
- *        ibm_hca_handle           HCA handle
- *        qp_handle                QP handle
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_setup_conn_listener (
-        IN  DAPL_IA               *ia_ptr,
-        IN  DAT_UINT64            ServiceID,
-        IN  DAPL_SP               *sp_ptr )
-{
-    ib_api_status_t               ib_status;
-    ib_cm_listen_t                cm_listen;
-    dapl_ibal_ca_t                *p_ca;
-    dapl_ibal_port_t              *p_active_port;
-
-    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-
-    /*
-     * We are using the first active port in the list for
-     * communication. We have to get back here when we decide to support
-     * fail-over and high-availability.
-     */
-    p_active_port = dapli_ibal_get_port( p_ca,
-					(uint8_t)ia_ptr->hca_ptr->port_num );
-
-    if (NULL == p_active_port)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"%s: SP %lx port %d not available\n",
-                __FUNCTION__, sp_ptr, ia_ptr->hca_ptr->port_num );
-        return (DAT_INVALID_STATE);
-    }
-
-    if (p_active_port->p_attr->lid == 0)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsSCL: SP %lx SID 0x" F64x " port %d\n", 
-                       sp_ptr, cl_hton64(ServiceID),
-                       p_active_port->p_attr->port_num);
-        return (DAT_INVALID_STATE);
-    }
-
-    dapl_dbg_log (DAPL_DBG_TYPE_CM,
-         "%s: SP %lx port %d GID{0x" F64x ", 0x" F64x "} and SID 0x" F64x "\n", 
-         __FUNCTION__,
-         sp_ptr, p_active_port->p_attr->port_num,
-         cl_hton64 (p_active_port->p_attr->p_gid_table[0].unicast.prefix),
-         cl_hton64 (p_active_port->p_attr->p_gid_table[0].unicast.interface_id),
-         cl_hton64 (ServiceID));
-    
-    dapl_os_memzero (&cm_listen, sizeof (ib_cm_listen_t));
-
-    /*
-     * Listen for all request on  this specific CA
-     */
-    cm_listen.ca_guid = (p_ca->p_ca_attr->ca_guid);
-    cm_listen.svc_id  = ServiceID;
-    cm_listen.qp_type = IB_QPT_RELIABLE_CONN; 
-
-    /*
-     * We do not use specific data buffer to check for specific connection
-     */
-    cm_listen.p_compare_buffer = NULL;//(uint8_t*)&sp_ptr->conn_qual;
-    cm_listen.compare_offset   = 0;//IB_MAX_REQ_PDATA_SIZE - sizeof(DAT_CONN_QUAL);
-    cm_listen.compare_length   = 0;//sizeof(DAT_CONN_QUAL);
-
-    /*
-     * We can pick a port here for communication and the others are reserved
-     * for fail-over / high-availability - TBD
-     */
-    cm_listen.port_guid     = p_active_port->p_attr->port_guid;
-    cm_listen.lid           = p_active_port->p_attr->lid;
-    cm_listen.pkey          = p_active_port->p_attr->p_pkey_table[0];
-
-    /*
-     * Register request or mra callback functions
-     */
-    cm_listen.pfn_cm_req_cb = dapli_ib_cm_req_cb;
-
-    ib_status = ib_cm_listen ( dapl_ibal_root.h_al,
-                               &cm_listen,
-                               (void *) sp_ptr,
-                               &sp_ptr->cm_srvc_handle );
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "%s: SP %lx SID 0x" F64x " listen failed %s\n", 
-                       __FUNCTION__, sp_ptr, cl_hton64 (ServiceID),
-                       ib_get_err_str(ib_status));
-    }
-
-    return dapl_ib_status_convert (ib_status);
-}
-
-
-/*
- * dapl_ib_remove_conn_listener
- *
- * Have the CM remove a connection listener.
- *
- * Input:
- *      ia_handle               IA handle
- *      ServiceID               IB Channel Service ID
- *
- * Output:
- *      none
- *
- * Returns:
- *      DAT_SUCCESS
- *      DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_remove_conn_listener (
-        IN  DAPL_IA        *ia_ptr,
-        IN  DAPL_SP        *sp_ptr )
-{
-    ib_api_status_t        ib_status;
-    DAT_RETURN             dat_status = DAT_SUCCESS;
-	
-    UNUSED_PARAM( ia_ptr );
-
-    dapl_os_assert ( sp_ptr );
-
-    dapl_os_assert ( sp_ptr->header.magic == DAPL_MAGIC_PSP ||
-         sp_ptr->header.magic == DAPL_MAGIC_RSP );
-
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s() cm_srvc_handle %lx\n",
-                   __FUNCTION__, sp_ptr->cm_srvc_handle );
-
-    if (sp_ptr->cm_srvc_handle)
-    {
-        ib_status = ib_cm_cancel ( sp_ptr->cm_srvc_handle, 
-                                   NULL );
-        
-        if (ib_status != IB_SUCCESS)
-        {
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "--> DsRCL: SP %lx ib_cm_cancel failed(0x%x) %s\n", 
-                           sp_ptr, sp_ptr->cm_srvc_handle,
-                           ib_get_err_str(ib_status));
-            sp_ptr->cm_srvc_handle = NULL;
-            return (DAT_INVALID_PARAMETER);
-        }
-
-        sp_ptr->cm_srvc_handle = NULL;
-    }
-
-    return dat_status;
-}
-
-/*
- * dapls_ib_reject_connection
- *
- * Perform necessary steps to reject a connection
- *
- * Input:
- *        cr_handle
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_reject_connection ( IN  dp_ib_cm_handle_t   ib_cm_handle,
-                             IN  int                 reject_reason,
-                             IN  DAT_COUNT           private_data_size,
-                             IN  const DAT_PVOID     private_data)
-{
-    ib_api_status_t        ib_status;
-    ib_cm_rej_t            cm_rej;
-    static char            *rej_table[] =
-    {
-        "INVALID_REJ_REASON",
-        "INVALID_REJ_REASON",
-        "INVALID_REJ_REASON",
-        "INVALID_REJ_REASON",
-        "INVALID_REJ_REASON",
-        "IB_CME_DESTINATION_REJECT",
-        "IB_CME_DESTINATION_REJECT_PRIVATE_DATA",
-        "IB_CME_DESTINATION_UNREACHABLE",
-        "IB_CME_TOO_MANY_CONNECTION_REQUESTS",
-        "IB_CME_LOCAL_FAILURE",
-        "IB_CM_LOCAL_FAILURE"
-    };
-
-#define REJ_TABLE_SIZE  IB_CM_LOCAL_FAILURE
-
-    reject_reason = __min( reject_reason & 0xff, REJ_TABLE_SIZE);
-
-    cm_rej.rej_status   = IB_REJ_USER_DEFINED;
-    cm_rej.p_ari        = (ib_ari_t *)&rej_table[reject_reason]; 
-    cm_rej.ari_length   = (uint8_t)strlen (rej_table[reject_reason]);
-
-    cm_rej.p_rej_pdata  = private_data;
-    cm_rej.rej_length   = private_data_size;
-
-#if defined(DAPL_DBG) && 0
-    dapli_print_private_data("DsRjC",private_data,private_data_size);
-#endif
-
-    ib_status = ib_cm_rej(ib_cm_handle->ib_cm, &cm_rej);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsRjC: cm_handle %p reject failed %s\n", 
-                       ib_cm_handle, ib_get_err_str(ib_status) );
-    }
-
-    return ( dapl_ib_status_convert ( ib_status ) );
-}
-
-
-
-#if 0
-static void
-dapli_query_qp( ib_qp_handle_t qp_handle, ib_qp_attr_t  *qpa )
-{
-    ib_api_status_t        ib_status;
-    
-    ib_status = ib_query_qp ( qp_handle, qpa );
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"ib_query_qp(%lx) '%s'\n",
-                qp_handle, ib_get_err_str(ib_status) );
-    }
-    else
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_CM, "--> QP(%lx) state %s "
-                       "type %d init %d acc %x\n",
-                       qp_handle,
-                       ib_get_port_state_str(qpa->state),
-                       qpa->qp_type,
-                       qpa->init_depth,
-                       qpa->access_ctrl );
-    }
-}
-#endif
-
-
-/*
- * dapls_ib_accept_connection
- *
- * Perform necessary steps to accept a connection
- *
- * Input:
- *        cr_handle
- *        ep_handle
- *        private_data_size
- *        private_data
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_accept_connection (
-        IN        DAT_CR_HANDLE            cr_handle,
-        IN        DAT_EP_HANDLE            ep_handle,
-        IN        DAT_COUNT                private_data_size,
-        IN const  DAT_PVOID                private_data )
-{
-    DAPL_CR                *cr_ptr;
-    DAPL_EP                *ep_ptr;
-    DAPL_IA                *ia_ptr;
-    DAT_RETURN             dat_status;
-    ib_api_status_t        ib_status;
-    dapl_ibal_ca_t         *p_ca;
-    dapl_ibal_port_t       *p_active_port;
-    ib_cm_rep_t            cm_rep;
-    ib_qp_attr_t           qpa;
-    dp_ib_cm_handle_t      cm_ptr;
-
-    cr_ptr = (DAPL_CR *) cr_handle;
-    ep_ptr = (DAPL_EP *) ep_handle;
-    ia_ptr = ep_ptr->header.owner_ia;
-
-    if ( ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED )
-    {
-        /*
-         * If we are lazy attaching the QP then we may need to
-         * hook it up here. Typically, we run this code only for
-         * DAT_PSP_PROVIDER_FLAG
-         */
-        dat_status = dapls_ib_qp_alloc ( ia_ptr, ep_ptr, ep_ptr );
-
-        if ( dat_status != DAT_SUCCESS)
-        {
-            /* This is not a great error code, but all the spec allows */
-            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                           "-->  DsIBAC: CR %lx EP %lx alloc QP failed 0x%x\n",
-                           cr_ptr, ep_ptr, dat_status );
-            return (dat_status);
-        }
-    }
-
-    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-    p_active_port = dapli_ibal_get_port ( p_ca,
-                                          (uint8_t)ia_ptr->hca_ptr->port_num );
-    if (NULL == p_active_port)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIBAC: CR %lx EP %lx port %d is not available\n",
-                       cr_ptr, ep_ptr, ia_ptr->hca_ptr->port_num);
-        return (DAT_INVALID_STATE);
-    }
-
-    cr_ptr->param.local_ep_handle = ep_handle;
-
-    /*
-     * assume ownership, in that once the EP is released the dynamic
-     * memory containing the IBAL CM handle (ib_cm_handle_t) struct will
-     * be released; see dapl_ep_dealloc().
-     */
-   
-    /* EP-CM, save/release CR CM object, use EP CM object already linked */
-    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
-    if (!cm_ptr) {
-	dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIBAC: CM linking to EP %p not available\n",
-                       ep_ptr);
-	return (DAT_INVALID_STATE);
-    }
-     
-    /* set remote IP addr fields. IP addr data is deduced from Connection
-     * Request record (gid/lib) and stashed away for use here. DAPL 1.1
-     * had an interface for passing the IP info down, interface went away
-     * in 2.0?
-     */
-    dapl_os_memcpy( (void*)&ep_ptr->remote_ia_address,
-                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,
-                    sizeof(DAT_SOCK_ADDR6) );
-
-    dapl_os_memcpy( (void*)&cr_ptr->remote_ia_address,
-                    (void*)&ep_ptr->remote_ia_address,
-                    sizeof(DAT_SOCK_ADDR6) );
-
-#if defined(DAPL_DBG)
-    {
-        char ipa[20];
-
-        dapl_dbg_log (DAPL_DBG_TYPE_CM|DAPL_DBG_TYPE_CALLBACK, 
-                      "%s: EP(%lx) RemoteAddr: %s\n",
-                      __FUNCTION__, ep_ptr,
-                     dapli_get_ip_addr_str(
-                            (DAT_SOCK_ADDR6*)&ep_ptr->remote_ia_address, ipa) );
-    }
-#endif
-
-    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,
-                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,
-                    sizeof(DAT_SOCK_ADDR6) );
-
-    /* get h_al and connection ID from CR CM object, h_qp already set */
-    cm_ptr->ib_cm.cid = cr_ptr->ib_cm_handle->ib_cm.cid; 
-    cm_ptr->ib_cm.h_al = cr_ptr->ib_cm_handle->ib_cm.h_al;
-    dapls_cm_release(cr_ptr->ib_cm_handle);
-
-    cr_ptr->ib_cm_handle = cm_ptr; /* for dapli_get_sp_ep() upcall */
-
-    ep_ptr->cr_ptr        = cr_ptr;
-
-    dapl_os_memzero ( (void*)&cm_rep, sizeof (ib_cm_rep_t) );
-
-    cm_rep.h_qp           = ep_ptr->qp_handle;
-    cm_rep.qp_type        = IB_QPT_RELIABLE_CONN;
-
-    if (private_data_size > IB_MAX_REP_PDATA_SIZE) {
-    	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-			"--> DsIBAC: private_data_size(%d) > Max(%d)\n",
-			private_data_size, IB_MAX_REP_PDATA_SIZE);
-	return DAT_ERROR(DAT_LENGTH_ERROR, DAT_NO_SUBTYPE);
-                                 
-        }
-    cm_rep.p_rep_pdata    = (const uint8_t *)private_data;
-    cm_rep.rep_length     = private_data_size;
-                            
-#if defined(DAPL_DBG) && 0
-    dapli_print_private_data( "DsIBAC",
-			      (const uint8_t*)private_data,
- 			      private_data_size );
-#endif
-
-    cm_rep.pfn_cm_rej_cb = dapli_ib_cm_rej_cb;
-    cm_rep.pfn_cm_mra_cb = dapli_ib_cm_mra_cb;
-    cm_rep.pfn_cm_rtu_cb  = dapli_ib_cm_rtu_cb;
-    cm_rep.pfn_cm_lap_cb  = dapli_ib_cm_lap_cb;
-    cm_rep.pfn_cm_dreq_cb = dapli_ib_cm_dreq_cb;
-
-    /*
-     * FIXME - Vu
-     *         Pay attention to the attributes. 
-     *         Some of them are desirably set by DAT consumers
-     */
-    /*
-     * We enable the qp associate with this connection ep all the access right
-     * We enable the flow_ctrl, retry till success
-     * We will limit the access right and flow_ctrl upon DAT consumers 
-     * requirements
-     */
-    cm_rep.access_ctrl =
-		IB_AC_LOCAL_WRITE|IB_AC_RDMA_WRITE|IB_AC_MW_BIND|IB_AC_ATOMIC;
-
-    if ((ep_ptr->param.ep_attr.max_rdma_read_in > 0) 
-		|| (ep_ptr->param.ep_attr.max_rdma_read_out > 0))
-    {
-	cm_rep.access_ctrl |= IB_AC_RDMA_READ;
-    }
-
-    cm_rep.sq_depth          = 0;
-    cm_rep.rq_depth          = 0;
-    cm_rep.init_depth        = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_out;
-    cm_rep.flow_ctrl         = TRUE;
-    cm_rep.flags             = 0;
-    cm_rep.failover_accepted = IB_FAILOVER_ACCEPT_UNSUPPORTED;
-    cm_rep.target_ack_delay  = 14;
-    cm_rep.rnr_nak_timeout   = IB_RNR_NAK_TIMEOUT;
-    cm_rep.rnr_retry_cnt     = IB_RNR_RETRY_CNT;
-    cm_rep.pp_recv_failure   = NULL;
-    cm_rep.p_recv_wr         = NULL;
-     
-    dapl_dbg_log (DAPL_DBG_TYPE_CM,
-                 "--> DsIBAC: cm_rep: acc %x init %d qp_type %x req_count %d\n",
-	         cm_rep.access_ctrl, cm_rep.init_depth,cm_rep.qp_type,
-                 dapls_cb_pending(&ep_ptr->req_buffer));
-
-    ib_status = ib_cm_rep ( cm_ptr->ib_cm, &cm_rep );
-
-    if (ib_status != IB_SUCCESS)
-    {
-	dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsIBAC: EP %lx QP %lx CR reply failed '%s'\n",
-                       ep_ptr, ep_ptr->qp_handle, ib_get_err_str(ib_status) );
-    }
- 
-    return ( dapl_ib_status_convert ( ib_status ) );
-}
-
-
-
-/*
- * dapls_ib_disconnect_clean
- *
- * Clean up outstanding connection data. This routine is invoked
- * after the final disconnect callback has occurred. Only on the
- * ACTIVE side of a connection.
- *
- * Input:
- *        ep_ptr                DAPL_EP
- *
- * Output:
- *         none
- *
- * Returns:
- *         void
- *
- */
-void
-dapls_ib_disconnect_clean (
-        IN  DAPL_EP                     *ep_ptr,
-        IN  DAT_BOOLEAN                 active,
-        IN  const ib_cm_events_t        ib_cm_event )
-{
-    DAPL_IA		*ia_ptr;
-    ib_qp_attr_t	qp_attr;
-    ib_api_status_t     ib_status;
-
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s(%s): cm_event: %s \n", __FUNCTION__,
-                   (active?"A":"P"), dapli_ib_cm_event_str(ib_cm_event));
-
-    ia_ptr = ep_ptr->header.owner_ia;
-    
-    if ( ia_ptr == NULL || ia_ptr->header.magic != DAPL_MAGIC_IA )
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_CM,
-                       ">>>DSCONN_CLEAN(%s): cm_event: %s Invalid IA_ptr\n",
-                       (active?"Act":"Pas"),dapli_ib_cm_event_str(ib_cm_event));
-        return;
-    }
-    dapl_os_assert ( ep_ptr->header.magic == DAPL_MAGIC_EP );
-    
-    ib_status = ib_query_qp ( ep_ptr->qp_handle, &qp_attr );
-    if ( ib_status != IB_SUCCESS )
-    {
-	    dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       ">>>DSCONN_CLEAN(%s): Query QP failed = %s\n",
-                       (active?"Act":"Pas"),ib_get_err_str(ib_status) );
-		return;
-    }
-    
-    ep_ptr->qp_state = qp_attr.state;
-
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM, ">>>DSCONN_CLEAN(%s): cm_event: %d "
-                   "ep_ptr %lx ep_state %s qp_state %#x\n", 
-                   (active?"A":"P"), ib_cm_event, ep_ptr,
-                   dapl_get_ep_state_str(ep_ptr->param.ep_state),
-                   ep_ptr->qp_state );
-
-    if ( ep_ptr->qp_state != IB_QPS_ERROR &&
-         ep_ptr->qp_state != IB_QPS_RESET &&
-         ep_ptr->qp_state != IB_QPS_INIT )
-    {
-        ep_ptr->qp_state = IB_QPS_ERROR;
-        dapls_modify_qp_state_to_error (ep_ptr->qp_handle);
-    }
-}
-
-
-#ifdef NOT_USED
-/*
- * dapls_ib_cr_handoff
- *
- * Hand off the connection request to another service point  
- *
- * Input:
- *        cr_handle                DAT_CR_HANDLE
- *        handoff_serv_id          DAT_CONN_QUAL
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *         DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN 
-dapls_ib_cr_handoff (
-        IN  DAT_CR_HANDLE      cr_handle,
-        IN  DAT_CONN_QUAL      handoff_serv_id )
-{
-    DAPL_CR                *cr_ptr;
-    ib_api_status_t        ib_status;
-    
-    cr_ptr = (DAPL_CR *) cr_handle;
-
-    if (cr_ptr->ib_cm_handle->ib_cm.cid == 0xFFFFFFFF)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsCH: CR = %lx invalid cm handle\n", cr_ptr);
-        return DAT_INVALID_PARAMETER;
-    }
-
-    if (cr_ptr->sp_ptr == DAPL_IB_INVALID_HANDLE)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsCH: CR = %lx invalid psp handle\n", cr_ptr);
-        return DAT_INVALID_PARAMETER;
-    }
-
-    ib_status = ib_cm_handoff (cr_ptr->ib_cm_handle->ib_cm, handoff_serv_id);
-
-    if (ib_status != IB_SUCCESS)
-    {
-        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
-                       "--> DsCH: CR = %lx handoff failed = %s\n", 
-                       cr_ptr, ib_get_err_str(ib_status) );
-
-        return dapl_ib_status_convert (ib_status);
-    }
-
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM,
-                   "--> %s(): remove CR %lx from SP %lx Queue\n",
-                   __FUNCTION__, cr_ptr, cr_ptr->sp_ptr);
-    /* Remove the CR from the queue */
-    dapl_sp_remove_cr (cr_ptr->sp_ptr, cr_ptr);
-
-    /*
-     * If this SP has been removed from service, free it
-     * up after the last CR is removed
-     */
-    dapl_os_lock (&cr_ptr->sp_ptr->header.lock);
-    if ( cr_ptr->sp_ptr->listening != DAT_TRUE && 
-         cr_ptr->sp_ptr->cr_list_count == 0 &&
-         cr_ptr->sp_ptr->state != DAPL_SP_STATE_FREE )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
-                      "--> DsCH: CR = %lx disconnect dump SP = %lx \n", 
-                      cr_ptr, cr_ptr->sp_ptr);
-        /* Decrement the ref count on the EVD */
-        if (cr_ptr->sp_ptr->evd_handle)
-        {
-            dapl_os_atomic_dec (& ((DAPL_EVD *)cr_ptr->sp_ptr->evd_handle)->evd_ref_count);
-            cr_ptr->sp_ptr->evd_handle = NULL;
-        }
-        cr_ptr->sp_ptr->state = DAPL_SP_STATE_FREE;
-        dapl_os_unlock (&cr_ptr->sp_ptr->header.lock);
-        (void)dapls_ib_remove_conn_listener ( cr_ptr->sp_ptr->header.owner_ia,
-                                              cr_ptr->sp_ptr );
-        dapls_ia_unlink_sp ( (DAPL_IA *)cr_ptr->sp_ptr->header.owner_ia,
-                             cr_ptr->sp_ptr );
-        dapls_sp_free_sp ( cr_ptr->sp_ptr );
-    }
-    else
-    {
-        dapl_os_unlock (&cr_ptr->sp_ptr->header.lock);
-    }
-
-    /*
-     * Clean up and dispose of the resource
-     */
-    dapls_cr_free (cr_ptr);
-
-    return (DAT_SUCCESS);
-}
-#endif
-
-int
-dapls_ib_private_data_size (
-	IN	DAPL_HCA		*hca_ptr)
-{
-    return IB_MAX_REQ_PDATA_SIZE;
-}
-
-
-/*
- * Local variables:
- *  c-indent-level: 4
- *  c-basic-offset: 4
- *  tab-width: 8
- * End:
- */
-
+
+/*
+ * Copyright (c) 2005-2007 Intel Corporation. All rights reserved.
+ * Copyright (c) 2002, Network Appliance, Inc. All rights reserved. 
+ * 
+ * This Software is licensed under the terms of the "Common Public
+ * License" a copy of which is in the file LICENSE.txt in the root
+ * directory. The license is also available from the Open Source
+ * Initiative, see http://www.opensource.org/licenses/cpl.php.
+ *
+ */
+
+/**********************************************************************
+ * 
+ * MODULE: dapl_ibal_cm.c
+ *
+ * PURPOSE: IB Connection routines for access to IBAL APIs
+ *
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_adapter_util.h"
+#include "dapl_evd_util.h"
+#include "dapl_cr_util.h"
+#include "dapl_sp_util.h"
+#include "dapl_ep_util.h"
+#include "dapl_ia_util.h"
+#include "dapl_ibal_util.h"
+#include "dapl_name_service.h"
+#include "dapl_ibal_name_service.h"
+#include "dapl_cookie.h"
+
+#define IB_INFINITE_SERVICE_LEASE   0xFFFFFFFF
+#define  DAPL_ATS_SERVICE_ID        ATS_SERVICE_ID //0x10000CE100415453
+#define  DAPL_ATS_NAME              ATS_NAME
+#define  HCA_IPV6_ADDRESS_LENGTH    16
+
+/* until dapl_ibal_util.h define of IB_INVALID_HANDLE which overlaps the
+ * Windows ib_types.h typedef enu ib_api_status_t IB_INVALID_HANDLE is fixed.
+ */
+#undef IB_INVALID_HANDLE
+#define DAPL_IB_INVALID_HANDLE NULL
+
+int g_dapl_loopback_connection = 0;
+extern dapl_ibal_root_t        dapl_ibal_root;
+
+static void dapli_ib_cm_drep_cb (
+	IN    ib_cm_drep_rec_t          *p_cm_drep_rec );
+
+/*
+ * Prototypes
+ */
+
+char *
+dapli_ib_cm_event_str(ib_cm_events_t e)
+{
+#if DBG
+    char        *cp;
+    static char *event_str[13] = {
+        "IB_CME_CONNECTED",
+        "IB_CME_DISCONNECTED",
+        "IB_CME_DISCONNECTED_ON_LINK_DOWN",
+        "IB_CME_CONNECTION_REQUEST_PENDING",
+        "IB_CME_CONNECTION_REQUEST_PENDING_PRIVATE_DATA",
+        "IB_CME_DESTINATION_REJECT",
+        "IB_CME_DESTINATION_REJECT_PRIVATE_DATA",
+        "IB_CME_DESTINATION_UNREACHABLE",
+        "IB_CME_TOO_MANY_CONNECTION_REQUESTS",
+        "IB_CME_LOCAL_FAILURE",
+        "IB_CME_REPLY_RECEIVED",
+        "IB_CME_REPLY_RECEIVED_PRIVATE_DATA",
+        "IB_CM_LOCAL_FAILURE"
+    };
+
+    if (e > IB_CM_LOCAL_FAILURE || e < IB_CME_CONNECTED)
+	cp =  "BAD EVENT";
+    else
+        cp = event_str[e];
+
+    return cp;
+#else
+    static char num[8];
+    sprintf(num,"%d",e);
+    return num;
+#endif
+}
+
+
+#if defined(DAPL_DBG)
+
+void dapli_print_private_data( char *prefix, const uint8_t *pd, int len )
+{
+    int i;
+            
+    if ( !pd || len <= 0 )
+	return;
+
+    dapl_log ( DAPL_DBG_TYPE_CM, "--> %s: private_data(len %d)\n    ",prefix,len);
+
+    if (len > IB_MAX_REP_PDATA_SIZE)
+    {
+    	dapl_log ( DAPL_DBG_TYPE_ERR,
+		"    Private data size(%d) > Max(%d), ignored.\n    ",
+					len,DAPL_MAX_PRIVATE_DATA_SIZE);
+	len = IB_MAX_REP_PDATA_SIZE;
+    }
+
+    for ( i = 0 ; i < len; i++ )
+    {
+	dapl_log ( DAPL_DBG_TYPE_CM, "%2x ", pd[i]);
+	if ( ((i+1) % 5) == 0 ) 
+	    dapl_log ( DAPL_DBG_TYPE_CM, "\n    ");
+    }
+   dapl_log ( DAPL_DBG_TYPE_CM, "\n");
+}
+#endif
+
+/* EP-CM linking support */
+dp_ib_cm_handle_t ibal_cm_alloc(void)
+{
+	dp_ib_cm_handle_t cm_ptr;
+
+	/* Allocate CM, init lock, and initialize */
+	if ((cm_ptr = dapl_os_alloc(sizeof(*cm_ptr))) == NULL)
+		return NULL;
+
+	(void)dapl_os_memzero(cm_ptr, sizeof(*cm_ptr));
+	cm_ptr->ref_count = 1;
+
+	if (dapl_os_lock_init(&cm_ptr->lock)) {
+		dapl_os_free(cm_ptr, sizeof(*cm_ptr));
+		return NULL;
+	}
+
+	dapl_llist_init_entry((DAPL_LLIST_ENTRY *)&cm_ptr->list_entry);
+	
+	return cm_ptr;
+}
+
+/* free CM object resources */
+static void ibal_cm_dealloc(dp_ib_cm_handle_t cm_ptr) 
+{
+	dapl_os_assert(!cm_ptr->ref_count);
+	dapl_os_lock_destroy(&cm_ptr->lock);
+	dapl_os_free(cm_ptr, sizeof(*cm_ptr));
+}
+
+void dapls_cm_acquire(dp_ib_cm_handle_t cm_ptr)
+{
+	dapl_os_lock(&cm_ptr->lock);
+	cm_ptr->ref_count++;
+	dapl_os_unlock(&cm_ptr->lock);
+}
+
+void dapls_cm_release(dp_ib_cm_handle_t cm_ptr)
+{
+	dapl_os_lock(&cm_ptr->lock);
+	cm_ptr->ref_count--;
+	if (cm_ptr->ref_count) {
+                dapl_os_unlock(&cm_ptr->lock);
+		return;
+	}
+	dapl_os_unlock(&cm_ptr->lock);
+	ibal_cm_dealloc(cm_ptr);
+}
+
+/* blocking: called from user thread dapl_ep_free() only */
+void dapls_cm_free(dp_ib_cm_handle_t cm_ptr)
+{
+	dapl_ep_unlink_cm(cm_ptr->ep, cm_ptr);
+
+	/* final reference, alloc */
+	dapls_cm_release(cm_ptr);
+}
+
+static void 
+dapli_ib_cm_apr_cb (
+        IN    ib_cm_apr_rec_t          *p_cm_apr_rec )
+{
+    UNUSED_PARAM( p_cm_apr_rec );
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> DiCAcb: CM callback APR (Alternate Path Request)\n");
+}
+
+static void 
+dapli_ib_cm_lap_cb (
+        IN    ib_cm_lap_rec_t          *p_cm_lap_rec )
+{
+    UNUSED_PARAM( p_cm_lap_rec );
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> DiCLcb: CM callback LAP (Load Alternate Path)\n");
+}
+
+static DAT_RETURN dapli_send_ib_cm_dreq(ib_cm_handle_t h_cm)
+{
+	ib_cm_dreq_t cm_dreq;
+
+	dapl_os_memzero(&cm_dreq, sizeof(ib_cm_dreq_t));
+
+	cm_dreq.flags = IB_FLAGS_SYNC;
+	cm_dreq.qp_type = IB_QPT_RELIABLE_CONN;
+	cm_dreq.h_qp = h_cm.h_qp;
+	cm_dreq.pfn_cm_drep_cb = dapli_ib_cm_drep_cb;
+
+	return dapl_ib_status_convert(ib_cm_dreq(&cm_dreq));
+}
+
+static DAT_RETURN dapli_send_ib_cm_drep(ib_cm_handle_t h_cm)
+{
+    ib_cm_drep_t cm_drep;
+
+    dapl_os_memzero(&cm_drep, sizeof(ib_cm_drep_t));
+	return dapl_ib_status_convert(ib_cm_drep(h_cm, &cm_drep));
+}
+
+/*
+ * Connection Disconnect Request callback
+ * We received a DREQ, return a DREP (disconnect reply).
+ */
+
+static void 
+dapli_ib_cm_dreq_cb (
+        IN    ib_cm_dreq_rec_t          *p_cm_dreq_rec )
+{
+    DAPL_EP             *ep_ptr;
+    dp_ib_cm_handle_t	cm_ptr;
+    
+    dapl_os_assert (p_cm_dreq_rec);
+
+    ep_ptr  = (DAPL_EP * __ptr64) p_cm_dreq_rec->qp_context;
+    if ( DAPL_BAD_PTR(ep_ptr) )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
+                      "--> %s: BAD_PTR EP %lx\n", __FUNCTION__, ep_ptr);
+        goto send_drep;
+    }
+    if ( ep_ptr->header.magic != DAPL_MAGIC_EP  )
+    {
+        if ( ep_ptr->header.magic == DAPL_MAGIC_INVALID )
+            goto send_drep;
+
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> %s: EP %p BAD_EP_MAGIC %x != wanted %x\n",
+		       __FUNCTION__, ep_ptr, ep_ptr->header.magic,
+		       DAPL_MAGIC_EP );
+        goto send_drep;
+    }
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+        goto send_drep;
+    }
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_dreq_rec->h_cm_dreq.h_qp);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> %s() EP %p, %s\n",
+                  __FUNCTION__,ep_ptr,
+                  dapl_get_ep_state_str(ep_ptr->param.ep_state));
+
+    dapl_os_lock (&ep_ptr->header.lock);
+    if ( ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                      "--> DiCDcb: EP %lx QP %lx already Disconnected\n",
+                      ep_ptr, ep_ptr->qp_handle);
+        goto unlock;
+    }
+
+    ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;
+
+    if (cm_ptr->state == IBAL_CM_CONNECT)
+    {
+	    cm_ptr->state = IBAL_CM_DREQ;
+	    cm_ptr->ib_cm = p_cm_dreq_rec->h_cm_dreq;
+    }
+    else
+    {
+	    dapli_send_ib_cm_drep(p_cm_dreq_rec->h_cm_dreq);
+    }
+    dapl_os_unlock (&ep_ptr->header.lock);
+
+    if (ep_ptr->cr_ptr)
+    {
+        /* passive side */
+        dapls_cr_callback ( cm_ptr,
+                            IB_CME_DISCONNECTED,
+                            (void * __ptr64) p_cm_dreq_rec->p_dreq_pdata,
+							IB_DREQ_PDATA_SIZE,
+                            (void *) (((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr) );
+    }
+    else
+    {
+        /* active side */
+        dapl_evd_connection_callback (
+                                  cm_ptr,
+                                  IB_CME_DISCONNECTED,
+                                  (void * __ptr64)
+                                  p_cm_dreq_rec->p_dreq_pdata,
+								  IB_DREQ_PDATA_SIZE,
+                                  p_cm_dreq_rec->qp_context );
+    }
+    return;
+
+unlock:
+	dapl_os_unlock (&ep_ptr->header.lock);
+send_drep:
+    dapli_send_ib_cm_drep(p_cm_dreq_rec->h_cm_dreq);
+}
+
+/*
+ * Connection Disconnect Reply callback
+ * We sent a DREQ and received a DREP.
+ */
+
+static void 
+dapli_ib_cm_drep_cb (
+        IN    ib_cm_drep_rec_t          *p_cm_drep_rec )
+{
+    DAPL_EP            *ep_ptr;
+    dp_ib_cm_handle_t	cm_ptr;
+    
+    dapl_os_assert (p_cm_drep_rec != NULL);
+
+    ep_ptr  = (DAPL_EP * __ptr64) p_cm_drep_rec->qp_context;
+
+    if (p_cm_drep_rec->cm_status)
+    {
+         dapl_dbg_log (DAPL_DBG_TYPE_CM,
+                  "--> %s: DREP cm_status(%s) EP=%p\n", __FUNCTION__,
+                  ib_get_err_str(p_cm_drep_rec->cm_status), ep_ptr); 
+    }
+
+    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
+    {
+         dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                  "--> %s: BAD EP Handle EP=%lx\n", __FUNCTION__,ep_ptr); 
+        return;
+    }
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+        return;
+    }
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_drep_rec->h_qp);
+    
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+		"--> DiCDpcb: EP %p state %s cm_hdl %p\n",ep_ptr,
+		dapl_get_ep_state_str(ep_ptr->param.ep_state), cm_ptr);
+
+    if ( ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
+                      "--> DiCDpcb: EP %lx QP %lx already Disconnected\n",
+                      ep_ptr, ep_ptr->qp_handle);
+        return;
+    }
+
+    if (ep_ptr->cr_ptr)
+    {
+        /* passive connection side */
+        dapls_cr_callback ( cm_ptr,
+                            IB_CME_DISCONNECTED,
+                           (void * __ptr64) p_cm_drep_rec->p_drep_pdata,
+						   IB_DREP_PDATA_SIZE,
+                           (void *) (((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr) );
+    }
+    else
+    {
+        /* active connection side */
+        dapl_evd_connection_callback (
+                                   cm_ptr,
+                                   IB_CME_DISCONNECTED,
+                                   (void * __ptr64) p_cm_drep_rec->p_drep_pdata,
+								   IB_DREP_PDATA_SIZE,
+                                   p_cm_drep_rec->qp_context );
+    }
+}
+
+/*
+ * CM reply callback
+ */
+
+static void 
+dapli_ib_cm_rep_cb (
+        IN    ib_cm_rep_rec_t          *p_cm_rep_rec )
+{
+    ib_api_status_t     ib_status; 
+    ib_cm_rtu_t         cm_rtu;
+    uint8_t             cm_cb_op;
+    DAPL_PRIVATE        *prd_ptr;
+    DAPL_EP             *ep_ptr;
+    dapl_ibal_ca_t      *p_ca;
+    dp_ib_cm_handle_t	cm_ptr;
+        
+    dapl_os_assert (p_cm_rep_rec != NULL);
+
+    ep_ptr  = (DAPL_EP * __ptr64) p_cm_rep_rec->qp_context;
+
+    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
+                      __FUNCTION__, ep_ptr);
+        return;
+    }
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+        return;
+    }
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rep_rec->h_cm_rep.h_qp);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> DiCRpcb: EP %lx local_max_rdma_read_in %d\n", 
+                  ep_ptr, p_cm_rep_rec->resp_res);
+
+    p_ca   = (dapl_ibal_ca_t *) 
+             ep_ptr->header.owner_ia->hca_ptr->ib_hca_handle;
+
+    dapl_os_memzero (&cm_rtu, sizeof ( ib_cm_rtu_t ));
+    cm_rtu.pfn_cm_apr_cb  = dapli_ib_cm_apr_cb;
+    cm_rtu.pfn_cm_dreq_cb = dapli_ib_cm_dreq_cb;
+    cm_rtu.p_rtu_pdata    = NULL;
+    cm_rtu.access_ctrl = 
+		IB_AC_LOCAL_WRITE|IB_AC_RDMA_WRITE|IB_AC_MW_BIND|IB_AC_ATOMIC;
+    if ((ep_ptr->param.ep_attr.max_rdma_read_in > 0) || 
+		(ep_ptr->param.ep_attr.max_rdma_read_out > 0))
+    {
+    	cm_rtu.access_ctrl |= IB_AC_RDMA_READ;
+    }
+	    
+    cm_rtu.rq_depth       = 0;
+    cm_rtu.sq_depth       = 0;
+       
+    ib_status = ib_cm_rtu (p_cm_rep_rec->h_cm_rep, &cm_rtu);
+
+    if (ib_status == IB_SUCCESS)
+    {
+        cm_cb_op = IB_CME_CONNECTED;
+        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> DiCRpcb: EP %lx Connected req_count %d\n", 
+                  ep_ptr, dapls_cb_pending(&ep_ptr->req_buffer));
+    }
+    else
+    {
+        cm_cb_op = IB_CME_LOCAL_FAILURE;
+    }
+
+    prd_ptr = (DAPL_PRIVATE * __ptr64) p_cm_rep_rec->p_rep_pdata;
+
+#if defined(DAPL_DBG) && 0
+    dapli_print_private_data( "DiCRpcb",
+			      prd_ptr->private_data,
+			      IB_MAX_REP_PDATA_SIZE);
+#endif
+
+    dapl_evd_connection_callback ( 
+                            cm_ptr,
+                            cm_cb_op,
+                            (void *) prd_ptr,
+			    IB_REP_PDATA_SIZE,
+                            (void * __ptr64) p_cm_rep_rec->qp_context);
+}
+
+
+static void 
+dapli_ib_cm_rej_cb (
+        IN    ib_cm_rej_rec_t          *p_cm_rej_rec )
+{
+    DAPL_EP         *ep_ptr;
+    ib_cm_events_t  cm_event;
+    dp_ib_cm_handle_t	cm_ptr;
+
+    dapl_os_assert (p_cm_rej_rec);
+
+    ep_ptr = (DAPL_EP * __ptr64) p_cm_rej_rec->qp_context;
+
+    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
+                      __FUNCTION__, ep_ptr);
+        return;
+    }
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+        return;
+    }
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rej_rec->h_qp);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "--> DiCRjcb: EP = %lx QP = %lx rej reason = 0x%x\n", 
+                  ep_ptr,ep_ptr->qp_handle,CL_NTOH16(p_cm_rej_rec->rej_status));
+
+    switch (p_cm_rej_rec->rej_status)
+    {
+        case IB_REJ_INSUF_RESOURCES:
+        case IB_REJ_INSUF_QP:
+        case IB_REJ_INVALID_COMM_ID:
+        case IB_REJ_INVALID_COMM_INSTANCE:
+        case IB_REJ_INVALID_PKT_RATE:
+        case IB_REJ_INVALID_ALT_GID:
+        case IB_REJ_INVALID_ALT_LID:
+        case IB_REJ_INVALID_ALT_SL:
+        case IB_REJ_INVALID_ALT_TRAFFIC_CLASS:
+        case IB_REJ_INVALID_ALT_PKT_RATE:
+        case IB_REJ_INVALID_ALT_HOP_LIMIT:
+        case IB_REJ_INVALID_ALT_FLOW_LBL:
+        case IB_REJ_INVALID_GID:
+        case IB_REJ_INVALID_LID:
+        case IB_REJ_INVALID_SID:
+        case IB_REJ_INVALID_SL:
+        case IB_REJ_INVALID_TRAFFIC_CLASS:
+        case IB_REJ_PORT_REDIRECT:
+        case IB_REJ_INVALID_MTU:
+        case IB_REJ_INSUFFICIENT_RESP_RES:
+        case IB_REJ_INVALID_CLASS_VER:
+        case IB_REJ_INVALID_FLOW_LBL:
+            cm_event = IB_CME_DESTINATION_REJECT;
+            break;
+
+        case IB_REJ_TIMEOUT:
+            cm_event = IB_CME_DESTINATION_UNREACHABLE;
+            dapl_dbg_log (DAPL_DBG_TYPE_CM, "--> DiCRjcb: CR TIMEOUT\n");
+            break;
+
+        case IB_REJ_USER_DEFINED:
+            cm_event = IB_CME_DESTINATION_REJECT;
+            dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                               "--> DiCRjcb: user defined rej reason %s\n",
+                               p_cm_rej_rec->p_ari);
+            break;
+
+        default:
+            cm_event = IB_CME_LOCAL_FAILURE;
+            dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                               "--> DiCRjcb: with unknown status %x\n", 
+                               p_cm_rej_rec->rej_status);
+            break;
+     }
+
+    /* FIXME - Vu
+     * We do not take care off the user defined rej reason with additional 
+     * rejection information (p_ari)
+     */
+
+    if (ep_ptr->cr_ptr)
+    {
+        dapls_cr_callback ( cm_ptr,
+                            cm_event,
+                            (void * __ptr64) p_cm_rej_rec->p_rej_pdata,
+			    IB_REJ_PDATA_SIZE,
+                            (void *) ((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr);
+    }
+    else
+    {
+        dapl_evd_connection_callback (
+                                   cm_ptr,
+                                   cm_event,
+                                   (void * __ptr64) p_cm_rej_rec->p_rej_pdata,
+				   IB_REJ_PDATA_SIZE,
+                                   (void * __ptr64) p_cm_rej_rec->qp_context );
+    }
+
+}
+
+
+
+static void 
+dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
+{
+    DAPL_SP              *sp_ptr;
+    DAT_SOCK_ADDR6       dest_ia_addr;
+    dp_ib_cm_handle_t    cm_ptr;
+
+    dapl_os_assert (p_cm_req_rec);
+
+    sp_ptr = (DAPL_SP * __ptr64) p_cm_req_rec->context;
+
+    dapl_os_assert (sp_ptr);
+
+    /*
+     * The context pointer could have been cleaned up in a racing
+     * CM callback, check to see if we should just exit here
+     */
+    if (sp_ptr->header.magic == DAPL_MAGIC_INVALID)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_CM,
+                     "%s: BAD-Magic in SP %lx, racing CM callback?\n",
+                      __FUNCTION__, sp_ptr );
+	return;
+    }
+
+    dapl_os_assert ( sp_ptr->header.magic == DAPL_MAGIC_PSP || 
+                     sp_ptr->header.magic == DAPL_MAGIC_RSP );
+
+    /* preserve ibal's connection handle storage so we have a consistent
+     * pointer value. The reasons this is done dynamically instead of a static
+     * allocation in an end_point is the pointer value is set in the SP list
+     * of CR's here and searched for from disconnect callbacks. If the pointer
+     * value changes, you never find the CR on the sp list...
+     * EP struct deallocation is where this memory is released or prior in the
+     * error case.
+     */
+    cm_ptr = ibal_cm_alloc();
+    if (!cm_ptr)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "%s: FAILED to alloc IB CM handle storage?\n",
+                       __FUNCTION__);
+        return;
+    }
+
+    /*
+     * Save the cm_srvc_handle to avoid the race condition between
+     * the return of the ib_cm_listen and the notification of a conn req
+     */
+    if (sp_ptr->cm_srvc_handle != p_cm_req_rec->h_cm_listen)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
+                           "--> DiCRqcb: cm_service_handle is changed\n"); 
+        sp_ptr->cm_srvc_handle = p_cm_req_rec->h_cm_listen;
+    }
+
+    dapl_os_memzero (&dest_ia_addr, sizeof (dest_ia_addr));
+
+#ifdef NO_NAME_SERVICE
+
+    {
+        DAPL_PRIVATE *prd_ptr;
+        
+        prd_ptr = (DAPL_PRIVATE *)p_cm_req_rec->p_req_pdata;
+
+        dapl_os_memcpy ((void *)&dest_ia_addr,
+                        (void *)&prd_ptr->hca_address,
+                        sizeof (DAT_SOCK_ADDR6));        
+    }
+    
+#else
+
+    {
+        GID            dest_gid;
+
+        dapl_os_memzero (&dest_gid, sizeof (dest_gid));
+
+        dest_gid.guid = p_cm_req_rec->primary_path.dgid.unicast.interface_id;
+        dest_gid.gid_prefix = p_cm_req_rec->primary_path.dgid.unicast.prefix;
+
+        if (DAT_SUCCESS != dapls_ns_map_ipaddr (
+                                 sp_ptr->header.owner_ia->hca_ptr,
+                                 dest_gid,
+                                 (DAT_IA_ADDRESS_PTR)&dest_ia_addr))
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "cm_req_cb: SP = %lx failed mapping GID-IPaddr\n",
+                           sp_ptr);
+        }
+    }
+
+#endif /* NO_NAME_SERVICE */
+
+    /* preserve CR cm handle data */
+    dapl_os_memcpy( (void*)&cm_ptr->ib_cm,
+                    (void*)&p_cm_req_rec->h_cm_req,
+                    sizeof(ib_cm_handle_t));
+
+    /* preserve remote IP address */
+    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,
+                    (void*)&dest_ia_addr,
+                    sizeof(dest_ia_addr));
+
+#if defined(DAPL_DBG)
+    {
+        char ipa[20];
+  
+        //rval = ((struct sockaddr_in *) (&dest_ia_addr))->sin_addr.s_addr;
+
+        dapl_dbg_log (DAPL_DBG_TYPE_CM|DAPL_DBG_TYPE_CALLBACK, 
+                      "%s: query SA (CM %lx)->dst_ip_addr: %s\n",
+                      __FUNCTION__,cm_ptr,
+                      dapli_get_ip_addr_str(
+				(DAT_SOCK_ADDR6*) &cm_ptr->dst_ip_addr, ipa) );
+    }
+#endif
+
+    /* FIXME - Vu
+     * We have NOT used/saved the primary and alternative path record
+     * ie. p_cm_req_rec->p_primary_path and p_cm_req_rec->p_alt_path
+     * We should cache some fields in path record in the Name Service DB
+     * such as: dgid, dlid
+     * Also we do not save resp_res (ie. max_oustanding_rdma_read/atomic)
+     * rnr_retry_cnt and flow_ctrl fields
+     */
+    dapl_dbg_log (DAPL_DBG_TYPE_CM,
+                  "%s: SP %lx max_rdma_read %d PrivateData %lx\n",
+                  __FUNCTION__, sp_ptr, p_cm_req_rec->resp_res,
+                  p_cm_req_rec->p_req_pdata);
+
+    dapls_cr_callback ( cm_ptr,
+                        IB_CME_CONNECTION_REQUEST_PENDING,
+                        (void * __ptr64) p_cm_req_rec->p_req_pdata,
+						IB_REQ_PDATA_SIZE,
+                        (void * __ptr64) sp_ptr );
+}
+
+
+static void 
+dapli_ib_cm_mra_cb (
+        IN    ib_cm_mra_rec_t          *p_cm_mra_rec )
+{
+	UNUSED_PARAM( p_cm_mra_rec );
+	dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
+                       "--> DiCMcb: CM callback MRA\n");
+}
+
+static void 
+dapli_ib_cm_rtu_cb (
+        IN    ib_cm_rtu_rec_t          *p_cm_rtu_rec )
+{
+    DAPL_EP         	*ep_ptr;
+    dp_ib_cm_handle_t	cm_ptr;
+
+    dapl_os_assert (p_cm_rtu_rec != NULL);
+   
+    ep_ptr = (DAPL_EP * __ptr64) p_cm_rtu_rec->qp_context;
+
+    if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: EP %lx invalid or FREED\n",
+                      __FUNCTION__, ep_ptr);
+        return;
+    }
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr)
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+        return;
+    }
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rtu_rec->h_qp);
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, 
+                  "--> DiCRucb: EP %lx QP %lx CR %lx\n",
+                  ep_ptr, ep_ptr->qp_handle, ep_ptr->cr_ptr); 
+
+    if (ep_ptr->cr_ptr)
+    {
+        DAPL_SP  *sp_ptr;
+
+        sp_ptr = ((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr;
+
+        /* passive connection side */
+        dapls_cr_callback ( cm_ptr,
+                            IB_CME_CONNECTED,
+                            (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,
+                            IB_RTU_PDATA_SIZE,
+                            (void *) sp_ptr);
+                            
+    }
+    else
+    {
+        dapl_evd_connection_callback ( 
+                            cm_ptr,
+                            IB_CME_CONNECTED,
+                            (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,
+			    IB_RTU_PDATA_SIZE,
+                            (void *) ep_ptr);
+    }
+}
+
+/*
+ * dapls_ib_cm_remote_addr
+ *
+ * Obtain the remote IP address given a connection
+ *
+ * Input:
+ *	cr_handle
+ *
+ * Output:
+ *	remote_ia_address: where to place the remote address
+ *
+ * Returns:
+ * 	DAT_SUCCESS
+ *	DAT_INVALID_HANDLE
+ *
+ */
+DAT_RETURN
+dapls_ib_cm_remote_addr (
+    IN      DAT_HANDLE          dat_handle,
+    OUT     DAT_SOCK_ADDR6      *remote_address )
+{
+
+    DAPL_HEADER        *header;
+    dp_ib_cm_handle_t  cm;
+    char               ipa[20];
+    char               *rtype;
+
+    header = (DAPL_HEADER *)dat_handle;
+
+    if (header->magic == DAPL_MAGIC_EP) 
+    {
+    	cm = dapl_get_cm_from_ep((DAPL_EP *)dat_handle);
+	rtype = "EP";
+    }
+    else if (header->magic == DAPL_MAGIC_CR) 
+    {
+    	cm = ((DAPL_CR *) dat_handle)->ib_cm_handle;
+	rtype = "CR";
+    }
+    else 
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_CM,
+                       "%s: hdr->magic %x, dat_handle(%lx)\n",
+                       __FUNCTION__, header->magic, dat_handle );
+    	return DAT_INVALID_HANDLE;
+    }
+
+    dapl_os_memcpy( remote_address, &cm->dst_ip_addr, sizeof(DAT_SOCK_ADDR6) );
+
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s: returns %s remote Addrs %s\n",
+                   __FUNCTION__, rtype,
+                   dapli_get_ip_addr_str((DAT_SOCK_ADDR6*)remote_address,ipa) );
+
+    return DAT_SUCCESS;
+}
+
+
+/*
+ * dapls_ib_connect
+ *
+ * Initiate a connection with the passive listener on another node
+ *
+ * Input:
+ *        ep_handle,
+ *        remote_ia_address,
+ *        remote_conn_qual,
+ *          prd_size                size of private data and structure
+ *          prd_prt                pointer to private data structure
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         DAT_SUCCESS
+ *        DAT_INSUFFICIENT_RESOURCES
+ *        DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_connect (
+        IN        DAT_EP_HANDLE                ep_handle,
+        IN        DAT_IA_ADDRESS_PTR           remote_ia_address,
+        IN        DAT_CONN_QUAL                remote_conn_qual,
+        IN        DAT_COUNT                    private_data_size,
+        IN        DAT_PVOID                    private_data )
+{
+    DAPL_EP                      *ep_ptr;
+    DAPL_IA                      *ia_ptr;
+    ib_api_status_t              ib_status;
+    dapl_ibal_port_t             *p_active_port;
+    dapl_ibal_ca_t               *p_ca;
+    ib_cm_req_t                  cm_req;
+    ib_path_rec_t                path_rec;
+    GID                          dest_GID;
+    ib_query_req_t               query_req;
+    ib_gid_pair_t                gid_pair;
+    ib_service_record_t          service_rec;
+    int                          retry_cnt;
+    DAT_RETURN                   dat_status;
+
+    ep_ptr         = (DAPL_EP *) ep_handle;
+    ia_ptr         = ep_ptr->header.owner_ia;
+    ep_ptr->cr_ptr = NULL;
+    retry_cnt      = 0;
+    dat_status     = DAT_SUCCESS;
+
+    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
+
+    /*
+     * We are using the first active port in the list for
+     * communication. We have to get back here when we decide to support
+     * fail-over and high-availability.
+     */
+    p_active_port = dapli_ibal_get_port ( p_ca,
+                                          (uint8_t)ia_ptr->hca_ptr->port_num );
+
+    if (NULL == p_active_port)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: Port %d not available %d\n",
+                       ia_ptr->hca_ptr->port_num, __LINE__ );
+        return (DAT_INVALID_STATE);
+    }
+
+    dapl_os_memzero (&dest_GID, sizeof (GID));
+    dapl_os_memzero (&cm_req, sizeof (ib_cm_req_t));
+    dapl_os_memzero (&path_rec, sizeof (ib_path_rec_t));
+    dapl_os_memzero (&service_rec, sizeof (ib_service_record_t));
+    dapl_os_memzero (&query_req, sizeof (ib_query_req_t));
+    dapl_os_memzero (&gid_pair, sizeof (ib_gid_pair_t));
+    dapl_os_memzero (&ep_ptr->remote_ia_address, sizeof (DAT_SOCK_ADDR6));
+
+    dapl_os_memcpy (&ep_ptr->remote_ia_address, 
+                    remote_ia_address, 
+                    sizeof (ep_ptr->remote_ia_address));
+
+
+#ifdef NO_NAME_SERVICE
+
+    if (DAT_SUCCESS !=
+        (dat_status = dapls_ns_lookup_address (
+                                         ia_ptr,
+                                         remote_ia_address,
+                                         &dest_GID         )))
+    {
+        /*
+         * Remote address not in the table, this is a
+         * strange return code!
+         */
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: exits status = %x\n", dat_status);
+        return dat_status;
+    }
+
+    dest_GID.guid = CL_HTON64 (dest_GID.guid);
+    dest_GID.gid_prefix = CL_HTON64 (dest_GID.gid_prefix);
+
+#else
+
+    /*
+     * We query the SA to get the dest_gid with the 
+     * {uDAPL_svc_id, IP-address} as the key to get GID.
+     */
+    if (DAT_SUCCESS !=
+        (dat_status = dapls_ns_map_gid (ia_ptr->hca_ptr, 
+                                        remote_ia_address,
+                                        &dest_GID)))
+        
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR, "--> DsC: fail to map remote_ia_addr "
+                       "(sa_family %d) to gid\n",
+                       remote_ia_address->sa_family); 
+        return dat_status;
+    }
+#endif /* NO_NAME_SERVICE */
+
+    gid_pair.dest_gid.unicast.interface_id = dest_GID.guid;
+    gid_pair.dest_gid.unicast.prefix       = dest_GID.gid_prefix;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                  "dapls_ib_connect: EP %lx QP %lx SERVER GID{0x" F64x
+                  ", 0x" F64x "}\n", 
+                  ep_ptr, ep_ptr->qp_handle,
+                  cl_hton64 (gid_pair.dest_gid.unicast.prefix),
+                  cl_hton64 (gid_pair.dest_gid.unicast.interface_id));
+
+    gid_pair.src_gid = p_active_port->p_attr->p_gid_table[0];
+/*
+    if ((gid_pair.src_gid.unicast.interface_id == 
+         gid_pair.dest_gid.unicast.interface_id   ) &&
+        (gid_pair.src_gid.unicast.prefix == 
+         gid_pair.dest_gid.unicast.prefix   ))
+    {
+        path_rec.dgid     = gid_pair.dest_gid;
+        path_rec.sgid     = gid_pair.src_gid;
+        path_rec.slid     = path_rec.dlid = p_active_port->p_attr->lid;
+        path_rec.pkey     = p_active_port->p_attr->p_pkey_table[0];
+        path_rec.mtu      = p_active_port->p_attr->mtu;
+		path_rec.pkt_life = 18;  // 1 sec
+		path_rec.rate     = IB_PATH_RECORD_RATE_10_GBS;
+	
+	}
+    else
+    {
+  */
+        /*
+         * Query SA to get the path record from pair of GIDs
+         */
+        dapl_os_memzero (&query_req, sizeof (ib_query_req_t));
+        query_req.query_type      = IB_QUERY_PATH_REC_BY_GIDS;
+        query_req.p_query_input   = (void *) &gid_pair;
+        query_req.flags           = IB_FLAGS_SYNC;  
+        query_req.timeout_ms      = 1 * 1000;       /* 1 second */
+        query_req.retry_cnt       = 3;
+        /* query SA using this port */
+        query_req.port_guid       = p_active_port->p_attr->port_guid;
+        query_req.query_context   = (void *) &path_rec;
+        query_req.pfn_query_cb    = dapli_ib_sa_query_cb;
+ 
+        ib_status = ib_query (dapl_ibal_root.h_al, &query_req, NULL);
+
+        if ((ib_status != IB_SUCCESS) || (!path_rec.dlid))
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"--> DsC: EP %lx QP %lx query "
+                           "pair_gids status = %s\n", 
+                           ep_ptr, ep_ptr->qp_handle,ib_get_err_str(ib_status));
+            return DAT_INVALID_PARAMETER;
+        }
+
+    //}
+
+	/*
+	 * Tavor has a HW bug that causes bandwidth with 2K MTU to be less than
+	 * with 1K MTU.  Cap the MTU based on device ID to compensate for this.
+	 */
+	if( (p_ca->p_ca_attr->dev_id == 0x5A44) &&
+		(ib_path_rec_mtu( &path_rec ) > IB_MTU_LEN_1024) )
+	{
+            /* Local endpoint is Tavor - cap MTU to 1K for extra bandwidth. */
+            path_rec.mtu &= IB_PATH_REC_SELECTOR_MASK;
+            path_rec.mtu |= IB_MTU_LEN_1024;
+	}
+
+	/* 
+     * prepare the Service ID from conn_qual 
+     */
+    cm_req.svc_id           = remote_conn_qual;
+    cm_req.p_primary_path   = &path_rec;
+    cm_req.p_alt_path       = NULL;
+    cm_req.h_qp             = ep_ptr->qp_handle;
+    cm_req.qp_type          = IB_QPT_RELIABLE_CONN;
+    cm_req.p_req_pdata      = (uint8_t *) private_data;
+    cm_req.req_length       = (uint8_t)
+				min(private_data_size,IB_MAX_REQ_PDATA_SIZE);
+    /* cm retry to send this request messages, IB max of 4 bits */
+    cm_req.max_cm_retries   = 15; /* timer outside of call, s/be infinite */
+    /* qp retry to send any wr */
+    cm_req.retry_cnt        = 5;
+    /* max num of oustanding RDMA read/atomic support */
+    cm_req.resp_res         = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_in;
+    /* max num of oustanding RDMA read/atomic will use */
+    cm_req.init_depth       = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_out;
+
+    /* time wait before retrying a pkt after receiving a RNR NAK */
+    cm_req.rnr_nak_timeout  = IB_RNR_NAK_TIMEOUT;
+    
+	/* 
+     * number of time local QP should retry after receiving RNR NACK before
+     * reporting an error
+     */
+    cm_req.rnr_retry_cnt       = IB_RNR_RETRY_CNT;
+
+    cm_req.remote_resp_timeout = 16;	/* 250ms */
+    cm_req.local_resp_timeout  = 16;	/* 250ms */
+    
+    cm_req.flow_ctrl           = TRUE;
+    cm_req.flags               = 0;
+    /*
+     * We do not use specific data buffer to check for specific connection
+     */
+    cm_req.p_compare_buffer    = NULL;
+    cm_req.compare_offset      = 0;
+    cm_req.compare_length      = 0;
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM, "--> DsConn: EP=%lx QP=%lx rio=%d,%d pl=%d "
+                  "mtu=%d slid=%#x dlid=%#x\n", 
+                  ep_ptr, ep_ptr->qp_handle,  cm_req.resp_res, 
+                  cm_req.init_depth, ib_path_rec_pkt_life(&path_rec),
+                  ib_path_rec_mtu(&path_rec),
+                  cm_req.p_primary_path->slid,
+                  cm_req.p_primary_path->dlid);
+
+    /*
+     * We do not support peer_to_peer; therefore, we set pfn_cm_req_cb = NULL
+     */
+    cm_req.pfn_cm_req_cb       = NULL;
+    cm_req.pfn_cm_rep_cb       = dapli_ib_cm_rep_cb;
+    cm_req.pfn_cm_rej_cb       = dapli_ib_cm_rej_cb;
+    /* callback when a message received acknowledgement is received */
+    cm_req.pfn_cm_mra_cb       = dapli_ib_cm_mra_cb;
+
+    ib_status = ib_cm_req (&cm_req);
+    
+    if ( ib_status != IB_SUCCESS )
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsC: EP %lx QP %lx conn_request failed = %s\n", 
+                       ep_ptr, ep_ptr->qp_handle, ib_get_err_str(ib_status));
+
+        return  (dapl_ib_status_convert (ib_status));
+    }
+
+    return DAT_SUCCESS;
+}
+
+
+/*
+ * dapls_ib_disconnect
+ *
+ * Disconnect an EP
+ *
+ * Input:
+ *        ep_handle,
+ *        disconnect_flags
+ *           DAT_CLOSE_ABRUPT_FLAG - no callback
+ *           DAT_CLOSE_GRACEFUL_FLAG - callback desired.
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *        DAT_SUCCESS
+ *        DAT_INSUFFICIENT_RESOURCES
+ *        DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_disconnect ( IN   DAPL_EP           *ep_ptr,
+                      IN   DAT_CLOSE_FLAGS   disconnect_flags )
+{
+	DAT_RETURN dat_status = DAT_SUCCESS;
+	ib_cm_dreq_t	cm_dreq;
+	dp_ib_cm_handle_t	cm_ptr;
+	ib_cm_handle_t h_cm;
+	enum dapl_ibal_cm_state state;
+
+	dapl_os_assert(ep_ptr);
+
+	if ( DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) )
+	{
+		dapl_dbg_log (DAPL_DBG_TYPE_CM,
+			"--> %s: BAD EP Magic EP=%lx\n", __FUNCTION__,ep_ptr); 
+		return DAT_SUCCESS;
+	}
+
+	cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+	if (!cm_ptr)
+	{
+		dapl_dbg_log (DAPL_DBG_TYPE_ERR, 
+			"--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);
+		return DAT_SUCCESS;
+	}
+ 
+	dapl_dbg_log (DAPL_DBG_TYPE_CM,
+		"--> %s() EP %p %s Close %s\n", __FUNCTION__,
+		ep_ptr, dapl_get_ep_state_str(ep_ptr->param.ep_state),
+		(disconnect_flags == DAT_CLOSE_ABRUPT_FLAG ? "Abrupt":"Graceful"));
+
+	//if ( disconnect_flags == DAT_CLOSE_ABRUPT_FLAG )
+	//{
+	//    dapl_dbg_log(DAPL_DBG_TYPE_CM,
+	//		"%s() calling legacy_post_disconnect()\n",__FUNCTION__);
+	//	dapl_ep_legacy_post_disconnect(ep_ptr, disconnect_flags);
+	//}
+
+	dapl_os_lock(&ep_ptr->header.lock);
+	if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED)
+	{
+		dapl_os_unlock(&ep_ptr->header.lock);
+		return dat_status;
+	}
+
+	h_cm = cm_ptr->ib_cm;
+	state = cm_ptr->state;
+	cm_ptr->state = IBAL_CM_DISCONNECT;
+	dapl_os_unlock(&ep_ptr->header.lock);
+
+	if (state == IBAL_CM_DREQ)
+		dapli_send_ib_cm_drep(h_cm);
+	else
+		dapli_send_ib_cm_dreq(cm_ptr->ib_cm);
+
+	return DAT_SUCCESS;
+}
+
+
+/*
+ * dapl_ib_setup_conn_listener
+ *
+ * Have the CM set up a connection listener.
+ *
+ * Input:
+ *        ibm_hca_handle           HCA handle
+ *        qp_handle                QP handle
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         DAT_SUCCESS
+ *        DAT_INSUFFICIENT_RESOURCES
+ *        DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_setup_conn_listener (
+        IN  DAPL_IA               *ia_ptr,
+        IN  DAT_UINT64            ServiceID,
+        IN  DAPL_SP               *sp_ptr )
+{
+    ib_api_status_t               ib_status;
+    ib_cm_listen_t                cm_listen;
+    dapl_ibal_ca_t                *p_ca;
+    dapl_ibal_port_t              *p_active_port;
+
+    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
+
+    /*
+     * We are using the first active port in the list for
+     * communication. We have to get back here when we decide to support
+     * fail-over and high-availability.
+     */
+    p_active_port = dapli_ibal_get_port( p_ca,
+					(uint8_t)ia_ptr->hca_ptr->port_num );
+
+    if (NULL == p_active_port)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"%s: SP %lx port %d not available\n",
+                __FUNCTION__, sp_ptr, ia_ptr->hca_ptr->port_num );
+        return (DAT_INVALID_STATE);
+    }
+
+    if (p_active_port->p_attr->lid == 0)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsSCL: SP %lx SID 0x" F64x " port %d\n", 
+                       sp_ptr, cl_hton64(ServiceID),
+                       p_active_port->p_attr->port_num);
+        return (DAT_INVALID_STATE);
+    }
+
+    dapl_dbg_log (DAPL_DBG_TYPE_CM,
+         "%s: SP %lx port %d GID{0x" F64x ", 0x" F64x "} and SID 0x" F64x "\n", 
+         __FUNCTION__,
+         sp_ptr, p_active_port->p_attr->port_num,
+         cl_hton64 (p_active_port->p_attr->p_gid_table[0].unicast.prefix),
+         cl_hton64 (p_active_port->p_attr->p_gid_table[0].unicast.interface_id),
+         cl_hton64 (ServiceID));
+    
+    dapl_os_memzero (&cm_listen, sizeof (ib_cm_listen_t));
+
+    /*
+     * Listen for all request on  this specific CA
+     */
+    cm_listen.ca_guid = (p_ca->p_ca_attr->ca_guid);
+    cm_listen.svc_id  = ServiceID;
+    cm_listen.qp_type = IB_QPT_RELIABLE_CONN; 
+
+    /*
+     * We do not use specific data buffer to check for specific connection
+     */
+    cm_listen.p_compare_buffer = NULL;//(uint8_t*)&sp_ptr->conn_qual;
+    cm_listen.compare_offset   = 0;//IB_MAX_REQ_PDATA_SIZE - sizeof(DAT_CONN_QUAL);
+    cm_listen.compare_length   = 0;//sizeof(DAT_CONN_QUAL);
+
+    /*
+     * We can pick a port here for communication and the others are reserved
+     * for fail-over / high-availability - TBD
+     */
+    cm_listen.port_guid     = p_active_port->p_attr->port_guid;
+    cm_listen.lid           = p_active_port->p_attr->lid;
+    cm_listen.pkey          = p_active_port->p_attr->p_pkey_table[0];
+
+    /*
+     * Register request or mra callback functions
+     */
+    cm_listen.pfn_cm_req_cb = dapli_ib_cm_req_cb;
+
+    ib_status = ib_cm_listen ( dapl_ibal_root.h_al,
+                               &cm_listen,
+                               (void *) sp_ptr,
+                               &sp_ptr->cm_srvc_handle );
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "%s: SP %lx SID 0x" F64x " listen failed %s\n", 
+                       __FUNCTION__, sp_ptr, cl_hton64 (ServiceID),
+                       ib_get_err_str(ib_status));
+    }
+
+    return dapl_ib_status_convert (ib_status);
+}
+
+
+/*
+ * dapl_ib_remove_conn_listener
+ *
+ * Have the CM remove a connection listener.
+ *
+ * Input:
+ *      ia_handle               IA handle
+ *      ServiceID               IB Channel Service ID
+ *
+ * Output:
+ *      none
+ *
+ * Returns:
+ *      DAT_SUCCESS
+ *      DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_remove_conn_listener (
+        IN  DAPL_IA        *ia_ptr,
+        IN  DAPL_SP        *sp_ptr )
+{
+    ib_api_status_t        ib_status;
+    DAT_RETURN             dat_status = DAT_SUCCESS;
+	
+    UNUSED_PARAM( ia_ptr );
+
+    dapl_os_assert ( sp_ptr );
+
+    dapl_os_assert ( sp_ptr->header.magic == DAPL_MAGIC_PSP ||
+         sp_ptr->header.magic == DAPL_MAGIC_RSP );
+
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s() cm_srvc_handle %lx\n",
+                   __FUNCTION__, sp_ptr->cm_srvc_handle );
+
+    if (sp_ptr->cm_srvc_handle)
+    {
+        ib_status = ib_cm_cancel ( sp_ptr->cm_srvc_handle, 
+                                   NULL );
+        
+        if (ib_status != IB_SUCCESS)
+        {
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "--> DsRCL: SP %lx ib_cm_cancel failed(0x%x) %s\n", 
+                           sp_ptr, sp_ptr->cm_srvc_handle,
+                           ib_get_err_str(ib_status));
+            sp_ptr->cm_srvc_handle = NULL;
+            return (DAT_INVALID_PARAMETER);
+        }
+
+        sp_ptr->cm_srvc_handle = NULL;
+    }
+
+    return dat_status;
+}
+
+/*
+ * dapls_ib_reject_connection
+ *
+ * Perform necessary steps to reject a connection
+ *
+ * Input:
+ *        cr_handle
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         DAT_SUCCESS
+ *        DAT_INSUFFICIENT_RESOURCES
+ *        DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_reject_connection ( IN  dp_ib_cm_handle_t   ib_cm_handle,
+                             IN  int                 reject_reason,
+                             IN  DAT_COUNT           private_data_size,
+                             IN  const DAT_PVOID     private_data)
+{
+    ib_api_status_t        ib_status;
+    ib_cm_rej_t            cm_rej;
+    static char            *rej_table[] =
+    {
+        "INVALID_REJ_REASON",
+        "INVALID_REJ_REASON",
+        "INVALID_REJ_REASON",
+        "INVALID_REJ_REASON",
+        "INVALID_REJ_REASON",
+        "IB_CME_DESTINATION_REJECT",
+        "IB_CME_DESTINATION_REJECT_PRIVATE_DATA",
+        "IB_CME_DESTINATION_UNREACHABLE",
+        "IB_CME_TOO_MANY_CONNECTION_REQUESTS",
+        "IB_CME_LOCAL_FAILURE",
+        "IB_CM_LOCAL_FAILURE"
+    };
+
+#define REJ_TABLE_SIZE  IB_CM_LOCAL_FAILURE
+
+    reject_reason = __min( reject_reason & 0xff, REJ_TABLE_SIZE);
+
+    cm_rej.rej_status   = IB_REJ_USER_DEFINED;
+    cm_rej.p_ari        = (ib_ari_t *)&rej_table[reject_reason]; 
+    cm_rej.ari_length   = (uint8_t)strlen (rej_table[reject_reason]);
+
+    cm_rej.p_rej_pdata  = private_data;
+    cm_rej.rej_length   = private_data_size;
+
+#if defined(DAPL_DBG) && 0
+    dapli_print_private_data("DsRjC",private_data,private_data_size);
+#endif
+
+    ib_status = ib_cm_rej(ib_cm_handle->ib_cm, &cm_rej);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsRjC: cm_handle %p reject failed %s\n", 
+                       ib_cm_handle, ib_get_err_str(ib_status) );
+    }
+
+    return ( dapl_ib_status_convert ( ib_status ) );
+}
+
+
+
+#if 0
+static void
+dapli_query_qp( ib_qp_handle_t qp_handle, ib_qp_attr_t  *qpa )
+{
+    ib_api_status_t        ib_status;
+    
+    ib_status = ib_query_qp ( qp_handle, qpa );
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,"ib_query_qp(%lx) '%s'\n",
+                qp_handle, ib_get_err_str(ib_status) );
+    }
+    else
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_CM, "--> QP(%lx) state %s "
+                       "type %d init %d acc %x\n",
+                       qp_handle,
+                       ib_get_port_state_str(qpa->state),
+                       qpa->qp_type,
+                       qpa->init_depth,
+                       qpa->access_ctrl );
+    }
+}
+#endif
+
+
+/*
+ * dapls_ib_accept_connection
+ *
+ * Perform necessary steps to accept a connection
+ *
+ * Input:
+ *        cr_handle
+ *        ep_handle
+ *        private_data_size
+ *        private_data
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         DAT_SUCCESS
+ *        DAT_INSUFFICIENT_RESOURCES
+ *        DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN
+dapls_ib_accept_connection (
+        IN        DAT_CR_HANDLE            cr_handle,
+        IN        DAT_EP_HANDLE            ep_handle,
+        IN        DAT_COUNT                private_data_size,
+        IN const  DAT_PVOID                private_data )
+{
+    DAPL_CR                *cr_ptr;
+    DAPL_EP                *ep_ptr;
+    DAPL_IA                *ia_ptr;
+    DAT_RETURN             dat_status;
+    ib_api_status_t        ib_status;
+    dapl_ibal_ca_t         *p_ca;
+    dapl_ibal_port_t       *p_active_port;
+    ib_cm_rep_t            cm_rep;
+    ib_qp_attr_t           qpa;
+    dp_ib_cm_handle_t      cm_ptr;
+
+    cr_ptr = (DAPL_CR *) cr_handle;
+    ep_ptr = (DAPL_EP *) ep_handle;
+    ia_ptr = ep_ptr->header.owner_ia;
+
+    if ( ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED )
+    {
+        /*
+         * If we are lazy attaching the QP then we may need to
+         * hook it up here. Typically, we run this code only for
+         * DAT_PSP_PROVIDER_FLAG
+         */
+        dat_status = dapls_ib_qp_alloc ( ia_ptr, ep_ptr, ep_ptr );
+
+        if ( dat_status != DAT_SUCCESS)
+        {
+            /* This is not a great error code, but all the spec allows */
+            dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                           "-->  DsIBAC: CR %lx EP %lx alloc QP failed 0x%x\n",
+                           cr_ptr, ep_ptr, dat_status );
+            return (dat_status);
+        }
+    }
+
+    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
+    p_active_port = dapli_ibal_get_port ( p_ca,
+                                          (uint8_t)ia_ptr->hca_ptr->port_num );
+    if (NULL == p_active_port)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIBAC: CR %lx EP %lx port %d is not available\n",
+                       cr_ptr, ep_ptr, ia_ptr->hca_ptr->port_num);
+        return (DAT_INVALID_STATE);
+    }
+
+    cr_ptr->param.local_ep_handle = ep_handle;
+
+    /*
+     * assume ownership, in that once the EP is released the dynamic
+     * memory containing the IBAL CM handle (ib_cm_handle_t) struct will
+     * be released; see dapl_ep_dealloc().
+     */
+   
+    /* EP-CM, save/release CR CM object, use EP CM object already linked */
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);
+    if (!cm_ptr) {
+	dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIBAC: CM linking to EP %p not available\n",
+                       ep_ptr);
+	return (DAT_INVALID_STATE);
+    }
+     
+    /* set remote IP addr fields. IP addr data is deduced from Connection
+     * Request record (gid/lib) and stashed away for use here. DAPL 1.1
+     * had an interface for passing the IP info down, interface went away
+     * in 2.0?
+     */
+    dapl_os_memcpy( (void*)&ep_ptr->remote_ia_address,
+                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,
+                    sizeof(DAT_SOCK_ADDR6) );
+
+    dapl_os_memcpy( (void*)&cr_ptr->remote_ia_address,
+                    (void*)&ep_ptr->remote_ia_address,
+                    sizeof(DAT_SOCK_ADDR6) );
+
+#if defined(DAPL_DBG)
+    {
+        char ipa[20];
+
+        dapl_dbg_log (DAPL_DBG_TYPE_CM|DAPL_DBG_TYPE_CALLBACK, 
+                      "%s: EP(%lx) RemoteAddr: %s\n",
+                      __FUNCTION__, ep_ptr,
+                     dapli_get_ip_addr_str(
+                            (DAT_SOCK_ADDR6*)&ep_ptr->remote_ia_address, ipa) );
+    }
+#endif
+
+    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,
+                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,
+                    sizeof(DAT_SOCK_ADDR6) );
+
+    /* get h_al and connection ID from CR CM object, h_qp already set */
+    cm_ptr->ib_cm.cid = cr_ptr->ib_cm_handle->ib_cm.cid; 
+    cm_ptr->ib_cm.h_al = cr_ptr->ib_cm_handle->ib_cm.h_al;
+    dapls_cm_release(cr_ptr->ib_cm_handle);
+
+    cr_ptr->ib_cm_handle = cm_ptr; /* for dapli_get_sp_ep() upcall */
+
+    ep_ptr->cr_ptr        = cr_ptr;
+
+    dapl_os_memzero ( (void*)&cm_rep, sizeof (ib_cm_rep_t) );
+
+    cm_rep.h_qp           = ep_ptr->qp_handle;
+    cm_rep.qp_type        = IB_QPT_RELIABLE_CONN;
+
+    if (private_data_size > IB_MAX_REP_PDATA_SIZE) {
+    	dapl_dbg_log (DAPL_DBG_TYPE_ERR,
+			"--> DsIBAC: private_data_size(%d) > Max(%d)\n",
+			private_data_size, IB_MAX_REP_PDATA_SIZE);
+	return DAT_ERROR(DAT_LENGTH_ERROR, DAT_NO_SUBTYPE);
+                                 
+        }
+    cm_rep.p_rep_pdata    = (const uint8_t *)private_data;
+    cm_rep.rep_length     = private_data_size;
+                            
+#if defined(DAPL_DBG) && 0
+    dapli_print_private_data( "DsIBAC",
+			      (const uint8_t*)private_data,
+ 			      private_data_size );
+#endif
+
+    cm_rep.pfn_cm_rej_cb = dapli_ib_cm_rej_cb;
+    cm_rep.pfn_cm_mra_cb = dapli_ib_cm_mra_cb;
+    cm_rep.pfn_cm_rtu_cb  = dapli_ib_cm_rtu_cb;
+    cm_rep.pfn_cm_lap_cb  = dapli_ib_cm_lap_cb;
+    cm_rep.pfn_cm_dreq_cb = dapli_ib_cm_dreq_cb;
+
+    /*
+     * FIXME - Vu
+     *         Pay attention to the attributes. 
+     *         Some of them are desirably set by DAT consumers
+     */
+    /*
+     * We enable the qp associate with this connection ep all the access right
+     * We enable the flow_ctrl, retry till success
+     * We will limit the access right and flow_ctrl upon DAT consumers 
+     * requirements
+     */
+    cm_rep.access_ctrl =
+		IB_AC_LOCAL_WRITE|IB_AC_RDMA_WRITE|IB_AC_MW_BIND|IB_AC_ATOMIC;
+
+    if ((ep_ptr->param.ep_attr.max_rdma_read_in > 0) 
+		|| (ep_ptr->param.ep_attr.max_rdma_read_out > 0))
+    {
+	cm_rep.access_ctrl |= IB_AC_RDMA_READ;
+    }
+
+    cm_rep.sq_depth          = 0;
+    cm_rep.rq_depth          = 0;
+    cm_rep.init_depth        = (uint8_t)ep_ptr->param.ep_attr.max_rdma_read_out;
+    cm_rep.flow_ctrl         = TRUE;
+    cm_rep.flags             = 0;
+    cm_rep.failover_accepted = IB_FAILOVER_ACCEPT_UNSUPPORTED;
+    cm_rep.target_ack_delay  = 14;
+    cm_rep.rnr_nak_timeout   = IB_RNR_NAK_TIMEOUT;
+    cm_rep.rnr_retry_cnt     = IB_RNR_RETRY_CNT;
+    cm_rep.pp_recv_failure   = NULL;
+    cm_rep.p_recv_wr         = NULL;
+     
+    dapl_dbg_log (DAPL_DBG_TYPE_CM,
+                 "--> DsIBAC: cm_rep: acc %x init %d qp_type %x req_count %d\n",
+	         cm_rep.access_ctrl, cm_rep.init_depth,cm_rep.qp_type,
+                 dapls_cb_pending(&ep_ptr->req_buffer));
+
+    ib_status = ib_cm_rep ( cm_ptr->ib_cm, &cm_rep );
+
+    if (ib_status != IB_SUCCESS)
+    {
+	dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsIBAC: EP %lx QP %lx CR reply failed '%s'\n",
+                       ep_ptr, ep_ptr->qp_handle, ib_get_err_str(ib_status) );
+    }
+ 
+    return ( dapl_ib_status_convert ( ib_status ) );
+}
+
+
+
+/*
+ * dapls_ib_disconnect_clean
+ *
+ * Clean up outstanding connection data. This routine is invoked
+ * after the final disconnect callback has occurred. Only on the
+ * ACTIVE side of a connection.
+ *
+ * Input:
+ *        ep_ptr                DAPL_EP
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         void
+ *
+ */
+void
+dapls_ib_disconnect_clean (
+        IN  DAPL_EP                     *ep_ptr,
+        IN  DAT_BOOLEAN                 active,
+        IN  const ib_cm_events_t        ib_cm_event )
+{
+    DAPL_IA		*ia_ptr;
+    ib_qp_attr_t	qp_attr;
+    ib_api_status_t     ib_status;
+
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s(%s): cm_event: %s \n", __FUNCTION__,
+                   (active?"A":"P"), dapli_ib_cm_event_str(ib_cm_event));
+
+    ia_ptr = ep_ptr->header.owner_ia;
+    
+    if ( ia_ptr == NULL || ia_ptr->header.magic != DAPL_MAGIC_IA )
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_CM,
+                       ">>>DSCONN_CLEAN(%s): cm_event: %s Invalid IA_ptr\n",
+                       (active?"Act":"Pas"),dapli_ib_cm_event_str(ib_cm_event));
+        return;
+    }
+    dapl_os_assert ( ep_ptr->header.magic == DAPL_MAGIC_EP );
+    
+    ib_status = ib_query_qp ( ep_ptr->qp_handle, &qp_attr );
+    if ( ib_status != IB_SUCCESS )
+    {
+	    dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       ">>>DSCONN_CLEAN(%s): Query QP failed = %s\n",
+                       (active?"Act":"Pas"),ib_get_err_str(ib_status) );
+		return;
+    }
+    
+    ep_ptr->qp_state = qp_attr.state;
+
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM, ">>>DSCONN_CLEAN(%s): cm_event: %d "
+                   "ep_ptr %lx ep_state %s qp_state %#x\n", 
+                   (active?"A":"P"), ib_cm_event, ep_ptr,
+                   dapl_get_ep_state_str(ep_ptr->param.ep_state),
+                   ep_ptr->qp_state );
+
+    if ( ep_ptr->qp_state != IB_QPS_ERROR &&
+         ep_ptr->qp_state != IB_QPS_RESET &&
+         ep_ptr->qp_state != IB_QPS_INIT )
+    {
+        ep_ptr->qp_state = IB_QPS_ERROR;
+        dapls_modify_qp_state_to_error (ep_ptr->qp_handle);
+    }
+}
+
+
+#ifdef NOT_USED
+/*
+ * dapls_ib_cr_handoff
+ *
+ * Hand off the connection request to another service point  
+ *
+ * Input:
+ *        cr_handle                DAT_CR_HANDLE
+ *        handoff_serv_id          DAT_CONN_QUAL
+ *
+ * Output:
+ *         none
+ *
+ * Returns:
+ *         DAT_SUCCESS
+ *         DAT_INVALID_PARAMETER
+ *
+ */
+DAT_RETURN 
+dapls_ib_cr_handoff (
+        IN  DAT_CR_HANDLE      cr_handle,
+        IN  DAT_CONN_QUAL      handoff_serv_id )
+{
+    DAPL_CR                *cr_ptr;
+    ib_api_status_t        ib_status;
+    
+    cr_ptr = (DAPL_CR *) cr_handle;
+
+    if (cr_ptr->ib_cm_handle->ib_cm.cid == 0xFFFFFFFF)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsCH: CR = %lx invalid cm handle\n", cr_ptr);
+        return DAT_INVALID_PARAMETER;
+    }
+
+    if (cr_ptr->sp_ptr == DAPL_IB_INVALID_HANDLE)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsCH: CR = %lx invalid psp handle\n", cr_ptr);
+        return DAT_INVALID_PARAMETER;
+    }
+
+    ib_status = ib_cm_handoff (cr_ptr->ib_cm_handle->ib_cm, handoff_serv_id);
+
+    if (ib_status != IB_SUCCESS)
+    {
+        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,
+                       "--> DsCH: CR = %lx handoff failed = %s\n", 
+                       cr_ptr, ib_get_err_str(ib_status) );
+
+        return dapl_ib_status_convert (ib_status);
+    }
+
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM,
+                   "--> %s(): remove CR %lx from SP %lx Queue\n",
+                   __FUNCTION__, cr_ptr, cr_ptr->sp_ptr);
+    /* Remove the CR from the queue */
+    dapl_sp_remove_cr (cr_ptr->sp_ptr, cr_ptr);
+
+    /*
+     * If this SP has been removed from service, free it
+     * up after the last CR is removed
+     */
+    dapl_os_lock (&cr_ptr->sp_ptr->header.lock);
+    if ( cr_ptr->sp_ptr->listening != DAT_TRUE && 
+         cr_ptr->sp_ptr->cr_list_count == 0 &&
+         cr_ptr->sp_ptr->state != DAPL_SP_STATE_FREE )
+    {
+        dapl_dbg_log (DAPL_DBG_TYPE_CM, 
+                      "--> DsCH: CR = %lx disconnect dump SP = %lx \n", 
+                      cr_ptr, cr_ptr->sp_ptr);
+        /* Decrement the ref count on the EVD */
+        if (cr_ptr->sp_ptr->evd_handle)
+        {
+            dapl_os_atomic_dec (& ((DAPL_EVD *)cr_ptr->sp_ptr->evd_handle)->evd_ref_count);
+            cr_ptr->sp_ptr->evd_handle = NULL;
+        }
+        cr_ptr->sp_ptr->state = DAPL_SP_STATE_FREE;
+        dapl_os_unlock (&cr_ptr->sp_ptr->header.lock);
+        (void)dapls_ib_remove_conn_listener ( cr_ptr->sp_ptr->header.owner_ia,
+                                              cr_ptr->sp_ptr );
+        dapls_ia_unlink_sp ( (DAPL_IA *)cr_ptr->sp_ptr->header.owner_ia,
+                             cr_ptr->sp_ptr );
+        dapls_sp_free_sp ( cr_ptr->sp_ptr );
+    }
+    else
+    {
+        dapl_os_unlock (&cr_ptr->sp_ptr->header.lock);
+    }
+
+    /*
+     * Clean up and dispose of the resource
+     */
+    dapls_cr_free (cr_ptr);
+
+    return (DAT_SUCCESS);
+}
+#endif
+
+int
+dapls_ib_private_data_size (
+	IN	DAPL_HCA		*hca_ptr)
+{
+    return IB_MAX_REQ_PDATA_SIZE;
+}
+
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 8
+ * End:
+ */
+
Index: ulp/netdirect2/user/netdirect.rc
===================================================================
--- ulp/netdirect2/user/netdirect.rc	(revision 3414)
+++ ulp/netdirect2/user/netdirect.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdefDBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"OpenFabrics Winverbs Network Direct Provider (Debug)"
 #define VER_INTERNALNAME_STR		"wvndprovd.dll"
 #define VER_ORIGINALFILENAME_STR	"wvndprovd.dll"
Index: ulp/libibmad/src/ibmad.rc
===================================================================
--- ulp/libibmad/src/ibmad.rc	(revision 3414)
+++ ulp/libibmad/src/ibmad.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"LibIbMad (Debug)"
 #define VER_INTERNALNAME_STR		"LibIbMadd.dll"
 #define VER_ORIGINALFILENAME_STR	"LibIbMadd.dll"
Index: ulp/srp/kernel/ibsrp.rc
===================================================================
--- ulp/srp/kernel/ibsrp.rc	(revision 3414)
+++ ulp/srp/kernel/ibsrp.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"InfiniBand SRP Miniport (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"InfiniBand SRP Miniport"
Index: ulp/ipoib_ndis5/kernel/ipoib.rc
===================================================================
--- ulp/ipoib_ndis5/kernel/ipoib.rc	(revision 3414)
+++ ulp/ipoib_ndis5/kernel/ipoib.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"IP over InfiniBand NDIS 5 Miniport (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"IP over InfiniBand NDIS 5 Miniport"
Index: ulp/qlgcvnic/kernel/inic.rc
===================================================================
--- ulp/qlgcvnic/kernel/inic.rc	(revision 3414)
+++ ulp/qlgcvnic/kernel/inic.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_DRV_NETWORK
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"QLogic VNIC NDIS Miniport (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"QLogic VNIC NDIS Miniport"
Index: tests/alts/kernel/alts.rc
===================================================================
--- tests/alts/kernel/alts.rc	(revision 3414)
+++ tests/alts/kernel/alts.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"InfiniBand Access Layer Test Driver (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"InfiniBand Access Layer Test Driver"
Index: tests/perftest/send_bw/send_bw.rc
===================================================================
--- tests/perftest/send_bw/send_bw.rc	(revision 3414)
+++ tests/perftest/send_bw/send_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Send/Recv Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Send/Recv Bandwidth Test "
Index: tests/perftest/write_bw/write_bw.rc
===================================================================
--- tests/perftest/write_bw/write_bw.rc	(revision 3414)
+++ tests/perftest/write_bw/write_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA write Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA write Bandwidth Test "
Index: tests/perftest/rdma_lat/rdma_lat.rc
===================================================================
--- tests/perftest/rdma_lat/rdma_lat.rc	(revision 3414)
+++ tests/perftest/rdma_lat/rdma_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Latency Test "
Index: tests/perftest/write_bw_postlist/write_bw_postlist.rc
===================================================================
--- tests/perftest/write_bw_postlist/write_bw_postlist.rc	(revision 3414)
+++ tests/perftest/write_bw_postlist/write_bw_postlist.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA_Write Post List BW Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA_Write Post List BW Test"
Index: tests/perftest/send_lat/send_lat.rc
===================================================================
--- tests/perftest/send_lat/send_lat.rc	(revision 3414)
+++ tests/perftest/send_lat/send_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - Send/Recv Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - Send/Recv Latency Test "
Index: tests/perftest/write_lat/write_lat.rc
===================================================================
--- tests/perftest/write_lat/write_lat.rc	(revision 3414)
+++ tests/perftest/write_lat/write_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA write Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA write Latency Test "
Index: tests/perftest/read_bw/read_bw.rc
===================================================================
--- tests/perftest/read_bw/read_bw.rc	(revision 3414)
+++ tests/perftest/read_bw/read_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA read Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA read Bandwidth Test "
Index: tests/perftest/rdma_bw/rdma_bw.rc
===================================================================
--- tests/perftest/rdma_bw/rdma_bw.rc	(revision 3414)
+++ tests/perftest/rdma_bw/rdma_bw.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Bandwidth Test "
Index: tests/perftest/read_lat/read_lat.rc
===================================================================
--- tests/perftest/read_lat/read_lat.rc	(revision 3414)
+++ tests/perftest/read_lat/read_lat.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA read Latency Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA read Latency Test "
Index: core/ibat/user/SOURCES
===================================================================
--- core/ibat/user/SOURCES	(revision 3414)
+++ core/ibat/user/SOURCES	(working copy)
@@ -9,5 +9,5 @@
 MSC_WARNING_LEVEL= /W4
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
-!endif
\ No newline at end of file
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
+!endif
Index: core/winmad/kernel/winmad.rc
===================================================================
--- core/winmad/kernel/winmad.rc	(revision 3414)
+++ core/winmad/kernel/winmad.rc	(working copy)
@@ -32,7 +32,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_DRV_SYSTEM
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Kernel WinMad (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Kernel WinMad"
Index: core/winmad/user/winmad.rc
===================================================================
--- core/winmad/user/winmad.rc	(revision 3414)
+++ core/winmad/user/winmad.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"WinMad (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"WinMad"
Index: core/winverbs/kernel/winverbs.rc
===================================================================
--- core/winverbs/kernel/winverbs.rc	(revision 3414)
+++ core/winverbs/kernel/winverbs.rc	(working copy)
@@ -32,7 +32,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_DRV_SYSTEM
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Kernel WinVerbs (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Kernel WinVerbs"
Index: core/winverbs/user/SOURCES
===================================================================
--- core/winverbs/user/SOURCES	(revision 3414)
+++ core/winverbs/user/SOURCES	(working copy)
@@ -30,7 +30,7 @@
 USER_C_FLAGS = $(USER_C_FLAGS) -DEXPORT_WV_SYMBOLS
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 TARGETLIBS = \
@@ -39,5 +39,3 @@
 	$(SDK_LIB_PATH)\ws2_32.lib      \
 	$(SDK_LIB_PATH)\iphlpapi.lib 	\
 	$(TARGETPATH)\*\ibat_ex.lib     \
-        $(TARGETPATH)\*\ibal.lib        \
-        $(TARGETPATH)\*\complib.lib
Index: core/winverbs/user/winverbs.rc
===================================================================
--- core/winverbs/user/winverbs.rc	(revision 3414)
+++ core/winverbs/user/winverbs.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE			VFT_DLL
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"WinVerbs (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"WinVerbs"
Index: core/complib/user/SOURCES
===================================================================
--- core/complib/user/SOURCES	(revision 3414)
+++ core/complib/user/SOURCES	(working copy)
@@ -43,7 +43,7 @@
 USER_C_FLAGS=$(USER_C_FLAGS) -DEXPORT_CL_SYMBOLS
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 TARGETLIBS=\
Index: core/complib/user/complib.rc
===================================================================
--- core/complib/user/complib.rc	(revision 3414)
+++ core/complib/user/complib.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Component Library (Debug)"
 #define VER_INTERNALNAME_STR		"complibd.dll"
 #define VER_ORIGINALFILENAME_STR	"complibd.dll"
Index: core/bus/kernel/ibbus.rc
===================================================================
--- core/bus/kernel/ibbus.rc	(revision 3414)
+++ core/bus/kernel/ibbus.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"InfiniBand Fabric Bus Driver (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"InfiniBand Fabric Bus Driver"
Index: core/ibat_ex/user/roce_at.h
===================================================================
--- core/ibat_ex/user/roce_at.h	(revision 3414)
+++ core/ibat_ex/user/roce_at.h	(working copy)
@@ -62,7 +62,7 @@
 #endif // _PREFAST_
 
 #ifndef CL_ASSERT
-#ifdef DBG
+#if DBG
 #define CL_ASSERT( exp )	(void)(!(exp)?OutputDebugString("Assertion Failed:" #exp "\n"),DebugBreak(),FALSE:TRUE);CONDITION_ASSUMED(exp)
 #else
 #define CL_ASSERT( exp )
Index: core/al/kernel/ibal.rc
===================================================================
--- core/al/kernel/ibal.rc	(revision 3414)
+++ core/al/kernel/ibal.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"Kernel Mode InfiniBand Access Layer (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"Kernel Mode InfiniBand Access Layer"
Index: core/al/al_ref_trace.c
===================================================================
--- core/al/al_ref_trace.c	(revision 3414)
+++ core/al/al_ref_trace.c	(working copy)
@@ -31,7 +31,7 @@
 
 #pragma warning(disable:4206) //nonstandard extension used : translation unit is empty
 
-#ifdef DBG
+#if DBG
 #include "al_ref_trace.h"
 #include "al_common.h"
 #include "al_debug.h"
Index: core/al/al_common.c
===================================================================
--- core/al/al_common.c	(revision 3414)
+++ core/al/al_common.c	(working copy)
@@ -163,7 +163,7 @@
 	p_obj->type = obj_type;
 	p_obj->timeout_ms = AL_DEFAULT_TIMEOUT_MS;
 	p_obj->ref_cnt = 1;
-#ifdef DBG
+#if DBG
 	ref_trace_init(p_obj);
 #endif
 	cl_event_construct( &p_obj->event );
@@ -262,7 +262,7 @@
 	p_obj->hdl = AL_INVALID_HANDLE;
 	cl_event_reset( &p_obj->event );
 	
-#ifdef DBG
+#if DBG
 	ref_trace_destroy(p_obj);
 	ref_trace_init(p_obj);
 #endif
@@ -496,7 +496,7 @@
 	cl_event_destroy( &p_obj->event );
 	cl_spinlock_destroy( &p_obj->lock );
 	
-#ifdef DBG
+#if DBG
 	ref_trace_destroy(p_obj);
 #endif
 
@@ -618,7 +618,7 @@
 					("IBAL stuck: AL object %s, ref_cnt: %d. Forcing object destruction.\n",
 					ib_get_obj_type( p_obj ), p_obj->ref_cnt));
 		}
-#ifdef DBG
+#if DBG
 
 		/* Print the ref count tracking */
 		if ( cl_status != CL_SUCCESS )
Index: core/al/al_common.h
===================================================================
--- core/al/al_common.h	(revision 3414)
+++ core/al/al_common.h	(working copy)
@@ -42,7 +42,7 @@
 #include <complib/cl_obj.h>
 #include <complib/cl_vector.h>
 
-#ifdef DBG
+#if DBG
 #include "al_ref_trace.h"
 #endif
 
@@ -269,7 +269,7 @@
 	cl_spinlock_t				lock;
 	cl_qlist_t					obj_list;
 	atomic32_t					ref_cnt;
-#ifdef DBG
+#if DBG
 	obj_ref_trace_t				ref_trace;
 #endif
 	cl_list_item_t				list_item;
@@ -343,7 +343,7 @@
 ref_al_obj_inner(
 	IN				al_obj_t * const			p_obj );
 
-#ifdef DBG
+#if DBG
 #define ref_ctx_al_obj(_p_obj_, ref_inx) 				\
 	ref_trace_insert(__FILE__, __LINE__,_p_obj_, AL_REF, ref_inx)
 #define ref_al_obj(_p_obj_) 	ref_ctx_al_obj(_p_obj_, 0)
@@ -367,7 +367,7 @@
 deref_al_obj_inner(
 	IN				al_obj_t * const			p_obj );
 
-#ifdef DBG
+#if DBG
 #define deref_ctx_al_obj(_p_obj_, ref_inx)						\
 	ref_trace_insert(__FILE__, __LINE__,_p_obj_, AL_DEREF, ref_inx) 
 	
Index: core/al/al_init.c
===================================================================
--- core/al/al_init.c	(revision 3414)
+++ core/al/al_init.c	(working copy)
@@ -44,7 +44,7 @@
 #include "ib_common.h"
 
 
-#ifdef DBG
+#if DBG
 #include "al_ref_trace.h"
 #endif
 
Index: core/al/user/ibal.rc
===================================================================
--- core/al/user/ibal.rc	(revision 3414)
+++ core/al/user/ibal.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"InfiniBand Access Layer (Debug)"
 #define VER_INTERNALNAME_STR		"ibald.dll"
 #define VER_ORIGINALFILENAME_STR	"ibald.dll"
Index: core/al/user/SOURCES
===================================================================
--- core/al/user/SOURCES	(revision 3414)
+++ core/al/user/SOURCES	(working copy)
@@ -80,7 +80,7 @@
 
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 !IFDEF ENABLE_EVENT_TRACING
Index: core/iou/kernel/ibiou.rc
===================================================================
--- core/iou/kernel/ibiou.rc	(revision 3414)
+++ core/iou/kernel/ibiou.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"InfiniBand I/O Unit Driver (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"InfiniBand I/O Unit Driver"
Index: OFED/WIX/SDK_Samples/rdma_bw/rdma_bw.rc
===================================================================
--- OFED/WIX/SDK_Samples/rdma_bw/rdma_bw.rc	(revision 3414)
+++ OFED/WIX/SDK_Samples/rdma_bw/rdma_bw.rc	(working copy)
@@ -37,7 +37,7 @@
 #define VER_FILETYPE			VFT_APP
 #define VER_FILESUBTYPE			VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Bandwidth Test (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"winverbs - RDMA Bandwidth Test "
Index: hw/mlx4/kernel/bus/net/net.rc
===================================================================
--- hw/mlx4/kernel/bus/net/net.rc	(revision 3414)
+++ hw/mlx4/kernel/bus/net/net.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"MLX4 Common HW Services (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"MLX4 Common HW Services"
Index: hw/mlx4/kernel/bus/core/core.rc
===================================================================
--- hw/mlx4/kernel/bus/core/core.rc	(revision 3414)
+++ hw/mlx4/kernel/bus/core/core.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"MLX4 Upper Layer (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"MLX4 Upper Layer"
Index: hw/mlx4/kernel/bus/ib/ib.rc
===================================================================
--- hw/mlx4/kernel/bus/ib/ib.rc	(revision 3414)
+++ hw/mlx4/kernel/bus/ib/ib.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"MLX4 InfiniBand Specific Services (Debug)"
 #else
 #define VER_FILEDESCRIPTION_STR		"MLX4 InfiniBand Specific Services"
Index: hw/mlx4/kernel/bus/drv/bus.rc
===================================================================
--- hw/mlx4/kernel/bus/drv/bus.rc	(revision 3414)
+++ hw/mlx4/kernel/bus/drv/bus.rc	(working copy)
@@ -7,7 +7,7 @@
 
 #ifndef HP_PROD
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "MLX4 Bus Driver (checked)"
 #else
 #define VER_FILEDESCRIPTION_STR     "MLX4 Bus Driver"
@@ -25,7 +25,7 @@
 #endif
 #define VER_COMPANYNAME_STR		"Hewlett-Packard"
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "HP Bus Driver (checked)"
 #else
 #define VER_FILEDESCRIPTION_STR     "HP Bus Driver"
Index: hw/mlx4/kernel/genutils/gu_hash.h
===================================================================
--- hw/mlx4/kernel/genutils/gu_hash.h	(revision 3414)
+++ hw/mlx4/kernel/genutils/gu_hash.h	(working copy)
@@ -46,7 +46,7 @@
          HashVal* hashVal = GetHashVal(Data);
          int index =  m_hashFunction(hashVal->m_keyType) % m_hashSize;
          
-#ifdef DBG
+#if DBG
          CEndPoint* p_TempEndPoint = (CEndPoint*)Get(hashVal);
          ASSERT(p_TempEndPoint == NULL);
 #endif
Index: hw/mlx4/kernel/hca/hca.rc
===================================================================
--- hw/mlx4/kernel/hca/hca.rc	(revision 3414)
+++ hw/mlx4/kernel/hca/hca.rc	(working copy)
@@ -32,7 +32,7 @@
 
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "MLX4 HCA Driver (checked)"
 #else
 #define VER_FILEDESCRIPTION_STR     "MLX4 HCA Driver"
Index: hw/mlx4/kernel/hca/data.h
===================================================================
--- hw/mlx4/kernel/hca/data.h	(revision 3414)
+++ hw/mlx4/kernel/hca/data.h	(working copy)
@@ -60,7 +60,7 @@
  */
 #define MLNX_COMP_MODEL		3
 
-#ifdef DBG
+#if DBG
 #define VALIDATE_INDEX(index, limit, error, label) \
 	{                  \
 		if (index >= limit) \
Index: hw/mlx4/user/hca/SOURCES
===================================================================
--- hw/mlx4/user/hca/SOURCES	(revision 3414)
+++ hw/mlx4/user/hca/SOURCES	(working copy)
@@ -46,11 +46,10 @@
 	$(SDK_LIB_PATH)\user32.lib \
 	$(SDK_LIB_PATH)\kernel32.lib \
 	$(SDK_LIB_PATH)\Advapi32.lib \
-        $(TARGETPATH)\*\complib.lib
+    $(TARGETPATH)\*\complib.lib \
 
-
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 #LINKER_FLAGS=/MAP /MAPINFO:LINES
Index: hw/mlx4/user/hca/mlx4u.rc
===================================================================
--- hw/mlx4/user/hca/mlx4u.rc	(revision 3414)
+++ hw/mlx4/user/hca/mlx4u.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR		"HCA User Mode Verb Provider (Debug)"
 #define VER_INTERNALNAME_STR		"mlx4u.dll"
 #define VER_ORIGINALFILENAME_STR	"mlx4u.dll"
Index: hw/mthca/kernel/hca.rc
===================================================================
--- hw/mthca/kernel/hca.rc	(revision 3414)
+++ hw/mthca/kernel/hca.rc	(working copy)
@@ -32,7 +32,7 @@
 
 #define VER_FILETYPE				VFT_DRV
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "HCA Driver (checked)"
 #else
 #define VER_FILEDESCRIPTION_STR     "HCA Driver"
Index: hw/mthca/kernel/hca_data.h
===================================================================
--- hw/mthca/kernel/hca_data.h	(revision 3414)
+++ hw/mthca/kernel/hca_data.h	(working copy)
@@ -73,7 +73,7 @@
  */
 #define MLNX_COMP_MODEL		3
 
-#ifdef DBG
+#if DBG
 #define VALIDATE_INDEX(index, limit, error, label) \
 	{                  \
 		if (index >= limit) \
Index: hw/mthca/user/mlnx_uvp.rc
===================================================================
--- hw/mthca/user/mlnx_uvp.rc	(revision 3414)
+++ hw/mthca/user/mlnx_uvp.rc	(working copy)
@@ -33,7 +33,7 @@
 #define VER_FILETYPE				VFT_DLL
 #define VER_FILESUBTYPE				VFT2_UNKNOWN
 
-#ifdef DBG
+#if DBG
 #define VER_FILEDESCRIPTION_STR     "HCA User Mode Verb Provider (checked)"
 #define VER_INTERNALNAME_STR		"mthcau.dll"
 #define VER_ORIGINALFILENAME_STR	"mthcau.dll"
Index: hw/mthca/user/SOURCES
===================================================================
--- hw/mthca/user/SOURCES	(revision 3414)
+++ hw/mthca/user/SOURCES	(working copy)
@@ -62,7 +62,7 @@
 
 
 !if !$(FREEBUILD)
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG
+C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG=1
 !endif
 
 #LINKER_FLAGS=/MAP /MAPINFO:LINES
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0.ifdefdbg.patch
Type: application/octet-stream
Size: 486481 bytes
Desc: 0.ifdefdbg.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20120619/23cc21b2/attachment.obj>


More information about the ofw mailing list