4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <sys/queue.h>
43 #include <rte_common.h>
45 #include <rte_debug.h>
46 #include <rte_memory.h>
47 #include <rte_memzone.h>
48 #include <rte_tailq.h>
49 #include <rte_ether.h>
50 #include <rte_malloc.h>
51 #include <rte_launch.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_atomic.h>
56 #include <rte_branch_prediction.h>
57 #include <rte_mempool.h>
59 #include <rte_string_fns.h>
60 #include <rte_spinlock.h>
61 #include <rte_hexdump.h>
65 #include "qat_crypto.h"
66 #include "adf_transport_access_macros.h"
70 static const struct rte_cryptodev_capabilities qat_pmd_capabilities[] = {
72 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
74 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
76 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
93 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
95 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
97 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
114 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
116 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
118 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
135 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
137 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
139 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
156 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
158 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
160 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
177 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
179 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
181 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
198 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
200 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
202 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
218 { /* AES GCM (AUTH) */
219 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
221 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
223 .algo = RTE_CRYPTO_AUTH_AES_GCM,
243 { /* SNOW3G (UIA2) */
244 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
246 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
248 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
268 { /* AES GCM (CIPHER) */
269 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
271 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
273 .algo = RTE_CRYPTO_CIPHER_AES_GCM,
289 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
291 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
293 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
308 { /* SNOW3G (UEA2) */
309 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
311 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
313 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
329 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
331 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
333 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
349 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
351 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
353 .algo = RTE_CRYPTO_AUTH_NULL,
369 { /* NULL (CIPHER) */
370 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
372 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
374 .algo = RTE_CRYPTO_CIPHER_NULL,
389 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
392 static inline uint32_t
393 adf_modulo(uint32_t data, uint32_t shift);
396 qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg);
398 void qat_crypto_sym_clear_session(struct rte_cryptodev *dev,
401 struct qat_session *sess = session;
402 phys_addr_t cd_paddr;
404 PMD_INIT_FUNC_TRACE();
406 cd_paddr = sess->cd_paddr;
407 memset(sess, 0, qat_crypto_sym_get_session_private_size(dev));
408 sess->cd_paddr = cd_paddr;
410 PMD_DRV_LOG(ERR, "NULL session");
414 qat_get_cmd_id(const struct rte_crypto_sym_xform *xform)
417 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL)
418 return ICP_QAT_FW_LA_CMD_CIPHER;
420 /* Authentication Only */
421 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && xform->next == NULL)
422 return ICP_QAT_FW_LA_CMD_AUTH;
424 if (xform->next == NULL)
427 /* Cipher then Authenticate */
428 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
429 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
430 return ICP_QAT_FW_LA_CMD_CIPHER_HASH;
432 /* Authenticate then Cipher */
433 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
434 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
435 return ICP_QAT_FW_LA_CMD_HASH_CIPHER;
440 static struct rte_crypto_auth_xform *
441 qat_get_auth_xform(struct rte_crypto_sym_xform *xform)
444 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH)
453 static struct rte_crypto_cipher_xform *
454 qat_get_cipher_xform(struct rte_crypto_sym_xform *xform)
457 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
458 return &xform->cipher;
466 qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
467 struct rte_crypto_sym_xform *xform, void *session_private)
469 struct qat_pmd_private *internals = dev->data->dev_private;
471 struct qat_session *session = session_private;
473 struct rte_crypto_cipher_xform *cipher_xform = NULL;
475 /* Get cipher xform from crypto xform chain */
476 cipher_xform = qat_get_cipher_xform(xform);
478 switch (cipher_xform->algo) {
479 case RTE_CRYPTO_CIPHER_AES_CBC:
480 if (qat_alg_validate_aes_key(cipher_xform->key.length,
481 &session->qat_cipher_alg) != 0) {
482 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
485 session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
487 case RTE_CRYPTO_CIPHER_AES_GCM:
488 if (qat_alg_validate_aes_key(cipher_xform->key.length,
489 &session->qat_cipher_alg) != 0) {
490 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
493 session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
495 case RTE_CRYPTO_CIPHER_AES_CTR:
496 if (qat_alg_validate_aes_key(cipher_xform->key.length,
497 &session->qat_cipher_alg) != 0) {
498 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
501 session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
503 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
504 if (qat_alg_validate_snow3g_key(cipher_xform->key.length,
505 &session->qat_cipher_alg) != 0) {
506 PMD_DRV_LOG(ERR, "Invalid SNOW3G cipher key size");
509 session->qat_mode = ICP_QAT_HW_CIPHER_ECB_MODE;
511 case RTE_CRYPTO_CIPHER_NULL:
512 session->qat_mode = ICP_QAT_HW_CIPHER_ECB_MODE;
514 case RTE_CRYPTO_CIPHER_3DES_ECB:
515 case RTE_CRYPTO_CIPHER_3DES_CBC:
516 case RTE_CRYPTO_CIPHER_AES_ECB:
517 case RTE_CRYPTO_CIPHER_AES_CCM:
518 case RTE_CRYPTO_CIPHER_KASUMI_F8:
519 PMD_DRV_LOG(ERR, "Crypto: Unsupported Cipher alg %u",
523 PMD_DRV_LOG(ERR, "Crypto: Undefined Cipher specified %u\n",
528 if (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
529 session->qat_dir = ICP_QAT_HW_CIPHER_ENCRYPT;
531 session->qat_dir = ICP_QAT_HW_CIPHER_DECRYPT;
533 if (qat_alg_aead_session_create_content_desc_cipher(session,
534 cipher_xform->key.data,
535 cipher_xform->key.length))
541 rte_mempool_put(internals->sess_mp, session);
547 qat_crypto_sym_configure_session(struct rte_cryptodev *dev,
548 struct rte_crypto_sym_xform *xform, void *session_private)
550 struct qat_pmd_private *internals = dev->data->dev_private;
552 struct qat_session *session = session_private;
556 PMD_INIT_FUNC_TRACE();
558 /* Get requested QAT command id */
559 qat_cmd_id = qat_get_cmd_id(xform);
560 if (qat_cmd_id < 0 || qat_cmd_id >= ICP_QAT_FW_LA_CMD_DELIMITER) {
561 PMD_DRV_LOG(ERR, "Unsupported xform chain requested");
564 session->qat_cmd = (enum icp_qat_fw_la_cmd_id)qat_cmd_id;
565 switch (session->qat_cmd) {
566 case ICP_QAT_FW_LA_CMD_CIPHER:
567 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
569 case ICP_QAT_FW_LA_CMD_AUTH:
570 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
572 case ICP_QAT_FW_LA_CMD_CIPHER_HASH:
573 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
574 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
576 case ICP_QAT_FW_LA_CMD_HASH_CIPHER:
577 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
578 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
580 case ICP_QAT_FW_LA_CMD_TRNG_GET_RANDOM:
581 case ICP_QAT_FW_LA_CMD_TRNG_TEST:
582 case ICP_QAT_FW_LA_CMD_SSL3_KEY_DERIVE:
583 case ICP_QAT_FW_LA_CMD_TLS_V1_1_KEY_DERIVE:
584 case ICP_QAT_FW_LA_CMD_TLS_V1_2_KEY_DERIVE:
585 case ICP_QAT_FW_LA_CMD_MGF1:
586 case ICP_QAT_FW_LA_CMD_AUTH_PRE_COMP:
587 case ICP_QAT_FW_LA_CMD_CIPHER_PRE_COMP:
588 case ICP_QAT_FW_LA_CMD_DELIMITER:
589 PMD_DRV_LOG(ERR, "Unsupported Service %u",
593 PMD_DRV_LOG(ERR, "Unsupported Service %u",
600 rte_mempool_put(internals->sess_mp, session);
605 qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
606 struct rte_crypto_sym_xform *xform,
607 struct qat_session *session_private)
610 struct qat_pmd_private *internals = dev->data->dev_private;
611 struct qat_session *session = session_private;
612 struct rte_crypto_auth_xform *auth_xform = NULL;
613 struct rte_crypto_cipher_xform *cipher_xform = NULL;
614 auth_xform = qat_get_auth_xform(xform);
616 switch (auth_xform->algo) {
617 case RTE_CRYPTO_AUTH_SHA1_HMAC:
618 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA1;
620 case RTE_CRYPTO_AUTH_SHA224_HMAC:
621 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA224;
623 case RTE_CRYPTO_AUTH_SHA256_HMAC:
624 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA256;
626 case RTE_CRYPTO_AUTH_SHA384_HMAC:
627 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA384;
629 case RTE_CRYPTO_AUTH_SHA512_HMAC:
630 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA512;
632 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
633 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC;
635 case RTE_CRYPTO_AUTH_AES_GCM:
636 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_GALOIS_128;
638 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
639 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2;
641 case RTE_CRYPTO_AUTH_MD5_HMAC:
642 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_MD5;
644 case RTE_CRYPTO_AUTH_NULL:
645 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_NULL;
647 case RTE_CRYPTO_AUTH_SHA1:
648 case RTE_CRYPTO_AUTH_SHA256:
649 case RTE_CRYPTO_AUTH_SHA512:
650 case RTE_CRYPTO_AUTH_SHA224:
651 case RTE_CRYPTO_AUTH_SHA384:
652 case RTE_CRYPTO_AUTH_MD5:
653 case RTE_CRYPTO_AUTH_AES_CCM:
654 case RTE_CRYPTO_AUTH_AES_GMAC:
655 case RTE_CRYPTO_AUTH_KASUMI_F9:
656 case RTE_CRYPTO_AUTH_AES_CMAC:
657 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
658 case RTE_CRYPTO_AUTH_ZUC_EIA3:
659 PMD_DRV_LOG(ERR, "Crypto: Unsupported hash alg %u",
663 PMD_DRV_LOG(ERR, "Crypto: Undefined Hash algo %u specified",
667 cipher_xform = qat_get_cipher_xform(xform);
669 if ((session->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128) ||
670 (session->qat_hash_alg ==
671 ICP_QAT_HW_AUTH_ALGO_GALOIS_64)) {
672 if (qat_alg_aead_session_create_content_desc_auth(session,
673 cipher_xform->key.data,
674 cipher_xform->key.length,
675 auth_xform->add_auth_data_length,
676 auth_xform->digest_length,
680 if (qat_alg_aead_session_create_content_desc_auth(session,
681 auth_xform->key.data,
682 auth_xform->key.length,
683 auth_xform->add_auth_data_length,
684 auth_xform->digest_length,
691 if (internals->sess_mp != NULL)
692 rte_mempool_put(internals->sess_mp, session);
696 unsigned qat_crypto_sym_get_session_private_size(
697 struct rte_cryptodev *dev __rte_unused)
699 return RTE_ALIGN_CEIL(sizeof(struct qat_session), 8);
704 qat_pmd_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
707 register struct qat_queue *queue;
708 struct qat_qp *tmp_qp = (struct qat_qp *)qp;
709 register uint32_t nb_ops_sent = 0;
710 register struct rte_crypto_op **cur_op = ops;
712 uint16_t nb_ops_possible = nb_ops;
713 register uint8_t *base_addr;
714 register uint32_t tail;
717 if (unlikely(nb_ops == 0))
720 /* read params used a lot in main loop into registers */
721 queue = &(tmp_qp->tx_q);
722 base_addr = (uint8_t *)queue->base_addr;
725 /* Find how many can actually fit on the ring */
726 overflow = rte_atomic16_add_return(&tmp_qp->inflights16, nb_ops)
727 - queue->max_inflights;
729 rte_atomic16_sub(&tmp_qp->inflights16, overflow);
730 nb_ops_possible = nb_ops - overflow;
731 if (nb_ops_possible == 0)
735 while (nb_ops_sent != nb_ops_possible) {
736 ret = qat_write_hw_desc_entry(*cur_op, base_addr + tail);
738 tmp_qp->stats.enqueue_err_count++;
739 if (nb_ops_sent == 0)
744 tail = adf_modulo(tail + queue->msg_size, queue->modulo);
749 WRITE_CSR_RING_TAIL(tmp_qp->mmap_bar_addr, queue->hw_bundle_number,
750 queue->hw_queue_number, tail);
752 tmp_qp->stats.enqueued_count += nb_ops_sent;
757 qat_pmd_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
760 struct qat_queue *queue;
761 struct qat_qp *tmp_qp = (struct qat_qp *)qp;
762 uint32_t msg_counter = 0;
763 struct rte_crypto_op *rx_op;
764 struct icp_qat_fw_comn_resp *resp_msg;
766 queue = &(tmp_qp->rx_q);
767 resp_msg = (struct icp_qat_fw_comn_resp *)
768 ((uint8_t *)queue->base_addr + queue->head);
770 while (*(uint32_t *)resp_msg != ADF_RING_EMPTY_SIG &&
771 msg_counter != nb_ops) {
772 rx_op = (struct rte_crypto_op *)(uintptr_t)
773 (resp_msg->opaque_data);
775 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_RX
776 rte_hexdump(stdout, "qat_response:", (uint8_t *)resp_msg,
777 sizeof(struct icp_qat_fw_comn_resp));
779 if (ICP_QAT_FW_COMN_STATUS_FLAG_OK !=
780 ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(
781 resp_msg->comn_hdr.comn_status)) {
782 rx_op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
784 rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
786 *(uint32_t *)resp_msg = ADF_RING_EMPTY_SIG;
787 queue->head = adf_modulo(queue->head +
789 ADF_RING_SIZE_MODULO(queue->queue_size));
790 resp_msg = (struct icp_qat_fw_comn_resp *)
791 ((uint8_t *)queue->base_addr +
797 if (msg_counter > 0) {
798 WRITE_CSR_RING_HEAD(tmp_qp->mmap_bar_addr,
799 queue->hw_bundle_number,
800 queue->hw_queue_number, queue->head);
801 rte_atomic16_sub(&tmp_qp->inflights16, msg_counter);
802 tmp_qp->stats.dequeued_count += msg_counter;
808 qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg)
810 struct qat_session *ctx;
811 struct icp_qat_fw_la_cipher_req_params *cipher_param;
812 struct icp_qat_fw_la_auth_req_params *auth_param;
813 register struct icp_qat_fw_la_bulk_req *qat_req;
815 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
816 if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
817 PMD_DRV_LOG(ERR, "QAT PMD only supports symmetric crypto "
818 "operation requests, op (%p) is not a "
819 "symmetric operation.", op);
823 if (unlikely(op->sym->sess_type == RTE_CRYPTO_SYM_OP_SESSIONLESS)) {
824 PMD_DRV_LOG(ERR, "QAT PMD only supports session oriented"
825 " requests, op (%p) is sessionless.", op);
829 if (unlikely(op->sym->session->dev_type != RTE_CRYPTODEV_QAT_SYM_PMD)) {
830 PMD_DRV_LOG(ERR, "Session was not created for this device");
834 ctx = (struct qat_session *)op->sym->session->_private;
835 qat_req = (struct icp_qat_fw_la_bulk_req *)out_msg;
836 rte_mov128((uint8_t *)qat_req, (const uint8_t *)&(ctx->fw_req));
837 qat_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
839 qat_req->comn_mid.dst_length =
840 qat_req->comn_mid.src_length =
841 rte_pktmbuf_data_len(op->sym->m_src);
843 qat_req->comn_mid.dest_data_addr =
844 qat_req->comn_mid.src_data_addr =
845 rte_pktmbuf_mtophys(op->sym->m_src);
847 if (unlikely(op->sym->m_dst != NULL)) {
848 qat_req->comn_mid.dest_data_addr =
849 rte_pktmbuf_mtophys(op->sym->m_dst);
850 qat_req->comn_mid.dst_length =
851 rte_pktmbuf_data_len(op->sym->m_dst);
854 cipher_param = (void *)&qat_req->serv_specif_rqpars;
855 auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param));
857 cipher_param->cipher_length = op->sym->cipher.data.length;
858 cipher_param->cipher_offset = op->sym->cipher.data.offset;
859 if (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2) {
860 if (unlikely((cipher_param->cipher_length % BYTE_LENGTH != 0) ||
861 (cipher_param->cipher_offset
862 % BYTE_LENGTH != 0))) {
863 PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only "
864 "supports byte aligned values");
865 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
868 cipher_param->cipher_length >>= 3;
869 cipher_param->cipher_offset >>= 3;
872 if (op->sym->cipher.iv.length && (op->sym->cipher.iv.length <=
873 sizeof(cipher_param->u.cipher_IV_array))) {
874 rte_memcpy(cipher_param->u.cipher_IV_array,
875 op->sym->cipher.iv.data,
876 op->sym->cipher.iv.length);
878 ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
879 qat_req->comn_hdr.serv_specif_flags,
880 ICP_QAT_FW_CIPH_IV_64BIT_PTR);
881 cipher_param->u.s.cipher_IV_ptr = op->sym->cipher.iv.phys_addr;
883 if (op->sym->auth.digest.phys_addr) {
884 ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
885 qat_req->comn_hdr.serv_specif_flags,
886 ICP_QAT_FW_LA_NO_DIGEST_IN_BUFFER);
887 auth_param->auth_res_addr = op->sym->auth.digest.phys_addr;
889 auth_param->auth_off = op->sym->auth.data.offset;
890 auth_param->auth_len = op->sym->auth.data.length;
891 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2) {
892 if (unlikely((auth_param->auth_off % BYTE_LENGTH != 0) ||
893 (auth_param->auth_len % BYTE_LENGTH != 0))) {
894 PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only "
895 "supports byte aligned values");
896 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
899 auth_param->auth_off >>= 3;
900 auth_param->auth_len >>= 3;
902 auth_param->u1.aad_adr = op->sym->auth.aad.phys_addr;
904 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
905 ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
906 if (op->sym->cipher.iv.length == 12) {
908 * For GCM a 12 bit IV is allowed,
909 * but we need to inform the f/w
911 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
912 qat_req->comn_hdr.serv_specif_flags,
913 ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
917 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
918 rte_hexdump(stdout, "qat_req:", qat_req,
919 sizeof(struct icp_qat_fw_la_bulk_req));
920 rte_hexdump(stdout, "src_data:",
921 rte_pktmbuf_mtod(op->sym->m_src, uint8_t*),
922 rte_pktmbuf_data_len(op->sym->m_src));
923 rte_hexdump(stdout, "iv:", op->sym->cipher.iv.data,
924 op->sym->cipher.iv.length);
925 rte_hexdump(stdout, "digest:", op->sym->auth.digest.data,
926 op->sym->auth.digest.length);
927 rte_hexdump(stdout, "aad:", op->sym->auth.aad.data,
928 op->sym->auth.aad.length);
933 static inline uint32_t adf_modulo(uint32_t data, uint32_t shift)
935 uint32_t div = data >> shift;
936 uint32_t mult = div << shift;
941 void qat_crypto_sym_session_init(struct rte_mempool *mp, void *sym_sess)
943 struct rte_cryptodev_sym_session *sess = sym_sess;
944 struct qat_session *s = (void *)sess->_private;
946 PMD_INIT_FUNC_TRACE();
947 s->cd_paddr = rte_mempool_virt2phy(mp, sess) +
948 offsetof(struct qat_session, cd) +
949 offsetof(struct rte_cryptodev_sym_session, _private);
952 int qat_dev_config(__rte_unused struct rte_cryptodev *dev)
954 PMD_INIT_FUNC_TRACE();
958 int qat_dev_start(__rte_unused struct rte_cryptodev *dev)
960 PMD_INIT_FUNC_TRACE();
964 void qat_dev_stop(__rte_unused struct rte_cryptodev *dev)
966 PMD_INIT_FUNC_TRACE();
969 int qat_dev_close(struct rte_cryptodev *dev)
973 PMD_INIT_FUNC_TRACE();
975 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
976 ret = qat_crypto_sym_qp_release(dev, i);
984 void qat_dev_info_get(__rte_unused struct rte_cryptodev *dev,
985 struct rte_cryptodev_info *info)
987 struct qat_pmd_private *internals = dev->data->dev_private;
989 PMD_INIT_FUNC_TRACE();
991 info->max_nb_queue_pairs =
992 ADF_NUM_SYM_QPS_PER_BUNDLE *
993 ADF_NUM_BUNDLES_PER_DEV;
994 info->feature_flags = dev->feature_flags;
995 info->capabilities = qat_pmd_capabilities;
996 info->sym.max_nb_sessions = internals->max_nb_sessions;
997 info->dev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
1001 void qat_crypto_sym_stats_get(struct rte_cryptodev *dev,
1002 struct rte_cryptodev_stats *stats)
1005 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
1007 PMD_INIT_FUNC_TRACE();
1008 if (stats == NULL) {
1009 PMD_DRV_LOG(ERR, "invalid stats ptr NULL");
1012 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
1013 if (qp[i] == NULL) {
1014 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
1018 stats->enqueued_count += qp[i]->stats.enqueued_count;
1019 stats->dequeued_count += qp[i]->stats.enqueued_count;
1020 stats->enqueue_err_count += qp[i]->stats.enqueue_err_count;
1021 stats->dequeue_err_count += qp[i]->stats.enqueue_err_count;
1025 void qat_crypto_sym_stats_reset(struct rte_cryptodev *dev)
1028 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
1030 PMD_INIT_FUNC_TRACE();
1031 for (i = 0; i < dev->data->nb_queue_pairs; i++)
1032 memset(&(qp[i]->stats), 0, sizeof(qp[i]->stats));
1033 PMD_DRV_LOG(DEBUG, "QAT crypto: stats cleared");