dapl2: update
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 4 Mar 2010 22:13:53 +0000 (22:13 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 4 Mar 2010 22:13:53 +0000 (22:13 +0000)
Update to commit 4b939076aa32bb52957fcc6791e187c9433d4c24 + ibal provider fixes for WOF2-2 support.  This synchronizes the trunk with the WOF2-2 branch.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2722 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

39 files changed:
ulp/dapl2/COPYING
ulp/dapl2/ChangeLog
ulp/dapl2/Makefile.am
ulp/dapl2/configure.in
ulp/dapl2/dapl.spec.in
ulp/dapl2/dapl/common/dapl_adapter_util.h
ulp/dapl2/dapl/common/dapl_cr_callback.c
ulp/dapl2/dapl/common/dapl_cr_util.c
ulp/dapl2/dapl/common/dapl_cr_util.h
ulp/dapl2/dapl/common/dapl_ep_connect.c
ulp/dapl2/dapl/common/dapl_ep_free.c
ulp/dapl2/dapl/common/dapl_ep_util.c
ulp/dapl2/dapl/common/dapl_ep_util.h
ulp/dapl2/dapl/common/dapl_evd_connection_callb.c
ulp/dapl2/dapl/common/dapl_evd_util.c
ulp/dapl2/dapl/common/dapl_evd_util.h
ulp/dapl2/dapl/common/dapl_ia_query.c
ulp/dapl2/dapl/ibal/dapl_ibal_cm.c
ulp/dapl2/dapl/ibal/dapl_ibal_qp.c
ulp/dapl2/dapl/ibal/dapl_ibal_util.h
ulp/dapl2/dapl/ibal/udapl.rc
ulp/dapl2/dapl/include/dapl.h
ulp/dapl2/dapl/openib_cma/cm.c
ulp/dapl2/dapl/openib_cma/dapl_ib_util.h
ulp/dapl2/dapl/openib_cma/device.c
ulp/dapl2/dapl/openib_cma/linux/openib_osd.h
ulp/dapl2/dapl/openib_cma/windows/openib_osd.h
ulp/dapl2/dapl/openib_common/dapl_ib_common.h
ulp/dapl2/dapl/openib_common/mem.c
ulp/dapl2/dapl/openib_common/qp.c
ulp/dapl2/dapl/openib_common/util.c
ulp/dapl2/dapl/openib_scm/cm.c
ulp/dapl2/dapl/openib_scm/dapl_ib_util.h
ulp/dapl2/dapl/openib_scm/device.c
ulp/dapl2/dapl/openib_ucm/cm.c
ulp/dapl2/dapl/openib_ucm/dapl_ib_util.h
ulp/dapl2/dapl/openib_ucm/device.c
ulp/dapl2/test/dapltest/scripts/dt-cli.bat
ulp/dapl2/test/dapltest/scripts/dt-svr.bat

index 2012c04..35ba319 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
 # Copyright (c) 2005 Voltaire Inc.  All rights reserved.
-# Copyright (c) 2005 Intel Corporation. All rights reserved.
+# Copyright (c) 2005-2010 Intel Corporation. All rights reserved.
 # Copyright (c) 2004-2005, Mellanox Technologies, Inc. All rights reserved. 
 # Copyright (c) 2003 Topspin Corporation.  All rights reserved. 
 # Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
@@ -9,19 +9,13 @@
 # This Software is licensed under one of the following licenses:
 #
 # 1) under the terms of the "Common Public License 1.0" 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.
+#    in the file LICENSE.txt in the root directory. 
 #
 # 2) under the terms of the "The BSD License" a copy of which is in the file
-#    LICENSE2.txt in the root directory. The license is also available from
-#    the Open Source Initiative, see
-#    http://www.opensource.org/licenses/bsd-license.php.
+#    LICENSE2.txt in the root directory. 
 #
 # 3) under the terms of the "GNU General Public License (GPL) Version 2" a 
-#    copy of which is in the file LICENSE3.txt in the root directory. The 
-#    license is also available from the Open Source Initiative, see
-#    http://www.opensource.org/licenses/gpl-license.php.
+#    copy of which is in the file LICENSE3.txt in the root directory. 
 #
 # Licensee has the right to choose one of the above licenses.
 #
@@ -32,5 +26,3 @@
 # notice, one of the license notices in the documentation
 # and/or other materials provided with the distribution.
 #
-
-
index ca4cb4f..abc9cc7 100644 (file)
@@ -1,3 +1,202 @@
+commit 454c27b1f357c7c3070e459b25d12929f86304ca
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Mon Feb 22 09:42:17 2010 -0800
+
+    windows: add scm makefile
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 66ac48d5280bcf0453760c6e22909de6b8519b6d
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Mon Feb 22 09:41:13 2010 -0800
+
+    Windows does not require rdma_cma_abi.h, move the include from common code and to OSD file.
+    
+    Signed-off-by: stan smith <stan.smith@intel.com>
+
+commit c05c41c31f01e1ddef91e92998ca66d258fafe3d
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Fri Feb 19 14:52:01 2010 -0800
+
+    Windows patch to fix IB_INVALID_HANDLE name collision
+    
+    signed-off-by: stan smith <stan.smith@intel.com>
+
+commit 712e7e5ba71f8a4344dfff481a9be870eefefe25
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Mon Feb 8 13:49:35 2010 -0800
+
+    scm: dat_ep_connect fails on 32bit servers
+    
+    memcpy for remote IA address uses incorrect sizeof for a pointer type.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 3040fa78d7d22c8f76c88dc77cedde09f016eb67
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Fri Feb 5 11:51:16 2010 -0800
+
+    undefined symbol: dapls_print_cm_list
+    
+    call prototype should be dependent on DAPL_COUNTERS.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit cbeebe422b952d679f49429be8ba045a62d7f4ac
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Fri Feb 5 11:39:21 2010 -0800
+
+    Cleanup CM object lock before freeing CM object memory
+    
+    Running windows application verifiier for uDAPL validation
+    for all 3 providers. Cleanup memory lock leaks found
+    by verifier.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 855a8e4aa83fa2e4f7847122415106f49286f4ca
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Wed Feb 3 16:21:30 2010 -0800
+
+    destroy verbs completion channels created via ia_open or ep_create.
+    
+    Completion channels are created with ia_open for CNO events and
+    with ep_create in cases where DAT allows EP(qp) to be created with
+    no EVD(cq) and IB doesn't. These completion channels need to be
+    destroyed at close along with a CQ for the EP without CQ case.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 4da540591148e47dd912851cc7314776f2f7622e
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Wed Feb 3 11:06:45 2010 -0800
+
+    Update Copyright file and include the 3 license files in distribution
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 9011abd4b1470c65bfe81eef5a2f3a81060cec81
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Tue Feb 2 14:43:03 2010 -0800
+
+    When copying private_data out of rdma_cm events, use the
+    reported private_data_len for the size, and not IB maximums.
+    This fixes a bug running over the librdmacm on windows, where
+    DAPL accessed invalid memory.
+    
+    Signed-off-by: Sean Hefty <sean.hefty@intel.com>
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 5da33bb3b9c230c08492f85d13caa330ce65906e
+Author: Sean Hefty <sean.hefty@intel.com>
+Date:   Thu Jan 28 10:19:20 2010 -0800
+
+    dapl/cma: fix referencing freed address
+    
+    DAPL uses a pointer to reference the local and remote addresses
+    of an endpoint.  It expects that those addresses are located
+    in memory that is always accessible.  Typically, for the local
+    address, the pointer references the address stored with the DAPL
+    HCA device.  However, for the cma provider, it changes this pointer
+    to reference the address stored with the rdma_cm_id.
+    
+    This causes a problem when that endpoint is connected on the
+    passive side of a connection.  When connect requests are given
+    to DAPL, a new rdma_cm_id is associated with the request.  The
+    DAPL code replaces the current rdma_cm_id associated with a
+    user's endpoint with the new rdma_cm_id.  The old rdma_cm_id is
+    then deleted.  But the endpoint's local address pointer still
+    references the address stored with the old rdma_cm_id.  The
+    result is that any reference to the address will access freed
+    memory.
+    
+    Fix this by keeping the local address pointer always pointing
+    to the address associated with the DAPL HCA device.  This is about
+    the best that can be done given the DAPL interface design.
+    
+    Signed-off-by: Sean Hefty <sean.hefty@intel.com>
+
+commit 66dbb5f20bf494eb3f5041655b478059165c5f1b
+Author: Sean Hefty <sean.hefty@intel.com>
+Date:   Tue Jan 26 15:13:03 2010 -0800
+
+    dapl: move close device after async thread is done
+    
+    using it
+    
+    Before calling ibv_close_device, wait for the asynchronous
+    processing thread to finish using the device.  This prevents
+    a use after free error.
+    
+    Signed-off-by: Sean Hefty <sean.hefty@intel.com>
+
+commit 560b235adc799fa710571ca63cbc3e4fa6374ff2
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Mon Jan 11 09:03:10 2010 -0800
+
+    Release 2.0.26-1
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 73dfb32ace6aff2fdb21e54689342fd551822286
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Tue Dec 22 14:00:33 2009 -0800
+
+    openib_common: add check for both gid and global routing in RTR
+    
+    check for valid gid pointer along with global route setting
+    during transition to RTR. Add more GID information to
+    debug print statement in qp modify call.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 7aab18fd8ff3f201b0a4b6c76896667b29f103c4
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Fri Dec 4 12:31:22 2009 -0800
+
+    openib_common: remote memory read privilege set multi times
+    
+    duplicate setting of read privilege in dapls_convert_privileges
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 016e2c40b8ac2fe18993e9fb7122ecb9b439e5eb
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Fri Dec 4 12:25:30 2009 -0800
+
+    ucm, scm: DAPL_GLOBAL_ROUTING enabled causes segv
+    
+    socket cm and ud cm providers support QP modify with is_global
+    set and GRH. New v2 providers didn't pass GID information
+    in modify_qp RTR call and incorrectly byte swapped the already
+    network order GID. Add debug print of GID during global modify.
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 7b0c596c7b4ad619f65da9f79dcbc4376e651dde
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Tue Nov 24 22:16:58 2009 -0800
+
+    Release 2.0.25-1
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 3197bffff478ad7ff5eff9220fa0528e42e6b56e
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Tue Nov 24 22:15:46 2009 -0800
+
+    winof scm: initialize opt for NODELAY setsockopt
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
+commit 8559ec069329249592f367b5b8f61427cbad0a46
+Author: Arlin Davis <arlin.r.davis@intel.com>
+Date:   Tue Nov 24 11:29:46 2009 -0800
+
+    Release 2.0.25
+    
+    Signed-off-by: Arlin Davis <arlin.r.davis@intel.com>
+
 commit 0983c66cbd9511128c1fa221470c4c983903e420
 Author: Arlin Davis <arlin.r.davis@intel.com>
 Date:   Tue Nov 24 08:58:44 2009 -0800
index 23f33e8..bf82853 100644 (file)
@@ -505,6 +505,9 @@ EXTRA_DIST = dat/common/dat_dictionary.h \
             dapl/udapl/libdaplofa.map \
             dapl/udapl/libdaploscm.map \
             dapl/udapl/libdaploucm.map \
+            LICENSE.txt \
+            LICENSE2.txt \
+            LICENSE3.txt \
             dapl.spec.in \
             $(man_MANS) \
             test/dapltest/include/dapl_bpool.h \
index c704145..0979cae 100644 (file)
@@ -1,11 +1,11 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.57)
-AC_INIT(dapl, 2.0.25, linux-rdma@vger.kernel.org)
+AC_INIT(dapl, 2.0.27, linux-rdma@vger.kernel.org)
 AC_CONFIG_SRCDIR([dat/udat/udat.c])
 AC_CONFIG_AUX_DIR(config)
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(dapl, 2.0.25)
+AM_INIT_AUTOMAKE(dapl, 2.0.27)
 
 AM_PROG_LIBTOOL
 
index ae20382..0f2c380 100644 (file)
@@ -121,7 +121,7 @@ fi
 %files
 %defattr(-,root,root,-)
 %{_libdir}/libda*.so.*
-%doc AUTHORS README ChangeLog
+%doc AUTHORS README COPYING ChangeLog LICENSE.txt LICENSE2.txt LICENSE3.txt
 
 %files devel
 %defattr(-,root,root,-)
