event/cnxk: add crypto adapter operations
[dpdk.git] / drivers / crypto / cnxk / cnxk_cryptodev_ops.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef _CNXK_CRYPTODEV_OPS_H_
6 #define _CNXK_CRYPTODEV_OPS_H_
7
8 #include <rte_cryptodev.h>
9
10 #include "roc_api.h"
11
12 #define CNXK_CPT_MIN_HEADROOM_REQ 24
13
14 /* Default command timeout in seconds */
15 #define DEFAULT_COMMAND_TIMEOUT 4
16
17 #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
18
19 struct cpt_qp_meta_info {
20         struct rte_mempool *pool;
21         int mlen;
22 };
23
24 enum sym_xform_type {
25         CNXK_CPT_CIPHER = 1,
26         CNXK_CPT_AUTH,
27         CNXK_CPT_AEAD,
28         CNXK_CPT_CIPHER_ENC_AUTH_GEN,
29         CNXK_CPT_AUTH_VRFY_CIPHER_DEC,
30         CNXK_CPT_AUTH_GEN_CIPHER_ENC,
31         CNXK_CPT_CIPHER_DEC_AUTH_VRFY
32 };
33
34 #define CPT_OP_FLAGS_METABUF           (1 << 1)
35 #define CPT_OP_FLAGS_AUTH_VERIFY       (1 << 0)
36 #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
37
38 struct cpt_inflight_req {
39         union cpt_res_s res;
40         struct rte_crypto_op *cop;
41         void *mdata;
42         uint8_t op_flags;
43 } __rte_aligned(16);
44
45 struct pending_queue {
46         /** Pending requests count */
47         uint64_t pending_count;
48         /** Array of pending requests */
49         struct cpt_inflight_req *req_queue;
50         /** Tail of queue to be used for enqueue */
51         uint16_t enq_tail;
52         /** Head of queue to be used for dequeue */
53         uint16_t deq_head;
54         /** Timeout to track h/w being unresponsive */
55         uint64_t time_out;
56 };
57
58 struct crypto_adpter_info {
59         bool enabled;
60         /**< Set if queue pair is added to crypto adapter */
61         struct rte_mempool *req_mp;
62         /**< CPT inflight request mempool */
63 };
64
65 struct cnxk_cpt_qp {
66         struct roc_cpt_lf lf;
67         /**< Crypto LF */
68         struct pending_queue pend_q;
69         /**< Pending queue */
70         struct rte_mempool *sess_mp;
71         /**< Session mempool */
72         struct rte_mempool *sess_mp_priv;
73         /**< Session private data mempool */
74         struct cpt_qp_meta_info meta_info;
75         /**< Metabuf info required to support operations on the queue pair */
76         struct roc_cpt_lmtline lmtline;
77         /**< Lmtline information */
78         struct crypto_adpter_info ca;
79         /**< Crypto adapter related info */
80 };
81
82 int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
83                         struct rte_cryptodev_config *conf);
84
85 int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
86
87 void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
88
89 int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
90
91 void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
92                            struct rte_cryptodev_info *info);
93
94 int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
95                               const struct rte_cryptodev_qp_conf *conf,
96                               int socket_id __rte_unused);
97
98 int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
99
100 unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
101
102 int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
103                                    struct rte_crypto_sym_xform *xform,
104                                    struct rte_cryptodev_sym_session *sess,
105                                    struct rte_mempool *pool);
106
107 int sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
108                           struct rte_crypto_sym_xform *xform,
109                           struct rte_cryptodev_sym_session *sess,
110                           struct rte_mempool *pool);
111
112 void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
113                                 struct rte_cryptodev_sym_session *sess);
114
115 void sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess);
116
117 unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
118
119 void cnxk_ae_session_clear(struct rte_cryptodev *dev,
120                            struct rte_cryptodev_asym_session *sess);
121 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
122                         struct rte_crypto_asym_xform *xform,
123                         struct rte_cryptodev_asym_session *sess,
124                         struct rte_mempool *pool);
125 #endif /* _CNXK_CRYPTODEV_OPS_H_ */