lkml.org 
[lkml]   [2020]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v1] usb:gadget: Fix issue with config_ep_by_speed function.
From
Date
Hi Pawel,

On 14/02/2020 21:55, Pawel Laszczak wrote:
>>
>> Pawel Laszczak wrote:
>>> Hi,
>>>
>>>> Hi,
>>>>
>>>> Jayshri Pawar wrote:
>>>>> This patch adds additional parameter alt to config_ep_by_speed function.
>>>>> This additional parameter allows to improve this function and
>>>>> find proper usb_ss_ep_comp_descriptor.
>>>>>
>>>>> Problem has appeared during testing f_tcm (BOT/UAS) driver function.
>>>>>
>>>>> f_tcm function for SS use array of headers for both BOT/UAS alternate
>>>>> setting:
>>>>>
>>>>> static struct usb_descriptor_header *uasp_ss_function_desc[] = {
>>>>> (struct usb_descriptor_header *) &bot_intf_desc,
>>>>> (struct usb_descriptor_header *) &bot_uasp_ss_bi_desc,
>>>>> (struct usb_descriptor_header *) &bot_bi_ep_comp_desc,
>>>>> (struct usb_descriptor_header *) &bot_uasp_ss_bo_desc,
>>>>> (struct usb_descriptor_header *) &bot_bo_ep_comp_desc,
>>>>>
>>>>> (struct usb_descriptor_header *) &uasp_intf_desc,
>>>>> (struct usb_descriptor_header *) &bot_uasp_ss_bi_desc,
>>>>> (struct usb_descriptor_header *) &uasp_bi_ep_comp_desc,
>>>>> (struct usb_descriptor_header *) &uasp_bi_pipe_desc,
>>>>> (struct usb_descriptor_header *) &bot_uasp_ss_bo_desc,
>>>>> (struct usb_descriptor_header *) &uasp_bo_ep_comp_desc,
>>>>> (struct usb_descriptor_header *) &uasp_bo_pipe_desc,
>>>>> (struct usb_descriptor_header *) &uasp_ss_status_desc,
>>>>> (struct usb_descriptor_header *) &uasp_status_in_ep_comp_desc,
>>>>> (struct usb_descriptor_header *) &uasp_status_pipe_desc,
>>>>> (struct usb_descriptor_header *) &uasp_ss_cmd_desc,
>>>>> (struct usb_descriptor_header *) &uasp_cmd_comp_desc,
>>>>> (struct usb_descriptor_header *) &uasp_cmd_pipe_desc,
>>>>> NULL,
>>>>> };
>>>>>
>>>>> The first 5 descriptors are associated with BOT alternate setting,
>>>>> and others are associated with UAS.
>>>>>
>>>>> During handling UAS alternate setting f_tcm drivr invokes
>>>>> config_ep_by_speed and this function sets incorrect companion endpoint
>>>>> descriptor in usb_ep object.
>>>>>
>>>>> Instead setting ep->comp_desc to uasp_bi_ep_comp_desc function in this
>>>>> case set ep->comp_desc to bot_uasp_ss_bi_desc.
>>>>>
>>>>> This is due to the fact that it search endpoint based on endpoint
>>>>> address:
>>>>>
>>>>> for_each_ep_desc(speed_desc, d_spd) {
>>>>> chosen_desc = (struct usb_endpoint_descriptor *)*d_spd;
>>>>> if (chosen_desc->bEndpoitAddress == _ep->address)
>>>>> goto ep_found;
>>>>> }
>>>>>
>>>>> And in result it uses the descriptor from BOT alternate setting
>>>>> instead UAS.
>>>>>
>>>>> Finally, it causes that controller driver during enabling endpoints
>>>>> detect that just enabled endpoint for bot.
>>>>>
>>>>> Signed-off-by: Jayshri Pawar <jpawar@cadence.com>
>>>>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>>>>> ---
>>>>> drivers/usb/gadget/composite.c | 46 ++++++++++++++------
>>>>> drivers/usb/gadget/function/f_acm.c | 7 +--
>>>>> drivers/usb/gadget/function/f_ecm.c | 7 +--
>>>>> drivers/usb/gadget/function/f_eem.c | 4 +-
>>>>> drivers/usb/gadget/function/f_fs.c | 3 +-
>>>>> drivers/usb/gadget/function/f_hid.c | 4 +-
>>>>> drivers/usb/gadget/function/f_loopback.c | 2 +-
>>>>> drivers/usb/gadget/function/f_mass_storage.c | 5 ++-
>>>>> drivers/usb/gadget/function/f_midi.c | 2 +-
>>>>> drivers/usb/gadget/function/f_ncm.c | 7 +--
>>>>> drivers/usb/gadget/function/f_obex.c | 4 +-
>>>>> drivers/usb/gadget/function/f_phonet.c | 4 +-
>>>>> drivers/usb/gadget/function/f_rndis.c | 7 +--
>>>>> drivers/usb/gadget/function/f_serial.c | 4 +-
>>>>> drivers/usb/gadget/function/f_sourcesink.c | 11 +++--
>>>>> drivers/usb/gadget/function/f_subset.c | 4 +-
>>>>> drivers/usb/gadget/function/f_tcm.c | 36 +++++++--------
>>>>> drivers/usb/gadget/function/f_uac1_legacy.c | 2 +-
>>>>> drivers/usb/gadget/function/f_uvc.c | 5 ++-
>>>>> drivers/usb/gadget/function/u_audio.c | 4 +-
>>>>> include/linux/usb/composite.h | 2 +-
>>>>> 21 files changed, 99 insertions(+), 71 deletions(-)
>>>>>
>>>> I think we should create a new function and keep the old
>>>> config_ep_by_speed() for default alt-setting (e.i. have
>>>> config_ep_by_speed calls the new function with default alt-setting 0).
>>>> This way, we can keep compatibility with old function drivers and
>>>> minimize changes. At least that's what we did.
>>>>
>>> I don't think we need the separate function.
>>> If we set last parameter alt=0 then this function will work in the same way as old one.
>>>
>>
>> I wasn't talking about that. This patch modifies the
>> config_ep_by_speed() parameters, which requires to make a change to
>> every function driver of the kernel, and all in a single patch. This
>> makes it difficult to backport this fix. The only function driver that
>> you really need this fix for is f_tcm because of the stream eps right?
>>
>> You could just add a function like
>>
>> int config_ep_by_speed_and_alt(struct usb_gadget *g, struct
>> usb_function *f, unsigned int alt, struct usb_ep *_ep);
>>
>>
>> Then redefine config_ep_by_speed() to use it
>>
>> int config_ep_by_speed(struct usb_gadget *g,
>>                       struct usb_function *f,
>>                       struct usb_ep *_ep)
>> {
>>        return config_ep_by_speed_and_alt(g, f, 0, _ep);
>> }
>>
>> This way, 1) you can split this patch, 2) you only need to make a fix to
>> f_tcm, 3) this fix can be backported much easier.
>>
>> Anyways, this is just a suggestion. It's up to the maintainers to decide.
>
> Thanks for clarification, now I got it. In my opinion, both solution has pros and cons
> 1. Original patch.
> cons: introduce many change in many files
> pros: we have only single API function - simpler Gadget Subsystem API
>
> 2. using config_ep_by_speed_and_alt
> cons: minimal impact to other files.
> pros: introduce the new API function which in fact could be omitted.
>

I would vote for 2.

> It's only my personal opinion :) .
>
> Felipe and Greg what is you opinion ?
>
> Best Regards,
> Pawel
>
>>
>> BR,
>> Thinh
>

--

cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

\
 
 \ /
  Last update: 2020-03-04 10:30    [W:0.073 / U:4.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site