1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
9 roc_npc_vtag_actions_get(struct roc_npc *roc_npc)
11 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
13 return npc->vtag_strip_actions;
17 roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
19 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
21 npc->vtag_strip_actions -= count;
22 return npc->vtag_strip_actions;
26 roc_npc_mcam_free_counter(struct roc_npc *roc_npc, uint16_t ctr_id)
28 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
30 return npc_mcam_free_counter(npc, ctr_id);
34 roc_npc_mcam_read_counter(struct roc_npc *roc_npc, uint32_t ctr_id,
37 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
39 return npc_mcam_read_counter(npc, ctr_id, count);
43 roc_npc_mcam_clear_counter(struct roc_npc *roc_npc, uint32_t ctr_id)
45 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
47 return npc_mcam_clear_counter(npc, ctr_id);
51 roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
53 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
55 return npc_mcam_free_entry(npc, entry);
59 roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
61 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
63 return npc_flow_free_all_resources(npc);
67 roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
68 int *alloc_entry, int req_count, int priority,
71 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
73 return npc_mcam_alloc_entries(npc, ref_entry, alloc_entry, req_count,
74 priority, resp_count);
78 roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
79 struct roc_npc_flow *ref_mcam, int prio,
82 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
84 return npc_mcam_alloc_entry(npc, mcam, ref_mcam, prio, resp_count);
88 roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
91 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
93 return npc_mcam_ena_dis_entry(npc, mcam, enable);
97 roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
99 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
101 return npc_mcam_write_entry(npc, mcam);
105 roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc)
107 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
109 if (roc_model_is_cn10k())
110 return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
112 return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
116 npc_mcam_tot_entries(void)
118 /* FIXME: change to reading in AF from NPC_AF_CONST1/2
119 * MCAM_BANK_DEPTH(_EXT) * MCAM_BANKS
121 if (roc_model_is_cn10k() || roc_model_is_cn98xx())
122 return 16 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 4096 */
124 return 4 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 1024 */
128 roc_npc_profile_name_get(struct roc_npc *roc_npc)
130 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
132 return (char *)npc->profile_name;
136 roc_npc_init(struct roc_npc *roc_npc)
138 uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
139 struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
140 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
145 PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
147 memset(npc, 0, sizeof(*npc));
148 npc->mbox = (&nix->dev)->mbox;
149 roc_npc->channel = nix->rx_chan_base;
150 roc_npc->pf_func = (&nix->dev)->pf_func;
151 npc->channel = roc_npc->channel;
152 npc->pf_func = roc_npc->pf_func;
153 npc->flow_max_priority = roc_npc->flow_max_priority;
154 npc->switch_header_type = roc_npc->switch_header_type;
155 npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
157 if (npc->mbox == NULL)
158 return NPC_ERR_PARAM;
160 rc = npc_mcam_fetch_kex_cfg(npc);
164 roc_npc->kex_capability = npc_get_kex_capability(npc);
165 roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
167 npc->mark_actions = 0;
169 npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
171 /* Free, free_rev, live and live_rev entries */
172 bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
173 mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
175 plt_err("Bmap alloc failed");
180 sz = npc->flow_max_priority * sizeof(struct npc_mcam_ents_info);
181 npc->flow_entry_info = plt_zmalloc(sz, 0);
182 if (npc->flow_entry_info == NULL) {
183 plt_err("flow_entry_info alloc failed");
188 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
189 npc->free_entries = plt_zmalloc(sz, 0);
190 if (npc->free_entries == NULL) {
191 plt_err("free_entries alloc failed");
196 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
197 npc->free_entries_rev = plt_zmalloc(sz, 0);
198 if (npc->free_entries_rev == NULL) {
199 plt_err("free_entries_rev alloc failed");
204 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
205 npc->live_entries = plt_zmalloc(sz, 0);
206 if (npc->live_entries == NULL) {
207 plt_err("live_entries alloc failed");
212 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
213 npc->live_entries_rev = plt_zmalloc(sz, 0);
214 if (npc->live_entries_rev == NULL) {
215 plt_err("live_entries_rev alloc failed");
220 sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
221 npc->flow_list = plt_zmalloc(sz, 0);
222 if (npc->flow_list == NULL) {
223 plt_err("flow_list alloc failed");
229 for (idx = 0; idx < npc->flow_max_priority; idx++) {
230 TAILQ_INIT(&npc->flow_list[idx]);
232 npc->free_entries[idx] =
233 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
236 npc->free_entries_rev[idx] =
237 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
240 npc->live_entries[idx] =
241 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
244 npc->live_entries_rev[idx] =
245 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
248 npc->flow_entry_info[idx].free_ent = 0;
249 npc->flow_entry_info[idx].live_ent = 0;
250 npc->flow_entry_info[idx].max_id = 0;
251 npc->flow_entry_info[idx].min_id = ~(0);
254 npc->rss_grps = NPC_RSS_GRPS;
256 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
257 nix_mem = plt_zmalloc(bmap_sz, 0);
258 if (nix_mem == NULL) {
259 plt_err("Bmap alloc failed");
264 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
266 if (!npc->rss_grp_entries) {
267 plt_err("bitmap init failed");
272 /* Group 0 will be used for RSS,
273 * 1 -7 will be used for npc_flow RSS action
275 plt_bitmap_set(npc->rss_grp_entries, 0);
281 plt_free(npc->flow_list);
282 if (npc->live_entries_rev)
283 plt_free(npc->live_entries_rev);
284 if (npc->live_entries)
285 plt_free(npc->live_entries);
286 if (npc->free_entries_rev)
287 plt_free(npc->free_entries_rev);
288 if (npc->free_entries)
289 plt_free(npc->free_entries);
290 if (npc->flow_entry_info)
291 plt_free(npc->flow_entry_info);
298 roc_npc_fini(struct roc_npc *roc_npc)
300 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
303 rc = npc_flow_free_all_resources(npc);
305 plt_err("Error when deleting NPC MCAM entries, counters");
309 if (npc->flow_list) {
310 plt_free(npc->flow_list);
311 npc->flow_list = NULL;
314 if (npc->live_entries_rev) {
315 plt_free(npc->live_entries_rev);
316 npc->live_entries_rev = NULL;
319 if (npc->live_entries) {
320 plt_free(npc->live_entries);
321 npc->live_entries = NULL;
324 if (npc->free_entries_rev) {
325 plt_free(npc->free_entries_rev);
326 npc->free_entries_rev = NULL;
329 if (npc->free_entries) {
330 plt_free(npc->free_entries);
331 npc->free_entries = NULL;
334 if (npc->flow_entry_info) {
335 plt_free(npc->flow_entry_info);
336 npc->flow_entry_info = NULL;
343 npc_parse_actions(struct npc *npc, const struct roc_npc_attr *attr,
344 const struct roc_npc_action actions[],
345 struct roc_npc_flow *flow)
347 const struct roc_npc_action_mark *act_mark;
348 const struct roc_npc_action_queue *act_q;
349 const struct roc_npc_action_vf *vf_act;
350 bool vlan_insert_action = false;
351 int sel_act, req_act = 0;
352 uint16_t pf_func, vf_id;
357 /* Initialize actions */
358 flow->ctr_id = NPC_COUNTER_NONE;
359 pf_func = npc->pf_func;
361 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
362 switch (actions->type) {
363 case ROC_NPC_ACTION_TYPE_VOID:
365 case ROC_NPC_ACTION_TYPE_MARK:
366 act_mark = (const struct roc_npc_action_mark *)
368 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
369 plt_err("mark value must be < 0xfffe");
372 mark = act_mark->id + 1;
373 req_act |= ROC_NPC_ACTION_TYPE_MARK;
374 npc->mark_actions += 1;
377 case ROC_NPC_ACTION_TYPE_FLAG:
378 mark = NPC_FLOW_FLAG_VAL;
379 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
380 npc->mark_actions += 1;
383 case ROC_NPC_ACTION_TYPE_COUNT:
384 /* Indicates, need a counter */
386 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
389 case ROC_NPC_ACTION_TYPE_DROP:
390 req_act |= ROC_NPC_ACTION_TYPE_DROP;
393 case ROC_NPC_ACTION_TYPE_PF:
394 req_act |= ROC_NPC_ACTION_TYPE_PF;
398 case ROC_NPC_ACTION_TYPE_VF:
400 (const struct roc_npc_action_vf *)actions->conf;
401 req_act |= ROC_NPC_ACTION_TYPE_VF;
402 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
404 pf_func = (pf_func | (vf_id + 1));
407 case ROC_NPC_ACTION_TYPE_QUEUE:
408 act_q = (const struct roc_npc_action_queue *)
411 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
414 case ROC_NPC_ACTION_TYPE_RSS:
415 req_act |= ROC_NPC_ACTION_TYPE_RSS;
418 case ROC_NPC_ACTION_TYPE_SEC:
419 /* Assumes user has already configured security
420 * session for this flow. Associated conf is
421 * opaque. When security is implemented,
422 * we need to verify that for specified security
425 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
426 * session_protocol ==
427 * NPC_SECURITY_PROTOCOL_IPSEC
429 * RSS is not supported with inline ipsec. Get the
430 * rq from associated conf, or make
431 * ROC_NPC_ACTION_TYPE_QUEUE compulsory with this
433 * Currently, rq = 0 is assumed.
435 req_act |= ROC_NPC_ACTION_TYPE_SEC;
438 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
439 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
441 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
442 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
444 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
445 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
447 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
448 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
451 errcode = NPC_ERR_ACTION_NOTSUP;
456 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
457 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
458 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
459 vlan_insert_action = true;
461 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
462 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
463 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
464 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
465 plt_err("PCP insert action can't be supported alone");
466 errcode = NPC_ERR_ACTION_NOTSUP;
470 /* Both STRIP and INSERT actions are not supported */
471 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
472 errcode = NPC_ERR_ACTION_NOTSUP;
476 /* Check if actions specified are compatible */
478 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
479 plt_err("VLAN pop action is not supported on Egress");
480 errcode = NPC_ERR_ACTION_NOTSUP;
485 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
486 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
487 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
488 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
489 plt_err("Only VLAN insert, drop, count supported on Egress");
490 errcode = NPC_ERR_ACTION_NOTSUP;
494 if (vlan_insert_action &&
495 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
496 plt_err("Both VLAN insert and drop actions cannot be supported");
497 errcode = NPC_ERR_ACTION_NOTSUP;
501 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
502 flow->npc_action = NIX_TX_ACTIONOP_DROP;
503 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
504 vlan_insert_action) {
505 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
507 plt_err("Unsupported action for egress");
508 errcode = NPC_ERR_ACTION_NOTSUP;
514 if (vlan_insert_action) {
515 errcode = NPC_ERR_ACTION_NOTSUP;
520 /* We have already verified the attr, this is ingress.
521 * - Exactly one terminating action is supported
522 * - Exactly one of MARK or FLAG is supported
523 * - If terminating action is DROP, only count is valid.
525 sel_act = req_act & NPC_ACTION_TERM;
526 if ((sel_act & (sel_act - 1)) != 0) {
527 errcode = NPC_ERR_ACTION_NOTSUP;
531 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
532 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
533 if ((sel_act & (sel_act - 1)) != 0) {
534 errcode = NPC_ERR_ACTION_NOTSUP;
539 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
540 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
541 errcode = NPC_ERR_ACTION_NOTSUP;
545 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
546 npc->vtag_strip_actions++;
548 /* Set NIX_RX_ACTIONOP */
549 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
550 /* Only VLAN action is provided */
551 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
553 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
554 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
555 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
556 flow->npc_action |= (uint64_t)rq << 20;
557 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
558 flow->npc_action = NIX_RX_ACTIONOP_DROP;
559 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
560 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
561 flow->npc_action |= (uint64_t)rq << 20;
562 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
563 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
564 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
565 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
566 flow->npc_action |= (uint64_t)rq << 20;
568 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
569 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
570 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
571 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
572 * This is default action, when user specify only
575 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
577 /* Should never reach here */
578 errcode = NPC_ERR_ACTION_NOTSUP;
583 flow->npc_action |= (uint64_t)mark << 40;
586 /* Ideally AF must ensure that correct pf_func is set */
587 flow->npc_action |= (uint64_t)pf_func << 4;
595 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
598 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
599 struct roc_npc_flow *flow, struct npc_parse_state *pst)
601 npc_parse_stage_func_t parse_stage_funcs[] = {
602 npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
603 npc_parse_la, npc_parse_lb, npc_parse_lc,
604 npc_parse_ld, npc_parse_le, npc_parse_lf,
605 npc_parse_lg, npc_parse_lh,
612 return NPC_ERR_PARAM;
614 memset(pst, 0, sizeof(*pst));
618 /* Use integral byte offset */
619 key_offset = pst->npc->keyx_len[flow->nix_intf];
620 key_offset = (key_offset + 7) / 8;
622 /* Location where LDATA would begin */
623 pst->mcam_data = (uint8_t *)flow->mcam_data;
624 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
626 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
627 layer < PLT_DIM(parse_stage_funcs)) {
628 /* Skip place-holders */
629 pattern = npc_parse_skip_void_and_any_items(pattern);
631 pst->pattern = pattern;
632 rc = parse_stage_funcs[layer](pst);
639 * Parse stage function sets pst->pattern to
640 * 1 past the last item it consumed.
642 pattern = pst->pattern;
648 /* Skip trailing place-holders */
649 pattern = npc_parse_skip_void_and_any_items(pattern);
651 /* Are there more items than what we can handle? */
652 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
653 return NPC_ERR_PATTERN_NOTSUP;
659 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
660 struct roc_npc_flow *flow)
663 return NPC_ERR_PARAM;
664 else if (attr->priority >= npc->flow_max_priority)
665 return NPC_ERR_PARAM;
666 else if ((!attr->egress && !attr->ingress) ||
667 (attr->egress && attr->ingress))
668 return NPC_ERR_PARAM;
671 flow->nix_intf = ROC_NPC_INTF_RX;
673 flow->nix_intf = ROC_NPC_INTF_TX;
675 flow->priority = attr->priority;
680 npc_parse_rule(struct npc *npc, const struct roc_npc_attr *attr,
681 const struct roc_npc_item_info pattern[],
682 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
683 struct npc_parse_state *pst)
688 err = npc_parse_attr(npc, attr, flow);
693 err = npc_parse_pattern(npc, pattern, flow, pst);
698 err = npc_parse_actions(npc, attr, actions, flow);
705 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
706 const struct roc_npc_item_info pattern[],
707 const struct roc_npc_action actions[],
708 struct roc_npc_flow *flow)
710 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
711 struct npc_parse_state parse_state = {0};
714 rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
718 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
720 return npc_program_mcam(npc, &parse_state, 0);
724 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
726 struct plt_bitmap *bmap = npc->rss_grp_entries;
728 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
729 if (!plt_bitmap_get(bmap, *pos))
732 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
736 npc_rss_action_configure(struct roc_npc *roc_npc,
737 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
738 uint32_t *rss_grp, uint32_t mcam_id)
740 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
741 struct roc_nix *roc_nix = roc_npc->roc_nix;
742 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
743 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
744 uint8_t key[ROC_NIX_RSS_KEY_LEN];
745 const uint8_t *key_ptr;
746 uint8_t flowkey_algx;
750 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
751 /* RSS group :0 is not usable for flow rss action */
752 if (rc < 0 || rss_grp_idx == 0)
755 for (i = 0; i < rss->queue_num; i++) {
756 if (rss->queue[i] >= nix->nb_rx_queues) {
757 plt_err("queue id > max number of queues");
762 *rss_grp = rss_grp_idx;
764 if (rss->key == NULL) {
765 roc_nix_rss_key_default_fill(roc_nix, key);
771 roc_nix_rss_key_set(roc_nix, key_ptr);
773 /* If queue count passed in the rss action is less than
774 * HW configured reta size, replicate rss action reta
775 * across HW reta table.
777 reta = nix->reta[rss_grp_idx];
779 if (rss->queue_num > nix->reta_sz) {
780 plt_err("too many queues for RSS context");
784 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
785 memcpy(reta + i * rss->queue_num, rss->queue,
786 sizeof(uint16_t) * rss->queue_num);
788 rem = nix->reta_sz % rss->queue_num;
790 memcpy(&reta[i * rss->queue_num], rss->queue,
791 rem * sizeof(uint16_t));
793 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
795 plt_err("Failed to init rss table rc = %d", rc);
799 flowkey_cfg = roc_npc->flowkey_cfg_state;
801 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
804 plt_err("Failed to set rss hash function rc = %d", rc);
808 *alg_idx = flowkey_algx;
810 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
816 npc_rss_action_program(struct roc_npc *roc_npc,
817 const struct roc_npc_action actions[],
818 struct roc_npc_flow *flow)
820 const struct roc_npc_action_rss *rss;
825 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
826 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
827 rss = (const struct roc_npc_action_rss *)actions->conf;
828 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
829 &rss_grp, flow->mcam_id);
833 flow->npc_action &= (~(0xfULL));
834 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
836 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
837 << NPC_RSS_ACT_ALG_OFFSET) |
838 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
839 << NPC_RSS_ACT_GRP_OFFSET);
847 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
849 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
851 return npc->mark_actions;
855 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
857 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
859 npc->mark_actions -= count;
860 return npc->mark_actions;
864 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
866 struct roc_nix *roc_nix = roc_npc->roc_nix;
867 struct nix_vtag_config *vtag_cfg;
868 struct nix_vtag_config_rsp *rsp;
875 struct nix_tx_vtag_action_s act;
878 nix = roc_nix_to_nix_priv(roc_nix);
879 mbox = (&nix->dev)->mbox;
881 tx_vtag_action.reg = flow->vtag_action;
882 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
884 if (vtag_cfg == NULL)
887 vtag_cfg->cfg_type = VTAG_TX;
888 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
889 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
890 vtag_cfg->tx.free_vtag0 = true;
892 if (flow->vtag_insert_count == 2) {
893 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
894 vtag_cfg->tx.free_vtag1 = true;
897 rc = mbox_process_msg(mbox, (void *)&rsp);
905 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
906 struct roc_npc_flow *flow,
907 struct npc_action_vtag_info *vlan_info,
910 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
915 /* This function parses parameters of one VLAN. When a parameter is
916 * found repeated, it treats it as the end of first VLAN's parameters
917 * and returns. The caller calls again to parse the parameters of the
921 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
922 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
926 const struct roc_npc_action_of_set_vlan_vid *vtag =
927 (const struct roc_npc_action_of_set_vlan_vid *)
930 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
932 if (vlan_info->vlan_id > 0xfff) {
933 plt_err("Invalid vlan_id for set vlan action");
937 flow->vtag_insert_enabled = true;
939 vlan_id_found = true;
940 } else if (actions->type ==
941 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
945 const struct roc_npc_action_of_push_vlan *ethtype =
946 (const struct roc_npc_action_of_push_vlan *)
948 vlan_info->vlan_ethtype =
949 plt_be_to_cpu_16(ethtype->ethertype);
950 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
951 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
952 plt_err("Invalid ethtype specified for push"
956 flow->vtag_insert_enabled = true;
958 ethtype_found = true;
959 } else if (actions->type ==
960 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
963 const struct roc_npc_action_of_set_vlan_pcp *pcp =
964 (const struct roc_npc_action_of_set_vlan_pcp *)
966 vlan_info->vlan_pcp = pcp->vlan_pcp;
967 if (vlan_info->vlan_pcp > 0x7) {
968 plt_err("Invalid PCP value for pcp action");
971 flow->vtag_insert_enabled = true;
983 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
984 struct npc_action_vtag_info *vlan_info)
986 struct nix_vtag_config *vtag_cfg;
987 struct nix_vtag_config_rsp *rsp;
992 struct nix_tx_vtag_action_s act;
995 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
997 if (vtag_cfg == NULL)
1000 vtag_cfg->cfg_type = VTAG_TX;
1001 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1002 vtag_cfg->tx.vtag0 =
1003 ((vlan_info[0].vlan_ethtype << 16) |
1004 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1006 vtag_cfg->tx.cfg_vtag0 = 1;
1008 if (flow->vtag_insert_count == 2) {
1009 vtag_cfg->tx.vtag1 =
1010 ((vlan_info[1].vlan_ethtype << 16) |
1011 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1013 vtag_cfg->tx.cfg_vtag1 = 1;
1016 rc = mbox_process_msg(mbox, (void *)&rsp);
1020 if (rsp->vtag0_idx < 0 ||
1021 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1022 plt_err("Failed to config TX VTAG action");
1026 tx_vtag_action.reg = 0;
1027 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1028 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1029 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1030 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1032 if (flow->vtag_insert_count == 2) {
1033 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1034 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1035 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1036 /* NIX_TX_VTAG_ACTION_S
1037 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1038 * offset accordingly. Thus, if the two offsets are equal in
1039 * the structure, hardware inserts Vtag 1 immediately after
1040 * Vtag 0 in the packet.
1042 tx_vtag_action.act.vtag1_relptr =
1043 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1046 flow->vtag_action = tx_vtag_action.reg;
1052 npc_vtag_strip_action_configure(struct mbox *mbox,
1053 const struct roc_npc_action actions[],
1054 struct roc_npc_flow *flow, int *strip_cnt)
1056 struct nix_vtag_config *vtag_cfg;
1057 uint64_t rx_vtag_action = 0;
1058 int count = 0, rc = 0;
1062 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1063 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1067 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1069 if (vtag_cfg == NULL)
1072 vtag_cfg->cfg_type = VTAG_RX;
1073 vtag_cfg->rx.strip_vtag = 1;
1074 /* Always capture */
1075 vtag_cfg->rx.capture_vtag = 1;
1076 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1077 vtag_cfg->rx.vtag_type = 0;
1079 rc = mbox_process(mbox);
1083 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1084 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1085 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1087 if (*strip_cnt == 2) {
1088 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1089 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1090 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1092 flow->vtag_action = rx_vtag_action;
1098 npc_vtag_action_program(struct roc_npc *roc_npc,
1099 const struct roc_npc_action actions[],
1100 struct roc_npc_flow *flow)
1102 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1103 const struct roc_npc_action *insert_actions;
1104 struct roc_nix *roc_nix = roc_npc->roc_nix;
1105 struct npc_action_vtag_info vlan_info[2];
1106 int parsed_cnt = 0, strip_cnt = 0;
1107 int tot_vlan_params = 0;
1112 nix = roc_nix_to_nix_priv(roc_nix);
1113 mbox = (&nix->dev)->mbox;
1115 memset(vlan_info, 0, sizeof(vlan_info));
1117 flow->vtag_insert_enabled = false;
1119 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1120 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1121 if (vlan_strip_parsed) {
1122 plt_err("Incorrect VLAN strip actions");
1125 rc = npc_vtag_strip_action_configure(mbox, actions,
1133 vlan_strip_parsed = true;
1134 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1136 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1138 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1139 if (vlan_insert_parsed) {
1140 plt_err("Incorrect VLAN insert actions");
1144 insert_actions = actions;
1146 for (i = 0; i < 2; i++) {
1147 rc = npc_vtag_insert_action_parse(
1148 insert_actions, flow, &vlan_info[i],
1155 insert_actions += parsed_cnt;
1156 tot_vlan_params += parsed_cnt;
1157 flow->vtag_insert_count++;
1160 actions += tot_vlan_params - 1;
1161 vlan_insert_parsed = true;
1165 if (flow->vtag_insert_enabled) {
1166 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1174 struct roc_npc_flow *
1175 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1176 const struct roc_npc_item_info pattern[],
1177 const struct roc_npc_action actions[], int *errcode)
1179 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1180 struct roc_npc_flow *flow, *flow_iter;
1181 struct npc_parse_state parse_state;
1182 struct npc_flow_list *list;
1185 npc->channel = roc_npc->channel;
1187 flow = plt_zmalloc(sizeof(*flow), 0);
1189 *errcode = NPC_ERR_NO_MEM;
1192 memset(flow, 0, sizeof(*flow));
1194 rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
1200 rc = npc_vtag_action_program(roc_npc, actions, flow);
1206 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1208 rc = npc_program_mcam(npc, &parse_state, 1);
1214 rc = npc_rss_action_program(roc_npc, actions, flow);
1217 goto set_rss_failed;
1220 list = &npc->flow_list[flow->priority];
1221 /* List in ascending order of mcam entries */
1222 TAILQ_FOREACH(flow_iter, list, next) {
1223 if (flow_iter->mcam_id > flow->mcam_id) {
1224 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1229 TAILQ_INSERT_TAIL(list, flow, next);
1233 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1245 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1249 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1250 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1251 NPC_RSS_ACT_GRP_MASK;
1252 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1255 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1262 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1264 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1265 struct plt_bitmap *bmap;
1268 rc = npc_rss_group_free(npc, flow);
1270 plt_err("Failed to free rss action rc = %d", rc);
1274 if (flow->vtag_insert_enabled) {
1275 rc = npc_vtag_cfg_delete(roc_npc, flow);
1280 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1284 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1286 bmap = npc->live_entries[flow->priority];
1287 plt_bitmap_clear(bmap, flow->mcam_id);
1294 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1296 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1297 struct roc_npc_flow *flow_iter;
1298 struct npc_flow_list *list;
1299 uint32_t max_prio, i;
1301 max_prio = npc->flow_max_priority;
1303 for (i = 0; i < max_prio; i++) {
1304 list = &npc->flow_list[i];
1306 /* List in ascending order of mcam entries */
1307 TAILQ_FOREACH(flow_iter, list, next) {
1308 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);