1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
6 #include <rte_bus_pci.h>
7 #include <rte_cryptodev.h>
8 #include <rte_cryptodev_pmd.h>
10 #include <rte_malloc.h>
11 #include <rte_mempool.h>
13 #include "otx_cryptodev.h"
14 #include "otx_cryptodev_capabilities.h"
15 #include "otx_cryptodev_hw_access.h"
16 #include "otx_cryptodev_mbox.h"
17 #include "otx_cryptodev_ops.h"
19 #include "cpt_pmd_logs.h"
20 #include "cpt_ucode.h"
21 #include "cpt_ucode_asym.h"
23 /* Forward declarations */
26 otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id);
31 otx_cpt_alarm_cb(void *arg)
33 struct cpt_vf *cptvf = arg;
34 otx_cpt_poll_misc(cptvf);
35 rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
36 otx_cpt_alarm_cb, cptvf);
40 otx_cpt_periodic_alarm_start(void *arg)
42 return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
43 otx_cpt_alarm_cb, arg);
47 otx_cpt_periodic_alarm_stop(void *arg)
49 return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg);
55 otx_cpt_dev_config(struct rte_cryptodev *dev __rte_unused,
56 struct rte_cryptodev_config *config __rte_unused)
58 CPT_PMD_INIT_FUNC_TRACE();
63 otx_cpt_dev_start(struct rte_cryptodev *c_dev)
65 void *cptvf = c_dev->data->dev_private;
67 CPT_PMD_INIT_FUNC_TRACE();
69 return otx_cpt_start_device(cptvf);
73 otx_cpt_dev_stop(struct rte_cryptodev *c_dev)
75 void *cptvf = c_dev->data->dev_private;
77 CPT_PMD_INIT_FUNC_TRACE();
79 otx_cpt_stop_device(cptvf);
83 otx_cpt_dev_close(struct rte_cryptodev *c_dev)
85 void *cptvf = c_dev->data->dev_private;
88 CPT_PMD_INIT_FUNC_TRACE();
90 for (i = 0; i < c_dev->data->nb_queue_pairs; i++) {
91 ret = otx_cpt_que_pair_release(c_dev, i);
96 otx_cpt_periodic_alarm_stop(cptvf);
97 otx_cpt_deinit_device(cptvf);
103 otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
105 CPT_PMD_INIT_FUNC_TRACE();
107 info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF;
108 info->feature_flags = dev->feature_flags;
109 info->capabilities = otx_get_capabilities(info->feature_flags);
110 info->sym.max_nb_sessions = 0;
111 info->driver_id = otx_cryptodev_driver_id;
112 info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ;
113 info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ;
118 otx_cpt_stats_get(struct rte_cryptodev *dev __rte_unused,
119 struct rte_cryptodev_stats *stats __rte_unused)
121 CPT_PMD_INIT_FUNC_TRACE();
125 otx_cpt_stats_reset(struct rte_cryptodev *dev __rte_unused)
127 CPT_PMD_INIT_FUNC_TRACE();
131 otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
132 uint16_t que_pair_id,
133 const struct rte_cryptodev_qp_conf *qp_conf,
134 int socket_id __rte_unused)
136 struct cpt_instance *instance = NULL;
137 struct rte_pci_device *pci_dev;
140 CPT_PMD_INIT_FUNC_TRACE();
142 if (dev->data->queue_pairs[que_pair_id] != NULL) {
143 ret = otx_cpt_que_pair_release(dev, que_pair_id);
148 if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) {
149 CPT_LOG_INFO("Number of descriptors too big %d, using default "
150 "queue length of %d", qp_conf->nb_descriptors,
154 pci_dev = RTE_DEV_TO_PCI(dev->device);
156 if (pci_dev->mem_resource[0].addr == NULL) {
157 CPT_LOG_ERR("PCI mem address null");
161 ret = otx_cpt_get_resource(dev, 0, &instance, que_pair_id);
162 if (ret != 0 || instance == NULL) {
163 CPT_LOG_ERR("Error getting instance handle from device %s : "
164 "ret = %d", dev->data->name, ret);
168 instance->queue_id = que_pair_id;
169 instance->sess_mp = qp_conf->mp_session;
170 instance->sess_mp_priv = qp_conf->mp_session_private;
171 dev->data->queue_pairs[que_pair_id] = instance;
177 otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id)
179 struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id];
182 CPT_PMD_INIT_FUNC_TRACE();
184 ret = otx_cpt_put_resource(instance);
186 CPT_LOG_ERR("Error putting instance handle of device %s : "
187 "ret = %d", dev->data->name, ret);
191 dev->data->queue_pairs[que_pair_id] = NULL;
197 otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused)
199 return cpt_get_session_size();
203 otx_cpt_session_init(void *sym_sess, uint8_t driver_id)
205 struct rte_cryptodev_sym_session *sess = sym_sess;
206 struct cpt_sess_misc *cpt_sess =
207 (struct cpt_sess_misc *) get_sym_session_private_data(sess, driver_id);
209 CPT_PMD_INIT_FUNC_TRACE();
210 cpt_sess->ctx_dma_addr = rte_mempool_virt2iova(cpt_sess) +
211 sizeof(struct cpt_sess_misc);
215 otx_cpt_session_cfg(struct rte_cryptodev *dev,
216 struct rte_crypto_sym_xform *xform,
217 struct rte_cryptodev_sym_session *sess,
218 struct rte_mempool *mempool)
220 struct rte_crypto_sym_xform *chain;
221 void *sess_private_data = NULL;
223 CPT_PMD_INIT_FUNC_TRACE();
225 if (cpt_is_algo_supported(xform))
228 if (unlikely(sess == NULL)) {
229 CPT_LOG_ERR("invalid session struct");
233 if (rte_mempool_get(mempool, &sess_private_data)) {
234 CPT_LOG_ERR("Could not allocate sess_private_data");
240 switch (chain->type) {
241 case RTE_CRYPTO_SYM_XFORM_AEAD:
242 if (fill_sess_aead(chain, sess_private_data))
245 case RTE_CRYPTO_SYM_XFORM_CIPHER:
246 if (fill_sess_cipher(chain, sess_private_data))
249 case RTE_CRYPTO_SYM_XFORM_AUTH:
250 if (chain->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
251 if (fill_sess_gmac(chain, sess_private_data))
254 if (fill_sess_auth(chain, sess_private_data))
259 CPT_LOG_ERR("Invalid crypto xform type");
264 set_sym_session_private_data(sess, dev->driver_id, sess_private_data);
265 otx_cpt_session_init(sess, dev->driver_id);
269 if (sess_private_data)
270 rte_mempool_put(mempool, sess_private_data);
275 otx_cpt_session_clear(struct rte_cryptodev *dev,
276 struct rte_cryptodev_sym_session *sess)
278 void *sess_priv = get_sym_session_private_data(sess, dev->driver_id);
280 CPT_PMD_INIT_FUNC_TRACE();
282 memset(sess_priv, 0, otx_cpt_get_session_size(dev));
283 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
284 set_sym_session_private_data(sess, dev->driver_id, NULL);
285 rte_mempool_put(sess_mp, sess_priv);
290 otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
292 return sizeof(struct cpt_asym_sess_misc);
296 otx_cpt_asym_session_cfg(struct rte_cryptodev *dev,
297 struct rte_crypto_asym_xform *xform __rte_unused,
298 struct rte_cryptodev_asym_session *sess,
299 struct rte_mempool *pool)
301 struct cpt_asym_sess_misc *priv;
304 CPT_PMD_INIT_FUNC_TRACE();
306 if (rte_mempool_get(pool, (void **)&priv)) {
307 CPT_LOG_ERR("Could not allocate session private data");
311 memset(priv, 0, sizeof(struct cpt_asym_sess_misc));
313 ret = cpt_fill_asym_session_parameters(priv, xform);
315 CPT_LOG_ERR("Could not configure session parameters");
317 /* Return session to mempool */
318 rte_mempool_put(pool, priv);
322 set_asym_session_private_data(sess, dev->driver_id, priv);
327 otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
328 struct rte_cryptodev_asym_session *sess)
330 struct cpt_asym_sess_misc *priv;
331 struct rte_mempool *sess_mp;
333 CPT_PMD_INIT_FUNC_TRACE();
335 priv = get_asym_session_private_data(sess, dev->driver_id);
340 /* Free resources allocated during session configure */
341 cpt_free_asym_session_parameters(priv);
342 memset(priv, 0, otx_cpt_asym_session_size_get(dev));
343 sess_mp = rte_mempool_from_obj(priv);
344 set_asym_session_private_data(sess, dev->driver_id, NULL);
345 rte_mempool_put(sess_mp, priv);
348 static __rte_always_inline int32_t __hot
349 otx_cpt_request_enqueue(struct cpt_instance *instance,
350 struct pending_queue *pqueue,
353 struct cpt_request_info *user_req = (struct cpt_request_info *)req;
355 if (unlikely(pqueue->pending_count >= DEFAULT_CMD_QLEN))
358 fill_cpt_inst(instance, req);
360 CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op);
362 /* Fill time_out cycles */
363 user_req->time_out = rte_get_timer_cycles() +
364 DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
365 user_req->extra_time = 0;
367 /* Default mode of software queue */
368 mark_cpt_inst(instance);
370 pqueue->rid_queue[pqueue->enq_tail].rid = (uintptr_t)user_req;
372 /* We will use soft queue length here to limit requests */
373 MOD_INC(pqueue->enq_tail, DEFAULT_CMD_QLEN);
374 pqueue->pending_count += 1;
376 CPT_LOG_DP_DEBUG("Submitted NB cmd with request: %p "
377 "op: %p", user_req, user_req->op);
381 static __rte_always_inline int __hot
382 otx_cpt_enq_single_asym(struct cpt_instance *instance,
383 struct rte_crypto_op *op,
384 struct pending_queue *pqueue)
386 struct cpt_qp_meta_info *minfo = &instance->meta_info;
387 struct rte_crypto_asym_op *asym_op = op->asym;
388 struct asym_op_params params = {0};
389 struct cpt_asym_sess_misc *sess;
394 if (unlikely(rte_mempool_get(minfo->pool, &mdata) < 0)) {
395 CPT_LOG_DP_ERR("Could not allocate meta buffer for request");
399 sess = get_asym_session_private_data(asym_op->session,
400 otx_cryptodev_driver_id);
402 /* Store phys_addr of the mdata to meta_buf */
403 params.meta_buf = rte_mempool_virt2iova(mdata);
406 cop[0] = (uintptr_t)mdata;
407 cop[1] = (uintptr_t)op;
408 cop[2] = cop[3] = 0ULL;
410 params.req = RTE_PTR_ADD(cop, 4 * sizeof(uintptr_t));
411 params.req->op = cop;
413 /* Adjust meta_buf by crypto_op data and request_info struct */
414 params.meta_buf += (4 * sizeof(uintptr_t)) +
415 sizeof(struct cpt_request_info);
417 switch (sess->xfrm_type) {
418 case RTE_CRYPTO_ASYM_XFORM_MODEX:
419 ret = cpt_modex_prep(¶ms, &sess->mod_ctx);
423 case RTE_CRYPTO_ASYM_XFORM_RSA:
424 ret = cpt_enqueue_rsa_op(op, ¶ms, sess);
429 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
434 ret = otx_cpt_request_enqueue(instance, pqueue, params.req);
437 CPT_LOG_DP_ERR("Could not enqueue crypto req");
444 free_op_meta(mdata, minfo->pool);
449 static __rte_always_inline int __hot
450 otx_cpt_enq_single_sym(struct cpt_instance *instance,
451 struct rte_crypto_op *op,
452 struct pending_queue *pqueue)
454 struct cpt_sess_misc *sess;
455 struct rte_crypto_sym_op *sym_op = op->sym;
456 void *prep_req, *mdata = NULL;
460 sess = (struct cpt_sess_misc *)
461 get_sym_session_private_data(sym_op->session,
462 otx_cryptodev_driver_id);
464 cpt_op = sess->cpt_op;
466 if (likely(cpt_op & CPT_OP_CIPHER_MASK))
467 ret = fill_fc_params(op, sess, &instance->meta_info, &mdata,
470 ret = fill_digest_params(op, sess, &instance->meta_info,
474 CPT_LOG_DP_ERR("prep cryto req : op %p, cpt_op 0x%x "
475 "ret 0x%x", op, (unsigned int)cpt_op, ret);
479 /* Enqueue prepared instruction to h/w */
480 ret = otx_cpt_request_enqueue(instance, pqueue, prep_req);
483 /* Buffer allocated for request preparation need to be freed */
484 free_op_meta(mdata, instance->meta_info.pool);
491 static __rte_always_inline int __hot
492 otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
493 struct rte_crypto_op *op,
494 struct pending_queue *pqueue)
496 struct cpt_sess_misc *sess;
497 struct rte_crypto_sym_op *sym_op = op->sym;
500 void *sess_private_data_t = NULL;
502 /* Create tmp session */
504 if (rte_mempool_get(instance->sess_mp, (void **)&sess_t)) {
509 if (rte_mempool_get(instance->sess_mp_priv,
510 (void **)&sess_private_data_t)) {
515 sess = (struct cpt_sess_misc *)sess_private_data_t;
517 sess->ctx_dma_addr = rte_mempool_virt2iova(sess) +
518 sizeof(struct cpt_sess_misc);
520 ret = instance_session_cfg(sym_op->xform, (void *)sess);
526 /* Save tmp session in op */
528 sym_op->session = (struct rte_cryptodev_sym_session *)sess_t;
529 set_sym_session_private_data(sym_op->session, otx_cryptodev_driver_id,
530 sess_private_data_t);
532 /* Enqueue op with the tmp session set */
533 ret = otx_cpt_enq_single_sym(instance, op, pqueue);
541 rte_mempool_put(instance->sess_mp_priv, sess_private_data_t);
543 rte_mempool_put(instance->sess_mp, sess_t);
548 #define OP_TYPE_SYM 0
549 #define OP_TYPE_ASYM 1
551 static __rte_always_inline int __hot
552 otx_cpt_enq_single(struct cpt_instance *inst,
553 struct rte_crypto_op *op,
554 struct pending_queue *pqueue,
555 const uint8_t op_type)
557 /* Check for the type */
559 if (op_type == OP_TYPE_SYM) {
560 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
561 return otx_cpt_enq_single_sym(inst, op, pqueue);
563 return otx_cpt_enq_single_sym_sessless(inst, op,
567 if (op_type == OP_TYPE_ASYM) {
568 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
569 return otx_cpt_enq_single_asym(inst, op, pqueue);
572 /* Should not reach here */
576 static __rte_always_inline uint16_t __hot
577 otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
578 const uint8_t op_type)
580 struct cpt_instance *instance = (struct cpt_instance *)qptr;
583 struct cpt_vf *cptvf = (struct cpt_vf *)instance;
584 struct pending_queue *pqueue = &cptvf->pqueue;
586 count = DEFAULT_CMD_QLEN - pqueue->pending_count;
591 while (likely(count < nb_ops)) {
593 /* Enqueue single op */
594 ret = otx_cpt_enq_single(instance, ops[count], pqueue, op_type);
600 otx_cpt_ring_dbell(instance, count);
605 otx_cpt_enqueue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
607 return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_ASYM);
611 otx_cpt_enqueue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
613 return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_SYM);
617 otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
618 struct rte_crypto_rsa_xform *rsa_ctx)
621 struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa;
623 switch (rsa->op_type) {
624 case RTE_CRYPTO_ASYM_OP_ENCRYPT:
625 rsa->cipher.length = rsa_ctx->n.length;
626 memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
628 case RTE_CRYPTO_ASYM_OP_DECRYPT:
629 if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE)
630 rsa->message.length = rsa_ctx->n.length;
632 /* Get length of decrypted output */
633 rsa->message.length = rte_cpu_to_be_16
634 (*((uint16_t *)req->rptr));
636 /* Offset data pointer by length fields */
639 memcpy(rsa->message.data, req->rptr, rsa->message.length);
641 case RTE_CRYPTO_ASYM_OP_SIGN:
642 rsa->sign.length = rsa_ctx->n.length;
643 memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
645 case RTE_CRYPTO_ASYM_OP_VERIFY:
646 if (rsa->pad == RTE_CRYPTO_RSA_PADDING_NONE)
647 rsa->sign.length = rsa_ctx->n.length;
649 /* Get length of decrypted output */
650 rsa->sign.length = rte_cpu_to_be_16
651 (*((uint16_t *)req->rptr));
653 /* Offset data pointer by length fields */
656 memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
658 if (memcmp(rsa->sign.data, rsa->message.data,
659 rsa->message.length)) {
660 CPT_LOG_DP_ERR("RSA verification failed");
661 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
665 CPT_LOG_DP_DEBUG("Invalid RSA operation type");
666 cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
671 static __rte_always_inline void __hot
672 otx_cpt_asym_post_process(struct rte_crypto_op *cop,
673 struct cpt_request_info *req)
675 struct rte_crypto_asym_op *op = cop->asym;
676 struct cpt_asym_sess_misc *sess;
678 sess = get_asym_session_private_data(op->session,
679 otx_cryptodev_driver_id);
681 switch (sess->xfrm_type) {
682 case RTE_CRYPTO_ASYM_XFORM_RSA:
683 otx_cpt_asym_rsa_op(cop, req, &sess->rsa_ctx);
685 case RTE_CRYPTO_ASYM_XFORM_MODEX:
686 op->modex.result.length = sess->mod_ctx.modulus.length;
687 memcpy(op->modex.result.data, req->rptr,
688 op->modex.result.length);
691 CPT_LOG_DP_DEBUG("Invalid crypto xform type");
692 cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
697 static __rte_always_inline void __hot
698 otx_cpt_dequeue_post_process(struct rte_crypto_op *cop, uintptr_t *rsp,
699 const uint8_t op_type)
701 /* H/w has returned success */
702 cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
704 /* Perform further post processing */
706 if ((op_type == OP_TYPE_SYM) &&
707 (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
708 /* Check if auth verify need to be completed */
709 if (unlikely(rsp[2]))
710 compl_auth_verify(cop, (uint8_t *)rsp[2], rsp[3]);
714 if ((op_type == OP_TYPE_ASYM) &&
715 (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC)) {
716 rsp = RTE_PTR_ADD(rsp, 4 * sizeof(uintptr_t));
717 otx_cpt_asym_post_process(cop, (struct cpt_request_info *)rsp);
723 static __rte_always_inline uint16_t __hot
724 otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
725 const uint8_t op_type)
727 struct cpt_instance *instance = (struct cpt_instance *)qptr;
728 struct cpt_request_info *user_req;
729 struct cpt_vf *cptvf = (struct cpt_vf *)instance;
732 int i, count, pcount;
735 struct pending_queue *pqueue = &cptvf->pqueue;
736 struct rte_crypto_op *cop;
740 pcount = pqueue->pending_count;
741 count = (nb_ops > pcount) ? pcount : nb_ops;
743 for (i = 0; i < count; i++) {
744 rid_e = &pqueue->rid_queue[pqueue->deq_head];
745 user_req = (struct cpt_request_info *)(rid_e->rid);
747 if (likely((i+1) < count))
748 rte_prefetch_non_temporal((void *)rid_e[1].rid);
750 ret = check_nb_command_id(user_req, instance);
752 if (unlikely(ret == ERR_REQ_PENDING)) {
753 /* Stop checking for completions */
757 /* Return completion code and op handle */
759 ops[i] = user_req->op;
761 CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d",
762 user_req, user_req->op, ret);
764 MOD_INC(pqueue->deq_head, DEFAULT_CMD_QLEN);
765 pqueue->pending_count -= 1;
770 for (i = 0; i < nb_completed; i++) {
772 rsp = (void *)ops[i];
774 if (likely((i + 1) < nb_completed))
775 rte_prefetch0(ops[i+1]);
777 metabuf = (void *)rsp[0];
778 cop = (void *)rsp[1];
782 /* Check completion code */
784 if (likely(cc[i] == 0)) {
785 /* H/w success pkt. Post process */
786 otx_cpt_dequeue_post_process(cop, rsp, op_type);
787 } else if (cc[i] == ERR_GC_ICV_MISCOMPARE) {
788 /* auth data mismatch */
789 cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
792 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
795 if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
796 void *sess_private_data_t =
797 get_sym_session_private_data(cop->sym->session,
798 otx_cryptodev_driver_id);
799 memset(sess_private_data_t, 0,
800 cpt_get_session_size());
801 memset(cop->sym->session, 0,
802 rte_cryptodev_sym_get_existing_header_session_size(
804 rte_mempool_put(instance->sess_mp_priv,
805 sess_private_data_t);
806 rte_mempool_put(instance->sess_mp, cop->sym->session);
807 cop->sym->session = NULL;
809 free_op_meta(metabuf, instance->meta_info.pool);
816 otx_cpt_dequeue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
818 return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_ASYM);
822 otx_cpt_dequeue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
824 return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_SYM);
827 static struct rte_cryptodev_ops cptvf_ops = {
828 /* Device related operations */
829 .dev_configure = otx_cpt_dev_config,
830 .dev_start = otx_cpt_dev_start,
831 .dev_stop = otx_cpt_dev_stop,
832 .dev_close = otx_cpt_dev_close,
833 .dev_infos_get = otx_cpt_dev_info_get,
835 .stats_get = otx_cpt_stats_get,
836 .stats_reset = otx_cpt_stats_reset,
837 .queue_pair_setup = otx_cpt_que_pair_setup,
838 .queue_pair_release = otx_cpt_que_pair_release,
839 .queue_pair_count = NULL,
841 /* Crypto related operations */
842 .sym_session_get_size = otx_cpt_get_session_size,
843 .sym_session_configure = otx_cpt_session_cfg,
844 .sym_session_clear = otx_cpt_session_clear,
846 .asym_session_get_size = otx_cpt_asym_session_size_get,
847 .asym_session_configure = otx_cpt_asym_session_cfg,
848 .asym_session_clear = otx_cpt_asym_session_clear,
852 otx_cpt_dev_create(struct rte_cryptodev *c_dev)
854 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device);
855 struct cpt_vf *cptvf = NULL;
860 if (pdev->mem_resource[0].phys_addr == 0ULL)
863 /* for secondary processes, we don't initialise any further as primary
864 * has already done this work.
866 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
869 cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem",
870 sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE,
874 CPT_LOG_ERR("Cannot allocate memory for device private data");
878 snprintf(dev_name, 32, "%02x:%02x.%x",
879 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
881 reg_base = pdev->mem_resource[0].addr;
883 CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name);
888 ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name);
890 CPT_LOG_ERR("Failed to init cptvf %s", dev_name);
895 switch (cptvf->vftype) {
896 case OTX_CPT_VF_TYPE_AE:
897 /* Set asymmetric cpt feature flags */
898 c_dev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
899 RTE_CRYPTODEV_FF_HW_ACCELERATED |
900 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT;
902 case OTX_CPT_VF_TYPE_SE:
903 /* Set symmetric cpt feature flags */
904 c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
905 RTE_CRYPTODEV_FF_HW_ACCELERATED |
906 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
907 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
908 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
909 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT;
912 /* Feature not supported. Abort */
913 CPT_LOG_ERR("VF type not supported by %s", dev_name);
918 /* Start off timer for mailbox interrupts */
919 otx_cpt_periodic_alarm_start(cptvf);
921 c_dev->dev_ops = &cptvf_ops;
923 if (c_dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
924 c_dev->enqueue_burst = otx_cpt_enqueue_sym;
925 c_dev->dequeue_burst = otx_cpt_dequeue_sym;
927 c_dev->enqueue_burst = otx_cpt_enqueue_asym;
928 c_dev->dequeue_burst = otx_cpt_dequeue_asym;
931 /* Save dev private data */
932 c_dev->data->dev_private = cptvf;
937 otx_cpt_deinit_device(cptvf);
941 /* Free private data allocated */