Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3120160imu; Mon, 17 Dec 2018 13:44:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/WeeWvTIVIaFwQurOo67Cg4al1xb3QNhcG3HhY3z0iWgExnRlk0ZXCKe4CphQEI7Ud9d2/K X-Received: by 2002:a63:4101:: with SMTP id o1mr13396635pga.447.1545083084367; Mon, 17 Dec 2018 13:44:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545083084; cv=none; d=google.com; s=arc-20160816; b=sPkeSfV3t2Eeh4Nx8OW17IPletkSiAtykJ8GzWR+fx8eJ6/ouFllR2LJgXTPIrxbpe 0WRqFWbdEfaey62DVOyuj/yTr2aQVemZsHTYRWf4giyCFdfq4pKjT6lX11shZl4JI8Ek voOWv8MUnWCdf10u+kboVeg96+WwVo/PhjyRyRHD4DHs8jvRwuF0U9rhq8kfjT5x0Vja Fn3ZaXX5DXnh4L+ybon/0+1qJFViP6s9hDv2zvkGnzh3cbo7PqRSEP85mChGNmGA9aYr cykc3fSOLHsCKc+W2l/4z4jiqv0/D51HLZsxQTQW/BkoQ1Qwh1Va4QDC9SH5Wzpjavjr 4q3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=evAEGb1hnlKeJGbQkCdqCsHQhJBA5yHj49QR/0O6GOQ=; b=TJo+5uxJ+TPy6q/559e3124RmcULCVFLBu7JWsKs0mrWvmG+BDiyesd2OjiG8FWg/u x9JxQtoPaPmNHBiWFbqJlAhsPFMEPAY5yybRLbN6Nl/YA6vSXrOySmdPr564uQDc1sWW iA124JoPVERrMSuKUOJgLGJbP4kawmSxBXqO05TX2AgOtr6fqfkeEOh6GpHLQkIBE52o hKNzDiCb6GklYZAyEK8DGSIgmHU8w191Ywvbu3hptg1js1i6yq43KWzSqPgYcMLXkbd4 su1bsoTLmunDDWSa78mOaOiZYRVzdsvbtpHR405b//6eyXX6tvw0kFG/MeWR1Bj+y3TQ nPQw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si248672pfm.50.2018.12.17.13.44.29; Mon, 17 Dec 2018 13:44:44 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388187AbeLQQNC (ORCPT + 99 others); Mon, 17 Dec 2018 11:13:02 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:56502 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727727AbeLQQNC (ORCPT ); Mon, 17 Dec 2018 11:13:02 -0500 Received: (qmail 2063 invoked by uid 2102); 17 Dec 2018 11:13:01 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 17 Dec 2018 11:13:01 -0500 Date: Mon, 17 Dec 2018 11:13:01 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Paul Elder cc: laurent.pinchart@ideasonboard.com, , , , , , , Subject: Re: [PATCH v2 4/6] usb: gadget: add mechanism to specify an explicit status stage In-Reply-To: <20181217060216.26368-5-paul.elder@ideasonboard.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 17 Dec 2018, Paul Elder wrote: > A usb gadget function driver may or may not want to delay the status > stage of a control OUT request. An instance it might want to is to > asynchronously validate the data of a class-specific request. > > A function driver that wants an explicit status stage should set the > newly added explicit_status flag of the usb_request corresponding to the > data stage. Later on the function driver can explicitly complete the > status stage by enqueueing a usb_request also with the explicit_status > flag set, and with the zero flag set to 1 for ACK, or 0 for STALL. This last part seems awkward. Why not have the function driver call usb_ep_set_halt() to indicate ep0 should send a STALL? That's already part of the API; no need to add another way of doing the same thing. > To support both explicit and implicit status stages, a UDC driver must > call the newly added usb_gadget_control_complete function right after > calling usb_gadget_giveback_request. To support the explicit status > stage, it might then check what stage the usb_request was queued in, or > the explicit_status flag, and the zero flag for what status to send. > > Signed-off-by: Paul Elder > v1 Reviewed-by: Laurent Pinchart > --- > Changes from v1: > > Complete change of API. Now we use a flag that should be set in the > usb_request that is queued for the data stage to signal to the UDC that > we want to delay the status stage (as opposed to setting a flag in the > UDC itself, that persists across all requests). We now also provide a > function for UDC drivers to very easily allow implicit status stages, to > mitigate the need to convert all function drivers to this new API at > once, and to make it easier for UDC drivers to convert. > > drivers/usb/gadget/udc/core.c | 33 +++++++++++++++++++++++++++++++++ > include/linux/usb/gadget.h | 10 ++++++++++ > 2 files changed, 43 insertions(+) > > diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c > index af88b48c1cea..e99481ef9147 100644 > --- a/drivers/usb/gadget/udc/core.c > +++ b/drivers/usb/gadget/udc/core.c > @@ -894,6 +894,39 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); > > /* ------------------------------------------------------------------------- */ > > +/** > + * usb_gadget_control_complete - complete the status stage of a control > + * request, or delay it > + * Context: in_interrupt() > + * > + * @gadget: gadget whose control request's status stage should be completed > + * @explicit_status: true to delay status stage, false to complete here > + * > + * This is called by device controller drivers after returning the completed > + * request back to the gadget layer, to either complete or delay the status > + * stage. > + */ > +void usb_gadget_control_complete(struct usb_gadget *gadget, > + unsigned int explicit_status) This signature is incomplete. You also need to know the status of the request that was just given back... > +{ > + struct usb_request *req; > + > + if (explicit_status) > + return; > + > + /* Send an implicit status-stage request for ep0 */ > + req = usb_ep_alloc_request(gadget->ep0, GFP_ATOMIC); ... because none of this should happen if the previous request completed unsuccessfully. Alan Stern