From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v4] net: dsa: motorcomm: Add devlink info and resources
Date: Thu, 12 Nov 2026 08:20:29 +0800 [thread overview]
Message-ID: <20261112002031.1475005-1-mmyangfl@gmail.com> (raw)
Expose the ASIC model via devlink info (ASIC_ID), and register devlink
resources for ACLs and meters.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v4:
- remove FDB-related changes
v3: https://lore.kernel.org/r/20261109163117.1792478-1-mmyangfl@gmail.com
- remove the buggy sub-resources
v2: https://lore.kernel.org/r/20261108094512.1285796-1-mmyangfl@gmail.com
- fix issues reported by sashiko
v1: https://lore.kernel.org/r/20261106184811.350700-1-mmyangfl@gmail.com
drivers/net/dsa/motorcomm/Makefile | 1 +
drivers/net/dsa/motorcomm/chip.c | 8 ++
drivers/net/dsa/motorcomm/chip.h | 2 +
drivers/net/dsa/motorcomm/devlink.c | 111 ++++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/devlink.h | 18 +++++
5 files changed, 140 insertions(+)
create mode 100644 drivers/net/dsa/motorcomm/devlink.c
create mode 100644 drivers/net/dsa/motorcomm/devlink.h
diff --git a/drivers/net/dsa/motorcomm/Makefile b/drivers/net/dsa/motorcomm/Makefile
index 9eaa59f699e8..0b31d815ce43 100644
--- a/drivers/net/dsa/motorcomm/Makefile
+++ b/drivers/net/dsa/motorcomm/Makefile
@@ -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
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index a1d0ce35f4f3..855637d0548d 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -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,
};
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index fc315f1d8f87..55a36716266c 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -248,6 +248,7 @@ enum yt921x_app_selector {
#define YT921X_PORT_LEARN_MODE_AUTO YT921X_PORT_LEARN_MODE(0)
#define YT921X_PORT_LEARN_MODE_AUTO_AND_COPY YT921X_PORT_LEARN_MODE(1)
#define YT921X_PORT_LEARN_MODE_CPU_CONTROL YT921X_PORT_LEARN_MODE(2)
+#define YT921X_LEARN_UCAST_CNT 0x18043c
#define YT921X_AGEING 0x180440
#define YT921X_AGEING_INTERVAL_M GENMASK(15, 0)
#define YT921X_FDB_IN0 0x180454
@@ -312,6 +313,7 @@ enum yt921x_app_selector {
#define YT921X_FDB_IO2_PRIO(x) FIELD_PREP(YT921X_FDB_IO2_PRIO_M, (x))
#define YT921X_FDB_IO2_NEW_VID_M GENMASK(11, 0)
#define YT921X_FDB_IO2_NEW_VID(x) FIELD_PREP(YT921X_FDB_IO2_NEW_VID_M, (x))
+#define YT921X_LEARN_MCAST_CNT 0x180504
#define YT921X_FILTER_UNK_UCAST 0x180508
#define YT921X_FILTER_UNK_MCAST 0x18050c
#define YT921X_FILTER_MCAST 0x180510
diff --git a/drivers/net/dsa/motorcomm/devlink.c b/drivers/net/dsa/motorcomm/devlink.c
new file mode 100644
index 000000000000..6be9630e1e5e
--- /dev/null
+++ b/drivers/net/dsa/motorcomm/devlink.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 David Yang
+ */
+
+#include "chip.h"
+#include "devlink.h"
+#include "tc.h"
+
+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;
+
+ if (!priv->info)
+ return -ENODEV;
+
+ res = devlink_info_version_fixed_put(req,
+ DEVLINK_INFO_VERSION_GENERIC_ASIC_ID,
+ priv->info->name);
+ if (res)
+ return res;
+
+ return 0;
+}
+
+static u64 yt921x_devlink_occ_get_acl(void *ctx)
+{
+ struct yt921x_priv *priv = ctx;
+ unsigned int count = 0;
+
+ mutex_lock(&priv->reg_lock);
+ for (unsigned int i = 0; i < YT921X_ACL_BLK_NUM; i++)
+ count += hweight8(priv->acl_masks[i]);
+ mutex_unlock(&priv->reg_lock);
+
+ return count;
+}
+
+static u64 yt921x_devlink_occ_get_meter(void *ctx)
+{
+ struct yt921x_priv *priv = ctx;
+ u64 count;
+
+ mutex_lock(&priv->reg_lock);
+ count = bitmap_weight(priv->meters_map, YT921X_METER_NUM);
+ mutex_unlock(&priv->reg_lock);
+
+ return count;
+}
+
+enum yt921x_devlink_resource_id {
+ YT921X_DEVLINK_RESOURCE_ID_NONE, /* DEVLINK_RESOURCE_ID_PARENT_TOP */
+ YT921X_DEVLINK_RESOURCE_ID_ACL,
+ YT921X_DEVLINK_RESOURCE_ID_METER,
+};
+
+struct yt921x_devlink_resource {
+ const char *name;
+ devlink_resource_occ_get_t *occ_get;
+ unsigned short size;
+ unsigned char id;
+ unsigned char parent_id;
+};
+
+static const struct yt921x_devlink_resource yt921x_devlink_resources[] = {
+ {
+ "ACL", yt921x_devlink_occ_get_acl,
+ YT921X_ACL_NUM,
+ 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,
+ },
+};
+
+int yt921x_devlink_setup(struct yt921x_priv *priv)
+{
+ struct dsa_switch *ds = &priv->ds;
+ int res;
+
+ for (unsigned int i = 0; i < ARRAY_SIZE(yt921x_devlink_resources);
+ i++) {
+ struct devlink_resource_size_params size_params;
+ const struct yt921x_devlink_resource *r;
+
+ r = &yt921x_devlink_resources[i];
+
+ devlink_resource_size_params_init(&size_params, r->size,
+ r->size, 1,
+ DEVLINK_RESOURCE_UNIT_ENTRY);
+
+ res = dsa_devlink_resource_register(ds, r->name, r->size, r->id,
+ r->parent_id, &size_params);
+ if (res) {
+ dsa_devlink_resources_unregister(ds);
+ return res;
+ }
+
+ dsa_devlink_resource_occ_get_register(ds, r->id, r->occ_get,
+ priv);
+ }
+
+ return 0;
+}
diff --git a/drivers/net/dsa/motorcomm/devlink.h b/drivers/net/dsa/motorcomm/devlink.h
new file mode 100644
index 000000000000..184b9f05742e
--- /dev/null
+++ b/drivers/net/dsa/motorcomm/devlink.h
@@ -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
--
2.53.0
reply other threads:[~2026-11-12 0:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112002031.1475005-1-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®