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 : : /* Tailroom required for RX-inject path.
22 : : * In RX-inject path, space is required for below entities:
23 : : * WQE header and NIX_RX_PARSE_S
24 : : * SG list format for 6 IOVA pointers
25 : : * Space for 128 byte alignment.
26 : : */
27 : : #define CNXK_CPT_MIN_TAILROOM_REQ 256
28 : : #define CNXK_CPT_MAX_SG_SEGS 6
29 : :
30 : : /* Default command timeout in seconds */
31 : : #define DEFAULT_COMMAND_TIMEOUT 4
32 : :
33 : : #define META_LEN 64
34 : :
35 : : #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
36 : :
37 : : #define CN10K_CPT_PKTS_PER_LOOP 64
38 : : #define CN20K_CPT_PKTS_PER_LOOP 64
39 : :
40 : : /* Macros to form words in CPT instruction */
41 : : #define CNXK_CPT_INST_W2(tag, tt, grp, rvu_pf_func) \
42 : : ((tag) | ((uint64_t)(tt) << 32) | ((uint64_t)(grp) << 34) | ((uint64_t)(rvu_pf_func) << 48))
43 : : #define CNXK_CPT_INST_W3(qord, wqe_ptr) (qord | ((uintptr_t)(wqe_ptr) >> 3) << 3)
44 : :
45 : : struct cpt_qp_meta_info {
46 : : struct rte_mempool *pool;
47 : : int mlen;
48 : : };
49 : :
50 : : #define CPT_OP_FLAGS_METABUF (1 << 1)
51 : : #define CPT_OP_FLAGS_AUTH_VERIFY (1 << 0)
52 : : #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
53 : : #define CPT_OP_FLAGS_IPSEC_INB_REPLAY (1 << 3)
54 : :
55 : : struct __rte_aligned(ROC_ALIGN) cpt_inflight_req {
56 : : union cpt_res_s res;
57 : : uint8_t rsvd[16];
58 : : uint8_t meta[META_LEN];
59 : : union {
60 : : void *opaque;
61 : : struct rte_crypto_op *cop;
62 : : struct rte_event_vector *vec;
63 : : };
64 : : void *qp;
65 : : void *mdata;
66 : : uint8_t op_flags;
67 : : #ifdef CPT_INST_DEBUG_ENABLE
68 : : uint8_t scatter_sz;
69 : : uint8_t opcode_major;
70 : : uint8_t is_sg_ver2;
71 : : uint8_t *dptr;
72 : : uint8_t *rptr;
73 : : #endif
74 : : };
75 : :
76 : : PLT_STATIC_ASSERT(sizeof(struct cpt_inflight_req) == ROC_CACHE_LINE_SZ);
77 : : PLT_STATIC_ASSERT(offsetof(struct cpt_inflight_req, meta) == 32);
78 : :
79 : : struct pending_queue {
80 : : /** Array of pending requests */
81 : : struct cpt_inflight_req *req_queue;
82 : : /** Head of the queue to be used for enqueue */
83 : : uint64_t head;
84 : : /** Tail of the queue to be used for dequeue */
85 : : uint64_t tail;
86 : : /** Pending queue mask */
87 : : uint64_t pq_mask;
88 : : /** Timeout to track h/w being unresponsive */
89 : : uint64_t time_out;
90 : : };
91 : :
92 : : struct crypto_adpter_info {
93 : : bool enabled;
94 : : /**< Set if queue pair is added to crypto adapter */
95 : : struct rte_mempool *req_mp;
96 : : /**< CPT inflight request mempool */
97 : : uint16_t vector_sz;
98 : : /** Maximum number of cops to combine into single vector */
99 : : struct rte_mempool *vector_mp;
100 : : /** Pool for allocating rte_event_vector */
101 : : uint64_t vector_timeout_ns;
102 : : /*
103 : : * Maximum number of nanoseconds to wait for aggregating
104 : : * crypto operations.
105 : : */
106 : : };
107 : :
108 : : struct cnxk_cpt_qp {
109 : : struct roc_cpt_lf lf;
110 : : /**< Crypto LF */
111 : : bool inst_cq_ena;
112 : : /**< Set CQ enable bit on instructions */
113 : : struct pending_queue pend_q;
114 : : /**< Pending queue */
115 : : struct roc_cpt_lmtline lmtline;
116 : : /**< Lmtline information */
117 : : struct cpt_qp_meta_info meta_info;
118 : : /**< Metabuf info required to support operations on the queue pair */
119 : : struct crypto_adpter_info ca;
120 : : /**< Crypto adapter related info */
121 : : struct rte_mempool *sess_mp;
122 : : /**< Session mempool */
123 : : struct cnxk_sso_evdev *evdev;
124 : : };
125 : :
126 : : int cnxk_cpt_asym_get_mlen(void);
127 : :
128 : : int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
129 : : struct rte_cryptodev_config *conf);
130 : :
131 : : int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
132 : :
133 : : void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
134 : :
135 : : int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
136 : :
137 : : void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
138 : : struct rte_cryptodev_info *info);
139 : :
140 : : int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
141 : : const struct rte_cryptodev_qp_conf *conf,
142 : : int socket_id __rte_unused);
143 : :
144 : : int cnxk_cpt_queue_pair_reset(struct rte_cryptodev *dev, uint16_t qp_id,
145 : : const struct rte_cryptodev_qp_conf *conf, int socket_id);
146 : :
147 : : int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
148 : :
149 : : unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
150 : :
151 : : int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform,
152 : : struct rte_cryptodev_sym_session *sess);
153 : :
154 : : int sym_session_configure(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
155 : : struct rte_cryptodev_sym_session *sess, bool is_session_less);
156 : :
157 : : void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess);
158 : :
159 : : void sym_session_clear(struct rte_cryptodev_sym_session *sess, bool is_session_less);
160 : :
161 : : unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
162 : :
163 : : void cnxk_ae_session_clear(struct rte_cryptodev *dev,
164 : : struct rte_cryptodev_asym_session *sess);
165 : : int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
166 : : struct rte_crypto_asym_xform *xform,
167 : : struct rte_cryptodev_asym_session *sess);
168 : : void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
169 : : int cnxk_cpt_queue_pair_event_error_query(struct rte_cryptodev *dev, uint16_t qp_id);
170 : :
171 : : uint32_t cnxk_cpt_qp_depth_used(void *qptr);
172 : :
173 : : #ifdef CPT_INST_DEBUG_ENABLE
174 : : void cnxk_cpt_request_data_sg_mode_dump(uint8_t *in_buffer, bool glist);
175 : :
176 : : void cnxk_cpt_request_data_sgv2_mode_dump(uint8_t *in_buffer, bool glist, uint16_t components);
177 : : #endif
178 : :
179 : : static __rte_always_inline void
180 : : pending_queue_advance(uint64_t *index, const uint64_t mask)
181 : : {
182 : 0 : *index = (*index + 1) & mask;
183 : : }
184 : :
185 : : static __rte_always_inline void
186 : : pending_queue_retreat(uint64_t *index, const uint64_t mask, uint64_t nb_entry)
187 : : {
188 : 0 : *index = (*index - nb_entry) & mask;
189 : 0 : }
190 : :
191 : : static __rte_always_inline uint64_t
192 : : pending_queue_infl_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
193 : : {
194 : : /*
195 : : * Mask is nb_desc - 1. Add nb_desc to head and mask to account for
196 : : * cases when tail > head, which happens during wrap around.
197 : : */
198 [ # # # # : 0 : return ((head + mask + 1) - tail) & mask;
# # # # ]
199 : : }
200 : :
201 : : static __rte_always_inline uint64_t
202 : : pending_queue_free_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
203 : : {
204 : : /* mask is nb_desc - 1 */
205 : : return mask - pending_queue_infl_cnt(head, tail, mask);
206 : : }
207 : :
208 : : static __rte_always_inline void *
209 : : alloc_op_meta(struct roc_se_buf_ptr *buf, int32_t len, struct rte_mempool *cpt_meta_pool,
210 : : struct cpt_inflight_req *infl_req)
211 : : {
212 : : uint8_t *mdata;
213 : :
214 [ # # # # : 0 : if (unlikely(rte_mempool_get(cpt_meta_pool, (void **)&mdata) < 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
215 : : return NULL;
216 : :
217 : : if (likely(buf)) {
218 : 0 : buf->vaddr = mdata;
219 : 0 : buf->size = len;
220 : : }
221 : :
222 : 0 : infl_req->mdata = mdata;
223 [ # # # # : 0 : infl_req->op_flags |= CPT_OP_FLAGS_METABUF;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
224 : :
225 : 0 : return mdata;
226 : : }
227 : :
228 : : static __rte_always_inline bool
229 : : hw_ctx_cache_enable(void)
230 : : {
231 [ # # # # : 0 : return roc_errata_cpt_hang_on_mixed_ctx_val() || roc_model_is_cn10ka_b0() ||
# # # # #
# # # ]
232 [ # # # # : 0 : roc_model_is_cn10kb_a0() || roc_model_is_cn20k();
# # # # #
# # # # #
# # # # ]
233 : : }
234 : :
235 : : static inline uint64_t
236 : : cnxk_cpt_sec_inst_w7_get(struct roc_cpt *roc_cpt, void *cptr)
237 : : {
238 : : union cpt_inst_w7 w7;
239 : :
240 [ # # # # ]: 0 : w7.u64 = 0;
241 [ # # # # ]: 0 : if (roc_model_is_cn20k())
242 : 0 : w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
243 : : else
244 : 0 : w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
245 : 0 : w7.s.ctx_val = 1;
246 : 0 : w7.s.cptr = (uint64_t)cptr;
247 : : rte_mb();
248 : :
249 [ # # # # ]: 0 : return w7.u64;
250 : : }
251 : :
252 : : static inline void
253 : : pktmbuf_trim_chain(struct rte_mbuf *m, uint16_t len)
254 : : {
255 : : uint16_t len_so_far = 0, left_over = 0, new_mlen;
256 : : struct rte_mbuf *cur = m;
257 : :
258 : 0 : new_mlen = m->pkt_len - len;
259 : :
260 [ # # # # ]: 0 : while (len_so_far < new_mlen) {
261 : 0 : left_over = new_mlen - len_so_far;
262 [ # # # # ]: 0 : if (left_over < cur->data_len)
263 : : break;
264 : 0 : len_so_far += cur->data_len;
265 : 0 : cur = cur->next;
266 : : }
267 : :
268 : 0 : cur->data_len = left_over;
269 : 0 : cur = cur->next;
270 [ # # # # ]: 0 : while (cur) {
271 : 0 : cur->data_len = 0;
272 : 0 : cur = cur->next;
273 : : }
274 : :
275 : 0 : m->pkt_len = new_mlen;
276 : 0 : }
277 : : #endif /* _CNXK_CRYPTODEV_OPS_H_ */
|