1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_cryptodev.h>
9 #include <cryptodev_pmd.h>
10 #include <rte_string_fns.h>
12 #include "rte_eth_softnic_internals.h"
14 #define SOFTNIC_CRYPTO_SESSION_CACHE_SIZE 128
17 softnic_cryptodev_init(struct pmd_internals *p)
19 TAILQ_INIT(&p->cryptodev_list);
25 softnic_cryptodev_free(struct pmd_internals *p)
28 struct softnic_cryptodev *cryptodev;
30 cryptodev = TAILQ_FIRST(&p->cryptodev_list);
31 if (cryptodev == NULL)
34 TAILQ_REMOVE(&p->cryptodev_list, cryptodev, node);
39 struct softnic_cryptodev *
40 softnic_cryptodev_find(struct pmd_internals *p,
43 struct softnic_cryptodev *cryptodev;
48 TAILQ_FOREACH(cryptodev, &p->cryptodev_list, node)
49 if (strcmp(cryptodev->name, name) == 0)
55 struct softnic_cryptodev *
56 softnic_cryptodev_create(struct pmd_internals *p,
58 struct softnic_cryptodev_params *params)
60 struct rte_cryptodev_info dev_info;
61 struct rte_cryptodev_config dev_conf;
62 struct rte_cryptodev_qp_conf queue_conf;
63 struct softnic_cryptodev *cryptodev;
67 char mp_name[NAME_SIZE];
70 /* Check input params */
72 softnic_cryptodev_find(p, name) ||
73 (params->n_queues == 0) ||
74 (params->queue_size == 0) ||
75 (params->session_pool_size == 0))
78 if (params->dev_name) {
79 status = rte_cryptodev_get_dev_id(params->dev_name);
83 dev_id = (uint32_t)status;
85 if (rte_cryptodev_is_valid_dev(params->dev_id) == 0)
88 dev_id = params->dev_id;
91 cache_size = (params->session_pool_size / 2 <
92 SOFTNIC_CRYPTO_SESSION_CACHE_SIZE) ?
93 (params->session_pool_size / 2) :
94 SOFTNIC_CRYPTO_SESSION_CACHE_SIZE;
96 socket_id = rte_cryptodev_socket_id(dev_id);
97 rte_cryptodev_info_get(dev_id, &dev_info);
99 if (dev_info.max_nb_queue_pairs < params->n_queues)
101 if (dev_info.feature_flags & RTE_CRYPTODEV_FF_HW_ACCELERATED)
104 dev_conf.socket_id = socket_id;
105 dev_conf.nb_queue_pairs = params->n_queues;
107 status = rte_cryptodev_configure(dev_id, &dev_conf);
111 queue_conf.nb_descriptors = params->queue_size;
112 for (i = 0; i < params->n_queues; i++) {
113 status = rte_cryptodev_queue_pair_setup(dev_id, i,
114 &queue_conf, socket_id);
119 if (rte_cryptodev_start(dev_id) < 0)
122 cryptodev = calloc(1, sizeof(struct softnic_cryptodev));
123 if (cryptodev == NULL) {
124 rte_cryptodev_stop(dev_id);
128 strlcpy(cryptodev->name, name, sizeof(cryptodev->name));
129 cryptodev->dev_id = dev_id;
130 cryptodev->n_queues = params->n_queues;
132 snprintf(mp_name, NAME_SIZE, "%s_mp%u", name, dev_id);
133 cryptodev->mp_create = rte_cryptodev_sym_session_pool_create(mp_name,
134 params->session_pool_size,
139 if (!cryptodev->mp_create)
142 snprintf(mp_name, NAME_SIZE, "%s_priv_mp%u", name, dev_id);
143 cryptodev->mp_init = rte_mempool_create(mp_name,
144 params->session_pool_size,
145 rte_cryptodev_sym_get_private_session_size(dev_id),
154 if (!cryptodev->mp_init)
157 TAILQ_INSERT_TAIL(&p->cryptodev_list, cryptodev, node);
162 if (cryptodev->mp_create)
163 rte_mempool_free(cryptodev->mp_create);
164 if (cryptodev->mp_init)
165 rte_mempool_free(cryptodev->mp_init);