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