1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include <cryptodev_pmd.h>
7 #include <rte_security.h>
8 #include <rte_security_driver.h>
10 #include "cnxk_cryptodev.h"
11 #include "cnxk_cryptodev_ops.h"
12 #include "cnxk_ipsec.h"
13 #include "cnxk_security.h"
14 #include "cn9k_ipsec.h"
19 cn9k_cpt_enq_sa_write(struct cn9k_ipsec_sa *sa, struct cnxk_cpt_qp *qp,
20 uint8_t opcode, size_t ctx_len)
22 struct roc_cpt *roc_cpt = qp->lf.roc_cpt;
23 uint64_t lmtline = qp->lmtline.lmt_base;
24 uint64_t io_addr = qp->lmtline.io_addr;
25 uint64_t lmt_status, time_out;
26 struct cpt_cn9k_res_s *res;
27 struct cpt_inst_s inst;
31 if (unlikely(rte_mempool_get(qp->meta_info.pool, (void **)&mdata) < 0))
34 res = (struct cpt_cn9k_res_s *)RTE_PTR_ALIGN(mdata, 16);
35 res->compcode = CPT_COMP_NOT_DONE;
37 inst.w4.s.opcode_major = opcode;
38 inst.w4.s.opcode_minor = ctx_len >> 3;
41 inst.w4.s.dlen = ctx_len;
42 inst.dptr = rte_mempool_virt2iova(sa);
44 inst.w7.s.cptr = rte_mempool_virt2iova(sa);
45 inst.w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
50 inst.res_addr = rte_mempool_virt2iova(res);
55 /* Copy CPT command to LMTLINE */
56 roc_lmt_mov((void *)lmtline, &inst, 2);
57 lmt_status = roc_lmt_submit_ldeor(io_addr);
58 } while (lmt_status == 0);
60 time_out = rte_get_timer_cycles() +
61 DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
63 while (res->compcode == CPT_COMP_NOT_DONE) {
64 if (rte_get_timer_cycles() > time_out) {
65 rte_mempool_put(qp->meta_info.pool, mdata);
66 plt_err("Request timed out");
72 if (unlikely(res->compcode != CPT_COMP_GOOD)) {
75 case CPT_COMP_INSTERR:
76 plt_err("Request failed with instruction error");
79 plt_err("Request failed with DMA fault");
82 plt_err("Request failed with hardware error");
85 plt_err("Request failed with unknown hardware "
86 "completion code : 0x%x",
93 if (unlikely(res->uc_compcode != ROC_IE_ON_UCC_SUCCESS)) {
94 ret = res->uc_compcode;
96 case ROC_IE_ON_AUTH_UNSUPPORTED:
97 plt_err("Invalid auth type");
99 case ROC_IE_ON_ENCRYPT_UNSUPPORTED:
100 plt_err("Invalid encrypt type");
103 plt_err("Request failed with unknown microcode "
104 "completion code : 0x%x",
111 rte_mempool_put(qp->meta_info.pool, mdata);
116 ipsec_sa_ctl_set(struct rte_security_ipsec_xform *ipsec,
117 struct rte_crypto_sym_xform *crypto_xform,
118 struct roc_ie_on_sa_ctl *ctl)
120 struct rte_crypto_sym_xform *cipher_xform, *auth_xform;
123 if (ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
124 ctl->direction = ROC_IE_SA_DIR_OUTBOUND;
125 cipher_xform = crypto_xform;
126 auth_xform = crypto_xform->next;
127 } else if (ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
128 ctl->direction = ROC_IE_SA_DIR_INBOUND;
129 auth_xform = crypto_xform;
130 cipher_xform = crypto_xform->next;
135 if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
136 if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4)
137 ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
138 else if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV6)
139 ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
144 if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) {
145 ctl->ipsec_mode = ROC_IE_SA_MODE_TRANSPORT;
146 ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
147 } else if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
148 ctl->ipsec_mode = ROC_IE_SA_MODE_TUNNEL;
152 if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_AH)
153 ctl->ipsec_proto = ROC_IE_SA_PROTOCOL_AH;
154 else if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_ESP)
155 ctl->ipsec_proto = ROC_IE_SA_PROTOCOL_ESP;
159 if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
160 switch (crypto_xform->aead.algo) {
161 case RTE_CRYPTO_AEAD_AES_GCM:
162 ctl->enc_type = ROC_IE_ON_SA_ENC_AES_GCM;
163 aes_key_len = crypto_xform->aead.key.length;
166 plt_err("Unsupported AEAD algorithm");
170 switch (cipher_xform->cipher.algo) {
171 case RTE_CRYPTO_CIPHER_NULL:
172 ctl->enc_type = ROC_IE_ON_SA_ENC_NULL;
174 case RTE_CRYPTO_CIPHER_AES_CBC:
175 ctl->enc_type = ROC_IE_ON_SA_ENC_AES_CBC;
176 aes_key_len = cipher_xform->cipher.key.length;
178 case RTE_CRYPTO_CIPHER_AES_CTR:
179 ctl->enc_type = ROC_IE_ON_SA_ENC_AES_CTR;
180 aes_key_len = cipher_xform->cipher.key.length;
183 plt_err("Unsupported cipher algorithm");
187 switch (auth_xform->auth.algo) {
188 case RTE_CRYPTO_AUTH_NULL:
189 ctl->auth_type = ROC_IE_ON_SA_AUTH_NULL;
191 case RTE_CRYPTO_AUTH_MD5_HMAC:
192 ctl->auth_type = ROC_IE_ON_SA_AUTH_MD5;
194 case RTE_CRYPTO_AUTH_SHA1_HMAC:
195 ctl->auth_type = ROC_IE_ON_SA_AUTH_SHA1;
197 case RTE_CRYPTO_AUTH_SHA224_HMAC:
198 ctl->auth_type = ROC_IE_ON_SA_AUTH_SHA2_224;
200 case RTE_CRYPTO_AUTH_SHA256_HMAC:
201 ctl->auth_type = ROC_IE_ON_SA_AUTH_SHA2_256;
203 case RTE_CRYPTO_AUTH_SHA384_HMAC:
204 ctl->auth_type = ROC_IE_ON_SA_AUTH_SHA2_384;
206 case RTE_CRYPTO_AUTH_SHA512_HMAC:
207 ctl->auth_type = ROC_IE_ON_SA_AUTH_SHA2_512;
209 case RTE_CRYPTO_AUTH_AES_GMAC:
210 ctl->auth_type = ROC_IE_ON_SA_AUTH_AES_GMAC;
212 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
213 ctl->auth_type = ROC_IE_ON_SA_AUTH_AES_XCBC_128;
216 plt_err("Unsupported auth algorithm");
221 /* Set AES key length */
222 if (ctl->enc_type == ROC_IE_ON_SA_ENC_AES_CBC ||
223 ctl->enc_type == ROC_IE_ON_SA_ENC_AES_CCM ||
224 ctl->enc_type == ROC_IE_ON_SA_ENC_AES_CTR ||
225 ctl->enc_type == ROC_IE_ON_SA_ENC_AES_GCM ||
226 ctl->auth_type == ROC_IE_ON_SA_AUTH_AES_GMAC) {
227 switch (aes_key_len) {
229 ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_128;
232 ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_192;
235 ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_256;
238 plt_err("Invalid AES key length");
243 if (ipsec->options.esn)
246 if (ipsec->options.udp_encap == 1)
247 ctl->encap_type = ROC_IE_ON_SA_ENCAP_UDP;
249 ctl->copy_df = ipsec->options.copy_df;
251 ctl->spi = rte_cpu_to_be_32(ipsec->spi);
261 fill_ipsec_common_sa(struct rte_security_ipsec_xform *ipsec,
262 struct rte_crypto_sym_xform *crypto_xform,
263 struct roc_ie_on_common_sa *common_sa)
265 struct rte_crypto_sym_xform *cipher_xform;
266 const uint8_t *cipher_key;
267 int cipher_key_len = 0;
270 if (ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
271 cipher_xform = crypto_xform->next;
273 cipher_xform = crypto_xform;
275 ret = ipsec_sa_ctl_set(ipsec, crypto_xform, &common_sa->ctl);
279 if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
280 if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM)
281 memcpy(common_sa->iv.gcm.nonce, &ipsec->salt, 4);
282 cipher_key = crypto_xform->aead.key.data;
283 cipher_key_len = crypto_xform->aead.key.length;
285 cipher_key = cipher_xform->cipher.key.data;
286 cipher_key_len = cipher_xform->cipher.key.length;
289 if (cipher_key_len != 0)
290 memcpy(common_sa->cipher_key, cipher_key, cipher_key_len);
296 cn9k_ipsec_outb_sa_create(struct cnxk_cpt_qp *qp,
297 struct rte_security_ipsec_xform *ipsec,
298 struct rte_crypto_sym_xform *crypto_xform,
299 struct rte_security_session *sec_sess)
301 struct rte_crypto_sym_xform *auth_xform = crypto_xform->next;
302 struct roc_ie_on_ip_template *template = NULL;
303 struct roc_cpt *roc_cpt = qp->lf.roc_cpt;
304 union roc_on_ipsec_outb_param1 param1;
305 struct cnxk_cpt_inst_tmpl *inst_tmpl;
306 struct roc_ie_on_outb_sa *out_sa;
307 struct cn9k_sec_session *sess;
308 struct roc_ie_on_sa_ctl *ctl;
309 struct cn9k_ipsec_sa *sa;
310 struct rte_ipv6_hdr *ip6;
311 struct rte_ipv4_hdr *ip4;
312 const uint8_t *auth_key;
313 union cpt_inst_w4 w4;
314 union cpt_inst_w7 w7;
315 int auth_key_len = 0;
319 sess = get_sec_session_private_data(sec_sess);
321 out_sa = &sa->out_sa;
322 ctl = &out_sa->common_sa.ctl;
324 memset(sa, 0, sizeof(struct cn9k_ipsec_sa));
326 /* Initialize lookaside IPsec private data */
327 sa->dir = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
328 /* Start ip id from 1 */
333 ret = fill_ipsec_common_sa(ipsec, crypto_xform, &out_sa->common_sa);
337 ret = cnxk_ipsec_outb_rlens_get(&sa->rlens, ipsec, crypto_xform);
341 if (ctl->enc_type == ROC_IE_ON_SA_ENC_AES_GCM ||
342 ctl->auth_type == ROC_IE_ON_SA_AUTH_NULL) {
343 template = &out_sa->aes_gcm.template;
344 ctx_len = offsetof(struct roc_ie_on_outb_sa, aes_gcm.template);
346 switch (ctl->auth_type) {
347 case ROC_IE_ON_SA_AUTH_SHA1:
348 template = &out_sa->sha1.template;
349 ctx_len = offsetof(struct roc_ie_on_outb_sa,
352 case ROC_IE_ON_SA_AUTH_SHA2_256:
353 case ROC_IE_ON_SA_AUTH_SHA2_384:
354 case ROC_IE_ON_SA_AUTH_SHA2_512:
355 template = &out_sa->sha2.template;
356 ctx_len = offsetof(struct roc_ie_on_outb_sa,
359 case ROC_IE_ON_SA_AUTH_AES_XCBC_128:
360 template = &out_sa->aes_xcbc.template;
361 ctx_len = offsetof(struct roc_ie_on_outb_sa,
365 plt_err("Unsupported auth algorithm");
370 ip4 = (struct rte_ipv4_hdr *)&template->ip4.ipv4_hdr;
371 if (ipsec->options.udp_encap) {
372 ip4->next_proto_id = IPPROTO_UDP;
373 template->ip4.udp_src = rte_be_to_cpu_16(4500);
374 template->ip4.udp_dst = rte_be_to_cpu_16(4500);
376 ip4->next_proto_id = IPPROTO_ESP;
379 if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
380 if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
381 uint16_t frag_off = 0;
382 ctx_len += sizeof(template->ip4);
384 ip4->version_ihl = RTE_IPV4_VHL_DEF;
385 ip4->time_to_live = ipsec->tunnel.ipv4.ttl;
386 ip4->type_of_service |= (ipsec->tunnel.ipv4.dscp << 2);
387 if (ipsec->tunnel.ipv4.df)
388 frag_off |= RTE_IPV4_HDR_DF_FLAG;
389 ip4->fragment_offset = rte_cpu_to_be_16(frag_off);
391 memcpy(&ip4->src_addr, &ipsec->tunnel.ipv4.src_ip,
392 sizeof(struct in_addr));
393 memcpy(&ip4->dst_addr, &ipsec->tunnel.ipv4.dst_ip,
394 sizeof(struct in_addr));
395 } else if (ipsec->tunnel.type ==
396 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
397 ctx_len += sizeof(template->ip6);
399 ip6 = (struct rte_ipv6_hdr *)&template->ip6.ipv6_hdr;
400 if (ipsec->options.udp_encap) {
401 ip6->proto = IPPROTO_UDP;
402 template->ip6.udp_src = rte_be_to_cpu_16(4500);
403 template->ip6.udp_dst = rte_be_to_cpu_16(4500);
405 ip6->proto = (ipsec->proto ==
406 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
411 rte_cpu_to_be_32(0x60000000 |
412 ((ipsec->tunnel.ipv6.dscp
413 << RTE_IPV6_HDR_TC_SHIFT) &
414 RTE_IPV6_HDR_TC_MASK) |
415 ((ipsec->tunnel.ipv6.flabel
416 << RTE_IPV6_HDR_FL_SHIFT) &
417 RTE_IPV6_HDR_FL_MASK));
418 ip6->hop_limits = ipsec->tunnel.ipv6.hlimit;
419 memcpy(&ip6->src_addr, &ipsec->tunnel.ipv6.src_addr,
420 sizeof(struct in6_addr));
421 memcpy(&ip6->dst_addr, &ipsec->tunnel.ipv6.dst_addr,
422 sizeof(struct in6_addr));
425 ctx_len += sizeof(template->ip4);
427 ctx_len += RTE_ALIGN_CEIL(ctx_len, 8);
429 if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
430 auth_key = auth_xform->auth.key.data;
431 auth_key_len = auth_xform->auth.key.length;
433 switch (auth_xform->auth.algo) {
434 case RTE_CRYPTO_AUTH_NULL:
436 case RTE_CRYPTO_AUTH_SHA1_HMAC:
437 memcpy(out_sa->sha1.hmac_key, auth_key, auth_key_len);
439 case RTE_CRYPTO_AUTH_SHA256_HMAC:
440 case RTE_CRYPTO_AUTH_SHA384_HMAC:
441 case RTE_CRYPTO_AUTH_SHA512_HMAC:
442 memcpy(out_sa->sha2.hmac_key, auth_key, auth_key_len);
444 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
445 memcpy(out_sa->aes_xcbc.key, auth_key, auth_key_len);
448 plt_err("Unsupported auth algorithm %u",
449 auth_xform->auth.algo);
454 inst_tmpl = &sa->inst;
457 w4.s.opcode_major = ROC_IE_ON_MAJOR_OP_PROCESS_OUTBOUND_IPSEC;
458 w4.s.opcode_minor = ctx_len >> 3;
463 sa->custom_hdr_len = sizeof(struct roc_ie_on_outb_hdr) -
464 ROC_IE_ON_MAX_IV_LEN;
466 #ifdef LA_IPSEC_DEBUG
467 /* Use IV from application in debug mode */
468 if (ipsec->options.iv_gen_disable == 1) {
469 param1.s.per_pkt_iv = ROC_IE_ON_IV_SRC_FROM_DPTR;
470 sa->custom_hdr_len = sizeof(struct roc_ie_on_outb_hdr);
472 if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
473 sa->cipher_iv_off = crypto_xform->aead.iv.offset;
474 sa->cipher_iv_len = crypto_xform->aead.iv.length;
476 sa->cipher_iv_off = crypto_xform->cipher.iv.offset;
477 sa->cipher_iv_len = crypto_xform->cipher.iv.length;
481 if (ipsec->options.iv_gen_disable != 0) {
482 plt_err("Application provided IV is not supported");
487 w4.s.param1 = param1.u16;
489 inst_tmpl->w4 = w4.u64;
492 w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
493 w7.s.cptr = rte_mempool_virt2iova(out_sa);
494 inst_tmpl->w7 = w7.u64;
496 return cn9k_cpt_enq_sa_write(
497 sa, qp, ROC_IE_ON_MAJOR_OP_WRITE_IPSEC_OUTBOUND, ctx_len);
501 cn9k_ipsec_inb_sa_create(struct cnxk_cpt_qp *qp,
502 struct rte_security_ipsec_xform *ipsec,
503 struct rte_crypto_sym_xform *crypto_xform,
504 struct rte_security_session *sec_sess)
506 struct rte_crypto_sym_xform *auth_xform = crypto_xform;
507 struct roc_cpt *roc_cpt = qp->lf.roc_cpt;
508 union roc_on_ipsec_inb_param2 param2;
509 struct cnxk_cpt_inst_tmpl *inst_tmpl;
510 struct roc_ie_on_inb_sa *in_sa;
511 struct cn9k_sec_session *sess;
512 struct cn9k_ipsec_sa *sa;
513 const uint8_t *auth_key;
514 union cpt_inst_w4 w4;
515 union cpt_inst_w7 w7;
516 int auth_key_len = 0;
520 sess = get_sec_session_private_data(sec_sess);
524 memset(sa, 0, sizeof(struct cn9k_ipsec_sa));
526 sa->dir = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
527 sa->replay_win_sz = ipsec->replay_win_sz;
529 ret = fill_ipsec_common_sa(ipsec, crypto_xform, &in_sa->common_sa);
533 if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD ||
534 auth_xform->auth.algo == RTE_CRYPTO_AUTH_NULL) {
535 ctx_len = offsetof(struct roc_ie_on_inb_sa,
536 sha1_or_gcm.hmac_key[0]);
538 auth_key = auth_xform->auth.key.data;
539 auth_key_len = auth_xform->auth.key.length;
541 switch (auth_xform->auth.algo) {
542 case RTE_CRYPTO_AUTH_NULL:
544 case RTE_CRYPTO_AUTH_SHA1_HMAC:
545 memcpy(in_sa->sha1_or_gcm.hmac_key, auth_key,
547 ctx_len = offsetof(struct roc_ie_on_inb_sa,
548 sha1_or_gcm.selector);
550 case RTE_CRYPTO_AUTH_SHA256_HMAC:
551 case RTE_CRYPTO_AUTH_SHA384_HMAC:
552 case RTE_CRYPTO_AUTH_SHA512_HMAC:
553 memcpy(in_sa->sha2.hmac_key, auth_key, auth_key_len);
554 ctx_len = offsetof(struct roc_ie_on_inb_sa,
557 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
558 memcpy(in_sa->aes_xcbc.key, auth_key, auth_key_len);
559 ctx_len = offsetof(struct roc_ie_on_inb_sa,
563 plt_err("Unsupported auth algorithm %u",
564 auth_xform->auth.algo);
569 inst_tmpl = &sa->inst;
572 w4.s.opcode_major = ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC;
573 w4.s.opcode_minor = ctx_len >> 3;
577 w4.s.param2 = param2.u16;
579 inst_tmpl->w4 = w4.u64;
582 w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
583 w7.s.cptr = rte_mempool_virt2iova(in_sa);
584 inst_tmpl->w7 = w7.u64;
586 if (sa->replay_win_sz) {
587 if (sa->replay_win_sz > CNXK_ON_AR_WIN_SIZE_MAX) {
588 plt_err("Replay window size:%u is not supported",
593 /* Set window bottom to 1, base and top to size of window */
595 sa->ar.wint = sa->replay_win_sz;
596 sa->ar.base = sa->replay_win_sz;
598 in_sa->common_sa.esn_low = 0;
599 in_sa->common_sa.esn_hi = 0;
602 return cn9k_cpt_enq_sa_write(
603 sa, qp, ROC_IE_ON_MAJOR_OP_WRITE_IPSEC_INBOUND, ctx_len);
607 cn9k_ipsec_xform_verify(struct rte_security_ipsec_xform *ipsec,
608 struct rte_crypto_sym_xform *crypto)
610 if (ipsec->life.bytes_hard_limit != 0 ||
611 ipsec->life.bytes_soft_limit != 0 ||
612 ipsec->life.packets_hard_limit != 0 ||
613 ipsec->life.packets_soft_limit != 0)
616 if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) {
617 enum rte_crypto_sym_xform_type type = crypto->type;
619 if (type == RTE_CRYPTO_SYM_XFORM_AEAD) {
620 if ((crypto->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) &&
621 (crypto->aead.key.length == 32)) {
622 plt_err("Transport mode AES-256-GCM is not supported");
626 struct rte_crypto_cipher_xform *cipher;
627 struct rte_crypto_auth_xform *auth;
629 if (crypto->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
630 cipher = &crypto->cipher;
631 auth = &crypto->next->auth;
633 cipher = &crypto->next->cipher;
634 auth = &crypto->auth;
637 if ((cipher->algo == RTE_CRYPTO_CIPHER_AES_CBC) &&
638 (auth->algo == RTE_CRYPTO_AUTH_SHA256_HMAC)) {
639 plt_err("Transport mode AES-CBC SHA2 HMAC 256 is not supported");
643 if ((cipher->algo == RTE_CRYPTO_CIPHER_AES_CBC) &&
644 (auth->algo == RTE_CRYPTO_AUTH_SHA384_HMAC)) {
645 plt_err("Transport mode AES-CBC SHA2 HMAC 384 is not supported");
649 if ((cipher->algo == RTE_CRYPTO_CIPHER_AES_CBC) &&
650 (auth->algo == RTE_CRYPTO_AUTH_SHA512_HMAC)) {
651 plt_err("Transport mode AES-CBC SHA2 HMAC 512 is not supported");
655 if ((cipher->algo == RTE_CRYPTO_CIPHER_AES_CBC) &&
656 (auth->algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC)) {
657 plt_err("Transport mode AES-CBC AES-XCBC is not supported");
667 cn9k_ipsec_session_create(void *dev,
668 struct rte_security_ipsec_xform *ipsec_xform,
669 struct rte_crypto_sym_xform *crypto_xform,
670 struct rte_security_session *sess)
672 struct rte_cryptodev *crypto_dev = dev;
673 struct cnxk_cpt_qp *qp;
676 qp = crypto_dev->data->queue_pairs[0];
678 plt_err("CPT queue pairs need to be setup for creating security"
683 ret = cnxk_ipsec_xform_verify(ipsec_xform, crypto_xform);
687 ret = cn9k_ipsec_xform_verify(ipsec_xform, crypto_xform);
691 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
692 return cn9k_ipsec_inb_sa_create(qp, ipsec_xform, crypto_xform,
695 return cn9k_ipsec_outb_sa_create(qp, ipsec_xform, crypto_xform,
700 cn9k_sec_session_create(void *device, struct rte_security_session_conf *conf,
701 struct rte_security_session *sess,
702 struct rte_mempool *mempool)
704 struct cn9k_sec_session *priv;
707 if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
710 if (rte_mempool_get(mempool, (void **)&priv)) {
711 plt_err("Could not allocate security session private data");
715 memset(priv, 0, sizeof(*priv));
717 set_sec_session_private_data(sess, priv);
719 if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC) {
724 ret = cn9k_ipsec_session_create(device, &conf->ipsec,
725 conf->crypto_xform, sess);
732 rte_mempool_put(mempool, priv);
733 set_sec_session_private_data(sess, NULL);
738 cn9k_sec_session_destroy(void *device __rte_unused,
739 struct rte_security_session *sess)
741 struct roc_ie_on_outb_sa *out_sa;
742 struct cn9k_sec_session *priv;
743 struct rte_mempool *sess_mp;
744 struct roc_ie_on_sa_ctl *ctl;
745 struct cn9k_ipsec_sa *sa;
747 priv = get_sec_session_private_data(sess);
752 out_sa = &sa->out_sa;
754 ctl = &out_sa->common_sa.ctl;
759 sess_mp = rte_mempool_from_obj(priv);
761 memset(priv, 0, sizeof(*priv));
763 set_sec_session_private_data(sess, NULL);
764 rte_mempool_put(sess_mp, priv);
770 cn9k_sec_session_get_size(void *device __rte_unused)
772 return sizeof(struct cn9k_sec_session);
775 /* Update platform specific security ops */
777 cn9k_sec_ops_override(void)
779 /* Update platform specific ops */
780 cnxk_sec_ops.session_create = cn9k_sec_session_create;
781 cnxk_sec_ops.session_destroy = cn9k_sec_session_destroy;
782 cnxk_sec_ops.session_get_size = cn9k_sec_session_get_size;