]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
octeontx2-af: npc: Use common structures
authorRatheesh Kannoth <rkannoth@marvell.com>
Tue, 24 Feb 2026 08:00:09 +0000 (13:30 +0530)
committerJakub Kicinski <kuba@kernel.org>
Sat, 28 Feb 2026 18:29:27 +0000 (10:29 -0800)
CN20K and legacy silicon differ in the size of key words used
in NPC MCAM. However, SoC-specific structures are not required
for low-level functions. Remove the SoC-specific structures
and rename the macros to improve readability.

Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
Link: https://patch.msgid.link/20260224080009.4147301-14-rkannoth@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c
drivers/net/ethernet/marvell/octeontx2/af/mbox.h
drivers/net/ethernet/marvell/octeontx2/af/rvu.h
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

index 63a287ee8f70032c1ad20d897f17f75c48612536..7291fdb89b03f67cf6fa2e4f5663757890aa5228 100644 (file)
@@ -4018,10 +4018,10 @@ int rvu_mbox_handler_npc_get_num_kws(struct rvu *rvu,
                                     struct npc_get_num_kws_req *req,
                                     struct npc_get_num_kws_rsp *rsp)
 {
+       u64 kw_mask[NPC_KWS_IN_KEY_SZ_MAX] = { 0 };
+       u64 kw[NPC_KWS_IN_KEY_SZ_MAX] = { 0 };
        struct rvu_npc_mcam_rule dummy = { 0 };
-       struct cn20k_mcam_entry cn20k_entry = { 0 };
        struct mcam_entry_mdata mdata = { };
-       struct mcam_entry entry = { 0 };
        struct npc_install_flow_req *fl;
        int i, cnt = 0, blkaddr;
 
@@ -4038,7 +4038,8 @@ int rvu_mbox_handler_npc_get_num_kws(struct rvu *rvu,
                return NPC_MCAM_INVALID_REQ;
        }
 
-       npc_populate_mcam_mdata(rvu, &mdata, &cn20k_entry, &entry);
+       mdata.kw = kw;
+       mdata.kw_mask = kw_mask;
 
        npc_update_flow(rvu, &mdata, fl->features, &fl->packet,
                        &fl->mask, &dummy, fl->intf, blkaddr);
@@ -4046,8 +4047,8 @@ int rvu_mbox_handler_npc_get_num_kws(struct rvu *rvu,
        /* Find the most significant word valid. Traverse from
         * MSB to LSB, check if cam0 or cam1 is set
         */
-       for (i = NPC_CN20K_MAX_KWS_IN_KEY - 1; i >= 0; i--) {
-               if (cn20k_entry.kw[i] || cn20k_entry.kw_mask[i]) {
+       for (i = NPC_KWS_IN_KEY_SZ_MAX - 1; i >= 0; i--) {
+               if (kw[i] || kw_mask[i]) {
                        cnt = i + 1;
                        break;
                }
index 2d9f6cb4820f22c0aab09aeb2d6a55496034382f..dc42c81c094256bcba2a0d7c310ac063283ea5a8 100644 (file)
@@ -1593,18 +1593,22 @@ struct mcam_entry_mdata {
        u8 max_kw;
 };
 
+enum npc_kws_in_key_sz {
+       NPC_KWS_IN_KEY_SZ_7 = 7,
+       NPC_KWS_IN_KEY_SZ_8 = 8,
+       NPC_KWS_IN_KEY_SZ_MAX,
+};
+
 struct mcam_entry {
-#define NPC_MAX_KWS_IN_KEY     7 /* Number of keywords in max keywidth */
-       u64     kw[NPC_MAX_KWS_IN_KEY];
-       u64     kw_mask[NPC_MAX_KWS_IN_KEY];
+       u64     kw[NPC_KWS_IN_KEY_SZ_7];
+       u64     kw_mask[NPC_KWS_IN_KEY_SZ_7];
        u64     action;
        u64     vtag_action;
 };
 
 struct cn20k_mcam_entry {
-#define NPC_CN20K_MAX_KWS_IN_KEY       8
-       u64     kw[NPC_CN20K_MAX_KWS_IN_KEY];
-       u64     kw_mask[NPC_CN20K_MAX_KWS_IN_KEY];
+       u64     kw[NPC_KWS_IN_KEY_SZ_8];
+       u64     kw_mask[NPC_KWS_IN_KEY_SZ_8];
        u64     action;
        u64     vtag_action;
        u64     action2;
index f811d6b5c5452f500305fc2a2c5f6cc8a535833b..a466181cf908263e1188bdbcbe0215686f541d7e 100644 (file)
@@ -197,7 +197,7 @@ struct npc_key_field {
        /* Masks where all set bits indicate position
         * of a field in the key
         */
-       u64 kw_mask[NPC_CN20K_MAX_KWS_IN_KEY];
+       u64 kw_mask[NPC_KWS_IN_KEY_SZ_MAX];
        /* Number of words in the key a field spans. If a field is
         * of 16 bytes and key offset is 4 then the field will use
         * 4 bytes in KW0, 8 bytes in KW1 and 4 bytes in KW2 and
index de613b27068d70a3eb0e2f150de505e3ba766c69..b45798d9fdabd338ba6a7df60624a3f8edbfaf3d 100644 (file)
@@ -227,7 +227,7 @@ static bool npc_check_overlap(struct rvu *rvu, int blkaddr,
                input = &mcam->tx_key_fields[type];
        }
 
-       kws = NPC_MAX_KWS_IN_KEY;
+       kws = NPC_KWS_IN_KEY_SZ_7;
 
        if (is_cn20k(rvu->pdev))
                goto skip_cn10k_config;
@@ -289,7 +289,7 @@ skip_cn10k_config:
                         * field bits
                         */
                        if (npc_check_overlap_fields(dummy, input,
-                                                    NPC_CN20K_MAX_KWS_IN_KEY))
+                                                    NPC_KWS_IN_KEY_SZ_8))
                                return true;
                }
        }
@@ -460,9 +460,9 @@ static void npc_handle_multi_layer_fields(struct rvu *rvu, int blkaddr, u8 intf)
        u8 start_lid;
 
        if (is_cn20k(rvu->pdev))
-               max_kw = NPC_CN20K_MAX_KWS_IN_KEY;
+               max_kw = NPC_KWS_IN_KEY_SZ_8;
        else
-               max_kw = NPC_MAX_KWS_IN_KEY;
+               max_kw = NPC_KWS_IN_KEY_SZ_7;
 
        key_fields = mcam->rx_key_fields;
        features = &mcam->rx_features;
@@ -906,12 +906,12 @@ void npc_update_entry(struct rvu *rvu, enum key_fields type,
                      struct mcam_entry_mdata *mdata, u64 val_lo,
                      u64 val_hi, u64 mask_lo, u64 mask_hi, u8 intf)
 {
-       struct cn20k_mcam_entry cn20k_dummy = { {0} };
+       u64 kw_mask[NPC_KWS_IN_KEY_SZ_MAX] = { 0 };
+       u64 kw[NPC_KWS_IN_KEY_SZ_MAX] = { 0 };
        struct npc_mcam *mcam = &rvu->hw->mcam;
-       struct mcam_entry dummy = { {0} };
-       u64 *kw, *kw_mask, *val, *mask;
        struct npc_key_field *field;
        u64 kw1, kw2, kw3;
+       u64 *val, *mask;
        int i, max_kw;
        u8 shift;
 
@@ -922,15 +922,10 @@ void npc_update_entry(struct rvu *rvu, enum key_fields type,
        if (!field->nr_kws)
                return;
 
-       if (is_cn20k(rvu->pdev)) {
-               max_kw = NPC_CN20K_MAX_KWS_IN_KEY;
-               kw = cn20k_dummy.kw;
-               kw_mask = cn20k_dummy.kw_mask;
-       } else {
-               max_kw = NPC_MAX_KWS_IN_KEY;
-               kw = dummy.kw;
-               kw_mask = dummy.kw_mask;
-       }
+       if (is_cn20k(rvu->pdev))
+               max_kw = NPC_KWS_IN_KEY_SZ_8;
+       else
+               max_kw = NPC_KWS_IN_KEY_SZ_7;
 
        for (i = 0; i < max_kw; i++) {
                if (!field->kw_mask[i])
@@ -1315,14 +1310,14 @@ npc_populate_mcam_mdata(struct rvu *rvu,
                mdata->kw_mask = cn20k_entry->kw_mask;
                mdata->action = &cn20k_entry->action;
                mdata->vtag_action = &cn20k_entry->vtag_action;
-               mdata->max_kw = NPC_CN20K_MAX_KWS_IN_KEY;
+               mdata->max_kw = NPC_KWS_IN_KEY_SZ_8;
                return;
        }
        mdata->kw = entry->kw;
        mdata->kw_mask = entry->kw_mask;
        mdata->action = &entry->action;
        mdata->vtag_action = &entry->vtag_action;
-       mdata->max_kw = NPC_MAX_KWS_IN_KEY;
+       mdata->max_kw = NPC_KWS_IN_KEY_SZ_7;
 }
 
 static int npc_update_rx_entry(struct rvu *rvu, struct rvu_pfvf *pfvf,