Skip to contentSkip to conversation

net: dsa: motorcomm: add support yt922x driver

PATCH Superseded Kyle Switch 3 participants 11 messages Oct 20 – Oct 22

Subsystems (4)

v16 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v16 cover net: dsa: motorcomm: add support yt922x driver

This patchset mainly adds support for the yt922x series to the dsa driver. Currently, only the yt9224 in the yt922x series is supported, and the corresponding tag handling for yt922x is added.

At the same time, it optimizes the max ports boundary check in the existing code, and initializes the dsa switch based on the chipid.

changes in 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 (5):
net: dsa: motorcomm: initialize dsa_switch based on chipid
net: dsa: motorcomm: use max_ports in series for port bounds checking
net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers
net: dsa: tag_yt922x: add support for Motorcomm YT922x tags
net: dsa: motorcomm: Add support for Motorcomm YT922x

 MAINTAINERS                          |   2 +
 drivers/net/dsa/motorcomm/Kconfig    |   7 +-
 drivers/net/dsa/motorcomm/Makefile   |   1 +
 drivers/net/dsa/motorcomm/chip.c     | 575 ++++++++++++++++++++++++++-
 drivers/net/dsa/motorcomm/chip.h     | 101 +++++
 drivers/net/dsa/motorcomm/mdio_bus.c |  48 ++-
 drivers/net/dsa/motorcomm/mdio_bus.h |   4 +
 drivers/net/dsa/motorcomm/pcs-922x.c | 282 +++++++++++++
 drivers/net/dsa/motorcomm/pcs.h      |   1 +
 include/net/dsa.h                    |   2 +
 net/dsa/Kconfig                      |   6 +
 net/dsa/Makefile                     |   1 +
 net/dsa/tag_yt922x.c                 | 122 ++++++
 13 files changed, 1135 insertions(+), 17 deletions(-)
 create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c
 create mode 100644 net/dsa/tag_yt922x.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v16 1/5 net: dsa: motorcomm: initialize dsa_switch based on chipid

Replace the hardcoded chip handling in yt92xx_register_switch() with a data-driven loopup based on the chip ID.

---
 drivers/net/dsa/motorcomm/chip.c | 73 ++++++++++++++++++++++++++++----
 drivers/net/dsa/motorcomm/chip.h | 19 +++++++++
 2 files changed, 84 insertions(+), 8 deletions(-)
drivers/net/dsa/motorcomm/chip.c +65 -8
index e2b5c89f7e77..ccb84f889dd2 100644
@@ -2580,6 +2580,67 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
 	.setup			= yt921x_dsa_setup,
 };
 
+static const struct yt92xx_series yt92xx_series_table[] = {
+	[YT92XX_MODE_YT921X] = {
+		.name = "YT921x",
+		.max_ports = YT921X_PORT_NUM,
+		.num_lag_ids = YT921X_LAG_NUM,
+		.ageing_time_min = 1 * 5000,
+		.ageing_time_max = U16_MAX * 5000,
+		.dscp_prio_mapping_is_global = true,
+		.assisted_learning_on_cpu_port = true,
+		.switch_ops = &yt921x_dsa_switch_ops,
+		.mac_ops = &yt921x_phylink_mac_ops
+	},
+};
+
+static const struct yt92xx_series *yt92xx_series_lookup(u32 major)
+{
+	if (major == YT9215_MAJOR || major == YT9218_MAJOR)
+		return &yt92xx_series_table[YT92XX_MODE_YT921X];
+	else
+		return NULL;
+}
+
+static int yt92xx_register_switch(struct dsa_switch *ds)
+{
+	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	struct device *dev = yt921x_priv_to_device(priv);
+	const struct yt92xx_series *series;
+	u32 chipid;
+	u32 major;
+	int res;
+
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid);
+	mutex_unlock(&priv->reg_lock);
+	if (res) {
+		dev_err(dev, "Unexpected chipid 0x%x\n", chipid);
+		return res;
+	}
+
+	major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid);
+	series = yt92xx_series_lookup(major);
+	if (!series) {
+		dev_err(dev, "Undefined series info for the corresponding major\n");
+		return -ENODEV;
+	}
+	priv->series = series;
+
+	ds->assisted_learning_on_cpu_port =
+		priv->series->assisted_learning_on_cpu_port;
+	ds->dscp_prio_mapping_is_global =
+		priv->series->dscp_prio_mapping_is_global;
+	ds->ageing_time_min = priv->series->ageing_time_min;
+	ds->ageing_time_max = priv->series->ageing_time_max;
+	ds->num_lag_ids = priv->series->num_lag_ids;
+	ds->num_ports = priv->series->max_ports;
+	ds->ops = priv->series->switch_ops;
+	ds->phylink_mac_ops = priv->series->mac_ops;
+
+	return 0;
+}
+
 static void yt921x_mdio_shutdown(struct mdio_device *mdiodev)
 {
 	struct yt921x_priv *priv = mdiodev_get_drvdata(mdiodev);
@@ -2622,6 +2683,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 	struct yt921x_reg_mdio *mdio;
 	struct yt921x_priv *priv;
 	struct dsa_switch *ds;
+	int res;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -2648,15 +2710,10 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 
 	ds = &priv->ds;
 	ds->dev = dev;
-	ds->assisted_learning_on_cpu_port = true;
-	ds->dscp_prio_mapping_is_global = true;
 	ds->priv = priv;
-	ds->ops = &yt921x_dsa_switch_ops;
-	ds->ageing_time_min = 1 * 5000;
-	ds->ageing_time_max = U16_MAX * 5000;
-	ds->phylink_mac_ops = &yt921x_phylink_mac_ops;
-	ds->num_lag_ids = YT921X_LAG_NUM;
-	ds->num_ports = YT921X_PORT_NUM;
+	res = yt92xx_register_switch(ds);
+	if (res)
+		return res;
 
 	mdiodev_set_drvdata(mdiodev, priv);
 
drivers/net/dsa/motorcomm/chip.h +19 -0
index 7047ad98f431..8e0b00281c56 100644
@@ -503,9 +503,28 @@ static inline u16 yt921x_info_ports_mask(const struct yt921x_info *info)
 	return info->internal_mask | info->xmii_mask | info->serdes_mask;
 }
 
