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