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