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