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