Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4319156ybf; Wed, 4 Mar 2020 01:30:16 -0800 (PST) X-Google-Smtp-Source: ADFU+vs1hzpTkIo6wEmcu/xtgCbefzf/c6Q8f2tlO3Yn2PvQmNNxWbPgVx28dImjxj6nfnC2O1/G X-Received: by 2002:aca:cc41:: with SMTP id c62mr1125906oig.58.1583314215963; Wed, 04 Mar 2020 01:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583314215; cv=none; d=google.com; s=arc-20160816; b=srO242k4NRv5SXvqWb7efvl9o0SQQe24Hs9Z7sFwcgDmg+ypw3SpjeXegFRVeooZVw HiM8ay8N87MyolCtDuBMYPDruYw3MfPpbWxCyacGTNFJHksuaA860o18hWpBikE+HyMs KNl20Us5e7Wh/0icJrIWNY8DdX3xRr2DyOMhLYrjYV9Z+UpZ5o1o5tQ+Xq74wxw/f0yB 3+NaptRq0x5vu6FhM1Bwv41lZ4amUG8UZBvx9v2pob7QCCD99PsGdtTaYKlsgyUJKD8T jeTWkPzjW8mFOLQr1CBjqlk1YbOEnyJKQme6INjtuOlwMU4pJs/alNaLHgAUQbhAPBpy 7r4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=e4PeKRutmxnsEKHu3OypTkMAaV/T5qt4QEtP5s9vREY=; b=MmWLGu1AgpMvkddS3nA/g52dGjTSA5sQE9clpE5RrFsnQPrkFjBBTJQahVKVkvzJYk e6M1LmcbBJe8RGD/nugGbmHpQO1QhceiM29El/rCjcP3n7f+af8epaD7KEOjzWlIjiW9 yjcyZLwJTS+6GKXr+IDyVO7WBU34paS/mohD3oNp2lxl57V4UTm5/KFtZ7ryieUi767X dH59KnuS/ectMp687Td83z4rEwsyeVVMqg3d7NrywXUXahiL+RAIgvZ0hsECXRWB26ok F889fHF/neabd3U5Ow2zeuWCZ+FEjPWkLNbw2i02a+MXzZa9+9oVr28E9H3JB0B0eQGH sk8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NRwhYCNq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w31si722168otb.59.2020.03.04.01.30.04; Wed, 04 Mar 2020 01:30:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=NRwhYCNq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728988AbgCDJ3y (ORCPT + 99 others); Wed, 4 Mar 2020 04:29:54 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:51252 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727734AbgCDJ3y (ORCPT ); Wed, 4 Mar 2020 04:29:54 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0249TjrZ089014; Wed, 4 Mar 2020 03:29:45 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1583314185; bh=e4PeKRutmxnsEKHu3OypTkMAaV/T5qt4QEtP5s9vREY=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=NRwhYCNqFvnyVPvKcBbdSJ4y9Do84BhAPnsMR6jbwPeQnDU8yGH+b/oun+IpeBj2X 5eL2geZEQ9ZtIHFY4ok0Zs/4qX7iXRYK3zGVTSUUQlIl8yPA3xjnxLxD17yC6KyD57 5jvdRlix0BTsyJIb1f2rM4fJeTlS0YaEIHlLPMcE= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0249Tjn1002490; Wed, 4 Mar 2020 03:29:45 -0600 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Wed, 4 Mar 2020 03:29:44 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Wed, 4 Mar 2020 03:29:44 -0600 Received: from [192.168.2.14] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0249TfK1079733; Wed, 4 Mar 2020 03:29:42 -0600 Subject: Re: [PATCH v1] usb:gadget: Fix issue with config_ep_by_speed function. To: Pawel Laszczak , Thinh Nguyen , Jayshri Dajiram Pawar , "linux-usb@vger.kernel.org" , "balbi@kernel.org" CC: "gregkh@linuxfoundation.org" , "heikki.krogerus@linux.intel.com" , "linux-kernel@vger.kernel.org" , "jbergsagel@ti.com" , "nsekhar@ti.com" , "nm@ti.com" , "peter.chen@nxp.com" , Rahul Kumar , Sanket Parmar References: <1581502748-22464-1-git-send-email-jpawar@cadence.com> <7ef4b9c5-8694-4d8e-2866-95ec11546bec@synopsys.com> From: Roger Quadros Message-ID: Date: Wed, 4 Mar 2020 11:29:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>>>> Signed-off-by: Pawel Laszczak >>>>> --- >>>>> 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