aesni_mb: add driver for multi buffer based crypto
[dpdk.git] / drivers / crypto / aesni_mb / rte_aesni_mb_pmd.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015 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_dev.h>
39 #include <rte_malloc.h>
40 #include <rte_cpuflags.h>
41 #include <rte_mbuf_offload.h>
42
43 #include "rte_aesni_mb_pmd_private.h"
44
45 /**
46  * Global static parameter used to create a unique name for each AES-NI multi
47  * buffer crypto device.
48  */
49 static unsigned unique_name_id;
50
51 static inline int
52 create_unique_device_name(char *name, size_t size)
53 {
54         int ret;
55
56         if (name == NULL)
57                 return -EINVAL;
58
59         ret = snprintf(name, size, "%s_%u", CRYPTODEV_NAME_AESNI_MB_PMD,
60                         unique_name_id++);
61         if (ret < 0)
62                 return ret;
63         return 0;
64 }
65
66 typedef void (*hash_one_block_t)(void *data, void *digest);
67 typedef void (*aes_keyexp_t)(void *key, void *enc_exp_keys, void *dec_exp_keys);
68
69 /**
70  * Calculate the authentication pre-computes
71  *
72  * @param one_block_hash        Function pointer to calculate digest on ipad/opad
73  * @param ipad                  Inner pad output byte array
74  * @param opad                  Outer pad output byte array
75  * @param hkey                  Authentication key
76  * @param hkey_len              Authentication key length
77  * @param blocksize             Block size of selected hash algo
78  */
79 static void
80 calculate_auth_precomputes(hash_one_block_t one_block_hash,
81                 uint8_t *ipad, uint8_t *opad,
82                 uint8_t *hkey, uint16_t hkey_len,
83                 uint16_t blocksize)
84 {
85         unsigned i, length;
86
87         uint8_t ipad_buf[blocksize] __rte_aligned(16);
88         uint8_t opad_buf[blocksize] __rte_aligned(16);
89
90         /* Setup inner and outer pads */
91         memset(ipad_buf, HMAC_IPAD_VALUE, blocksize);
92         memset(opad_buf, HMAC_OPAD_VALUE, blocksize);
93
94         /* XOR hash key with inner and outer pads */
95         length = hkey_len > blocksize ? blocksize : hkey_len;
96
97         for (i = 0; i < length; i++) {
98                 ipad_buf[i] ^= hkey[i];
99                 opad_buf[i] ^= hkey[i];
100         }
101
102         /* Compute partial hashes */
103         (*one_block_hash)(ipad_buf, ipad);
104         (*one_block_hash)(opad_buf, opad);
105
106         /* Clean up stack */
107         memset(ipad_buf, 0, blocksize);
108         memset(opad_buf, 0, blocksize);
109 }
110
111 /** Get xform chain order */
112 static int
113 aesni_mb_get_chain_order(const struct rte_crypto_xform *xform)
114 {
115         /*
116          * Multi-buffer only supports HASH_CIPHER or CIPHER_HASH chained
117          * operations, all other options are invalid, so we must have exactly
118          * 2 xform structs chained together
119          */
120         if (xform->next == NULL || xform->next->next != NULL)
121                 return -1;
122
123         if (xform->type == RTE_CRYPTO_XFORM_AUTH &&
124                         xform->next->type == RTE_CRYPTO_XFORM_CIPHER)
125                 return HASH_CIPHER;
126
127         if (xform->type == RTE_CRYPTO_XFORM_CIPHER &&
128                                 xform->next->type == RTE_CRYPTO_XFORM_AUTH)
129                 return CIPHER_HASH;
130
131         return -1;
132 }
133
134 /** Set session authentication parameters */
135 static int
136 aesni_mb_set_session_auth_parameters(const struct aesni_mb_ops *mb_ops,
137                 struct aesni_mb_session *sess,
138                 const struct rte_crypto_xform *xform)
139 {
140         hash_one_block_t hash_oneblock_fn;
141
142         if (xform->type != RTE_CRYPTO_XFORM_AUTH) {
143                 MB_LOG_ERR("Crypto xform struct not of type auth");
144                 return -1;
145         }
146
147         /* Set Authentication Parameters */
148         if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
149                 sess->auth.algo = AES_XCBC;
150                 (*mb_ops->aux.keyexp.aes_xcbc)(xform->auth.key.data,
151                                 sess->auth.xcbc.k1_expanded,
152                                 sess->auth.xcbc.k2, sess->auth.xcbc.k3);
153                 return 0;
154         }
155
156         switch (xform->auth.algo) {
157         case RTE_CRYPTO_AUTH_MD5_HMAC:
158                 sess->auth.algo = MD5;
159                 hash_oneblock_fn = mb_ops->aux.one_block.md5;
160                 break;
161         case RTE_CRYPTO_AUTH_SHA1_HMAC:
162                 sess->auth.algo = SHA1;
163                 hash_oneblock_fn = mb_ops->aux.one_block.sha1;
164                 break;
165         case RTE_CRYPTO_AUTH_SHA224_HMAC:
166                 sess->auth.algo = SHA_224;
167                 hash_oneblock_fn = mb_ops->aux.one_block.sha224;
168                 break;
169         case RTE_CRYPTO_AUTH_SHA256_HMAC:
170                 sess->auth.algo = SHA_256;
171                 hash_oneblock_fn = mb_ops->aux.one_block.sha256;
172                 break;
173         case RTE_CRYPTO_AUTH_SHA384_HMAC:
174                 sess->auth.algo = SHA_384;
175                 hash_oneblock_fn = mb_ops->aux.one_block.sha384;
176                 break;
177         case RTE_CRYPTO_AUTH_SHA512_HMAC:
178                 sess->auth.algo = SHA_512;
179                 hash_oneblock_fn = mb_ops->aux.one_block.sha512;
180                 break;
181         default:
182                 MB_LOG_ERR("Unsupported authentication algorithm selection");
183                 return -1;
184         }
185
186         /* Calculate Authentication precomputes */
187         calculate_auth_precomputes(hash_oneblock_fn,
188                         sess->auth.pads.inner, sess->auth.pads.outer,
189                         xform->auth.key.data,
190                         xform->auth.key.length,
191                         get_auth_algo_blocksize(sess->auth.algo));
192
193         return 0;
194 }
195
196 /** Set session cipher parameters */
197 static int
198 aesni_mb_set_session_cipher_parameters(const struct aesni_mb_ops *mb_ops,
199                 struct aesni_mb_session *sess,
200                 const struct rte_crypto_xform *xform)
201 {
202         aes_keyexp_t aes_keyexp_fn;
203
204         if (xform->type != RTE_CRYPTO_XFORM_CIPHER) {
205                 MB_LOG_ERR("Crypto xform struct not of type cipher");
206                 return -1;
207         }
208
209         /* Select cipher direction */
210         switch (xform->cipher.op) {
211         case RTE_CRYPTO_CIPHER_OP_ENCRYPT:
212                 sess->cipher.direction = ENCRYPT;
213                 break;
214         case RTE_CRYPTO_CIPHER_OP_DECRYPT:
215                 sess->cipher.direction = DECRYPT;
216                 break;
217         default:
218                 MB_LOG_ERR("Unsupported cipher operation parameter");
219                 return -1;
220         }
221
222         /* Select cipher mode */
223         switch (xform->cipher.algo) {
224         case RTE_CRYPTO_CIPHER_AES_CBC:
225                 sess->cipher.mode = CBC;
226                 break;
227         default:
228                 MB_LOG_ERR("Unsupported cipher mode parameter");
229                 return -1;
230         }
231
232         /* Check key length and choose key expansion function */
233         switch (xform->cipher.key.length) {
234         case AES_128_BYTES:
235                 sess->cipher.key_length_in_bytes = AES_128_BYTES;
236                 aes_keyexp_fn = mb_ops->aux.keyexp.aes128;
237                 break;
238         case AES_192_BYTES:
239                 sess->cipher.key_length_in_bytes = AES_192_BYTES;
240                 aes_keyexp_fn = mb_ops->aux.keyexp.aes192;
241                 break;
242         case AES_256_BYTES:
243                 sess->cipher.key_length_in_bytes = AES_256_BYTES;
244                 aes_keyexp_fn = mb_ops->aux.keyexp.aes256;
245                 break;
246         default:
247                 MB_LOG_ERR("Unsupported cipher key length");
248                 return -1;
249         }
250
251         /* Expanded cipher keys */
252         (*aes_keyexp_fn)(xform->cipher.key.data,
253                         sess->cipher.expanded_aes_keys.encode,
254                         sess->cipher.expanded_aes_keys.decode);
255
256         return 0;
257 }
258
259 /** Parse crypto xform chain and set private session parameters */
260 int
261 aesni_mb_set_session_parameters(const struct aesni_mb_ops *mb_ops,
262                 struct aesni_mb_session *sess,
263                 const struct rte_crypto_xform *xform)
264 {
265         const struct rte_crypto_xform *auth_xform = NULL;
266         const struct rte_crypto_xform *cipher_xform = NULL;
267
268         /* Select Crypto operation - hash then cipher / cipher then hash */
269         switch (aesni_mb_get_chain_order(xform)) {
270         case HASH_CIPHER:
271                 sess->chain_order = HASH_CIPHER;
272                 auth_xform = xform;
273                 cipher_xform = xform->next;
274                 break;
275         case CIPHER_HASH:
276                 sess->chain_order = CIPHER_HASH;
277                 auth_xform = xform->next;
278                 cipher_xform = xform;
279                 break;
280         default:
281                 MB_LOG_ERR("Unsupported operation chain order parameter");
282                 return -1;
283         }
284
285         if (aesni_mb_set_session_auth_parameters(mb_ops, sess, auth_xform)) {
286                 MB_LOG_ERR("Invalid/unsupported authentication parameters");
287                 return -1;
288         }
289
290         if (aesni_mb_set_session_cipher_parameters(mb_ops, sess,
291                         cipher_xform)) {
292                 MB_LOG_ERR("Invalid/unsupported cipher parameters");
293                 return -1;
294         }
295         return 0;
296 }
297
298 /** Get multi buffer session */
299 static struct aesni_mb_session *
300 get_session(struct aesni_mb_qp *qp, struct rte_crypto_op *crypto_op)
301 {
302         struct aesni_mb_session *sess;
303
304         if (crypto_op->type == RTE_CRYPTO_OP_WITH_SESSION) {
305                 if (unlikely(crypto_op->session->type !=
306                                 RTE_CRYPTODEV_AESNI_MB_PMD))
307                         return NULL;
308
309                 sess = (struct aesni_mb_session *)crypto_op->session->_private;
310         } else  {
311                 struct rte_cryptodev_session *c_sess = NULL;
312
313                 if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
314                         return NULL;
315
316                 sess = (struct aesni_mb_session *)c_sess->_private;
317
318                 if (unlikely(aesni_mb_set_session_parameters(qp->ops,
319                                 sess, crypto_op->xform) != 0))
320                         return NULL;
321         }
322
323         return sess;
324 }
325
326 /**
327  * Process a crypto operation and complete a JOB_AES_HMAC job structure for
328  * submission to the multi buffer library for processing.
329  *
330  * @param       qp      queue pair
331  * @param       job     JOB_AES_HMAC structure to fill
332  * @param       m       mbuf to process
333  *
334  * @return
335  * - Completed JOB_AES_HMAC structure pointer on success
336  * - NULL pointer if completion of JOB_AES_HMAC structure isn't possible
337  */
338 static JOB_AES_HMAC *
339 process_crypto_op(struct aesni_mb_qp *qp, struct rte_mbuf *m,
340                 struct rte_crypto_op *c_op, struct aesni_mb_session *session)
341 {
342         JOB_AES_HMAC *job;
343
344         job = (*qp->ops->job.get_next)(&qp->mb_mgr);
345         if (unlikely(job == NULL))
346                 return job;
347
348         /* Set crypto operation */
349         job->chain_order = session->chain_order;
350
351         /* Set cipher parameters */
352         job->cipher_direction = session->cipher.direction;
353         job->cipher_mode = session->cipher.mode;
354
355         job->aes_key_len_in_bytes = session->cipher.key_length_in_bytes;
356         job->aes_enc_key_expanded = session->cipher.expanded_aes_keys.encode;
357         job->aes_dec_key_expanded = session->cipher.expanded_aes_keys.decode;
358
359
360         /* Set authentication parameters */
361         job->hash_alg = session->auth.algo;
362         if (job->hash_alg == AES_XCBC) {
363                 job->_k1_expanded = session->auth.xcbc.k1_expanded;
364                 job->_k2 = session->auth.xcbc.k2;
365                 job->_k3 = session->auth.xcbc.k3;
366         } else {
367                 job->hashed_auth_key_xor_ipad = session->auth.pads.inner;
368                 job->hashed_auth_key_xor_opad = session->auth.pads.outer;
369         }
370
371         /* Mutable crypto operation parameters */
372
373         /* Set digest output location */
374         if (job->cipher_direction == DECRYPT) {
375                 job->auth_tag_output = (uint8_t *)rte_pktmbuf_append(m,
376                                 get_digest_byte_length(job->hash_alg));
377
378                 if (job->auth_tag_output)
379                         memset(job->auth_tag_output, 0,
380                                 sizeof(get_digest_byte_length(job->hash_alg)));
381                 else
382                         return NULL;
383         } else {
384                 job->auth_tag_output = c_op->digest.data;
385         }
386
387         /*
388          * Multiple buffer library current only support returning a truncated
389          * digest length as specified in the relevant IPsec RFCs
390          */
391         job->auth_tag_output_len_in_bytes =
392                         get_truncated_digest_byte_length(job->hash_alg);
393
394         /* Set IV parameters */
395         job->iv = c_op->iv.data;
396         job->iv_len_in_bytes = c_op->iv.length;
397
398         /* Data  Parameter */
399         job->src = rte_pktmbuf_mtod(m, uint8_t *);
400         job->dst = c_op->dst.m ?
401                         rte_pktmbuf_mtod(c_op->dst.m, uint8_t *) +
402                         c_op->dst.offset :
403                         rte_pktmbuf_mtod(m, uint8_t *) +
404                         c_op->data.to_cipher.offset;
405
406         job->cipher_start_src_offset_in_bytes = c_op->data.to_cipher.offset;
407         job->msg_len_to_cipher_in_bytes = c_op->data.to_cipher.length;
408
409         job->hash_start_src_offset_in_bytes = c_op->data.to_hash.offset;
410         job->msg_len_to_hash_in_bytes = c_op->data.to_hash.length;
411
412         /* Set user data to be crypto operation data struct */
413         job->user_data = m;
414         job->user_data2 = c_op;
415
416         return job;
417 }
418
419 /**
420  * Process a completed job and return rte_mbuf which job processed
421  *
422  * @param job   JOB_AES_HMAC job to process
423  *
424  * @return
425  * - Returns processed mbuf which is trimmed of output digest used in
426  * verification of supplied digest in the case of a HASH_CIPHER operation
427  * - Returns NULL on invalid job
428  */
429 static struct rte_mbuf *
430 post_process_mb_job(struct aesni_mb_qp *qp, JOB_AES_HMAC *job)
431 {
432         struct rte_mbuf *m;
433         struct rte_crypto_op *c_op;
434
435         if (job->user_data == NULL)
436                 return NULL;
437
438         /* handled retrieved job */
439         m = (struct rte_mbuf *)job->user_data;
440         c_op = (struct rte_crypto_op *)job->user_data2;
441
442         /* set status as successful by default */
443         c_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
444
445         /* check if job has been processed  */
446         if (unlikely(job->status != STS_COMPLETED)) {
447                 c_op->status = RTE_CRYPTO_OP_STATUS_ERROR;
448                 return m;
449         } else if (job->chain_order == HASH_CIPHER) {
450                 /* Verify digest if required */
451                 if (memcmp(job->auth_tag_output, c_op->digest.data,
452                                 job->auth_tag_output_len_in_bytes) != 0)
453                         c_op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
454
455                 /* trim area used for digest from mbuf */
456                 rte_pktmbuf_trim(m, get_digest_byte_length(job->hash_alg));
457         }
458
459         /* Free session if a session-less crypto op */
460         if (c_op->type == RTE_CRYPTO_OP_SESSIONLESS) {
461                 rte_mempool_put(qp->sess_mp, c_op->session);
462                 c_op->session = NULL;
463         }
464
465         return m;
466 }
467
468 /**
469  * Process a completed JOB_AES_HMAC job and keep processing jobs until
470  * get_completed_job return NULL
471  *
472  * @param qp            Queue Pair to process
473  * @param job           JOB_AES_HMAC job
474  *
475  * @return
476  * - Number of processed jobs
477  */
478 static unsigned
479 handle_completed_jobs(struct aesni_mb_qp *qp, JOB_AES_HMAC *job)
480 {
481         struct rte_mbuf *m = NULL;
482         unsigned processed_jobs = 0;
483
484         while (job) {
485                 processed_jobs++;
486                 m = post_process_mb_job(qp, job);
487                 if (m)
488                         rte_ring_enqueue(qp->processed_pkts, (void *)m);
489                 else
490                         qp->qp_stats.dequeue_err_count++;
491
492                 job = (*qp->ops->job.get_completed_job)(&qp->mb_mgr);
493         }
494
495         return processed_jobs;
496 }
497
498 static uint16_t
499 aesni_mb_pmd_enqueue_burst(void *queue_pair, struct rte_mbuf **bufs,
500                 uint16_t nb_bufs)
501 {
502         struct rte_mbuf_offload *ol;
503
504         struct aesni_mb_session *sess;
505         struct aesni_mb_qp *qp = queue_pair;
506
507         JOB_AES_HMAC *job = NULL;
508
509         int i, processed_jobs = 0;
510
511         for (i = 0; i < nb_bufs; i++) {
512                 ol = rte_pktmbuf_offload_get(bufs[i], RTE_PKTMBUF_OL_CRYPTO);
513                 if (unlikely(ol == NULL)) {
514                         qp->qp_stats.enqueue_err_count++;
515                         goto flush_jobs;
516                 }
517
518                 sess = get_session(qp, &ol->op.crypto);
519                 if (unlikely(sess == NULL)) {
520                         qp->qp_stats.enqueue_err_count++;
521                         goto flush_jobs;
522                 }
523
524                 job = process_crypto_op(qp, bufs[i], &ol->op.crypto, sess);
525                 if (unlikely(job == NULL)) {
526                         qp->qp_stats.enqueue_err_count++;
527                         goto flush_jobs;
528                 }
529
530                 /* Submit Job */
531                 job = (*qp->ops->job.submit)(&qp->mb_mgr);
532
533                 /*
534                  * If submit returns a processed job then handle it,
535                  * before submitting subsequent jobs
536                  */
537                 if (job)
538                         processed_jobs += handle_completed_jobs(qp, job);
539         }
540
541         if (processed_jobs == 0)
542                 goto flush_jobs;
543         else
544                 qp->qp_stats.enqueued_count += processed_jobs;
545                 return i;
546
547 flush_jobs:
548         /*
549          * If we haven't processed any jobs in submit loop, then flush jobs
550          * queue to stop the output stalling
551          */
552         job = (*qp->ops->job.flush_job)(&qp->mb_mgr);
553         if (job)
554                 qp->qp_stats.enqueued_count += handle_completed_jobs(qp, job);
555
556         return i;
557 }
558
559 static uint16_t
560 aesni_mb_pmd_dequeue_burst(void *queue_pair,
561                 struct rte_mbuf **bufs, uint16_t nb_bufs)
562 {
563         struct aesni_mb_qp *qp = queue_pair;
564
565         unsigned nb_dequeued;
566
567         nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
568                         (void **)bufs, nb_bufs);
569         qp->qp_stats.dequeued_count += nb_dequeued;
570
571         return nb_dequeued;
572 }
573
574
575 static int cryptodev_aesni_mb_uninit(const char *name);
576
577 static int
578 cryptodev_aesni_mb_create(const char *name, unsigned socket_id)
579 {
580         struct rte_cryptodev *dev;
581         char crypto_dev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
582         struct aesni_mb_private *internals;
583         enum aesni_mb_vector_mode vector_mode;
584
585         /* Check CPU for support for AES instruction set */
586         if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
587                 MB_LOG_ERR("AES instructions not supported by CPU");
588                 return -EFAULT;
589         }
590
591         /* Check CPU for supported vector instruction set */
592         if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
593                 vector_mode = RTE_AESNI_MB_AVX2;
594         else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX))
595                 vector_mode = RTE_AESNI_MB_AVX;
596         else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_1))
597                 vector_mode = RTE_AESNI_MB_SSE;
598         else {
599                 MB_LOG_ERR("Vector instructions are not supported by CPU");
600                 return -EFAULT;
601         }
602
603         /* create a unique device name */
604         if (create_unique_device_name(crypto_dev_name,
605                         RTE_CRYPTODEV_NAME_MAX_LEN) != 0) {
606                 MB_LOG_ERR("failed to create unique cryptodev name");
607                 return -EINVAL;
608         }
609
610
611         dev = rte_cryptodev_pmd_virtual_dev_init(crypto_dev_name,
612                         sizeof(struct aesni_mb_private), socket_id);
613         if (dev == NULL) {
614                 MB_LOG_ERR("failed to create cryptodev vdev");
615                 goto init_error;
616         }
617
618         dev->dev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
619         dev->dev_ops = rte_aesni_mb_pmd_ops;
620
621         /* register rx/tx burst functions for data path */
622         dev->dequeue_burst = aesni_mb_pmd_dequeue_burst;
623         dev->enqueue_burst = aesni_mb_pmd_enqueue_burst;
624
625         /* Set vector instructions mode supported */
626         internals = dev->data->dev_private;
627
628         internals->vector_mode = vector_mode;
629         internals->max_nb_queue_pairs = RTE_AESNI_MB_PMD_MAX_NB_QUEUE_PAIRS;
630         internals->max_nb_sessions = RTE_AESNI_MB_PMD_MAX_NB_SESSIONS;
631
632         return dev->data->dev_id;
633 init_error:
634         MB_LOG_ERR("driver %s: cryptodev_aesni_create failed", name);
635
636         cryptodev_aesni_mb_uninit(crypto_dev_name);
637         return -EFAULT;
638 }
639
640
641 static int
642 cryptodev_aesni_mb_init(const char *name,
643                 const char *params __rte_unused)
644 {
645         RTE_LOG(INFO, PMD, "Initialising %s\n", name);
646
647         return cryptodev_aesni_mb_create(name, rte_socket_id());
648 }
649
650 static int
651 cryptodev_aesni_mb_uninit(const char *name)
652 {
653         if (name == NULL)
654                 return -EINVAL;
655
656         RTE_LOG(INFO, PMD, "Closing AESNI crypto device %s on numa socket %u\n",
657                         name, rte_socket_id());
658
659         return 0;
660 }
661
662 static struct rte_driver cryptodev_aesni_mb_pmd_drv = {
663         .name = CRYPTODEV_NAME_AESNI_MB_PMD,
664         .type = PMD_VDEV,
665         .init = cryptodev_aesni_mb_init,
666         .uninit = cryptodev_aesni_mb_uninit
667 };
668
669 PMD_REGISTER_DRIVER(cryptodev_aesni_mb_pmd_drv);