Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by Oleksij Rempel
Sun, 15 Nov 2026 10:59
[PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Author: Oleksij Rempel
Date: Sun, 15 Nov 2026 10:59
Date: Sun, 15 Nov 2026 10:59
112 lines
14360 bytes
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
Re: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Author: Andrew Lunn
Date: Sun, 15 Nov 2026 15:38
Date: Sun, 15 Nov 2026 15:38
34 lines
10149 bytes
10149 bytes
On Sun, Nov 15, 2026 at 11:59:51AM +0100, Oleksij Rempel wrote:
> 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>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
Re: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 11:00
Date: Mon, 16 Nov 2026 11:00
138 lines
13325 bytes
13325 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In ksz9477_set_ageing_time()
(drivers/net/dsa/microchip/ksz9477.c:1361-1371), the new Fast Aging…
- [Low] The Fast Aging pulse in ksz9477_set_ageing_time() is a fixed
blind sleep: KSZ9477_FAST_AGE_PULSE_US = 2 ms (ksz9477.c:1293),…
--
net: dsa: microchip: ksz9477: apply a shorter ageing time at once
This patch makes ksz9477_set_ageing_time() pulse the Fast Aging bit in
REG_SW_LUE_CTRL_1 for a fixed 2 ms. It does this whenever the programmed
ageing time gets shorter or the Age Count gets smaller. The goal is that
stale entries no longer outlive an STP topology change on a KSZ9893.
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 8d4647e23cda1..a9d701f0404a7 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
[ ... ]
> @@ -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);
[Severity: Medium]
Does this flush the dynamic FDB entries of every port on the switch?
SW_FAST_AGING is BIT(1) of REG_SW_LUE_CTRL_1 in ksz9477_reg.h. That
register holds only switch-wide lookup engine controls, next to
SW_AGING_ENABLE and SW_LINK_AUTO_AGING. Fast Aging has no port or FID
selector, so each pulse removes dynamic entries on all ports. That
includes ports in other bridges that had no topology change.
When the software bridge shortens its ageing time, it only expires
entries that were not refreshed within the new time. This pulse also
drops entries that are still in use. Unicast traffic to those addresses
then floods until the hosts transmit again, and a host that only
receives can be flooded to for a long time.
The pulse can also fire when the ageing time grows. From the reset value
of 4 x 75 s, a request for 301 s gives:
max_val = 255 (76 * 4 != 301)
data = DIV_ROUND_UP(301, 255) = 2
new_period = DIV_ROUND_UP(301, 2) = 151
data (2) < mult (4), so the switch-wide flush runs although the ageing
time went up from 300 s to 302 s.
Neither the subject nor the body says the flush covers the whole switch.
The commit message only says:
On a KSZ9893 the pulse removed the dynamic entries on the one user port
I tested.
The driver already has a per-port flush, ksz9477_flush_dyn_mac_table(),
which is wired up as .port_fast_age. Could that be used here, or could
the commit message at least say that all ports are flushed?
> + 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);
[Severity: Low]
Is a fixed 2 ms sleep long enough on all chips that use this function?
The new define comes with this comment:
/* The datasheet gives no pulse length. A 2 ms pulse worked on a KSZ9893. */
Nothing checks that the dynamic entries are gone before SW_FAST_AGING is
cleared. ksz9477_set_ageing_time() is installed through ksz9477_switch_ops.
That covers many chip_data entries in ksz_common.c, including the 7-port
KSZ9477/KSZ9897/KSZ9567 parts, but it was only tested on a KSZ9893 with
one user port.
The other Fast Aging user in this driver suggests the timing depends on
the chip:
drivers/net/dsa/microchip/ksz8.c:ksz8_flush_dyn_mac_table() {
...
if (ksz_is_ksz8995xa(dev)) {
/* Allow the 800 us fast-age cycle to finish before restoring
* normal ageing and port learning.
*/
...
}
Some untested chips may count each entry's stored Age Count down at a
fast tick, or may need more time to sweep the ALU. If so, could the pulse
end before every entry has expired, so that stale entries still outlive
the topology change?
> +
> + return ret ?: err;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115-ksz-stp-ageing-v2-0-7af27320033e%40pengutronix.de
Re: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Author: Oleksij Rempel
Date: Tue, 17 Nov 2026 11:59
Date: Tue, 17 Nov 2026 11:59
24 lines
11209 bytes
11209 bytes
On Mon, Nov 16, 2026 at 11:00:35AM +0000, netdev-bot+sashiko@kernel.org wrote: > Does this flush the dynamic FDB entries of every port on the switch? Yes. Fast Aging is a control for the whole switch, and so are the Age Count and Age Period. I checked it on a KSZ9893 with one entry on each user port: both were gone right after the pulse. v3 says this in the commit message and the comment. A flush per port would not help: the stale period applies to the entries of all ports, so all of them would need the flush. > The pulse can also fire when the ageing time grows. Yes, that is on purpose. The commit message has this case: from 4 x 2 s to 1 x 31 s, an entry stayed about 63 s without the pulse. It happens only when the Age Count gets smaller. In STP use the count does not get smaller when the bridge restores the ageing time. > Is a fixed 2 ms sleep long enough on all chips that use this function? I can test only the KSZ9893. The comment at the define says so. pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads