//#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
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
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
\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
\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
--- /dev/null
+/*
+ * 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
#include "usb.h"\r
#include "mtcr.h"\r
#include "mtcr_i2c.h"\r
+#include "mthca_vc.h"\r
\r
//-----------------------------------------------------\r
// NEW FEATURES\r
\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
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