common/mlx5: fix device list operations concurrency
[dpdk.git] / drivers / common / cnxk / roc_npc.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include "roc_api.h"
6 #include "roc_priv.h"
7
8 int
9 roc_npc_vtag_actions_get(struct roc_npc *roc_npc)
10 {
11         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
12
13         return npc->vtag_strip_actions;
14 }
15
16 int
17 roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
18 {
19         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
20
21         npc->vtag_strip_actions -= count;
22         return npc->vtag_strip_actions;
23 }
24
25 int
26 roc_npc_mcam_free_counter(struct roc_npc *roc_npc, uint16_t ctr_id)
27 {
28         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
29
30         return npc_mcam_free_counter(npc, ctr_id);
31 }
32
33 int
34 roc_npc_mcam_read_counter(struct roc_npc *roc_npc, uint32_t ctr_id,
35                           uint64_t *count)
36 {
37         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
38
39         return npc_mcam_read_counter(npc, ctr_id, count);
40 }
41
42 int
43 roc_npc_mcam_clear_counter(struct roc_npc *roc_npc, uint32_t ctr_id)
44 {
45         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
46
47         return npc_mcam_clear_counter(npc, ctr_id);
48 }
49
50 int
51 roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
52 {
53         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
54
55         return npc_mcam_free_entry(npc, entry);
56 }
57
58 int
59 roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
60 {
61         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
62
63         return npc_flow_free_all_resources(npc);
64 }
65
66 int
67 roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
68                            int *alloc_entry, int req_count, int priority,
69                            int *resp_count)
70 {
71         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
72
73         return npc_mcam_alloc_entries(npc, ref_entry, alloc_entry, req_count,
74                                       priority, resp_count);
75 }
76
77 int
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,
80                          int *resp_count)
81 {
82         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
83
84         return npc_mcam_alloc_entry(npc, mcam, ref_mcam, prio, resp_count);
85 }
86
87 int
88 roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
89                            bool enable)
90 {
91         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
92
93         return npc_mcam_ena_dis_entry(npc, mcam, enable);
94 }
95
96 int
97 roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
98 {
99         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
100
101         return npc_mcam_write_entry(npc, mcam);
102 }
103
104 int
105 roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc)
106 {
107         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
108
109         if (roc_model_is_cn10k())
110                 return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
111         else
112                 return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
113 }
114
115 static int
116 npc_mcam_tot_entries(void)
117 {
118         /* FIXME: change to reading in AF from NPC_AF_CONST1/2
119          * MCAM_BANK_DEPTH(_EXT) * MCAM_BANKS
120          */
121         if (roc_model_is_cn10k() || roc_model_is_cn98xx())
122                 return 16 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 4096 */
123         else
124                 return 4 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 1024 */
125 }
126
127 const char *
128 roc_npc_profile_name_get(struct roc_npc *roc_npc)
129 {
130         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
131
132         return (char *)npc->profile_name;
133 }
134
135 int
136 roc_npc_init(struct roc_npc *roc_npc)
137 {
138         uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
139         struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
140         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
141         uint32_t bmap_sz;
142         int rc = 0, idx;
143         size_t sz;
144
145         PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
146
147         memset(npc, 0, sizeof(*npc));
148         npc->mbox = (&nix->dev)->mbox;
149         roc_npc->channel = nix->rx_chan_base;
150         roc_npc->pf_func = (&nix->dev)->pf_func;
151         npc->channel = roc_npc->channel;
152         npc->pf_func = roc_npc->pf_func;
153         npc->flow_max_priority = roc_npc->flow_max_priority;
154         npc->switch_header_type = roc_npc->switch_header_type;
155         npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
156
157         if (npc->mbox == NULL)
158                 return NPC_ERR_PARAM;
159
160         rc = npc_mcam_fetch_kex_cfg(npc);
161         if (rc)
162                 goto done;
163
164         roc_npc->kex_capability = npc_get_kex_capability(npc);
165         roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
166
167         npc->mark_actions = 0;
168
169         npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
170
171         /* Free, free_rev, live and live_rev entries */
172         bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
173         mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
174         if (mem == NULL) {
175                 plt_err("Bmap alloc failed");
176                 rc = NPC_ERR_NO_MEM;
177                 return rc;
178         }
179
180         sz = npc->flow_max_priority * sizeof(struct npc_mcam_ents_info);
181         npc->flow_entry_info = plt_zmalloc(sz, 0);
182         if (npc->flow_entry_info == NULL) {
183                 plt_err("flow_entry_info alloc failed");
184                 rc = NPC_ERR_NO_MEM;
185                 goto done;
186         }
187
188         sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
189         npc->free_entries = plt_zmalloc(sz, 0);
190         if (npc->free_entries == NULL) {
191                 plt_err("free_entries alloc failed");
192                 rc = NPC_ERR_NO_MEM;
193                 goto done;
194         }
195
196         sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
197         npc->free_entries_rev = plt_zmalloc(sz, 0);
198         if (npc->free_entries_rev == NULL) {
199                 plt_err("free_entries_rev alloc failed");
200                 rc = NPC_ERR_NO_MEM;
201                 goto done;
202         }
203
204         sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
205         npc->live_entries = plt_zmalloc(sz, 0);
206         if (npc->live_entries == NULL) {
207                 plt_err("live_entries alloc failed");
208                 rc = NPC_ERR_NO_MEM;
209                 goto done;
210         }
211
212         sz = npc->flow_max_priority * sizeof(struct plt_bitmap *);
213         npc->live_entries_rev = plt_zmalloc(sz, 0);
214         if (npc->live_entries_rev == NULL) {
215                 plt_err("live_entries_rev alloc failed");
216                 rc = NPC_ERR_NO_MEM;
217                 goto done;
218         }
219
220         sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
221         npc->flow_list = plt_zmalloc(sz, 0);
222         if (npc->flow_list == NULL) {
223                 plt_err("flow_list alloc failed");
224                 rc = NPC_ERR_NO_MEM;
225                 goto done;
226         }
227
228         npc_mem = mem;
229         for (idx = 0; idx < npc->flow_max_priority; idx++) {
230                 TAILQ_INIT(&npc->flow_list[idx]);
231
232                 npc->free_entries[idx] =
233                         plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
234                 mem += bmap_sz;
235
236                 npc->free_entries_rev[idx] =
237                         plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
238                 mem += bmap_sz;
239
240                 npc->live_entries[idx] =
241                         plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
242                 mem += bmap_sz;
243
244                 npc->live_entries_rev[idx] =
245                         plt_bitmap_init(npc->mcam_entries, mem, bmap_sz);
246                 mem += bmap_sz;
247
248                 npc->flow_entry_info[idx].free_ent = 0;
249                 npc->flow_entry_info[idx].live_ent = 0;
250                 npc->flow_entry_info[idx].max_id = 0;
251                 npc->flow_entry_info[idx].min_id = ~(0);
252         }
253
254         npc->rss_grps = NPC_RSS_GRPS;
255
256         bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
257         nix_mem = plt_zmalloc(bmap_sz, 0);
258         if (nix_mem == NULL) {
259                 plt_err("Bmap alloc failed");
260                 rc = NPC_ERR_NO_MEM;
261                 goto done;
262         }
263
264         npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
265
266         if (!npc->rss_grp_entries) {
267                 plt_err("bitmap init failed");
268                 rc = NPC_ERR_NO_MEM;
269                 goto done;
270         }
271
272         /* Group 0 will be used for RSS,
273          * 1 -7 will be used for npc_flow RSS action
274          */
275         plt_bitmap_set(npc->rss_grp_entries, 0);
276
277         return rc;
278
279 done:
280         if (npc->flow_list)
281                 plt_free(npc->flow_list);
282         if (npc->live_entries_rev)
283                 plt_free(npc->live_entries_rev);
284         if (npc->live_entries)
285                 plt_free(npc->live_entries);
286         if (npc->free_entries_rev)
287                 plt_free(npc->free_entries_rev);
288         if (npc->free_entries)
289                 plt_free(npc->free_entries);
290         if (npc->flow_entry_info)
291                 plt_free(npc->flow_entry_info);
292         if (npc_mem)
293                 plt_free(npc_mem);
294         return rc;
295 }
296
297 int
298 roc_npc_fini(struct roc_npc *roc_npc)
299 {
300         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
301         int rc;
302
303         rc = npc_flow_free_all_resources(npc);
304         if (rc) {
305                 plt_err("Error when deleting NPC MCAM entries, counters");
306                 return rc;
307         }
308
309         if (npc->flow_list) {
310                 plt_free(npc->flow_list);
311                 npc->flow_list = NULL;
312         }
313
314         if (npc->live_entries_rev) {
315                 plt_free(npc->live_entries_rev);
316                 npc->live_entries_rev = NULL;
317         }
318
319         if (npc->live_entries) {
320                 plt_free(npc->live_entries);
321                 npc->live_entries = NULL;
322         }
323
324         if (npc->free_entries_rev) {
325                 plt_free(npc->free_entries_rev);
326                 npc->free_entries_rev = NULL;
327         }
328
329         if (npc->free_entries) {
330                 plt_free(npc->free_entries);
331                 npc->free_entries = NULL;
332         }
333
334         if (npc->flow_entry_info) {
335                 plt_free(npc->flow_entry_info);
336                 npc->flow_entry_info = NULL;
337         }
338
339         return 0;
340 }
341
342 static int
343 npc_parse_actions(struct npc *npc, const struct roc_npc_attr *attr,
344                   const struct roc_npc_action actions[],
345                   struct roc_npc_flow *flow)
346 {
347         const struct roc_npc_action_mark *act_mark;
348         const struct roc_npc_action_queue *act_q;
349         const struct roc_npc_action_vf *vf_act;
350         bool vlan_insert_action = false;
351         int sel_act, req_act = 0;
352         uint16_t pf_func, vf_id;
353         int errcode = 0;
354         int mark = 0;
355         int rq = 0;
356
357         /* Initialize actions */
358         flow->ctr_id = NPC_COUNTER_NONE;
359         pf_func = npc->pf_func;
360
361         for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
362                 switch (actions->type) {
363                 case ROC_NPC_ACTION_TYPE_VOID:
364                         break;
365                 case ROC_NPC_ACTION_TYPE_MARK:
366                         act_mark = (const struct roc_npc_action_mark *)
367                                            actions->conf;
368                         if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
369                                 plt_err("mark value must be < 0xfffe");
370                                 goto err_exit;
371                         }
372                         mark = act_mark->id + 1;
373                         req_act |= ROC_NPC_ACTION_TYPE_MARK;
374                         npc->mark_actions += 1;
375                         break;
376
377                 case ROC_NPC_ACTION_TYPE_FLAG:
378                         mark = NPC_FLOW_FLAG_VAL;
379                         req_act |= ROC_NPC_ACTION_TYPE_FLAG;
380                         npc->mark_actions += 1;
381                         break;
382
383                 case ROC_NPC_ACTION_TYPE_COUNT:
384                         /* Indicates, need a counter */
385                         flow->ctr_id = 1;
386                         req_act |= ROC_NPC_ACTION_TYPE_COUNT;
387                         break;
388
389                 case ROC_NPC_ACTION_TYPE_DROP:
390                         req_act |= ROC_NPC_ACTION_TYPE_DROP;
391                         break;
392
393                 case ROC_NPC_ACTION_TYPE_PF:
394                         req_act |= ROC_NPC_ACTION_TYPE_PF;
395                         pf_func &= (0xfc00);
396                         break;
397
398                 case ROC_NPC_ACTION_TYPE_VF:
399                         vf_act =
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;
403                         pf_func &= (0xfc00);
404                         pf_func = (pf_func | (vf_id + 1));
405                         break;
406
407                 case ROC_NPC_ACTION_TYPE_QUEUE:
408                         act_q = (const struct roc_npc_action_queue *)
409                                         actions->conf;
410                         rq = act_q->index;
411                         req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
412                         break;
413
414                 case ROC_NPC_ACTION_TYPE_RSS:
415                         req_act |= ROC_NPC_ACTION_TYPE_RSS;
416                         break;
417
418                 case ROC_NPC_ACTION_TYPE_SEC:
419                         /* Assumes user has already configured security
420                          * session for this flow. Associated conf is
421                          * opaque. When security is implemented,
422                          * we need to verify that for specified security
423                          * session:
424                          *  action_type ==
425                          *    NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
426                          *  session_protocol ==
427                          *    NPC_SECURITY_PROTOCOL_IPSEC
428                          *
429                          * RSS is not supported with inline ipsec. Get the
430                          * rq from associated conf, or make
431                          * ROC_NPC_ACTION_TYPE_QUEUE compulsory with this
432                          * action.
433                          * Currently, rq = 0 is assumed.
434                          */
435                         req_act |= ROC_NPC_ACTION_TYPE_SEC;
436                         rq = 0;
437                         break;
438                 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
439                         req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
440                         break;
441                 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
442                         req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
443                         break;
444                 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
445                         req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
446                         break;
447                 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
448                         req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
449                         break;
450                 default:
451                         errcode = NPC_ERR_ACTION_NOTSUP;
452                         goto err_exit;
453                 }
454         }
455
456         if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
457                        ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
458                        ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
459                 vlan_insert_action = true;
460
461         if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
462                         ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
463                         ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
464             ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
465                 plt_err("PCP insert action can't be supported alone");
466                 errcode = NPC_ERR_ACTION_NOTSUP;
467                 goto err_exit;
468         }
469
470         /* Both STRIP and INSERT actions are not supported */
471         if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
472                 errcode = NPC_ERR_ACTION_NOTSUP;
473                 goto err_exit;
474         }
475
476         /* Check if actions specified are compatible */
477         if (attr->egress) {
478                 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
479                         plt_err("VLAN pop action is not supported on Egress");
480                         errcode = NPC_ERR_ACTION_NOTSUP;
481                         goto err_exit;
482                 }
483
484                 if (req_act &
485                     ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
486                       ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
487                       ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
488                       ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
489                         plt_err("Only VLAN insert, drop, count supported on Egress");
490                         errcode = NPC_ERR_ACTION_NOTSUP;
491                         goto err_exit;
492                 }
493
494                 if (vlan_insert_action &&
495                     (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
496                         plt_err("Both VLAN insert and drop actions cannot be supported");
497                         errcode = NPC_ERR_ACTION_NOTSUP;
498                         goto err_exit;
499                 }
500
501                 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
502                         flow->npc_action = NIX_TX_ACTIONOP_DROP;
503                 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
504                            vlan_insert_action) {
505                         flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
506                 } else {
507                         plt_err("Unsupported action for egress");
508                         errcode = NPC_ERR_ACTION_NOTSUP;
509                         goto err_exit;
510                 }
511
512                 goto set_pf_func;
513         } else {
514                 if (vlan_insert_action) {
515                         errcode = NPC_ERR_ACTION_NOTSUP;
516                         goto err_exit;
517                 }
518         }
519
520         /* We have already verified the attr, this is ingress.
521          * - Exactly one terminating action is supported
522          * - Exactly one of MARK or FLAG is supported
523          * - If terminating action is DROP, only count is valid.
524          */
525         sel_act = req_act & NPC_ACTION_TERM;
526         if ((sel_act & (sel_act - 1)) != 0) {
527                 errcode = NPC_ERR_ACTION_NOTSUP;
528                 goto err_exit;
529         }
530
531         if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
532                 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
533                 if ((sel_act & (sel_act - 1)) != 0) {
534                         errcode = NPC_ERR_ACTION_NOTSUP;
535                         goto err_exit;
536                 }
537         }
538
539         if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
540             (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
541                 errcode = NPC_ERR_ACTION_NOTSUP;
542                 goto err_exit;
543         }
544
545         if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
546                 npc->vtag_strip_actions++;
547
548         /* Set NIX_RX_ACTIONOP */
549         if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
550                 /* Only VLAN action is provided */
551                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
552         } else if (req_act &
553                    (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
554                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
555                 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
556                         flow->npc_action |= (uint64_t)rq << 20;
557         } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
558                 flow->npc_action = NIX_RX_ACTIONOP_DROP;
559         } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
560                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
561                 flow->npc_action |= (uint64_t)rq << 20;
562         } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
563                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
564         } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
565                 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
566                 flow->npc_action |= (uint64_t)rq << 20;
567         } else if (req_act &
568                    (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
569                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
570         } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
571                 /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
572                  * This is default action, when user specify only
573                  * COUNT ACTION
574                  */
575                 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
576         } else {
577                 /* Should never reach here */
578                 errcode = NPC_ERR_ACTION_NOTSUP;
579                 goto err_exit;
580         }
581
582         if (mark)
583                 flow->npc_action |= (uint64_t)mark << 40;
584
585 set_pf_func:
586         /* Ideally AF must ensure that correct pf_func is set */
587         flow->npc_action |= (uint64_t)pf_func << 4;
588
589         return 0;
590
591 err_exit:
592         return errcode;
593 }
594
595 typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
596
597 static int
598 npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
599                   struct roc_npc_flow *flow, struct npc_parse_state *pst)
600 {
601         npc_parse_stage_func_t parse_stage_funcs[] = {
602                 npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
603                 npc_parse_la,         npc_parse_lb,      npc_parse_lc,
604                 npc_parse_ld,         npc_parse_le,      npc_parse_lf,
605                 npc_parse_lg,         npc_parse_lh,
606         };
607         uint8_t layer = 0;
608         int key_offset;
609         int rc;
610
611         if (pattern == NULL)
612                 return NPC_ERR_PARAM;
613
614         memset(pst, 0, sizeof(*pst));
615         pst->npc = npc;
616         pst->flow = flow;
617
618         /* Use integral byte offset */
619         key_offset = pst->npc->keyx_len[flow->nix_intf];
620         key_offset = (key_offset + 7) / 8;
621
622         /* Location where LDATA would begin */
623         pst->mcam_data = (uint8_t *)flow->mcam_data;
624         pst->mcam_mask = (uint8_t *)flow->mcam_mask;
625
626         while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
627                layer < PLT_DIM(parse_stage_funcs)) {
628                 /* Skip place-holders */
629                 pattern = npc_parse_skip_void_and_any_items(pattern);
630
631                 pst->pattern = pattern;
632                 rc = parse_stage_funcs[layer](pst);
633                 if (rc != 0)
634                         return rc;
635
636                 layer++;
637
638                 /*
639                  * Parse stage function sets pst->pattern to
640                  * 1 past the last item it consumed.
641                  */
642                 pattern = pst->pattern;
643
644                 if (pst->terminate)
645                         break;
646         }
647
648         /* Skip trailing place-holders */
649         pattern = npc_parse_skip_void_and_any_items(pattern);
650
651         /* Are there more items than what we can handle? */
652         if (pattern->type != ROC_NPC_ITEM_TYPE_END)
653                 return NPC_ERR_PATTERN_NOTSUP;
654
655         return 0;
656 }
657
658 static int
659 npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
660                struct roc_npc_flow *flow)
661 {
662         if (attr == NULL)
663                 return NPC_ERR_PARAM;
664         else if (attr->priority >= npc->flow_max_priority)
665                 return NPC_ERR_PARAM;
666         else if ((!attr->egress && !attr->ingress) ||
667                  (attr->egress && attr->ingress))
668                 return NPC_ERR_PARAM;
669
670         if (attr->ingress)
671                 flow->nix_intf = ROC_NPC_INTF_RX;
672         else
673                 flow->nix_intf = ROC_NPC_INTF_TX;
674
675         flow->priority = attr->priority;
676         return 0;
677 }
678
679 static int
680 npc_parse_rule(struct npc *npc, const struct roc_npc_attr *attr,
681                const struct roc_npc_item_info pattern[],
682                const struct roc_npc_action actions[], struct roc_npc_flow *flow,
683                struct npc_parse_state *pst)
684 {
685         int err;
686
687         /* Check attr */
688         err = npc_parse_attr(npc, attr, flow);
689         if (err)
690                 return err;
691
692         /* Check pattern */
693         err = npc_parse_pattern(npc, pattern, flow, pst);
694         if (err)
695                 return err;
696
697         /* Check action */
698         err = npc_parse_actions(npc, attr, actions, flow);
699         if (err)
700                 return err;
701         return 0;
702 }
703
704 int
705 roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
706                    const struct roc_npc_item_info pattern[],
707                    const struct roc_npc_action actions[],
708                    struct roc_npc_flow *flow)
709 {
710         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
711         struct npc_parse_state parse_state = {0};
712         int rc;
713
714         rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
715         if (rc)
716                 return rc;
717
718         parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
719
720         return npc_program_mcam(npc, &parse_state, 0);
721 }
722
723 int
724 npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
725 {
726         struct plt_bitmap *bmap = npc->rss_grp_entries;
727
728         for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
729                 if (!plt_bitmap_get(bmap, *pos))
730                         break;
731         }
732         return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
733 }
734
735 int
736 npc_rss_action_configure(struct roc_npc *roc_npc,
737                          const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
738                          uint32_t *rss_grp, uint32_t mcam_id)
739 {
740         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
741         struct roc_nix *roc_nix = roc_npc->roc_nix;
742         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
743         uint32_t flowkey_cfg, rss_grp_idx, i, rem;
744         uint8_t key[ROC_NIX_RSS_KEY_LEN];
745         const uint8_t *key_ptr;
746         uint8_t flowkey_algx;
747         uint16_t *reta;
748         int rc;
749
750         rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
751         /* RSS group :0 is not usable for flow rss action */
752         if (rc < 0 || rss_grp_idx == 0)
753                 return -ENOSPC;
754
755         for (i = 0; i < rss->queue_num; i++) {
756                 if (rss->queue[i] >= nix->nb_rx_queues) {
757                         plt_err("queue id > max number of queues");
758                         return -EINVAL;
759                 }
760         }
761
762         *rss_grp = rss_grp_idx;
763
764         if (rss->key == NULL) {
765                 roc_nix_rss_key_default_fill(roc_nix, key);
766                 key_ptr = key;
767         } else {
768                 key_ptr = rss->key;
769         }
770
771         roc_nix_rss_key_set(roc_nix, key_ptr);
772
773         /* If queue count passed in the rss action is less than
774          * HW configured reta size, replicate rss action reta
775          * across HW reta table.
776          */
777         reta = nix->reta[rss_grp_idx];
778
779         if (rss->queue_num > nix->reta_sz) {
780                 plt_err("too many queues for RSS context");
781                 return -ENOTSUP;
782         }
783
784         for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
785                 memcpy(reta + i * rss->queue_num, rss->queue,
786                        sizeof(uint16_t) * rss->queue_num);
787
788         rem = nix->reta_sz % rss->queue_num;
789         if (rem)
790                 memcpy(&reta[i * rss->queue_num], rss->queue,
791                        rem * sizeof(uint16_t));
792
793         rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
794         if (rc) {
795                 plt_err("Failed to init rss table rc = %d", rc);
796                 return rc;
797         }
798
799         flowkey_cfg = roc_npc->flowkey_cfg_state;
800
801         rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
802                                      *rss_grp, mcam_id);
803         if (rc) {
804                 plt_err("Failed to set rss hash function rc = %d", rc);
805                 return rc;
806         }
807
808         *alg_idx = flowkey_algx;
809
810         plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
811
812         return 0;
813 }
814
815 int
816 npc_rss_action_program(struct roc_npc *roc_npc,
817                        const struct roc_npc_action actions[],
818                        struct roc_npc_flow *flow)
819 {
820         const struct roc_npc_action_rss *rss;
821         uint32_t rss_grp;
822         uint8_t alg_idx;
823         int rc;
824
825         for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
826                 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
827                         rss = (const struct roc_npc_action_rss *)actions->conf;
828                         rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
829                                                       &rss_grp, flow->mcam_id);
830                         if (rc)
831                                 return rc;
832
833                         flow->npc_action &= (~(0xfULL));
834                         flow->npc_action |= NIX_RX_ACTIONOP_RSS;
835                         flow->npc_action |=
836                                 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
837                                  << NPC_RSS_ACT_ALG_OFFSET) |
838                                 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
839                                  << NPC_RSS_ACT_GRP_OFFSET);
840                         break;
841                 }
842         }
843         return 0;
844 }
845
846 int
847 roc_npc_mark_actions_get(struct roc_npc *roc_npc)
848 {
849         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
850
851         return npc->mark_actions;
852 }
853
854 int
855 roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
856 {
857         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
858
859         npc->mark_actions -= count;
860         return npc->mark_actions;
861 }
862
863 static int
864 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
865 {
866         struct roc_nix *roc_nix = roc_npc->roc_nix;
867         struct nix_vtag_config *vtag_cfg;
868         struct nix_vtag_config_rsp *rsp;
869         struct mbox *mbox;
870         struct nix *nix;
871         int rc = 0;
872
873         union {
874                 uint64_t reg;
875                 struct nix_tx_vtag_action_s act;
876         } tx_vtag_action;
877
878         nix = roc_nix_to_nix_priv(roc_nix);
879         mbox = (&nix->dev)->mbox;
880
881         tx_vtag_action.reg = flow->vtag_action;
882         vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
883
884         if (vtag_cfg == NULL)
885                 return -ENOSPC;
886
887         vtag_cfg->cfg_type = VTAG_TX;
888         vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
889         vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
890         vtag_cfg->tx.free_vtag0 = true;
891
892         if (flow->vtag_insert_count == 2) {
893                 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
894                 vtag_cfg->tx.free_vtag1 = true;
895         }
896
897         rc = mbox_process_msg(mbox, (void *)&rsp);
898         if (rc)
899                 return rc;
900
901         return 0;
902 }
903
904 static int
905 npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
906                              struct roc_npc_flow *flow,
907                              struct npc_action_vtag_info *vlan_info,
908                              int *parsed_cnt)
909 {
910         bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
911         int count = 0;
912
913         *parsed_cnt = 0;
914
915         /* This function parses parameters of one VLAN. When a parameter is
916          * found repeated, it treats it as the end of first VLAN's parameters
917          * and returns. The caller calls again to parse the parameters of the
918          * second VLAN.
919          */
920
921         for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
922                 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
923                         if (vlan_id_found)
924                                 return 0;
925
926                         const struct roc_npc_action_of_set_vlan_vid *vtag =
927                                 (const struct roc_npc_action_of_set_vlan_vid *)
928                                         actions->conf;
929
930                         vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
931
932                         if (vlan_info->vlan_id > 0xfff) {
933                                 plt_err("Invalid vlan_id for set vlan action");
934                                 return -EINVAL;
935                         }
936
937                         flow->vtag_insert_enabled = true;
938                         (*parsed_cnt)++;
939                         vlan_id_found = true;
940                 } else if (actions->type ==
941                            ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
942                         if (ethtype_found)
943                                 return 0;
944
945                         const struct roc_npc_action_of_push_vlan *ethtype =
946                                 (const struct roc_npc_action_of_push_vlan *)
947                                         actions->conf;
948                         vlan_info->vlan_ethtype =
949                                 plt_be_to_cpu_16(ethtype->ethertype);
950                         if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
951                             vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
952                                 plt_err("Invalid ethtype specified for push"
953                                         " vlan action");
954                                 return -EINVAL;
955                         }
956                         flow->vtag_insert_enabled = true;
957                         (*parsed_cnt)++;
958                         ethtype_found = true;
959                 } else if (actions->type ==
960                            ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
961                         if (pcp_found)
962                                 return 0;
963                         const struct roc_npc_action_of_set_vlan_pcp *pcp =
964                                 (const struct roc_npc_action_of_set_vlan_pcp *)
965                                         actions->conf;
966                         vlan_info->vlan_pcp = pcp->vlan_pcp;
967                         if (vlan_info->vlan_pcp > 0x7) {
968                                 plt_err("Invalid PCP value for pcp action");
969                                 return -EINVAL;
970                         }
971                         flow->vtag_insert_enabled = true;
972                         (*parsed_cnt)++;
973                         pcp_found = true;
974                 } else {
975                         return 0;
976                 }
977         }
978
979         return 0;
980 }
981
982 static int
983 npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
984                                  struct npc_action_vtag_info *vlan_info)
985 {
986         struct nix_vtag_config *vtag_cfg;
987         struct nix_vtag_config_rsp *rsp;
988         int rc = 0;
989
990         union {
991                 uint64_t reg;
992                 struct nix_tx_vtag_action_s act;
993         } tx_vtag_action;
994
995         vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
996
997         if (vtag_cfg == NULL)
998                 return -ENOSPC;
999
1000         vtag_cfg->cfg_type = VTAG_TX;
1001         vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1002         vtag_cfg->tx.vtag0 =
1003                 ((vlan_info[0].vlan_ethtype << 16) |
1004                  (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1005
1006         vtag_cfg->tx.cfg_vtag0 = 1;
1007
1008         if (flow->vtag_insert_count == 2) {
1009                 vtag_cfg->tx.vtag1 =
1010                         ((vlan_info[1].vlan_ethtype << 16) |
1011                          (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1012
1013                 vtag_cfg->tx.cfg_vtag1 = 1;
1014         }
1015
1016         rc = mbox_process_msg(mbox, (void *)&rsp);
1017         if (rc)
1018                 return rc;
1019
1020         if (rsp->vtag0_idx < 0 ||
1021             ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1022                 plt_err("Failed to config TX VTAG action");
1023                 return -EINVAL;
1024         }
1025
1026         tx_vtag_action.reg = 0;
1027         tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1028         tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1029         tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1030         tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1031
1032         if (flow->vtag_insert_count == 2) {
1033                 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1034                 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1035                 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1036                 /* NIX_TX_VTAG_ACTION_S
1037                  *  If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1038                  *  offset accordingly. Thus, if the two offsets are equal in
1039                  *  the structure, hardware inserts Vtag 1 immediately after
1040                  *  Vtag 0 in the packet.
1041                  */
1042                 tx_vtag_action.act.vtag1_relptr =
1043                         NIX_TX_VTAGACTION_VTAG0_RELPTR;
1044         }
1045
1046         flow->vtag_action = tx_vtag_action.reg;
1047
1048         return 0;
1049 }
1050
1051 static int
1052 npc_vtag_strip_action_configure(struct mbox *mbox,
1053                                 const struct roc_npc_action actions[],
1054                                 struct roc_npc_flow *flow, int *strip_cnt)
1055 {
1056         struct nix_vtag_config *vtag_cfg;
1057         uint64_t rx_vtag_action = 0;
1058         int count = 0, rc = 0;
1059
1060         *strip_cnt = 0;
1061
1062         for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1063                 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1064                         (*strip_cnt)++;
1065         }
1066
1067         vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1068
1069         if (vtag_cfg == NULL)
1070                 return -ENOSPC;
1071
1072         vtag_cfg->cfg_type = VTAG_RX;
1073         vtag_cfg->rx.strip_vtag = 1;
1074         /* Always capture */
1075         vtag_cfg->rx.capture_vtag = 1;
1076         vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1077         vtag_cfg->rx.vtag_type = 0;
1078
1079         rc = mbox_process(mbox);
1080         if (rc)
1081                 return rc;
1082
1083         rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1084         rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1085         rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1086
1087         if (*strip_cnt == 2) {
1088                 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1089                 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1090                 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1091         }
1092         flow->vtag_action = rx_vtag_action;
1093
1094         return 0;
1095 }
1096
1097 static int
1098 npc_vtag_action_program(struct roc_npc *roc_npc,
1099                         const struct roc_npc_action actions[],
1100                         struct roc_npc_flow *flow)
1101 {
1102         bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1103         const struct roc_npc_action *insert_actions;
1104         struct roc_nix *roc_nix = roc_npc->roc_nix;
1105         struct npc_action_vtag_info vlan_info[2];
1106         int parsed_cnt = 0, strip_cnt = 0;
1107         int tot_vlan_params = 0;
1108         struct mbox *mbox;
1109         struct nix *nix;
1110         int i, rc;
1111
1112         nix = roc_nix_to_nix_priv(roc_nix);
1113         mbox = (&nix->dev)->mbox;
1114
1115         memset(vlan_info, 0, sizeof(vlan_info));
1116
1117         flow->vtag_insert_enabled = false;
1118
1119         for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1120                 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1121                         if (vlan_strip_parsed) {
1122                                 plt_err("Incorrect VLAN strip actions");
1123                                 return -EINVAL;
1124                         }
1125                         rc = npc_vtag_strip_action_configure(mbox, actions,
1126                                                              flow, &strip_cnt);
1127                         if (rc)
1128                                 return rc;
1129
1130                         if (strip_cnt == 2)
1131                                 actions++;
1132
1133                         vlan_strip_parsed = true;
1134                 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1135                            actions->type ==
1136                                    ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1137                            actions->type ==
1138                                    ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1139                         if (vlan_insert_parsed) {
1140                                 plt_err("Incorrect VLAN insert actions");
1141                                 return -EINVAL;
1142                         }
1143
1144                         insert_actions = actions;
1145
1146                         for (i = 0; i < 2; i++) {
1147                                 rc = npc_vtag_insert_action_parse(
1148                                         insert_actions, flow, &vlan_info[i],
1149                                         &parsed_cnt);
1150
1151                                 if (rc)
1152                                         return rc;
1153
1154                                 if (parsed_cnt) {
1155                                         insert_actions += parsed_cnt;
1156                                         tot_vlan_params += parsed_cnt;
1157                                         flow->vtag_insert_count++;
1158                                 }
1159                         }
1160                         actions += tot_vlan_params - 1;
1161                         vlan_insert_parsed = true;
1162                 }
1163         }
1164
1165         if (flow->vtag_insert_enabled) {
1166                 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1167
1168                 if (rc)
1169                         return rc;
1170         }
1171         return 0;
1172 }
1173
1174 struct roc_npc_flow *
1175 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1176                     const struct roc_npc_item_info pattern[],
1177                     const struct roc_npc_action actions[], int *errcode)
1178 {
1179         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1180         struct roc_npc_flow *flow, *flow_iter;
1181         struct npc_parse_state parse_state;
1182         struct npc_flow_list *list;
1183         int rc;
1184
1185         npc->channel = roc_npc->channel;
1186
1187         flow = plt_zmalloc(sizeof(*flow), 0);
1188         if (flow == NULL) {
1189                 *errcode = NPC_ERR_NO_MEM;
1190                 return NULL;
1191         }
1192         memset(flow, 0, sizeof(*flow));
1193
1194         rc = npc_parse_rule(npc, attr, pattern, actions, flow, &parse_state);
1195         if (rc != 0) {
1196                 *errcode = rc;
1197                 goto err_exit;
1198         }
1199
1200         rc = npc_vtag_action_program(roc_npc, actions, flow);
1201         if (rc != 0) {
1202                 *errcode = rc;
1203                 goto err_exit;
1204         }
1205
1206         parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1207
1208         rc = npc_program_mcam(npc, &parse_state, 1);
1209         if (rc != 0) {
1210                 *errcode = rc;
1211                 goto err_exit;
1212         }
1213
1214         rc = npc_rss_action_program(roc_npc, actions, flow);
1215         if (rc != 0) {
1216                 *errcode = rc;
1217                 goto set_rss_failed;
1218         }
1219
1220         list = &npc->flow_list[flow->priority];
1221         /* List in ascending order of mcam entries */
1222         TAILQ_FOREACH(flow_iter, list, next) {
1223                 if (flow_iter->mcam_id > flow->mcam_id) {
1224                         TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1225                         return flow;
1226                 }
1227         }
1228
1229         TAILQ_INSERT_TAIL(list, flow, next);
1230         return flow;
1231
1232 set_rss_failed:
1233         rc = npc_mcam_free_entry(npc, flow->mcam_id);
1234         if (rc != 0) {
1235                 *errcode = rc;
1236                 plt_free(flow);
1237                 return NULL;
1238         }
1239 err_exit:
1240         plt_free(flow);
1241         return NULL;
1242 }
1243
1244 int
1245 npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1246 {
1247         uint32_t rss_grp;
1248
1249         if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1250                 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1251                           NPC_RSS_ACT_GRP_MASK;
1252                 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1253                         return -EINVAL;
1254
1255                 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1256         }
1257
1258         return 0;
1259 }
1260
1261 int
1262 roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1263 {
1264         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1265         struct plt_bitmap *bmap;
1266         int rc;
1267
1268         rc = npc_rss_group_free(npc, flow);
1269         if (rc != 0) {
1270                 plt_err("Failed to free rss action rc = %d", rc);
1271                 return rc;
1272         }
1273
1274         if (flow->vtag_insert_enabled) {
1275                 rc = npc_vtag_cfg_delete(roc_npc, flow);
1276                 if (rc != 0)
1277                         return rc;
1278         }
1279
1280         rc = npc_mcam_free_entry(npc, flow->mcam_id);
1281         if (rc != 0)
1282                 return rc;
1283
1284         TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1285
1286         bmap = npc->live_entries[flow->priority];
1287         plt_bitmap_clear(bmap, flow->mcam_id);
1288
1289         plt_free(flow);
1290         return 0;
1291 }
1292
1293 void
1294 roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1295 {
1296         struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1297         struct roc_npc_flow *flow_iter;
1298         struct npc_flow_list *list;
1299         uint32_t max_prio, i;
1300
1301         max_prio = npc->flow_max_priority;
1302
1303         for (i = 0; i < max_prio; i++) {
1304                 list = &npc->flow_list[i];
1305
1306                 /* List in ascending order of mcam entries */
1307                 TAILQ_FOREACH(flow_iter, list, next) {
1308                         roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1309                 }
1310         }
1311 }