Skip to contentSkip to conversation

net: dsa: motorcomm: refactor registration path for upcoming switch families

PATCH In review Kyle Switch 3 participants 22 messages Sep 4 – Sep 7

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/6 net: dsa: motorcomm: refactor registration path for upcoming switch families

Introduce yt92xx_series_info structure to hold private data for different switch families, replacing hardcoded logic in probe(). This makes the driver more extensible for future switch support.

---
 drivers/net/dsa/motorcomm/chip.c | 82 +++++++++++++++++++++++++++-----
 drivers/net/dsa/motorcomm/chip.h | 20 ++++++++
 2 files changed, 91 insertions(+), 11 deletions(-)
drivers/net/dsa/motorcomm/chip.c +71 -11
index d663af010f43..557a0e07d8d7 100644
@@ -4679,6 +4679,68 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
 	.setup			= yt921x_dsa_setup,
 };
 
+static const struct yt92xx_series_info yt92xx_series_info_table[] = {
+	[YT921X] = {
+		.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_info *yt92xx_series_lookup_info(u32 major)
+{
+	enum yt92xx_mode mode = YT_MAX;
+	int i;
+
+	if (major == YT9215_MAJOR || major == YT9218_MAJOR)
+		mode = YT921X;
+
+	for (i = 0; i < ARRAY_SIZE(yt92xx_series_info_table); ++i)
+		if (yt92xx_series_info_table[i].mode == mode)
+			return &yt92xx_series_info_table[i];
+
+	return NULL;
+}
+
+static int yt92xx_register_switch(struct dsa_switch *ds)
+{
+	struct yt921x_priv *priv = to_yt921x_priv(ds);
+	const struct yt92xx_series_info *series_info;
+	u32 chipid;
+	u32 major;
+	int res;
+
+	res = yt921x_reg_read(priv, YT921X_CHIP_ID, &chipid);
+	if (res)
+		return res;
+
+	major = FIELD_GET(YT921X_CHIP_ID_MAJOR, chipid);
+	series_info = yt92xx_series_lookup_info(major);
+	if (!series_info)
+		return -ENODEV;
+	priv->series_info = series_info;
+
+	ds->assisted_learning_on_cpu_port =
+		priv->series_info->assisted_learning_on_cpu_port;
+	ds->dscp_prio_mapping_is_global =
+		priv->series_info->dscp_prio_mapping_is_global;
+	ds->ageing_time_min = priv->series_info->ageing_time_min;
+	ds->ageing_time_max = priv->series_info->ageing_time_max;
+	ds->num_lag_ids = priv->series_info->num_lag_ids;
+	ds->num_ports = priv->series_info->max_ports;
+	ds->ops = priv->series_info->switch_ops;
+	ds->phylink_mac_ops = priv->series_info->mac_ops;
+
+	return 0;
+}
+
 static void yt921x_mdio_shutdown(struct mdio_device *mdiodev)
 {
 	struct yt921x_priv *priv = mdiodev_get_drvdata(mdiodev);
@@ -4727,6 +4789,7 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 	struct yt921x_reg_mdio *mdio;
 	struct yt921x_priv *priv;
 	struct dsa_switch *ds;
+	int res;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -4754,15 +4817,9 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 
 	ds = &priv->ds;
 	ds->dev = dev;
-	ds->assisted_learning_on_cpu_port = true;
-	ds->dscp_prio_mapping_is_global = true;
-	ds->priv = priv;
-	ds->ops = &yt921x_dsa_switch_ops;
-	ds->ageing_time_min = 1 * 5000;
-	ds->ageing_time_max = U16_MAX * 5000;
-	ds->phylink_mac_ops = &yt921x_phylink_mac_ops;
-	ds->num_lag_ids = YT921X_LAG_NUM;
-	ds->num_ports = YT921X_PORT_NUM;
+	res = yt92xx_register_switch(ds);
+	if (res)
+		return res;
 
 	mdiodev_set_drvdata(mdiodev, priv);
 
@@ -4770,8 +4827,11 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 }
 
 static const struct of_device_id yt921x_of_match[] = {
-	{ .compatible = "motorcomm,yt9215" },
-	{}
+	{
+		.compatible = "motorcomm,yt9215",
+		.data = &yt92xx_series_info_table[YT921X],
+	},
+	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, yt921x_of_match);
 
drivers/net/dsa/motorcomm/chip.h +20 -0
index 83cd454955dd..65f9e6234678 100644
@@ -960,9 +960,29 @@ struct yt921x_reg_ops {
 	int (*write)(void *context, u32 reg, u32 val);
 };
 
+enum yt92xx_mode {
+	YT921X,
+	YT922X,
+	YT_MAX,
+};
+
+struct yt92xx_series_info {
+	enum yt92xx_mode mode;
+	const char *name;
+	unsigned int max_ports;
+	unsigned int num_lag_ids;
+	unsigned int ageing_time_min;
+	unsigned int ageing_time_max;
+	u32 dscp_prio_mapping_is_global;
+	u32 assisted_learning_on_cpu_port;
+	const struct dsa_switch_ops *switch_ops;
+	const struct phylink_mac_ops *mac_ops;
+};
+
 struct yt921x_priv {
 	struct dsa_switch ds;
 
+	const struct yt92xx_series_info *series_info;
 	const struct yt921x_info *info;
 	unsigned int meter_slot_ns;
 	unsigned int port_shape_slot_ns;
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 2/6 net: dsa: motorcomm: use max_ports from series_info for port bounds checking

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/chip.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/dsa/motorcomm/chip.c +5 -3
index 557a0e07d8d7..7ae48e6636a0 100644
@@ -357,7 +357,7 @@ static int yt921x_mbus_int_read(struct mii_bus *mbus, int port, int reg)
 	u16 val;
 	int res;
 
-	if (port >= YT921X_PORT_NUM)
+	if (port >= priv->series_info->max_ports)
 		return U16_MAX;
 
 	mutex_lock(&priv->reg_lock);
@@ -375,7 +375,7 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)
 	struct yt921x_priv *priv = mbus->priv;
 	int res;
 
-	if (port >= YT921X_PORT_NUM)
+	if (port >= priv->series_info->max_ports)
 		return -ENODEV;
 
 	mutex_lock(&priv->reg_lock);
@@ -390,6 +390,7 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 {
 	struct device *dev = to_device(priv);
 	struct mii_bus *mbus;
+	u32 max_ports;
 	int res;
 
 	mbus = devm_mdiobus_alloc(dev);
@@ -402,7 +403,8 @@ yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 	mbus->read = yt921x_mbus_int_read;
 	mbus->write = yt921x_mbus_int_write;
 	mbus->parent = dev;
-	mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0);
+	max_ports = priv->series_info->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
maintainer Reviewed-by on v5 2/6
#2 lore raw

Re: [PATCH net-next v5 2/6] net: dsa: motorcomm: use max_ports from series_info for port bounds checking

Quoted 8 lines · 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.

Did you review your own patch? Don't you think it is now a lot easier to see this patch is correct, now that it is short, does one thing and have a commit message focused on just this change.

Andrew

#3 lore raw

Re: [PATCH net-next v5 2/6] net: dsa: motorcomm: use max_ports from series_info for port bounds checking

Quoted 6 lines · Andrew Lunn
Quoted 5 lines · 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.

Quoted 6 lines
Quoted 3 lines

No functional change for existing YT921X devices.

Did you review your own patch? Don't you think it is now a lot easier to see this patch is correct, now that it is short, does one thing and have a commit message focused on just this change.

Ans: yes, by splitting patches so that each patch contains only

one functionality, it becomes more convenient and easier to review

the code logic and whether there are errors. We will follow a similar

approach going forward.

Quoted 3 lines

Andrew

#4 lore raw

PATCH v5 3/6 net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

In reply to Kyle Switch

Move MIB polling start from probe() to dsa_setup() so that it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

---
 drivers/net/dsa/motorcomm/chip.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/dsa/motorcomm/chip.c +8 -7
index 7ae48e6636a0..f74a44048fb1 100644
@@ -4553,6 +4553,14 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 	struct device_node *child;
 	int res;
 
+	/* mib polling init */
+	for (size_t i = 0; i < ARRAY_SIZE(priv->ports); i++) {
+		struct yt921x_port *pp = &priv->ports[i];
+
+		pp->index = i;
+		INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
+	}
+
 	mutex_lock(&priv->reg_lock);
 	res = yt921x_chip_reset(priv);
 	mutex_unlock(&priv->reg_lock);
@@ -4810,13 +4818,6 @@ static int yt921x_mdio_probe(struct mdio_device *mdiodev)
 	priv->reg_ops = &yt921x_reg_ops_mdio;
 	priv->reg_ctx = mdio;
 
-	for (size_t i = 0; i < ARRAY_SIZE(priv->ports); i++) {
-		struct yt921x_port *pp = &priv->ports[i];
-
-		pp->index = i;
-		INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
-	}
-
 	ds = &priv->ds;
 	ds->dev = dev;
 	res = yt92xx_register_switch(ds);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v5 3/6
#5 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

Quoted 5 lines · Kyle Switch

Move MIB polling start from probe() to dsa_setup() so that it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

Much better.

I would word the commit message slightly differently, in order to make it clear what this patch does vs a future patch.

Quoted 4 lines

Move MIB polling start from probe() to dsa_setup() so that in a future patch it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

What you want to avoid is my asking, did you forget to make it conditional?

Andrew

#6 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Kyle Switch

Move MIB polling start from probe() to dsa_setup() so that it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

Much better.

I would word the commit message slightly differently, in order to make it clear what this patch does vs a future patch.

Quoted 7 lines
Quoted 4 lines

Move MIB polling start from probe() to dsa_setup() so that in a future patch it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

What you want to avoid is my asking, did you forget to make it conditional?

Ans: okay,we will improve the commit message and keep this

in mind for future patch submissions.

Quoted 4 lines

Andrew

maintainer
#7 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

In reply to Kyle Switch
Quoted 1 line · Kyle Switch

Move MIB polling start from probe() to dsa_setup()

Actually, having thread the following patches...

For every start, there is generally a stop.

You move start from probe() to dsa_setup().

Should you not move stop from remove() to dsa_teardown()? You want to keep the driver symmetrical.

Andrew

#8 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

Quoted 10 lines · Andrew Lunn
Quoted 1 line · Kyle Switch

Move MIB polling start from probe() to dsa_setup()

Actually, having thread the following patches...

For every start, there is generally a stop.

You move start from probe() to dsa_setup().

Should you not move stop from remove() to dsa_teardown()? You want to keep the driver symmetrical.

Ans, yes, in the next version, we will optimize the handling

of MIB polling enable by moving into setup(), and remove MIB

polling disable into teardown(). From the current perspective, the

mib_init flag is no longer needed.

Quoted 1 line

Andrew

maintainer
#9 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

In reply to Kyle Switch
Quoted 9 lines · Kyle Switch

Move MIB polling start from probe() to dsa_setup() so that it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

---
 drivers/net/dsa/motorcomm/chip.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

I didn't see this patch being used afterwards (and patch 6 seems missing).

I'm not against the patch, but if you don't use it, please post it in another series.

#10 lore raw

Re: [PATCH net-next v5 3/6] net: dsa: motorcomm: relocate MIB polling initialization to dsa_setup()

Quoted 5 lines · David Yang
Quoted 4 lines · Kyle Switch

Move MIB polling start from probe() to dsa_setup() so that it can be conditionally enabled based on the actual switch family support, avoiding attempts to enable it on unsupported switch families.

Quoted 8 lines
Quoted 4 lines
---
  drivers/net/dsa/motorcomm/chip.c | 15 ++++++++-------
  1 file changed, 8 insertions(+), 7 deletions(-)

I didn't see this patch being used afterwards (and patch 6 seems missing).

I'm not against the patch, but if you don't use it, please post it in another series.

Ans: yes, as you can see from x/6, there should be 6 patches in this

series. The 6th patch was not sent successfully due to an email configuration

issue. in the future submissions, we will try our best to ensure the integrity of

the patches. thanks.

#11 lore raw

PATCH v5 4/6 net: dsa: motorcomm: introduce mib_init to control MIB polling initialization

In reply to Kyle Switch

Add a mib_init flag to indicate whether MIB polling has been successfully initialized. This prevents the driver from attempting to clean up MIB-related resources on removal for switch families that do not support MIB polling, which would otherwise trigger errors or crashes.

---
 drivers/net/dsa/motorcomm/chip.c | 2 ++
 drivers/net/dsa/motorcomm/chip.h | 1 +
 2 files changed, 3 insertions(+)
drivers/net/dsa/motorcomm/chip.c +2 -0
index f74a44048fb1..df5c0b995fde 100644
@@ -4559,6 +4559,7 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 
 		pp->index = i;
 		INIT_DELAYED_WORK(&pp->mib_read, yt921x_poll_mib);
+		pp->mib_init = true;
 	}
 
 	mutex_lock(&priv->reg_lock);
@@ -4771,6 +4772,7 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)
 	for (size_t i = ARRAY_SIZE(priv->ports); i-- > 0; ) {
 		struct yt921x_port *pp = &priv->ports[i];
 
+		if (pp->mib_init)
 			disable_delayed_work_sync(&pp->mib_read);
 	}
 
