Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: wei.fang@oss.nxp.com
To: xiaoning.wang@nxp.com, claudiu.manoil@nxp.com,
	vladimir.oltean@nxp.com, andrew@lunn.ch, olteanv@gmail.com,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, chleroy@kernel.org, richardcochran@gmail.com
Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH net-next 14/14] net: enetc: convert the RSST to the generic NTMP entry helpers
Date: Fri,  4 Dec 2026 15:14:10 +0800	[thread overview]
Message-ID: <20261204071410.692071-15-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20261204071410.692071-1-wei.fang@oss.nxp.com>

From: Wei Fang <wei.fang@nxp.com>

The RSS table (RSST) still open-codes its own CBDR sequences for the
update and query operations, duplicating the logic that is now
provided by the generic ntmp_update_entry_by_id() and
ntmp_query_entry_by_id() helpers.

Add a set of table ops for the RSST, moving the packing of the group
values into the request buffer and the unpacking of the queried
groups into ntmp_rsst_pack_v0() and ntmp_rsst_unpack_v0(), and
register them in ntmp_table_ops(). With the ops in place, convert
ntmp_rsst_update_entry() and ntmp_rsst_query_entry() into thin
wrappers around the generic helpers.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/ntmp.c | 109 +++++++++-----------
 1 file changed, 46 insertions(+), 63 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 0622e7e0b5756..1c295dc6d5059 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -347,6 +347,45 @@ static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version)
 	}
 }
 
+static void ntmp_rsst_pack_v0(const void *entry, void *buf, int access_method)
+{
+	struct rsst_req_update *req = buf;
+	const u32 *table = entry;
+
+	for (int i = 0; i < RSST_ENTRY_NUM; i++)
+		req->groups[i] = (u8)(table[i]);
+}
+
+static void ntmp_rsst_unpack_v0(const void *buf, void *entry, bool only_eid)
+{
+	const u8 *group = buf;
+	u32 *table = entry;
+
+	group += NTMP_ENTRY_ID_SIZE + RSST_STSE_DATA_SIZE(RSST_ENTRY_NUM);
+	for (int i = 0; i < RSST_ENTRY_NUM; i++)
+		table[i] = group[i];
+}
+
+static const struct ntmp_tbl_ops rsst_ops_v0 = {
+	.req_ua_len = sizeof(struct ntmp_req_by_eid) +
+		      RSST_CFGE_DATA_SIZE(RSST_ENTRY_NUM),
+	.resp_query_len = NTMP_ENTRY_ID_SIZE +
+			  RSST_CFGE_DATA_SIZE(RSST_ENTRY_NUM) +
+			  RSST_STSE_DATA_SIZE(RSST_ENTRY_NUM),
+	.pack = ntmp_rsst_pack_v0,
+	.unpack = ntmp_rsst_unpack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_rsst_ops(u8 version)
+{
+	switch (version) {
+	case NTMP_TBL_V(0):
+		return &rsst_ops_v0;
+	default:
+		return NULL;
+	}
+}
+
 static void ntmp_ipft_pack_v0(const void *entry, void *buf, int access_method)
 {
 	const struct ipft_entry_data *e = entry;
@@ -670,6 +709,8 @@ static const struct ntmp_tbl_ops *ntmp_table_ops(int tbl_id, u8 version)
 	switch (tbl_id) {
 	case NTMP_MAFT_ID:
 		return ntmp_get_maft_ops(version);
+	case NTMP_RSST_ID:
+		return ntmp_get_rsst_ops(version);
 	case NTMP_IPFT_ID:
 		return ntmp_get_ipft_ops(version);
 	case NTMP_FDBT_ID:
@@ -1002,82 +1043,24 @@ EXPORT_SYMBOL_GPL(ntmp_maft_delete_entry);
 int ntmp_rsst_update_entry(struct ntmp_user *user, const u32 *table,
 			   int count)
 {
-	struct rsst_req_update *req;
-	struct netc_swcbd swcbd;
-	struct netc_cbdr *cbdr;
-	union netc_cbd cbd;
-	int err, i;
-
 	if (count != RSST_ENTRY_NUM)
 		/* HW only takes in a full 64 entry table */
 		return -EINVAL;
 
-	swcbd.size = struct_size(req, groups, count);
-	err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
-	if (err)
-		return err;
-
-	/* Set the request data buffer */
-	ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_RSST_ID], 0,
-			  NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU, 0);
-	for (i = 0; i < count; i++)
-		req->groups[i] = (u8)(table[i]);
-
-	ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
-			      NTMP_RSST_ID, NTMP_CMD_UPDATE, NTMP_AM_ENTRY_ID);
-
-	ntmp_select_and_lock_cbdr(user, &cbdr);
-	err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
-	if (err)
-		dev_err(user->dev, "Failed to update RSST entry, err: %pe\n",
-			ERR_PTR(err));
-	ntmp_unlock_cbdr(cbdr);
-
-	return err;
+	return ntmp_update_entry_by_id(user, NTMP_RSST_ID, 0, (void *)table,
+				       NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU,
+				       0);
 }
 EXPORT_SYMBOL_GPL(ntmp_rsst_update_entry);
 
 int ntmp_rsst_query_entry(struct ntmp_user *user, u32 *table, int count)
 {
-	struct ntmp_req_by_eid *req;
-	struct netc_swcbd swcbd;
-	struct netc_cbdr *cbdr;
-	union netc_cbd cbd;
-	int err, i;
-	u8 *group;
-
 	if (count != RSST_ENTRY_NUM)
 		/* HW only takes in a full 64 entry table */
 		return -EINVAL;
 
-	swcbd.size = NTMP_ENTRY_ID_SIZE + RSST_STSE_DATA_SIZE(count) +
-		     RSST_CFGE_DATA_SIZE(count);
-	err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
-	if (err)
-		return err;
-
-	/* Set the request data buffer */
-	ntmp_fill_crd_eid(req, user->tbl_ver[NTMP_RSST_ID], 0, 0, 0);
-	ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(sizeof(*req), swcbd.size),
-			      NTMP_RSST_ID, NTMP_CMD_QUERY, NTMP_AM_ENTRY_ID);
-
-	ntmp_select_and_lock_cbdr(user, &cbdr);
-	err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
-	if (err) {
-		dev_err(user->dev, "Failed to query RSST entry, err: %pe\n",
-			ERR_PTR(err));
-		goto unlock_cbdr;
-	}
-
-	group = (u8 *)req;
-	group += NTMP_ENTRY_ID_SIZE + RSST_STSE_DATA_SIZE(count);
-	for (i = 0; i < count; i++)
-		table[i] = group[i];
-
-unlock_cbdr:
-	ntmp_unlock_cbdr(cbdr);
-
-	return err;
+	return ntmp_query_entry_by_id(user, NTMP_RSST_ID, 0, (void *)table,
+				      0, false);
 }
 EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry);
 