+enum yt92xx_mode {
+	YT92XX_MODE_YT921X,
+	YT92XX_MODE_YT922X,
+	YT92XX_MODE_MAX,
+};
+
+struct yt92xx_series {
+	const char *name;
+	unsigned int max_ports;
+	unsigned int num_lag_ids;
+	unsigned int ageing_time_min;
+	unsigned int ageing_time_max;
+	u32 dscp_prio_mapping_is_global;
+	u32 assisted_learning_on_cpu_port;
+	const struct dsa_switch_ops *switch_ops;
+	const struct phylink_mac_ops *mac_ops;
+};
+
 struct yt921x_priv {
 	struct dsa_switch ds;
 
+	const struct yt92xx_series *series;
 	const struct yt921x_info *info;
 	unsigned int meter_slot_ns;
 	unsigned int port_shape_slot_ns;
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH net-next v16 1/5] net: dsa: motorcomm: initialize dsa_switch based on chipid

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] When yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid) fails, yt92xx_register_switch() (drivers/net/dsa/motorcomm/chip.c) prints…

--

net: dsa: motorcomm: initialize dsa_switch based on chipid

This patch replaces the hardcoded dsa_switch setup in yt921x_mdio_probe() with a new helper, yt92xx_register_switch(). The helper reads the chip ID, looks up a per-series descriptor table and fills in the dsa_switch fields from that descriptor.

Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0 -0
index d4fc20c52a58d..4add61b89310a 100644

[ ... ]

Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +4 -0
+static int yt92xx_register_switch(struct dsa_switch *ds)
+{
+	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	struct device *dev = yt921x_priv_to_device(priv);

drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2618

Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10 -0
+	const struct yt92xx_series *series;
+	u32 chipid;
+	u32 major;
+	int res;
+
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid);
+	mutex_unlock(&priv->reg_lock);
+	if (res) {
+		dev_err(dev, "Unexpected chipid 0x%x\n", chipid);
                                                          ^^^^^^

[Severity: Low]
Can this print an uninitialized value?

chipid is a local u32 with no initializer. This dev_err() only runs when yt921x_reg_read() has failed. With the MDIO backend, the output pointer is written only on success. Every error path jumps over the store:

drivers/net/dsa/motorcomm/chip.c:yt921x_reg_mdio_read() {
    ...
	res = __mdiobus_read(bus, addr, reg_data);
	if (res < 0)
		goto end;
	val = (val << 16) | (u16)res;

	*valp = val;
	res = 0;

end:

	mutex_unlock(&bus->mdio_lock);
	return res;
}

So if an MDIO error happens during yt921x_mdio_probe(), the log line will show leftover stack contents. The wording also suggests a bad ID was read, when in fact the read failed.

The same string in yt921x_chip_detect() is printed only after a successful read, when the major is not recognized.

Could the read-failure path just return res, or print a message that does not use chipid?

It looks like the final patch of this series, "net: dsa: motorcomm: Add support for Motorcomm YT922x", rewrites this branch as a plain "if (res) return res;". After that change, chipid is printed only on the unknown-major path. The intermediate patches in the series still contain this code.

Quoted 2 lines
drivers/net/dsa/motorcomm/chip.c +2 -0
+		return res;
+	}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020111115.3072180-1-kyle.switch%40motor-comm.com
#3 lore raw

