From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288257; b=PYXGK5sn2fPtMuWOG2kEoXunoeKz2/1/2sFMprByrZhv6Ltv2d+MqEIxIuSxiF5lIRfN tHWg3If3GYIqLAAYQ8cEjuVSR5aIBB1RppWjmUvvG39GLH+8mEb449uqFCkb3zSmuDTFH uakGFh5zdmY++yz+6mPjraovsV1fbL7H34mxh2P1IgyUO2yMnX5Nqa4KtAix8EXl/36ta J2B7SOLnenGPoU77aMPSdTlzFipcowK4DB0WiQTCtf248AtQU4P58GZyWxi4Kbndr1m6d X5okTYuEJHRCIimYQrL6B+aNZCIu5zAVL0MRxx0e3EsJc0hiQt1mtNycUKPcAzJaVWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288257; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=lnRqIKb2cGJ1EhqZhlQ9BRUbQAILy75HXibtEMKKbJM=; b=zH91TXNEsC1gppnwObzaGbJtJqES8F9utB2l4AnGncOJRYj3PFMHWo6f5ZHUestN7rqc kVv/ttMj7Wbom5atqNuFrBlVSG7nsMPBMkRDShM2PER3bZqMlRonT3jUNkdinCP58mPvb oRYMwJ0mEwRBFR/IxsbsDiUSalwRpSTxVBoY7/HkoEnWGYKi3YEOD7RekyXDl9AK533VJ NYwkgb1//0J/VbpLhohGEf/M/UVLcQsIqTfVFsOPsUkWtmjsPlHp1xJrmCs+/KfTWfVzo d5y+brNEYTuCSNtQ+maSvshwfIrsXkQFVrN10YUnngaYEx4+TjWyztRt3bbq399SUrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eGEuQB+O; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81350606A32C; Thu, 3 Dec 2026 08:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eGEuQB+O Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDD7C1F0092C; Thu, 3 Dec 2026 08:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288257; bh=lnRqIKb2cGJ1EhqZhlQ9BRUbQAILy75HXibtEMKKbJM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=eGEuQB+OLUAS8AKJwzhCQuDIi3hzohGBZV3jWl5WZrRQDlAOSm/g1O72sQ5Bulpd/ /ZdGhS3EoG1K4SJsua73tjrQWxevoGUgAWRhY7p4WNVp4enhP6yNZ2zN2N/7PgTC5d DjU97IVFtsZ1MASzSP8xxoMEnvQzTuVvxHLJI/xeWUco2slasuqlijZsGQwpIQX+Il 9sfa+K7/VE+Nmeco/0GgdSou8u7wnVogMej4RQDljaY+JSo6LOydBMYwPNlkhnVoaL x9m/UwFoR+vaqfEX9eEGxqQu67thG/Um9AiurA6lRBLETiYjVXc5tyFkMJNPEqm98e e0lG8kaszh5VQ== Subject: Re: [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x 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 Date: Thu, 03 Dec 2026 08:57:35 +0000 Message-ID: <179628825554.3146.4460534130612468127@kernel.org> In-Reply-To: <20261202084022.3716891-7-kyle.switch@motor-comm.com> References: <20261202084022.3716891-7-kyle.switch@motor-comm.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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