1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2017 Intel Corporation
5 #include <intel-ipsec-mb.h>
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>
15 #include "rte_aesni_mb_pmd_private.h"
17 static uint8_t cryptodev_driver_id;
19 typedef void (*hash_one_block_t)(const void *data, void *digest);
20 typedef void (*aes_keyexp_t)(const void *key, void *enc_exp_keys, void *dec_exp_keys);
23 * Calculate the authentication pre-computes
25 * @param one_block_hash Function pointer to calculate digest on ipad/opad
26 * @param ipad Inner pad output byte array
27 * @param opad Outer pad output byte array
28 * @param hkey Authentication key
29 * @param hkey_len Authentication key length
30 * @param blocksize Block size of selected hash algo
33 calculate_auth_precomputes(hash_one_block_t one_block_hash,
34 uint8_t *ipad, uint8_t *opad,
35 uint8_t *hkey, uint16_t hkey_len,
40 uint8_t ipad_buf[blocksize] __rte_aligned(16);
41 uint8_t opad_buf[blocksize] __rte_aligned(16);
43 /* Setup inner and outer pads */
44 memset(ipad_buf, HMAC_IPAD_VALUE, blocksize);
45 memset(opad_buf, HMAC_OPAD_VALUE, blocksize);
47 /* XOR hash key with inner and outer pads */
48 length = hkey_len > blocksize ? blocksize : hkey_len;
50 for (i = 0; i < length; i++) {
51 ipad_buf[i] ^= hkey[i];
52 opad_buf[i] ^= hkey[i];
55 /* Compute partial hashes */
56 (*one_block_hash)(ipad_buf, ipad);
57 (*one_block_hash)(opad_buf, opad);
60 memset(ipad_buf, 0, blocksize);
61 memset(opad_buf, 0, blocksize);
64 /** Get xform chain order */
65 static enum aesni_mb_operation
66 aesni_mb_get_chain_order(const struct rte_crypto_sym_xform *xform)
69 return AESNI_MB_OP_NOT_SUPPORTED;
71 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
72 if (xform->next == NULL)
73 return AESNI_MB_OP_CIPHER_ONLY;
74 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
75 return AESNI_MB_OP_CIPHER_HASH;
78 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
79 if (xform->next == NULL)
80 return AESNI_MB_OP_HASH_ONLY;
81 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
82 return AESNI_MB_OP_HASH_CIPHER;
85 if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
86 if (xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) {
87 if (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
88 return AESNI_MB_OP_AEAD_CIPHER_HASH;
90 return AESNI_MB_OP_AEAD_HASH_CIPHER;
94 return AESNI_MB_OP_NOT_SUPPORTED;
97 /** Set session authentication parameters */
99 aesni_mb_set_session_auth_parameters(const struct aesni_mb_op_fns *mb_ops,
100 struct aesni_mb_session *sess,
101 const struct rte_crypto_sym_xform *xform)
103 hash_one_block_t hash_oneblock_fn;
106 sess->auth.algo = NULL_HASH;
110 if (xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
111 MB_LOG_ERR("Crypto xform struct not of type auth");
115 /* Select auth generate/verify */
116 sess->auth.operation = xform->auth.op;
118 /* Set Authentication Parameters */
119 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
120 sess->auth.algo = AES_XCBC;
121 (*mb_ops->aux.keyexp.aes_xcbc)(xform->auth.key.data,
122 sess->auth.xcbc.k1_expanded,
123 sess->auth.xcbc.k2, sess->auth.xcbc.k3);
127 if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_CMAC) {
128 sess->auth.algo = AES_CMAC;
129 (*mb_ops->aux.keyexp.aes_cmac_expkey)(xform->auth.key.data,
130 sess->auth.cmac.expkey);
132 (*mb_ops->aux.keyexp.aes_cmac_subkey)(sess->auth.cmac.expkey,
133 sess->auth.cmac.skey1, sess->auth.cmac.skey2);
138 switch (xform->auth.algo) {
139 case RTE_CRYPTO_AUTH_MD5_HMAC:
140 sess->auth.algo = MD5;
141 hash_oneblock_fn = mb_ops->aux.one_block.md5;
143 case RTE_CRYPTO_AUTH_SHA1_HMAC:
144 sess->auth.algo = SHA1;
145 hash_oneblock_fn = mb_ops->aux.one_block.sha1;
147 case RTE_CRYPTO_AUTH_SHA224_HMAC:
148 sess->auth.algo = SHA_224;
149 hash_oneblock_fn = mb_ops->aux.one_block.sha224;
151 case RTE_CRYPTO_AUTH_SHA256_HMAC:
152 sess->auth.algo = SHA_256;
153 hash_oneblock_fn = mb_ops->aux.one_block.sha256;
155 case RTE_CRYPTO_AUTH_SHA384_HMAC:
156 sess->auth.algo = SHA_384;
157 hash_oneblock_fn = mb_ops->aux.one_block.sha384;
159 case RTE_CRYPTO_AUTH_SHA512_HMAC:
160 sess->auth.algo = SHA_512;
161 hash_oneblock_fn = mb_ops->aux.one_block.sha512;
164 MB_LOG_ERR("Unsupported authentication algorithm selection");
168 /* Calculate Authentication precomputes */
169 calculate_auth_precomputes(hash_oneblock_fn,
170 sess->auth.pads.inner, sess->auth.pads.outer,
171 xform->auth.key.data,
172 xform->auth.key.length,
173 get_auth_algo_blocksize(sess->auth.algo));
178 /** Set session cipher parameters */
180 aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
181 struct aesni_mb_session *sess,
182 const struct rte_crypto_sym_xform *xform)
185 aes_keyexp_t aes_keyexp_fn;
188 sess->cipher.mode = NULL_CIPHER;
192 if (xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
193 MB_LOG_ERR("Crypto xform struct not of type cipher");
197 /* Select cipher direction */
198 switch (xform->cipher.op) {
199 case RTE_CRYPTO_CIPHER_OP_ENCRYPT:
200 sess->cipher.direction = ENCRYPT;
202 case RTE_CRYPTO_CIPHER_OP_DECRYPT:
203 sess->cipher.direction = DECRYPT;
206 MB_LOG_ERR("Invalid cipher operation parameter");
210 /* Select cipher mode */
211 switch (xform->cipher.algo) {
212 case RTE_CRYPTO_CIPHER_AES_CBC:
213 sess->cipher.mode = CBC;
216 case RTE_CRYPTO_CIPHER_AES_CTR:
217 sess->cipher.mode = CNTR;
220 case RTE_CRYPTO_CIPHER_AES_DOCSISBPI:
221 sess->cipher.mode = DOCSIS_SEC_BPI;
224 case RTE_CRYPTO_CIPHER_DES_CBC:
225 sess->cipher.mode = DES;
227 case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
228 sess->cipher.mode = DOCSIS_DES;
231 MB_LOG_ERR("Unsupported cipher mode parameter");
235 /* Set IV parameters */
236 sess->iv.offset = xform->cipher.iv.offset;
237 sess->iv.length = xform->cipher.iv.length;
239 /* Check key length and choose key expansion function for AES */
241 switch (xform->cipher.key.length) {
243 sess->cipher.key_length_in_bytes = AES_128_BYTES;
244 aes_keyexp_fn = mb_ops->aux.keyexp.aes128;
247 sess->cipher.key_length_in_bytes = AES_192_BYTES;
248 aes_keyexp_fn = mb_ops->aux.keyexp.aes192;
251 sess->cipher.key_length_in_bytes = AES_256_BYTES;
252 aes_keyexp_fn = mb_ops->aux.keyexp.aes256;
255 MB_LOG_ERR("Invalid cipher key length");
259 /* Expanded cipher keys */
260 (*aes_keyexp_fn)(xform->cipher.key.data,
261 sess->cipher.expanded_aes_keys.encode,
262 sess->cipher.expanded_aes_keys.decode);
265 if (xform->cipher.key.length != 8) {
266 MB_LOG_ERR("Invalid cipher key length");
269 sess->cipher.key_length_in_bytes = 8;
271 des_key_schedule((uint64_t *)sess->cipher.expanded_aes_keys.encode,
272 xform->cipher.key.data);
273 des_key_schedule((uint64_t *)sess->cipher.expanded_aes_keys.decode,
274 xform->cipher.key.data);
281 aesni_mb_set_session_aead_parameters(const struct aesni_mb_op_fns *mb_ops,
282 struct aesni_mb_session *sess,
283 const struct rte_crypto_sym_xform *xform)
285 aes_keyexp_t aes_keyexp_fn;
287 switch (xform->aead.op) {
288 case RTE_CRYPTO_AEAD_OP_ENCRYPT:
289 sess->cipher.direction = ENCRYPT;
290 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
292 case RTE_CRYPTO_AEAD_OP_DECRYPT:
293 sess->cipher.direction = DECRYPT;
294 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
297 MB_LOG_ERR("Invalid aead operation parameter");
301 switch (xform->aead.algo) {
302 case RTE_CRYPTO_AEAD_AES_CCM:
303 sess->cipher.mode = CCM;
304 sess->auth.algo = AES_CCM;
307 MB_LOG_ERR("Unsupported aead mode parameter");
311 /* Set IV parameters */
312 sess->iv.offset = xform->aead.iv.offset;
313 sess->iv.length = xform->aead.iv.length;
315 /* Check key length and choose key expansion function for AES */
317 switch (xform->aead.key.length) {
319 sess->cipher.key_length_in_bytes = AES_128_BYTES;
320 aes_keyexp_fn = mb_ops->aux.keyexp.aes128;
323 MB_LOG_ERR("Invalid cipher key length");
327 /* Expanded cipher keys */
328 (*aes_keyexp_fn)(xform->aead.key.data,
329 sess->cipher.expanded_aes_keys.encode,
330 sess->cipher.expanded_aes_keys.decode);
335 /** Parse crypto xform chain and set private session parameters */
337 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
338 struct aesni_mb_session *sess,
339 const struct rte_crypto_sym_xform *xform)
341 const struct rte_crypto_sym_xform *auth_xform = NULL;
342 const struct rte_crypto_sym_xform *cipher_xform = NULL;
343 const struct rte_crypto_sym_xform *aead_xform = NULL;
346 /* Select Crypto operation - hash then cipher / cipher then hash */
347 switch (aesni_mb_get_chain_order(xform)) {
348 case AESNI_MB_OP_HASH_CIPHER:
349 sess->chain_order = HASH_CIPHER;
351 cipher_xform = xform->next;
352 sess->auth.digest_len = xform->auth.digest_length;
354 case AESNI_MB_OP_CIPHER_HASH:
355 sess->chain_order = CIPHER_HASH;
356 auth_xform = xform->next;
357 cipher_xform = xform;
358 sess->auth.digest_len = xform->auth.digest_length;
360 case AESNI_MB_OP_HASH_ONLY:
361 sess->chain_order = HASH_CIPHER;
364 sess->auth.digest_len = xform->auth.digest_length;
366 case AESNI_MB_OP_CIPHER_ONLY:
368 * Multi buffer library operates only at two modes,
369 * CIPHER_HASH and HASH_CIPHER. When doing ciphering only,
370 * chain order depends on cipher operation: encryption is always
371 * the first operation and decryption the last one.
373 if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
374 sess->chain_order = CIPHER_HASH;
376 sess->chain_order = HASH_CIPHER;
378 cipher_xform = xform;
380 case AESNI_MB_OP_AEAD_CIPHER_HASH:
381 sess->chain_order = CIPHER_HASH;
382 sess->aead.aad_len = xform->aead.aad_length;
383 sess->auth.digest_len = xform->aead.digest_length;
386 case AESNI_MB_OP_AEAD_HASH_CIPHER:
387 sess->chain_order = HASH_CIPHER;
388 sess->aead.aad_len = xform->aead.aad_length;
389 sess->auth.digest_len = xform->aead.digest_length;
392 case AESNI_MB_OP_NOT_SUPPORTED:
394 MB_LOG_ERR("Unsupported operation chain order parameter");
398 /* Default IV length = 0 */
401 ret = aesni_mb_set_session_auth_parameters(mb_ops, sess, auth_xform);
403 MB_LOG_ERR("Invalid/unsupported authentication parameters");
407 ret = aesni_mb_set_session_cipher_parameters(mb_ops, sess,
410 MB_LOG_ERR("Invalid/unsupported cipher parameters");
415 ret = aesni_mb_set_session_aead_parameters(mb_ops, sess,
418 MB_LOG_ERR("Invalid/unsupported aead parameters");
427 * burst enqueue, place crypto operations on ingress queue for processing.
429 * @param __qp Queue Pair to process
430 * @param ops Crypto operations for processing
431 * @param nb_ops Number of crypto operations for processing
434 * - Number of crypto operations enqueued
437 aesni_mb_pmd_enqueue_burst(void *__qp, struct rte_crypto_op **ops,
440 struct aesni_mb_qp *qp = __qp;
442 unsigned int nb_enqueued;
444 nb_enqueued = rte_ring_enqueue_burst(qp->ingress_queue,
445 (void **)ops, nb_ops, NULL);
447 qp->stats.enqueued_count += nb_enqueued;
452 /** Get multi buffer session */
453 static inline struct aesni_mb_session *
454 get_session(struct aesni_mb_qp *qp, struct rte_crypto_op *op)
456 struct aesni_mb_session *sess = NULL;
458 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
459 if (likely(op->sym->session != NULL))
460 sess = (struct aesni_mb_session *)
461 get_session_private_data(
463 cryptodev_driver_id);
466 void *_sess_private_data = NULL;
468 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
471 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
474 sess = (struct aesni_mb_session *)_sess_private_data;
476 if (unlikely(aesni_mb_set_session_parameters(qp->op_fns,
477 sess, op->sym->xform) != 0)) {
478 rte_mempool_put(qp->sess_mp, _sess);
479 rte_mempool_put(qp->sess_mp, _sess_private_data);
482 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
483 set_session_private_data(op->sym->session, cryptodev_driver_id,
487 if (unlikely(sess == NULL))
488 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
494 * Process a crypto operation and complete a JOB_AES_HMAC job structure for
495 * submission to the multi buffer library for processing.
497 * @param qp queue pair
498 * @param job JOB_AES_HMAC structure to fill
499 * @param m mbuf to process
502 * - Completed JOB_AES_HMAC structure pointer on success
503 * - NULL pointer if completion of JOB_AES_HMAC structure isn't possible
506 set_mb_job_params(JOB_AES_HMAC *job, struct aesni_mb_qp *qp,
507 struct rte_crypto_op *op, uint8_t *digest_idx)
509 struct rte_mbuf *m_src = op->sym->m_src, *m_dst;
510 struct aesni_mb_session *session;
511 uint16_t m_offset = 0;
513 session = get_session(qp, op);
514 if (session == NULL) {
515 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
519 /* Set crypto operation */
520 job->chain_order = session->chain_order;
522 /* Set cipher parameters */
523 job->cipher_direction = session->cipher.direction;
524 job->cipher_mode = session->cipher.mode;
526 job->aes_key_len_in_bytes = session->cipher.key_length_in_bytes;
527 job->aes_enc_key_expanded = session->cipher.expanded_aes_keys.encode;
528 job->aes_dec_key_expanded = session->cipher.expanded_aes_keys.decode;
531 /* Set authentication parameters */
532 job->hash_alg = session->auth.algo;
533 if (job->hash_alg == AES_XCBC) {
534 job->u.XCBC._k1_expanded = session->auth.xcbc.k1_expanded;
535 job->u.XCBC._k2 = session->auth.xcbc.k2;
536 job->u.XCBC._k3 = session->auth.xcbc.k3;
537 } else if (job->hash_alg == AES_CCM) {
538 job->u.CCM.aad = op->sym->aead.aad.data + 18;
539 job->u.CCM.aad_len_in_bytes = session->aead.aad_len;
540 } else if (job->hash_alg == AES_CMAC) {
541 job->u.CMAC._key_expanded = session->auth.cmac.expkey;
542 job->u.CMAC._skey1 = session->auth.cmac.skey1;
543 job->u.CMAC._skey2 = session->auth.cmac.skey2;
546 job->u.HMAC._hashed_auth_key_xor_ipad = session->auth.pads.inner;
547 job->u.HMAC._hashed_auth_key_xor_opad = session->auth.pads.outer;
550 /* Mutable crypto operation parameters */
551 if (op->sym->m_dst) {
552 m_src = m_dst = op->sym->m_dst;
554 /* append space for output data to mbuf */
555 char *odata = rte_pktmbuf_append(m_dst,
556 rte_pktmbuf_data_len(op->sym->m_src));
558 MB_LOG_ERR("failed to allocate space in destination "
559 "mbuf for source data");
560 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
564 memcpy(odata, rte_pktmbuf_mtod(op->sym->m_src, void*),
565 rte_pktmbuf_data_len(op->sym->m_src));
568 if (job->hash_alg == AES_CCM)
569 m_offset = op->sym->aead.data.offset;
571 m_offset = op->sym->cipher.data.offset;
574 /* Set digest output location */
575 if (job->hash_alg != NULL_HASH &&
576 session->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
577 job->auth_tag_output = qp->temp_digests[*digest_idx];
578 *digest_idx = (*digest_idx + 1) % MAX_JOBS;
580 if (job->hash_alg == AES_CCM)
581 job->auth_tag_output = op->sym->aead.digest.data;
583 job->auth_tag_output = op->sym->auth.digest.data;
587 * Multi-buffer library current only support returning a truncated
588 * digest length as specified in the relevant IPsec RFCs
590 if (job->hash_alg != AES_CCM && job->hash_alg != AES_CMAC)
591 job->auth_tag_output_len_in_bytes =
592 get_truncated_digest_byte_length(job->hash_alg);
594 job->auth_tag_output_len_in_bytes = session->auth.digest_len;
597 /* Set IV parameters */
599 job->iv_len_in_bytes = session->iv.length;
602 job->src = rte_pktmbuf_mtod(m_src, uint8_t *);
603 job->dst = rte_pktmbuf_mtod_offset(m_dst, uint8_t *, m_offset);
605 if (job->hash_alg == AES_CCM) {
606 job->cipher_start_src_offset_in_bytes =
607 op->sym->aead.data.offset;
608 job->msg_len_to_cipher_in_bytes = op->sym->aead.data.length;
609 job->hash_start_src_offset_in_bytes = op->sym->aead.data.offset;
610 job->msg_len_to_hash_in_bytes = op->sym->aead.data.length;
612 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
613 session->iv.offset + 1);
615 job->cipher_start_src_offset_in_bytes =
616 op->sym->cipher.data.offset;
617 job->msg_len_to_cipher_in_bytes = op->sym->cipher.data.length;
619 job->hash_start_src_offset_in_bytes = op->sym->auth.data.offset;
620 job->msg_len_to_hash_in_bytes = op->sym->auth.data.length;
622 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
626 /* Set user data to be crypto operation data struct */
633 verify_digest(struct aesni_mb_qp *qp __rte_unused, JOB_AES_HMAC *job,
634 struct rte_crypto_op *op) {
635 /* Verify digest if required */
636 if (job->hash_alg == AES_CCM) {
637 if (memcmp(job->auth_tag_output, op->sym->aead.digest.data,
638 job->auth_tag_output_len_in_bytes) != 0)
639 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
641 if (memcmp(job->auth_tag_output, op->sym->auth.digest.data,
642 job->auth_tag_output_len_in_bytes) != 0)
643 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
648 * Process a completed job and return rte_mbuf which job processed
650 * @param qp Queue Pair to process
651 * @param job JOB_AES_HMAC job to process
654 * - Returns processed crypto operation.
655 * - Returns NULL on invalid job
657 static inline struct rte_crypto_op *
658 post_process_mb_job(struct aesni_mb_qp *qp, JOB_AES_HMAC *job)
660 struct rte_crypto_op *op = (struct rte_crypto_op *)job->user_data;
661 struct aesni_mb_session *sess = get_session_private_data(
663 cryptodev_driver_id);
665 if (likely(op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)) {
666 switch (job->status) {
668 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
670 if (job->hash_alg != NULL_HASH) {
671 if (sess->auth.operation ==
672 RTE_CRYPTO_AUTH_OP_VERIFY)
673 verify_digest(qp, job, op);
677 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
681 /* Free session if a session-less crypto op */
682 if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
683 memset(sess, 0, sizeof(struct aesni_mb_session));
684 memset(op->sym->session, 0,
685 rte_cryptodev_sym_get_header_session_size());
686 rte_mempool_put(qp->sess_mp, sess);
687 rte_mempool_put(qp->sess_mp, op->sym->session);
688 op->sym->session = NULL;
695 * Process a completed JOB_AES_HMAC job and keep processing jobs until
696 * get_completed_job return NULL
698 * @param qp Queue Pair to process
699 * @param job JOB_AES_HMAC job
702 * - Number of processed jobs
705 handle_completed_jobs(struct aesni_mb_qp *qp, JOB_AES_HMAC *job,
706 struct rte_crypto_op **ops, uint16_t nb_ops)
708 struct rte_crypto_op *op = NULL;
709 unsigned processed_jobs = 0;
711 while (job != NULL) {
712 op = post_process_mb_job(qp, job);
715 ops[processed_jobs++] = op;
716 qp->stats.dequeued_count++;
718 qp->stats.dequeue_err_count++;
721 if (processed_jobs == nb_ops)
724 job = (*qp->op_fns->job.get_completed_job)(&qp->mb_mgr);
727 return processed_jobs;
730 static inline uint16_t
731 flush_mb_mgr(struct aesni_mb_qp *qp, struct rte_crypto_op **ops,
734 int processed_ops = 0;
736 /* Flush the remaining jobs */
737 JOB_AES_HMAC *job = (*qp->op_fns->job.flush_job)(&qp->mb_mgr);
740 processed_ops += handle_completed_jobs(qp, job,
741 &ops[processed_ops], nb_ops - processed_ops);
743 return processed_ops;
746 static inline JOB_AES_HMAC *
747 set_job_null_op(JOB_AES_HMAC *job, struct rte_crypto_op *op)
749 job->chain_order = HASH_CIPHER;
750 job->cipher_mode = NULL_CIPHER;
751 job->hash_alg = NULL_HASH;
752 job->cipher_direction = DECRYPT;
754 /* Set user data to be crypto operation data struct */
761 aesni_mb_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
764 struct aesni_mb_qp *qp = queue_pair;
766 struct rte_crypto_op *op;
769 int retval, processed_jobs = 0;
771 if (unlikely(nb_ops == 0))
774 uint8_t digest_idx = qp->digest_idx;
776 /* Get next operation to process from ingress queue */
777 retval = rte_ring_dequeue(qp->ingress_queue, (void **)&op);
781 /* Get next free mb job struct from mb manager */
782 job = (*qp->op_fns->job.get_next)(&qp->mb_mgr);
783 if (unlikely(job == NULL)) {
784 /* if no free mb job structs we need to flush mb_mgr */
785 processed_jobs += flush_mb_mgr(qp,
786 &ops[processed_jobs],
787 (nb_ops - processed_jobs) - 1);
789 job = (*qp->op_fns->job.get_next)(&qp->mb_mgr);
792 retval = set_mb_job_params(job, qp, op, &digest_idx);
793 if (unlikely(retval != 0)) {
794 qp->stats.dequeue_err_count++;
795 set_job_null_op(job, op);
798 /* Submit job to multi-buffer for processing */
799 job = (*qp->op_fns->job.submit)(&qp->mb_mgr);
802 * If submit returns a processed job then handle it,
803 * before submitting subsequent jobs
806 processed_jobs += handle_completed_jobs(qp, job,
807 &ops[processed_jobs],
808 nb_ops - processed_jobs);
810 } while (processed_jobs < nb_ops);
812 qp->digest_idx = digest_idx;
814 if (processed_jobs < 1)
815 processed_jobs += flush_mb_mgr(qp,
816 &ops[processed_jobs],
817 nb_ops - processed_jobs);
819 return processed_jobs;
822 static int cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev);
825 cryptodev_aesni_mb_create(const char *name,
826 struct rte_vdev_device *vdev,
827 struct rte_cryptodev_pmd_init_params *init_params)
829 struct rte_cryptodev *dev;
830 struct aesni_mb_private *internals;
831 enum aesni_mb_vector_mode vector_mode;
833 /* Check CPU for support for AES instruction set */
834 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
835 MB_LOG_ERR("AES instructions not supported by CPU");
839 dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
841 MB_LOG_ERR("failed to create cryptodev vdev");
845 /* Check CPU for supported vector instruction set */
846 if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F))
847 vector_mode = RTE_AESNI_MB_AVX512;
848 else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
849 vector_mode = RTE_AESNI_MB_AVX2;
850 else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX))
851 vector_mode = RTE_AESNI_MB_AVX;
853 vector_mode = RTE_AESNI_MB_SSE;
855 dev->driver_id = cryptodev_driver_id;
856 dev->dev_ops = rte_aesni_mb_pmd_ops;
858 /* register rx/tx burst functions for data path */
859 dev->dequeue_burst = aesni_mb_pmd_dequeue_burst;
860 dev->enqueue_burst = aesni_mb_pmd_enqueue_burst;
862 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
863 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
864 RTE_CRYPTODEV_FF_CPU_AESNI;
866 switch (vector_mode) {
867 case RTE_AESNI_MB_SSE:
868 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
870 case RTE_AESNI_MB_AVX:
871 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX;
873 case RTE_AESNI_MB_AVX2:
874 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX2;
876 case RTE_AESNI_MB_AVX512:
877 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX512;
883 /* Set vector instructions mode supported */
884 internals = dev->data->dev_private;
886 internals->vector_mode = vector_mode;
887 internals->max_nb_queue_pairs = init_params->max_nb_queue_pairs;
888 internals->max_nb_sessions = init_params->max_nb_sessions;
894 cryptodev_aesni_mb_probe(struct rte_vdev_device *vdev)
896 struct rte_cryptodev_pmd_init_params init_params = {
898 sizeof(struct aesni_mb_private),
900 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS,
901 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS
903 const char *name, *args;
906 name = rte_vdev_device_name(vdev);
910 args = rte_vdev_device_args(vdev);
912 retval = rte_cryptodev_pmd_parse_input_args(&init_params, args);
914 MB_LOG_ERR("Failed to parse initialisation arguments[%s]\n",
919 return cryptodev_aesni_mb_create(name, vdev, &init_params);
923 cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev)
925 struct rte_cryptodev *cryptodev;
928 name = rte_vdev_device_name(vdev);
932 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
933 if (cryptodev == NULL)
936 return rte_cryptodev_pmd_destroy(cryptodev);
939 static struct rte_vdev_driver cryptodev_aesni_mb_pmd_drv = {
940 .probe = cryptodev_aesni_mb_probe,
941 .remove = cryptodev_aesni_mb_remove
944 static struct cryptodev_driver aesni_mb_crypto_drv;
946 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_AESNI_MB_PMD, cryptodev_aesni_mb_pmd_drv);
947 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_AESNI_MB_PMD, cryptodev_aesni_mb_pmd);
948 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_MB_PMD,
949 "max_nb_queue_pairs=<int> "
950 "max_nb_sessions=<int> "
952 RTE_PMD_REGISTER_CRYPTO_DRIVER(aesni_mb_crypto_drv,
953 cryptodev_aesni_mb_pmd_drv.driver,
954 cryptodev_driver_id);