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