drivers/net/dsa/motorcomm/chip.h +1 -0
index 65f9e6234678..6c89e3d304fa 100644
@@ -943,6 +943,7 @@ struct yt921x_port {
 	struct yt921x_mib mib;
 	u64 rx_frames;
 	u64 tx_frames;
+	bool mib_init;
 
 #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	unsigned char led_duty;
Signature · 1 line
2.25.1
maintainer
#12 lore raw

Re: [PATCH net-next v5 4/6] net: dsa: motorcomm: introduce mib_init to control MIB polling initialization

Quoted 5 lines · Kyle Switch

Add a mib_init flag to indicate whether MIB polling has been successfully initialized. This prevents the driver from attempting to clean up MIB-related resources on removal for switch families that do not support MIB polling, which would otherwise trigger errors or crashes.

This one i'm not convinced about. At some point, you are going to make initialisation of MIBs conditional. Why not use that condition to control removal as well a setup? Why do you need both a conditional and this pp->mib_init state flag?

drivers/net/dsa/motorcomm/chip.c static void yt921x_mdio_remove(struct mdio_device *mdiodev) · line 4776

Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +1 -0
@@ -4771,6 +4772,7 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)
 	for (size_t i = ARRAY_SIZE(priv->ports); i-- > 0; ) {
 		struct yt921x_port *pp = &priv->ports[i];
 
+		if (pp->mib_init)
 			disable_delayed_work_sync(&pp->mib_read);

This looks odd. When adding an if (), you would expect the next line to require an additional indent. Was the indentation already wrong?

Andrew

---
pw-bot: cr

#13 lore raw

Re: [PATCH net-next v5 4/6] net: dsa: motorcomm: introduce mib_init to control MIB polling initialization

Quoted 11 lines · Andrew Lunn
Quoted 5 lines · Kyle Switch

Add a mib_init flag to indicate whether MIB polling has been successfully initialized. This prevents the driver from attempting to clean up MIB-related resources on removal for switch families that do not support MIB polling, which would otherwise trigger errors or crashes.

This one i'm not convinced about. At some point, you are going to make initialisation of MIBs conditional. Why not use that condition to control removal as well a setup? Why do you need both a conditional and this pp->mib_init state flag?

Quoted 8 lines

drivers/net/dsa/motorcomm/chip.c static void yt921x_mdio_remove(struct mdio_device *mdiodev) · line 4776

Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +1 -0
@@ -4771,6 +4772,7 @@ static void yt921x_mdio_remove(struct mdio_device *mdiodev)
  	for (size_t i = ARRAY_SIZE(priv->ports); i-- > 0; ) {
  		struct yt921x_port *pp = &priv->ports[i];
 
+		if (pp->mib_init)
  			disable_delayed_work_sync(&pp->mib_read);

This looks odd. When adding an if (), you would expect the next line to require an additional indent. Was the indentation already wrong?

Ans: In the next version, we will modify patches 3/6 and 4/6 of this series.

Quoted 4 lines

Andrew

---
pw-bot: cr

#14 lore raw

PATCH v5 5/6 net: dsa: tag_922x: add support for Motorcomm YT922x tags

In reply to Kyle Switch

Add support for Motorcomm YT922x tags with 8bytes. which includes ethertype field (default to 0x9988).

---
 include/net/dsa.h    |   2 +
 net/dsa/Kconfig      |   6 +++
 net/dsa/Makefile     |   1 +
 net/dsa/tag_yt922x.c | 112 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 net/dsa/tag_yt922x.c
include/net/dsa.h +2 -0
index 7507d632e7c6..0807a595aaad 100644
@@ -61,6 +61,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_NETC_VALUE		33
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
 #define DSA_TAG_PROTO_MT7628_VALUE		35
+#define DSA_TAG_PROTO_YT922X_VALUE		36
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -99,6 +100,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NETC		= DSA_TAG_PROTO_NETC_VALUE,
 	DSA_TAG_PROTO_KSZ8463		= DSA_TAG_PROTO_KSZ8463_VALUE,
 	DSA_TAG_PROTO_MT7628		= DSA_TAG_PROTO_MT7628_VALUE,
+	DSA_TAG_PROTO_YT922X		= DSA_TAG_PROTO_YT922X_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +6 -0
index 23b4b74004ed..0b9f8a632cf2 100644
@@ -227,4 +227,10 @@ config NET_DSA_TAG_YT921X
 	  Say Y or M if you want to enable support for tagging frames for
 	  Motorcomm YT921x switches.
 
+config NET_DSA_TAG_YT922X
+	tristate "Tag driver for Motorcomm YT922x switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Motorcomm YT922x switches.
+
 endif
net/dsa/Makefile +1 -0
index d15bcf5c68f0..0c53f4184bdb 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
 obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
 obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
 obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o
+obj-$(CONFIG_NET_DSA_TAG_YT922X) += tag_yt922x.o
 
 # for tracing framework to find trace.h
 CFLAGS_trace.o := -I$(src)
net/dsa/tag_yt922x.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#15 lore raw

Re: [PATCH net-next v5 5/6] net: dsa: tag_922x: add support for Motorcomm YT922x tags

Quoted 4 lines · Kyle Switch
net/dsa/tag_yt922x.c new file +4 -0
+       tag[0] = htons(ETH_P_YT921X);
+       if (dp->index != 0) {
+               /* Port index is not equal 0 in tag[1] */
+               ctrl = YT922X_TAG_PRIO(skb->priority) | YT922X_TAG_FORCE_DST |

net/dsa/tag_yt922x.c line 53

Quoted 10 lines
net/dsa/tag_yt922x.c new file +10 -0
+                       YT922X_TAG_PORTS(dsa_xmit_port_mask(skb, netdev));
+               tag[1] = htons(ctrl);
+               tag[2] = 0;
+       } else {
+               /* Port 0 in bit15 in tag[2] */
+               ctrl = YT922X_TAG_PRIO(skb->priority) | YT922X_TAG_FORCE_DST;
+               tag[1] = htons(ctrl);
+               ctrl = YT922X_TAG_PORTMASK_0;
+               tag[2] = htons(ctrl);
+       }

This does not seem correct, as dsa_xmit_port_mask() may return a port combination, including port 0 and non-0 ports.

maintainer
#16 lore raw
In reply to Kyle Switch

Yah! A small patch in a series.

But patch series should have a patch 0/X explaining what the series as a whole does.

git format-patch --cover-letter

Take a look at all the other patch series on netdev.

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

Quoted 8 lines

static const struct of_device_id yt921x_of_match[] = {

drivers/net/dsa/motorcomm/chip.c +5 -2
-	{ .compatible = "motorcomm,yt9215" },
-	{}
+	{
+		.compatible = "motorcomm,yt9215",
+		.data = &yt92xx_series_info_table[YT921X],
+	},
+	{ /* sentinel */ },

There was a patchset of 33 patches posted overnight which removes the , after the sentinel. It would be good not to add one here.

Andrew

---
pw-bot: cr

maintainer
#17 lore raw
In reply to Kyle Switch
Quoted 1 line · Kyle Switch

+ .name = "YT921X",

nit: We usually stylize it with "YT921x".

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

Quoted 6 lines
drivers/net/dsa/motorcomm/chip.c +6 -0
+       if (major == YT9215_MAJOR || major == YT9218_MAJOR)
+               mode = YT921X;
+
+       for (i = 0; i < ARRAY_SIZE(yt92xx_series_info_table); ++i)
+               if (yt92xx_series_info_table[i].mode == mode)
+                       return &yt92xx_series_info_table[i];

Redundant if you use both indexed assignment and lookup routine, since you know the index already.

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

Quoted 6 lines

static const struct of_device_id yt921x_of_match[] = {

drivers/net/dsa/motorcomm/chip.c +3 -2
-       { .compatible = "motorcomm,yt9215" },
-       {}
+       {
+               .compatible = "motorcomm,yt9215",
+               .data = &yt92xx_series_info_table[YT921X],

Redundant if you use both runtime identification and the match data. Also I'm concerned with early IO operations, although I didn't see any incorrectness here.

drivers/net/dsa/motorcomm/chip.h struct yt921x_reg_ops { · line 967

Quoted 5 lines
drivers/net/dsa/motorcomm/chip.h +5 -0
+enum yt92xx_mode {
+       YT921X,
+       YT922X,
+       YT_MAX,
+};

nit: Use prefix/suffix like YT92XX_MODE_YT921X or YT921X_SERIES to avoid too broad names and future name collision.

Quoted 5 lines
 struct yt921x_priv {
        struct dsa_switch ds;
+       const struct yt92xx_series_info *series_info;
        const struct yt921x_info *info;

nit: Better to use const struct yt92xx_series *series for simplicity.

#18 lore raw
Quoted 3 lines · David Yang
Quoted 1 line · Kyle Switch

+ .name = "YT921X",

nit: We usually stylize it with "YT921x".

Ans: okay,will be fixed in next version.

Quoted 16 lines

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

Quoted 7 lines
drivers/net/dsa/motorcomm/chip.c +6 -0
+       if (major == YT9215_MAJOR || major == YT9218_MAJOR)
+               mode = YT921X;
+
+       for (i = 0; i < ARRAY_SIZE(yt92xx_series_info_table); ++i)
+               if (yt92xx_series_info_table[i].mode == mode)
+                       return &yt92xx_series_info_table[i];

Redundant if you use both indexed assignment and lookup routine, since you know the index already.

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

Quoted 6 lines
  static const struct of_device_id yt921x_of_match[] = {
drivers/net/dsa/motorcomm/chip.c +3 -2
-       { .compatible = "motorcomm,yt9215" },
-       {}
+       {
+               .compatible = "motorcomm,yt9215",
+               .data = &yt92xx_series_info_table[YT921X],
Quoted 3 lines

Redundant if you use both runtime identification and the match data. Also I'm concerned with early IO operations, although I didn't see any incorrectness here.

Ans: we have considered this issue before. in the next version, we

will consider whether to do it via chip_detect() or using indexed

assignment. From your suggestion, what are the side effects of each

approach and which of the two approaches do you recommend?

Quoted 8 lines

drivers/net/dsa/motorcomm/chip.h struct yt921x_reg_ops { · line 967

Quoted 6 lines
drivers/net/dsa/motorcomm/chip.h +5 -0
+enum yt92xx_mode {
+       YT921X,
+       YT922X,
+       YT_MAX,
+};

nit: Use prefix/suffix like YT92XX_MODE_YT921X or YT921X_SERIES to avoid too broad names and future name collision.

Ans: okay, will be fixed in next version.

Quoted 6 lines
Quoted 5 lines
  struct yt921x_priv {
         struct dsa_switch ds;
+       const struct yt92xx_series_info *series_info;
         const struct yt921x_info *info;

nit: Better to use const struct yt92xx_series *series for simplicity.

Ans: okay.

maintainer
#19 lore raw
Quoted 10 lines · Kyle Switch
Quoted 9 lines

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

Quoted 6 lines
  static const struct of_device_id yt921x_of_match[] = {
drivers/net/dsa/motorcomm/chip.c +3 -2
-       { .compatible = "motorcomm,yt9215" },
-       {}
+       {
+               .compatible = "motorcomm,yt9215",
+               .data = &yt92xx_series_info_table[YT921X],

Redundant if you use both runtime identification and the match data. Also I'm concerned with early IO operations, although I didn't see any incorrectness here.

Quoted 7 lines

Ans: we have considered this issue before. in the next version, we

will consider whether to do it via chip_detect() or using indexed

assignment. From your suggestion, what are the side effects of each

approach and which of the two approaches do you recommend?

We didn't use compat info since we can do all the probing after the reset, but I think the compat info here is "just enough". You can still change your mind in any series later.

maintainer
#20 lore raw
In reply to Kyle Switch
Quoted 10 lines
Quoted 9 lines

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

Quoted 6 lines
  static const struct of_device_id yt921x_of_match[] = {
drivers/net/dsa/motorcomm/chip.c +3 -2
-       { .compatible = "motorcomm,yt9215" },
-       {}
+       {
+               .compatible = "motorcomm,yt9215",
+               .data = &yt92xx_series_info_table[YT921X],

Redundant if you use both runtime identification and the match data. Also I'm concerned with early IO operations, although I didn't see any incorrectness here.

Quoted 7 lines

Ans: we have considered this issue before. in the next version, we

will consider whether to do it via chip_detect() or using indexed

assignment. From your suggestion, what are the side effects of each

approach and which of the two approaches do you recommend?

One problem with compatible is what do you do when it does not actually match the hardware, because the DT author has messed up?

For the Marvell devices, the compatible only indicates where the ID register can be found, because Marvell likes hide and seek, they keep moving it. Once the ID register is read, it is matched against a table to find the correct structure for that device.

Where compatible are interesting is when the silicon vendor messed up and produced two different devices with the same ID value, or put no ID in the ID register at all. Then you have to work around the silicon vendors mess, and hope the DT author gets it correct.

My suggestion would be to use the ID register and not have compatibles.

Andrew

#21 lore raw
Quoted 24 lines · Andrew Lunn
Quoted 9 lines
Quoted 9 lines

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

Quoted 6 lines
   static const struct of_device_id yt921x_of_match[] = {
drivers/net/dsa/motorcomm/chip.c +3 -2
-       { .compatible = "motorcomm,yt9215" },
-       {}
+       {
+               .compatible = "motorcomm,yt9215",
+               .data = &yt92xx_series_info_table[YT921X],

Redundant if you use both runtime identification and the match data. Also I'm concerned with early IO operations, although I didn't see any incorrectness here.

Quoted 7 lines

Ans: we have considered this issue before. in the next version, we

will consider whether to do it via chip_detect() or using indexed

assignment. From your suggestion, what are the side effects of each

approach and which of the two approaches do you recommend?

One problem with compatible is what do you do when it does not actually match the hardware, because the DT author has messed up?

For the Marvell devices, the compatible only indicates where the ID register can be found, because Marvell likes hide and seek, they keep moving it. Once the ID register is read, it is matched against a table to find the correct structure for that device.

Quoted 7 lines

Where compatible are interesting is when the silicon vendor messed up and produced two different devices with the same ID value, or put no ID in the ID register at all. Then you have to work around the silicon vendors mess, and hope the DT author gets it correct.

My suggestion would be to use the ID register and not have compatibles.

Ans: Now i finally understand why Marvell does this. When i referred

to Marvell implementation before, i had the same question as David-

isn't this redundant? So for the future optimization direction of yt92xx

driver, i can completely do without the compatible info and instead use

chip_detect to match entries in the table. is my understanding correct?

Quoted 1 line

Andrew