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