@@ -140,6 +140,12 @@ fi
 %{_mandir}/man5/*.5*
 
 %changelog
+* Tue Feb 23 2010 Arlin Davis <ardavis@ichips.intel.com> - 2.0.27
+- DAT/DAPL Version 2.0.27 Release 1, OFED 1.5.1  
+
+* Tue Jan 11 2010 Arlin Davis <ardavis@ichips.intel.com> - 2.0.26
+- DAT/DAPL Version 2.0.26 Release 1, OFED 1.5, OFED 1.5-RDMAoE  
+
 * Tue Nov 24 2009 Arlin Davis <ardavis@ichips.intel.com> - 2.0.25
 - DAT/DAPL Version 2.0.25 Release 1, OFED 1.5 RC3 
 
index 4190eb8..92cb9b7 100644 (file)
-/*\r
- * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    in the file LICENSE.txt in the root directory. The license is also\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is in the file\r
- *    LICENSE2.txt in the root directory. The license is also available from\r
- *    the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a \r
- *    copy of which is in the file LICENSE3.txt in the root directory. The \r
- *    license is also available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- * \r
- * HEADER: dapl_adapter_util.h\r
- *\r
- * PURPOSE: Utility defs & routines for the adapter data structure\r
- *\r
- * $Id: dapl_adapter_util.h 1317 2005-04-25 17:29:42Z jlentini $\r
- *\r
- **********************************************************************/\r
-\r
-#ifndef _DAPL_ADAPTER_UTIL_H_\r
-#define _DAPL_ADAPTER_UTIL_H_\r
-\r
-\r
-typedef enum async_handler_type\r
-{\r
-    DAPL_ASYNC_UNAFILIATED,\r
-       DAPL_ASYNC_CQ_ERROR,\r
-       DAPL_ASYNC_CQ_COMPLETION,\r
-       DAPL_ASYNC_QP_ERROR\r
-} DAPL_ASYNC_HANDLER_TYPE;\r
-\r
-\r
-int dapls_ib_init (void);\r
-\r
-int dapls_ib_release (void);\r
-\r
-DAT_RETURN dapls_ib_enum_hcas (\r
-        IN   const char                 *vendor, \r
-       OUT  DAPL_HCA_NAME              **hca_names,\r
-       OUT  DAT_COUNT                  *total_hca_count);\r
-\r
-DAT_RETURN dapls_ib_get_instance_data(\r
-       IN  DAPL_HCA_NAME hca_name, \r
-       OUT char *instance);\r
-\r
-DAT_RETURN dapls_ib_open_hca (\r
-       IN   char                      *namestr,\r
-       IN   DAPL_HCA                  *hca_ptr);\r
-\r
-DAT_RETURN dapls_ib_close_hca (\r
-       IN   DAPL_HCA                  *hca_ptr);\r
-\r
-DAT_RETURN dapls_ib_qp_alloc (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EP                     *ep_ptr,\r
-       IN  DAPL_EP                     *ep_ctx_ptr);\r
-\r
-DAT_RETURN dapls_ib_qp_free (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EP                     *ep_ptr);\r
-\r
-DAT_RETURN dapls_ib_qp_modify (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EP                     *ep_ptr,\r
-       IN  DAT_EP_ATTR                 *ep_attr);\r
-\r
-DAT_RETURN dapls_ib_connect (\r
-       IN  DAT_EP_HANDLE               ep_handle,\r
-       IN  DAT_IA_ADDRESS_PTR          remote_ia_address,\r
-       IN  DAT_CONN_QUAL               remote_conn_qual,\r
-       IN  DAT_COUNT                   private_data_size,\r
-       IN  DAT_PVOID                   private_data);\r
-\r
-DAT_RETURN dapls_ib_disconnect (\r
-       IN  DAPL_EP                     *ep_ptr,\r
-       IN  DAT_CLOSE_FLAGS             close_flags);\r
-\r
-DAT_RETURN dapls_ib_setup_conn_listener (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAT_UINT64                  ServiceID,\r
-       IN  DAPL_SP                     *sp_ptr);\r
-\r
-DAT_RETURN dapls_ib_remove_conn_listener (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_SP                     *sp_ptr);\r
-\r
-DAT_RETURN dapls_ib_accept_connection (\r
-       IN  DAT_CR_HANDLE               cr_handle,\r
-       IN  DAT_EP_HANDLE               ep_handle,\r
-       IN  DAT_COUNT                   private_data_size,\r
-       IN  const DAT_PVOID             private_data);\r
-\r
-DAT_RETURN dapls_ib_reject_connection (\r
-       IN  dp_ib_cm_handle_t           cm_handle,\r
-       IN  int                         reject_reason,\r
-       IN  DAT_COUNT                   private_data_size,\r
-       IN  const DAT_PVOID             private_data);\r
-\r
-DAT_RETURN dapls_ib_setup_async_callback (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_ASYNC_HANDLER_TYPE     handler_type,\r
-       IN  DAPL_EVD                    *evd_ptr,\r
-       IN  ib_async_handler_t          callback,\r
-       IN  void                        *context);\r
-\r
-DAT_RETURN dapls_ib_cq_alloc (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EVD                    *evd_ptr,\r
-       IN  DAT_COUNT                   *cqlen);\r
-\r
-DAT_RETURN dapls_ib_cq_free (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EVD                    *evd_ptr);\r
-\r
-DAT_RETURN dapls_set_cq_notify (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EVD                    *evd_ptr);\r
-\r
-DAT_RETURN dapls_ib_cq_resize (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_EVD                    *evd_ptr,\r
-       IN  DAT_COUNT                   *cqlen);\r
-\r
-DAT_RETURN dapls_ib_pd_alloc (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       IN  DAPL_PZ                     *pz);\r
-\r
-DAT_RETURN dapls_ib_pd_free (\r
-       IN  DAPL_PZ                     *pz);\r
-\r
-DAT_RETURN dapls_ib_mr_register (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-        IN  DAPL_LMR                   *lmr,\r
-       IN  DAT_PVOID                   virt_addr,\r
-       IN  DAT_VLEN                    length,\r
-       IN  DAT_MEM_PRIV_FLAGS          privileges,\r
-       IN  DAT_VA_TYPE                 va_type);\r
-\r
-#if defined(__KDAPL__)\r
-DAT_RETURN dapls_ib_mr_register_physical (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-       INOUT  DAPL_LMR                 *lmr,\r
-       IN  DAT_PADDR                   phys_addr,\r
-       IN  DAT_VLEN                    length,\r
-       IN  DAT_MEM_PRIV_FLAGS          privileges);\r
-#endif /* __KDAPL__ */\r
-\r
-DAT_RETURN dapls_ib_mr_deregister (\r
-       IN  DAPL_LMR                    *lmr);\r
-\r
-DAT_RETURN dapls_ib_mr_register_shared (\r
-       IN  DAPL_IA                     *ia_ptr,\r
-        IN  DAPL_LMR                   *lmr,\r
-       IN  DAT_MEM_PRIV_FLAGS          privileges,\r
-       IN  DAT_VA_TYPE                 va_type);\r
-\r
-DAT_RETURN dapls_ib_mw_alloc (\r
-       IN  DAPL_RMR                    *rmr);\r
-\r
-DAT_RETURN dapls_ib_mw_free (\r
-       IN  DAPL_RMR                    *rmr);\r
-\r
-DAT_RETURN dapls_ib_mw_bind (\r
-       IN  DAPL_RMR                    *rmr,\r
-       IN  DAPL_LMR                    *lmr,\r
-       IN  DAPL_EP                     *ep,\r
-       IN  DAPL_COOKIE                 *cookie,\r
-       IN  DAT_VADDR                   virtual_address,\r
-       IN  DAT_VLEN                    length,\r
-       IN  DAT_MEM_PRIV_FLAGS          mem_priv,\r
-       IN  DAT_BOOLEAN                 is_signaled);\r
-\r
-DAT_RETURN dapls_ib_mw_unbind (\r
-       IN  DAPL_RMR                    *rmr,\r
-       IN  DAPL_EP                     *ep,\r
-       IN  DAPL_COOKIE                 *cookie,\r
-       IN  DAT_BOOLEAN                 is_signaled);\r
-\r
-DAT_RETURN dapls_ib_query_hca (\r
-       IN  DAPL_HCA                    *hca_ptr,\r
-       OUT DAT_IA_ATTR                 *ia_attr,\r
-       OUT DAT_EP_ATTR                 *ep_attr,\r
-       OUT DAT_SOCK_ADDR6              *ip_addr);\r
-\r
-DAT_RETURN dapls_ib_completion_poll (\r
-       IN  DAPL_HCA                    *hca_ptr,\r
-       IN  DAPL_EVD                    *evd_ptr,\r
-       IN  ib_work_completion_t        *cqe_ptr);\r
-\r
-DAT_RETURN dapls_ib_completion_notify (\r
-       IN  ib_hca_handle_t             hca_handle,\r
-       IN  DAPL_EVD                    *evd_ptr,\r
-       IN  ib_notification_type_t      type);\r
-\r
-DAT_DTO_COMPLETION_STATUS dapls_ib_get_dto_status (\r
-       IN  ib_work_completion_t        *cqe_ptr);\r
-\r
-void dapls_ib_reinit_ep (\r
-       IN  DAPL_EP                     *ep_ptr);\r
-\r
-void dapls_ib_disconnect_clean (\r
-       IN  DAPL_EP                     *ep_ptr,\r
-       IN  DAT_BOOLEAN                 passive,\r
-       IN  const ib_cm_events_t        ib_cm_event);\r
-\r
-DAT_RETURN dapls_ib_get_async_event (\r
-       IN  ib_error_record_t           *cause_ptr,\r
-       OUT DAT_EVENT_NUMBER            *async_event);\r
-\r
-DAT_EVENT_NUMBER dapls_ib_get_dat_event (\r
-       IN  const ib_cm_events_t        ib_cm_event,\r
-       IN  DAT_BOOLEAN                 active);\r
-\r
-ib_cm_events_t dapls_ib_get_cm_event (\r
-       IN  DAT_EVENT_NUMBER            dat_event_num);\r
-\r
-DAT_RETURN dapls_ib_cm_remote_addr (\r
-       IN  DAT_HANDLE                  dat_handle,\r
-       OUT DAT_SOCK_ADDR6              *remote_ia_address);\r
-\r
-int dapls_ib_private_data_size(\r
-       IN DAPL_HCA                     *hca_ptr);\r
-\r
-void \r
-dapls_query_provider_specific_attr(\r
-       IN DAPL_IA                      *ia_ptr,\r
-       IN DAT_PROVIDER_ATTR            *attr_ptr );\r
-\r
-DAT_RETURN\r
-dapls_evd_dto_wakeup (\r
-       IN DAPL_EVD                     *evd_ptr);\r
-\r
-DAT_RETURN\r
-dapls_evd_dto_wait (\r
-       IN DAPL_EVD                     *evd_ptr,\r
-       IN uint32_t                     timeout);\r
-\r
-#ifdef DAT_EXTENSIONS\r
-void\r
-dapls_cqe_to_event_extension(\r
-       IN DAPL_EP                      *ep_ptr,\r
-       IN DAPL_COOKIE                  *cookie,\r
-       IN ib_work_completion_t         *cqe_ptr,\r
-       IN DAT_EVENT                    *event_ptr);\r
-#endif\r
-\r
-/*\r
- * Values for provider DAT_NAMED_ATTR\r
- */\r
-#define IB_QP_STATE            1       /* QP state change request */\r
-\r
-\r
-#ifdef IBAPI\r
-#include "dapl_ibapi_dto.h"\r
-#elif VAPI\r
-#include "dapl_vapi_dto.h"\r
-#elif __OPENIB__\r
-#include "dapl_openib_dto.h"\r
-#elif DUMMY\r
-#include "dapl_dummy_dto.h"\r
-#elif OPENIB\r
-#include "dapl_ib_dto.h"\r
-#else\r
-#include "dapl_ibal_dto.h"\r
-#endif\r
-\r
-\r
-#endif /*  _DAPL_ADAPTER_UTIL_H_ */\r
+/*
+ * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" 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.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is in the file
+ *    LICENSE2.txt in the root directory. The license is also available from
+ *    the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a 
+ *    copy of which is in the file LICENSE3.txt in the root directory. The 
+ *    license is also available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ * 
+ * HEADER: dapl_adapter_util.h
+ *
+ * PURPOSE: Utility defs & routines for the adapter data structure
+ *
+ * $Id: dapl_adapter_util.h 1317 2005-04-25 17:29:42Z jlentini $
+ *
+ **********************************************************************/
+
+#ifndef _DAPL_ADAPTER_UTIL_H_
+#define _DAPL_ADAPTER_UTIL_H_
+
+
+typedef enum async_handler_type
+{
+    DAPL_ASYNC_UNAFILIATED,
+       DAPL_ASYNC_CQ_ERROR,
+       DAPL_ASYNC_CQ_COMPLETION,
+       DAPL_ASYNC_QP_ERROR
+} DAPL_ASYNC_HANDLER_TYPE;
+
+
+int dapls_ib_init (void);
+
+int dapls_ib_release (void);
+
+DAT_RETURN dapls_ib_enum_hcas (
+        IN   const char                 *vendor, 
+       OUT  DAPL_HCA_NAME              **hca_names,
+       OUT  DAT_COUNT                  *total_hca_count);
+
+DAT_RETURN dapls_ib_get_instance_data(
+       IN  DAPL_HCA_NAME hca_name, 
+       OUT char *instance);
+
+DAT_RETURN dapls_ib_open_hca (
+       IN   char                      *namestr,
+       IN   DAPL_HCA                  *hca_ptr);
+
+DAT_RETURN dapls_ib_close_hca (
+       IN   DAPL_HCA                  *hca_ptr);
+
+DAT_RETURN dapls_ib_qp_alloc (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EP                     *ep_ptr,
+       IN  DAPL_EP                     *ep_ctx_ptr);
+
+DAT_RETURN dapls_ib_qp_free (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EP                     *ep_ptr);
+
+DAT_RETURN dapls_ib_qp_modify (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EP                     *ep_ptr,
+       IN  DAT_EP_ATTR                 *ep_attr);
+
+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);
+
+DAT_RETURN dapls_ib_disconnect (
+       IN  DAPL_EP                     *ep_ptr,
+       IN  DAT_CLOSE_FLAGS             close_flags);
+
+DAT_RETURN dapls_ib_setup_conn_listener (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAT_UINT64                  ServiceID,
+       IN  DAPL_SP                     *sp_ptr);
+
+DAT_RETURN dapls_ib_remove_conn_listener (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_SP                     *sp_ptr);
+
+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);
+
+DAT_RETURN dapls_ib_reject_connection (
+       IN  dp_ib_cm_handle_t           cm_handle,
+       IN  int                         reject_reason,
+       IN  DAT_COUNT                   private_data_size,
+       IN  const DAT_PVOID             private_data);
+
+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);
+
+DAT_RETURN dapls_ib_cq_alloc (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EVD                    *evd_ptr,
+       IN  DAT_COUNT                   *cqlen);
+
+DAT_RETURN dapls_ib_cq_free (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EVD                    *evd_ptr);
+
+DAT_RETURN dapls_set_cq_notify (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EVD                    *evd_ptr);
+
+DAT_RETURN dapls_ib_cq_resize (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_EVD                    *evd_ptr,
+       IN  DAT_COUNT                   *cqlen);
+
+DAT_RETURN dapls_ib_pd_alloc (
+       IN  DAPL_IA                     *ia_ptr,
+       IN  DAPL_PZ                     *pz);
+
+DAT_RETURN dapls_ib_pd_free (
+       IN  DAPL_PZ                     *pz);
+
+DAT_RETURN dapls_ib_mr_register (
+       IN  DAPL_IA                     *ia_ptr,
+        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);
+
+#if defined(__KDAPL__)
+DAT_RETURN dapls_ib_mr_register_physical (
+       IN  DAPL_IA                     *ia_ptr,
+       INOUT  DAPL_LMR                 *lmr,
+       IN  DAT_PADDR                   phys_addr,
+       IN  DAT_VLEN                    length,
+       IN  DAT_MEM_PRIV_FLAGS          privileges);
+#endif /* __KDAPL__ */
+
+DAT_RETURN dapls_ib_mr_deregister (
+       IN  DAPL_LMR                    *lmr);
+
+DAT_RETURN dapls_ib_mr_register_shared (
+       IN  DAPL_IA                     *ia_ptr,
+        IN  DAPL_LMR                   *lmr,
+       IN  DAT_MEM_PRIV_FLAGS          privileges,
+       IN  DAT_VA_TYPE                 va_type);
+
+DAT_RETURN dapls_ib_mw_alloc (
+       IN  DAPL_RMR                    *rmr);
+
+DAT_RETURN dapls_ib_mw_free (
+       IN  DAPL_RMR                    *rmr);
+
+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  DAT_BOOLEAN                 is_signaled);
+
+DAT_RETURN dapls_ib_mw_unbind (
+       IN  DAPL_RMR                    *rmr,
+       IN  DAPL_EP                     *ep,
+       IN  DAPL_COOKIE                 *cookie,
+       IN  DAT_BOOLEAN                 is_signaled);
+
+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);
+
+DAT_RETURN dapls_ib_completion_poll (
+       IN  DAPL_HCA                    *hca_ptr,
+       IN  DAPL_EVD                    *evd_ptr,
+       IN  ib_work_completion_t        *cqe_ptr);
+
+DAT_RETURN dapls_ib_completion_notify (
+       IN  ib_hca_handle_t             hca_handle,
+       IN  DAPL_EVD                    *evd_ptr,
+       IN  ib_notification_type_t      type);
+
+DAT_DTO_COMPLETION_STATUS dapls_ib_get_dto_status (
+       IN  ib_work_completion_t        *cqe_ptr);
+
+void dapls_ib_reinit_ep (
+       IN  DAPL_EP                     *ep_ptr);
+
+void dapls_ib_disconnect_clean (
+       IN  DAPL_EP                     *ep_ptr,
+       IN  DAT_BOOLEAN                 passive,
+       IN  const ib_cm_events_t        ib_cm_event);
+
+DAT_RETURN dapls_ib_get_async_event (
+       IN  ib_error_record_t           *cause_ptr,
+       OUT DAT_EVENT_NUMBER            *async_event);
+
+DAT_EVENT_NUMBER dapls_ib_get_dat_event (
+       IN  const ib_cm_events_t        ib_cm_event,
+       IN  DAT_BOOLEAN                 active);
+
+ib_cm_events_t dapls_ib_get_cm_event (
+       IN  DAT_EVENT_NUMBER            dat_event_num);
+
+DAT_RETURN dapls_ib_cm_remote_addr (
+       IN  DAT_HANDLE                  dat_handle,
+       OUT DAT_SOCK_ADDR6              *remote_ia_address);
+
+int dapls_ib_private_data_size(
+       IN DAPL_HCA                     *hca_ptr);
+
+void 
+dapls_query_provider_specific_attr(
+       IN DAPL_IA                      *ia_ptr,
+       IN DAT_PROVIDER_ATTR            *attr_ptr );
+
+DAT_RETURN
+dapls_evd_dto_wakeup (
+       IN DAPL_EVD                     *evd_ptr);
+
+DAT_RETURN
+dapls_evd_dto_wait (
+       IN DAPL_EVD                     *evd_ptr,
+       IN uint32_t                     timeout);
+
+#ifdef DAT_EXTENSIONS
+void
+dapls_cqe_to_event_extension(
+       IN DAPL_EP                      *ep_ptr,
+       IN DAPL_COOKIE                  *cookie,
+       IN ib_work_completion_t         *cqe_ptr,
+       IN DAT_EVENT                    *event_ptr);
+#endif
+
+/*
+ * Values for provider DAT_NAMED_ATTR
+ */
+#define IB_QP_STATE            1       /* QP state change request */
+
+
+#ifdef IBAPI
+#include "dapl_ibapi_dto.h"
+#elif VAPI
+#include "dapl_vapi_dto.h"
+#elif __OPENIB__
+#include "dapl_openib_dto.h"
+#elif DUMMY
+#include "dapl_dummy_dto.h"
+#elif OPENIB
+#include "dapl_ib_dto.h"
+#else
+#include "dapl_ibal_dto.h"
+#endif
+
+
+#endif /*  _DAPL_ADAPTER_UTIL_H_ */
index 6268cc6..3997b38 100644 (file)
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- *\r
- * MODULE: dapls_cr_callback.c\r
- *\r
- * PURPOSE: implements passive side connection callbacks\r
- *\r
- * Description: Accepts asynchronous callbacks from the Communications Manager\r
- *              for EVDs that have been specified as the connection_evd.\r
- *\r
- * $Id:$\r
- **********************************************************************/\r
-\r
-#include "dapl.h"\r
-#include "dapl_evd_util.h"\r
-#include "dapl_cr_util.h"\r
-#include "dapl_ia_util.h"\r
-#include "dapl_sp_util.h"\r
-#include "dapl_ep_util.h"\r
-#include "dapl_adapter_util.h"\r
-\r
-/*\r
- * Prototypes\r
- */\r
-DAT_RETURN dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,\r
-                                   IN DAPL_SP * sp_ptr,\r
-                                   IN DAPL_PRIVATE * prd_ptr,\r
-                                   IN int private_data_size,\r
-                                   IN DAPL_EVD * evd_ptr);\r
-\r
-DAPL_EP *dapli_get_sp_ep(IN dp_ib_cm_handle_t ib_cm_handle,\r
-                        IN DAPL_SP * sp_ptr,\r
-                        IN DAT_EVENT_NUMBER dat_event_num);\r
-\r
-/*\r
- * dapls_cr_callback\r
- *\r
- * The callback function registered with verbs for passive side of\r
- * connection requests. The interface is specified by cm_api.h\r
- *\r
- *\r
- * Input:\r
- *     ib_cm_handle,           Handle to CM\r
- *     ib_cm_event             Specific CM event\r
- *     instant_data            Private data with DAT ADDRESS header\r
- *     context                 SP pointer\r
- *\r
- * Output:\r
- *     None\r
- *\r
- */\r
-void dapls_cr_callback(IN dp_ib_cm_handle_t ib_cm_handle, IN const ib_cm_events_t ib_cm_event,\r
-                      IN const void *private_data_ptr, IN const int private_data_size,\r
-                      IN const void *context)\r
-{\r
-       DAPL_EP *ep_ptr;\r
-       DAPL_EVD *evd_ptr;\r
-       DAPL_SP *sp_ptr;\r
-       DAPL_PRIVATE *prd_ptr;\r
-       DAT_EVENT_NUMBER dat_event_num;\r
-       DAT_RETURN dat_status;\r
-\r
-       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,\r
-                    "--> dapl_cr_callback! context: %p event: %x cm_handle %p\n",\r
-                    context, ib_cm_event, (void *)ib_cm_handle);\r
-\r
-       /*\r
-        * Passive side of the connection, context is a SP and\r
-        * we need to look up the EP.\r
-        */\r
-       sp_ptr = (DAPL_SP *) context;\r
-       /*\r
-        * The context pointer could have been cleaned up in a racing\r
-        * CM callback, check to see if we should just exit here\r
-        */\r
-       if (sp_ptr->header.magic == DAPL_MAGIC_INVALID) {\r
-               return;\r
-       }\r
-       dapl_os_assert(sp_ptr->header.magic == DAPL_MAGIC_PSP ||\r
-                      sp_ptr->header.magic == DAPL_MAGIC_RSP);\r
-\r
-       /* Obtain the event number from the provider layer */\r
-       dat_event_num = dapls_ib_get_dat_event(ib_cm_event, DAT_FALSE);\r
-\r
-       /*\r
-        * CONNECT_REQUEST events create an event on the PSP\r
-        * EVD, which will trigger connection processing. The\r
-        * sequence is:\r
-        *    CONNECT_REQUEST         Event to SP\r
-        *    CONNECTED               Event to EP\r
-        *    DISCONNECT              Event to EP\r
-        *\r
-        * Obtain the EP if required and set an event up on the correct\r
-        * EVD.\r
-        */\r
-       if (dat_event_num == DAT_CONNECTION_REQUEST_EVENT) {\r
-               ep_ptr = NULL;\r
-               evd_ptr = sp_ptr->evd_handle;\r
-       } else {\r
-               /* see if there is an EP connected with this CM handle */\r
-               ep_ptr = dapli_get_sp_ep(ib_cm_handle, sp_ptr, dat_event_num);\r
-\r
-               /* if we lost a race with the CM just exit. */\r
-               if (ep_ptr == NULL) {\r
-                       return;\r
-               }\r
-\r
-               evd_ptr = (DAPL_EVD *) ep_ptr->param.connect_evd_handle;\r
-               /* if something has happened to our EVD, bail. */\r
-               if (evd_ptr == NULL) {\r
-                       return;\r
-               }\r
-       }\r
-\r
-       prd_ptr = (DAPL_PRIVATE *) private_data_ptr;\r
-\r
-       dat_status = DAT_INTERNAL_ERROR;        /* init to ERR */\r
-\r
-       switch (dat_event_num) {\r
-       case DAT_CONNECTION_REQUEST_EVENT:\r
-               {\r
-                       /*\r
-                        * Requests arriving on a disabled SP are immediatly rejected\r
-                        */\r
-\r
-                       dapl_os_lock(&sp_ptr->header.lock);\r
-                       if (sp_ptr->listening == DAT_FALSE) {\r
-                               dapl_os_unlock(&sp_ptr->header.lock);\r
-                               dapl_dbg_log(DAPL_DBG_TYPE_CM,\r
-                                            "---> dapls_cr_callback: conn event on down SP\n");\r
-                               (void)dapls_ib_reject_connection(ib_cm_handle,\r
-                                                                DAT_CONNECTION_EVENT_UNREACHABLE,\r
-                                                                0, NULL);\r
-\r
-                               return;\r
-                       }\r
-\r
-                       if (sp_ptr->header.handle_type == DAT_HANDLE_TYPE_RSP) {\r
-                               /*\r
-                                * RSP connections only allow a single connection. Close\r
-                                * it down NOW so we reject any further connections.\r
-                                */\r
-                               sp_ptr->listening = DAT_FALSE;\r
-                       }\r
-                       dapl_os_unlock(&sp_ptr->header.lock);\r
-\r
-                       /*\r
-                        * Only occurs on the passive side of a connection\r
-                        * dapli_connection_request will post the connection\r
-                        * event if appropriate.\r
-                        */\r
-                       dat_status = dapli_connection_request(ib_cm_handle,\r
-                                                             sp_ptr, prd_ptr, private_data_size, evd_ptr);\r
-                       /* Set evd_ptr = NULL so we don't generate an event below */\r
-                       evd_ptr = NULL;\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_ESTABLISHED:\r
-               {\r
-                       /* This is just a notification the connection is now\r
-                        * established, there isn't any private data to deal with.\r
-                        *\r
-                        * Update the EP state and cache a copy of the cm handle,\r
-                        * then let the user know we are ready to go.\r
-                        */\r
-                       dapl_os_lock(&ep_ptr->header.lock);\r
-                       if (ep_ptr->header.magic != DAPL_MAGIC_EP ||\r
-                           ep_ptr->param.ep_state !=\r
-                           DAT_EP_STATE_COMPLETION_PENDING) {\r
-                               /* If someone pulled the plug on the EP or connection,\r
-                                * just exit\r
-                                */\r
-                               dapl_os_unlock(&ep_ptr->header.lock);\r
-                               dat_status = DAT_SUCCESS;\r
-                               /* Set evd_ptr = NULL so we don't generate an event below */\r
-                               evd_ptr = NULL;\r
-\r
-                               break;\r
-                       }\r
-\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_CONNECTED;\r
-                       ep_ptr->cm_handle = ib_cm_handle;\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_DISCONNECTED:\r
-               {\r
-                       /*\r
-                        * EP is now fully disconnected; initiate any post processing\r
-                        * to reset the underlying QP and get the EP ready for\r
-                        * another connection\r
-                        */\r
-                       dapl_os_lock(&ep_ptr->header.lock);\r
-                       if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED) {\r
-                               /* The disconnect has already occurred, we are now\r
-                                * cleaned up and ready to exit\r
-                                */\r
-                               dapl_os_unlock(&ep_ptr->header.lock);\r
-                               return;\r
-                       }\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,\r
-                                                 ib_cm_event);\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:\r
-       case DAT_CONNECTION_EVENT_PEER_REJECTED:\r
-       case DAT_CONNECTION_EVENT_UNREACHABLE:\r
-               {\r
-                       /*\r
-                        * After posting an accept the requesting node has\r
-                        * stopped talking.\r
-                        */\r
-                       dapl_os_lock(&ep_ptr->header.lock);\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       ep_ptr->cm_handle = IB_INVALID_HANDLE;\r
-                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,\r
-                                                 ib_cm_event);\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_BROKEN:\r
-               {\r
-                       dapl_os_lock(&ep_ptr->header.lock);\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,\r
-                                                 ib_cm_event);\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       default:\r
-               {\r
-                       evd_ptr = NULL;\r
-                       dapl_os_assert(0);      /* shouldn't happen */\r
-                       break;\r
-               }\r
-       }\r
-\r
-       if (evd_ptr != NULL) {\r
-               dat_status = dapls_evd_post_connection_event(evd_ptr,\r
-                                                            dat_event_num,\r
-                                                            (DAT_HANDLE)\r
-                                                            ep_ptr, 0, NULL);\r
-       }\r
-\r
-       if (dat_status != DAT_SUCCESS) {\r
-               /* The event post failed; take appropriate action.  */\r
-               (void)dapls_ib_reject_connection(ib_cm_handle,\r
-                                                DAT_CONNECTION_EVENT_BROKEN,\r
-                                                0, NULL);\r
-\r
-               return;\r
-       }\r
-}\r
-\r
-/*\r
- * dapli_connection_request\r
- *\r
- * Process a connection request on the Passive side of a connection.\r
- * Create a CR record and link it on to the SP so we can update it\r
- * and free it later. Create an EP if specified by the PSP flags.\r
- *\r
- * Input:\r
- *     ib_cm_handle,\r
- *     sp_ptr\r
- *     event_ptr\r
- *     prd_ptr\r
- *\r
- * Output:\r
- *     None\r
- *\r
- * Returns\r
- *     DAT_INSUFFICIENT_RESOURCES\r
- *     DAT_SUCCESS\r
- *\r
- */\r
-DAT_RETURN\r
-dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,\r
-                        IN DAPL_SP * sp_ptr,\r
-                        IN DAPL_PRIVATE * prd_ptr, IN int private_data_size,\r
-                        IN DAPL_EVD * evd_ptr)\r
-{\r
-       DAT_RETURN dat_status;\r
-\r
-       DAPL_CR *cr_ptr;\r
-       DAPL_EP *ep_ptr;\r
-       DAPL_IA *ia_ptr;\r
-       DAT_SP_HANDLE sp_handle;\r
-\r
-       cr_ptr = dapls_cr_alloc(sp_ptr->header.owner_ia);\r
-       if (cr_ptr == NULL) {\r
-               /* Invoking function will call dapls_ib_cm_reject() */\r
-               return DAT_INSUFFICIENT_RESOURCES;\r
-       }\r
-\r
-       /*\r
-        * Set up the CR\r
-        */\r
-       cr_ptr->sp_ptr = sp_ptr;        /* maintain sp_ptr in case of reject */\r
-       cr_ptr->param.remote_port_qual = 0;\r
-       cr_ptr->ib_cm_handle = ib_cm_handle;\r
-#ifdef IBHOSTS_NAMING\r
-       /*\r
-        * Special case: pull the remote HCA address from the private data\r
-        * prefix. This is a spec violation as it introduces a protocol, but\r
-        * some implementations may find it necessary for a time.\r
-        */\r
-       cr_ptr->remote_ia_address = prd_ptr->hca_address;\r
-#endif                         /* IBHOSTS_NAMING */\r
-       cr_ptr->param.remote_ia_address_ptr =\r
-           (DAT_IA_ADDRESS_PTR) & cr_ptr->remote_ia_address;\r
-       /*\r
-        * Copy the remote address and private data out of the private_data\r
-        * payload and put them in a local structure\r
-        */\r
-\r
-       /* Private data size will be determined by the provider layer */\r
-       cr_ptr->param.private_data = cr_ptr->private_data;\r
-       cr_ptr->param.private_data_size = private_data_size;\r
-       if (cr_ptr->param.private_data_size > 0) {\r
-               dapl_os_memcpy(cr_ptr->private_data,\r
-                              prd_ptr->private_data,\r
-                              DAPL_MIN(cr_ptr->param.private_data_size,\r
-                                       DAPL_MAX_PRIVATE_DATA_SIZE));\r
-       }\r
-\r
-       /* EP will be NULL unless RSP service point */\r
-       ep_ptr = (DAPL_EP *) sp_ptr->ep_handle;\r
-\r
-       if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {\r
-               /*\r
-                * Never true for RSP connections\r
-                *\r
-                * Create an EP for the user. If we can't allocate an\r
-                * EP we are out of resources and need to tell the\r
-                * requestor that we cant help them.\r
-                */\r
-               ia_ptr = sp_ptr->header.owner_ia;\r
-               ep_ptr = dapl_ep_alloc(ia_ptr, NULL);\r
-               if (ep_ptr == NULL) {\r
-                       dapls_cr_free(cr_ptr);\r
-                       /* Invoking function will call dapls_ib_cm_reject() */\r
-                       return DAT_INSUFFICIENT_RESOURCES;\r
-               }\r
-               ep_ptr->param.ia_handle = ia_ptr;\r
-               ep_ptr->param.local_ia_address_ptr =\r
-                   (DAT_IA_ADDRESS_PTR) & ia_ptr->hca_ptr->hca_address;\r
-\r
-               /* Link the EP onto the IA */\r
-               dapl_ia_link_ep(ia_ptr, ep_ptr);\r
-       }\r
-\r
-       cr_ptr->param.local_ep_handle = ep_ptr;\r
-\r
-       if (ep_ptr != NULL) {\r
-               /* Assign valid EP fields: RSP and PSP_PROVIDER_FLAG only */\r
-               if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {\r
-                       ep_ptr->param.ep_state =\r
-                           DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING;\r
-               } else {\r
-                       /* RSP */\r
-                       dapl_os_assert(sp_ptr->header.handle_type ==\r
-                                      DAT_HANDLE_TYPE_RSP);\r
-                       ep_ptr->param.ep_state =\r
-                           DAT_EP_STATE_PASSIVE_CONNECTION_PENDING;\r
-               }\r
-               ep_ptr->cm_handle = ib_cm_handle;\r
-       }\r
-\r
-       /* link the CR onto the SP so we can pick it up later */\r
-       dapl_sp_link_cr(sp_ptr, cr_ptr);\r
-\r
-       /* Post the event.  */\r
-       /* assign sp_ptr to union to avoid typecast errors from some compilers */\r
-       sp_handle.psp_handle = (DAT_PSP_HANDLE) sp_ptr;\r
-\r
-       dat_status = dapls_evd_post_cr_arrival_event(evd_ptr,\r
-                                                    DAT_CONNECTION_REQUEST_EVENT,\r
-                                                    sp_handle,\r
-                                                    (DAT_IA_ADDRESS_PTR)\r
-                                                    & sp_ptr->header.owner_ia->\r
-                                                    hca_ptr->hca_address,\r
-                                                    sp_ptr->conn_qual,\r
-                                                    (DAT_CR_HANDLE) cr_ptr);\r
-\r
-       if (dat_status != DAT_SUCCESS) {\r
-               dapls_cr_free(cr_ptr);\r
-               (void)dapls_ib_reject_connection(ib_cm_handle,\r
-                                                DAT_CONNECTION_EVENT_BROKEN,\r
-                                                0, NULL);\r
-\r
-               /* Take the CR off the list, we can't use it */\r
-               dapl_os_lock(&sp_ptr->header.lock);\r
-               dapl_sp_remove_cr(sp_ptr, cr_ptr);\r
-               dapl_os_unlock(&sp_ptr->header.lock);\r
-               return DAT_INSUFFICIENT_RESOURCES;\r
-       }\r
-\r
-       return DAT_SUCCESS;\r
-}\r
-\r
-/*\r
- * dapli_get_sp_ep\r
- *\r
- * Passive side of a connection is now fully established. Clean\r
- * up resources and obtain the EP pointer associated with a CR in\r
- * the SP\r
- *\r
- * Input:\r
- *     ib_cm_handle,\r
- *     sp_ptr\r
- *     connection_event\r
- *\r
- * Output:\r
- *     none\r
- *\r
- * Returns\r
- *     ep_ptr\r
- *\r
- */\r
-DAPL_EP *dapli_get_sp_ep(IN dp_ib_cm_handle_t ib_cm_handle,\r
-                        IN DAPL_SP * sp_ptr, IN DAT_EVENT_NUMBER dat_event_num)\r
-{\r
-       DAPL_CR *cr_ptr;\r
-       DAPL_EP *ep_ptr;\r
-\r
-       /*\r
-        * acquire the lock, we may be racing with other threads here\r
-        */\r
-       dapl_os_lock(&sp_ptr->header.lock);\r
-\r
-       /* Verify under lock that the SP is still valid */\r
-       if (sp_ptr->header.magic == DAPL_MAGIC_INVALID) {\r
-               dapl_os_unlock(&sp_ptr->header.lock);\r
-               return NULL;\r
-       }\r
-       /*\r
-        * There are potentially multiple connections in progress. Need to\r
-        * go through the list and find the one we are interested\r
-        * in. There is no guarantee of order. dapl_sp_search_cr\r
-        * leaves the CR on the SP queue.\r
-        */\r
-       cr_ptr = dapl_sp_search_cr(sp_ptr, ib_cm_handle);\r
-       if (cr_ptr == NULL) {\r
-               dapl_os_unlock(&sp_ptr->header.lock);\r
-               return NULL;\r
-       }\r
-\r
-       ep_ptr = (DAPL_EP *) cr_ptr->param.local_ep_handle;\r
-\r
-       /* Quick check to ensure our EP is still valid */\r
-       if ((DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP))) {\r
-               ep_ptr = NULL;\r
-       }\r
-\r
-       /* The CR record is discarded in all except for the CONNECTED case,\r
-        * as it will have no further relevance.\r
-        */\r
-       if (dat_event_num != DAT_CONNECTION_EVENT_ESTABLISHED) {\r
-               /* Remove the CR from the queue */\r
-               dapl_sp_remove_cr(sp_ptr, cr_ptr);\r
-\r
-               if (ep_ptr != NULL) {\r
-                       ep_ptr->cr_ptr = NULL;\r
-               }\r
-\r
-               /*\r
-                * If this SP has been removed from service, free it\r
-                * up after the last CR is removed\r
-                */\r
-               if (sp_ptr->listening != DAT_TRUE && sp_ptr->cr_list_count == 0\r
-                   && sp_ptr->state != DAPL_SP_STATE_FREE) {\r
-                       dapl_dbg_log(DAPL_DBG_TYPE_CM,\r
-                                    "--> dapli_get_sp_ep! disconnect dump sp: %p \n",\r
-                                    sp_ptr);\r
-                       /* Decrement the ref count on the EVD */\r
-                       if (sp_ptr->evd_handle) {\r
-                               dapl_os_atomic_dec(&\r
-                                                  ((DAPL_EVD *) sp_ptr->\r
-                                                   evd_handle)->evd_ref_count);\r
-                               sp_ptr->evd_handle = NULL;\r
-                       }\r
-                       sp_ptr->state = DAPL_SP_STATE_FREE;\r
-                       dapl_os_unlock(&sp_ptr->header.lock);\r
-                       (void)dapls_ib_remove_conn_listener(sp_ptr->header.\r
-                                                           owner_ia, sp_ptr);\r
-                       dapls_ia_unlink_sp((DAPL_IA *) sp_ptr->header.owner_ia,\r
-                                          sp_ptr);\r
-                       dapls_sp_free_sp(sp_ptr);\r
-                       dapls_cr_free(cr_ptr);\r
-                       goto skip_unlock;\r
-               }\r
-\r
-               dapl_os_unlock(&sp_ptr->header.lock);\r
-               /* free memory outside of the lock */\r
-               dapls_cr_free(cr_ptr);\r
-       } else {\r
-               dapl_os_unlock(&sp_ptr->header.lock);\r
-       }\r
-\r
-      skip_unlock:\r
-       return ep_ptr;\r
-}\r
-\r
-/*\r
- * Local variables:\r
- *  c-indent-level: 4\r
- *  c-basic-offset: 4\r
- *  c-brace-offset: -4\r
- *  tab-width: 8\r
- * End:\r
- */\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ *
+ * MODULE: dapls_cr_callback.c
+ *
+ * PURPOSE: implements passive side connection callbacks
+ *
+ * Description: Accepts asynchronous callbacks from the Communications Manager
+ *              for EVDs that have been specified as the connection_evd.
+ *
+ * $Id:$
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_evd_util.h"
+#include "dapl_cr_util.h"
+#include "dapl_ia_util.h"
+#include "dapl_sp_util.h"
+#include "dapl_ep_util.h"
+#include "dapl_adapter_util.h"
+
+/*
+ * Prototypes
+ */
+DAT_RETURN dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,
+                                   IN DAPL_SP * sp_ptr,
+                                   IN DAPL_PRIVATE * prd_ptr,
+                                   IN int private_data_size,
+                                   IN DAPL_EVD * evd_ptr);
+
+DAPL_EP *dapli_get_sp_ep(IN dp_ib_cm_handle_t ib_cm_handle,
+                        IN DAPL_SP * sp_ptr,
+                        IN DAT_EVENT_NUMBER dat_event_num);
+
+/*
+ * dapls_cr_callback
+ *
+ * The callback function registered with verbs for passive side of
+ * connection requests. The interface is specified by cm_api.h
+ *
+ *
+ * Input:
+ *     ib_cm_handle,           Handle to CM
+ *     ib_cm_event             Specific CM event
+ *     instant_data            Private data with DAT ADDRESS header
+ *     context                 SP pointer
+ *
+ * Output:
+ *     None
+ *
+ */
+void dapls_cr_callback(IN dp_ib_cm_handle_t ib_cm_handle, IN const ib_cm_events_t ib_cm_event,
+                       IN const void *private_data_ptr, IN const int private_data_size,
+                       IN const void *context)
+{
+       DAPL_EP *ep_ptr;
+       DAPL_EVD *evd_ptr;
+       DAPL_SP *sp_ptr;
+       DAPL_PRIVATE *prd_ptr;
+       DAT_EVENT_NUMBER dat_event_num;
+       DAT_RETURN dat_status;
+
+       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
+                    "--> dapl_cr_callback! context: %p event: %x cm_handle %p\n",
+                    context, ib_cm_event, (void *)ib_cm_handle);
+
+       /*
+        * Passive side of the connection, context is a SP and
+        * we need to look up the EP.
+        */
+       sp_ptr = (DAPL_SP *) context;
+       /*
+        * 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) {
+               return;
+       }
+       dapl_os_assert(sp_ptr->header.magic == DAPL_MAGIC_PSP ||
+                      sp_ptr->header.magic == DAPL_MAGIC_RSP);
+
+       /* Obtain the event number from the provider layer */
+       dat_event_num = dapls_ib_get_dat_event(ib_cm_event, DAT_FALSE);
+
+       /*
+        * CONNECT_REQUEST events create an event on the PSP
+        * EVD, which will trigger connection processing. The
+        * sequence is:
+        *    CONNECT_REQUEST         Event to SP
+        *    CONNECTED               Event to EP
+        *    DISCONNECT              Event to EP
+        *
+        * Obtain the EP if required and set an event up on the correct
+        * EVD.
+        */
+       if (dat_event_num == DAT_CONNECTION_REQUEST_EVENT) {
+               ep_ptr = NULL;
+               evd_ptr = sp_ptr->evd_handle;
+       } else {
+               /* see if there is an EP connected with this CM handle */
+               ep_ptr = dapli_get_sp_ep(ib_cm_handle, sp_ptr, dat_event_num);
+
+               /* if we lost a race with the CM just exit. */
+               if (ep_ptr == NULL) {
+                       return;
+               }
+
+               evd_ptr = (DAPL_EVD *) ep_ptr->param.connect_evd_handle;
+               /* if something has happened to our EVD, bail. */
+               if (evd_ptr == NULL) {
+                       return;
+               }
+       }
+
+       prd_ptr = (DAPL_PRIVATE *) private_data_ptr;
+
+       dat_status = DAT_INTERNAL_ERROR;        /* init to ERR */
+
+       switch (dat_event_num) {
+       case DAT_CONNECTION_REQUEST_EVENT:
+               {
+                       /*
+                        * Requests arriving on a disabled SP are immediatly rejected
+                        */
+
+                       dapl_os_lock(&sp_ptr->header.lock);
+                       if (sp_ptr->listening == DAT_FALSE) {
+                               dapl_os_unlock(&sp_ptr->header.lock);
+                               dapl_dbg_log(DAPL_DBG_TYPE_CM,
+                                            "---> dapls_cr_callback: conn event on down SP\n");
+                               (void)dapls_ib_reject_connection(ib_cm_handle,
+                                                                DAT_CONNECTION_EVENT_UNREACHABLE,
+                                                                0, NULL);
+
+                               return;
+                       }
+
+                       if (sp_ptr->header.handle_type == DAT_HANDLE_TYPE_RSP) {
+                               /*
+                                * RSP connections only allow a single connection. Close
+                                * it down NOW so we reject any further connections.
+                                */
+                               sp_ptr->listening = DAT_FALSE;
+                       }
+                       dapl_os_unlock(&sp_ptr->header.lock);
+
+                       /*
+                        * Only occurs on the passive side of a connection
+                        * dapli_connection_request will post the connection
+                        * event if appropriate.
+                        */
+                       dat_status = dapli_connection_request(ib_cm_handle,
+                                                             sp_ptr, prd_ptr, private_data_size, evd_ptr);
+                       /* Set evd_ptr = NULL so we don't generate an event below */
+                       evd_ptr = NULL;
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_ESTABLISHED:
+               {
+                       /* This is just a notification the connection is now
+                        * established, there isn't any private data to deal with.
+                        *
+                        * Update the EP state and cache a copy of the cm handle,
+                        * then let the user know we are ready to go.
+                        */
+                       dapl_os_lock(&ep_ptr->header.lock);
+                       if (ep_ptr->header.magic != DAPL_MAGIC_EP ||
+                           ep_ptr->param.ep_state !=
+                           DAT_EP_STATE_COMPLETION_PENDING) {
+                               /* If someone pulled the plug on the EP or connection,
+                                * just exit
+                                */
+                               dapl_os_unlock(&ep_ptr->header.lock);
+                               dat_status = DAT_SUCCESS;
+                               /* Set evd_ptr = NULL so we don't generate an event below */
+                               evd_ptr = NULL;
+
+                               break;
+                       }
+
+                       ep_ptr->param.ep_state = DAT_EP_STATE_CONNECTED;
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_DISCONNECTED:
+               {
+                       /*
+                        * EP is now fully disconnected; initiate any post processing
+                        * to reset the underlying QP and get the EP ready for
+                        * another connection
+                        */
+                       dapl_os_lock(&ep_ptr->header.lock);
+                       if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED) {
+                               /* The disconnect has already occurred, we are now
+                                * cleaned up and ready to exit
+                                */
+                               dapl_os_unlock(&ep_ptr->header.lock);
+                               return;
+                       }
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
+                                                 ib_cm_event);
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:
+       case DAT_CONNECTION_EVENT_PEER_REJECTED:
+       case DAT_CONNECTION_EVENT_UNREACHABLE:
+               {
+                       /*
+                        * After posting an accept the requesting node has
+                        * stopped talking.
+                        */
+                       dapl_os_lock(&ep_ptr->header.lock);
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
+                                                 ib_cm_event);
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_BROKEN:
+               {
+                       dapl_os_lock(&ep_ptr->header.lock);
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
+                                                 ib_cm_event);
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       default:
+               {
+                       evd_ptr = NULL;
+                       dapl_os_assert(0);      /* shouldn't happen */
+                       break;
+               }
+       }
+
+       if (evd_ptr != NULL) {
+               dat_status = dapls_evd_post_connection_event(evd_ptr,
+                                                            dat_event_num,
+                                                            (DAT_HANDLE)
+                                                            ep_ptr, 0, NULL);
+       }
+
+       if (dat_status != DAT_SUCCESS) {
+               /* The event post failed; take appropriate action.  */
+               (void)dapls_ib_reject_connection(ib_cm_handle,
+                                                DAT_CONNECTION_EVENT_BROKEN,
+                                                0, NULL);
+
+               return;
+       }
+}
+
+/*
+ * dapli_connection_request
+ *
+ * Process a connection request on the Passive side of a connection.
+ * Create a CR record and link it on to the SP so we can update it
+ * and free it later. Create an EP if specified by the PSP flags.
+ *
+ * Input:
+ *     ib_cm_handle,
+ *     sp_ptr
+ *     event_ptr
+ *     prd_ptr
+ *
+ * Output:
+ *     None
+ *
+ * Returns
+ *     DAT_INSUFFICIENT_RESOURCES
+ *     DAT_SUCCESS
+ *
+ */
+DAT_RETURN
+dapli_connection_request(IN dp_ib_cm_handle_t ib_cm_handle,
+                        IN DAPL_SP * sp_ptr,
+                        IN DAPL_PRIVATE * prd_ptr, IN int private_data_size,
+                        IN DAPL_EVD * evd_ptr)
+{
+       DAT_RETURN dat_status;
+
+       DAPL_CR *cr_ptr;
+       DAPL_EP *ep_ptr;
+       DAPL_IA *ia_ptr;
+       DAT_SP_HANDLE sp_handle;
+
+       cr_ptr = dapls_cr_alloc(sp_ptr->header.owner_ia);
+       if (cr_ptr == NULL) {
+               /* Invoking function will call dapls_ib_cm_reject() */
+               return DAT_INSUFFICIENT_RESOURCES;
+       }
+
+       /*
+        * Set up the CR
+        */
+       cr_ptr->sp_ptr = sp_ptr;        /* maintain sp_ptr in case of reject */
+       cr_ptr->param.remote_port_qual = 0;
+       cr_ptr->ib_cm_handle = ib_cm_handle;
+#ifdef IBHOSTS_NAMING
+       /*
+        * Special case: pull the remote HCA address from the private data
+        * prefix. This is a spec violation as it introduces a protocol, but
+        * some implementations may find it necessary for a time.
+        */
+       cr_ptr->remote_ia_address = prd_ptr->hca_address;
+#endif                         /* IBHOSTS_NAMING */
+       cr_ptr->param.remote_ia_address_ptr =
+           (DAT_IA_ADDRESS_PTR) & cr_ptr->remote_ia_address;
+       /*
+        * Copy the remote address and private data out of the private_data
+        * payload and put them in a local structure
+        */
+
+       /* Private data size will be determined by the provider layer */
+       cr_ptr->param.private_data = cr_ptr->private_data;
+       cr_ptr->param.private_data_size = private_data_size;
+       if (cr_ptr->param.private_data_size > 0) {
+               dapl_os_memcpy(cr_ptr->private_data,
+                              prd_ptr->private_data,
+                              DAPL_MIN(cr_ptr->param.private_data_size,
+                                       DAPL_MAX_PRIVATE_DATA_SIZE));
+       }
+
+       /* EP will be NULL unless RSP service point */
+       ep_ptr = (DAPL_EP *) sp_ptr->ep_handle;
+
+       if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
+               /*
+                * Never true for RSP connections
+                *
+                * Create an EP for the user. If we can't allocate an
+                * EP we are out of resources and need to tell the
+                * requestor that we cant help them.
+                */
+               ia_ptr = sp_ptr->header.owner_ia;
+               ep_ptr = dapl_ep_alloc(ia_ptr, NULL);
+               if (ep_ptr == NULL) {
+                       dapls_cr_free(cr_ptr);
+                       /* Invoking function will call dapls_ib_cm_reject() */
+                       return DAT_INSUFFICIENT_RESOURCES;
+               }
+               ep_ptr->param.ia_handle = ia_ptr;
+               ep_ptr->param.local_ia_address_ptr =
+                   (DAT_IA_ADDRESS_PTR) & ia_ptr->hca_ptr->hca_address;
+
+               /* Link the EP onto the IA */
+               dapl_ia_link_ep(ia_ptr, ep_ptr);
+       }
+
+       cr_ptr->param.local_ep_handle = ep_ptr;
+
+       if (ep_ptr != NULL) {
+               /* Assign valid EP fields: RSP and PSP_PROVIDER_FLAG only */
+               if (sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
+                       ep_ptr->param.ep_state =
+                           DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING;
+               } else {
+                       /* RSP */
+                       dapl_os_assert(sp_ptr->header.handle_type ==
+                                      DAT_HANDLE_TYPE_RSP);
+                       ep_ptr->param.ep_state =
+                           DAT_EP_STATE_PASSIVE_CONNECTION_PENDING;
+               }
+               dapl_ep_link_cm(ep_ptr, ib_cm_handle);
+       }
+
+       /* link the CR onto the SP so we can pick it up later */
+       dapl_sp_link_cr(sp_ptr, cr_ptr);
+
+       /* Post the event.  */
+       /* assign sp_ptr to union to avoid typecast errors from some compilers */
+       sp_handle.psp_handle = (DAT_PSP_HANDLE) sp_ptr;
+
+       dat_status = dapls_evd_post_cr_arrival_event(evd_ptr,
+                                                    DAT_CONNECTION_REQUEST_EVENT,
+                                                    sp_handle,
+                                                    (DAT_IA_ADDRESS_PTR)
+                                                    & sp_ptr->header.owner_ia->
+                                                    hca_ptr->hca_address,
+                                                    sp_ptr->conn_qual,
+                                                    (DAT_CR_HANDLE) cr_ptr);
+
+       if (dat_status != DAT_SUCCESS) {
+               dapls_cr_free(cr_ptr);
+               (void)dapls_ib_reject_connection(ib_cm_handle,
+                                                DAT_CONNECTION_EVENT_BROKEN,
+                                                0, NULL);
+
+               /* Take the CR off the list, we can't use it */
+               dapl_os_lock(&sp_ptr->header.lock);
+               dapl_sp_remove_cr(sp_ptr, cr_ptr);
+               dapl_os_unlock(&sp_ptr->header.lock);
+               return DAT_INSUFFICIENT_RESOURCES;
+       }
+
+       return DAT_SUCCESS;
+}
+
+/*
+ * dapli_get_sp_ep
+ *
+ * Passive side of a connection is now fully established. Clean
+ * up resources and obtain the EP pointer associated with a CR in
+ * the SP
+ *
+ * Input:
+ *     ib_cm_handle,
+ *     sp_ptr
+ *     connection_event
+ *
+ * Output:
+ *     none
+ *
+ * Returns
+ *     ep_ptr
+ *
+ */
+DAPL_EP *dapli_get_sp_ep(IN dp_ib_cm_handle_t ib_cm_handle,
+                        IN DAPL_SP * sp_ptr, IN DAT_EVENT_NUMBER dat_event_num)
+{
+       DAPL_CR *cr_ptr;
+       DAPL_EP *ep_ptr;
+
+       /*
+        * acquire the lock, we may be racing with other threads here
+        */
+       dapl_os_lock(&sp_ptr->header.lock);
+
+       /* Verify under lock that the SP is still valid */
+       if (sp_ptr->header.magic == DAPL_MAGIC_INVALID) {
+               dapl_os_unlock(&sp_ptr->header.lock);
+               return NULL;
+       }
+       /*
+        * There are potentially multiple connections in progress. Need to
+        * go through the list and find the one we are interested
+        * in. There is no guarantee of order. dapl_sp_search_cr
+        * leaves the CR on the SP queue.
+        */
+       cr_ptr = dapl_sp_search_cr(sp_ptr, ib_cm_handle);
+       if (cr_ptr == NULL) {
+               dapl_os_unlock(&sp_ptr->header.lock);
+               return NULL;
+       }
+
+       ep_ptr = (DAPL_EP *) cr_ptr->param.local_ep_handle;
+
+       /* Quick check to ensure our EP is still valid */
+       if ((DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP))) {
+               ep_ptr = NULL;
+       }
+
+       /* The CR record is discarded in all except for the CONNECTED case,
+        * as it will have no further relevance.
+        */
+       if (dat_event_num != DAT_CONNECTION_EVENT_ESTABLISHED) {
+               /* Remove the CR from the queue */
+               dapl_sp_remove_cr(sp_ptr, cr_ptr);
+
+               if (ep_ptr != NULL) {
+                       ep_ptr->cr_ptr = NULL;
+               }
+
+               /*
+                * If this SP has been removed from service, free it
+                * up after the last CR is removed
+                */
+               if (sp_ptr->listening != DAT_TRUE && sp_ptr->cr_list_count == 0
+                   && sp_ptr->state != DAPL_SP_STATE_FREE) {
+                       dapl_dbg_log(DAPL_DBG_TYPE_CM,
+                                    "--> dapli_get_sp_ep! disconnect dump sp: %p \n",
+                                    sp_ptr);
+                       /* Decrement the ref count on the EVD */
+                       if (sp_ptr->evd_handle) {
+                               dapl_os_atomic_dec(&
+                                                  ((DAPL_EVD *) sp_ptr->
+                                                   evd_handle)->evd_ref_count);
+                               sp_ptr->evd_handle = NULL;
+                       }
+                       sp_ptr->state = DAPL_SP_STATE_FREE;
+                       dapl_os_unlock(&sp_ptr->header.lock);
+                       (void)dapls_ib_remove_conn_listener(sp_ptr->header.
+                                                           owner_ia, sp_ptr);
+                       dapls_ia_unlink_sp((DAPL_IA *) sp_ptr->header.owner_ia,
+                                          sp_ptr);
+                       dapls_sp_free_sp(sp_ptr);
+                       dapls_cr_free(cr_ptr);
+                       goto skip_unlock;
+               }
+
+               dapl_os_unlock(&sp_ptr->header.lock);
+               /* free memory outside of the lock */
+               dapls_cr_free(cr_ptr);
+       } else {
+               dapl_os_unlock(&sp_ptr->header.lock);
+       }
+
+      skip_unlock:
+       return ep_ptr;
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  c-brace-offset: -4
+ *  tab-width: 8
+ * End:
+ */
index 39b61ad..2479479 100644 (file)
-/*
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
- *
- * This Software is licensed under one of the following licenses:
- *
- * 1) under the terms of the "Common Public License 1.0" a copy of which is
- *    available from the Open Source Initiative, see
- *    http://www.opensource.org/licenses/cpl.php.
- *
- * 2) under the terms of the "The BSD License" a copy of which is
- *    available from the Open Source Initiative, see
- *    http://www.opensource.org/licenses/bsd-license.php.
- *
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
- *    copy of which is available from the Open Source Initiative, see
- *    http://www.opensource.org/licenses/gpl-license.php.
- *
- * Licensee has the right to choose one of the above licenses.
- *
- * Redistributions of source code must retain the above copyright
- * notice and one of the license notices.
- *
- * Redistributions in binary form must reproduce both the above copyright
- * notice, one of the license notices in the documentation
- * and/or other materials provided with the distribution.
- */
-
-/**********************************************************************
- * 
- * MODULE: dapl_cr_util.c
- *
- * PURPOSE: Manage CR (Connection Request) structure
- *
- * $Id:$
- **********************************************************************/
-
-#include "dapl.h"
-#include "dapl_cr_util.h"
-
-/*
- * dapls_cr_create
- *
- * Create a CR. Part of the passive side of a connection
- *
- * Input:
- *     ia_ptr
- *
- * Returns:
- *     DAPL_CR
- *
- */
-
-DAPL_CR *dapls_cr_alloc(DAPL_IA * ia_ptr)
-{
-       DAPL_CR *cr_ptr;
-
-       /* Allocate EP */
-       cr_ptr = (DAPL_CR *) dapl_os_alloc(sizeof(DAPL_CR));
-       if (cr_ptr == NULL) {
-               return (NULL);
-       }
-
-       /* zero the structure */
-       dapl_os_memzero(cr_ptr, sizeof(DAPL_CR));
-
-       /*
-        * initialize the header
-        */
-       cr_ptr->header.provider = ia_ptr->header.provider;
-       cr_ptr->header.magic = DAPL_MAGIC_CR;
-       cr_ptr->header.handle_type = DAT_HANDLE_TYPE_CR;
-       cr_ptr->header.owner_ia = ia_ptr;
-       cr_ptr->header.user_context.as_64 = 0;
-       cr_ptr->header.user_context.as_ptr = NULL;
-       dapl_llist_init_entry(&cr_ptr->header.ia_list_entry);
-       dapl_os_lock_init(&cr_ptr->header.lock);
-
-       return (cr_ptr);
-}
-
-/*
- * dapls_cr_free
- *
- * Free the passed in EP structure.
- *
- * Input:
- *     entry point pointer
- *
- * Output:
- *     none
- *
- * Returns:
- *     none
- *
- */
-void dapls_cr_free(IN DAPL_CR * cr_ptr)
-{
-       dapl_os_assert(cr_ptr->header.magic == DAPL_MAGIC_CR ||
-                      cr_ptr->header.magic == DAPL_MAGIC_CR_DESTROYED);
-
-       cr_ptr->header.magic = DAPL_MAGIC_INVALID;      /* reset magic to prevent reuse */
-       dapl_os_free(cr_ptr, sizeof(DAPL_CR));
-}
+/*\r
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
+ *\r
+ * This Software is licensed under one of the following licenses:\r
+ *\r
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
+ *    available from the Open Source Initiative, see\r
+ *    http://www.opensource.org/licenses/cpl.php.\r
+ *\r
+ * 2) under the terms of the "The BSD License" a copy of which is\r
+ *    available from the Open Source Initiative, see\r
+ *    http://www.opensource.org/licenses/bsd-license.php.\r
+ *\r
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
+ *    copy of which is available from the Open Source Initiative, see\r
+ *    http://www.opensource.org/licenses/gpl-license.php.\r
+ *\r
+ * Licensee has the right to choose one of the above licenses.\r
+ *\r
+ * Redistributions of source code must retain the above copyright\r
+ * notice and one of the license notices.\r
+ *\r
+ * Redistributions in binary form must reproduce both the above copyright\r
+ * notice, one of the license notices in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * MODULE: dapl_cr_util.c\r
+ *\r
+ * PURPOSE: Manage CR (Connection Request) structure\r
+ *\r
+ * $Id:$\r
+ **********************************************************************/\r
+\r
+#include "dapl.h"\r
+#include "dapl_cr_util.h"\r
+\r
+/*\r
+ * dapls_cr_create\r
+ *\r
+ * Create a CR. Part of the passive side of a connection\r
+ *\r
+ * Input:\r
+ *     ia_ptr\r
+ *\r
+ * Returns:\r
+ *     DAPL_CR\r
+ *\r
+ */\r
+\r
+DAPL_CR *dapls_cr_alloc(DAPL_IA * ia_ptr)\r
+{\r
+       DAPL_CR *cr_ptr;\r
+\r
+       /* Allocate EP */\r
+       cr_ptr = (DAPL_CR *) dapl_os_alloc(sizeof(DAPL_CR));\r
+       if (cr_ptr == NULL) {\r
+               return (NULL);\r
+       }\r
+\r
+       /* zero the structure */\r
+       dapl_os_memzero(cr_ptr, sizeof(DAPL_CR));\r
+\r
+       /*\r
+        * initialize the header\r
+        */\r
+       cr_ptr->header.provider = ia_ptr->header.provider;\r
+       cr_ptr->header.magic = DAPL_MAGIC_CR;\r
+       cr_ptr->header.handle_type = DAT_HANDLE_TYPE_CR;\r
+       cr_ptr->header.owner_ia = ia_ptr;\r
+       cr_ptr->header.user_context.as_64 = 0;\r
+       cr_ptr->header.user_context.as_ptr = NULL;\r
+       dapl_llist_init_entry(&cr_ptr->header.ia_list_entry);\r
+       dapl_os_lock_init(&cr_ptr->header.lock);\r
+\r
+       return (cr_ptr);\r
+}\r
+\r
+/*\r
+ * dapls_cr_free\r
+ *\r
+ * Free the passed in CR structure.\r
+ *\r
+ * Input:\r
+ *     entry point pointer\r
+ *\r
+ * Output:\r
+ *     none\r
+ *\r
+ * Returns:\r
+ *     none\r
+ *\r
+ */\r
+void dapls_cr_free(IN DAPL_CR * cr_ptr)\r
+{\r
+       dapl_os_assert(cr_ptr->header.magic == DAPL_MAGIC_CR ||\r
+                      cr_ptr->header.magic == DAPL_MAGIC_CR_DESTROYED);\r
+\r
+       cr_ptr->header.magic = DAPL_MAGIC_INVALID;      /* reset magic to prevent reuse */\r
+       dapl_os_free(cr_ptr, sizeof(DAPL_CR));\r
+}\r
index 27bcca9..cec980f 100644 (file)
@@ -1,59 +1,59 @@
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- * \r
- * HEADER: dapl_cr_util.h\r
- *\r
- * PURPOSE: Utility defs & routines for the CR data structure\r
- *\r
- * $Id:$\r
- *\r
- **********************************************************************/\r
-\r
-#ifndef _DAPL_CR_UTIL_H_\r
-#define _DAPL_CR_UTIL_H_\r
-\r
-#include "dapl.h" \r
-\r
-DAPL_CR        *\r
-dapls_cr_alloc (\r
-       DAPL_IA         *ia_ptr );\r
-\r
-void\r
-dapls_cr_free (\r
-       IN DAPL_CR              *cr_ptr );\r
-\r
-void\r
-dapls_cr_callback (\r
-    IN    dp_ib_cm_handle_t     ib_cm_handle,\r
-    IN    const ib_cm_events_t  ib_cm_event,\r
-    IN   const void            *private_data_ptr,\r
-    IN    const int            private_data_size,\r
-    IN    const void           *context);\r
-\r
-#endif /* _DAPL_CR_UTIL_H_ */\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ * 
+ * HEADER: dapl_cr_util.h
+ *
+ * PURPOSE: Utility defs & routines for the CR data structure
+ *
+ * $Id:$
+ *
+ **********************************************************************/
+
+#ifndef _DAPL_CR_UTIL_H_
+#define _DAPL_CR_UTIL_H_
+
+#include "dapl.h" 
+
+DAPL_CR        *
+dapls_cr_alloc (
+       DAPL_IA         *ia_ptr );
+
+void
+dapls_cr_free (
+       IN DAPL_CR              *cr_ptr );
+
+void
+dapls_cr_callback (
+    IN    dp_ib_cm_handle_t     ib_cm_handle,
+    IN    const ib_cm_events_t  ib_cm_event,
+    IN   const void            *private_data_ptr,
+    IN    const int            private_data_size,
+    IN    const void           *context);
+
+#endif /* _DAPL_CR_UTIL_H_ */
index a14785b..1f193ae 100644 (file)
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- *\r
- * MODULE: dapl_ep_connect.c\r
- *\r
- * PURPOSE: Endpoint management\r
- *\r
- * $Id:$\r
- **********************************************************************/\r
-\r
-#include "dapl.h"\r
-#include "dapl_ep_util.h"\r
-#include "dapl_adapter_util.h"\r
-#include "dapl_evd_util.h"\r
-#include "dapl_timer_util.h"\r
-\r
-/*\r
- * dapl_ep_connect\r
- *\r
- * Request a connection be established between the local Endpoint\r
- * and a remote Endpoint. This operation is used by the active/client\r
- * side of a connection\r
- *\r
- * Input:\r
- *     ep_handle\r
- *     remote_ia_address\r
- *     remote_conn_qual\r
- *     timeout\r
- *     private_data_size\r
- *     privaet_data\r
- *     qos\r
- *     connect_flags\r
- *\r
- * Output:\r
- *     None\r
- *\r
- * Returns:\r
- *     DAT_SUCCESS\r
- *     DAT_INSUFFICIENT_RESOUCRES\r
- *     DAT_INVALID_PARAMETER\r
- *     DAT_MODLE_NOT_SUPPORTED\r
- */\r
-DAT_RETURN DAT_API\r
-dapl_ep_connect(IN DAT_EP_HANDLE ep_handle,\r
-               IN DAT_IA_ADDRESS_PTR remote_ia_address,\r
-               IN DAT_CONN_QUAL remote_conn_qual,\r
-               IN DAT_TIMEOUT timeout,\r
-               IN DAT_COUNT private_data_size,\r
-               IN const DAT_PVOID private_data,\r
-               IN DAT_QOS qos, IN DAT_CONNECT_FLAGS connect_flags)\r
-{\r
-       DAPL_EP *ep_ptr;\r
-       DAPL_EP alloc_ep;\r
-       DAT_RETURN dat_status;\r
-       DAT_COUNT req_hdr_size;\r
-       void *private_data_ptr;\r
-\r
-       dapl_dbg_log(DAPL_DBG_TYPE_API | DAPL_DBG_TYPE_CM,\r
-                    "dapl_ep_connect (%p, {%u.%u.%u.%u}, %X, %d, %d, %p, %x, %x)\n",\r
-                    ep_handle,\r
-                    remote_ia_address->sa_data[2],\r
-                    remote_ia_address->sa_data[3],\r
-                    remote_ia_address->sa_data[4],\r
-                    remote_ia_address->sa_data[5],\r
-                    remote_conn_qual,\r
-                    timeout,\r
-                    private_data_size, private_data, qos, connect_flags);\r
-\r
-       dat_status = DAT_SUCCESS;\r
-       ep_ptr = (DAPL_EP *) ep_handle;\r
-\r
-       /*\r
-        * Verify parameter & state. The connection handle must be good\r
-        * at this point.\r
-        */\r
-       if (DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP)) {\r
-               dat_status =\r
-                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_EP);\r
-               goto bail;\r
-       }\r
-\r
-       if (DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD)) {\r
-               dat_status =\r
-                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_EVD_CONN);\r
-               goto bail;\r
-       }\r
-\r
-       /* Can't do a connection in 0 time, reject outright */\r
-       if (timeout == 0) {\r
-               dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);\r
-               goto bail;\r
-       }\r
-       DAPL_CNTR(ep_ptr, DCNT_EP_CONNECT);\r
-\r
-       /*\r
-        * If the endpoint needs a QP, associated the QP with it.\r
-        * This needs to be done carefully, in order to:\r
-        *  * Avoid allocating under a lock.\r
-        *  * Not step on data structures being altered by\r
-        *    routines with which we are racing.\r
-        * So we:\r
-        *  * Confirm that a new QP is needed and is not forbidden by the\r
-        *    current state.\r
-        *  * Allocate it into a separate EP.\r
-        *  * Take the EP lock.\r
-        *  * Reconfirm that the EP is in a state where it needs a QP.\r
-        *  * Assign the QP and release the lock.\r
-        */\r
-       if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {\r
-               if (ep_ptr->param.pz_handle == NULL\r
-                   || DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ))\r
-               {\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INVALID_STATE,\r
-                                     DAT_INVALID_STATE_EP_NOTREADY);\r
-                       goto bail;\r
-               }\r
-               alloc_ep = *ep_ptr;\r
-\r
-               dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,\r
-                                              &alloc_ep, ep_ptr);\r
-               if (dat_status != DAT_SUCCESS) {\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,\r
-                                     DAT_RESOURCE_MEMORY);\r
-                       goto bail;\r
-               }\r
-\r
-               dapl_os_lock(&ep_ptr->header.lock);\r
-               /*\r
-                * PZ shouldn't have changed since we're only racing with\r
-                * dapl_cr_accept()\r
-                */\r
-               if (ep_ptr->qp_state != DAPL_QP_STATE_UNATTACHED) {\r
-                       /* Bail, cleaning up.  */\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-                       dat_status = dapls_ib_qp_free(ep_ptr->header.owner_ia,\r
-                                                     &alloc_ep);\r
-                       if (dat_status != DAT_SUCCESS) {\r
-                               dapl_dbg_log(DAPL_DBG_TYPE_WARN,\r
-                                            "ep_connect: ib_qp_free failed with %x\n",\r
-                                            dat_status);\r
-                       }\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INVALID_STATE,\r
-                                     dapls_ep_state_subtype(ep_ptr));\r
-                       goto bail;\r
-               }\r
-\r
-               ep_ptr->qp_handle = alloc_ep.qp_handle;\r
-               ep_ptr->qpn = alloc_ep.qpn;\r
-               ep_ptr->qp_state = alloc_ep.qp_state;\r
-\r
-               dapl_os_unlock(&ep_ptr->header.lock);\r
-       }\r
-\r
-       /*\r
-        * We do state checks and transitions under lock.\r
-        * The only code we're racing against is dapl_cr_accept.\r
-        */\r
-       dapl_os_lock(&ep_ptr->header.lock);\r
-\r
-       /*\r
-        * Verify the attributes of the EP handle before we connect it. Test\r
-        * all of the handles to make sure they are currently valid.\r
-        * Specifically:\r
-        *   pz_handle              required\r
-        *   recv_evd_handle        optional, but must be valid\r
-        *   request_evd_handle     optional, but must be valid\r
-        *   connect_evd_handle     required\r
-        */\r
-       if (ep_ptr->param.pz_handle == NULL\r
-           || DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ)\r
-           /* test connect handle */\r
-           || ep_ptr->param.connect_evd_handle == NULL\r
-           || DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD)\r
-           || !(((DAPL_EVD *) ep_ptr->param.connect_evd_handle)->\r
-                evd_flags & DAT_EVD_CONNECTION_FLAG)\r
-           /* test optional completion handles */\r
-           || (ep_ptr->param.recv_evd_handle != DAT_HANDLE_NULL &&\r
-               (DAPL_BAD_HANDLE\r
-                (ep_ptr->param.recv_evd_handle, DAPL_MAGIC_EVD)))\r
-           || (ep_ptr->param.request_evd_handle != DAT_HANDLE_NULL\r
-               &&\r
-               (DAPL_BAD_HANDLE\r
-                (ep_ptr->param.request_evd_handle, DAPL_MAGIC_EVD)))) {\r
-               dapl_os_unlock(&ep_ptr->header.lock);\r
-               dat_status =\r
-                   DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_EP_NOTREADY);\r
-               goto bail;\r
-       }\r
-\r
-       /* Check both the EP state and the QP state: if we don't have a QP\r
-        *  we need to attach one now.\r
-        */\r
-       if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {\r
-               dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,\r
-                                              ep_ptr, ep_ptr);\r
-\r
-               if (dat_status != DAT_SUCCESS) {\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,\r
-                                     DAT_RESOURCE_TEP);\r
-                       goto bail;\r
-               }\r
-       }\r
-\r
-       if (ep_ptr->param.ep_state != DAT_EP_STATE_UNCONNECTED &&\r
-           ep_ptr->param.ep_attr.service_type == DAT_SERVICE_TYPE_RC) {\r
-               dapl_os_unlock(&ep_ptr->header.lock);\r
-               dat_status =\r
-                   DAT_ERROR(DAT_INVALID_STATE,\r
-                             dapls_ep_state_subtype(ep_ptr));\r
-               goto bail;\r
-       }\r
-\r
-       if (qos != DAT_QOS_BEST_EFFORT ||\r
-           connect_flags != DAT_CONNECT_DEFAULT_FLAG) {\r
-               /*\r
-                * At this point we only support one QOS level\r
-                */\r
-               dapl_os_unlock(&ep_ptr->header.lock);\r
-               dat_status = DAT_ERROR(DAT_MODEL_NOT_SUPPORTED, 0);\r
-               goto bail;\r
-       }\r
-\r
-       /*\r
-        * Verify the private data size doesn't exceed the max\r
-        * req_hdr_size will evaluate to 0 unless IBHOSTS_NAMING is enabled.\r
-        */\r
-       req_hdr_size = (sizeof(DAPL_PRIVATE) - DAPL_MAX_PRIVATE_DATA_SIZE);\r
-\r
-       /* transition the state before requesting a connection to avoid\r
-        * race conditions\r
-        */\r
-       ep_ptr->param.ep_state = DAT_EP_STATE_ACTIVE_CONNECTION_PENDING;\r
-\r
-       /*\r
-        * At this point we're committed, and done with the endpoint\r
-        * except for the connect, so we can drop the lock.\r
-        */\r
-       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-#ifdef IBHOSTS_NAMING\r
-       /*\r
-        * Special case: put the remote HCA address into the private data\r
-        * prefix. This is a spec violation as it introduces a protocol, but\r
-        * some implementations may find it necessary for a time.\r
-        * Copy the private data into the EP area so the data is contiguous.\r
-        * If the provider needs to pad the buffer with NULLs, it happens at\r
-        * the provider layer.\r
-        */\r
-       dapl_os_memcpy(&ep_ptr->hca_address,\r
-                      &ep_ptr->header.owner_ia->hca_ptr->hca_address,\r
-                      sizeof(DAT_SOCK_ADDR));\r
-       dapl_os_memcpy(ep_ptr->private.private_data, private_data,\r
-                      private_data_size);\r
-       private_data_ptr = (void *)&ep_ptr->private.private_data;\r
-#else\r
-       private_data_ptr = private_data;\r
-#endif                         /* IBHOSTS_NAMING */\r
-\r
-       /* Copy the connection qualifiers */\r
-       dapl_os_memcpy(ep_ptr->param.remote_ia_address_ptr,\r
-                      remote_ia_address, sizeof(DAT_SOCK_ADDR));\r
-       ep_ptr->param.remote_port_qual = remote_conn_qual;\r
-\r
-       dat_status = dapls_ib_connect(ep_handle,\r
-                                     remote_ia_address,\r
-                                     remote_conn_qual,\r
-                                     private_data_size + req_hdr_size,\r
-                                     private_data_ptr);\r
-\r
-       if (dat_status != DAT_SUCCESS) {\r
-               ep_ptr->param.ep_state = DAT_EP_STATE_UNCONNECTED;\r
-\r
-               /*\r
-                * Some implementations provide us with an error code that the\r
-                * remote destination is unreachable, but DAT doesn't have a\r
-                * synchronous error code to communicate this. So the provider\r
-                * layer generates an INTERNAL_ERROR with a subtype; when\r
-                * this happens, return SUCCESS and generate the event\r
-                */\r
-               if (dat_status == DAT_ERROR(DAT_INTERNAL_ERROR, 1)) {\r
-                       dapls_evd_post_connection_event((DAPL_EVD *) ep_ptr->\r
-                                                       param.\r
-                                                       connect_evd_handle,\r
-                                                       DAT_CONNECTION_EVENT_UNREACHABLE,\r
-                                                       (DAT_HANDLE) ep_ptr, 0,\r
-                                                       0);\r
-                       dat_status = DAT_SUCCESS;\r
-               }\r
-       } else {\r
-               /*\r
-                * Acquire the lock and recheck the state of the EP; this\r
-                * thread could have been descheduled after issuing the connect\r
-                * request and the EP is now connected. Set up a timer if\r
-                * necessary.\r
-                */\r
-               dapl_os_lock(&ep_ptr->header.lock);\r
-               if (ep_ptr->param.ep_state ==\r
-                   DAT_EP_STATE_ACTIVE_CONNECTION_PENDING\r
-                   && timeout != DAT_TIMEOUT_INFINITE) {\r
-                       ep_ptr->cxn_timer =\r
-                           (DAPL_OS_TIMER *)\r
-                           dapl_os_alloc(sizeof(DAPL_OS_TIMER));\r
-\r
-                       dapls_timer_set(ep_ptr->cxn_timer,\r
-                                       dapls_ep_timeout, ep_ptr, timeout);\r
-               }\r
-               dapl_os_unlock(&ep_ptr->header.lock);\r
-       }\r
-\r
-      bail:\r
-       dapl_dbg_log(DAPL_DBG_TYPE_RTN | DAPL_DBG_TYPE_CM,\r
-                    "dapl_ep_connect () returns 0x%x\n", dat_status);\r
-\r
-       return dat_status;\r
-}\r
-\r
-/*\r
- * dapl_ep_common_connect\r
- *\r
- * DAPL Requirements Version 2.0, 6.6.x\r
- *\r
- * Requests that a connection be established\r
- * between the local Endpoint and a remote Endpoint specified by the\r
- * remote_ia_address. This operation is used by the active/client side\r
- * Consumer of the Connection establishment model.\r
- *\r
- * EP must be properly configured for this operation. The EP Communicator\r
- * must be specified. As part of the successful completion of this operation,\r
- * the local Endpoint is bound to a local IA Address if it had these assigned\r
- * before.\r
- * \r
- * The local IP Address, port and protocol are passed to the remote side of\r
- * the requested connection and is available to the remote Consumer in the\r
- * Connection Request of the DAT_CONNECTION_REQUEST_EVENT.\r
- * \r
- * The Consumer-provided private_data is passed to the remote side and is\r
- * provided to the remote Consumer in the Connection Request. Consumers\r
- * can encapsulate any local Endpoint attributes that remote Consumers\r
- * need to know as part of an upper-level protocol.\r
- *\r
- * Input:\r
- *     ep_handle\r
- *     remote_ia_address\r
- *     timeout\r
- *     private_data_size\r
- *     private_date pointer\r
- *\r
- * Output:\r
- *     none\r
- * \r
- * Returns:\r
- *     DAT_SUCCESS\r
- *     DAT_INSUFFICIENT_RESOURCES\r
- *     DAT_INVALID_PARAMETER\r
- *     DAT_INVALID_HANDLE\r
- *     DAT_INVALID_STATE\r
- *     DAT_MODEL_NOT_SUPPORTED\r
- */\r
-DAT_RETURN DAT_API dapl_ep_common_connect(IN DAT_EP_HANDLE ep, /* ep_handle            */\r
-                                         IN DAT_IA_ADDRESS_PTR remote_addr,    /* remote_ia_address    */\r
-                                         IN DAT_TIMEOUT timeout,       /* timeout              */\r
-                                         IN DAT_COUNT pdata_size,      /* private_data_size    */\r
-                                         IN const DAT_PVOID pdata)\r
-{                              /* private_data         */\r
-       return DAT_MODEL_NOT_SUPPORTED;\r
-}\r
-\r
-/*\r
- * Local variables:\r
- *  c-indent-level: 4\r
- *  c-basic-offset: 4\r
- *  tab-width: 8\r
- * End:\r
- */\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ *
+ * MODULE: dapl_ep_connect.c
+ *
+ * PURPOSE: Endpoint management
+ *
+ * $Id:$
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_ep_util.h"
+#include "dapl_adapter_util.h"
+#include "dapl_evd_util.h"
+#include "dapl_timer_util.h"
+
+/*
+ * dapl_ep_connect
+ *
+ * Request a connection be established between the local Endpoint
+ * and a remote Endpoint. This operation is used by the active/client
+ * side of a connection
+ *
+ * Input:
+ *     ep_handle
+ *     remote_ia_address
+ *     remote_conn_qual
+ *     timeout
+ *     private_data_size
+ *     privaet_data
+ *     qos
+ *     connect_flags
+ *
+ * Output:
+ *     None
+ *
+ * Returns:
+ *     DAT_SUCCESS
+ *     DAT_INSUFFICIENT_RESOUCRES
+ *     DAT_INVALID_PARAMETER
+ *     DAT_MODLE_NOT_SUPPORTED
+ */
+DAT_RETURN DAT_API
+dapl_ep_connect(IN DAT_EP_HANDLE ep_handle,
+               IN DAT_IA_ADDRESS_PTR remote_ia_address,
+               IN DAT_CONN_QUAL remote_conn_qual,
+               IN DAT_TIMEOUT timeout,
+               IN DAT_COUNT private_data_size,
+               IN const DAT_PVOID private_data,
+               IN DAT_QOS qos, IN DAT_CONNECT_FLAGS connect_flags)
+{
+       DAPL_EP *ep_ptr;
+       DAPL_EP alloc_ep;
+       DAT_RETURN dat_status;
+       DAT_COUNT req_hdr_size;
+       void *private_data_ptr;
+
+       dapl_dbg_log(DAPL_DBG_TYPE_API | DAPL_DBG_TYPE_CM,
+                    "dapl_ep_connect (%p, {%u.%u.%u.%u}, %X, %d, %d, %p, %x, %x)\n",
+                    ep_handle,
+                    remote_ia_address->sa_data[2],
+                    remote_ia_address->sa_data[3],
+                    remote_ia_address->sa_data[4],
+                    remote_ia_address->sa_data[5],
+                    remote_conn_qual,
+                    timeout,
+                    private_data_size, private_data, qos, connect_flags);
+
+       dat_status = DAT_SUCCESS;
+       ep_ptr = (DAPL_EP *) ep_handle;
+
+       /*
+        * Verify parameter & state. The connection handle must be good
+        * at this point.
+        */
+       if (DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP)) {
+               dat_status =
+                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_EP);
+               goto bail;
+       }
+
+       if (DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD)) {
+               dat_status =
+                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_EVD_CONN);
+               goto bail;
+       }
+
+       /* Can't do a connection in 0 time, reject outright */
+       if (timeout == 0) {
+               dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
+               goto bail;
+       }
+       DAPL_CNTR(ep_ptr, DCNT_EP_CONNECT);
+
+       /*
+        * If the endpoint needs a QP, associated the QP with it.
+        * This needs to be done carefully, in order to:
+        *  * Avoid allocating under a lock.
+        *  * Not step on data structures being altered by
+        *    routines with which we are racing.
+        * So we:
+        *  * Confirm that a new QP is needed and is not forbidden by the
+        *    current state.
+        *  * Allocate it into a separate EP.
+        *  * Take the EP lock.
+        *  * Reconfirm that the EP is in a state where it needs a QP.
+        *  * Assign the QP and release the lock.
+        */
+       if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
+               if (ep_ptr->param.pz_handle == NULL
+                   || DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ))
+               {
+                       dat_status =
+                           DAT_ERROR(DAT_INVALID_STATE,
+                                     DAT_INVALID_STATE_EP_NOTREADY);
+                       goto bail;
+               }
+               alloc_ep = *ep_ptr;
+
+               dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,
+                                              &alloc_ep, ep_ptr);
+               if (dat_status != DAT_SUCCESS) {
+                       dat_status =
+                           DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
+                                     DAT_RESOURCE_MEMORY);
+                       goto bail;
+               }
+
+               dapl_os_lock(&ep_ptr->header.lock);
+               /*
+                * PZ shouldn't have changed since we're only racing with
+                * dapl_cr_accept()
+                */
+               if (ep_ptr->qp_state != DAPL_QP_STATE_UNATTACHED) {
+                       /* Bail, cleaning up.  */
+                       dapl_os_unlock(&ep_ptr->header.lock);
+                       dat_status = dapls_ib_qp_free(ep_ptr->header.owner_ia,
+                                                     &alloc_ep);
+                       if (dat_status != DAT_SUCCESS) {
+                               dapl_dbg_log(DAPL_DBG_TYPE_WARN,
+                                            "ep_connect: ib_qp_free failed with %x\n",
+                                            dat_status);
+                       }
+                       dat_status =
+                           DAT_ERROR(DAT_INVALID_STATE,
+                                     dapls_ep_state_subtype(ep_ptr));
+                       goto bail;
+               }
+
+               ep_ptr->qp_handle = alloc_ep.qp_handle;
+               ep_ptr->qpn = alloc_ep.qpn;
+               ep_ptr->qp_state = alloc_ep.qp_state;
+
+               dapl_os_unlock(&ep_ptr->header.lock);
+       }
+
+       /*
+        * We do state checks and transitions under lock.
+        * The only code we're racing against is dapl_cr_accept.
+        */
+       dapl_os_lock(&ep_ptr->header.lock);
+
+       /*
+        * Verify the attributes of the EP handle before we connect it. Test
+        * all of the handles to make sure they are currently valid.
+        * Specifically:
+        *   pz_handle              required
+        *   recv_evd_handle        optional, but must be valid
+        *   request_evd_handle     optional, but must be valid
+        *   connect_evd_handle     required
+        */
+       if (ep_ptr->param.pz_handle == NULL
+           || DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ)
+           /* test connect handle */
+           || ep_ptr->param.connect_evd_handle == NULL
+           || DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD)
+           || !(((DAPL_EVD *) ep_ptr->param.connect_evd_handle)->
+                evd_flags & DAT_EVD_CONNECTION_FLAG)
+           /* test optional completion handles */
+           || (ep_ptr->param.recv_evd_handle != DAT_HANDLE_NULL &&
+               (DAPL_BAD_HANDLE
+                (ep_ptr->param.recv_evd_handle, DAPL_MAGIC_EVD)))
+           || (ep_ptr->param.request_evd_handle != DAT_HANDLE_NULL
+               &&
+               (DAPL_BAD_HANDLE
+                (ep_ptr->param.request_evd_handle, DAPL_MAGIC_EVD)))) {
+               dapl_os_unlock(&ep_ptr->header.lock);
+               dat_status =
+                   DAT_ERROR(DAT_INVALID_STATE, DAT_INVALID_STATE_EP_NOTREADY);
+               goto bail;
+       }
+
+       /* Check both the EP state and the QP state: if we don't have a QP
+        *  we need to attach one now.
+        */
+       if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
+               dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,
+                                              ep_ptr, ep_ptr);
+
+               if (dat_status != DAT_SUCCESS) {
+                       dapl_os_unlock(&ep_ptr->header.lock);
+                       dat_status =
+                           DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
+                                     DAT_RESOURCE_TEP);
+                       goto bail;
+               }
+       }
+
+       if (ep_ptr->param.ep_state != DAT_EP_STATE_UNCONNECTED &&
+           ep_ptr->param.ep_attr.service_type == DAT_SERVICE_TYPE_RC) {
+               dapl_os_unlock(&ep_ptr->header.lock);
+               dat_status =
+                   DAT_ERROR(DAT_INVALID_STATE,
+                             dapls_ep_state_subtype(ep_ptr));
+               goto bail;
+       }
+
+       if (qos != DAT_QOS_BEST_EFFORT ||
+           connect_flags != DAT_CONNECT_DEFAULT_FLAG) {
+               /*
+                * At this point we only support one QOS level
+                */
+               dapl_os_unlock(&ep_ptr->header.lock);
+               dat_status = DAT_ERROR(DAT_MODEL_NOT_SUPPORTED, 0);
+               goto bail;
+       }
+
+       /*
+        * Verify the private data size doesn't exceed the max
+        * req_hdr_size will evaluate to 0 unless IBHOSTS_NAMING is enabled.
+        */
+       req_hdr_size = (sizeof(DAPL_PRIVATE) - DAPL_MAX_PRIVATE_DATA_SIZE);
+
+       /* transition the state before requesting a connection to avoid
+        * race conditions
+        */
+       ep_ptr->param.ep_state = DAT_EP_STATE_ACTIVE_CONNECTION_PENDING;
+
+       /*
+        * At this point we're committed, and done with the endpoint
+        * except for the connect, so we can drop the lock.
+        */
+       dapl_os_unlock(&ep_ptr->header.lock);
+
+#ifdef IBHOSTS_NAMING
+       /*
+        * Special case: put the remote HCA address into the private data
+        * prefix. This is a spec violation as it introduces a protocol, but
+        * some implementations may find it necessary for a time.
+        * Copy the private data into the EP area so the data is contiguous.
+        * If the provider needs to pad the buffer with NULLs, it happens at
+        * the provider layer.
+        */
+       dapl_os_memcpy(&ep_ptr->hca_address,
+                      &ep_ptr->header.owner_ia->hca_ptr->hca_address,
+                      sizeof(DAT_SOCK_ADDR));
+       dapl_os_memcpy(ep_ptr->private.private_data, private_data,
+                      private_data_size);
+       private_data_ptr = (void *)&ep_ptr->private.private_data;
+#else
+       private_data_ptr = private_data;
+#endif                         /* IBHOSTS_NAMING */
+
+       /* Copy the connection qualifiers */
+       dapl_os_memcpy(ep_ptr->param.remote_ia_address_ptr,
+                      remote_ia_address, sizeof(DAT_SOCK_ADDR));
+       ep_ptr->param.remote_port_qual = remote_conn_qual;
+
+       dat_status = dapls_ib_connect(ep_handle,
+                                     remote_ia_address,
+                                     remote_conn_qual,
+                                     private_data_size + req_hdr_size,
+                                     private_data_ptr);
+
+       if (dat_status != DAT_SUCCESS) {
+               ep_ptr->param.ep_state = DAT_EP_STATE_UNCONNECTED;
+
+               /*
+                * Some implementations provide us with an error code that the
+                * remote destination is unreachable, but DAT doesn't have a
+                * synchronous error code to communicate this. So the provider
+                * layer generates an INTERNAL_ERROR with a subtype; when
+                * this happens, return SUCCESS and generate the event
+                */
+               if (dat_status == DAT_ERROR(DAT_INTERNAL_ERROR, 1)) {
+                       dapls_evd_post_connection_event((DAPL_EVD *) ep_ptr->
+                                                       param.
+                                                       connect_evd_handle,
+                                                       DAT_CONNECTION_EVENT_UNREACHABLE,
+                                                       (DAT_HANDLE) ep_ptr, 0,
+                                                       0);
+                       dat_status = DAT_SUCCESS;
+               }
+       } else {
+               /*
+                * Acquire the lock and recheck the state of the EP; this
+                * thread could have been descheduled after issuing the connect
+                * request and the EP is now connected. Set up a timer if
+                * necessary.
+                */
+               dapl_os_lock(&ep_ptr->header.lock);
+               if (ep_ptr->param.ep_state ==
+                   DAT_EP_STATE_ACTIVE_CONNECTION_PENDING
+                   && timeout != DAT_TIMEOUT_INFINITE) {
+                       ep_ptr->cxn_timer =
+                           (DAPL_OS_TIMER *)
+                           dapl_os_alloc(sizeof(DAPL_OS_TIMER));
+
+                       dapls_timer_set(ep_ptr->cxn_timer,
+                                       dapls_ep_timeout, ep_ptr, timeout);
+
+                       dapl_log(DAPL_DBG_TYPE_WARN, " dapl_ep_connect timeout = %d us\n", timeout);
+               }
+               dapl_os_unlock(&ep_ptr->header.lock);
+       }
+
+      bail:
+       dapl_dbg_log(DAPL_DBG_TYPE_RTN | DAPL_DBG_TYPE_CM,
+                    "dapl_ep_connect () returns 0x%x\n", dat_status);
+
+       return dat_status;
+}
+
+/*
+ * dapl_ep_common_connect
+ *
+ * DAPL Requirements Version 2.0, 6.6.x
+ *
+ * Requests that a connection be established
+ * between the local Endpoint and a remote Endpoint specified by the
+ * remote_ia_address. This operation is used by the active/client side
+ * Consumer of the Connection establishment model.
+ *
+ * EP must be properly configured for this operation. The EP Communicator
+ * must be specified. As part of the successful completion of this operation,
+ * the local Endpoint is bound to a local IA Address if it had these assigned
+ * before.
+ * 
+ * The local IP Address, port and protocol are passed to the remote side of
+ * the requested connection and is available to the remote Consumer in the
+ * Connection Request of the DAT_CONNECTION_REQUEST_EVENT.
+ * 
+ * The Consumer-provided private_data is passed to the remote side and is
+ * provided to the remote Consumer in the Connection Request. Consumers
+ * can encapsulate any local Endpoint attributes that remote Consumers
+ * need to know as part of an upper-level protocol.
+ *
+ * Input:
+ *     ep_handle
+ *     remote_ia_address
+ *     timeout
+ *     private_data_size
+ *     private_date pointer
+ *
+ * Output:
+ *     none
+ * 
+ * Returns:
+ *     DAT_SUCCESS
+ *     DAT_INSUFFICIENT_RESOURCES
+ *     DAT_INVALID_PARAMETER
+ *     DAT_INVALID_HANDLE
+ *     DAT_INVALID_STATE
+ *     DAT_MODEL_NOT_SUPPORTED
+ */
+DAT_RETURN DAT_API dapl_ep_common_connect(IN DAT_EP_HANDLE ep, /* ep_handle            */
+                                         IN DAT_IA_ADDRESS_PTR remote_addr,    /* remote_ia_address    */
+                                         IN DAT_TIMEOUT timeout,       /* timeout              */
+                                         IN DAT_COUNT pdata_size,      /* private_data_size    */
+                                         IN const DAT_PVOID pdata)
+{                              /* private_data         */
+       return DAT_MODEL_NOT_SUPPORTED;
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 8
+ * End:
+ */
index fd9fcc7..8708e6f 100644 (file)
@@ -66,6 +66,7 @@ DAT_RETURN DAT_API dapl_ep_free(IN DAT_EP_HANDLE ep_handle)
        DAPL_EP *ep_ptr;
        DAPL_IA *ia_ptr;
        DAT_EP_PARAM *param;
+       dp_ib_cm_handle_t cm_ptr, next_cm_ptr;
        ib_qp_state_t save_qp_state;
        DAT_RETURN dat_status = DAT_SUCCESS;
 
@@ -187,6 +188,20 @@ DAT_RETURN DAT_API dapl_ep_free(IN DAT_EP_HANDLE ep_handle)
                }
        }
 
