xref: /f-stack/dpdk/drivers/crypto/qat/qat_asym.h (revision 2d9fd380)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4 
5 #ifndef _QAT_ASYM_H_
6 #define _QAT_ASYM_H_
7 
8 #include <rte_cryptodev_pmd.h>
9 #include <rte_crypto_asym.h>
10 #include "icp_qat_fw_pke.h"
11 #include "qat_common.h"
12 #include "qat_asym_pmd.h"
13 #include "icp_qat_fw.h"
14 
15 typedef uint64_t large_int_ptr;
16 #define MAX_PKE_PARAMS	8
17 #define QAT_PKE_MAX_LN_SIZE 512
18 #define _PKE_ALIGN_ __rte_aligned(8)
19 
20 #define QAT_ASYM_MAX_PARAMS			8
21 #define QAT_ASYM_MODINV_NUM_IN_PARAMS		2
22 #define QAT_ASYM_MODINV_NUM_OUT_PARAMS		1
23 #define QAT_ASYM_MODEXP_NUM_IN_PARAMS		3
24 #define QAT_ASYM_MODEXP_NUM_OUT_PARAMS		1
25 #define QAT_ASYM_RSA_NUM_IN_PARAMS		3
26 #define QAT_ASYM_RSA_NUM_OUT_PARAMS		1
27 #define QAT_ASYM_RSA_QT_NUM_IN_PARAMS		6
28 
29 struct qat_asym_op_cookie {
30 	size_t alg_size;
31 	uint64_t error;
32 	rte_iova_t input_addr;
33 	rte_iova_t output_addr;
34 	large_int_ptr input_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
35 	large_int_ptr output_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
36 	union {
37 		uint8_t input_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE];
38 		uint8_t input_buffer[MAX_PKE_PARAMS * QAT_PKE_MAX_LN_SIZE];
39 	} _PKE_ALIGN_;
40 	uint8_t output_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE] _PKE_ALIGN_;
41 } _PKE_ALIGN_;
42 
43 struct qat_asym_session {
44 	struct icp_qat_fw_pke_request req_tmpl;
45 	struct rte_crypto_asym_xform *xform;
46 };
47 
48 int
49 qat_asym_session_configure(struct rte_cryptodev *dev,
50 		struct rte_crypto_asym_xform *xform,
51 		struct rte_cryptodev_asym_session *sess,
52 		struct rte_mempool *mempool);
53 
54 unsigned int
55 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
56 
57 void
58 qat_asym_session_clear(struct rte_cryptodev *dev,
59 		struct rte_cryptodev_asym_session *sess);
60 
61 /*
62  * Build PKE request to be sent to the fw, partially uses template
63  * request generated during session creation.
64  *
65  * @param	in_op		Pointer to the crypto operation, for every
66  *				service it points to service specific struct.
67  * @param	out_msg		Message to be returned to enqueue function
68  * @param	op_cookie	Cookie pointer that holds private metadata
69  * @param	qat_dev_gen	Generation of QAT hardware
70  *
71  * @return
72  *	This function always returns zero,
73  *	it is because of backward compatibility.
74  *	- 0: Always returned
75  *
76  */
77 int
78 qat_asym_build_request(void *in_op, uint8_t *out_msg,
79 		void *op_cookie, enum qat_device_gen qat_dev_gen);
80 
81 /*
82  * Process PKE response received from outgoing queue of QAT
83  *
84  * @param	op		a ptr to the rte_crypto_op referred to by
85  *				the response message is returned in this param
86  * @param	resp		icp_qat_fw_pke_resp message received from
87  *				outgoing fw message queue
88  * @param	op_cookie	Cookie pointer that holds private metadata
89  *
90  */
91 void
92 qat_asym_process_response(void __rte_unused **op, uint8_t *resp,
93 		void *op_cookie);
94 
95 #endif /* _QAT_ASYM_H_ */
96