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