+       /* Free all CM objects */
+       cm_ptr = (dapl_llist_is_empty(&ep_ptr->cm_list_head)
+                 ? NULL : dapl_llist_peek_head(&ep_ptr->cm_list_head));
+       while (cm_ptr != NULL) {
+                dapl_log(DAPL_DBG_TYPE_EP,
+                        "dapl_ep_free: Free CM: EP=%p CM=%p\n",
+                        ep_ptr, cm_ptr);
+
+               next_cm_ptr = dapl_llist_next_entry(&ep_ptr->cm_list_head,
+                                                   &cm_ptr->list_entry);
+               dapls_cm_free(cm_ptr); /* blocking call */
+               cm_ptr = next_cm_ptr;
+       }
+
        /* Free the resource */
        dapl_ep_dealloc(ep_ptr);
 
index 48dee1e..e6432b9 100644 (file)
@@ -141,6 +141,7 @@ DAPL_EP *dapl_ep_alloc(IN DAPL_IA * ia_ptr, IN const DAT_EP_ATTR * ep_attr)
        ep_ptr->header.user_context.as_ptr = NULL;\r
 \r
        dapl_llist_init_entry(&ep_ptr->header.ia_list_entry);\r
+       dapl_llist_init_head(&ep_ptr->cm_list_head);\r
        dapl_os_lock_init(&ep_ptr->header.lock);\r
 \r
        /*\r
@@ -161,7 +162,6 @@ DAPL_EP *dapl_ep_alloc(IN DAPL_IA * ia_ptr, IN const DAT_EP_ATTR * ep_attr)
        ep_ptr->qp_handle = IB_INVALID_HANDLE;\r
        ep_ptr->qpn = 0;\r
        ep_ptr->qp_state = DAPL_QP_STATE_UNATTACHED;\r
-       ep_ptr->cm_handle = IB_INVALID_HANDLE;\r
 \r
        if (DAT_SUCCESS != dapls_cb_create(&ep_ptr->req_buffer,\r
                                           ep_ptr,\r
@@ -214,13 +214,6 @@ void dapl_ep_dealloc(IN DAPL_EP * ep_ptr)
        if (NULL != ep_ptr->cxn_timer) {\r
                dapl_os_free(ep_ptr->cxn_timer, sizeof(DAPL_OS_TIMER));\r
        }\r
-#if defined(_WIN32) || defined(_WIN64)\r
-       if (ep_ptr->ibal_cm_handle) {\r
-               dapl_os_free(ep_ptr->ibal_cm_handle,\r
-                            sizeof(*ep_ptr->ibal_cm_handle));\r
-               ep_ptr->ibal_cm_handle = NULL;\r
-       }\r
-#endif\r
 \r
 #ifdef DAPL_COUNTERS\r
        dapl_os_free(ep_ptr->cntrs, sizeof(DAT_UINT64) * DCNT_EP_ALL_COUNTERS);\r
@@ -417,7 +410,7 @@ void dapls_ep_timeout(uintptr_t arg)
         * The disconnect_clean interface requires the provided dependent \r
         *cm event number.\r
         */\r
