public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [net-next 0/2] Octeontx2-pf: Add support for DMAC_FILTER trap
@ 2026-01-14  6:57 Hariprasad Kelam
  2026-01-14  6:57 ` [net-next 1/2] octeontx2-af: Mailbox handlers to fetch DMAC filter drop counter Hariprasad Kelam
  2026-01-14  6:57 ` [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
  0 siblings, 2 replies; 6+ messages in thread
From: Hariprasad Kelam @ 2026-01-14  6:57 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: kuba, davem, sgoutham, gakula, jerinj, lcherian, sbhatta, hkelam,
	naveenm, edumazet, pabeni, andrew+netdev, bbhushan2

Octeontx2/CN10K silicon MAC blocks CGX/RPM supports DMAC filters.
These patches add devlink trap support for this functionality.

Patch 1: Introduces mailbox handlers to retrieve the DMAC filter 
         drop counter.

Patch 2: Adds driver callbacks to support devlink traps.

Hariprasad Kelam (2):
  octeontx2-af:  Mailbox handlers to fetch DMAC filter drop counter
  Octeontx2-pf: Add support for DMAC_FILTER trap

 .../net/ethernet/marvell/octeontx2/af/cgx.c   |  11 ++
 .../net/ethernet/marvell/octeontx2/af/cgx.h   |   2 +
 .../marvell/octeontx2/af/lmac_common.h        |   1 +
 .../net/ethernet/marvell/octeontx2/af/mbox.h  |   7 +
 .../net/ethernet/marvell/octeontx2/af/rpm.c   |  18 +-
 .../net/ethernet/marvell/octeontx2/af/rpm.h   |   2 +
 .../ethernet/marvell/octeontx2/af/rvu_cgx.c   |  20 +++
 .../marvell/octeontx2/nic/otx2_devlink.c      | 160 ++++++++++++++++++
 .../marvell/octeontx2/nic/otx2_devlink.h      |  28 ++-
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |   7 +
 10 files changed, 254 insertions(+), 2 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [net-next 1/2] octeontx2-af:  Mailbox handlers to fetch DMAC filter drop counter
  2026-01-14  6:57 [net-next 0/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
@ 2026-01-14  6:57 ` Hariprasad Kelam
  2026-01-19 14:53   ` Simon Horman
  2026-01-14  6:57 ` [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
  1 sibling, 1 reply; 6+ messages in thread
From: Hariprasad Kelam @ 2026-01-14  6:57 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: kuba, davem, sgoutham, gakula, jerinj, lcherian, sbhatta, hkelam,
	naveenm, edumazet, pabeni, andrew+netdev, bbhushan2

Both CGX/RPM mac blocks support DMAC filters. This patch
adds mbox support to read the counter.

Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>
---
 .../net/ethernet/marvell/octeontx2/af/cgx.c   | 11 ++++++++++
 .../net/ethernet/marvell/octeontx2/af/cgx.h   |  2 ++
 .../marvell/octeontx2/af/lmac_common.h        |  1 +
 .../net/ethernet/marvell/octeontx2/af/mbox.h  |  7 +++++++
 .../net/ethernet/marvell/octeontx2/af/rpm.c   | 18 ++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/af/rpm.h   |  2 ++
 .../ethernet/marvell/octeontx2/af/rvu_cgx.c   | 20 +++++++++++++++++++
 7 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
index 42044cd810b1..f29e6069acc1 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
@@ -740,6 +740,16 @@ u64 cgx_features_get(void *cgxd)
 	return ((struct cgx *)cgxd)->hw_features;
 }
 
+u64 cgx_get_dmacflt_dropped_pktcnt(void *cgxd, int lmac_id)
+{
+	struct cgx *cgx = cgxd;
+
+	if (!is_lmac_valid(cgx, lmac_id))
+		return 0;
+
+	return cgx_read(cgx, lmac_id, CGXX_CMRX_RX_STAT4);
+}
+
 int cgx_stats_reset(void *cgxd, int lmac_id)
 {
 	struct cgx *cgx = cgxd;
@@ -1924,6 +1934,7 @@ static struct mac_ops	cgx_mac_ops    = {
 	.pfc_config =                   cgx_lmac_pfc_config,
 	.mac_get_pfc_frm_cfg   =        cgx_lmac_get_pfc_frm_cfg,
 	.mac_reset   =			cgx_lmac_reset,
+	.get_dmacflt_dropped_pktcnt      =      cgx_get_dmacflt_dropped_pktcnt,
 	.mac_stats_reset       =	cgx_stats_reset,
 	.mac_x2p_reset                   =      cgx_x2p_reset,
 	.mac_enadis_rx			 =      cgx_enadis_rx,
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h
index 92ccf343dfe0..4c5ffd0aebdc 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.h
@@ -39,6 +39,7 @@
 #define CGXX_CMRX_INT_ENA_W1S		0x058
 #define CGXX_CMRX_RX_ID_MAP		0x060
 #define CGXX_CMRX_RX_STAT0		0x070
+#define CGXX_CMRX_RX_STAT4		0x090
 #define CGXX_CMRX_RX_LOGL_XON		0x100
 #define CGXX_CMRX_RX_LMACS		0x128
 #define CGXX_CMRX_RX_DMAC_CTL0		(0x1F8 + mac_ops->csr_offset)
@@ -186,5 +187,6 @@ int cgx_lmac_get_pfc_frm_cfg(void *cgxd, int lmac_id, u8 *tx_pause,
 int verify_lmac_fc_cfg(void *cgxd, int lmac_id, u8 tx_pause, u8 rx_pause,
 		       int pfvf_idx);
 int cgx_lmac_reset(void *cgxd, int lmac_id, u8 pf_req_flr);
+u64 cgx_get_dmacflt_dropped_pktcnt(void *cgx, int lmac_id);
 u32 cgx_get_fifo_len(void *cgxd);
 #endif /* CGX_H */
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
index 6180e68e1765..82446f6c27a3 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h
@@ -134,6 +134,7 @@ struct mac_ops {
 	int			(*mac_stats_reset)(void *cgxd, int lmac_id);
 	void                    (*mac_x2p_reset)(void *cgxd, bool enable);
 	int			(*mac_enadis_rx)(void *cgxd, int lmac_id, bool enable);
+	u64			(*get_dmacflt_dropped_pktcnt)(void *cgxd, int lmac_id);
 };
 
 struct cgx {
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
index a3e273126e4e..2b653a572eba 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
@@ -197,6 +197,8 @@ M(CGX_MAC_ADDR_UPDATE,	0x21E, cgx_mac_addr_update, cgx_mac_addr_update_req, \
 						    cgx_mac_addr_update_rsp) \
 M(CGX_PRIO_FLOW_CTRL_CFG, 0x21F, cgx_prio_flow_ctrl_cfg, cgx_pfc_cfg,  \
 				 cgx_pfc_rsp)                               \
+M(CGX_DMAC_FILTER_DROP_CNT, 0x220, cgx_get_dmacflt_dropped_pktcnt, msg_req,  \
+				 cgx_dmac_filter_drop_cnt)                      \
 /* NPA mbox IDs (range 0x400 - 0x5FF) */				\
 M(NPA_LF_ALLOC,		0x400, npa_lf_alloc,				\
 				npa_lf_alloc_req, npa_lf_alloc_rsp)	\
@@ -718,6 +720,11 @@ struct cgx_mac_addr_update_rsp {
 	u32 index;
 };
 
+struct cgx_dmac_filter_drop_cnt {
+	struct mbox_msghdr hdr;
+	u64 count;
+};
+
 #define RVU_LMAC_FEAT_FC		BIT_ULL(0) /* pause frames */
 #define	RVU_LMAC_FEAT_HIGIG2		BIT_ULL(1)
 			/* flow control from physical link higig2 messages */
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c
index 2e9945446199..7e0e0c5c11a3 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.c
@@ -37,7 +37,8 @@ static struct mac_ops		rpm_mac_ops   = {
 	.mac_tx_enable =		rpm_lmac_tx_enable,
 	.pfc_config =                   rpm_lmac_pfc_config,
 	.mac_get_pfc_frm_cfg   =        rpm_lmac_get_pfc_frm_cfg,
-	.mac_reset   =			rpm_lmac_reset,
+	.mac_reset			 =	  rpm_lmac_reset,
+	.get_dmacflt_dropped_pktcnt      =        rpm_get_dmacflt_dropped_pktcnt,
 	.mac_stats_reset		 =	  rpm_stats_reset,
 	.mac_x2p_reset                   =        rpm_x2p_reset,
 	.mac_enadis_rx			 =        rpm_enadis_rx,
@@ -73,6 +74,7 @@ static struct mac_ops		rpm2_mac_ops   = {
 	.pfc_config =                   rpm_lmac_pfc_config,
 	.mac_get_pfc_frm_cfg   =        rpm_lmac_get_pfc_frm_cfg,
 	.mac_reset   =			rpm_lmac_reset,
+	.get_dmacflt_dropped_pktcnt =   rpm_get_dmacflt_dropped_pktcnt,
 	.mac_stats_reset	    =	rpm_stats_reset,
 	.mac_x2p_reset              =   rpm_x2p_reset,
 	.mac_enadis_rx		    =   rpm_enadis_rx,
@@ -449,6 +451,20 @@ int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat)
 	return 0;
 }
 
+u64 rpm_get_dmacflt_dropped_pktcnt(void *rpmd, int lmac_id)
+{
+	rpm_t *rpm = rpmd;
+	u64 dmac_flt_stat;
+
+	if (!is_lmac_valid(rpm, lmac_id))
+		return 0;
+
+	dmac_flt_stat = is_dev_rpm2(rpm) ? RPM2_CMRX_RX_STAT2 :
+			RPMX_CMRX_RX_STAT2;
+
+	return rpm_read(rpm, lmac_id, dmac_flt_stat);
+}
+
 int rpm_stats_reset(void *rpmd, int lmac_id)
 {
 	rpm_t *rpm = rpmd;
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h
index b8d3972e096a..443481010aba 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rpm.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rpm.h
@@ -60,6 +60,7 @@
 #define RPMX_MTI_STAT_RX_STAT_PAGES_COUNTERX 0x12000
 #define RPMX_MTI_STAT_TX_STAT_PAGES_COUNTERX 0x13000
 #define RPMX_MTI_STAT_DATA_HI_CDC            0x10038
+#define RPMX_CMRX_RX_STAT2		     0x4010
 
 #define RPM_LMAC_FWI			0xa
 #define RPM_TX_EN			BIT_ULL(0)
@@ -129,6 +130,7 @@ int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id, u8 tx_pause,
 			      u8 rx_pause);
 int rpm_get_tx_stats(void *rpmd, int lmac_id, int idx, u64 *tx_stat);
 int rpm_get_rx_stats(void *rpmd, int lmac_id, int idx, u64 *rx_stat);
+u64 rpm_get_dmacflt_dropped_pktcnt(void *rpmd, int lmac_id);
 void rpm_lmac_ptp_config(void *rpmd, int lmac_id, bool enable);
 int rpm_lmac_rx_tx_enable(void *rpmd, int lmac_id, bool enable);
 int rpm_lmac_tx_enable(void *rpmd, int lmac_id, bool enable);
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
index 3abd750a4bd7..aef0087174b7 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
@@ -1352,3 +1352,23 @@ void rvu_mac_reset(struct rvu *rvu, u16 pcifunc)
 	if (mac_ops->mac_reset(cgxd, lmac, !is_vf(pcifunc)))
 		dev_err(rvu->dev, "Failed to reset MAC\n");
 }
+
+int rvu_mbox_handler_cgx_get_dmacflt_dropped_pktcnt(struct rvu *rvu,
+						    struct msg_req *req,
+						    struct cgx_dmac_filter_drop_cnt *rsp)
+{
+	int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc);
+	struct mac_ops *mac_ops;
+	u8 cgx_id, lmac_id;
+	void *cgxd;
+
+	rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
+	cgxd = rvu_cgx_pdata(cgx_id, rvu);
+	mac_ops = get_mac_ops(cgxd);
+
+	if (!mac_ops->get_dmacflt_dropped_pktcnt)
+		return 0;
+
+	rsp->count =  mac_ops->get_dmacflt_dropped_pktcnt(cgxd, lmac_id);
+	return 0;
+}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap
  2026-01-14  6:57 [net-next 0/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
  2026-01-14  6:57 ` [net-next 1/2] octeontx2-af: Mailbox handlers to fetch DMAC filter drop counter Hariprasad Kelam
@ 2026-01-14  6:57 ` Hariprasad Kelam
  2026-01-14 15:39   ` kernel test robot
  2026-01-19 15:01   ` Simon Horman
  1 sibling, 2 replies; 6+ messages in thread
From: Hariprasad Kelam @ 2026-01-14  6:57 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: kuba, davem, sgoutham, gakula, jerinj, lcherian, sbhatta, hkelam,
	naveenm, edumazet, pabeni, andrew+netdev, bbhushan2

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap
  2026-01-14  6:57 ` [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
@ 2026-01-14 15:39   ` kernel test robot
  2026-01-19 15:01   ` Simon Horman
  1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-01-14 15:39 UTC (permalink / raw)
  To: Hariprasad Kelam, netdev, linux-kernel
  Cc: oe-kbuild-all, kuba, davem, sgoutham, gakula, jerinj, lcherian,
	sbhatta, hkelam, naveenm, edumazet, pabeni, andrew+netdev,
	bbhushan2

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [net-next 1/2] octeontx2-af:  Mailbox handlers to fetch DMAC filter drop counter
  2026-01-14  6:57 ` [net-next 1/2] octeontx2-af: Mailbox handlers to fetch DMAC filter drop counter Hariprasad Kelam
@ 2026-01-19 14:53   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2026-01-19 14:53 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: netdev, linux-kernel, kuba, davem, sgoutham, gakula, jerinj,
	lcherian, sbhatta, naveenm, edumazet, pabeni, andrew+netdev,
	bbhushan2

On Wed, Jan 14, 2026 at 12:27:42PM +0530, Hariprasad Kelam wrote:
> Both CGX/RPM mac blocks support DMAC filters. This patch
> adds mbox support to read the counter.
> 
> Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>

...

> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
> index 3abd750a4bd7..aef0087174b7 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c
> @@ -1352,3 +1352,23 @@ void rvu_mac_reset(struct rvu *rvu, u16 pcifunc)
>  	if (mac_ops->mac_reset(cgxd, lmac, !is_vf(pcifunc)))
>  		dev_err(rvu->dev, "Failed to reset MAC\n");
>  }
> +
> +int rvu_mbox_handler_cgx_get_dmacflt_dropped_pktcnt(struct rvu *rvu,
> +						    struct msg_req *req,
> +						    struct cgx_dmac_filter_drop_cnt *rsp)
> +{
> +	int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc);
> +	struct mac_ops *mac_ops;
> +	u8 cgx_id, lmac_id;
> +	void *cgxd;
> +
> +	rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
> +	cgxd = rvu_cgx_pdata(cgx_id, rvu);
> +	mac_ops = get_mac_ops(cgxd);

Hi Hariprasad,

Claude Code with Review Prompts [1] flags that get_mac_ops may not
always return a valid ops structure. And that other handlers that
mac_ops guard against this using is_cgx_config_permitted().

I am wondering if that is appropriate here too.

[1] https://github.com/masoncl/review-prompts/

> +
> +	if (!mac_ops->get_dmacflt_dropped_pktcnt)
> +		return 0;
> +
> +	rsp->count =  mac_ops->get_dmacflt_dropped_pktcnt(cgxd, lmac_id);
> +	return 0;
> +}
> -- 
> 2.34.1
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap
  2026-01-14  6:57 ` [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
  2026-01-14 15:39   ` kernel test robot
@ 2026-01-19 15:01   ` Simon Horman
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Horman @ 2026-01-19 15:01 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: netdev, linux-kernel, kuba, davem, sgoutham, gakula, jerinj,
	lcherian, sbhatta, naveenm, edumazet, pabeni, andrew+netdev,
	bbhushan2

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
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-01-19 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14  6:57 [net-next 0/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
2026-01-14  6:57 ` [net-next 1/2] octeontx2-af: Mailbox handlers to fetch DMAC filter drop counter Hariprasad Kelam
2026-01-19 14:53   ` Simon Horman
2026-01-14  6:57 ` [net-next 2/2] Octeontx2-pf: Add support for DMAC_FILTER trap Hariprasad Kelam
2026-01-14 15:39   ` kernel test robot
2026-01-19 15:01   ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox