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