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