dad45068edf732394163b1c942e6b1d2c233457f
[deb_dpdk.git] / drivers / crypto / snow3g / rte_snow3g_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_snow3g_pmd_private.h"
44
45 #define SNOW3G_IV_LENGTH 16
46 #define SNOW3G_DIGEST_LENGTH 4
47 #define SNOW3G_MAX_BURST 8
48 #define BYTE_LEN 8
49
50 static uint8_t cryptodev_driver_id;
51
52 /** Get xform chain order. */
53 static enum snow3g_operation
54 snow3g_get_mode(const struct rte_crypto_sym_xform *xform)
55 {
56         if (xform == NULL)
57                 return SNOW3G_OP_NOT_SUPPORTED;
58
59         if (xform->next)
60                 if (xform->next->next != NULL)
61                         return SNOW3G_OP_NOT_SUPPORTED;
62
63         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
64                 if (xform->next == NULL)
65                         return SNOW3G_OP_ONLY_AUTH;
66                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
67                         return SNOW3G_OP_AUTH_CIPHER;
68                 else
69                         return SNOW3G_OP_NOT_SUPPORTED;
70         }
71
72         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
73                 if (xform->next == NULL)
74                         return SNOW3G_OP_ONLY_CIPHER;
75                 else if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
76                         return SNOW3G_OP_CIPHER_AUTH;
77                 else
78                         return SNOW3G_OP_NOT_SUPPORTED;
79         }
80
81         return SNOW3G_OP_NOT_SUPPORTED;
82 }
83
84
85 /** Parse crypto xform chain and set private session parameters. */
86 int
87 snow3g_set_session_parameters(struct snow3g_session *sess,
88                 const struct rte_crypto_sym_xform *xform)
89 {
90         const struct rte_crypto_sym_xform *auth_xform = NULL;
91         const struct rte_crypto_sym_xform *cipher_xform = NULL;
92         enum snow3g_operation mode;
93
94         /* Select Crypto operation - hash then cipher / cipher then hash */
95         mode = snow3g_get_mode(xform);
96
97         switch (mode) {
98         case SNOW3G_OP_CIPHER_AUTH:
99                 auth_xform = xform->next;
100
101                 /* Fall-through */
102         case SNOW3G_OP_ONLY_CIPHER:
103                 cipher_xform = xform;
104                 break;
105         case SNOW3G_OP_AUTH_CIPHER:
106                 cipher_xform = xform->next;
107                 /* Fall-through */
108         case SNOW3G_OP_ONLY_AUTH:
109                 auth_xform = xform;
110                 break;
111         case SNOW3G_OP_NOT_SUPPORTED:
112         default:
113                 SNOW3G_LOG_ERR("Unsupported operation chain order parameter");
114                 return -ENOTSUP;
115         }
116
117         if (cipher_xform) {
118                 /* Only SNOW 3G UEA2 supported */
119                 if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_SNOW3G_UEA2)
120                         return -ENOTSUP;
121
122                 if (cipher_xform->cipher.iv.length != SNOW3G_IV_LENGTH) {
123                         SNOW3G_LOG_ERR("Wrong IV length");
124                         return -EINVAL;
125                 }
126                 sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
127
128                 /* Initialize key */
129                 sso_snow3g_init_key_sched(cipher_xform->cipher.key.data,
130                                 &sess->pKeySched_cipher);
131         }
132
133         if (auth_xform) {
134                 /* Only SNOW 3G UIA2 supported */
135                 if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_SNOW3G_UIA2)
136                         return -ENOTSUP;
137
138                 if (auth_xform->auth.digest_length != SNOW3G_DIGEST_LENGTH) {
139                         SNOW3G_LOG_ERR("Wrong digest length");
140                         return -EINVAL;
141                 }
142
143                 sess->auth_op = auth_xform->auth.op;
144
145                 if (auth_xform->auth.iv.length != SNOW3G_IV_LENGTH) {
146                         SNOW3G_LOG_ERR("Wrong IV length");
147                         return -EINVAL;
148                 }
149                 sess->auth_iv_offset = auth_xform->auth.iv.offset;
150
151                 /* Initialize key */
152                 sso_snow3g_init_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 SNOW 3G session. */
163 static struct snow3g_session *
164 snow3g_get_session(struct snow3g_qp *qp, struct rte_crypto_op *op)
165 {
166         struct snow3g_session *sess = NULL;
167
168         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
169                 if (likely(op->sym->session != NULL))
170                         sess = (struct snow3g_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 snow3g_session *)_sess_private_data;
185
186                 if (unlikely(snow3g_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
201         return sess;
202 }
203
204 /** Encrypt/decrypt mbufs with same cipher key. */
205 static uint8_t
206 process_snow3g_cipher_op(struct rte_crypto_op **ops,
207                 struct snow3g_session *session,
208                 uint8_t num_ops)
209 {
210         unsigned i;
211         uint8_t processed_ops = 0;
212         uint8_t *src[SNOW3G_MAX_BURST], *dst[SNOW3G_MAX_BURST];
213         uint8_t *iv[SNOW3G_MAX_BURST];
214         uint32_t num_bytes[SNOW3G_MAX_BURST];
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[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
225                                 session->cipher_iv_offset);
226                 num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
227
228                 processed_ops++;
229         }
230
231         sso_snow3g_f8_n_buffer(&session->pKeySched_cipher, iv, src, dst,
232                         num_bytes, processed_ops);
233
234         return processed_ops;
235 }
236
237 /** Encrypt/decrypt mbuf (bit level function). */
238 static uint8_t
239 process_snow3g_cipher_op_bit(struct rte_crypto_op *op,
240                 struct snow3g_session *session)
241 {
242         uint8_t *src, *dst;
243         uint8_t *iv;
244         uint32_t length_in_bits, offset_in_bits;
245
246         offset_in_bits = op->sym->cipher.data.offset;
247         src = rte_pktmbuf_mtod(op->sym->m_src, uint8_t *);
248         if (op->sym->m_dst == NULL) {
249                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
250                 SNOW3G_LOG_ERR("bit-level in-place not supported\n");
251                 return 0;
252         }
253         dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
254         iv = rte_crypto_op_ctod_offset(op, uint8_t *,
255                                 session->cipher_iv_offset);
256         length_in_bits = op->sym->cipher.data.length;
257
258         sso_snow3g_f8_1_buffer_bit(&session->pKeySched_cipher, iv,
259                         src, dst, length_in_bits, offset_in_bits);
260
261         return 1;
262 }
263
264 /** Generate/verify hash from mbufs with same hash key. */
265 static int
266 process_snow3g_hash_op(struct rte_crypto_op **ops,
267                 struct snow3g_session *session,
268                 uint8_t num_ops)
269 {
270         unsigned i;
271         uint8_t processed_ops = 0;
272         uint8_t *src, *dst;
273         uint32_t length_in_bits;
274         uint8_t *iv;
275
276         for (i = 0; i < num_ops; i++) {
277                 /* Data must be byte aligned */
278                 if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
279                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
280                         SNOW3G_LOG_ERR("Offset");
281                         break;
282                 }
283
284                 length_in_bits = ops[i]->sym->auth.data.length;
285
286                 src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
287                                 (ops[i]->sym->auth.data.offset >> 3);
288                 iv = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
289                                 session->auth_iv_offset);
290
291                 if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
292                         dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src,
293                                         SNOW3G_DIGEST_LENGTH);
294
295                         sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
296                                         iv, src,
297                                         length_in_bits, dst);
298                         /* Verify digest. */
299                         if (memcmp(dst, ops[i]->sym->auth.digest.data,
300                                         SNOW3G_DIGEST_LENGTH) != 0)
301                                 ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
302
303                         /* Trim area used for digest from mbuf. */
304                         rte_pktmbuf_trim(ops[i]->sym->m_src,
305                                         SNOW3G_DIGEST_LENGTH);
306                 } else  {
307                         dst = ops[i]->sym->auth.digest.data;
308
309                         sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
310                                         iv, src,
311                                         length_in_bits, dst);
312                 }
313                 processed_ops++;
314         }
315
316         return processed_ops;
317 }
318
319 /** Process a batch of crypto ops which shares the same session. */
320 static int
321 process_ops(struct rte_crypto_op **ops, struct snow3g_session *session,
322                 struct snow3g_qp *qp, uint8_t num_ops,
323                 uint16_t *accumulated_enqueued_ops)
324 {
325         unsigned i;
326         unsigned enqueued_ops, processed_ops;
327
328 #ifdef RTE_LIBRTE_PMD_SNOW3G_DEBUG
329         for (i = 0; i < num_ops; i++) {
330                 if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
331                                 (ops[i]->sym->m_dst != NULL &&
332                                 !rte_pktmbuf_is_contiguous(
333                                                 ops[i]->sym->m_dst))) {
334                         SNOW3G_LOG_ERR("PMD supports only contiguous mbufs, "
335                                 "op (%p) provides noncontiguous mbuf as "
336                                 "source/destination buffer.\n", ops[i]);
337                         ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
338                         return 0;
339                 }
340         }
341 #endif
342
343         switch (session->op) {
344         case SNOW3G_OP_ONLY_CIPHER:
345                 processed_ops = process_snow3g_cipher_op(ops,
346                                 session, num_ops);
347                 break;
348         case SNOW3G_OP_ONLY_AUTH:
349                 processed_ops = process_snow3g_hash_op(ops, session,
350                                 num_ops);
351                 break;
352         case SNOW3G_OP_CIPHER_AUTH:
353                 processed_ops = process_snow3g_cipher_op(ops, session,
354                                 num_ops);
355                 process_snow3g_hash_op(ops, session, processed_ops);
356                 break;
357         case SNOW3G_OP_AUTH_CIPHER:
358                 processed_ops = process_snow3g_hash_op(ops, session,
359                                 num_ops);
360                 process_snow3g_cipher_op(ops, session, processed_ops);
361                 break;
362         default:
363                 /* Operation not supported. */
364                 processed_ops = 0;
365         }
366
367         for (i = 0; i < num_ops; i++) {
368                 /*
369                  * If there was no error/authentication failure,
370                  * change status to successful.
371                  */
372                 if (ops[i]->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
373                         ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
374                 /* Free session if a session-less crypto op. */
375                 if (ops[i]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
376                         memset(session, 0, sizeof(struct snow3g_session));
377                         memset(ops[i]->sym->session, 0,
378                                         rte_cryptodev_get_header_session_size());
379                         rte_mempool_put(qp->sess_mp, session);
380                         rte_mempool_put(qp->sess_mp, ops[i]->sym->session);
381                         ops[i]->sym->session = NULL;
382                 }
383         }
384
385         enqueued_ops = rte_ring_enqueue_burst(qp->processed_ops,
386                         (void **)ops, processed_ops, NULL);
387         qp->qp_stats.enqueued_count += enqueued_ops;
388         *accumulated_enqueued_ops += enqueued_ops;
389
390         return enqueued_ops;
391 }
392
393 /** Process a crypto op with length/offset in bits. */
394 static int
395 process_op_bit(struct rte_crypto_op *op, struct snow3g_session *session,
396                 struct snow3g_qp *qp, uint16_t *accumulated_enqueued_ops)
397 {
398         unsigned enqueued_op, processed_op;
399
400         switch (session->op) {
401         case SNOW3G_OP_ONLY_CIPHER:
402                 processed_op = process_snow3g_cipher_op_bit(op,
403                                 session);
404                 break;
405         case SNOW3G_OP_ONLY_AUTH:
406                 processed_op = process_snow3g_hash_op(&op, session, 1);
407                 break;
408         case SNOW3G_OP_CIPHER_AUTH:
409                 processed_op = process_snow3g_cipher_op_bit(op, session);
410                 if (processed_op == 1)
411                         process_snow3g_hash_op(&op, session, 1);
412                 break;
413         case SNOW3G_OP_AUTH_CIPHER:
414                 processed_op = process_snow3g_hash_op(&op, session, 1);
415                 if (processed_op == 1)
416                         process_snow3g_cipher_op_bit(op, session);
417                 break;
418         default:
419                 /* Operation not supported. */
420                 processed_op = 0;
421         }
422
423         /*
424          * If there was no error/authentication failure,
425          * change status to successful.
426          */
427         if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
428                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
429
430         /* Free session if a session-less crypto op. */
431         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
432                 memset(op->sym->session, 0, sizeof(struct snow3g_session));
433                 rte_cryptodev_sym_session_free(op->sym->session);
434                 op->sym->session = NULL;
435         }
436
437         enqueued_op = rte_ring_enqueue_burst(qp->processed_ops,
438                         (void **)&op, processed_op, NULL);
439         qp->qp_stats.enqueued_count += enqueued_op;
440         *accumulated_enqueued_ops += enqueued_op;
441
442         return enqueued_op;
443 }
444
445 static uint16_t
446 snow3g_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
447                 uint16_t nb_ops)
448 {
449         struct rte_crypto_op *c_ops[SNOW3G_MAX_BURST];
450         struct rte_crypto_op *curr_c_op;
451
452         struct snow3g_session *prev_sess = NULL, *curr_sess = NULL;
453         struct snow3g_qp *qp = queue_pair;
454         unsigned i;
455         uint8_t burst_size = 0;
456         uint16_t enqueued_ops = 0;
457         uint8_t processed_ops;
458
459         for (i = 0; i < nb_ops; i++) {
460                 curr_c_op = ops[i];
461
462                 /* Set status as enqueued (not processed yet) by default. */
463                 curr_c_op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
464
465                 curr_sess = snow3g_get_session(qp, curr_c_op);
466                 if (unlikely(curr_sess == NULL ||
467                                 curr_sess->op == SNOW3G_OP_NOT_SUPPORTED)) {
468                         curr_c_op->status =
469                                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
470                         break;
471                 }
472
473                 /* If length/offset is at bit-level, process this buffer alone. */
474                 if (((curr_c_op->sym->cipher.data.length % BYTE_LEN) != 0)
475                                 || ((curr_c_op->sym->cipher.data.offset
476                                         % BYTE_LEN) != 0)) {
477                         /* Process the ops of the previous session. */
478                         if (prev_sess != NULL) {
479                                 processed_ops = process_ops(c_ops, prev_sess,
480                                 qp, burst_size, &enqueued_ops);
481                                 if (processed_ops < burst_size) {
482                                         burst_size = 0;
483                                         break;
484                                 }
485
486                                 burst_size = 0;
487                                 prev_sess = NULL;
488                         }
489
490                         processed_ops = process_op_bit(curr_c_op, curr_sess,
491                                                         qp, &enqueued_ops);
492                         if (processed_ops != 1)
493                                 break;
494
495                         continue;
496                 }
497
498                 /* Batch ops that share the same session. */
499                 if (prev_sess == NULL) {
500                         prev_sess = curr_sess;
501                         c_ops[burst_size++] = curr_c_op;
502                 } else if (curr_sess == prev_sess) {
503                         c_ops[burst_size++] = curr_c_op;
504                         /*
505                          * When there are enough ops to process in a batch,
506                          * process them, and start a new batch.
507                          */
508                         if (burst_size == SNOW3G_MAX_BURST) {
509                                 processed_ops = process_ops(c_ops, prev_sess,
510                                                 qp, burst_size, &enqueued_ops);
511                                 if (processed_ops < burst_size) {
512                                         burst_size = 0;
513                                         break;
514                                 }
515
516                                 burst_size = 0;
517                                 prev_sess = NULL;
518                         }
519                 } else {
520                         /*
521                          * Different session, process the ops
522                          * of the previous session.
523                          */
524                         processed_ops = process_ops(c_ops, prev_sess,
525                                         qp, burst_size, &enqueued_ops);
526                         if (processed_ops < burst_size) {
527                                 burst_size = 0;
528                                 break;
529                         }
530
531                         burst_size = 0;
532                         prev_sess = curr_sess;
533
534                         c_ops[burst_size++] = curr_c_op;
535                 }
536         }
537
538         if (burst_size != 0) {
539                 /* Process the crypto ops of the last session. */
540                 processed_ops = process_ops(c_ops, prev_sess,
541                                 qp, burst_size, &enqueued_ops);
542         }
543
544         qp->qp_stats.enqueue_err_count += nb_ops - enqueued_ops;
545         return enqueued_ops;
546 }
547
548 static uint16_t
549 snow3g_pmd_dequeue_burst(void *queue_pair,
550                 struct rte_crypto_op **c_ops, uint16_t nb_ops)
551 {
552         struct snow3g_qp *qp = queue_pair;
553
554         unsigned nb_dequeued;
555
556         nb_dequeued = rte_ring_dequeue_burst(qp->processed_ops,
557                         (void **)c_ops, nb_ops, NULL);
558         qp->qp_stats.dequeued_count += nb_dequeued;
559
560         return nb_dequeued;
561 }
562
563 static int cryptodev_snow3g_remove(struct rte_vdev_device *vdev);
564
565 static int
566 cryptodev_snow3g_create(const char *name,
567                         struct rte_vdev_device *vdev,
568                         struct rte_crypto_vdev_init_params *init_params)
569 {
570         struct rte_cryptodev *dev;
571         struct snow3g_private *internals;
572         uint64_t cpu_flags = RTE_CRYPTODEV_FF_CPU_SSE;
573
574         if (init_params->name[0] == '\0')
575                 snprintf(init_params->name, sizeof(init_params->name),
576                                 "%s", name);
577
578         dev = rte_cryptodev_vdev_pmd_init(init_params->name,
579                         sizeof(struct snow3g_private), init_params->socket_id,
580                         vdev);
581         if (dev == NULL) {
582                 SNOW3G_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_snow3g_pmd_ops;
588
589         /* Register RX/TX burst functions for data path. */
590         dev->dequeue_burst = snow3g_pmd_dequeue_burst;
591         dev->enqueue_burst = snow3g_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         SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed",
605                         init_params->name);
606
607         cryptodev_snow3g_remove(vdev);
608         return -EFAULT;
609 }
610
611 static int
612 cryptodev_snow3g_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_snow3g_create(name, vdev, &init_params);
641 }
642
643 static int
644 cryptodev_snow3g_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 SNOW 3G 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_snow3g_pmd_drv = {
660         .probe = cryptodev_snow3g_probe,
661         .remove = cryptodev_snow3g_remove
662 };
663
664 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd_drv);
665 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_SNOW3G_PMD, cryptodev_snow3g_pmd);
666 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
667         "max_nb_queue_pairs=<int> "
668         "max_nb_sessions=<int> "
669         "socket_id=<int>");
670 RTE_PMD_REGISTER_CRYPTO_DRIVER(cryptodev_snow3g_pmd_drv, cryptodev_driver_id);