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