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