From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 500F2A0350; Tue, 22 Feb 2022 18:03:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D60AF4115B; Tue, 22 Feb 2022 18:03:32 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id 88A3E41158 for ; Tue, 22 Feb 2022 18:03:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645549410; x=1677085410; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vjUgdc06kCFt1n1IQ2zZQ7UHowwAsUUxtoOMUWF58eU=; b=bv/K1n58Rj5ll3vfe117WnoMbbYLhBPQptoRv3WOk8AWJGpZP975IcVy WH6e1kE+sXhTVUjM3lRNyKqU+aNaolb6casDA3lsgnkOaHGSzLaE+ItS4 oLmHT4uutgfdHC1lLF5T/BOR5M4vjYpyULy17vZclXS8s0JUT8PrZ2KEr ax5F/tbK+HChc3+8+q6m4UOhOaKRFlyAelvjcCBlhurlFL7LajA83ljWg Wi2YYPWNtooQGsIS5La+iUjSQv4MyUkNinAbS427ajYXgua4Q5whNPJty 7VOum5InNrqpT2Lg3MS44HvDtIi1RfBqVFF5b7TPedyjpuJcoWSfI09nW g==; X-IronPort-AV: E=McAfee;i="6200,9189,10266"; a="250584278" X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="250584278" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 09:02:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="490862996" Received: from silpixa00400465.ir.intel.com ([10.55.128.22]) by orsmga003.jf.intel.com with ESMTP; 22 Feb 2022 09:02:36 -0800 From: Kai Ji To: dev@dpdk.org Cc: gakhil@marvell.com, roy.fan.zhang@intel.com, Kai Ji Subject: [dpdk-dev v10 4/9] crypto/qat: rework asymmetric op build operation Date: Wed, 23 Feb 2022 01:02:21 +0800 Message-Id: <20220222170226.90002-5-kai.ji@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220222170226.90002-1-kai.ji@intel.com> References: <20220218171527.56719-1-kai.ji@intel.com> <20220222170226.90002-1-kai.ji@intel.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch reworks the asymmetric crypto data path implementation in QAT driver. The changes include asymmetric crypto data path separation for QAT hardware generations, and code optimisation of the device capabilities declaration. Signed-off-by: Kai Ji --- drivers/common/qat/qat_qp.c | 5 +- drivers/crypto/qat/qat_asym.c | 129 +++++++++++++++++++--------------- drivers/crypto/qat/qat_asym.h | 63 +++++++++++++++-- 3 files changed, 131 insertions(+), 66 deletions(-) diff --git a/drivers/common/qat/qat_qp.c b/drivers/common/qat/qat_qp.c index 56234ca1a4..7f2fdc53ce 100644 --- a/drivers/common/qat/qat_qp.c +++ b/drivers/common/qat/qat_qp.c @@ -619,7 +619,7 @@ qat_enqueue_op_burst(void *qp, #ifdef BUILD_QAT_ASYM ret = qat_asym_build_request(*ops, base_addr + tail, tmp_qp->op_cookies[tail >> queue->trailz], - tmp_qp->qat_dev_gen); + NULL, tmp_qp->qat_dev_gen); #endif } if (ret != 0) { @@ -847,7 +847,8 @@ qat_dequeue_op_burst(void *qp, void **ops, #ifdef BUILD_QAT_ASYM else if (tmp_qp->service_type == QAT_SERVICE_ASYMMETRIC) qat_asym_process_response(ops, resp_msg, - tmp_qp->op_cookies[head >> rx_queue->trailz]); + tmp_qp->op_cookies[head >> rx_queue->trailz], + NULL); #endif head = adf_modulo(head + rx_queue->msg_size, diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index f46eefd4b3..845e905a89 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -1,68 +1,36 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2019 Intel Corporation + * Copyright(c) 2019 - 2022 Intel Corporation */ #include -#include "qat_asym.h" +#include + #include "icp_qat_fw_pke.h" #include "icp_qat_fw.h" #include "qat_pke_functionality_arrays.h" -#define qat_asym_sz_2param(arg) (arg, sizeof(arg)/sizeof(*arg)) - -static int qat_asym_get_sz_and_func_id(const uint32_t arr[][2], - size_t arr_sz, size_t *size, uint32_t *func_id) -{ - size_t i; - - for (i = 0; i < arr_sz; i++) { - if (*size <= arr[i][0]) { - *size = arr[i][0]; - *func_id = arr[i][1]; - return 0; - } - } - return -1; -} - -static inline void qat_fill_req_tmpl(struct icp_qat_fw_pke_request *qat_req) -{ - memset(qat_req, 0, sizeof(*qat_req)); - qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_PKE; - - qat_req->pke_hdr.hdr_flags = - ICP_QAT_FW_COMN_HDR_FLAGS_BUILD - (ICP_QAT_FW_COMN_REQ_FLAG_SET); -} - -static inline void qat_asym_build_req_tmpl(void *sess_private_data) -{ - struct icp_qat_fw_pke_request *qat_req; - struct qat_asym_session *session = sess_private_data; +#include "qat_device.h" - qat_req = &session->req_tmpl; - qat_fill_req_tmpl(qat_req); -} +#include "qat_logs.h" +#include "qat_asym.h" -static size_t max_of(int n, ...) -{ - va_list args; - size_t len = 0, num; - int i; +uint8_t qat_asym_driver_id; - va_start(args, n); - len = va_arg(args, size_t); +struct qat_crypto_gen_dev_ops qat_asym_gen_dev_ops[QAT_N_GENS]; - for (i = 0; i < n - 1; i++) { - num = va_arg(args, size_t); - if (num > len) - len = num; - } - va_end(args); +/* An rte_driver is needed in the registration of both the device and the driver + * with cryptodev. + * The actual qat pci's rte_driver can't be used as its name represents + * the whole pci device with all services. Think of this as a holder for a name + * for the crypto part of the pci device. + */ +static const char qat_asym_drv_name[] = RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD); +static const struct rte_driver cryptodev_qat_asym_driver = { + .name = qat_asym_drv_name, + .alias = qat_asym_drv_name +}; - return len; -} static void qat_clear_arrays(struct qat_asym_op_cookie *cookie, int in_count, int out_count, int alg_size) @@ -106,7 +74,46 @@ static void qat_clear_arrays_by_alg(struct qat_asym_op_cookie *cookie, } } -static int qat_asym_check_nonzero(rte_crypto_param n) +#define qat_asym_sz_2param(arg) (arg, sizeof(arg)/sizeof(*arg)) + +static int +qat_asym_get_sz_and_func_id(const uint32_t arr[][2], + size_t arr_sz, size_t *size, uint32_t *func_id) +{ + size_t i; + + for (i = 0; i < arr_sz; i++) { + if (*size <= arr[i][0]) { + *size = arr[i][0]; + *func_id = arr[i][1]; + return 0; + } + } + return -1; +} + +static size_t +max_of(int n, ...) +{ + va_list args; + size_t len = 0, num; + int i; + + va_start(args, n); + len = va_arg(args, size_t); + + for (i = 0; i < n - 1; i++) { + num = va_arg(args, size_t); + if (num > len) + len = num; + } + va_end(args); + + return len; +} + +static int +qat_asym_check_nonzero(rte_crypto_param n) { if (n.length < 8) { /* Not a case for any cryptographic function except for DH @@ -475,10 +482,9 @@ qat_asym_fill_arrays(struct rte_crypto_asym_op *asym_op, } int -qat_asym_build_request(void *in_op, - uint8_t *out_msg, - void *op_cookie, - __rte_unused enum qat_device_gen qat_dev_gen) +qat_asym_build_request(void *in_op, uint8_t *out_msg, void *op_cookie, + __rte_unused uint64_t *opaque, + __rte_unused enum qat_device_gen dev_gen) { struct qat_asym_session *ctx; struct rte_crypto_op *op = (struct rte_crypto_op *)in_op; @@ -677,9 +683,9 @@ static void qat_asym_collect_response(struct rte_crypto_op *rx_op, qat_clear_arrays_by_alg(cookie, xform, alg_size_in_bytes); } -void +int qat_asym_process_response(void **op, uint8_t *resp, - void *op_cookie) + void *op_cookie, __rte_unused uint64_t *dequeue_err_count) { struct qat_asym_session *ctx; struct icp_qat_fw_pke_resp *resp_msg = @@ -722,6 +728,8 @@ qat_asym_process_response(void **op, uint8_t *resp, QAT_DP_HEXDUMP_LOG(DEBUG, "resp_msg:", resp_msg, sizeof(struct icp_qat_fw_pke_resp)); #endif + + return 1; } int @@ -779,3 +787,8 @@ qat_asym_session_clear(struct rte_cryptodev *dev, if (sess_priv) memset(s, 0, qat_asym_session_get_private_size(dev)); } + +static struct cryptodev_driver qat_crypto_drv; +RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv, + cryptodev_qat_asym_driver, + qat_asym_driver_id); diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h index c9242a12ca..3ae95f2e7b 100644 --- a/drivers/crypto/qat/qat_asym.h +++ b/drivers/crypto/qat/qat_asym.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2019 Intel Corporation + * Copyright(c) 2022 Intel Corporation */ #ifndef _QAT_ASYM_H_ @@ -8,10 +8,13 @@ #include #include #include "icp_qat_fw_pke.h" -#include "qat_common.h" -#include "qat_asym_pmd.h" +#include "qat_device.h" +#include "qat_crypto.h" #include "icp_qat_fw.h" +/** Intel(R) QAT Asymmetric Crypto PMD driver name */ +#define CRYPTODEV_NAME_QAT_ASYM_PMD crypto_qat_asym + typedef uint64_t large_int_ptr; #define MAX_PKE_PARAMS 8 #define QAT_PKE_MAX_LN_SIZE 512 @@ -26,6 +29,28 @@ typedef uint64_t large_int_ptr; #define QAT_ASYM_RSA_NUM_OUT_PARAMS 1 #define QAT_ASYM_RSA_QT_NUM_IN_PARAMS 6 +/** + * helper function to add an asym capability + * + **/ +#define QAT_ASYM_CAP(n, o, l, r, i) \ + { \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_##n,\ + .op_types = o, \ + { \ + .modlen = { \ + .min = l, \ + .max = r, \ + .increment = i \ + }, } \ + } \ + }, \ + } \ + } + struct qat_asym_op_cookie { size_t alg_size; uint64_t error; @@ -45,6 +70,27 @@ struct qat_asym_session { struct rte_crypto_asym_xform *xform; }; +static inline void +qat_fill_req_tmpl(struct icp_qat_fw_pke_request *qat_req) +{ + memset(qat_req, 0, sizeof(*qat_req)); + qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_PKE; + + qat_req->pke_hdr.hdr_flags = + ICP_QAT_FW_COMN_HDR_FLAGS_BUILD + (ICP_QAT_FW_COMN_REQ_FLAG_SET); +} + +static inline void +qat_asym_build_req_tmpl(void *sess_private_data) +{ + struct icp_qat_fw_pke_request *qat_req; + struct qat_asym_session *session = sess_private_data; + + qat_req = &session->req_tmpl; + qat_fill_req_tmpl(qat_req); +} + int qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused, struct rte_crypto_asym_xform *xform, @@ -75,7 +121,9 @@ qat_asym_session_clear(struct rte_cryptodev *dev, */ int qat_asym_build_request(void *in_op, uint8_t *out_msg, - void *op_cookie, enum qat_device_gen qat_dev_gen); + void *op_cookie, + __rte_unused uint64_t *opaque, + enum qat_device_gen qat_dev_gen); /* * Process PKE response received from outgoing queue of QAT @@ -87,8 +135,11 @@ qat_asym_build_request(void *in_op, uint8_t *out_msg, * @param op_cookie Cookie pointer that holds private metadata * */ +int +qat_asym_process_response(void **op, uint8_t *resp, + void *op_cookie, __rte_unused uint64_t *dequeue_err_count); + void -qat_asym_process_response(void __rte_unused **op, uint8_t *resp, - void *op_cookie); +qat_asym_init_op_cookie(void *cookie); #endif /* _QAT_ASYM_H_ */ -- 2.17.1