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