Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / drivers / crypto / caam / caamalg.c
1 /*
2  * caam - Freescale FSL CAAM support for crypto API
3  *
4  * Copyright 2008-2011 Freescale Semiconductor, Inc.
5  * Copyright 2016 NXP
6  *
7  * Based on talitos crypto API driver.
8  *
9  * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
10  *
11  * ---------------                     ---------------
12  * | JobDesc #1  |-------------------->|  ShareDesc  |
13  * | *(packet 1) |                     |   (PDB)     |
14  * ---------------      |------------->|  (hashKey)  |
15  *       .              |              | (cipherKey) |
16  *       .              |    |-------->| (operation) |
17  * ---------------      |    |         ---------------
18  * | JobDesc #2  |------|    |
19  * | *(packet 2) |           |
20  * ---------------           |
21  *       .                   |
22  *       .                   |
23  * ---------------           |
24  * | JobDesc #3  |------------
25  * | *(packet 3) |
26  * ---------------
27  *
28  * The SharedDesc never changes for a connection unless rekeyed, but
29  * each packet will likely be in a different place. So all we need
30  * to know to process the packet is where the input is, where the
31  * output goes, and what context we want to process with. Context is
32  * in the SharedDesc, packet references in the JobDesc.
33  *
34  * So, a job desc looks like:
35  *
36  * ---------------------
37  * | Header            |
38  * | ShareDesc Pointer |
39  * | SEQ_OUT_PTR       |
40  * | (output buffer)   |
41  * | (output length)   |
42  * | SEQ_IN_PTR        |
43  * | (input buffer)    |
44  * | (input length)    |
45  * ---------------------
46  */
47
48 #include "compat.h"
49
50 #include "regs.h"
51 #include "intern.h"
52 #include "desc_constr.h"
53 #include "jr.h"
54 #include "error.h"
55 #include "sg_sw_sec4.h"
56 #include "key_gen.h"
57 #include "caamalg_desc.h"
58
59 /*
60  * crypto alg
61  */
62 #define CAAM_CRA_PRIORITY               3000
63 /* max key is sum of AES_MAX_KEY_SIZE, max split key size */
64 #define CAAM_MAX_KEY_SIZE               (AES_MAX_KEY_SIZE + \
65                                          CTR_RFC3686_NONCE_SIZE + \
66                                          SHA512_DIGEST_SIZE * 2)
67
68 #define AEAD_DESC_JOB_IO_LEN            (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
69 #define GCM_DESC_JOB_IO_LEN             (AEAD_DESC_JOB_IO_LEN + \
70                                          CAAM_CMD_SZ * 4)
71 #define AUTHENC_DESC_JOB_IO_LEN         (AEAD_DESC_JOB_IO_LEN + \
72                                          CAAM_CMD_SZ * 5)
73
74 #define DESC_MAX_USED_BYTES             (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN)
75 #define DESC_MAX_USED_LEN               (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
76
77 #ifdef DEBUG
78 /* for print_hex_dumps with line references */
79 #define debug(format, arg...) printk(format, arg)
80 #else
81 #define debug(format, arg...)
82 #endif
83
84 #ifdef DEBUG
85 #include <linux/highmem.h>
86
87 static void dbg_dump_sg(const char *level, const char *prefix_str,
88                         int prefix_type, int rowsize, int groupsize,
89                         struct scatterlist *sg, size_t tlen, bool ascii)
90 {
91         struct scatterlist *it;
92         void *it_page;
93         size_t len;
94         void *buf;
95
96         for (it = sg; it != NULL && tlen > 0 ; it = sg_next(sg)) {
97                 /*
98                  * make sure the scatterlist's page
99                  * has a valid virtual memory mapping
100                  */
101                 it_page = kmap_atomic(sg_page(it));
102                 if (unlikely(!it_page)) {
103                         printk(KERN_ERR "dbg_dump_sg: kmap failed\n");
104                         return;
105                 }
106
107                 buf = it_page + it->offset;
108                 len = min_t(size_t, tlen, it->length);
109                 print_hex_dump(level, prefix_str, prefix_type, rowsize,
110                                groupsize, buf, len, ascii);
111                 tlen -= len;
112
113                 kunmap_atomic(it_page);
114         }
115 }
116 #endif
117
118 static struct list_head alg_list;
119
120 struct caam_alg_entry {
121         int class1_alg_type;
122         int class2_alg_type;
123         bool rfc3686;
124         bool geniv;
125 };
126
127 struct caam_aead_alg {
128         struct aead_alg aead;
129         struct caam_alg_entry caam;
130         bool registered;
131 };
132
133 /*
134  * per-session context
135  */
136 struct caam_ctx {
137         u32 sh_desc_enc[DESC_MAX_USED_LEN];
138         u32 sh_desc_dec[DESC_MAX_USED_LEN];
139         u32 sh_desc_givenc[DESC_MAX_USED_LEN];
140         u8 key[CAAM_MAX_KEY_SIZE];
141         dma_addr_t sh_desc_enc_dma;
142         dma_addr_t sh_desc_dec_dma;
143         dma_addr_t sh_desc_givenc_dma;
144         dma_addr_t key_dma;
145         struct device *jrdev;
146         struct alginfo adata;
147         struct alginfo cdata;
148         unsigned int authsize;
149 };
150
151 static int aead_null_set_sh_desc(struct crypto_aead *aead)
152 {
153         struct caam_ctx *ctx = crypto_aead_ctx(aead);
154         struct device *jrdev = ctx->jrdev;
155         u32 *desc;
156         int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN -
157                         ctx->adata.keylen_pad;
158
159         /*
160          * Job Descriptor and Shared Descriptors
161          * must all fit into the 64-word Descriptor h/w Buffer
162          */
163         if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) {
164                 ctx->adata.key_inline = true;
165                 ctx->adata.key_virt = ctx->key;
166         } else {
167                 ctx->adata.key_inline = false;
168                 ctx->adata.key_dma = ctx->key_dma;
169         }
170
171         /* aead_encrypt shared descriptor */
172         desc = ctx->sh_desc_enc;
173         cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize);
174         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
175                                    desc_bytes(desc), DMA_TO_DEVICE);
176
177         /*
178          * Job Descriptor and Shared Descriptors
179          * must all fit into the 64-word Descriptor h/w Buffer
180          */
181         if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) {
182                 ctx->adata.key_inline = true;
183                 ctx->adata.key_virt = ctx->key;
184         } else {
185                 ctx->adata.key_inline = false;
186                 ctx->adata.key_dma = ctx->key_dma;
187         }
188
189         /* aead_decrypt shared descriptor */
190         desc = ctx->sh_desc_dec;
191         cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize);
192         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
193                                    desc_bytes(desc), DMA_TO_DEVICE);
194
195         return 0;
196 }
197
198 static int aead_set_sh_desc(struct crypto_aead *aead)
199 {
200         struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
201                                                  struct caam_aead_alg, aead);
202         unsigned int ivsize = crypto_aead_ivsize(aead);
203         struct caam_ctx *ctx = crypto_aead_ctx(aead);
204         struct device *jrdev = ctx->jrdev;
205         u32 ctx1_iv_off = 0;
206         u32 *desc, *nonce = NULL;
207         u32 inl_mask;
208         unsigned int data_len[2];
209         const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
210                                OP_ALG_AAI_CTR_MOD128);
211         const bool is_rfc3686 = alg->caam.rfc3686;
212
213         if (!ctx->authsize)
214                 return 0;
215
216         /* NULL encryption / decryption */
217         if (!ctx->cdata.keylen)
218                 return aead_null_set_sh_desc(aead);
219
220         /*
221          * AES-CTR needs to load IV in CONTEXT1 reg
222          * at an offset of 128bits (16bytes)
223          * CONTEXT1[255:128] = IV
224          */
225         if (ctr_mode)
226                 ctx1_iv_off = 16;
227
228         /*
229          * RFC3686 specific:
230          *      CONTEXT1[255:128] = {NONCE, IV, COUNTER}
231          */
232         if (is_rfc3686) {
233                 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
234                 nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
235                                 ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
236         }
237
238         data_len[0] = ctx->adata.keylen_pad;
239         data_len[1] = ctx->cdata.keylen;
240
241         if (alg->caam.geniv)
242                 goto skip_enc;
243
244         /*
245          * Job Descriptor and Shared Descriptors
246          * must all fit into the 64-word Descriptor h/w Buffer
247          */
248         if (desc_inline_query(DESC_AEAD_ENC_LEN +
249                               (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
250                               AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
251                               ARRAY_SIZE(data_len)) < 0)
252                 return -EINVAL;
253
254         if (inl_mask & 1)
255                 ctx->adata.key_virt = ctx->key;
256         else
257                 ctx->adata.key_dma = ctx->key_dma;
258
259         if (inl_mask & 2)
260                 ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
261         else
262                 ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
263
264         ctx->adata.key_inline = !!(inl_mask & 1);
265         ctx->cdata.key_inline = !!(inl_mask & 2);
266
267         /* aead_encrypt shared descriptor */
268         desc = ctx->sh_desc_enc;
269         cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize,
270                                ctx->authsize, is_rfc3686, nonce, ctx1_iv_off,
271                                false);
272         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
273                                    desc_bytes(desc), DMA_TO_DEVICE);
274
275 skip_enc:
276         /*
277          * Job Descriptor and Shared Descriptors
278          * must all fit into the 64-word Descriptor h/w Buffer
279          */
280         if (desc_inline_query(DESC_AEAD_DEC_LEN +
281                               (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
282                               AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
283                               ARRAY_SIZE(data_len)) < 0)
284                 return -EINVAL;
285
286         if (inl_mask & 1)
287                 ctx->adata.key_virt = ctx->key;
288         else
289                 ctx->adata.key_dma = ctx->key_dma;
290
291         if (inl_mask & 2)
292                 ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
293         else
294                 ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
295
296         ctx->adata.key_inline = !!(inl_mask & 1);
297         ctx->cdata.key_inline = !!(inl_mask & 2);
298
299         /* aead_decrypt shared descriptor */
300         desc = ctx->sh_desc_dec;
301         cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize,
302                                ctx->authsize, alg->caam.geniv, is_rfc3686,
303                                nonce, ctx1_iv_off, false);
304         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
305                                    desc_bytes(desc), DMA_TO_DEVICE);
306
307         if (!alg->caam.geniv)
308                 goto skip_givenc;
309
310         /*
311          * Job Descriptor and Shared Descriptors
312          * must all fit into the 64-word Descriptor h/w Buffer
313          */
314         if (desc_inline_query(DESC_AEAD_GIVENC_LEN +
315                               (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
316                               AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
317                               ARRAY_SIZE(data_len)) < 0)
318                 return -EINVAL;
319
320         if (inl_mask & 1)
321                 ctx->adata.key_virt = ctx->key;
322         else
323                 ctx->adata.key_dma = ctx->key_dma;
324
325         if (inl_mask & 2)
326                 ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
327         else
328                 ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
329
330         ctx->adata.key_inline = !!(inl_mask & 1);
331         ctx->cdata.key_inline = !!(inl_mask & 2);
332
333         /* aead_givencrypt shared descriptor */
334         desc = ctx->sh_desc_enc;
335         cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize,
336                                   ctx->authsize, is_rfc3686, nonce,
337                                   ctx1_iv_off, false);
338         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
339                                    desc_bytes(desc), DMA_TO_DEVICE);
340
341 skip_givenc:
342         return 0;
343 }
344
345 static int aead_setauthsize(struct crypto_aead *authenc,
346                                     unsigned int authsize)
347 {
348         struct caam_ctx *ctx = crypto_aead_ctx(authenc);
349
350         ctx->authsize = authsize;
351         aead_set_sh_desc(authenc);
352
353         return 0;
354 }
355
356 static int gcm_set_sh_desc(struct crypto_aead *aead)
357 {
358         struct caam_ctx *ctx = crypto_aead_ctx(aead);
359         struct device *jrdev = ctx->jrdev;
360         u32 *desc;
361         int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
362                         ctx->cdata.keylen;
363
364         if (!ctx->cdata.keylen || !ctx->authsize)
365                 return 0;
366
367         /*
368          * AES GCM encrypt shared descriptor
369          * Job Descriptor and Shared Descriptor
370          * must fit into the 64-word Descriptor h/w Buffer
371          */
372         if (rem_bytes >= DESC_GCM_ENC_LEN) {
373                 ctx->cdata.key_inline = true;
374                 ctx->cdata.key_virt = ctx->key;
375         } else {
376                 ctx->cdata.key_inline = false;
377                 ctx->cdata.key_dma = ctx->key_dma;
378         }
379
380         desc = ctx->sh_desc_enc;
381         cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ctx->authsize);
382         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
383                                    desc_bytes(desc), DMA_TO_DEVICE);
384
385         /*
386          * Job Descriptor and Shared Descriptors
387          * must all fit into the 64-word Descriptor h/w Buffer
388          */
389         if (rem_bytes >= DESC_GCM_DEC_LEN) {
390                 ctx->cdata.key_inline = true;
391                 ctx->cdata.key_virt = ctx->key;
392         } else {
393                 ctx->cdata.key_inline = false;
394                 ctx->cdata.key_dma = ctx->key_dma;
395         }
396
397         desc = ctx->sh_desc_dec;
398         cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ctx->authsize);
399         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
400                                    desc_bytes(desc), DMA_TO_DEVICE);
401
402         return 0;
403 }
404
405 static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
406 {
407         struct caam_ctx *ctx = crypto_aead_ctx(authenc);
408
409         ctx->authsize = authsize;
410         gcm_set_sh_desc(authenc);
411
412         return 0;
413 }
414
415 static int rfc4106_set_sh_desc(struct crypto_aead *aead)
416 {
417         struct caam_ctx *ctx = crypto_aead_ctx(aead);
418         struct device *jrdev = ctx->jrdev;
419         u32 *desc;
420         int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
421                         ctx->cdata.keylen;
422
423         if (!ctx->cdata.keylen || !ctx->authsize)
424                 return 0;
425
426         /*
427          * RFC4106 encrypt shared descriptor
428          * Job Descriptor and Shared Descriptor
429          * must fit into the 64-word Descriptor h/w Buffer
430          */
431         if (rem_bytes >= DESC_RFC4106_ENC_LEN) {
432                 ctx->cdata.key_inline = true;
433                 ctx->cdata.key_virt = ctx->key;
434         } else {
435                 ctx->cdata.key_inline = false;
436                 ctx->cdata.key_dma = ctx->key_dma;
437         }
438
439         desc = ctx->sh_desc_enc;
440         cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ctx->authsize);
441         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
442                                    desc_bytes(desc), DMA_TO_DEVICE);
443
444         /*
445          * Job Descriptor and Shared Descriptors
446          * must all fit into the 64-word Descriptor h/w Buffer
447          */
448         if (rem_bytes >= DESC_RFC4106_DEC_LEN) {
449                 ctx->cdata.key_inline = true;
450                 ctx->cdata.key_virt = ctx->key;
451         } else {
452                 ctx->cdata.key_inline = false;
453                 ctx->cdata.key_dma = ctx->key_dma;
454         }
455
456         desc = ctx->sh_desc_dec;
457         cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ctx->authsize);
458         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
459                                    desc_bytes(desc), DMA_TO_DEVICE);
460
461         return 0;
462 }
463
464 static int rfc4106_setauthsize(struct crypto_aead *authenc,
465                                unsigned int authsize)
466 {
467         struct caam_ctx *ctx = crypto_aead_ctx(authenc);
468
469         ctx->authsize = authsize;
470         rfc4106_set_sh_desc(authenc);
471
472         return 0;
473 }
474
475 static int rfc4543_set_sh_desc(struct crypto_aead *aead)
476 {
477         struct caam_ctx *ctx = crypto_aead_ctx(aead);
478         struct device *jrdev = ctx->jrdev;
479         u32 *desc;
480         int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
481                         ctx->cdata.keylen;
482
483         if (!ctx->cdata.keylen || !ctx->authsize)
484                 return 0;
485
486         /*
487          * RFC4543 encrypt shared descriptor
488          * Job Descriptor and Shared Descriptor
489          * must fit into the 64-word Descriptor h/w Buffer
490          */
491         if (rem_bytes >= DESC_RFC4543_ENC_LEN) {
492                 ctx->cdata.key_inline = true;
493                 ctx->cdata.key_virt = ctx->key;
494         } else {
495                 ctx->cdata.key_inline = false;
496                 ctx->cdata.key_dma = ctx->key_dma;
497         }
498
499         desc = ctx->sh_desc_enc;
500         cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ctx->authsize);
501         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
502                                    desc_bytes(desc), DMA_TO_DEVICE);
503
504         /*
505          * Job Descriptor and Shared Descriptors
506          * must all fit into the 64-word Descriptor h/w Buffer
507          */
508         if (rem_bytes >= DESC_RFC4543_DEC_LEN) {
509                 ctx->cdata.key_inline = true;
510                 ctx->cdata.key_virt = ctx->key;
511         } else {
512                 ctx->cdata.key_inline = false;
513                 ctx->cdata.key_dma = ctx->key_dma;
514         }
515
516         desc = ctx->sh_desc_dec;
517         cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ctx->authsize);
518         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
519                                    desc_bytes(desc), DMA_TO_DEVICE);
520
521         return 0;
522 }
523
524 static int rfc4543_setauthsize(struct crypto_aead *authenc,
525                                unsigned int authsize)
526 {
527         struct caam_ctx *ctx = crypto_aead_ctx(authenc);
528
529         ctx->authsize = authsize;
530         rfc4543_set_sh_desc(authenc);
531
532         return 0;
533 }
534
535 static int aead_setkey(struct crypto_aead *aead,
536                                const u8 *key, unsigned int keylen)
537 {
538         struct caam_ctx *ctx = crypto_aead_ctx(aead);
539         struct device *jrdev = ctx->jrdev;
540         struct crypto_authenc_keys keys;
541         int ret = 0;
542
543         if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
544                 goto badkey;
545
546 #ifdef DEBUG
547         printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n",
548                keys.authkeylen + keys.enckeylen, keys.enckeylen,
549                keys.authkeylen);
550         print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
551                        DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
552 #endif
553
554         ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey,
555                             keys.authkeylen, CAAM_MAX_KEY_SIZE -
556                             keys.enckeylen);
557         if (ret) {
558                 goto badkey;
559         }
560
561         /* postpend encryption key to auth split key */
562         memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
563         dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
564                                    keys.enckeylen, DMA_TO_DEVICE);
565 #ifdef DEBUG
566         print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
567                        DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
568                        ctx->adata.keylen_pad + keys.enckeylen, 1);
569 #endif
570         ctx->cdata.keylen = keys.enckeylen;
571         return aead_set_sh_desc(aead);
572 badkey:
573         crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
574         return -EINVAL;
575 }
576
577 static int gcm_setkey(struct crypto_aead *aead,
578                       const u8 *key, unsigned int keylen)
579 {
580         struct caam_ctx *ctx = crypto_aead_ctx(aead);
581         struct device *jrdev = ctx->jrdev;
582
583 #ifdef DEBUG
584         print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
585                        DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
586 #endif
587
588         memcpy(ctx->key, key, keylen);
589         dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
590         ctx->cdata.keylen = keylen;
591
592         return gcm_set_sh_desc(aead);
593 }
594
595 static int rfc4106_setkey(struct crypto_aead *aead,
596                           const u8 *key, unsigned int keylen)
597 {
598         struct caam_ctx *ctx = crypto_aead_ctx(aead);
599         struct device *jrdev = ctx->jrdev;
600
601         if (keylen < 4)
602                 return -EINVAL;
603
604 #ifdef DEBUG
605         print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
606                        DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
607 #endif
608
609         memcpy(ctx->key, key, keylen);
610
611         /*
612          * The last four bytes of the key material are used as the salt value
613          * in the nonce. Update the AES key length.
614          */
615         ctx->cdata.keylen = keylen - 4;
616         dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
617                                    DMA_TO_DEVICE);
618         return rfc4106_set_sh_desc(aead);
619 }
620
621 static int rfc4543_setkey(struct crypto_aead *aead,
622                           const u8 *key, unsigned int keylen)
623 {
624         struct caam_ctx *ctx = crypto_aead_ctx(aead);
625         struct device *jrdev = ctx->jrdev;
626
627         if (keylen < 4)
628                 return -EINVAL;
629
630 #ifdef DEBUG
631         print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
632                        DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
633 #endif
634
635         memcpy(ctx->key, key, keylen);
636
637         /*
638          * The last four bytes of the key material are used as the salt value
639          * in the nonce. Update the AES key length.
640          */
641         ctx->cdata.keylen = keylen - 4;
642         dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
643                                    DMA_TO_DEVICE);
644         return rfc4543_set_sh_desc(aead);
645 }
646
647 static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
648                              const u8 *key, unsigned int keylen)
649 {
650         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
651         struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
652         const char *alg_name = crypto_tfm_alg_name(tfm);
653         struct device *jrdev = ctx->jrdev;
654         unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
655         u32 *desc;
656         u32 ctx1_iv_off = 0;
657         const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
658                                OP_ALG_AAI_CTR_MOD128);
659         const bool is_rfc3686 = (ctr_mode &&
660                                  (strstr(alg_name, "rfc3686") != NULL));
661
662         memcpy(ctx->key, key, keylen);
663 #ifdef DEBUG
664         print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
665                        DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
666 #endif
667         /*
668          * AES-CTR needs to load IV in CONTEXT1 reg
669          * at an offset of 128bits (16bytes)
670          * CONTEXT1[255:128] = IV
671          */
672         if (ctr_mode)
673                 ctx1_iv_off = 16;
674
675         /*
676          * RFC3686 specific:
677          *      | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
678          *      | *key = {KEY, NONCE}
679          */
680         if (is_rfc3686) {
681                 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
682                 keylen -= CTR_RFC3686_NONCE_SIZE;
683         }
684
685         dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
686         ctx->cdata.keylen = keylen;
687         ctx->cdata.key_virt = ctx->key;
688         ctx->cdata.key_inline = true;
689
690         /* ablkcipher_encrypt shared descriptor */
691         desc = ctx->sh_desc_enc;
692         cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
693                                      ctx1_iv_off);
694         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
695                                    desc_bytes(desc), DMA_TO_DEVICE);
696
697         /* ablkcipher_decrypt shared descriptor */
698         desc = ctx->sh_desc_dec;
699         cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
700                                      ctx1_iv_off);
701         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
702                                    desc_bytes(desc), DMA_TO_DEVICE);
703
704         /* ablkcipher_givencrypt shared descriptor */
705         desc = ctx->sh_desc_givenc;
706         cnstr_shdsc_ablkcipher_givencap(desc, &ctx->cdata, ivsize, is_rfc3686,
707                                         ctx1_iv_off);
708         dma_sync_single_for_device(jrdev, ctx->sh_desc_givenc_dma,
709                                    desc_bytes(desc), DMA_TO_DEVICE);
710
711         return 0;
712 }
713
714 static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
715                                  const u8 *key, unsigned int keylen)
716 {
717         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
718         struct device *jrdev = ctx->jrdev;
719         u32 *desc;
720
721         if (keylen != 2 * AES_MIN_KEY_SIZE  && keylen != 2 * AES_MAX_KEY_SIZE) {
722                 crypto_ablkcipher_set_flags(ablkcipher,
723                                             CRYPTO_TFM_RES_BAD_KEY_LEN);
724                 dev_err(jrdev, "key size mismatch\n");
725                 return -EINVAL;
726         }
727
728         memcpy(ctx->key, key, keylen);
729         dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, DMA_TO_DEVICE);
730         ctx->cdata.keylen = keylen;
731         ctx->cdata.key_virt = ctx->key;
732         ctx->cdata.key_inline = true;
733
734         /* xts_ablkcipher_encrypt shared descriptor */
735         desc = ctx->sh_desc_enc;
736         cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata);
737         dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
738                                    desc_bytes(desc), DMA_TO_DEVICE);
739
740         /* xts_ablkcipher_decrypt shared descriptor */
741         desc = ctx->sh_desc_dec;
742         cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata);
743         dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
744                                    desc_bytes(desc), DMA_TO_DEVICE);
745
746         return 0;
747 }
748
749 /*
750  * aead_edesc - s/w-extended aead descriptor
751  * @src_nents: number of segments in input s/w scatterlist
752  * @dst_nents: number of segments in output s/w scatterlist
753  * @sec4_sg_bytes: length of dma mapped sec4_sg space
754  * @sec4_sg_dma: bus physical mapped address of h/w link table
755  * @sec4_sg: pointer to h/w link table
756  * @hw_desc: the h/w job descriptor followed by any referenced link tables
757  */
758 struct aead_edesc {
759         int src_nents;
760         int dst_nents;
761         int sec4_sg_bytes;
762         dma_addr_t sec4_sg_dma;
763         struct sec4_sg_entry *sec4_sg;
764         u32 hw_desc[];
765 };
766
767 /*
768  * ablkcipher_edesc - s/w-extended ablkcipher descriptor
769  * @src_nents: number of segments in input s/w scatterlist
770  * @dst_nents: number of segments in output s/w scatterlist
771  * @iv_dma: dma address of iv for checking continuity and link table
772  * @sec4_sg_bytes: length of dma mapped sec4_sg space
773  * @sec4_sg_dma: bus physical mapped address of h/w link table
774  * @sec4_sg: pointer to h/w link table
775  * @hw_desc: the h/w job descriptor followed by any referenced link tables
776  */
777 struct ablkcipher_edesc {
778         int src_nents;
779         int dst_nents;
780         dma_addr_t iv_dma;
781         int sec4_sg_bytes;
782         dma_addr_t sec4_sg_dma;
783         struct sec4_sg_entry *sec4_sg;
784         u32 hw_desc[0];
785 };
786
787 static void caam_unmap(struct device *dev, struct scatterlist *src,
788                        struct scatterlist *dst, int src_nents,
789                        int dst_nents,
790                        dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
791                        int sec4_sg_bytes)
792 {
793         if (dst != src) {
794                 if (src_nents)
795                         dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
796                 dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
797         } else {
798                 dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
799         }
800
801         if (iv_dma)
802                 dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
803         if (sec4_sg_bytes)
804                 dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
805                                  DMA_TO_DEVICE);
806 }
807
808 static void aead_unmap(struct device *dev,
809                        struct aead_edesc *edesc,
810                        struct aead_request *req)
811 {
812         caam_unmap(dev, req->src, req->dst,
813                    edesc->src_nents, edesc->dst_nents, 0, 0,
814                    edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
815 }
816
817 static void ablkcipher_unmap(struct device *dev,
818                              struct ablkcipher_edesc *edesc,
819                              struct ablkcipher_request *req)
820 {
821         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
822         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
823
824         caam_unmap(dev, req->src, req->dst,
825                    edesc->src_nents, edesc->dst_nents,
826                    edesc->iv_dma, ivsize,
827                    edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
828 }
829
830 static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
831                                    void *context)
832 {
833         struct aead_request *req = context;
834         struct aead_edesc *edesc;
835
836 #ifdef DEBUG
837         dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
838 #endif
839
840         edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
841
842         if (err)
843                 caam_jr_strstatus(jrdev, err);
844
845         aead_unmap(jrdev, edesc, req);
846
847         kfree(edesc);
848
849         aead_request_complete(req, err);
850 }
851
852 static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
853                                    void *context)
854 {
855         struct aead_request *req = context;
856         struct aead_edesc *edesc;
857
858 #ifdef DEBUG
859         dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
860 #endif
861
862         edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
863
864         if (err)
865                 caam_jr_strstatus(jrdev, err);
866
867         aead_unmap(jrdev, edesc, req);
868
869         /*
870          * verify hw auth check passed else return -EBADMSG
871          */
872         if ((err & JRSTA_CCBERR_ERRID_MASK) == JRSTA_CCBERR_ERRID_ICVCHK)
873                 err = -EBADMSG;
874
875         kfree(edesc);
876
877         aead_request_complete(req, err);
878 }
879
880 static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
881                                    void *context)
882 {
883         struct ablkcipher_request *req = context;
884         struct ablkcipher_edesc *edesc;
885         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
886         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
887
888 #ifdef DEBUG
889         dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
890 #endif
891
892         edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
893
894         if (err)
895                 caam_jr_strstatus(jrdev, err);
896
897 #ifdef DEBUG
898         print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
899                        DUMP_PREFIX_ADDRESS, 16, 4, req->info,
900                        edesc->src_nents > 1 ? 100 : ivsize, 1);
901         dbg_dump_sg(KERN_ERR, "dst    @"__stringify(__LINE__)": ",
902                     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
903                     edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
904 #endif
905
906         ablkcipher_unmap(jrdev, edesc, req);
907
908         /*
909          * The crypto API expects us to set the IV (req->info) to the last
910          * ciphertext block. This is used e.g. by the CTS mode.
911          */
912         scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
913                                  ivsize, 0);
914
915         kfree(edesc);
916
917         ablkcipher_request_complete(req, err);
918 }
919
920 static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
921                                     void *context)
922 {
923         struct ablkcipher_request *req = context;
924         struct ablkcipher_edesc *edesc;
925         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
926         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
927
928 #ifdef DEBUG
929         dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
930 #endif
931
932         edesc = container_of(desc, struct ablkcipher_edesc, hw_desc[0]);
933         if (err)
934                 caam_jr_strstatus(jrdev, err);
935
936 #ifdef DEBUG
937         print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
938                        DUMP_PREFIX_ADDRESS, 16, 4, req->info,
939                        ivsize, 1);
940         dbg_dump_sg(KERN_ERR, "dst    @"__stringify(__LINE__)": ",
941                     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
942                     edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
943 #endif
944
945         ablkcipher_unmap(jrdev, edesc, req);
946
947         /*
948          * The crypto API expects us to set the IV (req->info) to the last
949          * ciphertext block.
950          */
951         scatterwalk_map_and_copy(req->info, req->src, req->nbytes - ivsize,
952                                  ivsize, 0);
953
954         kfree(edesc);
955
956         ablkcipher_request_complete(req, err);
957 }
958
959 /*
960  * Fill in aead job descriptor
961  */
962 static void init_aead_job(struct aead_request *req,
963                           struct aead_edesc *edesc,
964                           bool all_contig, bool encrypt)
965 {
966         struct crypto_aead *aead = crypto_aead_reqtfm(req);
967         struct caam_ctx *ctx = crypto_aead_ctx(aead);
968         int authsize = ctx->authsize;
969         u32 *desc = edesc->hw_desc;
970         u32 out_options, in_options;
971         dma_addr_t dst_dma, src_dma;
972         int len, sec4_sg_index = 0;
973         dma_addr_t ptr;
974         u32 *sh_desc;
975
976         sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
977         ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
978
979         len = desc_len(sh_desc);
980         init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
981
982         if (all_contig) {
983                 src_dma = edesc->src_nents ? sg_dma_address(req->src) : 0;
984                 in_options = 0;
985         } else {
986                 src_dma = edesc->sec4_sg_dma;
987                 sec4_sg_index += edesc->src_nents;
988                 in_options = LDST_SGF;
989         }
990
991         append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
992                           in_options);
993
994         dst_dma = src_dma;
995         out_options = in_options;
996
997         if (unlikely(req->src != req->dst)) {
998                 if (edesc->dst_nents == 1) {
999                         dst_dma = sg_dma_address(req->dst);
1000                 } else {
1001                         dst_dma = edesc->sec4_sg_dma +
1002                                   sec4_sg_index *
1003                                   sizeof(struct sec4_sg_entry);
1004                         out_options = LDST_SGF;
1005                 }
1006         }
1007
1008         if (encrypt)
1009                 append_seq_out_ptr(desc, dst_dma,
1010                                    req->assoclen + req->cryptlen + authsize,
1011                                    out_options);
1012         else
1013                 append_seq_out_ptr(desc, dst_dma,
1014                                    req->assoclen + req->cryptlen - authsize,
1015                                    out_options);
1016
1017         /* REG3 = assoclen */
1018         append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
1019 }
1020
1021 static void init_gcm_job(struct aead_request *req,
1022                          struct aead_edesc *edesc,
1023                          bool all_contig, bool encrypt)
1024 {
1025         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1026         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1027         unsigned int ivsize = crypto_aead_ivsize(aead);
1028         u32 *desc = edesc->hw_desc;
1029         bool generic_gcm = (ivsize == 12);
1030         unsigned int last;
1031
1032         init_aead_job(req, edesc, all_contig, encrypt);
1033
1034         /* BUG This should not be specific to generic GCM. */
1035         last = 0;
1036         if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
1037                 last = FIFOLD_TYPE_LAST1;
1038
1039         /* Read GCM IV */
1040         append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
1041                          FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last);
1042         /* Append Salt */
1043         if (!generic_gcm)
1044                 append_data(desc, ctx->key + ctx->cdata.keylen, 4);
1045         /* Append IV */
1046         append_data(desc, req->iv, ivsize);
1047         /* End of blank commands */
1048 }
1049
1050 static void init_authenc_job(struct aead_request *req,
1051                              struct aead_edesc *edesc,
1052                              bool all_contig, bool encrypt)
1053 {
1054         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1055         struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
1056                                                  struct caam_aead_alg, aead);
1057         unsigned int ivsize = crypto_aead_ivsize(aead);
1058         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1059         const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
1060                                OP_ALG_AAI_CTR_MOD128);
1061         const bool is_rfc3686 = alg->caam.rfc3686;
1062         u32 *desc = edesc->hw_desc;
1063         u32 ivoffset = 0;
1064
1065         /*
1066          * AES-CTR needs to load IV in CONTEXT1 reg
1067          * at an offset of 128bits (16bytes)
1068          * CONTEXT1[255:128] = IV
1069          */
1070         if (ctr_mode)
1071                 ivoffset = 16;
1072
1073         /*
1074          * RFC3686 specific:
1075          *      CONTEXT1[255:128] = {NONCE, IV, COUNTER}
1076          */
1077         if (is_rfc3686)
1078                 ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
1079
1080         init_aead_job(req, edesc, all_contig, encrypt);
1081
1082         if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv))
1083                 append_load_as_imm(desc, req->iv, ivsize,
1084                                    LDST_CLASS_1_CCB |
1085                                    LDST_SRCDST_BYTE_CONTEXT |
1086                                    (ivoffset << LDST_OFFSET_SHIFT));
1087 }
1088
1089 /*
1090  * Fill in ablkcipher job descriptor
1091  */
1092 static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
1093                                 struct ablkcipher_edesc *edesc,
1094                                 struct ablkcipher_request *req,
1095                                 bool iv_contig)
1096 {
1097         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1098         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1099         u32 *desc = edesc->hw_desc;
1100         u32 out_options = 0, in_options;
1101         dma_addr_t dst_dma, src_dma;
1102         int len, sec4_sg_index = 0;
1103
1104 #ifdef DEBUG
1105         print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
1106                        DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1107                        ivsize, 1);
1108         pr_err("asked=%d, nbytes%d\n",
1109                (int)edesc->src_nents > 1 ? 100 : req->nbytes, req->nbytes);
1110         dbg_dump_sg(KERN_ERR, "src    @"__stringify(__LINE__)": ",
1111                     DUMP_PREFIX_ADDRESS, 16, 4, req->src,
1112                     edesc->src_nents > 1 ? 100 : req->nbytes, 1);
1113 #endif
1114
1115         len = desc_len(sh_desc);
1116         init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1117
1118         if (iv_contig) {
1119                 src_dma = edesc->iv_dma;
1120                 in_options = 0;
1121         } else {
1122                 src_dma = edesc->sec4_sg_dma;
1123                 sec4_sg_index += edesc->src_nents + 1;
1124                 in_options = LDST_SGF;
1125         }
1126         append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options);
1127
1128         if (likely(req->src == req->dst)) {
1129                 if (edesc->src_nents == 1 && iv_contig) {
1130                         dst_dma = sg_dma_address(req->src);
1131                 } else {
1132                         dst_dma = edesc->sec4_sg_dma +
1133                                 sizeof(struct sec4_sg_entry);
1134                         out_options = LDST_SGF;
1135                 }
1136         } else {
1137                 if (edesc->dst_nents == 1) {
1138                         dst_dma = sg_dma_address(req->dst);
1139                 } else {
1140                         dst_dma = edesc->sec4_sg_dma +
1141                                 sec4_sg_index * sizeof(struct sec4_sg_entry);
1142                         out_options = LDST_SGF;
1143                 }
1144         }
1145         append_seq_out_ptr(desc, dst_dma, req->nbytes, out_options);
1146 }
1147
1148 /*
1149  * Fill in ablkcipher givencrypt job descriptor
1150  */
1151 static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
1152                                     struct ablkcipher_edesc *edesc,
1153                                     struct ablkcipher_request *req,
1154                                     bool iv_contig)
1155 {
1156         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1157         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1158         u32 *desc = edesc->hw_desc;
1159         u32 out_options, in_options;
1160         dma_addr_t dst_dma, src_dma;
1161         int len, sec4_sg_index = 0;
1162
1163 #ifdef DEBUG
1164         print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
1165                        DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1166                        ivsize, 1);
1167         dbg_dump_sg(KERN_ERR, "src    @" __stringify(__LINE__) ": ",
1168                     DUMP_PREFIX_ADDRESS, 16, 4, req->src,
1169                     edesc->src_nents > 1 ? 100 : req->nbytes, 1);
1170 #endif
1171
1172         len = desc_len(sh_desc);
1173         init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1174
1175         if (edesc->src_nents == 1) {
1176                 src_dma = sg_dma_address(req->src);
1177                 in_options = 0;
1178         } else {
1179                 src_dma = edesc->sec4_sg_dma;
1180                 sec4_sg_index += edesc->src_nents;
1181                 in_options = LDST_SGF;
1182         }
1183         append_seq_in_ptr(desc, src_dma, req->nbytes, in_options);
1184
1185         if (iv_contig) {
1186                 dst_dma = edesc->iv_dma;
1187                 out_options = 0;
1188         } else {
1189                 dst_dma = edesc->sec4_sg_dma +
1190                           sec4_sg_index * sizeof(struct sec4_sg_entry);
1191                 out_options = LDST_SGF;
1192         }
1193         append_seq_out_ptr(desc, dst_dma, req->nbytes + ivsize, out_options);
1194 }
1195
1196 /*
1197  * allocate and map the aead extended descriptor
1198  */
1199 static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
1200                                            int desc_bytes, bool *all_contig_ptr,
1201                                            bool encrypt)
1202 {
1203         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1204         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1205         struct device *jrdev = ctx->jrdev;
1206         gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
1207                        GFP_KERNEL : GFP_ATOMIC;
1208         int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
1209         struct aead_edesc *edesc;
1210         int sec4_sg_index, sec4_sg_len, sec4_sg_bytes;
1211         unsigned int authsize = ctx->authsize;
1212
1213         if (unlikely(req->dst != req->src)) {
1214                 src_nents = sg_nents_for_len(req->src, req->assoclen +
1215                                              req->cryptlen);
1216                 if (unlikely(src_nents < 0)) {
1217                         dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
1218                                 req->assoclen + req->cryptlen);
1219                         return ERR_PTR(src_nents);
1220                 }
1221
1222                 dst_nents = sg_nents_for_len(req->dst, req->assoclen +
1223                                              req->cryptlen +
1224                                                 (encrypt ? authsize :
1225                                                            (-authsize)));
1226                 if (unlikely(dst_nents < 0)) {
1227                         dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
1228                                 req->assoclen + req->cryptlen +
1229                                 (encrypt ? authsize : (-authsize)));
1230                         return ERR_PTR(dst_nents);
1231                 }
1232         } else {
1233                 src_nents = sg_nents_for_len(req->src, req->assoclen +
1234                                              req->cryptlen +
1235                                              (encrypt ? authsize : 0));
1236                 if (unlikely(src_nents < 0)) {
1237                         dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
1238                                 req->assoclen + req->cryptlen +
1239                                 (encrypt ? authsize : 0));
1240                         return ERR_PTR(src_nents);
1241                 }
1242         }
1243
1244         if (likely(req->src == req->dst)) {
1245                 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1246                                               DMA_BIDIRECTIONAL);
1247                 if (unlikely(!mapped_src_nents)) {
1248                         dev_err(jrdev, "unable to map source\n");
1249                         return ERR_PTR(-ENOMEM);
1250                 }
1251         } else {
1252                 /* Cover also the case of null (zero length) input data */
1253                 if (src_nents) {
1254                         mapped_src_nents = dma_map_sg(jrdev, req->src,
1255                                                       src_nents, DMA_TO_DEVICE);
1256                         if (unlikely(!mapped_src_nents)) {
1257                                 dev_err(jrdev, "unable to map source\n");
1258                                 return ERR_PTR(-ENOMEM);
1259                         }
1260                 } else {
1261                         mapped_src_nents = 0;
1262                 }
1263
1264                 mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
1265                                               DMA_FROM_DEVICE);
1266                 if (unlikely(!mapped_dst_nents)) {
1267                         dev_err(jrdev, "unable to map destination\n");
1268                         dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
1269                         return ERR_PTR(-ENOMEM);
1270                 }
1271         }
1272
1273         sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
1274         sec4_sg_len += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
1275         sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
1276
1277         /* allocate space for base edesc and hw desc commands, link tables */
1278         edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
1279                         GFP_DMA | flags);
1280         if (!edesc) {
1281                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
1282                            0, 0, 0);
1283                 return ERR_PTR(-ENOMEM);
1284         }
1285
1286         edesc->src_nents = src_nents;
1287         edesc->dst_nents = dst_nents;
1288         edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
1289                          desc_bytes;
1290         *all_contig_ptr = !(mapped_src_nents > 1);
1291
1292         sec4_sg_index = 0;
1293         if (mapped_src_nents > 1) {
1294                 sg_to_sec4_sg_last(req->src, mapped_src_nents,
1295                                    edesc->sec4_sg + sec4_sg_index, 0);
1296                 sec4_sg_index += mapped_src_nents;
1297         }
1298         if (mapped_dst_nents > 1) {
1299                 sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
1300                                    edesc->sec4_sg + sec4_sg_index, 0);
1301         }
1302
1303         if (!sec4_sg_bytes)
1304                 return edesc;
1305
1306         edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
1307                                             sec4_sg_bytes, DMA_TO_DEVICE);
1308         if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
1309                 dev_err(jrdev, "unable to map S/G table\n");
1310                 aead_unmap(jrdev, edesc, req);
1311                 kfree(edesc);
1312                 return ERR_PTR(-ENOMEM);
1313         }
1314
1315         edesc->sec4_sg_bytes = sec4_sg_bytes;
1316
1317         return edesc;
1318 }
1319
1320 static int gcm_encrypt(struct aead_request *req)
1321 {
1322         struct aead_edesc *edesc;
1323         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1324         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1325         struct device *jrdev = ctx->jrdev;
1326         bool all_contig;
1327         u32 *desc;
1328         int ret = 0;
1329
1330         /* allocate extended descriptor */
1331         edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true);
1332         if (IS_ERR(edesc))
1333                 return PTR_ERR(edesc);
1334
1335         /* Create and submit job descriptor */
1336         init_gcm_job(req, edesc, all_contig, true);
1337 #ifdef DEBUG
1338         print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1339                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1340                        desc_bytes(edesc->hw_desc), 1);
1341 #endif
1342
1343         desc = edesc->hw_desc;
1344         ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
1345         if (!ret) {
1346                 ret = -EINPROGRESS;
1347         } else {
1348                 aead_unmap(jrdev, edesc, req);
1349                 kfree(edesc);
1350         }
1351
1352         return ret;
1353 }
1354
1355 static int ipsec_gcm_encrypt(struct aead_request *req)
1356 {
1357         if (req->assoclen < 8)
1358                 return -EINVAL;
1359
1360         return gcm_encrypt(req);
1361 }
1362
1363 static int aead_encrypt(struct aead_request *req)
1364 {
1365         struct aead_edesc *edesc;
1366         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1367         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1368         struct device *jrdev = ctx->jrdev;
1369         bool all_contig;
1370         u32 *desc;
1371         int ret = 0;
1372
1373         /* allocate extended descriptor */
1374         edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
1375                                  &all_contig, true);
1376         if (IS_ERR(edesc))
1377                 return PTR_ERR(edesc);
1378
1379         /* Create and submit job descriptor */
1380         init_authenc_job(req, edesc, all_contig, true);
1381 #ifdef DEBUG
1382         print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1383                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1384                        desc_bytes(edesc->hw_desc), 1);
1385 #endif
1386
1387         desc = edesc->hw_desc;
1388         ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
1389         if (!ret) {
1390                 ret = -EINPROGRESS;
1391         } else {
1392                 aead_unmap(jrdev, edesc, req);
1393                 kfree(edesc);
1394         }
1395
1396         return ret;
1397 }
1398
1399 static int gcm_decrypt(struct aead_request *req)
1400 {
1401         struct aead_edesc *edesc;
1402         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1403         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1404         struct device *jrdev = ctx->jrdev;
1405         bool all_contig;
1406         u32 *desc;
1407         int ret = 0;
1408
1409         /* allocate extended descriptor */
1410         edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false);
1411         if (IS_ERR(edesc))
1412                 return PTR_ERR(edesc);
1413
1414         /* Create and submit job descriptor*/
1415         init_gcm_job(req, edesc, all_contig, false);
1416 #ifdef DEBUG
1417         print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1418                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1419                        desc_bytes(edesc->hw_desc), 1);
1420 #endif
1421
1422         desc = edesc->hw_desc;
1423         ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
1424         if (!ret) {
1425                 ret = -EINPROGRESS;
1426         } else {
1427                 aead_unmap(jrdev, edesc, req);
1428                 kfree(edesc);
1429         }
1430
1431         return ret;
1432 }
1433
1434 static int ipsec_gcm_decrypt(struct aead_request *req)
1435 {
1436         if (req->assoclen < 8)
1437                 return -EINVAL;
1438
1439         return gcm_decrypt(req);
1440 }
1441
1442 static int aead_decrypt(struct aead_request *req)
1443 {
1444         struct aead_edesc *edesc;
1445         struct crypto_aead *aead = crypto_aead_reqtfm(req);
1446         struct caam_ctx *ctx = crypto_aead_ctx(aead);
1447         struct device *jrdev = ctx->jrdev;
1448         bool all_contig;
1449         u32 *desc;
1450         int ret = 0;
1451
1452 #ifdef DEBUG
1453         dbg_dump_sg(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
1454                     DUMP_PREFIX_ADDRESS, 16, 4, req->src,
1455                     req->assoclen + req->cryptlen, 1);
1456 #endif
1457
1458         /* allocate extended descriptor */
1459         edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
1460                                  &all_contig, false);
1461         if (IS_ERR(edesc))
1462                 return PTR_ERR(edesc);
1463
1464         /* Create and submit job descriptor*/
1465         init_authenc_job(req, edesc, all_contig, false);
1466 #ifdef DEBUG
1467         print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1468                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1469                        desc_bytes(edesc->hw_desc), 1);
1470 #endif
1471
1472         desc = edesc->hw_desc;
1473         ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
1474         if (!ret) {
1475                 ret = -EINPROGRESS;
1476         } else {
1477                 aead_unmap(jrdev, edesc, req);
1478                 kfree(edesc);
1479         }
1480
1481         return ret;
1482 }
1483
1484 /*
1485  * allocate and map the ablkcipher extended descriptor for ablkcipher
1486  */
1487 static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
1488                                                        *req, int desc_bytes,
1489                                                        bool *iv_contig_out)
1490 {
1491         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1492         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1493         struct device *jrdev = ctx->jrdev;
1494         gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
1495                        GFP_KERNEL : GFP_ATOMIC;
1496         int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
1497         struct ablkcipher_edesc *edesc;
1498         dma_addr_t iv_dma = 0;
1499         bool in_contig;
1500         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1501         int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
1502
1503         src_nents = sg_nents_for_len(req->src, req->nbytes);
1504         if (unlikely(src_nents < 0)) {
1505                 dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
1506                         req->nbytes);
1507                 return ERR_PTR(src_nents);
1508         }
1509
1510         if (req->dst != req->src) {
1511                 dst_nents = sg_nents_for_len(req->dst, req->nbytes);
1512                 if (unlikely(dst_nents < 0)) {
1513                         dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
1514                                 req->nbytes);
1515                         return ERR_PTR(dst_nents);
1516                 }
1517         }
1518
1519         if (likely(req->src == req->dst)) {
1520                 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1521                                               DMA_BIDIRECTIONAL);
1522                 if (unlikely(!mapped_src_nents)) {
1523                         dev_err(jrdev, "unable to map source\n");
1524                         return ERR_PTR(-ENOMEM);
1525                 }
1526         } else {
1527                 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1528                                               DMA_TO_DEVICE);
1529                 if (unlikely(!mapped_src_nents)) {
1530                         dev_err(jrdev, "unable to map source\n");
1531                         return ERR_PTR(-ENOMEM);
1532                 }
1533
1534                 mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
1535                                               DMA_FROM_DEVICE);
1536                 if (unlikely(!mapped_dst_nents)) {
1537                         dev_err(jrdev, "unable to map destination\n");
1538                         dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
1539                         return ERR_PTR(-ENOMEM);
1540                 }
1541         }
1542
1543         iv_dma = dma_map_single(jrdev, req->info, ivsize, DMA_TO_DEVICE);
1544         if (dma_mapping_error(jrdev, iv_dma)) {
1545                 dev_err(jrdev, "unable to map IV\n");
1546                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
1547                            0, 0, 0);
1548                 return ERR_PTR(-ENOMEM);
1549         }
1550
1551         if (mapped_src_nents == 1 &&
1552             iv_dma + ivsize == sg_dma_address(req->src)) {
1553                 in_contig = true;
1554                 sec4_sg_ents = 0;
1555         } else {
1556                 in_contig = false;
1557                 sec4_sg_ents = 1 + mapped_src_nents;
1558         }
1559         dst_sg_idx = sec4_sg_ents;
1560         sec4_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
1561         sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
1562
1563         /* allocate space for base edesc and hw desc commands, link tables */
1564         edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
1565                         GFP_DMA | flags);
1566         if (!edesc) {
1567                 dev_err(jrdev, "could not allocate extended descriptor\n");
1568                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
1569                            iv_dma, ivsize, 0, 0);
1570                 return ERR_PTR(-ENOMEM);
1571         }
1572
1573         edesc->src_nents = src_nents;
1574         edesc->dst_nents = dst_nents;
1575         edesc->sec4_sg_bytes = sec4_sg_bytes;
1576         edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
1577                          desc_bytes;
1578
1579         if (!in_contig) {
1580                 dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
1581                 sg_to_sec4_sg_last(req->src, mapped_src_nents,
1582                                    edesc->sec4_sg + 1, 0);
1583         }
1584
1585         if (mapped_dst_nents > 1) {
1586                 sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
1587                                    edesc->sec4_sg + dst_sg_idx, 0);
1588         }
1589
1590         edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
1591                                             sec4_sg_bytes, DMA_TO_DEVICE);
1592         if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
1593                 dev_err(jrdev, "unable to map S/G table\n");
1594                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
1595                            iv_dma, ivsize, 0, 0);
1596                 kfree(edesc);
1597                 return ERR_PTR(-ENOMEM);
1598         }
1599
1600         edesc->iv_dma = iv_dma;
1601
1602 #ifdef DEBUG
1603         print_hex_dump(KERN_ERR, "ablkcipher sec4_sg@"__stringify(__LINE__)": ",
1604                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
1605                        sec4_sg_bytes, 1);
1606 #endif
1607
1608         *iv_contig_out = in_contig;
1609         return edesc;
1610 }
1611
1612 static int ablkcipher_encrypt(struct ablkcipher_request *req)
1613 {
1614         struct ablkcipher_edesc *edesc;
1615         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1616         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1617         struct device *jrdev = ctx->jrdev;
1618         bool iv_contig;
1619         u32 *desc;
1620         int ret = 0;
1621
1622         /* allocate extended descriptor */
1623         edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
1624                                        CAAM_CMD_SZ, &iv_contig);
1625         if (IS_ERR(edesc))
1626                 return PTR_ERR(edesc);
1627
1628         /* Create and submit job descriptor*/
1629         init_ablkcipher_job(ctx->sh_desc_enc,
1630                 ctx->sh_desc_enc_dma, edesc, req, iv_contig);
1631 #ifdef DEBUG
1632         print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
1633                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1634                        desc_bytes(edesc->hw_desc), 1);
1635 #endif
1636         desc = edesc->hw_desc;
1637         ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
1638
1639         if (!ret) {
1640                 ret = -EINPROGRESS;
1641         } else {
1642                 ablkcipher_unmap(jrdev, edesc, req);
1643                 kfree(edesc);
1644         }
1645
1646         return ret;
1647 }
1648
1649 static int ablkcipher_decrypt(struct ablkcipher_request *req)
1650 {
1651         struct ablkcipher_edesc *edesc;
1652         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1653         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1654         struct device *jrdev = ctx->jrdev;
1655         bool iv_contig;
1656         u32 *desc;
1657         int ret = 0;
1658
1659         /* allocate extended descriptor */
1660         edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
1661                                        CAAM_CMD_SZ, &iv_contig);
1662         if (IS_ERR(edesc))
1663                 return PTR_ERR(edesc);
1664
1665         /* Create and submit job descriptor*/
1666         init_ablkcipher_job(ctx->sh_desc_dec,
1667                 ctx->sh_desc_dec_dma, edesc, req, iv_contig);
1668         desc = edesc->hw_desc;
1669 #ifdef DEBUG
1670         print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
1671                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1672                        desc_bytes(edesc->hw_desc), 1);
1673 #endif
1674
1675         ret = caam_jr_enqueue(jrdev, desc, ablkcipher_decrypt_done, req);
1676         if (!ret) {
1677                 ret = -EINPROGRESS;
1678         } else {
1679                 ablkcipher_unmap(jrdev, edesc, req);
1680                 kfree(edesc);
1681         }
1682
1683         return ret;
1684 }
1685
1686 /*
1687  * allocate and map the ablkcipher extended descriptor
1688  * for ablkcipher givencrypt
1689  */
1690 static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
1691                                 struct skcipher_givcrypt_request *greq,
1692                                 int desc_bytes,
1693                                 bool *iv_contig_out)
1694 {
1695         struct ablkcipher_request *req = &greq->creq;
1696         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1697         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1698         struct device *jrdev = ctx->jrdev;
1699         gfp_t flags = (req->base.flags &  CRYPTO_TFM_REQ_MAY_SLEEP) ?
1700                        GFP_KERNEL : GFP_ATOMIC;
1701         int src_nents, mapped_src_nents, dst_nents, mapped_dst_nents;
1702         struct ablkcipher_edesc *edesc;
1703         dma_addr_t iv_dma = 0;
1704         bool out_contig;
1705         int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1706         int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
1707
1708         src_nents = sg_nents_for_len(req->src, req->nbytes);
1709         if (unlikely(src_nents < 0)) {
1710                 dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
1711                         req->nbytes);
1712                 return ERR_PTR(src_nents);
1713         }
1714
1715         if (likely(req->src == req->dst)) {
1716                 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1717                                               DMA_BIDIRECTIONAL);
1718                 if (unlikely(!mapped_src_nents)) {
1719                         dev_err(jrdev, "unable to map source\n");
1720                         return ERR_PTR(-ENOMEM);
1721                 }
1722
1723                 dst_nents = src_nents;
1724                 mapped_dst_nents = src_nents;
1725         } else {
1726                 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1727                                               DMA_TO_DEVICE);
1728                 if (unlikely(!mapped_src_nents)) {
1729                         dev_err(jrdev, "unable to map source\n");
1730                         return ERR_PTR(-ENOMEM);
1731                 }
1732
1733                 dst_nents = sg_nents_for_len(req->dst, req->nbytes);
1734                 if (unlikely(dst_nents < 0)) {
1735                         dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
1736                                 req->nbytes);
1737                         return ERR_PTR(dst_nents);
1738                 }
1739
1740                 mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
1741                                               DMA_FROM_DEVICE);
1742                 if (unlikely(!mapped_dst_nents)) {
1743                         dev_err(jrdev, "unable to map destination\n");
1744                         dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
1745                         return ERR_PTR(-ENOMEM);
1746                 }
1747         }
1748
1749         /*
1750          * Check if iv can be contiguous with source and destination.
1751          * If so, include it. If not, create scatterlist.
1752          */
1753         iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE);
1754         if (dma_mapping_error(jrdev, iv_dma)) {
1755                 dev_err(jrdev, "unable to map IV\n");
1756                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
1757                            0, 0, 0);
1758                 return ERR_PTR(-ENOMEM);
1759         }
1760
1761         sec4_sg_ents = mapped_src_nents > 1 ? mapped_src_nents : 0;
1762         dst_sg_idx = sec4_sg_ents;
1763         if (mapped_dst_nents == 1 &&
1764             iv_dma + ivsize == sg_dma_address(req->dst)) {
1765                 out_contig = true;
1766         } else {
1767                 out_contig = false;
1768                 sec4_sg_ents += 1 + mapped_dst_nents;
1769         }
1770
1771         /* allocate space for base edesc and hw desc commands, link tables */
1772         sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
1773         edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
1774                         GFP_DMA | flags);
1775         if (!edesc) {
1776                 dev_err(jrdev, "could not allocate extended descriptor\n");
1777                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
1778                            iv_dma, ivsize, 0, 0);
1779                 return ERR_PTR(-ENOMEM);
1780         }
1781
1782         edesc->src_nents = src_nents;
1783         edesc->dst_nents = dst_nents;
1784         edesc->sec4_sg_bytes = sec4_sg_bytes;
1785         edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
1786                          desc_bytes;
1787
1788         if (mapped_src_nents > 1)
1789                 sg_to_sec4_sg_last(req->src, mapped_src_nents, edesc->sec4_sg,
1790                                    0);
1791
1792         if (!out_contig) {
1793                 dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx,
1794                                    iv_dma, ivsize, 0);
1795                 sg_to_sec4_sg_last(req->dst, mapped_dst_nents,
1796                                    edesc->sec4_sg + dst_sg_idx + 1, 0);
1797         }
1798
1799         edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
1800                                             sec4_sg_bytes, DMA_TO_DEVICE);
1801         if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
1802                 dev_err(jrdev, "unable to map S/G table\n");
1803                 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
1804                            iv_dma, ivsize, 0, 0);
1805                 kfree(edesc);
1806                 return ERR_PTR(-ENOMEM);
1807         }
1808         edesc->iv_dma = iv_dma;
1809
1810 #ifdef DEBUG
1811         print_hex_dump(KERN_ERR,
1812                        "ablkcipher sec4_sg@" __stringify(__LINE__) ": ",
1813                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
1814                        sec4_sg_bytes, 1);
1815 #endif
1816
1817         *iv_contig_out = out_contig;
1818         return edesc;
1819 }
1820
1821 static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
1822 {
1823         struct ablkcipher_request *req = &creq->creq;
1824         struct ablkcipher_edesc *edesc;
1825         struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1826         struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1827         struct device *jrdev = ctx->jrdev;
1828         bool iv_contig = false;
1829         u32 *desc;
1830         int ret = 0;
1831
1832         /* allocate extended descriptor */
1833         edesc = ablkcipher_giv_edesc_alloc(creq, DESC_JOB_IO_LEN *
1834                                        CAAM_CMD_SZ, &iv_contig);
1835         if (IS_ERR(edesc))
1836                 return PTR_ERR(edesc);
1837
1838         /* Create and submit job descriptor*/
1839         init_ablkcipher_giv_job(ctx->sh_desc_givenc, ctx->sh_desc_givenc_dma,
1840                                 edesc, req, iv_contig);
1841 #ifdef DEBUG
1842         print_hex_dump(KERN_ERR,
1843                        "ablkcipher jobdesc@" __stringify(__LINE__) ": ",
1844                        DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1845                        desc_bytes(edesc->hw_desc), 1);
1846 #endif
1847         desc = edesc->hw_desc;
1848         ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
1849
1850         if (!ret) {
1851                 ret = -EINPROGRESS;
1852         } else {
1853                 ablkcipher_unmap(jrdev, edesc, req);
1854                 kfree(edesc);
1855         }
1856
1857         return ret;
1858 }
1859
1860 #define template_aead           template_u.aead
1861 #define template_ablkcipher     template_u.ablkcipher
1862 struct caam_alg_template {
1863         char name[CRYPTO_MAX_ALG_NAME];
1864         char driver_name[CRYPTO_MAX_ALG_NAME];
1865         unsigned int blocksize;
1866         u32 type;
1867         union {
1868                 struct ablkcipher_alg ablkcipher;
1869         } template_u;
1870         u32 class1_alg_type;
1871         u32 class2_alg_type;
1872 };
1873
1874 static struct caam_alg_template driver_algs[] = {
1875         /* ablkcipher descriptor */
1876         {
1877                 .name = "cbc(aes)",
1878                 .driver_name = "cbc-aes-caam",
1879                 .blocksize = AES_BLOCK_SIZE,
1880                 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
1881                 .template_ablkcipher = {
1882                         .setkey = ablkcipher_setkey,
1883                         .encrypt = ablkcipher_encrypt,
1884                         .decrypt = ablkcipher_decrypt,
1885                         .givencrypt = ablkcipher_givencrypt,
1886                         .geniv = "<built-in>",
1887                         .min_keysize = AES_MIN_KEY_SIZE,
1888                         .max_keysize = AES_MAX_KEY_SIZE,
1889                         .ivsize = AES_BLOCK_SIZE,
1890                         },
1891                 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
1892         },
1893         {
1894                 .name = "cbc(des3_ede)",
1895                 .driver_name = "cbc-3des-caam",
1896                 .blocksize = DES3_EDE_BLOCK_SIZE,
1897                 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
1898                 .template_ablkcipher = {
1899                         .setkey = ablkcipher_setkey,
1900                         .encrypt = ablkcipher_encrypt,
1901                         .decrypt = ablkcipher_decrypt,
1902                         .givencrypt = ablkcipher_givencrypt,
1903                         .geniv = "<built-in>",
1904                         .min_keysize = DES3_EDE_KEY_SIZE,
1905                         .max_keysize = DES3_EDE_KEY_SIZE,
1906                         .ivsize = DES3_EDE_BLOCK_SIZE,
1907                         },
1908                 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
1909         },
1910         {
1911                 .name = "cbc(des)",
1912                 .driver_name = "cbc-des-caam",
1913                 .blocksize = DES_BLOCK_SIZE,
1914                 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
1915                 .template_ablkcipher = {
1916                         .setkey = ablkcipher_setkey,
1917                         .encrypt = ablkcipher_encrypt,
1918                         .decrypt = ablkcipher_decrypt,
1919                         .givencrypt = ablkcipher_givencrypt,
1920                         .geniv = "<built-in>",
1921                         .min_keysize = DES_KEY_SIZE,
1922                         .max_keysize = DES_KEY_SIZE,
1923                         .ivsize = DES_BLOCK_SIZE,
1924                         },
1925                 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
1926         },
1927         {
1928                 .name = "ctr(aes)",
1929                 .driver_name = "ctr-aes-caam",
1930                 .blocksize = 1,
1931                 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1932                 .template_ablkcipher = {
1933                         .setkey = ablkcipher_setkey,
1934                         .encrypt = ablkcipher_encrypt,
1935                         .decrypt = ablkcipher_decrypt,
1936                         .geniv = "chainiv",
1937                         .min_keysize = AES_MIN_KEY_SIZE,
1938                         .max_keysize = AES_MAX_KEY_SIZE,
1939                         .ivsize = AES_BLOCK_SIZE,
1940                         },
1941                 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
1942         },
1943         {
1944                 .name = "rfc3686(ctr(aes))",
1945                 .driver_name = "rfc3686-ctr-aes-caam",
1946                 .blocksize = 1,
1947                 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
1948                 .template_ablkcipher = {
1949                         .setkey = ablkcipher_setkey,
1950                         .encrypt = ablkcipher_encrypt,
1951                         .decrypt = ablkcipher_decrypt,
1952                         .givencrypt = ablkcipher_givencrypt,
1953                         .geniv = "<built-in>",
1954                         .min_keysize = AES_MIN_KEY_SIZE +
1955                                        CTR_RFC3686_NONCE_SIZE,
1956                         .max_keysize = AES_MAX_KEY_SIZE +
1957                                        CTR_RFC3686_NONCE_SIZE,
1958                         .ivsize = CTR_RFC3686_IV_SIZE,
1959                         },
1960                 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
1961         },
1962         {
1963                 .name = "xts(aes)",
1964                 .driver_name = "xts-aes-caam",
1965                 .blocksize = AES_BLOCK_SIZE,
1966                 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
1967                 .template_ablkcipher = {
1968                         .setkey = xts_ablkcipher_setkey,
1969                         .encrypt = ablkcipher_encrypt,
1970                         .decrypt = ablkcipher_decrypt,
1971                         .geniv = "eseqiv",
1972                         .min_keysize = 2 * AES_MIN_KEY_SIZE,
1973                         .max_keysize = 2 * AES_MAX_KEY_SIZE,
1974                         .ivsize = AES_BLOCK_SIZE,
1975                         },
1976                 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
1977         },
1978 };
1979
1980 static struct caam_aead_alg driver_aeads[] = {
1981         {
1982                 .aead = {
1983                         .base = {
1984                                 .cra_name = "rfc4106(gcm(aes))",
1985                                 .cra_driver_name = "rfc4106-gcm-aes-caam",
1986                                 .cra_blocksize = 1,
1987                         },
1988                         .setkey = rfc4106_setkey,
1989                         .setauthsize = rfc4106_setauthsize,
1990                         .encrypt = ipsec_gcm_encrypt,
1991                         .decrypt = ipsec_gcm_decrypt,
1992                         .ivsize = 8,
1993                         .maxauthsize = AES_BLOCK_SIZE,
1994                 },
1995                 .caam = {
1996                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
1997                 },
1998         },
1999         {
2000                 .aead = {
2001                         .base = {
2002                                 .cra_name = "rfc4543(gcm(aes))",
2003                                 .cra_driver_name = "rfc4543-gcm-aes-caam",
2004                                 .cra_blocksize = 1,
2005                         },
2006                         .setkey = rfc4543_setkey,
2007                         .setauthsize = rfc4543_setauthsize,
2008                         .encrypt = ipsec_gcm_encrypt,
2009                         .decrypt = ipsec_gcm_decrypt,
2010                         .ivsize = 8,
2011                         .maxauthsize = AES_BLOCK_SIZE,
2012                 },
2013                 .caam = {
2014                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2015                 },
2016         },
2017         /* Galois Counter Mode */
2018         {
2019                 .aead = {
2020                         .base = {
2021                                 .cra_name = "gcm(aes)",
2022                                 .cra_driver_name = "gcm-aes-caam",
2023                                 .cra_blocksize = 1,
2024                         },
2025                         .setkey = gcm_setkey,
2026                         .setauthsize = gcm_setauthsize,
2027                         .encrypt = gcm_encrypt,
2028                         .decrypt = gcm_decrypt,
2029                         .ivsize = 12,
2030                         .maxauthsize = AES_BLOCK_SIZE,
2031                 },
2032                 .caam = {
2033                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2034                 },
2035         },
2036         /* single-pass ipsec_esp descriptor */
2037         {
2038                 .aead = {
2039                         .base = {
2040                                 .cra_name = "authenc(hmac(md5),"
2041                                             "ecb(cipher_null))",
2042                                 .cra_driver_name = "authenc-hmac-md5-"
2043                                                    "ecb-cipher_null-caam",
2044                                 .cra_blocksize = NULL_BLOCK_SIZE,
2045                         },
2046                         .setkey = aead_setkey,
2047                         .setauthsize = aead_setauthsize,
2048                         .encrypt = aead_encrypt,
2049                         .decrypt = aead_decrypt,
2050                         .ivsize = NULL_IV_SIZE,
2051                         .maxauthsize = MD5_DIGEST_SIZE,
2052                 },
2053                 .caam = {
2054                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2055                                            OP_ALG_AAI_HMAC_PRECOMP,
2056                 },
2057         },
2058         {
2059                 .aead = {
2060                         .base = {
2061                                 .cra_name = "authenc(hmac(sha1),"
2062                                             "ecb(cipher_null))",
2063                                 .cra_driver_name = "authenc-hmac-sha1-"
2064                                                    "ecb-cipher_null-caam",
2065                                 .cra_blocksize = NULL_BLOCK_SIZE,
2066                         },
2067                         .setkey = aead_setkey,
2068                         .setauthsize = aead_setauthsize,
2069                         .encrypt = aead_encrypt,
2070                         .decrypt = aead_decrypt,
2071                         .ivsize = NULL_IV_SIZE,
2072                         .maxauthsize = SHA1_DIGEST_SIZE,
2073                 },
2074                 .caam = {
2075                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2076                                            OP_ALG_AAI_HMAC_PRECOMP,
2077                 },
2078         },
2079         {
2080                 .aead = {
2081                         .base = {
2082                                 .cra_name = "authenc(hmac(sha224),"
2083                                             "ecb(cipher_null))",
2084                                 .cra_driver_name = "authenc-hmac-sha224-"
2085                                                    "ecb-cipher_null-caam",
2086                                 .cra_blocksize = NULL_BLOCK_SIZE,
2087                         },
2088                         .setkey = aead_setkey,
2089                         .setauthsize = aead_setauthsize,
2090                         .encrypt = aead_encrypt,
2091                         .decrypt = aead_decrypt,
2092                         .ivsize = NULL_IV_SIZE,
2093                         .maxauthsize = SHA224_DIGEST_SIZE,
2094                 },
2095                 .caam = {
2096                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2097                                            OP_ALG_AAI_HMAC_PRECOMP,
2098                 },
2099         },
2100         {
2101                 .aead = {
2102                         .base = {
2103                                 .cra_name = "authenc(hmac(sha256),"
2104                                             "ecb(cipher_null))",
2105                                 .cra_driver_name = "authenc-hmac-sha256-"
2106                                                    "ecb-cipher_null-caam",
2107                                 .cra_blocksize = NULL_BLOCK_SIZE,
2108                         },
2109                         .setkey = aead_setkey,
2110                         .setauthsize = aead_setauthsize,
2111                         .encrypt = aead_encrypt,
2112                         .decrypt = aead_decrypt,
2113                         .ivsize = NULL_IV_SIZE,
2114                         .maxauthsize = SHA256_DIGEST_SIZE,
2115                 },
2116                 .caam = {
2117                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2118                                            OP_ALG_AAI_HMAC_PRECOMP,
2119                 },
2120         },
2121         {
2122                 .aead = {
2123                         .base = {
2124                                 .cra_name = "authenc(hmac(sha384),"
2125                                             "ecb(cipher_null))",
2126                                 .cra_driver_name = "authenc-hmac-sha384-"
2127                                                    "ecb-cipher_null-caam",
2128                                 .cra_blocksize = NULL_BLOCK_SIZE,
2129                         },
2130                         .setkey = aead_setkey,
2131                         .setauthsize = aead_setauthsize,
2132                         .encrypt = aead_encrypt,
2133                         .decrypt = aead_decrypt,
2134                         .ivsize = NULL_IV_SIZE,
2135                         .maxauthsize = SHA384_DIGEST_SIZE,
2136                 },
2137                 .caam = {
2138                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2139                                            OP_ALG_AAI_HMAC_PRECOMP,
2140                 },
2141         },
2142         {
2143                 .aead = {
2144                         .base = {
2145                                 .cra_name = "authenc(hmac(sha512),"
2146                                             "ecb(cipher_null))",
2147                                 .cra_driver_name = "authenc-hmac-sha512-"
2148                                                    "ecb-cipher_null-caam",
2149                                 .cra_blocksize = NULL_BLOCK_SIZE,
2150                         },
2151                         .setkey = aead_setkey,
2152                         .setauthsize = aead_setauthsize,
2153                         .encrypt = aead_encrypt,
2154                         .decrypt = aead_decrypt,
2155                         .ivsize = NULL_IV_SIZE,
2156                         .maxauthsize = SHA512_DIGEST_SIZE,
2157                 },
2158                 .caam = {
2159                         .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2160                                            OP_ALG_AAI_HMAC_PRECOMP,
2161                 },
2162         },
2163         {
2164                 .aead = {
2165                         .base = {
2166                                 .cra_name = "authenc(hmac(md5),cbc(aes))",
2167                                 .cra_driver_name = "authenc-hmac-md5-"
2168                                                    "cbc-aes-caam",
2169                                 .cra_blocksize = AES_BLOCK_SIZE,
2170                         },
2171                         .setkey = aead_setkey,
2172                         .setauthsize = aead_setauthsize,
2173                         .encrypt = aead_encrypt,
2174                         .decrypt = aead_decrypt,
2175                         .ivsize = AES_BLOCK_SIZE,
2176                         .maxauthsize = MD5_DIGEST_SIZE,
2177                 },
2178                 .caam = {
2179                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2180                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2181                                            OP_ALG_AAI_HMAC_PRECOMP,
2182                 },
2183         },
2184         {
2185                 .aead = {
2186                         .base = {
2187                                 .cra_name = "echainiv(authenc(hmac(md5),"
2188                                             "cbc(aes)))",
2189                                 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2190                                                    "cbc-aes-caam",
2191                                 .cra_blocksize = AES_BLOCK_SIZE,
2192                         },
2193                         .setkey = aead_setkey,
2194                         .setauthsize = aead_setauthsize,
2195                         .encrypt = aead_encrypt,
2196                         .decrypt = aead_decrypt,
2197                         .ivsize = AES_BLOCK_SIZE,
2198                         .maxauthsize = MD5_DIGEST_SIZE,
2199                 },
2200                 .caam = {
2201                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2202                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2203                                            OP_ALG_AAI_HMAC_PRECOMP,
2204                         .geniv = true,
2205                 },
2206         },
2207         {
2208                 .aead = {
2209                         .base = {
2210                                 .cra_name = "authenc(hmac(sha1),cbc(aes))",
2211                                 .cra_driver_name = "authenc-hmac-sha1-"
2212                                                    "cbc-aes-caam",
2213                                 .cra_blocksize = AES_BLOCK_SIZE,
2214                         },
2215                         .setkey = aead_setkey,
2216                         .setauthsize = aead_setauthsize,
2217                         .encrypt = aead_encrypt,
2218                         .decrypt = aead_decrypt,
2219                         .ivsize = AES_BLOCK_SIZE,
2220                         .maxauthsize = SHA1_DIGEST_SIZE,
2221                 },
2222                 .caam = {
2223                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2224                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2225                                            OP_ALG_AAI_HMAC_PRECOMP,
2226                 },
2227         },
2228         {
2229                 .aead = {
2230                         .base = {
2231                                 .cra_name = "echainiv(authenc(hmac(sha1),"
2232                                             "cbc(aes)))",
2233                                 .cra_driver_name = "echainiv-authenc-"
2234                                                    "hmac-sha1-cbc-aes-caam",
2235                                 .cra_blocksize = AES_BLOCK_SIZE,
2236                         },
2237                         .setkey = aead_setkey,
2238                         .setauthsize = aead_setauthsize,
2239                         .encrypt = aead_encrypt,
2240                         .decrypt = aead_decrypt,
2241                         .ivsize = AES_BLOCK_SIZE,
2242                         .maxauthsize = SHA1_DIGEST_SIZE,
2243                 },
2244                 .caam = {
2245                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2246                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2247                                            OP_ALG_AAI_HMAC_PRECOMP,
2248                         .geniv = true,
2249                 },
2250         },
2251         {
2252                 .aead = {
2253                         .base = {
2254                                 .cra_name = "authenc(hmac(sha224),cbc(aes))",
2255                                 .cra_driver_name = "authenc-hmac-sha224-"
2256                                                    "cbc-aes-caam",
2257                                 .cra_blocksize = AES_BLOCK_SIZE,
2258                         },
2259                         .setkey = aead_setkey,
2260                         .setauthsize = aead_setauthsize,
2261                         .encrypt = aead_encrypt,
2262                         .decrypt = aead_decrypt,
2263                         .ivsize = AES_BLOCK_SIZE,
2264                         .maxauthsize = SHA224_DIGEST_SIZE,
2265                 },
2266                 .caam = {
2267                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2268                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2269                                            OP_ALG_AAI_HMAC_PRECOMP,
2270                 },
2271         },
2272         {
2273                 .aead = {
2274                         .base = {
2275                                 .cra_name = "echainiv(authenc(hmac(sha224),"
2276                                             "cbc(aes)))",
2277                                 .cra_driver_name = "echainiv-authenc-"
2278                                                    "hmac-sha224-cbc-aes-caam",
2279                                 .cra_blocksize = AES_BLOCK_SIZE,
2280                         },
2281                         .setkey = aead_setkey,
2282                         .setauthsize = aead_setauthsize,
2283                         .encrypt = aead_encrypt,
2284                         .decrypt = aead_decrypt,
2285                         .ivsize = AES_BLOCK_SIZE,
2286                         .maxauthsize = SHA224_DIGEST_SIZE,
2287                 },
2288                 .caam = {
2289                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2290                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2291                                            OP_ALG_AAI_HMAC_PRECOMP,
2292                         .geniv = true,
2293                 },
2294         },
2295         {
2296                 .aead = {
2297                         .base = {
2298                                 .cra_name = "authenc(hmac(sha256),cbc(aes))",
2299                                 .cra_driver_name = "authenc-hmac-sha256-"
2300                                                    "cbc-aes-caam",
2301                                 .cra_blocksize = AES_BLOCK_SIZE,
2302                         },
2303                         .setkey = aead_setkey,
2304                         .setauthsize = aead_setauthsize,
2305                         .encrypt = aead_encrypt,
2306                         .decrypt = aead_decrypt,
2307                         .ivsize = AES_BLOCK_SIZE,
2308                         .maxauthsize = SHA256_DIGEST_SIZE,
2309                 },
2310                 .caam = {
2311                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2312                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2313                                            OP_ALG_AAI_HMAC_PRECOMP,
2314                 },
2315         },
2316         {
2317                 .aead = {
2318                         .base = {
2319                                 .cra_name = "echainiv(authenc(hmac(sha256),"
2320                                             "cbc(aes)))",
2321                                 .cra_driver_name = "echainiv-authenc-"
2322                                                    "hmac-sha256-cbc-aes-caam",
2323                                 .cra_blocksize = AES_BLOCK_SIZE,
2324                         },
2325                         .setkey = aead_setkey,
2326                         .setauthsize = aead_setauthsize,
2327                         .encrypt = aead_encrypt,
2328                         .decrypt = aead_decrypt,
2329                         .ivsize = AES_BLOCK_SIZE,
2330                         .maxauthsize = SHA256_DIGEST_SIZE,
2331                 },
2332                 .caam = {
2333                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2334                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2335                                            OP_ALG_AAI_HMAC_PRECOMP,
2336                         .geniv = true,
2337                 },
2338         },
2339         {
2340                 .aead = {
2341                         .base = {
2342                                 .cra_name = "authenc(hmac(sha384),cbc(aes))",
2343                                 .cra_driver_name = "authenc-hmac-sha384-"
2344                                                    "cbc-aes-caam",
2345                                 .cra_blocksize = AES_BLOCK_SIZE,
2346                         },
2347                         .setkey = aead_setkey,
2348                         .setauthsize = aead_setauthsize,
2349                         .encrypt = aead_encrypt,
2350                         .decrypt = aead_decrypt,
2351                         .ivsize = AES_BLOCK_SIZE,
2352                         .maxauthsize = SHA384_DIGEST_SIZE,
2353                 },
2354                 .caam = {
2355                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2356                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2357                                            OP_ALG_AAI_HMAC_PRECOMP,
2358                 },
2359         },
2360         {
2361                 .aead = {
2362                         .base = {
2363                                 .cra_name = "echainiv(authenc(hmac(sha384),"
2364                                             "cbc(aes)))",
2365                                 .cra_driver_name = "echainiv-authenc-"
2366                                                    "hmac-sha384-cbc-aes-caam",
2367                                 .cra_blocksize = AES_BLOCK_SIZE,
2368                         },
2369                         .setkey = aead_setkey,
2370                         .setauthsize = aead_setauthsize,
2371                         .encrypt = aead_encrypt,
2372                         .decrypt = aead_decrypt,
2373                         .ivsize = AES_BLOCK_SIZE,
2374                         .maxauthsize = SHA384_DIGEST_SIZE,
2375                 },
2376                 .caam = {
2377                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2378                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2379                                            OP_ALG_AAI_HMAC_PRECOMP,
2380                         .geniv = true,
2381                 },
2382         },
2383         {
2384                 .aead = {
2385                         .base = {
2386                                 .cra_name = "authenc(hmac(sha512),cbc(aes))",
2387                                 .cra_driver_name = "authenc-hmac-sha512-"
2388                                                    "cbc-aes-caam",
2389                                 .cra_blocksize = AES_BLOCK_SIZE,
2390                         },
2391                         .setkey = aead_setkey,
2392                         .setauthsize = aead_setauthsize,
2393                         .encrypt = aead_encrypt,
2394                         .decrypt = aead_decrypt,
2395                         .ivsize = AES_BLOCK_SIZE,
2396                         .maxauthsize = SHA512_DIGEST_SIZE,
2397                 },
2398                 .caam = {
2399                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2400                         .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2401                                            OP_ALG_AAI_HMAC_PRECOMP,
2402                 },
2403         },
2404         {
2405                 .aead = {
2406                         .base = {
2407                                 .cra_name = "echainiv(authenc(hmac(sha512),"
2408                                             "cbc(aes)))",
2409                                 .cra_driver_name = "echainiv-authenc-"
2410                                                    "hmac-sha512-cbc-aes-caam",
2411                                 .cra_blocksize = AES_BLOCK_SIZE,
2412                         },
2413                         .setkey = aead_setkey,
2414                         .setauthsize = aead_setauthsize,
2415                         .encrypt = aead_encrypt,
2416                         .decrypt = aead_decrypt,
2417                         .ivsize = AES_BLOCK_SIZE,
2418                         .maxauthsize = SHA512_DIGEST_SIZE,
2419                 },
2420                 .caam = {
2421                         .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2422                         .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2423                                            OP_ALG_AAI_HMAC_PRECOMP,
2424                         .geniv = true,
2425                 },
2426         },
2427         {
2428                 .aead = {
2429                         .base = {
2430                                 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
2431                                 .cra_driver_name = "authenc-hmac-md5-"
2432                                                    "cbc-des3_ede-caam",
2433                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2434                         },
2435                         .setkey = aead_setkey,
2436                         .setauthsize = aead_setauthsize,
2437                         .encrypt = aead_encrypt,
2438                         .decrypt = aead_decrypt,
2439                         .ivsize = DES3_EDE_BLOCK_SIZE,
2440                         .maxauthsize = MD5_DIGEST_SIZE,
2441                 },
2442                 .caam = {
2443                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2444                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2445                                            OP_ALG_AAI_HMAC_PRECOMP,
2446                 }
2447         },
2448         {
2449                 .aead = {
2450                         .base = {
2451                                 .cra_name = "echainiv(authenc(hmac(md5),"
2452                                             "cbc(des3_ede)))",
2453                                 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2454                                                    "cbc-des3_ede-caam",
2455                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2456                         },
2457                         .setkey = aead_setkey,
2458                         .setauthsize = aead_setauthsize,
2459                         .encrypt = aead_encrypt,
2460                         .decrypt = aead_decrypt,
2461                         .ivsize = DES3_EDE_BLOCK_SIZE,
2462                         .maxauthsize = MD5_DIGEST_SIZE,
2463                 },
2464                 .caam = {
2465                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2466                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2467                                            OP_ALG_AAI_HMAC_PRECOMP,
2468                         .geniv = true,
2469                 }
2470         },
2471         {
2472                 .aead = {
2473                         .base = {
2474                                 .cra_name = "authenc(hmac(sha1),"
2475                                             "cbc(des3_ede))",
2476                                 .cra_driver_name = "authenc-hmac-sha1-"
2477                                                    "cbc-des3_ede-caam",
2478                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2479                         },
2480                         .setkey = aead_setkey,
2481                         .setauthsize = aead_setauthsize,
2482                         .encrypt = aead_encrypt,
2483                         .decrypt = aead_decrypt,
2484                         .ivsize = DES3_EDE_BLOCK_SIZE,
2485                         .maxauthsize = SHA1_DIGEST_SIZE,
2486                 },
2487                 .caam = {
2488                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2489                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2490                                            OP_ALG_AAI_HMAC_PRECOMP,
2491                 },
2492         },
2493         {
2494                 .aead = {
2495                         .base = {
2496                                 .cra_name = "echainiv(authenc(hmac(sha1),"
2497                                             "cbc(des3_ede)))",
2498                                 .cra_driver_name = "echainiv-authenc-"
2499                                                    "hmac-sha1-"
2500                                                    "cbc-des3_ede-caam",
2501                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2502                         },
2503                         .setkey = aead_setkey,
2504                         .setauthsize = aead_setauthsize,
2505                         .encrypt = aead_encrypt,
2506                         .decrypt = aead_decrypt,
2507                         .ivsize = DES3_EDE_BLOCK_SIZE,
2508                         .maxauthsize = SHA1_DIGEST_SIZE,
2509                 },
2510                 .caam = {
2511                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2512                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2513                                            OP_ALG_AAI_HMAC_PRECOMP,
2514                         .geniv = true,
2515                 },
2516         },
2517         {
2518                 .aead = {
2519                         .base = {
2520                                 .cra_name = "authenc(hmac(sha224),"
2521                                             "cbc(des3_ede))",
2522                                 .cra_driver_name = "authenc-hmac-sha224-"
2523                                                    "cbc-des3_ede-caam",
2524                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2525                         },
2526                         .setkey = aead_setkey,
2527                         .setauthsize = aead_setauthsize,
2528                         .encrypt = aead_encrypt,
2529                         .decrypt = aead_decrypt,
2530                         .ivsize = DES3_EDE_BLOCK_SIZE,
2531                         .maxauthsize = SHA224_DIGEST_SIZE,
2532                 },
2533                 .caam = {
2534                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2535                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2536                                            OP_ALG_AAI_HMAC_PRECOMP,
2537                 },
2538         },
2539         {
2540                 .aead = {
2541                         .base = {
2542                                 .cra_name = "echainiv(authenc(hmac(sha224),"
2543                                             "cbc(des3_ede)))",
2544                                 .cra_driver_name = "echainiv-authenc-"
2545                                                    "hmac-sha224-"
2546                                                    "cbc-des3_ede-caam",
2547                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2548                         },
2549                         .setkey = aead_setkey,
2550                         .setauthsize = aead_setauthsize,
2551                         .encrypt = aead_encrypt,
2552                         .decrypt = aead_decrypt,
2553                         .ivsize = DES3_EDE_BLOCK_SIZE,
2554                         .maxauthsize = SHA224_DIGEST_SIZE,
2555                 },
2556                 .caam = {
2557                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2558                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2559                                            OP_ALG_AAI_HMAC_PRECOMP,
2560                         .geniv = true,
2561                 },
2562         },
2563         {
2564                 .aead = {
2565                         .base = {
2566                                 .cra_name = "authenc(hmac(sha256),"
2567                                             "cbc(des3_ede))",
2568                                 .cra_driver_name = "authenc-hmac-sha256-"
2569                                                    "cbc-des3_ede-caam",
2570                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2571                         },
2572                         .setkey = aead_setkey,
2573                         .setauthsize = aead_setauthsize,
2574                         .encrypt = aead_encrypt,
2575                         .decrypt = aead_decrypt,
2576                         .ivsize = DES3_EDE_BLOCK_SIZE,
2577                         .maxauthsize = SHA256_DIGEST_SIZE,
2578                 },
2579                 .caam = {
2580                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2581                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2582                                            OP_ALG_AAI_HMAC_PRECOMP,
2583                 },
2584         },
2585         {
2586                 .aead = {
2587                         .base = {
2588                                 .cra_name = "echainiv(authenc(hmac(sha256),"
2589                                             "cbc(des3_ede)))",
2590                                 .cra_driver_name = "echainiv-authenc-"
2591                                                    "hmac-sha256-"
2592                                                    "cbc-des3_ede-caam",
2593                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2594                         },
2595                         .setkey = aead_setkey,
2596                         .setauthsize = aead_setauthsize,
2597                         .encrypt = aead_encrypt,
2598                         .decrypt = aead_decrypt,
2599                         .ivsize = DES3_EDE_BLOCK_SIZE,
2600                         .maxauthsize = SHA256_DIGEST_SIZE,
2601                 },
2602                 .caam = {
2603                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2604                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2605                                            OP_ALG_AAI_HMAC_PRECOMP,
2606                         .geniv = true,
2607                 },
2608         },
2609         {
2610                 .aead = {
2611                         .base = {
2612                                 .cra_name = "authenc(hmac(sha384),"
2613                                             "cbc(des3_ede))",
2614                                 .cra_driver_name = "authenc-hmac-sha384-"
2615                                                    "cbc-des3_ede-caam",
2616                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2617                         },
2618                         .setkey = aead_setkey,
2619                         .setauthsize = aead_setauthsize,
2620                         .encrypt = aead_encrypt,
2621                         .decrypt = aead_decrypt,
2622                         .ivsize = DES3_EDE_BLOCK_SIZE,
2623                         .maxauthsize = SHA384_DIGEST_SIZE,
2624                 },
2625                 .caam = {
2626                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2627                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2628                                            OP_ALG_AAI_HMAC_PRECOMP,
2629                 },
2630         },
2631         {
2632                 .aead = {
2633                         .base = {
2634                                 .cra_name = "echainiv(authenc(hmac(sha384),"
2635                                             "cbc(des3_ede)))",
2636                                 .cra_driver_name = "echainiv-authenc-"
2637                                                    "hmac-sha384-"
2638                                                    "cbc-des3_ede-caam",
2639                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2640                         },
2641                         .setkey = aead_setkey,
2642                         .setauthsize = aead_setauthsize,
2643                         .encrypt = aead_encrypt,
2644                         .decrypt = aead_decrypt,
2645                         .ivsize = DES3_EDE_BLOCK_SIZE,
2646                         .maxauthsize = SHA384_DIGEST_SIZE,
2647                 },
2648                 .caam = {
2649                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2650                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2651                                            OP_ALG_AAI_HMAC_PRECOMP,
2652                         .geniv = true,
2653                 },
2654         },
2655         {
2656                 .aead = {
2657                         .base = {
2658                                 .cra_name = "authenc(hmac(sha512),"
2659                                             "cbc(des3_ede))",
2660                                 .cra_driver_name = "authenc-hmac-sha512-"
2661                                                    "cbc-des3_ede-caam",
2662                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2663                         },
2664                         .setkey = aead_setkey,
2665                         .setauthsize = aead_setauthsize,
2666                         .encrypt = aead_encrypt,
2667                         .decrypt = aead_decrypt,
2668                         .ivsize = DES3_EDE_BLOCK_SIZE,
2669                         .maxauthsize = SHA512_DIGEST_SIZE,
2670                 },
2671                 .caam = {
2672                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2673                         .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2674                                            OP_ALG_AAI_HMAC_PRECOMP,
2675                 },
2676         },
2677         {
2678                 .aead = {
2679                         .base = {
2680                                 .cra_name = "echainiv(authenc(hmac(sha512),"
2681                                             "cbc(des3_ede)))",
2682                                 .cra_driver_name = "echainiv-authenc-"
2683                                                    "hmac-sha512-"
2684                                                    "cbc-des3_ede-caam",
2685                                 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2686                         },
2687                         .setkey = aead_setkey,
2688                         .setauthsize = aead_setauthsize,
2689                         .encrypt = aead_encrypt,
2690                         .decrypt = aead_decrypt,
2691                         .ivsize = DES3_EDE_BLOCK_SIZE,
2692                         .maxauthsize = SHA512_DIGEST_SIZE,
2693                 },
2694                 .caam = {
2695                         .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2696                         .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2697                                            OP_ALG_AAI_HMAC_PRECOMP,
2698                         .geniv = true,
2699                 },
2700         },
2701         {
2702                 .aead = {
2703                         .base = {
2704                                 .cra_name = "authenc(hmac(md5),cbc(des))",
2705                                 .cra_driver_name = "authenc-hmac-md5-"
2706                                                    "cbc-des-caam",
2707                                 .cra_blocksize = DES_BLOCK_SIZE,
2708                         },
2709                         .setkey = aead_setkey,
2710                         .setauthsize = aead_setauthsize,
2711                         .encrypt = aead_encrypt,
2712                         .decrypt = aead_decrypt,
2713                         .ivsize = DES_BLOCK_SIZE,
2714                         .maxauthsize = MD5_DIGEST_SIZE,
2715                 },
2716                 .caam = {
2717                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2718                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2719                                            OP_ALG_AAI_HMAC_PRECOMP,
2720                 },
2721         },
2722         {
2723                 .aead = {
2724                         .base = {
2725                                 .cra_name = "echainiv(authenc(hmac(md5),"
2726                                             "cbc(des)))",
2727                                 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2728                                                    "cbc-des-caam",
2729                                 .cra_blocksize = DES_BLOCK_SIZE,
2730                         },
2731                         .setkey = aead_setkey,
2732                         .setauthsize = aead_setauthsize,
2733                         .encrypt = aead_encrypt,
2734                         .decrypt = aead_decrypt,
2735                         .ivsize = DES_BLOCK_SIZE,
2736                         .maxauthsize = MD5_DIGEST_SIZE,
2737                 },
2738                 .caam = {
2739                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2740                         .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2741                                            OP_ALG_AAI_HMAC_PRECOMP,
2742                         .geniv = true,
2743                 },
2744         },
2745         {
2746                 .aead = {
2747                         .base = {
2748                                 .cra_name = "authenc(hmac(sha1),cbc(des))",
2749                                 .cra_driver_name = "authenc-hmac-sha1-"
2750                                                    "cbc-des-caam",
2751                                 .cra_blocksize = DES_BLOCK_SIZE,
2752                         },
2753                         .setkey = aead_setkey,
2754                         .setauthsize = aead_setauthsize,
2755                         .encrypt = aead_encrypt,
2756                         .decrypt = aead_decrypt,
2757                         .ivsize = DES_BLOCK_SIZE,
2758                         .maxauthsize = SHA1_DIGEST_SIZE,
2759                 },
2760                 .caam = {
2761                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2762                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2763                                            OP_ALG_AAI_HMAC_PRECOMP,
2764                 },
2765         },
2766         {
2767                 .aead = {
2768                         .base = {
2769                                 .cra_name = "echainiv(authenc(hmac(sha1),"
2770                                             "cbc(des)))",
2771                                 .cra_driver_name = "echainiv-authenc-"
2772                                                    "hmac-sha1-cbc-des-caam",
2773                                 .cra_blocksize = DES_BLOCK_SIZE,
2774                         },
2775                         .setkey = aead_setkey,
2776                         .setauthsize = aead_setauthsize,
2777                         .encrypt = aead_encrypt,
2778                         .decrypt = aead_decrypt,
2779                         .ivsize = DES_BLOCK_SIZE,
2780                         .maxauthsize = SHA1_DIGEST_SIZE,
2781                 },
2782                 .caam = {
2783                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2784                         .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2785                                            OP_ALG_AAI_HMAC_PRECOMP,
2786                         .geniv = true,
2787                 },
2788         },
2789         {
2790                 .aead = {
2791                         .base = {
2792                                 .cra_name = "authenc(hmac(sha224),cbc(des))",
2793                                 .cra_driver_name = "authenc-hmac-sha224-"
2794                                                    "cbc-des-caam",
2795                                 .cra_blocksize = DES_BLOCK_SIZE,
2796                         },
2797                         .setkey = aead_setkey,
2798                         .setauthsize = aead_setauthsize,
2799                         .encrypt = aead_encrypt,
2800                         .decrypt = aead_decrypt,
2801                         .ivsize = DES_BLOCK_SIZE,
2802                         .maxauthsize = SHA224_DIGEST_SIZE,
2803                 },
2804                 .caam = {
2805                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2806                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2807                                            OP_ALG_AAI_HMAC_PRECOMP,
2808                 },
2809         },
2810         {
2811                 .aead = {
2812                         .base = {
2813                                 .cra_name = "echainiv(authenc(hmac(sha224),"
2814                                             "cbc(des)))",
2815                                 .cra_driver_name = "echainiv-authenc-"
2816                                                    "hmac-sha224-cbc-des-caam",
2817                                 .cra_blocksize = DES_BLOCK_SIZE,
2818                         },
2819                         .setkey = aead_setkey,
2820                         .setauthsize = aead_setauthsize,
2821                         .encrypt = aead_encrypt,
2822                         .decrypt = aead_decrypt,
2823                         .ivsize = DES_BLOCK_SIZE,
2824                         .maxauthsize = SHA224_DIGEST_SIZE,
2825                 },
2826                 .caam = {
2827                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2828                         .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2829                                            OP_ALG_AAI_HMAC_PRECOMP,
2830                         .geniv = true,
2831                 },
2832         },
2833         {
2834                 .aead = {
2835                         .base = {
2836                                 .cra_name = "authenc(hmac(sha256),cbc(des))",
2837                                 .cra_driver_name = "authenc-hmac-sha256-"
2838                                                    "cbc-des-caam",
2839                                 .cra_blocksize = DES_BLOCK_SIZE,
2840                         },
2841                         .setkey = aead_setkey,
2842                         .setauthsize = aead_setauthsize,
2843                         .encrypt = aead_encrypt,
2844                         .decrypt = aead_decrypt,
2845                         .ivsize = DES_BLOCK_SIZE,
2846                         .maxauthsize = SHA256_DIGEST_SIZE,
2847                 },
2848                 .caam = {
2849                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2850                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2851                                            OP_ALG_AAI_HMAC_PRECOMP,
2852                 },
2853         },
2854         {
2855                 .aead = {
2856                         .base = {
2857                                 .cra_name = "echainiv(authenc(hmac(sha256),"
2858                                             "cbc(des)))",
2859                                 .cra_driver_name = "echainiv-authenc-"
2860                                                    "hmac-sha256-cbc-des-caam",
2861                                 .cra_blocksize = DES_BLOCK_SIZE,
2862                         },
2863                         .setkey = aead_setkey,
2864                         .setauthsize = aead_setauthsize,
2865                         .encrypt = aead_encrypt,
2866                         .decrypt = aead_decrypt,
2867                         .ivsize = DES_BLOCK_SIZE,
2868                         .maxauthsize = SHA256_DIGEST_SIZE,
2869                 },
2870                 .caam = {
2871                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2872                         .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2873                                            OP_ALG_AAI_HMAC_PRECOMP,
2874                         .geniv = true,
2875                 },
2876         },
2877         {
2878                 .aead = {
2879                         .base = {
2880                                 .cra_name = "authenc(hmac(sha384),cbc(des))",
2881                                 .cra_driver_name = "authenc-hmac-sha384-"
2882                                                    "cbc-des-caam",
2883                                 .cra_blocksize = DES_BLOCK_SIZE,
2884                         },
2885                         .setkey = aead_setkey,
2886                         .setauthsize = aead_setauthsize,
2887                         .encrypt = aead_encrypt,
2888                         .decrypt = aead_decrypt,
2889                         .ivsize = DES_BLOCK_SIZE,
2890                         .maxauthsize = SHA384_DIGEST_SIZE,
2891                 },
2892                 .caam = {
2893                         .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2894                         .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2895                                            OP_ALG_AAI_HMAC_PRECOMP,
2896                 },
2897         },