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 02/14] net: enetc: decouple MAFT logical config from hardware wire format
Date: Fri, 4 Dec 2026 15:13:58 +0800 [thread overview]
Message-ID: <20261204071410.692071-3-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20261204071410.692071-1-wei.fang@oss.nxp.com>
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement MAFT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
maft_entry_data embeds the version 0 hardware KEYE/CFGE structures
directly, so callers must know the wire format and open-code endianness
conversions. This interface is hard to extend: once a new version
changes the buffer layout or size, updating the callers becomes
cumbersome.
Turn struct maft_entry_data into a version-agnostic config using native
CPU types, and move the wire structures into ntmp_private.h to keep them
internal to the NTMP layer. Add a generic struct ntmp_tbl_ops holding
the buffer sizes and pack()/unpack() callbacks, and select the MAFT
version instance via ntmp_get_maft_ops(). ntmp_maft_add_entry() and
ntmp_maft_query_entry() now marshal through the ops, so callers work
with the logical config and no longer touch the hardware format.
A future version can then be added within the NTMP layer by providing
its wire structure, pack/unpack helpers and ops instance. Callers may
still need small adjustments, but they no longer deal with the wire
format or endianness.
It's worth noting that some inline functions were removed from ntmp.h
because these functions are only used in the nxp-enetc4 driver, which
selects NXP_NTMP and FSL_ENETC_CORE, so ultimately NXP_NETC_LIB will
also be selected. Therefore, these inline functions have no purpose.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
.../ethernet/freescale/enetc/enetc4_debugfs.c | 10 +-
.../net/ethernet/freescale/enetc/enetc4_pf.c | 17 ++--
drivers/net/ethernet/freescale/enetc/ntmp.c | 92 +++++++++++++------
.../ethernet/freescale/enetc/ntmp_private.h | 42 +++++++++
include/linux/fsl/ntmp.h | 44 +++------
5 files changed, 133 insertions(+), 72 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
index c73722e2285f5..dd8689ad1696d 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_debugfs.c
@@ -55,7 +55,7 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data)
struct enetc_pf *pf = enetc_si_priv(s->private);
struct enetc_hw *hw = &pf->si->hw;
int num_si = pf->total_vfs + 1;
- struct maft_entry_data maft;
+ struct maft_entry_data entry;
struct ntmp_user *user;
u32 val, entry_id;
int err = 0;
@@ -86,14 +86,14 @@ static int enetc_mac_filter_show(struct seq_file *s, void *data)
seq_puts(s, "MAC address filter table\n");
for_each_set_bit(entry_id, user->maft_eid_bitmap,
user->maft_num_entries) {
- memset(&maft, 0, sizeof(maft));
- err = ntmp_maft_query_entry(user, entry_id, &maft);
+ memset(&entry, 0, sizeof(entry));
+ entry.entry_id = entry_id;
+ err = ntmp_maft_query_entry(user, &entry);
if (err)
goto unlock_rtnl;
seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n",
- entry_id, maft.keye.mac_addr,
- le16_to_cpu(maft.cfge.si_bitmap));
+ entry_id, entry.mac_addr, entry.si_bitmap);
}
unlock_rtnl:
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
index 3074b8aac556f..756ead4719ae3 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
@@ -96,11 +96,9 @@ static int enetc4_pf_add_maft_entries(struct enetc_pf *pf,
{
struct ntmp_user *user = &pf->si->ntmp_user;
int mac_cnt = netdev_hw_addr_list_count(uc);
- struct maft_entry_data maft = {};
+ struct maft_entry_data entry = {};
struct netdev_hw_addr *ha;
u32 available_entries;
- u16 si_bit = BIT(0);
- u32 entry_id;
int err;
available_entries = user->maft_num_entries -
@@ -110,14 +108,15 @@ static int enetc4_pf_add_maft_entries(struct enetc_pf *pf,
if (mac_cnt > available_entries)
return -ENOSPC;
- maft.cfge.si_bitmap = cpu_to_le16(si_bit);
+ entry.si_bitmap = BIT(0);
netdev_hw_addr_list_for_each(ha, uc) {
- entry_id = ntmp_lookup_free_eid(user->maft_eid_bitmap,
- user->maft_num_entries);
- ether_addr_copy(maft.keye.mac_addr, ha->addr);
- err = ntmp_maft_add_entry(user, entry_id, &maft);
+ entry.entry_id = ntmp_lookup_free_eid(user->maft_eid_bitmap,
+ user->maft_num_entries);
+ ether_addr_copy(entry.mac_addr, ha->addr);
+ err = ntmp_maft_add_entry(user, &entry);
if (unlikely(err)) {
- ntmp_clear_eid_bitmap(user->maft_eid_bitmap, entry_id);
+ ntmp_clear_eid_bitmap(user->maft_eid_bitmap,
+ entry.entry_id);
goto clear_maft_entries;
}
}
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 1fb7aa7a6e62e..21174bf2320a6 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -312,6 +312,41 @@ static const char *ntmp_table_name(int tbl_id)
}
}
+static void ntmp_maft_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct maft_entry_data *e = entry;
+ struct maft_req_add *req = buf;
+
+ memcpy(req->keye.mac_addr, e->mac_addr, ETH_ALEN);
+ req->cfge.si_bitmap = cpu_to_le16(e->si_bitmap);
+}
+
+static void ntmp_maft_unpack_v0(const void *buf, void *entry, bool only_eid)
+{
+ const struct maft_resp_query *resp = buf;
+ struct maft_entry_data *e = entry;
+
+ memcpy(e->mac_addr, resp->keye.mac_addr, ETH_ALEN);
+ e->si_bitmap = le16_to_cpu(resp->cfge.si_bitmap);
+}
+
+static const struct ntmp_tbl_ops maft_ops_v0 = {
+ .req_ua_len = sizeof(struct maft_req_add),
+ .resp_query_len = sizeof(struct maft_resp_query),
+ .pack = ntmp_maft_pack_v0,
+ .unpack = ntmp_maft_unpack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &maft_ops_v0;
+ default:
+ return NULL;
+ }
+}
+
static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
u32 entry_id, u32 req_len, u32 resp_len)
{
@@ -386,26 +421,28 @@ static int ntmp_query_entry_by_id(struct netc_cbdr *cbdr, int tbl_id,
return 0;
}
-int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft)
+int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry)
{
- struct netc_swcbd swcbd = {
- .size = sizeof(struct maft_req_add),
- };
- struct maft_req_add *req;
+ u8 version = user->tbl_ver[NTMP_MAFT_ID];
+ const struct ntmp_tbl_ops *ops;
+ struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
int err;
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_maft_ops(version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = ops->req_ua_len;
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
if (err)
return err;
/* Set mac address filter table request data buffer */
- ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_MAFT_ID], 0, 0,
- entry_id);
- req->keye = maft->keye;
- req->cfge = maft->cfge;
+ ntmp_fill_crd_eid(buf, version, 0, 0, entry->entry_id);
+ ops->pack(entry, buf, 0);
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
NTMP_MAFT_ID, NTMP_CMD_ADD, NTMP_AM_ENTRY_ID);
@@ -413,39 +450,42 @@ int ntmp_maft_add_entry(struct ntmp_user *user, u32 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 add MAFT entry 0x%x, err: %pe\n",
- entry_id, ERR_PTR(err));
+ dev_err(user->dev, "Failed to add %s entry 0x%x, err: %pe\n",
+ ntmp_table_name(NTMP_MAFT_ID), entry->entry_id,
+ ERR_PTR(err));
ntmp_unlock_cbdr(cbdr);
return err;
}
EXPORT_SYMBOL_GPL(ntmp_maft_add_entry);
-int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft)
+int ntmp_maft_query_entry(struct ntmp_user *user,
+ struct maft_entry_data *entry)
{
- struct netc_swcbd swcbd = {
- .size = sizeof(struct maft_resp_query),
- };
- struct maft_resp_query *resp;
- struct ntmp_req_by_eid *req;
+ 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;
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ 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(req, user->tbl_ver[NTMP_MAFT_ID], 0, 0, entry_id);
+ 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, req, &swcbd, true);
+ err = ntmp_query_entry_by_id(cbdr, NTMP_MAFT_ID, buf, &swcbd, true);
if (err)
goto unlock_cbdr;
- resp = (struct maft_resp_query *)req;
- maft->keye = resp->keye;
- maft->cfge = resp->cfge;
+ ops->unpack(buf, entry, false);
unlock_cbdr:
ntmp_unlock_cbdr(cbdr);
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp_private.h b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
index 531ea7ddd1452..4d372dcc6ca31 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -79,6 +79,48 @@ struct ntmp_req_by_eid {
__le32 entry_id;
};
+/**
+ * struct ntmp_tbl_ops - Generic per-table buffer pack/unpack operations
+ * @req_ua_len: The request data buffer length of add or update operation
+ * @resp_query_len: The response data buffer length of query operation
+ * @pack: Pack a logical *_entry_data into the hardware request data buffer.
+ * Used by the add or update operation. access_method selects how the
+ * entry is accessed. Besides entry_id, some tables also support other
+ * access methods such as Exact key or Ternary key, and the format of
+ * the ACCESS_KEY field in the request data differs per method. It has
+ * no effect for tables that only support entry_id access.
+ * @unpack: Unpack the hardware response data buffer into a logical
+ * *_entry_data. Used by the query operation. Note that some tables have
+ * entry IDs assigned by the hardware, the "Add followed by a Query"
+ * command is usually used to get the hardware-generated entry ID. So
+ * only_eid means only unpacking the entry_id responded by the hardware.
+ * It has no effect for tables whose entry IDs are assigned by software.
+ *
+ * This is a generic structure that most NTMP tables can reuse. The buffer
+ * layout of a table may differ between hardware versions, so each table
+ * provides one instance of these operations per supported version. @pack
+ * and @unpack take void pointers because the generic NTMP helpers are
+ * table-agnostic; type safety is enforced by each table's own wrappers,
+ * which cast to the concrete *_entry_data and *_req_add / *_req_ua /
+ * *_resp_query types.
+ */
+struct ntmp_tbl_ops {
+ u32 req_ua_len;
+ u32 resp_query_len;
+ void (*pack)(const void *entry, void *buf, int access_method);
+ void (*unpack)(const void *buf, void *entry, bool only_eid);
+};
+
+struct maft_keye_data {
+ u8 mac_addr[ETH_ALEN];
+ __le16 resv;
+};
+
+struct maft_cfge_data {
+ __le16 si_bitmap;
+ __le16 resv;
+};
+
/* MAC Address Filter Table Request Data Buffer Format of Add action */
struct maft_req_add {
struct ntmp_req_by_eid rbe;
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index d21218ad33395..558577c052e77 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -10,15 +10,8 @@
#define NTMP_NULL_ENTRY_ID 0xffffffffU
#define IPFT_MAX_PLD_LEN 24
-struct maft_keye_data {
- u8 mac_addr[ETH_ALEN];
- __le16 resv;
-};
-
-struct maft_cfge_data {
- __le16 si_bitmap;
- __le16 resv;
-};
+/* NTMP table version */
+#define NTMP_TBL_V(x) (x)
struct netc_cbdr_regs {
void __iomem *pir;
@@ -85,8 +78,13 @@ struct ntmp_user {
};
struct maft_entry_data {
- struct maft_keye_data keye;
- struct maft_cfge_data cfge;
+ u32 entry_id;
+
+ /* KEYE_DATA */
+ u8 mac_addr[ETH_ALEN];
+
+ /* CFGE_DATA */
+ u16 si_bitmap;
};
struct ipft_pld_byte {
@@ -290,10 +288,9 @@ u32 ntmp_lookup_free_eid(unsigned long *bitmap, u32 size);
void ntmp_clear_eid_bitmap(unsigned long *bitmap, u32 entry_id);
/* NTMP APIs */
-int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft);
-int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft);
+int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry);
+int ntmp_maft_query_entry(struct ntmp_user *user,
+ struct maft_entry_data *entry);
int ntmp_maft_delete_entry(struct ntmp_user *user, u32 entry_id);
int ntmp_rsst_update_entry(struct ntmp_user *user, const u32 *table,
int count);
@@ -338,23 +335,6 @@ static inline void ntmp_free_cbdr(struct netc_cbdr *cbdr)
{
}
-static inline int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft)
-{
- return 0;
-}
-
-static inline int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id,
- struct maft_entry_data *maft)
-{
- return 0;
-}
-
-static inline int ntmp_maft_delete_entry(struct ntmp_user *user, u32 entry_id)
-{
- return 0;
-}
-
static inline int ntmp_rsst_update_entry(struct ntmp_user *user,
const u32 *table, int count)
{
--
2.34.1
next prev parent reply other threads:[~2026-12-04 7:09 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 ` wei.fang [this message]
2026-12-04 7:13 ` [PATCH net-next 03/14] net: enetc: decouple IPFT logical config from hardware wire format 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 ` [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-3-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