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