Branch data Line data Source code
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 : : uint8_t
9 : 0 : roc_npc_get_key_type(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
10 : : {
11 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
12 : :
13 : 0 : return npc_get_key_type(npc, flow);
14 : : }
15 : :
16 : : uint8_t
17 : 0 : roc_npc_kex_key_type_config_get(struct roc_npc *roc_npc)
18 : : {
19 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
20 : :
21 : 0 : return npc_kex_key_type_config_get(npc);
22 : : }
23 : :
24 : : int
25 : 0 : roc_npc_mark_actions_get(struct roc_npc *roc_npc)
26 : : {
27 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
28 : :
29 : 0 : return npc->mark_actions;
30 : : }
31 : :
32 : : int
33 : 0 : roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
34 : : {
35 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
36 : :
37 : 0 : npc->mark_actions -= count;
38 : 0 : return npc->mark_actions;
39 : : }
40 : :
41 : : int
42 : 0 : roc_npc_vtag_actions_get(struct roc_npc *roc_npc)
43 : : {
44 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
45 : :
46 : 0 : return npc->vtag_strip_actions;
47 : : }
48 : :
49 : : int
50 : 0 : roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
51 : : {
52 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
53 : :
54 : 0 : npc->vtag_strip_actions -= count;
55 : 0 : return npc->vtag_strip_actions;
56 : : }
57 : :
58 : : int
59 : 0 : roc_npc_mcam_free_counter(struct roc_npc *roc_npc, uint16_t ctr_id)
60 : : {
61 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
62 : :
63 : 0 : return npc_mcam_free_counter(npc->mbox, ctr_id);
64 : : }
65 : :
66 : : int
67 : 0 : roc_npc_inl_mcam_read_counter(uint32_t ctr_id, uint64_t *count)
68 : : {
69 : : struct nix_inl_dev *inl_dev = NULL;
70 : : struct idev_cfg *idev;
71 : :
72 : 0 : idev = idev_get_cfg();
73 [ # # ]: 0 : if (idev)
74 : 0 : inl_dev = idev->nix_inl_dev;
75 [ # # ]: 0 : if (!inl_dev)
76 : : return 0;
77 : 0 : return npc_mcam_read_counter(inl_dev->dev.mbox, ctr_id, count);
78 : : }
79 : :
80 : : int
81 : 0 : roc_npc_inl_mcam_clear_counter(uint32_t ctr_id)
82 : : {
83 : : struct nix_inl_dev *inl_dev = NULL;
84 : : struct idev_cfg *idev;
85 : :
86 : 0 : idev = idev_get_cfg();
87 [ # # ]: 0 : if (idev)
88 : 0 : inl_dev = idev->nix_inl_dev;
89 [ # # ]: 0 : if (!inl_dev)
90 : : return 0;
91 : :
92 : 0 : return npc_mcam_clear_counter(inl_dev->dev.mbox, ctr_id);
93 : : }
94 : :
95 : : int
96 : 0 : roc_npc_mcam_alloc_counter(struct roc_npc *roc_npc, uint16_t *ctr_id)
97 : : {
98 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
99 : :
100 : 0 : return npc_mcam_alloc_counter(npc->mbox, ctr_id);
101 : : }
102 : :
103 : : int
104 : 0 : roc_npc_get_free_mcam_entry(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
105 : : {
106 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
107 : :
108 : 0 : return npc_get_free_mcam_entry(npc->mbox, flow, npc);
109 : : }
110 : :
111 : : int
112 : 0 : roc_npc_mcam_read_counter(struct roc_npc *roc_npc, uint32_t ctr_id, uint64_t *count)
113 : : {
114 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
115 : :
116 : 0 : return npc_mcam_read_counter(npc->mbox, ctr_id, count);
117 : : }
118 : :
119 : : int
120 : 0 : roc_npc_mcam_get_stats(struct roc_npc *roc_npc, struct roc_npc_flow *flow, uint64_t *count)
121 : : {
122 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
123 : :
124 : 0 : return npc_mcam_get_stats(npc->mbox, flow, count);
125 : : }
126 : :
127 : : int
128 : 0 : roc_npc_mcam_clear_counter(struct roc_npc *roc_npc, uint32_t ctr_id)
129 : : {
130 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
131 : :
132 : 0 : return npc_mcam_clear_counter(npc->mbox, ctr_id);
133 : : }
134 : :
135 : : int
136 : 0 : roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
137 : : {
138 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
139 : :
140 : 0 : return npc_mcam_free_entry(npc->mbox, entry);
141 : : }
142 : :
143 : : int
144 : 0 : roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
145 : : {
146 : : int rc = 0;
147 : :
148 [ # # ]: 0 : if (mcam->use_ctr) {
149 : 0 : rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
150 [ # # ]: 0 : if (rc)
151 : : return rc;
152 : :
153 : 0 : rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
154 [ # # ]: 0 : if (rc)
155 : : return rc;
156 : : }
157 : :
158 : 0 : return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
159 : : }
160 : :
161 : : int
162 : 0 : roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
163 : : int mcam_id)
164 : : {
165 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
166 : : int rc;
167 : :
168 : 0 : rc = npc_mcam_init(npc, flow, mcam_id);
169 [ # # ]: 0 : if (rc != 0) {
170 : 0 : plt_err("npc: mcam initialisation write failed");
171 : 0 : return rc;
172 : : }
173 : : return 0;
174 : : }
175 : :
176 : : int
177 : 0 : roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
178 : : {
179 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
180 : 0 : struct mbox *mbox = npc->mbox;
181 : : int rc;
182 : :
183 : 0 : rc = npc_mcam_move(mbox, old_ent, new_ent);
184 [ # # ]: 0 : if (rc)
185 : 0 : return rc;
186 : :
187 : : return 0;
188 : : }
189 : :
190 : : int
191 : 0 : roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
192 : : {
193 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
194 : :
195 : 0 : return npc_flow_free_all_resources(npc);
196 : : }
197 : :
198 : : int
199 : 0 : roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry, int *alloc_entry, int req_count,
200 : : int priority, int *resp_count, bool is_conti)
201 : : {
202 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
203 : :
204 : 0 : return npc_mcam_alloc_entries(npc->mbox, ref_entry, alloc_entry, req_count, priority,
205 : : resp_count, is_conti);
206 : : }
207 : :
208 : : int
209 : 0 : roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc, bool enable)
210 : : {
211 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
212 : :
213 : 0 : return npc_flow_enable_all_entries(npc, enable);
214 : : }
215 : :
216 : : void
217 : 0 : roc_npc_defrag_mcam_banks(struct roc_npc *roc_npc)
218 : : {
219 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
220 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
221 : : struct npc_mcam_defrag_req *req;
222 : : struct npc_mcam_defrag_rsp *rsp;
223 : : int rc = 0;
224 : :
225 : 0 : req = (struct npc_mcam_defrag_req *)mbox_alloc_msg_npc_defrag(mbox);
226 [ # # ]: 0 : if (req == NULL)
227 : 0 : goto exit;
228 : :
229 : : rc = mbox_process_msg(mbox, (void *)&rsp);
230 [ # # ]: 0 : if (rc)
231 : 0 : plt_err("Error when defragmenting MCAM banks.");
232 : :
233 : 0 : exit:
234 : : mbox_put(mbox);
235 : 0 : }
236 : :
237 : : int
238 : 0 : roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
239 : : struct roc_npc_flow *ref_mcam, int prio, int *resp_count)
240 : : {
241 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
242 : :
243 : 0 : return npc_mcam_alloc_entry(npc, mcam, ref_mcam, prio, resp_count);
244 : : }
245 : :
246 : : int
247 : 0 : roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
248 : : bool enable)
249 : : {
250 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
251 : :
252 : 0 : return npc_mcam_ena_dis_entry(npc, mcam, enable);
253 : : }
254 : :
255 : : int
256 : 0 : roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
257 : : {
258 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
259 : :
260 : 0 : return npc_mcam_write_entry(npc->mbox, mcam);
261 : : }
262 : :
263 : : int
264 [ # # ]: 0 : roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc)
265 : : {
266 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
267 : :
268 [ # # ]: 0 : if (roc_model_is_cn20k())
269 : 0 : return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
270 [ # # ]: 0 : else if (roc_model_is_cn10k())
271 : 0 : return (npc->mcam_entries - NPC_MCAME_RESVD_10XX - 1);
272 [ # # ]: 0 : else if (roc_model_is_cn98xx())
273 : 0 : return (npc->mcam_entries - NPC_MCAME_RESVD_98XX - 1);
274 : : else
275 : 0 : return (npc->mcam_entries - NPC_MCAME_RESVD_9XXX - 1);
276 : : }
277 : :
278 : : static int
279 : : npc_mcam_tot_entries(void)
280 : : {
281 : : /* FIXME: change to reading in AF from NPC_AF_CONST1/2
282 : : * MCAM_BANK_DEPTH(_EXT) * MCAM_BANKS
283 : : */
284 [ # # ]: 0 : if (roc_model_is_cn20k())
285 : : return 2 * 8192; /* MCAM_BANKS = 2, BANK_DEPTH_EXT = 8192 */
286 [ # # # # ]: 0 : else if (roc_model_is_cn10k() || roc_model_is_cn98xx())
287 : : return 16 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 4096 */
288 : : else
289 : 0 : return 4 * 1024; /* MCAM_BANKS = 4, BANK_DEPTH_EXT = 1024 */
290 : : }
291 : :
292 : : const char *
293 : 0 : roc_npc_profile_name_get(struct roc_npc *roc_npc)
294 : : {
295 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
296 : :
297 : 0 : return (char *)npc->profile_name;
298 : : }
299 : :
300 : : int
301 : 0 : roc_npc_kex_capa_get(struct roc_nix *roc_nix, uint64_t *kex_capability)
302 : : {
303 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
304 : : struct npc npc;
305 : : int rc = 0;
306 : :
307 : : memset(&npc, 0, sizeof(npc));
308 : :
309 : 0 : npc.mbox = (&nix->dev)->mbox;
310 : :
311 : 0 : rc = npc_mcam_fetch_kex_cfg(&npc);
312 [ # # ]: 0 : if (rc)
313 : : return rc;
314 : :
315 : 0 : rc = npc_mcam_fetch_hw_cap(&npc, &npc.hash_extract_cap);
316 [ # # ]: 0 : if (rc)
317 : : return rc;
318 : :
319 : 0 : *kex_capability = npc_get_kex_capability(&npc);
320 : :
321 : 0 : return 0;
322 : : }
323 : :
324 : : int
325 : 0 : roc_npc_init(struct roc_npc *roc_npc)
326 : : {
327 : : uint8_t *mem = NULL, *nix_mem = NULL, *npc_mem = NULL;
328 [ # # ]: 0 : struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
329 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
330 : : uint32_t bmap_sz;
331 : : int rc = 0, idx;
332 : : size_t sz;
333 : :
334 : : PLT_STATIC_ASSERT(sizeof(struct npc) <= ROC_NPC_MEM_SZ);
335 : :
336 : : memset(npc, 0, sizeof(*npc));
337 : 0 : npc->mbox = (&nix->dev)->mbox;
338 : 0 : roc_npc->channel = nix->rx_chan_base;
339 : 0 : roc_npc->pf_func = (&nix->dev)->pf_func;
340 : 0 : npc->channel = roc_npc->channel;
341 : 0 : npc->pf_func = roc_npc->pf_func;
342 : 0 : npc->flow_max_priority = roc_npc->flow_max_priority;
343 : 0 : npc->switch_header_type = roc_npc->switch_header_type;
344 : 0 : npc->flow_prealloc_size = roc_npc->flow_prealloc_size;
345 : :
346 [ # # ]: 0 : if (npc->mbox == NULL)
347 : : return NPC_ERR_PARAM;
348 : :
349 : 0 : rc = npc_mcam_fetch_kex_cfg(npc);
350 [ # # ]: 0 : if (rc)
351 : 0 : goto done;
352 : :
353 : 0 : rc = npc_mcam_fetch_hw_cap(npc, &npc->hash_extract_cap);
354 [ # # ]: 0 : if (rc)
355 : 0 : goto done;
356 : :
357 : 0 : roc_npc->kex_capability = npc_get_kex_capability(npc);
358 [ # # ]: 0 : roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
359 : :
360 : 0 : npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
361 : 0 : nix->exact_match_ena = npc->exact_match_ena;
362 : 0 : roc_npc->max_entries = npc->mcam_entries;
363 : :
364 : : /* Free, free_rev, live and live_rev entries */
365 : 0 : bmap_sz = plt_bitmap_get_memory_footprint(npc->mcam_entries);
366 : 0 : mem = plt_zmalloc(4 * bmap_sz * npc->flow_max_priority, 0);
367 [ # # ]: 0 : if (mem == NULL) {
368 : 0 : plt_err("Bmap alloc failed");
369 : : rc = NPC_ERR_NO_MEM;
370 : 0 : return rc;
371 : : }
372 : :
373 : 0 : sz = npc->flow_max_priority * sizeof(struct npc_flow_list);
374 : 0 : npc->flow_list = plt_zmalloc(sz, 0);
375 [ # # ]: 0 : if (npc->flow_list == NULL) {
376 : 0 : plt_err("flow_list alloc failed");
377 : : rc = NPC_ERR_NO_MEM;
378 : 0 : goto done;
379 : : }
380 : :
381 : 0 : sz = npc->flow_max_priority * sizeof(struct npc_prio_flow_list_head);
382 : 0 : npc->prio_flow_list = plt_zmalloc(sz, 0);
383 [ # # ]: 0 : if (npc->prio_flow_list == NULL) {
384 : 0 : plt_err("prio_flow_list alloc failed");
385 : : rc = NPC_ERR_NO_MEM;
386 : 0 : goto done;
387 : : }
388 : :
389 : : npc_mem = mem;
390 : :
391 : 0 : TAILQ_INIT(&npc->ipsec_list);
392 : 0 : TAILQ_INIT(&npc->age_flow_list);
393 [ # # ]: 0 : for (idx = 0; idx < npc->flow_max_priority; idx++) {
394 : 0 : TAILQ_INIT(&npc->flow_list[idx]);
395 : 0 : TAILQ_INIT(&npc->prio_flow_list[idx]);
396 : : }
397 : :
398 : 0 : npc->rss_grps = NPC_RSS_GRPS;
399 : :
400 : 0 : bmap_sz = plt_bitmap_get_memory_footprint(npc->rss_grps);
401 : 0 : nix_mem = plt_zmalloc(bmap_sz, 0);
402 [ # # ]: 0 : if (nix_mem == NULL) {
403 : 0 : plt_err("Bmap alloc failed");
404 : : rc = NPC_ERR_NO_MEM;
405 : 0 : goto done;
406 : : }
407 : :
408 : 0 : npc->rss_grp_entries = plt_bitmap_init(npc->rss_grps, nix_mem, bmap_sz);
409 : :
410 [ # # ]: 0 : if (!npc->rss_grp_entries) {
411 : 0 : plt_err("bitmap init failed");
412 : : rc = NPC_ERR_NO_MEM;
413 : 0 : goto done;
414 : : }
415 : :
416 : : /* Group 0 will be used for RSS,
417 : : * 1 -7 will be used for npc_flow RSS action
418 : : */
419 : : plt_bitmap_set(npc->rss_grp_entries, 0);
420 : :
421 : 0 : roc_npc->flow_age.age_flow_refcnt = 0;
422 : :
423 : 0 : return rc;
424 : :
425 : 0 : done:
426 [ # # ]: 0 : if (npc->flow_list)
427 : 0 : plt_free(npc->flow_list);
428 [ # # ]: 0 : if (npc->prio_flow_list)
429 : 0 : plt_free(npc->prio_flow_list);
430 [ # # ]: 0 : if (npc_mem)
431 : 0 : plt_free(npc_mem);
432 : : return rc;
433 : : }
434 : :
435 : : int
436 [ # # ]: 0 : roc_npc_fini(struct roc_npc *roc_npc)
437 : : {
438 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
439 : : int rc;
440 : :
441 [ # # ]: 0 : if (!roc_npc->flow_age.aged_flows_get_thread_exit)
442 : 0 : npc_aging_ctrl_thread_destroy(roc_npc);
443 : :
444 : 0 : rc = npc_flow_free_all_resources(npc);
445 [ # # ]: 0 : if (rc) {
446 : 0 : plt_err("Error when deleting NPC MCAM entries, counters");
447 : 0 : return rc;
448 : : }
449 : :
450 [ # # ]: 0 : if (npc->flow_list) {
451 : 0 : plt_free(npc->flow_list);
452 : 0 : npc->flow_list = NULL;
453 : : }
454 : :
455 [ # # ]: 0 : if (npc->prio_flow_list) {
456 : 0 : plt_free(npc->prio_flow_list);
457 : 0 : npc->prio_flow_list = NULL;
458 : : }
459 : :
460 : : return 0;
461 : : }
462 : :
463 : : int
464 : 0 : roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
465 : : struct roc_npc *roc_npc_dst)
466 : : {
467 : 0 : struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
468 : : struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
469 : 0 : struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
470 : : struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
471 : :
472 [ # # ]: 0 : if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
473 : 0 : plt_err("Output port should be VF");
474 : 0 : return -EINVAL;
475 : : }
476 : :
477 [ # # ]: 0 : if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
478 : 0 : plt_err("Invalid VF for output port");
479 : 0 : return -EINVAL;
480 : : }
481 : :
482 [ # # ]: 0 : if (nix_src->dev.pf != nix_dst->dev.pf) {
483 : 0 : plt_err("Output port should be VF of ingress PF");
484 : 0 : return -EINVAL;
485 : : }
486 : : return 0;
487 : : }
488 : :
489 : : static int
490 : 0 : npc_parse_spi_to_sa_action(struct roc_npc *roc_npc, const struct roc_npc_action *act,
491 : : struct roc_npc_flow *flow, uint8_t *has_spi_to_sa_action)
492 : : {
493 : : const struct roc_npc_sec_action *sec_action;
494 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
495 : : struct nix_spi_to_sa_add_req *req;
496 : : struct nix_spi_to_sa_add_rsp *rsp;
497 : : struct nix_inl_dev *inl_dev;
498 : : struct idev_cfg *idev;
499 : : union {
500 : : uint64_t reg;
501 : : union nix_rx_vtag_action_u act;
502 : : } vtag_act;
503 : : struct mbox *mbox;
504 : : int rc;
505 : :
506 [ # # # # ]: 0 : if (roc_npc->roc_nix->custom_sa_action == 0 || roc_model_is_cn9k() == 1 ||
507 [ # # # # ]: 0 : act->conf == NULL || flow->is_validate)
508 : : return 0;
509 : :
510 : 0 : *has_spi_to_sa_action = true;
511 : 0 : sec_action = act->conf;
512 : :
513 : 0 : vtag_act.reg = 0;
514 : 0 : vtag_act.act.sa_xor = sec_action->sa_xor;
515 : 0 : vtag_act.act.sa_hi = sec_action->sa_hi;
516 : 0 : vtag_act.act.sa_lo = sec_action->sa_lo;
517 : :
518 : 0 : idev = idev_get_cfg();
519 [ # # ]: 0 : if (!idev)
520 : : return -1;
521 : :
522 : 0 : inl_dev = idev->nix_inl_dev;
523 : :
524 [ # # # # : 0 : switch (sec_action->alg) {
# # ]
525 : : case ROC_NPC_SEC_ACTION_ALG0:
526 : : break;
527 : 0 : case ROC_NPC_SEC_ACTION_ALG1:
528 : : vtag_act.act.vtag1_valid = false;
529 : 0 : vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG1;
530 : 0 : break;
531 : 0 : case ROC_NPC_SEC_ACTION_ALG2:
532 : : vtag_act.act.vtag1_valid = false;
533 : 0 : vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG2;
534 : 0 : break;
535 : 0 : case ROC_NPC_SEC_ACTION_ALG3:
536 : : vtag_act.act.vtag1_valid = false;
537 : 0 : vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG3;
538 : 0 : break;
539 : 0 : case ROC_NPC_SEC_ACTION_ALG4:
540 : : vtag_act.act.vtag1_valid = false;
541 : : vtag_act.act.vtag1_lid = 0;
542 : 0 : mbox = inl_dev->dev.mbox;
543 : 0 : req = mbox_alloc_msg_nix_spi_to_sa_add(mbox);
544 [ # # ]: 0 : if (req == NULL)
545 : : return -ENOSPC;
546 : 0 : req->sa_index = sec_action->sa_index;
547 [ # # ]: 0 : req->spi_index = plt_be_to_cpu_32(flow->spi_to_sa_info.spi);
548 : 0 : req->match_id = flow->match_id;
549 [ # # ]: 0 : req->valid = true;
550 [ # # ]: 0 : if (roc_model_is_cn20k())
551 : 0 : req->inline_profile_id =
552 : 0 : roc_nix_inl_inb_ipsec_profile_id_get(roc_nix, true);
553 : : rc = mbox_process_msg(mbox, (void *)&rsp);
554 [ # # ]: 0 : if (rc)
555 : : return rc;
556 : 0 : flow->spi_to_sa_info.hash_index = rsp->hash_index;
557 : 0 : flow->spi_to_sa_info.way = rsp->way;
558 : 0 : flow->spi_to_sa_info.duplicate = rsp->is_duplicate;
559 : 0 : flow->spi_to_sa_info.has_action = true;
560 : 0 : break;
561 : : default:
562 : : return -1;
563 : : }
564 : :
565 : 0 : flow->vtag_action = vtag_act.reg;
566 : :
567 : 0 : return 0;
568 : : }
569 : :
570 : : static int
571 : 0 : roc_npc_process_sample_action(struct roc_npc *roc_npc,
572 : : const struct roc_npc_action_sample *sample_action,
573 : : struct roc_npc_flow *flow)
574 : : {
575 : 0 : struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
576 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
577 : :
578 : 0 : flow->is_sampling_rule = true;
579 : :
580 [ # # # # ]: 0 : switch (sample_action->action_type) {
581 : 0 : case ROC_NPC_ACTION_TYPE_PORT_ID:
582 : 0 : flow->mcast_pf_funcs[0] = sample_action->pf_func;
583 : 0 : flow->mcast_channels[0] = sample_action->channel;
584 : 0 : break;
585 : 0 : case ROC_NPC_ACTION_TYPE_PF:
586 : 0 : flow->mcast_pf_funcs[0] = roc_npc->pf_func;
587 : 0 : flow->mcast_channels[0] = npc->channel;
588 : 0 : break;
589 : 0 : case ROC_NPC_ACTION_TYPE_VF:
590 [ # # ]: 0 : if (sample_action->pf_func >= nix->dev.maxvf)
591 : : return -EINVAL;
592 : 0 : flow->mcast_pf_funcs[0] =
593 : 0 : ((roc_npc->pf_func & 0xfc00) | (sample_action->pf_func + 1));
594 : 0 : flow->mcast_channels[0] = npc->channel;
595 : 0 : break;
596 : : default:
597 : : return -EINVAL;
598 : : }
599 : :
600 : : return 0;
601 : : }
602 : :
603 : : static int
604 : 0 : npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
605 : : const struct roc_npc_action actions[], struct roc_npc_flow *flow,
606 : : uint16_t dst_pf_func, uint64_t npc_default_action)
607 : : {
608 : : bool vlan_insert_action = false, npc_action_set = false;
609 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
610 : : const struct roc_npc_action *sec_action = NULL;
611 : : const struct roc_npc_action_sample *act_sample;
612 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
613 : : const struct roc_npc_action_mark *act_mark;
614 : : const struct roc_npc_action_meter *act_mtr;
615 : : const struct roc_npc_action_queue *act_q;
616 : : const struct roc_npc_sec_action *sec_act;
617 : : const struct roc_npc_action_vf *vf_act;
618 : 0 : uint8_t has_spi_to_sa_act = 0;
619 : : int sel_act, req_act = 0;
620 : : uint16_t pf_func, vf_id;
621 : : bool is_non_inp = false;
622 : : int errcode = 0;
623 : : int mark = 0;
624 : : int rq = 0;
625 : : int rc = 0;
626 : :
627 : : /* Initialize actions */
628 : 0 : flow->ctr_id = NPC_COUNTER_NONE;
629 : 0 : flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
630 : 0 : pf_func = npc->pf_func;
631 [ # # ]: 0 : if (flow->has_rep)
632 : 0 : pf_func = flow->rep_pf_func;
633 : :
634 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
635 [ # # # # : 0 : switch (actions->type) {
# # # # #
# # # # #
# # # #
# ]
636 : : case ROC_NPC_ACTION_TYPE_VOID:
637 : : break;
638 : 0 : case ROC_NPC_ACTION_TYPE_MARK:
639 : 0 : act_mark = (const struct roc_npc_action_mark *)
640 : : actions->conf;
641 [ # # ]: 0 : if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
642 : 0 : plt_err("mark value must be < 0xfffe");
643 : 0 : goto err_exit;
644 : : }
645 : 0 : mark = act_mark->id + 1;
646 : 0 : req_act |= ROC_NPC_ACTION_TYPE_MARK;
647 : 0 : npc->mark_actions += 1;
648 : 0 : flow->match_id = mark;
649 : 0 : break;
650 : :
651 : 0 : case ROC_NPC_ACTION_TYPE_FLAG:
652 : : mark = NPC_FLOW_FLAG_VAL;
653 : 0 : req_act |= ROC_NPC_ACTION_TYPE_FLAG;
654 : 0 : npc->mark_actions += 1;
655 : 0 : break;
656 : :
657 : 0 : case ROC_NPC_ACTION_TYPE_COUNT:
658 : : /* Indicates, need a counter */
659 : 0 : flow->use_ctr = 1;
660 : 0 : req_act |= ROC_NPC_ACTION_TYPE_COUNT;
661 : 0 : break;
662 : :
663 : 0 : case ROC_NPC_ACTION_TYPE_DROP:
664 : 0 : req_act |= ROC_NPC_ACTION_TYPE_DROP;
665 : 0 : break;
666 : :
667 : 0 : case ROC_NPC_ACTION_TYPE_PF:
668 : 0 : req_act |= ROC_NPC_ACTION_TYPE_PF;
669 : 0 : pf_func &= (0xfc00);
670 : 0 : break;
671 : :
672 : 0 : case ROC_NPC_ACTION_TYPE_VF:
673 : 0 : vf_act = (const struct roc_npc_action_vf *)actions->conf;
674 [ # # ]: 0 : req_act |= ROC_NPC_ACTION_TYPE_VF;
675 [ # # ]: 0 : if (roc_model_is_cn20k())
676 : 0 : vf_id = vf_act->id & RVU_PFVF_FUNC_MASK_CN20K;
677 : : else
678 : 0 : vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
679 : 0 : pf_func &= (0xfc00);
680 : 0 : pf_func = (pf_func | (vf_id + 1));
681 : 0 : break;
682 : :
683 : 0 : case ROC_NPC_ACTION_TYPE_PORT_ID:
684 : : pf_func = dst_pf_func;
685 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VF;
686 : 0 : break;
687 : :
688 : 0 : case ROC_NPC_ACTION_TYPE_QUEUE:
689 : 0 : act_q = (const struct roc_npc_action_queue *)actions->conf;
690 : 0 : rq = act_q->index & 0xFFFFF;
691 : 0 : req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
692 : 0 : break;
693 : :
694 : 0 : case ROC_NPC_ACTION_TYPE_RSS:
695 : 0 : req_act |= ROC_NPC_ACTION_TYPE_RSS;
696 : 0 : break;
697 : :
698 : 0 : case ROC_NPC_ACTION_TYPE_SEC:
699 : : /* Assumes user has already configured security
700 : : * session for this flow. Associated conf is
701 : : * opaque. When security is implemented,
702 : : * we need to verify that for specified security
703 : : * session:
704 : : * action_type ==
705 : : * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
706 : : * session_protocol ==
707 : : * NPC_SECURITY_PROTOCOL_IPSEC
708 : : */
709 : :
710 [ # # ]: 0 : if (!actions->no_sec_action) {
711 : 0 : sec_act = (const struct roc_npc_sec_action *)actions->conf;
712 : : sec_action = actions;
713 [ # # # # ]: 0 : is_non_inp = sec_act ? sec_act->is_non_inp : false;
714 : : } else {
715 : 0 : is_non_inp = actions->is_non_inp;
716 : : }
717 : :
718 : 0 : req_act |= ROC_NPC_ACTION_TYPE_SEC;
719 : : rq = 0;
720 : 0 : roc_nix = roc_npc->roc_nix;
721 : :
722 : : /* Special processing when with inline device */
723 [ # # # # ]: 0 : if (roc_nix_inb_is_with_inl_dev(roc_nix) &&
724 : 0 : roc_nix_inl_dev_is_probed()) {
725 : : struct roc_nix_rq *inl_rq;
726 : :
727 : 0 : inl_rq = roc_nix_inl_dev_rq(roc_nix);
728 [ # # ]: 0 : if (!inl_rq) {
729 : : errcode = NPC_ERR_INTERNAL;
730 : 0 : goto err_exit;
731 : : }
732 : 0 : rq = inl_rq->qid;
733 : 0 : pf_func = nix_inl_dev_pffunc_get();
734 : : }
735 : :
736 [ # # ]: 0 : if (roc_nix_inl_dev_is_probed())
737 : 0 : flow->is_inline_dev = 1;
738 : : break;
739 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
740 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
741 : 0 : break;
742 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
743 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
744 : 0 : break;
745 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
746 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
747 : 0 : break;
748 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
749 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
750 : 0 : break;
751 : 0 : case ROC_NPC_ACTION_TYPE_METER:
752 : 0 : act_mtr = (const struct roc_npc_action_meter *)
753 : : actions->conf;
754 : 0 : flow->mtr_id = act_mtr->mtr_id;
755 : 0 : req_act |= ROC_NPC_ACTION_TYPE_METER;
756 : 0 : break;
757 : 0 : case ROC_NPC_ACTION_TYPE_AGE:
758 [ # # ]: 0 : if (flow->is_validate == true)
759 : : break;
760 : : plt_seqcount_init(&roc_npc->flow_age.seq_cnt);
761 : 0 : errcode = npc_aging_ctrl_thread_create(roc_npc,
762 : 0 : actions->conf,
763 : : flow);
764 [ # # ]: 0 : if (errcode != 0)
765 : 0 : goto err_exit;
766 : 0 : req_act |= ROC_NPC_ACTION_TYPE_AGE;
767 : 0 : break;
768 : 0 : case ROC_NPC_ACTION_TYPE_SAMPLE:
769 : 0 : req_act |= ROC_NPC_ACTION_TYPE_SAMPLE;
770 : 0 : act_sample = actions->conf;
771 : 0 : errcode = roc_npc_process_sample_action(roc_npc, act_sample, flow);
772 [ # # ]: 0 : if (errcode)
773 : 0 : goto err_exit;
774 : : break;
775 : 0 : default:
776 : : errcode = NPC_ERR_ACTION_NOTSUP;
777 : 0 : goto err_exit;
778 : : }
779 : : }
780 : :
781 [ # # ]: 0 : if (sec_action) {
782 : 0 : rc = npc_parse_spi_to_sa_action(roc_npc, sec_action, flow, &has_spi_to_sa_act);
783 [ # # ]: 0 : if (rc) {
784 : : errcode = NPC_ERR_ACTION_NOTSUP;
785 : 0 : goto err_exit;
786 : : }
787 : : }
788 : :
789 [ # # ]: 0 : if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
790 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
791 : : vlan_insert_action = true;
792 : :
793 [ # # ]: 0 : if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
794 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
795 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
796 : 0 : plt_err("PCP insert action can't be supported alone");
797 : : errcode = NPC_ERR_ACTION_NOTSUP;
798 : 0 : goto err_exit;
799 : : }
800 : :
801 [ # # # # ]: 0 : if (has_spi_to_sa_act && (vlan_insert_action ||
802 [ # # ]: 0 : (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP))) {
803 : 0 : plt_err("Both MSNS and VLAN insert/strip action can't be supported"
804 : : " together");
805 : : errcode = NPC_ERR_ACTION_NOTSUP;
806 : 0 : goto err_exit;
807 : : }
808 : :
809 : : /* Both STRIP and INSERT actions are not supported */
810 [ # # # # ]: 0 : if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
811 : : errcode = NPC_ERR_ACTION_NOTSUP;
812 : 0 : goto err_exit;
813 : : }
814 : :
815 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE) {
816 : : /* One entry for the mce list PF and channel comes from the sample subaction.
817 : : * Another one is the action target of the flow rule getting created.
818 : : */
819 : 0 : flow->mcast_pf_funcs[1] = pf_func;
820 : 0 : flow->mcast_channels[1] = npc->channel;
821 [ # # ]: 0 : if (req_act & (ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_SEC |
822 : : ROC_NPC_ACTION_TYPE_RSS)) {
823 : 0 : plt_err("Drop/RSS/SEC not supported with action type sample");
824 : 0 : return -EINVAL;
825 : : }
826 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == flow->mcast_pf_funcs[1]) {
827 : 0 : plt_err("Sample destination and target cannot be same");
828 : 0 : return -EINVAL;
829 : : }
830 [ # # # # ]: 0 : if ((attr->egress) && (flow->mcast_channels[0] == flow->mcast_channels[1])) {
831 : 0 : plt_err("Mirroring within PF and VF not allowed");
832 : 0 : return -EINVAL;
833 : : }
834 : : }
835 : :
836 : : /* Check if actions specified are compatible */
837 [ # # ]: 0 : if (attr->egress) {
838 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
839 : 0 : plt_err("VLAN pop action is not supported on Egress");
840 : : errcode = NPC_ERR_ACTION_NOTSUP;
841 : 0 : goto err_exit;
842 : : }
843 : :
844 [ # # ]: 0 : if (req_act &
845 : : ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
846 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT | ROC_NPC_ACTION_TYPE_DROP |
847 : : ROC_NPC_ACTION_TYPE_COUNT | ROC_NPC_ACTION_TYPE_SAMPLE)) {
848 : 0 : plt_err("Only VLAN insert, drop, count, sample supported on Egress");
849 : : errcode = NPC_ERR_ACTION_NOTSUP;
850 : 0 : goto err_exit;
851 : : }
852 : :
853 [ # # ]: 0 : if (vlan_insert_action &&
854 [ # # ]: 0 : (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
855 : 0 : plt_err("Both VLAN insert and drop actions cannot be supported");
856 : : errcode = NPC_ERR_ACTION_NOTSUP;
857 : 0 : goto err_exit;
858 : : }
859 : :
860 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
861 : 0 : flow->npc_action = NIX_TX_ACTIONOP_DROP;
862 [ # # # # ]: 0 : } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) || vlan_insert_action) {
863 : 0 : flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
864 [ # # ]: 0 : if (flow->rep_act_rep) {
865 : : flow->npc_action = NIX_TX_ACTIONOP_UCAST_CHAN;
866 : 0 : flow->npc_action |= (uint64_t)0x3f << 12;
867 : : }
868 : : } else {
869 : 0 : plt_err("Unsupported action for egress");
870 : : errcode = NPC_ERR_ACTION_NOTSUP;
871 : 0 : goto err_exit;
872 : : }
873 : :
874 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE) {
875 : 0 : flow->mcast_pf_funcs[1] = pf_func;
876 : 0 : flow->mcast_channels[1] = npc->channel;
877 : : }
878 : :
879 : : /* PF func who is sending the packet */
880 : 0 : flow->tx_pf_func = pf_func;
881 : 0 : goto done;
882 : : } else {
883 [ # # ]: 0 : if (vlan_insert_action) {
884 : : errcode = NPC_ERR_ACTION_NOTSUP;
885 : 0 : goto err_exit;
886 : : }
887 : : }
888 : :
889 : : /* We have already verified the attr, this is ingress.
890 : : * - Exactly one terminating action is supported
891 : : * - Exactly one of MARK or FLAG is supported
892 : : * - If terminating action is DROP, only count is valid.
893 : : */
894 : 0 : sel_act = req_act & NPC_ACTION_TERM;
895 [ # # ]: 0 : if ((sel_act & (sel_act - 1)) != 0) {
896 : : errcode = NPC_ERR_ACTION_NOTSUP;
897 : 0 : goto err_exit;
898 : : }
899 : :
900 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
901 : 0 : sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
902 [ # # ]: 0 : if ((sel_act & (sel_act - 1)) != 0) {
903 : : errcode = NPC_ERR_ACTION_NOTSUP;
904 : 0 : goto err_exit;
905 : : }
906 : : }
907 : :
908 [ # # ]: 0 : if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
909 : : (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
910 : : errcode = NPC_ERR_ACTION_NOTSUP;
911 : 0 : goto err_exit;
912 : : }
913 : :
914 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
915 : 0 : npc->vtag_strip_actions++;
916 : :
917 : : /* Set NIX_RX_ACTIONOP */
918 [ # # ]: 0 : if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
919 : : /* Only VLAN action is provided */
920 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
921 [ # # ]: 0 : } else if (req_act & (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
922 : : /* Check if any other action is set */
923 [ # # ]: 0 : if ((req_act == ROC_NPC_ACTION_TYPE_PF) || (req_act == ROC_NPC_ACTION_TYPE_VF)) {
924 : 0 : flow->npc_action = npc_default_action;
925 : : npc_action_set = true;
926 : : } else {
927 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
928 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
929 : 0 : flow->recv_queue = rq;
930 : : }
931 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
932 : 0 : flow->npc_action = NIX_RX_ACTIONOP_DROP;
933 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
934 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
935 : 0 : flow->recv_queue = rq;
936 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
937 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
938 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
939 [ # # ]: 0 : if (roc_model_is_cn20k()) {
940 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_CPT;
941 : 0 : flow->npc_action |= (uint64_t)rq << 20;
942 : : flow->npc_action2 =
943 : 0 : roc_nix_inl_inb_ipsec_profile_id_get(roc_nix, true) << 8;
944 [ # # ]: 0 : flow->npc_action2 |= is_non_inp ? (1ULL << 15) : 0;
945 : : } else {
946 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
947 : 0 : flow->npc_action |= (uint64_t)rq << 20;
948 : : }
949 [ # # ]: 0 : } else if (req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
950 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
951 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
952 : : /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
953 : : * This is default action, when user specify only
954 : : * COUNT ACTION
955 : : */
956 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
957 : : } else {
958 : : /* Should never reach here */
959 : : errcode = NPC_ERR_ACTION_NOTSUP;
960 : 0 : goto err_exit;
961 : : }
962 : :
963 : : if (!npc_action_set) {
964 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE)
965 : 0 : flow->npc_action = NIX_RX_ACTIONOP_MCAST;
966 : :
967 [ # # ]: 0 : if (mark)
968 : 0 : flow->npc_action |= (uint64_t)mark << 40;
969 : :
970 : : /* Ideally AF must ensure that correct pf_func is set */
971 : 0 : flow->npc_action |= (uint64_t)pf_func << 4;
972 : : }
973 : : done:
974 : : return 0;
975 : :
976 : : err_exit:
977 : : return errcode;
978 : : }
979 : :
980 : : typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
981 : :
982 : : static int
983 : 0 : npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
984 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
985 : : {
986 : 0 : npc_parse_stage_func_t parse_stage_funcs[] = {
987 : : npc_parse_meta_items, npc_parse_port_representor_id,
988 : : npc_parse_mark_item, npc_parse_pre_l2,
989 : : npc_parse_cpt_hdr, npc_parse_higig2_hdr,
990 : : npc_parse_tx_queue, npc_parse_la,
991 : : npc_parse_lb, npc_parse_lc,
992 : : npc_parse_ld, npc_parse_le,
993 : : npc_parse_lf, npc_parse_lg,
994 : : npc_parse_lh,
995 : : };
996 : : uint8_t layer = 0;
997 : : int key_offset;
998 : : int rc;
999 : :
1000 [ # # ]: 0 : if (pattern == NULL)
1001 : : return NPC_ERR_PARAM;
1002 : :
1003 : 0 : pst->npc = npc;
1004 : 0 : pst->flow = flow;
1005 : 0 : pst->nix_intf = flow->nix_intf;
1006 : :
1007 : : /* Use integral byte offset */
1008 : : key_offset = pst->npc->keyx_len[flow->nix_intf];
1009 : : key_offset = (key_offset + 7) / 8;
1010 : :
1011 : : /* Location where LDATA would begin */
1012 : 0 : pst->mcam_data = (uint8_t *)flow->mcam_data;
1013 : 0 : pst->mcam_mask = (uint8_t *)flow->mcam_mask;
1014 : :
1015 [ # # # # ]: 0 : while (pattern->type != ROC_NPC_ITEM_TYPE_END && layer < PLT_DIM(parse_stage_funcs)) {
1016 : : /* Skip place-holders */
1017 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
1018 [ # # ]: 0 : if (pattern->type == ROC_NPC_ITEM_TYPE_END)
1019 : : break;
1020 : :
1021 : 0 : pst->pattern = pattern;
1022 : 0 : rc = parse_stage_funcs[layer](pst);
1023 [ # # ]: 0 : if (rc != 0)
1024 : 0 : return rc;
1025 : :
1026 : 0 : layer++;
1027 : :
1028 : : /*
1029 : : * Parse stage function sets pst->pattern to
1030 : : * 1 past the last item it consumed.
1031 : : */
1032 : 0 : pattern = pst->pattern;
1033 : :
1034 [ # # ]: 0 : if (pst->terminate)
1035 : : break;
1036 : : }
1037 : :
1038 : : /* Skip trailing place-holders */
1039 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
1040 : :
1041 : : /* Are there more items than what we can handle? */
1042 [ # # ]: 0 : if (pattern->type != ROC_NPC_ITEM_TYPE_END)
1043 : 0 : return NPC_ERR_PATTERN_NOTSUP;
1044 : :
1045 : : return 0;
1046 : : }
1047 : :
1048 : : static int
1049 : : npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
1050 : : struct roc_npc_flow *flow)
1051 : : {
1052 : 0 : if (attr == NULL)
1053 : : return NPC_ERR_PARAM;
1054 [ # # ]: 0 : else if (attr->priority >= npc->flow_max_priority)
1055 : : return NPC_ERR_PARAM;
1056 [ # # ]: 0 : else if ((!attr->egress && !attr->ingress) ||
1057 : : (attr->egress && attr->ingress))
1058 : : return NPC_ERR_PARAM;
1059 : :
1060 [ # # ]: 0 : if (attr->ingress)
1061 : 0 : flow->nix_intf = ROC_NPC_INTF_RX;
1062 : : else
1063 : 0 : flow->nix_intf = ROC_NPC_INTF_TX;
1064 : :
1065 : 0 : flow->priority = attr->priority;
1066 : : return 0;
1067 : : }
1068 : :
1069 : : static int
1070 [ # # ]: 0 : npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1071 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1072 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
1073 : : {
1074 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1075 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1076 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1077 : : int err;
1078 : :
1079 [ # # ]: 0 : pst->nb_tx_queues = nix->nb_tx_queues;
1080 : :
1081 : : /* Check attr */
1082 : : err = npc_parse_attr(npc, attr, flow);
1083 : : if (err)
1084 : : return err;
1085 : :
1086 : : /* Check pattern */
1087 : 0 : err = npc_parse_pattern(npc, pattern, flow, pst);
1088 [ # # ]: 0 : if (err)
1089 : : return err;
1090 : :
1091 : : /* Check action */
1092 : 0 : err = npc_parse_actions(roc_npc, attr, actions, flow, pst->dst_pf_func,
1093 : : pst->npc_default_action);
1094 [ # # ]: 0 : if (err)
1095 : 0 : return err;
1096 : : return 0;
1097 : : }
1098 : :
1099 : : int
1100 : 0 : roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1101 : : const struct roc_npc_item_info pattern[],
1102 : : const struct roc_npc_action actions[],
1103 : : struct roc_npc_flow *flow)
1104 : : {
1105 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1106 : 0 : struct npc_parse_state parse_state = {0};
1107 : : int rc;
1108 : :
1109 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1110 [ # # ]: 0 : if (rc)
1111 : : return rc;
1112 : :
1113 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1114 : :
1115 : 0 : return npc_program_mcam(npc, &parse_state, 0);
1116 : : }
1117 : :
1118 : : int
1119 : 0 : npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
1120 : : {
1121 : 0 : struct plt_bitmap *bmap = npc->rss_grp_entries;
1122 : :
1123 [ # # ]: 0 : for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
1124 [ # # ]: 0 : if (!plt_bitmap_get(bmap, *pos))
1125 : : break;
1126 : : }
1127 [ # # ]: 0 : return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
1128 : : }
1129 : :
1130 : : int
1131 : 0 : npc_rss_action_configure(struct roc_npc *roc_npc, const struct roc_npc_action_rss *rss,
1132 : : uint8_t *alg_idx, uint32_t *rss_grp, uint32_t mcam_id,
1133 : : uint16_t rss_repte_pf_func)
1134 : : {
1135 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1136 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1137 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1138 : : uint32_t flowkey_cfg, rss_grp_idx, i, rem;
1139 : : uint8_t key[ROC_NIX_RSS_KEY_LEN];
1140 : : const uint8_t *key_ptr;
1141 : : uint8_t flowkey_algx;
1142 : : uint32_t key_len;
1143 : : uint16_t *reta;
1144 : : int rc;
1145 : :
1146 : 0 : roc_nix_rss_key_get(roc_nix, key);
1147 [ # # ]: 0 : if (rss->key == NULL) {
1148 : : key_ptr = key;
1149 : : } else {
1150 : 0 : key_len = rss->key_len;
1151 : : if (key_len > ROC_NIX_RSS_KEY_LEN)
1152 : : key_len = ROC_NIX_RSS_KEY_LEN;
1153 : :
1154 [ # # ]: 0 : for (i = 0; i < key_len; i++) {
1155 [ # # ]: 0 : if (key[i] != rss->key[i]) {
1156 : 0 : plt_err("RSS key config not supported");
1157 : 0 : plt_err("New Key:");
1158 [ # # ]: 0 : for (i = 0; i < key_len; i++)
1159 : 0 : plt_dump_no_nl("0x%.2x ", rss->key[i]);
1160 : 0 : plt_dump_no_nl("\n");
1161 : 0 : plt_err("Configured Key:");
1162 [ # # ]: 0 : for (i = 0; i < ROC_NIX_RSS_KEY_LEN; i++)
1163 : 0 : plt_dump_no_nl("0x%.2x ", key[i]);
1164 : 0 : plt_dump_no_nl("\n");
1165 : 0 : return -ENOTSUP;
1166 : : }
1167 : : }
1168 : : key_ptr = rss->key;
1169 : : }
1170 : :
1171 : 0 : rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
1172 : : /* RSS group :0 is not usable for flow rss action */
1173 [ # # # # ]: 0 : if (rc < 0 || rss_grp_idx == 0)
1174 : : return -ENOSPC;
1175 : :
1176 [ # # # # ]: 0 : for (i = 0; (i < rss->queue_num) && !rss_repte_pf_func; i++) {
1177 [ # # ]: 0 : if (rss->queue[i] >= nix->nb_rx_queues) {
1178 : 0 : plt_err("queue id > max number of queues");
1179 : 0 : return -EINVAL;
1180 : : }
1181 : : }
1182 : :
1183 : 0 : *rss_grp = rss_grp_idx;
1184 : :
1185 : 0 : roc_nix_rss_key_set(roc_nix, key_ptr);
1186 : :
1187 : : /* If queue count passed in the rss action is less than
1188 : : * HW configured reta size, replicate rss action reta
1189 : : * across HW reta table.
1190 : : */
1191 : 0 : reta = nix->reta[rss_grp_idx];
1192 : :
1193 [ # # ]: 0 : if (rss->queue_num > nix->reta_sz) {
1194 : 0 : plt_err("too many queues for RSS context");
1195 : 0 : return -ENOTSUP;
1196 : : }
1197 : :
1198 [ # # ]: 0 : for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
1199 : 0 : memcpy(reta + i * rss->queue_num, rss->queue,
1200 : 0 : sizeof(uint16_t) * rss->queue_num);
1201 : :
1202 : 0 : rem = nix->reta_sz % rss->queue_num;
1203 [ # # ]: 0 : if (rem)
1204 : 0 : memcpy(&reta[i * rss->queue_num], rss->queue, rem * sizeof(uint16_t));
1205 : :
1206 : 0 : rc = nix_rss_reta_pffunc_set(roc_nix, *rss_grp, reta, rss_repte_pf_func);
1207 [ # # ]: 0 : if (rc) {
1208 : 0 : plt_err("Failed to init rss table rc = %d", rc);
1209 : 0 : return rc;
1210 : : }
1211 : :
1212 : 0 : flowkey_cfg = roc_npc->flowkey_cfg_state;
1213 : :
1214 : 0 : rc = nix_rss_flowkey_pffunc_set(roc_nix, &flowkey_algx, flowkey_cfg, *rss_grp, mcam_id,
1215 : : rss_repte_pf_func);
1216 [ # # ]: 0 : if (rc) {
1217 : 0 : plt_err("Failed to set rss hash function rc = %d", rc);
1218 : 0 : return rc;
1219 : : }
1220 : :
1221 : 0 : *alg_idx = flowkey_algx;
1222 : :
1223 : 0 : plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
1224 : :
1225 : 0 : return 0;
1226 : : }
1227 : :
1228 : : int
1229 : 0 : npc_rss_action_program(struct roc_npc *roc_npc,
1230 : : const struct roc_npc_action actions[],
1231 : : struct roc_npc_flow *flow)
1232 : : {
1233 : : const struct roc_npc_action_rss *rss;
1234 : : struct roc_npc *npc = roc_npc;
1235 : : uint32_t rss_grp;
1236 : : uint8_t alg_idx;
1237 : : int rc;
1238 : :
1239 [ # # ]: 0 : if (flow->has_rep) {
1240 : 0 : npc = roc_npc->rep_npc;
1241 : 0 : npc->flowkey_cfg_state = roc_npc->flowkey_cfg_state;
1242 : : }
1243 : :
1244 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1245 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
1246 : 0 : rss = (const struct roc_npc_action_rss *)actions->conf;
1247 : 0 : rc = npc_rss_action_configure(npc, rss, &alg_idx, &rss_grp, flow->mcam_id,
1248 : 0 : actions->rss_repte_pf_func);
1249 [ # # ]: 0 : if (rc)
1250 : : return rc;
1251 : :
1252 : 0 : flow->npc_action &= (~(0xfULL));
1253 : 0 : flow->npc_action |= NIX_RX_ACTIONOP_RSS;
1254 : 0 : flow->npc_action |=
1255 : 0 : ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
1256 : 0 : << NPC_RSS_ACT_ALG_OFFSET) |
1257 : 0 : ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
1258 : 0 : << NPC_RSS_ACT_GRP_OFFSET);
1259 : 0 : break;
1260 : : }
1261 : : }
1262 : : return 0;
1263 : : }
1264 : :
1265 : : static int
1266 : 0 : npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1267 : : {
1268 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1269 : : struct nix_vtag_config *vtag_cfg;
1270 : : struct nix_vtag_config_rsp *rsp;
1271 : : struct mbox *mbox, *ombox;
1272 : : struct nix *nix;
1273 : : int rc = 0;
1274 : :
1275 : : union {
1276 : : uint64_t reg;
1277 : : struct nix_tx_vtag_action_s act;
1278 : : } tx_vtag_action;
1279 : :
1280 : : nix = roc_nix_to_nix_priv(roc_nix);
1281 : 0 : ombox = (&nix->dev)->mbox;
1282 [ # # ]: 0 : if (flow->has_rep)
1283 : 0 : ombox = flow->rep_mbox;
1284 : : mbox = mbox_get(ombox);
1285 : :
1286 : 0 : tx_vtag_action.reg = flow->vtag_action;
1287 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1288 : :
1289 [ # # ]: 0 : if (vtag_cfg == NULL) {
1290 : : rc = -ENOSPC;
1291 : 0 : goto exit;
1292 : : }
1293 : :
1294 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1295 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1296 : 0 : vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
1297 : 0 : vtag_cfg->tx.free_vtag0 = true;
1298 : :
1299 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1300 : 0 : vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
1301 : 0 : vtag_cfg->tx.free_vtag1 = true;
1302 : : }
1303 : :
1304 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1305 [ # # ]: 0 : if (rc)
1306 : 0 : goto exit;
1307 : :
1308 : : rc = 0;
1309 : 0 : exit:
1310 : : mbox_put(mbox);
1311 : 0 : return rc;
1312 : : }
1313 : :
1314 : : static int
1315 : 0 : npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
1316 : : struct roc_npc_flow *flow,
1317 : : struct npc_action_vtag_info *vlan_info,
1318 : : int *parsed_cnt)
1319 : : {
1320 : : bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
1321 : : int count = 0;
1322 : :
1323 : 0 : *parsed_cnt = 0;
1324 : :
1325 : : /* This function parses parameters of one VLAN. When a parameter is
1326 : : * found repeated, it treats it as the end of first VLAN's parameters
1327 : : * and returns. The caller calls again to parse the parameters of the
1328 : : * second VLAN.
1329 : : */
1330 : :
1331 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
1332 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
1333 [ # # ]: 0 : if (vlan_id_found)
1334 : : return 0;
1335 : :
1336 : 0 : const struct roc_npc_action_of_set_vlan_vid *vtag =
1337 : : (const struct roc_npc_action_of_set_vlan_vid *)
1338 : : actions->conf;
1339 : :
1340 [ # # ]: 0 : vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
1341 : :
1342 [ # # ]: 0 : if (vlan_info->vlan_id > 0xfff) {
1343 : 0 : plt_err("Invalid vlan_id for set vlan action");
1344 : 0 : return -EINVAL;
1345 : : }
1346 : :
1347 : 0 : flow->vtag_insert_enabled = true;
1348 : 0 : (*parsed_cnt)++;
1349 : : vlan_id_found = true;
1350 [ # # ]: 0 : } else if (actions->type ==
1351 : : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
1352 [ # # ]: 0 : if (ethtype_found)
1353 : : return 0;
1354 : :
1355 : 0 : const struct roc_npc_action_of_push_vlan *ethtype =
1356 : : (const struct roc_npc_action_of_push_vlan *)
1357 : : actions->conf;
1358 : 0 : vlan_info->vlan_ethtype =
1359 [ # # ]: 0 : plt_be_to_cpu_16(ethtype->ethertype);
1360 [ # # ]: 0 : if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
1361 : : vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
1362 : 0 : plt_err("Invalid ethtype specified for push"
1363 : : " vlan action");
1364 : 0 : return -EINVAL;
1365 : : }
1366 : 0 : flow->vtag_insert_enabled = true;
1367 : 0 : (*parsed_cnt)++;
1368 : : ethtype_found = true;
1369 [ # # ]: 0 : } else if (actions->type ==
1370 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1371 [ # # ]: 0 : if (pcp_found)
1372 : : return 0;
1373 : 0 : const struct roc_npc_action_of_set_vlan_pcp *pcp =
1374 : : (const struct roc_npc_action_of_set_vlan_pcp *)
1375 : : actions->conf;
1376 : 0 : vlan_info->vlan_pcp = pcp->vlan_pcp;
1377 [ # # ]: 0 : if (vlan_info->vlan_pcp > 0x7) {
1378 : 0 : plt_err("Invalid PCP value for pcp action");
1379 : 0 : return -EINVAL;
1380 : : }
1381 : 0 : flow->vtag_insert_enabled = true;
1382 : 0 : (*parsed_cnt)++;
1383 : : pcp_found = true;
1384 : : } else {
1385 : : return 0;
1386 : : }
1387 : : }
1388 : :
1389 : : return 0;
1390 : : }
1391 : :
1392 : : static int
1393 : 0 : npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
1394 : : struct npc_action_vtag_info *vlan_info)
1395 : : {
1396 : : struct nix_vtag_config *vtag_cfg;
1397 : : struct nix_vtag_config_rsp *rsp;
1398 : : int rc = 0;
1399 : :
1400 : : union {
1401 : : uint64_t reg;
1402 : : struct nix_tx_vtag_action_s act;
1403 : : } tx_vtag_action;
1404 : :
1405 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1406 : :
1407 [ # # ]: 0 : if (vtag_cfg == NULL) {
1408 : : rc = -ENOSPC;
1409 : 0 : goto exit;
1410 : : }
1411 : :
1412 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1413 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1414 : 0 : vtag_cfg->tx.vtag0 =
1415 : 0 : (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
1416 : 0 : (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1417 : :
1418 : 0 : vtag_cfg->tx.cfg_vtag0 = 1;
1419 : :
1420 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1421 : 0 : vtag_cfg->tx.vtag1 =
1422 : 0 : (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
1423 : 0 : (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1424 : :
1425 : 0 : vtag_cfg->tx.cfg_vtag1 = 1;
1426 : : }
1427 : :
1428 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1429 [ # # ]: 0 : if (rc)
1430 : 0 : goto exit;
1431 : :
1432 [ # # ]: 0 : if (rsp->vtag0_idx < 0 ||
1433 [ # # # # ]: 0 : ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1434 : 0 : plt_err("Failed to config TX VTAG action");
1435 : : rc = -EINVAL;
1436 : 0 : goto exit;
1437 : : }
1438 : :
1439 : 0 : tx_vtag_action.reg = 0;
1440 : 0 : tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1441 : : tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1442 : 0 : tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1443 : 0 : tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1444 : :
1445 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1446 : 0 : tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1447 : : tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1448 : 0 : tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1449 : : /* NIX_TX_VTAG_ACTION_S
1450 : : * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1451 : : * offset accordingly. Thus, if the two offsets are equal in
1452 : : * the structure, hardware inserts Vtag 1 immediately after
1453 : : * Vtag 0 in the packet.
1454 : : */
1455 : 0 : tx_vtag_action.act.vtag1_relptr =
1456 : : NIX_TX_VTAGACTION_VTAG0_RELPTR;
1457 : : }
1458 : :
1459 : 0 : flow->vtag_action = tx_vtag_action.reg;
1460 : :
1461 : : rc = 0;
1462 : 0 : exit:
1463 : : mbox_put(mbox);
1464 : 0 : return rc;
1465 : : }
1466 : :
1467 : : static int
1468 : 0 : npc_vtag_strip_action_configure(struct mbox *mbox,
1469 : : const struct roc_npc_action actions[],
1470 : : struct roc_npc_flow *flow, int *strip_cnt)
1471 : : {
1472 : : struct nix_vtag_config *vtag_cfg;
1473 : : uint64_t rx_vtag_action = 0;
1474 : : int count = 0, rc = 0;
1475 : :
1476 : 0 : *strip_cnt = 0;
1477 : :
1478 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1479 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1480 : 0 : (*strip_cnt)++;
1481 : : }
1482 : :
1483 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1484 : :
1485 [ # # ]: 0 : if (vtag_cfg == NULL) {
1486 : : rc = -ENOSPC;
1487 : 0 : goto exit;
1488 : : }
1489 : :
1490 : 0 : vtag_cfg->cfg_type = VTAG_RX;
1491 : 0 : vtag_cfg->rx.strip_vtag = 1;
1492 : : /* Always capture */
1493 : 0 : vtag_cfg->rx.capture_vtag = 1;
1494 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1495 : 0 : vtag_cfg->rx.vtag_type = 0;
1496 : :
1497 : 0 : rc = mbox_process(mbox);
1498 [ # # ]: 0 : if (rc)
1499 : 0 : goto exit;
1500 : :
1501 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1502 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1503 : : rx_vtag_action |= ((uint64_t)NIX_RX_VTAG_TYPE6 << 12);
1504 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1505 : :
1506 [ # # ]: 0 : if (*strip_cnt == 2) {
1507 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1508 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1509 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1510 : : }
1511 : 0 : flow->vtag_action = rx_vtag_action;
1512 : :
1513 : : rc = 0;
1514 : 0 : exit:
1515 : : mbox_put(mbox);
1516 : 0 : return rc;
1517 : : }
1518 : :
1519 : : static int
1520 : 0 : npc_vtag_action_program(struct roc_npc *roc_npc,
1521 : : const struct roc_npc_action actions[],
1522 : : struct roc_npc_flow *flow)
1523 : : {
1524 : : bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1525 : : const struct roc_npc_action *insert_actions;
1526 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1527 : : struct npc_action_vtag_info vlan_info[2];
1528 : 0 : int parsed_cnt = 0, strip_cnt = 0;
1529 : : int tot_vlan_params = 0;
1530 : : struct mbox *mbox;
1531 : : struct nix *nix;
1532 : : int i, rc;
1533 : :
1534 : : nix = roc_nix_to_nix_priv(roc_nix);
1535 : 0 : mbox = (&nix->dev)->mbox;
1536 [ # # ]: 0 : if (flow->has_rep)
1537 : 0 : mbox = flow->rep_mbox;
1538 : :
1539 : : memset(vlan_info, 0, sizeof(vlan_info));
1540 : :
1541 : 0 : flow->vtag_insert_enabled = false;
1542 : :
1543 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1544 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1545 [ # # ]: 0 : if (vlan_strip_parsed) {
1546 : 0 : plt_err("Incorrect VLAN strip actions");
1547 : 0 : return -EINVAL;
1548 : : }
1549 : 0 : rc = npc_vtag_strip_action_configure(mbox, actions,
1550 : : flow, &strip_cnt);
1551 [ # # ]: 0 : if (rc)
1552 : 0 : return rc;
1553 : :
1554 : 0 : plt_npc_dbg("VLAN strip action, strip_cnt %d", strip_cnt);
1555 [ # # ]: 0 : if (strip_cnt == 2)
1556 : 0 : actions++;
1557 : :
1558 : : vlan_strip_parsed = true;
1559 [ # # ]: 0 : } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1560 : : actions->type ==
1561 [ # # ]: 0 : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1562 : : actions->type ==
1563 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1564 [ # # ]: 0 : if (vlan_insert_parsed) {
1565 : 0 : plt_err("Incorrect VLAN insert actions");
1566 : 0 : return -EINVAL;
1567 : : }
1568 : :
1569 : : insert_actions = actions;
1570 : :
1571 [ # # ]: 0 : for (i = 0; i < 2; i++) {
1572 : 0 : rc = npc_vtag_insert_action_parse(
1573 : : insert_actions, flow, &vlan_info[i],
1574 : : &parsed_cnt);
1575 : :
1576 [ # # ]: 0 : if (rc)
1577 : 0 : return rc;
1578 : :
1579 [ # # ]: 0 : if (parsed_cnt) {
1580 : 0 : insert_actions += parsed_cnt;
1581 : 0 : tot_vlan_params += parsed_cnt;
1582 : 0 : flow->vtag_insert_count++;
1583 : : }
1584 : : }
1585 : 0 : actions += tot_vlan_params - 1;
1586 : : vlan_insert_parsed = true;
1587 : : }
1588 : : }
1589 : :
1590 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1591 : 0 : rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1592 : :
1593 [ # # ]: 0 : if (rc)
1594 : 0 : return rc;
1595 : : }
1596 : : return 0;
1597 : : }
1598 : :
1599 : : static int
1600 : 0 : npc_inline_dev_ipsec_action_free(struct npc *npc, struct roc_npc_flow *flow)
1601 : : {
1602 : : struct nix_inl_dev *inl_dev;
1603 : : struct idev_cfg *idev;
1604 : : int rc;
1605 : :
1606 : : PLT_SET_USED(npc);
1607 : :
1608 : 0 : idev = idev_get_cfg();
1609 [ # # ]: 0 : if (!idev)
1610 : : return 1;
1611 : :
1612 : 0 : inl_dev = idev->nix_inl_dev;
1613 : :
1614 [ # # # # : 0 : if (flow->nix_intf == NIX_INTF_RX && inl_dev && inl_dev->ipsec_index &&
# # # # ]
1615 [ # # ]: 0 : roc_npc_action_is_rx_inline(flow->npc_action)) {
1616 : 0 : inl_dev->curr_ipsec_idx--;
1617 : 0 : inl_dev->ipsec_index[inl_dev->curr_ipsec_idx] = flow->mcam_id;
1618 : 0 : flow->enable = 0;
1619 [ # # ]: 0 : if (flow->use_ctr) {
1620 : 0 : rc = npc_mcam_clear_counter(inl_dev->dev.mbox, flow->ctr_id);
1621 [ # # ]: 0 : if (rc)
1622 : : return rc;
1623 : :
1624 : 0 : rc = npc_mcam_free_counter(inl_dev->dev.mbox, flow->ctr_id);
1625 [ # # ]: 0 : if (rc)
1626 : : return rc;
1627 : : }
1628 : 0 : return npc_mcam_write_entry(inl_dev->dev.mbox, flow);
1629 : : }
1630 : :
1631 : : return 1;
1632 : : }
1633 : :
1634 : : void
1635 : 0 : roc_npc_sdp_channel_get(struct roc_npc *roc_npc, uint16_t *chan_base, uint16_t *chan_mask)
1636 : : {
1637 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1638 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1639 : : uint16_t num_chan, range, num_bits = 0;
1640 : : uint16_t mask = 0;
1641 : :
1642 : 0 : *chan_base = nix->rx_chan_base;
1643 : 0 : num_chan = nix->rx_chan_cnt - 1;
1644 [ # # ]: 0 : if (num_chan) {
1645 : 0 : range = *chan_base ^ (*chan_base + num_chan);
1646 : 0 : num_bits = (sizeof(uint32_t) * 8) - plt_clz32(range) - 1;
1647 : : /* Set mask for (15 - numbits) MSB bits */
1648 : 0 : *chan_mask = (uint16_t)~GENMASK(num_bits, 0);
1649 : 0 : *chan_mask &= 0xFFF;
1650 : : } else {
1651 : 0 : *chan_mask = (uint16_t)GENMASK(11, 0);
1652 : : }
1653 : :
1654 : 0 : mask = (uint16_t)GENMASK(num_bits, 0);
1655 [ # # ]: 0 : if (mask > num_chan + 1)
1656 : 0 : plt_warn(
1657 : : "npc: SDP channel base:%x, channel count:%x. channel mask:%x covers more than channel count",
1658 : : *chan_base, nix->rx_chan_cnt, *chan_mask);
1659 : 0 : }
1660 : :
1661 : : struct roc_npc_flow *
1662 : 0 : roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1663 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1664 : : uint16_t dst_pf_func, uint64_t npc_default_action, int *errcode)
1665 : : {
1666 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1667 : 0 : uint16_t sdp_chan_base = 0, sdp_chan_mask = 0;
1668 : : struct roc_npc_flow *flow, *flow_iter;
1669 : : struct npc_parse_state parse_state;
1670 : : struct npc_flow_list *list;
1671 : : int rc;
1672 : :
1673 : 0 : npc->channel = roc_npc->channel;
1674 : 0 : npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1675 [ # # ]: 0 : if (npc->is_sdp_link) {
1676 [ # # ]: 0 : if (roc_npc->is_sdp_mask_set) {
1677 : 0 : npc->sdp_channel = roc_npc->sdp_channel;
1678 : 0 : npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1679 : : } else {
1680 : 0 : roc_npc_sdp_channel_get(roc_npc, &sdp_chan_base, &sdp_chan_mask);
1681 : 0 : npc->sdp_channel = sdp_chan_base;
1682 : 0 : npc->sdp_channel_mask = sdp_chan_mask;
1683 : : }
1684 : : }
1685 : :
1686 : 0 : flow = plt_zmalloc(sizeof(*flow), 0);
1687 [ # # ]: 0 : if (flow == NULL) {
1688 : 0 : *errcode = NPC_ERR_NO_MEM;
1689 : 0 : return NULL;
1690 : : }
1691 : : memset(flow, 0, sizeof(*flow));
1692 : : memset(&parse_state, 0, sizeof(parse_state));
1693 : :
1694 : 0 : flow->port_id = -1;
1695 [ # # ]: 0 : if (roc_npc->rep_npc) {
1696 : 0 : flow->rep_channel =
1697 [ # # ]: 0 : (roc_npc->rep_rx_channel == 0) ?
1698 : 0 : roc_nix_to_nix_priv(roc_npc->rep_npc->roc_nix)->rx_chan_base :
1699 : : roc_npc->rep_rx_channel;
1700 : 0 : flow->rep_pf_func = roc_npc->rep_pf_func;
1701 : 0 : flow->rep_act_pf_func = roc_npc->rep_act_pf_func;
1702 : 0 : flow->rep_act_rep = roc_npc->rep_act_rep;
1703 : 0 : flow->rep_mbox = roc_npc_to_npc_priv(roc_npc->rep_npc)->mbox;
1704 : 0 : flow->has_rep = true;
1705 : 0 : flow->is_rep_vf = !roc_nix_is_pf(roc_npc->rep_npc->roc_nix);
1706 : 0 : flow->port_id = roc_npc->rep_port_id;
1707 : 0 : flow->rep_npc = roc_npc_to_npc_priv(roc_npc->rep_npc);
1708 : 0 : roc_npc->rep_act_rep = false;
1709 : 0 : roc_npc->rep_act_pf_func = 0;
1710 : 0 : roc_npc->rep_rx_channel = 0;
1711 : : }
1712 : :
1713 : 0 : parse_state.dst_pf_func = dst_pf_func;
1714 : 0 : parse_state.npc_default_action = npc_default_action;
1715 : :
1716 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1717 [ # # ]: 0 : if (rc != 0) {
1718 : 0 : *errcode = rc;
1719 : 0 : goto err_exit;
1720 : : }
1721 : :
1722 : 0 : rc = npc_vtag_action_program(roc_npc, actions, flow);
1723 [ # # ]: 0 : if (rc != 0) {
1724 : 0 : *errcode = rc;
1725 : 0 : goto err_exit;
1726 : : }
1727 : :
1728 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1729 : :
1730 : 0 : rc = npc_program_mcam(npc, &parse_state, 1);
1731 [ # # ]: 0 : if (rc != 0) {
1732 : 0 : *errcode = rc;
1733 : 0 : goto err_exit;
1734 : : }
1735 : :
1736 : : /* If Egress mirror requested then enable TL3_TL2_LINK_CFG */
1737 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1738 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1739 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1740 : 0 : flow->mcast_pf_funcs[1], true);
1741 : : else
1742 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1743 : : flow->mcast_pf_funcs[0], true);
1744 [ # # ]: 0 : if (rc) {
1745 : 0 : plt_err("Adding egress mirror failed");
1746 : 0 : *errcode = rc;
1747 : 0 : goto err_exit;
1748 : : }
1749 : : }
1750 : :
1751 : 0 : rc = npc_rss_action_program(roc_npc, actions, flow);
1752 [ # # ]: 0 : if (rc != 0) {
1753 : 0 : *errcode = rc;
1754 : 0 : goto set_rss_failed;
1755 : : }
1756 : 0 : roc_npc->rep_npc = NULL;
1757 : 0 : roc_npc->rep_act_pf_func = 0;
1758 : :
1759 [ # # ]: 0 : if (flow->has_age_action)
1760 : 0 : npc_age_flow_list_entry_add(roc_npc, flow);
1761 : :
1762 [ # # ]: 0 : if (flow->use_pre_alloc == 0)
1763 : 0 : list = &npc->flow_list[flow->priority];
1764 : : else
1765 : 0 : list = &npc->ipsec_list;
1766 : : /* List in ascending order of mcam entries */
1767 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1768 [ # # ]: 0 : if (flow_iter->mcam_id > flow->mcam_id) {
1769 : 0 : TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1770 : 0 : roc_npc->rep_npc = NULL;
1771 : 0 : return flow;
1772 : : }
1773 : : }
1774 : 0 : TAILQ_INSERT_TAIL(list, flow, next);
1775 : :
1776 : 0 : return flow;
1777 : :
1778 : : set_rss_failed:
1779 : 0 : roc_npc->rep_npc = NULL;
1780 : 0 : roc_npc->rep_act_pf_func = 0;
1781 [ # # ]: 0 : if (flow->use_pre_alloc == 0) {
1782 : 0 : rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
1783 [ # # ]: 0 : if (rc != 0) {
1784 : 0 : *errcode = rc;
1785 : 0 : plt_free(flow);
1786 : 0 : return NULL;
1787 : : }
1788 : : } else {
1789 : 0 : npc_inline_dev_ipsec_action_free(npc, flow);
1790 : : }
1791 : 0 : err_exit:
1792 : 0 : roc_npc->rep_npc = NULL;
1793 : 0 : roc_npc->rep_act_pf_func = 0;
1794 : 0 : plt_free(flow);
1795 : 0 : return NULL;
1796 : : }
1797 : :
1798 : : int
1799 : 0 : npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1800 : : {
1801 : : struct npc *lnpc = npc;
1802 : : uint32_t rss_grp;
1803 : :
1804 [ # # ]: 0 : if (flow->has_rep)
1805 : 0 : lnpc = flow->rep_npc;
1806 : :
1807 [ # # ]: 0 : if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1808 : 0 : rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1809 : : NPC_RSS_ACT_GRP_MASK;
1810 [ # # # # ]: 0 : if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1811 : : return -EINVAL;
1812 : :
1813 : 0 : plt_bitmap_clear(lnpc->rss_grp_entries, rss_grp);
1814 : : }
1815 : :
1816 : : return 0;
1817 : : }
1818 : :
1819 : : static int
1820 : 0 : roc_npc_delete_spi_to_sa_action(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1821 : : {
1822 : : struct nix_spi_to_sa_delete_req *req;
1823 : : struct nix_inl_dev *inl_dev;
1824 : : struct idev_cfg *idev;
1825 : : struct mbox *mbox;
1826 : :
1827 : : PLT_SET_USED(roc_npc);
1828 : :
1829 [ # # # # ]: 0 : if (!flow->spi_to_sa_info.has_action || flow->spi_to_sa_info.duplicate)
1830 : : return 0;
1831 : :
1832 : 0 : idev = idev_get_cfg();
1833 [ # # ]: 0 : if (!idev)
1834 : : return -1;
1835 : :
1836 : 0 : inl_dev = idev->nix_inl_dev;
1837 : 0 : mbox = inl_dev->dev.mbox;
1838 : 0 : req = mbox_alloc_msg_nix_spi_to_sa_delete(mbox);
1839 [ # # ]: 0 : if (req == NULL)
1840 : : return -ENOSPC;
1841 : 0 : req->hash_index = flow->spi_to_sa_info.hash_index;
1842 : 0 : req->way = flow->spi_to_sa_info.way;
1843 : 0 : return mbox_process_msg(mbox, NULL);
1844 : : }
1845 : :
1846 : : int
1847 : 0 : roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1848 : : {
1849 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1850 : : int rc;
1851 : :
1852 : 0 : rc = roc_npc_delete_spi_to_sa_action(roc_npc, flow);
1853 [ # # ]: 0 : if (rc)
1854 : : return rc;
1855 : :
1856 [ # # ]: 0 : if (npc_inline_dev_ipsec_action_free(npc, flow) == 0) {
1857 [ # # ]: 0 : TAILQ_REMOVE(&npc->ipsec_list, flow, next);
1858 : 0 : goto done;
1859 : : }
1860 : :
1861 : 0 : rc = npc_rss_group_free(npc, flow);
1862 [ # # ]: 0 : if (rc != 0) {
1863 : 0 : plt_err("Failed to free rss action rc = %d", rc);
1864 : 0 : return rc;
1865 : : }
1866 : :
1867 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1868 : 0 : rc = npc_vtag_cfg_delete(roc_npc, flow);
1869 [ # # ]: 0 : if (rc != 0)
1870 : : return rc;
1871 : : }
1872 : :
1873 : : /* Disable egress mirror rule */
1874 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1875 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1876 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1877 : 0 : flow->mcast_pf_funcs[1], false);
1878 : : else
1879 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1880 : : flow->mcast_pf_funcs[0], false);
1881 [ # # ]: 0 : if (rc)
1882 : 0 : plt_err("Failed to remove egress mirror rule");
1883 : : }
1884 [ # # ]: 0 : if (flow->is_sampling_rule)
1885 : 0 : roc_nix_mcast_list_free(npc->mbox, flow->mcast_grp_index);
1886 : :
1887 : 0 : rc = roc_npc_mcam_free(roc_npc, flow);
1888 [ # # ]: 0 : if (rc != 0)
1889 : : return rc;
1890 : :
1891 [ # # ]: 0 : TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1892 : :
1893 : 0 : npc_delete_prio_list_entry(npc, flow);
1894 : :
1895 [ # # ]: 0 : if (flow->has_age_action)
1896 : 0 : npc_age_flow_list_entry_delete(roc_npc, flow);
1897 : :
1898 [ # # ]: 0 : if (roc_npc->flow_age.age_flow_refcnt == 0)
1899 : 0 : npc_aging_ctrl_thread_destroy(roc_npc);
1900 : :
1901 : 0 : done:
1902 : 0 : plt_free(flow);
1903 : 0 : return 0;
1904 : : }
1905 : :
1906 : : void
1907 : 0 : roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc, int rep_port_id)
1908 : : {
1909 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1910 : : struct roc_npc_flow *flow_iter;
1911 : : struct npc_flow_list *list;
1912 : : uint32_t max_prio, i;
1913 : :
1914 : 0 : max_prio = npc->flow_max_priority;
1915 : :
1916 [ # # ]: 0 : for (i = 0; i < max_prio; i++) {
1917 : 0 : list = &npc->flow_list[i];
1918 : :
1919 : : /* List in ascending order of mcam entries */
1920 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1921 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1922 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1923 : : }
1924 : : }
1925 : :
1926 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, &npc->ipsec_list, next) {
1927 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1928 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1929 : : }
1930 : 0 : }
1931 : :
1932 : : int
1933 : 0 : roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1934 : : {
1935 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1936 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
1937 : : int idx, rc;
1938 : :
1939 [ # # ]: 0 : if (roc_nix_is_pf(roc_npc->roc_nix)) {
1940 : : rc = 0;
1941 : 0 : goto exit;
1942 : : }
1943 : :
1944 [ # # ]: 0 : if (roc_model_is_cn20k()) {
1945 : : struct npc_cn20k_mcam_read_base_rule_rsp *base_rule_rsp;
1946 : : struct cn20k_mcam_entry *base_entry;
1947 : :
1948 : 0 : (void)mbox_alloc_msg_npc_cn20k_read_base_steer_rule(mbox);
1949 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
1950 [ # # ]: 0 : if (rc) {
1951 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
1952 : 0 : goto exit;
1953 : : }
1954 : 0 : base_entry = &base_rule_rsp->entry;
1955 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1956 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
1957 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
1958 : : }
1959 : :
1960 : : } else {
1961 : : struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1962 : : struct mcam_entry *base_entry;
1963 : :
1964 : 0 : (void)mbox_alloc_msg_npc_read_base_steer_rule(mbox);
1965 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
1966 [ # # ]: 0 : if (rc) {
1967 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
1968 : 0 : goto exit;
1969 : : }
1970 : 0 : base_entry = &base_rule_rsp->entry_data;
1971 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1972 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
1973 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
1974 : : }
1975 : : }
1976 : : rc = 0;
1977 : 0 : exit:
1978 : : mbox_put(mbox);
1979 : 0 : return rc;
1980 : : }
1981 : :
1982 : : int
1983 : 0 : roc_npc_mcam_default_rule_action_get(struct roc_npc *roc_npc, uint64_t *action)
1984 : : {
1985 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1986 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
1987 : : int rc;
1988 : :
1989 : : struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1990 : : struct mcam_entry *base_entry;
1991 : :
1992 : 0 : (void)mbox_alloc_msg_npc_read_default_rule(mbox);
1993 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
1994 [ # # ]: 0 : if (rc) {
1995 : 0 : plt_err("Failed to fetch default MCAM entry");
1996 : 0 : goto exit;
1997 : : }
1998 : 0 : base_entry = &base_rule_rsp->entry_data;
1999 : :
2000 : 0 : *action = base_entry->action;
2001 : 0 : exit:
2002 : : mbox_put(mbox);
2003 : 0 : return rc;
2004 : : }
|