event/dpaa: support Tx adapter
[dpdk.git] / drivers / crypto / qat / qat_asym.h
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_ __attribute__((__aligned__(8)))
19
20 #define QAT_ASYM_ERROR_INVALID_PARAM    0x01
21
22 struct qat_asym_op_cookie {
23         size_t alg_size;
24         uint64_t error;
25         rte_iova_t input_addr;
26         rte_iova_t output_addr;
27         large_int_ptr input_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
28         large_int_ptr output_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
29         union {
30                 uint8_t input_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE];
31                 uint8_t input_buffer[MAX_PKE_PARAMS * QAT_PKE_MAX_LN_SIZE];
32         } _PKE_ALIGN_;
33         uint8_t output_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE] _PKE_ALIGN_;
34 } _PKE_ALIGN_;
35
36 enum qat_asym_alg {
37         QAT_PKE_RSA,
38         QAT_PKE_DH,
39         QAT_PKE_DSA,
40         QAT_PKE_MODEXP,
41         QAT_PKE_MODINV,
42 };
43
44 struct qat_asym_session {
45         enum qat_asym_alg alg;
46         struct icp_qat_fw_pke_request req_tmpl;
47         uint64_t flags;
48         union {
49                 struct {
50                         rte_crypto_param n;
51                         rte_crypto_param e;
52                 } mod_exp;
53                 struct {
54                         rte_crypto_param n;
55                 } mod_inv;
56         } sess_alg_params;
57 };
58
59 int
60 qat_asym_session_configure(struct rte_cryptodev *dev,
61                 struct rte_crypto_asym_xform *xform,
62                 struct rte_cryptodev_asym_session *sess,
63                 struct rte_mempool *mempool);
64
65 unsigned int
66 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
67
68 void
69 qat_asym_session_clear(struct rte_cryptodev *dev,
70                 struct rte_cryptodev_asym_session *sess);
71
72 /*
73  * Build PKE request to be sent to the fw, partially uses template
74  * request generated during session creation.
75  *
76  * @param       in_op           Pointer to the crypto operation, for every
77  *                              service it points to service specific struct.
78  * @param       out_msg         Message to be returned to enqueue function
79  * @param       op_cookie       Cookie pointer that holds private metadata
80  * @param       qat_dev_gen     Generation of QAT hardware
81  *
82  * @return
83  *      This function always returns zero,
84  *      it is because of backward compatibility.
85  *      - 0: Always returned
86  *
87  */
88 int
89 qat_asym_build_request(void *in_op, uint8_t *out_msg,
90                 void *op_cookie, enum qat_device_gen qat_dev_gen);
91
92 /*
93  * Process PKE response received from outgoing queue of QAT
94  *
95  * @param       op              a ptr to the rte_crypto_op referred to by
96  *                              the response message is returned in this param
97  * @param       resp            icp_qat_fw_pke_resp message received from
98  *                              outgoing fw message queue
99  * @param       op_cookie       Cookie pointer that holds private metadata
100  *
101  */
102 void
103 qat_asym_process_response(void __rte_unused **op, uint8_t *resp,
104                 void *op_cookie);
105
106 #endif /* _QAT_ASYM_H_ */