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 "rte_snow3g_pmd_private.h"
41 /** Configure device */
43 snow3g_pmd_config(__rte_unused struct rte_cryptodev *dev)
50 snow3g_pmd_start(__rte_unused struct rte_cryptodev *dev)
57 snow3g_pmd_stop(__rte_unused struct rte_cryptodev *dev)
63 snow3g_pmd_close(__rte_unused struct rte_cryptodev *dev)
69 /** Get device statistics */
71 snow3g_pmd_stats_get(struct rte_cryptodev *dev,
72 struct rte_cryptodev_stats *stats)
76 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
77 struct snow3g_qp *qp = dev->data->queue_pairs[qp_id];
79 stats->enqueued_count += qp->qp_stats.enqueued_count;
80 stats->dequeued_count += qp->qp_stats.dequeued_count;
82 stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
83 stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
87 /** Reset device statistics */
89 snow3g_pmd_stats_reset(struct rte_cryptodev *dev)
93 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
94 struct snow3g_qp *qp = dev->data->queue_pairs[qp_id];
96 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
101 /** Get device info */
103 snow3g_pmd_info_get(struct rte_cryptodev *dev,
104 struct rte_cryptodev_info *dev_info)
106 struct snow3g_private *internals = dev->data->dev_private;
108 if (dev_info != NULL) {
109 dev_info->dev_type = dev->dev_type;
110 dev_info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
111 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
115 /** Release queue pair */
117 snow3g_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
119 if (dev->data->queue_pairs[qp_id] != NULL) {
120 rte_free(dev->data->queue_pairs[qp_id]);
121 dev->data->queue_pairs[qp_id] = NULL;
126 /** set a unique name for the queue pair based on its name, dev_id and qp_id */
128 snow3g_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
129 struct snow3g_qp *qp)
131 unsigned n = snprintf(qp->name, sizeof(qp->name),
132 "snow3g_pmd_%u_qp_%u",
133 dev->data->dev_id, qp->id);
135 if (n > sizeof(qp->name))
141 /** Create a ring to place processed ops on */
142 static struct rte_ring *
143 snow3g_pmd_qp_create_processed_ops_ring(struct snow3g_qp *qp,
144 unsigned ring_size, int socket_id)
148 r = rte_ring_lookup(qp->name);
150 if (r->prod.size >= ring_size) {
151 SNOW3G_LOG_INFO("Reusing existing ring %s"
152 " for processed packets",
157 SNOW3G_LOG_ERR("Unable to reuse existing ring %s"
158 " for processed packets",
163 return rte_ring_create(qp->name, ring_size, socket_id,
164 RING_F_SP_ENQ | RING_F_SC_DEQ);
167 /** Setup a queue pair */
169 snow3g_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
170 const struct rte_cryptodev_qp_conf *qp_conf,
173 struct snow3g_qp *qp = NULL;
175 /* Free memory prior to re-allocation if needed. */
176 if (dev->data->queue_pairs[qp_id] != NULL)
177 snow3g_pmd_qp_release(dev, qp_id);
179 /* Allocate the queue pair data structure. */
180 qp = rte_zmalloc_socket("SNOW3G PMD Queue Pair", sizeof(*qp),
181 RTE_CACHE_LINE_SIZE, socket_id);
186 dev->data->queue_pairs[qp_id] = qp;
188 if (snow3g_pmd_qp_set_unique_name(dev, qp))
189 goto qp_setup_cleanup;
191 qp->processed_ops = snow3g_pmd_qp_create_processed_ops_ring(qp,
192 qp_conf->nb_descriptors, socket_id);
193 if (qp->processed_ops == NULL)
194 goto qp_setup_cleanup;
196 qp->sess_mp = dev->data->session_pool;
198 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
209 /** Start queue pair */
211 snow3g_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
212 __rte_unused uint16_t queue_pair_id)
217 /** Stop queue pair */
219 snow3g_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
220 __rte_unused uint16_t queue_pair_id)
225 /** Return the number of allocated queue pairs */
227 snow3g_pmd_qp_count(struct rte_cryptodev *dev)
229 return dev->data->nb_queue_pairs;
232 /** Returns the size of the SNOW 3G session structure */
234 snow3g_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
236 return sizeof(struct snow3g_session);
239 /** Configure a SNOW 3G session from a crypto xform chain */
241 snow3g_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
242 struct rte_crypto_sym_xform *xform, void *sess)
244 if (unlikely(sess == NULL)) {
245 SNOW3G_LOG_ERR("invalid session struct");
249 if (snow3g_set_session_parameters(sess, xform) != 0) {
250 SNOW3G_LOG_ERR("failed configure session parameters");
257 /** Clear the memory of session so it doesn't leave key material behind */
259 snow3g_pmd_session_clear(struct rte_cryptodev *dev __rte_unused, void *sess)
262 * Current just resetting the whole data structure, need to investigate
263 * whether a more selective reset of key would be more performant
266 memset(sess, 0, sizeof(struct snow3g_session));
269 struct rte_cryptodev_ops snow3g_pmd_ops = {
270 .dev_configure = snow3g_pmd_config,
271 .dev_start = snow3g_pmd_start,
272 .dev_stop = snow3g_pmd_stop,
273 .dev_close = snow3g_pmd_close,
275 .stats_get = snow3g_pmd_stats_get,
276 .stats_reset = snow3g_pmd_stats_reset,
278 .dev_infos_get = snow3g_pmd_info_get,
280 .queue_pair_setup = snow3g_pmd_qp_setup,
281 .queue_pair_release = snow3g_pmd_qp_release,
282 .queue_pair_start = snow3g_pmd_qp_start,
283 .queue_pair_stop = snow3g_pmd_qp_stop,
284 .queue_pair_count = snow3g_pmd_qp_count,
286 .session_get_size = snow3g_pmd_session_get_size,
287 .session_configure = snow3g_pmd_session_configure,
288 .session_clear = snow3g_pmd_session_clear
291 struct rte_cryptodev_ops *rte_snow3g_pmd_ops = &snow3g_pmd_ops;