]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: enetc: add interfaces to manage dynamic FDB entries
authorWei Fang <wei.fang@nxp.com>
Thu, 11 Jun 2026 02:14:50 +0000 (10:14 +0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 15 Jun 2026 21:32:05 +0000 (14:32 -0700)
Add three interfaces to manage dynamic entries in the FDB table:

ntmp_fdbt_update_activity_element(): Update the activity element of all
dynamic FDB entries. For each entry, if its activity flag is not set,
which means no packet has matched this entry since the last update, the
activity counter is incremented. Otherwise, both the activity flag and
activity counter are reset. The activity counter is used to track how
long an FDB entry has been inactive, which is useful for implementing
an ageing mechanism.

ntmp_fdbt_delete_ageing_entries(): Delete all dynamic FDB entries whose
activity flag is not set and whose activity counter is greater than or
equal to the specified threshold. This is used to remove stale entries
that have been inactive for too long.

ntmp_fdbt_delete_port_dynamic_entries(): Delete all dynamic FDB entries
associated with the specified switch port. This is typically called when
a port goes down or is removed from a bridge.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Link: https://patch.msgid.link/20260611021458.2629145-2-wei.fang@oss.nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/enetc/ntmp.c
drivers/net/ethernet/freescale/enetc/ntmp_private.h
include/linux/fsl/ntmp.h

index f71cad9434249e352328eeba511c646807ddb80d..bda26fe93b8df72ca03cd6bc7e02deeb91d2f89f 100644 (file)
@@ -31,6 +31,7 @@
 #define NTMP_GEN_UA_STSEU              BIT(1)
 
 /* Specific Update Actions for some tables */
+#define FDBT_UA_ACTEU                  BIT(1)
 #define BPT_UA_BPSEU                   BIT(1)
 
 /* Query Action: 0: Full query. 1: Query entry ID, the fields after entry
@@ -793,6 +794,167 @@ unlock_cbdr:
 }
 EXPORT_SYMBOL_GPL(ntmp_fdbt_search_port_entry);
 
+/**
+ * ntmp_fdbt_update_activity_element - update the activity element of all
+ * the dynamic entries in the FDB table.
+ * @user: target ntmp_user struct
+ *
+ * A single activity update management could be used to process all the
+ * dynamic entries in the FDB table. When hardware process an activity
+ * update management command for an entry in the FDB table and the entry
+ * does not have its activity flag set, the activity counter is incremented.
+ * However, if the activity flag is set, then both the activity flag and
+ * activity counter are reset. Software can issue the activity update
+ * management commands at predefined times and the value of the activity
+ * counter can then be used to estimate the period of how long an FDB
+ * entry has been inactive.
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+int ntmp_fdbt_update_activity_element(struct ntmp_user *user)
+{
+       struct fdbt_req_ua *req;
+       struct netc_swcbd swcbd;
+       struct netc_cbdr *cbdr;
+       union netc_cbd cbd;
+       u32 len;
+       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(&req->crd, user->tbl.fdbt_ver, 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;
+
+       /* Request header */
+       len = NTMP_LEN(swcbd.size, NTMP_STATUS_RESP_LEN);
+       /* For activity update, the access method must be search */
+       ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
+                             NTMP_CMD_UPDATE, NTMP_AM_SEARCH);
+
+       ntmp_select_and_lock_cbdr(user, &cbdr);
+       err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
+       if (err)
+               dev_err(user->dev,
+                       "Failed to update activity of %s, err: %pe\n",
+                       ntmp_table_name(NTMP_FDBT_ID), ERR_PTR(err));
+
+       ntmp_unlock_cbdr(cbdr);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(ntmp_fdbt_update_activity_element);
+
+/**
+ * ntmp_fdbt_delete_ageing_entries - delete all the ageing dynamic entries
+ * in the FDB table
+ * @user: target ntmp_user struct
+ * @act_cnt: the target value of the activity counter
+ *
+ * The matching rule is that the activity flag is not set and the activity
+ * counter is greater than or equal to act_cnt
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+int ntmp_fdbt_delete_ageing_entries(struct ntmp_user *user, u8 act_cnt)
+{
+       struct fdbt_req_qd *req;
+       struct netc_swcbd swcbd;
+       struct netc_cbdr *cbdr;
+       union netc_cbd cbd;
+       u32 len;
+       int err;
+
+       if (act_cnt > FDBT_ACT_CNT)
+               return -EINVAL;
+
+       swcbd.size = sizeof(*req);
+       err = ntmp_alloc_data_mem(user->dev, &swcbd, (void **)&req);
+       if (err)
+               return err;
+
+       /* Request data */
+       ntmp_fill_crd(&req->crd, user->tbl.fdbt_ver, 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;
+       /* Exact match with ACTE_DATA[ACT_FLAG] AND
+        * match >= ACTE_DATA[ACT_CNT]
+        */
+       req->ak.search.acte_mc = FDBT_ACTE_MC;
+       req->ak.search.cfge_mc = FDBT_CFGE_MC_DYNAMIC;
+
+       /* Request header */
+       len = NTMP_LEN(swcbd.size, NTMP_STATUS_RESP_LEN);
+       ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
+                             NTMP_CMD_DELETE, NTMP_AM_SEARCH);
+
+       ntmp_select_and_lock_cbdr(user, &cbdr);
+       err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
+       if (err)
+               dev_err(user->dev,
+                       "Failed to delete ageing entries of %s, err: %pe\n",
+                       ntmp_table_name(NTMP_FDBT_ID), ERR_PTR(err));
+
+       ntmp_unlock_cbdr(cbdr);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_ageing_entries);
+
+/**
+ * ntmp_fdbt_delete_port_dynamic_entries - delete all dynamic FDB entries
+ * associated with the specified switch port
+ * @user: target ntmp_user struct
+ * @port: the specified switch port ID
+ *
+ * Return: 0 on success, otherwise a negative error code
+ */
+int ntmp_fdbt_delete_port_dynamic_entries(struct ntmp_user *user, int port)
+{
+       struct fdbt_req_qd *req;
+       struct netc_swcbd swcbd;
+       struct netc_cbdr *cbdr;
+       union netc_cbd cbd;
+       u32 len;
+       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(&req->crd, user->tbl.fdbt_ver, 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);
+       /* Match CFGE_DATA[DYNAMIC & PORT_BITMAP] field */
+       req->ak.search.cfge_mc = FDBT_CFGE_MC_DYNAMIC_AND_PORT_BITMAP;
+
+       /* Request header */
+       len = NTMP_LEN(swcbd.size, NTMP_STATUS_RESP_LEN);
+       ntmp_fill_request_hdr(&cbd, swcbd.dma, len, NTMP_FDBT_ID,
+                             NTMP_CMD_DELETE, NTMP_AM_SEARCH);
+
+       ntmp_select_and_lock_cbdr(user, &cbdr);
+       err = netc_xmit_ntmp_cmd(cbdr, &cbd, &swcbd);
+       if (err)
+               dev_err(user->dev,
+                       "Failed to delete dynamic %s entries on port %d, err: %pe\n",
+                       ntmp_table_name(NTMP_FDBT_ID), port, ERR_PTR(err));
+
+       ntmp_unlock_cbdr(cbdr);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(ntmp_fdbt_delete_port_dynamic_entries);
+
 /**
  * ntmp_vft_add_entry - add an entry into the VLAN filter table
  * @user: target ntmp_user struct
index 0a9b8728610521f70e007f351c37ea016b8e6350..ad532b059ba8055d514e45cb83dee2d0b37cf503 100644 (file)
@@ -155,8 +155,8 @@ struct fdbt_ak_search {
 #define FDBT_KEYE_MAC          GENMASK(1, 0)
        u8 cfge_mc;
 #define FDBT_CFGE_MC           GENMASK(2, 0)
-#define FDBT_CFGE_MC_ANY               0
-#define FDBT_CFGE_MC_DYNAMIC           1
+#define FDBT_CFGE_MC_ANY       0
+#define FDBT_CFGE_MC_DYNAMIC   1
 #define FDBT_CFGE_MC_PORT_BITMAP       2
 #define FDBT_CFGE_MC_DYNAMIC_AND_PORT_BITMAP   3
        u8 acte_mc;
index 88166f9ad3a2ecdb847f59af59165a8af8906db2..5db078e1caa0c063f47458ba203f0c398cc3c8c3 100644 (file)
@@ -263,6 +263,9 @@ 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);
+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_bpt_update_entry(struct ntmp_user *user, u32 entry_id,