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 static struct cryptodev_list cryptodev_list;
19 TAILQ_INIT(&cryptodev_list);
25 cryptodev_find(const char *name)
27 struct cryptodev *cryptodev;
32 TAILQ_FOREACH(cryptodev, &cryptodev_list, node)
33 if (strcmp(cryptodev->name, name) == 0)
40 cryptodev_next(struct cryptodev *cryptodev)
42 return (cryptodev == NULL) ?
43 TAILQ_FIRST(&cryptodev_list) :
44 TAILQ_NEXT(cryptodev, node);
48 cryptodev_create(const char *name, struct cryptodev_params *params)
50 struct rte_cryptodev_info dev_info;
51 struct rte_cryptodev_config dev_conf;
52 struct rte_cryptodev_qp_conf queue_conf;
53 struct cryptodev *cryptodev;
58 /* Check input params */
60 cryptodev_find(name) ||
61 (params->n_queues == 0) ||
62 (params->queue_size == 0))
65 if (params->dev_name) {
66 status = rte_cryptodev_get_dev_id(params->dev_name);
70 dev_id = (uint32_t)status;
72 if (rte_cryptodev_pmd_is_valid_dev(params->dev_id) == 0)
75 dev_id = params->dev_id;
78 socket_id = rte_cryptodev_socket_id(dev_id);
79 rte_cryptodev_info_get(dev_id, &dev_info);
81 if (dev_info.max_nb_queue_pairs < params->n_queues)
83 if (dev_info.feature_flags & RTE_CRYPTODEV_FF_HW_ACCELERATED)
86 dev_conf.socket_id = socket_id;
87 dev_conf.nb_queue_pairs = params->n_queues;
89 status = rte_cryptodev_configure(dev_id, &dev_conf);
93 queue_conf.nb_descriptors = params->queue_size;
94 for (i = 0; i < params->n_queues; i++) {
95 status = rte_cryptodev_queue_pair_setup(dev_id, i,
96 &queue_conf, socket_id, NULL);
101 if (rte_cryptodev_start(dev_id) < 0)
104 cryptodev = calloc(1, sizeof(struct cryptodev));
105 if (cryptodev == NULL) {
106 rte_cryptodev_stop(dev_id);
110 strlcpy(cryptodev->name, name, sizeof(cryptodev->name));
111 cryptodev->dev_id = dev_id;
112 cryptodev->n_queues = params->n_queues;
114 TAILQ_INSERT_TAIL(&cryptodev_list, cryptodev, node);