Devicetree
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: kyle.switch@motor-comm.com
Cc: andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	mmyangfl@gmail.com, horms@kernel.org, linux@armlinux.org.uk,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, david.laight.linux@gmail.com,
	ming.xu@motor-comm.com, xiaolin.xu@motor-comm.com,
	jianmin.wang@motor-comm.com, wei.zhang@gl-inet.com,
	sijia.huang@gl-inet.com
Subject: Re: [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
Date: Thu, 03 Dec 2026 08:57:26 +0000	[thread overview]
Message-ID: <179628824686.3146.10831703982542427707@kernel.org> (raw)
In-Reply-To: <20261202084022.3716891-2-kyle.switch@motor-comm.com>

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

Critical: 0 · High: 0 · Medium: 1 · Low: 2

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] yt92xx_register_switch() in drivers/net/dsa/motorcomm/chip.c
  is called from yt921x_mdio_probe().
- [Low] The commit message promises a "data-driven lookup by the chip
  ID", but yt92xx_series_lookup() in drivers/net/dsa/motorcomm/chip.c…
- [Low] The patch adds YT921X_AGEING_TIME_UNIT (5000U) in chip.h and uses
  it to compute the advertised ds->ageing_time_min/max in…

--

net: dsa: motorcomm: initialize dsa_switch based on chipid

This commit replaces the hardcoded dsa_switch setup in yt921x_mdio_probe()
with a lookup on the major revision read from YT921X_CHIP_ID. It adds
struct yt92xx_series and a yt92xx_series_table[] with a single YT921x
entry. The matched series is stored in yt921x_priv.

> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 82f364986aebd..197dadb1046a4 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -2699,6 +2699,68 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
>  	.setup			= yt921x_dsa_setup,
>  };
>  
> +static const struct yt92xx_series yt92xx_series_table[] = {
> +	[YT92XX_MODE_YT921X] = {
> +		.name = "YT921x",
> +		.max_ports = YT921X_PORT_NUM,
> +		.num_lag_ids = YT921X_LAG_NUM,
> +		.ageing_time_min = 1U * YT921X_AGEING_TIME_UNIT,
> +		.ageing_time_max = U16_MAX * YT921X_AGEING_TIME_UNIT,

[Severity: Low]
This isn't a bug, but the advertised ageing range now uses the new
YT921X_AGEING_TIME_UNIT. The function that programs the register still
uses a literal:

drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_set_ageing_time() {
    ...
	/* AGEING reg is set in 5s step */
	ctrl = clamp(msecs / 5000, 1, U16_MAX);
    ...
}

Should yt921x_dsa_set_ageing_time() use YT921X_AGEING_TIME_UNIT, or the
series data? Then the range DSA validates against and the value written
to YT921X_AGEING would come from one definition.

Later in the series, YT922X_AGEING_TIME_UNIT is added with a value of
6000U. The YT922x ops don't install .set_ageing_time today, so nothing is
mismatched yet. The two values could drift apart if the op were ever
shared.

> +		.dscp_prio_mapping_is_global = true,
> +		.assisted_learning_on_cpu_port = true,
> +		.switch_ops = &yt921x_dsa_switch_ops,
> +		.mac_ops = &yt921x_phylink_mac_ops
> +	},
> +};
> +
> +static const struct yt92xx_series *yt92xx_series_lookup(u32 major)
> +{
> +	if (major == YT9215_MAJOR || major == YT9218_MAJOR)
> +		return &yt92xx_series_table[YT92XX_MODE_YT921X];
> +	else
> +		return NULL;
> +}

[Severity: Low]
The commit message describes this as:

  "a data-driven lookup by the chip ID and Major"

However, yt92xx_series_lookup() is a hardcoded if-chain over the majors.
The supported majors are already listed in yt921x_infos[]. During .setup,
yt921x_chip_detect() reads YT921X_CHIP_ID again and matches it against
that table. Isn't this a second copy of the same list?

If a major is added to one list and not the other, probe in
yt92xx_register_switch() and setup in yt921x_chip_detect() would disagree
about whether the chip is supported. The later patch "net: dsa:
motorcomm: Add support for Motorcomm YT922x" already has to update both
places for YT9224_MAJOR.

