cryptodev: move IV parameters to session
[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_cryptodev_vdev.h>
39 #include <rte_vdev.h>
40 #include <rte_malloc.h>
41 #include <rte_cpuflags.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 /** 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 -EINVAL;
113         }
114
115         if (cipher_xform) {
116                 /* Only KASUMI F8 supported */
117                 if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_KASUMI_F8)
118                         return -EINVAL;
119
120                 sess->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 -EINVAL;
135                 sess->auth_op = auth_xform->auth.op;
136                 /* Initialize key */
137                 sso_kasumi_init_f9_key_sched(auth_xform->auth.key.data,
138                                 &sess->pKeySched_hash);
139         }
140
141
142         sess->op = mode;
143
144         return 0;
145 }
146
147 /** Get KASUMI session. */
148 static struct kasumi_session *
149 kasumi_get_session(struct kasumi_qp *qp, struct rte_crypto_op *op)
150 {
151         struct kasumi_session *sess;
152
153         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
154                 if (unlikely(op->sym->session->dev_type !=
155                                 RTE_CRYPTODEV_KASUMI_PMD))
156                         return NULL;
157
158                 sess = (struct kasumi_session *)op->sym->session->_private;
159         } else  {
160                 struct rte_cryptodev_session *c_sess = NULL;
161
162                 if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
163                         return NULL;
164
165                 sess = (struct kasumi_session *)c_sess->_private;
166
167                 if (unlikely(kasumi_set_session_parameters(sess,
168                                 op->sym->xform) != 0))
169                         return NULL;
170         }
171
172         return sess;
173 }
174
175 /** Encrypt/decrypt mbufs with same cipher key. */
176 static uint8_t
177 process_kasumi_cipher_op(struct rte_crypto_op **ops,
178                 struct kasumi_session *session,
179                 uint8_t num_ops)
180 {
181         unsigned i;
182         uint8_t processed_ops = 0;
183         uint8_t *src[num_ops], *dst[num_ops];
184         uint8_t *iv_ptr;
185         uint64_t iv[num_ops];
186         uint32_t num_bytes[num_ops];
187
188         for (i = 0; i < num_ops; i++) {
189                 src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
190                                 (ops[i]->sym->cipher.data.offset >> 3);
191                 dst[i] = ops[i]->sym->m_dst ?
192                         rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) +
193                                 (ops[i]->sym->cipher.data.offset >> 3) :
194                         rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
195                                 (ops[i]->sym->cipher.data.offset >> 3);
196                 iv_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
197                                 session->iv_offset);
198                 iv[i] = *((uint64_t *)(iv_ptr));
199                 num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
200
201                 processed_ops++;
202         }
203
204         if (processed_ops != 0)
205                 sso_kasumi_f8_n_buffer(&session->pKeySched_cipher, iv,
206                         src, dst, num_bytes, processed_ops);
207
208         return processed_ops;
209 }
210
211 /** Encrypt/decrypt mbuf (bit level function). */
212 static uint8_t
213 process_kasumi_cipher_op_bit(struct rte_crypto_op *op,
214                 struct kasumi_session *session)
215 {
216         uint8_t *src, *dst;
217         uint8_t *iv_ptr;
218         uint64_t iv;
219         uint32_t length_in_bits, offset_in_bits;
220
221         offset_in_bits = op->sym->cipher.data.offset;
222         src = rte_pktmbuf_mtod(op->sym->m_src, uint8_t *);
223         if (op->sym->m_dst == NULL) {
224                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
225                 KASUMI_LOG_ERR("bit-level in-place not supported\n");
226                 return 0;
227         }
228         dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
229         iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
230                         session->iv_offset);
231         iv = *((uint64_t *)(iv_ptr));
232         length_in_bits = op->sym->cipher.data.length;
233
234         sso_kasumi_f8_1_buffer_bit(&session->pKeySched_cipher, iv,
235                         src, dst, length_in_bits, offset_in_bits);
236
237         return 1;
238 }
239
240 /** Generate/verify hash from mbufs with same hash key. */
241 static int
242 process_kasumi_hash_op(struct rte_crypto_op **ops,
243                 struct kasumi_session *session,
244                 uint8_t num_ops)
245 {
246         unsigned i;
247         uint8_t processed_ops = 0;
248         uint8_t *src, *dst;
249         uint32_t length_in_bits;
250         uint32_t num_bytes;
251         uint32_t shift_bits;
252         uint64_t iv;
253         uint8_t direction;
254
255         for (i = 0; i < num_ops; i++) {
256                 if (unlikely(ops[i]->sym->auth.aad.length != KASUMI_IV_LENGTH)) {
257                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
258                         KASUMI_LOG_ERR("aad");
259                         break;
260                 }
261
262                 if (unlikely(ops[i]->sym->auth.digest.length != KASUMI_DIGEST_LENGTH)) {
263                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
264                         KASUMI_LOG_ERR("digest");
265                         break;
266                 }
267
268                 /* Data must be byte aligned */
269                 if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
270                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
271                         KASUMI_LOG_ERR("offset");
272                         break;
273                 }
274
275                 length_in_bits = ops[i]->sym->auth.data.length;
276
277                 src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
278                                 (ops[i]->sym->auth.data.offset >> 3);
279                 /* IV from AAD */
280                 iv = *((uint64_t *)(ops[i]->sym->auth.aad.data));
281                 /* Direction from next bit after end of message */
282                 num_bytes = (length_in_bits >> 3) + 1;
283                 shift_bits = (BYTE_LEN - 1 - length_in_bits) % BYTE_LEN;
284                 direction = (src[num_bytes - 1] >> shift_bits) & 0x01;
285
286                 if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
287                         dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src,
288                                         ops[i]->sym->auth.digest.length);
289
290                         sso_kasumi_f9_1_buffer_user(&session->pKeySched_hash,
291                                         iv, src,
292                                         length_in_bits, dst, direction);
293                         /* Verify digest. */
294                         if (memcmp(dst, ops[i]->sym->auth.digest.data,
295                                         ops[i]->sym->auth.digest.length) != 0)
296                                 ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
297
298                         /* Trim area used for digest from mbuf. */
299                         rte_pktmbuf_trim(ops[i]->sym->m_src,
300                                         ops[i]->sym->auth.digest.length);
301                 } else  {
302                         dst = ops[i]->sym->auth.digest.data;
303
304                         sso_kasumi_f9_1_buffer_user(&session->pKeySched_hash,
305                                         iv, src,
306                                         length_in_bits, dst, direction);
307                 }
308                 processed_ops++;
309         }
310
311         return processed_ops;
312 }
313
314 /** Process a batch of crypto ops which shares the same session. */
315 static int
316 process_ops(struct rte_crypto_op **ops, struct kasumi_session *session,
317                 struct kasumi_qp *qp, uint8_t num_ops,
318                 uint16_t *accumulated_enqueued_ops)
319 {
320         unsigned i;
321         unsigned enqueued_ops, processed_ops;
322
323         switch (session->op) {
324         case KASUMI_OP_ONLY_CIPHER:
325                 processed_ops = process_kasumi_cipher_op(ops,
326                                 session, num_ops);
327                 break;
328         case KASUMI_OP_ONLY_AUTH:
329                 processed_ops = process_kasumi_hash_op(ops, session,
330                                 num_ops);
331                 break;
332         case KASUMI_OP_CIPHER_AUTH:
333                 processed_ops = process_kasumi_cipher_op(ops, session,
334                                 num_ops);
335                 process_kasumi_hash_op(ops, session, processed_ops);
336                 break;
337         case KASUMI_OP_AUTH_CIPHER:
338                 processed_ops = process_kasumi_hash_op(ops, session,
339                                 num_ops);
340                 process_kasumi_cipher_op(ops, session, processed_ops);
341                 break;
342         default:
343                 /* Operation not supported. */
344                 processed_ops = 0;
345         }
346
347         for (i = 0; i < num_ops; i++) {
348                 /*
349                  * If there was no error/authentication failure,
350                  * change status to successful.
351                  */
352                 if (ops[i]->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
353                         ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
354                 /* Free session if a session-less crypto op. */
355                 if (ops[i]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
356                         rte_mempool_put(qp->sess_mp, ops[i]->sym->session);
357                         ops[i]->sym->session = NULL;
358                 }
359         }
360
361         enqueued_ops = rte_ring_enqueue_burst(qp->processed_ops,
362                                 (void **)ops, processed_ops, NULL);
363         qp->qp_stats.enqueued_count += enqueued_ops;
364         *accumulated_enqueued_ops += enqueued_ops;
365
366         return enqueued_ops;
367 }
368
369 /** Process a crypto op with length/offset in bits. */
370 static int
371 process_op_bit(struct rte_crypto_op *op, struct kasumi_session *session,
372                 struct kasumi_qp *qp, uint16_t *accumulated_enqueued_ops)
373 {
374         unsigned enqueued_op, processed_op;
375
376         switch (session->op) {
377         case KASUMI_OP_ONLY_CIPHER:
378                 processed_op = process_kasumi_cipher_op_bit(op,
379                                 session);
380                 break;
381         case KASUMI_OP_ONLY_AUTH:
382                 processed_op = process_kasumi_hash_op(&op, session, 1);
383                 break;
384         case KASUMI_OP_CIPHER_AUTH:
385                 processed_op = process_kasumi_cipher_op_bit(op, session);
386                 if (processed_op == 1)
387                         process_kasumi_hash_op(&op, session, 1);
388                 break;
389         case KASUMI_OP_AUTH_CIPHER:
390                 processed_op = process_kasumi_hash_op(&op, session, 1);
391                 if (processed_op == 1)
392                         process_kasumi_cipher_op_bit(op, session);
393                 break;
394         default:
395                 /* Operation not supported. */
396                 processed_op = 0;
397         }
398
399         /*
400          * If there was no error/authentication failure,
401          * change status to successful.
402          */
403         if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
404                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
405
406         /* Free session if a session-less crypto op. */
407         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
408                 rte_mempool_put(qp->sess_mp, op->sym->session);
409                 op->sym->session = NULL;
410         }
411
412         enqueued_op = rte_ring_enqueue_burst(qp->processed_ops, (void **)&op,
413                                 processed_op, NULL);
414         qp->qp_stats.enqueued_count += enqueued_op;
415         *accumulated_enqueued_ops += enqueued_op;
416
417         return enqueued_op;
418 }
419
420 static uint16_t
421 kasumi_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
422                 uint16_t nb_ops)
423 {
424         struct rte_crypto_op *c_ops[nb_ops];
425         struct rte_crypto_op *curr_c_op;
426
427         struct kasumi_session *prev_sess = NULL, *curr_sess = NULL;
428         struct kasumi_qp *qp = queue_pair;
429         unsigned i;
430         uint8_t burst_size = 0;
431         uint16_t enqueued_ops = 0;
432         uint8_t processed_ops;
433
434         for (i = 0; i < nb_ops; i++) {
435                 curr_c_op = ops[i];
436
437 #ifdef RTE_LIBRTE_PMD_KASUMI_DEBUG
438                 if (!rte_pktmbuf_is_contiguous(curr_c_op->sym->m_src) ||
439                                 (curr_c_op->sym->m_dst != NULL &&
440                                 !rte_pktmbuf_is_contiguous(
441                                                 curr_c_op->sym->m_dst))) {
442                         KASUMI_LOG_ERR("PMD supports only contiguous mbufs, "
443                                 "op (%p) provides noncontiguous mbuf as "
444                                 "source/destination buffer.\n", curr_c_op);
445                         curr_c_op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
446                         break;
447                 }
448 #endif
449
450                 /* Set status as enqueued (not processed yet) by default. */
451                 curr_c_op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
452
453                 curr_sess = kasumi_get_session(qp, curr_c_op);
454                 if (unlikely(curr_sess == NULL ||
455                                 curr_sess->op == KASUMI_OP_NOT_SUPPORTED)) {
456                         curr_c_op->status =
457                                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
458                         break;
459                 }
460
461                 /* If length/offset is at bit-level, process this buffer alone. */
462                 if (((curr_c_op->sym->cipher.data.length % BYTE_LEN) != 0)
463                                 || ((ops[i]->sym->cipher.data.offset
464                                         % BYTE_LEN) != 0)) {
465                         /* Process the ops of the previous session. */
466                         if (prev_sess != NULL) {
467                                 processed_ops = process_ops(c_ops, prev_sess,
468                                                 qp, burst_size, &enqueued_ops);
469                                 if (processed_ops < burst_size) {
470                                         burst_size = 0;
471                                         break;
472                                 }
473
474                                 burst_size = 0;
475                                 prev_sess = NULL;
476                         }
477
478                         processed_ops = process_op_bit(curr_c_op, curr_sess,
479                                                 qp, &enqueued_ops);
480                         if (processed_ops != 1)
481                                 break;
482
483                         continue;
484                 }
485
486                 /* Batch ops that share the same session. */
487                 if (prev_sess == NULL) {
488                         prev_sess = curr_sess;
489                         c_ops[burst_size++] = curr_c_op;
490                 } else if (curr_sess == prev_sess) {
491                         c_ops[burst_size++] = curr_c_op;
492                         /*
493                          * When there are enough ops to process in a batch,
494                          * process them, and start a new batch.
495                          */
496                         if (burst_size == KASUMI_MAX_BURST) {
497                                 processed_ops = process_ops(c_ops, prev_sess,
498                                                 qp, burst_size, &enqueued_ops);
499                                 if (processed_ops < burst_size) {
500                                         burst_size = 0;
501                                         break;
502                                 }
503
504                                 burst_size = 0;
505                                 prev_sess = NULL;
506                         }
507                 } else {
508                         /*
509                          * Different session, process the ops
510                          * of the previous session.
511                          */
512                         processed_ops = process_ops(c_ops, prev_sess,
513                                         qp, burst_size, &enqueued_ops);
514                         if (processed_ops < burst_size) {
515                                 burst_size = 0;
516                                 break;
517                         }
518
519                         burst_size = 0;
520                         prev_sess = curr_sess;
521
522                         c_ops[burst_size++] = curr_c_op;
523                 }
524         }
525
526         if (burst_size != 0) {
527                 /* Process the crypto ops of the last session. */
528                 processed_ops = process_ops(c_ops, prev_sess,
529                                 qp, burst_size, &enqueued_ops);
530         }
531
532         qp->qp_stats.enqueue_err_count += nb_ops - enqueued_ops;
533         return enqueued_ops;
534 }
535
536 static uint16_t
537 kasumi_pmd_dequeue_burst(void *queue_pair,
538                 struct rte_crypto_op **c_ops, uint16_t nb_ops)
539 {
540         struct kasumi_qp *qp = queue_pair;
541
542         unsigned nb_dequeued;
543
544         nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
545                         (void **)c_ops, nb_ops, NULL);
546         qp->qp_stats.dequeued_count += nb_dequeued;
547
548         return nb_dequeued;
549 }
550
551 static int cryptodev_kasumi_remove(struct rte_vdev_device *vdev);
552
553 static int
554 cryptodev_kasumi_create(const char *name,
555                         struct rte_vdev_device *vdev,
556                         struct rte_crypto_vdev_init_params *init_params)
557 {
558         struct rte_cryptodev *dev;
559         struct kasumi_private *internals;
560         uint64_t cpu_flags = 0;
561
562         if (init_params->name[0] == '\0')
563                 snprintf(init_params->name, sizeof(init_params->name),
564                                 "%s", name);
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 = rte_cryptodev_vdev_pmd_init(init_params->name,
573                         sizeof(struct kasumi_private), init_params->socket_id,
574                         vdev);
575         if (dev == NULL) {
576                 KASUMI_LOG_ERR("failed to create cryptodev vdev");
577                 goto init_error;
578         }
579
580         dev->dev_type = RTE_CRYPTODEV_KASUMI_PMD;
581         dev->dev_ops = rte_kasumi_pmd_ops;
582
583         /* Register RX/TX burst functions for data path. */
584         dev->dequeue_burst = kasumi_pmd_dequeue_burst;
585         dev->enqueue_burst = kasumi_pmd_enqueue_burst;
586
587         dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
588                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
589                         cpu_flags;
590
591         internals = dev->data->dev_private;
592
593         internals->max_nb_queue_pairs = init_params->max_nb_queue_pairs;
594         internals->max_nb_sessions = init_params->max_nb_sessions;
595
596         return 0;
597 init_error:
598         KASUMI_LOG_ERR("driver %s: cryptodev_kasumi_create failed",
599                         init_params->name);
600
601         cryptodev_kasumi_remove(vdev);
602         return -EFAULT;
603 }
604
605 static int
606 cryptodev_kasumi_probe(struct rte_vdev_device *vdev)
607 {
608         struct rte_crypto_vdev_init_params init_params = {
609                 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
610                 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
611                 rte_socket_id(),
612                 {0}
613         };
614         const char *name;
615         const char *input_args;
616
617         name = rte_vdev_device_name(vdev);
618         if (name == NULL)
619                 return -EINVAL;
620         input_args = rte_vdev_device_args(vdev);
621
622         rte_cryptodev_vdev_parse_init_params(&init_params, input_args);
623
624         RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
625                         init_params.socket_id);
626         if (init_params.name[0] != '\0')
627                 RTE_LOG(INFO, PMD, "  User defined name = %s\n",
628                         init_params.name);
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, vdev, &init_params);
635 }
636
637 static int
638 cryptodev_kasumi_remove(struct rte_vdev_device *vdev)
639 {
640         const char *name;
641
642         name = rte_vdev_device_name(vdev);
643         if (name == NULL)
644                 return -EINVAL;
645
646         RTE_LOG(INFO, PMD, "Closing KASUMI crypto device %s"
647                         " on numa socket %u\n",
648                         name, rte_socket_id());
649
650         return 0;
651 }
652
653 static struct rte_vdev_driver cryptodev_kasumi_pmd_drv = {
654         .probe = cryptodev_kasumi_probe,
655         .remove = cryptodev_kasumi_remove
656 };
657
658 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_KASUMI_PMD, cryptodev_kasumi_pmd_drv);
659 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_KASUMI_PMD, cryptodev_kasumi_pmd);
660 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_KASUMI_PMD,
661         "max_nb_queue_pairs=<int> "
662         "max_nb_sessions=<int> "
663         "socket_id=<int>");