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