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);
111 else if (roc_model_is_cn98xx())
112 return (npc->mcam_entries - NPC_MCAME_RESVD_98XX - 1);
114 return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
118 npc_mcam_tot_entries(void)
120 /* FIXME: change to reading in AF from NPC_AF_CONST1/2
121 * MCAM_BANK_DEPTH(_EXT) * MCAM_BANKS
123 if (roc_model_is_cn10k() || roc_model_is_cn98xx())
124 return 16 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 4096 */
126 return 4 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 1024 */
130 roc_npc_profile_name_get(struct roc_npc *roc_npc)
132 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
134 return (char *)npc->profile_name;
138 roc_npc_init(struct roc_npc *roc_npc)
140 uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
141 struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
142 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
147 PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
149 memset(npc, 0, sizeof(*npc));
150 npc->mbox = (&nix->dev)->mbox;
151 roc_npc->channel = nix->rx_chan_base;
152 roc_npc->pf_func = (&nix->dev)->pf_func;
153 npc->channel = roc_npc->channel;
154 npc->pf_func = roc_npc->pf_func;
155 npc->flow_max_priority = roc_npc->flow_max_priority;
156 npc->switch_header_type = roc_npc->switch_header_type;
157 npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
159 if (npc->mbox == NULL)
160 return NPC_ERR_PARAM;
162 rc = npc_mcam_fetch_kex_cfg(npc);
166 roc_npc->kex_capability = npc_get_kex_capability(npc);
167 roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
169 npc->mark_actions = 0;
171 npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
173 /* Free, free_rev, live and live_rev entries */
174 bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
175 mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
177 plt_err("Bmap alloc failed");
182 sz = npc->flow_max_priority * sizeof(struct npc_mcam_ents_info);
183 npc->flow_entry_info = plt_zmalloc(sz, 0);
184 if (npc->flow_entry_info == NULL) {
185 plt_err("flow_entry_info alloc failed");
190 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
191 npc->free_entries = plt_zmalloc(sz, 0);
192 if (npc->free_entries == NULL) {
193 plt_err("free_entries alloc failed");
198 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
199 npc->free_entries_rev = plt_zmalloc(sz, 0);
200 if (npc->free_entries_rev == NULL) {
201 plt_err("free_entries_rev alloc failed");
206 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
207 npc->live_entries = plt_zmalloc(sz, 0);
208 if (npc->live_entries == NULL) {
209 plt_err("live_entries alloc failed");
214 sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
215 npc->live_entries_rev = plt_zmalloc(sz, 0);
216 if (npc->live_entries_rev == NULL) {
217 plt_err("live_entries_rev alloc failed");
222 sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
223 npc->flow_list = plt_zmalloc(sz, 0);
224 if (npc->flow_list == NULL) {
225 plt_err("flow_list alloc failed");
231 for (idx = 0; idx < npc->flow_max_priority; idx++) {
232 TAILQ_INIT(&npc->flow_list[idx]);
234 npc->free_entries[idx] =
235 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
238 npc->free_entries_rev[idx] =
239 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
242 npc->live_entries[idx] =
243 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
246 npc->live_entries_rev[idx] =
247 plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
250 npc->flow_entry_info[idx].free_ent = 0;
251 npc->flow_entry_info[idx].live_ent = 0;
252 npc->flow_entry_info[idx].max_id = 0;
253 npc->flow_entry_info[idx].min_id = ~(0);
256 npc->rss_grps = NPC_RSS_GRPS;
258 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
259 nix_mem = plt_zmalloc(bmap_sz, 0);
260 if (nix_mem == NULL) {
261 plt_err("Bmap alloc failed");
266 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
268 if (!npc->rss_grp_entries) {
269 plt_err("bitmap init failed");
274 /* Group 0 will be used for RSS,
275 * 1 -7 will be used for npc_flow RSS action
277 plt_bitmap_set(npc->rss_grp_entries, 0);
283 plt_free(npc->flow_list);
284 if (npc->live_entries_rev)
285 plt_free(npc->live_entries_rev);
286 if (npc->live_entries)
287 plt_free(npc->live_entries);
288 if (npc->free_entries_rev)
289 plt_free(npc->free_entries_rev);
290 if (npc->free_entries)
291 plt_free(npc->free_entries);
292 if (npc->flow_entry_info)
293 plt_free(npc->flow_entry_info);
300 roc_npc_fini(struct roc_npc *roc_npc)
302 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
305 rc = npc_flow_free_all_resources(npc);
307 plt_err("Error when deleting NPC MCAM entries, counters");
311 if (npc->flow_list) {
312 plt_free(npc->flow_list);
313 npc->flow_list = NULL;
316 if (npc->live_entries_rev) {
317 plt_free(npc->live_entries_rev);
318 npc->live_entries_rev = NULL;
321 if (npc->live_entries) {
322 plt_free(npc->live_entries);
323 npc->live_entries = NULL;
326 if (npc->free_entries_rev) {
327 plt_free(npc->free_entries_rev);
328 npc->free_entries_rev = NULL;
331 if (npc->free_entries) {
332 plt_free(npc->free_entries);
333 npc->free_entries = NULL;
336 if (npc->flow_entry_info) {
337 plt_free(npc->flow_entry_info);
338 npc->flow_entry_info = NULL;
345 npc_parse_actions(struct npc *npc, const struct roc_npc_attr *attr,
346 const struct roc_npc_action actions[],
347 struct roc_npc_flow *flow)
349 const struct roc_npc_action_mark *act_mark;
350 const struct roc_npc_action_queue *act_q;
351 const struct roc_npc_action_vf *vf_act;
352 bool vlan_insert_action = false;
353 int sel_act, req_act = 0;
354 uint16_t pf_func, vf_id;
359 /* Initialize actions */
360 flow->ctr_id = NPC_COUNTER_NONE;
361 pf_func = npc->pf_func;
363 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
364 switch (actions->type) {
365 case ROC_NPC_ACTION_TYPE_VOID:
367 case ROC_NPC_ACTION_TYPE_MARK:
368 act_mark = (const struct roc_npc_action_mark *)
370 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
371 plt_err("mark value must be < 0xfffe");
374 mark = act_mark->id + 1;
375 req_act |= ROC_NPC_ACTION_TYPE_MARK;
376 npc->mark_actions += 1;
379 case ROC_NPC_ACTION_TYPE_FLAG:
380 mark = NPC_FLOW_FLAG_VAL;
381 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
382 npc->mark_actions += 1;
385 case ROC_NPC_ACTION_TYPE_COUNT:
386 /* Indicates, need a counter */
388 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
391 case ROC_NPC_ACTION_TYPE_DROP:
392 req_act |= ROC_NPC_ACTION_TYPE_DROP;
395 case ROC_NPC_ACTION_TYPE_PF:
396 req_act |= ROC_NPC_ACTION_TYPE_PF;
400 case ROC_NPC_ACTION_TYPE_VF:
402 (const struct roc_npc_action_vf *)actions->conf;
403 req_act |= ROC_NPC_ACTION_TYPE_VF;
404 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
406 pf_func = (pf_func | (vf_id + 1));
409 case ROC_NPC_ACTION_TYPE_QUEUE:
410 act_q = (const struct roc_npc_action_queue *)
413 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
416 case ROC_NPC_ACTION_TYPE_RSS:
417 req_act |= ROC_NPC_ACTION_TYPE_RSS;
420 case ROC_NPC_ACTION_TYPE_SEC:
421 /* Assumes user has already configured security
422 * session for this flow. Associated conf is
423 * opaque. When security is implemented,
424 * we need to verify that for specified security
427 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
428 * session_protocol ==
429 * NPC_SECURITY_PROTOCOL_IPSEC
431 * RSS is not supported with inline ipsec. Get the
432 * rq from associated conf, or make
433 * ROC_NPC_ACTION_TYPE_QUEUE compulsory with this
435 * Currently, rq = 0 is assumed.
437 req_act |= ROC_NPC_ACTION_TYPE_SEC;
440 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
441 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
443 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
444 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
446 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
447 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
449 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
450 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
453 errcode = NPC_ERR_ACTION_NOTSUP;
458 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
459 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
460 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
461 vlan_insert_action = true;
463 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
464 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
465 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
466 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
467 plt_err("PCP insert action can't be supported alone");
468 errcode = NPC_ERR_ACTION_NOTSUP;
472 /* Both STRIP and INSERT actions are not supported */
473 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
474 errcode = NPC_ERR_ACTION_NOTSUP;
478 /* Check if actions specified are compatible */
480 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
481 plt_err("VLAN pop action is not supported on Egress");
482 errcode = NPC_ERR_ACTION_NOTSUP;
487 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
488 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
489 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
490 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
491 plt_err("Only VLAN insert, drop, count supported on Egress");
492 errcode = NPC_ERR_ACTION_NOTSUP;
496 if (vlan_insert_action &&
497 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
498 plt_err("Both VLAN insert and drop actions cannot be supported");
499 errcode = NPC_ERR_ACTION_NOTSUP;
503 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
504 flow->npc_action = NIX_TX_ACTIONOP_DROP;
505 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
506 vlan_insert_action) {
507 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
509 plt_err("Unsupported action for egress");
510 errcode = NPC_ERR_ACTION_NOTSUP;
516 if (vlan_insert_action) {
517 errcode = NPC_ERR_ACTION_NOTSUP;
522 /* We have already verified the attr, this is ingress.
523 * - Exactly one terminating action is supported
524 * - Exactly one of MARK or FLAG is supported
525 * - If terminating action is DROP, only count is valid.
527 sel_act = req_act & NPC_ACTION_TERM;
528 if ((sel_act & (sel_act - 1)) != 0) {
529 errcode = NPC_ERR_ACTION_NOTSUP;
533 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
534 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
535 if ((sel_act & (sel_act - 1)) != 0) {
536 errcode = NPC_ERR_ACTION_NOTSUP;
541 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
542 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
543 errcode = NPC_ERR_ACTION_NOTSUP;
547 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
548 npc->vtag_strip_actions++;
550 /* Set NIX_RX_ACTIONOP */
551 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
552 /* Only VLAN action is provided */
553 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
555 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
556 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
557 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
558 flow->npc_action |= (uint64_t)rq << 20;
559 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
560 flow->npc_action = NIX_RX_ACTIONOP_DROP;
561 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
562 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
563 flow->npc_action |= (uint64_t)rq << 20;
564 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
565 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
566 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
567 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
568 flow->npc_action |= (uint64_t)rq << 20;
570 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
571 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
572 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
573 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
574 * This is default action, when user specify only
577 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
579 /* Should never reach here */
580 errcode = NPC_ERR_ACTION_NOTSUP;
585 flow->npc_action |= (uint64_t)mark << 40;
588 /* Ideally AF must ensure that correct pf_func is set */
589 flow->npc_action |= (uint64_t)pf_func << 4;
597 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
600 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
601 struct roc_npc_flow *flow, struct npc_parse_state *pst)
603 npc_parse_stage_func_t parse_stage_funcs[] = {
604 npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
605 npc_parse_la, npc_parse_lb, npc_parse_lc,
606 npc_parse_ld, npc_parse_le, npc_parse_lf,
607 npc_parse_lg, npc_parse_lh,
614 return NPC_ERR_PARAM;
616 memset(pst, 0, sizeof(*pst));
620 /* Use integral byte offset */
621 key_offset = pst->npc->keyx_len[flow->nix_intf];
622 key_offset = (key_offset + 7) / 8;
624 /* Location where LDATA would begin */
625 pst->mcam_data = (uint8_t *)flow->mcam_data;
626 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
628 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
629 layer < PLT_DIM(parse_stage_funcs)) {
630 /* Skip place-holders */
631 pattern = npc_parse_skip_void_and_any_items(pattern);
633 pst->pattern = pattern;
634 rc = parse_stage_funcs[layer](pst);
641 * Parse stage function sets pst->pattern to
642 * 1 past the last item it consumed.
644 pattern = pst->pattern;
650 /* Skip trailing place-holders */
651 pattern = npc_parse_skip_void_and_any_items(pattern);
653 /* Are there more items than what we can handle? */
654 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
655 return NPC_ERR_PATTERN_NOTSUP;
661 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
662 struct roc_npc_flow *flow)
665 return NPC_ERR_PARAM;
666 else if (attr->priority >= npc->flow_max_priority)
667 return NPC_ERR_PARAM;
668 else if ((!attr->egress && !attr->ingress) ||
669 (attr->egress && attr->ingress))
670 return NPC_ERR_PARAM;
673 flow->nix_intf = ROC_NPC_INTF_RX;
675 flow->nix_intf = ROC_NPC_INTF_TX;
677 flow->priority = attr->priority;
682 npc_parse_rule(struct npc *npc, const struct roc_npc_attr *attr,
683 const struct roc_npc_item_info pattern[],
684 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
685 struct npc_parse_state *pst)
690 err = npc_parse_attr(npc, attr, flow);
695 err = npc_parse_pattern(npc, pattern, flow, pst);
700 err = npc_parse_actions(npc, attr, actions, flow);
707 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
708 const struct roc_npc_item_info pattern[],
709 const struct roc_npc_action actions[],
710 struct roc_npc_flow *flow)
712 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
713 struct npc_parse_state parse_state = {0};
716 rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
720 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
722 return npc_program_mcam(npc, &parse_state, 0);
726 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
728 struct plt_bitmap *bmap = npc->rss_grp_entries;
730 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
731 if (!plt_bitmap_get(bmap, *pos))
734 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
738 npc_rss_action_configure(struct roc_npc *roc_npc,
739 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
740 uint32_t *rss_grp, uint32_t mcam_id)
742 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
743 struct roc_nix *roc_nix = roc_npc->roc_nix;
744 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
745 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
746 uint8_t key[ROC_NIX_RSS_KEY_LEN];
747 const uint8_t *key_ptr;
748 uint8_t flowkey_algx;
752 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
753 /* RSS group :0 is not usable for flow rss action */
754 if (rc < 0 || rss_grp_idx == 0)
757 for (i = 0; i < rss->queue_num; i++) {
758 if (rss->queue[i] >= nix->nb_rx_queues) {
759 plt_err("queue id > max number of queues");
764 *rss_grp = rss_grp_idx;
766 if (rss->key == NULL) {
767 roc_nix_rss_key_default_fill(roc_nix, key);
773 roc_nix_rss_key_set(roc_nix, key_ptr);
775 /* If queue count passed in the rss action is less than
776 * HW configured reta size, replicate rss action reta
777 * across HW reta table.
779 reta = nix->reta[rss_grp_idx];
781 if (rss->queue_num > nix->reta_sz) {
782 plt_err("too many queues for RSS context");
786 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
787 memcpy(reta + i * rss->queue_num, rss->queue,
788 sizeof(uint16_t) * rss->queue_num);
790 rem = nix->reta_sz % rss->queue_num;
792 memcpy(&reta[i * rss->queue_num], rss->queue,
793 rem * sizeof(uint16_t));
795 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
797 plt_err("Failed to init rss table rc = %d", rc);
801 flowkey_cfg = roc_npc->flowkey_cfg_state;
803 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
806 plt_err("Failed to set rss hash function rc = %d", rc);
810 *alg_idx = flowkey_algx;
812 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
818 npc_rss_action_program(struct roc_npc *roc_npc,
819 const struct roc_npc_action actions[],
820 struct roc_npc_flow *flow)
822 const struct roc_npc_action_rss *rss;
827 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
828 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
829 rss = (const struct roc_npc_action_rss *)actions->conf;
830 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
831 &rss_grp, flow->mcam_id);
835 flow->npc_action &= (~(0xfULL));
836 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
838 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
839 << NPC_RSS_ACT_ALG_OFFSET) |
840 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
841 << NPC_RSS_ACT_GRP_OFFSET);
849 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
851 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
853 return npc->mark_actions;
857 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
859 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
861 npc->mark_actions -= count;
862 return npc->mark_actions;
866 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
868 struct roc_nix *roc_nix = roc_npc->roc_nix;
869 struct nix_vtag_config *vtag_cfg;
870 struct nix_vtag_config_rsp *rsp;
877 struct nix_tx_vtag_action_s act;
880 nix = roc_nix_to_nix_priv(roc_nix);
881 mbox = (&nix->dev)->mbox;
883 tx_vtag_action.reg = flow->vtag_action;
884 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
886 if (vtag_cfg == NULL)
889 vtag_cfg->cfg_type = VTAG_TX;
890 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
891 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
892 vtag_cfg->tx.free_vtag0 = true;
894 if (flow->vtag_insert_count == 2) {
895 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
896 vtag_cfg->tx.free_vtag1 = true;
899 rc = mbox_process_msg(mbox, (void *)&rsp);
907 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
908 struct roc_npc_flow *flow,
909 struct npc_action_vtag_info *vlan_info,
912 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
917 /* This function parses parameters of one VLAN. When a parameter is
918 * found repeated, it treats it as the end of first VLAN's parameters
919 * and returns. The caller calls again to parse the parameters of the
923 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
924 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
928 const struct roc_npc_action_of_set_vlan_vid *vtag =
929 (const struct roc_npc_action_of_set_vlan_vid *)
932 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
934 if (vlan_info->vlan_id > 0xfff) {
935 plt_err("Invalid vlan_id for set vlan action");
939 flow->vtag_insert_enabled = true;
941 vlan_id_found = true;
942 } else if (actions->type ==
943 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
947 const struct roc_npc_action_of_push_vlan *ethtype =
948 (const struct roc_npc_action_of_push_vlan *)
950 vlan_info->vlan_ethtype =
951 plt_be_to_cpu_16(ethtype->ethertype);
952 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
953 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
954 plt_err("Invalid ethtype specified for push"
958 flow->vtag_insert_enabled = true;
960 ethtype_found = true;
961 } else if (actions->type ==
962 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
965 const struct roc_npc_action_of_set_vlan_pcp *pcp =
966 (const struct roc_npc_action_of_set_vlan_pcp *)
968 vlan_info->vlan_pcp = pcp->vlan_pcp;
969 if (vlan_info->vlan_pcp > 0x7) {
970 plt_err("Invalid PCP value for pcp action");
973 flow->vtag_insert_enabled = true;
985 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
986 struct npc_action_vtag_info *vlan_info)
988 struct nix_vtag_config *vtag_cfg;
989 struct nix_vtag_config_rsp *rsp;
994 struct nix_tx_vtag_action_s act;
997 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
999 if (vtag_cfg == NULL)
1002 vtag_cfg->cfg_type = VTAG_TX;
1003 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1004 vtag_cfg->tx.vtag0 =
1005 ((vlan_info[0].vlan_ethtype << 16) |
1006 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1008 vtag_cfg->tx.cfg_vtag0 = 1;
1010 if (flow->vtag_insert_count == 2) {
1011 vtag_cfg->tx.vtag1 =
1012 ((vlan_info[1].vlan_ethtype << 16) |
1013 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1015 vtag_cfg->tx.cfg_vtag1 = 1;
1018 rc = mbox_process_msg(mbox, (void *)&rsp);
1022 if (rsp->vtag0_idx < 0 ||
1023 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1024 plt_err("Failed to config TX VTAG action");
1028 tx_vtag_action.reg = 0;
1029 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1030 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1031 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1032 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1034 if (flow->vtag_insert_count == 2) {
1035 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1036 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1037 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1038 /* NIX_TX_VTAG_ACTION_S
1039 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1040 * offset accordingly. Thus, if the two offsets are equal in
1041 * the structure, hardware inserts Vtag 1 immediately after
1042 * Vtag 0 in the packet.
1044 tx_vtag_action.act.vtag1_relptr =
1045 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1048 flow->vtag_action = tx_vtag_action.reg;
1054 npc_vtag_strip_action_configure(struct mbox *mbox,
1055 const struct roc_npc_action actions[],
1056 struct roc_npc_flow *flow, int *strip_cnt)
1058 struct nix_vtag_config *vtag_cfg;
1059 uint64_t rx_vtag_action = 0;
1060 int count = 0, rc = 0;
1064 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1065 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1069 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1071 if (vtag_cfg == NULL)
1074 vtag_cfg->cfg_type = VTAG_RX;
1075 vtag_cfg->rx.strip_vtag = 1;
1076 /* Always capture */
1077 vtag_cfg->rx.capture_vtag = 1;
1078 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1079 vtag_cfg->rx.vtag_type = 0;
1081 rc = mbox_process(mbox);
1085 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1086 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1087 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1089 if (*strip_cnt == 2) {
1090 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1091 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1092 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1094 flow->vtag_action = rx_vtag_action;
1100 npc_vtag_action_program(struct roc_npc *roc_npc,
1101 const struct roc_npc_action actions[],
1102 struct roc_npc_flow *flow)
1104 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1105 const struct roc_npc_action *insert_actions;
1106 struct roc_nix *roc_nix = roc_npc->roc_nix;
1107 struct npc_action_vtag_info vlan_info[2];
1108 int parsed_cnt = 0, strip_cnt = 0;
1109 int tot_vlan_params = 0;
1114 nix = roc_nix_to_nix_priv(roc_nix);
1115 mbox = (&nix->dev)->mbox;
1117 memset(vlan_info, 0, sizeof(vlan_info));
1119 flow->vtag_insert_enabled = false;
1121 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1122 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1123 if (vlan_strip_parsed) {
1124 plt_err("Incorrect VLAN strip actions");
1127 rc = npc_vtag_strip_action_configure(mbox, actions,
1135 vlan_strip_parsed = true;
1136 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1138 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1140 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1141 if (vlan_insert_parsed) {
1142 plt_err("Incorrect VLAN insert actions");
1146 insert_actions = actions;
1148 for (i = 0; i < 2; i++) {
1149 rc = npc_vtag_insert_action_parse(
1150 insert_actions, flow, &vlan_info[i],
1157 insert_actions += parsed_cnt;
1158 tot_vlan_params += parsed_cnt;
1159 flow->vtag_insert_count++;
1162 actions += tot_vlan_params - 1;
1163 vlan_insert_parsed = true;
1167 if (flow->vtag_insert_enabled) {
1168 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1176 struct roc_npc_flow *
1177 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1178 const struct roc_npc_item_info pattern[],
1179 const struct roc_npc_action actions[], int *errcode)
1181 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1182 struct roc_npc_flow *flow, *flow_iter;
1183 struct npc_parse_state parse_state;
1184 struct npc_flow_list *list;
1187 npc->channel = roc_npc->channel;
1189 flow = plt_zmalloc(sizeof(*flow), 0);
1191 *errcode = NPC_ERR_NO_MEM;
1194 memset(flow, 0, sizeof(*flow));
1196 rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
1202 rc = npc_vtag_action_program(roc_npc, actions, flow);
1208 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1210 rc = npc_program_mcam(npc, &parse_state, 1);
1216 rc = npc_rss_action_program(roc_npc, actions, flow);
1219 goto set_rss_failed;
1222 list = &npc->flow_list[flow->priority];
1223 /* List in ascending order of mcam entries */
1224 TAILQ_FOREACH(flow_iter, list, next) {
1225 if (flow_iter->mcam_id > flow->mcam_id) {
1226 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1231 TAILQ_INSERT_TAIL(list, flow, next);
1235 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1247 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1251 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1252 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1253 NPC_RSS_ACT_GRP_MASK;
1254 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1257 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1264 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1266 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1267 struct plt_bitmap *bmap;
1270 rc = npc_rss_group_free(npc, flow);
1272 plt_err("Failed to free rss action rc = %d", rc);
1276 if (flow->vtag_insert_enabled) {
1277 rc = npc_vtag_cfg_delete(roc_npc, flow);
1282 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1286 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1288 bmap = npc->live_entries[flow->priority];
1289 plt_bitmap_clear(bmap, flow->mcam_id);
1296 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1298 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1299 struct roc_npc_flow *flow_iter;
1300 struct npc_flow_list *list;
1301 uint32_t max_prio, i;
1303 max_prio = npc->flow_max_priority;
1305 for (i = 0; i < max_prio; i++) {
1306 list = &npc->flow_list[i];
1308 /* List in ascending order of mcam entries */
1309 TAILQ_FOREACH(flow_iter, list, next) {
1310 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);