PATCH v16 2/5 net: dsa: motorcomm: use max_ports in series for port bounds checking

In reply to Kyle Switch

Replace the hardcoded YT921X_PORT_NUM macro with the per-series max_ports field in port validation. This removes family-specific constants from the common code path and simplifies adding new switch families with different port counts.

No functional change for existing YT921X devices.

---
 drivers/net/dsa/motorcomm/mdio_bus.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/mdio_bus.c +5 -3
index dd6c52f37bbf..83f0212551ff 100644
@@ -113,7 +113,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg)
 	u16 val;
 	int res;
 
-	if (port >= YT921X_PORT_NUM)
+	if (port >= priv->series->max_ports)
 		return U16_MAX;
 
 	mutex_lock(&priv->reg_lock);
@@ -131,7 +131,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)
 	struct yt921x_priv *priv = mbus->priv;
 	int res;
 
-	if (port >= YT921X_PORT_NUM)
+	if (port >= priv->series->max_ports)
 		return -ENODEV;
 
 	mutex_lock(&priv->reg_lock);
@@ -145,6 +145,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 {
 	struct device *dev = yt921x_priv_to_device(priv);
 	struct mii_bus *mbus;
+	u32 max_ports;
 	int res;
 
 	mbus = devm_mdiobus_alloc(dev);
@@ -157,7 +158,8 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 	mbus->read = yt921x_mbus_int_read;
 	mbus->write = yt921x_mbus_int_write;
 	mbus->parent = dev;
-	mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0);
+	max_ports = priv->series->max_ports;
+	mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
 
 	res = devm_of_mdiobus_register(dev, mbus, mnp);
 	if (res)
Signature · 1 line
2.25.1
#4 lore raw

PATCH v16 3/5 net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers

In reply to Kyle Switch

Some masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the YT921X_MBUS_CTRL_* masks used by mdio_bus.c to fixed-width helpers.

This is a type cleanup only, with no functional change. Other GENMASK() uses in the driver are intentionally left untouched.

---
 drivers/net/dsa/motorcomm/chip.c     | 2 +-
 drivers/net/dsa/motorcomm/mdio_bus.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/motorcomm/chip.c +1 -1
index ccb84f889dd2..bbb598e19a8d 100644
@@ -2285,7 +2285,7 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 	if (res)
 		return res;
 
-	ctrl = GENMASK(10, 0);
+	ctrl = GENMASK_U32(10, 0);
 	res = yt921x_reg_write(priv, YT921X_FILTER_UNK_UCAST, ctrl);
 	if (res)
 		return res;
drivers/net/dsa/motorcomm/mdio_bus.c +1 -1
index 83f0212551ff..3aa1111efaa4 100644
@@ -159,7 +159,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 	mbus->write = yt921x_mbus_int_write;
 	mbus->parent = dev;
 	max_ports = priv->series->max_ports;
-	mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0);
+	mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0);
 
 	res = devm_of_mdiobus_register(dev, mbus, mnp);
 	if (res)
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH net-next v16 3/5] net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] The commit message for "net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers" does not match the diff, in three ways.

--

net: dsa: motorcomm: use fixed-width GENMASK_U*() helpers

This commit changes two GENMASK() uses in the YT921x DSA driver to GENMASK_U32(): the FILTER_UNK value in yt921x_chip_setup_dsa(), and the mii_bus phy_mask in yt921x_mbus_int_init(). The commit message describes it as a type-only cleanup with no functional change.

Quoted 7 lines

Some masks assigned to u16 and u32 fields are defined with GENMASK(),which is an unsigned long constant and wider than the field type on 64-bit builds. Convert the YT921X_MBUS_CTRL_* masks used by mdio_bus.c to fixed-width helpers.

This is a type cleanup only, with no functional change. Other GENMASK() uses in the driver are intentionally left untouched.

[Severity: Medium]
Does this description match the diff?