-- 
2.34.1



      parent reply	other threads:[~2026-12-04  7:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
2026-12-04  7:13 ` [PATCH net-next 01/14] net: enetc: use an ID-indexed array to track NTMP table versions wei.fang
2026-12-04  7:13 ` [PATCH net-next 02/14] net: enetc: decouple MAFT logical config from hardware wire format wei.fang
2026-12-04  7:13 ` [PATCH net-next 03/14] net: enetc: decouple IPFT " wei.fang
2026-12-04  7:14 ` [PATCH net-next 04/14] net: enetc: decouple FDBT " wei.fang
2026-12-04  7:14 ` [PATCH net-next 05/14] net: enetc: decouple VFT " wei.fang
2026-12-04  7:14 ` [PATCH net-next 06/14] net: enetc: decouple ETT " wei.fang
2026-12-04  7:14 ` [PATCH net-next 07/14] net: enetc: decouple BPT " wei.fang
2026-12-04  7:14 ` [PATCH net-next 08/14] net: enetc: add generic ntmp_add_entry_by_id() helper wei.fang
2026-12-04  7:14 ` [PATCH net-next 09/14] net: enetc: simplify callers of ntmp_query_entry_by_id() wei.fang
2026-12-04  7:14 ` [PATCH net-next 10/14] net: enetc: add kernel-doc for ntmp_delete_entry_by_id() wei.fang
2026-12-04  7:14 ` [PATCH net-next 11/14] net: enetc: add a generic helper to update an NTMP entry by entry ID wei.fang
2026-12-04  7:14 ` [PATCH net-next 12/14] net: enetc: convert ntmp_ect_update_entry() to the generic update helper wei.fang
2026-12-04  7:14 ` [PATCH net-next 13/14] net: enetc: add a generic helper to add an NTMP entry by key wei.fang
2026-12-04  7:14 ` wei.fang [this message]

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=20261204071410.692071-15-wei.fang@oss.nxp.com \
    --to=wei.fang@oss.nxp.com \
    --cc=andrew@lunn.ch \
    --cc=chleroy@kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=imx@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wei.fang@nxp.com \
    --cc=xiaoning.wang@nxp.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