From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo2-f43.google.com (mail-oo2-f43.google.com [74.125.231.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28FFC439327 for ; Sun, 27 Sep 2026 18:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.231.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790535154; cv=none; b=Jy2e5Kid2FTOEihMmzme4EAu7LnT6oHCwaXPGavC4xWY3KJb9HBFbo8yfFLkVUd3UmOOMZHFAA6JaaOvSvmYdPufUCDE1QUnbsBe93uBlw1R7UMFQzuJC+mRFN44fHICtfEN4CNSuUCNlgBtohQEnZrM2L2xefucFyZBOlVa/8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790535154; c=relaxed/simple; bh=psnWFMW3NPVNytYJTkQa/ZphUpHOQe34G4oYriA8Hk0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J66wNoFYCtt406wyf1ilR8hV2eo+6saoW1Fpmr0/VL0sGNdLEdjy+jxIkd95a1s2M2VH52MOSIr2PFk9ab/aKSOT8EdSbLkE4hlF4rHgHKxWIiCyhcSk2Ua0sLs7tSHI2a8O+mSuBcW8v9DEE+8NeoBdoCXJUUlVAE8F4y5sn6o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hCFI4/PP; arc=none smtp.client-ip=74.125.231.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hCFI4/PP" Received: by mail-oo2-f43.google.com with SMTP id 006d021491bc7-6d7e33da780so475198eaf.3 for ; Sun, 27 Sep 2026 11:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790535152; x=1791139952; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DLWTLjVNNOaJBBp+6jLPkB34blfAphSZQL2nUEax2lA=; b=hCFI4/PP/I8+Pjuhph5Qb/YPTMW7JLaruGftSminAHhJeM79Se8FSuOJNjireWOd6k ZSlo4zaR8ryG5OgLgO8VQhWroxHnP8jQLWPa15N4A/bXREgWfcGa29tqN46PrzSSs2Jp nUumMAmK9dAeoHagZcdXWaEgOoVt99QtEsNzms9NTrhZI/tM3Uq8wFeOgJeO3zi9sMQa 4K8u+zVJUvsc6IOIrsjgWAb30tb2GSpQuClCneJBWEv1vyHCYalBfOKhpM8D3e0uVr2U ja47VwIJMjxJihTyoP+PaM5iXuRhUKmfFMt8ivrEO+sffy7+0iWshFRYygjHLelcA9rX bRkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790535152; x=1791139952; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DLWTLjVNNOaJBBp+6jLPkB34blfAphSZQL2nUEax2lA=; b=dHHIP31ILdVOjPKzDrpPTyx2AIEpEHjUKB2Ar1FdD6tLvzbd7VNHmuRUbWH5RYJDJO ZYAOvTcT3feRi7XuFrynhMEAGbAda4ZwGE1oOpT44H65/MnfDEJzx68pJ3eY6vP7Hp8d OVCqwtjgSE9ACEp5ZQb8iGYtLKBxG3nsBGE2hY2p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JUV313BRKB2E6 Fi4x6eJZ0zfrLqS4Mky8W X-Received: by 2002:a05:6820:4c82:b0:6b7:46fa:169a with SMTP id 006d021491bc7-6d43ff69796mr10523773eaf.47.1790535152003; Sun, 27 Sep 2026 11:52:32 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-494877590e5sm4489452fac.13.2026.09.27.11.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2026 11:52:29 -0700 (PDT) From: James Hilliard Date: Sun, 27 Sep 2026 12:52:19 -0600 Subject: [PATCH net-next v6 1/3] net: stmmac: sun8i: reset the MAC after PHY initialization Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260927-submit-h616-emac1-v1-v6-1-e64971f4e414@gmail.com> References: <20260927-submit-h616-emac1-v1-v6-0-e64971f4e414@gmail.com> In-Reply-To: <20260927-submit-h616-emac1-v1-v6-0-e64971f4e414@gmail.com> To: Richard Genoud , Maxime Chevallier , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Coquelin , Alexandre Torgue , LABBE Corentin , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Giuseppe Cavallaro , Jose Abreu Cc: Alastair D'Silva , Maxime Ripard , James Hilliard , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.15.2 The MAC software reset needs a running receive clock from the PHY. Resetting the MAC at the end of probe therefore fails when the PHY driver has not been loaded or its probe has deferred on a missing supplier. The failure removes the MAC and its MDIO bus, so loading the missing driver later cannot recover the interface without reprobing the MAC. Perform the software reset in the DMA reset callback instead. The stmmac core calls it during hardware setup after attaching and initializing the PHY, and resumes a suspended PHY before reopening or resuming the MAC. Mask interrupts before requesting the reset and retain the existing DMA and interrupt-register clearing even if the reset times out. Return reset errors through the normal hardware-setup error path. Remove the unconditional reset from probe. Keep the separate H3 MDIO-mux reset after switching the mux and powering the selected PHY, since it is needed to latch the selected interface before MDIO accesses. Fixes: 9f93ac8d4085 ("net-next: stmmac: Add dwmac-sun8i") Tested-by: Maxime Chevallier Reviewed-by: Maxime Chevallier Signed-off-by: James Hilliard --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 53 +++++++++++------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 38d7e71de925..5691da796454 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -269,11 +269,33 @@ static const struct emac_variant emac_variant_h6 = { #define SYSCON_ETCS_EXT_GMII 0x1 #define SYSCON_ETCS_INT_GMII 0x2 +static int sun8i_dwmac_reset(void __iomem *ioaddr) +{ + u32 v; + + v = readl(ioaddr + EMAC_BASIC_CTL1); + writel(v | 0x01, ioaddr + EMAC_BASIC_CTL1); + + /* The timeout was previously set to 10ms, but some board (OrangePI0) + * need more if no cable plugged. 100ms seems OK + */ + return readl_poll_timeout(ioaddr + EMAC_BASIC_CTL1, v, + !(v & 0x01), 100, 100000); +} + /* sun8i_dwmac_dma_reset() - reset the EMAC * Called from stmmac via stmmac_dma_ops->reset */ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr) { + int ret; + + writel(0, ioaddr + EMAC_INT_EN); + + /* The PHY receive clock must be running for the reset to complete. */ + ret = sun8i_dwmac_reset(ioaddr); + + /* Leave DMA and interrupts disabled even if the reset timed out. */ writel(0, ioaddr + EMAC_RX_CTL1); writel(0, ioaddr + EMAC_TX_CTL1); writel(0, ioaddr + EMAC_RX_FRM_FLT); @@ -281,7 +303,7 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr) writel(0, ioaddr + EMAC_TX_DESC_LIST); writel(0, ioaddr + EMAC_INT_EN); writel(0x1FFFFFF, ioaddr + EMAC_INT_STA); - return 0; + return ret; } /* sun8i_dwmac_dma_init() - initialize the EMAC @@ -738,27 +760,6 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw, writel(v, ioaddr + EMAC_TX_FLOW_CTL); } -static int sun8i_dwmac_reset(struct stmmac_priv *priv) -{ - u32 v; - int err; - - v = readl(priv->ioaddr + EMAC_BASIC_CTL1); - writel(v | 0x01, priv->ioaddr + EMAC_BASIC_CTL1); - - /* The timeout was previously set to 10ms, but some board (OrangePI0) - * need more if no cable plugged. 100ms seems OK - */ - err = readl_poll_timeout(priv->ioaddr + EMAC_BASIC_CTL1, v, - !(v & 0x01), 100, 100000); - - if (err) { - dev_err(priv->device, "EMAC reset timeout\n"); - return err; - } - return 0; -} - /* Search in mdio-mux node for internal PHY node and get its clk/reset */ static int get_ephy_nodes(struct stmmac_priv *priv) { @@ -899,7 +900,9 @@ static int mdio_mux_syscon_switch_fn(int current_child, int desired_child, /* After changing syscon value, the MAC need reset or it will * use the last value (and so the last PHY set). */ - ret = sun8i_dwmac_reset(priv); + ret = sun8i_dwmac_reset(priv->ioaddr); + if (ret) + dev_err(priv->device, "EMAC reset timeout\n"); } return ret; } @@ -1221,10 +1224,6 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to register mux\n"); goto dwmac_mux; } - } else { - ret = sun8i_dwmac_reset(priv); - if (ret) - goto dwmac_remove; } pm_runtime_put(&pdev->dev); -- 2.53.0