[IBAL] Fix CEP destruction.
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 9 Jul 2008 10:39:14 +0000 (10:39 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 9 Jul 2008 10:39:14 +0000 (10:39 +0000)
In my previous patch "Fix race reading/setting connection ID" I incorrectly stated that the patch changed the semantics of creation/destruction of the CEPs by providing the destroy callback at CEP creation time.  It didn't, but this patch does.

Note that it also backs out the "Cleanup CEPs after child objects have been destroyed" changes, as those actually introduced the following issue:

UM listen CEPs are not tracked in AL's handle table, but can queue MADs which take a reference on the AL instance.  AL's destroying callback must cleanup the CEPs to free the MADs in order for the ref count to reach zero.

The root problem, and the iterations of the fix that are apparent in the patch sequence has to do with race conditions cleaning up QPs while CM messages are being received and processed.  First there was the issue of the CID stored in the QP having two reserved states and races checking/assigning this value.  This was fixed (successfully) by pushing checks into the CEP manager, protected by the CEP manager's spinlock.  Next was the issue that a reference on the QP is taken when the CEP is bound to a QP, but if AL was destroyed the CEP cleanup in AL would blow away the CEPs before the QPs were done being destroyed.  This would leak a reference count on the QP since the CEP was destroyed without a destroy callback.  The change that added a cleanup callback to AL was the first (failed) attempt to fix this (for the reasons listed above).  This patch is the successful attempt to fix this, as it sets the destroy callback at creation time.  No matter what path destroys the CEP, if a destroy callback was taken (because some object has a reference for the CEP), the destroy callback will always be invoked.

Signed-off-by: Fab Tillier <ftillier@microsoft.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1356 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/al/al.c
core/al/al.h
core/al/al_cm_cep.h
core/al/al_cm_qp.c
core/al/al_qp.c
core/al/kernel/al_cm_cep.c
core/al/kernel/al_mgr.c
core/al/kernel/al_ndi_cm.c
core/al/kernel/al_proxy_cep.c
core/al/kernel/al_proxy_ndi.c
core/al/user/ual_cm_cep.c

index db8c0e2..f1e648f 100644 (file)
@@ -116,18 +116,13 @@ destroying_al(
        }\r
 \r
        cl_spinlock_release( &p_obj->lock );\r
-}\r
-\r
 \r
-void\r
-cleanup_al(\r
-       IN                              al_obj_t                                        *p_obj )\r
-{\r
        /* Cleanup any left-over connections. */\r
-       al_cep_cleanup_al( PARENT_STRUCT( p_obj, ib_al_t, obj ) );\r
+       al_cep_cleanup_al( h_al );\r
 }\r
 \r
 \r
+\r
 static void\r
 __free_mads(\r
        IN                              const   ib_al_handle_t          h_al )\r
index 58da621..07e402d 100644 (file)
@@ -108,11 +108,6 @@ destroying_al(
        IN                              al_obj_t                                        *p_obj );\r
 \r
 \r
-void\r
-cleanup_al(\r
-       IN                              al_obj_t                                        *p_obj );\r
-\r
-\r
 void\r
 free_al(\r
        IN                              al_obj_t                                        *p_obj );\r
index 6011827..10659b9 100644 (file)
@@ -98,6 +98,7 @@ al_create_cep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb OPTIONAL,\r
        IN      OUT                     net32_t* const                          p_cid );\r
 /*\r
 * NOTES\r
@@ -112,8 +113,7 @@ void
 al_destroy_cep(\r
        IN                              ib_al_handle_t                          h_al,\r
        IN      OUT                     net32_t* const                          p_cid,\r
-       IN                              boolean_t                                       reusable,\r
-       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb );\r
+       IN                              boolean_t                                       reusable );\r
 /*\r
 *********/\r
 \r
@@ -143,6 +143,7 @@ al_cep_pre_rep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              net32_t                                         cid,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb OPTIONAL,\r
        IN              const   ib_cm_rep_t* const                      p_cm_rep,\r
        IN      OUT                     net32_t* const                          p_cid,\r
                OUT                     ib_qp_mod_t* const                      p_init );\r
@@ -153,6 +154,7 @@ al_cep_pre_rep_ex(
        IN                              net32_t                                         cid,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb OPTIONAL,\r
        IN              const   ib_cm_rep_t* const                      p_cm_rep,\r
        IN      OUT                     net32_t* const                          p_cid,\r
                OUT                     ib_qp_mod_t* const                      p_init );\r
index 457a17d..2107ee7 100644 (file)
@@ -280,7 +280,7 @@ __proc_listen(
                CL_ASSERT( p_mad->attr_id == CM_REQ_ATTR_ID ||\r
                        p_mad->attr_id == CM_SIDR_REQ_ATTR_ID );\r
                /* Destroy the new CEP as it won't ever be reported to the user. */\r
-               al_destroy_cep( p_listen->obj.h_al, &new_cid, FALSE, NULL );\r
+               al_destroy_cep( p_listen->obj.h_al, &new_cid, FALSE );\r
        }\r
 \r
        AL_EXIT( AL_DBG_CM );\r