The patch doesn't modify drivers/net/dsa/motorcomm/mdio_bus.h, and the YT921X_MBUS_CTRL_* masks there still use plain GENMASK():

#define  YT921X_MBUS_CTRL_PORT_M		GENMASK(25, 21)
#define  YT921X_MBUS_CTRL_REG_M			GENMASK(20, 16)
#define  YT921X_MBUS_CTRL_TYPE_M		GENMASK(11, 8)  /* wild guess */
#define  YT921X_MBUS_CTRL_OP_M			GENMASK(3, 2)  /* wild guess */

They are still combined into u32 locals in yt921x_intif_read(), yt921x_intif_write(), yt921x_extif_read() and yt921x_extif_write(). For example:

	mask = YT921X_MBUS_CTRL_PORT_M | YT921X_MBUS_CTRL_REG_M |
	       YT921X_MBUS_CTRL_OP_M;

The only change in mdio_bus.c is the phy_mask expression in yt921x_mbus_int_init(), and that is not a YT921X_MBUS_CTRL_* mask:

	mbus->phy_mask = ~GENMASK_U32(max_ports - 1, 0);

Later patches in the series don't seem to convert these masks either.

The message also says other GENMASK() uses are left untouched, but the patch changes the open-coded value in yt921x_chip_setup_dsa() in chip.c:

	ctrl = GENMASK_U32(10, 0);
	res = yt921x_reg_write(priv, YT921X_FILTER_UNK_UCAST, ctrl);

The message doesn't mention this change. The named mask for the same field, YT921X_FILTER_PORTS_M in chip.h, is still GENMASK(10, 0).

Both changed sites are u32, so the reference to "u16 and u32 fields" doesn't match the diff either.

The message may describe a different version of this patch. Could it be rewritten to describe the two conversions that are actually made? The other option would be to convert the mdio_bus.h masks as described, and then drop or explain the chip.c hunk.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020111115.3072180-1-kyle.switch%40motor-comm.com
#6 lore raw

PATCH v16 4/5 net: dsa: tag_yt922x: add support for Motorcomm YT922x tags

In reply to Kyle Switch

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.

---
 MAINTAINERS          |   2 +
 include/net/dsa.h    |   2 +
 net/dsa/Kconfig      |   6 +++
 net/dsa/Makefile     |   1 +
 net/dsa/tag_yt922x.c | 122 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 133 insertions(+)
 create mode 100644 net/dsa/tag_yt922x.c
MAINTAINERS +2 -0
index 23e9194483d9..f10a2e4edae7 100644
@@ -18431,11 +18431,13 @@ F:	drivers/net/phy/motorcomm.c
 
 MOTORCOMM YT921X ETHERNET SWITCH DRIVER
 M:	David Yang <[email protected]>
+M:	Kyle Switch <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml
 F:	drivers/net/dsa/motorcomm/
 F:	net/dsa/tag_yt921x.c
+F:	net/dsa/tag_yt922x.c
 
 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
 M:	Jiri Slaby <[email protected]>
include/net/dsa.h +2 -0
index 5d12191b6f6f..5a173fe2bb87 100644
@@ -62,6 +62,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
 #define DSA_TAG_PROTO_MT7628_VALUE		35
 #define DSA_TAG_PROTO_KS8995_VALUE		36
+#define DSA_TAG_PROTO_YT922X_VALUE		37
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -101,6 +102,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_KSZ8463		= DSA_TAG_PROTO_KSZ8463_VALUE,
 	DSA_TAG_PROTO_MT7628		= DSA_TAG_PROTO_MT7628_VALUE,
 	DSA_TAG_PROTO_KS8995		= DSA_TAG_PROTO_KS8995_VALUE,
+	DSA_TAG_PROTO_YT922X		= DSA_TAG_PROTO_YT922X_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +6 -0
index 4f44bf3ede23..06d8d6526054 100644
@@ -233,4 +233,10 @@ config NET_DSA_TAG_YT921X
 	  Say Y or M if you want to enable support for tagging frames for
 	  Motorcomm YT921x switches.
 
+config NET_DSA_TAG_YT922X
+	tristate "Tag driver for Motorcomm YT922x switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Motorcomm YT922x switches.
+
 endif
net/dsa/Makefile +1 -0
index 1f9cc30e9988..0ef6dfce3b92 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
 obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
 obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
 obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o
+obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o
 
 # for tracing framework to find trace.h
 CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH net-next v16 4/5] net: dsa: tag_yt922x: add support for Motorcomm YT922x tags

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The layout comment in net/dsa/tag_yt922x.c does not match what yt922x_tag_xmit() puts on the wire, even though the commit message…
- [Low] Concern: yt922x_tag_rcv() never calls dsa_default_offload_fwd_mark(), unlike yt921x_tag_rcv(), so the…

--

net: dsa: tag_yt922x: add support for Motorcomm YT922x tags

This commit adds a DSA tag driver for Motorcomm YT922x switches. They use the same ETH_P_YT921X EtherType and 8-byte tag length as YT921x, but a different tag layout. The commit also adds a co-maintainer and the new file to the Motorcomm MAINTAINERS entry.

Quoted 6 lines
net/dsa/tag_yt922x.c new file +0 -0
new file mode 100644
index 0000000000000..b6146a9af98b3
@@ -0,0 +1,122 @@

[ ... ]

Quoted 8 lines
net/dsa/tag_yt922x.c new file +8 -0
+#define YT922X_TAG_LEN 8
+
+/*
+ * To define the from cpu tag format 8 bytes.
+ *
+ * To-CPU (RX) tag format, 8 bytes:
+ *
+ *   tag[0]: TPID (default: 0x9988)

net/dsa/tag_yt922x.c line 30

Quoted 10 lines
net/dsa/tag_yt922x.c new file +10 -0
+ *   tag[1]: VID lookup
+ *   tag[2]: bit 5:2  - RX source port
+ *
+ * From-CPU (TX) tag format, 8 bytes:
+ *
+ *   tag[0]: TPID (default: 0x9988)
+ *   tag[1]: bit 8:0 - Dst port mask
+ *   tag[2]: bit 15  - Dst port 0
+ *
+ */

[Severity: Low]
This isn't a bug, but does this From-CPU layout match what yt922x_tag_xmit() puts on the wire? The commit message says "The new driver documents both the to-CPU and from-CPU tag layouts".

Quoted 1 line

From the comment, tag[1] bit 0 would be port 0. The code shifts the mask

by one, though:

    ctrl = YT922X_TAG_PRIO(skb->priority) | YT922X_TAG_FORCE_DST |
           YT922X_TAG_PORTS(ports >> 1);

So tag[1] bit n is port n+1, and port 0 goes in tag[2] bit 15.

On every frame, tag[1] also carries YT922X_TAG_FORCE_DST (bit 9), YT922X_TAG_PRIO_M (bits 12:10) and YT922X_TAG_PRIO_EN (bit 13), and tag[3] is written as zero. None of these are in the comment.

Could the comment describe the shifted mask and these extra fields?

Also, the block starts with "To define the from cpu tag format 8 bytes." but then describes the To-CPU layout first.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020111115.3072180-1-kyle.switch%40motor-comm.com
#8 lore raw

PATCH v16 5/5 net: dsa: motorcomm: Add support for Motorcomm YT922x

In reply to Kyle Switch

Add support for Motorcomm YT922X, which is series of ethernet switches developed by Motorcomm Electronic Technology, includes YT9224 and YT9228.

This patch only adds support for the YT9224 variant. YT9228 is not supported yet.

This patch adds basic support for a working DSA switch, includes .port_setup, .setup, .phylink_get_caps, .get_tag_protocol.

---
 drivers/net/dsa/motorcomm/Kconfig    |   7 +-
 drivers/net/dsa/motorcomm/Makefile   |   1 +
 drivers/net/dsa/motorcomm/chip.c     | 508 ++++++++++++++++++++++++++-
 drivers/net/dsa/motorcomm/chip.h     |  82 +++++
 drivers/net/dsa/motorcomm/mdio_bus.c |  40 +++
 drivers/net/dsa/motorcomm/mdio_bus.h |   4 +
 drivers/net/dsa/motorcomm/pcs-922x.c | 282 +++++++++++++++
 drivers/net/dsa/motorcomm/pcs.h      |   1 +
 8 files changed, 916 insertions(+), 9 deletions(-)
 create mode 100644 drivers/net/dsa/motorcomm/pcs-922x.c
drivers/net/dsa/motorcomm/Kconfig +4 -3
index 79cdd79a1fd2..648c49d6c527 100644
@@ -1,11 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config NET_DSA_YT921X
-	tristate "Motorcomm YT9215 ethernet switch chip support"
+	tristate "Motorcomm YT9215 and YT9224 ethernet switch chip support"
 	select NET_DSA_TAG_YT921X
+	select NET_DSA_TAG_YT922X
 	select NET_IEEE8021Q_HELPERS if DCB
 	help
