Branch data Line data Source code
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 <cryptodev_pmd.h>
9 : : #include <rte_event_crypto_adapter.h>
10 : :
11 : : #include "hw/cpt.h"
12 : :
13 : : #include "roc_constants.h"
14 : : #include "roc_cpt.h"
15 : : #include "roc_cpt_sg.h"
16 : : #include "roc_errata.h"
17 : : #include "roc_se.h"
18 : :
19 : : /* Space for ctrl_word(8B), IV(48B), passthrough alignment(8B) */
20 : : #define CNXK_CPT_MIN_HEADROOM_REQ 64
21 : : #define CNXK_CPT_MIN_TAILROOM_REQ 102
22 : :
23 : : /* Default command timeout in seconds */
24 : : #define DEFAULT_COMMAND_TIMEOUT 4
25 : :
26 : : #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
27 : :
28 : : /* Macros to form words in CPT instruction */
29 : : #define CNXK_CPT_INST_W2(tag, tt, grp, rvu_pf_func) \
30 : : ((tag) | ((uint64_t)(tt) << 32) | ((uint64_t)(grp) << 34) | \
31 : : ((uint64_t)(rvu_pf_func) << 48))
32 : : #define CNXK_CPT_INST_W3(qord, wqe_ptr) \
33 : : (qord | ((uintptr_t)(wqe_ptr) >> 3) << 3)
34 : :
35 : : struct cpt_qp_meta_info {
36 : : struct rte_mempool *pool;
37 : : int mlen;
38 : : };
39 : :
40 : : #define CPT_OP_FLAGS_METABUF (1 << 1)
41 : : #define CPT_OP_FLAGS_AUTH_VERIFY (1 << 0)
42 : : #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
43 : : #define CPT_OP_FLAGS_IPSEC_INB_REPLAY (1 << 3)
44 : :
45 : : struct cpt_inflight_req {
46 : : union cpt_res_s res;
47 : : union {
48 : : void *opaque;
49 : : struct rte_crypto_op *cop;
50 : : struct rte_event_vector *vec;
51 : : };
52 : : void *mdata;
53 : : uint8_t op_flags;
54 : : #ifdef CPT_INST_DEBUG_ENABLE
55 : : uint8_t scatter_sz;
56 : : uint8_t opcode_major;
57 : : uint8_t is_sg_ver2;
58 : : uint8_t *dptr;
59 : : uint8_t *rptr;
60 : : #endif
61 : : void *qp;
62 : : } __rte_aligned(ROC_ALIGN);
63 : :
64 : : PLT_STATIC_ASSERT(sizeof(struct cpt_inflight_req) == ROC_CACHE_LINE_SZ);
65 : :
66 : : struct pending_queue {
67 : : /** Array of pending requests */
68 : : struct cpt_inflight_req *req_queue;
69 : : /** Head of the queue to be used for enqueue */
70 : : uint64_t head;
71 : : /** Tail of the queue to be used for dequeue */
72 : : uint64_t tail;
73 : : /** Pending queue mask */
74 : : uint64_t pq_mask;
75 : : /** Timeout to track h/w being unresponsive */
76 : : uint64_t time_out;
77 : : };
78 : :
79 : : struct crypto_adpter_info {
80 : : bool enabled;
81 : : /**< Set if queue pair is added to crypto adapter */
82 : : struct rte_mempool *req_mp;
83 : : /**< CPT inflight request mempool */
84 : : uint16_t vector_sz;
85 : : /** Maximum number of cops to combine into single vector */
86 : : struct rte_mempool *vector_mp;
87 : : /** Pool for allocating rte_event_vector */
88 : : };
89 : :
90 : : struct cnxk_cpt_qp {
91 : : struct roc_cpt_lf lf;
92 : : /**< Crypto LF */
93 : : struct pending_queue pend_q;
94 : : /**< Pending queue */
95 : : struct roc_cpt_lmtline lmtline;
96 : : /**< Lmtline information */
97 : : struct cpt_qp_meta_info meta_info;
98 : : /**< Metabuf info required to support operations on the queue pair */
99 : : struct crypto_adpter_info ca;
100 : : /**< Crypto adapter related info */
101 : : struct rte_mempool *sess_mp;
102 : : /**< Session mempool */
103 : : };
104 : :
105 : : int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
106 : : struct rte_cryptodev_config *conf);
107 : :
108 : : int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
109 : :
110 : : void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
111 : :
112 : : int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
113 : :
114 : : void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
115 : : struct rte_cryptodev_info *info);
116 : :
117 : : int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
118 : : const struct rte_cryptodev_qp_conf *conf,
119 : : int socket_id __rte_unused);
120 : :
121 : : int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
122 : :
123 : : unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
124 : :
125 : : int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform,
126 : : struct rte_cryptodev_sym_session *sess);
127 : :
128 : : int sym_session_configure(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
129 : : struct rte_cryptodev_sym_session *sess, bool is_session_less);
130 : :
131 : : void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess);
132 : :
133 : : void sym_session_clear(struct rte_cryptodev_sym_session *sess, bool is_session_less);
134 : :
135 : : unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
136 : :
137 : : void cnxk_ae_session_clear(struct rte_cryptodev *dev,
138 : : struct rte_cryptodev_asym_session *sess);
139 : : int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
140 : : struct rte_crypto_asym_xform *xform,
141 : : struct rte_cryptodev_asym_session *sess);
142 : : void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
143 : : int cnxk_cpt_queue_pair_event_error_query(struct rte_cryptodev *dev, uint16_t qp_id);
144 : :
145 : : static __rte_always_inline void
146 : : pending_queue_advance(uint64_t *index, const uint64_t mask)
147 : : {
148 : 0 : *index = (*index + 1) & mask;
149 : : }
150 : :
151 : : static __rte_always_inline void
152 : : pending_queue_retreat(uint64_t *index, const uint64_t mask, uint64_t nb_entry)
153 : : {
154 : 0 : *index = (*index - nb_entry) & mask;
155 : 0 : }
156 : :
157 : : static __rte_always_inline uint64_t
158 : : pending_queue_infl_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
159 : : {
160 : : /*
161 : : * Mask is nb_desc - 1. Add nb_desc to head and mask to account for
162 : : * cases when tail > head, which happens during wrap around.
163 : : */
164 [ # # # # : 0 : return ((head + mask + 1) - tail) & mask;
# # # # ]
165 : : }
166 : :
167 : : static __rte_always_inline uint64_t
168 : : pending_queue_free_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
169 : : {
170 : : /* mask is nb_desc - 1 */
171 : : return mask - pending_queue_infl_cnt(head, tail, mask);
172 : : }
173 : :
174 : : static __rte_always_inline void *
175 : : alloc_op_meta(struct roc_se_buf_ptr *buf, int32_t len, struct rte_mempool *cpt_meta_pool,
176 : : struct cpt_inflight_req *infl_req)
177 : : {
178 : : uint8_t *mdata;
179 : :
180 [ # # # # : 0 : if (unlikely(rte_mempool_get(cpt_meta_pool, (void **)&mdata) < 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
181 : : return NULL;
182 : :
183 : : if (likely(buf)) {
184 : 0 : buf->vaddr = mdata;
185 : 0 : buf->size = len;
186 : : }
187 : :
188 : 0 : infl_req->mdata = mdata;
189 [ # # # # : 0 : infl_req->op_flags |= CPT_OP_FLAGS_METABUF;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
190 : :
191 : 0 : return mdata;
192 : : }
193 : :
194 : : static __rte_always_inline bool
195 : : hw_ctx_cache_enable(void)
196 : : {
197 [ # # # # : 0 : return roc_errata_cpt_hang_on_mixed_ctx_val() || roc_model_is_cn10ka_b0() ||
# # # # #
# # # # #
# # # # #
# # # #
# ]
198 : : roc_model_is_cn10kb_a0();
199 : : }
200 : : #endif /* _CNXK_CRYPTODEV_OPS_H_ */
|