-       ib_cm_event = dapls_ib_get_cm_event(DAT_CONNECTION_EVENT_DISCONNECTED);\r
+       ib_cm_event = dapls_ib_get_cm_event(DAT_CONNECTION_EVENT_TIMED_OUT);\r
        dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE, ib_cm_event);\r
 \r
        (void)dapls_evd_post_connection_event((DAPL_EVD *) ep_ptr->param.\r
@@ -537,6 +530,7 @@ dapl_ep_legacy_post_disconnect(DAPL_EP * ep_ptr,
 {\r
        ib_cm_events_t ib_cm_event;\r
        DAPL_CR *cr_ptr;\r
+       dp_ib_cm_handle_t cm_ptr;\r
 \r
        /*\r
         * Acquire the lock and make sure we didn't get a callback\r
@@ -557,6 +551,8 @@ dapl_ep_legacy_post_disconnect(DAPL_EP * ep_ptr,
                    dapls_ib_get_cm_event(DAT_CONNECTION_EVENT_DISCONNECTED);\r
 \r
                cr_ptr = ep_ptr->cr_ptr;\r
+               cm_ptr = (dapl_llist_is_empty(&ep_ptr->cm_list_head)\r
+                         ? NULL : dapl_llist_peek_head(&ep_ptr->cm_list_head));\r
                dapl_os_unlock(&ep_ptr->header.lock);\r
 \r
                if (cr_ptr != NULL) {\r
@@ -567,7 +563,7 @@ dapl_ep_legacy_post_disconnect(DAPL_EP * ep_ptr,
                        dapls_cr_callback(cr_ptr->ib_cm_handle,\r
                                          ib_cm_event, NULL, 0, cr_ptr->sp_ptr);\r
                } else {\r
-                       dapl_evd_connection_callback(ep_ptr->cm_handle,\r
+                       dapl_evd_connection_callback(cm_ptr,\r
                                                     ib_cm_event,\r
                                                     NULL, 0, (void *)ep_ptr);\r
                }\r
@@ -576,6 +572,40 @@ dapl_ep_legacy_post_disconnect(DAPL_EP * ep_ptr,
        }\r
 }\r
 \r
+/*\r
+ * dapl_ep_link_cm\r
+ *\r
+ * Add linking of provider's CM object to a EP structure\r
+ * This enables multiple CM's per EP, and syncronization\r
+ *\r
+ * Input:\r
+ *     DAPL_EP *ep_ptr\r
+ *     dp_ib_cm_handle_t *cm_ptr  defined in provider's dapl_util.h\r
+ *\r
+ *     CM objects linked with EP using  ->list_entry\r
+ * Output:\r
+ *     none\r
+ *\r
+ * Returns:\r
+ *     none\r
+ *\r
+ */\r
+void dapl_ep_link_cm(IN DAPL_EP *ep_ptr, IN dp_ib_cm_handle_t cm_ptr)\r
+{\r
+       dapl_os_lock(&ep_ptr->header.lock);\r
+       dapls_cm_acquire(cm_ptr);\r
+       dapl_llist_add_tail(&ep_ptr->cm_list_head, &cm_ptr->list_entry, cm_ptr);\r
+       dapl_os_unlock(&ep_ptr->header.lock);\r
+}\r
+\r
+void dapl_ep_unlink_cm(IN DAPL_EP *ep_ptr, IN dp_ib_cm_handle_t cm_ptr)\r
+{\r
+       dapl_os_lock(&ep_ptr->header.lock);\r
+       dapl_llist_remove_entry(&ep_ptr->cm_list_head, &cm_ptr->list_entry);\r
+       dapls_cm_release(cm_ptr);\r
+       dapl_os_unlock(&ep_ptr->header.lock);\r
+}\r
+\r
 /*\r
  * Local variables:\r
  *  c-indent-level: 4\r
index 7ac4061..31d0e23 100644 (file)
@@ -83,5 +83,23 @@ dapl_ep_legacy_post_disconnect(
     DAT_CLOSE_FLAGS    disconnect_flags);
 
 extern char *dapl_get_ep_state_str(DAT_EP_STATE state);
+
+extern void dapl_ep_link_cm(IN DAPL_EP *ep_ptr, 
+                           IN dp_ib_cm_handle_t cm_ptr);
+
+extern void dapl_ep_unlink_cm(IN DAPL_EP *ep_ptr, 
+                             IN dp_ib_cm_handle_t cm_ptr);
+
+STATIC _INLINE_ dp_ib_cm_handle_t dapl_get_cm_from_ep(IN DAPL_EP *ep_ptr)
+{
+       dp_ib_cm_handle_t cm_ptr;
+
+       dapl_os_lock(&ep_ptr->header.lock);
+       cm_ptr = (dapl_llist_is_empty(&ep_ptr->cm_list_head)
+                 ? NULL : dapl_llist_peek_head(&ep_ptr->cm_list_head));
+       dapl_os_unlock(&ep_ptr->header.lock);
+
+       return cm_ptr;
+}
  
 #endif /*  _DAPL_EP_UTIL_H_ */
index 841b28d..3166702 100644 (file)
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- *\r
- * MODULE: dapl_evd_connection_callback.c\r
- *\r
- * PURPOSE: implements connection callbacks\r
- *\r
- * Description: Accepts asynchronous callbacks from the Communications Manager\r
- *              for EVDs that have been specified as the connection_evd.\r
- *\r
- * $Id:$\r
- **********************************************************************/\r
-\r
-#include "dapl.h"\r
-#include "dapl_evd_util.h"\r
-#include "dapl_ep_util.h"\r
-#include "dapl_timer_util.h"\r
-\r
-/*\r
- * dapl_evd_connection_callback\r
- *\r
- * Connection callback function for ACTIVE connection requests; callbacks\r
- * generated by the Connection Manager in response to issuing a\r
- * connect call.\r
- *\r
- * Input:\r
- *     ib_cm_handle,\r
- *     ib_cm_event\r
- *     private_data_ptr\r
- *     context (evd)\r
- *     cr_pp\r
- *\r
- * Output:\r
- *     None\r
- *\r
- */\r
-\r
-void\r
-dapl_evd_connection_callback(IN dp_ib_cm_handle_t ib_cm_handle,\r
-                            IN const ib_cm_events_t ib_cm_event,\r
-                            IN const void *private_data_ptr,\r
-                            IN const int private_data_size,\r
-                            IN const void *context)\r
-{\r
-       DAPL_EP *ep_ptr;\r
-       DAPL_EVD *evd_ptr;\r
-       DAPL_PRIVATE *prd_ptr;\r
-       DAT_EVENT_NUMBER dat_event_num;\r
-       DAT_RETURN dat_status;\r
-\r
-       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,\r
-                    "--> dapl_evd_connection_callback: ctxt: %p event: %x cm_handle %p\n",\r
-                    context, ib_cm_event, (void *)ib_cm_handle);\r
-\r
-       /*\r
-        * Determine the type of handle passed back to us in the context\r
-        * and sort out key parameters.\r
-        */\r
-       if (context == NULL\r
-           || ((DAPL_HEADER *) context)->magic != DAPL_MAGIC_EP) {\r
-               return;\r
-       }\r
-\r
-       /*\r
-        * Active side of the connection, context is an EP and\r
-        * PSP is irrelevant.\r
-        */\r
-       ep_ptr = (DAPL_EP *) context;\r
-       evd_ptr = (DAPL_EVD *) ep_ptr->param.connect_evd_handle;\r
-       DAPL_CNTR(evd_ptr, DCNT_EVD_CONN_CALLBACK);\r
-\r
-       prd_ptr = (DAPL_PRIVATE *) private_data_ptr;\r
-       /*\r
-        * All operations effect the EP, so lock it once and unlock\r
-        * when necessary\r
-        */\r
-       dapl_os_lock(&ep_ptr->header.lock);\r
-\r
-       /*\r
-        * If a connection timer has been set up on this EP, cancel it now\r
-        */\r
-       if (ep_ptr->cxn_timer != NULL) {\r
-               dapls_timer_cancel(ep_ptr->cxn_timer);\r
-               dapl_os_free(ep_ptr->cxn_timer, sizeof(DAPL_OS_TIMER));\r
-               ep_ptr->cxn_timer = NULL;\r
-       }\r
-\r
-       /* Obtain the event number from the provider layer */\r
-       dat_event_num = dapls_ib_get_dat_event(ib_cm_event, DAT_FALSE);\r
-\r
-       switch (dat_event_num) {\r
-       case DAT_CONNECTION_EVENT_ESTABLISHED:\r
-               {\r
-                       /* If we don't have an EP at this point we are very screwed\r
-                        * up\r
-                        */\r
-                       if (ep_ptr->param.ep_state !=\r
-                           DAT_EP_STATE_ACTIVE_CONNECTION_PENDING) {\r
-                               /* If someone pulled the plug on the connection, just\r
-                                * exit\r
-                                */\r
-                               dapl_os_unlock(&ep_ptr->header.lock);\r
-                               dat_status = DAT_SUCCESS;\r
-                               break;\r
-                       }\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_CONNECTED;\r
-                       ep_ptr->cm_handle = ib_cm_handle;\r
-\r
-                       if (private_data_size > 0) {\r
-                               /* copy in the private data */\r
-                               dapl_os_memcpy(ep_ptr->private.private_data,\r
-                                              prd_ptr->private_data,\r
-                                              DAPL_MIN(private_data_size,\r
-                                                       DAPL_MAX_PRIVATE_DATA_SIZE));\r
-                       }\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_PEER_REJECTED:\r
-               {\r
-                       /* peer reject may include private data */\r
-\r
-                       if (private_data_size > 0)\r
-                               dapl_os_memcpy(ep_ptr->private.private_data,\r
-                                              prd_ptr->private_data,\r
-                                              DAPL_MIN(private_data_size,\r
-                                                       DAPL_MAX_PRIVATE_DATA_SIZE));\r
-\r
-                       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,\r
-                                    "dapl_evd_connection_callback PEER REJ pd=%p sz=%d\n",\r
-                                    prd_ptr, private_data_size);\r
-               }\r
-       case DAT_CONNECTION_EVENT_DISCONNECTED:\r
-       case DAT_CONNECTION_EVENT_UNREACHABLE:\r
-       case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:\r
-               {\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE,\r
-                                                 ib_cm_event);\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_EVENT_BROKEN:\r
-       case DAT_CONNECTION_EVENT_TIMED_OUT:\r
-               {\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,\r
-                                                 ib_cm_event);\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-\r
-                       break;\r
-               }\r
-       case DAT_CONNECTION_REQUEST_EVENT:\r
-       default:\r
-               {\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-                       evd_ptr = NULL;\r
-\r
-                       dapl_os_assert(0);      /* shouldn't happen */\r
-                       break;\r
-               }\r
-       }\r
-\r
-       /*\r
-        * Post the event\r
-        * If the EP has been freed, the evd_ptr will be NULL\r
-        */\r
-       if (evd_ptr != NULL) {\r
-               dat_status = dapls_evd_post_connection_event(evd_ptr, dat_event_num, (DAT_HANDLE) ep_ptr, private_data_size,    /* CONNECTED or REJECT */\r
-                                                            ep_ptr->private.\r
-                                                            private_data);\r
-\r
-               if (dat_status != DAT_SUCCESS &&\r
-                   dat_event_num == DAT_CONNECTION_EVENT_ESTABLISHED) {\r
-                       /* We can't tell the user we are connected, something\r
-                        * is wrong locally. Just kill the connection and\r
-                        * reset the state to DISCONNECTED as we don't\r
-                        * expect a callback on an ABRUPT disconnect.\r
-                        */\r
-                       dapls_ib_disconnect(ep_ptr, DAT_CLOSE_ABRUPT_FLAG);\r
-                       dapl_os_lock(&ep_ptr->header.lock);\r
-                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;\r
-                       dapl_os_unlock(&ep_ptr->header.lock);\r
-               }\r
-       }\r
-\r
-       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,\r
-                    "dapl_evd_connection_callback () returns\n");\r
-\r
-}\r
-\r
-/*\r
- * Local variables:\r
- *  c-indent-level: 4\r
- *  c-basic-offset: 4\r
- *  tab-width: 8\r
- * End:\r
- */\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ *
+ * MODULE: dapl_evd_connection_callback.c
+ *
+ * PURPOSE: implements connection callbacks
+ *
+ * Description: Accepts asynchronous callbacks from the Communications Manager
+ *              for EVDs that have been specified as the connection_evd.
+ *
+ * $Id:$
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_evd_util.h"
+#include "dapl_ep_util.h"
+#include "dapl_timer_util.h"
+
+/*
+ * dapl_evd_connection_callback
+ *
+ * Connection callback function for ACTIVE connection requests; callbacks
+ * generated by the Connection Manager in response to issuing a
+ * connect call.
+ *
+ * Input:
+ *     ib_cm_handle,
+ *     ib_cm_event
+ *     private_data_ptr
+ *     context (evd)
+ *     cr_pp
+ *
+ * Output:
+ *     None
+ *
+ */
+
+void
+dapl_evd_connection_callback(IN dp_ib_cm_handle_t ib_cm_handle,
+                            IN const ib_cm_events_t ib_cm_event,
+                            IN const void *private_data_ptr,
+                            IN const int private_data_size,
+                            IN const void *context)
+{
+       DAPL_EP *ep_ptr;
+       DAPL_EVD *evd_ptr;
+       DAPL_PRIVATE *prd_ptr;
+       DAT_EVENT_NUMBER dat_event_num;
+       DAT_RETURN dat_status;
+
+       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
+                    "--> dapl_evd_connection_callback: ctxt: %p event: %x cm_handle %p\n",
+                    context, ib_cm_event, (void *)ib_cm_handle);
+
+       /*
+        * Determine the type of handle passed back to us in the context
+        * and sort out key parameters.
+        */
+       if (context == NULL
+           || ((DAPL_HEADER *) context)->magic != DAPL_MAGIC_EP) {
+               return;
+       }
+
+       /*
+        * Active side of the connection, context is an EP and
+        * PSP is irrelevant.
+        */
+       ep_ptr = (DAPL_EP *) context;
+       evd_ptr = (DAPL_EVD *) ep_ptr->param.connect_evd_handle;
+       DAPL_CNTR(evd_ptr, DCNT_EVD_CONN_CALLBACK);
+
+       prd_ptr = (DAPL_PRIVATE *) private_data_ptr;
+       /*
+        * All operations effect the EP, so lock it once and unlock
+        * when necessary
+        */
+       dapl_os_lock(&ep_ptr->header.lock);
+
+       /*
+        * If a connection timer has been set up on this EP, cancel it now
+        */
+       if (ep_ptr->cxn_timer != NULL) {
+               dapls_timer_cancel(ep_ptr->cxn_timer);
+               dapl_os_free(ep_ptr->cxn_timer, sizeof(DAPL_OS_TIMER));
+               ep_ptr->cxn_timer = NULL;
+       }
+
+       /* Obtain the event number from the provider layer */
+       dat_event_num = dapls_ib_get_dat_event(ib_cm_event, DAT_FALSE);
+
+       switch (dat_event_num) {
+       case DAT_CONNECTION_EVENT_ESTABLISHED:
+               {
+                       /* If we don't have an EP at this point we are very screwed
+                        * up
+                        */
+                       if (ep_ptr->param.ep_state !=
+                           DAT_EP_STATE_ACTIVE_CONNECTION_PENDING) {
+                               /* If someone pulled the plug on the connection, just
+                                * exit
+                                */
+                               dapl_os_unlock(&ep_ptr->header.lock);
+                               dat_status = DAT_SUCCESS;
+                               break;
+                       }
+                       ep_ptr->param.ep_state = DAT_EP_STATE_CONNECTED;
+
+                       if (private_data_size > 0) {
+                               /* copy in the private data */
+                               dapl_os_memcpy(ep_ptr->private.private_data,
+                                              prd_ptr->private_data,
+                                              DAPL_MIN(private_data_size,
+                                                       DAPL_MAX_PRIVATE_DATA_SIZE));
+                       }
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_PEER_REJECTED:
+               {
+                       /* peer reject may include private data */
+
+                       if (private_data_size > 0)
+                               dapl_os_memcpy(ep_ptr->private.private_data,
+                                              prd_ptr->private_data,
+                                              DAPL_MIN(private_data_size,
+                                                       DAPL_MAX_PRIVATE_DATA_SIZE));
+
+                       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
+                                    "dapl_evd_connection_callback PEER REJ pd=%p sz=%d\n",
+                                    prd_ptr, private_data_size);
+               }
+       case DAT_CONNECTION_EVENT_DISCONNECTED:
+       case DAT_CONNECTION_EVENT_UNREACHABLE:
+       case DAT_CONNECTION_EVENT_NON_PEER_REJECTED:
+               {
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapls_ib_disconnect_clean(ep_ptr, DAT_TRUE,
+                                                 ib_cm_event);
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_EVENT_BROKEN:
+       case DAT_CONNECTION_EVENT_TIMED_OUT:
+               {
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapls_ib_disconnect_clean(ep_ptr, DAT_FALSE,
+                                                 ib_cm_event);
+                       dapl_os_unlock(&ep_ptr->header.lock);
+
+                       break;
+               }
+       case DAT_CONNECTION_REQUEST_EVENT:
+       default:
+               {
+                       dapl_os_unlock(&ep_ptr->header.lock);
+                       evd_ptr = NULL;
+
+                       dapl_os_assert(0);      /* shouldn't happen */
+                       break;
+               }
+       }
+
+       /*
+        * Post the event
+        * If the EP has been freed, the evd_ptr will be NULL
+        */
+       if (evd_ptr != NULL) {
+               dat_status = dapls_evd_post_connection_event(evd_ptr, dat_event_num, (DAT_HANDLE) ep_ptr, private_data_size,    /* CONNECTED or REJECT */
+                                                            ep_ptr->private.
+                                                            private_data);
+
+               if (dat_status != DAT_SUCCESS &&
+                   dat_event_num == DAT_CONNECTION_EVENT_ESTABLISHED) {
+                       /* We can't tell the user we are connected, something
+                        * is wrong locally. Just kill the connection and
+                        * reset the state to DISCONNECTED as we don't
+                        * expect a callback on an ABRUPT disconnect.
+                        */
+                       dapls_ib_disconnect(ep_ptr, DAT_CLOSE_ABRUPT_FLAG);
+                       dapl_os_lock(&ep_ptr->header.lock);
+                       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
+                       dapl_os_unlock(&ep_ptr->header.lock);
+               }
+       }
+
+       dapl_dbg_log(DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK,
+                    "dapl_evd_connection_callback () returns\n");
+
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 8
+ * End:
+ */
index cc0aa17..14a10c7 100644 (file)
@@ -1077,7 +1077,7 @@ dapls_evd_post_cr_event_ext(IN DAPL_SP * sp_ptr,
                        ep_ptr->param.ep_state =
                            DAT_EP_STATE_PASSIVE_CONNECTION_PENDING;
                }
-               ep_ptr->cm_handle = ib_cm_handle;
+               dapl_ep_link_cm(ep_ptr, ib_cm_handle);
        }
 
        /* link the CR onto the SP so we can pick it up later */
