-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[USBCCGP][USBPORT][USBSTOR][USBHUB] Misc USB stack stability improvements. #8453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c944bec
6e2f3dc
c4025e7
3df4d97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ add_library(usbehci MODULE | |
| guid.c | ||
| usbehci.rc) | ||
|
|
||
| target_compile_definitions(usbehci | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe needs to be marked as "HACK" (+ same in the other cmakelists) |
||
| PRIVATE NO_KERNEL_LIST_ENTRY_CHECKS) | ||
|
|
||
| set_module_type(usbehci kernelmodedriver) | ||
| add_importlibs(usbehci usbport usbd hal ntoskrnl) | ||
| add_pch(usbehci usbehci.h SOURCE) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1853,7 +1853,12 @@ USBH_ProcessHubStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, | |||||
| USBH_SyncClearHubStatus(HubExtension, | ||||||
| USBHUB_FEATURE_C_HUB_LOCAL_POWER); | ||||||
| } | ||||||
| else if (HubStatusChange.OverCurrentChange) | ||||||
| /* | ||||||
| * per USB 2.0 spec multiple hub change bits | ||||||
| * may be set simultaneously. Handle OverCurrentChange independently so | ||||||
| * we don’t miss clearing it when LocalPowerChange is also set. | ||||||
| */ | ||||||
| if (HubStatusChange.OverCurrentChange) | ||||||
| { | ||||||
| USBH_SyncClearHubStatus(HubExtension, | ||||||
| USBHUB_FEATURE_C_HUB_OVER_CURRENT); | ||||||
|
|
@@ -1948,25 +1953,33 @@ USBH_ProcessPortStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, | |||||
| } | ||||||
|
|
||||||
| IoInvalidateDeviceRelations(HubExtension->LowerPDO, BusRelations); | ||||||
| return; | ||||||
| } | ||||||
| else if (PortStatusChange.PortEnableDisableChange) | ||||||
|
|
||||||
| /* | ||||||
| * Multiple port change bits can be set at once (e.g. enable + reset). | ||||||
| * Handle each independently | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| */ | ||||||
| if (PortStatusChange.PortEnableDisableChange) | ||||||
| { | ||||||
| RequestValue = USBHUB_FEATURE_C_PORT_ENABLE; | ||||||
| PortData->PortStatus = *PortStatus; | ||||||
| USBH_SyncClearPortStatus(HubExtension, Port, RequestValue); | ||||||
| return; | ||||||
| } | ||||||
| else if (PortStatusChange.SuspendChange) | ||||||
|
|
||||||
| if (PortStatusChange.SuspendChange) | ||||||
| { | ||||||
| DPRINT1("USBH_ProcessPortStateChange: SuspendChange UNIMPLEMENTED. FIXME\n"); | ||||||
| DbgBreakPoint(); | ||||||
| } | ||||||
| else if (PortStatusChange.OverCurrentIndicatorChange) | ||||||
|
|
||||||
| if (PortStatusChange.OverCurrentIndicatorChange) | ||||||
| { | ||||||
| DPRINT1("USBH_ProcessPortStateChange: OverCurrentIndicatorChange UNIMPLEMENTED. FIXME\n"); | ||||||
| DbgBreakPoint(); | ||||||
| } | ||||||
| else if (PortStatusChange.ResetChange) | ||||||
|
|
||||||
| if (PortStatusChange.ResetChange) | ||||||
| { | ||||||
| RequestValue = USBHUB_FEATURE_C_PORT_RESET; | ||||||
| PortData->PortStatus = *PortStatus; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1389,17 +1389,27 @@ USBPORT_InitializeDevice(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, | |||||
|
|
||||||
| if (NT_SUCCESS(Status)) | ||||||
| { | ||||||
| ASSERT(TransferedLen == sizeof(USB_DEVICE_DESCRIPTOR)); | ||||||
| ASSERT(DeviceHandle->DeviceDescriptor.bLength >= sizeof(USB_DEVICE_DESCRIPTOR)); | ||||||
| ASSERT(DeviceHandle->DeviceDescriptor.bDescriptorType == USB_DEVICE_DESCRIPTOR_TYPE); | ||||||
| /* Some devices may return a short transfer here; accept it if the | ||||||
| header through bMaxPacketSize0 was received earlier during | ||||||
| USBPORT_CreateDevice. */ | ||||||
| if (TransferedLen < sizeof(USB_DEVICE_DESCRIPTOR)) | ||||||
| { | ||||||
| DPRINT1("USBPORT_InitializeDevice: Short device descriptor len %lu\n", | ||||||
| TransferedLen); | ||||||
| } | ||||||
|
|
||||||
| /* Use the known bMaxPacketSize0 (was obtained prior to SetAddress). */ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes you have me remove periods like this comment or add them like above, I'm confused on what you actually want here. What are you trying to do?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here my "logic" was:
Just a preference, there's nothing as such in our code style, so do as you personally prefer. |
||||||
| MaxPacketSize = DeviceHandle->DeviceDescriptor.bMaxPacketSize0; | ||||||
|
|
||||||
| ASSERT((MaxPacketSize == 8) || | ||||||
| (MaxPacketSize == 16) || | ||||||
| (MaxPacketSize == 32) || | ||||||
| (MaxPacketSize == 64)); | ||||||
| if (!(MaxPacketSize == 8 || MaxPacketSize == 16 || | ||||||
| MaxPacketSize == 32 || MaxPacketSize == 64)) | ||||||
| { | ||||||
| DPRINT1("USBPORT_InitializeDevice: Invalid MPS0 %u\n", MaxPacketSize); | ||||||
| Status = STATUS_DEVICE_DATA_ERROR; | ||||||
| goto ExitError; | ||||||
| } | ||||||
|
|
||||||
| /* Mark USB2 hub flag when identifiable (bDeviceClass available in header). */ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if (DeviceHandle->DeviceSpeed == UsbHighSpeed && | ||||||
| DeviceHandle->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_HUB) | ||||||
| { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,13 @@ USBPORT_RootHubClassCommand(IN PDEVICE_OBJECT FdoDevice, | |
| return RHStatus; | ||
| } | ||
|
|
||
| if (Port == 0 || | ||
| Port > PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not |
||
| { | ||
| DPRINT1("USBPORT_RootHubClassCommand: CLEAR_FEATURE invalid port %u\n", Port); | ||
| return RHStatus; | ||
| } | ||
|
|
||
| switch (Feature) | ||
| { | ||
| case FEATURE_PORT_ENABLE: | ||
|
|
@@ -249,6 +256,13 @@ USBPORT_RootHubClassCommand(IN PDEVICE_OBJECT FdoDevice, | |
|
|
||
| Feature = SetupPacket->wValue.W; | ||
|
|
||
| if (Port == 0 || | ||
| Port > PdoExtension->RootHubDescriptors->Descriptor.bNumberOfPorts) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question |
||
| { | ||
| DPRINT1("USBPORT_RootHubClassCommand: SET_FEATURE invalid port %u\n", Port); | ||
| return RHStatus; | ||
| } | ||
|
|
||
| switch (Feature) | ||
| { | ||
| case FEATURE_PORT_ENABLE: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -474,7 +474,9 @@ USBSTOR_SendCBWRequest( | |||||
| Context->cbw.Tag = PtrToUlong(Irp); | ||||||
| Context->cbw.DataTransferLength = Request->DataTransferLength; | ||||||
| Context->cbw.Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1; | ||||||
| Context->cbw.LUN = PDODeviceExtension->LUN; | ||||||
|
|
||||||
| // Per BOT spec, LUN is 4 bits; clamp just in case | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BOT == Bulk Only Transfer ? |
||||||
| Context->cbw.LUN = (UCHAR)(PDODeviceExtension->LUN & 0x0F); | ||||||
| Context->cbw.CommandBlockLength = Request->CdbLength; | ||||||
|
|
||||||
| RtlCopyMemory(&Context->cbw.CommandBlock, Request->Cdb, Request->CdbLength); | ||||||
|
|
@@ -552,8 +554,21 @@ USBSTOR_HandleExecuteSCSI( | |||||
|
|
||||||
| DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", SrbGetCdb(Request)->CDB10.OperationCode, Request->DataTransferLength); | ||||||
|
|
||||||
| // check that we're sending to the right LUN | ||||||
| ASSERT(SrbGetCdb(Request)->CDB10.LogicalUnitNumber == PDODeviceExtension->LUN); | ||||||
| /* | ||||||
| * Some stacks/devices don’t propagate the LUN in the CDB10 header bits. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they don't propagate the LUN in the CDB10 header, then what does the |
||||||
| * USB BOT uses CBW.bCBWLUN for addressing. | ||||||
| * | ||||||
| * TODO: There's actually a bigger bug here though, | ||||||
| * while the above CAN HAPPPEN: | ||||||
| * Card Readers multiplex their card slots for example But we can deal with | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * that as we put more effort into fixing the USB stack. | ||||||
| */ | ||||||
| if (SrbGetCdb(Request)->CDB10.LogicalUnitNumber != PDODeviceExtension->LUN) | ||||||
| { | ||||||
| DPRINT1("USBSTOR_HandleExecuteSCSI: CDB LUN %u != PDO LUN %u (using CBW LUN)\n", | ||||||
| (ULONG)SrbGetCdb(Request)->CDB10.LogicalUnitNumber, | ||||||
| (ULONG)PDODeviceExtension->LUN); | ||||||
| } | ||||||
|
|
||||||
| return USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp); | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this
return Status;, this now looks e.g. like what we do in the bluetooth driver:https://git.reactos.org/?p=reactos.git;a=blob;f=drivers/bluetooth/fbtusb/fbtpnp.c;hb=bb7a6134c42c676d5abb5e14dae8a3d7c2f5568d#l1200
and
https://git.reactos.org/?p=reactos.git;a=blob;f=drivers/bluetooth/fbtusb/fbtpnp.c;hb=bb7a6134c42c676d5abb5e14dae8a3d7c2f5568d#l111
or in the keyboard HID driver:
https://git.reactos.org/?p=reactos.git;a=blob;f=drivers/hid/kbdhid/kbdhid.c;hb=bb7a6134c42c676d5abb5e14dae8a3d7c2f5568d#l906
Or, in
drivers/wdm/audio/hdaudbus/fdo.cpptheHDA_FDORemoveDevicefunction (see also thehdaudbus.cppfile).