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 struct rvu_npc_mcam_rule *rule;
406 u16 owner, target_func;
407 struct rvu_pfvf *pfvf;
410 owner = mcam->entry2pfvf_map[index];
411 target_func = (entry->action >> 4) & 0xffff;
412 /* do nothing when target is LBK/PF or owner is not PF */
413 if (is_pffunc_af(owner) || is_afvf(target_func) ||
414 (owner & RVU_PFVF_FUNC_MASK) ||
415 !(target_func & RVU_PFVF_FUNC_MASK))
418 /* save entry2target_pffunc */
419 pfvf = rvu_get_pfvf(rvu, target_func);
420 mcam->entry2target_pffunc[index] = target_func;
422 /* don't enable rule when nixlf not attached or initialized */
423 if (!(is_nixlf_attached(rvu, target_func) &&
424 test_bit(NIXLF_INITIALIZED, &pfvf->flags)))
427 /* fix up not needed for the rules added by user(ntuple filters) */
428 list_for_each_entry(rule, &mcam->mcam_rules, list) {
429 if (rule->entry == index)
433 /* copy VF default entry action to the VF mcam entry */
434 rx_action = npc_get_default_entry_action(rvu, mcam, blkaddr,
437 entry->action = rx_action;
440 static void npc_config_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
441 int blkaddr, int index, u8 intf,
442 struct mcam_entry *entry, bool enable)
444 int bank = npc_get_bank(mcam, index);
445 int kw = 0, actbank, actindex;
446 u8 tx_intf_mask = ~intf & 0x3;
450 actbank = bank; /* Save bank id, to set action later on */
452 index &= (mcam->banksize - 1);
454 /* Disable before mcam entry update */
455 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex, false);
457 /* Clear mcam entry to avoid writes being suppressed by NPC */
458 npc_clear_mcam_entry(rvu, mcam, blkaddr, actindex);
460 /* CAM1 takes the comparison value and
461 * CAM0 specifies match for a bit in key being '0' or '1' or 'dontcare'.
462 * CAM1<n> = 0 & CAM0<n> = 1 => match if key<n> = 0
463 * CAM1<n> = 1 & CAM0<n> = 0 => match if key<n> = 1
464 * CAM1<n> = 0 & CAM0<n> = 0 => always match i.e dontcare.
466 for (; bank < (actbank + mcam->banks_per_entry); bank++, kw = kw + 2) {
467 /* Interface should be set in all banks */
468 if (is_npc_intf_tx(intf)) {
469 /* Last bit must be set and rest don't care
473 tx_intf = intf & tx_intf_mask;
474 tx_intf_mask = ~tx_intf & tx_intf_mask;
477 rvu_write64(rvu, blkaddr,
478 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 1),
480 rvu_write64(rvu, blkaddr,
481 NPC_AF_MCAMEX_BANKX_CAMX_INTF(index, bank, 0),
484 /* Set the match key */
485 npc_get_keyword(entry, kw, &cam0, &cam1);
486 rvu_write64(rvu, blkaddr,
487 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 1), cam1);
488 rvu_write64(rvu, blkaddr,
489 NPC_AF_MCAMEX_BANKX_CAMX_W0(index, bank, 0), cam0);
491 npc_get_keyword(entry, kw + 1, &cam0, &cam1);
492 rvu_write64(rvu, blkaddr,
493 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 1), cam1);
494 rvu_write64(rvu, blkaddr,
495 NPC_AF_MCAMEX_BANKX_CAMX_W1(index, bank, 0), cam0);
498 /* PF installing VF rule */
499 if (is_npc_intf_rx(intf) && actindex < mcam->bmap_entries)
500 npc_fixup_vf_rule(rvu, mcam, blkaddr, actindex, entry, &enable);
503 rvu_write64(rvu, blkaddr,
504 NPC_AF_MCAMEX_BANKX_ACTION(index, actbank), entry->action);
506 /* Set TAG 'action' */
507 rvu_write64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_TAG_ACT(index, actbank),
510 /* Enable the entry */
512 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex, true);
515 void npc_read_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
516 int blkaddr, u16 src,
517 struct mcam_entry *entry, u8 *intf, u8 *ena)
519 int sbank = npc_get_bank(mcam, src);
523 src &= (mcam->banksize - 1);
526 for (; bank < (sbank + mcam->banks_per_entry); bank++, kw = kw + 2) {
527 cam1 = rvu_read64(rvu, blkaddr,
528 NPC_AF_MCAMEX_BANKX_CAMX_W0(src, bank, 1));
529 cam0 = rvu_read64(rvu, blkaddr,
530 NPC_AF_MCAMEX_BANKX_CAMX_W0(src, bank, 0));
531 npc_fill_entryword(entry, kw, cam0, cam1);
533 cam1 = rvu_read64(rvu, blkaddr,
534 NPC_AF_MCAMEX_BANKX_CAMX_W1(src, bank, 1));
535 cam0 = rvu_read64(rvu, blkaddr,
536 NPC_AF_MCAMEX_BANKX_CAMX_W1(src, bank, 0));
537 npc_fill_entryword(entry, kw + 1, cam0, cam1);
540 entry->action = rvu_read64(rvu, blkaddr,
541 NPC_AF_MCAMEX_BANKX_ACTION(src, sbank));
543 rvu_read64(rvu, blkaddr,
544 NPC_AF_MCAMEX_BANKX_TAG_ACT(src, sbank));
545 *intf = rvu_read64(rvu, blkaddr,
546 NPC_AF_MCAMEX_BANKX_CAMX_INTF(src, sbank, 1)) & 3;
547 *ena = rvu_read64(rvu, blkaddr,
548 NPC_AF_MCAMEX_BANKX_CFG(src, sbank)) & 1;
551 static void npc_copy_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
552 int blkaddr, u16 src, u16 dest)
554 int dbank = npc_get_bank(mcam, dest);
555 int sbank = npc_get_bank(mcam, src);
559 src &= (mcam->banksize - 1);
560 dest &= (mcam->banksize - 1);
562 /* Copy INTF's, W0's, W1's CAM0 and CAM1 configuration */
563 for (bank = 0; bank < mcam->banks_per_entry; bank++) {
564 sreg = NPC_AF_MCAMEX_BANKX_CAMX_INTF(src, sbank + bank, 0);
565 dreg = NPC_AF_MCAMEX_BANKX_CAMX_INTF(dest, dbank + bank, 0);
566 for (i = 0; i < 6; i++) {
567 cfg = rvu_read64(rvu, blkaddr, sreg + (i * 8));
568 rvu_write64(rvu, blkaddr, dreg + (i * 8), cfg);
573 cfg = rvu_read64(rvu, blkaddr,
574 NPC_AF_MCAMEX_BANKX_ACTION(src, sbank));
575 rvu_write64(rvu, blkaddr,
576 NPC_AF_MCAMEX_BANKX_ACTION(dest, dbank), cfg);
578 /* Copy TAG action */
579 cfg = rvu_read64(rvu, blkaddr,
580 NPC_AF_MCAMEX_BANKX_TAG_ACT(src, sbank));
581 rvu_write64(rvu, blkaddr,
582 NPC_AF_MCAMEX_BANKX_TAG_ACT(dest, dbank), cfg);
584 /* Enable or disable */
585 cfg = rvu_read64(rvu, blkaddr,
586 NPC_AF_MCAMEX_BANKX_CFG(src, sbank));
587 rvu_write64(rvu, blkaddr,
588 NPC_AF_MCAMEX_BANKX_CFG(dest, dbank), cfg);
591 static u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
592 int blkaddr, int index)
594 int bank = npc_get_bank(mcam, index);
596 index &= (mcam->banksize - 1);
597 return rvu_read64(rvu, blkaddr,
598 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
601 void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
602 int nixlf, u64 chan, u8 *mac_addr)
604 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
605 struct npc_install_flow_req req = { 0 };
606 struct npc_install_flow_rsp rsp = { 0 };
607 struct npc_mcam *mcam = &rvu->hw->mcam;
608 struct nix_rx_action action;
611 /* AF's and SDP VFs work in promiscuous mode */
612 if (is_afvf(pcifunc) || is_sdp_vf(pcifunc))
615 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
619 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
620 nixlf, NIXLF_UCAST_ENTRY);
622 /* Don't change the action if entry is already enabled
623 * Otherwise RSS action may get overwritten.
625 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, index)) {
626 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
629 *(u64 *)&action = 0x00;
630 action.op = NIX_RX_ACTIONOP_UCAST;
631 action.pf_func = pcifunc;
634 req.default_rule = 1;
635 ether_addr_copy(req.packet.dmac, mac_addr);
636 eth_broadcast_addr((u8 *)&req.mask.dmac);
637 req.features = BIT_ULL(NPC_DMAC);
639 req.chan_mask = 0xFFFU;
640 req.intf = pfvf->nix_rx_intf;
642 req.hdr.pcifunc = 0; /* AF is requester */
643 req.vf = action.pf_func;
644 req.index = action.index;
645 req.match_id = action.match_id;
646 req.flow_key_alg = action.flow_key_alg;
648 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
651 void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
652 int nixlf, u64 chan, u8 chan_cnt)
654 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
655 struct npc_install_flow_req req = { 0 };
656 struct npc_install_flow_rsp rsp = { 0 };
657 struct npc_mcam *mcam = &rvu->hw->mcam;
658 struct rvu_hwinfo *hw = rvu->hw;
659 int blkaddr, ucast_idx, index;
660 struct nix_rx_action action;
663 if (!hw->cap.nix_rx_multicast && is_cgx_vf(rvu, pcifunc))
666 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
670 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
671 nixlf, NIXLF_PROMISC_ENTRY);
673 if (is_cgx_vf(rvu, pcifunc))
674 index = npc_get_nixlf_mcam_index(mcam,
675 pcifunc & ~RVU_PFVF_FUNC_MASK,
676 nixlf, NIXLF_PROMISC_ENTRY);
678 /* If the corresponding PF's ucast action is RSS,
679 * use the same action for promisc also
681 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
682 nixlf, NIXLF_UCAST_ENTRY);
683 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
684 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
687 if (action.op != NIX_RX_ACTIONOP_RSS) {
688 *(u64 *)&action = 0x00;
689 action.op = NIX_RX_ACTIONOP_UCAST;
692 /* RX_ACTION set to MCAST for CGX PF's */
693 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list &&
694 is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc))) {
695 *(u64 *)&action = 0x00;
696 action.op = NIX_RX_ACTIONOP_MCAST;
697 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
698 action.index = pfvf->promisc_mce_idx;
701 /* For cn10k the upper two bits of the channel number are
702 * cpt channel number. with masking out these bits in the
703 * mcam entry, same entry used for NIX will allow packets
704 * received from cpt for parsing.
706 if (!is_rvu_otx2(rvu)) {
707 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
709 req.chan_mask = 0xFFFU;
713 if (!is_power_of_2(chan_cnt)) {
715 "%s: channel count more than 1, must be power of 2\n", __func__);
718 relaxed_mask = GENMASK_ULL(BITS_PER_LONG_LONG - 1,
720 req.chan_mask &= relaxed_mask;
724 req.intf = pfvf->nix_rx_intf;
727 req.hdr.pcifunc = 0; /* AF is requester */
729 req.index = action.index;
730 req.match_id = action.match_id;
731 req.flow_key_alg = action.flow_key_alg;
733 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
736 void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc,
737 int nixlf, bool enable)
739 struct npc_mcam *mcam = &rvu->hw->mcam;
742 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
746 /* Get 'pcifunc' of PF device */
747 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
749 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
750 nixlf, NIXLF_PROMISC_ENTRY);
751 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
754 void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
757 struct rvu_pfvf *pfvf;
758 struct npc_install_flow_req req = { 0 };
759 struct npc_install_flow_rsp rsp = { 0 };
760 struct npc_mcam *mcam = &rvu->hw->mcam;
761 struct rvu_hwinfo *hw = rvu->hw;
764 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
769 if (is_afvf(pcifunc))
772 /* If pkt replication is not supported,
773 * then only PF is allowed to add a bcast match entry.
775 if (!hw->cap.nix_rx_multicast && is_vf(pcifunc))
778 /* Get 'pcifunc' of PF device */
779 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
780 pfvf = rvu_get_pfvf(rvu, pcifunc);
781 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
782 nixlf, NIXLF_BCAST_ENTRY);
784 if (!hw->cap.nix_rx_multicast) {
785 /* Early silicon doesn't support pkt replication,
786 * so install entry with UCAST action, so that PF
787 * receives all broadcast packets.
789 req.op = NIX_RX_ACTIONOP_UCAST;
791 req.op = NIX_RX_ACTIONOP_MCAST;
792 req.index = pfvf->bcast_mce_idx;
795 eth_broadcast_addr((u8 *)&req.packet.dmac);
796 eth_broadcast_addr((u8 *)&req.mask.dmac);
797 req.features = BIT_ULL(NPC_DMAC);
799 req.chan_mask = 0xFFFU;
800 req.intf = pfvf->nix_rx_intf;
802 req.hdr.pcifunc = 0; /* AF is requester */
805 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
808 void rvu_npc_enable_bcast_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
811 struct npc_mcam *mcam = &rvu->hw->mcam;
814 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
818 /* Get 'pcifunc' of PF device */
819 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
821 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
823 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
826 void rvu_npc_install_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
829 struct npc_install_flow_req req = { 0 };
830 struct npc_install_flow_rsp rsp = { 0 };
831 struct npc_mcam *mcam = &rvu->hw->mcam;
832 struct rvu_hwinfo *hw = rvu->hw;
833 int blkaddr, ucast_idx, index;
834 u8 mac_addr[ETH_ALEN] = { 0 };
835 struct nix_rx_action action;
836 struct rvu_pfvf *pfvf;
839 /* Only CGX PF/VF can add allmulticast entry */
840 if (is_afvf(pcifunc) && is_sdp_vf(pcifunc))
843 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
847 /* Get 'pcifunc' of PF device */
848 vf_func = pcifunc & RVU_PFVF_FUNC_MASK;
849 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
850 pfvf = rvu_get_pfvf(rvu, pcifunc);
851 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
852 nixlf, NIXLF_ALLMULTI_ENTRY);
854 /* If the corresponding PF's ucast action is RSS,
855 * use the same action for multicast entry also
857 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
858 nixlf, NIXLF_UCAST_ENTRY);
859 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
860 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
863 if (action.op != NIX_RX_ACTIONOP_RSS) {
864 *(u64 *)&action = 0x00;
865 action.op = NIX_RX_ACTIONOP_UCAST;
866 action.pf_func = pcifunc;
869 /* RX_ACTION set to MCAST for CGX PF's */
870 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list) {
871 *(u64 *)&action = 0x00;
872 action.op = NIX_RX_ACTIONOP_MCAST;
873 action.index = pfvf->mcast_mce_idx;
876 mac_addr[0] = 0x01; /* LSB bit of 1st byte in DMAC */
877 ether_addr_copy(req.packet.dmac, mac_addr);
878 ether_addr_copy(req.mask.dmac, mac_addr);
879 req.features = BIT_ULL(NPC_DMAC);
881 /* For cn10k the upper two bits of the channel number are
882 * cpt channel number. with masking out these bits in the
883 * mcam entry, same entry used for NIX will allow packets
884 * received from cpt for parsing.
886 if (!is_rvu_otx2(rvu))
887 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
889 req.chan_mask = 0xFFFU;
892 req.intf = pfvf->nix_rx_intf;
895 req.hdr.pcifunc = 0; /* AF is requester */
896 req.vf = pcifunc | vf_func;
897 req.index = action.index;
898 req.match_id = action.match_id;
899 req.flow_key_alg = action.flow_key_alg;
901 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
904 void rvu_npc_enable_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
907 struct npc_mcam *mcam = &rvu->hw->mcam;
910 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
914 /* Get 'pcifunc' of PF device */
915 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
917 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
918 NIXLF_ALLMULTI_ENTRY);
919 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
922 static void npc_update_vf_flow_entry(struct rvu *rvu, struct npc_mcam *mcam,
923 int blkaddr, u16 pcifunc, u64 rx_action)
925 int actindex, index, bank, entry;
926 struct rvu_npc_mcam_rule *rule;
929 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
932 mutex_lock(&mcam->lock);
933 for (index = 0; index < mcam->bmap_entries; index++) {
934 if (mcam->entry2target_pffunc[index] == pcifunc) {
936 /* update not needed for the rules added via ntuple filters */
937 list_for_each_entry(rule, &mcam->mcam_rules, list) {
938 if (rule->entry == index)
943 bank = npc_get_bank(mcam, index);
945 entry = index & (mcam->banksize - 1);
947 /* read vf flow entry enable status */
948 enable = is_mcam_entry_enabled(rvu, mcam, blkaddr,
950 /* disable before mcam entry update */
951 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex,
953 /* update 'action' */
954 rvu_write64(rvu, blkaddr,
955 NPC_AF_MCAMEX_BANKX_ACTION(entry, bank),
958 npc_enable_mcam_entry(rvu, mcam, blkaddr,
962 mutex_unlock(&mcam->lock);
965 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
966 int group, int alg_idx, int mcam_index)
968 struct npc_mcam *mcam = &rvu->hw->mcam;
969 struct rvu_hwinfo *hw = rvu->hw;
970 struct nix_rx_action action;
971 int blkaddr, index, bank;
972 struct rvu_pfvf *pfvf;
974 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
978 /* Check if this is for reserved default entry */
979 if (mcam_index < 0) {
980 if (group != DEFAULT_RSS_CONTEXT_GROUP)
982 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
983 nixlf, NIXLF_UCAST_ENTRY);
985 /* TODO: validate this mcam index */
989 if (index >= mcam->total_entries)
992 bank = npc_get_bank(mcam, index);
993 index &= (mcam->banksize - 1);
995 *(u64 *)&action = rvu_read64(rvu, blkaddr,
996 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
997 /* Ignore if no action was set earlier */
998 if (!*(u64 *)&action)
1001 action.op = NIX_RX_ACTIONOP_RSS;
1002 action.pf_func = pcifunc;
1003 action.index = group;
1004 action.flow_key_alg = alg_idx;
1006 rvu_write64(rvu, blkaddr,
1007 NPC_AF_MCAMEX_BANKX_ACTION(index, bank), *(u64 *)&action);
1009 /* update the VF flow rule action with the VF default entry action */
1011 npc_update_vf_flow_entry(rvu, mcam, blkaddr, pcifunc,
1014 /* update the action change in default rule */
1015 pfvf = rvu_get_pfvf(rvu, pcifunc);
1016 if (pfvf->def_ucast_rule)
1017 pfvf->def_ucast_rule->rx_action = action;
1019 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1020 nixlf, NIXLF_PROMISC_ENTRY);
1022 /* If PF's promiscuous entry is enabled,
1023 * Set RSS action for that entry as well
1025 if ((!hw->cap.nix_rx_multicast || !pfvf->use_mce_list) &&
1026 is_mcam_entry_enabled(rvu, mcam, blkaddr, index)) {
1027 bank = npc_get_bank(mcam, index);
1028 index &= (mcam->banksize - 1);
1030 rvu_write64(rvu, blkaddr,
1031 NPC_AF_MCAMEX_BANKX_ACTION(index, bank),
1036 void npc_enadis_default_mce_entry(struct rvu *rvu, u16 pcifunc,
1037 int nixlf, int type, bool enable)
1039 struct npc_mcam *mcam = &rvu->hw->mcam;
1040 struct rvu_hwinfo *hw = rvu->hw;
1041 struct nix_mce_list *mce_list;
1042 int index, blkaddr, mce_idx;
1043 struct rvu_pfvf *pfvf;
1045 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1049 index = npc_get_nixlf_mcam_index(mcam, pcifunc & ~RVU_PFVF_FUNC_MASK,
1052 /* disable MCAM entry when packet replication is not supported by hw */
1053 if (!hw->cap.nix_rx_multicast && !is_vf(pcifunc)) {
1054 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1058 /* return incase mce list is not enabled */
1059 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
1060 if (hw->cap.nix_rx_multicast && is_vf(pcifunc) &&
1061 type != NIXLF_BCAST_ENTRY && !pfvf->use_mce_list)
1064 nix_get_mce_list(rvu, pcifunc, type, &mce_list, &mce_idx);
1066 nix_update_mce_list(rvu, pcifunc, mce_list,
1067 mce_idx, index, enable);
1069 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1072 static void npc_enadis_default_entries(struct rvu *rvu, u16 pcifunc,
1073 int nixlf, bool enable)
1075 struct npc_mcam *mcam = &rvu->hw->mcam;
1078 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1082 /* Ucast MCAM match entry of this PF/VF */
1083 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1084 nixlf, NIXLF_UCAST_ENTRY);
1085 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1087 /* Nothing to do for VFs, on platforms where pkt replication
1090 if ((pcifunc & RVU_PFVF_FUNC_MASK) && !rvu->hw->cap.nix_rx_multicast)
1093 /* add/delete pf_func to broadcast MCE list */
1094 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1095 NIXLF_BCAST_ENTRY, enable);
1098 void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1100 npc_enadis_default_entries(rvu, pcifunc, nixlf, false);
1102 /* Delete multicast and promisc MCAM entries */
1103 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1104 NIXLF_ALLMULTI_ENTRY, false);
1105 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1106 NIXLF_PROMISC_ENTRY, false);
1109 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1111 /* Enables only broadcast match entry. Promisc/Allmulti are enabled
1112 * in set_rx_mode mbox handler.
1114 npc_enadis_default_entries(rvu, pcifunc, nixlf, true);
1117 void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1119 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
1120 struct npc_mcam *mcam = &rvu->hw->mcam;
1121 struct rvu_npc_mcam_rule *rule, *tmp;
1124 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1128 mutex_lock(&mcam->lock);
1130 /* Disable MCAM entries directing traffic to this 'pcifunc' */
1131 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1132 if (is_npc_intf_rx(rule->intf) &&
1133 rule->rx_action.pf_func == pcifunc &&
1134 rule->rx_action.op != NIX_RX_ACTIONOP_MCAST) {
1135 npc_enable_mcam_entry(rvu, mcam, blkaddr,
1136 rule->entry, false);
1137 rule->enable = false;
1138 /* Indicate that default rule is disabled */
1139 if (rule->default_rule) {
1140 pfvf->def_ucast_rule = NULL;
1141 list_del(&rule->list);
1147 mutex_unlock(&mcam->lock);
1149 npc_mcam_disable_flows(rvu, pcifunc);
1151 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1154 void rvu_npc_free_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1156 struct npc_mcam *mcam = &rvu->hw->mcam;
1157 struct rvu_npc_mcam_rule *rule, *tmp;
1160 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1164 mutex_lock(&mcam->lock);
1166 /* Free all MCAM entries owned by this 'pcifunc' */
1167 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
1169 /* Free all MCAM counters owned by this 'pcifunc' */
1170 npc_mcam_free_all_counters(rvu, mcam, pcifunc);
1172 /* Delete MCAM entries owned by this 'pcifunc' */
1173 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1174 if (rule->owner == pcifunc && !rule->default_rule) {
1175 list_del(&rule->list);
1180 mutex_unlock(&mcam->lock);
1182 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1185 #define SET_KEX_LD(intf, lid, ltype, ld, cfg) \
1186 rvu_write64(rvu, blkaddr, \
1187 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, ltype, ld), cfg)
1189 #define SET_KEX_LDFLAGS(intf, ld, flags, cfg) \
1190 rvu_write64(rvu, blkaddr, \
1191 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, flags), cfg)
1193 static void npc_program_mkex_rx(struct rvu *rvu, int blkaddr,
1194 struct npc_mcam_kex *mkex, u8 intf)
1196 int lid, lt, ld, fl;
1198 if (is_npc_intf_tx(intf))
1201 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1202 mkex->keyx_cfg[NIX_INTF_RX]);
1205 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1206 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1207 for (ld = 0; ld < NPC_MAX_LD; ld++)
1208 SET_KEX_LD(intf, lid, lt, ld,
1209 mkex->intf_lid_lt_ld[NIX_INTF_RX]
1213 /* Program LFLAGS */
1214 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1215 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1216 SET_KEX_LDFLAGS(intf, ld, fl,
1217 mkex->intf_ld_flags[NIX_INTF_RX]
1222 static void npc_program_mkex_tx(struct rvu *rvu, int blkaddr,
1223 struct npc_mcam_kex *mkex, u8 intf)
1225 int lid, lt, ld, fl;
1227 if (is_npc_intf_rx(intf))
1230 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1231 mkex->keyx_cfg[NIX_INTF_TX]);
1234 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1235 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1236 for (ld = 0; ld < NPC_MAX_LD; ld++)
1237 SET_KEX_LD(intf, lid, lt, ld,
1238 mkex->intf_lid_lt_ld[NIX_INTF_TX]
1242 /* Program LFLAGS */
1243 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1244 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1245 SET_KEX_LDFLAGS(intf, ld, fl,
1246 mkex->intf_ld_flags[NIX_INTF_TX]
1251 static void npc_program_mkex_profile(struct rvu *rvu, int blkaddr,
1252 struct npc_mcam_kex *mkex)
1254 struct rvu_hwinfo *hw = rvu->hw;
1258 for (ld = 0; ld < NPC_MAX_LD; ld++)
1259 rvu_write64(rvu, blkaddr, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld),
1260 mkex->kex_ld_flags[ld]);
1262 for (intf = 0; intf < hw->npc_intfs; intf++) {
1263 npc_program_mkex_rx(rvu, blkaddr, mkex, intf);
1264 npc_program_mkex_tx(rvu, blkaddr, mkex, intf);
1268 static int npc_fwdb_prfl_img_map(struct rvu *rvu, void __iomem **prfl_img_addr,
1271 u64 prfl_addr, prfl_sz;
1276 prfl_addr = rvu->fwdata->mcam_addr;
1277 prfl_sz = rvu->fwdata->mcam_sz;
1279 if (!prfl_addr || !prfl_sz)
1282 *prfl_img_addr = ioremap_wc(prfl_addr, prfl_sz);
1283 if (!(*prfl_img_addr))
1291 /* strtoull of "mkexprof" with base:36 */
1292 #define MKEX_END_SIGN 0xdeadbeef
1294 static void npc_load_mkex_profile(struct rvu *rvu, int blkaddr,
1295 const char *mkex_profile)
1297 struct device *dev = &rvu->pdev->dev;
1298 struct npc_mcam_kex *mcam_kex;
1299 void __iomem *mkex_prfl_addr = NULL;
1303 /* If user not selected mkex profile */
1304 if (rvu->kpu_fwdata_sz ||
1305 !strncmp(mkex_profile, def_pfl_name, MKEX_NAME_LEN))
1308 /* Setting up the mapping for mkex profile image */
1309 ret = npc_fwdb_prfl_img_map(rvu, &mkex_prfl_addr, &prfl_sz);
1313 mcam_kex = (struct npc_mcam_kex __force *)mkex_prfl_addr;
1315 while (((s64)prfl_sz > 0) && (mcam_kex->mkex_sign != MKEX_END_SIGN)) {
1316 /* Compare with mkex mod_param name string */
1317 if (mcam_kex->mkex_sign == MKEX_SIGN &&
1318 !strncmp(mcam_kex->name, mkex_profile, MKEX_NAME_LEN)) {
1319 /* Due to an errata (35786) in A0/B0 pass silicon,
1320 * parse nibble enable configuration has to be
1321 * identical for both Rx and Tx interfaces.
1323 if (!is_rvu_96xx_B0(rvu) ||
1324 mcam_kex->keyx_cfg[NIX_INTF_RX] == mcam_kex->keyx_cfg[NIX_INTF_TX])
1325 rvu->kpu.mkex = mcam_kex;
1330 prfl_sz -= sizeof(struct npc_mcam_kex);
1332 dev_warn(dev, "Failed to load requested profile: %s\n", mkex_profile);
1335 dev_info(rvu->dev, "Using %s mkex profile\n", rvu->kpu.mkex->name);
1336 /* Program selected mkex profile */
1337 npc_program_mkex_profile(rvu, blkaddr, rvu->kpu.mkex);
1339 iounmap(mkex_prfl_addr);
1342 static void npc_config_kpuaction(struct rvu *rvu, int blkaddr,
1343 const struct npc_kpu_profile_action *kpuaction,
1344 int kpu, int entry, bool pkind)
1346 struct npc_kpu_action0 action0 = {0};
1347 struct npc_kpu_action1 action1 = {0};
1350 action1.errlev = kpuaction->errlev;
1351 action1.errcode = kpuaction->errcode;
1352 action1.dp0_offset = kpuaction->dp0_offset;
1353 action1.dp1_offset = kpuaction->dp1_offset;
1354 action1.dp2_offset = kpuaction->dp2_offset;
1357 reg = NPC_AF_PKINDX_ACTION1(entry);
1359 reg = NPC_AF_KPUX_ENTRYX_ACTION1(kpu, entry);
1361 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action1);
1363 action0.byp_count = kpuaction->bypass_count;
1364 action0.capture_ena = kpuaction->cap_ena;
1365 action0.parse_done = kpuaction->parse_done;
1366 action0.next_state = kpuaction->next_state;
1367 action0.capture_lid = kpuaction->lid;
1368 action0.capture_ltype = kpuaction->ltype;
1369 action0.capture_flags = kpuaction->flags;
1370 action0.ptr_advance = kpuaction->ptr_advance;
1371 action0.var_len_offset = kpuaction->offset;
1372 action0.var_len_mask = kpuaction->mask;
1373 action0.var_len_right = kpuaction->right;
1374 action0.var_len_shift = kpuaction->shift;
1377 reg = NPC_AF_PKINDX_ACTION0(entry);
1379 reg = NPC_AF_KPUX_ENTRYX_ACTION0(kpu, entry);
1381 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action0);
1384 static void npc_config_kpucam(struct rvu *rvu, int blkaddr,
1385 const struct npc_kpu_profile_cam *kpucam,
1388 struct npc_kpu_cam cam0 = {0};
1389 struct npc_kpu_cam cam1 = {0};
1391 cam1.state = kpucam->state & kpucam->state_mask;
1392 cam1.dp0_data = kpucam->dp0 & kpucam->dp0_mask;
1393 cam1.dp1_data = kpucam->dp1 & kpucam->dp1_mask;
1394 cam1.dp2_data = kpucam->dp2 & kpucam->dp2_mask;
1396 cam0.state = ~kpucam->state & kpucam->state_mask;
1397 cam0.dp0_data = ~kpucam->dp0 & kpucam->dp0_mask;
1398 cam0.dp1_data = ~kpucam->dp1 & kpucam->dp1_mask;
1399 cam0.dp2_data = ~kpucam->dp2 & kpucam->dp2_mask;
1401 rvu_write64(rvu, blkaddr,
1402 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 0), *(u64 *)&cam0);
1403 rvu_write64(rvu, blkaddr,
1404 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 1), *(u64 *)&cam1);
1407 static inline u64 enable_mask(int count)
1409 return (((count) < 64) ? ~(BIT_ULL(count) - 1) : (0x00ULL));
1412 static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu,
1413 const struct npc_kpu_profile *profile)
1415 int entry, num_entries, max_entries;
1418 if (profile->cam_entries != profile->action_entries) {
1420 "KPU%d: CAM and action entries [%d != %d] not equal\n",
1421 kpu, profile->cam_entries, profile->action_entries);
1424 max_entries = rvu->hw->npc_kpu_entries;
1426 /* Program CAM match entries for previous KPU extracted data */
1427 num_entries = min_t(int, profile->cam_entries, max_entries);
1428 for (entry = 0; entry < num_entries; entry++)
1429 npc_config_kpucam(rvu, blkaddr,
1430 &profile->cam[entry], kpu, entry);
1432 /* Program this KPU's actions */
1433 num_entries = min_t(int, profile->action_entries, max_entries);
1434 for (entry = 0; entry < num_entries; entry++)
1435 npc_config_kpuaction(rvu, blkaddr, &profile->action[entry],
1438 /* Enable all programmed entries */
1439 num_entries = min_t(int, profile->action_entries, profile->cam_entries);
1440 entry_mask = enable_mask(num_entries);
1441 /* Disable first KPU_MAX_CST_ENT entries for built-in profile */
1442 if (!rvu->kpu.custom)
1443 entry_mask |= GENMASK_ULL(KPU_MAX_CST_ENT - 1, 0);
1444 rvu_write64(rvu, blkaddr,
1445 NPC_AF_KPUX_ENTRY_DISX(kpu, 0), entry_mask);
1446 if (num_entries > 64) {
1447 rvu_write64(rvu, blkaddr,
1448 NPC_AF_KPUX_ENTRY_DISX(kpu, 1),
1449 enable_mask(num_entries - 64));
1452 /* Enable this KPU */
1453 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(kpu), 0x01);
1456 static int npc_prepare_default_kpu(struct npc_kpu_profile_adapter *profile)
1458 profile->custom = 0;
1459 profile->name = def_pfl_name;
1460 profile->version = NPC_KPU_PROFILE_VER;
1461 profile->ikpu = ikpu_action_entries;
1462 profile->pkinds = ARRAY_SIZE(ikpu_action_entries);
1463 profile->kpu = npc_kpu_profiles;
1464 profile->kpus = ARRAY_SIZE(npc_kpu_profiles);
1465 profile->lt_def = &npc_lt_defaults;
1466 profile->mkex = &npc_mkex_default;
1471 static int npc_apply_custom_kpu(struct rvu *rvu,
1472 struct npc_kpu_profile_adapter *profile)
1474 size_t hdr_sz = sizeof(struct npc_kpu_profile_fwdata), offset = 0;
1475 struct npc_kpu_profile_fwdata *fw = rvu->kpu_fwdata;
1476 struct npc_kpu_profile_action *action;
1477 struct npc_kpu_profile_cam *cam;
1478 struct npc_kpu_fwdata *fw_kpu;
1482 if (rvu->kpu_fwdata_sz < hdr_sz) {
1483 dev_warn(rvu->dev, "Invalid KPU profile size\n");
1486 if (le64_to_cpu(fw->signature) != KPU_SIGN) {
1487 dev_warn(rvu->dev, "Invalid KPU profile signature %llx\n",
1491 /* Verify if the using known profile structure */
1492 if (NPC_KPU_VER_MAJ(profile->version) >
1493 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER)) {
1494 dev_warn(rvu->dev, "Not supported Major version: %d > %d\n",
1495 NPC_KPU_VER_MAJ(profile->version),
1496 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER));
1499 /* Verify if profile is aligned with the required kernel changes */
1500 if (NPC_KPU_VER_MIN(profile->version) <
1501 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER)) {
1503 "Invalid KPU profile version: %d.%d.%d expected version <= %d.%d.%d\n",
1504 NPC_KPU_VER_MAJ(profile->version),
1505 NPC_KPU_VER_MIN(profile->version),
1506 NPC_KPU_VER_PATCH(profile->version),
1507 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER),
1508 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER),
1509 NPC_KPU_VER_PATCH(NPC_KPU_PROFILE_VER));
1512 /* Verify if profile fits the HW */
1513 if (fw->kpus > profile->kpus) {
1514 dev_warn(rvu->dev, "Not enough KPUs: %d > %ld\n", fw->kpus,
1519 profile->custom = 1;
1520 profile->name = fw->name;
1521 profile->version = le64_to_cpu(fw->version);
1522 profile->mkex = &fw->mkex;
1523 profile->lt_def = &fw->lt_def;
1525 for (kpu = 0; kpu < fw->kpus; kpu++) {
1526 fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset);
1527 if (fw_kpu->entries > KPU_MAX_CST_ENT)
1529 "Too many custom entries on KPU%d: %d > %d\n",
1530 kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
1531 entries = min(fw_kpu->entries, KPU_MAX_CST_ENT);
1532 cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
1533 offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
1534 action = (struct npc_kpu_profile_action *)(fw->data + offset);
1535 offset += fw_kpu->entries * sizeof(*action);
1536 if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
1538 "Profile size mismatch on KPU%i parsing.\n",
1542 for (entry = 0; entry < entries; entry++) {
1543 profile->kpu[kpu].cam[entry] = cam[entry];
1544 profile->kpu[kpu].action[entry] = action[entry];
1551 static int npc_load_kpu_prfl_img(struct rvu *rvu, void __iomem *prfl_addr,
1552 u64 prfl_sz, const char *kpu_profile)
1554 struct npc_kpu_profile_fwdata *kpu_data = NULL;
1557 kpu_data = (struct npc_kpu_profile_fwdata __force *)prfl_addr;
1558 if (le64_to_cpu(kpu_data->signature) == KPU_SIGN &&
1559 !strncmp(kpu_data->name, kpu_profile, KPU_NAME_LEN)) {
1560 dev_info(rvu->dev, "Loading KPU profile from firmware db: %s\n",
1562 rvu->kpu_fwdata = kpu_data;
1563 rvu->kpu_fwdata_sz = prfl_sz;
1564 rvu->kpu_prfl_addr = prfl_addr;
1571 static int npc_fwdb_detect_load_prfl_img(struct rvu *rvu, uint64_t prfl_sz,
1572 const char *kpu_profile)
1574 struct npc_coalesced_kpu_prfl *img_data = NULL;
1575 int i = 0, rc = -EINVAL;
1576 void __iomem *kpu_prfl_addr;
1579 img_data = (struct npc_coalesced_kpu_prfl __force *)rvu->kpu_prfl_addr;
1580 if (le64_to_cpu(img_data->signature) == KPU_SIGN &&
1581 !strncmp(img_data->name, kpu_profile, KPU_NAME_LEN)) {
1582 /* Loaded profile is a single KPU profile. */
1583 rc = npc_load_kpu_prfl_img(rvu, rvu->kpu_prfl_addr,
1584 prfl_sz, kpu_profile);
1588 /* Loaded profile is coalesced image, offset of first KPU profile.*/
1589 offset = offsetof(struct npc_coalesced_kpu_prfl, prfl_sz) +
1590 (img_data->num_prfl * sizeof(uint16_t));
1591 /* Check if mapped image is coalesced image. */
1592 while (i < img_data->num_prfl) {
1593 /* Profile image offsets are rounded up to next 8 multiple.*/
1594 offset = ALIGN_8B_CEIL(offset);
1595 kpu_prfl_addr = (void __iomem *)((uintptr_t)rvu->kpu_prfl_addr +
1597 rc = npc_load_kpu_prfl_img(rvu, kpu_prfl_addr,
1598 img_data->prfl_sz[i], kpu_profile);
1601 /* Calculating offset of profile image based on profile size.*/
1602 offset += img_data->prfl_sz[i];
1609 static int npc_load_kpu_profile_fwdb(struct rvu *rvu, const char *kpu_profile)
1614 /* Setting up the mapping for NPC profile image */
1615 ret = npc_fwdb_prfl_img_map(rvu, &rvu->kpu_prfl_addr, &prfl_sz);
1619 /* Detect if profile is coalesced or single KPU profile and load */
1620 ret = npc_fwdb_detect_load_prfl_img(rvu, prfl_sz, kpu_profile);
1624 /* Cleaning up if KPU profile image from fwdata is not valid. */
1625 if (rvu->kpu_prfl_addr) {
1626 iounmap(rvu->kpu_prfl_addr);
1627 rvu->kpu_prfl_addr = NULL;
1628 rvu->kpu_fwdata_sz = 0;
1629 rvu->kpu_fwdata = NULL;
1636 static void npc_load_kpu_profile(struct rvu *rvu)
1638 struct npc_kpu_profile_adapter *profile = &rvu->kpu;
1639 const char *kpu_profile = rvu->kpu_pfl_name;
1640 const struct firmware *fw = NULL;
1641 bool retry_fwdb = false;
1643 /* If user not specified profile customization */
1644 if (!strncmp(kpu_profile, def_pfl_name, KPU_NAME_LEN))
1645 goto revert_to_default;
1646 /* First prepare default KPU, then we'll customize top entries. */
1647 npc_prepare_default_kpu(profile);
1649 /* Order of preceedence for load loading NPC profile (high to low)
1650 * Firmware binary in filesystem.
1651 * Firmware database method.
1652 * Default KPU profile.
1654 if (!request_firmware(&fw, kpu_profile, rvu->dev)) {
1655 dev_info(rvu->dev, "Loading KPU profile from firmware: %s\n",
1657 rvu->kpu_fwdata = kzalloc(fw->size, GFP_KERNEL);
1658 if (rvu->kpu_fwdata) {
1659 memcpy(rvu->kpu_fwdata, fw->data, fw->size);
1660 rvu->kpu_fwdata_sz = fw->size;
1662 release_firmware(fw);
1668 /* Loading the KPU profile using firmware database */
1669 if (npc_load_kpu_profile_fwdb(rvu, kpu_profile))
1670 goto revert_to_default;
1673 /* Apply profile customization if firmware was loaded. */
1674 if (!rvu->kpu_fwdata_sz || npc_apply_custom_kpu(rvu, profile)) {
1675 /* If image from firmware filesystem fails to load or invalid
1676 * retry with firmware database method.
1678 if (rvu->kpu_fwdata || rvu->kpu_fwdata_sz) {
1679 /* Loading image from firmware database failed. */
1680 if (rvu->kpu_prfl_addr) {
1681 iounmap(rvu->kpu_prfl_addr);
1682 rvu->kpu_prfl_addr = NULL;
1684 kfree(rvu->kpu_fwdata);
1686 rvu->kpu_fwdata = NULL;
1687 rvu->kpu_fwdata_sz = 0;
1690 goto load_image_fwdb;
1695 "Can't load KPU profile %s. Using default.\n",
1697 kfree(rvu->kpu_fwdata);
1698 rvu->kpu_fwdata = NULL;
1699 goto revert_to_default;
1702 dev_info(rvu->dev, "Using custom profile '%s', version %d.%d.%d\n",
1703 profile->name, NPC_KPU_VER_MAJ(profile->version),
1704 NPC_KPU_VER_MIN(profile->version),
1705 NPC_KPU_VER_PATCH(profile->version));
1710 npc_prepare_default_kpu(profile);
1713 static void npc_parser_profile_init(struct rvu *rvu, int blkaddr)
1715 struct rvu_hwinfo *hw = rvu->hw;
1716 int num_pkinds, num_kpus, idx;
1718 /* Disable all KPUs and their entries */
1719 for (idx = 0; idx < hw->npc_kpus; idx++) {
1720 rvu_write64(rvu, blkaddr,
1721 NPC_AF_KPUX_ENTRY_DISX(idx, 0), ~0ULL);
1722 rvu_write64(rvu, blkaddr,
1723 NPC_AF_KPUX_ENTRY_DISX(idx, 1), ~0ULL);
1724 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(idx), 0x00);
1727 /* Load and customize KPU profile. */
1728 npc_load_kpu_profile(rvu);
1730 /* First program IKPU profile i.e PKIND configs.
1731 * Check HW max count to avoid configuring junk or
1732 * writing to unsupported CSR addresses.
1734 num_pkinds = rvu->kpu.pkinds;
1735 num_pkinds = min_t(int, hw->npc_pkinds, num_pkinds);
1737 for (idx = 0; idx < num_pkinds; idx++)
1738 npc_config_kpuaction(rvu, blkaddr, &rvu->kpu.ikpu[idx], 0, idx, true);
1740 /* Program KPU CAM and Action profiles */
1741 num_kpus = rvu->kpu.kpus;
1742 num_kpus = min_t(int, hw->npc_kpus, num_kpus);
1744 for (idx = 0; idx < num_kpus; idx++)
1745 npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);
1748 static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1750 int nixlf_count = rvu_get_nixlf_count(rvu);
1751 struct npc_mcam *mcam = &rvu->hw->mcam;
1757 /* Actual number of MCAM entries vary by entry size */
1758 cfg = (rvu_read64(rvu, blkaddr,
1759 NPC_AF_INTFX_KEX_CFG(0)) >> 32) & 0x07;
1760 mcam->total_entries = (mcam->banks / BIT_ULL(cfg)) * mcam->banksize;
1761 mcam->keysize = cfg;
1763 /* Number of banks combined per MCAM entry */
1764 if (cfg == NPC_MCAM_KEY_X4)
1765 mcam->banks_per_entry = 4;
1766 else if (cfg == NPC_MCAM_KEY_X2)
1767 mcam->banks_per_entry = 2;
1769 mcam->banks_per_entry = 1;
1771 /* Reserve one MCAM entry for each of the NIX LF to
1772 * guarantee space to install default matching DMAC rule.
1773 * Also reserve 2 MCAM entries for each PF for default
1774 * channel based matching or 'bcast & promisc' matching to
1775 * support BCAST and PROMISC modes of operation for PFs.
1778 rsvd = (nixlf_count * RSVD_MCAM_ENTRIES_PER_NIXLF) +
1779 ((rvu->hw->total_pfs - 1) * RSVD_MCAM_ENTRIES_PER_PF);
1780 if (mcam->total_entries <= rsvd) {
1782 "Insufficient NPC MCAM size %d for pkt I/O, exiting\n",
1783 mcam->total_entries);
1787 mcam->bmap_entries = mcam->total_entries - rsvd;
1788 mcam->nixlf_offset = mcam->bmap_entries;
1789 mcam->pf_offset = mcam->nixlf_offset + nixlf_count;
1791 /* Allocate bitmaps for managing MCAM entries */
1792 mcam->bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(mcam->bmap_entries),
1793 sizeof(long), GFP_KERNEL);
1797 mcam->bmap_reverse = devm_kcalloc(rvu->dev,
1798 BITS_TO_LONGS(mcam->bmap_entries),
1799 sizeof(long), GFP_KERNEL);
1800 if (!mcam->bmap_reverse)
1803 mcam->bmap_fcnt = mcam->bmap_entries;
1805 /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
1806 mcam->entry2pfvf_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1807 sizeof(u16), GFP_KERNEL);
1808 if (!mcam->entry2pfvf_map)
1811 /* Reserve 1/8th of MCAM entries at the bottom for low priority
1812 * allocations and another 1/8th at the top for high priority
1815 mcam->lprio_count = mcam->bmap_entries / 8;
1816 if (mcam->lprio_count > BITS_PER_LONG)
1817 mcam->lprio_count = round_down(mcam->lprio_count,
1819 mcam->lprio_start = mcam->bmap_entries - mcam->lprio_count;
1820 mcam->hprio_count = mcam->lprio_count;
1821 mcam->hprio_end = mcam->hprio_count;
1824 /* Allocate bitmap for managing MCAM counters and memory
1825 * for saving counter to RVU PFFUNC allocation mapping.
1827 err = rvu_alloc_bitmap(&mcam->counters);
1831 mcam->cntr2pfvf_map = devm_kcalloc(rvu->dev, mcam->counters.max,
1832 sizeof(u16), GFP_KERNEL);
1833 if (!mcam->cntr2pfvf_map)
1836 /* Alloc memory for MCAM entry to counter mapping and for tracking
1837 * counter's reference count.
1839 mcam->entry2cntr_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1840 sizeof(u16), GFP_KERNEL);
1841 if (!mcam->entry2cntr_map)
1844 mcam->cntr_refcnt = devm_kcalloc(rvu->dev, mcam->counters.max,
1845 sizeof(u16), GFP_KERNEL);
1846 if (!mcam->cntr_refcnt)
1849 /* Alloc memory for saving target device of mcam rule */
1850 mcam->entry2target_pffunc = devm_kcalloc(rvu->dev, mcam->total_entries,
1851 sizeof(u16), GFP_KERNEL);
1852 if (!mcam->entry2target_pffunc)
1855 for (index = 0; index < mcam->bmap_entries; index++) {
1856 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
1857 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
1860 for (cntr = 0; cntr < mcam->counters.max; cntr++)
1861 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
1863 mutex_init(&mcam->lock);
1868 kfree(mcam->counters.bmap);
1872 static void rvu_npc_hw_init(struct rvu *rvu, int blkaddr)
1874 struct npc_pkind *pkind = &rvu->hw->pkind;
1875 struct npc_mcam *mcam = &rvu->hw->mcam;
1876 struct rvu_hwinfo *hw = rvu->hw;
1877 u64 npc_const, npc_const1;
1880 npc_const = rvu_read64(rvu, blkaddr, NPC_AF_CONST);
1881 npc_const1 = rvu_read64(rvu, blkaddr, NPC_AF_CONST1);
1882 if (npc_const1 & BIT_ULL(63))
1883 npc_const2 = rvu_read64(rvu, blkaddr, NPC_AF_CONST2);
1885 pkind->rsrc.max = NPC_UNRESERVED_PKIND_COUNT;
1886 hw->npc_pkinds = (npc_const1 >> 12) & 0xFFULL;
1887 hw->npc_kpu_entries = npc_const1 & 0xFFFULL;
1888 hw->npc_kpus = (npc_const >> 8) & 0x1FULL;
1889 hw->npc_intfs = npc_const & 0xFULL;
1890 hw->npc_counters = (npc_const >> 48) & 0xFFFFULL;
1892 mcam->banks = (npc_const >> 44) & 0xFULL;
1893 mcam->banksize = (npc_const >> 28) & 0xFFFFULL;
1894 hw->npc_stat_ena = BIT_ULL(9);
1897 hw->npc_ext_set = true;
1898 /* 96xx supports only match_stats and npc_counters
1899 * reflected in NPC_AF_CONST reg.
1900 * STAT_SEL and ENA are at [0:8] and 9 bit positions.
1901 * 98xx has both match_stat and ext and npc_counter
1902 * reflected in NPC_AF_CONST2
1903 * STAT_SEL_EXT added at [12:14] bit position.
1904 * cn10k supports only ext and hence npc_counters in
1905 * NPC_AF_CONST is 0 and npc_counters reflected in NPC_AF_CONST2.
1906 * STAT_SEL bitpos incremented from [0:8] to [0:11] and ENA bit moved to 63
1908 if (!hw->npc_counters)
1909 hw->npc_stat_ena = BIT_ULL(63);
1910 hw->npc_counters = (npc_const2 >> 16) & 0xFFFFULL;
1911 mcam->banksize = npc_const2 & 0xFFFFULL;
1914 mcam->counters.max = hw->npc_counters;
1917 static void rvu_npc_setup_interfaces(struct rvu *rvu, int blkaddr)
1919 struct npc_mcam *mcam = &rvu->hw->mcam;
1920 struct rvu_hwinfo *hw = rvu->hw;
1921 u64 nibble_ena, rx_kex, tx_kex;
1924 /* Reserve last counter for MCAM RX miss action which is set to
1925 * drop packet. This way we will know how many pkts didn't match
1928 mcam->counters.max--;
1929 mcam->rx_miss_act_cntr = mcam->counters.max;
1931 rx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_RX];
1932 tx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_TX];
1933 nibble_ena = FIELD_GET(NPC_PARSE_NIBBLE, rx_kex);
1935 nibble_ena = rvu_npc_get_tx_nibble_cfg(rvu, nibble_ena);
1937 tx_kex &= ~NPC_PARSE_NIBBLE;
1938 tx_kex |= FIELD_PREP(NPC_PARSE_NIBBLE, nibble_ena);
1939 npc_mkex_default.keyx_cfg[NIX_INTF_TX] = tx_kex;
1942 /* Configure RX interfaces */
1943 for (intf = 0; intf < hw->npc_intfs; intf++) {
1944 if (is_npc_intf_tx(intf))
1947 /* Set RX MCAM search key size. LA..LE (ltype only) + Channel */
1948 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1951 /* If MCAM lookup doesn't result in a match, drop the received
1952 * packet. And map this action to a counter to count dropped
1955 rvu_write64(rvu, blkaddr,
1956 NPC_AF_INTFX_MISS_ACT(intf), NIX_RX_ACTIONOP_DROP);
1958 /* NPC_AF_INTFX_MISS_STAT_ACT[14:12] - counter[11:9]
1959 * NPC_AF_INTFX_MISS_STAT_ACT[8:0] - counter[8:0]
1961 rvu_write64(rvu, blkaddr,
1962 NPC_AF_INTFX_MISS_STAT_ACT(intf),
1963 ((mcam->rx_miss_act_cntr >> 9) << 12) |
1964 hw->npc_stat_ena | mcam->rx_miss_act_cntr);
1967 /* Configure TX interfaces */
1968 for (intf = 0; intf < hw->npc_intfs; intf++) {
1969 if (is_npc_intf_rx(intf))
1972 /* Extract Ltypes LID_LA to LID_LE */
1973 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1976 /* Set TX miss action to UCAST_DEFAULT i.e
1977 * transmit the packet on NIX LF SQ's default channel.
1979 rvu_write64(rvu, blkaddr,
1980 NPC_AF_INTFX_MISS_ACT(intf),
1981 NIX_TX_ACTIONOP_UCAST_DEFAULT);
1985 int rvu_npc_init(struct rvu *rvu)
1987 struct npc_kpu_profile_adapter *kpu = &rvu->kpu;
1988 struct npc_pkind *pkind = &rvu->hw->pkind;
1989 struct npc_mcam *mcam = &rvu->hw->mcam;
1990 int blkaddr, entry, bank, err;
1992 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1994 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
1998 rvu_npc_hw_init(rvu, blkaddr);
2000 /* First disable all MCAM entries, to stop traffic towards NIXLFs */
2001 for (bank = 0; bank < mcam->banks; bank++) {
2002 for (entry = 0; entry < mcam->banksize; entry++)
2003 rvu_write64(rvu, blkaddr,
2004 NPC_AF_MCAMEX_BANKX_CFG(entry, bank), 0);
2007 err = rvu_alloc_bitmap(&pkind->rsrc);
2010 /* Reserve PKIND#0 for LBKs. Power reset value of LBK_CH_PKIND is '0',
2011 * no need to configure PKIND for all LBKs separately.
2013 rvu_alloc_rsrc(&pkind->rsrc);
2015 /* Allocate mem for pkind to PF and channel mapping info */
2016 pkind->pfchan_map = devm_kcalloc(rvu->dev, pkind->rsrc.max,
2017 sizeof(u32), GFP_KERNEL);
2018 if (!pkind->pfchan_map)
2021 /* Configure KPU profile */
2022 npc_parser_profile_init(rvu, blkaddr);
2024 /* Config Outer L2, IPv4's NPC layer info */
2025 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OL2,
2026 (kpu->lt_def->pck_ol2.lid << 8) | (kpu->lt_def->pck_ol2.ltype_match << 4) |
2027 kpu->lt_def->pck_ol2.ltype_mask);
2028 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OIP4,
2029 (kpu->lt_def->pck_oip4.lid << 8) | (kpu->lt_def->pck_oip4.ltype_match << 4) |
2030 kpu->lt_def->pck_oip4.ltype_mask);
2032 /* Config Inner IPV4 NPC layer info */
2033 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_IIP4,
2034 (kpu->lt_def->pck_iip4.lid << 8) | (kpu->lt_def->pck_iip4.ltype_match << 4) |
2035 kpu->lt_def->pck_iip4.ltype_mask);
2037 /* Enable below for Rx pkts.
2038 * - Outer IPv4 header checksum validation.
2039 * - Detect outer L2 broadcast address and set NPC_RESULT_S[L2B].
2040 * - Detect outer L2 multicast address and set NPC_RESULT_S[L2M].
2041 * - Inner IPv4 header checksum validation.
2042 * - Set non zero checksum error code value
2044 rvu_write64(rvu, blkaddr, NPC_AF_PCK_CFG,
2045 rvu_read64(rvu, blkaddr, NPC_AF_PCK_CFG) |
2046 ((u64)NPC_EC_OIP4_CSUM << 32) | (NPC_EC_IIP4_CSUM << 24) |
2047 BIT_ULL(7) | BIT_ULL(6) | BIT_ULL(2) | BIT_ULL(1));
2049 rvu_npc_setup_interfaces(rvu, blkaddr);
2051 /* Configure MKEX profile */
2052 npc_load_mkex_profile(rvu, blkaddr, rvu->mkex_pfl_name);
2054 err = npc_mcam_rsrcs_init(rvu, blkaddr);
2058 err = npc_flow_steering_init(rvu, blkaddr);
2061 "Incorrect mkex profile loaded using default mkex\n");
2062 npc_load_mkex_profile(rvu, blkaddr, def_pfl_name);
2068 void rvu_npc_freemem(struct rvu *rvu)
2070 struct npc_pkind *pkind = &rvu->hw->pkind;
2071 struct npc_mcam *mcam = &rvu->hw->mcam;
2073 kfree(pkind->rsrc.bmap);
2074 kfree(mcam->counters.bmap);
2075 if (rvu->kpu_prfl_addr)
2076 iounmap(rvu->kpu_prfl_addr);
2078 kfree(rvu->kpu_fwdata);
2079 mutex_destroy(&mcam->lock);
2082 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
2083 int blkaddr, int *alloc_cnt,
2086 struct npc_mcam *mcam = &rvu->hw->mcam;
2092 for (entry = 0; entry < mcam->bmap_entries; entry++) {
2093 if (mcam->entry2pfvf_map[entry] == pcifunc) {
2095 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, entry))
2101 void rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
2102 int blkaddr, int *alloc_cnt,
2105 struct npc_mcam *mcam = &rvu->hw->mcam;
2111 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2112 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2114 if (mcam->cntr_refcnt[cntr])
2120 static int npc_mcam_verify_entry(struct npc_mcam *mcam,
2121 u16 pcifunc, int entry)
2123 /* verify AF installed entries */
2124 if (is_pffunc_af(pcifunc))
2126 /* Verify if entry is valid and if it is indeed
2127 * allocated to the requesting PFFUNC.
2129 if (entry >= mcam->bmap_entries)
2130 return NPC_MCAM_INVALID_REQ;
2132 if (pcifunc != mcam->entry2pfvf_map[entry])
2133 return NPC_MCAM_PERM_DENIED;
2138 static int npc_mcam_verify_counter(struct npc_mcam *mcam,
2139 u16 pcifunc, int cntr)
2141 /* Verify if counter is valid and if it is indeed
2142 * allocated to the requesting PFFUNC.
2144 if (cntr >= mcam->counters.max)
2145 return NPC_MCAM_INVALID_REQ;
2147 if (pcifunc != mcam->cntr2pfvf_map[cntr])
2148 return NPC_MCAM_PERM_DENIED;
2153 static void npc_map_mcam_entry_and_cntr(struct rvu *rvu, struct npc_mcam *mcam,
2154 int blkaddr, u16 entry, u16 cntr)
2156 u16 index = entry & (mcam->banksize - 1);
2157 u32 bank = npc_get_bank(mcam, entry);
2158 struct rvu_hwinfo *hw = rvu->hw;
2160 /* Set mapping and increment counter's refcnt */
2161 mcam->entry2cntr_map[entry] = cntr;
2162 mcam->cntr_refcnt[cntr]++;
2164 rvu_write64(rvu, blkaddr,
2165 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank),
2166 ((cntr >> 9) << 12) | hw->npc_stat_ena | cntr);
2169 static void npc_unmap_mcam_entry_and_cntr(struct rvu *rvu,
2170 struct npc_mcam *mcam,
2171 int blkaddr, u16 entry, u16 cntr)
2173 u16 index = entry & (mcam->banksize - 1);
2174 u32 bank = npc_get_bank(mcam, entry);
2176 /* Remove mapping and reduce counter's refcnt */
2177 mcam->entry2cntr_map[entry] = NPC_MCAM_INVALID_MAP;
2178 mcam->cntr_refcnt[cntr]--;
2180 rvu_write64(rvu, blkaddr,
2181 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank), 0x00);
2184 /* Sets MCAM entry in bitmap as used. Update
2185 * reverse bitmap too. Should be called with
2186 * 'mcam->lock' held.
2188 static void npc_mcam_set_bit(struct npc_mcam *mcam, u16 index)
2193 rentry = mcam->bmap_entries - index - 1;
2195 __set_bit(entry, mcam->bmap);
2196 __set_bit(rentry, mcam->bmap_reverse);
2200 /* Sets MCAM entry in bitmap as free. Update
2201 * reverse bitmap too. Should be called with
2202 * 'mcam->lock' held.
2204 static void npc_mcam_clear_bit(struct npc_mcam *mcam, u16 index)
2209 rentry = mcam->bmap_entries - index - 1;
2211 __clear_bit(entry, mcam->bmap);
2212 __clear_bit(rentry, mcam->bmap_reverse);
2216 static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mcam,
2217 int blkaddr, u16 pcifunc)
2221 /* Scan all MCAM entries and free the ones mapped to 'pcifunc' */
2222 for (index = 0; index < mcam->bmap_entries; index++) {
2223 if (mcam->entry2pfvf_map[index] == pcifunc) {
2224 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
2225 /* Free the entry in bitmap */
2226 npc_mcam_clear_bit(mcam, index);
2227 /* Disable the entry */
2228 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false);
2230 /* Update entry2counter mapping */
2231 cntr = mcam->entry2cntr_map[index];
2232 if (cntr != NPC_MCAM_INVALID_MAP)
2233 npc_unmap_mcam_entry_and_cntr(rvu, mcam,
2236 mcam->entry2target_pffunc[index] = 0x0;
2241 static void npc_mcam_free_all_counters(struct rvu *rvu, struct npc_mcam *mcam,
2246 /* Scan all MCAM counters and free the ones mapped to 'pcifunc' */
2247 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2248 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2249 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
2250 mcam->cntr_refcnt[cntr] = 0;
2251 rvu_free_rsrc(&mcam->counters, cntr);
2252 /* This API is expected to be called after freeing
2253 * MCAM entries, which inturn will remove
2254 * 'entry to counter' mapping.
2255 * No need to do it again.
2261 /* Find area of contiguous free entries of size 'nr'.
2262 * If not found return max contiguous free entries available.
2264 static u16 npc_mcam_find_zero_area(unsigned long *map, u16 size, u16 start,
2265 u16 nr, u16 *max_area)
2267 u16 max_area_start = 0;
2268 u16 index, next, end;
2273 index = find_next_zero_bit(map, size, start);
2275 return max_area_start;
2277 end = ((index + nr) >= size) ? size : index + nr;
2278 next = find_next_bit(map, end, index);
2279 if (*max_area < (next - index)) {
2280 *max_area = next - index;
2281 max_area_start = index;
2289 return max_area_start;
2292 /* Find number of free MCAM entries available
2293 * within range i.e in between 'start' and 'end'.
2295 static u16 npc_mcam_get_free_count(unsigned long *map, u16 start, u16 end)
2304 index = find_next_zero_bit(map, end, start);
2308 next = find_next_bit(map, end, index);
2310 fcnt += next - index;
2315 fcnt += end - index;
2320 npc_get_mcam_search_range_priority(struct npc_mcam *mcam,
2321 struct npc_mcam_alloc_entry_req *req,
2322 u16 *start, u16 *end, bool *reverse)
2326 if (req->priority == NPC_MCAM_HIGHER_PRIO)
2329 /* For a low priority entry allocation
2330 * - If reference entry is not in hprio zone then
2331 * search range: ref_entry to end.
2332 * - If reference entry is in hprio zone and if
2333 * request can be accomodated in non-hprio zone then
2334 * search range: 'start of middle zone' to 'end'
2335 * - else search in reverse, so that less number of hprio
2336 * zone entries are allocated.
2340 *start = req->ref_entry + 1;
2341 *end = mcam->bmap_entries;
2343 if (req->ref_entry >= mcam->hprio_end)
2346 fcnt = npc_mcam_get_free_count(mcam->bmap,
2347 mcam->hprio_end, mcam->bmap_entries);
2348 if (fcnt > req->count)
2349 *start = mcam->hprio_end;
2355 /* For a high priority entry allocation, search is always
2356 * in reverse to preserve hprio zone entries.
2357 * - If reference entry is not in lprio zone then
2358 * search range: 0 to ref_entry.
2359 * - If reference entry is in lprio zone and if
2360 * request can be accomodated in middle zone then
2361 * search range: 'hprio_end' to 'lprio_start'
2366 *end = req->ref_entry;
2368 if (req->ref_entry <= mcam->lprio_start)
2371 fcnt = npc_mcam_get_free_count(mcam->bmap,
2372 mcam->hprio_end, mcam->lprio_start);
2373 if (fcnt < req->count)
2375 *start = mcam->hprio_end;
2376 *end = mcam->lprio_start;
2379 static int npc_mcam_alloc_entries(struct npc_mcam *mcam, u16 pcifunc,
2380 struct npc_mcam_alloc_entry_req *req,
2381 struct npc_mcam_alloc_entry_rsp *rsp)
2383 u16 entry_list[NPC_MAX_NONCONTIG_ENTRIES];
2384 u16 fcnt, hp_fcnt, lp_fcnt;
2385 u16 start, end, index;
2386 int entry, next_start;
2387 bool reverse = false;
2388 unsigned long *bmap;
2391 mutex_lock(&mcam->lock);
2393 /* Check if there are any free entries */
2394 if (!mcam->bmap_fcnt) {
2395 mutex_unlock(&mcam->lock);
2396 return NPC_MCAM_ALLOC_FAILED;
2399 /* MCAM entries are divided into high priority, middle and
2400 * low priority zones. Idea is to not allocate top and lower
2401 * most entries as much as possible, this is to increase
2402 * probability of honouring priority allocation requests.
2404 * Two bitmaps are used for mcam entry management,
2405 * mcam->bmap for forward search i.e '0 to mcam->bmap_entries'.
2406 * mcam->bmap_reverse for reverse search i.e 'mcam->bmap_entries to 0'.
2408 * Reverse bitmap is used to allocate entries
2409 * - when a higher priority entry is requested
2410 * - when available free entries are less.
2411 * Lower priority ones out of avaialble free entries are always
2412 * chosen when 'high vs low' question arises.
2415 /* Get the search range for priority allocation request */
2416 if (req->priority) {
2417 npc_get_mcam_search_range_priority(mcam, req,
2418 &start, &end, &reverse);
2422 /* For a VF base MCAM match rule is set by its PF. And all the
2423 * further MCAM rules installed by VF on its own are
2424 * concatenated with the base rule set by its PF. Hence PF entries
2425 * should be at lower priority compared to VF entries. Otherwise
2426 * base rule is hit always and rules installed by VF will be of
2427 * no use. Hence if the request is from PF and NOT a priority
2428 * allocation request then allocate low priority entries.
2430 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
2433 /* Find out the search range for non-priority allocation request
2435 * Get MCAM free entry count in middle zone.
2437 lp_fcnt = npc_mcam_get_free_count(mcam->bmap,
2439 mcam->bmap_entries);
2440 hp_fcnt = npc_mcam_get_free_count(mcam->bmap, 0, mcam->hprio_end);
2441 fcnt = mcam->bmap_fcnt - lp_fcnt - hp_fcnt;
2443 /* Check if request can be accomodated in the middle zone */
2444 if (fcnt > req->count) {
2445 start = mcam->hprio_end;
2446 end = mcam->lprio_start;
2447 } else if ((fcnt + (hp_fcnt / 2) + (lp_fcnt / 2)) > req->count) {
2448 /* Expand search zone from half of hprio zone to
2449 * half of lprio zone.
2451 start = mcam->hprio_end / 2;
2452 end = mcam->bmap_entries - (mcam->lprio_count / 2);
2455 /* Not enough free entries, search all entries in reverse,
2456 * so that low priority ones will get used up.
2461 end = mcam->bmap_entries;
2466 bmap = mcam->bmap_reverse;
2467 start = mcam->bmap_entries - start;
2468 end = mcam->bmap_entries - end;
2475 /* Allocate requested number of contiguous entries, if
2476 * unsuccessful find max contiguous entries available.
2478 index = npc_mcam_find_zero_area(bmap, end, start,
2479 req->count, &max_contig);
2480 rsp->count = max_contig;
2482 rsp->entry = mcam->bmap_entries - index - max_contig;
2486 /* Allocate requested number of non-contiguous entries,
2487 * if unsuccessful allocate as many as possible.
2491 for (entry = 0; entry < req->count; entry++) {
2492 index = find_next_zero_bit(bmap, end, next_start);
2496 next_start = start + (index - start) + 1;
2498 /* Save the entry's index */
2500 index = mcam->bmap_entries - index - 1;
2501 entry_list[entry] = index;
2506 /* If allocating requested no of entries is unsucessful,
2507 * expand the search range to full bitmap length and retry.
2509 if (!req->priority && (rsp->count < req->count) &&
2510 ((end - start) != mcam->bmap_entries)) {
2513 end = mcam->bmap_entries;
2517 /* For priority entry allocation requests, if allocation is
2518 * failed then expand search to max possible range and retry.
2520 if (req->priority && rsp->count < req->count) {
2521 if (req->priority == NPC_MCAM_LOWER_PRIO &&
2522 (start != (req->ref_entry + 1))) {
2523 start = req->ref_entry + 1;
2524 end = mcam->bmap_entries;
2527 } else if ((req->priority == NPC_MCAM_HIGHER_PRIO) &&
2528 ((end - start) != req->ref_entry)) {
2530 end = req->ref_entry;
2536 /* Copy MCAM entry indices into mbox response entry_list.
2537 * Requester always expects indices in ascending order, so
2538 * so reverse the list if reverse bitmap is used for allocation.
2540 if (!req->contig && rsp->count) {
2542 for (entry = rsp->count - 1; entry >= 0; entry--) {
2544 rsp->entry_list[index++] = entry_list[entry];
2546 rsp->entry_list[entry] = entry_list[entry];
2550 /* Mark the allocated entries as used and set nixlf mapping */
2551 for (entry = 0; entry < rsp->count; entry++) {
2552 index = req->contig ?
2553 (rsp->entry + entry) : rsp->entry_list[entry];
2554 npc_mcam_set_bit(mcam, index);
2555 mcam->entry2pfvf_map[index] = pcifunc;
2556 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
2559 /* Update available free count in mbox response */
2560 rsp->free_count = mcam->bmap_fcnt;
2562 mutex_unlock(&mcam->lock);
2566 int rvu_mbox_handler_npc_mcam_alloc_entry(struct rvu *rvu,
2567 struct npc_mcam_alloc_entry_req *req,
2568 struct npc_mcam_alloc_entry_rsp *rsp)
2570 struct npc_mcam *mcam = &rvu->hw->mcam;
2571 u16 pcifunc = req->hdr.pcifunc;
2574 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2576 return NPC_MCAM_INVALID_REQ;
2578 rsp->entry = NPC_MCAM_ENTRY_INVALID;
2579 rsp->free_count = 0;
2581 /* Check if ref_entry is within range */
2582 if (req->priority && req->ref_entry >= mcam->bmap_entries) {
2583 dev_err(rvu->dev, "%s: reference entry %d is out of range\n",
2584 __func__, req->ref_entry);
2585 return NPC_MCAM_INVALID_REQ;
2588 /* ref_entry can't be '0' if requested priority is high.
2589 * Can't be last entry if requested priority is low.
2591 if ((!req->ref_entry && req->priority == NPC_MCAM_HIGHER_PRIO) ||
2592 ((req->ref_entry == (mcam->bmap_entries - 1)) &&
2593 req->priority == NPC_MCAM_LOWER_PRIO))
2594 return NPC_MCAM_INVALID_REQ;
2596 /* Since list of allocated indices needs to be sent to requester,
2597 * max number of non-contiguous entries per mbox msg is limited.
2599 if (!req->contig && req->count > NPC_MAX_NONCONTIG_ENTRIES) {
2601 "%s: %d Non-contiguous MCAM entries requested is more than max (%d) allowed\n",
2602 __func__, req->count, NPC_MAX_NONCONTIG_ENTRIES);
2603 return NPC_MCAM_INVALID_REQ;
2606 /* Alloc request from PFFUNC with no NIXLF attached should be denied */
2607 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2608 return NPC_MCAM_ALLOC_DENIED;
2610 return npc_mcam_alloc_entries(mcam, pcifunc, req, rsp);
2613 int rvu_mbox_handler_npc_mcam_free_entry(struct rvu *rvu,
2614 struct npc_mcam_free_entry_req *req,
2615 struct msg_rsp *rsp)
2617 struct npc_mcam *mcam = &rvu->hw->mcam;
2618 u16 pcifunc = req->hdr.pcifunc;
2619 int blkaddr, rc = 0;
2622 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2624 return NPC_MCAM_INVALID_REQ;
2626 /* Free request from PFFUNC with no NIXLF attached, ignore */
2627 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2628 return NPC_MCAM_INVALID_REQ;
2630 mutex_lock(&mcam->lock);
2635 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2639 mcam->entry2pfvf_map[req->entry] = NPC_MCAM_INVALID_MAP;
2640 mcam->entry2target_pffunc[req->entry] = 0x0;
2641 npc_mcam_clear_bit(mcam, req->entry);
2642 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2644 /* Update entry2counter mapping */
2645 cntr = mcam->entry2cntr_map[req->entry];
2646 if (cntr != NPC_MCAM_INVALID_MAP)
2647 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2653 /* Free up all entries allocated to requesting PFFUNC */
2654 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
2656 mutex_unlock(&mcam->lock);
2660 int rvu_mbox_handler_npc_mcam_read_entry(struct rvu *rvu,
2661 struct npc_mcam_read_entry_req *req,
2662 struct npc_mcam_read_entry_rsp *rsp)
2664 struct npc_mcam *mcam = &rvu->hw->mcam;
2665 u16 pcifunc = req->hdr.pcifunc;
2668 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2670 return NPC_MCAM_INVALID_REQ;
2672 mutex_lock(&mcam->lock);
2673 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2675 npc_read_mcam_entry(rvu, mcam, blkaddr, req->entry,
2677 &rsp->intf, &rsp->enable);
2680 mutex_unlock(&mcam->lock);
2684 int rvu_mbox_handler_npc_mcam_write_entry(struct rvu *rvu,
2685 struct npc_mcam_write_entry_req *req,
2686 struct msg_rsp *rsp)
2688 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
2689 struct npc_mcam *mcam = &rvu->hw->mcam;
2690 u16 pcifunc = req->hdr.pcifunc;
2694 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2696 return NPC_MCAM_INVALID_REQ;
2698 mutex_lock(&mcam->lock);
2699 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2703 if (req->set_cntr &&
2704 npc_mcam_verify_counter(mcam, pcifunc, req->cntr)) {
2705 rc = NPC_MCAM_INVALID_REQ;
2709 if (!is_npc_interface_valid(rvu, req->intf)) {
2710 rc = NPC_MCAM_INVALID_REQ;
2714 if (is_npc_intf_tx(req->intf))
2715 nix_intf = pfvf->nix_tx_intf;
2717 nix_intf = pfvf->nix_rx_intf;
2719 if (!is_pffunc_af(pcifunc) &&
2720 npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf, pcifunc)) {
2721 rc = NPC_MCAM_INVALID_REQ;
2725 /* For AF installed rules, the nix_intf should be set to target NIX */
2726 if (is_pffunc_af(req->hdr.pcifunc))
2727 nix_intf = req->intf;
2729 npc_config_mcam_entry(rvu, mcam, blkaddr, req->entry, nix_intf,
2730 &req->entry_data, req->enable_entry);
2733 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2734 req->entry, req->cntr);
2738 mutex_unlock(&mcam->lock);
2742 int rvu_mbox_handler_npc_mcam_ena_entry(struct rvu *rvu,
2743 struct npc_mcam_ena_dis_entry_req *req,
2744 struct msg_rsp *rsp)
2746 struct npc_mcam *mcam = &rvu->hw->mcam;
2747 u16 pcifunc = req->hdr.pcifunc;
2750 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2752 return NPC_MCAM_INVALID_REQ;
2754 mutex_lock(&mcam->lock);
2755 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2756 mutex_unlock(&mcam->lock);
2760 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, true);
2765 int rvu_mbox_handler_npc_mcam_dis_entry(struct rvu *rvu,
2766 struct npc_mcam_ena_dis_entry_req *req,
2767 struct msg_rsp *rsp)
2769 struct npc_mcam *mcam = &rvu->hw->mcam;
2770 u16 pcifunc = req->hdr.pcifunc;
2773 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2775 return NPC_MCAM_INVALID_REQ;
2777 mutex_lock(&mcam->lock);
2778 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2779 mutex_unlock(&mcam->lock);
2783 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2788 int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,
2789 struct npc_mcam_shift_entry_req *req,
2790 struct npc_mcam_shift_entry_rsp *rsp)
2792 struct npc_mcam *mcam = &rvu->hw->mcam;
2793 u16 pcifunc = req->hdr.pcifunc;
2794 u16 old_entry, new_entry;
2795 int blkaddr, rc = 0;
2798 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2800 return NPC_MCAM_INVALID_REQ;
2802 if (req->shift_count > NPC_MCAM_MAX_SHIFTS)
2803 return NPC_MCAM_INVALID_REQ;
2805 mutex_lock(&mcam->lock);
2806 for (index = 0; index < req->shift_count; index++) {
2807 old_entry = req->curr_entry[index];
2808 new_entry = req->new_entry[index];
2810 /* Check if both old and new entries are valid and
2811 * does belong to this PFFUNC or not.
2813 rc = npc_mcam_verify_entry(mcam, pcifunc, old_entry);
2817 rc = npc_mcam_verify_entry(mcam, pcifunc, new_entry);
2821 /* new_entry should not have a counter mapped */
2822 if (mcam->entry2cntr_map[new_entry] != NPC_MCAM_INVALID_MAP) {
2823 rc = NPC_MCAM_PERM_DENIED;
2827 /* Disable the new_entry */
2828 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, false);
2830 /* Copy rule from old entry to new entry */
2831 npc_copy_mcam_entry(rvu, mcam, blkaddr, old_entry, new_entry);
2833 /* Copy counter mapping, if any */
2834 cntr = mcam->entry2cntr_map[old_entry];
2835 if (cntr != NPC_MCAM_INVALID_MAP) {
2836 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2838 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2842 /* Enable new_entry and disable old_entry */
2843 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, true);
2844 npc_enable_mcam_entry(rvu, mcam, blkaddr, old_entry, false);
2847 /* If shift has failed then report the failed index */
2848 if (index != req->shift_count) {
2849 rc = NPC_MCAM_PERM_DENIED;
2850 rsp->failed_entry_idx = index;
2853 mutex_unlock(&mcam->lock);
2857 int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
2858 struct npc_mcam_alloc_counter_req *req,
2859 struct npc_mcam_alloc_counter_rsp *rsp)
2861 struct npc_mcam *mcam = &rvu->hw->mcam;
2862 u16 pcifunc = req->hdr.pcifunc;
2863 u16 max_contig, cntr;
2866 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2868 return NPC_MCAM_INVALID_REQ;
2870 /* If the request is from a PFFUNC with no NIXLF attached, ignore */
2871 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2872 return NPC_MCAM_INVALID_REQ;
2874 /* Since list of allocated counter IDs needs to be sent to requester,
2875 * max number of non-contiguous counters per mbox msg is limited.
2877 if (!req->contig && req->count > NPC_MAX_NONCONTIG_COUNTERS)
2878 return NPC_MCAM_INVALID_REQ;
2880 mutex_lock(&mcam->lock);
2882 /* Check if unused counters are available or not */
2883 if (!rvu_rsrc_free_count(&mcam->counters)) {
2884 mutex_unlock(&mcam->lock);
2885 return NPC_MCAM_ALLOC_FAILED;
2891 /* Allocate requested number of contiguous counters, if
2892 * unsuccessful find max contiguous entries available.
2894 index = npc_mcam_find_zero_area(mcam->counters.bmap,
2895 mcam->counters.max, 0,
2896 req->count, &max_contig);
2897 rsp->count = max_contig;
2899 for (cntr = index; cntr < (index + max_contig); cntr++) {
2900 __set_bit(cntr, mcam->counters.bmap);
2901 mcam->cntr2pfvf_map[cntr] = pcifunc;
2904 /* Allocate requested number of non-contiguous counters,
2905 * if unsuccessful allocate as many as possible.
2907 for (cntr = 0; cntr < req->count; cntr++) {
2908 index = rvu_alloc_rsrc(&mcam->counters);
2911 rsp->cntr_list[cntr] = index;
2913 mcam->cntr2pfvf_map[index] = pcifunc;
2917 mutex_unlock(&mcam->lock);
2921 int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
2922 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
2924 struct npc_mcam *mcam = &rvu->hw->mcam;
2925 u16 index, entry = 0;
2928 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2930 return NPC_MCAM_INVALID_REQ;
2932 mutex_lock(&mcam->lock);
2933 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2935 mutex_unlock(&mcam->lock);
2939 /* Mark counter as free/unused */
2940 mcam->cntr2pfvf_map[req->cntr] = NPC_MCAM_INVALID_MAP;
2941 rvu_free_rsrc(&mcam->counters, req->cntr);
2943 /* Disable all MCAM entry's stats which are using this counter */
2944 while (entry < mcam->bmap_entries) {
2945 if (!mcam->cntr_refcnt[req->cntr])
2948 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2949 if (index >= mcam->bmap_entries)
2952 if (mcam->entry2cntr_map[index] != req->cntr)
2955 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2959 mutex_unlock(&mcam->lock);
2963 int rvu_mbox_handler_npc_mcam_unmap_counter(struct rvu *rvu,
2964 struct npc_mcam_unmap_counter_req *req, struct msg_rsp *rsp)
2966 struct npc_mcam *mcam = &rvu->hw->mcam;
2967 u16 index, entry = 0;
2970 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2972 return NPC_MCAM_INVALID_REQ;
2974 mutex_lock(&mcam->lock);
2975 rc = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2979 /* Unmap the MCAM entry and counter */
2981 rc = npc_mcam_verify_entry(mcam, req->hdr.pcifunc, req->entry);
2984 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2985 req->entry, req->cntr);
2989 /* Disable all MCAM entry's stats which are using this counter */
2990 while (entry < mcam->bmap_entries) {
2991 if (!mcam->cntr_refcnt[req->cntr])
2994 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2995 if (index >= mcam->bmap_entries)
2999 if (mcam->entry2cntr_map[index] != req->cntr)
3002 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
3006 mutex_unlock(&mcam->lock);
3010 int rvu_mbox_handler_npc_mcam_clear_counter(struct rvu *rvu,
3011 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
3013 struct npc_mcam *mcam = &rvu->hw->mcam;
3016 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3018 return NPC_MCAM_INVALID_REQ;
3020 mutex_lock(&mcam->lock);
3021 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3022 mutex_unlock(&mcam->lock);
3026 rvu_write64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr), 0x00);
3031 int rvu_mbox_handler_npc_mcam_counter_stats(struct rvu *rvu,
3032 struct npc_mcam_oper_counter_req *req,
3033 struct npc_mcam_oper_counter_rsp *rsp)
3035 struct npc_mcam *mcam = &rvu->hw->mcam;
3038 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3040 return NPC_MCAM_INVALID_REQ;
3042 mutex_lock(&mcam->lock);
3043 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3044 mutex_unlock(&mcam->lock);
3048 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr));
3049 rsp->stat &= BIT_ULL(48) - 1;
3054 int rvu_mbox_handler_npc_mcam_alloc_and_write_entry(struct rvu *rvu,
3055 struct npc_mcam_alloc_and_write_entry_req *req,
3056 struct npc_mcam_alloc_and_write_entry_rsp *rsp)
3058 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
3059 struct npc_mcam_alloc_counter_req cntr_req;
3060 struct npc_mcam_alloc_counter_rsp cntr_rsp;
3061 struct npc_mcam_alloc_entry_req entry_req;
3062 struct npc_mcam_alloc_entry_rsp entry_rsp;
3063 struct npc_mcam *mcam = &rvu->hw->mcam;
3064 u16 entry = NPC_MCAM_ENTRY_INVALID;
3065 u16 cntr = NPC_MCAM_ENTRY_INVALID;
3069 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3071 return NPC_MCAM_INVALID_REQ;
3073 if (!is_npc_interface_valid(rvu, req->intf))
3074 return NPC_MCAM_INVALID_REQ;
3076 if (npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf,
3078 return NPC_MCAM_INVALID_REQ;
3080 /* Try to allocate a MCAM entry */
3081 entry_req.hdr.pcifunc = req->hdr.pcifunc;
3082 entry_req.contig = true;
3083 entry_req.priority = req->priority;
3084 entry_req.ref_entry = req->ref_entry;
3085 entry_req.count = 1;
3087 rc = rvu_mbox_handler_npc_mcam_alloc_entry(rvu,
3088 &entry_req, &entry_rsp);
3092 if (!entry_rsp.count)
3093 return NPC_MCAM_ALLOC_FAILED;
3095 entry = entry_rsp.entry;
3097 if (!req->alloc_cntr)
3100 /* Now allocate counter */
3101 cntr_req.hdr.pcifunc = req->hdr.pcifunc;
3102 cntr_req.contig = true;
3105 rc = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
3107 /* Free allocated MCAM entry */
3108 mutex_lock(&mcam->lock);
3109 mcam->entry2pfvf_map[entry] = NPC_MCAM_INVALID_MAP;
3110 npc_mcam_clear_bit(mcam, entry);
3111 mutex_unlock(&mcam->lock);
3115 cntr = cntr_rsp.cntr;
3118 mutex_lock(&mcam->lock);
3120 if (is_npc_intf_tx(req->intf))
3121 nix_intf = pfvf->nix_tx_intf;
3123 nix_intf = pfvf->nix_rx_intf;
3125 npc_config_mcam_entry(rvu, mcam, blkaddr, entry, nix_intf,
3126 &req->entry_data, req->enable_entry);
3128 if (req->alloc_cntr)
3129 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr, entry, cntr);
3130 mutex_unlock(&mcam->lock);
3138 #define GET_KEX_CFG(intf) \
3139 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_INTFX_KEX_CFG(intf))
3141 #define GET_KEX_FLAGS(ld) \
3142 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld))
3144 #define GET_KEX_LD(intf, lid, lt, ld) \
3145 rvu_read64(rvu, BLKADDR_NPC, \
3146 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, lt, ld))
3148 #define GET_KEX_LDFLAGS(intf, ld, fl) \
3149 rvu_read64(rvu, BLKADDR_NPC, \
3150 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, fl))
3152 int rvu_mbox_handler_npc_get_kex_cfg(struct rvu *rvu, struct msg_req *req,
3153 struct npc_get_kex_cfg_rsp *rsp)
3155 int lid, lt, ld, fl;
3157 rsp->rx_keyx_cfg = GET_KEX_CFG(NIX_INTF_RX);
3158 rsp->tx_keyx_cfg = GET_KEX_CFG(NIX_INTF_TX);
3159 for (lid = 0; lid < NPC_MAX_LID; lid++) {
3160 for (lt = 0; lt < NPC_MAX_LT; lt++) {
3161 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3162 rsp->intf_lid_lt_ld[NIX_INTF_RX][lid][lt][ld] =
3163 GET_KEX_LD(NIX_INTF_RX, lid, lt, ld);
3164 rsp->intf_lid_lt_ld[NIX_INTF_TX][lid][lt][ld] =
3165 GET_KEX_LD(NIX_INTF_TX, lid, lt, ld);
3169 for (ld = 0; ld < NPC_MAX_LD; ld++)
3170 rsp->kex_ld_flags[ld] = GET_KEX_FLAGS(ld);
3172 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3173 for (fl = 0; fl < NPC_MAX_LFL; fl++) {
3174 rsp->intf_ld_flags[NIX_INTF_RX][ld][fl] =
3175 GET_KEX_LDFLAGS(NIX_INTF_RX, ld, fl);
3176 rsp->intf_ld_flags[NIX_INTF_TX][ld][fl] =
3177 GET_KEX_LDFLAGS(NIX_INTF_TX, ld, fl);
3180 memcpy(rsp->mkex_pfl_name, rvu->mkex_pfl_name, MKEX_NAME_LEN);
3185 npc_set_var_len_offset_pkind(struct rvu *rvu, u16 pcifunc, u64 pkind,
3186 u8 var_len_off, u8 var_len_off_mask, u8 shift_dir)
3188 struct npc_kpu_action0 *act0;
3193 if (!var_len_off_mask)
3196 if (var_len_off_mask != 0xff) {
3198 shift_count = __ffs(var_len_off_mask);
3200 shift_count = (8 - __fls(var_len_off_mask));
3202 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, pcifunc);
3204 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
3207 val = rvu_read64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind));
3208 act0 = (struct npc_kpu_action0 *)&val;
3209 act0->var_len_shift = shift_count;
3210 act0->var_len_right = shift_dir;
3211 act0->var_len_mask = var_len_off_mask;
3212 act0->var_len_offset = var_len_off;
3213 rvu_write64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind), val);
3217 int rvu_npc_set_parse_mode(struct rvu *rvu, u16 pcifunc, u64 mode, u8 dir,
3218 u64 pkind, u8 var_len_off, u8 var_len_off_mask,
3222 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
3223 int blkaddr, nixlf, rc, intf_mode;
3224 int pf = rvu_get_pf(pcifunc);
3225 u64 rxpkind, txpkind;
3228 /* use default pkind to disable edsa/higig */
3229 rxpkind = rvu_npc_get_pkind(rvu, pf);
3230 txpkind = NPC_TX_DEF_PKIND;
3231 intf_mode = NPC_INTF_MODE_DEF;
3233 if (mode & OTX2_PRIV_FLAGS_CUSTOM) {
3234 if (pkind == NPC_RX_CUSTOM_PRE_L2_PKIND) {
3235 rc = npc_set_var_len_offset_pkind(rvu, pcifunc, pkind,
3246 if (dir & PKIND_RX) {
3247 /* rx pkind set req valid only for cgx mapped PFs */
3248 if (!is_cgx_config_permitted(rvu, pcifunc))
3250 rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
3252 rc = cgx_set_pkind(rvu_cgx_pdata(cgx_id, rvu), lmac_id,
3258 if (dir & PKIND_TX) {
3259 /* Tx pkind set request valid if PCIFUNC has NIXLF attached */
3260 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, &blkaddr);
3264 rvu_write64(rvu, blkaddr, NIX_AF_LFX_TX_PARSE_CFG(nixlf),
3268 pfvf->intf_mode = intf_mode;
3272 int rvu_mbox_handler_npc_set_pkind(struct rvu *rvu, struct npc_set_pkind *req,
3273 struct msg_rsp *rsp)
3275 return rvu_npc_set_parse_mode(rvu, req->hdr.pcifunc, req->mode,
3276 req->dir, req->pkind, req->var_len_off,
3277 req->var_len_off_mask, req->shift_dir);
3280 int rvu_mbox_handler_npc_read_base_steer_rule(struct rvu *rvu,
3281 struct msg_req *req,
3282 struct npc_mcam_read_base_rule_rsp *rsp)
3284 struct npc_mcam *mcam = &rvu->hw->mcam;
3285 int index, blkaddr, nixlf, rc = 0;
3286 u16 pcifunc = req->hdr.pcifunc;
3287 struct rvu_pfvf *pfvf;
3290 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3292 return NPC_MCAM_INVALID_REQ;
3294 /* Return the channel number in case of PF */
3295 if (!(pcifunc & RVU_PFVF_FUNC_MASK)) {
3296 pfvf = rvu_get_pfvf(rvu, pcifunc);
3297 rsp->entry.kw[0] = pfvf->rx_chan_base;
3298 rsp->entry.kw_mask[0] = 0xFFFULL;
3302 /* Find the pkt steering rule installed by PF to this VF */
3303 mutex_lock(&mcam->lock);
3304 for (index = 0; index < mcam->bmap_entries; index++) {
3305 if (mcam->entry2target_pffunc[index] == pcifunc)
3309 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, NULL);
3311 mutex_unlock(&mcam->lock);
3314 /* Read the default ucast entry if there is no pkt steering rule */
3315 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
3318 /* Read the mcam entry */
3319 npc_read_mcam_entry(rvu, mcam, blkaddr, index, &rsp->entry, &intf,
3321 mutex_unlock(&mcam->lock);
3326 int rvu_mbox_handler_npc_mcam_entry_stats(struct rvu *rvu,
3327 struct npc_mcam_get_stats_req *req,
3328 struct npc_mcam_get_stats_rsp *rsp)
3330 struct npc_mcam *mcam = &rvu->hw->mcam;
3336 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3338 return NPC_MCAM_INVALID_REQ;
3340 mutex_lock(&mcam->lock);
3342 index = req->entry & (mcam->banksize - 1);
3343 bank = npc_get_bank(mcam, req->entry);
3345 /* read MCAM entry STAT_ACT register */
3346 regval = rvu_read64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank));
3348 if (!(regval & rvu->hw->npc_stat_ena)) {
3350 mutex_unlock(&mcam->lock);
3354 cntr = regval & 0x1FF;
3357 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(cntr));
3358 rsp->stat &= BIT_ULL(48) - 1;
3360 mutex_unlock(&mcam->lock);