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