From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68D4E3783D4; Mon, 20 Apr 2026 02:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652530; cv=none; b=b43sqz6vWIQNU7Nw6tNR5HH+Ak7nkaQTdHK0zIQVi6lUvPvLB/AIMYqkK0Oce+egsN7hMcrY3oIF3RawOS5G5b2DXyoSdixuPwups+ekr6bevGyXJkxjl3HPkATVwJqmUCeO/WU+vCl8EWuOsyTedyqa+Dxc1bKmKrnXZcQ1jq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652530; c=relaxed/simple; bh=3XaTfMISC/M3+6C00JCYwDl0MhIWv/3VOavixiCStAg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mT9YP8RakwN2nGr7GC/Jc+eyAYshfYKgYt5ztmYYR6MNMdYyAvaOaF1oCI2fU55OKJlF2flbEpkL/EVWqV5H++uXLxUOI1g6U0kgXBVBn3nYO5yhgmlESt6mtEyVVkKaGpJqpZPSsxyTRPmbELZ/o+CX60LpU7EMEV0CktOCMmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=ClHO2t7G; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="ClHO2t7G" Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63K0F8q51847350; Sun, 19 Apr 2026 19:35:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=G j4hPcKsjMjjXJxSO0F7+OahvmT2G1ANFG2pIjSeezo=; b=ClHO2t7G/RNVUAoLw UrsQnoyIqGr+ldqz7Jf/4JA9iH/uxH2Fnl2hXndTXSAmxoUYs40gFn4FUwiqht+S SXkBsLRmX9miHV62mSff9jeSncaKjYfzBoiaW1oBhxdbnfwuVzOjV3oeCQTdBTW9 lNs4paIw84QfWYDWofVK1zvPBtZuLE6+y1gV5HGZgmYcCZnNbaleEy3+XHO/Tznf 6tjyTXAd8ed586ugvfkno10rYnGB2jQtvaiUE+ZfuxJwmiwuiCtdkyPChf2/+GTn k2gJPz2m1WiONK4+0R5bsCjckmwdTdK47C5P5eDH4P1Ec/ZoW3nsKE2B4V1hy/po 51UVw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4dm7ajtsy1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:06 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:05 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:05 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id EA09D3F7041; Sun, 19 Apr 2026 19:35:01 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Suman Ghosh" , Dan Carpenter Subject: [PATCH v2 net 01/11] octeontx2-af: npc: cn20k: Propagate MCAM key-type errors on cn20k Date: Mon, 20 Apr 2026 08:04:32 +0530 Message-ID: <20260420023442.3295891-2-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: EDmmNxkByjCe4wVxWLDD8kRoyD7q2Tk- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX3WJsGhNS7bAS Ctwfqx39W7m+3pKFbDdRMO5Qt86aF9kfeteO+oc1IWErvE5908Y/XZ5pI17U6AWQhwVebcGvVKO 5blQ3Dc1pgLvWwexZZm8ELU3aB9tbSspCufxOJL7lsXPtYfrQ2xTidYgyNjXhfqMp2ZRKkzoFmI Dsx6dJJO+XvmezdgFNjPAk01xLSbn/JHkOlYGCePVuEYeKZjgOIeljmRHoI4INz5bC2N/G3Opay hPQYXkBUtSzIl33QaYoqVvy5zgXDUwyyhVQCrQOCQuTS2oZrHuYlcdwd/K5cMsHKVaFP0ine3rN NErUacvzyqtHW6syzCM2k/P6ERhcUuH7bjSiJw+qP2dOPA8VWrjwZMhUV+QZcP53lmHZpeFZBJf R7Ps8pEGSmL2XdlX5nT5BdQC7gAGACq1XeRmJii71FAgzyh+Fic20Cr8anHKje0P7w6sIg3Z9Qb 2vAz/qq4Z9JkHwX1E0w== X-Authority-Analysis: v=2.4 cv=DuJmPm/+ c=1 sm=1 tr=0 ts=69e590da cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=EAYMVhzMl8SCOHhVQcBL:22 a=VwQbUJbxAAAA:8 a=M5GUcnROAAAA:8 a=pGLkceISAAAA:8 a=TnIioShXn-uTWYZ4KJoA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-GUID: EDmmNxkByjCe4wVxWLDD8kRoyD7q2Tk- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" 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. Cc: Suman Ghosh Cc: Dan Carpenter Fixes: 6d1e70282f76 ("octeontx2-af: npc: cn20k: Use common APIs") Link: https://lore.kernel.org/netdev/adiQJvuKlEhq2ILx@stanley.mountain/ Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 107 ++++++++++++------ .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 20 ++-- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 13 ++- .../marvell/octeontx2/af/rvu_npc_fs.c | 12 +- 4 files changed, 100 insertions(+), 52 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 7291fdb89b03..18d70f4527d1 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -798,7 +798,7 @@ void npc_cn20k_load_mkex_profile(struct rvu *rvu, int b= lkaddr, iounmap(mkex_prfl_addr); } =20 -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 blkadd= r, u64 cfg, hw_prio; u8 kw_type; =20 - 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 =3D=3D NPC_MCAM_KEY_X2) { cfg =3D 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 blkadd= r, rvu_write64(rvu, blkaddr, NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT(mcam_idx, bank), cfg); - return; + return 0; } =20 /* For NPC_CN20K_MCAM_KEY_X4 keys, both the banks @@ -836,6 +838,8 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkadd= r, NPC_AF_CN20K_MCAMEX_BANKX_CFG_EXT(mcam_idx, bank), cfg); } + + return 0; } =20 void @@ -1042,9 +1046,9 @@ npc_cn20k_set_mcam_bank_cfg(struct rvu *rvu, int blka= ddr, int mcam_idx, } } =20 -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 =3D &rvu->hw->mcam; int mcam_idx =3D index % mcam->banksize; @@ -1052,10 +1056,13 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, i= nt blkaddr, int index, int kw =3D 0; u8 kw_type; =20 + 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; =20 - 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 =3D 0 & CAM0 =3D 1 =3D> match if key =3D 0 @@ -1120,9 +1127,11 @@ void npc_cn20k_config_mcam_entry(struct rvu *rvu, in= t 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; } =20 -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 d= est) { struct npc_mcam *mcam =3D &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) =20 dbank =3D npc_get_bank(mcam, dest); sbank =3D 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 !=3D dest_kwtype) - return; + return -EINVAL; =20 src &=3D (mcam->banksize - 1); dest &=3D (mcam->banksize - 1); @@ -1170,6 +1184,8 @@ void npc_cn20k_copy_mcam_entry(struct rvu *rvu, int b= lkaddr, u16 src, u16 dest) if (src_kwtype =3D=3D NPC_MCAM_KEY_X2) break; } + + return 0; } =20 static void npc_cn20k_fill_entryword(struct cn20k_mcam_entry *entry, int i= dx, @@ -1179,16 +1195,17 @@ static void npc_cn20k_fill_entryword(struct cn20k_m= cam_entry *entry, int idx, entry->kw_mask[idx] =3D cam1 ^ cam0; } =20 -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 =3D &rvu->hw->mcam; u64 cam0, cam1, bank_cfg, cfg; int kw =3D 0, bank; u8 kw_type; =20 - npc_mcam_idx_2_key_type(rvu, index, &kw_type); + if (npc_mcam_idx_2_key_type(rvu, index, &kw_type)) + return -EINVAL; =20 bank =3D npc_get_bank(mcam, index); index &=3D (mcam->banksize - 1); @@ -1298,6 +1315,8 @@ void npc_cn20k_read_mcam_entry(struct rvu *rvu, int b= lkaddr, u16 index, cfg =3D rvu_read64(rvu, blkaddr, NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(index, 0, 1)); entry->vtag_action =3D cfg; + + return 0; } =20 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(str= uct rvu *rvu, if (is_pffunc_af(req->hdr.pcifunc)) nix_intf =3D req->intf; =20 - 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 =3D npc_cn20k_config_mcam_entry(rvu, blkaddr, req->entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type); =20 - rc =3D 0; exit: mutex_unlock(&mcam->lock); return rc; @@ -1361,11 +1379,13 @@ int rvu_mbox_handler_npc_cn20k_mcam_read_entry(stru= ct rvu *rvu, =20 mutex_lock(&mcam->lock); rc =3D 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; =20 + rc =3D 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,9 +1435,9 @@ int rvu_mbox_handler_npc_cn20k_mcam_alloc_and_write_e= ntry(struct rvu *rvu, else nix_intf =3D pfvf->nix_rx_intf; =20 - npc_cn20k_config_mcam_entry(rvu, blkaddr, entry, nix_intf, - &req->entry_data, req->enable_entry, - req->hw_prio, req->req_kw_type); + rc =3D npc_cn20k_config_mcam_entry(rvu, blkaddr, entry, nix_intf, + &req->entry_data, req->enable_entry, + req->hw_prio, req->req_kw_type); =20 mutex_unlock(&mcam->lock); =20 @@ -1480,9 +1500,9 @@ int rvu_mbox_handler_npc_cn20k_read_base_steer_rule(s= truct rvu *rvu, =20 read_entry: /* Read the mcam entry */ - npc_cn20k_read_mcam_entry(rvu, blkaddr, index, - &rsp->entry, &intf, - &enable, &hw_prio); + rc =3D 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)); =20 - 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 alloc= ation + * 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=3D%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 to while copying old_midx=3D%u new_midx=3D%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=3D%u\n", + __func__, new_midx); + return -EFAULT; + } =20 midx =3D new_midx % mcam->banksize; bank =3D new_midx / mcam->banksize; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.h index 815d0b257a7e..8f3eea9cfb1d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h @@ -320,16 +320,16 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pc= ifunc); int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 pcifunc, u16 *bcast, u16 *mcast, u16 *promisc, u16 *ucast); =20 -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); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_npc.c index c2ca5ed1d028..762fafd4ccb7 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -241,7 +241,8 @@ void npc_enable_mcam_entry(struct rvu *rvu, struct npc_= mcam *mcam, if (index < 0 || index >=3D mcam->banksize * mcam->banks) return; =20 - return npc_cn20k_enable_mcam_entry(rvu, blkaddr, index, enable); + npc_cn20k_enable_mcam_entry(rvu, blkaddr, index, enable); + return; } =20 index &=3D (mcam->banksize - 1); @@ -589,8 +590,8 @@ void npc_read_mcam_entry(struct rvu *rvu, struct npc_mc= am *mcam, NPC_AF_MCAMEX_BANKX_CFG(src, sbank)) & 1; } =20 -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 =3D npc_get_bank(mcam, dest); int sbank =3D npc_get_bank(mcam, src); @@ -630,6 +631,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; } =20 u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam, @@ -3266,7 +3268,10 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu= *rvu, npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, false); =20 /* 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 =3D NPC_MCAM_INVALID_REQ; + break; + } =20 /* Copy counter mapping, if any */ cntr =3D mcam->entry2cntr_map[old_entry]; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c b/drive= rs/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c index b45798d9fdab..bd1488fe1611 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c @@ -1980,13 +1980,15 @@ static int npc_update_dmac_value(struct rvu *rvu, i= nt npcblkaddr, =20 ether_addr_copy(rule->packet.dmac, pfvf->mac_addr); =20 - 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); + } =20 npc_update_entry(rvu, NPC_DMAC, &mdata, ether_addr_to_u64(pfvf->mac_addr), 0, --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ABA0378D98; Mon, 20 Apr 2026 02:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652542; cv=none; b=POeYORFN9lcsUYAy1YncavFt8blyMtQ2VfaCzq2FONulLDb3y59G2m0zIq8ZJM3/tupvW7SIbWc8Hj4Js0kIjejJ33T6XGZS6/q03nVCiHsc1b50nd8wdicNXbnFKK1fQ9voDmo7uon+KC7R9p8voZN7lanapqmJq8/d9RQmGBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652542; c=relaxed/simple; bh=IZ2hBW4Bo+GoLShx0jd516Ciam03WnWE2BZj7aa7U/c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mVCwwJBnTrUOh5fPm6Y8JOrTOe8sHNdl67JIBXgSxuRXz3ZTARhasGP04wKzVjwMR0NQMlR8VGriifwdYwjajnZiqMJlz8qAbz8pdKLRLEI3TM4TMmoF48pIBl/OUUtRo2uQR0thVtsCV1wJtan2A9SmzLXOZqmkZCw1B4TgfH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=Z2miBqlu; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="Z2miBqlu" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JJg1jd1882585; Sun, 19 Apr 2026 19:35:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=O Y6zj6dIb+/s9m3Kq874+RzZ1yvcw6vlIyoIaBodjWs=; b=Z2miBqlu995GTPo95 R19Nm9j9HQiYeWkOcuskh/vIEvxRKCTI3MlaMsifbCgqCDiiRRE/Jb+Un2MFkEsW jz2IDch8oRLIbDIfQYyrQZbvtadBIa8gwuqUf7U3AlEGUIj7uzCOdIOMqECn9QAY 0rqYLowlZEmUew0D9N5FfDLVMOrvwNYaLEPKJYYVvgsX+OKDanf298ThzRaGydx6 jbAXS4tDn0bTl4ztr3fHGTlQsnJ6i71mSG5ustuYJGqb4gl4oH1rFceWGA47LHct 6SqDsoj8Ukmv8az+W8Q9uVTDitqwavFyTgcpYAtThBmuZyC7c5zuk3pnGqmctDO2 6o93Q== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4dmx77h2n3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:10 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:09 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:09 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 1C5B73F7041; Sun, 19 Apr 2026 19:35:05 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Dan Carpenter" , Simon Horman Subject: [PATCH v2 net 02/11] octeontx2-af: npc: cn20k: Drop debugfs_create_file() error checks in init Date: Mon, 20 Apr 2026 08:04:33 +0530 Message-ID: <20260420023442.3295891-3-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX97hnm0faECvU Lk9sxOrhywnxDFwuPU03Y0a1XtvBEr+GqydgzMwokw3/6dt0q1p3zBIoK4c1mQuntLxg35YHbma tnssFqrhKqhoKQKsldUZYbW6KRF7LEWKQtpj6o0T5E8diFD+SbxRjQmDcIXokYjs2jYbHDU0YB7 e4CUCjsnQ92nbeSWpaEPiqr81++NtGYdCtKuU8L3TZG1IOW09nAyRohYrgAPaK/JaiOIzehEh8/ eF2KabHb3xxuref4UN1CvS8NDNiWkWpCa/IVSCpOxsbJYvE+/9AlyHysYkag6bXdP98eNJB43J0 WKE1Uf14T/D4pklACrA1osohS4pAVlNcIWS9zWEpTG9EvjBjSndd7NtZRpCIvPdqHwPmZSA/Eq7 FsO53561UNVmqcfpanuKxyMwt89837KunJLIZSQu0I3GalqWSFE3TpzVG6VMf2Gret7cusmBFHt 8Q3L9FP+h/WOL92oiBg== X-Proofpoint-GUID: sVbBgjIBeL8MFptzV07m8rPu_PsAcTWN X-Authority-Analysis: v=2.4 cv=P4IKQCAu c=1 sm=1 tr=0 ts=69e590de cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=TtqV-g6YmW1Jfm2GSLaY:22 a=5dRrolKJAAAA:8 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=M5GUcnROAAAA:8 a=m_5JYv9Gamu-D5dMTTYA:9 a=y3-2bcJ53AEkEa81XYCb:22 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: sVbBgjIBeL8MFptzV07m8rPu_PsAcTWN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" debugfs 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-s= upposed-to-be-checked/ Cc: Dan Carpenter Fixes: 528530dff56b ("octeontx2-af: npc: cn20k: add debugfs support") Link: https://lore.kernel.org/netdev/adjNGPWKMOk3KgWL@stanley.mountain/ Reviewed-by: Simon Horman Signed-off-by: Ratheesh Kannoth --- .../marvell/octeontx2/af/cn20k/debugfs.c | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c b/dr= ivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c index 3debf2fae1a4..6f13296303cb 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c @@ -249,34 +249,21 @@ DEFINE_SHOW_ATTRIBUTE(npc_defrag); int npc_cn20k_debugfs_init(struct rvu *rvu) { struct npc_priv_t *npc_priv =3D npc_priv_get(); - struct dentry *npc_dentry; =20 - npc_dentry =3D 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); =20 - if (!npc_dentry) - return -EFAULT; + debugfs_create_file("mcam_default", 0444, rvu->rvu_dbg.npc, + rvu, &npc_mcam_default_fops); =20 - npc_dentry =3D 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); =20 - if (!npc_dentry) - return -EFAULT; + debugfs_create_file("idx2vidx", 0444, rvu->rvu_dbg.npc, + npc_priv, &npc_idx2vidx_map_fops); =20 - npc_dentry =3D debugfs_create_file("vidx2idx", 0444, rvu->rvu_dbg.npc, - npc_priv, &npc_vidx2idx_map_fops); - if (!npc_dentry) - return -EFAULT; - - npc_dentry =3D debugfs_create_file("idx2vidx", 0444, rvu->rvu_dbg.npc, - npc_priv, &npc_idx2vidx_map_fops); - if (!npc_dentry) - return -EFAULT; - - npc_dentry =3D 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); =20 return 0; } --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60BA5378D8A; Mon, 20 Apr 2026 02:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652531; cv=none; b=MV9lIjwYeeXxqP36bD6fq0oPCujLVwD1TOUnKHG2d/F42b0VCC2Ub1X6vM/sy0FrkkEknsC3buvCtir1VopAr6OlDC2Cl2QKaORIb/8zKgGjeEhni6qHhLsGVYL5xvi8SrMANTGyj5jK2jq1Ki0tTo7kCwskaSTAy1uqQXHuwjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652531; c=relaxed/simple; bh=71MicUOqIEmx1kfHQTkpfZrEBt7UhK3/C2DWxKhdNC4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JAQF3dLugCsmrVCD1mcrShZRJXk0Xq+7/G0dgur9S6W6assoztUSD6hpaDh4ojGaxJGPwgnDlJL7vSNIwe6fibIlhkfnED9Ep1xP7tEyMc2Yr6kJzQ1doUeyxhKHfuP0nkwEI06nXEFxFKKL5Qo6+Cyfmqa3HBacQu+hgRFmMgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=ZqXFC/yJ; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="ZqXFC/yJ" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JJg1je1882585; Sun, 19 Apr 2026 19:35:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=D 3uNmAOJwNLaHrFA1kwhDbQ9a+SapkNnL26Nhuoz/JA=; b=ZqXFC/yJbIAB64XbY eLr0hNzZiDeGPlVDpDdVB2bxUUuM68fnwjgJ+MaXwE5IMqilCuI10KvlXNm+bVNR g2UhA8LxIzFjPLwXcwvZA474bALwhrheZgqLJWHHmFv6Mh6HOzezuBBE84jUZN9m Zq3wo9ao3MgMvJIhKZytwfWz7MSARJ5VZxqnDRpH5mNKxvzUCe6E/lErLWSteRCd 7AM3RJaZuOpRF6/g5bDBrupB0j/4kc/M3SRZKHSJ/41R6XqRC40SQpQ+bUvJ8jCd BKqAceiNUTHhj+uGUZLkOqg6eroZ9Jl4VgKGnZsQwGmJqjIRoNmKYwWM/+W9MGv3 uoHPQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4dmx77h2n6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:14 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:14 -0700 Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:13 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:13 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 419AE3F7041; Sun, 19 Apr 2026 19:35:10 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Dan Carpenter" Subject: [PATCH v2 net 03/11] octeontx2-af: npc: cn20k: Propagate errors in defrag MCAM alloc rollback Date: Mon, 20 Apr 2026 08:04:34 +0530 Message-ID: <20260420023442.3295891-4-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX7IhAsxHv6/FS TPq8sMGKmuTGPx3wGtn7QvKsVxe03NR0xEjGX8AmxlQ1oQhbjmXwD35ZVNGsG0Z3LbySTHl/II6 6rCL3LhMBAtkjyk1V8mPSPJwmj3w4a4r5SE4EIjDZ5sxahAVzHdalu9PmwdK9qstzYNGRT4usks 1aHKv4zyNtJQWGh3XLzpWNIY1/ltFYPuL1KgVBDrxleqfj4FKPx2Y9tqT0lgQvtqs6p721gZHGt 9fAQ5JDQeA3xqiAuyfRr0C5/1EFfIqeHZW61nYjJ8pb5C3DLYaLLZ8khdEZ202fBaEFRA8u172K u/9WeC/eIxhW73p0Sa/uVavbOcjR+y6JdkT6OLnW/w4ne+Nc34ovxfSq6Ptc7trZ3onNEM0Q11h KnNrvZgrlearP4DSUvPWj4SEovZ621pQeJI4AFulm0c9Ep8qJICzU9+hPStUWnGeER7RcuKnzyR 640O7WFN0eD6VYbNPcA== X-Proofpoint-GUID: -fgZQvQlYuv-26PYTEYL6mZnze9-FpeQ X-Authority-Analysis: v=2.4 cv=P4IKQCAu c=1 sm=1 tr=0 ts=69e590e3 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=TtqV-g6YmW1Jfm2GSLaY:22 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=M5GUcnROAAAA:8 a=LeiQjOPAn9kEfegU1kYA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: -fgZQvQlYuv-26PYTEYL6mZnze9-FpeQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" 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 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. Cc: Dan Carpenter Fixes: 645c6e3c1999 ("octeontx2-af: npc: cn20k: virtual index support") Link: https://lore.kernel.org/netdev/adjNJEpILRZATB2N@stanley.mountain/ Signed-off-by: Ratheesh Kannoth Reviewed-by: Simon Horman --- .../net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 18d70f4527d1..7f897ce0d17d 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -3502,7 +3502,7 @@ static int npc_defrag_alloc_free_slots(struct rvu *rv= u, { int alloc_cnt1, alloc_cnt2; struct npc_subbank *sb; - int rc, sb_off, i; + int rc, sb_off, i, err; bool deleted; =20 sb =3D &npc_priv.sb[f->idx]; @@ -3516,6 +3516,9 @@ static int npc_defrag_alloc_free_slots(struct rvu *rv= u, NPC_MCAM_LOWER_PRIO, false, cnt, save, cnt, true, &alloc_cnt1); + if (rc) + goto fail_free_alloc; + if (alloc_cnt1 < cnt) { rc =3D __npc_subbank_alloc(rvu, sb, NPC_MCAM_KEY_X2, sb->b1b, @@ -3525,21 +3528,25 @@ static int npc_defrag_alloc_free_slots(struct rvu *= rvu, save + alloc_cnt1, cnt - alloc_cnt1, true, &alloc_cnt2); + if (rc) + goto fail_free_alloc; } =20 if (alloc_cnt1 + alloc_cnt2 !=3D cnt) { dev_err(rvu->dev, "%s: Failed to alloc cnt=3D%u alloc_cnt1=3D%u alloc_cnt2=3D%u\n", __func__, cnt, alloc_cnt1, alloc_cnt2); + rc =3D -ENOSPC; goto fail_free_alloc; } + return 0; =20 fail_free_alloc: for (i =3D 0; i < alloc_cnt1 + alloc_cnt2; i++) { - rc =3D npc_mcam_idx_2_subbank_idx(rvu, save[i], - &sb, &sb_off); - if (rc) { + err =3D 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=3D%u\n", __func__, save[i]); --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3375637646A; Mon, 20 Apr 2026 02:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652528; cv=none; b=EzrUPox3Pxt30cweupQKxkaoWhCz/3FIk0rijihspjL67XtDJ+3nb6fMuvW3oWoKM65hUNio3aZpjmggcANXEbehH/am62H5MaTGlbm+1Ex1kH22h5ElYijwjvHj5iA+vMu9gG/JgL2W+KI3Q/251jIZ7WBlZyfc3pF8Dche9Fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652528; c=relaxed/simple; bh=pW2HzN4jUDd1SvgdLtt4bsZPsoB7pozh5KTsE4cWUlo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lU8MEAkS0GbMadl3CzFLawD8fWVeyvPkEbcKzXL9jQm659hYB7YYu/96eIl2/EtwCoKiKKwi4pT9LY/NdN2G7Dp/QsZoDtxauceRt+FBum5Pj9ppriChchUuU+mR+IVOdTAQuDbs2DBsunXfcFB3vD/FyscpwieROy8JIvmAC9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=f1MLquuA; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="f1MLquuA" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63K2IBL62058384; Sun, 19 Apr 2026 19:35:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=D EwavZX32cPfEwF4eXygQxYwSYVGjeJIWQmV073ewF8=; b=f1MLquuAx9C+n+d2o VcRicV/G4G4jGEnUitxsSFYw4hfjTmnnuer2Jv+fA9Y3ncWttW5Ya1N9Mciw9Qr+ A3bg7nsqZY4NYPVL0xADjQUh9jrIhCWUkROXJMmIqeZ7mURjVOx/I80b3c6ehoUb wM644zFcpAcaQSu6r/Nx9ZRe83MEqQta50NOWhpvm5wnEKeeA1aRtNSO9vOHNMmr gyHeLFiAse1CP07Bc4i1I5pJUvhqHI5lgY6xO0nDIn9ocYCPulv1Uatero+7PCBY q/adRQPoqv0juMWHhwq/hXa8rXgkywTucgUIobrVi78G/7+OfxHLDUp/F1kNaGtj iR9Ww== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dnb8180qv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:18 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:17 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:17 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 25EC83F7041; Sun, 19 Apr 2026 19:35:13 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth Subject: [PATCH v2 net 04/11] octeontx2-af: npc: cn20k: Make default entries as x4. Date: Mon, 20 Apr 2026 08:04:35 +0530 Message-ID: <20260420023442.3295891-5-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX+73s8z8ycKW4 CJE0UPWNfcleeEGZqjgyUHB/8+PBvR18v3R2WvV8wlHF1cqV3nokSHcE4JmyihqzYokHCNVw/tN vrroF3d0rkg/7SzGG76psa2V0FdhKVTatE8Qw8qJZGPteLSOSpBUa3BtRBRV385N2SkSxfccne+ /k658VqZyQd/IvAUrK3pIsks6BA6it4kTtVI5WWy+DQc7qJM+rUnWs43QDGGOhHLVCnQWDRNu8T XaKMtVFskuvJ/0hPHRYkyTXmrmX+p0yVnfKqhm8ODNFfUT1Fie27P26118o1nFcmAZAMps1ABCz B5tfNWG2gSXA2K7nh5DozfOpLyP2+niFOzY4HjwTypCzTZBQqqOFsgQ+eLBLDWdwLsJtotYcdJK xmFCawvk274wuwWMYvW1w/29At3YaCuv9QCPIHlfq2gu3rwbwpdq6lC5L+SG4sZCGV1/PbCL/i3 Uek0hmm/rUd3wl2pNXQ== X-Proofpoint-GUID: cn1dlEDK9aqv5afqxfaaN1WbPFqGKfQ5 X-Authority-Analysis: v=2.4 cv=W6wIkxWk c=1 sm=1 tr=0 ts=69e590e6 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=qit2iCtTFQkLgVSMPQTB:22 a=M5GUcnROAAAA:8 a=F9p9qQeY_ntdmK6_khkA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: cn1dlEDK9aqv5afqxfaaN1WbPFqGKfQ5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" X4 profile users won't alloc x2 entries. Allocating x2 entries would cause under utilized subbanks(X2). Avoid this in X4 kex profile, all allocations will be from x4 subbank. Fixes: 09d3b7a1403f ("octeontx2-af: npc: cn20k: Allocate default MCAM index= es") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 26 ++++++++-- .../marvell/octeontx2/nic/otx2_flows.c | 48 +++++++++++++------ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 7f897ce0d17d..108998b6d832 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -3592,9 +3592,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 =3D &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; @@ -3713,8 +3714,21 @@ int npc_defrag_move_vdx_to_free(struct rvu *rvu, mcam->entry2pfvf_map[new_midx] =3D pcifunc; /* Counter is not preserved */ mcam->entry2cntr_map[new_midx] =3D new_midx; + + target_pf =3D mcam->entry2target_pffunc[old_midx]; + mcam->entry2target_pffunc[new_midx] =3D target_pf; + mcam->entry2target_pffunc[old_midx] =3D 0; + npc_mcam_set_bit(mcam, new_midx); =20 + list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) { + if (rule->entry !=3D old_midx) + continue; + + rule->entry =3D new_midx; + break; + } + /* Mark as invalid */ v->vidx[vidx_cnt - i - 1] =3D -1; save[cnt - i - 1] =3D -1; @@ -4277,10 +4291,16 @@ int npc_cn20k_dft_rules_alloc(struct rvu *rvu, u16 = pcifunc) pfvf =3D rvu_get_pfvf(rvu, pcifunc); pfvf->hw_prio =3D NPC_DFT_RULE_PRIO; =20 + if (npc_priv.kw =3D=3D NPC_MCAM_KEY_X4) { + req.kw_type =3D NPC_MCAM_KEY_X4; + req.ref_entry =3D eidx & (npc_priv.bank_depth - 1); + } else { + req.kw_type =3D NPC_MCAM_KEY_X2; + req.ref_entry =3D eidx; + } + req.contig =3D false; req.ref_prio =3D NPC_MCAM_HIGHER_PRIO; - req.ref_entry =3D eidx; - req.kw_type =3D NPC_MCAM_KEY_X2; req.count =3D cnt; req.hdr.pcifunc =3D pcifunc; =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/driv= ers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c index 38cc539d724d..5dd0591fed99 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c @@ -37,14 +37,13 @@ static void otx2_clear_ntuple_flow_info(struct otx2_nic= *pfvf, struct otx2_flow_ flow_cfg->max_flows =3D 0; } =20 -static int otx2_mcam_pfl_info_get(struct otx2_nic *pfvf, bool *is_x2, - u16 *x4_slots) +static int otx2_mcam_pfl_info_get(struct otx2_nic *pfvf, u16 *x4_slots, u8= *kw_type) { struct npc_get_pfl_info_rsp *rsp; struct msg_req *req; static struct { bool is_set; - bool is_x2; + u8 kw_type; u16 x4_slots; } pfl_info; =20 @@ -53,8 +52,8 @@ static int otx2_mcam_pfl_info_get(struct otx2_nic *pfvf, = bool *is_x2, */ mutex_lock(&pfvf->mbox.lock); if (pfl_info.is_set) { - *is_x2 =3D pfl_info.is_x2; *x4_slots =3D pfl_info.x4_slots; + *kw_type =3D pfl_info.kw_type; mutex_unlock(&pfvf->mbox.lock); return 0; } @@ -79,16 +78,16 @@ static int otx2_mcam_pfl_info_get(struct otx2_nic *pfvf= , bool *is_x2, return -EFAULT; } =20 - *is_x2 =3D (rsp->kw_type =3D=3D NPC_MCAM_KEY_X2); - if (*is_x2) - *x4_slots =3D 0; + pfl_info.kw_type =3D rsp->kw_type; + if (rsp->kw_type =3D=3D NPC_MCAM_KEY_X2) + pfl_info.x4_slots =3D 0; else - *x4_slots =3D rsp->x4_slots; - - pfl_info.is_x2 =3D *is_x2; - pfl_info.x4_slots =3D *x4_slots; + pfl_info.x4_slots =3D rsp->x4_slots; pfl_info.is_set =3D true; =20 + *x4_slots =3D pfl_info.x4_slots; + *kw_type =3D pfl_info.kw_type; + mutex_unlock(&pfvf->mbox.lock); return 0; } @@ -164,6 +163,7 @@ int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 = count) u16 dft_idx =3D 0, x4_slots =3D 0; int ent, allocated =3D 0, ref; bool is_x2 =3D false; + u8 kw_type =3D 0; int rc; =20 /* Free current ones and allocate new ones with requested count */ @@ -182,12 +182,14 @@ int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u1= 6 count) } =20 if (is_cn20k(pfvf->pdev)) { - rc =3D otx2_mcam_pfl_info_get(pfvf, &is_x2, &x4_slots); + rc =3D otx2_mcam_pfl_info_get(pfvf, &x4_slots, &kw_type); if (rc) { netdev_err(pfvf->netdev, "Error to retrieve profile info\n"); return rc; } =20 + is_x2 =3D kw_type =3D=3D NPC_MCAM_KEY_X2; + rc =3D otx2_get_dft_rl_idx(pfvf, &dft_idx); if (rc) { netdev_err(pfvf->netdev, @@ -289,6 +291,8 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf) struct npc_mcam_alloc_entry_rsp *rsp; int vf_vlan_max_flows, count; int rc, ref, prio, ent; + u8 kw_type =3D 0; + u16 x4_slots; u16 dft_idx; =20 ref =3D 0; @@ -315,6 +319,16 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf) if (!flow_cfg->def_ent) return -ENOMEM; =20 + kw_type =3D NPC_MCAM_KEY_X2; + if (is_cn20k(pfvf->pdev)) { + rc =3D otx2_mcam_pfl_info_get(pfvf, &x4_slots, &kw_type); + if (rc) { + netdev_err(pfvf->netdev, + "Error to get pfl info\n"); + return rc; + } + } + mutex_lock(&pfvf->mbox.lock); =20 req =3D otx2_mbox_alloc_msg_npc_mcam_alloc_entry(&pfvf->mbox); @@ -324,6 +338,10 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf) } =20 req->kw_type =3D NPC_MCAM_KEY_X2; + if (is_cn20k(pfvf->pdev) && kw_type =3D=3D NPC_MCAM_KEY_X4) { + req->kw_type =3D NPC_MCAM_KEY_X4; + ref &=3D (x4_slots - 1); + } req->contig =3D false; req->count =3D count; req->ref_prio =3D prio; @@ -1174,15 +1192,14 @@ static int otx2_add_flow_msg(struct otx2_nic *pfvf,= struct otx2_flow *flow) #ifdef CONFIG_DCB int vlan_prio, qidx, pfc_rule =3D 0; #endif + bool modify =3D false, is_x2; int err, vf =3D 0, off, sz; - bool modify =3D false; u8 kw_type =3D 0; u8 *src, *dst; u16 x4_slots; - bool is_x2; =20 if (is_cn20k(pfvf->pdev)) { - err =3D otx2_mcam_pfl_info_get(pfvf, &is_x2, &x4_slots); + err =3D otx2_mcam_pfl_info_get(pfvf, &x4_slots, &kw_type); if (err) { netdev_err(pfvf->netdev, "Error to retrieve NPC profile info, pcifunc=3D%#x\n", @@ -1190,6 +1207,7 @@ static int otx2_add_flow_msg(struct otx2_nic *pfvf, s= truct otx2_flow *flow) return -EFAULT; } =20 + is_x2 =3D kw_type =3D=3D NPC_MCAM_KEY_X2; if (!is_x2) { err =3D otx2_prepare_flow_request(&flow->flow_spec, &treq); --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0C33783DE; Mon, 20 Apr 2026 02:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652536; cv=none; b=Grjv1G+zG2TGwtPdoQ7jS/6vQSOt7DfLc/5P1q0HB+WkNa4QQIGxXx549YGdgZ6gYcEqGzes53C1BTVmdHykAyk2PdM23lQFyqJGwjx29tzQcWT9OsZGufWhaKVOcitgs24U6FH3xU4dR23VQ7JJRuUS2iTjINSDy49t9srsrMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652536; c=relaxed/simple; bh=OtXu/bK0ftEHAn0OEWl0qk4cZsT3peqlIN6xob/pg2k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B5ri4DUj2DQh5fqnaL9UJxBdNxRYEvJxZNMSkVThSD2DsDUdK+n63M/nLqjEjL48XOncU16icgTacXEE4GJ1kFC+qhZHOhj9GyS1Zj2mLImkyGMLfQeifyU+Tfu+qlhamYx/R7noXp3t+F5VHgesg1sGZORhaMxnYFTpgscLfLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=HKF+aP0n; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="HKF+aP0n" Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JLIoXU614622; Sun, 19 Apr 2026 19:35:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=2 SvlWovSVWRpK+1xDn5vLWcz+oFHujdvo/WaEaavjwg=; b=HKF+aP0n5TQLfrSUY fSKLe4NhnjQDNOgYwOSc/nKm9CWYJfConxxgxSlE8x2gxjRcFN65HthU6QWk+glQ fO0YecuJlxkAhPgibc8V8vlPXheFsemekrorxXEnNneDoecP3QMhadNn9jBG3OMP 8FRfWHurwvTwSGeDQa+LVYfD1ODiOHP0TW1l1qwlZuGZ1a6UTWQ1M6buse3hEIdU Gs55RV/iR7CGqTe7Ui5l11khKrvDedT2BujA1284ESeXONQUUO3zYJvwdH7awP1A /+2aoeANKmuVDJfdhfJy7wAEdTCYKC/mdsEdCIpPcEu53wXg0M7fn/YVWXljcPGx TJm4Q== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dm9fgjj69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:22 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:20 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:20 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id C0FF53F7041; Sun, 19 Apr 2026 19:35:17 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth Subject: [PATCH v2 net 05/11] octeontx2-af: npc: cn20k: Reject request for x4 entries in x2 profile. Date: Mon, 20 Apr 2026 08:04:36 +0530 Message-ID: <20260420023442.3295891-6-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: o5EjJFMqQ1u6MAR3g9Vupg4OVYhRY-BD X-Authority-Analysis: v=2.4 cv=TYSmcxQh c=1 sm=1 tr=0 ts=69e590ea cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=QXcCYyLzdtTjyudCfB6f:22 a=M5GUcnROAAAA:8 a=ng8EnHo8p987gso5S4sA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX6IERT9RW9qYx jZ5GDamtmdXp/L5nm1Pop4qeR2ApLs37dYNCm7fJvGTOsvY3fijyfd1xIPTYxN9+I4SxeDkVjdb gi5DQV8BepqwyJhVJF/yG+gx+lBqoQEdESfopwPmp7m9feD+t18RAOEqyE8WxmavXAnHSRgninY zPswyR+9OHbSgHTJ0g++fZd6eOCUBAjg6w7Sl48hNo5aIN3fb0npCG58t6BLjx7LBaTk6XG+5sO eMc9RspPpezps79eSAC1rGmajpOUW+hkoHO51jjn6r/vY1FLDq5Ff+YozU/YEYXJpkWlM27PdtF Z7hOJ7FwfuDfPW12Py/qA8+nL8Nf+baVBzuQUjnNNylIkGnTK0aMqyzJxl3Udcdu1CclIPwQRTm +joIqU72j3YPrs2vwBOEz/sV3yntYJHfv+CH/65AimJUmm31GCBdN/pNfHOsMWGpmedBOfGp/CY ZQI4HK0LasFQHC2WyGw== X-Proofpoint-ORIG-GUID: o5EjJFMqQ1u6MAR3g9Vupg4OVYhRY-BD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" Flow install mbox can alloc x2/x4 npc mcam entry based on the flow entry size. If global kex profile is x2, x4 entries won't work. Return error upon request for x4 entry in x2 profile. Fixes: 9000cada7aa9 ("octeontx2-af: npc: cn20k: Allocate MCAM entry for flo= w installation") Signed-off-by: Ratheesh Kannoth --- .../net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 10 ++++++++-- .../net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 108998b6d832..705fe7a877e6 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -4330,11 +4330,17 @@ int npc_cn20k_dft_rules_alloc(struct rvu *rvu, u16 = pcifunc) * as NPC_DFT_RULE_PRIO - 1 (higher hw priority) */ req.contig =3D false; - req.kw_type =3D NPC_MCAM_KEY_X2; req.count =3D cnt; req.hdr.pcifunc =3D pcifunc; req.ref_prio =3D NPC_MCAM_LOWER_PRIO; - req.ref_entry =3D eidx + 1; + if (npc_priv.kw =3D=3D NPC_MCAM_KEY_X4) { + req.kw_type =3D NPC_MCAM_KEY_X4; + req.ref_entry =3D (eidx + 1) & (npc_priv.bank_depth - 1); + } else { + req.kw_type =3D NPC_MCAM_KEY_X2; + req.ref_entry =3D eidx + 1; + } + ret =3D rvu_mbox_handler_npc_mcam_alloc_entry(rvu, &req, &rsp); if (ret) { dev_err(rvu->dev, diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c b/drive= rs/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c index bd1488fe1611..d8945823e202 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c @@ -1663,9 +1663,11 @@ rvu_npc_alloc_entry_for_flow_install(struct rvu *rvu, { struct npc_mcam_alloc_entry_req entry_req; struct npc_mcam_alloc_entry_rsp entry_rsp; + struct npc_get_pfl_info_rsp rsp =3D { 0 }; struct npc_get_num_kws_req kws_req; struct npc_get_num_kws_rsp kws_rsp; int off, kw_bits, rc; + struct msg_req req; u8 *src, *dst; =20 if (!is_cn20k(rvu->pdev)) { @@ -1689,8 +1691,16 @@ rvu_npc_alloc_entry_for_flow_install(struct rvu *rvu, kw_bits =3D kws_rsp.kws * 64; =20 *kw_type =3D NPC_MCAM_KEY_X2; - if (kw_bits > 256) + if (kw_bits > 256) { + rvu_mbox_handler_npc_get_pfl_info(rvu, &req, &rsp); + if (rsp.kw_type =3D=3D NPC_MCAM_KEY_X2) { + dev_err(rvu->dev, + "Only X2 entries are supported in X2 profile\n"); + return -EOPNOTSUPP; + } + *kw_type =3D NPC_MCAM_KEY_X4; + } =20 memset(&entry_req, 0, sizeof(entry_req)); memset(&entry_rsp, 0, sizeof(entry_rsp)); --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BAC337881D; Mon, 20 Apr 2026 02:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; cv=none; b=nOLXtA3iQhVU3I4l43AWrbZ0JDWh+XRSuEn1/PH4rDts4nU+yn04E/jrRXIQqOZo+6gzJoXIWWliFklGuzpUXBQKscghpMrfysLz+BYD6rjHqMP9Gpy4ZgBP6DWzD/92aIrCiQcRkvtvoTejAUJYgeWfYsPBN5ylNUl42jLCKJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; c=relaxed/simple; bh=nYEcYNZJoUw3wy4NlQppXqao/5vo/lVMyHqT7uOXo+8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XmI4hzl5i3I5jwR1N8rM6jzReF4euxg4or5FmKWkPTgx4gSVMDLQoCVPmQyhuxaFpOMASek/OqvI842qz0rUvqvycnIr+f2Xgk9QHhr/OYkEXm6IrIZr4LlaE34r074mAjPzSCHG+yUS7GRXVAM4TECSl9G017HHp9KZWMJUfLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=Ugv1e4xb; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="Ugv1e4xb" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63K2IU2e2059171; Sun, 19 Apr 2026 19:35:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=+ iVIdVllkSLKyLa67P0D6uPYv24IsN7s9waK3UooU0M=; b=Ugv1e4xbXfeAwY3iU y93furGC36AcQosY+4PawBO7/fZM/V9X2W2FonmYJDqBXoWpHvAQ8LxItR/iE3SG /L2goV+a6qrC17+/l7cHx/M1/VVgj6DcE3XcOWTEyP/q3LYOn/iAMFi7b/MJAu47 9IY45+eVUglFAzcerTPjXkD/mbLo/0ZW9HRki2e28RaMzh3+bKzzQcOky7HhWGHW ax509HvoYYMWJe31F/mUvNwggeFtyUSvy5R1nUpKaY8O+axS+Ru3xklOU6yiBUUl nPCD5g4Vdvg9kjmK7u13KUiP/fLPCfkOfA8ivqAvYhe2c07omVI97iwQ5gZFxJIx Fm7TQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dnb8180qx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:26 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:25 -0700 Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:25 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:24 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 66E773F7041; Sun, 19 Apr 2026 19:35:21 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Suman Ghosh" Subject: [PATCH v2 net 06/11] octeontx2-af: npc: cn20k: Clear MCAM entries by index and key width Date: Mon, 20 Apr 2026 08:04:37 +0530 Message-ID: <20260420023442.3295891-7-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX42SmV2NFeKzC uNwqSnB4U21snqCrO1WEtb2HCFGj+nyFeG89Tn7TWjTEgEI4zvdmtm8q4eHU722GTHHtcAF9bHF xVFW3v7AyRt7B9Ag0eAcXvrqDFkM6vU7ROz4NHLgiy8WAddWe2JhbiRwiYQr1MD/JYpvVs6KhfA NphNSKMfvVxAf3nW6XZCcsWeRPIXh4eru80iET+jji+R+7KU4SdA6c0sl+xoIgTMban6kP7rzHV NJzcqBy49p9lnN0Ms/jYKDyMCAkwiam17fLmn+LmMzV+iuY9YF4qMGIfIn4nhSDbxzmvtFdVgwU icwHie6EmpsjYantov8vK46dNeDVu11v/rP/eM0zCeAJYIBOrCy8HP/GdNpmUKaGhHLBkJByFEn V19gRD7Kr+ZMvbnrMapBG0CyGzvvAoc5gCJbIzlbaFjuhnWedMQwsxF9tKBETCQ5NAnpbRDfBXL otLWnBnBbVB2kIuLsDg== X-Proofpoint-GUID: 9vHG2z_KGvXy-FfsxkAAmSKV0n86UuAz X-Authority-Analysis: v=2.4 cv=W6wIkxWk c=1 sm=1 tr=0 ts=69e590ee cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=qit2iCtTFQkLgVSMPQTB:22 a=M5GUcnROAAAA:8 a=MjTODloqs2dhJEbYUhsA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: 9vHG2z_KGvXy-FfsxkAAmSKV0n86UuAz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" 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 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. Cc: Suman Ghosh Fixes: 6d1e70282f76 ("octeontx2-af: npc: cn20k: Use common APIs") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 36 ++++++++++++++++--- .../ethernet/marvell/octeontx2/af/cn20k/npc.h | 3 +- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 17 +++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 705fe7a877e6..7bfd39fe0f5e 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -842,8 +842,8 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkadd= r, return 0; } =20 -void -npc_cn20k_clear_mcam_entry(struct rvu *rvu, int blkaddr, int bank, int ind= ex) +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,32 @@ npc_cn20k_clear_mcam_entry(struct rvu *rvu, int blkadd= r, int bank, int index) NPC_AF_CN20K_MCAMEX_BANKX_STAT_EXT(index, bank), 0); } =20 +int +npc_cn20k_clear_mcam_entry(struct rvu *rvu, int blkaddr, int mcam_idx) +{ + struct npc_mcam *mcam =3D &rvu->hw->mcam; + int bank =3D npc_get_bank(mcam, mcam_idx); + u8 kw_type, index; + + if (npc_mcam_idx_2_key_type(rvu, mcam_idx, &kw_type)) + return -EINVAL; + + index =3D mcam_idx & (mcam->banksize - 1); + + if (kw_type =3D=3D 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 =3D 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 +1097,7 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int = blkaddr, int index, */ if (kw_type =3D=3D 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 +1122,8 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int = blkaddr, int index, } =20 /* 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); =20 npc_cn20k_config_kw_x4(rvu, mcam, blkaddr, mcam_idx, intf, entry, diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.h index 8f3eea9cfb1d..2f761b97f91b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.h @@ -330,8 +330,7 @@ int npc_cn20k_copy_mcam_entry(struct rvu *rvu, int blka= ddr, 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); diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_npc.c index 762fafd4ccb7..0a2191fda614 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -259,6 +259,13 @@ static void npc_clear_mcam_entry(struct rvu *rvu, stru= ct npc_mcam *mcam, int bank =3D npc_get_bank(mcam, index); int actbank =3D bank; =20 + if (is_cn20k(rvu->pdev)) { + if (npc_cn20k_clear_mcam_entry(rvu, blkaddr, index)) + dev_err(rvu->dev, "%s Failed to enable mcam %u\n", + __func__, index); + return; + } + index &=3D (mcam->banksize - 1); for (; bank < (actbank + mcam->banks_per_entry); bank++) { rvu_write64(rvu, blkaddr, @@ -753,9 +760,15 @@ void rvu_npc_install_promisc_entry(struct rvu *rvu, u1= 6 pcifunc, =20 /* 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 =3D npc_get_nixlf_mcam_index(mcam, pcifunc, - nixlf, NIXLF_UCAST_ENTRY); + if (is_lbk_vf(rvu, pcifunc)) + ucast_idx =3D index; + else + ucast_idx =3D npc_get_nixlf_mcam_index(mcam, pcifunc, + nixlf, NIXLF_UCAST_ENTRY); + if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx)) *(u64 *)&action =3D npc_get_mcam_action(rvu, mcam, blkaddr, ucast_idx); --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BA1837880E; Mon, 20 Apr 2026 02:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; cv=none; b=T3JonVj9sd6i+sjap1ztfAsEWTTbzvLqogYsG9Onv9/HoovOQ3TbSSTFvrNkwh/WQ5rHlsA9bdfUWHRpHzARy7+AR5zaePK1EacPpSSGLi0GMBYxwXzP6xv8DnvY14cozIyGozqvmFmmlGO2pnYC603xomA75mlKqBpi0pp9v00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; c=relaxed/simple; bh=huiiG6KBGsqerQOD7ZMxlGMUB5OmWx4c9+pyIt9I2SI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UfLb19NYf7pyIjxmCQJGLSRzN3yYKRkOZTDZPIehCcycVfrkBb/SPB1jGQrtDCZaEvOhitXOi9RnuRFLqPJStd8/vw5WH9bZewYeab0qvcHLmofHct+laB715Kp3hj75LX5lEH2IszUvNYIuDGITs8JPG4qbcKSpkYyQ/80qSuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=hCEKLunN; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="hCEKLunN" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63K2IUKj2059144; Sun, 19 Apr 2026 19:35:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=P e73ZqMfYyUzG+fAE0V2ZH0QqqOR5rLFh53/YXXBvF8=; b=hCEKLunNPrT4VCj0L dNeW27KFidLykDKz8Ko6rwLk4PGYJ/pzfyJt/LYzmzz576tMjlwwBXG1hXzI4N/c Jdo5L/FGCpHEsgUfRZKWIXClSuKGZB7T1EgNDLhpcHHMRa3V3j/o9M/IRint+S0R ctr6SnoukEcQT3JVCyxQCaiZXtmqmhIv1eXVBp4REaNYp6jFSH2iCaqQ3PHvky8y QODhg26Dm+pOu7Tb2g/mw2OvxbxROoTHgsJ8XpOk/eYkqXTBduy8Isa1BRkVo/Ob slnlwqYKdv09pTLP8dHJPVWnVTBxLsFJNPVbbtICi8C7bWhieAIwvTMZM+/5iUvV ex+5g== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dnb8180r1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:29 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:28 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:28 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 4AED03F7041; Sun, 19 Apr 2026 19:35:25 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Suman Ghosh" Subject: [PATCH v2 net 07/11] octeontx2-af: npc: cn20k: Fix bank value. Date: Mon, 20 Apr 2026 08:04:38 +0530 Message-ID: <20260420023442.3295891-8-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfXyH/EI/JC99Yj u/X/vmKUmIUQ5O0bKPF/BrsMtVGwF82MHz5/Zt36Y8AHGqDQSYWPD5KcG6LqbIxGJr/UrXGiO4r 0EMClrVlsoWVr6qoJ93QUYogXboMwbyEzpmVoNLAiBWs/vKf2c3cwSO4LRQsQ6+uEwWgf9scmgn 3I2zVVLYN1nm/xO48ZFRCUExFmicnbtliQd960ZykFK8Ycu7rzW1dNs+bDoKOc03w4vl/sy3Kjc vw0GuqfW6ovI+WBye+coT7L9GPQZy4d1vP4OYKMziuhdQXav66iFf3GeYBNU0CzKxDEfvLf9Lgk 8MaQbKbQOXmu0rRBSEpqh1jwhM9mHqxI6/Ds+LJIi51W6wnyAxxW5+34RYjmvGnz5WsejhM+gjo 5Pz3LIaBe0vBWQvnyGyPmjMxSXGEH8UOhB1RDAiwTS98aKHdy6e07dHoTC4BqkZqnIF9q8scxCI UkrGA3KBLrTZduQoGyA== X-Proofpoint-GUID: OfNnNOwptTjfi8-vWJvUlWGRzoolp6Lb X-Authority-Analysis: v=2.4 cv=W6wIkxWk c=1 sm=1 tr=0 ts=69e590f1 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=qit2iCtTFQkLgVSMPQTB:22 a=M5GUcnROAAAA:8 a=1IUtMPC23dKFR1PEuaoA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: OfNnNOwptTjfi8-vWJvUlWGRzoolp6Lb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" or 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. Cc: Suman Ghosh Fixes: 4e527f1e5c15 ("octeontx2-af: npc: cn20k: Add new mailboxes for CN20K= silicon") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 92 ++++++++----------- 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 7bfd39fe0f5e..4b37d471f118 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -1044,34 +1044,6 @@ static void npc_cn20k_config_kw_x4(struct rvu *rvu, = struct npc_mcam *mcam, kw, req_kw_type); } =20 -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 =3D &rvu->hw->mcam; - u64 bank_cfg; - - bank_cfg =3D (u64)hw_prio << 24; - if (enable) - bank_cfg |=3D 0x1; - - if (kw_type =3D=3D 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 =3D 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) @@ -1079,6 +1051,7 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int = blkaddr, int index, struct npc_mcam *mcam =3D &rvu->hw->mcam; int mcam_idx =3D index % mcam->banksize; int bank =3D index / mcam->banksize; + u64 bank_cfg =3D (u64)hw_prio << 24; int kw =3D 0; u8 kw_type; =20 @@ -1118,41 +1091,50 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, in= t blkaddr, int index, NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(mcam_idx, bank, 1), entry->vtag_action); - goto set_cfg; - } =20 - /* 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 =3D 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); =20 - /* 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); =20 - /* 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 =3D 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); + } } =20 -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; =20 return 0; } --=20 2.43.0 From nobody Tue Jun 16 12:43:14 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3736C377EBA; Mon, 20 Apr 2026 02:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; cv=none; b=gklgW7zwlRdnPEUxSwXhtl+naI1jfgcvB+wn9fdsCBExquFdefG5ZZ8/4lhAtUUh2dPvl/NARdnmzaCQGp/Gmy+bArdGkBwgba9DiPmfd7siZLfLwILqOE1duJbUulXJbEOkX4+b0LRys+zK2Ub7WuKdJk3RArpQ1/bmcqmQJg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652543; c=relaxed/simple; bh=NFsobxYT1xORnMAa3ZvhAqTmIV4G/gbJKA2hr2yJh3I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KZt3iJfyaM+mnj98ajHp7s3CNZwkmO6zPXexRrtuRx4cUgc9AIv366ZINGL8Rmz4lPIxyGXw9Xnl0m5hcUF31Y51mwj9QotD5J7CaV5he2nLTNG/fiTZRP6O11V5au5MTEC8yeN2QthEmTiDxnp6a9rsUuI/s0SPa0LoEfb2zIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=EhMsKC6t; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="EhMsKC6t" Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JNBYmq814459; Sun, 19 Apr 2026 19:35:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=8 /GqIyqOA16yy+la+aqMrP/qeDZR17SITdIdAT5YyAg=; b=EhMsKC6tklnn2romH X8nLZkxmmKaSx1TiPZp8DHL7a2dUfBHDS2YFNMaFZfi+Wscq100OS15bG8c30qiY KP5W+T4C68mAxCDS/vTOvLmRZH4RPBt4mPeM/DdAfYinvQY1hTBxacbrZIfkkj1I gUDWUNdN3joaq/3KCIBLA4qKcjpAQYZTPb9pQxyctj2fheX3z6p6mM85VZZ1qtpH WlPlByhBY9F6BIbUGk4DcXydNeD906uu7S6pTBfphsdCJYD/VUWNt7//UHpZPDbJ zUhLzEz/yHCN2ZezIkchg0BgHosJdBNCe1bHsVOjLLGesZE7sx9Byu68e3Byv7MH q7QuQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dm9fgjj6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:34 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:33 -0700 Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:32 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 2FCF73F7041; Sun, 19 Apr 2026 19:35:28 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Suman Ghosh" Subject: [PATCH v2 net 08/11] octeontx2-af: npc: cn20k: Fix MCAM actions read Date: Mon, 20 Apr 2026 08:04:39 +0530 Message-ID: <20260420023442.3295891-9-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: sNWsMVBHO36bdNg92asFt5Hs_jmw4hdI X-Authority-Analysis: v=2.4 cv=TYSmcxQh c=1 sm=1 tr=0 ts=69e590f6 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=QXcCYyLzdtTjyudCfB6f:22 a=M5GUcnROAAAA:8 a=IbDIvz35LZQodz_KiiMA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX+zPw6J/+Kb5t lFy8jBr6hRyMOArLE7zbQXISV7uNRB37X/VH91iLDPa6hjWWJoFmBLjxBYazU3qV71pKVPqFMD+ hrg0fAoF4/S2/cgbA29R38F2Ol2rYTjtm+gf/W6AoZDoiNCtw+52Nyf6CqK8KsfBv6jqd14L1G2 2hsDh5mfDhkQr1to/ontJ2m5xksE4bErEkZ+O/wgUZyzBtV/kooMlC3KollZDNXZZ7NSk6j+D06 iYItLPGmBWWPmXXZQOa4Mk4Uu3bgwYLAVw1LgSLRAoYF9Q1T/kWBO93dHaLOkdsMJHSuLfBox3B N+Fultq/GowgFnOlkBXpDhdXfsadwNsg5ijrAN/OKw2gcE8v4Wa7NrSps0mZYCvXTCc98rTtLQT RjbvoIRswinqACV7ja5A7L1MDoj8H+JdFbnv+47fh655OTubY3X3NgEHUskRQG2ptvZsLnKbKbW utFAwaO9XvyMXiY1bXQ== X-Proofpoint-ORIG-GUID: sNWsMVBHO36bdNg92asFt5Hs_jmw4hdI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" npc_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. Cc: Suman Ghosh Fixes: 6d1e70282f76 ("octeontx2-af: npc: cn20k: Use common APIs") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 4b37d471f118..752dbcede90f 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -1218,6 +1218,14 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int b= lkaddr, u16 index, bank =3D npc_get_bank(mcam, index); index &=3D (mcam->banksize - 1); =20 + cfg =3D rvu_read64(rvu, blkaddr, + NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(index, bank, 0)); + entry->action =3D cfg; + + cfg =3D rvu_read64(rvu, blkaddr, + NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(index, bank, 1)); + entry->vtag_action =3D cfg; + cfg =3D rvu_read64(rvu, blkaddr, NPC_AF_CN20K_MCAMEX_BANKX_CAMX_INTF_EXT(index, bank, 1)) & 3; @@ -1267,7 +1275,7 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int bl= kaddr, u16 index, bank, 0)); npc_cn20k_fill_entryword(entry, kw + 3, cam0, cam1); - goto read_action; + return 0; } =20 for (bank =3D 0; bank < mcam->banks_per_entry; bank++, kw =3D kw + 4) { @@ -1312,18 +1320,6 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int b= lkaddr, u16 index, npc_cn20k_fill_entryword(entry, kw + 3, cam0, cam1); } =20 -read_action: - /* 'action' is set to same value for both bank '0' and '1'. - * Hence, reading bank '0' should be enough. - */ - cfg =3D rvu_read64(rvu, blkaddr, - NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(index, 0, 0)); - entry->action =3D cfg; - - cfg =3D rvu_read64(rvu, blkaddr, - NPC_AF_CN20K_MCAMEX_BANKX_ACTIONX_EXT(index, 0, 1)); - entry->vtag_action =3D cfg; - return 0; } =20 --=20 2.43.0 From nobody Tue Jun 16 12:43:15 2026 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90DA319F11B; Mon, 20 Apr 2026 02:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652547; cv=none; b=gsHO0aFrvt1q4oT34CuChSsKKPGdGYccpwXbaAb+Ek68e4/s6SDvOM0z9fpkzRyh61HfMyeM04MVc8/799ROwtwFQJ0g4KqPziH0W610US68Iqj/T//QyrHrj99E7cazlOLSLUVgKp/qVaI1CknDYIHL6ZlVqTzp+Xgb5dHuXkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652547; c=relaxed/simple; bh=bXbJ50rFUcbIasO1xX0zJRnkAC6bDqr9WbvInAZYxgM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JpkDqwlJhQJ6fBcqFzFLqzCTKZ/g9kGIlVxdH7b7UxwvpCcmR+hnKCQDInavpEDeV2AGwvg8ZcPn0d0vmdoE3iUYHC/+YNIyu94HfnFDY6dfpPNav8Ec0yXJVKLOKH+pwzqQxe5kP8CriO2JLRbKi66C+PqQLNLmKotWeLi7z8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=iXB7EH+d; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="iXB7EH+d" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JMfQXB2187676; Sun, 19 Apr 2026 19:35:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=K 64yxCKZ1tCxIC7h1IriReMi8/fzCDRdYMWcUSBl58o=; b=iXB7EH+dpGDWht4AQ VnVRUpREUTI2jEk0KOUFaSeqpnkz1Lzvmc61SmXD6aj0UcLm6wOluK9XxLCIZt5K 0N2UHV7+lVUKwMBjFkStueNRdKoAZH6c7/vm6RtSTmQ59h+GKnmod5gnvSuUie4m GFRY7xuJ2N5QEODJwKXiXseAizjsnM8pap3GtMTSkbZO57KWmZA9q4F/vk5/6jK9 ncQA+mYY4PBhrsEICA5ugPs9JHK6XBBKt9cuLrYyqOx+PIRgHMrI1yYFJRFYb+Zq ftHHuogXsbiPzeFvfciZ4ue8Zm7kmvENb/YcoFwilY1ZQeiTC28XoDPHpQxUrwMH JQHjw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4dmx77h2np-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:36 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:36 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:36 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id 153D13F7041; Sun, 19 Apr 2026 19:35:32 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth Subject: [PATCH v2 net 09/11] octeontx2-af: npc: cn20k: Initialize default-rule index outputs up front Date: Mon, 20 Apr 2026 08:04:40 +0530 Message-ID: <20260420023442.3295891-10-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfXzuy70Pzix5vH yyOzLR/BI2UlMy4OH2Sx+BYC0QeXeuf2JVkaImN1DhXdJKzpD7JjT9DwYXHLpQlRVD7IzLQ9HNQ 95tjIWM/3tt4lIFVCi0NlmnhhqVHCqta4DbW4Ca4wmNA32vsG+Saiu2XAJz9DLHcV3wE9aIeT+M Jf0FyYbFFNJksqovwH0Gf/UwxQfMBsIo7UoMVn/ClkN799EnbNSs8uK2z4gbqr+a45cyaQ6PLUZ tKjAkf5akubH+GCH2fEheMPQoTkWcuhaX/1YfyxBgqgR9M4RImzTFjltPkaTpQNM+us5+9GCHLR +wfpeLSiP8Mazr8iztMbuG+H5n2pg9t7TdduIXjGTIn+SwV3tComOdzi8KxKIb6q0RLp3prKFlY Spa0oe1QS8DondeZwhWdyz+G3+B6vQE91fRWC3ZbHBlT+nzSx40THo9ZAoZIDj4Y3JmXQvq99Px xyXPCxbcmVoa2VJZdxQ== X-Proofpoint-GUID: PfbYL4s8zxuWiLnMVyTfPQVvzQrojlj0 X-Authority-Analysis: v=2.4 cv=P4IKQCAu c=1 sm=1 tr=0 ts=69e590f8 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=TtqV-g6YmW1Jfm2GSLaY:22 a=M5GUcnROAAAA:8 a=jWBfGndVv8tF2AnpqLMA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: PfbYL4s8zxuWiLnMVyTfPQVvzQrojlj0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" npc_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. Fixes: 09d3b7a1403f ("octeontx2-af: npc: cn20k: Allocate default MCAM index= es") Signed-off-by: Ratheesh Kannoth --- drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 752dbcede90f..0714734c6af7 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -4001,6 +4001,13 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16= pcifunc, u16 *bcast, void *val; int i, j; =20 + for (i =3D 0; i < ARRAY_SIZE(ptr); i++) { + if (!ptr[i]) + continue; + + *ptr[i] =3D USHRT_MAX; + } + if (!npc_priv.init_done) return 0; =20 @@ -4016,7 +4023,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); =20 - *ptr[0] =3D USHRT_MAX; return -ESRCH; } =20 @@ -4036,7 +4042,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); =20 - *ptr[3] =3D USHRT_MAX; return -ESRCH; } =20 @@ -4056,7 +4061,6 @@ int npc_cn20k_dft_rules_idx_get(struct rvu *rvu, u16 = pcifunc, u16 *bcast, __func__, npc_dft_rule_name[i], pcifunc); =20 - *ptr[j] =3D USHRT_MAX; continue; } =20 --=20 2.43.0 From nobody Tue Jun 16 12:43:15 2026 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65D993783DE; Mon, 20 Apr 2026 02:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652557; cv=none; b=mqteaVAeetgP0WbDuTmv6siPMhoy4o/3ln0nCDIJcKxXT81BwLz+kxJedZ2p21TlKGqN9YkmcM+X1nN2tfWgjRQ4oaXs9XfDLNp0DnVSQ2lDzvvATlshk8tcFcaMd8IFwT4zOx06vXc4OJ48BHM+2+ntIu6SxZqdJe1ooaWSTuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652557; c=relaxed/simple; bh=Jde5f3SamFB5DgAGjLHtkm6wuwuM1wv6iL2d/a82u1M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BBX45gCZHsYmtkIoISjMoCsWEA0DD86MgFEUTmMCXYDZvEjUOROxma663ScCnghV5SRB47pAMnXvR+5WJJZBD2N++geo4zNj7FZ9fzUFUf/e21GmjpapGovnACKvrmsqa4k76QCPgG/EJ6sN0EmLDWeNABGS59N9hUGXsnQGoP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=VMZWxXWy; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="VMZWxXWy" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JMTxgw2167150; Sun, 19 Apr 2026 19:35:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=y BvPOi2+ZpDTv2CZnpcjWNZM0CpDPGcJHFwoy7T1fQc=; b=VMZWxXWyECpaCq+vK PW18SY4uny6pJ6Pv5To3NkDiK4dcl6tNgTvergkhf4GwAiKOQ4RG40LI4gzqu3z5 Zq/1VWech6Z/J11tteY0mj6QkQ9cM+0SA/Hajq17UuPEEZEpgvlBIGiAEZtStcNM x+dipktnYdyKrAkqXMqQGbIClfopZP4Bwn2Vk1gZ8pmfuEsoFnhE6bQUOrNr3WyQ I7RST1FfKvMjeeZA4er52wzmEnzszqtbAhZhwittTQGlZZvYNpNLAeJyK3B8/5Yj 0U3CyxFd0VF+Yq7dIOg/sXWKO/KbdSXfxOhv6qaOcy3JmP8yVLXhz075LBubl0gk RBxkQ== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 4dmx77h2ns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:42 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:42 -0700 Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:41 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:41 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id AE8FB3F7041; Sun, 19 Apr 2026 19:35:36 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth Subject: [PATCH v2 net 10/11] octeontx2-af: npc: cn20k: Tear down default MCAM rules explicitly on free Date: Mon, 20 Apr 2026 08:04:41 +0530 Message-ID: <20260420023442.3295891-11-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX15NAxoZe+hA7 IiwoX3WojD1GszLkShfy7EFqbvOm8iR6yRn7v7AvK2Q1ToWs032kUcZI4GbvUOusHzRRbWnBO47 i9678hFEWhLVezkDK/zsBI+vd+owfJw4nzOtZG6PLqhI3pg2AW68ERFWTZ4S8Am55AszrEEceFD 6u/anIr42HM9QnIz7HiSW8wNv1o1e7gohw3cQEmnQvlVQ1JmhhbECBBV8EhMmzwU+qDbqTIqUVw AOEFTY7D6UpG4tJRLQA8c9Uy9isg5tZuWNY9DXq9q4BspsqOaevZTVIz//9IIinxQTjgAMEsigJ iSLqYbki3JSFXHwoh9mbtNRGwfoiGfq9rSq/20FWwn0oxSf41VkTjf5LfMpocY7TOEhHlj2DAZR 98yNbdyVmAd9uBAHGWHlfuKnI9jFTDlVnaN1xgUGkSv0L38wuSLpNfxEFeIljv1SuqGlcQlGUqQ vDPzuwvVO7QtmvjCh4A== X-Proofpoint-GUID: srTRoqa4YE0J14k2pEmwu43Yo3wSD8F8 X-Authority-Analysis: v=2.4 cv=P4IKQCAu c=1 sm=1 tr=0 ts=69e590fe cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=TtqV-g6YmW1Jfm2GSLaY:22 a=M5GUcnROAAAA:8 a=qvf5-K3L102eB4Sd9qIA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-ORIG-GUID: srTRoqa4YE0J14k2pEmwu43Yo3wSD8F8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" 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 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. Fixes: 09d3b7a1403f ("octeontx2-af: npc: cn20k: Allocate default MCAM index= es") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 51 ++++++++++++---- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 59 +++++++++++++------ 2 files changed, 82 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index 0714734c6af7..cb2fc21e0583 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -4163,11 +4163,11 @@ static bool npc_is_cgx_or_lbk(struct rvu *rvu, u16 = pcifunc) =20 void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 pcifunc) { - struct npc_mcam_free_entry_req free_req =3D { 0 }; + struct npc_mcam *mcam =3D &rvu->hw->mcam; + u16 ptr[4] =3D {[0 ... 3] =3D 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; =20 if (!npc_priv.init_done) @@ -4225,14 +4225,43 @@ void npc_cn20k_dft_rules_free(struct rvu *rvu, u16 = pcifunc) } =20 free_rules: + blkaddr =3D rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); + if (blkaddr < 0) + return; + for (int i =3D 0; i < 4; i++) { + if (ptr[i] =3D=3D USHRT_MAX) + continue; =20 - free_req.hdr.pcifunc =3D pcifunc; - free_req.all =3D 1; - rc =3D rvu_mbox_handler_npc_mcam_free_entry(rvu, &free_req, &rsp); - if (rc) - dev_err(rvu->dev, - "%s: Error deleting default entries (pcifunc=3D%#x\n", - __func__, pcifunc); + mutex_lock(&mcam->lock); + npc_mcam_clear_bit(mcam, ptr[i]); + mcam->entry2pfvf_map[ptr[i]] =3D NPC_MCAM_INVALID_MAP; + npc_cn20k_enable_mcam_entry(rvu, blkaddr, ptr[i], false); + mcam->entry2target_pffunc[ptr[i]] =3D 0x0; + mutex_unlock(&mcam->lock); + + rc =3D 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=3D%#x) mcam_idx=3D%= 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 =3D 0; i < 4; i++) { + if (ptr[i] !=3D rule->entry) + continue; + + list_del(&rule->list); + kfree(rule); + break; + } + } + mutex_unlock(&mcam->lock); } =20 int npc_cn20k_dft_rules_alloc(struct rvu *rvu, u16 pcifunc) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_npc.c index 0a2191fda614..b2a9c8d0075b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -2519,33 +2519,58 @@ void npc_mcam_clear_bit(struct npc_mcam *mcam, u16 = index) static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mc= am, int blkaddr, u16 pcifunc) { + u16 dft_idxs[NPC_DFT_RULE_MAX_ID]; + bool cn20k_dft_rl; u16 index, cntr; int rc; =20 + npc_cn20k_dft_rules_idx_get(rvu, pcifunc, + &dft_idxs[NPC_DFT_RULE_BCAST_ID], + &dft_idxs[NPC_DFT_RULE_MCAST_ID], + &dft_idxs[NPC_DFT_RULE_PROMISC_ID], + &dft_idxs[NPC_DFT_RULE_UCAST_ID]); + /* Scan all MCAM entries and free the ones mapped to 'pcifunc' */ for (index =3D 0; index < mcam->bmap_entries; index++) { - if (mcam->entry2pfvf_map[index] =3D=3D pcifunc) { + if (mcam->entry2pfvf_map[index] !=3D pcifunc) + continue; + + cn20k_dft_rl =3D false; + + if (is_cn20k(rvu->pdev)) { + if (dft_idxs[NPC_DFT_RULE_BCAST_ID] =3D=3D index || + dft_idxs[NPC_DFT_RULE_MCAST_ID] =3D=3D index || + dft_idxs[NPC_DFT_RULE_PROMISC_ID] =3D=3D index || + dft_idxs[NPC_DFT_RULE_UCAST_ID] =3D=3D index) { + cn20k_dft_rl =3D true; + } + } + + /* Disable the entry */ + npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false); + + if (!cn20k_dft_rl) { mcam->entry2pfvf_map[index] =3D NPC_MCAM_INVALID_MAP; /* Free the entry in bitmap */ npc_mcam_clear_bit(mcam, index); - /* Disable the entry */ - npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false); - - /* Update entry2counter mapping */ - cntr =3D mcam->entry2cntr_map[index]; - if (cntr !=3D NPC_MCAM_INVALID_MAP) - npc_unmap_mcam_entry_and_cntr(rvu, mcam, - blkaddr, index, - cntr); mcam->entry2target_pffunc[index] =3D 0x0; - if (is_cn20k(rvu->pdev)) { - rc =3D npc_cn20k_idx_free(rvu, &index, 1); - if (rc) - dev_err(rvu->dev, - "Failed to free mcam idx=3D%u pcifunc=3D%#x\n", - index, pcifunc); - } } + + /* Update entry2counter mapping */ + cntr =3D mcam->entry2cntr_map[index]; + if (cntr !=3D NPC_MCAM_INVALID_MAP) + npc_unmap_mcam_entry_and_cntr(rvu, mcam, + blkaddr, index, + cntr); + + if (!is_cn20k(rvu->pdev) || cn20k_dft_rl) + continue; + + rc =3D npc_cn20k_idx_free(rvu, &index, 1); + if (rc) + dev_err(rvu->dev, + "Failed to free mcam idx=3D%u pcifunc=3D%#x\n", + index, pcifunc); } } =20 --=20 2.43.0 From nobody Tue Jun 16 12:43:15 2026 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01D32377EBA; Mon, 20 Apr 2026 02:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652556; cv=none; b=GkXanfRaKWIvWYSGkMBpTeiBpm7fLUDMNU5Mh3dSJ8GlW11FMZStNMMB9kYajvYmNJxaFzyJiLlT2ARnv+4+APwCwRrLvhwMnLjKTrQG0qDlkCe1z8dz9rT/IVClMpWBVXP6GZaxybjzc9lAoE77UwLf3P4JLdlhIjabSLN0VNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776652556; c=relaxed/simple; bh=GFhPQk1ixvVE/pSq2hhoA8j3mR3SOYgODPmyTBkgf+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tIAPFWeuVVTP/YpA++akB8Cv2TjJIEuTuIkc8QJPIXuPy8so++7GWPPsYOQoDGkaZQPg5few7JUHQRUkz63cX9X4K32gd0072gMv+OLTMhF48E41+MjfrKoK5e4mGE3wRdRClCZpeqXf+7sQoBVZ61+LYkpistETensop/GXejE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=BLGNZSvc; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="BLGNZSvc" Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63JNBYms814459; Sun, 19 Apr 2026 19:35:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=a wH1bJEdB1D/LvgtUdkC6aS/Fzej6IswWmjI4z75k3g=; b=BLGNZSvcgt8dZFBdg dCKjA4cvoNJmiNa9M7+rsPiuQ+CFLZMi7wsGYGDjG2H4nstx71NNKfT5YR9DLm9+ b2fBeGI/LMlLpIMGszSUC95j23LovXhjbiI31x/vTLfsidNHKbuPqut7LnpdQuf+ LlDRMbvkU+HiuskH9SKLAAfcTTH63tbWjLTP32qRr0glp5pXpwZ6aUlMh2wV+N1K LqPVn3r+jhfRuWV5J+Xr2G4hUXZ8YNz+jJs72ODNtaX0FiG3RMV35pBmQpsrk3fY +CuW1qXw82J3f6isiKUV4X8qi2xENVwMUb7nqAsLt7qwqtqFppe/4u+2q9KCkL1x NDp+w== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 4dm9fgjj6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 19 Apr 2026 19:35:46 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:46 -0700 Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.25; Sun, 19 Apr 2026 19:35:45 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.25 via Frontend Transport; Sun, 19 Apr 2026 19:35:45 -0700 Received: from rkannoth-OptiPlex-7090.. (unknown [10.28.36.165]) by maili.marvell.com (Postfix) with ESMTP id B830E3F7041; Sun, 19 Apr 2026 19:35:41 -0700 (PDT) From: Ratheesh Kannoth To: , CC: , , , , , , , Ratheesh Kannoth , "Suman Ghosh" Subject: [PATCH v2 net 11/11] octeontx2-af: npc: cn20k: Reject missing default-rule MCAM indices Date: Mon, 20 Apr 2026 08:04:42 +0530 Message-ID: <20260420023442.3295891-12-rkannoth@marvell.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260420023442.3295891-1-rkannoth@marvell.com> References: <20260420023442.3295891-1-rkannoth@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: Z3D4XYFHh0Id6lmdIQ262_oX3e-ae3UD X-Authority-Analysis: v=2.4 cv=TYSmcxQh c=1 sm=1 tr=0 ts=69e59103 cx=c_pps a=rEv8fa4AjpPjGxpoe8rlIQ==:117 a=rEv8fa4AjpPjGxpoe8rlIQ==:17 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=l0iWHRpgs5sLHlkKQ1IR:22 a=QXcCYyLzdtTjyudCfB6f:22 a=M5GUcnROAAAA:8 a=5PJ-8yRtmk1h066FuvsA:9 a=OBjm3rFKGHvpk9ecZwUJ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDIwMDAyMyBTYWx0ZWRfX6kOs7rJZOIxO rcRfrdFnUG4Xsc3u4cxxdSxt/yAO9La39X28tHkZCvWHE5Axd2J0Qp5jPpxQN/NYV93nysmrsPJ 9yzoTtQ98gq1n3Dx6boMgNSHFNNCwBm+wO7vMOaaW8sF7XqTFUlx41N3QaUOZbsJI3HbOf0pbec FShLW7teIbqTfqV83dxTHIVozQP9qAEsor/dubFhAYPE5IJI3VuGBSl5iBa5+1NvT0Z0OcVn/AA newXJYOeAyqnf81X2Yq4r3bS5/ipryDWCaTbqtj4cYBSorLNQ2jsm8+ACJfkv4VXe0zm2XejY2I ym0L3cguU7ZOBYC0eWeMIW7slIh9YPnWJTJVMJMQqUJSYmdQJEzc69vx1TsILn4D9bV5ZlOM8N7 tXed+Ojid0pDN5qWI0hqH4w6piKbFCjQGTSRLpdzrmAtDNiCp0tRPCPy9JiZRxbFk2gMEx6DMaE sGSOWAtDUAwynn/5ZcQ== X-Proofpoint-ORIG-GUID: Z3D4XYFHh0Id6lmdIQ262_oX3e-ae3UD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-19_07,2026-04-17_04,2025-10-01_01 Content-Type: text/plain; charset="utf-8" npc_get_nixlf_mcam_index() returned USHRT_MAX from npc_cn20k_dft_rules_idx_= get() for broadcast, multicast, promiscuous, and unicast default-rule slots when = no rule was installed. Callers could use that sentinel as a real MCAM index. Return -EINVAL from the cn20k cases when the reserved entry is still USHRT_= MAX. Teach rvu_npc_update_flowkey_alg_idx() to handle negative indices and skip = RSS action updates when the lookup fails. Add range checks to cn20k NPC MCAM h= elpers so bogus indices are rejected before touching hardware. Cc: Suman Ghosh Fixes: 6d1e70282f76 ("octeontx2-af: npc: cn20k: Use common APIs") Signed-off-by: Ratheesh Kannoth --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 12 ++++++++++ .../ethernet/marvell/octeontx2/af/rvu_npc.c | 23 ++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c b/driver= s/net/ethernet/marvell/octeontx2/af/cn20k/npc.c index cb2fc21e0583..59d22511b742 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c @@ -808,6 +808,9 @@ npc_cn20k_enable_mcam_entry(struct rvu *rvu, int blkadd= r, u64 cfg, hw_prio; u8 kw_type; =20 + if (index < 0 || index >=3D mcam->total_entries) + return -EINVAL; + if (npc_mcam_idx_2_key_type(rvu, index, &kw_type)) return -EINVAL; =20 @@ -1055,6 +1058,9 @@ int npc_cn20k_config_mcam_entry(struct rvu *rvu, int = blkaddr, int index, int kw =3D 0; u8 kw_type; =20 + if (index < 0 || index >=3D mcam->total_entries) + return -EINVAL; + if (npc_mcam_idx_2_key_type(rvu, index, &kw_type)) return -EINVAL; =20 @@ -1147,6 +1153,9 @@ int npc_cn20k_copy_mcam_entry(struct rvu *rvu, int bl= kaddr, u16 src, u16 dest) int bank, i, sb, db; int dbank, sbank; =20 + if (src >=3D mcam->total_entries || dest >=3D mcam->total_entries) + return -EINVAL; + dbank =3D npc_get_bank(mcam, dest); sbank =3D npc_get_bank(mcam, src); =20 @@ -1212,6 +1221,9 @@ int npc_cn20k_read_mcam_entry(struct rvu *rvu, int bl= kaddr, u16 index, int kw =3D 0, bank; u8 kw_type; =20 + if (index >=3D mcam->total_entries) + return -EINVAL; + if (npc_mcam_idx_2_key_type(rvu, index, &kw_type)) return -EINVAL; =20 diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/= net/ethernet/marvell/octeontx2/af/rvu_npc.c index b2a9c8d0075b..be79a51b4b48 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -165,12 +165,20 @@ int npc_get_nixlf_mcam_index(struct npc_mcam *mcam, =20 switch (type) { case NIXLF_BCAST_ENTRY: + if (bcast =3D=3D USHRT_MAX) + return -EINVAL; return bcast; case NIXLF_ALLMULTI_ENTRY: + if (mcast =3D=3D USHRT_MAX) + return -EINVAL; return mcast; case NIXLF_PROMISC_ENTRY: + if (promisc =3D=3D USHRT_MAX) + return -EINVAL; return promisc; case NIXLF_UCAST_ENTRY: + if (ucast =3D=3D USHRT_MAX) + return -EINVAL; return ucast; default: return -EINVAL; @@ -238,9 +246,6 @@ void npc_enable_mcam_entry(struct rvu *rvu, struct npc_= mcam *mcam, int actbank =3D bank; =20 if (is_cn20k(rvu->pdev)) { - if (index < 0 || index >=3D mcam->banksize * mcam->banks) - return; - npc_cn20k_enable_mcam_entry(rvu, blkaddr, index, enable); return; } @@ -1128,7 +1133,7 @@ void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, = u16 pcifunc, int nixlf, index =3D mcam_index; } =20 - if (index >=3D mcam->total_entries) + if (index < 0 || index >=3D mcam->total_entries) return; =20 bank =3D npc_get_bank(mcam, index); @@ -1173,16 +1178,18 @@ void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu= , u16 pcifunc, int nixlf, /* If PF's promiscuous entry is enabled, * Set RSS action for that entry as well */ - npc_update_rx_action_with_alg_idx(rvu, action, pfvf, index, - blkaddr, alg_idx); + if (index >=3D 0) + npc_update_rx_action_with_alg_idx(rvu, action, pfvf, index, + blkaddr, alg_idx); =20 index =3D npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf, NIXLF_ALLMULTI_ENTRY); /* If PF's allmulti entry is enabled, * Set RSS action for that entry as well */ - npc_update_rx_action_with_alg_idx(rvu, action, pfvf, index, - blkaddr, alg_idx); + if (index >=3D 0) + npc_update_rx_action_with_alg_idx(rvu, action, pfvf, index, + blkaddr, alg_idx); } } =20 --=20 2.43.0