From: wei.fang@oss.nxp.com
To: xiaoning.wang@nxp.com, claudiu.manoil@nxp.com,
vladimir.oltean@nxp.com, andrew@lunn.ch, olteanv@gmail.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, chleroy@kernel.org, richardcochran@gmail.com
Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH net-next 07/14] net: enetc: decouple BPT logical config from hardware wire format
Date: Fri, 4 Dec 2026 15:14:03 +0800 [thread overview]
Message-ID: <20261204071410.692071-8-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20261204071410.692071-1-wei.fang@oss.nxp.com>
From: Wei Fang <wei.fang@nxp.com>
Current SoCs only implement 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
next prev parent reply other threads:[~2026-12-04 7:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 7:13 [PATCH net-next 00/14] net: enetc: refactor NTMP table handling and add generic helpers wei.fang
2026-12-04 7:13 ` [PATCH net-next 01/14] net: enetc: use an ID-indexed array to track NTMP table versions wei.fang
2026-12-04 7:13 ` [PATCH net-next 02/14] net: enetc: decouple MAFT logical config from hardware wire format wei.fang
2026-12-04 7:13 ` [PATCH net-next 03/14] net: enetc: decouple IPFT " wei.fang
2026-12-04 7:14 ` [PATCH net-next 04/14] net: enetc: decouple FDBT " wei.fang
2026-12-04 7:14 ` [PATCH net-next 05/14] net: enetc: decouple VFT " wei.fang
2026-12-04 7:14 ` [PATCH net-next 06/14] net: enetc: decouple ETT " wei.fang
2026-12-04 7:14 ` wei.fang [this message]
2026-12-04 7:14 ` [PATCH net-next 08/14] net: enetc: add generic ntmp_add_entry_by_id() helper wei.fang
2026-12-04 7:14 ` [PATCH net-next 09/14] net: enetc: simplify callers of ntmp_query_entry_by_id() wei.fang
2026-12-04 7:14 ` [PATCH net-next 10/14] net: enetc: add kernel-doc for ntmp_delete_entry_by_id() wei.fang
2026-12-04 7:14 ` [PATCH net-next 11/14] net: enetc: add a generic helper to update an NTMP entry by entry ID wei.fang
2026-12-04 7:14 ` [PATCH net-next 12/14] net: enetc: convert ntmp_ect_update_entry() to the generic update helper wei.fang
2026-12-04 7:14 ` [PATCH net-next 13/14] net: enetc: add a generic helper to add an NTMP entry by key wei.fang
2026-12-04 7:14 ` [PATCH net-next 14/14] net: enetc: convert the RSST to the generic NTMP entry helpers wei.fang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204071410.692071-8-wei.fang@oss.nxp.com \
--to=wei.fang@oss.nxp.com \
--cc=andrew@lunn.ch \
--cc=chleroy@kernel.org \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vladimir.oltean@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox