cryptodev: move IV parameters to session
[dpdk.git] / drivers / crypto / snow3g / rte_snow3g_pmd.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
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.
19  *
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.
31  */
32
33 #include <rte_common.h>
34 #include <rte_config.h>
35 #include <rte_hexdump.h>
36 #include <rte_cryptodev.h>
37 #include <rte_cryptodev_pmd.h>
38 #include <rte_cryptodev_vdev.h>
39 #include <rte_vdev.h>
40 #include <rte_malloc.h>
41 #include <rte_cpuflags.h>
42
43 #include "rte_snow3g_pmd_private.h"
44
45 #define SNOW3G_IV_LENGTH 16
46 #define SNOW3G_DIGEST_LENGTH 4
47 #define SNOW3G_MAX_BURST 8
48 #define BYTE_LEN 8
49
50 /** Get xform chain order. */
51 static enum snow3g_operation
52 snow3g_get_mode(const struct rte_crypto_sym_xform *xform)
53 {
54         if (xform == NULL)
55                 return SNOW3G_OP_NOT_SUPPORTED;
56
57         if (xform->next)
58                 if (xform->next->next != NULL)
59                         return SNOW3G_OP_NOT_SUPPORTED;
60
61         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
62                 if (xform->next == NULL)
63                         return SNOW3G_OP_ONLY_AUTH;
64                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
65                         return SNOW3G_OP_AUTH_CIPHER;
66                 else
67                         return SNOW3G_OP_NOT_SUPPORTED;
68         }
69
70         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
71                 if (xform->next == NULL)
72                         return SNOW3G_OP_ONLY_CIPHER;
73                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
74                         return SNOW3G_OP_CIPHER_AUTH;
75                 else
76                         return SNOW3G_OP_NOT_SUPPORTED;
77         }
78
79         return SNOW3G_OP_NOT_SUPPORTED;
80 }
81
82
83 /** Parse crypto xform chain and set private session parameters. */
84 int
85 snow3g_set_session_parameters(struct snow3g_session *sess,
86                 const struct rte_crypto_sym_xform *xform)
87 {
88         const struct rte_crypto_sym_xform *auth_xform = NULL;
89         const struct rte_crypto_sym_xform *cipher_xform = NULL;
90         enum snow3g_operation mode;
91
92         /* Select Crypto operation - hash then cipher / cipher then hash */
93         mode = snow3g_get_mode(xform);
94
95         switch (mode) {
96         case SNOW3G_OP_CIPHER_AUTH:
97                 auth_xform = xform->next;
98
99                 /* Fall-through */
100         case SNOW3G_OP_ONLY_CIPHER:
101                 cipher_xform = xform;
102                 break;
103         case SNOW3G_OP_AUTH_CIPHER:
104                 cipher_xform = xform->next;
105                 /* Fall-through */
106         case SNOW3G_OP_ONLY_AUTH:
107                 auth_xform = xform;
108                 break;
109         case SNOW3G_OP_NOT_SUPPORTED:
110         default:
111                 SNOW3G_LOG_ERR("Unsupported operation chain order parameter");
112                 return -EINVAL;
113         }
114
115         if (cipher_xform) {
116                 /* Only SNOW 3G UEA2 supported */
117                 if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_SNOW3G_UEA2)
118                         return -EINVAL;
119
120                 if (cipher_xform->cipher.iv.length != SNOW3G_IV_LENGTH) {
121                         SNOW3G_LOG_ERR("Wrong IV length");
122                         return -EINVAL;
123                 }
124                 sess->iv_offset = cipher_xform->cipher.iv.offset;
125
126                 /* Initialize key */
127                 sso_snow3g_init_key_sched(cipher_xform->cipher.key.data,
128                                 &sess->pKeySched_cipher);
129         }
130
131         if (auth_xform) {
132                 /* Only SNOW 3G UIA2 supported */
133                 if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_SNOW3G_UIA2)
134                         return -EINVAL;
135                 sess->auth_op = auth_xform->auth.op;
136                 /* Initialize key */
137                 sso_snow3g_init_key_sched(auth_xform->auth.key.data,
138                                 &sess->pKeySched_hash);
139         }
140
141
142         sess->op = mode;
143
144         return 0;
145 }
146
147 /** Get SNOW 3G session. */
148 static struct snow3g_session *
149 snow3g_get_session(struct snow3g_qp *qp, struct rte_crypto_op *op)
150 {
151         struct snow3g_session *sess;
152
153         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
154                 if (unlikely(op->sym->session->dev_type !=
155                                 RTE_CRYPTODEV_SNOW3G_PMD))
156                         return NULL;
157
158                 sess = (struct snow3g_session *)op->sym->session->_private;
159         } else  {
160                 struct rte_cryptodev_session *c_sess = NULL;
161
162                 if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
163                         return NULL;
164
165                 sess = (struct snow3g_session *)c_sess->_private;
166
167                 if (unlikely(snow3g_set_session_parameters(sess,
168                                 op->sym->xform) != 0))
169                         return NULL;
170         }
171
172         return sess;
173 }
174
175 /** Encrypt/decrypt mbufs with same cipher key. */
176 static uint8_t
177 process_snow3g_cipher_op(struct rte_crypto_op **ops,
178                 struct snow3g_session *session,
179                 uint8_t num_ops)
180 {
181         unsigned i;
182         uint8_t processed_ops = 0;
183         uint8_t *src[SNOW3G_MAX_BURST], *dst[SNOW3G_MAX_BURST];
184         uint8_t *iv[SNOW3G_MAX_BURST];
185         uint32_t num_bytes[SNOW3G_MAX_BURST];
186
187         for (i = 0; i < num_ops; i++) {
188                 src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
189                                 (ops[i]->sym->cipher.data.offset >> 3);
190                 dst[i] = ops[i]->sym->m_dst ?
191                         rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) +
192                                 (ops[i]->sym->cipher.data.offset >> 3) :
193                         rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
194                                 (ops[i]->sym->cipher.data.offset >> 3);
195                 iv[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
196                                 session->iv_offset);
197                 num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
198
199                 processed_ops++;
200         }
201
202         sso_snow3g_f8_n_buffer(&session->pKeySched_cipher, iv, src, dst,
203                         num_bytes, processed_ops);
204
205         return processed_ops;
206 }
207
208 /** Encrypt/decrypt mbuf (bit level function). */
209 static uint8_t
210 process_snow3g_cipher_op_bit(struct rte_crypto_op *op,
211                 struct snow3g_session *session)
212 {
213         uint8_t *src, *dst;
214         uint8_t *iv;
215         uint32_t length_in_bits, offset_in_bits;
216
217         offset_in_bits = op->sym->cipher.data.offset;
218         src = rte_pktmbuf_mtod(op->sym->m_src, uint8_t *);
219         if (op->sym->m_dst == NULL) {
220                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
221                 SNOW3G_LOG_ERR("bit-level in-place not supported\n");
222                 return 0;
223         }
224         dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
225         iv = rte_crypto_op_ctod_offset(op, uint8_t *,
226                                 session->iv_offset);
227         length_in_bits = op->sym->cipher.data.length;
228
229         sso_snow3g_f8_1_buffer_bit(&session->pKeySched_cipher, iv,
230                         src, dst, length_in_bits, offset_in_bits);
231
232         return 1;
233 }
234
235 /** Generate/verify hash from mbufs with same hash key. */
236 static int
237 process_snow3g_hash_op(struct rte_crypto_op **ops,
238                 struct snow3g_session *session,
239                 uint8_t num_ops)
240 {
241         unsigned i;
242         uint8_t processed_ops = 0;
243         uint8_t *src, *dst;
244         uint32_t length_in_bits;
245
246         for (i = 0; i < num_ops; i++) {
247                 if (unlikely(ops[i]->sym->auth.aad.length != SNOW3G_IV_LENGTH)) {
248                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
249                         SNOW3G_LOG_ERR("aad");
250                         break;
251                 }
252
253                 if (unlikely(ops[i]->sym->auth.digest.length != SNOW3G_DIGEST_LENGTH)) {
254                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
255                         SNOW3G_LOG_ERR("digest");
256                         break;
257                 }
258
259                 /* Data must be byte aligned */
260                 if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
261                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
262                         SNOW3G_LOG_ERR("Offset");
263                         break;
264                 }
265
266                 length_in_bits = ops[i]->sym->auth.data.length;
267
268                 src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
269                                 (ops[i]->sym->auth.data.offset >> 3);
270
271                 if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
272                         dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src,
273                                         ops[i]->sym->auth.digest.length);
274
275                         sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
276                                         ops[i]->sym->auth.aad.data, src,
277                                         length_in_bits, dst);
278                         /* Verify digest. */
279                         if (memcmp(dst, ops[i]->sym->auth.digest.data,
280                                         ops[i]->sym->auth.digest.length) != 0)
281                                 ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
282
283                         /* Trim area used for digest from mbuf. */
284                         rte_pktmbuf_trim(ops[i]->sym->m_src,
285                                         ops[i]->sym->auth.digest.length);
286                 } else  {
287                         dst = ops[i]->sym->auth.digest.data;
288
289                         sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
290                                         ops[i]->sym->auth.aad.data, src,
291                                         length_in_bits, dst);
292                 }
293                 processed_ops++;
294         }
295
296         return processed_ops;
297 }
298
299 /** Process a batch of crypto ops which shares the same session. */
300 static int
301 process_ops(struct rte_crypto_op **ops, struct snow3g_session *session,
302                 struct snow3g_qp *qp, uint8_t num_ops,
303                 uint16_t *accumulated_enqueued_ops)
304 {
305         unsigned i;
306         unsigned enqueued_ops, processed_ops;
307
308 #ifdef RTE_LIBRTE_PMD_SNOW3G_DEBUG
309         for (i = 0; i < num_ops; i++) {
310                 if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
311                                 (ops[i]->sym->m_dst != NULL &&
312                                 !rte_pktmbuf_is_contiguous(
313                                                 ops[i]->sym->m_dst))) {
314                         SNOW3G_LOG_ERR("PMD supports only contiguous mbufs, "
315                                 "op (%p) provides noncontiguous mbuf as "
316                                 "source/destination buffer.\n", ops[i]);
317                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
318                         return 0;
319                 }
320         }
321 #endif
322
323         switch (session->op) {
324         case SNOW3G_OP_ONLY_CIPHER:
325                 processed_ops = process_snow3g_cipher_op(ops,
326                                 session, num_ops);
327                 break;
328         case SNOW3G_OP_ONLY_AUTH:
329                 processed_ops = process_snow3g_hash_op(ops, session,
330                                 num_ops);
331                 break;
332         case SNOW3G_OP_CIPHER_AUTH:
333                 processed_ops = process_snow3g_cipher_op(ops, session,
334                                 num_ops);
335                 process_snow3g_hash_op(ops, session, processed_ops);
336                 break;
337         case SNOW3G_OP_AUTH_CIPHER:
338                 processed_ops = process_snow3g_hash_op(ops, session,
339                                 num_ops);
340                 process_snow3g_cipher_op(ops, session, processed_ops);
341                 break;
342         default:
343                 /* Operation not supported. */
344                 processed_ops = 0;
345         }
346
347         for (i = 0; i < num_ops; i++) {
348                 /*
349                  * If there was no error/authentication failure,
350                  * change status to successful.
351                  */
352                 if (ops[i]->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
353                         ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
354                 /* Free session if a session-less crypto op. */
355                 if (ops[i]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
356                         rte_mempool_put(qp->sess_mp, ops[i]->sym->session);
357                         ops[i]->sym->session = NULL;
358                 }
359         }
360
361         enqueued_ops = rte_ring_enqueue_burst(qp->processed_ops,
362                         (void **)ops, processed_ops, NULL);
363         qp->qp_stats.enqueued_count += enqueued_ops;
364         *accumulated_enqueued_ops += enqueued_ops;
365
366         return enqueued_ops;
367 }
368
369 /** Process a crypto op with length/offset in bits. */
370 static int
371 process_op_bit(struct rte_crypto_op *op, struct snow3g_session *session,
372                 struct snow3g_qp *qp, uint16_t *accumulated_enqueued_ops)
373 {
374         unsigned enqueued_op, processed_op;
375
376         switch (session->op) {
377         case SNOW3G_OP_ONLY_CIPHER:
378                 processed_op = process_snow3g_cipher_op_bit(op,
379                                 session);
380                 break;
381         case SNOW3G_OP_ONLY_AUTH:
382                 processed_op = process_snow3g_hash_op(&op, session, 1);
383                 break;
384         case SNOW3G_OP_CIPHER_AUTH:
385                 processed_op = process_snow3g_cipher_op_bit(op, session);
386                 if (processed_op == 1)
387                         process_snow3g_hash_op(&op, session, 1);
388                 break;
389         case SNOW3G_OP_AUTH_CIPHER:
390                 processed_op = process_snow3g_hash_op(&op, session, 1);
391                 if (processed_op == 1)
392                         process_snow3g_cipher_op_bit(op, session);
393                 break;
394         default:
395                 /* Operation not supported. */
396                 processed_op = 0;
397         }
398
399         /*
400          * If there was no error/authentication failure,
401          * change status to successful.
402          */
403         if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
404                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
405
406         /* Free session if a session-less crypto op. */
407         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
408                 rte_mempool_put(qp->sess_mp, op->sym->session);
409                 op->sym->session = NULL;
410         }
411
412         enqueued_op = rte_ring_enqueue_burst(qp->processed_ops,
413                         (void **)&op, processed_op, NULL);
414         qp->qp_stats.enqueued_count += enqueued_op;
415         *accumulated_enqueued_ops += enqueued_op;
416
417         return enqueued_op;
418 }
419
420 static uint16_t
421 snow3g_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
422                 uint16_t nb_ops)
423 {
424         struct rte_crypto_op *c_ops[SNOW3G_MAX_BURST];
425         struct rte_crypto_op *curr_c_op;
426
427         struct snow3g_session *prev_sess = NULL, *curr_sess = NULL;
428         struct snow3g_qp *qp = queue_pair;
429         unsigned i;
430         uint8_t burst_size = 0;
431         uint16_t enqueued_ops = 0;
432         uint8_t processed_ops;
433
434         for (i = 0; i < nb_ops; i++) {
435                 curr_c_op = ops[i];
436
437                 /* Set status as enqueued (not processed yet) by default. */
438                 curr_c_op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
439
440                 curr_sess = snow3g_get_session(qp, curr_c_op);
441                 if (unlikely(curr_sess == NULL ||
442                                 curr_sess->op == SNOW3G_OP_NOT_SUPPORTED)) {
443                         curr_c_op->status =
444                                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
445                         break;
446                 }
447
448                 /* If length/offset is at bit-level, process this buffer alone. */
449                 if (((curr_c_op->sym->cipher.data.length % BYTE_LEN) != 0)
450                                 || ((curr_c_op->sym->cipher.data.offset
451                                         % BYTE_LEN) != 0)) {
452                         /* Process the ops of the previous session. */
453                         if (prev_sess != NULL) {
454                                 processed_ops = process_ops(c_ops, prev_sess,
455                                 qp, burst_size, &enqueued_ops);
456                                 if (processed_ops < burst_size) {
457                                         burst_size = 0;
458                                         break;
459                                 }
460
461                                 burst_size = 0;
462                                 prev_sess = NULL;
463                         }
464
465                         processed_ops = process_op_bit(curr_c_op, curr_sess,
466                                                         qp, &enqueued_ops);
467                         if (processed_ops != 1)
468                                 break;
469
470                         continue;
471                 }
472
473                 /* Batch ops that share the same session. */
474                 if (prev_sess == NULL) {
475                         prev_sess = curr_sess;
476                         c_ops[burst_size++] = curr_c_op;
477                 } else if (curr_sess == prev_sess) {
478                         c_ops[burst_size++] = curr_c_op;
479                         /*
480                          * When there are enough ops to process in a batch,
481                          * process them, and start a new batch.
482                          */
483                         if (burst_size == SNOW3G_MAX_BURST) {
484                                 processed_ops = process_ops(c_ops, prev_sess,
485                                                 qp, burst_size, &enqueued_ops);
486                                 if (processed_ops < burst_size) {
487                                         burst_size = 0;
488                                         break;
489                                 }
490
491                                 burst_size = 0;
492                                 prev_sess = NULL;
493                         }
494                 } else {
495                         /*
496                          * Different session, process the ops
497                          * of the previous session.
498                          */
499                         processed_ops = process_ops(c_ops, prev_sess,
500                                         qp, burst_size, &enqueued_ops);
501                         if (processed_ops < burst_size) {
502                                 burst_size = 0;
503                                 break;
504                         }
505
506                         burst_size = 0;
507                         prev_sess = curr_sess;
508
509                         c_ops[burst_size++] = curr_c_op;
510                 }
511         }
512
513         if (burst_size != 0) {
514                 /* Process the crypto ops of the last session. */
515                 processed_ops = process_ops(c_ops, prev_sess,
516                                 qp, burst_size, &enqueued_ops);
517         }
518
519         qp->qp_stats.enqueue_err_count += nb_ops - enqueued_ops;
520         return enqueued_ops;
521 }
522
523 static uint16_t
524 snow3g_pmd_dequeue_burst(void *queue_pair,
525                 struct rte_crypto_op **c_ops, uint16_t nb_ops)
526 {
527         struct snow3g_qp *qp = queue_pair;
528
529         unsigned nb_dequeued;
530
531         nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
532                         (void **)c_ops, nb_ops, NULL);
533         qp->qp_stats.dequeued_count += nb_dequeued;
534
535         return nb_dequeued;
536 }
537
538 static int cryptodev_snow3g_remove(struct rte_vdev_device *vdev);
539
540 static int
541 cryptodev_snow3g_create(const char *name,
542                         struct rte_vdev_device *vdev,
543                         struct rte_crypto_vdev_init_params *init_params)
544 {
545         struct rte_cryptodev *dev;
546         struct snow3g_private *internals;
547         uint64_t cpu_flags = RTE_CRYPTODEV_FF_CPU_SSE;
548
549         if (init_params->name[0] == '\0')
550                 snprintf(init_params->name, sizeof(init_params->name),
551                                 "%s", name);
552
553         dev = rte_cryptodev_vdev_pmd_init(init_params->name,
554                         sizeof(struct snow3g_private), init_params->socket_id,
555                         vdev);
556         if (dev == NULL) {
557                 SNOW3G_LOG_ERR("failed to create cryptodev vdev");
558                 goto init_error;
559         }
560
561         dev->dev_type = RTE_CRYPTODEV_SNOW3G_PMD;
562         dev->dev_ops = rte_snow3g_pmd_ops;
563
564         /* Register RX/TX burst functions for data path. */
565         dev->dequeue_burst = snow3g_pmd_dequeue_burst;
566         dev->enqueue_burst = snow3g_pmd_enqueue_burst;
567
568         dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
569                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
570                         cpu_flags;
571
572         internals = dev->data->dev_private;
573
574         internals->max_nb_queue_pairs = init_params->max_nb_queue_pairs;
575         internals->max_nb_sessions = init_params->max_nb_sessions;
576
577         return 0;
578 init_error:
579         SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed",
580                         init_params->name);
581
582         cryptodev_snow3g_remove(vdev);
583         return -EFAULT;
584 }
585
586 static int
587 cryptodev_snow3g_probe(struct rte_vdev_device *vdev)
588 {
589         struct rte_crypto_vdev_init_params init_params = {
590                 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
591                 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
592                 rte_socket_id(),
593                 {0}
594         };
595         const char *name;
596         const char *input_args;
597
598         name = rte_vdev_device_name(vdev);
599         if (name == NULL)
600                 return -EINVAL;
601         input_args = rte_vdev_device_args(vdev);
602
603         rte_cryptodev_vdev_parse_init_params(&init_params, input_args);
604
605         RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
606                         init_params.socket_id);
607         if (init_params.name[0] != '\0')
608                 RTE_LOG(INFO, PMD, "  User defined name = %s\n",
609                         init_params.name);
610         RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
611                         init_params.max_nb_queue_pairs);
612         RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
613                         init_params.max_nb_sessions);
614
615         return cryptodev_snow3g_create(name, vdev, &init_params);
616 }
617
618 static int
619 cryptodev_snow3g_remove(struct rte_vdev_device *vdev)
620 {
621         const char *name;
622
623         name = rte_vdev_device_name(vdev);
624         if (name == NULL)
625                 return -EINVAL;
626
627         RTE_LOG(INFO, PMD, "Closing SNOW 3G crypto device %s"
628                         " on numa socket %u\n",
629                         name, rte_socket_id());
630
631         return 0;
632 }
633
634 static struct rte_vdev_driver cryptodev_snow3g_pmd_drv = {
635         .probe = cryptodev_snow3g_probe,
636         .remove = cryptodev_snow3g_remove
637 };
638
639 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd_drv);
640 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd);
641 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
642         "max_nb_queue_pairs=<int> "
643         "max_nb_sessions=<int> "
644         "socket_id=<int>");