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