octeontx2-af: Fix max NPC MCAM entry check while validating ref_entry
authorSuman Ghosh <sumang@marvell.com>
Mon, 1 Jan 2024 14:50:42 +0000 (20:20 +0530)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Jan 2024 01:52:51 +0000 (17:52 -0800)
As of today, the last MCAM entry was not getting allocated because of
a <= check with the max_bmap count. This patch modifies that and if the
requested entry is greater than the available entries then set it to the
max value.

Signed-off-by: Suman Ghosh <sumang@marvell.com>
Link: https://lore.kernel.org/r/20240101145042.419697-1-sumang@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c

index 7f30e08b580f04e426daa54c122e7580a4f38d5b..167145bdcb75d3f852134fcaa44fc2f307c42478 100644 (file)
@@ -2715,18 +2715,17 @@ int rvu_mbox_handler_npc_mcam_alloc_entry(struct rvu *rvu,
        rsp->entry = NPC_MCAM_ENTRY_INVALID;
        rsp->free_count = 0;
 
-       /* Check if ref_entry is within range */
-       if (req->priority && req->ref_entry >= mcam->bmap_entries) {
-               dev_err(rvu->dev, "%s: reference entry %d is out of range\n",
-                       __func__, req->ref_entry);
-               return NPC_MCAM_INVALID_REQ;
-       }
+       /* Check if ref_entry is greater that the range
+        * then set it to max value.
+        */
+       if (req->ref_entry > mcam->bmap_entries)
+               req->ref_entry = mcam->bmap_entries;
 
        /* ref_entry can't be '0' if requested priority is high.
         * Can't be last entry if requested priority is low.
         */
        if ((!req->ref_entry && req->priority == NPC_MCAM_HIGHER_PRIO) ||
-           ((req->ref_entry == (mcam->bmap_entries - 1)) &&
+           ((req->ref_entry == mcam->bmap_entries) &&
             req->priority == NPC_MCAM_LOWER_PRIO))
                return NPC_MCAM_INVALID_REQ;