Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2024 Marvell.
3 : : */
4 : :
5 : : #include <rte_cryptodev.h>
6 : : #include <rte_eventdev.h>
7 : : #include <rte_pmd_cnxk.h>
8 : : #include <rte_security.h>
9 : : #include <rte_security_driver.h>
10 : :
11 : : #include <cn20k_ethdev.h>
12 : : #include <cn20k_rx.h>
13 : : #include <cnxk_security.h>
14 : : #include <roc_priv.h>
15 : :
16 : : PLT_STATIC_ASSERT(offsetof(struct rte_pmd_cnxk_ipsec_inb_sa, ctx.ar_winbits) ==
17 : : offsetof(struct roc_ow_ipsec_inb_sa, ctx.ar_winbits));
18 : :
19 : : PLT_STATIC_ASSERT(offsetof(struct rte_pmd_cnxk_ipsec_outb_sa, ctx.mib_pkts) ==
20 : : offsetof(struct roc_ow_ipsec_outb_sa, ctx.mib_pkts));
21 : :
22 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_CTX_MAX_CKEY_LEN == ROC_CTX_MAX_CKEY_LEN);
23 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_CTX_MAX_OPAD_IPAD_LEN == RTE_PMD_CNXK_CTX_MAX_OPAD_IPAD_LEN);
24 : :
25 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WIN_SIZE_MIN == ROC_AR_WIN_SIZE_MIN);
26 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WIN_SIZE_MAX == ROC_AR_WIN_SIZE_MAX);
27 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_LOG_MIN_AR_WIN_SIZE_M1 == ROC_LOG_MIN_AR_WIN_SIZE_M1);
28 : : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WINBITS_SZ == ROC_AR_WINBITS_SZ);
29 : :
30 : : static struct rte_cryptodev_capabilities cn20k_eth_sec_crypto_caps[] = {
31 : : { /* AES GCM */
32 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
33 : : {.sym = {
34 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
35 : : {.aead = {
36 : : .algo = RTE_CRYPTO_AEAD_AES_GCM,
37 : : .block_size = 16,
38 : : .key_size = {
39 : : .min = 16,
40 : : .max = 32,
41 : : .increment = 8
42 : : },
43 : : .digest_size = {
44 : : .min = 16,
45 : : .max = 16,
46 : : .increment = 0
47 : : },
48 : : .aad_size = {
49 : : .min = 8,
50 : : .max = 12,
51 : : .increment = 4
52 : : },
53 : : .iv_size = {
54 : : .min = 12,
55 : : .max = 12,
56 : : .increment = 0
57 : : }
58 : : }, }
59 : : }, }
60 : : },
61 : : { /* AES CBC */
62 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
63 : : {.sym = {
64 : : .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
65 : : {.cipher = {
66 : : .algo = RTE_CRYPTO_CIPHER_AES_CBC,
67 : : .block_size = 16,
68 : : .key_size = {
69 : : .min = 16,
70 : : .max = 32,
71 : : .increment = 8
72 : : },
73 : : .iv_size = {
74 : : .min = 16,
75 : : .max = 16,
76 : : .increment = 0
77 : : }
78 : : }, }
79 : : }, }
80 : : },
81 : : { /* AES CTR */
82 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
83 : : {.sym = {
84 : : .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
85 : : {.cipher = {
86 : : .algo = RTE_CRYPTO_CIPHER_AES_CTR,
87 : : .block_size = 16,
88 : : .key_size = {
89 : : .min = 16,
90 : : .max = 32,
91 : : .increment = 8
92 : : },
93 : : .iv_size = {
94 : : .min = 12,
95 : : .max = 16,
96 : : .increment = 4
97 : : }
98 : : }, }
99 : : }, }
100 : : },
101 : : { /* 3DES CBC */
102 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
103 : : {.sym = {
104 : : .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
105 : : {.cipher = {
106 : : .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
107 : : .block_size = 8,
108 : : .key_size = {
109 : : .min = 24,
110 : : .max = 24,
111 : : .increment = 0
112 : : },
113 : : .iv_size = {
114 : : .min = 8,
115 : : .max = 16,
116 : : .increment = 8
117 : : }
118 : : }, }
119 : : }, }
120 : : },
121 : : { /* AES-XCBC */
122 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
123 : : { .sym = {
124 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
125 : : {.auth = {
126 : : .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
127 : : .block_size = 16,
128 : : .key_size = {
129 : : .min = 16,
130 : : .max = 16,
131 : : .increment = 0
132 : : },
133 : : .digest_size = {
134 : : .min = 12,
135 : : .max = 12,
136 : : .increment = 0,
137 : : },
138 : : }, }
139 : : }, }
140 : : },
141 : : { /* SHA1 HMAC */
142 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
143 : : {.sym = {
144 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
145 : : {.auth = {
146 : : .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
147 : : .block_size = 64,
148 : : .key_size = {
149 : : .min = 20,
150 : : .max = 64,
151 : : .increment = 1
152 : : },
153 : : .digest_size = {
154 : : .min = 12,
155 : : .max = 12,
156 : : .increment = 0
157 : : },
158 : : }, }
159 : : }, }
160 : : },
161 : : { /* SHA256 HMAC */
162 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
163 : : {.sym = {
164 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
165 : : {.auth = {
166 : : .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
167 : : .block_size = 64,
168 : : .key_size = {
169 : : .min = 1,
170 : : .max = 1024,
171 : : .increment = 1
172 : : },
173 : : .digest_size = {
174 : : .min = 16,
175 : : .max = 32,
176 : : .increment = 16
177 : : },
178 : : }, }
179 : : }, }
180 : : },
181 : : { /* SHA384 HMAC */
182 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
183 : : {.sym = {
184 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
185 : : {.auth = {
186 : : .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
187 : : .block_size = 64,
188 : : .key_size = {
189 : : .min = 1,
190 : : .max = 1024,
191 : : .increment = 1
192 : : },
193 : : .digest_size = {
194 : : .min = 24,
195 : : .max = 48,
196 : : .increment = 24
197 : : },
198 : : }, }
199 : : }, }
200 : : },
201 : : { /* SHA512 HMAC */
202 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
203 : : {.sym = {
204 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
205 : : {.auth = {
206 : : .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
207 : : .block_size = 128,
208 : : .key_size = {
209 : : .min = 1,
210 : : .max = 1024,
211 : : .increment = 1
212 : : },
213 : : .digest_size = {
214 : : .min = 32,
215 : : .max = 64,
216 : : .increment = 32
217 : : },
218 : : }, }
219 : : }, }
220 : : },
221 : : { /* AES GMAC (AUTH) */
222 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
223 : : {.sym = {
224 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
225 : : {.auth = {
226 : : .algo = RTE_CRYPTO_AUTH_AES_GMAC,
227 : : .block_size = 16,
228 : : .key_size = {
229 : : .min = 16,
230 : : .max = 32,
231 : : .increment = 8
232 : : },
233 : : .digest_size = {
234 : : .min = 8,
235 : : .max = 16,
236 : : .increment = 4
237 : : },
238 : : .iv_size = {
239 : : .min = 12,
240 : : .max = 12,
241 : : .increment = 0
242 : : }
243 : : }, }
244 : : }, }
245 : : },
246 : : { /* AES CCM */
247 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
248 : : {.sym = {
249 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
250 : : {.aead = {
251 : : .algo = RTE_CRYPTO_AEAD_AES_CCM,
252 : : .block_size = 16,
253 : : .key_size = {
254 : : .min = 16,
255 : : .max = 32,
256 : : .increment = 8
257 : : },
258 : : .digest_size = {
259 : : .min = 16,
260 : : .max = 16,
261 : : .increment = 0
262 : : },
263 : : .aad_size = {
264 : : .min = 8,
265 : : .max = 12,
266 : : .increment = 4
267 : : },
268 : : .iv_size = {
269 : : .min = 11,
270 : : .max = 13,
271 : : .increment = 1
272 : : }
273 : : }, }
274 : : }, }
275 : : },
276 : : { /* NULL (AUTH) */
277 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
278 : : {.sym = {
279 : : .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
280 : : {.auth = {
281 : : .algo = RTE_CRYPTO_AUTH_NULL,
282 : : .block_size = 1,
283 : : .key_size = {
284 : : .min = 0,
285 : : .max = 0,
286 : : .increment = 0
287 : : },
288 : : .digest_size = {
289 : : .min = 0,
290 : : .max = 0,
291 : : .increment = 0
292 : : },
293 : : }, },
294 : : }, },
295 : : },
296 : : { /* NULL (CIPHER) */
297 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
298 : : {.sym = {
299 : : .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
300 : : {.cipher = {
301 : : .algo = RTE_CRYPTO_CIPHER_NULL,
302 : : .block_size = 1,
303 : : .key_size = {
304 : : .min = 0,
305 : : .max = 0,
306 : : .increment = 0
307 : : },
308 : : .iv_size = {
309 : : .min = 0,
310 : : .max = 0,
311 : : .increment = 0
312 : : }
313 : : }, },
314 : : }, }
315 : : },
316 : :
317 : : RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
318 : : };
319 : :
320 : : static const struct rte_security_capability cn20k_eth_sec_ipsec_capabilities[] = {
321 : : { /* IPsec Inline Protocol ESP Tunnel Ingress */
322 : : .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
323 : : .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
324 : : .ipsec = {
325 : : .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
326 : : .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
327 : : .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
328 : : .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
329 : : .options = {
330 : : .udp_encap = 1,
331 : : .udp_ports_verify = 1,
332 : : .copy_df = 1,
333 : : .copy_dscp = 1,
334 : : .copy_flabel = 1,
335 : : .tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR,
336 : : .dec_ttl = 1,
337 : : .ip_csum_enable = 1,
338 : : .l4_csum_enable = 1,
339 : : .stats = 1,
340 : : .esn = 1,
341 : : .ingress_oop = 1,
342 : : },
343 : : },
344 : : .crypto_capabilities = cn20k_eth_sec_crypto_caps,
345 : : .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
346 : : },
347 : : { /* IPsec Inline Protocol ESP Tunnel Egress */
348 : : .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
349 : : .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
350 : : .ipsec = {
351 : : .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
352 : : .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
353 : : .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
354 : : .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
355 : : .options = {
356 : : .iv_gen_disable = 1,
357 : : .udp_encap = 1,
358 : : .udp_ports_verify = 1,
359 : : .copy_df = 1,
360 : : .copy_dscp = 1,
361 : : .copy_flabel = 1,
362 : : .dec_ttl = 1,
363 : : .ip_csum_enable = 1,
364 : : .l4_csum_enable = 1,
365 : : .stats = 1,
366 : : .esn = 1,
367 : : },
368 : : },
369 : : .crypto_capabilities = cn20k_eth_sec_crypto_caps,
370 : : .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
371 : : },
372 : : { /* IPsec Inline Protocol ESP Transport Egress */
373 : : .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
374 : : .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
375 : : .ipsec = {
376 : : .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
377 : : .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
378 : : .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
379 : : .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
380 : : .options = {
381 : : .iv_gen_disable = 1,
382 : : .udp_encap = 1,
383 : : .udp_ports_verify = 1,
384 : : .copy_df = 1,
385 : : .copy_dscp = 1,
386 : : .dec_ttl = 1,
387 : : .ip_csum_enable = 1,
388 : : .l4_csum_enable = 1,
389 : : .stats = 1,
390 : : .esn = 1,
391 : : .ingress_oop = 1,
392 : : },
393 : : },
394 : : .crypto_capabilities = cn20k_eth_sec_crypto_caps,
395 : : .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
396 : : },
397 : : { /* IPsec Inline Protocol ESP Transport Ingress */
398 : : .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
399 : : .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
400 : : .ipsec = {
401 : : .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
402 : : .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
403 : : .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
404 : : .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
405 : : .options = {
406 : : .udp_encap = 1,
407 : : .udp_ports_verify = 1,
408 : : .copy_df = 1,
409 : : .copy_dscp = 1,
410 : : .dec_ttl = 1,
411 : : .ip_csum_enable = 1,
412 : : .l4_csum_enable = 1,
413 : : .stats = 1,
414 : : .esn = 1,
415 : : .ingress_oop = 1,
416 : : },
417 : : },
418 : : .crypto_capabilities = cn20k_eth_sec_crypto_caps,
419 : : .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
420 : : },
421 : : };
422 : :
423 : : #define SEC_CAPS_LEN (RTE_DIM(cn20k_eth_sec_ipsec_capabilities) + 1)
424 : :
425 : : static struct rte_security_capability cn20k_eth_sec_capabilities[SEC_CAPS_LEN];
426 : :
427 : : static inline void
428 : : cnxk_pktmbuf_free_no_cache(struct rte_mbuf *mbuf)
429 : : {
430 : : struct rte_mbuf *next;
431 : :
432 [ # # # # : 0 : if (!mbuf)
# # ]
433 : : return;
434 : : do {
435 : 0 : next = mbuf->next;
436 [ # # # # : 0 : roc_npa_aura_op_free(mbuf->pool->pool_id, 1, (rte_iova_t)mbuf);
# # ]
437 : : mbuf = next;
438 [ # # # # : 0 : } while (mbuf != NULL);
# # ]
439 : : }
440 : :
441 : : static bool
442 [ # # ]: 0 : cn20k_eth_sec_post_event(struct rte_eth_dev *eth_dev, void *sa, enum nix_inl_event_type type,
443 : : uint16_t uc_compcode, uint16_t compcode, struct rte_mbuf *mbuf)
444 : : {
445 : : struct rte_eth_event_ipsec_desc desc;
446 : : struct cn20k_sec_sess_priv sess_priv;
447 : : struct cn20k_outb_priv_data *outb_priv;
448 : : struct cn20k_inb_priv_data *inb_priv;
449 : : static uint64_t warn_cnt;
450 : : bool free_mbuf = false;
451 : : uint64_t life_unit;
452 : :
453 : : memset(&desc, 0, sizeof(desc));
454 : 0 : sess_priv.u64 = 0;
455 : :
456 [ # # ]: 0 : if (type == NIX_INL_INB_CPT_CQ) {
457 : : struct roc_ow_ipsec_inb_sa *inb_sa = (struct roc_ow_ipsec_inb_sa *)sa;
458 [ # # ]: 0 : inb_priv = sa ? roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(sa) : NULL;
459 : 0 : desc.metadata = inb_priv ? (uint64_t)inb_priv->userdata : 0;
460 [ # # ]: 0 : life_unit = inb_sa ? inb_sa->w2.s.life_unit : 0;
461 : : } else {
462 : : struct roc_ow_ipsec_outb_sa *outb_sa = (struct roc_ow_ipsec_outb_sa *)sa;
463 : : outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(sa);
464 : 0 : desc.metadata = (uint64_t)outb_priv->userdata;
465 : 0 : life_unit = outb_sa->w2.s.life_unit;
466 : : free_mbuf = true;
467 : : }
468 : :
469 [ # # ]: 0 : if (mbuf)
470 : 0 : sess_priv.u64 = *rte_security_dynfield(mbuf);
471 : :
472 [ # # # # : 0 : switch (uc_compcode) {
# ]
473 : 0 : case ROC_IE_OW_UCC_ERR_SA_OVERFLOW:
474 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW;
475 : 0 : break;
476 : 0 : case ROC_IE_OW_UCC_ERR_SA_EXPIRED:
477 [ # # ]: 0 : if (life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
478 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
479 : : else
480 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
481 : : break;
482 : 0 : case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_FIRST:
483 : : case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_AGAIN:
484 [ # # ]: 0 : if (life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
485 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
486 : : else
487 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
488 : : free_mbuf = false;
489 : : break;
490 : 0 : case ROC_IE_OW_UCC_ERR_PKT_IP:
491 : 0 : warn_cnt++;
492 [ # # ]: 0 : if (warn_cnt % 10000 == 0)
493 : 0 : plt_warn("Outbound error, bad ip pkt, mbuf %p,"
494 : : "sa_index %u (total warnings %" PRIu64 ")",
495 : : mbuf, sess_priv.sa_idx, warn_cnt);
496 : 0 : desc.subtype = -uc_compcode;
497 : 0 : break;
498 : 0 : default:
499 : 0 : warn_cnt++;
500 [ # # ]: 0 : if (warn_cnt % 10000 == 0)
501 : 0 : plt_warn("Outbound error, mbuf %p, sa_index %u,"
502 : : " compcode %x uc %x,"
503 : : " (total warnings %" PRIu64 ")",
504 : : mbuf, sess_priv.sa_idx, compcode, uc_compcode, warn_cnt);
505 : 0 : desc.subtype = -uc_compcode;
506 : 0 : break;
507 : : }
508 : :
509 [ # # ]: 0 : if (eth_dev)
510 : 0 : rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_IPSEC, &desc);
511 : :
512 : 0 : return free_mbuf;
513 : : }
514 : :
515 : : static const char *
516 : : get_inl_event_type(enum nix_inl_event_type type)
517 : : {
518 : 0 : switch (type) {
519 : : case NIX_INL_OUTB_CPT_CQ:
520 : : return "NIX_INL_OUTB_CPT_CQ";
521 : 0 : case NIX_INL_INB_CPT_CQ:
522 : 0 : return "NIX_INL_INB_CPT_CQ";
523 : 0 : case NIX_INL_SSO:
524 : 0 : return "NIX_INL_SSO";
525 : 0 : case NIX_INL_SOFT_EXPIRY_THRD:
526 : 0 : return "NIX_INL_SOFT_EXPIRY_THRD";
527 : :
528 : 0 : default:
529 : 0 : return "Unknown event";
530 : : }
531 : : }
532 : :
533 : : void
534 [ # # # # : 0 : cn20k_eth_sec_sso_work_cb(uint64_t *gw, void *args, enum nix_inl_event_type type, void *cq_s,
# ]
535 : : uint32_t port_id)
536 : : {
537 : : struct rte_eth_event_ipsec_desc desc;
538 : : struct cn20k_sec_sess_priv sess_priv;
539 : : struct cn20k_outb_priv_data *outb_priv;
540 : : struct roc_ow_ipsec_outb_sa *outb_sa;
541 : : struct rte_eth_dev *eth_dev = NULL;
542 : : struct rte_mbuf *mbuf = NULL;
543 : : struct cpt_cn20k_res_s *res;
544 : : struct cnxk_eth_dev *dev;
545 : : uint16_t dlen_adj, rlen;
546 : : uintptr_t sa_base;
547 : : uintptr_t nixtx;
548 : : bool free_mbuf;
549 : : uint8_t port;
550 : :
551 : 0 : plt_nix_dbg("Received %s event", get_inl_event_type(type));
552 : :
553 [ # # # ]: 0 : switch ((gw[0] >> 28) & 0xF) {
554 : 0 : case RTE_EVENT_TYPE_ETHDEV:
555 : : /* Event from inbound inline dev due to IPSEC packet bad L4 */
556 : 0 : mbuf = (struct rte_mbuf *)(gw[1] - sizeof(struct rte_mbuf));
557 : 0 : plt_nix_dbg("Received mbuf %p from inline dev inbound", mbuf);
558 : : cnxk_pktmbuf_free_no_cache(mbuf);
559 : 0 : return;
560 : 0 : case RTE_EVENT_TYPE_CPU:
561 : : /* Check for subtype */
562 [ # # ]: 0 : if (((gw[0] >> 20) & 0xFF) == CNXK_ETHDEV_SEC_OUTB_EV_SUB) {
563 : : /* Event from outbound inline error */
564 : 0 : mbuf = (struct rte_mbuf *)gw[1];
565 : : break;
566 : : }
567 : : /* Fall through */
568 : : default:
569 [ # # ]: 0 : if (type) {
570 : : struct cpt_cq_s *cqs = (struct cpt_cq_s *)cq_s;
571 : :
572 [ # # # # ]: 0 : if (type == NIX_INL_INB_CPT_CQ && cqs->w2.s.fmt != WQE_PTR_ANTI_REPLAY) {
573 : : struct cn20k_inb_priv_data *inb_priv;
574 : :
575 [ # # ]: 0 : inb_priv = args ? roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(args) : NULL;
576 [ # # # # ]: 0 : if (inb_priv && inb_priv->eth_sec && inb_priv->eth_sec->eth_dev) {
577 : : eth_dev = inb_priv->eth_sec->eth_dev;
578 : : } else {
579 : 0 : plt_nix_dbg("Inbound CPT CQ event: cc %x uc_cc %x fmt %x",
580 : : cqs->w0.s.compcode, cqs->w0.s.uc_compcode,
581 : : cqs->w2.s.fmt);
582 : 0 : return;
583 : : }
584 [ # # ]: 0 : } else if (type != NIX_INL_INB_CPT_CQ) {
585 [ # # ]: 0 : if (port_id >= RTE_MAX_ETHPORTS) {
586 : 0 : plt_err("CPT CQ event: invalid port_id %u", port_id);
587 : 0 : return;
588 : : }
589 : 0 : eth_dev = &rte_eth_devices[port_id];
590 : : }
591 : :
592 [ # # ]: 0 : if (type < NIX_INL_SSO) {
593 : 0 : mbuf = (struct rte_mbuf *)(uintptr_t)gw[1];
594 : :
595 : 0 : free_mbuf = cn20k_eth_sec_post_event(eth_dev, args,
596 : 0 : type, (uint16_t)cqs->w0.s.uc_compcode,
597 : 0 : (uint16_t)cqs->w0.s.compcode, mbuf);
598 : :
599 [ # # ]: 0 : if (free_mbuf)
600 : : cnxk_pktmbuf_free_no_cache(mbuf);
601 : 0 : return;
602 : : }
603 [ # # ]: 0 : if (type == NIX_INL_SOFT_EXPIRY_THRD) {
604 : : outb_sa = (struct roc_ow_ipsec_outb_sa *)args;
605 : : outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
606 : 0 : desc.metadata = (uint64_t)outb_priv->userdata;
607 [ # # ]: 0 : if (outb_sa->w2.s.life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
608 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
609 : : else
610 : 0 : desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
611 : : }
612 : 0 : rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_IPSEC, &desc);
613 : : } else {
614 : 0 : plt_err("Unknown event gw[0] = 0x%016lx, gw[1] = 0x%016lx", gw[0], gw[1]);
615 : : }
616 : : return;
617 : : }
618 : :
619 : : /* Get ethdev port from tag */
620 : 0 : port = gw[0] & 0xFF;
621 : 0 : eth_dev = &rte_eth_devices[port];
622 : : dev = cnxk_eth_pmd_priv(eth_dev);
623 : :
624 : 0 : sess_priv.u64 = *rte_security_dynfield(mbuf);
625 : : /* Calculate dlen adj */
626 : 0 : dlen_adj = mbuf->pkt_len - mbuf->l2_len;
627 : 0 : rlen = (dlen_adj + sess_priv.roundup_len) + (sess_priv.roundup_byte - 1);
628 : 0 : rlen &= ~(uint64_t)(sess_priv.roundup_byte - 1);
629 : 0 : rlen += sess_priv.partial_len;
630 : 0 : dlen_adj = rlen - dlen_adj;
631 : :
632 : : /* Find the res area residing on next cacheline after end of data */
633 : 0 : nixtx = rte_pktmbuf_mtod(mbuf, uintptr_t) + mbuf->pkt_len + dlen_adj;
634 : : nixtx += BIT_ULL(7);
635 : 0 : nixtx = (nixtx - 1) & ~(BIT_ULL(7) - 1);
636 : 0 : res = (struct cpt_cn20k_res_s *)nixtx;
637 : :
638 : 0 : plt_nix_dbg("Outbound error, mbuf %p, sa_index %u, compcode %x uc %x", mbuf,
639 : : sess_priv.sa_idx, res->compcode, res->uc_compcode);
640 : :
641 : 0 : sess_priv.u64 = *rte_security_dynfield(mbuf);
642 : :
643 : 0 : sa_base = dev->outb.sa_base;
644 : 0 : outb_sa = roc_nix_inl_ow_ipsec_outb_sa(sa_base, sess_priv.sa_idx);
645 : :
646 : 0 : cn20k_eth_sec_post_event(eth_dev, outb_sa, type, res->uc_compcode, res->compcode, mbuf);
647 : :
648 : : cnxk_pktmbuf_free_no_cache(mbuf);
649 : : }
650 : :
651 : : static void
652 : 0 : outb_dbg_iv_update(struct roc_ow_ipsec_outb_sa *outb_sa, const char *__iv_str)
653 : : {
654 : 0 : uint8_t *iv_dbg = outb_sa->iv.iv_dbg;
655 : 0 : char *iv_str = strdup(__iv_str);
656 : : char *iv_b = NULL, len = 16;
657 : : char *save;
658 : : int i;
659 : :
660 [ # # ]: 0 : if (!iv_str)
661 : 0 : return;
662 : :
663 [ # # ]: 0 : if (outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM ||
664 : 0 : outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_CTR ||
665 [ # # ]: 0 : outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_CCM ||
666 [ # # ]: 0 : outb_sa->w2.s.auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
667 : 0 : memset(outb_sa->iv.s.iv_dbg1, 0, sizeof(outb_sa->iv.s.iv_dbg1));
668 : 0 : memset(outb_sa->iv.s.iv_dbg2, 0, sizeof(outb_sa->iv.s.iv_dbg2));
669 : :
670 : : iv_dbg = outb_sa->iv.s.iv_dbg1;
671 [ # # ]: 0 : for (i = 0; i < 4; i++) {
672 [ # # ]: 0 : iv_b = strtok_r(i ? NULL : iv_str, ",", &save);
673 [ # # ]: 0 : if (!iv_b)
674 : : break;
675 : 0 : iv_dbg[i] = strtoul(iv_b, NULL, 0);
676 : : }
677 [ # # ]: 0 : *(uint32_t *)iv_dbg = rte_be_to_cpu_32(*(uint32_t *)iv_dbg);
678 : :
679 : : iv_dbg = outb_sa->iv.s.iv_dbg2;
680 [ # # ]: 0 : for (i = 0; i < 4; i++) {
681 : 0 : iv_b = strtok_r(NULL, ",", &save);
682 [ # # ]: 0 : if (!iv_b)
683 : : break;
684 : 0 : iv_dbg[i] = strtoul(iv_b, NULL, 0);
685 : : }
686 [ # # ]: 0 : *(uint32_t *)iv_dbg = rte_be_to_cpu_32(*(uint32_t *)iv_dbg);
687 : :
688 : : } else {
689 : : iv_dbg = outb_sa->iv.iv_dbg;
690 : : memset(iv_dbg, 0, sizeof(outb_sa->iv.iv_dbg));
691 : :
692 [ # # ]: 0 : for (i = 0; i < len; i++) {
693 [ # # ]: 0 : iv_b = strtok_r(i ? NULL : iv_str, ",", &save);
694 [ # # ]: 0 : if (!iv_b)
695 : : break;
696 : 0 : iv_dbg[i] = strtoul(iv_b, NULL, 0);
697 : : }
698 [ # # ]: 0 : *(uint64_t *)iv_dbg = rte_be_to_cpu_64(*(uint64_t *)iv_dbg);
699 [ # # ]: 0 : *(uint64_t *)&iv_dbg[8] = rte_be_to_cpu_64(*(uint64_t *)&iv_dbg[8]);
700 : : }
701 : :
702 : : /* Update source of IV */
703 : 0 : outb_sa->w2.s.iv_src = ROC_IE_OW_SA_IV_SRC_FROM_SA;
704 : 0 : free(iv_str);
705 : : }
706 : :
707 : : static void
708 : 0 : cn20k_eth_sec_inb_sa_misc_fill(struct roc_ow_ipsec_inb_sa *sa,
709 : : struct rte_security_ipsec_xform *ipsec_xfrm)
710 : : {
711 : : struct roc_ow_ipsec_inb_ctx_update_reg *ctx;
712 : : size_t offset;
713 : :
714 [ # # ]: 0 : if (sa->w2.s.enc_type != ROC_IE_SA_ENC_AES_GCM)
715 : : return;
716 : :
717 : : /* Update ctx push size for AES GCM */
718 : : offset = offsetof(struct roc_ow_ipsec_inb_sa, hmac_opad_ipad);
719 : : ctx = (struct roc_ow_ipsec_inb_ctx_update_reg *)((uint8_t *)sa + offset);
720 : 0 : sa->w0.s.hw_ctx_off = offset / 8;
721 : 0 : sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
722 : :
723 [ # # ]: 0 : if (ipsec_xfrm->life.bytes_soft_limit)
724 : 0 : ctx->soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
725 : :
726 [ # # ]: 0 : if (ipsec_xfrm->life.packets_soft_limit)
727 : 0 : ctx->soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
728 : :
729 [ # # ]: 0 : if (ipsec_xfrm->life.bytes_hard_limit)
730 : 0 : ctx->hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
731 : :
732 [ # # ]: 0 : if (ipsec_xfrm->life.packets_hard_limit)
733 : 0 : ctx->hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
734 : : }
735 : :
736 : : static int
737 : 0 : cn20k_eth_sec_outb_sa_misc_fill(struct roc_nix *roc_nix, struct roc_ow_ipsec_outb_sa *sa,
738 : : void *sa_cptr, struct rte_security_ipsec_xform *ipsec_xfrm,
739 : : uint32_t sa_idx)
740 : : {
741 : : struct roc_ow_ipsec_outb_ctx_update_reg *ctx;
742 : : uint64_t *ring_base, ring_addr;
743 : : size_t offset;
744 : :
745 [ # # ]: 0 : if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
746 : : offset = offsetof(struct roc_ow_ipsec_outb_sa, hmac_opad_ipad);
747 : 0 : ctx = (struct roc_ow_ipsec_outb_ctx_update_reg *)((uint8_t *)sa + offset);
748 : 0 : sa->w0.s.hw_ctx_off = offset / 8;
749 : 0 : sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
750 : :
751 [ # # ]: 0 : if (ipsec_xfrm->esn.value)
752 : 0 : ctx->esn_val = ipsec_xfrm->esn.value - 1;
753 : :
754 [ # # ]: 0 : if (ipsec_xfrm->life.bytes_soft_limit)
755 : 0 : ctx->soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
756 : :
757 [ # # ]: 0 : if (ipsec_xfrm->life.packets_soft_limit)
758 : 0 : ctx->soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
759 : :
760 [ # # ]: 0 : if (ipsec_xfrm->life.bytes_hard_limit)
761 : 0 : ctx->hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
762 : :
763 [ # # ]: 0 : if (ipsec_xfrm->life.packets_hard_limit)
764 : 0 : ctx->hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
765 : : } else {
766 : 0 : ctx = &sa->ctx;
767 : : }
768 : :
769 [ # # ]: 0 : if (roc_nix_inl_is_cq_ena(roc_nix))
770 : 0 : goto done;
771 : :
772 [ # # ]: 0 : if (ipsec_xfrm->life.bytes_soft_limit | ipsec_xfrm->life.packets_soft_limit) {
773 : 0 : ring_base = roc_nix_inl_outb_ring_base_get(roc_nix);
774 [ # # ]: 0 : if (ring_base == NULL)
775 : : return -ENOTSUP;
776 : :
777 : 0 : ring_addr = ring_base[sa_idx >> ROC_NIX_SOFT_EXP_ERR_RING_MAX_ENTRY_LOG2];
778 : 0 : ctx->err_ctl.s.mode = ROC_IE_OW_ERR_CTL_MODE_RING;
779 : 0 : ctx->err_ctl.s.address = ring_addr >> 3;
780 : 0 : sa->w0.s.ctx_id = ((uintptr_t)sa_cptr >> 51) & 0x1ff;
781 : : }
782 : 0 : done:
783 : : return 0;
784 : : }
785 : :
786 : : static int
787 [ # # ]: 0 : cn20k_eth_sec_session_create(void *device, struct rte_security_session_conf *conf,
788 : : struct rte_security_session *sess)
789 : : {
790 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
791 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
792 : : struct rte_security_ipsec_xform *ipsec;
793 : : struct cn20k_sec_sess_priv sess_priv;
794 : : struct rte_crypto_sym_xform *crypto;
795 : 0 : struct cnxk_eth_sec_sess *eth_sec = SECURITY_GET_SESS_PRIV(sess);
796 : 0 : struct roc_nix *nix = &dev->nix;
797 : : bool inbound, inl_dev;
798 : : rte_spinlock_t *lock;
799 : 0 : char tbuf[128] = {0};
800 : : int rc = 0;
801 : :
802 [ # # ]: 0 : if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
803 : : return -ENOTSUP;
804 : :
805 [ # # ]: 0 : if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
806 : : return -ENOTSUP;
807 : :
808 [ # # ]: 0 : if (rte_security_dynfield_register() < 0)
809 : : return -ENOTSUP;
810 : :
811 [ # # # # ]: 0 : if (conf->ipsec.options.ip_reassembly_en && dev->reass_dynfield_off < 0) {
812 [ # # ]: 0 : if (rte_eth_ip_reassembly_dynfield_register(&dev->reass_dynfield_off,
813 : : &dev->reass_dynflag_bit) < 0)
814 : 0 : return -rte_errno;
815 : : }
816 : :
817 [ # # # # ]: 0 : if (conf->ipsec.options.ingress_oop && rte_security_oop_dynfield_offset < 0) {
818 : : /* Register for security OOP dynfield if required */
819 [ # # ]: 0 : if (rte_security_oop_dynfield_register() < 0)
820 : 0 : return -rte_errno;
821 : : }
822 : :
823 : : /* We cannot support inbound reassembly and OOP together */
824 [ # # ]: 0 : if (conf->ipsec.options.ip_reassembly_en && conf->ipsec.options.ingress_oop) {
825 : 0 : plt_err("Cannot support Inbound reassembly and OOP together");
826 : 0 : return -ENOTSUP;
827 : : }
828 : :
829 : 0 : ipsec = &conf->ipsec;
830 : 0 : crypto = conf->crypto_xform;
831 : :
832 [ # # # # ]: 0 : if (nix->custom_inb_sa && ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
833 : : return -ENOTSUP;
834 : :
835 : 0 : rc = cnxk_ipsec_xform_verify(ipsec, crypto);
836 [ # # ]: 0 : if (rc) {
837 : 0 : plt_err("Crypto xform verify failed, rc=%d", rc);
838 : 0 : return rc;
839 : : }
840 : :
841 : 0 : inbound = !!(ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS);
842 [ # # ]: 0 : inl_dev = !!dev->inb.inl_dev;
843 : :
844 : : memset(eth_sec, 0, sizeof(struct cnxk_eth_sec_sess));
845 : 0 : eth_sec->eth_dev = eth_dev;
846 : 0 : sess_priv.u64 = 0;
847 : :
848 [ # # ]: 0 : lock = inbound ? &dev->inb.lock : &dev->outb.lock;
849 : : rte_spinlock_lock(lock);
850 : :
851 : : /* Acquire lock on inline dev for inbound */
852 [ # # ]: 0 : if (inbound && inl_dev)
853 : 0 : roc_nix_inl_dev_lock();
854 : :
855 [ # # ]: 0 : if (inbound) {
856 : : struct roc_ow_ipsec_inb_sa *inb_sa, *inb_sa_dptr;
857 : : struct cn20k_inb_priv_data *inb_priv;
858 : : uint32_t spi_mask;
859 : : uintptr_t sa;
860 : :
861 : : PLT_STATIC_ASSERT(sizeof(struct cn20k_inb_priv_data) <
862 : : ROC_NIX_INL_OW_IPSEC_INB_SW_RSVD);
863 : :
864 : 0 : spi_mask = roc_nix_inl_inb_spi_range(nix, inl_dev, NULL, NULL);
865 : :
866 : : /* Search if a session already exits */
867 [ # # ]: 0 : if (cnxk_eth_sec_sess_get_by_sa_idx(dev, ipsec->spi & spi_mask, true)) {
868 : 0 : plt_err("Inbound SA with SPI/SA index %u already in use", ipsec->spi);
869 : : rc = -EEXIST;
870 : 0 : goto err;
871 : : }
872 : :
873 : : /* Get Inbound SA from NIX_RX_IPSEC_SA_BASE */
874 : 0 : sa = roc_nix_inl_inb_sa_get(nix, inl_dev, ipsec->spi);
875 [ # # # # ]: 0 : if (!sa && dev->inb.inl_dev) {
876 : : snprintf(tbuf, sizeof(tbuf),
877 : : "Failed to create ingress sa, inline dev "
878 : : "not found or spi not in range");
879 : : rc = -ENOTSUP;
880 : 0 : goto err;
881 [ # # ]: 0 : } else if (!sa) {
882 : : snprintf(tbuf, sizeof(tbuf), "Failed to create ingress sa");
883 : : rc = -EFAULT;
884 : 0 : goto err;
885 : : }
886 : :
887 : 0 : inb_sa = (struct roc_ow_ipsec_inb_sa *)sa;
888 : :
889 : : /* Check if SA is already in use */
890 [ # # ]: 0 : if (inb_sa->w2.s.valid) {
891 : 0 : snprintf(tbuf, sizeof(tbuf), "Inbound SA with SPI %u already in use",
892 : : ipsec->spi);
893 : : rc = -EBUSY;
894 : 0 : goto err;
895 : : }
896 : :
897 : 0 : inb_sa_dptr = (struct roc_ow_ipsec_inb_sa *)dev->inb.sa_dptr;
898 : : memset(inb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_inb_sa));
899 : :
900 : : /* Fill inbound sa params */
901 : 0 : rc = cnxk_ow_ipsec_inb_sa_fill(inb_sa_dptr, ipsec, crypto, 0);
902 [ # # ]: 0 : if (rc) {
903 : : snprintf(tbuf, sizeof(tbuf), "Failed to init inbound sa, rc=%d", rc);
904 : 0 : goto err;
905 : : }
906 : :
907 : 0 : rc = roc_npc_skip_size_pkind_get(&dev->npc);
908 [ # # ]: 0 : if (rc >= 0)
909 : 0 : inb_sa_dptr->w0.s.pkind = rc;
910 : :
911 : 0 : cn20k_eth_sec_inb_sa_misc_fill(inb_sa_dptr, ipsec);
912 : :
913 : : inb_priv = roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(inb_sa);
914 : : /* Back pointer to get eth_sec */
915 : 0 : inb_priv->eth_sec = eth_sec;
916 : : /* Save userdata in inb private area */
917 : 0 : inb_priv->userdata = conf->userdata;
918 : :
919 : : /* Save SA index/SPI in cookie for now */
920 : 0 : inb_sa_dptr->w1.s.cookie = ipsec->spi & spi_mask;
921 : :
922 [ # # ]: 0 : if (ipsec->options.stats == 1) {
923 : : /* Enable mib counters */
924 : 0 : inb_sa_dptr->w0.s.count_mib_bytes = 1;
925 : 0 : inb_sa_dptr->w0.s.count_mib_pkts = 1;
926 : : }
927 : :
928 : : /* Prepare session priv */
929 : 0 : sess_priv.inb_sa = 1;
930 : 0 : sess_priv.sa_idx = ipsec->spi & spi_mask;
931 : :
932 : : /* Pointer from eth_sec -> inb_sa */
933 : 0 : eth_sec->sa = inb_sa;
934 : 0 : eth_sec->sess = sess;
935 : 0 : eth_sec->sa_idx = ipsec->spi & spi_mask;
936 : 0 : eth_sec->spi = ipsec->spi;
937 : 0 : eth_sec->inl_dev = !!dev->inb.inl_dev;
938 : 0 : eth_sec->inb = true;
939 : 0 : eth_sec->inb_oop = !!ipsec->options.ingress_oop;
940 : :
941 : 0 : TAILQ_INSERT_TAIL(&dev->inb.list, eth_sec, entry);
942 : 0 : dev->inb.nb_sess++;
943 : : /* Sync session in context cache */
944 : 0 : rc = roc_nix_inl_ctx_write(&dev->nix, inb_sa_dptr, eth_sec->sa, eth_sec->inb,
945 : : sizeof(struct roc_ow_ipsec_inb_sa));
946 [ # # ]: 0 : if (rc)
947 : 0 : goto err;
948 : :
949 [ # # ]: 0 : if (conf->ipsec.options.ip_reassembly_en) {
950 : 0 : inb_priv->reass_dynfield_off = dev->reass_dynfield_off;
951 : 0 : inb_priv->reass_dynflag_bit = dev->reass_dynflag_bit;
952 : : }
953 : :
954 [ # # ]: 0 : if (ipsec->options.ingress_oop)
955 : 0 : dev->inb.nb_oop++;
956 : :
957 : : /* Update function pointer to handle OOP sessions */
958 [ # # # # ]: 0 : if (dev->inb.nb_oop && !(dev->rx_offload_flags & NIX_RX_REAS_F)) {
959 : 0 : dev->rx_offload_flags |= NIX_RX_REAS_F;
960 : 0 : cn20k_eth_set_rx_function(eth_dev);
961 [ # # ]: 0 : if (cnxk_ethdev_rx_offload_cb)
962 : 0 : cnxk_ethdev_rx_offload_cb(eth_dev->data->port_id, NIX_RX_REAS_F);
963 : : }
964 : : } else {
965 : : struct roc_ow_ipsec_outb_sa *outb_sa, *outb_sa_dptr;
966 : : struct cn20k_outb_priv_data *outb_priv;
967 : : struct cnxk_ipsec_outb_rlens *rlens;
968 : 0 : uint64_t sa_base = dev->outb.sa_base;
969 : : const char *iv_str;
970 : : uint32_t sa_idx;
971 : :
972 : : PLT_STATIC_ASSERT(sizeof(struct cn20k_outb_priv_data) <
973 : : ROC_NIX_INL_OW_IPSEC_OUTB_SW_RSVD);
974 : :
975 : : /* Alloc an sa index */
976 : 0 : rc = cnxk_eth_outb_sa_idx_get(dev, &sa_idx, ipsec->spi);
977 [ # # ]: 0 : if (rc)
978 : 0 : goto err;
979 : :
980 : 0 : outb_sa = roc_nix_inl_ow_ipsec_outb_sa(sa_base, sa_idx);
981 : : outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
982 : 0 : rlens = &outb_priv->rlens;
983 : :
984 : 0 : outb_sa_dptr = (struct roc_ow_ipsec_outb_sa *)dev->outb.sa_dptr;
985 : : memset(outb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_outb_sa));
986 : :
987 : : /* Fill outbound sa params */
988 : 0 : rc = cnxk_ow_ipsec_outb_sa_fill(outb_sa_dptr, ipsec, crypto, 0);
989 [ # # ]: 0 : if (rc) {
990 : : snprintf(tbuf, sizeof(tbuf), "Failed to init outbound sa, rc=%d", rc);
991 : 0 : rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
992 : 0 : goto err;
993 : : }
994 : :
995 [ # # ]: 0 : if (conf->ipsec.options.iv_gen_disable == 1) {
996 : 0 : iv_str = getenv("ETH_SEC_IV_OVR");
997 [ # # ]: 0 : if (iv_str)
998 : 0 : outb_dbg_iv_update(outb_sa_dptr, iv_str);
999 : : }
1000 : : /* Fill outbound sa misc params */
1001 : 0 : rc = cn20k_eth_sec_outb_sa_misc_fill(&dev->nix, outb_sa_dptr, outb_sa, ipsec,
1002 : : sa_idx);
1003 [ # # ]: 0 : if (rc) {
1004 : : snprintf(tbuf, sizeof(tbuf), "Failed to init outb sa misc params, rc=%d",
1005 : : rc);
1006 : 0 : rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
1007 : 0 : goto err;
1008 : : }
1009 : :
1010 : : /* Save userdata */
1011 : 0 : outb_priv->userdata = conf->userdata;
1012 : 0 : outb_priv->sa_idx = sa_idx;
1013 : 0 : outb_priv->eth_sec = eth_sec;
1014 : :
1015 : : /* Save rlen info */
1016 : 0 : cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
1017 : :
1018 [ # # ]: 0 : if (ipsec->options.stats == 1) {
1019 : : /* Enable mib counters */
1020 : 0 : outb_sa_dptr->w0.s.count_mib_bytes = 1;
1021 : 0 : outb_sa_dptr->w0.s.count_mib_pkts = 1;
1022 : : }
1023 : :
1024 : : /* Prepare session priv */
1025 : 0 : sess_priv.sa_idx = outb_priv->sa_idx;
1026 : 0 : sess_priv.roundup_byte = rlens->roundup_byte;
1027 : 0 : sess_priv.roundup_len = rlens->roundup_len;
1028 : 0 : sess_priv.partial_len = rlens->partial_len;
1029 : 0 : sess_priv.mode = outb_sa_dptr->w2.s.ipsec_mode;
1030 : 0 : sess_priv.outer_ip_ver = outb_sa_dptr->w2.s.outer_ip_ver;
1031 : : /* Propagate inner checksum enable from SA to fast path */
1032 : 0 : sess_priv.chksum =
1033 [ # # ]: 0 : (!ipsec->options.ip_csum_enable << 1 | !ipsec->options.l4_csum_enable);
1034 : 0 : sess_priv.dec_ttl = ipsec->options.dec_ttl;
1035 : 0 : sess_priv.cpt_cq_ena = roc_nix_inl_is_cq_ena(&dev->nix);
1036 : :
1037 : : /* Pointer from eth_sec -> outb_sa */
1038 : 0 : eth_sec->sa = outb_sa;
1039 : 0 : eth_sec->sess = sess;
1040 : 0 : eth_sec->sa_idx = sa_idx;
1041 : 0 : eth_sec->spi = ipsec->spi;
1042 : :
1043 : 0 : TAILQ_INSERT_TAIL(&dev->outb.list, eth_sec, entry);
1044 : 0 : dev->outb.nb_sess++;
1045 : : /* Sync session in context cache */
1046 : 0 : rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa_dptr, eth_sec->sa, eth_sec->inb,
1047 : : sizeof(struct roc_ow_ipsec_outb_sa));
1048 [ # # ]: 0 : if (rc)
1049 : 0 : goto err;
1050 : : }
1051 [ # # ]: 0 : if (inbound && inl_dev)
1052 : 0 : roc_nix_inl_dev_unlock();
1053 : : rte_spinlock_unlock(lock);
1054 : :
1055 [ # # ]: 0 : plt_nix_dbg("Created %s session with spi=%u, sa_idx=%u inl_dev=%u",
1056 : : inbound ? "inbound" : "outbound", eth_sec->spi, eth_sec->sa_idx,
1057 : : eth_sec->inl_dev);
1058 : : /*
1059 : : * Update fast path info in priv area.
1060 : : */
1061 : 0 : sess->fast_mdata = sess_priv.u64;
1062 : :
1063 : 0 : return 0;
1064 : 0 : err:
1065 [ # # ]: 0 : if (inbound && inl_dev)
1066 : 0 : roc_nix_inl_dev_unlock();
1067 : : rte_spinlock_unlock(lock);
1068 : :
1069 [ # # ]: 0 : if (rc)
1070 : 0 : plt_err("%s", tbuf);
1071 : : return rc;
1072 : : }
1073 : :
1074 : : static int
1075 : 0 : cn20k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
1076 : : {
1077 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
1078 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1079 : : struct cnxk_eth_sec_sess *eth_sec;
1080 : : rte_spinlock_t *lock;
1081 : : void *sa_dptr;
1082 : :
1083 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
1084 [ # # ]: 0 : if (!eth_sec)
1085 : : return -ENOENT;
1086 [ # # # # ]: 0 : if (dev->nix.custom_inb_sa && eth_sec->inb)
1087 : : return -ENOTSUP;
1088 : :
1089 [ # # ]: 0 : lock = eth_sec->inb ? &dev->inb.lock : &dev->outb.lock;
1090 : : rte_spinlock_lock(lock);
1091 : :
1092 [ # # ]: 0 : if (eth_sec->inl_dev)
1093 : 0 : roc_nix_inl_dev_lock();
1094 : :
1095 [ # # ]: 0 : if (eth_sec->inb) {
1096 : : /* Disable SA */
1097 : 0 : sa_dptr = dev->inb.sa_dptr;
1098 : 0 : roc_ow_ipsec_inb_sa_init(sa_dptr);
1099 : :
1100 : 0 : roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa, eth_sec->inb,
1101 : : sizeof(struct roc_ow_ipsec_inb_sa));
1102 [ # # ]: 0 : TAILQ_REMOVE(&dev->inb.list, eth_sec, entry);
1103 : 0 : dev->inb.nb_sess--;
1104 [ # # ]: 0 : if (eth_sec->inb_oop)
1105 : 0 : dev->inb.nb_oop--;
1106 : :
1107 : : /* Clear offload flags if was used by OOP */
1108 [ # # # # ]: 0 : if (!dev->inb.nb_oop && !dev->inb.reass_en &&
1109 [ # # ]: 0 : dev->rx_offload_flags & NIX_RX_REAS_F) {
1110 : 0 : dev->rx_offload_flags &= ~NIX_RX_REAS_F;
1111 : 0 : cn20k_eth_set_rx_function(eth_dev);
1112 : : }
1113 : : } else {
1114 : : /* Disable SA */
1115 : 0 : sa_dptr = dev->outb.sa_dptr;
1116 : 0 : roc_ow_ipsec_outb_sa_init(sa_dptr);
1117 : :
1118 : 0 : roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa, eth_sec->inb,
1119 : : sizeof(struct roc_ow_ipsec_outb_sa));
1120 : : /* Release Outbound SA index */
1121 : 0 : cnxk_eth_outb_sa_idx_put(dev, eth_sec->sa_idx);
1122 [ # # ]: 0 : TAILQ_REMOVE(&dev->outb.list, eth_sec, entry);
1123 : 0 : dev->outb.nb_sess--;
1124 : : }
1125 [ # # ]: 0 : if (eth_sec->inl_dev)
1126 : 0 : roc_nix_inl_dev_unlock();
1127 : :
1128 : : rte_spinlock_unlock(lock);
1129 : :
1130 [ # # ]: 0 : plt_nix_dbg("Destroyed %s session with spi=%u, sa_idx=%u, inl_dev=%u",
1131 : : eth_sec->inb ? "inbound" : "outbound", eth_sec->spi, eth_sec->sa_idx,
1132 : : eth_sec->inl_dev);
1133 : :
1134 : 0 : return 0;
1135 : : }
1136 : :
1137 : : static const struct rte_security_capability *
1138 : 0 : cn20k_eth_sec_capabilities_get(void *device __rte_unused)
1139 : : {
1140 : 0 : return cn20k_eth_sec_capabilities;
1141 : : }
1142 : :
1143 : : static int
1144 [ # # ]: 0 : cn20k_eth_sec_session_update(void *device, struct rte_security_session *sess,
1145 : : struct rte_security_session_conf *conf)
1146 : : {
1147 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
1148 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1149 : : struct rte_security_ipsec_xform *ipsec;
1150 : : struct cn20k_sec_sess_priv sess_priv;
1151 : : struct rte_crypto_sym_xform *crypto;
1152 : : struct cnxk_eth_sec_sess *eth_sec;
1153 : : bool inbound;
1154 : : int rc;
1155 : :
1156 [ # # ]: 0 : if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ||
1157 : : conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
1158 : : return -ENOENT;
1159 : :
1160 : 0 : ipsec = &conf->ipsec;
1161 : 0 : crypto = conf->crypto_xform;
1162 : 0 : inbound = !!(ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS);
1163 : :
1164 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
1165 [ # # ]: 0 : if (!eth_sec)
1166 : : return -ENOENT;
1167 : :
1168 : 0 : eth_sec->spi = conf->ipsec.spi;
1169 : :
1170 [ # # ]: 0 : if (inbound) {
1171 : : struct roc_ow_ipsec_inb_sa *inb_sa_dptr, *inb_sa;
1172 : : struct cn20k_inb_priv_data *inb_priv;
1173 : :
1174 : 0 : inb_sa = eth_sec->sa;
1175 : : inb_priv = roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(inb_sa);
1176 : 0 : inb_sa_dptr = (struct roc_ow_ipsec_inb_sa *)dev->inb.sa_dptr;
1177 : : memset(inb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_inb_sa));
1178 : :
1179 : 0 : rc = cnxk_ow_ipsec_inb_sa_fill(inb_sa_dptr, ipsec, crypto, 0);
1180 [ # # ]: 0 : if (rc)
1181 : : return -EINVAL;
1182 : :
1183 : 0 : rc = roc_npc_skip_size_pkind_get(&dev->npc);
1184 [ # # ]: 0 : if (rc >= 0)
1185 : 0 : inb_sa_dptr->w0.s.pkind = rc;
1186 : :
1187 : 0 : cn20k_eth_sec_inb_sa_misc_fill(inb_sa_dptr, ipsec);
1188 : :
1189 : : /* Use cookie for original data */
1190 : 0 : inb_sa_dptr->w1.s.cookie = inb_sa->w1.s.cookie;
1191 : :
1192 [ # # ]: 0 : if (ipsec->options.stats == 1) {
1193 : : /* Enable mib counters */
1194 : 0 : inb_sa_dptr->w0.s.count_mib_bytes = 1;
1195 : 0 : inb_sa_dptr->w0.s.count_mib_pkts = 1;
1196 : : }
1197 : :
1198 : 0 : rc = roc_nix_inl_ctx_write(&dev->nix, inb_sa_dptr, eth_sec->sa, eth_sec->inb,
1199 : : sizeof(struct roc_ow_ipsec_inb_sa));
1200 [ # # ]: 0 : if (rc)
1201 : : return -EINVAL;
1202 : :
1203 : : /* Save userdata in inb private area */
1204 : 0 : inb_priv->userdata = conf->userdata;
1205 : : } else {
1206 : : struct roc_ow_ipsec_outb_sa *outb_sa_dptr, *outb_sa;
1207 : : struct cn20k_outb_priv_data *outb_priv;
1208 : : struct cnxk_ipsec_outb_rlens *rlens;
1209 : :
1210 : 0 : outb_sa = eth_sec->sa;
1211 : : outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
1212 : 0 : rlens = &outb_priv->rlens;
1213 : 0 : outb_sa_dptr = (struct roc_ow_ipsec_outb_sa *)dev->outb.sa_dptr;
1214 : : memset(outb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_outb_sa));
1215 : :
1216 : 0 : rc = cnxk_ow_ipsec_outb_sa_fill(outb_sa_dptr, ipsec, crypto, 0);
1217 [ # # ]: 0 : if (rc)
1218 : : return -EINVAL;
1219 : :
1220 : : /* Fill outbound sa misc params */
1221 : 0 : rc = cn20k_eth_sec_outb_sa_misc_fill(&dev->nix, outb_sa_dptr, outb_sa, ipsec,
1222 : : eth_sec->sa_idx);
1223 [ # # ]: 0 : if (rc) {
1224 : 0 : plt_err("Failed to init outb sa misc params, rc=%d", rc);
1225 : 0 : return rc;
1226 : : }
1227 : :
1228 : : /* Save rlen info */
1229 : 0 : cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
1230 : :
1231 [ # # ]: 0 : if (ipsec->options.stats == 1) {
1232 : : /* Enable mib counters */
1233 : 0 : outb_sa_dptr->w0.s.count_mib_bytes = 1;
1234 : 0 : outb_sa_dptr->w0.s.count_mib_pkts = 1;
1235 : : }
1236 : :
1237 : 0 : sess_priv.u64 = 0;
1238 : 0 : sess_priv.sa_idx = outb_priv->sa_idx;
1239 : 0 : sess_priv.roundup_byte = rlens->roundup_byte;
1240 : 0 : sess_priv.roundup_len = rlens->roundup_len;
1241 : 0 : sess_priv.partial_len = rlens->partial_len;
1242 : 0 : sess_priv.mode = outb_sa_dptr->w2.s.ipsec_mode;
1243 : 0 : sess_priv.outer_ip_ver = outb_sa_dptr->w2.s.outer_ip_ver;
1244 : : /* Propagate inner checksum enable from SA to fast path */
1245 : 0 : sess_priv.chksum =
1246 [ # # ]: 0 : (!ipsec->options.ip_csum_enable << 1 | !ipsec->options.l4_csum_enable);
1247 : 0 : sess_priv.dec_ttl = ipsec->options.dec_ttl;
1248 : :
1249 : 0 : sess_priv.cpt_cq_ena = roc_nix_inl_is_cq_ena(&dev->nix);
1250 : 0 : rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa_dptr, eth_sec->sa, eth_sec->inb,
1251 : : sizeof(struct roc_ow_ipsec_outb_sa));
1252 [ # # ]: 0 : if (rc)
1253 : : return -EINVAL;
1254 : :
1255 : : /* Save userdata */
1256 : 0 : outb_priv->userdata = conf->userdata;
1257 : 0 : sess->fast_mdata = sess_priv.u64;
1258 : : }
1259 : :
1260 : : return 0;
1261 : : }
1262 : :
1263 : : static int
1264 : 0 : cn20k_eth_sec_session_stats_get(void *device, struct rte_security_session *sess,
1265 : : struct rte_security_stats *stats)
1266 : : {
1267 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
1268 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1269 : : struct cnxk_eth_sec_sess *eth_sec;
1270 : : size_t offset;
1271 : : int rc;
1272 : :
1273 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
1274 [ # # ]: 0 : if (eth_sec == NULL)
1275 : : return -EINVAL;
1276 : :
1277 : 0 : rc = roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb, ROC_NIX_INL_SA_OP_FLUSH);
1278 [ # # ]: 0 : if (rc)
1279 : : return -EINVAL;
1280 : : rte_delay_ms(1);
1281 : :
1282 : 0 : stats->protocol = RTE_SECURITY_PROTOCOL_IPSEC;
1283 : :
1284 [ # # ]: 0 : if (eth_sec->inb) {
1285 : 0 : struct roc_ow_ipsec_inb_sa *sa = (struct roc_ow_ipsec_inb_sa *)eth_sec->sa;
1286 : : struct roc_ow_ipsec_inb_ctx_update_reg *ctx;
1287 : :
1288 [ # # ]: 0 : if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
1289 : : offset = offsetof(struct roc_ow_ipsec_inb_sa, hmac_opad_ipad);
1290 : 0 : ctx = (struct roc_ow_ipsec_inb_ctx_update_reg *)((uint8_t *)sa + offset);
1291 : : } else {
1292 : 0 : ctx = &sa->ctx;
1293 : : }
1294 : :
1295 : 0 : stats->ipsec.ipackets = ctx->mib_pkts;
1296 : 0 : stats->ipsec.ibytes = ctx->mib_octs;
1297 : : } else {
1298 : 0 : struct roc_ow_ipsec_outb_sa *sa = (struct roc_ow_ipsec_outb_sa *)eth_sec->sa;
1299 : : struct roc_ow_ipsec_outb_ctx_update_reg *ctx;
1300 : :
1301 [ # # ]: 0 : if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
1302 : : offset = offsetof(struct roc_ow_ipsec_outb_sa, hmac_opad_ipad);
1303 : 0 : ctx = (struct roc_ow_ipsec_outb_ctx_update_reg *)((uint8_t *)sa + offset);
1304 : : } else {
1305 : 0 : ctx = &sa->ctx;
1306 : : }
1307 : :
1308 : 0 : stats->ipsec.opackets = ctx->mib_pkts;
1309 : 0 : stats->ipsec.obytes = ctx->mib_octs;
1310 : : }
1311 : :
1312 : : return 0;
1313 : : }
1314 : :
1315 : : static void
1316 : 0 : eth_sec_caps_add(struct rte_security_capability eth_sec_caps[], uint32_t *idx,
1317 : : const struct rte_security_capability *caps, uint32_t nb_caps)
1318 : : {
1319 [ # # ]: 0 : PLT_VERIFY(*idx + nb_caps < SEC_CAPS_LEN);
1320 : :
1321 [ # # ]: 0 : rte_memcpy(ð_sec_caps[*idx], caps, nb_caps * sizeof(caps[0]));
1322 : 0 : *idx += nb_caps;
1323 : 0 : }
1324 : :
1325 : : static uint16_t __rte_hot
1326 : 0 : cn20k_eth_sec_inb_rx_inject(void *device, struct rte_mbuf **pkts,
1327 : : struct rte_security_session **sess, uint16_t nb_pkts)
1328 : : {
1329 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
1330 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1331 : :
1332 : 0 : return cn20k_nix_inj_pkts(sess, &dev->inj_cfg, pkts, nb_pkts);
1333 : : }
1334 : :
1335 : : static int
1336 : 0 : cn20k_eth_sec_rx_inject_config(void *device, uint16_t port_id, bool enable)
1337 : : {
1338 : : struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
1339 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1340 : : uint64_t channel, pf_func, inj_match_id = 0xFFFFUL;
1341 : : struct cnxk_ethdev_inj_cfg *inj_cfg;
1342 : 0 : struct roc_nix *nix = &dev->nix;
1343 : : struct roc_cpt_lf *inl_lf;
1344 : : uint64_t sa_base;
1345 : :
1346 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1347 : : return -EINVAL;
1348 : :
1349 [ # # ]: 0 : if (eth_dev->data->dev_started || !eth_dev->data->dev_configured)
1350 : : return -EBUSY;
1351 : :
1352 [ # # ]: 0 : if (!roc_nix_inl_inb_rx_inject_enable(nix, dev->inb.inl_dev))
1353 : : return -ENOTSUP;
1354 : :
1355 : 0 : roc_idev_nix_rx_inject_set(port_id, enable);
1356 : :
1357 : 0 : inl_lf = roc_nix_inl_inb_inj_lf_get(nix);
1358 [ # # ]: 0 : if (!inl_lf)
1359 : : return -ENOTSUP;
1360 : 0 : sa_base = roc_nix_inl_inb_sa_base_get(nix, dev->inb.inl_dev);
1361 : :
1362 : : inj_cfg = &dev->inj_cfg;
1363 : 0 : inj_cfg->sa_base = sa_base | eth_dev->data->port_id;
1364 : 0 : inj_cfg->io_addr = inl_lf->io_addr;
1365 : 0 : inj_cfg->lmt_base = nix->lmt_base;
1366 : 0 : channel = roc_nix_get_base_chan(nix);
1367 : 0 : pf_func = roc_idev_nix_inl_dev_pffunc_get();
1368 : 0 : inj_cfg->cmd_w0 = pf_func << 48 | inj_match_id << 32 | channel << 4;
1369 : :
1370 : 0 : return 0;
1371 : : }
1372 : :
1373 : : #define CPT_LMTST_BURST 32
1374 : : static uint16_t
1375 : 0 : cn20k_inl_dev_submit(struct roc_nix_inl_dev_q *q, void *inst, uint16_t nb_inst)
1376 : : {
1377 : 0 : uintptr_t lbase = q->lmt_base;
1378 : : uint8_t lnum, shft, loff;
1379 : : uint16_t left, burst;
1380 : : rte_iova_t io_addr;
1381 : : uint16_t lmt_id;
1382 : :
1383 : : /* Check the flow control to avoid the queue overflow */
1384 [ # # ]: 0 : if (cnxk_nix_inl_fc_check(q->fc_addr, &q->fc_addr_sw, q->nb_desc, nb_inst))
1385 : : return 0;
1386 : :
1387 : : io_addr = q->io_addr;
1388 : : ROC_LMT_CPT_BASE_ID_GET(lbase, lmt_id);
1389 : :
1390 : : left = nb_inst;
1391 : 0 : again:
1392 : 0 : burst = left > CPT_LMTST_BURST ? CPT_LMTST_BURST : left;
1393 : :
1394 : : lnum = 0;
1395 : : loff = 0;
1396 : : shft = 16;
1397 : 0 : memcpy(PLT_PTR_CAST(lbase), inst, burst * sizeof(struct cpt_inst_s));
1398 : : loff = (burst % 2) ? 1 : 0;
1399 : : lnum = (burst / 2);
1400 : : shft = shft + (lnum * 3);
1401 : :
1402 : 0 : left -= burst;
1403 : : cn20k_nix_sec_steorl(io_addr, lmt_id, lnum, loff, shft);
1404 : 0 : rte_io_wmb();
1405 [ # # ]: 0 : if (left) {
1406 : 0 : inst = RTE_PTR_ADD(inst, burst * sizeof(struct cpt_inst_s));
1407 : 0 : goto again;
1408 : : }
1409 : : return nb_inst;
1410 : : }
1411 : :
1412 : : void
1413 : 0 : cn20k_eth_sec_ops_override(void)
1414 : : {
1415 : : static int init_once;
1416 : 0 : uint32_t idx = 0;
1417 : :
1418 [ # # ]: 0 : if (init_once)
1419 : 0 : return;
1420 [ # # ]: 0 : init_once = 1;
1421 : :
1422 [ # # ]: 0 : if (roc_feature_nix_has_inl_ipsec())
1423 : 0 : eth_sec_caps_add(cn20k_eth_sec_capabilities, &idx, cn20k_eth_sec_ipsec_capabilities,
1424 : : RTE_DIM(cn20k_eth_sec_ipsec_capabilities));
1425 : :
1426 : 0 : cn20k_eth_sec_capabilities[idx].action = RTE_SECURITY_ACTION_TYPE_NONE;
1427 : :
1428 : : /* Update platform specific ops */
1429 : 0 : cnxk_eth_sec_ops.session_create = cn20k_eth_sec_session_create;
1430 : 0 : cnxk_eth_sec_ops.session_destroy = cn20k_eth_sec_session_destroy;
1431 : 0 : cnxk_eth_sec_ops.capabilities_get = cn20k_eth_sec_capabilities_get;
1432 : 0 : cnxk_eth_sec_ops.session_update = cn20k_eth_sec_session_update;
1433 : 0 : cnxk_eth_sec_ops.session_stats_get = cn20k_eth_sec_session_stats_get;
1434 : 0 : cnxk_eth_sec_ops.rx_inject_configure = cn20k_eth_sec_rx_inject_config;
1435 : 0 : cnxk_eth_sec_ops.inb_pkt_rx_inject = cn20k_eth_sec_inb_rx_inject;
1436 : :
1437 : : /* Update platform specific rte_pmd_cnxk ops */
1438 : 0 : cnxk_pmd_ops.inl_dev_submit = cn20k_inl_dev_submit;
1439 : : }
|