1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Marvell International Ltd.
3 * Copyright(c) 2017 Semihalf.
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_cryptodev.h>
10 #include <rte_cryptodev_pmd.h>
11 #include <rte_bus_vdev.h>
12 #include <rte_malloc.h>
13 #include <rte_cpuflags.h>
14 #include <rte_kvargs.h>
15 #include <rte_mvep_common.h>
17 #include "mrvl_pmd_private.h"
19 #define MRVL_PMD_MAX_NB_SESS_ARG ("max_nb_sessions")
20 #define MRVL_PMD_DEFAULT_MAX_NB_SESSIONS 2048
22 int mrvl_logtype_driver;
23 static uint8_t cryptodev_driver_id;
25 struct mrvl_pmd_init_params {
26 struct rte_cryptodev_pmd_init_params common;
27 uint32_t max_nb_sessions;
30 const char *mrvl_pmd_valid_params[] = {
31 RTE_CRYPTODEV_PMD_NAME_ARG,
32 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
33 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
34 MRVL_PMD_MAX_NB_SESS_ARG
38 * Flag if particular crypto algorithm is supported by PMD/MUSDK.
40 * The idea is to have Not Supported value as default (0).
41 * This way we need only to define proper map sizes,
42 * non-initialized entries will be by default not supported.
45 ALGO_NOT_SUPPORTED = 0,
49 /** Map elements for cipher mapping.*/
50 struct cipher_params_mapping {
51 enum algo_supported supported; /**< On/Off switch */
52 enum sam_cipher_alg cipher_alg; /**< Cipher algorithm */
53 enum sam_cipher_mode cipher_mode; /**< Cipher mode */
54 unsigned int max_key_len; /**< Maximum key length (in bytes)*/
56 /* We want to squeeze in multiple maps into the cache line. */
59 /** Map elements for auth mapping.*/
60 struct auth_params_mapping {
61 enum algo_supported supported; /**< On/off switch */
62 enum sam_auth_alg auth_alg; /**< Auth algorithm */
64 /* We want to squeeze in multiple maps into the cache line. */
68 * Map of supported cipher algorithms.
71 struct cipher_params_mapping cipher_map[RTE_CRYPTO_CIPHER_LIST_END] = {
72 [RTE_CRYPTO_CIPHER_NULL] = {
73 .supported = ALGO_SUPPORTED,
74 .cipher_alg = SAM_CIPHER_NONE },
75 [RTE_CRYPTO_CIPHER_3DES_CBC] = {
76 .supported = ALGO_SUPPORTED,
77 .cipher_alg = SAM_CIPHER_3DES,
78 .cipher_mode = SAM_CIPHER_CBC,
79 .max_key_len = BITS2BYTES(192) },
80 [RTE_CRYPTO_CIPHER_3DES_CTR] = {
81 .supported = ALGO_SUPPORTED,
82 .cipher_alg = SAM_CIPHER_3DES,
83 .cipher_mode = SAM_CIPHER_CTR,
84 .max_key_len = BITS2BYTES(192) },
85 [RTE_CRYPTO_CIPHER_3DES_ECB] = {
86 .supported = ALGO_SUPPORTED,
87 .cipher_alg = SAM_CIPHER_3DES,
88 .cipher_mode = SAM_CIPHER_ECB,
89 .max_key_len = BITS2BYTES(192) },
90 [RTE_CRYPTO_CIPHER_AES_CBC] = {
91 .supported = ALGO_SUPPORTED,
92 .cipher_alg = SAM_CIPHER_AES,
93 .cipher_mode = SAM_CIPHER_CBC,
94 .max_key_len = BITS2BYTES(256) },
95 [RTE_CRYPTO_CIPHER_AES_CTR] = {
96 .supported = ALGO_SUPPORTED,
97 .cipher_alg = SAM_CIPHER_AES,
98 .cipher_mode = SAM_CIPHER_CTR,
99 .max_key_len = BITS2BYTES(256) },
100 [RTE_CRYPTO_CIPHER_AES_ECB] = {
101 .supported = ALGO_SUPPORTED,
102 .cipher_alg = SAM_CIPHER_AES,
103 .cipher_mode = SAM_CIPHER_ECB,
104 .max_key_len = BITS2BYTES(256) },
108 * Map of supported auth algorithms.
111 struct auth_params_mapping auth_map[RTE_CRYPTO_AUTH_LIST_END] = {
112 [RTE_CRYPTO_AUTH_NULL] = {
113 .supported = ALGO_SUPPORTED,
114 .auth_alg = SAM_AUTH_NONE },
115 [RTE_CRYPTO_AUTH_MD5_HMAC] = {
116 .supported = ALGO_SUPPORTED,
117 .auth_alg = SAM_AUTH_HMAC_MD5 },
118 [RTE_CRYPTO_AUTH_MD5] = {
119 .supported = ALGO_SUPPORTED,
120 .auth_alg = SAM_AUTH_HASH_MD5 },
121 [RTE_CRYPTO_AUTH_SHA1_HMAC] = {
122 .supported = ALGO_SUPPORTED,
123 .auth_alg = SAM_AUTH_HMAC_SHA1 },
124 [RTE_CRYPTO_AUTH_SHA1] = {
125 .supported = ALGO_SUPPORTED,
126 .auth_alg = SAM_AUTH_HASH_SHA1 },
127 [RTE_CRYPTO_AUTH_SHA224_HMAC] = {
128 .supported = ALGO_SUPPORTED,
129 .auth_alg = SAM_AUTH_HMAC_SHA2_224 },
130 [RTE_CRYPTO_AUTH_SHA224] = {
131 .supported = ALGO_SUPPORTED,
132 .auth_alg = SAM_AUTH_HASH_SHA2_224 },
133 [RTE_CRYPTO_AUTH_SHA256_HMAC] = {
134 .supported = ALGO_SUPPORTED,
135 .auth_alg = SAM_AUTH_HMAC_SHA2_256 },
136 [RTE_CRYPTO_AUTH_SHA256] = {
137 .supported = ALGO_SUPPORTED,
138 .auth_alg = SAM_AUTH_HASH_SHA2_256 },
139 [RTE_CRYPTO_AUTH_SHA384_HMAC] = {
140 .supported = ALGO_SUPPORTED,
141 .auth_alg = SAM_AUTH_HMAC_SHA2_384 },
142 [RTE_CRYPTO_AUTH_SHA384] = {
143 .supported = ALGO_SUPPORTED,
144 .auth_alg = SAM_AUTH_HASH_SHA2_384 },
145 [RTE_CRYPTO_AUTH_SHA512_HMAC] = {
146 .supported = ALGO_SUPPORTED,
147 .auth_alg = SAM_AUTH_HMAC_SHA2_512 },
148 [RTE_CRYPTO_AUTH_SHA512] = {
149 .supported = ALGO_SUPPORTED,
150 .auth_alg = SAM_AUTH_HASH_SHA2_512 },
151 [RTE_CRYPTO_AUTH_AES_GMAC] = {
152 .supported = ALGO_SUPPORTED,
153 .auth_alg = SAM_AUTH_AES_GMAC },
157 * Map of supported aead algorithms.
160 struct cipher_params_mapping aead_map[RTE_CRYPTO_AEAD_LIST_END] = {
161 [RTE_CRYPTO_AEAD_AES_GCM] = {
162 .supported = ALGO_SUPPORTED,
163 .cipher_alg = SAM_CIPHER_AES,
164 .cipher_mode = SAM_CIPHER_GCM,
165 .max_key_len = BITS2BYTES(256) },
169 *-----------------------------------------------------------------------------
170 * Forward declarations.
171 *-----------------------------------------------------------------------------
173 static int cryptodev_mrvl_crypto_uninit(struct rte_vdev_device *vdev);
176 *-----------------------------------------------------------------------------
177 * Session Preparation.
178 *-----------------------------------------------------------------------------
182 * Get xform chain order.
184 * @param xform Pointer to configuration structure chain for crypto operations.
185 * @returns Order of crypto operations.
187 static enum mrvl_crypto_chain_order
188 mrvl_crypto_get_chain_order(const struct rte_crypto_sym_xform *xform)
190 /* Currently, Marvell supports max 2 operations in chain */
191 if (xform->next != NULL && xform->next->next != NULL)
192 return MRVL_CRYPTO_CHAIN_NOT_SUPPORTED;
194 if (xform->next != NULL) {
195 if ((xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
196 (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER))
197 return MRVL_CRYPTO_CHAIN_AUTH_CIPHER;
199 if ((xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
200 (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH))
201 return MRVL_CRYPTO_CHAIN_CIPHER_AUTH;
203 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH)
204 return MRVL_CRYPTO_CHAIN_AUTH_ONLY;
206 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
207 return MRVL_CRYPTO_CHAIN_CIPHER_ONLY;
209 if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD)
210 return MRVL_CRYPTO_CHAIN_COMBINED;
212 return MRVL_CRYPTO_CHAIN_NOT_SUPPORTED;
216 * Set session parameters for cipher part.
218 * @param sess Crypto session pointer.
219 * @param cipher_xform Pointer to configuration structure for cipher operations.
220 * @returns 0 in case of success, negative value otherwise.
223 mrvl_crypto_set_cipher_session_parameters(struct mrvl_crypto_session *sess,
224 const struct rte_crypto_sym_xform *cipher_xform)
228 /* Make sure we've got proper struct */
229 if (cipher_xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
230 MRVL_LOG(ERR, "Wrong xform struct provided!");
234 /* See if map data is present and valid */
235 if ((cipher_xform->cipher.algo > RTE_DIM(cipher_map)) ||
236 (cipher_map[cipher_xform->cipher.algo].supported
237 != ALGO_SUPPORTED)) {
238 MRVL_LOG(ERR, "Cipher algorithm not supported!");
242 sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
244 sess->sam_sess_params.dir =
245 (cipher_xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
246 SAM_DIR_ENCRYPT : SAM_DIR_DECRYPT;
247 sess->sam_sess_params.cipher_alg =
248 cipher_map[cipher_xform->cipher.algo].cipher_alg;
249 sess->sam_sess_params.cipher_mode =
250 cipher_map[cipher_xform->cipher.algo].cipher_mode;
252 /* Assume IV will be passed together with data. */
253 sess->sam_sess_params.cipher_iv = NULL;
255 /* Get max key length. */
256 if (cipher_xform->cipher.key.length >
257 cipher_map[cipher_xform->cipher.algo].max_key_len) {
258 MRVL_LOG(ERR, "Wrong key length!");
262 cipher_key = malloc(cipher_xform->cipher.key.length);
263 if (cipher_key == NULL) {
264 MRVL_LOG(ERR, "Insufficient memory!");
268 memcpy(cipher_key, cipher_xform->cipher.key.data,
269 cipher_xform->cipher.key.length);
271 sess->sam_sess_params.cipher_key_len = cipher_xform->cipher.key.length;
272 sess->sam_sess_params.cipher_key = cipher_key;
278 * Set session parameters for authentication part.
280 * @param sess Crypto session pointer.
281 * @param auth_xform Pointer to configuration structure for auth operations.
282 * @returns 0 in case of success, negative value otherwise.
285 mrvl_crypto_set_auth_session_parameters(struct mrvl_crypto_session *sess,
286 const struct rte_crypto_sym_xform *auth_xform)
288 uint8_t *auth_key = NULL;
290 /* Make sure we've got proper struct */
291 if (auth_xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
292 MRVL_LOG(ERR, "Wrong xform struct provided!");
296 /* See if map data is present and valid */
297 if ((auth_xform->auth.algo > RTE_DIM(auth_map)) ||
298 (auth_map[auth_xform->auth.algo].supported != ALGO_SUPPORTED)) {
299 MRVL_LOG(ERR, "Auth algorithm not supported!");
303 sess->sam_sess_params.dir =
304 (auth_xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
305 SAM_DIR_ENCRYPT : SAM_DIR_DECRYPT;
306 sess->sam_sess_params.auth_alg =
307 auth_map[auth_xform->auth.algo].auth_alg;
308 sess->sam_sess_params.u.basic.auth_icv_len =
309 auth_xform->auth.digest_length;
311 if (auth_xform->auth.key.length > 0) {
312 auth_key = malloc(auth_xform->auth.key.length);
313 if (auth_key == NULL) {
314 MRVL_LOG(ERR, "Not enough memory!");
318 memcpy(auth_key, auth_xform->auth.key.data,
319 auth_xform->auth.key.length);
322 /* auth_key must be NULL if auth algorithm does not use HMAC */
323 sess->sam_sess_params.auth_key = auth_key;
324 sess->sam_sess_params.auth_key_len = auth_xform->auth.key.length;
330 * Set session parameters for aead part.
332 * @param sess Crypto session pointer.
333 * @param aead_xform Pointer to configuration structure for aead operations.
334 * @returns 0 in case of success, negative value otherwise.
337 mrvl_crypto_set_aead_session_parameters(struct mrvl_crypto_session *sess,
338 const struct rte_crypto_sym_xform *aead_xform)
342 /* Make sure we've got proper struct */
343 if (aead_xform->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
344 MRVL_LOG(ERR, "Wrong xform struct provided!");
348 /* See if map data is present and valid */
349 if ((aead_xform->aead.algo > RTE_DIM(aead_map)) ||
350 (aead_map[aead_xform->aead.algo].supported
351 != ALGO_SUPPORTED)) {
352 MRVL_LOG(ERR, "AEAD algorithm not supported!");
356 sess->sam_sess_params.dir =
357 (aead_xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
358 SAM_DIR_ENCRYPT : SAM_DIR_DECRYPT;
359 sess->sam_sess_params.cipher_alg =
360 aead_map[aead_xform->aead.algo].cipher_alg;
361 sess->sam_sess_params.cipher_mode =
362 aead_map[aead_xform->aead.algo].cipher_mode;
364 /* Assume IV will be passed together with data. */
365 sess->sam_sess_params.cipher_iv = NULL;
367 /* Get max key length. */
368 if (aead_xform->aead.key.length >
369 aead_map[aead_xform->aead.algo].max_key_len) {
370 MRVL_LOG(ERR, "Wrong key length!");
374 aead_key = malloc(aead_xform->aead.key.length);
375 if (aead_key == NULL) {
376 MRVL_LOG(ERR, "Insufficient memory!");
380 memcpy(aead_key, aead_xform->aead.key.data,
381 aead_xform->aead.key.length);
383 sess->sam_sess_params.cipher_key = aead_key;
384 sess->sam_sess_params.cipher_key_len = aead_xform->aead.key.length;
386 if (sess->sam_sess_params.cipher_mode == SAM_CIPHER_GCM)
387 sess->sam_sess_params.auth_alg = SAM_AUTH_AES_GCM;
389 sess->sam_sess_params.u.basic.auth_icv_len =
390 aead_xform->aead.digest_length;
392 sess->sam_sess_params.u.basic.auth_aad_len =
393 aead_xform->aead.aad_length;
399 * Parse crypto transform chain and setup session parameters.
401 * @param dev Pointer to crypto device
402 * @param sess Poiner to crypto session
403 * @param xform Pointer to configuration structure chain for crypto operations.
404 * @returns 0 in case of success, negative value otherwise.
407 mrvl_crypto_set_session_parameters(struct mrvl_crypto_session *sess,
408 const struct rte_crypto_sym_xform *xform)
410 const struct rte_crypto_sym_xform *cipher_xform = NULL;
411 const struct rte_crypto_sym_xform *auth_xform = NULL;
412 const struct rte_crypto_sym_xform *aead_xform = NULL;
414 /* Filter out spurious/broken requests */
418 sess->chain_order = mrvl_crypto_get_chain_order(xform);
419 switch (sess->chain_order) {
420 case MRVL_CRYPTO_CHAIN_CIPHER_AUTH:
421 cipher_xform = xform;
422 auth_xform = xform->next;
424 case MRVL_CRYPTO_CHAIN_AUTH_CIPHER:
426 cipher_xform = xform->next;
428 case MRVL_CRYPTO_CHAIN_CIPHER_ONLY:
429 cipher_xform = xform;
431 case MRVL_CRYPTO_CHAIN_AUTH_ONLY:
434 case MRVL_CRYPTO_CHAIN_COMBINED:
441 if ((cipher_xform != NULL) &&
442 (mrvl_crypto_set_cipher_session_parameters(
443 sess, cipher_xform) < 0)) {
444 MRVL_LOG(ERR, "Invalid/unsupported cipher parameters!");
448 if ((auth_xform != NULL) &&
449 (mrvl_crypto_set_auth_session_parameters(
450 sess, auth_xform) < 0)) {
451 MRVL_LOG(ERR, "Invalid/unsupported auth parameters!");
455 if ((aead_xform != NULL) &&
456 (mrvl_crypto_set_aead_session_parameters(
457 sess, aead_xform) < 0)) {
458 MRVL_LOG(ERR, "Invalid/unsupported aead parameters!");
466 *-----------------------------------------------------------------------------
468 *-----------------------------------------------------------------------------
472 * Prepare a single request.
474 * This function basically translates DPDK crypto request into one
475 * understandable by MUDSK's SAM. If this is a first request in a session,
476 * it starts the session.
478 * @param request Pointer to pre-allocated && reset request buffer [Out].
479 * @param src_bd Pointer to pre-allocated source descriptor [Out].
480 * @param dst_bd Pointer to pre-allocated destination descriptor [Out].
481 * @param op Pointer to DPDK crypto operation struct [In].
484 mrvl_request_prepare(struct sam_cio_op_params *request,
485 struct sam_buf_info *src_bd,
486 struct sam_buf_info *dst_bd,
487 struct rte_crypto_op *op)
489 struct mrvl_crypto_session *sess;
490 struct rte_mbuf *src_mbuf, *dst_mbuf;
491 uint16_t segments_nb;
495 if (unlikely(op->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
496 MRVL_LOG(ERR, "MRVL CRYPTO PMD only supports session "
497 "oriented requests, op (%p) is sessionless!",
502 sess = (struct mrvl_crypto_session *)get_sym_session_private_data(
503 op->sym->session, cryptodev_driver_id);
504 if (unlikely(sess == NULL)) {
505 MRVL_LOG(ERR, "Session was not created for this device!");
509 request->sa = sess->sam_sess;
510 request->cookie = op;
512 src_mbuf = op->sym->m_src;
513 segments_nb = src_mbuf->nb_segs;
514 /* The following conditions must be met:
515 * - Destination buffer is required when segmented source buffer
516 * - Segmented destination buffer is not supported
518 if ((segments_nb > 1) && (!op->sym->m_dst)) {
519 MRVL_LOG(ERR, "op->sym->m_dst = NULL!");
523 * If application delivered us null dst buffer, it means it expects
524 * us to deliver the result in src buffer.
526 dst_mbuf = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;
528 if (!rte_pktmbuf_is_contiguous(dst_mbuf)) {
529 MRVL_LOG(ERR, "Segmented destination buffer not supported!");
533 request->num_bufs = segments_nb;
534 for (i = 0; i < segments_nb; i++) {
536 if (rte_pktmbuf_data_len(src_mbuf) == 0) {
537 /* EIP does not support 0 length buffers. */
538 MRVL_LOG(ERR, "Buffer length == 0 not supported!");
541 src_bd[i].vaddr = rte_pktmbuf_mtod(src_mbuf, void *);
542 src_bd[i].paddr = rte_pktmbuf_iova(src_mbuf);
543 src_bd[i].len = rte_pktmbuf_data_len(src_mbuf);
545 src_mbuf = src_mbuf->next;
547 request->src = src_bd;
549 /* Empty destination. */
550 if (rte_pktmbuf_data_len(dst_mbuf) == 0) {
551 /* Make dst buffer fit at least source data. */
552 if (rte_pktmbuf_append(dst_mbuf,
553 rte_pktmbuf_data_len(op->sym->m_src)) == NULL) {
554 MRVL_LOG(ERR, "Unable to set big enough dst buffer!");
559 request->dst = dst_bd;
560 dst_bd->vaddr = rte_pktmbuf_mtod(dst_mbuf, void *);
561 dst_bd->paddr = rte_pktmbuf_iova(dst_mbuf);
564 * We can use all available space in dst_mbuf,
565 * not only what's used currently.
567 dst_bd->len = dst_mbuf->buf_len - rte_pktmbuf_headroom(dst_mbuf);
569 if (sess->chain_order == MRVL_CRYPTO_CHAIN_COMBINED) {
570 request->cipher_len = op->sym->aead.data.length;
571 request->cipher_offset = op->sym->aead.data.offset;
572 request->cipher_iv = rte_crypto_op_ctod_offset(op, uint8_t *,
573 sess->cipher_iv_offset);
575 request->auth_aad = op->sym->aead.aad.data;
576 request->auth_offset = request->cipher_offset;
577 request->auth_len = request->cipher_len;
579 request->cipher_len = op->sym->cipher.data.length;
580 request->cipher_offset = op->sym->cipher.data.offset;
581 request->cipher_iv = rte_crypto_op_ctod_offset(op, uint8_t *,
582 sess->cipher_iv_offset);
584 request->auth_offset = op->sym->auth.data.offset;
585 request->auth_len = op->sym->auth.data.length;
588 digest = sess->chain_order == MRVL_CRYPTO_CHAIN_COMBINED ?
589 op->sym->aead.digest.data : op->sym->auth.digest.data;
590 if (digest == NULL) {
591 /* No auth - no worry. */
595 request->auth_icv_offset = request->auth_offset + request->auth_len;
598 * EIP supports only scenarios where ICV(digest buffer) is placed at
601 if (sess->sam_sess_params.dir == SAM_DIR_ENCRYPT) {
603 * This should be the most common case anyway,
604 * EIP will overwrite DST buffer at auth_icv_offset.
606 if (rte_pktmbuf_mtod_offset(
608 request->auth_icv_offset) == digest)
610 } else {/* sess->sam_sess_params.dir == SAM_DIR_DECRYPT */
612 * EIP will look for digest at auth_icv_offset
613 * offset in SRC buffer. It must be placed in the last
614 * segment and the offset must be set to reach digest
615 * in the last segment
617 struct rte_mbuf *last_seg = op->sym->m_src;
618 uint32_t d_offset = request->auth_icv_offset;
619 u32 d_size = sess->sam_sess_params.u.basic.auth_icv_len;
620 unsigned char *d_ptr;
622 /* Find the last segment and the offset for the last segment */
623 while ((last_seg->next != NULL) &&
624 (d_offset >= last_seg->data_len)) {
625 d_offset -= last_seg->data_len;
626 last_seg = last_seg->next;
629 if (rte_pktmbuf_mtod_offset(last_seg, uint8_t *,
633 /* copy digest to last segment */
634 if (last_seg->buf_len >= (d_size + d_offset)) {
635 d_ptr = (unsigned char *)last_seg->buf_addr +
637 rte_memcpy(d_ptr, digest, d_size);
643 * If we landed here it means that digest pointer is
644 * at different than expected place.
650 *-----------------------------------------------------------------------------
651 * PMD Framework handlers
652 *-----------------------------------------------------------------------------
658 * @param queue_pair Pointer to queue pair.
659 * @param ops Pointer to ops requests array.
660 * @param nb_ops Number of elements in ops requests array.
661 * @returns Number of elements consumed from ops.
664 mrvl_crypto_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
667 uint16_t iter_ops = 0;
669 uint16_t consumed = 0;
671 struct sam_cio_op_params requests[nb_ops];
673 * SAM does not store bd pointers, so on-stack scope will be enough.
675 struct mrvl_crypto_src_table src_bd[nb_ops];
676 struct sam_buf_info dst_bd[nb_ops];
677 struct mrvl_crypto_qp *qp = (struct mrvl_crypto_qp *)queue_pair;
682 /* Prepare the burst. */
683 memset(&requests, 0, sizeof(requests));
684 memset(&src_bd, 0, sizeof(src_bd));
686 /* Iterate through */
687 for (; iter_ops < nb_ops; ++iter_ops) {
688 /* store the op id for debug */
689 src_bd[iter_ops].iter_ops = iter_ops;
690 if (mrvl_request_prepare(&requests[iter_ops],
691 src_bd[iter_ops].src_bd,
693 ops[iter_ops]) < 0) {
694 MRVL_LOG(ERR, "Error while preparing parameters!");
695 qp->stats.enqueue_err_count++;
696 ops[iter_ops]->status = RTE_CRYPTO_OP_STATUS_ERROR;
699 * Number of handled ops is increased
700 * (even if the result of handling is error).
706 ops[iter_ops]->status =
707 RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
709 /* Increase the number of ops to enqueue. */
711 } /* for (; iter_ops < nb_ops;... */
715 ret = sam_cio_enq(qp->cio, requests, &to_enq);
719 * Trust SAM that in this case returned value will be at
720 * some point correct (now it is returned unmodified).
722 qp->stats.enqueue_err_count += to_enq;
723 for (iter_ops = 0; iter_ops < to_enq; ++iter_ops)
724 ops[iter_ops]->status =
725 RTE_CRYPTO_OP_STATUS_ERROR;
729 qp->stats.enqueued_count += to_enq;
736 * @param queue_pair Pointer to queue pair.
737 * @param ops Pointer to ops requests array.
738 * @param nb_ops Number of elements in ops requests array.
739 * @returns Number of elements dequeued.
742 mrvl_crypto_pmd_dequeue_burst(void *queue_pair,
743 struct rte_crypto_op **ops,
747 struct mrvl_crypto_qp *qp = queue_pair;
748 struct sam_cio *cio = qp->cio;
749 struct sam_cio_op_result results[nb_ops];
752 ret = sam_cio_deq(cio, results, &nb_ops);
754 /* Count all dequeued as error. */
755 qp->stats.dequeue_err_count += nb_ops;
757 /* But act as they were dequeued anyway*/
758 qp->stats.dequeued_count += nb_ops;
763 /* Unpack and check results. */
764 for (i = 0; i < nb_ops; ++i) {
765 ops[i] = results[i].cookie;
767 switch (results[i].status) {
769 ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
771 case SAM_CIO_ERR_ICV:
772 MRVL_LOG(DEBUG, "CIO returned SAM_CIO_ERR_ICV.");
773 ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
777 "CIO returned Error: %d.", results[i].status);
778 ops[i]->status = RTE_CRYPTO_OP_STATUS_ERROR;
783 qp->stats.dequeued_count += nb_ops;
788 * Create a new crypto device.
790 * @param name Driver name.
791 * @param vdev Pointer to device structure.
792 * @param init_params Pointer to initialization parameters.
793 * @returns 0 in case of success, negative value otherwise.
796 cryptodev_mrvl_crypto_create(const char *name,
797 struct rte_vdev_device *vdev,
798 struct mrvl_pmd_init_params *init_params)
800 struct rte_cryptodev *dev;
801 struct mrvl_crypto_private *internals;
802 struct sam_init_params sam_params;
805 dev = rte_cryptodev_pmd_create(name, &vdev->device,
806 &init_params->common);
808 MRVL_LOG(ERR, "Failed to create cryptodev vdev!");
812 dev->driver_id = cryptodev_driver_id;
813 dev->dev_ops = rte_mrvl_crypto_pmd_ops;
815 /* Register rx/tx burst functions for data path. */
816 dev->enqueue_burst = mrvl_crypto_pmd_enqueue_burst;
817 dev->dequeue_burst = mrvl_crypto_pmd_dequeue_burst;
819 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
820 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
821 RTE_CRYPTODEV_FF_HW_ACCELERATED |
822 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
823 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
825 internals = dev->data->dev_private;
827 internals->max_nb_qpairs = init_params->common.max_nb_queue_pairs;
828 internals->max_nb_sessions = init_params->max_nb_sessions;
830 ret = rte_mvep_init(MVEP_MOD_T_SAM, NULL);
834 sam_params.max_num_sessions = internals->max_nb_sessions;
836 /* sam_set_debug_flags(3); */
838 ret = sam_init(&sam_params);
846 "Driver %s: %s failed!", init_params->common.name, __func__);
848 cryptodev_mrvl_crypto_uninit(vdev);
852 /** Parse integer from integer argument */
854 parse_integer_arg(const char *key __rte_unused,
855 const char *value, void *extra_args)
857 int *i = (int *) extra_args;
861 MRVL_LOG(ERR, "Argument has to be positive!");
870 parse_name_arg(const char *key __rte_unused,
871 const char *value, void *extra_args)
873 struct rte_cryptodev_pmd_init_params *params = extra_args;
875 if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
876 MRVL_LOG(ERR, "Invalid name %s, should be less than %u bytes!",
877 value, RTE_CRYPTODEV_NAME_MAX_LEN - 1);
881 strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
887 mrvl_pmd_parse_input_args(struct mrvl_pmd_init_params *params,
888 const char *input_args)
890 struct rte_kvargs *kvlist = NULL;
897 kvlist = rte_kvargs_parse(input_args,
898 mrvl_pmd_valid_params);
902 /* Common VDEV parameters */
903 ret = rte_kvargs_process(kvlist,
904 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
906 ¶ms->common.max_nb_queue_pairs);
910 ret = rte_kvargs_process(kvlist,
911 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
913 ¶ms->common.socket_id);
917 ret = rte_kvargs_process(kvlist,
918 RTE_CRYPTODEV_PMD_NAME_ARG,
924 ret = rte_kvargs_process(kvlist,
925 MRVL_PMD_MAX_NB_SESS_ARG,
934 rte_kvargs_free(kvlist);
939 * Initialize the crypto device.
941 * @param vdev Pointer to device structure.
942 * @returns 0 in case of success, negative value otherwise.
945 cryptodev_mrvl_crypto_init(struct rte_vdev_device *vdev)
947 struct mrvl_pmd_init_params init_params = {
951 sizeof(struct mrvl_crypto_private),
952 .max_nb_queue_pairs =
953 sam_get_num_inst() * sam_get_num_cios(0),
954 .socket_id = rte_socket_id()
956 .max_nb_sessions = MRVL_PMD_DEFAULT_MAX_NB_SESSIONS
959 const char *name, *args;
962 name = rte_vdev_device_name(vdev);
965 args = rte_vdev_device_args(vdev);
967 ret = mrvl_pmd_parse_input_args(&init_params, args);
969 MRVL_LOG(ERR, "Failed to parse initialisation arguments[%s]!",
974 return cryptodev_mrvl_crypto_create(name, vdev, &init_params);
978 * Uninitialize the crypto device
980 * @param vdev Pointer to device structure.
981 * @returns 0 in case of success, negative value otherwise.
984 cryptodev_mrvl_crypto_uninit(struct rte_vdev_device *vdev)
986 struct rte_cryptodev *cryptodev;
987 const char *name = rte_vdev_device_name(vdev);
992 MRVL_LOG(INFO, "Closing Marvell crypto device %s on numa socket %u.",
993 name, rte_socket_id());
996 rte_mvep_deinit(MVEP_MOD_T_SAM);
998 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
999 if (cryptodev == NULL)
1002 return rte_cryptodev_pmd_destroy(cryptodev);
1006 * Basic driver handlers for use in the constructor.
1008 static struct rte_vdev_driver cryptodev_mrvl_pmd_drv = {
1009 .probe = cryptodev_mrvl_crypto_init,
1010 .remove = cryptodev_mrvl_crypto_uninit
1013 static struct cryptodev_driver mrvl_crypto_drv;
1015 /* Register the driver in constructor. */
1016 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_MRVL_PMD, cryptodev_mrvl_pmd_drv);
1017 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_MRVL_PMD,
1018 "max_nb_queue_pairs=<int> "
1019 "max_nb_sessions=<int> "
1021 RTE_PMD_REGISTER_CRYPTO_DRIVER(mrvl_crypto_drv, cryptodev_mrvl_pmd_drv.driver,
1022 cryptodev_driver_id);
1024 RTE_INIT(crypto_mrvl_init_log)
1026 mrvl_logtype_driver = rte_log_register("pmd.crypto.mvsam");