net: dsa: motorcomm: add support yt922x driver
v7 cover net: dsa: motorcomm: add support yt922x driver
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 | 1 + drivers/net/dsa/motorcomm/chip.c | 979 +++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 119 ++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 111 ++++ 7 files changed, 1191 insertions(+), 28 deletions(-) create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
PATCH v7 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 | 71 +++++++++++++++++++++++++++----- drivers/net/dsa/motorcomm/chip.h | 20 +++++++++ 2 files changed, 81 insertions(+), 10 deletions(-)
drivers/net/dsa/motorcomm/chip.c +61 -10
@@ -4679,6 +4679,61 @@ 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; + + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +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 +4782,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 +4810,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);
@@ -4770,8 +4821,8 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev) }static const struct of_device_id yt921x_of_match[] = { - { .compatible ="motorcomm,yt9215" }, - {} + { .compatible ="motorcomm,yt9215" , }, + {/* sentinel */ } };MODULE_DEVICE_TABLE (of, yt921x_of_match);
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
David Yang
maintainerRe: [PATCH net-next v7 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4827
Quoted 7 lines · Kyle Switch
static const struct
of_device_idyt921x_of_match[] = {drivers/net/dsa/motorcomm/chip.c +2
-2- { .compatible = "motorcomm,yt9215" }, - {} + { .compatible = "motorcomm,yt9215", }, + {/* sentinel */ } };MODULE_DEVICE_TABLE (of, yt921x_of_match);
Meaningless.
[email protected]
AI reviewRe: [PATCH net-next v7 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid
In reply to Kyle SwitchThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 · Low: 0
- [High] drivers/net/dsa/motorcomm/chip.c: the newly added yt92xx_register_switch() calls yt921x_reg_read(priv, YT921X_CHIP_ID,…
--
net: dsa: motorcomm: initialize dsa_switch based on chipid
This adds a yt92xx_series descriptor table and a new yt92xx_register_switch() helper that reads the chip ID, looks up the matching series and fills in the dsa_switch fields, replacing the hardcoded assignments previously done in yt921x_mdio_probe().
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.c +1
-0@@ -4679,6 +4679,61 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static const struct yt92xx_series yt92xx_series_table[] = {
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4715
Quoted 11 lines
drivers/net/dsa/motorcomm/chip.c +11
-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; + + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +if (res) +return res;
[Severity: High]
Should this read be done with priv->reg_lock held?
yt921x_reg_read() asserts the lock in drivers/net/dsa/motorcomm/smi.c:
int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp)
{
lockdep_assert_held_once(&priv->reg_lock);
return priv->reg_ops->read(priv->reg_ctx, reg, valp);
}yt921x_mdio_probe() only calls mutex_init(&priv->reg_lock) before invoking yt92xx_register_switch(), so the lock is never taken on this path. With CONFIG_PROVE_LOCKING enabled, doesn't that make every probe of this driver emit a WARN_ON_ONCE splat (and panic when booted with panic_on_warn)?
Every other register access in the driver takes the mutex first, for example yt921x_dsa_setup():
mutex_lock(&priv->reg_lock); res = yt921x_chip_reset(priv); mutex_unlock(&priv->reg_lock);
and the comment on the field in chip.h describes it as protecting the register access:
/* protect the access to the switch registers */ struct mutex reg_lock;
Since probe context can sleep, would wrapping the YT921X_CHIP_ID read in mutex_lock()/mutex_unlock(&priv->reg_lock) be the intended fix?
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +6
-0+ + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) +return -ENODEV ; + priv->series = series;
[ ... ]
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +0
-3@@ -4754,15 +4810,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;
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4818
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +3
-5- 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);
[ ... ]
One more note on this: checking the tip of the series (the commit adding support for Motorcomm YT922x), yt92xx_register_switch() still performs the chip ID read without taking priv->reg_lock and is still called from probe, so this does not appear to be addressed by a later patch.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914103009.3007019-1-kyle.switch%40motor-comm.com
PATCH v7 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 v7 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium] yt92xx_register_switch() (drivers/net/dsa/motorcomm/chip.c:4707-4737) calls…
--
net: dsa: motorcomm: use max_ports in series for port bounds checking
This replaces the hardcoded YT921X_PORT_NUM in the internal MDIO bus port checks and in the phy_mask computation with priv->series->max_ports, so the common code no longer carries a family-specific port count.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
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: Medium]
These new users of priv->series depend on the chip-ID read that fills it in, and that read looks like it now runs without priv->reg_lock held.
In yt92xx_register_switch():
res = yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid); if (res) return res; major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid); series = yt92xx_series_lookup(major);
and in drivers/net/dsa/motorcomm/smi.c:
int yt921x_reg_read(struct yt921x_priv *priv, u32 reg, u32 *valp)
{
lockdep_assert_held_once(&priv->reg_lock);
return priv->reg_ops->read(priv->reg_ctx, reg, valp);
}Does this trip the lockdep assertion on every probe with CONFIG_PROVE_LOCKING enabled? The only caller is yt921x_mdio_probe(), which does mutex_init(&priv->reg_lock) before yt92xx_register_switch(ds) but never takes it, so the multi-transaction SMI access also runs outside the mutex that chip.h describes as "protect the access to the switch registers".
Before this series the chip-ID read happened under the lock, via yt921x_dsa_setup():
mutex_lock(&priv->reg_lock); res = yt921x_chip_reset(priv); mutex_unlock(&priv->reg_lock);
which reached yt921x_chip_detect(). The move into the unlocked probe path came with "net: dsa: motorcomm: initialize dsa_switch based on chipid", and the end of the series still has no mutex_lock() in yt92xx_register_switch().
Would wrapping the yt921x_reg_read() in yt92xx_register_switch() with mutex_lock(&priv->reg_lock)/mutex_unlock(&priv->reg_lock) be the intended fix here?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914103009.3007019-1-kyle.switch%40motor-comm.com
PATCH v7 3/6 net: dsa: motorcomm: move mib start from probe() to dsa_setup()
In reply to Kyle SwitchMove MIB polling start from probe() to dsa_setup().so that it can be enabled based on the actual switch family support.
--- 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);
@@ -4803,13 +4811,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 v7 3/6] net: dsa: motorcomm: move mib start from probe() to dsa_setup()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 3 · Low: 0
- [Medium] Commit message does not describe the change: "Move MIB polling start from probe() to dsa_setup().so that it can be enabled based on…
- [Medium] Init/teardown asymmetry introduced by this patch: the only INIT_DELAYED_WORK(&pp->mib_read, ...) now runs in the DSA .setup…
- [Medium] Moving INIT_DELAYED_WORK(&pp->mib_read, ...) into yt921x_dsa_setup() places it on a path DSA can execute more than once…
--
net: dsa: motorcomm: move mib start from probe() to dsa_setup()
This moves the per-port loop that sets pp->index and calls INIT_DELAYED_WORK() for the MIB polling work out of yt921x_mdio_probe() and into the DSA .setup callback yt921x_dsa_setup().
Quoted 2 lines
Move MIB polling start from
probe()to dsa_setup().so that it can be enabled based on the actual switch family support.
[Severity: Medium]
Does the changelog match what the patch does?
The hunk only relocates the delayed work initialization, and the new comment even says so:
/* mib polling init */
for (size_t i = 0; i < ARRAY_SIZE(priv->ports); i++) {
...
INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
}The place where polling actually starts is untouched in yt921x_phylink_mac_link_up():
schedule_delayed_work(&priv->ports[port].mib_read, 0);
and the self re-arm in yt921x_poll_mib() is untouched as well:
schedule_delayed_work(&pp->mib_read, delay);
There is also no new priv->series or priv->info test added anywhere by this patch, so nothing is "enabled based on the actual switch family support" yet.
Could the changelog instead describe the actual delta, namely that the lifetime of the delayed work initialization changes from once per probe() to once per DSA .setup()?
Also, "dsa_setup().so that" is missing a space after the period.
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: Medium]
Can INIT_DELAYED_WORK() run here on a work item that is still armed?
DSA can call ds->ops->setup() more than once for the same priv. dsa_switch_setup() returns early on ds->setup, but dsa_switch_teardown() clears it:
net/dsa/dsa.c:dsa_switch_teardown() {
...
ds->setup = false;
}So on a multi-switch tree, unbinding and re-binding a peer member tears down and re-sets up the surviving switch.
In this patch yt921x_dsa_teardown() has no counterpart cancel:
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
}
and the only per-port stop is non-synchronous inyt921x_phylink_mac_link_down():
/* No need to sync; port control block is hold until device remove */ cancel_delayed_work(&priv->ports[port].mib_read);
while yt921x_poll_mib() unconditionally re-arms itself. Re-running INIT_DELAYED_WORK() (and thus timer_setup()) on a timer still linked in a timer base, and resetting work->data/work->entry, would give a debugobjects "init active timer" report, a lost cancellation, and a polling chain touching registers of a switch that yt921x_chip_reset() just reset a few lines below.
The following patch in the series, "net: dsa: motorcomm: move mib stop from remove() to teardown()", adds the disable_delayed_work_sync() loop to yt921x_dsa_teardown(), which closes this window at the end of the series. Would swapping the order of the two patches avoid the intermediate state?
Also, does the comment in yt921x_phylink_mac_link_down() saying the port control block is "hold until device remove" still hold once the work is initialized per .setup() rather than per probe()?
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 4812
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +0
-7@@ -4803,13 +4811,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 initialization gone from probe(), can yt921x_mdio_remove() call disable_delayed_work_sync() on a work item that was never initialized?
yt921x_mdio_remove() still does this 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);
}priv comes from devm_kzalloc(), so if ds->ops->setup() never ran, mib_read is all zeroes, including work->func and the timer.
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 is the multi-switch dsa,member case where the peer has not probed yet. Unbinding that switch then reaches:
disable_delayed_work_sync() -> __cancel_work_sync() -> __flush_work()
kernel/workqueue.c:__flush_work() {
if (WARN_ON(!work->func))
return false;
...
}so a WARN splat on unbind, fatal under panic_on_warn, preceded by __cancel_work()/work_grab_pending() operating on a timer that was never passed to timer_setup().
The next patch in the series moves this loop into yt921x_dsa_teardown(), where dsa_switch_teardown() returns early on !ds->setup, so the final state of the series is fine. Would reordering the two patches keep each one bisectable?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914103009.3007019-1-kyle.switch%40motor-comm.com
PATCH v7 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)
@@ -4761,12 +4766,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
PATCH v7 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 v7 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 0 · Low: 4
- [Low] Claim: the new DSA tag protocol DSA_TAG_PROTO_YT922X / CONFIG_NET_DSA_TAG_YT922X has no consumer in the tree (dead code).
- [Low] The YT922x tag layout is effectively undocumented:
net/dsa/tag_yt922x.c:15-17 contains only the placeholder comment "/*…
- [Low] The RX priority field declared by the new tag format is never decoded.
- [Low] The new tagger emits and validates the uAPI constant ETH_P_YT921X for a YT922x tag: net/dsa/tag_yt922x.c:40 (`tag[0] =…
--
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
This adds a new DSA tagging driver for Motorcomm YT922x switches with an 8-byte tag preceded by an EtherType of 0x9988, plus the new DSA_TAG_PROTO_YT922X protocol value, Kconfig symbol and Makefile entry.
A few questions below.
Quoted 6 lines
net/dsa/tag_yt922x.c new file +0
-0@@ -0,0 +1,111 @@
[ ... ]
net/dsa/tag_yt922x.c line 17
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: +*/
[Severity: Low]
This isn't a bug, but could the tag layout be documented here? The comment above currently describes none of the fields, while the sibling tagger for the same vendor, net/dsa/tag_yt921x.c, carries a full frame diagram and a per-bit description of every 16-bit tag word:
net/dsa/tag_yt921x.c:
* +----+----+-------+-----+----+---------
* | DA | SA | TagET | Tag | ET | Payload ...
* +----+----+-------+-----+----+---------
* 6 6 2 6 2 N
...
* 2:
* 15b: Tx Port(s) Valid
* 10b-0b: Tx Port(s) Mask
Without that, the reuse of tag[2] in opposite directions (transmit writes YT922X_TAG_PORTMASK_0 = BIT(15), receive reads YT922X_TAG_RX_PORT_M = GENMASK(5, 2)) and the split of the destination port mask across tag[1] bits 8:0 and tag[2] bit 15 cannot be checked against the hardware by a reviewer.
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? It is defined here but never referenced anywhere in the file, and yt922x_tag_rcv() only extracts the source port from tag[2] and never assigns skb->priority, so the ingress priority reported by the switch is dropped.
The transmit path does encode skb->priority into the tag:
ctrl = YT922X_TAG_PRIO(skb->priority) | YT922X_TAG_FORCE_DST | YT922X_TAG_PORTS(ports >> 1);
and comparable taggers decode it on receive, for example net/dsa/tag_yt921x.c:yt921x_tag_rcv():
skb->priority = FIELD_GET(YT921X_TAG_PRIO_M, rx);
Should yt922x_tag_rcv() do the same with YT922X_TAG_RX_PRIO_M?
Quoted 4 lines
net/dsa/tag_yt922x.c new file +4
-0+ +static struct sk_buff * +yt922x_tag_xmit (struct sk_buff *skb,struct net_device *netdev) +{
[ ... ]
net/dsa/tag_yt922x.c line 40
Quoted 1 line
net/dsa/tag_yt922x.c new file +1
-0+ tag[0 ] =htons (ETH_P_YT921X );
[Severity: Low]
This isn't a bug, but the YT922x tagger emits and validates a uAPI constant named for YT921x, both here and in yt922x_tag_rcv():
if (unlikely(tag[0] != htons(ETH_P_YT921X))) {include/uapi/linux/if_ether.h currently scopes that value to one family:
#define ETH_P_YT921X 0x9988 /* Motorcomm YT921x DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
Should the header comment be broadened (something like "Motorcomm YT92xx DSA") or a YT922x alias added, so the uAPI still describes all in-tree users of 0x9988? It would also help if the commit message stated that the two chip families intentionally share the tag EtherType while using different tag bodies.
Quoted 2 lines
net/dsa/tag_yt922x.c new file +2
-0+ ports =dsa_xmit_port_mask (skb, netdev); +/*To fill in the case where the port index is not 0 */
[ ... ]
net/dsa/tag_yt922x.c line 100
Quoted 3 lines
net/dsa/tag_yt922x.c new file +3
-0+static const struct dsa_device_ops yt922x_netdev_ops = { + .name =YT922X_TAG_NAME , + .proto =DSA_TAG_PROTO_YT922X ,
[Severity: Low]
This isn't a bug, but could the commit message mention the companion patch that consumes this protocol?
At this commit nothing requests DSA_TAG_PROTO_YT922X, and the consumer only appears in the last patch of the series, "net: dsa: motorcomm: Add support for Motorcomm YT922x", which 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 there is no dead code in the merged series, and the ordering is the usual DSA practice; a note in the commit message pointing at the driver patch would make that clear on its own.
net/dsa/tag_yt922x.c line 104
Quoted 4 lines
net/dsa/tag_yt922x.c new file +4
-0+ .xmit = yt922x_tag_xmit, + .rcv = yt922x_tag_rcv, + .needed_headroom = YT922X_TAG_LEN, +};
Also, in the commit message, "Add support for Motorcomm YT922x tags with 8bytes. which includes ethertype field (default to 0x9988)." reads a bit
oddly: "8bytes" is missing a space, and the sentence break before "which" should probably be a comma.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914103009.3007019-1-kyle.switch%40motor-comm.com
PATCH v7 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 adds basic support for a working DSA switch.
--- drivers/net/dsa/motorcomm/Kconfig | 1 + drivers/net/dsa/motorcomm/chip.c | 874 +++++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 99 ++++ 3 files changed, 972 insertions(+), 2 deletions(-)
drivers/net/dsa/motorcomm/Kconfig +1 -0
@@ -2,6 +2,7 @@ config NET_DSA_YT921X tristate "Motorcomm YT9215 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 +872 -2
946 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +99 -0
123 lines not on this page · raw message
Signature · 1 line
2.25.1
David Yang
maintainerRe: [PATCH net-next v7 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 157 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +157
-0+/* +* Initialize serdes configuration based on interface mode. +*/ +static int yt922x_sds_init (struct yt921x_priv *priv,int port, +phy_interface_t interface) +{ +int addr; +u16 data; +int res; + + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return -EINVAL ; +/* write protect */ + res =yt921x_intif_ext_write (priv, addr,0x4be ,0xd ); +if (res) +return res; +/* CDR */ +if (interface ==PHY_INTERFACE_MODE_100BASEX ) { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x0 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x3458 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x406 ,0x800 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x416 ,0x4558 ); +if (res) +return res; + } +/* PLL */ +if (interface ==PHY_INTERFACE_MODE_USXGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x1006 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3029 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + }else { + res =yt921x_intif_ext_write (priv, addr,0x43d ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43c ,0x207d ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43f ,0x3032 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x43a ,0x6 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x42a ,0xf070 ); +if (res) +return res; + } +/* VCO */ + res =yt921x_intif_ext_write (priv, addr,0x439 ,0xC0 ); +if (res) +return res; +/* Vdac */ + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x491 ,0x7f ); +if (res) +return res; +/* Eye */ + res =yt921x_intif_ext_write (priv, addr,0x454 ,0xf14 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x497 ,0xa44 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4cd ,0x0 ); +if (res) +return res; + + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e3 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x48a ,0xfff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x408 ,0x7c00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4d6 ,0x7f ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x44f ,0xff08 ); +if (res) +return res; +/* FFE */ + res =yt921x_intif_ext_write (priv, addr,0x48e ,0x7d00 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0xd ,0x60f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x4b0 ,0x804 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4b1 ,0x7774 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x4af ,0x45e7 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x3 ,0x5603 ); +if (res) +return res; + +msleep (20 ); + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7fff ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x492 ,0x7f7f ); +if (res) +return res; +/* CTLE */ + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x40 ); +if (res) +return res; + res =yt921x_intif_ext_write (priv, addr,0x2000 ,0x0 ); +if (res) +return res; + +if (interface ==PHY_INTERFACE_MODE_SGMII ) { + res =yt921x_intif_ext_write (priv, addr,0x1042 ,0x48c ); +if (res) +return res; + } +/* soft reset */ + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) +return res; + res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data &= ~(1 <<15 ); + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII , +YT922X_PHY_REG_SPACE_USXGMII ); +if (addr <0 ) +return res;
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5086
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ res =yt921x_intif_read (priv, addr,0x0 , &data); +if (res) +return res; + data |=1 <<15 ; + res =yt921x_intif_write (priv, addr,0x0 , data); +if (res) +return res; + +return 0 ; +}
You didn't read my previous review. Remove this from this series.
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +7
-0+static void +yt922x_dsa_phylink_get_caps (struct dsa_switch *ds,int port, +struct phylink_config *config) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +const struct yt921x_info *info = priv->info; +
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5313
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ config->mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ; + +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 ; + } +if (info->external_mask &BIT (port)) {
Worth an early return or else if here, but still OK.
[email protected]
AI reviewRe: [PATCH net-next v7 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchThank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
Critical: 1 · High: 3 · Medium: 3 · Low: 4
- [Critical] YT922x PCS callbacks recover their private structure from an uninitialized pp->index.
- [High] Four of the six YT922x serdes-mode constants are encoded into the wrong register field.
- [High] yt922x_sds_phyaddr_get() (chip.c:4901-4918) accepts an enum yt922x_phy_reg_space argument and its own comment says "sds phyaddr…
- [High] yt922x_dsa_setup() (chip.c:5507) takes priv->reg_lock at chip.c:5530 and calls yt922x_chip_setup() (chip.c:5463) with the…
- [Medium] The driver advertises PHY_INTERFACE_MODE_100BASEX for YT922x external ports (in yt922x_dsa_phylink_get_caps() at chip.c:5317 and…
- [Medium] yt922x_pcs_config() (chip.c:5217) ignores neg_mode, advertising and permit_pause_to_mac.
- [Medium] The driver adds the OF compatible "motorcomm,yt9224" to yt921x_of_match[] (chip.c:5695) but no device-tree binding documents…
- [Low] The commit message states the YT922X series "includes YT9224 and YT9228", but only YT9224 is implemented: a single yt921x_infos entry…
- [Low] NET_DSA_YT921X keeps the prompt "Motorcomm YT9215 ethernet switch chip support" and YT9215-only help text while the same patch…
- [Low] yt922x_chip_setup_dsa() writes a hardcoded GENMASK(9, 0) (10 port bits) to YT922X_FILTER_UNK_UCAST at chip.c:5440, while the two…
- [Low] yt922x_pcs_config() commits the new serdes mode to YT922X_PORT_SDSn (chip.c:~5262) and then runs the ~40-write…
--
net: dsa: motorcomm: Add support for Motorcomm YT922x
This adds a YT922x variant to the Motorcomm DSA driver: a new yt92xx_series entry with its own dsa_switch_ops and phylink_mac_ops, a YT9224 chip info entry, a large block of YT922x register definitions, and a per-port embedded phylink PCS for the serdes ports. It also registers the motorcomm,yt9224 OF compatible and selects the YT922x tagger.
A few questions on the commit message and the new code below.
Quoted 5 lines
Add support for Motorcomm YT922X, which is series of ethernet switches developed by Motorcomm Electronic Technology, includes YT9224 and YT9228.
This patch adds basic support for a working DSA switch.
[Severity: Low]
Is YT9228 actually supported here? Only YT9224 appears in the code: one yt921x_infos entry for YT9224_MAJOR (0x9004), one motorcomm,yt9224 compatible, and yt92xx_series_lookup() matching only YT9224_MAJOR. A grep of the tree finds no YT9228 identifier, so a YT9228 would be rejected in yt921x_chip_detect() with "Unexpected chipid" or by yt92xx_series_lookup() returning NULL.
Could the second sentence also state what "basic" covers? yt922x_dsa_switch_ops provides only get_tag_protocol, phylink_get_caps, port_setup and setup, and yt922x_port_setup() sets YT922X_PORT_LEARN_DIS on every port, so bridging, VLAN, FDB and statistics are not available.
drivers/net/dsa/motorcomm/Kconfig line 8
Quoted 12 lines
drivers/net/dsa/motorcomm/Kconfig +1
-0@@ -2,6 +2,7 @@ config NET_DSA_YT921X tristate "Motorcomm YT9215 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]
Should the prompt and help text mention YT922x too? The same patch makes this symbol bind motorcomm,yt9224, select NET_DSA_TAG_YT922X and set MODULE_DESCRIPTION("Driver for Motorcomm YT921x and YT922x Switch"), but the only user-visible description still says YT9215 only.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
drivers/net/dsa/motorcomm/chip.c struct yt921x_mib_desc { · line 44
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +3
-0@@ -38,6 +38,9 @@ struct yt921x_mib_desc {#define MIB_DESC (_size, _offset, _name) \ {_size, _offset, _name} +#define pcs_to_yt921x_port (_pcs) container_of((_pcs), struct yt921x_port, pcs) +#define yt921x_port_to_priv (pp) \ + container_of_const((pp), struct yt921x_priv, ports[(pp)->index])/* Must agree with yt921x_mib
[Severity: Critical]yt921x_port_to_priv() recovers priv by subtracting offsetof(struct yt921x_priv, ports[pp->index]), so it is only correct when pp->index equals the slot the yt921x_port actually occupies.
Where is pp->index assigned on the YT922x path? The only assignment in the driver is in yt921x_dsa_setup():
pp->index = i; INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
yt922x_dsa_setup() has no equivalent loop, and priv is zero-allocated, so every priv->ports[i].index stays 0 on YT922x.
yt922x_pcs_setup() then installs pp->pcs.ops for each bit of info->external_mask, which for YT9224 is BIT(0) | BIT(8), and yt922x_phylink_mac_select_pcs() returns &priv->ports[dp->index].pcs. So phylink calls the PCS ops with pp == &priv->ports[8] while pp->index == 0, and yt921x_port_to_priv() yields (char *)priv + 8 * sizeof(struct yt921x_port) instead of priv.
Does that mean yt922x_pcs_get_state() runs mutex_lock(&priv->reg_lock) on bytes that are really part of priv->ports[] (MIB counters and a delayed_work), and then calls priv->reg_ops->read() through a function pointer loaded from that same memory?
A second effect of the uninitialised index: int port = pp->index is 0 for port 8 in all three PCS callbacks, so the
if (port != 0 && port != 8) return -EINVAL;
check in yt922x_pcs_config() passes with the wrong port and port 0's serdes registers are programmed.
Quoted 21 lines
drivers/net/dsa/motorcomm/chip.c +8
-0@@ -112,6 +115,9 @@ struct yt921x_info {#define YT921X_PORT_MASK_INT0_n (n) GENMASK((n) - 1, 0)#define YT921X_PORT_MASK_EXT0 BIT(8)#define YT921X_PORT_MASK_EXT1 BIT(9) +#define YT922X_PORT_MASK_INTm_n (m, n) GENMASK((n), (m)) +#define YT922X_PORT_MASK_EXT0 BIT(0) +#define YT922X_PORT_MASK_EXT1 BIT(8)static const struct yt921x_info yt921x_infos[] = { {@@ -149,9 +155,17 @@ static const struct yt921x_info yt921x_infos[] = { YT921X_PORT_MASK_INT0_n(8), YT921X_PORT_MASK_EXT0 | YT921X_PORT_MASK_EXT1, }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +YT922X_PORT_MASK_INTm_n (4 ,7 ), + YT922X_PORT_MASK_EXT0 | YT922X_PORT_MASK_EXT1, + }, {} };
[ ... ]
Quoted 1 line
drivers/net/dsa/motorcomm/chip.c +0
-0@@ -4694,18 +4731,847 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
[ ... ]
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8
-0+static int yt922x_sds_phyaddr_get (int port, +enum yt922x_phy_reg_type reg_type, +enum yt922x_phy_reg_space reg_space) +{ +int res = port; + +/* +* sds phyaddr mapping depend on reg_type and reg_space
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4918
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+*/ +if (!yt922x_port_is_internal_sds (port)) +return -EOPNOTSUPP ; +if (reg_type ==YT922X_PHY_REG_TYPE_COMMON_EXT ) { + res =YT922X_COMMON_EXT_PHYADDR ; +return res; + } + +return res; +}
[Severity: High]
The comment says the mapping depends on reg_type and reg_space, but reg_space is never read: for every reg_type other than YT922X_PHY_REG_TYPE_COMMON_EXT the function returns port. Do the SGMII and USXGMII register spaces then alias to the same internal MDIO address?
The closing soft reset in yt922x_sds_init() looks like it becomes self-cancelling:
addr = yt922x_sds_phyaddr_get(port, YT922X_PHY_REG_TYPE_MII, YT922X_PHY_REG_SPACE_SGMII); ... data &= ~(1 << 15); res = yt921x_intif_write(priv, addr, 0x0, data); ... addr = yt922x_sds_phyaddr_get(port, YT922X_PHY_REG_TYPE_MII, YT922X_PHY_REG_SPACE_USXGMII); ... data |= 1 << 15; res = yt921x_intif_write(priv, addr, 0x0, data);
Both lookups return the same addr, so bit 15 is cleared and then set on one register and the USXGMII PCS is never touched. The same aliasing makes yt922x_pcs_get_state() read YT922X_PCS_LINK_CTRL/MII_LPA from the SGMII address in the USXGMII case, and makes yt922x_pcs_an_restart() perform the identical BMCR read-modify-write twice.
Two smaller points in the same area:
if (addr < 0) return res;
res is 0 at both of these sites in yt922x_sds_init(), so a failed address lookup reports success while silently skipping the soft reset. Should these return addr?
And yt922x_pcs_get_state() and yt922x_pcs_an_restart() pass addr straight to yt921x_intif_read() without checking for the -EOPNOTSUPP that yt922x_sds_phyaddr_get() returns for non-serdes ports.
[ ... ]
Quoted 18 lines
drivers/net/dsa/motorcomm/chip.c +18
-0+static void yt922x_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode, +struct phylink_link_state *state) +{ +struct yt921x_port *pp =pcs_to_yt921x_port (pcs); +struct yt921x_priv *priv =yt921x_port_to_priv (pp); +int port = pp->index; +int res =0 ; +u16 data; +int addr; +u16 lp; + +mutex_lock (&priv->reg_lock); +switch (state->interface) { +case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_100BASEX : +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : + addr = yt922x_sds_phyaddr_get
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5148
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); + res =yt921x_intif_read (priv, addr,MII_BMSR , &data); +if (res) + goto err; + res =yt921x_intif_read (priv, addr,MII_LPA , &lp); +if (res) + goto err; +phylink_mii_c22_pcs_decode_state (state, neg_mode, data, lp); +break ;
[Severity: Medium]
Can a 100BASE-X link ever be reported up through this path? phylink_mii_c22_pcs_decode_state() in drivers/net/phy/phylink.c has cases only for 1000BASE-X, 2500BASE-X, SGMII/PSGMII/QSGMII and QUSGMII:
default: state->link = false; break;
100BASE-X is advertised as supported by yt922x_dsa_phylink_get_caps() and yt922x_pcs_setup(), and yt922x_phylink_mac_select_pcs() returns this PCS for it, so the mode looks reachable but always decodes as link down.
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5227
Quoted 11 lines
drivers/net/dsa/motorcomm/chip.c +11
-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;
[Severity: Medium]neg_mode, advertising and permit_pause_to_mac appear only in the parameter list; the body only rewrites the serdes mode field and runs yt922x_sds_init(). Should this callback enable or disable in-band negotiation according to neg_mode and program the local advertisement for the Base-X modes?
As written, yt922x_pcs_get_state() hands neg_mode to phylink_mii_c22_pcs_decode_state(), so the read path assumes a negotiation setup that the write path never applied.
Quoted 36 lines
drivers/net/dsa/motorcomm/chip.c +36
-0+ port = pp->index; +if (port !=0 && port !=8 ) +return -EINVAL ; + +mutex_lock (&priv->reg_lock); +switch (interface) { +case PHY_INTERFACE_MODE_SGMII : + ctrl =YT92XX_SERDES_MODE_SGMII ; +break ; +case PHY_INTERFACE_MODE_100BASEX : + ctrl =YT92XX_SERDES_MODE_100BASEX ; +break ; +case PHY_INTERFACE_MODE_1000BASEX : + ctrl =YT92XX_SERDES_MODE_1000BASEX ; +break ; +case PHY_INTERFACE_MODE_2500BASEX : + ctrl =YT92XX_SERDES_MODE_2500BASEX ; +break ; +case PHY_INTERFACE_MODE_USXGMII : + ctrl =YT92XX_SERDES_MODE_USXGMII ; +break ; +default : + res = -EINVAL ; + goto err; + } + addr =yt922x_sds_phyaddr_get + (port,YT922X_PHY_REG_TYPE_SDS_COMMON_EXT , +YT922X_PHY_REG_SPACE_SGMII ); +if (addr <0 ) { + res = addr; + goto err; + } + + res =yt921x_intif_ext_read (priv, addr, YT922X_PORT_SDSn, &data); +if (res) + goto err;
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5274
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ data &= ~YT922X_SERDES_MODE_M ; + data |= ctrl; + res =yt921x_intif_ext_write (priv, addr, YT922X_PORT_SDSn, data); +if (res) + goto err; +/* SERDES init and interface configuration */ + res =yt922x_sds_init (priv, port, interface); +if (res) + goto err; +mutex_unlock (&priv->reg_lock);
[Severity: Low]
The new mode is committed to YT922X_PORT_SDSn before the roughly forty writes of yt922x_sds_init() run. If one of those indirect MDIO transactions fails, the error path only unlocks and returns, leaving the new mode selected with a mix of old and new CDR/PLL/VCO/eye/CTLE settings and no closing PCS reset. Is a rollback wanted here, or is the intent to rely on the next successful pcs_config? The YT921x paths such as yt921x_port_up() have the same shape today.
[ ... ]
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5438
Quoted 13 lines
drivers/net/dsa/motorcomm/chip.c +13
-0+static int yt922x_chip_setup_dsa (struct yt921x_priv *priv) +{ +unsigned long cpu_ports_mask; +u32 ctrl; +int port; +int res; + +/* cpu port set */ +mutex_lock (&priv->reg_lock); + res =yt922x_cpu_port_set (priv); +mutex_unlock (&priv->reg_lock); +if (res) +return res;
[Severity: High]
Can this deadlock the probing thread? yt922x_dsa_setup() already holds priv->reg_lock across the call:
mutex_lock(&priv->reg_lock); res = yt922x_chip_setup(priv); mutex_unlock(&priv->reg_lock);
and yt922x_chip_setup() calls yt922x_chip_setup_dsa() directly, so this mutex_lock() re-acquires a mutex the same task already owns. struct mutex is not recursive, so this looks like it hangs on the first YT9224 probe inside dsa_register_switch(), with lockdep reporting possible recursive locking.
The register accesses further down in this function need the outer lock anyway (yt921x_reg_read()/yt921x_reg_write() contain lockdep_assert_held_once(&priv->reg_lock)), so removing this inner lock/unlock pair rather than moving the outer one seems to be what is wanted.
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 5447
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.c +9
-0+ + ctrl =GENMASK (9 ,0 ); + res =yt921x_reg_write (priv,YT922X_FILTER_UNK_UCAST , ctrl); +if (res) +return res; + + ctrl =0 ; +for (int i =0 ; i < priv->series->max_ports; i++) + ctrl |=YT922X_ACT_UNK_ACTn_TRAP (i);
[Severity: Low]
The loops here size their masks with priv->series->max_ports, which is YT922X_PORT_NUM == 9, but GENMASK(9, 0) covers ten port bits. The YT921x equivalent writes GENMASK(10, 0) with YT921X_PORT_NUM == 11, i.e. exactly max_ports bits. Is bit 9 intentional here, or should this be derived from YT922X_PORT_NUM?
[ ... ]
Quoted 34 lines
drivers/net/dsa/motorcomm/chip.c +34
-0+static int yt922x_dsa_setup (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =to_yt921x_priv (ds); +struct device *dev =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 ; +}
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 5698
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +1
-0@@ -4824,6 +5692,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)static const struct of_device_id yt921x_of_match[] = { { .compatible ="motorcomm,yt9215" , }, + { .compatible ="motorcomm,yt9224" , }, {/* sentinel */ } };MODULE_DEVICE_TABLE (of, yt921x_of_match);
[Severity: Medium]
Is a binding update missing for this compatible? Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml still has:
compatible:
const: motorcomm,yt9215
so a DTS using motorcomm,yt9224 fails dtbs_check with "'motorcomm,yt9224' is not one of ['motorcomm,yt9215']".
The same binding also describes the port map as internal GbE PHYs on Port 0-7 with the GMACs on Port 8-9, which does not match the new YT9224 entry (internal_mask GENMASK(7, 4), external_mask BIT(0) | BIT(8), YT922X_PORT_NUM 9). Should the mdio/port description be extended for YT922x as well?
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.h +0
-0
[ ... ]
Quoted 1 line
drivers/net/dsa/motorcomm/chip.h +0
-0@@ -861,6 +863,102 @@ enum yt921x_fdb_entry_status {
[ ... ]
drivers/net/dsa/motorcomm/chip.h enum yt921x_fdb_entry_status { · line 905
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.h +9
-0+#define YT922X_PORT_SDSn 0x400 +#define YT922X_SERDES_MODE_M GENMASK(6, 4) +#define YT922X_SERDES_MODE (x) FIELD_PREP(YT922X_SERDES_MODE_M, (x)) +#define YT92XX_SERDES_MODE_SGMII YT922X_SERDES_MODE(0) +#define YT92XX_SERDES_MODE_REVSGMII YT921X_SERDES_MODE(1) +#define YT92XX_SERDES_MODE_1000BASEX YT921X_SERDES_MODE(2) +#define YT92XX_SERDES_MODE_100BASEX YT921X_SERDES_MODE(3) +#define YT92XX_SERDES_MODE_2500BASEX YT921X_SERDES_MODE(4) +#define YT92XX_SERDES_MODE_USXGMII YT922X_SERDES_MODE(6)
[Severity: High]
Should the four middle constants use YT922X_SERDES_MODE() rather than YT921X_SERDES_MODE()? YT921X_SERDES_MODE(x) is FIELD_PREP(GENMASK(9, 7), x), while the YT922x field is GENMASK(6, 4).
yt922x_pcs_config() does:
data &= ~YT922X_SERDES_MODE_M; data |= ctrl;
so for 100BASE-X, 1000BASE-X and 2500BASE-X the mode field in bits 6:4 is cleared to 0, which is SGMII, and the value ends up in bits 9:7 of YT922X_PORT_SDSn instead. Only SGMII (value 0) and USXGMII use the YT922x constructor.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914103009.3007019-1-kyle.switch%40motor-comm.com