Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1026476rdb; Sun, 20 Aug 2023 13:39:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb/yHxwmokX/G+QfZXcG+lckBqp2lBDfFF1V8iahCqL3fYk6XM8sTprk5wGU2f1g/l5KvM X-Received: by 2002:a05:6402:342:b0:525:6d74:7122 with SMTP id r2-20020a056402034200b005256d747122mr3114239edw.30.1692563947994; Sun, 20 Aug 2023 13:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692563947; cv=none; d=google.com; s=arc-20160816; b=DZRSnlD9wy11w7JtXJQPKPw8vS2pe62RJKb4/ZgDsl3Vv+u2WKjHPFpbwf4tD2YBOK sqq5VIis/OEfhdnj5pNUEfnoa+JppeuX2ApFWFMIwtUbyVoGUjgl8rANbaiK048i9ied 7uB+Bg/LqKoPYbwkUthwaG8Tsxl8vEYeT3mzR3ZPQh2+umtN+1cjB2cU5Nfv7l78uJ9Y c8bTXtr0lFhOxBfvdTvMgDctwZTROycw8m7gf38CP3MZ/v8+JIxXZ8wAyRTJR8RGfbfy 4luamaUyDJNcmb5+ja/sw6tivnVG1qq5FMwBkW7+Rq+MyuaUfvJp4pfaM01Ig2UEO0X2 ni1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=oJTBWpmc0lo7fDXJU1ebRv9YVUipge+6AJKLXjBTSbQ=; fh=CZ/kJV5Z2+9aeNn4fizkMkwdBslDsd2n+md1Qg3ZReI=; b=SwPEuX0F0jQV1uLOPWJ1bhH56esg5xWR+HuhepNOaWKzFSnXWhypHYiQf3KrS8uabK yzaueEOPxMre9dDnMbShTnynKmwkux/TI1Mtl4T2P/fNJQnImPvBUu11863++3eFzzeO AqXFOM/6LeqdwVUnjm1m21r5Ui9Uduhwdh7tzx0jye6UVE5DJtJoM4oDvpcvY49Fp3mT uBLPiwXhI7Lp2VuZ7Uia9hxpkxDULm9MEqf2m65arhRtxTxUwP4WHs23dzZIk+Oi5+GA LAXsXnB8aRESCni73rdgLhGh+DqymZpULEfLVyk9cSVMBqPSfU6dh6TVL2OvWuBMHnoD tcrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a056402125600b005232b8d1278si4699632edw.79.2023.08.20.13.38.43; Sun, 20 Aug 2023 13:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231138AbjHTOZU (ORCPT + 99 others); Sun, 20 Aug 2023 10:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbjHTOZT (ORCPT ); Sun, 20 Aug 2023 10:25:19 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id C09222723 for ; Sun, 20 Aug 2023 07:20:39 -0700 (PDT) Received: (qmail 90313 invoked by uid 1000); 20 Aug 2023 10:20:38 -0400 Date: Sun, 20 Aug 2023 10:20:38 -0400 From: Alan Stern To: Thinh Nguyen Cc: Andrey Konovalov , Felipe Balbi , Greg Kroah-Hartman , USB list , LKML Subject: Re: dwc3: unusual handling of setup requests with wLength == 0 Message-ID: References: <20230818010815.4kcue67idma5yguf@synopsys.com> <20230818031045.wovf5tj2un7nwf72@synopsys.com> <20230818194922.ys26zrqc4pocqq7q@synopsys.com> <45d9ef53-e2be-4740-a93a-d36f18a49b39@rowland.harvard.edu> <20230819000643.7mddkitzr4aqjsms@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230819000643.7mddkitzr4aqjsms@synopsys.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 19, 2023 at 12:06:53AM +0000, Thinh Nguyen wrote: > On Fri, Aug 18, 2023, Alan Stern wrote: > > Actually I agree with you. When a new SETUP packet arrives before the > > old control transfer has finished, the UDC driver should cancel all > > pending requests and then invoke the ->setup() callback. (I don't think > > there is a standard error code for the cancelled requests; net2280 seems > > to use -EPROTO whereas dummy-hcd seems to use -EOVERFLOW.) > > Those are very odd choice of error codes for cancelled request. Even > though the gadget side doesn't have very defined error codes, I try to > follow the equivalent doc from the host side > (driver-api/usb/error-codes.rst), which is -ECONNRESET. > > Whenever I see -EPROTO, I associate that to a specific host error: > transaction error. For -EOVERFLOW, I think of babble errors. Do you have a suggestion for an error code that all the UDCs should use in this situation? -ECONNRESET is currently being used for requests that were cancelled by usb_ep_dequeue(). Would -EREMOTEIO be more suitable for requests attached to an aborted control transfer? > > My impression from his initial email was that something different was > > happening. It sounded like his ->setup() callback was invoked with > > wLength = 0, but before the Raw Gadget driver was ready to queue a > > response request, the UDC driver sent an automatic status, at which > > point the host sent another SETUP packet. So the gadget driver got two > > ->setup() callbacks in a row with no chance to do anything in between. > > What else should the gadget driver do? There's no data stage for > wLength=0. So when wLength is 0, dwc3 should not automatically handle the Status stage. It should wait for the gadget driver to submit an explicit Status-stage request. As far as I know, all the gadget drivers will do this. > > > > This may be a holdover from the early days of the Gadget subsystem. My > > > > memory from back then isn't very good; I vaguely recall that the first > > > > UDC drivers would queue their automatic Status-stage requests if wLength > > > > was 0 and ->setup() returned 0 (which would explain why > > > > USB_GADGET_DELAYED_STATUS had to be invented). Unless I'm completely > > > > confused, that's not how UDC drivers are supposed to act now. > > > > I did a little checking. The USB_GADGET_DELAYED_STATUS mechanism was > > introduced for use by the composite framework -- not in order to make a > > UDC driver work properly. > > Hm... perhaps we can update so that it's applicable outside of the > composite framework. Currently dwc3 treats it as such, which may not > work if the gadget driver does not know about USB_GADGET_DELAYED_STATUS. I think USB_GADGET_DELAYED_STATUS belongs entirely inside the composite framework and it should not be used by UDC drivers at all. That return code makes some sense in composite.c, because the composite framework juggles several function drivers in a single gadget. It has to know when all of them are ready to complete a configuration change; it can't assume each function is ready when the callback returns. An alternative approach for composite.c would be _always_ to assume that functions aren't ready until they have called usb_composite_setup_continue(). However, doing this would require auditing each function driver. > dwc3 parse the SETUP data and determine whether it's a 3-state or > 2-stage control transfer. If wLength > 0, then it must be a 3-stage > control transfer. The dwc3 driver would not queue the status immediately > until the data stage is completed. > > To enforce the gadget driver to manually queue the status would take > some effort to ensure all the UDC driver comply to it. We would also > need to update the composite framework. The composite framework already does the right thing. And as Andrey said, most if not all of the other UDC drivers already behave this way. Alan Stern