DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arek Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com,
	Arek Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [dpdk-dev] [PATCH v4 1/5] crypto/qat: add sessionless implementation to asym pmd
Date: Tue, 22 Oct 2019 16:04:25 +0200	[thread overview]
Message-ID: <20191022140429.9008-2-arkadiuszx.kusztal@intel.com> (raw)
In-Reply-To: <20191022140429.9008-1-arkadiuszx.kusztal@intel.com>

This patch adds option to use asymmetric crypto pmd with
session-less support.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 doc/guides/cryptodevs/features/qat.ini |   1 +
 doc/guides/rel_notes/release_19_11.rst |   4 +
 drivers/crypto/qat/qat_asym.c          | 328 ++++++++++++++++++++-------------
 drivers/crypto/qat/qat_asym.h          |  26 +--
 drivers/crypto/qat/qat_asym_pmd.c      |   3 +-
 5 files changed, 208 insertions(+), 154 deletions(-)

diff --git a/doc/guides/cryptodevs/features/qat.ini b/doc/guides/cryptodevs/features/qat.ini
index 0832e59..cef8015 100644
--- a/doc/guides/cryptodevs/features/qat.ini
+++ b/doc/guides/cryptodevs/features/qat.ini
@@ -13,6 +13,7 @@ OOP SGL In LB  Out     = Y
 OOP LB  In SGL Out     = Y
 OOP LB  In LB  Out     = Y
 Digest encrypted       = Y
+Asymmetric sessionless = Y
 
 ;
 ; Supported crypto algorithms of the 'qat' crypto driver.
diff --git a/doc/guides/rel_notes/release_19_11.rst b/doc/guides/rel_notes/release_19_11.rst
index 066bb3c..a96d567 100644
--- a/doc/guides/rel_notes/release_19_11.rst
+++ b/doc/guides/rel_notes/release_19_11.rst
@@ -152,6 +152,10 @@ New Features
   Added eBPF JIT support for arm64 architecture to improve the eBPF program
   performance.
 
+* **Updated the Intel QuickAssist Technology (QAT) asymmetric crypto PMD.**
+
+  Added support for asymmetric session-less operations.
+
 
 Removed Items
 -------------
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 4ddb0e5..1145425 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -26,38 +26,23 @@ static int qat_asym_get_sz_and_func_id(const uint32_t arr[][2],
 	return -1;
 }
 
-static void qat_asym_build_req_tmpl(void *sess_private_data,
-		struct rte_crypto_asym_xform *xform)
+static inline void qat_fill_req_tmpl(struct icp_qat_fw_pke_request *qat_req)
 {
-
-	struct icp_qat_fw_pke_request *qat_req;
-	struct qat_asym_session *session = sess_private_data;
-
-	qat_req = &session->req_tmpl;
 	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);
-	qat_req->pke_hdr.comn_req_flags = 0;
-	qat_req->pke_hdr.resrvd1 = 0;
-	qat_req->pke_hdr.resrvd2 = 0;
-	qat_req->pke_hdr.kpt_mask = 0;
-	qat_req->pke_hdr.kpt_rn_mask = 0;
-	qat_req->pke_hdr.cd_pars.content_desc_addr = 0;
-	qat_req->pke_hdr.cd_pars.content_desc_resrvd = 0;
-	qat_req->resrvd1 = 0;
-	qat_req->resrvd2 = 0;
-	qat_req->next_req_adr = 0;
+}
 
-	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
-		qat_req->output_param_count = 1;
-		qat_req->input_param_count = 3;
-	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
-		qat_req->output_param_count = 1;
-		qat_req->input_param_count = 2;
-	}
+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);
 }
 
 static size_t max_of(int n, ...)
@@ -90,6 +75,19 @@ static void qat_clear_arrays(struct qat_asym_op_cookie *cookie,
 		memset(cookie->output_array[i], 0x0, out_size);
 }
 
