crypto/cnxk: allow different cores in pending queue
[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 #include <rte_event_crypto_adapter.h>
10
11 #include "roc_api.h"
12
13 #define CNXK_CPT_MIN_HEADROOM_REQ 24
14 #define CNXK_CPT_MIN_TAILROOM_REQ 102
15
16 /* Default command timeout in seconds */
17 #define DEFAULT_COMMAND_TIMEOUT 4
18
19 #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
20
21 /* Macros to form words in CPT instruction */
22 #define CNXK_CPT_INST_W2(tag, tt, grp, rvu_pf_func)                            \
23         ((tag) | ((uint64_t)(tt) << 32) | ((uint64_t)(grp) << 34) |            \
24          ((uint64_t)(rvu_pf_func) << 48))
25 #define CNXK_CPT_INST_W3(qord, wqe_ptr)                                        \
26         (qord | ((uintptr_t)(wqe_ptr) >> 3) << 3)
27
28 struct cpt_qp_meta_info {
29         struct rte_mempool *pool;
30         int mlen;
31 };
32
33 enum sym_xform_type {
34         CNXK_CPT_CIPHER = 1,
35         CNXK_CPT_AUTH,
36         CNXK_CPT_AEAD,
37         CNXK_CPT_CIPHER_ENC_AUTH_GEN,
38         CNXK_CPT_AUTH_VRFY_CIPHER_DEC,
39         CNXK_CPT_AUTH_GEN_CIPHER_ENC,
40         CNXK_CPT_CIPHER_DEC_AUTH_VRFY
41 };
42
43 #define CPT_OP_FLAGS_METABUF           (1 << 1)
44 #define CPT_OP_FLAGS_AUTH_VERIFY       (1 << 0)
45 #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
46
47 struct cpt_inflight_req {
48         union cpt_res_s res;
49         struct rte_crypto_op *cop;
50         void *mdata;
51         uint8_t op_flags;
52         void *qp;
53 } __rte_aligned(16);
54
55 struct pending_queue {
56         /** Array of pending requests */
57         struct cpt_inflight_req *req_queue;
58         /** Head of the queue to be used for enqueue */
59         uint64_t head;
60         /** Tail of the queue to be used for dequeue */
61         uint64_t tail;
62         /** Pending queue mask */
63         uint64_t pq_mask;
64         /** Timeout to track h/w being unresponsive */
65         uint64_t time_out;
66 };
67
68 struct crypto_adpter_info {
69         bool enabled;
70         /**< Set if queue pair is added to crypto adapter */
71         struct rte_mempool *req_mp;
72         /**< CPT inflight request mempool */
73 };
74
75 struct cnxk_cpt_qp {
76         struct roc_cpt_lf lf;
77         /**< Crypto LF */
78         struct pending_queue pend_q;
79         /**< Pending queue */
80         struct rte_mempool *sess_mp;
81         /**< Session mempool */
82         struct rte_mempool *sess_mp_priv;
83         /**< Session private data mempool */
84         struct cpt_qp_meta_info meta_info;
85         /**< Metabuf info required to support operations on the queue pair */
86         struct roc_cpt_lmtline lmtline;
87         /**< Lmtline information */
88         struct crypto_adpter_info ca;
89         /**< Crypto adapter related info */
90 };
91
92 int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
93                         struct rte_cryptodev_config *conf);
94
95 int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
96
97 void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
98
99 int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
100
101 void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
102                            struct rte_cryptodev_info *info);
103
104 int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
105                               const struct rte_cryptodev_qp_conf *conf,
106                               int socket_id __rte_unused);
107
108 int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
109
110 unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
111
112 int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
113                                    struct rte_crypto_sym_xform *xform,
114                                    struct rte_cryptodev_sym_session *sess,
115                                    struct rte_mempool *pool);
116
117 int sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
118                           struct rte_crypto_sym_xform *xform,
119                           struct rte_cryptodev_sym_session *sess,
120                           struct rte_mempool *pool);
121
122 void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
123                                 struct rte_cryptodev_sym_session *sess);
124
125 void sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess);
126
127 unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
128
129 void cnxk_ae_session_clear(struct rte_cryptodev *dev,
130                            struct rte_cryptodev_asym_session *sess);
131 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
132                         struct rte_crypto_asym_xform *xform,
133                         struct rte_cryptodev_asym_session *sess,
134                         struct rte_mempool *pool);
135
136 static inline union rte_event_crypto_metadata *
137 cnxk_event_crypto_mdata_get(struct rte_crypto_op *op)
138 {
139         union rte_event_crypto_metadata *ec_mdata;
140
141         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
142                 ec_mdata = rte_cryptodev_sym_session_get_user_data(
143                         op->sym->session);
144         else if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS &&
145                  op->private_data_offset)
146                 ec_mdata = (union rte_event_crypto_metadata
147                                     *)((uint8_t *)op + op->private_data_offset);
148         else
149                 return NULL;
150
151         return ec_mdata;
152 }
153
154 static __rte_always_inline void
155 pending_queue_advance(uint64_t *index, const uint64_t mask)
156 {
157         *index = (*index + 1) & mask;
158 }
159
160 static __rte_always_inline void
161 pending_queue_retreat(uint64_t *index, const uint64_t mask, uint64_t nb_entry)
162 {
163         *index = (*index - nb_entry) & mask;
164 }
165
166 static __rte_always_inline uint64_t
167 pending_queue_infl_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
168 {
169         return (head - tail) & mask;
170 }
171
172 static __rte_always_inline uint64_t
173 pending_queue_free_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
174 {
175         /* mask is nb_desc - 1 */
176         return mask - pending_queue_infl_cnt(head, tail, mask);
177 }
178
179 #endif /* _CNXK_CRYPTODEV_OPS_H_ */