I am writing a driver for the xHCI and I have been having a problem with the address assignment.
Here's what I am doing:
- Reset the controller by writing 1 to the USBCMD.HCRST and wait for USBSTATUS.CONTROLLER_NOT_READY flag to clear.
- Set the maximum slots enabled in the config register to 16 (which is the max supported by my xHC).
- Allocate the device context base address register on a 64 byte aligned memory location and write that address to the dcbaap register.
- allocate scratchpad buffers, write their addresses in an array, then write the address of that array in the 0th entry of the dcbaap.
- Allocate a command ring and write its address in CRCR.
- Set the R/S bit and wait for the controller not ready flag CNR to clear.
- Allocate event ring, and event ring segment table with one entry, and write the address of table in ERSTBA
- Then the software waits until a device is connected on port 12, I connect the device to port 12 and I can see the port goes to the enabled state as indicated by PP, CCS, PED being 1, and PR and PLS being 0.
- Submit an enable slot command and I get an event on the event ring with a success completion code and a slot ID.
- allocate output and input device contexts data structures and initialize them to valid values.
- allocate transfer ring and write its address to the input context.
- Submit the first address device command with BSR = 1 and I get an event on the event ring with success completion code.
- Here is where things go wrong: submit the second address device command with BSR = 0, and I get USB transaction error for the completion code.
In the xhci spec rev 1.2, it says the USB transaction error is the result of a USB3 DPP(Data Packet Payload) Error. I looked in the USB3.2 rev 1 and it said DPP error could happen due to any of the following:
1.CRC incorrect
2.DPP aborted
3.DPP missing
4.Data Length in the Setup DPH does not match the actual data payload length.
I've been trying on this for about 2-3 weeks now and getting nowhere. I did see a post here where someone had this issue with the EHCI and they fixed it by reducing their delays. I tried to do a similar thing but still didn't fix it.
Does anyone have an idea why am I getting this error or how do I go about fixing it?
Something I want to note is that if skip step 8, an continue to enable slot command, I still get the same results. So I still get a device slot and I still get a successful first Address Device command even though there is no device connected. Which makes me think that the usb device isn't even talking? I'm using a thumb drive, I tried different thumb drives and different ports and still the same issue. I'm using a USB 3.0 thumb drive on a SS port.