net: dsa: motorcomm: add support yt922x driver
v14 cover net: dsa: motorcomm: add support yt922x driver
This patchset mainly adds support for the yt922x series to the dsa driver. Currently, only the yt9224 in the yt922x series is supported, and the corresponding tag handling for yt922x is added.
At the same time, it optimizes the max ports boundary check in the existing code, and initializes the dsa switch based on the chipid.
changes in v14:
1) Replace the goto-based skip_extmode_check path with an early conditional in yt921x_chip_detect().
changes in v13:
1) Fix a compilation error in patch1 only.
The change is limited to the yt92xx_register_switch function:
- Replace yt921x_priv with dsa_to_yt921x_priv
- Replace to_device with yt921x_priv_to_device
changes in v12:
1) Rebase the code.
2) Delete origin patch4 and patch5 about MIB init and remove operation.
3) Optimize error message logging.
4) Add documents about yt922x tag.
changes in v11:
1) Initialize ctrl variable inside yt922x_port_up().
2) Update maitainer for new file.
changes in v10:
1) Rebase the code.
changes in v9:
patch 1: 1) Add a dev_err() when chipid mismatch.
patch 3: 1) Using GENMASK_U* to replace GENMASK
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 (5):
net: dsa: motorcomm: initialize dsa_switch based on chipid
net: dsa: motorcomm: use max_ports in series for port bounds checking
net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x
MAINTAINERS | 2 + drivers/net/dsa/motorcomm/Kconfig | 7 +- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 526 ++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 113 ++++++ drivers/net/dsa/motorcomm/mdio_bus.c | 47 ++- drivers/net/dsa/motorcomm/mdio_bus.h | 2 + drivers/net/dsa/motorcomm/pcs-922x.c | 173 +++++++++ drivers/net/dsa/motorcomm/pcs.h | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 122 +++++++ 13 files changed, 981 insertions(+), 22 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
PATCH v14 1/5 net: dsa: motorcomm: initialize dsa_switch based on chipid
Replace the hardcoded chip handling in yt92xx_register_switch() with a data-driven loopup based on the chip ID.
--- drivers/net/dsa/motorcomm/chip.c | 73 ++++++++++++++++++++++++++++---- drivers/net/dsa/motorcomm/chip.h | 19 +++++++++ 2 files changed, 84 insertions(+), 8 deletions(-)
drivers/net/dsa/motorcomm/chip.c +65 -8
@@ -4078,6 +4078,67 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static const struct yt92xx_series yt92xx_series_table[] = { + [YT92XX_MODE_YT921X ] = { + .name ="YT921x" , + .max_ports =YT921X_PORT_NUM , + .num_lag_ids =YT921X_LAG_NUM , + .ageing_time_min =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 =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; + +mutex_lock (&priv->reg_lock); + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +mutex_unlock (&priv->reg_lock); +if (res) { +dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +return res; + } + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) { +dev_err (dev,"Undefined series info for the corresponding major\n" ); +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);
@@ -4120,6 +4181,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)
@@ -4146,15 +4208,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 +19 -0
@@ -841,9 +841,28 @@ static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info)return info->internal_mask | info->xmii_mask | info->serdes_mask; } +enum yt92xx_mode { +YT92XX_MODE_YT921X , +YT92XX_MODE_YT922X , +YT92XX_MODE_MAX , +}; + +struct yt92xx_series { +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 v14 1/5] 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] In yt92xx_register_switch() (drivers/net/dsa/motorcomm/chip.c), when yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid) fails, the error…
- [Low] The commit message presents the change as a pure refactor ('Replace the hardcoded chip handling ... with a data-driven loopup').
- [Low] yt92xx_series_lookup() is an open-coded if-chain (major == YT9215_MAJOR || major == YT9218_MAJOR), not a table lookup.
- [Low] Naming and typing nits in the new series abstraction.
- [Low] The commit message says it replaces 'the hardcoded chip handling in yt92xx_register_switch()'.
- [Low] At this commit, enum yt92xx_mode defines YT92XX_MODE_YT922X and YT92XX_MODE_MAX, but yt92xx_series_table[] is unsized and has only the…
--
net: dsa: motorcomm: initialize dsa_switch based on chipid
This patch moves the dsa_switch field setup out of yt921x_mdio_probe() and into a new helper, yt92xx_register_switch(). The helper reads YT921X_CHIP_ID at probe time, maps the major number to an entry in a new struct yt92xx_series table, and copies that entry's ops and limits into the dsa_switch.
Quoted 2 lines
Replace the hardcoded chip handling in
yt92xx_register_switch()with a data-driven loopup based on the chip ID.
[Severity: Low]
This isn't a bug, but yt92xx_register_switch() doesn't exist before this patch. This patch adds it.
The hardcoded assignments being replaced were in yt921x_mdio_probe(). Should the message name yt921x_mdio_probe() instead?
There's also a typo: "loopup" should be "lookup".
Quoted 11 lines
drivers/net/dsa/motorcomm/chip.c +3
-0@@ -4078,6 +4078,67 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static const struct yt92xx_series yt92xx_series_table[] = { + [YT92XX_MODE_YT921X ] = { + .name ="YT921x" ,
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4093
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ .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 + }, +};
[Severity: Low]
This isn't a bug, but yt92xx_series_table[] has no explicit size and only one entry, YT92XX_MODE_YT921X. enum yt92xx_mode already defines YT92XX_MODE_YT922X and YT92XX_MODE_MAX, so indexing the table with YT92XX_MODE_YT922X would read past the end.
Nothing does that at this commit, because yt92xx_series_lookup() only returns index 0. The last patch in the series also adds the YT92XX_MODE_YT922X entry.
Would sizing the table as [YT92XX_MODE_MAX] make this clearer?
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4101
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8
-0+ +static const struct yt92xx_series *yt92xx_series_lookup (u32 major) +{ +if (major ==YT9215_MAJOR || major ==YT9218_MAJOR ) +return &yt92xx_series_table[YT92XX_MODE_YT921X ]; +else +return NULL ; +}
[Severity: Low]
This isn't a bug, but this if-chain classifies the major separately from yt921x_infos[]. Those entries already carry .major, and yt921x_chip_detect() walks them after reading YT921X_CHIP_ID a second time:
drivers/net/dsa/motorcomm/chip.c:yt921x_chip_detect() {
...
for (info = yt921x_infos; info->name; info++)
if (info->major == major)
break;
...
}Every new chip variant has to be added in both places:
- If only yt921x_infos[] is updated, probe rejects the chip with -ENODEV.
- If only this if-chain is updated, probe accepts the chip and setup rejects it later.
The last patch in the series, "net: dsa: motorcomm: Add support for Motorcomm YT922x", adds an "else if (major == YT9224_MAJOR)" here instead of linking the series to the info table.
Could the series come from yt921x_infos[] instead, to match the "data-driven lookup" in the commit message?
Quoted 14 lines
drivers/net/dsa/motorcomm/chip.c +14
-0+ +static int yt92xx_register_switch (struct dsa_switch *ds) +{ +struct yt921x_priv *priv =dsa_to_yt921x_priv (ds); +struct device *dev =yt921x_priv_to_device (priv); +const struct yt92xx_series *series; +u32 chipid; +u32 major; +int res; + +mutex_lock (&priv->reg_lock); + res =yt921x_reg_read (priv,YT921X_CHIP_ID , &chipid); +mutex_unlock (&priv->reg_lock); +if (res) {
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4125
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+dev_err (dev,"Unexpected chipid 0x%x\n" , chipid); +return res; + } + + major =FIELD_GET (YT921X_CHIP_ID_MAJOR , chipid); + series =yt92xx_series_lookup (major); +if (!series) { +dev_err (dev,"Undefined series info for the corresponding major\n" ); +return -ENODEV ; + }
[Severity: Low]
Is chipid initialized when the first dev_err() runs? yt921x_reg_mdio_read() only writes *valp after all four MDIO accesses succeed:
drivers/net/dsa/motorcomm/chip.c:yt921x_reg_mdio_read() {
...
res = __mdiobus_read(bus, addr, reg_data);
if (res < 0)
goto end;
val = (val << 16) | (u16)res;
*valp = val;
res = 0;end:
... }
On an MDIO error, the log would show a stale stack value and describe a bus failure as an unexpected chip ID.
The !series branch, where chipid is valid, doesn't print the ID at all. Should the two messages be swapped, the way yt921x_chip_detect() handles it?
The last patch in the series, "net: dsa: motorcomm: Add support for Motorcomm YT922x", fixes this. The read-failure branch becomes a plain return res, and the !series branch prints the chip ID. This intermediate commit could still be hit during a bisect, so could the fix be folded into this patch?
[ ... ]
Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +0
-2@@ -4146,15 +4208,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;
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4214
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +3
-6ds->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;
[Severity: Low]
The commit message describes this as a pure refactor. However, yt921x_mdio_probe() now takes priv->reg_lock and does an MDIO read of YT921X_CHIP_ID before dsa_register_switch().
Before this patch, probe only filled in static dsa_switch fields. The first register access was yt921x_chip_detect(), reached via yt921x_dsa_setup()->yt921x_chip_reset().
Now an MDIO error or an unknown major fails probe directly, rather than failing in the .setup callback. The chip ID is also read twice:
once here and again in yt921x_chip_detect().
Could the commit message mention this change in behaviour?
Quoted 15 lines
drivers/net/dsa/motorcomm/chip.h +7
-0@@ -841,9 +841,28 @@ static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info)return info->internal_mask | info->xmii_mask | info->serdes_mask; } +enum yt92xx_mode { +YT92XX_MODE_YT921X , +YT92XX_MODE_YT922X , +YT92XX_MODE_MAX , +}; + +struct yt92xx_series {
drivers/net/dsa/motorcomm/chip.h static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info) · line 860
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.h +10
-0+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; +};
[Severity: Low]
This isn't a bug, but a few small things about the new series abstraction:
dscp_prio_mapping_is_global and assisted_learning_on_cpu_port are boolean flags that get copied into bool fields of struct dsa_switch. Should they be bool here as well?
The name field and YT92XX_MODE_MAX don't appear to be used anywhere, either at this commit or at the end of the series.
yt92xx_register_switch() in chip.c doesn't register anything. It reads the chip ID and fills in dsa_switch fields, and the actual registration is the later dsa_register_switch() call in yt921x_mdio_probe(). Would a name such as yt92xx_init_switch() fit better?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261013011122.1889766-1-kyle.switch%40motor-comm.com
PATCH v14 2/5 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/mdio_bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/mdio_bus.c +5 -3
@@ -113,7 +113,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);
@@ -131,7 +131,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);
@@ -145,6 +145,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) {struct device *dev =yt921x_priv_to_device (priv);struct mii_bus *mbus; +u32 max_ports;int res; mbus =devm_mdiobus_alloc (dev);
@@ -157,7 +158,8 @@ int 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
PATCH v14 3/5 net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
In reply to Kyle SwitchSome masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the affected internal_mask entries in chip.c and the YT921X_MBUS_CTRL_* masks used by mdio_bus.c to fixed-width helpers.
This is a type cleanup only, with no functional change. Other GENMASK() uses in the driver are intentionally left untouched.
--- drivers/net/dsa/motorcomm/chip.c | 12 ++++++------ drivers/net/dsa/motorcomm/mdio_bus.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/dsa/motorcomm/chip.c +6 -6
@@ -36,19 +36,19 @@static const struct yt921x_info yt921x_infos[] = { {"YT9215SC" ,YT9215_MAJOR ,1 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ) |BIT (9 ), }, {"YT9215S" ,YT9215_MAJOR ,2 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ), }, {"YT9215RB" ,YT9215_MAJOR ,3 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (8 ) |BIT (9 ),0 , },
@@ -66,13 +66,13 @@ static const struct yt921x_info yt921x_infos[] = { }, {"YT9218N" ,YT9218_MAJOR ,0 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),0 ,0 , }, {"YT9218MB" ,YT9218_MAJOR ,1 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),BIT (8 ) |BIT (9 ), BIT(8) | BIT(9), },
@@ -3741,7 +3741,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)if (res)return res; - ctrl =GENMASK (10 ,0 ); + ctrl =GENMASK_U32 (10 ,0 ); res =yt921x_reg_write (priv,YT921X_FILTER_UNK_UCAST , ctrl);if (res)return res;
drivers/net/dsa/motorcomm/mdio_bus.c +1 -1
@@ -159,7 +159,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->write = yt921x_mbus_int_write; mbus->parent = dev; max_ports = priv->series->max_ports; - mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); + mbus->phy_mask = ~GENMASK_U32 (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 v14 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
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] The commit message for "net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers" does not describe the diff correctly.
--
net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
This patch replaces several GENMASK() uses in the motorcomm DSA driver with GENMASK_U16() and GENMASK_U32(). It touches the internal_mask entries in yt921x_infos[], the ctrl value in yt921x_chip_setup_dsa() and the phy_mask computation in yt921x_mbus_int_init(). It is described as a type cleanup with no functional change.
Quoted 5 lines
Some masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the affected
internal_maskentries inchip.cand the YT921X_MBUS_CTRL_* masks used bymdio_bus.cto fixed-width helpers.
[Severity: Low]
Does this description match the diff?
The YT921X_MBUS_CTRL_* masks are defined in drivers/net/dsa/motorcomm/mdio_bus.h. This patch does not touch that file, and the masks still use plain GENMASK() after the patch:
#define YT921X_MBUS_CTRL_PORT_M GENMASK(25, 21) #define YT921X_MBUS_CTRL_REG_M GENMASK(20, 16) #define YT921X_MBUS_CTRL_TYPE_M GENMASK(11, 8) /* wild guess */ #define YT921X_MBUS_CTRL_OP_M GENMASK(3, 2) /* wild guess */
The only change in mdio_bus.c is the mii_bus phy_mask in yt921x_mbus_int_init(). That mask is computed from a runtime value and is not one of the YT921X_MBUS_CTRL_* masks:
- mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
+ mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0);
In chip.c, the changes also go beyond the internal_mask entries. yt921x_chip_setup_dsa() converts the local register value written to YT921X_FILTER_UNK_UCAST and YT921X_FILTER_UNK_MCAST:
- ctrl = GENMASK(10, 0);
+ ctrl = GENMASK_U32(10, 0);
Could the message be reworded to describe the phy_mask and ctrl changes? Alternatively, should the mdio_bus.h conversion be added as the message describes?
The description and the diff disagree, so was the Reviewed-by tag perhaps given on an earlier revision with different content?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261013011122.1889766-1-kyle.switch%40motor-comm.com
David Yang
maintainerRe: [PATCH net-next v14 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
In reply to Kyle SwitchQuoted 40 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +5
-5@@ -36,19 +36,19 @@static const struct yt921x_info yt921x_infos[] = { {"YT9215SC" ,YT9215_MAJOR ,1 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ) |BIT (9 ), }, {"YT9215S" ,YT9215_MAJOR ,2 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ), }, {"YT9215RB" ,YT9215_MAJOR ,3 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (8 ) |BIT (9 ),0 , },@@ -66,13 +66,13 @@ static const struct yt921x_info yt921x_infos[] = { }, {"YT9218N" ,YT9218_MAJOR ,0 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),0 ,0 , }, {"YT9218MB" ,YT9218_MAJOR ,1 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),BIT (8 ) |BIT (9 ), BIT(8) | BIT(9), },
drivers/net/dsa/motorcomm/chip.c static int yt921x_chip_setup_dsa(struct yt921x_priv *priv) · line 3747
Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +1
-1@@ -3741,7 +3741,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)if (res)return res; - ctrl =GENMASK (10 ,0 ); + ctrl =GENMASK_U32 (10 ,0 ); res =yt921x_reg_write (priv,YT921X_FILTER_UNK_UCAST , ctrl);if (res)return res;
The change below is fine, but the ones above aren't, the width is already pinned by the variable being assigned to. Also DSA expects u32 port masks to some extent, those add unnecessary changes if you want to change port masks in yt921x_info to u32 some day.
Quoted 16 lines
drivers/net/dsa/motorcomm/mdio_bus.c +1
-2@@ -159,7 +159,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->write = yt921x_mbus_int_write; mbus->parent = dev; max_ports = priv->series->max_ports; - mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); + mbus->phy_mask = ~GENMASK_U32 (max_ports -1 ,0 ); res =devm_of_mdiobus_register (dev, mbus, mnp);if (res) --2.25.1
Re: [PATCH net-next v14 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
Quoted 44 lines · David Yang
Quoted 43 lines · Kyle Switch
drivers/net/dsa/motorcomm/chip.c +5
-5@@ -36,19 +36,19 @@static const struct yt921x_info yt921x_infos[] = { {"YT9215SC" ,YT9215_MAJOR ,1 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ) |BIT (9 ), }, {"YT9215S" ,YT9215_MAJOR ,2 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (9 ),BIT (8 ), }, {"YT9215RB" ,YT9215_MAJOR ,3 ,0 , -GENMASK (4 ,0 ), +GENMASK_U16 (4 ,0 ),BIT (8 ) |BIT (9 ),0 , },@@ -66,13 +66,13 @@ static const struct yt921x_info yt921x_infos[] = { }, {"YT9218N" ,YT9218_MAJOR ,0 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),0 ,0 , }, {"YT9218MB" ,YT9218_MAJOR ,1 ,0 , -GENMASK (7 ,0 ), +GENMASK_U16 (7 ,0 ),BIT (8 ) |BIT (9 ), BIT(8) | BIT(9), },@@ -3741,7 +3741,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)if (res)return res;
Quoted 9 lines
drivers/net/dsa/motorcomm/chip.c static int yt921x_chip_setup_dsa(struct yt921x_priv *priv) · line 3747
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +1
-1- ctrl =GENMASK (10 ,0 ); + ctrl =GENMASK_U32 (10 ,0 ); res =yt921x_reg_write (priv,YT921X_FILTER_UNK_UCAST , ctrl);if (res)return res;The change below is fine, but the ones above aren't, the width is already pinned by the variable being assigned to. Also DSA expects u32 port masks to some extent, those add unnecessary changes if you want to change port masks in
yt921x_infoto u32 some day.
you're right, It may work for the current definition, but it's not
conducive to future expansion. In future series, there will be multi-port scenarios.
will be fixed in next patch version.
Quoted 17 lines
Quoted 17 lines
drivers/net/dsa/motorcomm/mdio_bus.c +1
-2@@ -159,7 +159,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) mbus->write = yt921x_mbus_int_write; mbus->parent = dev; max_ports = priv->series->max_ports; - mbus->phy_mask = (u32 )~GENMASK (max_ports -1 ,0 ); + mbus->phy_mask = ~GENMASK_U32 (max_ports -1 ,0 ); res =devm_of_mdiobus_register (dev, mbus, mnp);if (res) --2.25.1
PATCH v14 4/5 net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
In reply to Kyle SwitchAdd DSA tag support for Motorcomm YT922x switches. YT922x uses the same ETH_P_YT921X EtherType and the same 8-byte tag length as YT921x, but the tag layout differs, so a separate tag driver is needed instead of extending tag_yt921x.c.
The new driver documents both the to-CPU and from-CPU tag layouts.
Update the co-maintainer for the Motorcomm DSA driver.
--- MAINTAINERS | 2 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 122 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 net/dsa/tag_yt922x.c
MAINTAINERS +2 -0
@@ -18434,11 +18434,13 @@ F: drivers/net/phy/motorcomm.c MOTORCOMM YT921X ETHERNET SWITCH DRIVER M: David Yang <[email protected]> +M: Kyle Switch <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c +F: net/dsa/tag_yt922x.c MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD M: Jiri Slaby <[email protected]>
include/net/dsa.h +2 -0
@@ -62,6 +62,7 @@ struct tc_action;#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35#define DSA_TAG_PROTO_KS8995_VALUE 36 +#define DSA_TAG_PROTO_YT922X_VALUE 37enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -101,6 +102,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE ,DSA_TAG_PROTO_KS8995 =DSA_TAG_PROTO_KS8995_VALUE , + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -233,4 +233,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
@@ -45,6 +45,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 +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net-next v14 4/5] 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] The tag-layout comment in net/dsa/tag_yt922x.c does not match what yt922x_tag_xmit() writes.
- [Low] Concern: yt922x_tag_rcv() never calls dsa_default_offload_fwd_mark(), so the software bridge might forward…
--
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
This adds a new DSA tag driver for Motorcomm YT922x switches. YT922x uses the same ETH_P_YT921X EtherType and 8-byte tag length as YT921x, but the tag layout is different. The patch also adds a co-maintainer to the Motorcomm DSA MAINTAINERS entry.
Quoted 6 lines
net/dsa/tag_yt922x.c new file +0
-0@@ -0,0 +1,122 @@
[ ... ]
Quoted 16 lines
+/*
+ * To define the from cpu tag format 8 bytes.
+ *
+ * To-CPU (RX) tag format, 8 bytes:
+ *+ * tag[0]: TPID (default: 0x9988) + * tag[1]: VID lookup + * tag[2]: bit 5:2 - RX source port + * + * From-CPU (TX) tag format, 8 bytes: + * + * tag[0]: TPID (default: 0x9988) + * tag[1]: bit 8:0 - Dst port mask + * tag[2]: bit 15 - Dst port 0+ *
+ */
[ ... ]
net/dsa/tag_yt922x.c line 57
Quoted 6 lines
net/dsa/tag_yt922x.c new file +6
-0+ tag[0 ] =htons (ETH_P_YT921X ); + ports =dsa_xmit_port_mask (skb, netdev); +/*To fill in the case where the port index is not 0 */ + ctrl =YT922X_TAG_PRIO (skb->priority) |YT922X_TAG_FORCE_DST | +YT922X_TAG_PORTS (ports >>1 ); + tag[1 ] =htons (ctrl);
[Severity: Low]
This isn't a bug, but does the tag layout comment match what yt922x_tag_xmit() writes? The commit message says:
The new driver documents both the to-CPU and from-CPU tag layouts.
The from-CPU part of the comment describes tag[1] bits 8:0 as the destination port mask. yt922x_tag_xmit() puts ports >> 1 into that field, though, so bit 0 there is port 1, not port 0.
tag[1] also always carries YT922X_TAG_FORCE_DST (bit 9), YT922X_TAG_PRIO_M (bits 12:10) and YT922X_TAG_PRIO_EN (bit 13), and tag[3] is written as 0. The comment doesn't mention any of these.
Separately, the comment block opens with "To define the from cpu tag format 8 bytes." right above the To-CPU (RX) description. Is that line a leftover?
[ ... ]
net/dsa/tag_yt922x.c line 108
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]
Should yt922x_tag_rcv() call dsa_default_offload_fwd_mark() before it returns? tag_yt921x.c and most of the other tag drivers do.
As far as I can tell, leaving it out has no effect with the switch driver later in the series. yt922x_dsa_switch_ops has no .port_bridge_join, so dp->bridge stays NULL and the bridge falls back to software bridging. In that case the helper would set the mark to 0 anyway:
net/dsa/tag.h:dsa_default_offload_fwd_mark() {
...
skb->offload_fwd_mark = !!(dp->bridge);
}The port isolation and trap-to-CPU setup in the switch driver also stop the hardware from forwarding between user ports.
If bridge offload is added later, would the software bridge forward frames again that the switch has already forwarded, unless the mark is set here?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261013011122.1889766-1-kyle.switch%40motor-comm.com
PATCH v14 5/5 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 | 7 +- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 449 ++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 94 ++++++ drivers/net/dsa/motorcomm/mdio_bus.c | 39 +++ drivers/net/dsa/motorcomm/mdio_bus.h | 2 + drivers/net/dsa/motorcomm/pcs-922x.c | 173 +++++++++++ drivers/net/dsa/motorcomm/pcs.h | 1 + 8 files changed, 757 insertions(+), 9 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c
drivers/net/dsa/motorcomm/Kconfig +4 -3
@@ -1,11 +1,12 @@ # 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 - chip. + This enables support for the Motorcomm YT9215 and YT9224 + ethernet switch chip. config NET_DSA_YT921X_LEDS bool "LED support for Motorcomm YT9215"
drivers/net/dsa/motorcomm/Makefile +1 -0
@@ -4,5 +4,6 @@ yt921x-objs := chip.o yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += mdio_bus.o yt921x-objs += mib.o +yt921x-objs += pcs-922x.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o
drivers/net/dsa/motorcomm/chip.c +443 -6
511 lines not on this page · raw message
drivers/net/dsa/motorcomm/chip.h +94 -0
118 lines not on this page · raw message
drivers/net/dsa/motorcomm/mdio_bus.c +39 -0
@@ -299,3 +299,42 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } + +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +}
drivers/net/dsa/motorcomm/mdio_bus.h +2 -0
@@ -50,5 +50,7 @@ yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,int yt921x_mbus_int_init (struct yt921x_priv *priv,struct device_node *mnp);int yt921x_mbus_ext_init (struct yt921x_priv *priv,struct device_node *mnp); +int yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val); +int yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp);#endif
drivers/net/dsa/motorcomm/pcs-922x.c new file +173 -0
173 lines not on this page · raw message
drivers/net/dsa/motorcomm/pcs.h +1 -0
@@ -9,5 +9,6 @@#include <linux/phylink.h> extern const struct phylink_pcs_ops yt921x_phylink_pcs_ops; +extern const struct phylink_pcs_ops yt922x_phylink_pcs_ops;#endif
Signature · 1 line
2.25.1
Andrew Lunn
maintainerRe: [PATCH net-next v14 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 34 lines
+++
b/drivers/net/dsa/motorcomm/mdio_bus.cdrivers/net/dsa/motorcomm/mdio_bus.c +29
-0@@ -299,3 +299,42 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } + +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; +
drivers/net/dsa/motorcomm/mdio_bus.c int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp) · line 340
Quoted 10 lines
drivers/net/dsa/motorcomm/mdio_bus.c +10
-0+ res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +}
Why are these in mdio_bus? They don't have anything to do with MDIO.
Since they build on yt921x_intif_read they seem to fit in yt921x.c better? Or am i missing something?
Quoted 19 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +19
-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; + + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII ); +if (addr <0 ) { + state->link = false; +return ; + } + +mutex_lock (&priv->reg_lock); +switch (state->interface) {
drivers/net/dsa/motorcomm/pcs-922x.c line 50
Quoted 10 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +10
-0+case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : + 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);
Rather than data, call it bmsr. It then fits:
void phylink_mii_c22_pcs_decode_state(struct phylink_link_state *state,
unsigned int neg_mode, u16 bmsr, u16 lpa)
Quoted 11 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +11
-0+static void yt922x_pcs_an_restart (struct phylink_pcs *pcs) +{ +struct yt921x_port *pp =pcs_to_yt921x_port (pcs); +struct yt921x_priv *priv =yt921x_port_to_priv (pp); +struct device *dev =to_device (priv); +int port = pp->index; +u16 data; +int addr; +int res; + +mutex_lock (&priv->reg_lock);
drivers/net/dsa/motorcomm/pcs-922x.c line 97
Quoted 10 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +10
-0+ addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII ); +if (addr <0 ) { + res = addr; + goto err; + } + res =yt921x_intif_read (priv, addr,MII_BMCR , &data); +if (res) + goto err; + data |=BMCR_ANRESTART ; + res =yt921x_intif_write (priv, addr,MII_BMCR , data);
Again, bmcr. It then looks a lot likephylink_mii_c22_pcs_an_restart().
Quoted 7 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +7
-0+if (res) + goto err; +mutex_unlock (&priv->reg_lock); +return ; + +err: +mutex_unlock (&priv->reg_lock);
drivers/net/dsa/motorcomm/pcs-922x.c line 114
Quoted 10 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +10
-0+if (res) +dev_err (dev,"Failed to %s PCS port %d: %i\n" ,"an restart" , + port, res); +} + +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) +{
advertising does not appear to be used here. Does this pcs not support it? That would be odd, because you looked at lpa in earlier functions.
Andrew
Re: [PATCH net-next v14 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 46 lines · Andrew Lunn
Quoted 34 lines
+++
b/drivers/net/dsa/motorcomm/mdio_bus.cdrivers/net/dsa/motorcomm/mdio_bus.c +29
-0@@ -299,3 +299,42 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } + +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; +drivers/net/dsa/motorcomm/mdio_bus.c int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp) · line 340
Quoted 10 lines
drivers/net/dsa/motorcomm/mdio_bus.c +10
-0+ res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +}Why are these in
mdio_bus? They don't have anything to do with MDIO.
Quoted 2 lines
Since they build on
yt921x_intif_readthey seem to fit inyt921x.cbetter? Or am i missing something?
These two interfaces access the extend registers of the Phy/serdes.
Following the existing code style-where the PHY/SerDes MII registers
were placed in the mdio_bus.c,these two interfaces are also placed
in the mdio_bus.c.
Quoted 32 lines
Quoted 19 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +19
-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; + + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII ); +if (addr <0 ) { + state->link = false; +return ; + } + +mutex_lock (&priv->reg_lock); +switch (state->interface) {drivers/net/dsa/motorcomm/pcs-922x.c line 50
Quoted 10 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +10
-0+case PHY_INTERFACE_MODE_SGMII : +case PHY_INTERFACE_MODE_1000BASEX : +case PHY_INTERFACE_MODE_2500BASEX : + 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);Rather than data, call it bmsr. It then fits:
Quoted 2 lines
void phylink_mii_c22_pcs_decode_state(struct
phylink_link_state*state,
unsigned intneg_mode, u16 bmsr, u16 lpa)
Okay.
Quoted 16 lines
Quoted 16 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +15
-0+static void yt922x_pcs_an_restart (struct phylink_pcs *pcs) +{ +struct yt921x_port *pp =pcs_to_yt921x_port (pcs); +struct yt921x_priv *priv =yt921x_port_to_priv (pp); +struct device *dev =to_device (priv); +int port = pp->index; +u16 data; +int addr; +int res; + +mutex_lock (&priv->reg_lock); + addr =yt922x_sds_phyaddr_get (port,YT922X_PHY_REG_TYPE_MII ); +if (addr <0 ) { + res = addr; + goto err;
Quoted 8 lines
drivers/net/dsa/motorcomm/pcs-922x.c line 97
Quoted 6 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +6
-0+ } + res =yt921x_intif_read (priv, addr,MII_BMCR , &data); +if (res) + goto err; + data |=BMCR_ANRESTART ; + res =yt921x_intif_write (priv, addr,MII_BMCR , data);Again, bmcr. It then looks a lot like
phylink_mii_c22_pcs_an_restart().
Okay.
Quoted 11 lines
Quoted 11 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +11
-0+if (res) + goto err; +mutex_unlock (&priv->reg_lock); +return ; + +err: +mutex_unlock (&priv->reg_lock); +if (res) +dev_err (dev,"Failed to %s PCS port %d: %i\n" ,"an restart" , + port, res); +}
Quoted 8 lines
drivers/net/dsa/motorcomm/pcs-922x.c line 114
Quoted 6 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +6
-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) +{advertising does not appear to be used here. Does this pcs not support it? That would be odd, because you looked at lpa in earlier functions.
advertising and neg_mode will been handled in next patch version.
Quoted 2 lines
Andrew
[email protected]
AI reviewRe: [PATCH net-next v14 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchThank 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: 1 · Medium: 3 · Low: 1
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] net: dsa: motorcomm: port control register clobbered in yt922x_port_up due to missing read
- [Medium] The new "YT9228" entry in yt921x_infos can never be selected.
- [Medium] The patch adds { .compatible = "motorcomm,yt9224" } to yt921x_of_match, but the only binding for this driver,…
- [Medium] yt922x_pcs_config() accepts neg_mode, advertising and permit_pause_to_mac but uses none of them.
- [Low] yt922x_port_down() and yt922x_port_up() each run several separate register transactions: the PORTn_CTRL MAC/link bits, then FORCE_OP,…
--
net: dsa: motorcomm: Add support for Motorcomm YT922x
This commit adds YT922x series support to the existing YT921x DSA driver. It adds a new series table entry, phylink MAC ops, a SerDes PCS implementation in pcs-922x.c and a "motorcomm,yt9224" compatible. The commit message says only the YT9224 variant is supported for now.
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0
-0
[ ... ]
Quoted 18 lines
drivers/net/dsa/motorcomm/chip.c +12
-0@@ -76,6 +76,18 @@ static const struct yt921x_info yt921x_infos[] = { BIT(8) | BIT(9), BIT(8) | BIT(9), }, + { +"YT9224" ,YT9224_MAJOR ,0 ,0 , +GENMASK_U16 (7 ,4 ), +0 , +BIT (8 ) |BIT (0 ), + }, + { +"YT9228" ,YT9224_MAJOR ,0 ,0 , +GENMASK_U16 (7 ,4 ), +0 , + BIT(8) | GENMASK_U16(3, 0), + }, {} };
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_chip_detect(struct yt921x_priv *priv) · line 3657
Quoted 11 lines
drivers/net/dsa/motorcomm/chip.c +7
-0@@ -3631,6 +3648,14 @@ static int yt921x_chip_detect(struct yt921x_priv *priv)return -ENODEV ; } +if (!yt921x_needs_extmode_check (major)) { +dev_info (dev, +"Motorcomm %s ethernet switch, chipid: 0x%x\n" , + info->name, chipid); + priv->info = info; +return 0 ; + }
[Severity: Medium]
Can the YT9228 entry in yt921x_infos[] ever be selected?
Both new entries use YT9224_MAJOR with mode 0 and extmode 0. The lookup loop in yt921x_chip_detect() stops at the first entry whose major matches:
for (info = yt921x_infos; info->name; info++) if (info->major == major) break;
For major 0x9004 that is always "YT9224". The new early return then uses that entry without checking mode or extmode, and the two entries have the same values for those anyway.
The commit message says:
YT9228 is not supported yet.
If a YT9228 reports this major, as the table says it does, wouldn't it bind instead of failing with -ENODEV? yt92xx_series_lookup() also sends every 0x9004 chip to the YT922x series, and the chip would be logged as "Motorcomm YT9224 ...".
It would also get the YT9224 serdes_mask. In that case, yt922x_dsa_phylink_get_caps() and yt922x_pcs_setup() leave ports 1-3 with no supported interfaces and no PCS. phylink_create() would then fail for those ports, and DSA would quietly treat them as unused. Is that intended?
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5
-0+static int +yt922x_port_up (struct yt921x_priv *priv,int port,unsigned int mode, +phy_interface_t interface,int speed,int duplex, +bool tx_pause,bool rx_pause) +{
[ ... ]
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+ res =yt921x_reg_write (priv,YT922X_PORTn_CTRL (port), ctrl); +if (res) +return res; + +/* force op */ + mask =YT922X_PORT_FORCE_OP ; + res =yt921x_reg_set_bits (priv,YT922X_PORTn_CTRL (port), mask); +if (res) +return res; +
drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 4195
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10
-0+/* enable en_phy */ + res =yt921x_reg_set_bits (priv,YT922X_EN_PHY_VALUE ,BIT (port)); +if (res) +return res; + res =yt921x_reg_set_bits (priv,YT922X_EN_PHY_OVERWRITE ,BIT (port)); +if (res) +return res; + +return 0 ; +}
[Severity: High]
Is this meant to be a read-modify-write of YT922X_PORTn_CTRL?
ctrl starts at 0. Only the speed, duplex, pause and MAC/CFG enable bits are ORed into it, so clearing YT922X_PORT_FC_AN and YT922X_PORT_LINK_AN afterwards does nothing. That clear only makes sense if ctrl was supposed to hold the current register contents first.
As written, yt921x_reg_write() replaces the whole register on every link up. Any field not set here is forced to zero each time phylink calls yt922x_phylink_mac_link_up(). That includes YT922X_PORT_HALF_PAUSE and any reserved or vendor-default bits above YT922X_PORT_FORCE_OP. Is that safe on this hardware?
If a full write is really intended, the dead clear could be dropped and the register layout documented. Otherwise, should this use yt921x_reg_update_bits() with a mask covering only the fields being programmed? That would mean speed, duplex, pause, the MAC/CFG enables and the AN bits, in the same way that yt922x_port_down() only touches the bits it cares about via yt921x_reg_clear_bits().
[Severity: Low]
This is minor, but what state is the port left in if the YT922X_EN_PHY_VALUE update fails after FORCE_OP has already applied the forced MAC link-up?
The MAC would stay forced up while the PHY-enable override from the previous yt922x_port_down() stays forced low. yt922x_phylink_mac_link_up() only logs the error. yt922x_port_down() has the same structure, with no rollback of earlier steps.
This copies the existing yt921x_port_up() and yt921x_port_down() pattern. It can only happen once SMI/MDIO access is already failing.
[ ... ]
drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 4660
Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +1
-0@@ -4220,6 +4655,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" }, {} };
[Severity: Medium]
Should this come with a binding update? The binding in Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml still only has:
compatible:
const: motorcomm,yt9215
With that binding, any DTS using "motorcomm,yt9224" would fail dt-schema validation, and checkpatch would report the compatible as undocumented.
The binding text also covers YT921x port layouts only. Its mdio description says:
Internal MDIO bus for the internal GbE PHYs. PHY 0-7 are used for Port 0-7 respectively.
The new info table gives YT9224 internal PHYs only on ports 4-7, and SerDes on ports 0 and 8.
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +5
-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) +{
[ ... ]
drivers/net/dsa/motorcomm/pcs-922x.c line 161
Quoted 11 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +11
-0+ res =yt921x_intif_ext_read (priv, addr, YT922X_PORT_SDSn, &data); +if (res) + goto err; + data &= ~YT922X_SERDES_MODE_M ; + data |= ctrl; + res =yt921x_intif_ext_write (priv, addr, YT922X_PORT_SDSn, data); +if (res) + goto err; +mutex_unlock (&priv->reg_lock); + +return res;
[Severity: Medium]yt922x_pcs_config() never uses neg_mode, advertising or permit_pause_to_mac. Apart from the 0xd write to ext reg 0x4be, it only rewrites the SerDes mode field. Is that enough to meet the pcs_config contract?
The pcs_config kernel-doc in include/linux/phylink.h says in-band should be enabled in MLO_AN_INBAND and disabled otherwise. It also says the 1000BASE-X advertisement should be programmed into the PCS. pcs-921x.c does this with phylink_mii_c22_pcs_encode_advertisement() and BMCR_ANENABLE handling.
Here, in-band-enabled and in-band-disabled requests produce the same register writes. Depending on the reset default, won't one of them leave the hardware AN state wrong? For example, a fixed-link 2500BASE-X CPU port could be left with AN enabled, or an in-band SGMII PHY link with AN disabled.
phylink_change_inband_advert() also relies on pcs_config() to apply advertisement and pause changes:
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);
Since this always returns 0 and never writes MII_ADVERTISE, wouldn't ethtool advertisement or pause changes be silently dropped?
yt922x_pcs_get_state() also decodes BMSR/LPA as if in-band AN had been configured. yt922x_pcs_an_restart() sets BMCR_ANRESTART even though AN was never configured.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261013011122.1889766-1-kyle.switch%40motor-comm.com
David Yang
maintainerRe: [PATCH net-next v14 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
In reply to Kyle SwitchQuoted 1 line · Kyle Switch
+/* yt922x register lists */
The indents below look inconsistent. Please adjust to match the existing macros.
drivers/net/dsa/motorcomm/chip.h enum yt921x_fdb_entry_status { · line 788
Quoted 13 lines
drivers/net/dsa/motorcomm/chip.h +13
-0+#define YT92XX_PAGE_SELECT 0x1e +#define YT92XX_PAGE 0x1f +#define YT922X_PORTn_STATUS (port) (0x80200 + 4 * (port)) +#define YT922X_PORT_LINK_STATE BIT(8) +#define YT922X_PORT_LINK_DUPLEX BIT(7) +#define YT922X_PORT_RX_FC_EN BIT(6) +#define YT922X_PORT_TX_FC_EN BIT(5) +#define YT922X_PORT_SPEED_10 0 +#define YT922X_PORT_SPEED_100 1 +#define YT922X_PORT_SPEED_1000 2 +#define YT922X_PORT_SPEED_10000 3 +#define YT922X_PORT_SPEED_2500 4 +#define YT922X_PORT_SPEED_5000 5
Leftover from yt921x_speed.
Quoted 1 line
+/* ISO */
The comments here (and below) did not provide much information beyond the code itself.
Quoted 1 line
+#define
YT922X_PORTn_ISOLATION(port)(0x4* (port) +0x180d80)
(0x180d80 + 4 * (port))
Quoted 52 lines
drivers/net/dsa/motorcomm/mdio_bus.c +39
-0@@ -299,3 +299,42 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } + +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +}drivers/net/dsa/motorcomm/mdio_bus.h +0
-0
drivers/net/dsa/motorcomm/mdio_bus.h yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask, · line 56
Quoted 7 lines
drivers/net/dsa/motorcomm/mdio_bus.h +2
-0@@ -50,5 +50,7 @@ yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,int yt921x_mbus_int_init (struct yt921x_priv *priv,struct device_node *mnp);int yt921x_mbus_ext_init (struct yt921x_priv *priv,struct device_node *mnp); +int yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val); +int yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp);#endif
intif_ext_* should be placed right after intif_* (if they are still in mdio_bus).
Re: [PATCH net-next v14 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x
Quoted 3 lines · David Yang
Quoted 1 line · Kyle Switch
+/* yt922x register lists */
The indents below look inconsistent. Please adjust to match the existing macros.
Okay.
Quoted 15 lines
Quoted 4 lines
drivers/net/dsa/motorcomm/chip.h +3
-0+#define YT92XX_PAGE_SELECT 0x1e +#define YT92XX_PAGE 0x1f +#define YT922X_PORTn_STATUS (port) (0x80200 + 4 * (port))drivers/net/dsa/motorcomm/chip.h enum yt921x_fdb_entry_status { · line 788
Quoted 10 lines
drivers/net/dsa/motorcomm/chip.h +10
-0+#define YT922X_PORT_LINK_STATE BIT(8) +#define YT922X_PORT_LINK_DUPLEX BIT(7) +#define YT922X_PORT_RX_FC_EN BIT(6) +#define YT922X_PORT_TX_FC_EN BIT(5) +#define YT922X_PORT_SPEED_10 0 +#define YT922X_PORT_SPEED_100 1 +#define YT922X_PORT_SPEED_1000 2 +#define YT922X_PORT_SPEED_10000 3 +#define YT922X_PORT_SPEED_2500 4 +#define YT922X_PORT_SPEED_5000 5Leftover from
yt921x_speed.
will be removed and use the macros defined earlier in 921x.
Quoted 5 lines
Quoted 2 lines
+/* ISO */
The comments here (and below) did not provide much information beyond the code itself.
okay, will remove meaningless code comments.
Quoted 2 lines
Quoted 1 line
+#define
YT922X_PORTn_ISOLATION(port)(0x4* (port) +0x180d80)(
0x180d80+ 4 * (port))
Okay.
Quoted 54 lines
Quoted 54 lines
drivers/net/dsa/motorcomm/mdio_bus.c +39
-0@@ -299,3 +299,42 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)return 0 ; } + +/* intif extend register read/write api */ +int +yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE , val); +if (res) +return res; + +return 0 ; +} + +int +yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp) +{ +int res; + +if (port > priv->series->max_ports) +return -ENODEV ; + + res =yt921x_intif_write (priv, port,YT92XX_PAGE_SELECT , reg); +if (res) +return res; + + res =yt921x_intif_read (priv, port,YT92XX_PAGE , valp); +if (res) +return res; + +return 0 ; +}drivers/net/dsa/motorcomm/mdio_bus.h +0
-0@@ -50,5 +50,7 @@ yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,
Quoted 8 lines
drivers/net/dsa/motorcomm/mdio_bus.h yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask, · line 56
Quoted 6 lines
drivers/net/dsa/motorcomm/mdio_bus.h +2
-0int yt921x_mbus_int_init (struct yt921x_priv *priv,struct device_node *mnp);int yt921x_mbus_ext_init (struct yt921x_priv *priv,struct device_node *mnp); +int yt921x_intif_ext_write (struct yt921x_priv *priv,int port,int reg,u16 val); +int yt921x_intif_ext_read (struct yt921x_priv *priv,int port,int reg,u16 *valp);#endif intif_ext_* should be placed right after intif_* (if they are still in
mdio_bus).
okay.