Skip to contentSkip to conversation

net: dsa: motorcomm: Add devlink info and resources

PATCH Superseded David Yang 3 participants 4 messages Nov 16 – Nov 18

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

David Yang

author maintainer
#0 lore raw

PATCH v5 1/1 net: dsa: motorcomm: Add devlink info and resources

Expose the ASIC model via devlink info (ASIC_ID), and register devlink resources for ACLs and meters.

---
v5:
- minor stylistic fixes
v4: https://lore.kernel.org/r/[email protected]
- remove FDB-related changes
v3: https://lore.kernel.org/r/[email protected]
- remove the buggy sub-resources
v2: https://lore.kernel.org/r/[email protected]
- fix issues reported by sashiko
v1: https://lore.kernel.org/r/[email protected]

 drivers/net/dsa/motorcomm/Makefile  |   1 +
 drivers/net/dsa/motorcomm/chip.c    |   8 +++
 drivers/net/dsa/motorcomm/devlink.c | 108 ++++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/devlink.h |  18 +++++
 4 files changed, 135 insertions(+)
 create mode 100644 drivers/net/dsa/motorcomm/devlink.c
 create mode 100644 drivers/net/dsa/motorcomm/devlink.h
drivers/net/dsa/motorcomm/Makefile +1 -0
index 9eaa59f699e8..0b31d815ce43 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_NET_DSA_YT921X) += yt921x.o
 yt921x-objs := chip.o
 yt921x-$(CONFIG_NET_DSA_YT921X_LEDS) += leds.o
+yt921x-objs += devlink.o
 yt921x-objs += mdio_bus.o
 yt921x-objs += mib.o
 yt921x-objs += pcs-921x.o
drivers/net/dsa/motorcomm/chip.c +8 -0
index a1d0ce35f4f3..855637d0548d 100644
@@ -26,6 +26,7 @@
 #include <net/ieee8021q.h>
 
 #include "chip.h"
+#include "devlink.h"
 #include "leds.h"
 #include "mdio_bus.h"
 #include "mib.h"
@@ -2141,6 +2142,8 @@ static void yt921x_dsa_teardown(struct dsa_switch *ds)
 
 	yt921x_leds_remove(priv);
 #endif
+
+	dsa_devlink_resources_unregister(ds);
 }
 
 static int yt921x_chip_detect(struct yt921x_priv *priv)
@@ -2475,6 +2478,10 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 	if (res)
 		return res;
 
+	res = yt921x_devlink_setup(priv);
+	if (res)
+		return res;
+
 #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	res = yt921x_leds_setup(priv);
 	if (res)
@@ -2563,6 +2570,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
 	.port_add_dscp_prio	= yt921x_dsa_port_add_dscp_prio,
 #endif
 	/* chip */
+	.devlink_info_get	= yt921x_dsa_devlink_info_get,
 	.teardown		= yt921x_dsa_teardown,
 	.setup			= yt921x_dsa_setup,
 };
drivers/net/dsa/motorcomm/devlink.c new file +108 -0

108 lines not on this page · raw message

drivers/net/dsa/motorcomm/devlink.h new file +18 -0
new file mode 100644
index 000000000000..184b9f05742e
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2026 David Yang
+ */
+
+#ifndef _YT_DEVLINK_H
+#define _YT_DEVLINK_H
+
+#include <net/dsa.h>
+
+struct yt921x_priv;
+
+int
+yt921x_dsa_devlink_info_get(struct dsa_switch *ds, struct devlink_info_req *req,
+			    struct netlink_ext_ack *extack);
+int yt921x_devlink_setup(struct yt921x_priv *priv);
+
+#endif
Signature · 1 line
2.53.0
maintainer
#2 lore raw
In reply to David Yang

This is an AI-generated review of your patch. The human sending this email says "AI is right, see below"
---
net: dsa: motorcomm: Add devlink info and resources

This patch adds devlink support to the yt921x DSA driver. It reports the ASIC model through devlink info as asic.id. It also registers two devlink resources, "ACL" and "meters", each with an occupancy callback.

Quoted 5 lines
drivers/net/dsa/motorcomm/devlink.c new file +0 -0
new file mode 100644
index 0000000000000..7b4f3a460f1b3

[ ... ]

Quoted 10 lines
drivers/net/dsa/motorcomm/devlink.c new file +10 -0
+int
+yt921x_dsa_devlink_info_get(struct dsa_switch *ds, struct devlink_info_req *req,
+			    struct netlink_ext_ack *extack)
+{
+	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	int res;
+
+	res = devlink_info_version_fixed_put(req,
+					     DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
+					     priv->info->name);

[ ... ]

Quoted 4 lines
drivers/net/dsa/motorcomm/devlink.c new file +4 -0
+static const struct yt921x_devlink_resource yt921x_devlink_resources[] = {
+	{
+		"ACL", yt921x_devlink_occ_get_acl,
+		YT921X_ACL_NUM,

drivers/net/dsa/motorcomm/devlink.c line 78

Quoted 10 lines
drivers/net/dsa/motorcomm/devlink.c new file +10 -0
+		YT921X_DEVLINK_RESOURCE_ID_ACL,
+		DEVLINK_RESOURCE_ID_PARENT_TOP,
+	},
+	{
+		"meters", yt921x_devlink_occ_get_meter,
+		YT921X_METER_NUM,
+		YT921X_DEVLINK_RESOURCE_ID_METER,
+		DEVLINK_RESOURCE_ID_PARENT_TOP,
+	},
+};

[Severity: Low]
This isn't a bug, but should there be a driver-specific devlink document for yt921x to go with this patch?

Documentation/networking/devlink/index.rst says:

Each driver that implements ``devlink`` is expected to document what parameters, info versions, and other features it supports.

There is no yt921x or motorcomm .rst file under Documentation/networking/devlink/, and the toctree in index.rst has no entry for it. A similar DSA driver, mv88e6xxx, does have one.

The "ACL" and "meters" resource names are driver-specific, so users of devlink resource show have no documented meaning for them. The same goes for the asic.id value that yt921x_dsa_devlink_info_get() reports.

Also, "meters" counts only the 64 custom meters tracked in priv->meters_map. It leaves out the 11 dedicated per-port meters. The only place that says so is a comment in chip.h:

    /* Custom meters only, not including dedicated port meters (11) */
    #define YT921X_METER_NUM	64

Could a short Documentation/networking/devlink/yt921x.rst describe the info version and the two resources, including what "meters" covers?

Signature · 1 line
pw-bot: cr
maintainer
#3 lore raw
In reply to David Yang

drivers/net/dsa/motorcomm/devlink.c line 86

Quoted 2 lines · On Mon, 16 Nov 2026 20:16:20 +0800 David Yang wrote:
drivers/net/dsa/motorcomm/devlink.c new file +2 -0
+	for (unsigned int i = 0; i < ARRAY_SIZE(yt921x_devlink_resources);
+	     i++) {

you could save yourselves the ugly line wrapping by using a signed type..