Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef _CNXK_SE_H_
6 : : #define _CNXK_SE_H_
7 : : #include <stdbool.h>
8 : :
9 : : #include <rte_cryptodev.h>
10 : :
11 : : #include "cnxk_cryptodev.h"
12 : : #include "cnxk_cryptodev_ops.h"
13 : : #include "cnxk_sg.h"
14 : :
15 : : #define SRC_IOV_SIZE \
16 : : (sizeof(struct roc_se_iov_ptr) + (sizeof(struct roc_se_buf_ptr) * ROC_MAX_SG_CNT))
17 : : #define DST_IOV_SIZE \
18 : : (sizeof(struct roc_se_iov_ptr) + (sizeof(struct roc_se_buf_ptr) * ROC_MAX_SG_CNT))
19 : :
20 : : enum cpt_dp_thread_type {
21 : : CPT_DP_THREAD_TYPE_FC_CHAIN = 0x1,
22 : : CPT_DP_THREAD_TYPE_FC_AEAD,
23 : : CPT_DP_THREAD_TYPE_PDCP,
24 : : CPT_DP_THREAD_TYPE_PDCP_CHAIN,
25 : : CPT_DP_THREAD_TYPE_KASUMI,
26 : : CPT_DP_THREAD_TYPE_SM,
27 : : CPT_DP_THREAD_AUTH_ONLY,
28 : : CPT_DP_THREAD_GENERIC,
29 : : CPT_DP_THREAD_TYPE_PT,
30 : : };
31 : :
32 : : struct cnxk_se_sess {
33 : : struct rte_cryptodev_sym_session rte_sess;
34 : : uint8_t aes_gcm : 1;
35 : : uint8_t aes_ccm : 1;
36 : : uint8_t aes_ctr : 1;
37 : : uint8_t chacha_poly : 1;
38 : : uint8_t is_null : 1;
39 : : uint8_t is_gmac : 1;
40 : : uint8_t chained_op : 1;
41 : : uint8_t auth_first : 1;
42 : : uint8_t aes_ctr_eea2 : 1;
43 : : uint8_t is_sha3 : 1;
44 : : uint8_t short_iv : 1;
45 : : uint8_t is_sm3 : 1;
46 : : uint8_t passthrough : 1;
47 : : uint8_t is_sm4 : 1;
48 : : uint8_t cipher_only : 1;
49 : : uint8_t rsvd : 1;
50 : : uint8_t cpt_op : 4;
51 : : uint8_t zsk_flag : 4;
52 : : uint8_t zs_cipher : 4;
53 : : uint8_t zs_auth : 4;
54 : : uint8_t dp_thr_type;
55 : : uint8_t mac_len;
56 : : uint8_t iv_length;
57 : : uint8_t auth_iv_length;
58 : : uint16_t aad_length;
59 : : uint16_t iv_offset;
60 : : uint16_t auth_iv_offset;
61 : : uint32_t salt;
62 : : uint64_t cpt_inst_w7;
63 : : uint64_t cpt_inst_w2;
64 : : struct cnxk_cpt_qp *qp;
65 : : struct roc_se_ctx roc_se_ctx;
66 : : struct roc_cpt_lf *lf;
67 : : } __rte_aligned(ROC_ALIGN);
68 : :
69 : : struct cnxk_sym_dp_ctx {
70 : : struct cnxk_se_sess *sess;
71 : : };
72 : :
73 : : struct cnxk_iov {
74 : : char src[SRC_IOV_SIZE];
75 : : char dst[SRC_IOV_SIZE];
76 : : void *iv_buf;
77 : : void *aad_buf;
78 : : void *mac_buf;
79 : : uint16_t c_head;
80 : : uint16_t c_tail;
81 : : uint16_t a_head;
82 : : uint16_t a_tail;
83 : : int data_len;
84 : : };
85 : :
86 : : static __rte_always_inline int fill_sess_gmac(struct rte_crypto_sym_xform *xform,
87 : : struct cnxk_se_sess *sess);
88 : :
89 : : static inline void
90 : 0 : cpt_pack_iv(uint8_t *iv_src, uint8_t *iv_dst)
91 : : {
92 : : /* pack the first 8 bytes of IV to 6 bytes.
93 : : * discard the 2 MSB bits of each byte
94 : : */
95 : 0 : iv_dst[0] = (((iv_src[0] & 0x3f) << 2) | ((iv_src[1] >> 4) & 0x3));
96 : 0 : iv_dst[1] = (((iv_src[1] & 0xf) << 4) | ((iv_src[2] >> 2) & 0xf));
97 : 0 : iv_dst[2] = (((iv_src[2] & 0x3) << 6) | (iv_src[3] & 0x3f));
98 : :
99 : 0 : iv_dst[3] = (((iv_src[4] & 0x3f) << 2) | ((iv_src[5] >> 4) & 0x3));
100 : 0 : iv_dst[4] = (((iv_src[5] & 0xf) << 4) | ((iv_src[6] >> 2) & 0xf));
101 : 0 : iv_dst[5] = (((iv_src[6] & 0x3) << 6) | (iv_src[7] & 0x3f));
102 : 0 : }
103 : :
104 : : static inline void
105 : 0 : pdcp_iv_copy(uint8_t *iv_d, const uint8_t *iv_s, const uint8_t pdcp_alg_type, uint8_t pack_iv)
106 : : {
107 : : const uint32_t *iv_s_temp;
108 : : uint32_t iv_temp[4];
109 : : int j;
110 : :
111 [ # # ]: 0 : if (unlikely(iv_s == NULL)) {
112 : : memset(iv_d, 0, 16);
113 : 0 : return;
114 : : }
115 : :
116 [ # # ]: 0 : if (pdcp_alg_type == ROC_SE_PDCP_ALG_TYPE_SNOW3G) {
117 : : /*
118 : : * DPDK seems to provide it in form of IV3 IV2 IV1 IV0
119 : : * and BigEndian, MC needs it as IV0 IV1 IV2 IV3
120 : : */
121 : :
122 : : iv_s_temp = (const uint32_t *)iv_s;
123 : :
124 [ # # ]: 0 : for (j = 0; j < 4; j++)
125 : 0 : iv_temp[j] = iv_s_temp[3 - j];
126 : : memcpy(iv_d, iv_temp, 16);
127 : 0 : } else if ((pdcp_alg_type == ROC_SE_PDCP_ALG_TYPE_ZUC) ||
128 [ # # ]: 0 : pdcp_alg_type == ROC_SE_PDCP_ALG_TYPE_AES_CTR) {
129 : : memcpy(iv_d, iv_s, 16);
130 [ # # ]: 0 : if (pack_iv) {
131 : : uint8_t iv_d23, iv_d24;
132 : :
133 : : /* Save last two bytes as only 23B IV space is available */
134 : 0 : iv_d23 = iv_d[23];
135 : 0 : iv_d24 = iv_d[24];
136 : :
137 : : /* Copy remaining part of IV */
138 : 0 : memcpy(iv_d + 16, iv_s + 16, 25 - 16);
139 : :
140 : : /* Swap IV */
141 : : roc_se_zuc_bytes_swap(iv_d, 25);
142 : :
143 : : /* Pack IV */
144 : 0 : cpt_pack_iv(iv_d, iv_d);
145 : :
146 : : /* Move IV */
147 [ # # ]: 0 : for (j = 6; j < 23; j++)
148 : 0 : iv_d[j] = iv_d[j + 2];
149 : :
150 : 0 : iv_d[23] = iv_d23;
151 : 0 : iv_d[24] = iv_d24;
152 : : }
153 : : }
154 : : }
155 : :
156 : : /*
157 : : * Digest immediately at the end of the data is the best case. Switch to SG if
158 : : * that cannot be ensured.
159 : : */
160 : : static inline void
161 : 0 : cpt_digest_buf_lb_check(const struct cnxk_se_sess *sess, struct rte_mbuf *m,
162 : : struct roc_se_fc_params *fc_params, uint32_t *flags,
163 : : struct rte_crypto_sym_op *sym_op, bool *inplace, uint32_t a_data_off,
164 : : uint32_t a_data_len, uint32_t c_data_off, uint32_t c_data_len,
165 : : const bool is_pdcp_chain)
166 : : {
167 : 0 : const uint32_t auth_end = a_data_off + a_data_len;
168 : : uint32_t mc_hash_off;
169 : :
170 : : /* PDCP_CHAIN only supports auth_first */
171 : :
172 [ # # # # ]: 0 : if (is_pdcp_chain || sess->auth_first)
173 : : mc_hash_off = auth_end;
174 : : else
175 : 0 : mc_hash_off = RTE_MAX(c_data_off + c_data_len, auth_end);
176 : :
177 : : /* Digest immediately following data is best case */
178 : :
179 [ # # ]: 0 : if (unlikely(rte_pktmbuf_mtod_offset(m, uint8_t *, mc_hash_off) !=
180 : : sym_op->auth.digest.data)) {
181 : 0 : *flags |= ROC_SE_VALID_MAC_BUF;
182 : 0 : fc_params->mac_buf.size = sess->mac_len;
183 : 0 : fc_params->mac_buf.vaddr = sym_op->auth.digest.data;
184 : 0 : *inplace = false;
185 : : }
186 : 0 : }
187 : :
188 : : static inline struct rte_mbuf *
189 : 0 : cpt_m_dst_get(uint8_t cpt_op, struct rte_mbuf *m_src, struct rte_mbuf *m_dst)
190 : : {
191 [ # # # # ]: 0 : if (m_dst != NULL && (cpt_op & ROC_SE_OP_ENCODE))
192 : : return m_dst;
193 : : else
194 : 0 : return m_src;
195 : : }
196 : :
197 : : static __rte_always_inline int
198 : : cpt_mac_len_verify(struct rte_crypto_auth_xform *auth)
199 : : {
200 : 0 : uint16_t mac_len = auth->digest_length;
201 : : int ret;
202 : :
203 [ # # # # ]: 0 : if ((auth->algo != RTE_CRYPTO_AUTH_NULL) && (mac_len == 0))
204 : : return -1;
205 : :
206 [ # # # # : 0 : switch (auth->algo) {
# # # # #
# ]
207 : 0 : case RTE_CRYPTO_AUTH_MD5:
208 : : case RTE_CRYPTO_AUTH_MD5_HMAC:
209 [ # # ]: 0 : ret = (mac_len <= 16) ? 0 : -1;
210 : : break;
211 : 0 : case RTE_CRYPTO_AUTH_SHA1:
212 : : case RTE_CRYPTO_AUTH_SHA1_HMAC:
213 [ # # ]: 0 : ret = (mac_len <= 20) ? 0 : -1;
214 : : break;
215 : 0 : case RTE_CRYPTO_AUTH_SHA224:
216 : : case RTE_CRYPTO_AUTH_SHA224_HMAC:
217 : : case RTE_CRYPTO_AUTH_SHA3_224:
218 : : case RTE_CRYPTO_AUTH_SHA3_224_HMAC:
219 [ # # ]: 0 : ret = (mac_len <= 28) ? 0 : -1;
220 : : break;
221 : 0 : case RTE_CRYPTO_AUTH_SHA256:
222 : : case RTE_CRYPTO_AUTH_SHA256_HMAC:
223 : : case RTE_CRYPTO_AUTH_SHA3_256:
224 : : case RTE_CRYPTO_AUTH_SHA3_256_HMAC:
225 [ # # ]: 0 : ret = (mac_len <= 32) ? 0 : -1;
226 : : break;
227 : 0 : case RTE_CRYPTO_AUTH_SHA384:
228 : : case RTE_CRYPTO_AUTH_SHA384_HMAC:
229 : : case RTE_CRYPTO_AUTH_SHA3_384:
230 : : case RTE_CRYPTO_AUTH_SHA3_384_HMAC:
231 [ # # ]: 0 : ret = (mac_len <= 48) ? 0 : -1;
232 : : break;
233 : 0 : case RTE_CRYPTO_AUTH_SHA512:
234 : : case RTE_CRYPTO_AUTH_SHA512_HMAC:
235 : : case RTE_CRYPTO_AUTH_SHA3_512:
236 : : case RTE_CRYPTO_AUTH_SHA3_512_HMAC:
237 [ # # ]: 0 : ret = (mac_len <= 64) ? 0 : -1;
238 : : break;
239 : : /* SHAKE itself doesn't have limitation of digest length,
240 : : * but in microcode size of length field is limited to 8 bits
241 : : */
242 : 0 : case RTE_CRYPTO_AUTH_SHAKE_128:
243 : : case RTE_CRYPTO_AUTH_SHAKE_256:
244 [ # # ]: 0 : ret = (mac_len <= UINT8_MAX) ? 0 : -1;
245 : : break;
246 : 0 : case RTE_CRYPTO_AUTH_SM3:
247 [ # # ]: 0 : ret = (mac_len <= 32) ? 0 : -1;
248 : : break;
249 : : case RTE_CRYPTO_AUTH_NULL:
250 : : ret = 0;
251 : : break;
252 : : default:
253 : : ret = -1;
254 : : }
255 : :
256 : : return ret;
257 : : }
258 : :
259 : : static __rte_always_inline int
260 : : sg_inst_prep(struct roc_se_fc_params *params, struct cpt_inst_s *inst, uint64_t offset_ctrl,
261 : : const uint8_t *iv_s, int iv_len, uint8_t pack_iv, uint8_t pdcp_alg_type,
262 : : int32_t inputlen, int32_t outputlen, uint32_t passthrough_len, uint32_t req_flags,
263 : : int pdcp_flag, int decrypt)
264 : : {
265 : : struct roc_sglist_comp *gather_comp, *scatter_comp;
266 : 0 : void *m_vaddr = params->meta_buf.vaddr;
267 : : struct roc_se_buf_ptr *aad_buf = NULL;
268 : : uint32_t mac_len = 0, aad_len = 0;
269 : : struct roc_se_ctx *se_ctx;
270 : : uint32_t i, g_size_bytes;
271 : : int zsk_flags, ret = 0;
272 : : uint64_t *offset_vaddr;
273 : : uint32_t s_size_bytes;
274 : : uint8_t *in_buffer;
275 : : uint32_t size;
276 : : uint8_t *iv_d;
277 : :
278 : : se_ctx = params->ctx;
279 : 0 : zsk_flags = se_ctx->zsk_flags;
280 : 0 : mac_len = se_ctx->mac_len;
281 : :
282 : 0 : if (unlikely(req_flags & ROC_SE_VALID_AAD_BUF)) {
283 : : /* We don't support both AAD and auth data separately */
284 : : aad_len = params->aad_buf.size;
285 : : aad_buf = ¶ms->aad_buf;
286 : : }
287 : :
288 : : /* save space for iv */
289 : : offset_vaddr = m_vaddr;
290 : :
291 : 0 : m_vaddr = (uint8_t *)m_vaddr + ROC_SE_OFF_CTRL_LEN + RTE_ALIGN_CEIL(iv_len, 8);
292 : :
293 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
294 : :
295 : : /* iv offset is 0 */
296 : 0 : *offset_vaddr = offset_ctrl;
297 : :
298 [ # # # # : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
# # # # #
# # # ]
299 : :
300 : : if (pdcp_flag) {
301 : 0 : if (likely(iv_len))
302 : 0 : pdcp_iv_copy(iv_d, iv_s, pdcp_alg_type, pack_iv);
303 : : } else {
304 [ # # # # : 0 : if (likely(iv_len))
# # # # #
# # # ]
305 : 0 : memcpy(iv_d, iv_s, iv_len);
306 : : }
307 : :
308 : : /* DPTR has SG list */
309 : :
310 : : /* TODO Add error check if space will be sufficient */
311 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_vaddr + 8);
312 : :
313 : : /*
314 : : * Input Gather List
315 : : */
316 : : i = 0;
317 : :
318 : : /* Offset control word followed by iv */
319 : :
320 [ # # # # : 0 : i = fill_sg_comp(gather_comp, i, (uint64_t)offset_vaddr, ROC_SE_OFF_CTRL_LEN + iv_len);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
321 : :
322 : : /* Add input data */
323 [ # # # # : 0 : if (decrypt && (req_flags & ROC_SE_VALID_MAC_BUF)) {
# # # # #
# # # ]
324 : 0 : size = inputlen - iv_len - mac_len;
325 [ # # # # : 0 : if (likely(size)) {
# # # # #
# # # ]
326 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # ]
327 : : /* input data only */
328 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # ]
329 : : i = fill_sg_comp_from_buf_min(gather_comp, i, params->bufs, &size);
330 : : } else {
331 [ # # # # ]: 0 : i = fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size,
332 : : aad_buf, aad_offset);
333 : : }
334 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # ]
335 : 0 : plt_dp_err("Insufficient buffer"
336 : : " space, size %d needed",
337 : : size);
338 : 0 : return -1;
339 : : }
340 : : }
341 : :
342 [ # # # # : 0 : if (mac_len)
# # # # #
# # # ]
343 : : i = fill_sg_comp_from_buf(gather_comp, i, ¶ms->mac_buf);
344 : : } else {
345 : : /* input data */
346 : 0 : size = inputlen - iv_len;
347 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
348 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # # # #
# # # ]
349 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
350 : : i = fill_sg_comp_from_buf_min(gather_comp, i, params->bufs, &size);
351 : : } else {
352 [ # # # # : 0 : i = fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size,
# # # # ]
353 : : aad_buf, aad_offset);
354 : : }
355 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
356 : 0 : plt_dp_err("Insufficient buffer space,"
357 : : " size %d needed",
358 : : size);
359 : 0 : return -1;
360 : : }
361 : : }
362 : : }
363 : :
364 : : in_buffer = m_vaddr;
365 : :
366 : 0 : ((uint16_t *)in_buffer)[0] = 0;
367 : 0 : ((uint16_t *)in_buffer)[1] = 0;
368 [ # # # # : 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
369 : :
370 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
371 : : /*
372 : : * Output Scatter List
373 : : */
374 : :
375 : : i = 0;
376 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
377 : :
378 [ # # # # : 0 : if (zsk_flags == 0x1) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
379 : : /* IV in SLIST only for EEA3 & UEA2 or for F8 */
380 : : iv_len = 0;
381 : : }
382 : :
383 [ # # # # : 0 : if (iv_len) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
384 [ # # # # : 0 : i = fill_sg_comp(scatter_comp, i, (uint64_t)offset_vaddr + ROC_SE_OFF_CTRL_LEN,
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
385 : : iv_len);
386 : : }
387 : :
388 : : /* Add output data */
389 [ # # # # : 0 : if ((!decrypt) && (req_flags & ROC_SE_VALID_MAC_BUF)) {
# # # # #
# # # # #
# # ]
390 : 0 : size = outputlen - iv_len - mac_len;
391 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
392 : :
393 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # ]
394 : :
395 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # ]
396 : : i = fill_sg_comp_from_buf_min(scatter_comp, i, params->bufs, &size);
397 : : } else {
398 [ # # # # ]: 0 : i = fill_sg_comp_from_iov(scatter_comp, i, params->dst_iov, 0,
399 : : &size, aad_buf, aad_offset);
400 : : }
401 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
402 : 0 : plt_dp_err("Insufficient buffer space,"
403 : : " size %d needed",
404 : : size);
405 : 0 : return -1;
406 : : }
407 : : }
408 : :
409 : : /* mac data */
410 [ # # # # : 0 : if (mac_len)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
411 : : i = fill_sg_comp_from_buf(scatter_comp, i, ¶ms->mac_buf);
412 : : } else {
413 : : /* Output including mac */
414 : 0 : size = outputlen - iv_len;
415 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
416 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # # # #
# # # ]
417 : :
418 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
419 : : i = fill_sg_comp_from_buf_min(scatter_comp, i, params->bufs, &size);
420 : : } else {
421 [ # # # # : 0 : i = fill_sg_comp_from_iov(scatter_comp, i, params->dst_iov, 0,
# # # # ]
422 : : &size, aad_buf, aad_offset);
423 : : }
424 : :
425 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
426 : 0 : plt_dp_err("Insufficient buffer space,"
427 : : " size %d needed",
428 : : size);
429 : 0 : return -1;
430 : : }
431 : : }
432 : : }
433 [ # # # # : 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
434 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
435 : :
436 : 0 : size = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
437 : :
438 : : /* This is DPTR len in case of SG mode */
439 : 0 : inst->w4.s.dlen = size;
440 : :
441 [ # # # # : 0 : if (unlikely(size > ROC_SG_MAX_DLEN_SIZE)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
442 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
443 : : ret = -1;
444 : : }
445 : :
446 : 0 : inst->dptr = (uint64_t)in_buffer;
447 : 0 : return ret;
448 : : }
449 : :
450 : : static __rte_always_inline int
451 : : sg2_inst_prep(struct roc_se_fc_params *params, struct cpt_inst_s *inst, uint64_t offset_ctrl,
452 : : const uint8_t *iv_s, int iv_len, uint8_t pack_iv, uint8_t pdcp_alg_type,
453 : : int32_t inputlen, int32_t outputlen, uint32_t passthrough_len, uint32_t req_flags,
454 : : int pdcp_flag, int decrypt)
455 : : {
456 : : struct roc_sg2list_comp *gather_comp, *scatter_comp;
457 : 0 : void *m_vaddr = params->meta_buf.vaddr;
458 : : struct roc_se_buf_ptr *aad_buf = NULL;
459 : : uint32_t mac_len = 0, aad_len = 0;
460 : : uint16_t scatter_sz, gather_sz;
461 : : union cpt_inst_w5 cpt_inst_w5;
462 : : union cpt_inst_w6 cpt_inst_w6;
463 : : struct roc_se_ctx *se_ctx;
464 : : uint32_t i, g_size_bytes;
465 : : uint64_t *offset_vaddr;
466 : : int zsk_flags, ret = 0;
467 : : uint32_t size;
468 : : uint8_t *iv_d;
469 : :
470 : : se_ctx = params->ctx;
471 : 0 : zsk_flags = se_ctx->zsk_flags;
472 : 0 : mac_len = se_ctx->mac_len;
473 : :
474 : 0 : if (unlikely(req_flags & ROC_SE_VALID_AAD_BUF)) {
475 : : /* We don't support both AAD and auth data separately */
476 : : aad_len = params->aad_buf.size;
477 : : aad_buf = ¶ms->aad_buf;
478 : : }
479 : :
480 : : /* save space for iv */
481 : : offset_vaddr = m_vaddr;
482 : :
483 : 0 : m_vaddr = (uint8_t *)m_vaddr + ROC_SE_OFF_CTRL_LEN + RTE_ALIGN_CEIL(iv_len, 8);
484 : :
485 : 0 : inst->w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
486 : :
487 : : /* This is DPTR len in case of SG mode */
488 : 0 : inst->w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
489 : :
490 : : /* iv offset is 0 */
491 : 0 : *offset_vaddr = offset_ctrl;
492 : :
493 [ # # # # : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
# # # # #
# # # ]
494 : : if (pdcp_flag) {
495 : 0 : if (likely(iv_len))
496 : 0 : pdcp_iv_copy(iv_d, iv_s, pdcp_alg_type, pack_iv);
497 : : } else {
498 [ # # # # : 0 : if (likely(iv_len))
# # # # #
# # # ]
499 : 0 : memcpy(iv_d, iv_s, iv_len);
500 : : }
501 : :
502 : : /* DPTR has SG list */
503 : :
504 : : /* TODO Add error check if space will be sufficient */
505 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_vaddr);
506 : :
507 : : /*
508 : : * Input Gather List
509 : : */
510 : : i = 0;
511 : :
512 : : /* Offset control word followed by iv */
513 : :
514 [ # # # # : 0 : i = fill_sg2_comp(gather_comp, i, (uint64_t)offset_vaddr, ROC_SE_OFF_CTRL_LEN + iv_len);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
515 : :
516 : : /* Add input data */
517 [ # # # # : 0 : if (decrypt && (req_flags & ROC_SE_VALID_MAC_BUF)) {
# # # # #
# # # ]
518 : 0 : size = inputlen - iv_len - mac_len;
519 [ # # # # : 0 : if (size) {
# # # # #
# # # ]
520 : : /* input data only */
521 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # ]
522 : : i = fill_sg2_comp_from_buf_min(gather_comp, i, params->bufs, &size);
523 : : } else {
524 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # ]
525 : :
526 [ # # # # ]: 0 : i = fill_sg2_comp_from_iov(gather_comp, i, params->src_iov, 0,
527 : : &size, aad_buf, aad_offset);
528 : : }
529 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # ]
530 : 0 : plt_dp_err("Insufficient buffer"
531 : : " space, size %d needed",
532 : : size);
533 : 0 : return -1;
534 : : }
535 : : }
536 : :
537 : : /* mac data */
538 [ # # # # : 0 : if (mac_len)
# # # # #
# # # ]
539 : : i = fill_sg2_comp_from_buf(gather_comp, i, ¶ms->mac_buf);
540 : : } else {
541 : : /* input data */
542 : 0 : size = inputlen - iv_len;
543 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
544 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # # # #
# # # ]
545 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
546 : : i = fill_sg2_comp_from_buf_min(gather_comp, i, params->bufs, &size);
547 : : } else {
548 [ # # # # : 0 : i = fill_sg2_comp_from_iov(gather_comp, i, params->src_iov, 0,
# # # # ]
549 : : &size, aad_buf, aad_offset);
550 : : }
551 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
552 : 0 : plt_dp_err("Insufficient buffer space,"
553 : : " size %d needed",
554 : : size);
555 : 0 : return -1;
556 : : }
557 : : }
558 : : }
559 : :
560 : 0 : gather_sz = (i + 2) / 3;
561 : 0 : g_size_bytes = gather_sz * sizeof(struct roc_sg2list_comp);
562 : :
563 : : /*
564 : : * Output Scatter List
565 : : */
566 : :
567 : : i = 0;
568 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
569 : :
570 [ # # # # : 0 : if (zsk_flags == 0x1) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
571 : : /* IV in SLIST only for EEA3 & UEA2 or for F8 */
572 : : iv_len = 0;
573 : : }
574 : :
575 [ # # # # : 0 : if (iv_len) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
576 : 0 : i = fill_sg2_comp(scatter_comp, i, (uint64_t)offset_vaddr + ROC_SE_OFF_CTRL_LEN,
577 : : iv_len);
578 : : }
579 : :
580 : : /* Add output data */
581 [ # # # # : 0 : if ((!decrypt) && (req_flags & ROC_SE_VALID_MAC_BUF)) {
# # # # #
# # # # #
# # ]
582 : 0 : size = outputlen - iv_len - mac_len;
583 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
584 : :
585 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # ]
586 : :
587 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # ]
588 : : i = fill_sg2_comp_from_buf_min(scatter_comp, i, params->bufs,
589 : : &size);
590 : : } else {
591 [ # # # # ]: 0 : i = fill_sg2_comp_from_iov(scatter_comp, i, params->dst_iov, 0,
592 : : &size, aad_buf, aad_offset);
593 : : }
594 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
595 : 0 : plt_dp_err("Insufficient buffer space,"
596 : : " size %d needed",
597 : : size);
598 : 0 : return -1;
599 : : }
600 : : }
601 : :
602 : : /* mac data */
603 [ # # # # : 0 : if (mac_len)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
604 : : i = fill_sg2_comp_from_buf(scatter_comp, i, ¶ms->mac_buf);
605 : : } else {
606 : : /* Output including mac */
607 : 0 : size = outputlen - iv_len;
608 [ # # # # : 0 : if (size) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
609 [ # # # # : 0 : uint32_t aad_offset = aad_len ? passthrough_len : 0;
# # # # #
# # # ]
610 : :
611 [ # # # # : 0 : if (unlikely(req_flags & ROC_SE_SINGLE_BUF_INPLACE)) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
612 : : i = fill_sg2_comp_from_buf_min(scatter_comp, i, params->bufs,
613 : : &size);
614 : : } else {
615 [ # # # # : 0 : i = fill_sg2_comp_from_iov(scatter_comp, i, params->dst_iov, 0,
# # # # ]
616 : : &size, aad_buf, aad_offset);
617 : : }
618 : :
619 [ # # # # : 0 : if (unlikely(size)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
620 : 0 : plt_dp_err("Insufficient buffer space,"
621 : : " size %d needed",
622 : : size);
623 : 0 : return -1;
624 : : }
625 : : }
626 : : }
627 : :
628 : 0 : scatter_sz = (i + 2) / 3;
629 : :
630 : 0 : cpt_inst_w5.s.gather_sz = gather_sz;
631 : 0 : cpt_inst_w6.s.scatter_sz = scatter_sz;
632 : :
633 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
634 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
635 : :
636 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
637 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
638 : :
639 [ # # # # : 0 : if (unlikely((scatter_sz >> 4) || (gather_sz >> 4))) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
640 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
641 : : ret = -1;
642 : : }
643 : :
644 : : return ret;
645 : : }
646 : :
647 : : static __rte_always_inline int
648 : : cpt_digest_gen_sg_ver1_prep(uint32_t flags, uint64_t d_lens, struct roc_se_fc_params *params,
649 : : struct cpt_inst_s *inst)
650 : : {
651 : : struct roc_sglist_comp *gather_comp, *scatter_comp;
652 : : void *m_vaddr = params->meta_buf.vaddr;
653 : : uint32_t g_size_bytes, s_size_bytes;
654 : : uint16_t data_len, mac_len, key_len;
655 : : union cpt_inst_w4 cpt_inst_w4;
656 : : roc_se_auth_type hash_type;
657 : : struct roc_se_ctx *ctx;
658 : : uint8_t *in_buffer;
659 : : uint32_t size, i;
660 : : int ret = 0;
661 : :
662 : : ctx = params->ctx;
663 : :
664 : 0 : hash_type = ctx->hash_type;
665 : 0 : mac_len = ctx->mac_len;
666 : 0 : key_len = ctx->auth_key_len;
667 : 0 : data_len = ROC_SE_AUTH_DLEN(d_lens);
668 : :
669 : 0 : cpt_inst_w4.u64 = ctx->template_w4.u64;
670 : 0 : cpt_inst_w4.s.param2 = ((uint16_t)hash_type << 8) | mac_len;
671 [ # # # # : 0 : if (ctx->hmac) {
# # ]
672 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_HMAC | ROC_DMA_MODE_SG;
673 : 0 : cpt_inst_w4.s.param1 = key_len;
674 : 0 : cpt_inst_w4.s.dlen = data_len + RTE_ALIGN_CEIL(key_len, 8);
675 : : } else {
676 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_HASH | ROC_DMA_MODE_SG;
677 : 0 : cpt_inst_w4.s.param1 = 0;
678 : 0 : cpt_inst_w4.s.dlen = data_len;
679 : : }
680 : :
681 : : /* DPTR has SG list */
682 : : in_buffer = m_vaddr;
683 : :
684 : 0 : ((uint16_t *)in_buffer)[0] = 0;
685 : 0 : ((uint16_t *)in_buffer)[1] = 0;
686 : :
687 : : /* TODO Add error check if space will be sufficient */
688 : 0 : gather_comp = (struct roc_sglist_comp *)((uint8_t *)m_vaddr + 8);
689 : :
690 : : /*
691 : : * Input gather list
692 : : */
693 : :
694 : : i = 0;
695 : :
696 [ # # # # : 0 : if (ctx->hmac) {
# # ]
697 : 0 : uint64_t k_vaddr = (uint64_t)ctx->auth_key;
698 : : /* Key */
699 : 0 : i = fill_sg_comp(gather_comp, i, k_vaddr,
700 [ # # # # : 0 : RTE_ALIGN_CEIL(key_len, 8));
# # ]
701 : : }
702 : :
703 : : /* input data */
704 : 0 : size = data_len;
705 : : i = fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0);
706 [ # # # # : 0 : if (unlikely(size)) {
# # ]
707 : 0 : plt_dp_err("Insufficient dst IOV size, short by %dB", size);
708 : : return -1;
709 : : }
710 [ # # # # : 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
# # ]
711 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
712 : :
713 : : /*
714 : : * Output Gather list
715 : : */
716 : :
717 : : i = 0;
718 : 0 : scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
719 : :
720 : : if (flags & ROC_SE_VALID_MAC_BUF) {
721 [ # # # # : 0 : if (unlikely(params->mac_buf.size < mac_len)) {
# # ]
722 : 0 : plt_dp_err("Insufficient MAC size");
723 : : return -1;
724 : : }
725 : :
726 : : size = mac_len;
727 : : i = fill_sg_comp_from_buf_min(scatter_comp, i, ¶ms->mac_buf,
728 : : &size);
729 : : } else {
730 : : size = mac_len;
731 : : i = fill_sg_comp_from_iov(scatter_comp, i, params->src_iov,
732 : : data_len, &size, NULL, 0);
733 : : if (unlikely(size)) {
734 : : plt_dp_err("Insufficient dst IOV size, short by %dB",
735 : : size);
736 : : return -1;
737 : : }
738 : : }
739 : :
740 : 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
741 : : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
742 : :
743 : 0 : size = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
744 : :
745 [ # # # # : 0 : if (unlikely(size > ROC_SG_MAX_DLEN_SIZE)) {
# # ]
746 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
747 : : ret = -1;
748 : : }
749 : :
750 : : /* This is DPTR len in case of SG mode */
751 : 0 : cpt_inst_w4.s.dlen = size;
752 : :
753 : 0 : inst->dptr = (uint64_t)in_buffer;
754 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
755 : :
756 : : return ret;
757 : : }
758 : :
759 : : static __rte_always_inline int
760 : : cpt_digest_gen_sg_ver2_prep(uint32_t flags, uint64_t d_lens, struct roc_se_fc_params *params,
761 : : struct cpt_inst_s *inst)
762 : : {
763 : : uint16_t data_len, mac_len, key_len, scatter_sz, gather_sz;
764 : : struct roc_sg2list_comp *gather_comp, *scatter_comp;
765 : : void *m_vaddr = params->meta_buf.vaddr;
766 : : union cpt_inst_w4 cpt_inst_w4;
767 : : union cpt_inst_w5 cpt_inst_w5;
768 : : union cpt_inst_w6 cpt_inst_w6;
769 : : roc_se_auth_type hash_type;
770 : : struct roc_se_ctx *ctx;
771 : : uint32_t g_size_bytes;
772 : : uint32_t size, i;
773 : : int ret = 0;
774 : :
775 : : ctx = params->ctx;
776 : :
777 : 0 : hash_type = ctx->hash_type;
778 : 0 : mac_len = ctx->mac_len;
779 : 0 : key_len = ctx->auth_key_len;
780 : 0 : data_len = ROC_SE_AUTH_DLEN(d_lens);
781 : :
782 : 0 : cpt_inst_w4.u64 = ctx->template_w4.u64;
783 : 0 : cpt_inst_w4.s.param2 = ((uint16_t)hash_type << 8) | mac_len;
784 [ # # # # : 0 : if (ctx->hmac) {
# # ]
785 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_HMAC;
786 : 0 : cpt_inst_w4.s.param1 = key_len;
787 : 0 : cpt_inst_w4.s.dlen = data_len + RTE_ALIGN_CEIL(key_len, 8);
788 : : } else {
789 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_HASH;
790 : 0 : cpt_inst_w4.s.param1 = 0;
791 : 0 : cpt_inst_w4.s.dlen = data_len;
792 : : }
793 : :
794 : : /* DPTR has SG list */
795 : :
796 : : /* TODO Add error check if space will be sufficient */
797 : : gather_comp = (struct roc_sg2list_comp *)((uint8_t *)m_vaddr + 0);
798 : :
799 : : /*
800 : : * Input gather list
801 : : */
802 : :
803 : : i = 0;
804 : :
805 [ # # # # : 0 : if (ctx->hmac) {
# # ]
806 : 0 : uint64_t k_vaddr = (uint64_t)ctx->auth_key;
807 : : /* Key */
808 : 0 : i = fill_sg2_comp(gather_comp, i, k_vaddr, RTE_ALIGN_CEIL(key_len, 8));
809 : : }
810 : :
811 : : /* input data */
812 : 0 : size = data_len;
813 : : i = fill_sg2_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0);
814 [ # # # # : 0 : if (unlikely(size)) {
# # ]
815 : 0 : plt_dp_err("Insufficient dst IOV size, short by %dB", size);
816 : : return -1;
817 : : }
818 : :
819 : 0 : gather_sz = (i + 2) / 3;
820 : 0 : g_size_bytes = gather_sz * sizeof(struct roc_sg2list_comp);
821 : :
822 : : /*
823 : : * Output Gather list
824 : : */
825 : :
826 : : i = 0;
827 : 0 : scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
828 : :
829 : : if (flags & ROC_SE_VALID_MAC_BUF) {
830 [ # # # # : 0 : if (unlikely(params->mac_buf.size < mac_len)) {
# # ]
831 : 0 : plt_dp_err("Insufficient MAC size");
832 : : return -1;
833 : : }
834 : :
835 : : size = mac_len;
836 : : i = fill_sg2_comp_from_buf_min(scatter_comp, i, ¶ms->mac_buf, &size);
837 : : } else {
838 : : size = mac_len;
839 : : i = fill_sg2_comp_from_iov(scatter_comp, i, params->src_iov, data_len, &size, NULL,
840 : : 0);
841 : : if (unlikely(size)) {
842 : : plt_dp_err("Insufficient dst IOV size, short by %dB", size);
843 : : return -1;
844 : : }
845 : : }
846 : :
847 : : scatter_sz = (i + 2) / 3;
848 : :
849 : 0 : cpt_inst_w5.s.gather_sz = gather_sz;
850 : 0 : cpt_inst_w6.s.scatter_sz = scatter_sz;
851 : :
852 : 0 : cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
853 : 0 : cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
854 : :
855 : 0 : inst->w5.u64 = cpt_inst_w5.u64;
856 : 0 : inst->w6.u64 = cpt_inst_w6.u64;
857 : :
858 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
859 : :
860 [ # # # # : 0 : if (unlikely((scatter_sz >> 4) || (gather_sz >> 4))) {
# # ]
861 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
862 : : ret = -1;
863 : : }
864 : :
865 : : return ret;
866 : : }
867 : :
868 : : static inline int
869 : 0 : pdcp_chain_sg1_prep(struct roc_se_fc_params *params, struct roc_se_ctx *cpt_ctx,
870 : : struct cpt_inst_s *inst, union cpt_inst_w4 w4, int32_t inputlen,
871 : : uint8_t hdr_len, uint64_t offset_ctrl, uint32_t req_flags,
872 : : const uint8_t *cipher_iv, const uint8_t *auth_iv, const int pack_iv,
873 : : const uint8_t pdcp_ci_alg, const uint8_t pdcp_auth_alg)
874 : : {
875 : : struct roc_sglist_comp *scatter_comp, *gather_comp;
876 : 0 : void *m_vaddr = params->meta_buf.vaddr;
877 : : uint32_t i, g_size_bytes, s_size_bytes;
878 : : const uint32_t mac_len = 4;
879 : : uint8_t *iv_d, *in_buffer;
880 : : uint64_t *offset_vaddr;
881 : : uint32_t size;
882 : : int ret = 0;
883 : :
884 : : /* save space for IV */
885 : : offset_vaddr = m_vaddr;
886 : :
887 : 0 : m_vaddr = PLT_PTR_ADD(m_vaddr, ROC_SE_OFF_CTRL_LEN + PLT_ALIGN_CEIL(hdr_len, 8));
888 : :
889 : 0 : w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
890 : :
891 : : /* DPTR has SG list */
892 : : in_buffer = m_vaddr;
893 : :
894 : 0 : ((uint16_t *)in_buffer)[0] = 0;
895 : 0 : ((uint16_t *)in_buffer)[1] = 0;
896 : :
897 : 0 : gather_comp = PLT_PTR_ADD(m_vaddr, 8);
898 : :
899 : : /* Input Gather List */
900 : : i = 0;
901 : :
902 : : /* Offset control word followed by IV */
903 : :
904 [ # # ]: 0 : i = fill_sg_comp(gather_comp, i, (uint64_t)offset_vaddr, ROC_SE_OFF_CTRL_LEN + hdr_len);
905 : :
906 : 0 : *(uint64_t *)offset_vaddr = offset_ctrl;
907 : :
908 : : /* Cipher IV */
909 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
910 : 0 : pdcp_iv_copy(iv_d, cipher_iv, pdcp_ci_alg, pack_iv);
911 : :
912 : : /* Auth IV */
913 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN + params->pdcp_iv_offset);
914 : 0 : pdcp_iv_copy(iv_d, auth_iv, pdcp_auth_alg, pack_iv);
915 : :
916 : : /* input data */
917 : 0 : size = inputlen - hdr_len;
918 [ # # ]: 0 : if (size) {
919 : 0 : i = fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0);
920 [ # # ]: 0 : if (unlikely(size)) {
921 : 0 : plt_dp_err("Insufficient buffer space, size %d needed", size);
922 : 0 : return -1;
923 : : }
924 : : }
925 [ # # ]: 0 : ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
926 : 0 : g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
927 : :
928 : : /*
929 : : * Output Scatter List
930 : : */
931 : :
932 : : i = 0;
933 : 0 : scatter_comp = PLT_PTR_ADD(gather_comp, g_size_bytes);
934 : :
935 [ # # ]: 0 : if ((hdr_len)) {
936 [ # # ]: 0 : i = fill_sg_comp(scatter_comp, i, (uint64_t)offset_vaddr + ROC_SE_OFF_CTRL_LEN,
937 : : hdr_len);
938 : : }
939 : :
940 : : /* Add output data */
941 [ # # # # ]: 0 : if (cpt_ctx->ciph_then_auth && (req_flags & ROC_SE_VALID_MAC_BUF))
942 : 0 : size = inputlen;
943 : : else
944 : : /* Output including mac */
945 : 0 : size = inputlen + mac_len;
946 : :
947 : 0 : size -= hdr_len;
948 : :
949 [ # # ]: 0 : if (size) {
950 : 0 : i = fill_sg_comp_from_iov(scatter_comp, i, params->dst_iov, 0, &size, NULL, 0);
951 : :
952 [ # # ]: 0 : if (unlikely(size)) {
953 : 0 : plt_dp_err("Insufficient buffer space, size %d needed", size);
954 : 0 : return -1;
955 : : }
956 : : }
957 : :
958 [ # # ]: 0 : ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
959 : 0 : s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
960 : :
961 : 0 : size = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
962 : :
963 [ # # ]: 0 : if (unlikely(size > ROC_SG_MAX_DLEN_SIZE)) {
964 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
965 : : ret = -1;
966 : : }
967 : :
968 : : /* This is DPTR len in case of SG mode */
969 : 0 : w4.s.dlen = size;
970 : 0 : inst->w4.u64 = w4.u64;
971 : :
972 : 0 : inst->dptr = (uint64_t)in_buffer;
973 : :
974 : 0 : return ret;
975 : : }
976 : :
977 : : static inline int
978 : 0 : pdcp_chain_sg2_prep(struct roc_se_fc_params *params, struct roc_se_ctx *cpt_ctx,
979 : : struct cpt_inst_s *inst, union cpt_inst_w4 w4, int32_t inputlen,
980 : : uint8_t hdr_len, uint64_t offset_ctrl, uint32_t req_flags,
981 : : const uint8_t *cipher_iv, const uint8_t *auth_iv, const int pack_iv,
982 : : const uint8_t pdcp_ci_alg, const uint8_t pdcp_auth_alg)
983 : : {
984 : : struct roc_sg2list_comp *gather_comp, *scatter_comp;
985 : 0 : void *m_vaddr = params->meta_buf.vaddr;
986 : : uint16_t scatter_sz, gather_sz;
987 : : const uint32_t mac_len = 4;
988 : : uint32_t i, g_size_bytes;
989 : : uint64_t *offset_vaddr;
990 : : union cpt_inst_w5 w5;
991 : : union cpt_inst_w6 w6;
992 : : uint8_t *iv_d;
993 : : uint32_t size;
994 : : int ret = 0;
995 : :
996 : : /* save space for IV */
997 : : offset_vaddr = m_vaddr;
998 : :
999 : 0 : m_vaddr = PLT_PTR_ADD(m_vaddr, ROC_SE_OFF_CTRL_LEN + RTE_ALIGN_CEIL(hdr_len, 8));
1000 : :
1001 : 0 : w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
1002 : 0 : w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1003 : :
1004 : : gather_comp = m_vaddr;
1005 : :
1006 : : /* Input Gather List */
1007 : : i = 0;
1008 : :
1009 : : /* Offset control word followed by IV */
1010 : 0 : *(uint64_t *)offset_vaddr = offset_ctrl;
1011 : :
1012 : 0 : i = fill_sg2_comp(gather_comp, i, (uint64_t)offset_vaddr, ROC_SE_OFF_CTRL_LEN + hdr_len);
1013 : :
1014 : : /* Cipher IV */
1015 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
1016 : 0 : pdcp_iv_copy(iv_d, cipher_iv, pdcp_ci_alg, pack_iv);
1017 : :
1018 : : /* Auth IV */
1019 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN + params->pdcp_iv_offset);
1020 : 0 : pdcp_iv_copy(iv_d, auth_iv, pdcp_auth_alg, pack_iv);
1021 : :
1022 : : /* input data */
1023 : 0 : size = inputlen - hdr_len;
1024 [ # # ]: 0 : if (size) {
1025 : 0 : i = fill_sg2_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0);
1026 [ # # ]: 0 : if (unlikely(size)) {
1027 : 0 : plt_dp_err("Insufficient buffer space, size %d needed", size);
1028 : 0 : return -1;
1029 : : }
1030 : : }
1031 : :
1032 : 0 : gather_sz = (i + 2) / 3;
1033 : 0 : g_size_bytes = gather_sz * sizeof(struct roc_sg2list_comp);
1034 : :
1035 : : /*
1036 : : * Output Scatter List
1037 : : */
1038 : :
1039 : : i = 0;
1040 : 0 : scatter_comp = PLT_PTR_ADD(gather_comp, g_size_bytes);
1041 : :
1042 [ # # ]: 0 : if ((hdr_len))
1043 : 0 : i = fill_sg2_comp(scatter_comp, i, (uint64_t)(offset_vaddr) + ROC_SE_OFF_CTRL_LEN,
1044 : : hdr_len);
1045 : :
1046 : : /* Add output data */
1047 [ # # # # ]: 0 : if (cpt_ctx->ciph_then_auth && (req_flags & ROC_SE_VALID_MAC_BUF))
1048 : 0 : size = inputlen;
1049 : : else
1050 : : /* Output including mac */
1051 : 0 : size = inputlen + mac_len;
1052 : :
1053 : 0 : size -= hdr_len;
1054 : :
1055 [ # # ]: 0 : if (size) {
1056 : 0 : i = fill_sg2_comp_from_iov(scatter_comp, i, params->dst_iov, 0, &size, NULL, 0);
1057 : :
1058 [ # # ]: 0 : if (unlikely(size)) {
1059 : 0 : plt_dp_err("Insufficient buffer space, size %d needed", size);
1060 : 0 : return -1;
1061 : : }
1062 : : }
1063 : :
1064 : 0 : scatter_sz = (i + 2) / 3;
1065 : :
1066 : 0 : w5.s.gather_sz = gather_sz;
1067 : 0 : w6.s.scatter_sz = scatter_sz;
1068 : :
1069 : 0 : w5.s.dptr = (uint64_t)gather_comp;
1070 : 0 : w6.s.rptr = (uint64_t)scatter_comp;
1071 : :
1072 : 0 : inst->w4.u64 = w4.u64;
1073 : 0 : inst->w5.u64 = w5.u64;
1074 : 0 : inst->w6.u64 = w6.u64;
1075 : :
1076 [ # # # # ]: 0 : if (unlikely((scatter_sz >> 4) || (gather_sz >> 4))) {
1077 : 0 : plt_dp_err("Exceeds max supported components. Reduce segments");
1078 : : ret = -1;
1079 : : }
1080 : :
1081 : : return ret;
1082 : : }
1083 : :
1084 : : static __rte_always_inline int
1085 : : cpt_sm_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens, struct roc_se_fc_params *fc_params,
1086 : : struct cpt_inst_s *inst, const bool is_sg_ver2, int decrypt)
1087 : : {
1088 : : int32_t inputlen, outputlen, enc_dlen;
1089 : : union cpt_inst_w4 cpt_inst_w4;
1090 : : uint32_t passthrough_len = 0;
1091 : : const uint8_t *src = NULL;
1092 : : struct roc_se_ctx *se_ctx;
1093 : : uint32_t encr_data_len;
1094 : : uint32_t encr_offset;
1095 : : uint64_t offset_ctrl;
1096 : : uint8_t iv_len = 16;
1097 : : void *offset_vaddr;
1098 : : int ret;
1099 : :
1100 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs);
1101 : : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1102 : :
1103 : : se_ctx = fc_params->ctx;
1104 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1105 : :
1106 [ # # # # ]: 0 : if (unlikely(!(flags & ROC_SE_VALID_IV_BUF)))
1107 : : iv_len = 0;
1108 : :
1109 : 0 : encr_offset += iv_len;
1110 : 0 : enc_dlen = RTE_ALIGN_CEIL(encr_data_len, 8) + encr_offset;
1111 : :
1112 : : inputlen = enc_dlen;
1113 : : outputlen = enc_dlen;
1114 : :
1115 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1116 : :
1117 [ # # # # ]: 0 : if (unlikely(encr_offset >> 8)) {
1118 : 0 : plt_dp_err("Offset not supported");
1119 : 0 : plt_dp_err("enc_offset: %d", encr_offset);
1120 : 0 : return -1;
1121 : : }
1122 : :
1123 [ # # # # ]: 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)encr_offset);
1124 : :
1125 : : /*
1126 : : * In cn9k, cn10k since we have a limitation of
1127 : : * IV & Offset control word not part of instruction
1128 : : * and need to be part of Data Buffer, we check if
1129 : : * head room is there and then only do the Direct mode processing
1130 : : */
1131 [ # # # # ]: 0 : if (likely((flags & ROC_SE_SINGLE_BUF_INPLACE) && (flags & ROC_SE_SINGLE_BUF_HEADROOM))) {
1132 : : void *dm_vaddr = fc_params->bufs[0].vaddr;
1133 : :
1134 : : /* Use Direct mode */
1135 : :
1136 : 0 : offset_vaddr = PLT_PTR_SUB(dm_vaddr, ROC_SE_OFF_CTRL_LEN + iv_len);
1137 : 0 : *(uint64_t *)offset_vaddr = offset_ctrl;
1138 : :
1139 : : /* DPTR */
1140 : 0 : inst->dptr = (uint64_t)offset_vaddr;
1141 : :
1142 : : /* RPTR should just exclude offset control word */
1143 : 0 : inst->rptr = (uint64_t)dm_vaddr - iv_len;
1144 : :
1145 : 0 : cpt_inst_w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1146 : :
1147 [ # # # # ]: 0 : if (likely(iv_len)) {
1148 [ # # # # ]: 0 : void *dst = PLT_PTR_ADD(offset_vaddr, ROC_SE_OFF_CTRL_LEN);
1149 : : const uint64_t *src = fc_params->iv_buf;
1150 : :
1151 : : rte_memcpy(dst, src, 16);
1152 : : }
1153 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1154 : : } else {
1155 [ # # # # ]: 0 : if (likely(iv_len))
1156 : : src = fc_params->iv_buf;
1157 : :
1158 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1159 : :
1160 [ # # # # ]: 0 : if (is_sg_ver2)
1161 [ # # # # ]: 0 : ret = sg2_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
1162 : : inputlen, outputlen, passthrough_len, flags, 0,
1163 : : decrypt);
1164 : : else
1165 [ # # # # ]: 0 : ret = sg_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
1166 : : inputlen, outputlen, passthrough_len, flags, 0, decrypt);
1167 : :
1168 [ # # # # ]: 0 : if (unlikely(ret)) {
1169 : 0 : plt_dp_err("sg prep failed");
1170 : 0 : return -1;
1171 : : }
1172 : : }
1173 : :
1174 : : return 0;
1175 : : }
1176 : :
1177 : : static __rte_always_inline int
1178 : : cpt_enc_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens,
1179 : : struct roc_se_fc_params *fc_params, struct cpt_inst_s *inst,
1180 : : const bool is_sg_ver2)
1181 : : {
1182 : : uint32_t encr_data_len, auth_data_len, aad_len = 0;
1183 : : uint32_t encr_offset, auth_offset, iv_offset = 0;
1184 : : int32_t inputlen, outputlen, enc_dlen, auth_dlen;
1185 : : uint32_t cipher_type, hash_type;
1186 : : union cpt_inst_w4 cpt_inst_w4;
1187 : : uint32_t passthrough_len = 0;
1188 : : const uint8_t *src = NULL;
1189 : : struct roc_se_ctx *se_ctx;
1190 : : uint64_t offset_ctrl;
1191 : : uint8_t iv_len = 16;
1192 : : void *offset_vaddr;
1193 : : uint8_t op_minor;
1194 : : uint32_t mac_len;
1195 : : int ret;
1196 : :
1197 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs);
1198 : 0 : auth_offset = ROC_SE_AUTH_OFFSET(d_offs);
1199 : 0 : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1200 : 0 : auth_data_len = ROC_SE_AUTH_DLEN(d_lens);
1201 [ # # # # : 0 : if (unlikely(flags & ROC_SE_VALID_AAD_BUF)) {
# # ]
1202 : : /* We don't support both AAD and auth data separately */
1203 : : auth_data_len = 0;
1204 : : auth_offset = 0;
1205 : 0 : aad_len = fc_params->aad_buf.size;
1206 : : }
1207 : :
1208 : : se_ctx = fc_params->ctx;
1209 : 0 : cipher_type = se_ctx->enc_cipher;
1210 : 0 : hash_type = se_ctx->hash_type;
1211 : 0 : mac_len = se_ctx->mac_len;
1212 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1213 : : op_minor = cpt_inst_w4.s.opcode_minor;
1214 : :
1215 [ # # # # : 0 : if (unlikely(!(flags & ROC_SE_VALID_IV_BUF))) {
# # # # #
# # # ]
1216 : : iv_len = 0;
1217 : 0 : iv_offset = ROC_SE_ENCR_IV_OFFSET(d_offs);
1218 : : }
1219 : :
1220 [ # # # # : 0 : if (unlikely(flags & ROC_SE_VALID_AAD_BUF)) {
# # ]
1221 : : /*
1222 : : * When AAD is given, data above encr_offset is pass through
1223 : : * Since AAD is given as separate pointer and not as offset,
1224 : : * this is a special case as we need to fragment input data
1225 : : * into passthrough + encr_data and then insert AAD in between.
1226 : : */
1227 [ # # # # : 0 : if (hash_type != ROC_SE_GMAC_TYPE) {
# # ]
1228 : : passthrough_len = encr_offset;
1229 : 0 : auth_offset = passthrough_len + iv_len;
1230 : 0 : encr_offset = passthrough_len + aad_len + iv_len;
1231 : 0 : auth_data_len = aad_len + encr_data_len;
1232 : : } else {
1233 : 0 : passthrough_len = 16 + aad_len;
1234 : 0 : auth_offset = passthrough_len + iv_len;
1235 : : auth_data_len = aad_len;
1236 : : }
1237 : : } else {
1238 : 0 : encr_offset += iv_len;
1239 : 0 : auth_offset += iv_len;
1240 : : }
1241 : :
1242 : : /* Encryption */
1243 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_FC;
1244 : : cpt_inst_w4.s.opcode_minor |= ROC_SE_FC_MINOR_OP_ENCRYPT;
1245 : :
1246 [ # # # # : 0 : if (hash_type == ROC_SE_GMAC_TYPE) {
# # # # #
# # # # #
# # ]
1247 : : encr_offset = 0;
1248 : : encr_data_len = 0;
1249 : : }
1250 : :
1251 : 0 : auth_dlen = auth_offset + auth_data_len;
1252 : 0 : enc_dlen = encr_data_len + encr_offset;
1253 [ # # # # : 0 : if (unlikely(encr_data_len & 0xf)) {
# # # # #
# # # ]
1254 [ # # # # : 0 : if ((cipher_type == ROC_SE_DES3_CBC) ||
# # # # #
# # # ]
1255 : : (cipher_type == ROC_SE_DES3_ECB))
1256 : 0 : enc_dlen =
1257 : 0 : RTE_ALIGN_CEIL(encr_data_len, 8) + encr_offset;
1258 [ # # # # : 0 : else if (likely((cipher_type == ROC_SE_AES_CBC) ||
# # # # #
# # # ]
1259 : : (cipher_type == ROC_SE_AES_ECB)))
1260 : 0 : enc_dlen =
1261 : 0 : RTE_ALIGN_CEIL(encr_data_len, 8) + encr_offset;
1262 : : }
1263 : :
1264 [ # # # # : 0 : if (unlikely(auth_dlen > enc_dlen)) {
# # # # #
# # # # #
# # # # ]
1265 : : inputlen = auth_dlen;
1266 : 0 : outputlen = auth_dlen + mac_len;
1267 : : } else {
1268 : : inputlen = enc_dlen;
1269 : 0 : outputlen = enc_dlen + mac_len;
1270 : : }
1271 : :
1272 [ # # # # : 0 : if (op_minor & ROC_SE_FC_MINOR_OP_HMAC_FIRST)
# # # # #
# # # # #
# # # # ]
1273 : : outputlen = enc_dlen;
1274 : :
1275 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1276 : 0 : cpt_inst_w4.s.param2 = auth_data_len;
1277 : :
1278 [ # # # # : 0 : if (unlikely((encr_offset >> 16) || (iv_offset >> 8) || (auth_offset >> 8))) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1279 : 0 : plt_dp_err("Offset not supported");
1280 : 0 : plt_dp_err("enc_offset: %d", encr_offset);
1281 : 0 : plt_dp_err("iv_offset : %d", iv_offset);
1282 : 0 : plt_dp_err("auth_offset: %d", auth_offset);
1283 : 0 : return -1;
1284 : : }
1285 : :
1286 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64(((uint64_t)encr_offset << 16) | ((uint64_t)iv_offset << 8) |
# # # # #
# # # # #
# # # # ]
1287 : : ((uint64_t)auth_offset));
1288 : :
1289 : : /*
1290 : : * In cn9k, cn10k since we have a limitation of
1291 : : * IV & Offset control word not part of instruction
1292 : : * and need to be part of Data Buffer, we check if
1293 : : * head room is there and then only do the Direct mode processing
1294 : : */
1295 [ # # # # : 0 : if (likely((flags & ROC_SE_SINGLE_BUF_INPLACE) &&
# # # # ]
1296 : : (flags & ROC_SE_SINGLE_BUF_HEADROOM))) {
1297 : 0 : void *dm_vaddr = fc_params->bufs[0].vaddr;
1298 : :
1299 : : /* Use Direct mode */
1300 : :
1301 : 0 : offset_vaddr = (uint8_t *)dm_vaddr - ROC_SE_OFF_CTRL_LEN - iv_len;
1302 : :
1303 : 0 : *(uint64_t *)offset_vaddr =
1304 [ # # # # : 0 : rte_cpu_to_be_64(((uint64_t)encr_offset << 16) |
# # # # ]
1305 : : ((uint64_t)iv_offset << 8) | ((uint64_t)auth_offset));
1306 : :
1307 : : /* DPTR */
1308 : 0 : inst->dptr = (uint64_t)offset_vaddr;
1309 : :
1310 : : /* RPTR should just exclude offset control word */
1311 : 0 : inst->rptr = (uint64_t)dm_vaddr - iv_len;
1312 : :
1313 : 0 : cpt_inst_w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1314 : :
1315 [ # # # # : 0 : if (likely(iv_len)) {
# # # # ]
1316 : : uint64_t *dest =
1317 : : (uint64_t *)((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
1318 : 0 : const uint64_t *src = fc_params->iv_buf;
1319 : 0 : dest[0] = src[0];
1320 : 0 : dest[1] = src[1];
1321 : : }
1322 : :
1323 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1324 : : } else {
1325 [ # # # # : 0 : if (likely(iv_len))
# # # # #
# # # ]
1326 : 0 : src = fc_params->iv_buf;
1327 : :
1328 [ # # # # ]: 0 : inst->w4.u64 = cpt_inst_w4.u64;
1329 : :
1330 [ # # # # : 0 : if (is_sg_ver2)
# # # # #
# # # # #
# # # # ]
1331 [ # # # # : 0 : ret = sg2_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
# # # # #
# # # ]
1332 : : inputlen, outputlen, passthrough_len, flags, 0, 0);
1333 : : else
1334 [ # # # # : 0 : ret = sg_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
# # # # #
# # # ]
1335 : : inputlen, outputlen, passthrough_len, flags, 0, 0);
1336 : :
1337 [ # # # # : 0 : if (unlikely(ret)) {
# # # # #
# # # # #
# # # # ]
1338 : 0 : plt_dp_err("sg prep failed");
1339 : 0 : return -1;
1340 : : }
1341 : : }
1342 : :
1343 : : return 0;
1344 : : }
1345 : :
1346 : : static __rte_always_inline int
1347 : : cpt_dec_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens,
1348 : : struct roc_se_fc_params *fc_params, struct cpt_inst_s *inst,
1349 : : const bool is_sg_ver2)
1350 : : {
1351 : : uint32_t encr_data_len, auth_data_len, aad_len = 0;
1352 : : uint32_t encr_offset, auth_offset, iv_offset = 0;
1353 : : int32_t inputlen, outputlen, enc_dlen, auth_dlen;
1354 : : union cpt_inst_w4 cpt_inst_w4;
1355 : : uint32_t passthrough_len = 0;
1356 : : int32_t hash_type, mac_len;
1357 : : const uint8_t *src = NULL;
1358 : : struct roc_se_ctx *se_ctx;
1359 : : uint64_t offset_ctrl;
1360 : : uint8_t iv_len = 16;
1361 : : void *offset_vaddr;
1362 : : uint8_t op_minor;
1363 : : int ret;
1364 : :
1365 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs);
1366 : 0 : auth_offset = ROC_SE_AUTH_OFFSET(d_offs);
1367 : 0 : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1368 : 0 : auth_data_len = ROC_SE_AUTH_DLEN(d_lens);
1369 : :
1370 [ # # # # : 0 : if (unlikely(flags & ROC_SE_VALID_AAD_BUF)) {
# # ]
1371 : : /* We don't support both AAD and auth data separately */
1372 : : auth_data_len = 0;
1373 : : auth_offset = 0;
1374 : 0 : aad_len = fc_params->aad_buf.size;
1375 : : }
1376 : :
1377 : : se_ctx = fc_params->ctx;
1378 : 0 : hash_type = se_ctx->hash_type;
1379 : 0 : mac_len = se_ctx->mac_len;
1380 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1381 : : op_minor = cpt_inst_w4.s.opcode_minor;
1382 : :
1383 [ # # # # : 0 : if (unlikely(!(flags & ROC_SE_VALID_IV_BUF))) {
# # # # #
# # # ]
1384 : : iv_len = 0;
1385 : 0 : iv_offset = ROC_SE_ENCR_IV_OFFSET(d_offs);
1386 : : }
1387 : :
1388 [ # # # # : 0 : if (unlikely(flags & ROC_SE_VALID_AAD_BUF)) {
# # ]
1389 : : /*
1390 : : * When AAD is given, data above encr_offset is pass through
1391 : : * Since AAD is given as separate pointer and not as offset,
1392 : : * this is a special case as we need to fragment input data
1393 : : * into passthrough + encr_data and then insert AAD in between.
1394 : : */
1395 [ # # # # : 0 : if (hash_type != ROC_SE_GMAC_TYPE) {
# # ]
1396 : : passthrough_len = encr_offset;
1397 : 0 : auth_offset = passthrough_len + iv_len;
1398 : 0 : encr_offset = passthrough_len + aad_len + iv_len;
1399 : 0 : auth_data_len = aad_len + encr_data_len;
1400 : : } else {
1401 : 0 : passthrough_len = 16 + aad_len;
1402 : 0 : auth_offset = passthrough_len + iv_len;
1403 : : auth_data_len = aad_len;
1404 : : }
1405 : : } else {
1406 : 0 : encr_offset += iv_len;
1407 : 0 : auth_offset += iv_len;
1408 : : }
1409 : :
1410 : : /* Decryption */
1411 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_FC;
1412 : : cpt_inst_w4.s.opcode_minor = ROC_SE_FC_MINOR_OP_DECRYPT;
1413 : 0 : cpt_inst_w4.s.opcode_minor |= (uint64_t)op_minor;
1414 : :
1415 [ # # # # : 0 : if (hash_type == ROC_SE_GMAC_TYPE) {
# # # # #
# # # ]
1416 : : encr_offset = 0;
1417 : : encr_data_len = 0;
1418 : : }
1419 : :
1420 : 0 : enc_dlen = encr_offset + encr_data_len;
1421 : 0 : auth_dlen = auth_offset + auth_data_len;
1422 : :
1423 [ # # # # : 0 : if (auth_dlen > enc_dlen) {
# # # # #
# # # ]
1424 : 0 : inputlen = auth_dlen + mac_len;
1425 : : outputlen = auth_dlen;
1426 : : } else {
1427 : 0 : inputlen = enc_dlen + mac_len;
1428 : : outputlen = enc_dlen;
1429 : : }
1430 : :
1431 [ # # # # : 0 : if (op_minor & ROC_SE_FC_MINOR_OP_HMAC_FIRST)
# # # # #
# # # ]
1432 : : outputlen = inputlen = enc_dlen;
1433 : :
1434 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1435 : 0 : cpt_inst_w4.s.param2 = auth_data_len;
1436 : :
1437 [ # # # # : 0 : if (unlikely((encr_offset >> 16) || (iv_offset >> 8) || (auth_offset >> 8))) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1438 : 0 : plt_dp_err("Offset not supported");
1439 : 0 : plt_dp_err("enc_offset: %d", encr_offset);
1440 : 0 : plt_dp_err("iv_offset : %d", iv_offset);
1441 : 0 : plt_dp_err("auth_offset: %d", auth_offset);
1442 : 0 : return -1;
1443 : : }
1444 : :
1445 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64(((uint64_t)encr_offset << 16) | ((uint64_t)iv_offset << 8) |
# # # # #
# # # ]
1446 : : ((uint64_t)auth_offset));
1447 : :
1448 : : /*
1449 : : * In cn9k, cn10k since we have a limitation of
1450 : : * IV & Offset control word not part of instruction
1451 : : * and need to be part of Data Buffer, we check if
1452 : : * head room is there and then only do the Direct mode processing
1453 : : */
1454 [ # # # # : 0 : if (likely((flags & ROC_SE_SINGLE_BUF_INPLACE) && (flags & ROC_SE_SINGLE_BUF_HEADROOM))) {
# # # # ]
1455 : 0 : void *dm_vaddr = fc_params->bufs[0].vaddr;
1456 : :
1457 : : /* Use Direct mode */
1458 : :
1459 : 0 : offset_vaddr = (uint8_t *)dm_vaddr - ROC_SE_OFF_CTRL_LEN - iv_len;
1460 : :
1461 : 0 : *(uint64_t *)offset_vaddr =
1462 [ # # # # : 0 : rte_cpu_to_be_64(((uint64_t)encr_offset << 16) |
# # # # ]
1463 : : ((uint64_t)iv_offset << 8) | ((uint64_t)auth_offset));
1464 : :
1465 : 0 : inst->dptr = (uint64_t)offset_vaddr;
1466 : :
1467 : : /* RPTR should just exclude offset control word */
1468 : 0 : inst->rptr = (uint64_t)dm_vaddr - iv_len;
1469 : :
1470 : 0 : cpt_inst_w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1471 : :
1472 [ # # # # : 0 : if (likely(iv_len)) {
# # # # ]
1473 : : uint64_t *dest =
1474 : : (uint64_t *)((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
1475 : 0 : const uint64_t *src = fc_params->iv_buf;
1476 : 0 : dest[0] = src[0];
1477 : 0 : dest[1] = src[1];
1478 : : }
1479 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1480 : :
1481 : : } else {
1482 [ # # # # : 0 : if (likely(iv_len)) {
# # # # #
# # # ]
1483 : 0 : src = fc_params->iv_buf;
1484 : : }
1485 : :
1486 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1487 : :
1488 [ # # # # : 0 : if (is_sg_ver2)
# # # # #
# # # ]
1489 [ # # # # : 0 : ret = sg2_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
# # # # #
# # # ]
1490 : : inputlen, outputlen, passthrough_len, flags, 0, 1);
1491 : : else
1492 [ # # # # : 0 : ret = sg_inst_prep(fc_params, inst, offset_ctrl, src, iv_len, 0, 0,
# # # # #
# # # ]
1493 : : inputlen, outputlen, passthrough_len, flags, 0, 1);
1494 [ # # # # : 0 : if (unlikely(ret)) {
# # # # #
# # # ]
1495 : 0 : plt_dp_err("sg prep failed");
1496 : 0 : return -1;
1497 : : }
1498 : : }
1499 : :
1500 : : return 0;
1501 : : }
1502 : :
1503 : : static __rte_always_inline int
1504 : : cpt_pdcp_chain_alg_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens,
1505 : : struct roc_se_fc_params *params, struct cpt_inst_s *inst,
1506 : : const bool is_sg_ver2)
1507 : : {
1508 : : uint32_t encr_data_len, auth_data_len, aad_len, passthr_len, pad_len, hdr_len;
1509 : : uint32_t encr_offset, auth_offset, iv_offset = 0;
1510 : : const uint8_t *auth_iv = NULL, *cipher_iv = NULL;
1511 : 0 : uint8_t pdcp_iv_off = params->pdcp_iv_offset;
1512 : 0 : const int iv_len = pdcp_iv_off * 2;
1513 : : uint8_t pdcp_ci_alg, pdcp_auth_alg;
1514 : : union cpt_inst_w4 cpt_inst_w4;
1515 : : struct roc_se_ctx *se_ctx;
1516 : : uint64_t *offset_vaddr;
1517 : : uint64_t offset_ctrl;
1518 : : uint8_t pack_iv = 0;
1519 : : int32_t inputlen;
1520 : : void *dm_vaddr;
1521 : : uint8_t *iv_d;
1522 : :
1523 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs);
1524 : 0 : auth_offset = ROC_SE_AUTH_OFFSET(d_offs);
1525 : :
1526 : 0 : aad_len = encr_offset - auth_offset;
1527 : :
1528 : : if (unlikely(encr_offset >> 16)) {
1529 : : plt_dp_err("Offset not supported");
1530 : : plt_dp_err("enc_offset: %d", encr_offset);
1531 : : return -1;
1532 : : }
1533 : :
1534 : 0 : se_ctx = params->ctx;
1535 : 0 : pdcp_ci_alg = se_ctx->pdcp_ci_alg;
1536 : 0 : pdcp_auth_alg = se_ctx->pdcp_auth_alg;
1537 : :
1538 : 0 : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1539 : 0 : auth_data_len = ROC_SE_AUTH_DLEN(d_lens);
1540 : 0 : auth_data_len -= aad_len;
1541 : :
1542 : 0 : encr_offset += iv_len;
1543 : 0 : auth_offset = encr_offset - aad_len;
1544 : 0 : passthr_len = RTE_ALIGN_CEIL(auth_offset, 8);
1545 : :
1546 [ # # # # ]: 0 : if (unlikely((aad_len >> 16) || (passthr_len >> 8))) {
1547 : 0 : plt_dp_err("Length not supported");
1548 : 0 : plt_dp_err("AAD_len: %d", aad_len);
1549 : 0 : plt_dp_err("Passthrough_len: %d", passthr_len);
1550 : 0 : return -1;
1551 : : }
1552 : :
1553 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1554 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_PDCP_CHAIN;
1555 : :
1556 : 0 : cpt_inst_w4.s.param1 = auth_data_len;
1557 : 0 : cpt_inst_w4.s.param2 = 0;
1558 : :
1559 [ # # # # ]: 0 : if (likely(params->auth_iv_len))
1560 : 0 : auth_iv = params->auth_iv_buf;
1561 : :
1562 [ # # # # ]: 0 : if (likely(params->cipher_iv_len))
1563 : 0 : cipher_iv = params->iv_buf;
1564 : :
1565 : 0 : pad_len = passthr_len - auth_offset;
1566 : 0 : hdr_len = iv_len + pad_len;
1567 : :
1568 [ # # # # ]: 0 : if (se_ctx->auth_then_ciph)
1569 : 0 : inputlen = auth_data_len;
1570 : : else
1571 : 0 : inputlen = encr_data_len;
1572 : :
1573 : 0 : inputlen += (encr_offset + pad_len);
1574 : :
1575 [ # # # # ]: 0 : offset_ctrl = rte_cpu_to_be_64(((uint64_t)(aad_len) << 16) | ((uint64_t)(iv_offset) << 8) |
1576 : : ((uint64_t)(passthr_len)));
1577 : :
1578 [ # # # # ]: 0 : if (likely(((req_flags & ROC_SE_SINGLE_BUF_INPLACE)) &&
1579 : : ((req_flags & ROC_SE_SINGLE_BUF_HEADROOM)))) {
1580 : :
1581 : 0 : dm_vaddr = params->bufs[0].vaddr;
1582 : :
1583 : : /* Use Direct mode */
1584 : :
1585 : 0 : offset_vaddr = PLT_PTR_SUB(dm_vaddr, ROC_SE_OFF_CTRL_LEN + hdr_len);
1586 : 0 : *offset_vaddr = offset_ctrl;
1587 : :
1588 : : /* DPTR */
1589 : 0 : inst->dptr = (uint64_t)offset_vaddr;
1590 : : /* RPTR should just exclude offset control word */
1591 : 0 : inst->rptr = (uint64_t)PLT_PTR_SUB(dm_vaddr, hdr_len);
1592 : :
1593 : 0 : cpt_inst_w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1594 : :
1595 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
1596 : 0 : pdcp_iv_copy(iv_d, cipher_iv, pdcp_ci_alg, pack_iv);
1597 : :
1598 : 0 : iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN + pdcp_iv_off);
1599 : 0 : pdcp_iv_copy(iv_d, auth_iv, pdcp_auth_alg, pack_iv);
1600 : :
1601 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1602 : 0 : return 0;
1603 : :
1604 : : } else {
1605 [ # # # # ]: 0 : if (is_sg_ver2)
1606 : 0 : return pdcp_chain_sg2_prep(params, se_ctx, inst, cpt_inst_w4, inputlen,
1607 : : hdr_len, offset_ctrl, req_flags, cipher_iv,
1608 : : auth_iv, pack_iv, pdcp_ci_alg, pdcp_auth_alg);
1609 : : else
1610 : 0 : return pdcp_chain_sg1_prep(params, se_ctx, inst, cpt_inst_w4, inputlen,
1611 : : hdr_len, offset_ctrl, req_flags, cipher_iv,
1612 : : auth_iv, pack_iv, pdcp_ci_alg, pdcp_auth_alg);
1613 : : }
1614 : : }
1615 : :
1616 : : static __rte_always_inline int
1617 : : cpt_pdcp_alg_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens,
1618 : : struct roc_se_fc_params *params, struct cpt_inst_s *inst, const bool is_sg_ver2)
1619 : : {
1620 : : uint32_t encr_data_len, auth_data_len;
1621 : : uint32_t encr_offset, auth_offset;
1622 : : union cpt_inst_w4 cpt_inst_w4;
1623 : : int32_t inputlen, outputlen;
1624 : : struct roc_se_ctx *se_ctx;
1625 : : uint64_t *offset_vaddr;
1626 : : uint8_t pdcp_alg_type;
1627 : : uint32_t mac_len = 0;
1628 : : const uint8_t *iv_s;
1629 : : uint8_t pack_iv = 0;
1630 : : uint64_t offset_ctrl;
1631 : : int flags, iv_len;
1632 : : int ret;
1633 : :
1634 : : se_ctx = params->ctx;
1635 : 0 : flags = se_ctx->zsk_flags;
1636 : 0 : mac_len = se_ctx->mac_len;
1637 : :
1638 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1639 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_PDCP;
1640 : :
1641 [ # # # # : 0 : if (flags == 0x1) {
# # # # #
# ]
1642 : 0 : iv_s = params->auth_iv_buf;
1643 : :
1644 : : /*
1645 : : * Microcode expects offsets in bytes
1646 : : * TODO: Rounding off
1647 : : */
1648 : : auth_data_len = ROC_SE_AUTH_DLEN(d_lens);
1649 : 0 : auth_offset = ROC_SE_AUTH_OFFSET(d_offs);
1650 : 0 : pdcp_alg_type = se_ctx->pdcp_auth_alg;
1651 : :
1652 [ # # # # : 0 : if (pdcp_alg_type != ROC_SE_PDCP_ALG_TYPE_AES_CMAC) {
# # # # #
# ]
1653 : 0 : iv_len = params->auth_iv_len;
1654 : :
1655 [ # # # # ]: 0 : if (iv_len == 25) {
1656 : : iv_len -= 2;
1657 : : pack_iv = 1;
1658 : : }
1659 : :
1660 : 0 : auth_offset = auth_offset / 8;
1661 : :
1662 : : /* consider iv len */
1663 : 0 : auth_offset += iv_len;
1664 : :
1665 : 0 : inputlen =
1666 : 0 : auth_offset + (RTE_ALIGN(auth_data_len, 8) / 8);
1667 : : } else {
1668 : : iv_len = 16;
1669 : :
1670 : : /* consider iv len */
1671 : 0 : auth_offset += iv_len;
1672 : :
1673 : 0 : inputlen = auth_offset + auth_data_len;
1674 : :
1675 : : /* length should be in bits */
1676 : 0 : auth_data_len *= 8;
1677 : : }
1678 : :
1679 : 0 : outputlen = mac_len;
1680 : :
1681 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)auth_offset);
# # # # #
# ]
1682 : :
1683 : : encr_data_len = 0;
1684 : : encr_offset = 0;
1685 : : } else {
1686 : : iv_s = params->iv_buf;
1687 : 0 : iv_len = params->cipher_iv_len;
1688 : 0 : pdcp_alg_type = se_ctx->pdcp_ci_alg;
1689 : :
1690 [ # # # # : 0 : if (iv_len == 25) {
# # ]
1691 : : iv_len -= 2;
1692 : : pack_iv = 1;
1693 : : }
1694 : :
1695 : : /*
1696 : : * Microcode expects offsets in bytes
1697 : : * TODO: Rounding off
1698 : : */
1699 : : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1700 : :
1701 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs);
1702 : 0 : encr_offset = encr_offset / 8;
1703 : : /* consider iv len */
1704 : 0 : encr_offset += iv_len;
1705 : :
1706 : 0 : inputlen = encr_offset + (RTE_ALIGN(encr_data_len, 8) / 8);
1707 : : outputlen = inputlen;
1708 : :
1709 : : /* iv offset is 0 */
1710 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)encr_offset << 16);
# # # # #
# ]
1711 : :
1712 : : auth_data_len = 0;
1713 : : auth_offset = 0;
1714 : : }
1715 : :
1716 [ # # # # : 0 : if (unlikely((encr_offset >> 16) || (auth_offset >> 8))) {
# # ]
1717 : 0 : plt_dp_err("Offset not supported");
1718 : 0 : plt_dp_err("enc_offset: %d", encr_offset);
1719 : 0 : plt_dp_err("auth_offset: %d", auth_offset);
1720 : : return -1;
1721 : : }
1722 : :
1723 : : /*
1724 : : * Lengths are expected in bits.
1725 : : */
1726 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1727 : 0 : cpt_inst_w4.s.param2 = auth_data_len;
1728 : :
1729 : : /*
1730 : : * In cn9k, cn10k since we have a limitation of
1731 : : * IV & Offset control word not part of instruction
1732 : : * and need to be part of Data Buffer, we check if
1733 : : * head room is there and then only do the Direct mode processing
1734 : : */
1735 [ # # # # ]: 0 : if (likely((req_flags & ROC_SE_SINGLE_BUF_INPLACE) &&
1736 : : (req_flags & ROC_SE_SINGLE_BUF_HEADROOM))) {
1737 : : void *dm_vaddr = params->bufs[0].vaddr;
1738 : :
1739 : : /* Use Direct mode */
1740 : :
1741 : 0 : offset_vaddr = (uint64_t *)((uint8_t *)dm_vaddr - ROC_SE_OFF_CTRL_LEN - iv_len);
1742 : :
1743 : : /* DPTR */
1744 : 0 : inst->dptr = (uint64_t)offset_vaddr;
1745 : : /* RPTR should just exclude offset control word */
1746 : 0 : inst->rptr = (uint64_t)dm_vaddr - iv_len;
1747 : :
1748 : 0 : cpt_inst_w4.s.dlen = inputlen + ROC_SE_OFF_CTRL_LEN;
1749 : :
1750 : 0 : uint8_t *iv_d = ((uint8_t *)offset_vaddr + ROC_SE_OFF_CTRL_LEN);
1751 : 0 : pdcp_iv_copy(iv_d, iv_s, pdcp_alg_type, pack_iv);
1752 : :
1753 : 0 : *offset_vaddr = offset_ctrl;
1754 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1755 : : } else {
1756 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1757 [ # # # # : 0 : if (is_sg_ver2)
# # # # #
# ]
1758 [ # # # # : 0 : ret = sg2_inst_prep(params, inst, offset_ctrl, iv_s, iv_len, pack_iv,
# # # # #
# ]
1759 : : pdcp_alg_type, inputlen, outputlen, 0, req_flags, 1, 0);
1760 : : else
1761 [ # # # # : 0 : ret = sg_inst_prep(params, inst, offset_ctrl, iv_s, iv_len, pack_iv,
# # # # #
# ]
1762 : : pdcp_alg_type, inputlen, outputlen, 0, req_flags, 1, 0);
1763 [ # # # # : 0 : if (unlikely(ret)) {
# # # # #
# ]
1764 : 0 : plt_dp_err("sg prep failed");
1765 : 0 : return -1;
1766 : : }
1767 : : }
1768 : :
1769 : : return 0;
1770 : : }
1771 : :
1772 : : static __rte_always_inline int
1773 : : cpt_kasumi_enc_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens,
1774 : : struct roc_se_fc_params *params, struct cpt_inst_s *inst, const bool is_sg_ver2)
1775 : : {
1776 : : uint32_t encr_data_len, auth_data_len;
1777 : : int32_t inputlen = 0, outputlen = 0;
1778 : : uint32_t encr_offset, auth_offset;
1779 : : const uint8_t *iv_s, iv_len = 8;
1780 : : union cpt_inst_w4 cpt_inst_w4;
1781 : : struct roc_se_ctx *se_ctx;
1782 : : uint64_t offset_ctrl;
1783 : : uint32_t mac_len = 0;
1784 : : uint8_t dir = 0;
1785 : : int flags;
1786 : :
1787 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs) / 8;
1788 : 0 : auth_offset = ROC_SE_AUTH_OFFSET(d_offs) / 8;
1789 : 0 : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1790 : 0 : auth_data_len = ROC_SE_AUTH_DLEN(d_lens);
1791 : :
1792 : : se_ctx = params->ctx;
1793 : 0 : flags = se_ctx->zsk_flags;
1794 : 0 : mac_len = se_ctx->mac_len;
1795 : :
1796 : 0 : cpt_inst_w4.u64 = se_ctx->template_w4.u64;
1797 : :
1798 [ # # # # : 0 : if (flags == 0x0) {
# # # # #
# ]
1799 : : iv_s = params->iv_buf;
1800 : : /* Consider IV len */
1801 : 0 : encr_offset += iv_len;
1802 : :
1803 : 0 : inputlen = encr_offset + (RTE_ALIGN(encr_data_len, 8) / 8);
1804 : : outputlen = inputlen;
1805 : : /* iv offset is 0 */
1806 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)encr_offset << 16);
# # # # ]
1807 : : if (unlikely((encr_offset >> 16))) {
1808 : : plt_dp_err("Offset not supported");
1809 : : plt_dp_err("enc_offset: %d", encr_offset);
1810 : : return -1;
1811 : : }
1812 : : } else {
1813 : 0 : iv_s = params->auth_iv_buf;
1814 : 0 : dir = iv_s[8] & 0x1;
1815 : :
1816 : 0 : inputlen = auth_offset + (RTE_ALIGN(auth_data_len, 8) / 8);
1817 : 0 : outputlen = mac_len;
1818 : : /* iv offset is 0 */
1819 [ # # # # : 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)auth_offset);
# # # # #
# ]
1820 [ # # # # : 0 : if (unlikely((auth_offset >> 8))) {
# # # # #
# ]
1821 : 0 : plt_dp_err("Offset not supported");
1822 : 0 : plt_dp_err("auth_offset: %d", auth_offset);
1823 : 0 : return -1;
1824 : : }
1825 : : }
1826 : :
1827 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_KASUMI | ROC_DMA_MODE_SG;
1828 : :
1829 : : /* Indicate ECB/CBC, direction, CTX from CPTR, IV from DPTR */
1830 : 0 : cpt_inst_w4.s.opcode_minor =
1831 : 0 : ((1 << 6) | (se_ctx->k_ecb << 5) | (dir << 4) | (0 << 3) | (flags & 0x7));
1832 : :
1833 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1834 : 0 : cpt_inst_w4.s.param2 = auth_data_len;
1835 : :
1836 : 0 : inst->w4.u64 = cpt_inst_w4.u64;
1837 : :
1838 [ # # # # : 0 : if (unlikely(iv_s == NULL))
# # # # ]
1839 : : return -1;
1840 : :
1841 [ # # # # : 0 : if (is_sg_ver2)
# # # # ]
1842 : : sg2_inst_prep(params, inst, offset_ctrl, iv_s, iv_len, 0, 0, inputlen, outputlen, 0,
1843 : : req_flags, 0, 0);
1844 : : else
1845 : : sg_inst_prep(params, inst, offset_ctrl, iv_s, iv_len, 0, 0, inputlen, outputlen, 0,
1846 : : req_flags, 0, 0);
1847 : :
1848 : : return 0;
1849 : : }
1850 : :
1851 : : static __rte_always_inline int
1852 : : cpt_kasumi_dec_prep(uint64_t d_offs, uint64_t d_lens, struct roc_se_fc_params *params,
1853 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
1854 : : {
1855 : : int32_t inputlen = 0, outputlen;
1856 : : struct roc_se_ctx *se_ctx;
1857 : : uint8_t iv_len = 8;
1858 : : uint32_t encr_offset;
1859 : : uint32_t encr_data_len;
1860 : : int flags;
1861 : : uint8_t dir = 0;
1862 : : union cpt_inst_w4 cpt_inst_w4;
1863 : : uint64_t offset_ctrl;
1864 : :
1865 : 0 : encr_offset = ROC_SE_ENCR_OFFSET(d_offs) / 8;
1866 : 0 : encr_data_len = ROC_SE_ENCR_DLEN(d_lens);
1867 : :
1868 : : se_ctx = params->ctx;
1869 : 0 : flags = se_ctx->zsk_flags;
1870 : :
1871 : 0 : cpt_inst_w4.u64 = 0;
1872 : 0 : cpt_inst_w4.s.opcode_major = ROC_SE_MAJOR_OP_KASUMI | ROC_DMA_MODE_SG;
1873 : :
1874 : : /* indicates ECB/CBC, direction, ctx from cptr, iv from dptr */
1875 : 0 : cpt_inst_w4.s.opcode_minor =
1876 : 0 : ((1 << 6) | (se_ctx->k_ecb << 5) | (dir << 4) | (0 << 3) | (flags & 0x7));
1877 : :
1878 : : /*
1879 : : * Lengths are expected in bits.
1880 : : */
1881 : 0 : cpt_inst_w4.s.param1 = encr_data_len;
1882 : :
1883 : : /* consider iv len */
1884 : 0 : encr_offset += iv_len;
1885 : :
1886 : 0 : inputlen = encr_offset + (RTE_ALIGN(encr_data_len, 8) / 8);
1887 : : outputlen = inputlen;
1888 : :
1889 [ # # # # ]: 0 : offset_ctrl = rte_cpu_to_be_64((uint64_t)encr_offset << 16);
1890 : : if (unlikely((encr_offset >> 16))) {
1891 : : plt_dp_err("Offset not supported");
1892 : : plt_dp_err("enc_offset: %d", encr_offset);
1893 : : return -1;
1894 : : }
1895 : :
1896 [ # # # # ]: 0 : inst->w4.u64 = cpt_inst_w4.u64;
1897 : :
1898 : : if (unlikely(params->iv_buf == NULL))
1899 : : return -1;
1900 : :
1901 [ # # # # ]: 0 : if (is_sg_ver2)
1902 : : sg2_inst_prep(params, inst, offset_ctrl, params->iv_buf, iv_len, 0, 0, inputlen,
1903 : : outputlen, 0, 0, 0, 1);
1904 : : else
1905 : : sg_inst_prep(params, inst, offset_ctrl, params->iv_buf, iv_len, 0, 0, inputlen,
1906 : : outputlen, 0, 0, 0, 1);
1907 : :
1908 : : return 0;
1909 : : }
1910 : :
1911 : : static __rte_always_inline int
1912 : : cpt_fc_enc_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens,
1913 : : struct roc_se_fc_params *fc_params, struct cpt_inst_s *inst,
1914 : : const bool is_sg_ver2)
1915 : : {
1916 : : struct roc_se_ctx *ctx = fc_params->ctx;
1917 : : uint8_t fc_type;
1918 : : int ret = -1;
1919 : :
1920 : 0 : fc_type = ctx->fc_type;
1921 : :
1922 [ # # # # ]: 0 : if (likely(fc_type == ROC_SE_FC_GEN)) {
1923 : : ret = cpt_enc_hmac_prep(flags, d_offs, d_lens, fc_params, inst, is_sg_ver2);
1924 [ # # # # : 0 : } else if (fc_type == ROC_SE_PDCP) {
# # ]
1925 : : ret = cpt_pdcp_alg_prep(flags, d_offs, d_lens, fc_params, inst, is_sg_ver2);
1926 [ # # # # : 0 : } else if (fc_type == ROC_SE_KASUMI) {
# # ]
1927 : : ret = cpt_kasumi_enc_prep(flags, d_offs, d_lens, fc_params, inst, is_sg_ver2);
1928 [ # # # # : 0 : } else if (fc_type == ROC_SE_HASH_HMAC) {
# # ]
1929 [ # # # # : 0 : if (is_sg_ver2)
# # ]
1930 : : ret = cpt_digest_gen_sg_ver2_prep(flags, d_lens, fc_params, inst);
1931 : : else
1932 : : ret = cpt_digest_gen_sg_ver1_prep(flags, d_lens, fc_params, inst);
1933 : : }
1934 : :
1935 : : return ret;
1936 : : }
1937 : :
1938 : : static __rte_always_inline int
1939 : : fill_sess_aead(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
1940 : : {
1941 : : struct rte_crypto_aead_xform *aead_form;
1942 : : uint8_t aes_gcm = 0, aes_ccm = 0;
1943 : : roc_se_cipher_type enc_type = 0; /* NULL Cipher type */
1944 : : roc_se_auth_type auth_type = 0; /* NULL Auth type */
1945 : : uint32_t cipher_key_len = 0;
1946 : : aead_form = &xform->aead;
1947 : :
1948 [ # # ]: 0 : if (aead_form->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
1949 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_ENCRYPT;
1950 : 0 : sess->cpt_op |= ROC_SE_OP_AUTH_GENERATE;
1951 [ # # ]: 0 : } else if (aead_form->op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
1952 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_DECRYPT;
1953 : 0 : sess->cpt_op |= ROC_SE_OP_AUTH_VERIFY;
1954 : : } else {
1955 : 0 : plt_dp_err("Unknown aead operation\n");
1956 : : return -1;
1957 : : }
1958 [ # # # # ]: 0 : switch (aead_form->algo) {
1959 : : case RTE_CRYPTO_AEAD_AES_GCM:
1960 : : enc_type = ROC_SE_AES_GCM;
1961 : : cipher_key_len = 16;
1962 : : aes_gcm = 1;
1963 : : break;
1964 : 0 : case RTE_CRYPTO_AEAD_AES_CCM:
1965 : : enc_type = ROC_SE_AES_CCM;
1966 : : cipher_key_len = 16;
1967 : : aes_ccm = 1;
1968 : 0 : break;
1969 : 0 : case RTE_CRYPTO_AEAD_CHACHA20_POLY1305:
1970 : : enc_type = ROC_SE_CHACHA20;
1971 : : auth_type = ROC_SE_POLY1305;
1972 : : cipher_key_len = 32;
1973 : 0 : sess->chacha_poly = 1;
1974 : 0 : break;
1975 : 0 : default:
1976 : 0 : plt_dp_err("Crypto: Undefined cipher algo %u specified",
1977 : : aead_form->algo);
1978 : : return -1;
1979 : : }
1980 [ # # ]: 0 : if (aead_form->key.length < cipher_key_len) {
1981 : 0 : plt_dp_err("Invalid cipher params keylen %u",
1982 : : aead_form->key.length);
1983 : : return -1;
1984 : : }
1985 : 0 : sess->zsk_flag = 0;
1986 : 0 : sess->aes_gcm = aes_gcm;
1987 : 0 : sess->aes_ccm = aes_ccm;
1988 : 0 : sess->mac_len = aead_form->digest_length;
1989 : 0 : sess->iv_offset = aead_form->iv.offset;
1990 : 0 : sess->iv_length = aead_form->iv.length;
1991 : 0 : sess->aad_length = aead_form->aad_length;
1992 : :
1993 [ # # ]: 0 : if (aes_ccm) {
1994 [ # # ]: 0 : if ((sess->iv_length < 11) || (sess->iv_length > 13)) {
1995 : 0 : plt_dp_err("Crypto: Unsupported IV length %u", sess->iv_length);
1996 : : return -1;
1997 : : }
1998 : : } else {
1999 [ # # # ]: 0 : switch (sess->iv_length) {
2000 : 0 : case 12:
2001 : 0 : sess->short_iv = 1;
2002 : : case 16:
2003 : : break;
2004 : 0 : default:
2005 : 0 : plt_dp_err("Crypto: Unsupported IV length %u", sess->iv_length);
2006 : : return -1;
2007 : : }
2008 : : }
2009 : :
2010 [ # # ]: 0 : if (unlikely(roc_se_ciph_key_set(&sess->roc_se_ctx, enc_type, aead_form->key.data,
2011 : : aead_form->key.length)))
2012 : : return -1;
2013 : :
2014 [ # # ]: 0 : if (unlikely(roc_se_auth_key_set(&sess->roc_se_ctx, auth_type, NULL, 0,
2015 : : aead_form->digest_length)))
2016 : : return -1;
2017 : :
2018 [ # # ]: 0 : if (enc_type == ROC_SE_CHACHA20)
2019 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor |= BIT(5);
2020 : : return 0;
2021 : : }
2022 : :
2023 : : static __rte_always_inline int
2024 : : fill_sm_sess_cipher(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
2025 : : {
2026 : : struct roc_se_sm_context *sm_ctx = &sess->roc_se_ctx.se_ctx.sm_ctx;
2027 : : struct rte_crypto_cipher_xform *c_form;
2028 : : roc_sm_cipher_type enc_type = 0;
2029 : :
2030 : : c_form = &xform->cipher;
2031 : :
2032 [ # # # # : 0 : if (c_form->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
# # ]
2033 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_ENCRYPT;
2034 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor = ROC_SE_FC_MINOR_OP_ENCRYPT;
2035 [ # # # # : 0 : } else if (c_form->op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
# # ]
2036 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_DECRYPT;
2037 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor = ROC_SE_FC_MINOR_OP_DECRYPT;
2038 : : } else {
2039 : 0 : plt_dp_err("Unknown cipher operation\n");
2040 : : return -1;
2041 : : }
2042 : :
2043 : : switch (c_form->algo) {
2044 : : case RTE_CRYPTO_CIPHER_SM4_CBC:
2045 : : enc_type = ROC_SM4_CBC;
2046 : : break;
2047 : : case RTE_CRYPTO_CIPHER_SM4_ECB:
2048 : : enc_type = ROC_SM4_ECB;
2049 : : break;
2050 : : case RTE_CRYPTO_CIPHER_SM4_CTR:
2051 : : enc_type = ROC_SM4_CTR;
2052 : : break;
2053 : : case RTE_CRYPTO_CIPHER_SM4_CFB:
2054 : : enc_type = ROC_SM4_CFB;
2055 : : break;
2056 : : case RTE_CRYPTO_CIPHER_SM4_OFB:
2057 : : enc_type = ROC_SM4_OFB;
2058 : : break;
2059 : 0 : default:
2060 : 0 : plt_dp_err("Crypto: Undefined cipher algo %u specified", c_form->algo);
2061 : : return -1;
2062 : : }
2063 : :
2064 : 0 : sess->iv_offset = c_form->iv.offset;
2065 : 0 : sess->iv_length = c_form->iv.length;
2066 : :
2067 [ # # # # : 0 : if (c_form->key.length != ROC_SE_SM4_KEY_LEN) {
# # ]
2068 : 0 : plt_dp_err("Invalid cipher params keylen %u", c_form->key.length);
2069 : : return -1;
2070 : : }
2071 : :
2072 : 0 : sess->zsk_flag = 0;
2073 : 0 : sess->zs_cipher = 0;
2074 : 0 : sess->aes_gcm = 0;
2075 : 0 : sess->aes_ctr = 0;
2076 : 0 : sess->is_null = 0;
2077 : 0 : sess->is_sm4 = 1;
2078 : 0 : sess->roc_se_ctx.fc_type = ROC_SE_SM;
2079 : :
2080 : 0 : sess->roc_se_ctx.template_w4.s.opcode_major = ROC_SE_MAJOR_OP_SM;
2081 : :
2082 : 0 : memcpy(sm_ctx->encr_key, c_form->key.data, ROC_SE_SM4_KEY_LEN);
2083 : 0 : sm_ctx->enc_cipher = enc_type;
2084 : :
2085 : : return 0;
2086 : : }
2087 : :
2088 : : static __rte_always_inline int
2089 : : fill_sess_cipher(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
2090 : : {
2091 : : uint8_t zsk_flag = 0, zs_cipher = 0, aes_ctr = 0, is_null = 0;
2092 : : struct rte_crypto_cipher_xform *c_form;
2093 : : roc_se_cipher_type enc_type = 0; /* NULL Cipher type */
2094 : : uint32_t cipher_key_len = 0;
2095 : :
2096 : : c_form = &xform->cipher;
2097 : :
2098 : 0 : if ((c_form->algo == RTE_CRYPTO_CIPHER_SM4_CBC) ||
2099 : : (c_form->algo == RTE_CRYPTO_CIPHER_SM4_ECB) ||
2100 [ # # # # : 0 : (c_form->algo == RTE_CRYPTO_CIPHER_SM4_CTR) ||
# # ]
2101 [ # # # # : 0 : (c_form->algo == RTE_CRYPTO_CIPHER_SM4_CFB) ||
# # ]
2102 : : (c_form->algo == RTE_CRYPTO_CIPHER_SM4_OFB))
2103 : : return fill_sm_sess_cipher(xform, sess);
2104 : :
2105 [ # # # # : 0 : if (c_form->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
# # ]
2106 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_ENCRYPT;
2107 [ # # # # : 0 : else if (c_form->op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
# # ]
2108 : 0 : sess->cpt_op |= ROC_SE_OP_CIPHER_DECRYPT;
2109 [ # # # # : 0 : if (xform->next != NULL &&
# # ]
2110 [ # # # # : 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
# # ]
2111 : : /* Perform decryption followed by auth verify */
2112 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor =
2113 : : ROC_SE_FC_MINOR_OP_HMAC_FIRST;
2114 : : }
2115 : : } else {
2116 : 0 : plt_dp_err("Unknown cipher operation\n");
2117 : : return -1;
2118 : : }
2119 : :
2120 [ # # # # : 0 : switch (c_form->algo) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
2121 : : case RTE_CRYPTO_CIPHER_AES_CBC:
2122 : : enc_type = ROC_SE_AES_CBC;
2123 : : cipher_key_len = 16;
2124 : : break;
2125 : 0 : case RTE_CRYPTO_CIPHER_3DES_CBC:
2126 : : enc_type = ROC_SE_DES3_CBC;
2127 : : cipher_key_len = 24;
2128 : 0 : break;
2129 : 0 : case RTE_CRYPTO_CIPHER_DES_CBC:
2130 : : /* DES is implemented using 3DES in hardware */
2131 : : enc_type = ROC_SE_DES3_CBC;
2132 : : cipher_key_len = 8;
2133 : 0 : break;
2134 : 0 : case RTE_CRYPTO_CIPHER_AES_CTR:
2135 [ # # # # : 0 : if (sess->aes_ctr_eea2) {
# # ]
2136 : : enc_type = ROC_SE_AES_CTR_EEA2;
2137 : : } else {
2138 : : enc_type = ROC_SE_AES_CTR;
2139 : : aes_ctr = 1;
2140 : : }
2141 : : cipher_key_len = 16;
2142 : : break;
2143 : 0 : case RTE_CRYPTO_CIPHER_NULL:
2144 : : enc_type = 0;
2145 : : is_null = 1;
2146 : 0 : break;
2147 : 0 : case RTE_CRYPTO_CIPHER_KASUMI_F8:
2148 [ # # # # ]: 0 : if (sess->chained_op)
2149 : : return -ENOTSUP;
2150 [ # # # # ]: 0 : if (c_form->iv.length != 8)
2151 : : return -EINVAL;
2152 : : enc_type = ROC_SE_KASUMI_F8_ECB;
2153 : : cipher_key_len = 16;
2154 : : zsk_flag = ROC_SE_K_F8;
2155 : : zs_cipher = ROC_SE_K_F8;
2156 : : break;
2157 : 0 : case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2158 : : enc_type = ROC_SE_SNOW3G_UEA2;
2159 : : cipher_key_len = 16;
2160 : : zsk_flag = ROC_SE_ZS_EA;
2161 : : zs_cipher = ROC_SE_ZS_EA;
2162 : 0 : break;
2163 : 0 : case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2164 : : enc_type = ROC_SE_ZUC_EEA3;
2165 : 0 : cipher_key_len = c_form->key.length;
2166 : : zsk_flag = ROC_SE_ZS_EA;
2167 : : zs_cipher = ROC_SE_ZS_EA;
2168 : 0 : break;
2169 : 0 : case RTE_CRYPTO_CIPHER_AES_XTS:
2170 : : enc_type = ROC_SE_AES_XTS;
2171 : : cipher_key_len = 16;
2172 : 0 : break;
2173 : 0 : case RTE_CRYPTO_CIPHER_3DES_ECB:
2174 : : enc_type = ROC_SE_DES3_ECB;
2175 : : cipher_key_len = 24;
2176 : 0 : break;
2177 : 0 : case RTE_CRYPTO_CIPHER_AES_ECB:
2178 : : enc_type = ROC_SE_AES_ECB;
2179 : : cipher_key_len = 16;
2180 : 0 : break;
2181 : 0 : case RTE_CRYPTO_CIPHER_AES_DOCSISBPI:
2182 : : /* Set DOCSIS flag */
2183 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor |= ROC_SE_FC_MINOR_OP_DOCSIS;
2184 : : enc_type = ROC_SE_AES_DOCSISBPI;
2185 : : cipher_key_len = 16;
2186 : 0 : break;
2187 : 0 : case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
2188 : : /* Set DOCSIS flag */
2189 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor |= ROC_SE_FC_MINOR_OP_DOCSIS;
2190 : : enc_type = ROC_SE_DES_DOCSISBPI;
2191 : : cipher_key_len = 8;
2192 : 0 : break;
2193 : 0 : case RTE_CRYPTO_CIPHER_3DES_CTR:
2194 : : case RTE_CRYPTO_CIPHER_AES_F8:
2195 : : case RTE_CRYPTO_CIPHER_ARC4:
2196 : 0 : plt_dp_err("Crypto: Unsupported cipher algo %u", c_form->algo);
2197 : : return -1;
2198 : 0 : default:
2199 : 0 : plt_dp_err("Crypto: Undefined cipher algo %u specified",
2200 : : c_form->algo);
2201 : : return -1;
2202 : : }
2203 : :
2204 [ # # # # : 0 : if (c_form->key.length < cipher_key_len) {
# # ]
2205 : 0 : plt_dp_err("Invalid cipher params keylen %u",
2206 : : c_form->key.length);
2207 : : return -1;
2208 : : }
2209 : :
2210 [ # # # # : 0 : if (zsk_flag && sess->roc_se_ctx.ciph_then_auth) {
# # # # #
# ]
2211 : : struct rte_crypto_auth_xform *a_form;
2212 : 0 : a_form = &xform->next->auth;
2213 [ # # # # : 0 : if (c_form->op != RTE_CRYPTO_CIPHER_OP_DECRYPT &&
# # ]
2214 [ # # # # : 0 : a_form->op != RTE_CRYPTO_AUTH_OP_VERIFY) {
# # ]
2215 : 0 : plt_dp_err("Crypto: PDCP cipher then auth must use"
2216 : : " options: decrypt and verify");
2217 : : return -EINVAL;
2218 : : }
2219 : : }
2220 : :
2221 : 0 : sess->cipher_only = 1;
2222 : 0 : sess->zsk_flag = zsk_flag;
2223 : 0 : sess->zs_cipher = zs_cipher;
2224 : 0 : sess->aes_gcm = 0;
2225 : 0 : sess->aes_ccm = 0;
2226 : 0 : sess->aes_ctr = aes_ctr;
2227 : 0 : sess->iv_offset = c_form->iv.offset;
2228 : 0 : sess->iv_length = c_form->iv.length;
2229 : 0 : sess->is_null = is_null;
2230 : :
2231 [ # # # # : 0 : if (aes_ctr)
# # ]
2232 [ # # # # : 0 : switch (sess->iv_length) {
# # # #
# ]
2233 : 0 : case 12:
2234 : 0 : sess->short_iv = 1;
2235 : : case 16:
2236 : : break;
2237 : 0 : default:
2238 : 0 : plt_dp_err("Crypto: Unsupported IV length %u", sess->iv_length);
2239 : : return -1;
2240 : : }
2241 : :
2242 [ # # # # : 0 : if (unlikely(roc_se_ciph_key_set(&sess->roc_se_ctx, enc_type, c_form->key.data,
# # ]
2243 : : c_form->key.length)))
2244 : : return -1;
2245 : :
2246 [ # # # # : 0 : if ((enc_type >= ROC_SE_ZUC_EEA3) && (enc_type <= ROC_SE_AES_CTR_EEA2))
# # ]
2247 : 0 : roc_se_ctx_swap(&sess->roc_se_ctx);
2248 : : return 0;
2249 : : }
2250 : :
2251 : : static __rte_always_inline int
2252 : : fill_sess_auth(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
2253 : : {
2254 : : uint8_t zsk_flag = 0, zs_auth = 0, aes_gcm = 0, is_null = 0, is_sha3 = 0;
2255 : : struct rte_crypto_auth_xform *a_form;
2256 : : roc_se_auth_type auth_type = 0; /* NULL Auth type */
2257 : : uint8_t is_sm3 = 0;
2258 : :
2259 [ # # # # : 0 : if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC)
# # ]
2260 : : return fill_sess_gmac(xform, sess);
2261 : :
2262 [ # # # # : 0 : if (xform->next != NULL &&
# # ]
2263 [ # # # # : 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
# # ]
2264 [ # # # # : 0 : xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
# # ]
2265 : : /* Perform auth followed by encryption */
2266 : 0 : sess->roc_se_ctx.template_w4.s.opcode_minor =
2267 : : ROC_SE_FC_MINOR_OP_HMAC_FIRST;
2268 : : }
2269 : :
2270 : : a_form = &xform->auth;
2271 : :
2272 [ # # # # : 0 : if (a_form->op == RTE_CRYPTO_AUTH_OP_VERIFY)
# # ]
2273 : 0 : sess->cpt_op |= ROC_SE_OP_AUTH_VERIFY;
2274 [ # # # # : 0 : else if (a_form->op == RTE_CRYPTO_AUTH_OP_GENERATE)
# # ]
2275 : 0 : sess->cpt_op |= ROC_SE_OP_AUTH_GENERATE;
2276 : : else {
2277 : 0 : plt_dp_err("Unknown auth operation");
2278 : : return -1;
2279 : : }
2280 : :
2281 [ # # # # : 0 : switch (a_form->algo) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
2282 : : case RTE_CRYPTO_AUTH_SHA1_HMAC:
2283 : : /* Fall through */
2284 : : case RTE_CRYPTO_AUTH_SHA1:
2285 : : auth_type = ROC_SE_SHA1_TYPE;
2286 : : break;
2287 : 0 : case RTE_CRYPTO_AUTH_SHA256_HMAC:
2288 : : case RTE_CRYPTO_AUTH_SHA256:
2289 : : auth_type = ROC_SE_SHA2_SHA256;
2290 : 0 : break;
2291 : 0 : case RTE_CRYPTO_AUTH_SHA512_HMAC:
2292 : : case RTE_CRYPTO_AUTH_SHA512:
2293 : : auth_type = ROC_SE_SHA2_SHA512;
2294 : 0 : break;
2295 : : case RTE_CRYPTO_AUTH_AES_GMAC:
2296 : : auth_type = ROC_SE_GMAC_TYPE;
2297 : : aes_gcm = 1;
2298 : : break;
2299 : 0 : case RTE_CRYPTO_AUTH_SHA224_HMAC:
2300 : : case RTE_CRYPTO_AUTH_SHA224:
2301 : : auth_type = ROC_SE_SHA2_SHA224;
2302 : 0 : break;
2303 : 0 : case RTE_CRYPTO_AUTH_SHA384_HMAC:
2304 : : case RTE_CRYPTO_AUTH_SHA384:
2305 : : auth_type = ROC_SE_SHA2_SHA384;
2306 : 0 : break;
2307 : 0 : case RTE_CRYPTO_AUTH_SHA3_224_HMAC:
2308 : : case RTE_CRYPTO_AUTH_SHA3_224:
2309 : : is_sha3 = 1;
2310 : : auth_type = ROC_SE_SHA3_SHA224;
2311 : 0 : break;
2312 : 0 : case RTE_CRYPTO_AUTH_SHA3_256_HMAC:
2313 : : case RTE_CRYPTO_AUTH_SHA3_256:
2314 : : is_sha3 = 1;
2315 : : auth_type = ROC_SE_SHA3_SHA256;
2316 : 0 : break;
2317 : 0 : case RTE_CRYPTO_AUTH_SHA3_384_HMAC:
2318 : : case RTE_CRYPTO_AUTH_SHA3_384:
2319 : : is_sha3 = 1;
2320 : : auth_type = ROC_SE_SHA3_SHA384;
2321 : 0 : break;
2322 : 0 : case RTE_CRYPTO_AUTH_SHA3_512_HMAC:
2323 : : case RTE_CRYPTO_AUTH_SHA3_512:
2324 : : is_sha3 = 1;
2325 : : auth_type = ROC_SE_SHA3_SHA512;
2326 : 0 : break;
2327 : 0 : case RTE_CRYPTO_AUTH_SHAKE_128:
2328 : : is_sha3 = 1;
2329 : : auth_type = ROC_SE_SHA3_SHAKE128;
2330 : 0 : break;
2331 : 0 : case RTE_CRYPTO_AUTH_SHAKE_256:
2332 : : is_sha3 = 1;
2333 : : auth_type = ROC_SE_SHA3_SHAKE256;
2334 : 0 : break;
2335 : 0 : case RTE_CRYPTO_AUTH_MD5_HMAC:
2336 : : case RTE_CRYPTO_AUTH_MD5:
2337 : : auth_type = ROC_SE_MD5_TYPE;
2338 : 0 : break;
2339 : 0 : case RTE_CRYPTO_AUTH_KASUMI_F9:
2340 [ # # # # ]: 0 : if (sess->chained_op)
2341 : : return -ENOTSUP;
2342 : : auth_type = ROC_SE_KASUMI_F9_ECB;
2343 : : /*
2344 : : * Indicate that direction needs to be taken out
2345 : : * from end of src
2346 : : */
2347 : : zsk_flag = ROC_SE_K_F9;
2348 : : zs_auth = ROC_SE_K_F9;
2349 : : break;
2350 : 0 : case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2351 : : auth_type = ROC_SE_SNOW3G_UIA2;
2352 : : zsk_flag = ROC_SE_ZS_IA;
2353 : : zs_auth = ROC_SE_ZS_IA;
2354 : 0 : break;
2355 : 0 : case RTE_CRYPTO_AUTH_ZUC_EIA3:
2356 : : auth_type = ROC_SE_ZUC_EIA3;
2357 : : zsk_flag = ROC_SE_ZS_IA;
2358 : : zs_auth = ROC_SE_ZS_IA;
2359 : 0 : break;
2360 : 0 : case RTE_CRYPTO_AUTH_NULL:
2361 : : auth_type = 0;
2362 : : is_null = 1;
2363 : 0 : break;
2364 : 0 : case RTE_CRYPTO_AUTH_AES_CMAC:
2365 : : auth_type = ROC_SE_AES_CMAC_EIA2;
2366 : : zsk_flag = ROC_SE_ZS_IA;
2367 : 0 : break;
2368 : 0 : case RTE_CRYPTO_AUTH_SM3:
2369 : : auth_type = ROC_SE_SM3;
2370 : : is_sm3 = 1;
2371 : 0 : break;
2372 : 0 : case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2373 : : case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2374 : 0 : plt_dp_err("Crypto: Unsupported hash algo %u", a_form->algo);
2375 : : return -1;
2376 : 0 : default:
2377 : 0 : plt_dp_err("Crypto: Undefined Hash algo %u specified",
2378 : : a_form->algo);
2379 : : return -1;
2380 : : }
2381 : :
2382 [ # # # # : 0 : if (zsk_flag && sess->roc_se_ctx.auth_then_ciph) {
# # # # #
# ]
2383 : : struct rte_crypto_cipher_xform *c_form;
2384 [ # # # # : 0 : if (xform->next != NULL) {
# # ]
2385 : : c_form = &xform->next->cipher;
2386 [ # # # # : 0 : if ((c_form != NULL) && (c_form->op != RTE_CRYPTO_CIPHER_OP_ENCRYPT) &&
# # # # #
# # # ]
2387 : : a_form->op != RTE_CRYPTO_AUTH_OP_GENERATE) {
2388 : 0 : plt_dp_err("Crypto: PDCP auth then cipher must use"
2389 : : " options: encrypt and generate");
2390 : : return -EINVAL;
2391 : : }
2392 : : }
2393 : : }
2394 : :
2395 : 0 : sess->zsk_flag = zsk_flag;
2396 : 0 : sess->zs_auth = zs_auth;
2397 : 0 : sess->aes_gcm = aes_gcm;
2398 : 0 : sess->mac_len = a_form->digest_length;
2399 : 0 : sess->is_null = is_null;
2400 : 0 : sess->is_sha3 = is_sha3;
2401 : 0 : sess->is_sm3 = is_sm3;
2402 [ # # # # : 0 : if (zsk_flag) {
# # ]
2403 : 0 : sess->auth_iv_offset = a_form->iv.offset;
2404 : 0 : sess->auth_iv_length = a_form->iv.length;
2405 : : }
2406 [ # # # # : 0 : if (unlikely(roc_se_auth_key_set(&sess->roc_se_ctx, auth_type,
# # ]
2407 : : a_form->key.data, a_form->key.length,
2408 : : a_form->digest_length)))
2409 : : return -1;
2410 : :
2411 [ # # # # : 0 : if ((auth_type >= ROC_SE_ZUC_EIA3) &&
# # ]
2412 : : (auth_type <= ROC_SE_AES_CMAC_EIA2))
2413 : 0 : roc_se_ctx_swap(&sess->roc_se_ctx);
2414 : :
2415 : : return 0;
2416 : : }
2417 : :
2418 : : static __rte_always_inline int
2419 : : fill_sess_gmac(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess)
2420 : : {
2421 : : struct rte_crypto_auth_xform *a_form;
2422 : : roc_se_cipher_type enc_type = 0; /* NULL Cipher type */
2423 : : roc_se_auth_type auth_type = 0; /* NULL Auth type */
2424 : :
2425 : : a_form = &xform->auth;
2426 : :
2427 [ # # # # : 0 : if (a_form->op == RTE_CRYPTO_AUTH_OP_GENERATE)
# # ]
2428 : 0 : sess->cpt_op |= ROC_SE_OP_ENCODE;
2429 [ # # # # : 0 : else if (a_form->op == RTE_CRYPTO_AUTH_OP_VERIFY)
# # ]
2430 : 0 : sess->cpt_op |= ROC_SE_OP_DECODE;
2431 : : else {
2432 : 0 : plt_dp_err("Unknown auth operation");
2433 : : return -1;
2434 : : }
2435 : :
2436 : : switch (a_form->algo) {
2437 : : case RTE_CRYPTO_AUTH_AES_GMAC:
2438 : : enc_type = ROC_SE_AES_GCM;
2439 : : auth_type = ROC_SE_GMAC_TYPE;
2440 : : break;
2441 : : default:
2442 : : plt_dp_err("Crypto: Undefined cipher algo %u specified",
2443 : : a_form->algo);
2444 : : return -1;
2445 : : }
2446 : :
2447 : 0 : sess->zsk_flag = 0;
2448 : 0 : sess->aes_gcm = 0;
2449 : 0 : sess->is_gmac = 1;
2450 : 0 : sess->iv_offset = a_form->iv.offset;
2451 : 0 : sess->iv_length = a_form->iv.length;
2452 : 0 : sess->mac_len = a_form->digest_length;
2453 : :
2454 [ # # # # : 0 : switch (sess->iv_length) {
# # # #
# ]
2455 : 0 : case 12:
2456 : 0 : sess->short_iv = 1;
2457 : : case 16:
2458 : : break;
2459 : 0 : default:
2460 : 0 : plt_dp_err("Crypto: Unsupported IV length %u", sess->iv_length);
2461 : : return -1;
2462 : : }
2463 : :
2464 [ # # # # : 0 : if (unlikely(roc_se_ciph_key_set(&sess->roc_se_ctx, enc_type, a_form->key.data,
# # ]
2465 : : a_form->key.length)))
2466 : : return -1;
2467 : :
2468 [ # # # # : 0 : if (unlikely(roc_se_auth_key_set(&sess->roc_se_ctx, auth_type, NULL, 0,
# # ]
2469 : : a_form->digest_length)))
2470 : : return -1;
2471 : :
2472 : : return 0;
2473 : : }
2474 : :
2475 : : static __rte_always_inline uint32_t
2476 : : prepare_iov_from_pkt(struct rte_mbuf *pkt, struct roc_se_iov_ptr *iovec, uint32_t start_offset)
2477 : : {
2478 : : uint16_t index = 0;
2479 : : void *seg_data = NULL;
2480 : : int32_t seg_size = 0;
2481 : :
2482 [ # # # # : 0 : if (!pkt) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
2483 : 0 : iovec->buf_cnt = 0;
2484 : 0 : return 0;
2485 : : }
2486 : :
2487 [ # # # # ]: 0 : if (!start_offset) {
2488 : 0 : seg_data = rte_pktmbuf_mtod(pkt, void *);
2489 : 0 : seg_size = pkt->data_len;
2490 : : } else {
2491 [ # # # # ]: 0 : while (start_offset >= pkt->data_len) {
2492 : 0 : start_offset -= pkt->data_len;
2493 : 0 : pkt = pkt->next;
2494 : : }
2495 : :
2496 : 0 : seg_data = rte_pktmbuf_mtod_offset(pkt, void *, start_offset);
2497 : 0 : seg_size = pkt->data_len - start_offset;
2498 [ # # # # ]: 0 : if (!seg_size)
2499 : : return 1;
2500 : : }
2501 : :
2502 : : /* first seg */
2503 : 0 : iovec->bufs[index].vaddr = seg_data;
2504 : 0 : iovec->bufs[index].size = seg_size;
2505 : : index++;
2506 : 0 : pkt = pkt->next;
2507 : :
2508 [ # # # # : 0 : while (unlikely(pkt != NULL)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
2509 : 0 : seg_data = rte_pktmbuf_mtod(pkt, void *);
2510 : 0 : seg_size = pkt->data_len;
2511 [ # # # # : 0 : if (!seg_size)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
2512 : : break;
2513 : :
2514 : 0 : iovec->bufs[index].vaddr = seg_data;
2515 : 0 : iovec->bufs[index].size = seg_size;
2516 : :
2517 : 0 : index++;
2518 : :
2519 : 0 : pkt = pkt->next;
2520 : : }
2521 : :
2522 : 0 : iovec->buf_cnt = index;
2523 : 0 : return 0;
2524 : : }
2525 : :
2526 : : static __rte_always_inline void
2527 : : prepare_iov_from_pkt_inplace(struct rte_mbuf *pkt,
2528 : : struct roc_se_fc_params *param, uint32_t *flags)
2529 : : {
2530 : : uint16_t index = 0;
2531 : : void *seg_data = NULL;
2532 : : uint32_t seg_size = 0;
2533 : : struct roc_se_iov_ptr *iovec;
2534 : :
2535 : 0 : seg_data = rte_pktmbuf_mtod(pkt, void *);
2536 : 0 : seg_size = pkt->data_len;
2537 : :
2538 : : /* first seg */
2539 : 0 : if (likely(!pkt->next)) {
2540 : : uint32_t headroom;
2541 : :
2542 : 0 : *flags |= ROC_SE_SINGLE_BUF_INPLACE;
2543 : 0 : headroom = rte_pktmbuf_headroom(pkt);
2544 [ # # # # : 0 : if (likely(headroom >= CNXK_CPT_MIN_HEADROOM_REQ))
# # # # #
# # # # #
# # # # #
# ]
2545 : 0 : *flags |= ROC_SE_SINGLE_BUF_HEADROOM;
2546 : :
2547 : 0 : param->bufs[0].vaddr = seg_data;
2548 : 0 : param->bufs[0].size = seg_size;
2549 : 0 : return;
2550 : : }
2551 : : iovec = param->src_iov;
2552 : 0 : iovec->bufs[index].vaddr = seg_data;
2553 : 0 : iovec->bufs[index].size = seg_size;
2554 : : index++;
2555 : : pkt = pkt->next;
2556 : :
2557 [ # # # # : 0 : while (unlikely(pkt != NULL)) {
# # # # #
# # # # #
# # # # #
# ]
2558 : 0 : seg_data = rte_pktmbuf_mtod(pkt, void *);
2559 : 0 : seg_size = pkt->data_len;
2560 : :
2561 [ # # # # : 0 : if (!seg_size)
# # # # #
# # # # #
# # # # #
# ]
2562 : : break;
2563 : :
2564 : 0 : iovec->bufs[index].vaddr = seg_data;
2565 : 0 : iovec->bufs[index].size = seg_size;
2566 : :
2567 : 0 : index++;
2568 : :
2569 : 0 : pkt = pkt->next;
2570 : : }
2571 : :
2572 : 0 : iovec->buf_cnt = index;
2573 : 0 : return;
2574 : : }
2575 : :
2576 : : static __rte_always_inline int
2577 : : fill_sm_params(struct rte_crypto_op *cop, struct cnxk_se_sess *sess,
2578 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
2579 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
2580 : : {
2581 : : struct rte_crypto_sym_op *sym_op = cop->sym;
2582 : : struct roc_se_fc_params fc_params;
2583 : : struct rte_mbuf *m_src, *m_dst;
2584 : : uint8_t cpt_op = sess->cpt_op;
2585 : : uint64_t d_offs, d_lens;
2586 : : char src[SRC_IOV_SIZE];
2587 : : char dst[SRC_IOV_SIZE];
2588 : : void *mdata = NULL;
2589 : : uint32_t flags = 0;
2590 : : int ret;
2591 : :
2592 : 0 : uint32_t ci_data_length = sym_op->cipher.data.length;
2593 : 0 : uint32_t ci_data_offset = sym_op->cipher.data.offset;
2594 : :
2595 : 0 : fc_params.cipher_iv_len = sess->iv_length;
2596 : : fc_params.auth_iv_len = 0;
2597 : : fc_params.auth_iv_buf = NULL;
2598 : : fc_params.iv_buf = NULL;
2599 : : fc_params.mac_buf.size = 0;
2600 : : fc_params.mac_buf.vaddr = 0;
2601 : :
2602 : 0 : if (likely(sess->iv_length)) {
2603 : : flags |= ROC_SE_VALID_IV_BUF;
2604 : 0 : fc_params.iv_buf = rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset);
2605 : : }
2606 : :
2607 : 0 : m_src = sym_op->m_src;
2608 : 0 : m_dst = sym_op->m_dst;
2609 : :
2610 : : d_offs = ci_data_offset;
2611 : : d_offs = (d_offs << 16);
2612 : :
2613 : : d_lens = ci_data_length;
2614 : : d_lens = (d_lens << 32);
2615 : :
2616 : : fc_params.ctx = &sess->roc_se_ctx;
2617 : :
2618 [ # # # # ]: 0 : if (m_dst == NULL) {
2619 [ # # # # ]: 0 : fc_params.dst_iov = fc_params.src_iov = (void *)src;
2620 : : prepare_iov_from_pkt_inplace(m_src, &fc_params, &flags);
2621 : : } else {
2622 : : /* Out of place processing */
2623 : : fc_params.src_iov = (void *)src;
2624 [ # # # # ]: 0 : fc_params.dst_iov = (void *)dst;
2625 : :
2626 : : /* Store SG I/O in the api for reuse */
2627 : : if (prepare_iov_from_pkt(m_src, fc_params.src_iov, 0)) {
2628 : : plt_dp_err("Prepare src iov failed");
2629 : : ret = -EINVAL;
2630 : : goto err_exit;
2631 : : }
2632 : :
2633 : : if (prepare_iov_from_pkt(m_dst, fc_params.dst_iov, 0)) {
2634 : : plt_dp_err("Prepare dst iov failed for m_dst %p", m_dst);
2635 : : ret = -EINVAL;
2636 : : goto err_exit;
2637 : : }
2638 : : }
2639 : :
2640 : : fc_params.meta_buf.vaddr = NULL;
2641 : :
2642 [ # # # # ]: 0 : if (unlikely(!((flags & ROC_SE_SINGLE_BUF_INPLACE) &&
2643 : : (flags & ROC_SE_SINGLE_BUF_HEADROOM)))) {
2644 [ # # # # ]: 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
2645 [ # # # # ]: 0 : if (mdata == NULL) {
2646 : 0 : plt_dp_err("Error allocating meta buffer for request");
2647 : 0 : return -ENOMEM;
2648 : : }
2649 : : }
2650 : :
2651 : : /* Finally prepare the instruction */
2652 : : ret = cpt_sm_prep(flags, d_offs, d_lens, &fc_params, inst, is_sg_ver2,
2653 : : !(cpt_op & ROC_SE_OP_ENCODE));
2654 : :
2655 [ # # # # ]: 0 : if (unlikely(ret)) {
2656 : 0 : plt_dp_err("Preparing request failed due to bad input arg");
2657 : 0 : goto free_mdata_and_exit;
2658 : : }
2659 : :
2660 : : return 0;
2661 : :
2662 : : free_mdata_and_exit:
2663 [ # # # # ]: 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
2664 [ # # # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
2665 : 0 : err_exit:
2666 : : return ret;
2667 : : }
2668 : :
2669 : : static __rte_always_inline int
2670 : : fill_fc_params(struct rte_crypto_op *cop, struct cnxk_se_sess *sess,
2671 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
2672 : : struct cpt_inst_s *inst, const bool is_kasumi, const bool is_aead,
2673 : : const bool is_sg_ver2)
2674 : : {
2675 : : struct rte_crypto_sym_op *sym_op = cop->sym;
2676 : : void *mdata = NULL;
2677 : : uint32_t mc_hash_off;
2678 : : uint32_t flags = 0;
2679 : : uint64_t d_offs, d_lens;
2680 : : struct rte_mbuf *m_src, *m_dst;
2681 : 0 : uint8_t cpt_op = sess->cpt_op;
2682 : : #ifdef CPT_ALWAYS_USE_SG_MODE
2683 : : uint8_t inplace = 0;
2684 : : #else
2685 : : uint8_t inplace = 1;
2686 : : #endif
2687 : : struct roc_se_fc_params fc_params;
2688 : : char src[SRC_IOV_SIZE];
2689 : : char dst[SRC_IOV_SIZE];
2690 : : uint8_t ccm_iv_buf[16];
2691 : : uint32_t iv_buf[4];
2692 : : int ret;
2693 : :
2694 : 0 : fc_params.cipher_iv_len = sess->iv_length;
2695 : 0 : fc_params.auth_iv_len = 0;
2696 : 0 : fc_params.auth_iv_buf = NULL;
2697 : 0 : fc_params.iv_buf = NULL;
2698 : 0 : fc_params.mac_buf.size = 0;
2699 : 0 : fc_params.mac_buf.vaddr = 0;
2700 : :
2701 : 0 : if (likely(is_kasumi || sess->iv_length)) {
2702 : : flags |= ROC_SE_VALID_IV_BUF;
2703 : 0 : fc_params.iv_buf = rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset);
2704 [ # # # # : 0 : if (sess->short_iv) {
# # # # ]
2705 : : memcpy((uint8_t *)iv_buf,
2706 : : rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 12);
2707 : 0 : iv_buf[3] = rte_cpu_to_be_32(0x1);
2708 : 0 : fc_params.iv_buf = iv_buf;
2709 : : }
2710 [ # # # # : 0 : if (sess->aes_ccm) {
# # # # #
# # # ]
2711 : 0 : memcpy((uint8_t *)ccm_iv_buf,
2712 : : rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset),
2713 : 0 : sess->iv_length + 1);
2714 : 0 : ccm_iv_buf[0] = 14 - sess->iv_length;
2715 : 0 : fc_params.iv_buf = ccm_iv_buf;
2716 : : }
2717 : : }
2718 : :
2719 : : /* Kasumi would need SG mode */
2720 : : if (is_kasumi)
2721 : : inplace = 0;
2722 : :
2723 : 0 : m_src = sym_op->m_src;
2724 : 0 : m_dst = sym_op->m_dst;
2725 : :
2726 : : if (is_aead) {
2727 : : struct rte_mbuf *m;
2728 : : uint8_t *aad_data;
2729 : : uint16_t aad_len;
2730 : :
2731 : 0 : d_offs = sym_op->aead.data.offset;
2732 : 0 : d_lens = sym_op->aead.data.length;
2733 : 0 : mc_hash_off =
2734 : : sym_op->aead.data.offset + sym_op->aead.data.length;
2735 : :
2736 : 0 : aad_data = sym_op->aead.aad.data;
2737 : 0 : aad_len = sess->aad_length;
2738 [ # # # # : 0 : if (likely((aad_len == 0) ||
# # # # ]
2739 : : ((aad_data + aad_len) ==
2740 : : rte_pktmbuf_mtod_offset(m_src, uint8_t *, sym_op->aead.data.offset)))) {
2741 : 0 : d_offs = (d_offs - aad_len) | (d_offs << 16);
2742 : 0 : d_lens = (d_lens + aad_len) | (d_lens << 32);
2743 : : } else {
2744 : : /* For AES CCM, AAD is written 18B after aad.data as per API */
2745 [ # # # # ]: 0 : if (sess->aes_ccm)
2746 : 0 : fc_params.aad_buf.vaddr = PLT_PTR_ADD(sym_op->aead.aad.data, 18);
2747 : : else
2748 : 0 : fc_params.aad_buf.vaddr = sym_op->aead.aad.data;
2749 : 0 : fc_params.aad_buf.size = aad_len;
2750 : 0 : flags |= ROC_SE_VALID_AAD_BUF;
2751 : : inplace = 0;
2752 : 0 : d_offs = d_offs << 16;
2753 : 0 : d_lens = d_lens << 32;
2754 : : }
2755 : :
2756 : 0 : m = cpt_m_dst_get(cpt_op, m_src, m_dst);
2757 : :
2758 : : /* Digest immediately following data is best case */
2759 [ # # # # ]: 0 : if (unlikely(rte_pktmbuf_mtod(m, uint8_t *) + mc_hash_off !=
2760 : : (uint8_t *)sym_op->aead.digest.data)) {
2761 : 0 : flags |= ROC_SE_VALID_MAC_BUF;
2762 : 0 : fc_params.mac_buf.size = sess->mac_len;
2763 : 0 : fc_params.mac_buf.vaddr = sym_op->aead.digest.data;
2764 : : inplace = 0;
2765 : : }
2766 : : } else {
2767 : 0 : uint32_t ci_data_length = sym_op->cipher.data.length;
2768 : 0 : uint32_t ci_data_offset = sym_op->cipher.data.offset;
2769 : 0 : uint32_t a_data_length = sym_op->auth.data.length;
2770 : 0 : uint32_t a_data_offset = sym_op->auth.data.offset;
2771 : : struct roc_se_ctx *ctx = &sess->roc_se_ctx;
2772 : :
2773 : 0 : const uint8_t op_minor = ctx->template_w4.s.opcode_minor;
2774 : :
2775 : 0 : d_offs = ci_data_offset;
2776 : 0 : d_offs = (d_offs << 16) | a_data_offset;
2777 : :
2778 : 0 : d_lens = ci_data_length;
2779 : 0 : d_lens = (d_lens << 32) | a_data_length;
2780 : :
2781 [ # # # # : 0 : if (likely(sess->mac_len)) {
# # # # ]
2782 : 0 : struct rte_mbuf *m = cpt_m_dst_get(cpt_op, m_src, m_dst);
2783 : :
2784 [ # # # # : 0 : if (sess->auth_first)
# # # # ]
2785 : 0 : mc_hash_off = a_data_offset + a_data_length;
2786 : : else
2787 : 0 : mc_hash_off = ci_data_offset + ci_data_length;
2788 : :
2789 : 0 : if (mc_hash_off < (a_data_offset + a_data_length))
2790 : : mc_hash_off = (a_data_offset + a_data_length);
2791 : :
2792 : : /* hmac immediately following data is best case */
2793 [ # # # # : 0 : if (!(op_minor & ROC_SE_FC_MINOR_OP_HMAC_FIRST) &&
# # # # ]
2794 [ # # # # : 0 : (unlikely(rte_pktmbuf_mtod(m, uint8_t *) +
# # # # ]
2795 : : mc_hash_off !=
2796 : : (uint8_t *)sym_op->auth.digest.data))) {
2797 : 0 : flags |= ROC_SE_VALID_MAC_BUF;
2798 : 0 : fc_params.mac_buf.size = sess->mac_len;
2799 : : fc_params.mac_buf.vaddr =
2800 : : sym_op->auth.digest.data;
2801 : : inplace = 0;
2802 : : }
2803 : : }
2804 : : }
2805 : 0 : fc_params.ctx = &sess->roc_se_ctx;
2806 : :
2807 [ # # # # : 0 : if (!(sess->auth_first) && unlikely(sess->is_null || sess->cpt_op == ROC_SE_OP_DECODE))
# # # # #
# # # # #
# # # # #
# # # #
# ]
2808 : : inplace = 0;
2809 : :
2810 [ # # # # : 0 : if (likely(!m_dst && inplace)) {
# # # # ]
2811 : : /* Case of single buffer without AAD buf or
2812 : : * separate mac buf in place and
2813 : : * not air crypto
2814 : : */
2815 [ # # # # : 0 : fc_params.dst_iov = fc_params.src_iov = (void *)src;
# # # # ]
2816 : :
2817 : : prepare_iov_from_pkt_inplace(m_src, &fc_params, &flags);
2818 : :
2819 : : } else {
2820 : : /* Out of place processing */
2821 : 0 : fc_params.src_iov = (void *)src;
2822 [ # # # # : 0 : fc_params.dst_iov = (void *)dst;
# # # # ]
2823 : :
2824 : : /* Store SG I/O in the api for reuse */
2825 : : if (prepare_iov_from_pkt(m_src, fc_params.src_iov, 0)) {
2826 : : plt_dp_err("Prepare src iov failed");
2827 : : ret = -EINVAL;
2828 : : goto err_exit;
2829 : : }
2830 : :
2831 [ # # # # : 0 : if (unlikely(m_dst != NULL)) {
# # # # #
# # # ]
2832 : : if (prepare_iov_from_pkt(m_dst, fc_params.dst_iov, 0)) {
2833 : : plt_dp_err("Prepare dst iov failed for "
2834 : : "m_dst %p",
2835 : : m_dst);
2836 : : ret = -EINVAL;
2837 : : goto err_exit;
2838 : : }
2839 : : } else {
2840 : 0 : fc_params.dst_iov = (void *)src;
2841 : : }
2842 : : }
2843 : :
2844 : 0 : fc_params.meta_buf.vaddr = NULL;
2845 [ # # # # : 0 : if (unlikely(is_kasumi || !((flags & ROC_SE_SINGLE_BUF_INPLACE) &&
# # # # ]
2846 : : (flags & ROC_SE_SINGLE_BUF_HEADROOM)))) {
2847 [ # # # # : 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
# # # # #
# # # ]
2848 [ # # # # : 0 : if (mdata == NULL) {
# # # # #
# # # ]
2849 : 0 : plt_dp_err("Error allocating meta buffer for request");
2850 : 0 : return -ENOMEM;
2851 : : }
2852 : : }
2853 : :
2854 : : /* Finally prepare the instruction */
2855 : :
2856 : : if (is_kasumi) {
2857 [ # # # # ]: 0 : if (cpt_op & ROC_SE_OP_ENCODE)
2858 : : ret = cpt_kasumi_enc_prep(flags, d_offs, d_lens, &fc_params, inst,
2859 : : is_sg_ver2);
2860 : : else
2861 : : ret = cpt_kasumi_dec_prep(d_offs, d_lens, &fc_params, inst, is_sg_ver2);
2862 : : } else {
2863 [ # # # # : 0 : if (cpt_op & ROC_SE_OP_ENCODE)
# # # # ]
2864 : : ret = cpt_enc_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
2865 : : is_sg_ver2);
2866 : : else
2867 : : ret = cpt_dec_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
2868 : : is_sg_ver2);
2869 : : }
2870 : :
2871 [ # # # # : 0 : if (unlikely(ret)) {
# # # # #
# # # ]
2872 : 0 : plt_dp_err("Preparing request failed due to bad input arg");
2873 : 0 : goto free_mdata_and_exit;
2874 : : }
2875 : :
2876 : : return 0;
2877 : :
2878 : : free_mdata_and_exit:
2879 [ # # # # : 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
# # # # #
# # # ]
2880 [ # # # # : 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
# # # # #
# # # ]
2881 : 0 : err_exit:
2882 : : return ret;
2883 : : }
2884 : :
2885 : : static inline int
2886 : 0 : fill_passthrough_params(struct rte_crypto_op *cop, struct cpt_inst_s *inst)
2887 : : {
2888 : : struct rte_crypto_sym_op *sym_op = cop->sym;
2889 : : struct rte_mbuf *m_src, *m_dst;
2890 : :
2891 : : const union cpt_inst_w4 w4 = {
2892 : : .s.opcode_major = ROC_SE_MAJOR_OP_MISC,
2893 : : .s.opcode_minor = ROC_SE_MISC_MINOR_OP_PASSTHROUGH,
2894 : : .s.param1 = 1,
2895 : : .s.param2 = 1,
2896 : : .s.dlen = 0,
2897 : : };
2898 : :
2899 : 0 : m_src = sym_op->m_src;
2900 : 0 : m_dst = sym_op->m_dst;
2901 : :
2902 [ # # ]: 0 : if (unlikely(m_dst != NULL && m_dst != m_src)) {
2903 : 0 : void *src = rte_pktmbuf_mtod_offset(m_src, void *, cop->sym->cipher.data.offset);
2904 : 0 : void *dst = rte_pktmbuf_mtod(m_dst, void *);
2905 : 0 : int data_len = cop->sym->cipher.data.length;
2906 : :
2907 [ # # ]: 0 : rte_memcpy(dst, src, data_len);
2908 : : }
2909 : :
2910 : 0 : inst->w0.u64 = 0;
2911 : 0 : inst->w5.u64 = 0;
2912 : 0 : inst->w6.u64 = 0;
2913 : 0 : inst->w4.u64 = w4.u64;
2914 : :
2915 : 0 : return 0;
2916 : : }
2917 : :
2918 : : static __rte_always_inline int
2919 : : fill_pdcp_params(struct rte_crypto_op *cop, struct cnxk_se_sess *sess,
2920 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
2921 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
2922 : : {
2923 : : struct rte_crypto_sym_op *sym_op = cop->sym;
2924 : : struct roc_se_fc_params fc_params;
2925 : : uint32_t c_data_len, c_data_off;
2926 : : struct rte_mbuf *m_src, *m_dst;
2927 : : uint64_t d_offs, d_lens;
2928 : : char src[SRC_IOV_SIZE];
2929 : : char dst[SRC_IOV_SIZE];
2930 : : void *mdata = NULL;
2931 : : uint32_t flags = 0;
2932 : : int ret;
2933 : :
2934 : : /* Cipher only */
2935 : :
2936 : 0 : fc_params.cipher_iv_len = sess->iv_length;
2937 : : fc_params.auth_iv_len = 0;
2938 : : fc_params.iv_buf = NULL;
2939 : : fc_params.auth_iv_buf = NULL;
2940 : : fc_params.pdcp_iv_offset = sess->roc_se_ctx.pdcp_iv_offset;
2941 : :
2942 : 0 : if (likely(sess->iv_length))
2943 : 0 : fc_params.iv_buf = rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset);
2944 : :
2945 : 0 : m_src = sym_op->m_src;
2946 : 0 : m_dst = sym_op->m_dst;
2947 : :
2948 : 0 : c_data_len = sym_op->cipher.data.length;
2949 : 0 : c_data_off = sym_op->cipher.data.offset;
2950 : :
2951 : : d_offs = (uint64_t)c_data_off << 16;
2952 : : d_lens = (uint64_t)c_data_len << 32;
2953 : :
2954 : : fc_params.ctx = &sess->roc_se_ctx;
2955 : :
2956 [ # # # # ]: 0 : if (likely(m_dst == NULL || m_src == m_dst)) {
2957 [ # # # # ]: 0 : fc_params.dst_iov = fc_params.src_iov = (void *)src;
2958 : : prepare_iov_from_pkt_inplace(m_src, &fc_params, &flags);
2959 : : } else {
2960 : : /* Out of place processing */
2961 : :
2962 : : fc_params.src_iov = (void *)src;
2963 [ # # # # ]: 0 : fc_params.dst_iov = (void *)dst;
2964 : :
2965 : : /* Store SG I/O in the api for reuse */
2966 : : if (unlikely(prepare_iov_from_pkt(m_src, fc_params.src_iov, 0))) {
2967 : : plt_dp_err("Prepare src iov failed");
2968 : : ret = -EINVAL;
2969 : : goto err_exit;
2970 : : }
2971 : :
2972 : : if (unlikely(prepare_iov_from_pkt(m_dst, fc_params.dst_iov, 0))) {
2973 : : plt_dp_err("Prepare dst iov failed for m_dst %p", m_dst);
2974 : : ret = -EINVAL;
2975 : : goto err_exit;
2976 : : }
2977 : : }
2978 : :
2979 : : fc_params.meta_buf.vaddr = NULL;
2980 [ # # # # ]: 0 : if (unlikely(!((flags & ROC_SE_SINGLE_BUF_INPLACE) &&
2981 : : (flags & ROC_SE_SINGLE_BUF_HEADROOM)))) {
2982 [ # # # # ]: 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
2983 [ # # # # ]: 0 : if (mdata == NULL) {
2984 : 0 : plt_dp_err("Could not allocate meta buffer");
2985 : : ret = -ENOMEM;
2986 : 0 : goto err_exit;
2987 : : }
2988 : : }
2989 : :
2990 : : ret = cpt_pdcp_alg_prep(flags, d_offs, d_lens, &fc_params, inst, is_sg_ver2);
2991 [ # # # # ]: 0 : if (unlikely(ret)) {
2992 : 0 : plt_dp_err("Could not prepare instruction");
2993 : 0 : goto free_mdata_and_exit;
2994 : : }
2995 : :
2996 : : return 0;
2997 : :
2998 : : free_mdata_and_exit:
2999 [ # # # # ]: 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
3000 [ # # # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
3001 : 0 : err_exit:
3002 : : return ret;
3003 : : }
3004 : :
3005 : : static __rte_always_inline int
3006 : : fill_pdcp_chain_params(struct rte_crypto_op *cop, struct cnxk_se_sess *sess,
3007 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
3008 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
3009 : : {
3010 : : uint32_t ci_data_length, ci_data_offset, a_data_length, a_data_offset;
3011 : 0 : struct rte_crypto_sym_op *sym_op = cop->sym;
3012 : : struct roc_se_fc_params fc_params;
3013 : : struct rte_mbuf *m_src, *m_dst;
3014 : 0 : uint8_t cpt_op = sess->cpt_op;
3015 : : uint64_t d_offs, d_lens;
3016 : : char src[SRC_IOV_SIZE];
3017 : : char dst[SRC_IOV_SIZE];
3018 : 0 : bool inplace = true;
3019 : 0 : uint32_t flags = 0;
3020 : : void *mdata;
3021 : : int ret;
3022 : :
3023 : 0 : fc_params.cipher_iv_len = sess->iv_length;
3024 : 0 : fc_params.auth_iv_len = sess->auth_iv_length;
3025 : 0 : fc_params.iv_buf = NULL;
3026 : 0 : fc_params.auth_iv_buf = NULL;
3027 : 0 : fc_params.pdcp_iv_offset = sess->roc_se_ctx.pdcp_iv_offset;
3028 : :
3029 : 0 : m_src = sym_op->m_src;
3030 : 0 : m_dst = sym_op->m_dst;
3031 : :
3032 : 0 : if (likely(sess->iv_length))
3033 : 0 : fc_params.iv_buf = rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset);
3034 : :
3035 : 0 : ci_data_length = sym_op->cipher.data.length;
3036 : 0 : ci_data_offset = sym_op->cipher.data.offset;
3037 : 0 : a_data_length = sym_op->auth.data.length;
3038 : 0 : a_data_offset = sym_op->auth.data.offset;
3039 : :
3040 : : /*
3041 : : * For ZUC & SNOW, length & offset is provided in bits. Convert to
3042 : : * bytes.
3043 : : */
3044 : :
3045 [ # # # # ]: 0 : if (sess->zs_cipher) {
3046 : 0 : ci_data_length /= 8;
3047 : 0 : ci_data_offset /= 8;
3048 : : }
3049 : :
3050 [ # # # # ]: 0 : if (sess->zs_auth) {
3051 : 0 : a_data_length /= 8;
3052 : 0 : a_data_offset /= 8;
3053 : : /*
3054 : : * ZUC & SNOW would have valid iv_buf. AES-CMAC doesn't require
3055 : : * IV from application.
3056 : : */
3057 : 0 : fc_params.auth_iv_buf =
3058 : 0 : rte_crypto_op_ctod_offset(cop, uint8_t *, sess->auth_iv_offset);
3059 : : #ifdef CNXK_CRYPTODEV_DEBUG
3060 : : if (sess->auth_iv_length == 0)
3061 : : plt_err("Invalid auth IV length");
3062 : : #endif
3063 : : }
3064 : :
3065 : 0 : d_offs = ci_data_offset;
3066 : 0 : d_offs = (d_offs << 16) | a_data_offset;
3067 : 0 : d_lens = ci_data_length;
3068 : 0 : d_lens = (d_lens << 32) | a_data_length;
3069 : :
3070 [ # # # # ]: 0 : if (likely(sess->mac_len)) {
3071 : 0 : struct rte_mbuf *m = cpt_m_dst_get(cpt_op, m_src, m_dst);
3072 : :
3073 : 0 : cpt_digest_buf_lb_check(sess, m, &fc_params, &flags, sym_op, &inplace,
3074 : : a_data_offset, a_data_length, ci_data_offset,
3075 : : ci_data_length, true);
3076 : : }
3077 : :
3078 : 0 : fc_params.ctx = &sess->roc_se_ctx;
3079 : :
3080 [ # # # # : 0 : if (likely((m_dst == NULL || m_dst == m_src)) && inplace) {
# # # # ]
3081 [ # # # # ]: 0 : fc_params.dst_iov = fc_params.src_iov = (void *)src;
3082 : : prepare_iov_from_pkt_inplace(m_src, &fc_params, &flags);
3083 : : } else {
3084 : : /* Out of place processing */
3085 : 0 : fc_params.src_iov = (void *)src;
3086 [ # # # # ]: 0 : fc_params.dst_iov = (void *)dst;
3087 : :
3088 : : /* Store SG I/O in the api for reuse */
3089 : : if (unlikely(prepare_iov_from_pkt(m_src, fc_params.src_iov, 0))) {
3090 : : plt_dp_err("Could not prepare src iov");
3091 : : ret = -EINVAL;
3092 : : goto err_exit;
3093 : : }
3094 : :
3095 [ # # # # ]: 0 : if (unlikely(m_dst != NULL)) {
3096 : : if (unlikely(prepare_iov_from_pkt(m_dst, fc_params.dst_iov, 0))) {
3097 : : plt_dp_err("Could not prepare m_dst iov %p", m_dst);
3098 : : ret = -EINVAL;
3099 : : goto err_exit;
3100 : : }
3101 : : } else {
3102 : 0 : fc_params.dst_iov = (void *)src;
3103 : : }
3104 : : }
3105 : :
3106 [ # # # # ]: 0 : if (unlikely(!((flags & ROC_SE_SINGLE_BUF_INPLACE) &&
3107 : : (flags & ROC_SE_SINGLE_BUF_HEADROOM)))) {
3108 [ # # # # ]: 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
3109 [ # # # # ]: 0 : if (unlikely(mdata == NULL)) {
3110 : 0 : plt_dp_err("Could not allocate meta buffer for request");
3111 : 0 : return -ENOMEM;
3112 : : }
3113 : : }
3114 : :
3115 : : /* Finally prepare the instruction */
3116 [ # # # # ]: 0 : ret = cpt_pdcp_chain_alg_prep(flags, d_offs, d_lens, &fc_params, inst, is_sg_ver2);
3117 [ # # # # ]: 0 : if (unlikely(ret)) {
3118 : 0 : plt_dp_err("Could not prepare instruction");
3119 : 0 : goto free_mdata_and_exit;
3120 : : }
3121 : :
3122 : : return 0;
3123 : :
3124 : : free_mdata_and_exit:
3125 [ # # # # ]: 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
3126 [ # # # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
3127 : 0 : err_exit:
3128 : : return ret;
3129 : : }
3130 : :
3131 : : static __rte_always_inline void
3132 : : compl_auth_verify(struct rte_crypto_op *op, uint8_t *gen_mac, uint64_t mac_len)
3133 : : {
3134 : : uint8_t *mac;
3135 : : struct rte_crypto_sym_op *sym_op = op->sym;
3136 : :
3137 [ # # ]: 0 : if (sym_op->auth.digest.data)
3138 : : mac = sym_op->auth.digest.data;
3139 : : else
3140 : 0 : mac = rte_pktmbuf_mtod_offset(sym_op->m_src, uint8_t *,
3141 : : sym_op->auth.data.length +
3142 : : sym_op->auth.data.offset);
3143 [ # # ]: 0 : if (!mac) {
3144 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
3145 : 0 : return;
3146 : : }
3147 : :
3148 [ # # ]: 0 : if (memcmp(mac, gen_mac, mac_len))
3149 : 0 : op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
3150 : : else
3151 : : op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
3152 : : }
3153 : :
3154 : : static __rte_always_inline void
3155 : : find_kasumif9_direction_and_length(uint8_t *src, uint32_t counter_num_bytes,
3156 : : uint32_t *addr_length_in_bits,
3157 : : uint8_t *addr_direction)
3158 : : {
3159 : : uint8_t found = 0;
3160 : : uint32_t pos;
3161 : : uint8_t last_byte;
3162 [ # # # # ]: 0 : while (!found && counter_num_bytes > 0) {
3163 : 0 : counter_num_bytes--;
3164 [ # # # # ]: 0 : if (src[counter_num_bytes] == 0x00)
3165 : 0 : continue;
3166 : 0 : pos = rte_bsf32(src[counter_num_bytes]);
3167 [ # # # # ]: 0 : if (pos == 7) {
3168 [ # # # # ]: 0 : if (likely(counter_num_bytes > 0)) {
3169 : 0 : last_byte = src[counter_num_bytes - 1];
3170 : 0 : *addr_direction = last_byte & 0x1;
3171 : : *addr_length_in_bits =
3172 : 0 : counter_num_bytes * 8 - 1;
3173 : : }
3174 : : } else {
3175 : 0 : last_byte = src[counter_num_bytes];
3176 : 0 : *addr_direction = (last_byte >> (pos + 1)) & 0x1;
3177 : : *addr_length_in_bits =
3178 : 0 : counter_num_bytes * 8 + (8 - (pos + 2));
3179 : : }
3180 : : found = 1;
3181 : : }
3182 : : }
3183 : :
3184 : : /*
3185 : : * This handles all auth only except AES_GMAC
3186 : : */
3187 : : static __rte_always_inline int
3188 : : fill_digest_params(struct rte_crypto_op *cop, struct cnxk_se_sess *sess,
3189 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
3190 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
3191 : : {
3192 : : uint32_t space = 0;
3193 : : struct rte_crypto_sym_op *sym_op = cop->sym;
3194 : : void *mdata;
3195 : : uint32_t auth_range_off;
3196 : : uint32_t flags = 0;
3197 : : uint64_t d_offs = 0, d_lens;
3198 : : struct rte_mbuf *m_src, *m_dst;
3199 : 0 : uint16_t auth_op = sess->cpt_op & ROC_SE_OP_AUTH_MASK;
3200 : 0 : uint16_t mac_len = sess->mac_len;
3201 : : struct roc_se_fc_params params;
3202 : : char src[SRC_IOV_SIZE];
3203 : : uint8_t iv_buf[16];
3204 : : int ret;
3205 : :
3206 : : memset(¶ms, 0, sizeof(struct roc_se_fc_params));
3207 : :
3208 : 0 : m_src = sym_op->m_src;
3209 : :
3210 [ # # # # ]: 0 : mdata = alloc_op_meta(¶ms.meta_buf, m_info->mlen, m_info->pool,
3211 : : infl_req);
3212 [ # # # # ]: 0 : if (mdata == NULL) {
3213 : : ret = -ENOMEM;
3214 : 0 : goto err_exit;
3215 : : }
3216 : :
3217 : 0 : auth_range_off = sym_op->auth.data.offset;
3218 : :
3219 : : flags = ROC_SE_VALID_MAC_BUF;
3220 : 0 : params.src_iov = (void *)src;
3221 [ # # # # ]: 0 : if (unlikely(sess->zsk_flag)) {
3222 : : /*
3223 : : * Since for Zuc, Kasumi, Snow3g offsets are in bits
3224 : : * we will send pass through even for auth only case,
3225 : : * let MC handle it
3226 : : */
3227 : 0 : d_offs = auth_range_off;
3228 : : auth_range_off = 0;
3229 : 0 : params.auth_iv_len = sess->auth_iv_length;
3230 : 0 : params.auth_iv_buf =
3231 : 0 : rte_crypto_op_ctod_offset(cop, uint8_t *, sess->auth_iv_offset);
3232 : 0 : params.pdcp_iv_offset = sess->roc_se_ctx.pdcp_iv_offset;
3233 [ # # # # ]: 0 : if (sess->zsk_flag == ROC_SE_K_F9) {
3234 : : uint32_t length_in_bits, num_bytes;
3235 : : uint8_t *src, direction = 0;
3236 : :
3237 : : memcpy(iv_buf,
3238 : 0 : rte_pktmbuf_mtod(cop->sym->m_src, uint8_t *), 8);
3239 : : /*
3240 : : * This is kasumi f9, take direction from
3241 : : * source buffer
3242 : : */
3243 : 0 : length_in_bits = cop->sym->auth.data.length;
3244 : 0 : num_bytes = (length_in_bits >> 3);
3245 : 0 : src = rte_pktmbuf_mtod(cop->sym->m_src, uint8_t *);
3246 : : find_kasumif9_direction_and_length(
3247 : : src, num_bytes, &length_in_bits, &direction);
3248 : 0 : length_in_bits -= 64;
3249 : 0 : cop->sym->auth.data.offset += 64;
3250 : 0 : d_offs = cop->sym->auth.data.offset;
3251 : 0 : auth_range_off = d_offs / 8;
3252 : 0 : cop->sym->auth.data.length = length_in_bits;
3253 : :
3254 : : /* Store it at end of auth iv */
3255 : 0 : iv_buf[8] = direction;
3256 : 0 : params.auth_iv_buf = iv_buf;
3257 : : }
3258 : : }
3259 : :
3260 : 0 : d_lens = sym_op->auth.data.length;
3261 : :
3262 : 0 : params.ctx = &sess->roc_se_ctx;
3263 : :
3264 [ # # # # ]: 0 : if (auth_op == ROC_SE_OP_AUTH_GENERATE) {
3265 [ # # # # ]: 0 : if (sym_op->auth.digest.data) {
3266 : : /*
3267 : : * Digest to be generated
3268 : : * in separate buffer
3269 : : */
3270 : 0 : params.mac_buf.size = sess->mac_len;
3271 : 0 : params.mac_buf.vaddr = sym_op->auth.digest.data;
3272 : : } else {
3273 : 0 : uint32_t off = sym_op->auth.data.offset +
3274 : : sym_op->auth.data.length;
3275 : : int32_t dlen, space;
3276 : :
3277 [ # # # # ]: 0 : m_dst = sym_op->m_dst ? sym_op->m_dst : sym_op->m_src;
3278 : 0 : dlen = rte_pktmbuf_pkt_len(m_dst);
3279 : :
3280 : 0 : space = off + mac_len - dlen;
3281 [ # # # # ]: 0 : if (space > 0)
3282 [ # # # # ]: 0 : if (!rte_pktmbuf_append(m_dst, space)) {
3283 : 0 : plt_dp_err("Failed to extend "
3284 : : "mbuf by %uB",
3285 : : space);
3286 : : ret = -EINVAL;
3287 : 0 : goto free_mdata_and_exit;
3288 : : }
3289 : :
3290 : 0 : params.mac_buf.vaddr =
3291 : 0 : rte_pktmbuf_mtod_offset(m_dst, void *, off);
3292 : 0 : params.mac_buf.size = mac_len;
3293 : : }
3294 : : } else {
3295 : : uint64_t *op = mdata;
3296 : :
3297 : : /* Need space for storing generated mac */
3298 : : space += 2 * sizeof(uint64_t);
3299 : :
3300 : 0 : params.mac_buf.vaddr = (uint8_t *)mdata + space;
3301 : 0 : params.mac_buf.size = mac_len;
3302 : 0 : space += RTE_ALIGN_CEIL(mac_len, 8);
3303 : 0 : op[0] = (uintptr_t)params.mac_buf.vaddr;
3304 : 0 : op[1] = mac_len;
3305 : 0 : infl_req->op_flags |= CPT_OP_FLAGS_AUTH_VERIFY;
3306 : : }
3307 : :
3308 : 0 : params.meta_buf.vaddr = (uint8_t *)mdata + space;
3309 [ # # # # ]: 0 : params.meta_buf.size -= space;
3310 : :
3311 : : /* Out of place processing */
3312 : : params.src_iov = (void *)src;
3313 : :
3314 : : /*Store SG I/O in the api for reuse */
3315 : : if (prepare_iov_from_pkt(m_src, params.src_iov, auth_range_off)) {
3316 : 0 : plt_dp_err("Prepare src iov failed");
3317 : : ret = -EINVAL;
3318 : 0 : goto free_mdata_and_exit;
3319 : : }
3320 : :
3321 : : ret = cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, ¶ms, inst, is_sg_ver2);
3322 [ # # # # ]: 0 : if (ret)
3323 : 0 : goto free_mdata_and_exit;
3324 : :
3325 : : return 0;
3326 : :
3327 : 0 : free_mdata_and_exit:
3328 [ # # # # ]: 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
3329 [ # # # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
3330 : 0 : err_exit:
3331 : : return ret;
3332 : : }
3333 : :
3334 : : static __rte_always_inline int __rte_hot
3335 : : cpt_sym_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, struct cnxk_se_sess *sess,
3336 : : struct cpt_inflight_req *infl_req, struct cpt_inst_s *inst, const bool is_sg_ver2)
3337 : : {
3338 : : enum cpt_dp_thread_type dp_thr_type;
3339 : : int ret;
3340 : :
3341 : 0 : dp_thr_type = sess->dp_thr_type;
3342 : :
3343 : : /*
3344 : : * With cipher only, microcode expects that cipher length is non-zero. To accept such
3345 : : * instructions, send to CPT as passthrough.
3346 : : */
3347 [ # # # # : 0 : if (unlikely(sess->cipher_only && op->sym->cipher.data.length == 0))
# # # # ]
3348 : : dp_thr_type = CPT_DP_THREAD_TYPE_PT;
3349 : :
3350 [ # # # # : 0 : switch (dp_thr_type) {
# # # # #
# # # # #
# # # # ]
3351 : 0 : case CPT_DP_THREAD_TYPE_PT:
3352 : 0 : ret = fill_passthrough_params(op, inst);
3353 : 0 : break;
3354 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_PDCP:
3355 : : ret = fill_pdcp_params(op, sess, &qp->meta_info, infl_req, inst, is_sg_ver2);
3356 : 0 : break;
3357 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_CHAIN:
3358 : : ret = fill_fc_params(op, sess, &qp->meta_info, infl_req, inst, false, false,
3359 : : is_sg_ver2);
3360 : 0 : break;
3361 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_AEAD:
3362 : : ret = fill_fc_params(op, sess, &qp->meta_info, infl_req, inst, false, true,
3363 : : is_sg_ver2);
3364 : 0 : break;
3365 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_PDCP_CHAIN:
3366 : : ret = fill_pdcp_chain_params(op, sess, &qp->meta_info, infl_req, inst, is_sg_ver2);
3367 : 0 : break;
3368 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_KASUMI:
3369 : : ret = fill_fc_params(op, sess, &qp->meta_info, infl_req, inst, true, false,
3370 : : is_sg_ver2);
3371 : 0 : break;
3372 [ # # # # ]: 0 : case CPT_DP_THREAD_TYPE_SM:
3373 : : ret = fill_sm_params(op, sess, &qp->meta_info, infl_req, inst, is_sg_ver2);
3374 : 0 : break;
3375 : :
3376 [ # # # # ]: 0 : case CPT_DP_THREAD_AUTH_ONLY:
3377 : : ret = fill_digest_params(op, sess, &qp->meta_info, infl_req, inst, is_sg_ver2);
3378 : 0 : break;
3379 : : default:
3380 : : ret = -EINVAL;
3381 : : }
3382 : :
3383 : : return ret;
3384 : : }
3385 : :
3386 : : static __rte_always_inline uint32_t
3387 : : prepare_iov_from_raw_vec(struct rte_crypto_vec *vec, struct roc_se_iov_ptr *iovec, uint32_t num)
3388 : : {
3389 : : uint32_t i, total_len = 0;
3390 : :
3391 [ # # # # : 0 : for (i = 0; i < num; i++) {
# # # # #
# ]
3392 : 0 : iovec->bufs[i].vaddr = vec[i].base;
3393 : 0 : iovec->bufs[i].size = vec[i].len;
3394 : :
3395 : 0 : total_len += vec[i].len;
3396 : : }
3397 : :
3398 : 0 : iovec->buf_cnt = i;
3399 : 0 : return total_len;
3400 : : }
3401 : :
3402 : : static __rte_always_inline void
3403 : : cnxk_raw_burst_to_iov(struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs *ofs, int index,
3404 : : struct cnxk_iov *iov)
3405 : : {
3406 : 0 : iov->iv_buf = vec->iv[index].va;
3407 : 0 : iov->aad_buf = vec->aad[index].va;
3408 : 0 : iov->mac_buf = vec->digest[index].va;
3409 : :
3410 : 0 : iov->data_len =
3411 : 0 : prepare_iov_from_raw_vec(vec->src_sgl[index].vec, (struct roc_se_iov_ptr *)iov->src,
3412 : 0 : vec->src_sgl[index].num);
3413 : :
3414 [ # # ]: 0 : if (vec->dest_sgl == NULL)
3415 : : prepare_iov_from_raw_vec(vec->src_sgl[index].vec, (struct roc_se_iov_ptr *)iov->dst,
3416 : : vec->src_sgl[index].num);
3417 : : else
3418 : 0 : prepare_iov_from_raw_vec(vec->dest_sgl[index].vec,
3419 : : (struct roc_se_iov_ptr *)iov->dst,
3420 : 0 : vec->dest_sgl[index].num);
3421 : :
3422 : 0 : iov->c_head = ofs->ofs.cipher.head;
3423 : 0 : iov->c_tail = ofs->ofs.cipher.tail;
3424 : :
3425 : 0 : iov->a_head = ofs->ofs.auth.head;
3426 : 0 : iov->a_tail = ofs->ofs.auth.tail;
3427 : : }
3428 : :
3429 : : static __rte_always_inline void
3430 : : cnxk_raw_to_iov(struct rte_crypto_vec *data_vec, uint16_t n_vecs, union rte_crypto_sym_ofs *ofs,
3431 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
3432 : : struct rte_crypto_va_iova_ptr *aad, struct cnxk_iov *iov)
3433 : : {
3434 : 0 : iov->iv_buf = iv->va;
3435 : 0 : iov->aad_buf = aad->va;
3436 : 0 : iov->mac_buf = digest->va;
3437 : :
3438 : 0 : iov->data_len =
3439 : 0 : prepare_iov_from_raw_vec(data_vec, (struct roc_se_iov_ptr *)iov->src, n_vecs);
3440 : : prepare_iov_from_raw_vec(data_vec, (struct roc_se_iov_ptr *)iov->dst, n_vecs);
3441 : :
3442 : 0 : iov->c_head = ofs->ofs.cipher.head;
3443 : 0 : iov->c_tail = ofs->ofs.cipher.tail;
3444 : :
3445 : 0 : iov->a_head = ofs->ofs.auth.head;
3446 [ # # ]: 0 : iov->a_tail = ofs->ofs.auth.tail;
3447 : : }
3448 : :
3449 : : static inline void
3450 : 0 : raw_memcpy(struct cnxk_iov *iov)
3451 : : {
3452 : : struct roc_se_iov_ptr *src = (struct roc_se_iov_ptr *)iov->src;
3453 : : struct roc_se_iov_ptr *dst = (struct roc_se_iov_ptr *)iov->dst;
3454 : 0 : int num = src->buf_cnt;
3455 : : int i;
3456 : :
3457 : : /* skip copy in case of inplace */
3458 [ # # ]: 0 : if (dst->bufs[0].vaddr == src->bufs[0].vaddr)
3459 : : return;
3460 : :
3461 [ # # ]: 0 : for (i = 0; i < num; i++) {
3462 [ # # ]: 0 : rte_memcpy(dst->bufs[i].vaddr, src->bufs[i].vaddr, src->bufs[i].size);
3463 : 0 : dst->bufs[i].size = src->bufs[i].size;
3464 : : }
3465 : : }
3466 : :
3467 : : static inline int
3468 : 0 : fill_raw_passthrough_params(struct cnxk_iov *iov, struct cpt_inst_s *inst)
3469 : : {
3470 : : const union cpt_inst_w4 w4 = {
3471 : : .s.opcode_major = ROC_SE_MAJOR_OP_MISC,
3472 : : .s.opcode_minor = ROC_SE_MISC_MINOR_OP_PASSTHROUGH,
3473 : : .s.param1 = 1,
3474 : : .s.param2 = 1,
3475 : : .s.dlen = 0,
3476 : : };
3477 : :
3478 : 0 : inst->w0.u64 = 0;
3479 : 0 : inst->w5.u64 = 0;
3480 : 0 : inst->w4.u64 = w4.u64;
3481 : :
3482 : 0 : raw_memcpy(iov);
3483 : :
3484 : 0 : return 0;
3485 : : }
3486 : :
3487 : : static __rte_always_inline int
3488 : : fill_raw_fc_params(struct cnxk_iov *iov, struct cnxk_se_sess *sess, struct cpt_qp_meta_info *m_info,
3489 : : struct cpt_inflight_req *infl_req, struct cpt_inst_s *inst, const bool is_kasumi,
3490 : : const bool is_aead, const bool is_sg_ver2)
3491 : : {
3492 : : uint32_t cipher_len, auth_len = 0;
3493 : : struct roc_se_fc_params fc_params;
3494 : 0 : uint8_t cpt_op = sess->cpt_op;
3495 : : uint64_t d_offs, d_lens;
3496 : : uint8_t ccm_iv_buf[16];
3497 : : uint32_t flags = 0;
3498 : : void *mdata = NULL;
3499 : : uint32_t iv_buf[4];
3500 : : int ret;
3501 : :
3502 : 0 : fc_params.cipher_iv_len = sess->iv_length;
3503 : 0 : fc_params.ctx = &sess->roc_se_ctx;
3504 : 0 : fc_params.auth_iv_buf = NULL;
3505 : 0 : fc_params.auth_iv_len = 0;
3506 : 0 : fc_params.mac_buf.size = 0;
3507 : 0 : fc_params.mac_buf.vaddr = 0;
3508 : 0 : fc_params.iv_buf = NULL;
3509 : :
3510 [ # # # # ]: 0 : if (likely(sess->iv_length)) {
3511 : : flags |= ROC_SE_VALID_IV_BUF;
3512 : :
3513 [ # # # # ]: 0 : if (sess->is_gmac) {
3514 : 0 : fc_params.iv_buf = iov->aad_buf;
3515 [ # # # # ]: 0 : if (sess->short_iv) {
3516 : : memcpy((void *)iv_buf, iov->aad_buf, 12);
3517 : 0 : iv_buf[3] = rte_cpu_to_be_32(0x1);
3518 : 0 : fc_params.iv_buf = iv_buf;
3519 : : }
3520 : : } else {
3521 : 0 : fc_params.iv_buf = iov->iv_buf;
3522 [ # # # # ]: 0 : if (sess->short_iv) {
3523 : : memcpy((void *)iv_buf, iov->iv_buf, 12);
3524 : 0 : iv_buf[3] = rte_cpu_to_be_32(0x1);
3525 : 0 : fc_params.iv_buf = iv_buf;
3526 : : }
3527 : : }
3528 : :
3529 [ # # # # ]: 0 : if (sess->aes_ccm) {
3530 : 0 : memcpy((uint8_t *)ccm_iv_buf, iov->iv_buf, sess->iv_length + 1);
3531 : 0 : ccm_iv_buf[0] = 14 - sess->iv_length;
3532 : 0 : fc_params.iv_buf = ccm_iv_buf;
3533 : : }
3534 : : }
3535 : :
3536 : 0 : fc_params.src_iov = (void *)iov->src;
3537 : 0 : fc_params.dst_iov = (void *)iov->dst;
3538 : :
3539 : 0 : cipher_len = iov->data_len - iov->c_head - iov->c_tail;
3540 : 0 : auth_len = iov->data_len - iov->a_head - iov->a_tail;
3541 : :
3542 : 0 : d_offs = (iov->c_head << 16) | iov->a_head;
3543 : 0 : d_lens = ((uint64_t)cipher_len << 32) | auth_len;
3544 : :
3545 : : if (is_aead) {
3546 : 0 : uint16_t aad_len = sess->aad_length;
3547 : :
3548 [ # # ]: 0 : if (likely(aad_len == 0)) {
3549 : 0 : d_offs = (iov->c_head << 16) | iov->c_head;
3550 : 0 : d_lens = ((uint64_t)cipher_len << 32) | cipher_len;
3551 : : } else {
3552 : 0 : flags |= ROC_SE_VALID_AAD_BUF;
3553 : 0 : fc_params.aad_buf.size = sess->aad_length;
3554 : : /* For AES CCM, AAD is written 18B after aad.data as per API */
3555 [ # # ]: 0 : if (sess->aes_ccm)
3556 : 0 : fc_params.aad_buf.vaddr = PLT_PTR_ADD((uint8_t *)iov->aad_buf, 18);
3557 : : else
3558 : 0 : fc_params.aad_buf.vaddr = iov->aad_buf;
3559 : :
3560 : 0 : d_offs = (iov->c_head << 16);
3561 : : d_lens = ((uint64_t)cipher_len << 32);
3562 : : }
3563 : : }
3564 : :
3565 [ # # # # ]: 0 : if (likely(sess->mac_len)) {
3566 : 0 : flags |= ROC_SE_VALID_MAC_BUF;
3567 : 0 : fc_params.mac_buf.size = sess->mac_len;
3568 : 0 : fc_params.mac_buf.vaddr = iov->mac_buf;
3569 : : }
3570 : :
3571 : 0 : fc_params.meta_buf.vaddr = NULL;
3572 [ # # # # ]: 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
3573 [ # # # # ]: 0 : if (mdata == NULL) {
3574 : 0 : plt_dp_err("Error allocating meta buffer for request");
3575 : 0 : return -ENOMEM;
3576 : : }
3577 : :
3578 : : if (is_kasumi) {
3579 : : if (cpt_op & ROC_SE_OP_ENCODE)
3580 : : ret = cpt_enc_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
3581 : : is_sg_ver2);
3582 : : else
3583 : : ret = cpt_dec_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
3584 : : is_sg_ver2);
3585 : : } else {
3586 [ # # # # ]: 0 : if (cpt_op & ROC_SE_OP_ENCODE)
3587 : : ret = cpt_enc_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
3588 : : is_sg_ver2);
3589 : : else
3590 : : ret = cpt_dec_hmac_prep(flags, d_offs, d_lens, &fc_params, inst,
3591 : : is_sg_ver2);
3592 : : }
3593 : :
3594 [ # # # # ]: 0 : if (unlikely(ret)) {
3595 : 0 : plt_dp_err("Preparing request failed due to bad input arg");
3596 : 0 : goto free_mdata_and_exit;
3597 : : }
3598 : :
3599 : : return 0;
3600 : :
3601 : : free_mdata_and_exit:
3602 [ # # # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
3603 : 0 : return ret;
3604 : : }
3605 : :
3606 : : static __rte_always_inline int
3607 : : fill_raw_digest_params(struct cnxk_iov *iov, struct cnxk_se_sess *sess,
3608 : : struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
3609 : : struct cpt_inst_s *inst, const bool is_sg_ver2)
3610 : : {
3611 : 0 : uint16_t auth_op = sess->cpt_op & ROC_SE_OP_AUTH_MASK;
3612 : : struct roc_se_fc_params fc_params;
3613 [ # # ]: 0 : uint16_t mac_len = sess->mac_len;
3614 : : uint64_t d_offs, d_lens;
3615 : : uint32_t auth_len = 0;
3616 : : uint32_t flags = 0;
3617 : : void *mdata = NULL;
3618 : : uint32_t space = 0;
3619 : : int ret;
3620 : :
3621 : : memset(&fc_params, 0, sizeof(struct roc_se_fc_params));
3622 : 0 : fc_params.cipher_iv_len = sess->iv_length;
3623 : 0 : fc_params.ctx = &sess->roc_se_ctx;
3624 : :
3625 [ # # ]: 0 : mdata = alloc_op_meta(&fc_params.meta_buf, m_info->mlen, m_info->pool, infl_req);
3626 [ # # ]: 0 : if (mdata == NULL) {
3627 : 0 : plt_dp_err("Error allocating meta buffer for request");
3628 : : ret = -ENOMEM;
3629 : 0 : goto err_exit;
3630 : : }
3631 : :
3632 : : flags |= ROC_SE_VALID_MAC_BUF;
3633 : 0 : fc_params.src_iov = (void *)iov->src;
3634 : 0 : auth_len = iov->data_len - iov->a_head - iov->a_tail;
3635 : : d_lens = auth_len;
3636 : 0 : d_offs = iov->a_head;
3637 : :
3638 [ # # ]: 0 : if (auth_op == ROC_SE_OP_AUTH_GENERATE) {
3639 : 0 : fc_params.mac_buf.size = sess->mac_len;
3640 : 0 : fc_params.mac_buf.vaddr = iov->mac_buf;
3641 : : } else {
3642 : : uint64_t *op = mdata;
3643 : :
3644 : : /* Need space for storing generated mac */
3645 : : space += 2 * sizeof(uint64_t);
3646 : :
3647 : 0 : fc_params.mac_buf.vaddr = (uint8_t *)mdata + space;
3648 : 0 : fc_params.mac_buf.size = mac_len;
3649 : 0 : space += RTE_ALIGN_CEIL(mac_len, 8);
3650 : 0 : op[0] = (uintptr_t)iov->mac_buf;
3651 : 0 : op[1] = mac_len;
3652 : 0 : infl_req->op_flags |= CPT_OP_FLAGS_AUTH_VERIFY;
3653 : : }
3654 : :
3655 : 0 : fc_params.meta_buf.vaddr = (uint8_t *)mdata + space;
3656 [ # # ]: 0 : fc_params.meta_buf.size -= space;
3657 : :
3658 : : ret = cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, &fc_params, inst, is_sg_ver2);
3659 [ # # ]: 0 : if (ret)
3660 : 0 : goto free_mdata_and_exit;
3661 : :
3662 : : return 0;
3663 : :
3664 : : free_mdata_and_exit:
3665 [ # # ]: 0 : if (infl_req->op_flags & CPT_OP_FLAGS_METABUF)
3666 [ # # ]: 0 : rte_mempool_put(m_info->pool, infl_req->mdata);
3667 : 0 : err_exit:
3668 : : return ret;
3669 : : }
3670 : :
3671 : : #endif /*_CNXK_SE_H_ */
|