Re: [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
From: netdev-bot+sashiko
Date: Thu Dec 03 2026 - 03:57:58 EST
Thank you for your contribution! Sashiko AI review found 8 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 5
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).
- [High] The YT922x internal MDIO bus is never unregistered, so its
callbacks keep using freed driver memory.
- [Medium] yt922x_port_down() may switch off the integrated PHY on every
link-down, with nothing to switch it back on.
- [Medium] In forced (out-of-band) mode on YT922x SerDes ports, the
resolved speed and duplex are never given to the PCS/SerDes.
- [Low] The commit message understates the shared-code change in
yt921x_chip_detect().
- [Low] yt922x_dsa_phylink_get_caps() sets MAC_2500FD on the internal PHY
ports (info->internal_mask = GENMASK(7,4), ports 4-7), with the…
- [Low] The YT922x "common extended" register space cannot be reached
through the new helpers.
- [Low] The YT922X_PORT_FORCE_OP write can be skipped on the second and
later link events.
- [Low] yt922x_pcs_config() changes the SerDes line rate without any
reset or power cycle.
--
net: dsa: motorcomm: Add support for Motorcomm YT922x
This adds YT9224 support to the existing yt921x DSA driver. It adds a
minimal set of dsa_switch_ops, a phylink_mac_ops set and a new PCS driver
in pcs-922x.c. It also adds extended register MDIO helpers and an early
return for YT9224 in yt921x_chip_detect().
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 197dadb1046a4..2a684beac408e 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
[ ... ]
> @@ -2279,6 +2290,14 @@ static int yt921x_chip_detect(struct yt921x_priv *priv)
> return -ENODEV;
> }
>
> + if (!yt921x_needs_extmode_check(major)) {
> + dev_info(dev,
> + "Motorcomm %s ethernet switch, chipid: 0x%x\n",
> + info->name, chipid);
> + priv->info = info;
> + return 0;
> + }
> +
[Severity: Low]
The commit message says:
- Add an early return for YT9224 in yt921x_chip_detect(), skipping
the CHIP_MODE, EXTMODE.
Does that cover everything this skips? The early return also skips the
YT921X_SYS_CLK read, so priv->cycle_ns stays 0 on YT9224. Right now the
only user is yt921x_chip_setup_tc(), and the YT922x path doesn't call it:
op_ns = 8 * priv->cycle_ns;
The early return also drops the per-variant match for major 0x9004. The
first table entry with that major is accepted, and the mode/extmode values
(0, 0) in the YT9224 entry are never compared.
Suppose another chip reports major 0x9004, for example a YT9228 if it
shares that major. Would it be logged as "YT9224" and run with
internal_mask GENMASK(7, 4) and serdes_mask BIT(8) | BIT(0)?
Could the commit message describe this, or should detection keep some
kind of variant check?
> res = yt921x_reg_read(priv, YT921X_CHIP_MODE, &mode);
> if (res)
> return res;
> @@ -2699,6 +2718,480 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
> .setup = yt921x_dsa_setup,
> };
>
> +static int yt922x_port_down(struct yt921x_priv *priv, int port)
> +{
> + u32 mask;
> + int res;
> +
> + /* mac force down */
> + mask = YT922X_PORT_LINK | YT922X_PORT_RX_MAC_EN |
> + YT922X_PORT_TX_MAC_EN | YT922X_PORT_LINK_AN;
> + res = yt921x_reg_clear_bits(priv, YT922X_PORTn_CTRL(port), mask);
> + if (res)
> + return res;
> + /* Need force op to make soft configuration effective */
> + mask = YT922X_PORT_FORCE_OP;
> + res = yt921x_reg_set_bits(priv, YT922X_PORTn_CTRL(port), mask);
[Severity: Low]
Does this FORCE_OP write still reach the hardware after the first link
event? yt921x_reg_set_bits() goes through yt921x_reg_update_bits(), which
skips the write if the value doesn't change:
u = v;
u &= ~mask;
u |= val;
if (u == v)
return 0;
The config write just before this doesn't include FORCE_OP in its mask.
So once the bit is 1 it stays 1, and the later FORCE_OP writes in
yt922x_port_down() and yt922x_port_up() do nothing.
That is harmless if FORCE_OP is a level-sensitive "use software config"
select. If it is a commit trigger that needs a new write, would speed,
duplex and pause changes and the forced link-down stop taking effect from
the second link event on?
> + if (res)
> + return res;
> +
> + /* disable en_phy */
> + res = yt921x_reg_clear_bits(priv, YT922X_EN_PHY_VALUE, BIT(port));
> + if (res)
> + return res;
> + res = yt921x_reg_set_bits(priv, YT922X_EN_PHY_OVERWRITE, BIT(port));
[Severity: Medium]
Can the internal PHY still see a link partner after this runs? Every
mac_link_down forces en_phy off for the port, with the override set.
The only code that turns en_phy back on is yt922x_port_up(), called from
mac_link_up. phylink only calls mac_link_up once the PHY or PCS has
already reported link. Nothing in .setup, .port_setup, mac_config or
pcs_enable restores it.
If en_phy gates the integrated PHYs on ports 4-7 (power, isolate or
reset), would a cable unplug or "ip link set dev lanX down" keep the port
down for good, since mac_link_up can never run to turn it back on?
Clearing the MAC TX/RX enables and forcing LINK=0 already quiesces the
MAC on link-down. Is the en_phy override needed here?
> + if (res)
> + return res;
> +
> + return 0;
> +}
[ ... ]
> + /*
> + * Self-negotiation: the LINK/AN bits in ctrl are set based to inband.
> + * Forced mode: set LINK, keep the AN bit at 0 and clear it via the mask
> + */
> + if (pp->serdes && pp->inband)
> + ctrl |= (YT922X_PORT_FC_AN | YT922X_PORT_LINK_AN);
> + else
> + ctrl |= YT922X_PORT_LINK;
> +
> + res = yt921x_reg_update_bits(priv, YT922X_PORTn_CTRL(port), mask, ctrl);
[Severity: Medium]
In forced (out-of-band) mode on the SerDes ports, where do the resolved
speed and duplex get written to the SerDes/PCS? A few things look
missing:
- yt922x_port_up() only writes YT922X_PORTn_CTRL.
- yt922x_phylink_pcs_ops has no .pcs_link_up.
- yt922x_pcs_config() only toggles BMCR_ANENABLE and never sets any
speed bits.
The YT921x path for the same family programs the SerDes side separately
in yt921x_port_up():
if (pp->serdes) {
mask = YT921X_SERDES_SPEED_M;
ctrl = YT921X_SERDES_SPEED(ps);
mask |= YT921X_SERDES_DUPLEX_FULL;
...
yt922x_dsa_phylink_get_caps() advertises 10 through 10000 on the SerDes
ports with SGMII and USXGMII, so phylink can resolve rates below the
lane's native rate. Examples are SGMII with an out-of-band PHY at 10/100,
or a USXGMII fixed-link at 1G/2.5G/5G.
In those cases, could the SerDes stay at its default rate, so the link
reports up but no traffic gets through?
> + if (res)
> + return res;
[ ... ]
> + if (info->internal_mask & BIT(port)) {
> + /* port 4 to port 7, internal utp */
> + __set_bit(PHY_INTERFACE_MODE_INTERNAL,
> + config->supported_interfaces);
> + config->mac_capabilities |= MAC_2500FD;
> + }
[Severity: Low]
Is MAC_2500FD right for the internal PHY ports? The internal_mask comment
in chip.h says "Ports with integral GbE PHYs". The YT9224 binding text
also describes ports 4-7 as internal GbE PHYs.
Either this capability or those descriptions look wrong for YT9224.
[ ... ]
> +static int yt922x_dsa_setup(struct dsa_switch *ds)
> +{
> + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
> + struct device *dev = yt921x_priv_to_device(priv);
> + struct device_node *np = dev->of_node;
> + struct device_node *child;
> + int res;
> +
> + mutex_lock(&priv->reg_lock);
> + res = yt921x_chip_reset(priv);
> + mutex_unlock(&priv->reg_lock);
> + if (res)
> + return res;
> +
> + /* Register the internal mdio bus. */
> + child = of_get_child_by_name(np, "mdio");
> + if (child) {
> + res = yt921x_mbus_int_init(priv, child);
> + of_node_put(child);
> + if (res)
> + return res;
> + }
> +
> + mutex_lock(&priv->reg_lock);
> + res = yt922x_chip_setup(priv);
> + mutex_unlock(&priv->reg_lock);
> + if (res)
> + return res;
> +
> + /* switch sds pcs setup */
> + yt922x_pcs_setup(ds);
> +
> + return 0;
> +}
> +
> +static const struct dsa_switch_ops yt922x_dsa_switch_ops = {
> + /* port */
> + .get_tag_protocol = yt922x_dsa_get_tag_protocol,
> + .phylink_get_caps = yt922x_dsa_phylink_get_caps,
> + .port_setup = yt922x_dsa_port_setup,
> + /* chip */
> + .setup = yt922x_dsa_setup,
> +};
[Severity: High]
What unregisters the internal MDIO bus that yt922x_dsa_setup() registers?
yt921x_mbus_int_init() uses the non-devm of_mdiobus_register() and saves
priv in mbus->priv.
yt922x_dsa_switch_ops has no .teardown, so yt921x_mbus_int_cleanup() is
never called. The YT921x path does this in yt921x_dsa_teardown():
if (priv->mbus_int)
yt921x_mbus_int_cleanup(priv);
On unbind or rmmod, yt921x_mdio_remove() calls dsa_unregister_switch()
and then devres frees priv. The mii_bus and its PHY devices stay
registered with mbus->priv pointing at freed memory. After rmmod,
mbus->read and mbus->write also point into unloaded module text.
A later MDIO access, for example mdio_bus_phy_suspend() during system
suspend, would then run:
yt921x_mbus_int_read()
priv->series->max_ports
mutex_lock(&priv->reg_lock)
on the freed priv. Is this a use-after-free?
The bus also leaks if yt922x_chip_setup() fails after the bus is
registered, because dsa_switch_setup() doesn't call ops->teardown when
ops->setup fails:
err = ds->ops->setup(ds);
if (err < 0)
goto unregister_notifier;
It also leaks on a later failure in dsa_tree_setup().
After that, would a rebind fail? of_mdiobus_register() would be called
again with the same bus id, dev_name(dev), while the old bus still
exists.
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/pcs-922x.c b/drivers/net/dsa/motorcomm/pcs-922x.c
> new file mode 100644
> index 0000000000000..11ef08b7f923d
> --- /dev/null
> +++ b/drivers/net/dsa/motorcomm/pcs-922x.c
[ ... ]
> + switch (reg_type) {
> + case YT922X_PHY_REG_TYPE_COMMON_EXT:
> + return YT922X_COMMON_EXT_PHYADDR;
[Severity: Low]
Can the common extended space be reached at this address?
YT922X_COMMON_EXT_PHYADDR is 9, which equals YT922X_PORT_NUM. Both new
helpers in mdio_bus.c reject it:
yt921x_intif_ext_write() / yt921x_intif_ext_read()
if (port >= priv->series->max_ports)
return -ENODEV;
No caller passes YT922X_PHY_REG_TYPE_COMMON_EXT today. yt922x_pcs_config()
uses SDS_COMMON_EXT, which maps to the port number. So nothing fails now,
but the first user of the common space would always get -ENODEV.
Should the bound check accept address 9, or should the COMMON_EXT case
be dropped until something needs it?
> + default:
> + return port;
> + }
> +}
[ ... ]
> + res = yt921x_intif_ext_read(priv, addr, YT922X_PORT_SDSn, &data);
> + if (res)
> + goto err;
> + data &= ~YT922X_SERDES_MODE_M;
> + data |= ctrl;
> + res = yt921x_intif_ext_write(priv, addr, YT922X_PORT_SDSn, data);
> + if (res)
> + goto err;
[Severity: Low]
Does the SerDes need a reset or power cycle after the mode changes here?
This write can move the lane between 1.25 Gbaud (SGMII, 1000BASE-X,
100BASE-X), 3.125 Gbaud (2500BASE-X) and 10.3125 Gbaud (USXGMII). There
is no BMCR_RESET, no BMCR_PDOWN toggle and no lane reset.
yt922x_phylink_mac_select_pcs() returns the same &priv->ports[port].pcs
for every SerDes interface. phylink_major_config() only calls pcs_disable
and pcs_enable when the PCS pointer changes.
So when the interface changes on a running port, for example an SFP
module swap or a PHY that changes its host interface with speed, could
the PLL/CDR stay set for the old rate until the port is cycled?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com