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 npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
266 const struct roc_npc_action actions[],
267 struct roc_npc_flow *flow)
269 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
270 const struct roc_npc_action_mark *act_mark;
271 const struct roc_npc_action_meter *act_mtr;
272 const struct roc_npc_action_queue *act_q;
273 const struct roc_npc_action_vf *vf_act;
274 bool vlan_insert_action = false;
275 int sel_act, req_act = 0;
276 uint16_t pf_func, vf_id;
281 /* Initialize actions */
282 flow->ctr_id = NPC_COUNTER_NONE;
283 pf_func = npc->pf_func;
285 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
286 switch (actions->type) {
287 case ROC_NPC_ACTION_TYPE_VOID:
289 case ROC_NPC_ACTION_TYPE_MARK:
290 act_mark = (const struct roc_npc_action_mark *)
292 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
293 plt_err("mark value must be < 0xfffe");
296 mark = act_mark->id + 1;
297 req_act |= ROC_NPC_ACTION_TYPE_MARK;
298 npc->mark_actions += 1;
301 case ROC_NPC_ACTION_TYPE_FLAG:
302 mark = NPC_FLOW_FLAG_VAL;
303 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
304 npc->mark_actions += 1;
307 case ROC_NPC_ACTION_TYPE_COUNT:
308 /* Indicates, need a counter */
310 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
313 case ROC_NPC_ACTION_TYPE_DROP:
314 req_act |= ROC_NPC_ACTION_TYPE_DROP;
317 case ROC_NPC_ACTION_TYPE_PF:
318 req_act |= ROC_NPC_ACTION_TYPE_PF;
322 case ROC_NPC_ACTION_TYPE_VF:
324 (const struct roc_npc_action_vf *)actions->conf;
325 req_act |= ROC_NPC_ACTION_TYPE_VF;
326 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
328 pf_func = (pf_func | (vf_id + 1));
331 case ROC_NPC_ACTION_TYPE_QUEUE:
332 act_q = (const struct roc_npc_action_queue *)
335 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
338 case ROC_NPC_ACTION_TYPE_RSS:
339 req_act |= ROC_NPC_ACTION_TYPE_RSS;
342 case ROC_NPC_ACTION_TYPE_SEC:
343 /* Assumes user has already configured security
344 * session for this flow. Associated conf is
345 * opaque. When security is implemented,
346 * we need to verify that for specified security
349 * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
350 * session_protocol ==
351 * NPC_SECURITY_PROTOCOL_IPSEC
353 req_act |= ROC_NPC_ACTION_TYPE_SEC;
356 /* Special processing when with inline device */
357 if (roc_nix_inb_is_with_inl_dev(roc_npc->roc_nix) &&
358 roc_nix_inl_dev_is_probed()) {
360 pf_func = nix_inl_dev_pffunc_get();
363 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
364 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
366 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
367 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
369 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
370 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
372 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
373 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
375 case ROC_NPC_ACTION_TYPE_METER:
376 act_mtr = (const struct roc_npc_action_meter *)
378 flow->mtr_id = act_mtr->mtr_id;
379 req_act |= ROC_NPC_ACTION_TYPE_METER;
382 errcode = NPC_ERR_ACTION_NOTSUP;
387 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
388 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
389 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
390 vlan_insert_action = true;
392 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
393 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
394 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
395 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
396 plt_err("PCP insert action can't be supported alone");
397 errcode = NPC_ERR_ACTION_NOTSUP;
401 /* Both STRIP and INSERT actions are not supported */
402 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
403 errcode = NPC_ERR_ACTION_NOTSUP;
407 /* Check if actions specified are compatible */
409 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
410 plt_err("VLAN pop action is not supported on Egress");
411 errcode = NPC_ERR_ACTION_NOTSUP;
416 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
417 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
418 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
419 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
420 plt_err("Only VLAN insert, drop, count supported on Egress");
421 errcode = NPC_ERR_ACTION_NOTSUP;
425 if (vlan_insert_action &&
426 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
427 plt_err("Both VLAN insert and drop actions cannot be supported");
428 errcode = NPC_ERR_ACTION_NOTSUP;
432 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
433 flow->npc_action = NIX_TX_ACTIONOP_DROP;
434 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
435 vlan_insert_action) {
436 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
438 plt_err("Unsupported action for egress");
439 errcode = NPC_ERR_ACTION_NOTSUP;
445 if (vlan_insert_action) {
446 errcode = NPC_ERR_ACTION_NOTSUP;
451 /* We have already verified the attr, this is ingress.
452 * - Exactly one terminating action is supported
453 * - Exactly one of MARK or FLAG is supported
454 * - If terminating action is DROP, only count is valid.
456 sel_act = req_act & NPC_ACTION_TERM;
457 if ((sel_act & (sel_act - 1)) != 0) {
458 errcode = NPC_ERR_ACTION_NOTSUP;
462 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
463 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
464 if ((sel_act & (sel_act - 1)) != 0) {
465 errcode = NPC_ERR_ACTION_NOTSUP;
470 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
471 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
472 errcode = NPC_ERR_ACTION_NOTSUP;
476 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
477 npc->vtag_strip_actions++;
479 /* Set NIX_RX_ACTIONOP */
480 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
481 /* Only VLAN action is provided */
482 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
484 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
485 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
486 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
487 flow->npc_action |= (uint64_t)rq << 20;
488 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
489 flow->npc_action = NIX_RX_ACTIONOP_DROP;
490 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
491 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
492 flow->npc_action |= (uint64_t)rq << 20;
493 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
494 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
495 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
496 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
497 flow->npc_action |= (uint64_t)rq << 20;
499 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
500 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
501 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
502 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
503 * This is default action, when user specify only
506 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
508 /* Should never reach here */
509 errcode = NPC_ERR_ACTION_NOTSUP;
514 flow->npc_action |= (uint64_t)mark << 40;
517 /* Ideally AF must ensure that correct pf_func is set */
518 flow->npc_action |= (uint64_t)pf_func << 4;
526 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
529 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
530 struct roc_npc_flow *flow, struct npc_parse_state *pst)
532 npc_parse_stage_func_t parse_stage_funcs[] = {
533 npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
534 npc_parse_la, npc_parse_lb, npc_parse_lc,
535 npc_parse_ld, npc_parse_le, npc_parse_lf,
536 npc_parse_lg, npc_parse_lh,
543 return NPC_ERR_PARAM;
545 memset(pst, 0, sizeof(*pst));
549 /* Use integral byte offset */
550 key_offset = pst->npc->keyx_len[flow->nix_intf];
551 key_offset = (key_offset + 7) / 8;
553 /* Location where LDATA would begin */
554 pst->mcam_data = (uint8_t *)flow->mcam_data;
555 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
557 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
558 layer < PLT_DIM(parse_stage_funcs)) {
559 /* Skip place-holders */
560 pattern = npc_parse_skip_void_and_any_items(pattern);
562 pst->pattern = pattern;
563 rc = parse_stage_funcs[layer](pst);
570 * Parse stage function sets pst->pattern to
571 * 1 past the last item it consumed.
573 pattern = pst->pattern;
579 /* Skip trailing place-holders */
580 pattern = npc_parse_skip_void_and_any_items(pattern);
582 /* Are there more items than what we can handle? */
583 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
584 return NPC_ERR_PATTERN_NOTSUP;
590 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
591 struct roc_npc_flow *flow)
594 return NPC_ERR_PARAM;
595 else if (attr->priority >= npc->flow_max_priority)
596 return NPC_ERR_PARAM;
597 else if ((!attr->egress && !attr->ingress) ||
598 (attr->egress && attr->ingress))
599 return NPC_ERR_PARAM;
602 flow->nix_intf = ROC_NPC_INTF_RX;
604 flow->nix_intf = ROC_NPC_INTF_TX;
606 flow->priority = attr->priority;
611 npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
612 const struct roc_npc_item_info pattern[],
613 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
614 struct npc_parse_state *pst)
616 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
620 err = npc_parse_attr(npc, attr, flow);
625 err = npc_parse_pattern(npc, pattern, flow, pst);
630 err = npc_parse_actions(roc_npc, attr, actions, flow);
637 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
638 const struct roc_npc_item_info pattern[],
639 const struct roc_npc_action actions[],
640 struct roc_npc_flow *flow)
642 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
643 struct npc_parse_state parse_state = {0};
646 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
651 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
653 return npc_program_mcam(npc, &parse_state, 0);
657 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
659 struct plt_bitmap *bmap = npc->rss_grp_entries;
661 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
662 if (!plt_bitmap_get(bmap, *pos))
665 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
669 npc_rss_action_configure(struct roc_npc *roc_npc,
670 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
671 uint32_t *rss_grp, uint32_t mcam_id)
673 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
674 struct roc_nix *roc_nix = roc_npc->roc_nix;
675 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
676 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
677 uint8_t key[ROC_NIX_RSS_KEY_LEN];
678 const uint8_t *key_ptr;
679 uint8_t flowkey_algx;
683 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
684 /* RSS group :0 is not usable for flow rss action */
685 if (rc < 0 || rss_grp_idx == 0)
688 for (i = 0; i < rss->queue_num; i++) {
689 if (rss->queue[i] >= nix->nb_rx_queues) {
690 plt_err("queue id > max number of queues");
695 *rss_grp = rss_grp_idx;
697 if (rss->key == NULL) {
698 roc_nix_rss_key_default_fill(roc_nix, key);
704 roc_nix_rss_key_set(roc_nix, key_ptr);
706 /* If queue count passed in the rss action is less than
707 * HW configured reta size, replicate rss action reta
708 * across HW reta table.
710 reta = nix->reta[rss_grp_idx];
712 if (rss->queue_num > nix->reta_sz) {
713 plt_err("too many queues for RSS context");
717 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
718 memcpy(reta + i * rss->queue_num, rss->queue,
719 sizeof(uint16_t) * rss->queue_num);
721 rem = nix->reta_sz % rss->queue_num;
723 memcpy(&reta[i * rss->queue_num], rss->queue,
724 rem * sizeof(uint16_t));
726 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
728 plt_err("Failed to init rss table rc = %d", rc);
732 flowkey_cfg = roc_npc->flowkey_cfg_state;
734 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
737 plt_err("Failed to set rss hash function rc = %d", rc);
741 *alg_idx = flowkey_algx;
743 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
749 npc_rss_action_program(struct roc_npc *roc_npc,
750 const struct roc_npc_action actions[],
751 struct roc_npc_flow *flow)
753 const struct roc_npc_action_rss *rss;
758 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
759 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
760 rss = (const struct roc_npc_action_rss *)actions->conf;
761 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
762 &rss_grp, flow->mcam_id);
766 flow->npc_action &= (~(0xfULL));
767 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
769 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
770 << NPC_RSS_ACT_ALG_OFFSET) |
771 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
772 << NPC_RSS_ACT_GRP_OFFSET);
780 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
782 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
784 return npc->mark_actions;
788 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
790 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
792 npc->mark_actions -= count;
793 return npc->mark_actions;
797 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
799 struct roc_nix *roc_nix = roc_npc->roc_nix;
800 struct nix_vtag_config *vtag_cfg;
801 struct nix_vtag_config_rsp *rsp;
808 struct nix_tx_vtag_action_s act;
811 nix = roc_nix_to_nix_priv(roc_nix);
812 mbox = (&nix->dev)->mbox;
814 tx_vtag_action.reg = flow->vtag_action;
815 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
817 if (vtag_cfg == NULL)
820 vtag_cfg->cfg_type = VTAG_TX;
821 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
822 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
823 vtag_cfg->tx.free_vtag0 = true;
825 if (flow->vtag_insert_count == 2) {
826 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
827 vtag_cfg->tx.free_vtag1 = true;
830 rc = mbox_process_msg(mbox, (void *)&rsp);
838 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
839 struct roc_npc_flow *flow,
840 struct npc_action_vtag_info *vlan_info,
843 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
848 /* This function parses parameters of one VLAN. When a parameter is
849 * found repeated, it treats it as the end of first VLAN's parameters
850 * and returns. The caller calls again to parse the parameters of the
854 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
855 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
859 const struct roc_npc_action_of_set_vlan_vid *vtag =
860 (const struct roc_npc_action_of_set_vlan_vid *)
863 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
865 if (vlan_info->vlan_id > 0xfff) {
866 plt_err("Invalid vlan_id for set vlan action");
870 flow->vtag_insert_enabled = true;
872 vlan_id_found = true;
873 } else if (actions->type ==
874 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
878 const struct roc_npc_action_of_push_vlan *ethtype =
879 (const struct roc_npc_action_of_push_vlan *)
881 vlan_info->vlan_ethtype =
882 plt_be_to_cpu_16(ethtype->ethertype);
883 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
884 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
885 plt_err("Invalid ethtype specified for push"
889 flow->vtag_insert_enabled = true;
891 ethtype_found = true;
892 } else if (actions->type ==
893 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
896 const struct roc_npc_action_of_set_vlan_pcp *pcp =
897 (const struct roc_npc_action_of_set_vlan_pcp *)
899 vlan_info->vlan_pcp = pcp->vlan_pcp;
900 if (vlan_info->vlan_pcp > 0x7) {
901 plt_err("Invalid PCP value for pcp action");
904 flow->vtag_insert_enabled = true;
916 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
917 struct npc_action_vtag_info *vlan_info)
919 struct nix_vtag_config *vtag_cfg;
920 struct nix_vtag_config_rsp *rsp;
925 struct nix_tx_vtag_action_s act;
928 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
930 if (vtag_cfg == NULL)
933 vtag_cfg->cfg_type = VTAG_TX;
934 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
936 ((vlan_info[0].vlan_ethtype << 16) |
937 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
939 vtag_cfg->tx.cfg_vtag0 = 1;
941 if (flow->vtag_insert_count == 2) {
943 ((vlan_info[1].vlan_ethtype << 16) |
944 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
946 vtag_cfg->tx.cfg_vtag1 = 1;
949 rc = mbox_process_msg(mbox, (void *)&rsp);
953 if (rsp->vtag0_idx < 0 ||
954 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
955 plt_err("Failed to config TX VTAG action");
959 tx_vtag_action.reg = 0;
960 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
961 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
962 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
963 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
965 if (flow->vtag_insert_count == 2) {
966 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
967 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
968 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
969 /* NIX_TX_VTAG_ACTION_S
970 * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
971 * offset accordingly. Thus, if the two offsets are equal in
972 * the structure, hardware inserts Vtag 1 immediately after
973 * Vtag 0 in the packet.
975 tx_vtag_action.act.vtag1_relptr =
976 NIX_TX_VTAGACTION_VTAG0_RELPTR;
979 flow->vtag_action = tx_vtag_action.reg;
985 npc_vtag_strip_action_configure(struct mbox *mbox,
986 const struct roc_npc_action actions[],
987 struct roc_npc_flow *flow, int *strip_cnt)
989 struct nix_vtag_config *vtag_cfg;
990 uint64_t rx_vtag_action = 0;
991 int count = 0, rc = 0;
995 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
996 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1000 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1002 if (vtag_cfg == NULL)
1005 vtag_cfg->cfg_type = VTAG_RX;
1006 vtag_cfg->rx.strip_vtag = 1;
1007 /* Always capture */
1008 vtag_cfg->rx.capture_vtag = 1;
1009 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1010 vtag_cfg->rx.vtag_type = 0;
1012 rc = mbox_process(mbox);
1016 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1017 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1018 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1020 if (*strip_cnt == 2) {
1021 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1022 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1023 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1025 flow->vtag_action = rx_vtag_action;
1031 npc_vtag_action_program(struct roc_npc *roc_npc,
1032 const struct roc_npc_action actions[],
1033 struct roc_npc_flow *flow)
1035 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1036 const struct roc_npc_action *insert_actions;
1037 struct roc_nix *roc_nix = roc_npc->roc_nix;
1038 struct npc_action_vtag_info vlan_info[2];
1039 int parsed_cnt = 0, strip_cnt = 0;
1040 int tot_vlan_params = 0;
1045 nix = roc_nix_to_nix_priv(roc_nix);
1046 mbox = (&nix->dev)->mbox;
1048 memset(vlan_info, 0, sizeof(vlan_info));
1050 flow->vtag_insert_enabled = false;
1052 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1053 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1054 if (vlan_strip_parsed) {
1055 plt_err("Incorrect VLAN strip actions");
1058 rc = npc_vtag_strip_action_configure(mbox, actions,
1066 vlan_strip_parsed = true;
1067 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1069 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1071 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1072 if (vlan_insert_parsed) {
1073 plt_err("Incorrect VLAN insert actions");
1077 insert_actions = actions;
1079 for (i = 0; i < 2; i++) {
1080 rc = npc_vtag_insert_action_parse(
1081 insert_actions, flow, &vlan_info[i],
1088 insert_actions += parsed_cnt;
1089 tot_vlan_params += parsed_cnt;
1090 flow->vtag_insert_count++;
1093 actions += tot_vlan_params - 1;
1094 vlan_insert_parsed = true;
1098 if (flow->vtag_insert_enabled) {
1099 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1107 struct roc_npc_flow *
1108 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1109 const struct roc_npc_item_info pattern[],
1110 const struct roc_npc_action actions[], int *errcode)
1112 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1113 struct roc_npc_flow *flow, *flow_iter;
1114 struct npc_parse_state parse_state;
1115 struct npc_flow_list *list;
1118 npc->channel = roc_npc->channel;
1120 flow = plt_zmalloc(sizeof(*flow), 0);
1122 *errcode = NPC_ERR_NO_MEM;
1125 memset(flow, 0, sizeof(*flow));
1127 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
1134 rc = npc_vtag_action_program(roc_npc, actions, flow);
1140 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1142 rc = npc_program_mcam(npc, &parse_state, 1);
1148 rc = npc_rss_action_program(roc_npc, actions, flow);
1151 goto set_rss_failed;
1154 list = &npc->flow_list[flow->priority];
1155 /* List in ascending order of mcam entries */
1156 TAILQ_FOREACH(flow_iter, list, next) {
1157 if (flow_iter->mcam_id > flow->mcam_id) {
1158 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1163 TAILQ_INSERT_TAIL(list, flow, next);
1167 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1179 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1183 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1184 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1185 NPC_RSS_ACT_GRP_MASK;
1186 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1189 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1196 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1198 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1201 rc = npc_rss_group_free(npc, flow);
1203 plt_err("Failed to free rss action rc = %d", rc);
1207 if (flow->vtag_insert_enabled) {
1208 rc = npc_vtag_cfg_delete(roc_npc, flow);
1213 rc = npc_mcam_free_entry(npc, flow->mcam_id);
1217 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1219 npc_delete_prio_list_entry(npc, flow);
1226 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1228 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1229 struct roc_npc_flow *flow_iter;
1230 struct npc_flow_list *list;
1231 uint32_t max_prio, i;
1233 max_prio = npc->flow_max_priority;
1235 for (i = 0; i < max_prio; i++) {
1236 list = &npc->flow_list[i];
1238 /* List in ascending order of mcam entries */
1239 TAILQ_FOREACH(flow_iter, list, next) {
1240 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1246 roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
1247 struct roc_npc_flow *flow)
1249 struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1250 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1251 struct mcam_entry *base_entry;
1254 if (roc_nix_is_pf(roc_npc->roc_nix))
1257 (void)mbox_alloc_msg_npc_read_base_steer_rule(npc->mbox);
1258 rc = mbox_process_msg(npc->mbox, (void *)&base_rule_rsp);
1260 plt_err("Failed to fetch VF's base MCAM entry");
1263 base_entry = &base_rule_rsp->entry_data;
1264 for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1265 flow->mcam_data[idx] |= base_entry->kw[idx];
1266 flow->mcam_mask[idx] |= base_entry->kw_mask[idx];