4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_common.h>
36 #include <rte_malloc.h>
37 #include <rte_cryptodev_pmd.h>
39 #include "null_crypto_pmd_private.h"
41 /** Configure device */
43 null_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev)
50 null_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
57 null_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
63 null_crypto_pmd_close(__rte_unused struct rte_cryptodev *dev)
68 /** Get device statistics */
70 null_crypto_pmd_stats_get(struct rte_cryptodev *dev,
71 struct rte_cryptodev_stats *stats)
75 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
76 struct null_crypto_qp *qp = dev->data->queue_pairs[qp_id];
78 stats->enqueued_count += qp->qp_stats.enqueued_count;
79 stats->dequeued_count += qp->qp_stats.dequeued_count;
81 stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
82 stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
86 /** Reset device statistics */
88 null_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
92 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
93 struct null_crypto_qp *qp = dev->data->queue_pairs[qp_id];
95 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
100 /** Get device info */
102 null_crypto_pmd_info_get(struct rte_cryptodev *dev,
103 struct rte_cryptodev_info *dev_info)
105 struct null_crypto_private *internals = dev->data->dev_private;
107 if (dev_info != NULL) {
108 dev_info->dev_type = dev->dev_type;
109 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
110 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
114 /** Release queue pair */
116 null_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
118 if (dev->data->queue_pairs[qp_id] != NULL) {
119 rte_free(dev->data->queue_pairs[qp_id]);
120 dev->data->queue_pairs[qp_id] = NULL;
125 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
127 null_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
128 struct null_crypto_qp *qp)
130 unsigned n = snprintf(qp->name, sizeof(qp->name),
131 "null_crypto_pmd_%u_qp_%u",
132 dev->data->dev_id, qp->id);
134 if (n > sizeof(qp->name))
140 /** Create a ring to place process packets on */
141 static struct rte_ring *
142 null_crypto_pmd_qp_create_processed_pkts_ring(struct null_crypto_qp *qp,
143 unsigned ring_size, int socket_id)
147 r = rte_ring_lookup(qp->name);
149 if (r->prod.size >= ring_size) {
150 NULL_CRYPTO_LOG_INFO(
151 "Reusing existing ring %s for processed packets",
156 NULL_CRYPTO_LOG_INFO(
157 "Unable to reuse existing ring %s for processed packets",
162 return rte_ring_create(qp->name, ring_size, socket_id,
163 RING_F_SP_ENQ | RING_F_SC_DEQ);
166 /** Setup a queue pair */
168 null_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
169 const struct rte_cryptodev_qp_conf *qp_conf,
172 struct null_crypto_private *internals = dev->data->dev_private;
173 struct null_crypto_qp *qp;
176 if (qp_id >= internals->max_nb_qpairs) {
177 NULL_CRYPTO_LOG_ERR("Invalid qp_id %u, greater than maximum "
178 "number of queue pairs supported (%u).",
179 qp_id, internals->max_nb_qpairs);
183 /* Free memory prior to re-allocation if needed. */
184 if (dev->data->queue_pairs[qp_id] != NULL)
185 null_crypto_pmd_qp_release(dev, qp_id);
187 /* Allocate the queue pair data structure. */
188 qp = rte_zmalloc_socket("Null Crypto PMD Queue Pair", sizeof(*qp),
189 RTE_CACHE_LINE_SIZE, socket_id);
191 NULL_CRYPTO_LOG_ERR("Failed to allocate queue pair memory");
196 dev->data->queue_pairs[qp_id] = qp;
198 retval = null_crypto_pmd_qp_set_unique_name(dev, qp);
200 NULL_CRYPTO_LOG_ERR("Failed to create unique name for null "
202 goto qp_setup_cleanup;
205 qp->processed_pkts = null_crypto_pmd_qp_create_processed_pkts_ring(qp,
206 qp_conf->nb_descriptors, socket_id);
207 if (qp->processed_pkts == NULL) {
208 NULL_CRYPTO_LOG_ERR("Failed to create unique name for null "
210 goto qp_setup_cleanup;
213 qp->sess_mp = dev->data->session_pool;
215 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
226 /** Start queue pair */
228 null_crypto_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
229 __rte_unused uint16_t queue_pair_id)
234 /** Stop queue pair */
236 null_crypto_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
237 __rte_unused uint16_t queue_pair_id)
242 /** Return the number of allocated queue pairs */
244 null_crypto_pmd_qp_count(struct rte_cryptodev *dev)
246 return dev->data->nb_queue_pairs;
249 /** Returns the size of the NULL crypto session structure */
251 null_crypto_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
253 return sizeof(struct null_crypto_session);
256 /** Configure a null crypto session from a crypto xform chain */
258 null_crypto_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
259 struct rte_crypto_sym_xform *xform, void *sess)
263 if (unlikely(sess == NULL)) {
264 NULL_CRYPTO_LOG_ERR("invalid session struct");
267 retval = null_crypto_set_session_parameters(
268 (struct null_crypto_session *)sess, xform);
270 NULL_CRYPTO_LOG_ERR("failed configure session parameters");
277 /** Clear the memory of session so it doesn't leave key material behind */
279 null_crypto_pmd_session_clear(struct rte_cryptodev *dev __rte_unused,
283 memset(sess, 0, sizeof(struct null_crypto_session));
286 struct rte_cryptodev_ops pmd_ops = {
287 .dev_configure = null_crypto_pmd_config,
288 .dev_start = null_crypto_pmd_start,
289 .dev_stop = null_crypto_pmd_stop,
290 .dev_close = null_crypto_pmd_close,
292 .stats_get = null_crypto_pmd_stats_get,
293 .stats_reset = null_crypto_pmd_stats_reset,
295 .dev_infos_get = null_crypto_pmd_info_get,
297 .queue_pair_setup = null_crypto_pmd_qp_setup,
298 .queue_pair_release = null_crypto_pmd_qp_release,
299 .queue_pair_start = null_crypto_pmd_qp_start,
300 .queue_pair_stop = null_crypto_pmd_qp_stop,
301 .queue_pair_count = null_crypto_pmd_qp_count,
303 .session_get_size = null_crypto_pmd_session_get_size,
304 .session_configure = null_crypto_pmd_session_configure,
305 .session_clear = null_crypto_pmd_session_clear
308 struct rte_cryptodev_ops *null_crypto_pmd_ops = &pmd_ops;