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