1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_cryptodev.h>
9 #include <rte_string_fns.h>
11 #include "cryptodev.h"
13 #define PIPELINE_CRYPTO_SESSION_CACHE_SIZE 128
15 static struct cryptodev_list cryptodev_list;
20 TAILQ_INIT(&cryptodev_list);
26 cryptodev_find(const char *name)
28 struct cryptodev *cryptodev;
33 TAILQ_FOREACH(cryptodev, &cryptodev_list, node)
34 if (strcmp(cryptodev->name, name) == 0)
41 cryptodev_next(struct cryptodev *cryptodev)
43 return (cryptodev == NULL) ?
44 TAILQ_FIRST(&cryptodev_list) :
45 TAILQ_NEXT(cryptodev, node);
49 cryptodev_create(const char *name, struct cryptodev_params *params)
51 struct rte_cryptodev_info dev_info;
52 struct rte_cryptodev_config dev_conf;
53 struct rte_cryptodev_qp_conf queue_conf;
54 struct cryptodev *cryptodev;
58 char mp_name[NAME_SIZE];
61 /* Check input params */
63 cryptodev_find(name) ||
64 (params->n_queues == 0) ||
65 (params->queue_size == 0) ||
66 (params->session_pool_size == 0))
69 if (params->dev_name) {
70 status = rte_cryptodev_get_dev_id(params->dev_name);
74 dev_id = (uint32_t)status;
76 if (rte_cryptodev_is_valid_dev(params->dev_id) == 0)
79 dev_id = params->dev_id;
82 cache_size = (params->session_pool_size / 2 <
83 PIPELINE_CRYPTO_SESSION_CACHE_SIZE) ?
84 (params->session_pool_size / 2) :
85 PIPELINE_CRYPTO_SESSION_CACHE_SIZE;
87 socket_id = rte_cryptodev_socket_id(dev_id);
88 rte_cryptodev_info_get(dev_id, &dev_info);
90 if (dev_info.max_nb_queue_pairs < params->n_queues)
93 dev_conf.socket_id = socket_id;
94 dev_conf.nb_queue_pairs = params->n_queues;
95 dev_conf.ff_disable = 0;
97 status = rte_cryptodev_configure(dev_id, &dev_conf);
101 queue_conf.nb_descriptors = params->queue_size;
102 for (i = 0; i < params->n_queues; i++) {
103 status = rte_cryptodev_queue_pair_setup(dev_id, i,
104 &queue_conf, socket_id);
109 if (rte_cryptodev_start(dev_id) < 0)
112 cryptodev = calloc(1, sizeof(struct cryptodev));
113 if (cryptodev == NULL) {
114 rte_cryptodev_stop(dev_id);
118 strlcpy(cryptodev->name, name, sizeof(cryptodev->name));
119 cryptodev->dev_id = dev_id;
120 cryptodev->n_queues = params->n_queues;
122 snprintf(mp_name, NAME_SIZE, "%s_mp%u", name, dev_id);
123 cryptodev->mp_create = rte_cryptodev_sym_session_pool_create(
125 params->session_pool_size,
130 if (!cryptodev->mp_create)
133 snprintf(mp_name, NAME_SIZE, "%s_mp_priv%u", name, dev_id);
134 cryptodev->mp_init = rte_mempool_create(
136 params->session_pool_size,
137 rte_cryptodev_sym_get_private_session_size(dev_id),
146 if (!cryptodev->mp_init)
149 TAILQ_INSERT_TAIL(&cryptodev_list, cryptodev, node);
154 rte_mempool_free(cryptodev->mp_create);
155 rte_mempool_free(cryptodev->mp_init);