[IBBUS] add control device to solve bugzilla #1367 problem.
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 3 May 2009 13:52:07 +0000 (13:52 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 3 May 2009 13:52:07 +0000 (13:52 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2147 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/bus/kernel/bus_driver.c
core/bus/kernel/bus_pnp.c
core/bus/kernel/bus_port_mgr.c

index 7ba8123..a59d528 100644 (file)
@@ -60,6 +60,8 @@
 \r
 \r
 char   node_desc[IB_NODE_DESCRIPTION_SIZE];\r
+PDEVICE_OBJECT g_ControlDeviceObject=NULL;\r
+UNICODE_STRING g_CDO_dev_name, g_CDO_dos_name;\r
 \r
 bus_globals_t  bus_globals = {\r
        BUS_DBG_ERROR,\r
@@ -738,7 +740,7 @@ __read_registry(
 \r
        // For manageable Debug output: Disable Enter/Exit macros in\r
        //  bus_drv_ioctl(), bus_drv_open(), bus_drv_cleanup()\r
-       // bus_globals.dbg_lvl |= BUS_DBG_DRV | BUS_DBG_PNP | BUS_DBG_POWER;\r
+       //bus_globals.dbg_lvl |= BUS_DBG_DRV | BUS_DBG_PNP | BUS_DBG_POWER;\r
 #endif\r
 \r
        BUS_TRACE(BUS_DBG_DRV ,\r
@@ -974,13 +976,16 @@ bus_drv_unload(
        IN                              DRIVER_OBJECT                           *p_driver_obj )\r
 {\r
        pkey_conf_t *cur_conf,*tmp;\r
-       UNICODE_STRING           dos_name;\r
        UNUSED_PARAM( p_driver_obj );\r
 \r
        BUS_ENTER( BUS_DBG_DRV );\r
        \r
-       RtlInitUnicodeString( &dos_name, L"\\DosDevices\\Global\\ibal" );\r
-       IoDeleteSymbolicLink( &dos_name );\r
+       IoDeleteSymbolicLink( &g_CDO_dos_name );\r
+       if (g_ControlDeviceObject)\r
+       {\r
+               IoDeleteDevice(g_ControlDeviceObject);\r
+               g_ControlDeviceObject = NULL; \r
+       }\r
        cur_conf = bus_globals.p_pkey_conf;\r
        while(cur_conf)\r
        {\r
@@ -1055,7 +1060,32 @@ DriverEntry(
        g_bfi_InstanceCount = 0;\r
        memset(  __out_bcount(sizeof(g_bus_filters)) (void*)g_bus_filters, 0,\r
                        sizeof(g_bus_filters) );\r
+       \r
+       {\r
+               bus_fdo_ext_t   *p_ext=NULL;\r
+\r
+               RtlInitUnicodeString( &g_CDO_dev_name, AL_DEVICE_NAME );\r
+               RtlInitUnicodeString( &g_CDO_dos_name, L"\\DosDevices\\Global\\ibal" );\r
 \r
+               status = IoCreateDevice( p_driver_obj, sizeof(bus_fdo_ext_t),\r
+                       &g_CDO_dev_name, FILE_DEVICE_BUS_EXTENDER,\r
+                       FILE_DEVICE_SECURE_OPEN, FALSE, &g_ControlDeviceObject );\r
+               if( !NT_SUCCESS(status) )\r
+               {\r
+                       g_ControlDeviceObject = NULL;\r
+                       BUS_PRINT( BUS_DBG_ERROR, \r
+                               ("Failed to create ControlDeviceObject, status %x.\n",status) );\r
+                       /* failure is OK - retry in bus_add_device() */\r
+               }\r
+               else {\r
+                               p_ext = g_ControlDeviceObject->DeviceExtension;\r
+                               RtlZeroMemory(p_ext, sizeof *p_ext);\r
+                               cl_init_pnp_po_ext( g_ControlDeviceObject, NULL, \r
+                                       NULL, bus_globals.dbg_lvl, NULL, NULL );\r
+                               IoInitializeRemoveLock( &p_ext->cl_ext.stop_lock, 'dtci', 0, 1000 );\r
+                       }\r
+               }\r
+       \r
        BUS_EXIT( BUS_DBG_DRV );\r
        return STATUS_SUCCESS;\r
 }\r
index 162c401..dc4da56 100644 (file)
@@ -40,6 +40,7 @@
 #include "al_ca.h"\r
 #include "al_init.h"\r
 #include "al_dev.h"\r
+#include "al_debug.h"\r
 #include "bus_port_mgr.h"\r
 #include "bus_iou_mgr.h"\r
 #include "complib/cl_memory.h"\r
@@ -59,7 +60,8 @@ KEVENT                                        g_ControlEvent;
 ULONG                                  g_bfi_InstanceCount;\r
 bus_filter_t                   g_bus_filters[MAX_BUS_FILTERS];\r
 \r
-extern ib_al_handle_t  gh_al; // NULL if AL needs init.\r
+extern PDEVICE_OBJECT  g_ControlDeviceObject;\r
+extern UNICODE_STRING  g_CDO_dev_name, g_CDO_dos_name;\r
 \r
 \r
 static NTSTATUS\r
@@ -179,7 +181,6 @@ bus_add_device(
        NTSTATUS                status;\r
        DEVICE_OBJECT   *p_dev_obj, *p_next_do;\r
        bus_fdo_ext_t   *p_ext=NULL;\r
-       UNICODE_STRING  dev_name, dos_name;\r
        bus_filter_t    *p_bfi;\r
        int                             ic;\r
 \r
@@ -197,13 +198,10 @@ bus_add_device(
        /* Create the FDO device object to attach to the stack. */\r
 \r
        /* if 1st Bus Filter Instance, then create device names for user ioctl */\r
-       if ( ic == 1 )\r
+       if ( ic == 1  && !g_ControlDeviceObject)\r
        {\r
-               RtlInitUnicodeString( &dev_name, AL_DEVICE_NAME );\r
-               RtlInitUnicodeString( &dos_name, L"\\DosDevices\\Global\\ibal" );\r
-\r
                status = IoCreateDevice( p_driver_obj, sizeof(bus_fdo_ext_t),\r
-                                                                &dev_name, FILE_DEVICE_BUS_EXTENDER,\r
+                                                                &g_CDO_dev_name, FILE_DEVICE_BUS_EXTENDER,\r
                                                                 FILE_DEVICE_SECURE_OPEN, FALSE, &p_dev_obj );\r
                if( !NT_SUCCESS(status) )\r
                {\r
@@ -211,14 +209,6 @@ bus_add_device(
                                ("Failed to create ControlDeviceObject, status %x.\n",status) );\r
                        goto err1;\r
                }\r
-               IoDeleteSymbolicLink( &dos_name );\r
-               status = IoCreateSymbolicLink( &dos_name, &dev_name );\r
-               if( !NT_SUCCESS(status) )\r
-               {\r
-                       BUS_PRINT( BUS_DBG_ERROR,\r
-                               ("Failed to create symlink for dos name.\n") );\r
-                       goto err2;\r
-               }\r
        }\r
        else {\r
                status = IoCreateDevice( p_driver_obj, sizeof(bus_fdo_ext_t),\r
@@ -232,6 +222,20 @@ bus_add_device(
                }\r
        }\r
 \r
+       if ( ic == 1 ) {\r
+               /* enable user-mode access to IB stack */\r
+               BUS_PRINT( BUS_DBG_PNP, ("Remove-n-reCreate dos_name symlink\n") );\r
+               IoDeleteSymbolicLink( &g_CDO_dos_name );\r
+               status = IoCreateSymbolicLink( &g_CDO_dos_name, &g_CDO_dev_name );\r
+               if( !NT_SUCCESS(status) )\r
+               {\r
+                       BUS_PRINT( BUS_DBG_ERROR,\r
+                               ("Failed to create symlink for dos name.\n") );\r
+                       goto err2;\r
+               }\r
+               BUS_TRACE( BUS_DBG_PNP, ("Created dos_name symlink\n") );\r
+       }\r
+\r
        p_ext = p_dev_obj->DeviceExtension;\r
        p_ext->n_al_ifc_ref = 0;\r
        p_ext->n_ci_ifc_ref = 0;\r
@@ -307,7 +311,7 @@ err1:
        /* if last Bus filter, then cleanup */\r
        if ( ic == 0 )\r
        {\r
-               IoDeleteSymbolicLink( &dos_name );\r
+               IoDeleteSymbolicLink( &g_CDO_dos_name );\r
                RtlFreeUnicodeString( &al_ifc_name );\r
        }\r
        BUS_EXIT( BUS_DBG_PNP );\r
@@ -404,7 +408,7 @@ fdo_start(
        }\r
 \r
        lock_control_event();\r
-       if ( !gh_al ) {\r
+       if ( !gp_async_proc_mgr ) {\r
                /* Initialize AL */\r
                ib_status = al_initialize();\r
                if( ib_status != IB_SUCCESS )\r
@@ -416,6 +420,7 @@ fdo_start(
                        return STATUS_UNSUCCESSFUL;\r
                }\r
                AL_init_here = TRUE;\r
+               BUS_TRACE( BUS_DBG_PNP, ("AL initialized\n"));\r
        }\r
        unlock_control_event();\r
 \r
@@ -571,12 +576,13 @@ fdo_release_resources(
                p_ext->p_iou_mgr = NULL;\r
        }\r
 \r
-       if (p_ext->hca_ifc_taken) {\r
+       if ( ic > 0 && p_ext->hca_ifc_taken ) {\r
                p_ext->hca_ifc.InterfaceHeader.InterfaceDereference(\r
                        p_ext->hca_ifc.InterfaceHeader.Context);\r
+               p_ext->hca_ifc_taken = FALSE;\r
        }\r
 \r
-       BUS_PRINT( BUS_DBG_PNP, ("Releasing BusFilter %s\n", p_bfi->whoami ));\r
+       BUS_TRACE( BUS_DBG_PNP, ("Releasing BusFilter %s\n", p_bfi->whoami ));\r
        if (p_bfi) {\r
                p_ext->bus_filter = NULL;\r
                p_bfi->p_bus_ext = NULL;\r
@@ -586,10 +592,12 @@ fdo_release_resources(
 \r
        /* if not last Buf Filter Instance, then exit, otherwise cleanup/shutdown */\r
        if ( ic > 0 ) {\r
-               BUS_PRINT( BUS_DBG_PNP, (" %d remaining BusFilters\n", ic ));\r
+               BUS_TRACE( BUS_DBG_PNP, ("%d remaining BusFilters\n", ic ));\r
                return;\r
        }\r
 \r
+       IoDeleteSymbolicLink( &g_CDO_dos_name );\r
+\r
        /* Disable any exported interfaces. */\r
        status = IoSetDeviceInterfaceState( &al_ifc_name, FALSE );\r
        ASSERT( NT_SUCCESS( status ) );\r
@@ -604,6 +612,18 @@ fdo_release_resources(
        RtlFreeUnicodeString( &al_ifc_name );\r
 \r
        al_cleanup();\r
+       cl_thread_suspend(50);  /* allow time for AL's async procs to run to exit */\r
+\r
+       ASSERT( !gp_async_proc_mgr && !gp_async_pnp_mgr && !gp_al_mgr );\r
+\r
+       /* AL needs the HCA to stick around until AL cleanup has completed.\r
+        * Now that it's done, let the HCA fade away.\r
+        */\r
+       if ( p_ext->hca_ifc_taken ) {\r
+               p_ext->hca_ifc.InterfaceHeader.InterfaceDereference(\r
+                       p_ext->hca_ifc.InterfaceHeader.Context);\r
+               p_ext->hca_ifc_taken = FALSE;\r
+       }\r
 \r
        BUS_EXIT( BUS_DBG_PNP );\r
 }\r
@@ -1429,9 +1449,8 @@ get_bfi_by_obj(IN int obj_type, IN cl_obj_t *p_obj )
        }\r
        unlock_control_event();\r
 \r
-       BUS_PRINT( BUS_DBG_PNP,\r
-                               ("%s() cl_obj %p type %s_MGR_OBJ --> bfi[%d] %p\n",\r
-                               __FUNCTION__,p_obj,\r
+       BUS_TRACE( BUS_DBG_PNP,\r
+                               ("cl_obj %p type %s_MGR_OBJ --> bfi[%d] %p\n", p_obj,\r
                                (obj_type == BFI_PORT_MGR_OBJ ? "PORT": "IOU"),\r
                                (matched ? (matched - g_bus_filters) : (-1)), matched ) );\r
 \r
@@ -1452,8 +1471,8 @@ get_bfi_by_ca_guid( IN net64_t ca_guid )
        if ( ca_guid == 0ULL )\r
        {\r
                matched = g_bus_filters;\r
-               BUS_PRINT( BUS_DBG_PNP, ("%s() ERR guid %I64x -> bfi[0] %p\n",\r
-                                                               __FUNCTION__, ca_guid, matched) );\r
+               BUS_TRACE( BUS_DBG_PNP, ("ERR guid %I64x -> bfi[0] %p\n",\r
+                                                               ca_guid, matched) );\r
                CL_ASSERT( ca_guid );\r
                return matched;\r
        }\r
@@ -1522,8 +1541,8 @@ alloc_bfi( IN DRIVER_OBJECT  *p_driver_obj, OUT int *p_instance_count )
        p_bfi->magic = BFI_MAGIC;\r
 #endif\r
 \r
-       BUS_PRINT( BUS_DBG_PNP, ("%s() %s %p\n",\r
-                               __FUNCTION__, (matched ? matched->whoami:"Nobody"), matched) );\r
+       BUS_TRACE( BUS_DBG_PNP, ("%s %p\n",\r
+                               (matched ? matched->whoami:"Nobody"), matched) );\r
 \r
        return matched;\r
 }\r
index bf5dec0..c0c3a68 100644 (file)
@@ -424,6 +424,7 @@ free_port_mgr(
                        BUS_TRACE( BUS_DBG_PNP, ("%s Deleted device %s: PDO %p, ext %p\n",\r
                                                p_bfi->whoami, p_ext->cl_ext.vfptr_pnp_po->identity,\r
                                                p_ext->cl_ext.p_self_do, p_ext ) );\r
+\r
                        IoDeleteDevice( p_ext->cl_ext.p_self_do );\r
                }\r
 \r
@@ -700,8 +701,7 @@ end:
 void\r
 dump_pnp_port_rec( ib_pnp_port_rec_t*  pr )\r
 {\r
-       BUS_PRINT( BUS_DBG_PNP, ("%s() ib_pnp_port_rec_t* @ %p\nib_pnp_rec_t*:\n",\r
-                               __FUNCTION__,pr));\r
+       BUS_TRACE( BUS_DBG_PNP, ("ib_pnp_port_rec_t* @ %p\nib_pnp_rec_t*:\n", pr));\r
 \r
 \r
        BUS_PRINT( BUS_DBG_PNP, ("  Event %s\n",\r
@@ -734,8 +734,7 @@ dump_pnp_port_rec( ib_pnp_port_rec_t*       pr )
 void\r
 dump_pnp_iou_rec( ib_pnp_iou_rec_t*    pr )\r
 {\r
-       BUS_PRINT( BUS_DBG_PNP, ("%s() ib_pnp_iou_rec_t* @ %p\nib_pnp_rec_t*:\n",\r
-                               __FUNCTION__,pr));\r
+       BUS_TRACE( BUS_DBG_PNP, ("ib_pnp_iou_rec_t* @ %p\nib_pnp_rec_t*:\n", pr));\r
 \r
 \r
        BUS_PRINT( BUS_DBG_PNP, ("  Event %s\n",\r