-	  This enables support for the Motorcomm YT9215 ethernet switch
-	  chip.
+	  This enables support for the Motorcomm YT9215 and YT9224
+	  ethernet switch chip.
 
 config NET_DSA_YT921X_LEDS
 	bool "LED support for Motorcomm YT9215"
drivers/net/dsa/motorcomm/Makefile +1 -0
index 9eaa59f699e8..3ca151358d19 100644
@@ -4,6 +4,7 @@ yt921x-objs := chip.o
 yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o
 yt921x-objs += mdio_bus.o
 yt921x-objs += mib.o
+yt921x-objs += pcs-922x.o
 yt921x-objs += pcs-921x.o
 yt921x-objs += smi.o
 yt921x-objs += tc.o
drivers/net/dsa/motorcomm/chip.c +502 -6

570 lines not on this page · raw message

drivers/net/dsa/motorcomm/chip.h +82 -0

106 lines not on this page · raw message

drivers/net/dsa/motorcomm/mdio_bus.c +40 -0
index 3aa1111efaa4..d545f338bd9d 100644
@@ -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;
@@ -299,3 +338,4 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)
 
 	return 0;
 }
+
drivers/net/dsa/motorcomm/mdio_bus.h +4 -0
index e79b725d435b..238a35891cb1 100644
@@ -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);
 
drivers/net/dsa/motorcomm/pcs-922x.c new file +282 -0

282 lines not on this page · raw message

drivers/net/dsa/motorcomm/pcs.h +1 -0
index 42426558086a..c85caa7bf212 100644
@@ -9,5 +9,6 @@
 #include <linux/phylink.h>
 
 extern const struct phylink_pcs_ops yt921x_phylink_pcs_ops;
+extern const struct phylink_pcs_ops yt922x_phylink_pcs_ops;
 
 #endif
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH net-next v16 5/5] net: dsa: motorcomm: Add support for Motorcomm YT922x

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · 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] yt921x_of_match in drivers/net/dsa/motorcomm/chip.c now accepts the new compatible "motorcomm,yt9224", but the DT binding was…
- [Medium] yt922x_port_up() (drivers/net/dsa/motorcomm/chip.c) sets YT922X_PORT_FC_AN | YT922X_PORT_LINK_AN whenever pp->inband is true.
- [Medium] On YT922x SerDes ports (0 and 8), nothing tells the SerDes side the resolved speed, duplex or link when in-band AN is not enabled.
- [Medium] yt922x_pcs_an_restart() (drivers/net/dsa/motorcomm/pcs-922x.c) sets BMCR_RESET in addition to BMCR_ANRESTART.
- [Low] The YT922x code disagrees with itself on PHY_INTERFACE_MODE_100BASEX.
- [Low] The YT92XX_MODE_YT922X entry in yt92xx_series_table (drivers/net/dsa/motorcomm/chip.c) declares capabilities that…

--

net: dsa: motorcomm: Add support for Motorcomm YT922x

This adds initial support for the Motorcomm YT9224 switch to the yt921x DSA driver. It adds a separate dsa_switch_ops and phylink_mac_ops table for the YT922x series and a new PCS implementation in pcs-922x.c. Only port_setup, setup, phylink_get_caps and get_tag_protocol are provided.

Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +0 -0
index be82fbb99a936..b5c76a5ce55a2 100644

[ ... ]

Quoted 1 line
drivers/net/dsa/motorcomm/chip.c +0 -0
@@ -2574,6 +2593,470 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {

[ ... ]

Quoted 5 lines
drivers/net/dsa/motorcomm/chip.c +5 -0
+static int
+yt922x_port_up(struct yt921x_priv *priv, int port, unsigned int mode,
+	       phy_interface_t interface, int speed, int duplex,
+	       bool tx_pause, bool rx_pause)
+{

[ ... ]

drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2687

Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8 -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->inband)
+		ctrl |= (YT922X_PORT_FC_AN | YT922X_PORT_LINK_AN);
+	else
+		ctrl |= YT922X_PORT_LINK;

[Severity: Medium]
Should YT922X_PORT_FC_AN really be set every time pp->inband is true?

pp->inband is set in yt922x_pcs_config():

	bool inband = neg_mode & PHYLINK_PCS_NEG_INBAND;

In include/linux/phylink.h, PHYLINK_PCS_NEG_INBAND_DISABLED has the same value as PHYLINK_PCS_NEG_INBAND. So this test is also true when in-band AN is disabled and BMCR_ANENABLE is being cleared. yt922x_pcs_config() also never reads permit_pause_to_mac.

As a result, FC_AN gets set in these cases:

- the INBAND_DISABLED case
- SGMII, whose in-band word carries no pause bits
- when phylink passes permit_pause_to_mac = false, for example after ethtool -A ... autoneg off

In those cases, would the MAC ignore the tx_pause/rx_pause values that phylink passed to mac_link_up()?

The YT921x path in pcs-921x.c gates the equivalent bit like this:

yt921x_serdes_config() {
    ...
	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED && permit_pause_to_mac &&
	    interface != PHY_INTERFACE_MODE_SGMII)
		ctrl |= YT921X_PORT_CTRL_PAUSE_AN;
    ...
}

