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