@@ -319,8 +319,7 @@ __proc_conn_timeout(
        /* Unbind the QP from the CEP. */\r
        __cep_timewait_qp( h_qp );\r
 \r
-       al_destroy_cep(\r
-               h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
 \r
        /* Invoke the callback. */\r
        ((al_conn_qp_t*)h_qp)->pfn_cm_rej_cb( &rej_rec );\r
@@ -376,8 +375,7 @@ __proc_dconn_timeout(
 \r
        __cep_timewait_qp( h_qp );\r
 \r
-       al_destroy_cep(\r
-               h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
 \r
        /* Call the user back. */\r
        ((al_conn_qp_t*)h_qp)->pfn_cm_drep_cb( &drep_rec );\r
@@ -509,8 +507,7 @@ __proc_rej(
                 */\r
                __cep_timewait_qp( p_cm->h_qp );\r
 \r
-               al_destroy_cep(\r
-                       p_cm->h_al, &((al_conn_qp_t*)p_cm->h_qp)->cid, TRUE, deref_al_obj );\r
+               al_destroy_cep( p_cm->h_al, &((al_conn_qp_t*)p_cm->h_qp)->cid, TRUE );\r
 \r
                /* Call the user back. */\r
                ((al_conn_qp_t*)p_cm->h_qp)->pfn_cm_rej_cb( &rej_rec );\r
@@ -608,8 +605,7 @@ __proc_drep(
 \r
        __cep_timewait_qp( p_cm->h_qp );\r
 \r
-       al_destroy_cep(\r
-               p_cm->h_al, &((al_conn_qp_t*)p_cm->h_qp)->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( p_cm->h_al, &((al_conn_qp_t*)p_cm->h_qp)->cid, TRUE );\r
 \r
        ((al_conn_qp_t*)p_cm->h_qp)->pfn_cm_drep_cb( &drep_rec );\r
 \r
@@ -1041,7 +1037,7 @@ __cep_conn_req(
        p_qp = (al_conn_qp_t*)p_cm_req->h_qp;\r
 \r
        /* Get a CEP and bind it to the QP. */\r
-       status = al_create_cep( h_al, __cm_handler, p_qp, &p_qp->cid );\r
+       status = al_create_cep( h_al, __cm_handler, p_qp, deref_al_obj, &p_qp->cid );\r
        if( status != IB_SUCCESS )\r
        {\r
                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
@@ -1076,7 +1072,7 @@ __cep_conn_req(
                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("al_cep_send_req returned %s.\n", ib_get_err_str(status)) );\r
 err:\r
-               al_destroy_cep( h_al, &p_qp->cid, TRUE, deref_al_obj );\r
+               al_destroy_cep( h_al, &p_qp->cid, TRUE );\r
        }\r
 \r
        /* wait on event if synchronous operation */\r
@@ -1277,7 +1273,7 @@ __cep_conn_rep(
        AL_ENTER( AL_DBG_CM );\r
 \r
        status = al_cep_pre_rep(\r
-               h_cm.h_al, h_cm.cid, p_cm_rep->h_qp, p_cm_rep,\r
+               h_cm.h_al, h_cm.cid, p_cm_rep->h_qp, deref_al_obj, p_cm_rep,\r
                &((al_conn_qp_t*)p_cm_rep->h_qp)->cid, &qp_mod );\r
        switch( status )\r
        {\r
@@ -1291,7 +1287,7 @@ __cep_conn_rep(
 \r
        default:\r
                al_cep_rej( h_cm.h_al, h_cm.cid, IB_REJ_INSUF_RESOURCES, NULL, 0, NULL, 0 );\r
-               al_destroy_cep( h_cm.h_al, &h_cm.cid, FALSE, NULL );\r
+               al_destroy_cep( h_cm.h_al, &h_cm.cid, FALSE );\r
 \r
                AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("al_cep_pre_rep returned %s.\n", ib_get_err_str( status )) );\r
@@ -1327,7 +1323,7 @@ err:
                /* Reject and abort the connection. */\r
                al_cep_rej( h_cm.h_al, h_cm.cid, IB_REJ_INSUF_QP, NULL, 0, NULL, 0 );\r
                al_destroy_cep(\r
-                       h_cm.h_al, &((al_conn_qp_t*)p_cm_rep->h_qp)->cid, TRUE, deref_al_obj );\r
+                       h_cm.h_al, &((al_conn_qp_t*)p_cm_rep->h_qp)->cid, TRUE );\r
        }\r
 \r
        AL_EXIT( AL_DBG_CM );\r
@@ -1391,7 +1387,7 @@ ib_cm_rep(
                cid = h_cm_req.cid;\r
                al_cep_rej(\r
                        h_cm_req.h_al, h_cm_req.cid, IB_REJ_INSUF_QP, NULL, 0, NULL, 0 );\r
-               al_destroy_cep( h_cm_req.h_al, &cid, FALSE, NULL );\r
+               al_destroy_cep( h_cm_req.h_al, &cid, FALSE );\r
 \r
                AL_EXIT( AL_DBG_CM );\r
                return status;\r
@@ -1460,7 +1456,7 @@ err:
                __cep_timewait_qp( h_cm_rep.h_qp );\r
 \r
                al_destroy_cep(\r
-                       h_cm_rep.h_al, &((al_conn_qp_t*)h_cm_rep.h_qp)->cid, TRUE, deref_al_obj );\r
+                       h_cm_rep.h_al, &((al_conn_qp_t*)h_cm_rep.h_qp)->cid, TRUE );\r
 \r
                AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("al_cep_rtu returned %s.\n", ib_get_err_str( status )) );\r
@@ -1524,12 +1520,12 @@ ib_cm_rej(
                __cep_timewait_qp( h_cm.h_qp );\r
 \r
                al_destroy_cep(\r
-                       h_cm.h_al, &((al_conn_qp_t*)h_cm.h_qp)->cid, TRUE, deref_al_obj );\r
+                       h_cm.h_al, &((al_conn_qp_t*)h_cm.h_qp)->cid, TRUE );\r
        }\r
        else\r
        {\r
                cid = h_cm.cid;\r
-               al_destroy_cep( h_cm.h_al, &cid, FALSE, NULL );\r
+               al_destroy_cep( h_cm.h_al, &cid, FALSE );\r
        }\r
 \r
        AL_EXIT( AL_DBG_CM );\r
@@ -1600,7 +1596,7 @@ ib_cm_dreq(
                __cep_timewait_qp( p_cm_dreq->h_qp );\r
 \r
                al_destroy_cep( p_cm_dreq->h_qp->obj.h_al,\r
-                       &((al_conn_qp_t*)p_cm_dreq->h_qp)->cid, TRUE, deref_al_obj );\r
+                       &((al_conn_qp_t*)p_cm_dreq->h_qp)->cid, TRUE );\r
                status = IB_SUCCESS;\r
        }\r
 \r
@@ -1646,7 +1642,7 @@ ib_cm_drep(
                __cep_timewait_qp( h_cm_dreq.h_qp );\r
 \r
                al_destroy_cep( h_cm_dreq.h_al,\r
-                       &((al_conn_qp_t*)h_cm_dreq.h_qp)->cid, TRUE, deref_al_obj );\r
+                       &((al_conn_qp_t*)h_cm_dreq.h_qp)->cid, TRUE );\r
        }\r
 \r
        AL_EXIT( AL_DBG_CM );\r
@@ -1797,8 +1793,7 @@ __destroying_listen(
        p_listen = PARENT_STRUCT( p_obj, al_listen_t, obj );\r
 \r
        /* Destroy the listen's CEP. */\r
-       al_destroy_cep(\r
-               p_obj->h_al, &p_listen->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( p_obj->h_al, &p_listen->cid, TRUE );\r
 }\r
 \r
 \r
@@ -1864,7 +1859,7 @@ __cep_listen(
 \r
        /* Create a CEP to listen on. */\r
     p_listen->cid = AL_INVALID_CID;\r
-       status = al_create_cep( h_al, __cm_handler, p_listen, &p_listen->cid );\r
+       status = al_create_cep( h_al, __cm_handler, p_listen, deref_al_obj, &p_listen->cid );\r
        if( status != IB_SUCCESS )\r
        {\r
                p_listen->obj.pfn_destroy( &p_listen->obj, NULL );\r
index ca787c9..05c99d5 100644 (file)
@@ -1116,7 +1116,7 @@ destroying_qp(
 \r
        case IB_QPT_RELIABLE_CONN:\r
        case IB_QPT_UNRELIABLE_CONN:\r
-               al_destroy_cep( h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, FALSE, deref_al_obj );\r
+               al_destroy_cep( h_qp->obj.h_al, &((al_conn_qp_t*)h_qp)->cid, FALSE );\r
 #ifdef CL_KERNEL\r
                ndi_qp_destroy( h_qp );\r
 #endif\r
index 91d79a6..6962bd7 100644 (file)
@@ -4060,6 +4060,7 @@ al_create_cep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN      OUT                     net32_t* const                          p_cid )\r
 {\r
        kcep_t                          *p_cep;\r
@@ -4085,6 +4086,7 @@ al_create_cep(
 \r
        __bind_cep( p_cep, h_al, pfn_cb, context );\r
 \r
+       p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
        *p_cid = p_cep->cid;\r
 \r
        KeReleaseInStackQueuedSpinLock( &hdl );\r
@@ -4102,13 +4104,13 @@ void
 al_destroy_cep(\r
        IN                              ib_al_handle_t                          h_al,\r
        IN      OUT                     net32_t* const                          p_cid,\r
-       IN                              boolean_t                                       reusable,\r
-       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb )\r
+       IN                              boolean_t                                       reusable )\r
 {\r
     net32_t             cid = *p_cid;\r
        kcep_t                          *p_cep;\r
        KLOCK_QUEUE_HANDLE      hdl;\r
        void                            *context;\r
+    ib_pfn_destroy_cb_t pfn_destroy_cb;\r
        int32_t                         ref_cnt;\r
 \r
        AL_ENTER( AL_DBG_CM );\r
@@ -4133,8 +4135,7 @@ al_destroy_cep(
        }\r
 \r
        context = p_cep->context;\r
-\r
-       p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
+       pfn_destroy_cb = p_cep->pfn_destroy_cb;\r
 \r
        /* Cancel any queued IRP */\r
        __cep_complete_irp( p_cep, STATUS_CANCELLED, IO_NO_INCREMENT );\r
@@ -4994,6 +4995,7 @@ al_cep_pre_rep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              net32_t                                         cid,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN              const   ib_cm_rep_t* const                      p_cm_rep,\r
        IN      OUT                     net32_t* const                          p_cid,\r
                OUT                     ib_qp_mod_t* const                      p_init )\r
@@ -5028,6 +5030,7 @@ al_cep_pre_rep(
 \r
        if( status == IB_SUCCESS )\r
        {\r
+               p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
                *p_cid = cid;\r
        }\r
 \r
@@ -5043,6 +5046,7 @@ al_cep_pre_rep_ex(
        IN                              net32_t                                         cid,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN              const   ib_cm_rep_t* const                      p_cm_rep,\r
        IN      OUT                     net32_t* const                          p_cid,\r
                OUT                     ib_qp_mod_t* const                      p_init )\r
@@ -5078,6 +5082,7 @@ al_cep_pre_rep_ex(
        if( status == IB_SUCCESS )\r
        {\r
                p_cep->pfn_cb = pfn_cb;\r
+               p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
                *p_cid = cid;\r
        }\r
 \r
@@ -6305,7 +6310,7 @@ al_cep_cleanup_al(
                 */\r
                cid = PARENT_STRUCT( p_item, kcep_t, al_item )->cid;\r
                cl_spinlock_release( &h_al->obj.lock );\r
-               al_destroy_cep( h_al, &cid, FALSE, NULL );\r
+               al_destroy_cep( h_al, &cid, FALSE );\r
                cl_spinlock_acquire( &h_al->obj.lock );\r
        }\r
        cl_spinlock_release( &h_al->obj.lock );\r
index 885ead6..1c7ab56 100644 (file)
@@ -414,7 +414,7 @@ ib_open_al(
 \r
        /* Initialize the base object. */\r
        status = init_al_obj( &h_al->obj, NULL, FALSE,\r
-               destroying_al, cleanup_al, free_al );\r
+               destroying_al, NULL, free_al );\r
        if( status != IB_SUCCESS )\r
        {\r
                free_al( &h_al->obj );\r
index 1378e7a..1bf25a5 100644 (file)
@@ -416,6 +416,7 @@ static VOID __ndi_complete_cancelled_irp(
        ndi_qp_csq_t *p_ndi_csq = (ndi_qp_csq_t*)Csq;\r
        ib_qp_handle_t h_qp = p_ndi_csq->h_qp;\r
        KIRQL irql;\r
+       ib_query_handle_t h_query;\r
 \r
        AL_ENTER( AL_DBG_NDI );\r
 \r
@@ -423,29 +424,21 @@ static VOID __ndi_complete_cancelled_irp(
        {\r
        case UAL_NDI_REQ_CM:\r
                __ndi_acquire_lock( Csq, &irql );\r
-               if( p_ndi_csq->state != NDI_CM_INVALID )\r
-               {\r
-                       switch( p_ndi_csq->state )\r
-                       {\r
-                       case NDI_CM_CONNECTING_ATS_SENT:\r
-                       case NDI_CM_CONNECTING_QPR_SENT:\r
                                /*\r
-                                * Note that al_cancel_sa_req must be synchronized with any potential\r
-                                * SA callback.\r
+                * Note that al_cancel_sa_req is synchronized with any potential\r
+                * SA callback by the CSQ lock.\r
                                 */\r
-                               al_cancel_sa_req( &h_qp->p_irp_queue->h_query->sa_req );\r
-                               break;\r
+#pragma warning( disable:4305 )\r
+               h_query = InterlockedExchangePointer( &h_qp->p_irp_queue->h_query, NULL );\r
+#pragma warning( default:4305 )\r
+               if( h_query != NULL )\r
+                       al_cancel_sa_req( &h_query->sa_req );\r
 \r
-                       default:\r
-                       CL_ASSERT( p_ndi_csq->state == NDI_CM_CONNECTING_ATS_SENT ||\r
-                               p_ndi_csq->state == NDI_CM_CONNECTING_QPR_SENT ||\r
-                               p_ndi_csq->state == NDI_CM_CONNECTING_REQ_SENT );\r
-                       }\r
-                       p_ndi_csq->state = NDI_CM_IDLE;\r
-               }\r
                /* Always try to destroy the CEP.  The CEP manager handles invalid CIDs. */\r
-               al_destroy_cep(\r
-                       qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+               al_destroy_cep( qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
+\r
+               if( p_ndi_csq->state != NDI_CM_INVALID )\r
+                       p_ndi_csq->state = NDI_CM_IDLE;\r
 \r
                __ndi_release_lock( Csq, irql );\r
 \r
@@ -681,18 +674,9 @@ __ndi_proc_rej(
                                __ndi_complete_irp( h_qp, p_irp, STATUS_CONNECTION_REFUSED );\r
 \r
                        al_destroy_cep(\r
-                               qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+                               qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
                        break;\r
 \r
-        // TODO: REP IRPs never get queued in the CSQ.  Can we delete?\r
-               //case UAL_NDI_REP_CM:\r
-               //      if( h_qp->p_irp_queue->state != NDI_CM_INVALID )\r
-               //              h_qp->p_irp_queue->state = NDI_CM_IDLE;\r
-               //      __ndi_complete_irp( h_qp, p_irp, STATUS_CONNECTION_ABORTED );\r
-               //      al_destroy_cep(\r
-               //              qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
-               //      break;\r
-\r
                case UAL_NDI_DREQ_CM:\r
                        __ndi_queue_drep( p_irp );\r
                        break;\r
@@ -777,8 +761,7 @@ __ndi_do_drep(
        /* Store the timestamp after which the QP exits timewait. */\r
        h_qp->timewait = cl_get_time_stamp() + timewait_us;\r
 \r
-       al_destroy_cep(\r
-               qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
 \r
        /* bring QP to error state */\r
        cl_memclr( &qp_mod, sizeof(qp_mod) );\r
@@ -865,17 +848,18 @@ __ndi_cm_handler(
                                AL_PRINT( TRACE_LEVEL_INFORMATION, AL_DBG_NDI,\r
                                        ("REP timeouted for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
                                        cid, h_al, h_qp, new_cid ) );\r
-                // TODO: REP IRPs don't get queued int he IRP queue, so don't complete some random IRP (like a DREQ)\r
-                               //__ndi_complete_irp_ex( h_qp, STATUS_CONNECTION_ABORTED );\r
                                break;\r
 \r
                        case CM_DREQ_ATTR_ID:\r
+                               AL_PRINT( TRACE_LEVEL_INFORMATION, AL_DBG_NDI,\r
+                                       ("DREQ timeouted for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
+                                       cid, h_al, h_qp, new_cid ) );\r
                                __ndi_proc_drep( h_qp );\r
                                break;\r
 \r
                        default:\r
                                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
-                                       ("Unhandled MAD attr ID %d for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
+                                       ("Unhandled failed MAD attr ID %d for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
                                        p_mad->attr_id, cid, h_al, h_qp, new_cid ) );\r
                                break;\r
                        }\r
@@ -912,12 +896,22 @@ __ndi_cm_handler(
                                break;\r
 \r
                        case CM_DREP_ATTR_ID:\r
+                               AL_PRINT( TRACE_LEVEL_INFORMATION, AL_DBG_NDI,\r
+                                       ("DREP received for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
+                                       cid, h_al, h_qp, new_cid ) );\r
                                __ndi_proc_drep( h_qp );\r
                                break;\r
                \r
+                       case CM_RTU_ATTR_ID:\r
+                               AL_PRINT( TRACE_LEVEL_INFORMATION, AL_DBG_NDI,\r
+                                       ("RTU received for CEP with cid %d, h_al %p, context %p, new_cid %d.\n",\r
+                                       cid, h_al, h_qp, new_cid ) );\r
+                               break;\r
+               \r
                        default:\r
                                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
-                                       ("Invalid CM recv MAD attribute ID %d.\n", p_mad->attr_id) );\r
+                                       ("Unhandled MAD attr ID %d for CEP with cid %d, h_al %p, context %p, new_cid %d .\n", \r
+                                       p_mad->attr_id, cid, h_al, h_qp, new_cid ) );\r
                        }\r
                }\r
 \r
@@ -1002,7 +996,8 @@ __ndi_send_req(
 \r
        /* Get a CEP and bind it to the QP. */\r
        status = al_create_cep(\r
-               qp_get_al( h_qp ), __ndi_cm_handler, h_qp, &((al_conn_qp_t*)h_qp)->cid );\r
+               qp_get_al( h_qp ), __ndi_cm_handler, h_qp, deref_al_obj,\r
+               &((al_conn_qp_t*)h_qp)->cid );\r
        if( status != IB_SUCCESS )\r
        {\r
                h_qp->p_irp_queue->state = NDI_CM_IDLE;\r
@@ -1043,8 +1038,7 @@ __ndi_send_req(
        return STATUS_SUCCESS;\r
 \r
 error:\r
-       al_destroy_cep(\r
-               qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+       al_destroy_cep( qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
        \r
        switch( status )\r
        {\r
@@ -1070,12 +1064,11 @@ static void AL_API
 __ndi_pr_query_cb(\r
                                        ib_query_rec_t                          *p_query_rec )\r
 {\r
-       ib_api_status_t status;\r
        cl_ioctl_handle_t p_irp;\r
        uint8_t pkt_life;\r
        ib_path_rec_t *p_path_rec;\r
        ib_qp_handle_t h_qp = (ib_qp_handle_t)p_query_rec->query_context;\r
-       NTSTATUS nt_status;\r
+       NTSTATUS status;\r
        KIRQL irql;\r
 \r
        AL_ENTER( AL_DBG_NDI );\r
@@ -1090,26 +1083,44 @@ __ndi_pr_query_cb(
                goto exit;\r
        }\r
 \r
-       status = p_query_rec->status;\r
-       if( status != IB_SUCCESS || !p_query_rec->result_cnt )\r
+#pragma warning( disable:4305 )\r
+       InterlockedExchangePointer( &h_qp->p_irp_queue->h_query, NULL );\r
+#pragma warning( default:4305 )\r
+\r
+       if( p_query_rec->status != IB_SUCCESS || p_query_rec->result_cnt == 0 )\r
        {\r
                __ndi_acquire_lock( &h_qp->p_irp_queue->csq, &irql );\r
                if( h_qp->p_irp_queue->state != NDI_CM_INVALID )\r
                        h_qp->p_irp_queue->state = NDI_CM_IDLE;\r
                __ndi_release_lock( &h_qp->p_irp_queue->csq, irql );\r
-               switch( status )\r
+               switch( p_query_rec->status )\r
                {\r
                case IB_TIMEOUT:\r
-                       __ndi_complete_irp( h_qp, p_irp, STATUS_TIMEOUT );\r
+               case IB_CANCELED:\r
+                       status = ib_to_ntstatus( p_query_rec->status );\r
                        break;\r
 \r
-               case IB_CANCELED:\r
-                       __ndi_complete_irp( h_qp, p_irp, STATUS_CANCELLED );\r
+               case IB_REMOTE_ERROR:\r
+                       CL_ASSERT( p_query_rec->p_result_mad );\r
+                       switch( p_query_rec->p_result_mad->p_mad_buf->status )\r
+                       {\r
+                       case IB_MAD_STATUS_BUSY:\r
+                       case IB_SA_MAD_STATUS_NO_RESOURCES:\r
+                               status = STATUS_TIMEOUT;\r
                        break;\r
 \r
                default:\r
-                       __ndi_complete_irp( h_qp, p_irp, STATUS_HOST_UNREACHABLE );\r
+                               status = STATUS_INVALID_PARAMETER_1 +\r
+                                       (p_query_rec->p_result_mad->p_mad_buf->status & 0xFF);\r
+                               break;\r
+                       }\r
+                       break;\r
+\r
+               default:\r
+                       status = STATUS_HOST_UNREACHABLE;\r
+                       break;\r
                }\r
+               __ndi_complete_irp( h_qp, p_irp, status );\r
                goto exit;\r
        }\r
 \r
@@ -1127,16 +1138,16 @@ __ndi_pr_query_cb(
 \r
        p_irp->Tail.Overlay.DriverContext[1] = p_path_rec;\r
 \r
-       nt_status = IoCsqInsertIrpEx(\r
+       status = IoCsqInsertIrpEx(\r
                &h_qp->p_irp_queue->csq,\r
                p_irp,\r
                NULL,\r
                (VOID*)(ULONG_PTR)NDI_CM_CONNECTING_REQ_SENT\r
                );\r
-       if( nt_status != STATUS_SUCCESS )\r
+       if( status != STATUS_SUCCESS )\r
        {\r
                p_irp->Tail.Overlay.DriverContext[1] = NULL;\r
-               __ndi_complete_irp( h_qp, p_irp, nt_status );\r
+               __ndi_complete_irp( h_qp, p_irp, status );\r
        }\r
        else\r
        {\r
@@ -1148,7 +1159,6 @@ __ndi_pr_query_cb(
        }\r
 \r
 exit:\r
-\r
        if( p_query_rec->p_result_mad )\r
                ib_put_mad( p_query_rec->p_result_mad );\r
 \r
@@ -1157,7 +1167,6 @@ exit:
 }\r
 \r
 \r
-\r
 /*\r
  * Send asynchronous query to the SA for a path record.\r
  *\r
@@ -1198,9 +1207,7 @@ __ndi_pr_query(
                p_req->guid, ib_gid_get_guid( &p_req->gids.dest_gid )) );\r
 \r
        ref_al_obj( &h_qp->obj );               /* take path query reference */\r
-\r
        status = ib_query( qp_get_al( h_qp ), &query_req, &h_qp->p_irp_queue->h_query );\r
-\r
        if( status != IB_SUCCESS )\r
        {\r
                h_qp->p_irp_queue->state = NDI_CM_IDLE;\r
@@ -1237,6 +1244,10 @@ __ndi_ats_query_cb(
                goto exit;\r
        }\r
 \r
+#pragma warning( disable:4305 )\r
+       InterlockedExchangePointer( &h_qp->p_irp_queue->h_query, NULL );\r
+#pragma warning( default:4305 )\r
+\r
        if( p_query_rec->status != IB_SUCCESS || !p_query_rec->result_cnt )\r
        {\r
                __ndi_acquire_lock( &h_qp->p_irp_queue->csq, &irql );\r
@@ -1462,8 +1473,7 @@ err:
 \r
                __cep_timewait_qp( h_qp );\r
 \r
-               al_destroy_cep(\r
-                       qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+               al_destroy_cep( qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
 \r
                AL_PRINT( TRACE_LEVEL_INFORMATION, AL_DBG_NDI,\r
                        ("al_cep_rtu returned %s.\n", ib_get_err_str( status )) );\r
@@ -1572,8 +1582,7 @@ err:
                /* transit QP to error state */\r
                __cep_timewait_qp( h_qp );\r
 \r
-               al_destroy_cep(\r
-                       qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE, deref_al_obj );\r
+               al_destroy_cep( qp_get_al( h_qp ), &((al_conn_qp_t*)h_qp)->cid, TRUE );\r
 \r
                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("al_cep_rtu returned %s.\n", ib_get_err_str( status )) );\r
@@ -1663,14 +1672,14 @@ __ndi_send_rep(
 \r
        /* prepare Passive CEP for connection */\r
        status = al_cep_pre_rep_ex(\r
-               qp_get_al( h_qp ), p_rep->cid, __ndi_cm_handler, h_qp, &cm_rep,\r
-               &((al_conn_qp_t*)h_qp)->cid, &qp_mod );\r
+               qp_get_al( h_qp ), p_rep->cid, __ndi_cm_handler, h_qp, deref_al_obj,\r
+               &cm_rep, &((al_conn_qp_t*)h_qp)->cid, &qp_mod );\r
        if( status != IB_SUCCESS )\r
        {\r
                IoFreeWorkItem( p_irp->Tail.Overlay.DriverContext[1] );\r
                p_irp->Tail.Overlay.DriverContext[1] = NULL;\r
                deref_al_obj( &h_qp->obj ); /* Release work item reference. */\r
-               al_destroy_cep( qp_get_al( h_qp ), &p_rep->cid, FALSE, NULL );\r
+               al_destroy_cep( qp_get_al( h_qp ), &p_rep->cid, FALSE );\r
                deref_al_obj( &h_qp->obj ); /* Release CEP reference. */\r
                AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("al_cep_pre_rep_ex returned %s.\n", ib_get_err_str( status )) );\r
index 673e9d9..7691438 100644 (file)
@@ -53,7 +53,7 @@ proxy_create_cep(
                OUT     size_t                                  *p_ret_bytes )\r
 {\r
        al_dev_open_context_t           *p_context;\r
-       void* VOID_PTR64 *                              p_user_context; //TODO use ioctl here\r
+       void*                                           user_context;\r
        ual_create_cep_ioctl_t          *p_ioctl;\r
 \r
        AL_ENTER( AL_DBG_CM );\r
@@ -62,19 +62,19 @@ proxy_create_cep(
        p_ioctl = (ual_create_cep_ioctl_t*)cl_ioctl_out_buf( h_ioctl );\r
 \r
        /* Validate user parameters. */\r
-       if( cl_ioctl_in_size( h_ioctl ) != sizeof(void* VOID_PTR64) ||\r
+       if( cl_ioctl_in_size( h_ioctl ) != sizeof(uint64_t) ||\r
                cl_ioctl_out_size( h_ioctl ) != sizeof(ual_create_cep_ioctl_t) )\r
        {\r
                AL_EXIT( AL_DBG_CM );\r
                return CL_INVALID_PARAMETER;\r
        }\r
 \r
-       p_user_context = cl_ioctl_in_buf( h_ioctl );\r
+       user_context = *(void**)cl_ioctl_in_buf( h_ioctl );\r
 \r
        /* We use IRPs as notification mechanism so the callback is NULL. */\r
        p_ioctl->cid = AL_INVALID_CID;\r
        p_ioctl->status = al_create_cep( p_context->h_al, NULL,\r
-               *p_user_context, &p_ioctl->cid );\r
+               user_context, NULL, &p_ioctl->cid );\r
 \r
        *p_ret_bytes = sizeof(ual_create_cep_ioctl_t);\r
 \r
@@ -124,7 +124,7 @@ proxy_destroy_cep(
        }\r
 \r
        al_destroy_cep( p_context->h_al,\r
-               (net32_t*)cl_ioctl_in_buf( h_ioctl ), TRUE, NULL );\r
+               (net32_t*)cl_ioctl_in_buf( h_ioctl ), TRUE );\r
 \r
        AL_EXIT( AL_DBG_CM );\r
        return CL_SUCCESS;\r
@@ -205,7 +205,7 @@ proxy_cep_pre_req(
                p_ioctl->in.cm_req.p_req_pdata = p_ioctl->in.pdata;\r
 \r
        /* Get the kernel QP handle. */\r
-       h_qp = (ib_qp_handle_t VOID_PTR64)al_hdl_ref(\r
+       h_qp = (ib_qp_handle_t)al_hdl_ref(\r
                p_context->h_al, (uint64_t)p_ioctl->in.cm_req.h_qp, AL_OBJ_TYPE_H_QP );\r
        if( !h_qp )\r
        {\r
@@ -291,7 +291,7 @@ proxy_cep_pre_rep(
                p_ioctl->in.cm_rep.p_rep_pdata = p_ioctl->in.pdata;\r
 \r
        /* Get the kernel QP handle. */\r
-       h_qp = (ib_qp_handle_t VOID_PTR64)al_hdl_ref(\r
+       h_qp = (ib_qp_handle_t)al_hdl_ref(\r
                p_context->h_al, (uint64_t)p_ioctl->in.cm_rep.h_qp, AL_OBJ_TYPE_H_QP );\r
        if( !h_qp )\r
        {\r
@@ -303,7 +303,7 @@ proxy_cep_pre_rep(
 \r
        cid = AL_INVALID_CID;\r
        p_ioctl->out.status = al_cep_pre_rep( p_context->h_al, p_ioctl->in.cid,\r
-               p_ioctl->in.context, &p_ioctl->in.cm_rep, &cid, &p_ioctl->out.init );\r
+               p_ioctl->in.context, NULL, &p_ioctl->in.cm_rep, &cid, &p_ioctl->out.init );\r
 \r
        deref_al_obj( &h_qp->obj );\r
 \r
@@ -551,7 +551,7 @@ proxy_cep_lap(
                p_ioctl->pdata;\r
 \r
        /* Get the kernel QP handle. */\r
-       h_qp = (ib_qp_handle_t VOID_PTR64)al_hdl_ref(\r
+       h_qp = (ib_qp_handle_t)al_hdl_ref(\r
                p_context->h_al, (uint64_t)p_ioctl->cm_lap.h_qp, AL_OBJ_TYPE_H_QP );\r
        if( !h_qp )\r
        {\r
@@ -604,7 +604,7 @@ proxy_cep_pre_apr(
                p_ioctl->in.cm_apr.p_apr_pdata = p_ioctl->in.pdata;\r
 \r
        /* Get the kernel QP handle. */\r
-       h_qp = (ib_qp_handle_t VOID_PTR64)al_hdl_ref(\r
+       h_qp = (ib_qp_handle_t)al_hdl_ref(\r
                p_context->h_al, (uint64_t)p_ioctl->in.cm_apr.h_qp, AL_OBJ_TYPE_H_QP );\r
        if( !h_qp )\r
        {\r
index 2b72dc0..7a93f77 100644 (file)
@@ -458,7 +458,7 @@ __ndi_rej_cm(
                goto exit;\r
        }\r
 \r
-       al_destroy_cep( p_context->h_al, &cid, FALSE, NULL );\r
+       al_destroy_cep( p_context->h_al, &p_rej->cid, FALSE );\r
        h_ioctl->IoStatus.Status = STATUS_SUCCESS;\r
 \r
 exit:\r
index fd4e1ef..dc4cd02 100644 (file)
@@ -221,7 +221,7 @@ al_cep_cleanup_al(
                 */\r
                cid = PARENT_STRUCT( p_item, ucep_t, al_item )->cid;\r
                cl_spinlock_release( &h_al->obj.lock );\r
-               al_destroy_cep( h_al, &cid, FALSE, NULL );\r
+               al_destroy_cep( h_al, &cid, FALSE );\r
                cl_spinlock_acquire( &h_al->obj.lock );\r
        }\r
        cl_spinlock_release( &h_al->obj.lock );\r
@@ -246,6 +246,7 @@ __create_ucep(
        IN                              net32_t                                         cid,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN      OUT                     net32_t* const                          p_cid )\r
 {\r
        ucep_t                                  *p_cep;\r
@@ -331,9 +332,10 @@ __create_ucep(
                if( *p_cid != AL_INVALID_CID )\r
                {\r
                        cl_spinlock_release( &h_al->obj.lock );\r
-                       al_destroy_cep( h_al, &cid, TRUE, NULL );\r
+                       al_destroy_cep( h_al, &cid, TRUE );\r
                        return IB_INVALID_STATE;\r
                }\r
+               p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
                *p_cid = p_cep->cid;\r
        }\r
 \r
@@ -351,13 +353,15 @@ al_create_cep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              al_pfn_cep_cb_t                         pfn_cb,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN      OUT                     net32_t* const                          p_cid )\r
 {\r
        ib_api_status_t         status;\r
 \r
        AL_ENTER( AL_DBG_CM );\r
 \r
-       status = __create_ucep( h_al, AL_INVALID_CID, pfn_cb, context, p_cid );\r
+       status = __create_ucep(\r
+               h_al, AL_INVALID_CID, pfn_cb, context, pfn_destroy_cb, p_cid );\r
 \r
        AL_EXIT( AL_DBG_CM );\r
        return status;\r
@@ -372,8 +376,7 @@ void
 al_destroy_cep(\r
        IN                              ib_al_handle_t                          h_al,\r
        IN      OUT                     net32_t* const                          p_cid,\r
-       IN                              boolean_t                                       reusable,\r
-       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb OPTIONAL )\r
+       IN                              boolean_t                                       reusable )\r
 {\r
        ucep_t          *p_cep;\r
        DWORD           bytes_ret;\r
@@ -415,8 +418,6 @@ invalid:
 \r
        cl_spinlock_release( &gp_cep_mgr->obj.lock );\r
 \r
-       p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
-\r
        /*\r
         * Remove from the AL instance.  Note that once removed, all\r
         * callbacks for an item will stop.\r
@@ -605,6 +606,7 @@ al_cep_pre_rep(
        IN                              ib_al_handle_t                          h_al,\r
        IN                              net32_t                                         cid,\r
        IN                              void*                                           context,\r
+       IN                              ib_pfn_destroy_cb_t                     pfn_destroy_cb,\r
        IN              const   ib_cm_rep_t* const                      p_cm_rep,\r
        IN      OUT                     net32_t* const                          p_cid,\r
                OUT                     ib_qp_mod_t* const                      p_init )\r
@@ -681,6 +683,7 @@ al_cep_pre_rep(
                        cl_spinlock_release( &h_al->obj.lock );\r
                        return IB_INVALID_STATE;\r
                }\r
+               p_cep->pfn_destroy_cb = pfn_destroy_cb;\r
                *p_cid = p_cep->cid;\r
                *p_init = ioctl.out.init;\r
                cl_spinlock_release( &h_al->obj.lock );\r
@@ -1364,7 +1367,7 @@ al_cep_poll(
                {\r
                        /* Need to create a new CEP for user-mode. */\r
                        status = __create_ucep( p_cep->h_al, ioctl.new_cid,\r
-                               p_cep->pfn_cb, NULL, NULL );\r
+                               p_cep->pfn_cb, NULL, NULL, NULL );\r
                        if( status != IB_SUCCESS )\r
                        {\r
                                DeviceIoControl( g_al_device, UAL_DESTROY_CEP,\r