From: leonidk Date: Sun, 23 Apr 2006 17:47:57 +0000 (+0000) Subject: [MTHCA] 1. get GUID by card query X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=84ff265f6b01f23b094338d07df90d561127618c;p=~shefty%2Frdma-win.git [MTHCA] 1. get GUID by card query 2. added 2 vendor calls: FW_MAP_CRSPACE and FW_UNMAP_CRSPACE git-svn-id: svn://openib.tc.cornell.edu/gen1@321 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- diff --git a/trunk/hw/mt23108/kernel/hca_data.c b/trunk/hw/mt23108/kernel/hca_data.c index 7cc876c4..662f6df7 100644 --- a/trunk/hw/mt23108/kernel/hca_data.c +++ b/trunk/hw/mt23108/kernel/hca_data.c @@ -142,6 +142,28 @@ mlnx_hca_from_guid( return p_hca; } +mlnx_hca_t* +mlnx_hca_from_hh_hndl( + IN HH_hca_hndl_t hh_hndl ) +{ + cl_list_item_t *p_item; + mlnx_hca_t *p_hca = NULL; + + cl_spinlock_acquire( &hob_lock ); + p_item = cl_qlist_head( &mlnx_hca_list ); + while( p_item != cl_qlist_end( &mlnx_hca_list ) ) + { + p_hca = PARENT_STRUCT( p_item, mlnx_hca_t, list_item ); + if( p_hca->hh_hndl == hh_hndl ) + break; + p_item = cl_qlist_next( p_item ); + p_hca = NULL; + } + cl_spinlock_release( &hob_lock ); + return p_hca; +} + + /* void mlnx_names_from_guid( diff --git a/trunk/hw/mt23108/kernel/hca_data.h b/trunk/hw/mt23108/kernel/hca_data.h index 89b2093c..0f4e739a 100644 --- a/trunk/hw/mt23108/kernel/hca_data.h +++ b/trunk/hw/mt23108/kernel/hca_data.h @@ -214,7 +214,6 @@ typedef struct _ib_um_ca /* The next two fields must be grouped together as the are mapped to UM. */ HH_hca_dev_t dev_info; uint8_t ul_hca_res[1]; // Beginning of UL resource buffer. - } mlnx_um_ca_t; typedef struct { @@ -227,7 +226,12 @@ typedef struct { typedef struct { cl_list_item_t list_item; - HH_hca_hndl_t hh_hndl; + HH_hca_hndl_t hh_hndl; + struct _hca_if { + HH_hca_hndl_t hh_hndl; + void * kernel_crspace_addr; + ULONG kernel_crspace_size; + } s; // char *hca_name_p; net64_t guid; const void* __ptr64 p_dev_obj; // hca device object @@ -375,6 +379,10 @@ mlnx_hca_t* mlnx_hca_from_guid( IN ib_net64_t guid ); +mlnx_hca_t* +mlnx_hca_from_hh_hndl( + IN HH_hca_hndl_t hh_hndl ); + /* void mlnx_names_from_guid( diff --git a/trunk/hw/mt23108/kernel/hca_driver.c b/trunk/hw/mt23108/kernel/hca_driver.c index 1bb64efd..bc2de2f1 100644 --- a/trunk/hw/mt23108/kernel/hca_driver.c +++ b/trunk/hw/mt23108/kernel/hca_driver.c @@ -540,8 +540,11 @@ __get_hca_handle( p_io_stack->Parameters.QueryInterface.Version = 1; p_io_stack->Parameters.QueryInterface.Size = 0; p_io_stack->Parameters.QueryInterface.Interface = NULL; - p_io_stack->Parameters.QueryInterface.InterfaceSpecificData = - &p_ext->hca.hh_hndl; + { + void *p = &p_ext->hca.s; + memset( p, 0, sizeof(p_ext->hca.s) ); + p_io_stack->Parameters.QueryInterface.InterfaceSpecificData = p; + } p_io_stack->Parameters.QueryInterface.InterfaceType = &GUID_MD_INTERFACE; p_irp->IoStatus.Status = STATUS_NOT_SUPPORTED; @@ -562,7 +565,8 @@ __get_hca_handle( ("Query interface for HCA handle returned %08x.\n", status) ); return status; } - + p_ext->hca.hh_hndl = p_ext->hca.s.hh_hndl; + HCA_EXIT( HCA_DBG_PNP ); return status; } @@ -913,7 +917,6 @@ hca_start( { NTSTATUS status; hca_dev_ext_t *p_ext; - net64_t ca_guid = 0; HCA_ENTER( HCA_DBG_PNP ); @@ -937,16 +940,27 @@ hca_start( return status; } - /* store HCA PDO */ - p_ext->hca.p_dev_obj = p_ext->cl_ext.p_pdo; - status = fw_flash_get_ca_guid(p_ext->cl_ext.p_pdo, &ca_guid); - if ( !NT_SUCCESS( status ) ) { - HCA_TRACE( HCA_DBG_ERROR, - ("fw_flash_get_ca_guid failed status =%#x.\n", status) ); - return status; + VAPI_hca_cap_t hca_cap; + int rc; + + if (HH_OK != THH_hob_open_hca(p_ext->hca.hh_hndl, NULL, NULL)) { + status = IB_ERROR; + return status; + } + + rc = THH_hob_query(p_ext->hca.hh_hndl, &hca_cap); + if (rc != HH_OK) { + HCA_TRACE( HCA_DBG_ERROR, ("Error on getting guid (%#x).\n", rc) ); + status = IB_ERROR; + return status; + } + p_ext->hca.guid = *(uint64_t *)hca_cap.node_guid; + p_ext->hca.p_dev_obj = p_ext->cl_ext.p_pdo; + + THH_hob_close_hca(p_ext->hca.hh_hndl); } - p_ext->hca.guid = ca_guid; + mlnx_hca_insert( &p_ext->hca ); /* @@ -1291,6 +1305,107 @@ End: return status; } +static NTSTATUS +__map_crspace( + IN mlnx_hob_t * p_hob, + IN PVOID p_buf, + IN ULONG buf_size + ) +{ + NTSTATUS status; + PMDL mdl_p; + mlnx_hca_t *p_hca = mlnx_hca_from_hh_hndl(p_hob->hh_hndl); + PVOID ua, ka; + ULONG sz; + struct _map_crspace *res_p = (struct _map_crspace *)p_buf; + + HCA_ENTER( HCA_DBG_PNP ); + + // sanity checks + if ( buf_size < sizeof *res_p ) { + status = STATUS_INVALID_PARAMETER; + goto out; + } + if (p_hca == NULL) { + status = STATUS_UNSUCCESSFUL; + goto out; + } + ka = p_hca->s.kernel_crspace_addr; + sz = p_hca->s.kernel_crspace_size; + if ( sz == 0 || ka == NULL) { + HCA_TRACE( HCA_DBG_ERROR, ("No kernel mapping of CR space.\n") ); + status = STATUS_UNSUCCESSFUL; + goto out; + } + + // prepare for mapping to user space + mdl_p = IoAllocateMdl( ka, sz, FALSE,FALSE,NULL); + if (mdl_p == NULL) { + HCA_TRACE( HCA_DBG_ERROR, ("IoAllocateMdl failed.\n") ); + status = STATUS_INSUFFICIENT_RESOURCES; + goto out; + } + + // fill MDL + MmBuildMdlForNonPagedPool(mdl_p); + + // map the buffer into user space + ua = MmMapLockedPagesSpecifyCache( mdl_p, UserMode, MmNonCached, + NULL, FALSE, NormalPagePriority ); + if (ua == NULL) { + HCA_TRACE( HCA_DBG_ERROR, ("MmMapLockedPagesSpecifyCache failed.\n") ); + IoFreeMdl( mdl_p ); + status = STATUS_UNSUCCESSFUL; + goto out; + } + + // fill the structure + res_p->va = ua; + res_p->size = sz; + res_p->ctx = mdl_p; + status = STATUS_SUCCESS; + +out: + HCA_EXIT( HCA_DBG_PNP ); + return status; +} + +static NTSTATUS +__unmap_crspace( + IN PVOID p_buf, + IN ULONG buf_size + ) +{ + NTSTATUS status; + PMDL mdl_p; + PVOID ua; + struct _unmap_crspace *parm = (struct _unmap_crspace *)p_buf; + + HCA_ENTER( HCA_DBG_PNP ); + + // sanity checks + if ( buf_size < sizeof *parm ) { + status = STATUS_INVALID_PARAMETER; + goto out; + } + mdl_p = parm->ctx; + ua = parm->va; + if ( mdl_p == NULL || ua == NULL) { + status = STATUS_INVALID_PARAMETER; + goto out; + } + + // do the work + MmUnmapLockedPages(ua, mdl_p); + IoFreeMdl( mdl_p ); + status = STATUS_SUCCESS; + +out: + HCA_EXIT( HCA_DBG_PNP ); + return status; +} + + ib_api_status_t fw_access_ctrl( IN const void* __ptr64 p_context, @@ -1333,6 +1448,14 @@ fw_access_ctrl( switch ( p_ci->command ) { + case FW_MAP_CRSPACE: + status = __map_crspace(p_hob, p_data, length); + break; + + case FW_UNMAP_CRSPACE: + status = __unmap_crspace(p_data, length); + break; + case FW_READ: // read data from flash if ( if_ready ) { diff --git a/trunk/hw/mt23108/kernel/hca_driver.h b/trunk/hw/mt23108/kernel/hca_driver.h index 7b08a5f6..50a56f65 100644 --- a/trunk/hw/mt23108/kernel/hca_driver.h +++ b/trunk/hw/mt23108/kernel/hca_driver.h @@ -129,11 +129,25 @@ Firmware Update definitions #define CPUMODE_MSK (0xc0000000UL) #define CPUMODE_SHIFT (30) +/* buffer structure for FW_MAP_CRBASE */ +struct _map_crspace { + PVOID va; /* address of CRSPACE, mapped to user space */ + PVOID ctx; /* opaque operation context; to be used in FW_UNMAP_CRBASE */ + ULONG size; /* size of CRSPACE, mapped to user space */ +}; + +struct _unmap_crspace { + PVOID va; /* address of CRSPACE, mapped to user space */ + PVOID ctx; /* operation context, received in FW_MAP_CRBASE */ +}; + /* Definitions intended to become shared with UM. Later... */ #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 diff --git a/trunk/hw/mt23108/vapi/mlxsys/mosal/os_dep/win/mosalu_socket.c b/trunk/hw/mt23108/vapi/mlxsys/mosal/os_dep/win/mosalu_socket.c index 87a289bb..d81c1e30 100644 --- a/trunk/hw/mt23108/vapi/mlxsys/mosal/os_dep/win/mosalu_socket.c +++ b/trunk/hw/mt23108/vapi/mlxsys/mosal/os_dep/win/mosalu_socket.c @@ -221,6 +221,9 @@ int MOSAL_socket_recv(int sock,void* buf,int len,int flags) int byte_cnt = recv( (SOCKET)sock, (char FAR *)buf, len, 0 ); if (byte_cnt == SOCKET_ERROR) return -1; + + if (byte_cnt == 0) + return -1; /* socket closed */ else return byte_cnt; } @@ -249,6 +252,9 @@ int MOSAL_socket_sendto (int sock,void *buf, int n,int flags, MOSAL_sockaddr_t* (const struct sockaddr FAR *)adrs, (int)adrs_len ); if (byte_cnt == SOCKET_ERROR) return -1; + + if (byte_cnt == 0) + return -1; /* socket closed */ else return byte_cnt; } diff --git a/trunk/hw/mt23108/vapi/mlxsys/os_dep/win/tdriver/MdPnp.c b/trunk/hw/mt23108/vapi/mlxsys/os_dep/win/tdriver/MdPnp.c index 1c73e036..2dd3c8a9 100644 --- a/trunk/hw/mt23108/vapi/mlxsys/os_dep/win/tdriver/MdPnp.c +++ b/trunk/hw/mt23108/vapi/mlxsys/os_dep/win/tdriver/MdPnp.c @@ -490,11 +490,18 @@ Return Value: { if( l_pIrpStack->Parameters.QueryInterface.InterfaceSpecificData ) { - // Our interface. Return the HH HCA handle in - // the "InterfaceSpecificData" member. - *(HH_hca_hndl_t*)l_pIrpStack->Parameters.QueryInterface. - InterfaceSpecificData = l_pMdDevContext->m_hHhHca; - pi_pIrp->IoStatus.Status = STATUS_SUCCESS; + struct _hca_if { + HH_hca_hndl_t hh_hndl; + void * kernel_crspace_addr; + ULONG kernel_crspace_size; + } *if_p = l_pIrpStack->Parameters.QueryInterface.InterfaceSpecificData; + + // Our interface. Return the HH HCA handle and other data + if_p->hh_hndl = l_pMdDevContext->m_hHhHca; + if_p->kernel_crspace_addr = l_pMdDevContext->m_Cr.m_pKernelAddr; + if_p->kernel_crspace_size = l_pMdDevContext->m_Cr.m_ulKernelSize; + + pi_pIrp->IoStatus.Status = STATUS_SUCCESS; l_Status = STATUS_SUCCESS; break; }