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