Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp233353rdb; Thu, 30 Nov 2023 03:30:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFewsofDrLfTMEhvd+VGiKCEKENijoggrjoaXmec/cJOOD2Zg/qzi4cCWrS/rhLnDESoRIe X-Received: by 2002:a05:6a00:9398:b0:6c3:6cdc:a297 with SMTP id ka24-20020a056a00939800b006c36cdca297mr22363084pfb.14.1701343849300; Thu, 30 Nov 2023 03:30:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701343849; cv=none; d=google.com; s=arc-20160816; b=rmwmR8zy22B+Pi5xw0oEtF7IDjuquXBxiDv3nLgQmvcZoNrHWqRP0gwOmu3nHxJ8D+ J2Ic0zFGKkuBjjnrZVVeG9yHTEdMLVtAdlASpKguZuQyVVU1kU/GAlH9vBieeb5AuQI+ fwhKWjsrwr6gUbAxU6NfSgSTXrdILfa4Xfw8Hbw6Zum3K6X0CCawiPyleGfjR9GYIZVq /rK+UlqFB8gp3Yfv33vV8mI9oGV52bAlMmQflM80sXn/1dyjE8Shw+WK0UE1p4/Al3ex wrXjjT5RdJpA1wXowHfHfMTCrsEj+MzACII/EKtr+5+luoLd31G99sa6ZyZOnCegC2yb +KQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=W/FxwvLSo2aSXToTBjpJVKAKqYmmPXB6EVCTzIYqm7Y=; fh=bOuLC27mZ7PFmtJl2Acd6B1GMf4ubyRJ9HVmOWpntVg=; b=JFnXDvWdAf/+qmFJY7LSMMGSTJSeLwfzsOEJt12vfE28NbD6WQ1jDmhAAc4vMUDYkU xyULvDIijd0S47z1O7rNdEi3mzkpdAA0ORYS4aIKWRPvBkCXwW3OZe5/yo5uYx9YXwuE UcWBaNtYc25jyNaZqW2jnp4Mt+dHNUTPaH2haQxQuBIFRT1c+1WXoCkfR5987XGlv8Vd l7kYO5WrlCl8Fy/Oes/c1hQegrj0L/faENKkoqEt7HVP2x0uZtOenv6g8jB1UrraaH/X ONlT5fDi+MzfXxSQVvb6TuwsGklC0UXoVwkTLiFwrH5ueQW2AaBso7VqzBM60CurHM8Z Nllg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u12-20020a056a00158c00b006cbee55fe7csi1091860pfk.379.2023.11.30.03.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 03:30:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 676A28033DFB; Thu, 30 Nov 2023 03:30:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345223AbjK3LaY (ORCPT + 99 others); Thu, 30 Nov 2023 06:30:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345228AbjK3LaB (ORCPT ); Thu, 30 Nov 2023 06:30:01 -0500 Received: from hi1smtp01.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17F01715; Thu, 30 Nov 2023 03:29:59 -0800 (PST) Received: from hi2exch02.adit-jv.com (hi2exch02.adit-jv.com [10.72.92.28]) by hi1smtp01.de.adit-jv.com (Postfix) with ESMTP id 78457520115; Thu, 30 Nov 2023 12:29:58 +0100 (CET) Received: from vmlxhi-118.adit-jv.com (10.72.93.77) by hi2exch02.adit-jv.com (10.72.92.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Thu, 30 Nov 2023 12:29:58 +0100 Date: Thu, 30 Nov 2023 12:29:53 +0100 From: Hardik Gajjar To: John Keeping CC: Hardik Gajjar , , , , , , , Subject: Re: [PATCH] usb: gadget: f_fs: Add the missing get_alt callback Message-ID: <20231130112953.GA120825@vmlxhi-118.adit-jv.com> References: <20231124164435.74727-1-hgajjar@de.adit-jv.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.72.93.77] X-ClientProxiedBy: hi2exch02.adit-jv.com (10.72.92.28) To hi2exch02.adit-jv.com (10.72.92.28) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 03:30:44 -0800 (PST) On Sun, Nov 26, 2023 at 12:41:15PM +0000, John Keeping wrote: > On Fri, Nov 24, 2023 at 05:44:35PM +0100, Hardik Gajjar wrote: > > Some USB OTG hubs have multiple alternate configurations to offer, > > such as one for Carplay and another for Carlife. > > > > This patch implements and sets the get_alt callback to retrieve the > > currently used alternate setting. The new function allows dynamic > > retrieval of the current alternate setting for a specific interface. The > > current alternate setting values are stored in the 'cur_alt' array > > within the 'ffs_function' structure. > > Doesn't the alt setting need to be forwarded to userspace? > > What happens if the available endpoints change - doesn't that mean the > available endpoint files change? > > It's not sufficient to just blindly accept any alt setting and assume it > will work, that may be the case in one specific constrained scenario, > but it's not true in general. At the very least we must not accept an > alt setting that is not defined in the descriptors. The commit message appears a bit confusing. The user space creates an FFS/iAP (Apple) gadget and writes an ep0 descriptor with multiple alt settings. The host then sends the set_alt request to configure alt_setting 0 or 1, verified by the subsequent get_alt request. Without this patch, the Host/Phone consistently sets alt 0 and retrieves alt 0, even when the request is for alt 1. Given that f_fs is a user space-controlled gadget, creating a descriptor seems quite flexible for this type of gadget. I intend to submit an upstream patch v2 with a clearer commit message. > > > Signed-off-by: Hardik Gajjar > > --- > > drivers/usb/gadget/function/f_fs.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c > > index efe3e3b85769..37c47c11f57a 100644 > > --- a/drivers/usb/gadget/function/f_fs.c > > +++ b/drivers/usb/gadget/function/f_fs.c > > @@ -75,6 +75,7 @@ struct ffs_function { > > short *interfaces_nums; > > > > struct usb_function function; > > + int cur_alt[MAX_CONFIG_INTERFACES]; > > }; > > > > > > @@ -98,6 +99,7 @@ static int __must_check ffs_func_eps_enable(struct ffs_function *func); > > static int ffs_func_bind(struct usb_configuration *, > > struct usb_function *); > > static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); > > +static int ffs_func_get_alt(struct usb_function *f, unsigned int intf); > > static void ffs_func_disable(struct usb_function *); > > static int ffs_func_setup(struct usb_function *, > > const struct usb_ctrlrequest *); > > @@ -3232,6 +3234,15 @@ static void ffs_reset_work(struct work_struct *work) > > ffs_data_reset(ffs); > > } > > > > +static int ffs_func_get_alt(struct usb_function *f, > > + unsigned int interface) > > +{ > > + struct ffs_function *func = ffs_func_from_usb(f); > > + int intf = ffs_func_revmap_intf(func, interface); > > + > > + return (intf < 0) ? intf : func->cur_alt[interface]; > > +} > > + > > static int ffs_func_set_alt(struct usb_function *f, > > unsigned interface, unsigned alt) > > { > > @@ -3266,8 +3277,10 @@ static int ffs_func_set_alt(struct usb_function *f, > > > > ffs->func = func; > > ret = ffs_func_eps_enable(func); > > - if (ret >= 0) > > + if (ret >= 0) { > > ffs_event_add(ffs, FUNCTIONFS_ENABLE); > > + func->cur_alt[interface] = alt; > > + } > > return ret; > > } > > > > @@ -3574,6 +3587,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi) > > func->function.bind = ffs_func_bind; > > func->function.unbind = ffs_func_unbind; > > func->function.set_alt = ffs_func_set_alt; > > + func->function.get_alt = ffs_func_get_alt; > > func->function.disable = ffs_func_disable; > > func->function.setup = ffs_func_setup; > > func->function.req_match = ffs_func_req_match; > > -- > > 2.17.1 > > Thanks, Hardik