+static void qat_clear_arrays_by_alg(struct qat_asym_op_cookie *cookie,
+		enum rte_crypto_asym_xform_type alg, int in_size, int out_size)
+{
+	if (alg == RTE_CRYPTO_ASYM_XFORM_MODEX)
+		qat_clear_arrays(cookie, QAT_ASYM_MODEXP_NUM_IN_PARAMS,
+				QAT_ASYM_MODEXP_NUM_OUT_PARAMS, in_size,
+				out_size);
+	else if (alg == RTE_CRYPTO_ASYM_XFORM_MODINV)
+		qat_clear_arrays(cookie, QAT_ASYM_MODINV_NUM_IN_PARAMS,
+				QAT_ASYM_MODINV_NUM_OUT_PARAMS, in_size,
+				out_size);
+}
+
 static int qat_asym_check_nonzero(rte_crypto_param n)
 {
 	if (n.length < 8) {
@@ -103,7 +101,7 @@ static int qat_asym_check_nonzero(rte_crypto_param n)
 				if (n.data[i] != 0x0)
 					break;
 			if (i == n.length - 1)
-				return QAT_ASYM_ERROR_INVALID_PARAM;
+				return -(EINVAL);
 		}
 	} else if (*(uint64_t *)&n.data[
 				n.length - 8] == 0) {
@@ -114,57 +112,40 @@ static int qat_asym_check_nonzero(rte_crypto_param n)
 			if (n.data[i] != 0x0)
 				break;
 		if (i == n.length - 8)
-			return QAT_ASYM_ERROR_INVALID_PARAM;
+			return -(EINVAL);
 	}
 
 	return 0;
 }
 
-int
-qat_asym_build_request(void *in_op,
-			uint8_t *out_msg,
-			void *op_cookie,
-			__rte_unused enum qat_device_gen qat_dev_gen)
+static int
+qat_asym_fill_arrays(struct rte_crypto_asym_op *asym_op,
+		struct icp_qat_fw_pke_request *qat_req,
+		struct qat_asym_op_cookie *cookie,
+		struct rte_crypto_asym_xform *xform)
 {
-	struct qat_asym_session *ctx;
-	struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
-	struct rte_crypto_asym_op *asym_op = op->asym;
-	struct icp_qat_fw_pke_request *qat_req =
-			(struct icp_qat_fw_pke_request *)out_msg;
-	struct qat_asym_op_cookie *cookie =
-				(struct qat_asym_op_cookie *)op_cookie;
-
-	uint64_t err = 0;
+	int err = 0;
 	size_t alg_size;
 	size_t alg_size_in_bytes;
-	uint32_t func_id;
-
-	ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			op->asym->session, cryptodev_qat_asym_driver_id);
-	rte_mov64((uint8_t *)qat_req, (const uint8_t *)&(ctx->req_tmpl));
-	qat_req->pke_mid.opaque = (uint64_t)(uintptr_t)op;
-
-	qat_req->pke_mid.src_data_addr = cookie->input_addr;
-	qat_req->pke_mid.dest_data_addr = cookie->output_addr;
+	uint32_t func_id = 0;
 
-	if (ctx->alg == QAT_PKE_MODEXP) {
-		err = qat_asym_check_nonzero(ctx->sess_alg_params.mod_exp.n);
+	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
+		err = qat_asym_check_nonzero(xform->modex.modulus);
 		if (err) {
 			QAT_LOG(ERR, "Empty modulus in modular exponentiation,"
 					" aborting this operation");
-			goto error;
+			return err;
 		}
 
 		alg_size_in_bytes = max_of(3, asym_op->modex.base.length,
-			       ctx->sess_alg_params.mod_exp.e.length,
-			       ctx->sess_alg_params.mod_exp.n.length);
+			       xform->modex.exponent.length,
+			       xform->modex.modulus.length);
 		alg_size = alg_size_in_bytes << 3;
 
 		if (qat_asym_get_sz_and_func_id(MOD_EXP_SIZE,
 				sizeof(MOD_EXP_SIZE)/sizeof(*MOD_EXP_SIZE),
 				&alg_size, &func_id)) {
-			err = QAT_ASYM_ERROR_INVALID_PARAM;
-			goto error;
+			return -(EINVAL);
 		}
 
 		alg_size_in_bytes = alg_size >> 3;
@@ -173,54 +154,54 @@ qat_asym_build_request(void *in_op,
 			, asym_op->modex.base.data,
 			asym_op->modex.base.length);
 		rte_memcpy(cookie->input_array[1] + alg_size_in_bytes -
-			ctx->sess_alg_params.mod_exp.e.length
-			, ctx->sess_alg_params.mod_exp.e.data,
-			ctx->sess_alg_params.mod_exp.e.length);
+			xform->modex.exponent.length
+			, xform->modex.exponent.data,
+			xform->modex.exponent.length);
 		rte_memcpy(cookie->input_array[2]  + alg_size_in_bytes -
-			ctx->sess_alg_params.mod_exp.n.length,
-			ctx->sess_alg_params.mod_exp.n.data,
-			ctx->sess_alg_params.mod_exp.n.length);
+			xform->modex.modulus.length,
+			xform->modex.modulus.data,
+			xform->modex.modulus.length);
 		cookie->alg_size = alg_size;
 		qat_req->pke_hdr.cd_pars.func_id = func_id;
