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