Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Cavium, Inc
3 : : */
4 : :
5 : : #include <rte_alarm.h>
6 : : #include <bus_pci_driver.h>
7 : : #include <rte_cryptodev.h>
8 : : #include <cryptodev_pmd.h>
9 : : #include <rte_eventdev.h>
10 : : #include <rte_event_crypto_adapter.h>
11 : : #include <rte_errno.h>
12 : : #include <rte_malloc.h>
13 : : #include <rte_mempool.h>
14 : :
15 : : #include "otx_cryptodev.h"
16 : : #include "otx_cryptodev_capabilities.h"
17 : : #include "otx_cryptodev_hw_access.h"
18 : : #include "otx_cryptodev_mbox.h"
19 : : #include "otx_cryptodev_ops.h"
20 : :
21 : : #include "cpt_pmd_logs.h"
22 : : #include "cpt_pmd_ops_helper.h"
23 : : #include "cpt_ucode.h"
24 : : #include "cpt_ucode_asym.h"
25 : :
26 : : #include "ssovf_worker.h"
27 : :
28 : : static uint64_t otx_fpm_iova[CPT_EC_ID_PMAX];
29 : :
30 : : /* Forward declarations */
31 : :
32 : : static int
33 : : otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id);
34 : :
35 : : /* Alarm routines */
36 : :
37 : : static void
38 : 0 : otx_cpt_alarm_cb(void *arg)
39 : : {
40 : : struct cpt_vf *cptvf = arg;
41 : 0 : otx_cpt_poll_misc(cptvf);
42 : 0 : rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
43 : : otx_cpt_alarm_cb, cptvf);
44 : 0 : }
45 : :
46 : : static int
47 : : otx_cpt_periodic_alarm_start(void *arg)
48 : : {
49 : 0 : return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
50 : : otx_cpt_alarm_cb, arg);
51 : : }
52 : :
53 : : static int
54 : : otx_cpt_periodic_alarm_stop(void *arg)
55 : : {
56 : 0 : return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg);
57 : : }
58 : :
59 : : /* PMD ops */
60 : :
61 : : static int
62 : 0 : otx_cpt_dev_config(struct rte_cryptodev *dev,
63 : : struct rte_cryptodev_config *config __rte_unused)
64 : : {
65 : : int ret = 0;
66 : :
67 : 0 : CPT_PMD_INIT_FUNC_TRACE();
68 : :
69 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
70 : : /* Initialize shared FPM table */
71 : 0 : ret = cpt_fpm_init(otx_fpm_iova);
72 : :
73 : 0 : return ret;
74 : : }
75 : :
76 : : static int
77 : 0 : otx_cpt_dev_start(struct rte_cryptodev *c_dev)
78 : : {
79 : 0 : void *cptvf = c_dev->data->dev_private;
80 : :
81 : 0 : CPT_PMD_INIT_FUNC_TRACE();
82 : :
83 : 0 : return otx_cpt_start_device(cptvf);
84 : : }
85 : :
86 : : static void
87 : 0 : otx_cpt_dev_stop(struct rte_cryptodev *c_dev)
88 : : {
89 : 0 : void *cptvf = c_dev->data->dev_private;
90 : :
91 : 0 : CPT_PMD_INIT_FUNC_TRACE();
92 : :
93 [ # # ]: 0 : if (c_dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
94 : 0 : cpt_fpm_clear();
95 : :
96 : 0 : otx_cpt_stop_device(cptvf);
97 : 0 : }
98 : :
99 : : static int
100 : 0 : otx_cpt_dev_close(struct rte_cryptodev *c_dev)
101 : : {
102 : 0 : void *cptvf = c_dev->data->dev_private;
103 : : int i, ret;
104 : :
105 : 0 : CPT_PMD_INIT_FUNC_TRACE();
106 : :
107 [ # # ]: 0 : for (i = 0; i < c_dev->data->nb_queue_pairs; i++) {
108 : 0 : ret = otx_cpt_que_pair_release(c_dev, i);
109 [ # # ]: 0 : if (ret)
110 : 0 : return ret;
111 : : }
112 : :
113 : : otx_cpt_periodic_alarm_stop(cptvf);
114 : 0 : otx_cpt_deinit_device(cptvf);
115 : :
116 : 0 : return 0;
117 : : }
118 : :
119 : : static void
120 : 0 : otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
121 : : {
122 : 0 : CPT_PMD_INIT_FUNC_TRACE();
123 [ # # ]: 0 : if (info != NULL) {
124 : 0 : info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF;
125 : 0 : info->feature_flags = dev->feature_flags;
126 : 0 : info->capabilities = otx_get_capabilities(info->feature_flags);
127 : 0 : info->sym.max_nb_sessions = 0;
128 : 0 : info->driver_id = otx_cryptodev_driver_id;
129 : 0 : info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ;
130 : 0 : info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ;
131 : : }
132 : 0 : }
133 : :
134 : : static int
135 : 0 : otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
136 : : uint16_t que_pair_id,
137 : : const struct rte_cryptodev_qp_conf *qp_conf,
138 : : int socket_id __rte_unused)
139 : : {
140 : 0 : struct cpt_instance *instance = NULL;
141 : : struct rte_pci_device *pci_dev;
142 : : int ret = -1;
143 : :
144 : 0 : CPT_PMD_INIT_FUNC_TRACE();
145 : :
146 [ # # ]: 0 : if (dev->data->queue_pairs[que_pair_id] != NULL) {
147 : 0 : ret = otx_cpt_que_pair_release(dev, que_pair_id);
148 [ # # ]: 0 : if (ret)
149 : : return ret;
150 : : }
151 : :
152 [ # # ]: 0 : if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) {
153 : 0 : CPT_LOG_INFO("Number of descriptors too big %d, using default "
154 : : "queue length of %d", qp_conf->nb_descriptors,
155 : : DEFAULT_CMD_QLEN);
156 : : }
157 : :
158 : 0 : pci_dev = RTE_DEV_TO_PCI(dev->device);
159 : :
160 [ # # ]: 0 : if (pci_dev->mem_resource[0].addr == NULL) {
161 : 0 : CPT_LOG_ERR("PCI mem address null");
162 : 0 : return -EIO;
163 : : }
164 : :
165 : 0 : ret = otx_cpt_get_resource(dev, 0, &instance, que_pair_id);
166 [ # # # # ]: 0 : if (ret != 0 || instance == NULL) {
167 : 0 : CPT_LOG_ERR("Error getting instance handle from device %s : "
168 : : "ret = %d", dev->data->name, ret);
169 : 0 : return ret;
170 : : }
171 : :
172 : 0 : instance->queue_id = que_pair_id;
173 : 0 : instance->sess_mp = qp_conf->mp_session;
174 : 0 : dev->data->queue_pairs[que_pair_id] = instance;
175 : :
176 : 0 : return 0;
177 : : }
178 : :
179 : : static int
180 : 0 : otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id)
181 : : {
182 : 0 : struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id];
183 : : int ret;
184 : :
185 : 0 : CPT_PMD_INIT_FUNC_TRACE();
186 : :
187 : 0 : ret = otx_cpt_put_resource(instance);
188 [ # # ]: 0 : if (ret != 0) {
189 : 0 : CPT_LOG_ERR("Error putting instance handle of device %s : "
190 : : "ret = %d", dev->data->name, ret);
191 : 0 : return ret;
192 : : }
193 : :
194 : 0 : dev->data->queue_pairs[que_pair_id] = NULL;
195 : :
196 : 0 : return 0;
197 : : }
198 : :
199 : : static unsigned int
200 : 0 : otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused)
201 : : {
202 : 0 : return cpt_get_session_size();
203 : : }
204 : :
205 : : static int
206 : 0 : sym_xform_verify(struct rte_crypto_sym_xform *xform)
207 : : {
208 [ # # ]: 0 : if (xform->next) {
209 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
210 [ # # ]: 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
211 [ # # ]: 0 : xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
212 [ # # ]: 0 : (xform->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC ||
213 [ # # ]: 0 : xform->next->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC))
214 : : return -ENOTSUP;
215 : :
216 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
217 [ # # ]: 0 : xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
218 [ # # ]: 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
219 [ # # ]: 0 : (xform->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC ||
220 [ # # ]: 0 : xform->next->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC))
221 : : return -ENOTSUP;
222 : :
223 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
224 [ # # ]: 0 : xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
225 [ # # ]: 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
226 [ # # ]: 0 : xform->next->auth.algo == RTE_CRYPTO_AUTH_SHA1)
227 : : return -ENOTSUP;
228 : :
229 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
230 [ # # ]: 0 : xform->auth.algo == RTE_CRYPTO_AUTH_SHA1 &&
231 [ # # ]: 0 : xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
232 [ # # ]: 0 : xform->next->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC)
233 : 0 : return -ENOTSUP;
234 : :
235 : : } else {
236 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
237 [ # # ]: 0 : xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
238 : : xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
239 : 0 : return -ENOTSUP;
240 : : }
241 : : return 0;
242 : : }
243 : :
244 : : static int
245 : 0 : sym_session_configure(struct rte_crypto_sym_xform *xform,
246 : : struct rte_cryptodev_sym_session *sess)
247 : : {
248 : : struct rte_crypto_sym_xform *temp_xform = xform;
249 : : struct cpt_sess_misc *misc;
250 : : vq_cmd_word3_t vq_cmd_w3;
251 : 0 : void *priv = CRYPTODEV_GET_SYM_SESS_PRIV(sess);
252 : : int ret;
253 : :
254 : 0 : ret = sym_xform_verify(xform);
255 [ # # ]: 0 : if (unlikely(ret))
256 : : return ret;
257 : :
258 : : memset(priv, 0, sizeof(struct cpt_sess_misc) +
259 : : offsetof(struct cpt_ctx, mc_ctx));
260 : :
261 : : misc = priv;
262 : :
263 [ # # ]: 0 : for ( ; xform != NULL; xform = xform->next) {
264 [ # # # # ]: 0 : switch (xform->type) {
265 : : case RTE_CRYPTO_SYM_XFORM_AEAD:
266 : : ret = fill_sess_aead(xform, misc);
267 : : break;
268 : : case RTE_CRYPTO_SYM_XFORM_CIPHER:
269 : : ret = fill_sess_cipher(xform, misc);
270 : : break;
271 : 0 : case RTE_CRYPTO_SYM_XFORM_AUTH:
272 [ # # ]: 0 : if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC)
273 : : ret = fill_sess_gmac(xform, misc);
274 : : else
275 : : ret = fill_sess_auth(xform, misc);
276 : : break;
277 : : default:
278 : : ret = -1;
279 : : }
280 : :
281 : : if (ret)
282 : 0 : goto priv_put;
283 : : }
284 : :
285 [ # # ]: 0 : if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) &&
286 : : cpt_mac_len_verify(&temp_xform->auth)) {
287 : 0 : CPT_LOG_ERR("MAC length is not supported");
288 : : struct cpt_ctx *ctx = SESS_PRIV(misc);
289 [ # # ]: 0 : if (ctx->auth_key != NULL) {
290 : 0 : rte_free(ctx->auth_key);
291 : 0 : ctx->auth_key = NULL;
292 : : }
293 : : ret = -ENOTSUP;
294 : 0 : goto priv_put;
295 : : }
296 : :
297 : 0 : misc->ctx_dma_addr = CRYPTODEV_GET_SYM_SESS_PRIV_IOVA(sess) +
298 : : sizeof(struct cpt_sess_misc);
299 : :
300 : 0 : vq_cmd_w3.u64 = 0;
301 : : vq_cmd_w3.s.grp = 0;
302 : 0 : vq_cmd_w3.s.cptr = misc->ctx_dma_addr + offsetof(struct cpt_ctx,
303 : : mc_ctx);
304 : :
305 : 0 : misc->cpt_inst_w7 = vq_cmd_w3.u64;
306 : :
307 : 0 : return 0;
308 : :
309 : : priv_put:
310 : : return -ENOTSUP;
311 : : }
312 : :
313 : : static void
314 : : sym_session_clear(struct rte_cryptodev_sym_session *sess)
315 : : {
316 : : void *priv = CRYPTODEV_GET_SYM_SESS_PRIV(sess);
317 : : struct cpt_sess_misc *misc;
318 : : struct cpt_ctx *ctx;
319 : :
320 : : if (priv == NULL)
321 : : return;
322 : :
323 : : misc = priv;
324 : : ctx = SESS_PRIV(misc);
325 : :
326 : 0 : rte_free(ctx->auth_key);
327 : : }
328 : :
329 : : static int
330 : 0 : otx_cpt_session_cfg(struct rte_cryptodev *dev __rte_unused,
331 : : struct rte_crypto_sym_xform *xform,
332 : : struct rte_cryptodev_sym_session *sess)
333 : : {
334 : 0 : CPT_PMD_INIT_FUNC_TRACE();
335 : :
336 : 0 : return sym_session_configure(xform, sess);
337 : : }
338 : :
339 : :
340 : : static void
341 : 0 : otx_cpt_session_clear(struct rte_cryptodev *dev __rte_unused,
342 : : struct rte_cryptodev_sym_session *sess)
343 : : {
344 : 0 : CPT_PMD_INIT_FUNC_TRACE();
345 : :
346 : 0 : return sym_session_clear(sess);
347 : : }
348 : :
349 : : static unsigned int
350 : 0 : otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
351 : : {
352 : 0 : return sizeof(struct cpt_asym_sess_misc);
353 : : }
354 : :
355 : : static int
356 : 0 : otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
357 : : struct rte_crypto_asym_xform *xform __rte_unused,
358 : : struct rte_cryptodev_asym_session *sess)
359 : : {
360 : : struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
361 : : sess->sess_private_data;
362 : : int ret;
363 : :
364 : 0 : CPT_PMD_INIT_FUNC_TRACE();
365 : :
366 : : ret = cpt_fill_asym_session_parameters(priv, xform);
367 : : if (ret) {
368 : 0 : CPT_LOG_ERR("Could not configure session parameters");
369 : 0 : return ret;
370 : : }
371 : :
372 : 0 : priv->cpt_inst_w7 = 0;
373 : :
374 : 0 : return 0;
375 : : }
376 : :
377 : : static void
378 : 0 : otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
379 : : struct rte_cryptodev_asym_session *sess)
380 : : {
381 : : struct cpt_asym_sess_misc *priv;
382 : :
383 : 0 : CPT_PMD_INIT_FUNC_TRACE();
384 : :
385 [ # # # # ]: 0 : priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
386 : :
387 : : if (priv == NULL)
388 : : return;
389 : :
390 : : /* Free resources allocated during session configure */
391 : : cpt_free_asym_session_parameters(priv);
392 : : memset(priv, 0, otx_cpt_asym_session_size_get(dev));
393 : : }
394 : :
395 : : static __rte_always_inline void * __rte_hot
396 : : otx_cpt_request_enqueue(struct cpt_instance *instance,
397 : : void *req, uint64_t cpt_inst_w7)
398 : : {
399 : : struct cpt_request_info *user_req = (struct cpt_request_info *)req;
400 : :
401 : : fill_cpt_inst(instance, req, cpt_inst_w7);
402 : :
403 : : CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op);
404 : :
405 : : /* Fill time_out cycles */
406 : 0 : user_req->time_out = rte_get_timer_cycles() +
407 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
408 [ # # # # : 0 : user_req->extra_time = 0;
# # # # #
# # # ]
409 : :
410 : : /* Default mode of software queue */
411 : : mark_cpt_inst(instance);
412 : :
413 : : CPT_LOG_DP_DEBUG("Submitted NB cmd with request: %p "
414 : : "op: %p", user_req, user_req->op);
415 : : return req;
416 : : }
417 : :
418 : : static __rte_always_inline void * __rte_hot
419 : : otx_cpt_enq_single_asym(struct cpt_instance *instance,
420 : : struct rte_crypto_op *op)
421 : : {
422 : : struct cpt_qp_meta_info *minfo = &instance->meta_info;
423 : : struct rte_crypto_asym_op *asym_op = op->asym;
424 : : struct asym_op_params params = {0};
425 : : struct cpt_asym_sess_misc *sess;
426 : : uintptr_t *cop;
427 : : void *mdata;
428 : : void *req;
429 : : int ret;
430 : :
431 [ # # # # : 0 : if (unlikely(rte_mempool_get(minfo->pool, &mdata) < 0)) {
# # # # ]
432 : 0 : CPT_LOG_DP_ERR("Could not allocate meta buffer for request");
433 : 0 : rte_errno = ENOMEM;
434 : 0 : return NULL;
435 : : }
436 : :
437 : : sess = (struct cpt_asym_sess_misc *)
438 : 0 : asym_op->session->sess_private_data;
439 : :
440 : : /* Store phys_addr of the mdata to meta_buf */
441 : 0 : params.meta_buf = rte_mempool_virt2iova(mdata);
442 : :
443 : : cop = mdata;
444 : 0 : cop[0] = (uintptr_t)mdata;
445 : 0 : cop[1] = (uintptr_t)op;
446 : 0 : cop[2] = cop[3] = 0ULL;
447 : :
448 : 0 : params.req = RTE_PTR_ADD(cop, 4 * sizeof(uintptr_t));
449 : 0 : params.req->op = cop;
450 : :
451 : : /* Adjust meta_buf by crypto_op data and request_info struct */
452 : 0 : params.meta_buf += (4 * sizeof(uintptr_t)) +
453 : : sizeof(struct cpt_request_info);
454 : :
455 [ # # # # : 0 : switch (sess->xfrm_type) {
# # # # #
# ]
456 [ # # # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
457 : : ret = cpt_modex_prep(¶ms, &sess->mod_ctx);
458 [ # # # # ]: 0 : if (unlikely(ret))
459 : 0 : goto req_fail;
460 : : break;
461 : : case RTE_CRYPTO_ASYM_XFORM_RSA:
462 : : ret = cpt_enqueue_rsa_op(op, ¶ms, sess);
463 [ # # # # ]: 0 : if (unlikely(ret))
464 : 0 : goto req_fail;
465 : : break;
466 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
467 : : ret = cpt_enqueue_ecdsa_op(op, ¶ms, sess, otx_fpm_iova);
468 [ # # # # ]: 0 : if (unlikely(ret))
469 : 0 : goto req_fail;
470 : : break;
471 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
472 : 0 : ret = cpt_ecpm_prep(&asym_op->ecpm, ¶ms,
473 : 0 : sess->ec_ctx.curveid);
474 : : if (unlikely(ret))
475 : : goto req_fail;
476 : : break;
477 : :
478 : 0 : default:
479 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
480 : 0 : rte_errno = EINVAL;
481 : 0 : goto req_fail;
482 : : }
483 : :
484 : 0 : req = otx_cpt_request_enqueue(instance, params.req, sess->cpt_inst_w7);
485 : : if (unlikely(req == NULL)) {
486 : : CPT_LOG_DP_ERR("Could not enqueue crypto req");
487 : : goto req_fail;
488 : : }
489 : :
490 : : return req;
491 : :
492 : 0 : req_fail:
493 [ # # # # ]: 0 : free_op_meta(mdata, minfo->pool);
494 : :
495 : : return NULL;
496 : : }
497 : :
498 : : static __rte_always_inline void * __rte_hot
499 : : otx_cpt_enq_single_sym(struct cpt_instance *instance,
500 : : struct rte_crypto_op *op)
501 : : {
502 : : struct cpt_sess_misc *sess;
503 : : struct rte_crypto_sym_op *sym_op = op->sym;
504 : : struct cpt_request_info *prep_req;
505 : : void *mdata = NULL;
506 : : int ret = 0;
507 : : void *req;
508 : : uint64_t cpt_op;
509 : :
510 : 0 : sess = CRYPTODEV_GET_SYM_SESS_PRIV(sym_op->session);
511 : 0 : cpt_op = sess->cpt_op;
512 : :
513 [ # # # # ]: 0 : if (likely(cpt_op & CPT_OP_CIPHER_MASK))
514 : : ret = fill_fc_params(op, sess, &instance->meta_info, &mdata,
515 : : (void **)&prep_req);
516 : : else
517 : : ret = fill_digest_params(op, sess, &instance->meta_info,
518 : : &mdata, (void **)&prep_req);
519 : :
520 [ # # # # : 0 : if (unlikely(ret)) {
# # # # ]
521 : 0 : CPT_LOG_DP_ERR("prep crypto req : op %p, cpt_op 0x%x "
522 : : "ret 0x%x", op, (unsigned int)cpt_op, ret);
523 : 0 : return NULL;
524 : : }
525 : :
526 : : /* Enqueue prepared instruction to h/w */
527 : 0 : req = otx_cpt_request_enqueue(instance, prep_req, sess->cpt_inst_w7);
528 : : if (unlikely(req == NULL))
529 : : /* Buffer allocated for request preparation need to be freed */
530 : : free_op_meta(mdata, instance->meta_info.pool);
531 : :
532 : : return req;
533 : : }
534 : :
535 : : static __rte_always_inline void * __rte_hot
536 : : otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
537 : : struct rte_crypto_op *op)
538 : : {
539 : : struct rte_crypto_sym_op *sym_op = op->sym;
540 : : struct rte_cryptodev_sym_session *sess;
541 : : void *req;
542 : : int ret;
543 : :
544 : : /* Create temporary session */
545 [ # # # # : 0 : if (rte_mempool_get(instance->sess_mp, (void **)&sess) < 0) {
# # # # ]
546 : 0 : rte_errno = ENOMEM;
547 : 0 : return NULL;
548 : : }
549 : :
550 : 0 : ret = sym_session_configure(sym_op->xform, sess);
551 [ # # # # ]: 0 : if (ret)
552 : 0 : goto sess_put;
553 : :
554 [ # # # # ]: 0 : sym_op->session = sess;
555 : :
556 : : /* Enqueue op with the tmp session set */
557 : : req = otx_cpt_enq_single_sym(instance, op);
558 [ # # # # ]: 0 : if (unlikely(req == NULL))
559 : 0 : goto sess_put;
560 : :
561 : : return req;
562 : :
563 : 0 : sess_put:
564 [ # # # # ]: 0 : rte_mempool_put(instance->sess_mp, sess);
565 : 0 : return NULL;
566 : : }
567 : :
568 : : #define OP_TYPE_SYM 0
569 : : #define OP_TYPE_ASYM 1
570 : :
571 : : static __rte_always_inline void *__rte_hot
572 : : otx_cpt_enq_single(struct cpt_instance *inst,
573 : : struct rte_crypto_op *op,
574 : : const uint8_t op_type)
575 : : {
576 : : /* Check for the type */
577 : :
578 : 0 : if (op_type == OP_TYPE_SYM) {
579 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
580 : : return otx_cpt_enq_single_sym(inst, op);
581 : : else
582 : 0 : return otx_cpt_enq_single_sym_sessless(inst, op);
583 : : }
584 : :
585 : : if (op_type == OP_TYPE_ASYM) {
586 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
587 : 0 : return otx_cpt_enq_single_asym(inst, op);
588 : : }
589 : :
590 : : /* Should not reach here */
591 : 0 : rte_errno = ENOTSUP;
592 : 0 : return NULL;
593 : : }
594 : :
595 : : static __rte_always_inline uint16_t __rte_hot
596 : : otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
597 : : const uint8_t op_type)
598 : : {
599 : : struct cpt_instance *instance = (struct cpt_instance *)qptr;
600 : : uint16_t count, free_slots;
601 : : void *req;
602 : : struct cpt_vf *cptvf = (struct cpt_vf *)instance;
603 : : struct pending_queue *pqueue = &cptvf->pqueue;
604 : :
605 : 0 : free_slots = pending_queue_free_slots(pqueue, DEFAULT_CMD_QLEN,
606 : : DEFAULT_CMD_QRSVD_SLOTS);
607 : : if (nb_ops > free_slots)
608 : : nb_ops = free_slots;
609 : :
610 : : count = 0;
611 [ # # # # ]: 0 : while (likely(count < nb_ops)) {
612 : :
613 : : /* Enqueue single op */
614 [ # # # # ]: 0 : req = otx_cpt_enq_single(instance, ops[count], op_type);
615 : :
616 [ # # # # ]: 0 : if (unlikely(req == NULL))
617 : : break;
618 : :
619 : 0 : pending_queue_push(pqueue, req, count, DEFAULT_CMD_QLEN);
620 : 0 : count++;
621 : : }
622 : :
623 [ # # # # ]: 0 : if (likely(count)) {
624 : 0 : pending_queue_commit(pqueue, count, DEFAULT_CMD_QLEN);
625 : : otx_cpt_ring_dbell(instance, count);
626 : : }
627 : : return count;
628 : : }
629 : :
630 : : static uint16_t
631 [ # # ]: 0 : otx_cpt_enqueue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
632 : : {
633 : 0 : return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_ASYM);
634 : : }
635 : :
636 : : static uint16_t
637 [ # # ]: 0 : otx_cpt_enqueue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
638 : : {
639 : 0 : return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_SYM);
640 : : }
641 : :
642 : : static __rte_always_inline void
643 : : submit_request_to_sso(struct ssows *ws, uintptr_t req,
644 : : struct rte_event *rsp_info)
645 : : {
646 : : uint64_t add_work;
647 : :
648 : 0 : add_work = rsp_info->flow_id | (RTE_EVENT_TYPE_CRYPTODEV << 28) |
649 : 0 : (rsp_info->sub_event_type << 20) |
650 : 0 : ((uint64_t)(rsp_info->sched_type) << 32);
651 : :
652 : 0 : if (!rsp_info->sched_type)
653 : : ssows_head_wait(ws);
654 : :
655 : : rte_atomic_thread_fence(rte_memory_order_release);
656 : 0 : ssovf_store_pair(add_work, req, ws->grps[rsp_info->queue_id]);
657 : : }
658 : :
659 : : uint16_t __rte_hot
660 : 0 : otx_crypto_adapter_enqueue(void *port, struct rte_crypto_op *op)
661 : : {
662 : : union rte_event_crypto_metadata *ec_mdata;
663 : : struct cpt_instance *instance;
664 : : struct cpt_request_info *req;
665 : : struct rte_event *rsp_info;
666 : : uint8_t op_type, cdev_id;
667 : : uint16_t qp_id;
668 : :
669 : 0 : ec_mdata = rte_cryptodev_session_event_mdata_get(op);
670 [ # # ]: 0 : if (unlikely(ec_mdata == NULL)) {
671 : 0 : rte_errno = EINVAL;
672 : 0 : return 0;
673 : : }
674 : :
675 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
676 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
677 : : rsp_info = &ec_mdata->response_info;
678 : 0 : instance = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
679 : :
680 [ # # ]: 0 : if (unlikely(!instance->ca_enabled)) {
681 : 0 : rte_errno = EINVAL;
682 : 0 : return 0;
683 : : }
684 : :
685 [ # # ]: 0 : op_type = op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM :
686 : : OP_TYPE_ASYM;
687 : : req = otx_cpt_enq_single(instance, op, op_type);
688 [ # # ]: 0 : if (unlikely(req == NULL))
689 : : return 0;
690 : :
691 : : otx_cpt_ring_dbell(instance, 1);
692 : 0 : req->qp = instance;
693 [ # # ]: 0 : submit_request_to_sso(port, (uintptr_t)req, rsp_info);
694 : :
695 : 0 : return 1;
696 : : }
697 : :
698 : : static inline void
699 : 0 : otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
700 : : struct rte_crypto_rsa_xform *rsa_ctx)
701 : :
702 : : {
703 : : struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa;
704 : :
705 [ # # # # : 0 : switch (rsa->op_type) {
# ]
706 : 0 : case RTE_CRYPTO_ASYM_OP_ENCRYPT:
707 : 0 : rsa->cipher.length = rsa_ctx->n.length;
708 : 0 : memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
709 : : break;
710 : 0 : case RTE_CRYPTO_ASYM_OP_DECRYPT:
711 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
712 : 0 : rsa->message.length = rsa_ctx->n.length;
713 : : else {
714 : : /* Get length of decrypted output */
715 [ # # ]: 0 : rsa->message.length = rte_cpu_to_be_16
716 : : (*((uint16_t *)req->rptr));
717 : :
718 : : /* Offset data pointer by length fields */
719 : 0 : req->rptr += 2;
720 : : }
721 : 0 : memcpy(rsa->message.data, req->rptr, rsa->message.length);
722 : : break;
723 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
724 : 0 : rsa->sign.length = rsa_ctx->n.length;
725 : 0 : memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
726 : : break;
727 : 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
728 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
729 : 0 : rsa->sign.length = rsa_ctx->n.length;
730 : : else {
731 : : /* Get length of decrypted output */
732 [ # # ]: 0 : rsa->sign.length = rte_cpu_to_be_16
733 : : (*((uint16_t *)req->rptr));
734 : :
735 : : /* Offset data pointer by length fields */
736 : 0 : req->rptr += 2;
737 : : }
738 [ # # ]: 0 : memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
739 : :
740 [ # # ]: 0 : if (memcmp(rsa->sign.data, rsa->message.data,
741 : : rsa->message.length)) {
742 : 0 : CPT_LOG_DP_ERR("RSA verification failed");
743 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
744 : : }
745 : : break;
746 : 0 : default:
747 : : CPT_LOG_DP_DEBUG("Invalid RSA operation type");
748 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
749 : 0 : break;
750 : : }
751 : 0 : }
752 : :
753 : : static __rte_always_inline void
754 : : otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
755 : : struct cpt_request_info *req,
756 : : struct cpt_asym_ec_ctx *ec)
757 : :
758 : : {
759 : 0 : int prime_len = ec_grp[ec->curveid].prime.length;
760 : :
761 : 0 : if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
762 : : return;
763 : :
764 : : /* Separate out sign r and s components */
765 : 0 : memcpy(ecdsa->r.data, req->rptr, prime_len);
766 : 0 : memcpy(ecdsa->s.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8),
767 : : prime_len);
768 : 0 : ecdsa->r.length = prime_len;
769 : 0 : ecdsa->s.length = prime_len;
770 : : }
771 : :
772 : : static __rte_always_inline void
773 : : otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm,
774 : : struct cpt_request_info *req,
775 : : struct cpt_asym_ec_ctx *ec)
776 : : {
777 : 0 : int prime_len = ec_grp[ec->curveid].prime.length;
778 : :
779 : 0 : memcpy(ecpm->r.x.data, req->rptr, prime_len);
780 : 0 : memcpy(ecpm->r.y.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8),
781 : : prime_len);
782 : 0 : ecpm->r.x.length = prime_len;
783 : 0 : ecpm->r.y.length = prime_len;
784 : 0 : }
785 : :
786 : : static __rte_always_inline void __rte_hot
787 : : otx_cpt_asym_post_process(struct rte_crypto_op *cop,
788 : : struct cpt_request_info *req)
789 : : {
790 : : struct rte_crypto_asym_op *op = cop->asym;
791 : : struct cpt_asym_sess_misc *sess;
792 : :
793 : 0 : sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
794 : :
795 : 0 : switch (sess->xfrm_type) {
796 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
797 : 0 : otx_cpt_asym_rsa_op(cop, req, &sess->rsa_ctx);
798 : 0 : break;
799 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
800 : 0 : op->modex.result.length = sess->mod_ctx.modulus.length;
801 : 0 : memcpy(op->modex.result.data, req->rptr,
802 : : op->modex.result.length);
803 : : break;
804 [ # # # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
805 : : otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
806 : : break;
807 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
808 : : otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
809 : : break;
810 : 0 : default:
811 : : CPT_LOG_DP_DEBUG("Invalid crypto xform type");
812 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
813 : 0 : break;
814 : : }
815 : : }
816 : :
817 : : static __rte_always_inline void __rte_hot
818 : : otx_cpt_dequeue_post_process(struct rte_crypto_op *cop, uintptr_t *rsp,
819 : : const uint8_t op_type)
820 : : {
821 : : /* H/w has returned success */
822 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
823 : :
824 : : /* Perform further post processing */
825 : :
826 [ # # ]: 0 : if ((op_type == OP_TYPE_SYM) &&
827 [ # # # # ]: 0 : (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
828 : : /* Check if auth verify need to be completed */
829 [ # # # # ]: 0 : if (unlikely(rsp[2]))
830 [ # # # # ]: 0 : compl_auth_verify(cop, (uint8_t *)rsp[2], rsp[3]);
831 : : return;
832 : : }
833 : :
834 [ # # ]: 0 : if ((op_type == OP_TYPE_ASYM) &&
835 [ # # # # ]: 0 : (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC)) {
836 [ # # # # : 0 : rsp = RTE_PTR_ADD(rsp, 4 * sizeof(uintptr_t));
# # # # #
# ]
837 : : otx_cpt_asym_post_process(cop, (struct cpt_request_info *)rsp);
838 : : }
839 : :
840 : : return;
841 : : }
842 : :
843 : : static inline void
844 : 0 : free_sym_session_data(const struct cpt_instance *instance,
845 : : struct rte_crypto_op *cop)
846 : : {
847 [ # # ]: 0 : void *sess_private_data_t = CRYPTODEV_GET_SYM_SESS_PRIV(cop->sym->session);
848 : :
849 : : memset(sess_private_data_t, 0, cpt_get_session_size());
850 [ # # ]: 0 : rte_mempool_put(instance->sess_mp, cop->sym->session);
851 : 0 : cop->sym->session = NULL;
852 : 0 : }
853 : :
854 : : static __rte_always_inline struct rte_crypto_op *
855 : : otx_cpt_process_response(const struct cpt_instance *instance, uintptr_t *rsp,
856 : : uint8_t cc, const uint8_t op_type)
857 : : {
858 : : struct rte_crypto_op *cop;
859 : : void *metabuf;
860 : :
861 : 0 : metabuf = (void *)rsp[0];
862 : 0 : cop = (void *)rsp[1];
863 : :
864 : : /* Check completion code */
865 : 0 : if (likely(cc == 0)) {
866 : : /* H/w success pkt. Post process */
867 : : otx_cpt_dequeue_post_process(cop, rsp, op_type);
868 [ # # # # : 0 : } else if (cc == ERR_GC_ICV_MISCOMPARE) {
# # ]
869 : : /* auth data mismatch */
870 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
871 : : } else {
872 : : /* Error */
873 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
874 : : }
875 : :
876 [ # # # # : 0 : if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS))
# # ]
877 : 0 : free_sym_session_data(instance, cop);
878 [ # # # # : 0 : free_op_meta(metabuf, instance->meta_info.pool);
# # ]
879 : :
880 : : return cop;
881 : : }
882 : :
883 : : static __rte_always_inline uint16_t __rte_hot
884 : : otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
885 : : const uint8_t op_type)
886 : 0 : {
887 : : struct cpt_instance *instance = (struct cpt_instance *)qptr;
888 : : struct cpt_request_info *user_req;
889 : : struct cpt_vf *cptvf = (struct cpt_vf *)instance;
890 : 0 : uint8_t cc[nb_ops];
891 : : int i, count, pcount;
892 : : uint8_t ret;
893 : : int nb_completed;
894 : : struct pending_queue *pqueue = &cptvf->pqueue;
895 : :
896 : 0 : pcount = pending_queue_level(pqueue, DEFAULT_CMD_QLEN);
897 : :
898 : : /* Ensure pcount isn't read before data lands */
899 : : rte_atomic_thread_fence(rte_memory_order_acquire);
900 : :
901 : 0 : count = (nb_ops > pcount) ? pcount : nb_ops;
902 : :
903 [ # # # # ]: 0 : for (i = 0; i < count; i++) {
904 : 0 : pending_queue_peek(pqueue, (void **) &user_req,
905 [ # # # # ]: 0 : DEFAULT_CMD_QLEN, i + 1 < count);
906 : :
907 : : ret = check_nb_command_id(user_req, instance);
908 : :
909 [ # # # # ]: 0 : if (unlikely(ret == ERR_REQ_PENDING)) {
910 : : /* Stop checking for completions */
911 : : break;
912 : : }
913 : :
914 : : /* Return completion code and op handle */
915 : 0 : cc[i] = ret;
916 : 0 : ops[i] = user_req->op;
917 : :
918 : : CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d",
919 : : user_req, user_req->op, ret);
920 : :
921 : : pending_queue_pop(pqueue, DEFAULT_CMD_QLEN);
922 : : }
923 : :
924 : : nb_completed = i;
925 : :
926 [ # # # # ]: 0 : for (i = 0; i < nb_completed; i++) {
927 [ # # # # ]: 0 : if (likely((i + 1) < nb_completed))
928 : 0 : rte_prefetch0(ops[i+1]);
929 : :
930 : 0 : ops[i] = otx_cpt_process_response(instance, (void *)ops[i],
931 [ # # # # ]: 0 : cc[i], op_type);
932 : : }
933 : :
934 : 0 : return nb_completed;
935 : : }
936 : :
937 : : static uint16_t
938 : 0 : otx_cpt_dequeue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
939 : : {
940 : 0 : return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_ASYM);
941 : : }
942 : :
943 : : static uint16_t
944 : 0 : otx_cpt_dequeue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
945 : : {
946 : 0 : return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_SYM);
947 : : }
948 : :
949 : : uintptr_t __rte_hot
950 : 0 : otx_crypto_adapter_dequeue(uintptr_t get_work1)
951 : : {
952 : : const struct cpt_instance *instance;
953 : : struct cpt_request_info *req;
954 : : struct rte_crypto_op *cop;
955 : : uint8_t cc, op_type;
956 : : uintptr_t *rsp;
957 : :
958 : 0 : req = (struct cpt_request_info *)get_work1;
959 : 0 : instance = req->qp;
960 : 0 : rsp = req->op;
961 : 0 : cop = (void *)rsp[1];
962 : 0 : op_type = cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM :
963 : : OP_TYPE_ASYM;
964 : :
965 : : do {
966 : : cc = check_nb_command_id(
967 : : req, (struct cpt_instance *)(uintptr_t)instance);
968 [ # # ]: 0 : } while (cc == ERR_REQ_PENDING);
969 : :
970 [ # # ]: 0 : cop = otx_cpt_process_response(instance, (void *)req->op, cc, op_type);
971 : :
972 : 0 : return (uintptr_t)(cop);
973 : : }
974 : :
975 : : static struct rte_cryptodev_ops cptvf_ops = {
976 : : /* Device related operations */
977 : : .dev_configure = otx_cpt_dev_config,
978 : : .dev_start = otx_cpt_dev_start,
979 : : .dev_stop = otx_cpt_dev_stop,
980 : : .dev_close = otx_cpt_dev_close,
981 : : .dev_infos_get = otx_cpt_dev_info_get,
982 : :
983 : : .stats_get = NULL,
984 : : .stats_reset = NULL,
985 : : .queue_pair_setup = otx_cpt_que_pair_setup,
986 : : .queue_pair_release = otx_cpt_que_pair_release,
987 : :
988 : : /* Crypto related operations */
989 : : .sym_session_get_size = otx_cpt_get_session_size,
990 : : .sym_session_configure = otx_cpt_session_cfg,
991 : : .sym_session_clear = otx_cpt_session_clear,
992 : :
993 : : .asym_session_get_size = otx_cpt_asym_session_size_get,
994 : : .asym_session_configure = otx_cpt_asym_session_cfg,
995 : : .asym_session_clear = otx_cpt_asym_session_clear,
996 : : };
997 : :
998 : : int
999 : 0 : otx_cpt_dev_create(struct rte_cryptodev *c_dev)
1000 : : {
1001 : 0 : struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device);
1002 : : struct cpt_vf *cptvf = NULL;
1003 : : void *reg_base;
1004 : : char dev_name[32];
1005 : : int ret;
1006 : :
1007 [ # # ]: 0 : if (pdev->mem_resource[0].phys_addr == 0ULL)
1008 : : return -EIO;
1009 : :
1010 : : /* for secondary processes, we don't initialise any further as primary
1011 : : * has already done this work.
1012 : : */
1013 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1014 : : return 0;
1015 : :
1016 : 0 : cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem",
1017 : : sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE,
1018 : 0 : rte_socket_id());
1019 : :
1020 [ # # ]: 0 : if (cptvf == NULL) {
1021 : 0 : CPT_LOG_ERR("Cannot allocate memory for device private data");
1022 : 0 : return -ENOMEM;
1023 : : }
1024 : :
1025 : 0 : snprintf(dev_name, 32, "%02x:%02x.%x",
1026 [ # # ]: 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
1027 : :
1028 : 0 : reg_base = pdev->mem_resource[0].addr;
1029 [ # # ]: 0 : if (!reg_base) {
1030 : 0 : CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name);
1031 : : ret = -ENODEV;
1032 : 0 : goto fail;
1033 : : }
1034 : :
1035 : 0 : ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name);
1036 [ # # ]: 0 : if (ret) {
1037 : 0 : CPT_LOG_ERR("Failed to init cptvf %s", dev_name);
1038 : : ret = -EIO;
1039 : 0 : goto fail;
1040 : : }
1041 : :
1042 [ # # # ]: 0 : switch (cptvf->vftype) {
1043 : 0 : case OTX_CPT_VF_TYPE_AE:
1044 : : /* Set asymmetric cpt feature flags */
1045 : 0 : c_dev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
1046 : : RTE_CRYPTODEV_FF_HW_ACCELERATED |
1047 : : RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT;
1048 : 0 : break;
1049 : 0 : case OTX_CPT_VF_TYPE_SE:
1050 : : /* Set symmetric cpt feature flags */
1051 : 0 : c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1052 : : RTE_CRYPTODEV_FF_HW_ACCELERATED |
1053 : : RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
1054 : : RTE_CRYPTODEV_FF_IN_PLACE_SGL |
1055 : : RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
1056 : : RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
1057 : : RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
1058 : : RTE_CRYPTODEV_FF_SYM_SESSIONLESS |
1059 : : RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED;
1060 : 0 : break;
1061 : 0 : default:
1062 : : /* Feature not supported. Abort */
1063 : 0 : CPT_LOG_ERR("VF type not supported by %s", dev_name);
1064 : : ret = -EIO;
1065 : 0 : goto deinit_dev;
1066 : : }
1067 : :
1068 : : /* Start off timer for mailbox interrupts */
1069 : : otx_cpt_periodic_alarm_start(cptvf);
1070 : :
1071 : 0 : c_dev->dev_ops = &cptvf_ops;
1072 : :
1073 [ # # ]: 0 : if (c_dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
1074 : 0 : c_dev->enqueue_burst = otx_cpt_enqueue_sym;
1075 : 0 : c_dev->dequeue_burst = otx_cpt_dequeue_sym;
1076 : : } else {
1077 : 0 : c_dev->enqueue_burst = otx_cpt_enqueue_asym;
1078 : 0 : c_dev->dequeue_burst = otx_cpt_dequeue_asym;
1079 : : }
1080 : :
1081 : : /* Save dev private data */
1082 : 0 : c_dev->data->dev_private = cptvf;
1083 : :
1084 : 0 : return 0;
1085 : :
1086 : : deinit_dev:
1087 : 0 : otx_cpt_deinit_device(cptvf);
1088 : :
1089 : 0 : fail:
1090 : : if (cptvf) {
1091 : : /* Free private data allocated */
1092 : 0 : rte_free(cptvf);
1093 : : }
1094 : :
1095 : 0 : return ret;
1096 : : }
|