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 09/14] net: enetc: simplify callers of ntmp_query_entry_by_id()
Date: Fri,  4 Dec 2026 15:14:05 +0800	[thread overview]
Message-ID: <20261204071410.692071-10-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20261204071410.692071-1-wei.fang@oss.nxp.com>

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

Most NTMP tables can query an entry by its entry ID, and they follow
the same logic. The current ntmp_query_entry_by_id() still leaves the
table ops lookup, buffer allocation, request filling, CBDR locking and
response unpacking to each caller, so every query wrapper duplicates
that boilerplate.

Move this common handling into ntmp_query_entry_by_id() and take the
user, table ID, entry ID and entry data directly, so a caller only
needs a single call. The response entry ID is now read from the first
field of the response buffer, which lets the one-field struct
ntmp_cmn_resp_query be dropped.

Convert the MAFT query path to the reworked helper. More tables will
reuse it later.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/ntmp.c   | 105 ++++++++++--------
 .../ethernet/freescale/enetc/ntmp_private.h   |   4 -
 2 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index fec6c3fcfd2e4..40085fd2fe61d 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -740,48 +740,82 @@ static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
 	return err;
 }
 
-static int ntmp_query_entry_by_id(struct netc_cbdr *cbdr, int tbl_id,
-				  struct ntmp_req_by_eid *req,
-				  struct netc_swcbd *swcbd,
+/**
+ * ntmp_query_entry_by_id - query an entry of a table by its entry ID
+ * @user: target ntmp_user struct
+ * @tbl_id: ID of the target table
+ * @entry_id: the entry ID to query
+ * @entry: used to store the queried entry data
+ * @ua: update actions, some tables support resetting the statistics
+ * after the query, in which case the caller passes the update actions,
+ * otherwise 0
+ * @compare_eid: whether to compare the queried entry ID against the
+ * entry ID returned by the hardware. Only a table whose response data
+ * starts with the entry_id field can set this.
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+static int ntmp_query_entry_by_id(struct ntmp_user *user, int tbl_id,
+				  u32 entry_id, void *entry, u16 ua,
 				  bool compare_eid)
 {
-	u32 len = NTMP_LEN(sizeof(*req), swcbd->size);
-	struct ntmp_cmn_resp_query *resp;
-	int cmd = NTMP_CMD_QUERY;
+	u32 req_len = sizeof(struct ntmp_req_by_eid);
+	int cmd = ua ? NTMP_CMD_QU : NTMP_CMD_QUERY;
+	u8 version = user->tbl_ver[tbl_id];
+	const struct ntmp_tbl_ops *ops;
+	struct netc_swcbd swcbd;
+	struct netc_cbdr *cbdr;
 	union netc_cbd cbd;
-	u32 entry_id;
+	__le32 *resp_eid;
+	void *buf;
+	u32 len;
 	int err;
 
-	entry_id = le32_to_cpu(req->entry_id);
-	if (le16_to_cpu(req->crd.update_act))
-		cmd = NTMP_CMD_QU;
+	ops = ntmp_table_ops(tbl_id, version);
+	if (!ops)
+		return -EOPNOTSUPP;
+
+	swcbd.size = max(req_len, ops->resp_query_len);
+	err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
+	if (err)
+		return err;
 
-	/* Request header */
-	ntmp_fill_request_hdr(&cbd, swcbd->dma, len, tbl_id, cmd,
+	len = NTMP_LEN(req_len, ops->resp_query_len);
+	ntmp_fill_crd_eid(buf, version, 0, ua, entry_id);
+	ntmp_fill_request_hdr(&cbd, swcbd.dma, len, tbl_id, cmd,
 			      NTMP_AM_ENTRY_ID);
-	err = netc_xmit_ntmp_cmd(cbdr, &cbd, swcbd);
+
+	ntmp_select_and_lock_cbdr(user, &cbdr);
+	err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
 	if (err) {
 		dev_err(cbdr->dev,
 			"Failed to query entry 0x%x of %s, err: %pe\n",
 			entry_id, ntmp_table_name(tbl_id), ERR_PTR(err));
-		return err;
+		goto unlock_cbdr;
 	}
 
 	/* For a few tables, the first field of their response data is not
 	 * entry_id, so directly return success.
 	 */
 	if (!compare_eid)
-		return 0;
+		goto unpack_resp_data;
 
-	resp = (struct ntmp_cmn_resp_query *)req;
-	if (unlikely(le32_to_cpu(resp->entry_id) != entry_id)) {
+	resp_eid = buf;
+	if (unlikely(le32_to_cpu(*resp_eid) != entry_id)) {
 		dev_err(cbdr->dev,
 			"%s: query EID 0x%x doesn't match response EID 0x%x\n",
-			ntmp_table_name(tbl_id), entry_id, le32_to_cpu(resp->entry_id));
-		return -EIO;
+			ntmp_table_name(tbl_id), entry_id,
+			le32_to_cpu(*resp_eid));
+		err = -EIO;
+		goto unlock_cbdr;
 	}
 
-	return 0;
+unpack_resp_data:
+	ops->unpack(buf, entry, false);
+unlock_cbdr:
+	ntmp_unlock_cbdr(cbdr);
+
+	return err;
 }
 
 int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry)
@@ -794,35 +828,8 @@ EXPORT_SYMBOL_GPL(ntmp_maft_add_entry);
 int ntmp_maft_query_entry(struct ntmp_user *user,
 			  struct maft_entry_data *entry)
 {
-	u8 version = user->tbl_ver[NTMP_MAFT_ID];
-	const struct ntmp_tbl_ops *ops;
-	struct netc_swcbd swcbd;
-	struct netc_cbdr *cbdr;
-	void *buf;
-	int err;
-
-	ops = ntmp_get_maft_ops(version);
-	if (!ops)
-		return -EOPNOTSUPP;
-
-	swcbd.size = ops->resp_query_len;
-	err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
-	if (err)
-		return err;
-
-	ntmp_fill_crd_eid(buf, version, 0, 0, entry->entry_id);
-
-	ntmp_select_and_lock_cbdr(user, &cbdr);
-	err = ntmp_query_entry_by_id(cbdr, NTMP_MAFT_ID, buf, &swcbd, true);
-	if (err)
-		goto unlock_cbdr;
-
-	ops->unpack(buf, entry, false);
-
-unlock_cbdr:
-	ntmp_unlock_cbdr(cbdr);
-
-	return err;
+	return ntmp_query_entry_by_id(user, NTMP_MAFT_ID, entry->entry_id,
+				      (void *)entry, 0, true);
 }
 EXPORT_SYMBOL_GPL(ntmp_maft_query_entry);
 
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp_private.h b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
index c356060a17bb9..3b16429708653 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -69,10 +69,6 @@ struct ntmp_cmn_req_data {
 				 ((a) & NTMP_QUERY_ACT))
 };
 
-struct ntmp_cmn_resp_query {
-	__le32 entry_id;
-};
-
 /* Generic structure for request data by entry ID  */
 struct ntmp_req_by_eid {
 	struct ntmp_cmn_req_data crd;
-- 
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 ` wei.fang [this message]
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 ` [PATCH net-next 14/14] net: enetc: convert the RSST to the generic NTMP entry helpers wei.fang

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-10-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