* [PATCH net-next 01/14] net: enetc: use an ID-indexed array to track NTMP table versions
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 ` wei.fang
2026-12-04 7:13 ` [PATCH net-next 02/14] net: enetc: decouple MAFT logical config from hardware wire format wei.fang
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:13 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
The NTMP table versions are kept in struct netc_tbl_vers, one named
u8 field per table, while the table IDs are duplicated as private
macros in ntmp.c. Callers must pick the right field by hand, and the
version has to be passed around even though the table ID is known.
Move the table IDs into a public enum ntmp_tbl_id with an
NTMP_TBL_MAX_ID sentinel, and replace the per-table fields with a
single u8 tbl_ver[NTMP_TBL_MAX_ID] indexed by table ID. Update the
call sites accordingly and drop the redundant tbl_ver argument from
ntmp_delete_entry_by_id().
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 2 +-
.../net/ethernet/freescale/enetc/enetc4_pf.c | 2 +-
drivers/net/ethernet/freescale/enetc/ntmp.c | 67 ++++++++-----------
include/linux/fsl/ntmp.h | 23 ++++---
4 files changed, 43 insertions(+), 51 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index 6c19b3a811aa9..b071c0c1e46a5 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -397,7 +397,7 @@ static void netc_init_ntmp_tbl_versions(struct netc_switch *priv)
struct ntmp_user *ntmp = &priv->ntmp;
/* All tables default to version 0 */
- memset(&ntmp->tbl, 0, sizeof(ntmp->tbl));
+ memset(ntmp->tbl_ver, 0, sizeof(ntmp->tbl_ver));
}
static int netc_init_all_cbdrs(struct netc_switch *priv)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
index b7e7201e6a71a..3074b8aac556f 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
@@ -470,7 +470,7 @@ static int enetc4_init_ntmp_user(struct enetc_si *si)
int err;
/* For ENETC 4.1, all table versions are 0 */
- memset(&user->tbl, 0, sizeof(user->tbl));
+ memset(user->tbl_ver, 0, sizeof(user->tbl_ver));
err = enetc4_setup_cbdr(si);
if (err)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 0d83f0c9dc6ee..1fb7aa7a6e62e 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -18,16 +18,6 @@
#define NTMP_BASE_ADDR_ALIGN 128
#define NTMP_DATA_ADDR_ALIGN 32
-/* Define NTMP Table ID */
-#define NTMP_MAFT_ID 1
-#define NTMP_RSST_ID 3
-#define NTMP_IPFT_ID 13
-#define NTMP_FDBT_ID 15
-#define NTMP_VFT_ID 18
-#define NTMP_ETT_ID 33
-#define NTMP_ECT_ID 39
-#define NTMP_BPT_ID 41
-
/* Generic Update Actions for most tables */
#define NTMP_GEN_UA_CFGEU BIT(0)
#define NTMP_GEN_UA_STSEU BIT(1)
@@ -323,8 +313,7 @@ static const char *ntmp_table_name(int tbl_id)
}
static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
- u8 tbl_ver, u32 entry_id, u32 req_len,
- u32 resp_len)
+ u32 entry_id, u32 req_len, u32 resp_len)
{
struct netc_swcbd swcbd = {
.size = max(req_len, resp_len),
@@ -338,7 +327,7 @@ static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
if (err)
return err;
- ntmp_fill_crd_eid(req, tbl_ver, 0, 0, entry_id);
+ ntmp_fill_crd_eid(req, user->tbl_ver[tbl_id], 0, 0, entry_id);
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(req_len, resp_len),
tbl_id, NTMP_CMD_DELETE, NTMP_AM_ENTRY_ID);
@@ -413,7 +402,8 @@ int ntmp_maft_add_entry(struct ntmp_user *user, u32 entry_id,
return err;
/* Set mac address filter table request data buffer */
- ntmp_fill_crd_eid(&req->rbe, user->tbl.maft_ver, 0, 0, entry_id);
+ ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_MAFT_ID], 0, 0,
+ entry_id);
req->keye = maft->keye;
req->cfge = maft->cfge;
@@ -446,7 +436,7 @@ int ntmp_maft_query_entry(struct ntmp_user *user, u32 entry_id,
if (err)
return err;
- ntmp_fill_crd_eid(req, user->tbl.maft_ver, 0, 0, entry_id);
+ ntmp_fill_crd_eid(req, user->tbl_ver[NTMP_MAFT_ID], 0, 0, entry_id);
ntmp_select_and_lock_cbdr(user, &cbdr);
err = ntmp_query_entry_by_id(cbdr, NTMP_MAFT_ID, req, &swcbd, true);
@@ -466,8 +456,8 @@ EXPORT_SYMBOL_GPL(ntmp_maft_query_entry);
int ntmp_maft_delete_entry(struct ntmp_user *user, u32 entry_id)
{
- return ntmp_delete_entry_by_id(user, NTMP_MAFT_ID, user->tbl.maft_ver,
- entry_id, NTMP_EID_REQ_LEN, 0);
+ return ntmp_delete_entry_by_id(user, NTMP_MAFT_ID, entry_id,
+ NTMP_EID_REQ_LEN, 0);
}
EXPORT_SYMBOL_GPL(ntmp_maft_delete_entry);
@@ -490,7 +480,7 @@ int ntmp_rsst_update_entry(struct ntmp_user *user, const u32 *table,
return err;
/* Set the request data buffer */
- ntmp_fill_crd_eid(&req->rbe, user->tbl.rsst_ver, 0,
+ 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]);
@@ -529,7 +519,7 @@ int ntmp_rsst_query_entry(struct ntmp_user *user, u32 *table, int count)
return err;
/* Set the request data buffer */
- ntmp_fill_crd_eid(req, user->tbl.rsst_ver, 0, 0, 0);
+ 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);
@@ -584,7 +574,7 @@ int ntmp_ipft_add_entry(struct ntmp_user *user,
* the entry. The STSE_DATA is not present in the request data for
* 'Add' operation.
*/
- ntmp_fill_crd(&req->crd, user->tbl.ipft_ver, NTMP_QA_ENTRY_ID,
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_IPFT_ID], NTMP_QA_ENTRY_ID,
NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU);
req->ak.keye = entry->keye;
req->cfge = entry->cfge;
@@ -623,9 +613,7 @@ int ntmp_ipft_delete_entry(struct ntmp_user *user, u32 entry_id)
{
u32 req_len = sizeof(struct ipft_req_qd);
- return ntmp_delete_entry_by_id(user, NTMP_IPFT_ID,
- user->tbl.ipft_ver,
- entry_id, req_len,
+ return ntmp_delete_entry_by_id(user, NTMP_IPFT_ID, entry_id, req_len,
NTMP_STATUS_RESP_LEN);
}
EXPORT_SYMBOL_GPL(ntmp_ipft_delete_entry);
@@ -657,7 +645,7 @@ int ntmp_fdbt_add_entry(struct ntmp_user *user, u32 *entry_id,
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, NTMP_QA_ENTRY_ID,
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], NTMP_QA_ENTRY_ID,
NTMP_GEN_UA_CFGEU);
req->ak.exact.keye = *keye;
req->cfge = *cfge;
@@ -715,7 +703,7 @@ int ntmp_fdbt_update_entry(struct ntmp_user *user, u32 entry_id,
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 0, NTMP_GEN_UA_CFGEU);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, NTMP_GEN_UA_CFGEU);
req->ak.eid.entry_id = cpu_to_le32(entry_id);
req->cfge = *cfge;
@@ -747,9 +735,7 @@ int ntmp_fdbt_delete_entry(struct ntmp_user *user, u32 entry_id)
{
u32 req_len = sizeof(struct fdbt_req_qd);
- return ntmp_delete_entry_by_id(user, NTMP_FDBT_ID,
- user->tbl.fdbt_ver,
- entry_id, req_len,
+ return ntmp_delete_entry_by_id(user, NTMP_FDBT_ID, entry_id, req_len,
NTMP_STATUS_RESP_LEN);
}
EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_entry);
@@ -785,7 +771,7 @@ int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 0, 0);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, 0);
req->ak.search.resume_eid = cpu_to_le32(*resume_entry_id);
req->ak.search.cfge.port_bitmap = cpu_to_le32(BIT(port));
/* Match CFGE_DATA[PORT_BITMAP] field */
@@ -857,7 +843,8 @@ int ntmp_fdbt_update_activity_element(struct ntmp_user *user)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 0, FDBT_UA_ACTEU);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID],
+ 0, FDBT_UA_ACTEU);
req->ak.search.resume_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
req->ak.search.cfge.cfg = cpu_to_le32(FDBT_DYNAMIC);
req->ak.search.cfge_mc = FDBT_CFGE_MC_DYNAMIC;
@@ -910,7 +897,7 @@ int ntmp_fdbt_delete_ageing_entries(struct ntmp_user *user, u8 act_cnt)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 0, 0);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, 0);
req->ak.search.resume_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
req->ak.search.cfge.cfg = cpu_to_le32(FDBT_DYNAMIC);
req->ak.search.acte = act_cnt;
@@ -961,7 +948,7 @@ int ntmp_fdbt_delete_port_dynamic_entries(struct ntmp_user *user, int port)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 0, 0);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, 0);
req->ak.search.resume_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
req->ak.search.cfge.port_bitmap = cpu_to_le32(BIT(port));
req->ak.search.cfge.cfg = cpu_to_le32(FDBT_DYNAMIC);
@@ -1015,7 +1002,8 @@ static int ntmp_vft_set_entry(struct ntmp_user *user, u16 vid, int cmd,
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.vft_ver, 0, NTMP_GEN_UA_CFGEU);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_VFT_ID],
+ 0, NTMP_GEN_UA_CFGEU);
req->ak.exact.vid = cpu_to_le16(vid);
req->cfge = *cfge;
@@ -1101,7 +1089,7 @@ int ntmp_vft_delete_entry(struct ntmp_user *user, u16 vid)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl.vft_ver, 0, 0);
+ ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_VFT_ID], 0, 0);
req->ak.exact.vid = cpu_to_le16(vid);
/* Request header */
@@ -1150,7 +1138,7 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, u32 entry_id,
return err;
/* Request data */
- ntmp_fill_crd_eid(&req->rbe, user->tbl.ett_ver, 0,
+ ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_ETT_ID], 0,
NTMP_GEN_UA_CFGEU, entry_id);
req->cfge = *cfge;
@@ -1220,8 +1208,8 @@ EXPORT_SYMBOL_GPL(ntmp_ett_update_entry);
*/
int ntmp_ett_delete_entry(struct ntmp_user *user, u32 entry_id)
{
- return ntmp_delete_entry_by_id(user, NTMP_ETT_ID, user->tbl.ett_ver,
- entry_id, NTMP_EID_REQ_LEN, 0);
+ return ntmp_delete_entry_by_id(user, NTMP_ETT_ID, entry_id,
+ NTMP_EID_REQ_LEN, 0);
}
EXPORT_SYMBOL_GPL(ntmp_ett_delete_entry);
@@ -1247,7 +1235,8 @@ int ntmp_ect_update_entry(struct ntmp_user *user, u32 entry_id)
return err;
/* Request data */
- ntmp_fill_crd_eid(req, user->tbl.ect_ver, 0, ECT_UA_STSEU, entry_id);
+ ntmp_fill_crd_eid(req, user->tbl_ver[NTMP_ECT_ID], 0,
+ ECT_UA_STSEU, entry_id);
/* Request header */
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
@@ -1284,7 +1273,7 @@ int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
* which is maintained by the hardware. The BPSE_DATA is not present in
* the request data for 'Update' operation.
*/
- ntmp_fill_crd_eid(&req->rbe, user->tbl.bpt_ver, 0,
+ ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_BPT_ID], 0,
NTMP_GEN_UA_CFGEU | BPT_UA_BPSEU, entry_id);
req->cfge = *cfge;
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 764ef28926085..d21218ad33395 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -30,15 +30,18 @@ struct netc_cbdr_regs {
void __iomem *lenr;
};
-struct netc_tbl_vers {
- u8 maft_ver;
- u8 rsst_ver;
- u8 fdbt_ver;
- u8 vft_ver;
- u8 bpt_ver;
- u8 ipft_ver;
- u8 ett_ver;
- u8 ect_ver;
+enum ntmp_tbl_id {
+ NTMP_MAFT_ID = 1,
+ NTMP_RSST_ID = 3,
+ NTMP_IPFT_ID = 13,
+ NTMP_FDBT_ID = 15,
+ NTMP_VFT_ID = 18,
+ NTMP_ETT_ID = 33,
+ NTMP_ECT_ID = 39,
+ NTMP_BPT_ID = 41,
+
+ /* Add new table ID above here */
+ NTMP_TBL_MAX_ID,
};
struct netc_swcbd {
@@ -70,7 +73,7 @@ struct ntmp_user {
int cbdr_num; /* number of control BD ring */
struct device *dev;
struct netc_cbdr *ring;
- struct netc_tbl_vers tbl;
+ u8 tbl_ver[NTMP_TBL_MAX_ID];
/* NTMP table bitmaps for resource management */
u32 ett_bitmap_size;
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 02/14] net: enetc: decouple MAFT logical config from hardware wire format
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
2026-12-04 7:13 ` [PATCH net-next 03/14] net: enetc: decouple IPFT " wei.fang
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:13 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
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
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 03/14] net: enetc: decouple IPFT logical config from hardware wire format
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 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 04/14] net: enetc: decouple FDBT " wei.fang
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:13 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement IPFT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
ipft_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 ipft_entry_data into a version-agnostic logical config, and
move the wire structures into ntmp_private.h to keep them internal to
the NTMP layer. The packet header fields (VLAN TCI, EtherType, IP
addresses and L4 ports) use network byte order to match the kernel
structures the caller copies them from; the remaining control fields
use native CPU types. Add a MAFT-style struct ntmp_tbl_ops instance
holding the buffer sizes and pack()/unpack() callbacks, and select it
via ntmp_get_ipft_ops(). ntmp_ipft_add_entry() now marshals through the
ops, so the caller works with the logical config and no longer touches
the wire format.
A future version can then be added within the NTMP layer by providing
its wire structure, pack/unpack helpers and ops instance.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 18 +--
drivers/net/dsa/netc/netc_ptp.c | 28 ++--
drivers/net/ethernet/freescale/enetc/ntmp.c | 148 ++++++++++++++++--
.../ethernet/freescale/enetc/ntmp_private.h | 42 +++++
include/linux/fsl/ntmp.h | 36 ++---
5 files changed, 210 insertions(+), 62 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index b071c0c1e46a5..9529eb66571c2 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -1883,10 +1883,7 @@ static int netc_port_add_host_flood_rule(struct netc_port *np,
const u8 dmac_mask[ETH_ALEN] = {0x1, 0, 0, 0, 0, 0};
struct netc_switch *priv = np->switch_priv;
struct ipft_entry_data *host_flood;
- struct ipft_keye_data *keye;
- struct ipft_cfge_data *cfge;
- u16 src_port;
- u32 cfg;
+ struct ipft_entry_keye *keye;
int err;
if (!uc && !mc)
@@ -1897,11 +1894,10 @@ static int netc_port_add_host_flood_rule(struct netc_port *np,
return -ENOMEM;
keye = &host_flood->keye;
- cfge = &host_flood->cfge;
-
- src_port = FIELD_PREP(IPFT_SRC_PORT, np->dp->index);
- src_port |= IPFT_SRC_PORT_MASK;
- keye->src_port = cpu_to_le16(src_port);
+ keye->src_port = FIELD_PREP(IPFT_SRC_PORT, np->dp->index) |
+ IPFT_SRC_PORT_MASK;
+ host_flood->cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT) |
+ FIELD_PREP(IPFT_HR, NETC_HR_HOST_FLOOD);
/* If either only unicast or only multicast need to be flooded
* to the host, we always set the mask that tests the first MAC
@@ -1918,10 +1914,6 @@ static int netc_port_add_host_flood_rule(struct netc_port *np,
ether_addr_copy(keye->dmac_mask, dmac_mask);
}
- cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT);
- cfg |= FIELD_PREP(IPFT_HR, NETC_HR_HOST_FLOOD);
- cfge->cfg = cpu_to_le32(cfg);
-
err = ntmp_ipft_add_entry(&priv->ntmp, host_flood);
if (err)
goto free_host_flood;
diff --git a/drivers/net/dsa/netc/netc_ptp.c b/drivers/net/dsa/netc/netc_ptp.c
index 46aa3b7ba2d2e..b27674486c8d3 100644
--- a/drivers/net/dsa/netc/netc_ptp.c
+++ b/drivers/net/dsa/netc/netc_ptp.c
@@ -454,15 +454,15 @@ static int netc_port_del_ptp_filter(struct netc_port *np)
return ret;
}
-static int netc_build_ptp_ipft_keye(struct ipft_keye_data *keye, int port,
+static int netc_build_ptp_ipft_keye(struct ipft_entry_data *entry, int port,
enum netc_ptp_type type)
{
- u16 src_port, frm_attr_flags;
+ struct ipft_entry_keye *keye = &entry->keye;
+ u16 frm_attr_flags;
- keye->precedence = cpu_to_le16(NETC_IPFT_PTP_PRECEDENCE);
- src_port = FIELD_PREP(IPFT_SRC_PORT, port);
- src_port |= IPFT_SRC_PORT_MASK;
- keye->src_port = cpu_to_le16(src_port);
+ keye->precedence = NETC_IPFT_PTP_PRECEDENCE;
+ keye->src_port = FIELD_PREP(IPFT_SRC_PORT, port) |
+ IPFT_SRC_PORT_MASK;
switch (type) {
case NETC_PTP_L2:
@@ -479,11 +479,11 @@ static int netc_build_ptp_ipft_keye(struct ipft_keye_data *keye, int port,
type == NETC_PTP_L4_IPV6_GENERAL)
frm_attr_flags |= IPFT_FAF_IP_VER6;
- keye->frm_attr_flags = cpu_to_le16(frm_attr_flags);
+ keye->frm_attr_flags = frm_attr_flags;
/* Update frm_attr_flags to reuse it as the mask */
frm_attr_flags |= IPFT_FAF_IP_VER6 | IPFT_FAF_L4_CODE;
- keye->frm_attr_flags_mask = cpu_to_le16(frm_attr_flags);
+ keye->frm_attr_flags_mask = frm_attr_flags;
keye->ip_protocol = IPPROTO_UDP;
keye->ip_protocol_mask = 0xff;
@@ -507,23 +507,19 @@ static int netc_port_add_ipft_ptp_entry(struct netc_port *np,
{
struct netc_switch *priv = np->switch_priv;
struct ipft_entry_data *entry;
- struct ipft_keye_data *keye;
- u32 cfg;
int err;
entry = kzalloc_obj(*entry);
if (!entry)
return -ENOMEM;
- keye = &entry->keye;
- err = netc_build_ptp_ipft_keye(keye, np->dp->index, type);
+ err = netc_build_ptp_ipft_keye(entry, np->dp->index, type);
if (err)
goto free_entry;
- cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT);
- cfg |= FIELD_PREP(IPFT_HR, NETC_HR_PTP_TRAP);
- cfg |= IPFT_TIMECAPE | IPFT_RRT;
- entry->cfge.cfg = cpu_to_le32(cfg);
+ entry->cfg = FIELD_PREP(IPFT_FLTFA, IPFT_FLTFA_REDIRECT) |
+ FIELD_PREP(IPFT_HR, NETC_HR_PTP_TRAP) |
+ IPFT_TIMECAPE | IPFT_RRT;
err = ntmp_ipft_add_entry(&priv->ntmp, entry);
if (err)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 21174bf2320a6..6143e8b5c6b1f 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -347,6 +347,127 @@ static const struct ntmp_tbl_ops *ntmp_get_maft_ops(u8 version)
}
}
+static void ntmp_ipft_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct ipft_entry_data *e = entry;
+ struct ipft_req_ua *req = buf;
+ struct ipft_cfge_data *cfge;
+
+ if (access_method == NTMP_AM_TERNARY_KEY) {
+ struct ipft_keye_data *keye = &req->ak.keye;
+ const struct ipft_entry_keye *k = &e->keye;
+
+ keye->precedence = cpu_to_le16(k->precedence);
+ keye->frm_attr_flags = cpu_to_le16(k->frm_attr_flags);
+ keye->frm_attr_flags_mask = cpu_to_le16(k->frm_attr_flags_mask);
+ keye->dscp = cpu_to_le16(k->dscp);
+ keye->src_port = cpu_to_le16(k->src_port);
+ keye->outer_vlan_tci = k->outer_vlan_tci;
+ keye->outer_vlan_tci_mask = k->outer_vlan_tci_mask;
+
+ memcpy(keye->dmac, k->dmac, ETH_ALEN);
+ memcpy(keye->dmac_mask, k->dmac_mask, ETH_ALEN);
+ memcpy(keye->smac, k->smac, ETH_ALEN);
+ memcpy(keye->smac_mask, k->smac_mask, ETH_ALEN);
+
+ keye->inner_vlan_tci = k->inner_vlan_tci;
+ keye->inner_vlan_tci_mask = k->inner_vlan_tci_mask;
+ keye->ethertype = k->ethertype;
+ keye->ethertype_mask = k->ethertype_mask;
+ keye->ip_protocol = k->ip_protocol;
+ keye->ip_protocol_mask = k->ip_protocol_mask;
+
+ for (int i = 0; i < 4; i++) {
+ keye->ip_src[i] = k->ip_src[i];
+ keye->ip_src_mask[i] = k->ip_src_mask[i];
+ keye->ip_dst[i] = k->ip_dst[i];
+ keye->ip_dst_mask[i] = k->ip_dst_mask[i];
+ }
+
+ keye->l4_src_port = k->l4_src_port;
+ keye->l4_src_port_mask = k->l4_src_port_mask;
+ keye->l4_dst_port = k->l4_dst_port;
+ keye->l4_dst_port_mask = k->l4_dst_port_mask;
+ memcpy(keye->byte, k->byte, sizeof(keye->byte));
+ } else { /* NTMP_AM_ENTRY_ID */
+ req->ak.eid.entry_id = cpu_to_le32(e->entry_id);
+ }
+
+ cfge = &req->cfge;
+ cfge->cfg = cpu_to_le32(e->cfg);
+ cfge->flta_tgt = cpu_to_le32(e->flta_tgt);
+}
+
+static void ntmp_ipft_unpack_v0(const void *buf, void *entry, bool only_eid)
+{
+ const struct ipft_resp_query *resp = buf;
+ const struct ipft_cfge_data *cfge;
+ const struct ipft_keye_data *keye;
+ struct ipft_entry_data *e = entry;
+ struct ipft_entry_keye *k;
+ int i;
+
+ e->entry_id = le32_to_cpu(resp->entry_id);
+ if (only_eid)
+ return;
+
+ keye = &resp->keye;
+ k = &e->keye;
+ k->precedence = le16_to_cpu(keye->precedence);
+ k->frm_attr_flags = le16_to_cpu(keye->frm_attr_flags);
+ k->frm_attr_flags_mask = le16_to_cpu(keye->frm_attr_flags_mask);
+ k->dscp = le16_to_cpu(keye->dscp);
+ k->src_port = le16_to_cpu(keye->src_port);
+ k->outer_vlan_tci = keye->outer_vlan_tci;
+ k->outer_vlan_tci_mask = keye->outer_vlan_tci_mask;
+
+ memcpy(k->dmac, keye->dmac, ETH_ALEN);
+ memcpy(k->dmac_mask, keye->dmac_mask, ETH_ALEN);
+ memcpy(k->smac, keye->smac, ETH_ALEN);
+ memcpy(k->smac_mask, keye->smac_mask, ETH_ALEN);
+
+ k->inner_vlan_tci = keye->inner_vlan_tci;
+ k->inner_vlan_tci_mask = keye->inner_vlan_tci_mask;
+ k->ethertype = keye->ethertype;
+ k->ethertype_mask = keye->ethertype_mask;
+ k->ip_protocol = keye->ip_protocol;
+ k->ip_protocol_mask = keye->ip_protocol_mask;
+
+ for (i = 0; i < 4; i++) {
+ k->ip_src[i] = keye->ip_src[i];
+ k->ip_src_mask[i] = keye->ip_src_mask[i];
+ k->ip_dst[i] = keye->ip_dst[i];
+ k->ip_dst_mask[i] = keye->ip_dst_mask[i];
+ }
+
+ k->l4_src_port = keye->l4_src_port;
+ k->l4_src_port_mask = keye->l4_src_port_mask;
+ k->l4_dst_port = keye->l4_dst_port;
+ k->l4_dst_port_mask = keye->l4_dst_port_mask;
+ memcpy(k->byte, keye->byte, sizeof(k->byte));
+
+ cfge = &resp->cfge;
+ e->cfg = le32_to_cpu(cfge->cfg);
+ e->flta_tgt = le32_to_cpu(cfge->flta_tgt);
+}
+
+static const struct ntmp_tbl_ops ipft_ops_v0 = {
+ .req_ua_len = sizeof(struct ipft_req_ua),
+ .resp_query_len = sizeof(struct ipft_resp_query),
+ .pack = ntmp_ipft_pack_v0,
+ .unpack = ntmp_ipft_unpack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_ipft_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &ipft_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)
{
@@ -586,8 +707,8 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry);
/**
* ntmp_ipft_add_entry - add an entry into the ingress port filter table
* @user: target ntmp_user struct
- * @entry: the entry data, entry->cfge (configuration element data) and
- * entry->keye (key element data) are used as input. Since the entry ID
+ * @entry: the entry data, the configuration element data (CFGE_DATA) and
+ * the key element data (KEYE_DATA) are used as input. Since the entry ID
* is assigned by the hardware, so entry->entry_id is a returned value
* for the driver to use, the driver can update/delete/query the entry
* based on the entry_id.
@@ -597,16 +718,21 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry);
int ntmp_ipft_add_entry(struct ntmp_user *user,
struct ipft_entry_data *entry)
{
- struct ipft_resp_query *resp;
- struct ipft_req_ua *req;
+ u8 version = user->tbl_ver[NTMP_IPFT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
u32 len;
int err;
- swcbd.size = sizeof(*resp);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_ipft_ops(version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
if (err)
return err;
@@ -614,12 +740,11 @@ int ntmp_ipft_add_entry(struct ntmp_user *user,
* the entry. The STSE_DATA is not present in the request data for
* 'Add' operation.
*/
- ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_IPFT_ID], NTMP_QA_ENTRY_ID,
+ ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID,
NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU);
- req->ak.keye = entry->keye;
- req->cfge = entry->cfge;
+ ops->pack(entry, buf, NTMP_AM_TERNARY_KEY);
- len = NTMP_LEN(sizeof(*req), swcbd.size);
+ len = NTMP_LEN(ops->req_ua_len, swcbd.size);
ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_IPFT_ID,
NTMP_CMD_AQ, NTMP_AM_TERNARY_KEY);
@@ -632,8 +757,7 @@ int ntmp_ipft_add_entry(struct ntmp_user *user,
goto unlock_cbdr;
}
- resp = (struct ipft_resp_query *)req;
- entry->entry_id = le32_to_cpu(resp->entry_id);
+ ops->unpack(buf, entry, true);
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 4d372dcc6ca31..5dcfc98b51066 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -141,6 +141,48 @@ struct rsst_req_update {
u8 groups[];
};
+/* Ingress Port Filter Table Key Element Data */
+struct ipft_keye_data {
+ __le16 precedence;
+ __le16 resv0[3];
+ __le16 frm_attr_flags;
+ __le16 frm_attr_flags_mask;
+ __le16 dscp;
+ __le16 src_port; /* This field is reserved for ENETC */
+ __be16 outer_vlan_tci;
+ __be16 outer_vlan_tci_mask;
+ u8 dmac[ETH_ALEN];
+ u8 dmac_mask[ETH_ALEN];
+ u8 smac[ETH_ALEN];
+ u8 smac_mask[ETH_ALEN];
+ __be16 inner_vlan_tci;
+ __be16 inner_vlan_tci_mask;
+ __be16 ethertype;
+ __be16 ethertype_mask;
+ u8 ip_protocol;
+ u8 ip_protocol_mask;
+ __le16 resv1[7];
+ __be32 ip_src[4];
+ __le32 resv2[2];
+ __be32 ip_src_mask[4];
+ __be16 l4_src_port;
+ __be16 l4_src_port_mask;
+ __le32 resv3;
+ __be32 ip_dst[4];
+ __le32 resv4[2];
+ __be32 ip_dst_mask[4];
+ __be16 l4_dst_port;
+ __be16 l4_dst_port_mask;
+ __le32 resv5;
+ struct ipft_pld_byte byte[IPFT_MAX_PLD_LEN];
+};
+
+/* Ingress Port Filter Table Configuration Element Data */
+struct ipft_cfge_data {
+ __le32 cfg;
+ __le32 flta_tgt;
+};
+
/* Ingress Port Filter Table Response Data Buffer Format of Query action */
struct ipft_resp_query {
__le32 status;
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 558577c052e77..226c672c845af 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -92,10 +92,9 @@ struct ipft_pld_byte {
u8 mask;
};
-struct ipft_keye_data {
- __le16 precedence;
- __le16 resv0[3];
- __le16 frm_attr_flags;
+struct ipft_entry_keye {
+ u16 precedence;
+ u16 frm_attr_flags;
#define IPFT_FAF_OVLAN BIT(2)
#define IPFT_FAF_IVLAN BIT(3)
#define IPFT_FAF_IP_HDR BIT(7)
@@ -105,12 +104,12 @@ struct ipft_keye_data {
#define IPFT_FAF_UDP_HDR 2
#define IPFT_FAF_SCTP_HDR 3
#define IPFT_FAF_WOL_MAGIC BIT(12)
- __le16 frm_attr_flags_mask;
- __le16 dscp;
+ u16 frm_attr_flags_mask;
+ u16 dscp;
#define IPFT_DSCP GENMASK(5, 0)
#define IPFT_DSCP_MASK GENMASK(11, 6)
#define IPFT_DSCP_MASK_ALL 0x3f
- __le16 src_port; /* This field is reserved for ENETC */
+ u16 src_port; /* This field is reserved for ENETC */
#define IPFT_SRC_PORT GENMASK(4, 0)
#define IPFT_SRC_PORT_MASK GENMASK(9, 5)
#define IPFT_SRC_PORT_MASK_ALL 0x1f
@@ -126,24 +125,25 @@ struct ipft_keye_data {
__be16 ethertype_mask;
u8 ip_protocol;
u8 ip_protocol_mask;
- __le16 resv1[7];
__be32 ip_src[4];
- __le32 resv2[2];
__be32 ip_src_mask[4];
__be16 l4_src_port;
__be16 l4_src_port_mask;
- __le32 resv3;
__be32 ip_dst[4];
- __le32 resv4[2];
__be32 ip_dst_mask[4];
__be16 l4_dst_port;
__be16 l4_dst_port_mask;
- __le32 resv5;
struct ipft_pld_byte byte[IPFT_MAX_PLD_LEN];
};
-struct ipft_cfge_data {
- __le32 cfg;
+struct ipft_entry_data {
+ u32 entry_id; /* hardware assigns entry ID */
+
+ /* KEYE_DATA */
+ struct ipft_entry_keye keye;
+
+ /* CFGE_DATA */
+ u32 cfg;
#define IPFT_IPV GENMASK(3, 0)
#define IPFT_OIPV BIT(4)
#define IPFT_DR GENMASK(6, 5)
@@ -166,13 +166,7 @@ struct ipft_cfge_data {
#define IPFT_RRT BIT(23)
#define IPFT_BL2F BIT(24)
#define IPFT_EVMEID GENMASK(31, 28)
- __le32 flta_tgt;
-};
-
-struct ipft_entry_data {
- u32 entry_id; /* hardware assigns entry ID */
- struct ipft_keye_data keye;
- struct ipft_cfge_data cfge;
+ u32 flta_tgt;
};
struct fdbt_keye_data {
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 04/14] net: enetc: decouple FDBT logical config from hardware wire format
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (2 preceding siblings ...)
2026-12-04 7:13 ` [PATCH net-next 03/14] net: enetc: decouple IPFT " wei.fang
@ 2026-12-04 7:14 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 05/14] net: enetc: decouple VFT " wei.fang
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement FDBT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
fdbt_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 fdbt_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 struct ntmp_tbl_ops instance holding
the buffer sizes and pack()/unpack() callbacks, and select it via
ntmp_get_fdbt_ops(), following the MAFT and IPFT tables.
Reshape the FDBT interface around the logical config. ntmp_fdbt_add_entry()
and ntmp_fdbt_update_entry() now take a struct fdbt_entry_data pointer
instead of separate keye/cfge pointers and an entry ID. Add a status
field to the logical config to carry the RESUME_ENTRY_ID of a search, so
ntmp_fdbt_search_port_entry() no longer needs a separate resume_entry_id
argument and its caller resumes from entry->status.
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.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 71 ++++----
drivers/net/dsa/netc/netc_switch.h | 4 +-
drivers/net/ethernet/freescale/enetc/ntmp.c | 155 ++++++++++++------
.../ethernet/freescale/enetc/ntmp_private.h | 15 ++
include/linux/fsl/ntmp.h | 35 ++--
5 files changed, 167 insertions(+), 113 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index 9529eb66571c2..9573672d65a3f 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -21,8 +21,8 @@ netc_lookup_fdb_entry(struct netc_switch *priv,
struct netc_fdb_entry *entry;
hlist_for_each_entry(entry, &priv->fdb_list, node)
- if (ether_addr_equal(entry->keye.mac_addr, addr) &&
- le16_to_cpu(entry->keye.fid) == vid)
+ if (ether_addr_equal(entry->data.mac_addr, addr) &&
+ entry->data.fid == vid)
return entry;
return NULL;
@@ -739,26 +739,19 @@ static int netc_port_add_fdb_entry(struct netc_port *np,
{
struct netc_switch *priv = np->switch_priv;
struct netc_fdb_entry *entry;
- struct fdbt_keye_data *keye;
- struct fdbt_cfge_data *cfge;
int port = np->dp->index;
- u32 cfg = 0;
int err;
entry = kzalloc_obj(*entry);
if (!entry)
return -ENOMEM;
- keye = &entry->keye;
- cfge = &entry->cfge;
- ether_addr_copy(keye->mac_addr, addr);
- keye->fid = cpu_to_le16(vid);
-
- cfge->port_bitmap = cpu_to_le32(BIT(port));
- cfge->cfg = cpu_to_le32(cfg);
- cfge->et_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
+ ether_addr_copy(entry->data.mac_addr, addr);
+ entry->data.fid = vid;
+ entry->data.port_bitmap = BIT(port);
+ entry->data.et_eid = NTMP_NULL_ENTRY_ID;
- err = ntmp_fdbt_add_entry(&priv->ntmp, &entry->entry_id, keye, cfge);
+ err = ntmp_fdbt_add_entry(&priv->ntmp, &entry->data);
if (err) {
kfree(entry);
@@ -775,9 +768,8 @@ static int netc_port_set_fdb_entry(struct netc_port *np,
{
struct netc_switch *priv = np->switch_priv;
struct netc_fdb_entry *entry;
- struct fdbt_cfge_data *cfge;
int port = np->dp->index;
- __le32 old_port_bitmap;
+ u32 old_port_bitmap;
int err = 0;
mutex_lock(&priv->fdbt_lock);
@@ -793,24 +785,23 @@ static int netc_port_set_fdb_entry(struct netc_port *np,
goto unlock_fdbt;
}
- cfge = &entry->cfge;
/* If the entry already exists on the port, return 0 directly */
- if (unlikely(cfge->port_bitmap & cpu_to_le32(BIT(port))))
+ if (unlikely(entry->data.port_bitmap & BIT(port)))
goto unlock_fdbt;
/* If the entry already exists, but not on this port, we need to
* update the port bitmap. In general, it should only be valid
* for multicast or broadcast address.
*/
- old_port_bitmap = cfge->port_bitmap;
+ old_port_bitmap = entry->data.port_bitmap;
if (is_multicast_ether_addr(addr))
- cfge->port_bitmap |= cpu_to_le32(BIT(port));
+ entry->data.port_bitmap |= BIT(port);
else
- cfge->port_bitmap = cpu_to_le32(BIT(port));
+ entry->data.port_bitmap = BIT(port);
- err = ntmp_fdbt_update_entry(&priv->ntmp, entry->entry_id, cfge);
+ err = ntmp_fdbt_update_entry(&priv->ntmp, &entry->data);
if (err) {
- cfge->port_bitmap = old_port_bitmap;
+ entry->data.port_bitmap = old_port_bitmap;
dev_err(priv->dev, "Failed to set FDB entry on port %d\n",
port);
}
@@ -827,7 +818,6 @@ static int netc_port_del_fdb_entry(struct netc_port *np,
struct netc_switch *priv = np->switch_priv;
struct ntmp_user *ntmp = &priv->ntmp;
struct netc_fdb_entry *entry;
- struct fdbt_cfge_data *cfge;
int port = np->dp->index;
int err = 0;
@@ -848,25 +838,24 @@ static int netc_port_del_fdb_entry(struct netc_port *np,
*/
goto unlock_fdbt;
- cfge = &entry->cfge;
- if (unlikely(!(cfge->port_bitmap & cpu_to_le32(BIT(port)))))
+ if (unlikely(!(entry->data.port_bitmap & BIT(port))))
goto unlock_fdbt;
- if (cfge->port_bitmap != cpu_to_le32(BIT(port))) {
+ if (entry->data.port_bitmap != BIT(port)) {
/* If the entry also exists on other ports, we need to
* update the entry in the FDB table.
*/
- cfge->port_bitmap &= cpu_to_le32(~BIT(port));
- err = ntmp_fdbt_update_entry(ntmp, entry->entry_id, cfge);
+ entry->data.port_bitmap &= ~BIT(port);
+ err = ntmp_fdbt_update_entry(ntmp, &entry->data);
if (err) {
- cfge->port_bitmap |= cpu_to_le32(BIT(port));
+ entry->data.port_bitmap |= BIT(port);
goto unlock_fdbt;
}
} else {
/* If the entry only exists on this port, just delete
* it from the FDB table.
*/
- err = ntmp_fdbt_delete_entry(ntmp, entry->entry_id);
+ err = ntmp_fdbt_delete_entry(ntmp, entry->data.entry_id);
if (err)
goto unlock_fdbt;
@@ -1818,10 +1807,8 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,
struct netc_switch *priv = ds->priv;
u32 resume_eid = NTMP_NULL_ENTRY_ID;
struct fdbt_entry_data *entry;
- struct fdbt_keye_data *keye;
- struct fdbt_cfge_data *cfge;
- u32 cfg, cnt = 0;
bool is_static;
+ u32 cnt = 0;
int err;
u16 vid;
@@ -1829,24 +1816,22 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,
if (!entry)
return -ENOMEM;
- keye = &entry->keye;
- cfge = &entry->cfge;
mutex_lock(&priv->fdbt_lock);
do {
memset(entry, 0, sizeof(*entry));
- err = ntmp_fdbt_search_port_entry(&priv->ntmp, port,
- &resume_eid, entry);
+ entry->status = resume_eid;
+
+ err = ntmp_fdbt_search_port_entry(&priv->ntmp, port, entry);
if (err || entry->entry_id == NTMP_NULL_ENTRY_ID)
break;
- cfg = le32_to_cpu(cfge->cfg);
- is_static = (cfg & FDBT_DYNAMIC) ? false : true;
- vid = le16_to_cpu(keye->fid);
+ is_static = (entry->cfg & FDBT_DYNAMIC) ? false : true;
+ vid = entry->fid;
if (vid >= NETC_VLAN_UNAWARE_PVID(ds->max_num_bridges))
vid = 0;
- err = cb(keye->mac_addr, vid, is_static, data);
+ err = cb(entry->mac_addr, vid, is_static, data);
if (err)
break;
@@ -1855,6 +1840,8 @@ static int netc_port_fdb_dump(struct dsa_switch *ds, int port,
*/
if (++cnt >= priv->htmcapr_num_words)
break;
+
+ resume_eid = entry->status;
} while (resume_eid != NTMP_NULL_ENTRY_ID);
mutex_unlock(&priv->fdbt_lock);
diff --git a/drivers/net/dsa/netc/netc_switch.h b/drivers/net/dsa/netc/netc_switch.h
index ae5e24c91f1cb..3c8dd539ed830 100644
--- a/drivers/net/dsa/netc/netc_switch.h
+++ b/drivers/net/dsa/netc/netc_switch.h
@@ -136,9 +136,7 @@ struct netc_switch_regs {
};
struct netc_fdb_entry {
- u32 entry_id;
- struct fdbt_cfge_data cfge;
- struct fdbt_keye_data keye;
+ struct fdbt_entry_data data;
struct hlist_node node;
};
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 6143e8b5c6b1f..801e4e7bb8314 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -468,6 +468,62 @@ static const struct ntmp_tbl_ops *ntmp_get_ipft_ops(u8 version)
}
}
+static void ntmp_fdbt_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct fdbt_entry_data *e = entry;
+ struct fdbt_req_ua *req = buf;
+ struct fdbt_cfge_data *cfge;
+
+ if (access_method == NTMP_AM_EXACT_KEY) {
+ struct fdbt_keye_data *keye = &req->ak.exact.keye;
+
+ memcpy(keye->mac_addr, e->mac_addr, ETH_ALEN);
+ keye->fid = cpu_to_le16(e->fid);
+ } else { /* NTMP_AM_ENTRY_ID */
+ req->ak.eid.entry_id = cpu_to_le32(e->entry_id);
+ }
+
+ cfge = &req->cfge;
+ cfge->port_bitmap = cpu_to_le32(e->port_bitmap);
+ cfge->cfg = cpu_to_le32(e->cfg);
+ cfge->et_eid = cpu_to_le32(e->et_eid);
+}
+
+static void ntmp_fdbt_unpack_v0(const void *buf, void *entry, bool only_eid)
+{
+ const struct fdbt_resp_query *resp = buf;
+ struct fdbt_entry_data *e = entry;
+
+ e->entry_id = le32_to_cpu(resp->entry_id);
+ if (only_eid)
+ return;
+
+ e->status = le32_to_cpu(resp->status);
+ memcpy(e->mac_addr, resp->keye.mac_addr, ETH_ALEN);
+ e->fid = le16_to_cpu(resp->keye.fid);
+ e->port_bitmap = le32_to_cpu(resp->cfge.port_bitmap);
+ e->cfg = le32_to_cpu(resp->cfge.cfg);
+ e->et_eid = le32_to_cpu(resp->cfge.et_eid);
+ e->acte = resp->acte;
+}
+
+static const struct ntmp_tbl_ops fdbt_ops_v0 = {
+ .req_ua_len = sizeof(struct fdbt_req_ua),
+ .resp_query_len = sizeof(struct fdbt_resp_query),
+ .pack = ntmp_fdbt_pack_v0,
+ .unpack = ntmp_fdbt_unpack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_fdbt_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &fdbt_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)
{
@@ -785,36 +841,38 @@ EXPORT_SYMBOL_GPL(ntmp_ipft_delete_entry);
/**
* ntmp_fdbt_add_entry - add an entry into the FDB table
* @user: target ntmp_user struct
- * @entry_id: returned value, the entry ID of the new added entry
- * @keye: key element data
- * @cfge: configuration element data
+ * @entry: the entry data, the key element data and configuration element
+ * data are used as input. Since the entry ID is assigned by the hardware,
+ * entry->entry_id is a returned value for the driver to use.
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_fdbt_add_entry(struct ntmp_user *user, u32 *entry_id,
- const struct fdbt_keye_data *keye,
- const struct fdbt_cfge_data *cfge)
+int ntmp_fdbt_add_entry(struct ntmp_user *user,
+ struct fdbt_entry_data *entry)
{
- struct fdbt_resp_query *resp;
- struct fdbt_req_ua *req;
+ u8 version = user->tbl_ver[NTMP_FDBT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
u32 len;
int err;
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_fdbt_ops(version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
if (err)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], NTMP_QA_ENTRY_ID,
- NTMP_GEN_UA_CFGEU);
- req->ak.exact.keye = *keye;
- req->cfge = *cfge;
+ ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, NTMP_GEN_UA_CFGEU);
+ ops->pack(entry, buf, NTMP_AM_EXACT_KEY);
- len = NTMP_LEN(swcbd.size, sizeof(*resp));
+ len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len);
/* The entry ID is allotted by hardware, so we need to perform
* a query action after the add action to get the entry ID from
* hardware.
@@ -830,10 +888,7 @@ int ntmp_fdbt_add_entry(struct ntmp_user *user, u32 *entry_id,
goto unlock_cbdr;
}
- if (entry_id) {
- resp = (struct fdbt_resp_query *)req;
- *entry_id = le32_to_cpu(resp->entry_id);
- }
+ ops->unpack(buf, entry, true);
unlock_cbdr:
ntmp_unlock_cbdr(cbdr);
@@ -846,33 +901,38 @@ EXPORT_SYMBOL_GPL(ntmp_fdbt_add_entry);
* ntmp_fdbt_update_entry - update the configuration element data of the
* specified FDB entry
* @user: target ntmp_user struct
- * @entry_id: the specified entry ID of the FDB table
- * @cfge: configuration element data
+ * @entry: the entry data, entry->entry_id selects the FDB entry to update
+ * and the configuration element data provides the new values
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_fdbt_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct fdbt_cfge_data *cfge)
+int ntmp_fdbt_update_entry(struct ntmp_user *user,
+ const struct fdbt_entry_data *entry)
{
- struct fdbt_req_ua *req;
+ u8 version = user->tbl_ver[NTMP_FDBT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
u32 len;
int err;
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_fdbt_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;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, NTMP_GEN_UA_CFGEU);
- req->ak.eid.entry_id = cpu_to_le32(entry_id);
- req->cfge = *cfge;
+ ntmp_fill_crd(buf, version, 0, NTMP_GEN_UA_CFGEU);
+ ops->pack(entry, buf, NTMP_AM_ENTRY_ID);
/* Request header */
- len = NTMP_LEN(swcbd.size, NTMP_STATUS_RESP_LEN);
+ len = NTMP_LEN(ops->req_ua_len, NTMP_STATUS_RESP_LEN);
ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
NTMP_CMD_UPDATE, NTMP_AM_ENTRY_ID);
@@ -909,19 +969,19 @@ EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_entry);
* port based on RESUME_ENTRY_ID
* @user: target ntmp_user struct
* @port: the specified switch port ID
- * @resume_entry_id: it is both an input and an output. As an input, it
- * represents the FDB entry ID to be searched. If it is a NULL entry ID,
- * it indicates that the first FDB entry for that port is being searched.
- * As an output, it represents the next FDB entry ID to be searched.
- * @entry: returned value, the response data of the searched FDB entry
+ * @entry: both an input and an output. On input, entry->status is the
+ * FDB entry ID to resume the search from; a NULL entry ID means searching
+ * from the first FDB entry of that port. On output, entry holds the
+ * response data of the searched FDB entry, and entry->status is the next
+ * FDB entry ID to resume from.
*
* Return: 0 on success, otherwise a negative error code
*/
int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
- u32 *resume_entry_id,
struct fdbt_entry_data *entry)
{
- struct fdbt_resp_query *resp;
+ u8 version = user->tbl_ver[NTMP_FDBT_ID];
+ const struct ntmp_tbl_ops *ops;
struct fdbt_req_qd *req;
struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
@@ -929,20 +989,24 @@ int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
u32 len;
int err;
- swcbd.size = sizeof(*req);
+ ops = ntmp_get_fdbt_ops(version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = max_t(u32, sizeof(*req), ops->resp_query_len);
err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
if (err)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_FDBT_ID], 0, 0);
- req->ak.search.resume_eid = cpu_to_le32(*resume_entry_id);
+ ntmp_fill_crd(&req->crd, version, 0, 0);
+ req->ak.search.resume_eid = cpu_to_le32(entry->status);
req->ak.search.cfge.port_bitmap = cpu_to_le32(BIT(port));
/* Match CFGE_DATA[PORT_BITMAP] field */
req->ak.search.cfge_mc = FDBT_CFGE_MC_PORT_BITMAP;
/* Request header */
- len = NTMP_LEN(swcbd.size, sizeof(*resp));
+ len = NTMP_LEN(swcbd.size, ops->resp_query_len);
ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
NTMP_CMD_QUERY, NTMP_AM_SEARCH);
@@ -957,16 +1021,11 @@ int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
if (!cbd.resp_hdr.num_matched) {
entry->entry_id = NTMP_NULL_ENTRY_ID;
- *resume_entry_id = NTMP_NULL_ENTRY_ID;
+ entry->status = NTMP_NULL_ENTRY_ID;
goto unlock_cbdr;
}
- resp = (struct fdbt_resp_query *)req;
- *resume_entry_id = le32_to_cpu(resp->status);
- entry->entry_id = le32_to_cpu(resp->entry_id);
- entry->keye = resp->keye;
- entry->cfge = resp->cfge;
- entry->acte = resp->acte;
+ ops->unpack(req, 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 5dcfc98b51066..f75129af40606 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -219,6 +219,21 @@ struct ipft_req_qd {
__le32 resv[52];
};
+/* FDB Table Key Element Data */
+struct fdbt_keye_data {
+ u8 mac_addr[ETH_ALEN]; /* big-endian */
+ __le16 resv0;
+ __le16 fid;
+ __le16 resv1;
+};
+
+/* FDB Table Configuration Element Data */
+struct fdbt_cfge_data {
+ __le32 port_bitmap;
+ __le32 cfg;
+ __le32 et_eid;
+};
+
/* Access Key Format of FDB Table */
struct fdbt_ak_eid {
__le32 entry_id;
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 226c672c845af..411a3f67c0268 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -169,31 +169,28 @@ struct ipft_entry_data {
u32 flta_tgt;
};
-struct fdbt_keye_data {
+struct fdbt_entry_data {
+ u32 entry_id;
+ u32 status; /* RESUME_ENTRY_ID returned by a search operation */
+
+ /* KEYE_DATA */
u8 mac_addr[ETH_ALEN]; /* big-endian */
- __le16 resv0;
- __le16 fid;
+ u16 fid;
#define FDBT_FID GENMASK(11, 0)
- __le16 resv1;
-};
-struct fdbt_cfge_data {
- __le32 port_bitmap;
+ /* CFGE_DATA */
+ u32 port_bitmap;
#define FDBT_PORT_BITMAP GENMASK(23, 0)
- __le32 cfg;
+ u32 cfg;
#define FDBT_OETEID GENMASK(1, 0)
#define FDBT_EPORT GENMASK(6, 2)
#define FDBT_IMIRE BIT(7)
#define FDBT_CTD GENMASK(10, 9)
#define FDBT_DYNAMIC BIT(11)
#define FDBT_TIMECAPE BIT(12)
- __le32 et_eid;
-};
+ u32 et_eid;
-struct fdbt_entry_data {
- u32 entry_id;
- struct fdbt_keye_data keye;
- struct fdbt_cfge_data cfge;
+ /* ACTE_DATA */
u8 acte;
#define FDBT_ACT_CNT GENMASK(6, 0)
#define FDBT_ACT_FLAG BIT(7)
@@ -293,14 +290,12 @@ int ntmp_rsst_query_entry(struct ntmp_user *user,
int ntmp_ipft_add_entry(struct ntmp_user *user,
struct ipft_entry_data *entry);
int ntmp_ipft_delete_entry(struct ntmp_user *user, u32 entry_id);
-int ntmp_fdbt_add_entry(struct ntmp_user *user, u32 *entry_id,
- const struct fdbt_keye_data *keye,
- const struct fdbt_cfge_data *cfge);
-int ntmp_fdbt_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct fdbt_cfge_data *cfge);
+int ntmp_fdbt_add_entry(struct ntmp_user *user,
+ struct fdbt_entry_data *entry);
+int ntmp_fdbt_update_entry(struct ntmp_user *user,
+ const struct fdbt_entry_data *entry);
int ntmp_fdbt_delete_entry(struct ntmp_user *user, u32 entry_id);
int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
- u32 *resume_entry_id,
struct fdbt_entry_data *entry);
int ntmp_fdbt_update_activity_element(struct ntmp_user *user);
int ntmp_fdbt_delete_ageing_entries(struct ntmp_user *user, u8 act_cnt);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 05/14] net: enetc: decouple VFT logical config from hardware wire format
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (3 preceding siblings ...)
2026-12-04 7:14 ` [PATCH net-next 04/14] net: enetc: decouple FDBT " wei.fang
@ 2026-12-04 7:14 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 06/14] net: enetc: decouple ETT " wei.fang
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement VFT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
vft_cfge_data is the hardware CFGE structure, 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.
Add a version-agnostic struct vft_entry_data that uses native CPU types
and also carries the VLAN ID, and move the wire structure into
ntmp_private.h to keep it internal to the NTMP layer. Add a struct
ntmp_tbl_ops instance holding the buffer size and a pack() callback, and
select it via ntmp_get_vft_ops(), following the MAFT, IPFT and FDBT
tables.
Reshape the VFT interface around the logical config. ntmp_vft_add_entry()
and ntmp_vft_update_entry() now take a struct vft_entry_data pointer
instead of a VLAN ID and a separate cfge pointer. Note that the command
in ntmp_vft_add_entry() has been changed NTMP_CMD_AQ. This allows the
NETC switch driver to track the ID of each entry and access thoes entries
using the entry ID match method.
A future version can then be added within the NTMP layer by providing
its wire structure, pack helper and ops instance. Callers may still need
small adjustments, but they no longer deal with the wire format or
endianness.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 83 +++++-------
drivers/net/dsa/netc/netc_switch.h | 3 +-
drivers/net/ethernet/freescale/enetc/ntmp.c | 120 ++++++++++++++----
.../ethernet/freescale/enetc/ntmp_private.h | 17 +++
include/linux/fsl/ntmp.h | 25 ++--
5 files changed, 161 insertions(+), 87 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index 9573672d65a3f..ce29b586f3c13 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -43,7 +43,7 @@ netc_lookup_vlan_entry(struct netc_switch *priv, u16 vid)
struct netc_vlan_entry *entry;
hlist_for_each_entry(entry, &priv->vlan_list, node)
- if (entry->vid == vid)
+ if (entry->data.vid == vid)
return entry;
return NULL;
@@ -699,18 +699,17 @@ static u32 netc_available_port_bitmap(struct netc_switch *priv)
static int netc_add_standalone_vlan_entry(struct netc_switch *priv)
{
- u32 bitmap_stg = VFT_STG_ID(0) | netc_available_port_bitmap(priv);
- struct vft_cfge_data *cfge;
- u16 cfg;
+ struct vft_entry_data *entry;
int err;
- cfge = kzalloc_obj(*cfge);
- if (!cfge)
+ entry = kzalloc_obj(*entry);
+ if (!entry)
return -ENOMEM;
- cfge->bitmap_stg = cpu_to_le32(bitmap_stg);
- cfge->et_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
- cfge->fid = cpu_to_le16(NETC_STANDALONE_PVID);
+ entry->vid = NETC_STANDALONE_PVID;
+ entry->bitmap_stg = VFT_STG_ID(0) | netc_available_port_bitmap(priv);
+ entry->et_eid = NTMP_NULL_ENTRY_ID;
+ entry->fid = NETC_STANDALONE_PVID;
/* For standalone ports, MAC learning needs to be disabled, so frames
* from other user ports will not be forwarded to the standalone ports,
@@ -720,16 +719,15 @@ static int netc_add_standalone_vlan_entry(struct netc_switch *priv)
* MFO_NO_MATCH_DISCARD, so the frames will be discarded rather than
* flooding to other ports.
*/
- cfg = FIELD_PREP(VFT_MLO, MLO_DISABLE) |
- FIELD_PREP(VFT_MFO, MFO_NO_MATCH_DISCARD);
- cfge->cfg = cpu_to_le16(cfg);
+ entry->cfg = FIELD_PREP(VFT_MLO, MLO_DISABLE) |
+ FIELD_PREP(VFT_MFO, MFO_NO_MATCH_DISCARD);
- err = ntmp_vft_add_entry(&priv->ntmp, NETC_STANDALONE_PVID, cfge);
+ err = ntmp_vft_add_entry(&priv->ntmp, entry);
if (err)
dev_err(priv->dev,
"Failed to add standalone VLAN entry\n");
- kfree(cfge);
+ kfree(entry);
return err;
}
@@ -1385,7 +1383,7 @@ static int netc_add_vlan_egress_rule(struct netc_switch *priv,
if (err)
goto clear_ett_gid;
- entry->cfge.et_eid = cpu_to_le32(ett_eid);
+ entry->data.et_eid = ett_eid;
entry->ect_gid = ect_gid;
return 0;
@@ -1407,7 +1405,7 @@ static void netc_delete_vlan_egress_rule(struct netc_switch *priv,
struct ntmp_user *ntmp = &priv->ntmp;
u32 ett_eid, ett_gid;
- ett_eid = le32_to_cpu(entry->cfge.et_eid);
+ ett_eid = entry->data.et_eid;
if (ett_eid == NTMP_NULL_ENTRY_ID)
return;
@@ -1427,8 +1425,8 @@ static int netc_port_update_vlan_egress_rule(struct netc_port *np,
{
bool untagged = !!(entry->untagged_port_bitmap & BIT(np->dp->index));
u32 num_ports = netc_num_available_ports(np->switch_priv);
- u32 ett_eid = le32_to_cpu(entry->cfge.et_eid);
struct netc_switch *priv = np->switch_priv;
+ u32 ett_eid = entry->data.et_eid;
u32 ect_eid = NTMP_NULL_ENTRY_ID;
int err;
@@ -1447,7 +1445,7 @@ static int netc_port_update_vlan_egress_rule(struct netc_port *np,
if (err) {
dev_err(priv->dev,
"Failed to update VLAN %u egress rule on port %d\n",
- entry->vid, np->dp->index);
+ entry->data.vid, np->dp->index);
return err;
}
@@ -1462,20 +1460,15 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid,
{
struct netc_switch *priv = np->switch_priv;
struct netc_vlan_entry *entry;
- struct vft_cfge_data *cfge;
u32 index = np->dp->index;
- u32 bitmap_stg;
int err;
- u16 cfg;
entry = kzalloc_obj(*entry);
if (!entry)
return -ENOMEM;
- entry->vid = vid;
entry->ect_gid = NTMP_NULL_ENTRY_ID;
-
- bitmap_stg = BIT(index) | VFT_STG_ID(0);
+ entry->data.bitmap_stg = BIT(index) | VFT_STG_ID(0);
/* If the VID is a VLAN-unaware PVID, the CPU port needs to be
* a member of this VLAN.
*/
@@ -1483,18 +1476,15 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid,
vid >= NETC_VLAN_UNAWARE_PVID(priv->ds->max_num_bridges)) {
struct dsa_port *cpu_dp = np->dp->cpu_dp;
- bitmap_stg |= BIT(cpu_dp->index);
+ entry->data.bitmap_stg |= BIT(cpu_dp->index);
}
- cfg = FIELD_PREP(VFT_MLO, MLO_HW) |
- FIELD_PREP(VFT_MFO, MFO_NO_MATCH_FLOOD);
-
- cfge = &entry->cfge;
- cfge->et_eid = cpu_to_le32(NTMP_NULL_ENTRY_ID);
- cfge->bitmap_stg = cpu_to_le32(bitmap_stg);
- cfge->fid = cpu_to_le16(vid);
- cfge->cfg = cpu_to_le16(cfg);
- cfge->eta_port_bitmap = cpu_to_le32(priv->port_bitmap);
+ entry->data.vid = vid;
+ entry->data.et_eid = NTMP_NULL_ENTRY_ID;
+ entry->data.fid = vid;
+ entry->data.cfg = FIELD_PREP(VFT_MLO, MLO_HW) |
+ FIELD_PREP(VFT_MFO, MFO_NO_MATCH_FLOOD);
+ entry->data.eta_port_bitmap = priv->port_bitmap;
if (untagged)
entry->untagged_port_bitmap = BIT(index);
@@ -1503,7 +1493,7 @@ static int netc_port_add_vlan_entry(struct netc_port *np, u16 vid,
if (err)
goto free_vlan_entry;
- err = ntmp_vft_add_entry(&priv->ntmp, vid, cfge);
+ err = ntmp_vft_add_entry(&priv->ntmp, &entry->data);
if (err) {
dev_err(priv->dev,
"Failed to add VLAN %u entry on port %d\n",
@@ -1528,9 +1518,10 @@ static bool netc_port_vlan_egress_rule_changed(struct netc_switch *priv,
int port, bool untagged)
{
bool old_untagged = !!(entry->untagged_port_bitmap & BIT(port));
+ u16 vid = entry->data.vid;
/* VLAN-unaware VIDs have no egress rules, so return 'false' */
- if (entry->vid >= NETC_VLAN_UNAWARE_PVID(priv->ds->max_num_bridges))
+ if (vid >= NETC_VLAN_UNAWARE_PVID(priv->ds->max_num_bridges))
return false;
return old_untagged != untagged;
@@ -1541,7 +1532,6 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid,
{
struct netc_switch *priv = np->switch_priv;
struct netc_vlan_entry *entry;
- struct vft_cfge_data *cfge;
int port = np->dp->index;
bool changed;
int err = 0;
@@ -1566,12 +1556,11 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid,
}
}
- cfge = &entry->cfge;
- if (cfge->bitmap_stg & cpu_to_le32(BIT(port)))
+ if (entry->data.bitmap_stg & BIT(port))
goto unlock_vft;
- cfge->bitmap_stg |= cpu_to_le32(BIT(port));
- err = ntmp_vft_update_entry(&priv->ntmp, vid, cfge);
+ entry->data.bitmap_stg |= BIT(port);
+ err = ntmp_vft_update_entry(&priv->ntmp, &entry->data);
if (err) {
dev_err(priv->dev,
"Failed to update VLAN %u entry on port %d\n",
@@ -1585,7 +1574,7 @@ static int netc_port_set_vlan_entry(struct netc_port *np, u16 vid,
return 0;
restore_bitmap_stg:
- cfge->bitmap_stg &= cpu_to_le32(~BIT(port));
+ entry->data.bitmap_stg &= ~BIT(port);
if (changed) {
entry->untagged_port_bitmap ^= BIT(port);
/* Recover the corresponding ETT entry. It doesn't matter
@@ -1606,7 +1595,6 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid)
{
struct netc_switch *priv = np->switch_priv;
struct netc_vlan_entry *entry;
- struct vft_cfge_data *cfge;
int port = np->dp->index;
u32 vlan_port_bitmap;
int err = 0;
@@ -1617,9 +1605,8 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid)
if (!entry)
goto unlock_vft;
- cfge = &entry->cfge;
vlan_port_bitmap = FIELD_GET(VFT_PORT_MEMBERSHIP,
- le32_to_cpu(cfge->bitmap_stg));
+ entry->data.bitmap_stg);
/* If the VID is a VLAN-unaware PVID, we need to clear the CPU
* port bit of vlan_port_bitmap, so that the VLAN entry can be
* deleted if no user ports use this VLAN.
@@ -1646,10 +1633,10 @@ static int netc_port_del_vlan_entry(struct netc_port *np, u16 vid)
if (!(vlan_port_bitmap & BIT(port)))
goto unlock_vft;
- cfge->bitmap_stg &= cpu_to_le32(~BIT(port));
- err = ntmp_vft_update_entry(&priv->ntmp, vid, cfge);
+ entry->data.bitmap_stg &= ~BIT(port);
+ err = ntmp_vft_update_entry(&priv->ntmp, &entry->data);
if (err) {
- cfge->bitmap_stg |= cpu_to_le32(BIT(port));
+ entry->data.bitmap_stg |= BIT(port);
goto unlock_vft;
}
diff --git a/drivers/net/dsa/netc/netc_switch.h b/drivers/net/dsa/netc/netc_switch.h
index 3c8dd539ed830..c61d3e3a366a0 100644
--- a/drivers/net/dsa/netc/netc_switch.h
+++ b/drivers/net/dsa/netc/netc_switch.h
@@ -141,10 +141,9 @@ struct netc_fdb_entry {
};
struct netc_vlan_entry {
- u16 vid;
u32 ect_gid;
u32 untagged_port_bitmap;
- struct vft_cfge_data cfge;
+ struct vft_entry_data data;
struct hlist_node node;
};
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 801e4e7bb8314..9d642dbf5e429 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -524,6 +524,62 @@ static const struct ntmp_tbl_ops *ntmp_get_fdbt_ops(u8 version)
}
}
+static void ntmp_vft_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct vft_entry_data *e = entry;
+ struct vft_req_ua *req = buf;
+ struct vft_cfge_data *cfge;
+
+ /* Currently, there is no need to support NTMP_AM_ENTRY_ID */
+ if (access_method == NTMP_AM_EXACT_KEY)
+ req->ak.exact.vid = cpu_to_le16(e->vid);
+
+ cfge = &req->cfge;
+ cfge->bitmap_stg = cpu_to_le32(e->bitmap_stg);
+ cfge->fid = cpu_to_le16(e->fid);
+ cfge->cfg = cpu_to_le16(e->cfg);
+ cfge->eta_port_bitmap = cpu_to_le32(e->eta_port_bitmap);
+ cfge->et_eid = cpu_to_le32(e->et_eid);
+}
+
+static void ntmp_vft_unpack_v0(const void *buf, void *entry, bool only_eid)
+{
+ const struct vft_resp_query *resp = buf;
+ const struct vft_cfge_data *cfge;
+ struct vft_entry_data *e = entry;
+
+ e->entry_id = le32_to_cpu(resp->entry_id);
+ if (only_eid)
+ return;
+
+ e->status = le32_to_cpu(resp->status);
+ e->vid = le16_to_cpu(resp->vid);
+
+ cfge = &resp->cfge;
+ e->bitmap_stg = le32_to_cpu(cfge->bitmap_stg);
+ e->fid = le16_to_cpu(cfge->fid);
+ e->cfg = le16_to_cpu(cfge->cfg);
+ e->eta_port_bitmap = le32_to_cpu(cfge->eta_port_bitmap);
+ e->et_eid = le32_to_cpu(cfge->et_eid);
+}
+
+static const struct ntmp_tbl_ops vft_ops_v0 = {
+ .req_ua_len = sizeof(struct vft_req_ua),
+ .resp_query_len = sizeof(struct vft_resp_query),
+ .pack = ntmp_vft_pack_v0,
+ .unpack = ntmp_vft_unpack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_vft_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &vft_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)
{
@@ -1200,43 +1256,51 @@ EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_port_dynamic_entries);
* ntmp_vft_set_entry - add an entry into the VLAN filter table or update
* the configuration element data of the specified VLAN filter entry
* @user: target ntmp_user struct
- * @vid: VLAN ID
- * @cmd: command type, NTMP_CMD_ADD or NTMP_CMD_UPDATE
- * @cfge: configuration element data
+ * @cmd: command type, NTMP_CMD_AQ or NTMP_CMD_UPDATE
+ * @entry: the entry data, entry->vid selects the VLAN filter entry and
+ * the configuration element data provides the values
*
* Return: 0 on success, otherwise a negative error code
*/
-static int ntmp_vft_set_entry(struct ntmp_user *user, u16 vid, int cmd,
- const struct vft_cfge_data *cfge)
+static int ntmp_vft_set_entry(struct ntmp_user *user, int cmd,
+ struct vft_entry_data *entry)
{
+ u8 version = user->tbl_ver[NTMP_VFT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
- struct vft_req_ua *req;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
u32 len;
int err;
- if (cmd != NTMP_CMD_ADD && cmd != NTMP_CMD_UPDATE)
- return -EINVAL;
+ ops = ntmp_get_vft_ops(version);
+ if (!ops)
+ return -EOPNOTSUPP;
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
if (err)
return err;
/* Request data */
- ntmp_fill_crd(&req->crd, user->tbl_ver[NTMP_VFT_ID],
- 0, NTMP_GEN_UA_CFGEU);
- req->ak.exact.vid = cpu_to_le16(vid);
- req->cfge = *cfge;
+ ntmp_fill_crd(buf, version, 0, NTMP_GEN_UA_CFGEU);
+ ops->pack(entry, buf, NTMP_AM_EXACT_KEY);
/* Request header */
- len = NTMP_LEN(swcbd.size, NTMP_STATUS_RESP_LEN);
+ len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len);
ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_VFT_ID,
cmd, NTMP_AM_EXACT_KEY);
ntmp_select_and_lock_cbdr(user, &cbdr);
err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
+ if (err)
+ goto unlock_cbdr;
+
+ if (cmd == NTMP_CMD_AQ)
+ ops->unpack(buf, (void *)entry, true);
+
+unlock_cbdr:
ntmp_unlock_cbdr(cbdr);
return err;
@@ -1245,21 +1309,22 @@ static int ntmp_vft_set_entry(struct ntmp_user *user, u16 vid, int cmd,
/**
* ntmp_vft_add_entry - add an entry into the VLAN filter table
* @user: target ntmp_user struct
- * @vid: VLAN ID
- * @cfge: configuration element data
+ * @entry: the entry data, entry->vid is the VLAN ID and the configuration
+ * element data provides the values
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_vft_add_entry(struct ntmp_user *user, u16 vid,
- const struct vft_cfge_data *cfge)
+int ntmp_vft_add_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry)
{
int err;
- err = ntmp_vft_set_entry(user, vid, NTMP_CMD_ADD, cfge);
+ err = ntmp_vft_set_entry(user, NTMP_CMD_AQ, entry);
if (err)
dev_err(user->dev,
"Failed to add %s entry, vid: %u, err: %pe\n",
- ntmp_table_name(NTMP_VFT_ID), vid, ERR_PTR(err));
+ ntmp_table_name(NTMP_VFT_ID), entry->vid,
+ ERR_PTR(err));
return err;
}
@@ -1269,21 +1334,22 @@ EXPORT_SYMBOL_GPL(ntmp_vft_add_entry);
* ntmp_vft_update_entry - update the configuration element data of the
* specified VLAN filter entry
* @user: target ntmp_user struct
- * @vid: VLAN ID
- * @cfge: configuration element data
+ * @entry: the entry data, entry->vid selects the VLAN filter entry and
+ * the configuration element data provides the new values
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_vft_update_entry(struct ntmp_user *user, u16 vid,
- const struct vft_cfge_data *cfge)
+int ntmp_vft_update_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry)
{
int err;
- err = ntmp_vft_set_entry(user, vid, NTMP_CMD_UPDATE, cfge);
+ err = ntmp_vft_set_entry(user, NTMP_CMD_UPDATE, entry);
if (err)
dev_err(user->dev,
"Failed to update %s entry, vid: %u, err: %pe\n",
- ntmp_table_name(NTMP_VFT_ID), vid, ERR_PTR(err));
+ ntmp_table_name(NTMP_VFT_ID), entry->vid,
+ ERR_PTR(err));
return err;
}
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp_private.h b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
index f75129af40606..d75cde81f81cf 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -291,6 +291,15 @@ struct fdbt_resp_query {
u8 resv[3];
};
+/* VLAN Filter Table Configuration Element Data */
+struct vft_cfge_data {
+ __le32 bitmap_stg;
+ __le16 fid;
+ __le16 cfg;
+ __le32 eta_port_bitmap;
+ __le32 et_eid;
+};
+
/* Access Key Format of VLAN Filter Table */
struct vft_ak_exact {
__le16 vid; /* bit0~11: VLAN ID, other bits are reserved */
@@ -316,6 +325,14 @@ struct vft_req_qd {
union vft_access_key ak;
};
+struct vft_resp_query {
+ __le32 status;
+ __le32 entry_id;
+ __le16 vid; /* KEYE_DATA */
+ __le16 resv;
+ struct vft_cfge_data cfge;
+};
+
/* Egress Treatment Table Request Data Buffer Format of Update and Add
* actions
*/
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 411a3f67c0268..202fd49ac8933 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -196,14 +196,19 @@ struct fdbt_entry_data {
#define FDBT_ACT_FLAG BIT(7)
};
-struct vft_cfge_data {
- __le32 bitmap_stg;
+struct vft_entry_data {
+ u16 vid;
+ u32 status; /* resume entry ID */
+ u32 entry_id; /* hardware assigns entry ID */
+
+ /* CFGE_DATA */
+ u32 bitmap_stg;
#define VFT_PORT_MEMBERSHIP GENMASK(23, 0)
#define VFT_STG_ID_MASK GENMASK(27, 24)
#define VFT_STG_ID(g) FIELD_PREP(VFT_STG_ID_MASK, (g))
- __le16 fid;
+ u16 fid;
#define VFT_FID GENMASK(11, 0)
- __le16 cfg;
+ u16 cfg;
#define VFT_MLO GENMASK(2, 0)
#define VFT_MFO GENMASK(4, 3)
#define VFT_IPMFE BIT(6)
@@ -212,9 +217,9 @@ struct vft_cfge_data {
#define VFT_SFDA BIT(10)
#define VFT_OSFDA BIT(11)
#define VFT_FDBAFSS BIT(12)
- __le32 eta_port_bitmap;
+ u32 eta_port_bitmap;
#define VFT_ETA_PORT_BITMAP GENMASK(23, 0)
- __le32 et_eid;
+ u32 et_eid;
};
struct ett_cfge_data {
@@ -300,10 +305,10 @@ int ntmp_fdbt_search_port_entry(struct ntmp_user *user, int port,
int ntmp_fdbt_update_activity_element(struct ntmp_user *user);
int ntmp_fdbt_delete_ageing_entries(struct ntmp_user *user, u8 act_cnt);
int ntmp_fdbt_delete_port_dynamic_entries(struct ntmp_user *user, int port);
-int ntmp_vft_add_entry(struct ntmp_user *user, u16 vid,
- const struct vft_cfge_data *cfge);
-int ntmp_vft_update_entry(struct ntmp_user *user, u16 vid,
- const struct vft_cfge_data *cfge);
+int ntmp_vft_add_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry);
+int ntmp_vft_update_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry);
int ntmp_vft_delete_entry(struct ntmp_user *user, u16 vid);
int ntmp_ett_add_entry(struct ntmp_user *user, u32 entry_id,
const struct ett_cfge_data *cfge);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 06/14] net: enetc: decouple ETT logical config from hardware wire format
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (4 preceding siblings ...)
2026-12-04 7:14 ` [PATCH net-next 05/14] net: enetc: decouple VFT " wei.fang
@ 2026-12-04 7:14 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 07/14] net: enetc: decouple BPT " wei.fang
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement ETT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
ett_cfge_data is the hardware CFGE structure, 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.
Add a version-agnostic struct ett_entry_data that uses native CPU types
and also carries the entry ID, and move the wire structure into
ntmp_private.h to keep it internal to the NTMP layer. Add a struct
ntmp_tbl_ops instance holding the buffer size and a pack() callback, and
select it via ntmp_get_ett_ops(), following the MAFT, IPFT, FDBT and VFT
tables.
Reshape the ETT interface around the logical config. ntmp_ett_add_entry()
and ntmp_ett_update_entry() now take a struct ett_entry_data pointer
instead of an entry ID and a separate cfge pointer.
A future version can then be added within the NTMP layer by providing
its wire structure, pack helper and ops instance. Callers may still need
small adjustments, but they no longer deal with the wire format or
endianness.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 23 +++---
drivers/net/ethernet/freescale/enetc/ntmp.c | 80 ++++++++++++++-----
.../ethernet/freescale/enetc/ntmp_private.h | 9 +++
include/linux/fsl/ntmp.h | 23 +++---
4 files changed, 92 insertions(+), 43 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index ce29b586f3c13..1ac6ec0087aa0 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -1251,16 +1251,17 @@ static void netc_switch_get_ip_revision(struct netc_switch *priv)
priv->revision = FIELD_GET(IPBRR0_IP_REV, val);
}
-static void netc_init_ett_cfge(struct ett_cfge_data *cfge,
- bool untagged, u32 ect_eid)
+static void netc_init_ett_entry(struct ett_entry_data *entry, bool untagged,
+ u32 ett_eid, u32 ect_eid)
{
u32 vuda_sqta = FMTEID_VUDA_SQTA;
u16 efm_cfg = 0;
+ entry->entry_id = ett_eid;
if (ect_eid != NTMP_NULL_ENTRY_ID) {
/* Increase egress frame counter */
efm_cfg |= FIELD_PREP(ETT_ECA, ETT_ECA_INC);
- cfge->ec_eid = cpu_to_le32(ect_eid);
+ entry->ec_eid = ect_eid;
}
/* If egress rule is VLAN untagged */
@@ -1272,30 +1273,30 @@ static void netc_init_ett_cfge(struct ett_cfge_data *cfge,
ETT_FRM_LEN_DEL_VLAN);
}
- cfge->efm_eid = cpu_to_le32(vuda_sqta);
- cfge->efm_cfg = cpu_to_le16(efm_cfg);
+ entry->efm_eid = vuda_sqta;
+ entry->efm_cfg = efm_cfg;
}
static int netc_add_ett_entry(struct netc_switch *priv, bool untagged,
u32 ett_eid, u32 ect_eid)
{
struct ntmp_user *ntmp = &priv->ntmp;
- struct ett_cfge_data cfge = {};
+ struct ett_entry_data entry = {};
- netc_init_ett_cfge(&cfge, untagged, ect_eid);
+ netc_init_ett_entry(&entry, untagged, ett_eid, ect_eid);
- return ntmp_ett_add_entry(ntmp, ett_eid, &cfge);
+ return ntmp_ett_add_entry(ntmp, &entry);
}
static int netc_update_ett_entry(struct netc_switch *priv, bool untagged,
u32 ett_eid, u32 ect_eid)
{
struct ntmp_user *ntmp = &priv->ntmp;
- struct ett_cfge_data cfge = {};
+ struct ett_entry_data entry = {};
- netc_init_ett_cfge(&cfge, untagged, ect_eid);
+ netc_init_ett_entry(&entry, untagged, ett_eid, ect_eid);
- return ntmp_ett_update_entry(ntmp, ett_eid, &cfge);
+ return ntmp_ett_update_entry(ntmp, &entry);
}
static int netc_add_ett_group_entries(struct netc_switch *priv,
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 9d642dbf5e429..c967439ad3589 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -580,6 +580,34 @@ static const struct ntmp_tbl_ops *ntmp_get_vft_ops(u8 version)
}
}
+static void ntmp_ett_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct ett_entry_data *_entry = entry;
+ struct ett_req_ua *req = buf;
+ struct ett_cfge_data *cfge = &req->cfge;
+
+ cfge->efm_cfg = cpu_to_le16(_entry->efm_cfg);
+ cfge->efm_data_len = cpu_to_le16(_entry->efm_data_len);
+ cfge->efm_eid = cpu_to_le32(_entry->efm_eid);
+ cfge->ec_eid = cpu_to_le32(_entry->ec_eid);
+ cfge->esqa_tgt_eid = cpu_to_le32(_entry->esqa_tgt_eid);
+}
+
+static const struct ntmp_tbl_ops ett_ops_v0 = {
+ .req_ua_len = sizeof(struct ett_req_ua),
+ .pack = ntmp_ett_pack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_ett_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &ett_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)
{
@@ -1403,33 +1431,39 @@ EXPORT_SYMBOL_GPL(ntmp_vft_delete_entry);
* ntmp_ett_set_entry - add a new entry to the egress treatment table or
* update the configuration element data of the specified entry
* @user: target ntmp_user struct
- * @entry_id: entry ID
* @cmd: command type, NTMP_CMD_ADD or NTMP_CMD_UPDATE
- * @cfge: configuration element data
+ * @entry: the entry data, entry->entry_id selects the entry and the
+ * configuration element data provides the values
*
* Return: 0 on success, otherwise a negative error code
*/
-static int ntmp_ett_set_entry(struct ntmp_user *user, u32 entry_id,
- int cmd, const struct ett_cfge_data *cfge)
+static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,
+ const struct ett_entry_data *entry)
{
+ u8 version = user->tbl_ver[NTMP_ETT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
- struct ett_req_ua *req;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
int err;
if (cmd != NTMP_CMD_ADD && cmd != NTMP_CMD_UPDATE)
return -EINVAL;
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_ett_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;
/* Request data */
- ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_ETT_ID], 0,
- NTMP_GEN_UA_CFGEU, entry_id);
- req->cfge = *cfge;
+ ntmp_fill_crd_eid(buf, version, 0, NTMP_GEN_UA_CFGEU,
+ entry->entry_id);
+ ops->pack(entry, buf, 0);
/* Request header */
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
@@ -1445,20 +1479,21 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, u32 entry_id,
/**
* ntmp_ett_add_entry - add a new entry to the egress treatment table
* @user: target ntmp_user struct
- * @entry_id: entry ID
- * @cfge: configuration element data
+ * @entry: the entry data, entry->entry_id is the entry ID and the
+ * configuration element data provides the values
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_ett_add_entry(struct ntmp_user *user, u32 entry_id,
- const struct ett_cfge_data *cfge)
+int ntmp_ett_add_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry)
{
int err;
- err = ntmp_ett_set_entry(user, entry_id, NTMP_CMD_ADD, cfge);
+ err = ntmp_ett_set_entry(user, NTMP_CMD_ADD, entry);
if (err)
dev_err(user->dev, "Failed to add %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_ETT_ID), entry_id, ERR_PTR(err));
+ ntmp_table_name(NTMP_ETT_ID), entry->entry_id,
+ ERR_PTR(err));
return err;
}
@@ -1468,21 +1503,22 @@ EXPORT_SYMBOL_GPL(ntmp_ett_add_entry);
* ntmp_ett_update_entry - update the configuration element data of the
* specified entry
* @user: target ntmp_user struct
- * @entry_id: entry ID
- * @cfge: configuration element data
+ * @entry: the entry data, entry->entry_id selects the entry and the
+ * configuration element data provides the new values
*
* Return: 0 on success, otherwise a negative error code
*/
-int ntmp_ett_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct ett_cfge_data *cfge)
+int ntmp_ett_update_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry)
{
int err;
- err = ntmp_ett_set_entry(user, entry_id, NTMP_CMD_UPDATE, cfge);
+ err = ntmp_ett_set_entry(user, NTMP_CMD_UPDATE, entry);
if (err)
dev_err(user->dev,
"Failed to update %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_ETT_ID), entry_id, ERR_PTR(err));
+ ntmp_table_name(NTMP_ETT_ID), entry->entry_id,
+ ERR_PTR(err));
return err;
}
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp_private.h b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
index d75cde81f81cf..710ab88560c7d 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -333,6 +333,15 @@ struct vft_resp_query {
struct vft_cfge_data cfge;
};
+/* Egress Treatment Table Configuration Element Data */
+struct ett_cfge_data {
+ __le16 efm_cfg;
+ __le16 efm_data_len;
+ __le32 efm_eid;
+ __le32 ec_eid;
+ __le32 esqa_tgt_eid;
+};
+
/* Egress Treatment Table Request Data Buffer Format of Update and Add
* actions
*/
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 202fd49ac8933..23a612ec0b969 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -222,8 +222,11 @@ struct vft_entry_data {
u32 et_eid;
};
-struct ett_cfge_data {
- __le16 efm_cfg;
+struct ett_entry_data {
+ u32 entry_id;
+
+ /* CFGE_DATA */
+ u16 efm_cfg;
#define ETT_EFM_MODE GENMASK(1, 0)
#define ETT_ESQA GENMASK(5, 4)
#define ETT_ECA GENMASK(8, 6)
@@ -232,11 +235,11 @@ struct ett_cfge_data {
#define ETT_FRM_LEN_DEL_VLAN 0x7c
#define ETT_FRM_LEN_DEL_RTAG 0x7a
#define ETT_FRM_LEN_DEL_VLAN_RTAG 0x76
- __le16 efm_data_len;
+ u16 efm_data_len;
#define ETT_EFM_DATA_LEN GENMASK(10, 0)
- __le32 efm_eid;
- __le32 ec_eid;
- __le32 esqa_tgt_eid;
+ u32 efm_eid;
+ u32 ec_eid;
+ u32 esqa_tgt_eid;
};
struct bpt_bpse_data {
@@ -310,10 +313,10 @@ int ntmp_vft_add_entry(struct ntmp_user *user,
int ntmp_vft_update_entry(struct ntmp_user *user,
struct vft_entry_data *entry);
int ntmp_vft_delete_entry(struct ntmp_user *user, u16 vid);
-int ntmp_ett_add_entry(struct ntmp_user *user, u32 entry_id,
- const struct ett_cfge_data *cfge);
-int ntmp_ett_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct ett_cfge_data *cfge);
+int ntmp_ett_add_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry);
+int ntmp_ett_update_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry);
int ntmp_ett_delete_entry(struct ntmp_user *user, u32 entry_id);
int ntmp_ect_update_entry(struct ntmp_user *user, u32 entry_id);
int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 07/14] net: enetc: decouple BPT logical config from hardware wire format
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (5 preceding siblings ...)
2026-12-04 7:14 ` [PATCH net-next 06/14] net: enetc: decouple ETT " wei.fang
@ 2026-12-04 7:14 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 08/14] net: enetc: add generic ntmp_add_entry_by_id() helper wei.fang
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement BPT version 0, but future versions may
extend the table with a different buffer layout and size. Today struct
bpt_cfge_data and struct bpt_bpse_data are the hardware CFGE and BPSE
structures, 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.
Add a version-agnostic struct bpt_entry_data that uses native CPU types
and also carries the entry ID, and move the wire structures into
ntmp_private.h to keep them internal to the NTMP layer. Add a struct
ntmp_tbl_ops instance holding the buffer size and a pack() callback, and
select it via ntmp_get_bpt_ops(), following the other NTMP tables.
Reshape the BPT interface around the logical config.
ntmp_bpt_update_entry() now takes a struct bpt_entry_data pointer instead
of an entry ID and a separate cfge pointer, and the driver caches struct
bpt_entry_data.
A future version can then be added within the NTMP layer by providing
its wire structures, pack helper and ops instance. Callers may still
need small adjustments, but they no longer deal with the wire format or
endianness.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/dsa/netc/netc_main.c | 34 ++++++-----
drivers/net/dsa/netc/netc_switch.h | 2 +-
drivers/net/ethernet/freescale/enetc/ntmp.c | 59 +++++++++++++++----
.../ethernet/freescale/enetc/ntmp_private.h | 20 +++++++
include/linux/fsl/ntmp.h | 35 +++++------
5 files changed, 106 insertions(+), 44 deletions(-)
diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
index 1ac6ec0087aa0..c8c653b23d63e 100644
--- a/drivers/net/dsa/netc/netc_main.c
+++ b/drivers/net/dsa/netc/netc_main.c
@@ -958,10 +958,11 @@ static int netc_switch_bpt_default_config(struct netc_switch *priv)
/* Initialize the maximum threshold of each buffer pool entry */
for (int i = 0; i < priv->num_bp; i++) {
- struct bpt_cfge_data *cfge = &priv->bpt_list[i];
+ struct bpt_entry_data *entry = &priv->bpt_list[i];
- cfge->max_thresh = cpu_to_le16(NETC_BP_THRESH);
- err = ntmp_bpt_update_entry(&priv->ntmp, i, cfge);
+ entry->entry_id = i;
+ entry->max_thresh = NETC_BP_THRESH;
+ err = ntmp_bpt_update_entry(&priv->ntmp, entry);
if (err)
goto free_bpt_list;
}
@@ -2395,24 +2396,25 @@ static void netc_port_set_tx_pause(struct netc_port *np, bool tx_pause)
num_bp = priv->num_bp / priv->info->num_ports;
for (i = 0, j = port * num_bp; i < num_bp; i++, j++) {
- struct bpt_cfge_data *cfge = &priv->bpt_list[j];
- struct bpt_cfge_data old_cfge = *cfge;
+ struct bpt_entry_data *entry = &priv->bpt_list[j];
+ struct bpt_entry_data old_entry = *entry;
if (tx_pause) {
- cfge->fc_on_thresh = cpu_to_le16(NETC_FC_THRESH_ON);
- cfge->fc_off_thresh = cpu_to_le16(NETC_FC_THRESH_OFF);
- cfge->fccfg_sbpen = FIELD_PREP(BPT_FC_CFG,
- BPT_FC_CFG_EN_BPFC);
- cfge->fc_ports = cpu_to_le32(BIT(port));
+ entry->fc_on_thresh = NETC_FC_THRESH_ON;
+ entry->fc_off_thresh = NETC_FC_THRESH_OFF;
+ entry->fccfg_sbpen = FIELD_PREP(BPT_FC_CFG,
+ BPT_FC_CFG_EN_BPFC);
+ entry->fc_ports = BIT(port);
} else {
- cfge->fc_on_thresh = cpu_to_le16(0);
- cfge->fc_off_thresh = cpu_to_le16(0);
- cfge->fccfg_sbpen = 0;
- cfge->fc_ports = cpu_to_le32(0);
+ entry->fc_on_thresh = 0;
+ entry->fc_off_thresh = 0;
+ entry->fccfg_sbpen = 0;
+ entry->fc_ports = 0;
}
- if (ntmp_bpt_update_entry(&priv->ntmp, j, cfge)) {
- *cfge = old_cfge;
+ entry->entry_id = j;
+ if (ntmp_bpt_update_entry(&priv->ntmp, entry)) {
+ *entry = old_entry;
dev_warn(priv->dev,
"Failed to %s TX pause of buffer pool %d (swp%d)\n",
tx_pause ? "enable" : "disable", j, port);
diff --git a/drivers/net/dsa/netc/netc_switch.h b/drivers/net/dsa/netc/netc_switch.h
index c61d3e3a366a0..f0a370dbcffca 100644
--- a/drivers/net/dsa/netc/netc_switch.h
+++ b/drivers/net/dsa/netc/netc_switch.h
@@ -178,7 +178,7 @@ struct netc_switch {
u32 htmcapr_num_words;
u32 num_bp;
- struct bpt_cfge_data *bpt_list;
+ struct bpt_entry_data *bpt_list;
struct pci_dev *tmr_dev; /* The PTP Timer PCI device */
};
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index c967439ad3589..07a9117273220 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -608,6 +608,38 @@ static const struct ntmp_tbl_ops *ntmp_get_ett_ops(u8 version)
}
}
+static void ntmp_bpt_pack_v0(const void *entry, void *buf, int access_method)
+{
+ const struct bpt_entry_data *_entry = entry;
+ struct bpt_req_update *req = buf;
+ struct bpt_cfge_data *cfge;
+
+ cfge = &req->cfge;
+ cfge->fccfg_sbpen = _entry->fccfg_sbpen;
+ cfge->pfc_vector = _entry->pfc_vector;
+ cfge->max_thresh = cpu_to_le16(_entry->max_thresh);
+ cfge->fc_on_thresh = cpu_to_le16(_entry->fc_on_thresh);
+ cfge->fc_off_thresh = cpu_to_le16(_entry->fc_off_thresh);
+ cfge->sbp_thresh = cpu_to_le16(_entry->sbp_thresh);
+ cfge->sbp_eid = cpu_to_le32(_entry->sbp_eid);
+ cfge->fc_ports = cpu_to_le32(_entry->fc_ports);
+}
+
+static const struct ntmp_tbl_ops bpt_ops_v0 = {
+ .req_ua_len = sizeof(struct bpt_req_update),
+ .pack = ntmp_bpt_pack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_bpt_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &bpt_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)
{
@@ -1580,17 +1612,23 @@ int ntmp_ect_update_entry(struct ntmp_user *user, u32 entry_id)
}
EXPORT_SYMBOL_GPL(ntmp_ect_update_entry);
-int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct bpt_cfge_data *cfge)
+int ntmp_bpt_update_entry(struct ntmp_user *user,
+ struct bpt_entry_data *entry)
{
- struct bpt_req_update *req;
+ u8 version = user->tbl_ver[NTMP_BPT_ID];
+ const struct ntmp_tbl_ops *ops;
struct netc_swcbd swcbd;
struct netc_cbdr *cbdr;
union netc_cbd cbd;
+ void *buf;
int err;
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+ ops = ntmp_get_bpt_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;
@@ -1598,10 +1636,10 @@ int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
* which is maintained by the hardware. The BPSE_DATA is not present in
* the request data for 'Update' operation.
*/
- ntmp_fill_crd_eid(&req->rbe, user->tbl_ver[NTMP_BPT_ID], 0,
- NTMP_GEN_UA_CFGEU | BPT_UA_BPSEU, entry_id);
- req->cfge = *cfge;
- ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
+ ntmp_fill_crd_eid(buf, version, 0, NTMP_GEN_UA_CFGEU | BPT_UA_BPSEU,
+ entry->entry_id);
+ ops->pack(entry, buf, 0);
+ ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(ops->req_ua_len, 0),
NTMP_BPT_ID, NTMP_CMD_UPDATE, NTMP_AM_ENTRY_ID);
ntmp_select_and_lock_cbdr(user, &cbdr);
@@ -1609,7 +1647,8 @@ int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
if (err)
dev_err(user->dev,
"Failed to update %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_BPT_ID), entry_id, ERR_PTR(err));
+ ntmp_table_name(NTMP_BPT_ID), entry->entry_id,
+ ERR_PTR(err));
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 710ab88560c7d..c356060a17bb9 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp_private.h
+++ b/drivers/net/ethernet/freescale/enetc/ntmp_private.h
@@ -350,6 +350,26 @@ struct ett_req_ua {
struct ett_cfge_data cfge;
};
+/* Buffer Pool Table Statistics Element Data */
+struct bpt_bpse_data {
+ __le32 amount_used;
+ __le32 amount_used_hwm;
+ u8 bpd_fc_state;
+} __packed;
+
+/* Buffer Pool Table Configuration Element Data */
+struct bpt_cfge_data {
+ u8 fccfg_sbpen;
+ u8 pfc_vector;
+ __le16 max_thresh;
+ __le16 fc_on_thresh;
+ __le16 fc_off_thresh;
+ __le16 sbp_thresh;
+ __le16 resv;
+ __le32 sbp_eid;
+ __le32 fc_ports;
+};
+
/* Buffer Pool Table Request Data Buffer Format of Update action */
struct bpt_req_update {
struct ntmp_req_by_eid rbe;
diff --git a/include/linux/fsl/ntmp.h b/include/linux/fsl/ntmp.h
index 23a612ec0b969..c54bf95739960 100644
--- a/include/linux/fsl/ntmp.h
+++ b/include/linux/fsl/ntmp.h
@@ -242,26 +242,27 @@ struct ett_entry_data {
u32 esqa_tgt_eid;
};
-struct bpt_bpse_data {
- __le32 amount_used;
- __le32 amount_used_hwm;
- u8 bpd_fc_state;
-#define BPT_FC_STATE BIT(0)
-#define BPT_BPD BIT(1)
-} __packed;
+struct bpt_entry_data {
+ u32 entry_id;
-struct bpt_cfge_data {
+ /* CFGE_DATA */
u8 fccfg_sbpen;
#define BPT_FC_CFG GENMASK(2, 1)
#define BPT_FC_CFG_EN_BPFC 1
u8 pfc_vector;
- __le16 max_thresh;
- __le16 fc_on_thresh;
- __le16 fc_off_thresh;
- __le16 sbp_thresh;
- __le16 resv;
- __le32 sbp_eid;
- __le32 fc_ports;
+ u16 max_thresh;
+ u16 fc_on_thresh;
+ u16 fc_off_thresh;
+ u16 sbp_thresh;
+ u32 sbp_eid;
+ u32 fc_ports;
+
+ /* BPSE_DATA */
+ u32 amount_used;
+ u32 amount_used_hwm;
+ u8 bpd_fc_state;
+#define BPT_FC_STATE BIT(0)
+#define BPT_BPD BIT(1)
};
union ntmp_fmt_eid {
@@ -319,8 +320,8 @@ int ntmp_ett_update_entry(struct ntmp_user *user,
const struct ett_entry_data *entry);
int ntmp_ett_delete_entry(struct ntmp_user *user, u32 entry_id);
int ntmp_ect_update_entry(struct ntmp_user *user, u32 entry_id);
-int ntmp_bpt_update_entry(struct ntmp_user *user, u32 entry_id,
- const struct bpt_cfge_data *cfge);
+int ntmp_bpt_update_entry(struct ntmp_user *user,
+ struct bpt_entry_data *entry);
#else
static inline int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev,
const struct netc_cbdr_regs *regs)
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 08/14] net: enetc: add generic ntmp_add_entry_by_id() helper
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (6 preceding siblings ...)
2026-12-04 7:14 ` [PATCH net-next 07/14] net: enetc: decouple BPT " wei.fang
@ 2026-12-04 7:14 ` wei.fang
2026-12-04 7:14 ` [PATCH net-next 09/14] net: enetc: simplify callers of ntmp_query_entry_by_id() wei.fang
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Some NTMP tables have their entry IDs allocated by software, and adding
a new entry to them follows the same logic: look up the table ops,
allocate the request buffer, fill the common request data and header,
then issue the add command over a CBDR. Adding such a table today means
duplicating this boilerplate.
Introduce ntmp_add_entry_by_id() to factor out this common logic, along
with ntmp_table_ops() to select the table ops by table ID. The update
actions are passed in so callers can request the needed element updates.
Convert the MAFT and ETT add paths to use the new helper. More tables
will reuse it later.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/ntmp.c | 182 +++++++++++---------
1 file changed, 96 insertions(+), 86 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 07a9117273220..fec6c3fcfd2e4 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -640,6 +640,76 @@ static const struct ntmp_tbl_ops *ntmp_get_bpt_ops(u8 version)
}
}
+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_IPFT_ID:
+ return ntmp_get_ipft_ops(version);
+ case NTMP_FDBT_ID:
+ return ntmp_get_fdbt_ops(version);
+ case NTMP_VFT_ID:
+ return ntmp_get_vft_ops(version);
+ case NTMP_ETT_ID:
+ return ntmp_get_ett_ops(version);
+ case NTMP_BPT_ID:
+ return ntmp_get_bpt_ops(version);
+ default:
+ return NULL;
+ }
+}
+
+/**
+ * ntmp_add_entry_by_id - add a new entry to a table whose entry ID is
+ * allocated by software
+ * @user: target ntmp_user struct
+ * @tbl_id: ID of the target table
+ * @entry_id: the software-allocated entry ID
+ * @entry: the logical entry data to be packed into the request buffer
+ * @ua: update actions applied to the entry, 0 if none
+ *
+ * A generic helper for tables that add a new entry with a software-allocated
+ * entry ID. It looks up the table ops for the current version, allocates the
+ * request buffer, packs the entry data and issues the add command over a CBDR.
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+static int ntmp_add_entry_by_id(struct ntmp_user *user, int tbl_id,
+ u32 entry_id, void *entry, u16 ua)
+{
+ 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;
+ void *buf;
+ int err;
+
+ ops = ntmp_table_ops(tbl_id, version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = ops->req_ua_len;
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
+ if (err)
+ return err;
+
+ ntmp_fill_crd_eid(buf, version, 0, ua, entry_id);
+ ops->pack(entry, buf, NTMP_AM_ENTRY_ID);
+ ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(ops->req_ua_len, 0),
+ tbl_id, NTMP_CMD_ADD, 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 add %s entry 0x%x, err: %pe\n",
+ ntmp_table_name(tbl_id), entry_id, ERR_PTR(err));
+ ntmp_unlock_cbdr(cbdr);
+
+ return err;
+}
+
static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
u32 entry_id, u32 req_len, u32 resp_len)
{
@@ -716,39 +786,8 @@ static int ntmp_query_entry_by_id(struct netc_cbdr *cbdr, int tbl_id,
int ntmp_maft_add_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;
- union netc_cbd cbd;
- void *buf;
- int err;
-
- 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(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);
-
- ntmp_select_and_lock_cbdr(user, &cbdr);
- err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
- if (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;
+ return ntmp_add_entry_by_id(user, NTMP_MAFT_ID, entry->entry_id,
+ (void *)entry, 0);
}
EXPORT_SYMBOL_GPL(ntmp_maft_add_entry);
@@ -1460,17 +1499,32 @@ int ntmp_vft_delete_entry(struct ntmp_user *user, u16 vid)
EXPORT_SYMBOL_GPL(ntmp_vft_delete_entry);
/**
- * ntmp_ett_set_entry - add a new entry to the egress treatment table or
- * update the configuration element data of the specified entry
+ * ntmp_ett_add_entry - add a new entry to the egress treatment table
* @user: target ntmp_user struct
- * @cmd: command type, NTMP_CMD_ADD or NTMP_CMD_UPDATE
- * @entry: the entry data, entry->entry_id selects the entry and the
+ * @entry: the entry data, entry->entry_id is the entry ID and the
* configuration element data provides the values
*
* Return: 0 on success, otherwise a negative error code
*/
-static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,
- const struct ett_entry_data *entry)
+int ntmp_ett_add_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry)
+{
+ return ntmp_add_entry_by_id(user, NTMP_ETT_ID, entry->entry_id,
+ (void *)entry, NTMP_GEN_UA_CFGEU);
+}
+EXPORT_SYMBOL_GPL(ntmp_ett_add_entry);
+
+/**
+ * ntmp_ett_update_entry - update the configuration element data of the
+ * specified entry
+ * @user: target ntmp_user struct
+ * @entry: the entry data, entry->entry_id selects the entry and the
+ * configuration element data provides the new values
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+int ntmp_ett_update_entry(struct ntmp_user *user,
+ const struct ett_entry_data *entry)
{
u8 version = user->tbl_ver[NTMP_ETT_ID];
const struct ntmp_tbl_ops *ops;
@@ -1480,9 +1534,6 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,
void *buf;
int err;
- if (cmd != NTMP_CMD_ADD && cmd != NTMP_CMD_UPDATE)
- return -EINVAL;
-
ops = ntmp_get_ett_ops(version);
if (!ops)
return -EOPNOTSUPP;
@@ -1499,59 +1550,18 @@ static int ntmp_ett_set_entry(struct ntmp_user *user, int cmd,
/* Request header */
ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
- NTMP_ETT_ID, cmd, NTMP_AM_ENTRY_ID);
+ NTMP_ETT_ID, NTMP_CMD_UPDATE, NTMP_AM_ENTRY_ID);
ntmp_select_and_lock_cbdr(user, &cbdr);
err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
- ntmp_unlock_cbdr(cbdr);
-
- return err;
-}
-
-/**
- * ntmp_ett_add_entry - add a new entry to the egress treatment table
- * @user: target ntmp_user struct
- * @entry: the entry data, entry->entry_id is the entry ID and the
- * configuration element data provides the values
- *
- * Return: 0 on success, otherwise a negative error code
- */
-int ntmp_ett_add_entry(struct ntmp_user *user,
- const struct ett_entry_data *entry)
-{
- int err;
-
- err = ntmp_ett_set_entry(user, NTMP_CMD_ADD, entry);
- if (err)
- dev_err(user->dev, "Failed to add %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_ETT_ID), entry->entry_id,
- ERR_PTR(err));
-
- return err;
-}
-EXPORT_SYMBOL_GPL(ntmp_ett_add_entry);
-
-/**
- * ntmp_ett_update_entry - update the configuration element data of the
- * specified entry
- * @user: target ntmp_user struct
- * @entry: the entry data, entry->entry_id selects the entry and the
- * configuration element data provides the new values
- *
- * Return: 0 on success, otherwise a negative error code
- */
-int ntmp_ett_update_entry(struct ntmp_user *user,
- const struct ett_entry_data *entry)
-{
- int err;
-
- err = ntmp_ett_set_entry(user, NTMP_CMD_UPDATE, entry);
if (err)
dev_err(user->dev,
"Failed to update %s entry 0x%x, err: %pe\n",
ntmp_table_name(NTMP_ETT_ID), entry->entry_id,
ERR_PTR(err));
+ ntmp_unlock_cbdr(cbdr);
+
return err;
}
EXPORT_SYMBOL_GPL(ntmp_ett_update_entry);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 09/14] net: enetc: simplify callers of ntmp_query_entry_by_id()
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (7 preceding siblings ...)
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
2026-12-04 7:14 ` [PATCH net-next 10/14] net: enetc: add kernel-doc for ntmp_delete_entry_by_id() wei.fang
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
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
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 10/14] net: enetc: add kernel-doc for ntmp_delete_entry_by_id()
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (8 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
The other generic by-ID helpers already have kernel-doc, while
ntmp_delete_entry_by_id() does not. Add its kernel-doc to keep the
documentation of these helpers consistent.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/ntmp.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 40085fd2fe61d..837bb37a349fe 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -710,6 +710,16 @@ static int ntmp_add_entry_by_id(struct ntmp_user *user, int tbl_id,
return err;
}
+/**
+ * ntmp_delete_entry_by_id - delete 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 delete
+ * @req_len: length of the request data buffer
+ * @resp_len: length of the response data buffer
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
static int ntmp_delete_entry_by_id(struct ntmp_user *user, int tbl_id,
u32 entry_id, u32 req_len, u32 resp_len)
{
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 11/14] net: enetc: add a generic helper to update an NTMP entry by entry ID
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (9 preceding siblings ...)
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 ` 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
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
Several NTMP tables implement their own update-by-entry-ID routine, and
ntmp_fdbt_update_entry(), ntmp_ett_update_entry() and
ntmp_bpt_update_entry() all repeat the same sequence: look up the table
ops, allocate the request buffer, fill the CRD and entry ID, pack the
config, build the request header and issue the command.
Add a generic ntmp_update_entry_by_id() helper that carries this common
flow and takes the per-table specifics, entry ID, update actions and
response length, as arguments. Convert the FDBT, ETT and BPT update
functions to call it. This removes the duplicated boilerplate and keeps
future table update paths consistent.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/ntmp.c | 174 +++++++-------------
1 file changed, 63 insertions(+), 111 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 837bb37a349fe..a0605f0d0b106 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -710,6 +710,61 @@ static int ntmp_add_entry_by_id(struct ntmp_user *user, int tbl_id,
return err;
}
+/**
+ * ntmp_update_entry_by_id - update 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 update
+ * @entry: the logical entry data to be packed into the request buffer
+ * @ua: update actions applied to the entry, 0 if none
+ * @resp_len: length of the response data buffer, 0 if none
+ *
+ * A generic helper for tables that update an entry by its entry ID. It looks
+ * up the table ops for the current version, allocates the request buffer,
+ * packs the entry data and issues the update command over a CBDR.
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+static int ntmp_update_entry_by_id(struct ntmp_user *user, int tbl_id,
+ u32 entry_id, void *entry, u16 ua,
+ u32 resp_len)
+{
+ 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;
+ void *buf;
+ u32 len;
+ int err;
+
+ ops = ntmp_table_ops(tbl_id, version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = max(ops->req_ua_len, resp_len);
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
+ if (err)
+ return err;
+
+ ntmp_fill_crd_eid(buf, version, 0, ua, entry_id);
+ ops->pack(entry, buf, NTMP_AM_ENTRY_ID);
+
+ len = NTMP_LEN(ops->req_ua_len, resp_len);
+ ntmp_fill_request_hdr(&cbd, swcbd.dma, len, tbl_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 %s entry 0x%x, err: %pe\n",
+ ntmp_table_name(tbl_id), entry_id, ERR_PTR(err));
+ ntmp_unlock_cbdr(cbdr);
+
+ return err;
+}
+
/**
* ntmp_delete_entry_by_id - delete an entry of a table by its entry ID
* @user: target ntmp_user struct
@@ -1081,42 +1136,9 @@ EXPORT_SYMBOL_GPL(ntmp_fdbt_add_entry);
int ntmp_fdbt_update_entry(struct ntmp_user *user,
const struct fdbt_entry_data *entry)
{
- u8 version = user->tbl_ver[NTMP_FDBT_ID];
- const struct ntmp_tbl_ops *ops;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- void *buf;
- u32 len;
- int err;
-
- ops = ntmp_get_fdbt_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;
-
- /* Request data */
- ntmp_fill_crd(buf, version, 0, NTMP_GEN_UA_CFGEU);
- ops->pack(entry, buf, NTMP_AM_ENTRY_ID);
-
- /* Request header */
- len = NTMP_LEN(ops->req_ua_len, NTMP_STATUS_RESP_LEN);
- ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_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 %s entry, err: %pe\n",
- ntmp_table_name(NTMP_FDBT_ID), ERR_PTR(err));
-
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_update_entry_by_id(user, NTMP_FDBT_ID, entry->entry_id,
+ (void *)entry, NTMP_GEN_UA_CFGEU,
+ NTMP_STATUS_RESP_LEN);
}
EXPORT_SYMBOL_GPL(ntmp_fdbt_update_entry);
@@ -1543,43 +1565,8 @@ EXPORT_SYMBOL_GPL(ntmp_ett_add_entry);
int ntmp_ett_update_entry(struct ntmp_user *user,
const struct ett_entry_data *entry)
{
- u8 version = user->tbl_ver[NTMP_ETT_ID];
- const struct ntmp_tbl_ops *ops;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- void *buf;
- int err;
-
- ops = ntmp_get_ett_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;
-
- /* Request data */
- ntmp_fill_crd_eid(buf, version, 0, NTMP_GEN_UA_CFGEU,
- entry->entry_id);
- ops->pack(entry, buf, 0);
-
- /* Request header */
- ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
- NTMP_ETT_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 %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_ETT_ID), entry->entry_id,
- ERR_PTR(err));
-
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_update_entry_by_id(user, NTMP_ETT_ID, entry->entry_id,
+ (void *)entry, NTMP_GEN_UA_CFGEU, 0);
}
EXPORT_SYMBOL_GPL(ntmp_ett_update_entry);
@@ -1642,44 +1629,9 @@ EXPORT_SYMBOL_GPL(ntmp_ect_update_entry);
int ntmp_bpt_update_entry(struct ntmp_user *user,
struct bpt_entry_data *entry)
{
- u8 version = user->tbl_ver[NTMP_BPT_ID];
- const struct ntmp_tbl_ops *ops;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- void *buf;
- int err;
-
- ops = ntmp_get_bpt_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;
-
- /* Note that BPT_UA_BPSEU is used to update the BPSE_DATA of the entry,
- * which is maintained by the hardware. The BPSE_DATA is not present in
- * the request data for 'Update' operation.
- */
- ntmp_fill_crd_eid(buf, version, 0, NTMP_GEN_UA_CFGEU | BPT_UA_BPSEU,
- entry->entry_id);
- ops->pack(entry, buf, 0);
- ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(ops->req_ua_len, 0),
- NTMP_BPT_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 %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_BPT_ID), entry->entry_id,
- ERR_PTR(err));
-
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_update_entry_by_id(user, NTMP_BPT_ID, entry->entry_id,
+ (void *)entry, NTMP_GEN_UA_CFGEU |
+ BPT_UA_BPSEU, 0);
}
EXPORT_SYMBOL_GPL(ntmp_bpt_update_entry);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 12/14] net: enetc: convert ntmp_ect_update_entry() to the generic update helper
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (10 preceding siblings ...)
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 ` 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
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
ntmp_ect_update_entry() still open-codes the update sequence while the
other tables now route through ntmp_update_entry_by_id(). To let the
Egress Count Table (ECT) reuse the generic helper, it needs a table ops
instance.
Add ect_ops_v0 and register it in ntmp_table_ops(). The ECT is a static
bounded-index table whose entries are always present, so it has no "Add"
operation, and its "Update" only resets the counter with no CFGE_DATA to
carry, hence its pack() callback is empty. Convert ntmp_ect_update_entry()
to call ntmp_update_entry_by_id(), which removes the duplicated
boilerplate.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/ntmp.c | 58 ++++++++++-----------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index a0605f0d0b106..3f8a39df78b6f 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -608,6 +608,31 @@ static const struct ntmp_tbl_ops *ntmp_get_ett_ops(u8 version)
}
}
+static void ntmp_ect_pack_v0(const void *entry, void *buf, int access_method)
+{
+ /* Egress Count table is a static bounded index table, its entries
+ * are always present, so it does not support "Add" operation. The
+ * "Update" operation only resets the counter, so there is no
+ * CFGE_DATA to be updated. Therefore, there's no need to pack any
+ * data here.
+ */
+}
+
+static const struct ntmp_tbl_ops ect_ops_v0 = {
+ .req_ua_len = sizeof(struct ntmp_req_by_eid),
+ .pack = ntmp_ect_pack_v0,
+};
+
+static const struct ntmp_tbl_ops *ntmp_get_ect_ops(u8 version)
+{
+ switch (version) {
+ case NTMP_TBL_V(0):
+ return &ect_ops_v0;
+ default:
+ return NULL;
+ }
+}
+
static void ntmp_bpt_pack_v0(const void *entry, void *buf, int access_method)
{
const struct bpt_entry_data *_entry = entry;
@@ -653,6 +678,8 @@ static const struct ntmp_tbl_ops *ntmp_table_ops(int tbl_id, u8 version)
return ntmp_get_vft_ops(version);
case NTMP_ETT_ID:
return ntmp_get_ett_ops(version);
+ case NTMP_ECT_ID:
+ return ntmp_get_ect_ops(version);
case NTMP_BPT_ID:
return ntmp_get_bpt_ops(version);
default:
@@ -1594,35 +1621,8 @@ EXPORT_SYMBOL_GPL(ntmp_ett_delete_entry);
*/
int ntmp_ect_update_entry(struct ntmp_user *user, u32 entry_id)
{
- struct ntmp_req_by_eid *req;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- int err;
-
- swcbd.size = sizeof(*req);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
- if (err)
- return err;
-
- /* Request data */
- ntmp_fill_crd_eid(req, user->tbl_ver[NTMP_ECT_ID], 0,
- ECT_UA_STSEU, entry_id);
-
- /* Request header */
- ntmp_fill_request_hdr(&cbd, swcbd.dma, NTMP_LEN(swcbd.size, 0),
- NTMP_ECT_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 %s entry 0x%x, err: %pe\n",
- ntmp_table_name(NTMP_ECT_ID), entry_id, ERR_PTR(err));
-
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_update_entry_by_id(user, NTMP_ECT_ID, entry_id, NULL,
+ ECT_UA_STSEU, 0);
}
EXPORT_SYMBOL_GPL(ntmp_ect_update_entry);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 13/14] net: enetc: add a generic helper to add an NTMP entry by key
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (11 preceding siblings ...)
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 ` 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
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
From: Wei Fang <wei.fang@nxp.com>
The Add operations for the IPFT, FDBT and VLAN filter tables share
the same logic: pack the request, issue an "Add then Query" command
so the hardware-allotted entry ID can be read back, and unpack the
response. Three separate functions open-coded this identical flow.
Add a generic ntmp_add_entry_by_key() helper that takes the table
ID, the update-actions mask and the access method, and convert
ntmp_ipft_add_entry(), ntmp_fdbt_add_entry() and ntmp_vft_add_entry()
into thin wrappers around it.
With the Add path moved out, ntmp_vft_set_entry() no longer needs to
handle both commands. Turn it into a dedicated ntmp_vft_update_entry()
that always issues NTMP_CMD_UPDATE, and drop the now-redundant command
argument and its validation.
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/ntmp.c | 242 ++++++++------------
1 file changed, 95 insertions(+), 147 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/ntmp.c b/drivers/net/ethernet/freescale/enetc/ntmp.c
index 3f8a39df78b6f..0622e7e0b5756 100644
--- a/drivers/net/ethernet/freescale/enetc/ntmp.c
+++ b/drivers/net/ethernet/freescale/enetc/ntmp.c
@@ -910,6 +910,73 @@ static int ntmp_query_entry_by_id(struct ntmp_user *user, int tbl_id,
return err;
}
+/**
+ * ntmp_add_entry_by_key - add a new entry to a table by its key element
+ * @user: target ntmp_user struct
+ * @tbl_id: ID of the target table
+ * @entry: the logical entry data to be packed into the request buffer, the
+ * hardware-allocated entry ID is read back into it on success
+ * @ua: update actions applied to the entry, 0 if none
+ * @access_method: how the key element is matched, either NTMP_AM_EXACT_KEY
+ * for tables matched by an exact key or NTMP_AM_TERNARY_KEY for tables
+ * matched by a masked (ternary) key
+ *
+ * A generic helper for tables that add a new entry by its key element. The
+ * entry ID of such tables is allocated by hardware, so it packs the entry
+ * data and issues an "Add and Query" command over a CBDR, so that the
+ * hardware-allocated entry ID can be read back and unpacked into @entry.
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+static int ntmp_add_entry_by_key(struct ntmp_user *user, int tbl_id,
+ void *entry, u16 ua, int access_method)
+{
+ 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;
+ void *buf;
+ u32 len;
+ int err;
+
+ ops = ntmp_table_ops(tbl_id, version);
+ if (!ops)
+ return -EOPNOTSUPP;
+
+ swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
+ err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
+ if (err)
+ return err;
+
+ /* Request data */
+ ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, ua);
+ ops->pack(entry, buf, access_method);
+
+ len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len);
+ /* The entry ID is allocated by hardware, so an "Add, followed by a
+ * Query" operation is required to retrieve the entry ID from the
+ * hardware.
+ */
+ ntmp_fill_request_hdr(&cbd, swcbd.dma, len, tbl_id,
+ NTMP_CMD_AQ, access_method);
+
+ ntmp_select_and_lock_cbdr(user, &cbdr);
+ err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
+ if (err) {
+ dev_err(user->dev, "Failed to add %s entry, err: %pe\n",
+ ntmp_table_name(tbl_id), ERR_PTR(err));
+ goto unlock_cbdr;
+ }
+
+ ops->unpack(buf, entry, true);
+
+unlock_cbdr:
+ ntmp_unlock_cbdr(cbdr);
+
+ return err;
+}
+
int ntmp_maft_add_entry(struct ntmp_user *user, struct maft_entry_data *entry)
{
return ntmp_add_entry_by_id(user, NTMP_MAFT_ID, entry->entry_id,
@@ -1028,51 +1095,9 @@ EXPORT_SYMBOL_GPL(ntmp_rsst_query_entry);
int ntmp_ipft_add_entry(struct ntmp_user *user,
struct ipft_entry_data *entry)
{
- u8 version = user->tbl_ver[NTMP_IPFT_ID];
- const struct ntmp_tbl_ops *ops;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- void *buf;
- u32 len;
- int err;
-
- ops = ntmp_get_ipft_ops(version);
- if (!ops)
- return -EOPNOTSUPP;
-
- swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
- if (err)
- return err;
-
- /* Note that NTMP_GEN_UA_STSEU is used to reset the statistics of
- * the entry. The STSE_DATA is not present in the request data for
- * 'Add' operation.
- */
- ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID,
- NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU);
- ops->pack(entry, buf, NTMP_AM_TERNARY_KEY);
-
- len = NTMP_LEN(ops->req_ua_len, swcbd.size);
- ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_IPFT_ID,
- NTMP_CMD_AQ, NTMP_AM_TERNARY_KEY);
-
- ntmp_select_and_lock_cbdr(user, &cbdr);
- err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
- if (err) {
- dev_err(user->dev, "Failed to add %s entry, err: %pe\n",
- ntmp_table_name(NTMP_IPFT_ID), ERR_PTR(err));
-
- goto unlock_cbdr;
- }
-
- ops->unpack(buf, entry, true);
-
-unlock_cbdr:
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_add_entry_by_key(user, NTMP_IPFT_ID, (void *)entry,
+ NTMP_GEN_UA_CFGEU | NTMP_GEN_UA_STSEU,
+ NTMP_AM_TERNARY_KEY);
}
EXPORT_SYMBOL_GPL(ntmp_ipft_add_entry);
@@ -1104,50 +1129,8 @@ EXPORT_SYMBOL_GPL(ntmp_ipft_delete_entry);
int ntmp_fdbt_add_entry(struct ntmp_user *user,
struct fdbt_entry_data *entry)
{
- u8 version = user->tbl_ver[NTMP_FDBT_ID];
- const struct ntmp_tbl_ops *ops;
- struct netc_swcbd swcbd;
- struct netc_cbdr *cbdr;
- union netc_cbd cbd;
- void *buf;
- u32 len;
- int err;
-
- ops = ntmp_get_fdbt_ops(version);
- if (!ops)
- return -EOPNOTSUPP;
-
- swcbd.size = max(ops->req_ua_len, ops->resp_query_len);
- err = ntmp_alloc_data_mem(user->dev, &swcbd, &buf);
- if (err)
- return err;
-
- /* Request data */
- ntmp_fill_crd(buf, version, NTMP_QA_ENTRY_ID, NTMP_GEN_UA_CFGEU);
- ops->pack(entry, buf, NTMP_AM_EXACT_KEY);
-
- len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len);
- /* The entry ID is allotted by hardware, so we need to perform
- * a query action after the add action to get the entry ID from
- * hardware.
- */
- ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
- NTMP_CMD_AQ, NTMP_AM_EXACT_KEY);
-
- ntmp_select_and_lock_cbdr(user, &cbdr);
- err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
- if (err) {
- dev_err(user->dev, "Failed to add %s entry, err: %pe\n",
- ntmp_table_name(NTMP_FDBT_ID), ERR_PTR(err));
- goto unlock_cbdr;
- }
-
- ops->unpack(buf, entry, true);
-
-unlock_cbdr:
- ntmp_unlock_cbdr(cbdr);
-
- return err;
+ return ntmp_add_entry_by_key(user, NTMP_FDBT_ID, (void *)entry,
+ NTMP_GEN_UA_CFGEU, NTMP_AM_EXACT_KEY);
}
EXPORT_SYMBOL_GPL(ntmp_fdbt_add_entry);
@@ -1418,17 +1401,31 @@ int ntmp_fdbt_delete_port_dynamic_entries(struct ntmp_user *user, int port)
EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_port_dynamic_entries);
/**
- * ntmp_vft_set_entry - add an entry into the VLAN filter table or update
- * the configuration element data of the specified VLAN filter entry
+ * ntmp_vft_add_entry - add an entry into the VLAN filter table
+ * @user: target ntmp_user struct
+ * @entry: the entry data, entry->vid is the VLAN ID and the configuration
+ * element data provides the values
+ * Return: 0 on success, otherwise a negative error code
+ */
+int ntmp_vft_add_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry)
+{
+ return ntmp_add_entry_by_key(user, NTMP_VFT_ID, (void *)entry,
+ NTMP_GEN_UA_CFGEU, NTMP_AM_EXACT_KEY);
+}
+EXPORT_SYMBOL_GPL(ntmp_vft_add_entry);
+
+/**
+ * ntmp_vft_update_entry - update the configuration element data of the
+ * specified VLAN filter entry
* @user: target ntmp_user struct
- * @cmd: command type, NTMP_CMD_AQ or NTMP_CMD_UPDATE
* @entry: the entry data, entry->vid selects the VLAN filter entry and
- * the configuration element data provides the values
+ * the configuration element data provides the new values
*
* Return: 0 on success, otherwise a negative error code
*/
-static int ntmp_vft_set_entry(struct ntmp_user *user, int cmd,
- struct vft_entry_data *entry)
+int ntmp_vft_update_entry(struct ntmp_user *user,
+ struct vft_entry_data *entry)
{
u8 version = user->tbl_ver[NTMP_VFT_ID];
const struct ntmp_tbl_ops *ops;
@@ -1455,67 +1452,18 @@ static int ntmp_vft_set_entry(struct ntmp_user *user, int cmd,
/* Request header */
len = NTMP_LEN(ops->req_ua_len, ops->resp_query_len);
ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_VFT_ID,
- cmd, NTMP_AM_EXACT_KEY);
+ NTMP_CMD_UPDATE, NTMP_AM_EXACT_KEY);
ntmp_select_and_lock_cbdr(user, &cbdr);
err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
- if (err)
- goto unlock_cbdr;
-
- if (cmd == NTMP_CMD_AQ)
- ops->unpack(buf, (void *)entry, true);
-
-unlock_cbdr:
- ntmp_unlock_cbdr(cbdr);
-
- return err;
-}
-
-/**
- * ntmp_vft_add_entry - add an entry into the VLAN filter table
- * @user: target ntmp_user struct
- * @entry: the entry data, entry->vid is the VLAN ID and the configuration
- * element data provides the values
- *
- * Return: 0 on success, otherwise a negative error code
- */
-int ntmp_vft_add_entry(struct ntmp_user *user,
- struct vft_entry_data *entry)
-{
- int err;
-
- err = ntmp_vft_set_entry(user, NTMP_CMD_AQ, entry);
- if (err)
- dev_err(user->dev,
- "Failed to add %s entry, vid: %u, err: %pe\n",
- ntmp_table_name(NTMP_VFT_ID), entry->vid,
- ERR_PTR(err));
-
- return err;
-}
-EXPORT_SYMBOL_GPL(ntmp_vft_add_entry);
-
-/**
- * ntmp_vft_update_entry - update the configuration element data of the
- * specified VLAN filter entry
- * @user: target ntmp_user struct
- * @entry: the entry data, entry->vid selects the VLAN filter entry and
- * the configuration element data provides the new values
- *
- * Return: 0 on success, otherwise a negative error code
- */
-int ntmp_vft_update_entry(struct ntmp_user *user,
- struct vft_entry_data *entry)
-{
- int err;
-
- err = ntmp_vft_set_entry(user, NTMP_CMD_UPDATE, entry);
if (err)
dev_err(user->dev,
"Failed to update %s entry, vid: %u, err: %pe\n",
ntmp_table_name(NTMP_VFT_ID), entry->vid,
ERR_PTR(err));
+ ntmp_unlock_cbdr(cbdr);
+
return err;
}
EXPORT_SYMBOL_GPL(ntmp_vft_update_entry);
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 14/14] net: enetc: convert the RSST to the generic NTMP entry helpers
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
` (12 preceding siblings ...)
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
13 siblings, 0 replies; 15+ messages in thread
From: wei.fang @ 2026-12-04 7:14 UTC (permalink / raw)
To: xiaoning.wang, claudiu.manoil, vladimir.oltean, andrew, olteanv,
davem, edumazet, kuba, pabeni, chleroy, richardcochran
Cc: wei.fang, imx, netdev, linuxppc-dev, linux-arm-kernel
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
^ permalink raw reply related [flat|nested] 15+ messages in thread