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