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:
- Attach device and a port status change event is posted.
- if the event is a USB2 attach, reset the port and wait for it to complete the reset.
- Send an
enableSlotcommand to the controller. - if success, send an
AddressDevicecommand to the controller. - If success, read the device descriptor and get the
maxPacketSize - Update the input context and send an
EvaluateContextcommand. - If success, read the configuration descriptor.
- Configure contexts, send
ConfigureEndpointcommand to the controller. - If success, send a
SET_CONFIGURATIONrequest to the device. - Device responds with a transfer event with a
successcompletion 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.
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.