[PATCH net-next 11/14] net: enetc: add a generic helper to update an NTMP entry by entry ID
wei.fang at oss.nxp.com
wei.fang at oss.nxp.com
Thu Dec 3 23:14:07 PST 2026
From: Wei Fang <wei.fang at 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 at 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
More information about the linux-arm-kernel
mailing list