Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include <cryptodev_pmd.h>
6 : : #include <rte_cryptodev.h>
7 : : #include <rte_event_crypto_adapter.h>
8 : : #include <rte_hexdump.h>
9 : : #include <rte_ip.h>
10 : :
11 : : #include <ethdev_driver.h>
12 : :
13 : : #include "roc_cpt.h"
14 : : #if defined(__aarch64__)
15 : : #include "roc_io.h"
16 : : #else
17 : : #include "roc_io_generic.h"
18 : : #endif
19 : : #include "roc_idev.h"
20 : : #include "roc_sso.h"
21 : : #include "roc_sso_dp.h"
22 : :
23 : : #include "cn10k_cryptodev.h"
24 : : #include "cn10k_cryptodev_event_dp.h"
25 : : #include "cn10k_cryptodev_ops.h"
26 : : #include "cn10k_cryptodev_sec.h"
27 : : #include "cn10k_eventdev.h"
28 : : #include "cn10k_ipsec.h"
29 : : #include "cn10k_ipsec_la_ops.h"
30 : : #include "cn10k_tls.h"
31 : : #include "cn10k_tls_ops.h"
32 : : #include "cnxk_ae.h"
33 : : #include "cnxk_cryptodev.h"
34 : : #include "cnxk_cryptodev_ops.h"
35 : : #include "cnxk_eventdev.h"
36 : : #include "cnxk_se.h"
37 : :
38 : : #include "rte_pmd_cnxk_crypto.h"
39 : :
40 : : /* Holds information required to send crypto operations in one burst */
41 : : struct ops_burst {
42 : : struct rte_crypto_op *op[CN10K_PKTS_PER_LOOP];
43 : : uint64_t w2[CN10K_PKTS_PER_LOOP];
44 : : struct cn10k_sso_hws *ws;
45 : : struct cnxk_cpt_qp *qp;
46 : : uint16_t nb_ops;
47 : : };
48 : :
49 : : /* Holds information required to send vector of operations */
50 : : struct vec_request {
51 : : struct cpt_inflight_req *req;
52 : : struct rte_event_vector *vec;
53 : : union cpt_inst_w7 w7;
54 : : uint64_t w2;
55 : : };
56 : :
57 : : static inline struct cnxk_se_sess *
58 : 0 : cn10k_cpt_sym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
59 : : {
60 : : struct rte_crypto_sym_op *sym_op = op->sym;
61 : : struct rte_cryptodev_sym_session *sess;
62 : : struct cnxk_se_sess *priv;
63 : : int ret;
64 : :
65 : : /* Create temporary session */
66 [ # # # # ]: 0 : if (rte_mempool_get(qp->sess_mp, (void **)&sess) < 0)
67 : : return NULL;
68 : :
69 : 0 : ret = sym_session_configure(qp->lf.roc_cpt, sym_op->xform, sess, true);
70 [ # # ]: 0 : if (ret) {
71 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, (void *)sess);
72 : 0 : goto sess_put;
73 : : }
74 : :
75 : 0 : priv = (void *)sess;
76 : 0 : sym_op->session = sess;
77 : :
78 : 0 : return priv;
79 : :
80 : : sess_put:
81 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, sess);
82 : 0 : return NULL;
83 : : }
84 : :
85 : : static __rte_always_inline int __rte_hot
86 : : cpt_sec_ipsec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
87 : : struct cn10k_sec_session *sess, struct cpt_inst_s *inst,
88 : : struct cpt_inflight_req *infl_req, const bool is_sg_ver2)
89 : : {
90 : : struct rte_crypto_sym_op *sym_op = op->sym;
91 : : int ret;
92 : :
93 [ # # # # ]: 0 : if (unlikely(sym_op->m_dst && sym_op->m_dst != sym_op->m_src)) {
94 : 0 : plt_dp_err("Out of place is not supported");
95 : 0 : return -ENOTSUP;
96 : : }
97 : :
98 [ # # ]: 0 : if (sess->ipsec.is_outbound)
99 : : ret = process_outb_sa(&qp->lf, op, sess, &qp->meta_info, infl_req, inst,
100 : : is_sg_ver2);
101 : : else
102 : : ret = process_inb_sa(op, sess, inst, &qp->meta_info, infl_req, is_sg_ver2);
103 : :
104 : : return ret;
105 : : }
106 : :
107 : : #ifdef CPT_INST_DEBUG_ENABLE
108 : : static inline void
109 : : cpt_request_data_sgv2_mode_dump(uint8_t *in_buffer, bool glist, uint16_t components)
110 : : {
111 : : struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
112 : : const char *list = glist ? "glist" : "slist";
113 : : struct roc_sg2list_comp *sg_ptr = NULL;
114 : : uint16_t list_cnt = 0;
115 : : char suffix[64];
116 : : int i, j;
117 : :
118 : : sg_ptr = (void *)in_buffer;
119 : : for (i = 0; i < components; i++) {
120 : : for (j = 0; j < sg_ptr->u.s.valid_segs; j++) {
121 : : list_ptr[i * 3 + j].size = sg_ptr->u.s.len[j];
122 : : list_ptr[i * 3 + j].vaddr = (void *)sg_ptr->ptr[j];
123 : : list_ptr[i * 3 + j].vaddr = list_ptr[i * 3 + j].vaddr;
124 : : list_cnt++;
125 : : }
126 : : sg_ptr++;
127 : : }
128 : :
129 : : printf("Current %s: %u\n", list, list_cnt);
130 : :
131 : : for (i = 0; i < list_cnt; i++) {
132 : : snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
133 : : list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
134 : : rte_hexdump(stdout, suffix, list_ptr[i].vaddr, list_ptr[i].size);
135 : : }
136 : : }
137 : :
138 : : static inline void
139 : : cpt_request_data_sg_mode_dump(uint8_t *in_buffer, bool glist)
140 : : {
141 : : struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
142 : : const char *list = glist ? "glist" : "slist";
143 : : struct roc_sglist_comp *sg_ptr = NULL;
144 : : uint16_t list_cnt, components;
145 : : char suffix[64];
146 : : int i;
147 : :
148 : : sg_ptr = (void *)(in_buffer + 8);
149 : : list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[2]));
150 : : if (!glist) {
151 : : components = list_cnt / 4;
152 : : if (list_cnt % 4)
153 : : components++;
154 : : sg_ptr += components;
155 : : list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[3]));
156 : : }
157 : :
158 : : printf("Current %s: %u\n", list, list_cnt);
159 : : components = list_cnt / 4;
160 : : for (i = 0; i < components; i++) {
161 : : list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
162 : : list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
163 : : list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
164 : : list_ptr[i * 4 + 3].size = rte_be_to_cpu_16(sg_ptr->u.s.len[3]);
165 : : list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
166 : : list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
167 : : list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
168 : : list_ptr[i * 4 + 3].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[3]);
169 : : list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
170 : : list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
171 : : list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
172 : : list_ptr[i * 4 + 3].vaddr = list_ptr[i * 4 + 3].vaddr;
173 : : sg_ptr++;
174 : : }
175 : :
176 : : components = list_cnt % 4;
177 : : switch (components) {
178 : : case 3:
179 : : list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
180 : : list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
181 : : list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
182 : : /* FALLTHROUGH */
183 : : case 2:
184 : : list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
185 : : list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
186 : : list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
187 : : /* FALLTHROUGH */
188 : : case 1:
189 : : list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
190 : : list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
191 : : list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
192 : : break;
193 : : default:
194 : : break;
195 : : }
196 : :
197 : : for (i = 0; i < list_cnt; i++) {
198 : : snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
199 : : list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
200 : : rte_hexdump(stdout, suffix, list_ptr[i].vaddr, list_ptr[i].size);
201 : : }
202 : : }
203 : : #endif
204 : :
205 : : static __rte_always_inline int __rte_hot
206 : : cpt_sec_tls_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
207 : : struct cn10k_sec_session *sess, struct cpt_inst_s *inst,
208 : : struct cpt_inflight_req *infl_req, const bool is_sg_ver2)
209 : : {
210 [ # # ]: 0 : if (sess->tls.is_write)
211 : 0 : return process_tls_write(&qp->lf, op, sess, &qp->meta_info, infl_req, inst,
212 : : is_sg_ver2);
213 : : else
214 : 0 : return process_tls_read(op, sess, &qp->meta_info, infl_req, inst, is_sg_ver2);
215 : : }
216 : :
217 : : static __rte_always_inline int __rte_hot
218 : : cpt_sec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, struct cn10k_sec_session *sess,
219 : : struct cpt_inst_s *inst, struct cpt_inflight_req *infl_req, const bool is_sg_ver2)
220 : : {
221 : :
222 : 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
223 : : return cpt_sec_ipsec_inst_fill(qp, op, sess, &inst[0], infl_req, is_sg_ver2);
224 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
225 : : return cpt_sec_tls_inst_fill(qp, op, sess, &inst[0], infl_req, is_sg_ver2);
226 : :
227 : : return 0;
228 : : }
229 : :
230 : : static inline int
231 : 0 : cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[], struct cpt_inst_s inst[],
232 : : struct cpt_inflight_req *infl_req, const bool is_sg_ver2)
233 : : {
234 : : struct cn10k_sec_session *sec_sess;
235 : : struct rte_crypto_asym_op *asym_op;
236 : : struct rte_crypto_sym_op *sym_op;
237 : : struct cnxk_ae_sess *ae_sess;
238 : : struct cnxk_se_sess *sess;
239 : : struct rte_crypto_op *op;
240 : : uint64_t w7;
241 : : int ret;
242 : :
243 : : const union cpt_res_s res = {
244 : : .cn10k.compcode = CPT_COMP_NOT_DONE,
245 : : };
246 : :
247 : 0 : op = ops[0];
248 : :
249 : 0 : inst[0].w0.u64 = 0;
250 : 0 : inst[0].w2.u64 = 0;
251 : 0 : inst[0].w3.u64 = 0;
252 : :
253 : : sym_op = op->sym;
254 : :
255 [ # # ]: 0 : if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
256 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
257 [ # # ]: 0 : sec_sess = (struct cn10k_sec_session *)sym_op->session;
258 : : ret = cpt_sec_inst_fill(qp, op, sec_sess, &inst[0], infl_req, is_sg_ver2);
259 [ # # ]: 0 : if (unlikely(ret))
260 : : return 0;
261 : 0 : w7 = sec_sess->inst.w7;
262 [ # # ]: 0 : } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
263 [ # # ]: 0 : sess = (struct cnxk_se_sess *)(sym_op->session);
264 : : ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], is_sg_ver2);
265 [ # # ]: 0 : if (unlikely(ret))
266 : : return 0;
267 : 0 : w7 = sess->cpt_inst_w7;
268 : : } else {
269 : 0 : sess = cn10k_cpt_sym_temp_sess_create(qp, op);
270 [ # # ]: 0 : if (unlikely(sess == NULL)) {
271 : 0 : plt_dp_err("Could not create temp session");
272 : 0 : return 0;
273 : : }
274 : :
275 : : ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], is_sg_ver2);
276 [ # # ]: 0 : if (unlikely(ret)) {
277 : 0 : sym_session_clear(op->sym->session, true);
278 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, op->sym->session);
279 : 0 : return 0;
280 : : }
281 : 0 : w7 = sess->cpt_inst_w7;
282 : : }
283 [ # # ]: 0 : } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
284 : :
285 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
286 : : asym_op = op->asym;
287 [ # # ]: 0 : ae_sess = (struct cnxk_ae_sess *)asym_op->session;
288 : : ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0], ae_sess);
289 [ # # ]: 0 : if (unlikely(ret))
290 : : return 0;
291 : 0 : w7 = ae_sess->cpt_inst_w7;
292 : : } else {
293 : 0 : plt_dp_err("Not supported Asym op without session");
294 : 0 : return 0;
295 : : }
296 : : } else {
297 : 0 : plt_dp_err("Unsupported op type");
298 : 0 : return 0;
299 : : }
300 : :
301 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
302 : 0 : __atomic_store_n(&infl_req->res.u64[0], res.u64[0], __ATOMIC_RELAXED);
303 : 0 : infl_req->cop = op;
304 : :
305 : 0 : inst[0].w7.u64 = w7;
306 : :
307 : : #ifdef CPT_INST_DEBUG_ENABLE
308 : : infl_req->dptr = (uint8_t *)inst[0].dptr;
309 : : infl_req->rptr = (uint8_t *)inst[0].rptr;
310 : : infl_req->is_sg_ver2 = is_sg_ver2;
311 : : infl_req->scatter_sz = inst[0].w6.s.scatter_sz;
312 : : infl_req->opcode_major = inst[0].w4.s.opcode_major;
313 : :
314 : : rte_hexdump(stdout, "cptr", (void *)(uint64_t)inst[0].w7.s.cptr, 128);
315 : : printf("major opcode:%d\n", inst[0].w4.s.opcode_major);
316 : : printf("minor opcode:%d\n", inst[0].w4.s.opcode_minor);
317 : : printf("param1:%d\n", inst[0].w4.s.param1);
318 : : printf("param2:%d\n", inst[0].w4.s.param2);
319 : : printf("dlen:%d\n", inst[0].w4.s.dlen);
320 : :
321 : : if (is_sg_ver2) {
322 : : cpt_request_data_sgv2_mode_dump((void *)inst[0].dptr, 1, inst[0].w5.s.gather_sz);
323 : : cpt_request_data_sgv2_mode_dump((void *)inst[0].rptr, 0, inst[0].w6.s.scatter_sz);
324 : : } else {
325 : : if (infl_req->opcode_major >> 7) {
326 : : cpt_request_data_sg_mode_dump((void *)inst[0].dptr, 1);
327 : : cpt_request_data_sg_mode_dump((void *)inst[0].dptr, 0);
328 : : }
329 : : }
330 : : #endif
331 : :
332 : 0 : return 1;
333 : : }
334 : :
335 : : static uint16_t
336 : 0 : cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
337 : : const bool is_sg_ver2)
338 : : {
339 : : uint64_t lmt_base, lmt_arg, io_addr;
340 : : struct cpt_inflight_req *infl_req;
341 : : uint16_t nb_allowed, count = 0;
342 : : struct cnxk_cpt_qp *qp = qptr;
343 : : struct pending_queue *pend_q;
344 : : struct cpt_inst_s *inst;
345 : : union cpt_fc_write_s fc;
346 : : uint64_t *fc_addr;
347 : : uint16_t lmt_id;
348 : : uint64_t head;
349 : : int ret, i;
350 : :
351 : : pend_q = &qp->pend_q;
352 : :
353 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
354 : :
355 : 0 : head = pend_q->head;
356 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
357 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
358 : :
359 [ # # ]: 0 : if (unlikely(nb_ops == 0))
360 : : return 0;
361 : :
362 : 0 : lmt_base = qp->lmtline.lmt_base;
363 : : io_addr = qp->lmtline.io_addr;
364 : 0 : fc_addr = qp->lmtline.fc_addr;
365 : :
366 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
367 : :
368 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
369 : 0 : inst = (struct cpt_inst_s *)lmt_base;
370 : :
371 : 0 : again:
372 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
373 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
374 : : i = 0;
375 : 0 : goto pend_q_commit;
376 : : }
377 : :
378 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN10K_PKTS_PER_LOOP, nb_ops); i++) {
379 : 0 : infl_req = &pend_q->req_queue[head];
380 : 0 : infl_req->op_flags = 0;
381 : :
382 : 0 : ret = cn10k_cpt_fill_inst(qp, ops + i, &inst[2 * i], infl_req, is_sg_ver2);
383 [ # # ]: 0 : if (unlikely(ret != 1)) {
384 : 0 : plt_dp_err("Could not process op: %p", ops + i);
385 [ # # ]: 0 : if (i == 0)
386 : 0 : goto pend_q_commit;
387 : : break;
388 : : }
389 : :
390 : : pending_queue_advance(&head, pq_mask);
391 : : }
392 : :
393 : : if (i > CN10K_PKTS_PER_STEORL) {
394 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (CN10K_PKTS_PER_STEORL - 1) << 12 |
395 : : (uint64_t)lmt_id;
396 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
397 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - CN10K_PKTS_PER_STEORL - 1) << 12 |
398 : : (uint64_t)(lmt_id + CN10K_PKTS_PER_STEORL);
399 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
400 : : } else {
401 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | (uint64_t)lmt_id;
402 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
403 : : }
404 : :
405 : 0 : rte_io_wmb();
406 : :
407 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN10K_PKTS_PER_LOOP) {
408 : 0 : nb_ops -= i;
409 : 0 : ops += i;
410 : 0 : count += i;
411 : 0 : goto again;
412 : : }
413 : :
414 : 0 : pend_q_commit:
415 : : rte_atomic_thread_fence(__ATOMIC_RELEASE);
416 : :
417 : 0 : pend_q->head = head;
418 : 0 : pend_q->time_out = rte_get_timer_cycles() +
419 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
420 : :
421 : 0 : return count + i;
422 : : }
423 : :
424 : : static uint16_t
425 : 0 : cn10k_cpt_sg_ver1_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
426 : : {
427 : 0 : return cn10k_cpt_enqueue_burst(qptr, ops, nb_ops, false);
428 : : }
429 : :
430 : : static uint16_t
431 : 0 : cn10k_cpt_sg_ver2_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
432 : : {
433 : 0 : return cn10k_cpt_enqueue_burst(qptr, ops, nb_ops, true);
434 : : }
435 : :
436 : : static int
437 : 0 : cn10k_cpt_crypto_adapter_ev_mdata_set(struct rte_cryptodev *dev __rte_unused, void *sess,
438 : : enum rte_crypto_op_type op_type,
439 : : enum rte_crypto_op_sess_type sess_type, void *mdata)
440 : : {
441 : : union rte_event_crypto_metadata *ec_mdata = mdata;
442 : : struct rte_event *rsp_info;
443 : : struct cnxk_cpt_qp *qp;
444 : : uint64_t w2, tag_type;
445 : : uint8_t cdev_id;
446 : : int16_t qp_id;
447 : :
448 : : /* Get queue pair */
449 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
450 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
451 : 0 : qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
452 : :
453 [ # # ]: 0 : if (!qp->ca.enabled)
454 : : return -EINVAL;
455 : :
456 : : /* Prepare w2 */
457 [ # # ]: 0 : tag_type = qp->ca.vector_sz ? RTE_EVENT_TYPE_CRYPTODEV_VECTOR : RTE_EVENT_TYPE_CRYPTODEV;
458 : : rsp_info = &ec_mdata->response_info;
459 : 0 : w2 = CNXK_CPT_INST_W2((tag_type << 28) | (rsp_info->sub_event_type << 20) |
460 : : rsp_info->flow_id,
461 : : rsp_info->sched_type, rsp_info->queue_id, 0);
462 : :
463 : : /* Set meta according to session type */
464 [ # # ]: 0 : if (op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
465 [ # # ]: 0 : if (sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
466 : : struct cn10k_sec_session *sec_sess = (struct cn10k_sec_session *)sess;
467 : :
468 : 0 : sec_sess->qp = qp;
469 : 0 : sec_sess->inst.w2 = w2;
470 [ # # ]: 0 : } else if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
471 : : struct cnxk_se_sess *priv;
472 : :
473 : : priv = (struct cnxk_se_sess *)sess;
474 : 0 : priv->qp = qp;
475 : 0 : priv->cpt_inst_w2 = w2;
476 : : } else
477 : : return -EINVAL;
478 [ # # ]: 0 : } else if (op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
479 [ # # ]: 0 : if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
480 : : struct cnxk_ae_sess *priv;
481 : :
482 : : priv = (struct cnxk_ae_sess *)sess;
483 : 0 : priv->qp = qp;
484 : 0 : priv->cpt_inst_w2 = w2;
485 : : } else
486 : : return -EINVAL;
487 : : } else
488 : : return -EINVAL;
489 : :
490 : : return 0;
491 : : }
492 : :
493 : : static inline int
494 : 0 : cn10k_ca_meta_info_extract(struct rte_crypto_op *op, struct cnxk_cpt_qp **qp, uint64_t *w2)
495 : : {
496 [ # # ]: 0 : if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
497 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
498 : : struct cn10k_sec_session *sec_sess;
499 : :
500 : 0 : sec_sess = (struct cn10k_sec_session *)op->sym->session;
501 : :
502 : 0 : *qp = sec_sess->qp;
503 : 0 : *w2 = sec_sess->inst.w2;
504 [ # # ]: 0 : } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
505 : : struct cnxk_se_sess *priv;
506 : :
507 : 0 : priv = (struct cnxk_se_sess *)op->sym->session;
508 : 0 : *qp = priv->qp;
509 : 0 : *w2 = priv->cpt_inst_w2;
510 : : } else {
511 : : union rte_event_crypto_metadata *ec_mdata;
512 : : struct rte_event *rsp_info;
513 : : uint8_t cdev_id;
514 : : uint16_t qp_id;
515 : :
516 [ # # ]: 0 : if (unlikely(op->private_data_offset == 0))
517 : : return -EINVAL;
518 : 0 : ec_mdata = (union rte_event_crypto_metadata *)
519 : 0 : ((uint8_t *)op + op->private_data_offset);
520 : : rsp_info = &ec_mdata->response_info;
521 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
522 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
523 : 0 : *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
524 : 0 : *w2 = CNXK_CPT_INST_W2(
525 : : (RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
526 : : rsp_info->sched_type, rsp_info->queue_id, 0);
527 : : }
528 [ # # ]: 0 : } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
529 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
530 : : struct cnxk_ae_sess *priv;
531 : :
532 : 0 : priv = (struct cnxk_ae_sess *)op->asym->session;
533 : 0 : *qp = priv->qp;
534 : 0 : *w2 = priv->cpt_inst_w2;
535 : : } else
536 : : return -EINVAL;
537 : : } else
538 : : return -EINVAL;
539 : :
540 : : return 0;
541 : : }
542 : :
543 : : static inline void
544 : 0 : cn10k_cpt_vec_inst_fill(struct vec_request *vec_req, struct cpt_inst_s *inst,
545 : : struct cnxk_cpt_qp *qp, union cpt_inst_w7 w7)
546 : : {
547 : : const union cpt_res_s res = {.cn10k.compcode = CPT_COMP_NOT_DONE};
548 : 0 : struct cpt_inflight_req *infl_req = vec_req->req;
549 : :
550 : : const union cpt_inst_w4 w4 = {
551 : : .s.opcode_major = ROC_SE_MAJOR_OP_MISC,
552 : : .s.opcode_minor = ROC_SE_MISC_MINOR_OP_PASSTHROUGH,
553 : : .s.param1 = 1,
554 : : .s.param2 = 1,
555 : : .s.dlen = 0,
556 : : };
557 : :
558 : 0 : w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
559 : :
560 : 0 : infl_req->vec = vec_req->vec;
561 : 0 : infl_req->qp = qp;
562 : :
563 : 0 : inst->res_addr = (uint64_t)&infl_req->res;
564 : 0 : __atomic_store_n(&infl_req->res.u64[0], res.u64[0], __ATOMIC_RELAXED);
565 : :
566 : 0 : inst->w0.u64 = 0;
567 : 0 : inst->w2.u64 = vec_req->w2;
568 : 0 : inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
569 : 0 : inst->w4.u64 = w4.u64;
570 : 0 : inst->w5.u64 = 0;
571 : 0 : inst->w6.u64 = 0;
572 : 0 : inst->w7.u64 = w7.u64;
573 : 0 : }
574 : :
575 : : static void
576 : 0 : cn10k_cpt_vec_pkt_submission_timeout_handle(void)
577 : : {
578 : 0 : plt_dp_err("Vector packet submission timedout");
579 : 0 : abort();
580 : : }
581 : :
582 : : static inline void
583 : 0 : cn10k_cpt_vec_submit(struct vec_request vec_tbl[], uint16_t vec_tbl_len, struct cnxk_cpt_qp *qp)
584 : : {
585 : : uint64_t lmt_base, lmt_arg, lmt_id, io_addr;
586 : : union cpt_fc_write_s fc;
587 : : struct cpt_inst_s *inst;
588 : : uint16_t burst_size;
589 : : uint64_t *fc_addr;
590 : : int i;
591 : :
592 [ # # ]: 0 : if (vec_tbl_len == 0)
593 : : return;
594 : :
595 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
596 : : /*
597 : : * Use 10 mins timeout for the poll. It is not possible to recover from partial submission
598 : : * of vector packet. Actual packets for processing are submitted to CPT prior to this
599 : : * routine. Hence, any failure for submission of vector packet would indicate an
600 : : * unrecoverable error for the application.
601 : : */
602 : 0 : const uint64_t timeout = rte_get_timer_cycles() + 10 * 60 * rte_get_timer_hz();
603 : :
604 : 0 : lmt_base = qp->lmtline.lmt_base;
605 : : io_addr = qp->lmtline.io_addr;
606 : 0 : fc_addr = qp->lmtline.fc_addr;
607 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
608 : 0 : inst = (struct cpt_inst_s *)lmt_base;
609 : :
610 : 0 : again:
611 : 0 : burst_size = RTE_MIN(CN10K_PKTS_PER_STEORL, vec_tbl_len);
612 [ # # ]: 0 : for (i = 0; i < burst_size; i++)
613 : 0 : cn10k_cpt_vec_inst_fill(&vec_tbl[i], &inst[i * 2], qp, vec_tbl[0].w7);
614 : :
615 : : do {
616 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
617 [ # # ]: 0 : if (likely(fc.s.qsize < fc_thresh))
618 : : break;
619 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > timeout))
620 : 0 : cn10k_cpt_vec_pkt_submission_timeout_handle();
621 : : } while (true);
622 : :
623 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | lmt_id;
624 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
625 : :
626 : 0 : rte_io_wmb();
627 : :
628 : 0 : vec_tbl_len -= i;
629 : :
630 [ # # ]: 0 : if (vec_tbl_len > 0) {
631 : 0 : vec_tbl += i;
632 : 0 : goto again;
633 : : }
634 : : }
635 : :
636 : : static inline int
637 : 0 : ca_lmtst_vec_submit(struct ops_burst *burst, struct vec_request vec_tbl[], uint16_t *vec_tbl_len,
638 : : const bool is_sg_ver2)
639 : : {
640 : : struct cpt_inflight_req *infl_reqs[CN10K_PKTS_PER_LOOP];
641 : : uint64_t lmt_base, lmt_arg, io_addr;
642 : 0 : uint16_t lmt_id, len = *vec_tbl_len;
643 : : struct cpt_inst_s *inst, *inst_base;
644 : : struct cpt_inflight_req *infl_req;
645 : : struct rte_event_vector *vec;
646 : : union cpt_fc_write_s fc;
647 : : struct cnxk_cpt_qp *qp;
648 : : uint64_t *fc_addr;
649 : : int ret, i, vi;
650 : :
651 : 0 : qp = burst->qp;
652 : :
653 : 0 : lmt_base = qp->lmtline.lmt_base;
654 : : io_addr = qp->lmtline.io_addr;
655 : 0 : fc_addr = qp->lmtline.fc_addr;
656 : :
657 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
658 : :
659 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
660 : 0 : inst_base = (struct cpt_inst_s *)lmt_base;
661 : :
662 : : #ifdef CNXK_CRYPTODEV_DEBUG
663 : : if (unlikely(!qp->ca.enabled)) {
664 : : rte_errno = EINVAL;
665 : : return 0;
666 : : }
667 : : #endif
668 : :
669 : : /* Perform fc check before putting packets into vectors */
670 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
671 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
672 : 0 : rte_errno = EAGAIN;
673 : 0 : return 0;
674 : : }
675 : :
676 [ # # # # ]: 0 : if (unlikely(rte_mempool_get_bulk(qp->ca.req_mp, (void **)infl_reqs, burst->nb_ops))) {
677 : 0 : rte_errno = ENOMEM;
678 : 0 : return 0;
679 : : }
680 : :
681 [ # # ]: 0 : for (i = 0; i < burst->nb_ops; i++) {
682 : 0 : inst = &inst_base[2 * i];
683 : 0 : infl_req = infl_reqs[i];
684 : 0 : infl_req->op_flags = 0;
685 : :
686 : 0 : ret = cn10k_cpt_fill_inst(qp, &burst->op[i], inst, infl_req, is_sg_ver2);
687 [ # # ]: 0 : if (unlikely(ret != 1)) {
688 : 0 : plt_cpt_dbg("Could not process op: %p", burst->op[i]);
689 [ # # ]: 0 : if (i != 0)
690 : 0 : goto submit;
691 : : else
692 : 0 : goto put;
693 : : }
694 : :
695 : 0 : infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
696 : 0 : infl_req->qp = qp;
697 : 0 : inst->w3.u64 = 0x1;
698 : :
699 : : /* Lookup for existing vector by w2 */
700 [ # # ]: 0 : for (vi = len - 1; vi >= 0; vi--) {
701 [ # # ]: 0 : if (vec_tbl[vi].w2 != burst->w2[i])
702 : 0 : continue;
703 : 0 : vec = vec_tbl[vi].vec;
704 [ # # ]: 0 : if (unlikely(vec->nb_elem == qp->ca.vector_sz))
705 : 0 : continue;
706 : 0 : vec->ptrs[vec->nb_elem++] = infl_req;
707 : 0 : goto next_op; /* continue outer loop */
708 : : }
709 : :
710 : : /* No available vectors found, allocate a new one */
711 [ # # # # ]: 0 : if (unlikely(rte_mempool_get(qp->ca.vector_mp, (void **)&vec_tbl[len].vec))) {
712 : 0 : rte_errno = ENOMEM;
713 [ # # ]: 0 : if (i != 0)
714 : 0 : goto submit;
715 : : else
716 : 0 : goto put;
717 : : }
718 : : /* Also preallocate in-flight request, that will be used to
719 : : * submit misc passthrough instruction
720 : : */
721 [ # # # # ]: 0 : if (unlikely(rte_mempool_get(qp->ca.req_mp, (void **)&vec_tbl[len].req))) {
722 [ # # ]: 0 : rte_mempool_put(qp->ca.vector_mp, vec_tbl[len].vec);
723 : 0 : rte_errno = ENOMEM;
724 [ # # ]: 0 : if (i != 0)
725 : 0 : goto submit;
726 : : else
727 : 0 : goto put;
728 : : }
729 : 0 : vec_tbl[len].w2 = burst->w2[i];
730 : 0 : vec_tbl[len].vec->ptrs[0] = infl_req;
731 : 0 : vec_tbl[len].vec->nb_elem = 1;
732 : 0 : len++;
733 : :
734 : 0 : next_op:;
735 : : }
736 : :
737 : : /* Submit operations in burst */
738 : 0 : submit:
739 [ # # ]: 0 : if (CNXK_TT_FROM_TAG(burst->ws->gw_rdata) == SSO_TT_ORDERED)
740 : 0 : roc_sso_hws_head_wait(burst->ws->base);
741 : :
742 : : if (i > CN10K_PKTS_PER_STEORL) {
743 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (CN10K_PKTS_PER_STEORL - 1) << 12 |
744 : : (uint64_t)lmt_id;
745 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
746 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - CN10K_PKTS_PER_STEORL - 1) << 12 |
747 : : (uint64_t)(lmt_id + CN10K_PKTS_PER_STEORL);
748 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
749 : : } else {
750 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | (uint64_t)lmt_id;
751 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
752 : : }
753 : :
754 : : /* Store w7 of last successfully filled instruction */
755 : 0 : inst = &inst_base[2 * (i - 1)];
756 : 0 : vec_tbl[0].w7 = inst->w7;
757 : :
758 : 0 : rte_io_wmb();
759 : :
760 : 0 : put:
761 [ # # ]: 0 : if (i != burst->nb_ops)
762 [ # # ]: 0 : rte_mempool_put_bulk(qp->ca.req_mp, (void *)&infl_reqs[i], burst->nb_ops - i);
763 : :
764 : 0 : *vec_tbl_len = len;
765 : :
766 : 0 : return i;
767 : : }
768 : :
769 : : static inline uint16_t
770 : 0 : ca_lmtst_burst_submit(struct ops_burst *burst, const bool is_sg_ver2)
771 : : {
772 : : struct cpt_inflight_req *infl_reqs[CN10K_PKTS_PER_LOOP];
773 : : uint64_t lmt_base, lmt_arg, io_addr;
774 : : struct cpt_inst_s *inst, *inst_base;
775 : : struct cpt_inflight_req *infl_req;
776 : : union cpt_fc_write_s fc;
777 : : struct cnxk_cpt_qp *qp;
778 : : uint64_t *fc_addr;
779 : : uint16_t lmt_id;
780 : : int ret, i, j;
781 : :
782 : 0 : qp = burst->qp;
783 : :
784 : 0 : lmt_base = qp->lmtline.lmt_base;
785 : : io_addr = qp->lmtline.io_addr;
786 : 0 : fc_addr = qp->lmtline.fc_addr;
787 : :
788 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
789 : :
790 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
791 : 0 : inst_base = (struct cpt_inst_s *)lmt_base;
792 : :
793 : : #ifdef CNXK_CRYPTODEV_DEBUG
794 : : if (unlikely(!qp->ca.enabled)) {
795 : : rte_errno = EINVAL;
796 : : return 0;
797 : : }
798 : : #endif
799 : :
800 [ # # # # ]: 0 : if (unlikely(rte_mempool_get_bulk(qp->ca.req_mp, (void **)infl_reqs, burst->nb_ops))) {
801 : 0 : rte_errno = ENOMEM;
802 : 0 : return 0;
803 : : }
804 : :
805 [ # # ]: 0 : for (i = 0; i < burst->nb_ops; i++) {
806 : 0 : inst = &inst_base[2 * i];
807 : 0 : infl_req = infl_reqs[i];
808 : 0 : infl_req->op_flags = 0;
809 : :
810 : 0 : ret = cn10k_cpt_fill_inst(qp, &burst->op[i], inst, infl_req, is_sg_ver2);
811 [ # # ]: 0 : if (unlikely(ret != 1)) {
812 : : plt_dp_dbg("Could not process op: %p", burst->op[i]);
813 [ # # ]: 0 : if (i != 0)
814 : 0 : goto submit;
815 : : else
816 : 0 : goto put;
817 : : }
818 : :
819 : 0 : infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
820 : 0 : infl_req->qp = qp;
821 : 0 : inst->w0.u64 = 0;
822 : 0 : inst->res_addr = (uint64_t)&infl_req->res;
823 : 0 : inst->w2.u64 = burst->w2[i];
824 : 0 : inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
825 : : }
826 : :
827 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
828 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
829 : 0 : rte_errno = EAGAIN;
830 [ # # ]: 0 : for (j = 0; j < i; j++) {
831 : 0 : infl_req = infl_reqs[j];
832 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
833 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
834 : : }
835 : : i = 0;
836 : 0 : goto put;
837 : : }
838 : :
839 : 0 : submit:
840 [ # # ]: 0 : if (CNXK_TT_FROM_TAG(burst->ws->gw_rdata) == SSO_TT_ORDERED)
841 : 0 : roc_sso_hws_head_wait(burst->ws->base);
842 : :
843 : : if (i > CN10K_PKTS_PER_STEORL) {
844 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (CN10K_PKTS_PER_STEORL - 1) << 12 |
845 : : (uint64_t)lmt_id;
846 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
847 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - CN10K_PKTS_PER_STEORL - 1) << 12 |
848 : : (uint64_t)(lmt_id + CN10K_PKTS_PER_STEORL);
849 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
850 : : } else {
851 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | (uint64_t)lmt_id;
852 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
853 : : }
854 : :
855 : 0 : rte_io_wmb();
856 : :
857 : 0 : put:
858 [ # # ]: 0 : if (unlikely(i != burst->nb_ops))
859 [ # # ]: 0 : rte_mempool_put_bulk(qp->ca.req_mp, (void *)&infl_reqs[i], burst->nb_ops - i);
860 : :
861 : 0 : return i;
862 : : }
863 : :
864 : : static inline uint16_t __rte_hot
865 : 0 : cn10k_cpt_crypto_adapter_enqueue(void *ws, struct rte_event ev[], uint16_t nb_events,
866 : : const bool is_sg_ver2)
867 : 0 : {
868 : 0 : uint16_t submitted, count = 0, vec_tbl_len = 0;
869 : 0 : struct vec_request vec_tbl[nb_events];
870 : : struct rte_crypto_op *op;
871 : : struct ops_burst burst;
872 : : struct cnxk_cpt_qp *qp;
873 : : bool is_vector = false;
874 : : uint64_t w2;
875 : : int ret, i;
876 : :
877 : 0 : burst.ws = ws;
878 : 0 : burst.qp = NULL;
879 : 0 : burst.nb_ops = 0;
880 : :
881 [ # # ]: 0 : for (i = 0; i < nb_events; i++) {
882 : 0 : op = ev[i].event_ptr;
883 : 0 : ret = cn10k_ca_meta_info_extract(op, &qp, &w2);
884 [ # # ]: 0 : if (unlikely(ret)) {
885 : 0 : rte_errno = EINVAL;
886 : 0 : goto vec_submit;
887 : : }
888 : :
889 : : /* Queue pair change check */
890 [ # # ]: 0 : if (qp != burst.qp) {
891 [ # # ]: 0 : if (burst.nb_ops) {
892 [ # # ]: 0 : if (is_vector) {
893 : 0 : submitted = ca_lmtst_vec_submit(&burst, vec_tbl,
894 : : &vec_tbl_len, is_sg_ver2);
895 : : /*
896 : : * Vector submission is required on qp change, but not in
897 : : * other cases, since we could send several vectors per
898 : : * lmtst instruction only for same qp
899 : : */
900 : 0 : cn10k_cpt_vec_submit(vec_tbl, vec_tbl_len, burst.qp);
901 : 0 : vec_tbl_len = 0;
902 : : } else {
903 : 0 : submitted = ca_lmtst_burst_submit(&burst, is_sg_ver2);
904 : : }
905 : 0 : count += submitted;
906 [ # # ]: 0 : if (unlikely(submitted != burst.nb_ops))
907 : 0 : goto vec_submit;
908 : 0 : burst.nb_ops = 0;
909 : : }
910 : 0 : is_vector = qp->ca.vector_sz;
911 : 0 : burst.qp = qp;
912 : : }
913 : 0 : burst.w2[burst.nb_ops] = w2;
914 : 0 : burst.op[burst.nb_ops] = op;
915 : :
916 : : /* Max nb_ops per burst check */
917 [ # # ]: 0 : if (++burst.nb_ops == CN10K_PKTS_PER_LOOP) {
918 [ # # ]: 0 : if (is_vector)
919 : 0 : submitted = ca_lmtst_vec_submit(&burst, vec_tbl, &vec_tbl_len,
920 : : is_sg_ver2);
921 : : else
922 : 0 : submitted = ca_lmtst_burst_submit(&burst, is_sg_ver2);
923 : 0 : count += submitted;
924 [ # # ]: 0 : if (unlikely(submitted != burst.nb_ops))
925 : 0 : goto vec_submit;
926 : 0 : burst.nb_ops = 0;
927 : : }
928 : : }
929 : : /* Submit the rest of crypto operations */
930 [ # # ]: 0 : if (burst.nb_ops) {
931 [ # # ]: 0 : if (is_vector)
932 : 0 : count += ca_lmtst_vec_submit(&burst, vec_tbl, &vec_tbl_len, is_sg_ver2);
933 : : else
934 : 0 : count += ca_lmtst_burst_submit(&burst, is_sg_ver2);
935 : : }
936 : :
937 : 0 : vec_submit:
938 : 0 : cn10k_cpt_vec_submit(vec_tbl, vec_tbl_len, burst.qp);
939 : 0 : return count;
940 : : }
941 : :
942 : : uint16_t __rte_hot
943 : 0 : cn10k_cpt_sg_ver1_crypto_adapter_enqueue(void *ws, struct rte_event ev[], uint16_t nb_events)
944 : : {
945 : 0 : return cn10k_cpt_crypto_adapter_enqueue(ws, ev, nb_events, false);
946 : : }
947 : :
948 : : uint16_t __rte_hot
949 : 0 : cn10k_cpt_sg_ver2_crypto_adapter_enqueue(void *ws, struct rte_event ev[], uint16_t nb_events)
950 : : {
951 : 0 : return cn10k_cpt_crypto_adapter_enqueue(ws, ev, nb_events, true);
952 : : }
953 : :
954 : : static inline void
955 : 0 : cn10k_cpt_ipsec_post_process(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res)
956 : : {
957 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
958 : 0 : const uint16_t m_len = res->rlen;
959 : :
960 [ # # # # : 0 : switch (res->uc_compcode) {
# # ]
961 : 0 : case ROC_IE_OT_UCC_SUCCESS_PKT_IP_BADCSUM:
962 : 0 : mbuf->ol_flags &= ~RTE_MBUF_F_RX_IP_CKSUM_GOOD;
963 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
964 : 0 : break;
965 : 0 : case ROC_IE_OT_UCC_SUCCESS_PKT_L4_GOODCSUM:
966 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD |
967 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD;
968 : 0 : break;
969 : 0 : case ROC_IE_OT_UCC_SUCCESS_PKT_L4_BADCSUM:
970 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD |
971 : : RTE_MBUF_F_RX_IP_CKSUM_GOOD;
972 : 0 : break;
973 : : case ROC_IE_OT_UCC_SUCCESS_PKT_IP_GOODCSUM:
974 : : break;
975 : 0 : case ROC_IE_OT_UCC_SUCCESS_SA_SOFTEXP_FIRST:
976 : : case ROC_IE_OT_UCC_SUCCESS_SA_SOFTEXP_AGAIN:
977 : 0 : cop->aux_flags = RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY;
978 : 0 : break;
979 : 0 : default:
980 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
981 : 0 : cop->aux_flags = res->uc_compcode;
982 : 0 : return;
983 : : }
984 : :
985 [ # # ]: 0 : if (mbuf->next == NULL)
986 : 0 : mbuf->data_len = m_len;
987 : :
988 : 0 : mbuf->pkt_len = m_len;
989 : : }
990 : :
991 : : static inline void
992 : 0 : cn10k_cpt_tls_post_process(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res)
993 : : {
994 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
995 : 0 : const uint16_t m_len = res->rlen;
996 : :
997 [ # # ]: 0 : if (!res->uc_compcode) {
998 [ # # ]: 0 : if (mbuf->next == NULL)
999 : 0 : mbuf->data_len = m_len;
1000 : 0 : mbuf->pkt_len = m_len;
1001 : : } else {
1002 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1003 : 0 : cop->aux_flags = res->uc_compcode;
1004 : 0 : plt_err("crypto op failed with UC compcode: 0x%x", res->uc_compcode);
1005 : : }
1006 : 0 : }
1007 : :
1008 : : static inline void
1009 : 0 : cn10k_cpt_sec_post_process(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res)
1010 : : {
1011 : : struct rte_crypto_sym_op *sym_op = cop->sym;
1012 : : struct cn10k_sec_session *sess;
1013 : :
1014 : 0 : sess = sym_op->session;
1015 [ # # ]: 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
1016 : 0 : cn10k_cpt_ipsec_post_process(cop, res);
1017 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
1018 : 0 : cn10k_cpt_tls_post_process(cop, res);
1019 : 0 : }
1020 : :
1021 : : static inline void
1022 : 0 : cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
1023 : : struct cpt_inflight_req *infl_req, struct cpt_cn10k_res_s *res)
1024 : : {
1025 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1026 : 0 : const uint8_t compcode = res->compcode;
1027 : :
1028 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1029 : :
1030 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
1031 : : cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1032 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
1033 : : /* Success with additional info */
1034 : 0 : cn10k_cpt_sec_post_process(cop, res);
1035 : : } else {
1036 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1037 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
1038 [ # # ]: 0 : if (compcode == CPT_COMP_GOOD) {
1039 : 0 : plt_dp_info(
1040 : : "Request failed with microcode error");
1041 : 0 : plt_dp_info("MC completion code 0x%x",
1042 : : uc_compcode);
1043 : : }
1044 : : }
1045 : :
1046 : 0 : return;
1047 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC &&
1048 : 0 : cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION &&
1049 [ # # ]: 0 : cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
1050 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1051 [ # # ]: 0 : if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) {
1052 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1053 : 0 : return;
1054 [ # # ]: 0 : } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) {
1055 : : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1056 : : return;
1057 : : }
1058 : : }
1059 : : }
1060 : :
1061 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1062 : : #ifdef CPT_INST_DEBUG_ENABLE
1063 : : if (infl_req->is_sg_ver2)
1064 : : cpt_request_data_sgv2_mode_dump(infl_req->rptr, 0, infl_req->scatter_sz);
1065 : : else {
1066 : : if (infl_req->opcode_major >> 7)
1067 : : cpt_request_data_sg_mode_dump(infl_req->dptr, 0);
1068 : : }
1069 : : #endif
1070 : :
1071 [ # # ]: 0 : if (unlikely(uc_compcode)) {
1072 [ # # ]: 0 : if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
1073 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1074 : : else
1075 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1076 : :
1077 : 0 : plt_dp_info("Request failed with microcode error");
1078 : 0 : plt_dp_info("MC completion code 0x%x",
1079 : : res->uc_compcode);
1080 : 0 : cop->aux_flags = uc_compcode;
1081 : 0 : goto temp_sess_free;
1082 : : }
1083 : :
1084 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1085 : : /* Verify authentication data if required */
1086 [ # # ]: 0 : if (unlikely(infl_req->op_flags &
1087 : : CPT_OP_FLAGS_AUTH_VERIFY)) {
1088 : 0 : uintptr_t *rsp = infl_req->mdata;
1089 [ # # ]: 0 : compl_auth_verify(cop, (uint8_t *)rsp[0],
1090 : : rsp[1]);
1091 : : }
1092 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1093 : : struct rte_crypto_asym_op *op = cop->asym;
1094 : 0 : uintptr_t *mdata = infl_req->mdata;
1095 : 0 : struct cnxk_ae_sess *sess = (struct cnxk_ae_sess *)op->session;
1096 : :
1097 [ # # # # : 0 : cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
# # # ]
1098 : : }
1099 : : } else {
1100 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1101 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
1102 : :
1103 [ # # # # ]: 0 : switch (compcode) {
1104 : 0 : case CPT_COMP_INSTERR:
1105 : 0 : plt_dp_err("Request failed with instruction error");
1106 : 0 : break;
1107 : 0 : case CPT_COMP_FAULT:
1108 : 0 : plt_dp_err("Request failed with DMA fault");
1109 : 0 : break;
1110 : 0 : case CPT_COMP_HWERR:
1111 : 0 : plt_dp_err("Request failed with hardware error");
1112 : 0 : break;
1113 : 0 : default:
1114 : 0 : plt_dp_err(
1115 : : "Request failed with unknown completion code");
1116 : : }
1117 : : }
1118 : :
1119 : 0 : temp_sess_free:
1120 [ # # ]: 0 : if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
1121 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1122 : 0 : sym_session_clear(cop->sym->session, true);
1123 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->sym->session);
1124 : 0 : cop->sym->session = NULL;
1125 : : }
1126 : : }
1127 : : }
1128 : :
1129 : : uintptr_t
1130 : 0 : cn10k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
1131 : : {
1132 : : struct cpt_inflight_req *infl_req;
1133 : : struct rte_crypto_op *cop;
1134 : : struct cnxk_cpt_qp *qp;
1135 : : union cpt_res_s res;
1136 : :
1137 : 0 : infl_req = (struct cpt_inflight_req *)(get_work1);
1138 : 0 : cop = infl_req->cop;
1139 : 0 : qp = infl_req->qp;
1140 : :
1141 : 0 : res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
1142 : :
1143 : 0 : cn10k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn10k);
1144 : :
1145 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1146 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1147 : :
1148 [ # # ]: 0 : rte_mempool_put(qp->ca.req_mp, infl_req);
1149 : 0 : return (uintptr_t)cop;
1150 : : }
1151 : :
1152 : : uintptr_t
1153 : 0 : cn10k_cpt_crypto_adapter_vector_dequeue(uintptr_t get_work1)
1154 : : {
1155 : : struct cpt_inflight_req *infl_req, *vec_infl_req;
1156 : : struct rte_mempool *meta_mp, *req_mp;
1157 : : struct rte_event_vector *vec;
1158 : : struct rte_crypto_op *cop;
1159 : : struct cnxk_cpt_qp *qp;
1160 : : union cpt_res_s res;
1161 : : int i;
1162 : :
1163 : 0 : vec_infl_req = (struct cpt_inflight_req *)(get_work1);
1164 : :
1165 : 0 : vec = vec_infl_req->vec;
1166 : 0 : qp = vec_infl_req->qp;
1167 : 0 : meta_mp = qp->meta_info.pool;
1168 : 0 : req_mp = qp->ca.req_mp;
1169 : :
1170 : : #ifdef CNXK_CRYPTODEV_DEBUG
1171 : : res.u64[0] = __atomic_load_n(&vec_infl_req->res.u64[0], __ATOMIC_RELAXED);
1172 : : PLT_ASSERT(res.cn10k.compcode == CPT_COMP_GOOD);
1173 : : PLT_ASSERT(res.cn10k.uc_compcode == 0);
1174 : : #endif
1175 : :
1176 [ # # ]: 0 : for (i = 0; i < vec->nb_elem; i++) {
1177 : 0 : infl_req = vec->ptrs[i];
1178 : 0 : cop = infl_req->cop;
1179 : :
1180 : 0 : res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
1181 : 0 : cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
1182 : :
1183 : 0 : vec->ptrs[i] = cop;
1184 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1185 [ # # ]: 0 : rte_mempool_put(meta_mp, infl_req->mdata);
1186 : :
1187 : 0 : rte_mempool_put(req_mp, infl_req);
1188 : : }
1189 : :
1190 : 0 : rte_mempool_put(req_mp, vec_infl_req);
1191 : :
1192 : 0 : return (uintptr_t)vec;
1193 : : }
1194 : :
1195 : : static uint16_t
1196 : 0 : cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
1197 : : {
1198 : : struct cpt_inflight_req *infl_req;
1199 : : struct cnxk_cpt_qp *qp = qptr;
1200 : : struct pending_queue *pend_q;
1201 : : uint64_t infl_cnt, pq_tail;
1202 : : struct rte_crypto_op *cop;
1203 : : union cpt_res_s res;
1204 : : int i;
1205 : :
1206 : : pend_q = &qp->pend_q;
1207 : :
1208 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1209 : :
1210 : 0 : pq_tail = pend_q->tail;
1211 : 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1212 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1213 : :
1214 : : /* Ensure infl_cnt isn't read before data lands */
1215 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1216 : :
1217 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1218 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1219 : :
1220 : 0 : res.u64[0] = __atomic_load_n(&infl_req->res.u64[0],
1221 : : __ATOMIC_RELAXED);
1222 : :
1223 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1224 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() >
1225 : : pend_q->time_out)) {
1226 : 0 : plt_err("Request timed out");
1227 : 0 : cnxk_cpt_dump_on_err(qp);
1228 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1229 : 0 : DEFAULT_COMMAND_TIMEOUT *
1230 : : rte_get_timer_hz();
1231 : : }
1232 : : break;
1233 : : }
1234 : :
1235 : : pending_queue_advance(&pq_tail, pq_mask);
1236 : :
1237 : 0 : cop = infl_req->cop;
1238 : :
1239 : 0 : ops[i] = cop;
1240 : :
1241 : 0 : cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
1242 : :
1243 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1244 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1245 : : }
1246 : :
1247 : 0 : pend_q->tail = pq_tail;
1248 : :
1249 : 0 : return i;
1250 : : }
1251 : :
1252 : : uint16_t __rte_hot
1253 : 0 : cn10k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1254 : : struct rte_security_session **sess, uint16_t nb_pkts)
1255 : : {
1256 : : uint16_t l2_len, pf_func, lmt_id, count = 0;
1257 : : uint64_t lmt_base, lmt_arg, io_addr;
1258 : : struct cn10k_sec_session *sec_sess;
1259 : : struct rte_cryptodev *cdev = dev;
1260 : : union cpt_res_s *hw_res = NULL;
1261 : : struct cpt_inst_s *inst;
1262 : : struct cnxk_cpt_vf *vf;
1263 : : struct rte_mbuf *m;
1264 : : uint64_t dptr;
1265 : : int i;
1266 : :
1267 : : const union cpt_res_s res = {
1268 : : .cn10k.compcode = CPT_COMP_NOT_DONE,
1269 : : };
1270 : :
1271 : 0 : vf = cdev->data->dev_private;
1272 : :
1273 : 0 : lmt_base = vf->rx_inj_lmtline.lmt_base;
1274 : : io_addr = vf->rx_inj_lmtline.io_addr;
1275 : :
1276 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1277 : 0 : pf_func = vf->rx_inj_pf_func;
1278 : :
1279 : 0 : again:
1280 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1281 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN10K_PKTS_PER_LOOP, nb_pkts); i++) {
1282 : :
1283 : 0 : m = pkts[i];
1284 [ # # ]: 0 : sec_sess = (struct cn10k_sec_session *)sess[i];
1285 : :
1286 [ # # ]: 0 : if (unlikely(rte_pktmbuf_headroom(m) < 32)) {
1287 : 0 : plt_dp_err("No space for CPT res_s");
1288 : 0 : break;
1289 : : }
1290 : :
1291 [ # # ]: 0 : if (unlikely(!rte_pktmbuf_is_contiguous(m))) {
1292 : 0 : plt_dp_err("Multi seg is not supported");
1293 : 0 : break;
1294 : : }
1295 : :
1296 : 0 : l2_len = m->l2_len;
1297 : :
1298 : 0 : *rte_security_dynfield(m) = (uint64_t)sec_sess->userdata;
1299 : :
1300 : 0 : hw_res = rte_pktmbuf_mtod(m, void *);
1301 : 0 : hw_res = RTE_PTR_SUB(hw_res, 32);
1302 : 0 : hw_res = RTE_PTR_ALIGN_CEIL(hw_res, 16);
1303 : :
1304 : : /* Prepare CPT instruction */
1305 : 0 : inst->w0.u64 = 0;
1306 : 0 : inst->w2.u64 = 0;
1307 : 0 : inst->w2.s.rvu_pf_func = pf_func;
1308 : 0 : inst->w3.u64 = (((uint64_t)m + sizeof(struct rte_mbuf)) >> 3) << 3 | 1;
1309 : :
1310 : 0 : inst->w4.u64 = sec_sess->inst.w4 | (rte_pktmbuf_pkt_len(m));
1311 : 0 : dptr = (uint64_t)rte_pktmbuf_iova(m);
1312 : 0 : inst->dptr = dptr;
1313 : 0 : inst->rptr = dptr;
1314 : :
1315 : 0 : inst->w0.hw_s.chan = *(vf->rx_chan_base + m->port);
1316 : 0 : inst->w0.hw_s.l2_len = l2_len;
1317 : 0 : inst->w0.hw_s.et_offset = l2_len - 2;
1318 : :
1319 : 0 : inst->res_addr = (uint64_t)hw_res;
1320 : 0 : rte_atomic_store_explicit((unsigned long __rte_atomic *)&hw_res->u64[0], res.u64[0],
1321 : : rte_memory_order_relaxed);
1322 : :
1323 : 0 : inst->w7.u64 = sec_sess->inst.w7;
1324 : :
1325 : 0 : inst += 2;
1326 : : }
1327 : :
1328 : : if (i > CN10K_PKTS_PER_STEORL) {
1329 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (CN10K_PKTS_PER_STEORL - 1) << 12 |
1330 : : (uint64_t)lmt_id;
1331 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1332 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - CN10K_PKTS_PER_STEORL - 1) << 12 |
1333 : : (uint64_t)(lmt_id + CN10K_PKTS_PER_STEORL);
1334 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1335 : : } else {
1336 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | (uint64_t)lmt_id;
1337 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1338 : : }
1339 : :
1340 : 0 : rte_io_wmb();
1341 : :
1342 [ # # # # ]: 0 : if (nb_pkts - i > 0 && i == CN10K_PKTS_PER_LOOP) {
1343 : 0 : nb_pkts -= i;
1344 : 0 : pkts += i;
1345 : 0 : count += i;
1346 : 0 : goto again;
1347 : : }
1348 : :
1349 : 0 : return count + i;
1350 : : }
1351 : :
1352 : : void
1353 : 0 : cn10k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev, struct cnxk_cpt_vf *vf)
1354 : : {
1355 [ # # # # ]: 0 : if (vf->cpt.hw_caps[CPT_ENG_TYPE_SE].sg_ver2 && vf->cpt.hw_caps[CPT_ENG_TYPE_IE].sg_ver2)
1356 : 0 : dev->enqueue_burst = cn10k_cpt_sg_ver2_enqueue_burst;
1357 : : else
1358 : 0 : dev->enqueue_burst = cn10k_cpt_sg_ver1_enqueue_burst;
1359 : :
1360 : 0 : dev->dequeue_burst = cn10k_cpt_dequeue_burst;
1361 : :
1362 : : rte_mb();
1363 : 0 : }
1364 : :
1365 : : static void
1366 : 0 : cn10k_cpt_dev_info_get(struct rte_cryptodev *dev,
1367 : : struct rte_cryptodev_info *info)
1368 : : {
1369 [ # # ]: 0 : if (info != NULL) {
1370 : 0 : cnxk_cpt_dev_info_get(dev, info);
1371 : 0 : info->driver_id = cn10k_cryptodev_driver_id;
1372 : : }
1373 : 0 : }
1374 : :
1375 : : static inline int
1376 : 0 : cn10k_cpt_raw_fill_inst(struct cnxk_iov *iov, struct cnxk_cpt_qp *qp,
1377 : : struct cnxk_sym_dp_ctx *dp_ctx, struct cpt_inst_s inst[],
1378 : : struct cpt_inflight_req *infl_req, void *opaque, const bool is_sg_ver2)
1379 : : {
1380 : : struct cnxk_se_sess *sess;
1381 : : int ret;
1382 : :
1383 : : const union cpt_res_s res = {
1384 : : .cn10k.compcode = CPT_COMP_NOT_DONE,
1385 : : };
1386 : :
1387 : 0 : inst[0].w0.u64 = 0;
1388 : 0 : inst[0].w2.u64 = 0;
1389 : 0 : inst[0].w3.u64 = 0;
1390 : :
1391 : 0 : sess = dp_ctx->sess;
1392 : :
1393 [ # # # # : 0 : switch (sess->dp_thr_type) {
# ]
1394 : 0 : case CPT_DP_THREAD_TYPE_PT:
1395 : 0 : ret = fill_raw_passthrough_params(iov, inst);
1396 : 0 : break;
1397 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_CHAIN:
1398 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false,
1399 : : false, is_sg_ver2);
1400 : 0 : break;
1401 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_AEAD:
1402 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false, true,
1403 : : is_sg_ver2);
1404 : 0 : break;
1405 [ # # ]: 0 : case CPT_DP_THREAD_AUTH_ONLY:
1406 : : ret = fill_raw_digest_params(iov, sess, &qp->meta_info, infl_req, &inst[0],
1407 : : is_sg_ver2);
1408 : 0 : break;
1409 : : default:
1410 : : ret = -EINVAL;
1411 : : }
1412 : :
1413 [ # # ]: 0 : if (unlikely(ret))
1414 : : return 0;
1415 : :
1416 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
1417 : 0 : __atomic_store_n(&infl_req->res.u64[0], res.u64[0], __ATOMIC_RELAXED);
1418 : 0 : infl_req->opaque = opaque;
1419 : :
1420 : 0 : inst[0].w7.u64 = sess->cpt_inst_w7;
1421 : :
1422 : 0 : return 1;
1423 : : }
1424 : :
1425 : : static uint32_t
1426 : 0 : cn10k_cpt_raw_enqueue_burst(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1427 : : union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status,
1428 : : const bool is_sgv2)
1429 : : {
1430 : 0 : uint16_t lmt_id, nb_allowed, nb_ops = vec->num;
1431 : : uint64_t lmt_base, lmt_arg, io_addr, head;
1432 : : struct cpt_inflight_req *infl_req;
1433 : : struct cnxk_cpt_qp *qp = qpair;
1434 : : struct cnxk_sym_dp_ctx *dp_ctx;
1435 : : struct pending_queue *pend_q;
1436 : : uint32_t count = 0, index;
1437 : : union cpt_fc_write_s fc;
1438 : : struct cpt_inst_s *inst;
1439 : : uint64_t *fc_addr;
1440 : : int ret, i;
1441 : :
1442 : : pend_q = &qp->pend_q;
1443 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1444 : :
1445 : 0 : head = pend_q->head;
1446 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1447 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
1448 : :
1449 [ # # ]: 0 : if (unlikely(nb_ops == 0))
1450 : : return 0;
1451 : :
1452 : 0 : lmt_base = qp->lmtline.lmt_base;
1453 : : io_addr = qp->lmtline.io_addr;
1454 : 0 : fc_addr = qp->lmtline.fc_addr;
1455 : :
1456 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1457 : :
1458 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1459 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1460 : :
1461 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1462 : 0 : again:
1463 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
1464 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
1465 : : i = 0;
1466 : 0 : goto pend_q_commit;
1467 : : }
1468 : :
1469 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN10K_PKTS_PER_LOOP, nb_ops); i++) {
1470 : : struct cnxk_iov iov;
1471 : :
1472 : 0 : index = count + i;
1473 : 0 : infl_req = &pend_q->req_queue[head];
1474 : 0 : infl_req->op_flags = 0;
1475 : :
1476 : 0 : cnxk_raw_burst_to_iov(vec, &ofs, index, &iov);
1477 : 0 : ret = cn10k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[2 * i], infl_req,
1478 : 0 : user_data[index], is_sgv2);
1479 [ # # ]: 0 : if (unlikely(ret != 1)) {
1480 : 0 : plt_dp_err("Could not process vec: %d", index);
1481 [ # # ]: 0 : if (i == 0 && count == 0)
1482 : 0 : return -1;
1483 [ # # ]: 0 : else if (i == 0)
1484 : 0 : goto pend_q_commit;
1485 : : else
1486 : : break;
1487 : : }
1488 : : pending_queue_advance(&head, pq_mask);
1489 : : }
1490 : :
1491 : : if (i > CN10K_PKTS_PER_STEORL) {
1492 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (CN10K_PKTS_PER_STEORL - 1) << 12 |
1493 : : (uint64_t)lmt_id;
1494 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1495 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - CN10K_PKTS_PER_STEORL - 1) << 12 |
1496 : : (uint64_t)(lmt_id + CN10K_PKTS_PER_STEORL);
1497 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1498 : : } else {
1499 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 | (uint64_t)lmt_id;
1500 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1501 : : }
1502 : :
1503 : 0 : rte_io_wmb();
1504 : :
1505 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN10K_PKTS_PER_LOOP) {
1506 : 0 : nb_ops -= i;
1507 : 0 : count += i;
1508 : 0 : goto again;
1509 : : }
1510 : :
1511 : 0 : pend_q_commit:
1512 : : rte_atomic_thread_fence(__ATOMIC_RELEASE);
1513 : :
1514 : 0 : pend_q->head = head;
1515 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1516 : :
1517 : 0 : *enqueue_status = 1;
1518 : 0 : return count + i;
1519 : : }
1520 : :
1521 : : static uint32_t
1522 : 0 : cn10k_cpt_raw_enqueue_burst_sgv2(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1523 : : union rte_crypto_sym_ofs ofs, void *user_data[],
1524 : : int *enqueue_status)
1525 : : {
1526 : 0 : return cn10k_cpt_raw_enqueue_burst(qpair, drv_ctx, vec, ofs, user_data, enqueue_status,
1527 : : true);
1528 : : }
1529 : :
1530 : : static uint32_t
1531 : 0 : cn10k_cpt_raw_enqueue_burst_sgv1(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1532 : : union rte_crypto_sym_ofs ofs, void *user_data[],
1533 : : int *enqueue_status)
1534 : : {
1535 : 0 : return cn10k_cpt_raw_enqueue_burst(qpair, drv_ctx, vec, ofs, user_data, enqueue_status,
1536 : : false);
1537 : : }
1538 : :
1539 : : static int
1540 : 0 : cn10k_cpt_raw_enqueue(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1541 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1542 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1543 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data,
1544 : : const bool is_sgv2)
1545 : : {
1546 : : uint64_t lmt_base, lmt_arg, io_addr, head;
1547 : : struct cpt_inflight_req *infl_req;
1548 : : struct cnxk_cpt_qp *qp = qpair;
1549 : : struct cnxk_sym_dp_ctx *dp_ctx;
1550 : : uint16_t lmt_id, nb_allowed;
1551 : : struct cpt_inst_s *inst;
1552 : : union cpt_fc_write_s fc;
1553 : : struct cnxk_iov iov;
1554 : : uint64_t *fc_addr;
1555 : : int ret;
1556 : :
1557 : : struct pending_queue *pend_q = &qp->pend_q;
1558 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1559 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1560 : :
1561 : 0 : head = pend_q->head;
1562 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1563 : :
1564 [ # # ]: 0 : if (unlikely(nb_allowed == 0))
1565 : : return -1;
1566 : :
1567 : : cnxk_raw_to_iov(data_vec, n_data_vecs, &ofs, iv, digest, aad_or_auth_iv, &iov);
1568 : :
1569 : 0 : lmt_base = qp->lmtline.lmt_base;
1570 : : io_addr = qp->lmtline.io_addr;
1571 : 0 : fc_addr = qp->lmtline.fc_addr;
1572 : :
1573 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1574 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1575 : :
1576 : 0 : fc.u64[0] = __atomic_load_n(fc_addr, __ATOMIC_RELAXED);
1577 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh))
1578 : : return -1;
1579 : :
1580 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1581 : 0 : infl_req = &pend_q->req_queue[head];
1582 : 0 : infl_req->op_flags = 0;
1583 : :
1584 : 0 : ret = cn10k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[0], infl_req, user_data, is_sgv2);
1585 [ # # ]: 0 : if (unlikely(ret != 1)) {
1586 : 0 : plt_dp_err("Could not process vec");
1587 : 0 : return -1;
1588 : : }
1589 : :
1590 : : pending_queue_advance(&head, pq_mask);
1591 : :
1592 : : lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
1593 : : roc_lmt_submit_steorl(lmt_arg, io_addr);
1594 : :
1595 : 0 : rte_io_wmb();
1596 : :
1597 : 0 : pend_q->head = head;
1598 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1599 : :
1600 : 0 : return 1;
1601 : : }
1602 : :
1603 : : static int
1604 : 0 : cn10k_cpt_raw_enqueue_sgv2(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1605 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1606 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1607 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1608 : : {
1609 : 0 : return cn10k_cpt_raw_enqueue(qpair, drv_ctx, data_vec, n_data_vecs, ofs, iv, digest,
1610 : : aad_or_auth_iv, user_data, true);
1611 : : }
1612 : :
1613 : : static int
1614 : 0 : cn10k_cpt_raw_enqueue_sgv1(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1615 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1616 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1617 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1618 : : {
1619 : 0 : return cn10k_cpt_raw_enqueue(qpair, drv_ctx, data_vec, n_data_vecs, ofs, iv, digest,
1620 : : aad_or_auth_iv, user_data, false);
1621 : : }
1622 : :
1623 : : static inline int
1624 : 0 : cn10k_cpt_raw_dequeue_post_process(struct cpt_cn10k_res_s *res)
1625 : : {
1626 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1627 : 0 : const uint8_t compcode = res->compcode;
1628 : : int ret = 1;
1629 : :
1630 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1631 [ # # ]: 0 : if (unlikely(uc_compcode))
1632 : 0 : plt_dp_info("Request failed with microcode error: 0x%x", res->uc_compcode);
1633 : : else
1634 : : ret = 0;
1635 : : }
1636 : :
1637 : 0 : return ret;
1638 : : }
1639 : :
1640 : : static uint32_t
1641 : 0 : cn10k_cpt_sym_raw_dequeue_burst(void *qptr, uint8_t *drv_ctx,
1642 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1643 : : uint32_t max_nb_to_dequeue,
1644 : : rte_cryptodev_raw_post_dequeue_t post_dequeue, void **out_user_data,
1645 : : uint8_t is_user_data_array, uint32_t *n_success,
1646 : : int *dequeue_status)
1647 : : {
1648 : : struct cpt_inflight_req *infl_req;
1649 : : struct cnxk_cpt_qp *qp = qptr;
1650 : : struct pending_queue *pend_q;
1651 : : uint64_t infl_cnt, pq_tail;
1652 : : union cpt_res_s res;
1653 : : int is_op_success;
1654 : : uint16_t nb_ops;
1655 : : void *opaque;
1656 : : int i = 0;
1657 : :
1658 : : pend_q = &qp->pend_q;
1659 : :
1660 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1661 : :
1662 : : RTE_SET_USED(drv_ctx);
1663 : 0 : pq_tail = pend_q->tail;
1664 [ # # ]: 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1665 : :
1666 : : /* Ensure infl_cnt isn't read before data lands */
1667 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1668 : :
1669 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1670 : :
1671 : 0 : opaque = infl_req->opaque;
1672 [ # # ]: 0 : if (get_dequeue_count)
1673 : 0 : nb_ops = get_dequeue_count(opaque);
1674 : : else
1675 : 0 : nb_ops = max_nb_to_dequeue;
1676 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1677 : :
1678 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1679 : : is_op_success = 0;
1680 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1681 : :
1682 : 0 : res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
1683 : :
1684 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1685 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1686 : 0 : plt_err("Request timed out");
1687 : 0 : cnxk_cpt_dump_on_err(qp);
1688 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1689 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1690 : : }
1691 : : break;
1692 : : }
1693 : :
1694 : : pending_queue_advance(&pq_tail, pq_mask);
1695 : :
1696 [ # # ]: 0 : if (!cn10k_cpt_raw_dequeue_post_process(&res.cn10k)) {
1697 : : is_op_success = 1;
1698 : 0 : *n_success += 1;
1699 : : }
1700 : :
1701 [ # # ]: 0 : if (is_user_data_array) {
1702 : 0 : out_user_data[i] = infl_req->opaque;
1703 : 0 : post_dequeue(out_user_data[i], i, is_op_success);
1704 : : } else {
1705 [ # # ]: 0 : if (i == 0)
1706 : 0 : out_user_data[0] = opaque;
1707 : 0 : post_dequeue(out_user_data[0], i, is_op_success);
1708 : : }
1709 : :
1710 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1711 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1712 : : }
1713 : :
1714 : 0 : pend_q->tail = pq_tail;
1715 : 0 : *dequeue_status = 1;
1716 : :
1717 : 0 : return i;
1718 : : }
1719 : :
1720 : : static void *
1721 : 0 : cn10k_cpt_sym_raw_dequeue(void *qptr, uint8_t *drv_ctx, int *dequeue_status,
1722 : : enum rte_crypto_op_status *op_status)
1723 : : {
1724 : : struct cpt_inflight_req *infl_req;
1725 : : struct cnxk_cpt_qp *qp = qptr;
1726 : : struct pending_queue *pend_q;
1727 : : uint64_t pq_tail;
1728 : : union cpt_res_s res;
1729 : : void *opaque = NULL;
1730 : :
1731 : : pend_q = &qp->pend_q;
1732 : :
1733 : : const uint64_t pq_mask = pend_q->pq_mask;
1734 : :
1735 : : RTE_SET_USED(drv_ctx);
1736 : :
1737 [ # # ]: 0 : pq_tail = pend_q->tail;
1738 : :
1739 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1740 : :
1741 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1742 : :
1743 : 0 : res.u64[0] = __atomic_load_n(&infl_req->res.u64[0], __ATOMIC_RELAXED);
1744 : :
1745 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1746 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1747 : 0 : plt_err("Request timed out");
1748 : 0 : cnxk_cpt_dump_on_err(qp);
1749 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1750 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1751 : : }
1752 : 0 : goto exit;
1753 : : }
1754 : :
1755 : : pending_queue_advance(&pq_tail, pq_mask);
1756 : :
1757 : 0 : opaque = infl_req->opaque;
1758 : :
1759 [ # # ]: 0 : if (!cn10k_cpt_raw_dequeue_post_process(&res.cn10k))
1760 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1761 : : else
1762 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_ERROR;
1763 : :
1764 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1765 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1766 : :
1767 : 0 : *dequeue_status = 1;
1768 : 0 : exit:
1769 : 0 : return opaque;
1770 : : }
1771 : :
1772 : : static int
1773 : 0 : cn10k_sym_get_raw_dp_ctx_size(struct rte_cryptodev *dev __rte_unused)
1774 : : {
1775 : 0 : return sizeof(struct cnxk_sym_dp_ctx);
1776 : : }
1777 : :
1778 : : static int
1779 : 0 : cn10k_sym_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
1780 : : struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
1781 : : enum rte_crypto_op_sess_type sess_type,
1782 : : union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
1783 : : {
1784 : 0 : struct cnxk_se_sess *sess = (struct cnxk_se_sess *)session_ctx.crypto_sess;
1785 : : struct cnxk_sym_dp_ctx *dp_ctx;
1786 : :
1787 [ # # ]: 0 : if (sess_type != RTE_CRYPTO_OP_WITH_SESSION)
1788 : : return -ENOTSUP;
1789 : :
1790 [ # # ]: 0 : if (sess == NULL)
1791 : : return -EINVAL;
1792 : :
1793 : 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP) ||
1794 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP_CHAIN) ||
1795 [ # # ]: 0 : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_KASUMI) ||
1796 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_SM))
1797 : : return -ENOTSUP;
1798 : :
1799 [ # # ]: 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_AUTH_ONLY) &&
1800 [ # # ]: 0 : ((sess->roc_se_ctx.fc_type == ROC_SE_KASUMI) ||
1801 : : (sess->roc_se_ctx.fc_type == ROC_SE_PDCP)))
1802 : : return -ENOTSUP;
1803 : :
1804 [ # # ]: 0 : if (sess->roc_se_ctx.hash_type == ROC_SE_SHA1_TYPE)
1805 : : return -ENOTSUP;
1806 : :
1807 : : dp_ctx = (struct cnxk_sym_dp_ctx *)raw_dp_ctx->drv_ctx_data;
1808 : 0 : dp_ctx->sess = sess;
1809 : :
1810 [ # # ]: 0 : if (!is_update) {
1811 : : struct cnxk_cpt_vf *vf;
1812 : :
1813 : 0 : raw_dp_ctx->qp_data = (struct cnxk_cpt_qp *)dev->data->queue_pairs[qp_id];
1814 : 0 : raw_dp_ctx->dequeue = cn10k_cpt_sym_raw_dequeue;
1815 : 0 : raw_dp_ctx->dequeue_burst = cn10k_cpt_sym_raw_dequeue_burst;
1816 : :
1817 : 0 : vf = dev->data->dev_private;
1818 [ # # ]: 0 : if (vf->cpt.hw_caps[CPT_ENG_TYPE_SE].sg_ver2 &&
1819 [ # # ]: 0 : vf->cpt.hw_caps[CPT_ENG_TYPE_IE].sg_ver2) {
1820 : 0 : raw_dp_ctx->enqueue = cn10k_cpt_raw_enqueue_sgv2;
1821 : 0 : raw_dp_ctx->enqueue_burst = cn10k_cpt_raw_enqueue_burst_sgv2;
1822 : : } else {
1823 : 0 : raw_dp_ctx->enqueue = cn10k_cpt_raw_enqueue_sgv1;
1824 : 0 : raw_dp_ctx->enqueue_burst = cn10k_cpt_raw_enqueue_burst_sgv1;
1825 : : }
1826 : : }
1827 : :
1828 : : return 0;
1829 : : }
1830 : :
1831 : : int
1832 : 0 : cn10k_cryptodev_sec_rx_inject_configure(void *device, uint16_t port_id, bool enable)
1833 : : {
1834 : : struct rte_cryptodev *crypto_dev = device;
1835 : : struct rte_eth_dev *eth_dev;
1836 : : int ret;
1837 : :
1838 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1839 : : return -EINVAL;
1840 : :
1841 [ # # ]: 0 : if (!(crypto_dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT))
1842 : : return -ENOTSUP;
1843 : :
1844 : : eth_dev = &rte_eth_devices[port_id];
1845 : :
1846 : 0 : ret = strncmp(eth_dev->device->driver->name, "net_cn10k", 8);
1847 [ # # ]: 0 : if (ret)
1848 : : return -ENOTSUP;
1849 : :
1850 : 0 : roc_idev_nix_rx_inject_set(port_id, enable);
1851 : :
1852 : 0 : return 0;
1853 : : }
1854 : :
1855 : : struct rte_cryptodev_ops cn10k_cpt_ops = {
1856 : : /* Device control ops */
1857 : : .dev_configure = cnxk_cpt_dev_config,
1858 : : .dev_start = cnxk_cpt_dev_start,
1859 : : .dev_stop = cnxk_cpt_dev_stop,
1860 : : .dev_close = cnxk_cpt_dev_close,
1861 : : .dev_infos_get = cn10k_cpt_dev_info_get,
1862 : :
1863 : : .stats_get = NULL,
1864 : : .stats_reset = NULL,
1865 : : .queue_pair_setup = cnxk_cpt_queue_pair_setup,
1866 : : .queue_pair_release = cnxk_cpt_queue_pair_release,
1867 : :
1868 : : /* Symmetric crypto ops */
1869 : : .sym_session_get_size = cnxk_cpt_sym_session_get_size,
1870 : : .sym_session_configure = cnxk_cpt_sym_session_configure,
1871 : : .sym_session_clear = cnxk_cpt_sym_session_clear,
1872 : :
1873 : : /* Asymmetric crypto ops */
1874 : : .asym_session_get_size = cnxk_ae_session_size_get,
1875 : : .asym_session_configure = cnxk_ae_session_cfg,
1876 : : .asym_session_clear = cnxk_ae_session_clear,
1877 : :
1878 : : /* Event crypto ops */
1879 : : .session_ev_mdata_set = cn10k_cpt_crypto_adapter_ev_mdata_set,
1880 : : .queue_pair_event_error_query = cnxk_cpt_queue_pair_event_error_query,
1881 : :
1882 : : /* Raw data-path API related operations */
1883 : : .sym_get_raw_dp_ctx_size = cn10k_sym_get_raw_dp_ctx_size,
1884 : : .sym_configure_raw_dp_ctx = cn10k_sym_configure_raw_dp_ctx,
1885 : : };
|