🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16629

[PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once

#16629
From: Oleksij Rempel
Date: Sun, 15 Nov 2026 10:59
112 lines
14360 bytes
Pulse Fast Aging when the programmed ageing time gets shorter or the Age
Count gets smaller.

The ageing time is Age Count times Age Period. An entry stores the Age
Count when it is updated, as the datasheet says. The datasheet does not
say when a new Age Period applies.

Without the pulse, stale entries outlived an STP topology change. In my
STP tests the switch ran at 300 s as 4 x 75 s, its reset value. With
forward_delay 4 s, the bridge asks for an ageing time of 8 s. Read back
right after the write, the register showed 8 s. In three tests, an
entry learned before the change still stayed for more than a minute. I
think the switch uses the new Age Period only after the running one
ends.

The pulse is also needed when the ageing time grows but the Age Count
shrinks. From 8 s (4 x 2 s) to 31 s (1 x 31 s), an entry stayed about
63 s in one test.

On a KSZ9893 the pulse removed the dynamic entries on the one user port
I tested. The new period then started right away.

I found this in STP tests on a KSZ9893. I tested the fix there with
kernel STP and with STP off. With mstpd I checked only the programmed
ageing time, not the FDB.

Fixes: 2c119d9982b1 ("net: dsa: microchip: add the support for set_ageing_time")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
Changes in v2:
- Fix the tense in the comment (Andrew)
- Add new_period, and compute old_secs next to new_secs
- Rephrase the comments and the commit message
- Add a Fixes tag
---
 drivers/net/dsa/microchip/ksz9477.c | 41 ++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 8d4647e23cda153bc68255a44c44e0d1d92469f9..a9d701f0404a706e6ad2a6faa2f57dbe28d383c2 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1289,13 +1289,16 @@ static void ksz9477_phylink_get_caps(struct dsa_switch *ds, int port,
 	ksz_phylink_get_caps(ds, port, config);
 }
 
+/* The datasheet gives no pulse length. A 2 ms pulse worked on a KSZ9893. */
+#define KSZ9477_FAST_AGE_PULSE_US	(2 * USEC_PER_MSEC)
+
 static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
 {
+	u8 data, mult, value, old_period, new_period;
 	struct ksz_device *dev = ds->priv;
+	u32 old_secs, new_secs, max_val;
 	u32 secs = msecs / 1000;
-	u8 data, mult, value;
-	u32 max_val;
-	int ret;
+	int ret, err;
 
 #define MAX_TIMER_VAL	((1 << 8) - 1)
 
@@ -1314,6 +1317,10 @@ static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
 	if (ret < 0)
 		return ret;
 
+	ret = ksz_read8(dev, REG_SW_LUE_CTRL_3, &old_period);
+	if (ret < 0)
+		return ret;
+
 	/* Check whether there is need to update the multiplier. */
 	mult = FIELD_GET(SW_AGE_CNT_M, value);
 	max_val = MAX_TIMER_VAL;
@@ -1336,8 +1343,32 @@ static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
 			return ret;
 	}
 
-	value = DIV_ROUND_UP(secs, data);
-	return ksz_write8(dev, REG_SW_LUE_CTRL_3, value);
+	new_period = DIV_ROUND_UP(secs, data);
+	ret = ksz_write8(dev, REG_SW_LUE_CTRL_3, new_period);
+	if (ret < 0)
+		return ret;
+
+	/* data is the new Age Count and mult is the old one. An entry
+	 * stores the Age Count when it is updated. The datasheet does not
+	 * say when a new Age Period applies. On a KSZ9893, entries outlived
+	 * the new ageing time after it got shorter, and after the Age Count
+	 * got smaller. Pulse Fast Aging in both cases. On a KSZ9893 the
+	 * pulse removes the dynamic entries (checked on one user port) and
+	 * starts the new period.
+	 */
+	old_secs = mult * old_period;
+	new_secs = data * new_period;
+	if (new_secs >= old_secs && data >= mult)
+		return 0;
+
+	ret = ksz_rmw8(dev, REG_SW_LUE_CTRL_1, SW_FAST_AGING, SW_FAST_AGING);
+	if (!ret)
+		fsleep(KSZ9477_FAST_AGE_PULSE_US);
+
+	/* Clear the bit even after an error. */
+	err = ksz_rmw8(dev, REG_SW_LUE_CTRL_1, SW_FAST_AGING, 0);
+
+	return ret ?: err;
 }
 
 void ksz9477_port_queue_split(struct ksz_device *dev, int port)

