1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef __CN10K_IPSEC_LA_OPS_H__
6 #define __CN10K_IPSEC_LA_OPS_H__
8 #include <rte_crypto_sym.h>
9 #include <rte_security.h>
11 #include "cn10k_cryptodev.h"
12 #include "cn10k_ipsec.h"
13 #include "cnxk_cryptodev.h"
16 ipsec_po_sa_iv_set(struct cn10k_ipsec_sa *sess, struct rte_crypto_op *cop)
18 uint64_t *iv = &sess->out_sa.iv.u64[0];
21 memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset),
23 tmp_iv = (uint64_t *)iv;
24 *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
26 tmp_iv = (uint64_t *)(iv + 1);
27 *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
31 ipsec_po_sa_aes_gcm_iv_set(struct cn10k_ipsec_sa *sess,
32 struct rte_crypto_op *cop)
34 uint8_t *iv = &sess->out_sa.iv.s.iv_dbg1[0];
37 memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset),
39 tmp_iv = (uint32_t *)iv;
40 *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
42 iv = &sess->out_sa.iv.s.iv_dbg2[0];
44 rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4),
46 tmp_iv = (uint32_t *)iv;
47 *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
50 static __rte_always_inline int
51 process_outb_sa(struct rte_crypto_op *cop, struct cn10k_ipsec_sa *sess,
52 struct cpt_inst_s *inst)
54 struct rte_crypto_sym_op *sym_op = cop->sym;
55 struct rte_mbuf *m_src = sym_op->m_src;
56 uint64_t inst_w4_u64 = sess->inst.w4;
58 if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
59 plt_dp_err("Not enough tail room");
64 if (sess->out_sa.w2.s.iv_src == ROC_IE_OT_SA_IV_SRC_FROM_SA) {
65 if (sess->out_sa.w2.s.enc_type == ROC_IE_OT_SA_ENC_AES_GCM)
66 ipsec_po_sa_aes_gcm_iv_set(sess, cop);
68 ipsec_po_sa_iv_set(sess, cop);
72 if (m_src->ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
73 inst_w4_u64 &= ~BIT_ULL(33);
75 if (m_src->ol_flags & RTE_MBUF_F_TX_L4_MASK)
76 inst_w4_u64 &= ~BIT_ULL(32);
78 /* Prepare CPT instruction */
79 inst->w4.u64 = inst_w4_u64;
80 inst->w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
81 inst->dptr = rte_pktmbuf_iova(m_src);
82 inst->rptr = inst->dptr;
87 static __rte_always_inline int
88 process_inb_sa(struct rte_crypto_op *cop, struct cn10k_ipsec_sa *sa,
89 struct cpt_inst_s *inst)
91 struct rte_crypto_sym_op *sym_op = cop->sym;
92 struct rte_mbuf *m_src = sym_op->m_src;
94 /* Prepare CPT instruction */
95 inst->w4.u64 = sa->inst.w4;
96 inst->w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
97 inst->dptr = rte_pktmbuf_iova(m_src);
98 inst->rptr = inst->dptr;
103 #endif /* __CN10K_IPSEC_LA_OPS_H__ */