79959590d6230e8237202506676ef0690582e326
[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 cnxk_cpt_qp {
59         struct roc_cpt_lf lf;
60         /**< Crypto LF */
61         struct pending_queue pend_q;
62         /**< Pending queue */
63         struct rte_mempool *sess_mp;
64         /**< Session mempool */
65         struct rte_mempool *sess_mp_priv;
66         /**< Session private data mempool */
67         struct cpt_qp_meta_info meta_info;
68         /**< Metabuf info required to support operations on the queue pair */
69         struct roc_cpt_lmtline lmtline;
70         /**< Lmtline information */
71 };
72
73 int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
74                         struct rte_cryptodev_config *conf);
75
76 int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
77
78 void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
79
80 int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
81
82 void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
83                            struct rte_cryptodev_info *info);
84
85 int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
86                               const struct rte_cryptodev_qp_conf *conf,
87                               int socket_id __rte_unused);
88
89 int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
90
91 unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
92
93 int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
94                                    struct rte_crypto_sym_xform *xform,
95                                    struct rte_cryptodev_sym_session *sess,
96                                    struct rte_mempool *pool);
97
98 int sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
99                           struct rte_crypto_sym_xform *xform,
100                           struct rte_cryptodev_sym_session *sess,
101                           struct rte_mempool *pool);
102
103 void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
104                                 struct rte_cryptodev_sym_session *sess);
105
106 void sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess);
107
108 #endif /* _CNXK_CRYPTODEV_OPS_H_ */