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 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
572 : : const struct roc_npc_action_mark *act_mark;
573 : : const struct roc_npc_action_meter *act_mtr;
574 : : const struct roc_npc_action_queue *act_q;
575 : : const struct roc_npc_action_vf *vf_act;
576 : : bool vlan_insert_action = false;
577 : 0 : uint8_t has_spi_to_sa_act = 0;
578 : : int sel_act, req_act = 0;
579 : : uint16_t pf_func, vf_id;
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 [ # # ]: 0 : if (roc_model_is_cn20k()) {
889 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_CPT;
890 : 0 : flow->npc_action |= (uint64_t)rq << 20;
891 : 0 : flow->npc_action2 =
892 : 0 : roc_nix_inl_inb_ipsec_profile_id_get(roc_nix, true) << 8;
893 : : } else {
894 : : flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
895 : 0 : flow->npc_action |= (uint64_t)rq << 20;
896 : : }
897 [ # # ]: 0 : } else if (req_act & (ROC_NPC_ACTION_TYPE_FLAG | ROC_NPC_ACTION_TYPE_MARK)) {
898 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
899 [ # # ]: 0 : } else if (req_act & ROC_NPC_ACTION_TYPE_COUNT) {
900 : : /* Keep ROC_NPC_ACTION_TYPE_COUNT_ACT always at the end
901 : : * This is default action, when user specify only
902 : : * COUNT ACTION
903 : : */
904 : 0 : flow->npc_action = NIX_RX_ACTIONOP_UCAST;
905 : : } else {
906 : : /* Should never reach here */
907 : : errcode = NPC_ERR_ACTION_NOTSUP;
908 : 0 : goto err_exit;
909 : : }
910 : :
911 [ # # ]: 0 : if (req_act & ROC_NPC_ACTION_TYPE_SAMPLE)
912 : 0 : flow->npc_action = NIX_RX_ACTIONOP_MCAST;
913 : :
914 [ # # ]: 0 : if (mark)
915 : 0 : flow->npc_action |= (uint64_t)mark << 40;
916 : :
917 : : /* Ideally AF must ensure that correct pf_func is set */
918 : 0 : flow->npc_action |= (uint64_t)pf_func << 4;
919 : :
920 : : done:
921 : : return 0;
922 : :
923 : : err_exit:
924 : : return errcode;
925 : : }
926 : :
927 : : typedef int (*npc_parse_stage_func_t)(struct npc_parse_state *pst);
928 : :
929 : : static int
930 : 0 : npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
931 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
932 : : {
933 : 0 : npc_parse_stage_func_t parse_stage_funcs[] = {
934 : : npc_parse_meta_items, npc_parse_port_representor_id,
935 : : npc_parse_mark_item, npc_parse_pre_l2,
936 : : npc_parse_cpt_hdr, npc_parse_higig2_hdr,
937 : : npc_parse_tx_queue, npc_parse_la,
938 : : npc_parse_lb, npc_parse_lc,
939 : : npc_parse_ld, npc_parse_le,
940 : : npc_parse_lf, npc_parse_lg,
941 : : npc_parse_lh,
942 : : };
943 : : uint8_t layer = 0;
944 : : int key_offset;
945 : : int rc;
946 : :
947 [ # # ]: 0 : if (pattern == NULL)
948 : : return NPC_ERR_PARAM;
949 : :
950 : 0 : pst->npc = npc;
951 : 0 : pst->flow = flow;
952 : 0 : pst->nix_intf = flow->nix_intf;
953 : :
954 : : /* Use integral byte offset */
955 : : key_offset = pst->npc->keyx_len[flow->nix_intf];
956 : : key_offset = (key_offset + 7) / 8;
957 : :
958 : : /* Location where LDATA would begin */
959 : 0 : pst->mcam_data = (uint8_t *)flow->mcam_data;
960 : 0 : pst->mcam_mask = (uint8_t *)flow->mcam_mask;
961 : :
962 [ # # # # ]: 0 : while (pattern->type != ROC_NPC_ITEM_TYPE_END &&
963 : : layer < PLT_DIM(parse_stage_funcs)) {
964 : : /* Skip place-holders */
965 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
966 : :
967 : 0 : pst->pattern = pattern;
968 : 0 : rc = parse_stage_funcs[layer](pst);
969 [ # # ]: 0 : if (rc != 0)
970 : 0 : return rc;
971 : :
972 : 0 : layer++;
973 : :
974 : : /*
975 : : * Parse stage function sets pst->pattern to
976 : : * 1 past the last item it consumed.
977 : : */
978 : 0 : pattern = pst->pattern;
979 : :
980 [ # # ]: 0 : if (pst->terminate)
981 : : break;
982 : : }
983 : :
984 : : /* Skip trailing place-holders */
985 : 0 : pattern = npc_parse_skip_void_and_any_items(pattern);
986 : :
987 : : /* Are there more items than what we can handle? */
988 [ # # ]: 0 : if (pattern->type != ROC_NPC_ITEM_TYPE_END)
989 : 0 : return NPC_ERR_PATTERN_NOTSUP;
990 : :
991 : : return 0;
992 : : }
993 : :
994 : : static int
995 : : npc_parse_attr(struct npc *npc, const struct roc_npc_attr *attr,
996 : : struct roc_npc_flow *flow)
997 : : {
998 : 0 : if (attr == NULL)
999 : : return NPC_ERR_PARAM;
1000 [ # # ]: 0 : else if (attr->priority >= npc->flow_max_priority)
1001 : : return NPC_ERR_PARAM;
1002 [ # # ]: 0 : else if ((!attr->egress && !attr->ingress) ||
1003 : : (attr->egress && attr->ingress))
1004 : : return NPC_ERR_PARAM;
1005 : :
1006 [ # # ]: 0 : if (attr->ingress)
1007 : 0 : flow->nix_intf = ROC_NPC_INTF_RX;
1008 : : else
1009 : 0 : flow->nix_intf = ROC_NPC_INTF_TX;
1010 : :
1011 : 0 : flow->priority = attr->priority;
1012 : : return 0;
1013 : : }
1014 : :
1015 : : static int
1016 [ # # ]: 0 : npc_parse_rule(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1017 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1018 : : struct roc_npc_flow *flow, struct npc_parse_state *pst)
1019 : : {
1020 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1021 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1022 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1023 : : int err;
1024 : :
1025 [ # # ]: 0 : pst->nb_tx_queues = nix->nb_tx_queues;
1026 : :
1027 : : /* Check attr */
1028 : : err = npc_parse_attr(npc, attr, flow);
1029 : : if (err)
1030 : : return err;
1031 : :
1032 : : /* Check pattern */
1033 : 0 : err = npc_parse_pattern(npc, pattern, flow, pst);
1034 [ # # ]: 0 : if (err)
1035 : : return err;
1036 : :
1037 : : /* Check action */
1038 : 0 : err = npc_parse_actions(roc_npc, attr, actions, flow, pst->dst_pf_func);
1039 [ # # ]: 0 : if (err)
1040 : 0 : return err;
1041 : : return 0;
1042 : : }
1043 : :
1044 : : int
1045 : 0 : roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1046 : : const struct roc_npc_item_info pattern[],
1047 : : const struct roc_npc_action actions[],
1048 : : struct roc_npc_flow *flow)
1049 : : {
1050 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1051 : 0 : struct npc_parse_state parse_state = {0};
1052 : : int rc;
1053 : :
1054 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1055 [ # # ]: 0 : if (rc)
1056 : : return rc;
1057 : :
1058 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1059 : :
1060 : 0 : return npc_program_mcam(npc, &parse_state, 0);
1061 : : }
1062 : :
1063 : : int
1064 : 0 : npc_rss_free_grp_get(struct npc *npc, uint32_t *pos)
1065 : : {
1066 : 0 : struct plt_bitmap *bmap = npc->rss_grp_entries;
1067 : :
1068 [ # # ]: 0 : for (*pos = 0; *pos < ROC_NIX_RSS_GRPS; ++*pos) {
1069 [ # # ]: 0 : if (!plt_bitmap_get(bmap, *pos))
1070 : : break;
1071 : : }
1072 [ # # ]: 0 : return *pos < ROC_NIX_RSS_GRPS ? 0 : -1;
1073 : : }
1074 : :
1075 : : int
1076 : 0 : npc_rss_action_configure(struct roc_npc *roc_npc, const struct roc_npc_action_rss *rss,
1077 : : uint8_t *alg_idx, uint32_t *rss_grp, uint32_t mcam_id,
1078 : : uint16_t rss_repte_pf_func)
1079 : : {
1080 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1081 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1082 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1083 : : uint32_t flowkey_cfg, rss_grp_idx, i, rem;
1084 : : uint8_t key[ROC_NIX_RSS_KEY_LEN];
1085 : : const uint8_t *key_ptr;
1086 : : uint8_t flowkey_algx;
1087 : : uint32_t key_len;
1088 : : uint16_t *reta;
1089 : : int rc;
1090 : :
1091 : 0 : roc_nix_rss_key_get(roc_nix, key);
1092 [ # # ]: 0 : if (rss->key == NULL) {
1093 : : key_ptr = key;
1094 : : } else {
1095 : 0 : key_len = rss->key_len;
1096 : : if (key_len > ROC_NIX_RSS_KEY_LEN)
1097 : : key_len = ROC_NIX_RSS_KEY_LEN;
1098 : :
1099 [ # # ]: 0 : for (i = 0; i < key_len; i++) {
1100 [ # # ]: 0 : if (key[i] != rss->key[i]) {
1101 : 0 : plt_err("RSS key config not supported");
1102 : 0 : plt_err("New Key:");
1103 [ # # ]: 0 : for (i = 0; i < key_len; i++)
1104 : 0 : plt_dump_no_nl("0x%.2x ", rss->key[i]);
1105 : 0 : plt_dump_no_nl("\n");
1106 : 0 : plt_err("Configured Key:");
1107 [ # # ]: 0 : for (i = 0; i < ROC_NIX_RSS_KEY_LEN; i++)
1108 : 0 : plt_dump_no_nl("0x%.2x ", key[i]);
1109 : 0 : plt_dump_no_nl("\n");
1110 : 0 : return -ENOTSUP;
1111 : : }
1112 : : }
1113 : : key_ptr = rss->key;
1114 : : }
1115 : :
1116 : 0 : rc = npc_rss_free_grp_get(npc, &rss_grp_idx);
1117 : : /* RSS group :0 is not usable for flow rss action */
1118 [ # # # # ]: 0 : if (rc < 0 || rss_grp_idx == 0)
1119 : : return -ENOSPC;
1120 : :
1121 [ # # # # ]: 0 : for (i = 0; (i < rss->queue_num) && !rss_repte_pf_func; i++) {
1122 [ # # ]: 0 : if (rss->queue[i] >= nix->nb_rx_queues) {
1123 : 0 : plt_err("queue id > max number of queues");
1124 : 0 : return -EINVAL;
1125 : : }
1126 : : }
1127 : :
1128 : 0 : *rss_grp = rss_grp_idx;
1129 : :
1130 : 0 : roc_nix_rss_key_set(roc_nix, key_ptr);
1131 : :
1132 : : /* If queue count passed in the rss action is less than
1133 : : * HW configured reta size, replicate rss action reta
1134 : : * across HW reta table.
1135 : : */
1136 : 0 : reta = nix->reta[rss_grp_idx];
1137 : :
1138 [ # # ]: 0 : if (rss->queue_num > nix->reta_sz) {
1139 : 0 : plt_err("too many queues for RSS context");
1140 : 0 : return -ENOTSUP;
1141 : : }
1142 : :
1143 [ # # ]: 0 : for (i = 0; i < (nix->reta_sz / rss->queue_num); i++)
1144 : 0 : memcpy(reta + i * rss->queue_num, rss->queue,
1145 : 0 : sizeof(uint16_t) * rss->queue_num);
1146 : :
1147 : 0 : rem = nix->reta_sz % rss->queue_num;
1148 [ # # ]: 0 : if (rem)
1149 : 0 : memcpy(&reta[i * rss->queue_num], rss->queue, rem * sizeof(uint16_t));
1150 : :
1151 : 0 : rc = nix_rss_reta_pffunc_set(roc_nix, *rss_grp, reta, rss_repte_pf_func);
1152 [ # # ]: 0 : if (rc) {
1153 : 0 : plt_err("Failed to init rss table rc = %d", rc);
1154 : 0 : return rc;
1155 : : }
1156 : :
1157 : 0 : flowkey_cfg = roc_npc->flowkey_cfg_state;
1158 : :
1159 : 0 : rc = nix_rss_flowkey_pffunc_set(roc_nix, &flowkey_algx, flowkey_cfg, *rss_grp, mcam_id,
1160 : : rss_repte_pf_func);
1161 [ # # ]: 0 : if (rc) {
1162 : 0 : plt_err("Failed to set rss hash function rc = %d", rc);
1163 : 0 : return rc;
1164 : : }
1165 : :
1166 : 0 : *alg_idx = flowkey_algx;
1167 : :
1168 : 0 : plt_bitmap_set(npc->rss_grp_entries, *rss_grp);
1169 : :
1170 : 0 : return 0;
1171 : : }
1172 : :
1173 : : int
1174 : 0 : npc_rss_action_program(struct roc_npc *roc_npc,
1175 : : const struct roc_npc_action actions[],
1176 : : struct roc_npc_flow *flow)
1177 : : {
1178 : : const struct roc_npc_action_rss *rss;
1179 : : struct roc_npc *npc = roc_npc;
1180 : : uint32_t rss_grp;
1181 : : uint8_t alg_idx;
1182 : : int rc;
1183 : :
1184 [ # # ]: 0 : if (flow->has_rep) {
1185 : 0 : npc = roc_npc->rep_npc;
1186 : 0 : npc->flowkey_cfg_state = roc_npc->flowkey_cfg_state;
1187 : : }
1188 : :
1189 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1190 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_RSS) {
1191 : 0 : rss = (const struct roc_npc_action_rss *)actions->conf;
1192 : 0 : rc = npc_rss_action_configure(npc, rss, &alg_idx, &rss_grp, flow->mcam_id,
1193 : 0 : actions->rss_repte_pf_func);
1194 [ # # ]: 0 : if (rc)
1195 : : return rc;
1196 : :
1197 : 0 : flow->npc_action &= (~(0xfULL));
1198 : 0 : flow->npc_action |= NIX_RX_ACTIONOP_RSS;
1199 : 0 : flow->npc_action |=
1200 : 0 : ((uint64_t)(alg_idx & NPC_RSS_ACT_ALG_MASK)
1201 : 0 : << NPC_RSS_ACT_ALG_OFFSET) |
1202 : 0 : ((uint64_t)(rss_grp & NPC_RSS_ACT_GRP_MASK)
1203 : 0 : << NPC_RSS_ACT_GRP_OFFSET);
1204 : 0 : break;
1205 : : }
1206 : : }
1207 : : return 0;
1208 : : }
1209 : :
1210 : : static int
1211 : 0 : npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1212 : : {
1213 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1214 : : struct nix_vtag_config *vtag_cfg;
1215 : : struct nix_vtag_config_rsp *rsp;
1216 : : struct mbox *mbox, *ombox;
1217 : : struct nix *nix;
1218 : : int rc = 0;
1219 : :
1220 : : union {
1221 : : uint64_t reg;
1222 : : struct nix_tx_vtag_action_s act;
1223 : : } tx_vtag_action;
1224 : :
1225 : : nix = roc_nix_to_nix_priv(roc_nix);
1226 : 0 : ombox = (&nix->dev)->mbox;
1227 [ # # ]: 0 : if (flow->has_rep)
1228 : 0 : ombox = flow->rep_mbox;
1229 : : mbox = mbox_get(ombox);
1230 : :
1231 : 0 : tx_vtag_action.reg = flow->vtag_action;
1232 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox);
1233 : :
1234 [ # # ]: 0 : if (vtag_cfg == NULL) {
1235 : : rc = -ENOSPC;
1236 : 0 : goto exit;
1237 : : }
1238 : :
1239 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1240 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1241 : 0 : vtag_cfg->tx.vtag0_idx = tx_vtag_action.act.vtag0_def;
1242 : 0 : vtag_cfg->tx.free_vtag0 = true;
1243 : :
1244 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1245 : 0 : vtag_cfg->tx.vtag1_idx = tx_vtag_action.act.vtag1_def;
1246 : 0 : vtag_cfg->tx.free_vtag1 = true;
1247 : : }
1248 : :
1249 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1250 [ # # ]: 0 : if (rc)
1251 : 0 : goto exit;
1252 : :
1253 : : rc = 0;
1254 : 0 : exit:
1255 : : mbox_put(mbox);
1256 : 0 : return rc;
1257 : : }
1258 : :
1259 : : static int
1260 : 0 : npc_vtag_insert_action_parse(const struct roc_npc_action actions[],
1261 : : struct roc_npc_flow *flow,
1262 : : struct npc_action_vtag_info *vlan_info,
1263 : : int *parsed_cnt)
1264 : : {
1265 : : bool vlan_id_found = false, ethtype_found = false, pcp_found = false;
1266 : : int count = 0;
1267 : :
1268 : 0 : *parsed_cnt = 0;
1269 : :
1270 : : /* This function parses parameters of one VLAN. When a parameter is
1271 : : * found repeated, it treats it as the end of first VLAN's parameters
1272 : : * and returns. The caller calls again to parse the parameters of the
1273 : : * second VLAN.
1274 : : */
1275 : :
1276 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLAN_PARAMS; count++, actions++) {
1277 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT) {
1278 [ # # ]: 0 : if (vlan_id_found)
1279 : : return 0;
1280 : :
1281 : 0 : const struct roc_npc_action_of_set_vlan_vid *vtag =
1282 : : (const struct roc_npc_action_of_set_vlan_vid *)
1283 : : actions->conf;
1284 : :
1285 [ # # ]: 0 : vlan_info->vlan_id = plt_be_to_cpu_16(vtag->vlan_vid);
1286 : :
1287 [ # # ]: 0 : if (vlan_info->vlan_id > 0xfff) {
1288 : 0 : plt_err("Invalid vlan_id for set vlan action");
1289 : 0 : return -EINVAL;
1290 : : }
1291 : :
1292 : 0 : flow->vtag_insert_enabled = true;
1293 : 0 : (*parsed_cnt)++;
1294 : : vlan_id_found = true;
1295 [ # # ]: 0 : } else if (actions->type ==
1296 : : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT) {
1297 [ # # ]: 0 : if (ethtype_found)
1298 : : return 0;
1299 : :
1300 : 0 : const struct roc_npc_action_of_push_vlan *ethtype =
1301 : : (const struct roc_npc_action_of_push_vlan *)
1302 : : actions->conf;
1303 : 0 : vlan_info->vlan_ethtype =
1304 [ # # ]: 0 : plt_be_to_cpu_16(ethtype->ethertype);
1305 [ # # ]: 0 : if (vlan_info->vlan_ethtype != ROC_ETHER_TYPE_VLAN &&
1306 : : vlan_info->vlan_ethtype != ROC_ETHER_TYPE_QINQ) {
1307 : 0 : plt_err("Invalid ethtype specified for push"
1308 : : " vlan action");
1309 : 0 : return -EINVAL;
1310 : : }
1311 : 0 : flow->vtag_insert_enabled = true;
1312 : 0 : (*parsed_cnt)++;
1313 : : ethtype_found = true;
1314 [ # # ]: 0 : } else if (actions->type ==
1315 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1316 [ # # ]: 0 : if (pcp_found)
1317 : : return 0;
1318 : 0 : const struct roc_npc_action_of_set_vlan_pcp *pcp =
1319 : : (const struct roc_npc_action_of_set_vlan_pcp *)
1320 : : actions->conf;
1321 : 0 : vlan_info->vlan_pcp = pcp->vlan_pcp;
1322 [ # # ]: 0 : if (vlan_info->vlan_pcp > 0x7) {
1323 : 0 : plt_err("Invalid PCP value for pcp action");
1324 : 0 : return -EINVAL;
1325 : : }
1326 : 0 : flow->vtag_insert_enabled = true;
1327 : 0 : (*parsed_cnt)++;
1328 : : pcp_found = true;
1329 : : } else {
1330 : : return 0;
1331 : : }
1332 : : }
1333 : :
1334 : : return 0;
1335 : : }
1336 : :
1337 : : static int
1338 : 0 : npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
1339 : : struct npc_action_vtag_info *vlan_info)
1340 : : {
1341 : : struct nix_vtag_config *vtag_cfg;
1342 : : struct nix_vtag_config_rsp *rsp;
1343 : : int rc = 0;
1344 : :
1345 : : union {
1346 : : uint64_t reg;
1347 : : struct nix_tx_vtag_action_s act;
1348 : : } tx_vtag_action;
1349 : :
1350 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1351 : :
1352 [ # # ]: 0 : if (vtag_cfg == NULL) {
1353 : : rc = -ENOSPC;
1354 : 0 : goto exit;
1355 : : }
1356 : :
1357 : 0 : vtag_cfg->cfg_type = VTAG_TX;
1358 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1359 : 0 : vtag_cfg->tx.vtag0 =
1360 : 0 : (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
1361 : 0 : (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
1362 : :
1363 : 0 : vtag_cfg->tx.cfg_vtag0 = 1;
1364 : :
1365 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1366 : 0 : vtag_cfg->tx.vtag1 =
1367 : 0 : (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
1368 : 0 : (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
1369 : :
1370 : 0 : vtag_cfg->tx.cfg_vtag1 = 1;
1371 : : }
1372 : :
1373 : : rc = mbox_process_msg(mbox, (void *)&rsp);
1374 [ # # ]: 0 : if (rc)
1375 : 0 : goto exit;
1376 : :
1377 [ # # ]: 0 : if (rsp->vtag0_idx < 0 ||
1378 [ # # # # ]: 0 : ((flow->vtag_insert_count == 2) && (rsp->vtag1_idx < 0))) {
1379 : 0 : plt_err("Failed to config TX VTAG action");
1380 : : rc = -EINVAL;
1381 : 0 : goto exit;
1382 : : }
1383 : :
1384 : 0 : tx_vtag_action.reg = 0;
1385 : 0 : tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
1386 : : tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
1387 : 0 : tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
1388 : 0 : tx_vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
1389 : :
1390 [ # # ]: 0 : if (flow->vtag_insert_count == 2) {
1391 : 0 : tx_vtag_action.act.vtag1_def = rsp->vtag1_idx;
1392 : : tx_vtag_action.act.vtag1_lid = NPC_LID_LA;
1393 : 0 : tx_vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
1394 : : /* NIX_TX_VTAG_ACTION_S
1395 : : * If Vtag 0 is inserted, hardware adjusts the Vtag 1 byte
1396 : : * offset accordingly. Thus, if the two offsets are equal in
1397 : : * the structure, hardware inserts Vtag 1 immediately after
1398 : : * Vtag 0 in the packet.
1399 : : */
1400 : 0 : tx_vtag_action.act.vtag1_relptr =
1401 : : NIX_TX_VTAGACTION_VTAG0_RELPTR;
1402 : : }
1403 : :
1404 : 0 : flow->vtag_action = tx_vtag_action.reg;
1405 : :
1406 : : rc = 0;
1407 : 0 : exit:
1408 : : mbox_put(mbox);
1409 : 0 : return rc;
1410 : : }
1411 : :
1412 : : static int
1413 : 0 : npc_vtag_strip_action_configure(struct mbox *mbox,
1414 : : const struct roc_npc_action actions[],
1415 : : struct roc_npc_flow *flow, int *strip_cnt)
1416 : : {
1417 : : struct nix_vtag_config *vtag_cfg;
1418 : : uint64_t rx_vtag_action = 0;
1419 : : int count = 0, rc = 0;
1420 : :
1421 : 0 : *strip_cnt = 0;
1422 : :
1423 [ # # ]: 0 : for (; count < NPC_ACTION_MAX_VLANS_STRIPPED; count++, actions++) {
1424 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP)
1425 : 0 : (*strip_cnt)++;
1426 : : }
1427 : :
1428 : 0 : vtag_cfg = mbox_alloc_msg_nix_vtag_cfg(mbox_get(mbox));
1429 : :
1430 [ # # ]: 0 : if (vtag_cfg == NULL) {
1431 : : rc = -ENOSPC;
1432 : 0 : goto exit;
1433 : : }
1434 : :
1435 : 0 : vtag_cfg->cfg_type = VTAG_RX;
1436 : 0 : vtag_cfg->rx.strip_vtag = 1;
1437 : : /* Always capture */
1438 : 0 : vtag_cfg->rx.capture_vtag = 1;
1439 : 0 : vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
1440 : 0 : vtag_cfg->rx.vtag_type = 0;
1441 : :
1442 : 0 : rc = mbox_process(mbox);
1443 [ # # ]: 0 : if (rc)
1444 : 0 : goto exit;
1445 : :
1446 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
1447 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 8);
1448 : : rx_vtag_action |= ((uint64_t)NIX_RX_VTAG_TYPE6 << 12);
1449 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
1450 : :
1451 [ # # ]: 0 : if (*strip_cnt == 2) {
1452 : : rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
1453 : : rx_vtag_action |= ((uint64_t)NPC_LID_LB << 40);
1454 : : rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR << 32;
1455 : : }
1456 : 0 : flow->vtag_action = rx_vtag_action;
1457 : :
1458 : : rc = 0;
1459 : 0 : exit:
1460 : : mbox_put(mbox);
1461 : 0 : return rc;
1462 : : }
1463 : :
1464 : : static int
1465 : 0 : npc_vtag_action_program(struct roc_npc *roc_npc,
1466 : : const struct roc_npc_action actions[],
1467 : : struct roc_npc_flow *flow)
1468 : : {
1469 : : bool vlan_strip_parsed = false, vlan_insert_parsed = false;
1470 : : const struct roc_npc_action *insert_actions;
1471 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1472 : : struct npc_action_vtag_info vlan_info[2];
1473 : 0 : int parsed_cnt = 0, strip_cnt = 0;
1474 : : int tot_vlan_params = 0;
1475 : : struct mbox *mbox;
1476 : : struct nix *nix;
1477 : : int i, rc;
1478 : :
1479 : : nix = roc_nix_to_nix_priv(roc_nix);
1480 : 0 : mbox = (&nix->dev)->mbox;
1481 [ # # ]: 0 : if (flow->has_rep)
1482 : 0 : mbox = flow->rep_mbox;
1483 : :
1484 : : memset(vlan_info, 0, sizeof(vlan_info));
1485 : :
1486 : 0 : flow->vtag_insert_enabled = false;
1487 : :
1488 [ # # ]: 0 : for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
1489 [ # # ]: 0 : if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_STRIP) {
1490 [ # # ]: 0 : if (vlan_strip_parsed) {
1491 : 0 : plt_err("Incorrect VLAN strip actions");
1492 : 0 : return -EINVAL;
1493 : : }
1494 : 0 : rc = npc_vtag_strip_action_configure(mbox, actions,
1495 : : flow, &strip_cnt);
1496 [ # # ]: 0 : if (rc)
1497 : 0 : return rc;
1498 : :
1499 : 0 : plt_npc_dbg("VLAN strip action, strip_cnt %d", strip_cnt);
1500 [ # # ]: 0 : if (strip_cnt == 2)
1501 : 0 : actions++;
1502 : :
1503 : : vlan_strip_parsed = true;
1504 [ # # ]: 0 : } else if (actions->type == ROC_NPC_ACTION_TYPE_VLAN_INSERT ||
1505 : : actions->type ==
1506 [ # # ]: 0 : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT ||
1507 : : actions->type ==
1508 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT) {
1509 [ # # ]: 0 : if (vlan_insert_parsed) {
1510 : 0 : plt_err("Incorrect VLAN insert actions");
1511 : 0 : return -EINVAL;
1512 : : }
1513 : :
1514 : : insert_actions = actions;
1515 : :
1516 [ # # ]: 0 : for (i = 0; i < 2; i++) {
1517 : 0 : rc = npc_vtag_insert_action_parse(
1518 : : insert_actions, flow, &vlan_info[i],
1519 : : &parsed_cnt);
1520 : :
1521 [ # # ]: 0 : if (rc)
1522 : 0 : return rc;
1523 : :
1524 [ # # ]: 0 : if (parsed_cnt) {
1525 : 0 : insert_actions += parsed_cnt;
1526 : 0 : tot_vlan_params += parsed_cnt;
1527 : 0 : flow->vtag_insert_count++;
1528 : : }
1529 : : }
1530 : 0 : actions += tot_vlan_params - 1;
1531 : : vlan_insert_parsed = true;
1532 : : }
1533 : : }
1534 : :
1535 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1536 : 0 : rc = npc_vtag_insert_action_configure(mbox, flow, vlan_info);
1537 : :
1538 [ # # ]: 0 : if (rc)
1539 : 0 : return rc;
1540 : : }
1541 : : return 0;
1542 : : }
1543 : :
1544 : : static int
1545 : 0 : npc_inline_dev_ipsec_action_free(struct npc *npc, struct roc_npc_flow *flow)
1546 : : {
1547 : : struct nix_inl_dev *inl_dev;
1548 : : struct idev_cfg *idev;
1549 : : int rc;
1550 : :
1551 : : PLT_SET_USED(npc);
1552 : :
1553 : 0 : idev = idev_get_cfg();
1554 [ # # ]: 0 : if (!idev)
1555 : : return 1;
1556 : :
1557 : 0 : inl_dev = idev->nix_inl_dev;
1558 : :
1559 [ # # # # : 0 : if (flow->nix_intf == NIX_INTF_RX && inl_dev && inl_dev->ipsec_index &&
# # # # ]
1560 [ # # ]: 0 : roc_npc_action_is_rx_inline(flow->npc_action)) {
1561 : 0 : inl_dev->curr_ipsec_idx--;
1562 : 0 : inl_dev->ipsec_index[inl_dev->curr_ipsec_idx] = flow->mcam_id;
1563 : 0 : flow->enable = 0;
1564 [ # # ]: 0 : if (flow->use_ctr) {
1565 : 0 : rc = npc_mcam_clear_counter(inl_dev->dev.mbox, flow->ctr_id);
1566 [ # # ]: 0 : if (rc)
1567 : : return rc;
1568 : :
1569 : 0 : rc = npc_mcam_free_counter(inl_dev->dev.mbox, flow->ctr_id);
1570 [ # # ]: 0 : if (rc)
1571 : : return rc;
1572 : : }
1573 : 0 : return npc_mcam_write_entry(inl_dev->dev.mbox, flow);
1574 : : }
1575 : :
1576 : : return 1;
1577 : : }
1578 : :
1579 : : void
1580 : 0 : roc_npc_sdp_channel_get(struct roc_npc *roc_npc, uint16_t *chan_base, uint16_t *chan_mask)
1581 : : {
1582 : 0 : struct roc_nix *roc_nix = roc_npc->roc_nix;
1583 : : struct nix *nix = roc_nix_to_nix_priv(roc_nix);
1584 : : uint16_t num_chan, range, num_bits = 0;
1585 : : uint16_t mask = 0;
1586 : :
1587 : 0 : *chan_base = nix->rx_chan_base;
1588 : 0 : num_chan = nix->rx_chan_cnt - 1;
1589 [ # # ]: 0 : if (num_chan) {
1590 : 0 : range = *chan_base ^ (*chan_base + num_chan);
1591 : 0 : num_bits = (sizeof(uint32_t) * 8) - plt_clz32(range) - 1;
1592 : : /* Set mask for (15 - numbits) MSB bits */
1593 : 0 : *chan_mask = (uint16_t)~GENMASK(num_bits, 0);
1594 : 0 : *chan_mask &= 0xFFF;
1595 : : } else {
1596 : 0 : *chan_mask = (uint16_t)GENMASK(11, 0);
1597 : : }
1598 : :
1599 : 0 : mask = (uint16_t)GENMASK(num_bits, 0);
1600 [ # # ]: 0 : if (mask > num_chan + 1)
1601 : 0 : plt_warn(
1602 : : "npc: SDP channel base:%x, channel count:%x. channel mask:%x covers more than channel count",
1603 : : *chan_base, nix->rx_chan_cnt, *chan_mask);
1604 : 0 : }
1605 : :
1606 : : struct roc_npc_flow *
1607 : 0 : roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
1608 : : const struct roc_npc_item_info pattern[], const struct roc_npc_action actions[],
1609 : : uint16_t dst_pf_func, int *errcode)
1610 : : {
1611 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1612 : 0 : uint16_t sdp_chan_base = 0, sdp_chan_mask = 0;
1613 : : struct roc_npc_flow *flow, *flow_iter;
1614 : : struct npc_parse_state parse_state;
1615 : : struct npc_flow_list *list;
1616 : : int rc;
1617 : :
1618 : 0 : npc->channel = roc_npc->channel;
1619 : 0 : npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
1620 [ # # ]: 0 : if (npc->is_sdp_link) {
1621 [ # # ]: 0 : if (roc_npc->is_sdp_mask_set) {
1622 : 0 : npc->sdp_channel = roc_npc->sdp_channel;
1623 : 0 : npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
1624 : : } else {
1625 : 0 : roc_npc_sdp_channel_get(roc_npc, &sdp_chan_base, &sdp_chan_mask);
1626 : 0 : npc->sdp_channel = sdp_chan_base;
1627 : 0 : npc->sdp_channel_mask = sdp_chan_mask;
1628 : : }
1629 : : }
1630 : :
1631 : 0 : flow = plt_zmalloc(sizeof(*flow), 0);
1632 [ # # ]: 0 : if (flow == NULL) {
1633 : 0 : *errcode = NPC_ERR_NO_MEM;
1634 : 0 : return NULL;
1635 : : }
1636 : : memset(flow, 0, sizeof(*flow));
1637 : : memset(&parse_state, 0, sizeof(parse_state));
1638 : :
1639 : 0 : flow->port_id = -1;
1640 [ # # ]: 0 : if (roc_npc->rep_npc) {
1641 : 0 : flow->rep_channel =
1642 [ # # ]: 0 : (roc_npc->rep_rx_channel == 0) ?
1643 : 0 : roc_nix_to_nix_priv(roc_npc->rep_npc->roc_nix)->rx_chan_base :
1644 : : roc_npc->rep_rx_channel;
1645 : 0 : flow->rep_pf_func = roc_npc->rep_pf_func;
1646 : 0 : flow->rep_act_pf_func = roc_npc->rep_act_pf_func;
1647 : 0 : flow->rep_act_rep = roc_npc->rep_act_rep;
1648 : 0 : flow->rep_mbox = roc_npc_to_npc_priv(roc_npc->rep_npc)->mbox;
1649 : 0 : flow->has_rep = true;
1650 : 0 : flow->is_rep_vf = !roc_nix_is_pf(roc_npc->rep_npc->roc_nix);
1651 : 0 : flow->port_id = roc_npc->rep_port_id;
1652 : 0 : flow->rep_npc = roc_npc_to_npc_priv(roc_npc->rep_npc);
1653 : 0 : roc_npc->rep_act_rep = false;
1654 : 0 : roc_npc->rep_act_pf_func = 0;
1655 : 0 : roc_npc->rep_rx_channel = 0;
1656 : : }
1657 : :
1658 : 0 : parse_state.dst_pf_func = dst_pf_func;
1659 : :
1660 : 0 : rc = npc_parse_rule(roc_npc, attr, pattern, actions, flow, &parse_state);
1661 [ # # ]: 0 : if (rc != 0) {
1662 : 0 : *errcode = rc;
1663 : 0 : goto err_exit;
1664 : : }
1665 : :
1666 : 0 : rc = npc_vtag_action_program(roc_npc, actions, flow);
1667 [ # # ]: 0 : if (rc != 0) {
1668 : 0 : *errcode = rc;
1669 : 0 : goto err_exit;
1670 : : }
1671 : :
1672 : 0 : parse_state.is_vf = !roc_nix_is_pf(roc_npc->roc_nix);
1673 : :
1674 : 0 : rc = npc_program_mcam(npc, &parse_state, 1);
1675 [ # # ]: 0 : if (rc != 0) {
1676 : 0 : *errcode = rc;
1677 : 0 : goto err_exit;
1678 : : }
1679 : :
1680 : : /* If Egress mirror requested then enable TL3_TL2_LINK_CFG */
1681 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1682 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1683 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1684 : 0 : flow->mcast_pf_funcs[1], true);
1685 : : else
1686 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1687 : : flow->mcast_pf_funcs[0], true);
1688 [ # # ]: 0 : if (rc) {
1689 : 0 : plt_err("Adding egress mirror failed");
1690 : 0 : *errcode = rc;
1691 : 0 : goto err_exit;
1692 : : }
1693 : : }
1694 : :
1695 : 0 : rc = npc_rss_action_program(roc_npc, actions, flow);
1696 [ # # ]: 0 : if (rc != 0) {
1697 : 0 : *errcode = rc;
1698 : 0 : goto set_rss_failed;
1699 : : }
1700 : 0 : roc_npc->rep_npc = NULL;
1701 : 0 : roc_npc->rep_act_pf_func = 0;
1702 : :
1703 [ # # ]: 0 : if (flow->has_age_action)
1704 : 0 : npc_age_flow_list_entry_add(roc_npc, flow);
1705 : :
1706 [ # # ]: 0 : if (flow->use_pre_alloc == 0)
1707 : 0 : list = &npc->flow_list[flow->priority];
1708 : : else
1709 : 0 : list = &npc->ipsec_list;
1710 : : /* List in ascending order of mcam entries */
1711 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1712 [ # # ]: 0 : if (flow_iter->mcam_id > flow->mcam_id) {
1713 : 0 : TAILQ_INSERT_BEFORE(flow_iter, flow, next);
1714 : 0 : roc_npc->rep_npc = NULL;
1715 : 0 : return flow;
1716 : : }
1717 : : }
1718 : 0 : TAILQ_INSERT_TAIL(list, flow, next);
1719 : :
1720 : 0 : return flow;
1721 : :
1722 : : set_rss_failed:
1723 : 0 : roc_npc->rep_npc = NULL;
1724 : 0 : roc_npc->rep_act_pf_func = 0;
1725 [ # # ]: 0 : if (flow->use_pre_alloc == 0) {
1726 : 0 : rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
1727 [ # # ]: 0 : if (rc != 0) {
1728 : 0 : *errcode = rc;
1729 : 0 : plt_free(flow);
1730 : 0 : return NULL;
1731 : : }
1732 : : } else {
1733 : 0 : npc_inline_dev_ipsec_action_free(npc, flow);
1734 : : }
1735 : 0 : err_exit:
1736 : 0 : roc_npc->rep_npc = NULL;
1737 : 0 : roc_npc->rep_act_pf_func = 0;
1738 : 0 : plt_free(flow);
1739 : 0 : return NULL;
1740 : : }
1741 : :
1742 : : int
1743 : 0 : npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow)
1744 : : {
1745 : : struct npc *lnpc = npc;
1746 : : uint32_t rss_grp;
1747 : :
1748 [ # # ]: 0 : if (flow->has_rep)
1749 : 0 : lnpc = flow->rep_npc;
1750 : :
1751 [ # # ]: 0 : if ((flow->npc_action & 0xF) == NIX_RX_ACTIONOP_RSS) {
1752 : 0 : rss_grp = (flow->npc_action >> NPC_RSS_ACT_GRP_OFFSET) &
1753 : : NPC_RSS_ACT_GRP_MASK;
1754 [ # # # # ]: 0 : if (rss_grp == 0 || rss_grp >= npc->rss_grps)
1755 : : return -EINVAL;
1756 : :
1757 : 0 : plt_bitmap_clear(lnpc->rss_grp_entries, rss_grp);
1758 : : }
1759 : :
1760 : : return 0;
1761 : : }
1762 : :
1763 : : static int
1764 : 0 : roc_npc_delete_spi_to_sa_action(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1765 : : {
1766 : : struct nix_spi_to_sa_delete_req *req;
1767 : : struct nix_inl_dev *inl_dev;
1768 : : struct idev_cfg *idev;
1769 : : struct mbox *mbox;
1770 : :
1771 : : PLT_SET_USED(roc_npc);
1772 : :
1773 [ # # # # ]: 0 : if (!flow->spi_to_sa_info.has_action || flow->spi_to_sa_info.duplicate)
1774 : : return 0;
1775 : :
1776 : 0 : idev = idev_get_cfg();
1777 [ # # ]: 0 : if (!idev)
1778 : : return -1;
1779 : :
1780 : 0 : inl_dev = idev->nix_inl_dev;
1781 : 0 : mbox = inl_dev->dev.mbox;
1782 : 0 : req = mbox_alloc_msg_nix_spi_to_sa_delete(mbox);
1783 [ # # ]: 0 : if (req == NULL)
1784 : : return -ENOSPC;
1785 : 0 : req->hash_index = flow->spi_to_sa_info.hash_index;
1786 : 0 : req->way = flow->spi_to_sa_info.way;
1787 : 0 : return mbox_process_msg(mbox, NULL);
1788 : : }
1789 : :
1790 : : int
1791 : 0 : roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1792 : : {
1793 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1794 : : int rc;
1795 : :
1796 : 0 : rc = roc_npc_delete_spi_to_sa_action(roc_npc, flow);
1797 [ # # ]: 0 : if (rc)
1798 : : return rc;
1799 : :
1800 [ # # ]: 0 : if (npc_inline_dev_ipsec_action_free(npc, flow) == 0) {
1801 [ # # ]: 0 : TAILQ_REMOVE(&npc->ipsec_list, flow, next);
1802 : 0 : goto done;
1803 : : }
1804 : :
1805 : 0 : rc = npc_rss_group_free(npc, flow);
1806 [ # # ]: 0 : if (rc != 0) {
1807 : 0 : plt_err("Failed to free rss action rc = %d", rc);
1808 : 0 : return rc;
1809 : : }
1810 : :
1811 [ # # ]: 0 : if (flow->vtag_insert_enabled) {
1812 : 0 : rc = npc_vtag_cfg_delete(roc_npc, flow);
1813 [ # # ]: 0 : if (rc != 0)
1814 : : return rc;
1815 : : }
1816 : :
1817 : : /* Disable egress mirror rule */
1818 [ # # # # ]: 0 : if (flow->is_sampling_rule && (flow->nix_intf == NIX_INTF_TX)) {
1819 [ # # ]: 0 : if (flow->mcast_pf_funcs[0] == npc->pf_func)
1820 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1821 : 0 : flow->mcast_pf_funcs[1], false);
1822 : : else
1823 : 0 : rc = roc_nix_tm_egress_link_cfg_set(roc_npc->roc_nix,
1824 : : flow->mcast_pf_funcs[0], false);
1825 [ # # ]: 0 : if (rc)
1826 : 0 : plt_err("Failed to remove egress mirror rule");
1827 : : }
1828 [ # # ]: 0 : if (flow->is_sampling_rule)
1829 : 0 : roc_nix_mcast_list_free(npc->mbox, flow->mcast_grp_index);
1830 : :
1831 : 0 : rc = roc_npc_mcam_free(roc_npc, flow);
1832 [ # # ]: 0 : if (rc != 0)
1833 : : return rc;
1834 : :
1835 [ # # ]: 0 : TAILQ_REMOVE(&npc->flow_list[flow->priority], flow, next);
1836 : :
1837 : 0 : npc_delete_prio_list_entry(npc, flow);
1838 : :
1839 [ # # ]: 0 : if (flow->has_age_action)
1840 : 0 : npc_age_flow_list_entry_delete(roc_npc, flow);
1841 : :
1842 [ # # ]: 0 : if (roc_npc->flow_age.age_flow_refcnt == 0)
1843 : 0 : npc_aging_ctrl_thread_destroy(roc_npc);
1844 : :
1845 : 0 : done:
1846 : 0 : plt_free(flow);
1847 : 0 : return 0;
1848 : : }
1849 : :
1850 : : void
1851 : 0 : roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc, int rep_port_id)
1852 : : {
1853 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1854 : : struct roc_npc_flow *flow_iter;
1855 : : struct npc_flow_list *list;
1856 : : uint32_t max_prio, i;
1857 : :
1858 : 0 : max_prio = npc->flow_max_priority;
1859 : :
1860 [ # # ]: 0 : for (i = 0; i < max_prio; i++) {
1861 : 0 : list = &npc->flow_list[i];
1862 : :
1863 : : /* List in ascending order of mcam entries */
1864 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, list, next) {
1865 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1866 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1867 : : }
1868 : : }
1869 : :
1870 [ # # ]: 0 : TAILQ_FOREACH(flow_iter, &npc->ipsec_list, next) {
1871 [ # # # # ]: 0 : if (rep_port_id == -1 || rep_port_id == flow_iter->port_id)
1872 : 0 : roc_npc_flow_mcam_dump(file, roc_npc, flow_iter);
1873 : : }
1874 : 0 : }
1875 : :
1876 : : int
1877 : 0 : roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
1878 : : {
1879 : : struct npc *npc = roc_npc_to_npc_priv(roc_npc);
1880 : 0 : struct mbox *mbox = mbox_get(npc->mbox);
1881 : : int idx, rc;
1882 : :
1883 [ # # ]: 0 : if (roc_nix_is_pf(roc_npc->roc_nix)) {
1884 : : rc = 0;
1885 : 0 : goto exit;
1886 : : }
1887 : :
1888 : 0 : (void)mbox_alloc_msg_npc_read_base_steer_rule(mbox);
1889 [ # # ]: 0 : if (roc_model_is_cn20k()) {
1890 : : struct npc_cn20k_mcam_read_base_rule_rsp *base_rule_rsp;
1891 : : struct cn20k_mcam_entry *base_entry;
1892 : :
1893 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
1894 [ # # ]: 0 : if (rc) {
1895 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
1896 : 0 : goto exit;
1897 : : }
1898 : 0 : base_entry = &base_rule_rsp->entry;
1899 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1900 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
1901 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
1902 : : }
1903 : :
1904 : : } else {
1905 : : struct npc_mcam_read_base_rule_rsp *base_rule_rsp;
1906 : : struct mcam_entry *base_entry;
1907 : :
1908 : : rc = mbox_process_msg(mbox, (void *)&base_rule_rsp);
1909 [ # # ]: 0 : if (rc) {
1910 : 0 : plt_err("Failed to fetch VF's base MCAM entry");
1911 : 0 : goto exit;
1912 : : }
1913 : 0 : base_entry = &base_rule_rsp->entry_data;
1914 [ # # ]: 0 : for (idx = 0; idx < ROC_NPC_MAX_MCAM_WIDTH_DWORDS; idx++) {
1915 : 0 : flow->mcam_data[idx] |= base_entry->kw[idx];
1916 : 0 : flow->mcam_mask[idx] |= base_entry->kw_mask[idx];
1917 : : }
1918 : : }
1919 : : rc = 0;
1920 : 0 : exit:
1921 : : mbox_put(mbox);
1922 : 0 : return rc;
1923 : : }
|