4 * Copyright (C) Cavium networks Ltd. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_common.h>
36 #include <rte_hexdump.h>
37 #include <rte_cryptodev.h>
38 #include <rte_cryptodev_pmd.h>
40 #include <rte_malloc.h>
41 #include <rte_cpuflags.h>
43 #include "armv8_crypto_defs.h"
45 #include "rte_armv8_pmd_private.h"
47 static int cryptodev_armv8_crypto_uninit(struct rte_vdev_device *vdev);
50 * Pointers to the supported combined mode crypto functions are stored
51 * in the static tables. Each combined (chained) cryptographic operation
52 * can be described by a set of numbers:
53 * - order: order of operations (cipher, auth) or (auth, cipher)
54 * - direction: encryption or decryption
55 * - calg: cipher algorithm such as AES_CBC, AES_CTR, etc.
56 * - aalg: authentication algorithm such as SHA1, SHA256, etc.
57 * - keyl: cipher key length, for example 128, 192, 256 bits
59 * In order to quickly acquire each function pointer based on those numbers,
60 * a hierarchy of arrays is maintained. The final level, 3D array is indexed
61 * by the combined mode function parameters only (cipher algorithm,
62 * authentication algorithm and key length).
64 * This gives 3 memory accesses to obtain a function pointer instead of
65 * traversing the array manually and comparing function parameters on each loop.
79 * 3D array type for ARM Combined Mode crypto functions pointers.
80 * CRYPTO_CIPHER_MAX: max cipher ID number
81 * CRYPTO_AUTH_MAX: max auth ID number
82 * CRYPTO_CIPHER_KEYLEN_MAX: max key length ID number
84 typedef const crypto_func_t
85 crypto_func_tbl_t[CRYPTO_CIPHER_MAX][CRYPTO_AUTH_MAX][CRYPTO_CIPHER_KEYLEN_MAX];
87 /* Evaluate to key length definition */
88 #define KEYL(keyl) (ARMV8_CRYPTO_CIPHER_KEYLEN_ ## keyl)
90 /* Local aliases for supported ciphers */
91 #define CIPH_AES_CBC RTE_CRYPTO_CIPHER_AES_CBC
92 /* Local aliases for supported hashes */
93 #define AUTH_SHA1_HMAC RTE_CRYPTO_AUTH_SHA1_HMAC
94 #define AUTH_SHA256_HMAC RTE_CRYPTO_AUTH_SHA256_HMAC
97 * Arrays containing pointers to particular cryptographic,
98 * combined mode functions.
99 * crypto_op_ca_encrypt: cipher (encrypt), authenticate
100 * crypto_op_ca_decrypt: cipher (decrypt), authenticate
101 * crypto_op_ac_encrypt: authenticate, cipher (encrypt)
102 * crypto_op_ac_decrypt: authenticate, cipher (decrypt)
104 static const crypto_func_tbl_t
105 crypto_op_ca_encrypt = {
106 /* [cipher alg][auth alg][key length] = crypto_function, */
107 [CIPH_AES_CBC][AUTH_SHA1_HMAC][KEYL(128)] = aes128cbc_sha1_hmac,
108 [CIPH_AES_CBC][AUTH_SHA256_HMAC][KEYL(128)] = aes128cbc_sha256_hmac,
111 static const crypto_func_tbl_t
112 crypto_op_ca_decrypt = {
116 static const crypto_func_tbl_t
117 crypto_op_ac_encrypt = {
121 static const crypto_func_tbl_t
122 crypto_op_ac_decrypt = {
123 /* [cipher alg][auth alg][key length] = crypto_function, */
124 [CIPH_AES_CBC][AUTH_SHA1_HMAC][KEYL(128)] = sha1_hmac_aes128cbc_dec,
125 [CIPH_AES_CBC][AUTH_SHA256_HMAC][KEYL(128)] = sha256_hmac_aes128cbc_dec,
129 * Arrays containing pointers to particular cryptographic function sets,
130 * covering given cipher operation directions (encrypt, decrypt)
131 * for each order of cipher and authentication pairs.
133 static const crypto_func_tbl_t *
134 crypto_cipher_auth[] = {
135 &crypto_op_ca_encrypt,
136 &crypto_op_ca_decrypt,
140 static const crypto_func_tbl_t *
141 crypto_auth_cipher[] = {
142 &crypto_op_ac_encrypt,
143 &crypto_op_ac_decrypt,
148 * Top level array containing pointers to particular cryptographic
149 * function sets, covering given order of chained operations.
150 * crypto_cipher_auth: cipher first, authenticate after
151 * crypto_auth_cipher: authenticate first, cipher after
153 static const crypto_func_tbl_t **
154 crypto_chain_order[] = {
161 * Extract particular combined mode crypto function from the 3D array.
163 #define CRYPTO_GET_ALGO(order, cop, calg, aalg, keyl) \
165 crypto_func_tbl_t *func_tbl = \
166 (crypto_chain_order[(order)])[(cop)]; \
168 ((*func_tbl)[(calg)][(aalg)][KEYL(keyl)]); \
171 /*----------------------------------------------------------------------------*/
174 * 2D array type for ARM key schedule functions pointers.
175 * CRYPTO_CIPHER_MAX: max cipher ID number
176 * CRYPTO_CIPHER_KEYLEN_MAX: max key length ID number
178 typedef const crypto_key_sched_t
179 crypto_key_sched_tbl_t[CRYPTO_CIPHER_MAX][CRYPTO_CIPHER_KEYLEN_MAX];
181 static const crypto_key_sched_tbl_t
182 crypto_key_sched_encrypt = {
183 /* [cipher alg][key length] = key_expand_func, */
184 [CIPH_AES_CBC][KEYL(128)] = aes128_key_sched_enc,
187 static const crypto_key_sched_tbl_t
188 crypto_key_sched_decrypt = {
189 /* [cipher alg][key length] = key_expand_func, */
190 [CIPH_AES_CBC][KEYL(128)] = aes128_key_sched_dec,
194 * Top level array containing pointers to particular key generation
195 * function sets, covering given operation direction.
196 * crypto_key_sched_encrypt: keys for encryption
197 * crypto_key_sched_decrypt: keys for decryption
199 static const crypto_key_sched_tbl_t *
200 crypto_key_sched_dir[] = {
201 &crypto_key_sched_encrypt,
202 &crypto_key_sched_decrypt,
207 * Extract particular combined mode crypto function from the 3D array.
209 #define CRYPTO_GET_KEY_SCHED(cop, calg, keyl) \
211 crypto_key_sched_tbl_t *ks_tbl = crypto_key_sched_dir[(cop)]; \
213 ((*ks_tbl)[(calg)][KEYL(keyl)]); \
216 /*----------------------------------------------------------------------------*/
219 *------------------------------------------------------------------------------
221 *------------------------------------------------------------------------------
224 /** Get xform chain order */
225 static enum armv8_crypto_chain_order
226 armv8_crypto_get_chain_order(const struct rte_crypto_sym_xform *xform)
230 * This driver currently covers only chained operations.
231 * Ignore only cipher or only authentication operations
232 * or chains longer than 2 xform structures.
234 if (xform->next == NULL || xform->next->next != NULL)
235 return ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED;
237 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
238 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
239 return ARMV8_CRYPTO_CHAIN_AUTH_CIPHER;
242 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
243 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
244 return ARMV8_CRYPTO_CHAIN_CIPHER_AUTH;
247 return ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED;
251 auth_hmac_pad_prepare(struct armv8_crypto_session *sess,
252 const struct rte_crypto_sym_xform *xform)
256 /* Generate i_key_pad and o_key_pad */
257 memset(sess->auth.hmac.i_key_pad, 0, sizeof(sess->auth.hmac.i_key_pad));
258 rte_memcpy(sess->auth.hmac.i_key_pad, sess->auth.hmac.key,
259 xform->auth.key.length);
260 memset(sess->auth.hmac.o_key_pad, 0, sizeof(sess->auth.hmac.o_key_pad));
261 rte_memcpy(sess->auth.hmac.o_key_pad, sess->auth.hmac.key,
262 xform->auth.key.length);
264 * XOR key with IPAD/OPAD values to obtain i_key_pad
266 * Byte-by-byte operation may seem to be the less efficient
267 * here but in fact it's the opposite.
268 * The result ASM code is likely operate on NEON registers
269 * (load auth key to Qx, load IPAD/OPAD to multiple
270 * elements of Qy, eor 128 bits at once).
272 for (i = 0; i < SHA_BLOCK_MAX; i++) {
273 sess->auth.hmac.i_key_pad[i] ^= HMAC_IPAD_VALUE;
274 sess->auth.hmac.o_key_pad[i] ^= HMAC_OPAD_VALUE;
279 auth_set_prerequisites(struct armv8_crypto_session *sess,
280 const struct rte_crypto_sym_xform *xform)
282 uint8_t partial[64] = { 0 };
285 switch (xform->auth.algo) {
286 case RTE_CRYPTO_AUTH_SHA1_HMAC:
288 * Generate authentication key, i_key_pad and o_key_pad.
290 /* Zero memory under key */
291 memset(sess->auth.hmac.key, 0, SHA1_AUTH_KEY_LENGTH);
293 if (xform->auth.key.length > SHA1_AUTH_KEY_LENGTH) {
295 * In case the key is longer than 160 bits
296 * the algorithm will use SHA1(key) instead.
298 error = sha1_block(NULL, xform->auth.key.data,
299 sess->auth.hmac.key, xform->auth.key.length);
304 * Now copy the given authentication key to the session
305 * key assuming that the session key is zeroed there is
306 * no need for additional zero padding if the key is
307 * shorter than SHA1_AUTH_KEY_LENGTH.
309 rte_memcpy(sess->auth.hmac.key, xform->auth.key.data,
310 xform->auth.key.length);
313 /* Prepare HMAC padding: key|pattern */
314 auth_hmac_pad_prepare(sess, xform);
316 * Calculate partial hash values for i_key_pad and o_key_pad.
317 * Will be used as initialization state for final HMAC.
319 error = sha1_block_partial(NULL, sess->auth.hmac.i_key_pad,
320 partial, SHA1_BLOCK_SIZE);
323 memcpy(sess->auth.hmac.i_key_pad, partial, SHA1_BLOCK_SIZE);
325 error = sha1_block_partial(NULL, sess->auth.hmac.o_key_pad,
326 partial, SHA1_BLOCK_SIZE);
329 memcpy(sess->auth.hmac.o_key_pad, partial, SHA1_BLOCK_SIZE);
332 case RTE_CRYPTO_AUTH_SHA256_HMAC:
334 * Generate authentication key, i_key_pad and o_key_pad.
336 /* Zero memory under key */
337 memset(sess->auth.hmac.key, 0, SHA256_AUTH_KEY_LENGTH);
339 if (xform->auth.key.length > SHA256_AUTH_KEY_LENGTH) {
341 * In case the key is longer than 256 bits
342 * the algorithm will use SHA256(key) instead.
344 error = sha256_block(NULL, xform->auth.key.data,
345 sess->auth.hmac.key, xform->auth.key.length);
350 * Now copy the given authentication key to the session
351 * key assuming that the session key is zeroed there is
352 * no need for additional zero padding if the key is
353 * shorter than SHA256_AUTH_KEY_LENGTH.
355 rte_memcpy(sess->auth.hmac.key, xform->auth.key.data,
356 xform->auth.key.length);
359 /* Prepare HMAC padding: key|pattern */
360 auth_hmac_pad_prepare(sess, xform);
362 * Calculate partial hash values for i_key_pad and o_key_pad.
363 * Will be used as initialization state for final HMAC.
365 error = sha256_block_partial(NULL, sess->auth.hmac.i_key_pad,
366 partial, SHA256_BLOCK_SIZE);
369 memcpy(sess->auth.hmac.i_key_pad, partial, SHA256_BLOCK_SIZE);
371 error = sha256_block_partial(NULL, sess->auth.hmac.o_key_pad,
372 partial, SHA256_BLOCK_SIZE);
375 memcpy(sess->auth.hmac.o_key_pad, partial, SHA256_BLOCK_SIZE);
386 cipher_set_prerequisites(struct armv8_crypto_session *sess,
387 const struct rte_crypto_sym_xform *xform)
389 crypto_key_sched_t cipher_key_sched;
391 cipher_key_sched = sess->cipher.key_sched;
392 if (likely(cipher_key_sched != NULL)) {
393 /* Set up cipher session key */
394 cipher_key_sched(sess->cipher.key.data, xform->cipher.key.data);
401 armv8_crypto_set_session_chained_parameters(struct armv8_crypto_session *sess,
402 const struct rte_crypto_sym_xform *cipher_xform,
403 const struct rte_crypto_sym_xform *auth_xform)
405 enum armv8_crypto_chain_order order;
406 enum armv8_crypto_cipher_operation cop;
407 enum rte_crypto_cipher_algorithm calg;
408 enum rte_crypto_auth_algorithm aalg;
410 /* Validate and prepare scratch order of combined operations */
411 switch (sess->chain_order) {
412 case ARMV8_CRYPTO_CHAIN_CIPHER_AUTH:
413 case ARMV8_CRYPTO_CHAIN_AUTH_CIPHER:
414 order = sess->chain_order;
419 /* Select cipher direction */
420 sess->cipher.direction = cipher_xform->cipher.op;
421 /* Select cipher key */
422 sess->cipher.key.length = cipher_xform->cipher.key.length;
423 /* Set cipher direction */
424 cop = sess->cipher.direction;
425 /* Set cipher algorithm */
426 calg = cipher_xform->cipher.algo;
428 /* Select cipher algo */
430 /* Cover supported cipher algorithms */
431 case RTE_CRYPTO_CIPHER_AES_CBC:
432 sess->cipher.algo = calg;
433 /* IV len is always 16 bytes (block size) for AES CBC */
434 sess->cipher.iv_len = 16;
439 /* Select auth generate/verify */
440 sess->auth.operation = auth_xform->auth.op;
442 /* Select auth algo */
443 switch (auth_xform->auth.algo) {
444 /* Cover supported hash algorithms */
445 case RTE_CRYPTO_AUTH_SHA1_HMAC:
446 case RTE_CRYPTO_AUTH_SHA256_HMAC: /* Fall through */
447 aalg = auth_xform->auth.algo;
448 sess->auth.mode = ARMV8_CRYPTO_AUTH_AS_HMAC;
454 /* Verify supported key lengths and extract proper algorithm */
455 switch (cipher_xform->cipher.key.length << 3) {
458 CRYPTO_GET_ALGO(order, cop, calg, aalg, 128);
459 sess->cipher.key_sched =
460 CRYPTO_GET_KEY_SCHED(cop, calg, 128);
464 /* These key lengths are not supported yet */
465 default: /* Fall through */
466 sess->crypto_func = NULL;
467 sess->cipher.key_sched = NULL;
471 if (unlikely(sess->crypto_func == NULL)) {
473 * If we got here that means that there must be a bug
474 * in the algorithms selection above. Nevertheless keep
475 * it here to catch bug immediately and avoid NULL pointer
476 * dereference in OPs processing.
478 ARMV8_CRYPTO_LOG_ERR(
479 "No appropriate crypto function for given parameters");
483 /* Set up cipher session prerequisites */
484 if (cipher_set_prerequisites(sess, cipher_xform) != 0)
487 /* Set up authentication session prerequisites */
488 if (auth_set_prerequisites(sess, auth_xform) != 0)
494 /** Parse crypto xform chain and set private session parameters */
496 armv8_crypto_set_session_parameters(struct armv8_crypto_session *sess,
497 const struct rte_crypto_sym_xform *xform)
499 const struct rte_crypto_sym_xform *cipher_xform = NULL;
500 const struct rte_crypto_sym_xform *auth_xform = NULL;
504 /* Filter out spurious/broken requests */
508 sess->chain_order = armv8_crypto_get_chain_order(xform);
509 switch (sess->chain_order) {
510 case ARMV8_CRYPTO_CHAIN_CIPHER_AUTH:
511 cipher_xform = xform;
512 auth_xform = xform->next;
513 is_chained_op = true;
515 case ARMV8_CRYPTO_CHAIN_AUTH_CIPHER:
517 cipher_xform = xform->next;
518 is_chained_op = true;
521 is_chained_op = false;
526 ret = armv8_crypto_set_session_chained_parameters(sess,
527 cipher_xform, auth_xform);
528 if (unlikely(ret != 0)) {
529 ARMV8_CRYPTO_LOG_ERR(
530 "Invalid/unsupported chained (cipher/auth) parameters");
534 ARMV8_CRYPTO_LOG_ERR("Invalid/unsupported operation");
541 /** Provide session for operation */
542 static inline struct armv8_crypto_session *
543 get_session(struct armv8_crypto_qp *qp, struct rte_crypto_op *op)
545 struct armv8_crypto_session *sess = NULL;
547 if (op->sym->sess_type == RTE_CRYPTO_SYM_OP_WITH_SESSION) {
548 /* get existing session */
549 if (likely(op->sym->session != NULL &&
550 op->sym->session->dev_type ==
551 RTE_CRYPTODEV_ARMV8_PMD)) {
552 sess = (struct armv8_crypto_session *)
553 op->sym->session->_private;
556 /* provide internal session */
559 if (!rte_mempool_get(qp->sess_mp, (void **)&_sess)) {
560 sess = (struct armv8_crypto_session *)
561 ((struct rte_cryptodev_sym_session *)_sess)
564 if (unlikely(armv8_crypto_set_session_parameters(
565 sess, op->sym->xform) != 0)) {
566 rte_mempool_put(qp->sess_mp, _sess);
569 op->sym->session = _sess;
573 if (unlikely(sess == NULL))
574 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
580 *------------------------------------------------------------------------------
582 *------------------------------------------------------------------------------
585 /*----------------------------------------------------------------------------*/
587 /** Process cipher operation */
589 process_armv8_chained_op
590 (struct rte_crypto_op *op, struct armv8_crypto_session *sess,
591 struct rte_mbuf *mbuf_src, struct rte_mbuf *mbuf_dst)
593 crypto_func_t crypto_func;
595 struct rte_mbuf *m_asrc, *m_adst;
596 uint8_t *csrc, *cdst;
597 uint8_t *adst, *asrc;
601 clen = op->sym->cipher.data.length;
602 alen = op->sym->auth.data.length;
604 csrc = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
605 op->sym->cipher.data.offset);
606 cdst = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
607 op->sym->cipher.data.offset);
609 switch (sess->chain_order) {
610 case ARMV8_CRYPTO_CHAIN_CIPHER_AUTH:
611 m_asrc = m_adst = mbuf_dst;
613 case ARMV8_CRYPTO_CHAIN_AUTH_CIPHER:
618 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
621 asrc = rte_pktmbuf_mtod_offset(m_asrc, uint8_t *,
622 op->sym->auth.data.offset);
624 switch (sess->auth.mode) {
625 case ARMV8_CRYPTO_AUTH_AS_AUTH:
626 /* Nothing to do here, just verify correct option */
628 case ARMV8_CRYPTO_AUTH_AS_HMAC:
629 arg.digest.hmac.key = sess->auth.hmac.key;
630 arg.digest.hmac.i_key_pad = sess->auth.hmac.i_key_pad;
631 arg.digest.hmac.o_key_pad = sess->auth.hmac.o_key_pad;
634 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
638 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_GENERATE) {
639 adst = op->sym->auth.digest.data;
641 adst = rte_pktmbuf_mtod_offset(m_adst,
643 op->sym->auth.data.offset +
644 op->sym->auth.data.length);
647 adst = (uint8_t *)rte_pktmbuf_append(m_asrc,
648 op->sym->auth.digest.length);
651 if (unlikely(op->sym->cipher.iv.length != sess->cipher.iv_len)) {
652 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
656 arg.cipher.iv = op->sym->cipher.iv.data;
657 arg.cipher.key = sess->cipher.key.data;
658 /* Acquire combined mode function */
659 crypto_func = sess->crypto_func;
660 ARMV8_CRYPTO_ASSERT(crypto_func != NULL);
661 error = crypto_func(csrc, cdst, clen, asrc, adst, alen, &arg);
663 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
667 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
668 if (sess->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
669 if (memcmp(adst, op->sym->auth.digest.data,
670 op->sym->auth.digest.length) != 0) {
671 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
673 /* Trim area used for digest from mbuf. */
674 rte_pktmbuf_trim(m_asrc,
675 op->sym->auth.digest.length);
679 /** Process crypto operation for mbuf */
681 process_op(const struct armv8_crypto_qp *qp, struct rte_crypto_op *op,
682 struct armv8_crypto_session *sess)
684 struct rte_mbuf *msrc, *mdst;
686 msrc = op->sym->m_src;
687 mdst = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;
689 op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
691 switch (sess->chain_order) {
692 case ARMV8_CRYPTO_CHAIN_CIPHER_AUTH:
693 case ARMV8_CRYPTO_CHAIN_AUTH_CIPHER: /* Fall through */
694 process_armv8_chained_op(op, sess, msrc, mdst);
697 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
701 /* Free session if a session-less crypto op */
702 if (op->sym->sess_type == RTE_CRYPTO_SYM_OP_SESSIONLESS) {
703 memset(sess, 0, sizeof(struct armv8_crypto_session));
704 rte_mempool_put(qp->sess_mp, op->sym->session);
705 op->sym->session = NULL;
708 if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
709 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
711 if (unlikely(op->status == RTE_CRYPTO_OP_STATUS_ERROR))
718 *------------------------------------------------------------------------------
720 *------------------------------------------------------------------------------
725 armv8_crypto_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
728 struct armv8_crypto_session *sess;
729 struct armv8_crypto_qp *qp = queue_pair;
732 for (i = 0; i < nb_ops; i++) {
733 sess = get_session(qp, ops[i]);
734 if (unlikely(sess == NULL))
737 retval = process_op(qp, ops[i], sess);
738 if (unlikely(retval < 0))
742 retval = rte_ring_enqueue_burst(qp->processed_ops, (void *)ops, i,
744 qp->stats.enqueued_count += retval;
749 retval = rte_ring_enqueue_burst(qp->processed_ops, (void *)ops, i,
752 ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
754 qp->stats.enqueue_err_count++;
760 armv8_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
763 struct armv8_crypto_qp *qp = queue_pair;
765 unsigned int nb_dequeued = 0;
767 nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
768 (void **)ops, nb_ops, NULL);
769 qp->stats.dequeued_count += nb_dequeued;
774 /** Create ARMv8 crypto device */
776 cryptodev_armv8_crypto_create(struct rte_vdev_device *vdev,
777 struct rte_crypto_vdev_init_params *init_params)
779 struct rte_cryptodev *dev;
780 struct armv8_crypto_private *internals;
783 /* Check CPU for support for AES instruction set */
784 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
785 ARMV8_CRYPTO_LOG_ERR(
786 "AES instructions not supported by CPU");
790 /* Check CPU for support for SHA instruction set */
791 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_SHA1) ||
792 !rte_cpu_get_flag_enabled(RTE_CPUFLAG_SHA2)) {
793 ARMV8_CRYPTO_LOG_ERR(
794 "SHA1/SHA2 instructions not supported by CPU");
798 /* Check CPU for support for Advance SIMD instruction set */
799 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON)) {
800 ARMV8_CRYPTO_LOG_ERR(
801 "Advanced SIMD instructions not supported by CPU");
805 if (init_params->name[0] == '\0') {
806 ret = rte_cryptodev_pmd_create_dev_name(
808 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
811 ARMV8_CRYPTO_LOG_ERR("failed to create unique name");
816 dev = rte_cryptodev_pmd_virtual_dev_init(init_params->name,
817 sizeof(struct armv8_crypto_private),
818 init_params->socket_id);
820 ARMV8_CRYPTO_LOG_ERR("failed to create cryptodev vdev");
824 dev->dev_type = RTE_CRYPTODEV_ARMV8_PMD;
825 dev->dev_ops = rte_armv8_crypto_pmd_ops;
827 /* register rx/tx burst functions for data path */
828 dev->dequeue_burst = armv8_crypto_pmd_dequeue_burst;
829 dev->enqueue_burst = armv8_crypto_pmd_enqueue_burst;
831 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
832 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
833 RTE_CRYPTODEV_FF_CPU_NEON |
834 RTE_CRYPTODEV_FF_CPU_ARM_CE;
836 /* Set vector instructions mode supported */
837 internals = dev->data->dev_private;
839 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
840 internals->max_nb_sessions = init_params->max_nb_sessions;
845 ARMV8_CRYPTO_LOG_ERR(
846 "driver %s: cryptodev_armv8_crypto_create failed",
849 cryptodev_armv8_crypto_uninit(vdev);
853 /** Initialise ARMv8 crypto device */
855 cryptodev_armv8_crypto_init(struct rte_vdev_device *vdev)
857 struct rte_crypto_vdev_init_params init_params = {
858 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
859 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
864 const char *input_args;
866 name = rte_vdev_device_name(vdev);
869 input_args = rte_vdev_device_args(vdev);
870 rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
872 RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
873 init_params.socket_id);
874 if (init_params.name[0] != '\0') {
875 RTE_LOG(INFO, PMD, " User defined name = %s\n",
878 RTE_LOG(INFO, PMD, " Max number of queue pairs = %d\n",
879 init_params.max_nb_queue_pairs);
880 RTE_LOG(INFO, PMD, " Max number of sessions = %d\n",
881 init_params.max_nb_sessions);
883 return cryptodev_armv8_crypto_create(vdev, &init_params);
886 /** Uninitialise ARMv8 crypto device */
888 cryptodev_armv8_crypto_uninit(struct rte_vdev_device *vdev)
892 name = rte_vdev_device_name(vdev);
897 "Closing ARMv8 crypto device %s on numa socket %u\n",
898 name, rte_socket_id());
903 static struct rte_vdev_driver armv8_crypto_drv = {
904 .probe = cryptodev_armv8_crypto_init,
905 .remove = cryptodev_armv8_crypto_uninit
908 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_ARMV8_PMD, armv8_crypto_drv);
909 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_ARMV8_PMD, cryptodev_armv8_pmd);
910 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_ARMV8_PMD,
911 "max_nb_queue_pairs=<int> "
912 "max_nb_sessions=<int> "