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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 769A7C982CC for ; Sun, 20 Sep 2026 06:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Z3+Fx9EZEE+VQ2/YVvwLsbnZUCmzfjGk9Iv40ZT2s+o=; b=CZpBjg2Y/N3SykhtHqnWfCXPv8 GxsfSpWSbW5d4hhsVWtyQ0VuyvyyVmP0VPLX3R/OxpYts4hxIMcBeAxFCqOmZP3DNTJL16tveWDMK VB3hDT8mhD1F5PUC4HMXovOfCrAz6Bl7OumZReUC8HfsGxZvNSl8OvpjXuwJbPjmaqOQMH++F4e7o z1DL60F98KlzhL+mT+piBxg/AVNUrYpxtTh1G+3x+CtjyrOkUbWPIHyoBEYhmgQFSU9vm7N+kRCGP ldP4qkoWSsOPiKYOMkytNtePI9RjYFIcVKpDeK2ohROK8dz7EOO+62ao8QmlUAGjvBTQlRn+5Wpk/ tc1rVVzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8AQN-0000000GxsU-0PWU; Sun, 20 Sep 2026 05:49:15 +0000 Received: from proxy25213.mail.163.com ([103.129.252.13]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8AQK-0000000Gxrm-20uY for linux-arm-kernel@lists.infradead.org; Sun, 20 Sep 2026 05:49:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Z3 +Fx9EZEE+VQ2/YVvwLsbnZUCmzfjGk9Iv40ZT2s+o=; b=nkKW5prFP4eZ4hKYBY OxqKTBzPbriILyLcLBPOsdnB3Ael6YuXSjDjjBhMGTQlGyamj2wJlgdl481EDZ5J uUqImrus8zyMQ9F94kRV2/faxn/ofvEoey4MsTWwbFr+y3VvciDZLZ/32auEQnDC 1DfHJp5ph9NBsXkmDGea0TGtY= Received: from localhost.localdomain (unknown []) by gzsmtp3 (Coremail) with SMTP id PikvCgD3v_VZc69qjRGcAA--.48413S2; Sun, 20 Sep 2026 13:47:05 +0800 (CST) From: Linkui Xiao To: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linkui Xiao , stable@vger.kernel.org Subject: [PATCH net v2] net: stmmac: request the MDIO reset GPIO only once Date: Sun, 20 Sep 2026 13:47:03 +0800 Message-Id: <20260920054703.1897755-1-xiaolinkui@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: PikvCgD3v_VZc69qjRGcAA--.48413S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFWxKrWUKFW7Jr48Gw17ZFb_yoWruw4Up3 y3Zay5ArykJr4xtw4kJw48ZF9Ykay3tr4Uuw109rWS9a1DKrWavr1Sqry5ZFy7KrWDWFya qr18uF1Uua1qyaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UYiiDUUUUU= X-CM-SenderInfo: p0ld0z5lqn3xa6rslhhfrp/xtbBqRl5UGqvc1kKygAA32 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260919_224912_769323_935270DA X-CRM114-Status: GOOD ( 15.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Linkui Xiao stmmac_mdio_reset() calls devm_gpiod_get_optional() every time it runs. A GPIO line can only be requested once, so from the second call on gpiod_request_commit() returns -EBUSY. devm_gpiod_get_optional() only turns -ENOENT into NULL, hence the error is passed straight back and stmmac_mdio_reset() bails out before pulsing "snps,reset" and before running the STE101P MDC workaround. The first call, made by of_mdiobus_register(), succeeds, so the failure is only visible later on: every resume that does not use WoL goes through stmmac_resume() -> stmmac_mdio_reset(), and that caller ignores the return value, so the PHY silently stays un-reset. The descriptor used to be requested exactly once: stmmac_mdio_reset() resolved "snps,reset-gpio" itself and cached the GPIO number in stmmac_mdio_bus_data::reset_gpio, and commit ae26c1c6cb9b ("stmmac: fix PHY reset during resume") relies on that cache to reuse the line on every call. commit 7c86f20d15b7 ("net: stmmac: use GPIO descriptors in stmmac_mdio_reset") replaced it with a devm_gpiod_get_optional() that caches nothing, so the request is repeated on every call and fails from the second one on. Request the GPIO in stmmac_mdio_register(), at probe time, and keep the descriptor in struct stmmac_priv. This is where devm-gpiod is meant to be used: the line is acquired with the device and released with it, and any failure to acquire it is reported during probe instead of being ignored by stmmac_resume(). stmmac_mdio_reset() then only pulses the cached line. The request is still gated on mdio_bus_data->needs_reset, which is the condition that installs the reset callback, and on the device using DT, as the reset itself is. Fixes: 7c86f20d15b7 ("net: stmmac: use GPIO descriptors in stmmac_mdio_reset") Cc: stable@vger.kernel.org Signed-off-by: Linkui Xiao --- Changes in v2: - Do not request the GPIO from stmmac_mdio_reset(); request it once in stmmac_mdio_register() at probe time instead. (Maxime Chevallier) drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 ++ .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 7582fca63741..986fb43db45f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -25,6 +25,7 @@ #include #include +struct gpio_desc; struct stmmac_pcs; struct stmmac_resources { @@ -287,6 +288,7 @@ struct stmmac_priv { unsigned int pause_time; struct mii_bus *mii; + struct gpio_desc *mdio_reset_gpio; struct stmmac_pcs *integrated_pcs; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index afe98ff5bdcb..346f93f86abe 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -386,15 +386,8 @@ int stmmac_mdio_reset(struct mii_bus *bus) #ifdef CONFIG_OF if (priv->device->of_node) { - struct gpio_desc *reset_gpio; u32 delays[3] = { 0, 0, 0 }; - reset_gpio = devm_gpiod_get_optional(priv->device, - "snps,reset", - GPIOD_OUT_LOW); - if (IS_ERR(reset_gpio)) - return PTR_ERR(reset_gpio); - device_property_read_u32_array(priv->device, "snps,reset-delays-us", delays, ARRAY_SIZE(delays)); @@ -402,11 +395,11 @@ int stmmac_mdio_reset(struct mii_bus *bus) if (delays[0]) msleep(DIV_ROUND_UP(delays[0], 1000)); - gpiod_set_value_cansleep(reset_gpio, 1); + gpiod_set_value_cansleep(priv->mdio_reset_gpio, 1); if (delays[1]) msleep(DIV_ROUND_UP(delays[1], 1000)); - gpiod_set_value_cansleep(reset_gpio, 0); + gpiod_set_value_cansleep(priv->mdio_reset_gpio, 0); if (delays[2]) msleep(DIV_ROUND_UP(delays[2], 1000)); } @@ -608,6 +601,14 @@ int stmmac_mdio_register(struct net_device *ndev) if (!mdio_bus_data) return 0; + if (mdio_bus_data->needs_reset && dev_of_node(priv->device)) { + priv->mdio_reset_gpio = + devm_gpiod_get_optional(priv->device, "snps,reset", + GPIOD_OUT_LOW); + if (IS_ERR(priv->mdio_reset_gpio)) + return PTR_ERR(priv->mdio_reset_gpio); + } + stmmac_mdio_bus_config(priv); new_bus = mdiobus_alloc(); -- 2.25.1