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 "rte_eth_softnic_internals.h"
15 softnic_cryptodev_init(struct pmd_internals *p)
17 TAILQ_INIT(&p->cryptodev_list);
23 softnic_cryptodev_free(struct pmd_internals *p)
26 struct softnic_cryptodev *cryptodev;
28 cryptodev = TAILQ_FIRST(&p->cryptodev_list);
29 if (cryptodev == NULL)
32 TAILQ_REMOVE(&p->cryptodev_list, cryptodev, node);
37 struct softnic_cryptodev *
38 softnic_cryptodev_find(struct pmd_internals *p,
41 struct softnic_cryptodev *cryptodev;
46 TAILQ_FOREACH(cryptodev, &p->cryptodev_list, node)
47 if (strcmp(cryptodev->name, name) == 0)
53 struct softnic_cryptodev *
54 softnic_cryptodev_create(struct pmd_internals *p,
56 struct softnic_cryptodev_params *params)
58 struct rte_cryptodev_info dev_info;
59 struct rte_cryptodev_config dev_conf;
60 struct rte_cryptodev_qp_conf queue_conf;
61 struct softnic_cryptodev *cryptodev;
66 /* Check input params */
68 softnic_cryptodev_find(p, name) ||
69 (params->n_queues == 0) ||
70 (params->queue_size == 0))
73 if (params->dev_name) {
74 status = rte_cryptodev_get_dev_id(params->dev_name);
78 dev_id = (uint32_t)status;
80 if (rte_cryptodev_pmd_is_valid_dev(params->dev_id) == 0)
83 dev_id = params->dev_id;
86 socket_id = rte_cryptodev_socket_id(dev_id);
87 rte_cryptodev_info_get(dev_id, &dev_info);
89 if (dev_info.max_nb_queue_pairs < params->n_queues)
91 if (dev_info.feature_flags & RTE_CRYPTODEV_FF_HW_ACCELERATED)
94 dev_conf.socket_id = socket_id;
95 dev_conf.nb_queue_pairs = params->n_queues;
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, NULL);
109 if (rte_cryptodev_start(dev_id) < 0)
112 cryptodev = calloc(1, sizeof(struct softnic_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 TAILQ_INSERT_TAIL(&p->cryptodev_list, cryptodev, node);