From patchwork Sun Nov 20 15:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferry Toth X-Patchwork-Id: 23433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1165204wrr; Sun, 20 Nov 2022 07:39:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Nd3gnhKjUe2JPV+E1IhWfx3LJVay47yCo98FH9JOwvRpMQOTc44IUmsfJKDjVmiyoxVra X-Received: by 2002:a63:da45:0:b0:434:aa27:6bee with SMTP id l5-20020a63da45000000b00434aa276beemr13806669pgj.388.1668958745245; Sun, 20 Nov 2022 07:39:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668958745; cv=none; d=google.com; s=arc-20160816; b=V3K1ewltek/A2YGnkt3XI3Pefw3lPyoBJSLoI4xCFR0jGc1ThS7qxFjErOHDGyWpvE sFBXQSUBfknr/vQ21STW0mTVzfNx1h+P1RPunhqqrIuyeD4og+iEeOLBWFbnSkEnTxxz an4jrAiGTXsnOZ67Ldi3USQ64PqdrXgRy7u7QWQw3vI6fuq8kLukr4SQ4bi77C5QeZ+0 7ix8+QP0j2Q9r/4x8GXjlAuPCS0+mwaAvJ04V5p0RkN8gJtrTpQ2P525hJGgQAofIl6B MHiH/XWsEyoQOtB2bXWkwEVG7OeTs1F5lFLRRgdrZOOlioAeqXt5Dafub5bKPrYlGvi6 YQUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pL3v1LXTDSwlVQKeW2cdKoypwqG73N7k6gDtgGMdYn0=; b=C9wVnbCdZqWffKHI+SVTgG6/sm2DwP28z8yY4F273TdNoe2ku9hb0KMNFxsIQ0IeMJ F2jdkZesisdtIKs56TtI19JWoy9jaUtLzjy+WkgMJjAzETXHvvtcOtsAM82xIKt/K+ud 5CuERNEIEUj/QyHWASe+E6C8INsAz6AkrdgxkEwLXJOaJWzXCYmb51ND+2CNtZjZ72m6 EUM0KF1dI/7rfl0ymdw+/SqpAO/4zBMP2SqXgu0PcBn7MDCbc5/gxlpApqwG1w39VyTR hwi2P+6tA53t8ZQzoTZ2dTqepS9AFx22rDxXBNVlF4axGtNTjoqSsfXZn/5zyHue39l/ 3aaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@exalondelft.nl header.s=whs1 header.b=fykCvFRd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=exalondelft.nl Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a170902744100b0017a8a84a3b6si8307676plt.106.2022.11.20.07.38.51; Sun, 20 Nov 2022 07:39:05 -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; dkim=pass header.i=@exalondelft.nl header.s=whs1 header.b=fykCvFRd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=exalondelft.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbiKTPhg (ORCPT + 99 others); Sun, 20 Nov 2022 10:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbiKTPhd (ORCPT ); Sun, 20 Nov 2022 10:37:33 -0500 Received: from mailfilter05-out40.webhostingserver.nl (mailfilter05-out40.webhostingserver.nl [195.211.74.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE55921A9 for ; Sun, 20 Nov 2022 07:37:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=exalondelft.nl; s=whs1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=pL3v1LXTDSwlVQKeW2cdKoypwqG73N7k6gDtgGMdYn0=; b=fykCvFRdSymPbE7P4/0KI1oXYDb0vKv3BSSHwC5nCsm4tkAj1iNWhsuZjswgBU2b2BXR8+Fyox9Vv Zxll944e+9uco78mCsfQjRFyi7rJ7e/D3Du6bSYJuvk3hSiThSIdV0FLWYjOU7agxCYh7UraQARJ9n oFKWov1IvO/U98EIrFo7w4VXmRx6PR1E5QLdielzxlBzn90JZs7lVppmttEVCaanu6b+Z+//IyLGzV iszTq5dL4jJD7s8rDMfDqrMZ5lwtRLDb36m3oWCL3JkZxNruxbNy1kj3Dex0J9yzNgvtVawtz49fS8 2v435afgopxECdTXJA3KtpUGFjgiS6w== X-Halon-ID: 3bab168f-68e9-11ed-9686-001a4a4cb933 Received: from s198.webhostingserver.nl (s198.webhostingserver.nl [141.138.168.154]) by mailfilter05.webhostingserver.nl (Halon) with ESMTPSA id 3bab168f-68e9-11ed-9686-001a4a4cb933; Sun, 20 Nov 2022 16:37:25 +0100 (CET) Received: from 2a02-a466-68ed-1-a813-1b80-f6b2-b786.fixed6.kpn.net ([2a02:a466:68ed:1:a813:1b80:f6b2:b786] helo=delfion.fritz.box) by s198.webhostingserver.nl with esmtpa (Exim 4.96) (envelope-from ) id 1owmNp-004Y9S-1U; Sun, 20 Nov 2022 16:37:25 +0100 From: Ferry Toth To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Heikki Krogerus , Greg Kroah-Hartman , Thinh Nguyen , Sean Anderson , Liu Shixin , Ferry Toth , Andrey Smirnov , Andy Shevchenko , Ferry Toth , stable@vger.kernel.org Subject: [PATCH v4 1/2] usb: ulpi: defer ulpi_register on ulpi_read_id timeout Date: Sun, 20 Nov 2022 16:37:03 +0100 Message-Id: <20221120153704.9090-2-ftoth@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221120153704.9090-1-ftoth@exalondelft.nl> References: <20221120153704.9090-1-ftoth@exalondelft.nl> MIME-Version: 1.0 X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750030085112711844?= X-GMAIL-MSGID: =?utf-8?q?1750030085112711844?= Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present") 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. As a result usb probe completes without phy. On Intel Merrifield the issue is reproducible but difficult to find the root cause. Using an ordinary kernel and rootfs with buildroot ulpi_read_id() succeeds. As soon as adding ftrace / bootconfig to find out why, ulpi_read_id() fails and we can't analyze the flow. Using another rootfs ulpi_read_id() fails even without adding ftrace. Appearantly the issue is some kind of timing / race, but merely retrying ulpi_read_id() does not resolve the issue. This patch makes ulpi_read_id() return -ETIMEDOUT to its user if the first test write fails. The user should then handle it appropriately. A follow up patch will make dwc3_core_init() set -EPROBE_DEFER in this case and bail out. Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT") Cc: stable@vger.kernel.org Signed-off-by: Ferry Toth --- drivers/usb/common/ulpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c index d7c8461976ce..60e8174686a1 100644 --- a/drivers/usb/common/ulpi.c +++ b/drivers/usb/common/ulpi.c @@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulpi) /* Test the interface */ ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); if (ret < 0) - goto err; + return ret; ret = ulpi_read(ulpi, ULPI_SCRATCH); if (ret < 0) From patchwork Sun Nov 20 15:37:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferry Toth X-Patchwork-Id: 23434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1165362wrr; Sun, 20 Nov 2022 07:39:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf4iruquWsIY9pmmbQ/+Jcjbes+0iYPZjuFaoXu3ZhLGe5ZtLrszLkHPfmyer5+U4hiFUjDD X-Received: by 2002:a17:90b:1bc6:b0:218:4d16:cecf with SMTP id oa6-20020a17090b1bc600b002184d16cecfmr16305682pjb.96.1668958774261; Sun, 20 Nov 2022 07:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668958774; cv=none; d=google.com; s=arc-20160816; b=aavmJflktkbJYtFp/cPngRct7t4vMfzw8V2qMKcUiG4hBXFNz5O5P1qwogVbZmAVpB ytQVkXcCp6K+WwevMDqCY75S3t3ARQ7lgBZlJ4fHOSa4HbAUxpAGru8oYwZs6GWsZjjz nml3uL61XbGH0Y/IOCt7SfZgWBITpSNj+n3QOe3n8h9NbCvErGDI2ghzSdfMnAiteWD1 hHNhshTcOqf/x7mHKhneJ/vJ7A1j2JM/383yb2PMTDre/xEJuqcFubQhQYpy51THqyMv 7mXIhWWdEGxxlnCU+sf8cx8lBbjRRKWJdZVfxA6rNQMh/FMyVXyzGG6VkxyPqKKVCea5 KtDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QQeRuPxvis9IApqQRvO4LcaXKr9jzOl2EQ5uHPW9pYc=; b=FvTBjnT0iVD2G6L/tI5Rd4g7Y48A9UcuurUGfj+9oUTk6EWJqV+w359sbriRamO2HP uzBR6mS+WVQCwsx9NHEDHSq303+Jc/gIukdB7NAyKd6616lvoa+eSpWTlEaxWztLBexZ A32op1CJRU9+7hg+xdpAVy3Y3cJiujvwYYmiAZDiguRTtlEx+umDmTl270nFiEfHEt+2 2Rrp2sws4yhNsbPOUaIEiTbG+tQFdelTyMyqi4Ozj5ZhxLo4aLyaclQjxIpkzkkgDtJy qMmWGAgZqvF9hnFV3wswrXshWjKXLsgMw6dOQqPclVspB5Wyz6Ckcp53Aswz00+RuEFP to3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@exalondelft.nl header.s=whs1 header.b=g3TCgOFN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=exalondelft.nl Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j193-20020a638bca000000b0046ed15af9d1si8861886pge.213.2022.11.20.07.39.21; Sun, 20 Nov 2022 07:39:34 -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; dkim=pass header.i=@exalondelft.nl header.s=whs1 header.b=g3TCgOFN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=exalondelft.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229722AbiKTPhp (ORCPT + 99 others); Sun, 20 Nov 2022 10:37:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229730AbiKTPhk (ORCPT ); Sun, 20 Nov 2022 10:37:40 -0500 Received: from mailfilter01-out40.webhostingserver.nl (mailfilter01-out40.webhostingserver.nl [195.211.73.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D68321A9 for ; Sun, 20 Nov 2022 07:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=exalondelft.nl; s=whs1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=QQeRuPxvis9IApqQRvO4LcaXKr9jzOl2EQ5uHPW9pYc=; b=g3TCgOFNr1Fncb+ZK5iRIcw8GXA+ex+WN5HUzj0qtTb56wtMW4AugvL+IJvh80PVgFl5zewDHN1/R qPFAL4jZV0CUoQunPafTOGoqNNISyJ90Jfbq4aHBwkg34EI0FPEEd4EgwRTDt5+Xb7JaaHRjoSkijW RSPegHapfwbjmg/oFbDmskCy/CkPYteVqwpzTbprNqitXOuWVTuyZqCPYV2xGpjLOf0vo5qxsQQYJk KK+6eW+Oi6lUUNuZzGTujXea7c2zodqEJlukcdMqGC+yZaUACvTg4/YdxJ8wYp0/Uuh2rtiZkroHko bUPNq3o5Di3lzY7lZTGVjRUBsxWh4dA== X-Halon-ID: 41c3f0a1-68e9-11ed-a6af-001a4a4cb906 Received: from s198.webhostingserver.nl (s198.webhostingserver.nl [141.138.168.154]) by mailfilter01.webhostingserver.nl (Halon) with ESMTPSA id 41c3f0a1-68e9-11ed-a6af-001a4a4cb906; Sun, 20 Nov 2022 16:37:35 +0100 (CET) Received: from 2a02-a466-68ed-1-a813-1b80-f6b2-b786.fixed6.kpn.net ([2a02:a466:68ed:1:a813:1b80:f6b2:b786] helo=delfion.fritz.box) by s198.webhostingserver.nl with esmtpa (Exim 4.96) (envelope-from ) id 1owmNz-004Y9S-2T; Sun, 20 Nov 2022 16:37:35 +0100 From: Ferry Toth To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Heikki Krogerus , Greg Kroah-Hartman , Thinh Nguyen , Sean Anderson , Liu Shixin , Ferry Toth , Andrey Smirnov , Andy Shevchenko , Ferry Toth , stable@vger.kernel.org Subject: [PATCH v4 2/2] usb: dwc3: core: defer probe on ulpi_read_id timeout Date: Sun, 20 Nov 2022 16:37:04 +0100 Message-Id: <20221120153704.9090-3-ftoth@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221120153704.9090-1-ftoth@exalondelft.nl> References: <20221120153704.9090-1-ftoth@exalondelft.nl> MIME-Version: 1.0 X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750030027015328983?= X-GMAIL-MSGID: =?utf-8?q?1750030115588548757?= Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present"), 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() masking the timeout on the first test write. In the past dwc3 probe continued by calling dwc3_core_soft_reset() followed by dwc3_get_extcon() which happend to return -EPROBE_DEFER. On deferred probe ulpi_read_id() finally succeeded. Due to above mentioned rearranging -EPROBE_DEFER is not returned and probe completes without phy. As we now changed ulpi_read_id() to return -ETIMEDOUT in this case, we need to handle the error by calling dwc3_core_soft_reset() and request -EPROBE_DEFER. On deferred probe ulpi_read_id() is retried and succeeds. Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT") Cc: stable@vger.kernel.org Signed-off-by: Ferry Toth --- drivers/usb/dwc3/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 648f1c570021..2779f17bffaf 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1106,8 +1106,13 @@ static int dwc3_core_init(struct dwc3 *dwc) if (!dwc->ulpi_ready) { ret = dwc3_core_ulpi_init(dwc); - if (ret) + if (ret) { + if (ret == -ETIMEDOUT) { + dwc3_core_soft_reset(dwc); + ret = -EPROBE_DEFER; + } goto err0; + } dwc->ulpi_ready = true; }