Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include <eal_export.h>
6 : : #include <rte_atomic.h>
7 : : #include <rte_cryptodev.h>
8 : : #include <cryptodev_pmd.h>
9 : : #include <rte_errno.h>
10 : : #ifdef CPT_INST_DEBUG_ENABLE
11 : : #include <rte_hexdump.h>
12 : : #endif
13 : : #include <rte_security_driver.h>
14 : :
15 : : #include "roc_ae_fpm_tables.h"
16 : : #include "roc_cpt.h"
17 : : #include "roc_errata.h"
18 : : #include "roc_idev.h"
19 : : #include "roc_ie_on.h"
20 : : #if defined(__aarch64__)
21 : : #include "roc_io.h"
22 : : #else
23 : : #include "roc_io_generic.h"
24 : : #endif
25 : :
26 : : #include "cnxk_ae.h"
27 : : #include "cnxk_cryptodev.h"
28 : : #include "cnxk_cryptodev_capabilities.h"
29 : : #include "cnxk_cryptodev_ops.h"
30 : : #include "cnxk_se.h"
31 : :
32 : : #include "cn10k_cryptodev_ops.h"
33 : : #include "cn10k_cryptodev_sec.h"
34 : : #include "cn20k_cryptodev_ops.h"
35 : : #include "cn20k_cryptodev_sec.h"
36 : : #include "cn9k_cryptodev_ops.h"
37 : : #include "cn9k_ipsec.h"
38 : :
39 : : #include "rte_pmd_cnxk_crypto.h"
40 : :
41 : : #define CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS 5
42 : : #define CNXK_CPT_MAX_ASYM_OP_MOD_LEN 1024
43 : : #define CNXK_CPT_META_BUF_MAX_CACHE_SIZE 128
44 : :
45 : : static int
46 : : cnxk_cpt_get_mlen(void)
47 : : {
48 : : uint32_t len;
49 : :
50 : : /* For MAC */
51 : : len = 2 * sizeof(uint64_t);
52 : : len += ROC_SE_MAX_MAC_LEN * sizeof(uint8_t);
53 : :
54 : : /* For PDCP_CHAIN passthrough alignment */
55 : : len += 8;
56 : : len += ROC_SE_OFF_CTRL_LEN + ROC_CPT_AES_CBC_IV_LEN;
57 : : len += RTE_ALIGN_CEIL((ROC_SG_LIST_HDR_SIZE +
58 : : (RTE_ALIGN_CEIL(ROC_MAX_SG_IN_OUT_CNT, 4) >> 2) * ROC_SG_ENTRY_SIZE),
59 : : 8);
60 : :
61 : : return len;
62 : : }
63 : :
64 : : static int
65 : : cnxk_cpt_sec_get_mlen(void)
66 : : {
67 : : uint32_t len;
68 : :
69 : : len = ROC_IE_ON_OUTB_DPTR_HDR + ROC_IE_ON_MAX_IV_LEN;
70 : : len += RTE_ALIGN_CEIL((ROC_SG_LIST_HDR_SIZE +
71 : : (RTE_ALIGN_CEIL(ROC_MAX_SG_IN_OUT_CNT, 4) >> 2) * ROC_SG_ENTRY_SIZE),
72 : : 8);
73 : :
74 : : return len;
75 : : }
76 : :
77 : : int
78 : 0 : cnxk_cpt_asym_get_mlen(void)
79 : : {
80 : : uint32_t len;
81 : :
82 : : /* To hold RPTR */
83 : : len = sizeof(uint64_t);
84 : :
85 : : /* Get meta len for asymmetric operations */
86 : : len += CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS * CNXK_CPT_MAX_ASYM_OP_MOD_LEN;
87 : :
88 : 0 : return len;
89 : : }
90 : :
91 : : static int
92 : 0 : cnxk_cpt_dev_clear(struct rte_cryptodev *dev)
93 : : {
94 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
95 : : int ret;
96 : :
97 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
98 : 0 : roc_ae_fpm_put();
99 : 0 : roc_ae_ec_grp_put();
100 : : }
101 : :
102 : 0 : ret = roc_cpt_int_misc_cb_unregister(cnxk_cpt_int_misc_cb, NULL);
103 [ # # ]: 0 : if (ret < 0) {
104 : 0 : plt_err("Could not unregister CPT_MISC_INT cb");
105 : 0 : return ret;
106 : : }
107 : :
108 : 0 : roc_cpt_dev_clear(&vf->cpt);
109 : :
110 : 0 : return 0;
111 : : }
112 : :
113 : : int
114 : 0 : cnxk_cpt_dev_config(struct rte_cryptodev *dev, struct rte_cryptodev_config *conf)
115 : : {
116 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
117 : 0 : struct roc_cpt *roc_cpt = &vf->cpt;
118 : : uint16_t nb_lf_avail, nb_lf;
119 : : bool rxc_ena = false;
120 : : int ret;
121 : :
122 : : /* If this is a reconfigure attempt, clear the device and configure again */
123 [ # # ]: 0 : if (roc_cpt->nb_lf > 0) {
124 : 0 : cnxk_cpt_dev_clear(dev);
125 : 0 : roc_cpt->opaque = NULL;
126 : : }
127 : :
128 : 0 : dev->feature_flags = cnxk_cpt_default_ff_get() & ~conf->ff_disable;
129 : :
130 : 0 : nb_lf_avail = roc_cpt->nb_lf_avail;
131 : 0 : nb_lf = conf->nb_queue_pairs;
132 : :
133 [ # # ]: 0 : if (nb_lf > nb_lf_avail)
134 : : return -ENOTSUP;
135 : :
136 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) {
137 [ # # ]: 0 : if (rte_security_dynfield_register() < 0)
138 : : return -ENOTSUP;
139 : : rxc_ena = true;
140 : 0 : vf->rx_chan_base = roc_idev_nix_rx_chan_base_get();
141 : : }
142 : :
143 : 0 : ret = roc_cpt_dev_configure(roc_cpt, nb_lf, rxc_ena, vf->rx_inject_qp);
144 [ # # ]: 0 : if (ret) {
145 : 0 : plt_err("Could not configure device");
146 : 0 : return ret;
147 : : }
148 : :
149 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
150 : : /* Initialize shared FPM table */
151 : 0 : ret = roc_ae_fpm_get(vf->cnxk_fpm_iova);
152 [ # # ]: 0 : if (ret) {
153 : 0 : plt_err("Could not get FPM table");
154 : 0 : return ret;
155 : : }
156 : :
157 : : /* Init EC grp table */
158 : 0 : ret = roc_ae_ec_grp_get(vf->ec_grp);
159 [ # # ]: 0 : if (ret) {
160 : 0 : plt_err("Could not get EC grp table");
161 : 0 : roc_ae_fpm_put();
162 : 0 : return ret;
163 : : }
164 : : }
165 : 0 : roc_cpt->opaque = dev;
166 : : /* Register callback to handle CPT_MISC_INT */
167 : 0 : roc_cpt_int_misc_cb_register(cnxk_cpt_int_misc_cb, NULL);
168 : :
169 : 0 : return 0;
170 : : }
171 : :
172 : : int
173 : 0 : cnxk_cpt_dev_start(struct rte_cryptodev *dev)
174 : : {
175 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
176 : : struct roc_cpt *roc_cpt = &vf->cpt;
177 : 0 : uint16_t nb_lf = roc_cpt->nb_lf;
178 : : uint16_t qp_id;
179 : :
180 [ # # ]: 0 : for (qp_id = 0; qp_id < nb_lf; qp_id++) {
181 : : /* Application may not setup all queue pair */
182 [ # # ]: 0 : if (roc_cpt->lf[qp_id] == NULL)
183 : 0 : continue;
184 : :
185 : 0 : roc_cpt_iq_enable(roc_cpt->lf[qp_id]);
186 : : }
187 : :
188 : 0 : return 0;
189 : : }
190 : :
191 : : void
192 : 0 : cnxk_cpt_dev_stop(struct rte_cryptodev *dev)
193 : : {
194 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
195 : : struct roc_cpt *roc_cpt = &vf->cpt;
196 : 0 : uint16_t nb_lf = roc_cpt->nb_lf;
197 : : uint16_t qp_id;
198 : :
199 [ # # ]: 0 : for (qp_id = 0; qp_id < nb_lf; qp_id++) {
200 [ # # ]: 0 : if (roc_cpt->lf[qp_id] == NULL)
201 : 0 : continue;
202 : :
203 : 0 : roc_cpt_iq_disable(roc_cpt->lf[qp_id]);
204 : : }
205 : 0 : }
206 : :
207 : : int
208 : 0 : cnxk_cpt_dev_close(struct rte_cryptodev *dev)
209 : : {
210 : : uint16_t i;
211 : : int ret;
212 : :
213 [ # # ]: 0 : for (i = 0; i < dev->data->nb_queue_pairs; i++) {
214 : 0 : ret = cnxk_cpt_queue_pair_release(dev, i);
215 [ # # ]: 0 : if (ret < 0) {
216 : 0 : plt_err("Could not release queue pair %u", i);
217 : 0 : return ret;
218 : : }
219 : : }
220 : :
221 : 0 : return cnxk_cpt_dev_clear(dev);
222 : : }
223 : :
224 : : void
225 : 0 : cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
226 : : struct rte_cryptodev_info *info)
227 : : {
228 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
229 : : struct roc_cpt *roc_cpt = &vf->cpt;
230 : :
231 : 0 : info->max_nb_queue_pairs =
232 : 0 : RTE_MIN(roc_cpt->nb_lf_avail, vf->max_qps_limit);
233 : 0 : plt_cpt_dbg("max_nb_queue_pairs %u", info->max_nb_queue_pairs);
234 : :
235 : 0 : info->feature_flags = cnxk_cpt_default_ff_get();
236 : 0 : info->capabilities = cnxk_crypto_capabilities_get(vf);
237 : 0 : info->sym.max_nb_sessions = 0;
238 : 0 : info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ;
239 : 0 : info->min_mbuf_tailroom_req = CNXK_CPT_MIN_TAILROOM_REQ;
240 : :
241 : : /* If the LF ID for RX Inject is less than the available lfs. */
242 [ # # ]: 0 : if (vf->rx_inject_qp > info->max_nb_queue_pairs)
243 : 0 : info->feature_flags &= ~RTE_CRYPTODEV_FF_SECURITY_RX_INJECT;
244 : 0 : }
245 : :
246 : : static void
247 : : qp_memzone_name_get(char *name, int size, int dev_id, int qp_id)
248 : : {
249 : : snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id);
250 : : }
251 : :
252 : : static int
253 : 0 : cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev,
254 : : struct cnxk_cpt_qp *qp, uint8_t qp_id,
255 : : uint32_t nb_elements)
256 : : {
257 : : char mempool_name[RTE_MEMPOOL_NAMESIZE];
258 : : struct cpt_qp_meta_info *meta_info;
259 : 0 : int lcore_cnt = rte_lcore_count();
260 : : struct rte_mempool *pool;
261 : : int mb_pool_sz, mlen = 8;
262 : : uint32_t cache_sz;
263 : :
264 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
265 : : /* Get meta len */
266 : : mlen = cnxk_cpt_get_mlen();
267 : : }
268 : :
269 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY) {
270 : : /* Get meta len for security operations */
271 : : mlen = cnxk_cpt_sec_get_mlen();
272 : : }
273 : :
274 [ # # ]: 0 : if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
275 : :
276 : : /* Get meta len required for asymmetric operations */
277 : 0 : mlen = RTE_MAX(mlen, cnxk_cpt_asym_get_mlen());
278 : : }
279 : :
280 : : mb_pool_sz = nb_elements;
281 [ # # ]: 0 : cache_sz = RTE_MIN(CNXK_CPT_META_BUF_MAX_CACHE_SIZE, nb_elements / 1.5);
282 : :
283 : : /* For poll mode, core that enqueues and core that dequeues can be
284 : : * different. For event mode, all cores are allowed to use same crypto
285 : : * queue pair.
286 : : */
287 : :
288 : 0 : mb_pool_sz += (RTE_MAX(2, lcore_cnt) * cache_sz);
289 : :
290 : : /* Allocate mempool */
291 : :
292 : 0 : snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u",
293 : 0 : dev->data->dev_id, qp_id);
294 : :
295 : 0 : pool = rte_mempool_create(mempool_name, mb_pool_sz, mlen, cache_sz, 0,
296 : 0 : NULL, NULL, NULL, NULL, rte_socket_id(), 0);
297 : :
298 [ # # ]: 0 : if (pool == NULL) {
299 : 0 : plt_err("Could not create mempool for metabuf");
300 : 0 : return rte_errno;
301 : : }
302 : :
303 : : meta_info = &qp->meta_info;
304 : :
305 : 0 : meta_info->pool = pool;
306 : 0 : meta_info->mlen = mlen;
307 : :
308 : 0 : return 0;
309 : : }
310 : :
311 : : static void
312 : : cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp)
313 : : {
314 : : struct cpt_qp_meta_info *meta_info = &qp->meta_info;
315 : :
316 : 0 : rte_mempool_free(meta_info->pool);
317 : :
318 : 0 : meta_info->pool = NULL;
319 : 0 : meta_info->mlen = 0;
320 : : }
321 : :
322 : : static struct cnxk_cpt_qp *
323 : 0 : cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
324 : : uint32_t iq_len)
325 : : {
326 : : const struct rte_memzone *pq_mem;
327 : : char name[RTE_MEMZONE_NAMESIZE];
328 : : struct cnxk_cpt_qp *qp;
329 : : uint32_t len;
330 : : uint8_t *va;
331 : : int ret;
332 : :
333 : : /* Allocate queue pair */
334 : 0 : qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp),
335 : : ROC_ALIGN, 0);
336 [ # # ]: 0 : if (qp == NULL) {
337 : 0 : plt_err("Could not allocate queue pair");
338 : 0 : return NULL;
339 : : }
340 : :
341 : : /* For pending queue */
342 : 0 : len = iq_len * sizeof(struct cpt_inflight_req);
343 : :
344 : 0 : qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
345 : : qp_id);
346 : :
347 : 0 : pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(),
348 : : RTE_MEMZONE_SIZE_HINT_ONLY |
349 : : RTE_MEMZONE_256MB,
350 : : RTE_CACHE_LINE_SIZE);
351 [ # # ]: 0 : if (pq_mem == NULL) {
352 : 0 : plt_err("Could not allocate reserved memzone");
353 : 0 : goto qp_free;
354 : : }
355 : :
356 : 0 : va = pq_mem->addr;
357 : :
358 : : memset(va, 0, len);
359 : :
360 : 0 : ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len);
361 [ # # ]: 0 : if (ret) {
362 : 0 : plt_err("Could not create mempool for metabuf");
363 : 0 : goto pq_mem_free;
364 : : }
365 : :
366 : : /* Initialize pending queue */
367 : 0 : qp->pend_q.req_queue = pq_mem->addr;
368 : 0 : qp->pend_q.head = 0;
369 : 0 : qp->pend_q.tail = 0;
370 : :
371 : 0 : return qp;
372 : :
373 : : pq_mem_free:
374 : 0 : rte_memzone_free(pq_mem);
375 : 0 : qp_free:
376 : 0 : rte_free(qp);
377 : 0 : return NULL;
378 : : }
379 : :
380 : : static int
381 : 0 : cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp)
382 : : {
383 : : const struct rte_memzone *pq_mem;
384 : : char name[RTE_MEMZONE_NAMESIZE];
385 : : int ret;
386 : :
387 : : cnxk_cpt_metabuf_mempool_destroy(qp);
388 : :
389 : 0 : qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id,
390 : 0 : qp->lf.lf_id);
391 : :
392 : 0 : pq_mem = rte_memzone_lookup(name);
393 : :
394 : 0 : ret = rte_memzone_free(pq_mem);
395 [ # # ]: 0 : if (ret)
396 : : return ret;
397 : :
398 : 0 : rte_free(qp);
399 : :
400 : 0 : return 0;
401 : : }
402 : :
403 : : int
404 : 0 : cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id)
405 : : {
406 : 0 : struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id];
407 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
408 : : struct roc_cpt *roc_cpt = &vf->cpt;
409 : : struct roc_cpt_lf *lf;
410 : : int ret;
411 : :
412 [ # # ]: 0 : if (qp == NULL)
413 : : return -EINVAL;
414 : :
415 : 0 : lf = roc_cpt->lf[qp_id];
416 [ # # ]: 0 : if (lf == NULL)
417 : : return -ENOTSUP;
418 : :
419 : 0 : roc_cpt_lf_fini(lf);
420 : :
421 : 0 : ret = cnxk_cpt_qp_destroy(dev, qp);
422 [ # # ]: 0 : if (ret) {
423 : 0 : plt_err("Could not destroy queue pair %d", qp_id);
424 : 0 : return ret;
425 : : }
426 : :
427 : 0 : roc_cpt->lf[qp_id] = NULL;
428 : 0 : dev->data->queue_pairs[qp_id] = NULL;
429 : :
430 : 0 : return 0;
431 : : }
432 : :
433 : : int
434 : 0 : cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
435 : : const struct rte_cryptodev_qp_conf *conf,
436 : : int socket_id __rte_unused)
437 : : {
438 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
439 : 0 : struct roc_cpt *roc_cpt = &vf->cpt;
440 : : struct rte_pci_device *pci_dev;
441 : : struct cnxk_cpt_qp *qp;
442 : : uint32_t nb_desc;
443 : : int ret;
444 : :
445 [ # # ]: 0 : if (dev->data->queue_pairs[qp_id] != NULL)
446 : 0 : cnxk_cpt_queue_pair_release(dev, qp_id);
447 : :
448 : 0 : pci_dev = RTE_DEV_TO_PCI(dev->device);
449 : :
450 [ # # ]: 0 : if (pci_dev->mem_resource[2].addr == NULL) {
451 : 0 : plt_err("Invalid PCI mem address");
452 : 0 : return -EIO;
453 : : }
454 : :
455 : : /* Update nb_desc to next power of 2 to aid in pending queue checks */
456 : 0 : nb_desc = plt_align32pow2(conf->nb_descriptors);
457 : :
458 : 0 : qp = cnxk_cpt_qp_create(dev, qp_id, nb_desc);
459 [ # # ]: 0 : if (qp == NULL) {
460 : 0 : plt_err("Could not create queue pair %d", qp_id);
461 : 0 : return -ENOMEM;
462 : : }
463 : :
464 : 0 : qp->lf.lf_id = qp_id;
465 : 0 : qp->lf.nb_desc = nb_desc;
466 : :
467 : 0 : ret = roc_cpt_lf_init(roc_cpt, &qp->lf);
468 [ # # ]: 0 : if (ret < 0) {
469 : 0 : plt_err("Could not initialize queue pair %d", qp_id);
470 : : ret = -EINVAL;
471 : 0 : goto exit;
472 : : }
473 : :
474 : 0 : qp->pend_q.pq_mask = qp->lf.nb_desc - 1;
475 : :
476 : 0 : roc_cpt->lf[qp_id] = &qp->lf;
477 : :
478 : 0 : ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id, true);
479 [ # # ]: 0 : if (ret < 0) {
480 : 0 : roc_cpt->lf[qp_id] = NULL;
481 : 0 : plt_err("Could not init lmtline for queue pair %d", qp_id);
482 : 0 : goto exit;
483 : : }
484 : :
485 : 0 : qp->sess_mp = conf->mp_session;
486 : 0 : dev->data->queue_pairs[qp_id] = qp;
487 : :
488 [ # # ]: 0 : if (qp_id == vf->rx_inject_qp) {
489 : 0 : ret = roc_cpt_lmtline_init(roc_cpt, &vf->rx_inj_lmtline, vf->rx_inject_qp, true);
490 [ # # ]: 0 : if (ret) {
491 : 0 : plt_err("Could not init lmtline Rx inject");
492 : 0 : goto exit;
493 : : }
494 : :
495 : 0 : vf->rx_inj_sso_pf_func = roc_idev_nix_inl_dev_pffunc_get();
496 : :
497 : : /* Block the queue for other submissions */
498 : 0 : qp->pend_q.pq_mask = 0;
499 : : }
500 : :
501 : : return 0;
502 : :
503 : 0 : exit:
504 : 0 : cnxk_cpt_qp_destroy(dev, qp);
505 : 0 : return ret;
506 : : }
507 : :
508 : : int
509 : 0 : cnxk_cpt_queue_pair_reset(struct rte_cryptodev *dev, uint16_t qp_id,
510 : : const struct rte_cryptodev_qp_conf *conf, int socket_id)
511 : : {
512 [ # # ]: 0 : if (conf == NULL) {
513 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
514 : : struct roc_cpt_lf *lf;
515 : :
516 [ # # ]: 0 : if (vf == NULL)
517 : : return -ENOTSUP;
518 : :
519 : 0 : lf = vf->cpt.lf[qp_id];
520 : 0 : roc_cpt_lf_reset(lf);
521 : 0 : roc_cpt_iq_enable(lf);
522 : :
523 : 0 : return 0;
524 : : }
525 : :
526 : 0 : return cnxk_cpt_queue_pair_setup(dev, qp_id, conf, socket_id);
527 : : }
528 : :
529 : : uint32_t
530 : 0 : cnxk_cpt_qp_depth_used(void *qptr)
531 : : {
532 : : struct cnxk_cpt_qp *qp = qptr;
533 : : struct pending_queue *pend_q;
534 : : union cpt_fc_write_s fc;
535 : :
536 : : pend_q = &qp->pend_q;
537 : :
538 : 0 : fc.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)(qp->lmtline.fc_addr),
539 : : rte_memory_order_relaxed);
540 : :
541 : 0 : return RTE_MAX(pending_queue_infl_cnt(pend_q->head, pend_q->tail, pend_q->pq_mask),
542 : : fc.s.qsize);
543 : : }
544 : :
545 : : unsigned int
546 : 0 : cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
547 : : {
548 : 0 : return sizeof(struct cnxk_se_sess);
549 : : }
550 : :
551 : : static bool
552 : : is_valid_pdcp_cipher_alg(struct rte_crypto_sym_xform *c_xfrm,
553 : : struct cnxk_se_sess *sess)
554 : : {
555 [ # # # # : 0 : switch (c_xfrm->cipher.algo) {
# # ]
556 : : case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
557 : : case RTE_CRYPTO_CIPHER_ZUC_EEA3:
558 : : break;
559 : 0 : case RTE_CRYPTO_CIPHER_AES_CTR:
560 : 0 : sess->aes_ctr_eea2 = 1;
561 : : break;
562 : : default:
563 : : return false;
564 : : }
565 : :
566 : : return true;
567 : : }
568 : :
569 : : static int
570 : 0 : cnxk_sess_fill(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
571 : : struct cnxk_se_sess *sess)
572 : : {
573 : : struct rte_crypto_sym_xform *aead_xfrm = NULL;
574 : : struct rte_crypto_sym_xform *c_xfrm = NULL;
575 : : struct rte_crypto_sym_xform *a_xfrm = NULL;
576 : : bool ciph_then_auth = false;
577 : :
578 [ # # ]: 0 : if (roc_cpt->hw_caps[CPT_ENG_TYPE_SE].pdcp_chain_zuc256)
579 : 0 : sess->roc_se_ctx.pdcp_iv_offset = 24;
580 : : else
581 : 0 : sess->roc_se_ctx.pdcp_iv_offset = 16;
582 : :
583 [ # # ]: 0 : if (xform == NULL)
584 : : return -EINVAL;
585 : :
586 [ # # ]: 0 : if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
587 : : c_xfrm = xform;
588 : 0 : a_xfrm = xform->next;
589 : : ciph_then_auth = true;
590 [ # # ]: 0 : } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
591 : 0 : c_xfrm = xform->next;
592 : : a_xfrm = xform;
593 : : ciph_then_auth = false;
594 : : } else {
595 : : aead_xfrm = xform;
596 : : }
597 : :
598 [ # # # # ]: 0 : if (c_xfrm != NULL && c_xfrm->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
599 : 0 : plt_dp_err("Invalid type in cipher xform");
600 : 0 : return -EINVAL;
601 : : }
602 : :
603 [ # # # # ]: 0 : if (a_xfrm != NULL && a_xfrm->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
604 : 0 : plt_dp_err("Invalid type in auth xform");
605 : 0 : return -EINVAL;
606 : : }
607 : :
608 [ # # # # ]: 0 : if (aead_xfrm != NULL && aead_xfrm->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
609 : 0 : plt_dp_err("Invalid type in AEAD xform");
610 : 0 : return -EINVAL;
611 : : }
612 : :
613 [ # # # # ]: 0 : if ((aead_xfrm == NULL) &&
614 [ # # # # ]: 0 : (c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL) &&
615 [ # # ]: 0 : (a_xfrm == NULL || a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL))
616 : 0 : sess->passthrough = 1;
617 : :
618 : : /* Cipher only */
619 [ # # # # : 0 : if (c_xfrm != NULL && (a_xfrm == NULL || a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL)) {
# # ]
620 : : if (fill_sess_cipher(c_xfrm, sess))
621 : 0 : return -ENOTSUP;
622 : : else
623 : 0 : return 0;
624 : : }
625 : :
626 : : /* Auth only */
627 [ # # # # ]: 0 : if (a_xfrm != NULL &&
628 [ # # ]: 0 : (c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL)) {
629 : : if (fill_sess_auth(a_xfrm, sess))
630 : 0 : return -ENOTSUP;
631 : : else
632 : 0 : return 0;
633 : : }
634 : :
635 : : /* AEAD */
636 [ # # ]: 0 : if (aead_xfrm != NULL) {
637 : : if (fill_sess_aead(aead_xfrm, sess))
638 : 0 : return -ENOTSUP;
639 : : else
640 : 0 : return 0;
641 : : }
642 : :
643 : : /* Chained ops */
644 [ # # ]: 0 : if (c_xfrm == NULL || a_xfrm == NULL) {
645 : 0 : plt_dp_err("Invalid xforms");
646 : 0 : return -EINVAL;
647 : : }
648 : :
649 [ # # ]: 0 : if (c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_AES_XTS) {
650 : 0 : plt_err("AES XTS with auth algorithm is not supported");
651 : 0 : return -ENOTSUP;
652 : : }
653 : :
654 [ # # ]: 0 : if (c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
655 [ # # ]: 0 : a_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA1) {
656 : 0 : plt_dp_err("3DES-CBC + SHA1 is not supported");
657 : 0 : return -ENOTSUP;
658 : : }
659 : :
660 : : /* Cipher then auth */
661 [ # # ]: 0 : if (ciph_then_auth) {
662 [ # # ]: 0 : if (c_xfrm->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
663 [ # # ]: 0 : if (a_xfrm->auth.op != RTE_CRYPTO_AUTH_OP_VERIFY)
664 : : return -EINVAL;
665 : 0 : sess->auth_first = 1;
666 [ # # # ]: 0 : switch (a_xfrm->auth.algo) {
667 [ # # ]: 0 : case RTE_CRYPTO_AUTH_SHA1_HMAC:
668 : : switch (c_xfrm->cipher.algo) {
669 : : case RTE_CRYPTO_CIPHER_AES_CBC:
670 : : break;
671 : : default:
672 : : return -ENOTSUP;
673 : : }
674 : : break;
675 : : case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
676 : : case RTE_CRYPTO_AUTH_ZUC_EIA3:
677 : : case RTE_CRYPTO_AUTH_AES_CMAC:
678 : : if (!is_valid_pdcp_cipher_alg(c_xfrm, sess))
679 : : return -ENOTSUP;
680 : : break;
681 : : default:
682 : : return -ENOTSUP;
683 : : }
684 : : }
685 : 0 : sess->roc_se_ctx.ciph_then_auth = 1;
686 [ # # ]: 0 : sess->chained_op = 1;
687 : : if (fill_sess_cipher(c_xfrm, sess))
688 : 0 : return -ENOTSUP;
689 : : if (fill_sess_auth(a_xfrm, sess))
690 : 0 : return -ENOTSUP;
691 : : else
692 : 0 : return 0;
693 : : }
694 : :
695 : : /* else */
696 : :
697 [ # # ]: 0 : if (c_xfrm->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
698 [ # # ]: 0 : if (a_xfrm->auth.op != RTE_CRYPTO_AUTH_OP_GENERATE)
699 : : return -EINVAL;
700 : 0 : sess->auth_first = 1;
701 [ # # # ]: 0 : switch (a_xfrm->auth.algo) {
702 [ # # ]: 0 : case RTE_CRYPTO_AUTH_SHA1_HMAC:
703 : : switch (c_xfrm->cipher.algo) {
704 : : case RTE_CRYPTO_CIPHER_AES_CBC:
705 : : break;
706 : : default:
707 : : return -ENOTSUP;
708 : : }
709 : : break;
710 : : case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
711 : : case RTE_CRYPTO_AUTH_ZUC_EIA3:
712 : : case RTE_CRYPTO_AUTH_AES_CMAC:
713 : : if (!is_valid_pdcp_cipher_alg(c_xfrm, sess))
714 : : return -ENOTSUP;
715 : : break;
716 : : default:
717 : : return -ENOTSUP;
718 : : }
719 : : }
720 : :
721 : 0 : sess->roc_se_ctx.auth_then_ciph = 1;
722 [ # # ]: 0 : sess->chained_op = 1;
723 : : if (fill_sess_auth(a_xfrm, sess))
724 : 0 : return -ENOTSUP;
725 : : if (fill_sess_cipher(c_xfrm, sess))
726 : 0 : return -ENOTSUP;
727 : : else
728 : 0 : return 0;
729 : : }
730 : :
731 : : static uint64_t
732 : 0 : cnxk_cpt_inst_w7_get(struct cnxk_se_sess *sess, struct roc_cpt *roc_cpt)
733 : : {
734 : : union cpt_inst_w7 inst_w7;
735 : :
736 [ # # ]: 0 : inst_w7.s.cptr = (uint64_t)&sess->roc_se_ctx.se_ctx;
737 : :
738 [ # # ]: 0 : if (hw_ctx_cache_enable())
739 : 0 : inst_w7.s.ctx_val = 1;
740 : : else
741 : 0 : inst_w7.s.cptr += 8;
742 : :
743 : : /* Set the engine group */
744 [ # # ]: 0 : if (roc_model_is_cn20k())
745 : 0 : inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
746 : 0 : else if (sess->zsk_flag || sess->aes_ctr_eea2 || sess->is_sha3 || sess->is_sm3 ||
747 [ # # ]: 0 : sess->passthrough || sess->is_sm4)
748 : 0 : inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
749 : : else
750 : 0 : inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
751 : :
752 : 0 : return inst_w7.u64;
753 : : }
754 : :
755 : : int
756 : 0 : sym_session_configure(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
757 : : struct rte_cryptodev_sym_session *sess, bool is_session_less)
758 : : {
759 : : enum cpt_dp_thread_type thr_type;
760 : : struct cnxk_se_sess *sess_priv = (struct cnxk_se_sess *)sess;
761 : : int ret;
762 : :
763 [ # # ]: 0 : if (is_session_less)
764 : : memset(sess_priv, 0, sizeof(struct cnxk_se_sess));
765 : :
766 : 0 : ret = cnxk_sess_fill(roc_cpt, xform, sess_priv);
767 [ # # ]: 0 : if (ret)
768 : 0 : goto priv_put;
769 : :
770 : 0 : sess_priv->lf = roc_cpt->lf[0];
771 : :
772 [ # # ]: 0 : if (sess_priv->passthrough)
773 : : thr_type = CPT_DP_THREAD_TYPE_PT;
774 [ # # ]: 0 : else if (sess_priv->cpt_op & ROC_SE_OP_CIPHER_MASK) {
775 [ # # # # : 0 : switch (sess_priv->roc_se_ctx.fc_type) {
# # ]
776 : 0 : case ROC_SE_FC_GEN:
777 [ # # ]: 0 : if (sess_priv->aes_gcm || sess_priv->aes_ccm || sess_priv->chacha_poly)
778 : : thr_type = CPT_DP_THREAD_TYPE_FC_AEAD;
779 : : else
780 : : thr_type = CPT_DP_THREAD_TYPE_FC_CHAIN;
781 : : break;
782 : : case ROC_SE_PDCP:
783 : : thr_type = CPT_DP_THREAD_TYPE_PDCP;
784 : : break;
785 : 0 : case ROC_SE_KASUMI:
786 : : thr_type = CPT_DP_THREAD_TYPE_KASUMI;
787 : 0 : break;
788 : 0 : case ROC_SE_PDCP_CHAIN:
789 : : thr_type = CPT_DP_THREAD_TYPE_PDCP_CHAIN;
790 : 0 : break;
791 : 0 : case ROC_SE_SM:
792 : : thr_type = CPT_DP_THREAD_TYPE_SM;
793 : 0 : break;
794 : 0 : default:
795 : 0 : plt_err("Invalid op type");
796 : : ret = -ENOTSUP;
797 : 0 : goto priv_put;
798 : : }
799 : : } else {
800 : : thr_type = CPT_DP_THREAD_AUTH_ONLY;
801 : : }
802 : :
803 : 0 : sess_priv->dp_thr_type = thr_type;
804 : :
805 [ # # ]: 0 : if ((sess_priv->roc_se_ctx.fc_type == ROC_SE_HASH_HMAC) &&
806 : : cpt_mac_len_verify(&xform->auth)) {
807 : 0 : plt_dp_err("MAC length is not supported");
808 [ # # ]: 0 : if (sess_priv->roc_se_ctx.auth_key != NULL) {
809 : 0 : plt_free(sess_priv->roc_se_ctx.auth_key);
810 : 0 : sess_priv->roc_se_ctx.auth_key = NULL;
811 : : }
812 : :
813 : : ret = -ENOTSUP;
814 : 0 : goto priv_put;
815 : : }
816 : :
817 [ # # ]: 0 : sess_priv->cpt_inst_w7 = cnxk_cpt_inst_w7_get(sess_priv, roc_cpt);
818 : :
819 [ # # ]: 0 : if (hw_ctx_cache_enable())
820 : 0 : roc_se_ctx_init(&sess_priv->roc_se_ctx);
821 : :
822 : : return 0;
823 : :
824 : : priv_put:
825 : : return ret;
826 : : }
827 : :
828 : : int
829 : 0 : cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
830 : : struct rte_crypto_sym_xform *xform,
831 : : struct rte_cryptodev_sym_session *sess)
832 : : {
833 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
834 : 0 : struct roc_cpt *roc_cpt = &vf->cpt;
835 : :
836 : 0 : return sym_session_configure(roc_cpt, xform, sess, false);
837 : : }
838 : :
839 : : void
840 [ # # ]: 0 : sym_session_clear(struct rte_cryptodev_sym_session *sess, bool is_session_less)
841 : : {
842 : : struct cnxk_se_sess *sess_priv = (struct cnxk_se_sess *)sess;
843 : :
844 : : /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
845 [ # # ]: 0 : if (hw_ctx_cache_enable())
846 : 0 : roc_cpt_lf_ctx_flush(sess_priv->lf, &sess_priv->roc_se_ctx.se_ctx, true);
847 : :
848 [ # # ]: 0 : if (sess_priv->roc_se_ctx.auth_key != NULL)
849 : 0 : plt_free(sess_priv->roc_se_ctx.auth_key);
850 : :
851 [ # # ]: 0 : if (is_session_less)
852 : 0 : memset(sess_priv, 0, cnxk_cpt_sym_session_get_size(NULL));
853 : 0 : }
854 : :
855 : : void
856 : 0 : cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev __rte_unused,
857 : : struct rte_cryptodev_sym_session *sess)
858 : : {
859 : 0 : return sym_session_clear(sess, false);
860 : : }
861 : :
862 : : unsigned int
863 : 0 : cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused)
864 : : {
865 : 0 : return sizeof(struct cnxk_ae_sess);
866 : : }
867 : :
868 : : void
869 [ # # ]: 0 : cnxk_ae_session_clear(struct rte_cryptodev *dev __rte_unused,
870 : : struct rte_cryptodev_asym_session *sess)
871 : : {
872 : : struct cnxk_ae_sess *priv = (struct cnxk_ae_sess *)sess;
873 : :
874 : : /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
875 [ # # ]: 0 : if (roc_errata_cpt_hang_on_mixed_ctx_val())
876 : 0 : roc_cpt_lf_ctx_flush(priv->lf, &priv->hw_ctx, true);
877 : :
878 : : /* Free resources allocated in session_cfg */
879 : 0 : cnxk_ae_free_session_parameters(priv);
880 : :
881 : : /* Reset and free object back to pool */
882 : : memset(priv, 0, sizeof(struct cnxk_ae_sess));
883 : 0 : }
884 : :
885 : : int
886 : 0 : cnxk_ae_session_cfg(struct rte_cryptodev *dev, struct rte_crypto_asym_xform *xform,
887 : : struct rte_cryptodev_asym_session *sess)
888 : : {
889 : : struct cnxk_ae_sess *priv = (struct cnxk_ae_sess *)sess;
890 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
891 : : struct roc_cpt *roc_cpt = &vf->cpt;
892 : : union cpt_inst_w7 w7;
893 : : struct hw_ctx_s *hwc;
894 : : int ret;
895 : :
896 : : ret = cnxk_ae_fill_session_parameters(priv, xform);
897 : : if (ret)
898 : 0 : return ret;
899 : :
900 : 0 : priv->lf = roc_cpt->lf[0];
901 : :
902 : 0 : w7.u64 = 0;
903 [ # # ]: 0 : w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
904 : :
905 [ # # ]: 0 : if (roc_errata_cpt_hang_on_mixed_ctx_val()) {
906 : 0 : hwc = &priv->hw_ctx;
907 : 0 : hwc->w0.s.aop_valid = 1;
908 : 0 : hwc->w0.s.ctx_hdr_size = 0;
909 : 0 : hwc->w0.s.ctx_size = 1;
910 : 0 : hwc->w0.s.ctx_push_size = 1;
911 : :
912 : 0 : w7.s.cptr = (uint64_t)hwc;
913 : 0 : w7.s.ctx_val = 1;
914 : : }
915 : :
916 : 0 : priv->cpt_inst_w7 = w7.u64;
917 : 0 : priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
918 : 0 : priv->ec_grp = vf->ec_grp;
919 : :
920 : 0 : return 0;
921 : : }
922 : :
923 : : void
924 : 0 : cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp)
925 : : {
926 : : struct pending_queue *pend_q = &qp->pend_q;
927 : : uint64_t inflight, enq_ptr, deq_ptr, insts;
928 : : union cpt_lf_q_inst_ptr inst_ptr;
929 : : union cpt_lf_inprog lf_inprog;
930 : :
931 : 0 : plt_print("Lcore ID: %d, LF/QP ID: %d", rte_lcore_id(), qp->lf.lf_id);
932 : 0 : plt_print("");
933 : 0 : plt_print("S/w pending queue:");
934 : 0 : plt_print("\tHead: %"PRIu64"", pend_q->head);
935 : 0 : plt_print("\tTail: %"PRIu64"", pend_q->tail);
936 : 0 : plt_print("\tMask: 0x%"PRIx64"", pend_q->pq_mask);
937 : 0 : plt_print("\tInflight count: %"PRIu64"",
938 : : pending_queue_infl_cnt(pend_q->head, pend_q->tail,
939 : : pend_q->pq_mask));
940 : :
941 : 0 : plt_print("");
942 : 0 : plt_print("H/w pending queue:");
943 : :
944 : 0 : lf_inprog.u = plt_read64(qp->lf.rbase + CPT_LF_INPROG);
945 : 0 : inflight = lf_inprog.s.inflight;
946 : 0 : plt_print("\tInflight in engines: %"PRIu64"", inflight);
947 : :
948 [ # # ]: 0 : inst_ptr.u = plt_read64(qp->lf.rbase + CPT_LF_Q_INST_PTR);
949 : :
950 : 0 : enq_ptr = inst_ptr.s.nq_ptr;
951 : 0 : deq_ptr = inst_ptr.s.dq_ptr;
952 : :
953 [ # # ]: 0 : if (enq_ptr >= deq_ptr)
954 : 0 : insts = enq_ptr - deq_ptr;
955 : : else
956 : 0 : insts = (enq_ptr + pend_q->pq_mask + 1 + 320 + 40) - deq_ptr;
957 : :
958 : 0 : plt_print("\tNQ ptr: 0x%"PRIx64"", enq_ptr);
959 : 0 : plt_print("\tDQ ptr: 0x%"PRIx64"", deq_ptr);
960 : 0 : plt_print("Insts waiting in CPT: %"PRIu64"", insts);
961 : :
962 : 0 : plt_print("");
963 : 0 : roc_cpt_afs_print(qp->lf.roc_cpt);
964 : 0 : roc_cpt_lfs_print(qp->lf.roc_cpt);
965 : 0 : }
966 : :
967 : : int
968 : 0 : cnxk_cpt_queue_pair_event_error_query(struct rte_cryptodev *dev, uint16_t qp_id)
969 : : {
970 : 0 : struct cnxk_cpt_vf *vf = dev->data->dev_private;
971 : : struct roc_cpt *roc_cpt = &vf->cpt;
972 : : struct roc_cpt_lf *lf;
973 : :
974 : 0 : lf = roc_cpt->lf[qp_id];
975 [ # # # # ]: 0 : if (lf && lf->error_event_pending) {
976 : 0 : lf->error_event_pending = 0;
977 : 0 : return 1;
978 : : }
979 : : return 0;
980 : : }
981 : :
982 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_qptr_get, 24.03)
983 : : struct rte_pmd_cnxk_crypto_qptr *
984 : 0 : rte_pmd_cnxk_crypto_qptr_get(uint8_t dev_id, uint16_t qp_id)
985 : : {
986 : : const struct rte_crypto_fp_ops *fp_ops;
987 : : void *qptr;
988 : :
989 : 0 : fp_ops = &rte_crypto_fp_ops[dev_id];
990 : 0 : qptr = fp_ops->qp.data[qp_id];
991 : :
992 : 0 : return qptr;
993 : : }
994 : :
995 : : static inline void
996 : 0 : cnxk_crypto_cn10k_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
997 : : {
998 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
999 : : uint64_t lmt_base, io_addr;
1000 : : uint16_t lmt_id;
1001 : : void *lmt_dst;
1002 : : int i;
1003 : :
1004 : 0 : lmt_base = qp->lmtline.lmt_base;
1005 : : io_addr = qp->lmtline.io_addr;
1006 : :
1007 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1008 : :
1009 : 0 : lmt_dst = PLT_PTR_CAST(lmt_base);
1010 : 0 : again:
1011 : 0 : i = RTE_MIN(nb_inst, CN10K_CPT_PKTS_PER_LOOP);
1012 : :
1013 [ # # ]: 0 : memcpy(lmt_dst, inst, i * sizeof(struct cpt_inst_s));
1014 : :
1015 : : cn10k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1016 : :
1017 [ # # ]: 0 : if (nb_inst - i > 0) {
1018 : 0 : nb_inst -= CN10K_CPT_PKTS_PER_LOOP;
1019 : 0 : inst = RTE_PTR_ADD(inst, CN10K_CPT_PKTS_PER_LOOP * sizeof(struct cpt_inst_s));
1020 : 0 : goto again;
1021 : : }
1022 : 0 : }
1023 : :
1024 : : static inline void
1025 : : cnxk_crypto_cn9k_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
1026 : : {
1027 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
1028 : :
1029 : : const uint64_t lmt_base = qp->lf.lmt_base;
1030 : : const uint64_t io_addr = qp->lf.io_addr;
1031 : :
1032 [ # # ]: 0 : if (unlikely(nb_inst & 1)) {
1033 : : cn9k_cpt_inst_submit(inst, lmt_base, io_addr);
1034 : : inst = RTE_PTR_ADD(inst, sizeof(struct cpt_inst_s));
1035 : : nb_inst -= 1;
1036 : : }
1037 : :
1038 [ # # ]: 0 : while (nb_inst > 0) {
1039 : : cn9k_cpt_inst_submit_dual(inst, lmt_base, io_addr);
1040 : : inst = RTE_PTR_ADD(inst, 2 * sizeof(struct cpt_inst_s));
1041 : : nb_inst -= 2;
1042 : : }
1043 : : }
1044 : :
1045 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_submit, 24.03)
1046 : : void
1047 [ # # ]: 0 : rte_pmd_cnxk_crypto_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
1048 : : {
1049 [ # # # # ]: 0 : if (roc_model_is_cn10k() || roc_model_is_cn20k())
1050 : 0 : return cnxk_crypto_cn10k_submit(qptr, inst, nb_inst);
1051 [ # # ]: 0 : else if (roc_model_is_cn9k())
1052 : : return cnxk_crypto_cn9k_submit(qptr, inst, nb_inst);
1053 : :
1054 : 0 : plt_err("Invalid cnxk model");
1055 : : }
1056 : :
1057 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_flush, 24.07)
1058 : : int
1059 : 0 : rte_pmd_cnxk_crypto_cptr_flush(struct rte_pmd_cnxk_crypto_qptr *qptr,
1060 : : struct rte_pmd_cnxk_crypto_cptr *cptr, bool invalidate)
1061 : : {
1062 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
1063 : :
1064 [ # # ]: 0 : if (unlikely(qptr == NULL)) {
1065 : 0 : plt_err("Invalid queue pair pointer");
1066 : 0 : return -EINVAL;
1067 : : }
1068 : :
1069 [ # # ]: 0 : if (unlikely(cptr == NULL)) {
1070 : 0 : plt_err("Invalid CPTR pointer");
1071 : 0 : return -EINVAL;
1072 : : }
1073 : :
1074 [ # # ]: 0 : if (unlikely(roc_model_is_cn9k())) {
1075 : 0 : plt_err("Invalid cnxk model");
1076 : 0 : return -EINVAL;
1077 : : }
1078 : :
1079 : 0 : return roc_cpt_lf_ctx_flush(&qp->lf, cptr, invalidate);
1080 : : }
1081 : :
1082 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_get, 24.07)
1083 : : struct rte_pmd_cnxk_crypto_cptr *
1084 : 0 : rte_pmd_cnxk_crypto_cptr_get(struct rte_pmd_cnxk_crypto_sess *rte_sess)
1085 : : {
1086 [ # # ]: 0 : if (rte_sess == NULL) {
1087 : 0 : plt_err("Invalid session pointer");
1088 : 0 : return NULL;
1089 : : }
1090 : :
1091 [ # # ]: 0 : if (rte_sess->sec_sess == NULL) {
1092 : 0 : plt_err("Invalid RTE session pointer");
1093 : 0 : return NULL;
1094 : : }
1095 : :
1096 [ # # ]: 0 : if (rte_sess->op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1097 : : struct cnxk_ae_sess *ae_sess = PLT_PTR_CAST(rte_sess->crypto_asym_sess);
1098 : 0 : return PLT_PTR_CAST(&ae_sess->hw_ctx);
1099 : : }
1100 : :
1101 [ # # ]: 0 : if (rte_sess->op_type != RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1102 : 0 : plt_err("Invalid crypto operation type");
1103 : 0 : return NULL;
1104 : : }
1105 : :
1106 [ # # ]: 0 : if (rte_sess->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
1107 : : struct cnxk_se_sess *se_sess = PLT_PTR_CAST(rte_sess->crypto_sym_sess);
1108 : 0 : return PLT_PTR_CAST(&se_sess->roc_se_ctx.se_ctx);
1109 : : }
1110 : :
1111 [ # # ]: 0 : if (rte_sess->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1112 [ # # ]: 0 : if (roc_model_is_cn20k()) {
1113 : : struct cn20k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
1114 : :
1115 : 0 : return PLT_PTR_CAST(&sec_sess->sa);
1116 : : }
1117 : :
1118 [ # # ]: 0 : if (roc_model_is_cn10k()) {
1119 : : struct cn10k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
1120 : 0 : return PLT_PTR_CAST(&sec_sess->sa);
1121 : : }
1122 : :
1123 [ # # ]: 0 : if (roc_model_is_cn9k()) {
1124 : : struct cn9k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
1125 : 0 : return PLT_PTR_CAST(&sec_sess->sa);
1126 : : }
1127 : :
1128 : 0 : plt_err("Invalid cnxk model");
1129 : 0 : return NULL;
1130 : : }
1131 : :
1132 : 0 : plt_err("Invalid session type");
1133 : 0 : return NULL;
1134 : : }
1135 : :
1136 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_read, 24.07)
1137 : : int
1138 : 0 : rte_pmd_cnxk_crypto_cptr_read(struct rte_pmd_cnxk_crypto_qptr *qptr,
1139 : : struct rte_pmd_cnxk_crypto_cptr *cptr, void *data, uint32_t len)
1140 : : {
1141 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
1142 : : int ret;
1143 : :
1144 [ # # ]: 0 : if (unlikely(qptr == NULL)) {
1145 : 0 : plt_err("Invalid queue pair pointer");
1146 : 0 : return -EINVAL;
1147 : : }
1148 : :
1149 [ # # ]: 0 : if (unlikely(cptr == NULL)) {
1150 : 0 : plt_err("Invalid CPTR pointer");
1151 : 0 : return -EINVAL;
1152 : : }
1153 : :
1154 [ # # ]: 0 : if (unlikely(data == NULL)) {
1155 : 0 : plt_err("Invalid data pointer");
1156 : 0 : return -EINVAL;
1157 : : }
1158 : :
1159 : 0 : ret = roc_cpt_lf_ctx_flush(&qp->lf, cptr, false);
1160 [ # # ]: 0 : if (ret)
1161 : : return ret;
1162 : :
1163 : : /* Wait for the flush to complete. */
1164 : : rte_delay_ms(1);
1165 : :
1166 : 0 : memcpy(data, cptr, len);
1167 : 0 : return 0;
1168 : : }
1169 : :
1170 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_write, 24.07)
1171 : : int
1172 : 0 : rte_pmd_cnxk_crypto_cptr_write(struct rte_pmd_cnxk_crypto_qptr *qptr,
1173 : : struct rte_pmd_cnxk_crypto_cptr *cptr, void *data, uint32_t len)
1174 : : {
1175 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
1176 : : int ret;
1177 : :
1178 [ # # ]: 0 : if (unlikely(qptr == NULL)) {
1179 : 0 : plt_err("Invalid queue pair pointer");
1180 : 0 : return -EINVAL;
1181 : : }
1182 : :
1183 [ # # ]: 0 : if (unlikely(cptr == NULL)) {
1184 : 0 : plt_err("Invalid CPTR pointer");
1185 : 0 : return -EINVAL;
1186 : : }
1187 : :
1188 [ # # ]: 0 : if (unlikely(data == NULL)) {
1189 : 0 : plt_err("Invalid data pointer");
1190 : 0 : return -EINVAL;
1191 : : }
1192 : :
1193 : 0 : ret = roc_cpt_ctx_write(&qp->lf, data, cptr, len);
1194 [ # # ]: 0 : if (ret) {
1195 : 0 : plt_err("Could not write to CPTR");
1196 : 0 : return ret;
1197 : : }
1198 : :
1199 : 0 : ret = roc_cpt_lf_ctx_flush(&qp->lf, cptr, false);
1200 [ # # ]: 0 : if (ret)
1201 : : return ret;
1202 : :
1203 : : rte_atomic_thread_fence(rte_memory_order_seq_cst);
1204 : :
1205 : 0 : return 0;
1206 : : }
1207 : :
1208 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_qp_stats_get, 24.07)
1209 : : int
1210 : 0 : rte_pmd_cnxk_crypto_qp_stats_get(struct rte_pmd_cnxk_crypto_qptr *qptr,
1211 : : struct rte_pmd_cnxk_crypto_qp_stats *stats)
1212 : : {
1213 : : struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
1214 : : struct roc_cpt_lf *lf;
1215 : :
1216 [ # # ]: 0 : if (unlikely(qptr == NULL)) {
1217 : 0 : plt_err("Invalid queue pair pointer");
1218 : 0 : return -EINVAL;
1219 : : }
1220 : :
1221 [ # # ]: 0 : if (unlikely(stats == NULL)) {
1222 : 0 : plt_err("Invalid stats pointer");
1223 : 0 : return -EINVAL;
1224 : : }
1225 : :
1226 [ # # ]: 0 : if (unlikely(roc_model_is_cn9k())) {
1227 : 0 : plt_err("Invalid cnxk model");
1228 : 0 : return -EINVAL;
1229 : : }
1230 : :
1231 : : lf = &qp->lf;
1232 : :
1233 : 0 : stats->ctx_enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
1234 : 0 : stats->ctx_enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
1235 : 0 : stats->ctx_dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
1236 : 0 : stats->ctx_dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
1237 : :
1238 : 0 : return 0;
1239 : : }
1240 : :
1241 : : #ifdef CPT_INST_DEBUG_ENABLE
1242 : : void
1243 : : cnxk_cpt_request_data_sgv2_mode_dump(uint8_t *in_buffer, bool glist, uint16_t components)
1244 : : {
1245 : : struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
1246 : : const char *list = glist ? "glist" : "slist";
1247 : : struct roc_sg2list_comp *sg_ptr = NULL;
1248 : : uint16_t list_cnt = 0;
1249 : : char suffix[64];
1250 : : int i, j;
1251 : :
1252 : : sg_ptr = (void *)in_buffer;
1253 : : for (i = 0; i < components; i++) {
1254 : : for (j = 0; j < sg_ptr->u.s.valid_segs; j++) {
1255 : : list_ptr[i * 3 + j].size = sg_ptr->u.s.len[j];
1256 : : list_ptr[i * 3 + j].vaddr = (void *)sg_ptr->ptr[j];
1257 : : list_ptr[i * 3 + j].vaddr = list_ptr[i * 3 + j].vaddr;
1258 : : list_cnt++;
1259 : : }
1260 : : sg_ptr++;
1261 : : }
1262 : :
1263 : : plt_err("Current %s: %u", list, list_cnt);
1264 : :
1265 : : for (i = 0; i < list_cnt; i++) {
1266 : : snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
1267 : : list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
1268 : : rte_hexdump(rte_log_get_stream(), suffix, list_ptr[i].vaddr, list_ptr[i].size);
1269 : : }
1270 : : }
1271 : :
1272 : : void
1273 : : cnxk_cpt_request_data_sg_mode_dump(uint8_t *in_buffer, bool glist)
1274 : : {
1275 : : struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
1276 : : const char *list = glist ? "glist" : "slist";
1277 : : struct roc_sglist_comp *sg_ptr = NULL;
1278 : : uint16_t list_cnt, components;
1279 : : char suffix[64];
1280 : : int i;
1281 : :
1282 : : sg_ptr = (void *)(in_buffer + 8);
1283 : : list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[2]));
1284 : : if (!glist) {
1285 : : components = list_cnt / 4;
1286 : : if (list_cnt % 4)
1287 : : components++;
1288 : : sg_ptr += components;
1289 : : list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[3]));
1290 : : }
1291 : :
1292 : : plt_err("Current %s: %u", list, list_cnt);
1293 : : components = list_cnt / 4;
1294 : : for (i = 0; i < components; i++) {
1295 : : list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
1296 : : list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
1297 : : list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
1298 : : list_ptr[i * 4 + 3].size = rte_be_to_cpu_16(sg_ptr->u.s.len[3]);
1299 : : list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
1300 : : list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
1301 : : list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
1302 : : list_ptr[i * 4 + 3].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[3]);
1303 : : list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
1304 : : list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
1305 : : list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
1306 : : list_ptr[i * 4 + 3].vaddr = list_ptr[i * 4 + 3].vaddr;
1307 : : sg_ptr++;
1308 : : }
1309 : :
1310 : : components = list_cnt % 4;
1311 : : switch (components) {
1312 : : case 3:
1313 : : list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
1314 : : list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
1315 : : list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
1316 : : [[fallthrough]];
1317 : : case 2:
1318 : : list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
1319 : : list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
1320 : : list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
1321 : : [[fallthrough]];
1322 : : case 1:
1323 : : list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
1324 : : list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
1325 : : list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
1326 : : break;
1327 : : default:
1328 : : break;
1329 : : }
1330 : :
1331 : : for (i = 0; i < list_cnt; i++) {
1332 : : snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
1333 : : list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
1334 : : rte_hexdump(rte_log_get_stream(), suffix, list_ptr[i].vaddr, list_ptr[i].size);
1335 : : }
1336 : : }
1337 : : #endif
|