Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp606713rwb; Thu, 10 Nov 2022 05:19:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM51qsmB4qyTWusGpWipaLa88DfTJEXf1YJBwQ6M+1ZLXT1RtsWu+yNE5Bw+UpThABvFq+OB X-Received: by 2002:a17:907:3e88:b0:78d:b3f0:b5c0 with SMTP id hs8-20020a1709073e8800b0078db3f0b5c0mr2926186ejc.141.1668086366039; Thu, 10 Nov 2022 05:19:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668086366; cv=none; d=google.com; s=arc-20160816; b=GzOswf8hUQLYjJU+5gR+EBFEo0ppgWsrpxUJcqPcJabABPqmdLqa0woLxZpO6hvhZE OnNSBLLKUPwctAiC2X+pLngPOrGv3svX6qrxNT3AEMeo0rVHBgCCogNIPYwdWd9Mo0fz FyPg2vymqctIRET1mTM1R7z9CIrHRgKUKKTQ2Ygn56dFFpQTetbV5tJWdMuFSX5a1pbz M1uBZ/ha2mC7daXSjjM8ZtFlnqyNSLHqGgcNmq210p5WQgQrK9sU6n9gm0EjU3De30rZ KZ1jzHTUjHmJ2H9TgH/2Lb4yKu84bWuaWusmIT9gv1ivJwRosr0lndZjcfubVw+kZhKu NwrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=Dm5kGQkFYM9g95wGxoFvG2OQeloY1VPaRzyoc4XwDP8=; b=l9pVAkHFbjHHRnEaRqicZFZiw+5HptfXZM4Pn9gIHgAJVcbYIEfCSdXt4EM30WQFKw uUWxIiSbcGb77pbMQx4qiwPS5e2QnEnObQhqDyYHaG7Ja/Vz8omdsyg7VWfoGeoM88xP JcCOyZNPcuaq7a4/Z8pOLdB1f5XmDHQNqAS+xVz9XSM4oec+ByiDhhRwJZ+s/qXmb8pN iy4ltiEak9pUgj07NMRH7B+O+tYZzYfdGsMgPlrRD47pBAi+TDDz3Q+xMZawBOZ22qzf YisrOutIK/j1wUU+Zn3xrulJw5vi9RmhREuKKDlkbyRsnSlsRkUXxKVht3nnA7lksPIy 6DmA== 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc16-20020a1709078a1000b00782da4ff18dsi17631313ejc.668.2022.11.10.05.19.01; Thu, 10 Nov 2022 05:19:26 -0800 (PST) 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiKJMpb (ORCPT + 93 others); Thu, 10 Nov 2022 07:45:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiKJMp3 (ORCPT ); Thu, 10 Nov 2022 07:45:29 -0500 Received: from radex-web.radex.nl (smtp.radex.nl [178.250.146.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C18EF3E084; Thu, 10 Nov 2022 04:45:28 -0800 (PST) Received: from [192.168.1.35] (cust-178-250-146-69.breedbanddelft.nl [178.250.146.69]) by radex-web.radex.nl (Postfix) with ESMTPS id 2DAA4240A8; Thu, 10 Nov 2022 13:45:28 +0100 (CET) Message-ID: Date: Thu, 10 Nov 2022 13:45:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 From: Ferry Toth Subject: Re: [PATCH v1 1/1] usb: ulpi: defer ulpi_register on ulpi_read_id timeout To: Thinh Nguyen Cc: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Heikki Krogerus , Greg Kroah-Hartman , Sean Anderson , Liu Shixin , Andrey Smirnov , Andy Shevchenko References: <20221109221749.8210-1-ftoth@exalondelft.nl> <20221110000643.xdoav4c4653x3tjd@synopsys.com> Content-Language: en-US In-Reply-To: <20221110000643.xdoav4c4653x3tjd@synopsys.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NICE_REPLY_A,NML_ADSP_CUSTOM_MED, SPF_HELO_NONE,SPF_SOFTFAIL 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 (sorry sent html with previous attempt) On 10-11-2022 01:06, Thinh Nguyen wrote: > Hi Ferry, > > On Wed, Nov 09, 2022, Ferry Toth wrote: >> Since commit 0f010171 >> Dual Role support on Intel Merrifield platform broke due to rearranging >> the call to dwc3_get_extcon(). >> >> It appears to be caused by ulpi_read_id() on the first test write failing >> with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via >> DT when the test write fails and returns 0 in that case even if DT does not >> provide the phy. Due to the timeout being masked dwc3 probe continues by >> calling dwc3_core_soft_reset() followed by dwc3_get_extcon() which happens >> to return -EPROBE_DEFER. On deferred probe ulpi_read_id() finally succeeds. >> >> This patch changes ulpi_read_id() to return -ETIMEDOUT when it occurs and >> catches the error in dwc3_core_init(). It handles the error by calling >> dwc3_core_soft_reset() after which it requests -EPROBE_DEFER. On deferred >> probe ulpi_read_id() again succeeds. >> >> Signed-off-by: Ferry Toth >> --- >> drivers/usb/common/ulpi.c | 5 +++-- >> drivers/usb/dwc3/core.c | 5 ++++- >> 2 files changed, 7 insertions(+), 3 deletions(-) >> > Can you split the dwc3 change and ulpi change to separate patches? Thanks for your comments. I will send v2 >> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c >> index d7c8461976ce..d8f22bc2f9d0 100644 >> --- a/drivers/usb/common/ulpi.c >> +++ b/drivers/usb/common/ulpi.c >> @@ -206,8 +206,9 @@ static int ulpi_read_id(struct ulpi *ulpi) >> >> /* Test the interface */ >> ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); >> - if (ret < 0) >> - goto err; >> + if (ret < 0) { >> + return ret; >> + } >> >> ret = ulpi_read(ulpi, ULPI_SCRATCH); >> if (ret < 0) >> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >> index 648f1c570021..e293ef70039b 100644 >> --- a/drivers/usb/dwc3/core.c >> +++ b/drivers/usb/dwc3/core.c >> @@ -1106,8 +1106,11 @@ static int dwc3_core_init(struct dwc3 *dwc) >> >> if (!dwc->ulpi_ready) { >> ret = dwc3_core_ulpi_init(dwc); >> - if (ret) >> + if (ret) { >> + dwc3_core_soft_reset(dwc); > We shouldn't need to do soft reset here. The controller shouldn't be at > a bad/incorrect state at this point to warrant a soft-reset. There will > be a soft-reset when it goes through the initialization again. It doesn't go through the initialization again unless we set -EPROBE_DEFER. And when we make ulpi_read_id() return -EPROBE_DEFER it will goto err0 here, so skips dwc3_core_soft_reset. Do you mean you prefer something like: if (ret) {     if (ret == -ETIMEDOUT) ret = -EPROBE_DEFER;     else goto err0; } >> + ret = -EPROBE_DEFER; > We shouldn't automatically set every error status to correspond to > -EPROBE_DEFER. Check only the approapriate error codes (-ETIMEDOUT + > any other?). Other could be -ENOMEM. I think no need to do any new handling for that. >> goto err0; >> + } >> dwc->ulpi_ready = true; >> } >> >> -- >> 2.34.1 >> > Thanks, > Thinh