[IBAL] Cleanup syntax of latest destroy FMR changes.
[mirror/winof/.git] / core / al / kernel / al_mr.c
index a4f14d4..16120ec 100644 (file)
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
  * SOFTWARE.\r
  *\r
- * $Id:$\r
+ * $Id$\r
  */\r
 \r
 #include <iba/ib_al.h>\r
 \r
 #include "al_debug.h"\r
+#if defined(EVENT_TRACING)\r
+#ifdef offsetof\r
+#undef offsetof\r
+#endif\r
+#include "al_mr.tmh"\r
+#endif\r
 #include "al_mr.h"\r
 #include "al_pd.h"\r
 #include "al_res_mgr.h"\r
 #include "ib_common.h"\r
 \r
 \r
+static void\r
+__cleanup_mlnx_fmr(\r
+       IN                              struct _al_obj                          *p_obj );\r
+\r
+static void\r
+__return_mlnx_fmr(\r
+       IN                              al_obj_t                                        *p_obj );\r
+\r
+\r
 static al_shmid_t*\r
 __create_shmid(\r
        IN              const   int                                                     shmid );\r
@@ -50,6 +65,264 @@ __free_shmid(
        IN                              struct _al_obj                          *p_obj );\r
 \r
 \r
+cl_status_t\r
+mlnx_fmr_ctor(\r
+       IN                              void* const                                     p_object,\r
+       IN                              void*                                           context,\r
+               OUT                     cl_pool_item_t** const          pp_pool_item )\r
+{\r
+       ib_api_status_t                 status;\r
+       mlnx_fmr_handle_t                       h_fmr;\r
+\r
+       UNUSED_PARAM( context );\r
+\r
+       h_fmr = (mlnx_fmr_handle_t)p_object;\r
+       cl_memclr( h_fmr, sizeof(mlnx_fmr_t) );\r
+\r
+       construct_al_obj( &h_fmr->obj, AL_OBJ_TYPE_H_FMR );\r
+       status = init_al_obj( &h_fmr->obj, NULL, FALSE, NULL,\r
+               __cleanup_mlnx_fmr, __return_mlnx_fmr );\r
+       if( status != IB_SUCCESS )\r
+       {\r
+               return CL_ERROR;\r
+       }\r
+\r
+       *pp_pool_item = &((mlnx_fmr_handle_t)p_object)->obj.pool_item;\r
+\r
+       /* Release the reference taken in init_al_obj. */\r
+       deref_al_obj( &h_fmr->obj );\r
+\r
+       return CL_SUCCESS;\r
+}\r
+\r
+\r
+\r
+void\r
+mlnx_fmr_dtor(\r
+       IN              const   cl_pool_item_t* const           p_pool_item,\r
+       IN                              void*                                           context )\r
+{\r
+       al_obj_t                                *p_obj;\r
+\r
+       UNUSED_PARAM( context );\r
+\r
+       p_obj = PARENT_STRUCT( p_pool_item, al_obj_t, pool_item );\r
+\r
+       /*\r
+        * The FMR is being totally destroyed.  Modify the free_cb to destroy the\r
+        * AL object.\r
+        */\r
+       p_obj->pfn_free = (al_pfn_free_t)destroy_al_obj;\r
+       ref_al_obj( p_obj );\r
+       p_obj->pfn_destroy( p_obj, NULL );\r
+}\r
+\r
+\r
+\r
+static void\r
+__cleanup_mlnx_fmr(\r
+       IN                              struct _al_obj                          *p_obj )\r
+{\r
+       ib_api_status_t                 status;\r
+       mlnx_fmr_handle_t                       h_fmr;\r
+\r
+       CL_ASSERT( p_obj );\r
+       h_fmr = PARENT_STRUCT( p_obj, mlnx_fmr_t, obj );\r
+\r
+       /* Deregister the memory. */\r
+       if( verbs_check_mlnx_fmr( h_fmr ) )\r
+       {\r
+               status = verbs_destroy_mlnx_fmr( h_fmr );\r
+               CL_ASSERT( status == IB_SUCCESS );\r
+\r
+               h_fmr->h_ci_fmr = NULL;\r
+       }\r
+}\r
+\r
+\r
+\r
+static void\r
+__return_mlnx_fmr(\r
+       IN                              al_obj_t                                        *p_obj )\r
+{\r
+       mlnx_fmr_handle_t                       h_fmr;\r
+\r
+       h_fmr = PARENT_STRUCT( p_obj, mlnx_fmr_t, obj );\r
+       reset_al_obj( p_obj );\r
+       put_mlnx_fmr( h_fmr );\r
+}\r
+\r
+\r
+\r
+ib_api_status_t\r
+mlnx_create_fmr(\r
+       IN              const   ib_pd_handle_t                          h_pd,\r
+       IN              const   mlnx_fmr_create_t*      const   p_fmr_create,\r
+       OUT                             mlnx_fmr_handle_t*      const   ph_fmr )\r
+{\r
+       mlnx_fmr_handle_t               h_fmr;\r
+       ib_api_status_t                 status;\r
+\r
+       AL_ENTER( AL_DBG_MR );\r
+\r
+       if( AL_OBJ_INVALID_HANDLE( h_pd, AL_OBJ_TYPE_H_PD ) )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PD_HANDLE\n") );\r
+               return IB_INVALID_PD_HANDLE;\r
+       }\r
+\r
+       if( !p_fmr_create || !ph_fmr )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
+               return IB_INVALID_PARAMETER;\r
+       }\r
+\r
+       /* Get a MR tracking structure. */\r
+       h_fmr = alloc_mlnx_fmr();\r
+       if( !h_fmr )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                       ("unable to allocate memory handle\n") );\r
+               return IB_INSUFFICIENT_MEMORY;\r
+       }\r
+\r
+       status = attach_al_obj( &h_pd->obj, &h_fmr->obj );\r
+       if( status != IB_SUCCESS )\r
+       {\r
+               h_fmr->obj.pfn_destroy( &h_fmr->obj, NULL );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                       ("attach_al_obj returned %s.\n", ib_get_err_str(status)) );\r
+               return status;\r
+       }\r
+\r
+       /* Register the memory region. */\r
+       status = verbs_create_mlnx_fmr( h_pd, p_fmr_create, h_fmr );\r
+       if( status != IB_SUCCESS )\r
+       {\r
+               h_fmr->obj.pfn_destroy( &h_fmr->obj, NULL );\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                       ("unable to register memory: %s\n", ib_get_err_str(status)) );\r
+               return status;\r
+       }\r
+\r
+       *ph_fmr = h_fmr;\r
+       /* Release the reference taken in alloc_mlnx_fmr for initialization. */\r
+       deref_al_obj( &(*ph_fmr )->obj );\r
+\r
+       AL_EXIT( AL_DBG_MR );\r
+       return IB_SUCCESS;\r
+}\r
+\r
+\r
+ib_api_status_t\r
+mlnx_map_phys_fmr(\r
+       IN              const   mlnx_fmr_handle_t                       h_fmr,\r
+       IN              const   uint64_t* const                         paddr_list,\r
+       IN              const   int                                                     list_len,\r
+       IN      OUT                     uint64_t* const                         p_vaddr,\r
+               OUT                     net32_t* const                          p_lkey,\r
+               OUT                     net32_t* const                          p_rkey)\r
+{\r
+       ib_api_status_t                 status;\r
+\r
+       AL_ENTER( AL_DBG_MR );\r
+\r
+       if( AL_OBJ_INVALID_HANDLE( h_fmr, AL_OBJ_TYPE_H_FMR ) )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_FMR_HANDLE\n") );\r
+               return IB_INVALID_FMR_HANDLE;\r
+       }\r
+\r
+       if( !paddr_list || !p_vaddr  || !p_lkey || !p_rkey )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
+               return IB_INVALID_PARAMETER;\r
+       }\r
+\r
+       ref_al_obj( &h_fmr->obj );\r
+\r
+       /* Register the memory region. */\r
+       status = verbs_map_phys_mlnx_fmr( h_fmr, paddr_list, list_len, p_vaddr, p_lkey, p_rkey);\r
+       if( status != IB_SUCCESS )\r
+       {\r
+               //TODO: do we need to do something more about the error ?\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                       ("unable to map FMR: %s\n", ib_get_err_str(status)) );\r
+       }\r
+\r
+       deref_al_obj( &h_fmr->obj );\r
+\r
+       AL_EXIT( AL_DBG_MR );\r
+       return status;\r
+}\r
+\r
+\r
+ib_api_status_t\r
+mlnx_unmap_fmr(\r
+       IN              const   mlnx_fmr_handle_t                               h_fmr )\r
+{\r
+       ib_api_status_t         status;\r
+\r
+       AL_ENTER( AL_DBG_MR );\r
+\r
+       if( AL_OBJ_INVALID_HANDLE( h_fmr, AL_OBJ_TYPE_H_FMR ) )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_FMR_HANDLE\n") );\r
+               return IB_INVALID_FMR_HANDLE;\r
+       }\r
+\r
+       ref_al_obj( &h_fmr->obj );\r
+       status = verbs_unmap_mlnx_fmr( h_fmr );\r
+       deref_al_obj( &h_fmr->obj );\r
+\r
+       AL_EXIT( AL_DBG_MR );\r
+       return status;\r
+}\r
+\r
+\r
+ib_api_status_t\r
+mlnx_destroy_fmr(\r
+       IN              const   mlnx_fmr_handle_t                               h_fmr )\r
+{\r
+       ib_api_status_t         status;\r
+\r
+       AL_ENTER( AL_DBG_MR );\r
+\r
+       if( AL_OBJ_INVALID_HANDLE( h_fmr, AL_OBJ_TYPE_H_FMR ) )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_FMR_HANDLE\n") );\r
+               return IB_INVALID_FMR_HANDLE;\r
+       }\r
+\r
+       if( !verbs_check_mlnx_fmr( h_fmr ) )\r
+       {\r
+               AL_PRINT_EXIT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_FMR_HANDLE\n") );\r
+               return IB_INVALID_FMR_HANDLE;\r
+       }\r
+\r
+       ref_al_obj( &h_fmr->obj );\r
+\r
+       /* FMR's are destroyed synchronously */\r
+       status = verbs_destroy_mlnx_fmr( h_fmr );\r
+\r
+       if( status == IB_SUCCESS )\r
+       {\r
+               h_fmr->h_ci_fmr = NULL;\r
+               /* We're good to destroy the object. \r
+               NOTE: No need to deref the al object , \r
+               we are reseting the fmr objb before inserting it back to the pool */\r
+               \r
+               h_fmr->obj.pfn_destroy( &h_fmr->obj, NULL );\r
+       }\r
+       else\r
+       {\r
+               deref_al_obj( &h_fmr->obj );\r
+       }\r
+       AL_EXIT( AL_DBG_MR );\r
+       return status;\r
+}\r
+\r
+\r
 \r
 ib_api_status_t\r
 ib_create_shmid(\r
@@ -66,16 +339,16 @@ ib_create_shmid(
        net32_t                         rkey;\r
        ib_mr_handle_t          h_mr;\r
 \r
-       CL_ENTER( AL_DBG_MR, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_MR );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_pd, AL_OBJ_TYPE_H_PD ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PD_HANDLE\n") );\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PD_HANDLE\n") );\r
                return IB_INVALID_PD_HANDLE;\r
        }\r
        if( !p_mr_create || !p_lkey || !p_rkey || !ph_mr )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -83,7 +356,7 @@ ib_create_shmid(
        status = ib_reg_mem( h_pd, p_mr_create, &lkey, &rkey, &h_mr );\r
        if( status != IB_SUCCESS )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("unable to register memory: %s\n", ib_get_err_str(status)) );\r
                return status;\r
        }\r
