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