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