index 78a75a9..e5a7c3f 100644 (file)
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- * \r
- * HEADER: dapl_evd_util.h\r
- *\r
- * PURPOSE: Utility defs & routines for the EVD data structure\r
- *\r
- * $Id:$\r
- *\r
- **********************************************************************/\r
-\r
-#ifndef _DAPL_EVD_UTIL_H_\r
-#define _DAPL_EVD_UTIL_H_\r
-\r
-#include "dapl.h"\r
-\r
-DAT_RETURN\r
-dapls_evd_internal_create (\r
-    IN DAPL_IA         *ia_ptr, \r
-    IN DAPL_CNO                *cno_ptr,\r
-    IN DAT_COUNT       min_qlen,\r
-    IN DAT_EVD_FLAGS   evd_flags,\r
-    OUT DAPL_EVD       **evd_ptr_ptr) ;\r
-\r
-DAPL_EVD *\r
-dapls_evd_alloc ( \r
-    IN DAPL_IA         *ia_ptr,\r
-    IN DAPL_CNO                *cno_ptr,\r
-    IN DAT_EVD_FLAGS   evd_flags,\r
-    IN DAT_COUNT       qlen) ;\r
-\r
-DAT_RETURN\r
-dapls_evd_dealloc ( \r
-    IN DAPL_EVD        *evd_ptr) ;\r
-\r
-DAT_RETURN dapls_evd_event_realloc (\r
-    IN DAPL_EVD                *evd_ptr,\r
-    IN DAT_COUNT       qlen);\r
-\r
-/*\r
- * Each of these functions will retrieve a free event from\r
- * the specified EVD, fill in the elements of that event, and\r
- * post the event back to the EVD.  If there is no EVD available,\r
- * an overflow event will be posted to the async EVD associated\r
- * with the EVD.\r
- *\r
- * DAT_INSUFFICIENT_RESOURCES will be returned on overflow,\r
- * DAT_SUCCESS otherwise.\r
- */\r
-\r
-DAT_RETURN\r
-dapls_evd_post_cr_arrival_event (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_SP_HANDLE                   sp_handle,\r
-    DAT_IA_ADDRESS_PTR                 ia_address_ptr,\r
-    DAT_CONN_QUAL                      conn_qual,\r
-    DAT_CR_HANDLE                      cr_handle);\r
-    \r
-DAT_RETURN\r
-dapls_evd_post_connection_event (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_EP_HANDLE                   ep_handle,\r
-    IN DAT_COUNT                       private_data_size,\r
-    IN DAT_PVOID                       private_data);\r
-\r
-DAT_RETURN\r
-dapls_evd_post_async_error_event (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_IA_HANDLE                   ia_handle);\r
-\r
-DAT_RETURN\r
-dapls_evd_post_software_event (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_PVOID                       pointer);\r
-\r
-DAT_RETURN\r
-dapls_evd_post_generic_event (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_EVENT_DATA                  *data);\r
-\r
-#ifdef DAT_EXTENSIONS\r
-DAT_RETURN\r
-dapls_evd_post_cr_event_ext (\r
-    IN DAPL_SP                         *sp_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN dp_ib_cm_handle_t               ib_cm_handle,\r
-    IN DAT_COUNT                       p_size,\r
-    IN DAT_PVOID                       p_data,\r
-    IN DAT_PVOID                       ext_data);\r
-\r
-DAT_RETURN\r
-dapls_evd_post_connection_event_ext (\r
-    IN DAPL_EVD                                *evd_ptr,\r
-    IN DAT_EVENT_NUMBER                        event_number,\r
-    IN DAT_EP_HANDLE                   ep_handle,\r
-    IN DAT_COUNT                       private_data_size,\r
-    IN DAT_PVOID                       private_data,\r
-    IN DAT_PVOID                       ext_data);\r
-#endif\r
-\r
-/*************************************\r
- * dapl internal callbacks functions *\r
- *************************************/\r
-\r
-/* connection verb callback */\r
-extern void dapl_evd_connection_callback (\r
-    IN dp_ib_cm_handle_t       ib_cm_handle,\r
-    IN const ib_cm_events_t    ib_cm_events,\r
-    IN const void              *private_data_ptr,\r
-    IN const int               private_data_size,\r
-    IN const void *            context );\r
-\r
-/* dto verb callback */\r
-extern void dapl_evd_dto_callback (\r
-    IN  ib_hca_handle_t        ib_hca_handle, \r
-    IN  ib_cq_handle_t                 ib_cq_handle, \r
-    IN  void*                  context);\r
-\r
-/* async verb callbacks */\r
-extern void dapl_evd_un_async_error_callback (\r
-    IN ib_hca_handle_t         ib_hca_handle,\r
-    IN ib_error_record_t *     cause_ptr,\r
-    IN void *                  context);\r
-\r
-extern void dapl_evd_cq_async_error_callback (\r
-    IN ib_hca_handle_t         ib_hca_handle,\r
-    IN ib_cq_handle_t          ib_cq_handle,\r
-    IN ib_error_record_t *     cause_ptr,\r
-    IN void *                  context);\r
-\r
-extern void dapl_evd_qp_async_error_callback (\r
-    IN ib_hca_handle_t         ib_hca_handle,\r
-    IN ib_qp_handle_t          ib_qp_handle,\r
-    IN ib_error_record_t *     cause_ptr,\r
-    IN void *                  context);\r
-\r
-extern void dapls_evd_copy_cq (\r
-    DAPL_EVD                   *evd_ptr);\r
-\r
-extern DAT_RETURN dapls_evd_cq_poll_to_event (\r
-    IN DAPL_EVD                *evd_ptr,\r
-    OUT DAT_EVENT              *event);\r
-\r
-#endif\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ * 
+ * HEADER: dapl_evd_util.h
+ *
+ * PURPOSE: Utility defs & routines for the EVD data structure
+ *
+ * $Id:$
+ *
+ **********************************************************************/
+
+#ifndef _DAPL_EVD_UTIL_H_
+#define _DAPL_EVD_UTIL_H_
+
+#include "dapl.h"
+
+DAT_RETURN
+dapls_evd_internal_create (
+    IN DAPL_IA         *ia_ptr, 
+    IN DAPL_CNO                *cno_ptr,
+    IN DAT_COUNT       min_qlen,
+    IN DAT_EVD_FLAGS   evd_flags,
+    OUT DAPL_EVD       **evd_ptr_ptr) ;
+
+DAPL_EVD *
+dapls_evd_alloc ( 
+    IN DAPL_IA         *ia_ptr,
+    IN DAPL_CNO                *cno_ptr,
+    IN DAT_EVD_FLAGS   evd_flags,
+    IN DAT_COUNT       qlen) ;
+
+DAT_RETURN
+dapls_evd_dealloc ( 
+    IN DAPL_EVD        *evd_ptr) ;
+
+DAT_RETURN dapls_evd_event_realloc (
+    IN DAPL_EVD                *evd_ptr,
+    IN DAT_COUNT       qlen);
+
+/*
+ * Each of these functions will retrieve a free event from
+ * the specified EVD, fill in the elements of that event, and
+ * post the event back to the EVD.  If there is no EVD available,
+ * an overflow event will be posted to the async EVD associated
+ * with the EVD.
+ *
+ * DAT_INSUFFICIENT_RESOURCES will be returned on overflow,
+ * DAT_SUCCESS otherwise.
+ */
+
+DAT_RETURN
+dapls_evd_post_cr_arrival_event (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_SP_HANDLE                   sp_handle,
+    DAT_IA_ADDRESS_PTR                 ia_address_ptr,
+    DAT_CONN_QUAL                      conn_qual,
+    DAT_CR_HANDLE                      cr_handle);
+    
+DAT_RETURN
+dapls_evd_post_connection_event (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_EP_HANDLE                   ep_handle,
+    IN DAT_COUNT                       private_data_size,
+    IN DAT_PVOID                       private_data);
+
+DAT_RETURN
+dapls_evd_post_async_error_event (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_IA_HANDLE                   ia_handle);
+
+DAT_RETURN
+dapls_evd_post_software_event (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_PVOID                       pointer);
+
+DAT_RETURN
+dapls_evd_post_generic_event (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_EVENT_DATA                  *data);
+
+#ifdef DAT_EXTENSIONS
+DAT_RETURN
+dapls_evd_post_cr_event_ext (
+    IN DAPL_SP                         *sp_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN dp_ib_cm_handle_t               ib_cm_handle,
+    IN DAT_COUNT                       p_size,
+    IN DAT_PVOID                       p_data,
+    IN DAT_PVOID                       ext_data);
+
+DAT_RETURN
+dapls_evd_post_connection_event_ext (
+    IN DAPL_EVD                                *evd_ptr,
+    IN DAT_EVENT_NUMBER                        event_number,
+    IN DAT_EP_HANDLE                   ep_handle,
+    IN DAT_COUNT                       private_data_size,
+    IN DAT_PVOID                       private_data,
+    IN DAT_PVOID                       ext_data);
+#endif
+
+/*************************************
+ * dapl internal callbacks functions *
+ *************************************/
+
+/* connection verb callback */
+extern void dapl_evd_connection_callback (
+    IN dp_ib_cm_handle_t       ib_cm_handle,
+    IN const ib_cm_events_t    ib_cm_events,
+    IN const void              *private_data_ptr,
+    IN const int               private_data_size,
+    IN const void *            context );
+
+/* dto verb callback */
+extern void dapl_evd_dto_callback (
+    IN  ib_hca_handle_t        ib_hca_handle, 
+    IN  ib_cq_handle_t                 ib_cq_handle, 
+    IN  void*                  context);
+
+/* async verb callbacks */
+extern void dapl_evd_un_async_error_callback (
+    IN ib_hca_handle_t         ib_hca_handle,
+    IN ib_error_record_t *     cause_ptr,
+    IN void *                  context);
+
+extern void dapl_evd_cq_async_error_callback (
+    IN ib_hca_handle_t         ib_hca_handle,
+    IN ib_cq_handle_t          ib_cq_handle,
+    IN ib_error_record_t *     cause_ptr,
+    IN void *                  context);
+
+extern void dapl_evd_qp_async_error_callback (
+    IN ib_hca_handle_t         ib_hca_handle,
+    IN ib_qp_handle_t          ib_qp_handle,
+    IN ib_error_record_t *     cause_ptr,
+    IN void *                  context);
+
+extern void dapls_evd_copy_cq (
+    DAPL_EVD                   *evd_ptr);
+
+extern DAT_RETURN dapls_evd_cq_poll_to_event (
+    IN DAPL_EVD                *evd_ptr,
+    OUT DAT_EVENT              *event);
+
+#endif
index 093ed1c..d530d72 100644 (file)
-/*\r
- * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.\r
- *\r
- * This Software is licensed under one of the following licenses:\r
- *\r
- * 1) under the terms of the "Common Public License 1.0" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/cpl.php.\r
- *\r
- * 2) under the terms of the "The BSD License" a copy of which is\r
- *    available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/bsd-license.php.\r
- *\r
- * 3) under the terms of the "GNU General Public License (GPL) Version 2" a\r
- *    copy of which is available from the Open Source Initiative, see\r
- *    http://www.opensource.org/licenses/gpl-license.php.\r
- *\r
- * Licensee has the right to choose one of the above licenses.\r
- *\r
- * Redistributions of source code must retain the above copyright\r
- * notice and one of the license notices.\r
- *\r
- * Redistributions in binary form must reproduce both the above copyright\r
- * notice, one of the license notices in the documentation\r
- * and/or other materials provided with the distribution.\r
- */\r
-\r
-/**********************************************************************\r
- * \r
- * MODULE: dapl_ia_query.c\r
- *\r
- * PURPOSE: Interface Adapter management\r
- * Description: Interfaces in this file are completely described in\r
- *             the DAPL 1.1 API, Chapter 6, section 2\r
- *\r
- * $Id:$\r
- **********************************************************************/\r
-\r
-#include "dapl.h"\r
-#include "dapl_adapter_util.h"\r
-#include "dapl_vendor.h"\r
-\r
-/*\r
- * dapl_ia_query\r
- *\r
- * DAPL Requirements Version xxx, 6.2.1.3\r
- *\r
- * Provide the consumer with Interface Adapter and Provider parameters.\r
- *\r
- * Input:\r
- *     ia_handle\r
- *     ia_mask\r
- *     provider_mask\r
- *\r
- * Output:\r
- *     async_evd_handle\r
- *     ia_parameters\r
- *     provider_parameters\r
- *\r
- * Returns:\r
- *     DAT_SUCCESS\r
- *     DAT_INVALID_PARAMETER\r
- */\r
-DAT_RETURN DAT_API\r
-dapl_ia_query(IN DAT_IA_HANDLE ia_handle,\r
-             OUT DAT_EVD_HANDLE * async_evd_handle,\r
-             IN DAT_IA_ATTR_MASK ia_attr_mask,\r
-             OUT DAT_IA_ATTR * ia_attr,\r
-             IN DAT_PROVIDER_ATTR_MASK provider_attr_mask,\r
-             OUT DAT_PROVIDER_ATTR * provider_attr)\r
-{\r
-       DAPL_IA *ia_ptr;\r
-       DAT_RETURN dat_status;\r
-       struct evd_merge_type {\r
-               DAT_BOOLEAN array[6][6];\r
-       } *evd_merge;\r
-       DAT_BOOLEAN val;\r
-       int i;\r
-       int j;\r
-\r
-       dapl_dbg_log(DAPL_DBG_TYPE_API,\r
-                    "dapl_ia_query (%p, %p, 0x%llx, %p, 0x%x, %p)\n",\r
-                    ia_handle,\r
-                    async_evd_handle,\r
-                    ia_attr_mask, ia_attr, provider_attr_mask, provider_attr);\r
-\r
-       ia_ptr = (DAPL_IA *) ia_handle;\r
-       dat_status = DAT_SUCCESS;\r
-\r
-       if (DAPL_BAD_HANDLE(ia_ptr, DAPL_MAGIC_IA)) {\r
-               dat_status =\r
-                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_IA);\r
-               goto bail;\r
-       }\r
-\r
-       if (NULL != async_evd_handle) {\r
-               *async_evd_handle = ia_ptr->async_error_evd;\r
-       }\r
-\r
-       if (ia_attr_mask & DAT_IA_FIELD_ALL) {\r
-               if (NULL == ia_attr) {\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);\r
-                       goto bail;\r
-               }\r
-\r
-               /*\r
-                * Obtain parameters from the HCA.  Protect against multiple\r
-                * IAs beating on the HCA at the same time.\r
-                */\r
-               dat_status =\r
-                   dapls_ib_query_hca(ia_ptr->hca_ptr, ia_attr, NULL, NULL);\r
-               if (dat_status != DAT_SUCCESS) {\r
-                       goto bail;\r
-               }\r
-       }\r
-\r
-       if (ia_attr_mask & ~DAT_IA_FIELD_ALL) {\r
-               dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);\r
-               goto bail;\r
-       }\r
-\r
-       if (provider_attr_mask & DAT_PROVIDER_FIELD_ALL) {\r
-               if (NULL == provider_attr) {\r
-                       dat_status =\r
-                           DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG6);\r
-                       goto bail;\r
-               }\r
-\r
-               strncpy(provider_attr->provider_name,\r
-                       ia_ptr->header.provider->device_name,\r
-                       DAT_NAME_MAX_LENGTH);\r
-               provider_attr->provider_version_major = VN_PROVIDER_MAJOR;\r
-               provider_attr->provider_version_minor = VN_PROVIDER_MINOR;\r
-               provider_attr->dapl_version_major = DAT_VERSION_MAJOR;\r
-               provider_attr->dapl_version_minor = DAT_VERSION_MINOR;\r
-               provider_attr->lmr_mem_types_supported =\r
-                   DAT_MEM_TYPE_VIRTUAL | DAT_MEM_TYPE_LMR;\r
-#if VN_MEM_SHARED_VIRTUAL_SUPPORT > 0 && !defined(__KDAPL__)\r
-               provider_attr->lmr_mem_types_supported |=\r
-                   DAT_MEM_TYPE_SHARED_VIRTUAL;\r
-#endif\r
-               provider_attr->iov_ownership_on_return = DAT_IOV_CONSUMER;\r
-               provider_attr->dat_qos_supported = DAT_QOS_BEST_EFFORT;\r
-               provider_attr->completion_flags_supported =\r
-                   DAT_COMPLETION_DEFAULT_FLAG;\r
-               provider_attr->is_thread_safe = DAT_FALSE;\r
-               /*\r
-                * N.B. The second part of the following equation will evaluate\r
-                *      to 0 unless IBHOSTS_NAMING is enabled.\r
-                */\r
-               provider_attr->max_private_data_size =\r
-                   dapls_ib_private_data_size(ia_ptr->hca_ptr) -\r
-                   (sizeof(DAPL_PRIVATE) - DAPL_MAX_PRIVATE_DATA_SIZE);\r
-               provider_attr->supports_multipath = DAT_FALSE;\r
-               provider_attr->ep_creator = DAT_PSP_CREATES_EP_NEVER;\r
-               provider_attr->optimal_buffer_alignment = DAT_OPTIMAL_ALIGNMENT;\r
-               /* The value of pz_support may vary by transport */\r
-               provider_attr->num_provider_specific_attr = 0;\r
-               provider_attr->provider_specific_attr = NULL;\r
-#if !defined(__KDAPL__)\r
-               provider_attr->pz_support = DAT_PZ_UNIQUE;\r
-#endif                         /* !KDAPL */\r
-\r
-               /*\r
-                *  Query for provider specific attributes\r
-                */\r
-               dapls_query_provider_specific_attr(ia_ptr, provider_attr);\r
-\r
-               /*\r
-                * Set up evd_stream_merging_supported options. Note there is\r
-                * one bit per allowable combination, using the ordinal\r
-                * position of the DAT_EVD_FLAGS as positions in the\r
-                * array. e.g.\r
-                * [0][0] is DAT_EVD_SOFTWARE_FLAG | DAT_EVD_SOFTWARE_FLAG,\r
-                * [0][1] is DAT_EVD_SOFTWARE_FLAG | DAT_EVD_CR_FLAG, and\r
-                * [2][4] is DAT_EVD_DTO_FLAG | DAT_EVD_RMR_BIND_FLAG\r
-                *\r
-                * Most combinations are true, so initialize the array that way.\r
-                * Then finish by resetting the bad combinations.\r
-                *\r
-                * DAT_EVD_ASYNC_FLAG is not supported. InfiniBand only allows\r
-                * a single asynchronous event handle per HCA, and the first\r
-                * dat_ia_open forces the creation of the only one that can be\r
-                * used. We disallow the user from creating an ASYNC EVD here.\r
-                */\r
-\r
-               evd_merge =\r
-                   (struct evd_merge_type *)&provider_attr->\r
-                   evd_stream_merging_supported[0][0];\r
-               val = DAT_TRUE;\r
-               for (i = 0; i < 6; i++) {\r
-                       if (i > 4) {\r
-                               /* ASYNC EVD is 5, so entire row will be 0 */\r
-                               val = DAT_FALSE;\r
-                       }\r
-                       for (j = 0; j < 5; j++) {\r
-                               evd_merge->array[i][j] = val;\r
-                       }\r
-                       /* Set the ASYNC_EVD column to FALSE */\r
-                       evd_merge->array[i][5] = DAT_FALSE;\r
-               }\r
-\r
-#ifndef DAPL_MERGE_CM_DTO\r
-               /*\r
-                * If an implementation supports CM and DTO completions on\r
-                * the same EVD then DAPL_MERGE_CM_DTO should be set to\r
-                * skip the following code\r
-                */\r
-               /* DAT_EVD_DTO_FLAG | DAT_EVD_CONNECTION_FLAG */\r
-               evd_merge->array[2][3] = DAT_FALSE;\r
-               /* DAT_EVD_CONNECTION_FLAG | DAT_EVD_DTO_FLAG */\r
-               evd_merge->array[3][2] = DAT_FALSE;\r
-#endif                         /* DAPL_MERGE_CM_DTO */\r
-       }\r
-\r
-      bail:\r
-       if (dat_status != DAT_SUCCESS) {\r
-               dapl_dbg_log(DAPL_DBG_TYPE_RTN,\r
-                            "dapl_ia_query () returns 0x%x\n", dat_status);\r
-       }\r
-\r
-       return dat_status;\r
-}\r
-\r
-/*\r
- * Local variables:\r
- *  c-indent-level: 4\r
- *  c-basic-offset: 4\r
- *  tab-width: 8\r
- * End:\r
- */\r
+/*
+ * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
+ *
+ * This Software is licensed under one of the following licenses:
+ *
+ * 1) under the terms of the "Common Public License 1.0" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/cpl.php.
+ *
+ * 2) under the terms of the "The BSD License" a copy of which is
+ *    available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
+ *    copy of which is available from the Open Source Initiative, see
+ *    http://www.opensource.org/licenses/gpl-license.php.
+ *
+ * Licensee has the right to choose one of the above licenses.
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice and one of the license notices.
+ *
+ * Redistributions in binary form must reproduce both the above copyright
+ * notice, one of the license notices in the documentation
+ * and/or other materials provided with the distribution.
+ */
+
+/**********************************************************************
+ * 
+ * MODULE: dapl_ia_query.c
+ *
+ * PURPOSE: Interface Adapter management
+ * Description: Interfaces in this file are completely described in
+ *             the DAPL 1.1 API, Chapter 6, section 2
+ *
+ * $Id:$
+ **********************************************************************/
+
+#include "dapl.h"
+#include "dapl_adapter_util.h"
+#include "dapl_vendor.h"
+
+/*
+ * dapl_ia_query
+ *
+ * DAPL Requirements Version xxx, 6.2.1.3
+ *
+ * Provide the consumer with Interface Adapter and Provider parameters.
+ *
+ * Input:
+ *     ia_handle
+ *     ia_mask
+ *     provider_mask
+ *
+ * Output:
+ *     async_evd_handle
+ *     ia_parameters
+ *     provider_parameters
+ *
+ * Returns:
+ *     DAT_SUCCESS
+ *     DAT_INVALID_PARAMETER
+ */
+DAT_RETURN DAT_API
+dapl_ia_query(IN DAT_IA_HANDLE ia_handle,
+             OUT DAT_EVD_HANDLE * async_evd_handle,
+             IN DAT_IA_ATTR_MASK ia_attr_mask,
+             OUT DAT_IA_ATTR * ia_attr,
+             IN DAT_PROVIDER_ATTR_MASK provider_attr_mask,
+             OUT DAT_PROVIDER_ATTR * provider_attr)
+{
+       DAPL_IA *ia_ptr;
+       DAT_RETURN dat_status;
+       struct evd_merge_type {
+               DAT_BOOLEAN array[6][6];
+       } *evd_merge;
+       DAT_BOOLEAN val;
+       int i;
+       int j;
+
+       dapl_dbg_log(DAPL_DBG_TYPE_API,
+                    "dapl_ia_query (%p, %p, 0x%llx, %p, 0x%x, %p)\n",
+                    ia_handle,
+                    async_evd_handle,
+                    ia_attr_mask, ia_attr, provider_attr_mask, provider_attr);
+
+       ia_ptr = (DAPL_IA *) ia_handle;
+       dat_status = DAT_SUCCESS;
+
+       if (DAPL_BAD_HANDLE(ia_ptr, DAPL_MAGIC_IA)) {
+               dat_status =
+                   DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_IA);
+               goto bail;
+       }
+
+       if (NULL != async_evd_handle) {
+               *async_evd_handle = ia_ptr->async_error_evd;
+       }
+
+       if (ia_attr_mask & DAT_IA_FIELD_ALL) {
+               if (NULL == ia_attr) {
+                       dat_status =
+                           DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
+                       goto bail;
+               }
+
+               /*
+                * Obtain parameters from the HCA.  Protect against multiple
+                * IAs beating on the HCA at the same time.
+                */
+               dat_status =
+                   dapls_ib_query_hca(ia_ptr->hca_ptr, ia_attr, NULL, NULL);
+               if (dat_status != DAT_SUCCESS) {
+                       goto bail;
+               }
+       }
+
+       if (ia_attr_mask & ~DAT_IA_FIELD_ALL) {
+               dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);
+               goto bail;
+       }
+
+       if (provider_attr_mask & DAT_PROVIDER_FIELD_ALL) {
+               if (NULL == provider_attr) {
+                       dat_status =
+                           DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG6);
+                       goto bail;
+               }
+
+               strncpy(provider_attr->provider_name,
+                       ia_ptr->header.provider->device_name,
+                       DAT_NAME_MAX_LENGTH);
+               provider_attr->provider_version_major = VN_PROVIDER_MAJOR;
+               provider_attr->provider_version_minor = VN_PROVIDER_MINOR;
+               provider_attr->dapl_version_major = DAT_VERSION_MAJOR;
+               provider_attr->dapl_version_minor = DAT_VERSION_MINOR;
+               provider_attr->lmr_mem_types_supported =
+                   DAT_MEM_TYPE_VIRTUAL | DAT_MEM_TYPE_LMR;
+#if VN_MEM_SHARED_VIRTUAL_SUPPORT > 0 && !defined(__KDAPL__)
+               provider_attr->lmr_mem_types_supported |=
+                   DAT_MEM_TYPE_SHARED_VIRTUAL;
+#endif
+               provider_attr->iov_ownership_on_return = DAT_IOV_CONSUMER;
+               provider_attr->dat_qos_supported = DAT_QOS_BEST_EFFORT;
+               provider_attr->completion_flags_supported =
+                   DAT_COMPLETION_DEFAULT_FLAG;
+               provider_attr->is_thread_safe = DAT_FALSE;
+               /*
+                * N.B. The second part of the following equation will evaluate
+                *      to 0 unless IBHOSTS_NAMING is enabled.
+                */
+               provider_attr->max_private_data_size =
+                   dapls_ib_private_data_size(ia_ptr->hca_ptr) -
+                   (sizeof(DAPL_PRIVATE) - DAPL_MAX_PRIVATE_DATA_SIZE);
+               provider_attr->supports_multipath = DAT_FALSE;
+               provider_attr->ep_creator = DAT_PSP_CREATES_EP_NEVER;
+               provider_attr->optimal_buffer_alignment = DAT_OPTIMAL_ALIGNMENT;
+               /* The value of pz_support may vary by transport */
+               provider_attr->num_provider_specific_attr = 0;
+               provider_attr->provider_specific_attr = NULL;
+#if !defined(__KDAPL__)
+               provider_attr->pz_support = DAT_PZ_UNIQUE;
+#endif                         /* !KDAPL */
+
+               /*
+                *  Query for provider specific attributes
+                */
+               dapls_query_provider_specific_attr(ia_ptr, provider_attr);
+
+               /*
+                * Set up evd_stream_merging_supported options. Note there is
+                * one bit per allowable combination, using the ordinal
+                * position of the DAT_EVD_FLAGS as positions in the
+                * array. e.g.
+                * [0][0] is DAT_EVD_SOFTWARE_FLAG | DAT_EVD_SOFTWARE_FLAG,
+                * [0][1] is DAT_EVD_SOFTWARE_FLAG | DAT_EVD_CR_FLAG, and
+                * [2][4] is DAT_EVD_DTO_FLAG | DAT_EVD_RMR_BIND_FLAG
+                *
+                * Most combinations are true, so initialize the array that way.
+                * Then finish by resetting the bad combinations.
+                *
+                * DAT_EVD_ASYNC_FLAG is not supported. InfiniBand only allows
+                * a single asynchronous event handle per HCA, and the first
+                * dat_ia_open forces the creation of the only one that can be
+                * used. We disallow the user from creating an ASYNC EVD here.
+                */
+
+               evd_merge =
+                   (struct evd_merge_type *)&provider_attr->
+                   evd_stream_merging_supported[0][0];
+               val = DAT_TRUE;
+               for (i = 0; i < 6; i++) {
+                       if (i > 4) {
+                               /* ASYNC EVD is 5, so entire row will be 0 */
+                               val = DAT_FALSE;
+                       }
+                       for (j = 0; j < 5; j++) {
+                               evd_merge->array[i][j] = val;
+                       }
+                       /* Set the ASYNC_EVD column to FALSE */
+                       evd_merge->array[i][5] = DAT_FALSE;
+               }
+
+#ifndef DAPL_MERGE_CM_DTO
+               /*
+                * If an implementation supports CM and DTO completions on
+                * the same EVD then DAPL_MERGE_CM_DTO should be set to
+                * skip the following code
+                */
+               /* DAT_EVD_DTO_FLAG | DAT_EVD_CONNECTION_FLAG */
+               evd_merge->array[2][3] = DAT_FALSE;
+               /* DAT_EVD_CONNECTION_FLAG | DAT_EVD_DTO_FLAG */
+               evd_merge->array[3][2] = DAT_FALSE;
+#endif                         /* DAPL_MERGE_CM_DTO */
+       }
+
+      bail:
+       if (dat_status != DAT_SUCCESS) {
+               dapl_dbg_log(DAPL_DBG_TYPE_RTN,
+                            "dapl_ia_query () returns 0x%x\n", dat_status);
+       }
+
+       return dat_status;
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 8
+ * End:
+ */
index 7d42b49..a35b118 100644 (file)
@@ -16,7 +16,7 @@
  *\r
  * PURPOSE: IB Connection routines for access to IBAL APIs\r
  *\r