+		qat_req->input_param_count = QAT_ASYM_MODEXP_NUM_IN_PARAMS;
+		qat_req->output_param_count = QAT_ASYM_MODEXP_NUM_OUT_PARAMS;
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
-		QAT_DP_HEXDUMP_LOG(DEBUG, "base",
+		QAT_DP_HEXDUMP_LOG(DEBUG, "ModExp base",
 				cookie->input_array[0],
 				alg_size_in_bytes);
-		QAT_DP_HEXDUMP_LOG(DEBUG, "exponent",
+		QAT_DP_HEXDUMP_LOG(DEBUG, "ModExp exponent",
 				cookie->input_array[1],
 				alg_size_in_bytes);
-		QAT_DP_HEXDUMP_LOG(DEBUG, "modulus",
+		QAT_DP_HEXDUMP_LOG(DEBUG, " ModExpmodulus",
 				cookie->input_array[2],
 				alg_size_in_bytes);
 #endif
-	} else if (ctx->alg == QAT_PKE_MODINV) {
-		err = qat_asym_check_nonzero(ctx->sess_alg_params.mod_inv.n);
+	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
+		err = qat_asym_check_nonzero(xform->modinv.modulus);
 		if (err) {
 			QAT_LOG(ERR, "Empty modulus in modular multiplicative"
 					" inverse, aborting this operation");
-			goto error;
+			return err;
 		}
 
 		alg_size_in_bytes = max_of(2, asym_op->modinv.base.length,
-				ctx->sess_alg_params.mod_inv.n.length);
+				xform->modinv.modulus.length);
 		alg_size = alg_size_in_bytes << 3;
 
-		if (ctx->sess_alg_params.mod_inv.n.data[
-				ctx->sess_alg_params.mod_inv.n.length - 1] & 0x01) {
+		if (xform->modinv.modulus.data[
+				xform->modinv.modulus.length - 1] & 0x01) {
 			if (qat_asym_get_sz_and_func_id(MOD_INV_IDS_ODD,
 					sizeof(MOD_INV_IDS_ODD)/
 					sizeof(*MOD_INV_IDS_ODD),
 					&alg_size, &func_id)) {
-				err = QAT_ASYM_ERROR_INVALID_PARAM;
-				goto error;
+				return -(EINVAL);
 			}
 		} else {
 			if (qat_asym_get_sz_and_func_id(MOD_INV_IDS_EVEN,
 					sizeof(MOD_INV_IDS_EVEN)/
 					sizeof(*MOD_INV_IDS_EVEN),
 					&alg_size, &func_id)) {
-				err = QAT_ASYM_ERROR_INVALID_PARAM;
-				goto error;
+				return -(EINVAL);
 			}
 		}
 
@@ -230,27 +211,93 @@ qat_asym_build_request(void *in_op,
 				, asym_op->modinv.base.data,
 				asym_op->modinv.base.length);
 		rte_memcpy(cookie->input_array[1] + alg_size_in_bytes -
-				ctx->sess_alg_params.mod_inv.n.length
-				, ctx->sess_alg_params.mod_inv.n.data,
-				ctx->sess_alg_params.mod_inv.n.length);
+				xform->modinv.modulus.length
+				, xform->modinv.modulus.data,
+				xform->modinv.modulus.length);
 		cookie->alg_size = alg_size;
 		qat_req->pke_hdr.cd_pars.func_id = func_id;
+		qat_req->input_param_count =
+				QAT_ASYM_MODINV_NUM_IN_PARAMS;
+		qat_req->output_param_count =
+				QAT_ASYM_MODINV_NUM_OUT_PARAMS;
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
-		QAT_DP_HEXDUMP_LOG(DEBUG, "base",
+		QAT_DP_HEXDUMP_LOG(DEBUG, "ModInv base",
 				cookie->input_array[0],
 				alg_size_in_bytes);
-		QAT_DP_HEXDUMP_LOG(DEBUG, "modulus",
+		QAT_DP_HEXDUMP_LOG(DEBUG, "ModInv modulus",
 				cookie->input_array[1],
 				alg_size_in_bytes);
 #endif
+	} else {
+		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
+		return -(EINVAL);
+	}
+	return 0;
+}
+
+int
+qat_asym_build_request(void *in_op,
+			uint8_t *out_msg,
+			void *op_cookie,
+			__rte_unused enum qat_device_gen qat_dev_gen)
+{
+	struct qat_asym_session *ctx;
+	struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
+	struct rte_crypto_asym_op *asym_op = op->asym;
+	struct icp_qat_fw_pke_request *qat_req =
+			(struct icp_qat_fw_pke_request *)out_msg;
+	struct qat_asym_op_cookie *cookie =
+				(struct qat_asym_op_cookie *)op_cookie;
+	int err = 0;
+
+	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
+	if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
+		ctx = (struct qat_asym_session *)
+			get_asym_session_private_data(
+			op->asym->session, cryptodev_qat_asym_driver_id);
+		if (unlikely(ctx == NULL)) {
+			QAT_LOG(ERR, "Session has not been created for this device");
+			goto error;
+		}
+		rte_mov64((uint8_t *)qat_req, (const uint8_t *)&(ctx->req_tmpl));
+		err = qat_asym_fill_arrays(asym_op, qat_req, cookie, ctx->xform);
+		if (err) {
+			op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			goto error;
+		}
+	} else if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
+		qat_fill_req_tmpl(qat_req);
+		err = qat_asym_fill_arrays(asym_op, qat_req, cookie,
+				op->asym->xform);
+		if (err) {
+			op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			goto error;
+		}
+	} else {
+		QAT_DP_LOG(ERR, "Invalid session/xform settings");
+		op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
+		goto error;
 	}
 
+	qat_req->pke_mid.opaque = (uint64_t)(uintptr_t)op;
+	qat_req->pke_mid.src_data_addr = cookie->input_addr;
+	qat_req->pke_mid.dest_data_addr = cookie->output_addr;
+
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
 	QAT_DP_HEXDUMP_LOG(DEBUG, "qat_req:", qat_req,
 			sizeof(struct icp_qat_fw_pke_request));
 #endif
+
 	return 0;
 error:
+
+	qat_req->pke_mid.opaque = (uint64_t)(uintptr_t)op;
+
+#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
+	QAT_DP_HEXDUMP_LOG(DEBUG, "qat_req:", qat_req,
+		sizeof(struct icp_qat_fw_pke_request));
+#endif
+
 	qat_req->output_param_count = 0;
 	qat_req->input_param_count = 0;
 	qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_NULL;
@@ -259,42 +306,16 @@ qat_asym_build_request(void *in_op,
 	return 0;
 }
 
-void
-qat_asym_process_response(void **op, uint8_t *resp,
-		void *op_cookie)
+static void qat_asym_collect_response(struct rte_crypto_op *rx_op,
+		struct qat_asym_op_cookie *cookie,
+		struct rte_crypto_asym_xform *xform)
 {
-	struct qat_asym_session *ctx;
-	struct icp_qat_fw_pke_resp *resp_msg =
-			(struct icp_qat_fw_pke_resp *)resp;
-	struct rte_crypto_op *rx_op = (struct rte_crypto_op *)(uintptr_t)
-			(resp_msg->opaque);
+	size_t alg_size, alg_size_in_bytes = 0;
 	struct rte_crypto_asym_op *asym_op = rx_op->asym;
-	struct qat_asym_op_cookie *cookie = op_cookie;
-	size_t alg_size, alg_size_in_bytes;
-
-	ctx = (struct qat_asym_session *)get_asym_session_private_data(
-			rx_op->asym->session, cryptodev_qat_asym_driver_id);
-
-	*op = rx_op;
-	rx_op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 
-	if (cookie->error) {
-		cookie->error = 0;
-		rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
-		QAT_DP_LOG(ERR, "Cookie status returned error");
-	} else {
-		if (ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(
-			resp_msg->pke_resp_hdr.resp_status.pke_resp_flags)) {
-			rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
-			QAT_DP_LOG(ERR, "Asymmetric response status returned error");
-		}
-		if (resp_msg->pke_resp_hdr.resp_status.comn_err_code) {
-			rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
-			QAT_DP_LOG(ERR, "Asymmetric common status returned error");
-		}
-	}
+	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
+		rte_crypto_param n = xform->modex.modulus;
 
-	if (ctx->alg == QAT_PKE_MODEXP) {
 		alg_size = cookie->alg_size;
 		alg_size_in_bytes = alg_size >> 3;
 		uint8_t *modexp_result = asym_op->modex.result.data;
@@ -302,42 +323,83 @@ qat_asym_process_response(void **op, uint8_t *resp,
 		if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED) {
 			rte_memcpy(modexp_result +
 				(asym_op->modex.result.length -
-					ctx->sess_alg_params.mod_exp.n.length),
+					n.length),
 				cookie->output_array[0] + alg_size_in_bytes
-				- ctx->sess_alg_params.mod_exp.n.length,
-				ctx->sess_alg_params.mod_exp.n.length
+				- n.length, n.length
 				);
 			rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
-			QAT_DP_HEXDUMP_LOG(DEBUG, "modexp_result",
+			QAT_DP_HEXDUMP_LOG(DEBUG, "ModExp result",
 					cookie->output_array[0],
 					alg_size_in_bytes);
+
 #endif
 		}
-		qat_clear_arrays(cookie, 3, 1, alg_size_in_bytes,
-				alg_size_in_bytes);
-	} else if (ctx->alg == QAT_PKE_MODINV) {
+	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
+		rte_crypto_param n = xform->modinv.modulus;
+
 		alg_size = cookie->alg_size;
 		alg_size_in_bytes = alg_size >> 3;
 		uint8_t *modinv_result = asym_op->modinv.result.data;
 
 		if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED) {
 			rte_memcpy(modinv_result + (asym_op->modinv.result.length
-				- ctx->sess_alg_params.mod_inv.n.length),
+				- n.length),
 				cookie->output_array[0] + alg_size_in_bytes
-				- ctx->sess_alg_params.mod_inv.n.length,
-				ctx->sess_alg_params.mod_inv.n.length);
+				- n.length, n.length);
 			rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
-			QAT_DP_HEXDUMP_LOG(DEBUG, "modinv_result",
+			QAT_DP_HEXDUMP_LOG(DEBUG, "ModInv result",
 					cookie->output_array[0],
 					alg_size_in_bytes);
 #endif
 		}
-		qat_clear_arrays(cookie, 2, 1, alg_size_in_bytes,
+	}
+	qat_clear_arrays_by_alg(cookie, xform->xform_type, alg_size_in_bytes,
 			alg_size_in_bytes);
+}
+
+void
+qat_asym_process_response(void **op, uint8_t *resp,
+		void *op_cookie)
+{
+	struct qat_asym_session *ctx;
+	struct icp_qat_fw_pke_resp *resp_msg =
+			(struct icp_qat_fw_pke_resp *)resp;
+	struct rte_crypto_op *rx_op = (struct rte_crypto_op *)(uintptr_t)
+			(resp_msg->opaque);
+	struct qat_asym_op_cookie *cookie = op_cookie;
+
+	if (cookie->error) {
+		cookie->error = 0;
+		if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
+			rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+		QAT_DP_LOG(ERR, "Cookie status returned error");
+	} else {
+		if (ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(
+			resp_msg->pke_resp_hdr.resp_status.pke_resp_flags)) {
+			if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
+				rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+			QAT_DP_LOG(ERR, "Asymmetric response status"
+					" returned error");
+		}
+		if (resp_msg->pke_resp_hdr.resp_status.comn_err_code) {
+			if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
+				rx_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+			QAT_DP_LOG(ERR, "Asymmetric common status"
+					" returned error");
+		}
 	}
 
+	if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
+		ctx = (struct qat_asym_session *)get_asym_session_private_data(
+				rx_op->asym->session, cryptodev_qat_asym_driver_id);
+		qat_asym_collect_response(rx_op, cookie, ctx->xform);
+	} else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
+		qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
+	}
+	*op = rx_op;
+
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
 	QAT_DP_HEXDUMP_LOG(DEBUG, "resp_msg:", resp_msg,
 			sizeof(struct icp_qat_fw_pke_resp));
