[IBAL] bugfix: QP has to increment the reference on the pool key upon creation and...
[mirror/winof/.git] / core / al / al_qp.c
index fd0c563..9ff407c 100644 (file)
 #include "al.h"\r
 #include "al_av.h"\r
 #include "al_ca.h"\r
-#include "al_cm_shared.h"\r
+#include "al_cm_cep.h"\r
 #include "al_cq.h"\r
 #include "al_debug.h"\r
+#if defined(EVENT_TRACING)\r
+#ifdef offsetof\r
+#undef offsetof\r
+#endif\r
+#include "al_qp.tmh"\r
+#endif\r
 #include "al_mad.h"\r
 #include "al_mad_pool.h"\r
 #include "al_mcast.h"\r
@@ -284,7 +290,7 @@ create_qp(
 \r
        if( !p_qp_create || !ph_qp )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -377,7 +383,7 @@ get_spl_qp(
 \r
        if( !p_qp_create || !ph_qp )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -442,7 +448,14 @@ get_spl_qp(
                        status = ib_reg_mad_pool( gh_mad_pool, h_pd,\r
                                &((al_qp_alias_t*)h_qp)->pool_key );\r
                        if( status == IB_SUCCESS )\r
+                       {\r
+                               /*\r
+                                * Take a reference on the pool key since we don't have a\r
+                                * mechanism for the pool key to clear the QP's pointer to it.\r
+                                */\r
+                               ref_al_obj( &((al_qp_alias_t*)h_qp)->pool_key->obj );\r
                                *p_pool_key = ((al_qp_alias_t*)h_qp)->pool_key;\r
+                       }\r
                }\r
                break;\r
 \r
@@ -583,37 +596,6 @@ al_bad_join_mcast(
 }\r
 \r
 \r
-/*\r
-static ib_api_status_t\r
-al_bad_leave_mcast(\r
-       IN              const   ib_mcast_handle_t                       h_mcast )\r
-{\r
-       UNUSED_PARAM( h_mcast );\r
-       return IB_INVALID_PARAMETER;\r
-}\r
-*/\r
-\r
-\r
-static ib_api_status_t\r
-al_bad_cm_call(\r
-       IN      OUT                     al_conn_t*       const                  p_conn )\r
-{\r
-       UNUSED_PARAM( p_conn );\r
-       return IB_INVALID_PARAMETER;\r
-}\r
-\r
-\r
-static ib_api_status_t\r
-al_bad_cm_pre_rep(\r
-       IN      OUT                     al_conn_t*       const                  p_conn,\r
-       IN      OUT     const   ib_cm_rep_t*                            p_cm_rep )\r
-{\r
-       UNUSED_PARAM( p_conn );\r
-       UNUSED_PARAM( p_cm_rep );\r
-       return IB_INVALID_PARAMETER;\r
-}\r
-\r
-\r
 ib_api_status_t\r
 init_base_qp(\r
        IN                              ib_qp_t* const                          p_qp,\r
@@ -654,6 +636,12 @@ init_base_qp(
        p_qp->pfn_init_dgrm_svc = al_bad_init_dgrm_svc;\r
        p_qp->pfn_join_mcast = al_bad_join_mcast;\r
 \r
+       if( p_qp->type == IB_QPT_RELIABLE_CONN ||\r
+               p_qp->type == IB_QPT_UNRELIABLE_CONN )\r
+       {\r
+               ((al_conn_qp_t*)p_qp)->cid = AL_INVALID_CID;\r
+       }\r
+\r
        return status;\r
 }\r
 \r
@@ -733,11 +721,6 @@ init_raw_qp(
        cq_attach_qp( h_qp->h_recv_cq, &h_qp->recv_cq_rel );\r
        cq_attach_qp( h_qp->h_send_cq, &h_qp->send_cq_rel );\r
 \r
-       /*\r
-        * Get the QP attributes.  This works around a bug with create QP calls\r
-        * above not reporting the correct attributes.\r
-        */\r
-//     ib_query_qp( h_qp, &qp_attr );\r
        h_qp->num = qp_attr.num;\r
 \r
        return IB_SUCCESS;\r
@@ -758,12 +741,9 @@ init_conn_qp(
        /* Initialize the inherited QP first. */\r
        status = init_raw_qp( &p_conn_qp->qp, h_pd, UNBOUND_PORT_GUID,\r
                p_qp_create, p_umv_buf );\r
-       if( status != IB_SUCCESS )\r
-       {\r
-               return status;\r
-       }\r
 \r
-       return IB_SUCCESS;\r
+\r
+       return status;\r
 }\r
 \r
 \r
@@ -1023,18 +1003,18 @@ ib_destroy_qp(
        IN              const   ib_qp_handle_t                          h_qp,\r
        IN              const   ib_pfn_destroy_cb_t                     pfn_destroy_cb OPTIONAL )\r
 {\r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
 \r
        ref_al_obj( &h_qp->obj );\r
        h_qp->obj.pfn_destroy( &h_qp->obj, pfn_destroy_cb );\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        return IB_SUCCESS;\r
 }\r
 \r
@@ -1051,7 +1031,7 @@ destroying_qp(
        ib_qp_handle_t                  h_qp;\r
        al_mad_qp_t                             *p_mad_qp;\r
        al_qp_alias_t                   *p_qp_alias;\r
-       al_conn_qp_t                    *p_conn_qp;\r
+       net32_t                                 cid;\r
 \r
        CL_ASSERT( p_obj );\r
        h_qp = PARENT_STRUCT( p_obj, ib_qp_t, obj );\r
@@ -1090,12 +1070,13 @@ destroying_qp(
                {\r
                        ib_api_status_t         status;\r
                        /* Deregister the pool_key. */\r
-                       ref_al_obj( &p_qp_alias->pool_key->obj );\r
                        status = dereg_mad_pool( p_qp_alias->pool_key, AL_KEY_ALIAS );\r
                        if( status != IB_SUCCESS )\r
                        {\r
-                               AL_TRACE( AL_DBG_ERROR, ("dereg_mad_pool returned %s.\n",\r
+                               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                                       ("dereg_mad_pool returned %s.\n",\r
                                        ib_get_err_str(status)) );\r
+                               /* Release the reference taken when we created the pool key. */\r
                                deref_al_obj( &p_qp_alias->pool_key->obj );\r
                        }\r
                        p_qp_alias->pool_key = NULL;\r
@@ -1119,12 +1100,19 @@ destroying_qp(
 \r
        case IB_QPT_RELIABLE_CONN:\r
        case IB_QPT_UNRELIABLE_CONN:\r
-               p_conn_qp = PARENT_STRUCT( h_qp, al_conn_qp_t, qp);\r
+               cid = cl_atomic_xchg(\r
+                       &((al_conn_qp_t*)h_qp)->cid, AL_INVALID_CID );\r
+               if( cid != AL_INVALID_CID )\r
+               {\r
+                       ref_al_obj( &h_qp->obj );\r
+                       if( al_destroy_cep(\r
+                               h_qp->obj.h_al, cid, deref_al_obj ) != IB_SUCCESS )\r
+                       {\r
+                               deref_al_obj( &h_qp->obj );\r
+                       }\r
+               }\r
 \r
-               /* Disconnect the QP. */\r
-               cm_conn_destroy( p_conn_qp );\r
                /* Fall through. */\r
-\r
        case IB_QPT_UNRELIABLE_DGRM:\r
        default:\r
                /* Multicast membership gets cleaned up by object hierarchy. */\r
@@ -1157,7 +1145,7 @@ cleanup_qp(
                status = verbs_destroy_qp( h_qp );\r
                if( status != IB_SUCCESS )\r
                {\r
-                       CL_TRACE( AL_DBG_ERROR, g_al_dbg_lvl,\r
+                       AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                                ("verbs_destroy_qp failed with status %s.\n",\r
                                ib_get_err_str(status)) );\r
                }\r
@@ -1259,23 +1247,23 @@ query_qp(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_qp_attr )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
        status = verbs_query_qp( h_qp, p_qp_attr );\r
        if( status != IB_SUCCESS )\r
        {\r
-               CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+               AL_EXIT( AL_DBG_QP );\r
                return status;\r
        }\r
 \r
@@ -1285,7 +1273,7 @@ query_qp(
        p_qp_attr->h_sq_cq = h_qp->h_send_cq;\r
        p_qp_attr->qp_type = h_qp->type;\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        return IB_SUCCESS;\r
 }\r
 \r
@@ -1309,22 +1297,22 @@ modify_qp(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_qp_mod )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
        status = h_qp->pfn_modify_qp( h_qp, p_qp_mod, p_umv_buf );\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        return status;\r
 }\r
 \r
@@ -1373,11 +1361,11 @@ ib_init_dgrm_svc(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
 \r
@@ -1393,20 +1381,20 @@ ib_init_dgrm_svc(
        case IB_QPT_MAD:\r
                if( !p_dgrm_info )\r
                {\r
-                       CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
+                       AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                                ("IB_INVALID_PARAMETER\n") );\r
                        return IB_INVALID_PARAMETER;\r
                }\r
                break;\r
 \r
        default:\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
        status = h_qp->pfn_init_dgrm_svc( h_qp, p_dgrm_info );\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        return status;\r
 }\r
 \r
@@ -1530,11 +1518,11 @@ ib_reg_mad_svc(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_MAD_SVC, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_MAD_SVC );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
 \r
@@ -1544,7 +1532,7 @@ ib_reg_mad_svc(
        if( status == IB_SUCCESS )\r
                deref_al_obj( &(*ph_mad_svc)->obj );\r
 \r
-       CL_EXIT( AL_DBG_MAD_SVC, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_MAD_SVC );\r
        return status;\r
 }\r
 \r
@@ -1556,22 +1544,22 @@ ib_join_mcast(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_MCAST, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_MCAST );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_mcast_req )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
        status = h_qp->pfn_join_mcast( h_qp, p_mcast_req );\r
 \r
-       CL_EXIT( AL_DBG_MCAST, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_MCAST );\r
        return status;\r
 }\r
 \r
@@ -1591,16 +1579,16 @@ ib_post_send(
        PERF_DECLARE( PostSend );\r
 \r
        cl_perf_start( IbPostSend );\r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_send_wr || ( p_send_wr->p_next && !pp_send_failure ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -1609,7 +1597,7 @@ ib_post_send(
                h_qp->pfn_post_send( h_qp->h_send_qp, p_send_wr, pp_send_failure );\r
        cl_perf_stop( &g_perf, PostSend );\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        cl_perf_stop( &g_perf, IbPostSend );\r
        return status;\r
 }\r
@@ -1803,23 +1791,23 @@ ib_post_recv(
 {\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_QP );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_recv_wr || ( p_recv_wr->p_next && !pp_recv_failure ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
        status =\r
                h_qp->pfn_post_recv( h_qp->h_recv_qp, p_recv_wr, pp_recv_failure );\r
 \r
-       CL_EXIT( AL_DBG_QP, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_QP );\r
        return status;\r
 }\r
 \r
@@ -2039,6 +2027,26 @@ qp_async_event_cb(
        CL_ASSERT( p_event_rec );\r
        h_qp = (ib_qp_handle_t)p_event_rec->context;\r
 \r
+#if defined(CL_KERNEL)\r
+       switch( p_event_rec->code )\r
+       {\r
+       case IB_AE_QP_COMM:\r
+               al_cep_established( h_qp->obj.h_al, ((al_conn_qp_t*)h_qp)->cid );\r
+               break;\r
+\r
+       case IB_AE_QP_APM:\r
+               al_cep_migrate( h_qp->obj.h_al, ((al_conn_qp_t*)h_qp)->cid );\r
+               break;\r
+\r
+       case IB_AE_QP_APM_ERROR:\r
+               //***TODO: Figure out how to handle these errors.\r
+               break;\r
+\r
+       default:\r
+               break;\r
+       }\r
+#endif\r
+\r
        p_event_rec->context = (void*)h_qp->obj.context;\r
        p_event_rec->handle.h_qp = h_qp;\r
 \r
@@ -2058,21 +2066,21 @@ ib_bind_mw(
        ib_mr_handle_t                  h_mr;\r
        ib_api_status_t                 status;\r
 \r
-       CL_ENTER( AL_DBG_MW, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_MW );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_mw, AL_OBJ_TYPE_H_MW ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_MW_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_MW_HANDLE\n") );\r
                return IB_INVALID_MW_HANDLE;\r
        }\r
        if( AL_OBJ_INVALID_HANDLE( h_qp, AL_OBJ_TYPE_H_QP ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_QP_HANDLE\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_QP_HANDLE\n") );\r
                return IB_INVALID_QP_HANDLE;\r
        }\r
        if( !p_mw_bind || !p_rkey )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -2084,16 +2092,6 @@ ib_bind_mw(
 \r
        p_mw_bind->h_mr = h_mr;\r
 \r
-       CL_EXIT( AL_DBG_MW, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_MW );\r
        return status;\r
 }\r
-\r
-\r
-ib_al_handle_t\r
-qp_get_al(\r
-       IN              const   ib_qp_handle_t                          h_qp )\r
-{\r
-       /* AL the is great-grandparent of the QP. */\r
-       return (ib_al_handle_t)\r
-               h_qp->obj.p_parent_obj->p_parent_obj->p_parent_obj;\r
-}\r