- * $Id$\r
+ * $Id: dapl_ibal_cm.c 584 2007-02-07 13:12:18Z sleybo $\r
  *\r
  **********************************************************************/\r
 \r
@@ -94,7 +94,7 @@ void dapli_print_private_data( char *prefix, const uint8_t *pd, int len )
     if ( !pd || len <= 0 )\r
        return;\r
 \r
-    dapl_log ( DAPL_DBG_TYPE_CM, "--> %s: private_data:\n    ",prefix);\r
+    dapl_log ( DAPL_DBG_TYPE_CM, "--> %s: private_data(len %d)\n    ",prefix,len);\r
 \r
     if (len > IB_MAX_REP_PDATA_SIZE)\r
     {\r
@@ -107,13 +107,70 @@ void dapli_print_private_data( char *prefix, const uint8_t *pd, int len )
     for ( i = 0 ; i < len; i++ )\r
     {\r
        dapl_log ( DAPL_DBG_TYPE_CM, "%2x ", pd[i]);\r
-       if ( ((i+1) % 20) == 0 ) \r
+       if ( ((i+1) % 5) == 0 ) \r
            dapl_log ( DAPL_DBG_TYPE_CM, "\n    ");\r
     }\r
    dapl_log ( DAPL_DBG_TYPE_CM, "\n");\r
 }\r
 #endif\r
 \r
