From b503e8f88619125b35bcabd2b3afcf15355a786d Mon Sep 17 00:00:00 2001 From: leonidk Date: Sun, 9 Jul 2006 18:10:46 +0000 Subject: [PATCH] [MTHCA] 1. feature: added support for ReregisterHca test. 2. bugfix: in handling TARGET_DEVICE_REMOVE_COMPLETE notification. 3. cleaning git-svn-id: svn://openib.tc.cornell.edu/gen1@411 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/hw/mthca/kernel/hca_driver.c | 5 +++ trunk/hw/mthca/kernel/hca_driver.h | 2 +- trunk/hw/mthca/kernel/hca_pnp.c | 67 +++++++++++++++++++++++++++++- trunk/hw/mthca/kernel/hca_verbs.c | 4 +- trunk/inc/mthca/mthca_vc.h | 1 + 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/trunk/hw/mthca/kernel/hca_driver.c b/trunk/hw/mthca/kernel/hca_driver.c index bfb991d1..d921de47 100644 --- a/trunk/hw/mthca/kernel/hca_driver.c +++ b/trunk/hw/mthca/kernel/hca_driver.c @@ -77,6 +77,7 @@ UNICODE_STRING g_param_path; */ char mlnx_uvp_lib_name[MAX_LIB_NAME] = {"mthcau"}; +void reregister_hca( hca_dev_ext_t *p_ext ); NTSTATUS @@ -628,6 +629,10 @@ fw_access_ctrl( switch ( p_ci_op->command ) { + case FW_REREGISTER_HCA: + reregister_hca(p_ext); + break; + case FW_MAP_CRSPACE: status = __map_crspace(p_context, p_hob, p_data, length); break; diff --git a/trunk/hw/mthca/kernel/hca_driver.h b/trunk/hw/mthca/kernel/hca_driver.h index 9d65aa0c..ec212508 100644 --- a/trunk/hw/mthca/kernel/hca_driver.h +++ b/trunk/hw/mthca/kernel/hca_driver.h @@ -139,7 +139,7 @@ typedef struct _hca_dev_ext * LOW LEVEL DRIVER' DATA * ------------------------------------------------ */ mlnx_hca_t hca; - atomic_t usecnt; /* the number of working applications*/ + atomic32_t usecnt; /* the number of working applications*/ cl_spinlock_t uctx_lock; // spinlock for the below chain cl_qlist_t uctx_list; // chain of user contexts diff --git a/trunk/hw/mthca/kernel/hca_pnp.c b/trunk/hw/mthca/kernel/hca_pnp.c index ef72c381..e9ce52d1 100644 --- a/trunk/hw/mthca/kernel/hca_pnp.c +++ b/trunk/hw/mthca/kernel/hca_pnp.c @@ -347,7 +347,17 @@ __pnp_notify_target( else if( IsEqualGUID( &pNotify->Event, &GUID_TARGET_DEVICE_REMOVE_COMPLETE ) ) { - __hca_deregister( p_ext ); + if (p_ext->ci_ifc.deregister_ca) { + /* Notify AL that the CA is being removed. */ + p_ext->ci_ifc.deregister_ca( p_ext->hca.guid ); + p_ext->ci_ifc.deregister_ca = NULL; + } + + if ( p_ext->state == HCA_REGISTERED) { + /* Release AL's CI interface. */ + p_ext->ci_ifc.wdm.InterfaceDereference( p_ext->ci_ifc.wdm.Context ); + } + p_ext->state = HCA_STARTED; /* Release AL's file object so that it can unload. */ if( p_ext->p_al_file_obj ) @@ -1630,3 +1640,58 @@ hca_set_power( HCA_EXIT( HCA_DBG_PNP ); return status; } + +static void +__reregister_hca_cb( + IN DEVICE_OBJECT* p_dev_obj, + IN void* context ) +{ +#define SLEEP_TIME 100000 // 100 msec +#define POLL_TRIES 20 // to wait for 2 sec + int i; + NTSTATUS status; + LARGE_INTEGER interval; + hca_dev_ext_t *p_ext = (hca_dev_ext_t*)p_dev_obj->DeviceExtension; + PIO_WORKITEM pPoWorkItem = (PIO_WORKITEM)context; + + HCA_ENTER( HCA_DBG_PO ); + + IoFreeWorkItem( pPoWorkItem ); + + /* wait SLEEP_TIME_USEC usec for application to exit */ + interval.QuadPart = (-10) * SLEEP_TIME; + KeDelayExecutionThread( KernelMode, FALSE, &interval ); + for (i=0; p_ext->usecnt && i < POLL_TRIES; ++i) { + KeDelayExecutionThread( KernelMode, FALSE, &interval ); + } + + if (!p_ext->usecnt) { + /* reregister HCA */ + __hca_deregister( p_ext ); + + if( p_ext->p_al_dev ) { + status = __hca_register( p_dev_obj ); + if( !NT_SUCCESS( status ) ) { + HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, + ("__hca_register returned 0x%08X.\n", status)); + } + } + } + + HCA_EXIT( HCA_DBG_PO ); +} + + +void reregister_hca( hca_dev_ext_t *p_ext ) +{ + DEVICE_OBJECT *p_dev_obj = (DEVICE_OBJECT *)p_ext->cl_ext.p_self_do; + PIO_WORKITEM pPoWorkItem; + + /* Process in a work item - deregister_ca and HcaDeinit block. */ + pPoWorkItem = IoAllocateWorkItem( p_dev_obj ); + if( pPoWorkItem ) + IoQueueWorkItem( pPoWorkItem, __reregister_hca_cb, + DelayedWorkQueue, pPoWorkItem ); + +} + diff --git a/trunk/hw/mthca/kernel/hca_verbs.c b/trunk/hw/mthca/kernel/hca_verbs.c index dfdcb8e3..1b331c25 100644 --- a/trunk/hw/mthca/kernel/hca_verbs.c +++ b/trunk/hw/mthca/kernel/hca_verbs.c @@ -452,7 +452,7 @@ done: // chain user context to the device cl_spinlock_acquire( &ext_p->uctx_lock ); cl_qlist_insert_tail( &ext_p->uctx_list, &p_context->list_item ); - atomic_inc(&ext_p->usecnt); + cl_atomic_inc(&ext_p->usecnt); cl_spinlock_release( &ext_p->uctx_lock ); // return the result @@ -487,7 +487,7 @@ mlnx_um_close( done: cl_spinlock_acquire( &ext_p->uctx_lock ); cl_qlist_remove_item( &ext_p->uctx_list, &p_ucontext->list_item ); - atomic_dec(&ext_p->usecnt); + cl_atomic_dec(&ext_p->usecnt); cl_spinlock_release( &ext_p->uctx_lock ); if( !p_ucontext->pd ) cl_free( h_um_ca ); diff --git a/trunk/inc/mthca/mthca_vc.h b/trunk/inc/mthca/mthca_vc.h index 35b4a28a..2a4d9d2f 100644 --- a/trunk/inc/mthca/mthca_vc.h +++ b/trunk/inc/mthca/mthca_vc.h @@ -47,6 +47,7 @@ struct _map_crspace { #define FW_WRITE_CMD 0x09 #define FW_MAP_CRSPACE 0x0A #define FW_UNMAP_CRSPACE 0x0B +#define FW_REREGISTER_HCA 0x0c #define FW_OPEN_IF 0xe7 #define FW_CLOSE_IF 0x7e -- 2.41.0