[MTHCA] 1. feature: added support for ReregisterHca test.
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 9 Jul 2006 18:10:46 +0000 (18:10 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 9 Jul 2006 18:10:46 +0000 (18:10 +0000)
2. bugfix: in handling TARGET_DEVICE_REMOVE_COMPLETE notification.
3. cleaning

git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@411 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mthca/kernel/hca_driver.c
hw/mthca/kernel/hca_driver.h
hw/mthca/kernel/hca_pnp.c
hw/mthca/kernel/hca_verbs.c
inc/mthca/mthca_vc.h

index bfb991d..d921de4 100644 (file)
@@ -77,6 +77,7 @@ UNICODE_STRING                                g_param_path;
  */\r
 char                   mlnx_uvp_lib_name[MAX_LIB_NAME] = {"mthcau"};\r
 \r
+void reregister_hca( hca_dev_ext_t *p_ext );\r
 \r
 \r
 NTSTATUS\r
@@ -628,6 +629,10 @@ fw_access_ctrl(
 \r
        switch ( p_ci_op->command )\r
        {\r
+       case FW_REREGISTER_HCA:\r
+               reregister_hca(p_ext);\r
+               break;\r
+               \r
        case FW_MAP_CRSPACE:\r
                status = __map_crspace(p_context, p_hob, p_data, length);\r
                break;\r
index 9d65aa0..ec21250 100644 (file)
@@ -139,7 +139,7 @@ typedef struct _hca_dev_ext
        *               LOW LEVEL DRIVER' DATA   \r
        * ------------------------------------------------ */\r
        mlnx_hca_t                                                      hca;\r
-       atomic_t                                                                usecnt; /* the number of working applications*/\r
+       atomic32_t                                                              usecnt; /* the number of working applications*/\r
        cl_spinlock_t                                                   uctx_lock;                      // spinlock for the below chain\r
        cl_qlist_t                                                              uctx_list;                      // chain of user contexts\r
 \r
index ef72c38..e9ce52d 100644 (file)
@@ -347,7 +347,17 @@ __pnp_notify_target(
        else if( IsEqualGUID( &pNotify->Event, \r
                &GUID_TARGET_DEVICE_REMOVE_COMPLETE ) )\r
        {\r
-               __hca_deregister( p_ext );\r
+               if (p_ext->ci_ifc.deregister_ca) {\r
+                       /* Notify AL that the CA is being removed. */\r
+                       p_ext->ci_ifc.deregister_ca( p_ext->hca.guid );\r
+                       p_ext->ci_ifc.deregister_ca = NULL;\r
+               }\r
+\r
+               if ( p_ext->state == HCA_REGISTERED) {\r
+                       /* Release AL's CI interface. */\r
+                       p_ext->ci_ifc.wdm.InterfaceDereference( p_ext->ci_ifc.wdm.Context );\r
+               }\r
+               p_ext->state = HCA_STARTED;\r
 \r
                /* Release AL's file object so that it can unload. */\r
                if( p_ext->p_al_file_obj )\r
@@ -1630,3 +1640,58 @@ hca_set_power(
        HCA_EXIT( HCA_DBG_PNP );\r
        return status;\r
 }\r
+\r
+static void\r
+__reregister_hca_cb(\r
+       IN                              DEVICE_OBJECT*                          p_dev_obj,\r
+       IN                              void*                                           context )\r
+{\r
+#define SLEEP_TIME             100000  // 100 msec\r
+#define POLL_TRIES             20              // to wait for 2 sec\r
+       int i;\r
+       NTSTATUS                        status;\r
+       LARGE_INTEGER  interval;\r
+       hca_dev_ext_t           *p_ext = (hca_dev_ext_t*)p_dev_obj->DeviceExtension;\r
+       PIO_WORKITEM            pPoWorkItem = (PIO_WORKITEM)context;\r
+\r
+       HCA_ENTER( HCA_DBG_PO );\r
+\r
+       IoFreeWorkItem( pPoWorkItem );\r
+\r
+       /* wait SLEEP_TIME_USEC usec for application to exit */\r
+       interval.QuadPart = (-10) * SLEEP_TIME;\r
+       KeDelayExecutionThread( KernelMode, FALSE, &interval );\r
+       for (i=0; p_ext->usecnt && i < POLL_TRIES; ++i) {\r
+               KeDelayExecutionThread( KernelMode, FALSE, &interval );\r
+       }\r
+\r
+       if (!p_ext->usecnt) {\r
+               /* reregister HCA */\r
+                __hca_deregister( p_ext );\r
+\r
+               if( p_ext->p_al_dev ) {\r
+                       status = __hca_register( p_dev_obj );\r
+                       if( !NT_SUCCESS( status ) ) {\r
+                               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
+                                       ("__hca_register returned 0x%08X.\n", status));\r
+                       }\r
+               }\r
+       }\r
+\r
+       HCA_EXIT( HCA_DBG_PO );\r
+}\r
+\r
+\r
+void reregister_hca( hca_dev_ext_t *p_ext )\r
+{\r
+       DEVICE_OBJECT *p_dev_obj = (DEVICE_OBJECT *)p_ext->cl_ext.p_self_do;\r
+       PIO_WORKITEM pPoWorkItem;\r
+\r
+       /* Process in a work item - deregister_ca and HcaDeinit block. */\r
+       pPoWorkItem = IoAllocateWorkItem( p_dev_obj );\r
+       if( pPoWorkItem ) \r
+               IoQueueWorkItem( pPoWorkItem, __reregister_hca_cb, \r
+                       DelayedWorkQueue, pPoWorkItem );\r
+       \r
+}\r
+\r
index dfdcb8e..1b331c2 100644 (file)
@@ -452,7 +452,7 @@ done:
        // chain user context to the device\r
        cl_spinlock_acquire( &ext_p->uctx_lock );\r
        cl_qlist_insert_tail( &ext_p->uctx_list, &p_context->list_item );\r
-       atomic_inc(&ext_p->usecnt);\r
+       cl_atomic_inc(&ext_p->usecnt);\r
        cl_spinlock_release( &ext_p->uctx_lock );\r
        \r
        // return the result\r
@@ -487,7 +487,7 @@ mlnx_um_close(
 done:  \r
        cl_spinlock_acquire( &ext_p->uctx_lock );\r
        cl_qlist_remove_item( &ext_p->uctx_list, &p_ucontext->list_item );\r
-       atomic_dec(&ext_p->usecnt);\r
+       cl_atomic_dec(&ext_p->usecnt);\r
        cl_spinlock_release( &ext_p->uctx_lock );\r
        if( !p_ucontext->pd )\r
                cl_free( h_um_ca );\r
index 35b4a28..2a4d9d2 100644 (file)
@@ -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