+/* EP-CM linking support */\r
+dp_ib_cm_handle_t ibal_cm_alloc(void)\r
+{\r
+       dp_ib_cm_handle_t cm_ptr;\r
+\r
+       /* Allocate CM, init lock, and initialize */\r
+       if ((cm_ptr = dapl_os_alloc(sizeof(*cm_ptr))) == NULL)\r
+               return NULL;\r
+\r
+       (void)dapl_os_memzero(cm_ptr, sizeof(*cm_ptr));\r
+       cm_ptr->ref_count = 1;\r
+\r
+       if (dapl_os_lock_init(&cm_ptr->lock)) {\r
+               dapl_os_free(cm_ptr, sizeof(*cm_ptr));\r
+               return NULL;\r
+       }\r
+\r
+       dapl_llist_init_entry((DAPL_LLIST_ENTRY *)&cm_ptr->list_entry);\r
+       \r
+       return cm_ptr;\r
+}\r
+\r
+/* free CM object resources */\r
+static void ibal_cm_dealloc(dp_ib_cm_handle_t cm_ptr) \r
+{\r
+       dapl_os_assert(!cm_ptr->ref_count);\r
+       dapl_os_lock_destroy(&cm_ptr->lock);\r
+       dapl_os_free(cm_ptr, sizeof(*cm_ptr));\r
+}\r
+\r
+void dapls_cm_acquire(dp_ib_cm_handle_t cm_ptr)\r
+{\r
+       dapl_os_lock(&cm_ptr->lock);\r
+       cm_ptr->ref_count++;\r
+       dapl_os_unlock(&cm_ptr->lock);\r
+}\r
+\r
+void dapls_cm_release(dp_ib_cm_handle_t cm_ptr)\r
+{\r
+       dapl_os_lock(&cm_ptr->lock);\r
+       cm_ptr->ref_count--;\r
+       if (cm_ptr->ref_count) {\r
+                dapl_os_unlock(&cm_ptr->lock);\r
+               return;\r
+       }\r
+       dapl_os_unlock(&cm_ptr->lock);\r
+       ibal_cm_dealloc(cm_ptr);\r
+}\r
+\r
+/* blocking: called from user thread dapl_ep_free() only */\r
+void dapls_cm_free(dp_ib_cm_handle_t cm_ptr)\r
+{\r
+       dapl_ep_unlink_cm(cm_ptr->ep, cm_ptr);\r
+\r
+       /* final reference, alloc */\r
+       dapls_cm_release(cm_ptr);\r
+}\r
 \r
 static void \r
 dapli_ib_cm_apr_cb (\r
@@ -147,6 +204,7 @@ dapli_ib_cm_dreq_cb (
     ib_cm_drep_t        cm_drep;\r
     DAPL_EP             *ep_ptr;\r
     int                        bail=10;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
     \r
     dapl_os_assert (p_cm_dreq_rec);\r
 \r
@@ -168,6 +226,14 @@ dapli_ib_cm_dreq_cb (
                       DAPL_MAGIC_EP );\r
         return;\r
     }\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
+        return;\r
+    }\r
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_dreq_rec->h_cm_dreq.h_qp);\r
 \r
     dapl_dbg_log (DAPL_DBG_TYPE_CM, \r
                   "--> %s() EP %p, %s sent_discreq %s\n",\r
@@ -210,10 +276,8 @@ dapli_ib_cm_dreq_cb (
           \r
     if (ep_ptr->cr_ptr)\r
     {\r
-        dapl_os_assert(ep_ptr->ibal_cm_handle->cid\r
-                                             == p_cm_dreq_rec->h_cm_dreq.cid);\r
         /* passive side */\r
-        dapls_cr_callback ( ep_ptr->cm_handle,\r
+        dapls_cr_callback ( cm_ptr,\r
                             IB_CME_DISCONNECTED,\r
                             (void * __ptr64) p_cm_dreq_rec->p_dreq_pdata,\r
                            IB_DREQ_PDATA_SIZE,\r
@@ -223,7 +287,7 @@ dapli_ib_cm_dreq_cb (
     {\r
         /* active side */\r
         dapl_evd_connection_callback (\r
-                                  (dp_ib_cm_handle_t) &p_cm_dreq_rec->h_cm_dreq,\r
+                                  cm_ptr,\r
                                   IB_CME_DISCONNECTED,\r
                                   (void * __ptr64)\r
                                   p_cm_dreq_rec->p_dreq_pdata,\r
@@ -242,6 +306,7 @@ dapli_ib_cm_drep_cb (
         IN    ib_cm_drep_rec_t          *p_cm_drep_rec )\r
 {\r
     DAPL_EP            *ep_ptr;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
     \r
     dapl_os_assert (p_cm_drep_rec != NULL);\r
 \r
@@ -260,11 +325,19 @@ dapli_ib_cm_drep_cb (
                   "--> %s: BAD EP Handle EP=%lx\n", __FUNCTION__,ep_ptr); \r
         return;\r
     }\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
+        return;\r
+    }\r
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_drep_rec->h_qp);\r
     \r
     dapl_dbg_log (DAPL_DBG_TYPE_CM, \r
        "--> DiCDpcb: EP %p state %s cm_hdl %p\n",ep_ptr,\r
                   dapl_get_ep_state_str(ep_ptr->param.ep_state),\r
-                  ep_ptr->cm_handle);\r
+                  cm_ptr);\r
 \r
     if ( ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED )\r
     {\r
@@ -274,17 +347,10 @@ dapli_ib_cm_drep_cb (
         return;\r
     }\r
 \r
-    if (ep_ptr->cm_handle == DAPL_IB_INVALID_HANDLE )\r
-    {\r
-         dapl_dbg_log (DAPL_DBG_TYPE_CM,\r
-                  "--> %s: Invalid EP->CM handle?\n", __FUNCTION__); \r
-        return;\r
-    }\r
-\r
     if (ep_ptr->cr_ptr)\r
     {\r
         /* passive connection side */\r
-        dapls_cr_callback ( ep_ptr->cm_handle,\r
+        dapls_cr_callback ( cm_ptr,\r
                             IB_CME_DISCONNECTED,\r
                            (void * __ptr64) p_cm_drep_rec->p_drep_pdata,\r
                           IB_DREP_PDATA_SIZE,\r
@@ -294,7 +360,7 @@ dapli_ib_cm_drep_cb (
     {\r
         /* active connection side */\r
         dapl_evd_connection_callback (\r
-                                   ep_ptr->cm_handle,\r
+                                   cm_ptr,\r
                                    IB_CME_DISCONNECTED,\r
                                    (void * __ptr64) p_cm_drep_rec->p_drep_pdata,\r
                                   IB_DREP_PDATA_SIZE,\r
@@ -316,6 +382,7 @@ dapli_ib_cm_rep_cb (
     DAPL_PRIVATE        *prd_ptr;\r
     DAPL_EP             *ep_ptr;\r
     dapl_ibal_ca_t      *p_ca;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
         \r
     dapl_os_assert (p_cm_rep_rec != NULL);\r
 \r
@@ -327,8 +394,17 @@ dapli_ib_cm_rep_cb (
                       __FUNCTION__, ep_ptr);\r
         return;\r
     }\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
+        return;\r
+    }\r
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rep_rec->h_cm_rep.h_qp);\r
+\r
     dapl_dbg_log (DAPL_DBG_TYPE_CM, \r
-                  "--> DiCRpcb: EP %lx local_max_rdma_read_in %d\n", \r
+                  "--> DiCRpcb: EP %lx local_max_rdma_read_in %d\n", \r
                   ep_ptr, p_cm_rep_rec->resp_res);\r
 \r
     p_ca   = (dapl_ibal_ca_t *) \r
@@ -372,7 +448,7 @@ dapli_ib_cm_rep_cb (
 #endif\r
 \r
     dapl_evd_connection_callback ( \r
-                            (dp_ib_cm_handle_t)&p_cm_rep_rec->h_cm_rep,\r
+                            cm_ptr,\r
                             cm_cb_op,\r
                             (void *) prd_ptr,\r
                            IB_REP_PDATA_SIZE,\r
@@ -386,6 +462,7 @@ dapli_ib_cm_rej_cb (
 {\r
     DAPL_EP         *ep_ptr;\r
     ib_cm_events_t  cm_event;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
 \r
     dapl_os_assert (p_cm_rej_rec);\r
 \r
@@ -397,6 +474,14 @@ dapli_ib_cm_rej_cb (
                       __FUNCTION__, ep_ptr);\r
         return;\r
     }\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, \r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
+        return;\r
+    }\r
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rej_rec->h_qp);\r
 \r
     dapl_dbg_log (DAPL_DBG_TYPE_CM, \r
                   "--> DiCRjcb: EP = %lx QP = %lx rej reason = 0x%x\n", \r
@@ -456,7 +541,7 @@ dapli_ib_cm_rej_cb (
 \r
     if (ep_ptr->cr_ptr)\r
     {\r
-        dapls_cr_callback ( ep_ptr->cm_handle,\r
+        dapls_cr_callback ( cm_ptr,\r
                             cm_event,\r
                             (void * __ptr64) p_cm_rej_rec->p_rej_pdata,\r
                            IB_REJ_PDATA_SIZE,\r
@@ -465,7 +550,7 @@ dapli_ib_cm_rej_cb (
     else\r
     {\r
         dapl_evd_connection_callback (\r
-                                   ep_ptr->cm_handle,\r
+                                   cm_ptr,\r
                                    cm_event,\r
                                    (void * __ptr64) p_cm_rej_rec->p_rej_pdata,\r
                                   IB_REJ_PDATA_SIZE,\r
@@ -481,12 +566,7 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
 {\r
     DAPL_SP              *sp_ptr;\r
     DAT_SOCK_ADDR6       dest_ia_addr;\r
-    dp_ib_cm_handle_t    cm_handle;\r
-\r
-    struct ibal_cr_data {\r
-        ib_cm_handle_t   cm_hdl;\r
-        DAT_SOCK_ADDR6   dst_ip_addr;\r
-    } *crd;\r
+    dp_ib_cm_handle_t    cm_ptr;\r
 \r
     dapl_os_assert (p_cm_req_rec);\r
 \r
@@ -517,8 +597,8 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
      * EP struct deallocation is where this memory is released or prior in the\r
      * error case.\r
      */\r
-    crd = dapl_os_alloc ( sizeof(struct ibal_cr_data) );\r
-    if ( !crd )\r
+    cm_ptr = ibal_cm_alloc();\r
+    if (!cm_ptr)\r
     {\r
         dapl_dbg_log ( DAPL_DBG_TYPE_ERR,\r
                        "%s: FAILED to alloc IB CM handle storage?\n",\r
@@ -526,9 +606,6 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
         return;\r
     }\r
 \r
-    cm_handle = &crd->cm_hdl;\r
-    dapl_os_memzero ( (void*)crd, sizeof(*crd) );\r
-\r
     /*\r
      * Save the cm_srvc_handle to avoid the race condition between\r
      * the return of the ib_cm_listen and the notification of a conn req\r
@@ -577,6 +654,16 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
 \r
 #endif /* NO_NAME_SERVICE */\r
 \r
+    /* preserve CR cm handle data */\r
+    dapl_os_memcpy( (void*)&cm_ptr->ib_cm,\r
+                    (void*)&p_cm_req_rec->h_cm_req,\r
+                    sizeof(ib_cm_handle_t));\r
+\r
+    /* preserve remote IP address */\r
+    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,\r
+                    (void*)&dest_ia_addr,\r
+                    sizeof(dest_ia_addr));\r
+\r
 #if defined(DAPL_DBG)\r
     {\r
         char ipa[20];\r
@@ -584,23 +671,13 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
         //rval = ((struct sockaddr_in *) (&dest_ia_addr))->sin_addr.s_addr;\r
 \r
         dapl_dbg_log (DAPL_DBG_TYPE_CM|DAPL_DBG_TYPE_CALLBACK, \r
-                      "%s: query SA for RemoteAddr: %s\n",\r
-                      __FUNCTION__,\r
-                      dapli_get_ip_addr_str( (DAT_SOCK_ADDR6*)\r
-                                                         &dest_ia_addr, ipa) );\r
+                      "%s: query SA (CM %lx)->dst_ip_addr: %s\n",\r
+                      __FUNCTION__,cm_ptr,\r
+                      dapli_get_ip_addr_str(\r
+                               (DAT_SOCK_ADDR6*) &cm_ptr->dst_ip_addr, ipa) );\r
     }\r
 #endif\r
 \r
-    /* preserve CR cm handle data */\r
-    dapl_os_memcpy( (void*)cm_handle,\r
-                    (void*)&p_cm_req_rec->h_cm_req,\r
-                    sizeof(ib_cm_handle_t) );\r
-\r
-    /* preserve remote IP address */\r
-    dapl_os_memcpy( (void*)&crd->dst_ip_addr,\r
-                    (void*)&dest_ia_addr,\r
-                    sizeof(dest_ia_addr) );\r
-\r
     /* FIXME - Vu\r
      * We have NOT used/saved the primary and alternative path record\r
      * ie. p_cm_req_rec->p_primary_path and p_cm_req_rec->p_alt_path\r
@@ -614,10 +691,10 @@ dapli_ib_cm_req_cb ( IN  ib_cm_req_rec_t  *p_cm_req_rec )
                   __FUNCTION__, sp_ptr, p_cm_req_rec->resp_res,\r
                   p_cm_req_rec->p_req_pdata);\r
 \r
-    dapls_cr_callback ( cm_handle,\r
+    dapls_cr_callback ( cm_ptr,\r
                         IB_CME_CONNECTION_REQUEST_PENDING,\r
                         (void * __ptr64) p_cm_req_rec->p_req_pdata,\r
-                       IB_REQ_PDATA_SIZE,\r
+                                               IB_REQ_PDATA_SIZE,\r
                         (void * __ptr64) sp_ptr );\r
 }\r
 \r
@@ -627,7 +704,7 @@ dapli_ib_cm_mra_cb (
         IN    ib_cm_mra_rec_t          *p_cm_mra_rec )\r
 {\r
        UNUSED_PARAM( p_cm_mra_rec );\r
-    dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, \r
+       dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, \r
                        "--> DiCMcb: CM callback MRA\n");\r
 }\r
 \r
@@ -635,7 +712,8 @@ static void
 dapli_ib_cm_rtu_cb (\r
         IN    ib_cm_rtu_rec_t          *p_cm_rtu_rec )\r
 {\r
-    DAPL_EP         *ep_ptr;\r
+    DAPL_EP            *ep_ptr;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
 \r
     dapl_os_assert (p_cm_rtu_rec != NULL);\r
    \r
@@ -647,9 +725,18 @@ dapli_ib_cm_rtu_cb (
                       __FUNCTION__, ep_ptr);\r
         return;\r
     }\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
+        return;\r
+    }\r
+    dapl_os_assert(cm_ptr->ib_cm.h_qp == p_cm_rtu_rec->h_qp);\r
 \r
     dapl_dbg_log (DAPL_DBG_TYPE_CM | DAPL_DBG_TYPE_CALLBACK, \r
-                  "--> DiCRucb: EP %lx QP %lx\n", ep_ptr, ep_ptr->qp_handle); \r
+                  "--> DiCRucb: EP %lx QP %lx CR %lx\n",\r
+                  ep_ptr, ep_ptr->qp_handle, ep_ptr->cr_ptr); \r
 \r
     if (ep_ptr->cr_ptr)\r
     {\r
@@ -657,7 +744,8 @@ dapli_ib_cm_rtu_cb (
 \r
         sp_ptr = ((DAPL_CR *) ep_ptr->cr_ptr)->sp_ptr;\r
 \r
-        dapls_cr_callback ( ep_ptr->cm_handle,\r
+        /* passive connection side */\r
+        dapls_cr_callback ( cm_ptr,\r
                             IB_CME_CONNECTED,\r
                             (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,\r
                             IB_RTU_PDATA_SIZE,\r
@@ -667,7 +755,7 @@ dapli_ib_cm_rtu_cb (
     else\r
     {\r
         dapl_evd_connection_callback ( \r
-                            ep_ptr->cm_handle,\r
+                            cm_ptr,\r
                             IB_CME_CONNECTED,\r
                             (void * __ptr64) p_cm_rtu_rec->p_rtu_pdata,\r
                            IB_RTU_PDATA_SIZE,\r
@@ -698,18 +786,21 @@ dapls_ib_cm_remote_addr (
 {\r
 \r
     DAPL_HEADER        *header;\r
-    void               *vp;\r
+    dp_ib_cm_handle_t  cm;\r
     char               ipa[20];\r
+    char               *rtype;\r
 \r
     header = (DAPL_HEADER *)dat_handle;\r
 \r
     if (header->magic == DAPL_MAGIC_EP) \r
     {\r
-       vp = &((DAPL_EP *) dat_handle)->remote_ia_address;\r
+       cm = dapl_get_cm_from_ep((DAPL_EP *)dat_handle);\r
+       rtype = "EP";\r
     }\r
     else if (header->magic == DAPL_MAGIC_CR) \r
     {\r
-       vp = &((DAPL_CR *) dat_handle)->remote_ia_address;\r
+       cm = ((DAPL_CR *) dat_handle)->ib_cm_handle;\r
+       rtype = "CR";\r
     }\r
     else \r
     {\r
@@ -719,10 +810,10 @@ dapls_ib_cm_remote_addr (
        return DAT_INVALID_HANDLE;\r
     }\r
 \r
-    dapl_os_memcpy( remote_address, vp, sizeof(DAT_SOCK_ADDR6) );\r
+    dapl_os_memcpy( remote_address, &cm->dst_ip_addr, sizeof(DAT_SOCK_ADDR6) );\r
 \r
-    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s: returns %s\n",\r
-                   __FUNCTION__,\r
+    dapl_dbg_log ( DAPL_DBG_TYPE_CM, "%s: returns %s remote Addrs %s\n",\r
+                   __FUNCTION__, rtype,\r
                    dapli_get_ip_addr_str((DAT_SOCK_ADDR6*)remote_address,ipa) );\r
 \r
     return DAT_SUCCESS;\r
@@ -1011,7 +1102,8 @@ dapls_ib_disconnect ( IN   DAPL_EP           *ep_ptr,
                       IN   DAT_CLOSE_FLAGS   disconnect_flags )\r
 {\r
     ib_api_status_t    ib_status = IB_SUCCESS;\r
-    ib_cm_dreq_t                   cm_dreq;\r
+    ib_cm_dreq_t       cm_dreq;\r
+    dp_ib_cm_handle_t  cm_ptr;\r
 \r
     dapl_os_assert(ep_ptr);\r
 \r
@@ -1021,14 +1113,14 @@ dapls_ib_disconnect ( IN   DAPL_EP           *ep_ptr,
                   "--> %s: BAD EP Magic EP=%lx\n", __FUNCTION__,ep_ptr); \r
         return DAT_SUCCESS;\r
     }\r
-\r
-    if (ep_ptr->cm_handle == DAPL_IB_INVALID_HANDLE )\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr)\r
     {\r
-         dapl_dbg_log (DAPL_DBG_TYPE_CM,\r
-                  "--> %s: Invalid EP->CM handle, OK.\n", __FUNCTION__); \r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR, \r
+                      "--> %s: !CM_PTR on EP %p\n", __FUNCTION__, ep_ptr);\r
         return DAT_SUCCESS;\r
     }\r
-\r
\r
     dapl_dbg_log (DAPL_DBG_TYPE_CM,\r
        "--> %s() EP %p %s rx_drq %d tx_drq %d Close %s\n", __FUNCTION__,\r
        ep_ptr, dapl_get_ep_state_str(ep_ptr->param.ep_state),\r
@@ -1314,12 +1406,12 @@ dapls_ib_reject_connection ( IN  dp_ib_cm_handle_t   ib_cm_handle,
     dapli_print_private_data("DsRjC",private_data,private_data_size);\r
 #endif\r
 \r
-    ib_status = ib_cm_rej ( *ib_cm_handle, &cm_rej);\r
+    ib_status = ib_cm_rej(ib_cm_handle->ib_cm, &cm_rej);\r
 \r
     if (ib_status != IB_SUCCESS)\r
     {\r
         dapl_dbg_log ( DAPL_DBG_TYPE_ERR,\r
-                       "--> DsRjC: cm_handle %lx reject failed %s\n", \r
+                       "--> DsRjC: cm_handle %p reject failed %s\n", \r
                        ib_cm_handle, ib_get_err_str(ib_status) );\r
     }\r
 \r
@@ -1390,6 +1482,7 @@ dapls_ib_accept_connection (
     dapl_ibal_port_t       *p_active_port;\r
     ib_cm_rep_t            cm_rep;\r
     ib_qp_attr_t           qpa;\r
+    dp_ib_cm_handle_t      cm_ptr;\r
 \r
     cr_ptr = (DAPL_CR *) cr_handle;\r
     ep_ptr = (DAPL_EP *) ep_handle;\r
@@ -1426,28 +1519,36 @@ dapls_ib_accept_connection (
     }\r
 \r
     cr_ptr->param.local_ep_handle = ep_handle;\r
-    ep_ptr->cm_handle             = cr_ptr->ib_cm_handle;\r
+\r
     /*\r
      * assume ownership, in that once the EP is released the dynamic\r
      * memory containing the IBAL CM handle (ib_cm_handle_t) struct will\r
      * be released; see dapl_ep_dealloc().\r
      */\r
-    ep_ptr->ibal_cm_handle        = cr_ptr->ib_cm_handle;\r
-\r
+   \r
+    /* EP-CM, save/release CR CM object, use EP CM object already linked */\r
+    cm_ptr = dapl_get_cm_from_ep(ep_ptr);\r
+    if (!cm_ptr) {\r
+       dapl_dbg_log ( DAPL_DBG_TYPE_ERR,\r
+                       "--> DsIBAC: CM linking to EP %p not available\n",\r
+                       ep_ptr);\r
+       return (DAT_INVALID_STATE);\r
+    }\r
+     \r
     /* set remote IP addr fields. IP addr data is deduced from Connection\r
      * Request record (gid/lib) and stashed away for use here. DAPL 1.1\r
      * had an interface for passing the IP info down, interface went away\r
      * in 2.0?\r
      */\r
     dapl_os_memcpy( (void*)&ep_ptr->remote_ia_address,\r
-                    (void*)(ep_ptr->cm_handle+1),\r
+                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,\r
                     sizeof(DAT_SOCK_ADDR6) );\r
 \r
     dapl_os_memcpy( (void*)&cr_ptr->remote_ia_address,\r
                     (void*)&ep_ptr->remote_ia_address,\r
                     sizeof(DAT_SOCK_ADDR6) );\r
 \r
-#if defined(DAPL_DBG) && 0\r
+#if defined(DAPL_DBG)\r
     {\r
         char ipa[20];\r
 \r
@@ -1455,11 +1556,21 @@ dapls_ib_accept_connection (
                       "%s: EP(%lx) RemoteAddr: %s\n",\r
                       __FUNCTION__, ep_ptr,\r
                      dapli_get_ip_addr_str(\r
-                             (DAT_SOCK_ADDR6*)&ep_ptr->remote_ia_address, ipa));\r
+                            (DAT_SOCK_ADDR6*)&ep_ptr->remote_ia_address, ipa) );\r
     }\r
 #endif\r
 \r
-    ep_ptr->qp_state      = IB_QPS_INIT;\r
+    dapl_os_memcpy( (void*)&cm_ptr->dst_ip_addr,\r
+                    (void*)&cr_ptr->ib_cm_handle->dst_ip_addr,\r
+                    sizeof(DAT_SOCK_ADDR6) );\r
+\r
+    /* get h_al and connection ID from CR CM object, h_qp already set */\r
+    cm_ptr->ib_cm.cid = cr_ptr->ib_cm_handle->ib_cm.cid; \r
+    cm_ptr->ib_cm.h_al = cr_ptr->ib_cm_handle->ib_cm.h_al;\r
+    dapls_cm_release(cr_ptr->ib_cm_handle);\r
+\r
+    cr_ptr->ib_cm_handle = cm_ptr; /* for dapli_get_sp_ep() upcall */\r
+\r
     ep_ptr->cr_ptr        = cr_ptr;\r
 \r
     dapl_os_memzero ( (void*)&cm_rep, sizeof (ib_cm_rep_t) );\r
@@ -1526,19 +1637,13 @@ dapls_ib_accept_connection (
                 cm_rep.access_ctrl, cm_rep.init_depth,cm_rep.qp_type,\r
                  dapls_cb_pending(&ep_ptr->req_buffer));\r
 \r
-    ib_status = ib_cm_rep ( *ep_ptr->cm_handle, &cm_rep );\r
+    ib_status = ib_cm_rep ( cm_ptr->ib_cm, &cm_rep );\r
 \r
     if (ib_status != IB_SUCCESS)\r
     {\r
        dapl_dbg_log ( DAPL_DBG_TYPE_ERR,\r
                        "--> DsIBAC: EP %lx QP %lx CR reply failed '%s'\n",\r
                        ep_ptr, ep_ptr->qp_handle, ib_get_err_str(ib_status) );\r
-\r
-        /* errors not perculated back to CR callback which allocated the\r
-         * memory, free it here on error.\r
-         */\r
-        dapl_os_free ( (void*)ep_ptr->ibal_cm_handle, sizeof(ib_cm_handle_t) );\r
-        ep_ptr->ibal_cm_handle = NULL;\r
     }\r
  \r
     return ( dapl_ib_status_convert ( ib_status ) );\r
@@ -1589,11 +1694,6 @@ dapls_ib_disconnect_clean (
     \r
     ep_ptr->sent_discreq = DAT_FALSE;\r
     ep_ptr->recv_discreq = DAT_FALSE;\r
-    if ( ep_ptr->ibal_cm_handle )\r
-    {\r
-        dapl_os_free ( (void*)ep_ptr->ibal_cm_handle, sizeof(ib_cm_handle_t) );\r
-    }\r
-    ep_ptr->ibal_cm_handle = NULL;\r
 \r
     /* \r
      * Query the QP to get the current state */\r
@@ -1653,7 +1753,7 @@ dapls_ib_cr_handoff (
     \r
     cr_ptr = (DAPL_CR *) cr_handle;\r
 \r
-    if (cr_ptr->ib_cm_handle->cid == 0xFFFFFFFF)\r
+    if (cr_ptr->ib_cm_handle->ib_cm.cid == 0xFFFFFFFF)\r
     {\r
         dapl_dbg_log ( DAPL_DBG_TYPE_ERR,\r
                        "--> DsCH: CR = %lx invalid cm handle\n", cr_ptr);\r
@@ -1667,7 +1767,7 @@ dapls_ib_cr_handoff (
         return DAT_INVALID_PARAMETER;\r
     }\r
 \r
-    ib_status = ib_cm_handoff (*cr_ptr->ib_cm_handle, handoff_serv_id);\r
+    ib_status = ib_cm_handoff (cr_ptr->ib_cm_handle->ib_cm, handoff_serv_id);\r
 \r
     if (ib_status != IB_SUCCESS)\r
     {\r
index cc8c394..eff6d11 100644 (file)
-
-/*
- * 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_qp.c
- *
- * PURPOSE: IB QP routines  for access to IBAL APIs
- *
- * $Id: dapl_ibal_qp.c 33 2005-07-11 19:51:17Z ftillier $
- *
- **********************************************************************/
-
-#include "dapl.h"
-#include "dapl_adapter_util.h"
-#include "dapl_evd_util.h"
-#include "dapl_ibal_util.h"
-
-#define DAPL_IBAL_QKEY              0
-#define DAPL_IBAL_START_PSN         0
-
-extern DAT_RETURN
-dapls_ib_cq_late_alloc ( IN  ib_pd_handle_t        pd_handle,
-                         IN  DAPL_EVD              *evd_ptr );
-
-static void
-dapli_ib_qp_async_error_cb( IN  ib_async_event_rec_t* p_err_rec )
-{
-       DAPL_EP                 *ep_ptr = (DAPL_EP *)p_err_rec->context;
-       DAPL_EVD                *evd_ptr;
-       DAPL_IA                 *ia_ptr;
-       dapl_ibal_ca_t          *p_ca;
-        dapl_ibal_evd_cb_t     *evd_cb;
-
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,"--> DiQpAEC QP event %s qp ctx %p\n", 
-               ib_get_async_event_str(p_err_rec->code), p_err_rec->context);
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,"--> DiQpAEC qp_handle %p qpn %u\n", 
-               ((DAPL_EP *)p_err_rec->context)->qp_handle, 
-               ((DAPL_EP *)p_err_rec->context)->qpn);
-
-       /*
-        * Verify handles EP, EVD, and hca_handle
-        */
-       if (DAPL_BAD_HANDLE (ep_ptr, DAPL_MAGIC_EP ) ||
-           DAPL_BAD_HANDLE (ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD))
-       {
-               dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                               "--> DiQpAEC: invalid EP %p \n", ep_ptr);
-               return;
-       }
-       ia_ptr = ep_ptr->header.owner_ia;
-       evd_ptr = ia_ptr->async_error_evd;
-
-       if (DAPL_BAD_HANDLE (evd_ptr, DAPL_MAGIC_EVD) ||
-           ! (evd_ptr->evd_flags & DAT_EVD_ASYNC_FLAG))
-       {
-               dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                               "--> DiQpAEC: invalid EVD %p \n", evd_ptr);
-               return;
-       }
-       p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-       if (p_ca == NULL)
-       {
-               dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                               "--> DiQpAEC: can't find %s HCA\n", 
-                               (ia_ptr->header.provider)->device_name);
-               return;
-       }
-
-       /* find QP error callback using ia_ptr for context */
-       evd_cb = dapli_find_evd_cb_by_context (ia_ptr, p_ca);
-       if ((evd_cb == NULL) || (evd_cb->pfn_async_qp_err_cb == NULL))
-       {
-               dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                       "--> DiQpAEC: no ERROR cb on p_ca %p found\n", p_ca);
-               return;
-       }
-
-       dapl_os_lock (&ep_ptr->header.lock);
-       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;
-       dapl_os_unlock (&ep_ptr->header.lock);
-
-       /* force disconnect, QP error state, to insure DTO's get flushed */
-       dapls_ib_disconnect ( ep_ptr, DAT_CLOSE_ABRUPT_FLAG );
-       
-       /* maps to dapl_evd_qp_async_error_callback(), context is EP */
-       evd_cb->pfn_async_qp_err_cb(    (ib_hca_handle_t)p_ca, 
-                                    ep_ptr->qp_handle,
-                                       (ib_error_record_t*)&p_err_rec->code,
-                                    ep_ptr );
-}
-
-/*
- * dapls_ib_qp_alloc
- *
- * Alloc a QP
- *
- * Input:
- *        *ia_ptr                pointer to DAPL IA
- *        *ep_ptr                pointer to DAPL EP
- *        *ep_ctx_ptr            pointer to DAPL EP context
- *
- * Output:
- *         none
- *
- * Returns:
- *        DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *
- */
-DAT_RETURN
-dapls_ib_qp_alloc (
-        IN  DAPL_IA                *ia_ptr,
-        IN  DAPL_EP                *ep_ptr,
-       IN  DAPL_EP                *ep_ctx_ptr)
-{
-    DAT_EP_ATTR           *attr;
-    DAPL_EVD              *recv_evd_ptr, *request_evd_ptr;
-    DAT_RETURN            dat_status;
-    ib_api_status_t       ib_status;
-    ib_qp_create_t        qp_create;
-    ib_pd_handle_t        ib_pd_handle;
-    ib_cq_handle_t        cq_recv;
-    ib_cq_handle_t        cq_send;
-    dapl_ibal_ca_t        *p_ca;
-    dapl_ibal_port_t      *p_active_port;
-    ib_qp_attr_t           qp_attr;
-
-    attr = &ep_ptr->param.ep_attr;
-
-    dapl_os_assert ( ep_ptr->param.pz_handle != NULL );
-
-    ib_pd_handle    = ((DAPL_PZ *)ep_ptr->param.pz_handle)->pd_handle;
-    dapl_os_assert(ib_pd_handle);
-    recv_evd_ptr    = (DAPL_EVD *) ep_ptr->param.recv_evd_handle;
-    request_evd_ptr = (DAPL_EVD *) ep_ptr->param.request_evd_handle;
-    
-    cq_recv = IB_INVALID_HANDLE;
-    cq_send = IB_INVALID_HANDLE;
-
-    dapl_os_assert ( recv_evd_ptr != DAT_HANDLE_NULL );
-    {
-        cq_recv = (ib_cq_handle_t) recv_evd_ptr->ib_cq_handle;
-        
-        if ((cq_recv == IB_INVALID_HANDLE) && 
-            ( 0 != (recv_evd_ptr->evd_flags & ~DAT_EVD_SOFTWARE_FLAG) ))
-        {
-            dat_status = dapls_ib_cq_late_alloc ( ib_pd_handle, recv_evd_ptr);
-            if (dat_status != DAT_SUCCESS)
-            {
-                dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> %s: failed to create CQ\n","DsQA");
-                return (dat_status);
-            }
-
-            dat_status = dapls_set_cq_notify (ia_ptr, recv_evd_ptr);
-
-            if (dat_status != DAT_SUCCESS)
-            {
-                dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> %s: failed to enable notify CQ\n","DsQA");
-                return (dat_status);
-            }
-        
-            cq_recv = (ib_cq_handle_t) recv_evd_ptr->ib_cq_handle;
-            dapl_dbg_log (DAPL_DBG_TYPE_EP, 
-                          "--> DsQA: alloc_recv_CQ = %p\n", cq_recv); 
-        
-        }
-    }
-
-    dapl_os_assert ( request_evd_ptr != DAT_HANDLE_NULL );
-    {
-        cq_send = (ib_cq_handle_t) request_evd_ptr->ib_cq_handle;
-        
-        if ((cq_send == IB_INVALID_HANDLE) && 
-            ( 0 != (request_evd_ptr->evd_flags & ~DAT_EVD_SOFTWARE_FLAG) ))
-        {
-            dat_status = dapls_ib_cq_late_alloc (ib_pd_handle, request_evd_ptr);
-            if (dat_status != DAT_SUCCESS)
-            {
-                dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> %s: failed to create CQ\n","DsQA");
-                return (dat_status);
-            }
-
-            dat_status = dapls_set_cq_notify (ia_ptr, request_evd_ptr);
-
-            if (dat_status != DAT_SUCCESS)
-            {
-                dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                              "--> %s: failed to enable notify CQ\n","DsQA");
-                return (dat_status);
-            }
-
-            cq_send = (ib_cq_handle_t) request_evd_ptr->ib_cq_handle;
-            dapl_dbg_log (DAPL_DBG_TYPE_EP, 
-                          "--> DsQA: alloc_send_CQ = %p\n", cq_send); 
-        }
-    }
-
-    /*
-     * Get the CA structure
-     */
-    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;
-
-    dapl_os_memzero (&qp_create, sizeof (qp_create));
-    qp_create.qp_type     = IB_QPT_RELIABLE_CONN;
-    qp_create.sq_depth    = attr->max_request_dtos;
-    qp_create.rq_depth    = attr->max_recv_dtos;
-    qp_create.sq_sge      = attr->max_recv_iov;
-    qp_create.rq_sge      = attr->max_request_iov;                       
-    qp_create.h_sq_cq     = cq_send;
-    qp_create.h_rq_cq     = cq_recv;
-    qp_create.sq_signaled = FALSE;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, 
-                  "--> DsQA: sqd,iov=%d,%d rqd,iov=%d,%d\n", 
-                  attr->max_request_dtos, attr->max_request_iov,
-                  attr->max_recv_dtos, attr->max_recv_iov); 
-    
-    ib_status = ib_create_qp ( 
-                       ib_pd_handle,
-                       &qp_create,
-                       (void *) ep_ctx_ptr /* context */,
-                       dapli_ib_qp_async_error_cb,
-                       &ep_ptr->qp_handle);
-
-    if (ib_status != IB_SUCCESS)
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsQA: Create QP failed = %s\n",
-                      ib_get_err_str(ib_status));
-       return (DAT_INSUFFICIENT_RESOURCES);
-    }
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQA: EP=%p, tEVD=%p, rEVD=%p QP=%p\n",
-                  ep_ptr, ep_ptr->param.request_evd_handle,
-                  ep_ptr->param.recv_evd_handle,
-                  ep_ptr->qp_handle ); 
-
-    ep_ptr->qp_state = IB_QPS_RESET;
-
-    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,
-                      "--> DsQA: Port %d is not available = %d\n",
-                      ia_ptr->hca_ptr->port_num, __LINE__);
-        return (DAT_INVALID_STATE);
-    }
-
-    ib_status = dapls_modify_qp_state_to_init ( ep_ptr->qp_handle, 
-                                               &ep_ptr->param.ep_attr,
-                                                p_active_port );
-
-    if ( ib_status != IB_SUCCESS )
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> DsQA: Change QP state to INIT failed = %s\n",
-                      ib_get_err_str(ib_status));
-       return (DAT_INVALID_HANDLE);
-    }
-    ib_status = ib_query_qp ( ep_ptr->qp_handle, &qp_attr );
-
-    ep_ptr->qp_state = qp_attr.state;
-    ep_ptr->qpn = qp_attr.num;
-    
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQAQA: EP:%p new_QP %p state %s\n",
-                  ep_ptr,
-                  ep_ptr->qp_handle,
-                  ib_get_port_state_str(ep_ptr->qp_state));
-
-    return (DAT_SUCCESS);
-}
-
-
-/*
- * dapls_ib_qp_free
- *
- * Free a QP
- *
- * Input:
- *        *ia_ptr                pointer to IA structure
- *        *ep_ptr                pointer to EP structure
- *
- * Output:
- *         none
- *
- * Returns:
- *         none
- *
- */
-DAT_RETURN
-dapls_ib_qp_free (
-        IN  DAPL_IA                *ia_ptr,
-        IN  DAPL_EP                *ep_ptr )
-{
-
-       ib_qp_handle_t          qp_handle;
-       UNREFERENCED_PARAMETER(ia_ptr);
-
-       dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQF: free %p, state %s\n", 
-                      ep_ptr->qp_handle,
-                      ib_get_port_state_str(ep_ptr->qp_state));
-
-       if (( ep_ptr->qp_handle != IB_INVALID_HANDLE ) &&
-           ( ep_ptr->qp_state != DAPL_QP_STATE_UNATTACHED ))
-       {
-               qp_handle = ep_ptr->qp_handle;
-               ep_ptr->qp_handle = IB_INVALID_HANDLE;
-               ep_ptr->qp_state = DAPL_QP_STATE_UNATTACHED;
-               ib_destroy_qp ( qp_handle, NULL /* callback */);
-               dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQF: freed QP %p\n",
-                               qp_handle ); 
-       }
-
-    return DAT_SUCCESS;
-}
-
-
-/*
- * dapls_ib_qp_modify
- *
- * Set the QP to the parameters specified in an EP_PARAM
- *
- * We can't be sure what state the QP is in so we first obtain the state
- * from the driver. The EP_PARAM structure that is provided has been
- * sanitized such that only non-zero values are valid.
- *
- * Input:
- *        *ia_ptr                pointer to DAPL IA
- *        *ep_ptr                pointer to DAPL EP
- *        *ep_attr               pointer to DAT EP attribute
- *
- * Output:
- *         none
- *
- * Returns:
- *         DAT_SUCCESS
- *        DAT_INSUFFICIENT_RESOURCES
- *        DAT_INVALID_PARAMETER
- *
- */
-DAT_RETURN
-dapls_ib_qp_modify (
-        IN  DAPL_IA                        *ia_ptr,
-        IN  DAPL_EP                        *ep_ptr,
-        IN  DAT_EP_ATTR                    *ep_attr )
-{
-    ib_qp_attr_t                  qp_attr;
-    ib_api_status_t               ib_status;
-    ib_qp_handle_t                qp_handle;
-    ib_qp_state_t                 qp_state;
-    ib_qp_mod_t                   qp_mod;
-    ib_av_attr_t                  *p_av_attr;
-    ib_qp_opts_t                  *p_qp_opts;
-    uint32_t                      *p_sq_depth, *p_rq_depth;
-    DAT_BOOLEAN                   need_modify;
-    DAT_RETURN                    dat_status;
-
-    qp_handle     = ep_ptr->qp_handle;
-    need_modify   = DAT_FALSE;
-    dat_status    = DAT_SUCCESS;
-    if ( ia_ptr == NULL || ia_ptr->header.magic != DAPL_MAGIC_IA )
-    {
-       dat_status = DAT_INVALID_HANDLE;
-       goto bail;
-    }
-    /* 
-     * Query the QP to get the current state.
-     */
-    ib_status = ib_query_qp ( qp_handle, &qp_attr );
-                       
-    if ( ib_status != IB_SUCCESS )
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsIQM: Query QP failed = %s\n",
-                       ib_get_err_str(ib_status));
-        dat_status = DAT_INTERNAL_ERROR;
-        goto bail;
-    }
-
-    qp_state = qp_attr.state;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM: modify qp state=%d\n",qp_state);
-    /*
-     * Check if we have the right qp_state or not
-     */
-    if ( (qp_state != IB_QPS_RTR ) && (qp_state != IB_QPS_RTS ) )
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_EP,
-                      "--> DsIQM: postpone to modify qp to EP values later\n");
-        dat_status = DAT_SUCCESS;
-        goto bail;
-    }
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    if (qp_state == IB_QPS_RTR)
-    {
-        p_av_attr   = &qp_mod.state.rtr.primary_av;
-        p_qp_opts   = &qp_mod.state.rtr.opts;
-        p_sq_depth  = &qp_mod.state.rtr.sq_depth;
-        p_rq_depth  = &qp_mod.state.rtr.rq_depth;
-    }
-    else
-    {
-        /*
-        * RTS does not have primary_av field
-        */
-        p_av_attr   = &qp_mod.state.rts.alternate_av;
-        p_qp_opts   = &qp_mod.state.rts.opts;
-        p_sq_depth  = &qp_mod.state.rts.sq_depth;
-        p_rq_depth  = &qp_mod.state.rts.rq_depth;
-    }
-
-    if ( (ep_attr->max_recv_dtos > 0) &&
-               ((DAT_UINT32)ep_attr->max_recv_dtos != qp_attr.rq_depth) )
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_EP,"--> DsIQM: rq_depth modified (%d,%d)\n",
-                       qp_attr.rq_depth, ep_attr->max_recv_dtos);
-
-        *p_rq_depth = ep_attr->max_recv_dtos;
-        *p_qp_opts |= IB_MOD_QP_RQ_DEPTH;
-        need_modify = DAT_TRUE;
-    }
-
-    if ( (ep_attr->max_request_dtos > 0) &&
-               ((DAT_UINT32)ep_attr->max_request_dtos != qp_attr.sq_depth) ) 
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_EP,
-                       "--> DsIQM: sq_depth modified (%d,%d)\n",
-                       qp_attr.sq_depth, ep_attr->max_request_dtos);
-
-        *p_sq_depth = ep_attr->max_request_dtos;
-        *p_qp_opts |= IB_MOD_QP_SQ_DEPTH;
-        need_modify = DAT_TRUE;
-    }
-
-    qp_mod.req_state  = qp_state;
-
-    if ( need_modify == DAT_TRUE )
-    {
-       ib_status = ib_modify_qp (qp_handle, &qp_mod);
-        if ( ib_status != IB_SUCCESS)
-        {
-           dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: ib_status = %d\n",
-                          "DsIQM", ib_status);
-           dat_status = DAT_INTERNAL_ERROR;
-        }
-    }
-
-bail:
-
-    return dat_status;
-}
-
-
-ib_api_status_t 
-dapls_modify_qp_state_to_error ( ib_qp_handle_t  qp_handle )
-{
-    ib_qp_mod_t      qp_mod;
-    ib_api_status_t  ib_status;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_Err: QP state change --> Err\n");
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    qp_mod.req_state  = IB_QPS_ERROR;
-
-    ib_status = ib_modify_qp (qp_handle, &qp_mod);
-
-    return (ib_status);
-}
-
-
-ib_api_status_t 
-dapls_modify_qp_state_to_reset ( ib_qp_handle_t  qp_handle )
-{
-    ib_qp_mod_t      qp_mod;
-    ib_api_status_t  ib_status;
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RESET: QP state change\n");
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    qp_mod.req_state  = IB_QPS_RESET;
-
-    ib_status = ib_modify_qp (qp_handle, &qp_mod);
-
-    return (ib_status);
-}
-
-
-ib_api_status_t 
-dapls_modify_qp_state_to_init (
-        IN    ib_qp_handle_t         qp_handle,
-        IN    DAT_EP_ATTR            *p_attr,
-        IN    dapl_ibal_port_t       *p_port )
-{
-    ib_qp_mod_t                   qp_mod;
-    ib_api_status_t               ib_status;
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    qp_mod.req_state               = IB_QPS_INIT;
-    qp_mod.state.init.primary_port = p_port->p_attr->port_num;
-    qp_mod.state.init.qkey         = DAPL_IBAL_QKEY;
-    qp_mod.state.init.pkey_index   = 0;
-    qp_mod.state.init.access_ctrl = IB_AC_LOCAL_WRITE |
-                                       IB_AC_RDMA_WRITE |
-                                       IB_AC_MW_BIND |
-                                       IB_AC_ATOMIC;
-    if ((p_attr->max_rdma_read_in > 0) || (p_attr->max_rdma_read_out > 0))
-    {
-       qp_mod.state.init.access_ctrl |= IB_AC_RDMA_READ;
-    }
-    ib_status = ib_modify_qp (qp_handle, &qp_mod);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_INIT: QP(%p) state change, %s\n",
-                  qp_handle, ib_get_err_str(ib_status));
-
-    return (ib_status);
-}
-
-
-ib_api_status_t 
-dapls_modify_qp_state_to_rtr (
-        ib_qp_handle_t          qp_handle,
-        ib_net32_t              dest_qp,
-        ib_lid_t                dest_lid,
-        dapl_ibal_port_t        *p_port)
-{
-    ib_qp_mod_t                 qp_mod;
-    ib_api_status_t             ib_status;
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    qp_mod.req_state                        = IB_QPS_RTR;
-    qp_mod.state.rtr.rq_psn                 = DAPL_IBAL_START_PSN;
-    qp_mod.state.rtr.dest_qp                = dest_qp;
-    qp_mod.state.rtr.primary_av.port_num    = p_port->p_attr->port_num;
-    qp_mod.state.rtr.primary_av.sl          = 0;
-    qp_mod.state.rtr.primary_av.dlid        = dest_lid;
-    qp_mod.state.rtr.primary_av.grh_valid   = 0; /* FALSE */
-    qp_mod.state.rtr.primary_av.static_rate = IB_PATH_RECORD_RATE_10_GBS;
-    qp_mod.state.rtr.primary_av.path_bits   = 0;
-    qp_mod.state.rtr.primary_av.conn.path_mtu = p_port->p_attr->mtu;
-    qp_mod.state.rtr.primary_av.conn.local_ack_timeout = 7;
-    qp_mod.state.rtr.primary_av.conn.seq_err_retry_cnt = 7;
-    qp_mod.state.rtr.primary_av.conn.rnr_retry_cnt = IB_RNR_RETRY_CNT;
-    qp_mod.state.rtr.resp_res               = 4; // in-flight RDMAs
-    qp_mod.state.rtr.rnr_nak_timeout        = IB_RNR_NAK_TIMEOUT;
-    ib_status = ib_modify_qp (qp_handle, &qp_mod);
-    
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RTR: QP(%p) state change %s\n",
-                  qp_handle, ib_get_err_str(ib_status));
-
-    return (ib_status);
-}
-
-ib_api_status_t 
-dapls_modify_qp_state_to_rts ( ib_qp_handle_t  qp_handle )
-{
-    ib_qp_mod_t        qp_mod;
-    ib_api_status_t    ib_status;
-
-    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));
-
-    qp_mod.req_state                   = IB_QPS_RTS;
-    qp_mod.state.rts.sq_psn            = DAPL_IBAL_START_PSN;
-    qp_mod.state.rts.retry_cnt         = 7;
-    qp_mod.state.rts.rnr_retry_cnt     = IB_RNR_RETRY_CNT;
-    qp_mod.state.rtr.rnr_nak_timeout   = IB_RNR_NAK_TIMEOUT;
-    qp_mod.state.rts.local_ack_timeout = 7;
-    qp_mod.state.rts.init_depth        = 4; 
-
-    ib_status = ib_modify_qp (qp_handle, &qp_mod);
-
-    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RTS: QP(%p) state change %s\n",
-                  qp_handle, ib_get_err_str(ib_status));
-
-    return (ib_status);
-}
-
-
-/*
- * dapls_ib_reinit_ep
- *
- * Move the QP to INIT state again.
- *
- * Input:
- *     ep_ptr          DAPL_EP
- *
- * Output:
- *     none
- *
- * Returns:
- *     void
- *
- */
-void
-dapls_ib_reinit_ep ( IN DAPL_EP  *ep_ptr )
-{
-    DAPL_IA                  *ia_ptr;
-    ib_api_status_t          ib_status;
-    dapl_ibal_ca_t           *p_ca;
-    dapl_ibal_port_t         *p_active_port;
-       
-    dapl_dbg_log (DAPL_DBG_TYPE_EP,
-                  "--> DsIQM_REINIT: EP(%p) QP(%p) state change\n", 
-                  ep_ptr, ep_ptr->qp_handle );
-
-    if ( ep_ptr->param.ep_state != DAT_EP_STATE_DISCONNECTED )
-    {
-       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsIRE: EP invalid state(%d)\n",
-                      ep_ptr->param.ep_state);
-       return /*DAT_INVALID_STATE*/;
-    }
-
-    ia_ptr = ep_ptr->header.owner_ia;
-
-    /* Re-create QP if cleaned up, alloc will return init state */
-    if ( ep_ptr->qp_handle == IB_INVALID_HANDLE )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_EP,
-                      "--> DsIRE: !EP(%p)->qp_handle, re-create QP\n",ep_ptr);
-        ib_status = dapls_ib_qp_alloc ( ia_ptr, ep_ptr, ep_ptr );
-        if ( ib_status != IB_SUCCESS )
-        {
-            dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> DsIRE: failed to move qp to RESET status = %s\n", 
-                      ib_get_err_str(ib_status));
-        }
-        return /*ib_status*/;
-    }
-
-    ib_status = dapls_modify_qp_state_to_reset (ep_ptr->qp_handle);
-
-    if ( ib_status != IB_SUCCESS )
-    {
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> DsIRE: failed to move qp to RESET status = %s\n", 
-                      ib_get_err_str(ib_status));
-        return /*DAT_INTERNAL_ERROR*/;
-    }
-
-    ep_ptr->qp_state = IB_QPS_RESET;
-
-    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,
-                     "--> DsIRE: Port %d is not available = %d\n",
-                     ia_ptr->hca_ptr->port_num, __LINE__);
-        return /*DAT_INTERNAL_ERROR*/;
-    }
-
-       /* May fail if QP still RESET and in timewait, keep in reset state */
-    ib_status = dapls_modify_qp_state_to_init ( ep_ptr->qp_handle,
-                                                &ep_ptr->param.ep_attr,
-                                                p_active_port);
-    if ( ib_status != IB_SUCCESS )
-    {
-        ep_ptr->qp_state = IB_QPS_RESET;
-
-        dapl_dbg_log (DAPL_DBG_TYPE_ERR,
-                      "--> DsIRE: failed to move qp to INIT status %s\n", 
-                      ib_get_err_str(ib_status));
-        return /*DAT_INTERNAL_ERROR*/;
-    }
-    ep_ptr->qp_state = IB_QPS_INIT;
-}
-
-
-/*
- * Local variables:
- *  c-indent-level: 4
- *  c-basic-offset: 4
- *  tab-width: 8
- * End:
- */
-
+\r
+/*\r
+ * Copyright (c) 2005-2007 Intel Corporation. All rights reserved.\r
+ * Copyright (c) 2002, Network Appliance, Inc. All rights reserved. \r
+ * \r
+ * This Software is licensed under the terms of the "Common Public\r
+ * License" a copy of which is in the file LICENSE.txt in the root\r
+ * directory. The license is also available from the Open Source\r
+ * Initiative, see http://www.opensource.org/licenses/cpl.php.\r
+ *\r
+ */\r
+\r
+/**********************************************************************\r
+ * \r
+ * MODULE: dapl_ibal_qp.c\r
+ *\r
+ * PURPOSE: IB QP routines  for access to IBAL APIs\r
+ *\r
+ * $Id: dapl_ibal_qp.c 33 2005-07-11 19:51:17Z ftillier $\r
+ *\r
+ **********************************************************************/\r
+\r
+#include "dapl.h"\r
+#include "dapl_adapter_util.h"\r
+#include "dapl_evd_util.h"\r
+#include "dapl_ibal_util.h"\r
+#include "dapl_ep_util.h"\r
+\r
+#define DAPL_IBAL_QKEY              0\r
+#define DAPL_IBAL_START_PSN         0\r
+\r
+extern DAT_RETURN\r
+dapls_ib_cq_late_alloc ( IN  ib_pd_handle_t        pd_handle,\r
+                         IN  DAPL_EVD              *evd_ptr );\r
+\r
+static void\r
+dapli_ib_qp_async_error_cb( IN  ib_async_event_rec_t* p_err_rec )\r
+{\r
+       DAPL_EP                 *ep_ptr = (DAPL_EP *)p_err_rec->context;\r
+       DAPL_EVD                *evd_ptr;\r
+       DAPL_IA                 *ia_ptr;\r
+       dapl_ibal_ca_t          *p_ca;\r
+        dapl_ibal_evd_cb_t     *evd_cb;\r
+\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,"--> DiQpAEC QP event %s qp ctx %p\n", \r
+               ib_get_async_event_str(p_err_rec->code), p_err_rec->context);\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,"--> DiQpAEC qp_handle %p qpn %u\n", \r
+               ((DAPL_EP *)p_err_rec->context)->qp_handle, \r
+               ((DAPL_EP *)p_err_rec->context)->qpn);\r
+\r
+       /*\r
+        * Verify handles EP, EVD, and hca_handle\r
+        */\r
+       if (DAPL_BAD_HANDLE (ep_ptr, DAPL_MAGIC_EP ) ||\r
+           DAPL_BAD_HANDLE (ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD))\r
+       {\r
+               dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                               "--> DiQpAEC: invalid EP %p \n", ep_ptr);\r
+               return;\r
+       }\r
+       ia_ptr = ep_ptr->header.owner_ia;\r
+       evd_ptr = ia_ptr->async_error_evd;\r
+\r
+       if (DAPL_BAD_HANDLE (evd_ptr, DAPL_MAGIC_EVD) ||\r
+           ! (evd_ptr->evd_flags & DAT_EVD_ASYNC_FLAG))\r
+       {\r
+               dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                               "--> DiQpAEC: invalid EVD %p \n", evd_ptr);\r
+               return;\r
+       }\r
+       p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;\r
+       if (p_ca == NULL)\r
+       {\r
+               dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                               "--> DiQpAEC: can't find %s HCA\n", \r
+                               (ia_ptr->header.provider)->device_name);\r
+               return;\r
+       }\r
+\r
+       /* find QP error callback using ia_ptr for context */\r
+       evd_cb = dapli_find_evd_cb_by_context (ia_ptr, p_ca);\r
+       if ((evd_cb == NULL) || (evd_cb->pfn_async_qp_err_cb == NULL))\r
+       {\r
+               dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                       "--> DiQpAEC: no ERROR cb on p_ca %p found\n", p_ca);\r
+               return;\r
+       }\r
+\r
+       dapl_os_lock (&ep_ptr->header.lock);\r
+       ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;\r
+       dapl_os_unlock (&ep_ptr->header.lock);\r
+\r
+       /* force disconnect, QP error state, to insure DTO's get flushed */\r
+       dapls_ib_disconnect ( ep_ptr, DAT_CLOSE_ABRUPT_FLAG );\r
+       \r
+       /* maps to dapl_evd_qp_async_error_callback(), context is EP */\r
+       evd_cb->pfn_async_qp_err_cb(    (ib_hca_handle_t)p_ca, \r
+                                    ep_ptr->qp_handle,\r
+                                       (ib_error_record_t*)&p_err_rec->code,\r
+                                    ep_ptr );\r
+}\r
+\r
+/*\r
+ * dapls_ib_qp_alloc\r
+ *\r
+ * Alloc a QP\r
+ *\r
+ * Input:\r
+ *        *ia_ptr                pointer to DAPL IA\r
+ *        *ep_ptr                pointer to DAPL EP\r
+ *        *ep_ctx_ptr            pointer to DAPL EP context\r
+ *\r
+ * Output:\r
+ *         none\r
+ *\r
+ * Returns:\r
+ *        DAT_SUCCESS\r
+ *        DAT_INSUFFICIENT_RESOURCES\r
+ *\r
+ */\r
+DAT_RETURN\r
+dapls_ib_qp_alloc (\r
+        IN  DAPL_IA                *ia_ptr,\r
+        IN  DAPL_EP                *ep_ptr,\r
+       IN  DAPL_EP                *ep_ctx_ptr)\r
+{\r
+    DAT_EP_ATTR           *attr;\r
+    DAPL_EVD              *recv_evd_ptr, *request_evd_ptr;\r
+    DAT_RETURN            dat_status;\r
+    ib_api_status_t       ib_status;\r
+    ib_qp_create_t        qp_create;\r
+    ib_pd_handle_t        ib_pd_handle;\r
+    ib_cq_handle_t        cq_recv;\r
+    ib_cq_handle_t        cq_send;\r
+    dapl_ibal_ca_t        *p_ca;\r
+    dapl_ibal_port_t      *p_active_port;\r
+    ib_qp_attr_t          qp_attr;\r
+    dp_ib_cm_handle_t     cm_ptr;\r
+\r
+    attr = &ep_ptr->param.ep_attr;\r
+\r
+    dapl_os_assert ( ep_ptr->param.pz_handle != NULL );\r
+\r
+    ib_pd_handle    = ((DAPL_PZ *)ep_ptr->param.pz_handle)->pd_handle;\r
+    dapl_os_assert(ib_pd_handle);\r
+    recv_evd_ptr    = (DAPL_EVD *) ep_ptr->param.recv_evd_handle;\r
+    request_evd_ptr = (DAPL_EVD *) ep_ptr->param.request_evd_handle;\r
+    \r
+    cq_recv = IB_INVALID_HANDLE;\r
+    cq_send = IB_INVALID_HANDLE;\r
+\r
+    dapl_os_assert ( recv_evd_ptr != DAT_HANDLE_NULL );\r
+    {\r
+        cq_recv = (ib_cq_handle_t) recv_evd_ptr->ib_cq_handle;\r
+        \r
+        if ((cq_recv == IB_INVALID_HANDLE) && \r
+            ( 0 != (recv_evd_ptr->evd_flags & ~DAT_EVD_SOFTWARE_FLAG) ))\r
+        {\r
+            dat_status = dapls_ib_cq_late_alloc ( ib_pd_handle, recv_evd_ptr);\r
+            if (dat_status != DAT_SUCCESS)\r
+            {\r
+                dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                              "--> %s: failed to create CQ\n","DsQA");\r
+                return (dat_status);\r
+            }\r
+\r
+            dat_status = dapls_set_cq_notify (ia_ptr, recv_evd_ptr);\r
+\r
+            if (dat_status != DAT_SUCCESS)\r
+            {\r
+                dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                              "--> %s: failed to enable notify CQ\n","DsQA");\r
+                return (dat_status);\r
+            }\r
+        \r
+            cq_recv = (ib_cq_handle_t) recv_evd_ptr->ib_cq_handle;\r
+            dapl_dbg_log (DAPL_DBG_TYPE_EP, \r
+                          "--> DsQA: alloc_recv_CQ = %p\n", cq_recv); \r
+        \r
+        }\r
+    }\r
+\r
+    dapl_os_assert ( request_evd_ptr != DAT_HANDLE_NULL );\r
+    {\r
+        cq_send = (ib_cq_handle_t) request_evd_ptr->ib_cq_handle;\r
+        \r
+        if ((cq_send == IB_INVALID_HANDLE) && \r
+            ( 0 != (request_evd_ptr->evd_flags & ~DAT_EVD_SOFTWARE_FLAG) ))\r
+        {\r
+            dat_status = dapls_ib_cq_late_alloc (ib_pd_handle, request_evd_ptr);\r
+            if (dat_status != DAT_SUCCESS)\r
+            {\r
+                dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                              "--> %s: failed to create CQ\n","DsQA");\r
+                return (dat_status);\r
+            }\r
+\r
+            dat_status = dapls_set_cq_notify (ia_ptr, request_evd_ptr);\r
+\r
+            if (dat_status != DAT_SUCCESS)\r
+            {\r
+                dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                              "--> %s: failed to enable notify CQ\n","DsQA");\r
+                return (dat_status);\r
+            }\r
+\r
+            cq_send = (ib_cq_handle_t) request_evd_ptr->ib_cq_handle;\r
+            dapl_dbg_log (DAPL_DBG_TYPE_EP, \r
+                          "--> DsQA: alloc_send_CQ = %p\n", cq_send); \r
+        }\r
+    }\r
+\r
+    /*\r
+     * Get the CA structure\r
+     */\r
+    p_ca = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;\r
+\r
+    dapl_os_memzero (&qp_create, sizeof (qp_create));\r
+    qp_create.qp_type     = IB_QPT_RELIABLE_CONN;\r
+    qp_create.sq_depth    = attr->max_request_dtos;\r
+    qp_create.rq_depth    = attr->max_recv_dtos;\r
+    qp_create.sq_sge      = attr->max_recv_iov;\r
+    qp_create.rq_sge      = attr->max_request_iov;                       \r
+    qp_create.h_sq_cq     = cq_send;\r
+    qp_create.h_rq_cq     = cq_recv;\r
+    qp_create.sq_signaled = FALSE;\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, \r
+                  "--> DsQA: sqd,iov=%d,%d rqd,iov=%d,%d\n", \r
+                  attr->max_request_dtos, attr->max_request_iov,\r
+                  attr->max_recv_dtos, attr->max_recv_iov); \r
+    \r
+    ib_status = ib_create_qp ( \r
+                       ib_pd_handle,\r
+                       &qp_create,\r
+                       (void *) ep_ctx_ptr /* context */,\r
+                       dapli_ib_qp_async_error_cb,\r
+                       &ep_ptr->qp_handle);\r
+\r
+    if (ib_status != IB_SUCCESS)\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsQA: Create QP failed = %s\n",\r
+                      ib_get_err_str(ib_status));\r
+       return (DAT_INSUFFICIENT_RESOURCES);\r
+    }\r
+    /* EP-CM linking */\r
+    cm_ptr = ibal_cm_alloc();\r
+    if (!cm_ptr) \r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsQA: Create CM failed\n");\r
+       return (DAT_INSUFFICIENT_RESOURCES);\r
+    }\r
+    cm_ptr->ib_cm.h_qp = ep_ptr->qp_handle;\r
+    cm_ptr->ep = ep_ptr;\r
+    dapl_ep_link_cm(ep_ptr, cm_ptr); \r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQA: EP=%p, tEVD=%p, rEVD=%p QP=%p\n",\r
+                  ep_ptr, ep_ptr->param.request_evd_handle,\r
+                  ep_ptr->param.recv_evd_handle,\r
+                  ep_ptr->qp_handle ); \r
+\r
+    ep_ptr->qp_state = IB_QPS_RESET;\r
+\r
+    p_active_port = dapli_ibal_get_port(p_ca,(uint8_t)ia_ptr->hca_ptr->port_num);\r
+\r
+    if (NULL == p_active_port)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> DsQA: Port %d is not available = %d\n",\r
+                      ia_ptr->hca_ptr->port_num, __LINE__);\r
+        return (DAT_INVALID_STATE);\r
+    }\r
+\r
+    ib_status = dapls_modify_qp_state_to_init ( ep_ptr->qp_handle, \r
+                                               &ep_ptr->param.ep_attr,\r
+                                                p_active_port );\r
+\r
+    if ( ib_status != IB_SUCCESS )\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> DsQA: Change QP state to INIT failed = %s\n",\r
+                      ib_get_err_str(ib_status));\r
+       return (DAT_INVALID_HANDLE);\r
+    }\r
+    ib_status = ib_query_qp ( ep_ptr->qp_handle, &qp_attr );\r
+\r
+    ep_ptr->qp_state = qp_attr.state;\r
+    ep_ptr->qpn = qp_attr.num;\r
+    \r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQAQA: EP:%p new_QP %p state %s\n",\r
+                  ep_ptr,\r
+                  ep_ptr->qp_handle,\r
+                  ib_get_port_state_str(ep_ptr->qp_state));\r
+\r
+    return (DAT_SUCCESS);\r
+}\r
+\r
+\r
+/*\r
+ * dapls_ib_qp_free\r
+ *\r
+ * Free a QP\r
+ *\r
+ * Input:\r
+ *        *ia_ptr                pointer to IA structure\r
+ *        *ep_ptr                pointer to EP structure\r
+ *\r
+ * Output:\r
+ *         none\r
+ *\r
+ * Returns:\r
+ *         none\r
+ *\r
+ */\r
+DAT_RETURN\r
+dapls_ib_qp_free (\r
+        IN  DAPL_IA                *ia_ptr,\r
+        IN  DAPL_EP                *ep_ptr )\r
+{\r
+\r
+       ib_qp_handle_t          qp_handle;\r
+       UNREFERENCED_PARAMETER(ia_ptr);\r
+\r
+       dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQF: free %p, state %s\n", \r
+                      ep_ptr->qp_handle,\r
+                      ib_get_port_state_str(ep_ptr->qp_state));\r
+\r
+       if (( ep_ptr->qp_handle != IB_INVALID_HANDLE ) &&\r
+           ( ep_ptr->qp_state != DAPL_QP_STATE_UNATTACHED ))\r
+       {\r
+               qp_handle = ep_ptr->qp_handle;\r
+               ep_ptr->qp_handle = IB_INVALID_HANDLE;\r
+               ep_ptr->qp_state = DAPL_QP_STATE_UNATTACHED;\r
+               ib_destroy_qp ( qp_handle, NULL /* callback */);\r
+               dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsQF: freed QP %p\n",\r
+                               qp_handle ); \r
+       }\r
+\r
+    return DAT_SUCCESS;\r
+}\r
+\r
+\r
+/*\r
+ * dapls_ib_qp_modify\r
+ *\r
+ * Set the QP to the parameters specified in an EP_PARAM\r
+ *\r
+ * We can't be sure what state the QP is in so we first obtain the state\r
+ * from the driver. The EP_PARAM structure that is provided has been\r
+ * sanitized such that only non-zero values are valid.\r
+ *\r
+ * Input:\r
+ *        *ia_ptr                pointer to DAPL IA\r
+ *        *ep_ptr                pointer to DAPL EP\r
+ *        *ep_attr               pointer to DAT EP attribute\r
+ *\r
+ * Output:\r
+ *         none\r
+ *\r
+ * Returns:\r
+ *         DAT_SUCCESS\r
+ *        DAT_INSUFFICIENT_RESOURCES\r
+ *        DAT_INVALID_PARAMETER\r
+ *\r
+ */\r
+DAT_RETURN\r
+dapls_ib_qp_modify (\r
+        IN  DAPL_IA                        *ia_ptr,\r
+        IN  DAPL_EP                        *ep_ptr,\r
+        IN  DAT_EP_ATTR                    *ep_attr )\r
+{\r
+    ib_qp_attr_t                  qp_attr;\r
+    ib_api_status_t               ib_status;\r
+    ib_qp_handle_t                qp_handle;\r
+    ib_qp_state_t                 qp_state;\r
+    ib_qp_mod_t                   qp_mod;\r
+    ib_av_attr_t                  *p_av_attr;\r
+    ib_qp_opts_t                  *p_qp_opts;\r
+    uint32_t                      *p_sq_depth, *p_rq_depth;\r
+    DAT_BOOLEAN                   need_modify;\r
+    DAT_RETURN                    dat_status;\r
+\r
+    qp_handle     = ep_ptr->qp_handle;\r
+    need_modify   = DAT_FALSE;\r
+    dat_status    = DAT_SUCCESS;\r
+    if ( ia_ptr == NULL || ia_ptr->header.magic != DAPL_MAGIC_IA )\r
+    {\r
+       dat_status = DAT_INVALID_HANDLE;\r
+       goto bail;\r
+    }\r
+    /* \r
+     * Query the QP to get the current state.\r
+     */\r
+    ib_status = ib_query_qp ( qp_handle, &qp_attr );\r
+                       \r
+    if ( ib_status != IB_SUCCESS )\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsIQM: Query QP failed = %s\n",\r
+                       ib_get_err_str(ib_status));\r
+        dat_status = DAT_INTERNAL_ERROR;\r
+        goto bail;\r
+    }\r
+\r
+    qp_state = qp_attr.state;\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM: modify qp state=%d\n",qp_state);\r
+    /*\r
+     * Check if we have the right qp_state or not\r
+     */\r
+    if ( (qp_state != IB_QPS_RTR ) && (qp_state != IB_QPS_RTS ) )\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_EP,\r
+                      "--> DsIQM: postpone to modify qp to EP values later\n");\r
+        dat_status = DAT_SUCCESS;\r
+        goto bail;\r
+    }\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    if (qp_state == IB_QPS_RTR)\r
+    {\r
+        p_av_attr   = &qp_mod.state.rtr.primary_av;\r
+        p_qp_opts   = &qp_mod.state.rtr.opts;\r
+        p_sq_depth  = &qp_mod.state.rtr.sq_depth;\r
+        p_rq_depth  = &qp_mod.state.rtr.rq_depth;\r
+    }\r
+    else\r
+    {\r
+        /*\r
+        * RTS does not have primary_av field\r
+        */\r
+        p_av_attr   = &qp_mod.state.rts.alternate_av;\r
+        p_qp_opts   = &qp_mod.state.rts.opts;\r
+        p_sq_depth  = &qp_mod.state.rts.sq_depth;\r
+        p_rq_depth  = &qp_mod.state.rts.rq_depth;\r
+    }\r
+\r
+    if ( (ep_attr->max_recv_dtos > 0) &&\r
+               ((DAT_UINT32)ep_attr->max_recv_dtos != qp_attr.rq_depth) )\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_EP,"--> DsIQM: rq_depth modified (%d,%d)\n",\r
+                       qp_attr.rq_depth, ep_attr->max_recv_dtos);\r
+\r
+        *p_rq_depth = ep_attr->max_recv_dtos;\r
+        *p_qp_opts |= IB_MOD_QP_RQ_DEPTH;\r
+        need_modify = DAT_TRUE;\r
+    }\r
+\r
+    if ( (ep_attr->max_request_dtos > 0) &&\r
+               ((DAT_UINT32)ep_attr->max_request_dtos != qp_attr.sq_depth) ) \r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_EP,\r
+                       "--> DsIQM: sq_depth modified (%d,%d)\n",\r
+                       qp_attr.sq_depth, ep_attr->max_request_dtos);\r
+\r
+        *p_sq_depth = ep_attr->max_request_dtos;\r
+        *p_qp_opts |= IB_MOD_QP_SQ_DEPTH;\r
+        need_modify = DAT_TRUE;\r
+    }\r
+\r
+    qp_mod.req_state  = qp_state;\r
+\r
+    if ( need_modify == DAT_TRUE )\r
+    {\r
+       ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+        if ( ib_status != IB_SUCCESS)\r
+        {\r
+           dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> %s: ib_status = %d\n",\r
+                          "DsIQM", ib_status);\r
+           dat_status = DAT_INTERNAL_ERROR;\r
+        }\r
+    }\r
+\r
+bail:\r
+\r
+    return dat_status;\r
+}\r
+\r
+\r
+ib_api_status_t \r
+dapls_modify_qp_state_to_error ( ib_qp_handle_t  qp_handle )\r
+{\r
+    ib_qp_mod_t      qp_mod;\r
+    ib_api_status_t  ib_status;\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_Err: QP state change --> Err\n");\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    qp_mod.req_state  = IB_QPS_ERROR;\r
+\r
+    ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+\r
+    return (ib_status);\r
+}\r
+\r
+\r
+ib_api_status_t \r
+dapls_modify_qp_state_to_reset ( ib_qp_handle_t  qp_handle )\r
+{\r
+    ib_qp_mod_t      qp_mod;\r
+    ib_api_status_t  ib_status;\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RESET: QP state change\n");\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    qp_mod.req_state  = IB_QPS_RESET;\r
+\r
+    ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+\r
+    return (ib_status);\r
+}\r
+\r
+\r
+ib_api_status_t \r
+dapls_modify_qp_state_to_init (\r
+        IN    ib_qp_handle_t         qp_handle,\r
+        IN    DAT_EP_ATTR            *p_attr,\r
+        IN    dapl_ibal_port_t       *p_port )\r
+{\r
+    ib_qp_mod_t                   qp_mod;\r
+    ib_api_status_t               ib_status;\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    qp_mod.req_state               = IB_QPS_INIT;\r
+    qp_mod.state.init.primary_port = p_port->p_attr->port_num;\r
+    qp_mod.state.init.qkey         = DAPL_IBAL_QKEY;\r
+    qp_mod.state.init.pkey_index   = 0;\r
+    qp_mod.state.init.access_ctrl = IB_AC_LOCAL_WRITE |\r
+                                       IB_AC_RDMA_WRITE |\r
+                                       IB_AC_MW_BIND |\r
+                                       IB_AC_ATOMIC;\r
+    if ((p_attr->max_rdma_read_in > 0) || (p_attr->max_rdma_read_out > 0))\r
+    {\r
+       qp_mod.state.init.access_ctrl |= IB_AC_RDMA_READ;\r
+    }\r
+    ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_INIT: QP(%p) state change, %s\n",\r
+                  qp_handle, ib_get_err_str(ib_status));\r
+\r
+    return (ib_status);\r
+}\r
+\r
+\r
+ib_api_status_t \r
+dapls_modify_qp_state_to_rtr (\r
+        ib_qp_handle_t          qp_handle,\r
+        ib_net32_t              dest_qp,\r
+        ib_lid_t                dest_lid,\r
+        dapl_ibal_port_t        *p_port)\r
+{\r
+    ib_qp_mod_t                 qp_mod;\r
+    ib_api_status_t             ib_status;\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    qp_mod.req_state                        = IB_QPS_RTR;\r
+    qp_mod.state.rtr.rq_psn                 = DAPL_IBAL_START_PSN;\r
+    qp_mod.state.rtr.dest_qp                = dest_qp;\r
+    qp_mod.state.rtr.primary_av.port_num    = p_port->p_attr->port_num;\r
+    qp_mod.state.rtr.primary_av.sl          = 0;\r
+    qp_mod.state.rtr.primary_av.dlid        = dest_lid;\r
+    qp_mod.state.rtr.primary_av.grh_valid   = 0; /* FALSE */\r
+    qp_mod.state.rtr.primary_av.static_rate = IB_PATH_RECORD_RATE_10_GBS;\r
+    qp_mod.state.rtr.primary_av.path_bits   = 0;\r
+    qp_mod.state.rtr.primary_av.conn.path_mtu = p_port->p_attr->mtu;\r
+    qp_mod.state.rtr.primary_av.conn.local_ack_timeout = 7;\r
+    qp_mod.state.rtr.primary_av.conn.seq_err_retry_cnt = 7;\r
+    qp_mod.state.rtr.primary_av.conn.rnr_retry_cnt = IB_RNR_RETRY_CNT;\r
+    qp_mod.state.rtr.resp_res               = 4; // in-flight RDMAs\r
+    qp_mod.state.rtr.rnr_nak_timeout        = IB_RNR_NAK_TIMEOUT;\r
\r
+    ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+    \r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RTR: QP(%p) state change %s\n",\r
+                  qp_handle, ib_get_err_str(ib_status));\r
+\r
+    return (ib_status);\r
+}\r
+\r
+ib_api_status_t \r
+dapls_modify_qp_state_to_rts ( ib_qp_handle_t  qp_handle )\r
+{\r
+    ib_qp_mod_t        qp_mod;\r
+    ib_api_status_t    ib_status;\r
+\r
+    dapl_os_memzero (&qp_mod, sizeof (ib_qp_mod_t));\r
+\r
+    qp_mod.req_state                   = IB_QPS_RTS;\r
+    qp_mod.state.rts.sq_psn            = DAPL_IBAL_START_PSN;\r
+    qp_mod.state.rts.retry_cnt         = 7;\r
+    qp_mod.state.rts.rnr_retry_cnt     = IB_RNR_RETRY_CNT;\r
+    qp_mod.state.rtr.rnr_nak_timeout   = IB_RNR_NAK_TIMEOUT;\r
+    qp_mod.state.rts.local_ack_timeout = 7;\r
+    qp_mod.state.rts.init_depth        = 4; \r
+\r
+    ib_status = ib_modify_qp (qp_handle, &qp_mod);\r
+\r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP, "--> DsIQM_RTS: QP(%p) state change %s\n",\r
+                  qp_handle, ib_get_err_str(ib_status));\r
+\r
+    return (ib_status);\r
+}\r
+\r
+\r
+/*\r
+ * dapls_ib_reinit_ep\r
+ *\r
+ * Move the QP to INIT state again.\r
+ *\r
+ * Input:\r
+ *     ep_ptr          DAPL_EP\r
+ *\r
+ * Output:\r
+ *     none\r
+ *\r
+ * Returns:\r
+ *     void\r
+ *\r
+ */\r
+void\r
+dapls_ib_reinit_ep ( IN DAPL_EP  *ep_ptr )\r
+{\r
+    DAPL_IA                  *ia_ptr;\r
+    ib_api_status_t          ib_status;\r
+    dapl_ibal_ca_t           *p_ca;\r
+    dapl_ibal_port_t         *p_active_port;\r
+       \r
+    dapl_dbg_log (DAPL_DBG_TYPE_EP,\r
+                  "--> DsIQM_REINIT: EP(%p) QP(%p) state change\n", \r
+                  ep_ptr, ep_ptr->qp_handle );\r
+\r
+    if ( ep_ptr->param.ep_state != DAT_EP_STATE_DISCONNECTED )\r
+    {\r
+       dapl_dbg_log (DAPL_DBG_TYPE_ERR, "--> DsIRE: EP invalid state(%d)\n",\r
+                      ep_ptr->param.ep_state);\r
+       return /*DAT_INVALID_STATE*/;\r
+    }\r
+\r
+    ia_ptr = ep_ptr->header.owner_ia;\r
+\r
+    /* Re-create QP if cleaned up, alloc will return init state */\r
+    if ( ep_ptr->qp_handle == IB_INVALID_HANDLE )\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_EP,\r
+                      "--> DsIRE: !EP(%p)->qp_handle, re-create QP\n",ep_ptr);\r
+        ib_status = dapls_ib_qp_alloc ( ia_ptr, ep_ptr, ep_ptr );\r
+        if ( ib_status != IB_SUCCESS )\r
+        {\r
+            dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> DsIRE: failed to move qp to RESET status = %s\n", \r
+                      ib_get_err_str(ib_status));\r
+        }\r
+        return /*ib_status*/;\r
+    }\r
+\r
+    ib_status = dapls_modify_qp_state_to_reset (ep_ptr->qp_handle);\r
+\r
+    if ( ib_status != IB_SUCCESS )\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> DsIRE: failed to move qp to RESET status = %s\n", \r
+                      ib_get_err_str(ib_status));\r
+        return /*DAT_INTERNAL_ERROR*/;\r
+    }\r
+\r
+    ep_ptr->qp_state = IB_QPS_RESET;\r
+\r
+    p_ca   = (dapl_ibal_ca_t *) ia_ptr->hca_ptr->ib_hca_handle;\r
+    p_active_port = dapli_ibal_get_port ( p_ca,\r
+                                          (uint8_t)ia_ptr->hca_ptr->port_num );\r
+    if (NULL == p_active_port)\r
+    {\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                     "--> DsIRE: Port %d is not available = %d\n",\r
+                     ia_ptr->hca_ptr->port_num, __LINE__);\r
+        return /*DAT_INTERNAL_ERROR*/;\r
+    }\r
+\r
+       /* May fail if QP still RESET and in timewait, keep in reset state */\r
+    ib_status = dapls_modify_qp_state_to_init ( ep_ptr->qp_handle,\r
+                                                &ep_ptr->param.ep_attr,\r
+                                                p_active_port);\r
+    if ( ib_status != IB_SUCCESS )\r
+    {\r
+        ep_ptr->qp_state = IB_QPS_RESET;\r
+\r
+        dapl_dbg_log (DAPL_DBG_TYPE_ERR,\r
+                      "--> DsIRE: failed to move qp to INIT status %s\n", \r
+                      ib_get_err_str(ib_status));\r
+        return /*DAT_INTERNAL_ERROR*/;\r
+    }\r
+    ep_ptr->qp_state = IB_QPS_INIT;\r
+}\r
+\r
+\r
+/*\r
+ * Local variables:\r
+ *  c-indent-level: 4\r
+ *  c-basic-offset: 4\r
+ *  tab-width: 8\r
+ * End:\r
+ */\r
+\r
index a73d6c1..d5d6b4c 100644 (file)
-
-/*
- * 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.h
- *
- * PURPOSE: Utility defs & routines for access to openib-windows IBAL APIs
- *
- * $Id: dapl_ibal_util.h 33 2005-07-11 19:51:17Z ftillier $
- *
- **********************************************************************/
-
-#ifndef _DAPL_IBAL_UTIL_H_
-#define _DAPL_IBAL_UTIL_H_
-
-#include <iba/ib_al.h>
-#include <complib/cl_spinlock.h>
-#include <complib/cl_qlist.h>
-#include <complib/cl_atomic.h>
-
-#ifdef DAT_EXTENSIONS
-#include <dat2\dat_ib_extensions.h>
-#endif
-
-/*
- * Typedefs to map IBAL types to more generic 'ib' types
- */
-#ifdef SOCK_CM
-typedef  struct ib_cm_handle           *dp_ib_cm_handle_t;
-typedef  struct ib_cm_handle           *ib_cm_srvc_handle_t;
-#else
-typedef  ib_cm_handle_t                *dp_ib_cm_handle_t;
-typedef  ib_listen_handle_t            ib_cm_srvc_handle_t;
-#endif
-
-typedef  ib_net64_t                    IB_HCA_NAME;
-typedef  ib_ca_handle_t                ib_hca_handle_t;
-typedef  DAT_PVOID                     ib_cqd_handle_t;
-typedef  ib_async_event_rec_t          ib_error_record_t;
-typedef  ib_wr_type_t                  ib_send_op_type_t;
-typedef  ib_wc_t                       ib_work_completion_t;
-typedef  uint32_t                      ib_hca_port_t;
-typedef  uint32_t                      ib_uint32_t;
-typedef  ib_local_ds_t                 ib_data_segment_t;
-
-typedef  unsigned __int3264            cl_dev_handle_t;
-
-
-typedef void (*ib_async_handler_t)(
-    IN    ib_hca_handle_t    ib_hca_handle,
-    IN    ib_error_record_t  *err_code,
-    IN    void               *context);
-
-typedef void (*ib_async_qp_handler_t)(
-    IN    ib_hca_handle_t    ib_hca_handle,
-    IN    ib_qp_handle_t     ib_qp_handle,
-    IN    ib_error_record_t  *err_code,
-    IN    void               *context);
-
-typedef void (*ib_async_cq_handler_t)(
-    IN    ib_hca_handle_t    ib_hca_handle,
-    IN    ib_cq_handle_t     ib_cq_handle,
-    IN    ib_error_record_t  *err_code,
-    IN    void               *context);
-
-typedef ib_net64_t   ib_guid_t;
-typedef ib_net16_t   ib_lid_t;
-typedef boolean_t    ib_bool_t;
-
-typedef struct _GID
-{
-    uint64_t gid_prefix;
-    uint64_t guid;
-} GID;
-
-typedef enum 
-{
-    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
-} ib_cm_events_t;
-
-
-typedef enum
-{
-    IB_NOTIFY_ON_NEXT_COMP,
-    IB_NOTIFY_ON_SOLIC_COMP
-} ib_notification_type_t;
-
-typedef struct _ib_hca_name
-{
-    DAT_NAME_PTR hca_name[DAT_NAME_MAX_LENGTH];
-} ib_hca_name_t;
-
-
-#define          IB_INVALID_HANDLE             NULL
-#define          true                          TRUE
-#define          false                         FALSE
-
-#define          IB_MAX_REQ_PDATA_SIZE      92
-#define          IB_MAX_REP_PDATA_SIZE      196
-#define          IB_MAX_REJ_PDATA_SIZE      148
-#define          IB_MAX_DREQ_PDATA_SIZE     220
-#define          IB_MAX_DREP_PDATA_SIZE     224
-
-
-/* Resource Not Ready
-       1-6 is an actual retry count which is decremented to zero before
-        an error condition is set.
-    7 is 'magic' in that it implies Infinite retry, just keeps trying.
-*/
-#define                IB_RNR_RETRY_CNT   7
-
-/*
-IB 1.2 spec, page 331, table 45, RNR NAK timeout encoding (5-bits)
-00000=655.36ms(milliseconds)
-00001=0.01ms
-00010=0.02ms
-00011=0.03ms
-00100=0.04ms
-00101=0.06ms
-00110=0.08ms
-00111=0.12ms
-
-11100=163.84ms 28d
-11101=245.76ms 29d
-11110=327.68ms 30d
-11111=491.52ms 31d
-*/
-#define                IB_RNR_NAK_TIMEOUT   0
-
-
-typedef void
-(*dapl_ibal_pfn_destructor_t)(
-    IN    void*    context );
-
-typedef struct _dapl_ibal_refs
-{
-    atomic32_t                      count;        // number of references
-    void*                         context;     // context for destructor
-    dapl_ibal_pfn_destructor_t    destructor;   // called when reference goes to zero
-
-} dapl_ibal_refs_t;
-
-
-typedef struct _dapl_ibal_root
-{
-    ib_al_handle_t        h_al;        // handle to Access Layer
-    cl_spinlock_t         ca_lock;     // CA list lock
-    cl_qlist_t            ca_head;     // list head of CAs
-    boolean_t             shutdown;    // when true, driver is shutting down
-    boolean_t             initialized;    // when true, lib is initialized 
-
-} dapl_ibal_root_t;
-
-
-typedef struct _dapl_ibal_ca
-{
-    cl_list_item_t    next;        // peer CA list
-    ib_ca_handle_t    h_ca;        // handle to open CA
-    ib_ca_attr_t      *p_ca_attr;  // CA attributes
-    uint32_t          ca_attr_size;// size of ca attribute
-    dapl_ibal_refs_t  refs;        // reference counting
-    cl_spinlock_t     port_lock;   // port list lock
-    cl_qlist_t        port_head;   // port list head for this CA
-    cl_spinlock_t     evd_cb_lock; // EVD async error cb list lock
-    cl_qlist_t        evd_cb_head; // EVD async error cb list head for this CA
-    cl_dev_handle_t   mlnx_device;
-    DAT_PVOID         *ia_ptr;     // hook for CA async callbacks
-} dapl_ibal_ca_t;
-
-
-typedef struct _dapl_ibal_port
-{
-    cl_list_item_t    next;            // peer CA list
-    dapl_ibal_ca_t    *ca;             // pointer to parent CA
-    ib_port_attr_t    *p_attr;         // port attributes
-    dapl_ibal_refs_t  refs;            // reference counting
-} dapl_ibal_port_t;
-
-typedef struct _dapl_ibal_evd_cb
-{
-    cl_list_item_t     next;        // peer CA list
-    ib_async_handler_t pfn_async_err_cb;
-    ib_async_qp_handler_t  pfn_async_qp_err_cb;
-    ib_async_cq_handler_t  pfn_async_cq_err_cb;
-    void               *context;
-} dapl_ibal_evd_cb_t;
-
-/*
- * Definitions to map DTO OPs to IBAL Work-Request ops.
- */
-#define    OP_BAD_OPCODE      0
-#define    OP_RDMA_READ       WR_RDMA_READ
-#define    OP_RDMA_WRITE      WR_RDMA_WRITE
-#define    OP_SEND            WR_SEND
-#define    OP_COMP_AND_SWAP   WR_COMPARE_SWAP
-#define    OP_FETCH_AND_ADD   WR_FETCH_ADD
-
-#define    OP_RECEIVE         8                /* (8)  */
-#define    OP_BIND_MW         9                /* no-equivalent */
-#define    OP_RDMA_WRITE_IMM  10       /* RDMA_WRITE+Immediate data */
-#define    OP_RECEIVE_IMM     11       /* no-equivalent */
-
-/*
- * Definitions to map QP state
- */
-#define IB_QP_STATE_RESET    IB_QPS_RESET
-#define IB_QP_STATE_INIT     IB_QPS_INIT
-#define IB_QP_STATE_RTR      IB_QPS_RTR
-#define IB_QP_STATE_RTS      IB_QPS_RTS
-#define IB_QP_STATE_SQE      IB_QPS_SQERR
-#define IB_QP_STATE_SQD      IB_QPS_SQD
-#define IB_QP_STATE_ERROR    IB_QPS_ERROR
-
-/*
- * Definitions to map Memory OPs
- */
-#define IB_ACCESS_LOCAL_WRITE      IB_AC_LOCAL_WRITE
-#define IB_ACCESS_REMOTE_READ      IB_AC_RDMA_READ
-#define IB_ACCESS_REMOTE_WRITE     IB_AC_RDMA_WRITE
-#define IB_ACCESS_REMOTE_ATOMIC    IB_AC_ATOMIC
-#define IB_ACCESS_MEM_WINDOW_BIND  IB_AC_MW_BIND
-
-/*
- * CQE status 
- */
-enum _dapl_comp_status
-{
-       IB_COMP_ST_SUCCESS              = IB_WCS_SUCCESS,
-       IB_COMP_ST_LOCAL_LEN_ERR        = IB_WCS_LOCAL_LEN_ERR,
-       IB_COMP_ST_LOCAL_OP_ERR         = IB_WCS_LOCAL_OP_ERR,
-       IB_COMP_ST_LOCAL_PROTECT_ERR    = IB_WCS_LOCAL_PROTECTION_ERR,
-       IB_COMP_ST_WR_FLUSHED_ERR       = IB_WCS_WR_FLUSHED_ERR,
-       IB_COMP_ST_MW_BIND_ERR          = IB_WCS_MEM_WINDOW_BIND_ERR,
-       IB_COMP_ST_REM_ACC_ERR          = IB_WCS_REM_ACCESS_ERR,
-       IB_COMP_ST_REM_OP_ERR           = IB_WCS_REM_OP_ERR,
-       IB_COMP_ST_RNR_COUNTER          = IB_WCS_RNR_RETRY_ERR,
-       IB_COMP_ST_TRANSP_COUNTER       = IB_WCS_TIMEOUT_RETRY_ERR,
-       IB_COMP_ST_REM_REQ_ERR          = IB_WCS_REM_INVALID_REQ_ERR,
-       IB_COMP_ST_BAD_RESPONSE_ERR     = IB_WCS_UNMATCHED_RESPONSE,
-       IB_COMP_ST_EE_STATE_ERR,
-       IB_COMP_ST_EE_CTX_NO_ERR
-};
-
-
-/*
- * Macro to check the state of an EP/QP
- */
-#define DAPLIB_NEEDS_INIT(ep)  ((ep)->qp_state == IB_QPS_ERROR)
-
-
-/*
- * Resolve IBAL return codes to their DAPL equivelent.
- * Do not return invalid Handles, the user is not able
- * to deal with them.
- */
-STATIC _INLINE_ DAT_RETURN 
-dapl_ib_status_convert (
-    IN     int32_t     ib_status)
-{
-    switch ( ib_status )
-    {
-    case IB_SUCCESS:
-    {
-        return DAT_SUCCESS;
-    }
-    case IB_INSUFFICIENT_RESOURCES:
-    case IB_INSUFFICIENT_MEMORY:
-    case IB_RESOURCE_BUSY:
-    {
-        return DAT_INSUFFICIENT_RESOURCES;
-    }
-    case IB_INVALID_CA_HANDLE:
-    case IB_INVALID_CQ_HANDLE:
-    case IB_INVALID_QP_HANDLE:
-    case IB_INVALID_PD_HANDLE:
-    case IB_INVALID_MR_HANDLE:
-    case IB_INVALID_MW_HANDLE:
-    case IB_INVALID_AL_HANDLE:
-    case IB_INVALID_AV_HANDLE:
-    {
-        return DAT_INVALID_HANDLE;
-    }
-    case IB_INVALID_PKEY:
-    {
-        return DAT_PROTECTION_VIOLATION;
-    }
-    case IB_INVALID_LKEY:
-    case IB_INVALID_RKEY:
-    case IB_INVALID_PERMISSION:
-    {
-        return DAT_PRIVILEGES_VIOLATION;
-    }
-    case IB_INVALID_MAX_WRS:
-    case IB_INVALID_MAX_SGE:
-    case IB_INVALID_CQ_SIZE:
-    case IB_INVALID_SETTING:
-    case IB_INVALID_SERVICE_TYPE:
-    case IB_INVALID_GID:
-    case IB_INVALID_LID:
-    case IB_INVALID_GUID:
-    case IB_INVALID_PARAMETER:
-    {
-        return DAT_INVALID_PARAMETER;
-    }
-    case IB_INVALID_QP_STATE:
-    case IB_INVALID_APM_STATE:
-    case IB_INVALID_PORT_STATE:
-    case IB_INVALID_STATE:
-    {
-        return DAT_INVALID_STATE;
-    }
-    case IB_NOT_FOUND:
-    {
-        return DAT_QUEUE_EMPTY;
-    }
-    case IB_OVERFLOW:
-    {
-        return DAT_QUEUE_FULL;
-    }
-    case IB_UNSUPPORTED:
-    {
-        return DAT_NOT_IMPLEMENTED;
-    }
-    case IB_TIMEOUT:
-    {
-        return DAT_TIMEOUT_EXPIRED;
-    }
-    case IB_CANCELED:
-    {
-        return DAT_ABORT;
-    }
-    default:
-    {
-        return DAT_INTERNAL_ERROR;
-    }
-    }
-}
-   
-#define TAKE_LOCK( lock ) \
-        cl_spinlock_acquire( &(lock) )
-
-#define RELEASE_LOCK( lock ) \
-        cl_spinlock_release( &(lock) )
-
-#define LOCK_INSERT_HEAD( lock, head, item ) \
-{ \
-        TAKE_LOCK( lock ); \
-        cl_qlist_insert_head( &head, (cl_list_item_t*)(&item) ); \
-        RELEASE_LOCK( lock ); \
-}
-
-#define LOCK_INSERT_TAIL( lock, tail, item&nb