]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
octeontx2-af: Refactor few NPC mcam APIs
authorLinu Cherian <lcherian@marvell.com>
Tue, 5 Nov 2024 12:56:18 +0000 (18:26 +0530)
committerJakub Kicinski <kuba@kernel.org>
Mon, 11 Nov 2024 22:15:57 +0000 (14:15 -0800)
Introduce lowlevel variant of rvu_mcam_remove/add_counter_from/to_rule
for better code reuse, which assumes necessary locks are taken at
higher level.

These low level functions would be used for implementing default rule
counter APIs in the subsequent patch.

Signed-off-by: Linu Cherian <lcherian@marvell.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241105125620.2114301-2-lcherian@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/af/rvu.h
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

index 5016ba82e1423aeb4b07b1c0a4cd8f8903422661..d92a5f47a476fc32b37c4d46d4866b0bd63273ce 100644 (file)
@@ -960,7 +960,11 @@ void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
                                    int group, int alg_idx, int mcam_index);
-
+void __rvu_mcam_remove_counter_from_rule(struct rvu *rvu, u16 pcifunc,
+                                        struct rvu_npc_mcam_rule *rule);
+void __rvu_mcam_add_counter_to_rule(struct rvu *rvu, u16 pcifunc,
+                                   struct rvu_npc_mcam_rule *rule,
+                                   struct npc_install_flow_rsp *rsp);
 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
                                       int blkaddr, int *alloc_cnt,
                                       int *enable_cnt);
index 97722ce8c4cb34e2fac06adfb08c189d18989a5b..c4ef1e83cc46184597b5756a83d0129d328aea80 100644 (file)
@@ -2975,9 +2975,9 @@ int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,
        return rc;
 }
 
-int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
-                       struct npc_mcam_alloc_counter_req *req,
-                       struct npc_mcam_alloc_counter_rsp *rsp)
+static int __npc_mcam_alloc_counter(struct rvu *rvu,
+                                   struct npc_mcam_alloc_counter_req *req,
+                                   struct npc_mcam_alloc_counter_rsp *rsp)
 {
        struct npc_mcam *mcam = &rvu->hw->mcam;
        u16 pcifunc = req->hdr.pcifunc;
@@ -2998,11 +2998,9 @@ int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
        if (!req->contig && req->count > NPC_MAX_NONCONTIG_COUNTERS)
                return NPC_MCAM_INVALID_REQ;
 
-       mutex_lock(&mcam->lock);
 
        /* Check if unused counters are available or not */
        if (!rvu_rsrc_free_count(&mcam->counters)) {
-               mutex_unlock(&mcam->lock);
                return NPC_MCAM_ALLOC_FAILED;
        }
 
@@ -3035,12 +3033,27 @@ int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
                }
        }
 
-       mutex_unlock(&mcam->lock);
        return 0;
 }
 
-int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
-               struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
+int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
+                       struct npc_mcam_alloc_counter_req *req,
+                       struct npc_mcam_alloc_counter_rsp *rsp)
+{
+       struct npc_mcam *mcam = &rvu->hw->mcam;
+       int err;
+
+       mutex_lock(&mcam->lock);
+
+       err = __npc_mcam_alloc_counter(rvu, req, rsp);
+
+       mutex_unlock(&mcam->lock);
+       return err;
+}
+
+static int __npc_mcam_free_counter(struct rvu *rvu,
+                                  struct npc_mcam_oper_counter_req *req,
+                                  struct msg_rsp *rsp)
 {
        struct npc_mcam *mcam = &rvu->hw->mcam;
        u16 index, entry = 0;
@@ -3050,10 +3063,8 @@ int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
        if (blkaddr < 0)
                return NPC_MCAM_INVALID_REQ;
 
-       mutex_lock(&mcam->lock);
        err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
        if (err) {
-               mutex_unlock(&mcam->lock);
                return err;
        }
 
@@ -3077,10 +3088,66 @@ int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
                                              index, req->cntr);
        }
 
-       mutex_unlock(&mcam->lock);
        return 0;
 }
 
