[USBSTOR] Do not try to retry a failed request
authorVictor Perevertkin <victor@perevertkin.ru>
Wed, 10 Apr 2019 00:22:03 +0000 (03:22 +0300)
committerVictor Perevertkin <victor@perevertkin.ru>
Tue, 11 Jun 2019 01:39:43 +0000 (04:39 +0300)
for all cases except receiving a USBD_STATUS_STALL_PID status.
This decision should be made by higher-level driver (and classpnp drivers do it)

drivers/usb/usbstor/error.c
drivers/usb/usbstor/queue.c
drivers/usb/usbstor/scsi.c
drivers/usb/usbstor/usbstor.h

index 9309032..571c89d 100644 (file)
@@ -107,7 +107,7 @@ USBSTOR_HandleTransferError(
     pCDB = (PCDB)Request->Cdb;
     ASSERT(pCDB);
 
     pCDB = (PCDB)Request->Cdb;
     ASSERT(pCDB);
 
-    if (Status != STATUS_SUCCESS || Context->RetryCount >= 1)
+    if (!NT_SUCCESS(Status))
     {
         // Complete the master IRP
         Context->Irp->IoStatus.Status = Status;
     {
         // Complete the master IRP
         Context->Irp->IoStatus.Status = Status;
@@ -124,22 +124,6 @@ USBSTOR_HandleTransferError(
         // clear timer srb
         Context->FDODeviceExtension->LastTimerActiveSrb = NULL;
     }
         // clear timer srb
         Context->FDODeviceExtension->LastTimerActiveSrb = NULL;
     }
-    else
-    {
-        DPRINT1("Retrying Count %lu %p\n", Context->RetryCount, Stack->DeviceObject);
-
-        // re-schedule request
-        USBSTOR_HandleExecuteSCSI(Stack->DeviceObject, Context->Irp, Context->RetryCount + 1);
-
-        // srb error handling finished
-        Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE;
-
-        // srb error handling finished
-        Context->FDODeviceExtension->TimerWorkQueueEnabled = TRUE;
-
-        // clear timer srb
-        Context->FDODeviceExtension->LastTimerActiveSrb = NULL;
-    }
 
     FreeItem(Context);
 
 
     FreeItem(Context);
 
index f4dbe5c..8babc98 100644 (file)
@@ -355,7 +355,7 @@ USBSTOR_StartIo(
         return;
     }
 
         return;
     }
 
-    USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp, 0);
+    USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp);
 
     // FIXME: handle error
 }
 
     // FIXME: handle error
 }
index 05ef1c9..002b8f2 100644 (file)
@@ -183,9 +183,9 @@ USBSTOR_CSWCompletionRoutine(
     {
         if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
         {
     {
         if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
         {
-            if (Context->RetryCount < 2)
+            if (Context->StallRetryCount < 2)
             {
             {
-                ++Context->RetryCount;
+                ++Context->StallRetryCount;
 
                 // clear stall and resend cbw
                 Context->ErrorIndex = 1;
 
                 // clear stall and resend cbw
                 Context->ErrorIndex = 1;
@@ -345,7 +345,7 @@ USBSTOR_DataCompletionRoutine(
     }
     else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
     {
     }
     else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID))
     {
-        ++Context->RetryCount;
+        ++Context->StallRetryCount;
 
         Request->SrbStatus = SRB_STATUS_DATA_OVERRUN;
         Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
 
         Request->SrbStatus = SRB_STATUS_DATA_OVERRUN;
         Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength;
@@ -527,7 +527,7 @@ USBSTOR_SendCBWRequest(
     // initialize rest of context
     Context->Irp = Irp;
     Context->FDODeviceExtension = FDODeviceExtension;
     // initialize rest of context
     Context->Irp = Irp;
     Context->FDODeviceExtension = FDODeviceExtension;
-    Context->RetryCount = 0;
+    Context->StallRetryCount = 0;
 
     return USBSTOR_IssueBulkOrInterruptRequest(
         FDODeviceExtension,
 
     return USBSTOR_IssueBulkOrInterruptRequest(
         FDODeviceExtension,
@@ -586,8 +586,7 @@ USBSTOR_IssueRequestSense(
 NTSTATUS
 USBSTOR_HandleExecuteSCSI(
     IN PDEVICE_OBJECT DeviceObject,
 NTSTATUS
 USBSTOR_HandleExecuteSCSI(
     IN PDEVICE_OBJECT DeviceObject,
-    IN PIRP Irp,
-    IN ULONG RetryCount)
+    IN PIRP Irp)
 {
     PCDB pCDB;
     NTSTATUS Status;
 {
     PCDB pCDB;
     NTSTATUS Status;
index 25066cc..d2a72ec 100644 (file)
@@ -286,7 +286,7 @@ typedef struct
     PIRP Irp;
     PFDO_DEVICE_EXTENSION FDODeviceExtension;
     ULONG ErrorIndex;
     PIRP Irp;
     PFDO_DEVICE_EXTENSION FDODeviceExtension;
     ULONG ErrorIndex;
-    ULONG RetryCount;
+    ULONG StallRetryCount;                                            // the number of retries after receiving USBD_STATUS_STALL_PID status
     union
     {
         CBW cbw;
     union
     {
         CBW cbw;
@@ -406,8 +406,7 @@ USBSTOR_GetPipeHandles(
 NTSTATUS
 USBSTOR_HandleExecuteSCSI(
     IN PDEVICE_OBJECT DeviceObject,
 NTSTATUS
 USBSTOR_HandleExecuteSCSI(
     IN PDEVICE_OBJECT DeviceObject,
-    IN PIRP Irp,
-    IN ULONG RetryCount);
+    IN PIRP Irp);
 
 NTSTATUS
 USBSTOR_SendCSWRequest(
 
 NTSTATUS
 USBSTOR_SendCSWRequest(