Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017-2022 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_cryptodev.h>
6 : : #include <rte_security_driver.h>
7 : :
8 : : #include "adf_transport_access_macros.h"
9 : : #include "icp_qat_fw.h"
10 : : #include "icp_qat_fw_la.h"
11 : :
12 : : #include "qat_sym.h"
13 : : #include "qat_sym_session.h"
14 : : #include "qat_crypto.h"
15 : : #include "qat_crypto_pmd_gens.h"
16 : :
17 : : static struct rte_cryptodev_capabilities qat_sym_crypto_legacy_caps_gen1[] = {
18 : : QAT_SYM_CIPHER_CAP(DES_CBC,
19 : : CAP_SET(block_size, 8),
20 : : CAP_RNG(key_size, 8, 24, 8), CAP_RNG(iv_size, 8, 8, 0)),
21 : : QAT_SYM_CIPHER_CAP(3DES_CBC,
22 : : CAP_SET(block_size, 8),
23 : : CAP_RNG(key_size, 8, 24, 8), CAP_RNG(iv_size, 8, 8, 0)),
24 : : QAT_SYM_CIPHER_CAP(3DES_CTR,
25 : : CAP_SET(block_size, 8),
26 : : CAP_RNG(key_size, 16, 24, 8), CAP_RNG(iv_size, 8, 8, 0)),
27 : : QAT_SYM_PLAIN_AUTH_CAP(SHA1,
28 : : CAP_SET(block_size, 64),
29 : : CAP_RNG(digest_size, 1, 20, 1)),
30 : : QAT_SYM_AUTH_CAP(SHA224,
31 : : CAP_SET(block_size, 64),
32 : : CAP_RNG_ZERO(key_size), CAP_RNG(digest_size, 1, 28, 1),
33 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
34 : : QAT_SYM_AUTH_CAP(SHA1_HMAC,
35 : : CAP_SET(block_size, 64),
36 : : CAP_RNG(key_size, 1, 64, 1), CAP_RNG(digest_size, 1, 20, 1),
37 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
38 : : QAT_SYM_AUTH_CAP(SHA224_HMAC,
39 : : CAP_SET(block_size, 64),
40 : : CAP_RNG(key_size, 1, 64, 1), CAP_RNG(digest_size, 1, 28, 1),
41 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
42 : : QAT_SYM_AUTH_CAP(MD5_HMAC,
43 : : CAP_SET(block_size, 64),
44 : : CAP_RNG(key_size, 1, 64, 1), CAP_RNG(digest_size, 1, 16, 1),
45 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
46 : : QAT_SYM_CIPHER_CAP(DES_DOCSISBPI,
47 : : CAP_SET(block_size, 8),
48 : : CAP_RNG(key_size, 8, 8, 0), CAP_RNG(iv_size, 8, 8, 0)),
49 : : };
50 : :
51 : : static struct rte_cryptodev_capabilities qat_sym_crypto_caps_gen1[] = {
52 : : QAT_SYM_AEAD_CAP(AES_GCM,
53 : : CAP_SET(block_size, 16),
54 : : CAP_RNG(key_size, 16, 32, 8), CAP_RNG(digest_size, 8, 16, 4),
55 : : CAP_RNG(aad_size, 0, 240, 1), CAP_RNG(iv_size, 0, 12, 12)),
56 : : QAT_SYM_AEAD_CAP(AES_CCM,
57 : : CAP_SET(block_size, 16),
58 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(digest_size, 4, 16, 2),
59 : : CAP_RNG(aad_size, 0, 224, 1), CAP_RNG(iv_size, 7, 13, 1)),
60 : : QAT_SYM_AUTH_CAP(AES_GMAC,
61 : : CAP_SET(block_size, 16),
62 : : CAP_RNG(key_size, 16, 32, 8), CAP_RNG(digest_size, 8, 16, 4),
63 : : CAP_RNG_ZERO(aad_size), CAP_RNG(iv_size, 0, 12, 12)),
64 : : QAT_SYM_AUTH_CAP(AES_CMAC,
65 : : CAP_SET(block_size, 16),
66 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(digest_size, 4, 16, 4),
67 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
68 : : QAT_SYM_AUTH_CAP(SHA256,
69 : : CAP_SET(block_size, 64),
70 : : CAP_RNG_ZERO(key_size), CAP_RNG(digest_size, 1, 32, 1),
71 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
72 : : QAT_SYM_AUTH_CAP(SHA384,
73 : : CAP_SET(block_size, 128),
74 : : CAP_RNG_ZERO(key_size), CAP_RNG(digest_size, 1, 48, 1),
75 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
76 : : QAT_SYM_AUTH_CAP(SHA512,
77 : : CAP_SET(block_size, 128),
78 : : CAP_RNG_ZERO(key_size), CAP_RNG(digest_size, 1, 64, 1),
79 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
80 : : QAT_SYM_AUTH_CAP(SHA256_HMAC,
81 : : CAP_SET(block_size, 64),
82 : : CAP_RNG(key_size, 1, 64, 1), CAP_RNG(digest_size, 1, 32, 1),
83 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
84 : : QAT_SYM_AUTH_CAP(SHA384_HMAC,
85 : : CAP_SET(block_size, 128),
86 : : CAP_RNG(key_size, 1, 128, 1), CAP_RNG(digest_size, 1, 48, 1),
87 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
88 : : QAT_SYM_AUTH_CAP(SHA512_HMAC,
89 : : CAP_SET(block_size, 128),
90 : : CAP_RNG(key_size, 1, 128, 1), CAP_RNG(digest_size, 1, 64, 1),
91 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
92 : : QAT_SYM_AUTH_CAP(AES_XCBC_MAC,
93 : : CAP_SET(block_size, 16),
94 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(digest_size, 12, 12, 0),
95 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
96 : : QAT_SYM_AUTH_CAP(SNOW3G_UIA2,
97 : : CAP_SET(block_size, 16),
98 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(digest_size, 4, 4, 0),
99 : : CAP_RNG_ZERO(aad_size), CAP_RNG(iv_size, 16, 16, 0)),
100 : : QAT_SYM_AUTH_CAP(KASUMI_F9,
101 : : CAP_SET(block_size, 8),
102 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(digest_size, 4, 4, 0),
103 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
104 : : QAT_SYM_AUTH_CAP(NULL,
105 : : CAP_SET(block_size, 1),
106 : : CAP_RNG_ZERO(key_size), CAP_RNG_ZERO(digest_size),
107 : : CAP_RNG_ZERO(aad_size), CAP_RNG_ZERO(iv_size)),
108 : : QAT_SYM_CIPHER_CAP(AES_CBC,
109 : : CAP_SET(block_size, 16),
110 : : CAP_RNG(key_size, 16, 32, 8), CAP_RNG(iv_size, 16, 16, 0)),
111 : : QAT_SYM_CIPHER_CAP(AES_CTR,
112 : : CAP_SET(block_size, 16),
113 : : CAP_RNG(key_size, 16, 32, 8), CAP_RNG(iv_size, 16, 16, 0)),
114 : : QAT_SYM_CIPHER_CAP(AES_XTS,
115 : : CAP_SET(block_size, 16),
116 : : CAP_RNG(key_size, 32, 64, 32), CAP_RNG(iv_size, 16, 16, 0)),
117 : : QAT_SYM_CIPHER_CAP(AES_DOCSISBPI,
118 : : CAP_SET(block_size, 16),
119 : : CAP_RNG(key_size, 16, 32, 16), CAP_RNG(iv_size, 16, 16, 0)),
120 : : QAT_SYM_CIPHER_CAP(SNOW3G_UEA2,
121 : : CAP_SET(block_size, 16),
122 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(iv_size, 16, 16, 0)),
123 : : QAT_SYM_CIPHER_CAP(KASUMI_F8,
124 : : CAP_SET(block_size, 8),
125 : : CAP_RNG(key_size, 16, 16, 0), CAP_RNG(iv_size, 8, 8, 0)),
126 : : QAT_SYM_CIPHER_CAP(NULL,
127 : : CAP_SET(block_size, 1),
128 : : CAP_RNG_ZERO(key_size), CAP_RNG_ZERO(iv_size)),
129 : : RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
130 : : };
131 : :
132 : : struct rte_cryptodev_ops qat_sym_crypto_ops_gen1 = {
133 : :
134 : : /* Device related operations */
135 : : .dev_configure = qat_cryptodev_config,
136 : : .dev_start = qat_cryptodev_start,
137 : : .dev_stop = qat_cryptodev_stop,
138 : : .dev_close = qat_cryptodev_close,
139 : : .dev_infos_get = qat_cryptodev_info_get,
140 : :
141 : : .stats_get = qat_cryptodev_stats_get,
142 : : .stats_reset = qat_cryptodev_stats_reset,
143 : : .queue_pair_setup = qat_cryptodev_qp_setup,
144 : : .queue_pair_release = qat_cryptodev_qp_release,
145 : :
146 : : /* Crypto related operations */
147 : : .sym_session_get_size = qat_sym_session_get_private_size,
148 : : .sym_session_configure = qat_sym_session_configure,
149 : : .sym_session_clear = qat_sym_session_clear,
150 : :
151 : : /* Raw data-path API related operations */
152 : : .sym_get_raw_dp_ctx_size = qat_sym_get_dp_ctx_size,
153 : : .sym_configure_raw_dp_ctx = qat_sym_configure_dp_ctx,
154 : : };
155 : :
156 : : static int
157 : 0 : qat_sym_crypto_cap_get_gen1(struct qat_cryptodev_private *internals,
158 : : const char *capa_memz_name,
159 : : const uint16_t __rte_unused slice_map)
160 : : {
161 : :
162 : : uint32_t legacy_capa_num;
163 : : uint32_t size = sizeof(qat_sym_crypto_caps_gen1);
164 : : uint32_t legacy_size = sizeof(qat_sym_crypto_legacy_caps_gen1);
165 : : legacy_capa_num = legacy_size/sizeof(struct rte_cryptodev_capabilities);
166 : :
167 [ # # ]: 0 : if (unlikely(qat_legacy_capa))
168 : : size = size + legacy_size;
169 : :
170 : 0 : internals->capa_mz = rte_memzone_lookup(capa_memz_name);
171 [ # # ]: 0 : if (internals->capa_mz == NULL) {
172 : 0 : internals->capa_mz = rte_memzone_reserve(capa_memz_name,
173 : 0 : size, rte_socket_id(), 0);
174 [ # # ]: 0 : if (internals->capa_mz == NULL) {
175 : 0 : QAT_LOG(DEBUG,
176 : : "Error allocating memzone for capabilities");
177 : 0 : return -1;
178 : : }
179 : : }
180 : :
181 : 0 : struct rte_cryptodev_capabilities *addr =
182 : : (struct rte_cryptodev_capabilities *)
183 : 0 : internals->capa_mz->addr;
184 : :
185 : : struct rte_cryptodev_capabilities *capabilities;
186 : :
187 [ # # ]: 0 : if (unlikely(qat_legacy_capa)) {
188 : : capabilities = qat_sym_crypto_legacy_caps_gen1;
189 : : memcpy(addr, capabilities, legacy_size);
190 : 0 : addr += legacy_capa_num;
191 : : }
192 : : capabilities = qat_sym_crypto_caps_gen1;
193 : : memcpy(addr, capabilities, sizeof(qat_sym_crypto_caps_gen1));
194 : 0 : internals->qat_dev_capabilities = internals->capa_mz->addr;
195 : :
196 : 0 : return 0;
197 : : }
198 : :
199 : : uint64_t
200 : 0 : qat_sym_crypto_feature_flags_get_gen1(
201 : : struct qat_pci_device *qat_dev __rte_unused)
202 : : {
203 : : uint64_t feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
204 : : RTE_CRYPTODEV_FF_HW_ACCELERATED |
205 : : RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
206 : : RTE_CRYPTODEV_FF_IN_PLACE_SGL |
207 : : RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
208 : : RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
209 : : RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
210 : : RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
211 : : RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED |
212 : : RTE_CRYPTODEV_FF_SYM_RAW_DP;
213 : :
214 : 0 : return feature_flags;
215 : : }
216 : :
217 : : int
218 [ # # ]: 0 : qat_sym_build_op_cipher_gen1(void *in_op, struct qat_sym_session *ctx,
219 : : uint8_t *out_msg, void *op_cookie)
220 : : {
221 : : register struct icp_qat_fw_la_bulk_req *req;
222 : : struct rte_crypto_op *op = in_op;
223 : : struct qat_sym_op_cookie *cookie = op_cookie;
224 : : struct rte_crypto_sgl in_sgl, out_sgl;
225 : : struct rte_crypto_vec in_vec[QAT_SYM_SGL_MAX_NUMBER],
226 : : out_vec[QAT_SYM_SGL_MAX_NUMBER];
227 : : struct rte_crypto_va_iova_ptr cipher_iv;
228 : : union rte_crypto_sym_ofs ofs;
229 : : int32_t total_len;
230 : :
231 : : in_sgl.vec = in_vec;
232 : : out_sgl.vec = out_vec;
233 : :
234 : : req = (struct icp_qat_fw_la_bulk_req *)out_msg;
235 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
236 : :
237 : : ofs.raw = qat_sym_convert_op_to_vec_cipher(op, ctx, &in_sgl, &out_sgl,
238 : : &cipher_iv, NULL, NULL);
239 [ # # ]: 0 : if (unlikely(ofs.raw == UINT64_MAX)) {
240 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
241 : 0 : return -EINVAL;
242 : : }
243 : :
244 [ # # ]: 0 : total_len = qat_sym_build_req_set_data(req, in_op, cookie,
245 : : in_sgl.vec, in_sgl.num, out_sgl.vec, out_sgl.num);
246 [ # # ]: 0 : if (unlikely(total_len < 0)) {
247 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
248 : 0 : return -EINVAL;
249 : : }
250 : :
251 [ # # ]: 0 : enqueue_one_cipher_job_gen1(ctx, req, &cipher_iv, ofs, total_len, op_cookie);
252 : :
253 : : qat_sym_debug_log_dump(req, ctx, in_sgl.vec, in_sgl.num, &cipher_iv,
254 : : NULL, NULL, NULL);
255 : :
256 : 0 : return 0;
257 : : }
258 : :
259 : : int
260 [ # # ]: 0 : qat_sym_build_op_auth_gen1(void *in_op, struct qat_sym_session *ctx,
261 : : uint8_t *out_msg, void *op_cookie)
262 : : {
263 : : register struct icp_qat_fw_la_bulk_req *req;
264 : : struct rte_crypto_op *op = in_op;
265 : : struct qat_sym_op_cookie *cookie = op_cookie;
266 : : struct rte_crypto_sgl in_sgl, out_sgl;
267 : : struct rte_crypto_vec in_vec[QAT_SYM_SGL_MAX_NUMBER],
268 : : out_vec[QAT_SYM_SGL_MAX_NUMBER];
269 : : struct rte_crypto_va_iova_ptr auth_iv;
270 : : struct rte_crypto_va_iova_ptr digest;
271 : : union rte_crypto_sym_ofs ofs;
272 : : int32_t total_len;
273 : :
274 : : in_sgl.vec = in_vec;
275 : : out_sgl.vec = out_vec;
276 : :
277 : : req = (struct icp_qat_fw_la_bulk_req *)out_msg;
278 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
279 : :
280 : : ofs.raw = qat_sym_convert_op_to_vec_auth(op, ctx, &in_sgl, &out_sgl,
281 : : NULL, &auth_iv, &digest, op_cookie);
282 [ # # ]: 0 : if (unlikely(ofs.raw == UINT64_MAX)) {
283 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
284 : 0 : return -EINVAL;
285 : : }
286 : :
287 [ # # ]: 0 : total_len = qat_sym_build_req_set_data(req, in_op, cookie,
288 : : in_sgl.vec, in_sgl.num, out_sgl.vec, out_sgl.num);
289 [ # # ]: 0 : if (unlikely(total_len < 0)) {
290 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
291 : 0 : return -EINVAL;
292 : : }
293 : :
294 [ # # # # ]: 0 : enqueue_one_auth_job_gen1(ctx, req, &digest, &auth_iv, ofs,
295 : : total_len);
296 : :
297 : : qat_sym_debug_log_dump(req, ctx, in_sgl.vec, in_sgl.num, NULL,
298 : : &auth_iv, NULL, &digest);
299 : :
300 : 0 : return 0;
301 : : }
302 : :
303 : : int
304 : 0 : qat_sym_build_op_aead_gen1(void *in_op, struct qat_sym_session *ctx,
305 : : uint8_t *out_msg, void *op_cookie)
306 : : {
307 : : register struct icp_qat_fw_la_bulk_req *req;
308 : : struct rte_crypto_op *op = in_op;
309 : : struct qat_sym_op_cookie *cookie = op_cookie;
310 : : struct rte_crypto_sgl in_sgl, out_sgl;
311 : : struct rte_crypto_vec in_vec[QAT_SYM_SGL_MAX_NUMBER],
312 : : out_vec[QAT_SYM_SGL_MAX_NUMBER];
313 : : struct rte_crypto_va_iova_ptr cipher_iv;
314 : : struct rte_crypto_va_iova_ptr aad;
315 : : struct rte_crypto_va_iova_ptr digest;
316 : : union rte_crypto_sym_ofs ofs;
317 : : int32_t total_len;
318 : :
319 : : in_sgl.vec = in_vec;
320 : : out_sgl.vec = out_vec;
321 : :
322 : : req = (struct icp_qat_fw_la_bulk_req *)out_msg;
323 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
324 : :
325 : : ofs.raw = qat_sym_convert_op_to_vec_aead(op, ctx, &in_sgl, &out_sgl,
326 : : &cipher_iv, &aad, &digest);
327 [ # # ]: 0 : if (unlikely(ofs.raw == UINT64_MAX)) {
328 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
329 : 0 : return -EINVAL;
330 : : }
331 : :
332 [ # # ]: 0 : total_len = qat_sym_build_req_set_data(req, in_op, cookie,
333 : : in_sgl.vec, in_sgl.num, out_sgl.vec, out_sgl.num);
334 [ # # ]: 0 : if (unlikely(total_len < 0)) {
335 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
336 : 0 : return -EINVAL;
337 : : }
338 : :
339 [ # # # ]: 0 : enqueue_one_aead_job_gen1(ctx, req, &cipher_iv, &digest, &aad, ofs,
340 : : total_len);
341 : :
342 : : qat_sym_debug_log_dump(req, ctx, in_sgl.vec, in_sgl.num, &cipher_iv,
343 : : NULL, &aad, &digest);
344 : :
345 : 0 : return 0;
346 : : }
347 : :
348 : : int
349 [ # # ]: 0 : qat_sym_build_op_chain_gen1(void *in_op, struct qat_sym_session *ctx,
350 : : uint8_t *out_msg, void *op_cookie)
351 : : {
352 : : register struct icp_qat_fw_la_bulk_req *req;
353 : : struct rte_crypto_op *op = in_op;
354 : : struct qat_sym_op_cookie *cookie = op_cookie;
355 : : struct rte_crypto_sgl in_sgl = {0}, out_sgl = {0};
356 : : struct rte_crypto_vec in_vec[QAT_SYM_SGL_MAX_NUMBER],
357 : : out_vec[QAT_SYM_SGL_MAX_NUMBER];
358 : : struct rte_crypto_va_iova_ptr cipher_iv;
359 : : struct rte_crypto_va_iova_ptr auth_iv;
360 : : struct rte_crypto_va_iova_ptr digest;
361 : : union rte_crypto_sym_ofs ofs;
362 : : int32_t total_len;
363 : :
364 : : in_sgl.vec = in_vec;
365 : : out_sgl.vec = out_vec;
366 : :
367 : : req = (struct icp_qat_fw_la_bulk_req *)out_msg;
368 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
369 : :
370 : : ofs.raw = qat_sym_convert_op_to_vec_chain(op, ctx, &in_sgl, &out_sgl,
371 : : &cipher_iv, &auth_iv, &digest, cookie);
372 [ # # ]: 0 : if (unlikely(ofs.raw == UINT64_MAX)) {
373 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
374 : 0 : return -EINVAL;
375 : : }
376 : :
377 [ # # ]: 0 : total_len = qat_sym_build_req_set_data(req, in_op, cookie,
378 : : in_sgl.vec, in_sgl.num, out_sgl.vec, out_sgl.num);
379 [ # # ]: 0 : if (unlikely(total_len < 0)) {
380 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
381 : 0 : return -EINVAL;
382 : : }
383 : :
384 [ # # ]: 0 : enqueue_one_chain_job_gen1(ctx, req, in_sgl.vec, in_sgl.num,
385 : : out_sgl.vec, out_sgl.num, &cipher_iv, &digest, &auth_iv,
386 : : ofs, total_len, cookie);
387 : :
388 : : qat_sym_debug_log_dump(req, ctx, in_sgl.vec, in_sgl.num, &cipher_iv,
389 : : &auth_iv, NULL, &digest);
390 : :
391 : : return 0;
392 : : }
393 : :
394 : : #define QAT_SECURITY_SYM_CAPABILITIES \
395 : : { /* AES DOCSIS BPI */ \
396 : : .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, \
397 : : {.sym = { \
398 : : .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, \
399 : : {.cipher = { \
400 : : .algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI,\
401 : : .block_size = 16, \
402 : : .key_size = { \
403 : : .min = 16, \
404 : : .max = 32, \
405 : : .increment = 16 \
406 : : }, \
407 : : .iv_size = { \
408 : : .min = 16, \
409 : : .max = 16, \
410 : : .increment = 0 \
411 : : } \
412 : : }, } \
413 : : }, } \
414 : : }
415 : :
416 : : #define QAT_SECURITY_CAPABILITIES(sym) \
417 : : [0] = { /* DOCSIS Uplink */ \
418 : : .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, \
419 : : .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, \
420 : : .docsis = { \
421 : : .direction = RTE_SECURITY_DOCSIS_UPLINK \
422 : : }, \
423 : : .crypto_capabilities = (sym) \
424 : : }, \
425 : : [1] = { /* DOCSIS Downlink */ \
426 : : .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, \
427 : : .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, \
428 : : .docsis = { \
429 : : .direction = RTE_SECURITY_DOCSIS_DOWNLINK \
430 : : }, \
431 : : .crypto_capabilities = (sym) \
432 : : }
433 : :
434 : : static const struct rte_cryptodev_capabilities
435 : : qat_security_sym_capabilities[] = {
436 : : QAT_SECURITY_SYM_CAPABILITIES,
437 : : RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
438 : : };
439 : :
440 : : static const struct rte_security_capability qat_security_capabilities_gen1[] = {
441 : : QAT_SECURITY_CAPABILITIES(qat_security_sym_capabilities),
442 : : {
443 : : .action = RTE_SECURITY_ACTION_TYPE_NONE
444 : : }
445 : : };
446 : :
447 : : static const struct rte_security_capability *
448 : 0 : qat_security_cap_get_gen1(void *dev __rte_unused)
449 : : {
450 : 0 : return qat_security_capabilities_gen1;
451 : : }
452 : :
453 : : struct rte_security_ops security_qat_ops_gen1 = {
454 : : .session_create = qat_security_session_create,
455 : : .session_update = NULL,
456 : : .session_get_size = qat_security_session_get_size,
457 : : .session_stats_get = NULL,
458 : : .session_destroy = qat_security_session_destroy,
459 : : .set_pkt_metadata = NULL,
460 : : .capabilities_get = qat_security_cap_get_gen1
461 : : };
462 : :
463 : : void *
464 : 0 : qat_sym_create_security_gen1(void *cryptodev)
465 : : {
466 : : struct rte_security_ctx *security_instance;
467 : :
468 : 0 : security_instance = rte_malloc(NULL, sizeof(struct rte_security_ctx),
469 : : RTE_CACHE_LINE_SIZE);
470 [ # # ]: 0 : if (security_instance == NULL)
471 : : return NULL;
472 : :
473 : 0 : security_instance->device = cryptodev;
474 : 0 : security_instance->ops = &security_qat_ops_gen1;
475 : 0 : security_instance->sess_cnt = 0;
476 : :
477 : 0 : return (void *)security_instance;
478 : : }
479 : :
480 : : int
481 : 0 : qat_sym_dp_enqueue_single_cipher_gen1(void *qp_data, uint8_t *drv_ctx,
482 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
483 : : union rte_crypto_sym_ofs ofs,
484 : : struct rte_crypto_va_iova_ptr *iv,
485 : : struct rte_crypto_va_iova_ptr *digest __rte_unused,
486 : : struct rte_crypto_va_iova_ptr *aad __rte_unused,
487 : : void *user_data)
488 : : {
489 : : struct qat_qp *qp = qp_data;
490 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
491 : : struct qat_queue *tx_queue = &qp->tx_q;
492 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
493 : : struct qat_sym_op_cookie *cookie;
494 : : struct icp_qat_fw_la_bulk_req *req;
495 : : int32_t data_len;
496 : 0 : uint32_t tail = dp_ctx->tail;
497 : :
498 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
499 : 0 : (uint8_t *)tx_queue->base_addr + tail);
500 : 0 : cookie = qp->op_cookies[tail >> tx_queue->trailz];
501 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
502 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
503 : 0 : rte_prefetch0((uint8_t *)tx_queue->base_addr + tail);
504 : :
505 : : data_len = qat_sym_build_req_set_data(req, user_data, cookie,
506 : : data, n_data_vecs, NULL, 0);
507 [ # # ]: 0 : if (unlikely(data_len < 0))
508 : : return -1;
509 : :
510 [ # # ]: 0 : enqueue_one_cipher_job_gen1(ctx, req, iv, ofs, (uint32_t)data_len, cookie);
511 : :
512 : : qat_sym_debug_log_dump(req, ctx, data, n_data_vecs, iv,
513 : : NULL, NULL, NULL);
514 : :
515 : 0 : dp_ctx->tail = tail;
516 : 0 : dp_ctx->cached_enqueue++;
517 : :
518 : 0 : return 0;
519 : : }
520 : :
521 : : uint32_t
522 : 0 : qat_sym_dp_enqueue_cipher_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
523 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
524 : : void *user_data[], int *status)
525 : : {
526 : : struct qat_qp *qp = qp_data;
527 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
528 : : struct qat_queue *tx_queue = &qp->tx_q;
529 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
530 : : uint32_t i, n;
531 : : uint32_t tail;
532 : : struct icp_qat_fw_la_bulk_req *req;
533 : : int32_t data_len;
534 : :
535 : 0 : n = QAT_SYM_DP_GET_MAX_ENQ(qp, dp_ctx->cached_enqueue, vec->num);
536 [ # # ]: 0 : if (unlikely(n == 0)) {
537 : 0 : qat_sym_dp_fill_vec_status(vec->status, -1, vec->num);
538 : 0 : *status = 0;
539 : 0 : return 0;
540 : : }
541 : :
542 : 0 : tail = dp_ctx->tail;
543 : :
544 [ # # ]: 0 : for (i = 0; i < n; i++) {
545 : 0 : struct qat_sym_op_cookie *cookie =
546 : 0 : qp->op_cookies[tail >> tx_queue->trailz];
547 : :
548 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
549 [ # # ]: 0 : (uint8_t *)tx_queue->base_addr + tail);
550 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
551 : :
552 [ # # ]: 0 : if (vec->dest_sgl) {
553 : 0 : data_len = qat_sym_build_req_set_data(req,
554 : 0 : user_data[i], cookie,
555 : 0 : vec->src_sgl[i].vec, vec->src_sgl[i].num,
556 [ # # ]: 0 : vec->dest_sgl[i].vec, vec->dest_sgl[i].num);
557 : : } else {
558 : 0 : data_len = qat_sym_build_req_set_data(req,
559 : 0 : user_data[i], cookie,
560 : : vec->src_sgl[i].vec,
561 [ # # ]: 0 : vec->src_sgl[i].num, NULL, 0);
562 : : }
563 : :
564 [ # # ]: 0 : if (unlikely(data_len < 0))
565 : : break;
566 [ # # ]: 0 : enqueue_one_cipher_job_gen1(ctx, req, &vec->iv[i], ofs,
567 : : (uint32_t)data_len, cookie);
568 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
569 : :
570 : : qat_sym_debug_log_dump(req, ctx, vec->src_sgl[i].vec,
571 : : vec->src_sgl[i].num, &vec->iv[i],
572 : : NULL, NULL, NULL);
573 : : }
574 : :
575 [ # # ]: 0 : if (unlikely(i < n))
576 : 0 : qat_sym_dp_fill_vec_status(vec->status + i, -1, n - i);
577 : :
578 : 0 : dp_ctx->tail = tail;
579 : 0 : dp_ctx->cached_enqueue += i;
580 : 0 : *status = 0;
581 : 0 : return i;
582 : : }
583 : :
584 : : int
585 : 0 : qat_sym_dp_enqueue_single_auth_gen1(void *qp_data, uint8_t *drv_ctx,
586 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
587 : : union rte_crypto_sym_ofs ofs,
588 : : struct rte_crypto_va_iova_ptr *iv __rte_unused,
589 : : struct rte_crypto_va_iova_ptr *digest,
590 : : struct rte_crypto_va_iova_ptr *auth_iv,
591 : : void *user_data)
592 : : {
593 : : struct qat_qp *qp = qp_data;
594 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
595 : : struct qat_queue *tx_queue = &qp->tx_q;
596 : : struct qat_sym_op_cookie *cookie;
597 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
598 : : struct icp_qat_fw_la_bulk_req *req;
599 : : int32_t data_len;
600 : 0 : uint32_t tail = dp_ctx->tail;
601 : : struct rte_crypto_va_iova_ptr null_digest;
602 : : struct rte_crypto_va_iova_ptr *job_digest = digest;
603 : :
604 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
605 : 0 : (uint8_t *)tx_queue->base_addr + tail);
606 : 0 : cookie = qp->op_cookies[tail >> tx_queue->trailz];
607 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
608 : :
609 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
610 : 0 : rte_prefetch0((uint8_t *)tx_queue->base_addr + tail);
611 : : data_len = qat_sym_build_req_set_data(req, user_data, cookie,
612 : : data, n_data_vecs, NULL, 0);
613 [ # # ]: 0 : if (unlikely(data_len < 0))
614 : : return -1;
615 : :
616 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL) {
617 : 0 : null_digest.iova = cookie->digest_null_phys_addr;
618 : : job_digest = &null_digest;
619 : : }
620 : :
621 [ # # # # ]: 0 : enqueue_one_auth_job_gen1(ctx, req, job_digest, auth_iv, ofs,
622 : : (uint32_t)data_len);
623 : :
624 : 0 : dp_ctx->tail = tail;
625 : 0 : dp_ctx->cached_enqueue++;
626 : :
627 : : qat_sym_debug_log_dump(req, ctx, data, n_data_vecs, NULL,
628 : : auth_iv, NULL, digest);
629 : :
630 : 0 : return 0;
631 : : }
632 : :
633 : : uint32_t
634 : 0 : qat_sym_dp_enqueue_auth_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
635 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
636 : : void *user_data[], int *status)
637 : : {
638 : : struct qat_qp *qp = qp_data;
639 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
640 : : struct qat_queue *tx_queue = &qp->tx_q;
641 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
642 : : uint32_t i, n;
643 : : uint32_t tail;
644 : : struct icp_qat_fw_la_bulk_req *req;
645 : : int32_t data_len;
646 : : struct rte_crypto_va_iova_ptr null_digest;
647 : : struct rte_crypto_va_iova_ptr *job_digest = NULL;
648 : :
649 : 0 : n = QAT_SYM_DP_GET_MAX_ENQ(qp, dp_ctx->cached_enqueue, vec->num);
650 [ # # ]: 0 : if (unlikely(n == 0)) {
651 : 0 : qat_sym_dp_fill_vec_status(vec->status, -1, vec->num);
652 : 0 : *status = 0;
653 : 0 : return 0;
654 : : }
655 : :
656 : 0 : tail = dp_ctx->tail;
657 : :
658 [ # # ]: 0 : for (i = 0; i < n; i++) {
659 : 0 : struct qat_sym_op_cookie *cookie =
660 : 0 : qp->op_cookies[tail >> tx_queue->trailz];
661 : :
662 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
663 [ # # ]: 0 : (uint8_t *)tx_queue->base_addr + tail);
664 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
665 : :
666 [ # # ]: 0 : if (vec->dest_sgl) {
667 : 0 : data_len = qat_sym_build_req_set_data(req,
668 : 0 : user_data[i], cookie,
669 : 0 : vec->src_sgl[i].vec, vec->src_sgl[i].num,
670 [ # # ]: 0 : vec->dest_sgl[i].vec, vec->dest_sgl[i].num);
671 : : } else {
672 : 0 : data_len = qat_sym_build_req_set_data(req,
673 : 0 : user_data[i], cookie,
674 : : vec->src_sgl[i].vec,
675 [ # # ]: 0 : vec->src_sgl[i].num, NULL, 0);
676 : : }
677 : :
678 [ # # ]: 0 : if (unlikely(data_len < 0))
679 : : break;
680 : :
681 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL) {
682 : 0 : null_digest.iova = cookie->digest_null_phys_addr;
683 : : job_digest = &null_digest;
684 : : } else
685 : 0 : job_digest = &vec->digest[i];
686 : :
687 : 0 : enqueue_one_auth_job_gen1(ctx, req, job_digest,
688 [ # # # # ]: 0 : &vec->auth_iv[i], ofs, (uint32_t)data_len);
689 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
690 : :
691 : : qat_sym_debug_log_dump(req, ctx, vec->src_sgl[i].vec,
692 : : vec->src_sgl[i].num, NULL, &vec->auth_iv[i],
693 : : NULL, &vec->digest[i]);
694 : : }
695 : :
696 [ # # ]: 0 : if (unlikely(i < n))
697 : 0 : qat_sym_dp_fill_vec_status(vec->status + i, -1, n - i);
698 : :
699 : 0 : dp_ctx->tail = tail;
700 : 0 : dp_ctx->cached_enqueue += i;
701 : 0 : *status = 0;
702 : 0 : return i;
703 : : }
704 : :
705 : : int
706 : 0 : qat_sym_dp_enqueue_single_chain_gen1(void *qp_data, uint8_t *drv_ctx,
707 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
708 : : union rte_crypto_sym_ofs ofs,
709 : : struct rte_crypto_va_iova_ptr *cipher_iv,
710 : : struct rte_crypto_va_iova_ptr *digest,
711 : : struct rte_crypto_va_iova_ptr *auth_iv,
712 : : void *user_data)
713 : : {
714 : : struct qat_qp *qp = qp_data;
715 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
716 : : struct qat_queue *tx_queue = &qp->tx_q;
717 : : struct qat_sym_op_cookie *cookie;
718 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
719 : : struct icp_qat_fw_la_bulk_req *req;
720 : : int32_t data_len;
721 : 0 : uint32_t tail = dp_ctx->tail;
722 : : struct rte_crypto_va_iova_ptr null_digest;
723 : : struct rte_crypto_va_iova_ptr *job_digest = digest;
724 : :
725 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
726 : 0 : (uint8_t *)tx_queue->base_addr + tail);
727 : 0 : cookie = qp->op_cookies[tail >> tx_queue->trailz];
728 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
729 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
730 : 0 : rte_prefetch0((uint8_t *)tx_queue->base_addr + tail);
731 [ # # ]: 0 : data_len = qat_sym_build_req_set_data(req, user_data, cookie,
732 : : data, n_data_vecs, NULL, 0);
733 [ # # ]: 0 : if (unlikely(data_len < 0))
734 : : return -1;
735 : :
736 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL) {
737 : 0 : null_digest.iova = cookie->digest_null_phys_addr;
738 : : job_digest = &null_digest;
739 : : }
740 : :
741 [ # # # # ]: 0 : if (unlikely(enqueue_one_chain_job_gen1(ctx, req, data, n_data_vecs,
742 : : NULL, 0, cipher_iv, job_digest, auth_iv, ofs,
743 : : (uint32_t)data_len, cookie)))
744 : : return -1;
745 : :
746 : 0 : dp_ctx->tail = tail;
747 : 0 : dp_ctx->cached_enqueue++;
748 : :
749 : :
750 : : qat_sym_debug_log_dump(req, ctx, data, n_data_vecs, cipher_iv,
751 : : auth_iv, NULL, digest);
752 : :
753 : 0 : return 0;
754 : : }
755 : :
756 : : uint32_t
757 : 0 : qat_sym_dp_enqueue_chain_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
758 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
759 : : void *user_data[], int *status)
760 : : {
761 : : struct qat_qp *qp = qp_data;
762 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
763 : : struct qat_queue *tx_queue = &qp->tx_q;
764 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
765 : : uint32_t i, n;
766 : : uint32_t tail;
767 : : struct icp_qat_fw_la_bulk_req *req;
768 : : int32_t data_len;
769 : : struct rte_crypto_va_iova_ptr null_digest;
770 : : struct rte_crypto_va_iova_ptr *job_digest;
771 : :
772 : 0 : n = QAT_SYM_DP_GET_MAX_ENQ(qp, dp_ctx->cached_enqueue, vec->num);
773 [ # # ]: 0 : if (unlikely(n == 0)) {
774 : 0 : qat_sym_dp_fill_vec_status(vec->status, -1, vec->num);
775 : 0 : *status = 0;
776 : 0 : return 0;
777 : : }
778 : :
779 : 0 : tail = dp_ctx->tail;
780 : :
781 [ # # ]: 0 : for (i = 0; i < n; i++) {
782 : 0 : struct qat_sym_op_cookie *cookie =
783 : 0 : qp->op_cookies[tail >> tx_queue->trailz];
784 : :
785 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
786 [ # # ]: 0 : (uint8_t *)tx_queue->base_addr + tail);
787 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
788 : :
789 [ # # ]: 0 : if (vec->dest_sgl) {
790 : 0 : data_len = qat_sym_build_req_set_data(req,
791 : 0 : user_data[i], cookie,
792 : 0 : vec->src_sgl[i].vec, vec->src_sgl[i].num,
793 [ # # ]: 0 : vec->dest_sgl[i].vec, vec->dest_sgl[i].num);
794 : : } else {
795 : 0 : data_len = qat_sym_build_req_set_data(req,
796 : 0 : user_data[i], cookie,
797 : : vec->src_sgl[i].vec,
798 [ # # ]: 0 : vec->src_sgl[i].num, NULL, 0);
799 : : }
800 : :
801 [ # # ]: 0 : if (unlikely(data_len < 0))
802 : : break;
803 : :
804 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL) {
805 : 0 : null_digest.iova = cookie->digest_null_phys_addr;
806 : : job_digest = &null_digest;
807 : : } else
808 : 0 : job_digest = &vec->digest[i];
809 : :
810 [ # # # # ]: 0 : if (unlikely(enqueue_one_chain_job_gen1(ctx, req,
811 : : vec->src_sgl[i].vec, vec->src_sgl[i].num,
812 : : NULL, 0,
813 : : &vec->iv[i], job_digest,
814 : : &vec->auth_iv[i], ofs, (uint32_t)data_len, cookie)))
815 : : break;
816 : :
817 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
818 : :
819 : : qat_sym_debug_log_dump(req, ctx, vec->src_sgl[i].vec,
820 : : vec->src_sgl[i].num, &vec->iv[i],
821 : : &vec->auth_iv[i],
822 : : NULL, &vec->digest[i]);
823 : : }
824 : :
825 [ # # ]: 0 : if (unlikely(i < n))
826 : 0 : qat_sym_dp_fill_vec_status(vec->status + i, -1, n - i);
827 : :
828 : 0 : dp_ctx->tail = tail;
829 : 0 : dp_ctx->cached_enqueue += i;
830 : 0 : *status = 0;
831 : 0 : return i;
832 : : }
833 : :
834 : : int
835 : 0 : qat_sym_dp_enqueue_single_aead_gen1(void *qp_data, uint8_t *drv_ctx,
836 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
837 : : union rte_crypto_sym_ofs ofs,
838 : : struct rte_crypto_va_iova_ptr *iv,
839 : : struct rte_crypto_va_iova_ptr *digest,
840 : : struct rte_crypto_va_iova_ptr *aad,
841 : : void *user_data)
842 : : {
843 : : struct qat_qp *qp = qp_data;
844 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
845 : : struct qat_queue *tx_queue = &qp->tx_q;
846 : : struct qat_sym_op_cookie *cookie;
847 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
848 : : struct icp_qat_fw_la_bulk_req *req;
849 : :
850 : : int32_t data_len;
851 : 0 : uint32_t tail = dp_ctx->tail;
852 : :
853 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
854 : 0 : (uint8_t *)tx_queue->base_addr + tail);
855 : 0 : cookie = qp->op_cookies[tail >> tx_queue->trailz];
856 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
857 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
858 : 0 : rte_prefetch0((uint8_t *)tx_queue->base_addr + tail);
859 : : data_len = qat_sym_build_req_set_data(req, user_data, cookie,
860 : : data, n_data_vecs, NULL, 0);
861 [ # # ]: 0 : if (unlikely(data_len < 0))
862 : : return -1;
863 : :
864 [ # # # ]: 0 : enqueue_one_aead_job_gen1(ctx, req, iv, digest, aad, ofs,
865 : : (uint32_t)data_len);
866 : :
867 : 0 : dp_ctx->tail = tail;
868 : 0 : dp_ctx->cached_enqueue++;
869 : :
870 : : qat_sym_debug_log_dump(req, ctx, data, n_data_vecs, iv,
871 : : NULL, aad, digest);
872 : :
873 : 0 : return 0;
874 : : }
875 : :
876 : : uint32_t
877 : 0 : qat_sym_dp_enqueue_aead_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
878 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
879 : : void *user_data[], int *status)
880 : : {
881 : : struct qat_qp *qp = qp_data;
882 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
883 : : struct qat_queue *tx_queue = &qp->tx_q;
884 : 0 : struct qat_sym_session *ctx = dp_ctx->session;
885 : : uint32_t i, n;
886 : : uint32_t tail;
887 : : struct icp_qat_fw_la_bulk_req *req;
888 : : int32_t data_len;
889 : :
890 : 0 : n = QAT_SYM_DP_GET_MAX_ENQ(qp, dp_ctx->cached_enqueue, vec->num);
891 [ # # ]: 0 : if (unlikely(n == 0)) {
892 : 0 : qat_sym_dp_fill_vec_status(vec->status, -1, vec->num);
893 : 0 : *status = 0;
894 : 0 : return 0;
895 : : }
896 : :
897 : 0 : tail = dp_ctx->tail;
898 : :
899 [ # # ]: 0 : for (i = 0; i < n; i++) {
900 : 0 : struct qat_sym_op_cookie *cookie =
901 : 0 : qp->op_cookies[tail >> tx_queue->trailz];
902 : :
903 : 0 : req = (struct icp_qat_fw_la_bulk_req *)(
904 [ # # ]: 0 : (uint8_t *)tx_queue->base_addr + tail);
905 : : rte_mov128((uint8_t *)req, (const uint8_t *)&(ctx->fw_req));
906 : :
907 [ # # ]: 0 : if (vec->dest_sgl) {
908 : 0 : data_len = qat_sym_build_req_set_data(req,
909 : 0 : user_data[i], cookie,
910 : 0 : vec->src_sgl[i].vec, vec->src_sgl[i].num,
911 [ # # ]: 0 : vec->dest_sgl[i].vec, vec->dest_sgl[i].num);
912 : : } else {
913 : 0 : data_len = qat_sym_build_req_set_data(req,
914 : 0 : user_data[i], cookie,
915 : : vec->src_sgl[i].vec,
916 [ # # ]: 0 : vec->src_sgl[i].num, NULL, 0);
917 : : }
918 : :
919 [ # # ]: 0 : if (unlikely(data_len < 0))
920 : : break;
921 : :
922 : 0 : enqueue_one_aead_job_gen1(ctx, req, &vec->iv[i],
923 [ # # # ]: 0 : &vec->digest[i], &vec->aad[i], ofs,
924 : : (uint32_t)data_len);
925 : :
926 : 0 : tail = (tail + tx_queue->msg_size) & tx_queue->modulo_mask;
927 : :
928 : : qat_sym_debug_log_dump(req, ctx, vec->src_sgl[i].vec,
929 : : vec->src_sgl[i].num, &vec->iv[i], NULL,
930 : : &vec->aad[i], &vec->digest[i]);
931 : : }
932 : :
933 [ # # ]: 0 : if (unlikely(i < n))
934 : 0 : qat_sym_dp_fill_vec_status(vec->status + i, -1, n - i);
935 : :
936 : 0 : dp_ctx->tail = tail;
937 : 0 : dp_ctx->cached_enqueue += i;
938 : 0 : *status = 0;
939 : 0 : return i;
940 : : }
941 : :
942 : :
943 : : uint32_t
944 : 0 : qat_sym_dp_dequeue_burst_gen1(void *qp_data, uint8_t *drv_ctx,
945 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
946 : : uint32_t max_nb_to_dequeue,
947 : : rte_cryptodev_raw_post_dequeue_t post_dequeue,
948 : : void **out_user_data, uint8_t is_user_data_array,
949 : : uint32_t *n_success_jobs, int *return_status)
950 : : {
951 : : struct qat_qp *qp = qp_data;
952 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
953 : : struct qat_queue *rx_queue = &qp->rx_q;
954 : : struct icp_qat_fw_comn_resp *resp;
955 : : void *resp_opaque;
956 : : uint32_t i, n, inflight;
957 : : uint32_t head;
958 : : uint8_t status;
959 : :
960 : 0 : *n_success_jobs = 0;
961 : 0 : *return_status = 0;
962 : 0 : head = dp_ctx->head;
963 : :
964 : 0 : inflight = qp->enqueued - qp->dequeued;
965 [ # # ]: 0 : if (unlikely(inflight == 0))
966 : : return 0;
967 : :
968 : 0 : resp = (struct icp_qat_fw_comn_resp *)((uint8_t *)rx_queue->base_addr +
969 : : head);
970 : : /* no operation ready */
971 [ # # ]: 0 : if (unlikely(*(uint32_t *)resp == ADF_RING_EMPTY_SIG))
972 : : return 0;
973 : :
974 : 0 : resp_opaque = (void *)(uintptr_t)resp->opaque_data;
975 : : /* get the dequeue count */
976 [ # # ]: 0 : if (get_dequeue_count) {
977 : 0 : n = get_dequeue_count(resp_opaque);
978 [ # # ]: 0 : if (unlikely(n == 0))
979 : : return 0;
980 : : } else {
981 [ # # ]: 0 : if (unlikely(max_nb_to_dequeue == 0))
982 : : return 0;
983 : : n = max_nb_to_dequeue;
984 : : }
985 : :
986 : 0 : out_user_data[0] = resp_opaque;
987 : 0 : status = QAT_SYM_DP_IS_RESP_SUCCESS(resp);
988 : 0 : post_dequeue(resp_opaque, 0, status);
989 : 0 : *n_success_jobs += status;
990 : :
991 : 0 : head = (head + rx_queue->msg_size) & rx_queue->modulo_mask;
992 : :
993 : : /* we already finished dequeue when n == 1 */
994 [ # # ]: 0 : if (unlikely(n == 1)) {
995 : : i = 1;
996 : 0 : goto end_deq;
997 : : }
998 : :
999 [ # # ]: 0 : if (is_user_data_array) {
1000 [ # # ]: 0 : for (i = 1; i < n; i++) {
1001 : 0 : resp = (struct icp_qat_fw_comn_resp *)(
1002 : 0 : (uint8_t *)rx_queue->base_addr + head);
1003 [ # # ]: 0 : if (unlikely(*(uint32_t *)resp ==
1004 : : ADF_RING_EMPTY_SIG))
1005 : 0 : goto end_deq;
1006 : 0 : out_user_data[i] = (void *)(uintptr_t)resp->opaque_data;
1007 : 0 : status = QAT_SYM_DP_IS_RESP_SUCCESS(resp);
1008 : 0 : *n_success_jobs += status;
1009 : 0 : post_dequeue(out_user_data[i], i, status);
1010 : 0 : head = (head + rx_queue->msg_size) &
1011 : 0 : rx_queue->modulo_mask;
1012 : : }
1013 : :
1014 : 0 : goto end_deq;
1015 : : }
1016 : :
1017 : : /* opaque is not array */
1018 [ # # ]: 0 : for (i = 1; i < n; i++) {
1019 : 0 : resp = (struct icp_qat_fw_comn_resp *)(
1020 : 0 : (uint8_t *)rx_queue->base_addr + head);
1021 : 0 : status = QAT_SYM_DP_IS_RESP_SUCCESS(resp);
1022 [ # # ]: 0 : if (unlikely(*(uint32_t *)resp == ADF_RING_EMPTY_SIG))
1023 : 0 : goto end_deq;
1024 : 0 : head = (head + rx_queue->msg_size) &
1025 : 0 : rx_queue->modulo_mask;
1026 : 0 : post_dequeue(resp_opaque, i, status);
1027 : 0 : *n_success_jobs += status;
1028 : : }
1029 : :
1030 : 0 : end_deq:
1031 : 0 : dp_ctx->head = head;
1032 : 0 : dp_ctx->cached_dequeue += i;
1033 : 0 : return i;
1034 : : }
1035 : :
1036 : : void *
1037 : 0 : qat_sym_dp_dequeue_single_gen1(void *qp_data, uint8_t *drv_ctx,
1038 : : int *dequeue_status, enum rte_crypto_op_status *op_status)
1039 : : {
1040 : : struct qat_qp *qp = qp_data;
1041 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
1042 : : struct qat_queue *rx_queue = &qp->rx_q;
1043 : : register struct icp_qat_fw_comn_resp *resp;
1044 : :
1045 : 0 : resp = (struct icp_qat_fw_comn_resp *)((uint8_t *)rx_queue->base_addr +
1046 : 0 : dp_ctx->head);
1047 : :
1048 [ # # ]: 0 : if (unlikely(*(uint32_t *)resp == ADF_RING_EMPTY_SIG))
1049 : : return NULL;
1050 : :
1051 : 0 : dp_ctx->head = (dp_ctx->head + rx_queue->msg_size) &
1052 : 0 : rx_queue->modulo_mask;
1053 : 0 : dp_ctx->cached_dequeue++;
1054 : :
1055 : 0 : *op_status = QAT_SYM_DP_IS_RESP_SUCCESS(resp) ?
1056 [ # # ]: 0 : RTE_CRYPTO_OP_STATUS_SUCCESS :
1057 : : RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1058 : 0 : *dequeue_status = 0;
1059 : 0 : return (void *)(uintptr_t)resp->opaque_data;
1060 : : }
1061 : :
1062 : : int
1063 : 0 : qat_sym_dp_enqueue_done_gen1(void *qp_data, uint8_t *drv_ctx, uint32_t n)
1064 : : {
1065 : : struct qat_qp *qp = qp_data;
1066 : : struct qat_queue *tx_queue = &qp->tx_q;
1067 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
1068 : :
1069 [ # # ]: 0 : if (unlikely(dp_ctx->cached_enqueue != n))
1070 : : return -1;
1071 : :
1072 : 0 : qp->enqueued += n;
1073 : 0 : qp->stats.enqueued_count += n;
1074 : :
1075 : 0 : tx_queue->tail = dp_ctx->tail;
1076 : :
1077 : 0 : WRITE_CSR_RING_TAIL(qp->mmap_bar_addr,
1078 : : tx_queue->hw_bundle_number,
1079 : : tx_queue->hw_queue_number, tx_queue->tail);
1080 : 0 : tx_queue->csr_tail = tx_queue->tail;
1081 : 0 : dp_ctx->cached_enqueue = 0;
1082 : :
1083 : 0 : return 0;
1084 : : }
1085 : :
1086 : : int
1087 : 0 : qat_sym_dp_dequeue_done_gen1(void *qp_data, uint8_t *drv_ctx, uint32_t n)
1088 : : {
1089 : : struct qat_qp *qp = qp_data;
1090 : : struct qat_queue *rx_queue = &qp->rx_q;
1091 : : struct qat_sym_dp_ctx *dp_ctx = (void *)drv_ctx;
1092 : :
1093 [ # # ]: 0 : if (unlikely(dp_ctx->cached_dequeue != n))
1094 : : return -1;
1095 : :
1096 : 0 : rx_queue->head = dp_ctx->head;
1097 : 0 : rx_queue->nb_processed_responses += n;
1098 : 0 : qp->dequeued += n;
1099 : 0 : qp->stats.dequeued_count += n;
1100 [ # # ]: 0 : if (rx_queue->nb_processed_responses > QAT_CSR_HEAD_WRITE_THRESH) {
1101 : : uint32_t old_head, new_head;
1102 : : uint32_t max_head;
1103 : :
1104 : 0 : old_head = rx_queue->csr_head;
1105 : : new_head = rx_queue->head;
1106 : 0 : max_head = qp->nb_descriptors * rx_queue->msg_size;
1107 : :
1108 : : /* write out free descriptors */
1109 : 0 : void *cur_desc = (uint8_t *)rx_queue->base_addr + old_head;
1110 : :
1111 [ # # ]: 0 : if (new_head < old_head) {
1112 : 0 : memset(cur_desc, ADF_RING_EMPTY_SIG_BYTE,
1113 : 0 : max_head - old_head);
1114 : 0 : memset(rx_queue->base_addr, ADF_RING_EMPTY_SIG_BYTE,
1115 : : new_head);
1116 : : } else {
1117 : 0 : memset(cur_desc, ADF_RING_EMPTY_SIG_BYTE, new_head -
1118 : : old_head);
1119 : : }
1120 : 0 : rx_queue->nb_processed_responses = 0;
1121 : 0 : rx_queue->csr_head = new_head;
1122 : :
1123 : : /* write current head to CSR */
1124 : 0 : WRITE_CSR_RING_HEAD(qp->mmap_bar_addr,
1125 : : rx_queue->hw_bundle_number, rx_queue->hw_queue_number,
1126 : : new_head);
1127 : : }
1128 : :
1129 : 0 : dp_ctx->cached_dequeue = 0;
1130 : 0 : return 0;
1131 : : }
1132 : :
1133 : : int
1134 : 0 : qat_sym_configure_raw_dp_ctx_gen1(void *_raw_dp_ctx, void *_ctx)
1135 : : {
1136 : : struct rte_crypto_raw_dp_ctx *raw_dp_ctx = _raw_dp_ctx;
1137 : : struct qat_sym_session *ctx = _ctx;
1138 : :
1139 : 0 : raw_dp_ctx->enqueue_done = qat_sym_dp_enqueue_done_gen1;
1140 : 0 : raw_dp_ctx->dequeue_burst = qat_sym_dp_dequeue_burst_gen1;
1141 : 0 : raw_dp_ctx->dequeue = qat_sym_dp_dequeue_single_gen1;
1142 : 0 : raw_dp_ctx->dequeue_done = qat_sym_dp_dequeue_done_gen1;
1143 : :
1144 [ # # ]: 0 : if ((ctx->qat_cmd == ICP_QAT_FW_LA_CMD_HASH_CIPHER ||
1145 : 0 : ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_HASH) &&
1146 [ # # ]: 0 : !ctx->is_gmac) {
1147 : : /* AES-GCM or AES-CCM */
1148 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
1149 : 0 : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64 ||
1150 [ # # ]: 0 : (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128
1151 [ # # ]: 0 : && ctx->qat_mode == ICP_QAT_HW_CIPHER_CTR_MODE
1152 [ # # ]: 0 : && ctx->qat_hash_alg ==
1153 : : ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC)) {
1154 : 0 : raw_dp_ctx->enqueue_burst =
1155 : : qat_sym_dp_enqueue_aead_jobs_gen1;
1156 : 0 : raw_dp_ctx->enqueue =
1157 : : qat_sym_dp_enqueue_single_aead_gen1;
1158 : : } else {
1159 : 0 : raw_dp_ctx->enqueue_burst =
1160 : : qat_sym_dp_enqueue_chain_jobs_gen1;
1161 : 0 : raw_dp_ctx->enqueue =
1162 : : qat_sym_dp_enqueue_single_chain_gen1;
1163 : : }
1164 [ # # # # ]: 0 : } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_AUTH || ctx->is_gmac) {
1165 : 0 : raw_dp_ctx->enqueue_burst = qat_sym_dp_enqueue_auth_jobs_gen1;
1166 : 0 : raw_dp_ctx->enqueue = qat_sym_dp_enqueue_single_auth_gen1;
1167 [ # # ]: 0 : } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER) {
1168 [ # # ]: 0 : if (ctx->qat_mode == ICP_QAT_HW_CIPHER_AEAD_MODE ||
1169 [ # # ]: 0 : ctx->qat_cipher_alg ==
1170 : : ICP_QAT_HW_CIPHER_ALGO_CHACHA20_POLY1305) {
1171 : 0 : raw_dp_ctx->enqueue_burst =
1172 : : qat_sym_dp_enqueue_aead_jobs_gen1;
1173 : 0 : raw_dp_ctx->enqueue =
1174 : : qat_sym_dp_enqueue_single_aead_gen1;
1175 : : } else {
1176 : 0 : raw_dp_ctx->enqueue_burst =
1177 : : qat_sym_dp_enqueue_cipher_jobs_gen1;
1178 : 0 : raw_dp_ctx->enqueue =
1179 : : qat_sym_dp_enqueue_single_cipher_gen1;
1180 : : }
1181 : : } else
1182 : : return -1;
1183 : :
1184 : : return 0;
1185 : : }
1186 : :
1187 : : int
1188 : 0 : qat_sym_crypto_set_session_gen1(void *cryptodev __rte_unused, void *session)
1189 : : {
1190 : : struct qat_sym_session *ctx = session;
1191 : : qat_sym_build_request_t build_request = NULL;
1192 : 0 : enum rte_proc_type_t proc_type = rte_eal_process_type();
1193 : : int handle_mixed = 0;
1194 : :
1195 [ # # ]: 0 : if (proc_type == RTE_PROC_AUTO || proc_type == RTE_PROC_INVALID)
1196 : : return -EINVAL;
1197 : :
1198 [ # # ]: 0 : if ((ctx->qat_cmd == ICP_QAT_FW_LA_CMD_HASH_CIPHER ||
1199 : 0 : ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_HASH) &&
1200 [ # # ]: 0 : !ctx->is_gmac) {
1201 : : /* AES-GCM or AES-CCM */
1202 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
1203 : 0 : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64 ||
1204 [ # # ]: 0 : (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128
1205 [ # # ]: 0 : && ctx->qat_mode == ICP_QAT_HW_CIPHER_CTR_MODE
1206 [ # # ]: 0 : && ctx->qat_hash_alg ==
1207 : : ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC)) {
1208 : : /* do_aead = 1; */
1209 : : build_request = qat_sym_build_op_aead_gen1;
1210 : : } else {
1211 : : /* do_auth = 1; do_cipher = 1; */
1212 : : build_request = qat_sym_build_op_chain_gen1;
1213 : : handle_mixed = 1;
1214 : : }
1215 [ # # # # ]: 0 : } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_AUTH || ctx->is_gmac) {
1216 : : /* do_auth = 1; do_cipher = 0;*/
1217 : : build_request = qat_sym_build_op_auth_gen1;
1218 [ # # ]: 0 : } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER) {
1219 : : /* do_auth = 0; do_cipher = 1; */
1220 : : build_request = qat_sym_build_op_cipher_gen1;
1221 [ # # ]: 0 : } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_CRC) {
1222 : : /* do_auth = 1; do_cipher = 1; */
1223 : : build_request = qat_sym_build_op_chain_gen1;
1224 : : handle_mixed = 1;
1225 : : }
1226 : :
1227 : : if (build_request)
1228 : 0 : ctx->build_request[proc_type] = build_request;
1229 : : else
1230 : : return -EINVAL;
1231 : :
1232 : : /* no more work if not mixed op */
1233 [ # # ]: 0 : if (!handle_mixed)
1234 : : return 0;
1235 : :
1236 : : /* Check none supported algs if mixed */
1237 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3 &&
1238 [ # # ]: 0 : ctx->qat_cipher_alg !=
1239 : : ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3) {
1240 : : return -ENOTSUP;
1241 [ # # ]: 0 : } else if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 &&
1242 [ # # ]: 0 : ctx->qat_cipher_alg !=
1243 : : ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2) {
1244 : : return -ENOTSUP;
1245 [ # # # # ]: 0 : } else if ((ctx->aes_cmac ||
1246 : 0 : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL) &&
1247 : 0 : (ctx->qat_cipher_alg ==
1248 [ # # ]: 0 : ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ||
1249 : : ctx->qat_cipher_alg ==
1250 : : ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3)) {
1251 : 0 : return -ENOTSUP;
1252 : : }
1253 : :
1254 : : return 0;
1255 : : }
1256 : :
1257 : 235 : RTE_INIT(qat_sym_crypto_gen1_init)
1258 : : {
1259 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].cryptodev_ops = &qat_sym_crypto_ops_gen1;
1260 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].get_capabilities =
1261 : : qat_sym_crypto_cap_get_gen1;
1262 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].set_session =
1263 : : qat_sym_crypto_set_session_gen1;
1264 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].set_raw_dp_ctx =
1265 : : qat_sym_configure_raw_dp_ctx_gen1;
1266 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].get_feature_flags =
1267 : : qat_sym_crypto_feature_flags_get_gen1;
1268 : 235 : qat_sym_gen_dev_ops[QAT_GEN1].create_security_ctx =
1269 : : qat_sym_create_security_gen1;
1270 : 235 : }
|