OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 1:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: XHCI: configure endpoint
PostPosted: Thu Jan 26, 2023 3:53 pm 
Offline
Member
Member

Joined: Tue Aug 30, 2016 1:31 pm
Posts: 67
Hello everyone,

currently, I am working on my XHCI implementation and I managed to get the configuration information from the attached USB device.
On EHCI I could just call SET_CONFIGURATION and then I have access to my bulk endpoints.
But I am not sure how to achieve the same on XHCI.

I have the following questions:
1 - Should I first run SET_CONFIGURATION and then the Configure Endpoint Command?
2 - If I read the documentation about the Configure Endpoint Command, it says it requires me to create an Input Context, is this the same input context of the Set Address Command but then with two extra EP contexts added? (for both bulk endpoints)
3 - should I enable A2 and A3 in the Input Control Context?
4 - do I need to declare an interface number/configuration number? if yes, does it mean I need to run this command twice? one for the bulk in and one for the bulk out?

Thank you for your time!


Top
 Profile  
 
 Post subject: Re: XHCI: configure endpoint
PostPosted: Thu Jan 26, 2023 5:53 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
SanderR wrote:
I have the following questions:
1 - Should I first run SET_CONFIGURATION and then the Configure Endpoint Command?
2 - If I read the documentation about the Configure Endpoint Command, it says it requires me to create an Input Context, is this the same input context of the Set Address Command but then with two extra EP contexts added? (for both bulk endpoints)
3 - should I enable A2 and A3 in the Input Control Context?
4 - do I need to declare an interface number/configuration number? if yes, does it mean I need to run this command twice? one for the bulk in and one for the bulk out?

You have to configure the endpoint(s) first, very similar to how you set the address. With the 'A' bits (A2 and A3 as you mention), you are telling the controller, when an 'A' bit is set, that you are adding these to the configuration. You can add more than one at a time if you wish. However, it is normal and usually done one at a time. You found a device that has two bulk endpoints, each endpoint needing to be setup separately, so in theory, you call the CONFIG_EP command once for each endpoint, with its corresponding 'A' bit set. (If the 'A' or 'D' bits are clear, the controller will ignore the Input Context for that corresponding bit. So if you have already set up A2, leaving A2 and D2 clear when setting up A3 will have no effect on the A2's Context, which is desired.)

Once you have setup each endpoint (calling the CONFIG_EP command), you can then set the configuration (SET_CONFIGURATION).

As for "declaring an interface number/configuration number", I don't quite understand what you mean. The endpoints already have a number. For example, the Bulk IN may be 0x81. This means that A3 will be used. A0 = Slot, A1 = Control EP, A2 = EP1 Out, A3 = EP1 In, A4 = EP2 Out, A5 = EP2 In, etc.

Again, you could configure both Bulk EPs at once if you wish. Usually it will not be A2 and A3 together. If it was, this means that both endpoints have the same value of 1. Usually they have a different value like 1 and 2, or 2 and 3, etc. (the IN endpoints having bit 7 set). It is valid to have both endpoints with the same value (I have seen a few devices that do this), though it is normal for each to have a different value. For example, I have seen a few devices with the bulk endpoint values of 0x82 and 0x02 which means that they will have the same endpoint value, bit 7 indicating which direction. However, normally the two bulk endpoints will have values of 0x01 and 0x82 or 0x02 and 0x83 or similar.

Since you have to set up a transfer ring for each endpoint, which is done separately and once for each endpoint, you usually configure the endpoint at the same time, which in turn means you configure them one at a time, not at the same time.

To add to that, now that you are using xHCI, you have to know that a super-speed device will now have a BOS descriptor and each bulk endpoint will have an Endpoint Companion descriptor. Also, a super-speed MSD may have two (alternate) interfaces, a BBB and a UASP. You will have to choose one of them. Something more to look for. :-)

Hope this helps,
Ben
- https://www.fysnet.net/the_universal_serial_bus.htm


Top
 Profile  
 
 Post subject: Re: XHCI: configure endpoint
PostPosted: Thu Feb 09, 2023 4:34 pm 
Offline
Member
Member

Joined: Tue Aug 30, 2016 1:31 pm
Posts: 67
Thank you for your answer,

I was struggling with the implementation of this.
The system keeps giving the command event status of 17, what am I doing wrong?
This is the code: https://github.com/AdeRegt/SanderOS64/b ... hci.c#L648

Thank you in advantage!


Top
 Profile  
 
 Post subject: Re: XHCI: configure endpoint
PostPosted: Fri Feb 10, 2023 7:10 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
Completion code 17 is parameter error. This means that your context for that slot and endpoint is not valid. You have an invalid value in one of the members of the INPUT CONTEXT.

Ben


Top
 Profile  
 
 Post subject: Re: XHCI: configure endpoint
PostPosted: Sun Feb 12, 2023 12:52 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
About the only thing I see that catches my eye, is that the LSA field should be zero, you aren't using streams anyway.

Also, the AverageTRBLength should be much larger than 8 (in this particular case). For the Control pipe, 8 is sufficient. For Interrupt pipes, at least two times the max packet size. In your case, the Bulk (and ISO) pipe will be about six times the max packet size.

The xHCI 1.0 spec, page 188 states: "Reasonable initial values of Average TRB Length for Control endpoints would be 8B, Interrupt endpoints 1KB, and Bulk and Isoch endpoints 3KB."

Page 327 of the same spec defines the interval parameter. If the Bulk pipe is a super-speed pipe, the parameter must be zero. There is a good explanation and example on that page for the interval parameter.

Ben


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group