octeontx2-af: npc: cn20k: MCAM fixes
Ratheesh Kannoth
maintainerv4 cover octeontx2-af: npc: cn20k: MCAM fixes
This series tightens Marvell OcteonTX2 AF NPC support for CN20K silicon around MCAM key typing, optional debugfs setup, defrag allocation rollback, defrag entry relocation bookkeeping, logical MCAM clear and configuration, default-rule index handling and explicit teardown, and NIXLF reserved-slot lookup when default rules are missing.
Patches 1 through 3 focus on AF error handling: propagate npc_mcam_idx_2_key_type() failures through cn20k MCAM enable, config, copy, and read paths; treat cn20k NPC debugfs files as optional so probe does not fail when debugfs is unavailable; and fix defrag MCAM allocation rollback so allocation errno is not overwritten by subbank index resolution.
Patch 4 fixes npc_defrag_move_vdx_to_free(): when an MCAM line is moved to a new physical index, copy entry2target_pffunc[] to the new slot, clear the old slot, and update the matching mcam_rules entry so software state matches hardware after defrag.
Patches 5 through 7 refine cn20k MCAM programming: clear entries by logical index and resolved key width, fix bank and CFG sequencing in npc_cn20k_config_mcam_entry(), and read action metadata from the correct bank in npc_cn20k_read_mcam_entry().
Patches 8 through 10 complete default-rule lifecycle handling:
initialize all default-rule index outputs up front, tear down default MCAM rules explicitly (coordinated with npc_mcam_free_all_entries()), and reject USHRT_MAX sentinel indices in npc_get_nixlf_mcam_index() for cn20k.
Ratheesh Kannoth (10):
octeontx2-af: npc: cn20k: Propagate MCAM key-type errors on cn20k
octeontx2-af: npc: cn20k: Drop debugfs_create_file() error checks in init
octeontx2-af: npc: cn20k: Propagate errors in defrag MCAM alloc rollback
octeontx2-af: npc: cn20k: Fix target map and rule index while defrag
octeontx2-af: npc: cn20k: Clear MCAM entries by index and key width
octeontx2-af: npc: cn20k: Fix bank value.
octeontx2-af: npc: cn20k: Fix MCAM actions read
octeontx2-af: npc: cn20k: Initialize default-rule index outputs up front
octeontx2-af: npc: cn20k: Tear down default MCAM rules explicitly on free
octeontx2-af: npc: cn20k: Reject missing default-rule MCAM indices
--
v3 -> v4:
- Add patch fixing entry2target_pffunc[] and mcam_rules when defrag relocates an MCAM entry (npc_defrag_move_vdx_to_free()).
- Drop the standalone default-entry x4 preference and x2-profile flow-install rejection patches from this series (10 patches total).
https://lore.kernel.org/netdev/[email protected]/
v2 -> v3: Addresses simon, paolo comments.
https://lore.kernel.org/netdev/[email protected]/
v1 -> v2: Addressed simon comments. Added more patch fixes to this series.
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 1/10 octeontx2-af: npc: cn20k: Propagate MCAM key-type errors on cn20k
npc_mcam_idx_2_key_type() can fail; callers used to ignore it and still used kw_type when enabling, configuring, copying, and reading MCAM entries. That could program or decode hardware with an undefined key type.
Return -EINVAL when key-type lookup fails. Return -EINVAL from npc_cn20k_copy_mcam_entry() when src and dest key types differ instead of failing silently.
Change npc_cn20k_{enable,config,copy,read}_mcam_entry() to return int on success or error. Thread those errors through the cn20k MCAM write and read mbox handlers, the cn20k baseline steer read path, NPC defrag move (disable/copy/enable with dev_err and -EFAULT), and the DMAC update path in rvu_npc_fs.c.
Make npc_copy_mcam_entry() return int so the cn20k branch can return npc_cn20k_copy_mcam_entry() without a void/int mismatch, and fail NPC_MCAM_SHIFT_ENTRY when copy fails.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 109 ++++++++++++------ .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 20 ++-- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 18 ++- .../marvell/octeontx2/af/rvu_npc_fs.c | 20 ++-- 4 files changed, 111 insertions(+), 56 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +75 -34
@@ -798,7 +798,7 @@ void npc_cn20k_load_mkex_profile(struct rvu *rvu, int blkaddr,iounmap (mkex_prfl_addr); } -void +int npc_cn20k_enable_mcam_entry (struct rvu *rvu,int blkaddr,int index,bool enable) {
@@ -808,7 +808,9 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,u64 cfg, hw_prio;u8 kw_type; -npc_mcam_idx_2_key_type (rvu, index, &kw_type); +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type)) +return -EINVAL ; +if (kw_type ==NPC_MCAM_KEY_X2 ) { cfg = rvu_read64(rvu, blkaddr, NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT(mcam_idx,
@@ -819,7 +821,7 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,rvu_write64 (rvu, blkaddr,NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), cfg); -return ; +return 0 ; }/* For NPC_CN20K_MCAM_KEY_X4 keys, both the banks
@@ -836,6 +838,8 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), cfg); } + +return 0 ; }void
@@ -1042,9 +1046,9 @@ npc_cn20k_set_mcam_bank_cfg(struct rvu *rvu, int blkaddr, int mcam_idx, } } -void npc_cn20k_config_mcam_entry (struct rvu *rvu,int blkaddr,int index, -u8 intf,struct cn20k_mcam_entry *entry, -bool enable,u8 hw_prio,u8 req_kw_type) +int npc_cn20k_config_mcam_entry (struct rvu *rvu,int blkaddr,int index, +u8 intf,struct cn20k_mcam_entry *entry, +bool enable,u8 hw_prio,u8 req_kw_type) {struct npc_mcam *mcam = &rvu->hw->mcam;int mcam_idx = index % mcam->banksize;
@@ -1052,10 +1056,13 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,int kw =0 ;u8 kw_type; +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type)) +return -EINVAL ; +/* Disable before mcam entry update */ -npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, false); +if (npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, false)) +return -EINVAL ; -npc_mcam_idx_2_key_type (rvu, index, &kw_type);/* CAM1 takes the comparison value and * CAM0 specifies match for a bit in key being '0' or '1' or 'dontcare'. * CAM1<n> = 0 & CAM0<n> = 1 => match if key<n> = 0
@@ -1120,9 +1127,11 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,/* PF installing VF rule */ npc_cn20k_set_mcam_bank_cfg (rvu, blkaddr, mcam_idx, bank, kw_type, enable, hw_prio); + +return 0 ; } -void npc_cn20k_copy_mcam_entry (struct rvu *rvu,int blkaddr,u16 src,u16 dest) +int npc_cn20k_copy_mcam_entry (struct rvu *rvu,int blkaddr,u16 src,u16 dest) {struct npc_mcam *mcam = &rvu->hw->mcam;u64 cfg, sreg, dreg, soff, doff;
@@ -1132,10 +1141,15 @@ void npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blkaddr, u16 src, u16 dest) dbank =npc_get_bank (mcam, dest); sbank =npc_get_bank (mcam, src); -npc_mcam_idx_2_key_type (rvu, src, &src_kwtype); -npc_mcam_idx_2_key_type (rvu, dest, &dest_kwtype); + +if (npc_mcam_idx_2_key_type (rvu, src, &src_kwtype)) +return -EINVAL ; + +if (npc_mcam_idx_2_key_type (rvu, dest, &dest_kwtype)) +return -EINVAL ; +if (src_kwtype != dest_kwtype) -return ; +return -EINVAL ; src &= (mcam->banksize -1 ); dest &= (mcam->banksize -1 );
@@ -1170,6 +1184,8 @@ void npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blkaddr, u16 src, u16 dest)if (src_kwtype ==NPC_MCAM_KEY_X2 )break ; } + +return 0 ; } static void npc_cn20k_fill_entryword(struct cn20k_mcam_entry *entry, int idx,
@@ -1179,16 +1195,17 @@ static void npc_cn20k_fill_entryword(struct cn20k_mcam_entry *entry, int idx, entry->kw_mask[idx] = cam1 ^ cam0; } -void npc_cn20k_read_mcam_entry (struct rvu *rvu,int blkaddr,u16 index, -struct cn20k_mcam_entry *entry, -u8 *intf,u8 *ena,u8 *hw_prio) +int npc_cn20k_read_mcam_entry (struct rvu *rvu,int blkaddr,u16 index, +struct cn20k_mcam_entry *entry, +u8 *intf,u8 *ena,u8 *hw_prio) {struct npc_mcam *mcam = &rvu->hw->mcam;u64 cam0, cam1, bank_cfg, cfg;int kw =0 , bank;u8 kw_type; -npc_mcam_idx_2_key_type (rvu, index, &kw_type); +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type)) +return -EINVAL ; bank =npc_get_bank (mcam, index); index &= (mcam->banksize -1 );
@@ -1298,6 +1315,8 @@ void npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index, cfg =rvu_read64 (rvu, blkaddr,NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index,0 ,1 )); entry->vtag_action = cfg; + +return 0 ; } int rvu_mbox_handler_npc_cn20k_mcam_write_entry(struct rvu *rvu,
@@ -1335,11 +1354,10 @@ int rvu_mbox_handler_npc_cn20k_mcam_write_entry(struct rvu *rvu,if (is_pffunc_af (req->hdr.pcifunc)) nix_intf = req->intf; -npc_cn20k_config_mcam_entry (rvu, blkaddr, req->entry, nix_intf, - &req->entry_data, req->enable_entry, - req->hw_prio, req->req_kw_type); + rc =npc_cn20k_config_mcam_entry (rvu, blkaddr, req->entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type); - rc =0 ; exit:mutex_unlock (&mcam->lock);return rc;
@@ -1361,11 +1379,13 @@ int rvu_mbox_handler_npc_cn20k_mcam_read_entry(struct rvu *rvu,mutex_lock (&mcam->lock); rc =npc_mcam_verify_entry (mcam, pcifunc, req->entry); -if (!rc) -npc_cn20k_read_mcam_entry (rvu, blkaddr, req->entry, - &rsp->entry_data, &rsp->intf, - &rsp->enable, &rsp->hw_prio); +if (rc) + goto fail; + rc =npc_cn20k_read_mcam_entry (rvu, blkaddr, req->entry, + &rsp->entry_data, &rsp->intf, + &rsp->enable, &rsp->hw_prio); +fail:mutex_unlock (&mcam->lock);return rc; }
@@ -1415,14 +1435,14 @@ int rvu_mbox_handler_npc_cn20k_mcam_alloc_and_write_entry(struct rvu *rvu,else nix_intf = pfvf->nix_rx_intf; -npc_cn20k_config_mcam_entry (rvu, blkaddr, entry, nix_intf, - &req->entry_data, req->enable_entry, - req->hw_prio, req->req_kw_type); + rc =npc_cn20k_config_mcam_entry (rvu, blkaddr, entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type);mutex_unlock (&mcam->lock); rsp->entry = entry_rsp.entry; -return 0 ; +return rc; }static int rvu_npc_get_base_steer_rule_type (struct rvu *rvu,u16 pcifunc)
@@ -1480,9 +1500,9 @@ int rvu_mbox_handler_npc_cn20k_read_base_steer_rule(struct rvu *rvu, read_entry:/* Read the mcam entry */ -npc_cn20k_read_mcam_entry (rvu, blkaddr, index, - &rsp->entry, &intf, - &enable, &hw_prio); + rc =npc_cn20k_read_mcam_entry (rvu, blkaddr, index, + &rsp->entry, &intf, + &enable, &hw_prio);mutex_unlock (&mcam->lock); out:return rc;
@@ -3607,9 +3627,30 @@ int npc_defrag_move_vdx_to_free(struct rvu *rvu,NPC_AF_CN20K_MCAMEX_BANKX_STAT_EXT (midx, bank)); -npc_cn20k_enable_mcam_entry (rvu, blkaddr, old_midx, false); -npc_cn20k_copy_mcam_entry (rvu, blkaddr, old_midx, new_midx); -npc_cn20k_enable_mcam_entry (rvu, blkaddr, new_midx, true); +/* If bug happened during copy/enable mcam, then there is a bug in allocation +* algorithm itself. There is no point in rewinding and returning, as it +* will face further issue. Return error after printing error +*/ +if (npc_cn20k_enable_mcam_entry (rvu, blkaddr, old_midx, false)) { +dev_err (rvu->dev, +"%s: Error happened while disabling old_mid=%u\n" , + __func__, old_midx); +return -EFAULT ; + } + +if (npc_cn20k_copy_mcam_entry (rvu, blkaddr, old_midx, new_midx)) { +dev_err (rvu->dev, +"%s: Error happened while copying old_midx=%u new_midx=%u\n" , + __func__, old_midx, new_midx); +return -EFAULT ; + } + +if (npc_cn20k_enable_mcam_entry (rvu, blkaddr, new_midx, true)) { +dev_err (rvu->dev, +"%s: Error happened while enabling new_mid=%u\n" , + __func__, new_midx); +return -EFAULT ; + } midx = new_midx % mcam->banksize; bank = new_midx / mcam->banksize;
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +10 -10
@@ -320,16 +320,16 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc);int npc_cn20k_dft_rules_idx_get (struct rvu *rvu,u16 pcifunc,u16 *bcast,u16 *mcast,u16 *promisc,u16 *ucast); -void npc_cn20k_config_mcam_entry (struct rvu *rvu,int blkaddr,int index, -u8 intf,struct cn20k_mcam_entry *entry, -bool enable,u8 hw_prio,u8 req_kw_type); -void npc_cn20k_enable_mcam_entry (struct rvu *rvu,int blkaddr, -int index,bool enable); -void npc_cn20k_copy_mcam_entry (struct rvu *rvu,int blkaddr, -u16 src,u16 dest); -void npc_cn20k_read_mcam_entry (struct rvu *rvu,int blkaddr,u16 index, -struct cn20k_mcam_entry *entry,u8 *intf, -u8 *ena,u8 *hw_prio); +int npc_cn20k_config_mcam_entry (struct rvu *rvu,int blkaddr,int index, +u8 intf,struct cn20k_mcam_entry *entry, +bool enable,u8 hw_prio,u8 req_kw_type); +int npc_cn20k_enable_mcam_entry (struct rvu *rvu,int blkaddr, +int index,bool enable); +int npc_cn20k_copy_mcam_entry (struct rvu *rvu,int blkaddr, +u16 src,u16 dest); +int npc_cn20k_read_mcam_entry (struct rvu *rvu,int blkaddr,u16 index, +struct cn20k_mcam_entry *entry,u8 *intf, +u8 *ena,u8 *hw_prio);void npc_cn20k_clear_mcam_entry (struct rvu *rvu,int blkaddr,int bank,int index);int npc_mcam_idx_2_key_type (struct rvu *rvu,u16 mcam_idx,u8 *key_type);
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +13 -5
@@ -241,7 +241,10 @@ void npc_enable_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,if (index <0 || index >= mcam->banksize * mcam->banks)return ; -return npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, enable); +if (npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, enable)) +dev_err (rvu->dev,"Error to %s mcam %u entry\n" , + enable ?"enable" :"disable" , index); +return ; } index &= (mcam->banksize -1 );
@@ -589,8 +592,8 @@ void npc_read_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam, NPC_AF_MCAMEX_BANKX_CFG(src, sbank)) & 1; } -static void npc_copy_mcam_entry (struct rvu *rvu,struct npc_mcam *mcam, -int blkaddr,u16 src,u16 dest) +static int npc_copy_mcam_entry (struct rvu *rvu,struct npc_mcam *mcam, +int blkaddr,u16 src,u16 dest) {int dbank =npc_get_bank (mcam, dest);int sbank =npc_get_bank (mcam, src);
@@ -630,6 +633,7 @@ static void npc_copy_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam, NPC_AF_MCAMEX_BANKX_CFG(src, sbank));rvu_write64 (rvu, blkaddr,NPC_AF_MCAMEX_BANKX_CFG (dest, dbank), cfg); +return 0 ; } u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
@@ -3266,7 +3270,10 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,npc_enable_mcam_entry (rvu, mcam, blkaddr, new_entry, false);/* Copy rule from old entry to new entry */ -npc_copy_mcam_entry (rvu, mcam, blkaddr, old_entry, new_entry); +if (npc_copy_mcam_entry (rvu, mcam, blkaddr, old_entry, new_entry)) { + rc =NPC_MCAM_INVALID_REQ ; +break ; + }/* Copy counter mapping, if any */ cntr = mcam->entry2cntr_map[old_entry];
@@ -3284,7 +3291,8 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,/* If shift has failed then report the failed index */ if (index != req->shift_count) { - rc =NPC_MCAM_PERM_DENIED ; +if (!rc) + rc =NPC_MCAM_PERM_DENIED ; rsp->failed_entry_idx = index; }
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +13 -7
@@ -1980,13 +1980,15 @@ static int npc_update_dmac_value(struct rvu *rvu, int npcblkaddr,ether_addr_copy (rule->packet.dmac, pfvf->mac_addr); -if (is_cn20k (rvu->pdev)) -npc_cn20k_read_mcam_entry (rvu, npcblkaddr, rule->entry, - cn20k_entry, &intf, - &enable, &hw_prio); -else +if (is_cn20k (rvu->pdev)) { +if (npc_cn20k_read_mcam_entry (rvu, npcblkaddr, rule->entry, + cn20k_entry, &intf, + &enable, &hw_prio)) +return -EINVAL ; + }else {npc_read_mcam_entry (rvu, mcam, npcblkaddr, rule->entry, entry, &intf, &enable); + } npc_update_entry(rvu, NPC_DMAC, &mdata, ether_addr_to_u64(pfvf->mac_addr), 0,
@@ -2038,8 +2040,12 @@ void npc_mcam_enable_flows(struct rvu *rvu, u16 target)continue ; } -if (rule->vfvlan_cfg) -npc_update_dmac_value (rvu, blkaddr, rule, pfvf); +if (rule->vfvlan_cfg) { +if (npc_update_dmac_value (rvu, blkaddr, rule, pfvf)) +dev_err (rvu->dev, +"Update dmac failed for %u, target=%#x\n" , + rule->entry, target); + }if (rule->rx_action.op ==NIX_RX_ACTION_DEFAULT ) {if (!def_ucast_rule)
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerRe: [PATCH v4 net 01/10] octeontx2-af: npc: cn20k: Propagate MCAM key-type errors on cn20k
Quoted 15 lines · Ratheesh Kannoth
npc_mcam_idx_2_key_type()can fail; callers used to ignore it and still usedkw_typewhen enabling, configuring, copying, and reading MCAM entries. That could program or decode hardware with an undefined key type.Return
-EINVALwhen key-type lookup fails. Return-EINVALfromnpc_cn20k_copy_mcam_entry()when src and dest key types differ instead of failing silently.Change npc_cn20k_{enable,config,copy,read}_mcam_entry() to return int on success or error. Thread those errors through the cn20k MCAM write and read mbox handlers, the cn20k baseline steer read path, NPC defrag move (disable/copy/enable with
dev_errand-EFAULT), and the DMAC update path inrvu_npc_fs.c.
Quoted 3 lines
Make
npc_copy_mcam_entry()return int so the cn20k branch can returnnpc_cn20k_copy_mcam_entry()without a void/int mismatch, and failNPC_MCAM_SHIFT_ENTRYwhen copy fails.
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260427063213.3937451-1-rkannoth%40marvell.com
Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +0
-0[ ... ]
Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +3
-3@@ -1335,11 +1354,10 @@ int rvu_mbox_handler_npc_cn20k_mcam_write_entry(struct rvu *rvu,if (is_pffunc_af (req->hdr.pcifunc)) nix_intf = req->intf; -npc_cn20k_config_mcam_entry (rvu, blkaddr, req->entry, nix_intf, - &req->entry_data, req->enable_entry, - req->hw_prio, req->req_kw_type); + rc =npc_cn20k_config_mcam_entry (rvu, blkaddr, req->entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type);
Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c int rvu_mbox_handler_npc_cn20k_mcam_write_entry(struct rvu *rvu, · line 1363
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +0
-1- rc =0 ; exit:mutex_unlock (&mcam->lock);return rc;Is it intentional that this handler, and the other cn20k mbox handlers touched here, now return a bare
-EINVALfrom the new failure paths while every other error exit in the same handlers returns one of the NPC_MCAM_* enum codes defined inmbox.h(NPC_MCAM_INVALID_REQ,NPC_MCAM_PERM_DENIED,NPC_MCAM_ALLOC_FAILED)?
A caller switching on those enum values would not match-EINVALcoming out ofnpc_cn20k_config_mcam_entry()ornpc_cn20k_read_mcam_entry().
I agree, Error handler's need a lot of cleanup, and is a candidate for net-next.
This patch is to fix a smatch error; so dont want to address this comment as part of this change. will do as a followup patch
Quoted 11 lines
(quoted diff) +0
-0@@ -1361,11 +1379,13 @@ int rvu_mbox_handler_npc_cn20k_mcam_read_entry(struct rvu *rvu,Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +2
-4mutex_lock (&mcam->lock); rc =npc_mcam_verify_entry (mcam, pcifunc, req->entry); -if (!rc) -npc_cn20k_read_mcam_entry (rvu, blkaddr, req->entry, - &rsp->entry_data, &rsp->intf, - &rsp->enable, &rsp->hw_prio); +if (rc) + goto fail;
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c int rvu_mbox_handler_npc_cn20k_mcam_read_entry(struct rvu *rvu, · line 1391
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +4
-0+ rc =npc_cn20k_read_mcam_entry (rvu, blkaddr, req->entry, + &rsp->entry_data, &rsp->intf, + &rsp->enable, &rsp->hw_prio); +fail:mutex_unlock (&mcam->lock);return rc; }When
npc_cn20k_read_mcam_entry()fails here (and in the base-steer read handler below), rc is returned butrsp->entry_dataand friends may be partially populated or untouched. Should the response buffer be zeroed on the error path, or is it documented elsewhere that callers must ignore rsp on error?
Callers won't use rsp upon error. So we can ignore this comment.
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +3
-3@@ -1415,14 +1435,14 @@ int rvu_mbox_handler_npc_cn20k_mcam_alloc_and_write_entry(struct rvu *rvu,else nix_intf = pfvf->nix_rx_intf; -npc_cn20k_config_mcam_entry (rvu, blkaddr, entry, nix_intf, - &req->entry_data, req->enable_entry, - req->hw_prio, req->req_kw_type); + rc =npc_cn20k_config_mcam_entry (rvu, blkaddr, entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type);mutex_unlock (&mcam->lock);
Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c int rvu_mbox_handler_npc_cn20k_mcam_alloc_and_write_entry(struct rvu *rvu, · line 1446
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +1
-1rsp->entry = entry_rsp.entry; -return 0 ; +return rc; }Does this path now leak the MCAM entry on the new error?
The entry was just obtained viarvu_mbox_handler_npc_mcam_alloc_entry()and its slot is recorded inentry_rsp. Whennpc_cn20k_config_mcam_entry()returns-EINVAL, the function returns rc without freeing the allocated entry, and it still writesrsp->entry= entry_rsp.entry so the caller gets an error alongside what looks like a valid entry index. Should a failure here release the entry (and likely clear rsp->
I agree; but this is also falls in same category of proper error handling; i believe we can take this as part of follow up patch. Please suggest as this needs a lot of code change to handle errors from all callers.
Quoted 19 lines
Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0[ ... ]
Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +4
-1@@ -3266,7 +3270,10 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,npc_enable_mcam_entry (rvu, mcam, blkaddr, new_entry, false);/* Copy rule from old entry to new entry */ -npc_copy_mcam_entry (rvu, mcam, blkaddr, old_entry, new_entry); +if (npc_copy_mcam_entry (rvu, mcam, blkaddr, old_entry, new_entry)) { + rc =NPC_MCAM_INVALID_REQ ; +break ; + }/* Copy counter mapping, if any */ cntr = mcam->entry2cntr_map[old_entry];@@ -3284,7 +3291,8 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,
Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu, · line 3297
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +2
-1/* If shift has failed then report the failed index */ if (index != req->shift_count) { - rc =NPC_MCAM_PERM_DENIED ; +if (!rc) + rc =NPC_MCAM_PERM_DENIED ; rsp->failed_entry_idx = index; }Is
NPC_MCAM_INVALID_REQthe intended code for a copy failure here? The sibling error paths in this loop propagate whatevernpc_mcam_verify_entry()returns (NPC_MCAM_INVALID_REQorNPC_MCAM_PERM_DENIED), and the post-loop block used to setNPC_MCAM_PERM_DENIEDunconditionally. The copy-failure case picksNPC_MCAM_INVALID_REQwhich is inconsistent with the existing codes for mid-shift failures in the same function.
Here rc was getting overwritten by previous rc. That is wrong. There is bigger work to handle errors properly; that will be taken as a followup error code handling. i believe, this fix change does not need to handle that. Please advise.
Ratheesh Kannoth
maintainerPATCH v4 2/10 octeontx2-af: npc: cn20k: Drop debugfs_create_file() error checks in init
In reply to Ratheesh Kannothdebugfs is not intended to be checked for allocation failures the way other kernel APIs are: callers should not fail probe or subsystem init because a debugfs node could not be created, including when debugfs is disabled in Kconfig. Replacing NULL checks with IS_ERR() checks is similarly wrong for optional debugfs.
Remove dentry checks and -EFAULT returns from npc_cn20k_debugfs_init().
https://staticthinking.wordpress.com/2023/07/24/debugfs-functions-are-not-supposed-to-be-checked/
--- .../marvell/octeontx2/af/cn20k/debugfs.c | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c +10 -23
@@ -249,34 +249,21 @@ DEFINE_SHOW_ATTRIBUTE(npc_defrag);int npc_cn20k_debugfs_init (struct rvu *rvu) {struct npc_priv_t *npc_priv =npc_priv_get (); -struct dentry *npc_dentry; - npc_dentry =debugfs_create_file ("mcam_layout" ,0444 , rvu->rvu_dbg.npc, - npc_priv, &npc_mcam_layout_fops); +debugfs_create_file ("mcam_layout" ,0444 , rvu->rvu_dbg.npc, + npc_priv, &npc_mcam_layout_fops); -if (!npc_dentry) -return -EFAULT ; +debugfs_create_file ("mcam_default" ,0444 , rvu->rvu_dbg.npc, + rvu, &npc_mcam_default_fops); - npc_dentry =debugfs_create_file ("mcam_default" ,0444 , rvu->rvu_dbg.npc, - rvu, &npc_mcam_default_fops); +debugfs_create_file ("vidx2idx" ,0444 , rvu->rvu_dbg.npc, + npc_priv, &npc_vidx2idx_map_fops); -if (!npc_dentry) -return -EFAULT ; +debugfs_create_file ("idx2vidx" ,0444 , rvu->rvu_dbg.npc, + npc_priv, &npc_idx2vidx_map_fops); - npc_dentry =debugfs_create_file ("vidx2idx" ,0444 , rvu->rvu_dbg.npc, - npc_priv, &npc_vidx2idx_map_fops); -if (!npc_dentry) -return -EFAULT ; - - npc_dentry =debugfs_create_file ("idx2vidx" ,0444 , rvu->rvu_dbg.npc, - npc_priv, &npc_idx2vidx_map_fops); -if (!npc_dentry) -return -EFAULT ; - - npc_dentry =debugfs_create_file ("defrag" ,0444 , rvu->rvu_dbg.npc, - npc_priv, &npc_defrag_fops); -if (!npc_dentry) -return -EFAULT ; +debugfs_create_file ("defrag" ,0444 , rvu->rvu_dbg.npc, + npc_priv, &npc_defrag_fops);return 0 ; }
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 3/10 octeontx2-af: npc: cn20k: Propagate errors in defrag MCAM alloc rollback
In reply to Ratheesh Kannothnpc_defrag_alloc_free_slots() allocates MCAM indexes in up to two passes on bank0 then bank1. On failure it rolls back by freeing entries already placed in save[].
__npc_subbank_alloc() can return a negative errno while only part of the indexes are valid. The rollback loop used rc for npc_mcam_idx_2_subbank_idx() as well, so a successful lookup stored zero in rc and a later __npc_subbank_free() failure could still end with return 0 when the allocation path had also left rc at zero (for example shortfall after zero return values from the alloc helpers).
Jump to the rollback path immediately when either __npc_subbank_alloc() call fails, preserving its errno. If both calls succeed but the total allocated count is still less than cnt, set rc to -ENOSPC before rollback. Use a separate err variable for npc_mcam_idx_2_subbank_idx() so a successful lookup no longer clears a non-zero rc from the allocation phase.
--- drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +7 -4
@@ -2325,6 +2325,7 @@ static int __npc_subbank_alloc(struct rvu *rvu, struct npc_subbank *sb,__npc_subbank_mark_free (rvu, sb); err1:kfree (save); + *alloc_cnt =0 ;return rc; }
@@ -3502,7 +3503,7 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu, {int alloc_cnt1, alloc_cnt2;struct npc_subbank *sb; -int rc, sb_off, i; +int rc, sb_off, i, err;bool deleted; sb = &npc_priv.sb[f->idx];
@@ -3516,6 +3517,7 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu,NPC_MCAM_LOWER_PRIO , false, cnt, save, cnt, true, &alloc_cnt1); +if (alloc_cnt1 < cnt) { rc = __npc_subbank_alloc(rvu, sb, NPC_MCAM_KEY_X2, sb->b1b,
@@ -3533,13 +3535,14 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu, __func__, cnt, alloc_cnt1, alloc_cnt2); goto fail_free_alloc; } +return 0 ; fail_free_alloc:for (i =0 ; i < alloc_cnt1 + alloc_cnt2; i++) { - rc =npc_mcam_idx_2_subbank_idx (rvu, save[i], - &sb, &sb_off); -if (rc) { + err =npc_mcam_idx_2_subbank_idx (rvu, save[i], + &sb, &sb_off); +if (err) {dev_err (rvu->dev,"%s: Error to find subbank for mcam idx=%u\n" , __func__, save[i]);
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerRe: [PATCH v4 net 03/10] octeontx2-af: npc: cn20k: Propagate errors in defrag MCAM alloc rollback
Quoted 38 lines · Ratheesh Kannoth
npc_defrag_alloc_free_slots()allocates MCAM indexes in up to two passes on bank0 then bank1. On failure it rolls back by freeing entries already placed in save[].
__npc_subbank_alloc()can return a negative errno while only part of the indexes are valid. The rollback loop used rc fornpc_mcam_idx_2_subbank_idx()as well, so a successful lookup stored zero in rc and a later__npc_subbank_free()failure could still end with return 0 when the allocation path had also left rc at zero (for example shortfall after zero return values from the alloc helpers).Jump to the rollback path immediately when either
__npc_subbank_alloc()call fails, preserving its errno. If both calls succeed but the total allocated count is still less than cnt, set rc to-ENOSPCbefore rollback. Use a separate err variable fornpc_mcam_idx_2_subbank_idx()so a successful lookup no longer clears a non-zero rc from the allocation phase.Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +1
-0@@ -3533,13 +3535,14 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu, __func__, cnt, alloc_cnt1, alloc_cnt2); goto fail_free_alloc; } +return 0 ; fail_free_alloc:drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c static int npc_defrag_alloc_free_slots(struct rvu *rvu, · line 3548
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +3
-3for (i =0 ; i < alloc_cnt1 + alloc_cnt2; i++) { - rc =npc_mcam_idx_2_subbank_idx (rvu, save[i], - &sb, &sb_off); -if (rc) { + err =npc_mcam_idx_2_subbank_idx (rvu, save[i], + &sb, &sb_off); +if (err) {dev_err (rvu->dev,"%s: Error to find subbank for mcam idx=%u\n" , __func__, save[i]);Does the diff implement what the commit message describes?
Quoted 8 lines
The commit message states:
Jump to the rollback path immediately when either__npc_subbank_alloc()call fails, preserving its errno. If both calls succeed but the total allocated count is still less than cnt, set rc to-ENOSPCbefore rollback.
Looking atnpc_defrag_alloc_free_slots()after the patch applies, there is no early jump after the first__npc_subbank_alloc()call, and no assignment of rc =-ENOSPCbefore the goto:
ACK.
pw-bot: changes-requested
Quoted 19 lines
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +1
-0@@ -3533,13 +3535,14 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu, __func__, cnt, alloc_cnt1, alloc_cnt2); goto fail_free_alloc; } +return 0 ; fail_free_alloc:drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c static int npc_defrag_alloc_free_slots(struct rvu *rvu, · line 3548
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +3
-3for (i =0 ; i < alloc_cnt1 + alloc_cnt2; i++) { - rc =npc_mcam_idx_2_subbank_idx (rvu, save[i], - &sb, &sb_off); -if (rc) { + err =npc_mcam_idx_2_subbank_idx (rvu, save[i], + &sb, &sb_off); +if (err) {dev_err (rvu->dev,"%s: Error to find subbank for mcam idx=%u\n" , __func__, save[i]);Does the diff implement what the commit message describes?
Quoted 8 lines
The commit message states:
Jump to the rollback path immediately when either__npc_subbank_alloc()call fails, preserving its errno. If both calls succeed but the total allocated count is still less than cnt, set rc to-ENOSPCbefore rollback.
Looking atnpc_defrag_alloc_free_slots()after the patch applies, there is no early jump after the first__npc_subbank_alloc()call, and no assignment of rc =-ENOSPCbefore the goto:
ACK.
Ratheesh Kannoth
maintainerPATCH v4 4/10 octeontx2-af: npc: cn20k: Fix target map and rule
In reply to Ratheesh Kannothnpc_defrag_move_vdx_to_free() disables, copies, and enables the MCAM entry at a new index but previously left entry2target_pffunc[] and the mcam_rules list still keyed to the old index. Copy the target PF association to the new slot, clear the old one, and retarget the rule entry so software state matches the relocated hardware context.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +15 -1
@@ -3588,9 +3588,10 @@ int npc_defrag_move_vdx_to_free(struct rvu *rvu,struct npc_defrag_node *v, int cnt, u16 *save) { + u16 new_midx, old_midx, vidx, target_pf;struct npc_mcam *mcam = &rvu->hw->mcam; +struct rvu_npc_mcam_rule *rule, *tmp;int i, vidx_cnt, rc, sb_off; -u16 new_midx, old_midx, vidx;struct npc_subbank *sb;bool deleted;u16 pcifunc;
@@ -3709,8 +3710,21 @@ int npc_defrag_move_vdx_to_free(struct rvu *rvu, mcam->entry2pfvf_map[new_midx] = pcifunc;/* Counter is not preserved */ mcam->entry2cntr_map[new_midx] = new_midx; + target_pf = mcam->entry2target_pffunc[old_midx]; + mcam->entry2target_pffunc[new_midx] = target_pf; + mcam->entry2target_pffunc[old_midx] =0 ; +npc_mcam_set_bit (mcam, new_midx); +/* Note: list order is not functionally required for mcam_rules */ +list_for_each_entry_safe (rule, tmp, &mcam->mcam_rules, list) { +if (rule->entry != old_midx) +continue ; + + rule->entry = new_midx; +break ; + } +/* Mark as invalid */ v->vidx[vidx_cnt - i -1 ] =-1 ; save[cnt - i -1 ] =-1 ;
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 5/10 octeontx2-af: npc: cn20k: Clear MCAM entries by index and key width
In reply to Ratheesh KannothReplace the old four-argument CN20K MCAM clear with a per-bank static helper and npc_cn20k_clear_mcam_entry() that takes a logical MCAM index, resolves the key width via npc_mcam_idx_2_key_type(), and clears either one bank (X2) or every bank (X4).
Call it from npc_clear_mcam_entry() on cn20k and log when key-type lookup fails. Use the per-bank helper from npc_cn20k_config_mcam_entry() for pre-program clears.
For loopback VFs, use the promisc MCAM index as ucast_idx when copying RSS action for promisc, matching cn20k default-rule layout.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 37 ++++++++++++++++--- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 3 +- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 17 ++++++++- 3 files changed, 48 insertions(+), 9 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +32 -5
@@ -842,8 +842,8 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,return 0 ; } -void -npc_cn20k_clear_mcam_entry (struct rvu *rvu,int blkaddr,int bank,int index) +static void +npc_clear_x2_entry (struct rvu *rvu,int blkaddr,int bank,int index) { rvu_write64(rvu, blkaddr, NPC_AF_CN20K_MCAMEX_BANKX_CAMX_INTF_EXT(index, bank, 1),
@@ -877,6 +877,33 @@ npc_cn20k_clear_mcam_entry(struct rvu *rvu, int blkaddr, int bank, int index) NPC_AF_CN20K_MCAMEX_BANKX_STAT_EXT(index, bank), 0); } +int +npc_cn20k_clear_mcam_entry (struct rvu *rvu,int blkaddr,int mcam_idx) +{ +struct npc_mcam *mcam = &rvu->hw->mcam; +int bank =npc_get_bank (mcam, mcam_idx); +u8 kw_type; +int index; + +if (npc_mcam_idx_2_key_type (rvu, mcam_idx, &kw_type)) +return -EINVAL ; + + index = mcam_idx & (mcam->banksize -1 ); + +if (kw_type ==NPC_MCAM_KEY_X2 ) { +npc_clear_x2_entry (rvu, blkaddr, bank, index); +return 0 ; + } + +/* For NPC_MCAM_KEY_X4 keys, both the banks +* need to be programmed with the same value. +*/ +for (bank =0 ; bank < mcam->banks_per_entry; bank++) +npc_clear_x2_entry (rvu, blkaddr, bank, index); + +return 0 ; +} +static void npc_cn20k_get_keyword (struct cn20k_mcam_entry *entry,int idx,u64 *cam0,u64 *cam1) {
@@ -1071,7 +1098,7 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,*/ if (kw_type ==NPC_MCAM_KEY_X2 ) {/* Clear mcam entry to avoid writes being suppressed by NPC */ -npc_cn20k_clear_mcam_entry (rvu, blkaddr, bank, mcam_idx); +npc_clear_x2_entry (rvu, blkaddr, bank, mcam_idx);npc_cn20k_config_kw_x2 (rvu, mcam, blkaddr, mcam_idx, intf, entry, bank, kw_type, kw, req_kw_type);
@@ -1096,8 +1123,8 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index, }/* Clear mcam entry to avoid writes being suppressed by NPC */ -npc_cn20k_clear_mcam_entry (rvu, blkaddr,0 , mcam_idx); -npc_cn20k_clear_mcam_entry (rvu, blkaddr,1 , mcam_idx); +npc_clear_x2_entry (rvu, blkaddr,0 , mcam_idx); +npc_clear_x2_entry (rvu, blkaddr,1 , mcam_idx); npc_cn20k_config_kw_x4(rvu, mcam, blkaddr, mcam_idx, intf, entry,
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +1 -2
@@ -330,8 +330,7 @@ int npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blkaddr,int npc_cn20k_read_mcam_entry (struct rvu *rvu,int blkaddr,u16 index,struct cn20k_mcam_entry *entry,u8 *intf,u8 *ena,u8 *hw_prio); -void npc_cn20k_clear_mcam_entry (struct rvu *rvu,int blkaddr, -int bank,int index); +int npc_cn20k_clear_mcam_entry (struct rvu *rvu,int blkaddr,int index);int npc_mcam_idx_2_key_type (struct rvu *rvu,u16 mcam_idx,u8 *key_type);u16 npc_cn20k_vidx2idx (u16 index);u16 npc_cn20k_idx2vidx (u16 idx);
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +15 -2
@@ -261,6 +261,13 @@ static void npc_clear_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,int bank =npc_get_bank (mcam, index);int actbank = bank; +if (is_cn20k (rvu->pdev)) { +if (npc_cn20k_clear_mcam_entry (rvu, blkaddr, index)) +dev_err (rvu->dev,"%s Failed to clear mcam %u\n" , + __func__, index); +return ; + } + index &= (mcam->banksize -1 );for (; bank < (actbank + mcam->banks_per_entry); bank++) { rvu_write64(rvu, blkaddr,
@@ -755,9 +762,15 @@ void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,/* If the corresponding PF's ucast action is RSS, * use the same action for promisc also +* Please note that for lbk(s) "index" and "ucast_idx" +* will be same. */ - ucast_idx =npc_get_nixlf_mcam_index (mcam, pcifunc, - nixlf,NIXLF_UCAST_ENTRY ); +if (is_lbk_vf (rvu, pcifunc)) + ucast_idx = index; +else + ucast_idx =npc_get_nixlf_mcam_index (mcam, pcifunc, + nixlf,NIXLF_UCAST_ENTRY ); +if (is_mcam_entry_enabled (rvu, mcam, blkaddr, ucast_idx)) *(u64 *)&action =npc_get_mcam_action (rvu, mcam, blkaddr, ucast_idx);
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerRe: [PATCH v4 net 05/10] octeontx2-af: npc: cn20k: Clear MCAM entries by index and key width
Quoted 37 lines · Ratheesh Kannoth
Replace the old four-argument CN20K MCAM clear with a per-bank static helper and
npc_cn20k_clear_mcam_entry()that takes a logical MCAM index, resolves the key width vianpc_mcam_idx_2_key_type(), and clears either one bank (X2) or every bank (X4).
Call it fromnpc_clear_mcam_entry()on cn20k and log when key-type lookup fails. Use the per-bank helper fromnpc_cn20k_config_mcam_entry()for pre-program clears.
For loopback VFs, use the promisc MCAM index asucast_idxwhen copying RSS action for promisc, matching cn20k default-rule layout.Cc Suman Ghosh <[email protected]>Fixes 6d1e70282f76 ("octeontx2-af: npc: cn20k: Use common APIs")Signed-off-by Ratheesh Kannoth <[email protected]>Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +1
-0@@ -755,9 +762,15 @@ void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,/* If the corresponding PF's ucast action is RSS, * use the same action for promisc also +* Please note that for lbk(s) "index" and "ucast_idx" drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc, · line 773
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +7
-2+* will be same. */ - ucast_idx =npc_get_nixlf_mcam_index (mcam, pcifunc, - nixlf,NIXLF_UCAST_ENTRY ); +if (is_lbk_vf (rvu, pcifunc)) + ucast_idx = index; +else + ucast_idx =npc_get_nixlf_mcam_index (mcam, pcifunc, + nixlf,NIXLF_UCAST_ENTRY ); +The commit subject and the Fixes: tag reference a cn20k-only change, and the comment added above says the new layout matches cn20k default-rules, but
is_lbk_vf()is silicon-agnostic:static inline bool is_lbk_vf(struct rvu *rvu, u16 pcifunc) { return (!(pcifunc & ~RVU_PFVF_FUNC_MASK) && (rvu->vf_devid == RVU_LBK_VF_DEVID)); }
Quoted 14 lines
Is it intentional that this branch fires on cn10k and otx2 LBK VFs as well?
Previously, for any LBK VF,ucast_idxwas obtained fromnpc_get_nixlf_mcam_index(..., NIXLF_UCAST_ENTRY), which on non-cn20k falls through tonpc_get_ucast_mcam_index()and returns the ucast slot. After this patchucast_idxbecomes the promisc slot for all LBK VFs.
The subsequentis_mcam_entry_enabled(ucast_idx)andnpc_get_mcam_action(ucast_idx)now read a different MCAM entry on non-cn20k silicon, which can change whether an RSS action is inherited for the LBK VF promisc rule.
Should this hunk be gated byis_cn20k(rvu->pdev), or is the behavioural change on cn10k/otx2 LBK VFs intended and worth calling out in the commit message?
This is intentional change.
Ratheesh Kannoth
maintainerPATCH v4 6/10 octeontx2-af: npc: cn20k: Fix bank value.
In reply to Ratheesh Kannothor X4 keys its loop reused the bank parameter as the loop counter, so bank no longer reflected the caller's bank after the loop and the control flow was hard to follow.
Program NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT directly in npc_cn20k_config_mcam_entry(): one CFG write for X2 using the computed bank, and one CFG write per bank inside the X4 action loop. Enable the entry at the end with npc_cn20k_enable_mcam_entry(..., true) instead of embedding the enable bit in bank_cfg via the removed helper.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 92 ++++++++----------- 1 file changed, 37 insertions(+), 55 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +37 -55
@@ -1045,34 +1045,6 @@ static void npc_cn20k_config_kw_x4(struct rvu *rvu, struct npc_mcam *mcam, kw, req_kw_type); } -static void -npc_cn20k_set_mcam_bank_cfg (struct rvu *rvu,int blkaddr,int mcam_idx, -int bank,u8 kw_type,bool enable,u8 hw_prio) -{ -struct npc_mcam *mcam = &rvu->hw->mcam; -u64 bank_cfg; - - bank_cfg = (u64 )hw_prio <<24 ; -if (enable) - bank_cfg |=0x1 ; - -if (kw_type ==NPC_MCAM_KEY_X2 ) { -rvu_write64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), - bank_cfg); -return ; - } - -/* For NPC_MCAM_KEY_X4 keys, both the banks -* need to be programmed with the same value. -*/ -for (bank =0 ; bank < mcam->banks_per_entry; bank++) { -rvu_write64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), - bank_cfg); - } -} -int npc_cn20k_config_mcam_entry (struct rvu *rvu,int blkaddr,int index,u8 intf,struct cn20k_mcam_entry *entry,bool enable,u8 hw_prio,u8 req_kw_type)
@@ -1080,6 +1052,7 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,struct npc_mcam *mcam = &rvu->hw->mcam;int mcam_idx = index % mcam->banksize;int bank = index / mcam->banksize; +u64 bank_cfg = (u64 )hw_prio <<24 ;int kw =0 ;u8 kw_type;
@@ -1119,41 +1092,50 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, bank,1 ), entry->vtag_action); - goto set_cfg; - } -/* Clear mcam entry to avoid writes being suppressed by NPC */ -npc_clear_x2_entry (rvu, blkaddr,0 , mcam_idx); -npc_clear_x2_entry (rvu, blkaddr,1 , mcam_idx); - -npc_cn20k_config_kw_x4 (rvu, mcam, blkaddr, - mcam_idx, intf, entry, - kw_type, req_kw_type); -for (bank =0 ; bank < mcam->banks_per_entry; bank++) { -/* Set 'action' */ +/* Set HW priority */ rvu_write64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, - bank,0 ), - entry->action); +NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), + bank_cfg); -/* Set TAG 'action' */ -rvu_write64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, - bank,1 ), - entry->vtag_action); + }else { +/* Clear mcam entry to avoid writes being suppressed by NPC */ +npc_clear_x2_entry (rvu, blkaddr,0 , mcam_idx); +npc_clear_x2_entry (rvu, blkaddr,1 , mcam_idx); -/* Set 'action2' for inline receive */ -rvu_write64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, - bank,2 ), - entry->action2); +npc_cn20k_config_kw_x4 (rvu, mcam, blkaddr, + mcam_idx, intf, entry, + kw_type, req_kw_type); +for (bank =0 ; bank < mcam->banks_per_entry; bank++) { +/* Set 'action' */ +rvu_write64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, + bank,0 ), + entry->action); + +/* Set TAG 'action' */ +rvu_write64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, + bank,1 ), + entry->vtag_action); + +/* Set 'action2' for inline receive */ +rvu_write64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (mcam_idx, + bank,2 ), + entry->action2); + +/* Set HW priority */ +rvu_write64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT (mcam_idx, bank), + bank_cfg); + } } -set_cfg:/* TODO: */ /* PF installing VF rule */ -npc_cn20k_set_mcam_bank_cfg (rvu, blkaddr, mcam_idx, bank, - kw_type, enable, hw_prio); +if (npc_cn20k_enable_mcam_entry (rvu, blkaddr, index, enable)) +return -EINVAL ;return 0 ; }
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 7/10 octeontx2-af: npc: cn20k: Fix MCAM actions read
In reply to Ratheesh Kannothnpc_cn20k_read_mcam_entry() always reloaded action and vtag_action from bank 0 after programming the CAM words. Use the bank returned by npc_get_bank() for the ACTION reads as well, and read those registers once up front so both X2 and X4 paths share the same metadata.
Return directly from the X2 keyword path now that the action fields are already populated.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +13 -13
@@ -1219,6 +1219,18 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index, bank =npc_get_bank (mcam, index); index &= (mcam->banksize -1 ); + cfg =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index, bank,0 )); + entry->action = cfg; + + cfg =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index, bank,1 )); + entry->vtag_action = cfg; + + cfg =rvu_read64 (rvu, blkaddr, +NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index, bank,2 )); + entry->action2 = cfg; + cfg =rvu_read64 (rvu, blkaddr,NPC_AF_CN20K_MCAMEX_BANKX_CAMX_INTF_EXT (index, bank,1 )) &3 ;
@@ -1268,7 +1280,7 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index, bank, 0));npc_cn20k_fill_entryword (entry, kw +3 , cam0, cam1); - goto read_action; +return 0 ; }for (bank =0 ; bank < mcam->banks_per_entry; bank++, kw = kw +4 ) {
@@ -1313,18 +1325,6 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index,npc_cn20k_fill_entryword (entry, kw +3 , cam0, cam1); } -read_action: -/* 'action' is set to same value for both bank '0' and '1'. -* Hence, reading bank '0' should be enough. -*/ - cfg =rvu_read64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index,0 ,0 )); - entry->action = cfg; - - cfg =rvu_read64 (rvu, blkaddr, -NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT (index,0 ,1 )); - entry->vtag_action = cfg; -return 0 ; }
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 8/10 octeontx2-af: npc: cn20k: Initialize default-rule index outputs up front
In reply to Ratheesh Kannothnpc_cn20k_dft_rules_idx_get() wrote USHRT_MAX into individual outputs only on some error paths (lbk promisc lookup, VF ucast lookup, and the PF rule walk), which could leave other caller slots stale across retries.
Set every non-NULL bcast/mcast/promisc/ucast pointer to USHRT_MAX once at entry, then drop the duplicate assignments on failure. Successful lookups still overwrite the relevant slot before returning.
--- drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +7 -3
@@ -4002,6 +4002,13 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast,void *val;int i, j; +for (i =0 ; i <ARRAY_SIZE (ptr); i++) { +if (!ptr[i]) +continue ; + + *ptr[i] =USHRT_MAX ; + } +if (!npc_priv.init_done)return 0 ;
@@ -4017,7 +4024,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, npc_dft_rule_name[NPC_DFT_RULE_PROMISC_ID ], pcifunc); - *ptr[0 ] =USHRT_MAX ;return -ESRCH ; }
@@ -4037,7 +4043,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, npc_dft_rule_name[NPC_DFT_RULE_UCAST_ID ], pcifunc); - *ptr[3 ] =USHRT_MAX ;return -ESRCH ; }
@@ -4057,7 +4062,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, __func__, npc_dft_rule_name[i], pcifunc); - *ptr[j] =USHRT_MAX ;continue ; }
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v4 9/10 octeontx2-af: npc: cn20k: Tear down default MCAM rules explicitly on free
In reply to Ratheesh Kannothnpc_cn20k_dft_rules_free() used the NPC MCAM mbox "free all" path, which does not match how cn20k tracks default-rule MCAM slots indexes.
Resolve the default-rule indices, then for each valid slot clear the bitmap entry, drop the PF/VF map, disable the MCAM line, clear the target function, and npc_cn20k_idx_free(). Remove any matching software mcam_rules nodes. On hard failure from idx_free, WARN and stop so the box stays up for analysis.
In npc_mcam_free_all_entries(), prefetch the same default-rule indices and, on cn20k, skip bitmap clear and idx_free when the scanned entry is one of those reserved defaults (they are released by npc_cn20k_dft_rules_free). Still disable the entry and tear down counter mapping for every matching index.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 51 ++++++++++++---- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 59 +++++++++++++------ 2 files changed, 82 insertions(+), 28 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +40 -11
@@ -4164,11 +4164,11 @@ static bool npc_is_cgx_or_lbk(struct rvu *rvu, u16 pcifunc)void npc_cn20k_dft_rules_free (struct rvu *rvu,u16 pcifunc) { -struct npc_mcam_free_entry_req free_req = {0 }; +struct npc_mcam *mcam = &rvu->hw->mcam; +u16 ptr[4 ] = {[0 ...3 ] =USHRT_MAX }; +struct rvu_npc_mcam_rule *rule, *tmp;unsigned long index; -struct msg_rsp rsp; -u16 ptr[4 ]; -int rc, i; +int blkaddr, rc, i;void *map;if (!npc_priv.init_done)
@@ -4226,14 +4226,43 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) } free_rules: + blkaddr =rvu_get_blkaddr (rvu,BLKTYPE_NPC ,0 ); +if (blkaddr <0 ) +return ; +for (int i =0 ; i <4 ; i++) { +if (ptr[i] ==USHRT_MAX ) +continue ; - free_req.hdr.pcifunc = pcifunc; - free_req.all =1 ; - rc =rvu_mbox_handler_npc_mcam_free_entry (rvu, &free_req, &rsp); -if (rc) -dev_err (rvu->dev, -"%s: Error deleting default entries (pcifunc=%#x\n" , - __func__, pcifunc); +mutex_lock (&mcam->lock); +npc_mcam_clear_bit (mcam, ptr[i]); + mcam->entry2pfvf_map[ptr[i]] =NPC_MCAM_INVALID_MAP ; +npc_cn20k_enable_mcam_entry (rvu, blkaddr, ptr[i], false); + mcam->entry2target_pffunc[ptr[i]] =0x0 ; +mutex_unlock (&mcam->lock); + + rc =npc_cn20k_idx_free (rvu, &ptr[i],1 ); +if (rc) { +/* Non recoverable error. Let us WARN and return. Keep system alive to +* enable debugging +*/ +WARN (1 ,"%s Error deleting default entries (pcifunc=%#x) mcam_idx=%u\n" , + __func__, pcifunc, ptr[i]); +return ; + } + } + +mutex_lock (&mcam->lock); +list_for_each_entry_safe (rule, tmp, &mcam->mcam_rules, list) { +for (int i =0 ; i <4 ; i++) { +if (ptr[i] != rule->entry) +continue ; + +list_del (&rule->list); +kfree (rule); +break ; + } + } +mutex_unlock (&mcam->lock); }int npc_cn20k_dft_rules_alloc (struct rvu *rvu,u16 pcifunc)
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +42 -17
75 lines not on this page · raw message
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerRe: [PATCH v4 net 09/10] octeontx2-af: npc: cn20k: Tear down default MCAM rules explicitly on free
Quoted 52 lines · Ratheesh Kannoth
npc_cn20k_dft_rules_free()used the NPC MCAM mbox "free all" path, which does not match how cn20k tracks default-rule MCAM slots indexes.Resolve the default-rule indices, then for each valid slot clear the bitmap entry, drop the PF/VF map, disable the MCAM line, clear the target function, and
npc_cn20k_idx_free(). Remove any matching softwaremcam_rulesnodes. On hard failure fromidx_free, WARN and stop so the box stays up for analysis.In
npc_mcam_free_all_entries(), prefetch the same default-rule indices and, on cn20k, skip bitmap clear andidx_freewhen the scanned entry is one of those reserved defaults (they are released bynpc_cn20k_dft_rules_free). Still disable the entry and tear down counter mapping for every matching index.Fixes 09d3b7a1403f ("octeontx2-af: npc: cn20k: Allocate default MCAM indexes")Signed-off-by Ratheesh Kannoth <[email protected]>Quoted 20 lines
free_rules:drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +11
-7+ blkaddr =rvu_get_blkaddr (rvu,BLKTYPE_NPC ,0 ); +if (blkaddr <0 ) +return ; +for (int i =0 ; i <4 ; i++) { +if (ptr[i] ==USHRT_MAX ) +continue ; - free_req.hdr.pcifunc = pcifunc; - free_req.all =1 ; - rc =rvu_mbox_handler_npc_mcam_free_entry (rvu, &free_req, &rsp); -if (rc) -dev_err (rvu->dev, -"%s: Error deleting default entries (pcifunc=%#x\n" , - __func__, pcifunc); +mutex_lock (&mcam->lock); +npc_mcam_clear_bit (mcam, ptr[i]); + mcam->entry2pfvf_map[ptr[i]] =NPC_MCAM_INVALID_MAP ; +npc_cn20k_enable_mcam_entry (rvu, blkaddr, ptr[i], false); + mcam->entry2target_pffunc[ptr[i]] =0x0 ;drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) · line 4250
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +10
-0+mutex_unlock (&mcam->lock); + + rc =npc_cn20k_idx_free (rvu, &ptr[i],1 ); +if (rc) { +/* Non recoverable error. Let us WARN and return. Keep system alive to +* enable debugging +*/ +WARN (1 ,"%s Error deleting default entries (pcifunc=%#x) mcam_idx=%u\n" , + __func__, pcifunc, ptr[i]); +return ;When
npc_cn20k_idx_free()fails on some ptr[i], this path WARNs and returns from inside the per-entry loop. At that point, the earlier block innpc_cn20k_dft_rules_free()has already xa_erase()d thexa_pf2dfl_rmapentries for all four default rule IDs for this pcifunc,
Quoted 8 lines
so
npc_cn20k_dft_rules_idx_get()on a retry would return-ESRCHand could not reclaim anything.
Given that, could the remaining ptr[i+1..3] entries leak on this path? Their bitmap bits stay cleared only if they were processed before the failure, but any entries after i still have their bitmap slot allocated,entry2pfvf_mapstill referencing pcifunc, MCAM line still enabled,entry2target_pffuncstill set, and the cn20k idx allocator still holding the slots.
No. This is a non recoverable error and no way we can recover and proceed. So this warning and returning would enable the user to debug the system.
Quoted 24 lines
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +6
-0+ } + } + +mutex_lock (&mcam->lock); +list_for_each_entry_safe (rule, tmp, &mcam->mcam_rules, list) { +for (int i =0 ; i <4 ; i++) {drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) · line 4266
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +9
-0+if (ptr[i] != rule->entry) +continue ; + +list_del (&rule->list); +kfree (rule); +break ; + } + } +mutex_unlock (&mcam->lock); }On the same error path, the
list_for_each_entry_safe()walk overmcam->mcam_rulesbelow is skipped entirely because of the early return, sorvu_npc_mcam_rulenodes for all four default indices (including the ones that were successfully torn down before the failure) stay on the list.
The commit message says:
Resolve the default-rule indices, then for each valid slot clear the bitmap entry, drop the PF/VF map, disable the MCAM line, clear the
Quoted 8 lines
target function, and
npc_cn20k_idx_free(). Remove any matching softwaremcam_rulesnodes. On hard failure fromidx_free, WARN and stop so the box stays up for analysis.
Is the "Remove any matching softwaremcam_rulesnodes" step intended to also be skipped wheneveridx_free()fails? If not, would it make sense to move themcam_rulescleanup ahead of the per-entry loop, or continue the loop best-effort and WARN once at the end, so the software list and the already-torn-down slots do not silently diverge on the error path?
No. mcam list will show more information in debugfs. I dont think, freeing 4 entries (in default entries) would save us anything. So better to keep this way.
Ratheesh Kannoth
maintainerPATCH v4 10/10 octeontx2-af: npc: cn20k: Reject missing default-rule MCAM indices
In reply to Ratheesh KannothWhen cn20k default L2 rules are not installed, npc_cn20k_dft_rules_idx_get() leaves broadcast, multicast, promiscuous, and unicast slots at USHRT_MAX. npc_get_nixlf_mcam_index() previously returned that sentinel as a valid MCAM index, so callers could program hardware with an invalid index.
Return -EINVAL from the cn20k branches of npc_get_nixlf_mcam_index() when the requested slot is still USHRT_MAX. Harden cn20k NPC MCAM entry helpers to reject out-of-range indices before touching hardware.
Drop the early bounds check in npc_enable_mcam_entry() for cn20k so invalid indices are validated inside npc_cn20k_enable_mcam_entry() instead of being silently ignored.
In rvu_npc_update_flowkey_alg_idx(), treat negative MCAM indices like out-of-range values, and only update RSS actions for promiscuous and all-multi paths when the resolved index is non-negative.
--- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 14 +- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 1 + .../ethernet/marvell/octeontx2/af/rvu_nix.c | 3 + .../ethernet/marvell/octeontx2/af/rvu_npc.c | 139 +++++++++++++++++- .../marvell/octeontx2/af/rvu_npc_fs.c | 10 +- 5 files changed, 157 insertions(+), 10 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +13 -1
@@ -808,6 +808,9 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkaddr,u64 cfg, hw_prio;u8 kw_type; +if (index <0 || index >= mcam->total_entries) +return -EINVAL ; +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type))return -EINVAL ;
@@ -1056,6 +1059,9 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int blkaddr, int index,int kw =0 ;u8 kw_type; +if (index <0 || index >= mcam->total_entries) +return -EINVAL ; +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type))return -EINVAL ;
@@ -1148,6 +1154,9 @@ int npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blkaddr, u16 src, u16 dest)int bank, i, sb, db;int dbank, sbank; +if (src >= mcam->total_entries || dest >= mcam->total_entries) +return -EINVAL ; + dbank =npc_get_bank (mcam, dest); sbank =npc_get_bank (mcam, src);
@@ -1213,6 +1222,9 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int blkaddr, u16 index,int kw =0 , bank;u8 kw_type; +if (index >= mcam->total_entries) +return -EINVAL ; +if (npc_mcam_idx_2_key_type (rvu, index, &kw_type))return -EINVAL ;
@@ -4156,7 +4168,7 @@ int rvu_mbox_handler_npc_get_dft_rl_idxs(struct rvu *rvu, struct msg_req *req,return 0 ; } -static bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc) +bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc) {return is_pf_cgxmapped (rvu,rvu_get_pf (rvu->pdev, pcifunc)) ||is_lbk_vf (rvu, pcifunc);
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +1 -0
@@ -335,5 +335,6 @@ int npc_mcam_idx_2_key_type(struct rvu *rvu, u16 mcam_idx, u8 *key_type);u16 npc_cn20k_vidx2idx (u16 index);u16 npc_cn20k_idx2vidx (u16 idx);int npc_cn20k_defrag (struct rvu *rvu); +bool npc_is_cgx_or_lbk (struct rvu *rvu,u16 pcifunc);#endif /* NPC_CN20K_H */
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +3 -0
@@ -3577,6 +3577,9 @@ static int nix_update_mce_rule(struct rvu *rvu, u16 pcifunc, mcam_index =npc_get_nixlf_mcam_index (mcam, pcifunc & ~RVU_PFVF_FUNC_MASK , nixlf, type); +if (mcam_index <0 ) +return -EINVAL ; + err =nix_update_mce_list (rvu, pcifunc, mce_list, mce_idx, mcam_index, add);return err;
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +131 -8
273 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +9 -1
@@ -1444,7 +1444,7 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,struct msg_rsp write_rsp;struct mcam_entry *entry;bool new = false; -u16 entry_index; +int entry_index;int err; installed_features = req->features;
@@ -1477,6 +1477,14 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,if (req->default_rule) { entry_index =npc_get_nixlf_mcam_index (mcam, target, nixlf,NIXLF_UCAST_ENTRY ); + +if (entry_index <0 ) { +dev_err (rvu->dev, +"%s: Error to get ucast entry for target=%#x\n" , + __func__, target); +return -EINVAL ; + } + enable =is_mcam_entry_enabled (rvu, mcam, blkaddr, entry_index); }
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerRe: [PATCH v4 net 10/10] octeontx2-af: npc: cn20k: Reject missing default-rule MCAM indices
Quoted 9 lines · Ratheesh Kannoth
When cn20k default L2 rules are not installed,
npc_cn20k_dft_rules_idx_get()leaves broadcast, multicast, promiscuous, and unicast slots atUSHRT_MAX.npc_get_nixlf_mcam_index()previously returned that sentinel as adrivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0
[ ... ]
Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c int rvu_mbox_handler_npc_read_base_steer_rule(struct rvu *rvu, · line 4016
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +8
-0@@ -3897,6 +4006,14 @@ int rvu_mbox_handler_npc_read_base_steer_rule(struct rvu *rvu,/* Read the default ucast entry if there is no pkt steering rule */ index =npc_get_nixlf_mcam_index (mcam, pcifunc, nixlf,NIXLF_UCAST_ENTRY ); +if (index <0 ) { +mutex_unlock (&mcam->lock); +dev_err (rvu->dev, +"%s: Error to get ucast entry for pcifunc=%#x\n" , + __func__, pcifunc); + goto out; + } +Should this path set rc before jumping to out?
Looking at the surrounding function, rc is initialized to 0 and the out label simply returns rc:int index, blkaddr, nixlf, rc = 0; ... out: return rc;
Quoted 10 lines
The adjacent
nix_get_nixlf()failure path assigns rc before the goto, and other error paths in this file use returnNPC_MCAM_INVALID_REQ. On this new error path rc stays 0,npc_read_mcam_entry()is skipped, and the handler returns success withrsp->entryleft zero-filled. Would the requester be unable to distinguish this failure from a legitimate reply? Would assigning rc =NPC_MCAM_INVALID_REQ(or another negative errno) before goto out be more appropriate here?Quoted 3 lines
read_entry:drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +0
-0/* Read the mcam entry */ npc_read_mcam_entry(rvu, mcam, blkaddr, index, &rsp->entry, &intf,
pw-bot: changes-requested
ACK. will set rc for this error path.