usbdriverintelosdev

USB2.0 control endpoint stall upon set_configuration request


I'm working on xhci controller driver for a proprietary OS. I'm having a problem with enumerating USB2 devices. USB3 devices get enumerated without issues. Here's what my driver does:

  1. Attach device and a port status change event is posted.
  2. if the event is a USB2 attach, reset the port and wait for it to complete the reset.
  3. Send an enableSlot command to the controller.
  4. if success, send an AddressDevice command to the controller.
  5. If success, read the device descriptor and get the maxPacketSize
  6. Update the input context and send an EvaluateContext command.
  7. If success, read the configuration descriptor.
  8. Configure contexts, send ConfigureEndpoint command to the controller.
  9. If success, send a SET_CONFIGURATION request to the device.
  10. Device responds with a transfer event with a success completion code.

Now, if I attach a USB3 device, all 10 steps complete without issues. However, if I attach a USB2 device, only the first 9 steps complete and the device responds with a STALL on the 10th step.

I have tried more things than I can even list here, including playing with the BSR, sending SET_ADDRESS requests manually, trying other configurations, different devices, sending wrong configurations... They all return a STALL on the status stage trb.

Is there any way to know what is causing the usb2 devices to stall? How can I fix this? Any pointers are much appreciated.


Solution

  • The problem was that I need to set the DIR bit of the status stage trb of the set configuration request to 1. USB3 devices want DIR = 0. I don't know but it works.