1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell RVU Admin Function driver
4 * Copyright (C) 2018 Marvell.
8 #include <linux/bitfield.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
12 #include "rvu_struct.h"
17 #include "npc_profile.h"
19 #define RSVD_MCAM_ENTRIES_PER_PF 3 /* Broadcast, Promisc and AllMulticast */
20 #define RSVD_MCAM_ENTRIES_PER_NIXLF 1 /* Ucast for LFs */
22 #define NPC_PARSE_RESULT_DMAC_OFFSET 8
23 #define NPC_HW_TSTAMP_OFFSET 8ULL
24 #define NPC_KEX_CHAN_MASK 0xFFFULL
25 #define NPC_KEX_PF_FUNC_MASK 0xFFFFULL
27 #define ALIGN_8B_CEIL(__a) (((__a) + 7) & (-8))
29 static const char def_pfl_name[] = "default";
31 static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mcam,
32 int blkaddr, u16 pcifunc);
33 static void npc_mcam_free_all_counters(struct rvu *rvu, struct npc_mcam *mcam,
36 bool is_npc_intf_tx(u8 intf)
38 return !!(intf & 0x1);
41 bool is_npc_intf_rx(u8 intf)
46 bool is_npc_interface_valid(struct rvu *rvu, u8 intf)
48 struct rvu_hwinfo *hw = rvu->hw;
50 return intf < hw->npc_intfs;
53 int rvu_npc_get_tx_nibble_cfg(struct rvu *rvu, u64 nibble_ena)
55 /* Due to a HW issue in these silicon versions, parse nibble enable
56 * configuration has to be identical for both Rx and Tx interfaces.
58 if (is_rvu_96xx_B0(rvu))
63 static int npc_mcam_verify_pf_func(struct rvu *rvu,
64 struct mcam_entry *entry_data, u8 intf,
67 u16 pf_func, pf_func_mask;
69 if (is_npc_intf_rx(intf))
72 pf_func_mask = (entry_data->kw_mask[0] >> 32) &
74 pf_func = (entry_data->kw[0] >> 32) & NPC_KEX_PF_FUNC_MASK;
76 pf_func = be16_to_cpu((__force __be16)pf_func);
77 if (pf_func_mask != NPC_KEX_PF_FUNC_MASK ||
78 ((pf_func & ~RVU_PFVF_FUNC_MASK) !=
79 (pcifunc & ~RVU_PFVF_FUNC_MASK)))
85 void rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf)
90 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
94 /* Config CPI base for the PKIND */
95 val = pkind | 1ULL << 62;
96 rvu_write64(rvu, blkaddr, NPC_AF_PKINDX_CPI_DEFX(pkind, 0), val);
99 int rvu_npc_get_pkind(struct rvu *rvu, u16 pf)
101 struct npc_pkind *pkind = &rvu->hw->pkind;
105 for (i = 0; i < pkind->rsrc.max; i++) {
106 map = pkind->pfchan_map[i];
107 if (((map >> 16) & 0x3F) == pf)
113 #define NPC_AF_ACTION0_PTR_ADVANCE GENMASK_ULL(27, 20)
115 int npc_config_ts_kpuaction(struct rvu *rvu, int pf, u16 pcifunc, bool enable)
120 pkind = rvu_npc_get_pkind(rvu, pf);
122 dev_err(rvu->dev, "%s: pkind not mapped\n", __func__);
126 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, pcifunc);
128 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
132 val = rvu_read64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind));
133 val &= ~NPC_AF_ACTION0_PTR_ADVANCE;
134 /* If timestamp is enabled then configure NPC to shift 8 bytes */
136 val |= FIELD_PREP(NPC_AF_ACTION0_PTR_ADVANCE,
137 NPC_HW_TSTAMP_OFFSET);
138 rvu_write64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind), val);
143 static int npc_get_ucast_mcam_index(struct npc_mcam *mcam, u16 pcifunc,
146 struct rvu_hwinfo *hw = container_of(mcam, struct rvu_hwinfo, mcam);
147 struct rvu *rvu = hw->rvu;
148 int blkaddr = 0, max = 0;
149 struct rvu_block *block;
150 struct rvu_pfvf *pfvf;
152 pfvf = rvu_get_pfvf(rvu, pcifunc);
153 /* Given a PF/VF and NIX LF number calculate the unicast mcam
154 * entry index based on the NIX block assigned to the PF/VF.
156 blkaddr = rvu_get_next_nix_blkaddr(rvu, blkaddr);
158 if (pfvf->nix_blkaddr == blkaddr)
160 block = &rvu->hw->block[blkaddr];
161 max += block->lf.max;
162 blkaddr = rvu_get_next_nix_blkaddr(rvu, blkaddr);
165 return mcam->nixlf_offset + (max + nixlf) * RSVD_MCAM_ENTRIES_PER_NIXLF;
168 int npc_get_nixlf_mcam_index(struct npc_mcam *mcam,
169 u16 pcifunc, int nixlf, int type)
171 int pf = rvu_get_pf(pcifunc);
174 /* Check if this is for a PF */
175 if (pf && !(pcifunc & RVU_PFVF_FUNC_MASK)) {
176 /* Reserved entries exclude PF0 */
178 index = mcam->pf_offset + (pf * RSVD_MCAM_ENTRIES_PER_PF);
179 /* Broadcast address matching entry should be first so
180 * that the packet can be replicated to all VFs.
182 if (type == NIXLF_BCAST_ENTRY)
184 else if (type == NIXLF_ALLMULTI_ENTRY)
186 else if (type == NIXLF_PROMISC_ENTRY)
190 return npc_get_ucast_mcam_index(mcam, pcifunc, nixlf);
193 int npc_get_bank(struct npc_mcam *mcam, int index)
195 int bank = index / mcam->banksize;
197 /* 0,1 & 2,3 banks are combined for this keysize */
198 if (mcam->keysize == NPC_MCAM_KEY_X2)
204 bool is_mcam_entry_enabled(struct rvu *rvu, struct npc_mcam *mcam,
205 int blkaddr, int index)
207 int bank = npc_get_bank(mcam, index);
210 index &= (mcam->banksize - 1);
211 cfg = rvu_read64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_CFG(index, bank));
215 void npc_enable_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
216 int blkaddr, int index, bool enable)
218 int bank = npc_get_bank(mcam, index);
221 index &= (mcam->banksize - 1);
222 for (; bank < (actbank + mcam->banks_per_entry); bank++) {
223 rvu_write64(rvu, blkaddr,
224 NPC_AF_MCAMEX_BANKX_CFG(index, bank),
229 static void npc_clear_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
230 int blkaddr, int index)
232 int bank = npc_get_bank(mcam, index);
235 index &= (mcam->banksize - 1);
236 for (; bank < (actbank + mcam->banks_per_entry); bank++) {
237 rvu_write64(rvu, blkaddr,
238 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 1), 0);
239 rvu_write64(rvu, blkaddr,
240 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 0), 0);
242 rvu_write64(rvu, blkaddr,
243 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 1), 0);
244 rvu_write64(rvu, blkaddr,
245 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 0), 0);
247 rvu_write64(rvu, blkaddr,
248 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 1), 0);
249 rvu_write64(rvu, blkaddr,
250 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 0), 0);
254 static void npc_get_keyword(struct mcam_entry *entry, int idx,
255 u64 *cam0, u64 *cam1)
259 #define CAM_MASK(n) (BIT_ULL(n) - 1)
261 /* 0, 2, 4, 6 indices refer to BANKX_CAMX_W0 and
262 * 1, 3, 5, 7 indices refer to BANKX_CAMX_W1.
264 * Also, only 48 bits of BANKX_CAMX_W1 are valid.
268 /* BANK(X)_CAM_W0<63:0> = MCAM_KEY[KW0]<63:0> */
269 *cam1 = entry->kw[0];
270 kw_mask = entry->kw_mask[0];
273 /* BANK(X)_CAM_W1<47:0> = MCAM_KEY[KW1]<47:0> */
274 *cam1 = entry->kw[1] & CAM_MASK(48);
275 kw_mask = entry->kw_mask[1] & CAM_MASK(48);
278 /* BANK(X + 1)_CAM_W0<15:0> = MCAM_KEY[KW1]<63:48>
279 * BANK(X + 1)_CAM_W0<63:16> = MCAM_KEY[KW2]<47:0>
281 *cam1 = (entry->kw[1] >> 48) & CAM_MASK(16);
282 *cam1 |= ((entry->kw[2] & CAM_MASK(48)) << 16);
283 kw_mask = (entry->kw_mask[1] >> 48) & CAM_MASK(16);
284 kw_mask |= ((entry->kw_mask[2] & CAM_MASK(48)) << 16);
287 /* BANK(X + 1)_CAM_W1<15:0> = MCAM_KEY[KW2]<63:48>
288 * BANK(X + 1)_CAM_W1<47:16> = MCAM_KEY[KW3]<31:0>
290 *cam1 = (entry->kw[2] >> 48) & CAM_MASK(16);
291 *cam1 |= ((entry->kw[3] & CAM_MASK(32)) << 16);
292 kw_mask = (entry->kw_mask[2] >> 48) & CAM_MASK(16);
293 kw_mask |= ((entry->kw_mask[3] & CAM_MASK(32)) << 16);
296 /* BANK(X + 2)_CAM_W0<31:0> = MCAM_KEY[KW3]<63:32>
297 * BANK(X + 2)_CAM_W0<63:32> = MCAM_KEY[KW4]<31:0>
299 *cam1 = (entry->kw[3] >> 32) & CAM_MASK(32);
300 *cam1 |= ((entry->kw[4] & CAM_MASK(32)) << 32);
301 kw_mask = (entry->kw_mask[3] >> 32) & CAM_MASK(32);
302 kw_mask |= ((entry->kw_mask[4] & CAM_MASK(32)) << 32);
305 /* BANK(X + 2)_CAM_W1<31:0> = MCAM_KEY[KW4]<63:32>
306 * BANK(X + 2)_CAM_W1<47:32> = MCAM_KEY[KW5]<15:0>
308 *cam1 = (entry->kw[4] >> 32) & CAM_MASK(32);
309 *cam1 |= ((entry->kw[5] & CAM_MASK(16)) << 32);
310 kw_mask = (entry->kw_mask[4] >> 32) & CAM_MASK(32);
311 kw_mask |= ((entry->kw_mask[5] & CAM_MASK(16)) << 32);
314 /* BANK(X + 3)_CAM_W0<47:0> = MCAM_KEY[KW5]<63:16>
315 * BANK(X + 3)_CAM_W0<63:48> = MCAM_KEY[KW6]<15:0>
317 *cam1 = (entry->kw[5] >> 16) & CAM_MASK(48);
318 *cam1 |= ((entry->kw[6] & CAM_MASK(16)) << 48);
319 kw_mask = (entry->kw_mask[5] >> 16) & CAM_MASK(48);
320 kw_mask |= ((entry->kw_mask[6] & CAM_MASK(16)) << 48);
323 /* BANK(X + 3)_CAM_W1<47:0> = MCAM_KEY[KW6]<63:16> */
324 *cam1 = (entry->kw[6] >> 16) & CAM_MASK(48);
325 kw_mask = (entry->kw_mask[6] >> 16) & CAM_MASK(48);
330 *cam0 = ~*cam1 & kw_mask;
333 static void npc_fill_entryword(struct mcam_entry *entry, int idx,
336 /* Similar to npc_get_keyword, but fills mcam_entry structure from
342 entry->kw_mask[0] = cam1 ^ cam0;
346 entry->kw_mask[1] = cam1 ^ cam0;
349 entry->kw[1] |= (cam1 & CAM_MASK(16)) << 48;
350 entry->kw[2] = (cam1 >> 16) & CAM_MASK(48);
351 entry->kw_mask[1] |= ((cam1 ^ cam0) & CAM_MASK(16)) << 48;
352 entry->kw_mask[2] = ((cam1 ^ cam0) >> 16) & CAM_MASK(48);
355 entry->kw[2] |= (cam1 & CAM_MASK(16)) << 48;
356 entry->kw[3] = (cam1 >> 16) & CAM_MASK(32);
357 entry->kw_mask[2] |= ((cam1 ^ cam0) & CAM_MASK(16)) << 48;
358 entry->kw_mask[3] = ((cam1 ^ cam0) >> 16) & CAM_MASK(32);
361 entry->kw[3] |= (cam1 & CAM_MASK(32)) << 32;
362 entry->kw[4] = (cam1 >> 32) & CAM_MASK(32);
363 entry->kw_mask[3] |= ((cam1 ^ cam0) & CAM_MASK(32)) << 32;
364 entry->kw_mask[4] = ((cam1 ^ cam0) >> 32) & CAM_MASK(32);
367 entry->kw[4] |= (cam1 & CAM_MASK(32)) << 32;
368 entry->kw[5] = (cam1 >> 32) & CAM_MASK(16);
369 entry->kw_mask[4] |= ((cam1 ^ cam0) & CAM_MASK(32)) << 32;
370 entry->kw_mask[5] = ((cam1 ^ cam0) >> 32) & CAM_MASK(16);
373 entry->kw[5] |= (cam1 & CAM_MASK(48)) << 16;
374 entry->kw[6] = (cam1 >> 48) & CAM_MASK(16);
375 entry->kw_mask[5] |= ((cam1 ^ cam0) & CAM_MASK(48)) << 16;
376 entry->kw_mask[6] = ((cam1 ^ cam0) >> 48) & CAM_MASK(16);
379 entry->kw[6] |= (cam1 & CAM_MASK(48)) << 16;
380 entry->kw_mask[6] |= ((cam1 ^ cam0) & CAM_MASK(48)) << 16;
385 static u64 npc_get_default_entry_action(struct rvu *rvu, struct npc_mcam *mcam,
386 int blkaddr, u16 pf_func)
388 int bank, nixlf, index;
390 /* get ucast entry rule entry index */
391 nix_get_nixlf(rvu, pf_func, &nixlf, NULL);
392 index = npc_get_nixlf_mcam_index(mcam, pf_func, nixlf,
394 bank = npc_get_bank(mcam, index);
395 index &= (mcam->banksize - 1);
397 return rvu_read64(rvu, blkaddr,
398 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
401 static void npc_fixup_vf_rule(struct rvu *rvu, struct npc_mcam *mcam,
402 int blkaddr, int index, struct mcam_entry *entry,
405 u16 owner, target_func;
406 struct rvu_pfvf *pfvf;
409 owner = mcam->entry2pfvf_map[index];
410 target_func = (entry->action >> 4) & 0xffff;
411 /* do nothing when target is LBK/PF or owner is not PF */
412 if (is_pffunc_af(owner) || is_afvf(target_func) ||
413 (owner & RVU_PFVF_FUNC_MASK) ||
414 !(target_func & RVU_PFVF_FUNC_MASK))
417 /* save entry2target_pffunc */
418 pfvf = rvu_get_pfvf(rvu, target_func);
419 mcam->entry2target_pffunc[index] = target_func;
421 /* don't enable rule when nixlf not attached or initialized */
422 if (!(is_nixlf_attached(rvu, target_func) &&
423 test_bit(NIXLF_INITIALIZED, &pfvf->flags)))
426 /* copy VF default entry action to the VF mcam entry */
427 rx_action = npc_get_default_entry_action(rvu, mcam, blkaddr,
430 entry->action = rx_action;
433 static void npc_config_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
434 int blkaddr, int index, u8 intf,
435 struct mcam_entry *entry, bool enable)
437 int bank = npc_get_bank(mcam, index);
438 int kw = 0, actbank, actindex;
439 u8 tx_intf_mask = ~intf & 0x3;
443 actbank = bank; /* Save bank id, to set action later on */
445 index &= (mcam->banksize - 1);
447 /* Disable before mcam entry update */
448 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex, false);
450 /* Clear mcam entry to avoid writes being suppressed by NPC */
451 npc_clear_mcam_entry(rvu, mcam, blkaddr, actindex);
453 /* CAM1 takes the comparison value and
454 * CAM0 specifies match for a bit in key being '0' or '1' or 'dontcare'.
455 * CAM1<n> = 0 & CAM0<n> = 1 => match if key<n> = 0
456 * CAM1<n> = 1 & CAM0<n> = 0 => match if key<n> = 1
457 * CAM1<n> = 0 & CAM0<n> = 0 => always match i.e dontcare.
459 for (; bank < (actbank + mcam->banks_per_entry); bank++, kw = kw + 2) {
460 /* Interface should be set in all banks */
461 if (is_npc_intf_tx(intf)) {
462 /* Last bit must be set and rest don't care
466 tx_intf = intf & tx_intf_mask;
467 tx_intf_mask = ~tx_intf & tx_intf_mask;
470 rvu_write64(rvu, blkaddr,
471 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 1),
473 rvu_write64(rvu, blkaddr,
474 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 0),
477 /* Set the match key */
478 npc_get_keyword(entry, kw, &cam0, &cam1);
479 rvu_write64(rvu, blkaddr,
480 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 1), cam1);
481 rvu_write64(rvu, blkaddr,
482 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 0), cam0);
484 npc_get_keyword(entry, kw + 1, &cam0, &cam1);
485 rvu_write64(rvu, blkaddr,
486 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 1), cam1);
487 rvu_write64(rvu, blkaddr,
488 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 0), cam0);
491 /* PF installing VF rule */
492 if (intf == NIX_INTF_RX && actindex < mcam->bmap_entries)
493 npc_fixup_vf_rule(rvu, mcam, blkaddr, index, entry, &enable);
496 rvu_write64(rvu, blkaddr,
497 NPC_AF_MCAMEX_BANKX_ACTION(index, actbank), entry->action);
499 /* Set TAG 'action' */
500 rvu_write64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_TAG_ACT(index, actbank),
503 /* Enable the entry */
505 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex, true);
508 void npc_read_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
509 int blkaddr, u16 src,
510 struct mcam_entry *entry, u8 *intf, u8 *ena)
512 int sbank = npc_get_bank(mcam, src);
516 src &= (mcam->banksize - 1);
519 for (; bank < (sbank + mcam->banks_per_entry); bank++, kw = kw + 2) {
520 cam1 = rvu_read64(rvu, blkaddr,
521 NPC_AF_MCAMEX_BANKX_CAMX_W0(src, bank, 1));
522 cam0 = rvu_read64(rvu, blkaddr,
523 NPC_AF_MCAMEX_BANKX_CAMX_W0(src, bank, 0));
524 npc_fill_entryword(entry, kw, cam0, cam1);
526 cam1 = rvu_read64(rvu, blkaddr,
527 NPC_AF_MCAMEX_BANKX_CAMX_W1(src, bank, 1));
528 cam0 = rvu_read64(rvu, blkaddr,
529 NPC_AF_MCAMEX_BANKX_CAMX_W1(src, bank, 0));
530 npc_fill_entryword(entry, kw + 1, cam0, cam1);
533 entry->action = rvu_read64(rvu, blkaddr,
534 NPC_AF_MCAMEX_BANKX_ACTION(src, sbank));
536 rvu_read64(rvu, blkaddr,
537 NPC_AF_MCAMEX_BANKX_TAG_ACT(src, sbank));
538 *intf = rvu_read64(rvu, blkaddr,
539 NPC_AF_MCAMEX_BANKX_CAMX_INTF(src, sbank, 1)) & 3;
540 *ena = rvu_read64(rvu, blkaddr,
541 NPC_AF_MCAMEX_BANKX_CFG(src, sbank)) & 1;
544 static void npc_copy_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
545 int blkaddr, u16 src, u16 dest)
547 int dbank = npc_get_bank(mcam, dest);
548 int sbank = npc_get_bank(mcam, src);
552 src &= (mcam->banksize - 1);
553 dest &= (mcam->banksize - 1);
555 /* Copy INTF's, W0's, W1's CAM0 and CAM1 configuration */
556 for (bank = 0; bank < mcam->banks_per_entry; bank++) {
557 sreg = NPC_AF_MCAMEX_BANKX_CAMX_INTF(src, sbank + bank, 0);
558 dreg = NPC_AF_MCAMEX_BANKX_CAMX_INTF(dest, dbank + bank, 0);
559 for (i = 0; i < 6; i++) {
560 cfg = rvu_read64(rvu, blkaddr, sreg + (i * 8));
561 rvu_write64(rvu, blkaddr, dreg + (i * 8), cfg);
566 cfg = rvu_read64(rvu, blkaddr,
567 NPC_AF_MCAMEX_BANKX_ACTION(src, sbank));
568 rvu_write64(rvu, blkaddr,
569 NPC_AF_MCAMEX_BANKX_ACTION(dest, dbank), cfg);
571 /* Copy TAG action */
572 cfg = rvu_read64(rvu, blkaddr,
573 NPC_AF_MCAMEX_BANKX_TAG_ACT(src, sbank));
574 rvu_write64(rvu, blkaddr,
575 NPC_AF_MCAMEX_BANKX_TAG_ACT(dest, dbank), cfg);
577 /* Enable or disable */
578 cfg = rvu_read64(rvu, blkaddr,
579 NPC_AF_MCAMEX_BANKX_CFG(src, sbank));
580 rvu_write64(rvu, blkaddr,
581 NPC_AF_MCAMEX_BANKX_CFG(dest, dbank), cfg);
584 static u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
585 int blkaddr, int index)
587 int bank = npc_get_bank(mcam, index);
589 index &= (mcam->banksize - 1);
590 return rvu_read64(rvu, blkaddr,
591 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
594 void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
595 int nixlf, u64 chan, u8 *mac_addr)
597 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
598 struct npc_install_flow_req req = { 0 };
599 struct npc_install_flow_rsp rsp = { 0 };
600 struct npc_mcam *mcam = &rvu->hw->mcam;
601 struct nix_rx_action action;
604 /* AF's and SDP VFs work in promiscuous mode */
605 if (is_afvf(pcifunc) || is_sdp_vf(pcifunc))
608 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
612 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
613 nixlf, NIXLF_UCAST_ENTRY);
615 /* Don't change the action if entry is already enabled
616 * Otherwise RSS action may get overwritten.
618 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, index)) {
619 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
622 *(u64 *)&action = 0x00;
623 action.op = NIX_RX_ACTIONOP_UCAST;
624 action.pf_func = pcifunc;
627 req.default_rule = 1;
628 ether_addr_copy(req.packet.dmac, mac_addr);
629 eth_broadcast_addr((u8 *)&req.mask.dmac);
630 req.features = BIT_ULL(NPC_DMAC);
632 req.chan_mask = 0xFFFU;
633 req.intf = pfvf->nix_rx_intf;
635 req.hdr.pcifunc = 0; /* AF is requester */
636 req.vf = action.pf_func;
637 req.index = action.index;
638 req.match_id = action.match_id;
639 req.flow_key_alg = action.flow_key_alg;
641 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
644 void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
645 int nixlf, u64 chan, u8 chan_cnt)
647 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
648 struct npc_install_flow_req req = { 0 };
649 struct npc_install_flow_rsp rsp = { 0 };
650 struct npc_mcam *mcam = &rvu->hw->mcam;
651 struct rvu_hwinfo *hw = rvu->hw;
652 int blkaddr, ucast_idx, index;
653 struct nix_rx_action action;
656 if (!hw->cap.nix_rx_multicast && is_cgx_vf(rvu, pcifunc))
659 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
663 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
664 nixlf, NIXLF_PROMISC_ENTRY);
666 if (is_cgx_vf(rvu, pcifunc))
667 index = npc_get_nixlf_mcam_index(mcam,
668 pcifunc & ~RVU_PFVF_FUNC_MASK,
669 nixlf, NIXLF_PROMISC_ENTRY);
671 /* If the corresponding PF's ucast action is RSS,
672 * use the same action for promisc also
674 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
675 nixlf, NIXLF_UCAST_ENTRY);
676 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
677 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
680 if (action.op != NIX_RX_ACTIONOP_RSS) {
681 *(u64 *)&action = 0x00;
682 action.op = NIX_RX_ACTIONOP_UCAST;
685 /* RX_ACTION set to MCAST for CGX PF's */
686 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list &&
687 is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc))) {
688 *(u64 *)&action = 0x00;
689 action.op = NIX_RX_ACTIONOP_MCAST;
690 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
691 action.index = pfvf->promisc_mce_idx;
694 /* For cn10k the upper two bits of the channel number are
695 * cpt channel number. with masking out these bits in the
696 * mcam entry, same entry used for NIX will allow packets
697 * received from cpt for parsing.
699 if (!is_rvu_otx2(rvu)) {
700 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
702 req.chan_mask = 0xFFFU;
706 if (!is_power_of_2(chan_cnt)) {
708 "%s: channel count more than 1, must be power of 2\n", __func__);
711 relaxed_mask = GENMASK_ULL(BITS_PER_LONG_LONG - 1,
713 req.chan_mask &= relaxed_mask;
717 req.intf = pfvf->nix_rx_intf;
720 req.hdr.pcifunc = 0; /* AF is requester */
722 req.index = action.index;
723 req.match_id = action.match_id;
724 req.flow_key_alg = action.flow_key_alg;
726 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
729 void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc,
730 int nixlf, bool enable)
732 struct npc_mcam *mcam = &rvu->hw->mcam;
735 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
739 /* Get 'pcifunc' of PF device */
740 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
742 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
743 nixlf, NIXLF_PROMISC_ENTRY);
744 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
747 void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
750 struct rvu_pfvf *pfvf;
751 struct npc_install_flow_req req = { 0 };
752 struct npc_install_flow_rsp rsp = { 0 };
753 struct npc_mcam *mcam = &rvu->hw->mcam;
754 struct rvu_hwinfo *hw = rvu->hw;
757 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
762 if (is_afvf(pcifunc))
765 /* If pkt replication is not supported,
766 * then only PF is allowed to add a bcast match entry.
768 if (!hw->cap.nix_rx_multicast && is_vf(pcifunc))
771 /* Get 'pcifunc' of PF device */
772 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
773 pfvf = rvu_get_pfvf(rvu, pcifunc);
774 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
775 nixlf, NIXLF_BCAST_ENTRY);
777 if (!hw->cap.nix_rx_multicast) {
778 /* Early silicon doesn't support pkt replication,
779 * so install entry with UCAST action, so that PF
780 * receives all broadcast packets.
782 req.op = NIX_RX_ACTIONOP_UCAST;
784 req.op = NIX_RX_ACTIONOP_MCAST;
785 req.index = pfvf->bcast_mce_idx;
788 eth_broadcast_addr((u8 *)&req.packet.dmac);
789 eth_broadcast_addr((u8 *)&req.mask.dmac);
790 req.features = BIT_ULL(NPC_DMAC);
792 req.chan_mask = 0xFFFU;
793 req.intf = pfvf->nix_rx_intf;
795 req.hdr.pcifunc = 0; /* AF is requester */
798 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
801 void rvu_npc_enable_bcast_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
804 struct npc_mcam *mcam = &rvu->hw->mcam;
807 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
811 /* Get 'pcifunc' of PF device */
812 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
814 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
816 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
819 void rvu_npc_install_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
822 struct npc_install_flow_req req = { 0 };
823 struct npc_install_flow_rsp rsp = { 0 };
824 struct npc_mcam *mcam = &rvu->hw->mcam;
825 struct rvu_hwinfo *hw = rvu->hw;
826 int blkaddr, ucast_idx, index;
827 u8 mac_addr[ETH_ALEN] = { 0 };
828 struct nix_rx_action action;
829 struct rvu_pfvf *pfvf;
832 /* Only CGX PF/VF can add allmulticast entry */
833 if (is_afvf(pcifunc) && is_sdp_vf(pcifunc))
836 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
840 /* Get 'pcifunc' of PF device */
841 vf_func = pcifunc & RVU_PFVF_FUNC_MASK;
842 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
843 pfvf = rvu_get_pfvf(rvu, pcifunc);
844 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
845 nixlf, NIXLF_ALLMULTI_ENTRY);
847 /* If the corresponding PF's ucast action is RSS,
848 * use the same action for multicast entry also
850 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
851 nixlf, NIXLF_UCAST_ENTRY);
852 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
853 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
856 if (action.op != NIX_RX_ACTIONOP_RSS) {
857 *(u64 *)&action = 0x00;
858 action.op = NIX_RX_ACTIONOP_UCAST;
859 action.pf_func = pcifunc;
862 /* RX_ACTION set to MCAST for CGX PF's */
863 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list) {
864 *(u64 *)&action = 0x00;
865 action.op = NIX_RX_ACTIONOP_MCAST;
866 action.index = pfvf->mcast_mce_idx;
869 mac_addr[0] = 0x01; /* LSB bit of 1st byte in DMAC */
870 ether_addr_copy(req.packet.dmac, mac_addr);
871 ether_addr_copy(req.mask.dmac, mac_addr);
872 req.features = BIT_ULL(NPC_DMAC);
874 /* For cn10k the upper two bits of the channel number are
875 * cpt channel number. with masking out these bits in the
876 * mcam entry, same entry used for NIX will allow packets
877 * received from cpt for parsing.
879 if (!is_rvu_otx2(rvu))
880 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
882 req.chan_mask = 0xFFFU;
885 req.intf = pfvf->nix_rx_intf;
888 req.hdr.pcifunc = 0; /* AF is requester */
889 req.vf = pcifunc | vf_func;
890 req.index = action.index;
891 req.match_id = action.match_id;
892 req.flow_key_alg = action.flow_key_alg;
894 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
897 void rvu_npc_enable_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
900 struct npc_mcam *mcam = &rvu->hw->mcam;
903 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
907 /* Get 'pcifunc' of PF device */
908 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
910 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
911 NIXLF_ALLMULTI_ENTRY);
912 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
915 static void npc_update_vf_flow_entry(struct rvu *rvu, struct npc_mcam *mcam,
916 int blkaddr, u16 pcifunc, u64 rx_action)
918 int actindex, index, bank, entry;
921 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
924 mutex_lock(&mcam->lock);
925 for (index = 0; index < mcam->bmap_entries; index++) {
926 if (mcam->entry2target_pffunc[index] == pcifunc) {
927 bank = npc_get_bank(mcam, index);
929 entry = index & (mcam->banksize - 1);
931 /* read vf flow entry enable status */
932 enable = is_mcam_entry_enabled(rvu, mcam, blkaddr,
934 /* disable before mcam entry update */
935 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex,
937 /* update 'action' */
938 rvu_write64(rvu, blkaddr,
939 NPC_AF_MCAMEX_BANKX_ACTION(entry, bank),
942 npc_enable_mcam_entry(rvu, mcam, blkaddr,
946 mutex_unlock(&mcam->lock);
949 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
950 int group, int alg_idx, int mcam_index)
952 struct npc_mcam *mcam = &rvu->hw->mcam;
953 struct rvu_hwinfo *hw = rvu->hw;
954 struct nix_rx_action action;
955 int blkaddr, index, bank;
956 struct rvu_pfvf *pfvf;
958 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
962 /* Check if this is for reserved default entry */
963 if (mcam_index < 0) {
964 if (group != DEFAULT_RSS_CONTEXT_GROUP)
966 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
967 nixlf, NIXLF_UCAST_ENTRY);
969 /* TODO: validate this mcam index */
973 if (index >= mcam->total_entries)
976 bank = npc_get_bank(mcam, index);
977 index &= (mcam->banksize - 1);
979 *(u64 *)&action = rvu_read64(rvu, blkaddr,
980 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
981 /* Ignore if no action was set earlier */
982 if (!*(u64 *)&action)
985 action.op = NIX_RX_ACTIONOP_RSS;
986 action.pf_func = pcifunc;
987 action.index = group;
988 action.flow_key_alg = alg_idx;
990 rvu_write64(rvu, blkaddr,
991 NPC_AF_MCAMEX_BANKX_ACTION(index, bank), *(u64 *)&action);
993 /* update the VF flow rule action with the VF default entry action */
995 npc_update_vf_flow_entry(rvu, mcam, blkaddr, pcifunc,
998 /* update the action change in default rule */
999 pfvf = rvu_get_pfvf(rvu, pcifunc);
1000 if (pfvf->def_ucast_rule)
1001 pfvf->def_ucast_rule->rx_action = action;
1003 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1004 nixlf, NIXLF_PROMISC_ENTRY);
1006 /* If PF's promiscuous entry is enabled,
1007 * Set RSS action for that entry as well
1009 if ((!hw->cap.nix_rx_multicast || !pfvf->use_mce_list) &&
1010 is_mcam_entry_enabled(rvu, mcam, blkaddr, index)) {
1011 bank = npc_get_bank(mcam, index);
1012 index &= (mcam->banksize - 1);
1014 rvu_write64(rvu, blkaddr,
1015 NPC_AF_MCAMEX_BANKX_ACTION(index, bank),
1020 void npc_enadis_default_mce_entry(struct rvu *rvu, u16 pcifunc,
1021 int nixlf, int type, bool enable)
1023 struct npc_mcam *mcam = &rvu->hw->mcam;
1024 struct rvu_hwinfo *hw = rvu->hw;
1025 struct nix_mce_list *mce_list;
1026 int index, blkaddr, mce_idx;
1027 struct rvu_pfvf *pfvf;
1029 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1033 index = npc_get_nixlf_mcam_index(mcam, pcifunc & ~RVU_PFVF_FUNC_MASK,
1036 /* disable MCAM entry when packet replication is not supported by hw */
1037 if (!hw->cap.nix_rx_multicast && !is_vf(pcifunc)) {
1038 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1042 /* return incase mce list is not enabled */
1043 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
1044 if (hw->cap.nix_rx_multicast && is_vf(pcifunc) &&
1045 type != NIXLF_BCAST_ENTRY && !pfvf->use_mce_list)
1048 nix_get_mce_list(rvu, pcifunc, type, &mce_list, &mce_idx);
1050 nix_update_mce_list(rvu, pcifunc, mce_list,
1051 mce_idx, index, enable);
1053 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1056 static void npc_enadis_default_entries(struct rvu *rvu, u16 pcifunc,
1057 int nixlf, bool enable)
1059 struct npc_mcam *mcam = &rvu->hw->mcam;
1062 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1066 /* Ucast MCAM match entry of this PF/VF */
1067 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1068 nixlf, NIXLF_UCAST_ENTRY);
1069 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1071 /* Nothing to do for VFs, on platforms where pkt replication
1074 if ((pcifunc & RVU_PFVF_FUNC_MASK) && !rvu->hw->cap.nix_rx_multicast)
1077 /* add/delete pf_func to broadcast MCE list */
1078 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1079 NIXLF_BCAST_ENTRY, enable);
1082 void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1084 npc_enadis_default_entries(rvu, pcifunc, nixlf, false);
1086 /* Delete multicast and promisc MCAM entries */
1087 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1088 NIXLF_ALLMULTI_ENTRY, false);
1089 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1090 NIXLF_PROMISC_ENTRY, false);
1093 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1095 /* Enables only broadcast match entry. Promisc/Allmulti are enabled
1096 * in set_rx_mode mbox handler.
1098 npc_enadis_default_entries(rvu, pcifunc, nixlf, true);
1101 void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1103 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
1104 struct npc_mcam *mcam = &rvu->hw->mcam;
1105 struct rvu_npc_mcam_rule *rule, *tmp;
1108 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1112 mutex_lock(&mcam->lock);
1114 /* Disable MCAM entries directing traffic to this 'pcifunc' */
1115 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1116 if (is_npc_intf_rx(rule->intf) &&
1117 rule->rx_action.pf_func == pcifunc &&
1118 rule->rx_action.op != NIX_RX_ACTIONOP_MCAST) {
1119 npc_enable_mcam_entry(rvu, mcam, blkaddr,
1120 rule->entry, false);
1121 rule->enable = false;
1122 /* Indicate that default rule is disabled */
1123 if (rule->default_rule) {
1124 pfvf->def_ucast_rule = NULL;
1125 list_del(&rule->list);
1131 mutex_unlock(&mcam->lock);
1133 npc_mcam_disable_flows(rvu, pcifunc);
1135 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1138 void rvu_npc_free_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1140 struct npc_mcam *mcam = &rvu->hw->mcam;
1141 struct rvu_npc_mcam_rule *rule, *tmp;
1144 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1148 mutex_lock(&mcam->lock);
1150 /* Free all MCAM entries owned by this 'pcifunc' */
1151 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
1153 /* Free all MCAM counters owned by this 'pcifunc' */
1154 npc_mcam_free_all_counters(rvu, mcam, pcifunc);
1156 /* Delete MCAM entries owned by this 'pcifunc' */
1157 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1158 if (rule->owner == pcifunc && !rule->default_rule) {
1159 list_del(&rule->list);
1164 mutex_unlock(&mcam->lock);
1166 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1169 #define SET_KEX_LD(intf, lid, ltype, ld, cfg) \
1170 rvu_write64(rvu, blkaddr, \
1171 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, ltype, ld), cfg)
1173 #define SET_KEX_LDFLAGS(intf, ld, flags, cfg) \
1174 rvu_write64(rvu, blkaddr, \
1175 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, flags), cfg)
1177 static void npc_program_mkex_rx(struct rvu *rvu, int blkaddr,
1178 struct npc_mcam_kex *mkex, u8 intf)
1180 int lid, lt, ld, fl;
1182 if (is_npc_intf_tx(intf))
1185 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1186 mkex->keyx_cfg[NIX_INTF_RX]);
1189 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1190 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1191 for (ld = 0; ld < NPC_MAX_LD; ld++)
1192 SET_KEX_LD(intf, lid, lt, ld,
1193 mkex->intf_lid_lt_ld[NIX_INTF_RX]
1197 /* Program LFLAGS */
1198 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1199 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1200 SET_KEX_LDFLAGS(intf, ld, fl,
1201 mkex->intf_ld_flags[NIX_INTF_RX]
1206 static void npc_program_mkex_tx(struct rvu *rvu, int blkaddr,
1207 struct npc_mcam_kex *mkex, u8 intf)
1209 int lid, lt, ld, fl;
1211 if (is_npc_intf_rx(intf))
1214 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1215 mkex->keyx_cfg[NIX_INTF_TX]);
1218 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1219 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1220 for (ld = 0; ld < NPC_MAX_LD; ld++)
1221 SET_KEX_LD(intf, lid, lt, ld,
1222 mkex->intf_lid_lt_ld[NIX_INTF_TX]
1226 /* Program LFLAGS */
1227 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1228 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1229 SET_KEX_LDFLAGS(intf, ld, fl,
1230 mkex->intf_ld_flags[NIX_INTF_TX]
1235 static void npc_program_mkex_profile(struct rvu *rvu, int blkaddr,
1236 struct npc_mcam_kex *mkex)
1238 struct rvu_hwinfo *hw = rvu->hw;
1242 for (ld = 0; ld < NPC_MAX_LD; ld++)
1243 rvu_write64(rvu, blkaddr, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld),
1244 mkex->kex_ld_flags[ld]);
1246 for (intf = 0; intf < hw->npc_intfs; intf++) {
1247 npc_program_mkex_rx(rvu, blkaddr, mkex, intf);
1248 npc_program_mkex_tx(rvu, blkaddr, mkex, intf);
1252 static int npc_fwdb_prfl_img_map(struct rvu *rvu, void __iomem **prfl_img_addr,
1255 u64 prfl_addr, prfl_sz;
1260 prfl_addr = rvu->fwdata->mcam_addr;
1261 prfl_sz = rvu->fwdata->mcam_sz;
1263 if (!prfl_addr || !prfl_sz)
1266 *prfl_img_addr = ioremap_wc(prfl_addr, prfl_sz);
1267 if (!(*prfl_img_addr))
1275 /* strtoull of "mkexprof" with base:36 */
1276 #define MKEX_END_SIGN 0xdeadbeef
1278 static void npc_load_mkex_profile(struct rvu *rvu, int blkaddr,
1279 const char *mkex_profile)
1281 struct device *dev = &rvu->pdev->dev;
1282 struct npc_mcam_kex *mcam_kex;
1283 void __iomem *mkex_prfl_addr = NULL;
1287 /* If user not selected mkex profile */
1288 if (rvu->kpu_fwdata_sz ||
1289 !strncmp(mkex_profile, def_pfl_name, MKEX_NAME_LEN))
1292 /* Setting up the mapping for mkex profile image */
1293 ret = npc_fwdb_prfl_img_map(rvu, &mkex_prfl_addr, &prfl_sz);
1297 mcam_kex = (struct npc_mcam_kex __force *)mkex_prfl_addr;
1299 while (((s64)prfl_sz > 0) && (mcam_kex->mkex_sign != MKEX_END_SIGN)) {
1300 /* Compare with mkex mod_param name string */
1301 if (mcam_kex->mkex_sign == MKEX_SIGN &&
1302 !strncmp(mcam_kex->name, mkex_profile, MKEX_NAME_LEN)) {
1303 /* Due to an errata (35786) in A0/B0 pass silicon,
1304 * parse nibble enable configuration has to be
1305 * identical for both Rx and Tx interfaces.
1307 if (!is_rvu_96xx_B0(rvu) ||
1308 mcam_kex->keyx_cfg[NIX_INTF_RX] == mcam_kex->keyx_cfg[NIX_INTF_TX])
1309 rvu->kpu.mkex = mcam_kex;
1314 prfl_sz -= sizeof(struct npc_mcam_kex);
1316 dev_warn(dev, "Failed to load requested profile: %s\n", mkex_profile);
1319 dev_info(rvu->dev, "Using %s mkex profile\n", rvu->kpu.mkex->name);
1320 /* Program selected mkex profile */
1321 npc_program_mkex_profile(rvu, blkaddr, rvu->kpu.mkex);
1323 iounmap(mkex_prfl_addr);
1326 static void npc_config_kpuaction(struct rvu *rvu, int blkaddr,
1327 const struct npc_kpu_profile_action *kpuaction,
1328 int kpu, int entry, bool pkind)
1330 struct npc_kpu_action0 action0 = {0};
1331 struct npc_kpu_action1 action1 = {0};
1334 action1.errlev = kpuaction->errlev;
1335 action1.errcode = kpuaction->errcode;
1336 action1.dp0_offset = kpuaction->dp0_offset;
1337 action1.dp1_offset = kpuaction->dp1_offset;
1338 action1.dp2_offset = kpuaction->dp2_offset;
1341 reg = NPC_AF_PKINDX_ACTION1(entry);
1343 reg = NPC_AF_KPUX_ENTRYX_ACTION1(kpu, entry);
1345 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action1);
1347 action0.byp_count = kpuaction->bypass_count;
1348 action0.capture_ena = kpuaction->cap_ena;
1349 action0.parse_done = kpuaction->parse_done;
1350 action0.next_state = kpuaction->next_state;
1351 action0.capture_lid = kpuaction->lid;
1352 action0.capture_ltype = kpuaction->ltype;
1353 action0.capture_flags = kpuaction->flags;
1354 action0.ptr_advance = kpuaction->ptr_advance;
1355 action0.var_len_offset = kpuaction->offset;
1356 action0.var_len_mask = kpuaction->mask;
1357 action0.var_len_right = kpuaction->right;
1358 action0.var_len_shift = kpuaction->shift;
1361 reg = NPC_AF_PKINDX_ACTION0(entry);
1363 reg = NPC_AF_KPUX_ENTRYX_ACTION0(kpu, entry);
1365 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action0);
1368 static void npc_config_kpucam(struct rvu *rvu, int blkaddr,
1369 const struct npc_kpu_profile_cam *kpucam,
1372 struct npc_kpu_cam cam0 = {0};
1373 struct npc_kpu_cam cam1 = {0};
1375 cam1.state = kpucam->state & kpucam->state_mask;
1376 cam1.dp0_data = kpucam->dp0 & kpucam->dp0_mask;
1377 cam1.dp1_data = kpucam->dp1 & kpucam->dp1_mask;
1378 cam1.dp2_data = kpucam->dp2 & kpucam->dp2_mask;
1380 cam0.state = ~kpucam->state & kpucam->state_mask;
1381 cam0.dp0_data = ~kpucam->dp0 & kpucam->dp0_mask;
1382 cam0.dp1_data = ~kpucam->dp1 & kpucam->dp1_mask;
1383 cam0.dp2_data = ~kpucam->dp2 & kpucam->dp2_mask;
1385 rvu_write64(rvu, blkaddr,
1386 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 0), *(u64 *)&cam0);
1387 rvu_write64(rvu, blkaddr,
1388 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 1), *(u64 *)&cam1);
1391 static inline u64 enable_mask(int count)
1393 return (((count) < 64) ? ~(BIT_ULL(count) - 1) : (0x00ULL));
1396 static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu,
1397 const struct npc_kpu_profile *profile)
1399 int entry, num_entries, max_entries;
1402 if (profile->cam_entries != profile->action_entries) {
1404 "KPU%d: CAM and action entries [%d != %d] not equal\n",
1405 kpu, profile->cam_entries, profile->action_entries);
1408 max_entries = rvu->hw->npc_kpu_entries;
1410 /* Program CAM match entries for previous KPU extracted data */
1411 num_entries = min_t(int, profile->cam_entries, max_entries);
1412 for (entry = 0; entry < num_entries; entry++)
1413 npc_config_kpucam(rvu, blkaddr,
1414 &profile->cam[entry], kpu, entry);
1416 /* Program this KPU's actions */
1417 num_entries = min_t(int, profile->action_entries, max_entries);
1418 for (entry = 0; entry < num_entries; entry++)
1419 npc_config_kpuaction(rvu, blkaddr, &profile->action[entry],
1422 /* Enable all programmed entries */
1423 num_entries = min_t(int, profile->action_entries, profile->cam_entries);
1424 entry_mask = enable_mask(num_entries);
1425 /* Disable first KPU_MAX_CST_ENT entries for built-in profile */
1426 if (!rvu->kpu.custom)
1427 entry_mask |= GENMASK_ULL(KPU_MAX_CST_ENT - 1, 0);
1428 rvu_write64(rvu, blkaddr,
1429 NPC_AF_KPUX_ENTRY_DISX(kpu, 0), entry_mask);
1430 if (num_entries > 64) {
1431 rvu_write64(rvu, blkaddr,
1432 NPC_AF_KPUX_ENTRY_DISX(kpu, 1),
1433 enable_mask(num_entries - 64));
1436 /* Enable this KPU */
1437 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(kpu), 0x01);
1440 static int npc_prepare_default_kpu(struct npc_kpu_profile_adapter *profile)
1442 profile->custom = 0;
1443 profile->name = def_pfl_name;
1444 profile->version = NPC_KPU_PROFILE_VER;
1445 profile->ikpu = ikpu_action_entries;
1446 profile->pkinds = ARRAY_SIZE(ikpu_action_entries);
1447 profile->kpu = npc_kpu_profiles;
1448 profile->kpus = ARRAY_SIZE(npc_kpu_profiles);
1449 profile->lt_def = &npc_lt_defaults;
1450 profile->mkex = &npc_mkex_default;
1455 static int npc_apply_custom_kpu(struct rvu *rvu,
1456 struct npc_kpu_profile_adapter *profile)
1458 size_t hdr_sz = sizeof(struct npc_kpu_profile_fwdata), offset = 0;
1459 struct npc_kpu_profile_fwdata *fw = rvu->kpu_fwdata;
1460 struct npc_kpu_profile_action *action;
1461 struct npc_kpu_profile_cam *cam;
1462 struct npc_kpu_fwdata *fw_kpu;
1466 if (rvu->kpu_fwdata_sz < hdr_sz) {
1467 dev_warn(rvu->dev, "Invalid KPU profile size\n");
1470 if (le64_to_cpu(fw->signature) != KPU_SIGN) {
1471 dev_warn(rvu->dev, "Invalid KPU profile signature %llx\n",
1475 /* Verify if the using known profile structure */
1476 if (NPC_KPU_VER_MAJ(profile->version) >
1477 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER)) {
1478 dev_warn(rvu->dev, "Not supported Major version: %d > %d\n",
1479 NPC_KPU_VER_MAJ(profile->version),
1480 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER));
1483 /* Verify if profile is aligned with the required kernel changes */
1484 if (NPC_KPU_VER_MIN(profile->version) <
1485 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER)) {
1487 "Invalid KPU profile version: %d.%d.%d expected version <= %d.%d.%d\n",
1488 NPC_KPU_VER_MAJ(profile->version),
1489 NPC_KPU_VER_MIN(profile->version),
1490 NPC_KPU_VER_PATCH(profile->version),
1491 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER),
1492 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER),
1493 NPC_KPU_VER_PATCH(NPC_KPU_PROFILE_VER));
1496 /* Verify if profile fits the HW */
1497 if (fw->kpus > profile->kpus) {
1498 dev_warn(rvu->dev, "Not enough KPUs: %d > %ld\n", fw->kpus,
1503 profile->custom = 1;
1504 profile->name = fw->name;
1505 profile->version = le64_to_cpu(fw->version);
1506 profile->mkex = &fw->mkex;
1507 profile->lt_def = &fw->lt_def;
1509 for (kpu = 0; kpu < fw->kpus; kpu++) {
1510 fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset);
1511 if (fw_kpu->entries > KPU_MAX_CST_ENT)
1513 "Too many custom entries on KPU%d: %d > %d\n",
1514 kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
1515 entries = min(fw_kpu->entries, KPU_MAX_CST_ENT);
1516 cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
1517 offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
1518 action = (struct npc_kpu_profile_action *)(fw->data + offset);
1519 offset += fw_kpu->entries * sizeof(*action);
1520 if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
1522 "Profile size mismatch on KPU%i parsing.\n",
1526 for (entry = 0; entry < entries; entry++) {
1527 profile->kpu[kpu].cam[entry] = cam[entry];
1528 profile->kpu[kpu].action[entry] = action[entry];
1535 static int npc_load_kpu_prfl_img(struct rvu *rvu, void __iomem *prfl_addr,
1536 u64 prfl_sz, const char *kpu_profile)
1538 struct npc_kpu_profile_fwdata *kpu_data = NULL;
1541 kpu_data = (struct npc_kpu_profile_fwdata __force *)prfl_addr;
1542 if (le64_to_cpu(kpu_data->signature) == KPU_SIGN &&
1543 !strncmp(kpu_data->name, kpu_profile, KPU_NAME_LEN)) {
1544 dev_info(rvu->dev, "Loading KPU profile from firmware db: %s\n",
1546 rvu->kpu_fwdata = kpu_data;
1547 rvu->kpu_fwdata_sz = prfl_sz;
1548 rvu->kpu_prfl_addr = prfl_addr;
1555 static int npc_fwdb_detect_load_prfl_img(struct rvu *rvu, uint64_t prfl_sz,
1556 const char *kpu_profile)
1558 struct npc_coalesced_kpu_prfl *img_data = NULL;
1559 int i = 0, rc = -EINVAL;
1560 void __iomem *kpu_prfl_addr;
1563 img_data = (struct npc_coalesced_kpu_prfl __force *)rvu->kpu_prfl_addr;
1564 if (le64_to_cpu(img_data->signature) == KPU_SIGN &&
1565 !strncmp(img_data->name, kpu_profile, KPU_NAME_LEN)) {
1566 /* Loaded profile is a single KPU profile. */
1567 rc = npc_load_kpu_prfl_img(rvu, rvu->kpu_prfl_addr,
1568 prfl_sz, kpu_profile);
1572 /* Loaded profile is coalesced image, offset of first KPU profile.*/
1573 offset = offsetof(struct npc_coalesced_kpu_prfl, prfl_sz) +
1574 (img_data->num_prfl * sizeof(uint16_t));
1575 /* Check if mapped image is coalesced image. */
1576 while (i < img_data->num_prfl) {
1577 /* Profile image offsets are rounded up to next 8 multiple.*/
1578 offset = ALIGN_8B_CEIL(offset);
1579 kpu_prfl_addr = (void __iomem *)((uintptr_t)rvu->kpu_prfl_addr +
1581 rc = npc_load_kpu_prfl_img(rvu, kpu_prfl_addr,
1582 img_data->prfl_sz[i], kpu_profile);
1585 /* Calculating offset of profile image based on profile size.*/
1586 offset += img_data->prfl_sz[i];
1593 static int npc_load_kpu_profile_fwdb(struct rvu *rvu, const char *kpu_profile)
1598 /* Setting up the mapping for NPC profile image */
1599 ret = npc_fwdb_prfl_img_map(rvu, &rvu->kpu_prfl_addr, &prfl_sz);
1603 /* Detect if profile is coalesced or single KPU profile and load */
1604 ret = npc_fwdb_detect_load_prfl_img(rvu, prfl_sz, kpu_profile);
1608 /* Cleaning up if KPU profile image from fwdata is not valid. */
1609 if (rvu->kpu_prfl_addr) {
1610 iounmap(rvu->kpu_prfl_addr);
1611 rvu->kpu_prfl_addr = NULL;
1612 rvu->kpu_fwdata_sz = 0;
1613 rvu->kpu_fwdata = NULL;
1620 static void npc_load_kpu_profile(struct rvu *rvu)
1622 struct npc_kpu_profile_adapter *profile = &rvu->kpu;
1623 const char *kpu_profile = rvu->kpu_pfl_name;
1624 const struct firmware *fw = NULL;
1625 bool retry_fwdb = false;
1627 /* If user not specified profile customization */
1628 if (!strncmp(kpu_profile, def_pfl_name, KPU_NAME_LEN))
1629 goto revert_to_default;
1630 /* First prepare default KPU, then we'll customize top entries. */
1631 npc_prepare_default_kpu(profile);
1633 /* Order of preceedence for load loading NPC profile (high to low)
1634 * Firmware binary in filesystem.
1635 * Firmware database method.
1636 * Default KPU profile.
1638 if (!request_firmware(&fw, kpu_profile, rvu->dev)) {
1639 dev_info(rvu->dev, "Loading KPU profile from firmware: %s\n",
1641 rvu->kpu_fwdata = kzalloc(fw->size, GFP_KERNEL);
1642 if (rvu->kpu_fwdata) {
1643 memcpy(rvu->kpu_fwdata, fw->data, fw->size);
1644 rvu->kpu_fwdata_sz = fw->size;
1646 release_firmware(fw);
1652 /* Loading the KPU profile using firmware database */
1653 if (npc_load_kpu_profile_fwdb(rvu, kpu_profile))
1654 goto revert_to_default;
1657 /* Apply profile customization if firmware was loaded. */
1658 if (!rvu->kpu_fwdata_sz || npc_apply_custom_kpu(rvu, profile)) {
1659 /* If image from firmware filesystem fails to load or invalid
1660 * retry with firmware database method.
1662 if (rvu->kpu_fwdata || rvu->kpu_fwdata_sz) {
1663 /* Loading image from firmware database failed. */
1664 if (rvu->kpu_prfl_addr) {
1665 iounmap(rvu->kpu_prfl_addr);
1666 rvu->kpu_prfl_addr = NULL;
1668 kfree(rvu->kpu_fwdata);
1670 rvu->kpu_fwdata = NULL;
1671 rvu->kpu_fwdata_sz = 0;
1674 goto load_image_fwdb;
1679 "Can't load KPU profile %s. Using default.\n",
1681 kfree(rvu->kpu_fwdata);
1682 rvu->kpu_fwdata = NULL;
1683 goto revert_to_default;
1686 dev_info(rvu->dev, "Using custom profile '%s', version %d.%d.%d\n",
1687 profile->name, NPC_KPU_VER_MAJ(profile->version),
1688 NPC_KPU_VER_MIN(profile->version),
1689 NPC_KPU_VER_PATCH(profile->version));
1694 npc_prepare_default_kpu(profile);
1697 static void npc_parser_profile_init(struct rvu *rvu, int blkaddr)
1699 struct rvu_hwinfo *hw = rvu->hw;
1700 int num_pkinds, num_kpus, idx;
1702 /* Disable all KPUs and their entries */
1703 for (idx = 0; idx < hw->npc_kpus; idx++) {
1704 rvu_write64(rvu, blkaddr,
1705 NPC_AF_KPUX_ENTRY_DISX(idx, 0), ~0ULL);
1706 rvu_write64(rvu, blkaddr,
1707 NPC_AF_KPUX_ENTRY_DISX(idx, 1), ~0ULL);
1708 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(idx), 0x00);
1711 /* Load and customize KPU profile. */
1712 npc_load_kpu_profile(rvu);
1714 /* First program IKPU profile i.e PKIND configs.
1715 * Check HW max count to avoid configuring junk or
1716 * writing to unsupported CSR addresses.
1718 num_pkinds = rvu->kpu.pkinds;
1719 num_pkinds = min_t(int, hw->npc_pkinds, num_pkinds);
1721 for (idx = 0; idx < num_pkinds; idx++)
1722 npc_config_kpuaction(rvu, blkaddr, &rvu->kpu.ikpu[idx], 0, idx, true);
1724 /* Program KPU CAM and Action profiles */
1725 num_kpus = rvu->kpu.kpus;
1726 num_kpus = min_t(int, hw->npc_kpus, num_kpus);
1728 for (idx = 0; idx < num_kpus; idx++)
1729 npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);
1732 static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1734 int nixlf_count = rvu_get_nixlf_count(rvu);
1735 struct npc_mcam *mcam = &rvu->hw->mcam;
1741 /* Actual number of MCAM entries vary by entry size */
1742 cfg = (rvu_read64(rvu, blkaddr,
1743 NPC_AF_INTFX_KEX_CFG(0)) >> 32) & 0x07;
1744 mcam->total_entries = (mcam->banks / BIT_ULL(cfg)) * mcam->banksize;
1745 mcam->keysize = cfg;
1747 /* Number of banks combined per MCAM entry */
1748 if (cfg == NPC_MCAM_KEY_X4)
1749 mcam->banks_per_entry = 4;
1750 else if (cfg == NPC_MCAM_KEY_X2)
1751 mcam->banks_per_entry = 2;
1753 mcam->banks_per_entry = 1;
1755 /* Reserve one MCAM entry for each of the NIX LF to
1756 * guarantee space to install default matching DMAC rule.
1757 * Also reserve 2 MCAM entries for each PF for default
1758 * channel based matching or 'bcast & promisc' matching to
1759 * support BCAST and PROMISC modes of operation for PFs.
1762 rsvd = (nixlf_count * RSVD_MCAM_ENTRIES_PER_NIXLF) +
1763 ((rvu->hw->total_pfs - 1) * RSVD_MCAM_ENTRIES_PER_PF);
1764 if (mcam->total_entries <= rsvd) {
1766 "Insufficient NPC MCAM size %d for pkt I/O, exiting\n",
1767 mcam->total_entries);
1771 mcam->bmap_entries = mcam->total_entries - rsvd;
1772 mcam->nixlf_offset = mcam->bmap_entries;
1773 mcam->pf_offset = mcam->nixlf_offset + nixlf_count;
1775 /* Allocate bitmaps for managing MCAM entries */
1776 mcam->bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(mcam->bmap_entries),
1777 sizeof(long), GFP_KERNEL);
1781 mcam->bmap_reverse = devm_kcalloc(rvu->dev,
1782 BITS_TO_LONGS(mcam->bmap_entries),
1783 sizeof(long), GFP_KERNEL);
1784 if (!mcam->bmap_reverse)
1787 mcam->bmap_fcnt = mcam->bmap_entries;
1789 /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
1790 mcam->entry2pfvf_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1791 sizeof(u16), GFP_KERNEL);
1792 if (!mcam->entry2pfvf_map)
1795 /* Reserve 1/8th of MCAM entries at the bottom for low priority
1796 * allocations and another 1/8th at the top for high priority
1799 mcam->lprio_count = mcam->bmap_entries / 8;
1800 if (mcam->lprio_count > BITS_PER_LONG)
1801 mcam->lprio_count = round_down(mcam->lprio_count,
1803 mcam->lprio_start = mcam->bmap_entries - mcam->lprio_count;
1804 mcam->hprio_count = mcam->lprio_count;
1805 mcam->hprio_end = mcam->hprio_count;
1808 /* Allocate bitmap for managing MCAM counters and memory
1809 * for saving counter to RVU PFFUNC allocation mapping.
1811 err = rvu_alloc_bitmap(&mcam->counters);
1815 mcam->cntr2pfvf_map = devm_kcalloc(rvu->dev, mcam->counters.max,
1816 sizeof(u16), GFP_KERNEL);
1817 if (!mcam->cntr2pfvf_map)
1820 /* Alloc memory for MCAM entry to counter mapping and for tracking
1821 * counter's reference count.
1823 mcam->entry2cntr_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1824 sizeof(u16), GFP_KERNEL);
1825 if (!mcam->entry2cntr_map)
1828 mcam->cntr_refcnt = devm_kcalloc(rvu->dev, mcam->counters.max,
1829 sizeof(u16), GFP_KERNEL);
1830 if (!mcam->cntr_refcnt)
1833 /* Alloc memory for saving target device of mcam rule */
1834 mcam->entry2target_pffunc = devm_kcalloc(rvu->dev, mcam->total_entries,
1835 sizeof(u16), GFP_KERNEL);
1836 if (!mcam->entry2target_pffunc)
1839 for (index = 0; index < mcam->bmap_entries; index++) {
1840 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
1841 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
1844 for (cntr = 0; cntr < mcam->counters.max; cntr++)
1845 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
1847 mutex_init(&mcam->lock);
1852 kfree(mcam->counters.bmap);
1856 static void rvu_npc_hw_init(struct rvu *rvu, int blkaddr)
1858 struct npc_pkind *pkind = &rvu->hw->pkind;
1859 struct npc_mcam *mcam = &rvu->hw->mcam;
1860 struct rvu_hwinfo *hw = rvu->hw;
1861 u64 npc_const, npc_const1;
1864 npc_const = rvu_read64(rvu, blkaddr, NPC_AF_CONST);
1865 npc_const1 = rvu_read64(rvu, blkaddr, NPC_AF_CONST1);
1866 if (npc_const1 & BIT_ULL(63))
1867 npc_const2 = rvu_read64(rvu, blkaddr, NPC_AF_CONST2);
1869 pkind->rsrc.max = NPC_UNRESERVED_PKIND_COUNT;
1870 hw->npc_pkinds = (npc_const1 >> 12) & 0xFFULL;
1871 hw->npc_kpu_entries = npc_const1 & 0xFFFULL;
1872 hw->npc_kpus = (npc_const >> 8) & 0x1FULL;
1873 hw->npc_intfs = npc_const & 0xFULL;
1874 hw->npc_counters = (npc_const >> 48) & 0xFFFFULL;
1876 mcam->banks = (npc_const >> 44) & 0xFULL;
1877 mcam->banksize = (npc_const >> 28) & 0xFFFFULL;
1878 hw->npc_stat_ena = BIT_ULL(9);
1881 hw->npc_ext_set = true;
1882 /* 96xx supports only match_stats and npc_counters
1883 * reflected in NPC_AF_CONST reg.
1884 * STAT_SEL and ENA are at [0:8] and 9 bit positions.
1885 * 98xx has both match_stat and ext and npc_counter
1886 * reflected in NPC_AF_CONST2
1887 * STAT_SEL_EXT added at [12:14] bit position.
1888 * cn10k supports only ext and hence npc_counters in
1889 * NPC_AF_CONST is 0 and npc_counters reflected in NPC_AF_CONST2.
1890 * STAT_SEL bitpos incremented from [0:8] to [0:11] and ENA bit moved to 63
1892 if (!hw->npc_counters)
1893 hw->npc_stat_ena = BIT_ULL(63);
1894 hw->npc_counters = (npc_const2 >> 16) & 0xFFFFULL;
1895 mcam->banksize = npc_const2 & 0xFFFFULL;
1898 mcam->counters.max = hw->npc_counters;
1901 static void rvu_npc_setup_interfaces(struct rvu *rvu, int blkaddr)
1903 struct npc_mcam *mcam = &rvu->hw->mcam;
1904 struct rvu_hwinfo *hw = rvu->hw;
1905 u64 nibble_ena, rx_kex, tx_kex;
1908 /* Reserve last counter for MCAM RX miss action which is set to
1909 * drop packet. This way we will know how many pkts didn't match
1912 mcam->counters.max--;
1913 mcam->rx_miss_act_cntr = mcam->counters.max;
1915 rx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_RX];
1916 tx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_TX];
1917 nibble_ena = FIELD_GET(NPC_PARSE_NIBBLE, rx_kex);
1919 nibble_ena = rvu_npc_get_tx_nibble_cfg(rvu, nibble_ena);
1921 tx_kex &= ~NPC_PARSE_NIBBLE;
1922 tx_kex |= FIELD_PREP(NPC_PARSE_NIBBLE, nibble_ena);
1923 npc_mkex_default.keyx_cfg[NIX_INTF_TX] = tx_kex;
1926 /* Configure RX interfaces */
1927 for (intf = 0; intf < hw->npc_intfs; intf++) {
1928 if (is_npc_intf_tx(intf))
1931 /* Set RX MCAM search key size. LA..LE (ltype only) + Channel */
1932 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1935 /* If MCAM lookup doesn't result in a match, drop the received
1936 * packet. And map this action to a counter to count dropped
1939 rvu_write64(rvu, blkaddr,
1940 NPC_AF_INTFX_MISS_ACT(intf), NIX_RX_ACTIONOP_DROP);
1942 /* NPC_AF_INTFX_MISS_STAT_ACT[14:12] - counter[11:9]
1943 * NPC_AF_INTFX_MISS_STAT_ACT[8:0] - counter[8:0]
1945 rvu_write64(rvu, blkaddr,
1946 NPC_AF_INTFX_MISS_STAT_ACT(intf),
1947 ((mcam->rx_miss_act_cntr >> 9) << 12) |
1948 hw->npc_stat_ena | mcam->rx_miss_act_cntr);
1951 /* Configure TX interfaces */
1952 for (intf = 0; intf < hw->npc_intfs; intf++) {
1953 if (is_npc_intf_rx(intf))
1956 /* Extract Ltypes LID_LA to LID_LE */
1957 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1960 /* Set TX miss action to UCAST_DEFAULT i.e
1961 * transmit the packet on NIX LF SQ's default channel.
1963 rvu_write64(rvu, blkaddr,
1964 NPC_AF_INTFX_MISS_ACT(intf),
1965 NIX_TX_ACTIONOP_UCAST_DEFAULT);
1969 int rvu_npc_init(struct rvu *rvu)
1971 struct npc_kpu_profile_adapter *kpu = &rvu->kpu;
1972 struct npc_pkind *pkind = &rvu->hw->pkind;
1973 struct npc_mcam *mcam = &rvu->hw->mcam;
1974 int blkaddr, entry, bank, err;
1976 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1978 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
1982 rvu_npc_hw_init(rvu, blkaddr);
1984 /* First disable all MCAM entries, to stop traffic towards NIXLFs */
1985 for (bank = 0; bank < mcam->banks; bank++) {
1986 for (entry = 0; entry < mcam->banksize; entry++)
1987 rvu_write64(rvu, blkaddr,
1988 NPC_AF_MCAMEX_BANKX_CFG(entry, bank), 0);
1991 err = rvu_alloc_bitmap(&pkind->rsrc);
1994 /* Reserve PKIND#0 for LBKs. Power reset value of LBK_CH_PKIND is '0',
1995 * no need to configure PKIND for all LBKs separately.
1997 rvu_alloc_rsrc(&pkind->rsrc);
1999 /* Allocate mem for pkind to PF and channel mapping info */
2000 pkind->pfchan_map = devm_kcalloc(rvu->dev, pkind->rsrc.max,
2001 sizeof(u32), GFP_KERNEL);
2002 if (!pkind->pfchan_map)
2005 /* Configure KPU profile */
2006 npc_parser_profile_init(rvu, blkaddr);
2008 /* Config Outer L2, IPv4's NPC layer info */
2009 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OL2,
2010 (kpu->lt_def->pck_ol2.lid << 8) | (kpu->lt_def->pck_ol2.ltype_match << 4) |
2011 kpu->lt_def->pck_ol2.ltype_mask);
2012 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OIP4,
2013 (kpu->lt_def->pck_oip4.lid << 8) | (kpu->lt_def->pck_oip4.ltype_match << 4) |
2014 kpu->lt_def->pck_oip4.ltype_mask);
2016 /* Config Inner IPV4 NPC layer info */
2017 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_IIP4,
2018 (kpu->lt_def->pck_iip4.lid << 8) | (kpu->lt_def->pck_iip4.ltype_match << 4) |
2019 kpu->lt_def->pck_iip4.ltype_mask);
2021 /* Enable below for Rx pkts.
2022 * - Outer IPv4 header checksum validation.
2023 * - Detect outer L2 broadcast address and set NPC_RESULT_S[L2B].
2024 * - Detect outer L2 multicast address and set NPC_RESULT_S[L2M].
2025 * - Inner IPv4 header checksum validation.
2026 * - Set non zero checksum error code value
2028 rvu_write64(rvu, blkaddr, NPC_AF_PCK_CFG,
2029 rvu_read64(rvu, blkaddr, NPC_AF_PCK_CFG) |
2030 ((u64)NPC_EC_OIP4_CSUM << 32) | (NPC_EC_IIP4_CSUM << 24) |
2031 BIT_ULL(7) | BIT_ULL(6) | BIT_ULL(2) | BIT_ULL(1));
2033 rvu_npc_setup_interfaces(rvu, blkaddr);
2035 /* Configure MKEX profile */
2036 npc_load_mkex_profile(rvu, blkaddr, rvu->mkex_pfl_name);
2038 err = npc_mcam_rsrcs_init(rvu, blkaddr);
2042 err = npc_flow_steering_init(rvu, blkaddr);
2045 "Incorrect mkex profile loaded using default mkex\n");
2046 npc_load_mkex_profile(rvu, blkaddr, def_pfl_name);
2052 void rvu_npc_freemem(struct rvu *rvu)
2054 struct npc_pkind *pkind = &rvu->hw->pkind;
2055 struct npc_mcam *mcam = &rvu->hw->mcam;
2057 kfree(pkind->rsrc.bmap);
2058 kfree(mcam->counters.bmap);
2059 if (rvu->kpu_prfl_addr)
2060 iounmap(rvu->kpu_prfl_addr);
2062 kfree(rvu->kpu_fwdata);
2063 mutex_destroy(&mcam->lock);
2066 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
2067 int blkaddr, int *alloc_cnt,
2070 struct npc_mcam *mcam = &rvu->hw->mcam;
2076 for (entry = 0; entry < mcam->bmap_entries; entry++) {
2077 if (mcam->entry2pfvf_map[entry] == pcifunc) {
2079 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, entry))
2085 void rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
2086 int blkaddr, int *alloc_cnt,
2089 struct npc_mcam *mcam = &rvu->hw->mcam;
2095 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2096 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2098 if (mcam->cntr_refcnt[cntr])
2104 static int npc_mcam_verify_entry(struct npc_mcam *mcam,
2105 u16 pcifunc, int entry)
2107 /* verify AF installed entries */
2108 if (is_pffunc_af(pcifunc))
2110 /* Verify if entry is valid and if it is indeed
2111 * allocated to the requesting PFFUNC.
2113 if (entry >= mcam->bmap_entries)
2114 return NPC_MCAM_INVALID_REQ;
2116 if (pcifunc != mcam->entry2pfvf_map[entry])
2117 return NPC_MCAM_PERM_DENIED;
2122 static int npc_mcam_verify_counter(struct npc_mcam *mcam,
2123 u16 pcifunc, int cntr)
2125 /* Verify if counter is valid and if it is indeed
2126 * allocated to the requesting PFFUNC.
2128 if (cntr >= mcam->counters.max)
2129 return NPC_MCAM_INVALID_REQ;
2131 if (pcifunc != mcam->cntr2pfvf_map[cntr])
2132 return NPC_MCAM_PERM_DENIED;
2137 static void npc_map_mcam_entry_and_cntr(struct rvu *rvu, struct npc_mcam *mcam,
2138 int blkaddr, u16 entry, u16 cntr)
2140 u16 index = entry & (mcam->banksize - 1);
2141 u32 bank = npc_get_bank(mcam, entry);
2142 struct rvu_hwinfo *hw = rvu->hw;
2144 /* Set mapping and increment counter's refcnt */
2145 mcam->entry2cntr_map[entry] = cntr;
2146 mcam->cntr_refcnt[cntr]++;
2148 rvu_write64(rvu, blkaddr,
2149 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank),
2150 ((cntr >> 9) << 12) | hw->npc_stat_ena | cntr);
2153 static void npc_unmap_mcam_entry_and_cntr(struct rvu *rvu,
2154 struct npc_mcam *mcam,
2155 int blkaddr, u16 entry, u16 cntr)
2157 u16 index = entry & (mcam->banksize - 1);
2158 u32 bank = npc_get_bank(mcam, entry);
2160 /* Remove mapping and reduce counter's refcnt */
2161 mcam->entry2cntr_map[entry] = NPC_MCAM_INVALID_MAP;
2162 mcam->cntr_refcnt[cntr]--;
2164 rvu_write64(rvu, blkaddr,
2165 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank), 0x00);
2168 /* Sets MCAM entry in bitmap as used. Update
2169 * reverse bitmap too. Should be called with
2170 * 'mcam->lock' held.
2172 static void npc_mcam_set_bit(struct npc_mcam *mcam, u16 index)
2177 rentry = mcam->bmap_entries - index - 1;
2179 __set_bit(entry, mcam->bmap);
2180 __set_bit(rentry, mcam->bmap_reverse);
2184 /* Sets MCAM entry in bitmap as free. Update
2185 * reverse bitmap too. Should be called with
2186 * 'mcam->lock' held.
2188 static void npc_mcam_clear_bit(struct npc_mcam *mcam, u16 index)
2193 rentry = mcam->bmap_entries - index - 1;
2195 __clear_bit(entry, mcam->bmap);
2196 __clear_bit(rentry, mcam->bmap_reverse);
2200 static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mcam,
2201 int blkaddr, u16 pcifunc)
2205 /* Scan all MCAM entries and free the ones mapped to 'pcifunc' */
2206 for (index = 0; index < mcam->bmap_entries; index++) {
2207 if (mcam->entry2pfvf_map[index] == pcifunc) {
2208 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
2209 /* Free the entry in bitmap */
2210 npc_mcam_clear_bit(mcam, index);
2211 /* Disable the entry */
2212 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false);
2214 /* Update entry2counter mapping */
2215 cntr = mcam->entry2cntr_map[index];
2216 if (cntr != NPC_MCAM_INVALID_MAP)
2217 npc_unmap_mcam_entry_and_cntr(rvu, mcam,
2220 mcam->entry2target_pffunc[index] = 0x0;
2225 static void npc_mcam_free_all_counters(struct rvu *rvu, struct npc_mcam *mcam,
2230 /* Scan all MCAM counters and free the ones mapped to 'pcifunc' */
2231 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2232 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2233 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
2234 mcam->cntr_refcnt[cntr] = 0;
2235 rvu_free_rsrc(&mcam->counters, cntr);
2236 /* This API is expected to be called after freeing
2237 * MCAM entries, which inturn will remove
2238 * 'entry to counter' mapping.
2239 * No need to do it again.
2245 /* Find area of contiguous free entries of size 'nr'.
2246 * If not found return max contiguous free entries available.
2248 static u16 npc_mcam_find_zero_area(unsigned long *map, u16 size, u16 start,
2249 u16 nr, u16 *max_area)
2251 u16 max_area_start = 0;
2252 u16 index, next, end;
2257 index = find_next_zero_bit(map, size, start);
2259 return max_area_start;
2261 end = ((index + nr) >= size) ? size : index + nr;
2262 next = find_next_bit(map, end, index);
2263 if (*max_area < (next - index)) {
2264 *max_area = next - index;
2265 max_area_start = index;
2273 return max_area_start;
2276 /* Find number of free MCAM entries available
2277 * within range i.e in between 'start' and 'end'.
2279 static u16 npc_mcam_get_free_count(unsigned long *map, u16 start, u16 end)
2288 index = find_next_zero_bit(map, end, start);
2292 next = find_next_bit(map, end, index);
2294 fcnt += next - index;
2299 fcnt += end - index;
2304 npc_get_mcam_search_range_priority(struct npc_mcam *mcam,
2305 struct npc_mcam_alloc_entry_req *req,
2306 u16 *start, u16 *end, bool *reverse)
2310 if (req->priority == NPC_MCAM_HIGHER_PRIO)
2313 /* For a low priority entry allocation
2314 * - If reference entry is not in hprio zone then
2315 * search range: ref_entry to end.
2316 * - If reference entry is in hprio zone and if
2317 * request can be accomodated in non-hprio zone then
2318 * search range: 'start of middle zone' to 'end'
2319 * - else search in reverse, so that less number of hprio
2320 * zone entries are allocated.
2324 *start = req->ref_entry + 1;
2325 *end = mcam->bmap_entries;
2327 if (req->ref_entry >= mcam->hprio_end)
2330 fcnt = npc_mcam_get_free_count(mcam->bmap,
2331 mcam->hprio_end, mcam->bmap_entries);
2332 if (fcnt > req->count)
2333 *start = mcam->hprio_end;
2339 /* For a high priority entry allocation, search is always
2340 * in reverse to preserve hprio zone entries.
2341 * - If reference entry is not in lprio zone then
2342 * search range: 0 to ref_entry.
2343 * - If reference entry is in lprio zone and if
2344 * request can be accomodated in middle zone then
2345 * search range: 'hprio_end' to 'lprio_start'
2350 *end = req->ref_entry;
2352 if (req->ref_entry <= mcam->lprio_start)
2355 fcnt = npc_mcam_get_free_count(mcam->bmap,
2356 mcam->hprio_end, mcam->lprio_start);
2357 if (fcnt < req->count)
2359 *start = mcam->hprio_end;
2360 *end = mcam->lprio_start;
2363 static int npc_mcam_alloc_entries(struct npc_mcam *mcam, u16 pcifunc,
2364 struct npc_mcam_alloc_entry_req *req,
2365 struct npc_mcam_alloc_entry_rsp *rsp)
2367 u16 entry_list[NPC_MAX_NONCONTIG_ENTRIES];
2368 u16 fcnt, hp_fcnt, lp_fcnt;
2369 u16 start, end, index;
2370 int entry, next_start;
2371 bool reverse = false;
2372 unsigned long *bmap;
2375 mutex_lock(&mcam->lock);
2377 /* Check if there are any free entries */
2378 if (!mcam->bmap_fcnt) {
2379 mutex_unlock(&mcam->lock);
2380 return NPC_MCAM_ALLOC_FAILED;
2383 /* MCAM entries are divided into high priority, middle and
2384 * low priority zones. Idea is to not allocate top and lower
2385 * most entries as much as possible, this is to increase
2386 * probability of honouring priority allocation requests.
2388 * Two bitmaps are used for mcam entry management,
2389 * mcam->bmap for forward search i.e '0 to mcam->bmap_entries'.
2390 * mcam->bmap_reverse for reverse search i.e 'mcam->bmap_entries to 0'.
2392 * Reverse bitmap is used to allocate entries
2393 * - when a higher priority entry is requested
2394 * - when available free entries are less.
2395 * Lower priority ones out of avaialble free entries are always
2396 * chosen when 'high vs low' question arises.
2399 /* Get the search range for priority allocation request */
2400 if (req->priority) {
2401 npc_get_mcam_search_range_priority(mcam, req,
2402 &start, &end, &reverse);
2406 /* For a VF base MCAM match rule is set by its PF. And all the
2407 * further MCAM rules installed by VF on its own are
2408 * concatenated with the base rule set by its PF. Hence PF entries
2409 * should be at lower priority compared to VF entries. Otherwise
2410 * base rule is hit always and rules installed by VF will be of
2411 * no use. Hence if the request is from PF and NOT a priority
2412 * allocation request then allocate low priority entries.
2414 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
2417 /* Find out the search range for non-priority allocation request
2419 * Get MCAM free entry count in middle zone.
2421 lp_fcnt = npc_mcam_get_free_count(mcam->bmap,
2423 mcam->bmap_entries);
2424 hp_fcnt = npc_mcam_get_free_count(mcam->bmap, 0, mcam->hprio_end);
2425 fcnt = mcam->bmap_fcnt - lp_fcnt - hp_fcnt;
2427 /* Check if request can be accomodated in the middle zone */
2428 if (fcnt > req->count) {
2429 start = mcam->hprio_end;
2430 end = mcam->lprio_start;
2431 } else if ((fcnt + (hp_fcnt / 2) + (lp_fcnt / 2)) > req->count) {
2432 /* Expand search zone from half of hprio zone to
2433 * half of lprio zone.
2435 start = mcam->hprio_end / 2;
2436 end = mcam->bmap_entries - (mcam->lprio_count / 2);
2439 /* Not enough free entries, search all entries in reverse,
2440 * so that low priority ones will get used up.
2445 end = mcam->bmap_entries;
2450 bmap = mcam->bmap_reverse;
2451 start = mcam->bmap_entries - start;
2452 end = mcam->bmap_entries - end;
2459 /* Allocate requested number of contiguous entries, if
2460 * unsuccessful find max contiguous entries available.
2462 index = npc_mcam_find_zero_area(bmap, end, start,
2463 req->count, &max_contig);
2464 rsp->count = max_contig;
2466 rsp->entry = mcam->bmap_entries - index - max_contig;
2470 /* Allocate requested number of non-contiguous entries,
2471 * if unsuccessful allocate as many as possible.
2475 for (entry = 0; entry < req->count; entry++) {
2476 index = find_next_zero_bit(bmap, end, next_start);
2480 next_start = start + (index - start) + 1;
2482 /* Save the entry's index */
2484 index = mcam->bmap_entries - index - 1;
2485 entry_list[entry] = index;
2490 /* If allocating requested no of entries is unsucessful,
2491 * expand the search range to full bitmap length and retry.
2493 if (!req->priority && (rsp->count < req->count) &&
2494 ((end - start) != mcam->bmap_entries)) {
2497 end = mcam->bmap_entries;
2501 /* For priority entry allocation requests, if allocation is
2502 * failed then expand search to max possible range and retry.
2504 if (req->priority && rsp->count < req->count) {
2505 if (req->priority == NPC_MCAM_LOWER_PRIO &&
2506 (start != (req->ref_entry + 1))) {
2507 start = req->ref_entry + 1;
2508 end = mcam->bmap_entries;
2511 } else if ((req->priority == NPC_MCAM_HIGHER_PRIO) &&
2512 ((end - start) != req->ref_entry)) {
2514 end = req->ref_entry;
2520 /* Copy MCAM entry indices into mbox response entry_list.
2521 * Requester always expects indices in ascending order, so
2522 * so reverse the list if reverse bitmap is used for allocation.
2524 if (!req->contig && rsp->count) {
2526 for (entry = rsp->count - 1; entry >= 0; entry--) {
2528 rsp->entry_list[index++] = entry_list[entry];
2530 rsp->entry_list[entry] = entry_list[entry];
2534 /* Mark the allocated entries as used and set nixlf mapping */
2535 for (entry = 0; entry < rsp->count; entry++) {
2536 index = req->contig ?
2537 (rsp->entry + entry) : rsp->entry_list[entry];
2538 npc_mcam_set_bit(mcam, index);
2539 mcam->entry2pfvf_map[index] = pcifunc;
2540 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
2543 /* Update available free count in mbox response */
2544 rsp->free_count = mcam->bmap_fcnt;
2546 mutex_unlock(&mcam->lock);
2550 int rvu_mbox_handler_npc_mcam_alloc_entry(struct rvu *rvu,
2551 struct npc_mcam_alloc_entry_req *req,
2552 struct npc_mcam_alloc_entry_rsp *rsp)
2554 struct npc_mcam *mcam = &rvu->hw->mcam;
2555 u16 pcifunc = req->hdr.pcifunc;
2558 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2560 return NPC_MCAM_INVALID_REQ;
2562 rsp->entry = NPC_MCAM_ENTRY_INVALID;
2563 rsp->free_count = 0;
2565 /* Check if ref_entry is within range */
2566 if (req->priority && req->ref_entry >= mcam->bmap_entries) {
2567 dev_err(rvu->dev, "%s: reference entry %d is out of range\n",
2568 __func__, req->ref_entry);
2569 return NPC_MCAM_INVALID_REQ;
2572 /* ref_entry can't be '0' if requested priority is high.
2573 * Can't be last entry if requested priority is low.
2575 if ((!req->ref_entry && req->priority == NPC_MCAM_HIGHER_PRIO) ||
2576 ((req->ref_entry == (mcam->bmap_entries - 1)) &&
2577 req->priority == NPC_MCAM_LOWER_PRIO))
2578 return NPC_MCAM_INVALID_REQ;
2580 /* Since list of allocated indices needs to be sent to requester,
2581 * max number of non-contiguous entries per mbox msg is limited.
2583 if (!req->contig && req->count > NPC_MAX_NONCONTIG_ENTRIES) {
2585 "%s: %d Non-contiguous MCAM entries requested is more than max (%d) allowed\n",
2586 __func__, req->count, NPC_MAX_NONCONTIG_ENTRIES);
2587 return NPC_MCAM_INVALID_REQ;
2590 /* Alloc request from PFFUNC with no NIXLF attached should be denied */
2591 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2592 return NPC_MCAM_ALLOC_DENIED;
2594 return npc_mcam_alloc_entries(mcam, pcifunc, req, rsp);
2597 int rvu_mbox_handler_npc_mcam_free_entry(struct rvu *rvu,
2598 struct npc_mcam_free_entry_req *req,
2599 struct msg_rsp *rsp)
2601 struct npc_mcam *mcam = &rvu->hw->mcam;
2602 u16 pcifunc = req->hdr.pcifunc;
2603 int blkaddr, rc = 0;
2606 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2608 return NPC_MCAM_INVALID_REQ;
2610 /* Free request from PFFUNC with no NIXLF attached, ignore */
2611 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2612 return NPC_MCAM_INVALID_REQ;
2614 mutex_lock(&mcam->lock);
2619 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2623 mcam->entry2pfvf_map[req->entry] = NPC_MCAM_INVALID_MAP;
2624 mcam->entry2target_pffunc[req->entry] = 0x0;
2625 npc_mcam_clear_bit(mcam, req->entry);
2626 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2628 /* Update entry2counter mapping */
2629 cntr = mcam->entry2cntr_map[req->entry];
2630 if (cntr != NPC_MCAM_INVALID_MAP)
2631 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2637 /* Free up all entries allocated to requesting PFFUNC */
2638 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
2640 mutex_unlock(&mcam->lock);
2644 int rvu_mbox_handler_npc_mcam_read_entry(struct rvu *rvu,
2645 struct npc_mcam_read_entry_req *req,
2646 struct npc_mcam_read_entry_rsp *rsp)
2648 struct npc_mcam *mcam = &rvu->hw->mcam;
2649 u16 pcifunc = req->hdr.pcifunc;
2652 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2654 return NPC_MCAM_INVALID_REQ;
2656 mutex_lock(&mcam->lock);
2657 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2659 npc_read_mcam_entry(rvu, mcam, blkaddr, req->entry,
2661 &rsp->intf, &rsp->enable);
2664 mutex_unlock(&mcam->lock);
2668 int rvu_mbox_handler_npc_mcam_write_entry(struct rvu *rvu,
2669 struct npc_mcam_write_entry_req *req,
2670 struct msg_rsp *rsp)
2672 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
2673 struct npc_mcam *mcam = &rvu->hw->mcam;
2674 u16 pcifunc = req->hdr.pcifunc;
2678 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2680 return NPC_MCAM_INVALID_REQ;
2682 mutex_lock(&mcam->lock);
2683 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2687 if (req->set_cntr &&
2688 npc_mcam_verify_counter(mcam, pcifunc, req->cntr)) {
2689 rc = NPC_MCAM_INVALID_REQ;
2693 if (!is_npc_interface_valid(rvu, req->intf)) {
2694 rc = NPC_MCAM_INVALID_REQ;
2698 if (is_npc_intf_tx(req->intf))
2699 nix_intf = pfvf->nix_tx_intf;
2701 nix_intf = pfvf->nix_rx_intf;
2703 if (!is_pffunc_af(pcifunc) &&
2704 npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf, pcifunc)) {
2705 rc = NPC_MCAM_INVALID_REQ;
2709 /* For AF installed rules, the nix_intf should be set to target NIX */
2710 if (is_pffunc_af(req->hdr.pcifunc))
2711 nix_intf = req->intf;
2713 npc_config_mcam_entry(rvu, mcam, blkaddr, req->entry, nix_intf,
2714 &req->entry_data, req->enable_entry);
2717 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2718 req->entry, req->cntr);
2722 mutex_unlock(&mcam->lock);
2726 int rvu_mbox_handler_npc_mcam_ena_entry(struct rvu *rvu,
2727 struct npc_mcam_ena_dis_entry_req *req,
2728 struct msg_rsp *rsp)
2730 struct npc_mcam *mcam = &rvu->hw->mcam;
2731 u16 pcifunc = req->hdr.pcifunc;
2734 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2736 return NPC_MCAM_INVALID_REQ;
2738 mutex_lock(&mcam->lock);
2739 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2740 mutex_unlock(&mcam->lock);
2744 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, true);
2749 int rvu_mbox_handler_npc_mcam_dis_entry(struct rvu *rvu,
2750 struct npc_mcam_ena_dis_entry_req *req,
2751 struct msg_rsp *rsp)
2753 struct npc_mcam *mcam = &rvu->hw->mcam;
2754 u16 pcifunc = req->hdr.pcifunc;
2757 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2759 return NPC_MCAM_INVALID_REQ;
2761 mutex_lock(&mcam->lock);
2762 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2763 mutex_unlock(&mcam->lock);
2767 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2772 int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,
2773 struct npc_mcam_shift_entry_req *req,
2774 struct npc_mcam_shift_entry_rsp *rsp)
2776 struct npc_mcam *mcam = &rvu->hw->mcam;
2777 u16 pcifunc = req->hdr.pcifunc;
2778 u16 old_entry, new_entry;
2779 int blkaddr, rc = 0;
2782 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2784 return NPC_MCAM_INVALID_REQ;
2786 if (req->shift_count > NPC_MCAM_MAX_SHIFTS)
2787 return NPC_MCAM_INVALID_REQ;
2789 mutex_lock(&mcam->lock);
2790 for (index = 0; index < req->shift_count; index++) {
2791 old_entry = req->curr_entry[index];
2792 new_entry = req->new_entry[index];
2794 /* Check if both old and new entries are valid and
2795 * does belong to this PFFUNC or not.
2797 rc = npc_mcam_verify_entry(mcam, pcifunc, old_entry);
2801 rc = npc_mcam_verify_entry(mcam, pcifunc, new_entry);
2805 /* new_entry should not have a counter mapped */
2806 if (mcam->entry2cntr_map[new_entry] != NPC_MCAM_INVALID_MAP) {
2807 rc = NPC_MCAM_PERM_DENIED;
2811 /* Disable the new_entry */
2812 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, false);
2814 /* Copy rule from old entry to new entry */
2815 npc_copy_mcam_entry(rvu, mcam, blkaddr, old_entry, new_entry);
2817 /* Copy counter mapping, if any */
2818 cntr = mcam->entry2cntr_map[old_entry];
2819 if (cntr != NPC_MCAM_INVALID_MAP) {
2820 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2822 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2826 /* Enable new_entry and disable old_entry */
2827 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, true);
2828 npc_enable_mcam_entry(rvu, mcam, blkaddr, old_entry, false);
2831 /* If shift has failed then report the failed index */
2832 if (index != req->shift_count) {
2833 rc = NPC_MCAM_PERM_DENIED;
2834 rsp->failed_entry_idx = index;
2837 mutex_unlock(&mcam->lock);
2841 int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
2842 struct npc_mcam_alloc_counter_req *req,
2843 struct npc_mcam_alloc_counter_rsp *rsp)
2845 struct npc_mcam *mcam = &rvu->hw->mcam;
2846 u16 pcifunc = req->hdr.pcifunc;
2847 u16 max_contig, cntr;
2850 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2852 return NPC_MCAM_INVALID_REQ;
2854 /* If the request is from a PFFUNC with no NIXLF attached, ignore */
2855 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2856 return NPC_MCAM_INVALID_REQ;
2858 /* Since list of allocated counter IDs needs to be sent to requester,
2859 * max number of non-contiguous counters per mbox msg is limited.
2861 if (!req->contig && req->count > NPC_MAX_NONCONTIG_COUNTERS)
2862 return NPC_MCAM_INVALID_REQ;
2864 mutex_lock(&mcam->lock);
2866 /* Check if unused counters are available or not */
2867 if (!rvu_rsrc_free_count(&mcam->counters)) {
2868 mutex_unlock(&mcam->lock);
2869 return NPC_MCAM_ALLOC_FAILED;
2875 /* Allocate requested number of contiguous counters, if
2876 * unsuccessful find max contiguous entries available.
2878 index = npc_mcam_find_zero_area(mcam->counters.bmap,
2879 mcam->counters.max, 0,
2880 req->count, &max_contig);
2881 rsp->count = max_contig;
2883 for (cntr = index; cntr < (index + max_contig); cntr++) {
2884 __set_bit(cntr, mcam->counters.bmap);
2885 mcam->cntr2pfvf_map[cntr] = pcifunc;
2888 /* Allocate requested number of non-contiguous counters,
2889 * if unsuccessful allocate as many as possible.
2891 for (cntr = 0; cntr < req->count; cntr++) {
2892 index = rvu_alloc_rsrc(&mcam->counters);
2895 rsp->cntr_list[cntr] = index;
2897 mcam->cntr2pfvf_map[index] = pcifunc;
2901 mutex_unlock(&mcam->lock);
2905 int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
2906 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
2908 struct npc_mcam *mcam = &rvu->hw->mcam;
2909 u16 index, entry = 0;
2912 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2914 return NPC_MCAM_INVALID_REQ;
2916 mutex_lock(&mcam->lock);
2917 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2919 mutex_unlock(&mcam->lock);
2923 /* Mark counter as free/unused */
2924 mcam->cntr2pfvf_map[req->cntr] = NPC_MCAM_INVALID_MAP;
2925 rvu_free_rsrc(&mcam->counters, req->cntr);
2927 /* Disable all MCAM entry's stats which are using this counter */
2928 while (entry < mcam->bmap_entries) {
2929 if (!mcam->cntr_refcnt[req->cntr])
2932 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2933 if (index >= mcam->bmap_entries)
2936 if (mcam->entry2cntr_map[index] != req->cntr)
2939 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2943 mutex_unlock(&mcam->lock);
2947 int rvu_mbox_handler_npc_mcam_unmap_counter(struct rvu *rvu,
2948 struct npc_mcam_unmap_counter_req *req, struct msg_rsp *rsp)
2950 struct npc_mcam *mcam = &rvu->hw->mcam;
2951 u16 index, entry = 0;
2954 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2956 return NPC_MCAM_INVALID_REQ;
2958 mutex_lock(&mcam->lock);
2959 rc = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2963 /* Unmap the MCAM entry and counter */
2965 rc = npc_mcam_verify_entry(mcam, req->hdr.pcifunc, req->entry);
2968 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2969 req->entry, req->cntr);
2973 /* Disable all MCAM entry's stats which are using this counter */
2974 while (entry < mcam->bmap_entries) {
2975 if (!mcam->cntr_refcnt[req->cntr])
2978 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2979 if (index >= mcam->bmap_entries)
2983 if (mcam->entry2cntr_map[index] != req->cntr)
2986 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2990 mutex_unlock(&mcam->lock);
2994 int rvu_mbox_handler_npc_mcam_clear_counter(struct rvu *rvu,
2995 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
2997 struct npc_mcam *mcam = &rvu->hw->mcam;
3000 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3002 return NPC_MCAM_INVALID_REQ;
3004 mutex_lock(&mcam->lock);
3005 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3006 mutex_unlock(&mcam->lock);
3010 rvu_write64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr), 0x00);
3015 int rvu_mbox_handler_npc_mcam_counter_stats(struct rvu *rvu,
3016 struct npc_mcam_oper_counter_req *req,
3017 struct npc_mcam_oper_counter_rsp *rsp)
3019 struct npc_mcam *mcam = &rvu->hw->mcam;
3022 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3024 return NPC_MCAM_INVALID_REQ;
3026 mutex_lock(&mcam->lock);
3027 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3028 mutex_unlock(&mcam->lock);
3032 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr));
3033 rsp->stat &= BIT_ULL(48) - 1;
3038 int rvu_mbox_handler_npc_mcam_alloc_and_write_entry(struct rvu *rvu,
3039 struct npc_mcam_alloc_and_write_entry_req *req,
3040 struct npc_mcam_alloc_and_write_entry_rsp *rsp)
3042 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
3043 struct npc_mcam_alloc_counter_req cntr_req;
3044 struct npc_mcam_alloc_counter_rsp cntr_rsp;
3045 struct npc_mcam_alloc_entry_req entry_req;
3046 struct npc_mcam_alloc_entry_rsp entry_rsp;
3047 struct npc_mcam *mcam = &rvu->hw->mcam;
3048 u16 entry = NPC_MCAM_ENTRY_INVALID;
3049 u16 cntr = NPC_MCAM_ENTRY_INVALID;
3053 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3055 return NPC_MCAM_INVALID_REQ;
3057 if (!is_npc_interface_valid(rvu, req->intf))
3058 return NPC_MCAM_INVALID_REQ;
3060 if (npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf,
3062 return NPC_MCAM_INVALID_REQ;
3064 /* Try to allocate a MCAM entry */
3065 entry_req.hdr.pcifunc = req->hdr.pcifunc;
3066 entry_req.contig = true;
3067 entry_req.priority = req->priority;
3068 entry_req.ref_entry = req->ref_entry;
3069 entry_req.count = 1;
3071 rc = rvu_mbox_handler_npc_mcam_alloc_entry(rvu,
3072 &entry_req, &entry_rsp);
3076 if (!entry_rsp.count)
3077 return NPC_MCAM_ALLOC_FAILED;
3079 entry = entry_rsp.entry;
3081 if (!req->alloc_cntr)
3084 /* Now allocate counter */
3085 cntr_req.hdr.pcifunc = req->hdr.pcifunc;
3086 cntr_req.contig = true;
3089 rc = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
3091 /* Free allocated MCAM entry */
3092 mutex_lock(&mcam->lock);
3093 mcam->entry2pfvf_map[entry] = NPC_MCAM_INVALID_MAP;
3094 npc_mcam_clear_bit(mcam, entry);
3095 mutex_unlock(&mcam->lock);
3099 cntr = cntr_rsp.cntr;
3102 mutex_lock(&mcam->lock);
3104 if (is_npc_intf_tx(req->intf))
3105 nix_intf = pfvf->nix_tx_intf;
3107 nix_intf = pfvf->nix_rx_intf;
3109 npc_config_mcam_entry(rvu, mcam, blkaddr, entry, nix_intf,
3110 &req->entry_data, req->enable_entry);
3112 if (req->alloc_cntr)
3113 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr, entry, cntr);
3114 mutex_unlock(&mcam->lock);
3122 #define GET_KEX_CFG(intf) \
3123 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_INTFX_KEX_CFG(intf))
3125 #define GET_KEX_FLAGS(ld) \
3126 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld))
3128 #define GET_KEX_LD(intf, lid, lt, ld) \
3129 rvu_read64(rvu, BLKADDR_NPC, \
3130 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, lt, ld))
3132 #define GET_KEX_LDFLAGS(intf, ld, fl) \
3133 rvu_read64(rvu, BLKADDR_NPC, \
3134 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, fl))
3136 int rvu_mbox_handler_npc_get_kex_cfg(struct rvu *rvu, struct msg_req *req,
3137 struct npc_get_kex_cfg_rsp *rsp)
3139 int lid, lt, ld, fl;
3141 rsp->rx_keyx_cfg = GET_KEX_CFG(NIX_INTF_RX);
3142 rsp->tx_keyx_cfg = GET_KEX_CFG(NIX_INTF_TX);
3143 for (lid = 0; lid < NPC_MAX_LID; lid++) {
3144 for (lt = 0; lt < NPC_MAX_LT; lt++) {
3145 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3146 rsp->intf_lid_lt_ld[NIX_INTF_RX][lid][lt][ld] =
3147 GET_KEX_LD(NIX_INTF_RX, lid, lt, ld);
3148 rsp->intf_lid_lt_ld[NIX_INTF_TX][lid][lt][ld] =
3149 GET_KEX_LD(NIX_INTF_TX, lid, lt, ld);
3153 for (ld = 0; ld < NPC_MAX_LD; ld++)
3154 rsp->kex_ld_flags[ld] = GET_KEX_FLAGS(ld);
3156 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3157 for (fl = 0; fl < NPC_MAX_LFL; fl++) {
3158 rsp->intf_ld_flags[NIX_INTF_RX][ld][fl] =
3159 GET_KEX_LDFLAGS(NIX_INTF_RX, ld, fl);
3160 rsp->intf_ld_flags[NIX_INTF_TX][ld][fl] =
3161 GET_KEX_LDFLAGS(NIX_INTF_TX, ld, fl);
3164 memcpy(rsp->mkex_pfl_name, rvu->mkex_pfl_name, MKEX_NAME_LEN);
3169 npc_set_var_len_offset_pkind(struct rvu *rvu, u16 pcifunc, u64 pkind,
3170 u8 var_len_off, u8 var_len_off_mask, u8 shift_dir)
3172 struct npc_kpu_action0 *act0;
3177 if (!var_len_off_mask)
3180 if (var_len_off_mask != 0xff) {
3182 shift_count = __ffs(var_len_off_mask);
3184 shift_count = (8 - __fls(var_len_off_mask));
3186 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, pcifunc);
3188 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
3191 val = rvu_read64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind));
3192 act0 = (struct npc_kpu_action0 *)&val;
3193 act0->var_len_shift = shift_count;
3194 act0->var_len_right = shift_dir;
3195 act0->var_len_mask = var_len_off_mask;
3196 act0->var_len_offset = var_len_off;
3197 rvu_write64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind), val);
3201 int rvu_npc_set_parse_mode(struct rvu *rvu, u16 pcifunc, u64 mode, u8 dir,
3202 u64 pkind, u8 var_len_off, u8 var_len_off_mask,
3206 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
3207 int blkaddr, nixlf, rc, intf_mode;
3208 int pf = rvu_get_pf(pcifunc);
3209 u64 rxpkind, txpkind;
3212 /* use default pkind to disable edsa/higig */
3213 rxpkind = rvu_npc_get_pkind(rvu, pf);
3214 txpkind = NPC_TX_DEF_PKIND;
3215 intf_mode = NPC_INTF_MODE_DEF;
3217 if (mode & OTX2_PRIV_FLAGS_CUSTOM) {
3218 if (pkind == NPC_RX_CUSTOM_PRE_L2_PKIND) {
3219 rc = npc_set_var_len_offset_pkind(rvu, pcifunc, pkind,
3230 if (dir & PKIND_RX) {
3231 /* rx pkind set req valid only for cgx mapped PFs */
3232 if (!is_cgx_config_permitted(rvu, pcifunc))
3234 rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
3236 rc = cgx_set_pkind(rvu_cgx_pdata(cgx_id, rvu), lmac_id,
3242 if (dir & PKIND_TX) {
3243 /* Tx pkind set request valid if PCIFUNC has NIXLF attached */
3244 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, &blkaddr);
3248 rvu_write64(rvu, blkaddr, NIX_AF_LFX_TX_PARSE_CFG(nixlf),
3252 pfvf->intf_mode = intf_mode;
3256 int rvu_mbox_handler_npc_set_pkind(struct rvu *rvu, struct npc_set_pkind *req,
3257 struct msg_rsp *rsp)
3259 return rvu_npc_set_parse_mode(rvu, req->hdr.pcifunc, req->mode,
3260 req->dir, req->pkind, req->var_len_off,
3261 req->var_len_off_mask, req->shift_dir);
3264 int rvu_mbox_handler_npc_read_base_steer_rule(struct rvu *rvu,
3265 struct msg_req *req,
3266 struct npc_mcam_read_base_rule_rsp *rsp)
3268 struct npc_mcam *mcam = &rvu->hw->mcam;
3269 int index, blkaddr, nixlf, rc = 0;
3270 u16 pcifunc = req->hdr.pcifunc;
3271 struct rvu_pfvf *pfvf;
3274 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3276 return NPC_MCAM_INVALID_REQ;
3278 /* Return the channel number in case of PF */
3279 if (!(pcifunc & RVU_PFVF_FUNC_MASK)) {
3280 pfvf = rvu_get_pfvf(rvu, pcifunc);
3281 rsp->entry.kw[0] = pfvf->rx_chan_base;
3282 rsp->entry.kw_mask[0] = 0xFFFULL;
3286 /* Find the pkt steering rule installed by PF to this VF */
3287 mutex_lock(&mcam->lock);
3288 for (index = 0; index < mcam->bmap_entries; index++) {
3289 if (mcam->entry2target_pffunc[index] == pcifunc)
3293 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, NULL);
3295 mutex_unlock(&mcam->lock);
3298 /* Read the default ucast entry if there is no pkt steering rule */
3299 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
3302 /* Read the mcam entry */
3303 npc_read_mcam_entry(rvu, mcam, blkaddr, index, &rsp->entry, &intf,
3305 mutex_unlock(&mcam->lock);
3310 int rvu_mbox_handler_npc_mcam_entry_stats(struct rvu *rvu,
3311 struct npc_mcam_get_stats_req *req,
3312 struct npc_mcam_get_stats_rsp *rsp)
3314 struct npc_mcam *mcam = &rvu->hw->mcam;
3320 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3322 return NPC_MCAM_INVALID_REQ;
3324 mutex_lock(&mcam->lock);
3326 index = req->entry & (mcam->banksize - 1);
3327 bank = npc_get_bank(mcam, req->entry);
3329 /* read MCAM entry STAT_ACT register */
3330 regval = rvu_read64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank));
3332 if (!(regval & rvu->hw->npc_stat_ena)) {
3334 mutex_unlock(&mcam->lock);
3338 cntr = regval & 0x1FF;
3341 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(cntr));
3342 rsp->stat &= BIT_ULL(48) - 1;
3344 mutex_unlock(&mcam->lock);