crypto/kasumi: do not append digest
[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_MAX_BURST 4
48 #define BYTE_LEN 8
49
50 static uint8_t cryptodev_driver_id;
51
52 /** Get xform chain order. */
53 static enum kasumi_operation
54 kasumi_get_mode(const struct rte_crypto_sym_xform *xform)
55 {
56         if (xform == NULL)
57                 return KASUMI_OP_NOT_SUPPORTED;
58
59         if (xform->next)
60                 if (xform->next->next != NULL)
61                         return KASUMI_OP_NOT_SUPPORTED;
62
63         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
64                 if (xform->next == NULL)
65                         return KASUMI_OP_ONLY_AUTH;
66                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
67                         return KASUMI_OP_AUTH_CIPHER;
68                 else
69                         return KASUMI_OP_NOT_SUPPORTED;
70         }
71
72         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
73                 if (xform->next == NULL)
74                         return KASUMI_OP_ONLY_CIPHER;
75                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
76                         return KASUMI_OP_CIPHER_AUTH;
77                 else
78                         return KASUMI_OP_NOT_SUPPORTED;
79         }
80
81         return KASUMI_OP_NOT_SUPPORTED;
82 }
83
84
85 /** Parse crypto xform chain and set private session parameters. */
86 int
87 kasumi_set_session_parameters(struct kasumi_session *sess,
88                 const struct rte_crypto_sym_xform *xform)
89 {
90         const struct rte_crypto_sym_xform *auth_xform = NULL;
91         const struct rte_crypto_sym_xform *cipher_xform = NULL;
92         enum kasumi_operation mode;
93
94         /* Select Crypto operation - hash then cipher / cipher then hash */
95         mode = kasumi_get_mode(xform);
96
97         switch (mode) {
98         case KASUMI_OP_CIPHER_AUTH:
99                 auth_xform = xform->next;
100                 /* Fall-through */
101         case KASUMI_OP_ONLY_CIPHER:
102                 cipher_xform = xform;
103                 break;
104         case KASUMI_OP_AUTH_CIPHER:
105                 cipher_xform = xform->next;
106                 /* Fall-through */
107         case KASUMI_OP_ONLY_AUTH:
108                 auth_xform = xform;
109                 break;
110         case KASUMI_OP_NOT_SUPPORTED:
111         default:
112                 KASUMI_LOG_ERR("Unsupported operation chain order parameter");
113                 return -ENOTSUP;
114         }
115
116         if (cipher_xform) {
117                 /* Only KASUMI F8 supported */
118                 if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_KASUMI_F8)
119                         return -ENOTSUP;
120
121                 sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
122                 if (cipher_xform->cipher.iv.length != KASUMI_IV_LENGTH) {
123                         KASUMI_LOG_ERR("Wrong IV length");
124                         return -EINVAL;
125                 }
126
127                 /* Initialize key */
128                 sso_kasumi_init_f8_key_sched(cipher_xform->cipher.key.data,
129                                 &sess->pKeySched_cipher);
130         }
131
132         if (auth_xform) {
133                 /* Only KASUMI F9 supported */
134                 if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_KASUMI_F9)
135                         return -ENOTSUP;
136
137                 if (auth_xform->auth.digest_length != KASUMI_DIGEST_LENGTH) {
138                         KASUMI_LOG_ERR("Wrong digest length");
139                         return -EINVAL;
140                 }
141
142                 sess->auth_op = auth_xform->auth.op;
143
144                 /* Initialize key */
145                 sso_kasumi_init_f9_key_sched(auth_xform->auth.key.data,
146                                 &sess->pKeySched_hash);
147         }
148
149
150         sess->op = mode;
151
152         return 0;
153 }
154
155 /** Get KASUMI session. */
156 static struct kasumi_session *
157 kasumi_get_session(struct kasumi_qp *qp, struct rte_crypto_op *op)
158 {
159         struct kasumi_session *sess = NULL;
160
161         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
162                 if (likely(op->sym->session != NULL))
163                         sess = (struct kasumi_session *)
164                                         get_session_private_data(
165                                         op->sym->session,
166                                         cryptodev_driver_id);
167         } else {
168                 void *_sess = NULL;
169                 void *_sess_private_data = NULL;
170
171                 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
172                         return NULL;
173
174                 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
175                         return NULL;
176
177                 sess = (struct kasumi_session *)_sess_private_data;
178
179                 if (unlikely(kasumi_set_session_parameters(sess,
180                                 op->sym->xform) != 0)) {
181                         rte_mempool_put(qp->sess_mp, _sess);
182                         rte_mempool_put(qp->sess_mp, _sess_private_data);
183                         sess = NULL;
184                 }
185                 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
186                 set_session_private_data(op->sym->session, cryptodev_driver_id,
187                         _sess_private_data);
188         }
189
190         if (unlikely(sess == NULL))
191                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
192
193         return sess;
194 }
195
196 /** Encrypt/decrypt mbufs with same cipher key. */
197 static uint8_t
198 process_kasumi_cipher_op(struct rte_crypto_op **ops,
199                 struct kasumi_session *session,
200                 uint8_t num_ops)
201 {
202         unsigned i;
203         uint8_t processed_ops = 0;
204         uint8_t *src[num_ops], *dst[num_ops];
205         uint8_t *iv_ptr;
206         uint64_t iv[num_ops];
207         uint32_t num_bytes[num_ops];
208
209         for (i = 0; i < num_ops; i++) {
210                 src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
211                                 (ops[i]->sym->cipher.data.offset >> 3);
212                 dst[i] = ops[i]->sym->m_dst ?
213                         rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) +
214                                 (ops[i]->sym->cipher.data.offset >> 3) :
215                         rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
216                                 (ops[i]->sym->cipher.data.offset >> 3);
217                 iv_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
218                                 session->cipher_iv_offset);
219                 iv[i] = *((uint64_t *)(iv_ptr));
220                 num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
221
222                 processed_ops++;
223         }
224
225         if (processed_ops != 0)
226                 sso_kasumi_f8_n_buffer(&session->pKeySched_cipher, iv,
227                         src, dst, num_bytes, processed_ops);
228
229         return processed_ops;
230 }
231
232 /** Encrypt/decrypt mbuf (bit level function). */
233 static uint8_t
234 process_kasumi_cipher_op_bit(struct rte_crypto_op *op,
235                 struct kasumi_session *session)
236 {
237         uint8_t *src, *dst;
238         uint8_t *iv_ptr;
239         uint64_t iv;
240         uint32_t length_in_bits, offset_in_bits;
241
242         offset_in_bits = op->sym->cipher.data.offset;
243         src = rte_pktmbuf_mtod(op->sym->m_src, uint8_t *);
244         if (op->sym->m_dst == NULL) {
245                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
246                 KASUMI_LOG_ERR("bit-level in-place not supported\n");
247                 return 0;
248         }
249         dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
250         iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
251                         session->cipher_iv_offset);
252         iv = *((uint64_t *)(iv_ptr));
253         length_in_bits = op->sym->cipher.data.length;
254
255         sso_kasumi_f8_1_buffer_bit(&session->pKeySched_cipher, iv,
256                         src, dst, length_in_bits, offset_in_bits);
257
258         return 1;
259 }
260
261 /** Generate/verify hash from mbufs with same hash key. */
262 static int
263 process_kasumi_hash_op(struct kasumi_qp *qp, struct rte_crypto_op **ops,
264                 struct kasumi_session *session,
265                 uint8_t num_ops)
266 {
267         unsigned i;
268         uint8_t processed_ops = 0;
269         uint8_t *src, *dst;
270         uint32_t length_in_bits;
271         uint32_t num_bytes;
272
273         for (i = 0; i < num_ops; i++) {
274                 /* Data must be byte aligned */
275                 if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
276                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
277                         KASUMI_LOG_ERR("offset");
278                         break;
279                 }
280
281                 length_in_bits = ops[i]->sym->auth.data.length;
282
283                 src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
284                                 (ops[i]->sym->auth.data.offset >> 3);
285                 /* Direction from next bit after end of message */
286                 num_bytes = length_in_bits >> 3;
287
288                 if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
289                         dst = qp->temp_digest;
290                         sso_kasumi_f9_1_buffer(&session->pKeySched_hash, src,
291                                         num_bytes, dst);
292
293                         /* Verify digest. */
294                         if (memcmp(dst, ops[i]->sym->auth.digest.data,
295                                         KASUMI_DIGEST_LENGTH) != 0)
296                                 ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
297                 } else  {
298                         dst = ops[i]->sym->auth.digest.data;
299
300                         sso_kasumi_f9_1_buffer(&session->pKeySched_hash, src,
301                                         num_bytes, dst);
302                 }
303                 processed_ops++;
304         }
305
306         return processed_ops;
307 }
308
309 /** Process a batch of crypto ops which shares the same session. */
310 static int
311 process_ops(struct rte_crypto_op **ops, struct kasumi_session *session,
312                 struct kasumi_qp *qp, uint8_t num_ops,
313                 uint16_t *accumulated_enqueued_ops)
314 {
315         unsigned i;
316         unsigned enqueued_ops, processed_ops;
317
318         switch (session->op) {
319         case KASUMI_OP_ONLY_CIPHER:
320                 processed_ops = process_kasumi_cipher_op(ops,
321                                 session, num_ops);
322                 break;
323         case KASUMI_OP_ONLY_AUTH:
324                 processed_ops = process_kasumi_hash_op(qp, ops, session,
325                                 num_ops);
326                 break;
327         case KASUMI_OP_CIPHER_AUTH:
328                 processed_ops = process_kasumi_cipher_op(ops, session,
329                                 num_ops);
330                 process_kasumi_hash_op(qp, ops, session, processed_ops);
331                 break;
332         case KASUMI_OP_AUTH_CIPHER:
333                 processed_ops = process_kasumi_hash_op(qp, ops, session,
334                                 num_ops);
335                 process_kasumi_cipher_op(ops, session, processed_ops);
336                 break;
337         default:
338                 /* Operation not supported. */
339                 processed_ops = 0;
340         }
341
342         for (i = 0; i < num_ops; i++) {
343                 /*
344                  * If there was no error/authentication failure,
345                  * change status to successful.
346                  */
347                 if (ops[i]->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
348                         ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
349                 /* Free session if a session-less crypto op. */
350                 if (ops[i]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
351                         memset(session, 0, sizeof(struct kasumi_session));
352                         memset(ops[i]->sym->session, 0,
353                                         rte_cryptodev_get_header_session_size());
354                         rte_mempool_put(qp->sess_mp, session);
355                         rte_mempool_put(qp->sess_mp, ops[i]->sym->session);
356                         ops[i]->sym->session = NULL;
357                 }
358         }
359
360         enqueued_ops = rte_ring_enqueue_burst(qp->processed_ops,
361                                 (void **)ops, processed_ops, NULL);
362         qp->qp_stats.enqueued_count += enqueued_ops;
363         *accumulated_enqueued_ops += enqueued_ops;
364
365         return enqueued_ops;
366 }
367
368 /** Process a crypto op with length/offset in bits. */
369 static int
370 process_op_bit(struct rte_crypto_op *op, struct kasumi_session *session,
371                 struct kasumi_qp *qp, uint16_t *accumulated_enqueued_ops)
372 {
373         unsigned enqueued_op, processed_op;
374
375         switch (session->op) {
376         case KASUMI_OP_ONLY_CIPHER:
377                 processed_op = process_kasumi_cipher_op_bit(op,
378                                 session);
379                 break;
380         case KASUMI_OP_ONLY_AUTH:
381                 processed_op = process_kasumi_hash_op(qp, &op, session, 1);
382                 break;
383         case KASUMI_OP_CIPHER_AUTH:
384                 processed_op = process_kasumi_cipher_op_bit(op, session);
385                 if (processed_op == 1)
386                         process_kasumi_hash_op(qp, &op, session, 1);
387                 break;
388         case KASUMI_OP_AUTH_CIPHER:
389                 processed_op = process_kasumi_hash_op(qp, &op, session, 1);
390                 if (processed_op == 1)
391                         process_kasumi_cipher_op_bit(op, session);
392                 break;
393         default:
394                 /* Operation not supported. */
395                 processed_op = 0;
396         }
397
398         /*
399          * If there was no error/authentication failure,
400          * change status to successful.
401          */
402         if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
403                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
404
405         /* Free session if a session-less crypto op. */
406         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
407                 memset(op->sym->session, 0, sizeof(struct kasumi_session));
408                 rte_cryptodev_sym_session_free(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->driver_id = cryptodev_driver_id;
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 static struct cryptodev_driver kasumi_crypto_drv;
659
660 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_KASUMI_PMD, cryptodev_kasumi_pmd_drv);
661 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_KASUMI_PMD, cryptodev_kasumi_pmd);
662 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_KASUMI_PMD,
663         "max_nb_queue_pairs=<int> "
664         "max_nb_sessions=<int> "
665         "socket_id=<int>");
666 RTE_PMD_REGISTER_CRYPTO_DRIVER(kasumi_crypto_drv, cryptodev_kasumi_pmd_drv,
667                 cryptodev_driver_id);