crypto/qat: update raw data path
[dpdk.git] / drivers / crypto / cnxk / cn10k_ipsec_la_ops.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef __CN10K_IPSEC_LA_OPS_H__
6 #define __CN10K_IPSEC_LA_OPS_H__
7
8 #include <rte_crypto_sym.h>
9 #include <rte_security.h>
10
11 #include "cn10k_cryptodev.h"
12 #include "cn10k_ipsec.h"
13 #include "cnxk_cryptodev.h"
14
15 static __rte_always_inline int32_t
16 ipsec_po_out_rlen_get(struct cn10k_ipsec_sa *sess, uint32_t plen)
17 {
18         uint32_t enc_payload_len;
19
20         enc_payload_len =
21                 RTE_ALIGN_CEIL(plen + sess->roundup_len, sess->roundup_byte);
22
23         return sess->partial_len + enc_payload_len;
24 }
25
26 static __rte_always_inline int
27 process_outb_sa(struct rte_crypto_op *cop, struct cn10k_ipsec_sa *sess,
28                 struct cpt_inst_s *inst)
29 {
30         struct rte_crypto_sym_op *sym_op = cop->sym;
31         struct rte_mbuf *m_src = sym_op->m_src;
32         uint32_t dlen, rlen, extend_tail;
33         char *mdata;
34
35         dlen = rte_pktmbuf_pkt_len(m_src);
36         rlen = ipsec_po_out_rlen_get(sess, dlen);
37
38         extend_tail = rlen - dlen;
39
40         mdata = rte_pktmbuf_append(m_src, extend_tail);
41         if (unlikely(mdata == NULL)) {
42                 plt_dp_err("Not enough tail room");
43                 return -ENOMEM;
44         }
45
46         /* Prepare CPT instruction */
47         inst->w4.u64 = sess->inst.w4;
48         inst->w4.s.dlen = dlen;
49         inst->dptr = rte_pktmbuf_iova(m_src);
50         inst->rptr = inst->dptr;
51
52         return 0;
53 }
54
55 static __rte_always_inline int
56 process_inb_sa(struct rte_crypto_op *cop, struct cn10k_ipsec_sa *sa,
57                struct cpt_inst_s *inst)
58 {
59         struct rte_crypto_sym_op *sym_op = cop->sym;
60         struct rte_mbuf *m_src = sym_op->m_src;
61         uint32_t dlen;
62
63         dlen = rte_pktmbuf_pkt_len(m_src);
64
65         /* Prepare CPT instruction */
66         inst->w4.u64 = sa->inst.w4;
67         inst->w4.s.dlen = dlen;
68         inst->dptr = rte_pktmbuf_iova(m_src);
69         inst->rptr = inst->dptr;
70
71         return 0;
72 }
73
74 #endif /* __CN10K_IPSEC_LA_OPS_H__ */