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->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
179 /* Free, free_rev, live and live_rev entries */
180 bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
181 mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
183 plt_err("Bmap alloc failed");
188 sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
189 npc->flow_list = plt_zmalloc(sz, 0);
190 if (npc->flow_list == NULL) {
191 plt_err("flow_list alloc failed");
196 sz = npc->flow_max_priority * sizeof(struct npc_prio_flow_list_head);
197 npc->prio_flow_list = plt_zmalloc(sz, 0);
198 if (npc->prio_flow_list == NULL) {
199 plt_err("prio_flow_list alloc failed");
205 for (idx = 0; idx < npc->flow_max_priority; idx++) {
206 TAILQ_INIT(&npc->flow_list[idx]);
207 TAILQ_INIT(&npc->prio_flow_list[idx]);
210 npc->rss_grps = NPC_RSS_GRPS;
212 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
213 nix_mem = plt_zmalloc(bmap_sz, 0);
214 if (nix_mem == NULL) {
215 plt_err("Bmap alloc failed");
220 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
222 if (!npc->rss_grp_entries) {
223 plt_err("bitmap init failed");
228 /* Group 0 will be used for RSS,
229 * 1 -7 will be used for npc_flow RSS action
231 plt_bitmap_set(npc->rss_grp_entries, 0);
237 plt_free(npc->flow_list);
238 if (npc->prio_flow_list)
239 plt_free(npc->prio_flow_list);
246 roc_npc_fini(struct roc_npc *roc_npc)
248 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
251 rc = npc_flow_free_all_resources(npc);
253 plt_err("Error when deleting NPC MCAM entries, counters");
257 if (npc->flow_list) {
258 plt_free(npc->flow_list);
259 npc->flow_list = NULL;
262 if (npc->prio_flow_list) {
263 plt_free(npc->prio_flow_list);
264 npc->prio_flow_list = NULL;
271 roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
272 struct roc_npc *roc_npc_dst)
274 struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
275 struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
276 struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
277 struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
279 if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
280 plt_err("Output port should be VF");
284 if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
285 plt_err("Invalid VF for output port");
289 if (nix_src->dev.pf != nix_dst->dev.pf) {
290 plt_err("Output port should be VF of ingress PF");
297 npc_parse_msns_action(struct roc_npc *roc_npc, const struct roc_npc_action *act,
298 struct roc_npc_flow *flow, uint8_t *has_msns_action)
300 const struct roc_npc_sec_action *sec_action;
303 union nix_rx_vtag_action_u act;
306 if (roc_npc->roc_nix->custom_sa_action == 0 ||
307 roc_model_is_cn9k() == 1 || act->conf == NULL)
310 *has_msns_action = true;
311 sec_action = act->conf;
314 vtag_act.act.sa_xor = sec_action->sa_xor;
315 vtag_act.act.sa_hi = sec_action->sa_hi;
316 vtag_act.act.sa_lo = sec_action->sa_lo;
318 switch (sec_action->alg) {
319 case ROC_NPC_SEC_ACTION_ALG0:
321 case ROC_NPC_SEC_ACTION_ALG1:
322 vtag_act.act.vtag1_valid = false;
323 vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG1;
325 case ROC_NPC_SEC_ACTION_ALG2:
326 vtag_act.act.vtag1_valid = false;
327 vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG2;
333 flow->vtag_action = vtag_act.reg;
339 npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
340 const struct roc_npc_action actions[],
341 struct roc_npc_flow *flow)
343 const struct roc_npc_action_port_id *act_portid;
344 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
345 const struct roc_npc_action_mark *act_mark;
346 const struct roc_npc_action_meter *act_mtr;
347 const struct roc_npc_action_queue *act_q;
348 const struct roc_npc_action_vf *vf_act;
349 bool vlan_insert_action = false;
350 uint8_t has_msns_act = 0;
351 int sel_act, req_act = 0;
352 uint16_t pf_func, vf_id;
358 /* Initialize actions */
359 flow->ctr_id = NPC_COUNTER_NONE;
360 flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
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;
378 case ROC_NPC_ACTION_TYPE_FLAG:
379 mark = NPC_FLOW_FLAG_VAL;
380 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
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_PORT_ID:
408 act_portid = (const struct roc_npc_action_port_id *)
411 pf_func = (pf_func | (act_portid->id + 1));
412 req_act |= ROC_NPC_ACTION_TYPE_VF;
415 case ROC_NPC_ACTION_TYPE_QUEUE:
416 act_q = (const struct roc_npc_action_queue *)
419 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
422 case ROC_NPC_ACTION_TYPE_RSS:
423 req_act |= ROC_NPC_ACTION_TYPE_RSS;
426 case ROC_NPC_ACTION_TYPE_SEC:
427 /* Assumes user has already configured security
428 * session for this flow. Associated conf is
429 * opaque. When security is implemented,
430 * we need to verify that for specified security
433 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
434 * session_protocol ==
435 * NPC_SECURITY_PROTOCOL_IPSEC
437 req_act |= ROC_NPC_ACTION_TYPE_SEC;
440 /* Special processing when with inline device */
441 if (roc_nix_inb_is_with_inl_dev(roc_npc->roc_nix) &&
442 roc_nix_inl_dev_is_probed()) {
444 pf_func = nix_inl_dev_pffunc_get();
446 rc = npc_parse_msns_action(roc_npc, actions, flow,
449 errcode = NPC_ERR_ACTION_NOTSUP;
453 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
454 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
456 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
457 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
459 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
460 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
462 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
463 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
465 case ROC_NPC_ACTION_TYPE_METER:
466 act_mtr = (const struct roc_npc_action_meter *)
468 flow->mtr_id = act_mtr->mtr_id;
469 req_act |= ROC_NPC_ACTION_TYPE_METER;
472 errcode = NPC_ERR_ACTION_NOTSUP;
477 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
478 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
479 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
480 vlan_insert_action = true;
482 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
483 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
484 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
485 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
486 plt_err("PCP insert action can't be supported alone");
487 errcode = NPC_ERR_ACTION_NOTSUP;
491 if (has_msns_act && (vlan_insert_action ||
492 (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP))) {
493 plt_err("Both MSNS and VLAN insert/strip action can't be supported"
495 errcode = NPC_ERR_ACTION_NOTSUP;
499 /* Both STRIP and INSERT actions are not supported */
500 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
501 errcode = NPC_ERR_ACTION_NOTSUP;
505 /* Check if actions specified are compatible */
507 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
508 plt_err("VLAN pop action is not supported on Egress");
509 errcode = NPC_ERR_ACTION_NOTSUP;
514 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
515 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
516 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
517 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
518 plt_err("Only VLAN insert, drop, count supported on Egress");
519 errcode = NPC_ERR_ACTION_NOTSUP;
523 if (vlan_insert_action &&
524 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
525 plt_err("Both VLAN insert and drop actions cannot be supported");
526 errcode = NPC_ERR_ACTION_NOTSUP;
530 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
531 flow->npc_action = NIX_TX_ACTIONOP_DROP;
532 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
533 vlan_insert_action) {
534 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
536 plt_err("Unsupported action for egress");
537 errcode = NPC_ERR_ACTION_NOTSUP;
543 if (vlan_insert_action) {
544 errcode = NPC_ERR_ACTION_NOTSUP;
549 /* We have already verified the attr, this is ingress.
550 * - Exactly one terminating action is supported
551 * - Exactly one of MARK or FLAG is supported
552 * - If terminating action is DROP, only count is valid.
554 sel_act = req_act & NPC_ACTION_TERM;
555 if ((sel_act & (sel_act - 1)) != 0) {
556 errcode = NPC_ERR_ACTION_NOTSUP;
560 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
561 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
562 if ((sel_act & (sel_act - 1)) != 0) {
563 errcode = NPC_ERR_ACTION_NOTSUP;
568 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
569 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
570 errcode = NPC_ERR_ACTION_NOTSUP;
574 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
575 npc->vtag_strip_actions++;
577 /* Set NIX_RX_ACTIONOP */
578 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
579 /* Only VLAN action is provided */
580 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
582 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
583 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
584 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
585 flow->npc_action |= (uint64_t)rq << 20;
586 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
587 flow->npc_action = NIX_RX_ACTIONOP_DROP;
588 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
589 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
590 flow->npc_action |= (uint64_t)rq << 20;
591 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
592 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
593 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
594 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
595 flow->npc_action |= (uint64_t)rq << 20;
597 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
598 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
599 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
600 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
601 * This is default action, when user specify only
604 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
606 /* Should never reach here */
607 errcode = NPC_ERR_ACTION_NOTSUP;
612 flow->npc_action |= (uint64_t)mark << 40;
615 /* Ideally AF must ensure that correct pf_func is set */
616 flow->npc_action |= (uint64_t)pf_func << 4;
624 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
627 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
628 struct roc_npc_flow *flow, struct npc_parse_state *pst)
630 npc_parse_stage_func_t parse_stage_funcs[] = {
631 npc_parse_meta_items, npc_parse_mark_item, npc_parse_pre_l2,
632 npc_parse_cpt_hdr, npc_parse_higig2_hdr, npc_parse_la,
633 npc_parse_lb, npc_parse_lc, npc_parse_ld,
634 npc_parse_le, npc_parse_lf, npc_parse_lg,
642 return NPC_ERR_PARAM;
644 memset(pst, 0, sizeof(*pst));
648 /* Use integral byte offset */
649 key_offset = pst->npc->keyx_len[flow->nix_intf];
650 key_offset = (key_offset + 7) / 8;
652 /* Location where LDATA would begin */
653 pst->mcam_data = (uint8_t *)flow->mcam_data;
654 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
656 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
657 layer < PLT_DIM(parse_stage_funcs)) {
658 /* Skip place-holders */
659 pattern = npc_parse_skip_void_and_any_items(pattern);
661 pst->pattern = pattern;
662 rc = parse_stage_funcs[layer](pst);
669 * Parse stage function sets pst->pattern to
670 * 1 past the last item it consumed.
672 pattern = pst->pattern;
678 /* Skip trailing place-holders */
679 pattern = npc_parse_skip_void_and_any_items(pattern);
681 /* Are there more items than what we can handle? */
682 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
683 return NPC_ERR_PATTERN_NOTSUP;
689 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
690 struct roc_npc_flow *flow)
693 return NPC_ERR_PARAM;
694 else if (attr->priority >= npc->flow_max_priority)
695 return NPC_ERR_PARAM;
696 else if ((!attr->egress && !attr->ingress) ||
697 (attr->egress && attr->ingress))
698 return NPC_ERR_PARAM;
701 flow->nix_intf = ROC_NPC_INTF_RX;
703 flow->nix_intf = ROC_NPC_INTF_TX;
705 flow->priority = attr->priority;
710 npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
711 const struct roc_npc_item_info pattern[],
712 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
713 struct npc_parse_state *pst)
715 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
719 err = npc_parse_attr(npc, attr, flow);
724 err = npc_parse_pattern(npc, pattern, flow, pst);
729 err = npc_parse_actions(roc_npc, attr, actions, flow);
736 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
737 const struct roc_npc_item_info pattern[],
738 const struct roc_npc_action actions[],
739 struct roc_npc_flow *flow)
741 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
742 struct npc_parse_state parse_state = {0};
745 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
750 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
752 return npc_program_mcam(npc, &parse_state, 0);
756 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
758 struct plt_bitmap *bmap = npc->rss_grp_entries;
760 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
761 if (!plt_bitmap_get(bmap, *pos))
764 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
768 npc_rss_action_configure(struct roc_npc *roc_npc,
769 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
770 uint32_t *rss_grp, uint32_t mcam_id)
772 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
773 struct roc_nix *roc_nix = roc_npc->roc_nix;
774 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
775 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
776 uint8_t key[ROC_NIX_RSS_KEY_LEN];
777 const uint8_t *key_ptr;
778 uint8_t flowkey_algx;
782 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
783 /* RSS group :0 is not usable for flow rss action */
784 if (rc < 0 || rss_grp_idx == 0)
787 for (i = 0; i < rss->queue_num; i++) {
788 if (rss->queue[i] >= nix->nb_rx_queues) {
789 plt_err("queue id > max number of queues");
794 *rss_grp = rss_grp_idx;
796 if (rss->key == NULL) {
797 roc_nix_rss_key_default_fill(roc_nix, key);
803 roc_nix_rss_key_set(roc_nix, key_ptr);
805 /* If queue count passed in the rss action is less than
806 * HW configured reta size, replicate rss action reta
807 * across HW reta table.
809 reta = nix->reta[rss_grp_idx];
811 if (rss->queue_num > nix->reta_sz) {
812 plt_err("too many queues for RSS context");
816 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
817 memcpy(reta + i * rss->queue_num, rss->queue,
818 sizeof(uint16_t) * rss->queue_num);
820 rem = nix->reta_sz % rss->queue_num;
822 memcpy(&reta[i * rss->queue_num], rss->queue,
823 rem * sizeof(uint16_t));
825 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
827 plt_err("Failed to init rss table rc = %d", rc);
831 flowkey_cfg = roc_npc->flowkey_cfg_state;
833 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
836 plt_err("Failed to set rss hash function rc = %d", rc);
840 *alg_idx = flowkey_algx;
842 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
848 npc_rss_action_program(struct roc_npc *roc_npc,
849 const struct roc_npc_action actions[],
850 struct roc_npc_flow *flow)
852 const struct roc_npc_action_rss *rss;
857 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
858 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
859 rss = (const struct roc_npc_action_rss *)actions->conf;
860 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
861 &rss_grp, flow->mcam_id);
865 flow->npc_action &= (~(0xfULL));
866 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
868 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
869 << NPC_RSS_ACT_ALG_OFFSET) |
870 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
871 << NPC_RSS_ACT_GRP_OFFSET);
879 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
881 struct roc_nix *roc_nix = roc_npc->roc_nix;
882 struct nix_vtag_config *vtag_cfg;
883 struct nix_vtag_config_rsp *rsp;
890 struct nix_tx_vtag_action_s act;
893 nix = roc_nix_to_nix_priv(roc_nix);
894 mbox = (&nix->dev)->mbox;
896 tx_vtag_action.reg = flow->vtag_action;
897 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
899 if (vtag_cfg == NULL)
902 vtag_cfg->cfg_type = VTAG_TX;
903 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
904 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
905 vtag_cfg->tx.free_vtag0 = true;
907 if (flow->vtag_insert_count == 2) {
908 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
909 vtag_cfg->tx.free_vtag1 = true;
912 rc = mbox_process_msg(mbox, (void *)&rsp);
920 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
921 struct roc_npc_flow *flow,
922 struct npc_action_vtag_info *vlan_info,
925 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
930 /* This function parses parameters of one VLAN. When a parameter is
931 * found repeated, it treats it as the end of first VLAN's parameters
932 * and returns. The caller calls again to parse the parameters of the
936 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
937 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
941 const struct roc_npc_action_of_set_vlan_vid *vtag =
942 (const struct roc_npc_action_of_set_vlan_vid *)
945 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
947 if (vlan_info->vlan_id > 0xfff) {
948 plt_err("Invalid vlan_id for set vlan action");
952 flow->vtag_insert_enabled = true;
954 vlan_id_found = true;
955 } else if (actions->type ==
956 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
960 const struct roc_npc_action_of_push_vlan *ethtype =
961 (const struct roc_npc_action_of_push_vlan *)
963 vlan_info->vlan_ethtype =
964 plt_be_to_cpu_16(ethtype->ethertype);
965 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
966 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
967 plt_err("Invalid ethtype specified for push"
971 flow->vtag_insert_enabled = true;
973 ethtype_found = true;
974 } else if (actions->type ==
975 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
978 const struct roc_npc_action_of_set_vlan_pcp *pcp =
979 (const struct roc_npc_action_of_set_vlan_pcp *)
981 vlan_info->vlan_pcp = pcp->vlan_pcp;
982 if (vlan_info->vlan_pcp > 0x7) {
983 plt_err("Invalid PCP value for pcp action");
986 flow->vtag_insert_enabled = true;
998 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
999 struct npc_action_vtag_info *vlan_info)
1001 struct nix_vtag_config *vtag_cfg;
1002 struct nix_vtag_config_rsp *rsp;
1007 struct nix_tx_vtag_action_s act;
1010 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1012 if (vtag_cfg == NULL)
1015 vtag_cfg->cfg_type = VTAG_TX;
1016 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1017 vtag_cfg->tx.vtag0 =
1018 (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
1019 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1021 vtag_cfg->tx.cfg_vtag0 = 1;
1023 if (flow->vtag_insert_count == 2) {
1024 vtag_cfg->tx.vtag1 =
1025 (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
1026 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1028 vtag_cfg->tx.cfg_vtag1 = 1;
1031 rc = mbox_process_msg(mbox, (void *)&rsp);
1035 if (rsp->vtag0_idx < 0 ||
1036 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1037 plt_err("Failed to config TX VTAG action");
1041 tx_vtag_action.reg = 0;
1042 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1043 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1044 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1045 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1047 if (flow->vtag_insert_count == 2) {
1048 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1049 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1050 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1051 /* NIX_TX_VTAG_ACTION_S
1052 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1053 * offset accordingly. Thus, if the two offsets are equal in
1054 * the structure, hardware inserts Vtag 1 immediately after
1055 * Vtag 0 in the packet.
1057 tx_vtag_action.act.vtag1_relptr =
1058 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1061 flow->vtag_action = tx_vtag_action.reg;
1067 npc_vtag_strip_action_configure(struct mbox *mbox,
1068 const struct roc_npc_action actions[],
1069 struct roc_npc_flow *flow, int *strip_cnt)
1071 struct nix_vtag_config *vtag_cfg;
1072 uint64_t rx_vtag_action = 0;
1073 int count = 0, rc = 0;
1077 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1078 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1082 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1084 if (vtag_cfg == NULL)
1087 vtag_cfg->cfg_type = VTAG_RX;
1088 vtag_cfg->rx.strip_vtag = 1;
1089 /* Always capture */
1090 vtag_cfg->rx.capture_vtag = 1;
1091 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1092 vtag_cfg->rx.vtag_type = 0;
1094 rc = mbox_process(mbox);
1098 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1099 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1100 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1102 if (*strip_cnt == 2) {
1103 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1104 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1105 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1107 flow->vtag_action = rx_vtag_action;
1113 npc_vtag_action_program(struct roc_npc *roc_npc,
1114 const struct roc_npc_action actions[],
1115 struct roc_npc_flow *flow)
1117 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1118 const struct roc_npc_action *insert_actions;
1119 struct roc_nix *roc_nix = roc_npc->roc_nix;
1120 struct npc_action_vtag_info vlan_info[2];
1121 int parsed_cnt = 0, strip_cnt = 0;
1122 int tot_vlan_params = 0;
1127 nix = roc_nix_to_nix_priv(roc_nix);
1128 mbox = (&nix->dev)->mbox;
1130 memset(vlan_info, 0, sizeof(vlan_info));
1132 flow->vtag_insert_enabled = false;
1134 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1135 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1136 if (vlan_strip_parsed) {
1137 plt_err("Incorrect VLAN strip actions");
1140 rc = npc_vtag_strip_action_configure(mbox, actions,
1148 vlan_strip_parsed = true;
1149 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1151 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1153 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1154 if (vlan_insert_parsed) {
1155 plt_err("Incorrect VLAN insert actions");
1159 insert_actions = actions;
1161 for (i = 0; i < 2; i++) {
1162 rc = npc_vtag_insert_action_parse(
1163 insert_actions, flow, &vlan_info[i],
1170 insert_actions += parsed_cnt;
1171 tot_vlan_params += parsed_cnt;
1172 flow->vtag_insert_count++;
1175 actions += tot_vlan_params - 1;
1176 vlan_insert_parsed = true;
1180 if (flow->vtag_insert_enabled) {
1181 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1189 struct roc_npc_flow *
1190 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1191 const struct roc_npc_item_info pattern[],
1192 const struct roc_npc_action actions[], int *errcode)
1194 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1195 struct roc_npc_flow *flow, *flow_iter;
1196 struct npc_parse_state parse_state;
1197 struct npc_flow_list *list;
1200 npc->channel = roc_npc->channel;
1201 npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1202 if (npc->is_sdp_link) {
1203 if (roc_npc->is_sdp_mask_set) {
1204 npc->sdp_channel = roc_npc->sdp_channel;
1205 npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1207 /* By default set the channel and mask to cover
1208 * the whole SDP channel range.
1210 npc->sdp_channel = (uint16_t)NIX_CHAN_SDP_CH_START;
1211 npc->sdp_channel_mask = (uint16_t)NIX_CHAN_SDP_CH_START;
1215 flow = plt_zmalloc(sizeof(*flow), 0);
1217 *errcode = NPC_ERR_NO_MEM;
1220 memset(flow, 0, sizeof(*flow));
1222 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
1229 rc = npc_vtag_action_program(roc_npc, actions, flow);
1235 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1237 rc = npc_program_mcam(npc, &parse_state, 1);
1243 rc = npc_rss_action_program(roc_npc, actions, flow);
1246 goto set_rss_failed;
1249 list = &npc->flow_list[flow->priority];
1250 /* List in ascending order of mcam entries */
1251 TAILQ_FOREACH(flow_iter, list, next) {
1252 if (flow_iter->mcam_id > flow->mcam_id) {
1253 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1258 TAILQ_INSERT_TAIL(list, flow, next);
1262 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1274 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1278 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1279 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1280 NPC_RSS_ACT_GRP_MASK;
1281 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1284 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1291 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1293 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1296 rc = npc_rss_group_free(npc, flow);
1298 plt_err("Failed to free rss action rc = %d", rc);
1302 if (flow->vtag_insert_enabled) {
1303 rc = npc_vtag_cfg_delete(roc_npc, flow);
1308 if (flow->ctr_id != NPC_COUNTER_NONE) {
1309 rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
1313 rc = npc_mcam_free_counter(npc, flow->ctr_id);
1318 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1322 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1324 npc_delete_prio_list_entry(npc, flow);
1331 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1333 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1334 struct roc_npc_flow *flow_iter;
1335 struct npc_flow_list *list;
1336 uint32_t max_prio, i;
1338 max_prio = npc->flow_max_priority;
1340 for (i = 0; i < max_prio; i++) {
1341 list = &npc->flow_list[i];
1343 /* List in ascending order of mcam entries */
1344 TAILQ_FOREACH(flow_iter, list, next) {
1345 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1351 roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
1352 struct roc_npc_flow *flow)
1354 struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1355 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1356 struct mcam_entry *base_entry;
1359 if (roc_nix_is_pf(roc_npc->roc_nix))
1362 (void)mbox_alloc_msg_npc_read_base_steer_rule(npc->mbox);
1363 rc = mbox_process_msg(npc->mbox, (void *)&base_rule_rsp);
1365 plt_err("Failed to fetch VF's base MCAM entry");
1368 base_entry = &base_rule_rsp->entry_data;
1369 for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1370 flow->mcam_data[idx] |= base_entry->kw[idx];
1371 flow->mcam_mask[idx] |= base_entry->kw_mask[idx];