@@ -92,7 +365,7 @@ ib_create_shmid(
        h_mr->p_shmid = __create_shmid( shmid );\r
        if( !h_mr->p_shmid )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("unable to allocate shmid\n") );\r
                ib_dereg_mr( h_mr );\r
                return IB_INSUFFICIENT_MEMORY;\r
@@ -114,7 +387,7 @@ ib_create_shmid(
        *p_lkey = lkey;\r
        *p_rkey = rkey;\r
        *ph_mr = h_mr;\r
-       CL_EXIT( AL_DBG_MR, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_MR );\r
        return IB_SUCCESS;\r
 }\r
 \r
@@ -227,16 +500,16 @@ reg_shmid(
        net32_t                         rkey;\r
        ib_mr_handle_t          h_mr, h_reg_mr;\r
 \r
-       CL_ENTER( AL_DBG_MR, g_al_dbg_lvl );\r
+       AL_ENTER( AL_DBG_MR );\r
 \r
        if( AL_OBJ_INVALID_HANDLE( h_pd, AL_OBJ_TYPE_H_PD ) )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PD_HANDLE\n") );\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PD_HANDLE\n") );\r
                return IB_INVALID_PD_HANDLE;\r
        }\r
        if( !p_vaddr || !p_lkey || !p_rkey || !ph_mr )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("IB_INVALID_PARAMETER\n") );\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("IB_INVALID_PARAMETER\n") );\r
                return IB_INVALID_PARAMETER;\r
        }\r
 \r
@@ -244,7 +517,7 @@ reg_shmid(
        status = acquire_shmid( h_pd->obj.p_ci_ca, shmid, &p_shmid );\r
        if( status != IB_SUCCESS )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("shmid not found: %s\n", ib_get_err_str(status)) );\r
                return IB_NOT_FOUND;\r
        }\r
@@ -259,7 +532,7 @@ reg_shmid(
        if( cl_is_list_empty( &p_shmid->mr_list ) )\r
        {\r
                /* There are no registrations left to share. */\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl, ("shmid not found\n") );\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR, ("shmid not found\n") );\r
                cl_spinlock_release( &p_shmid->obj.lock );\r
                release_shmid( p_shmid );\r
                return IB_NOT_FOUND;\r
@@ -277,8 +550,8 @@ reg_shmid(
                &lkey, &rkey, &h_mr );\r
        if( status != IB_SUCCESS )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
-                       ("unable to register shared memory: 0x%0"PRIx64" %s\n",\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
+                       ("unable to register shared memory: 0x%0I64x %s\n",\r
                                vaddr, ib_get_err_str(status)) );\r
                release_shmid( p_shmid );\r
                return status;\r
@@ -290,7 +563,7 @@ reg_shmid(
        cl_status = cl_list_insert_head( &p_shmid->mr_list, h_mr );\r
        if( cl_status != CL_SUCCESS )\r
        {\r
-               CL_TRACE_EXIT( AL_DBG_ERROR, g_al_dbg_lvl,\r
+               AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
                        ("insertion into shmid list failed\n") );\r
                cl_spinlock_release( &p_shmid->obj.lock );\r
                release_shmid( p_shmid );\r
@@ -305,7 +578,7 @@ reg_shmid(
        *p_lkey = lkey;\r
        *p_rkey = rkey;\r
        *ph_mr = h_mr;\r
-       CL_EXIT( AL_DBG_MR, g_al_dbg_lvl );\r
+       AL_EXIT( AL_DBG_MR );\r
        return IB_SUCCESS;\r
 #endif\r
 }\r