New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / crypto / aesni_mb / rte_aesni_mb_pmd.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation
3  */
4
5 #include <intel-ipsec-mb.h>
6
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_cryptodev.h>
10 #include <rte_cryptodev_pmd.h>
11 #include <rte_bus_vdev.h>
12 #include <rte_malloc.h>
13 #include <rte_cpuflags.h>
14
15 #include "rte_aesni_mb_pmd_private.h"
16
17 #define AES_CCM_DIGEST_MIN_LEN 4
18 #define AES_CCM_DIGEST_MAX_LEN 16
19 #define HMAC_MAX_BLOCK_SIZE 128
20 static uint8_t cryptodev_driver_id;
21
22 typedef void (*hash_one_block_t)(const void *data, void *digest);
23 typedef void (*aes_keyexp_t)(const void *key, void *enc_exp_keys, void *dec_exp_keys);
24
25 /**
26  * Calculate the authentication pre-computes
27  *
28  * @param one_block_hash        Function pointer to calculate digest on ipad/opad
29  * @param ipad                  Inner pad output byte array
30  * @param opad                  Outer pad output byte array
31  * @param hkey                  Authentication key
32  * @param hkey_len              Authentication key length
33  * @param blocksize             Block size of selected hash algo
34  */
35 static void
36 calculate_auth_precomputes(hash_one_block_t one_block_hash,
37                 uint8_t *ipad, uint8_t *opad,
38                 uint8_t *hkey, uint16_t hkey_len,
39                 uint16_t blocksize)
40 {
41         unsigned i, length;
42
43         uint8_t ipad_buf[blocksize] __rte_aligned(16);
44         uint8_t opad_buf[blocksize] __rte_aligned(16);
45
46         /* Setup inner and outer pads */
47         memset(ipad_buf, HMAC_IPAD_VALUE, blocksize);
48         memset(opad_buf, HMAC_OPAD_VALUE, blocksize);
49
50         /* XOR hash key with inner and outer pads */
51         length = hkey_len > blocksize ? blocksize : hkey_len;
52
53         for (i = 0; i < length; i++) {
54                 ipad_buf[i] ^= hkey[i];
55                 opad_buf[i] ^= hkey[i];
56         }
57
58         /* Compute partial hashes */
59         (*one_block_hash)(ipad_buf, ipad);
60         (*one_block_hash)(opad_buf, opad);
61
62         /* Clean up stack */
63         memset(ipad_buf, 0, blocksize);
64         memset(opad_buf, 0, blocksize);
65 }
66
67 /** Get xform chain order */
68 static enum aesni_mb_operation
69 aesni_mb_get_chain_order(const struct rte_crypto_sym_xform *xform)
70 {
71         if (xform == NULL)
72                 return AESNI_MB_OP_NOT_SUPPORTED;
73
74         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
75                 if (xform->next == NULL)
76                         return AESNI_MB_OP_CIPHER_ONLY;
77                 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH)
78                         return AESNI_MB_OP_CIPHER_HASH;
79         }
80
81         if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
82                 if (xform->next == NULL)
83                         return AESNI_MB_OP_HASH_ONLY;
84                 if (xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
85                         return AESNI_MB_OP_HASH_CIPHER;
86         }
87
88         if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
89                 if (xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM ||
90                                 xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM) {
91                         if (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
92                                 return AESNI_MB_OP_AEAD_CIPHER_HASH;
93                         else
94                                 return AESNI_MB_OP_AEAD_HASH_CIPHER;
95                 }
96         }
97
98         return AESNI_MB_OP_NOT_SUPPORTED;
99 }
100
101 /** Set session authentication parameters */
102 static int
103 aesni_mb_set_session_auth_parameters(const struct aesni_mb_op_fns *mb_ops,
104                 struct aesni_mb_session *sess,
105                 const struct rte_crypto_sym_xform *xform)
106 {
107         hash_one_block_t hash_oneblock_fn;
108         unsigned int key_larger_block_size = 0;
109         uint8_t hashed_key[HMAC_MAX_BLOCK_SIZE] = { 0 };
110
111         if (xform == NULL) {
112                 sess->auth.algo = NULL_HASH;
113                 return 0;
114         }
115
116         if (xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
117                 AESNI_MB_LOG(ERR, "Crypto xform struct not of type auth");
118                 return -1;
119         }
120
121         /* Set the request digest size */
122         sess->auth.req_digest_len = xform->auth.digest_length;
123
124         /* Select auth generate/verify */
125         sess->auth.operation = xform->auth.op;
126
127         /* Set Authentication Parameters */
128         if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
129                 sess->auth.algo = AES_XCBC;
130
131                 uint16_t xcbc_mac_digest_len =
132                         get_truncated_digest_byte_length(AES_XCBC);
133                 if (sess->auth.req_digest_len != xcbc_mac_digest_len) {
134                         AESNI_MB_LOG(ERR, "Invalid digest size\n");
135                         return -EINVAL;
136                 }
137                 sess->auth.gen_digest_len = sess->auth.req_digest_len;
138                 (*mb_ops->aux.keyexp.aes_xcbc)(xform->auth.key.data,
139                                 sess->auth.xcbc.k1_expanded,
140                                 sess->auth.xcbc.k2, sess->auth.xcbc.k3);
141                 return 0;
142         }
143
144         if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_CMAC) {
145                 sess->auth.algo = AES_CMAC;
146
147                 uint16_t cmac_digest_len = get_digest_byte_length(AES_CMAC);
148
149                 if (sess->auth.req_digest_len > cmac_digest_len) {
150                         AESNI_MB_LOG(ERR, "Invalid digest size\n");
151                         return -EINVAL;
152                 }
153                 /*
154                  * Multi-buffer lib supports digest sizes from 4 to 16 bytes
155                  * in version 0.50 and sizes of 12 and 16 bytes,
156                  * in version 0.49.
157                  * If size requested is different, generate the full digest
158                  * (16 bytes) in a temporary location and then memcpy
159                  * the requested number of bytes.
160                  */
161 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
162                 if (sess->auth.req_digest_len < 4)
163 #else
164                 uint16_t cmac_trunc_digest_len =
165                                 get_truncated_digest_byte_length(AES_CMAC);
166                 if (sess->auth.req_digest_len != cmac_digest_len &&
167                                 sess->auth.req_digest_len != cmac_trunc_digest_len)
168 #endif
169                         sess->auth.gen_digest_len = cmac_digest_len;
170                 else
171                         sess->auth.gen_digest_len = sess->auth.req_digest_len;
172                 (*mb_ops->aux.keyexp.aes_cmac_expkey)(xform->auth.key.data,
173                                 sess->auth.cmac.expkey);
174
175                 (*mb_ops->aux.keyexp.aes_cmac_subkey)(sess->auth.cmac.expkey,
176                                 sess->auth.cmac.skey1, sess->auth.cmac.skey2);
177                 return 0;
178         }
179
180         switch (xform->auth.algo) {
181         case RTE_CRYPTO_AUTH_MD5_HMAC:
182                 sess->auth.algo = MD5;
183                 hash_oneblock_fn = mb_ops->aux.one_block.md5;
184                 break;
185         case RTE_CRYPTO_AUTH_SHA1_HMAC:
186                 sess->auth.algo = SHA1;
187                 hash_oneblock_fn = mb_ops->aux.one_block.sha1;
188 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
189                 if (xform->auth.key.length > get_auth_algo_blocksize(SHA1)) {
190                         mb_ops->aux.multi_block.sha1(
191                                 xform->auth.key.data,
192                                 xform->auth.key.length,
193                                 hashed_key);
194                         key_larger_block_size = 1;
195                 }
196 #endif
197                 break;
198         case RTE_CRYPTO_AUTH_SHA224_HMAC:
199                 sess->auth.algo = SHA_224;
200                 hash_oneblock_fn = mb_ops->aux.one_block.sha224;
201 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
202                 if (xform->auth.key.length > get_auth_algo_blocksize(SHA_224)) {
203                         mb_ops->aux.multi_block.sha224(
204                                 xform->auth.key.data,
205                                 xform->auth.key.length,
206                                 hashed_key);
207                         key_larger_block_size = 1;
208                 }
209 #endif
210                 break;
211         case RTE_CRYPTO_AUTH_SHA256_HMAC:
212                 sess->auth.algo = SHA_256;
213                 hash_oneblock_fn = mb_ops->aux.one_block.sha256;
214 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
215                 if (xform->auth.key.length > get_auth_algo_blocksize(SHA_256)) {
216                         mb_ops->aux.multi_block.sha256(
217                                 xform->auth.key.data,
218                                 xform->auth.key.length,
219                                 hashed_key);
220                         key_larger_block_size = 1;
221                 }
222 #endif
223                 break;
224         case RTE_CRYPTO_AUTH_SHA384_HMAC:
225                 sess->auth.algo = SHA_384;
226                 hash_oneblock_fn = mb_ops->aux.one_block.sha384;
227 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
228                 if (xform->auth.key.length > get_auth_algo_blocksize(SHA_384)) {
229                         mb_ops->aux.multi_block.sha384(
230                                 xform->auth.key.data,
231                                 xform->auth.key.length,
232                                 hashed_key);
233                         key_larger_block_size = 1;
234                 }
235 #endif
236                 break;
237         case RTE_CRYPTO_AUTH_SHA512_HMAC:
238                 sess->auth.algo = SHA_512;
239                 hash_oneblock_fn = mb_ops->aux.one_block.sha512;
240 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
241                 if (xform->auth.key.length > get_auth_algo_blocksize(SHA_512)) {
242                         mb_ops->aux.multi_block.sha512(
243                                 xform->auth.key.data,
244                                 xform->auth.key.length,
245                                 hashed_key);
246                         key_larger_block_size = 1;
247                 }
248 #endif
249                 break;
250         default:
251                 AESNI_MB_LOG(ERR, "Unsupported authentication algorithm selection");
252                 return -ENOTSUP;
253         }
254         uint16_t trunc_digest_size =
255                         get_truncated_digest_byte_length(sess->auth.algo);
256         uint16_t full_digest_size =
257                         get_digest_byte_length(sess->auth.algo);
258
259 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
260         if (sess->auth.req_digest_len > full_digest_size ||
261                         sess->auth.req_digest_len == 0) {
262 #else
263         if (sess->auth.req_digest_len != trunc_digest_size) {
264 #endif
265                 AESNI_MB_LOG(ERR, "Invalid digest size\n");
266                 return -EINVAL;
267         }
268
269         if (sess->auth.req_digest_len != trunc_digest_size &&
270                         sess->auth.req_digest_len != full_digest_size)
271                 sess->auth.gen_digest_len = full_digest_size;
272         else
273                 sess->auth.gen_digest_len = sess->auth.req_digest_len;
274
275         /* Calculate Authentication precomputes */
276         if (key_larger_block_size) {
277                 calculate_auth_precomputes(hash_oneblock_fn,
278                         sess->auth.pads.inner, sess->auth.pads.outer,
279                         hashed_key,
280                         xform->auth.key.length,
281                         get_auth_algo_blocksize(sess->auth.algo));
282         } else {
283                 calculate_auth_precomputes(hash_oneblock_fn,
284                         sess->auth.pads.inner, sess->auth.pads.outer,
285                         xform->auth.key.data,
286                         xform->auth.key.length,
287                         get_auth_algo_blocksize(sess->auth.algo));
288         }
289
290         return 0;
291 }
292
293 /** Set session cipher parameters */
294 static int
295 aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
296                 struct aesni_mb_session *sess,
297                 const struct rte_crypto_sym_xform *xform)
298 {
299         uint8_t is_aes = 0;
300         uint8_t is_3DES = 0;
301         aes_keyexp_t aes_keyexp_fn;
302
303         if (xform == NULL) {
304                 sess->cipher.mode = NULL_CIPHER;
305                 return 0;
306         }
307
308         if (xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
309                 AESNI_MB_LOG(ERR, "Crypto xform struct not of type cipher");
310                 return -EINVAL;
311         }
312
313         /* Select cipher direction */
314         switch (xform->cipher.op) {
315         case RTE_CRYPTO_CIPHER_OP_ENCRYPT:
316                 sess->cipher.direction = ENCRYPT;
317                 break;
318         case RTE_CRYPTO_CIPHER_OP_DECRYPT:
319                 sess->cipher.direction = DECRYPT;
320                 break;
321         default:
322                 AESNI_MB_LOG(ERR, "Invalid cipher operation parameter");
323                 return -EINVAL;
324         }
325
326         /* Select cipher mode */
327         switch (xform->cipher.algo) {
328         case RTE_CRYPTO_CIPHER_AES_CBC:
329                 sess->cipher.mode = CBC;
330                 is_aes = 1;
331                 break;
332         case RTE_CRYPTO_CIPHER_AES_CTR:
333                 sess->cipher.mode = CNTR;
334                 is_aes = 1;
335                 break;
336         case RTE_CRYPTO_CIPHER_AES_DOCSISBPI:
337                 sess->cipher.mode = DOCSIS_SEC_BPI;
338                 is_aes = 1;
339                 break;
340         case RTE_CRYPTO_CIPHER_DES_CBC:
341                 sess->cipher.mode = DES;
342                 break;
343         case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
344                 sess->cipher.mode = DOCSIS_DES;
345                 break;
346         case RTE_CRYPTO_CIPHER_3DES_CBC:
347                 sess->cipher.mode = DES3;
348                 is_3DES = 1;
349                 break;
350         default:
351                 AESNI_MB_LOG(ERR, "Unsupported cipher mode parameter");
352                 return -ENOTSUP;
353         }
354
355         /* Set IV parameters */
356         sess->iv.offset = xform->cipher.iv.offset;
357         sess->iv.length = xform->cipher.iv.length;
358
359         /* Check key length and choose key expansion function for AES */
360         if (is_aes) {
361                 switch (xform->cipher.key.length) {
362                 case AES_128_BYTES:
363                         sess->cipher.key_length_in_bytes = AES_128_BYTES;
364                         aes_keyexp_fn = mb_ops->aux.keyexp.aes128;
365                         break;
366                 case AES_192_BYTES:
367                         sess->cipher.key_length_in_bytes = AES_192_BYTES;
368                         aes_keyexp_fn = mb_ops->aux.keyexp.aes192;
369                         break;
370                 case AES_256_BYTES:
371                         sess->cipher.key_length_in_bytes = AES_256_BYTES;
372                         aes_keyexp_fn = mb_ops->aux.keyexp.aes256;
373                         break;
374                 default:
375                         AESNI_MB_LOG(ERR, "Invalid cipher key length");
376                         return -EINVAL;
377                 }
378
379                 /* Expanded cipher keys */
380                 (*aes_keyexp_fn)(xform->cipher.key.data,
381                                 sess->cipher.expanded_aes_keys.encode,
382                                 sess->cipher.expanded_aes_keys.decode);
383
384         } else if (is_3DES) {
385                 uint64_t *keys[3] = {sess->cipher.exp_3des_keys.key[0],
386                                 sess->cipher.exp_3des_keys.key[1],
387                                 sess->cipher.exp_3des_keys.key[2]};
388
389                 switch (xform->cipher.key.length) {
390                 case  24:
391                         des_key_schedule(keys[0], xform->cipher.key.data);
392                         des_key_schedule(keys[1], xform->cipher.key.data+8);
393                         des_key_schedule(keys[2], xform->cipher.key.data+16);
394
395                         /* Initialize keys - 24 bytes: [K1-K2-K3] */
396                         sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
397                         sess->cipher.exp_3des_keys.ks_ptr[1] = keys[1];
398                         sess->cipher.exp_3des_keys.ks_ptr[2] = keys[2];
399                         break;
400                 case 16:
401                         des_key_schedule(keys[0], xform->cipher.key.data);
402                         des_key_schedule(keys[1], xform->cipher.key.data+8);
403
404                         /* Initialize keys - 16 bytes: [K1=K1,K2=K2,K3=K1] */
405                         sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
406                         sess->cipher.exp_3des_keys.ks_ptr[1] = keys[1];
407                         sess->cipher.exp_3des_keys.ks_ptr[2] = keys[0];
408                         break;
409                 case 8:
410                         des_key_schedule(keys[0], xform->cipher.key.data);
411
412                         /* Initialize keys - 8 bytes: [K1 = K2 = K3] */
413                         sess->cipher.exp_3des_keys.ks_ptr[0] = keys[0];
414                         sess->cipher.exp_3des_keys.ks_ptr[1] = keys[0];
415                         sess->cipher.exp_3des_keys.ks_ptr[2] = keys[0];
416                         break;
417                 default:
418                         AESNI_MB_LOG(ERR, "Invalid cipher key length");
419                         return -EINVAL;
420                 }
421
422 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
423                 sess->cipher.key_length_in_bytes = 24;
424 #else
425                 sess->cipher.key_length_in_bytes = 8;
426 #endif
427         } else {
428                 if (xform->cipher.key.length != 8) {
429                         AESNI_MB_LOG(ERR, "Invalid cipher key length");
430                         return -EINVAL;
431                 }
432                 sess->cipher.key_length_in_bytes = 8;
433
434                 des_key_schedule((uint64_t *)sess->cipher.expanded_aes_keys.encode,
435                                 xform->cipher.key.data);
436                 des_key_schedule((uint64_t *)sess->cipher.expanded_aes_keys.decode,
437                                 xform->cipher.key.data);
438         }
439
440         return 0;
441 }
442
443 static int
444 aesni_mb_set_session_aead_parameters(const struct aesni_mb_op_fns *mb_ops,
445                 struct aesni_mb_session *sess,
446                 const struct rte_crypto_sym_xform *xform)
447 {
448         union {
449                 aes_keyexp_t aes_keyexp_fn;
450                 aes_gcm_keyexp_t aes_gcm_keyexp_fn;
451         } keyexp;
452
453         switch (xform->aead.op) {
454         case RTE_CRYPTO_AEAD_OP_ENCRYPT:
455                 sess->cipher.direction = ENCRYPT;
456                 sess->auth.operation = RTE_CRYPTO_AUTH_OP_GENERATE;
457                 break;
458         case RTE_CRYPTO_AEAD_OP_DECRYPT:
459                 sess->cipher.direction = DECRYPT;
460                 sess->auth.operation = RTE_CRYPTO_AUTH_OP_VERIFY;
461                 break;
462         default:
463                 AESNI_MB_LOG(ERR, "Invalid aead operation parameter");
464                 return -EINVAL;
465         }
466
467         switch (xform->aead.algo) {
468         case RTE_CRYPTO_AEAD_AES_CCM:
469                 sess->cipher.mode = CCM;
470                 sess->auth.algo = AES_CCM;
471
472                 /* Check key length and choose key expansion function for AES */
473                 switch (xform->aead.key.length) {
474                 case AES_128_BYTES:
475                         sess->cipher.key_length_in_bytes = AES_128_BYTES;
476                         keyexp.aes_keyexp_fn = mb_ops->aux.keyexp.aes128;
477                         break;
478                 default:
479                         AESNI_MB_LOG(ERR, "Invalid cipher key length");
480                         return -EINVAL;
481                 }
482
483                 /* Expanded cipher keys */
484                 (*keyexp.aes_keyexp_fn)(xform->aead.key.data,
485                                 sess->cipher.expanded_aes_keys.encode,
486                                 sess->cipher.expanded_aes_keys.decode);
487                 break;
488
489         case RTE_CRYPTO_AEAD_AES_GCM:
490                 sess->cipher.mode = GCM;
491                 sess->auth.algo = AES_GMAC;
492
493                 switch (xform->aead.key.length) {
494                 case AES_128_BYTES:
495                         sess->cipher.key_length_in_bytes = AES_128_BYTES;
496                         keyexp.aes_gcm_keyexp_fn =
497                                         mb_ops->aux.keyexp.aes_gcm_128;
498                         break;
499                 case AES_192_BYTES:
500                         sess->cipher.key_length_in_bytes = AES_192_BYTES;
501                         keyexp.aes_gcm_keyexp_fn =
502                                         mb_ops->aux.keyexp.aes_gcm_192;
503                         break;
504                 case AES_256_BYTES:
505                         sess->cipher.key_length_in_bytes = AES_256_BYTES;
506                         keyexp.aes_gcm_keyexp_fn =
507                                         mb_ops->aux.keyexp.aes_gcm_256;
508                         break;
509                 default:
510                         AESNI_MB_LOG(ERR, "Invalid cipher key length");
511                         return -EINVAL;
512                 }
513
514                 (keyexp.aes_gcm_keyexp_fn)(xform->aead.key.data,
515                                 &sess->cipher.gcm_key);
516                 break;
517
518         default:
519                 AESNI_MB_LOG(ERR, "Unsupported aead mode parameter");
520                 return -ENOTSUP;
521         }
522
523         /* Set IV parameters */
524         sess->iv.offset = xform->aead.iv.offset;
525         sess->iv.length = xform->aead.iv.length;
526
527         sess->auth.req_digest_len = xform->aead.digest_length;
528         /* CCM digests must be between 4 and 16 and an even number */
529         if (sess->auth.req_digest_len < AES_CCM_DIGEST_MIN_LEN ||
530                         sess->auth.req_digest_len > AES_CCM_DIGEST_MAX_LEN ||
531                         (sess->auth.req_digest_len & 1) == 1) {
532                 AESNI_MB_LOG(ERR, "Invalid digest size\n");
533                 return -EINVAL;
534         }
535         sess->auth.gen_digest_len = sess->auth.req_digest_len;
536
537         return 0;
538 }
539
540 /** Parse crypto xform chain and set private session parameters */
541 int
542 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
543                 struct aesni_mb_session *sess,
544                 const struct rte_crypto_sym_xform *xform)
545 {
546         const struct rte_crypto_sym_xform *auth_xform = NULL;
547         const struct rte_crypto_sym_xform *cipher_xform = NULL;
548         const struct rte_crypto_sym_xform *aead_xform = NULL;
549         int ret;
550
551         /* Select Crypto operation - hash then cipher / cipher then hash */
552         switch (aesni_mb_get_chain_order(xform)) {
553         case AESNI_MB_OP_HASH_CIPHER:
554                 sess->chain_order = HASH_CIPHER;
555                 auth_xform = xform;
556                 cipher_xform = xform->next;
557                 break;
558         case AESNI_MB_OP_CIPHER_HASH:
559                 sess->chain_order = CIPHER_HASH;
560                 auth_xform = xform->next;
561                 cipher_xform = xform;
562                 break;
563         case AESNI_MB_OP_HASH_ONLY:
564                 sess->chain_order = HASH_CIPHER;
565                 auth_xform = xform;
566                 cipher_xform = NULL;
567                 break;
568         case AESNI_MB_OP_CIPHER_ONLY:
569                 /*
570                  * Multi buffer library operates only at two modes,
571                  * CIPHER_HASH and HASH_CIPHER. When doing ciphering only,
572                  * chain order depends on cipher operation: encryption is always
573                  * the first operation and decryption the last one.
574                  */
575                 if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
576                         sess->chain_order = CIPHER_HASH;
577                 else
578                         sess->chain_order = HASH_CIPHER;
579                 auth_xform = NULL;
580                 cipher_xform = xform;
581                 break;
582         case AESNI_MB_OP_AEAD_CIPHER_HASH:
583                 sess->chain_order = CIPHER_HASH;
584                 sess->aead.aad_len = xform->aead.aad_length;
585                 aead_xform = xform;
586                 break;
587         case AESNI_MB_OP_AEAD_HASH_CIPHER:
588                 sess->chain_order = HASH_CIPHER;
589                 sess->aead.aad_len = xform->aead.aad_length;
590                 aead_xform = xform;
591                 break;
592         case AESNI_MB_OP_NOT_SUPPORTED:
593         default:
594                 AESNI_MB_LOG(ERR, "Unsupported operation chain order parameter");
595                 return -ENOTSUP;
596         }
597
598         /* Default IV length = 0 */
599         sess->iv.length = 0;
600
601         ret = aesni_mb_set_session_auth_parameters(mb_ops, sess, auth_xform);
602         if (ret != 0) {
603                 AESNI_MB_LOG(ERR, "Invalid/unsupported authentication parameters");
604                 return ret;
605         }
606
607         ret = aesni_mb_set_session_cipher_parameters(mb_ops, sess,
608                         cipher_xform);
609         if (ret != 0) {
610                 AESNI_MB_LOG(ERR, "Invalid/unsupported cipher parameters");
611                 return ret;
612         }
613
614         if (aead_xform) {
615                 ret = aesni_mb_set_session_aead_parameters(mb_ops, sess,
616                                 aead_xform);
617                 if (ret != 0) {
618                         AESNI_MB_LOG(ERR, "Invalid/unsupported aead parameters");
619                         return ret;
620                 }
621         }
622
623         return 0;
624 }
625
626 /**
627  * burst enqueue, place crypto operations on ingress queue for processing.
628  *
629  * @param __qp         Queue Pair to process
630  * @param ops          Crypto operations for processing
631  * @param nb_ops       Number of crypto operations for processing
632  *
633  * @return
634  * - Number of crypto operations enqueued
635  */
636 static uint16_t
637 aesni_mb_pmd_enqueue_burst(void *__qp, struct rte_crypto_op **ops,
638                 uint16_t nb_ops)
639 {
640         struct aesni_mb_qp *qp = __qp;
641
642         unsigned int nb_enqueued;
643
644         nb_enqueued = rte_ring_enqueue_burst(qp->ingress_queue,
645                         (void **)ops, nb_ops, NULL);
646
647         qp->stats.enqueued_count += nb_enqueued;
648
649         return nb_enqueued;
650 }
651
652 /** Get multi buffer session */
653 static inline struct aesni_mb_session *
654 get_session(struct aesni_mb_qp *qp, struct rte_crypto_op *op)
655 {
656         struct aesni_mb_session *sess = NULL;
657
658         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
659                 if (likely(op->sym->session != NULL))
660                         sess = (struct aesni_mb_session *)
661                                         get_sym_session_private_data(
662                                         op->sym->session,
663                                         cryptodev_driver_id);
664         } else {
665                 void *_sess = NULL;
666                 void *_sess_private_data = NULL;
667
668                 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
669                         return NULL;
670
671                 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
672                         return NULL;
673
674                 sess = (struct aesni_mb_session *)_sess_private_data;
675
676                 if (unlikely(aesni_mb_set_session_parameters(qp->op_fns,
677                                 sess, op->sym->xform) != 0)) {
678                         rte_mempool_put(qp->sess_mp, _sess);
679                         rte_mempool_put(qp->sess_mp, _sess_private_data);
680                         sess = NULL;
681                 }
682                 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
683                 set_sym_session_private_data(op->sym->session,
684                                 cryptodev_driver_id, _sess_private_data);
685         }
686
687         if (unlikely(sess == NULL))
688                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
689
690         return sess;
691 }
692
693 /**
694  * Process a crypto operation and complete a JOB_AES_HMAC job structure for
695  * submission to the multi buffer library for processing.
696  *
697  * @param       qp      queue pair
698  * @param       job     JOB_AES_HMAC structure to fill
699  * @param       m       mbuf to process
700  *
701  * @return
702  * - Completed JOB_AES_HMAC structure pointer on success
703  * - NULL pointer if completion of JOB_AES_HMAC structure isn't possible
704  */
705 static inline int
706 set_mb_job_params(JOB_AES_HMAC *job, struct aesni_mb_qp *qp,
707                 struct rte_crypto_op *op, uint8_t *digest_idx)
708 {
709         struct rte_mbuf *m_src = op->sym->m_src, *m_dst;
710         struct aesni_mb_session *session;
711         uint16_t m_offset = 0;
712
713         session = get_session(qp, op);
714         if (session == NULL) {
715                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
716                 return -1;
717         }
718
719         /* Set crypto operation */
720         job->chain_order = session->chain_order;
721
722         /* Set cipher parameters */
723         job->cipher_direction = session->cipher.direction;
724         job->cipher_mode = session->cipher.mode;
725
726         job->aes_key_len_in_bytes = session->cipher.key_length_in_bytes;
727
728         /* Set authentication parameters */
729         job->hash_alg = session->auth.algo;
730
731         switch (job->hash_alg) {
732         case AES_XCBC:
733                 job->u.XCBC._k1_expanded = session->auth.xcbc.k1_expanded;
734                 job->u.XCBC._k2 = session->auth.xcbc.k2;
735                 job->u.XCBC._k3 = session->auth.xcbc.k3;
736
737                 job->aes_enc_key_expanded =
738                                 session->cipher.expanded_aes_keys.encode;
739                 job->aes_dec_key_expanded =
740                                 session->cipher.expanded_aes_keys.decode;
741                 break;
742
743         case AES_CCM:
744                 job->u.CCM.aad = op->sym->aead.aad.data + 18;
745                 job->u.CCM.aad_len_in_bytes = session->aead.aad_len;
746                 job->aes_enc_key_expanded =
747                                 session->cipher.expanded_aes_keys.encode;
748                 job->aes_dec_key_expanded =
749                                 session->cipher.expanded_aes_keys.decode;
750                 break;
751
752         case AES_CMAC:
753                 job->u.CMAC._key_expanded = session->auth.cmac.expkey;
754                 job->u.CMAC._skey1 = session->auth.cmac.skey1;
755                 job->u.CMAC._skey2 = session->auth.cmac.skey2;
756                 job->aes_enc_key_expanded =
757                                 session->cipher.expanded_aes_keys.encode;
758                 job->aes_dec_key_expanded =
759                                 session->cipher.expanded_aes_keys.decode;
760                 break;
761
762         case AES_GMAC:
763                 job->u.GCM.aad = op->sym->aead.aad.data;
764                 job->u.GCM.aad_len_in_bytes = session->aead.aad_len;
765                 job->aes_enc_key_expanded = &session->cipher.gcm_key;
766                 job->aes_dec_key_expanded = &session->cipher.gcm_key;
767                 break;
768
769         default:
770                 job->u.HMAC._hashed_auth_key_xor_ipad = session->auth.pads.inner;
771                 job->u.HMAC._hashed_auth_key_xor_opad = session->auth.pads.outer;
772
773                 if (job->cipher_mode == DES3) {
774                         job->aes_enc_key_expanded =
775                                 session->cipher.exp_3des_keys.ks_ptr;
776                         job->aes_dec_key_expanded =
777                                 session->cipher.exp_3des_keys.ks_ptr;
778                 } else {
779                         job->aes_enc_key_expanded =
780                                 session->cipher.expanded_aes_keys.encode;
781                         job->aes_dec_key_expanded =
782                                 session->cipher.expanded_aes_keys.decode;
783                 }
784         }
785
786         /* Mutable crypto operation parameters */
787         if (op->sym->m_dst) {
788                 m_src = m_dst = op->sym->m_dst;
789
790                 /* append space for output data to mbuf */
791                 char *odata = rte_pktmbuf_append(m_dst,
792                                 rte_pktmbuf_data_len(op->sym->m_src));
793                 if (odata == NULL) {
794                         AESNI_MB_LOG(ERR, "failed to allocate space in destination "
795                                         "mbuf for source data");
796                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
797                         return -1;
798                 }
799
800                 memcpy(odata, rte_pktmbuf_mtod(op->sym->m_src, void*),
801                                 rte_pktmbuf_data_len(op->sym->m_src));
802         } else {
803                 m_dst = m_src;
804                 if (job->hash_alg == AES_CCM || job->hash_alg == AES_GMAC)
805                         m_offset = op->sym->aead.data.offset;
806                 else
807                         m_offset = op->sym->cipher.data.offset;
808         }
809
810         /* Set digest output location */
811         if (job->hash_alg != NULL_HASH &&
812                         session->auth.operation == RTE_CRYPTO_AUTH_OP_VERIFY) {
813                 job->auth_tag_output = qp->temp_digests[*digest_idx];
814                 *digest_idx = (*digest_idx + 1) % MAX_JOBS;
815         } else {
816                 if (job->hash_alg == AES_CCM || job->hash_alg == AES_GMAC)
817                         job->auth_tag_output = op->sym->aead.digest.data;
818                 else
819                         job->auth_tag_output = op->sym->auth.digest.data;
820
821                 if (session->auth.req_digest_len != session->auth.gen_digest_len) {
822                         job->auth_tag_output = qp->temp_digests[*digest_idx];
823                         *digest_idx = (*digest_idx + 1) % MAX_JOBS;
824                 }
825         }
826         /*
827          * Multi-buffer library current only support returning a truncated
828          * digest length as specified in the relevant IPsec RFCs
829          */
830
831         /* Set digest length */
832         job->auth_tag_output_len_in_bytes = session->auth.gen_digest_len;
833
834         /* Set IV parameters */
835         job->iv_len_in_bytes = session->iv.length;
836
837         /* Data  Parameter */
838         job->src = rte_pktmbuf_mtod(m_src, uint8_t *);
839         job->dst = rte_pktmbuf_mtod_offset(m_dst, uint8_t *, m_offset);
840
841         switch (job->hash_alg) {
842         case AES_CCM:
843                 job->cipher_start_src_offset_in_bytes =
844                                 op->sym->aead.data.offset;
845                 job->msg_len_to_cipher_in_bytes = op->sym->aead.data.length;
846                 job->hash_start_src_offset_in_bytes = op->sym->aead.data.offset;
847                 job->msg_len_to_hash_in_bytes = op->sym->aead.data.length;
848
849                 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
850                         session->iv.offset + 1);
851                 break;
852
853         case AES_GMAC:
854                 job->cipher_start_src_offset_in_bytes =
855                                 op->sym->aead.data.offset;
856                 job->hash_start_src_offset_in_bytes = op->sym->aead.data.offset;
857                 job->msg_len_to_cipher_in_bytes = op->sym->aead.data.length;
858                 job->msg_len_to_hash_in_bytes = job->msg_len_to_cipher_in_bytes;
859                 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
860                                 session->iv.offset);
861                 break;
862
863         default:
864                 job->cipher_start_src_offset_in_bytes =
865                                 op->sym->cipher.data.offset;
866                 job->msg_len_to_cipher_in_bytes = op->sym->cipher.data.length;
867
868                 job->hash_start_src_offset_in_bytes = op->sym->auth.data.offset;
869                 job->msg_len_to_hash_in_bytes = op->sym->auth.data.length;
870
871                 job->iv = rte_crypto_op_ctod_offset(op, uint8_t *,
872                         session->iv.offset);
873         }
874
875         /* Set user data to be crypto operation data struct */
876         job->user_data = op;
877
878         return 0;
879 }
880
881 static inline void
882 verify_digest(JOB_AES_HMAC *job, struct rte_crypto_op *op,
883                 struct aesni_mb_session *sess)
884 {
885         /* Verify digest if required */
886         if (job->hash_alg == AES_CCM || job->hash_alg == AES_GMAC) {
887                 if (memcmp(job->auth_tag_output, op->sym->aead.digest.data,
888                                 sess->auth.req_digest_len) != 0)
889                         op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
890         } else {
891                 if (memcmp(job->auth_tag_output, op->sym->auth.digest.data,
892                                 sess->auth.req_digest_len) != 0)
893                         op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
894         }
895 }
896
897 static inline void
898 generate_digest(JOB_AES_HMAC *job, struct rte_crypto_op *op,
899                 struct aesni_mb_session *sess)
900 {
901         /* No extra copy neeed */
902         if (likely(sess->auth.req_digest_len == sess->auth.gen_digest_len))
903                 return;
904
905         /*
906          * This can only happen for HMAC, so only digest
907          * for authentication algos is required
908          */
909         memcpy(op->sym->auth.digest.data, job->auth_tag_output,
910                         sess->auth.req_digest_len);
911 }
912
913 /**
914  * Process a completed job and return rte_mbuf which job processed
915  *
916  * @param qp            Queue Pair to process
917  * @param job   JOB_AES_HMAC job to process
918  *
919  * @return
920  * - Returns processed crypto operation.
921  * - Returns NULL on invalid job
922  */
923 static inline struct rte_crypto_op *
924 post_process_mb_job(struct aesni_mb_qp *qp, JOB_AES_HMAC *job)
925 {
926         struct rte_crypto_op *op = (struct rte_crypto_op *)job->user_data;
927         struct aesni_mb_session *sess = get_sym_session_private_data(
928                                                         op->sym->session,
929                                                         cryptodev_driver_id);
930
931         if (likely(op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)) {
932                 switch (job->status) {
933                 case STS_COMPLETED:
934                         op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
935
936                         if (job->hash_alg != NULL_HASH) {
937                                 if (sess->auth.operation ==
938                                                 RTE_CRYPTO_AUTH_OP_VERIFY)
939                                         verify_digest(job, op, sess);
940                                 else
941                                         generate_digest(job, op, sess);
942                         }
943                         break;
944                 default:
945                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
946                 }
947         }
948
949         /* Free session if a session-less crypto op */
950         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
951                 memset(sess, 0, sizeof(struct aesni_mb_session));
952                 memset(op->sym->session, 0,
953                                 rte_cryptodev_sym_get_header_session_size());
954                 rte_mempool_put(qp->sess_mp, sess);
955                 rte_mempool_put(qp->sess_mp, op->sym->session);
956                 op->sym->session = NULL;
957         }
958
959         return op;
960 }
961
962 /**
963  * Process a completed JOB_AES_HMAC job and keep processing jobs until
964  * get_completed_job return NULL
965  *
966  * @param qp            Queue Pair to process
967  * @param job           JOB_AES_HMAC job
968  *
969  * @return
970  * - Number of processed jobs
971  */
972 static unsigned
973 handle_completed_jobs(struct aesni_mb_qp *qp, JOB_AES_HMAC *job,
974                 struct rte_crypto_op **ops, uint16_t nb_ops)
975 {
976         struct rte_crypto_op *op = NULL;
977         unsigned processed_jobs = 0;
978
979         while (job != NULL) {
980                 op = post_process_mb_job(qp, job);
981
982                 if (op) {
983                         ops[processed_jobs++] = op;
984                         qp->stats.dequeued_count++;
985                 } else {
986                         qp->stats.dequeue_err_count++;
987                         break;
988                 }
989                 if (processed_jobs == nb_ops)
990                         break;
991
992                 job = (*qp->op_fns->job.get_completed_job)(qp->mb_mgr);
993         }
994
995         return processed_jobs;
996 }
997
998 static inline uint16_t
999 flush_mb_mgr(struct aesni_mb_qp *qp, struct rte_crypto_op **ops,
1000                 uint16_t nb_ops)
1001 {
1002         int processed_ops = 0;
1003
1004         /* Flush the remaining jobs */
1005         JOB_AES_HMAC *job = (*qp->op_fns->job.flush_job)(qp->mb_mgr);
1006
1007         if (job)
1008                 processed_ops += handle_completed_jobs(qp, job,
1009                                 &ops[processed_ops], nb_ops - processed_ops);
1010
1011         return processed_ops;
1012 }
1013
1014 static inline JOB_AES_HMAC *
1015 set_job_null_op(JOB_AES_HMAC *job, struct rte_crypto_op *op)
1016 {
1017         job->chain_order = HASH_CIPHER;
1018         job->cipher_mode = NULL_CIPHER;
1019         job->hash_alg = NULL_HASH;
1020         job->cipher_direction = DECRYPT;
1021
1022         /* Set user data to be crypto operation data struct */
1023         job->user_data = op;
1024
1025         return job;
1026 }
1027
1028 static uint16_t
1029 aesni_mb_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
1030                 uint16_t nb_ops)
1031 {
1032         struct aesni_mb_qp *qp = queue_pair;
1033
1034         struct rte_crypto_op *op;
1035         JOB_AES_HMAC *job;
1036
1037         int retval, processed_jobs = 0;
1038
1039         if (unlikely(nb_ops == 0))
1040                 return 0;
1041
1042         uint8_t digest_idx = qp->digest_idx;
1043         do {
1044                 /* Get next free mb job struct from mb manager */
1045                 job = (*qp->op_fns->job.get_next)(qp->mb_mgr);
1046                 if (unlikely(job == NULL)) {
1047                         /* if no free mb job structs we need to flush mb_mgr */
1048                         processed_jobs += flush_mb_mgr(qp,
1049                                         &ops[processed_jobs],
1050                                         nb_ops - processed_jobs);
1051
1052                         if (nb_ops == processed_jobs)
1053                                 break;
1054
1055                         job = (*qp->op_fns->job.get_next)(qp->mb_mgr);
1056                 }
1057
1058                 /*
1059                  * Get next operation to process from ingress queue.
1060                  * There is no need to return the job to the MB_MGR
1061                  * if there are no more operations to process, since the MB_MGR
1062                  * can use that pointer again in next get_next calls.
1063                  */
1064                 retval = rte_ring_dequeue(qp->ingress_queue, (void **)&op);
1065                 if (retval < 0)
1066                         break;
1067
1068                 retval = set_mb_job_params(job, qp, op, &digest_idx);
1069                 if (unlikely(retval != 0)) {
1070                         qp->stats.dequeue_err_count++;
1071                         set_job_null_op(job, op);
1072                 }
1073
1074                 /* Submit job to multi-buffer for processing */
1075                 job = (*qp->op_fns->job.submit)(qp->mb_mgr);
1076
1077                 /*
1078                  * If submit returns a processed job then handle it,
1079                  * before submitting subsequent jobs
1080                  */
1081                 if (job)
1082                         processed_jobs += handle_completed_jobs(qp, job,
1083                                         &ops[processed_jobs],
1084                                         nb_ops - processed_jobs);
1085
1086         } while (processed_jobs < nb_ops);
1087
1088         qp->digest_idx = digest_idx;
1089
1090         if (processed_jobs < 1)
1091                 processed_jobs += flush_mb_mgr(qp,
1092                                 &ops[processed_jobs],
1093                                 nb_ops - processed_jobs);
1094
1095         return processed_jobs;
1096 }
1097
1098 static int cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev);
1099
1100 static int
1101 cryptodev_aesni_mb_create(const char *name,
1102                         struct rte_vdev_device *vdev,
1103                         struct rte_cryptodev_pmd_init_params *init_params)
1104 {
1105         struct rte_cryptodev *dev;
1106         struct aesni_mb_private *internals;
1107         enum aesni_mb_vector_mode vector_mode;
1108
1109         /* Check CPU for support for AES instruction set */
1110         if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AES)) {
1111                 AESNI_MB_LOG(ERR, "AES instructions not supported by CPU");
1112                 return -EFAULT;
1113         }
1114
1115         dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
1116         if (dev == NULL) {
1117                 AESNI_MB_LOG(ERR, "failed to create cryptodev vdev");
1118                 return -ENODEV;
1119         }
1120
1121         /* Check CPU for supported vector instruction set */
1122         if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F))
1123                 vector_mode = RTE_AESNI_MB_AVX512;
1124         else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2))
1125                 vector_mode = RTE_AESNI_MB_AVX2;
1126         else if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX))
1127                 vector_mode = RTE_AESNI_MB_AVX;
1128         else
1129                 vector_mode = RTE_AESNI_MB_SSE;
1130
1131         dev->driver_id = cryptodev_driver_id;
1132         dev->dev_ops = rte_aesni_mb_pmd_ops;
1133
1134         /* register rx/tx burst functions for data path */
1135         dev->dequeue_burst = aesni_mb_pmd_dequeue_burst;
1136         dev->enqueue_burst = aesni_mb_pmd_enqueue_burst;
1137
1138         dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1139                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
1140                         RTE_CRYPTODEV_FF_CPU_AESNI;
1141
1142         switch (vector_mode) {
1143         case RTE_AESNI_MB_SSE:
1144                 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_SSE;
1145                 break;
1146         case RTE_AESNI_MB_AVX:
1147                 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX;
1148                 break;
1149         case RTE_AESNI_MB_AVX2:
1150                 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX2;
1151                 break;
1152         case RTE_AESNI_MB_AVX512:
1153                 dev->feature_flags |= RTE_CRYPTODEV_FF_CPU_AVX512;
1154                 break;
1155         default:
1156                 break;
1157         }
1158
1159         /* Set vector instructions mode supported */
1160         internals = dev->data->dev_private;
1161
1162         internals->vector_mode = vector_mode;
1163         internals->max_nb_queue_pairs = init_params->max_nb_queue_pairs;
1164
1165 #if IMB_VERSION_NUM >= IMB_VERSION(0, 50, 0)
1166         AESNI_MB_LOG(INFO, "IPSec Multi-buffer library version used: %s\n",
1167                         imb_get_version_str());
1168 #else
1169         AESNI_MB_LOG(INFO, "IPSec Multi-buffer library version used: 0.49.0\n");
1170 #endif
1171
1172         return 0;
1173 }
1174
1175 static int
1176 cryptodev_aesni_mb_probe(struct rte_vdev_device *vdev)
1177 {
1178         struct rte_cryptodev_pmd_init_params init_params = {
1179                 "",
1180                 sizeof(struct aesni_mb_private),
1181                 rte_socket_id(),
1182                 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS
1183         };
1184         const char *name, *args;
1185         int retval;
1186
1187         name = rte_vdev_device_name(vdev);
1188         if (name == NULL)
1189                 return -EINVAL;
1190
1191         args = rte_vdev_device_args(vdev);
1192
1193         retval = rte_cryptodev_pmd_parse_input_args(&init_params, args);
1194         if (retval) {
1195                 AESNI_MB_LOG(ERR, "Failed to parse initialisation arguments[%s]",
1196                                 args);
1197                 return -EINVAL;
1198         }
1199
1200         return cryptodev_aesni_mb_create(name, vdev, &init_params);
1201 }
1202
1203 static int
1204 cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev)
1205 {
1206         struct rte_cryptodev *cryptodev;
1207         const char *name;
1208
1209         name = rte_vdev_device_name(vdev);
1210         if (name == NULL)
1211                 return -EINVAL;
1212
1213         cryptodev = rte_cryptodev_pmd_get_named_dev(name);
1214         if (cryptodev == NULL)
1215                 return -ENODEV;
1216
1217         return rte_cryptodev_pmd_destroy(cryptodev);
1218 }
1219
1220 static struct rte_vdev_driver cryptodev_aesni_mb_pmd_drv = {
1221         .probe = cryptodev_aesni_mb_probe,
1222         .remove = cryptodev_aesni_mb_remove
1223 };
1224
1225 static struct cryptodev_driver aesni_mb_crypto_drv;
1226
1227 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_AESNI_MB_PMD, cryptodev_aesni_mb_pmd_drv);
1228 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_AESNI_MB_PMD, cryptodev_aesni_mb_pmd);
1229 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_AESNI_MB_PMD,
1230         "max_nb_queue_pairs=<int> "
1231         "socket_id=<int>");
1232 RTE_PMD_REGISTER_CRYPTO_DRIVER(aesni_mb_crypto_drv,
1233                 cryptodev_aesni_mb_pmd_drv.driver,
1234                 cryptodev_driver_id);
1235
1236 RTE_INIT(aesni_mb_init_log)
1237 {
1238         aesni_mb_logtype_driver = rte_log_register("pmd.crypto.aesni_mb");
1239 }