1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_cryptodev.h>
9 #include <rte_cryptodev_pmd.h>
10 #include <rte_string_fns.h>
12 #include "cryptodev.h"
14 #define PIPELINE_CRYPTO_SESSION_CACHE_SIZE 128
16 static struct cryptodev_list cryptodev_list;
21 TAILQ_INIT(&cryptodev_list);
27 cryptodev_find(const char *name)
29 struct cryptodev *cryptodev;
34 TAILQ_FOREACH(cryptodev, &cryptodev_list, node)
35 if (strcmp(cryptodev->name, name) == 0)
42 cryptodev_next(struct cryptodev *cryptodev)
44 return (cryptodev == NULL) ?
45 TAILQ_FIRST(&cryptodev_list) :
46 TAILQ_NEXT(cryptodev, node);
50 cryptodev_create(const char *name, struct cryptodev_params *params)
52 struct rte_cryptodev_info dev_info;
53 struct rte_cryptodev_config dev_conf;
54 struct rte_cryptodev_qp_conf queue_conf;
55 struct cryptodev *cryptodev;
59 char mp_name[NAME_SIZE];
62 /* Check input params */
64 cryptodev_find(name) ||
65 (params->n_queues == 0) ||
66 (params->queue_size == 0) ||
67 (params->session_pool_size == 0))
70 if (params->dev_name) {
71 status = rte_cryptodev_get_dev_id(params->dev_name);
75 dev_id = (uint32_t)status;
77 if (rte_cryptodev_pmd_is_valid_dev(params->dev_id) == 0)
80 dev_id = params->dev_id;
83 cache_size = (params->session_pool_size / 2 <
84 PIPELINE_CRYPTO_SESSION_CACHE_SIZE) ?
85 (params->session_pool_size / 2) :
86 PIPELINE_CRYPTO_SESSION_CACHE_SIZE;
88 socket_id = rte_cryptodev_socket_id(dev_id);
89 rte_cryptodev_info_get(dev_id, &dev_info);
91 if (dev_info.max_nb_queue_pairs < params->n_queues)
94 dev_conf.socket_id = socket_id;
95 dev_conf.nb_queue_pairs = params->n_queues;
96 dev_conf.ff_disable = 0;
98 status = rte_cryptodev_configure(dev_id, &dev_conf);
102 queue_conf.nb_descriptors = params->queue_size;
103 for (i = 0; i < params->n_queues; i++) {
104 status = rte_cryptodev_queue_pair_setup(dev_id, i,
105 &queue_conf, socket_id);
110 if (rte_cryptodev_start(dev_id) < 0)
113 cryptodev = calloc(1, sizeof(struct cryptodev));
114 if (cryptodev == NULL) {
115 rte_cryptodev_stop(dev_id);
119 strlcpy(cryptodev->name, name, sizeof(cryptodev->name));
120 cryptodev->dev_id = dev_id;
121 cryptodev->n_queues = params->n_queues;
123 snprintf(mp_name, NAME_SIZE, "%s_mp%u", name, dev_id);
124 cryptodev->mp_create = rte_cryptodev_sym_session_pool_create(
126 params->session_pool_size,
131 if (!cryptodev->mp_create)
134 snprintf(mp_name, NAME_SIZE, "%s_mp_priv%u", name, dev_id);
135 cryptodev->mp_init = rte_mempool_create(
137 params->session_pool_size,
138 rte_cryptodev_sym_get_private_session_size(dev_id),
147 if (!cryptodev->mp_init)
150 TAILQ_INSERT_TAIL(&cryptodev_list, cryptodev, node);
155 if (cryptodev->mp_create)
156 rte_mempool_free(cryptodev->mp_create);
157 if (cryptodev->mp_init)
158 rte_mempool_free(cryptodev->mp_init);