-- 
2.47.3
Technical Details
Message-ID: <20261115-ksz-stp-ageing-v2-1-7af27320033e@pengutronix.de>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363672-linux-kernel-netdev=dewy.ru
References: <20261115-ksz-stp-ageing-v2-0-7af27320033e@pengutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-sfo.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363672-linux-kernel-netdev=dewy.ru
From: o.rempel@pengutronix.de (Oleksij Rempel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a
 shorter ageing time at once
Date: Sun, 15 Nov 2026 11:59:51 +0100
Organization: Usenet Network
Message-ID: <20261115-ksz-stp-ageing-v2-1-7af27320033e@pengutronix.de>
References: <20261115-ksz-stp-ageing-v2-0-7af27320033e@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1777506"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:faVTuELqxEJTV8YYMVa/tITZeao= sha256:Ejv9NPTiQwVguNCeT42m/jH3+T7Q1NkXLrWz/ZsUXmI=
	sha1:zGqWydTMGTZ4CRkJ9JgGNrRzRbQ= sha256:n1Nq4+zjNGSSUVca7uulEBUM763JGMoS66GQ+0gvMk8=
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 CFCFA1149B1; Sun, 15 Nov 2026 14:00:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, 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=pengutronix.de
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 ytuwrUJ1PJKL;
	Sun, 15 Nov 2026 14:00:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363672-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 3CCDF114974; Sun, 15 Nov 2026 14:00:19 +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 75B8537443; Sun, 15 Nov 2026 11:00:14 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794740405;
	b=DKDJIeTzoJEABd0brBExSz6q84flAXEAbZpTNGxQp8ktM2QzUkaXOQBZIhLqOcOVOhn3
	 DRxh/gezW4CuVMiz3Mbf+pt4Y2dHkLpGZqD1JgPtjRe1VMWSW3ks7em6/RqCqMoAJClPs
	 gURuuUo+fB6QVbAOkRN/EnPP8w1d054RZoLZ7jxuIB3Fd2/gdzBQi5GfNT/aQkOLwDEtp
	 HYnAmFD+H/Lo9l+z6vjq3W13Edf+9YVey+d7n0Z2fzc/aMxS1UJH0Yj6kTIX8FIAq0H9+
	 m2DX0/q6iMrTtBm2ePr0lHJ+PZqNnhvphqudULeKHlAeBnkFwNlLshR5JBJ39doSgcQ==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794740405;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:Received:
	 From:Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer;
	bh=wkA+VPYGFLuORnMAtbJKzLsvwtfdb241bM0vf1HQ6aQ=;
	b=NYIRV8wo3p+4v7GvgfXI/d9rocbzmmu41u0MR7Dvv70wFQZwL9oUwiJBD/809EL4U/iB
	 zs47bs+YhQWM5T2VdU28gncGZDEdU/2kU/BBlfrSjoogaKGDg1U/x2Fr+ZCVhWOj3TBSe
	 jQq+dLWZr0OcOK79+rZ1i3XupiZsTiuQJ0otlFqfYP4hhw0sseEjhRkyWWpi1V5kfMCqa
	 dRdXCjnN853KwtnW3SGKp5pgcmBw0OcIzeHY9zj9wmCAGoLIID3y6yjyIchdD+01HsIKS
	 6zDeM57SGszhFbO5n48Y2Xuh9r/66Oyo48tKxtBr3eL9nPq4I1vbFdJSuw3htR91KEg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=A3mQRzK9;
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.de;
	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 D9060606A89B;
	Sun, 15 Nov 2026 11:00:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=A3mQRzK9
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794740405;
	b=TwPkpxR/fn6EGEe3rtHjNAhoAbeR1lFoRrmtpfJygY9qXcxLoeUcrza5NjNnCww/6Oki
	 ITa7d4NgT70Qq8q18WJxTalsGNf/m+eyGOSm44x/M2/do40JJQ+/HQpHD6vW5MhDq0V9q
	 l5wwa+MhQL2CizO+U5QsVV0mIrULtN/3DKcPbN38Z1RYe0rQPbL+xK95fyi114LV5D3O2
	 hdZWgKI+fAfJ5IEr4OUPOTFarWto27mp+gNxnr0E6lU0CYYe6uAVRlt3+7rGkxBkOI9fm
	 a3hC4QS4e+ywVp1fF5LztUzoc1XMnH2HvzIFojd9Nezx3cv0vxNaDih6ocelEXjj0Xg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794740405;
	h=DMARC-Filter:Received:DKIM-Signature:Received:From:Date:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:
	 References:In-Reply-To:To:Cc:X-Mailer;
	bh=wkA+VPYGFLuORnMAtbJKzLsvwtfdb241bM0vf1HQ6aQ=;
	b=0T+nUOGeQJS9rI0E+awtXYpQmlixNHNwVJLeIRlvGp71Sw6YDZomCCtj2h2KAwE62ASo
	 tkqAFm6FDnSqBjvGvtcILlLpvU7iAKV8i0tZQCuMVsW+9dIfG3SY9Y7qqbWHpdNNWjV67
	 Z+OFHpfhYyYBkdRT6sAYXj7XKkrSRbPLg0vygqbLr2O+5q+iYJ4BLXH6RILLAnHjhiVNU
	 q5EMcsx/+qcTm4X0Pl4HKW5wbmObNdj9IEmFMCRCLY45DjSiC1JDKeLkPhLFnJwFagXEh
	 BvbwTgxPmItEUNUCbfqV69Nt+TlUoPn69Cb44528Xy8u2Rse3EB6lTU9j35XmcaSXlw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.de;
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=A3mQRzK9;
	arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EE80606A331;
	Sun, 15 Nov 2026 11:00:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3EE80606A331
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de
X-Received: from dude04.red.stw.pengutronix.de (dude04.red.stw.4.pengutronix.de [10.17.1.12])
	(Authenticated sender: relay-from-dude04.red.stw.pengutronix.de)
	by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 26B892059F2;
	Sun, 15 Nov 2026 12:00:01 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1794740401;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=wkA+VPYGFLuORnMAtbJKzLsvwtfdb241bM0vf1HQ6aQ=;
	b=A3mQRzK99xHypblrjsJtV2XPfGBv6xLKfgmmz5O8A5LZqRzNPB0jqR4Jt7IOWwrr10Hq3T
	Ye+U3a2h4oTtcwr74p7F8KMOTAqW2c/8mX2WyG27+zbdcStFOzdRxJiDKCyBJJsy9zkkmc
	lmX7hMZG4yZ2vfiG4DtJ+B8Zu0OXo8/hGnpEQ4hh5fmXii7OIToiLb/kobjVKLbRqZqLQw
	DrKkNUmRqQSH/rfZQue4ObOGnwRbT5DcWX3lqu/B6McUxQmAutOaVRhFcJ7YA/XlY8dSSn
	PzOj3xEbM7kyJ4WWKa0jpRFGuD0bW9c0DXTh/hJCyqzX6uv7FndOC99rx4zv1w==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1794740401;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=wkA+VPYGFLuORnMAtbJKzLsvwtfdb241bM0vf1HQ6aQ=;
	b=OhqtE2KrEI+91VlvhuX0adPeSijA+m22ZMJXkZtSWQa3eZI1Qw3SnzQ8HldS8SbCzUcoa8
	mtykOO+L84bt0ZLpdy4qUAfbynJzcAPp+A3nBciKlE0tmVgpV7x3kijdNtBrcIkoUGw/yZ
	GVI0qDbe2UXCPBkA6IdLvMjIYC0Ql2meCI0gthwP7xjhSZMP5OXBHLmPqLWBy3ZctNEDqV
	QOvdG1MaU2T4yiqluBp+xzOP8nXg7i8zRF/Cw3v2sXmSACPJ4OOHAZRfyRvo/9LIS57OoR
	hFETDHPmJvH7yuJWXGrGPvuaFstLumP9e4j1WpNcgljF4TOsEYq9/RaQukAj1Q==
X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1794740401; a=rsa-sha256;
	cv=none;
	b=ClPViRJ1vo1HpNWcVJkJauwnTXTNMV8owgI7SD5jrVQ0E+pqNSlkIwa3DeI6oJ+2juEleM
	aLyzZOijZ2Lm4MpI0j6GtoLjzwE6BOAFqmf/OeSVzTWP2ggLDDCWQNBJCfGpunxLcBIE0l
	gD1jgBlrCckq0onMOlMphxPb5bBS622lCRm2WzCAa2gacxNqszdGyxjtctpfRUcBq0XG//
	3G40/xdBCwpN5l+XleYxaUqlozpXlN1yxPJskUTvwHwIoC8a/I8rPzNWAkRleFFloLeT/c
	+jJnzki9UXMCC5ppfHr1JZ4w4lQyq3Ce0zcLYL0o76drJ5/MxTBG8YtVY3qFRQ==
X-ARC-Authentication-Results: i=1;
	ORIGINATING;
	auth=pass smtp.auth=relay-from-dude04.red.stw.pengutronix.de smtp.mailfrom=ore@pengutronix.de
X-Received: by dude04.red.stw.pengutronix.de (Postfix, from userid 1058)
	id 06FB73815CE; Sun, 15 Nov 2026 12:00:01 +0100 (CET)
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
X-In-Reply-To: <20261115-ksz-stp-ageing-v2-0-7af27320033e@pengutronix.de>
X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, 
 kernel@pengutronix.de, 
 Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>, 
 Oleksij Rempel <o.rempel@pengutronix.de>
X-Mailer: b4 0.14.2