From patchwork Fri Mar 1 12:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hardik Gajjar X-Patchwork-Id: 208824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1051187dyb; Fri, 1 Mar 2024 04:47:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVkNxPo+BgtlOKiwVMcOJXEavEdn9n2yTEOuZvnZHSjOPR+vwOr7VyinsfiZb7wCN06R6rMAtnBU48w2oYY2n1lbfPEaQ== X-Google-Smtp-Source: AGHT+IHTOu4puYpBMUq5FKtIsRtZglHuDyZTv1ElKK6qRxl1QWzMw9GNketwUV4SkrgEO+SH99Uy X-Received: by 2002:a05:6808:d52:b0:3c1:d367:2a90 with SMTP id w18-20020a0568080d5200b003c1d3672a90mr1447496oik.20.1709297260497; Fri, 01 Mar 2024 04:47:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709297260; cv=pass; d=google.com; s=arc-20160816; b=Co3pTP0od4UJkK8dbVrmKyPDUarwPmboWXkD3YY7+412UMzqJIrytVlo8Yr6NXVU3q 8xvt3MDuSJz0AhuOVNiwEvCzxql+udwDr6JC/4PJR6mXnRhJfkU8P/8mNLSXpXBS8Cn/ BfdXifATXMfo/5gL7PWf6QqN5YdHHAIaTZWeQtiKBDnhnLAWbA1bOQ1ZLPUzshyPaNX3 qmEbpHboV3NwBhNvC08gPiHwxj8rd5Serid62KisQ9jQEg/cckjeyfbaJ/vg8YK+oZXy B53/L/f796VgdoZgxH31z13Wyf9N4genxLv9POMhyrPCO00C87/Zi0J2m/mFDtn2n3Aj iUXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=FhkKW2kPM99sgB1Ac6uhaD1B4tfJaA+Ms4dbCpwNjp0=; fh=Xynkik3dPEgzKo1QNuDCrHQo30veZAkjUzrNI+tWrJ0=; b=xcRqz07ZT82FpFdZNAwoX3F9oH2qeztGk8pb4GLq6UeRIj2Fw92kjYvGV2oyQCUAzk 0rCV0c1xH1qG7Q63PbWzdj3PYWUH3I52qI1fCKvEW6BGcVpl1xCPFTTQHc5xNa7EV9Wg glOcLepRzzfWs6xNMjU7FUrvTamJwnyAB/4I9S1CSVnKIwKuUh4uKLUNT8vyqmbRjQBs /HH+DN8lqpd5P2uMjwlfkmazQSunY1fjJZY6c1jhw+1AUY8pde47Jer1yz3yCMGdp0mO KDfp70oh/vPwwkKWqE1g6rglE7rAzbc5rFeTbLyPgtVhbCtMYM57+weVxWPf5V0O9dx/ zCvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=de.adit-jv.com); spf=pass (google.com: domain of linux-kernel+bounces-88415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88415-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w20-20020a63fb54000000b005dcc8a4590esi3475937pgj.680.2024.03.01.04.47.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 04:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=de.adit-jv.com); spf=pass (google.com: domain of linux-kernel+bounces-88415-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88415-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 46414282901 for ; Fri, 1 Mar 2024 12:47:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C54F341C7F; Fri, 1 Mar 2024 12:47:26 +0000 (UTC) Received: from hi1smtp01.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B970E7E1; Fri, 1 Mar 2024 12:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.241.18.167 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709297245; cv=none; b=cbwJZklosJBHmaQGSu3gsL0VS+khS7+bzzn9yCGtA9R0ZPdRrQOkW8GU/7pTDS6I3WH9hJkrYXNNpO53dhJkParSnBRTNeJhpZWYaz6RvSOayVGu+0ZYrncAnLfndJl2JfQpFHzoppQylpthUz6j3nS8nZ6o7Rz6qiUTDbsom+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709297245; c=relaxed/simple; bh=xmtt/dJqJpEhHTRjQVG1J/CP+alT6/cJsmAw7/JRl/I=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GRrjH4TKJWAk9P02JU/KVhrA97W0losTQzHHYSrvpTESltrjomCYX8vz1NiEQ+mX143gI8r2J/LNaPdtBuk47l2XVFty2lCifMiILFo9X7C6HlFTfJ5eTS85BW5Qk62w1g2coWvWrgPZdifxocGHj/IqKbPTdGnTGLmAnm36etk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=de.adit-jv.com; spf=pass smtp.mailfrom=de.adit-jv.com; arc=none smtp.client-ip=93.241.18.167 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=de.adit-jv.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=de.adit-jv.com Received: from hi2exch02.adit-jv.com (hi2exch02.adit-jv.com [10.72.92.28]) by hi1smtp01.de.adit-jv.com (Postfix) with ESMTP id 7AE30520252; Fri, 1 Mar 2024 13:47:16 +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.35; Fri, 1 Mar 2024 13:47:16 +0100 From: Hardik Gajjar To: , , , , , , , , CC: , , , , Subject: [PATCH] usb: gadget: f_fs: Add the missing get_alt callback Date: Fri, 1 Mar 2024 13:47:08 +0100 Message-ID: <20240301124708.120394-1-hgajjar@de.adit-jv.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: hi2exch02.adit-jv.com (10.72.92.28) To hi2exch02.adit-jv.com (10.72.92.28) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792328083800324075 X-GMAIL-MSGID: 1792328083800324075 The Apple CarLife iAP gadget has a descriptor in userspace with two alternate settings. The host sends the set_alt request to configure alt_setting 0 or 1, and this is verified by the subsequent get_alt request. This patch implements and sets the get_alt callback. Without the get_alt callback, composite.c abruptly concludes the USB_REQ_GET/SET_INTERFACE request, assuming only one alt setting for the endpoint. unlike the uvc and ncm, f_fs gadget is fully implemented in userspace, and driver just reset the eps and generate the event. so no additional adaptaion associated with this change is not required in set_alt callback Signed-off-by: Hardik Gajjar --- drivers/usb/gadget/function/f_fs.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 6bff6cb93789..a3e8cf7963e7 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -42,6 +42,7 @@ #include "configfs.h" #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ +#define MAX_ALT_SETTINGS 2 /* Allow up to 2 alt settings to be set. */ /* Reference counter handling */ static void ffs_data_get(struct ffs_data *ffs); @@ -75,6 +76,7 @@ struct ffs_function { short *interfaces_nums; struct usb_function function; + int cur_alt[MAX_CONFIG_INTERFACES]; }; @@ -98,6 +100,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 *); @@ -3231,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) { @@ -3238,6 +3250,9 @@ static int ffs_func_set_alt(struct usb_function *f, struct ffs_data *ffs = func->ffs; int ret = 0, intf; + if (alt > MAX_ALT_SETTINGS) + return -EINVAL; + if (alt != (unsigned)-1) { intf = ffs_func_revmap_intf(func, interface); if (intf < 0) @@ -3265,8 +3280,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; } @@ -3573,6 +3590,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;