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