Octeontx2-pf: Add support for DMAC_FILTER trap
Subsystems (4)
v3 cover Octeontx2-pf: Add support for DMAC_FILTER trap
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
----
V3 * Address review comments suggested by Claude Code
V2 * fix warnings reported by kernel test robot
.../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 | 23 +++ .../marvell/octeontx2/nic/otx2_devlink.c | 167 ++++++++++++++++++ .../marvell/octeontx2/nic/otx2_devlink.h | 23 ++- .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 + 10 files changed, 257 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/2 octeontx2-af: Mailbox handlers to fetch DMAC filter drop counter
Both CGX/RPM mac blocks support DMAC filters. This patch adds mbox support to read the counter.
---
V3 * Return early on non CGX mapped interfaces by adding
"is_pf_cgxmapped" check
V2 * no changes
.../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 | 23 +++++++++++++++++++ 7 files changed, 63 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +11 -0
@@ -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,
drivers/net/ethernet/marvell/octeontx2/af/cgx.h +2 -0
@@ -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 */
drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +1 -0
@@ -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 {
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +7 -0
@@ -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 */
drivers/net/ethernet/marvell/octeontx2/af/rpm.c +17 -1
@@ -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;
drivers/net/ethernet/marvell/octeontx2/af/rpm.h +2 -0
@@ -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);
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +23 -0
@@ -1352,3 +1352,26 @@ 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; + +if (!is_pf_cgxmapped (rvu, pf)) +return 0 ; + +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 ; +}
Signature · 1 line
2.34.1
PATCH v3 2/2 Octeontx2-pf: Add support for DMAC_FILTER trap
In reply to Hariprasad KelamThis 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
---
V3 * Address issues on otx2_devlink_traps_register error path,
suggested by Claude Code
V2 * fix warnings reported by kernel test robot
.../marvell/octeontx2/nic/otx2_devlink.c | 167 ++++++++++++++++++ .../marvell/octeontx2/nic/otx2_devlink.h | 23 ++- .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 5 + 3 files changed, 194 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c +167 -0
@@ -6,6 +6,17 @@#include "otx2_common.h" +static struct devlink_trap_group otx2_trap_groups_arr[] = { +/* No policer is associated with following groups (policerid == 0)*/ +DEVLINK_TRAP_GROUP_GENERIC (L2_DROPS ,0 ), +}; + +static 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 +200,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 +335,77 @@ 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: + pf->dl->trap_data =NULL ; +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); + pf->dl->trap_data =NULL ; +}
drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.h +22 -1
@@ -8,13 +8,34 @@#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; +}; +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 */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +5 -0
@@ -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_mcam_flow_del; +/* Initialize SR-IOV resources */ err =otx2_sriov_vfcfg_init (pf);if (err)
@@ -3514,6 +3518,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);
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
Octeontx2-pf: Add support for DMAC_FILTER trap
This patch adds devlink trap support for DMAC_FILTER, allowing users to monitor packets dropped by the DMAC filter via the devlink interface.
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0
-0
[ ... ]
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3287
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3
-0@@ -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_mcam_flow_del;
If otx2_devlink_traps_register() fails here, the error path jumps to err_mcam_flow_del. However, otx2_register_dl() was called earlier in otx2_probe() and succeeded. Should there be a call to otx2_unregister_dl() on this error path to avoid leaking the devlink structure?
Looking at otx2_remove(), the cleanup order is:
otx2_devlink_traps_unregister(pf);
otx2_unregister_dl(pf);But the err_mcam_flow_del path does not call either of these functions.
Signature · 1 line
pw-bot: cr