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 = { 0 };
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 action.op = NIX_RX_ACTIONOP_UCAST;
630 action.pf_func = pcifunc;
633 req.default_rule = 1;
634 ether_addr_copy(req.packet.dmac, mac_addr);
635 eth_broadcast_addr((u8 *)&req.mask.dmac);
636 req.features = BIT_ULL(NPC_DMAC);
638 req.chan_mask = 0xFFFU;
639 req.intf = pfvf->nix_rx_intf;
641 req.hdr.pcifunc = 0; /* AF is requester */
642 req.vf = action.pf_func;
643 req.index = action.index;
644 req.match_id = action.match_id;
645 req.flow_key_alg = action.flow_key_alg;
647 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
650 void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
651 int nixlf, u64 chan, u8 chan_cnt)
653 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
654 struct npc_install_flow_req req = { 0 };
655 struct npc_install_flow_rsp rsp = { 0 };
656 struct npc_mcam *mcam = &rvu->hw->mcam;
657 struct rvu_hwinfo *hw = rvu->hw;
658 int blkaddr, ucast_idx, index;
659 struct nix_rx_action action = { 0 };
662 if (!hw->cap.nix_rx_multicast && is_cgx_vf(rvu, pcifunc))
665 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
669 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
670 nixlf, NIXLF_PROMISC_ENTRY);
672 if (is_cgx_vf(rvu, pcifunc))
673 index = npc_get_nixlf_mcam_index(mcam,
674 pcifunc & ~RVU_PFVF_FUNC_MASK,
675 nixlf, NIXLF_PROMISC_ENTRY);
677 /* If the corresponding PF's ucast action is RSS,
678 * use the same action for promisc also
680 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
681 nixlf, NIXLF_UCAST_ENTRY);
682 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
683 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
686 if (action.op != NIX_RX_ACTIONOP_RSS) {
688 action.op = NIX_RX_ACTIONOP_UCAST;
691 /* RX_ACTION set to MCAST for CGX PF's */
692 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list &&
693 is_pf_cgxmapped(rvu, rvu_get_pf(pcifunc))) {
695 action.op = NIX_RX_ACTIONOP_MCAST;
696 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
697 action.index = pfvf->promisc_mce_idx;
700 /* For cn10k the upper two bits of the channel number are
701 * cpt channel number. with masking out these bits in the
702 * mcam entry, same entry used for NIX will allow packets
703 * received from cpt for parsing.
705 if (!is_rvu_otx2(rvu)) {
706 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
708 req.chan_mask = 0xFFFU;
712 if (!is_power_of_2(chan_cnt)) {
714 "%s: channel count more than 1, must be power of 2\n", __func__);
717 relaxed_mask = GENMASK_ULL(BITS_PER_LONG_LONG - 1,
719 req.chan_mask &= relaxed_mask;
723 req.intf = pfvf->nix_rx_intf;
726 req.hdr.pcifunc = 0; /* AF is requester */
728 req.index = action.index;
729 req.match_id = action.match_id;
730 req.flow_key_alg = action.flow_key_alg;
732 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
735 void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc,
736 int nixlf, bool enable)
738 struct npc_mcam *mcam = &rvu->hw->mcam;
741 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
745 /* Get 'pcifunc' of PF device */
746 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
748 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
749 nixlf, NIXLF_PROMISC_ENTRY);
750 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
753 void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
756 struct rvu_pfvf *pfvf;
757 struct npc_install_flow_req req = { 0 };
758 struct npc_install_flow_rsp rsp = { 0 };
759 struct npc_mcam *mcam = &rvu->hw->mcam;
760 struct rvu_hwinfo *hw = rvu->hw;
763 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
768 if (is_afvf(pcifunc))
771 /* If pkt replication is not supported,
772 * then only PF is allowed to add a bcast match entry.
774 if (!hw->cap.nix_rx_multicast && is_vf(pcifunc))
777 /* Get 'pcifunc' of PF device */
778 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
779 pfvf = rvu_get_pfvf(rvu, pcifunc);
780 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
781 nixlf, NIXLF_BCAST_ENTRY);
783 if (!hw->cap.nix_rx_multicast) {
784 /* Early silicon doesn't support pkt replication,
785 * so install entry with UCAST action, so that PF
786 * receives all broadcast packets.
788 req.op = NIX_RX_ACTIONOP_UCAST;
790 req.op = NIX_RX_ACTIONOP_MCAST;
791 req.index = pfvf->bcast_mce_idx;
794 eth_broadcast_addr((u8 *)&req.packet.dmac);
795 eth_broadcast_addr((u8 *)&req.mask.dmac);
796 req.features = BIT_ULL(NPC_DMAC);
798 req.chan_mask = 0xFFFU;
799 req.intf = pfvf->nix_rx_intf;
801 req.hdr.pcifunc = 0; /* AF is requester */
804 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
807 void rvu_npc_enable_bcast_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
810 struct npc_mcam *mcam = &rvu->hw->mcam;
813 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
817 /* Get 'pcifunc' of PF device */
818 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
820 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
822 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
825 void rvu_npc_install_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
828 struct npc_install_flow_req req = { 0 };
829 struct npc_install_flow_rsp rsp = { 0 };
830 struct npc_mcam *mcam = &rvu->hw->mcam;
831 struct rvu_hwinfo *hw = rvu->hw;
832 int blkaddr, ucast_idx, index;
833 u8 mac_addr[ETH_ALEN] = { 0 };
834 struct nix_rx_action action = { 0 };
835 struct rvu_pfvf *pfvf;
838 /* Only CGX PF/VF can add allmulticast entry */
839 if (is_afvf(pcifunc) && is_sdp_vf(pcifunc))
842 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
846 /* Get 'pcifunc' of PF device */
847 vf_func = pcifunc & RVU_PFVF_FUNC_MASK;
848 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
849 pfvf = rvu_get_pfvf(rvu, pcifunc);
850 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
851 nixlf, NIXLF_ALLMULTI_ENTRY);
853 /* If the corresponding PF's ucast action is RSS,
854 * use the same action for multicast entry also
856 ucast_idx = npc_get_nixlf_mcam_index(mcam, pcifunc,
857 nixlf, NIXLF_UCAST_ENTRY);
858 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, ucast_idx))
859 *(u64 *)&action = npc_get_mcam_action(rvu, mcam,
862 if (action.op != NIX_RX_ACTIONOP_RSS) {
864 action.op = NIX_RX_ACTIONOP_UCAST;
865 action.pf_func = pcifunc;
868 /* RX_ACTION set to MCAST for CGX PF's */
869 if (hw->cap.nix_rx_multicast && pfvf->use_mce_list) {
871 action.op = NIX_RX_ACTIONOP_MCAST;
872 action.index = pfvf->mcast_mce_idx;
875 mac_addr[0] = 0x01; /* LSB bit of 1st byte in DMAC */
876 ether_addr_copy(req.packet.dmac, mac_addr);
877 ether_addr_copy(req.mask.dmac, mac_addr);
878 req.features = BIT_ULL(NPC_DMAC);
880 /* For cn10k the upper two bits of the channel number are
881 * cpt channel number. with masking out these bits in the
882 * mcam entry, same entry used for NIX will allow packets
883 * received from cpt for parsing.
885 if (!is_rvu_otx2(rvu))
886 req.chan_mask = NIX_CHAN_CPT_X2P_MASK;
888 req.chan_mask = 0xFFFU;
891 req.intf = pfvf->nix_rx_intf;
894 req.hdr.pcifunc = 0; /* AF is requester */
895 req.vf = pcifunc | vf_func;
896 req.index = action.index;
897 req.match_id = action.match_id;
898 req.flow_key_alg = action.flow_key_alg;
900 rvu_mbox_handler_npc_install_flow(rvu, &req, &rsp);
903 void rvu_npc_enable_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
906 struct npc_mcam *mcam = &rvu->hw->mcam;
909 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
913 /* Get 'pcifunc' of PF device */
914 pcifunc = pcifunc & ~RVU_PFVF_FUNC_MASK;
916 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
917 NIXLF_ALLMULTI_ENTRY);
918 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
921 static void npc_update_vf_flow_entry(struct rvu *rvu, struct npc_mcam *mcam,
922 int blkaddr, u16 pcifunc, u64 rx_action)
924 int actindex, index, bank, entry;
925 struct rvu_npc_mcam_rule *rule;
928 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
931 mutex_lock(&mcam->lock);
932 for (index = 0; index < mcam->bmap_entries; index++) {
933 if (mcam->entry2target_pffunc[index] == pcifunc) {
935 /* update not needed for the rules added via ntuple filters */
936 list_for_each_entry(rule, &mcam->mcam_rules, list) {
937 if (rule->entry == index)
942 bank = npc_get_bank(mcam, index);
944 entry = index & (mcam->banksize - 1);
946 /* read vf flow entry enable status */
947 enable = is_mcam_entry_enabled(rvu, mcam, blkaddr,
949 /* disable before mcam entry update */
950 npc_enable_mcam_entry(rvu, mcam, blkaddr, actindex,
952 /* update 'action' */
953 rvu_write64(rvu, blkaddr,
954 NPC_AF_MCAMEX_BANKX_ACTION(entry, bank),
957 npc_enable_mcam_entry(rvu, mcam, blkaddr,
961 mutex_unlock(&mcam->lock);
964 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
965 int group, int alg_idx, int mcam_index)
967 struct npc_mcam *mcam = &rvu->hw->mcam;
968 struct rvu_hwinfo *hw = rvu->hw;
969 struct nix_rx_action action;
970 int blkaddr, index, bank;
971 struct rvu_pfvf *pfvf;
973 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
977 /* Check if this is for reserved default entry */
978 if (mcam_index < 0) {
979 if (group != DEFAULT_RSS_CONTEXT_GROUP)
981 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
982 nixlf, NIXLF_UCAST_ENTRY);
984 /* TODO: validate this mcam index */
988 if (index >= mcam->total_entries)
991 bank = npc_get_bank(mcam, index);
992 index &= (mcam->banksize - 1);
994 *(u64 *)&action = rvu_read64(rvu, blkaddr,
995 NPC_AF_MCAMEX_BANKX_ACTION(index, bank));
996 /* Ignore if no action was set earlier */
997 if (!*(u64 *)&action)
1000 action.op = NIX_RX_ACTIONOP_RSS;
1001 action.pf_func = pcifunc;
1002 action.index = group;
1003 action.flow_key_alg = alg_idx;
1005 rvu_write64(rvu, blkaddr,
1006 NPC_AF_MCAMEX_BANKX_ACTION(index, bank), *(u64 *)&action);
1008 /* update the VF flow rule action with the VF default entry action */
1010 npc_update_vf_flow_entry(rvu, mcam, blkaddr, pcifunc,
1013 /* update the action change in default rule */
1014 pfvf = rvu_get_pfvf(rvu, pcifunc);
1015 if (pfvf->def_ucast_rule)
1016 pfvf->def_ucast_rule->rx_action = action;
1018 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1019 nixlf, NIXLF_PROMISC_ENTRY);
1021 /* If PF's promiscuous entry is enabled,
1022 * Set RSS action for that entry as well
1024 if ((!hw->cap.nix_rx_multicast || !pfvf->use_mce_list) &&
1025 is_mcam_entry_enabled(rvu, mcam, blkaddr, index)) {
1026 bank = npc_get_bank(mcam, index);
1027 index &= (mcam->banksize - 1);
1029 rvu_write64(rvu, blkaddr,
1030 NPC_AF_MCAMEX_BANKX_ACTION(index, bank),
1035 void npc_enadis_default_mce_entry(struct rvu *rvu, u16 pcifunc,
1036 int nixlf, int type, bool enable)
1038 struct npc_mcam *mcam = &rvu->hw->mcam;
1039 struct rvu_hwinfo *hw = rvu->hw;
1040 struct nix_mce_list *mce_list;
1041 int index, blkaddr, mce_idx;
1042 struct rvu_pfvf *pfvf;
1044 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1048 index = npc_get_nixlf_mcam_index(mcam, pcifunc & ~RVU_PFVF_FUNC_MASK,
1051 /* disable MCAM entry when packet replication is not supported by hw */
1052 if (!hw->cap.nix_rx_multicast && !is_vf(pcifunc)) {
1053 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1057 /* return incase mce list is not enabled */
1058 pfvf = rvu_get_pfvf(rvu, pcifunc & ~RVU_PFVF_FUNC_MASK);
1059 if (hw->cap.nix_rx_multicast && is_vf(pcifunc) &&
1060 type != NIXLF_BCAST_ENTRY && !pfvf->use_mce_list)
1063 nix_get_mce_list(rvu, pcifunc, type, &mce_list, &mce_idx);
1065 nix_update_mce_list(rvu, pcifunc, mce_list,
1066 mce_idx, index, enable);
1068 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1071 static void npc_enadis_default_entries(struct rvu *rvu, u16 pcifunc,
1072 int nixlf, bool enable)
1074 struct npc_mcam *mcam = &rvu->hw->mcam;
1077 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1081 /* Ucast MCAM match entry of this PF/VF */
1082 index = npc_get_nixlf_mcam_index(mcam, pcifunc,
1083 nixlf, NIXLF_UCAST_ENTRY);
1084 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, enable);
1086 /* Nothing to do for VFs, on platforms where pkt replication
1089 if ((pcifunc & RVU_PFVF_FUNC_MASK) && !rvu->hw->cap.nix_rx_multicast)
1092 /* add/delete pf_func to broadcast MCE list */
1093 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1094 NIXLF_BCAST_ENTRY, enable);
1097 void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1099 npc_enadis_default_entries(rvu, pcifunc, nixlf, false);
1101 /* Delete multicast and promisc MCAM entries */
1102 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1103 NIXLF_ALLMULTI_ENTRY, false);
1104 npc_enadis_default_mce_entry(rvu, pcifunc, nixlf,
1105 NIXLF_PROMISC_ENTRY, false);
1108 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1110 /* Enables only broadcast match entry. Promisc/Allmulti are enabled
1111 * in set_rx_mode mbox handler.
1113 npc_enadis_default_entries(rvu, pcifunc, nixlf, true);
1116 void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1118 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
1119 struct npc_mcam *mcam = &rvu->hw->mcam;
1120 struct rvu_npc_mcam_rule *rule, *tmp;
1123 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1127 mutex_lock(&mcam->lock);
1129 /* Disable MCAM entries directing traffic to this 'pcifunc' */
1130 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1131 if (is_npc_intf_rx(rule->intf) &&
1132 rule->rx_action.pf_func == pcifunc &&
1133 rule->rx_action.op != NIX_RX_ACTIONOP_MCAST) {
1134 npc_enable_mcam_entry(rvu, mcam, blkaddr,
1135 rule->entry, false);
1136 rule->enable = false;
1137 /* Indicate that default rule is disabled */
1138 if (rule->default_rule) {
1139 pfvf->def_ucast_rule = NULL;
1140 list_del(&rule->list);
1146 mutex_unlock(&mcam->lock);
1148 npc_mcam_disable_flows(rvu, pcifunc);
1150 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1153 void rvu_npc_free_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
1155 struct npc_mcam *mcam = &rvu->hw->mcam;
1156 struct rvu_npc_mcam_rule *rule, *tmp;
1159 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1163 mutex_lock(&mcam->lock);
1165 /* Free all MCAM entries owned by this 'pcifunc' */
1166 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
1168 /* Free all MCAM counters owned by this 'pcifunc' */
1169 npc_mcam_free_all_counters(rvu, mcam, pcifunc);
1171 /* Delete MCAM entries owned by this 'pcifunc' */
1172 list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1173 if (rule->owner == pcifunc && !rule->default_rule) {
1174 list_del(&rule->list);
1179 mutex_unlock(&mcam->lock);
1181 rvu_npc_disable_default_entries(rvu, pcifunc, nixlf);
1184 #define SET_KEX_LD(intf, lid, ltype, ld, cfg) \
1185 rvu_write64(rvu, blkaddr, \
1186 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, ltype, ld), cfg)
1188 #define SET_KEX_LDFLAGS(intf, ld, flags, cfg) \
1189 rvu_write64(rvu, blkaddr, \
1190 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, flags), cfg)
1192 static void npc_program_mkex_rx(struct rvu *rvu, int blkaddr,
1193 struct npc_mcam_kex *mkex, u8 intf)
1195 int lid, lt, ld, fl;
1197 if (is_npc_intf_tx(intf))
1200 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1201 mkex->keyx_cfg[NIX_INTF_RX]);
1204 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1205 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1206 for (ld = 0; ld < NPC_MAX_LD; ld++)
1207 SET_KEX_LD(intf, lid, lt, ld,
1208 mkex->intf_lid_lt_ld[NIX_INTF_RX]
1212 /* Program LFLAGS */
1213 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1214 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1215 SET_KEX_LDFLAGS(intf, ld, fl,
1216 mkex->intf_ld_flags[NIX_INTF_RX]
1221 static void npc_program_mkex_tx(struct rvu *rvu, int blkaddr,
1222 struct npc_mcam_kex *mkex, u8 intf)
1224 int lid, lt, ld, fl;
1226 if (is_npc_intf_rx(intf))
1229 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1230 mkex->keyx_cfg[NIX_INTF_TX]);
1233 for (lid = 0; lid < NPC_MAX_LID; lid++) {
1234 for (lt = 0; lt < NPC_MAX_LT; lt++) {
1235 for (ld = 0; ld < NPC_MAX_LD; ld++)
1236 SET_KEX_LD(intf, lid, lt, ld,
1237 mkex->intf_lid_lt_ld[NIX_INTF_TX]
1241 /* Program LFLAGS */
1242 for (ld = 0; ld < NPC_MAX_LD; ld++) {
1243 for (fl = 0; fl < NPC_MAX_LFL; fl++)
1244 SET_KEX_LDFLAGS(intf, ld, fl,
1245 mkex->intf_ld_flags[NIX_INTF_TX]
1250 static void npc_program_mkex_profile(struct rvu *rvu, int blkaddr,
1251 struct npc_mcam_kex *mkex)
1253 struct rvu_hwinfo *hw = rvu->hw;
1257 for (ld = 0; ld < NPC_MAX_LD; ld++)
1258 rvu_write64(rvu, blkaddr, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld),
1259 mkex->kex_ld_flags[ld]);
1261 for (intf = 0; intf < hw->npc_intfs; intf++) {
1262 npc_program_mkex_rx(rvu, blkaddr, mkex, intf);
1263 npc_program_mkex_tx(rvu, blkaddr, mkex, intf);
1267 static int npc_fwdb_prfl_img_map(struct rvu *rvu, void __iomem **prfl_img_addr,
1270 u64 prfl_addr, prfl_sz;
1275 prfl_addr = rvu->fwdata->mcam_addr;
1276 prfl_sz = rvu->fwdata->mcam_sz;
1278 if (!prfl_addr || !prfl_sz)
1281 *prfl_img_addr = ioremap_wc(prfl_addr, prfl_sz);
1282 if (!(*prfl_img_addr))
1290 /* strtoull of "mkexprof" with base:36 */
1291 #define MKEX_END_SIGN 0xdeadbeef
1293 static void npc_load_mkex_profile(struct rvu *rvu, int blkaddr,
1294 const char *mkex_profile)
1296 struct device *dev = &rvu->pdev->dev;
1297 struct npc_mcam_kex *mcam_kex;
1298 void __iomem *mkex_prfl_addr = NULL;
1302 /* If user not selected mkex profile */
1303 if (rvu->kpu_fwdata_sz ||
1304 !strncmp(mkex_profile, def_pfl_name, MKEX_NAME_LEN))
1307 /* Setting up the mapping for mkex profile image */
1308 ret = npc_fwdb_prfl_img_map(rvu, &mkex_prfl_addr, &prfl_sz);
1312 mcam_kex = (struct npc_mcam_kex __force *)mkex_prfl_addr;
1314 while (((s64)prfl_sz > 0) && (mcam_kex->mkex_sign != MKEX_END_SIGN)) {
1315 /* Compare with mkex mod_param name string */
1316 if (mcam_kex->mkex_sign == MKEX_SIGN &&
1317 !strncmp(mcam_kex->name, mkex_profile, MKEX_NAME_LEN)) {
1318 /* Due to an errata (35786) in A0/B0 pass silicon,
1319 * parse nibble enable configuration has to be
1320 * identical for both Rx and Tx interfaces.
1322 if (!is_rvu_96xx_B0(rvu) ||
1323 mcam_kex->keyx_cfg[NIX_INTF_RX] == mcam_kex->keyx_cfg[NIX_INTF_TX])
1324 rvu->kpu.mkex = mcam_kex;
1329 prfl_sz -= sizeof(struct npc_mcam_kex);
1331 dev_warn(dev, "Failed to load requested profile: %s\n", mkex_profile);
1334 dev_info(rvu->dev, "Using %s mkex profile\n", rvu->kpu.mkex->name);
1335 /* Program selected mkex profile */
1336 npc_program_mkex_profile(rvu, blkaddr, rvu->kpu.mkex);
1338 iounmap(mkex_prfl_addr);
1341 static void npc_config_kpuaction(struct rvu *rvu, int blkaddr,
1342 const struct npc_kpu_profile_action *kpuaction,
1343 int kpu, int entry, bool pkind)
1345 struct npc_kpu_action0 action0 = {0};
1346 struct npc_kpu_action1 action1 = {0};
1349 action1.errlev = kpuaction->errlev;
1350 action1.errcode = kpuaction->errcode;
1351 action1.dp0_offset = kpuaction->dp0_offset;
1352 action1.dp1_offset = kpuaction->dp1_offset;
1353 action1.dp2_offset = kpuaction->dp2_offset;
1356 reg = NPC_AF_PKINDX_ACTION1(entry);
1358 reg = NPC_AF_KPUX_ENTRYX_ACTION1(kpu, entry);
1360 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action1);
1362 action0.byp_count = kpuaction->bypass_count;
1363 action0.capture_ena = kpuaction->cap_ena;
1364 action0.parse_done = kpuaction->parse_done;
1365 action0.next_state = kpuaction->next_state;
1366 action0.capture_lid = kpuaction->lid;
1367 action0.capture_ltype = kpuaction->ltype;
1368 action0.capture_flags = kpuaction->flags;
1369 action0.ptr_advance = kpuaction->ptr_advance;
1370 action0.var_len_offset = kpuaction->offset;
1371 action0.var_len_mask = kpuaction->mask;
1372 action0.var_len_right = kpuaction->right;
1373 action0.var_len_shift = kpuaction->shift;
1376 reg = NPC_AF_PKINDX_ACTION0(entry);
1378 reg = NPC_AF_KPUX_ENTRYX_ACTION0(kpu, entry);
1380 rvu_write64(rvu, blkaddr, reg, *(u64 *)&action0);
1383 static void npc_config_kpucam(struct rvu *rvu, int blkaddr,
1384 const struct npc_kpu_profile_cam *kpucam,
1387 struct npc_kpu_cam cam0 = {0};
1388 struct npc_kpu_cam cam1 = {0};
1390 cam1.state = kpucam->state & kpucam->state_mask;
1391 cam1.dp0_data = kpucam->dp0 & kpucam->dp0_mask;
1392 cam1.dp1_data = kpucam->dp1 & kpucam->dp1_mask;
1393 cam1.dp2_data = kpucam->dp2 & kpucam->dp2_mask;
1395 cam0.state = ~kpucam->state & kpucam->state_mask;
1396 cam0.dp0_data = ~kpucam->dp0 & kpucam->dp0_mask;
1397 cam0.dp1_data = ~kpucam->dp1 & kpucam->dp1_mask;
1398 cam0.dp2_data = ~kpucam->dp2 & kpucam->dp2_mask;
1400 rvu_write64(rvu, blkaddr,
1401 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 0), *(u64 *)&cam0);
1402 rvu_write64(rvu, blkaddr,
1403 NPC_AF_KPUX_ENTRYX_CAMX(kpu, entry, 1), *(u64 *)&cam1);
1406 static inline u64 enable_mask(int count)
1408 return (((count) < 64) ? ~(BIT_ULL(count) - 1) : (0x00ULL));
1411 static void npc_program_kpu_profile(struct rvu *rvu, int blkaddr, int kpu,
1412 const struct npc_kpu_profile *profile)
1414 int entry, num_entries, max_entries;
1417 if (profile->cam_entries != profile->action_entries) {
1419 "KPU%d: CAM and action entries [%d != %d] not equal\n",
1420 kpu, profile->cam_entries, profile->action_entries);
1423 max_entries = rvu->hw->npc_kpu_entries;
1425 /* Program CAM match entries for previous KPU extracted data */
1426 num_entries = min_t(int, profile->cam_entries, max_entries);
1427 for (entry = 0; entry < num_entries; entry++)
1428 npc_config_kpucam(rvu, blkaddr,
1429 &profile->cam[entry], kpu, entry);
1431 /* Program this KPU's actions */
1432 num_entries = min_t(int, profile->action_entries, max_entries);
1433 for (entry = 0; entry < num_entries; entry++)
1434 npc_config_kpuaction(rvu, blkaddr, &profile->action[entry],
1437 /* Enable all programmed entries */
1438 num_entries = min_t(int, profile->action_entries, profile->cam_entries);
1439 entry_mask = enable_mask(num_entries);
1440 /* Disable first KPU_MAX_CST_ENT entries for built-in profile */
1441 if (!rvu->kpu.custom)
1442 entry_mask |= GENMASK_ULL(KPU_MAX_CST_ENT - 1, 0);
1443 rvu_write64(rvu, blkaddr,
1444 NPC_AF_KPUX_ENTRY_DISX(kpu, 0), entry_mask);
1445 if (num_entries > 64) {
1446 rvu_write64(rvu, blkaddr,
1447 NPC_AF_KPUX_ENTRY_DISX(kpu, 1),
1448 enable_mask(num_entries - 64));
1451 /* Enable this KPU */
1452 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(kpu), 0x01);
1455 static int npc_prepare_default_kpu(struct npc_kpu_profile_adapter *profile)
1457 profile->custom = 0;
1458 profile->name = def_pfl_name;
1459 profile->version = NPC_KPU_PROFILE_VER;
1460 profile->ikpu = ikpu_action_entries;
1461 profile->pkinds = ARRAY_SIZE(ikpu_action_entries);
1462 profile->kpu = npc_kpu_profiles;
1463 profile->kpus = ARRAY_SIZE(npc_kpu_profiles);
1464 profile->lt_def = &npc_lt_defaults;
1465 profile->mkex = &npc_mkex_default;
1470 static int npc_apply_custom_kpu(struct rvu *rvu,
1471 struct npc_kpu_profile_adapter *profile)
1473 size_t hdr_sz = sizeof(struct npc_kpu_profile_fwdata), offset = 0;
1474 struct npc_kpu_profile_fwdata *fw = rvu->kpu_fwdata;
1475 struct npc_kpu_profile_action *action;
1476 struct npc_kpu_profile_cam *cam;
1477 struct npc_kpu_fwdata *fw_kpu;
1481 if (rvu->kpu_fwdata_sz < hdr_sz) {
1482 dev_warn(rvu->dev, "Invalid KPU profile size\n");
1485 if (le64_to_cpu(fw->signature) != KPU_SIGN) {
1486 dev_warn(rvu->dev, "Invalid KPU profile signature %llx\n",
1490 /* Verify if the using known profile structure */
1491 if (NPC_KPU_VER_MAJ(profile->version) >
1492 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER)) {
1493 dev_warn(rvu->dev, "Not supported Major version: %d > %d\n",
1494 NPC_KPU_VER_MAJ(profile->version),
1495 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER));
1498 /* Verify if profile is aligned with the required kernel changes */
1499 if (NPC_KPU_VER_MIN(profile->version) <
1500 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER)) {
1502 "Invalid KPU profile version: %d.%d.%d expected version <= %d.%d.%d\n",
1503 NPC_KPU_VER_MAJ(profile->version),
1504 NPC_KPU_VER_MIN(profile->version),
1505 NPC_KPU_VER_PATCH(profile->version),
1506 NPC_KPU_VER_MAJ(NPC_KPU_PROFILE_VER),
1507 NPC_KPU_VER_MIN(NPC_KPU_PROFILE_VER),
1508 NPC_KPU_VER_PATCH(NPC_KPU_PROFILE_VER));
1511 /* Verify if profile fits the HW */
1512 if (fw->kpus > profile->kpus) {
1513 dev_warn(rvu->dev, "Not enough KPUs: %d > %ld\n", fw->kpus,
1518 profile->custom = 1;
1519 profile->name = fw->name;
1520 profile->version = le64_to_cpu(fw->version);
1521 profile->mkex = &fw->mkex;
1522 profile->lt_def = &fw->lt_def;
1524 for (kpu = 0; kpu < fw->kpus; kpu++) {
1525 fw_kpu = (struct npc_kpu_fwdata *)(fw->data + offset);
1526 if (fw_kpu->entries > KPU_MAX_CST_ENT)
1528 "Too many custom entries on KPU%d: %d > %d\n",
1529 kpu, fw_kpu->entries, KPU_MAX_CST_ENT);
1530 entries = min(fw_kpu->entries, KPU_MAX_CST_ENT);
1531 cam = (struct npc_kpu_profile_cam *)fw_kpu->data;
1532 offset += sizeof(*fw_kpu) + fw_kpu->entries * sizeof(*cam);
1533 action = (struct npc_kpu_profile_action *)(fw->data + offset);
1534 offset += fw_kpu->entries * sizeof(*action);
1535 if (rvu->kpu_fwdata_sz < hdr_sz + offset) {
1537 "Profile size mismatch on KPU%i parsing.\n",
1541 for (entry = 0; entry < entries; entry++) {
1542 profile->kpu[kpu].cam[entry] = cam[entry];
1543 profile->kpu[kpu].action[entry] = action[entry];
1550 static int npc_load_kpu_prfl_img(struct rvu *rvu, void __iomem *prfl_addr,
1551 u64 prfl_sz, const char *kpu_profile)
1553 struct npc_kpu_profile_fwdata *kpu_data = NULL;
1556 kpu_data = (struct npc_kpu_profile_fwdata __force *)prfl_addr;
1557 if (le64_to_cpu(kpu_data->signature) == KPU_SIGN &&
1558 !strncmp(kpu_data->name, kpu_profile, KPU_NAME_LEN)) {
1559 dev_info(rvu->dev, "Loading KPU profile from firmware db: %s\n",
1561 rvu->kpu_fwdata = kpu_data;
1562 rvu->kpu_fwdata_sz = prfl_sz;
1563 rvu->kpu_prfl_addr = prfl_addr;
1570 static int npc_fwdb_detect_load_prfl_img(struct rvu *rvu, uint64_t prfl_sz,
1571 const char *kpu_profile)
1573 struct npc_coalesced_kpu_prfl *img_data = NULL;
1574 int i = 0, rc = -EINVAL;
1575 void __iomem *kpu_prfl_addr;
1578 img_data = (struct npc_coalesced_kpu_prfl __force *)rvu->kpu_prfl_addr;
1579 if (le64_to_cpu(img_data->signature) == KPU_SIGN &&
1580 !strncmp(img_data->name, kpu_profile, KPU_NAME_LEN)) {
1581 /* Loaded profile is a single KPU profile. */
1582 rc = npc_load_kpu_prfl_img(rvu, rvu->kpu_prfl_addr,
1583 prfl_sz, kpu_profile);
1587 /* Loaded profile is coalesced image, offset of first KPU profile.*/
1588 offset = offsetof(struct npc_coalesced_kpu_prfl, prfl_sz) +
1589 (img_data->num_prfl * sizeof(uint16_t));
1590 /* Check if mapped image is coalesced image. */
1591 while (i < img_data->num_prfl) {
1592 /* Profile image offsets are rounded up to next 8 multiple.*/
1593 offset = ALIGN_8B_CEIL(offset);
1594 kpu_prfl_addr = (void __iomem *)((uintptr_t)rvu->kpu_prfl_addr +
1596 rc = npc_load_kpu_prfl_img(rvu, kpu_prfl_addr,
1597 img_data->prfl_sz[i], kpu_profile);
1600 /* Calculating offset of profile image based on profile size.*/
1601 offset += img_data->prfl_sz[i];
1608 static int npc_load_kpu_profile_fwdb(struct rvu *rvu, const char *kpu_profile)
1613 /* Setting up the mapping for NPC profile image */
1614 ret = npc_fwdb_prfl_img_map(rvu, &rvu->kpu_prfl_addr, &prfl_sz);
1618 /* Detect if profile is coalesced or single KPU profile and load */
1619 ret = npc_fwdb_detect_load_prfl_img(rvu, prfl_sz, kpu_profile);
1623 /* Cleaning up if KPU profile image from fwdata is not valid. */
1624 if (rvu->kpu_prfl_addr) {
1625 iounmap(rvu->kpu_prfl_addr);
1626 rvu->kpu_prfl_addr = NULL;
1627 rvu->kpu_fwdata_sz = 0;
1628 rvu->kpu_fwdata = NULL;
1635 static void npc_load_kpu_profile(struct rvu *rvu)
1637 struct npc_kpu_profile_adapter *profile = &rvu->kpu;
1638 const char *kpu_profile = rvu->kpu_pfl_name;
1639 const struct firmware *fw = NULL;
1640 bool retry_fwdb = false;
1642 /* If user not specified profile customization */
1643 if (!strncmp(kpu_profile, def_pfl_name, KPU_NAME_LEN))
1644 goto revert_to_default;
1645 /* First prepare default KPU, then we'll customize top entries. */
1646 npc_prepare_default_kpu(profile);
1648 /* Order of preceedence for load loading NPC profile (high to low)
1649 * Firmware binary in filesystem.
1650 * Firmware database method.
1651 * Default KPU profile.
1653 if (!request_firmware(&fw, kpu_profile, rvu->dev)) {
1654 dev_info(rvu->dev, "Loading KPU profile from firmware: %s\n",
1656 rvu->kpu_fwdata = kzalloc(fw->size, GFP_KERNEL);
1657 if (rvu->kpu_fwdata) {
1658 memcpy(rvu->kpu_fwdata, fw->data, fw->size);
1659 rvu->kpu_fwdata_sz = fw->size;
1661 release_firmware(fw);
1667 /* Loading the KPU profile using firmware database */
1668 if (npc_load_kpu_profile_fwdb(rvu, kpu_profile))
1669 goto revert_to_default;
1672 /* Apply profile customization if firmware was loaded. */
1673 if (!rvu->kpu_fwdata_sz || npc_apply_custom_kpu(rvu, profile)) {
1674 /* If image from firmware filesystem fails to load or invalid
1675 * retry with firmware database method.
1677 if (rvu->kpu_fwdata || rvu->kpu_fwdata_sz) {
1678 /* Loading image from firmware database failed. */
1679 if (rvu->kpu_prfl_addr) {
1680 iounmap(rvu->kpu_prfl_addr);
1681 rvu->kpu_prfl_addr = NULL;
1683 kfree(rvu->kpu_fwdata);
1685 rvu->kpu_fwdata = NULL;
1686 rvu->kpu_fwdata_sz = 0;
1689 goto load_image_fwdb;
1694 "Can't load KPU profile %s. Using default.\n",
1696 kfree(rvu->kpu_fwdata);
1697 rvu->kpu_fwdata = NULL;
1698 goto revert_to_default;
1701 dev_info(rvu->dev, "Using custom profile '%s', version %d.%d.%d\n",
1702 profile->name, NPC_KPU_VER_MAJ(profile->version),
1703 NPC_KPU_VER_MIN(profile->version),
1704 NPC_KPU_VER_PATCH(profile->version));
1709 npc_prepare_default_kpu(profile);
1712 static void npc_parser_profile_init(struct rvu *rvu, int blkaddr)
1714 struct rvu_hwinfo *hw = rvu->hw;
1715 int num_pkinds, num_kpus, idx;
1717 /* Disable all KPUs and their entries */
1718 for (idx = 0; idx < hw->npc_kpus; idx++) {
1719 rvu_write64(rvu, blkaddr,
1720 NPC_AF_KPUX_ENTRY_DISX(idx, 0), ~0ULL);
1721 rvu_write64(rvu, blkaddr,
1722 NPC_AF_KPUX_ENTRY_DISX(idx, 1), ~0ULL);
1723 rvu_write64(rvu, blkaddr, NPC_AF_KPUX_CFG(idx), 0x00);
1726 /* Load and customize KPU profile. */
1727 npc_load_kpu_profile(rvu);
1729 /* First program IKPU profile i.e PKIND configs.
1730 * Check HW max count to avoid configuring junk or
1731 * writing to unsupported CSR addresses.
1733 num_pkinds = rvu->kpu.pkinds;
1734 num_pkinds = min_t(int, hw->npc_pkinds, num_pkinds);
1736 for (idx = 0; idx < num_pkinds; idx++)
1737 npc_config_kpuaction(rvu, blkaddr, &rvu->kpu.ikpu[idx], 0, idx, true);
1739 /* Program KPU CAM and Action profiles */
1740 num_kpus = rvu->kpu.kpus;
1741 num_kpus = min_t(int, hw->npc_kpus, num_kpus);
1743 for (idx = 0; idx < num_kpus; idx++)
1744 npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]);
1747 static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1749 int nixlf_count = rvu_get_nixlf_count(rvu);
1750 struct npc_mcam *mcam = &rvu->hw->mcam;
1756 /* Actual number of MCAM entries vary by entry size */
1757 cfg = (rvu_read64(rvu, blkaddr,
1758 NPC_AF_INTFX_KEX_CFG(0)) >> 32) & 0x07;
1759 mcam->total_entries = (mcam->banks / BIT_ULL(cfg)) * mcam->banksize;
1760 mcam->keysize = cfg;
1762 /* Number of banks combined per MCAM entry */
1763 if (cfg == NPC_MCAM_KEY_X4)
1764 mcam->banks_per_entry = 4;
1765 else if (cfg == NPC_MCAM_KEY_X2)
1766 mcam->banks_per_entry = 2;
1768 mcam->banks_per_entry = 1;
1770 /* Reserve one MCAM entry for each of the NIX LF to
1771 * guarantee space to install default matching DMAC rule.
1772 * Also reserve 2 MCAM entries for each PF for default
1773 * channel based matching or 'bcast & promisc' matching to
1774 * support BCAST and PROMISC modes of operation for PFs.
1777 rsvd = (nixlf_count * RSVD_MCAM_ENTRIES_PER_NIXLF) +
1778 ((rvu->hw->total_pfs - 1) * RSVD_MCAM_ENTRIES_PER_PF);
1779 if (mcam->total_entries <= rsvd) {
1781 "Insufficient NPC MCAM size %d for pkt I/O, exiting\n",
1782 mcam->total_entries);
1786 mcam->bmap_entries = mcam->total_entries - rsvd;
1787 mcam->nixlf_offset = mcam->bmap_entries;
1788 mcam->pf_offset = mcam->nixlf_offset + nixlf_count;
1790 /* Allocate bitmaps for managing MCAM entries */
1791 mcam->bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(mcam->bmap_entries),
1792 sizeof(long), GFP_KERNEL);
1796 mcam->bmap_reverse = devm_kcalloc(rvu->dev,
1797 BITS_TO_LONGS(mcam->bmap_entries),
1798 sizeof(long), GFP_KERNEL);
1799 if (!mcam->bmap_reverse)
1802 mcam->bmap_fcnt = mcam->bmap_entries;
1804 /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
1805 mcam->entry2pfvf_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1806 sizeof(u16), GFP_KERNEL);
1807 if (!mcam->entry2pfvf_map)
1810 /* Reserve 1/8th of MCAM entries at the bottom for low priority
1811 * allocations and another 1/8th at the top for high priority
1814 mcam->lprio_count = mcam->bmap_entries / 8;
1815 if (mcam->lprio_count > BITS_PER_LONG)
1816 mcam->lprio_count = round_down(mcam->lprio_count,
1818 mcam->lprio_start = mcam->bmap_entries - mcam->lprio_count;
1819 mcam->hprio_count = mcam->lprio_count;
1820 mcam->hprio_end = mcam->hprio_count;
1823 /* Allocate bitmap for managing MCAM counters and memory
1824 * for saving counter to RVU PFFUNC allocation mapping.
1826 err = rvu_alloc_bitmap(&mcam->counters);
1830 mcam->cntr2pfvf_map = devm_kcalloc(rvu->dev, mcam->counters.max,
1831 sizeof(u16), GFP_KERNEL);
1832 if (!mcam->cntr2pfvf_map)
1835 /* Alloc memory for MCAM entry to counter mapping and for tracking
1836 * counter's reference count.
1838 mcam->entry2cntr_map = devm_kcalloc(rvu->dev, mcam->bmap_entries,
1839 sizeof(u16), GFP_KERNEL);
1840 if (!mcam->entry2cntr_map)
1843 mcam->cntr_refcnt = devm_kcalloc(rvu->dev, mcam->counters.max,
1844 sizeof(u16), GFP_KERNEL);
1845 if (!mcam->cntr_refcnt)
1848 /* Alloc memory for saving target device of mcam rule */
1849 mcam->entry2target_pffunc = devm_kcalloc(rvu->dev, mcam->total_entries,
1850 sizeof(u16), GFP_KERNEL);
1851 if (!mcam->entry2target_pffunc)
1854 for (index = 0; index < mcam->bmap_entries; index++) {
1855 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
1856 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
1859 for (cntr = 0; cntr < mcam->counters.max; cntr++)
1860 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
1862 mutex_init(&mcam->lock);
1867 kfree(mcam->counters.bmap);
1871 static void rvu_npc_hw_init(struct rvu *rvu, int blkaddr)
1873 struct npc_pkind *pkind = &rvu->hw->pkind;
1874 struct npc_mcam *mcam = &rvu->hw->mcam;
1875 struct rvu_hwinfo *hw = rvu->hw;
1876 u64 npc_const, npc_const1;
1879 npc_const = rvu_read64(rvu, blkaddr, NPC_AF_CONST);
1880 npc_const1 = rvu_read64(rvu, blkaddr, NPC_AF_CONST1);
1881 if (npc_const1 & BIT_ULL(63))
1882 npc_const2 = rvu_read64(rvu, blkaddr, NPC_AF_CONST2);
1884 pkind->rsrc.max = NPC_UNRESERVED_PKIND_COUNT;
1885 hw->npc_pkinds = (npc_const1 >> 12) & 0xFFULL;
1886 hw->npc_kpu_entries = npc_const1 & 0xFFFULL;
1887 hw->npc_kpus = (npc_const >> 8) & 0x1FULL;
1888 hw->npc_intfs = npc_const & 0xFULL;
1889 hw->npc_counters = (npc_const >> 48) & 0xFFFFULL;
1891 mcam->banks = (npc_const >> 44) & 0xFULL;
1892 mcam->banksize = (npc_const >> 28) & 0xFFFFULL;
1893 hw->npc_stat_ena = BIT_ULL(9);
1896 hw->npc_ext_set = true;
1897 /* 96xx supports only match_stats and npc_counters
1898 * reflected in NPC_AF_CONST reg.
1899 * STAT_SEL and ENA are at [0:8] and 9 bit positions.
1900 * 98xx has both match_stat and ext and npc_counter
1901 * reflected in NPC_AF_CONST2
1902 * STAT_SEL_EXT added at [12:14] bit position.
1903 * cn10k supports only ext and hence npc_counters in
1904 * NPC_AF_CONST is 0 and npc_counters reflected in NPC_AF_CONST2.
1905 * STAT_SEL bitpos incremented from [0:8] to [0:11] and ENA bit moved to 63
1907 if (!hw->npc_counters)
1908 hw->npc_stat_ena = BIT_ULL(63);
1909 hw->npc_counters = (npc_const2 >> 16) & 0xFFFFULL;
1910 mcam->banksize = npc_const2 & 0xFFFFULL;
1913 mcam->counters.max = hw->npc_counters;
1916 static void rvu_npc_setup_interfaces(struct rvu *rvu, int blkaddr)
1918 struct npc_mcam *mcam = &rvu->hw->mcam;
1919 struct rvu_hwinfo *hw = rvu->hw;
1920 u64 nibble_ena, rx_kex, tx_kex;
1923 /* Reserve last counter for MCAM RX miss action which is set to
1924 * drop packet. This way we will know how many pkts didn't match
1927 mcam->counters.max--;
1928 mcam->rx_miss_act_cntr = mcam->counters.max;
1930 rx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_RX];
1931 tx_kex = npc_mkex_default.keyx_cfg[NIX_INTF_TX];
1932 nibble_ena = FIELD_GET(NPC_PARSE_NIBBLE, rx_kex);
1934 nibble_ena = rvu_npc_get_tx_nibble_cfg(rvu, nibble_ena);
1936 tx_kex &= ~NPC_PARSE_NIBBLE;
1937 tx_kex |= FIELD_PREP(NPC_PARSE_NIBBLE, nibble_ena);
1938 npc_mkex_default.keyx_cfg[NIX_INTF_TX] = tx_kex;
1941 /* Configure RX interfaces */
1942 for (intf = 0; intf < hw->npc_intfs; intf++) {
1943 if (is_npc_intf_tx(intf))
1946 /* Set RX MCAM search key size. LA..LE (ltype only) + Channel */
1947 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1950 /* If MCAM lookup doesn't result in a match, drop the received
1951 * packet. And map this action to a counter to count dropped
1954 rvu_write64(rvu, blkaddr,
1955 NPC_AF_INTFX_MISS_ACT(intf), NIX_RX_ACTIONOP_DROP);
1957 /* NPC_AF_INTFX_MISS_STAT_ACT[14:12] - counter[11:9]
1958 * NPC_AF_INTFX_MISS_STAT_ACT[8:0] - counter[8:0]
1960 rvu_write64(rvu, blkaddr,
1961 NPC_AF_INTFX_MISS_STAT_ACT(intf),
1962 ((mcam->rx_miss_act_cntr >> 9) << 12) |
1963 hw->npc_stat_ena | mcam->rx_miss_act_cntr);
1966 /* Configure TX interfaces */
1967 for (intf = 0; intf < hw->npc_intfs; intf++) {
1968 if (is_npc_intf_rx(intf))
1971 /* Extract Ltypes LID_LA to LID_LE */
1972 rvu_write64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(intf),
1975 /* Set TX miss action to UCAST_DEFAULT i.e
1976 * transmit the packet on NIX LF SQ's default channel.
1978 rvu_write64(rvu, blkaddr,
1979 NPC_AF_INTFX_MISS_ACT(intf),
1980 NIX_TX_ACTIONOP_UCAST_DEFAULT);
1984 int rvu_npc_init(struct rvu *rvu)
1986 struct npc_kpu_profile_adapter *kpu = &rvu->kpu;
1987 struct npc_pkind *pkind = &rvu->hw->pkind;
1988 struct npc_mcam *mcam = &rvu->hw->mcam;
1989 int blkaddr, entry, bank, err;
1991 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1993 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
1997 rvu_npc_hw_init(rvu, blkaddr);
1999 /* First disable all MCAM entries, to stop traffic towards NIXLFs */
2000 for (bank = 0; bank < mcam->banks; bank++) {
2001 for (entry = 0; entry < mcam->banksize; entry++)
2002 rvu_write64(rvu, blkaddr,
2003 NPC_AF_MCAMEX_BANKX_CFG(entry, bank), 0);
2006 err = rvu_alloc_bitmap(&pkind->rsrc);
2009 /* Reserve PKIND#0 for LBKs. Power reset value of LBK_CH_PKIND is '0',
2010 * no need to configure PKIND for all LBKs separately.
2012 rvu_alloc_rsrc(&pkind->rsrc);
2014 /* Allocate mem for pkind to PF and channel mapping info */
2015 pkind->pfchan_map = devm_kcalloc(rvu->dev, pkind->rsrc.max,
2016 sizeof(u32), GFP_KERNEL);
2017 if (!pkind->pfchan_map)
2020 /* Configure KPU profile */
2021 npc_parser_profile_init(rvu, blkaddr);
2023 /* Config Outer L2, IPv4's NPC layer info */
2024 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OL2,
2025 (kpu->lt_def->pck_ol2.lid << 8) | (kpu->lt_def->pck_ol2.ltype_match << 4) |
2026 kpu->lt_def->pck_ol2.ltype_mask);
2027 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_OIP4,
2028 (kpu->lt_def->pck_oip4.lid << 8) | (kpu->lt_def->pck_oip4.ltype_match << 4) |
2029 kpu->lt_def->pck_oip4.ltype_mask);
2031 /* Config Inner IPV4 NPC layer info */
2032 rvu_write64(rvu, blkaddr, NPC_AF_PCK_DEF_IIP4,
2033 (kpu->lt_def->pck_iip4.lid << 8) | (kpu->lt_def->pck_iip4.ltype_match << 4) |
2034 kpu->lt_def->pck_iip4.ltype_mask);
2036 /* Enable below for Rx pkts.
2037 * - Outer IPv4 header checksum validation.
2038 * - Detect outer L2 broadcast address and set NPC_RESULT_S[L2B].
2039 * - Detect outer L2 multicast address and set NPC_RESULT_S[L2M].
2040 * - Inner IPv4 header checksum validation.
2041 * - Set non zero checksum error code value
2043 rvu_write64(rvu, blkaddr, NPC_AF_PCK_CFG,
2044 rvu_read64(rvu, blkaddr, NPC_AF_PCK_CFG) |
2045 ((u64)NPC_EC_OIP4_CSUM << 32) | (NPC_EC_IIP4_CSUM << 24) |
2046 BIT_ULL(7) | BIT_ULL(6) | BIT_ULL(2) | BIT_ULL(1));
2048 rvu_npc_setup_interfaces(rvu, blkaddr);
2050 /* Configure MKEX profile */
2051 npc_load_mkex_profile(rvu, blkaddr, rvu->mkex_pfl_name);
2053 err = npc_mcam_rsrcs_init(rvu, blkaddr);
2057 err = npc_flow_steering_init(rvu, blkaddr);
2060 "Incorrect mkex profile loaded using default mkex\n");
2061 npc_load_mkex_profile(rvu, blkaddr, def_pfl_name);
2067 void rvu_npc_freemem(struct rvu *rvu)
2069 struct npc_pkind *pkind = &rvu->hw->pkind;
2070 struct npc_mcam *mcam = &rvu->hw->mcam;
2072 kfree(pkind->rsrc.bmap);
2073 kfree(mcam->counters.bmap);
2074 if (rvu->kpu_prfl_addr)
2075 iounmap(rvu->kpu_prfl_addr);
2077 kfree(rvu->kpu_fwdata);
2078 mutex_destroy(&mcam->lock);
2081 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
2082 int blkaddr, int *alloc_cnt,
2085 struct npc_mcam *mcam = &rvu->hw->mcam;
2091 for (entry = 0; entry < mcam->bmap_entries; entry++) {
2092 if (mcam->entry2pfvf_map[entry] == pcifunc) {
2094 if (is_mcam_entry_enabled(rvu, mcam, blkaddr, entry))
2100 void rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
2101 int blkaddr, int *alloc_cnt,
2104 struct npc_mcam *mcam = &rvu->hw->mcam;
2110 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2111 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2113 if (mcam->cntr_refcnt[cntr])
2119 static int npc_mcam_verify_entry(struct npc_mcam *mcam,
2120 u16 pcifunc, int entry)
2122 /* verify AF installed entries */
2123 if (is_pffunc_af(pcifunc))
2125 /* Verify if entry is valid and if it is indeed
2126 * allocated to the requesting PFFUNC.
2128 if (entry >= mcam->bmap_entries)
2129 return NPC_MCAM_INVALID_REQ;
2131 if (pcifunc != mcam->entry2pfvf_map[entry])
2132 return NPC_MCAM_PERM_DENIED;
2137 static int npc_mcam_verify_counter(struct npc_mcam *mcam,
2138 u16 pcifunc, int cntr)
2140 /* Verify if counter is valid and if it is indeed
2141 * allocated to the requesting PFFUNC.
2143 if (cntr >= mcam->counters.max)
2144 return NPC_MCAM_INVALID_REQ;
2146 if (pcifunc != mcam->cntr2pfvf_map[cntr])
2147 return NPC_MCAM_PERM_DENIED;
2152 static void npc_map_mcam_entry_and_cntr(struct rvu *rvu, struct npc_mcam *mcam,
2153 int blkaddr, u16 entry, u16 cntr)
2155 u16 index = entry & (mcam->banksize - 1);
2156 u32 bank = npc_get_bank(mcam, entry);
2157 struct rvu_hwinfo *hw = rvu->hw;
2159 /* Set mapping and increment counter's refcnt */
2160 mcam->entry2cntr_map[entry] = cntr;
2161 mcam->cntr_refcnt[cntr]++;
2163 rvu_write64(rvu, blkaddr,
2164 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank),
2165 ((cntr >> 9) << 12) | hw->npc_stat_ena | cntr);
2168 static void npc_unmap_mcam_entry_and_cntr(struct rvu *rvu,
2169 struct npc_mcam *mcam,
2170 int blkaddr, u16 entry, u16 cntr)
2172 u16 index = entry & (mcam->banksize - 1);
2173 u32 bank = npc_get_bank(mcam, entry);
2175 /* Remove mapping and reduce counter's refcnt */
2176 mcam->entry2cntr_map[entry] = NPC_MCAM_INVALID_MAP;
2177 mcam->cntr_refcnt[cntr]--;
2179 rvu_write64(rvu, blkaddr,
2180 NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank), 0x00);
2183 /* Sets MCAM entry in bitmap as used. Update
2184 * reverse bitmap too. Should be called with
2185 * 'mcam->lock' held.
2187 static void npc_mcam_set_bit(struct npc_mcam *mcam, u16 index)
2192 rentry = mcam->bmap_entries - index - 1;
2194 __set_bit(entry, mcam->bmap);
2195 __set_bit(rentry, mcam->bmap_reverse);
2199 /* Sets MCAM entry in bitmap as free. Update
2200 * reverse bitmap too. Should be called with
2201 * 'mcam->lock' held.
2203 static void npc_mcam_clear_bit(struct npc_mcam *mcam, u16 index)
2208 rentry = mcam->bmap_entries - index - 1;
2210 __clear_bit(entry, mcam->bmap);
2211 __clear_bit(rentry, mcam->bmap_reverse);
2215 static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mcam,
2216 int blkaddr, u16 pcifunc)
2220 /* Scan all MCAM entries and free the ones mapped to 'pcifunc' */
2221 for (index = 0; index < mcam->bmap_entries; index++) {
2222 if (mcam->entry2pfvf_map[index] == pcifunc) {
2223 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
2224 /* Free the entry in bitmap */
2225 npc_mcam_clear_bit(mcam, index);
2226 /* Disable the entry */
2227 npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false);
2229 /* Update entry2counter mapping */
2230 cntr = mcam->entry2cntr_map[index];
2231 if (cntr != NPC_MCAM_INVALID_MAP)
2232 npc_unmap_mcam_entry_and_cntr(rvu, mcam,
2235 mcam->entry2target_pffunc[index] = 0x0;
2240 static void npc_mcam_free_all_counters(struct rvu *rvu, struct npc_mcam *mcam,
2245 /* Scan all MCAM counters and free the ones mapped to 'pcifunc' */
2246 for (cntr = 0; cntr < mcam->counters.max; cntr++) {
2247 if (mcam->cntr2pfvf_map[cntr] == pcifunc) {
2248 mcam->cntr2pfvf_map[cntr] = NPC_MCAM_INVALID_MAP;
2249 mcam->cntr_refcnt[cntr] = 0;
2250 rvu_free_rsrc(&mcam->counters, cntr);
2251 /* This API is expected to be called after freeing
2252 * MCAM entries, which inturn will remove
2253 * 'entry to counter' mapping.
2254 * No need to do it again.
2260 /* Find area of contiguous free entries of size 'nr'.
2261 * If not found return max contiguous free entries available.
2263 static u16 npc_mcam_find_zero_area(unsigned long *map, u16 size, u16 start,
2264 u16 nr, u16 *max_area)
2266 u16 max_area_start = 0;
2267 u16 index, next, end;
2272 index = find_next_zero_bit(map, size, start);
2274 return max_area_start;
2276 end = ((index + nr) >= size) ? size : index + nr;
2277 next = find_next_bit(map, end, index);
2278 if (*max_area < (next - index)) {
2279 *max_area = next - index;
2280 max_area_start = index;
2288 return max_area_start;
2291 /* Find number of free MCAM entries available
2292 * within range i.e in between 'start' and 'end'.
2294 static u16 npc_mcam_get_free_count(unsigned long *map, u16 start, u16 end)
2303 index = find_next_zero_bit(map, end, start);
2307 next = find_next_bit(map, end, index);
2309 fcnt += next - index;
2314 fcnt += end - index;
2319 npc_get_mcam_search_range_priority(struct npc_mcam *mcam,
2320 struct npc_mcam_alloc_entry_req *req,
2321 u16 *start, u16 *end, bool *reverse)
2325 if (req->priority == NPC_MCAM_HIGHER_PRIO)
2328 /* For a low priority entry allocation
2329 * - If reference entry is not in hprio zone then
2330 * search range: ref_entry to end.
2331 * - If reference entry is in hprio zone and if
2332 * request can be accomodated in non-hprio zone then
2333 * search range: 'start of middle zone' to 'end'
2334 * - else search in reverse, so that less number of hprio
2335 * zone entries are allocated.
2339 *start = req->ref_entry + 1;
2340 *end = mcam->bmap_entries;
2342 if (req->ref_entry >= mcam->hprio_end)
2345 fcnt = npc_mcam_get_free_count(mcam->bmap,
2346 mcam->hprio_end, mcam->bmap_entries);
2347 if (fcnt > req->count)
2348 *start = mcam->hprio_end;
2354 /* For a high priority entry allocation, search is always
2355 * in reverse to preserve hprio zone entries.
2356 * - If reference entry is not in lprio zone then
2357 * search range: 0 to ref_entry.
2358 * - If reference entry is in lprio zone and if
2359 * request can be accomodated in middle zone then
2360 * search range: 'hprio_end' to 'lprio_start'
2365 *end = req->ref_entry;
2367 if (req->ref_entry <= mcam->lprio_start)
2370 fcnt = npc_mcam_get_free_count(mcam->bmap,
2371 mcam->hprio_end, mcam->lprio_start);
2372 if (fcnt < req->count)
2374 *start = mcam->hprio_end;
2375 *end = mcam->lprio_start;
2378 static int npc_mcam_alloc_entries(struct npc_mcam *mcam, u16 pcifunc,
2379 struct npc_mcam_alloc_entry_req *req,
2380 struct npc_mcam_alloc_entry_rsp *rsp)
2382 u16 entry_list[NPC_MAX_NONCONTIG_ENTRIES];
2383 u16 fcnt, hp_fcnt, lp_fcnt;
2384 u16 start, end, index;
2385 int entry, next_start;
2386 bool reverse = false;
2387 unsigned long *bmap;
2390 mutex_lock(&mcam->lock);
2392 /* Check if there are any free entries */
2393 if (!mcam->bmap_fcnt) {
2394 mutex_unlock(&mcam->lock);
2395 return NPC_MCAM_ALLOC_FAILED;
2398 /* MCAM entries are divided into high priority, middle and
2399 * low priority zones. Idea is to not allocate top and lower
2400 * most entries as much as possible, this is to increase
2401 * probability of honouring priority allocation requests.
2403 * Two bitmaps are used for mcam entry management,
2404 * mcam->bmap for forward search i.e '0 to mcam->bmap_entries'.
2405 * mcam->bmap_reverse for reverse search i.e 'mcam->bmap_entries to 0'.
2407 * Reverse bitmap is used to allocate entries
2408 * - when a higher priority entry is requested
2409 * - when available free entries are less.
2410 * Lower priority ones out of avaialble free entries are always
2411 * chosen when 'high vs low' question arises.
2414 /* Get the search range for priority allocation request */
2415 if (req->priority) {
2416 npc_get_mcam_search_range_priority(mcam, req,
2417 &start, &end, &reverse);
2421 /* For a VF base MCAM match rule is set by its PF. And all the
2422 * further MCAM rules installed by VF on its own are
2423 * concatenated with the base rule set by its PF. Hence PF entries
2424 * should be at lower priority compared to VF entries. Otherwise
2425 * base rule is hit always and rules installed by VF will be of
2426 * no use. Hence if the request is from PF and NOT a priority
2427 * allocation request then allocate low priority entries.
2429 if (!(pcifunc & RVU_PFVF_FUNC_MASK))
2432 /* Find out the search range for non-priority allocation request
2434 * Get MCAM free entry count in middle zone.
2436 lp_fcnt = npc_mcam_get_free_count(mcam->bmap,
2438 mcam->bmap_entries);
2439 hp_fcnt = npc_mcam_get_free_count(mcam->bmap, 0, mcam->hprio_end);
2440 fcnt = mcam->bmap_fcnt - lp_fcnt - hp_fcnt;
2442 /* Check if request can be accomodated in the middle zone */
2443 if (fcnt > req->count) {
2444 start = mcam->hprio_end;
2445 end = mcam->lprio_start;
2446 } else if ((fcnt + (hp_fcnt / 2) + (lp_fcnt / 2)) > req->count) {
2447 /* Expand search zone from half of hprio zone to
2448 * half of lprio zone.
2450 start = mcam->hprio_end / 2;
2451 end = mcam->bmap_entries - (mcam->lprio_count / 2);
2454 /* Not enough free entries, search all entries in reverse,
2455 * so that low priority ones will get used up.
2460 end = mcam->bmap_entries;
2465 bmap = mcam->bmap_reverse;
2466 start = mcam->bmap_entries - start;
2467 end = mcam->bmap_entries - end;
2474 /* Allocate requested number of contiguous entries, if
2475 * unsuccessful find max contiguous entries available.
2477 index = npc_mcam_find_zero_area(bmap, end, start,
2478 req->count, &max_contig);
2479 rsp->count = max_contig;
2481 rsp->entry = mcam->bmap_entries - index - max_contig;
2485 /* Allocate requested number of non-contiguous entries,
2486 * if unsuccessful allocate as many as possible.
2490 for (entry = 0; entry < req->count; entry++) {
2491 index = find_next_zero_bit(bmap, end, next_start);
2495 next_start = start + (index - start) + 1;
2497 /* Save the entry's index */
2499 index = mcam->bmap_entries - index - 1;
2500 entry_list[entry] = index;
2505 /* If allocating requested no of entries is unsucessful,
2506 * expand the search range to full bitmap length and retry.
2508 if (!req->priority && (rsp->count < req->count) &&
2509 ((end - start) != mcam->bmap_entries)) {
2512 end = mcam->bmap_entries;
2516 /* For priority entry allocation requests, if allocation is
2517 * failed then expand search to max possible range and retry.
2519 if (req->priority && rsp->count < req->count) {
2520 if (req->priority == NPC_MCAM_LOWER_PRIO &&
2521 (start != (req->ref_entry + 1))) {
2522 start = req->ref_entry + 1;
2523 end = mcam->bmap_entries;
2526 } else if ((req->priority == NPC_MCAM_HIGHER_PRIO) &&
2527 ((end - start) != req->ref_entry)) {
2529 end = req->ref_entry;
2535 /* Copy MCAM entry indices into mbox response entry_list.
2536 * Requester always expects indices in ascending order, so
2537 * so reverse the list if reverse bitmap is used for allocation.
2539 if (!req->contig && rsp->count) {
2541 for (entry = rsp->count - 1; entry >= 0; entry--) {
2543 rsp->entry_list[index++] = entry_list[entry];
2545 rsp->entry_list[entry] = entry_list[entry];
2549 /* Mark the allocated entries as used and set nixlf mapping */
2550 for (entry = 0; entry < rsp->count; entry++) {
2551 index = req->contig ?
2552 (rsp->entry + entry) : rsp->entry_list[entry];
2553 npc_mcam_set_bit(mcam, index);
2554 mcam->entry2pfvf_map[index] = pcifunc;
2555 mcam->entry2cntr_map[index] = NPC_MCAM_INVALID_MAP;
2558 /* Update available free count in mbox response */
2559 rsp->free_count = mcam->bmap_fcnt;
2561 mutex_unlock(&mcam->lock);
2565 int rvu_mbox_handler_npc_mcam_alloc_entry(struct rvu *rvu,
2566 struct npc_mcam_alloc_entry_req *req,
2567 struct npc_mcam_alloc_entry_rsp *rsp)
2569 struct npc_mcam *mcam = &rvu->hw->mcam;
2570 u16 pcifunc = req->hdr.pcifunc;
2573 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2575 return NPC_MCAM_INVALID_REQ;
2577 rsp->entry = NPC_MCAM_ENTRY_INVALID;
2578 rsp->free_count = 0;
2580 /* Check if ref_entry is within range */
2581 if (req->priority && req->ref_entry >= mcam->bmap_entries) {
2582 dev_err(rvu->dev, "%s: reference entry %d is out of range\n",
2583 __func__, req->ref_entry);
2584 return NPC_MCAM_INVALID_REQ;
2587 /* ref_entry can't be '0' if requested priority is high.
2588 * Can't be last entry if requested priority is low.
2590 if ((!req->ref_entry && req->priority == NPC_MCAM_HIGHER_PRIO) ||
2591 ((req->ref_entry == (mcam->bmap_entries - 1)) &&
2592 req->priority == NPC_MCAM_LOWER_PRIO))
2593 return NPC_MCAM_INVALID_REQ;
2595 /* Since list of allocated indices needs to be sent to requester,
2596 * max number of non-contiguous entries per mbox msg is limited.
2598 if (!req->contig && req->count > NPC_MAX_NONCONTIG_ENTRIES) {
2600 "%s: %d Non-contiguous MCAM entries requested is more than max (%d) allowed\n",
2601 __func__, req->count, NPC_MAX_NONCONTIG_ENTRIES);
2602 return NPC_MCAM_INVALID_REQ;
2605 /* Alloc request from PFFUNC with no NIXLF attached should be denied */
2606 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2607 return NPC_MCAM_ALLOC_DENIED;
2609 return npc_mcam_alloc_entries(mcam, pcifunc, req, rsp);
2612 int rvu_mbox_handler_npc_mcam_free_entry(struct rvu *rvu,
2613 struct npc_mcam_free_entry_req *req,
2614 struct msg_rsp *rsp)
2616 struct npc_mcam *mcam = &rvu->hw->mcam;
2617 u16 pcifunc = req->hdr.pcifunc;
2618 int blkaddr, rc = 0;
2621 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2623 return NPC_MCAM_INVALID_REQ;
2625 /* Free request from PFFUNC with no NIXLF attached, ignore */
2626 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2627 return NPC_MCAM_INVALID_REQ;
2629 mutex_lock(&mcam->lock);
2634 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2638 mcam->entry2pfvf_map[req->entry] = NPC_MCAM_INVALID_MAP;
2639 mcam->entry2target_pffunc[req->entry] = 0x0;
2640 npc_mcam_clear_bit(mcam, req->entry);
2641 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2643 /* Update entry2counter mapping */
2644 cntr = mcam->entry2cntr_map[req->entry];
2645 if (cntr != NPC_MCAM_INVALID_MAP)
2646 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2652 /* Free up all entries allocated to requesting PFFUNC */
2653 npc_mcam_free_all_entries(rvu, mcam, blkaddr, pcifunc);
2655 mutex_unlock(&mcam->lock);
2659 int rvu_mbox_handler_npc_mcam_read_entry(struct rvu *rvu,
2660 struct npc_mcam_read_entry_req *req,
2661 struct npc_mcam_read_entry_rsp *rsp)
2663 struct npc_mcam *mcam = &rvu->hw->mcam;
2664 u16 pcifunc = req->hdr.pcifunc;
2667 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2669 return NPC_MCAM_INVALID_REQ;
2671 mutex_lock(&mcam->lock);
2672 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2674 npc_read_mcam_entry(rvu, mcam, blkaddr, req->entry,
2676 &rsp->intf, &rsp->enable);
2679 mutex_unlock(&mcam->lock);
2683 int rvu_mbox_handler_npc_mcam_write_entry(struct rvu *rvu,
2684 struct npc_mcam_write_entry_req *req,
2685 struct msg_rsp *rsp)
2687 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
2688 struct npc_mcam *mcam = &rvu->hw->mcam;
2689 u16 pcifunc = req->hdr.pcifunc;
2693 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2695 return NPC_MCAM_INVALID_REQ;
2697 mutex_lock(&mcam->lock);
2698 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2702 if (req->set_cntr &&
2703 npc_mcam_verify_counter(mcam, pcifunc, req->cntr)) {
2704 rc = NPC_MCAM_INVALID_REQ;
2708 if (!is_npc_interface_valid(rvu, req->intf)) {
2709 rc = NPC_MCAM_INVALID_REQ;
2713 if (is_npc_intf_tx(req->intf))
2714 nix_intf = pfvf->nix_tx_intf;
2716 nix_intf = pfvf->nix_rx_intf;
2718 if (!is_pffunc_af(pcifunc) &&
2719 npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf, pcifunc)) {
2720 rc = NPC_MCAM_INVALID_REQ;
2724 /* For AF installed rules, the nix_intf should be set to target NIX */
2725 if (is_pffunc_af(req->hdr.pcifunc))
2726 nix_intf = req->intf;
2728 npc_config_mcam_entry(rvu, mcam, blkaddr, req->entry, nix_intf,
2729 &req->entry_data, req->enable_entry);
2732 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2733 req->entry, req->cntr);
2737 mutex_unlock(&mcam->lock);
2741 int rvu_mbox_handler_npc_mcam_ena_entry(struct rvu *rvu,
2742 struct npc_mcam_ena_dis_entry_req *req,
2743 struct msg_rsp *rsp)
2745 struct npc_mcam *mcam = &rvu->hw->mcam;
2746 u16 pcifunc = req->hdr.pcifunc;
2749 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2751 return NPC_MCAM_INVALID_REQ;
2753 mutex_lock(&mcam->lock);
2754 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2755 mutex_unlock(&mcam->lock);
2759 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, true);
2764 int rvu_mbox_handler_npc_mcam_dis_entry(struct rvu *rvu,
2765 struct npc_mcam_ena_dis_entry_req *req,
2766 struct msg_rsp *rsp)
2768 struct npc_mcam *mcam = &rvu->hw->mcam;
2769 u16 pcifunc = req->hdr.pcifunc;
2772 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2774 return NPC_MCAM_INVALID_REQ;
2776 mutex_lock(&mcam->lock);
2777 rc = npc_mcam_verify_entry(mcam, pcifunc, req->entry);
2778 mutex_unlock(&mcam->lock);
2782 npc_enable_mcam_entry(rvu, mcam, blkaddr, req->entry, false);
2787 int rvu_mbox_handler_npc_mcam_shift_entry(struct rvu *rvu,
2788 struct npc_mcam_shift_entry_req *req,
2789 struct npc_mcam_shift_entry_rsp *rsp)
2791 struct npc_mcam *mcam = &rvu->hw->mcam;
2792 u16 pcifunc = req->hdr.pcifunc;
2793 u16 old_entry, new_entry;
2794 int blkaddr, rc = 0;
2797 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2799 return NPC_MCAM_INVALID_REQ;
2801 if (req->shift_count > NPC_MCAM_MAX_SHIFTS)
2802 return NPC_MCAM_INVALID_REQ;
2804 mutex_lock(&mcam->lock);
2805 for (index = 0; index < req->shift_count; index++) {
2806 old_entry = req->curr_entry[index];
2807 new_entry = req->new_entry[index];
2809 /* Check if both old and new entries are valid and
2810 * does belong to this PFFUNC or not.
2812 rc = npc_mcam_verify_entry(mcam, pcifunc, old_entry);
2816 rc = npc_mcam_verify_entry(mcam, pcifunc, new_entry);
2820 /* new_entry should not have a counter mapped */
2821 if (mcam->entry2cntr_map[new_entry] != NPC_MCAM_INVALID_MAP) {
2822 rc = NPC_MCAM_PERM_DENIED;
2826 /* Disable the new_entry */
2827 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, false);
2829 /* Copy rule from old entry to new entry */
2830 npc_copy_mcam_entry(rvu, mcam, blkaddr, old_entry, new_entry);
2832 /* Copy counter mapping, if any */
2833 cntr = mcam->entry2cntr_map[old_entry];
2834 if (cntr != NPC_MCAM_INVALID_MAP) {
2835 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2837 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2841 /* Enable new_entry and disable old_entry */
2842 npc_enable_mcam_entry(rvu, mcam, blkaddr, new_entry, true);
2843 npc_enable_mcam_entry(rvu, mcam, blkaddr, old_entry, false);
2846 /* If shift has failed then report the failed index */
2847 if (index != req->shift_count) {
2848 rc = NPC_MCAM_PERM_DENIED;
2849 rsp->failed_entry_idx = index;
2852 mutex_unlock(&mcam->lock);
2856 int rvu_mbox_handler_npc_mcam_alloc_counter(struct rvu *rvu,
2857 struct npc_mcam_alloc_counter_req *req,
2858 struct npc_mcam_alloc_counter_rsp *rsp)
2860 struct npc_mcam *mcam = &rvu->hw->mcam;
2861 u16 pcifunc = req->hdr.pcifunc;
2862 u16 max_contig, cntr;
2865 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2867 return NPC_MCAM_INVALID_REQ;
2869 /* If the request is from a PFFUNC with no NIXLF attached, ignore */
2870 if (!is_pffunc_af(pcifunc) && !is_nixlf_attached(rvu, pcifunc))
2871 return NPC_MCAM_INVALID_REQ;
2873 /* Since list of allocated counter IDs needs to be sent to requester,
2874 * max number of non-contiguous counters per mbox msg is limited.
2876 if (!req->contig && req->count > NPC_MAX_NONCONTIG_COUNTERS)
2877 return NPC_MCAM_INVALID_REQ;
2879 mutex_lock(&mcam->lock);
2881 /* Check if unused counters are available or not */
2882 if (!rvu_rsrc_free_count(&mcam->counters)) {
2883 mutex_unlock(&mcam->lock);
2884 return NPC_MCAM_ALLOC_FAILED;
2890 /* Allocate requested number of contiguous counters, if
2891 * unsuccessful find max contiguous entries available.
2893 index = npc_mcam_find_zero_area(mcam->counters.bmap,
2894 mcam->counters.max, 0,
2895 req->count, &max_contig);
2896 rsp->count = max_contig;
2898 for (cntr = index; cntr < (index + max_contig); cntr++) {
2899 __set_bit(cntr, mcam->counters.bmap);
2900 mcam->cntr2pfvf_map[cntr] = pcifunc;
2903 /* Allocate requested number of non-contiguous counters,
2904 * if unsuccessful allocate as many as possible.
2906 for (cntr = 0; cntr < req->count; cntr++) {
2907 index = rvu_alloc_rsrc(&mcam->counters);
2910 rsp->cntr_list[cntr] = index;
2912 mcam->cntr2pfvf_map[index] = pcifunc;
2916 mutex_unlock(&mcam->lock);
2920 int rvu_mbox_handler_npc_mcam_free_counter(struct rvu *rvu,
2921 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
2923 struct npc_mcam *mcam = &rvu->hw->mcam;
2924 u16 index, entry = 0;
2927 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2929 return NPC_MCAM_INVALID_REQ;
2931 mutex_lock(&mcam->lock);
2932 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2934 mutex_unlock(&mcam->lock);
2938 /* Mark counter as free/unused */
2939 mcam->cntr2pfvf_map[req->cntr] = NPC_MCAM_INVALID_MAP;
2940 rvu_free_rsrc(&mcam->counters, req->cntr);
2942 /* Disable all MCAM entry's stats which are using this counter */
2943 while (entry < mcam->bmap_entries) {
2944 if (!mcam->cntr_refcnt[req->cntr])
2947 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2948 if (index >= mcam->bmap_entries)
2951 if (mcam->entry2cntr_map[index] != req->cntr)
2954 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2958 mutex_unlock(&mcam->lock);
2962 int rvu_mbox_handler_npc_mcam_unmap_counter(struct rvu *rvu,
2963 struct npc_mcam_unmap_counter_req *req, struct msg_rsp *rsp)
2965 struct npc_mcam *mcam = &rvu->hw->mcam;
2966 u16 index, entry = 0;
2969 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2971 return NPC_MCAM_INVALID_REQ;
2973 mutex_lock(&mcam->lock);
2974 rc = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
2978 /* Unmap the MCAM entry and counter */
2980 rc = npc_mcam_verify_entry(mcam, req->hdr.pcifunc, req->entry);
2983 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
2984 req->entry, req->cntr);
2988 /* Disable all MCAM entry's stats which are using this counter */
2989 while (entry < mcam->bmap_entries) {
2990 if (!mcam->cntr_refcnt[req->cntr])
2993 index = find_next_bit(mcam->bmap, mcam->bmap_entries, entry);
2994 if (index >= mcam->bmap_entries)
2998 if (mcam->entry2cntr_map[index] != req->cntr)
3001 npc_unmap_mcam_entry_and_cntr(rvu, mcam, blkaddr,
3005 mutex_unlock(&mcam->lock);
3009 int rvu_mbox_handler_npc_mcam_clear_counter(struct rvu *rvu,
3010 struct npc_mcam_oper_counter_req *req, struct msg_rsp *rsp)
3012 struct npc_mcam *mcam = &rvu->hw->mcam;
3015 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3017 return NPC_MCAM_INVALID_REQ;
3019 mutex_lock(&mcam->lock);
3020 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3021 mutex_unlock(&mcam->lock);
3025 rvu_write64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr), 0x00);
3030 int rvu_mbox_handler_npc_mcam_counter_stats(struct rvu *rvu,
3031 struct npc_mcam_oper_counter_req *req,
3032 struct npc_mcam_oper_counter_rsp *rsp)
3034 struct npc_mcam *mcam = &rvu->hw->mcam;
3037 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3039 return NPC_MCAM_INVALID_REQ;
3041 mutex_lock(&mcam->lock);
3042 err = npc_mcam_verify_counter(mcam, req->hdr.pcifunc, req->cntr);
3043 mutex_unlock(&mcam->lock);
3047 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(req->cntr));
3048 rsp->stat &= BIT_ULL(48) - 1;
3053 int rvu_mbox_handler_npc_mcam_alloc_and_write_entry(struct rvu *rvu,
3054 struct npc_mcam_alloc_and_write_entry_req *req,
3055 struct npc_mcam_alloc_and_write_entry_rsp *rsp)
3057 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
3058 struct npc_mcam_alloc_counter_req cntr_req;
3059 struct npc_mcam_alloc_counter_rsp cntr_rsp;
3060 struct npc_mcam_alloc_entry_req entry_req;
3061 struct npc_mcam_alloc_entry_rsp entry_rsp;
3062 struct npc_mcam *mcam = &rvu->hw->mcam;
3063 u16 entry = NPC_MCAM_ENTRY_INVALID;
3064 u16 cntr = NPC_MCAM_ENTRY_INVALID;
3068 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3070 return NPC_MCAM_INVALID_REQ;
3072 if (!is_npc_interface_valid(rvu, req->intf))
3073 return NPC_MCAM_INVALID_REQ;
3075 if (npc_mcam_verify_pf_func(rvu, &req->entry_data, req->intf,
3077 return NPC_MCAM_INVALID_REQ;
3079 /* Try to allocate a MCAM entry */
3080 entry_req.hdr.pcifunc = req->hdr.pcifunc;
3081 entry_req.contig = true;
3082 entry_req.priority = req->priority;
3083 entry_req.ref_entry = req->ref_entry;
3084 entry_req.count = 1;
3086 rc = rvu_mbox_handler_npc_mcam_alloc_entry(rvu,
3087 &entry_req, &entry_rsp);
3091 if (!entry_rsp.count)
3092 return NPC_MCAM_ALLOC_FAILED;
3094 entry = entry_rsp.entry;
3096 if (!req->alloc_cntr)
3099 /* Now allocate counter */
3100 cntr_req.hdr.pcifunc = req->hdr.pcifunc;
3101 cntr_req.contig = true;
3104 rc = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
3106 /* Free allocated MCAM entry */
3107 mutex_lock(&mcam->lock);
3108 mcam->entry2pfvf_map[entry] = NPC_MCAM_INVALID_MAP;
3109 npc_mcam_clear_bit(mcam, entry);
3110 mutex_unlock(&mcam->lock);
3114 cntr = cntr_rsp.cntr;
3117 mutex_lock(&mcam->lock);
3119 if (is_npc_intf_tx(req->intf))
3120 nix_intf = pfvf->nix_tx_intf;
3122 nix_intf = pfvf->nix_rx_intf;
3124 npc_config_mcam_entry(rvu, mcam, blkaddr, entry, nix_intf,
3125 &req->entry_data, req->enable_entry);
3127 if (req->alloc_cntr)
3128 npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr, entry, cntr);
3129 mutex_unlock(&mcam->lock);
3137 #define GET_KEX_CFG(intf) \
3138 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_INTFX_KEX_CFG(intf))
3140 #define GET_KEX_FLAGS(ld) \
3141 rvu_read64(rvu, BLKADDR_NPC, NPC_AF_KEX_LDATAX_FLAGS_CFG(ld))
3143 #define GET_KEX_LD(intf, lid, lt, ld) \
3144 rvu_read64(rvu, BLKADDR_NPC, \
3145 NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, lt, ld))
3147 #define GET_KEX_LDFLAGS(intf, ld, fl) \
3148 rvu_read64(rvu, BLKADDR_NPC, \
3149 NPC_AF_INTFX_LDATAX_FLAGSX_CFG(intf, ld, fl))
3151 int rvu_mbox_handler_npc_get_kex_cfg(struct rvu *rvu, struct msg_req *req,
3152 struct npc_get_kex_cfg_rsp *rsp)
3154 int lid, lt, ld, fl;
3156 rsp->rx_keyx_cfg = GET_KEX_CFG(NIX_INTF_RX);
3157 rsp->tx_keyx_cfg = GET_KEX_CFG(NIX_INTF_TX);
3158 for (lid = 0; lid < NPC_MAX_LID; lid++) {
3159 for (lt = 0; lt < NPC_MAX_LT; lt++) {
3160 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3161 rsp->intf_lid_lt_ld[NIX_INTF_RX][lid][lt][ld] =
3162 GET_KEX_LD(NIX_INTF_RX, lid, lt, ld);
3163 rsp->intf_lid_lt_ld[NIX_INTF_TX][lid][lt][ld] =
3164 GET_KEX_LD(NIX_INTF_TX, lid, lt, ld);
3168 for (ld = 0; ld < NPC_MAX_LD; ld++)
3169 rsp->kex_ld_flags[ld] = GET_KEX_FLAGS(ld);
3171 for (ld = 0; ld < NPC_MAX_LD; ld++) {
3172 for (fl = 0; fl < NPC_MAX_LFL; fl++) {
3173 rsp->intf_ld_flags[NIX_INTF_RX][ld][fl] =
3174 GET_KEX_LDFLAGS(NIX_INTF_RX, ld, fl);
3175 rsp->intf_ld_flags[NIX_INTF_TX][ld][fl] =
3176 GET_KEX_LDFLAGS(NIX_INTF_TX, ld, fl);
3179 memcpy(rsp->mkex_pfl_name, rvu->mkex_pfl_name, MKEX_NAME_LEN);
3184 npc_set_var_len_offset_pkind(struct rvu *rvu, u16 pcifunc, u64 pkind,
3185 u8 var_len_off, u8 var_len_off_mask, u8 shift_dir)
3187 struct npc_kpu_action0 *act0;
3192 if (!var_len_off_mask)
3195 if (var_len_off_mask != 0xff) {
3197 shift_count = __ffs(var_len_off_mask);
3199 shift_count = (8 - __fls(var_len_off_mask));
3201 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, pcifunc);
3203 dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
3206 val = rvu_read64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind));
3207 act0 = (struct npc_kpu_action0 *)&val;
3208 act0->var_len_shift = shift_count;
3209 act0->var_len_right = shift_dir;
3210 act0->var_len_mask = var_len_off_mask;
3211 act0->var_len_offset = var_len_off;
3212 rvu_write64(rvu, blkaddr, NPC_AF_PKINDX_ACTION0(pkind), val);
3216 int rvu_npc_set_parse_mode(struct rvu *rvu, u16 pcifunc, u64 mode, u8 dir,
3217 u64 pkind, u8 var_len_off, u8 var_len_off_mask,
3221 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
3222 int blkaddr, nixlf, rc, intf_mode;
3223 int pf = rvu_get_pf(pcifunc);
3224 u64 rxpkind, txpkind;
3227 /* use default pkind to disable edsa/higig */
3228 rxpkind = rvu_npc_get_pkind(rvu, pf);
3229 txpkind = NPC_TX_DEF_PKIND;
3230 intf_mode = NPC_INTF_MODE_DEF;
3232 if (mode & OTX2_PRIV_FLAGS_CUSTOM) {
3233 if (pkind == NPC_RX_CUSTOM_PRE_L2_PKIND) {
3234 rc = npc_set_var_len_offset_pkind(rvu, pcifunc, pkind,
3245 if (dir & PKIND_RX) {
3246 /* rx pkind set req valid only for cgx mapped PFs */
3247 if (!is_cgx_config_permitted(rvu, pcifunc))
3249 rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id);
3251 rc = cgx_set_pkind(rvu_cgx_pdata(cgx_id, rvu), lmac_id,
3257 if (dir & PKIND_TX) {
3258 /* Tx pkind set request valid if PCIFUNC has NIXLF attached */
3259 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, &blkaddr);
3263 rvu_write64(rvu, blkaddr, NIX_AF_LFX_TX_PARSE_CFG(nixlf),
3267 pfvf->intf_mode = intf_mode;
3271 int rvu_mbox_handler_npc_set_pkind(struct rvu *rvu, struct npc_set_pkind *req,
3272 struct msg_rsp *rsp)
3274 return rvu_npc_set_parse_mode(rvu, req->hdr.pcifunc, req->mode,
3275 req->dir, req->pkind, req->var_len_off,
3276 req->var_len_off_mask, req->shift_dir);
3279 int rvu_mbox_handler_npc_read_base_steer_rule(struct rvu *rvu,
3280 struct msg_req *req,
3281 struct npc_mcam_read_base_rule_rsp *rsp)
3283 struct npc_mcam *mcam = &rvu->hw->mcam;
3284 int index, blkaddr, nixlf, rc = 0;
3285 u16 pcifunc = req->hdr.pcifunc;
3286 struct rvu_pfvf *pfvf;
3289 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3291 return NPC_MCAM_INVALID_REQ;
3293 /* Return the channel number in case of PF */
3294 if (!(pcifunc & RVU_PFVF_FUNC_MASK)) {
3295 pfvf = rvu_get_pfvf(rvu, pcifunc);
3296 rsp->entry.kw[0] = pfvf->rx_chan_base;
3297 rsp->entry.kw_mask[0] = 0xFFFULL;
3301 /* Find the pkt steering rule installed by PF to this VF */
3302 mutex_lock(&mcam->lock);
3303 for (index = 0; index < mcam->bmap_entries; index++) {
3304 if (mcam->entry2target_pffunc[index] == pcifunc)
3308 rc = nix_get_nixlf(rvu, pcifunc, &nixlf, NULL);
3310 mutex_unlock(&mcam->lock);
3313 /* Read the default ucast entry if there is no pkt steering rule */
3314 index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
3317 /* Read the mcam entry */
3318 npc_read_mcam_entry(rvu, mcam, blkaddr, index, &rsp->entry, &intf,
3320 mutex_unlock(&mcam->lock);
3325 int rvu_mbox_handler_npc_mcam_entry_stats(struct rvu *rvu,
3326 struct npc_mcam_get_stats_req *req,
3327 struct npc_mcam_get_stats_rsp *rsp)
3329 struct npc_mcam *mcam = &rvu->hw->mcam;
3335 blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
3337 return NPC_MCAM_INVALID_REQ;
3339 mutex_lock(&mcam->lock);
3341 index = req->entry & (mcam->banksize - 1);
3342 bank = npc_get_bank(mcam, req->entry);
3344 /* read MCAM entry STAT_ACT register */
3345 regval = rvu_read64(rvu, blkaddr, NPC_AF_MCAMEX_BANKX_STAT_ACT(index, bank));
3347 if (!(regval & rvu->hw->npc_stat_ena)) {
3349 mutex_unlock(&mcam->lock);
3353 cntr = regval & 0x1FF;
3356 rsp->stat = rvu_read64(rvu, blkaddr, NPC_AF_MATCH_STATX(cntr));
3357 rsp->stat &= BIT_ULL(48) - 1;
3359 mutex_unlock(&mcam->lock);