[IBBUS] fix bug in Control device implementation (patches 4218,4280). [mlnx: 4396]
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 2 Jun 2009 17:48:10 +0000 (17:48 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 2 Jun 2009 17:48:10 +0000 (17:48 +0000)
Control Device was created in DriverEntry and removed in DrvUnload routine.
But PnP Manager won't call DrvUnload before Control Device is removed.
So IBBUS gets never unloaded.

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

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

index 8b19d35..79f9f87 100644 (file)
@@ -1000,12 +1000,6 @@ bus_drv_unload(
 \r
        BUS_ENTER( BUS_DBG_DRV );\r
        \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
@@ -1084,31 +1078,6 @@ DriverEntry(
        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 74de4f2..82ffddd 100644 (file)
@@ -195,45 +195,54 @@ bus_add_device(
                return STATUS_UNSUCCESSFUL;\r
        }\r
 \r
-       /* 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  && !g_ControlDeviceObject)\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, &p_dev_obj );\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
                        goto err1;\r
                }\r
-       }\r
-       else {\r
-               status = IoCreateDevice( p_driver_obj, sizeof(bus_fdo_ext_t),\r
-                                                                NULL, FILE_DEVICE_BUS_EXTENDER,\r
-                                                                FILE_DEVICE_SECURE_OPEN, FALSE, &p_dev_obj );\r
-               if( !NT_SUCCESS(status) )\r
-               {\r
-                       BUS_PRINT( BUS_DBG_ERROR, \r
-                               ("Failed to create bus root FDO device.\n") );\r
-                       goto err1;\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
+                       /* 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
+                               IoDeleteDevice( g_ControlDeviceObject );\r
+                               g_ControlDeviceObject = NULL;\r
+                               goto err1;\r
+                       }\r
+                       BUS_TRACE( BUS_DBG_PNP, ("Created dos_name symlink\n") );\r
                }\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
+       /* Create the FDO device object to attach to the stack. */\r
+       status = IoCreateDevice( p_driver_obj, sizeof(bus_fdo_ext_t),\r
+                                                        NULL, FILE_DEVICE_BUS_EXTENDER,\r
+                                                        FILE_DEVICE_SECURE_OPEN, FALSE, &p_dev_obj );\r
+       if( !NT_SUCCESS(status) )\r
+       {\r
+               BUS_PRINT( BUS_DBG_ERROR, \r
+                       ("Failed to create bus root FDO device.\n") );\r
+               goto err1;\r
        }\r
 \r
        p_ext = p_dev_obj->DeviceExtension;\r
@@ -308,12 +317,6 @@ err2:
 err1:\r
        BUS_PRINT( BUS_DBG_PNP, ("%s exit status 0x%x\n", p_bfi->whoami,status) );\r
        ic = free_bfi(p_bfi);\r
-       /* if last Bus filter, then cleanup */\r
-       if ( ic == 0 )\r
-       {\r
-               IoDeleteSymbolicLink( &g_CDO_dos_name );\r
-               RtlFreeUnicodeString( &al_ifc_name );\r
-       }\r
        BUS_EXIT( BUS_DBG_PNP );\r
        return status;\r
 }\r
@@ -470,7 +473,7 @@ fdo_start(
        p_bfi->ca_guid = p_ext->hca_ifc.Verbs.guid;\r
 \r
        /* register HCA */\r
-       ib_status = ib_register_ca( &p_ext->hca_ifc.Verbs, p_ext->cl_ext.p_pdo );\r
+       ib_status = ib_register_ca( &p_ext->hca_ifc.Verbs, p_ext->cl_ext.p_pdo, p_dev_obj );\r
        if( ib_status != IB_SUCCESS )\r
        {\r
                BUS_TRACE_EXIT( BUS_DBG_ERROR, ("ib_register_ca returned %s.\n",\r
@@ -596,7 +599,12 @@ fdo_release_resources(
                return;\r
        }\r
 \r
-       IoDeleteSymbolicLink( &g_CDO_dos_name );\r
+       if (g_ControlDeviceObject)\r
+       {\r
+               IoDeleteSymbolicLink( &g_CDO_dos_name );\r
+               IoDeleteDevice(g_ControlDeviceObject);\r
+               g_ControlDeviceObject = NULL; \r
+       }\r
 \r
        /* Disable any exported interfaces. */\r
        status = IoSetDeviceInterfaceState( &al_ifc_name, FALSE );\r