Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: juraj.sladek@littleit.sk
Cc: linusw@kernel.org, luizluca@gmail.com, alvin.sipraga@analog.com,
	andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	linux@armlinux.org.uk, contact@c127.dev, netdev@vger.kernel.org
Subject: Re: [PATCH net 2/2] net: dsa: realtek: rtl8365mb: soft reset switch core after conduit comes up
Date: Sat, 28 Nov 2026 13:21:42 +0000	[thread overview]
Message-ID: <179587210275.3135.16334129438019832908@kernel.org> (raw)
In-Reply-To: <20261127-rtl8365mb-hsgmii-fix-v1-2-f2827126aa6a@littleit.sk>

Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 5 · 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] The whole switch core is soft-reset (CHIP_RESET.SW_RST) 3
  seconds after every time the conduit becomes operational, for as long…
- [Medium] The reset is gated only on mb->sds_in_use, but
  rtl8365mb_pcs_config() sets mb->sds_in_use = true for SGMII as well as…
- [Medium] rtl8365mb_conduit_state_change() ignores its `conduit`
  argument, so the new cancel/schedule logic reacts to every conduit of…
- [Medium] On conduit down, rtl8365mb_conduit_state_change() cancels
  sds_core_reset_work with the non-sync cancel_delayed_work(), which…
- [Medium] rtl8365mb_sds_core_reset_work() asserts SW_RST without any
  lock that serializes it against the driver's other multi-register…
- [Low] The new rtl8365mb_sds_core_reset_work() writes CHIP_RESET
  (0x1322) under different assumptions than the existing code that…

--

net: dsa: realtek: rtl8365mb: soft reset switch core after conduit comes up

This adds a delayed work that soft resets the switch core
(CHIP_RESET.SW_RST) 3 seconds after the conduit becomes operational while
the SerDes is in use. The goal is to recover the CPU port on an RTL8367S
connected to an IPQ5018 over HSGMII, which sometimes stops forwarding
frames from the CPU or forwards them corrupted. The work is cancelled on
conduit down, and synchronously in rtl8365mb_teardown().

> diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
> index 54d90121ecd26..f307581107f2e 100644
> --- a/drivers/net/dsa/realtek/rtl8365mb_main.c
> +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c

[ ... ]

> @@ -3094,11 +3096,48 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)
>  					20000, 1e6);
>  }
>  
> +/* On an RTL8367S connected to an IPQ5018 over HSGMII, the port MAC behind the
> + * SerDes occasionally ends up, after the link comes up, in a state where the

[ ... ]

> +static void rtl8365mb_sds_core_reset_work(struct work_struct *work)
> +{
> +	struct rtl8365mb *mb = container_of(to_delayed_work(work),
> +					    struct rtl8365mb,
> +					    sds_core_reset_work);
> +	struct realtek_priv *priv = mb->priv;
> +	u32 val;
> +	int ret;
> +
> +	ret = regmap_update_bits(priv->map, RTL8365MB_CHIP_RESET_REG,
> +				 RTL8365MB_CHIP_RESET_SW_MASK,
> +				 RTL8365MB_CHIP_RESET_SW_MASK);

[Severity: Low]
rtl8365mb_reset_chip() writes the same CHIP_RESET register with
priv->write_reg_noack(). It then sleeps 100 ms before polling, with a
1 second timeout:

	priv->write_reg_noack(priv, RTL8365MB_CHIP_RESET_REG,
			      FIELD_PREP(RTL8365MB_CHIP_RESET_HW_MASK, 1));
	...
	msleep(100);

realtek_smi_write_reg_noack() also carries this comment:

/* There is one single case when we need to use this accessor and that
 * is when issueing soft reset. Since the device reset as soon as we write
 * that bit, no ACK will come back for natural reasons.
 */

Does SW_RST behave differently on the bus? If it also suppresses the ACK,
regmap_update_bits() would fail on SMI-attached switches. The worker would
then print "failed to soft reset switch core" even though the reset went
out, and it would skip the completion poll.

The tested board is MDIO-attached. There, write_reg_noack is
realtek_mdio_write(), so the testing would not show this difference.

Is a 100 ms poll timeout enough, given the 1 second reset time documented
in rtl8365mb_reset_chip()?

