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