1
2
3
4
5#include "roc_api.h"
6#include "roc_priv.h"
7
8int
9roc_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
16int
17roc_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
25int
26roc_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
33int
34roc_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
42int
43roc_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
50int
51roc_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
58int
59roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
60{
61 int rc = 0;
62
63 if (mcam->use_ctr) {
64 rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
65 if (rc)
66 return rc;
67
68 rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
69 if (rc)
70 return rc;
71 }
72
73 return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
74}
75
76int
77roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
78 int mcam_id)
79{
80 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
81 int rc;
82
83 rc = npc_mcam_init(npc, flow, mcam_id);
84 if (rc != 0) {
85 plt_err("npc: mcam initialisation write failed");
86 return rc;
87 }
88 return 0;
89}
90
91int
92roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
93{
94 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
95 struct mbox *mbox = npc->mbox;
96 int rc;
97
98 rc = npc_mcam_move(mbox, old_ent, new_ent);
99 if (rc)
100 return rc;
101
102 return 0;
103}
104
105int
106roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
107{
108 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
109
110 return npc_flow_free_all_resources(npc);
111}
112
113int
114roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
115 int *alloc_entry, int req_count, int priority,
116 int *resp_count)
117{
118 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
119
120 return npc_mcam_alloc_entries(npc, ref_entry, alloc_entry, req_count,
121 priority, resp_count);
122}
123
124int
125roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc, bool enable)
126{
127 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
128
129 return npc_flow_enable_all_entries(npc, enable);
130}
131
132int
133roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
134 struct roc_npc_flow *ref_mcam, int prio,
135 int *resp_count)
136{
137 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
138
139 return npc_mcam_alloc_entry(npc, mcam, ref_mcam, prio, resp_count);
140}
141
142int
143roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
144 bool enable)
145{
146 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
147
148 return npc_mcam_ena_dis_entry(npc, mcam, enable);
149}
150
151int
152roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
153{
154 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
155
156 return npc_mcam_write_entry(npc, mcam);
157}
158
159int
160roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc)
161{
162 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
163
164 if (roc_model_is_cn10k())
165 return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
166 else if (roc_model_is_cn98xx())
167 return (npc->mcam_entries - NPC_MCAME_RESVD_98XX - 1);
168 else
169 return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
170}
171
172static int
173npc_mcam_tot_entries(void)
174{
175
176
177
178 if (roc_model_is_cn10k() || roc_model_is_cn98xx())
179 return 16 * 1024;
180 else
181 return 4 * 1024;
182}
183
184const char *
185roc_npc_profile_name_get(struct roc_npc *roc_npc)
186{
187 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
188
189 return (char *)npc->profile_name;
190}
191
192int
193roc_npc_init(struct roc_npc *roc_npc)
194{
195 uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
196 struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
197 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
198 uint32_t bmap_sz;
199 int rc = 0, idx;
200 size_t sz;
201
202 PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
203
204 memset(npc, 0, sizeof(*npc));
205 npc->mbox = (&nix->dev)->mbox;
206 roc_npc->channel = nix->rx_chan_base;
207 roc_npc->pf_func = (&nix->dev)->pf_func;
208 npc->channel = roc_npc->channel;
209 npc->pf_func = roc_npc->pf_func;
210 npc->flow_max_priority = roc_npc->flow_max_priority;
211 npc->switch_header_type = roc_npc->switch_header_type;
212 npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
213
214 if (npc->mbox == NULL)
215 return NPC_ERR_PARAM;
216
217 rc = npc_mcam_fetch_kex_cfg(npc);
218 if (rc)
219 goto done;
220
221 roc_npc->kex_capability = npc_get_kex_capability(npc);
222 roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
223
224 npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
225
226
227 bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
228 mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
229 if (mem == NULL) {
230 plt_err("Bmap alloc failed");
231 rc = NPC_ERR_NO_MEM;
232 return rc;
233 }
234
235 sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
236 npc->flow_list = plt_zmalloc(sz, 0);
237 if (npc->flow_list == NULL) {
238 plt_err("flow_list alloc failed");
239 rc = NPC_ERR_NO_MEM;
240 goto done;
241 }
242
243 sz = npc->flow_max_priority * sizeof(struct npc_prio_flow_list_head);
244 npc->prio_flow_list = plt_zmalloc(sz, 0);
245 if (npc->prio_flow_list == NULL) {
246 plt_err("prio_flow_list alloc failed");
247 rc = NPC_ERR_NO_MEM;
248 goto done;
249 }
250
251 npc_mem = mem;
252 for (idx = 0; idx < npc->flow_max_priority; idx++) {
253 TAILQ_INIT(&npc->flow_list[idx]);
254 TAILQ_INIT(&npc->prio_flow_list[idx]);
255 }
256
257 npc->rss_grps = NPC_RSS_GRPS;
258
259 bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
260 nix_mem = plt_zmalloc(bmap_sz, 0);
261 if (nix_mem == NULL) {
262 plt_err("Bmap alloc failed");
263 rc = NPC_ERR_NO_MEM;
264 goto done;
265 }
266
267 npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
268
269 if (!npc->rss_grp_entries) {
270 plt_err("bitmap init failed");
271 rc = NPC_ERR_NO_MEM;
272 goto done;
273 }
274
275
276
277
278 plt_bitmap_set(npc->rss_grp_entries, 0);
279
280 return rc;
281
282done:
283 if (npc->flow_list)
284 plt_free(npc->flow_list);
285 if (npc->prio_flow_list)
286 plt_free(npc->prio_flow_list);
287 if (npc_mem)
288 plt_free(npc_mem);
289 return rc;
290}
291
292int
293roc_npc_fini(struct roc_npc *roc_npc)
294{
295 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
296 int rc;
297
298 rc = npc_flow_free_all_resources(npc);
299 if (rc) {
300 plt_err("Error when deleting NPC MCAM entries, counters");
301 return rc;
302 }
303
304 if (npc->flow_list) {
305 plt_free(npc->flow_list);
306 npc->flow_list = NULL;
307 }
308
309 if (npc->prio_flow_list) {
310 plt_free(npc->prio_flow_list);
311 npc->prio_flow_list = NULL;
312 }
313
314 return 0;
315}
316
317int
318roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
319 struct roc_npc *roc_npc_dst)
320{
321 struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
322 struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
323 struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
324 struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
325
326 if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
327 plt_err("Output port should be VF");
328 return -EINVAL;
329 }
330
331 if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
332 plt_err("Invalid VF for output port");
333 return -EINVAL;
334 }
335
336 if (nix_src->dev.pf != nix_dst->dev.pf) {
337 plt_err("Output port should be VF of ingress PF");
338 return -EINVAL;
339 }
340 return 0;
341}
342
343static int
344npc_parse_msns_action(struct roc_npc *roc_npc, const struct roc_npc_action *act,
345 struct roc_npc_flow *flow, uint8_t *has_msns_action)
346{
347 const struct roc_npc_sec_action *sec_action;
348 union {
349 uint64_t reg;
350 union nix_rx_vtag_action_u act;
351 } vtag_act;
352
353 if (roc_npc->roc_nix->custom_sa_action == 0 ||
354 roc_model_is_cn9k() == 1 || act->conf == NULL)
355 return 0;
356
357 *has_msns_action = true;
358 sec_action = act->conf;
359
360 vtag_act.reg = 0;
361 vtag_act.act.sa_xor = sec_action->sa_xor;
362 vtag_act.act.sa_hi = sec_action->sa_hi;
363 vtag_act.act.sa_lo = sec_action->sa_lo;
364
365 switch (sec_action->alg) {
366 case ROC_NPC_SEC_ACTION_ALG0:
367 break;
368 case ROC_NPC_SEC_ACTION_ALG1:
369 vtag_act.act.vtag1_valid = false;
370 vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG1;
371 break;
372 case ROC_NPC_SEC_ACTION_ALG2:
373 vtag_act.act.vtag1_valid = false;
374 vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG2;
375 break;
376 default:
377 return -1;
378 }
379
380 flow->vtag_action = vtag_act.reg;
381
382 return 0;
383}
384
385static int
386npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
387 const struct roc_npc_action actions[],
388 struct roc_npc_flow *flow)
389{
390 const struct roc_npc_action_port_id *act_portid;
391 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
392 const struct roc_npc_action_mark *act_mark;
393 const struct roc_npc_action_meter *act_mtr;
394 const struct roc_npc_action_queue *act_q;
395 const struct roc_npc_action_vf *vf_act;
396 bool vlan_insert_action = false;
397 uint8_t has_msns_act = 0;
398 int sel_act, req_act = 0;
399 uint16_t pf_func, vf_id;
400 struct roc_nix *roc_nix;
401 int errcode = 0;
402 int mark = 0;
403 int rq = 0;
404 int rc = 0;
405
406
407 flow->ctr_id = NPC_COUNTER_NONE;
408 flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
409 pf_func = npc->pf_func;
410
411 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
412 switch (actions->type) {
413 case ROC_NPC_ACTION_TYPE_VOID:
414 break;
415 case ROC_NPC_ACTION_TYPE_MARK:
416 act_mark = (const struct roc_npc_action_mark *)
417 actions->conf;
418 if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
419 plt_err("mark value must be < 0xfffe");
420 goto err_exit;
421 }
422 mark = act_mark->id + 1;
423 req_act |= ROC_NPC_ACTION_TYPE_MARK;
424 break;
425
426 case ROC_NPC_ACTION_TYPE_FLAG:
427 mark = NPC_FLOW_FLAG_VAL;
428 req_act |= ROC_NPC_ACTION_TYPE_FLAG;
429 break;
430
431 case ROC_NPC_ACTION_TYPE_COUNT:
432
433 flow->use_ctr = 1;
434 req_act |= ROC_NPC_ACTION_TYPE_COUNT;
435 break;
436
437 case ROC_NPC_ACTION_TYPE_DROP:
438 req_act |= ROC_NPC_ACTION_TYPE_DROP;
439 break;
440
441 case ROC_NPC_ACTION_TYPE_PF:
442 req_act |= ROC_NPC_ACTION_TYPE_PF;
443 pf_func &= (0xfc00);
444 break;
445
446 case ROC_NPC_ACTION_TYPE_VF:
447 vf_act =
448 (const struct roc_npc_action_vf *)actions->conf;
449 req_act |= ROC_NPC_ACTION_TYPE_VF;
450 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
451 pf_func &= (0xfc00);
452 pf_func = (pf_func | (vf_id + 1));
453 break;
454
455 case ROC_NPC_ACTION_TYPE_PORT_ID:
456 act_portid = (const struct roc_npc_action_port_id *)
457 actions->conf;
458 pf_func &= (0xfc00);
459 pf_func = (pf_func | (act_portid->id + 1));
460 req_act |= ROC_NPC_ACTION_TYPE_VF;
461 break;
462
463 case ROC_NPC_ACTION_TYPE_QUEUE:
464 act_q = (const struct roc_npc_action_queue *)
465 actions->conf;
466 rq = act_q->index;
467 req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
468 break;
469
470 case ROC_NPC_ACTION_TYPE_RSS:
471 req_act |= ROC_NPC_ACTION_TYPE_RSS;
472 break;
473
474 case ROC_NPC_ACTION_TYPE_SEC:
475
476
477
478
479
480
481
482
483
484
485 req_act |= ROC_NPC_ACTION_TYPE_SEC;
486 rq = 0;
487 roc_nix = roc_npc->roc_nix;
488
489
490 if (roc_nix_inb_is_with_inl_dev(roc_nix) &&
491 roc_nix_inl_dev_is_probed()) {
492 struct roc_nix_rq *inl_rq;
493
494 inl_rq = roc_nix_inl_dev_rq(roc_nix);
495 if (!inl_rq) {
496 errcode = NPC_ERR_INTERNAL;
497 goto err_exit;
498 }
499 rq = inl_rq->qid;
500 pf_func = nix_inl_dev_pffunc_get();
501 }
502 rc = npc_parse_msns_action(roc_npc, actions, flow,
503 &has_msns_act);
504 if (rc) {
505 errcode = NPC_ERR_ACTION_NOTSUP;
506 goto err_exit;
507 }
508 break;
509 case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
510 req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
511 break;
512 case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
513 req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
514 break;
515 case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
516 req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
517 break;
518 case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
519 req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
520 break;
521 case ROC_NPC_ACTION_TYPE_METER:
522 act_mtr = (const struct roc_npc_action_meter *)
523 actions->conf;
524 flow->mtr_id = act_mtr->mtr_id;
525 req_act |= ROC_NPC_ACTION_TYPE_METER;
526 break;
527 default:
528 errcode = NPC_ERR_ACTION_NOTSUP;
529 goto err_exit;
530 }
531 }
532
533 if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
534 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
535 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
536 vlan_insert_action = true;
537
538 if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT |
539 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
540 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
541 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
542 plt_err("PCP insert action can't be supported alone");
543 errcode = NPC_ERR_ACTION_NOTSUP;
544 goto err_exit;
545 }
546
547 if (has_msns_act && (vlan_insert_action ||
548 (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP))) {
549 plt_err("Both MSNS and VLAN insert/strip action can't be supported"
550 " together");
551 errcode = NPC_ERR_ACTION_NOTSUP;
552 goto err_exit;
553 }
554
555
556 if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
557 errcode = NPC_ERR_ACTION_NOTSUP;
558 goto err_exit;
559 }
560
561
562 if (attr->egress) {
563 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
564 plt_err("VLAN pop action is not supported on Egress");
565 errcode = NPC_ERR_ACTION_NOTSUP;
566 goto err_exit;
567 }
568
569 if (req_act &
570 ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT |
571 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
572 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT |
573 ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_COUNT)) {
574 plt_err("Only VLAN insert, drop, count supported on Egress");
575 errcode = NPC_ERR_ACTION_NOTSUP;
576 goto err_exit;
577 }
578
579 if (vlan_insert_action &&
580 (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
581 plt_err("Both VLAN insert and drop actions cannot be supported");
582 errcode = NPC_ERR_ACTION_NOTSUP;
583 goto err_exit;
584 }
585
586 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
587 flow->npc_action = NIX_TX_ACTIONOP_DROP;
588 } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) ||
589 vlan_insert_action) {
590 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
591 } else {
592 plt_err("Unsupported action for egress");
593 errcode = NPC_ERR_ACTION_NOTSUP;
594 goto err_exit;
595 }
596
597 goto set_pf_func;
598 } else {
599 if (vlan_insert_action) {
600 errcode = NPC_ERR_ACTION_NOTSUP;
601 goto err_exit;
602 }
603 }
604
605
606
607
608
609
610 sel_act = req_act & NPC_ACTION_TERM;
611 if ((sel_act & (sel_act - 1)) != 0) {
612 errcode = NPC_ERR_ACTION_NOTSUP;
613 goto err_exit;
614 }
615
616 if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
617 sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
618 if ((sel_act & (sel_act - 1)) != 0) {
619 errcode = NPC_ERR_ACTION_NOTSUP;
620 goto err_exit;
621 }
622 }
623
624 if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
625 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
626 errcode = NPC_ERR_ACTION_NOTSUP;
627 goto err_exit;
628 }
629
630 if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
631 npc->vtag_strip_actions++;
632
633
634 if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
635
636 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
637 } else if (req_act &
638 (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
639 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
640 if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
641 flow->npc_action |= (uint64_t)rq << 20;
642 } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
643 flow->npc_action = NIX_RX_ACTIONOP_DROP;
644 } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
645 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
646 flow->npc_action |= (uint64_t)rq << 20;
647 } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
648 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
649 } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
650 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
651 flow->npc_action |= (uint64_t)rq << 20;
652 } else if (req_act &
653 (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
654 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
655 } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
656
657
658
659
660 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
661 } else {
662
663 errcode = NPC_ERR_ACTION_NOTSUP;
664 goto err_exit;
665 }
666
667 if (mark)
668 flow->npc_action |= (uint64_t)mark << 40;
669
670set_pf_func:
671
672 flow->npc_action |= (uint64_t)pf_func << 4;
673
674 return 0;
675
676err_exit:
677 return errcode;
678}
679
680typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
681
682static int
683npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
684 struct roc_npc_flow *flow, struct npc_parse_state *pst)
685{
686 npc_parse_stage_func_t parse_stage_funcs[] = {
687 npc_parse_meta_items, npc_parse_mark_item, npc_parse_pre_l2,
688 npc_parse_cpt_hdr, npc_parse_higig2_hdr, npc_parse_la,
689 npc_parse_lb, npc_parse_lc, npc_parse_ld,
690 npc_parse_le, npc_parse_lf, npc_parse_lg,
691 npc_parse_lh,
692 };
693 uint8_t layer = 0;
694 int key_offset;
695 int rc;
696
697 if (pattern == NULL)
698 return NPC_ERR_PARAM;
699
700 memset(pst, 0, sizeof(*pst));
701 pst->npc = npc;
702 pst->flow = flow;
703
704
705 key_offset = pst->npc->keyx_len[flow->nix_intf];
706 key_offset = (key_offset + 7) / 8;
707
708
709 pst->mcam_data = (uint8_t *)flow->mcam_data;
710 pst->mcam_mask = (uint8_t *)flow->mcam_mask;
711
712 while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
713 layer < PLT_DIM(parse_stage_funcs)) {
714
715 pattern = npc_parse_skip_void_and_any_items(pattern);
716
717 pst->pattern = pattern;
718 rc = parse_stage_funcs[layer](pst);
719 if (rc != 0)
720 return rc;
721
722 layer++;
723
724
725
726
727
728 pattern = pst->pattern;
729
730 if (pst->terminate)
731 break;
732 }
733
734
735 pattern = npc_parse_skip_void_and_any_items(pattern);
736
737
738 if (pattern->type != ROC_NPC_ITEM_TYPE_END)
739 return NPC_ERR_PATTERN_NOTSUP;
740
741 return 0;
742}
743
744static int
745npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
746 struct roc_npc_flow *flow)
747{
748 if (attr == NULL)
749 return NPC_ERR_PARAM;
750 else if (attr->priority >= npc->flow_max_priority)
751 return NPC_ERR_PARAM;
752 else if ((!attr->egress && !attr->ingress) ||
753 (attr->egress && attr->ingress))
754 return NPC_ERR_PARAM;
755
756 if (attr->ingress)
757 flow->nix_intf = ROC_NPC_INTF_RX;
758 else
759 flow->nix_intf = ROC_NPC_INTF_TX;
760
761 flow->priority = attr->priority;
762 return 0;
763}
764
765static int
766npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
767 const struct roc_npc_item_info pattern[],
768 const struct roc_npc_action actions[], struct roc_npc_flow *flow,
769 struct npc_parse_state *pst)
770{
771 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
772 int err;
773
774
775 err = npc_parse_attr(npc, attr, flow);
776 if (err)
777 return err;
778
779
780 err = npc_parse_pattern(npc, pattern, flow, pst);
781 if (err)
782 return err;
783
784
785 err = npc_parse_actions(roc_npc, attr, actions, flow);
786 if (err)
787 return err;
788 return 0;
789}
790
791int
792roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
793 const struct roc_npc_item_info pattern[],
794 const struct roc_npc_action actions[],
795 struct roc_npc_flow *flow)
796{
797 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
798 struct npc_parse_state parse_state = {0};
799 int rc;
800
801 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
802 &parse_state);
803 if (rc)
804 return rc;
805
806 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
807
808 return npc_program_mcam(npc, &parse_state, 0);
809}
810
811int
812npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
813{
814 struct plt_bitmap *bmap = npc->rss_grp_entries;
815
816 for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
817 if (!plt_bitmap_get(bmap, *pos))
818 break;
819 }
820 return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
821}
822
823int
824npc_rss_action_configure(struct roc_npc *roc_npc,
825 const struct roc_npc_action_rss *rss, uint8_t *alg_idx,
826 uint32_t *rss_grp, uint32_t mcam_id)
827{
828 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
829 struct roc_nix *roc_nix = roc_npc->roc_nix;
830 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
831 uint32_t flowkey_cfg, rss_grp_idx, i, rem;
832 uint8_t key[ROC_NIX_RSS_KEY_LEN];
833 const uint8_t *key_ptr;
834 uint8_t flowkey_algx;
835 uint16_t *reta;
836 int rc;
837
838 rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
839
840 if (rc < 0 || rss_grp_idx == 0)
841 return -ENOSPC;
842
843 for (i = 0; i < rss->queue_num; i++) {
844 if (rss->queue[i] >= nix->nb_rx_queues) {
845 plt_err("queue id > max number of queues");
846 return -EINVAL;
847 }
848 }
849
850 *rss_grp = rss_grp_idx;
851
852 if (rss->key == NULL) {
853 roc_nix_rss_key_default_fill(roc_nix, key);
854 key_ptr = key;
855 } else {
856 key_ptr = rss->key;
857 }
858
859 roc_nix_rss_key_set(roc_nix, key_ptr);
860
861
862
863
864
865 reta = nix->reta[rss_grp_idx];
866
867 if (rss->queue_num > nix->reta_sz) {
868 plt_err("too many queues for RSS context");
869 return -ENOTSUP;
870 }
871
872 for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
873 memcpy(reta + i * rss->queue_num, rss->queue,
874 sizeof(uint16_t) * rss->queue_num);
875
876 rem = nix->reta_sz % rss->queue_num;
877 if (rem)
878 memcpy(&reta[i * rss->queue_num], rss->queue,
879 rem * sizeof(uint16_t));
880
881 rc = roc_nix_rss_reta_set(roc_nix, *rss_grp, reta);
882 if (rc) {
883 plt_err("Failed to init rss table rc = %d", rc);
884 return rc;
885 }
886
887 flowkey_cfg = roc_npc->flowkey_cfg_state;
888
889 rc = roc_nix_rss_flowkey_set(roc_nix, &flowkey_algx, flowkey_cfg,
890 *rss_grp, mcam_id);
891 if (rc) {
892 plt_err("Failed to set rss hash function rc = %d", rc);
893 return rc;
894 }
895
896 *alg_idx = flowkey_algx;
897
898 plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
899
900 return 0;
901}
902
903int
904npc_rss_action_program(struct roc_npc *roc_npc,
905 const struct roc_npc_action actions[],
906 struct roc_npc_flow *flow)
907{
908 const struct roc_npc_action_rss *rss;
909 uint32_t rss_grp;
910 uint8_t alg_idx;
911 int rc;
912
913 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
914 if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
915 rss = (const struct roc_npc_action_rss *)actions->conf;
916 rc = npc_rss_action_configure(roc_npc, rss, &alg_idx,
917 &rss_grp, flow->mcam_id);
918 if (rc)
919 return rc;
920
921 flow->npc_action &= (~(0xfULL));
922 flow->npc_action |= NIX_RX_ACTIONOP_RSS;
923 flow->npc_action |=
924 ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
925 << NPC_RSS_ACT_ALG_OFFSET) |
926 ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
927 << NPC_RSS_ACT_GRP_OFFSET);
928 break;
929 }
930 }
931 return 0;
932}
933
934static int
935npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
936{
937 struct roc_nix *roc_nix = roc_npc->roc_nix;
938 struct nix_vtag_config *vtag_cfg;
939 struct nix_vtag_config_rsp *rsp;
940 struct mbox *mbox;
941 struct nix *nix;
942 int rc = 0;
943
944 union {
945 uint64_t reg;
946 struct nix_tx_vtag_action_s act;
947 } tx_vtag_action;
948
949 nix = roc_nix_to_nix_priv(roc_nix);
950 mbox = (&nix->dev)->mbox;
951
952 tx_vtag_action.reg = flow->vtag_action;
953 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
954
955 if (vtag_cfg == NULL)
956 return -ENOSPC;
957
958 vtag_cfg->cfg_type = VTAG_TX;
959 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
960 vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
961 vtag_cfg->tx.free_vtag0 = true;
962
963 if (flow->vtag_insert_count == 2) {
964 vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
965 vtag_cfg->tx.free_vtag1 = true;
966 }
967
968 rc = mbox_process_msg(mbox, (void *)&rsp);
969 if (rc)
970 return rc;
971
972 return 0;
973}
974
975static int
976npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
977 struct roc_npc_flow *flow,
978 struct npc_action_vtag_info *vlan_info,
979 int *parsed_cnt)
980{
981 bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
982 int count = 0;
983
984 *parsed_cnt = 0;
985
986
987
988
989
990
991
992 for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
993 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
994 if (vlan_id_found)
995 return 0;
996
997 const struct roc_npc_action_of_set_vlan_vid *vtag =
998 (const struct roc_npc_action_of_set_vlan_vid *)
999 actions->conf;
1000
1001 vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
1002
1003 if (vlan_info->vlan_id > 0xfff) {
1004 plt_err("Invalid vlan_id for set vlan action");
1005 return -EINVAL;
1006 }
1007
1008 flow->vtag_insert_enabled = true;
1009 (*parsed_cnt)++;
1010 vlan_id_found = true;
1011 } else if (actions->type ==
1012 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
1013 if (ethtype_found)
1014 return 0;
1015
1016 const struct roc_npc_action_of_push_vlan *ethtype =
1017 (const struct roc_npc_action_of_push_vlan *)
1018 actions->conf;
1019 vlan_info->vlan_ethtype =
1020 plt_be_to_cpu_16(ethtype->ethertype);
1021 if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
1022 vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
1023 plt_err("Invalid ethtype specified for push"
1024 " vlan action");
1025 return -EINVAL;
1026 }
1027 flow->vtag_insert_enabled = true;
1028 (*parsed_cnt)++;
1029 ethtype_found = true;
1030 } else if (actions->type ==
1031 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1032 if (pcp_found)
1033 return 0;
1034 const struct roc_npc_action_of_set_vlan_pcp *pcp =
1035 (const struct roc_npc_action_of_set_vlan_pcp *)
1036 actions->conf;
1037 vlan_info->vlan_pcp = pcp->vlan_pcp;
1038 if (vlan_info->vlan_pcp > 0x7) {
1039 plt_err("Invalid PCP value for pcp action");
1040 return -EINVAL;
1041 }
1042 flow->vtag_insert_enabled = true;
1043 (*parsed_cnt)++;
1044 pcp_found = true;
1045 } else {
1046 return 0;
1047 }
1048 }
1049
1050 return 0;
1051}
1052
1053static int
1054npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
1055 struct npc_action_vtag_info *vlan_info)
1056{
1057 struct nix_vtag_config *vtag_cfg;
1058 struct nix_vtag_config_rsp *rsp;
1059 int rc = 0;
1060
1061 union {
1062 uint64_t reg;
1063 struct nix_tx_vtag_action_s act;
1064 } tx_vtag_action;
1065
1066 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1067
1068 if (vtag_cfg == NULL)
1069 return -ENOSPC;
1070
1071 vtag_cfg->cfg_type = VTAG_TX;
1072 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1073 vtag_cfg->tx.vtag0 =
1074 (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
1075 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1076
1077 vtag_cfg->tx.cfg_vtag0 = 1;
1078
1079 if (flow->vtag_insert_count == 2) {
1080 vtag_cfg->tx.vtag1 =
1081 (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
1082 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1083
1084 vtag_cfg->tx.cfg_vtag1 = 1;
1085 }
1086
1087 rc = mbox_process_msg(mbox, (void *)&rsp);
1088 if (rc)
1089 return rc;
1090
1091 if (rsp->vtag0_idx < 0 ||
1092 ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1093 plt_err("Failed to config TX VTAG action");
1094 return -EINVAL;
1095 }
1096
1097 tx_vtag_action.reg = 0;
1098 tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1099 tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1100 tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1101 tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1102
1103 if (flow->vtag_insert_count == 2) {
1104 tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1105 tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1106 tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1107
1108
1109
1110
1111
1112
1113 tx_vtag_action.act.vtag1_relptr =
1114 NIX_TX_VTAGACTION_VTAG0_RELPTR;
1115 }
1116
1117 flow->vtag_action = tx_vtag_action.reg;
1118
1119 return 0;
1120}
1121
1122static int
1123npc_vtag_strip_action_configure(struct mbox *mbox,
1124 const struct roc_npc_action actions[],
1125 struct roc_npc_flow *flow, int *strip_cnt)
1126{
1127 struct nix_vtag_config *vtag_cfg;
1128 uint64_t rx_vtag_action = 0;
1129 int count = 0, rc = 0;
1130
1131 *strip_cnt = 0;
1132
1133 for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1134 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1135 (*strip_cnt)++;
1136 }
1137
1138 vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1139
1140 if (vtag_cfg == NULL)
1141 return -ENOSPC;
1142
1143 vtag_cfg->cfg_type = VTAG_RX;
1144 vtag_cfg->rx.strip_vtag = 1;
1145
1146 vtag_cfg->rx.capture_vtag = 1;
1147 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1148 vtag_cfg->rx.vtag_type = 0;
1149
1150 rc = mbox_process(mbox);
1151 if (rc)
1152 return rc;
1153
1154 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1155 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1156 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1157
1158 if (*strip_cnt == 2) {
1159 rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1160 rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1161 rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1162 }
1163 flow->vtag_action = rx_vtag_action;
1164
1165 return 0;
1166}
1167
1168static int
1169npc_vtag_action_program(struct roc_npc *roc_npc,
1170 const struct roc_npc_action actions[],
1171 struct roc_npc_flow *flow)
1172{
1173 bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1174 const struct roc_npc_action *insert_actions;
1175 struct roc_nix *roc_nix = roc_npc->roc_nix;
1176 struct npc_action_vtag_info vlan_info[2];
1177 int parsed_cnt = 0, strip_cnt = 0;
1178 int tot_vlan_params = 0;
1179 struct mbox *mbox;
1180 struct nix *nix;
1181 int i, rc;
1182
1183 nix = roc_nix_to_nix_priv(roc_nix);
1184 mbox = (&nix->dev)->mbox;
1185
1186 memset(vlan_info, 0, sizeof(vlan_info));
1187
1188 flow->vtag_insert_enabled = false;
1189
1190 for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1191 if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1192 if (vlan_strip_parsed) {
1193 plt_err("Incorrect VLAN strip actions");
1194 return -EINVAL;
1195 }
1196 rc = npc_vtag_strip_action_configure(mbox, actions,
1197 flow, &strip_cnt);
1198 if (rc)
1199 return rc;
1200
1201 if (strip_cnt == 2)
1202 actions++;
1203
1204 vlan_strip_parsed = true;
1205 } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1206 actions->type ==
1207 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1208 actions->type ==
1209 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1210 if (vlan_insert_parsed) {
1211 plt_err("Incorrect VLAN insert actions");
1212 return -EINVAL;
1213 }
1214
1215 insert_actions = actions;
1216
1217 for (i = 0; i < 2; i++) {
1218 rc = npc_vtag_insert_action_parse(
1219 insert_actions, flow, &vlan_info[i],
1220 &parsed_cnt);
1221
1222 if (rc)
1223 return rc;
1224
1225 if (parsed_cnt) {
1226 insert_actions += parsed_cnt;
1227 tot_vlan_params += parsed_cnt;
1228 flow->vtag_insert_count++;
1229 }
1230 }
1231 actions += tot_vlan_params - 1;
1232 vlan_insert_parsed = true;
1233 }
1234 }
1235
1236 if (flow->vtag_insert_enabled) {
1237 rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1238
1239 if (rc)
1240 return rc;
1241 }
1242 return 0;
1243}
1244
1245struct roc_npc_flow *
1246roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1247 const struct roc_npc_item_info pattern[],
1248 const struct roc_npc_action actions[], int *errcode)
1249{
1250 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1251 struct roc_npc_flow *flow, *flow_iter;
1252 struct npc_parse_state parse_state;
1253 struct npc_flow_list *list;
1254 int rc;
1255
1256 npc->channel = roc_npc->channel;
1257 npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1258 if (npc->is_sdp_link) {
1259 if (roc_npc->is_sdp_mask_set) {
1260 npc->sdp_channel = roc_npc->sdp_channel;
1261 npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1262 } else {
1263
1264
1265
1266 npc->sdp_channel = (uint16_t)NIX_CHAN_SDP_CH_START;
1267 npc->sdp_channel_mask = (uint16_t)NIX_CHAN_SDP_CH_START;
1268 }
1269 }
1270
1271 flow = plt_zmalloc(sizeof(*flow), 0);
1272 if (flow == NULL) {
1273 *errcode = NPC_ERR_NO_MEM;
1274 return NULL;
1275 }
1276 memset(flow, 0, sizeof(*flow));
1277
1278 rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow,
1279 &parse_state);
1280 if (rc != 0) {
1281 *errcode = rc;
1282 goto err_exit;
1283 }
1284
1285 rc = npc_vtag_action_program(roc_npc, actions, flow);
1286 if (rc != 0) {
1287 *errcode = rc;
1288 goto err_exit;
1289 }
1290
1291 parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1292
1293 rc = npc_program_mcam(npc, &parse_state, 1);
1294 if (rc != 0) {
1295 *errcode = rc;
1296 goto err_exit;
1297 }
1298
1299 rc = npc_rss_action_program(roc_npc, actions, flow);
1300 if (rc != 0) {
1301 *errcode = rc;
1302 goto set_rss_failed;
1303 }
1304
1305 list = &npc->flow_list[flow->priority];
1306
1307 TAILQ_FOREACH(flow_iter, list, next) {
1308 if (flow_iter->mcam_id > flow->mcam_id) {
1309 TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1310 return flow;
1311 }
1312 }
1313
1314 TAILQ_INSERT_TAIL(list, flow, next);
1315 return flow;
1316
1317set_rss_failed:
1318 rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
1319 if (rc != 0) {
1320 *errcode = rc;
1321 plt_free(flow);
1322 return NULL;
1323 }
1324err_exit:
1325 plt_free(flow);
1326 return NULL;
1327}
1328
1329int
1330npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1331{
1332 uint32_t rss_grp;
1333
1334 if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1335 rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1336 NPC_RSS_ACT_GRP_MASK;
1337 if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1338 return -EINVAL;
1339
1340 plt_bitmap_clear(npc->rss_grp_entries, rss_grp);
1341 }
1342
1343 return 0;
1344}
1345
1346int
1347roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1348{
1349 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1350 int rc;
1351
1352 rc = npc_rss_group_free(npc, flow);
1353 if (rc != 0) {
1354 plt_err("Failed to free rss action rc = %d", rc);
1355 return rc;
1356 }
1357
1358 if (flow->vtag_insert_enabled) {
1359 rc = npc_vtag_cfg_delete(roc_npc, flow);
1360 if (rc != 0)
1361 return rc;
1362 }
1363
1364 rc = roc_npc_mcam_free(roc_npc, flow);
1365 if (rc != 0)
1366 return rc;
1367
1368 TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1369
1370 npc_delete_prio_list_entry(npc, flow);
1371
1372 plt_free(flow);
1373 return 0;
1374}
1375
1376void
1377roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc)
1378{
1379 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1380 struct roc_npc_flow *flow_iter;
1381 struct npc_flow_list *list;
1382 uint32_t max_prio, i;
1383
1384 max_prio = npc->flow_max_priority;
1385
1386 for (i = 0; i < max_prio; i++) {
1387 list = &npc->flow_list[i];
1388
1389
1390 TAILQ_FOREACH(flow_iter, list, next) {
1391 roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1392 }
1393 }
1394}
1395
1396int
1397roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
1398 struct roc_npc_flow *flow)
1399{
1400 struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1401 struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1402 struct mcam_entry *base_entry;
1403 int idx, rc;
1404
1405 if (roc_nix_is_pf(roc_npc->roc_nix))
1406 return 0;
1407
1408 (void)mbox_alloc_msg_npc_read_base_steer_rule(npc->mbox);
1409 rc = mbox_process_msg(npc->mbox, (void *)&base_rule_rsp);
1410 if (rc) {
1411 plt_err("Failed to fetch VF's base MCAM entry");
1412 return rc;
1413 }
1414 base_entry = &base_rule_rsp->entry_data;
1415 for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1416 flow->mcam_data[idx] |= base_entry->kw[idx];
1417 flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
1418 }
1419
1420 return 0;
1421}
1422