+int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
+               struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
+{
+       struct npc_mcam *mcam = &rvu->hw->mcam;
+       int err;
+
+       mutex_lock(&mcam->lock);
+
+       err = __npc_mcam_free_counter(rvu, req, rsp);
+
+       mutex_unlock(&mcam->lock);
+
+       return err;
+}
+
+void __rvu_mcam_remove_counter_from_rule(struct rvu *rvu, u16 pcifunc,
+                                        struct rvu_npc_mcam_rule *rule)
+{
+       struct npc_mcam_oper_counter_req free_req = { 0 };
+       struct msg_rsp free_rsp;
+
+       if (!rule->has_cntr)
+               return;
+
+       free_req.hdr.pcifunc = pcifunc;
+       free_req.cntr = rule->cntr;
+
+       __npc_mcam_free_counter(rvu, &free_req, &free_rsp);
+       rule->has_cntr = false;
+}
+
+void __rvu_mcam_add_counter_to_rule(struct rvu *rvu, u16 pcifunc,
+                                   struct rvu_npc_mcam_rule *rule,
+                                   struct npc_install_flow_rsp *rsp)
+{
+       struct npc_mcam_alloc_counter_req cntr_req = { 0 };
+       struct npc_mcam_alloc_counter_rsp cntr_rsp = { 0 };
+       int err;
+
+       cntr_req.hdr.pcifunc = pcifunc;
+       cntr_req.contig = true;
+       cntr_req.count = 1;
+
+       /* we try to allocate a counter to track the stats of this
+        * rule. If counter could not be allocated then proceed
+        * without counter because counters are limited than entries.
+        */
+       err = __npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
+       if (!err && cntr_rsp.count) {
+               rule->cntr = cntr_rsp.cntr;
+               rule->has_cntr = true;
+               rsp->counter = rule->cntr;
+       } else {
+               rsp->counter = err;
+       }
+}
+
 int rvu_mbox_handler_npc_mcam_unmap_counter(struct rvu *rvu,
                struct npc_mcam_unmap_counter_req *req, struct msg_rsp *rsp)
 {
index 150635de2bd5a1b86f51c33ac4bd14513e144355..7a1c18b1486d2f13dfce7523b42b380991de28d1 100644 (file)
@@ -1081,44 +1081,26 @@ static void rvu_mcam_add_rule(struct npc_mcam *mcam,
 static void rvu_mcam_remove_counter_from_rule(struct rvu *rvu, u16 pcifunc,
                                              struct rvu_npc_mcam_rule *rule)
 {
-       struct npc_mcam_oper_counter_req free_req = { 0 };
-       struct msg_rsp free_rsp;
+       struct npc_mcam *mcam = &rvu->hw->mcam;
 
-       if (!rule->has_cntr)
-               return;
+       mutex_lock(&mcam->lock);
 
-       free_req.hdr.pcifunc = pcifunc;
-       free_req.cntr = rule->cntr;
+       __rvu_mcam_remove_counter_from_rule(rvu, pcifunc, rule);
 
-       rvu_mbox_handler_npc_mcam_free_counter(rvu, &free_req, &free_rsp);
-       rule->has_cntr = false;
+       mutex_unlock(&mcam->lock);
 }
 
 static void rvu_mcam_add_counter_to_rule(struct rvu *rvu, u16 pcifunc,
                                         struct rvu_npc_mcam_rule *rule,
                                         struct npc_install_flow_rsp *rsp)
 {
-       struct npc_mcam_alloc_counter_req cntr_req = { 0 };
-       struct npc_mcam_alloc_counter_rsp cntr_rsp = { 0 };
-       int err;
+       struct npc_mcam *mcam = &rvu->hw->mcam;
 
-       cntr_req.hdr.pcifunc = pcifunc;
-       cntr_req.contig = true;
-       cntr_req.count = 1;
+       mutex_lock(&mcam->lock);
 
-       /* we try to allocate a counter to track the stats of this
-        * rule. If counter could not be allocated then proceed
-        * without counter because counters are limited than entries.
-        */
-       err = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req,
-                                                     &cntr_rsp);
-       if (!err && cntr_rsp.count) {
-               rule->cntr = cntr_rsp.cntr;
-               rule->has_cntr = true;
-               rsp->counter = rule->cntr;
-       } else {
-               rsp->counter = err;
-       }
+       __rvu_mcam_add_counter_to_rule(rvu, pcifunc, rule, rsp);
+
+       mutex_unlock(&mcam->lock);
 }
 
 static int npc_mcast_update_action_index(struct rvu *rvu, struct npc_install_flow_req *req,