This patch adds support for DMAC_FILTER trap.
devlink trap show
pci/0002:02:00.0:
name otx2_dmac_filter type drop generic false action trap group l2_drops
to get counter
devlink -s trap show
pci/0002:02:00.0:
name otx2_dmac_filter type drop generic false action trap group l2_drops
stats:
rx:
bytes 0 packets 0 dropped 0
Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>
---
.../marvell/octeontx2/nic/otx2_devlink.c | 160 ++++++++++++++++++
.../marvell/octeontx2/nic/otx2_devlink.h | 28 ++-
.../ethernet/marvell/octeontx2/nic/otx2_pf.c | 7 +
3 files changed, 194 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
index a72694219df4..98b835e66479 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
@@ -6,6 +6,12 @@
#include "otx2_common.h"
+struct otx2_trap otx2_trap_items_arr[] = {
+ {
+ .trap = OTX2_TRAP_DROP(DMAC_FILTER, L2_DROPS),
+ },
+};
+
/* Devlink Params APIs */
static int otx2_dl_mcam_count_validate(struct devlink *devlink, u32 id,
union devlink_param_value val,
@@ -189,11 +195,93 @@ static int otx2_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
}
#endif
+static struct otx2_trap_item *
+otx2_devlink_trap_item_lookup(struct otx2_devlink *dl, u16 trap_id)
+{
+ struct otx2_trap_data *trap_data = dl->trap_data;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(otx2_trap_items_arr); i++) {
+ if (otx2_trap_items_arr[i].trap.id == trap_id)
+ return &trap_data->trap_items_arr[i];
+ }
+
+ return NULL;
+}
+
+static int otx2_trap_init(struct devlink *devlink,
+ const struct devlink_trap *trap, void *trap_ctx)
+{
+ struct otx2_devlink *otx2_dl = devlink_priv(devlink);
+ struct otx2_trap_item *trap_item;
+
+ trap_item = otx2_devlink_trap_item_lookup(otx2_dl, trap->id);
+ if (WARN_ON(!trap_item))
+ return -EINVAL;
+
+ trap_item->trap_ctx = trap_ctx;
+ trap_item->action = trap->init_action;
+
+ return 0;
+}
+
+static int otx2_trap_action_set(struct devlink *devlink,
+ const struct devlink_trap *trap,
+ enum devlink_trap_action action,
+ struct netlink_ext_ack *extack)
+{
+ /* Currently, driver does not support trap action altering */
+ return -EOPNOTSUPP;
+}
+
+static int
+otx2_trap_drop_counter_get(struct devlink *devlink,
+ const struct devlink_trap *trap,
+ u64 *p_drops)
+{
+ struct otx2_devlink *otx2_dl = devlink_priv(devlink);
+ struct otx2_nic *pfvf = otx2_dl->pfvf;
+ struct cgx_dmac_filter_drop_cnt *rsp;
+ struct msg_req *req;
+ int err;
+
+ if (trap->id != DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER)
+ return -EINVAL;
+
+ /* send mailbox to AF */
+ mutex_lock(&pfvf->mbox.lock);
+
+ req = otx2_mbox_alloc_msg_cgx_get_dmacflt_dropped_pktcnt(&pfvf->mbox);
+ if (!req) {
+ mutex_unlock(&pfvf->mbox.lock);
+ return -ENOMEM;
+ }
+
+ err = otx2_sync_mbox_msg(&pfvf->mbox);
+ if (err)
+ goto fail;
+
+ rsp = (struct cgx_dmac_filter_drop_cnt *)
+ otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr);
+ if (IS_ERR(rsp)) {
+ err = PTR_ERR(rsp);
+ goto fail;
+ }
+ *p_drops = rsp->count;
+
+fail:
+ mutex_unlock(&pfvf->mbox.lock);
+ return err;
+}
+
static const struct devlink_ops otx2_devlink_ops = {
#ifdef CONFIG_RVU_ESWITCH
.eswitch_mode_get = otx2_devlink_eswitch_mode_get,
.eswitch_mode_set = otx2_devlink_eswitch_mode_set,
#endif
+ .trap_init = otx2_trap_init,
+ .trap_action_set = otx2_trap_action_set,
+ .trap_drop_counter_get = otx2_trap_drop_counter_get,
};
int otx2_register_dl(struct otx2_nic *pfvf)
@@ -242,3 +330,75 @@ void otx2_unregister_dl(struct otx2_nic *pfvf)
devlink_free(dl);
}
EXPORT_SYMBOL(otx2_unregister_dl);
+
+int otx2_devlink_traps_register(struct otx2_nic *pf)
+{
+ const u32 groups_count = ARRAY_SIZE(otx2_trap_groups_arr);
+ const u32 traps_count = ARRAY_SIZE(otx2_trap_items_arr);
+ struct devlink *devlink = priv_to_devlink(pf->dl);
+ struct otx2_trap_data *trap_data;
+ struct otx2_trap *otx2_trap;
+ int err, i;
+
+ trap_data = kzalloc(sizeof(*trap_data), GFP_KERNEL);
+ if (!trap_data)
+ return -ENOMEM;
+
+ trap_data->trap_items_arr = kcalloc(traps_count,
+ sizeof(struct otx2_trap_item),
+ GFP_KERNEL);
+ if (!trap_data->trap_items_arr) {
+ err = -ENOMEM;
+ goto err_trap_items_alloc;
+ }
+
+ trap_data->dl = pf->dl;
+ trap_data->traps_count = traps_count;
+ pf->dl->trap_data = trap_data;
+
+ err = devlink_trap_groups_register(devlink, otx2_trap_groups_arr,
+ groups_count);
+ if (err)
+ goto err_groups_register;
+
+ for (i = 0; i < traps_count; i++) {
+ otx2_trap = &otx2_trap_items_arr[i];
+ err = devlink_traps_register(devlink, &otx2_trap->trap, 1,
+ pf);
+ if (err)
+ goto err_trap_register;
+ }
+
+ return 0;
+
+err_trap_register:
+ for (i--; i >= 0; i--) {
+ otx2_trap = &otx2_trap_items_arr[i];
+ devlink_traps_unregister(devlink, &otx2_trap->trap, 1);
+ }
+ devlink_trap_groups_unregister(devlink, otx2_trap_groups_arr,
+ groups_count);
+err_groups_register:
+ kfree(trap_data->trap_items_arr);
+err_trap_items_alloc:
+ kfree(trap_data);
+ return err;
+}
+
+void otx2_devlink_traps_unregister(struct otx2_nic *pf)
+{
+ struct otx2_trap_data *trap_data = pf->dl->trap_data;
+ struct devlink *devlink = priv_to_devlink(pf->dl);
+ const struct devlink_trap *trap;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(otx2_trap_items_arr); ++i) {
+ trap = &otx2_trap_items_arr[i].trap;
+ devlink_traps_unregister(devlink, trap, 1);
+ }
+
+ devlink_trap_groups_unregister(devlink, otx2_trap_groups_arr,
+ ARRAY_SIZE(otx2_trap_groups_arr));
+ kfree(trap_data->trap_items_arr);
+ kfree(trap_data);
+}
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h
index c7bd4f3c6c6b..70608e8937b8 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h
@@ -8,13 +8,39 @@
#ifndef OTX2_DEVLINK_H
#define OTX2_DEVLINK_H
+#define OTX2_TRAP_DROP(_id, _group_id) \
+ DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \
+ DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id, \
+ DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT)
+struct otx2_trap {
+ struct devlink_trap trap;
+};
+
+struct otx2_trap_item {
+ enum devlink_trap_action action;
+ void *trap_ctx;
+};
+
+struct otx2_trap_data {
+ struct otx2_devlink *dl;
+ struct otx2_trap_item *trap_items_arr;
+ u32 traps_count;
+};
+
+static const struct devlink_trap_group otx2_trap_groups_arr[] = {
+ /* No policer is associated with following groups (policerid == 0)*/
+ DEVLINK_TRAP_GROUP_GENERIC(L2_DROPS, 0),
+};
+
struct otx2_devlink {
struct devlink *dl;
struct otx2_nic *pfvf;
+ struct otx2_trap_data *trap_data;
};
/* Devlink APIs */
int otx2_register_dl(struct otx2_nic *pfvf);
void otx2_unregister_dl(struct otx2_nic *pfvf);
-
+void otx2_devlink_traps_unregister(struct otx2_nic *pfvf);
+int otx2_devlink_traps_register(struct otx2_nic *pfvf);
#endif /* RVU_DEVLINK_H */
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index a7feb4c392b3..5da1605a1a90 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -3282,6 +3282,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (err)
goto err_mcam_flow_del;
+ err = otx2_devlink_traps_register(pf);
+ if (err)
+ goto err_traps_unregister;
+
/* Initialize SR-IOV resources */
err = otx2_sriov_vfcfg_init(pf);
if (err)
@@ -3314,6 +3318,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
otx2_sriov_vfcfg_cleanup(pf);
err_pf_sriov_init:
otx2_shutdown_tc(pf);
+err_traps_unregister:
+ otx2_devlink_traps_unregister(pf);
err_mcam_flow_del:
otx2_mcam_flow_del(pf);
err_unreg_netdev:
@@ -3514,6 +3520,7 @@ static void otx2_remove(struct pci_dev *pdev)
/* Disable link notifications */
otx2_cgx_config_linkevents(pf, false);
+ otx2_devlink_traps_unregister(pf);
otx2_unregister_dl(pf);
unregister_netdev(netdev);
cn10k_ipsec_clean(pf);
--
2.34.1
On Wed, Jan 14, 2026 at 12:27:43PM +0530, Hariprasad Kelam wrote:
...
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c
...
> +
> +int otx2_devlink_traps_register(struct otx2_nic *pf)
> +{
> + const u32 groups_count = ARRAY_SIZE(otx2_trap_groups_arr);
> + const u32 traps_count = ARRAY_SIZE(otx2_trap_items_arr);
> + struct devlink *devlink = priv_to_devlink(pf->dl);
> + struct otx2_trap_data *trap_data;
> + struct otx2_trap *otx2_trap;
> + int err, i;
> +
> + trap_data = kzalloc(sizeof(*trap_data), GFP_KERNEL);
> + if (!trap_data)
Hi Hariprasad,
If the code reaches this line then the function will return an
error value, and pf->dl->trap_data will be NULL.
> + return -ENOMEM;
> +
> + trap_data->trap_items_arr = kcalloc(traps_count,
> + sizeof(struct otx2_trap_item),
> + GFP_KERNEL);
> + if (!trap_data->trap_items_arr) {
> + err = -ENOMEM;
> + goto err_trap_items_alloc;
> + }
> +
> + trap_data->dl = pf->dl;
> + trap_data->traps_count = traps_count;
> + pf->dl->trap_data = trap_data;
> +
> + err = devlink_trap_groups_register(devlink, otx2_trap_groups_arr,
> + groups_count);
> + if (err)
> + goto err_groups_register;
> +
> + for (i = 0; i < traps_count; i++) {
> + otx2_trap = &otx2_trap_items_arr[i];
> + err = devlink_traps_register(devlink, &otx2_trap->trap, 1,
> + pf);
> + if (err)
> + goto err_trap_register;
> + }
> +
> + return 0;
> +
> +err_trap_register:
> + for (i--; i >= 0; i--) {
> + otx2_trap = &otx2_trap_items_arr[i];
> + devlink_traps_unregister(devlink, &otx2_trap->trap, 1);
> + }
> + devlink_trap_groups_unregister(devlink, otx2_trap_groups_arr,
> + groups_count);
> +err_groups_register:
> + kfree(trap_data->trap_items_arr);
> +err_trap_items_alloc:
> + kfree(trap_data);
And if the code reaches this line then the function will
return an error value, with pf->dl->trap_data set to a pointer
which has been freed.
> + return err;
> +}
> +
> +void otx2_devlink_traps_unregister(struct otx2_nic *pf)
> +{
> + struct otx2_trap_data *trap_data = pf->dl->trap_data;
> + struct devlink *devlink = priv_to_devlink(pf->dl);
> + const struct devlink_trap *trap;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(otx2_trap_items_arr); ++i) {
> + trap = &otx2_trap_items_arr[i].trap;
> + devlink_traps_unregister(devlink, trap, 1);
> + }
> +
> + devlink_trap_groups_unregister(devlink, otx2_trap_groups_arr,
> + ARRAY_SIZE(otx2_trap_groups_arr));
> + kfree(trap_data->trap_items_arr);
But, if otx2_devlink_traps_register returns an error value then
otx2_devlink_traps_unregister will be called. And the like above
will dereference pf->dl->trap_data.
> + kfree(trap_data);
> +}
Flagged by Claude Code with Review Prompts [1].
https://github.com/masoncl/review-prompts/
...
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> index a7feb4c392b3..5da1605a1a90 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> @@ -3282,6 +3282,10 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> if (err)
> goto err_mcam_flow_del;
>
> + err = otx2_devlink_traps_register(pf);
> + if (err)
> + goto err_traps_unregister;
> +
> /* Initialize SR-IOV resources */
> err = otx2_sriov_vfcfg_init(pf);
> if (err)
> @@ -3314,6 +3318,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> otx2_sriov_vfcfg_cleanup(pf);
> err_pf_sriov_init:
> otx2_shutdown_tc(pf);
> +err_traps_unregister:
> + otx2_devlink_traps_unregister(pf);
> err_mcam_flow_del:
> otx2_mcam_flow_del(pf);
> err_unreg_netdev:
> @@ -3514,6 +3520,7 @@ static void otx2_remove(struct pci_dev *pdev)
> /* Disable link notifications */
> otx2_cgx_config_linkevents(pf, false);
>
> + otx2_devlink_traps_unregister(pf);
> otx2_unregister_dl(pf);
> unregister_netdev(netdev);
> cn10k_ipsec_clean(pf);
> --
> 2.34.1
>
>
Hi Hariprasad,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Hariprasad-Kelam/octeontx2-af-Mailbox-handlers-to-fetch-DMAC-filter-drop-counter/20260114-150046
base: net-next/main
patch link: https://lore.kernel.org/r/20260114065743.2162706-3-hkelam%40marvell.com
patch subject: [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap
config: um-allyesconfig (https://download.01.org/0day-ci/archive/20260114/202601142356.TWrRByBh-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260114/202601142356.TWrRByBh-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601142356.TWrRByBh-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h:31,
from drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c:22:
>> drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h:30:40: warning: 'otx2_trap_groups_arr' defined but not used [-Wunused-const-variable=]
30 | static const struct devlink_trap_group otx2_trap_groups_arr[] = {
| ^~~~~~~~~~~~~~~~~~~~
vim +/otx2_trap_groups_arr +30 drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h
29
> 30 static const struct devlink_trap_group otx2_trap_groups_arr[] = {
31 /* No policer is associated with following groups (policerid == 0)*/
32 DEVLINK_TRAP_GROUP_GENERIC(L2_DROPS, 0),
33 };
34
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.