4 * Copyright (C) Cavium, Inc. 2017.
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 Cavium, Inc 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 "armv8_crypto_defs.h"
41 #include "rte_armv8_pmd_private.h"
43 static const struct rte_cryptodev_capabilities
44 armv8_crypto_pmd_capabilities[] = {
46 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
48 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
50 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
68 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
70 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
72 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
90 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
92 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
94 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
110 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
114 /** Configure device */
116 armv8_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev,
117 __rte_unused struct rte_cryptodev_config *config)
124 armv8_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
131 armv8_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
137 armv8_crypto_pmd_close(__rte_unused struct rte_cryptodev *dev)
143 /** Get device statistics */
145 armv8_crypto_pmd_stats_get(struct rte_cryptodev *dev,
146 struct rte_cryptodev_stats *stats)
150 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
151 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
153 stats->enqueued_count += qp->stats.enqueued_count;
154 stats->dequeued_count += qp->stats.dequeued_count;
156 stats->enqueue_err_count += qp->stats.enqueue_err_count;
157 stats->dequeue_err_count += qp->stats.dequeue_err_count;
161 /** Reset device statistics */
163 armv8_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
167 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
168 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
170 memset(&qp->stats, 0, sizeof(qp->stats));
175 /** Get device info */
177 armv8_crypto_pmd_info_get(struct rte_cryptodev *dev,
178 struct rte_cryptodev_info *dev_info)
180 struct armv8_crypto_private *internals = dev->data->dev_private;
182 if (dev_info != NULL) {
183 dev_info->driver_id = dev->driver_id;
184 dev_info->feature_flags = dev->feature_flags;
185 dev_info->capabilities = armv8_crypto_pmd_capabilities;
186 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
187 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
191 /** Release queue pair */
193 armv8_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
196 if (dev->data->queue_pairs[qp_id] != NULL) {
197 rte_free(dev->data->queue_pairs[qp_id]);
198 dev->data->queue_pairs[qp_id] = NULL;
204 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
206 armv8_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
207 struct armv8_crypto_qp *qp)
211 n = snprintf(qp->name, sizeof(qp->name), "armv8_crypto_pmd_%u_qp_%u",
212 dev->data->dev_id, qp->id);
214 if (n > sizeof(qp->name))
221 /** Create a ring to place processed operations on */
222 static struct rte_ring *
223 armv8_crypto_pmd_qp_create_processed_ops_ring(struct armv8_crypto_qp *qp,
224 unsigned int ring_size, int socket_id)
228 r = rte_ring_lookup(qp->name);
230 if (rte_ring_get_size(r) >= ring_size) {
231 ARMV8_CRYPTO_LOG_INFO(
232 "Reusing existing ring %s for processed ops",
237 ARMV8_CRYPTO_LOG_ERR(
238 "Unable to reuse existing ring %s for processed ops",
243 return rte_ring_create(qp->name, ring_size, socket_id,
244 RING_F_SP_ENQ | RING_F_SC_DEQ);
248 /** Setup a queue pair */
250 armv8_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
251 const struct rte_cryptodev_qp_conf *qp_conf,
252 int socket_id, struct rte_mempool *session_pool)
254 struct armv8_crypto_qp *qp = NULL;
256 /* Free memory prior to re-allocation if needed. */
257 if (dev->data->queue_pairs[qp_id] != NULL)
258 armv8_crypto_pmd_qp_release(dev, qp_id);
260 /* Allocate the queue pair data structure. */
261 qp = rte_zmalloc_socket("ARMv8 PMD Queue Pair", sizeof(*qp),
262 RTE_CACHE_LINE_SIZE, socket_id);
267 dev->data->queue_pairs[qp_id] = qp;
269 if (armv8_crypto_pmd_qp_set_unique_name(dev, qp) != 0)
270 goto qp_setup_cleanup;
272 qp->processed_ops = armv8_crypto_pmd_qp_create_processed_ops_ring(qp,
273 qp_conf->nb_descriptors, socket_id);
274 if (qp->processed_ops == NULL)
275 goto qp_setup_cleanup;
277 qp->sess_mp = session_pool;
279 memset(&qp->stats, 0, sizeof(qp->stats));
290 /** Start queue pair */
292 armv8_crypto_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
293 __rte_unused uint16_t queue_pair_id)
298 /** Stop queue pair */
300 armv8_crypto_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
301 __rte_unused uint16_t queue_pair_id)
306 /** Return the number of allocated queue pairs */
308 armv8_crypto_pmd_qp_count(struct rte_cryptodev *dev)
310 return dev->data->nb_queue_pairs;
313 /** Returns the size of the session structure */
315 armv8_crypto_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
317 return sizeof(struct armv8_crypto_session);
320 /** Configure the session from a crypto xform chain */
322 armv8_crypto_pmd_session_configure(struct rte_cryptodev *dev,
323 struct rte_crypto_sym_xform *xform,
324 struct rte_cryptodev_sym_session *sess,
325 struct rte_mempool *mempool)
327 void *sess_private_data;
329 if (unlikely(sess == NULL)) {
330 ARMV8_CRYPTO_LOG_ERR("invalid session struct");
334 if (rte_mempool_get(mempool, &sess_private_data)) {
336 "Couldn't get object from session mempool");
340 if (armv8_crypto_set_session_parameters(sess_private_data, xform) != 0) {
341 ARMV8_CRYPTO_LOG_ERR("failed configure session parameters");
343 /* Return session to mempool */
344 rte_mempool_put(mempool, sess_private_data);
348 set_session_private_data(sess, dev->driver_id,
354 /** Clear the memory of session so it doesn't leave key material behind */
356 armv8_crypto_pmd_session_clear(struct rte_cryptodev *dev,
357 struct rte_cryptodev_sym_session *sess)
359 uint8_t index = dev->driver_id;
360 void *sess_priv = get_session_private_data(sess, index);
362 /* Zero out the whole structure */
364 memset(sess_priv, 0, sizeof(struct armv8_crypto_session));
365 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
366 set_session_private_data(sess, index, NULL);
367 rte_mempool_put(sess_mp, sess_priv);
371 struct rte_cryptodev_ops armv8_crypto_pmd_ops = {
372 .dev_configure = armv8_crypto_pmd_config,
373 .dev_start = armv8_crypto_pmd_start,
374 .dev_stop = armv8_crypto_pmd_stop,
375 .dev_close = armv8_crypto_pmd_close,
377 .stats_get = armv8_crypto_pmd_stats_get,
378 .stats_reset = armv8_crypto_pmd_stats_reset,
380 .dev_infos_get = armv8_crypto_pmd_info_get,
382 .queue_pair_setup = armv8_crypto_pmd_qp_setup,
383 .queue_pair_release = armv8_crypto_pmd_qp_release,
384 .queue_pair_start = armv8_crypto_pmd_qp_start,
385 .queue_pair_stop = armv8_crypto_pmd_qp_stop,
386 .queue_pair_count = armv8_crypto_pmd_qp_count,
388 .session_get_size = armv8_crypto_pmd_session_get_size,
389 .session_configure = armv8_crypto_pmd_session_configure,
390 .session_clear = armv8_crypto_pmd_session_clear
393 struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops = &armv8_crypto_pmd_ops;