Page 1 of 1

XHCI: Error when configuring endpoint

Posted: Wed Sep 28, 2022 5:45 am
by longjin
Hello,
I'm building the a usb keyboard for my OS, but I've met some problem when configuring the endpoint.

Code: https://github.com/fslongjin/DragonOS/b ... ci.c#L1613

My procedures are:
1. Get device descriptor (Line 1613)
2. Get the interface descriptor (Line 1744)
3. Get endpoint descriptor (Line 1748)
4. Set configuration with the value I retrieved from the config descriptor. (Line 1751)
5. Initialize the input_ep1 and create the input context, issue a "Configure Endpoint" command. (Line 1755)

In the first four steps, QEMU does not report errors, and it can also run normally on the physical machine. But the QEMU generates a 'CC_TRB_ERROR' TRB in the fifth step.
I check the "Configure Endpoint" TRB carefully, but I can't find anything wrong. I think, may be there are something wrong in the input context. I already checked the xhci spec and usb3.2 spec, but I don't know how to solve the problem.
So, what's wrong with my code?
Thank you!!!

Re: XHCI: Error when configuring endpoint

Posted: Wed Sep 28, 2022 4:56 pm
by BenLunt
Did you send the Set Address command with the Block bit set? This is usually done quite a bit before you send the Configure Endpoint command.

If you have not, please read about the Set Address command. It is sent twice, once with the Block bit set and later with the Block bit cleared.

Ben
- https://www.fysnet.net/the_universal_serial_bus.htm

Re: XHCI: Error when configuring endpoint

Posted: Wed Sep 28, 2022 8:47 pm
by longjin
BenLunt wrote:Did you send the Set Address command with the Block bit set? This is usually done quite a bit before you send the Configure Endpoint command.

If you have not, please read about the Set Address command. It is sent twice, once with the Block bit set and later with the Block bit cleared.

Ben
- https://www.fysnet.net/the_universal_serial_bus.htm
Hello, thanks for your reminder. Now I send set address twice, and I initialize the correct endpoint with the number from endpoint descriptor.
But, the qemu still report trb error…

Re: XHCI: Error when configuring endpoint

Posted: Wed Sep 28, 2022 9:49 pm
by Gigasoft
You forgot to set the Max Endpoint and Route string fields of the input context. Also don't know why you're messing with the output context, which is supposed to be managed by the controller.

Re: XHCI: Error when configuring endpoint

Posted: Thu Sep 29, 2022 3:08 am
by longjin
Gigasoft wrote:You forgot to set the Max Endpoint and Route string fields of the input context. Also don't know why you're messing with the output context, which is supposed to be managed by the controller.
Hmm, what's the Max Endpoint field? I can't see it in the input context. Do you mean the Max Endpoint Service Time Interval Payload?

Re: XHCI: Error when configuring endpoint

Posted: Thu Sep 29, 2022 3:33 am
by Gigasoft
Sorry, I mean "Context entries", which must be set to the highest numbered endpoint that you are configuring with the command. And bit 0 of the "Add" field should also be set to 1.

Re: XHCI: Error when configuring endpoint

Posted: Fri Sep 30, 2022 5:35 am
by longjin
Gigasoft wrote:Sorry, I mean "Context entries", which must be set to the highest numbered endpoint that you are configuring with the command. And bit 0 of the "Add" field should also be set to 1.
Thank you very much! It works!