From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7714BC43334 for ; Wed, 13 Jul 2022 12:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236104AbiGMMBC (ORCPT ); Wed, 13 Jul 2022 08:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236128AbiGMMBB (ORCPT ); Wed, 13 Jul 2022 08:01:01 -0400 X-Greylist: delayed 1189 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 13 Jul 2022 05:00:59 PDT Received: from metanate.com (unknown [IPv6:2001:8b0:1628:5005::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C289F4235 for ; Wed, 13 Jul 2022 05:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metanate.com; s=stronger; h=In-Reply-To:Content-Type:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=8ZCq1iSnvi0O00uuBMOScdqdbc5RwcoliWQLs0MPRVc=; b=Z9D/0 zOzvVLXlw6ceawn/Xw117z0+LKbgtLfyrEvGdT6jyR8dShVBR+WgO+uUDpbj6SVT7ZeUTxVJi4E8V 87giNudYKUWDUv0T3dsns+zIc7IAnp80gcZZahgyabAr573IpNnS1OCB/zzcXR9WpbaKrsC9WvZSp NvKVmNdCDjUSBl404vNSUsvUOeu6I4U6OY22eCrfe2ny7hyjjWP8T4s279+Sqg7DTeHsDg26FxTq/ xObn/LVI471dwKJebtiU6b8sR7meDZxCUn87d3r+xakk9LvfOFs/eKlb0sAXF8TjVsDM9CNyF7oup 7XH/314jjoKDaI9xplhJuxZA9o2tA==; Received: from dougal.metanate.com ([192.168.88.1] helo=donbot) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oBaji-00075W-1G; Wed, 13 Jul 2022 12:40:59 +0100 Date: Wed, 13 Jul 2022 12:40:53 +0100 From: John Keeping To: Jack Pham Cc: Wesley Cheng , balbi@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Thinh.Nguyen@synopsys.com Subject: Re: [PATCH v2 5/5] usb: dwc3: gadget: Increase DWC3 controller halt timeout Message-ID: References: <20220713003523.29309-1-quic_wcheng@quicinc.com> <20220713003523.29309-6-quic_wcheng@quicinc.com> <20220713025643.GC8200@jackp-linux.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220713025643.GC8200@jackp-linux.qualcomm.com> X-Authenticated: YES Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Tue, Jul 12, 2022 at 07:56:43PM -0700, Jack Pham wrote: > Hi Wesley, > > On Tue, Jul 12, 2022 at 05:35:23PM -0700, Wesley Cheng wrote: > > Since EP0 transactions need to be completed before the controller halt > > sequence is finished, this may take some time depending on the host and the > > enabled functions. Increase the controller halt timeout, so that we give > > the controller sufficient time to handle EP0 transfers. > > > > Fixes: 861c010a2ee1 ("usb: dwc3: gadget: Refactor pullup()") > > Suggested-by: Thinh Nguyen > > Signed-off-by: Wesley Cheng > > --- > > Link: > > https://lore.kernel.org/linux-usb/4988ed34-04a4-060a-ccef-f57790f76a2b@synopsys.com/ > > > > drivers/usb/dwc3/gadget.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > > index 41b7007358de..e32d7293c447 100644 > > --- a/drivers/usb/dwc3/gadget.c > > +++ b/drivers/usb/dwc3/gadget.c > > @@ -2476,6 +2476,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) > > dwc3_gadget_dctl_write_safe(dwc, reg); > > > > do { > > + msleep(1); > > Be aware that this probably won't sleep for *just* 1ms. From > Documentation/timers/timers-howto.rst: > > msleep(1~20) may not do what the caller intends, and > will often sleep longer (~20 ms actual sleep for any > value given in the 1~20ms range). In many cases this > is not the desired behavior. > > So with timeout==500 this loop could very well end up iterating for up > to 10 seconds. Granted this shouldn't be called from any atomic context > but just wanted to make sure that the effective increase in timeout as > $SUBJECT intends is made clear here and that it's not overly generous. > > > reg = dwc3_readl(dwc->regs, DWC3_DSTS); > > reg &= DWC3_DSTS_DEVCTRLHLT; > > } while (--timeout && !(!is_on ^ !reg)); Does it make sense to convert this loop to use read_poll_timeout() and make the timeout explicit, something like: ret = read_poll_timeout(dwc3_readl, reg, !(!is_on ^ !(reg & DWC3_DSTS_DEVCTRLHLT)), 100, timeout * USEC_PER_MSEC, true, dwc->regs, DWC3_DSTS); ?