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,
348 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
351 static inline uint32_t
352 adf_modulo(uint32_t data, uint32_t shift);
355 qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg);
357 void qat_crypto_sym_clear_session(struct rte_cryptodev *dev,
360 struct qat_session *sess = session;
361 phys_addr_t cd_paddr;
363 PMD_INIT_FUNC_TRACE();
365 cd_paddr = sess->cd_paddr;
366 memset(sess, 0, qat_crypto_sym_get_session_private_size(dev));
367 sess->cd_paddr = cd_paddr;
369 PMD_DRV_LOG(ERR, "NULL session");
373 qat_get_cmd_id(const struct rte_crypto_sym_xform *xform)
376 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL)
377 return ICP_QAT_FW_LA_CMD_CIPHER;
379 /* Authentication Only */
380 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && xform->next == NULL)
381 return ICP_QAT_FW_LA_CMD_AUTH;
383 if (xform->next == NULL)
386 /* Cipher then Authenticate */
387 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
388 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
389 return ICP_QAT_FW_LA_CMD_CIPHER_HASH;
391 /* Authenticate then Cipher */
392 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
393 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
394 return ICP_QAT_FW_LA_CMD_HASH_CIPHER;
399 static struct rte_crypto_auth_xform *
400 qat_get_auth_xform(struct rte_crypto_sym_xform *xform)
403 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH)
412 static struct rte_crypto_cipher_xform *
413 qat_get_cipher_xform(struct rte_crypto_sym_xform *xform)
416 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
417 return &xform->cipher;
425 qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
426 struct rte_crypto_sym_xform *xform, void *session_private)
428 struct qat_pmd_private *internals = dev->data->dev_private;
430 struct qat_session *session = session_private;
432 struct rte_crypto_cipher_xform *cipher_xform = NULL;
434 /* Get cipher xform from crypto xform chain */
435 cipher_xform = qat_get_cipher_xform(xform);
437 switch (cipher_xform->algo) {
438 case RTE_CRYPTO_CIPHER_AES_CBC:
439 if (qat_alg_validate_aes_key(cipher_xform->key.length,
440 &session->qat_cipher_alg) != 0) {
441 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
444 session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
446 case RTE_CRYPTO_CIPHER_AES_GCM:
447 if (qat_alg_validate_aes_key(cipher_xform->key.length,
448 &session->qat_cipher_alg) != 0) {
449 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
452 session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
454 case RTE_CRYPTO_CIPHER_AES_CTR:
455 if (qat_alg_validate_aes_key(cipher_xform->key.length,
456 &session->qat_cipher_alg) != 0) {
457 PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
460 session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
462 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
463 if (qat_alg_validate_snow3g_key(cipher_xform->key.length,
464 &session->qat_cipher_alg) != 0) {
465 PMD_DRV_LOG(ERR, "Invalid SNOW3G cipher key size");
468 session->qat_mode = ICP_QAT_HW_CIPHER_ECB_MODE;
470 case RTE_CRYPTO_CIPHER_NULL:
471 case RTE_CRYPTO_CIPHER_3DES_ECB:
472 case RTE_CRYPTO_CIPHER_3DES_CBC:
473 case RTE_CRYPTO_CIPHER_AES_ECB:
474 case RTE_CRYPTO_CIPHER_AES_CCM:
475 case RTE_CRYPTO_CIPHER_KASUMI_F8:
476 PMD_DRV_LOG(ERR, "Crypto: Unsupported Cipher alg %u",
480 PMD_DRV_LOG(ERR, "Crypto: Undefined Cipher specified %u\n",
485 if (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
486 session->qat_dir = ICP_QAT_HW_CIPHER_ENCRYPT;
488 session->qat_dir = ICP_QAT_HW_CIPHER_DECRYPT;
490 if (qat_alg_aead_session_create_content_desc_cipher(session,
491 cipher_xform->key.data,
492 cipher_xform->key.length))
498 rte_mempool_put(internals->sess_mp, session);
504 qat_crypto_sym_configure_session(struct rte_cryptodev *dev,
505 struct rte_crypto_sym_xform *xform, void *session_private)
507 struct qat_pmd_private *internals = dev->data->dev_private;
509 struct qat_session *session = session_private;
513 PMD_INIT_FUNC_TRACE();
515 /* Get requested QAT command id */
516 qat_cmd_id = qat_get_cmd_id(xform);
517 if (qat_cmd_id < 0 || qat_cmd_id >= ICP_QAT_FW_LA_CMD_DELIMITER) {
518 PMD_DRV_LOG(ERR, "Unsupported xform chain requested");
521 session->qat_cmd = (enum icp_qat_fw_la_cmd_id)qat_cmd_id;
522 switch (session->qat_cmd) {
523 case ICP_QAT_FW_LA_CMD_CIPHER:
524 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
526 case ICP_QAT_FW_LA_CMD_AUTH:
527 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
529 case ICP_QAT_FW_LA_CMD_CIPHER_HASH:
530 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
531 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
533 case ICP_QAT_FW_LA_CMD_HASH_CIPHER:
534 session = qat_crypto_sym_configure_session_auth(dev, xform, session);
535 session = qat_crypto_sym_configure_session_cipher(dev, xform, session);
537 case ICP_QAT_FW_LA_CMD_TRNG_GET_RANDOM:
538 case ICP_QAT_FW_LA_CMD_TRNG_TEST:
539 case ICP_QAT_FW_LA_CMD_SSL3_KEY_DERIVE:
540 case ICP_QAT_FW_LA_CMD_TLS_V1_1_KEY_DERIVE:
541 case ICP_QAT_FW_LA_CMD_TLS_V1_2_KEY_DERIVE:
542 case ICP_QAT_FW_LA_CMD_MGF1:
543 case ICP_QAT_FW_LA_CMD_AUTH_PRE_COMP:
544 case ICP_QAT_FW_LA_CMD_CIPHER_PRE_COMP:
545 case ICP_QAT_FW_LA_CMD_DELIMITER:
546 PMD_DRV_LOG(ERR, "Unsupported Service %u",
550 PMD_DRV_LOG(ERR, "Unsupported Service %u",
557 rte_mempool_put(internals->sess_mp, session);
562 qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
563 struct rte_crypto_sym_xform *xform,
564 struct qat_session *session_private)
567 struct qat_pmd_private *internals = dev->data->dev_private;
568 struct qat_session *session = session_private;
569 struct rte_crypto_auth_xform *auth_xform = NULL;
570 struct rte_crypto_cipher_xform *cipher_xform = NULL;
571 auth_xform = qat_get_auth_xform(xform);
573 switch (auth_xform->algo) {
574 case RTE_CRYPTO_AUTH_SHA1_HMAC:
575 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA1;
577 case RTE_CRYPTO_AUTH_SHA224_HMAC:
578 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA224;
580 case RTE_CRYPTO_AUTH_SHA256_HMAC:
581 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA256;
583 case RTE_CRYPTO_AUTH_SHA384_HMAC:
584 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA384;
586 case RTE_CRYPTO_AUTH_SHA512_HMAC:
587 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SHA512;
589 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
590 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC;
592 case RTE_CRYPTO_AUTH_AES_GCM:
593 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_GALOIS_128;
595 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
596 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2;
598 case RTE_CRYPTO_AUTH_MD5_HMAC:
599 session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_MD5;
601 case RTE_CRYPTO_AUTH_NULL:
602 case RTE_CRYPTO_AUTH_SHA1:
603 case RTE_CRYPTO_AUTH_SHA256:
604 case RTE_CRYPTO_AUTH_SHA512:
605 case RTE_CRYPTO_AUTH_SHA224:
606 case RTE_CRYPTO_AUTH_SHA384:
607 case RTE_CRYPTO_AUTH_MD5:
608 case RTE_CRYPTO_AUTH_AES_CCM:
609 case RTE_CRYPTO_AUTH_AES_GMAC:
610 case RTE_CRYPTO_AUTH_KASUMI_F9:
611 case RTE_CRYPTO_AUTH_AES_CMAC:
612 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
613 case RTE_CRYPTO_AUTH_ZUC_EIA3:
614 PMD_DRV_LOG(ERR, "Crypto: Unsupported hash alg %u",
618 PMD_DRV_LOG(ERR, "Crypto: Undefined Hash algo %u specified",
622 cipher_xform = qat_get_cipher_xform(xform);
624 if ((session->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128) ||
625 (session->qat_hash_alg ==
626 ICP_QAT_HW_AUTH_ALGO_GALOIS_64)) {
627 if (qat_alg_aead_session_create_content_desc_auth(session,
628 cipher_xform->key.data,
629 cipher_xform->key.length,
630 auth_xform->add_auth_data_length,
631 auth_xform->digest_length,
635 if (qat_alg_aead_session_create_content_desc_auth(session,
636 auth_xform->key.data,
637 auth_xform->key.length,
638 auth_xform->add_auth_data_length,
639 auth_xform->digest_length,
646 if (internals->sess_mp != NULL)
647 rte_mempool_put(internals->sess_mp, session);
651 unsigned qat_crypto_sym_get_session_private_size(
652 struct rte_cryptodev *dev __rte_unused)
654 return RTE_ALIGN_CEIL(sizeof(struct qat_session), 8);
659 qat_pmd_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
662 register struct qat_queue *queue;
663 struct qat_qp *tmp_qp = (struct qat_qp *)qp;
664 register uint32_t nb_ops_sent = 0;
665 register struct rte_crypto_op **cur_op = ops;
667 uint16_t nb_ops_possible = nb_ops;
668 register uint8_t *base_addr;
669 register uint32_t tail;
672 if (unlikely(nb_ops == 0))
675 /* read params used a lot in main loop into registers */
676 queue = &(tmp_qp->tx_q);
677 base_addr = (uint8_t *)queue->base_addr;
680 /* Find how many can actually fit on the ring */
681 overflow = rte_atomic16_add_return(&tmp_qp->inflights16, nb_ops)
682 - queue->max_inflights;
684 rte_atomic16_sub(&tmp_qp->inflights16, overflow);
685 nb_ops_possible = nb_ops - overflow;
686 if (nb_ops_possible == 0)
690 while (nb_ops_sent != nb_ops_possible) {
691 ret = qat_write_hw_desc_entry(*cur_op, base_addr + tail);
693 tmp_qp->stats.enqueue_err_count++;
694 if (nb_ops_sent == 0)
699 tail = adf_modulo(tail + queue->msg_size, queue->modulo);
704 WRITE_CSR_RING_TAIL(tmp_qp->mmap_bar_addr, queue->hw_bundle_number,
705 queue->hw_queue_number, tail);
707 tmp_qp->stats.enqueued_count += nb_ops_sent;
712 qat_pmd_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
715 struct qat_queue *queue;
716 struct qat_qp *tmp_qp = (struct qat_qp *)qp;
717 uint32_t msg_counter = 0;
718 struct rte_crypto_op *rx_op;
719 struct icp_qat_fw_comn_resp *resp_msg;
721 queue = &(tmp_qp->rx_q);
722 resp_msg = (struct icp_qat_fw_comn_resp *)
723 ((uint8_t *)queue->base_addr + queue->head);
725 while (*(uint32_t *)resp_msg != ADF_RING_EMPTY_SIG &&
726 msg_counter != nb_ops) {
727 rx_op = (struct rte_crypto_op *)(uintptr_t)
728 (resp_msg->opaque_data);
730 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_RX
731 rte_hexdump(stdout, "qat_response:", (uint8_t *)resp_msg,
732 sizeof(struct icp_qat_fw_comn_resp));
734 if (ICP_QAT_FW_COMN_STATUS_FLAG_OK !=
735 ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(
736 resp_msg->comn_hdr.comn_status)) {
737 rx_op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
739 rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
741 *(uint32_t *)resp_msg = ADF_RING_EMPTY_SIG;
742 queue->head = adf_modulo(queue->head +
744 ADF_RING_SIZE_MODULO(queue->queue_size));
745 resp_msg = (struct icp_qat_fw_comn_resp *)
746 ((uint8_t *)queue->base_addr +
752 if (msg_counter > 0) {
753 WRITE_CSR_RING_HEAD(tmp_qp->mmap_bar_addr,
754 queue->hw_bundle_number,
755 queue->hw_queue_number, queue->head);
756 rte_atomic16_sub(&tmp_qp->inflights16, msg_counter);
757 tmp_qp->stats.dequeued_count += msg_counter;
763 qat_write_hw_desc_entry(struct rte_crypto_op *op, uint8_t *out_msg)
765 struct qat_session *ctx;
766 struct icp_qat_fw_la_cipher_req_params *cipher_param;
767 struct icp_qat_fw_la_auth_req_params *auth_param;
768 register struct icp_qat_fw_la_bulk_req *qat_req;
770 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
771 if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
772 PMD_DRV_LOG(ERR, "QAT PMD only supports symmetric crypto "
773 "operation requests, op (%p) is not a "
774 "symmetric operation.", op);
778 if (unlikely(op->sym->sess_type == RTE_CRYPTO_SYM_OP_SESSIONLESS)) {
779 PMD_DRV_LOG(ERR, "QAT PMD only supports session oriented"
780 " requests, op (%p) is sessionless.", op);
784 if (unlikely(op->sym->session->dev_type != RTE_CRYPTODEV_QAT_SYM_PMD)) {
785 PMD_DRV_LOG(ERR, "Session was not created for this device");
789 ctx = (struct qat_session *)op->sym->session->_private;
790 qat_req = (struct icp_qat_fw_la_bulk_req *)out_msg;
791 rte_mov128((uint8_t *)qat_req, (const uint8_t *)&(ctx->fw_req));
792 qat_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
794 qat_req->comn_mid.dst_length =
795 qat_req->comn_mid.src_length =
796 rte_pktmbuf_data_len(op->sym->m_src);
798 qat_req->comn_mid.dest_data_addr =
799 qat_req->comn_mid.src_data_addr =
800 rte_pktmbuf_mtophys(op->sym->m_src);
802 if (unlikely(op->sym->m_dst != NULL)) {
803 qat_req->comn_mid.dest_data_addr =
804 rte_pktmbuf_mtophys(op->sym->m_dst);
805 qat_req->comn_mid.dst_length =
806 rte_pktmbuf_data_len(op->sym->m_dst);
809 cipher_param = (void *)&qat_req->serv_specif_rqpars;
810 auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param));
812 cipher_param->cipher_length = op->sym->cipher.data.length;
813 cipher_param->cipher_offset = op->sym->cipher.data.offset;
814 if (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2) {
815 if (unlikely((cipher_param->cipher_length % BYTE_LENGTH != 0) ||
816 (cipher_param->cipher_offset
817 % BYTE_LENGTH != 0))) {
818 PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only "
819 "supports byte aligned values");
820 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
823 cipher_param->cipher_length >>= 3;
824 cipher_param->cipher_offset >>= 3;
827 if (op->sym->cipher.iv.length && (op->sym->cipher.iv.length <=
828 sizeof(cipher_param->u.cipher_IV_array))) {
829 rte_memcpy(cipher_param->u.cipher_IV_array,
830 op->sym->cipher.iv.data,
831 op->sym->cipher.iv.length);
833 ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
834 qat_req->comn_hdr.serv_specif_flags,
835 ICP_QAT_FW_CIPH_IV_64BIT_PTR);
836 cipher_param->u.s.cipher_IV_ptr = op->sym->cipher.iv.phys_addr;
838 if (op->sym->auth.digest.phys_addr) {
839 ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
840 qat_req->comn_hdr.serv_specif_flags,
841 ICP_QAT_FW_LA_NO_DIGEST_IN_BUFFER);
842 auth_param->auth_res_addr = op->sym->auth.digest.phys_addr;
844 auth_param->auth_off = op->sym->auth.data.offset;
845 auth_param->auth_len = op->sym->auth.data.length;
846 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2) {
847 if (unlikely((auth_param->auth_off % BYTE_LENGTH != 0) ||
848 (auth_param->auth_len % BYTE_LENGTH != 0))) {
849 PMD_DRV_LOG(ERR, " For Snow3g, QAT PMD only "
850 "supports byte aligned values");
851 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
854 auth_param->auth_off >>= 3;
855 auth_param->auth_len >>= 3;
857 auth_param->u1.aad_adr = op->sym->auth.aad.phys_addr;
859 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
860 ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
861 if (op->sym->cipher.iv.length == 12) {
863 * For GCM a 12 bit IV is allowed,
864 * but we need to inform the f/w
866 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
867 qat_req->comn_hdr.serv_specif_flags,
868 ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
872 #ifdef RTE_LIBRTE_PMD_QAT_DEBUG_TX
873 rte_hexdump(stdout, "qat_req:", qat_req,
874 sizeof(struct icp_qat_fw_la_bulk_req));
875 rte_hexdump(stdout, "src_data:",
876 rte_pktmbuf_mtod(op->sym->m_src, uint8_t*),
877 rte_pktmbuf_data_len(op->sym->m_src));
878 rte_hexdump(stdout, "iv:", op->sym->cipher.iv.data,
879 op->sym->cipher.iv.length);
880 rte_hexdump(stdout, "digest:", op->sym->auth.digest.data,
881 op->sym->auth.digest.length);
882 rte_hexdump(stdout, "aad:", op->sym->auth.aad.data,
883 op->sym->auth.aad.length);
888 static inline uint32_t adf_modulo(uint32_t data, uint32_t shift)
890 uint32_t div = data >> shift;
891 uint32_t mult = div << shift;
896 void qat_crypto_sym_session_init(struct rte_mempool *mp, void *sym_sess)
898 struct rte_cryptodev_sym_session *sess = sym_sess;
899 struct qat_session *s = (void *)sess->_private;
901 PMD_INIT_FUNC_TRACE();
902 s->cd_paddr = rte_mempool_virt2phy(mp, sess) +
903 offsetof(struct qat_session, cd) +
904 offsetof(struct rte_cryptodev_sym_session, _private);
907 int qat_dev_config(__rte_unused struct rte_cryptodev *dev)
909 PMD_INIT_FUNC_TRACE();
913 int qat_dev_start(__rte_unused struct rte_cryptodev *dev)
915 PMD_INIT_FUNC_TRACE();
919 void qat_dev_stop(__rte_unused struct rte_cryptodev *dev)
921 PMD_INIT_FUNC_TRACE();
924 int qat_dev_close(struct rte_cryptodev *dev)
928 PMD_INIT_FUNC_TRACE();
930 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
931 ret = qat_crypto_sym_qp_release(dev, i);
939 void qat_dev_info_get(__rte_unused struct rte_cryptodev *dev,
940 struct rte_cryptodev_info *info)
942 struct qat_pmd_private *internals = dev->data->dev_private;
944 PMD_INIT_FUNC_TRACE();
946 info->max_nb_queue_pairs =
947 ADF_NUM_SYM_QPS_PER_BUNDLE *
948 ADF_NUM_BUNDLES_PER_DEV;
949 info->feature_flags = dev->feature_flags;
950 info->capabilities = qat_pmd_capabilities;
951 info->sym.max_nb_sessions = internals->max_nb_sessions;
952 info->dev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
956 void qat_crypto_sym_stats_get(struct rte_cryptodev *dev,
957 struct rte_cryptodev_stats *stats)
960 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
962 PMD_INIT_FUNC_TRACE();
964 PMD_DRV_LOG(ERR, "invalid stats ptr NULL");
967 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
969 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
973 stats->enqueued_count += qp[i]->stats.enqueued_count;
974 stats->dequeued_count += qp[i]->stats.enqueued_count;
975 stats->enqueue_err_count += qp[i]->stats.enqueue_err_count;
976 stats->dequeue_err_count += qp[i]->stats.enqueue_err_count;
980 void qat_crypto_sym_stats_reset(struct rte_cryptodev *dev)
983 struct qat_qp **qp = (struct qat_qp **)(dev->data->queue_pairs);
985 PMD_INIT_FUNC_TRACE();
986 for (i = 0; i < dev->data->nb_queue_pairs; i++)
987 memset(&(qp[i]->stats), 0, sizeof(qp[i]->stats));
988 PMD_DRV_LOG(DEBUG, "QAT crypto: stats cleared");