🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25891

[PATCH net] net: stmmac: hold the MDIO bus lock during the MAC soft reset

#25891
From: Savvas Etairidis
Date: Wed, 02 Dec 2026 17:04
49 lines
12879 bytes
From: Savvas Etairidis <saet@hms.se>

The MAC soft reset in stmmac_init_dma_engine() stops the MDIO master.
If an MDIO transaction is in flight at that moment, it is cut off in
the middle of a frame. On a Realtek switch managed over MDIO (SMI),
this was seen to store a value in the wrong register (0x00bb written to
0x08a2) or leave the switch not answering.

Take the MDIO bus lock around the reset with stmmac_mdio_lock(), as
dwmac-dwc-qos-eth already does for its pad calibration, so that no
transaction can be running while the reset happens. Every MDIO
transaction holds this lock for the whole frame.

On two boards, forced MAC resets triggered the corruption within 250
resets without the lock. With the lock, 36000 forced resets caused
none.

stmmac_init_dma_engine() is only called from __stmmac_open() and
stmmac_resume(), neither of which holds the bus lock.

This patch was developed with the help of an AI coding assistant
(Claude Code). It wrote the change and the changelog. I reviewed
both and tested the fix on 6.6.162 hardware (36000 forced MAC resets
with the lock, none failing).

Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")
Signed-off-by: Savvas Etairidis <saet@hms.se>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4638f6..1011e08f20c8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3331,7 +3331,10 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
 	if (ret)
 		return ret;
 
+	/* The soft reset stops the MDIO master, so keep the bus idle. */
+	stmmac_mdio_lock(priv);
 	ret = stmmac_reset(priv);
