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_flow_list);
183 npc->flow_list = plt_zmalloc(sz, 0);
184 if (npc->flow_list == NULL) {
185 plt_err("flow_list alloc failed");
190 sz = npc->flow_max_priority * sizeof(struct npc_prio_flow_list_head);
191 npc->prio_flow_list = plt_zmalloc(sz, 0);
192 if (npc->prio_flow_list == NULL) {
193 plt_err("prio_flow_list alloc failed");
199 for (idx = 0; idx < npc->flow_max_priority; idx++) {
200 TAILQ_INIT(&npc->flow_list[idx]);
201 TAILQ_INIT(&npc->prio_flow_list[idx]);
204 npc->rss_grps = NPC_RSS_GRPS;
206 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
207 nix_mem = plt_zmalloc(bmap_sz, 0);
208 if (nix_mem == NULL) {
209 plt_err("Bmap alloc failed");
214 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
216 if (!npc->rss_grp_entries) {
217 plt_err("bitmap init failed");
222 /* Group 0 will be used for RSS,
223 * 1 -7 will be used for npc_flow RSS action
225 plt_bitmap_set(npc->rss_grp_entries, 0);
231 plt_free(npc->flow_list);
232 if (npc->prio_flow_list)
233 plt_free(npc->prio_flow_list);
240 roc_npc_fini(struct roc_npc *roc_npc)
242 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
245 rc = npc_flow_free_all_resources(npc);
247 plt_err("Error when deleting NPC MCAM entries, counters");
251 if (npc->flow_list) {
252 plt_free(npc->flow_list);
253 npc->flow_list = NULL;
256 if (npc->prio_flow_list) {
257 plt_free(npc->prio_flow_list);
258 npc->prio_flow_list = NULL;
265 roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
266 struct roc_npc *roc_npc_dst)
268 struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
269 struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
270 struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
271 struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
273 if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
274 plt_err("Output port should be VF");
278 if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
279 plt_err("Invalid VF for output port");
283 if (nix_src->dev.pf != nix_dst->dev.pf) {
284 plt_err("Output port should be VF of ingress PF");
291 npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
292 const struct roc_npc_action actions[],
293 struct roc_npc_flow *flow)
295 const struct roc_npc_action_port_id *act_portid;
296 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
297 const struct roc_npc_action_mark *act_mark;
298 const struct roc_npc_action_meter *act_mtr;
299 const struct roc_npc_action_queue *act_q;
300 const struct roc_npc_action_vf *vf_act;
301 bool vlan_insert_action = false;
302 int sel_act, req_act = 0;
303 uint16_t pf_func, vf_id;
308 /* Initialize actions */
309 flow->ctr_id = NPC_COUNTER_NONE;
310 flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
311 pf_func = npc->pf_func;
313 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
314 switch (actions->type) {
315 case ROC_NPC_ACTION_TYPE_VOID:
317 case ROC_NPC_ACTION_TYPE_MARK:
318 act_mark = (const struct roc_npc_action_mark *)
320 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
321 plt_err("mark value must be < 0xfffe");
324 mark = act_mark->id + 1;
325 req_act |= ROC_NPC_ACTION_TYPE_MARK;
326 npc->mark_actions += 1;
329 case ROC_NPC_ACTION_TYPE_FLAG:
330 mark = NPC_FLOW_FLAG_VAL;
331 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
332 npc->mark_actions += 1;
335 case ROC_NPC_ACTION_TYPE_COUNT:
336 /* Indicates, need a counter */
338 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
341 case ROC_NPC_ACTION_TYPE_DROP:
342 req_act |= ROC_NPC_ACTION_TYPE_DROP;
345 case ROC_NPC_ACTION_TYPE_PF:
346 req_act |= ROC_NPC_ACTION_TYPE_PF;
350 case ROC_NPC_ACTION_TYPE_VF:
352 (const struct roc_npc_action_vf *)actions->conf;
353 req_act |= ROC_NPC_ACTION_TYPE_VF;
354 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
356 pf_func = (pf_func | (vf_id + 1));
359 case ROC_NPC_ACTION_TYPE_PORT_ID:
360 act_portid = (const struct roc_npc_action_port_id *)
363 pf_func = (pf_func | (act_portid->id + 1));
364 req_act |= ROC_NPC_ACTION_TYPE_VF;
367 case ROC_NPC_ACTION_TYPE_QUEUE:
368 act_q = (const struct roc_npc_action_queue *)
371 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
374 case ROC_NPC_ACTION_TYPE_RSS:
375 req_act |= ROC_NPC_ACTION_TYPE_RSS;
378 case ROC_NPC_ACTION_TYPE_SEC:
379 /* Assumes user has already configured security
380 * session for this flow. Associated conf is
381 * opaque. When security is implemented,
382 * we need to verify that for specified security
385 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
386 * session_protocol ==
387 * NPC_SECURITY_PROTOCOL_IPSEC
389 req_act |= ROC_NPC_ACTION_TYPE_SEC;
392 /* Special processing when with inline device */
393 if (roc_nix_inb_is_with_inl_dev(roc_npc->roc_nix) &&
394 roc_nix_inl_dev_is_probed()) {
396 pf_func = nix_inl_dev_pffunc_get();
399 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
400 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
402 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
403 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
405 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
406 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
408 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
409 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
411 case ROC_NPC_ACTION_TYPE_METER:
412 act_mtr = (const struct roc_npc_action_meter *)
414 flow->mtr_id = act_mtr->mtr_id;
415 req_act |= ROC_NPC_ACTION_TYPE_METER;
418 errcode = NPC_ERR_ACTION_NOTSUP;
423 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
424 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
425 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
426 vlan_insert_action = true;
428 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
429 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
430 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
431 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
432 plt_err("PCP insert action can't be supported alone");
433 errcode = NPC_ERR_ACTION_NOTSUP;
437 /* Both STRIP and INSERT actions are not supported */
438 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
439 errcode = NPC_ERR_ACTION_NOTSUP;
443 /* Check if actions specified are compatible */
445 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
446 plt_err("VLAN pop action is not supported on Egress");
447 errcode = NPC_ERR_ACTION_NOTSUP;
452 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
453 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
454 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
455 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
456 plt_err("Only VLAN insert, drop, count supported on Egress");
457 errcode = NPC_ERR_ACTION_NOTSUP;
461 if (vlan_insert_action &&
462 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
463 plt_err("Both VLAN insert and drop actions cannot be supported");
464 errcode = NPC_ERR_ACTION_NOTSUP;
468 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
469 flow->npc_action = NIX_TX_ACTIONOP_DROP;
470 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
471 vlan_insert_action) {
472 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
474 plt_err("Unsupported action for egress");
475 errcode = NPC_ERR_ACTION_NOTSUP;
481 if (vlan_insert_action) {
482 errcode = NPC_ERR_ACTION_NOTSUP;
487 /* We have already verified the attr, this is ingress.
488 * - Exactly one terminating action is supported
489 * - Exactly one of MARK or FLAG is supported
490 * - If terminating action is DROP, only count is valid.
492 sel_act = req_act & NPC_ACTION_TERM;
493 if ((sel_act & (sel_act - 1)) != 0) {
494 errcode = NPC_ERR_ACTION_NOTSUP;
498 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
499 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
500 if ((sel_act & (sel_act - 1)) != 0) {
501 errcode = NPC_ERR_ACTION_NOTSUP;
506 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
507 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
508 errcode = NPC_ERR_ACTION_NOTSUP;
512 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
513 npc->vtag_strip_actions++;
515 /* Set NIX_RX_ACTIONOP */
516 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
517 /* Only VLAN action is provided */
518 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
520 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
521 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
522 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
523 flow->npc_action |= (uint64_t)rq << 20;
524 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
525 flow->npc_action = NIX_RX_ACTIONOP_DROP;
526 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
527 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
528 flow->npc_action |= (uint64_t)rq << 20;
529 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
530 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
531 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
532 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
533 flow->npc_action |= (uint64_t)rq << 20;
535 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
536 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
537 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
538 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
539 * This is default action, when user specify only
542 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
544 /* Should never reach here */
545 errcode = NPC_ERR_ACTION_NOTSUP;
550 flow->npc_action |= (uint64_t)mark << 40;
553 /* Ideally AF must ensure that correct pf_func is set */
554 flow->npc_action |= (uint64_t)pf_func << 4;
562 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
565 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
566 struct roc_npc_flow *flow, struct npc_parse_state *pst)
568 npc_parse_stage_func_t parse_stage_funcs[] = {
569 npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
570 npc_parse_la, npc_parse_lb, npc_parse_lc,
571 npc_parse_ld, npc_parse_le, npc_parse_lf,
572 npc_parse_lg, npc_parse_lh,
579 return NPC_ERR_PARAM;
581 memset(pst, 0, sizeof(*pst));
585 /* Use integral byte offset */
586 key_offset = pst->npc->keyx_len[flow->nix_intf];
587 key_offset = (key_offset + 7) / 8;
589 /* Location where LDATA would begin */
590 pst->mcam_data = (uint8_t *)flow->mcam_data;
591 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
593 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
594 layer < PLT_DIM(parse_stage_funcs)) {
595 /* Skip place-holders */
596 pattern = npc_parse_skip_void_and_any_items(pattern);
598 pst->pattern = pattern;
599 rc = parse_stage_funcs[layer](pst);
606 * Parse stage function sets pst->pattern to
607 * 1 past the last item it consumed.
609 pattern = pst->pattern;
615 /* Skip trailing place-holders */
616 pattern = npc_parse_skip_void_and_any_items(pattern);
618 /* Are there more items than what we can handle? */
619 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
620 return NPC_ERR_PATTERN_NOTSUP;
626 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
627 struct roc_npc_flow *flow)
630 return NPC_ERR_PARAM;
631 else if (attr->priority >= npc->flow_max_priority)
632 return NPC_ERR_PARAM;
633 else if ((!attr->egress && !attr->ingress) ||
634 (attr->egress && attr->ingress))
635 return NPC_ERR_PARAM;
638 flow->nix_intf = ROC_NPC_INTF_RX;
640 flow->nix_intf = ROC_NPC_INTF_TX;
642 flow->priority = attr->priority;
647 npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
648 const struct roc_npc_item_info pattern[],
649 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
650 struct npc_parse_state *pst)
652 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
656 err = npc_parse_attr(npc, attr, flow);
661 err = npc_parse_pattern(npc, pattern, flow, pst);
666 err = npc_parse_actions(roc_npc, attr, actions, flow);
673 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
674 const struct roc_npc_item_info pattern[],
675 const struct roc_npc_action actions[],
676 struct roc_npc_flow *flow)
678 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
679 struct npc_parse_state parse_state = {0};
682 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
687 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
689 return npc_program_mcam(npc, &parse_state, 0);
693 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
695 struct plt_bitmap *bmap = npc->rss_grp_entries;
697 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
698 if (!plt_bitmap_get(bmap, *pos))
701 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
705 npc_rss_action_configure(struct roc_npc *roc_npc,
706 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
707 uint32_t *rss_grp, uint32_t mcam_id)
709 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
710 struct roc_nix *roc_nix = roc_npc->roc_nix;
711 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
712 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
713 uint8_t key[ROC_NIX_RSS_KEY_LEN];
714 const uint8_t *key_ptr;
715 uint8_t flowkey_algx;
719 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
720 /* RSS group :0 is not usable for flow rss action */
721 if (rc < 0 || rss_grp_idx == 0)
724 for (i = 0; i < rss->queue_num; i++) {
725 if (rss->queue[i] >= nix->nb_rx_queues) {
726 plt_err("queue id > max number of queues");
731 *rss_grp = rss_grp_idx;
733 if (rss->key == NULL) {
734 roc_nix_rss_key_default_fill(roc_nix, key);
740 roc_nix_rss_key_set(roc_nix, key_ptr);
742 /* If queue count passed in the rss action is less than
743 * HW configured reta size, replicate rss action reta
744 * across HW reta table.
746 reta = nix->reta[rss_grp_idx];
748 if (rss->queue_num > nix->reta_sz) {
749 plt_err("too many queues for RSS context");
753 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
754 memcpy(reta + i * rss->queue_num, rss->queue,
755 sizeof(uint16_t) * rss->queue_num);
757 rem = nix->reta_sz % rss->queue_num;
759 memcpy(&reta[i * rss->queue_num], rss->queue,
760 rem * sizeof(uint16_t));
762 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
764 plt_err("Failed to init rss table rc = %d", rc);
768 flowkey_cfg = roc_npc->flowkey_cfg_state;
770 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
773 plt_err("Failed to set rss hash function rc = %d", rc);
777 *alg_idx = flowkey_algx;
779 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
785 npc_rss_action_program(struct roc_npc *roc_npc,
786 const struct roc_npc_action actions[],
787 struct roc_npc_flow *flow)
789 const struct roc_npc_action_rss *rss;
794 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
795 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
796 rss = (const struct roc_npc_action_rss *)actions->conf;
797 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
798 &rss_grp, flow->mcam_id);
802 flow->npc_action &= (~(0xfULL));
803 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
805 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
806 << NPC_RSS_ACT_ALG_OFFSET) |
807 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
808 << NPC_RSS_ACT_GRP_OFFSET);
816 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
818 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
820 return npc->mark_actions;
824 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
826 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
828 npc->mark_actions -= count;
829 return npc->mark_actions;
833 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
835 struct roc_nix *roc_nix = roc_npc->roc_nix;
836 struct nix_vtag_config *vtag_cfg;
837 struct nix_vtag_config_rsp *rsp;
844 struct nix_tx_vtag_action_s act;
847 nix = roc_nix_to_nix_priv(roc_nix);
848 mbox = (&nix->dev)->mbox;
850 tx_vtag_action.reg = flow->vtag_action;
851 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
853 if (vtag_cfg == NULL)
856 vtag_cfg->cfg_type = VTAG_TX;
857 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
858 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
859 vtag_cfg->tx.free_vtag0 = true;
861 if (flow->vtag_insert_count == 2) {
862 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
863 vtag_cfg->tx.free_vtag1 = true;
866 rc = mbox_process_msg(mbox, (void *)&rsp);
874 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
875 struct roc_npc_flow *flow,
876 struct npc_action_vtag_info *vlan_info,
879 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
884 /* This function parses parameters of one VLAN. When a parameter is
885 * found repeated, it treats it as the end of first VLAN's parameters
886 * and returns. The caller calls again to parse the parameters of the
890 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
891 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
895 const struct roc_npc_action_of_set_vlan_vid *vtag =
896 (const struct roc_npc_action_of_set_vlan_vid *)
899 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
901 if (vlan_info->vlan_id > 0xfff) {
902 plt_err("Invalid vlan_id for set vlan action");
906 flow->vtag_insert_enabled = true;
908 vlan_id_found = true;
909 } else if (actions->type ==
910 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
914 const struct roc_npc_action_of_push_vlan *ethtype =
915 (const struct roc_npc_action_of_push_vlan *)
917 vlan_info->vlan_ethtype =
918 plt_be_to_cpu_16(ethtype->ethertype);
919 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
920 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
921 plt_err("Invalid ethtype specified for push"
925 flow->vtag_insert_enabled = true;
927 ethtype_found = true;
928 } else if (actions->type ==
929 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
932 const struct roc_npc_action_of_set_vlan_pcp *pcp =
933 (const struct roc_npc_action_of_set_vlan_pcp *)
935 vlan_info->vlan_pcp = pcp->vlan_pcp;
936 if (vlan_info->vlan_pcp > 0x7) {
937 plt_err("Invalid PCP value for pcp action");
940 flow->vtag_insert_enabled = true;
952 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
953 struct npc_action_vtag_info *vlan_info)
955 struct nix_vtag_config *vtag_cfg;
956 struct nix_vtag_config_rsp *rsp;
961 struct nix_tx_vtag_action_s act;
964 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
966 if (vtag_cfg == NULL)
969 vtag_cfg->cfg_type = VTAG_TX;
970 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
972 ((vlan_info[0].vlan_ethtype << 16) |
973 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
975 vtag_cfg->tx.cfg_vtag0 = 1;
977 if (flow->vtag_insert_count == 2) {
979 ((vlan_info[1].vlan_ethtype << 16) |
980 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
982 vtag_cfg->tx.cfg_vtag1 = 1;
985 rc = mbox_process_msg(mbox, (void *)&rsp);
989 if (rsp->vtag0_idx < 0 ||
990 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
991 plt_err("Failed to config TX VTAG action");
995 tx_vtag_action.reg = 0;
996 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
997 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
998 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
999 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1001 if (flow->vtag_insert_count == 2) {
1002 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1003 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1004 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1005 /* NIX_TX_VTAG_ACTION_S
1006 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1007 * offset accordingly. Thus, if the two offsets are equal in
1008 * the structure, hardware inserts Vtag 1 immediately after
1009 * Vtag 0 in the packet.
1011 tx_vtag_action.act.vtag1_relptr =
1012 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1015 flow->vtag_action = tx_vtag_action.reg;
1021 npc_vtag_strip_action_configure(struct mbox *mbox,
1022 const struct roc_npc_action actions[],
1023 struct roc_npc_flow *flow, int *strip_cnt)
1025 struct nix_vtag_config *vtag_cfg;
1026 uint64_t rx_vtag_action = 0;
1027 int count = 0, rc = 0;
1031 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1032 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1036 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1038 if (vtag_cfg == NULL)
1041 vtag_cfg->cfg_type = VTAG_RX;
1042 vtag_cfg->rx.strip_vtag = 1;
1043 /* Always capture */
1044 vtag_cfg->rx.capture_vtag = 1;
1045 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1046 vtag_cfg->rx.vtag_type = 0;
1048 rc = mbox_process(mbox);
1052 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1053 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1054 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1056 if (*strip_cnt == 2) {
1057 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1058 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1059 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1061 flow->vtag_action = rx_vtag_action;
1067 npc_vtag_action_program(struct roc_npc *roc_npc,
1068 const struct roc_npc_action actions[],
1069 struct roc_npc_flow *flow)
1071 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1072 const struct roc_npc_action *insert_actions;
1073 struct roc_nix *roc_nix = roc_npc->roc_nix;
1074 struct npc_action_vtag_info vlan_info[2];
1075 int parsed_cnt = 0, strip_cnt = 0;
1076 int tot_vlan_params = 0;
1081 nix = roc_nix_to_nix_priv(roc_nix);
1082 mbox = (&nix->dev)->mbox;
1084 memset(vlan_info, 0, sizeof(vlan_info));
1086 flow->vtag_insert_enabled = false;
1088 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1089 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1090 if (vlan_strip_parsed) {
1091 plt_err("Incorrect VLAN strip actions");
1094 rc = npc_vtag_strip_action_configure(mbox, actions,
1102 vlan_strip_parsed = true;
1103 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1105 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1107 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1108 if (vlan_insert_parsed) {
1109 plt_err("Incorrect VLAN insert actions");
1113 insert_actions = actions;
1115 for (i = 0; i < 2; i++) {
1116 rc = npc_vtag_insert_action_parse(
1117 insert_actions, flow, &vlan_info[i],
1124 insert_actions += parsed_cnt;
1125 tot_vlan_params += parsed_cnt;
1126 flow->vtag_insert_count++;
1129 actions += tot_vlan_params - 1;
1130 vlan_insert_parsed = true;
1134 if (flow->vtag_insert_enabled) {
1135 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1143 struct roc_npc_flow *
1144 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1145 const struct roc_npc_item_info pattern[],
1146 const struct roc_npc_action actions[], int *errcode)
1148 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1149 struct roc_npc_flow *flow, *flow_iter;
1150 struct npc_parse_state parse_state;
1151 struct npc_flow_list *list;
1154 npc->channel = roc_npc->channel;
1156 flow = plt_zmalloc(sizeof(*flow), 0);
1158 *errcode = NPC_ERR_NO_MEM;
1161 memset(flow, 0, sizeof(*flow));
1163 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
1170 rc = npc_vtag_action_program(roc_npc, actions, flow);
1176 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1178 rc = npc_program_mcam(npc, &parse_state, 1);
1184 rc = npc_rss_action_program(roc_npc, actions, flow);
1187 goto set_rss_failed;
1190 list = &npc->flow_list[flow->priority];
1191 /* List in ascending order of mcam entries */
1192 TAILQ_FOREACH(flow_iter, list, next) {
1193 if (flow_iter->mcam_id > flow->mcam_id) {
1194 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1199 TAILQ_INSERT_TAIL(list, flow, next);
1203 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1215 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1219 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1220 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1221 NPC_RSS_ACT_GRP_MASK;
1222 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1225 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1232 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1234 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1237 rc = npc_rss_group_free(npc, flow);
1239 plt_err("Failed to free rss action rc = %d", rc);
1243 if (flow->vtag_insert_enabled) {
1244 rc = npc_vtag_cfg_delete(roc_npc, flow);
1249 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1253 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1255 npc_delete_prio_list_entry(npc, flow);
1262 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1264 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1265 struct roc_npc_flow *flow_iter;
1266 struct npc_flow_list *list;
1267 uint32_t max_prio, i;
1269 max_prio = npc->flow_max_priority;
1271 for (i = 0; i < max_prio; i++) {
1272 list = &npc->flow_list[i];
1274 /* List in ascending order of mcam entries */
1275 TAILQ_FOREACH(flow_iter, list, next) {
1276 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1282 roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
1283 struct roc_npc_flow *flow)
1285 struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1286 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1287 struct mcam_entry *base_entry;
1290 if (roc_nix_is_pf(roc_npc->roc_nix))
1293 (void)mbox_alloc_msg_npc_read_base_steer_rule(npc->mbox);
1294 rc = mbox_process_msg(npc->mbox, (void *)&base_rule_rsp);
1296 plt_err("Failed to fetch VF's base MCAM entry");
1299 base_entry = &base_rule_rsp->entry_data;
1300 for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1301 flow->mcam_data[idx] |= base_entry->kw[idx];
1302 flow->mcam_mask[idx] |= base_entry->kw_mask[idx];