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_enable_all_entries(struct roc_npc *roc_npc, bool enable)
80 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
82 return npc_flow_enable_all_entries(npc, enable);
86 roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
87 struct roc_npc_flow *ref_mcam, int prio,
90 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
92 return npc_mcam_alloc_entry(npc, mcam, ref_mcam, prio, resp_count);
96 roc_npc_mcam_ena_dis_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_ena_dis_entry(npc, mcam, enable);
105 roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
107 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
109 return npc_mcam_write_entry(npc, mcam);
113 roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc)
115 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
117 if (roc_model_is_cn10k())
118 return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
119 else if (roc_model_is_cn98xx())
120 return (npc->mcam_entries - NPC_MCAME_RESVD_98XX - 1);
122 return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
126 npc_mcam_tot_entries(void)
128 /* FIXME: change to reading in AF from NPC_AF_CONST1/2
129 * MCAM_BANK_DEPTH(_EXT) * MCAM_BANKS
131 if (roc_model_is_cn10k() || roc_model_is_cn98xx())
132 return 16 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 4096 */
134 return 4 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 1024 */
138 roc_npc_profile_name_get(struct roc_npc *roc_npc)
140 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
142 return (char *)npc->profile_name;
146 roc_npc_init(struct roc_npc *roc_npc)
148 uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
149 struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
150 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
155 PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
157 memset(npc, 0, sizeof(*npc));
158 npc->mbox = (&nix->dev)->mbox;
159 roc_npc->channel = nix->rx_chan_base;
160 roc_npc->pf_func = (&nix->dev)->pf_func;
161 npc->channel = roc_npc->channel;
162 npc->pf_func = roc_npc->pf_func;
163 npc->flow_max_priority = roc_npc->flow_max_priority;
164 npc->switch_header_type = roc_npc->switch_header_type;
165 npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
167 if (npc->mbox == NULL)
168 return NPC_ERR_PARAM;
170 rc = npc_mcam_fetch_kex_cfg(npc);
174 roc_npc->kex_capability = npc_get_kex_capability(npc);
175 roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
177 npc->mark_actions = 0;
179 npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
181 /* Free, free_rev, live and live_rev entries */
182 bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
183 mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
185 plt_err("Bmap alloc failed");
190 sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
191 npc->flow_list = plt_zmalloc(sz, 0);
192 if (npc->flow_list == NULL) {
193 plt_err("flow_list alloc failed");
198 sz = npc->flow_max_priority * sizeof(struct npc_prio_flow_list_head);
199 npc->prio_flow_list = plt_zmalloc(sz, 0);
200 if (npc->prio_flow_list == NULL) {
201 plt_err("prio_flow_list alloc failed");
207 for (idx = 0; idx < npc->flow_max_priority; idx++) {
208 TAILQ_INIT(&npc->flow_list[idx]);
209 TAILQ_INIT(&npc->prio_flow_list[idx]);
212 npc->rss_grps = NPC_RSS_GRPS;
214 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
215 nix_mem = plt_zmalloc(bmap_sz, 0);
216 if (nix_mem == NULL) {
217 plt_err("Bmap alloc failed");
222 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
224 if (!npc->rss_grp_entries) {
225 plt_err("bitmap init failed");
230 /* Group 0 will be used for RSS,
231 * 1 -7 will be used for npc_flow RSS action
233 plt_bitmap_set(npc->rss_grp_entries, 0);
239 plt_free(npc->flow_list);
240 if (npc->prio_flow_list)
241 plt_free(npc->prio_flow_list);
248 roc_npc_fini(struct roc_npc *roc_npc)
250 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
253 rc = npc_flow_free_all_resources(npc);
255 plt_err("Error when deleting NPC MCAM entries, counters");
259 if (npc->flow_list) {
260 plt_free(npc->flow_list);
261 npc->flow_list = NULL;
264 if (npc->prio_flow_list) {
265 plt_free(npc->prio_flow_list);
266 npc->prio_flow_list = NULL;
273 roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
274 struct roc_npc *roc_npc_dst)
276 struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
277 struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
278 struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
279 struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
281 if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
282 plt_err("Output port should be VF");
286 if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
287 plt_err("Invalid VF for output port");
291 if (nix_src->dev.pf != nix_dst->dev.pf) {
292 plt_err("Output port should be VF of ingress PF");
299 npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
300 const struct roc_npc_action actions[],
301 struct roc_npc_flow *flow)
303 const struct roc_npc_action_port_id *act_portid;
304 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
305 const struct roc_npc_action_mark *act_mark;
306 const struct roc_npc_action_meter *act_mtr;
307 const struct roc_npc_action_queue *act_q;
308 const struct roc_npc_action_vf *vf_act;
309 bool vlan_insert_action = false;
310 int sel_act, req_act = 0;
311 uint16_t pf_func, vf_id;
316 /* Initialize actions */
317 flow->ctr_id = NPC_COUNTER_NONE;
318 flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
319 pf_func = npc->pf_func;
321 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
322 switch (actions->type) {
323 case ROC_NPC_ACTION_TYPE_VOID:
325 case ROC_NPC_ACTION_TYPE_MARK:
326 act_mark = (const struct roc_npc_action_mark *)
328 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
329 plt_err("mark value must be < 0xfffe");
332 mark = act_mark->id + 1;
333 req_act |= ROC_NPC_ACTION_TYPE_MARK;
334 npc->mark_actions += 1;
337 case ROC_NPC_ACTION_TYPE_FLAG:
338 mark = NPC_FLOW_FLAG_VAL;
339 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
340 npc->mark_actions += 1;
343 case ROC_NPC_ACTION_TYPE_COUNT:
344 /* Indicates, need a counter */
346 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
349 case ROC_NPC_ACTION_TYPE_DROP:
350 req_act |= ROC_NPC_ACTION_TYPE_DROP;
353 case ROC_NPC_ACTION_TYPE_PF:
354 req_act |= ROC_NPC_ACTION_TYPE_PF;
358 case ROC_NPC_ACTION_TYPE_VF:
360 (const struct roc_npc_action_vf *)actions->conf;
361 req_act |= ROC_NPC_ACTION_TYPE_VF;
362 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
364 pf_func = (pf_func | (vf_id + 1));
367 case ROC_NPC_ACTION_TYPE_PORT_ID:
368 act_portid = (const struct roc_npc_action_port_id *)
371 pf_func = (pf_func | (act_portid->id + 1));
372 req_act |= ROC_NPC_ACTION_TYPE_VF;
375 case ROC_NPC_ACTION_TYPE_QUEUE:
376 act_q = (const struct roc_npc_action_queue *)
379 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
382 case ROC_NPC_ACTION_TYPE_RSS:
383 req_act |= ROC_NPC_ACTION_TYPE_RSS;
386 case ROC_NPC_ACTION_TYPE_SEC:
387 /* Assumes user has already configured security
388 * session for this flow. Associated conf is
389 * opaque. When security is implemented,
390 * we need to verify that for specified security
393 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
394 * session_protocol ==
395 * NPC_SECURITY_PROTOCOL_IPSEC
397 req_act |= ROC_NPC_ACTION_TYPE_SEC;
400 /* Special processing when with inline device */
401 if (roc_nix_inb_is_with_inl_dev(roc_npc->roc_nix) &&
402 roc_nix_inl_dev_is_probed()) {
404 pf_func = nix_inl_dev_pffunc_get();
407 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
408 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
410 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
411 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
413 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
414 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
416 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
417 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
419 case ROC_NPC_ACTION_TYPE_METER:
420 act_mtr = (const struct roc_npc_action_meter *)
422 flow->mtr_id = act_mtr->mtr_id;
423 req_act |= ROC_NPC_ACTION_TYPE_METER;
426 errcode = NPC_ERR_ACTION_NOTSUP;
431 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
432 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
433 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
434 vlan_insert_action = true;
436 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
437 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
438 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
439 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
440 plt_err("PCP insert action can't be supported alone");
441 errcode = NPC_ERR_ACTION_NOTSUP;
445 /* Both STRIP and INSERT actions are not supported */
446 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
447 errcode = NPC_ERR_ACTION_NOTSUP;
451 /* Check if actions specified are compatible */
453 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
454 plt_err("VLAN pop action is not supported on Egress");
455 errcode = NPC_ERR_ACTION_NOTSUP;
460 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
461 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
462 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
463 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
464 plt_err("Only VLAN insert, drop, count supported on Egress");
465 errcode = NPC_ERR_ACTION_NOTSUP;
469 if (vlan_insert_action &&
470 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
471 plt_err("Both VLAN insert and drop actions cannot be supported");
472 errcode = NPC_ERR_ACTION_NOTSUP;
476 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
477 flow->npc_action = NIX_TX_ACTIONOP_DROP;
478 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
479 vlan_insert_action) {
480 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
482 plt_err("Unsupported action for egress");
483 errcode = NPC_ERR_ACTION_NOTSUP;
489 if (vlan_insert_action) {
490 errcode = NPC_ERR_ACTION_NOTSUP;
495 /* We have already verified the attr, this is ingress.
496 * - Exactly one terminating action is supported
497 * - Exactly one of MARK or FLAG is supported
498 * - If terminating action is DROP, only count is valid.
500 sel_act = req_act & NPC_ACTION_TERM;
501 if ((sel_act & (sel_act - 1)) != 0) {
502 errcode = NPC_ERR_ACTION_NOTSUP;
506 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
507 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
508 if ((sel_act & (sel_act - 1)) != 0) {
509 errcode = NPC_ERR_ACTION_NOTSUP;
514 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
515 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
516 errcode = NPC_ERR_ACTION_NOTSUP;
520 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
521 npc->vtag_strip_actions++;
523 /* Set NIX_RX_ACTIONOP */
524 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
525 /* Only VLAN action is provided */
526 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
528 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
529 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
530 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
531 flow->npc_action |= (uint64_t)rq << 20;
532 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
533 flow->npc_action = NIX_RX_ACTIONOP_DROP;
534 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
535 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
536 flow->npc_action |= (uint64_t)rq << 20;
537 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
538 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
539 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
540 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
541 flow->npc_action |= (uint64_t)rq << 20;
543 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
544 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
545 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
546 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
547 * This is default action, when user specify only
550 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
552 /* Should never reach here */
553 errcode = NPC_ERR_ACTION_NOTSUP;
558 flow->npc_action |= (uint64_t)mark << 40;
561 /* Ideally AF must ensure that correct pf_func is set */
562 flow->npc_action |= (uint64_t)pf_func << 4;
570 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
573 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
574 struct roc_npc_flow *flow, struct npc_parse_state *pst)
576 npc_parse_stage_func_t parse_stage_funcs[] = {
577 npc_parse_meta_items, npc_parse_pre_l2, npc_parse_cpt_hdr,
578 npc_parse_higig2_hdr, npc_parse_la, npc_parse_lb,
579 npc_parse_lc, npc_parse_ld, npc_parse_le,
580 npc_parse_lf, npc_parse_lg, npc_parse_lh,
587 return NPC_ERR_PARAM;
589 memset(pst, 0, sizeof(*pst));
593 /* Use integral byte offset */
594 key_offset = pst->npc->keyx_len[flow->nix_intf];
595 key_offset = (key_offset + 7) / 8;
597 /* Location where LDATA would begin */
598 pst->mcam_data = (uint8_t *)flow->mcam_data;
599 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
601 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
602 layer < PLT_DIM(parse_stage_funcs)) {
603 /* Skip place-holders */
604 pattern = npc_parse_skip_void_and_any_items(pattern);
606 pst->pattern = pattern;
607 rc = parse_stage_funcs[layer](pst);
614 * Parse stage function sets pst->pattern to
615 * 1 past the last item it consumed.
617 pattern = pst->pattern;
623 /* Skip trailing place-holders */
624 pattern = npc_parse_skip_void_and_any_items(pattern);
626 /* Are there more items than what we can handle? */
627 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
628 return NPC_ERR_PATTERN_NOTSUP;
634 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
635 struct roc_npc_flow *flow)
638 return NPC_ERR_PARAM;
639 else if (attr->priority >= npc->flow_max_priority)
640 return NPC_ERR_PARAM;
641 else if ((!attr->egress && !attr->ingress) ||
642 (attr->egress && attr->ingress))
643 return NPC_ERR_PARAM;
646 flow->nix_intf = ROC_NPC_INTF_RX;
648 flow->nix_intf = ROC_NPC_INTF_TX;
650 flow->priority = attr->priority;
655 npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
656 const struct roc_npc_item_info pattern[],
657 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
658 struct npc_parse_state *pst)
660 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
664 err = npc_parse_attr(npc, attr, flow);
669 err = npc_parse_pattern(npc, pattern, flow, pst);
674 err = npc_parse_actions(roc_npc, attr, actions, flow);
681 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
682 const struct roc_npc_item_info pattern[],
683 const struct roc_npc_action actions[],
684 struct roc_npc_flow *flow)
686 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
687 struct npc_parse_state parse_state = {0};
690 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
695 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
697 return npc_program_mcam(npc, &parse_state, 0);
701 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
703 struct plt_bitmap *bmap = npc->rss_grp_entries;
705 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
706 if (!plt_bitmap_get(bmap, *pos))
709 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
713 npc_rss_action_configure(struct roc_npc *roc_npc,
714 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
715 uint32_t *rss_grp, uint32_t mcam_id)
717 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
718 struct roc_nix *roc_nix = roc_npc->roc_nix;
719 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
720 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
721 uint8_t key[ROC_NIX_RSS_KEY_LEN];
722 const uint8_t *key_ptr;
723 uint8_t flowkey_algx;
727 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
728 /* RSS group :0 is not usable for flow rss action */
729 if (rc < 0 || rss_grp_idx == 0)
732 for (i = 0; i < rss->queue_num; i++) {
733 if (rss->queue[i] >= nix->nb_rx_queues) {
734 plt_err("queue id > max number of queues");
739 *rss_grp = rss_grp_idx;
741 if (rss->key == NULL) {
742 roc_nix_rss_key_default_fill(roc_nix, key);
748 roc_nix_rss_key_set(roc_nix, key_ptr);
750 /* If queue count passed in the rss action is less than
751 * HW configured reta size, replicate rss action reta
752 * across HW reta table.
754 reta = nix->reta[rss_grp_idx];
756 if (rss->queue_num > nix->reta_sz) {
757 plt_err("too many queues for RSS context");
761 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
762 memcpy(reta + i * rss->queue_num, rss->queue,
763 sizeof(uint16_t) * rss->queue_num);
765 rem = nix->reta_sz % rss->queue_num;
767 memcpy(&reta[i * rss->queue_num], rss->queue,
768 rem * sizeof(uint16_t));
770 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
772 plt_err("Failed to init rss table rc = %d", rc);
776 flowkey_cfg = roc_npc->flowkey_cfg_state;
778 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
781 plt_err("Failed to set rss hash function rc = %d", rc);
785 *alg_idx = flowkey_algx;
787 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
793 npc_rss_action_program(struct roc_npc *roc_npc,
794 const struct roc_npc_action actions[],
795 struct roc_npc_flow *flow)
797 const struct roc_npc_action_rss *rss;
802 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
803 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
804 rss = (const struct roc_npc_action_rss *)actions->conf;
805 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
806 &rss_grp, flow->mcam_id);
810 flow->npc_action &= (~(0xfULL));
811 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
813 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
814 << NPC_RSS_ACT_ALG_OFFSET) |
815 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
816 << NPC_RSS_ACT_GRP_OFFSET);
824 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
826 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
828 return npc->mark_actions;
832 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
834 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
836 npc->mark_actions -= count;
837 return npc->mark_actions;
841 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
843 struct roc_nix *roc_nix = roc_npc->roc_nix;
844 struct nix_vtag_config *vtag_cfg;
845 struct nix_vtag_config_rsp *rsp;
852 struct nix_tx_vtag_action_s act;
855 nix = roc_nix_to_nix_priv(roc_nix);
856 mbox = (&nix->dev)->mbox;
858 tx_vtag_action.reg = flow->vtag_action;
859 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
861 if (vtag_cfg == NULL)
864 vtag_cfg->cfg_type = VTAG_TX;
865 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
866 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
867 vtag_cfg->tx.free_vtag0 = true;
869 if (flow->vtag_insert_count == 2) {
870 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
871 vtag_cfg->tx.free_vtag1 = true;
874 rc = mbox_process_msg(mbox, (void *)&rsp);
882 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
883 struct roc_npc_flow *flow,
884 struct npc_action_vtag_info *vlan_info,
887 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
892 /* This function parses parameters of one VLAN. When a parameter is
893 * found repeated, it treats it as the end of first VLAN's parameters
894 * and returns. The caller calls again to parse the parameters of the
898 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
899 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
903 const struct roc_npc_action_of_set_vlan_vid *vtag =
904 (const struct roc_npc_action_of_set_vlan_vid *)
907 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
909 if (vlan_info->vlan_id > 0xfff) {
910 plt_err("Invalid vlan_id for set vlan action");
914 flow->vtag_insert_enabled = true;
916 vlan_id_found = true;
917 } else if (actions->type ==
918 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
922 const struct roc_npc_action_of_push_vlan *ethtype =
923 (const struct roc_npc_action_of_push_vlan *)
925 vlan_info->vlan_ethtype =
926 plt_be_to_cpu_16(ethtype->ethertype);
927 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
928 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
929 plt_err("Invalid ethtype specified for push"
933 flow->vtag_insert_enabled = true;
935 ethtype_found = true;
936 } else if (actions->type ==
937 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
940 const struct roc_npc_action_of_set_vlan_pcp *pcp =
941 (const struct roc_npc_action_of_set_vlan_pcp *)
943 vlan_info->vlan_pcp = pcp->vlan_pcp;
944 if (vlan_info->vlan_pcp > 0x7) {
945 plt_err("Invalid PCP value for pcp action");
948 flow->vtag_insert_enabled = true;
960 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
961 struct npc_action_vtag_info *vlan_info)
963 struct nix_vtag_config *vtag_cfg;
964 struct nix_vtag_config_rsp *rsp;
969 struct nix_tx_vtag_action_s act;
972 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
974 if (vtag_cfg == NULL)
977 vtag_cfg->cfg_type = VTAG_TX;
978 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
980 (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
981 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
983 vtag_cfg->tx.cfg_vtag0 = 1;
985 if (flow->vtag_insert_count == 2) {
987 (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
988 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
990 vtag_cfg->tx.cfg_vtag1 = 1;
993 rc = mbox_process_msg(mbox, (void *)&rsp);
997 if (rsp->vtag0_idx < 0 ||
998 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
999 plt_err("Failed to config TX VTAG action");
1003 tx_vtag_action.reg = 0;
1004 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1005 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1006 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1007 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1009 if (flow->vtag_insert_count == 2) {
1010 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1011 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1012 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1013 /* NIX_TX_VTAG_ACTION_S
1014 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1015 * offset accordingly. Thus, if the two offsets are equal in
1016 * the structure, hardware inserts Vtag 1 immediately after
1017 * Vtag 0 in the packet.
1019 tx_vtag_action.act.vtag1_relptr =
1020 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1023 flow->vtag_action = tx_vtag_action.reg;
1029 npc_vtag_strip_action_configure(struct mbox *mbox,
1030 const struct roc_npc_action actions[],
1031 struct roc_npc_flow *flow, int *strip_cnt)
1033 struct nix_vtag_config *vtag_cfg;
1034 uint64_t rx_vtag_action = 0;
1035 int count = 0, rc = 0;
1039 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1040 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1044 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1046 if (vtag_cfg == NULL)
1049 vtag_cfg->cfg_type = VTAG_RX;
1050 vtag_cfg->rx.strip_vtag = 1;
1051 /* Always capture */
1052 vtag_cfg->rx.capture_vtag = 1;
1053 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1054 vtag_cfg->rx.vtag_type = 0;
1056 rc = mbox_process(mbox);
1060 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1061 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1062 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1064 if (*strip_cnt == 2) {
1065 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1066 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1067 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1069 flow->vtag_action = rx_vtag_action;
1075 npc_vtag_action_program(struct roc_npc *roc_npc,
1076 const struct roc_npc_action actions[],
1077 struct roc_npc_flow *flow)
1079 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1080 const struct roc_npc_action *insert_actions;
1081 struct roc_nix *roc_nix = roc_npc->roc_nix;
1082 struct npc_action_vtag_info vlan_info[2];
1083 int parsed_cnt = 0, strip_cnt = 0;
1084 int tot_vlan_params = 0;
1089 nix = roc_nix_to_nix_priv(roc_nix);
1090 mbox = (&nix->dev)->mbox;
1092 memset(vlan_info, 0, sizeof(vlan_info));
1094 flow->vtag_insert_enabled = false;
1096 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1097 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1098 if (vlan_strip_parsed) {
1099 plt_err("Incorrect VLAN strip actions");
1102 rc = npc_vtag_strip_action_configure(mbox, actions,
1110 vlan_strip_parsed = true;
1111 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1113 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1115 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1116 if (vlan_insert_parsed) {
1117 plt_err("Incorrect VLAN insert actions");
1121 insert_actions = actions;
1123 for (i = 0; i < 2; i++) {
1124 rc = npc_vtag_insert_action_parse(
1125 insert_actions, flow, &vlan_info[i],
1132 insert_actions += parsed_cnt;
1133 tot_vlan_params += parsed_cnt;
1134 flow->vtag_insert_count++;
1137 actions += tot_vlan_params - 1;
1138 vlan_insert_parsed = true;
1142 if (flow->vtag_insert_enabled) {
1143 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1151 struct roc_npc_flow *
1152 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1153 const struct roc_npc_item_info pattern[],
1154 const struct roc_npc_action actions[], int *errcode)
1156 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1157 struct roc_npc_flow *flow, *flow_iter;
1158 struct npc_parse_state parse_state;
1159 struct npc_flow_list *list;
1162 npc->channel = roc_npc->channel;
1163 npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1164 if (npc->is_sdp_link) {
1165 if (roc_npc->is_sdp_mask_set) {
1166 npc->sdp_channel = roc_npc->sdp_channel;
1167 npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1169 /* By default set the channel and mask to cover
1170 * the whole SDP channel range.
1172 npc->sdp_channel = (uint16_t)NIX_CHAN_SDP_CH_START;
1173 npc->sdp_channel_mask = (uint16_t)NIX_CHAN_SDP_CH_START;
1177 flow = plt_zmalloc(sizeof(*flow), 0);
1179 *errcode = NPC_ERR_NO_MEM;
1182 memset(flow, 0, sizeof(*flow));
1184 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
1191 rc = npc_vtag_action_program(roc_npc, actions, flow);
1197 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1199 rc = npc_program_mcam(npc, &parse_state, 1);
1205 rc = npc_rss_action_program(roc_npc, actions, flow);
1208 goto set_rss_failed;
1211 list = &npc->flow_list[flow->priority];
1212 /* List in ascending order of mcam entries */
1213 TAILQ_FOREACH(flow_iter, list, next) {
1214 if (flow_iter->mcam_id > flow->mcam_id) {
1215 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1220 TAILQ_INSERT_TAIL(list, flow, next);
1224 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1236 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1240 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1241 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1242 NPC_RSS_ACT_GRP_MASK;
1243 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1246 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1253 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1255 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1258 rc = npc_rss_group_free(npc, flow);
1260 plt_err("Failed to free rss action rc = %d", rc);
1264 if (flow->vtag_insert_enabled) {
1265 rc = npc_vtag_cfg_delete(roc_npc, flow);
1270 if (flow->ctr_id != NPC_COUNTER_NONE) {
1271 rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
1275 rc = npc_mcam_free_counter(npc, flow->ctr_id);
1280 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1284 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1286 npc_delete_prio_list_entry(npc, flow);
1293 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1295 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1296 struct roc_npc_flow *flow_iter;
1297 struct npc_flow_list *list;
1298 uint32_t max_prio, i;
1300 max_prio = npc->flow_max_priority;
1302 for (i = 0; i < max_prio; i++) {
1303 list = &npc->flow_list[i];
1305 /* List in ascending order of mcam entries */
1306 TAILQ_FOREACH(flow_iter, list, next) {
1307 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1313 roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
1314 struct roc_npc_flow *flow)
1316 struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1317 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1318 struct mcam_entry *base_entry;
1321 if (roc_nix_is_pf(roc_npc->roc_nix))
1324 (void)mbox_alloc_msg_npc_read_base_steer_rule(npc->mbox);
1325 rc = mbox_process_msg(npc->mbox, (void *)&base_rule_rsp);
1327 plt_err("Failed to fetch VF's base MCAM entry");
1330 base_entry = &base_rule_rsp->entry_data;
1331 for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1332 flow->mcam_data[idx] |= base_entry->kw[idx];
1333 flow->mcam_mask[idx] |= base_entry->kw_mask[idx];