Branch data Line data Source code
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 "roc_ie.h"
12 : :
13 : : #include "cn10k_cryptodev.h"
14 : : #include "cn10k_cryptodev_sec.h"
15 : : #include "cn10k_ipsec.h"
16 : : #include "cnxk_cryptodev.h"
17 : : #include "cnxk_cryptodev_ops.h"
18 : : #include "cnxk_sg.h"
19 : :
20 : : static inline void
21 : : ipsec_po_sa_iv_set(struct cn10k_sec_session *sess, struct rte_crypto_op *cop)
22 : : {
23 : : uint64_t *iv = &sess->sa.out_sa.iv.u64[0];
24 : : uint64_t *tmp_iv;
25 : :
26 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 16);
27 : : tmp_iv = (uint64_t *)iv;
28 : : *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
29 : :
30 : : tmp_iv = (uint64_t *)(iv + 1);
31 : : *tmp_iv = rte_be_to_cpu_64(*tmp_iv);
32 : : }
33 : :
34 : : static inline void
35 : : ipsec_po_sa_aes_gcm_iv_set(struct cn10k_sec_session *sess, struct rte_crypto_op *cop)
36 : : {
37 : : uint8_t *iv = &sess->sa.out_sa.iv.s.iv_dbg1[0];
38 : : uint32_t *tmp_iv;
39 : :
40 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 4);
41 : : tmp_iv = (uint32_t *)iv;
42 : : *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
43 : :
44 : : iv = &sess->sa.out_sa.iv.s.iv_dbg2[0];
45 : : memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4), 4);
46 : : tmp_iv = (uint32_t *)iv;
47 : : *tmp_iv = rte_be_to_cpu_32(*tmp_iv);
48 : : }
49 : :
50 : : static __rte_always_inline int
51 : : process_outb_sa(struct roc_cpt_lf *lf, struct rte_crypto_op *cop, struct cn10k_sec_session *sess,
52 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
53 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
54 : : {
55 : : struct rte_crypto_sym_op *sym_op = cop->sym;
56 : 0 : struct rte_mbuf *m_src = sym_op->m_src;
57 : 0 : uint64_t inst_w4_u64 = sess->inst.w4;
58 : : uint64_t dptr;
59 : :
60 : : RTE_SET_USED(lf);
61 : :
62 : : #ifdef LA_IPSEC_DEBUG
63 : : if (sess->sa.out_sa.w2.s.iv_src == ROC_IE_OT_SA_IV_SRC_FROM_SA) {
64 : : if (sess->sa.out_sa.w2.s.enc_type == ROC_IE_OT_SA_ENC_AES_GCM ||
65 : : sess->sa.out_sa.w2.s.enc_type == ROC_IE_OT_SA_ENC_AES_CCM ||
66 : : sess->sa.out_sa.w2.s.auth_type == ROC_IE_OT_SA_AUTH_AES_GMAC)
67 : : ipsec_po_sa_aes_gcm_iv_set(sess, cop);
68 : : else
69 : : ipsec_po_sa_iv_set(sess, cop);
70 : : }
71 : :
72 : : /* Trigger CTX reload to fetch new data from DRAM */
73 : : roc_cpt_lf_ctx_reload(lf, &sess->sa.out_sa);
74 : : rte_delay_ms(1);
75 : : #endif
76 : :
77 [ # # ]: 0 : if (m_src->ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
78 : 0 : inst_w4_u64 &= ~BIT_ULL(33);
79 : :
80 [ # # ]: 0 : if (m_src->ol_flags & RTE_MBUF_F_TX_L4_MASK)
81 : 0 : inst_w4_u64 &= ~BIT_ULL(32);
82 : :
83 [ # # ]: 0 : if (likely(m_src->next == NULL)) {
84 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
85 : 0 : plt_dp_err("Not enough tail room");
86 : 0 : return -ENOMEM;
87 : : }
88 : :
89 : : /* Prepare CPT instruction */
90 : 0 : inst->w4.u64 = inst_w4_u64 | rte_pktmbuf_pkt_len(m_src);
91 : 0 : dptr = rte_pktmbuf_mtod(m_src, uint64_t);
92 : 0 : inst->dptr = dptr;
93 [ # # ]: 0 : } else if (is_sg_ver2 == false) {
94 : : struct roc_sglist_comp *scatter_comp, *gather_comp;
95 : : uint32_t g_size_bytes, s_size_bytes;
96 : : struct rte_mbuf *last_seg;
97 : : uint8_t *in_buffer;
98 : : uint32_t dlen;
99 : : void *m_data;
100 : : int i;
101 : :
102 : 0 : last_seg = rte_pktmbuf_lastseg(m_src);
103 : :
104 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
105 : 0 : plt_dp_err("Not enough tail room (required: %d, available: %d)",
106 : : sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
107 : 0 : return -ENOMEM;
108 : : }
109 : :
110 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
111 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
112 : 0 : plt_dp_err("Error allocating meta buffer for request");
113 : 0 : return -ENOMEM;
114 : : }
115 : :
116 : : in_buffer = m_data;
117 : :
118 : 0 : ((uint16_t *)in_buffer)[0] = 0;
119 : 0 : ((uint16_t *)in_buffer)[1] = 0;
120 : :
121 : : /* Input Gather List */
122 : : i = 0;
123 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_data + 8);
124 : :
125 : 0 : i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
126 [ # # ]: 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
127 : :
128 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
129 : :
130 : : /* Output Scatter List */
131 : 0 : last_seg->data_len += sess->max_extended_len;
132 : :
133 : : i = 0;
134 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
135 : :
136 : 0 : i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
137 [ # # ]: 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
138 : :
139 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
140 : :
141 : 0 : dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
142 : :
143 : 0 : inst->dptr = (uint64_t)in_buffer;
144 : :
145 : 0 : inst->w4.u64 = sess->inst.w4 | dlen;
146 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
147 : : } else {
148 : : struct roc_sg2list_comp *scatter_comp, *gather_comp;
149 : : union cpt_inst_w5 cpt_inst_w5;
150 : : union cpt_inst_w6 cpt_inst_w6;
151 : : struct rte_mbuf *last_seg;
152 : : uint32_t g_size_bytes;
153 : : void *m_data;
154 : : int i;
155 : :
156 : 0 : last_seg = rte_pktmbuf_lastseg(m_src);
157 : :
158 [ # # ]: 0 : if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
159 : 0 : plt_dp_err("Not enough tail room (required: %d, available: %d)",
160 : : sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
161 : 0 : return -ENOMEM;
162 : : }
163 : :
164 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
165 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
166 : 0 : plt_dp_err("Error allocating meta buffer for request");
167 : 0 : return -ENOMEM;
168 : : }
169 : :
170 : : /* Input Gather List */
171 : : i = 0;
172 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_data);
173 : :
174 : 0 : i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
175 : :
176 : 0 : cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
177 : 0 : g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
178 : :
179 : : /* Output Scatter List */
180 : 0 : last_seg->data_len += sess->max_extended_len;
181 : :
182 : : i = 0;
183 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
184 : :
185 : 0 : i = fill_sg2_comp_from_pkt(scatter_comp, i, m_src);
186 : :
187 : 0 : cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
188 : :
189 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
190 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
191 : :
192 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
193 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
194 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
195 : 0 : inst->w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
196 : : }
197 : :
198 : : return 0;
199 : : }
200 : :
201 : : static __rte_always_inline int
202 : : process_inb_sa(struct rte_crypto_op *cop, struct cn10k_sec_session *sess, struct cpt_inst_s *inst,
203 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
204 : : const bool is_sg_ver2)
205 : : {
206 : : struct rte_crypto_sym_op *sym_op = cop->sym;
207 : 0 : struct rte_mbuf *m_src = sym_op->m_src;
208 : : uint64_t dptr;
209 : :
210 [ # # ]: 0 : if (likely(m_src->next == NULL)) {
211 : : /* Prepare CPT instruction */
212 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
213 : 0 : dptr = rte_pktmbuf_mtod(m_src, uint64_t);
214 : 0 : inst->dptr = dptr;
215 : 0 : m_src->ol_flags |= (uint64_t)sess->ipsec.ip_csum;
216 [ # # ]: 0 : } else if (is_sg_ver2 == false) {
217 : : struct roc_sglist_comp *scatter_comp, *gather_comp;
218 : : uint32_t g_size_bytes, s_size_bytes;
219 : : uint8_t *in_buffer;
220 : : uint32_t dlen;
221 : : void *m_data;
222 : : int i;
223 : :
224 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
225 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
226 : 0 : plt_dp_err("Error allocating meta buffer for request");
227 : 0 : return -ENOMEM;
228 : : }
229 : :
230 : : in_buffer = m_data;
231 : :
232 : 0 : ((uint16_t *)in_buffer)[0] = 0;
233 : 0 : ((uint16_t *)in_buffer)[1] = 0;
234 : :
235 : : /* Input Gather List */
236 : : i = 0;
237 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_data + 8);
238 : 0 : i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
239 [ # # ]: 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
240 : :
241 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
242 : :
243 : : /* Output Scatter List */
244 : : i = 0;
245 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
246 : 0 : i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
247 [ # # ]: 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
248 : :
249 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
250 : :
251 : 0 : dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
252 : :
253 : 0 : inst->dptr = (uint64_t)in_buffer;
254 : 0 : inst->w4.u64 = sess->inst.w4 | dlen;
255 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
256 : : } else {
257 : : struct roc_sg2list_comp *scatter_comp, *gather_comp;
258 : : union cpt_inst_w5 cpt_inst_w5;
259 : : union cpt_inst_w6 cpt_inst_w6;
260 : : uint32_t g_size_bytes;
261 : : void *m_data;
262 : : int i;
263 : :
264 [ # # ]: 0 : m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
265 [ # # ]: 0 : if (unlikely(m_data == NULL)) {
266 : 0 : plt_dp_err("Error allocating meta buffer for request");
267 : 0 : return -ENOMEM;
268 : : }
269 : :
270 : : /* Input Gather List */
271 : : i = 0;
272 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_data);
273 : :
274 : 0 : i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
275 : :
276 : 0 : cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
277 : 0 : g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
278 : :
279 : : /* Output Scatter List */
280 : : i = 0;
281 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
282 : 0 : i = fill_sg2_comp_from_pkt(scatter_comp, i, m_src);
283 : :
284 : 0 : cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
285 : :
286 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
287 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
288 : :
289 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
290 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
291 : 0 : inst->w4.u64 = sess->inst.w4 | rte_pktmbuf_pkt_len(m_src);
292 : 0 : inst->w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
293 : : }
294 : : return 0;
295 : : }
296 : :
297 : : #endif /* __CN10K_IPSEC_LA_OPS_H__ */
|