* [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver
@ 2026-12-02 8:40 Kyle Switch
2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw)
To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms,
linux, netdev, linux-kernel
Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu,
xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang
changes in v18:
This series adds yt9224 driver support and includes several fixes and
cleanups for the yt92xx driver.
Patch 1 updates the commit message, improves the chip lookup series
failure logging to print the failure reason instead of a potentially
stale chip id, aligns the data types of ageing_time_max/ageing_time_min
with dsa_switch, and removes the YT92XX_MODE_YT922X definition (to be
re-added when the yt922x driver is introduced).
Patch 2 updates the commit message and adds max_port check logic.
Patch 3 updates the commit message.
Patch 4 adds the yt9224 driver dts.
Patch 5 improves the format comments for the YT9224 tag.
Patch 6 improves the commit message, adds BX100 handling, and adds
some code comments.
changes in v17:
1) Rebase.
changes in v16:
1) Add missing break in switch case to prevent fall-through in
yt922x_port_config()
changes in v15:
1) Revert the use of GENMASK_U16() to replace GENMASK(), so as to
facilitate adaptation to scenarios with more ports in the future.
2) Group functions with the same functionality together in mdio_bus.c.
3) Remove meaningless code comments.
4) Renaming parameters in yt922x_pcs_get_state().
5) Add neg_mode and advertising handle.
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 (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: use GENMASK_U32() for mbus phy_mask
dt-bindings: net: dsa: add Motorcomm YT9224
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x
.../bindings/net/dsa/motorcomm,yt9224.yaml | 142 +++++
MAINTAINERS | 5 +-
drivers/net/dsa/motorcomm/Kconfig | 7 +-
drivers/net/dsa/motorcomm/Makefile | 1 +
drivers/net/dsa/motorcomm/chip.c | 586 +++++++++++++++++-
drivers/net/dsa/motorcomm/chip.h | 103 +++
drivers/net/dsa/motorcomm/mdio_bus.c | 51 +-
drivers/net/dsa/motorcomm/mdio_bus.h | 4 +
drivers/net/dsa/motorcomm/pcs-922x.c | 300 +++++++++
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 | 133 ++++
14 files changed, 1325 insertions(+), 17 deletions(-)
create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml
create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c
create mode 100644 net/dsa/tag_yt922x.c
--
2.25.1
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch ` (4 subsequent siblings) 5 siblings, 2 replies; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Replace the hardcoded dsa_switch configuration in yt921x_mdio_probe() with a data-driven lookup by the chip ID and Major. This is a preparation step for supporting additional chips in the YT92xx family. Introduce struct yt92xx_series to describe per-chip properties (max_ports, num_lag_ids, ageing_time_min/max, dscp_prio_mapping_is_global, assisted_learning_on_cpu_port, switch_ops and mac_ops), and populate a yt92xx_series_table[] indexed by enum yt92xx_mode. yt92xx_register_switch() reads YT921X_CHIP_ID, extracts the major revision, looks up the matching series and fills in ds->ops, ds->phylink_mac_ops and the remaining dsa_switch fields from it. The table currently contains a single YT921x entry covering the YT9215 and YT9218 majors, so behaviour is unchanged. Store the matched series in yt921x_priv for later use. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- drivers/net/dsa/motorcomm/chip.c | 74 ++++++++++++++++++++++++++++---- drivers/net/dsa/motorcomm/chip.h | 19 ++++++++ 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 82f364986aeb..197dadb1046a 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -2699,6 +2699,68 @@ 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 = 1U * YT921X_AGEING_TIME_UNIT, + .ageing_time_max = U16_MAX * YT921X_AGEING_TIME_UNIT, + .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, "Failed to read Chip ID with errcode: %d\n", res); + return res; + } + + major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid); + series = yt92xx_series_lookup(major); + if (!series) { + dev_err(dev, "Unknown Chip ID: 0x%x, or unknown Major: 0x%x\n", + chipid, major); + 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); @@ -2741,6 +2803,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_obj(dev, *priv); if (!priv) @@ -2767,15 +2830,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); diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index fc315f1d8f87..b58b47883b91 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -18,6 +18,7 @@ #define YT921X_SMI_READ YT921X_SMI_RW #define YT921X_SWITCHID_NUM 4 +#define YT921X_AGEING_TIME_UNIT 5000U #define YT921X_RST 0x80000 #define YT921X_RST_HW BIT(31) @@ -503,9 +504,27 @@ 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_MAX, +}; + +struct yt92xx_series { + const char *name; + unsigned int max_ports; + unsigned int num_lag_ids; + u32 ageing_time_min; + u32 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; -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid 2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch @ 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 1 sibling, 0 replies; 17+ messages in thread From: sashiko-bot @ 2026-12-03 8:40 UTC (permalink / raw) To: Kyle Switch; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: dsa: motorcomm: chip ID read before SMI reset in yt92xx_register_switch() -- commit 4dd56147d8289334bbc07f03f99e9d097c16b21b Author: Kyle Switch <kyle.switch@motor-comm.com> net: dsa: motorcomm: initialize dsa_switch based on chipid This commit replaces the hardcoded dsa_switch initialization in yt921x_mdio_probe() with a lookup table indexed by the chip's major ID read from YT921X_CHIP_ID. > diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c > index 82f364986aebd..197dadb1046a4 100644 > --- a/drivers/net/dsa/motorcomm/chip.c > +++ b/drivers/net/dsa/motorcomm/chip.c > @@ -2699,6 +2699,68 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { [ ... ] > +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, "Failed to read Chip ID with errcode: %d\n", res); > + return res; > + } > + > + major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid); > + series = yt92xx_series_lookup(major); > + if (!series) { > + dev_err(dev, "Unknown Chip ID: 0x%x, or unknown Major: 0x%x\n", > + chipid, major); > + return -ENODEV; > + } [Severity: Medium] Does reading YT921X_CHIP_ID here before yt921x_reg_mdio_reset() break recovery when the 4-frame SMI slave state machine is out of phase at probe time? Previously, the first register access happened in yt921x_dsa_setup() -> yt921x_chip_reset(), right after yt921x_reg_mdio_reset() realigned the SMI state machine (added in bc686737f555 ("net: dsa: motorcomm: Resync SMI slave before register access")). With yt92xx_register_switch() running in yt921x_mdio_probe() before dsa_register_switch(), a misaligned SMI bus causes yt921x_reg_read() to return the 0xdeaddead sentinel (or a stale address), so yt92xx_series_lookup() fails with -ENODEV before yt921x_chip_reset() is ever reached. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202084022.3716891-1-kyle.switch@motor-comm.com?part=1 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid 2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch 2026-12-03 8:40 ` sashiko-bot @ 2026-12-03 8:57 ` netdev-bot+sashiko 1 sibling, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 2 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] yt92xx_register_switch() in drivers/net/dsa/motorcomm/chip.c is called from yt921x_mdio_probe(). - [Low] The commit message promises a "data-driven lookup by the chip ID", but yt92xx_series_lookup() in drivers/net/dsa/motorcomm/chip.c… - [Low] The patch adds YT921X_AGEING_TIME_UNIT (5000U) in chip.h and uses it to compute the advertised ds->ageing_time_min/max in… -- net: dsa: motorcomm: initialize dsa_switch based on chipid This commit replaces the hardcoded dsa_switch setup in yt921x_mdio_probe() with a lookup on the major revision read from YT921X_CHIP_ID. It adds struct yt92xx_series and a yt92xx_series_table[] with a single YT921x entry. The matched series is stored in yt921x_priv. > diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c > index 82f364986aebd..197dadb1046a4 100644 > --- a/drivers/net/dsa/motorcomm/chip.c > +++ b/drivers/net/dsa/motorcomm/chip.c > @@ -2699,6 +2699,68 @@ 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 = 1U * YT921X_AGEING_TIME_UNIT, > + .ageing_time_max = U16_MAX * YT921X_AGEING_TIME_UNIT, [Severity: Low] This isn't a bug, but the advertised ageing range now uses the new YT921X_AGEING_TIME_UNIT. The function that programs the register still uses a literal: drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_set_ageing_time() { ... /* AGEING reg is set in 5s step */ ctrl = clamp(msecs / 5000, 1, U16_MAX); ... } Should yt921x_dsa_set_ageing_time() use YT921X_AGEING_TIME_UNIT, or the series data? Then the range DSA validates against and the value written to YT921X_AGEING would come from one definition. Later in the series, YT922X_AGEING_TIME_UNIT is added with a value of 6000U. The YT922x ops don't install .set_ageing_time today, so nothing is mismatched yet. The two values could drift apart if the op were ever shared. > + .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; > +} [Severity: Low] The commit message describes this as: "a data-driven lookup by the chip ID and Major" However, yt92xx_series_lookup() is a hardcoded if-chain over the majors. The supported majors are already listed in yt921x_infos[]. During .setup, yt921x_chip_detect() reads YT921X_CHIP_ID again and matches it against that table. Isn't this a second copy of the same list? If a major is added to one list and not the other, probe in yt92xx_register_switch() and setup in yt921x_chip_detect() would disagree about whether the chip is supported. The later patch "net: dsa: motorcomm: Add support for Motorcomm YT922x" already has to update both places for YT9224_MAJOR. Would it be simpler to add a series pointer to each yt921x_info entry and do a single detection pass? > + > +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); [Severity: Medium] Is it safe to read YT921X_CHIP_ID here before the SMI state machine has been realigned? This is now the first register access to the switch, and nothing calls yt921x_reg_mdio_reset() before it. The comment above yt921x_reg_mdio_reset() describes this ordering as the problem the reset was added to solve: * An SMI register access is 4 MDIO frames. An interrupted access leaves the * machine in an unknown state, and every following access fails or acts on a * stale address. ... * Furthermore, the driver verifies the chip id before * firing the reset, so the reset can never be triggered reliably. yt921x_reg_mdio_read() only checks MDIO bus return codes. The FSM can be left misaligned, for example by an interrupted access from a bootloader, a kexec, or a previous driver instance. In that case the read still succeeds, but returns 0xdeaddead or stale data. For example, starting in DHw: DHw --awr--> AH --awr--> ALr --dr--> 0xdead --dr--> 0xdead The major then comes out as 0xdead, yt92xx_series_lookup() returns NULL, and probe fails: yt921x_mdio_probe() yt92xx_register_switch() yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid) /* returns 0 */ yt92xx_series_lookup(0xdead) /* NULL */ return -ENODEV; This happens before dsa_register_switch(), so .setup never runs and yt921x_chip_reset() never gets to realign the FSM: drivers/net/dsa/motorcomm/chip.c:yt921x_chip_reset() { ... res = yt921x_reg_mdio_reset(priv->reg_ctx); ... res = yt921x_chip_detect(priv); ... } Probe is not retried after -ENODEV. The switch ports stay unavailable until the driver is manually unbound and rebound. Before this patch, probe did no register access, so the realign always ran first. The later YT922x support patch keeps the same read in yt92xx_register_switch(). Would it work to call yt921x_reg_mdio_reset(priv->reg_ctx) under reg_lock before this read? Another option is to pick the series from the OF compatible and leave the chip ID check to yt921x_chip_reset(), after the realign. > + if (res) { > + dev_err(dev, "Failed to read Chip ID with errcode: %d\n", res); > + return res; > + } > + > + major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid); > + series = yt92xx_series_lookup(major); > + if (!series) { > + dev_err(dev, "Unknown Chip ID: 0x%x, or unknown Major: 0x%x\n", > + chipid, major); > + return -ENODEV; > + } [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch 2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch ` (3 subsequent siblings) 5 siblings, 2 replies; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Replace the hardcoded YT921X_PORT_NUM macro with the per-series max_ports field in port validation and in the internal mii_bus phy_mask setup. This removes family-specific constants from the common code path and simplifies adding new switch families with different port counts. Validate max_ports against the size of priv->ports (and the u32 width of phy_mask) before using it in GENMASK(). No functional change for existing YT921X devices, as their max_ports equals YT921X_PORT_NUM. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- drivers/net/dsa/motorcomm/mdio_bus.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index a4062e6b0f00..a06e2cc94a3e 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -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); @@ -155,6 +155,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 = mdiobus_alloc(); @@ -167,7 +168,12 @@ 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; + if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { + dev_err(dev, "Invalid max_ports: %u\n", max_ports); + return -EINVAL; + } + mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); res = of_mdiobus_register(mbus, mnp); if (res) { -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking 2026-12-02 8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch @ 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 1 sibling, 0 replies; 17+ messages in thread From: sashiko-bot @ 2026-12-03 8:40 UTC (permalink / raw) To: Kyle Switch; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: dsa: motorcomm: leak of struct mii_bus in yt921x_mbus_int_init() -- commit 8074bb765350f7aada8a9ccc2903eb46cbd7f38d Author: Kyle Switch <kyle.switch@motor-comm.com> net: dsa: motorcomm: use max_ports in series for port bounds checking This commit replaces the hardcoded YT921X_PORT_NUM constant in internal MDIO bus operations and setup with the per-series max_ports field, and validates max_ports before computing mbus->phy_mask. > diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c > index a4062e6b0f000..a06e2cc94a3e2 100644 > --- a/drivers/net/dsa/motorcomm/mdio_bus.c > +++ b/drivers/net/dsa/motorcomm/mdio_bus.c [ ... ] > @@ -155,6 +155,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 = mdiobus_alloc(); > @@ -167,7 +168,12 @@ 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; > + if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { > + dev_err(dev, "Invalid max_ports: %u\n", max_ports); > + return -EINVAL; > + } [Severity: Medium] Does this error path leak mbus? mbus was allocated with mdiobus_alloc() above (not devm_mdiobus_alloc()), so returning -EINVAL without calling mdiobus_free(mbus) or validating max_ports before mdiobus_alloc() leaks the struct mii_bus. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202084022.3716891-1-kyle.switch@motor-comm.com?part=2 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking 2026-12-02 8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch 2026-12-03 8:40 ` sashiko-bot @ 2026-12-03 8:57 ` netdev-bot+sashiko 1 sibling, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · 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). - [Medium] yt921x_mbus_int_init() in drivers/net/dsa/motorcomm/mdio_bus.c leaks the mii_bus on the new max_ports error path. - [Low] The commit message says the patch will "Validate max_ports against the size of priv->ports (and the u32 width of phy_mask) before… -- net: dsa: motorcomm: use max_ports in series for port bounds checking This commit replaces the hardcoded YT921X_PORT_NUM with the per-series max_ports field. The field is now used in the internal MDIO bus read and write bounds checks and in the phy_mask setup in yt921x_mbus_int_init(). It also adds a validation of max_ports before it is used in GENMASK(). > Validate max_ports against the size of priv->ports (and the u32 > width of phy_mask) before using it in GENMASK(). [Severity: Low] Does the code in yt921x_mbus_int_init() actually check the u32 width of phy_mask? The only check is: if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { Nothing compares max_ports against 32 or BITS_PER_TYPE(u32). There is also no static_assert() or BUILD_BUG_ON() that ties ARRAY_SIZE(priv->ports) to the width of mbus->phy_mask. The u32 bound only holds because struct yt921x_priv still declares: struct yt921x_port ports[YT921X_PORT_NUM]; If priv->ports ever grew past 32 entries, GENMASK(max_ports - 1, 0) would get an out-of-range shift that this check would not catch. The commit message also says this "removes family-specific constants from the common code path". The new bound is still YT921X_PORT_NUM through ARRAY_SIZE(priv->ports), so a family with more than 11 ports would be rejected rather than supported. Could the message be reworded, or an explicit check be added for the u32 width? > diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c > index a4062e6b0f000..a06e2cc94a3e2 100644 > --- a/drivers/net/dsa/motorcomm/mdio_bus.c > +++ b/drivers/net/dsa/motorcomm/mdio_bus.c [ ... ] > @@ -155,6 +155,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 = mdiobus_alloc(); > @@ -167,7 +168,12 @@ 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; > + if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { > + dev_err(dev, "Invalid max_ports: %u\n", max_ports); > + return -EINVAL; ^^^^ [Severity: Medium] Does this early return leak the mii_bus allocated by mdiobus_alloc() just above? mdiobus_alloc() is not devm-managed. priv->mbus_int is only set on success, so the caller has no pointer it could free: drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_setup() { ... res = yt921x_mbus_int_init(priv, child); of_node_put(child); if (res) return res; ... } The of_mdiobus_register() failure path later in the same function does call mdiobus_free(mbus) before returning. The leak is also still there after the later patch in this series, "net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask". That patch only changes the phy_mask line. Could the max_ports check be moved before mdiobus_alloc()? Alternatively, mdiobus_free(mbus) could be called before returning -EINVAL. > + } > + mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); > > res = of_mdiobus_register(mbus, mnp); > if (res) { -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch 2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch 2026-12-02 8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch ` (2 subsequent siblings) 5 siblings, 1 reply; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang mbus->phy_mask is a u32, but the mask was built with GENMASK(), which has type unsigned long, requiring an explicit (u32) cast to avoid a truncation warning. Use GENMASK_U32() instead, which yields a u32 and makes the intended 32-bit width explicit. The cast can then be dropped. GENMASK_U32() also lets the compiler reject out-of-range masks at build time. No functional change. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- drivers/net/dsa/motorcomm/mdio_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index a06e2cc94a3e..94087c9962cc 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -173,7 +173,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) dev_err(dev, "Invalid max_ports: %u\n", max_ports); return -EINVAL; } - mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); + mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0); res = of_mdiobus_register(mbus, mnp); if (res) { -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask 2026-12-02 8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch @ 2026-12-03 8:57 ` netdev-bot+sashiko 0 siblings, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang 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 of "net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask" says "GENMASK_U32() also lets the compiler reject out-… - [Low] yt921x_mbus_int_init() (drivers/net/dsa/motorcomm/mdio_bus.c) leaks the mii_bus on the invalid-max_ports error path. -- net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask This commit changes how yt921x_mbus_int_init() builds the internal MDIO bus phy_mask. It now uses GENMASK_U32() instead of a (u32) cast of GENMASK() and drops the explicit cast. It is described as no functional change. > GENMASK_U32() also lets the compiler reject out-of-range masks at build > time. [Severity: Low] Does this hold for the call site changed here? In yt921x_mbus_int_init() the high bit is max_ports - 1, and max_ports is read at runtime: max_ports = priv->series->max_ports; GENMASK_U32() goes through GENMASK_TYPE(), whose input check is: include/linux/bits.h: #define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h))) const_true() is 0 for non-constant expressions. -Wshift-count-overflow also only fires for constant shift counts. So no build-time check applies here. The only bound on the shift is the runtime check: if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { This works today only because YT921X_PORT_NUM is 11. Nothing ties ARRAY_SIZE(priv->ports) to BITS_PER_TYPE(u32). If ports[] ever grew past 32 entries, the shift inside GENMASK_TYPE() would get a negative count, and the compiler would not warn. The earlier commit "net: dsa: motorcomm: use max_ports in series for port bounds checking" has a similar problem. It says it validates "the u32 width of phy_mask", but it only compares against ARRAY_SIZE(priv->ports). Could this sentence be dropped? Alternatively, adding BUILD_BUG_ON(ARRAY_SIZE(priv->ports) > BITS_PER_TYPE(u32)) would make the claim true. The code change itself looks correct for max_ports in 1..11. > diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c > index a06e2cc94a3e2..94087c9962cca 100644 > --- a/drivers/net/dsa/motorcomm/mdio_bus.c > +++ b/drivers/net/dsa/motorcomm/mdio_bus.c > @@ -173,7 +173,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) > dev_err(dev, "Invalid max_ports: %u\n", max_ports); > return -EINVAL; > } [Severity: Low] Does this return leak the mii_bus? Earlier in yt921x_mbus_int_init() the bus is allocated: mbus = mdiobus_alloc(); if (!mbus) return -ENOMEM; The return -EINVAL above does not call mdiobus_free(mbus). mbus has not been stored in priv->mbus_int yet, so yt921x_mbus_int_cleanup() cannot free it either. The of_mdiobus_register() failure path just below does call mdiobus_free(). The current yt92xx_series_table entries cannot reach this path, since max_ports values of 11 and 9 both pass the check. The check came from the earlier commit "net: dsa: motorcomm: use max_ports in series for port bounds checking" in this series, and the leak is still there at the end of the series. Could the max_ports check move before mdiobus_alloc()? Calling mdiobus_free(mbus) before returning -EINVAL would also work. > - mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); > + mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0); [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch ` (2 preceding siblings ...) 2026-12-02 8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-02 22:58 ` Rob Herring (Arm) ` (2 more replies) 2026-12-02 8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch 2026-12-02 8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch 5 siblings, 3 replies; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Add a device tree binding for the Motorcomm YT9224, a member of the YT922x Ethernet switch family. It has 4 internal GbE PHYs on ports 4-7 and 2 SerDes ports on ports 0 and 8. Any port can be used as the CPU port. The YT9224 port layout differs from the YT921x family described by motorcomm,yt921x.yaml (internal PHYs on ports 0-7, SerDes on 8-9), so give it its own binding instead of extending the existing one. This also avoids the dt_binding_check failure caused by yt921x.yaml declaring compatible as a const for motorcomm,yt9215. Also add the new binding file to the Motorcomm YT921x switch driver MAINTAINERS entry so that it is covered by get_maintainer.pl. Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- .../bindings/net/dsa/motorcomm,yt9224.yaml | 142 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 143 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml diff --git a/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml new file mode 100644 index 000000000000..01b61b47d372 --- /dev/null +++ b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml @@ -0,0 +1,142 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/motorcomm,yt9224.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Motorcomm YT9224 Ethernet switch + +maintainers: + - Kyle Switch <kyle.switch@motor-comm.com> + +description: | + The Motorcomm YT9224 is a member of the YT922x Ethernet switch family, + with 4 internal GbE PHYs (Port 4-7) and 2 SerDes ports (Port 0 and 8). + + Any port can be used as the CPU port. + +properties: + compatible: + const: motorcomm,yt9224 + + reg: + enum: [0x0, 0x1d] + + mdio: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: + Internal MDIO bus for the internal GbE PHYs. PHY 4-7 are used for + Port 4-7 respectively. + + mdio-external: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: + External MDIO bus to access external components. External PHYs for + the SerDes ports (Port 0 and 8) are expected to be connected to the + external MDIO bus, but that is not a hard limitation from the chip. + +required: + - compatible + - reg + +allOf: + - $ref: dsa.yaml#/$defs/ethernet-ports + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/leds/common.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + switch@1d { + compatible = "motorcomm,yt9224"; + /* default 0x1d, alternate 0x0 */ + reg = <0x1d>; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + sw_phy4: phy@4 { + reg = <0x4>; + }; + + sw_phy5: phy@5 { + reg = <0x5>; + }; + + sw_phy6: phy@6 { + reg = <0x6>; + }; + + sw_phy7: phy@7 { + reg = <0x7>; + }; + }; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + /* SerDes port 0 */ + ethernet-port@0 { + reg = <0>; + label = "wan"; + phy-mode = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + }; + }; + + /* Internal PHY ports 4-7 */ + ethernet-port@4 { + reg = <4>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&sw_phy4>; + }; + + ethernet-port@5 { + reg = <5>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&sw_phy5>; + }; + + ethernet-port@6 { + reg = <6>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&sw_phy6>; + }; + + ethernet-port@7 { + reg = <7>; + label = "lan4"; + phy-mode = "internal"; + phy-handle = <&sw_phy7>; + }; + + /* SerDes port 8, CPU port */ + ethernet-port@8 { + reg = <8>; + phy-mode = "usxgmii"; + ethernet = <ð0>; + + fixed-link { + speed = <5000>; + full-duplex; + }; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 9336fa93ce38..864777388be6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18937,6 +18937,7 @@ M: David Yang <mmyangfl@gmail.com> L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml +F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml F: Documentation/networking/devlink/yt921x.rst F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch @ 2026-12-02 22:58 ` Rob Herring (Arm) 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2 siblings, 0 replies; 17+ messages in thread From: Rob Herring (Arm) @ 2026-12-02 22:58 UTC (permalink / raw) To: Kyle Switch Cc: wei.zhang, netdev, conor+dt, linux-kernel, mmyangfl, xiaolin.xu, sijia.huang, andrew, krzk+dt, pabeni, david.laight.linux, devicetree, jianmin.wang, horms, linux, olteanv, kuba, davem, ming.xu, edumazet On Wed, 02 Dec 2026 16:40:20 +0800, Kyle Switch wrote: > Add a device tree binding for the Motorcomm YT9224, a member of the > YT922x Ethernet switch family. It has 4 internal GbE PHYs on ports 4-7 > and 2 SerDes ports on ports 0 and 8. Any port can be used as the CPU > port. > > The YT9224 port layout differs from the YT921x family described by > motorcomm,yt921x.yaml (internal PHYs on ports 0-7, SerDes on 8-9), so > give it its own binding instead of extending the existing one. This > also avoids the dt_binding_check failure caused by yt921x.yaml > declaring compatible as a const for motorcomm,yt9215. > > Also add the new binding file to the Motorcomm YT921x switch driver > MAINTAINERS entry so that it is covered by get_maintainer.pl. > > Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> > --- > .../bindings/net/dsa/motorcomm,yt9224.yaml | 142 ++++++++++++++++++ > MAINTAINERS | 1 + > 2 files changed, 143 insertions(+) > create mode 100644 Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml > Reviewed-by: Rob Herring (Arm) <robh@kernel.org> ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch 2026-12-02 22:58 ` Rob Herring (Arm) @ 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2 siblings, 0 replies; 17+ messages in thread From: sashiko-bot @ 2026-12-03 8:40 UTC (permalink / raw) To: Kyle Switch; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] dt-bindings: net: dsa: motorcomm,yt9224.yaml duplicates motorcomm,yt921x.yaml - [Low] dt-bindings: net: dsa: missing reset-gpios and unused includes in yt9224 -- commit 827082185ba0054b4f8cd0011f638e983d5ab730 Author: Kyle Switch <kyle.switch@motor-comm.com> dt-bindings: net: dsa: add Motorcomm YT9224 This commit adds a new Device Tree binding schema for the Motorcomm YT9224 Ethernet switch and adds the schema file to MAINTAINERS. > diff --git a/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml > new file mode 100644 > index 0000000000000..01b61b47d3726 > --- /dev/null > +++ b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml > @@ -0,0 +1,142 @@ > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/net/dsa/motorcomm,yt9224.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: Motorcomm YT9224 Ethernet switch > + > +maintainers: > + - Kyle Switch <kyle.switch@motor-comm.com> > + > +description: | > + The Motorcomm YT9224 is a member of the YT922x Ethernet switch family, > + with 4 internal GbE PHYs (Port 4-7) and 2 SerDes ports (Port 0 and 8). > + > + Any port can be used as the CPU port. > + > +properties: > + compatible: > + const: motorcomm,yt9224 > + > + reg: > + enum: [0x0, 0x1d] [Severity: Low] Can motorcomm,yt9224 be added to an enum under compatible in motorcomm,yt921x.yaml instead of duplicating the binding? Neither schema enforces port or PHY numbering rules beyond referencing dsa.yaml#/$defs/ethernet-ports and /schemas/net/mdio.yaml#, and motorcomm,yt921x.yaml already documents several switch variants with different port layouts that are handled by the same driver. > + mdio: > + $ref: /schemas/net/mdio.yaml# > + unevaluatedProperties: false > + description: > + Internal MDIO bus for the internal GbE PHYs. PHY 4-7 are used for > + Port 4-7 respectively. > + > + mdio-external: > + $ref: /schemas/net/mdio.yaml# > + unevaluatedProperties: false > + description: > + External MDIO bus to access external components. External PHYs for > + the SerDes ports (Port 0 and 8) are expected to be connected to the > + external MDIO bus, but that is not a hard limitation from the chip. > + > +required: > + - compatible > + - reg > + > +allOf: > + - $ref: dsa.yaml#/$defs/ethernet-ports > + > +unevaluatedProperties: false > + > +examples: > + - | > + #include <dt-bindings/gpio/gpio.h> > + #include <dt-bindings/leds/common.h> [Severity: Low] If this remains a separate schema, should properties include reset-gpios (as in motorcomm,yt921x.yaml)? Because unevaluatedProperties is false, omitting reset-gpios causes dtbs_check to reject switch nodes that specify a hardware reset line for the MDIO bus core. Also, dt-bindings/gpio/gpio.h and dt-bindings/leds/common.h are unused in the example below. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261202084022.3716891-1-kyle.switch@motor-comm.com?part=4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch 2026-12-02 22:58 ` Rob Herring (Arm) 2026-12-03 8:40 ` sashiko-bot @ 2026-12-03 8:57 ` netdev-bot+sashiko 2 siblings, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang 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's reasons for creating a separate motorcomm,yt9224.yaml do not hold up, and the new file is a near-copy… - [Low] The new motorcomm,yt9224.yaml drops the `reset-gpios` property that its source binding motorcomm,yt921x.yaml defines (`reset-gpios:… -- dt-bindings: net: dsa: add Motorcomm YT9224 This commit adds a standalone device tree binding, motorcomm,yt9224.yaml, for the Motorcomm YT9224 switch. The chip has internal PHYs on ports 4-7 and SerDes on ports 0 and 8. The commit also adds the new file to the existing YT921x MAINTAINERS entry. > The YT9224 port layout differs from the YT921x family described by > motorcomm,yt921x.yaml (internal PHYs on ports 0-7, SerDes on 8-9), so > give it its own binding instead of extending the existing one. This > also avoids the dt_binding_check failure caused by yt921x.yaml > declaring compatible as a const for motorcomm,yt9215. [Severity: Low] Is this the right reason for a separate schema? Neither schema describes a port layout. Both only reference dsa.yaml#/$defs/ethernet-ports. Neither has patternProperties or reg limits on the ethernet-port nodes. motorcomm,yt921x.yaml already covers family members with quite different port maps under one compatible. YT9213NB has PHYs on ports 1/3 and a GMAC only on port 9. YT9218N has PHYs on ports 0-7 and no GMAC. The driver also picks the port layout at runtime by chip ID, through the yt921x_info table in drivers/net/dsa/motorcomm/chip.c, rather than from DT: "YT9224", YT9224_MAJOR, 0, 0, GENMASK(7, 4), 0, BIT(8) | BIT(0), On the dt_binding_check point, a new compatible is normally added by changing this line in motorcomm,yt921x.yaml into an enum: const: motorcomm,yt9215 Apart from that, the new file matches motorcomm,yt921x.yaml: - the same reg enum - the same mdio and mdio-external nodes and descriptions - the same allOf reference - unevaluatedProperties: false - the same example layout The only differences are the compatible, the description text and the missing reset-gpios. Could motorcomm,yt9224 be added to motorcomm,yt921x.yaml instead? If not, could the commit message explain what the existing binding can't describe? > diff --git a/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml > new file mode 100644 > index 0000000000000..01b61b47d3726 > --- /dev/null > +++ b/Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml > @@ -0,0 +1,142 @@ [ ... ] > +properties: > + compatible: > + const: motorcomm,yt9224 > + > + reg: > + enum: [0x0, 0x1d] > + > + mdio: [ ... ] > +allOf: > + - $ref: dsa.yaml#/$defs/ethernet-ports > + > +unevaluatedProperties: false > + > +examples: > + - | > + #include <dt-bindings/gpio/gpio.h> > + #include <dt-bindings/leds/common.h> [Severity: Low] Was reset-gpios meant to be dropped from this schema? motorcomm,yt921x.yaml, which this file is based on, defines: reset-gpios: maxItems: 1 Its example also uses: reset-gpios = <&tlmm 39 GPIO_ACTIVE_LOW>; This schema has no reset-gpios, and dsa.yaml#/$defs/ethernet-ports doesn't add it either. With unevaluatedProperties: false, a board that wires the YT9224 reset pin to a SoC GPIO can't describe it without failing dt_binding_check and dtbs_check. The example still includes dt-bindings/gpio/gpio.h and dt-bindings/leds/common.h, but it doesn't use any GPIO or LED macro. This suggests reset-gpios was removed by accident. If the YT9224 has no reset input, could the commit message say so and the unused includes be removed? Otherwise, should reset-gpios be restored? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch ` (3 preceding siblings ...) 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch 5 siblings, 1 reply; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Add 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. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- MAINTAINERS | 2 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 ++ net/dsa/Makefile | 1 + net/dsa/tag_yt922x.c | 133 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 net/dsa/tag_yt922x.c diff --git a/MAINTAINERS b/MAINTAINERS index 864777388be6..cc9117ea56b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18934,6 +18934,7 @@ F: drivers/net/phy/motorcomm.c MOTORCOMM YT921X ETHERNET SWITCH DRIVER M: David Yang <mmyangfl@gmail.com> +M: Kyle Switch <kyle.switch@motor-comm.com> L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml @@ -18941,6 +18942,7 @@ F: Documentation/devicetree/bindings/net/dsa/motorcomm,yt9224.yaml F: Documentation/networking/devlink/yt921x.rst F: drivers/net/dsa/motorcomm/ F: net/dsa/tag_yt921x.c +F: net/dsa/tag_yt922x.c MOXA SMARTIO/INDUSTIO SERIAL CARD M: Jiri Slaby <jirislaby@kernel.org> diff --git a/include/net/dsa.h b/include/net/dsa.h index 09f3043d57f0..63ad6e6729be 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -63,6 +63,7 @@ struct tc_action; #define DSA_TAG_PROTO_MT7628_VALUE 35 #define DSA_TAG_PROTO_KS8995_VALUE 36 #define DSA_TAG_PROTO_LAN9645X_VALUE 37 +#define DSA_TAG_PROTO_YT922X_VALUE 38 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -103,6 +104,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_MT7628 = DSA_TAG_PROTO_MT7628_VALUE, DSA_TAG_PROTO_KS8995 = DSA_TAG_PROTO_KS8995_VALUE, DSA_TAG_PROTO_LAN9645X = DSA_TAG_PROTO_LAN9645X_VALUE, + DSA_TAG_PROTO_YT922X = DSA_TAG_PROTO_YT922X_VALUE, }; struct dsa_switch; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index bdeb60af764b..3baa56563a97 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -244,4 +244,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 diff --git a/net/dsa/Makefile b/net/dsa/Makefile index 3cd53124448d..ce53586c7eee 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -46,6 +46,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) diff --git a/net/dsa/tag_yt922x.c b/net/dsa/tag_yt922x.c new file mode 100644 index 000000000000..ee5d44df0dc7 --- /dev/null +++ b/net/dsa/tag_yt922x.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Motorcomm YT922x Switch Extended CPU Port Tagging + * + * Copyright (c) 2026 Kyle switch <kyle.switch@motor-comm.com> + * + */ + +/* + * To define the from cpu tag format 8 bytes. + * + * +----+----+-------+-----+----+--------- + * | DA | SA | TagET | Tag | ET | Payload ... + * +----+----+-------+-----+----+--------- + * 6 6 2 6 2 N + * + * To-CPU (RX) tag format, 8 bytes: + * + * tag[0]: TPID (default: 0x9988) + * tag[1]: VID lookup + * tag[2]: bit 5:2 - RX source port + * tag[3]: reserved (set to 0) + * + * From-CPU (TX) tag format, 8 bytes: + * + * tag[0]: TPID (default: 0x9988) + * tag[1]: + * bit 8:0 - Dst port mask (bit n maps to port n+1) + * bit 9 - Force Dst Port mask + * bit 12:10 - Inter priority + * bit 13 - Inter priority valid + * tag[2]: bit 15 - Dst port 0 + * tag[3]: reserved (set to 0) + * + */ + +#include <linux/etherdevice.h> + +#include "tag.h" + +#define YT922X_TAG_LEN 8 +#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) + +static struct sk_buff * +yt922x_tag_xmit(struct sk_buff *skb, struct net_device *netdev) +{ + unsigned long ports; + __be16 *tag; + u16 ctrl; + + skb_push(skb, YT922X_TAG_LEN); + dsa_alloc_etype_header(skb, YT922X_TAG_LEN); + tag = dsa_etype_header_pos_tx(skb); + + 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); + if (ports & BIT(0)) { + /* To fill in the case where the port index is 0 */ + ctrl = YT922X_TAG_PORTMASK_0; + tag[2] = htons(ctrl); + } else { + tag[2] = 0; + } + tag[3] = 0; + + return skb; +} + +static struct sk_buff * +yt922x_tag_rcv(struct sk_buff *skb, struct net_device *netdev) +{ + unsigned int port; + __be16 *tag; + u16 rx; + + if (unlikely(!pskb_may_pull(skb, YT922X_TAG_LEN))) { + kfree_skb(skb); + return NULL; + } + + tag = dsa_etype_header_pos_rx(skb); + + if (unlikely(tag[0] != htons(ETH_P_YT921X))) { + dev_warn_ratelimited(&netdev->dev, + "Unexpected EtherType 0x%04x\n", + ntohs(tag[0])); + kfree_skb(skb); + return NULL; + } + + /* Locate which port this is coming from */ + rx = ntohs(tag[2]); + port = FIELD_GET(YT922X_TAG_RX_PORT_M, rx); + skb->dev = dsa_conduit_find_user(netdev, 0, port); + if (unlikely(!skb->dev)) { + dev_warn_ratelimited(&netdev->dev, + "Couldn't decode source port %u\n", port); + kfree_skb(skb); + return NULL; + } + + /* Remove tag and update checksum */ + skb_pull_rcsum(skb, YT922X_TAG_LEN); + dsa_strip_etype_header(skb, YT922X_TAG_LEN); + + return skb; +} + +static const struct dsa_device_ops yt922x_netdev_ops = { + .name = YT922X_TAG_NAME, + .proto = DSA_TAG_PROTO_YT922X, + .xmit = yt922x_tag_xmit, + .rcv = yt922x_tag_rcv, + .needed_headroom = YT922X_TAG_LEN, +}; + +MODULE_DESCRIPTION("DSA tag driver for Motorcomm YT922x switches"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_YT922X, YT922X_TAG_NAME); + +module_dsa_tag_driver(yt922x_netdev_ops); -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags 2026-12-02 8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch @ 2026-12-03 8:57 ` netdev-bot+sashiko 0 siblings, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · 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). - [Medium] yt922x_tag_xmit() in net/dsa/tag_yt922x.c line 66 builds the TX tag with YT922X_TAG_PRIO(skb->priority). - [Low] The layout documentation in the header of net/dsa/tag_yt922x.c is mislabelled, and the commit message describes the MAINTAINERS change… -- net: dsa: tag_yt922x: add support for Motorcomm YT922x tags This adds a new DSA tag driver for Motorcomm YT922x switches. They use the same ETH_P_YT921X EtherType and 8-byte tag length as YT921x, but the tag layout is different. The patch also adds a DSA_TAG_PROTO_YT922X protocol value and a new maintainer to the Motorcomm YT921X MAINTAINERS entry. > diff --git a/net/dsa/tag_yt922x.c b/net/dsa/tag_yt922x.c > new file mode 100644 > index 0000000000000..ee5d44df0dc79 > --- /dev/null > +++ b/net/dsa/tag_yt922x.c > @@ -0,0 +1,133 @@ [ ... ] > +/* > + * To define the from cpu tag format 8 bytes. > + * > + * +----+----+-------+-----+----+--------- > + * | DA | SA | TagET | Tag | ET | Payload ... > + * +----+----+-------+-----+----+--------- > + * 6 6 2 6 2 N > + * > + * To-CPU (RX) tag format, 8 bytes: [Severity: Low] This isn't a bug, but is "from cpu tag format" the right label for this diagram? The DA | SA | TagET | Tag | ET layout covers both directions. The comment then describes the To-CPU (RX) and From-CPU (TX) layouts separately. Also, the commit message says: Update the co-maintainer for the Motorcomm DSA driver. The MAINTAINERS hunk doesn't update an existing entry. It adds a new "M: Kyle Switch" line to the MOTORCOMM YT921X ETHERNET SWITCH DRIVER section, and that line isn't related to the new tag driver. Could the commit message say that a maintainer is being added? [ ... ] > +#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) [ ... ] > + 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); [Severity: Medium] In yt922x_tag_xmit(), what happens when skb->priority is larger than 7? skb->priority is a runtime u32, so FIELD_PREP() does no range check here. It only shifts the value and masks it into GENMASK(12, 10), which wraps it modulo 8. For example, 8 becomes 0, 9 becomes 1, and a classid such as 0x10001 becomes 1. YT922X_TAG_PRIO() always sets YT922X_TAG_PRIO_EN, so the switch applies the wrapped value as the frame's internal priority. A frame given a high priority via SO_PRIORITY, tc skbedit or a VLAN egress QoS map could then be sent at the lowest hardware priority. This path is used once yt922x_dsa_get_tag_protocol() returns DSA_TAG_PROTO_YT922X in the follow-up patch "net: dsa: motorcomm: Add support for Motorcomm YT922x". Other taggers map the value and/or clamp it first. tag_lan9645x.c does: qos_class = netdev_get_num_tc(ndev) ? netdev_get_prio_tc_map(ndev, skb->priority) : skb->priority; qos_class = min_t(u32, qos_class, GENMASK(IFH_QOS_CLASS_SZ - 1, 0)); tag_ocelot.c also uses netdev_get_prio_tc_map(). Should yt922x_tag_xmit() map and clamp skb->priority in a similar way before building the tag? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch ` (4 preceding siblings ...) 2026-12-02 8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch @ 2026-12-02 8:40 ` Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko 5 siblings, 1 reply; 17+ messages in thread From: Kyle Switch @ 2026-12-02 8:40 UTC (permalink / raw) To: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel Cc: devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Add support for the Motorcomm YT922x family of Ethernet switches, which includes the YT9224 and YT9228. This patch only adds support for the YT9224; YT9228 is not supported yet. This adds basic support for a working DSA switch, including .port_setup, .setup, .phylink_get_caps and .get_tag_protocol. Alongside the YT9224-specific additions, this touches shared yt921x code, so the blast radius on the existing YT921x path is called out below. New functionality: - Add four dsa_switch_ops for the YT9224. - Implement a full phylink_mac_ops set (mac_config, mac_link_up, mac_link_down, mac_select_pcs). - Add a new PCS driver in pcs-922x.c supporting SGMII, 1000BASE-X, 2500BASE-X and USXGMII. - Add two MDIO helpers, yt921x_intif_ext_read() and yt921x_intif_ext_write(). Shared code changes (also used by the YT921x path): - Add YT921X_SPEED_5000 to the yt921x_speed enum and a SPEED_5000 case in ethtool_speed_to_yt921x(). - Add an early return for YT9224 in yt921x_chip_detect(), skipping the CHIP_MODE, EXTMODE. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Kyle Switch <kyle.switch@motor-comm.com> --- MAINTAINERS | 2 +- drivers/net/dsa/motorcomm/Kconfig | 7 +- drivers/net/dsa/motorcomm/Makefile | 1 + drivers/net/dsa/motorcomm/chip.c | 512 ++++++++++++++++++++++++++- drivers/net/dsa/motorcomm/chip.h | 84 +++++ drivers/net/dsa/motorcomm/mdio_bus.c | 39 ++ drivers/net/dsa/motorcomm/mdio_bus.h | 4 + drivers/net/dsa/motorcomm/pcs-922x.c | 300 ++++++++++++++++ drivers/net/dsa/motorcomm/pcs.h | 1 + 9 files changed, 944 insertions(+), 6 deletions(-) create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c diff --git a/MAINTAINERS b/MAINTAINERS index cc9117ea56b3..2fe7d7de8490 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18932,7 +18932,7 @@ S: Maintained F: Documentation/devicetree/bindings/net/motorcomm,yt8xxx.yaml F: drivers/net/phy/motorcomm.c -MOTORCOMM YT921X ETHERNET SWITCH DRIVER +MOTORCOMM YT921X AND YT922X ETHERNET SWITCH DRIVER M: David Yang <mmyangfl@gmail.com> M: Kyle Switch <kyle.switch@motor-comm.com> L: netdev@vger.kernel.org diff --git a/drivers/net/dsa/motorcomm/Kconfig b/drivers/net/dsa/motorcomm/Kconfig index 79cdd79a1fd2..648c49d6c527 100644 --- a/drivers/net/dsa/motorcomm/Kconfig +++ b/drivers/net/dsa/motorcomm/Kconfig @@ -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" diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile index 0b31d815ce43..733afff04ae7 100644 --- a/drivers/net/dsa/motorcomm/Makefile +++ b/drivers/net/dsa/motorcomm/Makefile @@ -5,6 +5,7 @@ yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o yt921x-objs += devlink.o yt921x-objs += mdio_bus.o yt921x-objs += mib.o +yt921x-objs += pcs-922x.o yt921x-objs += pcs-921x.o yt921x-objs += smi.o yt921x-objs += tc.o diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 197dadb1046a..2a684beac408 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Driver for Motorcomm YT921x Switch + * Driver for Motorcomm YT921x and YT922x Switch * * Should work on YT9213/YT9214/YT9215/YT9218, but only tested on YT9215+SGMII, * be sure to do your own checks before porting to another chip. @@ -77,6 +77,12 @@ static const struct yt921x_info yt921x_infos[] = { BIT(8) | BIT(9), BIT(8) | BIT(9), }, + { + "YT9224", YT9224_MAJOR, 0, 0, + GENMASK(7, 4), + 0, + BIT(8) | BIT(0), + }, {} }; @@ -2254,6 +2260,11 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds) yt921x_mbus_int_cleanup(priv); } +static bool yt921x_needs_extmode_check(u32 major) +{ + return (major == YT9224_MAJOR) ? false : true; +} + static int yt921x_chip_detect(struct yt921x_priv *priv) { struct device *dev = yt921x_priv_to_device(priv); @@ -2279,6 +2290,14 @@ static int yt921x_chip_detect(struct yt921x_priv *priv) return -ENODEV; } + if (!yt921x_needs_extmode_check(major)) { + dev_info(dev, + "Motorcomm %s ethernet switch, chipid: 0x%x\n", + info->name, chipid); + priv->info = info; + return 0; + } + res = yt921x_reg_read(priv, YT921X_CHIP_MODE, &mode); if (res) return res; @@ -2699,6 +2718,480 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { .setup = yt921x_dsa_setup, }; +static int yt922x_port_down(struct yt921x_priv *priv, int port) +{ + u32 mask; + int res; + + /* mac force down */ + mask = YT922X_PORT_LINK | YT922X_PORT_RX_MAC_EN | + YT922X_PORT_TX_MAC_EN | YT922X_PORT_LINK_AN; + res = yt921x_reg_clear_bits(priv, YT922X_PORTn_CTRL(port), mask); + if (res) + return res; + /* Need force op to make soft configuration effective */ + mask = YT922X_PORT_FORCE_OP; + res = yt921x_reg_set_bits(priv, YT922X_PORTn_CTRL(port), mask); + if (res) + return res; + + /* disable en_phy */ + res = yt921x_reg_clear_bits(priv, YT922X_EN_PHY_VALUE, BIT(port)); + if (res) + return res; + res = yt921x_reg_set_bits(priv, YT922X_EN_PHY_OVERWRITE, BIT(port)); + if (res) + return res; + + return 0; +} + +static void +yt922x_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, + phy_interface_t interface) +{ + struct dsa_port *dp = dsa_phylink_to_port(config); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + int port = dp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt922x_port_down(priv, port); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dp->ds->dev, "Failed to %s port %d: %i\n", "bring down", + port, res); +} + +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) +{ + struct yt921x_port *pp = &priv->ports[port]; + int ps = ethtool_speed_to_yt921x(speed); + u32 ctrl = 0; + u32 mask; + int res; + + if (ps == YT921X_SPEED_INVALID) + return -EINVAL; + + mask = YT922X_PORT_SPEED_M | YT922X_PORT_TX_MAC_EN | + YT922X_PORT_RX_MAC_EN | YT922X_PORT_TX_PAUSE | + YT922X_PORT_RX_PAUSE | YT922X_PORT_DUPLEX_FULL | + YT922X_PORT_LINK_AN | YT922X_PORT_CFG_RX_EN | + YT922X_PORT_CFG_TX_EN | YT922X_PORT_FC_AN | + YT922X_PORT_LINK; + + ctrl |= ps; + + if (duplex == DUPLEX_FULL) + ctrl |= YT922X_PORT_DUPLEX_FULL; + if (tx_pause) + ctrl |= YT922X_PORT_TX_PAUSE; + if (rx_pause) + ctrl |= YT922X_PORT_RX_PAUSE; + ctrl |= YT922X_PORT_RX_MAC_EN | YT922X_PORT_TX_MAC_EN | + YT922X_PORT_CFG_TX_EN | YT922X_PORT_CFG_RX_EN; + + /* + * Self-negotiation: the LINK/AN bits in ctrl are set based to inband. + * Forced mode: set LINK, keep the AN bit at 0 and clear it via the mask + */ + if (pp->serdes && pp->inband) + ctrl |= (YT922X_PORT_FC_AN | YT922X_PORT_LINK_AN); + else + ctrl |= YT922X_PORT_LINK; + + res = yt921x_reg_update_bits(priv, YT922X_PORTn_CTRL(port), mask, ctrl); + 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; + + /* 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; +} + +static void +yt922x_phylink_mac_link_up(struct phylink_config *config, + struct phy_device *phydev, unsigned int mode, + phy_interface_t interface, int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct dsa_port *dp = dsa_phylink_to_port(config); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + int port = dp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt922x_port_up(priv, port, mode, interface, speed, duplex, + tx_pause, rx_pause); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dp->ds->dev, "Failed to %s port %d: %i\n", "bring up", + port, res); +} + +static int +yt922x_port_config(struct yt921x_priv *priv, int port, unsigned int mode, + phy_interface_t interface) +{ + struct device *dev = yt921x_priv_to_device(priv); + const struct yt921x_info *info = priv->info; + struct yt921x_port *pp = &priv->ports[port]; + + if (BIT(port) & info->internal_mask) { + if (interface != PHY_INTERFACE_MODE_INTERNAL) + goto err; + return 0; + } + + switch (interface) { + /* SERDES */ + case PHY_INTERFACE_MODE_SGMII: + case PHY_INTERFACE_MODE_100BASEX: + case PHY_INTERFACE_MODE_1000BASEX: + case PHY_INTERFACE_MODE_2500BASEX: + case PHY_INTERFACE_MODE_USXGMII: + if (!(BIT(port) & info->serdes_mask)) + goto err; + pp->serdes = true; + break; + default: + goto err; + } + + return 0; + +err: + dev_err(dev, "Wrong mode %d on port %d\n", interface, port); + return -EINVAL; +} + +static void +yt922x_phylink_mac_config(struct phylink_config *config, unsigned int mode, + const struct phylink_link_state *state) +{ + struct dsa_port *dp = dsa_phylink_to_port(config); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + int port = dp->index; + int res; + + mutex_lock(&priv->reg_lock); + res = yt922x_port_config(priv, port, mode, state->interface); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dp->ds->dev, "Failed to %s port %d: %i\n", "config", + port, res); +} + +static struct phylink_pcs * +yt922x_phylink_mac_select_pcs(struct phylink_config *config, + phy_interface_t interface) +{ + struct dsa_port *dp = dsa_phylink_to_port(config); + struct yt921x_priv *priv = dsa_to_yt921x_priv(dp->ds); + const struct yt921x_info *info = priv->info; + int port = dp->index; + + if (!(BIT(port) & info->serdes_mask)) + return NULL; + + switch (interface) { + case PHY_INTERFACE_MODE_SGMII: + case PHY_INTERFACE_MODE_100BASEX: + case PHY_INTERFACE_MODE_1000BASEX: + case PHY_INTERFACE_MODE_2500BASEX: + case PHY_INTERFACE_MODE_USXGMII: + return &priv->ports[port].pcs; + default: + return NULL; + } +} + +static const struct phylink_mac_ops yt922x_phylink_mac_ops = { + .mac_select_pcs = yt922x_phylink_mac_select_pcs, + .mac_link_down = yt922x_phylink_mac_link_down, + .mac_link_up = yt922x_phylink_mac_link_up, + .mac_config = yt922x_phylink_mac_config, +}; + +static enum dsa_tag_protocol +yt922x_dsa_get_tag_protocol(struct dsa_switch *ds, int port, + enum dsa_tag_protocol m) +{ + return DSA_TAG_PROTO_YT922X; +} + +static void +yt922x_dsa_phylink_get_caps(struct dsa_switch *ds, int port, + struct phylink_config *config) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + const struct yt921x_info *info = priv->info; + + 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->serdes_mask & BIT(port)) { + /* serdes */ + __set_bit(PHY_INTERFACE_MODE_SGMII, + config->supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, + config->supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + config->supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, + config->supported_interfaces); + config->mac_capabilities |= MAC_2500FD; + __set_bit(PHY_INTERFACE_MODE_USXGMII, + config->supported_interfaces); + config->mac_capabilities |= MAC_5000FD; + config->mac_capabilities |= MAC_10000FD; + } +} + +static int yt922x_port_setup(struct yt921x_priv *priv, int port) +{ + struct dsa_switch *ds = &priv->ds; + u32 mask; + u32 ctrl; + int res; + + /* enable user port isolation and disable fdb learning */ + ctrl = ~priv->cpu_ports_mask; + res = yt921x_reg_write(priv, YT922X_PORTn_ISOLATION(port), ctrl); + if (res) + return res; + + mask = YT922X_PORT_LEARN_DIS; + res = yt921x_reg_set_bits(priv, YT922X_PORTn_LEARN(port), mask); + if (res) + return res; + + if (dsa_is_cpu_port(ds, port)) { + ctrl = ~(u32)0; + res = yt921x_reg_write(priv, YT922X_PORTn_ISOLATION(port), + ctrl); + if (res) + return res; + } + + return 0; +} + +static int yt922x_dsa_port_setup(struct dsa_switch *ds, int port) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + int res; + + mutex_lock(&priv->reg_lock); + res = yt922x_port_setup(priv, port); + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int yt922x_cpu_tag_mode_set_8b(struct yt921x_priv *priv) +{ + u32 val; + u32 val1; + int res; + + /* cpu tag mode set to 8b */ + res = yt921x_reg_read(priv, YT922X_CPU_TAG_RX_CTRL, &val); + if (res) + return res; + res = yt921x_reg_read(priv, YT922X_CPU_TAG_TX_CTRL, &val1); + if (res) + return res; + val &= ~YT922X_CPU_TAG_RX_MODE; + val1 &= ~YT922X_CPU_TAG_TX_MODE; + val1 &= ~YT922X_CPU_TAG_TX_TYPE; + res = yt921x_reg_write(priv, YT922X_CPU_TAG_RX_CTRL, val); + if (res) + return res; + res = yt921x_reg_write(priv, YT922X_CPU_TAG_TX_CTRL, val1); + if (res) + return res; + + return 0; +} + +static int yt922x_cpu_port_set(struct yt921x_priv *priv) +{ + struct dsa_switch *ds = &priv->ds; + u32 ctrl; + int res; + + /* cpu tag mode */ + res = yt922x_cpu_tag_mode_set_8b(priv); + if (res) + return res; + + /* Enable DSA */ + priv->cpu_ports_mask = dsa_cpu_ports(ds); + ctrl = YT921X_EXT_CPU_PORT_TAG_EN | YT921X_EXT_CPU_PORT_PORT_EN | + YT921X_EXT_CPU_PORT_PORT(__ffs(priv->cpu_ports_mask)); + res = yt921x_reg_write(priv, YT921X_EXT_CPU_PORT, ctrl); + if (res) + return res; + + /* Setup software switch */ + ctrl = YT922X_CPU_COPY_TO_EXT_CPU; + res = yt921x_reg_write(priv, YT922X_CPU_COPY, ctrl); + if (res) + return res; + + return res; +} + +static int yt922x_chip_setup_dsa(struct yt921x_priv *priv) +{ + unsigned long cpu_ports_mask; + u32 ctrl; + int port; + int res; + int i; + + /* cpu port set */ + res = yt922x_cpu_port_set(priv); + if (res) + return res; + + ctrl = GENMASK_U32(8, 0); + res = yt921x_reg_write(priv, YT922X_FILTER_UNK_UCAST, ctrl); + if (res) + return res; + + ctrl = 0; + for (i = 0; i < priv->series->max_ports; i++) + ctrl |= YT922X_ACT_UNK_ACTn_TRAP(i); + cpu_ports_mask = priv->cpu_ports_mask; + for_each_set_bit(port, &cpu_ports_mask, priv->series->max_ports) { + ctrl &= ~YT922X_ACT_UNK_ACTn_M(port); + ctrl |= YT922X_ACT_UNK_ACTn_DROP(port); + } + res = yt921x_reg_write(priv, YT922X_ACT_UNK_UCAST, ctrl); + if (res) + return res; + res = yt921x_reg_write(priv, YT922X_ACT_UNK_MCAST, ctrl); + if (res) + return res; + + return 0; +} + +static int yt922x_chip_setup(struct yt921x_priv *priv) +{ + u32 ctrl; + int res; + + ctrl = YT922X_FUNC_MIB | YT922X_FUNC_ACL; + res = yt921x_reg_set_bits(priv, YT921X_FUNC, ctrl); + if (res) + return res; + + res = yt922x_chip_setup_dsa(priv); + if (res) + return res; + + return 0; +} + +static void yt922x_pcs_setup(struct dsa_switch *ds) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + const struct yt921x_info *info = priv->info; + unsigned long mask; + int port; + + mask = info->serdes_mask; + for_each_set_bit(port, &mask, priv->series->max_ports) { + struct yt921x_port *pp = &priv->ports[port]; + + pp->pcs.ops = &yt922x_phylink_pcs_ops; + pp->pcs.poll = true; + + __set_bit(PHY_INTERFACE_MODE_SGMII, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, + pp->pcs.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_USXGMII, + pp->pcs.supported_interfaces); + } +} + +static int yt922x_dsa_setup(struct dsa_switch *ds) +{ + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); + struct device_node *np = dev->of_node; + struct device_node *child; + int res; + + mutex_lock(&priv->reg_lock); + res = yt921x_chip_reset(priv); + mutex_unlock(&priv->reg_lock); + if (res) + return res; + + /* Register the internal mdio bus. */ + child = of_get_child_by_name(np, "mdio"); + if (child) { + res = yt921x_mbus_int_init(priv, child); + of_node_put(child); + if (res) + return res; + } + + mutex_lock(&priv->reg_lock); + res = yt922x_chip_setup(priv); + mutex_unlock(&priv->reg_lock); + if (res) + return res; + + /* switch sds pcs setup */ + yt922x_pcs_setup(ds); + + return 0; +} + +static const struct dsa_switch_ops yt922x_dsa_switch_ops = { + /* port */ + .get_tag_protocol = yt922x_dsa_get_tag_protocol, + .phylink_get_caps = yt922x_dsa_phylink_get_caps, + .port_setup = yt922x_dsa_port_setup, + /* chip */ + .setup = yt922x_dsa_setup, +}; + static const struct yt92xx_series yt92xx_series_table[] = { [YT92XX_MODE_YT921X] = { .name = "YT921x", @@ -2711,12 +3204,25 @@ static const struct yt92xx_series yt92xx_series_table[] = { .switch_ops = &yt921x_dsa_switch_ops, .mac_ops = &yt921x_phylink_mac_ops }, + [YT92XX_MODE_YT922X] = { + .name = "YT922x", + .max_ports = YT922X_PORT_NUM, + .num_lag_ids = YT922X_LAG_NUM, + .ageing_time_min = 1U * YT922X_AGEING_TIME_UNIT, + .ageing_time_max = U16_MAX * YT922X_AGEING_TIME_UNIT, + .dscp_prio_mapping_is_global = true, + .assisted_learning_on_cpu_port = true, + .switch_ops = &yt922x_dsa_switch_ops, + .mac_ops = &yt922x_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 if (major == YT9224_MAJOR) + return &yt92xx_series_table[YT92XX_MODE_YT922X]; else return NULL; } @@ -2842,6 +3348,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" }, {} }; MODULE_DEVICE_TABLE(of, yt921x_of_match); @@ -2859,5 +3366,6 @@ static struct mdio_driver yt921x_mdio_driver = { mdio_module_driver(yt921x_mdio_driver); MODULE_AUTHOR("David Yang <mmyangfl@gmail.com>"); -MODULE_DESCRIPTION("Driver for Motorcomm YT921x Switch"); +MODULE_AUTHOR("Kyle Switch <kyle.switch@motor-comm.com>"); +MODULE_DESCRIPTION("Driver for Motorcomm YT921x and YT922x Switch"); MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index b58b47883b91..247aae365b0a 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -120,6 +120,7 @@ enum yt921x_speed { YT921X_SPEED_1000, YT921X_SPEED_10000, YT921X_SPEED_2500, + YT921X_SPEED_5000, YT921X_SPEED_INVALID }; @@ -432,6 +433,7 @@ enum yt921x_fdb_entry_status { #define YT9215_MAJOR 0x9002 #define YT9218_MAJOR 0x9001 +#define YT9224_MAJOR 0x9004 /* required for a hard reset */ #define YT921X_RST_DELAY_US 10000 @@ -451,6 +453,85 @@ enum yt921x_fdb_entry_status { #define YT921X_NAME "yt921x" +/* yt922x register lists */ +#define YT92XX_PAGE_SELECT 0x1e +#define YT92XX_PAGE 0x1f +#define YT922X_EN_PHY_OVERWRITE (0x80040) +#define YT922X_EN_PHY_VALUE (0x8003c) +/* CTRL: force op to make soft configuration effective */ +#define YT922X_PORTn_CTRL(port) (0x80080 + 4 * (port)) +#define YT922X_PORT_FORCE_OP BIT(14) +#define YT922X_PORT_CFG_TX_EN BIT(13) +#define YT922X_PORT_CFG_RX_EN BIT(12) +#define YT922X_PORT_FC_AN BIT(11) +#define YT922X_PORT_LINK_AN BIT(10) /* CTRL: auto negotiation */ +#define YT922X_PORT_LINK BIT(9) /* CTRL: link status */ +#define YT922X_PORT_HALF_PAUSE BIT(8) /* Half-duplex back pressure mode */ +#define YT922X_PORT_DUPLEX_FULL BIT(7) +#define YT922X_PORT_RX_PAUSE BIT(6) +#define YT922X_PORT_TX_PAUSE BIT(5) +#define YT922X_PORT_RX_MAC_EN BIT(4) +#define YT922X_PORT_TX_MAC_EN BIT(3) +#define YT922X_PORT_SPEED_M GENMASK(2, 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 YT922X_SERDES_MODE_SGMII YT922X_SERDES_MODE(0) +#define YT922X_SERDES_MODE_REVSGMII YT922X_SERDES_MODE(1) +#define YT922X_SERDES_MODE_1000BASEX YT922X_SERDES_MODE(2) +#define YT922X_SERDES_MODE_100BASEX YT922X_SERDES_MODE(3) +#define YT922X_SERDES_MODE_2500BASEX YT922X_SERDES_MODE(4) +#define YT922X_SERDES_MODE_USXGMII YT922X_SERDES_MODE(6) +#define YT922X_PORT_NUM 9 +#define YT922X_PCS_LINK_CTRL 0x11 +#define YT922X_PCS_LINK_STATUS BIT(10) +#define YT922X_PCS_AN_COMPLETE BIT(11) +#define YT922X_PCS_WRITE_PROTECT 0x4be + +#define YT922X_LAG_NUM 4 + +#define YT922X_PORTn_ISOLATION(port) (0x180d80 + 0x4 * (port)) + +#define YT922X_PORTn_LEARN(port) (0x180300 + 4 * (port)) +#define YT922X_PORT_LEARN_DIS BIT(18) + +#define YT922X_FUNC_ACL BIT(5) +#define YT922X_FUNC_MIB BIT(4) + +#define YT922X_FILTER_UNK_UCAST 0x180ec8 +#define YT922X_ACT_UNK_UCAST 0x180ed8 +#define YT922X_ACT_UNK_MCAST 0x180ee0 +#define YT922X_ACT_UNK_MCAST_BYPASS_DROP_PIM BIT(22) +#define YT922X_ACT_UNK_MCAST_BYPASS_DROP_MLD BIT(21) +#define YT922X_ACT_UNK_MCAST_BYPASS_DROP_IGMP BIT(20) +#define YT922X_ACT_UNK_ACTn_M(port) GENMASK(2 * (port) + 1, 2 * (port)) +#define YT922X_ACT_UNK_ACTn(port, x) ((x) << (2 * (port))) +#define YT922X_ACT_UNK_ACTn_FORWARD(port) YT922X_ACT_UNK_ACTn(port, 0) /* flood */ +#define YT922X_ACT_UNK_ACTn_DROP(port) YT922X_ACT_UNK_ACTn(port, 1) /* discard */ +#define YT922X_ACT_UNK_ACTn_TRAP(port) YT922X_ACT_UNK_ACTn(port, 3) /* steer to CPU */ + +#define YT922X_CPU_COPY 0x181100 +#define YT922X_CPU_COPY_TO_INT_CPU BIT(1) +#define YT922X_CPU_COPY_TO_EXT_CPU BIT(0) +#define YT922X_CPU_TAG_RX_CTRL 0x80504 +#define YT922X_CPU_TAG_RX_MODE BIT(0) +#define YT922X_CPU_TAG_TX_CTRL 0x100710 +#define YT922X_CPU_TAG_TX_TYPE BIT(0) +#define YT922X_CPU_TAG_TX_MODE BIT(1) +#define YT922X_CPU_TAG_TX_CTAG_OP BIT(2) +#define YT922X_CPU_TAG_TX_STAG_OP BIT(3) +/* Define top ext addr for yt922x */ +#define YT922X_COMMON_EXT_PHYADDR 9 +#define YT922X_AGEING_TIME_UNIT 6000U + +enum yt922x_phy_reg_type { + YT922X_PHY_REG_TYPE_COMMON_EXT, + YT922X_PHY_REG_TYPE_SDS_COMMON_EXT, + YT922X_PHY_REG_TYPE_MII, + YT922X_PHY_REG_TYPE_EXT, + YT922X_PHY_REG_TYPE_MAX +}; + struct yt921x_port { unsigned char index; @@ -506,6 +587,7 @@ static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info) enum yt92xx_mode { YT92XX_MODE_YT921X, + YT92XX_MODE_YT922X, YT92XX_MODE_MAX, }; @@ -569,6 +651,8 @@ static inline int ethtool_speed_to_yt921x(int speed) return YT921X_SPEED_2500; case SPEED_10000: return YT921X_SPEED_10000; + case SPEED_5000: + return YT921X_SPEED_5000; default: return YT921X_SPEED_INVALID; } diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c index 94087c9962cc..62d46b302f9b 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.c +++ b/drivers/net/dsa/motorcomm/mdio_bus.c @@ -107,6 +107,45 @@ yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg, return 1; } +/* 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; +} + static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg) { struct yt921x_priv *priv = mbus->priv; diff --git a/drivers/net/dsa/motorcomm/mdio_bus.h b/drivers/net/dsa/motorcomm/mdio_bus.h index 603088b5b8f4..1b06091854ff 100644 --- a/drivers/net/dsa/motorcomm/mdio_bus.h +++ b/drivers/net/dsa/motorcomm/mdio_bus.h @@ -35,6 +35,10 @@ struct yt921x_priv; int yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp); int yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val); +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); int yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg, u16 mask, u16 val); diff --git a/drivers/net/dsa/motorcomm/pcs-922x.c b/drivers/net/dsa/motorcomm/pcs-922x.c new file mode 100644 index 000000000000..11ef08b7f923 --- /dev/null +++ b/drivers/net/dsa/motorcomm/pcs-922x.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Kyle Switch + */ + +#include "chip.h" +#include "mdio_bus.h" +#include "pcs.h" +#include "smi.h" + +#define to_device(priv) ((priv)->ds.dev) + +static int yt922x_sds_phyaddr_get(struct yt921x_priv *priv, int port, + enum yt922x_phy_reg_type reg_type) +{ + const struct yt921x_info *info = priv->info; + + if (!(BIT(port) & info->serdes_mask)) + return -EINVAL; + + /* + * YT922x PCS MDIO addressing: + * Chip-level common extended registers are accessed at a fixed MDIO + * address (YT922X_COMMON_EXT_PHYADDR, 9), regardless of the port. + * All other register types, including the per-port SDS space, are + * accessed at the plain port number. + */ + switch (reg_type) { + case YT922X_PHY_REG_TYPE_COMMON_EXT: + return YT922X_COMMON_EXT_PHYADDR; + default: + return port; + } +} + +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; + u16 link_ctrl; + int res; + u16 bmsr; + int addr; + u16 lp; + + addr = yt922x_sds_phyaddr_get(priv, port, YT922X_PHY_REG_TYPE_MII); + if (addr < 0) { + state->link = false; + return; + } + + mutex_lock(&priv->reg_lock); + switch (state->interface) { + case PHY_INTERFACE_MODE_SGMII: + case PHY_INTERFACE_MODE_1000BASEX: + case PHY_INTERFACE_MODE_2500BASEX: + res = yt921x_intif_read(priv, addr, MII_BMSR, &bmsr); + 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, bmsr, lp); + break; + case PHY_INTERFACE_MODE_100BASEX: + res = yt921x_intif_read(priv, addr, MII_BMSR, &bmsr); + if (res) + goto err; + state->speed = SPEED_100; + state->duplex = DUPLEX_FULL; + state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; + state->link = !!(bmsr & BMSR_LSTATUS); + break; + case PHY_INTERFACE_MODE_USXGMII: + res = yt921x_intif_read(priv, addr, YT922X_PCS_LINK_CTRL, + &link_ctrl); + if (res) + goto err; + state->link = FIELD_GET(YT922X_PCS_LINK_STATUS, link_ctrl); + state->an_complete = FIELD_GET(YT922X_PCS_AN_COMPLETE, + link_ctrl); + res = yt921x_intif_read(priv, addr, MII_LPA, &lp); + if (res) + goto err; + if (state->link) + phylink_decode_usxgmii_word(state, lp); + break; + default: + state->link = false; + break; + } + mutex_unlock(&priv->reg_lock); + return; + +err: + mutex_unlock(&priv->reg_lock); + state->link = false; +} + +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 bmcr; + int addr; + int res; + + addr = yt922x_sds_phyaddr_get(priv, port, YT922X_PHY_REG_TYPE_MII); + if (addr < 0) { + dev_err(dev, "Invalid SDS PHY addr for port %d\n", port); + return; + } + + mutex_lock(&priv->reg_lock); + res = yt921x_intif_read(priv, addr, MII_BMCR, &bmcr); + if (res) + goto err; + bmcr |= BMCR_ANRESTART; + res = yt921x_intif_write(priv, addr, MII_BMCR, bmcr); + if (res) + goto err; + mutex_unlock(&priv->reg_lock); + return; + +err: + mutex_unlock(&priv->reg_lock); + dev_err(dev, "Failed to an restart PCS port %d: %i\n", 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) +{ + bool inband = neg_mode & PHYLINK_PCS_NEG_INBAND; + struct yt921x_port *pp = pcs_to_yt921x_port(pcs); + struct yt921x_priv *priv = yt921x_port_to_priv(pp); + bool changed = false; + int res, port; + u16 bmcr_old; + u16 bmcr_new; + u16 data; + u16 ctrl; + int addr; + int adv; + + port = pp->index; + addr = yt922x_sds_phyaddr_get + (priv, port, YT922X_PHY_REG_TYPE_SDS_COMMON_EXT); + if (addr < 0) + return addr; + + mutex_lock(&priv->reg_lock); + + /* + * Unlock the SerDes extended space so the YT922X_PORT_SDSn write + * below takes effect. 0xd is the unlock value and is intentionally + * left in place: the space stays writable for subsequent + * configuration, no restore is needed. + */ + res = yt921x_intif_ext_write(priv, addr, YT922X_PCS_WRITE_PROTECT, 0xd); + if (res) + goto err; + switch (interface) { + case PHY_INTERFACE_MODE_SGMII: + ctrl = YT922X_SERDES_MODE_SGMII; + break; + case PHY_INTERFACE_MODE_100BASEX: + ctrl = YT922X_SERDES_MODE_100BASEX; + break; + case PHY_INTERFACE_MODE_1000BASEX: + ctrl = YT922X_SERDES_MODE_1000BASEX; + break; + case PHY_INTERFACE_MODE_2500BASEX: + ctrl = YT922X_SERDES_MODE_2500BASEX; + break; + case PHY_INTERFACE_MODE_USXGMII: + ctrl = YT922X_SERDES_MODE_USXGMII; + break; + default: + res = -EINVAL; + goto err; + } + res = yt921x_intif_ext_read(priv, addr, YT922X_PORT_SDSn, &data); + 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; + + if (inband) { + adv = phylink_mii_c22_pcs_encode_advertisement(interface, + advertising); + if (adv >= 0) { + res = yt921x_intif_modify_changed(priv, port, + MII_ADVERTISE, + U16_MAX, adv); + if (res < 0) + goto err; + + changed = !!res; + } + } + + res = yt921x_intif_read(priv, port, MII_BMCR, &bmcr_old); + if (res) + goto err; + + bmcr_new = bmcr_old; + if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) + bmcr_new |= BMCR_ANENABLE; + else + bmcr_new &= ~BMCR_ANENABLE; + + changed |= (bmcr_new != bmcr_old); + + res = yt921x_intif_write(priv, port, MII_BMCR, bmcr_new); + if (res) + goto err; + pp->inband = inband; + mutex_unlock(&priv->reg_lock); + + return changed; + +err: + mutex_unlock(&priv->reg_lock); + + return res; +} + +static int yt922x_pcs_enable(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 = yt921x_priv_to_device(priv); + int port = pp->index; + int addr; + u16 bmcr; + int res; + + addr = yt922x_sds_phyaddr_get(priv, port, YT922X_PHY_REG_TYPE_MII); + if (addr < 0) + return addr; + + mutex_lock(&priv->reg_lock); + + res = yt921x_intif_read(priv, addr, MII_BMCR, &bmcr); + if (res) + goto end; + + bmcr &= ~BMCR_PDOWN; + bmcr |= BMCR_ANRESTART; + res = yt921x_intif_write(priv, addr, MII_BMCR, bmcr); + +end: + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to enable PCS port %d: %i\n", port, res); + + return res; +} + +static void yt922x_pcs_disable(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 = yt921x_priv_to_device(priv); + int port = pp->index; + int addr; + int res; + + addr = yt922x_sds_phyaddr_get(priv, port, YT922X_PHY_REG_TYPE_MII); + if (addr < 0) { + dev_err(dev, "Invalid SDS PHY addr for port %d\n", port); + return; + } + + mutex_lock(&priv->reg_lock); + res = yt921x_intif_modify(priv, addr, MII_BMCR, BMCR_PDOWN, BMCR_PDOWN); + mutex_unlock(&priv->reg_lock); + + if (res) + dev_err(dev, "Failed to power down PCS port %d: %i\n", port, + res); +} + +const struct phylink_pcs_ops yt922x_phylink_pcs_ops = { + .pcs_get_state = yt922x_pcs_get_state, + .pcs_config = yt922x_pcs_config, + .pcs_an_restart = yt922x_pcs_an_restart, + .pcs_enable = yt922x_pcs_enable, + .pcs_disable = yt922x_pcs_disable, +}; diff --git a/drivers/net/dsa/motorcomm/pcs.h b/drivers/net/dsa/motorcomm/pcs.h index 42426558086a..c85caa7bf212 100644 --- a/drivers/net/dsa/motorcomm/pcs.h +++ b/drivers/net/dsa/motorcomm/pcs.h @@ -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 -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x 2026-12-02 8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch @ 2026-12-03 8:57 ` netdev-bot+sashiko 0 siblings, 0 replies; 17+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 8:57 UTC (permalink / raw) To: kyle.switch Cc: andrew, olteanv, davem, edumazet, kuba, pabeni, mmyangfl, horms, linux, netdev, linux-kernel, devicetree, krzk+dt, conor+dt, david.laight.linux, ming.xu, xiaolin.xu, jianmin.wang, wei.zhang, sijia.huang Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 2 · Low: 5 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The YT922x internal MDIO bus is never unregistered, so its callbacks keep using freed driver memory. - [Medium] yt922x_port_down() may switch off the integrated PHY on every link-down, with nothing to switch it back on. - [Medium] In forced (out-of-band) mode on YT922x SerDes ports, the resolved speed and duplex are never given to the PCS/SerDes. - [Low] The commit message understates the shared-code change in yt921x_chip_detect(). - [Low] yt922x_dsa_phylink_get_caps() sets MAC_2500FD on the internal PHY ports (info->internal_mask = GENMASK(7,4), ports 4-7), with the… - [Low] The YT922x "common extended" register space cannot be reached through the new helpers. - [Low] The YT922X_PORT_FORCE_OP write can be skipped on the second and later link events. - [Low] yt922x_pcs_config() changes the SerDes line rate without any reset or power cycle. -- net: dsa: motorcomm: Add support for Motorcomm YT922x This adds YT9224 support to the existing yt921x DSA driver. It adds a minimal set of dsa_switch_ops, a phylink_mac_ops set and a new PCS driver in pcs-922x.c. It also adds extended register MDIO helpers and an early return for YT9224 in yt921x_chip_detect(). > diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c > index 197dadb1046a4..2a684beac408e 100644 > --- a/drivers/net/dsa/motorcomm/chip.c > +++ b/drivers/net/dsa/motorcomm/chip.c [ ... ] > @@ -2279,6 +2290,14 @@ static int yt921x_chip_detect(struct yt921x_priv *priv) > return -ENODEV; > } > > + if (!yt921x_needs_extmode_check(major)) { > + dev_info(dev, > + "Motorcomm %s ethernet switch, chipid: 0x%x\n", > + info->name, chipid); > + priv->info = info; > + return 0; > + } > + [Severity: Low] The commit message says: - Add an early return for YT9224 in yt921x_chip_detect(), skipping the CHIP_MODE, EXTMODE. Does that cover everything this skips? The early return also skips the YT921X_SYS_CLK read, so priv->cycle_ns stays 0 on YT9224. Right now the only user is yt921x_chip_setup_tc(), and the YT922x path doesn't call it: op_ns = 8 * priv->cycle_ns; The early return also drops the per-variant match for major 0x9004. The first table entry with that major is accepted, and the mode/extmode values (0, 0) in the YT9224 entry are never compared. Suppose another chip reports major 0x9004, for example a YT9228 if it shares that major. Would it be logged as "YT9224" and run with internal_mask GENMASK(7, 4) and serdes_mask BIT(8) | BIT(0)? Could the commit message describe this, or should detection keep some kind of variant check? > res = yt921x_reg_read(priv, YT921X_CHIP_MODE, &mode); > if (res) > return res; > @@ -2699,6 +2718,480 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = { > .setup = yt921x_dsa_setup, > }; > > +static int yt922x_port_down(struct yt921x_priv *priv, int port) > +{ > + u32 mask; > + int res; > + > + /* mac force down */ > + mask = YT922X_PORT_LINK | YT922X_PORT_RX_MAC_EN | > + YT922X_PORT_TX_MAC_EN | YT922X_PORT_LINK_AN; > + res = yt921x_reg_clear_bits(priv, YT922X_PORTn_CTRL(port), mask); > + if (res) > + return res; > + /* Need force op to make soft configuration effective */ > + mask = YT922X_PORT_FORCE_OP; > + res = yt921x_reg_set_bits(priv, YT922X_PORTn_CTRL(port), mask); [Severity: Low] Does this FORCE_OP write still reach the hardware after the first link event? yt921x_reg_set_bits() goes through yt921x_reg_update_bits(), which skips the write if the value doesn't change: u = v; u &= ~mask; u |= val; if (u == v) return 0; The config write just before this doesn't include FORCE_OP in its mask. So once the bit is 1 it stays 1, and the later FORCE_OP writes in yt922x_port_down() and yt922x_port_up() do nothing. That is harmless if FORCE_OP is a level-sensitive "use software config" select. If it is a commit trigger that needs a new write, would speed, duplex and pause changes and the forced link-down stop taking effect from the second link event on? > + if (res) > + return res; > + > + /* disable en_phy */ > + res = yt921x_reg_clear_bits(priv, YT922X_EN_PHY_VALUE, BIT(port)); > + if (res) > + return res; > + res = yt921x_reg_set_bits(priv, YT922X_EN_PHY_OVERWRITE, BIT(port)); [Severity: Medium] Can the internal PHY still see a link partner after this runs? Every mac_link_down forces en_phy off for the port, with the override set. The only code that turns en_phy back on is yt922x_port_up(), called from mac_link_up. phylink only calls mac_link_up once the PHY or PCS has already reported link. Nothing in .setup, .port_setup, mac_config or pcs_enable restores it. If en_phy gates the integrated PHYs on ports 4-7 (power, isolate or reset), would a cable unplug or "ip link set dev lanX down" keep the port down for good, since mac_link_up can never run to turn it back on? Clearing the MAC TX/RX enables and forcing LINK=0 already quiesces the MAC on link-down. Is the en_phy override needed here? > + if (res) > + return res; > + > + return 0; > +} [ ... ] > + /* > + * Self-negotiation: the LINK/AN bits in ctrl are set based to inband. > + * Forced mode: set LINK, keep the AN bit at 0 and clear it via the mask > + */ > + if (pp->serdes && pp->inband) > + ctrl |= (YT922X_PORT_FC_AN | YT922X_PORT_LINK_AN); > + else > + ctrl |= YT922X_PORT_LINK; > + > + res = yt921x_reg_update_bits(priv, YT922X_PORTn_CTRL(port), mask, ctrl); [Severity: Medium] In forced (out-of-band) mode on the SerDes ports, where do the resolved speed and duplex get written to the SerDes/PCS? A few things look missing: - yt922x_port_up() only writes YT922X_PORTn_CTRL. - yt922x_phylink_pcs_ops has no .pcs_link_up. - yt922x_pcs_config() only toggles BMCR_ANENABLE and never sets any speed bits. The YT921x path for the same family programs the SerDes side separately in yt921x_port_up(): if (pp->serdes) { mask = YT921X_SERDES_SPEED_M; ctrl = YT921X_SERDES_SPEED(ps); mask |= YT921X_SERDES_DUPLEX_FULL; ... yt922x_dsa_phylink_get_caps() advertises 10 through 10000 on the SerDes ports with SGMII and USXGMII, so phylink can resolve rates below the lane's native rate. Examples are SGMII with an out-of-band PHY at 10/100, or a USXGMII fixed-link at 1G/2.5G/5G. In those cases, could the SerDes stay at its default rate, so the link reports up but no traffic gets through? > + if (res) > + return res; [ ... ] > + if (info->internal_mask & BIT(port)) { > + /* port 4 to port 7, internal utp */ > + __set_bit(PHY_INTERFACE_MODE_INTERNAL, > + config->supported_interfaces); > + config->mac_capabilities |= MAC_2500FD; > + } [Severity: Low] Is MAC_2500FD right for the internal PHY ports? The internal_mask comment in chip.h says "Ports with integral GbE PHYs". The YT9224 binding text also describes ports 4-7 as internal GbE PHYs. Either this capability or those descriptions look wrong for YT9224. [ ... ] > +static int yt922x_dsa_setup(struct dsa_switch *ds) > +{ > + struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); > + struct device *dev = yt921x_priv_to_device(priv); > + struct device_node *np = dev->of_node; > + struct device_node *child; > + int res; > + > + mutex_lock(&priv->reg_lock); > + res = yt921x_chip_reset(priv); > + mutex_unlock(&priv->reg_lock); > + if (res) > + return res; > + > + /* Register the internal mdio bus. */ > + child = of_get_child_by_name(np, "mdio"); > + if (child) { > + res = yt921x_mbus_int_init(priv, child); > + of_node_put(child); > + if (res) > + return res; > + } > + > + mutex_lock(&priv->reg_lock); > + res = yt922x_chip_setup(priv); > + mutex_unlock(&priv->reg_lock); > + if (res) > + return res; > + > + /* switch sds pcs setup */ > + yt922x_pcs_setup(ds); > + > + return 0; > +} > + > +static const struct dsa_switch_ops yt922x_dsa_switch_ops = { > + /* port */ > + .get_tag_protocol = yt922x_dsa_get_tag_protocol, > + .phylink_get_caps = yt922x_dsa_phylink_get_caps, > + .port_setup = yt922x_dsa_port_setup, > + /* chip */ > + .setup = yt922x_dsa_setup, > +}; [Severity: High] What unregisters the internal MDIO bus that yt922x_dsa_setup() registers? yt921x_mbus_int_init() uses the non-devm of_mdiobus_register() and saves priv in mbus->priv. yt922x_dsa_switch_ops has no .teardown, so yt921x_mbus_int_cleanup() is never called. The YT921x path does this in yt921x_dsa_teardown(): if (priv->mbus_int) yt921x_mbus_int_cleanup(priv); On unbind or rmmod, yt921x_mdio_remove() calls dsa_unregister_switch() and then devres frees priv. The mii_bus and its PHY devices stay registered with mbus->priv pointing at freed memory. After rmmod, mbus->read and mbus->write also point into unloaded module text. A later MDIO access, for example mdio_bus_phy_suspend() during system suspend, would then run: yt921x_mbus_int_read() priv->series->max_ports mutex_lock(&priv->reg_lock) on the freed priv. Is this a use-after-free? The bus also leaks if yt922x_chip_setup() fails after the bus is registered, because dsa_switch_setup() doesn't call ops->teardown when ops->setup fails: err = ds->ops->setup(ds); if (err < 0) goto unregister_notifier; It also leaks on a later failure in dsa_tree_setup(). After that, would a rebind fail? of_mdiobus_register() would be called again with the same bus id, dev_name(dev), while the old bus still exists. [ ... ] > diff --git a/drivers/net/dsa/motorcomm/pcs-922x.c b/drivers/net/dsa/motorcomm/pcs-922x.c > new file mode 100644 > index 0000000000000..11ef08b7f923d > --- /dev/null > +++ b/drivers/net/dsa/motorcomm/pcs-922x.c [ ... ] > + switch (reg_type) { > + case YT922X_PHY_REG_TYPE_COMMON_EXT: > + return YT922X_COMMON_EXT_PHYADDR; [Severity: Low] Can the common extended space be reached at this address? YT922X_COMMON_EXT_PHYADDR is 9, which equals YT922X_PORT_NUM. Both new helpers in mdio_bus.c reject it: yt921x_intif_ext_write() / yt921x_intif_ext_read() if (port >= priv->series->max_ports) return -ENODEV; No caller passes YT922X_PHY_REG_TYPE_COMMON_EXT today. yt922x_pcs_config() uses SDS_COMMON_EXT, which maps to the port number. So nothing fails now, but the first user of the common space would always get -ENODEV. Should the bound check accept address 9, or should the COMMON_EXT case be dropped until something needs it? > + default: > + return port; > + } > +} [ ... ] > + res = yt921x_intif_ext_read(priv, addr, YT922X_PORT_SDSn, &data); > + if (res) > + goto err; > + data &= ~YT922X_SERDES_MODE_M; > + data |= ctrl; > + res = yt921x_intif_ext_write(priv, addr, YT922X_PORT_SDSn, data); > + if (res) > + goto err; [Severity: Low] Does the SerDes need a reset or power cycle after the mode changes here? This write can move the lane between 1.25 Gbaud (SGMII, 1000BASE-X, 100BASE-X), 3.125 Gbaud (2500BASE-X) and 10.3125 Gbaud (USXGMII). There is no BMCR_RESET, no BMCR_PDOWN toggle and no lane reset. yt922x_phylink_mac_select_pcs() returns the same &priv->ports[port].pcs for every SerDes interface. phylink_major_config() only calls pcs_disable and pcs_enable when the PCS pointer changes. So when the interface changes on a running port, for example an SFP module swap or a PHY that changes its host interface with speed, could the PLL/CDR stay set for the old rate until the port is cycled? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-12-03 8:57 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 8:40 [PATCH net-next v18 0/6] net: dsa: motorcomm: add support yt922x driver Kyle Switch 2026-12-02 8:40 ` [PATCH net-next v18 1/6] net: dsa: motorcomm: initialize dsa_switch based on chipid Kyle Switch 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking Kyle Switch 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 3/6] net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 4/6] dt-bindings: net: dsa: add Motorcomm YT9224 Kyle Switch 2026-12-02 22:58 ` Rob Herring (Arm) 2026-12-03 8:40 ` sashiko-bot 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 5/6] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko 2026-12-02 8:40 ` [PATCH net-next v18 6/6] net: dsa: motorcomm: Add support for Motorcomm YT922x Kyle Switch 2026-12-03 8:57 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox