[MTHCA] added support for burning (for flint et al)
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 30 Mar 2006 19:51:23 +0000 (19:51 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Thu, 30 Mar 2006 19:51:23 +0000 (19:51 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@265 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mthca/kernel/SOURCES
hw/mthca/kernel/hca_data.h
hw/mthca/kernel/hca_driver.c
hw/mthca/kernel/hca_verbs.c
hw/mthca/kernel/ib_verbs.h
inc/mthca/mthca_vc.h [new file with mode: 0644]
tools/mtcr/user/SOURCES
tools/mtcr/user/mtcr.c

index 66f4f52..22452cf 100644 (file)
@@ -59,8 +59,9 @@ SOURCES= \
 INCLUDES=\\r
        ..; \\r
        $(TRUNK)\inc;   \\r
-       $(TRUNK)\inc\kernel; \\r
        $(TRUNK)\inc\complib; \\r
+       $(TRUNK)\inc\mthca; \\r
+       $(TRUNK)\inc\kernel; \\r
        $(TRUNK)\inc\kernel\complib; \\r
        \r
 C_DEFINES=$(C_DEFINES) -DDRIVER -DDEPRECATE_DDK_FUNCTIONS -D__LITTLE_ENDIAN\r
index ca0ba9e..5af2524 100644 (file)
@@ -336,6 +336,7 @@ fw_access_ctrl(
        IN                              ib_ci_op_t* const                       p_ci_op,\r
        IN      OUT                     ci_umv_buf_t                            *p_umv_buf              OPTIONAL);\r
 \r
+void unmap_crspace_for_all( struct ib_ucontext *p_context );\r
 \r
 void cq_comp_handler(struct ib_cq *cq, void *context);\r
 \r
index 13e6239..49db4bc 100644 (file)
@@ -51,6 +51,7 @@
 //#include "MdCard.h"\r
 #pragma warning( pop )\r
 #include <iba/ib_ci_ifc.h>\r
+#include "mthca_vc.h"\r
 \r
 /* from \inc\platform\evntrace.h\r
 #define TRACE_LEVEL_NONE        0   // Tracing is not on\r
@@ -434,6 +435,194 @@ End:
        return status;\r
 }\r
 \r
+typedef struct _mthca_map_space {\r
+       struct list_head list;\r
+       PMDL    p_mdl;\r
+       PVOID   va;\r
+       PEPROCESS p_pcs;\r
+} mthca_map_space;\r
+\r
+static NTSTATUS\r
+__map_crspace(\r
+       IN                              struct ib_ucontext *                    p_context,\r
+       IN                              mlnx_hob_t                      *       p_hob,\r
+       IN                              PVOID                                           p_buf,\r
+       IN                              ULONG                                           buf_size\r
+       )\r
+{\r
+       NTSTATUS status;\r
+       PMDL p_mdl;\r
+       PVOID ua, ka;\r
+       ULONG sz;\r
+       mthca_map_space *p_map;\r
+       hca_dev_ext_t *p_ext = EXT_FROM_HOB(p_hob);\r
+       map_crspace *p_res = (map_crspace *)p_buf;\r
+\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+       // sanity checks\r
+       if ( buf_size < sizeof *p_res ) {\r
+               status = STATUS_INVALID_PARAMETER;\r
+               goto err_invalid_params;\r
+       }\r
+\r
+       // allocate a structure\r
+       p_map = (mthca_map_space *)kmalloc(sizeof *p_map, GFP_KERNEL);\r
+       if (p_map == NULL) {\r
+               status = STATUS_INSUFFICIENT_RESOURCES;\r
+               goto err_no_memory;\r
+       }\r
+\r
+       // support several sim clients \r
+       down( &p_context->mutex );\r
+       \r
+       // map memory\r
+       sz =(ULONG)p_ext->bar[HCA_BAR_TYPE_HCR].size;\r
+       if (!p_ext->bar[HCA_BAR_TYPE_HCR].virt) {\r
+               PHYSICAL_ADDRESS pa;\r
+               pa.QuadPart = p_ext->bar[HCA_BAR_TYPE_HCR].phys;\r
+               ka = MmMapIoSpace( pa, sz, MmNonCached ); \r
+               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
+                       goto err_map_to_kernel;\r
+               }\r
+               p_ext->bar[HCA_BAR_TYPE_HCR].virt = ka;\r
+       }\r
+       ka = p_ext->bar[HCA_BAR_TYPE_HCR].virt;\r
+\r
+       // prepare for mapping to user space \r
+       p_mdl = IoAllocateMdl( ka, sz, FALSE,FALSE,NULL);\r
+       if (p_mdl == NULL) {\r
+               HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_SHIM, \r
+                       ("IoAllocateMdl failed.\n") );\r
+               status = STATUS_INSUFFICIENT_RESOURCES;\r
+               goto err_alloc_mdl;\r
+       }\r
+\r
+       // fill MDL\r
+       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
+                       ("MmMapLockedPagesSpecifyCache failed.\n") );\r
+               status =  STATUS_UNSUCCESSFUL;\r
+               goto err_map_to_user;\r
+       }\r
+       \r
+       // fill the results\r
+       p_res->va = ua;\r
+       p_res->size = sz;\r
+\r
+       // 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
+       status = STATUS_SUCCESS;\r
+       goto out;\r
+\r
+err_map_to_user:\r
+       IoFreeMdl( p_mdl );\r
+err_alloc_mdl:\r
+err_map_to_kernel:\r
+       up( &p_context->mutex );\r
+       kfree( p_map );\r
+err_no_memory:\r
+err_invalid_params:    \r
+out:   \r
+       HCA_EXIT( HCA_DBG_PNP );\r
+       return status;\r
+}\r
+\r
+\r
+static NTSTATUS\r
+__unmap_crspace(\r
+       IN                              struct ib_ucontext *                    p_context,\r
+       IN                              PVOID                                           p_buf,\r
+       IN                              ULONG                                           buf_size\r
+       )\r
+{\r
+       NTSTATUS status;\r
+       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
+               status = STATUS_INVALID_PARAMETER;\r
+               goto err_invalid_params;\r
+       }\r
+\r
+       // support several sim clients \r
+       down( &p_context->mutex );\r
+\r
+       // 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
+                       found = TRUE;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       if (!found) {\r
+               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
+               goto err_not_found;\r
+       }\r
+\r
+       // release the resources\r
+       list_del( &p_map->list );\r
+       MmUnmapLockedPages(p_map->va, p_map->p_mdl);\r
+       IoFreeMdl( p_map->p_mdl );\r
+       kfree( p_map );\r
+\r
+       up( &p_context->mutex );\r
+       status = STATUS_SUCCESS;\r
+       goto out;\r
+\r
+err_not_found:\r
+       up( &p_context->mutex );\r
+err_invalid_params:    \r
+out:   \r
+       HCA_EXIT( HCA_DBG_PNP );\r
+       return status;\r
+}\r
+\r
+void\r
+unmap_crspace_for_all( struct ib_ucontext *p_context )\r
+{\r
+       mthca_map_space *p_map, *p_tmp;\r
+\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+       down( &p_context->mutex );\r
+\r
+       list_for_each_entry_safe(p_map, p_tmp, &p_context->map_list, list, \r
+               mthca_map_space, mthca_map_space) {\r
+               list_del( &p_map->list );\r
+               MmUnmapLockedPages(p_map->va, p_map->p_mdl);\r
+               IoFreeMdl( p_map->p_mdl );\r
+               kfree( p_map );\r
+       }\r
+\r
+       up( &p_context->mutex );\r
+\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+}\r
+\r
 ib_api_status_t\r
 fw_access_ctrl(\r
        IN              const   ib_ca_handle_t                          h_ca,\r
@@ -451,6 +640,7 @@ fw_access_ctrl(
        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
        UNREFERENCED_PARAMETER(handle_array);\r
        UNREFERENCED_PARAMETER(num_handles);\r
@@ -458,17 +648,19 @@ fw_access_ctrl(
 \r
        status =  STATUS_SUCCESS;\r
 \r
-       if( p_umv_buf )\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
-       else\r
+       }\r
+       else {\r
+               p_context = NULL;\r
                p_hob = (mlnx_hob_t *)(const void *)h_ca;\r
+       }\r
 \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 )\r
-               return STATUS_INVALID_DEVICE_REQUEST;\r
-       if ( !p_ci->buf_size )\r
+       if ( !p_ci ||  !p_ci->buf_size )\r
                return STATUS_INVALID_DEVICE_REQUEST;\r
 \r
        length = p_ci->buf_size;\r
@@ -477,6 +669,14 @@ fw_access_ctrl(
 \r
        switch ( p_ci->command )\r
        {\r
+       case FW_MAP_CRSPACE:\r
+               status = __map_crspace(p_context, p_hob, p_data, length);\r
+               break;\r
+               \r
+       case FW_UNMAP_CRSPACE:\r
+               status = __unmap_crspace(p_context, p_data, length);\r
+               break;\r
+                               \r
        case FW_READ: // read data from flash\r
                if ( if_ready )\r
                        status = fw_flash_read_data(&BusInterface, p_data, offset, length);\r
index ed458f8..58dca78 100644 (file)
@@ -44,7 +44,6 @@
 \r
 #define PTR_ALIGN(size)        (((size) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))\r
 \r
-\r
 /* Matches definition in IbAccess for MaxSMPsWatermark */\r
 uint32_t       g_sqp_max_avs = ((4096/sizeof(ib_mad_t))*32*5);\r
 \r
@@ -423,6 +422,10 @@ mlnx_um_open(
        uresp_p->dev_id = (uint16_t)ext_p->hcaConfig.DeviceID;\r
 \r
 done:\r
+       // some more inits\r
+       INIT_LIST_HEAD(&context_p->map_list);\r
+       KeInitializeMutex( &context_p->mutex, 0 );\r
+       \r
        // return the result\r
        if (ph_um_ca) *ph_um_ca = (ib_ca_handle_t)context_p;\r
 \r
@@ -445,12 +448,14 @@ mlnx_um_close(
        IN                              ib_ca_handle_t                          h_ca,\r
        IN                              ib_ca_handle_t                          h_um_ca )\r
 {\r
+       struct ib_ucontext *p_ucontext = (struct ib_ucontext *)h_um_ca;\r
        UNREFERENCED_PARAMETER(h_ca);\r
 \r
-       if( !((struct ib_ucontext*)h_um_ca)->pd )\r
+       unmap_crspace_for_all(p_ucontext);\r
+       if( !p_ucontext->pd )\r
                cl_free( h_um_ca );\r
        else\r
-               ibv_um_close((struct ib_ucontext *)h_um_ca);\r
+               ibv_um_close(p_ucontext);\r
        return;\r
 }\r
 \r
index 58e73aa..3f2fdd7 100644 (file)
@@ -531,6 +531,9 @@ struct ib_ucontext {
        struct ib_pd *pd;
        atomic_t                usecnt; /* count all resources */
        ULONG           is_removing;
+       // for CR space mapping
+       KMUTEX  mutex;
+       struct list_head map_list;
 };
 
 struct ib_uobject {
diff --git a/inc/mthca/mthca_vc.h b/inc/mthca/mthca_vc.h
new file mode 100644 (file)
index 0000000..45c001e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.
+ * Copyright (c) 2004-2005 Mellanox Technologies, Inc. All rights reserved. 
+ *
+ * This software is available to you under the OpenIB.org BSD license
+ * below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * $Id: hca_verbs.c 148 2005-07-12 07:48:46Z sleybo $
+ */
+
+#ifndef MTHCA_VC_H
+#define MTHCA_VC_H
+
+typedef
+struct _map_crspace {
+       void *          va;             /* address of CRSPACE, mapped to user space */
+       unsigned long           size;   /* size of CRSPACE, mapped to user space */
+} map_crspace;
+
+typedef
+struct _unmap_crspace {
+       void *          va;             /* address of CRSPACE, mapped to user space */
+} unmap_crspace;
+
+
+/* Definitions for hca_driver commands*/
+#define FW_READ                        0x00
+#define FW_WRITE               0x01
+#define FW_READ_CMD            0x08
+#define FW_WRITE_CMD           0x09
+#define FW_MAP_CRSPACE         0x0A
+#define FW_UNMAP_CRSPACE       0x0B
+#define FW_OPEN_IF             0xe7
+#define FW_CLOSE_IF            0x7e
+
+#endif
index d0111cf..1a2e6e5 100644 (file)
@@ -23,6 +23,7 @@ TARGETPATH=$(WINIBHOME)\bin\user\obj$(BUILD_ALT_DIR)
 INCLUDES= $(WINIBHOME)\inc;                    \\r
           $(WINIBHOME)\inc\user;               \\r
          $(WINIBHOME)\inc\iba;                \\r
+         $(WINIBHOME)\inc\mthca;                \\r
          .\usb;\r
          \r
 \r
index 1105e0c..d01463f 100644 (file)
@@ -10,6 +10,7 @@
 #include "usb.h"\r
 #include "mtcr.h"\r
 #include "mtcr_i2c.h"\r
+#include "mthca_vc.h"\r
 \r
 //-----------------------------------------------------\r
 // NEW FEATURES\r
@@ -31,37 +32,6 @@ ULONG g_DebugLevel = DEBUG_LEVEL_LOW;
 \r
 //-----------------------------------------------------\r
 \r
-\r
-\r
-\r
-// Copied from : #include <ib_al.h>\r
-/* Definitions intended to become shared with UM. Later... */\r
-\r
-typedef\r
-struct _map_crspace {\r
-       PVOID           va;             /* address of CRSPACE, mapped to user space */\r
-       PVOID           ctx;            /* opaque operation context; to be used in FW_UNMAP_CRSPACE */\r
-       ULONG           size;   /* size of CRSPACE, mapped to user space */\r
-} map_crspace;\r
-\r
-typedef\r
-struct _unmap_crspace {\r
-       PVOID           va;             /* address of CRSPACE, mapped to user space */\r
-       PVOID           ctx;            /* operation context, received in FW_MAP_CRSPACE */\r
-} unmap_crspace;\r
-\r
-\r
-/* Definitions for hca_driver commands*/\r
-#define FW_READ                        0x00\r
-#define FW_WRITE               0x01\r
-#define FW_READ_CMD            0x08\r
-#define FW_WRITE_CMD           0x09\r
-#define FW_MAP_CRSPACE         0x0A\r
-#define FW_UNMAP_CRSPACE       0x0B\r
-#define FW_OPEN_IF             0xe7\r
-#define FW_CLOSE_IF            0x7e\r
-\r
-\r
 #define MAX_HCA_NUM 16\r
 \r
 \r
@@ -735,7 +705,6 @@ MTCR_API int mclose(mfile *mf)
                 unmap_crspace unmap;\r
                 \r
                 unmap.va  = mfi->cr_map.va;\r
-                unmap.ctx = mfi->cr_map.ctx;\r
                 if (ibal_access(mfi->h_ca, 0x0, &unmap, sizeof(unmap), FW_UNMAP_CRSPACE ) != IB_SUCCESS) {\r
                     DPRINT1(("Unmap crspace failed"));\r
                 }         \r