+	stmmac_mdio_unlock(priv);
 	if (ret) {
 		netdev_err(priv->dev, "Failed to reset the dma\n");
 		return ret;
-- 
2.56.1
Technical Details
Message-ID: <20261202170439.2911343-1-setairidis@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375947-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375947-linux-kernel-netdev=dewy.ru
From: setairidis@gmail.com (Savvas Etairidis)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net: stmmac: hold the MDIO bus lock during the MAC soft reset
Date: Wed,  2 Dec 2026 18:04:39 +0100
Organization: Usenet Network
Message-ID: <20261202170439.2911343-1-setairidis@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2016183"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:R7hZu20PGrfoaGk7CgqF1zzH1Z8= sha256:iI1MGxIoy1JTB2QS6Z95YLxMdb/MICVzuiJOf/gcZbo=
	sha1:53xh2qs2o5TuAJwqPPVnjpSQghc= sha256:dFrYaK6X4ukhCXCehReRNx215q/ZgxMx+OY21olI+jY=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D85171176B8; Wed,  2 Dec 2026 20:06:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.149
X-Spam-Status: No, score=-2.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id RzQZF-EtnNsu;
	Wed,  2 Dec 2026 20:06:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375947-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 31B4D1176A7; Wed,  2 Dec 2026 20:06:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id A08C62AFE7; Wed,  2 Dec 2026 17:06:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796231178;
	b=o89ThgjmL1q91d1iOFUlM/MFLw20fUiwmXN0qFxIIvTEPuEYXwzvU91jrhUlmalrKEHx
	 D7KOPtWcOKYIp27h+ENKD67Q0YZqsygOJbMQLRaQPQ5Ct8TIFhdyr+FyRtbM87VbTbQFY
	 CNkt1Ht4F6yDQCzXgIjEUE/D9za+uvZyopMEolmldF6j1VUyhwKdonAhjY8jiq+RkvtnK
	 ulFJg81qCiWvqLnuMzMbLxB9umshEFd3TwjJQDvwfHjuScVsPY6LLTYf8InDD3RtZe5J6
	 2DdYNhfEHLr/kpWjcY+OximHs1Wso+vpPZFlI0in7TvZ96+koomfEkI18HGR8jhK5Sw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796231178;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=bWffGETui37sRCD5qrvApu/kxGuh3WyPt+b8szKDLiw=;
	b=FH1q45U5y7ul3HA+J18KbKLxixPOzswXd3wg13lZAzokhOA86wL3esM+mNXWEMCb6zsZ
	 z6D09EXSZk+nxj1zvZPsUn/jvjl7UGvdP8FbHyxnR4me/khw8nMGjAeNAL7E8XwMI7BcN
	 UPHH9nlACYL5M/z6mx82Atb7NbNPPd/4gCh2cXJWeXaBmCqPfsLHo2ul+hDbsM0xl6K4r
	 09SyW757rsPQYPUoUcMslJJOexjXmzRqErbcLDDnR1K1BN/Cm8UJMqdHweJ1eMmVBXRB2
	 1e5iaNPDA/cr/gA6zK6sRQjbrGB+DgqTTnwIBtBe3PHYu7TTQGMWC/ZwzfcF/hQNuDQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="qw/uu8N+";
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id EE91F606A33D;
	Wed,  2 Dec 2026 17:06:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qw/uu8N+
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796231177;
	b=ob+lxHM15qlPNfWgUefHpGgF5sdozsZ/l4QzIB7T2NaIGW+9fv79UC136QDBEiBHBkym
	 5Q0iiY0wyrb9Q/MnewTnGd3Awvcw5XNJ2vmA5uaBdC6/OtZ3EjIE7Y2DKm+QlMMRwVrqY
	 N/QgC+AsgB+zCndF/uqr/Pr8/5hC/z0MJcIFUD3qTA1Q0llgwm4qm9OwGV9ivsSXoNiDz
	 Cv25ReSzct5eMDhnNYA/OwzRqCVDM0mnGwA+ZA2694/d184sXuFNtyk0GtSntVjsN8wta
	 eo1wqUiIFfEnpRMCpCcT1sEb4HyjWJZxKDsZ5BtB+cTmqfKyuOyXVvYXyXqMRQp6yQA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796231177;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=bWffGETui37sRCD5qrvApu/kxGuh3WyPt+b8szKDLiw=;
	b=JgVuT7UpT0fs6CjHNoGjdtGahGvFk2Vlo3QWqtMn9KYv049MLGEe/h0vTCLcg1LGqIQ/
	 MQJRRGmqsUGPcM/AQIbQl0AZJ6lfhL6NJjaXlUAvCE8eJMR2lyzn/TGYsewhoLD938Hae
	 lOyTX5DCzBq58L1lOoTZPpodJjg/N6PNCp1iyHHS/pV2HVbdWg9RG1nyY1eWwTujvT7dm
	 Fvp4Q1UKP74ljKt70eoYXMzgENln5eJmR0JJe1p9ddX6570xsm3BLOXB6mKX4/ffrFLgA
	 8AE2aND0lqyCCE9U5nfxgtAPzZaQMHnV/8U0MT5POeXoa6hcBmb9J/F8ivqpsvv4xng==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="qw/uu8N+";
	arc=none smtp.remote-ip=209.85.208.42
X-Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC78E606A32C
	for <netdev@vger.kernel.org>; Wed,  2 Dec 2026 17:06:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BC78E606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-6a642495d81so20862028a12.2
        for <netdev@vger.kernel.org>; Wed, 02 Dec 2026 09:06:16 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796231175; x=1796835975; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=bWffGETui37sRCD5qrvApu/kxGuh3WyPt+b8szKDLiw=;
        b=qw/uu8N+AU8y0uNKvlaZcUyWMCX7kVSpOXSvxhWHtjy3ey+ICCHm3kzlgadNiDc5OE
         iy2nrKHUid8x6Hpg6pHe3PSr2uXFjlIYiPCpkY7ZvAfk0m1gW2+c42Agli0h1xQsdR2a
         ez2CcX7E2FEkc5ymIr5Qzysk5BPknGrw4Rd8CWoT6//QWzECX7anJU7+C/Jrcb1dL62U
         kF0DBW3pRXJ1UbtzyTSTl2ceQ6k6zJJllv9M7jm6/emeYorN8zhRyWzDTa/JfErXzOi+
         33ROcr0r8lofSFy61hj/MX1Q1x6RrBnP1G9AdJOTcp6r5xqo86OCRdY9p+uhXi3MKdOd
         56Jw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796231175; x=1796835975;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=bWffGETui37sRCD5qrvApu/kxGuh3WyPt+b8szKDLiw=;
        b=L8wUqZNpyU2IPt//iVTSwLvKb4/g9zHerCChZiBqmW5tBApkVDtfgRKUnH3p8nlWSE
         lQn2suzHcWRqM0Fh2Wge/BvLPbpmjrhaXyw69hYPxdBQd/M+cXdMhA/qjTz3YqanuTTy
         CSRaqZO4ibs6JHfsheYE180U/Yz1HcdHOp8SZw1M4w3+7Tj0nF28WCtx04lbOyQrFeng
         tUb1roySXi5rgkXw3ZFyN1EAJorZWQf4Ez+1mVbgjvS8WJYbzls4hmbsKTsHRiNbmSX2
         tDZaimmFWBLJ5hjj8zdlwqpQxksFFjCPweYReUyhyBkAgQzJQPsBT7LeUYFmtN0sA8Uh
         MLiA==
X-Gm-Message-State: APuU4Z9gQwEF8cMEy/NU1SkYbINWB5byPanHjR9/0K04AfNUtyDvFrq2
	FMA1/AY1Dkd/mAjQTwfGleCOx/eUHmIZJTJ+0w3t5rYajdRFC5FH/BY+D4RLgzxp
X-Gm-Gg: AZFdTZfsOv6FJ499GoWr3jxdTQvx3fFHMvCljtggeN+ujq1RO/6W6hSTq8D9slTZ9Vk
	fMrMt7nnxWXyTCmMEdHa1NGhClVk8suh1+EcKRX7EJHJzeua+Nj5KuW79Qiy5cK/U7c5QmEGKRx
	rdRJSWVOl2l6ZYK/kx/kj0cwmXBjc3ek8KA4w2AqLJ5vn1APanu4sZRgOoCUbTxIDWGk1+4DQdX
	2Pq/u17af2EU+fJ/R46m9HyL7pWi8ANEHcF3ZonIM38cYWqVyAisyPEQYz8QvI+n4BtcVoY60vm
	ZOEbEFLG9YVEZXeAuUPq9J0hq0wDt1QpxJaAhkwLdcRH6HQIrGf3Vaw2CesZ92rPtbSfdL3hR2D
	mLEloK5pZK1Eq9o5ilF8uTWWWt8TZPVXfeUkvid0mmS7oLTFkKqHVs4+KJtOsMrA1AJuAKRB2ME
	OBGqpwPoO51lUlwo/HWl0573pmtJt8TA47yMKdKzSmtB+w55u11lCurWQUf2QRqx3YfwAg+UMY+
	HKZ94+lGuH7ynKtyp4p1FLvdclUKsqH5+gq9jFBixSAm1KpGAl8uOsXEMh9yiJFhOT+sOpNiP4O
	voAWjGmMgeknaZDtpQGPvZAzimBSYIvpIqiHkpjWg4QBRNlEufXa0tkqKNz1c19Lrpuhtx7OYEE
	qEzp523sf6VvdjPaF6QlqcOg=
X-Received: by 2002:aa7:c1d9:0:b0:6b5:8c80:d12d with SMTP id 4fb4d7f45d1cf-6ba37e87eefmr22449471a12.37.1796231174888;
        Wed, 02 Dec 2026 09:06:14 -0800 (PST)
X-Received: from WET-9YN9DY3.hms.se ([195.243.140.190])
        by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6ba370fa8a4sm16442169a12.21.2026.12.02.09.06.13
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 02 Dec 2026 09:06:14 -0800 (PST)
X-Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	saet@hms.se,
	Andre Pribil <andpr@hms.se>,
	Bela Scholtes <besc@hms.se>,
	Michail Georgios Etairidis <miet@hms.se>
X-Mailer: git-send-email 2.56.1
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list