Could YT922x use the same condition?

drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2691

Quoted 4 lines
drivers/net/dsa/motorcomm/chip.c +4 -0
+
+	res = yt921x_reg_update_bits(priv, YT922X_PORTn_CTRL(port), mask, ctrl);
+	if (res)
+		return res;

[Severity: Medium]
On the SerDes ports (0 and 8), does anything program the SerDes side with the resolved speed, duplex and link when in-band AN is not used? Examples are SGMII with an out-of-band PHY, or a fixed-link.

As far as I can see, nothing does:

- yt922x_port_up() writes only YT922X_PORTn_CTRL.
- yt922x_pcs_config() writes only the SerDes mode field and BMCR_ANENABLE.
- yt922x_phylink_pcs_ops has no .pcs_link_up.
- yt922x_port_config() sets pp->serdes = true, but no YT922x code reads it.

The YT921x path does this step in yt921x_port_up():

	if (pp->serdes) {
		mask = YT921X_SERDES_SPEED_M;
		ctrl = YT921X_SERDES_SPEED(ps);
		...

If the YT922x PCS works the same way, could a 10/100 link through an SGMII PHY with AN disabled leave the PCS at its default rate while the MAC is forced to 10/100? The link would come up but pass no traffic.

The YT922x register map isn't public, so the MAC-side write may be enough on its own. Could this be confirmed?

[ ... ]

Quoted 8 lines
drivers/net/dsa/motorcomm/chip.c +8 -0
+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);
+
+	switch (interface) {

drivers/net/dsa/motorcomm/chip.c static const struct dsa_switch_ops yt921x_dsa_switch_ops = { · line 2802

Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +10 -0
+	case PHY_INTERFACE_MODE_SGMII:
+	case PHY_INTERFACE_MODE_1000BASEX:
+	case PHY_INTERFACE_MODE_2500BASEX:
+	case PHY_INTERFACE_MODE_USXGMII:
+		return &priv->ports[dp->index].pcs;
+
+	default:
+		return NULL;
+	}
+}

[Severity: Low]
Is PHY_INTERFACE_MODE_100BASEX meant to be supported on YT922x?

Some of the code handles it:

- yt922x_port_config() accepts it.
- yt922x_pcs_config() programs YT922X_SERDES_MODE_100BASEX.
- yt922x_pcs_get_state() has a dedicated 100BASEX branch.

Other places leave it out:

- yt922x_dsa_phylink_get_caps() does not set it in config->supported_interfaces.
- yt922x_pcs_setup() does not set it in pcs.supported_interfaces.
- yt922x_phylink_mac_select_pcs() returns NULL for it.

phylink will reject 100base-x, so the 100BASEX handling looks like dead code. Should 100BASEX be added to the caps and the PCS selection, or dropped?

Also, yt922x_phylink_pcs_ops has no .pcs_inband_caps. yt921x_phylink_pcs_ops has yt921x_phylink_pcs_inband_caps(), which limits 100BASEX to LINK_INBAND_DISABLE. Should YT922x provide one as well, so phylink knows the in-band limits of the PCS?

[ ... ]

Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +2 -0
@@ -2586,12 +3069,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",

drivers/net/dsa/motorcomm/chip.c static const struct yt92xx_series yt92xx_series_table[] = { · line 3083

Quoted 10 lines
drivers/net/dsa/motorcomm/chip.c +9 -0
+		.max_ports = YT922X_PORT_NUM,
+		.num_lag_ids = YT922X_LAG_NUM,
+		.ageing_time_min = 1 * 6000,
+		.ageing_time_max = U16_MAX * 6000,
+		.dscp_prio_mapping_is_global = true,
+		.assisted_learning_on_cpu_port = true,
+		.switch_ops = &yt922x_dsa_switch_ops,
+		.mac_ops = &yt922x_phylink_mac_ops,
+	},
 };

