ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
June 2019
----- 2024 -----
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
28 participants
288 discussions
Start a n
N
ew thread
[reactos] 17/17: [USBSTOR] Properly handle IRP_MN_QUERY_DEVICE_RELATIONS(BusRelations) for FDO. This fixes Driver Verifier warnings
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da1b08e842c65553cd357…
commit da1b08e842c65553cd3576e9396d4f62cd86cb96 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Tue Jun 11 02:50:43 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Properly handle IRP_MN_QUERY_DEVICE_RELATIONS(BusRelations) for FDO. This fixes Driver Verifier warnings --- drivers/usb/usbstor/fdo.c | 65 +++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c index 6879b4efe8f..a8a1a4d37b3 100644 --- a/drivers/usb/usbstor/fdo.c +++ b/drivers/usb/usbstor/fdo.c @@ -5,6 +5,7 @@ * COPYRIGHT: 2005-2006 James Tabor * 2011-2012 Michael Martin (michael.martin(a)reactos.org) * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) + * 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) */ #include "usbstor.h" @@ -45,46 +46,49 @@ USBSTOR_FdoHandleDeviceRelations( IoStack = IoGetCurrentIrpStackLocation(Irp); - // check if relation type is BusRelations - if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations) + // FDO always only handles bus relations + if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations) { - // FDO always only handles bus relations - return USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp); - } - - // go through array and count device objects - for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) - { - if (DeviceExtension->ChildPDO[Index]) + // go through array and count device objects + for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) { - DeviceCount++; + if (DeviceExtension->ChildPDO[Index]) + { + DeviceCount++; + } } - } - DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0)); - if (!DeviceRelations) - { - return STATUS_INSUFFICIENT_RESOURCES; - } + DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0)); + if (!DeviceRelations) + { + Irp->IoStatus.Information = 0; + Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return STATUS_INSUFFICIENT_RESOURCES; + } - // add device objects - for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) - { - if (DeviceExtension->ChildPDO[Index]) + // add device objects + for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) { - // store child pdo - DeviceRelations->Objects[DeviceRelations->Count] = DeviceExtension->ChildPDO[Index]; + if (DeviceExtension->ChildPDO[Index]) + { + // store child pdo + DeviceRelations->Objects[DeviceRelations->Count] = DeviceExtension->ChildPDO[Index]; - // add reference - ObReferenceObject(DeviceExtension->ChildPDO[Index]); + // add reference + ObReferenceObject(DeviceExtension->ChildPDO[Index]); - DeviceRelations->Count++; + DeviceRelations->Count++; + } } + + Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; + Irp->IoStatus.Status = STATUS_SUCCESS; } - Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; + IoCopyCurrentIrpStackLocationToNext(Irp); - return STATUS_SUCCESS; + return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); } NTSTATUS @@ -291,9 +295,8 @@ USBSTOR_FdoHandlePnp( } case IRP_MN_QUERY_DEVICE_RELATIONS: { - DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p\n", DeviceObject); - Status = USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp); - break; + DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p Type: %u\n", DeviceObject, IoStack->Parameters.QueryDeviceRelations.Type); + return USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp); } case IRP_MN_STOP_DEVICE: {
5 years, 5 months
1
0
0
0
[reactos] 16/17: [USBSTOR] Register dumb IRP_MJ_SYSTEM_CONTROL handler. This satisfies Driver Verifier
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=04409942d6d787357e745…
commit 04409942d6d787357e7453193f8f93ba4694aac7 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Tue Jun 11 01:42:28 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Register dumb IRP_MJ_SYSTEM_CONTROL handler. This satisfies Driver Verifier --- drivers/usb/usbstor/usbstor.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/usb/usbstor/usbstor.c b/drivers/usb/usbstor/usbstor.c index 99392f7e092..75dee316052 100644 --- a/drivers/usb/usbstor/usbstor.c +++ b/drivers/usb/usbstor/usbstor.c @@ -138,6 +138,25 @@ USBSTOR_DispatchPnp( } } +NTSTATUS +NTAPI +USBSTOR_DispatchSystemControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PUSBSTOR_COMMON_DEVICE_EXTENSION DeviceExtension = (PUSBSTOR_COMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + IoSkipCurrentIrpStackLocation(Irp); + + if (DeviceExtension->IsFDO) + { + return IoCallDriver(((PFDO_DEVICE_EXTENSION)DeviceExtension)->LowerDeviceObject, Irp); + } + else + { + return IoCallDriver(((PPDO_DEVICE_EXTENSION)DeviceExtension)->LowerDeviceObject, Irp); + } +} + NTSTATUS NTAPI USBSTOR_DispatchPower( @@ -183,6 +202,7 @@ DriverEntry( DriverObject->MajorFunction[IRP_MJ_WRITE] = USBSTOR_DispatchReadWrite; DriverObject->MajorFunction[IRP_MJ_SCSI] = USBSTOR_DispatchScsi; DriverObject->MajorFunction[IRP_MJ_PNP] = USBSTOR_DispatchPnp; + DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = USBSTOR_DispatchSystemControl; DriverObject->MajorFunction[IRP_MJ_POWER] = USBSTOR_DispatchPower; return STATUS_SUCCESS;
5 years, 5 months
1
0
0
0
[reactos] 15/17: [USBSTOR] Improve handling of IRP_MN_QUERY_DEVICE_TEXT for PDOs CORE-15883
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=126abaf88f58ec3dd3da9…
commit 126abaf88f58ec3dd3da9d6631d5b6a554a852ae Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Tue Jun 11 01:40:43 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Improve handling of IRP_MN_QUERY_DEVICE_TEXT for PDOs CORE-15883 --- drivers/usb/usbstor/pdo.c | 92 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index 9a84483b701..ef9a4fb4511 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -119,6 +119,7 @@ USBSTOR_GetGenericType( } } +static ULONG CopyField( IN PUCHAR Name, @@ -144,50 +145,89 @@ CopyField( return MaxLength; } +static +ULONG +CopyFieldTruncate( + IN PUCHAR Name, + IN PCHAR Buffer, + IN ULONG MaxLength) +{ + ULONG Index; + + for (Index = 0; Index < MaxLength; Index++) + { + if (Name[Index] == '\0') + { + break; + } + else if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',') + { + // convert to underscore + Buffer[Index] = ' '; + } + else + { + // just copy character + Buffer[Index] = Name[Index]; + } + } + + return Index; +} + NTSTATUS USBSTOR_PdoHandleQueryDeviceText( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { + PPDO_DEVICE_EXTENSION DeviceExtension; PIO_STACK_LOCATION IoStack; - LPWSTR Buffer; - static WCHAR DeviceText[] = L"USB Mass Storage Device"; + CHAR LocalBuffer[26]; + UINT32 Offset = 0; + PINQUIRYDATA InquiryData; + ANSI_STRING AnsiString; + UNICODE_STRING DeviceDescription; IoStack = IoGetCurrentIrpStackLocation(Irp); - if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription) - { - DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextDescription\n"); + DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(DeviceExtension->InquiryData); + InquiryData = DeviceExtension->InquiryData; - Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText)); - if (!Buffer) + switch (IoStack->Parameters.QueryDeviceText.DeviceTextType) + { + case DeviceTextDescription: + case DeviceTextLocationInformation: { - Irp->IoStatus.Information = 0; - return STATUS_INSUFFICIENT_RESOURCES; - } + DPRINT("USBSTOR_PdoHandleQueryDeviceText\n"); - wcscpy(Buffer, DeviceText); + Offset += CopyFieldTruncate(InquiryData->VendorId, &LocalBuffer[Offset], sizeof(InquiryData->VendorId)); + LocalBuffer[Offset++] = ' '; + Offset += CopyFieldTruncate(InquiryData->ProductId, &LocalBuffer[Offset], sizeof(InquiryData->ProductId)); + LocalBuffer[Offset++] = '\0'; - Irp->IoStatus.Information = (ULONG_PTR)Buffer; - return STATUS_SUCCESS; - } - else - { - DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextLocationInformation\n"); + RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer); + + DeviceDescription.Length = 0; + DeviceDescription.MaximumLength = (USHORT)(Offset * sizeof(WCHAR)); + DeviceDescription.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceDescription.MaximumLength); + if (!DeviceDescription.Buffer) + { + Irp->IoStatus.Information = 0; + return STATUS_INSUFFICIENT_RESOURCES; + } - Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText)); - if (!Buffer) + RtlAnsiStringToUnicodeString(&DeviceDescription, &AnsiString, FALSE); + + Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer; + return STATUS_SUCCESS; + } + default: { Irp->IoStatus.Information = 0; - return STATUS_INSUFFICIENT_RESOURCES; + return Irp->IoStatus.Status; } - - wcscpy(Buffer, DeviceText); - - Irp->IoStatus.Information = (ULONG_PTR)Buffer; - return STATUS_SUCCESS; } - } NTSTATUS
5 years, 5 months
1
0
0
0
[reactos] 14/17: [USBSTOR] Do not leak fields of DeviceExtensions upon device removal
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=40b25634ffcfd13ce98c3…
commit 40b25634ffcfd13ce98c338cdc272f1aa1d4bbf2 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Tue Jun 11 01:31:44 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Do not leak fields of DeviceExtensions upon device removal --- drivers/usb/usbstor/fdo.c | 19 +++++++++++++++++++ drivers/usb/usbstor/pdo.c | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c index 1c1949533f9..6879b4efe8f 100644 --- a/drivers/usb/usbstor/fdo.c +++ b/drivers/usb/usbstor/fdo.c @@ -108,8 +108,27 @@ USBSTOR_FdoHandleRemoveDevice( } } + // Freeing everything in DeviceExtension + ASSERT( + DeviceExtension->DeviceDescriptor && + DeviceExtension->ConfigurationDescriptor && + DeviceExtension->InterfaceInformation && + DeviceExtension->ResetDeviceWorkItem + ); + + ExFreePoolWithTag(DeviceExtension->DeviceDescriptor, USB_STOR_TAG); + ExFreePoolWithTag(DeviceExtension->ConfigurationDescriptor, USB_STOR_TAG); + ExFreePoolWithTag(DeviceExtension->InterfaceInformation, USB_STOR_TAG); + IoFreeWorkItem(DeviceExtension->ResetDeviceWorkItem); + + if (DeviceExtension->SerialNumber) + { + ExFreePoolWithTag(DeviceExtension->SerialNumber, USB_STOR_TAG); + } + // Send the IRP down the stack IoSkipCurrentIrpStackLocation(Irp); + Irp->IoStatus.Status = STATUS_SUCCESS; Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); // Detach from the device stack diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index b41cb9345d1..9a84483b701 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -575,6 +575,10 @@ USBSTOR_PdoHandlePnp( bDelete = FALSE; } + // clean up the device extension + ASSERT(DeviceExtension->InquiryData); + ExFreePoolWithTag(DeviceExtension->InquiryData, USB_STOR_TAG); + Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); @@ -658,7 +662,7 @@ USBSTOR_SyncCompletionRoutine( /* * @name USBSTOR_SendInternalCdb -* +* * Issues an internal SCSI request to device. * The request is sent in a synchronous way. */
5 years, 5 months
1
0
0
0
[reactos] 13/17: [DISK] Disable IsFloppyDevice check. It wrongly marks USB flash drives as a floppy device
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fa530aee92e417e4330c6…
commit fa530aee92e417e4330c604bbe6ea2e9100709dc Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sun Apr 28 00:44:55 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [DISK] Disable IsFloppyDevice check. It wrongly marks USB flash drives as a floppy device --- drivers/storage/class/disk/disk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/storage/class/disk/disk.c b/drivers/storage/class/disk/disk.c index b91e88e04de..580c89998d9 100644 --- a/drivers/storage/class/disk/disk.c +++ b/drivers/storage/class/disk/disk.c @@ -969,12 +969,14 @@ Return Value: // IsFloppyDevice also checks for write cache enabled. // +#if 0 if (IsFloppyDevice(deviceObject) && deviceObject->Characteristics & FILE_REMOVABLE_MEDIA && (((PINQUIRYDATA)LunInfo->InquiryData)->DeviceType == DIRECT_ACCESS_DEVICE)) { status = STATUS_NO_SUCH_DEVICE; goto CreateDiskDeviceObjectsExit; } +#endif DisableWriteCache(deviceObject,LunInfo);
5 years, 5 months
1
0
0
0
[reactos] 12/17: [USBSTOR] Weaken the type checks of a device. This adds usb-cdrom support to usbstor.sys
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b7de5870e6e6a845b4b45…
commit b7de5870e6e6a845b4b452d0c6fb105c00392ca5 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sat Apr 27 23:29:45 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Weaken the type checks of a device. This adds usb-cdrom support to usbstor.sys --- drivers/usb/usbstor/fdo.c | 4 ++-- drivers/usb/usbstor/pdo.c | 2 +- media/inf/usbstor.inf | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c index 16e00da1964..1c1949533f9 100644 --- a/drivers/usb/usbstor/fdo.c +++ b/drivers/usb/usbstor/fdo.c @@ -177,12 +177,12 @@ USBSTOR_FdoHandleStartDevice( return STATUS_NOT_SUPPORTED; } - if (InterfaceDesc->bInterfaceSubClass != 0x06) + if (InterfaceDesc->bInterfaceSubClass == 0x04) // UFI subclass { // FIXME: need to pad CDBs to 12 byte // mode select commands must be translated from 1AH / 15h to 5AH / 55h DPRINT1("[USBSTOR] Error: need to pad CDBs\n"); - return STATUS_NOT_IMPLEMENTED; + return STATUS_NOT_SUPPORTED; } // now select an interface diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index 93caca4e1ef..b41cb9345d1 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -897,7 +897,7 @@ USBSTOR_CreatePDO( return Status; } - if (PDODeviceExtension->InquiryData->DeviceType == DIRECT_ACCESS_DEVICE) + if (PDODeviceExtension->InquiryData->DeviceType == DIRECT_ACCESS_DEVICE || PDODeviceExtension->InquiryData->DeviceType == READ_ONLY_DIRECT_ACCESS_DEVICE) { PDODeviceExtension->IsFloppy = FALSE; // TODO: implement the actual check } diff --git a/media/inf/usbstor.inf b/media/inf/usbstor.inf index a7fd9ff3651..87a80f63cb4 100644 --- a/media/inf/usbstor.inf +++ b/media/inf/usbstor.inf @@ -18,7 +18,9 @@ DefaultDestDir = 12 %GenericMfg% = GenericMfg [GenericMfg] -%GenericBulkOnlyTransport.DeviceDesc% = USBBulkOnly_Inst,USB\Class_08&SubClass_06&Prot_50 +%GenericBulkOnlyTransport.DeviceDesc% = USBBulkOnly_Inst,USB\Class_08&SubClass_06&Prot_50 ; SCSI devices +; usbstor.sys supports usb-cdroms but cdrom.sys from ReactOS does not like it +;%GenericBulkOnlyTransport.DeviceDesc% = USBBulkOnly_Inst,USB\Class_08&SubClass_02&Prot_50 ; SFF-8020i (ATAPI) ;-------------------------- USB STORAGE DRIVER --------------------------
5 years, 5 months
1
0
0
0
[reactos] 11/17: [USBSTOR] Refactor device reset and pipe reset code. Return correct status codes from completion routines. Reject requests while the device is being reset
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7bb93db3728d721556f17…
commit 7bb93db3728d721556f17f350d8813f97fd7cea7 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sat Apr 13 15:48:14 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Refactor device reset and pipe reset code. Return correct status codes from completion routines. Reject requests while the device is being reset --- drivers/usb/usbstor/error.c | 146 ++++++++++++++++++++---------------------- drivers/usb/usbstor/fdo.c | 12 ++++ drivers/usb/usbstor/queue.c | 21 +++--- drivers/usb/usbstor/scsi.c | 129 +++++++++++++++---------------------- drivers/usb/usbstor/usbstor.c | 2 + drivers/usb/usbstor/usbstor.h | 35 ++++++---- 6 files changed, 168 insertions(+), 177 deletions(-) diff --git a/drivers/usb/usbstor/error.c b/drivers/usb/usbstor/error.c index 571c89dab42..3964b2c7b4d 100644 --- a/drivers/usb/usbstor/error.c +++ b/drivers/usb/usbstor/error.c @@ -5,6 +5,7 @@ * COPYRIGHT: 2005-2006 James Tabor * 2011-2012 Michael Martin (michael.martin(a)reactos.org) * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) + * 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) */ #include "usbstor.h" @@ -69,104 +70,97 @@ USBSTOR_ResetPipeWithHandle( return Status; } -NTSTATUS -USBSTOR_HandleTransferError( - PDEVICE_OBJECT DeviceObject, - PIRP_CONTEXT Context) +VOID +NTAPI +USBSTOR_ResetPipeWorkItemRoutine( + IN PDEVICE_OBJECT FdoDevice, + IN PVOID Ctx) { - PPDO_DEVICE_EXTENSION PDODeviceExtension; - NTSTATUS Status = STATUS_SUCCESS; - PIO_STACK_LOCATION Stack; - PSCSI_REQUEST_BLOCK Request; - PCDB pCDB; + NTSTATUS Status; + PIRP_CONTEXT Context = (PIRP_CONTEXT)Ctx; + PFDO_DEVICE_EXTENSION FDODeviceExtension = (PFDO_DEVICE_EXTENSION)FdoDevice->DeviceExtension; - ASSERT(Context); - ASSERT(Context->Irp); + // clear stall on the corresponding pipe + Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, Context->Urb.UrbBulkOrInterruptTransfer.PipeHandle); + DPRINT1("USBSTOR_ResetPipeWithHandle Status %x\n", Status); - // first perform a mass storage reset step 1 in 5.3.4 USB Mass Storage Bulk Only Specification - Status = USBSTOR_ResetDevice(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension); - if (NT_SUCCESS(Status)) - { - // step 2 reset bulk in pipe section 5.3.4 - Status = USBSTOR_ResetPipeWithHandle(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle); - if (NT_SUCCESS(Status)) - { - // finally reset bulk out pipe - Status = USBSTOR_ResetPipeWithHandle(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle); - } - } + // now resend the csw as the stall got cleared + USBSTOR_SendCSWRequest(Context, Context->Irp); +} - Stack = IoGetCurrentIrpStackLocation(Context->Irp); - ASSERT(Stack->DeviceObject); - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)Stack->DeviceObject->DeviceExtension; +VOID +NTAPI +USBSTOR_ResetDeviceWorkItemRoutine( + IN PDEVICE_OBJECT FdoDevice, + IN PVOID Context) +{ + PFDO_DEVICE_EXTENSION FDODeviceExtension; + UINT32 ix; + NTSTATUS Status; + KIRQL OldIrql; - Request = (PSCSI_REQUEST_BLOCK)Stack->Parameters.Others.Argument1; - ASSERT(Request); + DPRINT("USBSTOR_ResetDeviceWorkItemRoutine\n"); - // obtain request type - pCDB = (PCDB)Request->Cdb; - ASSERT(pCDB); + FDODeviceExtension = FdoDevice->DeviceExtension; - if (!NT_SUCCESS(Status)) + for (ix = 0; ix < 3; ++ix) { - // Complete the master IRP - Context->Irp->IoStatus.Status = Status; - Context->Irp->IoStatus.Information = 0; - USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Context->Irp); - IoCompleteRequest(Context->Irp, IO_NO_INCREMENT); - - // Start the next request - USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); - - // srb handling finished - Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE; - - // clear timer srb - Context->FDODeviceExtension->LastTimerActiveSrb = NULL; + // first perform a mass storage reset step 1 in 5.3.4 USB Mass Storage Bulk Only Specification + Status = USBSTOR_ResetDevice(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension); + if (NT_SUCCESS(Status)) + { + // step 2 reset bulk in pipe section 5.3.4 + Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle); + if (NT_SUCCESS(Status)) + { + // finally reset bulk out pipe + Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle); + if (NT_SUCCESS(Status)) + { + break; + } + } + } } - FreeItem(Context); + KeAcquireSpinLock(&FDODeviceExtension->CommonLock, &OldIrql); + FDODeviceExtension->Flags &= ~USBSTOR_FDO_FLAGS_DEVICE_RESETTING; + KeReleaseSpinLock(&FDODeviceExtension->CommonLock, OldIrql); - DPRINT1("USBSTOR_HandleTransferError returning with Status %x\n", Status); - return Status; + USBSTOR_QueueNextRequest(FdoDevice); } VOID NTAPI -USBSTOR_ResetHandlerWorkItemRoutine( - PVOID Context) +USBSTOR_QueueResetPipe( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP_CONTEXT Context) { - NTSTATUS Status; - PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context; + DPRINT("USBSTOR_QueueResetPipe\n"); - // clear stall on BulkIn pipe - Status = USBSTOR_ResetPipeWithHandle(WorkItemData->Context->FDODeviceExtension->LowerDeviceObject, WorkItemData->Context->FDODeviceExtension->InterfaceInformation->Pipes[WorkItemData->Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle); - DPRINT1("USBSTOR_ResetPipeWithHandle Status %x\n", Status); - - // now resend the csw as the stall got cleared - USBSTOR_SendCSWRequest(WorkItemData->Context, WorkItemData->Irp); + IoQueueWorkItem(FDODeviceExtension->ResetDeviceWorkItem, + USBSTOR_ResetPipeWorkItemRoutine, + CriticalWorkQueue, + Context); } VOID NTAPI -ErrorHandlerWorkItemRoutine( - PVOID Context) +USBSTOR_QueueResetDevice( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension) { - PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context; + KIRQL OldIrql; - if (WorkItemData->Context->ErrorIndex == 2) - { - // reset device - USBSTOR_HandleTransferError(WorkItemData->DeviceObject, WorkItemData->Context); - } - else - { - // clear stall - USBSTOR_ResetHandlerWorkItemRoutine(WorkItemData); - } + DPRINT("USBSTOR_QueueResetDevice\n"); - // Free Work Item Data - ExFreePoolWithTag(WorkItemData, USB_STOR_TAG); + KeAcquireSpinLock(&FDODeviceExtension->CommonLock, &OldIrql); + FDODeviceExtension->Flags |= USBSTOR_FDO_FLAGS_DEVICE_RESETTING; + KeReleaseSpinLock(&FDODeviceExtension->CommonLock, OldIrql); + + IoQueueWorkItem(FDODeviceExtension->ResetDeviceWorkItem, + USBSTOR_ResetDeviceWorkItemRoutine, + CriticalWorkQueue, + NULL); } VOID @@ -219,12 +213,12 @@ USBSTOR_TimerRoutine( FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Context; DPRINT1("[USBSTOR] TimerRoutine entered\n"); - DPRINT1("[USBSTOR] ActiveSrb %p ResetInProgress %x LastTimerActiveSrb %p\n", FDODeviceExtension->ActiveSrb, FDODeviceExtension->ResetInProgress, FDODeviceExtension->LastTimerActiveSrb); + // DPRINT1("[USBSTOR] ActiveSrb %p ResetInProgress %x LastTimerActiveSrb %p\n", FDODeviceExtension->ActiveSrb, FDODeviceExtension->ResetInProgress, FDODeviceExtension->LastTimerActiveSrb); KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock); // is there an active srb and no global reset is in progress - if (FDODeviceExtension->ActiveSrb && FDODeviceExtension->ResetInProgress == FALSE && FDODeviceExtension->TimerWorkQueueEnabled) + if (FDODeviceExtension->ActiveSrb && /* FDODeviceExtension->ResetInProgress == FALSE && */ FDODeviceExtension->TimerWorkQueueEnabled) { if (FDODeviceExtension->LastTimerActiveSrb != NULL && FDODeviceExtension->LastTimerActiveSrb == FDODeviceExtension->ActiveSrb) { diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c index 3dff594dccb..16e00da1964 100644 --- a/drivers/usb/usbstor/fdo.c +++ b/drivers/usb/usbstor/fdo.c @@ -129,6 +129,7 @@ USBSTOR_FdoHandleStartDevice( PUSB_INTERFACE_DESCRIPTOR InterfaceDesc; NTSTATUS Status; UCHAR Index = 0; + PIO_WORKITEM WorkItem; // forward irp to lower device Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp); @@ -138,6 +139,17 @@ USBSTOR_FdoHandleStartDevice( return Status; } + if (!DeviceExtension->ResetDeviceWorkItem) + { + WorkItem = IoAllocateWorkItem(DeviceObject); + DeviceExtension->ResetDeviceWorkItem = WorkItem; + + if (!WorkItem) + { + return STATUS_INSUFFICIENT_RESOURCES; + } + } + // initialize irp queue USBSTOR_QueueInitialize(DeviceExtension); diff --git a/drivers/usb/usbstor/queue.c b/drivers/usb/usbstor/queue.c index 8babc987912..ba36022f4ba 100644 --- a/drivers/usb/usbstor/queue.c +++ b/drivers/usb/usbstor/queue.c @@ -103,7 +103,7 @@ USBSTOR_QueueAddIrp( KeClearEvent(&FDODeviceExtension->NoPendingRequests); // check if queue is freezed - IrpListFreeze = FDODeviceExtension->IrpListFreeze; + IrpListFreeze = BooleanFlagOn(FDODeviceExtension->Flags, USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE); KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); @@ -230,7 +230,7 @@ USBSTOR_QueueNextRequest( // check first if there's already a request pending or the queue is frozen if (FDODeviceExtension->ActiveSrb != NULL || - FDODeviceExtension->IrpListFreeze) + BooleanFlagOn(FDODeviceExtension->Flags, USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE)) { // no work to do yet return; @@ -274,7 +274,7 @@ USBSTOR_QueueRelease( KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); // clear freezed status - FDODeviceExtension->IrpListFreeze = FALSE; + FDODeviceExtension->Flags &= ~USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE; KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); @@ -302,6 +302,7 @@ USBSTOR_StartIo( PIRP Irp) { PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK Request; PFDO_DEVICE_EXTENSION FDODeviceExtension; PPDO_DEVICE_EXTENSION PDODeviceExtension; KIRQL OldLevel; @@ -332,26 +333,26 @@ USBSTOR_StartIo( IoReleaseCancelSpinLock(OldLevel); - KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - - ResetInProgress = FDODeviceExtension->ResetInProgress; - ASSERT(ResetInProgress == FALSE); - - KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); + KeAcquireSpinLock(&FDODeviceExtension->CommonLock, &OldLevel); + ResetInProgress = BooleanFlagOn(FDODeviceExtension->Flags, USBSTOR_FDO_FLAGS_DEVICE_RESETTING); + KeReleaseSpinLock(&FDODeviceExtension->CommonLock, OldLevel); IoStack = IoGetCurrentIrpStackLocation(Irp); PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; + Request = IoStack->Parameters.Scsi.Srb; ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); - // TODO: this condition is always false if (ResetInProgress) { // hard reset is in progress + Request->SrbStatus = SRB_STATUS_NO_DEVICE; + Request->DataTransferLength = 0; Irp->IoStatus.Information = 0; Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST; USBSTOR_QueueTerminateRequest(DeviceObject, Irp); IoCompleteRequest(Irp, IO_NO_INCREMENT); + USBSTOR_QueueNextRequest(DeviceObject); return; } diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 002b8f29768..f917e0345e0 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -116,40 +116,6 @@ USBSTOR_IsCSWValid( return TRUE; } -NTSTATUS -USBSTOR_QueueWorkItem( - PIRP_CONTEXT Context, - PIRP Irp) -{ - PERRORHANDLER_WORKITEM_DATA ErrorHandlerWorkItemData; - - ErrorHandlerWorkItemData = ExAllocatePoolWithTag(NonPagedPool, sizeof(ERRORHANDLER_WORKITEM_DATA), USB_STOR_TAG); - if (!ErrorHandlerWorkItemData) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - - // error handling started - Context->FDODeviceExtension->SrbErrorHandlingActive = TRUE; - - // srb error handling finished - Context->FDODeviceExtension->TimerWorkQueueEnabled = FALSE; - - // Initialize and queue the work item to handle the error - ExInitializeWorkItem(&ErrorHandlerWorkItemData->WorkQueueItem, - ErrorHandlerWorkItemRoutine, - ErrorHandlerWorkItemData); - - ErrorHandlerWorkItemData->DeviceObject = Context->FDODeviceExtension->FunctionalDeviceObject; - ErrorHandlerWorkItemData->Context = Context; - ErrorHandlerWorkItemData->Irp = Irp; - ErrorHandlerWorkItemData->DeviceObject = Context->FDODeviceExtension->FunctionalDeviceObject; - - DPRINT1("Queuing WorkItemROutine\n"); - ExQueueWorkItem(&ErrorHandlerWorkItemData->WorkQueueItem, DelayedWorkQueue); - return STATUS_MORE_PROCESSING_REQUIRED; -} - static NTSTATUS USBSTOR_IssueRequestSense( @@ -172,12 +138,17 @@ USBSTOR_CSWCompletionRoutine( PFDO_DEVICE_EXTENSION FDODeviceExtension; PSCSI_REQUEST_BLOCK Request; PUFI_CAPACITY_RESPONSE Response; - NTSTATUS Status; Context = (PIRP_CONTEXT)Ctx; DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); + IoStack = IoGetCurrentIrpStackLocation(Irp); + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; + FDODeviceExtension = Context->FDODeviceExtension; + Request = IoStack->Parameters.Scsi.Srb; + ASSERT(Request); + // first check for Irp errors if (!NT_SUCCESS(Irp->IoStatus.Status)) { @@ -188,9 +159,7 @@ USBSTOR_CSWCompletionRoutine( ++Context->StallRetryCount; // clear stall and resend cbw - Context->ErrorIndex = 1; - Status = USBSTOR_QueueWorkItem(Context, Irp); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + USBSTOR_QueueResetPipe(FDODeviceExtension, Context); return STATUS_MORE_PROCESSING_REQUIRED; } @@ -200,29 +169,15 @@ USBSTOR_CSWCompletionRoutine( DPRINT1("USBSTOR_CSWCompletionRoutine: Urb.Hdr.Status - %x\n", Context->Urb.UrbHeader.Status); } - // perform reset recovery - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; + goto ResetRecovery; } // now check the CSW packet validity if (!USBSTOR_IsCSWValid(Context) || Context->csw.Status == CSW_STATUS_PHASE_ERROR) { - // perform reset recovery - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; + goto ResetRecovery; } - IoStack = IoGetCurrentIrpStackLocation(Irp); - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; - FDODeviceExtension = Context->FDODeviceExtension; - Request = IoStack->Parameters.Scsi.Srb; - ASSERT(Request); - // finally check for CSW errors if (Context->csw.Status == CSW_STATUS_COMMAND_PASSED) { @@ -247,7 +202,7 @@ USBSTOR_CSWCompletionRoutine( PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); } - Status = USBSTOR_SrbStatusToNtStatus(Request); + Irp->IoStatus.Status = USBSTOR_SrbStatusToNtStatus(Request); } else if (Context->csw.Status == CSW_STATUS_COMMAND_FAILED) { @@ -272,10 +227,9 @@ USBSTOR_CSWCompletionRoutine( return STATUS_MORE_PROCESSING_REQUIRED; } - Status = STATUS_IO_DEVICE_ERROR; + Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR; } - Irp->IoStatus.Status = Status; Irp->IoStatus.Information = Request->DataTransferLength; // terminate current request @@ -283,7 +237,21 @@ USBSTOR_CSWCompletionRoutine( USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); ExFreePoolWithTag(Context, USB_STOR_TAG); - return Status; + return STATUS_CONTINUE_COMPLETION; + +ResetRecovery: + + Request = FDODeviceExtension->ActiveSrb; + IoStack->Parameters.Scsi.Srb = Request; + Irp->IoStatus.Information = 0; + Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR; + Request->SrbStatus = SRB_STATUS_BUS_RESET; + + USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); + USBSTOR_QueueResetDevice(FDODeviceExtension); + + ExFreePoolWithTag(Context, USB_STOR_TAG); + return STATUS_CONTINUE_COMPLETION; } NTSTATUS @@ -312,15 +280,16 @@ USBSTOR_DataCompletionRoutine( PVOID Ctx) { PIRP_CONTEXT Context; - NTSTATUS Status; PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; + PPDO_DEVICE_EXTENSION PDODeviceExtension; DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); Context = (PIRP_CONTEXT)Ctx; IoStack = IoGetCurrentIrpStackLocation(Irp); Request = IoStack->Parameters.Scsi.Srb; + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; // for Sense Request a partial MDL was already freed (if existed) if (Request == Context->FDODeviceExtension->ActiveSrb && @@ -351,16 +320,19 @@ USBSTOR_DataCompletionRoutine( Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength; // clear stall and resend cbw - Context->ErrorIndex = 1; - Status = USBSTOR_QueueWorkItem(Context, Irp); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + USBSTOR_QueueResetPipe(Context->FDODeviceExtension, Context); } else { - // perform reset recovery - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + Irp->IoStatus.Information = 0; + Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR; + Request->SrbStatus = SRB_STATUS_BUS_RESET; + + USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); + USBSTOR_QueueResetDevice(Context->FDODeviceExtension); + + ExFreePoolWithTag(Context, USB_STOR_TAG); + return STATUS_CONTINUE_COMPLETION; } return STATUS_MORE_PROCESSING_REQUIRED; @@ -378,17 +350,18 @@ USBSTOR_CBWCompletionRoutine( PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; + PPDO_DEVICE_EXTENSION PDODeviceExtension; USBD_PIPE_HANDLE PipeHandle; ULONG TransferFlags; PMDL Mdl = NULL; PVOID TransferBuffer = NULL; - NTSTATUS Status; DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); Context = (PIRP_CONTEXT)Ctx; IoStack = IoGetCurrentIrpStackLocation(Irp); Request = IoStack->Parameters.Scsi.Srb; + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; if (!NT_SUCCESS(Irp->IoStatus.Status)) { @@ -455,13 +428,8 @@ USBSTOR_CBWCompletionRoutine( } else { + ASSERT(Request->DataBuffer); TransferBuffer = Request->DataBuffer; - - if (!Request->DataBuffer) - { - DPRINT("USBSTOR_CBWCompletionRoutine: Request->DataBuffer == NULL!\n"); - return STATUS_INVALID_PARAMETER; - } } USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension, @@ -477,10 +445,17 @@ USBSTOR_CBWCompletionRoutine( return STATUS_MORE_PROCESSING_REQUIRED; ResetRecovery: - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; + Request = Context->FDODeviceExtension->ActiveSrb; + IoStack->Parameters.Scsi.Srb = Request; + Irp->IoStatus.Information = 0; + Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR; + Request->SrbStatus = SRB_STATUS_BUS_RESET; + + USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); + USBSTOR_QueueResetDevice(Context->FDODeviceExtension); + + ExFreePoolWithTag(Context, USB_STOR_TAG); + return STATUS_CONTINUE_COMPLETION; } VOID diff --git a/drivers/usb/usbstor/usbstor.c b/drivers/usb/usbstor/usbstor.c index 0076c519d38..99392f7e092 100644 --- a/drivers/usb/usbstor/usbstor.c +++ b/drivers/usb/usbstor/usbstor.c @@ -40,6 +40,8 @@ USBSTOR_AddDevice( DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject; DeviceExtension->LowerDeviceObject = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject); + KeInitializeSpinLock(&DeviceExtension->CommonLock); + IoInitializeTimer(DeviceObject, USBSTOR_TimerRoutine, (PVOID)DeviceExtension); // did attaching fail diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index d2a72eccc96..9fc3101ef2c 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -25,6 +25,10 @@ ((((unsigned long)(n) & 0xFF0000)) >> 8) | \ ((((unsigned long)(n) & 0xFF000000)) >> 24)) +#ifndef BooleanFlagOn +#define BooleanFlagOn(Flags, SingleFlag) ((BOOLEAN)((((Flags) & (SingleFlag)) != 0))) +#endif + #define USB_RECOVERABLE_ERRORS (USBD_STATUS_STALL_PID | USBD_STATUS_DEV_NOT_RESPONDING \ | USBD_STATUS_ENDPOINT_HALTED | USBD_STATUS_NO_BANDWIDTH) @@ -34,6 +38,9 @@ typedef struct __COMMON_DEVICE_EXTENSION__ }USBSTOR_COMMON_DEVICE_EXTENSION, *PUSBSTOR_COMMON_DEVICE_EXTENSION; +#define USBSTOR_FDO_FLAGS_DEVICE_RESETTING 0x00000001 // hard reset is in progress +#define USBSTOR_FDO_FLAGS_IRP_LIST_FREEZE 0x00000002 // the irp list is freezed + typedef struct { USBSTOR_COMMON_DEVICE_EXTENSION Common; // common device extension @@ -53,8 +60,6 @@ typedef struct PDEVICE_OBJECT ChildPDO[16]; // max 16 child pdo devices KSPIN_LOCK IrpListLock; // irp list lock LIST_ENTRY IrpListHead; // irp list head - BOOLEAN IrpListFreeze; // if true the irp list is freezed - BOOLEAN ResetInProgress; // if hard reset is in progress ULONG IrpPendingCount; // count of irp pending PSCSI_REQUEST_BLOCK ActiveSrb; // stores the current active SRB KEVENT NoPendingRequests; // set if no pending or in progress requests @@ -62,6 +67,9 @@ typedef struct ULONG SrbErrorHandlingActive; // error handling of srb is activated ULONG TimerWorkQueueEnabled; // timer work queue enabled ULONG InstanceCount; // pdo instance count + KSPIN_LOCK CommonLock; + PIO_WORKITEM ResetDeviceWorkItem; + ULONG Flags; }FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; typedef struct @@ -461,18 +469,6 @@ VOID USBSTOR_QueueInitialize( PFDO_DEVICE_EXTENSION FDODeviceExtension); -VOID -NTAPI -ErrorHandlerWorkItemRoutine( - PVOID Context); - -VOID -NTAPI -ResetHandlerWorkItemRoutine( - PVOID Context); - - - VOID USBSTOR_QueueNextRequest( IN PDEVICE_OBJECT DeviceObject); @@ -500,4 +496,15 @@ USBSTOR_TimerRoutine( PDEVICE_OBJECT DeviceObject, PVOID Context); +VOID +NTAPI +USBSTOR_QueueResetPipe( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP_CONTEXT Context); + +VOID +NTAPI +USBSTOR_QueueResetDevice( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension); + #endif /* _USBSTOR_H_ */
5 years, 5 months
1
0
0
0
[reactos] 10/17: [USBSTOR] Do not try to retry a failed request 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)
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=aaa90f698680fb51d27dc…
commit aaa90f698680fb51d27dc870fbe214ffd982bcde Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Wed Apr 10 03:22:03 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Do not try to retry a failed request 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 | 18 +----------------- drivers/usb/usbstor/queue.c | 2 +- drivers/usb/usbstor/scsi.c | 11 +++++------ drivers/usb/usbstor/usbstor.h | 5 ++--- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/drivers/usb/usbstor/error.c b/drivers/usb/usbstor/error.c index 93090327650..571c89dab42 100644 --- a/drivers/usb/usbstor/error.c +++ b/drivers/usb/usbstor/error.c @@ -107,7 +107,7 @@ USBSTOR_HandleTransferError( 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; @@ -124,22 +124,6 @@ USBSTOR_HandleTransferError( // 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); diff --git a/drivers/usb/usbstor/queue.c b/drivers/usb/usbstor/queue.c index f4dbe5c63d9..8babc987912 100644 --- a/drivers/usb/usbstor/queue.c +++ b/drivers/usb/usbstor/queue.c @@ -355,7 +355,7 @@ USBSTOR_StartIo( return; } - USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp, 0); + USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp); // FIXME: handle error } diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 05ef1c925c8..002b8f29768 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -183,9 +183,9 @@ USBSTOR_CSWCompletionRoutine( { 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; @@ -345,7 +345,7 @@ USBSTOR_DataCompletionRoutine( } 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; @@ -527,7 +527,7 @@ USBSTOR_SendCBWRequest( // initialize rest of context Context->Irp = Irp; Context->FDODeviceExtension = FDODeviceExtension; - Context->RetryCount = 0; + Context->StallRetryCount = 0; return USBSTOR_IssueBulkOrInterruptRequest( FDODeviceExtension, @@ -586,8 +586,7 @@ USBSTOR_IssueRequestSense( NTSTATUS USBSTOR_HandleExecuteSCSI( IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) + IN PIRP Irp) { PCDB pCDB; NTSTATUS Status; diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 25066cc1de7..d2a72eccc96 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -286,7 +286,7 @@ typedef struct 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; @@ -406,8 +406,7 @@ USBSTOR_GetPipeHandles( NTSTATUS USBSTOR_HandleExecuteSCSI( IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount); + IN PIRP Irp); NTSTATUS USBSTOR_SendCSWRequest(
5 years, 5 months
1
0
0
0
[reactos] 09/17: [USBSTOR] Issue a SCSI Request Sense after receiving a CSW with failed status. CORE-15884 Based on Vadim Galyant's patches to usbstor
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c7ed299aaa35d746ac167…
commit c7ed299aaa35d746ac1677144341150d5e79e373 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Mon Apr 1 03:03:40 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Issue a SCSI Request Sense after receiving a CSW with failed status. CORE-15884 Based on Vadim Galyant's patches to usbstor --- drivers/usb/usbstor/scsi.c | 91 ++++++++++++++++++++++++++++++++++++++++--- drivers/usb/usbstor/usbstor.h | 1 + 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 71dafea35cf..05ef1c925c8 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -150,6 +150,13 @@ USBSTOR_QueueWorkItem( return STATUS_MORE_PROCESSING_REQUIRED; } +static +NTSTATUS +USBSTOR_IssueRequestSense( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP Irp, + IN PIRP_CONTEXT Context); + IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine; NTSTATUS @@ -162,6 +169,7 @@ USBSTOR_CSWCompletionRoutine( PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; PPDO_DEVICE_EXTENSION PDODeviceExtension; + PFDO_DEVICE_EXTENSION FDODeviceExtension; PSCSI_REQUEST_BLOCK Request; PUFI_CAPACITY_RESPONSE Response; NTSTATUS Status; @@ -211,12 +219,23 @@ USBSTOR_CSWCompletionRoutine( IoStack = IoGetCurrentIrpStackLocation(Irp); PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; + FDODeviceExtension = Context->FDODeviceExtension; Request = IoStack->Parameters.Scsi.Srb; ASSERT(Request); // finally check for CSW errors if (Context->csw.Status == CSW_STATUS_COMMAND_PASSED) { + // should happen only when a sense request was sent + if (Request != FDODeviceExtension->ActiveSrb) + { + ASSERT(IoStack->Parameters.Scsi.Srb == &Context->SenseSrb); + FDODeviceExtension->ActiveSrb->SenseInfoBufferLength = Request->DataTransferLength; + Request = FDODeviceExtension->ActiveSrb; + IoStack->Parameters.Scsi.Srb = Request; + Request->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID; + } + // read capacity needs special work if (Request->Cdb[0] == SCSIOP_READ_CAPACITY) { @@ -235,7 +254,7 @@ USBSTOR_CSWCompletionRoutine( // the command is correct but with failed status - issue request sense DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n"); - ASSERT(Context->FDODeviceExtension->ActiveSrb == Request); + ASSERT(FDODeviceExtension->ActiveSrb == Request); // setting a generic error status, additional information // should be read by higher-level driver from SenseInfoBuffer @@ -249,7 +268,8 @@ USBSTOR_CSWCompletionRoutine( Request->SenseInfoBufferLength && Request->SenseInfoBuffer) { - // TODO: issue request sense + USBSTOR_IssueRequestSense(FDODeviceExtension, Irp, Context); + return STATUS_MORE_PROCESSING_REQUIRED; } Status = STATUS_IO_DEVICE_ERROR; @@ -302,7 +322,9 @@ USBSTOR_DataCompletionRoutine( IoStack = IoGetCurrentIrpStackLocation(Irp); Request = IoStack->Parameters.Scsi.Srb; - if (Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL != Irp->MdlAddress) + // for Sense Request a partial MDL was already freed (if existed) + if (Request == Context->FDODeviceExtension->ActiveSrb && + Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL != Irp->MdlAddress) { IoFreeMdl(Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL); } @@ -373,8 +395,9 @@ USBSTOR_CBWCompletionRoutine( goto ResetRecovery; } - // a request without the buffer - if (!Irp->MdlAddress) + // a request without the buffer AND not a sense request + // for a sense request we provide just a TransferBuffer, an Mdl will be allocated by usbport (see below) + if (!Irp->MdlAddress && Request == Context->FDODeviceExtension->ActiveSrb) { Request->SrbStatus = SRB_STATUS_SUCCESS; USBSTOR_SendCSWRequest(Context, Irp); @@ -400,6 +423,9 @@ USBSTOR_CBWCompletionRoutine( goto ResetRecovery; } + // if it is not a Sense Request + if (Request == Context->FDODeviceExtension->ActiveSrb) + { if (MmGetMdlVirtualAddress(Irp->MdlAddress) == Request->DataBuffer) { Mdl = Irp->MdlAddress; @@ -423,9 +449,20 @@ USBSTOR_CBWCompletionRoutine( if (!Mdl) { - DPRINT1("USBSTOR_DataTransfer: Mdl - %p\n", Mdl); + DPRINT1("USBSTOR_CBWCompletionRoutine: Mdl - %p\n", Mdl); goto ResetRecovery; } + } + else + { + TransferBuffer = Request->DataBuffer; + + if (!Request->DataBuffer) + { + DPRINT("USBSTOR_CBWCompletionRoutine: Request->DataBuffer == NULL!\n"); + return STATUS_INVALID_PARAMETER; + } + } USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension, Irp, @@ -504,6 +541,48 @@ USBSTOR_SendCBWRequest( Context); } +static +NTSTATUS +USBSTOR_IssueRequestSense( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP Irp, + IN PIRP_CONTEXT Context) +{ + PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK CurrentSrb; + PSCSI_REQUEST_BLOCK SenseSrb; + PCDB pCDB; + + DPRINT("USBSTOR_IssueRequestSense: \n"); + + CurrentSrb = FDODeviceExtension->ActiveSrb; + SenseSrb = &Context->SenseSrb; + IoStack = IoGetCurrentIrpStackLocation(Irp); + IoStack->Parameters.Scsi.Srb = SenseSrb; + + RtlZeroMemory(SenseSrb, sizeof(*SenseSrb)); + + SenseSrb->Function = SRB_FUNCTION_EXECUTE_SCSI; + SenseSrb->Length = sizeof(*SenseSrb); + SenseSrb->CdbLength = CDB6GENERIC_LENGTH; + SenseSrb->SrbFlags = SRB_FLAGS_DATA_IN | + SRB_FLAGS_NO_QUEUE_FREEZE | + SRB_FLAGS_DISABLE_AUTOSENSE; + + ASSERT(CurrentSrb->SenseInfoBufferLength); + ASSERT(CurrentSrb->SenseInfoBuffer); + DPRINT("SenseInfoBuffer %x, SenseInfoBufferLength %x\n", CurrentSrb->SenseInfoBuffer, CurrentSrb->SenseInfoBufferLength); + + SenseSrb->DataTransferLength = CurrentSrb->SenseInfoBufferLength; + SenseSrb->DataBuffer = CurrentSrb->SenseInfoBuffer; + + pCDB = (PCDB)SenseSrb->Cdb; + pCDB->CDB6GENERIC.OperationCode = SCSIOP_REQUEST_SENSE; + pCDB->AsByte[4] = CurrentSrb->SenseInfoBufferLength; + + return USBSTOR_SendCBWRequest(FDODeviceExtension, Irp, Context); +} + NTSTATUS USBSTOR_HandleExecuteSCSI( IN PDEVICE_OBJECT DeviceObject, diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 26be827f8ae..25066cc1de7 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -293,6 +293,7 @@ typedef struct CSW csw; }; URB Urb; + SCSI_REQUEST_BLOCK SenseSrb; } IRP_CONTEXT, *PIRP_CONTEXT; typedef struct _ERRORHANDLER_WORKITEM_DATA
5 years, 5 months
1
0
0
0
[reactos] 08/17: [USBSTOR] Keep CBW and CSW inside an IRP context. Remove obsolete fields from the IRP context structure.
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5046f1b3faf157f2e84f6…
commit 5046f1b3faf157f2e84f655331e04ccbc6019f8e Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Mon Apr 1 02:33:35 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Keep CBW and CSW inside an IRP context. Remove obsolete fields from the IRP context structure. --- drivers/usb/usbstor/error.c | 14 +++--- drivers/usb/usbstor/scsi.c | 103 ++++++++++++++++-------------------------- drivers/usb/usbstor/usbstor.h | 18 +++----- 3 files changed, 53 insertions(+), 82 deletions(-) diff --git a/drivers/usb/usbstor/error.c b/drivers/usb/usbstor/error.c index 3ae8a3bfca4..93090327650 100644 --- a/drivers/usb/usbstor/error.c +++ b/drivers/usb/usbstor/error.c @@ -74,14 +74,13 @@ USBSTOR_HandleTransferError( PDEVICE_OBJECT DeviceObject, PIRP_CONTEXT Context) { + PPDO_DEVICE_EXTENSION PDODeviceExtension; NTSTATUS Status = STATUS_SUCCESS; PIO_STACK_LOCATION Stack; PSCSI_REQUEST_BLOCK Request; PCDB pCDB; ASSERT(Context); - ASSERT(Context->PDODeviceExtension); - ASSERT(Context->PDODeviceExtension->Self); ASSERT(Context->Irp); // first perform a mass storage reset step 1 in 5.3.4 USB Mass Storage Bulk Only Specification @@ -98,6 +97,8 @@ USBSTOR_HandleTransferError( } Stack = IoGetCurrentIrpStackLocation(Context->Irp); + ASSERT(Stack->DeviceObject); + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)Stack->DeviceObject->DeviceExtension; Request = (PSCSI_REQUEST_BLOCK)Stack->Parameters.Others.Argument1; ASSERT(Request); @@ -111,11 +112,11 @@ USBSTOR_HandleTransferError( // Complete the master IRP Context->Irp->IoStatus.Status = Status; Context->Irp->IoStatus.Information = 0; - USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Context->Irp); + USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Context->Irp); IoCompleteRequest(Context->Irp, IO_NO_INCREMENT); // Start the next request - USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject); + USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); // srb handling finished Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE; @@ -125,10 +126,10 @@ USBSTOR_HandleTransferError( } else { - DPRINT1("Retrying Count %lu %p\n", Context->RetryCount, Context->PDODeviceExtension->Self); + DPRINT1("Retrying Count %lu %p\n", Context->RetryCount, Stack->DeviceObject); // re-schedule request - USBSTOR_HandleExecuteSCSI(Context->PDODeviceExtension->Self, Context->Irp, Context->RetryCount + 1); + USBSTOR_HandleExecuteSCSI(Stack->DeviceObject, Context->Irp, Context->RetryCount + 1); // srb error handling finished Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE; @@ -140,7 +141,6 @@ USBSTOR_HandleTransferError( Context->FDODeviceExtension->LastTimerActiveSrb = NULL; } - FreeItem(Context->cbw); FreeItem(Context); DPRINT1("USBSTOR_HandleTransferError returning with Status %x\n", Status); diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 5411468a0a9..71dafea35cf 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -96,41 +96,20 @@ USBSTOR_IssueBulkOrInterruptRequest( return IoCallDriver(FDODeviceExtension->LowerDeviceObject, Irp); } -PIRP_CONTEXT -USBSTOR_AllocateIrpContext() -{ - PIRP_CONTEXT Context; - - Context = (PIRP_CONTEXT)AllocateItem(NonPagedPool, sizeof(IRP_CONTEXT)); - if (!Context) - { - return NULL; - } - - Context->cbw = (PCBW)AllocateItem(NonPagedPool, 512); - if (!Context->cbw) - { - FreeItem(Context); - return NULL; - } - - return Context; -} - static BOOLEAN USBSTOR_IsCSWValid( PIRP_CONTEXT Context) { - if (Context->csw->Signature != CSW_SIGNATURE) + if (Context->csw.Signature != CSW_SIGNATURE) { - DPRINT1("[USBSTOR] Expected Signature %x but got %x\n", CSW_SIGNATURE, Context->csw->Signature); + DPRINT1("[USBSTOR] Expected Signature %x but got %x\n", CSW_SIGNATURE, Context->csw.Signature); return FALSE; } - if (Context->csw->Tag != (ULONG_PTR)Context->csw) + if (Context->csw.Tag != PtrToUlong(&Context->csw)) { - DPRINT1("[USBSTOR] Expected Tag %Ix but got %x\n", (ULONG_PTR)Context->csw, Context->csw->Tag); + DPRINT1("[USBSTOR] Expected Tag %Ix but got %x\n", PtrToUlong(&Context->csw), Context->csw.Tag); return FALSE; } @@ -182,6 +161,7 @@ USBSTOR_CSWCompletionRoutine( { PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; + PPDO_DEVICE_EXTENSION PDODeviceExtension; PSCSI_REQUEST_BLOCK Request; PUFI_CAPACITY_RESPONSE Response; NTSTATUS Status; @@ -220,7 +200,7 @@ USBSTOR_CSWCompletionRoutine( } // now check the CSW packet validity - if (!USBSTOR_IsCSWValid(Context) || Context->csw->Status == CSW_STATUS_PHASE_ERROR) + if (!USBSTOR_IsCSWValid(Context) || Context->csw.Status == CSW_STATUS_PHASE_ERROR) { // perform reset recovery Context->ErrorIndex = 2; @@ -230,26 +210,27 @@ USBSTOR_CSWCompletionRoutine( } IoStack = IoGetCurrentIrpStackLocation(Irp); + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; Request = IoStack->Parameters.Scsi.Srb; ASSERT(Request); // finally check for CSW errors - if (Context->csw->Status == CSW_STATUS_COMMAND_PASSED) + if (Context->csw.Status == CSW_STATUS_COMMAND_PASSED) { // read capacity needs special work if (Request->Cdb[0] == SCSIOP_READ_CAPACITY) { // get output buffer - Response = (PUFI_CAPACITY_RESPONSE)Context->TransferData; + Response = (PUFI_CAPACITY_RESPONSE)Request->DataBuffer; // store in pdo - Context->PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); - Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); + PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); + PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); } Status = USBSTOR_SrbStatusToNtStatus(Request); } - else if (Context->csw->Status == CSW_STATUS_COMMAND_FAILED) + else if (Context->csw.Status == CSW_STATUS_COMMAND_FAILED) { // the command is correct but with failed status - issue request sense DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n"); @@ -277,13 +258,11 @@ USBSTOR_CSWCompletionRoutine( Irp->IoStatus.Status = Status; Irp->IoStatus.Information = Request->DataTransferLength; - FreeItem(Context->cbw); - // terminate current request - USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Irp); - USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject); + USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); + USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); - FreeItem(Context); + ExFreePoolWithTag(Context, USB_STOR_TAG); return Status; } @@ -297,7 +276,7 @@ USBSTOR_SendCSWRequest( Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, USBD_TRANSFER_DIRECTION_IN, sizeof(CSW), - Context->csw, + &Context->csw, NULL, USBSTOR_CSWCompletionRoutine, Context); @@ -489,42 +468,28 @@ USBSTOR_SendCBWRequest( PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; - if (!Context) - { - Context = USBSTOR_AllocateIrpContext(); - if (!Context) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - } - else - { - RtlZeroMemory(Context->cbw, sizeof(CBW)); - RtlZeroMemory(&Context->Urb, sizeof(URB)); - } + RtlZeroMemory(&Context->cbw, sizeof(CBW)); + RtlZeroMemory(&Context->Urb, sizeof(URB)); IoStack = IoGetCurrentIrpStackLocation(Irp); PDODeviceExtension = IoStack->DeviceObject->DeviceExtension; Request = IoStack->Parameters.Scsi.Srb; - Context->cbw->Signature = CBW_SIGNATURE; - Context->cbw->Tag = PtrToUlong(Context->cbw); - Context->cbw->DataTransferLength = Request->DataTransferLength; - Context->cbw->Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1; - Context->cbw->LUN = PDODeviceExtension->LUN; - Context->cbw->CommandBlockLength = Request->CdbLength; + Context->cbw.Signature = CBW_SIGNATURE; + Context->cbw.Tag = PtrToUlong(&Context->cbw); + Context->cbw.DataTransferLength = Request->DataTransferLength; + Context->cbw.Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1; + Context->cbw.LUN = PDODeviceExtension->LUN; + Context->cbw.CommandBlockLength = Request->CdbLength; - RtlCopyMemory(Context->cbw->CommandBlock, Request->Cdb, Request->CdbLength); + RtlCopyMemory(&Context->cbw.CommandBlock, Request->Cdb, Request->CdbLength); - DPRINT("CBW %p\n", Context->cbw); - DumpCBW((PUCHAR)Context->cbw); + DPRINT("CBW for IRP %p\n", Irp); + DumpCBW((PUCHAR)&Context->cbw); // initialize rest of context Context->Irp = Irp; - Context->TransferData = Request->DataBuffer; - Context->TransferDataLength = Request->DataTransferLength; Context->FDODeviceExtension = FDODeviceExtension; - Context->PDODeviceExtension = PDODeviceExtension; Context->RetryCount = 0; return USBSTOR_IssueBulkOrInterruptRequest( @@ -533,7 +498,7 @@ USBSTOR_SendCBWRequest( FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle, USBD_TRANSFER_DIRECTION_OUT, sizeof(CBW), - Context->cbw, + &Context->cbw, NULL, USBSTOR_CBWCompletionRoutine, Context); @@ -550,6 +515,7 @@ USBSTOR_HandleExecuteSCSI( PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; PPDO_DEVICE_EXTENSION PDODeviceExtension; + PIRP_CONTEXT Context; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); @@ -562,7 +528,16 @@ USBSTOR_HandleExecuteSCSI( // check that we're sending to the right LUN ASSERT(pCDB->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN)); - Status = USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp, NULL); + Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(IRP_CONTEXT), USB_STOR_TAG); + + if (!Context) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + Status = USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp, Context); + } return Status; } diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index fc3870ed298..26be827f8ae 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -283,21 +283,17 @@ typedef struct typedef struct { - union - { - PCBW cbw; - PCSW csw; - }; - URB Urb; PIRP Irp; - ULONG TransferDataLength; - PUCHAR TransferData; PFDO_DEVICE_EXTENSION FDODeviceExtension; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PMDL TransferBufferMDL; ULONG ErrorIndex; ULONG RetryCount; -}IRP_CONTEXT, *PIRP_CONTEXT; + union + { + CBW cbw; + CSW csw; + }; + URB Urb; +} IRP_CONTEXT, *PIRP_CONTEXT; typedef struct _ERRORHANDLER_WORKITEM_DATA {
5 years, 5 months
1
0
0
0
← Newer
1
...
15
16
17
18
19
20
21
...
29
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Results per page:
10
25
50
100
200