Re: [PATCH] usb: dwc3: fix endpoint direction when inputs are more than outputs

From: Thinh Nguyen
Date: Thu Oct 07 2021 - 20:40:38 EST


Shantur Rathore wrote:
> On Tue, Sep 14, 2021 at 1:52 AM Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx>
> wrote:
>
>> Shantur Rathore wrote:
>>> Hi Thinh,
>>
>> Hi Shantur, please don't do top-post.
>>
>>>
>>> Thanks for replying.
>>>
>>> As per the documentation for RK3399, it says
>>>
>>> USB3.0 Device Features
>>> Up to 7 IN endpoints, including control endpoint 0
>>> Up to 6 OUT endpoints, including control endpoint 0
>>>
>>
>> The statements above are not accurate. You can have more OUT endpoints,
>> but if you assign all 7 endpoints as IN, then you have up to 6 endpoints
>> left for OUT. The dwc3 controller is flexible and you can have various
>> configurations.
>>
>>> In this case, I think the hardware defines the endpoints being in / out.
>>> I am in no case a dwc3 expert or have DWC3 documentation so cannot say
>>> for certain.
>>> It is all based on RK3399 documentation.
>>>
>>> I am trying to use a composite gadget with
>>>
>>> - HID Keyboard - 1 IN
>>> - HID Mouse - 1 IN
>>> - NCM - 2 IN and 1 OUT
>>> - 2 Mass Storage Devices - 2 IN and 2 OUT
>>
>> Why do you need 2 Mass Storage devices? Can you use 2 LUNs instead?
>>
>> Multi lun mass storage devices don't work when you boot from them.
> So, I need to use dual Mass storage devices
>

Ok.

>
>>>
>>> That including ep0 totals to 7 IN endpoints and 3 Out endpoints.
>>>
>>>> Currently, dwc3 driver assumes that DWC3_NUM_IN_EPS(params) is at least
>>>> half of DWC3_NUM_EPS(parms). If that's not the case, we may see
>>>> problems. To cover most application setup, the driver tries to setup
>>>> number of OUT = IN.
>>>
>>> I think I am seeing this issue when I try to use the last IN endpoint.
>>>
>>> Can you please let me know the direction I should take?
>>>
>>
>> At the moment, I don't have a good/clean solution for this. dwc3 setups
>> half IN and half OUT from the total number of endpoints ahead of time.
>> Without the full context of the configuration from the composite layer,
>> it can't adjust easily.
>>
>> Maybe others have some ideas.
>>
>
> It would be best if endpoints could be set up as IN or OUT as when
> allocated rather than preallocating it.
> Looking forward to other ideas.
>

One way is if the controller driver can get the entire configuration
from the composite layer to check if it's possible to setup. So it knows
how many and what direction to setup the endpoints instead of the other
way around.

Maybe this is something that Wesley can also benefit for txfifo resizing
by enhancing the "check_config"?

BR,
Thinh