[IBBUS] workaround for some problems with WHQL PnP test over IPoIB. [mlnx: 3535]
[mirror/winof/.git] / core / complib / kernel / cl_pnp_po.c
index 972937b..17302f7 100644 (file)
@@ -213,6 +213,9 @@ cl_pnp(
        {\r
                CL_TRACE_EXIT( CL_DBG_ERROR, p_ext->dbg_lvl, \r
                        ("IoAcquireRemoveLock returned %08x.\n", status) );\r
+               p_io_stack = IoGetCurrentIrpStackLocation( p_irp );\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, \r
+                       ("Minor function %x for %s\n", p_io_stack->MinorFunction, p_ext->vfptr_pnp_po->identity) );\r
                p_irp->IoStatus.Status = status;\r
                IoCompleteRequest( p_irp, IO_NO_INCREMENT );\r
                return status;\r
@@ -243,7 +246,7 @@ cl_pnp(
 \r
        case IRP_MN_CANCEL_STOP_DEVICE:\r
                CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, \r
-                       ("IRP_MN_START_DEVICE for %s\n", p_ext->vfptr_pnp_po->identity) );\r
+                       ("IRP_MN_CANCEL_STOP_DEVICE for %s\n", p_ext->vfptr_pnp_po->identity) );\r
                status = __cancel_stop( p_dev_obj, p_irp, &action );\r
                break;\r
 \r
@@ -394,6 +397,8 @@ cl_pnp(
        {\r
        case IrpPassDown:\r
                p_irp->IoStatus.Status = status;\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IrpPassDown: passing down to PDO %p, ext %p, status %#x\n",\r
+                       p_ext->p_next_do, p_ext, p_irp->IoStatus.Status) );\r
                IoCopyCurrentIrpStackLocationToNext( p_irp );\r
                status = IoCallDriver( p_ext->p_next_do, p_irp );\r
                break;\r
@@ -402,23 +407,28 @@ cl_pnp(
                p_irp->IoStatus.Status = status;\r
 \r
        case IrpIgnore:\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IrpSkip/IrpIgnore: skipping down to PDO %p, ext %p, status %#x\n",\r
+                       p_ext->p_next_do, p_ext, p_irp->IoStatus.Status) );\r
                IoSkipCurrentIrpStackLocation( p_irp );\r
                status = IoCallDriver( p_ext->p_next_do, p_irp );\r
                break;\r
 \r
        case IrpComplete:\r
                p_irp->IoStatus.Status = status;\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IrpComplete: complete IRP with status %#x\n",\r
+                       p_irp->IoStatus.Status) );\r
                IoCompleteRequest( p_irp, IO_NO_INCREMENT );\r
                break;\r
 \r
        case IrpDoNothing:\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IrpDoNothing: do nothing\n") );\r
                break;\r
        }\r
 \r
        if( action != IrpDoNothing )\r
                IoReleaseRemoveLock( &p_ext->remove_lock, p_irp );\r
 \r
-       CL_EXIT( CL_DBG_PNP, p_ext->dbg_lvl );\r
+       CL_TRACE_EXIT( CL_DBG_PNP, p_ext->dbg_lvl, ("returned with status %#x\n", status) );\r
        return status;\r
 }\r
 \r
@@ -444,8 +454,10 @@ __start(
         * If we get the start request when we're already started, don't \r
         * re-initialize the stop lock.\r
         */\r
-       if( p_ext->last_pnp_state != Started )\r
+       if( p_ext->last_pnp_state != Started ) {\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IoInitializeRemoveLock: stop_lock %p[\n", &p_ext->stop_lock));\r
                IoInitializeRemoveLock( &p_ext->stop_lock, 'dtci', 0, 1000 );\r
+       }\r
 \r
        CL_EXIT( CL_DBG_PNP, p_ext->dbg_lvl );\r
        return status;\r
@@ -493,7 +505,12 @@ __query_stop(
        if( p_ext->last_pnp_state == Started )\r
        {\r
                /* Acquire the lock so we can release and wait. */\r
-               IoAcquireRemoveLock( &p_ext->stop_lock, p_irp );\r
+               status = IoAcquireRemoveLock( &p_ext->stop_lock, p_irp );\r
+               if( !NT_SUCCESS( status ) )\r
+               {\r
+                       CL_TRACE( CL_DBG_ERROR, p_ext->dbg_lvl, \r
+                               ("IoAcquireRemoveLock returned %08x. Continue anyway ...\n", status) );\r
+               }\r
                /* Wait for all IO operations to complete. */\r
                IoReleaseRemoveLockAndWait( &p_ext->stop_lock, p_irp );\r
        }\r
@@ -563,14 +580,28 @@ __cancel_stop(
        if( p_ext->last_pnp_state == Started )\r
        {\r
                /*\r
-                * Re-initialize the remove lock before rolling back the PnP\r
+                * Re-initialize the stop lock before rolling back the PnP\r
                 * state so that there's no contention while it's uninitialized.\r
                 */\r
+               CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IoInitializeRemoveLock: stop_lock %p[\n", &p_ext->stop_lock));\r
                IoInitializeRemoveLock( &p_ext->stop_lock, 'dtci', 0, 1000 );\r
+#if 0          \r
+               // leo: it seems like a bug, because it can never get released\r
+               {\r
                /* \r
                 * Acquire the stop lock to allow releasing and waiting when stopping.\r
                 */\r
-               IoAcquireRemoveLock( &p_ext->stop_lock, NULL );\r
+                       NTSTATUS                        status1;\r
+                       CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IoAcquireRemoveLock: stop_lock %p[\n", &p_ext->stop_lock));\r
+                       status1 = IoAcquireRemoveLock( &p_ext->stop_lock, NULL );\r
+                       if( !NT_SUCCESS( status1 ) )\r
+                       {\r
+                               CL_TRACE( CL_DBG_ERROR, p_ext->dbg_lvl, \r
+                                       ("IoAcquireRemoveLock returned %08x. Continue anyway ...\n", status) );\r
+                       }\r
+                       CL_TRACE( CL_DBG_PNP, p_ext->dbg_lvl, ("IoAcquireRemoveLock: stop_lock ]\n"));\r
+               }\r
+#endif         \r
        }\r
 \r
        /* Return to the previous PnP state. */\r
@@ -653,7 +684,10 @@ __remove(
        ASSERT( p_ext->pnp_state == NotStarted ||\r
                p_ext->pnp_state == Started ||\r
                p_ext->pnp_state == RemovePending ||\r
-               p_ext->pnp_state == SurpriseRemoved );\r
+               p_ext->pnp_state == SurpriseRemoved ||\r
+               // it can be on this state if IRP_MN_START_DEVICE failed\r
+               // pnpdtest /rebalance FailRestart creates this situation\r
+               p_ext->pnp_state == Stopped);\r
 \r
        /* Set the device state. */\r
        cl_set_pnp_state( p_ext, Deleted );\r