> +	if (!ret)
> +		ret = regmap_read_poll_timeout(priv->map,
> +					       RTL8365MB_CHIP_RESET_REG, val,
> +					       !(val & RTL8365MB_CHIP_RESET_SW_MASK),
> +					       1000, 100000);

[Severity: Medium]
What keeps this reset from overlapping the driver's other multi-register
sequences?

regmap_update_bits() holds priv->map_lock only for the read-modify-write.
regmap_read_poll_timeout() sleeps between reads with map_lock released.
So while SW_RST is still asserted, other contexts can start register
sequences, for example:

  phylink poll (mb->pcs.poll = true) -> pcs_get_state -> rtl8365mb_sds_read()
    (separate ADR write, CMD write, BUSY poll and DATA read)
  mib_work or ethtool -> rtl8365mb_mib_counter_read() under mib_lock
  VLAN/L2 table ops -> rtl8365mb_table_access() under map_lock
  indirect PHY OCP accesses

A table operation already in progress holds map_lock throughout, so the
reset can't interrupt it. A new one can still start during the reset
window, though, and a SerDes or MIB sequence can be split across the
reset.

The 3 second timer starts at conduit up. That is also when userspace
typically creates bridges and adds VLANs and FDB entries.

Could writes issued during the reset be lost? Could a PCS poll read a
bogus link status and make phylink bounce the CPU link? The commit message
says the reset keeps the driver's configuration. Does that only hold for
writes that completed before the reset?

> +	if (ret)
> +		dev_err(priv->dev, "failed to soft reset switch core: %pe\n",
> +			ERR_PTR(ret));
> +}

[ ... ]

> @@ -3108,13 +3147,20 @@ static void rtl8365mb_conduit_state_change(struct dsa_switch *ds,
>  	struct rtl8365mb *mb = priv->chip_data;
>  	int ret;
>  
> -	if (!operational || !mb->sds_in_use)
> +	if (!operational) {
> +		cancel_delayed_work(&mb->sds_core_reset_work);
> +		return;
> +	}

[Severity: Medium]
rtl8365mb_conduit_state_change() never looks at its conduit argument.
rtl8365mb_setup() accepts several CPU ports, and the RTL8367S chip info
lists both a SerDes and an RGMII external interface:

	{ 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) },
	{ 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) |
		PHY_INTF(RMII) | PHY_INTF(RGMII) },

Say ports 6 and 7 are both CPU ports, and the RGMII conduit goes down
within 3 seconds of the SerDes conduit coming up. Would that cancel the
reset meant for the SerDes CPU port?

The SerDes conduit stays operational and gets no further up event, so the
port could stay in the broken state this patch is meant to recover from.

The reverse case: when the RGMII conduit comes up, it passes the global
mb->sds_in_use check. That triggers a SerDes datapath reset and a
switch-wide SW_RST even though the SerDes link did not change.

The same happens when the SerDes is used for a user port and the CPU port
is RGMII, since rtl8365mb_phylink_get_caps() advertises SGMII/2500BASEX
for any port whose extint supports it. Every conduit up would then reset
the whole switch core.

Should this check that the conduit is the one behind the SerDes CPU port?

> +
> +	if (!mb->sds_in_use)
>  		return;

