From patchwork Mon Dec 5 20:15:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferry Toth X-Patchwork-Id: 13065058 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 A5924C47089 for ; Mon, 5 Dec 2022 20:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232903AbiLEUPu (ORCPT ); Mon, 5 Dec 2022 15:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbiLEUPr (ORCPT ); Mon, 5 Dec 2022 15:15:47 -0500 Received: from mailfilter05-out40.webhostingserver.nl (mailfilter05-out40.webhostingserver.nl [195.211.74.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9529427FD2 for ; Mon, 5 Dec 2022 12:15:45 -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=dr7UwJp1aWEnCa4twHC7nPXuky/8LKPXZIlvLw50gwY=; b=FiilAHVFYovMsp/DEEMDbX1gG3gpcz315Q+nUTOTDXIpWcAtxGcD8sZLL9ktJL4PIRCsErdW7wg3g XHkTxxmyHesDqCOW1RY435eaIdzPyrbjZ82N2dIRJ9xukVQFf2X78WN9HG1denjgG27VBTQA/xzze8 W1Put4fi07ZFyhsMChyyIEgy/dNqFKalQ5Rd2FGXs47/+NtY/wypFUalv0719UFnWxmPzTGC5mlsIU c8WiWhFZbyIWoI/Izi9qpejhBBJ3QLUKW7ROanWuvv3eZC26eiKhBH/fzet+u+V+69WWLpJkGfL0tY vEIPbfGrQSXT4FPGd+3NclRd62C5szQ== X-Halon-ID: 985df67c-74d9-11ed-9686-001a4a4cb933 Received: from s198.webhostingserver.nl (s198.webhostingserver.nl [141.138.168.154]) by mailfilter05.webhostingserver.nl (Halon) with ESMTPSA id 985df67c-74d9-11ed-9686-001a4a4cb933; Mon, 05 Dec 2022 21:15:43 +0100 (CET) Received: from 2a02-a466-68ed-1-f633-1bb8-92a6-ba5d.fixed6.kpn.net ([2a02:a466:68ed:1:f633:1bb8:92a6:ba5d] helo=delfion.fritz.box) by s198.webhostingserver.nl with esmtpa (Exim 4.96) (envelope-from ) id 1p2HsM-001b54-2t; Mon, 05 Dec 2022 21:15:42 +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 v5 1/2] usb: ulpi: defer ulpi_register on ulpi_read_id timeout Date: Mon, 5 Dec 2022 21:15:26 +0100 Message-Id: <20221205201527.13525-2-ftoth@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221205201527.13525-1-ftoth@exalondelft.nl> References: <20221205201527.13525-1-ftoth@exalondelft.nl> MIME-Version: 1.0 X-Antivirus-Scanner: Clean mail though you should still use an Antivirus Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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. Make 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 Acked-by: Heikki Krogerus --- 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 Mon Dec 5 20:15:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferry Toth X-Patchwork-Id: 13065059 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 DCF89C47089 for ; Mon, 5 Dec 2022 20:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233119AbiLEUQB (ORCPT ); Mon, 5 Dec 2022 15:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233260AbiLEUP5 (ORCPT ); Mon, 5 Dec 2022 15:15:57 -0500 Received: from mailfilter02-out40.webhostingserver.nl (mailfilter02-out40.webhostingserver.nl [195.211.72.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B960B286EA for ; Mon, 5 Dec 2022 12:15:55 -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=AL68zLQaEqSRdRgznjgITv4ps8SL1cEIOEoowj++pC0=; b=LdS12PfvgO5v8km82BezuW5J7/N+8R0QJmVHg5WCv4c2rBVONAILw2o5N2+KXgYO91Zy0658TRUPf o8lpPyIMVCTlQe5ipASaefd3/OsYLGbhrvKQ8g3e+xtusdTdgrwBZilus7V2RkwbgPLhNF1V1Tlc0Z VS/3AT8MmDjNPk9ZfG4vyVS9VCF2K6futTKdwrkRfeXN/WpzXr55i6yaKmaMfgMrOiNOyfN2vkpaQ0 wNtEah/xcTLXS0v28pHx1ZATXIeYXDSsFjdKg40jkO7SmBKqpbMC3HIPbbN/hGl8pW9xyB/r0wqcMW CVGeBWDep4K/pm9cCKIIhUumeLXMMmw== X-Halon-ID: 9e8bd91a-74d9-11ed-aeca-001a4a4cb922 Received: from s198.webhostingserver.nl (s198.webhostingserver.nl [141.138.168.154]) by mailfilter02.webhostingserver.nl (Halon) with ESMTPSA id 9e8bd91a-74d9-11ed-aeca-001a4a4cb922; Mon, 05 Dec 2022 21:15:53 +0100 (CET) Received: from 2a02-a466-68ed-1-f633-1bb8-92a6-ba5d.fixed6.kpn.net ([2a02:a466:68ed:1:f633:1bb8:92a6:ba5d] helo=delfion.fritz.box) by s198.webhostingserver.nl with esmtpa (Exim 4.96) (envelope-from ) id 1p2HsX-001b54-0z; Mon, 05 Dec 2022 21:15:53 +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 v5 2/2] usb: dwc3: core: defer probe on ulpi_read_id timeout Date: Mon, 5 Dec 2022 21:15:27 +0100 Message-Id: <20221205201527.13525-3-ftoth@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221205201527.13525-1-ftoth@exalondelft.nl> References: <20221205201527.13525-1-ftoth@exalondelft.nl> MIME-Version: 1.0 X-Antivirus-Scanner: Clean mail though you should still use an Antivirus Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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. On Intel Merrifield the timeout on the first test write issue is reproducible but it is difficult to find the root cause. Using a mainline 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. We suspect the issue is some kind of timing / race, but merely retrying ulpi_read_id() does not resolve the issue. 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 Acked-by: Thinh Nguyen --- 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; }