net: dsa: motorcomm: add support yt922x driver
v8 cover net: dsa: motorcomm: add support yt922x driver
changes in v8:
patch 1: 1) Add a lock operation to acquire the chip ID during the probe()
stage.
2) Remove meaningless changes.
patch 3: Modify the changelog description.
patch 6: 1) Remove sds_init() in this patch.
2) Code refactoring, including yt922x_sds_phyaddr_get() and yt921x_needs_extmode_check()
3) In yt921x_intif_ext_write() and yt921x_intif_ext_read(), add a boundary check for phyaddr. The reason is that the phyaddr of the top ext register is 9, so max_ports should be used for the check to include it.
4) In the yt922x driver, added initialization of yt921x_port for exporting priv.
changes in v7:
patch 1: Fix the series_lookup() redundancy issue.
Fix the dsa->priv initialization and the code style issue.
patch 6: Move psc definition to yt921x_port
Fix psc_get_state() and an_restart().
Use the existing yt921x driver interface for the duplicated logic for chip_reset().
Move the yt922x_cpu_port_set() to chip_setup_dsa() to align with yt921x function.
Kyle Switch (6):
net: dsa: motorcomm: initialize dsa_switch based on chipid
net: dsa: motorcomm: use max_ports in series for port bounds checking
net: dsa: motorcomm: move mib start from probe() to dsa_setup()
net: dsa: motorcomm: move mib stop from remove() to teardown()
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x
drivers/net/dsa/motorcomm/Kconfig | 3 +- drivers/net/dsa/motorcomm/chip.c | 789 ++++++++++++++++++++++++++++-- drivers/net/dsa/motorcomm/chip.h | 113 +++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 +++++ 7 files changed, 996 insertions(+), 29 deletions(-) create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
PATCH v8 1/6 net: dsa: motorcomm: initialize dsa_switch based on chipid
Introduce yt92xx_series structure to hold private data for different switch families, replacing hardcoded logic in probe(). This makes the driver more extensible for future switch support.
--- drivers/net/dsa/motorcomm/chip.c | 69 ++++++++++++++++++++++++++++---- drivers/net/dsa/motorcomm/chip.h | 20 +++++++++ 2 files changed, 81 insertions(+), 8 deletions(-)
drivers/net/dsa/motorcomm/chip.c +61 -8
@@ -4679,6 +4679,63 @@ 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 ] = { + .mode =YT92XX_MODE_YT921X , + .name ="YT921x" , + .max_ports =YT921X_PORT_NUM , + .num_lag_ids =YT921X_LAG_NUM , + .ageing_time_min =1 *5000 , + .ageing_time_max =U16_MAX *5000 , + .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 ; +} + +static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +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); +if (res) +return res; + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) +return -ENODEV ; + priv->series = series; + + ds->assisted_learning_on_cpu_port = + priv->series->assisted_learning_on_cpu_port; + ds->dscp_prio_mapping_is_global = + priv->series->dscp_prio_mapping_is_global; + ds->ageing_time_min = priv->series->ageing_time_min; + ds->ageing_time_max = priv->series->ageing_time_max; + ds->num_lag_ids = priv->series->num_lag_ids; + ds->num_ports = priv->series->max_ports; + ds->ops = priv->series->switch_ops; + ds->phylink_mac_ops = priv->series->mac_ops; + +return 0 ; +} +static void yt921x_mdio_shutdown (struct mdio_device *mdiodev) {struct yt921x_priv *priv =mdiodev_get_drvdata (mdiodev);
@@ -4727,6 +4784,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)struct yt921x_reg_mdio *mdio;struct yt921x_priv *priv;struct dsa_switch *ds; +int res; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -4754,15 +4812,10 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) ds = &priv->ds; ds->dev = dev; - ds->assisted_learning_on_cpu_port = true; - ds->dscp_prio_mapping_is_global = true; ds->priv = priv; - ds->ops = &yt921x_dsa_switch_ops; - ds->ageing_time_min =1 *5000 ; - ds->ageing_time_max =U16_MAX *5000 ; - ds->phylink_mac_ops = &yt921x_phylink_mac_ops; - ds->num_lag_ids =YT921X_LAG_NUM ; - ds->num_ports =YT921X_PORT_NUM ; + res =yt92xx_register_switch (ds); +if (res) +return res;mdiodev_set_drvdata (mdiodev, priv);
drivers/net/dsa/motorcomm/chip.h +20 -0
@@ -960,9 +960,29 @@ struct yt921x_reg_ops {int (*write)(void *context,u32 reg,u32 val); }; +enum yt92xx_mode { +YT92XX_MODE_YT921X , +YT92XX_MODE_YT922X , +YT92XX_MODE_MAX , +}; + +struct yt92xx_series { +enum yt92xx_mode mode; +const char *name; +unsigned int max_ports; +unsigned int num_lag_ids; +unsigned int ageing_time_min; +unsigned int ageing_time_max; +u32 dscp_prio_mapping_is_global; +u32 assisted_learning_on_cpu_port; +const struct dsa_switch_ops *switch_ops; +const struct phylink_mac_ops *mac_ops; +}; +struct yt921x_priv {struct dsa_switch ds; +const struct yt92xx_series *series;const struct yt921x_info *info;unsigned int meter_slot_ns;unsigned int port_shape_slot_ns;
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] yt92xx_register_switch() (drivers/net/dsa/motorcomm/chip.c:4705) adds a live MDIO transaction and a new, completely silent probe abort…
--
net: dsa: motorcomm: initialize dsa_switch based on chipid
This adds a yt92xx_series table describing per-family dsa_switch parameters, and a new yt92xx_register_switch() helper that reads the chip ID and fills in ds fields from the matching table entry. The previously hardcoded assignments in yt921x_mdio_probe() are removed.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8
-0+static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; +
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4722
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+mutex_lock (&priv->reg_lock); + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +mutex_unlock (&priv->reg_lock); +if (res) +return res; + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) +return -ENODEV ;
[Severity: Low]
Should this path print something when the chip ID is not recognised?
Before this patch the first register access happened later, in yt921x_dsa_setup() -> yt921x_chip_detect(), which logs the value it read before giving up:
drivers/net/dsa/motorcomm/chip.c:yt921x_chip_detect() {
...
if (!info->name) {
dev_err(dev, "Unexpected chipid 0x%x\n", chipid);
return -ENODEV;
}
...
}Here yt92xx_register_switch() returns a bare -ENODEV when yt92xx_series_lookup() does not match YT9215_MAJOR or YT9218_MAJOR, and a bare bus errno when yt921x_reg_read() of YT921X_CHIP_ID fails. Since really_probe() only pr_debug()s an -ENODEV/-ENXIO return, a board with an unsupported or non-responding switch would end up with no message in dmesg explaining why the DSA switch never appeared. Would a dev_err() with the chipid here keep the previous diagnostics?
Related: the commit message says the change is about
"replacing hardcoded logic in probe()"
which reads as a pure data-driven refactor. Could it also mention that probe() now performs an MDIO read of YT921X_CHIP_ID and can fail early because of it? That is a behavioural change for probe(), which previously had no hardware dependency.
Quoted 15 lines
drivers/net/dsa/motorcomm/chip.c +15
-0+ priv->series = series; + + ds->assisted_learning_on_cpu_port = + priv->series->assisted_learning_on_cpu_port; + ds->dscp_prio_mapping_is_global = + priv->series->dscp_prio_mapping_is_global; + ds->ageing_time_min = priv->series->ageing_time_min; + ds->ageing_time_max = priv->series->ageing_time_max; + ds->num_lag_ids = priv->series->num_lag_ids; + ds->num_ports = priv->series->max_ports; + ds->ops = priv->series->switch_ops; + ds->phylink_mac_ops = priv->series->mac_ops; + +return 0 ; +}
[ ... ]
Quoted 16 lines
drivers/net/dsa/motorcomm/chip.c +3
-8@@ -4754,15 +4812,10 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) ds = &priv->ds; ds->dev = dev; - ds->assisted_learning_on_cpu_port = true; - ds->dscp_prio_mapping_is_global = true; ds->priv = priv; - ds->ops = &yt921x_dsa_switch_ops; - ds->ageing_time_min =1 *5000 ; - ds->ageing_time_max =U16_MAX *5000 ; - ds->phylink_mac_ops = &yt921x_phylink_mac_ops; - ds->num_lag_ids =YT921X_LAG_NUM ; - ds->num_ports =YT921X_PORT_NUM ; + res =yt92xx_register_switch (ds); +if (res) +return res;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com
Re: [PATCH net-next v8 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
In reply to Kyle Switchdrivers/net/dsa/motorcomm/chip.h struct yt921x_reg_ops { · line 970
Quoted 2 lines
drivers/net/dsa/motorcomm/chip.h +2
-0+struct yt92xx_series { +enum yt92xx_mode mode;
Is this mode value actually needed?
Other than that:
Andrew
PATCH v8 2/6 net: dsa: motorcomm: use max_ports in series for port bounds checking
In reply to Kyle SwitchReplace the hardcoded YT921X_PORT_NUM macro with the per-series max_ports field in port validation. This removes family-specific constants from the common code path and simplifies adding new switch families with different port counts.
No functional change for existing YT921X devices.
--- drivers/net/dsa/motorcomm/chip.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/chip.c +5 -3
@@ -357,7 +357,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg)u16 val;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return U16_MAX ;mutex_lock (&priv->reg_lock);
@@ -375,7 +375,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)struct yt921x_priv *priv = mbus->priv;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return -ENODEV ;mutex_lock (&priv->reg_lock);
@@ -390,6 +390,7 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) {struct device *dev =to_device (priv);struct mii_bus *mbus; +u32 max_ports;int res; mbus =devm_mdiobus_alloc (dev);
@@ -402,7 +403,8 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->read = yt921x_mbus_int_read; mbus->write = yt921x_mbus_int_write; mbus->parent = dev; - mbus->phy_mask = (u32 )~GENMASK (YT921X_PORT_NUM -1 ,0 ); + max_ports = priv->series->max_ports; + mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); res =devm_of_mdiobus_register (dev, mbus, mnp);if (res)
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] yt921x_mbus_int_read()/yt921x_mbus_int_write() (chip.c:360 and chip.c:378) now validate internal-MDIO addresses against…
Pre-existing issues:
- [Low] Claim of an inconsistency between the runtime per-series bound (ds->num_ports = priv->series->max_ports at chip.c:4734, and now the…
--
net: dsa: motorcomm: use max_ports in series for port bounds checking
This patch replaces YT921X_PORT_NUM with priv->series->max_ports in the internal MDIO bus read/write address checks and in the phy_mask computation in yt921x_mbus_int_init(). The commit message states there is no functional change for existing YT921X devices.
Quoted 14 lines
drivers/net/dsa/motorcomm/chip.c +1
-1@@ -357,7 +357,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg)u16 val;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return U16_MAX ;mutex_lock (&priv->reg_lock);
drivers/net/dsa/motorcomm/chip.c yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data) · line 379
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +1
-1@@ -375,7 +375,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)struct yt921x_priv *priv = mbus->priv;int res; -if (port >=YT921X_PORT_NUM ) +if (port >= priv->series->max_ports)return -ENODEV ;
[Severity: Low]
Is max_ports the right quantity for these two checks? The address passed to yt921x_mbus_int_read()/yt921x_mbus_int_write() ends up in the YT921X_INT_MBUS_CTRL PORT field, which selects one of the integral GbE PHYs, whereas max_ports is the total DSA port count including the external MAC ports and the MCU port.
The driver keeps those as separate quantities:
drivers/net/dsa/motorcomm/chip.h:
/* 8 internal + 2 external + 1 mcu */ #define YT921X_PORT_NUM 11 ... #define yt921x_port_is_internal(port) ((port) < 8) #define yt921x_port_is_external(port) ((port) == 8 || (port) == 9)
and struct yt921x_info carries:
/* Ports with integral GbE PHYs, not including MCU Port 10 */ u16 internal_mask;
With max_ports == 11 the guard now accepts internal-bus transactions for ports 8 and 9 (external MACs) and port 10 (MCU), none of which have an integral PHY. For a series whose integral PHYs are not the lowest port indices, the accepted set diverges further: the YT922x entry added later in this series sets max_ports = 9 while its integral UTP PHYs are only ports 4..7, so ports 0..3 and 8 would also be accepted.
The effect is bounded: these callbacks only see addresses phylib has bound from the "mdio" child node, so a DT would have to list a PHY at such an address. When it does, the driver runs a real INT_MBUS cycle against a nonexistent PHY index, and yt921x_intif_read() already has a dev_info() for the resulting unexpected read data.
Would keying the check off the integral-PHY count or mask (the internal_mask / yt921x_port_is_internal equivalent) rather than max_ports, which DSA consumes as ds->num_ports, match the hardware field being programmed?
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.c +1
-0@@ -390,6 +390,7 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) {struct device *dev =to_device (priv);struct mii_bus *mbus; +u32 max_ports;int res; mbus =devm_mdiobus_alloc (dev);
drivers/net/dsa/motorcomm/chip.c yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) · line 407
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +2
-1@@ -402,7 +403,8 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->read = yt921x_mbus_int_read; mbus->write = yt921x_mbus_int_write; mbus->parent = dev; - mbus->phy_mask = (u32 )~GENMASK (YT921X_PORT_NUM -1 ,0 ); + max_ports = priv->series->max_ports; + mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 );
[Severity: Low]
This isn't a bug introduced by this patch, but now that the runtime bound comes from priv->series->max_ports, is it worth tying that value to the compile-time array size?
yt92xx_register_switch() already does:
ds->num_ports = priv->series->max_ports;
while the per-port state stays fixed size in chip.h:
struct yt921x_port ports[YT921X_PORT_NUM];
and several helpers still loop on the old constant, for example in yt921x_chip_setup_dsa():
for (int i = 0; i < YT921X_PORT_NUM; i++) ctrl |= YT921X_ACT_UNK_ACTn_TRAP(i);
Nothing is broken today: the only two series entries are max_ports == 11 (YT921x) and max_ports == 9 (YT922x), both within ARRAY_SIZE(priv->ports), and the remaining YT921X_PORT_NUM loops live in helpers reachable only through yt921x_dsa_switch_ops, i.e. only when max_ports == 11. A BUILD_BUG_ON() relating max_ports to ARRAY_SIZE(priv->ports), or converting those loops to max_ports, would make the invariant explicit for the next series added.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com
Re: [PATCH net-next v8 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
In reply to Kyle Switchdrivers/net/dsa/motorcomm/chip.c yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) · line 407
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +2
-1@@ -402,7 +403,8 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->read = yt921x_mbus_int_read; mbus->write = yt921x_mbus_int_write; mbus->parent = dev; - mbus->phy_mask = (u32 )~GENMASK (YT921X_PORT_NUM -1 ,0 ); + max_ports = priv->series->max_ports; + mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 );
A separate patch, but can this be changed to GENMASK_U32() so the cast is not needed? There maybe be other instances in this driver which can be changed as well.
Andrew
Re: [PATCH net-next v8 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
Quoted 10 lines · Andrew Lunn
drivers/net/dsa/motorcomm/chip.c yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) · line 407
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +2
-1@@ -402,7 +403,8 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->read = yt921x_mbus_int_read; mbus->write = yt921x_mbus_int_write; mbus->parent = dev; - mbus->phy_mask = (u32 )~GENMASK (YT921X_PORT_NUM -1 ,0 ); + max_ports = priv->series->max_ports; + mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 );A separate patch, but can this be changed to
GENMASK_U32()so the cast is not needed? There maybe be other instances in this driver which can be changed as well.
Ans: okay, will be updated in next patch.
Quoted 4 lines
Reviewed-by Andrew Lunn <[email protected]>Andrew
PATCH v8 3/6 net: dsa: motorcomm: move mib start from probe() to dsa_setup()
In reply to Kyle SwitchMove the delayed work initialization of the per-port MIB polling from yt921x_mdio_probe() into the DSA .setup() callback, changing its lifetime from once per probe() to once per DSA .setup().
--- drivers/net/dsa/motorcomm/chip.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/dsa/motorcomm/chip.c +8 -7
@@ -4553,6 +4553,14 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)struct device_node *child;int res; +/* mib polling init */ +for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { +struct yt921x_port *pp = &priv->ports[i]; + + pp->index = i; +INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); + } +mutex_lock (&priv->reg_lock); res =yt921x_chip_reset (priv);mutex_unlock (&priv->reg_lock);
@@ -4805,13 +4813,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) priv->reg_ops = &yt921x_reg_ops_mdio; priv->reg_ctx = mdio; -for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { -struct yt921x_port *pp = &priv->ports[i]; - - pp->index = i; -INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); - } - ds = &priv->ds; ds->dev = dev; ds->priv = priv;
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 3/6] net: dsa: motorcomm: move mib start from probe() to dsa_setup()
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 (3) · Low: 0
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] yt921x_dsa_setup() now runs INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib) for every port on every DSA .setup() invocation…
- [Medium] After this patch the per-port delayed works are initialized only inside yt921x_dsa_setup() (chip.c:4556-4562), while…
Pre-existing issues:
- [Medium] If dsa_register_switch() fails after yt921x_dsa_setup() already ran and a port's mib_read work has been scheduled…
- [Medium] The self-re-arming per-port MIB poller (yt921x_poll_mib() -> yt921x_read_mib(), chip.c:609-626) is never stopped by…
- [Medium] The per-port init block moved into yt921x_dsa_setup() (chip.c:4556-4562) sets pp->index and initializes pp->mib_read but…
--
net: dsa: motorcomm: move mib start from probe() to dsa_setup()
This moves the per-port MIB delayed_work initialization out of yt921x_mdio_probe() and into the DSA .setup() callback, so the works are now initialized once per .setup() instead of once per probe().
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +0
-0@@ -4553,6 +4553,14 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)struct device_node *child;
drivers/net/dsa/motorcomm/chip.c static int yt921x_dsa_setup(struct dsa_switch *ds) · line 4563
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +8
-0int res; +/* mib polling init */ +for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { +struct yt921x_port *pp = &priv->ports[i]; + + pp->index = i; +INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); + } +
[Severity: High]
Can this re-initialize a delayed_work that is still armed or queued?
.setup() can run a second time for the same struct yt921x_priv without a new probe(). dsa_switch_teardown() clears ds->setup, so when a peer switch of a multi-switch tree is unbound and re-bound, the whole tree is torn down and set up again and ds->ops->setup() is invoked once more.
The counterpart yt921x_dsa_teardown() does not touch the works at all:
static void yt921x_dsa_teardown(struct dsa_switch *ds)
{
struct yt921x_priv *priv = to_yt921x_priv(ds);
#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
yt921x_leds_remove(priv);
#endif
}The only per-port cancellation before device removal is the non-synchronous cancel in yt921x_phylink_mac_link_down():
/* No need to sync; port control block is hold until device remove */ cancel_delayed_work(&priv->ports[port].mib_read);
and the worker re-arms itself unconditionally:
yt921x_poll_mib() ... schedule_delayed_work(&pp->mib_read, delay);
So if yt921x_poll_mib() is executing when the port goes down, the cancel is a no-op and the work is armed again. A subsequent .setup() then runs INIT_DELAYED_WORK() on that live work, overwriting work->data, work->entry and dwork->timer while they are linked into the timer base or a pool worklist. Does that risk list corruption, lost work, and debug-objects/lockdep splats?
The comment quoted above ("port control block is hold until device remove") also seems to no longer hold once the init lifetime becomes per-.setup(); should it be updated together with this change?
Note the follow-up patch in this series, "net: dsa: motorcomm: move mib stop from remove() to teardown()", adds the disable_delayed_work_sync() loop to yt921x_dsa_teardown(), and with that in place the works are drained before any re-initialization. Would it make sense to fold the two changes together so this intermediate state does not exist for bisect?
[Severity: Medium]
This is a pre-existing issue, but the new placement of the init loop makes it worth asking about: can the poller read the MIB block while it is reset?
The init block now sits immediately before:
mutex_lock(&priv->reg_lock); res = yt921x_chip_reset(priv); mutex_unlock(&priv->reg_lock);
Since yt921x_dsa_teardown() does not stop the poller and yt921x_phylink_mac_link_down() only uses cancel_delayed_work() against a worker that re-arms itself, a poll can still run during a second .setup(), in the window between yt921x_chip_reset() and yt921x_chip_setup() re-enabling YT921X_FUNC_MIB plus writing YT921X_MIB_CTRL_CLEAN. priv->reg_lock serializes individual register accesses but does not keep the poller out of that window.
yt921x_read_mib() treats any decrease of the low 32 bits as a wrap:
val = (old_val & ~(u64)U32_MAX) | val0; if (val < old_val) val += 1ull << 32;
so one read of a reset or disabled MIB block permanently shifts the shadow counter by 2^32 rather than producing a single bad sample. The follow-up patch adding disable_delayed_work_sync() to yt921x_dsa_teardown() closes this window.
[Severity: Medium]
This is a pre-existing divergence, but this hunk moves the per-port init onto exactly the path that clears the hardware counters: should the software MIB shadow be reset here too?
The block sets pp->index and initializes pp->mib_read, but leaves pp->mib, pp->rx_frames and pp->tx_frames untouched, while the same .setup() path clears the hardware counters in yt921x_chip_setup():
/* Clear MIB */ ctrl = YT921X_MIB_CTRL_CLEAN | YT921X_MIB_CTRL_ALL_PORT; res = yt921x_reg_write(priv, YT921X_MIB_CTRL, ctrl);
yt921x_read_mib() documents the precondition:
/* Read and handle overflow of 32bit MIBs. MIB buffer must be zeroed before. */
pp->mib is only ever zeroed by the devm_kzalloc() in yt921x_mdio_probe(). On a second .setup() for the same priv the hardware counters restart at zero while the shadow keeps its old values, so the wrap heuristic adds 2^32 to every 32-bit counter and ethtool -S / rtnl statistics jump by roughly 4.29e9 per counter. This one is still present at the end of the series.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0mutex_lock (&priv->reg_lock); res =yt921x_chip_reset (priv);mutex_unlock (&priv->reg_lock);
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4814
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +0
-7@@ -4805,13 +4813,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) priv->reg_ops = &yt921x_reg_ops_mdio; priv->reg_ctx = mdio; -for (size_t i =0 ; i <ARRAY_SIZE (priv->ports); i++) { -struct yt921x_port *pp = &priv->ports[i]; - - pp->index = i; -INIT_DELAYED_WORK (&pp->mib_read, yt921x_poll_mib); - } -
[Severity: Medium]
With the init now conditional on .setup() having run, can yt921x_mdio_remove() operate on never-initialized works?
yt921x_mdio_remove() still disables all of them unconditionally:
for (size_t i = ARRAY_SIZE(priv->ports); i-- > 0; ) {
struct yt921x_port *pp = &priv->ports[i];
disable_delayed_work_sync(&pp->mib_read);
}dsa_register_switch() can return 0 without ever calling ds->ops->setup():
net/dsa/dsa.c:dsa_tree_setup() {
...
complete = dsa_tree_setup_routing_table(dst);
if (!complete)
return 0;
...
}That happens when a DT-declared dsa-link peer switch has not probed yet, or never probes. priv is devm_kzalloc()'d and drvdata is set before dsa_register_switch(), so a later unbind or module unload reaches yt921x_mdio_remove() with zero-filled delayed_work objects.
disable_delayed_work_sync() -> __cancel_work_sync() then calls timer_delete() on an uninitialized timer, which trips the debug-objects assert under CONFIG_DEBUG_OBJECTS_TIMERS, and unconditionally calls __flush_work(work, true):
kernel/workqueue.c:__flush_work() {
if (WARN_ON(!work->func))
return false;
...
}so one warning per port. The follow-up patch moves this loop into yt921x_dsa_teardown(), which DSA only invokes when setup actually ran (dsa_switch_teardown() returns early on !ds->setup), so this only exists at this bisect point.
[Severity: Medium]
This isn't a bug introduced by this patch, but the probe error path looks
unprotected: does it leave a scheduled work pointing at freed memory?
yt921x_mdio_probe() ends with:
mdiodev_set_drvdata(mdiodev, priv); return dsa_register_switch(ds);
If dsa_register_switch() fails after yt921x_dsa_setup() already ran and a port's work has been armed byyt921x_phylink_mac_link_up() -> schedule_delayed_work(&priv->ports[port].mib_read, 0), probe returns the error, the mdio core does not call yt921x_mdio_remove(), and devm releases the priv that embeds the delayed_work. Port teardown on the unwind path only calls cancel_delayed_work(), and yt921x_poll_mib() re-arms itself, so the work is not guaranteed to be drained and can run against freed priv/pp memory.
Placing disable_delayed_work_sync() in yt921x_dsa_teardown(), as the follow-up patch does, also covers this, since DSA calls .teardown() on the tree-setup error paths via dsa_tree_teardown_switches().
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com
PATCH v8 4/6 net: dsa: motorcomm: move mib stop from remove() to teardown()
In reply to Kyle SwitchThis change ensures symmetry with the MIB start operation, which is already invoked in the setup(). Additionally, it consolidates per-switch operation into the appropriate DSA ops, improving code organization and maintainability.
--- drivers/net/dsa/motorcomm/chip.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/net/dsa/motorcomm/chip.c +5 -6
@@ -4233,6 +4233,11 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds)#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS )yt921x_leds_remove (priv);#endif +for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) { +struct yt921x_port *pp = &priv->ports[i]; + +disable_delayed_work_sync (&pp->mib_read); + } }static int yt921x_chip_detect (struct yt921x_priv *priv)
@@ -4763,12 +4768,6 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)if (!priv)return ; -for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) { -struct yt921x_port *pp = &priv->ports[i]; - -disable_delayed_work_sync (&pp->mib_read); - } -dsa_unregister_switch (&priv->ds);for (unsigned int i =0 ; i <ARRAY_SIZE (priv->acl_blks); i++) {
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 4/6] net: dsa: motorcomm: move mib stop from remove() to teardown()
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Commit message inaccuracy plus fragile use of a counting-disable API.
--
net: dsa: motorcomm: move mib stop from remove() to teardown()
The per-port MIB polling work is now disabled in yt921x_dsa_teardown() instead of yt921x_mdio_remove(). The loop calling disable_delayed_work_sync() on priv->ports[i].mib_read is moved verbatim from the mdio remove path into the DSA teardown op.
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
drivers/net/dsa/motorcomm/chip.c static void yt921x_dsa_teardown(struct dsa_switch *ds) · line 4241
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.c +5
-0@@ -4233,6 +4233,11 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds)#if IS_ENABLED (CONFIG_NET_DSA_YT921X_LEDS )yt921x_leds_remove (priv);#endif +for (size_t i =ARRAY_SIZE (priv->ports); i-- >0 ; ) { +struct yt921x_port *pp = &priv->ports[i]; + +disable_delayed_work_sync (&pp->mib_read); + } }
[Severity: Low]
The changelog says this change "ensures symmetry with the MIB start operation, which is already invoked in the setup()". Is that accurate? The only MIB work operation in yt921x_dsa_setup() is the initialization:
INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
The polling is actually started from yt921x_phylink_mac_link_up():
schedule_delayed_work(&priv->ports[port].mib_read, 0);
and re-armed by yt921x_poll_mib() itself:
schedule_delayed_work(&pp->mib_read, delay);
So what the new teardown call pairs with looks like the work initialization rather than a start. Would it be worth rewording that sentence?
A second question about the API choice here. disable_delayed_work_sync() is a counting disable:
kernel/workqueue.c:disable_delayed_work_sync() {
return __cancel_work_sync(&dwork->work,
WORK_CANCEL_DELAYED | WORK_CANCEL_DISABLE);
}The disable depth it leaves in work->data is only cleared by enable_delayed_work(), and there is no enable_delayed_work() call anywhere under drivers/net/dsa/motorcomm/. ds->ops->teardown is repeatable — dsa_switch_teardown() runs it on unregister and the dsa_switch_setup() error path runs it too — and a later ->setup() can run on the same priv.
Today this still works only because yt921x_dsa_setup() re-runs INIT_DELAYED_WORK() for every port, which resets work->data and silently drops the accumulated disable count. If that one-shot init is ever moved back to probe(), which is the more usual DSA pattern, would the schedule_delayed_work() in yt921x_phylink_mac_link_up() become a no-op after the first teardown/setup cycle, freezing the per-port MIB counters?
Would cancel_delayed_work_sync() in teardown (or an explicit enable_delayed_work() in setup) make the pairing symmetric without depending on the re-init side effect?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com
PATCH v8 5/6 net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
In reply to Kyle SwitchAdd support for Motorcomm YT922x tags with 8bytes. which includes ethertype field (default to 0x9988).
--- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 net/dsa/tag_yt922x.c
include/net/dsa.h +2 -0
@@ -61,6 +61,7 @@ struct tc_action;#define DSA_TAG_PROTO_NETC_VALUE 33#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35 +#define DSA_TAG_PROTO_YT922X_VALUE 36enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -99,6 +100,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE ,DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -227,4 +227,10 @@ config NET_DSA_TAG_YT921X Say Y or M if you want to enable support for tagging frames for Motorcomm YT921x switches. +config NET_DSA_TAG_YT922X + tristate "Tag driver for Motorcomm YT922x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT922x switches. + endif
net/dsa/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o +obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o # for tracing framework to find trace.h CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Claim that the new tagger has no in-tree user (dead code, wasted DSA_TAG_PROTO value).
- [Low] yt922x_tag_rcv() (net/dsa/tag_yt922x.c:58-96) never calls dsa_default_offload_fwd_mark(), unlike the sibling tagger…
- [Low] net/dsa/tag_yt922x.c declares an ingress-priority field YT922X_TAG_RX_PRIO_M GENMASK(15, 13) (line 27) that no code…
--
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
Adds a new DSA tagger for Motorcomm YT922x switches using an 8 byte EtherType-based tag, allocating DSA_TAG_PROTO_YT922X_VALUE 36, plus the Kconfig and Makefile entries. A few questions below, none of them serious.
Quoted 5 lines
net/dsa/Kconfig +0
-0
net/dsa/Kconfig config NET_DSA_TAG_YT921X · line 236
Quoted 10 lines
net/dsa/Kconfig +6
-0@@ -227,4 +227,10 @@ config NET_DSA_TAG_YT921X Say Y or M if you want to enable support for tagging frames for Motorcomm YT921x switches. +config NET_DSA_TAG_YT922X + tristate "Tag driver for Motorcomm YT922x switches" + help + Say Y or M if you want to enable support for tagging frames for + Motorcomm YT922x switches. + endif
[Severity: Low]
This isn't a bug, just a note for anyone reading the patch on its own:
as of this commit nothing in the tree selects NET_DSA_TAG_YT922X and nothing returns DSA_TAG_PROTO_YT922X.
The next patch in the series ("net: dsa: motorcomm: Add support for Motorcomm YT922x") adds yt922x_dsa_get_tag_protocol() returning DSA_TAG_PROTO_YT922X and adds select NET_DSA_TAG_YT922X to drivers/net/dsa/motorcomm/Kconfig, so the tagger does get a user by the end of the series.
[ ... ]
Quoted 6 lines
net/dsa/tag_yt922x.c new file +0
-0@@ -0,0 +1,111 @@
[ ... ]
Quoted 5 lines
net/dsa/tag_yt922x.c new file +5
-0+#define YT922X_TAG_LEN 8 + +/* +* To define the from cpu tag format 8 bytes: +*/
net/dsa/tag_yt922x.c line 27
Quoted 10 lines
net/dsa/tag_yt922x.c new file +10
-0+#define YT922X_TAG_NAME "yt922x" +#define YT922X_TAG_PORTMASK_0 BIT(15) +#define YT922X_TAG_PORTMASK_M GENMASK(8, 0) +#define YT922X_TAG_PORTS (x) FIELD_PREP(YT922X_TAG_PORTMASK_M, (x)) +#define YT922X_TAG_FORCE_DST BIT(9) +#define YT922X_TAG_PRIO_M GENMASK(12, 10) +#define YT922X_TAG_PRIO_EN BIT(13) +#define YT922X_TAG_PRIO (x) (FIELD_PREP(YT922X_TAG_PRIO_M, (x)) | YT922X_TAG_PRIO_EN) +#define YT922X_TAG_RX_PORT_M GENMASK(5, 2) +#define YT922X_TAG_RX_PRIO_M GENMASK(15, 13)
[Severity: Low]
Is YT922X_TAG_RX_PRIO_M meant to be used somewhere? It is defined here and never referenced anywhere else in the file, so the hardware ingress traffic class is dropped.
yt922x_tag_rcv() reads the word that contains it but only extracts the source port:
rx = ntohs(tag[2]); port = FIELD_GET(YT922X_TAG_RX_PORT_M, rx);
The sibling tagger does propagate it in yt921x_tag_rcv():
skb->priority = FIELD_GET(YT921X_TAG_PRIO_M, rx);
Should yt922x_tag_rcv() set skb->priority the same way, or should the unused macro be dropped?
Related to that, the only comment describing the layout says "To define the from cpu tag format 8 bytes", but the block mixes from-CPU and to-CPU fields. In particular tag[2] bit 15 is the port 0 destination bit on transmit (YT922X_TAG_PORTMASK_0, used in yt922x_tag_xmit()) while YT922X_TAG_RX_PRIO_M declares bits 15:13 of the same word as receive priority. Could the comment be extended to spell out the from-CPU and to-CPU words separately, so it is clear which fields belong to which direction?
[ ... ]
net/dsa/tag_yt922x.c line 96
Quoted 6 lines
net/dsa/tag_yt922x.c new file +6
-0+/* Remove tag and update checksum */ +skb_pull_rcsum (skb,YT922X_TAG_LEN ); +dsa_strip_etype_header (skb,YT922X_TAG_LEN ); + +return skb; +}
[Severity: Low]yt922x_tag_rcv() returns without calling dsa_default_offload_fwd_mark(), unlike yt921x_tag_rcv() which does:
/* Already forwarded by hardware */ dsa_default_offload_fwd_mark(skb);
This has no effect today, since dsa_default_offload_fwd_mark() computes:
skb->offload_fwd_mark = !!(dp->bridge);
and yt922x_dsa_switch_ops in the following patch provides only get_tag_protocol, phylink_get_caps, port_setup and setup, so dsa_switch_bridge_join() returns -EOPNOTSUPP, dp->bridge stays NULL and DSA falls back to software bridging.
The observation is more about the RX tag decode: it does not extract any forward/trap ("code") field, so there is currently no way to tell a hardware-forwarded frame from a CPU-only trap. Is that field absent from the YT922x to-CPU tag, or is the decode intentionally left minimal until bridge offload ops are added?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com
PATCH v8 6/6 net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchAdd support for Motorcomm YT922X, which is series of ethernet switches developed by Motorcomm Electronic Technology, includes YT9224 and YT9228.
This patch only adds support for the YT9224 variant. YT9228 is not supported yet.
This patch adds basic support for a working DSA switch, includes .port_setup, .setup, .phylink_get_caps, .get_tag_protocol.
--- drivers/net/dsa/motorcomm/Kconfig | 3 +- drivers/net/dsa/motorcomm/chip.c | 686 +++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 93 ++++ 3 files changed, 777 insertions(+), 5 deletions(-)
drivers/net/dsa/motorcomm/Kconfig +2 -1
@@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" + tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support" select NET_DSA_TAG_YT921X + select NET_DSA_TAG_YT922X select NET_IEEE8021Q_HELPERS if DCB help This enables support for the Motorcomm YT9215 ethernet switch
drivers/net/dsa/motorcomm/chip.c +682 -4
758 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +93 -0
117 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v8 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 2 · 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).
- [High] yt922x_pcs_config() violates the documented phylink PCS
contract: it ignores neg_mode, advertising and permit_pause_to_mac and…
- [High] net: devm_ leak and sysfs crash in DSA .setup callback
- [Medium] The driver advertises a new device-tree compatible "motorcomm,yt9224" in yt921x_of_match[], but no DT binding documents…
- [Low] drivers/net/dsa/motorcomm/Kconfig: the NET_DSA_YT921X prompt is updated to "Motorcomm YT9215 and YT9224 ethernet switch chip support"…
- [Low] net/dsa/tag_yt922x.c defines YT922X_TAG_RX_PRIO_M (bits 15:13 of the received control word) but yt922x_tag_rcv() reads that same word…
--
net: dsa: motorcomm: Add support for Motorcomm YT922x
This adds YT922x (YT9224 only for now) support to the existing Motorcomm YT921x DSA driver: a new chip info entry, a new yt92xx series entry with its own dsa_switch_ops and phylink_mac_ops, a PCS implementation for the internal SerDes ports, and a new "motorcomm,yt9224" OF compatible.
A few questions below.
Quoted 5 lines
drivers/net/dsa/motorcomm/Kconfig +0
-0
drivers/net/dsa/motorcomm/Kconfig line 8
Quoted 9 lines
drivers/net/dsa/motorcomm/Kconfig +2
-1@@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only config NET_DSA_YT921X - tristate "Motorcomm YT9215 ethernet switch chip support" + tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support" select NET_DSA_TAG_YT921X + select NET_DSA_TAG_YT922X select NET_IEEE8021Q_HELPERS if DCB help This enables support for the Motorcomm YT9215 ethernet switch
[Severity: Low]
This isn't a bug, but the prompt now mentions YT9224 while the help text right below it still says:
This enables support for the Motorcomm YT9215 ethernet switch chip.
Should the help text mention YT9224 too?
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/dsa/motorcomm/chip.c +0
-0@@ -4694,6 +4725,637 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5
-0+static void +yt922x_phylink_mac_config (struct phylink_config *config,unsigned int mode, +const struct phylink_link_state *state) +{ +}
[ ... ]
Quoted 45 lines
drivers/net/dsa/motorcomm/chip.c +45
-0+static int yt922x_pcs_config (struct phylink_pcs *pcs,unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac) +{ +struct yt921x_port *pp =pcs_to_yt921x_port (pcs); +struct yt921x_priv *priv =yt921x_port_to_priv (pp); +int res, port; +u16 data; +u16 ctrl; +int addr; + + port = pp->index; +if (!yt922x_port_is_internal_sds (port)) +return -EINVAL ; + +mutex_lock (&priv->reg_lock); + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT ); +if (addr <0 ) { + res = addr; + goto err; + } +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) + goto err; +switch (interface) { +case PHY_INTERFACE_MODE_SGMII : + ctrl =YT922X_SERDES_MODE_SGMII ; +break ; +case PHY_INTERFACE_MODE_1000BASEX : + ctrl =YT922X_SERDES_MODE_1000BASEX ; +break ; +case PHY_INTERFACE_MODE_2500BASEX : + ctrl =YT922X_SERDES_MODE_2500BASEX ; +break ; +case PHY_INTERFACE_MODE_USXGMII : + ctrl =YT922X_SERDES_MODE_USXGMII ; +break ; +default : + res = -EINVAL ; + goto err; + } + res =yt921x_intif_ext_read (priv, addr, YT922X_PORT_SDSn, &data);
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5083
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+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; +mutex_unlock (&priv->reg_lock); + +return res;
[Severity: High]
Is this safe on a second .setup() call?
DSA .setup() is not a once-per-device callback: the tree is torn down and set up again whenever the conduit goes away and comes back (dsa_tree_teardown() / dsa_tree_setup()), while the mdio_device that owns the devm allocations stays bound the whole time. So the devm resources taken in yt921x_mbus_int_init() (devm_mdiobus_alloc() plus devm_of_mdiobus_register()) are only released when the mdiodev itself unbinds, not when the switch is torn down.
That means on the second yt922x_dsa_setup() the first internal MDIO bus is still registered, priv->mbus_int gets overwritten (leaking the first allocation), and the of_mdiobus_register() for the new bus hits a duplicate sysfs name for the same bus id, which fails the re-setup and leaves the switch half-configured.
Making it worse, yt922x_dsa_switch_ops has no .teardown at all, unlike yt921x_dsa_switch_ops which supplies yt921x_dsa_teardown(), so there is nothing on the yt922x path that can unwind anything allocated or registered from .setup().
How do you want to fix this? Either register the internal bus with the plain mdiobus_alloc()/of_mdiobus_register() and drop it from a new yt922x .teardown callback, or move the bus registration out of .setup() into yt921x_mdio_probe(), where the devm lifetime actually matches the device. If the yt921x path has the same issue today, please say so and fix both consistently rather than copying the pattern into the new ops.
[Severity: High]
Can the SerDes ports negotiate a link with this pcs_config()?
The callback only rewrites the 3-bit SERDES_MODE field of the ext register YT922X_PORT_SDSn. neg_mode, advertising and permit_pause_to_mac are unused, so MII_BMCR.BMCR_ANENABLE is never set or cleared and MII_ADVERTISE is never programmed.
The kerneldoc for pcs_config in include/linux/phylink.h states:
* When operating in %MLO_AN_INBAND, inband should always be enabled,
* otherwise inband should be disabled.
...
* For 1000BASE-X, the advertisement should be programmed into the PCS.
...
* When an autonegotiation restart is required for 802.3z modes, .pcs_config()
* should return a positive non-zero integer (e.g. 1)
Here res is 0 on the success path, so phylink never triggers the restart:
drivers/net/phy/phylink.c:phylink_change_inband_advert() {
ret = phylink_pcs_config(pl->pcs, pl->pcs_neg_mode, &pl->link_config,
!!(pl->link_config.pause & MLO_PAUSE_AN));
if (ret < 0)
return ret;
if (ret > 0)
phylink_pcs_an_restart(pl);
}which means an ethtool advertisement change never reaches yt922x_pcs_an_restart(), and yt922x_pcs_an_restart() itself only sets BMCR_ANRESTART, so it cannot enable in-band AN either.
Meanwhile yt922x_pcs_get_state() hands MII_LPA to phylink_mii_c22_pcs_decode_state() (and phylink_decode_usxgmii_word() for USXGMII) as if it were a completed negotiation word, and yt922x_phylink_mac_link_up() -> yt922x_port_up() then force-writes that speed/duplex/pause into YT922X_PORTn_CTRL. Since yt922x_phylink_mac_config() is empty, nothing else applies the interface change either.
Is there also anything that resets or re-times the SerDes when the mode changes between rates (SGMII 1.25G, 2500BASEX 3.125G, USXGMII 10.3125G)?
For YT9224 external_mask is BIT(0) | BIT(8), so this affects the ports that normally carry the CPU link.
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5102
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +6
-0+static enum dsa_tag_protocol +yt922x_dsa_get_tag_protocol (struct dsa_switch *ds,int port, +enum dsa_tag_protocol m) +{ +return DSA_TAG_PROTO_YT922X ; +}
[Severity: Low]
On the tagger added earlier in this series (net/dsa/tag_yt922x.c), is YT922X_TAG_RX_PRIO_M used anywhere? yt922x_tag_rcv() reads the same control word only for the source port:
rx = ntohs(tag[2]); port = FIELD_GET(YT922X_TAG_RX_PORT_M, rx); skb->dev = dsa_conduit_find_user(netdev, 0, port);
while the sibling yt921x_tag_rcv() does:
skb->priority = FIELD_GET(YT921X_TAG_RX_PRIO_M, rx);
Was the skb->priority assignment meant to be there as well, or should the unused macro be dropped?
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 5508
Quoted 11 lines
drivers/net/dsa/motorcomm/chip.c +3
-2@@ -4825,8 +5501,9 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) }static const struct of_device_id yt921x_of_match[] = { - { .compatible ="motorcomm,yt9215" }, - {} + { .compatible ="motorcomm,yt9215" , }, + { .compatible ="motorcomm,yt9224" , }, + {/* sentinel */ } };MODULE_DEVICE_TABLE (of, yt921x_of_match);
[Severity: Medium]
Should this series also update the binding? The only Motorcomm DSA schema in the tree, Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml, still has:
properties:
compatible:
const: motorcomm,yt9215
so a node with compatible = "motorcomm,yt9224" is matched by the driver but rejected by dt_binding_check/dtbs_check.
The binding prose also disagrees with the topology added here. The schema describes "up to 8 internal GbE PHYs and up to 2 GMACs" with "PHY 0-7 are used for Port 0-7 respectively", while the new chip info entry is:
{
"YT9224", YT9224_MAJOR, 0, 0,
YT922X_PORT_MASK_INTm_n(4, 7),
YT922X_PORT_MASK_EXT0 | YT922X_PORT_MASK_EXT1,
},i.e. internal PHYs on ports 4-7 and SerDes on ports 0 and 8, with YT922X_PORT_NUM = 9 (no port 9). Following the current binding text, would a device tree author end up describing ports the driver cannot drive?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917082236.3427168-1-kyle.switch%40motor-comm.com