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