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