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