[Severity: Low]
Do these capabilities match what yt922x_dsa_switch_ops implements?

yt92xx_register_switch() copies these fields into struct dsa_switch:

- num_lag_ids
- ageing_time_min/max
- dscp_prio_mapping_is_global
- assisted_learning_on_cpu_port

yt922x_dsa_switch_ops only has get_tag_protocol, phylink_get_caps, port_setup and setup. There is no port_lag_join, set_ageing_time, port_fdb_add/del or DSCP op.

With assisted_learning_on_cpu_port set, the DSA core will try to program host FDB entries. dsa_user_fdb_event() then returns -EOPNOTSUPP because port_fdb_add/del are missing.

Nothing breaks at runtime today. Should these fields stay unset until the matching ops are added? They look copied from the YT921x entry.

[ ... ]

drivers/net/dsa/motorcomm/chip.c static int yt921x_mdio_probe(struct mdio_device *mdiodev) · line 3215

Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +1 -0
@@ -2716,6 +3210,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 
 static const struct of_device_id yt921x_of_match[] = {
 	{ .compatible = "motorcomm,yt9215" },
+	{ .compatible = "motorcomm,yt9224" },
 	{}
 };

[Severity: Medium]
Is a binding update for this compatible missing from the series?

Documentation/devicetree/bindings/net/dsa/motorcomm,yt921x.yaml still has:

    const: motorcomm,yt9215

Its description only covers the YT9213/4/5/8 port layouts. YT9224 has a different layout: internal PHYs on ports 4-7, SerDes on ports 0 and 8, and no xMII.

Any DTS using motorcomm,yt9224 would fail dtbs_check. checkpatch will also warn about an undocumented compatible.

[ ... ]

Quoted 5 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +0 -0
new file mode 100644
index 0000000000000..5ad7873e0df7e

[ ... ]

Quoted 2 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +2 -0
+static void yt922x_pcs_an_restart(struct phylink_pcs *pcs)
+{

[ ... ]

drivers/net/dsa/motorcomm/pcs-922x.c line 110

Quoted 7 lines
drivers/net/dsa/motorcomm/pcs-922x.c new file +7 -0
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_intif_read(priv, addr, MII_BMCR, &bmcr);
+	if (res)
+		goto err;
+	bmcr |= BMCR_ANRESTART;
+	bmcr |= BMCR_RESET;
+	res = yt921x_intif_write(priv, addr, MII_BMCR, bmcr);

[Severity: Medium]
Is BMCR_RESET intended here?

This PCS is driven as a Clause 22 device. get_state uses MII_BMSR/MII_LPA and phylink_mii_c22_pcs_decode_state().

On such a PCS, BMCR bit 15 resets the control registers to their defaults. Could that wipe out the MII_ADVERTISE value and the BMCR_ANENABLE state that yt922x_pcs_config() just wrote? The code also does not wait for the self-clearing reset to complete.

This path runs right after configuration. yt922x_pcs_config() reports a change even when only ANENABLE toggles:

	changed |= (bmcr_new != bmcr_old);

So for 1000BASE-X/2500BASE-X with in-band AN, the first major config returns > 0 and phylink then calls pcs_an_restart. Running ethtool -r on the port takes the same path through phylink_ethtool_nway_reset().

The YT921x version, yt921x_phylink_pcs_an_restart(), only sets BMCR_ANRESTART. yt921x_serdes_config() also clears changed when ANENABLE toggles:

	/* If the ANENABLE bit was changed, the PHY will restart negotiation,
	 * so we don't need to flag a change to trigger its own restart.
	 */
	if (bmcr != val)
		changed = false;

Should YT922x follow the same approach?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261020111115.3072180-1-kyle.switch%40motor-comm.com
maintainer
#10 lore raw
In reply to Kyle Switch
Quoted 3 lines · On Tue, 20 Oct 2026 19:11:10 +0800 Kyle Switch wrote:

This patchset mainly adds support for the yt922x series to the dsa driver. Currently, only the yt9224 in the yt922x series is supported, and the corresponding tag handling for yt922x is added.

## Form letter - net-next-closed

The merge window for Linux v7.4 has begun, and the net-next tree is now closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.

Please repost when net-next reopens. There is some uncertainty about how long this merge window will last, so please check
https://netdev.bots.linux.dev/net-next.html
before reposting. net-next _may_ reopen on Nov 2nd.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle

Signature · 2 lines
pw-bot: defer
pv-bot: closed