@@ -362,10 +424,6 @@ qat_asym_session_configure(struct rte_cryptodev *dev,
 
 	session = sess_private_data;
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
-		session->sess_alg_params.mod_exp.e = xform->modex.exponent;
-		session->sess_alg_params.mod_exp.n = xform->modex.modulus;
-		session->alg = QAT_PKE_MODEXP;
-
 		if (xform->modex.exponent.length == 0 ||
 				xform->modex.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod exp input parameter");
@@ -373,20 +431,24 @@ qat_asym_session_configure(struct rte_cryptodev *dev,
 			goto error;
 		}
 	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
-		session->sess_alg_params.mod_inv.n = xform->modinv.modulus;
-		session->alg = QAT_PKE_MODINV;
-
 		if (xform->modinv.modulus.length == 0) {
 			QAT_LOG(ERR, "Invalid mod inv input parameter");
 			err = -EINVAL;
 			goto error;
 		}
-	} else {
+	} else if (xform->xform_type >= RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
+			|| xform->xform_type <= RTE_CRYPTO_ASYM_XFORM_NONE) {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
 		err = -EINVAL;
 		goto error;
+	} else {
+		QAT_LOG(ERR, "Asymmetric crypto xform not implemented");
+		err = -EINVAL;
+		goto error;
 	}
-	qat_asym_build_req_tmpl(sess_private_data, xform);
+
+	session->xform = xform;
+	qat_asym_build_req_tmpl(sess_private_data);
 	set_asym_session_private_data(sess, dev->driver_id,
 		sess_private_data);
 
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index ce4839b..2959b07 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -17,7 +17,11 @@ typedef uint64_t large_int_ptr;
 #define QAT_PKE_MAX_LN_SIZE 512
 #define _PKE_ALIGN_ __attribute__((__aligned__(8)))
 
-#define QAT_ASYM_ERROR_INVALID_PARAM	0x01
+#define QAT_ASYM_MAX_PARAMS			8
+#define QAT_ASYM_MODINV_NUM_IN_PARAMS		2
+#define QAT_ASYM_MODINV_NUM_OUT_PARAMS		1
+#define QAT_ASYM_MODEXP_NUM_IN_PARAMS		3
+#define QAT_ASYM_MODEXP_NUM_OUT_PARAMS		1
 
 struct qat_asym_op_cookie {
 	size_t alg_size;
@@ -33,27 +37,9 @@ struct qat_asym_op_cookie {
 	uint8_t output_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE] _PKE_ALIGN_;
 } _PKE_ALIGN_;
 
-enum qat_asym_alg {
-	QAT_PKE_RSA,
-	QAT_PKE_DH,
-	QAT_PKE_DSA,
-	QAT_PKE_MODEXP,
-	QAT_PKE_MODINV,
-};
-
 struct qat_asym_session {
-	enum qat_asym_alg alg;
 	struct icp_qat_fw_pke_request req_tmpl;
-	uint64_t flags;
-	union {
-		struct {
-			rte_crypto_param n;
-			rte_crypto_param e;
-		} mod_exp;
-		struct {
-			rte_crypto_param n;
-		} mod_inv;
-	} sess_alg_params;
+	struct rte_crypto_asym_xform *xform;
 };
 
 int
diff --git a/drivers/crypto/qat/qat_asym_pmd.c b/drivers/crypto/qat/qat_asym_pmd.c
index c999799..71fd709 100644
--- a/drivers/crypto/qat/qat_asym_pmd.c
+++ b/drivers/crypto/qat/qat_asym_pmd.c
@@ -270,7 +270,8 @@ qat_asym_dev_create(struct qat_pci_device *qat_pci_dev)
 	cryptodev->dequeue_burst = qat_asym_pmd_dequeue_op_burst;
 
 	cryptodev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
-			RTE_CRYPTODEV_FF_HW_ACCELERATED;
+			RTE_CRYPTODEV_FF_HW_ACCELERATED |
+			RTE_CRYPTODEV_FF_ASYM_SESSIONLESS;
 	internals = cryptodev->data->dev_private;
 	internals->qat_dev = qat_pci_dev;
 	qat_pci_dev->asym_dev = internals;
-- 
2.1.0


  reply	other threads:[~2019-10-22 14:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 14:04 [dpdk-dev] [PATCH v4 0/5] Add session-less, RSA, RSA-CRT to QAT Arek Kusztal
2019-10-22 14:04 ` Arek Kusztal [this message]
2019-10-22 14:04 ` [dpdk-dev] [PATCH v4 2/5] crypto/qat: add rsa implementation to asym pmd Arek Kusztal
2019-10-22 14:04 ` [dpdk-dev] [PATCH v4 3/5] crypto/qat: add rsa crt " Arek Kusztal
2019-10-22 14:04 ` [dpdk-dev] [PATCH v4 4/5] test/crypto: add sessionless to asymmetric mod exp Arek Kusztal
2019-10-22 14:04 ` [dpdk-dev] [PATCH v4 5/5] test/crypto: add rsa tests to qat and openssl with no padding Arek Kusztal
2019-10-23 13:42 ` [dpdk-dev] [PATCH v4 0/5] Add session-less, RSA, RSA-CRT to QAT Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191022140429.9008-2-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).