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 : : /* Create skip-size PKIND memzone if it doesn't exist */
424 [ # # ]: 0 : if (!plt_memzone_lookup(SKIP_SIZE_PKIND_MEMZONE)) {
425 : : const struct plt_memzone *mz;
426 : :
427 : 0 : mz = plt_memzone_reserve_cache_align(SKIP_SIZE_PKIND_MEMZONE,
428 : : sizeof(struct skip_size_pkind_cfg));
429 [ # # ]: 0 : if (mz != NULL)
430 : 0 : memset(mz->addr, 0, sizeof(struct skip_size_pkind_cfg));
431 : : }
432 : :
433 : : return rc;
434 : :
435 : 0 : done:
436 [ # # ]: 0 : if (npc->flow_list)
437 : 0 : plt_free(npc->flow_list);
438 [ # # ]: 0 : if (npc->prio_flow_list)
439 : 0 : plt_free(npc->prio_flow_list);
440 [ # # ]: 0 : if (npc_mem)
441 : 0 : plt_free(npc_mem);
442 : : return rc;
443 : : }
444 : :
445 : : int
446 [ # # ]: 0 : roc_npc_fini(struct roc_npc *roc_npc)
447 : : {
448 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
449 : : struct skip_size_pkind_cfg *cfg;
450 : : const struct plt_memzone *mz;
451 : : uint16_t i, count = 0;
452 : : int rc;
453 : :
454 [ # # ]: 0 : if (!roc_npc->flow_age.aged_flows_get_thread_exit)
455 : 0 : npc_aging_ctrl_thread_destroy(roc_npc);
456 : :
457 : 0 : rc = npc_flow_free_all_resources(npc);
458 [ # # ]: 0 : if (rc) {
459 : 0 : plt_err("Error when deleting NPC MCAM entries, counters");
460 : 0 : return rc;
461 : : }
462 : :
463 [ # # ]: 0 : if (npc->flow_list) {
464 : 0 : plt_free(npc->flow_list);
465 : 0 : npc->flow_list = NULL;
466 : : }
467 : :
468 [ # # ]: 0 : if (npc->prio_flow_list) {
469 : 0 : plt_free(npc->prio_flow_list);
470 : 0 : npc->prio_flow_list = NULL;
471 : : }
472 : :
473 : 0 : mz = plt_memzone_lookup(SKIP_SIZE_PKIND_MEMZONE);
474 [ # # ]: 0 : if (mz) {
475 : 0 : cfg = mz->addr;
476 : :
477 [ # # ]: 0 : for (i = 0; i < cfg->count; i++) {
478 [ # # ]: 0 : if (cfg->entries[i].skip_size == 0)
479 : 0 : count++;
480 : : }
481 : :
482 [ # # ]: 0 : if (count == cfg->count)
483 : 0 : plt_memzone_free(mz);
484 : : }
485 : :
486 : : return 0;
487 : : }
488 : :
489 : : int
490 : 0 : roc_npc_skip_size_pkind_get(struct roc_npc *roc_npc)
491 : : {
492 : : struct skip_size_pkind_cfg *cfg;
493 : : const struct plt_memzone *mz;
494 : : int i;
495 : :
496 [ # # ]: 0 : if (roc_npc->switch_header_type != ROC_PRIV_FLAGS_SKIP_SIZE)
497 : : return -1;
498 : :
499 : 0 : mz = plt_memzone_lookup(SKIP_SIZE_PKIND_MEMZONE);
500 [ # # ]: 0 : if (!mz)
501 : : return -1;
502 : 0 : cfg = mz->addr;
503 : :
504 [ # # ]: 0 : for (i = 0; i < cfg->count; i++) {
505 [ # # ]: 0 : if (cfg->entries[i].skip_size == roc_npc->skip_size)
506 : 0 : return cfg->entries[i].pkind + NPC_SKIP_SIZE_PKIND_MAX;
507 : : }
508 : :
509 : : return -1;
510 : : }
511 : :
512 : : int
513 : 0 : roc_npc_validate_portid_action(struct roc_npc *roc_npc_src, struct roc_npc *roc_npc_dst)
514 : : {
515 : 0 : struct roc_nix *roc_nix_src = roc_npc_src->roc_nix;
516 : : struct nix *nix_src = roc_nix_to_nix_priv(roc_nix_src);
517 : 0 : struct roc_nix *roc_nix_dst = roc_npc_dst->roc_nix;
518 : : struct nix *nix_dst = roc_nix_to_nix_priv(roc_nix_dst);
519 : :
520 [ # # ]: 0 : if (roc_nix_is_pf(roc_npc_dst->roc_nix)) {
521 : 0 : plt_err("Output port should be VF");
522 : 0 : return -EINVAL;
523 : : }
524 : :
525 [ # # ]: 0 : if (nix_dst->dev.vf >= nix_src->dev.maxvf) {
526 : 0 : plt_err("Invalid VF for output port");
527 : 0 : return -EINVAL;
528 : : }
529 : :
530 [ # # ]: 0 : if (nix_src->dev.pf != nix_dst->dev.pf) {
531 : 0 : plt_err("Output port should be VF of ingress PF");
532 : 0 : return -EINVAL;
533 : : }
534 : : return 0;
535 : : }
536 : :
537 : : static int
538 : 0 : npc_parse_spi_to_sa_action(struct roc_npc *roc_npc, const struct roc_npc_action *act,
539 : : struct roc_npc_flow *flow, uint8_t *has_spi_to_sa_action)
540 : : {
541 : : const struct roc_npc_sec_action *sec_action;
542 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
543 : : struct nix_spi_to_sa_add_req *req;
544 : : struct nix_spi_to_sa_add_rsp *rsp;
545 : : struct nix_inl_dev *inl_dev;
546 : : struct idev_cfg *idev;
547 : : uint64_t npc_action2 = 0;
548 : : union {
549 : : uint64_t reg;
550 : : union nix_rx_vtag_action_u act;
551 : 0 : } vtag_act = {0};
552 : : struct mbox *mbox;
553 : : uint8_t alg = 0;
554 : : int rc;
555 : :
556 [ # # # # ]: 0 : if (roc_npc->roc_nix->custom_sa_action == 0 || roc_model_is_cn9k() == 1 ||
557 [ # # # # ]: 0 : act->conf == NULL || flow->is_validate)
558 : : return 0;
559 : :
560 : 0 : idev = idev_get_cfg();
561 [ # # ]: 0 : if (!idev)
562 : : return -1;
563 : :
564 : 0 : inl_dev = idev->nix_inl_dev;
565 : :
566 : 0 : *has_spi_to_sa_action = true;
567 : 0 : sec_action = act->conf;
568 : :
569 [ # # # ]: 0 : switch (sec_action->alg) {
570 : 0 : case ROC_NPC_SEC_ACTION_ALG0:
571 : : case ROC_NPC_SEC_ACTION_ALG1:
572 : : case ROC_NPC_SEC_ACTION_ALG2:
573 : : case ROC_NPC_SEC_ACTION_ALG3:
574 : 0 : alg = sec_action->alg;
575 : 0 : break;
576 : 0 : case ROC_NPC_SEC_ACTION_ALG4:
577 : : alg = 0;
578 : 0 : mbox = inl_dev->dev.mbox;
579 : 0 : req = mbox_alloc_msg_nix_spi_to_sa_add(mbox);
580 [ # # ]: 0 : if (req == NULL)
581 : : return -ENOSPC;
582 : 0 : req->sa_index = sec_action->sa_index;
583 [ # # ]: 0 : req->spi_index = plt_be_to_cpu_32(flow->spi_to_sa_info.spi);
584 : 0 : req->match_id = flow->match_id;
585 [ # # ]: 0 : req->valid = true;
586 [ # # ]: 0 : if (roc_feature_nix_has_inl_profile()) {
587 [ # # ]: 0 : if (sec_action->use_custom_profile)
588 : 0 : req->inline_profile_id = sec_action->profile_id;
589 : : else
590 : 0 : req->inline_profile_id =
591 : 0 : roc_nix_inl_inb_ipsec_profile_id_get(roc_nix, true);
592 : : }
593 : : rc = mbox_process_msg(mbox, (void *)&rsp);
594 [ # # ]: 0 : if (rc)
595 : : return rc;
596 : 0 : flow->spi_to_sa_info.hash_index = rsp->hash_index;
597 : 0 : flow->spi_to_sa_info.way = rsp->way;
598 : 0 : flow->spi_to_sa_info.duplicate = rsp->is_duplicate;
599 : 0 : flow->spi_to_sa_info.has_action = true;
600 : 0 : break;
601 : : default:
602 : : return -1;
603 : : }
604 : :
605 [ # # ]: 0 : if (!roc_feature_nix_has_inl_profile()) {
606 : 0 : vtag_act.act.sa_xor = sec_action->sa_xor;
607 : 0 : vtag_act.act.sa_hi = sec_action->sa_hi;
608 : 0 : vtag_act.act.sa_lo = sec_action->sa_lo;
609 : : vtag_act.act.vtag1_valid = false;
610 : 0 : vtag_act.act.vtag1_lid = alg;
611 : :
612 : : } else {
613 : 0 : npc_action2 = ((uint64_t)sec_action->sa_xor << 7);
614 : 0 : npc_action2 |= ((uint64_t)sec_action->sa_hi << 48);
615 : 0 : npc_action2 |= ((uint64_t)sec_action->sa_lo << 32);
616 : 0 : npc_action2 |= ((uint64_t)alg << 17);
617 : : }
618 : 0 : flow->vtag_action = vtag_act.reg;
619 : 0 : flow->npc_action2 |= npc_action2;
620 : :
621 : 0 : return 0;
622 : : }
623 : :
624 : : static int
625 : 0 : roc_npc_process_sample_action(struct roc_npc *roc_npc,
626 : : const struct roc_npc_action_sample *sample_action,
627 : : struct roc_npc_flow *flow)
628 : : {
629 : 0 : struct nix *nix = roc_nix_to_nix_priv(roc_npc->roc_nix);
630 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
631 : :
632 : 0 : flow->is_sampling_rule = true;
633 : :
634 [ # # # # ]: 0 : switch (sample_action->action_type) {
635 : 0 : case ROC_NPC_ACTION_TYPE_PORT_ID:
636 : 0 : flow->mcast_pf_funcs[0] = sample_action->pf_func;
637 : 0 : flow->mcast_channels[0] = sample_action->channel;
638 : 0 : break;
639 : 0 : case ROC_NPC_ACTION_TYPE_PF:
640 : 0 : flow->mcast_pf_funcs[0] = roc_npc->pf_func;
641 : 0 : flow->mcast_channels[0] = npc->channel;
642 : 0 : break;
643 : 0 : case ROC_NPC_ACTION_TYPE_VF:
644 [ # # ]: 0 : if (sample_action->pf_func >= nix->dev.maxvf)
645 : : return -EINVAL;
646 : 0 : flow->mcast_pf_funcs[0] =
647 : 0 : ((roc_npc->pf_func & 0xfc00) | (sample_action->pf_func + 1));
648 : 0 : flow->mcast_channels[0] = npc->channel;
649 : 0 : break;
650 : : default:
651 : : return -EINVAL;
652 : : }
653 : :
654 : : return 0;
655 : : }
656 : :
657 : : static int
658 : 0 : npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
659 : : const struct roc_npc_action actions[], struct roc_npc_flow *flow,
660 : : uint16_t dst_pf_func, uint64_t npc_default_action)
661 : : {
662 : : bool vlan_insert_action = false, npc_action_set = false;
663 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
664 : : const struct roc_npc_action *sec_action = NULL;
665 : : const struct roc_npc_action_sample *act_sample;
666 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
667 : : const struct roc_npc_action_mark *act_mark;
668 : : const struct roc_npc_action_meter *act_mtr;
669 : : const struct roc_npc_action_queue *act_q;
670 : : const struct roc_npc_sec_action *sec_act;
671 : : const struct roc_npc_action_vf *vf_act;
672 : 0 : uint8_t has_spi_to_sa_act = 0;
673 : : int sel_act, req_act = 0;
674 : : uint16_t pf_func, vf_id;
675 : : bool is_non_inp = false;
676 : : int errcode = 0;
677 : : int mark = 0;
678 : : int rq = 0;
679 : : int rc = 0;
680 : :
681 : : /* Initialize actions */
682 : 0 : flow->ctr_id = NPC_COUNTER_NONE;
683 : 0 : flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
684 : 0 : flow->npc_action2 = 0;
685 : 0 : pf_func = npc->pf_func;
686 [ # # ]: 0 : if (flow->has_rep)
687 : 0 : pf_func = flow->rep_pf_func;
688 : :
689 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
690 [ # # # # : 0 : switch (actions->type) {
# # # # #
# # # # #
# # # #
# ]
691 : : case ROC_NPC_ACTION_TYPE_VOID:
692 : : break;
693 : 0 : case ROC_NPC_ACTION_TYPE_MARK:
694 : 0 : act_mark = (const struct roc_npc_action_mark *)
695 : : actions->conf;
696 [ # # ]: 0 : if (act_mark->id > (NPC_FLOW_FLAG_VAL - 2)) {
697 : 0 : plt_err("mark value must be < 0xfffe");
698 : 0 : goto err_exit;
699 : : }
700 : 0 : mark = act_mark->id + 1;
701 : 0 : req_act |= ROC_NPC_ACTION_TYPE_MARK;
702 : 0 : npc->mark_actions += 1;
703 : 0 : flow->match_id = mark;
704 : 0 : break;
705 : :
706 : 0 : case ROC_NPC_ACTION_TYPE_FLAG:
707 : : mark = NPC_FLOW_FLAG_VAL;
708 : 0 : req_act |= ROC_NPC_ACTION_TYPE_FLAG;
709 : 0 : npc->mark_actions += 1;
710 : 0 : break;
711 : :
712 : 0 : case ROC_NPC_ACTION_TYPE_COUNT:
713 : : /* Indicates, need a counter */
714 : 0 : flow->use_ctr = 1;
715 : 0 : req_act |= ROC_NPC_ACTION_TYPE_COUNT;
716 : 0 : break;
717 : :
718 : 0 : case ROC_NPC_ACTION_TYPE_DROP:
719 : 0 : req_act |= ROC_NPC_ACTION_TYPE_DROP;
720 : 0 : break;
721 : :
722 : 0 : case ROC_NPC_ACTION_TYPE_PF:
723 : 0 : req_act |= ROC_NPC_ACTION_TYPE_PF;
724 : 0 : pf_func &= (0xfc00);
725 : 0 : break;
726 : :
727 : 0 : case ROC_NPC_ACTION_TYPE_VF:
728 : 0 : vf_act = (const struct roc_npc_action_vf *)actions->conf;
729 [ # # ]: 0 : req_act |= ROC_NPC_ACTION_TYPE_VF;
730 [ # # ]: 0 : if (roc_model_is_cn20k())
731 : 0 : vf_id = vf_act->id & RVU_PFVF_FUNC_MASK_CN20K;
732 : : else
733 : 0 : vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
734 : 0 : pf_func &= (0xfc00);
735 : 0 : pf_func = (pf_func | (vf_id + 1));
736 : 0 : break;
737 : :
738 : 0 : case ROC_NPC_ACTION_TYPE_PORT_ID:
739 : : pf_func = dst_pf_func;
740 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VF;
741 : 0 : break;
742 : :
743 : 0 : case ROC_NPC_ACTION_TYPE_QUEUE:
744 : 0 : act_q = (const struct roc_npc_action_queue *)actions->conf;
745 : 0 : rq = act_q->index & 0xFFFFF;
746 : 0 : req_act |= ROC_NPC_ACTION_TYPE_QUEUE;
747 : 0 : break;
748 : :
749 : 0 : case ROC_NPC_ACTION_TYPE_RSS:
750 : 0 : req_act |= ROC_NPC_ACTION_TYPE_RSS;
751 : 0 : break;
752 : :
753 : 0 : case ROC_NPC_ACTION_TYPE_SEC:
754 : : /* Assumes user has already configured security
755 : : * session for this flow. Associated conf is
756 : : * opaque. When security is implemented,
757 : : * we need to verify that for specified security
758 : : * session:
759 : : * action_type ==
760 : : * NPC_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
761 : : * session_protocol ==
762 : : * NPC_SECURITY_PROTOCOL_IPSEC
763 : : */
764 : :
765 [ # # ]: 0 : if (!actions->no_sec_action) {
766 : 0 : sec_act = (const struct roc_npc_sec_action *)actions->conf;
767 : : sec_action = actions;
768 [ # # # # ]: 0 : is_non_inp = sec_act ? sec_act->is_non_inp : false;
769 : : } else {
770 : 0 : is_non_inp = actions->is_non_inp;
771 : : }
772 : :
773 : 0 : req_act |= ROC_NPC_ACTION_TYPE_SEC;
774 : : rq = 0;
775 : 0 : roc_nix = roc_npc->roc_nix;
776 : :
777 : : /* Special processing when with inline device */
778 [ # # # # ]: 0 : if (roc_nix_inb_is_with_inl_dev(roc_nix) &&
779 : 0 : roc_nix_inl_dev_is_probed()) {
780 : : struct roc_nix_rq *inl_rq;
781 : :
782 : 0 : inl_rq = roc_nix_inl_dev_rq(roc_nix);
783 [ # # ]: 0 : if (!inl_rq) {
784 : : errcode = NPC_ERR_INTERNAL;
785 : 0 : goto err_exit;
786 : : }
787 : 0 : rq = inl_rq->qid;
788 : 0 : pf_func = nix_inl_dev_pffunc_get();
789 : : }
790 : :
791 [ # # ]: 0 : if (roc_nix_inl_dev_is_probed())
792 : 0 : flow->is_inline_dev = 1;
793 : : break;
794 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
795 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
796 : 0 : break;
797 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_INSERT:
798 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_INSERT;
799 : 0 : break;
800 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT:
801 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
802 : 0 : break;
803 : 0 : case ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT:
804 : 0 : req_act |= ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
805 : 0 : break;
806 : 0 : case ROC_NPC_ACTION_TYPE_METER:
807 : 0 : act_mtr = (const struct roc_npc_action_meter *)
808 : : actions->conf;
809 : 0 : flow->mtr_id = act_mtr->mtr_id;
810 : 0 : req_act |= ROC_NPC_ACTION_TYPE_METER;
811 : 0 : break;
812 : 0 : case ROC_NPC_ACTION_TYPE_AGE:
813 [ # # ]: 0 : if (flow->is_validate == true)
814 : : break;
815 : : plt_seqcount_init(&roc_npc->flow_age.seq_cnt);
816 : 0 : errcode = npc_aging_ctrl_thread_create(roc_npc,
817 : 0 : actions->conf,
818 : : flow);
819 [ # # ]: 0 : if (errcode != 0)
820 : 0 : goto err_exit;
821 : 0 : req_act |= ROC_NPC_ACTION_TYPE_AGE;
822 : 0 : break;
823 : 0 : case ROC_NPC_ACTION_TYPE_SAMPLE:
824 : 0 : req_act |= ROC_NPC_ACTION_TYPE_SAMPLE;
825 : 0 : act_sample = actions->conf;
826 : 0 : errcode = roc_npc_process_sample_action(roc_npc, act_sample, flow);
827 [ # # ]: 0 : if (errcode)
828 : 0 : goto err_exit;
829 : : break;
830 : 0 : default:
831 : : errcode = NPC_ERR_ACTION_NOTSUP;
832 : 0 : goto err_exit;
833 : : }
834 : : }
835 : :
836 [ # # ]: 0 : if (sec_action) {
837 : 0 : rc = npc_parse_spi_to_sa_action(roc_npc, sec_action, flow, &has_spi_to_sa_act);
838 [ # # ]: 0 : if (rc) {
839 : : errcode = NPC_ERR_ACTION_NOTSUP;
840 : 0 : goto err_exit;
841 : : }
842 : : }
843 : :
844 [ # # ]: 0 : if (req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
845 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT))
846 : : vlan_insert_action = true;
847 : :
848 [ # # ]: 0 : if ((req_act & (ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
849 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT)) ==
850 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
851 : 0 : plt_err("PCP insert action can't be supported alone");
852 : : errcode = NPC_ERR_ACTION_NOTSUP;
853 : 0 : goto err_exit;
854 : : }
855 : :
856 [ # # # # ]: 0 : if (has_spi_to_sa_act && (vlan_insert_action ||
857 [ # # ]: 0 : (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP))) {
858 : 0 : plt_err("Both MSNS and VLAN insert/strip action can't be supported"
859 : : " together");
860 : : errcode = NPC_ERR_ACTION_NOTSUP;
861 : 0 : goto err_exit;
862 : : }
863 : :
864 : : /* Both STRIP and INSERT actions are not supported */
865 [ # # # # ]: 0 : if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
866 : : errcode = NPC_ERR_ACTION_NOTSUP;
867 : 0 : goto err_exit;
868 : : }
869 : :
870 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE) {
871 : : /* One entry for the mce list PF and channel comes from the sample subaction.
872 : : * Another one is the action target of the flow rule getting created.
873 : : */
874 : 0 : flow->mcast_pf_funcs[1] = pf_func;
875 : 0 : flow->mcast_channels[1] = npc->channel;
876 [ # # ]: 0 : if (req_act & (ROC_NPC_ACTION_TYPE_DROP | ROC_NPC_ACTION_TYPE_SEC |
877 : : ROC_NPC_ACTION_TYPE_RSS)) {
878 : 0 : plt_err("Drop/RSS/SEC not supported with action type sample");
879 : 0 : return -EINVAL;
880 : : }
881 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == flow->mcast_pf_funcs[1]) {
882 : 0 : plt_err("Sample destination and target cannot be same");
883 : 0 : return -EINVAL;
884 : : }
885 [ # # # # ]: 0 : if ((attr->egress) && (flow->mcast_channels[0] == flow->mcast_channels[1])) {
886 : 0 : plt_err("Mirroring within PF and VF not allowed");
887 : 0 : return -EINVAL;
888 : : }
889 : : }
890 : :
891 : : /* Check if actions specified are compatible */
892 [ # # ]: 0 : if (attr->egress) {
893 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
894 : 0 : plt_err("VLAN pop action is not supported on Egress");
895 : : errcode = NPC_ERR_ACTION_NOTSUP;
896 : 0 : goto err_exit;
897 : : }
898 : :
899 [ # # ]: 0 : if (req_act &
900 : : ~(ROC_NPC_ACTION_TYPE_VLAN_INSERT | ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT |
901 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT | ROC_NPC_ACTION_TYPE_DROP |
902 : : ROC_NPC_ACTION_TYPE_COUNT | ROC_NPC_ACTION_TYPE_SAMPLE)) {
903 : 0 : plt_err("Only VLAN insert, drop, count, sample supported on Egress");
904 : : errcode = NPC_ERR_ACTION_NOTSUP;
905 : 0 : goto err_exit;
906 : : }
907 : :
908 [ # # ]: 0 : if (vlan_insert_action &&
909 [ # # ]: 0 : (req_act & ROC_NPC_ACTION_TYPE_DROP)) {
910 : 0 : plt_err("Both VLAN insert and drop actions cannot be supported");
911 : : errcode = NPC_ERR_ACTION_NOTSUP;
912 : 0 : goto err_exit;
913 : : }
914 : :
915 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
916 : 0 : flow->npc_action = NIX_TX_ACTIONOP_DROP;
917 [ # # # # ]: 0 : } else if ((req_act & ROC_NPC_ACTION_TYPE_COUNT) || vlan_insert_action) {
918 : 0 : flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
919 [ # # ]: 0 : if (flow->rep_act_rep) {
920 : : flow->npc_action = NIX_TX_ACTIONOP_UCAST_CHAN;
921 : 0 : flow->npc_action |= (uint64_t)0x3f << 12;
922 : : }
923 : : } else {
924 : 0 : plt_err("Unsupported action for egress");
925 : : errcode = NPC_ERR_ACTION_NOTSUP;
926 : 0 : goto err_exit;
927 : : }
928 : :
929 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE) {
930 : 0 : flow->mcast_pf_funcs[1] = pf_func;
931 : 0 : flow->mcast_channels[1] = npc->channel;
932 : : }
933 : :
934 : : /* PF func who is sending the packet */
935 : 0 : flow->tx_pf_func = pf_func;
936 : 0 : goto done;
937 : : } else {
938 [ # # ]: 0 : if (vlan_insert_action) {
939 : : errcode = NPC_ERR_ACTION_NOTSUP;
940 : 0 : goto err_exit;
941 : : }
942 : : }
943 : :
944 : : /* We have already verified the attr, this is ingress.
945 : : * - Exactly one terminating action is supported
946 : : * - Exactly one of MARK or FLAG is supported
947 : : * - If terminating action is DROP, only count is valid.
948 : : */
949 : 0 : sel_act = req_act & NPC_ACTION_TERM;
950 [ # # ]: 0 : if ((sel_act & (sel_act - 1)) != 0) {
951 : : errcode = NPC_ERR_ACTION_NOTSUP;
952 : 0 : goto err_exit;
953 : : }
954 : :
955 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
956 : 0 : sel_act = req_act & ~ROC_NPC_ACTION_TYPE_COUNT;
957 [ # # ]: 0 : if ((sel_act & (sel_act - 1)) != 0) {
958 : : errcode = NPC_ERR_ACTION_NOTSUP;
959 : 0 : goto err_exit;
960 : : }
961 : : }
962 : :
963 [ # # ]: 0 : if ((req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) ==
964 : : (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
965 : : errcode = NPC_ERR_ACTION_NOTSUP;
966 : 0 : goto err_exit;
967 : : }
968 : :
969 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)
970 : 0 : npc->vtag_strip_actions++;
971 : :
972 : : /* Set NIX_RX_ACTIONOP */
973 [ # # ]: 0 : if (req_act == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
974 : : /* Only VLAN action is provided */
975 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
976 [ # # ]: 0 : } else if (req_act & (ROC_NPC_ACTION_TYPE_PF | ROC_NPC_ACTION_TYPE_VF)) {
977 : : /* Check if any other action is set */
978 [ # # ]: 0 : if ((req_act == ROC_NPC_ACTION_TYPE_PF) || (req_act == ROC_NPC_ACTION_TYPE_VF)) {
979 : 0 : flow->npc_action = npc_default_action;
980 : : npc_action_set = true;
981 : : } else {
982 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
983 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_QUEUE)
984 : 0 : flow->recv_queue = rq;
985 : : }
986 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_DROP) {
987 : 0 : flow->npc_action = NIX_RX_ACTIONOP_DROP;
988 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) {
989 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
990 : 0 : flow->recv_queue = rq;
991 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_RSS) {
992 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
993 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_SEC) {
994 [ # # ]: 0 : if (roc_feature_nix_has_inl_profile()) {
995 : : const struct roc_npc_sec_action *sa_action = NULL;
996 : : uint16_t profile_id;
997 : :
998 : 0 : profile_id = roc_nix_inl_inb_ipsec_profile_id_get(roc_nix, true);
999 [ # # # # ]: 0 : if (sec_action && sec_action->conf) {
1000 : : sa_action = (const struct roc_npc_sec_action *)sec_action->conf;
1001 [ # # ]: 0 : if (sa_action->use_custom_profile)
1002 : 0 : profile_id = sa_action->profile_id;
1003 : : }
1004 [ # # ]: 0 : flow->npc_action2 |= (is_non_inp ? (1ULL << 15) : 0) | (profile_id << 8);
1005 : :
1006 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_CPT;
1007 : 0 : flow->npc_action |= (uint64_t)rq << 20;
1008 : : } else {
1009 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
1010 : 0 : flow->npc_action |= (uint64_t)rq << 20;
1011 : : }
1012 [ # # ]: 0 : } else if (req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
1013 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1014 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
1015 : : /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
1016 : : * This is default action, when user specify only
1017 : : * COUNT ACTION
1018 : : */
1019 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1020 : : } else {
1021 : : /* Should never reach here */
1022 : : errcode = NPC_ERR_ACTION_NOTSUP;
1023 : 0 : goto err_exit;
1024 : : }
1025 : :
1026 : : if (!npc_action_set) {
1027 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE)
1028 : 0 : flow->npc_action = NIX_RX_ACTIONOP_MCAST;
1029 : :
1030 [ # # ]: 0 : if (mark)
1031 : 0 : flow->npc_action |= (uint64_t)mark << 40;
1032 : :
1033 : : /* Ideally AF must ensure that correct pf_func is set */
1034 : 0 : flow->npc_action |= (uint64_t)pf_func << 4;
1035 : : }
1036 : : done:
1037 : : return 0;
1038 : :
1039 : : err_exit:
1040 : : return errcode;
1041 : : }
1042 : :
1043 : : typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
1044 : :
1045 : : static int
1046 : 0 : npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
1047 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
1048 : : {
1049 : 0 : npc_parse_stage_func_t parse_stage_funcs[] = {
1050 : : npc_parse_meta_items, npc_parse_port_representor_id,
1051 : : npc_parse_mark_item, npc_parse_pre_l2,
1052 : : npc_parse_cpt_hdr, npc_parse_higig2_hdr,
1053 : : npc_parse_tx_queue, npc_parse_la,
1054 : : npc_parse_lb, npc_parse_lc,
1055 : : npc_parse_ld, npc_parse_le,
1056 : : npc_parse_lf, npc_parse_lg,
1057 : : npc_parse_lh,
1058 : : };
1059 : : uint8_t layer = 0;
1060 : : int key_offset;
1061 : : int rc;
1062 : :
1063 [ # # ]: 0 : if (pattern == NULL)
1064 : : return NPC_ERR_PARAM;
1065 : :
1066 : 0 : pst->npc = npc;
1067 : 0 : pst->flow = flow;
1068 : 0 : pst->nix_intf = flow->nix_intf;
1069 : :
1070 : : /* Use integral byte offset */
1071 : : key_offset = pst->npc->keyx_len[flow->nix_intf];
1072 : : key_offset = (key_offset + 7) / 8;
1073 : :
1074 : : /* Location where LDATA would begin */
1075 : 0 : pst->mcam_data = (uint8_t *)flow->mcam_data;
1076 : 0 : pst->mcam_mask = (uint8_t *)flow->mcam_mask;
1077 : :
1078 [ # # # # ]: 0 : while (pattern->type != ROC_NPC_ITEM_TYPE_END && layer < PLT_DIM(parse_stage_funcs)) {
1079 : : /* Skip place-holders */
1080 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
1081 [ # # ]: 0 : if (pattern->type == ROC_NPC_ITEM_TYPE_END)
1082 : : break;
1083 : :
1084 : 0 : pst->pattern = pattern;
1085 : 0 : rc = parse_stage_funcs[layer](pst);
1086 [ # # ]: 0 : if (rc != 0)
1087 : 0 : return rc;
1088 : :
1089 : 0 : layer++;
1090 : :
1091 : : /*
1092 : : * Parse stage function sets pst->pattern to
1093 : : * 1 past the last item it consumed.
1094 : : */
1095 : 0 : pattern = pst->pattern;
1096 : :
1097 [ # # ]: 0 : if (pst->terminate)
1098 : : break;
1099 : : }
1100 : :
1101 : : /* Skip trailing place-holders */
1102 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
1103 : :
1104 : : /* Are there more items than what we can handle? */
1105 [ # # ]: 0 : if (pattern->type != ROC_NPC_ITEM_TYPE_END)
1106 : 0 : return NPC_ERR_PATTERN_NOTSUP;
1107 : :
1108 : : return 0;
1109 : : }
1110 : :
1111 : : static int
1112 : : npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
1113 : : struct roc_npc_flow *flow)
1114 : : {
1115 : 0 : if (attr == NULL)
1116 : : return NPC_ERR_PARAM;
1117 [ # # ]: 0 : else if (attr->priority >= npc->flow_max_priority)
1118 : : return NPC_ERR_PARAM;
1119 [ # # ]: 0 : else if ((!attr->egress && !attr->ingress) ||
1120 : : (attr->egress && attr->ingress))
1121 : : return NPC_ERR_PARAM;
1122 : :
1123 [ # # ]: 0 : if (attr->ingress)
1124 : 0 : flow->nix_intf = ROC_NPC_INTF_RX;
1125 : : else
1126 : 0 : flow->nix_intf = ROC_NPC_INTF_TX;
1127 : :
1128 : 0 : flow->priority = attr->priority;
1129 : : return 0;
1130 : : }
1131 : :
1132 : : static int
1133 [ # # ]: 0 : npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1134 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1135 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
1136 : : {
1137 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1138 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1139 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1140 : : int err;
1141 : :
1142 [ # # ]: 0 : pst->nb_tx_queues = nix->nb_tx_queues;
1143 : :
1144 : : /* Check attr */
1145 : : err = npc_parse_attr(npc, attr, flow);
1146 : : if (err)
1147 : : return err;
1148 : :
1149 : : /* Check pattern */
1150 : 0 : err = npc_parse_pattern(npc, pattern, flow, pst);
1151 [ # # ]: 0 : if (err)
1152 : : return err;
1153 : :
1154 : : /* Check action */
1155 : 0 : err = npc_parse_actions(roc_npc, attr, actions, flow, pst->dst_pf_func,
1156 : : pst->npc_default_action);
1157 [ # # ]: 0 : if (err)
1158 : 0 : return err;
1159 : : return 0;
1160 : : }
1161 : :
1162 : : int
1163 : 0 : roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1164 : : const struct roc_npc_item_info pattern[],
1165 : : const struct roc_npc_action actions[],
1166 : : struct roc_npc_flow *flow)
1167 : : {
1168 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1169 : 0 : struct npc_parse_state parse_state = {0};
1170 : : int rc;
1171 : :
1172 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1173 [ # # ]: 0 : if (rc)
1174 : : return rc;
1175 : :
1176 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1177 : :
1178 : 0 : return npc_program_mcam(npc, &parse_state, 0);
1179 : : }
1180 : :
1181 : : int
1182 : 0 : npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
1183 : : {
1184 : 0 : struct plt_bitmap *bmap = npc->rss_grp_entries;
1185 : :
1186 [ # # ]: 0 : for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
1187 [ # # ]: 0 : if (!plt_bitmap_get(bmap, *pos))
1188 : : break;
1189 : : }
1190 [ # # ]: 0 : return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
1191 : : }
1192 : :
1193 : : int
1194 : 0 : npc_rss_action_configure(struct roc_npc *roc_npc, const struct roc_npc_action_rss *rss,
1195 : : uint8_t *alg_idx, uint32_t *rss_grp, uint32_t mcam_id,
1196 : : uint16_t rss_repte_pf_func)
1197 : : {
1198 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1199 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1200 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1201 : : uint32_t flowkey_cfg, rss_grp_idx, i, rem;
1202 : : uint8_t key[ROC_NIX_RSS_KEY_LEN];
1203 : : const uint8_t *key_ptr;
1204 : : uint8_t flowkey_algx;
1205 : : uint32_t key_len;
1206 : : uint16_t *reta;
1207 : : int rc;
1208 : :
1209 : 0 : roc_nix_rss_key_get(roc_nix, key);
1210 [ # # ]: 0 : if (rss->key == NULL) {
1211 : : key_ptr = key;
1212 : : } else {
1213 : 0 : key_len = rss->key_len;
1214 : : if (key_len > ROC_NIX_RSS_KEY_LEN)
1215 : : key_len = ROC_NIX_RSS_KEY_LEN;
1216 : :
1217 [ # # ]: 0 : for (i = 0; i < key_len; i++) {
1218 [ # # ]: 0 : if (key[i] != rss->key[i]) {
1219 : 0 : plt_err("RSS key config not supported");
1220 : 0 : plt_err("New Key:");
1221 [ # # ]: 0 : for (i = 0; i < key_len; i++)
1222 : 0 : plt_dump_no_nl("0x%.2x ", rss->key[i]);
1223 : 0 : plt_dump_no_nl("\n");
1224 : 0 : plt_err("Configured Key:");
1225 [ # # ]: 0 : for (i = 0; i < ROC_NIX_RSS_KEY_LEN; i++)
1226 : 0 : plt_dump_no_nl("0x%.2x ", key[i]);
1227 : 0 : plt_dump_no_nl("\n");
1228 : 0 : return -ENOTSUP;
1229 : : }
1230 : : }
1231 : : key_ptr = rss->key;
1232 : : }
1233 : :
1234 : 0 : rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
1235 : : /* RSS group :0 is not usable for flow rss action */
1236 [ # # # # ]: 0 : if (rc < 0 || rss_grp_idx == 0)
1237 : : return -ENOSPC;
1238 : :
1239 [ # # # # ]: 0 : for (i = 0; (i < rss->queue_num) && !rss_repte_pf_func; i++) {
1240 [ # # ]: 0 : if (rss->queue[i] >= nix->nb_rx_queues) {
1241 : 0 : plt_err("queue id > max number of queues");
1242 : 0 : return -EINVAL;
1243 : : }
1244 : : }
1245 : :
1246 : 0 : *rss_grp = rss_grp_idx;
1247 : :
1248 : 0 : roc_nix_rss_key_set(roc_nix, key_ptr);
1249 : :
1250 : : /* If queue count passed in the rss action is less than
1251 : : * HW configured reta size, replicate rss action reta
1252 : : * across HW reta table.
1253 : : */
1254 : 0 : reta = nix->reta[rss_grp_idx];
1255 : :
1256 [ # # ]: 0 : if (rss->queue_num > nix->reta_sz) {
1257 : 0 : plt_err("too many queues for RSS context");
1258 : 0 : return -ENOTSUP;
1259 : : }
1260 : :
1261 [ # # ]: 0 : for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
1262 : 0 : memcpy(reta + i * rss->queue_num, rss->queue,
1263 : 0 : sizeof(uint16_t) * rss->queue_num);
1264 : :
1265 : 0 : rem = nix->reta_sz % rss->queue_num;
1266 [ # # ]: 0 : if (rem)
1267 : 0 : memcpy(&reta[i * rss->queue_num], rss->queue, rem * sizeof(uint16_t));
1268 : :
1269 : 0 : rc = nix_rss_reta_pffunc_set(roc_nix, *rss_grp, reta, rss_repte_pf_func);
1270 [ # # ]: 0 : if (rc) {
1271 : 0 : plt_err("Failed to init rss table rc = %d", rc);
1272 : 0 : return rc;
1273 : : }
1274 : :
1275 : 0 : flowkey_cfg = roc_npc->flowkey_cfg_state;
1276 : :
1277 : 0 : rc = nix_rss_flowkey_pffunc_set(roc_nix, &flowkey_algx, flowkey_cfg, *rss_grp, mcam_id,
1278 : : rss_repte_pf_func);
1279 [ # # ]: 0 : if (rc) {
1280 : 0 : plt_err("Failed to set rss hash function rc = %d", rc);
1281 : 0 : return rc;
1282 : : }
1283 : :
1284 : 0 : *alg_idx = flowkey_algx;
1285 : :
1286 : 0 : plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
1287 : :
1288 : 0 : return 0;
1289 : : }
1290 : :
1291 : : int
1292 : 0 : npc_rss_action_program(struct roc_npc *roc_npc,
1293 : : const struct roc_npc_action actions[],
1294 : : struct roc_npc_flow *flow)
1295 : : {
1296 : : const struct roc_npc_action_rss *rss;
1297 : : struct roc_npc *npc = roc_npc;
1298 : : uint32_t rss_grp;
1299 : : uint8_t alg_idx;
1300 : : int rc;
1301 : :
1302 [ # # ]: 0 : if (flow->has_rep) {
1303 : 0 : npc = roc_npc->rep_npc;
1304 : 0 : npc->flowkey_cfg_state = roc_npc->flowkey_cfg_state;
1305 : : }
1306 : :
1307 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1308 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
1309 : 0 : rss = (const struct roc_npc_action_rss *)actions->conf;
1310 : 0 : rc = npc_rss_action_configure(npc, rss, &alg_idx, &rss_grp, flow->mcam_id,
1311 : 0 : actions->rss_repte_pf_func);
1312 [ # # ]: 0 : if (rc)
1313 : : return rc;
1314 : :
1315 : 0 : flow->npc_action &= (~(0xfULL));
1316 : 0 : flow->npc_action |= NIX_RX_ACTIONOP_RSS;
1317 : 0 : flow->npc_action |=
1318 : 0 : ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
1319 : 0 : << NPC_RSS_ACT_ALG_OFFSET) |
1320 : 0 : ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
1321 : 0 : << NPC_RSS_ACT_GRP_OFFSET);
1322 : 0 : break;
1323 : : }
1324 : : }
1325 : : return 0;
1326 : : }
1327 : :
1328 : : static int
1329 : 0 : npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1330 : : {
1331 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1332 : : struct nix_vtag_config *vtag_cfg;
1333 : : struct nix_vtag_config_rsp *rsp;
1334 : : struct mbox *mbox, *ombox;
1335 : : struct nix *nix;
1336 : : int rc = 0;
1337 : :
1338 : : union {
1339 : : uint64_t reg;
1340 : : struct nix_tx_vtag_action_s act;
1341 : : } tx_vtag_action;
1342 : :
1343 : : nix = roc_nix_to_nix_priv(roc_nix);
1344 : 0 : ombox = (&nix->dev)->mbox;
1345 [ # # ]: 0 : if (flow->has_rep)
1346 : 0 : ombox = flow->rep_mbox;
1347 : : mbox = mbox_get(ombox);
1348 : :
1349 : 0 : tx_vtag_action.reg = flow->vtag_action;
1350 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1351 : :
1352 [ # # ]: 0 : if (vtag_cfg == NULL) {
1353 : : rc = -ENOSPC;
1354 : 0 : goto exit;
1355 : : }
1356 : :
1357 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1358 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1359 : 0 : vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
1360 : 0 : vtag_cfg->tx.free_vtag0 = true;
1361 : :
1362 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1363 : 0 : vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
1364 : 0 : vtag_cfg->tx.free_vtag1 = true;
1365 : : }
1366 : :
1367 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1368 [ # # ]: 0 : if (rc)
1369 : 0 : goto exit;
1370 : :
1371 : : rc = 0;
1372 : 0 : exit:
1373 : : mbox_put(mbox);
1374 : 0 : return rc;
1375 : : }
1376 : :
1377 : : static int
1378 : 0 : npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
1379 : : struct roc_npc_flow *flow,
1380 : : struct npc_action_vtag_info *vlan_info,
1381 : : int *parsed_cnt)
1382 : : {
1383 : : bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
1384 : : int count = 0;
1385 : :
1386 : 0 : *parsed_cnt = 0;
1387 : :
1388 : : /* This function parses parameters of one VLAN. When a parameter is
1389 : : * found repeated, it treats it as the end of first VLAN's parameters
1390 : : * and returns. The caller calls again to parse the parameters of the
1391 : : * second VLAN.
1392 : : */
1393 : :
1394 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
1395 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
1396 [ # # ]: 0 : if (vlan_id_found)
1397 : : return 0;
1398 : :
1399 : 0 : const struct roc_npc_action_of_set_vlan_vid *vtag =
1400 : : (const struct roc_npc_action_of_set_vlan_vid *)
1401 : : actions->conf;
1402 : :
1403 [ # # ]: 0 : vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
1404 : :
1405 [ # # ]: 0 : if (vlan_info->vlan_id > 0xfff) {
1406 : 0 : plt_err("Invalid vlan_id for set vlan action");
1407 : 0 : return -EINVAL;
1408 : : }
1409 : :
1410 : 0 : flow->vtag_insert_enabled = true;
1411 : 0 : (*parsed_cnt)++;
1412 : : vlan_id_found = true;
1413 [ # # ]: 0 : } else if (actions->type ==
1414 : : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
1415 [ # # ]: 0 : if (ethtype_found)
1416 : : return 0;
1417 : :
1418 : 0 : const struct roc_npc_action_of_push_vlan *ethtype =
1419 : : (const struct roc_npc_action_of_push_vlan *)
1420 : : actions->conf;
1421 : 0 : vlan_info->vlan_ethtype =
1422 [ # # ]: 0 : plt_be_to_cpu_16(ethtype->ethertype);
1423 [ # # ]: 0 : if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
1424 : : vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
1425 : 0 : plt_err("Invalid ethtype specified for push"
1426 : : " vlan action");
1427 : 0 : return -EINVAL;
1428 : : }
1429 : 0 : flow->vtag_insert_enabled = true;
1430 : 0 : (*parsed_cnt)++;
1431 : : ethtype_found = true;
1432 [ # # ]: 0 : } else if (actions->type ==
1433 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1434 [ # # ]: 0 : if (pcp_found)
1435 : : return 0;
1436 : 0 : const struct roc_npc_action_of_set_vlan_pcp *pcp =
1437 : : (const struct roc_npc_action_of_set_vlan_pcp *)
1438 : : actions->conf;
1439 : 0 : vlan_info->vlan_pcp = pcp->vlan_pcp;
1440 [ # # ]: 0 : if (vlan_info->vlan_pcp > 0x7) {
1441 : 0 : plt_err("Invalid PCP value for pcp action");
1442 : 0 : return -EINVAL;
1443 : : }
1444 : 0 : flow->vtag_insert_enabled = true;
1445 : 0 : (*parsed_cnt)++;
1446 : : pcp_found = true;
1447 : : } else {
1448 : : return 0;
1449 : : }
1450 : : }
1451 : :
1452 : : return 0;
1453 : : }
1454 : :
1455 : : static int
1456 : 0 : npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
1457 : : struct npc_action_vtag_info *vlan_info)
1458 : : {
1459 : : struct nix_vtag_config *vtag_cfg;
1460 : : struct nix_vtag_config_rsp *rsp;
1461 : : int rc = 0;
1462 : :
1463 : : union {
1464 : : uint64_t reg;
1465 : : struct nix_tx_vtag_action_s act;
1466 : : } tx_vtag_action;
1467 : :
1468 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1469 : :
1470 [ # # ]: 0 : if (vtag_cfg == NULL) {
1471 : : rc = -ENOSPC;
1472 : 0 : goto exit;
1473 : : }
1474 : :
1475 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1476 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1477 : 0 : vtag_cfg->tx.vtag0 =
1478 : 0 : (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
1479 : 0 : (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1480 : :
1481 : 0 : vtag_cfg->tx.cfg_vtag0 = 1;
1482 : :
1483 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1484 : 0 : vtag_cfg->tx.vtag1 =
1485 : 0 : (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
1486 : 0 : (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1487 : :
1488 : 0 : vtag_cfg->tx.cfg_vtag1 = 1;
1489 : : }
1490 : :
1491 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1492 [ # # ]: 0 : if (rc)
1493 : 0 : goto exit;
1494 : :
1495 [ # # ]: 0 : if (rsp->vtag0_idx < 0 ||
1496 [ # # # # ]: 0 : ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1497 : 0 : plt_err("Failed to config TX VTAG action");
1498 : : rc = -EINVAL;
1499 : 0 : goto exit;
1500 : : }
1501 : :
1502 : 0 : tx_vtag_action.reg = 0;
1503 : 0 : tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1504 : : tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1505 : 0 : tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1506 : 0 : tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1507 : :
1508 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1509 : 0 : tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1510 : : tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1511 : 0 : tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1512 : : /* NIX_TX_VTAG_ACTION_S
1513 : : * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1514 : : * offset accordingly. Thus, if the two offsets are equal in
1515 : : * the structure, hardware inserts Vtag 1 immediately after
1516 : : * Vtag 0 in the packet.
1517 : : */
1518 : 0 : tx_vtag_action.act.vtag1_relptr =
1519 : : NIX_TX_VTAGACTION_VTAG0_RELPTR;
1520 : : }
1521 : :
1522 : 0 : flow->vtag_action = tx_vtag_action.reg;
1523 : :
1524 : : rc = 0;
1525 : 0 : exit:
1526 : : mbox_put(mbox);
1527 : 0 : return rc;
1528 : : }
1529 : :
1530 : : static int
1531 : 0 : npc_vtag_strip_action_configure(struct mbox *mbox,
1532 : : const struct roc_npc_action actions[],
1533 : : struct roc_npc_flow *flow, int *strip_cnt)
1534 : : {
1535 : : struct nix_vtag_config *vtag_cfg;
1536 : : uint64_t rx_vtag_action = 0;
1537 : : int count = 0, rc = 0;
1538 : :
1539 : 0 : *strip_cnt = 0;
1540 : :
1541 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1542 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1543 : 0 : (*strip_cnt)++;
1544 : : }
1545 : :
1546 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1547 : :
1548 [ # # ]: 0 : if (vtag_cfg == NULL) {
1549 : : rc = -ENOSPC;
1550 : 0 : goto exit;
1551 : : }
1552 : :
1553 : 0 : vtag_cfg->cfg_type = VTAG_RX;
1554 : 0 : vtag_cfg->rx.strip_vtag = 1;
1555 : : /* Always capture */
1556 : 0 : vtag_cfg->rx.capture_vtag = 1;
1557 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1558 : 0 : vtag_cfg->rx.vtag_type = 0;
1559 : :
1560 : 0 : rc = mbox_process(mbox);
1561 [ # # ]: 0 : if (rc)
1562 : 0 : goto exit;
1563 : :
1564 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1565 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1566 : : rx_vtag_action |= ((uint64_t)NIX_RX_VTAG_TYPE6 << 12);
1567 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1568 : :
1569 [ # # ]: 0 : if (*strip_cnt == 2) {
1570 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1571 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1572 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1573 : : }
1574 : 0 : flow->vtag_action = rx_vtag_action;
1575 : :
1576 : : rc = 0;
1577 : 0 : exit:
1578 : : mbox_put(mbox);
1579 : 0 : return rc;
1580 : : }
1581 : :
1582 : : static int
1583 : 0 : npc_vtag_action_program(struct roc_npc *roc_npc,
1584 : : const struct roc_npc_action actions[],
1585 : : struct roc_npc_flow *flow)
1586 : : {
1587 : : bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1588 : : const struct roc_npc_action *insert_actions;
1589 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1590 : : struct npc_action_vtag_info vlan_info[2];
1591 : 0 : int parsed_cnt = 0, strip_cnt = 0;
1592 : : int tot_vlan_params = 0;
1593 : : struct mbox *mbox;
1594 : : struct nix *nix;
1595 : : int i, rc;
1596 : :
1597 : : nix = roc_nix_to_nix_priv(roc_nix);
1598 : 0 : mbox = (&nix->dev)->mbox;
1599 [ # # ]: 0 : if (flow->has_rep)
1600 : 0 : mbox = flow->rep_mbox;
1601 : :
1602 : : memset(vlan_info, 0, sizeof(vlan_info));
1603 : :
1604 : 0 : flow->vtag_insert_enabled = false;
1605 : :
1606 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1607 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1608 [ # # ]: 0 : if (vlan_strip_parsed) {
1609 : 0 : plt_err("Incorrect VLAN strip actions");
1610 : 0 : return -EINVAL;
1611 : : }
1612 : 0 : rc = npc_vtag_strip_action_configure(mbox, actions,
1613 : : flow, &strip_cnt);
1614 [ # # ]: 0 : if (rc)
1615 : 0 : return rc;
1616 : :
1617 : 0 : plt_npc_dbg("VLAN strip action, strip_cnt %d", strip_cnt);
1618 [ # # ]: 0 : if (strip_cnt == 2)
1619 : 0 : actions++;
1620 : :
1621 : : vlan_strip_parsed = true;
1622 [ # # ]: 0 : } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1623 : : actions->type ==
1624 [ # # ]: 0 : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1625 : : actions->type ==
1626 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1627 [ # # ]: 0 : if (vlan_insert_parsed) {
1628 : 0 : plt_err("Incorrect VLAN insert actions");
1629 : 0 : return -EINVAL;
1630 : : }
1631 : :
1632 : : insert_actions = actions;
1633 : :
1634 [ # # ]: 0 : for (i = 0; i < 2; i++) {
1635 : 0 : rc = npc_vtag_insert_action_parse(
1636 : : insert_actions, flow, &vlan_info[i],
1637 : : &parsed_cnt);
1638 : :
1639 [ # # ]: 0 : if (rc)
1640 : 0 : return rc;
1641 : :
1642 [ # # ]: 0 : if (parsed_cnt) {
1643 : 0 : insert_actions += parsed_cnt;
1644 : 0 : tot_vlan_params += parsed_cnt;
1645 : 0 : flow->vtag_insert_count++;
1646 : : }
1647 : : }
1648 : 0 : actions += tot_vlan_params - 1;
1649 : : vlan_insert_parsed = true;
1650 : : }
1651 : : }
1652 : :
1653 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1654 : 0 : rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1655 : :
1656 [ # # ]: 0 : if (rc)
1657 : 0 : return rc;
1658 : : }
1659 : : return 0;
1660 : : }
1661 : :
1662 : : static int
1663 : 0 : npc_inline_dev_ipsec_action_free(struct npc *npc, struct roc_npc_flow *flow)
1664 : : {
1665 : : struct nix_inl_dev *inl_dev;
1666 : : struct idev_cfg *idev;
1667 : : int rc;
1668 : :
1669 : : PLT_SET_USED(npc);
1670 : :
1671 : 0 : idev = idev_get_cfg();
1672 [ # # ]: 0 : if (!idev)
1673 : : return 1;
1674 : :
1675 : 0 : inl_dev = idev->nix_inl_dev;
1676 : :
1677 [ # # # # : 0 : if (flow->nix_intf == NIX_INTF_RX && inl_dev && inl_dev->ipsec_index &&
# # # # ]
1678 [ # # ]: 0 : roc_npc_action_is_rx_inline(flow->npc_action)) {
1679 : 0 : inl_dev->curr_ipsec_idx--;
1680 : 0 : inl_dev->ipsec_index[inl_dev->curr_ipsec_idx] = flow->mcam_id;
1681 : 0 : flow->enable = 0;
1682 [ # # ]: 0 : if (flow->use_ctr) {
1683 : 0 : rc = npc_mcam_clear_counter(inl_dev->dev.mbox, flow->ctr_id);
1684 [ # # ]: 0 : if (rc)
1685 : : return rc;
1686 : :
1687 : 0 : rc = npc_mcam_free_counter(inl_dev->dev.mbox, flow->ctr_id);
1688 [ # # ]: 0 : if (rc)
1689 : : return rc;
1690 : : }
1691 : 0 : return npc_mcam_write_entry(inl_dev->dev.mbox, flow);
1692 : : }
1693 : :
1694 : : return 1;
1695 : : }
1696 : :
1697 : : void
1698 : 0 : roc_npc_sdp_channel_get(struct roc_npc *roc_npc, uint16_t *chan_base, uint16_t *chan_mask)
1699 : : {
1700 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1701 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1702 : : uint16_t num_chan, range, num_bits = 0;
1703 : : uint16_t mask = 0;
1704 : :
1705 : 0 : *chan_base = nix->rx_chan_base;
1706 : 0 : num_chan = nix->rx_chan_cnt - 1;
1707 [ # # ]: 0 : if (num_chan) {
1708 : 0 : range = *chan_base ^ (*chan_base + num_chan);
1709 : 0 : num_bits = (sizeof(uint32_t) * 8) - plt_clz32(range) - 1;
1710 : : /* Set mask for (15 - numbits) MSB bits */
1711 : 0 : *chan_mask = (uint16_t)~GENMASK(num_bits, 0);
1712 : 0 : *chan_mask &= 0xFFF;
1713 : : } else {
1714 : 0 : *chan_mask = (uint16_t)GENMASK(11, 0);
1715 : : }
1716 : :
1717 : 0 : mask = (uint16_t)GENMASK(num_bits, 0);
1718 [ # # ]: 0 : if (mask > num_chan + 1)
1719 : 0 : plt_warn(
1720 : : "npc: SDP channel base:%x, channel count:%x. channel mask:%x covers more than channel count",
1721 : : *chan_base, nix->rx_chan_cnt, *chan_mask);
1722 : 0 : }
1723 : :
1724 : : struct roc_npc_flow *
1725 : 0 : roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1726 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1727 : : uint16_t dst_pf_func, uint64_t npc_default_action, int *errcode)
1728 : : {
1729 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1730 : 0 : uint16_t sdp_chan_base = 0, sdp_chan_mask = 0;
1731 : : struct roc_npc_flow *flow, *flow_iter;
1732 : : struct npc_parse_state parse_state;
1733 : : struct npc_flow_list *list;
1734 : : int rc;
1735 : :
1736 : 0 : npc->channel = roc_npc->channel;
1737 : 0 : npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1738 [ # # ]: 0 : if (npc->is_sdp_link) {
1739 [ # # ]: 0 : if (roc_npc->is_sdp_mask_set) {
1740 : 0 : npc->sdp_channel = roc_npc->sdp_channel;
1741 : 0 : npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1742 : : } else {
1743 : 0 : roc_npc_sdp_channel_get(roc_npc, &sdp_chan_base, &sdp_chan_mask);
1744 : 0 : npc->sdp_channel = sdp_chan_base;
1745 : 0 : npc->sdp_channel_mask = sdp_chan_mask;
1746 : : }
1747 : : }
1748 : :
1749 : 0 : flow = plt_zmalloc(sizeof(*flow), 0);
1750 [ # # ]: 0 : if (flow == NULL) {
1751 : 0 : *errcode = NPC_ERR_NO_MEM;
1752 : 0 : return NULL;
1753 : : }
1754 : : memset(flow, 0, sizeof(*flow));
1755 : : memset(&parse_state, 0, sizeof(parse_state));
1756 : :
1757 : 0 : flow->port_id = -1;
1758 [ # # ]: 0 : if (roc_npc->rep_npc) {
1759 : 0 : flow->rep_channel =
1760 [ # # ]: 0 : (roc_npc->rep_rx_channel == 0) ?
1761 : 0 : roc_nix_to_nix_priv(roc_npc->rep_npc->roc_nix)->rx_chan_base :
1762 : : roc_npc->rep_rx_channel;
1763 : 0 : flow->rep_pf_func = roc_npc->rep_pf_func;
1764 : 0 : flow->rep_act_pf_func = roc_npc->rep_act_pf_func;
1765 : 0 : flow->rep_act_rep = roc_npc->rep_act_rep;
1766 : 0 : flow->rep_mbox = roc_npc_to_npc_priv(roc_npc->rep_npc)->mbox;
1767 : 0 : flow->has_rep = true;
1768 : 0 : flow->is_rep_vf = !roc_nix_is_pf(roc_npc->rep_npc->roc_nix);
1769 : 0 : flow->port_id = roc_npc->rep_port_id;
1770 : 0 : flow->rep_npc = roc_npc_to_npc_priv(roc_npc->rep_npc);
1771 : 0 : roc_npc->rep_act_rep = false;
1772 : 0 : roc_npc->rep_act_pf_func = 0;
1773 : 0 : roc_npc->rep_rx_channel = 0;
1774 : : }
1775 : :
1776 : 0 : parse_state.dst_pf_func = dst_pf_func;
1777 : 0 : parse_state.npc_default_action = npc_default_action;
1778 : :
1779 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1780 [ # # ]: 0 : if (rc != 0) {
1781 : 0 : *errcode = rc;
1782 : 0 : goto err_exit;
1783 : : }
1784 : :
1785 : 0 : rc = npc_vtag_action_program(roc_npc, actions, flow);
1786 [ # # ]: 0 : if (rc != 0) {
1787 : 0 : *errcode = rc;
1788 : 0 : goto err_exit;
1789 : : }
1790 : :
1791 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1792 : :
1793 : 0 : rc = npc_program_mcam(npc, &parse_state, 1);
1794 [ # # ]: 0 : if (rc != 0) {
1795 : 0 : *errcode = rc;
1796 : 0 : goto err_exit;
1797 : : }
1798 : :
1799 : : /* If Egress mirror requested then enable TL3_TL2_LINK_CFG */
1800 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1801 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1802 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1803 : 0 : flow->mcast_pf_funcs[1], true);
1804 : : else
1805 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1806 : : flow->mcast_pf_funcs[0], true);
1807 [ # # ]: 0 : if (rc) {
1808 : 0 : plt_err("Adding egress mirror failed");
1809 : 0 : *errcode = rc;
1810 : 0 : goto err_exit;
1811 : : }
1812 : : }
1813 : :
1814 : 0 : rc = npc_rss_action_program(roc_npc, actions, flow);
1815 [ # # ]: 0 : if (rc != 0) {
1816 : 0 : *errcode = rc;
1817 : 0 : goto set_rss_failed;
1818 : : }
1819 : 0 : roc_npc->rep_npc = NULL;
1820 : 0 : roc_npc->rep_act_pf_func = 0;
1821 : :
1822 [ # # ]: 0 : if (flow->has_age_action)
1823 : 0 : npc_age_flow_list_entry_add(roc_npc, flow);
1824 : :
1825 [ # # ]: 0 : if (flow->use_pre_alloc == 0)
1826 : 0 : list = &npc->flow_list[flow->priority];
1827 : : else
1828 : 0 : list = &npc->ipsec_list;
1829 : : /* List in ascending order of mcam entries */
1830 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1831 [ # # ]: 0 : if (flow_iter->mcam_id > flow->mcam_id) {
1832 : 0 : TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1833 : 0 : roc_npc->rep_npc = NULL;
1834 : 0 : return flow;
1835 : : }
1836 : : }
1837 : 0 : TAILQ_INSERT_TAIL(list, flow, next);
1838 : :
1839 : 0 : return flow;
1840 : :
1841 : : set_rss_failed:
1842 : 0 : roc_npc->rep_npc = NULL;
1843 : 0 : roc_npc->rep_act_pf_func = 0;
1844 [ # # ]: 0 : if (flow->use_pre_alloc == 0) {
1845 : 0 : rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
1846 [ # # ]: 0 : if (rc != 0) {
1847 : 0 : *errcode = rc;
1848 : 0 : plt_free(flow);
1849 : 0 : return NULL;
1850 : : }
1851 : : } else {
1852 : 0 : npc_inline_dev_ipsec_action_free(npc, flow);
1853 : : }
1854 : 0 : err_exit:
1855 : 0 : roc_npc->rep_npc = NULL;
1856 : 0 : roc_npc->rep_act_pf_func = 0;
1857 : 0 : plt_free(flow);
1858 : 0 : return NULL;
1859 : : }
1860 : :
1861 : : int
1862 : 0 : npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1863 : : {
1864 : : struct npc *lnpc = npc;
1865 : : uint32_t rss_grp;
1866 : :
1867 [ # # ]: 0 : if (flow->has_rep)
1868 : 0 : lnpc = flow->rep_npc;
1869 : :
1870 [ # # ]: 0 : if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1871 : 0 : rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1872 : : NPC_RSS_ACT_GRP_MASK;
1873 [ # # # # ]: 0 : if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1874 : : return -EINVAL;
1875 : :
1876 : 0 : plt_bitmap_clear(lnpc->rss_grp_entries, rss_grp);
1877 : : }
1878 : :
1879 : : return 0;
1880 : : }
1881 : :
1882 : : static int
1883 : 0 : roc_npc_delete_spi_to_sa_action(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1884 : : {
1885 : : struct nix_spi_to_sa_delete_req *req;
1886 : : struct nix_inl_dev *inl_dev;
1887 : : struct idev_cfg *idev;
1888 : : struct mbox *mbox;
1889 : :
1890 : : PLT_SET_USED(roc_npc);
1891 : :
1892 [ # # # # ]: 0 : if (!flow->spi_to_sa_info.has_action || flow->spi_to_sa_info.duplicate)
1893 : : return 0;
1894 : :
1895 : 0 : idev = idev_get_cfg();
1896 [ # # ]: 0 : if (!idev)
1897 : : return -1;
1898 : :
1899 : 0 : inl_dev = idev->nix_inl_dev;
1900 : 0 : mbox = inl_dev->dev.mbox;
1901 : 0 : req = mbox_alloc_msg_nix_spi_to_sa_delete(mbox);
1902 [ # # ]: 0 : if (req == NULL)
1903 : : return -ENOSPC;
1904 : 0 : req->hash_index = flow->spi_to_sa_info.hash_index;
1905 : 0 : req->way = flow->spi_to_sa_info.way;
1906 : 0 : return mbox_process_msg(mbox, NULL);
1907 : : }
1908 : :
1909 : : int
1910 : 0 : roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1911 : : {
1912 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1913 : : int rc;
1914 : :
1915 : 0 : rc = roc_npc_delete_spi_to_sa_action(roc_npc, flow);
1916 [ # # ]: 0 : if (rc)
1917 : : return rc;
1918 : :
1919 [ # # ]: 0 : if (npc_inline_dev_ipsec_action_free(npc, flow) == 0) {
1920 [ # # ]: 0 : TAILQ_REMOVE(&npc->ipsec_list, flow, next);
1921 : 0 : goto done;
1922 : : }
1923 : :
1924 : 0 : rc = npc_rss_group_free(npc, flow);
1925 [ # # ]: 0 : if (rc != 0) {
1926 : 0 : plt_err("Failed to free rss action rc = %d", rc);
1927 : 0 : return rc;
1928 : : }
1929 : :
1930 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1931 : 0 : rc = npc_vtag_cfg_delete(roc_npc, flow);
1932 [ # # ]: 0 : if (rc != 0)
1933 : : return rc;
1934 : : }
1935 : :
1936 : : /* Disable egress mirror rule */
1937 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1938 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1939 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1940 : 0 : flow->mcast_pf_funcs[1], false);
1941 : : else
1942 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1943 : : flow->mcast_pf_funcs[0], false);
1944 [ # # ]: 0 : if (rc)
1945 : 0 : plt_err("Failed to remove egress mirror rule");
1946 : : }
1947 [ # # ]: 0 : if (flow->is_sampling_rule)
1948 : 0 : roc_nix_mcast_list_free(npc->mbox, flow->mcast_grp_index);
1949 : :
1950 : 0 : rc = roc_npc_mcam_free(roc_npc, flow);
1951 [ # # ]: 0 : if (rc != 0)
1952 : : return rc;
1953 : :
1954 [ # # ]: 0 : TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1955 : :
1956 : 0 : npc_delete_prio_list_entry(npc, flow);
1957 : :
1958 [ # # ]: 0 : if (flow->has_age_action)
1959 : 0 : npc_age_flow_list_entry_delete(roc_npc, flow);
1960 : :
1961 [ # # ]: 0 : if (roc_npc->flow_age.age_flow_refcnt == 0)
1962 : 0 : npc_aging_ctrl_thread_destroy(roc_npc);
1963 : :
1964 : 0 : done:
1965 : 0 : plt_free(flow);
1966 : 0 : return 0;
1967 : : }
1968 : :
1969 : : void
1970 : 0 : roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc, int rep_port_id)
1971 : : {
1972 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1973 : : struct roc_npc_flow *flow_iter;
1974 : : struct npc_flow_list *list;
1975 : : uint32_t max_prio, i;
1976 : :
1977 : 0 : max_prio = npc->flow_max_priority;
1978 : :
1979 [ # # ]: 0 : for (i = 0; i < max_prio; i++) {
1980 : 0 : list = &npc->flow_list[i];
1981 : :
1982 : : /* List in ascending order of mcam entries */
1983 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1984 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1985 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1986 : : }
1987 : : }
1988 : :
1989 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, &npc->ipsec_list, next) {
1990 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1991 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1992 : : }
1993 : 0 : }
1994 : :
1995 : : int
1996 : 0 : roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1997 : : {
1998 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1999 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
2000 : : int idx, rc;
2001 : :
2002 [ # # ]: 0 : if (roc_nix_is_pf(roc_npc->roc_nix)) {
2003 : : rc = 0;
2004 : 0 : goto exit;
2005 : : }
2006 : :
2007 [ # # ]: 0 : if (roc_model_is_cn20k()) {
2008 : : struct npc_cn20k_mcam_read_base_rule_rsp *base_rule_rsp;
2009 : : struct cn20k_mcam_entry *base_entry;
2010 : :
2011 : 0 : (void)mbox_alloc_msg_npc_cn20k_read_base_steer_rule(mbox);
2012 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
2013 [ # # ]: 0 : if (rc) {
2014 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
2015 : 0 : goto exit;
2016 : : }
2017 : 0 : base_entry = &base_rule_rsp->entry;
2018 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
2019 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
2020 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
2021 : : }
2022 : :
2023 : : } else {
2024 : : struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
2025 : : struct mcam_entry *base_entry;
2026 : :
2027 : 0 : (void)mbox_alloc_msg_npc_read_base_steer_rule(mbox);
2028 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
2029 [ # # ]: 0 : if (rc) {
2030 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
2031 : 0 : goto exit;
2032 : : }
2033 : 0 : base_entry = &base_rule_rsp->entry_data;
2034 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
2035 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
2036 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
2037 : : }
2038 : : }
2039 : : rc = 0;
2040 : 0 : exit:
2041 : : mbox_put(mbox);
2042 : 0 : return rc;
2043 : : }
2044 : :
2045 : : int
2046 : 0 : roc_npc_mcam_default_rule_action_get(struct roc_npc *roc_npc, uint64_t *action)
2047 : : {
2048 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
2049 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
2050 : : int rc;
2051 : :
2052 : : struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
2053 : : struct mcam_entry *base_entry;
2054 : :
2055 : 0 : (void)mbox_alloc_msg_npc_read_default_rule(mbox);
2056 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
2057 [ # # ]: 0 : if (rc) {
2058 : 0 : plt_err("Failed to fetch default MCAM entry");
2059 : 0 : goto exit;
2060 : : }
2061 : 0 : base_entry = &base_rule_rsp->entry_data;
2062 : :
2063 : 0 : *action = base_entry->action;
2064 : 0 : exit:
2065 : : mbox_put(mbox);
2066 : 0 : return rc;
2067 : : }
|