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