[Severity: Medium]
rtl8365mb_pcs_config() sets mb->sds_in_use for SGMII as well as
2500base-x:

	if (interface == PHY_INTERFACE_MODE_2500BASEX) {
		sds_jam = rtl8365mb_sds_jam_hsgmii;
	...
	mb->sds_in_use = true;

The commit message and the new comment above
rtl8365mb_sds_core_reset_work() describe the problem only for an RTL8367S
connected to an IPQ5018 over HSGMII, and only the Archer AX55 was tested.

Is it intended that every SerDes user now gets an unconditional
switch-core soft reset after conduit up? That includes SGMII setups and
the Mercusys MR80X HSGMII board the Fixes: commit was tested on.

SGMII support predates commit 987137345f33. Because of the Fixes: tag,
stable backports would also change behaviour for SGMII configurations
that existed before that commit.

Could the commit message cover the wider scope, or could the reset be
limited to the affected mode?

>  
>  	ret = rtl8365mb_sds_reset_datapath(priv);
>  	if (ret)
>  		dev_err(priv->dev, "failed to reset SerDes data path: %pe\n",
>  			ERR_PTR(ret));
> +
> +	schedule_delayed_work(&mb->sds_core_reset_work, 3 * HZ);

[Severity: Medium]
This schedules a SW_RST every time the conduit becomes operational, not
only on the first bring-up after rtl8365mb_setup(). In net/dsa/user.c, a
NETDEV_CHANGE on the conduit calls:

	dsa_tree_conduit_oper_state_change(dst, dev,
					   netif_oper_up(dev));

It also calls dsa_tree_conduit_admin_state_change() based on
qdisc_tx_is_noop(). Both reach
dsa_tree_conduit_state_change() -> rtl8365mb_conduit_state_change().

So each of the following resets the switch core 3 seconds later:

  ip link set down/up on the conduit
  a conduit carrier flap
  a conduit driver reset
  a qdisc change

Does that interrupt forwarding on every user port, including bridged
user-to-user traffic that never touches the CPU?

All of the testing in the commit message is on boots. After a runtime
SW_RST, does the L2 LUT keep its contents? That includes the host FDB/MDB
entries DSA installs (assisted_learning_on_cpu_port and fdb_isolation are
set) as well as learned entries.

What about STP state and isolation masks programmed at runtime? Nothing
re-applies or checks that state after the reset.

Should the reset be limited to the first conduit up after setup?

>  }

[ ... ]

> @@ -3323,7 +3371,9 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
>  static void rtl8365mb_teardown(struct dsa_switch *ds)
>  {
>  	struct realtek_priv *priv = ds->priv;
> +	struct rtl8365mb *mb = priv->chip_data;
>  
> +	cancel_delayed_work_sync(&mb->sds_core_reset_work);

[Severity: Medium]
cancel_delayed_work_sync() is only reached through .teardown. On the
shutdown path, dsa_switch_shutdown() closes the conduits and unlinks the
user ports but never calls ds->ops->teardown:

rtl83xx_shutdown()
  dsa_switch_shutdown()
    netif_close_many()
      ... rtl8365mb_conduit_state_change(operational=false)
            cancel_delayed_work()
  dev_set_drvdata(priv->dev, NULL);

cancel_delayed_work() does not wait for an instance that is already
running. The worker can be running for up to about 100 ms (the SW_RST
write plus the poll). Can it keep using priv->map after shutdown has
returned?

The comment on rtl83xx_shutdown() notes that the parent bus may implement
.shutdown() as .remove(). In that case devres frees the devm_kzalloc()'d
realtek_priv, which also holds struct rtl8365mb and this delayed_work.
Would a worker still running then use freed memory?

The same non-sync cancel matters at runtime. If the conduit goes down and
up while the worker runs, rtl8365mb_sds_reset_datapath() can issue its
rtl8365mb_sds_write() sequences while SW_RST may still be asserted. A
reset can also complete after the conduit was reported non-operational.

The existing per-port mib_work has a similar gap on shutdown.

>  	rtl8365mb_stats_teardown(priv);
>  	rtl8365mb_irq_teardown(priv);
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-rtl8365mb-hsgmii-fix-v1-0-f2827126aa6a%40littleit.sk

  reply	other threads:[~2026-11-28 13:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 13:15 [PATCH net 0/2] net: dsa: realtek: rtl8365mb: fix CPU port on HSGMII after boot Juraj Sladek via B4 Relay
2026-11-27 13:15 ` [PATCH net 1/2] net: dsa: realtek: rtl8365mb: reset SerDes data path when conduit comes up Juraj Sladek via B4 Relay
2026-11-27 23:09   ` Mieczyslaw Nalewaj
2026-11-28  6:34     ` Juraj Sládek
2026-11-28  8:19     ` Juraj Sládek
2026-11-28  9:04       ` Mieczyslaw Nalewaj
2026-11-28 13:21   ` netdev-bot+sashiko
2026-11-27 13:15 ` [PATCH net 2/2] net: dsa: realtek: rtl8365mb: soft reset switch core after " Juraj Sladek via B4 Relay
2026-11-28 13:21   ` netdev-bot+sashiko [this message]
2026-11-28 17:55     ` Juraj Sládek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179587210275.3135.16334129438019832908@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=contact@c127.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=juraj.sladek@littleit.sk \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox