[MTHCA] a cleanup of the FW update path
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 2 Apr 2006 09:38:04 +0000 (09:38 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 2 Apr 2006 09:38:04 +0000 (09:38 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@270 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mthca/kernel/hca_driver.c

index df388be..139f978 100644 (file)
@@ -345,6 +345,9 @@ fw_access_pciconf (
 \r
        PAGED_CODE();\r
 \r
+       if( !p_buffer )\r
+               return STATUS_INVALID_PARAMETER;\r
+\r
        if (p_BusInterface)\r
        {\r
 \r
@@ -439,7 +442,6 @@ typedef struct _mthca_map_space {
        struct list_head list;\r
        PMDL    p_mdl;\r
        PVOID   va;\r
-       PEPROCESS p_pcs;\r
 } mthca_map_space;\r
 \r
 static NTSTATUS\r
@@ -461,7 +463,7 @@ __map_crspace(
        HCA_ENTER( HCA_DBG_PNP );\r
 \r
        // sanity checks\r
-       if ( buf_size < sizeof *p_res ) {\r
+       if ( buf_size < sizeof *p_res || !p_buf ) {\r
                status = STATUS_INVALID_PARAMETER;\r
                goto err_invalid_params;\r
        }\r
@@ -485,7 +487,7 @@ __map_crspace(
                if ( ka == NULL) {\r
                        HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_SHIM,\r
                                ("No kernel mapping of CR space.\n") );\r
-                       status = STATUS_UNSUCCESSFUL;\r
+                       status = STATUS_INSUFFICIENT_RESOURCES;\r
                        goto err_map_to_kernel;\r
                }\r
                p_ext->bar[HCA_BAR_TYPE_HCR].virt = ka;\r
@@ -505,12 +507,16 @@ __map_crspace(
        MmBuildMdlForNonPagedPool(p_mdl);\r
        \r
        // map the buffer into user space \r
-       ua = MmMapLockedPagesSpecifyCache( p_mdl, UserMode, MmNonCached, \r
-               NULL, FALSE, NormalPagePriority );\r
-       if (ua == NULL) {\r
-               HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_SHIM, \r
+       __try\r
+       {\r
+               ua = MmMapLockedPagesSpecifyCache( p_mdl, UserMode, MmNonCached,\r
+                       NULL, FALSE, NormalPagePriority );\r
+       }\r
+       __except(EXCEPTION_EXECUTE_HANDLER)\r
+       {\r
+               HCA_PRINT(TRACE_LEVEL_ERROR , HCA_DBG_SHIM,\r
                        ("MmMapLockedPagesSpecifyCache failed.\n") );\r
-               status =  STATUS_UNSUCCESSFUL;\r
+               status = STATUS_INSUFFICIENT_RESOURCES;\r
                goto err_map_to_user;\r
        }\r
        \r
@@ -521,7 +527,6 @@ __map_crspace(
        // resource tracking\r
        p_map->p_mdl = p_mdl;\r
        p_map->va = ua;\r
-       p_map->p_pcs = PsGetCurrentProcess();\r
        list_add_tail(&p_map->list, &p_context->map_list);\r
        \r
        up( &p_context->mutex );\r
@@ -553,12 +558,11 @@ __unmap_crspace(
        unmap_crspace *parm = (unmap_crspace *)p_buf;\r
        mthca_map_space *p_map, *p_tmp;\r
        int found = FALSE;\r
-       PEPROCESS  p_pcs = PsGetCurrentProcess();\r
 \r
        HCA_ENTER( HCA_DBG_PNP );\r
 \r
        // sanity checks\r
-       if ( buf_size < sizeof *parm ) {\r
+       if ( buf_size < sizeof *parm || !p_buf ) {\r
                status = STATUS_INVALID_PARAMETER;\r
                goto err_invalid_params;\r
        }\r
@@ -569,7 +573,7 @@ __unmap_crspace(
        // look for the mapping info\r
        list_for_each_entry_safe(p_map, p_tmp, &p_context->map_list, list, \r
                mthca_map_space, mthca_map_space) {\r
-               if (p_map->va == parm->va && p_map->p_pcs == p_pcs) {\r
+               if (p_map->va == parm->va) {\r
                        found = TRUE;\r
                        break;\r
                }\r
@@ -579,7 +583,7 @@ __unmap_crspace(
                HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_SHIM, \r
                        ("Not found internal info for unmappipng.%p for PID %d.\n" , \r
                        parm->va, (int)(INT_PTR)PsGetCurrentProcessId()));\r
-               status =  STATUS_UNSUCCESSFUL;\r
+               status = STATUS_INVALID_PARAMETER;\r
                goto err_not_found;\r
        }\r
 \r
@@ -638,7 +642,6 @@ fw_access_ctrl(
        PVOID                                           p_data;\r
        ULONG                                           offset;\r
        ULONG POINTER_ALIGNMENT         length;\r
-       ib_ci_op_t                                      *p_ci;\r
        mlnx_hob_t                                      *p_hob;\r
        struct ib_ucontext *                    p_context;\r
 \r
@@ -646,28 +649,23 @@ fw_access_ctrl(
        UNREFERENCED_PARAMETER(num_handles);\r
        UNREFERENCED_PARAMETER(p_umv_buf);\r
 \r
-       status =  STATUS_SUCCESS;\r
+       status = STATUS_INVALID_DEVICE_REQUEST;\r
 \r
-       if( p_umv_buf ) {\r
-               p_context = (struct ib_ucontext *)h_ca;\r
-               p_hob = HOB_FROM_IBDEV( ((struct ib_ucontext*)h_ca)->device );\r
-       }\r
-       else {\r
-               p_context = NULL;\r
-               p_hob = (mlnx_hob_t *)(const void *)h_ca;\r
-       }\r
+       if( !p_umv_buf )\r
+               return IB_UNSUPPORTED;\r
 \r
+       p_context = (struct ib_ucontext *)h_ca;\r
+       p_hob = HOB_FROM_IBDEV( ((struct ib_ucontext*)h_ca)->device );\r
        p_dev_obj = (DEVICE_OBJECT *)EXT_FROM_HOB(p_hob)->cl_ext.p_self_do;\r
-       p_ci =  p_ci_op;\r
 \r
-       if ( !p_ci ||  !p_ci->buf_size )\r
-               return STATUS_INVALID_DEVICE_REQUEST;\r
+       if ( !p_ci_op || !p_ci_op->buf_size )\r
+               return IB_INVALID_PARAMETER;\r
 \r
-       length = p_ci->buf_size;\r
-       offset = p_ci->buf_info;\r
-       p_data = p_ci->p_buf;\r
+       length = p_ci_op->buf_size;\r
+       offset = p_ci_op->buf_info;\r
+       p_data = p_ci_op->p_buf;\r
 \r
-       switch ( p_ci->command )\r
+       switch ( p_ci_op->command )\r
        {\r
        case FW_MAP_CRSPACE:\r
                status = __map_crspace(p_context, p_hob, p_data, length);\r
@@ -703,7 +701,7 @@ fw_access_ctrl(
                        if_ready = 0;\r
                        BusInterface.InterfaceDereference((PVOID)BusInterface.Context);\r
                }\r
-               return status;\r
+               return IB_SUCCESS;\r
 \r
        case FW_OPEN_IF: // open BusInterface\r
                if ( !if_ready )\r
@@ -713,13 +711,16 @@ fw_access_ctrl(
                        if ( NT_SUCCESS( status ) )\r
                        {\r
                                if_ready = 1;\r
-                               status = STATUS_SUCCESS;\r
                        }\r
                }\r
-               return status;\r
+               else\r
+               {\r
+                       status = STATUS_SUCCESS;\r
+               }\r
+               break;\r
 \r
        default:\r
-               status = STATUS_NOT_SUPPORTED;\r
+               status = STATUS_INVALID_DEVICE_REQUEST;\r
        }\r
 \r
        if ( status != STATUS_SUCCESS )\r
@@ -730,9 +731,22 @@ fw_access_ctrl(
                        BusInterface.InterfaceDereference((PVOID)BusInterface.Context);\r
                }\r
                HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_INIT, \r
-                       ("fw_access_ctrl failed returns %08x.\n", status));\r
+                       ("fw_access_ctrl failed, ntstatus: %08x.\n", status));\r
+       }\r
+       switch( status )\r
+       {\r
+       case STATUS_SUCCESS:\r
+               return IB_SUCCESS;\r
+\r
+       case STATUS_INVALID_DEVICE_REQUEST:\r
+               return IB_UNSUPPORTED;\r
+\r
+       case STATUS_INSUFFICIENT_RESOURCES:\r
+               return IB_INSUFFICIENT_RESOURCES;\r
+\r
+       default:\r
+               return IB_ERROR;\r
        }\r
-       return status;\r
 }\r
 \r
 static NTSTATUS\r