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