Would it be simpler to add a series pointer to each yt921x_info entry and
do a single detection pass?

> +
> +static int yt92xx_register_switch(struct dsa_switch *ds)
> +{
> +	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
> +	struct device *dev = yt921x_priv_to_device(priv);
> +	const struct yt92xx_series *series;
> +	u32 chipid;
> +	u32 major;
> +	int res;
> +
> +	mutex_lock(&priv->reg_lock);
> +	res = yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid);
> +	mutex_unlock(&priv->reg_lock);

[Severity: Medium]
Is it safe to read YT921X_CHIP_ID here before the SMI state machine has
been realigned?

This is now the first register access to the switch, and nothing calls
yt921x_reg_mdio_reset() before it. The comment above
yt921x_reg_mdio_reset() describes this ordering as the problem the reset
was added to solve:

 * An SMI register access is 4 MDIO frames. An interrupted access leaves the
 * machine in an unknown state, and every following access fails or acts on a
 * stale address.
 ...
 * Furthermore, the driver verifies the chip id before
 * firing the reset, so the reset can never be triggered reliably.

yt921x_reg_mdio_read() only checks MDIO bus return codes. The FSM can be
left misaligned, for example by an interrupted access from a bootloader,
a kexec, or a previous driver instance. In that case the read still
succeeds, but returns 0xdeaddead or stale data. For example, starting in
DHw:

  DHw --awr--> AH --awr--> ALr --dr--> 0xdead --dr--> 0xdead

The major then comes out as 0xdead, yt92xx_series_lookup() returns NULL,
and probe fails:

yt921x_mdio_probe()
  yt92xx_register_switch()
    yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid)  /* returns 0 */
    yt92xx_series_lookup(0xdead)                     /* NULL */
    return -ENODEV;

This happens before dsa_register_switch(), so .setup never runs and
yt921x_chip_reset() never gets to realign the FSM:

drivers/net/dsa/motorcomm/chip.c:yt921x_chip_reset() {
    ...
	res = yt921x_reg_mdio_reset(priv->reg_ctx);
    ...
	res = yt921x_chip_detect(priv);
    ...
}

Probe is not retried after -ENODEV. The switch ports stay unavailable
until the driver is manually unbound and rebound.

Before this patch, probe did no register access, so the realign always
ran first. The later YT922x support patch keeps the same read in
yt92xx_register_switch().

Would it work to call yt921x_reg_mdio_reset(priv->reg_ctx) under
reg_lock before this read? Another option is to pick the series from the
OF compatible and leave the chip ID check to yt921x_chip_reset(), after
the realign.

> +	if (res) {
> +		dev_err(dev, "Failed to read Chip ID with errcode: %d\n", res);
> +		return res;
> +	}
> +
> +	major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid);
> +	series = yt92xx_series_lookup(major);
> +	if (!series) {
> +		dev_err(dev, "Unknown Chip ID: 0x%x, or unknown Major: 0x%x\n",
> +			chipid, major);
> +		return -ENODEV;
> +	}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com

  parent reply	other threads:[~2026-12-03  8:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch
2026-12-02  8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch
2026-12-03  8:40   ` sashiko-bot
2026-12-03  8:57   ` netdev-bot+sashiko [this message]
2026-12-02  8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch
2026-12-03  8:40   ` sashiko-bot
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch
2026-12-02 22:58   ` Rob Herring (Arm)
2026-12-03  8:40   ` sashiko-bot
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch
2026-12-03  8:57   ` netdev-bot+sashiko
2026-12-02  8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch
2026-12-03  8:40   ` sashiko-bot
2026-12-03  8:57   ` netdev-bot+sashiko

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=179628824686.3146.10831703982542427707@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jianmin.wang@motor-comm.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kyle.switch@motor-comm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=ming.xu@motor-comm.com \
    --cc=mmyangfl@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=sijia.huang@gl-inet.com \
    --cc=wei.zhang@gl-inet.com \
    --cc=xiaolin.xu@motor-comm.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