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